1
0

run-agent.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. # Headless Claude Code run against a repo with codegraph MCP, capturing the
  3. # full stream-json so we can see tool calls + token usage. Complements the
  4. # interactive itrun.sh: headless gives a clean per-tool breakdown + exact
  5. # tokens/cost, but defaults to the general-purpose subagent (not Explore).
  6. # To force the Explore path, ask for it in the prompt.
  7. #
  8. # Usage: run-agent.sh <repo-path> <label> "<prompt>"
  9. # Env: AGENT_EVAL_OUT (default /tmp/agent-eval), CG_BIN (codegraph dist binary)
  10. set -uo pipefail
  11. REPO="$1"; LABEL="$2"; PROMPT="$3"
  12. CG_BIN="${CG_BIN:-$(command -v codegraph || echo /usr/local/bin/codegraph)}"
  13. OUT_DIR="${AGENT_EVAL_OUT:-/tmp/agent-eval}"; mkdir -p "$OUT_DIR"
  14. OUT="$OUT_DIR/run-${LABEL}.jsonl"
  15. MCP_CONFIG=$(cat <<JSON
  16. {"mcpServers":{"codegraph":{"command":"${CG_BIN}","args":["serve","--mcp","--path","${REPO}"]}}}
  17. JSON
  18. )
  19. echo "→ running [$LABEL] in $REPO"
  20. cd "$REPO" || exit 1
  21. claude -p "$PROMPT" \
  22. --output-format stream-json --verbose \
  23. --permission-mode bypassPermissions \
  24. --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" \
  25. --max-budget-usd 2 \
  26. --strict-mcp-config --mcp-config "$MCP_CONFIG" \
  27. > "$OUT" 2>"$OUT_DIR/run-${LABEL}.err"
  28. echo "exit: $? | wrote $OUT ($(wc -l < "$OUT") lines)"
  29. node "$(cd "$(dirname "$0")" && pwd)/parse-run.mjs" "$OUT" 2>/dev/null || true