MCPcopy Create free account
hub / github.com/idank/explainshell / run_agent

Function run_agent

tools/scan_bot_traffic.py:280–301  ·  view source on GitHub ↗
(agent: str, prompt: str)

Source from the content-addressed store, hash-verified

278
279
280def 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 --------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 1

_whichFunction · 0.85

Tested by

no test coverage detected