@stupidloud/codegraph 0.8.1 → 0.9.9
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.
- package/README.md +319 -152
- package/dist/bin/codegraph.d.ts +4 -0
- package/dist/bin/codegraph.d.ts.map +1 -1
- package/dist/bin/codegraph.js +354 -90
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/bin/node-version-check.d.ts +17 -0
- package/dist/bin/node-version-check.d.ts.map +1 -1
- package/dist/bin/node-version-check.js +37 -0
- package/dist/bin/node-version-check.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -11
- package/dist/config.js.map +1 -1
- package/dist/context/formatter.d.ts.map +1 -1
- package/dist/context/formatter.js +25 -6
- package/dist/context/formatter.js.map +1 -1
- package/dist/context/index.d.ts +22 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +257 -6
- package/dist/context/index.js.map +1 -1
- package/dist/context/markers.d.ts +19 -0
- package/dist/context/markers.d.ts.map +1 -0
- package/dist/context/markers.js +22 -0
- package/dist/context/markers.js.map +1 -0
- package/dist/db/index.d.ts +30 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +75 -25
- package/dist/db/index.js.map +1 -1
- package/dist/db/queries.d.ts +104 -0
- package/dist/db/queries.d.ts.map +1 -1
- package/dist/db/queries.js +328 -31
- package/dist/db/queries.js.map +1 -1
- package/dist/db/sqlite-adapter.d.ts +24 -23
- package/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/dist/db/sqlite-adapter.js +54 -174
- package/dist/db/sqlite-adapter.js.map +1 -1
- package/dist/directory.d.ts.map +1 -1
- package/dist/directory.js +6 -20
- package/dist/directory.js.map +1 -1
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/generated-detection.d.ts.map +1 -0
- package/dist/extraction/generated-detection.js +80 -0
- package/dist/extraction/generated-detection.js.map +1 -0
- package/dist/extraction/grammars.d.ts +23 -1
- package/dist/extraction/grammars.d.ts.map +1 -1
- package/dist/extraction/grammars.js +107 -3
- package/dist/extraction/grammars.js.map +1 -1
- package/dist/extraction/index.d.ts +22 -14
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +272 -183
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/dist/extraction/languages/c-cpp.js +45 -0
- package/dist/extraction/languages/c-cpp.js.map +1 -1
- package/dist/extraction/languages/csharp.d.ts.map +1 -1
- package/dist/extraction/languages/csharp.js +2 -1
- package/dist/extraction/languages/csharp.js.map +1 -1
- package/dist/extraction/languages/go.d.ts.map +1 -1
- package/dist/extraction/languages/go.js +18 -2
- package/dist/extraction/languages/go.js.map +1 -1
- package/dist/extraction/languages/index.d.ts.map +1 -1
- package/dist/extraction/languages/index.js +6 -0
- package/dist/extraction/languages/index.js.map +1 -1
- package/dist/extraction/languages/java.d.ts.map +1 -1
- package/dist/extraction/languages/java.js +6 -0
- package/dist/extraction/languages/java.js.map +1 -1
- package/dist/extraction/languages/kotlin.d.ts.map +1 -1
- package/dist/extraction/languages/kotlin.js +6 -0
- package/dist/extraction/languages/kotlin.js.map +1 -1
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts.map +1 -0
- package/dist/extraction/languages/lua.js +150 -0
- package/dist/extraction/languages/lua.js.map +1 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts.map +1 -0
- package/dist/extraction/languages/luau.js +37 -0
- package/dist/extraction/languages/luau.js.map +1 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts.map +1 -0
- package/dist/extraction/languages/objc.js +133 -0
- package/dist/extraction/languages/objc.js.map +1 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
- package/dist/extraction/mybatis-extractor.js +198 -0
- package/dist/extraction/mybatis-extractor.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +14 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.d.ts +84 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/dist/extraction/tree-sitter.js +715 -16
- package/dist/extraction/tree-sitter.js.map +1 -1
- package/dist/extraction/vue-extractor.d.ts +15 -0
- package/dist/extraction/vue-extractor.d.ts.map +1 -1
- package/dist/extraction/vue-extractor.js +88 -0
- package/dist/extraction/vue-extractor.js.map +1 -1
- package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
- package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
- package/dist/extraction/wasm-runtime-flags.js +106 -0
- package/dist/extraction/wasm-runtime-flags.js.map +1 -0
- package/dist/graph/traversal.d.ts.map +1 -1
- package/dist/graph/traversal.js +76 -38
- package/dist/graph/traversal.js.map +1 -1
- package/dist/index.d.ts +77 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -19
- package/dist/index.js.map +1 -1
- package/dist/installer/config-writer.d.ts +7 -8
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +7 -27
- package/dist/installer/config-writer.js.map +1 -1
- package/dist/installer/index.d.ts +51 -16
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +120 -29
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/instructions-template.d.ts +11 -21
- package/dist/installer/instructions-template.d.ts.map +1 -1
- package/dist/installer/instructions-template.js +12 -56
- package/dist/installer/instructions-template.js.map +1 -1
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/antigravity.d.ts.map +1 -0
- package/dist/installer/targets/antigravity.js +308 -0
- package/dist/installer/targets/antigravity.js.map +1 -0
- package/dist/installer/targets/claude.d.ts +26 -1
- package/dist/installer/targets/claude.d.ts.map +1 -1
- package/dist/installer/targets/claude.js +118 -40
- package/dist/installer/targets/claude.js.map +1 -1
- package/dist/installer/targets/codex.d.ts.map +1 -1
- package/dist/installer/targets/codex.js +15 -13
- package/dist/installer/targets/codex.js.map +1 -1
- package/dist/installer/targets/cursor.d.ts.map +1 -1
- package/dist/installer/targets/cursor.js +61 -36
- package/dist/installer/targets/cursor.js.map +1 -1
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/gemini.d.ts.map +1 -0
- package/dist/installer/targets/gemini.js +167 -0
- package/dist/installer/targets/gemini.js.map +1 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/hermes.d.ts.map +1 -0
- package/dist/installer/targets/hermes.js +359 -0
- package/dist/installer/targets/hermes.js.map +1 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/kiro.d.ts.map +1 -0
- package/dist/installer/targets/kiro.js +178 -0
- package/dist/installer/targets/kiro.js.map +1 -0
- package/dist/installer/targets/opencode.d.ts.map +1 -1
- package/dist/installer/targets/opencode.js +15 -13
- package/dist/installer/targets/opencode.js.map +1 -1
- package/dist/installer/targets/registry.d.ts.map +1 -1
- package/dist/installer/targets/registry.js +8 -0
- package/dist/installer/targets/registry.js.map +1 -1
- package/dist/installer/targets/shared.d.ts.map +1 -1
- package/dist/installer/targets/shared.js +3 -2
- package/dist/installer/targets/shared.js.map +1 -1
- package/dist/installer/targets/types.d.ts +1 -16
- package/dist/installer/targets/types.d.ts.map +1 -1
- package/dist/mcp/daemon-paths.d.ts +46 -0
- package/dist/mcp/daemon-paths.d.ts.map +1 -0
- package/dist/mcp/daemon-paths.js +125 -0
- package/dist/mcp/daemon-paths.js.map +1 -0
- package/dist/mcp/daemon.d.ts +161 -0
- package/dist/mcp/daemon.d.ts.map +1 -0
- package/dist/mcp/daemon.js +403 -0
- package/dist/mcp/daemon.js.map +1 -0
- package/dist/mcp/engine.d.ts +105 -0
- package/dist/mcp/engine.d.ts.map +1 -0
- package/dist/mcp/engine.js +270 -0
- package/dist/mcp/engine.js.map +1 -0
- package/dist/mcp/index.d.ts +70 -52
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +355 -331
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/proxy.d.ts +81 -0
- package/dist/mcp/proxy.d.ts.map +1 -0
- package/dist/mcp/proxy.js +510 -0
- package/dist/mcp/proxy.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.d.ts.map +1 -1
- package/dist/mcp/server-instructions.js +21 -21
- package/dist/mcp/session.d.ts +77 -0
- package/dist/mcp/session.d.ts.map +1 -0
- package/dist/mcp/session.js +294 -0
- package/dist/mcp/session.js.map +1 -0
- package/dist/mcp/tools.d.ts +171 -15
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +1714 -298
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transport.d.ts +111 -29
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +181 -71
- package/dist/mcp/transport.js.map +1 -1
- package/dist/mcp/version.d.ts +19 -0
- package/dist/mcp/version.d.ts.map +1 -0
- package/dist/mcp/version.js +71 -0
- package/dist/mcp/version.js.map +1 -0
- package/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
- package/dist/resolution/callback-synthesizer.js +1300 -0
- package/dist/resolution/callback-synthesizer.js.map +1 -0
- package/dist/resolution/frameworks/csharp.d.ts.map +1 -1
- package/dist/resolution/frameworks/csharp.js +36 -8
- package/dist/resolution/frameworks/csharp.js.map +1 -1
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
- package/dist/resolution/frameworks/drupal.js +367 -0
- package/dist/resolution/frameworks/drupal.js.map +1 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
- package/dist/resolution/frameworks/expo-modules.js +143 -0
- package/dist/resolution/frameworks/expo-modules.js.map +1 -0
- package/dist/resolution/frameworks/express.d.ts.map +1 -1
- package/dist/resolution/frameworks/express.js +102 -19
- package/dist/resolution/frameworks/express.js.map +1 -1
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
- package/dist/resolution/frameworks/fabric.js +354 -0
- package/dist/resolution/frameworks/fabric.js.map +1 -0
- package/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/dist/resolution/frameworks/go.js +6 -3
- package/dist/resolution/frameworks/go.js.map +1 -1
- package/dist/resolution/frameworks/index.d.ts +6 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/dist/resolution/frameworks/index.js +29 -1
- package/dist/resolution/frameworks/index.js.map +1 -1
- package/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/dist/resolution/frameworks/java.js +339 -12
- package/dist/resolution/frameworks/java.js.map +1 -1
- package/dist/resolution/frameworks/laravel.d.ts.map +1 -1
- package/dist/resolution/frameworks/laravel.js +17 -8
- package/dist/resolution/frameworks/laravel.js.map +1 -1
- package/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
- package/dist/resolution/frameworks/nestjs.js +324 -0
- package/dist/resolution/frameworks/nestjs.js.map +1 -1
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/play.d.ts.map +1 -0
- package/dist/resolution/frameworks/play.js +111 -0
- package/dist/resolution/frameworks/play.js.map +1 -0
- package/dist/resolution/frameworks/python.d.ts.map +1 -1
- package/dist/resolution/frameworks/python.js +134 -16
- package/dist/resolution/frameworks/python.js.map +1 -1
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
- package/dist/resolution/frameworks/react-native.js +360 -0
- package/dist/resolution/frameworks/react-native.js.map +1 -0
- package/dist/resolution/frameworks/react.d.ts.map +1 -1
- package/dist/resolution/frameworks/react.js +96 -3
- package/dist/resolution/frameworks/react.js.map +1 -1
- package/dist/resolution/frameworks/ruby.d.ts.map +1 -1
- package/dist/resolution/frameworks/ruby.js +106 -2
- package/dist/resolution/frameworks/ruby.js.map +1 -1
- package/dist/resolution/frameworks/rust.d.ts.map +1 -1
- package/dist/resolution/frameworks/rust.js +102 -5
- package/dist/resolution/frameworks/rust.js.map +1 -1
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
- package/dist/resolution/frameworks/swift-objc.js +252 -0
- package/dist/resolution/frameworks/swift-objc.js.map +1 -0
- package/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/dist/resolution/frameworks/swift.js +30 -6
- package/dist/resolution/frameworks/swift.js.map +1 -1
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/go-module.d.ts.map +1 -0
- package/dist/resolution/go-module.js +78 -0
- package/dist/resolution/go-module.js.map +1 -0
- package/dist/resolution/import-resolver.d.ts +28 -0
- package/dist/resolution/import-resolver.d.ts.map +1 -1
- package/dist/resolution/import-resolver.js +617 -5
- package/dist/resolution/import-resolver.js.map +1 -1
- package/dist/resolution/index.d.ts +11 -0
- package/dist/resolution/index.d.ts.map +1 -1
- package/dist/resolution/index.js +196 -10
- package/dist/resolution/index.js.map +1 -1
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/lru-cache.d.ts.map +1 -0
- package/dist/resolution/lru-cache.js +62 -0
- package/dist/resolution/lru-cache.js.map +1 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -1
- package/dist/resolution/name-matcher.js +212 -0
- package/dist/resolution/name-matcher.js.map +1 -1
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
- package/dist/resolution/swift-objc-bridge.js +256 -0
- package/dist/resolution/swift-objc-bridge.js.map +1 -0
- package/dist/resolution/types.d.ts +44 -0
- package/dist/resolution/types.d.ts.map +1 -1
- package/dist/resolution/workspace-packages.d.ts +48 -0
- package/dist/resolution/workspace-packages.d.ts.map +1 -0
- package/dist/resolution/workspace-packages.js +208 -0
- package/dist/resolution/workspace-packages.js.map +1 -0
- package/dist/search/query-utils.d.ts +18 -0
- package/dist/search/query-utils.d.ts.map +1 -1
- package/dist/search/query-utils.js +30 -0
- package/dist/search/query-utils.js.map +1 -1
- package/dist/sync/git-hooks.d.ts.map +1 -1
- package/dist/sync/git-hooks.js +2 -0
- package/dist/sync/git-hooks.js.map +1 -1
- package/dist/sync/index.d.ts +3 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +8 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/watcher.d.ts +214 -12
- package/dist/sync/watcher.d.ts.map +1 -1
- package/dist/sync/watcher.js +467 -55
- package/dist/sync/watcher.js.map +1 -1
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/sync/worktree.d.ts.map +1 -0
- package/dist/sync/worktree.js +137 -0
- package/dist/sync/worktree.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.js +1 -1
- package/package.json +2 -2
- package/scripts/add-lang/bench.sh +60 -0
- package/scripts/add-lang/check-grammar.mjs +75 -0
- package/scripts/add-lang/dump-ast.mjs +103 -0
- package/scripts/add-lang/verify-extraction.mjs +70 -0
- package/scripts/agent-eval/arms-F.sh +21 -0
- package/scripts/agent-eval/arms-matrix.sh +37 -0
- package/scripts/agent-eval/bench-readme.sh +28 -0
- package/scripts/agent-eval/bench-why-repo.sh +22 -0
- package/scripts/agent-eval/block-read-hook.sh +19 -0
- package/scripts/agent-eval/hook-settings.json +15 -0
- package/scripts/agent-eval/itrun.sh +24 -11
- package/scripts/agent-eval/parse-arms.mjs +116 -0
- package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
- package/scripts/agent-eval/probe-context.mjs +21 -0
- package/scripts/agent-eval/probe-explore.mjs +40 -0
- package/scripts/agent-eval/probe-node.mjs +20 -0
- package/scripts/agent-eval/probe-sweep.mjs +119 -0
- package/scripts/agent-eval/probe-trace.mjs +20 -0
- package/scripts/agent-eval/run-arms.sh +56 -0
- package/scripts/agent-eval/seq-matrix.mjs +137 -0
- package/scripts/build-bundle.sh +118 -0
- package/scripts/npm-sdk.js +75 -0
- package/scripts/npm-shim.js +246 -0
- package/scripts/pack-npm.sh +119 -0
- package/scripts/prepare-release.mjs +270 -0
- package/scripts/patch-tree-sitter-dart.js +0 -112
- package/scripts/release.sh +0 -68
|
@@ -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 opus --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,118 @@
|
|
|
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
|
+
# --liftoff-only: avoid the V8 turboshaft WASM Zone OOM (issues #293/#298).
|
|
102
|
+
exec "$DIR/node" --liftoff-only "$DIR/lib/dist/bin/codegraph.js" "$@"
|
|
103
|
+
LAUNCH
|
|
104
|
+
chmod +x "$STAGE/bin/codegraph"
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
# 5. Archive (.zip for Windows, .tar.gz otherwise).
|
|
108
|
+
mkdir -p "$OUT"
|
|
109
|
+
if [ "$OSFAM" = "win32" ]; then
|
|
110
|
+
ARCHIVE="$OUT/codegraph-${TARGET}.zip"
|
|
111
|
+
rm -f "$ARCHIVE"
|
|
112
|
+
( cd "$WORK" && zip -rqX "$ARCHIVE" "codegraph-${TARGET}" )
|
|
113
|
+
else
|
|
114
|
+
ARCHIVE="$OUT/codegraph-${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" "codegraph-${TARGET}"
|
|
117
|
+
fi
|
|
118
|
+
echo "[bundle] wrote ${ARCHIVE} ($(du -h "$ARCHIVE" | cut -f1))"
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
//
|
|
4
|
+
// npm thin-installer launcher for CodeGraph.
|
|
5
|
+
//
|
|
6
|
+
// The heavy artifact (a vendored Node runtime + the app) ships as a per-platform
|
|
7
|
+
// optionalDependency: @colbymchenry/codegraph-<platform>-<arch>. npm installs
|
|
8
|
+
// only the one matching the host, via each package's `os`/`cpu` fields (the
|
|
9
|
+
// esbuild pattern). This shim — run by the user's OWN Node — locates that bundle
|
|
10
|
+
// and execs its launcher, so the real work always runs on the bundled Node 24
|
|
11
|
+
// (with node:sqlite), regardless of the user's Node version. The user's Node is
|
|
12
|
+
// only ever a launcher; even an ancient version can run this file.
|
|
13
|
+
//
|
|
14
|
+
// Self-heal (issue #303): some registries — notably the npmmirror/cnpm mirrors,
|
|
15
|
+
// and some corporate proxies — don't reliably mirror the per-platform
|
|
16
|
+
// optionalDependencies. npm treats an unfetchable optional dep as success and
|
|
17
|
+
// silently skips it, so the bundle goes missing and every command fails. When
|
|
18
|
+
// the installed bundle can't be resolved, this shim falls back to downloading
|
|
19
|
+
// the matching bundle straight from GitHub Releases — the very archive
|
|
20
|
+
// install.sh uses — into a cache dir, then runs that. Knobs:
|
|
21
|
+
// CODEGRAPH_NO_DOWNLOAD=1 disable the network fallback (print guidance)
|
|
22
|
+
// CODEGRAPH_INSTALL_DIR=DIR cache location (default: ~/.codegraph)
|
|
23
|
+
// CODEGRAPH_DOWNLOAD_BASE=URL release-download base (for mirrors/air-gapped)
|
|
24
|
+
//
|
|
25
|
+
// Wired up at release time as the main package's `bin`:
|
|
26
|
+
// "bin": { "codegraph": "npm-shim.js" }
|
|
27
|
+
// with the platform packages listed in `optionalDependencies`.
|
|
28
|
+
|
|
29
|
+
var childProcess = require('child_process');
|
|
30
|
+
var fs = require('fs');
|
|
31
|
+
var os = require('os');
|
|
32
|
+
var path = require('path');
|
|
33
|
+
|
|
34
|
+
var target = process.platform + '-' + process.arch; // e.g. darwin-arm64, linux-x64
|
|
35
|
+
var pkg = '@colbymchenry/codegraph-' + target;
|
|
36
|
+
var isWindows = process.platform === 'win32';
|
|
37
|
+
var REPO = 'colbymchenry/codegraph';
|
|
38
|
+
|
|
39
|
+
main().catch(function (e) {
|
|
40
|
+
process.stderr.write('codegraph: ' + (e && e.message ? e.message : String(e)) + '\n');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
async function main() {
|
|
45
|
+
// Happy path: the npm-installed optional dependency. Fall back to a download
|
|
46
|
+
// when the registry didn't deliver it.
|
|
47
|
+
var resolved = resolveInstalledBundle() || (await selfHealBundle());
|
|
48
|
+
var res = childProcess.spawnSync(resolved.command, resolved.args, { stdio: 'inherit' });
|
|
49
|
+
if (res.error) {
|
|
50
|
+
process.stderr.write('codegraph: ' + res.error.message + '\n');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
process.exit(res.status === null ? 1 : res.status);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Resolve the launcher from the installed per-platform optionalDependency.
|
|
57
|
+
// Returns {command, args} or null if the package isn't installed.
|
|
58
|
+
function resolveInstalledBundle() {
|
|
59
|
+
try {
|
|
60
|
+
if (isWindows) {
|
|
61
|
+
// Modern Node refuses to spawn the bundle's .cmd directly (EINVAL, the
|
|
62
|
+
// CVE-2024-27980 hardening on Node 24), so invoke the bundled node.exe
|
|
63
|
+
// against the app entry point and pass --liftoff-only here.
|
|
64
|
+
var nodeExe = require.resolve(pkg + '/node.exe');
|
|
65
|
+
var entry = require.resolve(pkg + '/lib/dist/bin/codegraph.js');
|
|
66
|
+
return { command: nodeExe, args: liftoff(entry) };
|
|
67
|
+
}
|
|
68
|
+
return { command: require.resolve(pkg + '/bin/codegraph'), args: process.argv.slice(2) };
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Locate the launcher inside an extracted GitHub bundle directory (same
|
|
75
|
+
// node/lib/bin layout as the npm platform package). Returns {command, args} or
|
|
76
|
+
// null when the directory doesn't hold a usable bundle yet.
|
|
77
|
+
function launcherIn(dir) {
|
|
78
|
+
if (isWindows) {
|
|
79
|
+
var nodeExe = path.join(dir, 'node.exe');
|
|
80
|
+
var entry = path.join(dir, 'lib', 'dist', 'bin', 'codegraph.js');
|
|
81
|
+
if (fs.existsSync(nodeExe) && fs.existsSync(entry)) {
|
|
82
|
+
return { command: nodeExe, args: liftoff(entry) };
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
var launcher = path.join(dir, 'bin', 'codegraph');
|
|
86
|
+
if (fs.existsSync(launcher)) return { command: launcher, args: process.argv.slice(2) };
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// --liftoff-only keeps tree-sitter's WASM grammars off V8's turboshaft tier to
|
|
92
|
+
// avoid the Zone OOM on Node >= 22 (issues #293/#298). The unix bin/codegraph
|
|
93
|
+
// launcher already passes it; on Windows we invoke node.exe directly so add it.
|
|
94
|
+
function liftoff(entry) {
|
|
95
|
+
return ['--liftoff-only', entry].concat(process.argv.slice(2));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Download + cache the platform bundle from GitHub Releases. Returns
|
|
99
|
+
// {command, args}; exits the process with guidance if it can't.
|
|
100
|
+
async function selfHealBundle() {
|
|
101
|
+
var version = readVersion();
|
|
102
|
+
var bundlesDir = path.join(process.env.CODEGRAPH_INSTALL_DIR || path.join(os.homedir(), '.codegraph'), 'bundles');
|
|
103
|
+
var dest = path.join(bundlesDir, target + '-' + version);
|
|
104
|
+
|
|
105
|
+
// Already downloaded by a previous run? Use it even when downloads are
|
|
106
|
+
// disabled — CODEGRAPH_NO_DOWNLOAD blocks fetching, not a cached bundle.
|
|
107
|
+
var cached = launcherIn(dest);
|
|
108
|
+
if (cached) return cached;
|
|
109
|
+
|
|
110
|
+
if (process.env.CODEGRAPH_NO_DOWNLOAD) {
|
|
111
|
+
fail('the network fallback is disabled (CODEGRAPH_NO_DOWNLOAD is set).');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var asset = 'codegraph-' + target + (isWindows ? '.zip' : '.tar.gz');
|
|
115
|
+
var base = process.env.CODEGRAPH_DOWNLOAD_BASE || ('https://github.com/' + REPO + '/releases/download');
|
|
116
|
+
var url = base + '/v' + version + '/' + asset;
|
|
117
|
+
|
|
118
|
+
process.stderr.write(
|
|
119
|
+
'codegraph: platform bundle missing (registry did not provide ' + pkg + ').\n' +
|
|
120
|
+
'codegraph: downloading ' + asset + ' from GitHub Releases (' + version + ')...\n'
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Stage inside bundlesDir so the final rename is on the same filesystem (atomic,
|
|
124
|
+
// no EXDEV across tmpfs). Strip the archive's top-level codegraph-<target>/ dir.
|
|
125
|
+
fs.mkdirSync(bundlesDir, { recursive: true });
|
|
126
|
+
var stage = fs.mkdtempSync(path.join(bundlesDir, '.dl-'));
|
|
127
|
+
try {
|
|
128
|
+
var archivePath = path.join(stage, asset);
|
|
129
|
+
await download(url, archivePath, 6);
|
|
130
|
+
await verifyChecksum(archivePath, asset, base, version);
|
|
131
|
+
var extracted = path.join(stage, 'bundle');
|
|
132
|
+
fs.mkdirSync(extracted);
|
|
133
|
+
extract(archivePath, extracted);
|
|
134
|
+
|
|
135
|
+
var raced = launcherIn(dest); // another process may have finished meanwhile
|
|
136
|
+
if (raced) { rmrf(stage); return raced; }
|
|
137
|
+
try {
|
|
138
|
+
fs.renameSync(extracted, dest);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
var other = launcherIn(dest); // lost the race but theirs is valid
|
|
141
|
+
if (other) { rmrf(stage); return other; }
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
} catch (e) {
|
|
145
|
+
rmrf(stage);
|
|
146
|
+
fail('download failed (' + e.message + ').\n URL: ' + url);
|
|
147
|
+
}
|
|
148
|
+
rmrf(stage);
|
|
149
|
+
|
|
150
|
+
var ready = launcherIn(dest);
|
|
151
|
+
if (!ready) fail('downloaded bundle is missing its launcher under ' + dest + '.');
|
|
152
|
+
process.stderr.write('codegraph: bundle ready.\n');
|
|
153
|
+
return ready;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function readVersion() {
|
|
157
|
+
try {
|
|
158
|
+
return require(path.join(__dirname, 'package.json')).version;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
fail('could not read this package\'s version to locate a matching release.');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// GET with manual redirect following (GitHub release URLs redirect to a CDN).
|
|
165
|
+
function download(url, dest, redirectsLeft) {
|
|
166
|
+
return new Promise(function (resolve, reject) {
|
|
167
|
+
var https = require('https');
|
|
168
|
+
// timeout is an idle/inactivity timeout — it won't kill a slow-but-progressing
|
|
169
|
+
// download, only a stalled connection (so a blocked mirror fails fast with
|
|
170
|
+
// guidance instead of hanging the user's command forever).
|
|
171
|
+
var req = https.get(url, { headers: { 'User-Agent': 'codegraph-npm-shim' }, timeout: 30000 }, function (res) {
|
|
172
|
+
var status = res.statusCode;
|
|
173
|
+
if (status >= 300 && status < 400 && res.headers.location) {
|
|
174
|
+
res.resume();
|
|
175
|
+
if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
|
|
176
|
+
download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
|
|
180
|
+
var file = fs.createWriteStream(dest);
|
|
181
|
+
res.on('error', reject);
|
|
182
|
+
res.pipe(file);
|
|
183
|
+
file.on('error', reject);
|
|
184
|
+
file.on('finish', function () { file.close(function () { resolve(); }); });
|
|
185
|
+
});
|
|
186
|
+
req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
|
|
187
|
+
req.on('error', reject);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Best-effort integrity check. When the release publishes a SHA256SUMS file, the
|
|
192
|
+
// downloaded archive MUST match its listed hash or we abort. When that file is
|
|
193
|
+
// absent (older releases) or simply unreachable, we proceed — the archive still
|
|
194
|
+
// arrived from GitHub over TLS. So tampering/corruption is caught, while a
|
|
195
|
+
// missing checksum never breaks an install.
|
|
196
|
+
async function verifyChecksum(archivePath, asset, base, version) {
|
|
197
|
+
var sumsPath = archivePath + '.SHA256SUMS';
|
|
198
|
+
try {
|
|
199
|
+
await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
return; // not published / unreachable → skip
|
|
202
|
+
}
|
|
203
|
+
var expected = null;
|
|
204
|
+
var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
|
|
205
|
+
for (var i = 0; i < lines.length; i++) {
|
|
206
|
+
var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
|
|
207
|
+
if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
|
|
208
|
+
}
|
|
209
|
+
if (!expected) return; // asset not listed → nothing to check
|
|
210
|
+
var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
|
|
211
|
+
if (actual !== expected) {
|
|
212
|
+
throw new Error('checksum mismatch for ' + asset +
|
|
213
|
+
' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
|
|
214
|
+
}
|
|
215
|
+
process.stderr.write('codegraph: checksum verified.\n');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Extract via the system tar — present on macOS, Linux, and Windows 10+
|
|
219
|
+
// (bsdtar reads .zip too). No third-party dependency in the shim.
|
|
220
|
+
function extract(archive, destDir) {
|
|
221
|
+
var args = isWindows
|
|
222
|
+
? ['-xf', archive, '-C', destDir, '--strip-components=1']
|
|
223
|
+
: ['-xzf', archive, '-C', destDir, '--strip-components=1'];
|
|
224
|
+
var res = childProcess.spawnSync('tar', args, { stdio: 'ignore' });
|
|
225
|
+
if (res.error) throw new Error('tar unavailable: ' + res.error.message);
|
|
226
|
+
if (res.status !== 0) throw new Error('tar exited ' + res.status);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function rmrf(p) {
|
|
230
|
+
try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* best effort */ }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function fail(reason) {
|
|
234
|
+
process.stderr.write(
|
|
235
|
+
'codegraph: no prebuilt bundle for ' + target + '.\n' +
|
|
236
|
+
(reason ? 'codegraph: ' + reason + '\n' : '') +
|
|
237
|
+
'Expected the optional package ' + pkg + ' to be installed.\n' +
|
|
238
|
+
'A registry mirror (e.g. npmmirror/cnpm) that did not mirror the per-platform\n' +
|
|
239
|
+
'package is the usual cause. Fixes:\n' +
|
|
240
|
+
' - install from the official registry:\n' +
|
|
241
|
+
' npm i -g @colbymchenry/codegraph --registry=https://registry.npmjs.org\n' +
|
|
242
|
+
' - or use the standalone installer (no Node required):\n' +
|
|
243
|
+
' curl -fsSL https://raw.githubusercontent.com/' + REPO + '/main/install.sh | sh\n'
|
|
244
|
+
);
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|