diff --git a/src/commands/list.ts b/src/commands/list.ts index b64c27b..202bf2d 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -1,59 +1,40 @@ +import * as path from 'path'; import { Command } from 'commander'; import chalk from 'chalk'; -import { - getAllWorkspaces, - loadGlobalConfig, - loadWorkspaceConfig -} from '../utils/file-utils'; -import { - createGit, - getWorktreeStatus -} from '../utils/git-utils'; +import { loadGlobalConfig, getAllWorkspaces, loadWorkspaceConfig } from '../utils/file-utils'; +import { getWorktreeStatus, getLastCommitInfo } from '../utils/git-utils'; +import { GitAgentSyncError } from '../utils/errors'; export function createListCommand(): Command { - const cmd = new Command('list') - .alias('ls') - .description('List all active agent workspaces') - .option('--json', 'Output as JSON') - .action(async (options) => { - try { - const currentPath = process.cwd(); - const workspaces = await getAllWorkspaces(currentPath); - - if (workspaces.length === 0) { - console.log(chalk.yellow('\nNo agent workspaces found.')); - console.log(chalk.cyan('\nšŸ’” Create one with: git-agent-sync create ')); - return; + const cmd = new Command('list').alias('ls').description('List all active agent workspaces').option('--json', 'Output as JSON').option('--verbose', 'Show detailed information').action(async (options) => { + try { + const currentPath = process.cwd(); + const globalConfig = await loadGlobalConfig(); + const workspaces = await getAllWorkspaces(currentPath); + if (workspaces.length === 0) { console.log(chalk.yellow('\nšŸ“­ No agent workspaces found.')); return; } + const workspaceDetails = []; + for (const workspace of workspaces) { + const config = await loadWorkspaceConfig(workspace.path); + if (config) { + const status = await getWorktreeStatus(workspace.path); + const lastCommit = await getLastCommitInfo(workspace.path); + workspaceDetails.push({ ...workspace, hasChanges: status.uncommittedCount > 0, changeCount: status.uncommittedCount, lastCommit: lastCommit.message || 'No commits' }); } - - if (options.json) { - console.log(JSON.stringify(workspaces, null, 2)); - return; - } - - console.log(chalk.cyan('\nšŸ“‹ Agent Workspaces')); - console.log(chalk.gray('─'.repeat(70))); - - for (const workspace of workspaces) { - console.log(`\n${chalk.bold(workspace.name)}`); - console.log(` Path: ${chalk.white(workspace.path)}`); - console.log(` Branch: ${chalk.white(workspace.branch)}`); - - if (workspace.hasChanges) { - console.log(` ${chalk.yellow(`⚠ ${workspace.changeCount} uncommitted changes`)}`); - } else { - console.log(` ${chalk.green('āœ“ No uncommitted changes')}`); - } - } - - console.log(chalk.gray('─'.repeat(70))); - console.log(chalk.cyan(`\nTotal: ${workspaces.length} workspace(s)`)); - - } catch (error) { - console.error(chalk.red(`\nāŒ Error: ${(error as Error).message}`)); - process.exit(1); } - }); - + if (options.json) { console.log(JSON.stringify(workspaceDetails, null, 2)); return; } + console.log(chalk.cyan('\nšŸ¤– Agent Workspaces')); + console.log(chalk.gray('─'.repeat(80))); + for (const row of workspaceDetails) { + const status = row.hasChanges ? chalk.yellow('šŸ”„ modified') : chalk.green('āœ“ clean'); + console.log(` ${chalk.white(row.name.padEnd(15))} ${chalk.gray('│')} ${chalk.white(row.branch.padEnd(25))} ${chalk.gray('│')} ${status} ${chalk.gray('│')} ${chalk.yellow(`${row.changeCount}`)} changes`); + } + console.log(chalk.gray('─'.repeat(80))); + console.log(` ${chalk.white(`${workspaces.length} workspace(s)`)}`); + } 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; -} +} \ No newline at end of file