ghosttrack
Version:
Living code intelligence - track AI changes at function level. No more commits, only ghosts!
150 lines (149 loc) ⢠4.58 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import { initializeGhostTrack } from '../core/init.js';
import { captureGhost } from '../core/capture.js';
import { listGhosts } from '../core/list.js';
import { showHistory } from '../core/history.js';
import { showDiff } from '../core/diff.js';
import { rollbackGhost } from '../core/rollback.js';
import { analyzeImpact } from '../core/impact.js';
import { showSummary } from '../core/summary.js';
const program = new Command();
console.log(chalk.cyan(`
š» GhostTrack - Living Code Intelligence
No more commits, only ghosts.
`));
program
.name('ghosttrack')
.description('Track ghosts (AI changes) at the function level')
.version('0.0.1');
program
.command('init')
.description('Initialize GhostTrack in your project')
.action(async () => {
try {
await initializeGhostTrack();
}
catch (error) {
console.error(chalk.red('Error initializing GhostTrack:', error));
process.exit(1);
}
});
program
.command('capture')
.description('Capture the current state (create a ghost)')
.option('-m, --message <message>', 'Ghost message')
.option('-f, --files <files...>', 'Specific files to capture')
.option('--ai <model>', 'AI model that created changes')
.action(async (options) => {
try {
await captureGhost({
message: options.message,
files: options.files,
aiModel: options.ai
});
}
catch (error) {
console.error(chalk.red('Error capturing ghost:', error));
process.exit(1);
}
});
program
.command('list')
.description('List all tracked functions and their ghosts')
.option('-f, --file <file>', 'Filter by file')
.option('--function <name>', 'Filter by function name')
.action(async (options) => {
try {
await listGhosts({
file: options.file,
function: options.function
});
}
catch (error) {
console.error(chalk.red('Error listing ghosts:', error));
process.exit(1);
}
});
program
.command('history <function>')
.description('Show ghost history for a function')
.option('-f, --file <file>', 'Specify file if function name is ambiguous')
.action(async (functionName, options) => {
try {
await showHistory(functionName, {
file: options.file
});
}
catch (error) {
console.error(chalk.red('Error showing history:', error));
process.exit(1);
}
});
program
.command('diff <function>')
.description('Show differences between ghost versions')
.option('-f, --file <file>', 'Specify file if function name is ambiguous')
.option('--from <hash>', 'Starting ghost hash')
.option('--to <hash>', 'Ending ghost hash')
.action(async (functionName, options) => {
try {
await showDiff(functionName, {
file: options.file,
from: options.from,
to: options.to
});
}
catch (error) {
console.error(chalk.red('Error showing diff:', error));
process.exit(1);
}
});
program
.command('rollback <function>')
.description('Rollback a function to a previous ghost')
.option('-f, --file <file>', 'Specify file if function name is ambiguous')
.option('--to <hash>', 'Rollback to specific ghost hash')
.option('-n, --steps <n>', 'Number of ghosts to go back', '1')
.action(async (functionName, options) => {
try {
await rollbackGhost(functionName, {
file: options.file,
to: options.to,
steps: parseInt(options.steps)
});
}
catch (error) {
console.error(chalk.red('Error rolling back ghost:', error));
process.exit(1);
}
});
program
.command('impact <function>')
.description('Analyze impact of changing a function')
.option('-f, --file <file>', 'Specify file if function name is ambiguous')
.action(async (functionName, options) => {
try {
await analyzeImpact(functionName, {
file: options.file
});
}
catch (error) {
console.error(chalk.red('Error analyzing impact:', error));
process.exit(1);
}
});
program
.command('summary')
.description('Show GhostTrack summary statistics')
.action(async () => {
try {
await showSummary();
}
catch (error) {
console.error(chalk.red('Error showing summary:', error));
process.exit(1);
}
});
program.parse();