run-all.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. # With/without A/B (and optional interactive) eval for a codegraph version on a
  3. # repo. Codegraph is the ONLY variable: both arms launch claude with
  4. # --strict-mcp-config — with = codegraph-only MCP (pointed at $CG_BIN),
  5. # without = empty MCP. Built-in Read/Grep/Bash stay available in both arms.
  6. #
  7. # Usage: run-all.sh <repo-path> "<question>" [headless|tmux|all]
  8. # Env: CG_BIN codegraph binary (default: command -v codegraph)
  9. # AGENT_EVAL_OUT output dir (default: /tmp/agent-eval)
  10. # MODEL / EFFORT claude model/effort (default: sonnet / high — the
  11. # standing A/B policy; see CLAUDE.md, don't raise)
  12. set -uo pipefail
  13. REPO="${1:?usage: run-all.sh <repo-path> \"<question>\" [headless|tmux|all]}"
  14. Q="${2:?question required}"
  15. MODE="${3:-headless}"
  16. CG_BIN="${CG_BIN:-$(command -v codegraph)}"
  17. OUT="${AGENT_EVAL_OUT:-/tmp/agent-eval}"
  18. HARNESS="$(cd "$(dirname "$0")" && pwd)"
  19. mkdir -p "$OUT"
  20. # Neutralize any ambient CodeGraph prompt-hook (~/.claude) in BOTH arms:
  21. # the hook injects codegraph context into every prompt, which contaminates
  22. # the without-arm (free structural context) and double-counts the with-arm.
  23. # The A/B's only variable must be the MCP server wired below.
  24. export CODEGRAPH_NO_PROMPT_HOOK=1
  25. [ -n "$CG_BIN" ] || { echo "no codegraph binary on PATH (set CG_BIN)"; exit 1; }
  26. [ -d "$REPO/.codegraph" ] || { echo "no .codegraph index at $REPO — index it first"; exit 1; }
  27. case "$MODE" in headless|tmux|all) ;; *) echo "mode must be headless|tmux|all (got '$MODE')"; exit 1;; esac
  28. # MCP config files (path form avoids inline-JSON quoting through tmux).
  29. cat > "$OUT/mcp-codegraph.json" <<JSON
  30. {"mcpServers":{"codegraph":{"command":"$CG_BIN","args":["serve","--mcp","--path","$REPO"]}}}
  31. JSON
  32. echo '{"mcpServers":{}}' > "$OUT/mcp-empty.json"
  33. echo "###### codegraph: $CG_BIN"
  34. echo "###### repo: $REPO"
  35. echo "###### question: $Q"
  36. echo
  37. # Headless arm: claude -p with stream-json -> exact tool sequence + tokens/cost.
  38. headless() {
  39. local label="$1" cfg="$2"
  40. echo "############################## HEADLESS [$label] ##############################"
  41. ( cd "$REPO" && claude -p "$Q" \
  42. --output-format stream-json --verbose \
  43. --permission-mode bypassPermissions \
  44. --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" \
  45. --max-budget-usd 4 \
  46. --strict-mcp-config --mcp-config "$cfg" \
  47. > "$OUT/run-$label.jsonl" 2>"$OUT/run-$label.err" )
  48. echo "exit $? -> $OUT/run-$label.jsonl ($(wc -l < "$OUT/run-$label.jsonl" | tr -d ' ') lines)"
  49. tail -2 "$OUT/run-$label.err" 2>/dev/null
  50. node "$HARNESS/parse-run.mjs" "$OUT/run-$label.jsonl" 2>&1 || true
  51. echo
  52. }
  53. if [ "$MODE" = headless ] || [ "$MODE" = all ]; then
  54. headless "headless-with" "$OUT/mcp-codegraph.json"
  55. headless "headless-without" "$OUT/mcp-empty.json"
  56. fi
  57. if [ "$MODE" = tmux ] || [ "$MODE" = all ]; then
  58. echo "############################## INTERACTIVE [with] ##############################"
  59. CLAUDE_EXTRA_ARGS="--model ${MODEL:-sonnet} --effort ${EFFORT:-high} --strict-mcp-config --mcp-config $OUT/mcp-codegraph.json" \
  60. bash "$HARNESS/itrun.sh" "$REPO" "int-with" "$Q" 2>&1 || echo "[itrun WITH failed]"
  61. echo
  62. echo "############################## INTERACTIVE [without] ##############################"
  63. CLAUDE_EXTRA_ARGS="--model ${MODEL:-sonnet} --effort ${EFFORT:-high} --strict-mcp-config --mcp-config $OUT/mcp-empty.json" \
  64. bash "$HARNESS/itrun.sh" "$REPO" "int-without" "$Q" 2>&1 || echo "[itrun WITHOUT failed]"
  65. echo
  66. fi
  67. echo "############################## RUN-ALL COMPLETE ##############################"