This commit is contained in:
@@ -1,110 +1,59 @@
|
|||||||
import * as path from 'path';
|
|
||||||
import { Command } from 'commander';
|
import { Command } from 'commander';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import {
|
import {
|
||||||
loadGlobalConfig,
|
|
||||||
getAllWorkspaces,
|
getAllWorkspaces,
|
||||||
loadWorkspaceConfig,
|
loadGlobalConfig,
|
||||||
loadChangeTracking
|
loadWorkspaceConfig
|
||||||
} from '../utils/file-utils';
|
} from '../utils/file-utils';
|
||||||
import {
|
import {
|
||||||
createGit,
|
createGit,
|
||||||
getWorktreeStatus,
|
getWorktreeStatus
|
||||||
hasUncommittedChanges,
|
|
||||||
getLastCommitInfo
|
|
||||||
} from '../utils/git-utils';
|
} from '../utils/git-utils';
|
||||||
import { GitAgentSyncError } from '../utils/errors';
|
|
||||||
import { WorkspaceInfo, WorkspaceChange } from '../types';
|
|
||||||
|
|
||||||
export function createListCommand(): Command {
|
export function createListCommand(): Command {
|
||||||
const cmd = new Command('list')
|
const cmd = new Command('list')
|
||||||
.alias('ls')
|
.alias('ls')
|
||||||
.description('List all active agent workspaces')
|
.description('List all active agent workspaces')
|
||||||
.option('--json', 'Output as JSON')
|
.option('--json', 'Output as JSON')
|
||||||
.option('--verbose', 'Show detailed information')
|
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
try {
|
try {
|
||||||
const currentPath = process.cwd();
|
const currentPath = process.cwd();
|
||||||
const globalConfig = await loadGlobalConfig();
|
|
||||||
const workspaces = await getAllWorkspaces(currentPath);
|
const workspaces = await getAllWorkspaces(currentPath);
|
||||||
|
|
||||||
if (workspaces.length === 0) {
|
if (workspaces.length === 0) {
|
||||||
console.log(chalk.yellow('\n📭 No agent workspaces found.'));
|
console.log(chalk.yellow('\nNo agent workspaces found.'));
|
||||||
console.log(` Create one with: ${chalk.cyan('git-agent-sync create <agent-name>')}`);
|
console.log(chalk.cyan('\n💡 Create one with: git-agent-sync create <agent-name>'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspaceDetails: (WorkspaceInfo & { status?: WorkspaceChange; lastCommit?: string })[] = [];
|
|
||||||
|
|
||||||
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) {
|
if (options.json) {
|
||||||
console.log(JSON.stringify(workspaceDetails, null, 2));
|
console.log(JSON.stringify(workspaces, null, 2));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(chalk.cyan('\n🤖 Agent Workspaces'));
|
console.log(chalk.cyan('\n📋 Agent Workspaces'));
|
||||||
console.log(chalk.gray('─'.repeat(80)));
|
console.log(chalk.gray('─'.repeat(70)));
|
||||||
|
|
||||||
const tableData = workspaceDetails.map(ws => ({
|
for (const workspace of workspaces) {
|
||||||
name: ws.name,
|
console.log(`\n${chalk.bold(workspace.name)}`);
|
||||||
branch: ws.branch,
|
console.log(` Path: ${chalk.white(workspace.path)}`);
|
||||||
path: path.relative(currentPath, ws.path),
|
console.log(` Branch: ${chalk.white(workspace.branch)}`);
|
||||||
status: ws.hasChanges ? chalk.yellow('🔄 modified') : chalk.green('✓ clean'),
|
|
||||||
changes: ws.hasChanges ? chalk.yellow(`${ws.changeCount}`) : chalk.gray('0'),
|
|
||||||
lastCommit: truncateString(ws.lastCommit || '', 30)
|
|
||||||
}));
|
|
||||||
|
|
||||||
const maxName = Math.max(...tableData.map(d => d.name.length));
|
if (workspace.hasChanges) {
|
||||||
const maxBranch = Math.max(...tableData.map(d => d.branch.length));
|
console.log(` ${chalk.yellow(`⚠ ${workspace.changeCount} uncommitted changes`)}`);
|
||||||
const maxPath = Math.max(...tableData.map(d => d.path.length));
|
} else {
|
||||||
|
console.log(` ${chalk.green('✓ No uncommitted changes')}`);
|
||||||
for (const row of tableData) {
|
|
||||||
const nameCol = row.name.padEnd(maxName);
|
|
||||||
const branchCol = row.branch.padEnd(maxBranch);
|
|
||||||
const pathCol = row.path.padEnd(maxPath);
|
|
||||||
const changesCol = row.changes.padStart(3);
|
|
||||||
|
|
||||||
console.log(` ${chalk.white(nameCol)} ${chalk.gray('│')} ${chalk.white(branchCol)} ${chalk.gray('│')} ${chalk.white(pathCol)} ${chalk.gray('│')} ${row.status} ${chalk.gray('│')} ${changesCol} changes`);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(chalk.gray('─'.repeat(80)));
|
|
||||||
console.log(` ${chalk.white(`${workspaces.length} workspace(s)`)}`);
|
|
||||||
const totalChanges = workspaceDetails.reduce((sum, ws) => sum + ws.changeCount, 0);
|
|
||||||
console.log(` ${chalk.white(`${totalChanges} total uncommitted change(s)`)}`);
|
|
||||||
|
|
||||||
if (options.verbose) {
|
|
||||||
console.log(chalk.cyan('\n📁 Workspace Paths:'));
|
|
||||||
for (const ws of workspaceDetails) {
|
|
||||||
console.log(` ${chalk.white(ws.name)}: ${ws.path}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(chalk.gray('─'.repeat(70)));
|
||||||
|
console.log(chalk.cyan(`\nTotal: ${workspaces.length} workspace(s)`));
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const gitError = error instanceof GitAgentSyncError ? error : new GitAgentSyncError(String(error));
|
console.error(chalk.red(`\n❌ Error: ${(error as Error).message}`));
|
||||||
console.error(chalk.red(`\n❌ Error: ${gitError.message}`));
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
function truncateString(str: string, maxLength: number): string {
|
|
||||||
if (str.length <= maxLength) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return str.substring(0, maxLength - 3) + '...';
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user