homegraph 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +305 -305
  3. package/dist/bin/command-supervision.d.ts.map +1 -1
  4. package/dist/bin/command-supervision.js +7 -4
  5. package/dist/bin/command-supervision.js.map +1 -1
  6. package/dist/bin/homegraph.js +9 -9
  7. package/dist/db/index.js +36 -36
  8. package/dist/db/migrations.js +37 -37
  9. package/dist/db/queries.js +156 -156
  10. package/dist/db/schema.sql +203 -203
  11. package/dist/directory.js +5 -5
  12. package/dist/extraction/languages/arkts-viewtree.d.ts +2 -4
  13. package/dist/extraction/languages/arkts-viewtree.d.ts.map +1 -1
  14. package/dist/extraction/languages/arkts-viewtree.js +6 -21
  15. package/dist/extraction/languages/arkts-viewtree.js.map +1 -1
  16. package/dist/extraction/languages/arkts.d.ts +16 -6
  17. package/dist/extraction/languages/arkts.d.ts.map +1 -1
  18. package/dist/extraction/languages/arkts.js +174 -21
  19. package/dist/extraction/languages/arkts.js.map +1 -1
  20. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  21. package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
  22. package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
  23. package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
  24. package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  25. package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
  26. package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
  27. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  28. package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  29. package/dist/installer/instructions-template.js +9 -9
  30. package/dist/mcp/liveness-watchdog.d.ts +18 -0
  31. package/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  32. package/dist/mcp/liveness-watchdog.js +185 -73
  33. package/dist/mcp/liveness-watchdog.js.map +1 -1
  34. package/dist/mcp/server-instructions.js +47 -47
  35. package/dist/reasoning/reasoner.js +32 -32
  36. package/dist/spec/db/commit-node.js +4 -4
  37. package/dist/spec/db/fragment-node.js +10 -10
  38. package/dist/spec/db/fts.js +8 -8
  39. package/dist/spec/db/relations.js +88 -88
  40. package/dist/spec/db/schema.js +6 -6
  41. package/dist/spec/db/schema.sql +121 -121
  42. package/dist/spec/db/spec-node.js +4 -4
  43. package/dist/spec/llm/prompts.js +53 -53
  44. package/dist/spec/utils.d.ts +16 -4
  45. package/dist/spec/utils.d.ts.map +1 -1
  46. package/dist/spec/utils.js +58 -6
  47. package/dist/spec/utils.js.map +1 -1
  48. package/package.json +62 -62
  49. package/scripts/_tmp-cfwk-resolve.log +0 -0
  50. package/scripts/_tmp-cfwk-sig.log +0 -0
  51. package/scripts/_tmp-cfwk-vt.log +0 -0
  52. package/scripts/add-lang/bench.sh +60 -60
  53. package/scripts/add-lang/check-grammar.mjs +75 -75
  54. package/scripts/add-lang/dump-ast.mjs +103 -103
  55. package/scripts/add-lang/verify-extraction.mjs +70 -70
  56. package/scripts/agent-eval/ab-adoption.sh +91 -91
  57. package/scripts/agent-eval/ab-hook.sh +86 -86
  58. package/scripts/agent-eval/ab-impl.sh +78 -78
  59. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -102
  60. package/scripts/agent-eval/ab-sufficiency.sh +78 -78
  61. package/scripts/agent-eval/arms-F.sh +21 -21
  62. package/scripts/agent-eval/arms-matrix.sh +37 -37
  63. package/scripts/agent-eval/audit.sh +68 -68
  64. package/scripts/agent-eval/bench-readme.sh +28 -28
  65. package/scripts/agent-eval/bench-why-repo.sh +22 -22
  66. package/scripts/agent-eval/block-read-hook.sh +19 -19
  67. package/scripts/agent-eval/hook-settings.json +15 -15
  68. package/scripts/agent-eval/itrun.sh +120 -120
  69. package/scripts/agent-eval/offload-eval-3arm.sh +72 -72
  70. package/scripts/agent-eval/offload-eval-cost.mjs +133 -133
  71. package/scripts/agent-eval/offload-eval-effort.mjs +108 -108
  72. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -25
  73. package/scripts/agent-eval/offload-eval-frontload.sh +47 -47
  74. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -18
  75. package/scripts/agent-eval/offload-eval-hook.mjs +84 -84
  76. package/scripts/agent-eval/offload-eval-judge.mjs +103 -103
  77. package/scripts/agent-eval/offload-eval-matrix.sh +20 -20
  78. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -94
  79. package/scripts/agent-eval/offload-eval-refs1.sh +50 -50
  80. package/scripts/agent-eval/offload-eval-setup.sh +24 -24
  81. package/scripts/agent-eval/offload-eval-styles.sh +71 -71
  82. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -68
  83. package/scripts/agent-eval/offload-eval.md +76 -76
  84. package/scripts/agent-eval/parse-arms.mjs +116 -116
  85. package/scripts/agent-eval/parse-bench-readme.mjs +84 -84
  86. package/scripts/agent-eval/parse-run.mjs +45 -45
  87. package/scripts/agent-eval/parse-session.mjs +93 -93
  88. package/scripts/agent-eval/probe-context.mjs +21 -21
  89. package/scripts/agent-eval/probe-explore.mjs +40 -40
  90. package/scripts/agent-eval/probe-node.mjs +20 -20
  91. package/scripts/agent-eval/probe-sweep.mjs +119 -119
  92. package/scripts/agent-eval/probe-trace.mjs +20 -20
  93. package/scripts/agent-eval/redirect-read-hook.sh +38 -38
  94. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -119
  95. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -125
  96. package/scripts/agent-eval/run-agent.sh +34 -34
  97. package/scripts/agent-eval/run-all.sh +75 -75
  98. package/scripts/agent-eval/run-arms.sh +56 -56
  99. package/scripts/agent-eval/seq-matrix.mjs +137 -137
  100. package/scripts/bench-arkts-init-rss.log +0 -0
  101. package/scripts/build-bundle.sh +123 -123
  102. package/scripts/exp_boundary_eval/README.md +247 -247
  103. package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-310.pyc +0 -0
  104. package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-38.pyc +0 -0
  105. package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-310.pyc +0 -0
  106. package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-38.pyc +0 -0
  107. package/scripts/exp_boundary_eval/__pycache__/deveco_arm.cpython-38.pyc +0 -0
  108. package/scripts/exp_boundary_eval/__pycache__/run_all.cpython-310.pyc +0 -0
  109. package/scripts/exp_boundary_eval/__pycache__/run_all.cpython-38.pyc +0 -0
  110. package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-310.pyc +0 -0
  111. package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-38.pyc +0 -0
  112. package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-310.pyc +0 -0
  113. package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-38.pyc +0 -0
  114. package/scripts/exp_boundary_eval/__pycache__/setup.cpython-310.pyc +0 -0
  115. package/scripts/exp_boundary_eval/__pycache__/setup.cpython-38.pyc +0 -0
  116. package/scripts/exp_boundary_eval/__pycache__/win_mcp_launcher.cpython-38.pyc +0 -0
  117. package/scripts/exp_boundary_eval/_test_mcp_chain.py +78 -78
  118. package/scripts/exp_boundary_eval/_test_stdin.py +8 -8
  119. package/scripts/exp_boundary_eval/_utils.py +1116 -1116
  120. package/scripts/exp_boundary_eval/analyze.py +1313 -1313
  121. package/scripts/exp_boundary_eval/deveco_arm.py +519 -519
  122. package/scripts/exp_boundary_eval/run_all.py +378 -378
  123. package/scripts/exp_boundary_eval/run_one.py +165 -165
  124. package/scripts/exp_boundary_eval/run_session.py +158 -158
  125. package/scripts/exp_boundary_eval/setup.py +120 -120
  126. package/scripts/exp_boundary_eval/win_mcp_launcher.py +73 -73
  127. package/scripts/exp_boundary_eval/win_mcp_stdio_wrap.js +36 -36
  128. package/scripts/exp_boundary_eval/win_node_launcher.py +24 -24
  129. package/scripts/extract-release-notes.mjs +130 -130
  130. package/scripts/local-install.sh +41 -41
  131. package/scripts/npm-sdk.js +75 -75
  132. package/scripts/npm-shim.js +275 -275
  133. package/scripts/ohos-sdk-publish.mjs +133 -133
  134. package/scripts/pack-npm.sh +119 -119
  135. package/scripts/prepare-release.mjs +270 -270
  136. package/scripts/probe-arkts-mem-why-run.log +0 -0
  137. package/scripts/probe-banner-livecard-ir.log +0 -0
  138. package/scripts/probe-cfwk-ast.stderr.log +0 -0
  139. package/scripts/probe-cfwk-ast.stdout.log +0 -0
  140. package/scripts/probe-cfwk-attr-shape.log +0 -0
  141. package/scripts/probe-cfwk-cfgdump.stderr.log +0 -0
  142. package/scripts/probe-cfwk-cfgdump.stdout.log +0 -0
  143. package/scripts/probe-cfwk-cvc.stderr.log +0 -0
  144. package/scripts/probe-cfwk-cvc.stdout.log +0 -0
  145. package/scripts/probe-cfwk-diag2.log +0 -0
  146. package/scripts/probe-cfwk-diag3.log +0 -0
  147. package/scripts/probe-cfwk-fedbg.stderr.log +0 -0
  148. package/scripts/probe-cfwk-fedbg.stdout.log +0 -0
  149. package/scripts/probe-cfwk-fileresult.log +0 -0
  150. package/scripts/probe-cfwk-fix.stderr.log +0 -0
  151. package/scripts/probe-cfwk-fix.stdout.log +0 -0
  152. package/scripts/probe-cfwk-fix2.stderr.log +0 -0
  153. package/scripts/probe-cfwk-fix2.stdout.log +0 -0
  154. package/scripts/probe-cfwk-fix3.stderr.log +0 -0
  155. package/scripts/probe-cfwk-fix3.stdout.log +0 -0
  156. package/scripts/probe-cfwk-foreach.log +0 -0
  157. package/scripts/probe-cfwk-getmethod-throw.log +0 -0
  158. package/scripts/probe-cfwk-hg-extract.log +0 -0
  159. package/scripts/probe-cfwk-pr1003-noprior.stderr.log +0 -0
  160. package/scripts/probe-cfwk-pr1003-noprior.stdout.log +0 -0
  161. package/scripts/probe-cfwk-pr1003.stderr.log +0 -0
  162. package/scripts/probe-cfwk-pr1003.stdout.log +0 -0
  163. package/scripts/probe-cfwk-preroot-noprior.stderr.log +0 -0
  164. package/scripts/probe-cfwk-preroot-noprior.stdout.log +0 -0
  165. package/scripts/probe-cfwk-preroot-prior.stderr.log +0 -0
  166. package/scripts/probe-cfwk-preroot-prior.stdout.log +0 -0
  167. package/scripts/probe-cfwk-preroot-skipstate.stderr.log +0 -0
  168. package/scripts/probe-cfwk-preroot-skipstate.stdout.log +0 -0
  169. package/scripts/probe-cfwk-resolve-sim.log +0 -0
  170. package/scripts/probe-cfwk-tree-shape.log +0 -0
  171. package/scripts/probe-cfwk-walk-abort.log +0 -0
  172. package/scripts/probe-cfwk.log +0 -0
  173. package/scripts/probe-force-index.log +0 -0
  174. package/scripts/probe-no-force-index.log +0 -0
  175. package/scripts/probe-samefile-ir.stderr.log +0 -0
  176. package/scripts/probe-samefile-ir.stdout.log +224 -0
  177. package/scripts/probe-sdk-vs-project.log +0 -0
  178. package/scripts/probe-viewtree-downgrade.log +0 -0
  179. package/dist/arkts/ohos-api-index.d.ts +0 -15
  180. package/dist/arkts/ohos-api-index.d.ts.map +0 -1
  181. package/dist/arkts/ohos-api-index.js +0 -190
  182. package/dist/arkts/ohos-api-index.js.map +0 -1
  183. package/dist/arkts/ohos-sdk-input.d.ts +0 -36
  184. package/dist/arkts/ohos-sdk-input.d.ts.map +0 -1
  185. package/dist/arkts/ohos-sdk-input.js +0 -214
  186. package/dist/arkts/ohos-sdk-input.js.map +0 -1
  187. package/dist/extraction/languages/arkts-state-decorators.d.ts +0 -13
  188. package/dist/extraction/languages/arkts-state-decorators.d.ts.map +0 -1
  189. package/dist/extraction/languages/arkts-state-decorators.js +0 -26
  190. package/dist/extraction/languages/arkts-state-decorators.js.map +0 -1
  191. package/dist/extraction/languages/ohos-api-consumer.d.ts +0 -34
  192. package/dist/extraction/languages/ohos-api-consumer.d.ts.map +0 -1
  193. package/dist/extraction/languages/ohos-api-consumer.js +0 -283
  194. package/dist/extraction/languages/ohos-api-consumer.js.map +0 -1
  195. package/dist/spec/build/git-scanner.d.ts +0 -93
  196. package/dist/spec/build/git-scanner.d.ts.map +0 -1
  197. package/dist/spec/build/git-scanner.js +0 -254
  198. package/dist/spec/build/git-scanner.js.map +0 -1
  199. package/dist/spec/git-utils.d.ts +0 -8
  200. package/dist/spec/git-utils.d.ts.map +0 -1
  201. package/dist/spec/git-utils.js +0 -14
  202. package/dist/spec/git-utils.js.map +0 -1
  203. package/dist/spec/mine/clusterer.d.ts +0 -63
  204. package/dist/spec/mine/clusterer.d.ts.map +0 -1
  205. package/dist/spec/mine/clusterer.js +0 -904
  206. package/dist/spec/mine/clusterer.js.map +0 -1
  207. package/dist/spec/mine/progress-handler.d.ts +0 -22
  208. package/dist/spec/mine/progress-handler.d.ts.map +0 -1
  209. package/dist/spec/mine/progress-handler.js +0 -108
  210. package/dist/spec/mine/progress-handler.js.map +0 -1
  211. package/dist/spec/mine/progress.d.ts +0 -23
  212. package/dist/spec/mine/progress.d.ts.map +0 -1
  213. package/dist/spec/mine/progress.js +0 -12
  214. package/dist/spec/mine/progress.js.map +0 -1
@@ -1,91 +1,91 @@
1
- #!/usr/bin/env bash
2
- # Does the agent PICK homegraph_node to read a file, vs the built-in Read tool?
3
- # Build A/B: NEW build (HEAD, homegraph_node has Read parity) vs BASELINE build
4
- # (a ref where it doesn't), BOTH homegraph-attached + pre-warmed, same task. The
5
- # metric is tool CHOICE: Read calls vs homegraph_node[file] calls per run.
6
- #
7
- # Usage: ab-adoption.sh <indexed-repo> "<task>" [runs-per-arm] [baseline-ref]
8
- # Env: AGENT_EVAL_OUT (default: /tmp/ab-adoption)
9
- set -uo pipefail
10
- TARGET="${1:?usage: ab-adoption.sh <indexed-repo> \"<task>\" [runs] [baseline-ref]}"
11
- TASK="${2:?task required}"
12
- RUNS="${3:-2}"
13
- BASE_REF="${4:-HEAD~1}"
14
- ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
15
- BIN="$ENGINE/dist/bin/homegraph.js"
16
- OUT="${AGENT_EVAL_OUT:-/tmp/ab-adoption}"
17
-
18
- command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
19
- [ -d "$TARGET/.homegraph" ] || { echo "target not indexed: run 'homegraph init $TARGET' first"; exit 1; }
20
- git -C "$ENGINE" diff --quiet && git -C "$ENGINE" diff --cached --quiet || { echo "engine has uncommitted changes — commit/stash first"; exit 1; }
21
- CHANGED=$(git -C "$ENGINE" diff --name-only "$BASE_REF" HEAD -- src 2>/dev/null)
22
- [ -n "$CHANGED" ] || { echo "no src/ changes between $BASE_REF and HEAD"; exit 1; }
23
-
24
- cleanup() {
25
- pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null
26
- git -C "$ENGINE" checkout HEAD -- $CHANGED 2>/dev/null
27
- ( cd "$ENGINE" && npm run build >/dev/null 2>&1 )
28
- }
29
- trap cleanup EXIT
30
- mkdir -p "$OUT"
31
- echo "###### target=$TARGET runs/arm=$RUNS baseline=$BASE_REF"
32
- echo "###### changed: $(echo "$CHANGED" | tr '\n' ' ')"
33
- echo "###### task=$TASK"; echo
34
-
35
- prewarm() {
36
- pkill -9 -f "serve --mcp --path $1" 2>/dev/null
37
- HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
38
- node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
39
- }
40
-
41
- # Per-run tool-choice counts: Read vs homegraph_node[file] vs [symbol].
42
- count() {
43
- node -e '
44
- const fs=require("fs");
45
- const lines=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
46
- let read=0,cgFile=0,cgSym=0,cgOther=0,exposed="?";
47
- for(const l of lines){try{const o=JSON.parse(l);
48
- if(o.type==="system"&&o.subtype==="init"){exposed=(o.tools||[]).filter(t=>/homegraph/.test(t)).length;}
49
- const blocks=o.message?.content||[];
50
- for(const b of (Array.isArray(blocks)?blocks:[])){
51
- if(b.type!=="tool_use")continue;
52
- if(b.name==="Read")read++;
53
- else if(b.name==="mcp__homegraph__homegraph_node"){ if(b.input&&b.input.symbol)cgSym++; else cgFile++; }
54
- else if(/mcp__homegraph__/.test(b.name))cgOther++;
55
- }
56
- }catch{}}
57
- console.log(` Read=${read} homegraph_node[file]=${cgFile} homegraph_node[symbol]=${cgSym} other_cg=${cgOther} (cg exposed=${exposed})`);
58
- ' "$1"
59
- }
60
-
61
- run_arm() { # label, N
62
- local label="$1" n="$2"
63
- local c="$OUT/mcp-$label.json"
64
- for i in $(seq 1 "$n"); do
65
- local tgt="$OUT/t-$label-$i"
66
- rm -rf "$tgt"
67
- rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$TARGET/" "$tgt/"
68
- node "$BIN" init "$tgt" >/dev/null 2>&1
69
- printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
70
- prewarm "$tgt"
71
- echo "----- [$label] run $i -----"
72
- ( cd "$tgt" && claude -p "$TASK" \
73
- --output-format stream-json --verbose --permission-mode bypassPermissions \
74
- --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" \
75
- </dev/null > "$OUT/run-$label-$i.jsonl" 2>"$OUT/run-$label-$i.err" )
76
- count "$OUT/run-$label-$i.jsonl"
77
- pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
78
- done
79
- echo
80
- }
81
-
82
- echo "== NEW build (HEAD: homegraph_node has Read parity) =="
83
- ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
84
- run_arm new "$RUNS"
85
-
86
- echo "== BASELINE build ($BASE_REF) =="
87
- git -C "$ENGINE" checkout "$BASE_REF" -- $CHANGED
88
- ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
89
- run_arm baseline "$RUNS"
90
-
91
- echo "###### DONE — compare [new] vs [baseline]: does homegraph_node[file] rise / Read fall? Logs: $OUT"
1
+ #!/usr/bin/env bash
2
+ # Does the agent PICK homegraph_node to read a file, vs the built-in Read tool?
3
+ # Build A/B: NEW build (HEAD, homegraph_node has Read parity) vs BASELINE build
4
+ # (a ref where it doesn't), BOTH homegraph-attached + pre-warmed, same task. The
5
+ # metric is tool CHOICE: Read calls vs homegraph_node[file] calls per run.
6
+ #
7
+ # Usage: ab-adoption.sh <indexed-repo> "<task>" [runs-per-arm] [baseline-ref]
8
+ # Env: AGENT_EVAL_OUT (default: /tmp/ab-adoption)
9
+ set -uo pipefail
10
+ TARGET="${1:?usage: ab-adoption.sh <indexed-repo> \"<task>\" [runs] [baseline-ref]}"
11
+ TASK="${2:?task required}"
12
+ RUNS="${3:-2}"
13
+ BASE_REF="${4:-HEAD~1}"
14
+ ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
15
+ BIN="$ENGINE/dist/bin/homegraph.js"
16
+ OUT="${AGENT_EVAL_OUT:-/tmp/ab-adoption}"
17
+
18
+ command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
19
+ [ -d "$TARGET/.homegraph" ] || { echo "target not indexed: run 'homegraph init $TARGET' first"; exit 1; }
20
+ git -C "$ENGINE" diff --quiet && git -C "$ENGINE" diff --cached --quiet || { echo "engine has uncommitted changes — commit/stash first"; exit 1; }
21
+ CHANGED=$(git -C "$ENGINE" diff --name-only "$BASE_REF" HEAD -- src 2>/dev/null)
22
+ [ -n "$CHANGED" ] || { echo "no src/ changes between $BASE_REF and HEAD"; exit 1; }
23
+
24
+ cleanup() {
25
+ pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null
26
+ git -C "$ENGINE" checkout HEAD -- $CHANGED 2>/dev/null
27
+ ( cd "$ENGINE" && npm run build >/dev/null 2>&1 )
28
+ }
29
+ trap cleanup EXIT
30
+ mkdir -p "$OUT"
31
+ echo "###### target=$TARGET runs/arm=$RUNS baseline=$BASE_REF"
32
+ echo "###### changed: $(echo "$CHANGED" | tr '\n' ' ')"
33
+ echo "###### task=$TASK"; echo
34
+
35
+ prewarm() {
36
+ pkill -9 -f "serve --mcp --path $1" 2>/dev/null
37
+ HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
38
+ node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
39
+ }
40
+
41
+ # Per-run tool-choice counts: Read vs homegraph_node[file] vs [symbol].
42
+ count() {
43
+ node -e '
44
+ const fs=require("fs");
45
+ const lines=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
46
+ let read=0,cgFile=0,cgSym=0,cgOther=0,exposed="?";
47
+ for(const l of lines){try{const o=JSON.parse(l);
48
+ if(o.type==="system"&&o.subtype==="init"){exposed=(o.tools||[]).filter(t=>/homegraph/.test(t)).length;}
49
+ const blocks=o.message?.content||[];
50
+ for(const b of (Array.isArray(blocks)?blocks:[])){
51
+ if(b.type!=="tool_use")continue;
52
+ if(b.name==="Read")read++;
53
+ else if(b.name==="mcp__homegraph__homegraph_node"){ if(b.input&&b.input.symbol)cgSym++; else cgFile++; }
54
+ else if(/mcp__homegraph__/.test(b.name))cgOther++;
55
+ }
56
+ }catch{}}
57
+ console.log(` Read=${read} homegraph_node[file]=${cgFile} homegraph_node[symbol]=${cgSym} other_cg=${cgOther} (cg exposed=${exposed})`);
58
+ ' "$1"
59
+ }
60
+
61
+ run_arm() { # label, N
62
+ local label="$1" n="$2"
63
+ local c="$OUT/mcp-$label.json"
64
+ for i in $(seq 1 "$n"); do
65
+ local tgt="$OUT/t-$label-$i"
66
+ rm -rf "$tgt"
67
+ rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$TARGET/" "$tgt/"
68
+ node "$BIN" init "$tgt" >/dev/null 2>&1
69
+ printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
70
+ prewarm "$tgt"
71
+ echo "----- [$label] run $i -----"
72
+ ( cd "$tgt" && claude -p "$TASK" \
73
+ --output-format stream-json --verbose --permission-mode bypassPermissions \
74
+ --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" \
75
+ </dev/null > "$OUT/run-$label-$i.jsonl" 2>"$OUT/run-$label-$i.err" )
76
+ count "$OUT/run-$label-$i.jsonl"
77
+ pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
78
+ done
79
+ echo
80
+ }
81
+
82
+ echo "== NEW build (HEAD: homegraph_node has Read parity) =="
83
+ ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
84
+ run_arm new "$RUNS"
85
+
86
+ echo "== BASELINE build ($BASE_REF) =="
87
+ git -C "$ENGINE" checkout "$BASE_REF" -- $CHANGED
88
+ ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
89
+ run_arm baseline "$RUNS"
90
+
91
+ echo "###### DONE — compare [new] vs [baseline]: does homegraph_node[file] rise / Read fall? Logs: $OUT"
@@ -1,86 +1,86 @@
1
- #!/usr/bin/env bash
2
- # A/B the PreToolUse(Read) REDIRECT hook (P1): does steering Read → homegraph_node
3
- # file-view actually move the agent off Read during implementation? BOTH arms use
4
- # the CURRENT build with homegraph attached and pre-warmed; the only difference is
5
- # the hook. Isolates the hook's behavioral effect from the build/file-view change
6
- # (use ab-new-vs-baseline.sh for the build A/B).
7
- #
8
- # arm [nohook] — homegraph on, no hook (does the better file-view get picked on its own?)
9
- # arm [hook] — homegraph on, + redirect hook (does routing close it?)
10
- #
11
- # Reliable attach (works nested): each arm pre-warms a persistent daemon and skips
12
- # the startup re-exec (HOMEGRAPH_WASM_RELAUNCHED=1), so claude connects before the
13
- # agent's first turn. Judge by ACTUAL homegraph usage in parse-run.mjs's "by type",
14
- # not claude's init snapshot (which can read pending even when it then connects).
15
- #
16
- # Usage: ab-hook.sh <indexed-repo> "<implementation task>" [runs-per-arm]
17
- # <indexed-repo> a repo with a .homegraph index (copied per arm; never mutated)
18
- # "<task>" a GENUINELY-NEW implementation task (verify it isn't already done)
19
- # [runs-per-arm] default 2 (n=1 is noisy — the doctrine says >=2)
20
- # Env: AGENT_EVAL_OUT (default: /tmp/ab-hook)
21
- set -uo pipefail
22
-
23
- TARGET="${1:?usage: ab-hook.sh <indexed-repo> \"<task>\" [runs-per-arm]}"
24
- TASK="${2:?task required}"
25
- RUNS="${3:-2}"
26
- ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
27
- BIN="$ENGINE/dist/bin/homegraph.js"
28
- HOOK="$ENGINE/scripts/agent-eval/redirect-read-hook.sh"
29
- OUT="${AGENT_EVAL_OUT:-/tmp/ab-hook}"
30
- PARSE="$ENGINE/scripts/agent-eval/parse-run.mjs"
31
-
32
- command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
33
- command -v jq >/dev/null || { echo "jq not on PATH (the hook needs it)"; exit 1; }
34
- [ -d "$TARGET/.homegraph" ] || { echo "target not indexed: run 'homegraph init $TARGET' first"; exit 1; }
35
- chmod +x "$HOOK"
36
-
37
- cleanup() { pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
38
- trap cleanup EXIT
39
-
40
- mkdir -p "$OUT"
41
- echo "###### engine=$ENGINE"
42
- echo "###### target=$TARGET runs/arm=$RUNS"
43
- echo "###### task=$TASK"
44
- echo
45
-
46
- ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
47
-
48
- # A settings file carrying ONLY the PreToolUse(Read) redirect hook.
49
- HOOK_SETTINGS="$OUT/hook-settings.json"
50
- jq -n --arg cmd "bash $HOOK" \
51
- '{hooks:{PreToolUse:[{matcher:"Read",hooks:[{type:"command",command:$cmd}]}]}}' > "$HOOK_SETTINGS"
52
-
53
- prewarm() { # target — spawn a persistent daemon and wait for its socket
54
- pkill -9 -f "serve --mcp --path $1" 2>/dev/null
55
- HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
56
- node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" \
57
- && echo " daemon warm: $1" || echo " WARN: daemon never bound for $1"
58
- }
59
-
60
- run_one() { # arm-label, run-index, use-hook(0|1)
61
- local label="$1" idx="$2" hook="$3"
62
- local tgt="$OUT/t-$label-$idx" c="$OUT/mcp-$label.json"
63
- rm -rf "$tgt"
64
- rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$TARGET/" "$tgt/"
65
- node "$BIN" init "$tgt" >/dev/null 2>&1
66
- printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
67
- prewarm "$tgt"
68
- local extra=()
69
- [ "$hook" = "1" ] && extra=(--settings "$HOOK_SETTINGS")
70
- echo "----- [$label] run $idx -----"
71
- # ${extra[@]+...} guard: bash 3.2 (macOS) under `set -u` errors on an empty
72
- # array expansion otherwise, which would skip the no-hook arm's claude run.
73
- ( cd "$tgt" && claude -p "$TASK" \
74
- --output-format stream-json --verbose --permission-mode bypassPermissions \
75
- --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" ${extra[@]+"${extra[@]}"} \
76
- </dev/null > "$OUT/run-$label-$idx.jsonl" 2>"$OUT/run-$label-$idx.err" )
77
- node "$PARSE" "$OUT/run-$label-$idx.jsonl" 2>&1 | grep -E "by type|Result" || echo " (parse failed — see $OUT/run-$label-$idx.jsonl)"
78
- pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
79
- echo
80
- }
81
-
82
- for i in $(seq 1 "$RUNS"); do run_one nohook "$i" 0; done
83
- for i in $(seq 1 "$RUNS"); do run_one hook "$i" 1; done
84
-
85
- echo "###### DONE. Compare [nohook] vs [hook] 'by type' — Read should fall and"
86
- echo "###### mcp__homegraph__homegraph_node should rise in the [hook] arm. Logs: $OUT"
1
+ #!/usr/bin/env bash
2
+ # A/B the PreToolUse(Read) REDIRECT hook (P1): does steering Read → homegraph_node
3
+ # file-view actually move the agent off Read during implementation? BOTH arms use
4
+ # the CURRENT build with homegraph attached and pre-warmed; the only difference is
5
+ # the hook. Isolates the hook's behavioral effect from the build/file-view change
6
+ # (use ab-new-vs-baseline.sh for the build A/B).
7
+ #
8
+ # arm [nohook] — homegraph on, no hook (does the better file-view get picked on its own?)
9
+ # arm [hook] — homegraph on, + redirect hook (does routing close it?)
10
+ #
11
+ # Reliable attach (works nested): each arm pre-warms a persistent daemon and skips
12
+ # the startup re-exec (HOMEGRAPH_WASM_RELAUNCHED=1), so claude connects before the
13
+ # agent's first turn. Judge by ACTUAL homegraph usage in parse-run.mjs's "by type",
14
+ # not claude's init snapshot (which can read pending even when it then connects).
15
+ #
16
+ # Usage: ab-hook.sh <indexed-repo> "<implementation task>" [runs-per-arm]
17
+ # <indexed-repo> a repo with a .homegraph index (copied per arm; never mutated)
18
+ # "<task>" a GENUINELY-NEW implementation task (verify it isn't already done)
19
+ # [runs-per-arm] default 2 (n=1 is noisy — the doctrine says >=2)
20
+ # Env: AGENT_EVAL_OUT (default: /tmp/ab-hook)
21
+ set -uo pipefail
22
+
23
+ TARGET="${1:?usage: ab-hook.sh <indexed-repo> \"<task>\" [runs-per-arm]}"
24
+ TASK="${2:?task required}"
25
+ RUNS="${3:-2}"
26
+ ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
27
+ BIN="$ENGINE/dist/bin/homegraph.js"
28
+ HOOK="$ENGINE/scripts/agent-eval/redirect-read-hook.sh"
29
+ OUT="${AGENT_EVAL_OUT:-/tmp/ab-hook}"
30
+ PARSE="$ENGINE/scripts/agent-eval/parse-run.mjs"
31
+
32
+ command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
33
+ command -v jq >/dev/null || { echo "jq not on PATH (the hook needs it)"; exit 1; }
34
+ [ -d "$TARGET/.homegraph" ] || { echo "target not indexed: run 'homegraph init $TARGET' first"; exit 1; }
35
+ chmod +x "$HOOK"
36
+
37
+ cleanup() { pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
38
+ trap cleanup EXIT
39
+
40
+ mkdir -p "$OUT"
41
+ echo "###### engine=$ENGINE"
42
+ echo "###### target=$TARGET runs/arm=$RUNS"
43
+ echo "###### task=$TASK"
44
+ echo
45
+
46
+ ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
47
+
48
+ # A settings file carrying ONLY the PreToolUse(Read) redirect hook.
49
+ HOOK_SETTINGS="$OUT/hook-settings.json"
50
+ jq -n --arg cmd "bash $HOOK" \
51
+ '{hooks:{PreToolUse:[{matcher:"Read",hooks:[{type:"command",command:$cmd}]}]}}' > "$HOOK_SETTINGS"
52
+
53
+ prewarm() { # target — spawn a persistent daemon and wait for its socket
54
+ pkill -9 -f "serve --mcp --path $1" 2>/dev/null
55
+ HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
56
+ node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" \
57
+ && echo " daemon warm: $1" || echo " WARN: daemon never bound for $1"
58
+ }
59
+
60
+ run_one() { # arm-label, run-index, use-hook(0|1)
61
+ local label="$1" idx="$2" hook="$3"
62
+ local tgt="$OUT/t-$label-$idx" c="$OUT/mcp-$label.json"
63
+ rm -rf "$tgt"
64
+ rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$TARGET/" "$tgt/"
65
+ node "$BIN" init "$tgt" >/dev/null 2>&1
66
+ printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
67
+ prewarm "$tgt"
68
+ local extra=()
69
+ [ "$hook" = "1" ] && extra=(--settings "$HOOK_SETTINGS")
70
+ echo "----- [$label] run $idx -----"
71
+ # ${extra[@]+...} guard: bash 3.2 (macOS) under `set -u` errors on an empty
72
+ # array expansion otherwise, which would skip the no-hook arm's claude run.
73
+ ( cd "$tgt" && claude -p "$TASK" \
74
+ --output-format stream-json --verbose --permission-mode bypassPermissions \
75
+ --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" ${extra[@]+"${extra[@]}"} \
76
+ </dev/null > "$OUT/run-$label-$idx.jsonl" 2>"$OUT/run-$label-$idx.err" )
77
+ node "$PARSE" "$OUT/run-$label-$idx.jsonl" 2>&1 | grep -E "by type|Result" || echo " (parse failed — see $OUT/run-$label-$idx.jsonl)"
78
+ pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
79
+ echo
80
+ }
81
+
82
+ for i in $(seq 1 "$RUNS"); do run_one nohook "$i" 0; done
83
+ for i in $(seq 1 "$RUNS"); do run_one hook "$i" 1; done
84
+
85
+ echo "###### DONE. Compare [nohook] vs [hook] 'by type' — Read should fall and"
86
+ echo "###### mcp__homegraph__homegraph_node should rise in the [hook] arm. Logs: $OUT"
@@ -1,78 +1,78 @@
1
- #!/usr/bin/env bash
2
- # Sufficiency A/B for an IMPLEMENTATION task (the agent edits): when it uses
3
- # homegraph (explore/node) to understand before editing, does it still Read? Like
4
- # ab-sufficiency.sh but copies+indexes a FRESH target per run (the agent mutates
5
- # it), so runs don't see each other's edits.
6
- #
7
- # WITH homegraph (pre-warmed) vs WITHOUT (empty MCP), N runs each. Reports
8
- # explore/node vs Read/Grep + the files Read, and whether the build still passes.
9
- #
10
- # Usage: ab-impl.sh <indexed-repo> "<task>" [runs] [build-cmd]
11
- # Env: AGENT_EVAL_OUT (default: /tmp/ab-impl)
12
- set -uo pipefail
13
- REPO="${1:?usage: ab-impl.sh <indexed-repo> \"<task>\" [runs] [build-cmd]}"
14
- Q="${2:?task required}"
15
- RUNS="${3:-2}"
16
- BUILD_CMD="${4:-}"
17
- ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
18
- BIN="$ENGINE/dist/bin/homegraph.js"
19
- OUT="${AGENT_EVAL_OUT:-/tmp/ab-impl}"
20
- command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
21
- [ -d "$REPO/.homegraph" ] || { echo "no .homegraph index at $REPO"; exit 1; }
22
- cleanup(){ pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
23
- trap cleanup EXIT
24
- mkdir -p "$OUT"
25
- ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built engine"
26
- echo "###### repo=$REPO runs/arm=$RUNS"
27
- echo "###### task=$Q"; echo
28
- echo '{"mcpServers":{}}' > "$OUT/mcp-empty.json"
29
-
30
- prewarm(){
31
- pkill -9 -f "serve --mcp --path $1" 2>/dev/null
32
- HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
33
- node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
34
- }
35
-
36
- analyze(){
37
- node -e '
38
- const fs=require("fs");
39
- const L=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
40
- let ex=0,nf=0,ns=0,oc=0,gr=0,ed=0,exposed="?";const reads=[];
41
- for(const l of L){try{const o=JSON.parse(l);
42
- if(o.type==="system"&&o.subtype==="init")exposed=(o.tools||[]).filter(t=>/homegraph/.test(t)).length;
43
- for(const b of (o.message?.content||[])){if(b.type!=="tool_use")continue;
44
- if(b.name==="mcp__homegraph__homegraph_explore")ex++;
45
- else if(b.name==="mcp__homegraph__homegraph_node"){if(b.input&&b.input.symbol)ns++;else nf++;}
46
- else if(/mcp__homegraph__/.test(b.name))oc++;
47
- else if(b.name==="Read")reads.push((b.input?.file_path||"").split("/").pop());
48
- else if(b.name==="Grep")gr++;
49
- else if(b.name==="Edit"||b.name==="Write")ed++;
50
- }}catch{}}
51
- console.log(` explore=${ex} node[sym]=${ns} node[file]=${nf} other_cg=${oc} | Read=${reads.length}${reads.length?" ("+reads.join(", ")+")":""} Grep=${gr} Edit=${ed} [cg exposed=${exposed}]`);
52
- ' "$1"
53
- }
54
-
55
- run(){ # label, withCodegraph(0/1)
56
- local label="$1" wcg="$2"
57
- for i in $(seq 1 "$RUNS"); do
58
- local tgt="$OUT/t-$label-$i" cfg="$OUT/mcp-$label.json"
59
- rm -rf "$tgt"
60
- rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$REPO/" "$tgt/"
61
- node "$BIN" init "$tgt" >/dev/null 2>&1
62
- if [ "$wcg" = "1" ]; then
63
- printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$cfg"
64
- prewarm "$tgt"
65
- else cp "$OUT/mcp-empty.json" "$cfg"; fi
66
- ( cd "$tgt" && claude -p "$Q" --output-format stream-json --verbose \
67
- --permission-mode bypassPermissions --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 \
68
- --strict-mcp-config --mcp-config "$cfg" </dev/null > "$OUT/$label-$i.jsonl" 2>"$OUT/$label-$i.err" )
69
- echo "[$label] run $i:"; analyze "$OUT/$label-$i.jsonl"
70
- if [ -n "$BUILD_CMD" ]; then ( cd "$tgt" && eval "$BUILD_CMD" >/dev/null 2>&1 && echo " build: PASS" || echo " build: FAIL" ); fi
71
- pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
72
- done
73
- echo
74
- }
75
-
76
- echo "== WITH homegraph =="; run with 1
77
- echo "== WITHOUT (Read/Grep only) =="; run without 0
78
- echo "###### DONE: $OUT"
1
+ #!/usr/bin/env bash
2
+ # Sufficiency A/B for an IMPLEMENTATION task (the agent edits): when it uses
3
+ # homegraph (explore/node) to understand before editing, does it still Read? Like
4
+ # ab-sufficiency.sh but copies+indexes a FRESH target per run (the agent mutates
5
+ # it), so runs don't see each other's edits.
6
+ #
7
+ # WITH homegraph (pre-warmed) vs WITHOUT (empty MCP), N runs each. Reports
8
+ # explore/node vs Read/Grep + the files Read, and whether the build still passes.
9
+ #
10
+ # Usage: ab-impl.sh <indexed-repo> "<task>" [runs] [build-cmd]
11
+ # Env: AGENT_EVAL_OUT (default: /tmp/ab-impl)
12
+ set -uo pipefail
13
+ REPO="${1:?usage: ab-impl.sh <indexed-repo> \"<task>\" [runs] [build-cmd]}"
14
+ Q="${2:?task required}"
15
+ RUNS="${3:-2}"
16
+ BUILD_CMD="${4:-}"
17
+ ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
18
+ BIN="$ENGINE/dist/bin/homegraph.js"
19
+ OUT="${AGENT_EVAL_OUT:-/tmp/ab-impl}"
20
+ command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
21
+ [ -d "$REPO/.homegraph" ] || { echo "no .homegraph index at $REPO"; exit 1; }
22
+ cleanup(){ pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
23
+ trap cleanup EXIT
24
+ mkdir -p "$OUT"
25
+ ( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built engine"
26
+ echo "###### repo=$REPO runs/arm=$RUNS"
27
+ echo "###### task=$Q"; echo
28
+ echo '{"mcpServers":{}}' > "$OUT/mcp-empty.json"
29
+
30
+ prewarm(){
31
+ pkill -9 -f "serve --mcp --path $1" 2>/dev/null
32
+ HOMEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
33
+ node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.homegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
34
+ }
35
+
36
+ analyze(){
37
+ node -e '
38
+ const fs=require("fs");
39
+ const L=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
40
+ let ex=0,nf=0,ns=0,oc=0,gr=0,ed=0,exposed="?";const reads=[];
41
+ for(const l of L){try{const o=JSON.parse(l);
42
+ if(o.type==="system"&&o.subtype==="init")exposed=(o.tools||[]).filter(t=>/homegraph/.test(t)).length;
43
+ for(const b of (o.message?.content||[])){if(b.type!=="tool_use")continue;
44
+ if(b.name==="mcp__homegraph__homegraph_explore")ex++;
45
+ else if(b.name==="mcp__homegraph__homegraph_node"){if(b.input&&b.input.symbol)ns++;else nf++;}
46
+ else if(/mcp__homegraph__/.test(b.name))oc++;
47
+ else if(b.name==="Read")reads.push((b.input?.file_path||"").split("/").pop());
48
+ else if(b.name==="Grep")gr++;
49
+ else if(b.name==="Edit"||b.name==="Write")ed++;
50
+ }}catch{}}
51
+ console.log(` explore=${ex} node[sym]=${ns} node[file]=${nf} other_cg=${oc} | Read=${reads.length}${reads.length?" ("+reads.join(", ")+")":""} Grep=${gr} Edit=${ed} [cg exposed=${exposed}]`);
52
+ ' "$1"
53
+ }
54
+
55
+ run(){ # label, withCodegraph(0/1)
56
+ local label="$1" wcg="$2"
57
+ for i in $(seq 1 "$RUNS"); do
58
+ local tgt="$OUT/t-$label-$i" cfg="$OUT/mcp-$label.json"
59
+ rm -rf "$tgt"
60
+ rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .homegraph "$REPO/" "$tgt/"
61
+ node "$BIN" init "$tgt" >/dev/null 2>&1
62
+ if [ "$wcg" = "1" ]; then
63
+ printf '{"mcpServers":{"homegraph":{"command":"env","args":["HOMEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$cfg"
64
+ prewarm "$tgt"
65
+ else cp "$OUT/mcp-empty.json" "$cfg"; fi
66
+ ( cd "$tgt" && claude -p "$Q" --output-format stream-json --verbose \
67
+ --permission-mode bypassPermissions --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 \
68
+ --strict-mcp-config --mcp-config "$cfg" </dev/null > "$OUT/$label-$i.jsonl" 2>"$OUT/$label-$i.err" )
69
+ echo "[$label] run $i:"; analyze "$OUT/$label-$i.jsonl"
70
+ if [ -n "$BUILD_CMD" ]; then ( cd "$tgt" && eval "$BUILD_CMD" >/dev/null 2>&1 && echo " build: PASS" || echo " build: FAIL" ); fi
71
+ pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
72
+ done
73
+ echo
74
+ }
75
+
76
+ echo "== WITH homegraph =="; run with 1
77
+ echo "== WITHOUT (Read/Grep only) =="; run without 0
78
+ echo "###### DONE: $OUT"