fable-agent/src/core/claude-cli-caller.ts

19 lines
602 B
TypeScript

/**
* Claude CLI Caller — shells out to the local Claude CLI with the prompt on stdin.
* Uses Claude Code desktop auth; no API key required.
*/
import { runCli } from "./cli-runner.js";
export async function callClaudeCli(model: string, prompt: string): Promise<string> {
if (!/^[a-zA-Z0-9._-]+$/.test(model)) {
throw new Error(`callClaudeCli: unsafe model id "${model}"`);
}
const result = await runCli("claude", ["--print", "--model", model], 120_000, {
stdin: prompt,
windowsCmdShim: true,
});
if (result.startsWith("[CLI ")) throw new Error(result);
return result;
}