@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.
- package/LICENSE +21 -0
- package/README.md +885 -0
- package/package.json +42 -10
- 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/ab-adoption.sh +91 -0
- package/scripts/agent-eval/ab-hook.sh +86 -0
- package/scripts/agent-eval/ab-impl.sh +78 -0
- package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
- package/scripts/agent-eval/ab-sufficiency.sh +78 -0
- package/scripts/agent-eval/arms-F.sh +21 -0
- package/scripts/agent-eval/arms-matrix.sh +37 -0
- package/scripts/agent-eval/audit.sh +68 -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 +120 -0
- package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
- package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
- package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
- package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
- package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
- package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
- package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
- package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
- package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
- package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
- package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
- package/scripts/agent-eval/offload-eval-setup.sh +24 -0
- package/scripts/agent-eval/offload-eval-styles.sh +72 -0
- package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
- package/scripts/agent-eval/offload-eval.md +76 -0
- package/scripts/agent-eval/parse-arms.mjs +116 -0
- package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
- package/scripts/agent-eval/parse-run.mjs +45 -0
- package/scripts/agent-eval/parse-session.mjs +93 -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/redirect-read-hook.sh +38 -0
- package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
- package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
- package/scripts/agent-eval/run-agent.sh +34 -0
- package/scripts/agent-eval/run-all.sh +75 -0
- package/scripts/agent-eval/run-arms.sh +56 -0
- package/scripts/agent-eval/seq-matrix.mjs +137 -0
- package/scripts/build-bundle.sh +123 -0
- package/scripts/extract-release-notes.mjs +130 -0
- package/scripts/local-install.sh +41 -0
- package/scripts/npm-sdk.js +75 -0
- package/scripts/npm-shim.js +275 -0
- package/scripts/pack-npm.sh +119 -0
- package/scripts/prepare-release.mjs +270 -0
- package/dist/bin/codegraph.d.ts +0 -25
- package/dist/bin/node-version-check.d.ts +0 -37
- package/dist/bin/uninstall.d.ts +0 -14
- package/dist/context/formatter.d.ts +0 -33
- package/dist/context/formatter.js +0 -244
- package/dist/context/index.d.ts +0 -117
- package/dist/context/index.js +0 -1050
- package/dist/db/index.d.ts +0 -101
- package/dist/db/index.js +0 -250
- package/dist/db/migrations.d.ts +0 -47
- package/dist/db/migrations.js +0 -131
- package/dist/db/queries.d.ts +0 -291
- package/dist/db/queries.js +0 -1349
- package/dist/db/schema.sql +0 -151
- package/dist/db/sqlite-adapter.d.ts +0 -49
- package/dist/db/sqlite-adapter.js +0 -141
- package/dist/directory.d.ts +0 -62
- package/dist/directory.js +0 -264
- package/dist/errors.d.ts +0 -149
- package/dist/errors.js +0 -219
- package/dist/extraction/dfm-extractor.d.ts +0 -31
- package/dist/extraction/dfm-extractor.js +0 -151
- package/dist/extraction/grammars.d.ts +0 -94
- package/dist/extraction/grammars.js +0 -357
- package/dist/extraction/index.d.ts +0 -148
- package/dist/extraction/index.js +0 -1286
- package/dist/extraction/languages/c-cpp.d.ts +0 -4
- package/dist/extraction/languages/c-cpp.js +0 -126
- package/dist/extraction/languages/csharp.d.ts +0 -3
- package/dist/extraction/languages/csharp.js +0 -72
- package/dist/extraction/languages/dart.d.ts +0 -3
- package/dist/extraction/languages/dart.js +0 -192
- package/dist/extraction/languages/go.d.ts +0 -3
- package/dist/extraction/languages/go.js +0 -58
- package/dist/extraction/languages/index.d.ts +0 -10
- package/dist/extraction/languages/index.js +0 -49
- package/dist/extraction/languages/java.d.ts +0 -3
- package/dist/extraction/languages/java.js +0 -64
- package/dist/extraction/languages/javascript.d.ts +0 -3
- package/dist/extraction/languages/javascript.js +0 -90
- package/dist/extraction/languages/kotlin.d.ts +0 -3
- package/dist/extraction/languages/kotlin.js +0 -253
- package/dist/extraction/languages/lua.d.ts +0 -3
- package/dist/extraction/languages/lua.js +0 -150
- package/dist/extraction/languages/luau.d.ts +0 -3
- package/dist/extraction/languages/luau.js +0 -37
- package/dist/extraction/languages/pascal.d.ts +0 -3
- package/dist/extraction/languages/pascal.js +0 -66
- package/dist/extraction/languages/php.d.ts +0 -3
- package/dist/extraction/languages/php.js +0 -107
- package/dist/extraction/languages/python.d.ts +0 -3
- package/dist/extraction/languages/python.js +0 -56
- package/dist/extraction/languages/ruby.d.ts +0 -3
- package/dist/extraction/languages/ruby.js +0 -114
- package/dist/extraction/languages/rust.d.ts +0 -3
- package/dist/extraction/languages/rust.js +0 -109
- package/dist/extraction/languages/scala.d.ts +0 -3
- package/dist/extraction/languages/scala.js +0 -139
- package/dist/extraction/languages/swift.d.ts +0 -3
- package/dist/extraction/languages/swift.js +0 -91
- package/dist/extraction/languages/typescript.d.ts +0 -3
- package/dist/extraction/languages/typescript.js +0 -129
- package/dist/extraction/liquid-extractor.d.ts +0 -52
- package/dist/extraction/liquid-extractor.js +0 -313
- package/dist/extraction/parse-worker.d.ts +0 -8
- package/dist/extraction/parse-worker.js +0 -94
- package/dist/extraction/svelte-extractor.d.ts +0 -56
- package/dist/extraction/svelte-extractor.js +0 -272
- package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
- package/dist/extraction/tree-sitter-helpers.js +0 -103
- package/dist/extraction/tree-sitter-types.d.ts +0 -191
- package/dist/extraction/tree-sitter-types.js +0 -10
- package/dist/extraction/tree-sitter.d.ts +0 -238
- package/dist/extraction/tree-sitter.js +0 -2430
- package/dist/extraction/vue-extractor.d.ts +0 -36
- package/dist/extraction/vue-extractor.js +0 -163
- package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
- package/dist/extraction/wasm-runtime-flags.js +0 -105
- package/dist/graph/index.d.ts +0 -8
- package/dist/graph/index.js +0 -13
- package/dist/graph/queries.d.ts +0 -109
- package/dist/graph/queries.js +0 -366
- package/dist/graph/traversal.d.ts +0 -137
- package/dist/graph/traversal.js +0 -528
- package/dist/index.d.ts +0 -509
- package/dist/index.js +0 -800
- package/dist/installer/claude-md-template.d.ts +0 -19
- package/dist/installer/config-writer.d.ts +0 -29
- package/dist/installer/index.d.ts +0 -140
- package/dist/installer/instructions-template.d.ts +0 -30
- package/dist/installer/targets/claude.d.ts +0 -55
- package/dist/installer/targets/codex.d.ts +0 -18
- package/dist/installer/targets/cursor.d.ts +0 -35
- package/dist/installer/targets/hermes.d.ts +0 -18
- package/dist/installer/targets/opencode.d.ts +0 -30
- package/dist/installer/targets/registry.d.ts +0 -38
- package/dist/installer/targets/shared.d.ts +0 -92
- package/dist/installer/targets/toml.d.ts +0 -64
- package/dist/installer/targets/types.d.ts +0 -122
- package/dist/mcp/index.d.ts +0 -98
- package/dist/mcp/server-instructions.d.ts +0 -20
- package/dist/mcp/tools.d.ts +0 -269
- package/dist/mcp/transport.d.ts +0 -117
- package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
- package/dist/resolution/frameworks/cargo-workspace.js +0 -225
- package/dist/resolution/frameworks/csharp.d.ts +0 -8
- package/dist/resolution/frameworks/csharp.js +0 -213
- package/dist/resolution/frameworks/drupal.d.ts +0 -51
- package/dist/resolution/frameworks/drupal.js +0 -335
- package/dist/resolution/frameworks/express.d.ts +0 -8
- package/dist/resolution/frameworks/express.js +0 -225
- package/dist/resolution/frameworks/go.d.ts +0 -8
- package/dist/resolution/frameworks/go.js +0 -158
- package/dist/resolution/frameworks/index.d.ts +0 -52
- package/dist/resolution/frameworks/index.js +0 -137
- package/dist/resolution/frameworks/java.d.ts +0 -8
- package/dist/resolution/frameworks/java.js +0 -177
- package/dist/resolution/frameworks/laravel.d.ts +0 -13
- package/dist/resolution/frameworks/laravel.js +0 -248
- package/dist/resolution/frameworks/nestjs.d.ts +0 -26
- package/dist/resolution/frameworks/nestjs.js +0 -374
- package/dist/resolution/frameworks/python.d.ts +0 -10
- package/dist/resolution/frameworks/python.js +0 -278
- package/dist/resolution/frameworks/react.d.ts +0 -8
- package/dist/resolution/frameworks/react.js +0 -272
- package/dist/resolution/frameworks/ruby.d.ts +0 -8
- package/dist/resolution/frameworks/ruby.js +0 -198
- package/dist/resolution/frameworks/rust.d.ts +0 -8
- package/dist/resolution/frameworks/rust.js +0 -207
- package/dist/resolution/frameworks/svelte.d.ts +0 -9
- package/dist/resolution/frameworks/svelte.js +0 -249
- package/dist/resolution/frameworks/swift.d.ts +0 -10
- package/dist/resolution/frameworks/swift.js +0 -376
- package/dist/resolution/frameworks/vue.d.ts +0 -9
- package/dist/resolution/frameworks/vue.js +0 -306
- package/dist/resolution/import-resolver.d.ts +0 -61
- package/dist/resolution/import-resolver.js +0 -663
- package/dist/resolution/index.d.ts +0 -118
- package/dist/resolution/index.js +0 -744
- package/dist/resolution/lru-cache.d.ts +0 -24
- package/dist/resolution/lru-cache.js +0 -62
- package/dist/resolution/name-matcher.d.ts +0 -50
- package/dist/resolution/name-matcher.js +0 -384
- package/dist/resolution/path-aliases.d.ts +0 -72
- package/dist/resolution/path-aliases.js +0 -238
- package/dist/resolution/strip-comments.d.ts +0 -40
- package/dist/resolution/strip-comments.js +0 -441
- package/dist/resolution/types.d.ts +0 -181
- package/dist/resolution/types.js +0 -8
- package/dist/search/query-parser.d.ts +0 -61
- package/dist/search/query-parser.js +0 -177
- package/dist/search/query-utils.d.ts +0 -59
- package/dist/search/query-utils.js +0 -383
- package/dist/sync/git-hooks.d.ts +0 -54
- package/dist/sync/git-hooks.js +0 -223
- package/dist/sync/index.d.ts +0 -25
- package/dist/sync/index.js +0 -28
- package/dist/sync/watch-policy.d.ts +0 -51
- package/dist/sync/watch-policy.js +0 -124
- package/dist/sync/watcher.d.ts +0 -83
- package/dist/sync/watcher.js +0 -192
- package/dist/types.d.ts +0 -433
- package/dist/types.js +0 -75
- package/dist/ui/glyphs.d.ts +0 -42
- package/dist/ui/shimmer-progress.d.ts +0 -11
- package/dist/ui/shimmer-worker.d.ts +0 -2
- package/dist/ui/types.d.ts +0 -20
- package/dist/utils.d.ts +0 -231
- package/dist/utils.js +0 -549
package/package.json
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saluzi/codegraph",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Supercharge AI coding agents with semantic code intelligence — surgical context, fewer tool calls, faster answers. 100% local.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"codegraph": "./dist/bin/codegraph.js"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
8
|
-
"dist
|
|
11
|
+
"dist",
|
|
12
|
+
"scripts",
|
|
13
|
+
"README.md"
|
|
9
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc && npm run copy-assets && node -e \"require('fs').chmodSync('dist/bin/codegraph.js', 0o755)\"",
|
|
17
|
+
"preuninstall": "node dist/bin/uninstall.js",
|
|
18
|
+
"copy-assets": "node -e \"const fs=require('fs');fs.mkdirSync('dist/db',{recursive:true});fs.copyFileSync('src/db/schema.sql','dist/db/schema.sql');fs.mkdirSync('dist/extraction/wasm',{recursive:true});fs.readdirSync('src/extraction/wasm').filter(f=>f.endsWith('.wasm')).forEach(f=>fs.copyFileSync('src/extraction/wasm/'+f,'dist/extraction/wasm/'+f))\"",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"cli": "npm run build && node dist/bin/codegraph.js",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"test:eval": "vitest run __tests__/evaluation/",
|
|
24
|
+
"eval": "npm run build && npx tsx __tests__/evaluation/runner.ts",
|
|
25
|
+
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\""
|
|
26
|
+
},
|
|
10
27
|
"keywords": [
|
|
11
28
|
"code-intelligence",
|
|
12
|
-
"tree-sitter",
|
|
13
|
-
"sqlite",
|
|
14
29
|
"knowledge-graph",
|
|
15
|
-
"
|
|
30
|
+
"static-analysis"
|
|
16
31
|
],
|
|
32
|
+
"author": "",
|
|
17
33
|
"license": "MIT",
|
|
18
34
|
"dependencies": {
|
|
19
|
-
"
|
|
35
|
+
"@clack/prompts": "^1.3.0",
|
|
36
|
+
"commander": "^14.0.2",
|
|
37
|
+
"fast-string-width": "^3.0.2",
|
|
38
|
+
"fast-wrap-ansi": "^0.2.0",
|
|
20
39
|
"ignore": "^7.0.5",
|
|
40
|
+
"jsonc-parser": "^3.3.1",
|
|
21
41
|
"picomatch": "^4.0.3",
|
|
22
|
-
"
|
|
42
|
+
"sisteransi": "^1.0.5",
|
|
43
|
+
"tree-sitter-wasms": "^0.1.11",
|
|
44
|
+
"web-tree-sitter": "^0.25.3"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
48
|
+
"@types/node": "^20.19.30",
|
|
49
|
+
"@types/picomatch": "^4.0.2",
|
|
50
|
+
"typescript": "^5.0.0",
|
|
51
|
+
"vitest": "^2.1.9"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20.0.0 <25.0.0"
|
|
23
55
|
}
|
|
24
56
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Add-lang benchmark for ONE repo:
|
|
3
|
+
# clone -> wipe+index (with the codegraph on PATH) -> verify extraction ->
|
|
4
|
+
# with/without retrieval A/B (reuses scripts/agent-eval/run-all.sh).
|
|
5
|
+
#
|
|
6
|
+
# Assumes the codegraph dev build is already built + linked on PATH — the skill
|
|
7
|
+
# runs `npm run build && ./scripts/local-install.sh` ONCE before looping repos.
|
|
8
|
+
# The A/B is skipped if extraction fails its critical checks (don't burn $ on a
|
|
9
|
+
# broken extractor); set FORCE_AB=1 to run it anyway.
|
|
10
|
+
#
|
|
11
|
+
# Usage: bench.sh <lang> <repo-name> <repo-url> "<question>" [headless|tmux|all]
|
|
12
|
+
# Env: CORPUS corpus dir (default /tmp/codegraph-corpus, shared with agent-eval)
|
|
13
|
+
set -uo pipefail
|
|
14
|
+
|
|
15
|
+
LANG_TOKEN="${1:?usage: bench.sh <lang> <repo-name> <repo-url> \"<question>\" [mode]}"
|
|
16
|
+
NAME="${2:?repo-name required}"
|
|
17
|
+
URL="${3:?repo-url required}"
|
|
18
|
+
Q="${4:?question required}"
|
|
19
|
+
MODE="${5:-headless}"
|
|
20
|
+
|
|
21
|
+
HARNESS="$(cd "$(dirname "$0")" && pwd)"
|
|
22
|
+
AGENT_EVAL="$(cd "$HARNESS/../agent-eval" && pwd)"
|
|
23
|
+
CORPUS="${CORPUS:-/tmp/codegraph-corpus}"
|
|
24
|
+
REPO="$CORPUS/$NAME"
|
|
25
|
+
|
|
26
|
+
command -v codegraph >/dev/null || { echo "no codegraph on PATH (build + ./scripts/local-install.sh first)"; exit 1; }
|
|
27
|
+
|
|
28
|
+
echo "==================== add-lang bench: $NAME ($LANG_TOKEN) ===================="
|
|
29
|
+
echo "codegraph: $(command -v codegraph) -> $(codegraph --version 2>/dev/null || echo '?')"
|
|
30
|
+
|
|
31
|
+
# 1. Ensure the repo (shallow clone, reuse if present).
|
|
32
|
+
mkdir -p "$CORPUS"
|
|
33
|
+
if [ -d "$REPO/.git" ]; then
|
|
34
|
+
echo "→ reusing checkout: $REPO"
|
|
35
|
+
else
|
|
36
|
+
echo "→ cloning $URL"
|
|
37
|
+
git clone --depth 1 "$URL" "$REPO" || { echo "git clone failed"; exit 1; }
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# 2. Wipe + index with the binary under test.
|
|
41
|
+
echo "→ wiping .codegraph and indexing"
|
|
42
|
+
rm -rf "$REPO/.codegraph"
|
|
43
|
+
( cd "$REPO" && codegraph init -i ) || { echo "indexing failed"; exit 1; }
|
|
44
|
+
|
|
45
|
+
# 3. Verify extraction (cheap guard before the paid A/B).
|
|
46
|
+
echo "→ verifying extraction"
|
|
47
|
+
node "$HARNESS/verify-extraction.mjs" "$REPO" "$LANG_TOKEN"
|
|
48
|
+
VERIFY=$?
|
|
49
|
+
|
|
50
|
+
# 4. Retrieval A/B (skipped if extraction is broken, unless FORCE_AB=1).
|
|
51
|
+
if [ "$VERIFY" -ne 0 ] && [ "${FORCE_AB:-0}" != "1" ]; then
|
|
52
|
+
echo "→ SKIPPING A/B — extraction failed critical checks (set FORCE_AB=1 to override)"
|
|
53
|
+
else
|
|
54
|
+
echo "→ retrieval A/B (mode=$MODE)"
|
|
55
|
+
bash "$AGENT_EVAL/run-all.sh" "$REPO" "$Q" "$MODE"
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
echo "==================== bench complete: $NAME (verify exit=$VERIFY) ===================="
|
|
59
|
+
# Exit reflects extraction: 0 = pass/warn, 1 = critical fail, 2 = couldn't read status.
|
|
60
|
+
exit "$VERIFY"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Verify a tree-sitter grammar wasm is HEALTHY under the project's web-tree-sitter
|
|
3
|
+
// runtime BEFORE writing an extractor. Prints the ABI version and parses a valid
|
|
4
|
+
// sample many times in a multi-grammar context, to catch heap-corruption bugs
|
|
5
|
+
// that silently drop nodes on every parse after the first.
|
|
6
|
+
//
|
|
7
|
+
// Why this exists: the tree-sitter-wasms Lua grammar is ABI 13 and corrupts the
|
|
8
|
+
// shared WASM heap under web-tree-sitter 0.25 — Lua extraction degraded on every
|
|
9
|
+
// file after the first (nested calls/imports vanished). The fix was to vendor the
|
|
10
|
+
// upstream ABI-15 wasm. Run this on any new grammar first; if it FAILs, vendor a
|
|
11
|
+
// newer build instead of using the tree-sitter-wasms one.
|
|
12
|
+
//
|
|
13
|
+
// Usage: node scripts/add-lang/check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]
|
|
14
|
+
// Exit: 0 healthy, 1 corruption / parse errors, 2 could not run.
|
|
15
|
+
// NOTE: the sample must be SYNTACTICALLY VALID — a broken sample fails for the
|
|
16
|
+
// wrong reason.
|
|
17
|
+
|
|
18
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
19
|
+
import { createRequire } from 'node:module';
|
|
20
|
+
import { Parser, Language } from 'web-tree-sitter';
|
|
21
|
+
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const fail = (code, msg) => { console.error(`[check-grammar] ${msg}`); process.exit(code); };
|
|
24
|
+
|
|
25
|
+
const [token, sample, iterArg] = process.argv.slice(2);
|
|
26
|
+
if (!token || !sample) fail(2, 'usage: check-grammar.mjs <lang|wasm-path> <valid-sample> [iterations]');
|
|
27
|
+
if (!existsSync(sample)) fail(2, `sample not found: ${sample}`);
|
|
28
|
+
const iters = iterArg ? parseInt(iterArg, 10) : 20;
|
|
29
|
+
|
|
30
|
+
const SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
|
|
31
|
+
function resolveWasm(t) {
|
|
32
|
+
if (t.endsWith('.wasm')) return existsSync(t) ? t : fail(2, `wasm not found: ${t}`);
|
|
33
|
+
const base = SPECIAL[t.toLowerCase()] ?? t.toLowerCase();
|
|
34
|
+
try { return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`); } catch { /* try vendored */ }
|
|
35
|
+
const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
|
|
36
|
+
if (existsSync(vendored)) return vendored;
|
|
37
|
+
return fail(2, `no grammar for "${t}" — not in tree-sitter-wasms and not vendored`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const wasmPath = resolveWasm(token);
|
|
41
|
+
const source = readFileSync(sample, 'utf8');
|
|
42
|
+
|
|
43
|
+
try { await Parser.init(); }
|
|
44
|
+
catch { await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') }); }
|
|
45
|
+
|
|
46
|
+
// Load a second, known-good grammar — the corruption surfaces under the
|
|
47
|
+
// multi-grammar runtime that real indexing uses, not a single grammar in isolation.
|
|
48
|
+
try { await Language.load(require.resolve('tree-sitter-wasms/out/tree-sitter-python.wasm')); } catch { /* ok */ }
|
|
49
|
+
|
|
50
|
+
let language;
|
|
51
|
+
try { language = await Language.load(wasmPath); }
|
|
52
|
+
catch (e) { fail(2, `failed to load ${wasmPath}: ${e.message}`); }
|
|
53
|
+
|
|
54
|
+
const parser = new Parser();
|
|
55
|
+
parser.setLanguage(language);
|
|
56
|
+
|
|
57
|
+
let ok = 0, err = 0;
|
|
58
|
+
for (let i = 0; i < iters; i++) {
|
|
59
|
+
const tree = parser.parse(source);
|
|
60
|
+
if (tree.rootNode.hasError) err++; else ok++;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(`grammar: ${wasmPath.split('/').pop()}`);
|
|
64
|
+
console.log(` ABI version: ${language.abiVersion}`);
|
|
65
|
+
console.log(` parses: ${ok} clean / ${err} with errors (of ${iters})`);
|
|
66
|
+
if (err > 0) {
|
|
67
|
+
console.log(
|
|
68
|
+
`RESULT: FAIL — ${err}/${iters} parses produced ERROR trees on a valid sample. ` +
|
|
69
|
+
`This grammar corrupts under web-tree-sitter; vendor a newer (ABI 14/15) wasm ` +
|
|
70
|
+
`(see SKILL.md "Find a grammar"). Confirm your sample is syntactically valid first.`
|
|
71
|
+
);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
console.log('RESULT: PASS — grammar parses cleanly and reuses safely.');
|
|
75
|
+
process.exit(0);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Dump the tree-sitter AST for a sample file so you can write a LanguageExtractor
|
|
3
|
+
// mapping. Loads a grammar .wasm directly via web-tree-sitter (the same runtime
|
|
4
|
+
// codegraph uses) — you do NOT need to register the language first.
|
|
5
|
+
//
|
|
6
|
+
// Usage:
|
|
7
|
+
// node scripts/add-lang/dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]
|
|
8
|
+
// Examples:
|
|
9
|
+
// node scripts/add-lang/dump-ast.mjs lua sample.lua
|
|
10
|
+
// node scripts/add-lang/dump-ast.mjs src/extraction/wasm/tree-sitter-zig.wasm a.zig --depth=4
|
|
11
|
+
//
|
|
12
|
+
// Output: an indented AST (named nodes, with field names) followed by a
|
|
13
|
+
// node-type FREQUENCY table. The frequency table is the payoff — it tells you
|
|
14
|
+
// which node types to map to functionTypes / classTypes / importTypes / etc.
|
|
15
|
+
|
|
16
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
import { Parser, Language } from 'web-tree-sitter';
|
|
19
|
+
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
const fail = (msg) => { console.error(`[dump-ast] ${msg}`); process.exit(1); };
|
|
22
|
+
|
|
23
|
+
const argv = process.argv.slice(2);
|
|
24
|
+
const positional = argv.filter((a) => !a.startsWith('--'));
|
|
25
|
+
const [langOrWasm, sampleFile] = positional;
|
|
26
|
+
const depthFlag = argv.find((a) => a.startsWith('--depth='));
|
|
27
|
+
const showAll = argv.includes('--full'); // also print anonymous (token) nodes
|
|
28
|
+
const maxDepth = depthFlag ? parseInt(depthFlag.split('=')[1], 10) : (showAll ? Infinity : 8);
|
|
29
|
+
|
|
30
|
+
if (!langOrWasm || !sampleFile) {
|
|
31
|
+
fail('usage: dump-ast.mjs <lang|wasm-path> <sample-file> [--depth=N] [--full]');
|
|
32
|
+
}
|
|
33
|
+
if (!existsSync(sampleFile)) fail(`sample file not found: ${sampleFile}`);
|
|
34
|
+
|
|
35
|
+
// Language tokens whose tree-sitter-wasms filename differs from the token.
|
|
36
|
+
const WASM_SPECIAL = { csharp: 'c_sharp', 'c#': 'c_sharp' };
|
|
37
|
+
|
|
38
|
+
function resolveWasm(token) {
|
|
39
|
+
if (token.endsWith('.wasm')) {
|
|
40
|
+
if (!existsSync(token)) fail(`wasm not found: ${token}`);
|
|
41
|
+
return token;
|
|
42
|
+
}
|
|
43
|
+
const base = WASM_SPECIAL[token.toLowerCase()] ?? token.toLowerCase();
|
|
44
|
+
try {
|
|
45
|
+
return require.resolve(`tree-sitter-wasms/out/tree-sitter-${base}.wasm`);
|
|
46
|
+
} catch {
|
|
47
|
+
/* not in tree-sitter-wasms — try a vendored copy */
|
|
48
|
+
}
|
|
49
|
+
const vendored = `src/extraction/wasm/tree-sitter-${base}.wasm`;
|
|
50
|
+
if (existsSync(vendored)) return vendored;
|
|
51
|
+
fail(
|
|
52
|
+
`no grammar for "${token}" — not in tree-sitter-wasms and not vendored at ` +
|
|
53
|
+
`${vendored}. Pass an explicit .wasm path, or vendor one (see SKILL.md "Find a grammar").`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const wasmPath = resolveWasm(langOrWasm);
|
|
58
|
+
const source = readFileSync(sampleFile, 'utf8');
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
await Parser.init();
|
|
62
|
+
} catch {
|
|
63
|
+
await Parser.init({ locateFile: () => require.resolve('web-tree-sitter/tree-sitter.wasm') });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let language;
|
|
67
|
+
try {
|
|
68
|
+
language = await Language.load(wasmPath);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
fail(`failed to load grammar ${wasmPath}: ${e.message}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const parser = new Parser();
|
|
74
|
+
parser.setLanguage(language);
|
|
75
|
+
const tree = parser.parse(source);
|
|
76
|
+
|
|
77
|
+
const freq = new Map();
|
|
78
|
+
const snippet = (node) => {
|
|
79
|
+
const t = node.text.replace(/\s+/g, ' ').trim();
|
|
80
|
+
return t.length > 48 ? `${t.slice(0, 48)}…` : t;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function walk(node, depth, fieldName) {
|
|
84
|
+
if (node.isNamed) freq.set(node.type, (freq.get(node.type) || 0) + 1);
|
|
85
|
+
if ((node.isNamed || showAll) && depth <= maxDepth) {
|
|
86
|
+
const field = fieldName ? `${fieldName}: ` : '';
|
|
87
|
+
const leaf = node.childCount === 0 ? ` "${snippet(node)}"` : '';
|
|
88
|
+
console.log(`${' '.repeat(depth)}${field}${node.type} @${node.startPosition.row + 1}:${node.startPosition.column}${leaf}`);
|
|
89
|
+
}
|
|
90
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
91
|
+
const child = node.child(i);
|
|
92
|
+
if (child) walk(child, depth + 1, node.fieldNameForChild(i));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(`\n# AST for ${sampleFile} (grammar: ${wasmPath.split('/').pop()})\n`);
|
|
97
|
+
walk(tree.rootNode, 0, null);
|
|
98
|
+
|
|
99
|
+
console.log('\n# Node-type frequency (named nodes) — map the relevant ones in your extractor:\n');
|
|
100
|
+
[...freq.entries()]
|
|
101
|
+
.sort((a, b) => b[1] - a[1])
|
|
102
|
+
.forEach(([type, n]) => console.log(` ${String(n).padStart(5)} ${type}`));
|
|
103
|
+
console.log();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Sanity-check that codegraph extracted REAL symbols (not just file/import nodes)
|
|
3
|
+
// from a repo for a given language. Exits non-zero on a critical failure so it
|
|
4
|
+
// can drive a write-extractor -> build -> re-check loop.
|
|
5
|
+
//
|
|
6
|
+
// Usage: node scripts/add-lang/verify-extraction.mjs <repo-path> <lang>
|
|
7
|
+
// Reads `codegraph status <repo> --json` using whatever codegraph is on PATH,
|
|
8
|
+
// so it reflects the binary that built the index.
|
|
9
|
+
//
|
|
10
|
+
// Exit codes: 0 = pass or soft-warn, 1 = critical fail, 2 = could not run.
|
|
11
|
+
|
|
12
|
+
import { execFileSync } from 'node:child_process';
|
|
13
|
+
|
|
14
|
+
const [repo, lang] = process.argv.slice(2);
|
|
15
|
+
if (!repo || !lang) {
|
|
16
|
+
console.error('usage: verify-extraction.mjs <repo-path> <lang>');
|
|
17
|
+
process.exit(2);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let status;
|
|
21
|
+
try {
|
|
22
|
+
const out = execFileSync('codegraph', ['status', repo, '--json'], { encoding: 'utf8' });
|
|
23
|
+
status = JSON.parse(out);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(`[verify] could not read codegraph status for ${repo}: ${e.message}`);
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Kinds that prove the extractor mapped AST node types (everything except
|
|
30
|
+
// 'file' and 'import', which codegraph creates structurally for any language).
|
|
31
|
+
const SYMBOL_KINDS = new Set([
|
|
32
|
+
'module', 'class', 'struct', 'interface', 'trait', 'protocol', 'function',
|
|
33
|
+
'method', 'property', 'field', 'variable', 'constant', 'enum', 'enum_member',
|
|
34
|
+
'type_alias', 'namespace', 'route', 'component',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const byKind = status.nodesByKind || {};
|
|
38
|
+
const langs = status.languages || [];
|
|
39
|
+
const files = status.fileCount || 0;
|
|
40
|
+
const edges = status.edgeCount || 0;
|
|
41
|
+
const symbolKinds = Object.keys(byKind).filter((k) => SYMBOL_KINDS.has(k));
|
|
42
|
+
const symbolCount = symbolKinds.reduce((s, k) => s + byKind[k], 0);
|
|
43
|
+
|
|
44
|
+
const checks = [];
|
|
45
|
+
const add = (severity, ok, label, detail) => checks.push({ severity, ok, label, detail });
|
|
46
|
+
|
|
47
|
+
add('critical', status.initialized === true, 'index initialized', `initialized=${status.initialized}`);
|
|
48
|
+
add('critical', langs.includes(lang), `language "${lang}" detected`, `languages=[${langs.join(', ')}]`);
|
|
49
|
+
add('critical', symbolCount > 0, 'structural symbols extracted', `${symbolCount} symbols (${symbolKinds.join(', ') || 'NONE — only file/import nodes!'})`);
|
|
50
|
+
add('soft', symbolCount >= files, 'symbol density >= 1/file', `${symbolCount} symbols across ${files} files`);
|
|
51
|
+
add('soft', edges > files, 'edges resolved', `${edges} edges across ${files} files`);
|
|
52
|
+
|
|
53
|
+
console.log(`\n# Extraction check — ${repo} (lang=${lang}, backend=${status.backend})`);
|
|
54
|
+
console.log(` files=${files} nodes=${status.nodeCount} edges=${edges}`);
|
|
55
|
+
console.log(` nodesByKind: ${JSON.stringify(byKind)}\n`);
|
|
56
|
+
for (const c of checks) console.log(` ${c.ok ? '✓' : '✗'} ${c.label} — ${c.detail}`);
|
|
57
|
+
|
|
58
|
+
const critical = checks.filter((c) => !c.ok && c.severity === 'critical');
|
|
59
|
+
const soft = checks.filter((c) => !c.ok && c.severity === 'soft');
|
|
60
|
+
console.log();
|
|
61
|
+
if (critical.length) {
|
|
62
|
+
console.log(`RESULT: FAIL (${critical.length} critical) — extractor or grammar wiring is broken. Re-run dump-ast.mjs and fix the node-type mappings.`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (soft.length) {
|
|
66
|
+
console.log(`RESULT: WARN (${soft.length} soft) — extraction works but looks thin; inspect the counts above.`);
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|
|
69
|
+
console.log('RESULT: PASS — extraction looks healthy.');
|
|
70
|
+
process.exit(0);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Does the agent PICK codegraph_node to read a file, vs the built-in Read tool?
|
|
3
|
+
# Build A/B: NEW build (HEAD, codegraph_node has Read parity) vs BASELINE build
|
|
4
|
+
# (a ref where it doesn't), BOTH codegraph-attached + pre-warmed, same task. The
|
|
5
|
+
# metric is tool CHOICE: Read calls vs codegraph_node[file] calls per run.
|
|
6
|
+
#
|
|
7
|
+
# Usage: ab-adoption.sh <indexed-repo> "<task>" [runs-per-arm] [baseline-ref]
|
|
8
|
+
# Env: AGENT_EVAL_OUT (default: /tmp/ab-adoption)
|
|
9
|
+
set -uo pipefail
|
|
10
|
+
TARGET="${1:?usage: ab-adoption.sh <indexed-repo> \"<task>\" [runs] [baseline-ref]}"
|
|
11
|
+
TASK="${2:?task required}"
|
|
12
|
+
RUNS="${3:-2}"
|
|
13
|
+
BASE_REF="${4:-HEAD~1}"
|
|
14
|
+
ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
15
|
+
BIN="$ENGINE/dist/bin/codegraph.js"
|
|
16
|
+
OUT="${AGENT_EVAL_OUT:-/tmp/ab-adoption}"
|
|
17
|
+
|
|
18
|
+
command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
|
|
19
|
+
[ -d "$TARGET/.codegraph" ] || { echo "target not indexed: run 'codegraph init $TARGET' first"; exit 1; }
|
|
20
|
+
git -C "$ENGINE" diff --quiet && git -C "$ENGINE" diff --cached --quiet || { echo "engine has uncommitted changes — commit/stash first"; exit 1; }
|
|
21
|
+
CHANGED=$(git -C "$ENGINE" diff --name-only "$BASE_REF" HEAD -- src 2>/dev/null)
|
|
22
|
+
[ -n "$CHANGED" ] || { echo "no src/ changes between $BASE_REF and HEAD"; exit 1; }
|
|
23
|
+
|
|
24
|
+
cleanup() {
|
|
25
|
+
pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null
|
|
26
|
+
git -C "$ENGINE" checkout HEAD -- $CHANGED 2>/dev/null
|
|
27
|
+
( cd "$ENGINE" && npm run build >/dev/null 2>&1 )
|
|
28
|
+
}
|
|
29
|
+
trap cleanup EXIT
|
|
30
|
+
mkdir -p "$OUT"
|
|
31
|
+
echo "###### target=$TARGET runs/arm=$RUNS baseline=$BASE_REF"
|
|
32
|
+
echo "###### changed: $(echo "$CHANGED" | tr '\n' ' ')"
|
|
33
|
+
echo "###### task=$TASK"; echo
|
|
34
|
+
|
|
35
|
+
prewarm() {
|
|
36
|
+
pkill -9 -f "serve --mcp --path $1" 2>/dev/null
|
|
37
|
+
CODEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
|
|
38
|
+
node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.codegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Per-run tool-choice counts: Read vs codegraph_node[file] vs [symbol].
|
|
42
|
+
count() {
|
|
43
|
+
node -e '
|
|
44
|
+
const fs=require("fs");
|
|
45
|
+
const lines=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
|
|
46
|
+
let read=0,cgFile=0,cgSym=0,cgOther=0,exposed="?";
|
|
47
|
+
for(const l of lines){try{const o=JSON.parse(l);
|
|
48
|
+
if(o.type==="system"&&o.subtype==="init"){exposed=(o.tools||[]).filter(t=>/codegraph/.test(t)).length;}
|
|
49
|
+
const blocks=o.message?.content||[];
|
|
50
|
+
for(const b of (Array.isArray(blocks)?blocks:[])){
|
|
51
|
+
if(b.type!=="tool_use")continue;
|
|
52
|
+
if(b.name==="Read")read++;
|
|
53
|
+
else if(b.name==="mcp__codegraph__codegraph_node"){ if(b.input&&b.input.symbol)cgSym++; else cgFile++; }
|
|
54
|
+
else if(/mcp__codegraph__/.test(b.name))cgOther++;
|
|
55
|
+
}
|
|
56
|
+
}catch{}}
|
|
57
|
+
console.log(` Read=${read} codegraph_node[file]=${cgFile} codegraph_node[symbol]=${cgSym} other_cg=${cgOther} (cg exposed=${exposed})`);
|
|
58
|
+
' "$1"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
run_arm() { # label, N
|
|
62
|
+
local label="$1" n="$2"
|
|
63
|
+
local c="$OUT/mcp-$label.json"
|
|
64
|
+
for i in $(seq 1 "$n"); do
|
|
65
|
+
local tgt="$OUT/t-$label-$i"
|
|
66
|
+
rm -rf "$tgt"
|
|
67
|
+
rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .codegraph "$TARGET/" "$tgt/"
|
|
68
|
+
node "$BIN" init "$tgt" >/dev/null 2>&1
|
|
69
|
+
printf '{"mcpServers":{"codegraph":{"command":"env","args":["CODEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
|
|
70
|
+
prewarm "$tgt"
|
|
71
|
+
echo "----- [$label] run $i -----"
|
|
72
|
+
( cd "$tgt" && claude -p "$TASK" \
|
|
73
|
+
--output-format stream-json --verbose --permission-mode bypassPermissions \
|
|
74
|
+
--model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" \
|
|
75
|
+
</dev/null > "$OUT/run-$label-$i.jsonl" 2>"$OUT/run-$label-$i.err" )
|
|
76
|
+
count "$OUT/run-$label-$i.jsonl"
|
|
77
|
+
pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
|
|
78
|
+
done
|
|
79
|
+
echo
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
echo "== NEW build (HEAD: codegraph_node has Read parity) =="
|
|
83
|
+
( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
|
|
84
|
+
run_arm new "$RUNS"
|
|
85
|
+
|
|
86
|
+
echo "== BASELINE build ($BASE_REF) =="
|
|
87
|
+
git -C "$ENGINE" checkout "$BASE_REF" -- $CHANGED
|
|
88
|
+
( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
|
|
89
|
+
run_arm baseline "$RUNS"
|
|
90
|
+
|
|
91
|
+
echo "###### DONE — compare [new] vs [baseline]: does codegraph_node[file] rise / Read fall? Logs: $OUT"
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# A/B the PreToolUse(Read) REDIRECT hook (P1): does steering Read → codegraph_node
|
|
3
|
+
# file-view actually move the agent off Read during implementation? BOTH arms use
|
|
4
|
+
# the CURRENT build with codegraph attached and pre-warmed; the only difference is
|
|
5
|
+
# the hook. Isolates the hook's behavioral effect from the build/file-view change
|
|
6
|
+
# (use ab-new-vs-baseline.sh for the build A/B).
|
|
7
|
+
#
|
|
8
|
+
# arm [nohook] — codegraph on, no hook (does the better file-view get picked on its own?)
|
|
9
|
+
# arm [hook] — codegraph on, + redirect hook (does routing close it?)
|
|
10
|
+
#
|
|
11
|
+
# Reliable attach (works nested): each arm pre-warms a persistent daemon and skips
|
|
12
|
+
# the startup re-exec (CODEGRAPH_WASM_RELAUNCHED=1), so claude connects before the
|
|
13
|
+
# agent's first turn. Judge by ACTUAL codegraph usage in parse-run.mjs's "by type",
|
|
14
|
+
# not claude's init snapshot (which can read pending even when it then connects).
|
|
15
|
+
#
|
|
16
|
+
# Usage: ab-hook.sh <indexed-repo> "<implementation task>" [runs-per-arm]
|
|
17
|
+
# <indexed-repo> a repo with a .codegraph index (copied per arm; never mutated)
|
|
18
|
+
# "<task>" a GENUINELY-NEW implementation task (verify it isn't already done)
|
|
19
|
+
# [runs-per-arm] default 2 (n=1 is noisy — the doctrine says >=2)
|
|
20
|
+
# Env: AGENT_EVAL_OUT (default: /tmp/ab-hook)
|
|
21
|
+
set -uo pipefail
|
|
22
|
+
|
|
23
|
+
TARGET="${1:?usage: ab-hook.sh <indexed-repo> \"<task>\" [runs-per-arm]}"
|
|
24
|
+
TASK="${2:?task required}"
|
|
25
|
+
RUNS="${3:-2}"
|
|
26
|
+
ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
27
|
+
BIN="$ENGINE/dist/bin/codegraph.js"
|
|
28
|
+
HOOK="$ENGINE/scripts/agent-eval/redirect-read-hook.sh"
|
|
29
|
+
OUT="${AGENT_EVAL_OUT:-/tmp/ab-hook}"
|
|
30
|
+
PARSE="$ENGINE/scripts/agent-eval/parse-run.mjs"
|
|
31
|
+
|
|
32
|
+
command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
|
|
33
|
+
command -v jq >/dev/null || { echo "jq not on PATH (the hook needs it)"; exit 1; }
|
|
34
|
+
[ -d "$TARGET/.codegraph" ] || { echo "target not indexed: run 'codegraph init $TARGET' first"; exit 1; }
|
|
35
|
+
chmod +x "$HOOK"
|
|
36
|
+
|
|
37
|
+
cleanup() { pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
|
|
38
|
+
trap cleanup EXIT
|
|
39
|
+
|
|
40
|
+
mkdir -p "$OUT"
|
|
41
|
+
echo "###### engine=$ENGINE"
|
|
42
|
+
echo "###### target=$TARGET runs/arm=$RUNS"
|
|
43
|
+
echo "###### task=$TASK"
|
|
44
|
+
echo
|
|
45
|
+
|
|
46
|
+
( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built"
|
|
47
|
+
|
|
48
|
+
# A settings file carrying ONLY the PreToolUse(Read) redirect hook.
|
|
49
|
+
HOOK_SETTINGS="$OUT/hook-settings.json"
|
|
50
|
+
jq -n --arg cmd "bash $HOOK" \
|
|
51
|
+
'{hooks:{PreToolUse:[{matcher:"Read",hooks:[{type:"command",command:$cmd}]}]}}' > "$HOOK_SETTINGS"
|
|
52
|
+
|
|
53
|
+
prewarm() { # target — spawn a persistent daemon and wait for its socket
|
|
54
|
+
pkill -9 -f "serve --mcp --path $1" 2>/dev/null
|
|
55
|
+
CODEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
|
|
56
|
+
node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.codegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" \
|
|
57
|
+
&& echo " daemon warm: $1" || echo " WARN: daemon never bound for $1"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
run_one() { # arm-label, run-index, use-hook(0|1)
|
|
61
|
+
local label="$1" idx="$2" hook="$3"
|
|
62
|
+
local tgt="$OUT/t-$label-$idx" c="$OUT/mcp-$label.json"
|
|
63
|
+
rm -rf "$tgt"
|
|
64
|
+
rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .codegraph "$TARGET/" "$tgt/"
|
|
65
|
+
node "$BIN" init "$tgt" >/dev/null 2>&1
|
|
66
|
+
printf '{"mcpServers":{"codegraph":{"command":"env","args":["CODEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$c"
|
|
67
|
+
prewarm "$tgt"
|
|
68
|
+
local extra=()
|
|
69
|
+
[ "$hook" = "1" ] && extra=(--settings "$HOOK_SETTINGS")
|
|
70
|
+
echo "----- [$label] run $idx -----"
|
|
71
|
+
# ${extra[@]+...} guard: bash 3.2 (macOS) under `set -u` errors on an empty
|
|
72
|
+
# array expansion otherwise, which would skip the no-hook arm's claude run.
|
|
73
|
+
( cd "$tgt" && claude -p "$TASK" \
|
|
74
|
+
--output-format stream-json --verbose --permission-mode bypassPermissions \
|
|
75
|
+
--model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 --strict-mcp-config --mcp-config "$c" ${extra[@]+"${extra[@]}"} \
|
|
76
|
+
</dev/null > "$OUT/run-$label-$idx.jsonl" 2>"$OUT/run-$label-$idx.err" )
|
|
77
|
+
node "$PARSE" "$OUT/run-$label-$idx.jsonl" 2>&1 | grep -E "by type|Result" || echo " (parse failed — see $OUT/run-$label-$idx.jsonl)"
|
|
78
|
+
pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
|
|
79
|
+
echo
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for i in $(seq 1 "$RUNS"); do run_one nohook "$i" 0; done
|
|
83
|
+
for i in $(seq 1 "$RUNS"); do run_one hook "$i" 1; done
|
|
84
|
+
|
|
85
|
+
echo "###### DONE. Compare [nohook] vs [hook] 'by type' — Read should fall and"
|
|
86
|
+
echo "###### mcp__codegraph__codegraph_node should rise in the [hook] arm. Logs: $OUT"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Sufficiency A/B for an IMPLEMENTATION task (the agent edits): when it uses
|
|
3
|
+
# codegraph (explore/node) to understand before editing, does it still Read? Like
|
|
4
|
+
# ab-sufficiency.sh but copies+indexes a FRESH target per run (the agent mutates
|
|
5
|
+
# it), so runs don't see each other's edits.
|
|
6
|
+
#
|
|
7
|
+
# WITH codegraph (pre-warmed) vs WITHOUT (empty MCP), N runs each. Reports
|
|
8
|
+
# explore/node vs Read/Grep + the files Read, and whether the build still passes.
|
|
9
|
+
#
|
|
10
|
+
# Usage: ab-impl.sh <indexed-repo> "<task>" [runs] [build-cmd]
|
|
11
|
+
# Env: AGENT_EVAL_OUT (default: /tmp/ab-impl)
|
|
12
|
+
set -uo pipefail
|
|
13
|
+
REPO="${1:?usage: ab-impl.sh <indexed-repo> \"<task>\" [runs] [build-cmd]}"
|
|
14
|
+
Q="${2:?task required}"
|
|
15
|
+
RUNS="${3:-2}"
|
|
16
|
+
BUILD_CMD="${4:-}"
|
|
17
|
+
ENGINE="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
18
|
+
BIN="$ENGINE/dist/bin/codegraph.js"
|
|
19
|
+
OUT="${AGENT_EVAL_OUT:-/tmp/ab-impl}"
|
|
20
|
+
command -v claude >/dev/null || { echo "claude CLI not on PATH"; exit 1; }
|
|
21
|
+
[ -d "$REPO/.codegraph" ] || { echo "no .codegraph index at $REPO"; exit 1; }
|
|
22
|
+
cleanup(){ pkill -9 -f "serve --mcp --path $OUT/" 2>/dev/null; }
|
|
23
|
+
trap cleanup EXIT
|
|
24
|
+
mkdir -p "$OUT"
|
|
25
|
+
( cd "$ENGINE" && npm run build >/dev/null 2>&1 ) && echo "built engine"
|
|
26
|
+
echo "###### repo=$REPO runs/arm=$RUNS"
|
|
27
|
+
echo "###### task=$Q"; echo
|
|
28
|
+
echo '{"mcpServers":{}}' > "$OUT/mcp-empty.json"
|
|
29
|
+
|
|
30
|
+
prewarm(){
|
|
31
|
+
pkill -9 -f "serve --mcp --path $1" 2>/dev/null
|
|
32
|
+
CODEGRAPH_DAEMON_IDLE_TIMEOUT_MS=1800000 node "$BIN" serve --mcp --path "$1" </dev/null >/dev/null 2>&1 &
|
|
33
|
+
node -e 'const fs=require("fs");let n=0;const t=setInterval(()=>{if(fs.existsSync(process.argv[1]+"/.codegraph/daemon.sock")){clearInterval(t);process.exit(0)}if(n++>150){clearInterval(t);process.exit(1)}},100)' "$1" >/dev/null 2>&1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
analyze(){
|
|
37
|
+
node -e '
|
|
38
|
+
const fs=require("fs");
|
|
39
|
+
const L=fs.readFileSync(process.argv[1],"utf8").split("\n").filter(Boolean);
|
|
40
|
+
let ex=0,nf=0,ns=0,oc=0,gr=0,ed=0,exposed="?";const reads=[];
|
|
41
|
+
for(const l of L){try{const o=JSON.parse(l);
|
|
42
|
+
if(o.type==="system"&&o.subtype==="init")exposed=(o.tools||[]).filter(t=>/codegraph/.test(t)).length;
|
|
43
|
+
for(const b of (o.message?.content||[])){if(b.type!=="tool_use")continue;
|
|
44
|
+
if(b.name==="mcp__codegraph__codegraph_explore")ex++;
|
|
45
|
+
else if(b.name==="mcp__codegraph__codegraph_node"){if(b.input&&b.input.symbol)ns++;else nf++;}
|
|
46
|
+
else if(/mcp__codegraph__/.test(b.name))oc++;
|
|
47
|
+
else if(b.name==="Read")reads.push((b.input?.file_path||"").split("/").pop());
|
|
48
|
+
else if(b.name==="Grep")gr++;
|
|
49
|
+
else if(b.name==="Edit"||b.name==="Write")ed++;
|
|
50
|
+
}}catch{}}
|
|
51
|
+
console.log(` explore=${ex} node[sym]=${ns} node[file]=${nf} other_cg=${oc} | Read=${reads.length}${reads.length?" ("+reads.join(", ")+")":""} Grep=${gr} Edit=${ed} [cg exposed=${exposed}]`);
|
|
52
|
+
' "$1"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
run(){ # label, withCodegraph(0/1)
|
|
56
|
+
local label="$1" wcg="$2"
|
|
57
|
+
for i in $(seq 1 "$RUNS"); do
|
|
58
|
+
local tgt="$OUT/t-$label-$i" cfg="$OUT/mcp-$label.json"
|
|
59
|
+
rm -rf "$tgt"
|
|
60
|
+
rsync -a --exclude node_modules --exclude .git --exclude dist --exclude .codegraph "$REPO/" "$tgt/"
|
|
61
|
+
node "$BIN" init "$tgt" >/dev/null 2>&1
|
|
62
|
+
if [ "$wcg" = "1" ]; then
|
|
63
|
+
printf '{"mcpServers":{"codegraph":{"command":"env","args":["CODEGRAPH_WASM_RELAUNCHED=1","node","%s","serve","--mcp","--path","%s"]}}}' "$BIN" "$tgt" > "$cfg"
|
|
64
|
+
prewarm "$tgt"
|
|
65
|
+
else cp "$OUT/mcp-empty.json" "$cfg"; fi
|
|
66
|
+
( cd "$tgt" && claude -p "$Q" --output-format stream-json --verbose \
|
|
67
|
+
--permission-mode bypassPermissions --model "${MODEL:-sonnet}" --effort "${EFFORT:-high}" --max-budget-usd 4 \
|
|
68
|
+
--strict-mcp-config --mcp-config "$cfg" </dev/null > "$OUT/$label-$i.jsonl" 2>"$OUT/$label-$i.err" )
|
|
69
|
+
echo "[$label] run $i:"; analyze "$OUT/$label-$i.jsonl"
|
|
70
|
+
if [ -n "$BUILD_CMD" ]; then ( cd "$tgt" && eval "$BUILD_CMD" >/dev/null 2>&1 && echo " build: PASS" || echo " build: FAIL" ); fi
|
|
71
|
+
pkill -9 -f "serve --mcp --path $tgt" 2>/dev/null
|
|
72
|
+
done
|
|
73
|
+
echo
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
echo "== WITH codegraph =="; run with 1
|
|
77
|
+
echo "== WITHOUT (Read/Grep only) =="; run without 0
|
|
78
|
+
echo "###### DONE: $OUT"
|