| 278 | |
| 279 | |
| 280 | def run_agent(agent: str, prompt: str) -> str: |
| 281 | if agent == "codex": |
| 282 | if not _which("codex"): |
| 283 | raise SystemExit("codex CLI not found in PATH") |
| 284 | cmd = ["codex", "exec", "--skip-git-repo-check", "-"] |
| 285 | log.info("invoking %s ...", " ".join(cmd)) |
| 286 | proc = subprocess.run(cmd, input=prompt, capture_output=True, text=True) |
| 287 | elif agent == "claude": |
| 288 | if not _which("claude"): |
| 289 | raise SystemExit("claude CLI not found in PATH") |
| 290 | cmd = ["claude", "-p", prompt] |
| 291 | log.info("invoking claude -p (prompt elided) ...") |
| 292 | proc = subprocess.run(cmd, capture_output=True, text=True) |
| 293 | else: |
| 294 | raise SystemExit(f"unknown agent: {agent}") |
| 295 | |
| 296 | if proc.returncode != 0: |
| 297 | sys.stderr.write(proc.stderr) |
| 298 | raise SystemExit(f"{agent} exited {proc.returncode}") |
| 299 | if proc.stderr.strip(): |
| 300 | sys.stderr.write(proc.stderr) |
| 301 | return proc.stdout |
| 302 | |
| 303 | |
| 304 | # --- CLI -------------------------------------------------------------------- |