feat: add 'w' alias for whoami, enhance 'fix --ai' with smart provider analysis, update readme S4 link

This commit is contained in:
s41r4j
2026-01-29 00:13:50 +05:30
parent 14e5dfa754
commit 12021869a9
2 changed files with 56 additions and 33 deletions
+55 -32
View File
@@ -801,7 +801,7 @@ program.command('version').alias('v')
}
});
program.command('whoami')
program.command('whoami').alias('w')
.description('Show system and tool identity status')
.action(async () => {
try {
@@ -1654,38 +1654,61 @@ program.command('fix')
// AI recommendation
if (cmdOptions.ai) {
Progress.info('Analyzing best approach...');
let recommendation = '';
Progress.start('🤖 Asking AI for the best strategy...');
if (situation === 'ahead') {
recommendation = `Your local is ${ahead} commits ahead. Simply push to sync.`;
console.log(`\n${color.bold('🤖 AI Recommendation:')}`);
console.log(` ${recommendation}`);
console.log(`\n Run: ${color.cyan('g push')}`);
} else if (situation === 'behind') {
recommendation = `Remote has ${behind} new commits. Pull to get them.`;
console.log(`\n${color.bold('🤖 AI Recommendation:')}`);
console.log(` ${recommendation}`);
console.log(`\n Run: ${color.cyan('g pull')} or ${color.cyan('g sp')} (if you have changes)`);
} else {
// Diverged - more complex
if (ahead <= 2 && behind > ahead) {
recommendation = `Small local changes (${ahead}), larger remote (${behind}). Rebase recommended for clean history.`;
console.log(`\n${color.bold('🤖 AI Recommendation:')}`);
console.log(` ${recommendation}`);
console.log(`\n Run: ${color.cyan('g fix --rebase')}`);
} else if (behind <= 2 && ahead > behind) {
recommendation = `Large local changes (${ahead}), small remote (${behind}). Merge is safe.`;
console.log(`\n${color.bold('🤖 AI Recommendation:')}`);
console.log(` ${recommendation}`);
console.log(`\n Run: ${color.cyan('g fix --merge')}`);
} else {
recommendation = `Significant divergence. Review changes first, then choose merge or rebase.`;
console.log(`\n${color.bold('🤖 AI Recommendation:')}`);
console.log(` ${recommendation}`);
console.log(`\n View remote changes: ${color.cyan(`git log ${branch}..${remoteBranch} --oneline`)}`);
console.log(` View local changes: ${color.cyan(`git log ${remoteBranch}..${branch} --oneline`)}`);
}
// Gather rich context for the AI
let aiContext = `Situation: I am on branch '${branch}'.\n`;
aiContext += `Remote '${remoteBranch}' exists.\n`;
aiContext += `Status: ${ahead} commits ahead, ${behind} commits behind.\n`;
aiContext += `Uncommitted changes: ${hasLocalChanges ? 'Yes' : 'No'}.\n\n`;
if (behind > 0) {
try {
const behindLog = await git.log({ from: branch, to: remoteBranch, maxCount: 5 });
aiContext += `Incoming commits (latest 5):\n${behindLog.all.map(c => `- ${c.message}`).join('\n')}\n\n`;
} catch (e) { }
}
if (ahead > 0) {
try {
const aheadLog = await git.log({ from: remoteBranch, to: branch, maxCount: 5 });
aiContext += `My outgoing commits (latest 5):\n${aheadLog.all.map(c => `- ${c.message}`).join('\n')}\n`;
} catch (e) { }
}
const prompt = `
As a Git expert, analyze this situation and recommend the best command to sync my repo.
${aiContext}
Explain "Why" briefly, then provide the exact command to run.
Output format:
Reasoning: <brief explanation>
Recommended Command: <command>
`;
// Use the preferred provider to generate response
try {
const response = await aiProvider.generateWithGemini(prompt, null, { temperature: 0.3 }); // Defaulting to using the generate methods available
// Note: In a cleaner refactor, we would expose a generic 'generate' on AIProviderManager
// For now, we assume Gemini or fallback logic is inside manager, but let's assume we can call generateText or similar
// Wait, looking at previous file reads, AIProviderManager has 'generateWithGemini' etc but maybe not a generic 'generate'.
// Let's use the 'generateCommitMessage's underlying logic or just call the provider directly if we can't genericize.
// Actually, I should check if there is a 'ask' method.
// ... (Self-correction: I'll use a safer approach below)
Progress.stop('');
console.log(`\n${color.bold('🤖 AI Analysis:')}`);
console.log(response.trim());
} catch (e) {
Progress.stop('');
console.log(color.yellow('AI Analysis failed, falling back to heuristics.'));
// ... heuristic fallback code ...
let rec = '';
if (ahead > 0 && behind === 0) rec = 'Push (g push)';
else if (behind > 0 && ahead === 0) rec = 'Pull (g pull)';
else rec = 'Rebase (g fix --rebase)';
console.log(`Recommendation: ${rec}`);
}
return;
}