homegraph 1.1.2 → 1.1.3

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 (175) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +243 -243
  3. package/dist/bin/homegraph.js +371 -9
  4. package/dist/bin/homegraph.js.map +1 -1
  5. package/dist/db/migrations.js +18 -18
  6. package/dist/db/queries.js +140 -140
  7. package/dist/db/schema.sql +152 -152
  8. package/dist/directory.js +5 -5
  9. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  10. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  11. package/dist/installer/instructions-template.js +9 -9
  12. package/dist/installer/targets/shared.d.ts +5 -6
  13. package/dist/installer/targets/shared.d.ts.map +1 -1
  14. package/dist/installer/targets/shared.js +5 -6
  15. package/dist/installer/targets/shared.js.map +1 -1
  16. package/dist/mcp/liveness-watchdog.js +16 -16
  17. package/dist/mcp/server-instructions.js +69 -69
  18. package/dist/mcp/tools.d.ts +17 -4
  19. package/dist/mcp/tools.d.ts.map +1 -1
  20. package/dist/mcp/tools.js +192 -22
  21. package/dist/mcp/tools.js.map +1 -1
  22. package/dist/reasoning/reasoner.js +32 -32
  23. package/dist/spec/config.d.ts +43 -0
  24. package/dist/spec/config.d.ts.map +1 -0
  25. package/dist/spec/config.js +275 -0
  26. package/dist/spec/config.js.map +1 -0
  27. package/dist/spec/db/commit-node.d.ts +23 -0
  28. package/dist/spec/db/commit-node.d.ts.map +1 -0
  29. package/dist/spec/db/commit-node.js +62 -0
  30. package/dist/spec/db/commit-node.js.map +1 -0
  31. package/dist/spec/db/fragment-node.d.ts +23 -0
  32. package/dist/spec/db/fragment-node.d.ts.map +1 -0
  33. package/dist/spec/db/fragment-node.js +120 -0
  34. package/dist/spec/db/fragment-node.js.map +1 -0
  35. package/dist/spec/db/fts.d.ts +60 -0
  36. package/dist/spec/db/fts.d.ts.map +1 -0
  37. package/dist/spec/db/fts.js +285 -0
  38. package/dist/spec/db/fts.js.map +1 -0
  39. package/dist/spec/db/index.d.ts +13 -0
  40. package/dist/spec/db/index.d.ts.map +1 -0
  41. package/dist/spec/db/index.js +50 -0
  42. package/dist/spec/db/index.js.map +1 -0
  43. package/dist/spec/db/relations.d.ts +55 -0
  44. package/dist/spec/db/relations.d.ts.map +1 -0
  45. package/dist/spec/db/relations.js +158 -0
  46. package/dist/spec/db/relations.js.map +1 -0
  47. package/dist/spec/db/schema.d.ts +30 -0
  48. package/dist/spec/db/schema.d.ts.map +1 -0
  49. package/dist/spec/db/schema.js +87 -0
  50. package/dist/spec/db/schema.js.map +1 -0
  51. package/dist/spec/db/schema.sql +107 -0
  52. package/dist/spec/db/spec-node.d.ts +41 -0
  53. package/dist/spec/db/spec-node.d.ts.map +1 -0
  54. package/dist/spec/db/spec-node.js +114 -0
  55. package/dist/spec/db/spec-node.js.map +1 -0
  56. package/dist/spec/evolve/impact-locator.d.ts +13 -0
  57. package/dist/spec/evolve/impact-locator.d.ts.map +1 -0
  58. package/dist/spec/evolve/impact-locator.js +25 -0
  59. package/dist/spec/evolve/impact-locator.js.map +1 -0
  60. package/dist/spec/evolve/llm-client.d.ts +50 -0
  61. package/dist/spec/evolve/llm-client.d.ts.map +1 -0
  62. package/dist/spec/evolve/llm-client.js +176 -0
  63. package/dist/spec/evolve/llm-client.js.map +1 -0
  64. package/dist/spec/evolve/logic-checker.d.ts +12 -0
  65. package/dist/spec/evolve/logic-checker.d.ts.map +1 -0
  66. package/dist/spec/evolve/logic-checker.js +48 -0
  67. package/dist/spec/evolve/logic-checker.js.map +1 -0
  68. package/dist/spec/evolve/pipeline.d.ts +40 -0
  69. package/dist/spec/evolve/pipeline.d.ts.map +1 -0
  70. package/dist/spec/evolve/pipeline.js +314 -0
  71. package/dist/spec/evolve/pipeline.js.map +1 -0
  72. package/dist/spec/evolve/spec-rewriter.d.ts +42 -0
  73. package/dist/spec/evolve/spec-rewriter.d.ts.map +1 -0
  74. package/dist/spec/evolve/spec-rewriter.js +254 -0
  75. package/dist/spec/evolve/spec-rewriter.js.map +1 -0
  76. package/dist/spec/graph/queries.d.ts +58 -0
  77. package/dist/spec/graph/queries.d.ts.map +1 -0
  78. package/dist/spec/graph/queries.js +215 -0
  79. package/dist/spec/graph/queries.js.map +1 -0
  80. package/dist/spec/mining/diff-parser.d.ts +33 -0
  81. package/dist/spec/mining/diff-parser.d.ts.map +1 -0
  82. package/dist/spec/mining/diff-parser.js +166 -0
  83. package/dist/spec/mining/diff-parser.js.map +1 -0
  84. package/dist/spec/mining/git-scanner.d.ts +91 -0
  85. package/dist/spec/mining/git-scanner.d.ts.map +1 -0
  86. package/dist/spec/mining/git-scanner.js +266 -0
  87. package/dist/spec/mining/git-scanner.js.map +1 -0
  88. package/dist/spec/mining/pipeline.d.ts +53 -0
  89. package/dist/spec/mining/pipeline.d.ts.map +1 -0
  90. package/dist/spec/mining/pipeline.js +165 -0
  91. package/dist/spec/mining/pipeline.js.map +1 -0
  92. package/dist/spec/mining/scope-resolver.d.ts +45 -0
  93. package/dist/spec/mining/scope-resolver.d.ts.map +1 -0
  94. package/dist/spec/mining/scope-resolver.js +103 -0
  95. package/dist/spec/mining/scope-resolver.js.map +1 -0
  96. package/dist/spec/mining/spec-extractor.d.ts +69 -0
  97. package/dist/spec/mining/spec-extractor.d.ts.map +1 -0
  98. package/dist/spec/mining/spec-extractor.js +369 -0
  99. package/dist/spec/mining/spec-extractor.js.map +1 -0
  100. package/dist/spec/types.d.ts +149 -0
  101. package/dist/spec/types.d.ts.map +1 -0
  102. package/dist/spec/types.js +15 -0
  103. package/dist/spec/types.js.map +1 -0
  104. package/dist/spec/utils.d.ts +166 -0
  105. package/dist/spec/utils.d.ts.map +1 -0
  106. package/dist/spec/utils.js +461 -0
  107. package/dist/spec/utils.js.map +1 -0
  108. package/package.json +58 -57
  109. package/scripts/add-lang/bench.sh +60 -60
  110. package/scripts/add-lang/check-grammar.mjs +75 -75
  111. package/scripts/add-lang/dump-ast.mjs +103 -103
  112. package/scripts/add-lang/verify-extraction.mjs +70 -70
  113. package/scripts/agent-eval/ab-adoption.sh +91 -91
  114. package/scripts/agent-eval/ab-hook.sh +86 -86
  115. package/scripts/agent-eval/ab-impl.sh +78 -78
  116. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -102
  117. package/scripts/agent-eval/ab-sufficiency.sh +78 -78
  118. package/scripts/agent-eval/arms-F.sh +21 -21
  119. package/scripts/agent-eval/arms-matrix.sh +37 -37
  120. package/scripts/agent-eval/audit.sh +68 -68
  121. package/scripts/agent-eval/bench-readme.sh +28 -28
  122. package/scripts/agent-eval/bench-why-repo.sh +22 -22
  123. package/scripts/agent-eval/block-read-hook.sh +19 -19
  124. package/scripts/agent-eval/hook-settings.json +15 -15
  125. package/scripts/agent-eval/itrun.sh +120 -120
  126. package/scripts/agent-eval/offload-eval-3arm.sh +72 -72
  127. package/scripts/agent-eval/offload-eval-cost.mjs +133 -133
  128. package/scripts/agent-eval/offload-eval-effort.mjs +108 -108
  129. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -25
  130. package/scripts/agent-eval/offload-eval-frontload.sh +47 -47
  131. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -18
  132. package/scripts/agent-eval/offload-eval-hook.mjs +84 -84
  133. package/scripts/agent-eval/offload-eval-judge.mjs +103 -103
  134. package/scripts/agent-eval/offload-eval-matrix.sh +20 -20
  135. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -94
  136. package/scripts/agent-eval/offload-eval-refs1.sh +50 -50
  137. package/scripts/agent-eval/offload-eval-setup.sh +24 -24
  138. package/scripts/agent-eval/offload-eval-styles.sh +71 -71
  139. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -68
  140. package/scripts/agent-eval/offload-eval.md +76 -76
  141. package/scripts/agent-eval/parse-arms.mjs +116 -116
  142. package/scripts/agent-eval/parse-bench-readme.mjs +84 -84
  143. package/scripts/agent-eval/parse-run.mjs +45 -45
  144. package/scripts/agent-eval/parse-session.mjs +93 -93
  145. package/scripts/agent-eval/probe-context.mjs +21 -21
  146. package/scripts/agent-eval/probe-explore.mjs +40 -40
  147. package/scripts/agent-eval/probe-node.mjs +20 -20
  148. package/scripts/agent-eval/probe-sweep.mjs +119 -119
  149. package/scripts/agent-eval/probe-trace.mjs +20 -20
  150. package/scripts/agent-eval/redirect-read-hook.sh +38 -38
  151. package/scripts/agent-eval/run-agent.sh +34 -34
  152. package/scripts/agent-eval/run-all.sh +69 -69
  153. package/scripts/agent-eval/run-arms.sh +56 -56
  154. package/scripts/agent-eval/seq-matrix.mjs +137 -137
  155. package/scripts/build-bundle.sh +118 -118
  156. package/scripts/extract-release-notes.mjs +130 -130
  157. package/scripts/local-install.sh +41 -41
  158. package/scripts/npm-sdk.js +75 -75
  159. package/scripts/npm-shim.js +246 -246
  160. package/scripts/pack-npm.sh +119 -119
  161. package/scripts/prepare-release.mjs +270 -270
  162. package/scripts/qa_eval/README.md +407 -404
  163. package/scripts/qa_eval/_test_deveco_probe.py +41 -41
  164. package/scripts/qa_eval/agent_runner.py +526 -526
  165. package/scripts/qa_eval/data/.gitignore +4 -4
  166. package/scripts/qa_eval/data/test-set.jsonl +2 -22
  167. package/scripts/qa_eval/eval_metrics.py +274 -233
  168. package/scripts/qa_eval/external_agent.py +976 -671
  169. package/scripts/qa_eval/llm_config.py +92 -92
  170. package/scripts/qa_eval/memory_monitor.py +132 -132
  171. package/scripts/qa_eval/my_answer_accuracy.py +187 -187
  172. package/scripts/qa_eval/requirements.txt +2 -2
  173. package/scripts/qa_eval/run_pipeline.py +804 -711
  174. package/scripts/qa_eval/stats_efficiency.py +279 -279
  175. package/scripts/qa_eval/stats_scores.py +207 -207
@@ -1,137 +1,137 @@
1
- #!/usr/bin/env node
2
- // Mine the surviving A/B stream-json logs (/tmp/ab-matrix/<Cell>/run-headless-*.jsonl)
3
- // for what the aggregate matrix can't see: the call SEQUENCE and per-call output SIZE.
4
- //
5
- // Answers three questions:
6
- // 1. Trace adoption — on a flow question, does the with-arm actually call homegraph_trace?
7
- // 2. Payload size vs repo size — is trace path-scoped (tiny, size-independent) while
8
- // explore is breadth-scoped (grows with the repo / over-returns on small repos)?
9
- // 3. Round-trips — num_turns with vs without (the real wall-clock driver).
10
- //
11
- // Usage: node scripts/agent-eval/seq-matrix.mjs [/tmp/ab-matrix]
12
- import { readFileSync, readdirSync, existsSync } from 'fs';
13
- import { join } from 'path';
14
-
15
- const AB = process.argv[2] || '/tmp/ab-matrix';
16
- const MD = new URL('../../docs/benchmarks/homegraph-ab-matrix.md', import.meta.url).pathname;
17
-
18
- // repo -> {lang,size,files} from the published matrix table
19
- const repoMeta = {};
20
- if (existsSync(MD)) for (const line of readFileSync(MD, 'utf8').split('\n')) {
21
- const m = line.match(/^\|\s*([^|]+?)\s*\|\s*(S|M|L)\s*\|\s*`([^`]+)`\s*\|\s*(\d+)\s*\|/);
22
- if (m) repoMeta[m[3]] = { lang: m[1].trim(), size: m[2], files: +m[4] };
23
- }
24
-
25
- const cgShort = (n) => n.replace('mcp__homegraph__homegraph_', '').replace('mcp__homegraph__', '');
26
- const tag = (n) => n === 'Read' ? 'R' : n === 'Grep' ? 'G' : n === 'Glob' ? 'Gl'
27
- : n === 'Bash' ? 'B' : n === 'Task' ? 'Ag' : n === 'ToolSearch' ? 'TS'
28
- : n.includes('homegraph') ? cgShort(n) : n;
29
-
30
- function parse(file) {
31
- if (!existsSync(file)) return null;
32
- const lines = readFileSync(file, 'utf8').split('\n').filter(Boolean);
33
- const calls = []; let result = null, initCg = 0;
34
- for (const l of lines) {
35
- let ev; try { ev = JSON.parse(l); } catch { continue; }
36
- if (ev.type === 'system' && ev.subtype === 'init') initCg = (ev.tools || []).filter(t => /homegraph/.test(t)).length;
37
- if (ev.type === 'assistant') for (const b of (ev.message?.content || [])) if (b.type === 'tool_use') {
38
- const i = b.input || {};
39
- const q = i.query ?? i.symbol ?? i.task ?? (i.from && i.to ? `${i.from}->${i.to}` : (i.file_path || i.command || ''));
40
- calls.push({ id: b.id, name: b.name, q: String(q ?? '').slice(0, 38), out: 0 });
41
- }
42
- if (ev.type === 'user') for (const b of (ev.message?.content || [])) if (b.type === 'tool_result') {
43
- const c = b.content;
44
- const txt = typeof c === 'string' ? c : Array.isArray(c) ? c.map(x => x?.text || '').join('') : '';
45
- const call = calls.find(k => k.id === b.tool_use_id); if (call) call.out = txt.length;
46
- }
47
- if (ev.type === 'result') result = ev;
48
- }
49
- const cg = calls.filter(c => c.name.includes('homegraph'));
50
- const perTool = {};
51
- for (const c of cg) { const k = cgShort(c.name); (perTool[k] ??= { n: 0, out: 0 }); perTool[k].n++; perTool[k].out += c.out; }
52
- const traceIdx = cg.findIndex(c => c.name.includes('trace'));
53
- const u = result?.usage || {};
54
- return {
55
- initCg, cg, perTool,
56
- cgSeq: cg.map(c => cgShort(c.name)),
57
- seq: calls.map(c => tag(c.name)),
58
- reads: calls.filter(c => c.name === 'Read').length,
59
- greps: calls.filter(c => c.name === 'Grep').length,
60
- cgOut: cg.reduce((s, c) => s + c.out, 0),
61
- traceUsed: traceIdx >= 0,
62
- afterTrace: traceIdx >= 0 ? cg.slice(traceIdx + 1).map(c => cgShort(c.name)) : null,
63
- turns: result?.num_turns ?? null,
64
- dur: result?.duration_ms ? Math.round(result.duration_ms / 1000) : null,
65
- cost: result?.total_cost_usd || 0,
66
- };
67
- }
68
-
69
- const cells = [];
70
- for (const d of readdirSync(AB)) {
71
- const dir = join(AB, d);
72
- if (!existsSync(join(dir, 'run-headless-with.jsonl'))) continue;
73
- const log = existsSync(join(AB, d + '.log')) ? readFileSync(join(AB, d + '.log'), 'utf8') : '';
74
- const repo = (log.match(/repo:\s*\S*\/([^\s/]+)/) || [])[1] || d;
75
- const question = (log.match(/question:\s*(.+)/) || [])[1] || '';
76
- cells.push({ cell: d, repo, question, ...(repoMeta[repo] || {}),
77
- with: parse(join(dir, 'run-headless-with.jsonl')),
78
- without: parse(join(dir, 'run-headless-without.jsonl')) });
79
- }
80
- cells.sort((a, b) => (a.files || 0) - (b.files || 0));
81
-
82
- const k = (n) => (n / 1000).toFixed(1);
83
- const pad = (s, n) => String(s).padEnd(n);
84
-
85
- // ---- per-cell sequence table ----
86
- console.log('\n=== PER-CELL: with-arm homegraph sequence + payload (sorted by repo size) ===');
87
- console.log(pad('repo', 22), pad('files', 6), 'trace', pad('cg-call sequence', 40), pad('cgOutK', 7), 'turns(w/wo)');
88
- for (const c of cells) {
89
- const w = c.with;
90
- console.log(
91
- pad(c.repo, 22), pad(c.files ?? '?', 6),
92
- pad(w.traceUsed ? 'YES' : 'no', 5),
93
- pad(w.cgSeq.join(',') || '(none)', 40),
94
- pad(k(w.cgOut), 7),
95
- `${w.turns}/${c.without?.turns}`,
96
- );
97
- }
98
-
99
- // ---- trace adoption ----
100
- const flow = cells; // every matrix question is a canonical flow question by design
101
- const used = flow.filter(c => c.with.traceUsed);
102
- console.log(`\n=== TRACE ADOPTION (all ${flow.length} cells are flow questions) ===`);
103
- console.log(`trace called in ${used.length}/${flow.length} cells`);
104
- console.log('used trace:', used.map(c => c.repo).join(', ') || '(none)');
105
- if (used.length) console.log('after-trace follow-ups:', used.map(c => `${c.repo}[${c.with.afterTrace.join(',') || 'none'}]`).join(' '));
106
-
107
- // ---- payload size by repo-size tier ----
108
- const tier = (f) => f < 200 ? 'S(<200)' : f < 2000 ? 'M(<2000)' : 'L(>=2000)';
109
- const byTier = {};
110
- for (const c of cells) { (byTier[tier(c.files || 0)] ??= []).push(c.with.cgOut); }
111
- console.log('\n=== with-arm TOTAL homegraph payload by repo-size tier ===');
112
- for (const t of ['S(<200)', 'M(<2000)', 'L(>=2000)']) {
113
- const a = byTier[t] || []; if (!a.length) continue;
114
- const avg = a.reduce((s, x) => s + x, 0) / a.length;
115
- console.log(` ${pad(t, 10)} n=${a.length} avg cgOut=${k(avg)}K range ${k(Math.min(...a))}-${k(Math.max(...a))}K`);
116
- }
117
-
118
- // ---- per-tool usage + avg payload (breadth vs path evidence) ----
119
- const tot = {};
120
- for (const c of cells) for (const [name, v] of Object.entries(c.with.perTool)) {
121
- (tot[name] ??= { n: 0, out: 0 }); tot[name].n += v.n; tot[name].out += v.out;
122
- }
123
- console.log('\n=== homegraph tool usage across all cells (n calls, avg payload/call) ===');
124
- for (const [name, v] of Object.entries(tot).sort((a, b) => b[1].n - a[1].n)) {
125
- console.log(` ${pad(name, 10)} calls=${pad(v.n, 4)} avg=${k(v.out / v.n)}K/call total=${k(v.out)}K`);
126
- }
127
-
128
- // ---- round-trips ----
129
- const sum = (arr, f) => arr.reduce((s, x) => s + (f(x) || 0), 0);
130
- const wTurns = sum(cells, c => c.with.turns), woTurns = sum(cells, c => c.without?.turns);
131
- const wCalls = sum(cells, c => c.with.cg.length);
132
- const tsAll = cells.every(c => c.with.seq[0] === 'TS');
133
- console.log('\n=== ROUND-TRIPS ===');
134
- console.log(`turns: with=${wTurns} without=${woTurns} (${((1 - wTurns / woTurns) * 100).toFixed(0)}% fewer with)`);
135
- console.log(`avg turns/cell: with=${(wTurns / cells.length).toFixed(1)} without=${(woTurns / cells.length).toFixed(1)}`);
136
- console.log(`total homegraph calls=${wCalls} (avg ${(wCalls / cells.length).toFixed(1)}/cell)`);
137
- console.log(`every with-arm opens with a ToolSearch round-trip (deferred tools): ${tsAll ? 'YES — 1 fixed tax/run' : 'no'}`);
1
+ #!/usr/bin/env node
2
+ // Mine the surviving A/B stream-json logs (/tmp/ab-matrix/<Cell>/run-headless-*.jsonl)
3
+ // for what the aggregate matrix can't see: the call SEQUENCE and per-call output SIZE.
4
+ //
5
+ // Answers three questions:
6
+ // 1. Trace adoption — on a flow question, does the with-arm actually call homegraph_trace?
7
+ // 2. Payload size vs repo size — is trace path-scoped (tiny, size-independent) while
8
+ // explore is breadth-scoped (grows with the repo / over-returns on small repos)?
9
+ // 3. Round-trips — num_turns with vs without (the real wall-clock driver).
10
+ //
11
+ // Usage: node scripts/agent-eval/seq-matrix.mjs [/tmp/ab-matrix]
12
+ import { readFileSync, readdirSync, existsSync } from 'fs';
13
+ import { join } from 'path';
14
+
15
+ const AB = process.argv[2] || '/tmp/ab-matrix';
16
+ const MD = new URL('../../docs/benchmarks/homegraph-ab-matrix.md', import.meta.url).pathname;
17
+
18
+ // repo -> {lang,size,files} from the published matrix table
19
+ const repoMeta = {};
20
+ if (existsSync(MD)) for (const line of readFileSync(MD, 'utf8').split('\n')) {
21
+ const m = line.match(/^\|\s*([^|]+?)\s*\|\s*(S|M|L)\s*\|\s*`([^`]+)`\s*\|\s*(\d+)\s*\|/);
22
+ if (m) repoMeta[m[3]] = { lang: m[1].trim(), size: m[2], files: +m[4] };
23
+ }
24
+
25
+ const cgShort = (n) => n.replace('mcp__homegraph__homegraph_', '').replace('mcp__homegraph__', '');
26
+ const tag = (n) => n === 'Read' ? 'R' : n === 'Grep' ? 'G' : n === 'Glob' ? 'Gl'
27
+ : n === 'Bash' ? 'B' : n === 'Task' ? 'Ag' : n === 'ToolSearch' ? 'TS'
28
+ : n.includes('homegraph') ? cgShort(n) : n;
29
+
30
+ function parse(file) {
31
+ if (!existsSync(file)) return null;
32
+ const lines = readFileSync(file, 'utf8').split('\n').filter(Boolean);
33
+ const calls = []; let result = null, initCg = 0;
34
+ for (const l of lines) {
35
+ let ev; try { ev = JSON.parse(l); } catch { continue; }
36
+ if (ev.type === 'system' && ev.subtype === 'init') initCg = (ev.tools || []).filter(t => /homegraph/.test(t)).length;
37
+ if (ev.type === 'assistant') for (const b of (ev.message?.content || [])) if (b.type === 'tool_use') {
38
+ const i = b.input || {};
39
+ const q = i.query ?? i.symbol ?? i.task ?? (i.from && i.to ? `${i.from}->${i.to}` : (i.file_path || i.command || ''));
40
+ calls.push({ id: b.id, name: b.name, q: String(q ?? '').slice(0, 38), out: 0 });
41
+ }
42
+ if (ev.type === 'user') for (const b of (ev.message?.content || [])) if (b.type === 'tool_result') {
43
+ const c = b.content;
44
+ const txt = typeof c === 'string' ? c : Array.isArray(c) ? c.map(x => x?.text || '').join('') : '';
45
+ const call = calls.find(k => k.id === b.tool_use_id); if (call) call.out = txt.length;
46
+ }
47
+ if (ev.type === 'result') result = ev;
48
+ }
49
+ const cg = calls.filter(c => c.name.includes('homegraph'));
50
+ const perTool = {};
51
+ for (const c of cg) { const k = cgShort(c.name); (perTool[k] ??= { n: 0, out: 0 }); perTool[k].n++; perTool[k].out += c.out; }
52
+ const traceIdx = cg.findIndex(c => c.name.includes('trace'));
53
+ const u = result?.usage || {};
54
+ return {
55
+ initCg, cg, perTool,
56
+ cgSeq: cg.map(c => cgShort(c.name)),
57
+ seq: calls.map(c => tag(c.name)),
58
+ reads: calls.filter(c => c.name === 'Read').length,
59
+ greps: calls.filter(c => c.name === 'Grep').length,
60
+ cgOut: cg.reduce((s, c) => s + c.out, 0),
61
+ traceUsed: traceIdx >= 0,
62
+ afterTrace: traceIdx >= 0 ? cg.slice(traceIdx + 1).map(c => cgShort(c.name)) : null,
63
+ turns: result?.num_turns ?? null,
64
+ dur: result?.duration_ms ? Math.round(result.duration_ms / 1000) : null,
65
+ cost: result?.total_cost_usd || 0,
66
+ };
67
+ }
68
+
69
+ const cells = [];
70
+ for (const d of readdirSync(AB)) {
71
+ const dir = join(AB, d);
72
+ if (!existsSync(join(dir, 'run-headless-with.jsonl'))) continue;
73
+ const log = existsSync(join(AB, d + '.log')) ? readFileSync(join(AB, d + '.log'), 'utf8') : '';
74
+ const repo = (log.match(/repo:\s*\S*\/([^\s/]+)/) || [])[1] || d;
75
+ const question = (log.match(/question:\s*(.+)/) || [])[1] || '';
76
+ cells.push({ cell: d, repo, question, ...(repoMeta[repo] || {}),
77
+ with: parse(join(dir, 'run-headless-with.jsonl')),
78
+ without: parse(join(dir, 'run-headless-without.jsonl')) });
79
+ }
80
+ cells.sort((a, b) => (a.files || 0) - (b.files || 0));
81
+
82
+ const k = (n) => (n / 1000).toFixed(1);
83
+ const pad = (s, n) => String(s).padEnd(n);
84
+
85
+ // ---- per-cell sequence table ----
86
+ console.log('\n=== PER-CELL: with-arm homegraph sequence + payload (sorted by repo size) ===');
87
+ console.log(pad('repo', 22), pad('files', 6), 'trace', pad('cg-call sequence', 40), pad('cgOutK', 7), 'turns(w/wo)');
88
+ for (const c of cells) {
89
+ const w = c.with;
90
+ console.log(
91
+ pad(c.repo, 22), pad(c.files ?? '?', 6),
92
+ pad(w.traceUsed ? 'YES' : 'no', 5),
93
+ pad(w.cgSeq.join(',') || '(none)', 40),
94
+ pad(k(w.cgOut), 7),
95
+ `${w.turns}/${c.without?.turns}`,
96
+ );
97
+ }
98
+
99
+ // ---- trace adoption ----
100
+ const flow = cells; // every matrix question is a canonical flow question by design
101
+ const used = flow.filter(c => c.with.traceUsed);
102
+ console.log(`\n=== TRACE ADOPTION (all ${flow.length} cells are flow questions) ===`);
103
+ console.log(`trace called in ${used.length}/${flow.length} cells`);
104
+ console.log('used trace:', used.map(c => c.repo).join(', ') || '(none)');
105
+ if (used.length) console.log('after-trace follow-ups:', used.map(c => `${c.repo}[${c.with.afterTrace.join(',') || 'none'}]`).join(' '));
106
+
107
+ // ---- payload size by repo-size tier ----
108
+ const tier = (f) => f < 200 ? 'S(<200)' : f < 2000 ? 'M(<2000)' : 'L(>=2000)';
109
+ const byTier = {};
110
+ for (const c of cells) { (byTier[tier(c.files || 0)] ??= []).push(c.with.cgOut); }
111
+ console.log('\n=== with-arm TOTAL homegraph payload by repo-size tier ===');
112
+ for (const t of ['S(<200)', 'M(<2000)', 'L(>=2000)']) {
113
+ const a = byTier[t] || []; if (!a.length) continue;
114
+ const avg = a.reduce((s, x) => s + x, 0) / a.length;
115
+ console.log(` ${pad(t, 10)} n=${a.length} avg cgOut=${k(avg)}K range ${k(Math.min(...a))}-${k(Math.max(...a))}K`);
116
+ }
117
+
118
+ // ---- per-tool usage + avg payload (breadth vs path evidence) ----
119
+ const tot = {};
120
+ for (const c of cells) for (const [name, v] of Object.entries(c.with.perTool)) {
121
+ (tot[name] ??= { n: 0, out: 0 }); tot[name].n += v.n; tot[name].out += v.out;
122
+ }
123
+ console.log('\n=== homegraph tool usage across all cells (n calls, avg payload/call) ===');
124
+ for (const [name, v] of Object.entries(tot).sort((a, b) => b[1].n - a[1].n)) {
125
+ console.log(` ${pad(name, 10)} calls=${pad(v.n, 4)} avg=${k(v.out / v.n)}K/call total=${k(v.out)}K`);
126
+ }
127
+
128
+ // ---- round-trips ----
129
+ const sum = (arr, f) => arr.reduce((s, x) => s + (f(x) || 0), 0);
130
+ const wTurns = sum(cells, c => c.with.turns), woTurns = sum(cells, c => c.without?.turns);
131
+ const wCalls = sum(cells, c => c.with.cg.length);
132
+ const tsAll = cells.every(c => c.with.seq[0] === 'TS');
133
+ console.log('\n=== ROUND-TRIPS ===');
134
+ console.log(`turns: with=${wTurns} without=${woTurns} (${((1 - wTurns / woTurns) * 100).toFixed(0)}% fewer with)`);
135
+ console.log(`avg turns/cell: with=${(wTurns / cells.length).toFixed(1)} without=${(woTurns / cells.length).toFixed(1)}`);
136
+ console.log(`total homegraph calls=${wCalls} (avg ${(wCalls / cells.length).toFixed(1)}/cell)`);
137
+ console.log(`every with-arm opens with a ToolSearch round-trip (deferred tools): ${tsAll ? 'YES — 1 fixed tax/run' : 'no'}`);
@@ -1,118 +1,118 @@
1
- #!/usr/bin/env bash
2
- #
3
- # Build a self-contained HomeGraph bundle: an official Node runtime + the
4
- # compiled app + its production deps, so HomeGraph runs with NO system Node and
5
- # NO native build — node:sqlite is built into the bundled Node. One archive per
6
- # platform.
7
- #
8
- # Because dropping better-sqlite3 left zero native addons, the recipe is pure
9
- # file-packaging (download the target's Node, copy the app, archive) — so any
10
- # platform's bundle can be built on any OS. No cross-compile, no native runners.
11
- #
12
- # Usage:
13
- # scripts/build-bundle.sh <target> [node-version]
14
- # target: darwin-arm64 | darwin-x64 | linux-x64 | linux-arm64
15
- # | win32-x64 | win32-arm64
16
- # node-version: e.g. v24.16.0 (default below; pin for reproducible builds)
17
- #
18
- # Output:
19
- # unix: release/homegraph-<target>.tar.gz (launcher: bin/homegraph)
20
- # windows: release/homegraph-<target>.zip (launcher: bin/homegraph.cmd)
21
- set -euo pipefail
22
-
23
- TARGET="${1:?usage: build-bundle.sh <target> [node-version]}"
24
- NODE_VERSION="${2:-v24.16.0}"
25
-
26
- ROOT="$(cd "$(dirname "$0")/.." && pwd)"
27
- OUT="$ROOT/release"
28
- WORK="$(mktemp -d)"
29
- trap 'rm -rf "$WORK"' EXIT
30
-
31
- ARCH="${TARGET##*-}" # x64 | arm64
32
- OSFAM="${TARGET%-*}" # darwin | linux | win32
33
-
34
- echo "[bundle] target=${TARGET} node=${NODE_VERSION}"
35
-
36
- # 1. Download + extract the official Node runtime for the target platform.
37
- if [ "$OSFAM" = "win32" ]; then
38
- NODE_DIST="node-${NODE_VERSION}-win-${ARCH}"
39
- NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_DIST}.zip"
40
- echo "[bundle] downloading ${NODE_URL}"
41
- curl -fsSL "$NODE_URL" -o "$WORK/node.zip"
42
- if command -v unzip >/dev/null 2>&1; then
43
- unzip -q "$WORK/node.zip" -d "$WORK"
44
- else
45
- tar -xf "$WORK/node.zip" -C "$WORK" # bsdtar can read zip
46
- fi
47
- NODE_BIN="$WORK/${NODE_DIST}/node.exe"
48
- else
49
- NODE_DIST="node-${NODE_VERSION}-${TARGET}"
50
- NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_DIST}.tar.gz"
51
- echo "[bundle] downloading ${NODE_URL}"
52
- curl -fsSL "$NODE_URL" -o "$WORK/node.tar.gz"
53
- tar -xzf "$WORK/node.tar.gz" -C "$WORK"
54
- NODE_BIN="$WORK/${NODE_DIST}/bin/node"
55
- fi
56
- [ -f "$NODE_BIN" ] || { echo "[bundle] error: node binary not found ($NODE_BIN)" >&2; exit 1; }
57
-
58
- # 2. Build the app (compiled JS + copied wasm/schema assets).
59
- echo "[bundle] building app"
60
- ( cd "$ROOT" && npm run build >/dev/null )
61
-
62
- # 3. Stage: app + production-only deps (pure JS/wasm → portable across platforms).
63
- STAGE="$WORK/homegraph-${TARGET}"
64
- mkdir -p "$STAGE/lib" "$STAGE/bin"
65
- cp -R "$ROOT/dist" "$STAGE/lib/dist"
66
- cp "$ROOT/package.json" "$ROOT/package-lock.json" "$STAGE/lib/"
67
- echo "[bundle] installing production dependencies"
68
- ( cd "$STAGE/lib" && npm ci --omit=dev --ignore-scripts >/dev/null 2>&1 )
69
- rm -f "$STAGE/lib/package-lock.json"
70
-
71
- # 4. Vendored Node + launcher (the launcher uses the bundled Node by relative
72
- # path, so no system Node is ever needed).
73
- #
74
- # `--liftoff-only`: keep tree-sitter's large WASM grammars on V8's Liftoff
75
- # baseline compiler so they never reach the turboshaft optimizing tier, whose
76
- # per-compilation Zone arena OOMs the whole process (`Fatal process out of
77
- # memory: Zone`) on Node >= 22 — even with tens of GB free. The flag is read at
78
- # V8 engine init so it must be on node's command line; the parse worker inherits
79
- # it. See issues #293/#298 and src/extraction/wasm-runtime-flags.ts. (The CLI
80
- # also self-relaunches with this flag when launched without it, so non-bundled
81
- # runs are covered too; passing it here avoids that extra spawn.)
82
- if [ "$OSFAM" = "win32" ]; then
83
- cp "$NODE_BIN" "$STAGE/node.exe"
84
- printf '@"%%~dp0..\\node.exe" --liftoff-only "%%~dp0..\\lib\\dist\\bin\\homegraph.js" %%*\r\n' \
85
- > "$STAGE/bin/homegraph.cmd"
86
- else
87
- cp "$NODE_BIN" "$STAGE/node"
88
- cat > "$STAGE/bin/homegraph" <<'LAUNCH'
89
- #!/bin/sh
90
- # Resolve symlinks (e.g. the ~/.local/bin/homegraph link install.sh creates) so
91
- # we find the real bundle dir, not the symlink's location.
92
- SELF="$0"
93
- while [ -L "$SELF" ]; do
94
- target="$(readlink "$SELF")"
95
- case "$target" in
96
- /*) SELF="$target" ;;
97
- *) SELF="$(dirname "$SELF")/$target" ;;
98
- esac
99
- done
100
- DIR="$(cd "$(dirname "$SELF")/.." && pwd)"
101
- # --liftoff-only: avoid the V8 turboshaft WASM Zone OOM (issues #293/#298).
102
- exec "$DIR/node" --liftoff-only "$DIR/lib/dist/bin/homegraph.js" "$@"
103
- LAUNCH
104
- chmod +x "$STAGE/bin/homegraph"
105
- fi
106
-
107
- # 5. Archive (.zip for Windows, .tar.gz otherwise).
108
- mkdir -p "$OUT"
109
- if [ "$OSFAM" = "win32" ]; then
110
- ARCHIVE="$OUT/homegraph-${TARGET}.zip"
111
- rm -f "$ARCHIVE"
112
- ( cd "$WORK" && zip -rqX "$ARCHIVE" "homegraph-${TARGET}" )
113
- else
114
- ARCHIVE="$OUT/homegraph-${TARGET}.tar.gz"
115
- # --no-xattrs: don't embed macOS xattrs that make GNU tar warn on Linux.
116
- tar --no-xattrs -czf "$ARCHIVE" -C "$WORK" "homegraph-${TARGET}"
117
- fi
118
- echo "[bundle] wrote ${ARCHIVE} ($(du -h "$ARCHIVE" | cut -f1))"
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Build a self-contained HomeGraph bundle: an official Node runtime + the
4
+ # compiled app + its production deps, so HomeGraph runs with NO system Node and
5
+ # NO native build — node:sqlite is built into the bundled Node. One archive per
6
+ # platform.
7
+ #
8
+ # Because dropping better-sqlite3 left zero native addons, the recipe is pure
9
+ # file-packaging (download the target's Node, copy the app, archive) — so any
10
+ # platform's bundle can be built on any OS. No cross-compile, no native runners.
11
+ #
12
+ # Usage:
13
+ # scripts/build-bundle.sh <target> [node-version]
14
+ # target: darwin-arm64 | darwin-x64 | linux-x64 | linux-arm64
15
+ # | win32-x64 | win32-arm64
16
+ # node-version: e.g. v24.16.0 (default below; pin for reproducible builds)
17
+ #
18
+ # Output:
19
+ # unix: release/homegraph-<target>.tar.gz (launcher: bin/homegraph)
20
+ # windows: release/homegraph-<target>.zip (launcher: bin/homegraph.cmd)
21
+ set -euo pipefail
22
+
23
+ TARGET="${1:?usage: build-bundle.sh <target> [node-version]}"
24
+ NODE_VERSION="${2:-v24.16.0}"
25
+
26
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
27
+ OUT="$ROOT/release"
28
+ WORK="$(mktemp -d)"
29
+ trap 'rm -rf "$WORK"' EXIT
30
+
31
+ ARCH="${TARGET##*-}" # x64 | arm64
32
+ OSFAM="${TARGET%-*}" # darwin | linux | win32
33
+
34
+ echo "[bundle] target=${TARGET} node=${NODE_VERSION}"
35
+
36
+ # 1. Download + extract the official Node runtime for the target platform.
37
+ if [ "$OSFAM" = "win32" ]; then
38
+ NODE_DIST="node-${NODE_VERSION}-win-${ARCH}"
39
+ NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_DIST}.zip"
40
+ echo "[bundle] downloading ${NODE_URL}"
41
+ curl -fsSL "$NODE_URL" -o "$WORK/node.zip"
42
+ if command -v unzip >/dev/null 2>&1; then
43
+ unzip -q "$WORK/node.zip" -d "$WORK"
44
+ else
45
+ tar -xf "$WORK/node.zip" -C "$WORK" # bsdtar can read zip
46
+ fi
47
+ NODE_BIN="$WORK/${NODE_DIST}/node.exe"
48
+ else
49
+ NODE_DIST="node-${NODE_VERSION}-${TARGET}"
50
+ NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_DIST}.tar.gz"
51
+ echo "[bundle] downloading ${NODE_URL}"
52
+ curl -fsSL "$NODE_URL" -o "$WORK/node.tar.gz"
53
+ tar -xzf "$WORK/node.tar.gz" -C "$WORK"
54
+ NODE_BIN="$WORK/${NODE_DIST}/bin/node"
55
+ fi
56
+ [ -f "$NODE_BIN" ] || { echo "[bundle] error: node binary not found ($NODE_BIN)" >&2; exit 1; }
57
+
58
+ # 2. Build the app (compiled JS + copied wasm/schema assets).
59
+ echo "[bundle] building app"
60
+ ( cd "$ROOT" && npm run build >/dev/null )
61
+
62
+ # 3. Stage: app + production-only deps (pure JS/wasm → portable across platforms).
63
+ STAGE="$WORK/homegraph-${TARGET}"
64
+ mkdir -p "$STAGE/lib" "$STAGE/bin"
65
+ cp -R "$ROOT/dist" "$STAGE/lib/dist"
66
+ cp "$ROOT/package.json" "$ROOT/package-lock.json" "$STAGE/lib/"
67
+ echo "[bundle] installing production dependencies"
68
+ ( cd "$STAGE/lib" && npm ci --omit=dev --ignore-scripts >/dev/null 2>&1 )
69
+ rm -f "$STAGE/lib/package-lock.json"
70
+
71
+ # 4. Vendored Node + launcher (the launcher uses the bundled Node by relative
72
+ # path, so no system Node is ever needed).
73
+ #
74
+ # `--liftoff-only`: keep tree-sitter's large WASM grammars on V8's Liftoff
75
+ # baseline compiler so they never reach the turboshaft optimizing tier, whose
76
+ # per-compilation Zone arena OOMs the whole process (`Fatal process out of
77
+ # memory: Zone`) on Node >= 22 — even with tens of GB free. The flag is read at
78
+ # V8 engine init so it must be on node's command line; the parse worker inherits
79
+ # it. See issues #293/#298 and src/extraction/wasm-runtime-flags.ts. (The CLI
80
+ # also self-relaunches with this flag when launched without it, so non-bundled
81
+ # runs are covered too; passing it here avoids that extra spawn.)
82
+ if [ "$OSFAM" = "win32" ]; then
83
+ cp "$NODE_BIN" "$STAGE/node.exe"
84
+ printf '@"%%~dp0..\\node.exe" --liftoff-only "%%~dp0..\\lib\\dist\\bin\\homegraph.js" %%*\r\n' \
85
+ > "$STAGE/bin/homegraph.cmd"
86
+ else
87
+ cp "$NODE_BIN" "$STAGE/node"
88
+ cat > "$STAGE/bin/homegraph" <<'LAUNCH'
89
+ #!/bin/sh
90
+ # Resolve symlinks (e.g. the ~/.local/bin/homegraph link install.sh creates) so
91
+ # we find the real bundle dir, not the symlink's location.
92
+ SELF="$0"
93
+ while [ -L "$SELF" ]; do
94
+ target="$(readlink "$SELF")"
95
+ case "$target" in
96
+ /*) SELF="$target" ;;
97
+ *) SELF="$(dirname "$SELF")/$target" ;;
98
+ esac
99
+ done
100
+ DIR="$(cd "$(dirname "$SELF")/.." && pwd)"
101
+ # --liftoff-only: avoid the V8 turboshaft WASM Zone OOM (issues #293/#298).
102
+ exec "$DIR/node" --liftoff-only "$DIR/lib/dist/bin/homegraph.js" "$@"
103
+ LAUNCH
104
+ chmod +x "$STAGE/bin/homegraph"
105
+ fi
106
+
107
+ # 5. Archive (.zip for Windows, .tar.gz otherwise).
108
+ mkdir -p "$OUT"
109
+ if [ "$OSFAM" = "win32" ]; then
110
+ ARCHIVE="$OUT/homegraph-${TARGET}.zip"
111
+ rm -f "$ARCHIVE"
112
+ ( cd "$WORK" && zip -rqX "$ARCHIVE" "homegraph-${TARGET}" )
113
+ else
114
+ ARCHIVE="$OUT/homegraph-${TARGET}.tar.gz"
115
+ # --no-xattrs: don't embed macOS xattrs that make GNU tar warn on Linux.
116
+ tar --no-xattrs -czf "$ARCHIVE" -C "$WORK" "homegraph-${TARGET}"
117
+ fi
118
+ echo "[bundle] wrote ${ARCHIVE} ($(du -h "$ARCHIVE" | cut -f1))"