clawdie-ai/setup/agent-cli-check.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

/**
* setup/agent-cli-check.ts Detect agent CLIs available on PATH.
*
* Clawdie's controlplane harness uses Aider+Pi as the primary driver.
* At least one agent CLI must be resolvable on PATH for onboarding to
* succeed. This mirrors the standard per-adapter command-resolvable
* pattern, but as a single fail-fast check at the top of `setup onboard`.
*
* No "hello probe" yet `command -v` is enough.
*/
import { commandExists } from './platform.js';
export interface AgentCli {
name: string;
command: string;
present: boolean;
}
export const AGENT_CLIS: ReadonlyArray<{ name: string; command: string }> = [
{ name: 'pi', command: 'pi' },
{ name: 'aider', command: 'aider' },
{ name: 'claude', command: 'claude' },
{ name: 'codex', command: 'codex' },
{ name: 'gemini', command: 'gemini' },
];
export function detectAgentClis(): AgentCli[] {
return AGENT_CLIS.map(({ name, command }) => ({
name,
command,
present: commandExists(command),
}));
}
export class NoAgentCliError extends Error {
constructor() {
super(
[
'No agent CLI found on PATH.',
'Clawdie needs pi and aider for the Aider+Pi controlplane harness.',
'Install via the ISO bundle or: npm install -g @earendil-works/pi-coding-agent; install Aider in a Python 3.12 venv if needed.',
'Alternative CLIs (claude, codex, gemini) are also accepted.',
].join(' '),
);
this.name = 'NoAgentCliError';
}
}
export function requireAtLeastOneAgentCli(): AgentCli[] {
const clis = detectAgentClis();
if (!clis.some((c) => c.present)) {
throw new NoAgentCliError();
}
return clis;
}