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
package/package.json CHANGED
@@ -1,57 +1,58 @@
1
- {
2
- "name": "homegraph",
3
- "version": "1.1.2",
4
- "description": "Supercharge AI coding agents with semantic code intelligence — surgical context, fewer tool calls, faster answers. 100% local.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "bin": {
8
- "homegraph": "./dist/bin/homegraph.js"
9
- },
10
- "files": [
11
- "dist",
12
- "scripts",
13
- "README.md"
14
- ],
15
- "scripts": {
16
- "build": "tsc && npm run copy-assets && node -e \"require('fs').chmodSync('dist/bin/homegraph.js', 0o755)\"",
17
- "preuninstall": "node dist/bin/uninstall.js",
18
- "copy-assets": "node -e \"const fs=require('fs');fs.mkdirSync('dist/db',{recursive:true});fs.copyFileSync('src/db/schema.sql','dist/db/schema.sql');fs.mkdirSync('dist/extraction/wasm',{recursive:true});fs.readdirSync('src/extraction/wasm').filter(f=>f.endsWith('.wasm')).forEach(f=>fs.copyFileSync('src/extraction/wasm/'+f,'dist/extraction/wasm/'+f))\"",
19
- "dev": "tsc --watch",
20
- "cli": "npm run build && node dist/bin/homegraph.js",
21
- "test": "vitest run",
22
- "test:watch": "vitest",
23
- "test:eval": "vitest run __tests__/evaluation/",
24
- "eval": "npm run build && npx tsx __tests__/evaluation/runner.ts",
25
- "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\""
26
- },
27
- "keywords": [
28
- "code-intelligence",
29
- "knowledge-graph",
30
- "static-analysis"
31
- ],
32
- "author": "",
33
- "license": "MIT",
34
- "dependencies": {
35
- "@clack/prompts": "^1.3.0",
36
- "commander": "^14.0.2",
37
- "fast-string-width": "^3.0.2",
38
- "fast-wrap-ansi": "^0.2.0",
39
- "ignore": "^7.0.5",
40
- "jsonc-parser": "^3.3.1",
41
- "picomatch": "^4.0.3",
42
- "sisteransi": "^1.0.5",
43
- "tree-sitter-wasms": "^0.1.11",
44
- "web-tree-sitter": "^0.25.3"
45
- },
46
- "devDependencies": {
47
- "@types/better-sqlite3": "^7.6.0",
48
- "@types/node": "^20.19.30",
49
- "@types/picomatch": "^4.0.2",
50
- "arkanalyzer": "^1.0.90",
51
- "typescript": "^5.0.0",
52
- "vitest": "^2.1.9"
53
- },
54
- "engines": {
55
- "node": ">=20.0.0 <25.0.0"
56
- }
57
- }
1
+ {
2
+ "name": "homegraph",
3
+ "version": "1.1.3",
4
+ "description": "Supercharge AI coding agents with semantic code intelligence — surgical context, fewer tool calls, faster answers. 100% local.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "homegraph": "./dist/bin/homegraph.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "scripts",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc && npm run copy-assets && node -e \"require('fs').chmodSync('dist/bin/homegraph.js', 0o755)\"",
17
+ "preuninstall": "node dist/bin/uninstall.js",
18
+ "copy-assets": "node -e \"const fs=require('fs');fs.mkdirSync('dist/db',{recursive:true});fs.copyFileSync('src/db/schema.sql','dist/db/schema.sql');fs.mkdirSync('dist/spec/db',{recursive:true});fs.copyFileSync('src/spec/db/schema.sql','dist/spec/db/schema.sql');fs.mkdirSync('dist/extraction/wasm',{recursive:true});fs.readdirSync('src/extraction/wasm').filter(f=>f.endsWith('.wasm')).forEach(f=>fs.copyFileSync('src/extraction/wasm/'+f,'dist/extraction/wasm/'+f))\"",
19
+ "dev": "tsc --watch",
20
+ "cli": "npm run build && node dist/bin/homegraph.js",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "test:eval": "vitest run __tests__/evaluation/",
24
+ "eval": "npm run build && npx tsx __tests__/evaluation/runner.ts",
25
+ "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\""
26
+ },
27
+ "keywords": [
28
+ "code-intelligence",
29
+ "knowledge-graph",
30
+ "static-analysis"
31
+ ],
32
+ "author": "",
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "@clack/prompts": "^1.3.0",
36
+ "commander": "^14.0.2",
37
+ "fast-string-width": "^3.0.2",
38
+ "fast-wrap-ansi": "^0.2.0",
39
+ "ignore": "^7.0.5",
40
+ "jsonc-parser": "^3.3.1",
41
+ "picomatch": "^4.0.3",
42
+ "sisteransi": "^1.0.5",
43
+ "tree-sitter-wasms": "^0.1.11",
44
+ "web-tree-sitter": "^0.25.3",
45
+ "openai": "^4.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/better-sqlite3": "^7.6.0",
49
+ "@types/node": "^20.19.30",
50
+ "@types/picomatch": "^4.0.2",
51
+ "arkanalyzer": "^1.0.90",
52
+ "typescript": "^5.0.0",
53
+ "vitest": "^2.1.9"
54
+ },
55
+ "engines": {
56
+ "node": ">=20.0.0 <25.0.0"
57
+ }
58
+ }
@@ -1,60 +1,60 @@
1
- #!/usr/bin/env bash
2
- # Add-lang benchmark for ONE repo:
3
- # clone -> wipe+index (with the homegraph on PATH) -> verify extraction ->
4
- # with/without retrieval A/B (reuses scripts/agent-eval/run-all.sh).
5
- #
6
- # Assumes the homegraph dev build is already built + linked on PATH — the skill
7
- # runs `npm run build && ./scripts/local-install.sh` ONCE before looping repos.
8
- # The A/B is skipped if extraction fails its critical checks (don't burn $ on a
9
- # broken extractor); set FORCE_AB=1 to run it anyway.
10
- #
11
- # Usage: bench.sh <lang> <repo-name> <repo-url> "<question>" [headless|tmux|all]
12
- # Env: CORPUS corpus dir (default /tmp/homegraph-corpus, shared with agent-eval)
13
- set -uo pipefail
14
-
15
- LANG_TOKEN="${1:?usage: bench.sh <lang> <repo-name> <repo-url> \"<question>\" [mode]}"
16
- NAME="${2:?repo-name required}"
17
- URL="${3:?repo-url required}"
18
- Q="${4:?question required}"
19
- MODE="${5:-headless}"
20
-
21
- HARNESS="$(cd "$(dirname "$0")" && pwd)"
22
- AGENT_EVAL="$(cd "$HARNESS/../agent-eval" && pwd)"
23
- CORPUS="${CORPUS:-/tmp/homegraph-corpus}"
24
- REPO="$CORPUS/$NAME"
25
-
26
- command -v homegraph >/dev/null || { echo "no homegraph on PATH (build + ./scripts/local-install.sh first)"; exit 1; }
27
-
28
- echo "==================== add-lang bench: $NAME ($LANG_TOKEN) ===================="
29
- echo "homegraph: $(command -v homegraph) -> $(homegraph --version 2>/dev/null || echo '?')"
30
-
31
- # 1. Ensure the repo (shallow clone, reuse if present).
32
- mkdir -p "$CORPUS"
33
- if [ -d "$REPO/.git" ]; then
34
- echo "→ reusing checkout: $REPO"
35
- else
36
- echo "→ cloning $URL"
37
- git clone --depth 1 "$URL" "$REPO" || { echo "git clone failed"; exit 1; }
38
- fi
39
-
40
- # 2. Wipe + index with the binary under test.
41
- echo "→ wiping .homegraph and indexing"
42
- rm -rf "$REPO/.homegraph"
43
- ( cd "$REPO" && homegraph init -i ) || { echo "indexing failed"; exit 1; }
44
-
45
- # 3. Verify extraction (cheap guard before the paid A/B).
46
- echo "→ verifying extraction"
47
- node "$HARNESS/verify-extraction.mjs" "$REPO" "$LANG_TOKEN"
48
- VERIFY=$?
49
-
50
- # 4. Retrieval A/B (skipped if extraction is broken, unless FORCE_AB=1).
51
- if [ "$VERIFY" -ne 0 ] && [ "${FORCE_AB:-0}" != "1" ]; then
52
- echo "→ SKIPPING A/B — extraction failed critical checks (set FORCE_AB=1 to override)"
53
- else
54
- echo "→ retrieval A/B (mode=$MODE)"
55
- bash "$AGENT_EVAL/run-all.sh" "$REPO" "$Q" "$MODE"
56
- fi
57
-
58
- echo "==================== bench complete: $NAME (verify exit=$VERIFY) ===================="
59
- # Exit reflects extraction: 0 = pass/warn, 1 = critical fail, 2 = couldn't read status.
60
- exit "$VERIFY"
1
+ #!/usr/bin/env bash
2
+ # Add-lang benchmark for ONE repo:
3
+ # clone -> wipe+index (with the homegraph on PATH) -> verify extraction ->
4
+ # with/without retrieval A/B (reuses scripts/agent-eval/run-all.sh).
5
+ #
6
+ # Assumes the homegraph dev build is already built + linked on PATH — the skill
7
+ # runs `npm run build && ./scripts/local-install.sh` ONCE before looping repos.
8
+ # The A/B is skipped if extraction fails its critical checks (don't burn $ on a
9
+ # broken extractor); set FORCE_AB=1 to run it anyway.
10
+ #
11
+ # Usage: bench.sh <lang> <repo-name> <repo-url> "<question>" [headless|tmux|all]
12
+ # Env: CORPUS corpus dir (default /tmp/homegraph-corpus, shared with agent-eval)
13
+ set -uo pipefail
14
+
15
+ LANG_TOKEN="${1:?usage: bench.sh <lang> <repo-name> <repo-url> \"<question>\" [mode]}"
16
+ NAME="${2:?repo-name required}"
17
+ URL="${3:?repo-url required}"
18
+ Q="${4:?question required}"
19
+ MODE="${5:-headless}"
20
+
21
+ HARNESS="$(cd "$(dirname "$0")" && pwd)"
22
+ AGENT_EVAL="$(cd "$HARNESS/../agent-eval" && pwd)"
23
+ CORPUS="${CORPUS:-/tmp/homegraph-corpus}"
24
+ REPO="$CORPUS/$NAME"
25
+
26
+ command -v homegraph >/dev/null || { echo "no homegraph on PATH (build + ./scripts/local-install.sh first)"; exit 1; }
27
+
28
+ echo "==================== add-lang bench: $NAME ($LANG_TOKEN) ===================="
29
+ echo "homegraph: $(command -v homegraph) -> $(homegraph --version 2>/dev/null || echo '?')"
30
+
31
+ # 1. Ensure the repo (shallow clone, reuse if present).
32
+ mkdir -p "$CORPUS"
33
+ if [ -d "$REPO/.git" ]; then
34
+ echo "→ reusing checkout: $REPO"
35
+ else
36
+ echo "→ cloning $URL"
37
+ git clone --depth 1 "$URL" "$REPO" || { echo "git clone failed"; exit 1; }
38
+ fi
39
+
40
+ # 2. Wipe + index with the binary under test.
41
+ echo "→ wiping .homegraph and indexing"
42
+ rm -rf "$REPO/.homegraph"
43
+ ( cd "$REPO" && homegraph init -i ) || { echo "indexing failed"; exit 1; }
44
+
45
+ # 3. Verify extraction (cheap guard before the paid A/B).
46
+ echo "→ verifying extraction"
47
+ node "$HARNESS/verify-extraction.mjs" "$REPO" "$LANG_TOKEN"
48
+ VERIFY=$?
49
+
50
+ # 4. Retrieval A/B (skipped if extraction is broken, unless FORCE_AB=1).
51
+ if [ "$VERIFY" -ne 0 ] && [ "${FORCE_AB:-0}" != "1" ]; then
52
+ echo "→ SKIPPING A/B — extraction failed critical checks (set FORCE_AB=1 to override)"
53
+ else
54
+ echo "→ retrieval A/B (mode=$MODE)"
55
+ bash "$AGENT_EVAL/run-all.sh" "$REPO" "$Q" "$MODE"
56
+ fi
57
+
58
+ echo "==================== bench complete: $NAME (verify exit=$VERIFY) ===================="
59
+ # Exit reflects extraction: 0 = pass/warn, 1 = critical fail, 2 = couldn't read status.
60
+ exit "$VERIFY"
@@ -1,75 +1,75 @@
1
- #!/usr/bin/env node
2
- // Verify a tree-sitter grammar wasm is HEALTHY under the project's web-tree-sitter
3
- // runtime BEFORE writing an extractor. Prints the ABI version and parses a valid
4
- // sample many times in a multi-grammar context, to catch heap-corruption bugs
5
- // that silently drop nodes on every parse after the first.
6
- //
7
- // Why this exists: the tree-sitter-wasms Lua grammar is ABI 13 and corrupts the
8
- // shared WASM heap under web-tree-sitter 0.25 — Lua extraction degraded on every
9
- // file after the first (nested calls/imports vanished). The fix was to vendor the
10
- // upstream ABI-15 wasm. Run this on any new grammar first; if it FAILs, vendor a
11
- // newer build instead of using the tree-sitter-wasms one.
12
- //
13
- // Usage: node scripts/add-lang/check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]
14
- // Exit: 0 healthy, 1 corruption / parse errors, 2 could not run.
15
- // NOTE: the sample must be SYNTACTICALLY VALID — a broken sample fails for the
16
- // wrong reason.
17
-
18
- import { readFileSync, existsSync } from 'node:fs';
19
- import { createRequire } from 'node:module';
20
- import { Parser, Language } from 'web-tree-sitter';
21
-
22
- const require = createRequire(import.meta.url);
23
- const fail = (code, msg) => { console.error(`[check-grammar] ${msg}`); process.exit(code); };
24
-
25
- const [token, sample, iterArg] = process.argv.slice(2);
26
- if (!token || !sample) fail(2, 'usage: check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]');
27
- if (!existsSync(sample)) fail(2, `sample not found: ${sample}`);
28
- const iters = iterArg ? parseInt(iterArg, 10) : 20;
29
-
30
- const SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
31
- function resolveWasm(t) {
32
- if (t.endsWith('.wasm')) return existsSync(t) ? t : fail(2, `wasm not found: ${t}`);
33
- const base = SPECIAL[t.toLowerCase()] ?? t.toLowerCase();
34
- try { return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`); } catch { /* try vendored */ }
35
- const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
36
- if (existsSync(vendored)) return vendored;
37
- return fail(2, `no grammar for "${t}" — not in tree-sitter-wasms and not vendored`);
38
- }
39
-
40
- const wasmPath = resolveWasm(token);
41
- const source = readFileSync(sample, 'utf8');
42
-
43
- try { await Parser.init(); }
44
- catch { await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') }); }
45
-
46
- // Load a second, known-good grammar — the corruption surfaces under the
47
- // multi-grammar runtime that real indexing uses, not a single grammar in isolation.
48
- try { await Language.load(require.resolve('tree-sitter-wasms/out/tree-sitter-python.wasm')); } catch { /* ok */ }
49
-
50
- let language;
51
- try { language = await Language.load(wasmPath); }
52
- catch (e) { fail(2, `failed to load ${wasmPath}: ${e.message}`); }
53
-
54
- const parser = new Parser();
55
- parser.setLanguage(language);
56
-
57
- let ok = 0, err = 0;
58
- for (let i = 0; i < iters; i++) {
59
- const tree = parser.parse(source);
60
- if (tree.rootNode.hasError) err++; else ok++;
61
- }
62
-
63
- console.log(`grammar: ${wasmPath.split('/').pop()}`);
64
- console.log(` ABI version: ${language.abiVersion}`);
65
- console.log(` parses: ${ok} clean / ${err} with errors (of ${iters})`);
66
- if (err > 0) {
67
- console.log(
68
- `RESULT: FAIL — ${err}/${iters} parses produced ERROR trees on a valid sample. ` +
69
- `This grammar corrupts under web-tree-sitter; vendor a newer (ABI 14/15) wasm ` +
70
- `(see SKILL.md "Find a grammar"). Confirm your sample is syntactically valid first.`
71
- );
72
- process.exit(1);
73
- }
74
- console.log('RESULT: PASS — grammar parses cleanly and reuses safely.');
75
- process.exit(0);
1
+ #!/usr/bin/env node
2
+ // Verify a tree-sitter grammar wasm is HEALTHY under the project's web-tree-sitter
3
+ // runtime BEFORE writing an extractor. Prints the ABI version and parses a valid
4
+ // sample many times in a multi-grammar context, to catch heap-corruption bugs
5
+ // that silently drop nodes on every parse after the first.
6
+ //
7
+ // Why this exists: the tree-sitter-wasms Lua grammar is ABI 13 and corrupts the
8
+ // shared WASM heap under web-tree-sitter 0.25 — Lua extraction degraded on every
9
+ // file after the first (nested calls/imports vanished). The fix was to vendor the
10
+ // upstream ABI-15 wasm. Run this on any new grammar first; if it FAILs, vendor a
11
+ // newer build instead of using the tree-sitter-wasms one.
12
+ //
13
+ // Usage: node scripts/add-lang/check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]
14
+ // Exit: 0 healthy, 1 corruption / parse errors, 2 could not run.
15
+ // NOTE: the sample must be SYNTACTICALLY VALID — a broken sample fails for the
16
+ // wrong reason.
17
+
18
+ import { readFileSync, existsSync } from 'node:fs';
19
+ import { createRequire } from 'node:module';
20
+ import { Parser, Language } from 'web-tree-sitter';
21
+
22
+ const require = createRequire(import.meta.url);
23
+ const fail = (code, msg) => { console.error(`[check-grammar] ${msg}`); process.exit(code); };
24
+
25
+ const [token, sample, iterArg] = process.argv.slice(2);
26
+ if (!token || !sample) fail(2, 'usage: check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]');
27
+ if (!existsSync(sample)) fail(2, `sample not found: ${sample}`);
28
+ const iters = iterArg ? parseInt(iterArg, 10) : 20;
29
+
30
+ const SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
31
+ function resolveWasm(t) {
32
+ if (t.endsWith('.wasm')) return existsSync(t) ? t : fail(2, `wasm not found: ${t}`);
33
+ const base = SPECIAL[t.toLowerCase()] ?? t.toLowerCase();
34
+ try { return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`); } catch { /* try vendored */ }
35
+ const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
36
+ if (existsSync(vendored)) return vendored;
37
+ return fail(2, `no grammar for "${t}" — not in tree-sitter-wasms and not vendored`);
38
+ }
39
+
40
+ const wasmPath = resolveWasm(token);
41
+ const source = readFileSync(sample, 'utf8');
42
+
43
+ try { await Parser.init(); }
44
+ catch { await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') }); }
45
+
46
+ // Load a second, known-good grammar — the corruption surfaces under the
47
+ // multi-grammar runtime that real indexing uses, not a single grammar in isolation.
48
+ try { await Language.load(require.resolve('tree-sitter-wasms/out/tree-sitter-python.wasm')); } catch { /* ok */ }
49
+
50
+ let language;
51
+ try { language = await Language.load(wasmPath); }
52
+ catch (e) { fail(2, `failed to load ${wasmPath}: ${e.message}`); }
53
+
54
+ const parser = new Parser();
55
+ parser.setLanguage(language);
56
+
57
+ let ok = 0, err = 0;
58
+ for (let i = 0; i < iters; i++) {
59
+ const tree = parser.parse(source);
60
+ if (tree.rootNode.hasError) err++; else ok++;
61
+ }
62
+
63
+ console.log(`grammar: ${wasmPath.split('/').pop()}`);
64
+ console.log(` ABI version: ${language.abiVersion}`);
65
+ console.log(` parses: ${ok} clean / ${err} with errors (of ${iters})`);
66
+ if (err > 0) {
67
+ console.log(
68
+ `RESULT: FAIL — ${err}/${iters} parses produced ERROR trees on a valid sample. ` +
69
+ `This grammar corrupts under web-tree-sitter; vendor a newer (ABI 14/15) wasm ` +
70
+ `(see SKILL.md "Find a grammar"). Confirm your sample is syntactically valid first.`
71
+ );
72
+ process.exit(1);
73
+ }
74
+ console.log('RESULT: PASS — grammar parses cleanly and reuses safely.');
75
+ process.exit(0);
@@ -1,103 +1,103 @@
1
- #!/usr/bin/env node
2
- // Dump the tree-sitter AST for a sample file so you can write a LanguageExtractor
3
- // mapping. Loads a grammar .wasm directly via web-tree-sitter (the same runtime
4
- // homegraph uses) — you do NOT need to register the language first.
5
- //
6
- // Usage:
7
- // node scripts/add-lang/dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]
8
- // Examples:
9
- // node scripts/add-lang/dump-ast.mjs lua sample.lua
10
- // node scripts/add-lang/dump-ast.mjs src/extraction/wasm/tree-sitter-zig.wasm a.zig --depth=4
11
- //
12
- // Output: an indented AST (named nodes, with field names) followed by a
13
- // node-type FREQUENCY table. The frequency table is the payoff — it tells you
14
- // which node types to map to functionTypes / classTypes / importTypes / etc.
15
-
16
- import { readFileSync, existsSync } from 'node:fs';
17
- import { createRequire } from 'node:module';
18
- import { Parser, Language } from 'web-tree-sitter';
19
-
20
- const require = createRequire(import.meta.url);
21
- const fail = (msg) => { console.error(`[dump-ast] ${msg}`); process.exit(1); };
22
-
23
- const argv = process.argv.slice(2);
24
- const positional = argv.filter((a) => !a.startsWith('--'));
25
- const [langOrWasm, sampleFile] = positional;
26
- const depthFlag = argv.find((a) => a.startsWith('--depth='));
27
- const showAll = argv.includes('--full'); // also print anonymous (token) nodes
28
- const maxDepth = depthFlag ? parseInt(depthFlag.split('=')[1], 10) : (showAll ? Infinity : 8);
29
-
30
- if (!langOrWasm || !sampleFile) {
31
- fail('usage: dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]');
32
- }
33
- if (!existsSync(sampleFile)) fail(`sample file not found: ${sampleFile}`);
34
-
35
- // Language tokens whose tree-sitter-wasms filename differs from the token.
36
- const WASM_SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
37
-
38
- function resolveWasm(token) {
39
- if (token.endsWith('.wasm')) {
40
- if (!existsSync(token)) fail(`wasm not found: ${token}`);
41
- return token;
42
- }
43
- const base = WASM_SPECIAL[token.toLowerCase()] ?? token.toLowerCase();
44
- try {
45
- return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`);
46
- } catch {
47
- /* not in tree-sitter-wasms — try a vendored copy */
48
- }
49
- const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
50
- if (existsSync(vendored)) return vendored;
51
- fail(
52
- `no grammar for "${token}" — not in tree-sitter-wasms and not vendored at ` +
53
- `${vendored}. Pass an explicit .wasm path, or vendor one (see SKILL.md "Find a grammar").`
54
- );
55
- }
56
-
57
- const wasmPath = resolveWasm(langOrWasm);
58
- const source = readFileSync(sampleFile, 'utf8');
59
-
60
- try {
61
- await Parser.init();
62
- } catch {
63
- await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') });
64
- }
65
-
66
- let language;
67
- try {
68
- language = await Language.load(wasmPath);
69
- } catch (e) {
70
- fail(`failed to load grammar ${wasmPath}: ${e.message}`);
71
- }
72
-
73
- const parser = new Parser();
74
- parser.setLanguage(language);
75
- const tree = parser.parse(source);
76
-
77
- const freq = new Map();
78
- const snippet = (node) => {
79
- const t = node.text.replace(/\s+/g, ' ').trim();
80
- return t.length > 48 ? `${t.slice(0, 48)}…` : t;
81
- };
82
-
83
- function walk(node, depth, fieldName) {
84
- if (node.isNamed) freq.set(node.type, (freq.get(node.type) || 0) + 1);
85
- if ((node.isNamed || showAll) && depth <= maxDepth) {
86
- const field = fieldName ? `${fieldName}: ` : '';
87
- const leaf = node.childCount === 0 ? ` "${snippet(node)}"` : '';
88
- console.log(`${' '.repeat(depth)}${field}${node.type} @${node.startPosition.row + 1}:${node.startPosition.column}${leaf}`);
89
- }
90
- for (let i = 0; i < node.childCount; i++) {
91
- const child = node.child(i);
92
- if (child) walk(child, depth + 1, node.fieldNameForChild(i));
93
- }
94
- }
95
-
96
- console.log(`\n# AST for ${sampleFile} (grammar: ${wasmPath.split('/').pop()})\n`);
97
- walk(tree.rootNode, 0, null);
98
-
99
- console.log('\n# Node-type frequency (named nodes) — map the relevant ones in your extractor:\n');
100
- [...freq.entries()]
101
- .sort((a, b) => b[1] - a[1])
102
- .forEach(([type, n]) => console.log(` ${String(n).padStart(5)} ${type}`));
103
- console.log();
1
+ #!/usr/bin/env node
2
+ // Dump the tree-sitter AST for a sample file so you can write a LanguageExtractor
3
+ // mapping. Loads a grammar .wasm directly via web-tree-sitter (the same runtime
4
+ // homegraph uses) — you do NOT need to register the language first.
5
+ //
6
+ // Usage:
7
+ // node scripts/add-lang/dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]
8
+ // Examples:
9
+ // node scripts/add-lang/dump-ast.mjs lua sample.lua
10
+ // node scripts/add-lang/dump-ast.mjs src/extraction/wasm/tree-sitter-zig.wasm a.zig --depth=4
11
+ //
12
+ // Output: an indented AST (named nodes, with field names) followed by a
13
+ // node-type FREQUENCY table. The frequency table is the payoff — it tells you
14
+ // which node types to map to functionTypes / classTypes / importTypes / etc.
15
+
16
+ import { readFileSync, existsSync } from 'node:fs';
17
+ import { createRequire } from 'node:module';
18
+ import { Parser, Language } from 'web-tree-sitter';
19
+
20
+ const require = createRequire(import.meta.url);
21
+ const fail = (msg) => { console.error(`[dump-ast] ${msg}`); process.exit(1); };
22
+
23
+ const argv = process.argv.slice(2);
24
+ const positional = argv.filter((a) => !a.startsWith('--'));
25
+ const [langOrWasm, sampleFile] = positional;
26
+ const depthFlag = argv.find((a) => a.startsWith('--depth='));
27
+ const showAll = argv.includes('--full'); // also print anonymous (token) nodes
28
+ const maxDepth = depthFlag ? parseInt(depthFlag.split('=')[1], 10) : (showAll ? Infinity : 8);
29
+
30
+ if (!langOrWasm || !sampleFile) {
31
+ fail('usage: dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]');
32
+ }
33
+ if (!existsSync(sampleFile)) fail(`sample file not found: ${sampleFile}`);
34
+
35
+ // Language tokens whose tree-sitter-wasms filename differs from the token.
36
+ const WASM_SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
37
+
38
+ function resolveWasm(token) {
39
+ if (token.endsWith('.wasm')) {
40
+ if (!existsSync(token)) fail(`wasm not found: ${token}`);
41
+ return token;
42
+ }
43
+ const base = WASM_SPECIAL[token.toLowerCase()] ?? token.toLowerCase();
44
+ try {
45
+ return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`);
46
+ } catch {
47
+ /* not in tree-sitter-wasms — try a vendored copy */
48
+ }
49
+ const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
50
+ if (existsSync(vendored)) return vendored;
51
+ fail(
52
+ `no grammar for "${token}" — not in tree-sitter-wasms and not vendored at ` +
53
+ `${vendored}. Pass an explicit .wasm path, or vendor one (see SKILL.md "Find a grammar").`
54
+ );
55
+ }
56
+
57
+ const wasmPath = resolveWasm(langOrWasm);
58
+ const source = readFileSync(sampleFile, 'utf8');
59
+
60
+ try {
61
+ await Parser.init();
62
+ } catch {
63
+ await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') });
64
+ }
65
+
66
+ let language;
67
+ try {
68
+ language = await Language.load(wasmPath);
69
+ } catch (e) {
70
+ fail(`failed to load grammar ${wasmPath}: ${e.message}`);
71
+ }
72
+
73
+ const parser = new Parser();
74
+ parser.setLanguage(language);
75
+ const tree = parser.parse(source);
76
+
77
+ const freq = new Map();
78
+ const snippet = (node) => {
79
+ const t = node.text.replace(/\s+/g, ' ').trim();
80
+ return t.length > 48 ? `${t.slice(0, 48)}…` : t;
81
+ };
82
+
83
+ function walk(node, depth, fieldName) {
84
+ if (node.isNamed) freq.set(node.type, (freq.get(node.type) || 0) + 1);
85
+ if ((node.isNamed || showAll) && depth <= maxDepth) {
86
+ const field = fieldName ? `${fieldName}: ` : '';
87
+ const leaf = node.childCount === 0 ? ` "${snippet(node)}"` : '';
88
+ console.log(`${' '.repeat(depth)}${field}${node.type} @${node.startPosition.row + 1}:${node.startPosition.column}${leaf}`);
89
+ }
90
+ for (let i = 0; i < node.childCount; i++) {
91
+ const child = node.child(i);
92
+ if (child) walk(child, depth + 1, node.fieldNameForChild(i));
93
+ }
94
+ }
95
+
96
+ console.log(`\n# AST for ${sampleFile} (grammar: ${wasmPath.split('/').pop()})\n`);
97
+ walk(tree.rootNode, 0, null);
98
+
99
+ console.log('\n# Node-type frequency (named nodes) — map the relevant ones in your extractor:\n');
100
+ [...freq.entries()]
101
+ .sort((a, b) => b[1] - a[1])
102
+ .forEach(([type, n]) => console.log(` ${String(n).padStart(5)} ${type}`));
103
+ console.log();