687
Oc
orc-code / files
orc-code / packages / plugin-claude / src / index.ts
1.0 KB
1import type { AgentEvent, AgentPlugin, AgentProcess, AgentSessionOpts } from "@orc-code/types"; 2import { checkCommand, spawnAgentProcess } from "@orc-code/types"; 3import { parseLine } from "./parser.js"; 4 5function extractSessionId(_raw: string, events: AgentEvent[]): string | null { 6 for (const event of events) { 7 if (event.type === "done") return event.sessionId; 8 } 9 return null; 10} 11 12const plugin: AgentPlugin = { 13 name: "claude", 14 command: "claude", 15 opts: ["-p", "--output-format", "stream-json", "--verbose", "--dangerously-skip-permissions"], 16 17 isAvailable: () => checkCommand("claude"), 18 19 createSession(prompt: string, opts?: AgentSessionOpts): AgentProcess { 20 return spawnAgentProcess( 21 "claude", 22 [...this.opts, prompt], 23 parseLine, 24 extractSessionId, 25 opts?.cwd, 26 ); 27 }, 28 29 resumeSession(sessionId: string, prompt: string, opts?: AgentSessionOpts): AgentProcess { 30 return spawnAgentProcess( 31 "claude", 32 [...this.opts, "--resume", sessionId, prompt], 33 parseLine, 34 extractSessionId, 35 opts?.cwd, 36 ); 37 }, 38}; 39 40export default plugin;