/** * `ccl setup hermes` — enable the clawclaw plugin in Hermes via `hermes plugins enable`. */ import { Command } from 'commander'; import { spawnSync } from 'child_process'; export const PLUGIN_ID = 'clawclaw'; export interface SetupHermesResult { exitCode: number; output: string[]; } export function runHermesSetup(flags: { yes?: boolean; print?: boolean }): SetupHermesResult { const out: string[] = []; // Check hermes is available const which = spawnSync('hermes', ['--version'], { stdio: 'pipe', timeout: 5000 }); if (which.status !== 0) { out.push('hermes CLI not found. Install it first, then re-run.'); return { exitCode: 1, output: out }; } // Check current plugin status const list = spawnSync('hermes', ['plugins', 'list'], { stdio: 'pipe', timeout: 5000, env: { ...process.env, HERMES_PLUGINS_DEBUG: '1' }, }); const listOutput = list.stdout?.toString() ?? ''; const alreadyEnabled = listOutput.includes(PLUGIN_ID) && !listOutput.includes(`${PLUGIN_ID} (disabled)`); if (alreadyEnabled) { out.push(`Plugin "${PLUGIN_ID}" is already enabled in Hermes.`); return { exitCode: 0, output: out }; } if (flags.print) { out.push(`# Will run: hermes plugins enable ${PLUGIN_ID}`); return { exitCode: 0, output: out }; } if (!flags.yes) { out.push(`Pending: hermes plugins enable ${PLUGIN_ID}`); out.push(``); out.push(`Dry-run only. Re-run with -y to apply.`); return { exitCode: 2, output: out }; } const result = spawnSync('hermes', ['plugins', 'enable', PLUGIN_ID], { stdio: 'pipe', timeout: 10000, }); if (result.status !== 0) { out.push(`Failed to enable plugin: ${result.stderr?.toString() ?? result.stdout?.toString() ?? 'unknown error'}`); return { exitCode: 1, output: out }; } out.push(`Plugin "${PLUGIN_ID}" enabled in Hermes.`); out.push(`Verify: HERMES_PLUGINS_DEBUG=1 hermes plugins list`); return { exitCode: 0, output: out }; } export function createSetupHermesSubcommand(): Command { return new Command('hermes') .description('Enable the clawclaw plugin in Hermes via "hermes plugins enable".') .option('-y, --yes', 'Apply changes (default is dry-run)') .option('--print', 'Only print the command that would be run; do not execute') .action((opts: { yes?: boolean; print?: boolean }) => { const result = runHermesSetup({ yes: opts.yes, print: opts.print }); for (const line of result.output) console.log(line); if (result.exitCode !== 0) process.exit(result.exitCode); }); }