From 85691305845ff9d142c218e9bc15725d56204e91 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Tue, 3 Feb 2026 08:39:25 +0000 Subject: [PATCH] chore: Push command files (part 1) --- src/commands/status.ts | 133 +++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 72 deletions(-) diff --git a/src/commands/status.ts b/src/commands/status.ts index 03f3d94..c2d74f1 100644 --- a/src/commands/status.ts +++ b/src/commands/status.ts @@ -1,93 +1,93 @@ -import * as path from 'path'; import { Command } from 'commander'; import chalk from 'chalk'; import { getWorkspacePath, loadWorkspaceConfig, - sanitizeAgentName + sanitizeAgentName, + hasUncommittedChanges, + getGitUserInfo } from '../utils/file-utils'; import { - getWorktreeStatus, + generateDiff, createGit, - getCurrentBranch + getCurrentBranch, + getWorktreeStatus, + getLastCommitInfo } from '../utils/git-utils'; -import { - formatChangesForReview, - generateShortDiffSummary -} from '../utils/diff-utils'; -import { DiffResult } from '../types/index'; +import { formatDiffAsMarkdown, formatChangesForReview, generateShortDiffSummary } from '../utils/diff-utils'; import { GitAgentSyncError, WorkspaceNotFoundError } from '../utils/errors'; export function createStatusCommand(): Command { const cmd = new Command('status') - .alias('st') .description('Show detailed changes for a specific agent workspace') - .argument('[agent-name]', 'Agent name (defaults to current workspace if in one)') + .argument('[agent-name]', 'Agent name (defaults to current workspace)') .option('--short', 'Show short summary only') - .option('--output ', 'Export to file') + .option('--json', 'Output as JSON') .action(async (agentName, options) => { try { const currentPath = process.cwd(); let workspacePath: string; + let targetAgentName: string; if (agentName) { - const sanitizedName = sanitizeAgentName(agentName); - workspacePath = getWorkspacePath(currentPath, sanitizedName); + targetAgentName = sanitizeAgentName(agentName); + workspacePath = getWorkspacePath(currentPath, targetAgentName); } else { - workspacePath = await detectCurrentWorkspace(currentPath); + const workspaceResult = await detectCurrentWorkspace(currentPath); + workspacePath = workspaceResult.path; + targetAgentName = workspaceResult.agentName; } const config = await loadWorkspaceConfig(workspacePath); if (!config) { - throw new WorkspaceNotFoundError(agentName || 'current'); + throw new WorkspaceNotFoundError(targetAgentName); } - const status = await getWorktreeStatus(workspacePath); + const workspaceChange = await getWorktreeStatus(workspacePath); if (options.short) { - const diffResult: DiffResult = { - agentName: config.agentName, - branch: status.branch, - comparedBranch: '', - files: [], - summary: { - filesChanged: status.changes.length, - additions: 0, - deletions: 0 - } - }; - const summary = generateShortDiffSummary(diffResult); - console.log(chalk.white(`${config.agentName}: ${summary}`)); + const summary = workspaceChange.uncommittedCount > 0 + ? `${workspaceChange.uncommittedCount} uncommitted change(s)` + : 'No uncommitted changes'; + console.log(chalk.white(`${targetAgentName}: ${summary}`)); return; } - const reviewContent = formatChangesForReview(workspacePath, status.changes, config.agentName); - - if (options.output) { - const fs = await import('fs-extra'); - await fs.writeFile(options.output, reviewContent, 'utf-8'); - console.log(chalk.green(`\nāœ“ Status exported to ${options.output}`)); - } else { - console.log(chalk.cyan(`\nšŸ“Š Agent: ${config.agentName}`)); - console.log(chalk.gray('─'.repeat(60))); - console.log(` Branch: ${chalk.white(status.branch)}`); - console.log(` Path: ${chalk.white(workspacePath)}`); - console.log(` Changes: ${chalk.white(status.uncommittedCount.toString())}`); - console.log(` Last Updated: ${chalk.white(new Date(status.lastUpdated).toLocaleString())}`); - console.log(chalk.gray('─'.repeat(60))); - - 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 status.changes) { - const statusIcon = getStatusIcon(change.status); - const stagedBadge = change.staged ? chalk.green('[staged]') : ''; - console.log(` ${statusIcon} ${chalk.white(change.file)} ${stagedBadge}`); - } - } + 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.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(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}`); + } + + 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}`)); @@ -98,29 +98,18 @@ export function createStatusCommand(): Command { return cmd; } -async function detectCurrentWorkspace(currentPath: string): Promise { +async function detectCurrentWorkspace(currentPath: string): Promise<{ path: string; agentName: string }> { const git = createGit(currentPath); const branch = await getCurrentBranch(git); if (branch.startsWith('agent-')) { const agentName = branch.replace(/^agent-/, ''); - return getWorkspacePath(currentPath, agentName); + const { getWorkspacePath } = await import('../utils/file-utils'); + return { + agentName, + path: getWorkspacePath(currentPath, agentName) + }; } throw new GitAgentSyncError('Not in an agent workspace. Please specify an agent name.'); } - -function getStatusIcon(status: string): string { - switch (status) { - case 'added': - return chalk.green('✚'); - case 'modified': - return chalk.yellow('āœŽ'); - case 'deleted': - return chalk.red('āœ–'); - case 'renamed': - return chalk.cyan('↔'); - default: - return chalk.gray('?'); - } -}