import { parseArgs } from "@earendil-works/pi-coding-agent"; export const AGENT_FLAG = "pp-agent"; export const AGENT_CHECK_FLAG = "pp-agent-check"; export interface CliModelRequest { model: string; provider?: string; thinking?: string; } /** * The model pi was started with (`--model`, `--provider`, `--thinking`), read * from pi's own command line: pi gives an extension no other way to tell a * model someone asked for from one it picked by default. Apps that drive pi * (bb, scripts) choose the model this way. */ export function cliModelRequest(argv: readonly string[] = process.argv.slice(2)): CliModelRequest | null { let parsed: ReturnType; try { parsed = parseArgs([...argv]); } catch { return null; } if (!parsed.model) return null; return { model: parsed.model, provider: parsed.provider, thinking: parsed.thinking }; } /** * The pi-pi agent pi was started as (`--pp-agent `), read from pi's own * command line like the model: the extension decides what to register before * pi hands it flag values. A flag given without a role reads as ""; * `--pp-agent-check` asks only whether the agent can run. */ export function cliAgentRequest(argv: readonly string[] = process.argv.slice(2)): { role: string; check: boolean } | null { let parsed: ReturnType; try { parsed = parseArgs([...argv]); } catch { return null; } const value = parsed.unknownFlags.get(AGENT_FLAG); if (value === undefined) return null; return { role: typeof value === "string" ? value : "", check: parsed.unknownFlags.has(AGENT_CHECK_FLAG) }; }