@saluzi/codegraph 0.1.0 → 0.2.0

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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/package.json +42 -10
  4. package/scripts/add-lang/bench.sh +60 -0
  5. package/scripts/add-lang/check-grammar.mjs +75 -0
  6. package/scripts/add-lang/dump-ast.mjs +103 -0
  7. package/scripts/add-lang/verify-extraction.mjs +70 -0
  8. package/scripts/agent-eval/ab-adoption.sh +91 -0
  9. package/scripts/agent-eval/ab-hook.sh +86 -0
  10. package/scripts/agent-eval/ab-impl.sh +78 -0
  11. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  12. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  13. package/scripts/agent-eval/arms-F.sh +21 -0
  14. package/scripts/agent-eval/arms-matrix.sh +37 -0
  15. package/scripts/agent-eval/audit.sh +68 -0
  16. package/scripts/agent-eval/bench-readme.sh +28 -0
  17. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  18. package/scripts/agent-eval/block-read-hook.sh +19 -0
  19. package/scripts/agent-eval/hook-settings.json +15 -0
  20. package/scripts/agent-eval/itrun.sh +120 -0
  21. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  22. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  23. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  24. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  25. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  26. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  27. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  28. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  29. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  30. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  31. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  32. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  33. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  34. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  35. package/scripts/agent-eval/offload-eval.md +76 -0
  36. package/scripts/agent-eval/parse-arms.mjs +116 -0
  37. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  38. package/scripts/agent-eval/parse-run.mjs +45 -0
  39. package/scripts/agent-eval/parse-session.mjs +93 -0
  40. package/scripts/agent-eval/probe-context.mjs +21 -0
  41. package/scripts/agent-eval/probe-explore.mjs +40 -0
  42. package/scripts/agent-eval/probe-node.mjs +20 -0
  43. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  44. package/scripts/agent-eval/probe-trace.mjs +20 -0
  45. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  46. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  47. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  48. package/scripts/agent-eval/run-agent.sh +34 -0
  49. package/scripts/agent-eval/run-all.sh +75 -0
  50. package/scripts/agent-eval/run-arms.sh +56 -0
  51. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  52. package/scripts/build-bundle.sh +123 -0
  53. package/scripts/extract-release-notes.mjs +130 -0
  54. package/scripts/local-install.sh +41 -0
  55. package/scripts/npm-sdk.js +75 -0
  56. package/scripts/npm-shim.js +275 -0
  57. package/scripts/pack-npm.sh +119 -0
  58. package/scripts/prepare-release.mjs +270 -0
  59. package/dist/bin/codegraph.d.ts +0 -25
  60. package/dist/bin/node-version-check.d.ts +0 -37
  61. package/dist/bin/uninstall.d.ts +0 -14
  62. package/dist/context/formatter.d.ts +0 -33
  63. package/dist/context/formatter.js +0 -244
  64. package/dist/context/index.d.ts +0 -117
  65. package/dist/context/index.js +0 -1050
  66. package/dist/db/index.d.ts +0 -101
  67. package/dist/db/index.js +0 -250
  68. package/dist/db/migrations.d.ts +0 -47
  69. package/dist/db/migrations.js +0 -131
  70. package/dist/db/queries.d.ts +0 -291
  71. package/dist/db/queries.js +0 -1349
  72. package/dist/db/schema.sql +0 -151
  73. package/dist/db/sqlite-adapter.d.ts +0 -49
  74. package/dist/db/sqlite-adapter.js +0 -141
  75. package/dist/directory.d.ts +0 -62
  76. package/dist/directory.js +0 -264
  77. package/dist/errors.d.ts +0 -149
  78. package/dist/errors.js +0 -219
  79. package/dist/extraction/dfm-extractor.d.ts +0 -31
  80. package/dist/extraction/dfm-extractor.js +0 -151
  81. package/dist/extraction/grammars.d.ts +0 -94
  82. package/dist/extraction/grammars.js +0 -357
  83. package/dist/extraction/index.d.ts +0 -148
  84. package/dist/extraction/index.js +0 -1286
  85. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  86. package/dist/extraction/languages/c-cpp.js +0 -126
  87. package/dist/extraction/languages/csharp.d.ts +0 -3
  88. package/dist/extraction/languages/csharp.js +0 -72
  89. package/dist/extraction/languages/dart.d.ts +0 -3
  90. package/dist/extraction/languages/dart.js +0 -192
  91. package/dist/extraction/languages/go.d.ts +0 -3
  92. package/dist/extraction/languages/go.js +0 -58
  93. package/dist/extraction/languages/index.d.ts +0 -10
  94. package/dist/extraction/languages/index.js +0 -49
  95. package/dist/extraction/languages/java.d.ts +0 -3
  96. package/dist/extraction/languages/java.js +0 -64
  97. package/dist/extraction/languages/javascript.d.ts +0 -3
  98. package/dist/extraction/languages/javascript.js +0 -90
  99. package/dist/extraction/languages/kotlin.d.ts +0 -3
  100. package/dist/extraction/languages/kotlin.js +0 -253
  101. package/dist/extraction/languages/lua.d.ts +0 -3
  102. package/dist/extraction/languages/lua.js +0 -150
  103. package/dist/extraction/languages/luau.d.ts +0 -3
  104. package/dist/extraction/languages/luau.js +0 -37
  105. package/dist/extraction/languages/pascal.d.ts +0 -3
  106. package/dist/extraction/languages/pascal.js +0 -66
  107. package/dist/extraction/languages/php.d.ts +0 -3
  108. package/dist/extraction/languages/php.js +0 -107
  109. package/dist/extraction/languages/python.d.ts +0 -3
  110. package/dist/extraction/languages/python.js +0 -56
  111. package/dist/extraction/languages/ruby.d.ts +0 -3
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/rust.d.ts +0 -3
  114. package/dist/extraction/languages/rust.js +0 -109
  115. package/dist/extraction/languages/scala.d.ts +0 -3
  116. package/dist/extraction/languages/scala.js +0 -139
  117. package/dist/extraction/languages/swift.d.ts +0 -3
  118. package/dist/extraction/languages/swift.js +0 -91
  119. package/dist/extraction/languages/typescript.d.ts +0 -3
  120. package/dist/extraction/languages/typescript.js +0 -129
  121. package/dist/extraction/liquid-extractor.d.ts +0 -52
  122. package/dist/extraction/liquid-extractor.js +0 -313
  123. package/dist/extraction/parse-worker.d.ts +0 -8
  124. package/dist/extraction/parse-worker.js +0 -94
  125. package/dist/extraction/svelte-extractor.d.ts +0 -56
  126. package/dist/extraction/svelte-extractor.js +0 -272
  127. package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
  128. package/dist/extraction/tree-sitter-helpers.js +0 -103
  129. package/dist/extraction/tree-sitter-types.d.ts +0 -191
  130. package/dist/extraction/tree-sitter-types.js +0 -10
  131. package/dist/extraction/tree-sitter.d.ts +0 -238
  132. package/dist/extraction/tree-sitter.js +0 -2430
  133. package/dist/extraction/vue-extractor.d.ts +0 -36
  134. package/dist/extraction/vue-extractor.js +0 -163
  135. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  136. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  137. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  138. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  139. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  140. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  141. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  142. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  143. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  144. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  145. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  146. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  147. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  148. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  149. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  150. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  151. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  152. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  153. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  154. package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
  155. package/dist/extraction/wasm-runtime-flags.js +0 -105
  156. package/dist/graph/index.d.ts +0 -8
  157. package/dist/graph/index.js +0 -13
  158. package/dist/graph/queries.d.ts +0 -109
  159. package/dist/graph/queries.js +0 -366
  160. package/dist/graph/traversal.d.ts +0 -137
  161. package/dist/graph/traversal.js +0 -528
  162. package/dist/index.d.ts +0 -509
  163. package/dist/index.js +0 -800
  164. package/dist/installer/claude-md-template.d.ts +0 -19
  165. package/dist/installer/config-writer.d.ts +0 -29
  166. package/dist/installer/index.d.ts +0 -140
  167. package/dist/installer/instructions-template.d.ts +0 -30
  168. package/dist/installer/targets/claude.d.ts +0 -55
  169. package/dist/installer/targets/codex.d.ts +0 -18
  170. package/dist/installer/targets/cursor.d.ts +0 -35
  171. package/dist/installer/targets/hermes.d.ts +0 -18
  172. package/dist/installer/targets/opencode.d.ts +0 -30
  173. package/dist/installer/targets/registry.d.ts +0 -38
  174. package/dist/installer/targets/shared.d.ts +0 -92
  175. package/dist/installer/targets/toml.d.ts +0 -64
  176. package/dist/installer/targets/types.d.ts +0 -122
  177. package/dist/mcp/index.d.ts +0 -98
  178. package/dist/mcp/server-instructions.d.ts +0 -20
  179. package/dist/mcp/tools.d.ts +0 -269
  180. package/dist/mcp/transport.d.ts +0 -117
  181. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
  182. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  183. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  184. package/dist/resolution/frameworks/csharp.js +0 -213
  185. package/dist/resolution/frameworks/drupal.d.ts +0 -51
  186. package/dist/resolution/frameworks/drupal.js +0 -335
  187. package/dist/resolution/frameworks/express.d.ts +0 -8
  188. package/dist/resolution/frameworks/express.js +0 -225
  189. package/dist/resolution/frameworks/go.d.ts +0 -8
  190. package/dist/resolution/frameworks/go.js +0 -158
  191. package/dist/resolution/frameworks/index.d.ts +0 -52
  192. package/dist/resolution/frameworks/index.js +0 -137
  193. package/dist/resolution/frameworks/java.d.ts +0 -8
  194. package/dist/resolution/frameworks/java.js +0 -177
  195. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  196. package/dist/resolution/frameworks/laravel.js +0 -248
  197. package/dist/resolution/frameworks/nestjs.d.ts +0 -26
  198. package/dist/resolution/frameworks/nestjs.js +0 -374
  199. package/dist/resolution/frameworks/python.d.ts +0 -10
  200. package/dist/resolution/frameworks/python.js +0 -278
  201. package/dist/resolution/frameworks/react.d.ts +0 -8
  202. package/dist/resolution/frameworks/react.js +0 -272
  203. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  204. package/dist/resolution/frameworks/ruby.js +0 -198
  205. package/dist/resolution/frameworks/rust.d.ts +0 -8
  206. package/dist/resolution/frameworks/rust.js +0 -207
  207. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  208. package/dist/resolution/frameworks/svelte.js +0 -249
  209. package/dist/resolution/frameworks/swift.d.ts +0 -10
  210. package/dist/resolution/frameworks/swift.js +0 -376
  211. package/dist/resolution/frameworks/vue.d.ts +0 -9
  212. package/dist/resolution/frameworks/vue.js +0 -306
  213. package/dist/resolution/import-resolver.d.ts +0 -61
  214. package/dist/resolution/import-resolver.js +0 -663
  215. package/dist/resolution/index.d.ts +0 -118
  216. package/dist/resolution/index.js +0 -744
  217. package/dist/resolution/lru-cache.d.ts +0 -24
  218. package/dist/resolution/lru-cache.js +0 -62
  219. package/dist/resolution/name-matcher.d.ts +0 -50
  220. package/dist/resolution/name-matcher.js +0 -384
  221. package/dist/resolution/path-aliases.d.ts +0 -72
  222. package/dist/resolution/path-aliases.js +0 -238
  223. package/dist/resolution/strip-comments.d.ts +0 -40
  224. package/dist/resolution/strip-comments.js +0 -441
  225. package/dist/resolution/types.d.ts +0 -181
  226. package/dist/resolution/types.js +0 -8
  227. package/dist/search/query-parser.d.ts +0 -61
  228. package/dist/search/query-parser.js +0 -177
  229. package/dist/search/query-utils.d.ts +0 -59
  230. package/dist/search/query-utils.js +0 -383
  231. package/dist/sync/git-hooks.d.ts +0 -54
  232. package/dist/sync/git-hooks.js +0 -223
  233. package/dist/sync/index.d.ts +0 -25
  234. package/dist/sync/index.js +0 -28
  235. package/dist/sync/watch-policy.d.ts +0 -51
  236. package/dist/sync/watch-policy.js +0 -124
  237. package/dist/sync/watcher.d.ts +0 -83
  238. package/dist/sync/watcher.js +0 -192
  239. package/dist/types.d.ts +0 -433
  240. package/dist/types.js +0 -75
  241. package/dist/ui/glyphs.d.ts +0 -42
  242. package/dist/ui/shimmer-progress.d.ts +0 -11
  243. package/dist/ui/shimmer-worker.d.ts +0 -2
  244. package/dist/ui/types.d.ts +0 -20
  245. package/dist/utils.d.ts +0 -231
  246. package/dist/utils.js +0 -549
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bash
2
+ # With/without A/B (and optional interactive) eval for a codegraph version on a
3
+ # repo. Codegraph is the ONLY variable: both arms launch claude with
4
+ # --strict-mcp-config — with = codegraph-only MCP (pointed at $CG_BIN),
5
+ # without = empty MCP. Built-in Read/Grep/Bash stay available in both arms.
6
+ #
7
+ # Usage: run-all.sh <repo-path> "<question>" [headless|tmux|all]
8
+ # Env: CG_BIN codegraph binary (default: command -v codegraph)
9
+ # AGENT_EVAL_OUT output dir (default: /tmp/agent-eval)
10
+ # MODEL / EFFORT claude model/effort (default: sonnet / high — the
11
+ # standing A/B policy; see CLAUDE.md, don't raise)
12
+ set -uo pipefail
13
+
14
+ REPO="${1:?usage: run-all.sh <repo-path> \"<question>\" [headless|tmux|all]}"
15
+ Q="${2:?question required}"
16
+ MODE="${3:-headless}"
17
+ CG_BIN="${CG_BIN:-$(command -v codegraph)}"
18
+ OUT="${AGENT_EVAL_OUT:-/tmp/agent-eval}"
19
+ HARNESS="$(cd "$(dirname "$0")" && pwd)"
20
+ mkdir -p "$OUT"
21
+
22
+ # Neutralize any ambient CodeGraph prompt-hook (~/.claude) in BOTH arms:
23
+ # the hook injects codegraph context into every prompt, which contaminates
24
+ # the without-arm (free structural context) and double-counts the with-arm.
25
+ # The A/B's only variable must be the MCP server wired below.
26
+ export CODEGRAPH_NO_PROMPT_HOOK=1
27
+
28
+ [ -n "$CG_BIN" ] || { echo "no codegraph binary on PATH (set CG_BIN)"; exit 1; }
29
+ [ -d "$REPO/.codegraph" ] || { echo "no .codegraph index at $REPO — index it first"; exit 1; }
30
+ case "$MODE" in headless|tmux|all) ;; *) echo "mode must be headless|tmux|all (got '$MODE')"; exit 1;; esac
31
+
32
+ # MCP config files (path form avoids inline-JSON quoting through tmux).
33
+ cat > "$OUT/mcp-codegraph.json" <<JSON
34
+ {"mcpServers":{"codegraph":{"command":"$CG_BIN","args":["serve","--mcp","--path","$REPO"]}}}
35
+ JSON
36
+ echo '{"mcpServers":{}}' > "$OUT/mcp-empty.json"
37
+
38
+ echo "###### codegraph: $CG_BIN"
39
+ echo "###### repo: $REPO"
40
+ echo "###### question: $Q"
41
+ echo
42
+
43
+ # Headless arm: claude -p with stream-json -> exact tool sequence + tokens/cost.
44
+ headless() {
45
+ local label="$1" cfg="$2"
46
+ echo "############################## HEADLESS [$label] ##############################"
47
+ ( cd "$REPO" && claude -p "$Q" \
48
+ --output-format stream-json --verbose \
49
+ --permission-mode bypassPermissions \
50
+ --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" \
51
+ --max-budget-usd 4 \
52
+ --strict-mcp-config --mcp-config "$cfg" \
53
+ > "$OUT/run-$label.jsonl" 2>"$OUT/run-$label.err" )
54
+ echo "exit $? -> $OUT/run-$label.jsonl ($(wc -l < "$OUT/run-$label.jsonl" | tr -d ' ') lines)"
55
+ tail -2 "$OUT/run-$label.err" 2>/dev/null
56
+ node "$HARNESS/parse-run.mjs" "$OUT/run-$label.jsonl" 2>&1 || true
57
+ echo
58
+ }
59
+
60
+ if [ "$MODE" = headless ] || [ "$MODE" = all ]; then
61
+ headless "headless-with" "$OUT/mcp-codegraph.json"
62
+ headless "headless-without" "$OUT/mcp-empty.json"
63
+ fi
64
+
65
+ if [ "$MODE" = tmux ] || [ "$MODE" = all ]; then
66
+ echo "############################## INTERACTIVE [with] ##############################"
67
+ CLAUDE_EXTRA_ARGS="--model ${MODEL:-sonnet} --effort ${EFFORT:-high} --strict-mcp-config --mcp-config $OUT/mcp-codegraph.json" \
68
+ bash "$HARNESS/itrun.sh" "$REPO" "int-with" "$Q" 2>&1 || echo "[itrun WITH failed]"
69
+ echo
70
+ echo "############################## INTERACTIVE [without] ##############################"
71
+ CLAUDE_EXTRA_ARGS="--model ${MODEL:-sonnet} --effort ${EFFORT:-high} --strict-mcp-config --mcp-config $OUT/mcp-empty.json" \
72
+ bash "$HARNESS/itrun.sh" "$REPO" "int-without" "$Q" 2>&1 || echo "[itrun WITHOUT failed]"
73
+ echo
74
+ fi
75
+ echo "############################## RUN-ALL COMPLETE ##############################"
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bash
2
+ # Tool-surface ablation — run ONE repo+question under ONE arm.
3
+ #
4
+ # Arms vary (exposed codegraph tools, trace-first steering). Tools are trimmed
5
+ # SERVER-SIDE via CODEGRAPH_MCP_TOOLS in the MCP config's `env` block, so an
6
+ # ablated tool is genuinely absent from ListTools — no deferred-ToolSearch or
7
+ # denied-call confound (which --disallowedTools would introduce). Steering is
8
+ # injected with --append-system-prompt, so no rebuild of the shipped
9
+ # server-instructions is needed to A/B it.
10
+ #
11
+ # A control all tools no steering
12
+ # B steer all tools trace-first
13
+ # C no-explore hide explore trace-first
14
+ # D trace-centric hide explore+context trace-first
15
+ # E control-probe hide explore+context trace-first (caller passes a NON-flow Q)
16
+ #
17
+ # Usage: run-arms.sh <repo-path> "<question>" <A|B|C|D|E> [run-id]
18
+ set -uo pipefail
19
+ REPO="${1:?repo path}"; Q="${2:?question}"; ARM="${3:?arm A-E}"; RID="${4:-1}"
20
+ CG_BIN="${CG_BIN:-$(command -v codegraph)}"
21
+ OUT="${ARMS_OUT:-/tmp/arms}/$(basename "$REPO")"
22
+ mkdir -p "$OUT"
23
+ [ -n "$CG_BIN" ] || { echo "no codegraph binary (set CG_BIN)"; exit 1; }
24
+ [ -d "$REPO/.codegraph" ] || { echo "no .codegraph index at $REPO"; exit 1; }
25
+
26
+ STEER='Flow questions ("how does X reach/become Y", "trace the flow", request to handler, state to render): call codegraph_trace(from,to) FIRST — one call returns the whole path. Use codegraph_context/search only to locate the two endpoint symbols if you do not know them. Do NOT reconstruct the path with repeated search/callers/explore.'
27
+ KEEP_NO_EXPLORE="trace,search,node,context,callers,callees,impact,files,status"
28
+ KEEP_TRACE_CENTRIC="trace,search,node,callers,callees,impact,files,status"
29
+
30
+ case "$ARM" in
31
+ A|G|H|I) TOOLS=""; STEERING="" ;; # no steering; H = body-trace, I = body-trace + destination callees (sufficiency)
32
+ B|F) TOOLS=""; STEERING="$STEER" ;; # F = B's surface, run on the body-inlining trace build
33
+ C) TOOLS="$KEEP_NO_EXPLORE"; STEERING="$STEER" ;;
34
+ D|E) TOOLS="$KEEP_TRACE_CENTRIC"; STEERING="$STEER" ;;
35
+ *) echo "bad arm '$ARM' (want A|B|C|D|E)"; exit 1 ;;
36
+ esac
37
+
38
+ CFG="$OUT/mcp-$ARM.json"
39
+ if [ -n "$TOOLS" ]; then
40
+ cat > "$CFG" <<JSON
41
+ {"mcpServers":{"codegraph":{"command":"$CG_BIN","args":["serve","--mcp","--path","$REPO"],"env":{"CODEGRAPH_MCP_TOOLS":"$TOOLS"}}}}
42
+ JSON
43
+ else
44
+ cat > "$CFG" <<JSON
45
+ {"mcpServers":{"codegraph":{"command":"$CG_BIN","args":["serve","--mcp","--path","$REPO"]}}}
46
+ JSON
47
+ fi
48
+
49
+ LOG="$OUT/$ARM-r$RID.jsonl"; ERR="$OUT/$ARM-r$RID.err"
50
+ ARGS=( -p "$Q" --output-format stream-json --verbose
51
+ --permission-mode bypassPermissions --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4
52
+ --strict-mcp-config --mcp-config "$CFG" )
53
+ [ -n "$STEERING" ] && ARGS+=( --append-system-prompt "$STEERING" )
54
+
55
+ ( cd "$REPO" && claude "${ARGS[@]}" > "$LOG" 2>"$ERR" )
56
+ echo "[$(basename "$REPO") $ARM r$RID] exit $? -> $LOG ($(wc -l < "$LOG" | tr -d ' ') lines)"
@@ -0,0 +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 codegraph_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/codegraph-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__codegraph__codegraph_', '').replace('mcp__codegraph__', '');
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('codegraph') ? 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 => /codegraph/.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('codegraph'));
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 codegraph 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 codegraph 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=== codegraph 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 codegraph 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'}`);
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Build a self-contained CodeGraph bundle: an official Node runtime + the
4
+ # compiled app + its production deps, so CodeGraph 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/codegraph-<target>.tar.gz (launcher: bin/codegraph)
20
+ # windows: release/codegraph-<target>.zip (launcher: bin/codegraph.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/codegraph-${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\\codegraph.js" %%*\r\n' \
85
+ > "$STAGE/bin/codegraph.cmd"
86
+ else
87
+ cp "$NODE_BIN" "$STAGE/node"
88
+ cat > "$STAGE/bin/codegraph" <<'LAUNCH'
89
+ #!/bin/sh
90
+ # Resolve symlinks (e.g. the ~/.local/bin/codegraph 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
+ # Thread the MCP host's pid to the server's orphan watchdog (issue #1185).
102
+ # $PPID is our parent — the host itself when it launched this script directly;
103
+ # an already-threaded value (the npm shim sets the true host pid) wins.
104
+ CODEGRAPH_HOST_PPID="${CODEGRAPH_HOST_PPID:-$PPID}"
105
+ export CODEGRAPH_HOST_PPID
106
+ # --liftoff-only: avoid the V8 turboshaft WASM Zone OOM (issues #293/#298).
107
+ exec "$DIR/node" --liftoff-only "$DIR/lib/dist/bin/codegraph.js" "$@"
108
+ LAUNCH
109
+ chmod +x "$STAGE/bin/codegraph"
110
+ fi
111
+
112
+ # 5. Archive (.zip for Windows, .tar.gz otherwise).
113
+ mkdir -p "$OUT"
114
+ if [ "$OSFAM" = "win32" ]; then
115
+ ARCHIVE="$OUT/codegraph-${TARGET}.zip"
116
+ rm -f "$ARCHIVE"
117
+ ( cd "$WORK" && zip -rqX "$ARCHIVE" "codegraph-${TARGET}" )
118
+ else
119
+ ARCHIVE="$OUT/codegraph-${TARGET}.tar.gz"
120
+ # --no-xattrs: don't embed macOS xattrs that make GNU tar warn on Linux.
121
+ tar --no-xattrs -czf "$ARCHIVE" -C "$WORK" "codegraph-${TARGET}"
122
+ fi
123
+ echo "[bundle] wrote ${ARCHIVE} ($(du -h "$ARCHIVE" | cut -f1))"
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Extract a release-notes block from CHANGELOG.md for a given version
4
+ * (or unwrap text supplied on stdin), then join hard-wrapped paragraphs.
5
+ *
6
+ * Why: GitHub renders release-note Markdown with GFM hard breaks, so
7
+ * every `\n` becomes `<br>`. The CHANGELOG is hard-wrapped at ~75
8
+ * chars for readable diffs, which then renders as awkward visible
9
+ * line breaks on the release page. This script joins indented
10
+ * continuation lines into a single line per bullet so the GFM
11
+ * renderer produces clean paragraphs.
12
+ *
13
+ * Repo-level CHANGELOG.md viewing is unaffected (CommonMark treats
14
+ * newlines as spaces there).
15
+ *
16
+ * Usage:
17
+ * extract-release-notes.mjs <version> # read CHANGELOG.md
18
+ * extract-release-notes.mjs --stdin # read from stdin (any text)
19
+ */
20
+
21
+ import { readFileSync } from 'fs';
22
+
23
+ const arg = process.argv[2];
24
+ if (!arg) {
25
+ console.error('usage: extract-release-notes.mjs <version> | --stdin');
26
+ process.exit(1);
27
+ }
28
+
29
+ let block;
30
+ if (arg === '--stdin') {
31
+ block = readFileSync(0, 'utf8').replace(/\r\n?/g, '\n').split('\n');
32
+ } else {
33
+ const version = arg;
34
+ const escaped = version.replace(/\./g, '\\.');
35
+ const headerRe = new RegExp(`^## \\[${escaped}\\]`);
36
+ const anyHeaderRe = /^## \[/;
37
+ const lines = readFileSync('CHANGELOG.md', 'utf8').split('\n');
38
+ const start = lines.findIndex((l) => headerRe.test(l));
39
+ if (start === -1) {
40
+ console.error(`no '## [${version}]' entry found in CHANGELOG.md`);
41
+ process.exit(1);
42
+ }
43
+ const after = lines.findIndex((l, i) => i > start && anyHeaderRe.test(l));
44
+ block = lines.slice(start, after === -1 ? lines.length : after);
45
+ }
46
+
47
+ // Track a stack of `{ indent: number }` frames so a continuation line
48
+ // can attach to the right ancestor. Handles the post-nested-list
49
+ // continuation pattern:
50
+ //
51
+ // - top-level
52
+ // - nested
53
+ // back to top-level <- 2-space indent, joins the top-level bullet
54
+ const out = [];
55
+ let buf = '';
56
+ let stack = [];
57
+
58
+ function flushBuf() {
59
+ if (buf !== '') {
60
+ out.push(buf);
61
+ buf = '';
62
+ }
63
+ }
64
+
65
+ function leadingSpaces(s) {
66
+ const m = s.match(/^(\s*)/);
67
+ return m ? m[1].length : 0;
68
+ }
69
+
70
+ // Bullets: `-`, `*`, `digit.` only. `+` is intentionally excluded — the
71
+ // CHANGELOG uses literal `+` inline (`config + instructions`) and we
72
+ // don't want to misread those as nested bullets.
73
+ const listItemRe = /^(\s*)([-*]|\d+\.)\s+/;
74
+ const fenceRe = /^\s*```/;
75
+
76
+ let inFence = false;
77
+
78
+ for (const line of block) {
79
+ // Fenced code blocks: pass through verbatim, no joining.
80
+ if (fenceRe.test(line)) {
81
+ flushBuf();
82
+ stack = [];
83
+ out.push(line);
84
+ inFence = !inFence;
85
+ continue;
86
+ }
87
+ if (inFence) {
88
+ out.push(line);
89
+ continue;
90
+ }
91
+ if (/^\s*$/.test(line)) {
92
+ flushBuf();
93
+ out.push('');
94
+ continue;
95
+ }
96
+ if (/^#/.test(line)) {
97
+ flushBuf();
98
+ stack = [];
99
+ out.push(line);
100
+ continue;
101
+ }
102
+ const itemMatch = line.match(listItemRe);
103
+ if (itemMatch) {
104
+ flushBuf();
105
+ const indent = itemMatch[1].length;
106
+ while (stack.length > 0 && stack[stack.length - 1].indent >= indent) {
107
+ stack.pop();
108
+ }
109
+ stack.push({ indent });
110
+ buf = line;
111
+ continue;
112
+ }
113
+ if (/^\s/.test(line)) {
114
+ const indent = leadingSpaces(line);
115
+ while (stack.length > 1 && stack[stack.length - 1].indent >= indent) {
116
+ flushBuf();
117
+ stack.pop();
118
+ }
119
+ const trimmed = line.replace(/^\s+/, '');
120
+ buf = buf === '' ? trimmed : `${buf} ${trimmed}`;
121
+ continue;
122
+ }
123
+ flushBuf();
124
+ stack = [];
125
+ out.push(line);
126
+ }
127
+ flushBuf();
128
+
129
+ process.stdout.write(out.join('\n'));
130
+ if (!out[out.length - 1]?.endsWith('\n')) process.stdout.write('\n');
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # Build the current branch and link it as the global `codegraph` for
3
+ # hands-on testing. Replaces any existing global install for as long
4
+ # as the symlink is in place.
5
+ #
6
+ # Usage:
7
+ # ./scripts/local-install.sh # build + link
8
+ # ./scripts/local-install.sh --undo # unlink + restore the published version
9
+
10
+ set -euo pipefail
11
+
12
+ cd "$(dirname "$0")/.."
13
+
14
+ PKG=$(node -p "require('./package.json').name")
15
+ VERSION=$(node -p "require('./package.json').version")
16
+ BRANCH=$(git rev-parse --abbrev-ref HEAD)
17
+
18
+ if [ "${1:-}" = "--undo" ]; then
19
+ echo "→ unlinking ${PKG}"
20
+ npm unlink -g "${PKG}" >/dev/null 2>&1 || true
21
+ echo "→ reinstalling published ${PKG}"
22
+ npm install -g "${PKG}"
23
+ echo "done: global codegraph -> $(command -v codegraph)"
24
+ exit 0
25
+ fi
26
+
27
+ echo "→ building ${PKG} ${VERSION} (${BRANCH})"
28
+ npm run build
29
+
30
+ echo "→ linking globally"
31
+ npm link
32
+
33
+ LINKED=$(command -v codegraph || echo "(not on PATH)")
34
+ echo
35
+ echo "✓ global codegraph now points to this branch"
36
+ echo " binary: ${LINKED}"
37
+ echo " branch: ${BRANCH}"
38
+ echo " version: ${VERSION}"
39
+ echo
40
+ echo "To restore the published version:"
41
+ echo " ./scripts/local-install.sh --undo"
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+ //
3
+ // Programmatic / embedded SDK entry for @colbymchenry/codegraph (issue #354).
4
+ //
5
+ // The CLI/MCP `bin` (npm-shim.js) execs the per-platform bundle's OWN Node 24 so
6
+ // the tool never depends on the user's runtime. Embedded library consumers are
7
+ // the opposite case: they already run their own Node and just want the compiled
8
+ // API — `require("@colbymchenry/codegraph")` returning the CodeGraph class et al.
9
+ //
10
+ // The compiled library + its production dependencies (web-tree-sitter,
11
+ // tree-sitter-wasms, …) ship INSIDE the per-platform bundle, at
12
+ // @colbymchenry/codegraph-<platform>-<arch>/lib/dist/index.js
13
+ // (with the deps in the sibling lib/node_modules). Re-exporting that bundle keeps
14
+ // the main package thin — no second 50 MB copy of the grammars — while making the
15
+ // SDK work in the consumer's process. Types are a separate concern: the main
16
+ // package ships its own dist/**/*.d.ts tree (pointed at by `types`), built from
17
+ // the same release so it can never skew from the runtime it re-exports.
18
+ //
19
+ // node:sqlite (Node >= 22.5) is required to OPEN a graph, but only lazily inside
20
+ // the SQLite adapter — so loading this module is safe on older Node, and the
21
+ // node:sqlite requirement surfaces with an actionable error only when a DB is
22
+ // actually opened. Heavy extraction additionally wants the bundled launcher's
23
+ // --liftoff-only flag (the WASM Zone-OOM guard, issues #293/#298); an embedded
24
+ // host that drives large indexing should pass that flag to its own Node.
25
+
26
+ var path = require('path');
27
+ var os = require('os');
28
+ var fs = require('fs');
29
+
30
+ var target = process.platform + '-' + process.arch; // e.g. darwin-arm64, linux-x64
31
+ var pkg = '@colbymchenry/codegraph-' + target;
32
+
33
+ module.exports = require(resolveLibrary());
34
+
35
+ // Locate the compiled library entry inside the installed per-platform bundle.
36
+ // Throws an actionable error (rather than a bare MODULE_NOT_FOUND) when no bundle
37
+ // is present, so an embedded consumer knows exactly what to install.
38
+ function resolveLibrary() {
39
+ // 1) The npm-installed optional dependency — the normal case.
40
+ try {
41
+ return require.resolve(pkg + '/lib/dist/index.js');
42
+ } catch (e) {
43
+ /* fall through to the self-healed cache */
44
+ }
45
+
46
+ // 2) A bundle the CLI shim self-healed from GitHub Releases into the cache
47
+ // (issue #303). Same node/lib/bin layout as the npm package. We only REUSE a
48
+ // cached bundle here — unlike the CLI shim we never trigger a network
49
+ // download from inside require(), which must stay synchronous and cheap.
50
+ var cached = cachedLibrary();
51
+ if (cached) return cached;
52
+
53
+ throw new Error(
54
+ 'codegraph: the programmatic API is unavailable because the platform bundle\n' +
55
+ '(' + pkg + ') is not installed.\n' +
56
+ 'The compiled library ships inside that per-platform optional dependency.\n' +
57
+ 'Fixes:\n' +
58
+ ' - install from the official npm registry so the matching bundle is fetched:\n' +
59
+ ' npm i @colbymchenry/codegraph --registry=https://registry.npmjs.org\n' +
60
+ ' - or run the CLI once (e.g. `npx @colbymchenry/codegraph status`) to\n' +
61
+ ' self-heal the bundle into ~/.codegraph, then require() will find it.'
62
+ );
63
+ }
64
+
65
+ function cachedLibrary() {
66
+ try {
67
+ var version = require(path.join(__dirname, 'package.json')).version;
68
+ var base = process.env.CODEGRAPH_INSTALL_DIR || path.join(os.homedir(), '.codegraph');
69
+ var lib = path.join(base, 'bundles', target + '-' + version, 'lib', 'dist', 'index.js');
70
+ if (fs.existsSync(lib)) return lib;
71
+ } catch (e) {
72
+ /* no readable cache → caller reports the install guidance */
73
+ }
74
+ return null;
75
+ }