This commit is contained in:
@@ -1,115 +1,56 @@
|
||||
import * as path from 'path';
|
||||
import { Command } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import {
|
||||
getWorkspacePath,
|
||||
loadWorkspaceConfig,
|
||||
sanitizeAgentName,
|
||||
hasUncommittedChanges,
|
||||
getGitUserInfo
|
||||
} from '../utils/file-utils';
|
||||
import {
|
||||
generateDiff,
|
||||
createGit,
|
||||
getCurrentBranch,
|
||||
getWorktreeStatus,
|
||||
getLastCommitInfo
|
||||
} from '../utils/git-utils';
|
||||
import { formatDiffAsMarkdown, formatChangesForReview, generateShortDiffSummary } from '../utils/diff-utils';
|
||||
import { getWorkspacePath, loadWorkspaceConfig, sanitizeAgentName } from '../utils/file-utils';
|
||||
import { getWorktreeStatus, createGit, getCurrentBranch } from '../utils/git-utils';
|
||||
import { formatChangesForReview, generateShortDiffSummary } from '../utils/diff-utils';
|
||||
import { DiffResult } from '../types/index';
|
||||
import { GitAgentSyncError, WorkspaceNotFoundError } from '../utils/errors';
|
||||
|
||||
export function createStatusCommand(): Command {
|
||||
const cmd = new Command('status')
|
||||
.description('Show detailed changes for a specific agent workspace')
|
||||
.argument('[agent-name]', 'Agent name (defaults to current workspace)')
|
||||
.option('--short', 'Show short summary only')
|
||||
.option('--json', 'Output as JSON')
|
||||
.action(async (agentName, options) => {
|
||||
const cmd = new Command('status').alias('st').description('Show detailed changes for a specific agent workspace').argument('[agent-name]', 'Agent name').option('--short', 'Show short summary only').option('--output <file>', 'Export to file').action(async (agentName, options) => {
|
||||
try {
|
||||
const currentPath = process.cwd();
|
||||
let workspacePath: string;
|
||||
let targetAgentName: string;
|
||||
|
||||
if (agentName) {
|
||||
targetAgentName = sanitizeAgentName(agentName);
|
||||
workspacePath = getWorkspacePath(currentPath, targetAgentName);
|
||||
workspacePath = getWorkspacePath(currentPath, sanitizeAgentName(agentName));
|
||||
} else {
|
||||
const workspaceResult = await detectCurrentWorkspace(currentPath);
|
||||
workspacePath = workspaceResult.path;
|
||||
targetAgentName = workspaceResult.agentName;
|
||||
workspacePath = await detectCurrentWorkspace(currentPath);
|
||||
}
|
||||
|
||||
const config = await loadWorkspaceConfig(workspacePath);
|
||||
if (!config) {
|
||||
throw new WorkspaceNotFoundError(targetAgentName);
|
||||
}
|
||||
|
||||
const workspaceChange = await getWorktreeStatus(workspacePath);
|
||||
|
||||
if (!config) throw new WorkspaceNotFoundError(agentName || 'current');
|
||||
const status = await getWorktreeStatus(workspacePath);
|
||||
if (options.short) {
|
||||
const summary = workspaceChange.uncommittedCount > 0
|
||||
? `${workspaceChange.uncommittedCount} uncommitted change(s)`
|
||||
: 'No uncommitted changes';
|
||||
console.log(chalk.white(`${targetAgentName}: ${summary}`));
|
||||
const diffResult: DiffResult = { agentName: config.agentName, branch: status.branch, comparedBranch: '', files: [], summary: { filesChanged: status.changes.length, additions: 0, deletions: 0 } };
|
||||
console.log(chalk.white(`${config.agentName}: ${generateShortDiffSummary(diffResult)}`));
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify(workspaceChange, null, 2));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(chalk.cyan(`\n📊 Status: ${targetAgentName}`));
|
||||
console.log(chalk.gray(`Branch: ${workspaceChange.branch}`));
|
||||
console.log(chalk.gray(`Path: ${workspacePath}`));
|
||||
console.log(chalk.gray(`Last Updated: ${new Date(workspaceChange.lastUpdated).toLocaleString()}`));
|
||||
console.log(chalk.cyan(`\n📊 Agent: ${config.agentName}`));
|
||||
console.log(chalk.gray('─'.repeat(60)));
|
||||
|
||||
if (workspaceChange.changes.length === 0) {
|
||||
console.log(chalk.green('\n✓ No uncommitted changes'));
|
||||
return;
|
||||
}
|
||||
|
||||
const added = workspaceChange.changes.filter(c => c.status === 'added').length;
|
||||
const modified = workspaceChange.changes.filter(c => c.status === 'modified').length;
|
||||
const deleted = workspaceChange.changes.filter(c => c.status === 'deleted').length;
|
||||
|
||||
console.log(chalk.cyan('\n📈 Change Summary:'));
|
||||
console.log(` ${chalk.green(`+${added} added`)}`);
|
||||
console.log(` ${chalk.yellow(`~${modified} modified`)}`);
|
||||
console.log(` ${chalk.red(`-${deleted} deleted`)}`);
|
||||
console.log(chalk.gray('─'.repeat(60)));
|
||||
|
||||
console.log(` Branch: ${chalk.white(status.branch)}`);
|
||||
console.log(` Changes: ${chalk.white(status.uncommittedCount.toString())}`);
|
||||
if (status.changes.length === 0) console.log(chalk.yellow('\n No changes detected.'));
|
||||
else {
|
||||
console.log(chalk.cyan('\n📝 Changed Files:'));
|
||||
for (const change of workspaceChange.changes) {
|
||||
const statusIcon = change.status === 'added' ? '+' : change.status === 'modified' ? '~' : '-';
|
||||
const statusColor = change.status === 'added' ? chalk.green : change.status === 'modified' ? chalk.yellow : chalk.red;
|
||||
console.log(` ${statusColor(statusIcon)} ${change.file}`);
|
||||
for (const change of status.changes) {
|
||||
const statusIcon = change.status === 'added' ? chalk.green('✚') : change.status === 'modified' ? chalk.yellow('✎') : change.status === 'deleted' ? chalk.red('✖') : chalk.cyan('↔');
|
||||
console.log(` ${statusIcon} ${chalk.white(change.file)}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(chalk.cyan('\n💡 Use git-agent-sync diff to generate a full diff'));
|
||||
|
||||
} catch (error) {
|
||||
const gitError = error instanceof GitAgentSyncError ? error : new GitAgentSyncError(String(error));
|
||||
console.error(chalk.red(`\n❌ Error: ${gitError.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
async function detectCurrentWorkspace(currentPath: string): Promise<{ path: string; agentName: string }> {
|
||||
async function detectCurrentWorkspace(currentPath: string): Promise<string> {
|
||||
const git = createGit(currentPath);
|
||||
const branch = await getCurrentBranch(git);
|
||||
|
||||
if (branch.startsWith('agent-')) {
|
||||
const agentName = branch.replace(/^agent-/, '');
|
||||
const { getWorkspacePath } = await import('../utils/file-utils');
|
||||
return {
|
||||
agentName,
|
||||
path: getWorkspacePath(currentPath, agentName)
|
||||
};
|
||||
return getWorkspacePath(currentPath, agentName);
|
||||
}
|
||||
|
||||
throw new GitAgentSyncError('Not in an agent workspace. Please specify an agent name.');
|
||||
}
|
||||
Reference in New Issue
Block a user