chore: Push command files (part 1)
Some checks failed
/ test (push) Has been cancelled

This commit is contained in:
2026-02-03 08:39:25 +00:00
parent dcbed0c079
commit 8569130584

View File

@@ -1,93 +1,93 @@
import * as path from 'path';
import { Command } from 'commander'; import { Command } from 'commander';
import chalk from 'chalk'; import chalk from 'chalk';
import { import {
getWorkspacePath, getWorkspacePath,
loadWorkspaceConfig, loadWorkspaceConfig,
sanitizeAgentName sanitizeAgentName,
hasUncommittedChanges,
getGitUserInfo
} from '../utils/file-utils'; } from '../utils/file-utils';
import { import {
getWorktreeStatus, generateDiff,
createGit, createGit,
getCurrentBranch getCurrentBranch,
getWorktreeStatus,
getLastCommitInfo
} from '../utils/git-utils'; } from '../utils/git-utils';
import { import { formatDiffAsMarkdown, formatChangesForReview, generateShortDiffSummary } from '../utils/diff-utils';
formatChangesForReview,
generateShortDiffSummary
} from '../utils/diff-utils';
import { DiffResult } from '../types/index';
import { GitAgentSyncError, WorkspaceNotFoundError } from '../utils/errors'; import { GitAgentSyncError, WorkspaceNotFoundError } from '../utils/errors';
export function createStatusCommand(): Command { export function createStatusCommand(): Command {
const cmd = new Command('status') const cmd = new Command('status')
.alias('st')
.description('Show detailed changes for a specific agent workspace') .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('--short', 'Show short summary only')
.option('--output <file>', 'Export to file') .option('--json', 'Output as JSON')
.action(async (agentName, options) => { .action(async (agentName, options) => {
try { try {
const currentPath = process.cwd(); const currentPath = process.cwd();
let workspacePath: string; let workspacePath: string;
let targetAgentName: string;
if (agentName) { if (agentName) {
const sanitizedName = sanitizeAgentName(agentName); targetAgentName = sanitizeAgentName(agentName);
workspacePath = getWorkspacePath(currentPath, sanitizedName); workspacePath = getWorkspacePath(currentPath, targetAgentName);
} else { } else {
workspacePath = await detectCurrentWorkspace(currentPath); const workspaceResult = await detectCurrentWorkspace(currentPath);
workspacePath = workspaceResult.path;
targetAgentName = workspaceResult.agentName;
} }
const config = await loadWorkspaceConfig(workspacePath); const config = await loadWorkspaceConfig(workspacePath);
if (!config) { if (!config) {
throw new WorkspaceNotFoundError(agentName || 'current'); throw new WorkspaceNotFoundError(targetAgentName);
} }
const status = await getWorktreeStatus(workspacePath); const workspaceChange = await getWorktreeStatus(workspacePath);
if (options.short) { if (options.short) {
const diffResult: DiffResult = { const summary = workspaceChange.uncommittedCount > 0
agentName: config.agentName, ? `${workspaceChange.uncommittedCount} uncommitted change(s)`
branch: status.branch, : 'No uncommitted changes';
comparedBranch: '', console.log(chalk.white(`${targetAgentName}: ${summary}`));
files: [],
summary: {
filesChanged: status.changes.length,
additions: 0,
deletions: 0
}
};
const summary = generateShortDiffSummary(diffResult);
console.log(chalk.white(`${config.agentName}: ${summary}`));
return; return;
} }
const reviewContent = formatChangesForReview(workspacePath, status.changes, config.agentName); if (options.json) {
console.log(JSON.stringify(workspaceChange, null, 2));
return;
}
if (options.output) { console.log(chalk.cyan(`\n📊 Status: ${targetAgentName}`));
const fs = await import('fs-extra'); console.log(chalk.gray(`Branch: ${workspaceChange.branch}`));
await fs.writeFile(options.output, reviewContent, 'utf-8'); console.log(chalk.gray(`Path: ${workspacePath}`));
console.log(chalk.green(`\n✓ Status exported to ${options.output}`)); console.log(chalk.gray(`Last Updated: ${new Date(workspaceChange.lastUpdated).toLocaleString()}`));
} else { console.log(chalk.gray('─'.repeat(60)));
console.log(chalk.cyan(`\n📊 Agent: ${config.agentName}`));
console.log(chalk.gray('─'.repeat(60))); if (workspaceChange.changes.length === 0) {
console.log(` Branch: ${chalk.white(status.branch)}`); console.log(chalk.green('\n✓ No uncommitted changes'));
console.log(` Path: ${chalk.white(workspacePath)}`); return;
console.log(` Changes: ${chalk.white(status.uncommittedCount.toString())}`); }
console.log(` Last Updated: ${chalk.white(new Date(status.lastUpdated).toLocaleString())}`);
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.gray('─'.repeat(60)));
if (status.changes.length === 0) {
console.log(chalk.yellow('\n No changes detected.'));
} else {
console.log(chalk.cyan('\n📝 Changed Files:')); console.log(chalk.cyan('\n📝 Changed Files:'));
for (const change of status.changes) { for (const change of workspaceChange.changes) {
const statusIcon = getStatusIcon(change.status); const statusIcon = change.status === 'added' ? '+' : change.status === 'modified' ? '~' : '-';
const stagedBadge = change.staged ? chalk.green('[staged]') : ''; const statusColor = change.status === 'added' ? chalk.green : change.status === 'modified' ? chalk.yellow : chalk.red;
console.log(` ${statusIcon} ${chalk.white(change.file)} ${stagedBadge}`); console.log(` ${statusColor(statusIcon)} ${change.file}`);
}
}
} }
console.log(chalk.cyan('\n💡 Use git-agent-sync diff to generate a full diff'));
} catch (error) { } catch (error) {
const gitError = error instanceof GitAgentSyncError ? error : new GitAgentSyncError(String(error)); const gitError = error instanceof GitAgentSyncError ? error : new GitAgentSyncError(String(error));
console.error(chalk.red(`\n❌ Error: ${gitError.message}`)); console.error(chalk.red(`\n❌ Error: ${gitError.message}`));
@@ -98,29 +98,18 @@ export function createStatusCommand(): Command {
return cmd; return cmd;
} }
async function detectCurrentWorkspace(currentPath: string): Promise<string> { async function detectCurrentWorkspace(currentPath: string): Promise<{ path: string; agentName: string }> {
const git = createGit(currentPath); const git = createGit(currentPath);
const branch = await getCurrentBranch(git); const branch = await getCurrentBranch(git);
if (branch.startsWith('agent-')) { if (branch.startsWith('agent-')) {
const agentName = branch.replace(/^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.'); 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('?');
}
}