Skip to content

GDScript support, plus two fixes: Windows blast radius and sticky --only-dir - #299

Closed
wesleytakatsu wants to merge 4 commits into
trailhq:mainfrom
wesleytakatsu:feat/gdscript-breadth-tier
Closed

wesleytakatsu wants to merge 4 commits into
trailhq:mainfrom
wesleytakatsu:feat/gdscript-breadth-tier

Conversation

@wesleytakatsu

Copy link
Copy Markdown

Four changes, found while wiring graft into a 1,619-file Godot + Go game repo. Two are bug fixes that stand on their own; two add GDScript. Happy to split this into separate PRs if you'd rather review them apart — the files don't overlap.

Every claim below is measured on that repo (1,273 files indexed after scoping, 846 of them .gd).


1. fix(claude): match the edited file on Windows, so blast radius fires (c4f39b9)

The post-edit hook forwards tool_input.file_path exactly as the host wrote it. On Windows that is a backslash path, while every node.path in the graph is posix by construction. nodeIdsInFile compared them with filePath.endsWith("/" + n.path), which cannot match across separators — so the lookup returned an empty set and formatBlastRadius returned null.

On every edit, in every language, with no error anywhere. Editing a file with eight dependents cost the hook's full ~9s and printed nothing. Normalizing the incoming path turns that same edit into the eight-line radius the hook was written to produce.

This one is independent of the GDScript work and affects every Windows user today.

2. fix(build): make --only-dir survive a no-flag rebuild (4408ba9)

--only-dir's whitelist was recorded only in the graph fingerprint, and the fingerprint is rewritten by every build. sync-run.ts shells a bare graft build . that never sees a CLI flag, so the first post-edit rebuild after a --only-dir build silently re-indexed the whole repo.

Where the excluded directories are vendored reference code, that is not cosmetic: on this repo an unscoped index put four of six hits for "player movement" in sample FPS templates and none in the actual game. One file edit undid the scope, with nothing in the output saying so.

The list now persists in graft/.cache/only-dirs.json and is read back when no flag is passed. Keeping it under graft/ rather than in .graft/config.json preserves the property test/graph-only-dir.test.ts guards — a --only-dir build still leaves no trace in the repo being indexed, and that test passes unchanged. --all-dirs clears it, since a sticky whitelist otherwise has no escape hatch short of deleting the graph.

Measured: --only-dir build indexes 1,273 files; a subsequent bare graft build . used to return to 1,619 and now stays at 1,273.

3. feat(graph): add GDScript to the breadth tier (c06d6ad)

Godot projects are a large unserved corpus — a mid-size game is a four-figure count of .gd files, and today every one is skipped, so graft indexes the C#/C++/Go edges of a Godot repo and none of the game logic. tree-sitter-wasm already ships the gdscript grammar, so this is one registry row plus a tags query.

The query is deliberately narrow on variables. A bare (variable_statement) also matches every local inside a function body — on this repo that was ~36k extra nodes (66.5k vs 30.5k total), which buries the symbols an agent is searching for. Scoping const/var to (source ...) and (class_body ...) keeps the class-level API and drops the locals, at the cost of ~1.4k local-to-local call edges.

Signals get a name of their own so graft callers <signal> finds every emit and connect site — that is the wiring an agent most needs in a Godot codebase, and the thing grep is worst at.

4. feat(graph): GDScript preload/load become import edges (d1cb17c)

GDScript has no import statement; a script reaches another through preload("res://...") or load(...). Without those, .gd files had symbol-level call edges and no file-level edges at all, so anything reading incoming edges on a file — blast radius, graft callers <file> — had nothing to report for an entire language.

res:// is the Godot project root, which sits at an unknown depth under the repo root and may appear more than once, so the specifier is matched as a path suffix over an index of every directory boundary — the same approach already used for Java, C and PHP. Only a unique hit resolves; an ambiguous or absent one keeps the raw specifier rather than pointing the edge at a same-named file in a different project.

@reference.import is handled generically rather than as a GDScript special case: any breadth-tier grammar can now mark a specifier and get file-level import edges, and the edge is attributed to the file, not to whatever definition encloses the call.

Measured: 3,301 import edges, 3,252 resolved to a file (the 49 left are runtime load() of computed paths); total edges 29,166 → 31,204.


Tests

New regression tests in test/generic-extract.test.ts (GDScript symbols, and preload/load import edges including the dedupe and the dangling-specifier case), test/graph-only-dir.test.ts (whitelist survives a no-flag rebuild; --all-dirs clears it), and test/claude-format.test.ts (a Windows path resolves to the same nodes).

npx tsx --test over test/graph-*.test.ts plus generic-extract, covers, regression-single-repo, supported-extensions, util-state, context-only-dir: 377 pass, 0 fail, 5 skipped.

Three tests in claude-format and four in claude-hooks/session-metrics fail on my machine, all in the token/dollar accounting paths. They fail identically on a clean checkout of main — I verified with git stash — so they are not from this branch.

Docs

README.md's breadth-tier list gains GDScript (23 → 24 languages).

🤖 Generated with Claude Code

wesleytakatsu and others added 4 commits September 4, 2026 03:03
Godot projects are a large, unserved corpus: a mid-size game is a
four-figure count of .gd files, and today every one of them is skipped, so
graft indexes the C#/C++/Go edges of a Godot repo and none of the game
logic. tree-sitter-wasm already ships the gdscript grammar, so this costs
one registry row plus a tags query.

The query is deliberately narrow on variables. A bare `(variable_statement)`
also matches every local inside a function body — on a real 1,074-file Godot
repo that is ~36k extra nodes (66.5k vs 30.5k total), which buries the
symbols an agent is searching for. Scoping const/var to `(source ...)` and
`(class_body ...)` keeps the class-level API and drops the locals, at the
cost of ~1.4k local-to-local call edges.

Signals get a name of their own so `graft callers <signal>` finds every
emit and connect site — that is the wiring an agent most needs in a Godot
codebase and the thing grep is worst at.

Measured on a 1,619-file mixed Godot/Go repo: 545 → 1,619 files indexed,
6,323 → 30,480 nodes, 14,816 → 36,906 edges, 86s cold build.
The whitelist was recorded only in the graph fingerprint, and the fingerprint
is rewritten by every build. The Claude Code hooks shell a bare
`graft build .` (sync-run.ts) that never sees a CLI flag, so the first
post-edit rebuild after a `--only-dir` build silently re-indexed the whole
repo. On a repo where the excluded directories are vendored reference code,
that is not a cosmetic regression: the scope the user set to keep sample
code out of their results is gone after one file edit, with no output
saying so.

Persist the list beside the graph, in `graft/.cache/only-dirs.json`, and
read it back when no flag is passed. Keeping it under `graft/` rather than
in `.graft/config.json` preserves the property the existing test guards —
a `--only-dir` build still leaves no trace in the repo being indexed.

`--all-dirs` clears it, since otherwise a sticky whitelist would have no
escape hatch short of deleting the graph.

Measured on a 1,619-file repo: `--only-dir` build indexes 1,273 files; a
subsequent bare `graft build .` used to return to 1,619 and now stays at
1,273.
The post-edit hook forwards `tool_input.file_path` exactly as the host
wrote it. On Windows that is a backslash path; every `node.path` in the
graph is posix by construction. `nodeIdsInFile` compared them with
`filePath.endsWith("/" + n.path)`, which cannot match across separators,
so the lookup returned an empty set and `formatBlastRadius` returned
null — on every edit, in every language, with no error anywhere.

Symptom on a 1,273-file repo: editing a file with eight dependents cost
the hook's full ~9s and printed nothing. Normalizing the incoming path
turns the same edit into the eight-line radius the hook was written to
produce.

Co-Authored-By: Claude Opus 5 <[email protected]>
GDScript has no import statement — a script reaches another script through
`preload("res://...")` or `load(...)`. Without those the breadth tier gave
.gd files symbol-level call edges and no file-level edges at all, so
anything reading incoming edges on a file (blast radius, `graft callers
<file>`) had nothing to report for an entire language.

`res://` is the Godot project root, which sits at an unknown depth under
the repo root and may appear more than once, so the specifier is matched
as a path suffix over an index of every directory boundary — the same
approach already used for Java, C and PHP. Only a unique hit resolves;
an ambiguous or absent one keeps the raw specifier rather than pointing
the edge at a same-named file in a different project.

@reference.import is handled generically rather than as a GDScript
special case: any breadth-tier grammar can now mark a specifier and get
file-level import edges, and the edge is attributed to the file, not to
whatever definition happens to enclose the call.

Measured on a 1,273-file repo: 3,301 import edges, 3,252 of them resolved
to a file (the 49 left are runtime `load()` of computed paths); total
edges 29,166 to 31,204.

Co-Authored-By: Claude Opus 5 <[email protected]>
@trailhq-graft

trailhq-graft Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

🌱 graft blast radius

4 areas changed → 6 areas can be affected. 15 dependent symbols, depth 2.
Tests: no test reaches Directory State Tracking, File Node Formatting; 1 area updated its tests.
Tag: @anirudhkumar-nanonets — 8 of 10 areas · @shhdwi — 7 of 10 areas · @bhavesh-gupta-investis — Synchronous Execution

flowchart TB
  A0(("Graph Freshness Check<br/>6 symbols"))
  A1(("Pull Request Review<br/>4 symbols"))
  A2(("Engine Graph API<br/>2 symbols"))
  A3(("Viewer Build Script<br/>1 symbol"))
  A4(("MCP Tool Invocation<br/>1 symbol"))
  AX(("1 smaller area<br/>1 symbol"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0,A1,A2,A3,A4 reached;
  classDef tail fill:#EEF2F3,stroke:#9AA4A9,stroke-width:1px,color:#3A4247;
  class AX tail;
Loading
Can be affected Symbols Nearest hop Reached from
Graph Freshness Check 6 src/graph/check.ts:L58-L164 checkGraph — calls, depth 1 Graph Construction, Directory State Tracking
Pull Request Review 4 src/app/review.ts:L45-L99 reviewPullRequest — calls, depth 1 Graph Construction, Directory State Tracking
Engine Graph API 2 src/engine.ts:L91-L101 graph — calls, depth 1 Graph Construction, Directory State Tracking
Viewer Build Script 1 scripts/build-viewer.mjs:L1-L45 build-viewer.mjs — calls, depth 2 Graph Construction
MCP Tool Invocation 1 src/mcp/tools.ts:L216-L244 callTool — calls, depth 2 Graph Construction
Synchronous Execution 1 src/claude/sync-run.ts:L19-L33 runSync — calls, depth 2 Graph Construction
Who knows this code — 3 people across 10 areas
Area Who knows it
Graph Construction · changed @anirudhkumar-nanonets — 20 commits, last 10d ago · @shhdwi — 15 commits, last 22d ago
Directory State Tracking · changed @anirudhkumar-nanonets — 5 commits, last 29d ago
CLI Entry Point · changed @anirudhkumar-nanonets — 36 commits, last 2d ago · @shhdwi — 23 commits, last 22d ago
File Node Formatting · changed @shhdwi — 10 commits, last 1mo ago · @anirudhkumar-nanonets — 6 commits, last 2d ago
Graph Freshness Check · affected @anirudhkumar-nanonets — 16 commits, last 8d ago · @shhdwi — 8 commits, last 23d ago
Pull Request Review · affected @anirudhkumar-nanonets — 5 commits, last 3d ago
Engine Graph API · affected @anirudhkumar-nanonets — 16 commits, last 1mo ago
Viewer Build Script · affected @shhdwi — 2 commits, last 23d ago
…2 further areas

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

All 15 dependent symbols, grouped by area

Graph Freshness Check — 6 symbols in 5 files

  • src/graph/check.ts:L58-L164 — checkGraph (calls, depth 1)
    89: const sourceFiles = listSourceFiles(root, outDir, undefined, onlyDirs);
  • src/graph/refresh.ts:L150-L227 — ensureFreshGraph (calls, depth 1)
    216: await buildGraph(dir, { contextDir: opts.contextDir, graphOnly: true, onlyDirs });
  • src/graph/fingerprint.ts:L150-L196 — probeDrift (calls, depth 2)
  • src/graph/refresh.ts:L235-L261 — ensureFreshChildren (calls, depth 2)
  • src/graph/workspace-cli.ts:L49-L70 — buildChild (calls, depth 2)
  • src/graph/workspace.ts:L630-L655 — federateCheck (calls, depth 2)

Pull Request Review — 4 symbols in 4 files

  • src/app/review.ts:L45-L99 — reviewPullRequest (calls, depth 1)
    55: await buildGraph(checkout.dir);
  • src/app/review-process.ts:L179-L183 — childReviewer (references, depth 2)
  • src/app/review-worker.ts:L67-L87 — run (calls, depth 2)
  • src/app/server.ts:L31-L37 — AppSeams (references, depth 2)

Engine Graph API — 2 symbols in 1 file

  • src/engine.ts:L91-L101 — graph (calls, depth 1)
    92: return buildGraph(dir, {
  • src/engine.ts:L82-L84 — checkGraph (calls, depth 2)

Viewer Build Script — 1 symbol in 1 file

  • scripts/build-viewer.mjs:L1-L45 — build-viewer.mjs (calls, depth 2)
    3: * assets). Runs as part of `npm run build`; the bundle ships in the package

MCP Tool Invocation — 1 symbol in 1 file

  • src/mcp/tools.ts:L216-L244 — callTool (calls, depth 2)

Synchronous Execution — 1 symbol in 1 file

  • src/claude/sync-run.ts:L19-L33 — runSync (calls, depth 2)
Test signal per changed area — 1 ✓ · 2 ✗ · 1 –

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✓ Graph Construction — 2 of 5 reached · 1 test file changed here: test/generic-extract.test.ts
    • not reached: tagsExtract, resolveGodotRes, listSourceFiles
  • ✗ Directory State Tracking — 0 of 3 reached · no test file reaches it
    • not reached: onlyDirsPath, readOnlyDirs, writeOnlyDirs
  • – CLI Entry Point — no function, method or class changed here
  • ✗ File Node Formatting — 0 of 1 reached · no test file reaches it
    • not reached: nodeIdsInFile
35 test suites also reference this code

44 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.

  • test/ask-index.test.ts
  • test/ask.test.ts
  • test/container-extract.test.ts
  • test/context-only-dir.test.ts
  • test/context.test.ts
  • test/covers.test.ts
  • test/generic-node24-probe.ts
  • test/graph-cross-language.test.ts
  • test/graph-go.test.ts
  • test/graph-incremental.test.ts
  • test/graph-invariants.test.ts
  • test/graph-java.test.ts
  • test/graph-languages.test.ts
  • test/graph-php.test.ts
  • test/graph-posix-paths.test.ts
  • test/graph-python.test.ts
  • test/graph-r-classes.test.ts
  • test/graph-r-phase3.test.ts
  • test/graph-r-phase4.test.ts
  • test/graph-r-phase5.test.ts
  • …15 more

⚠️ 2 changed files not in the graph (README.md, src/graph/queries/gdscript.scm) — no parser claims the extension, or the index predates the file.

graft blast · origin/main...HEAD · depth 2 · 12 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

github-actions Bot added a commit that referenced this pull request Sep 4, 2026
@Frankie-Xu

Copy link
Copy Markdown
Contributor

[email protected] does ship gdscript (and glsl / gdshader). This PR is the right place for the .gd half of #293 — I will not open a parallel GDScript registry-row PR.

#293 also asks for .glsl. That grammar is in the same wasm bundle and is not in this diff. Happy to take that as a follow-up so this PR does not grow.

The Windows blast-radius path match and sticky --only-dir look independently useful; splitting them as you offered would make review easier, but not blocking on that from here.

@shhdwi

shhdwi commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks! GDScript itself works well: on a small .gd fixture we got both functions and the helper ← compute call edge, and the sticky --only-dir fix covers a real gap on main. But the new test incomingEdges matches a Windows path against posix node paths fails on macOS and Linux every time. toPosixPath does nothing when sep === "/", so the backslash path is never normalized there, and the suite fails on POSIX CI. Since this bundles three unrelated changes, could you reopen them as three focused PRs? They would be GDScript, the Windows blast-radius fix with separator-independent normalization (for example replace(/\\/g, "/")), and sticky --only-dir. We would review each quickly. Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants