Skip to content

Add Svelte and Astro to the container tier - #430

Closed
zeppytoh wants to merge 1 commit into
trailhq:mainfrom
zeppytoh:container-tier-svelte-astro
Closed

zeppytoh wants to merge 1 commit into
trailhq:mainfrom
zeppytoh:container-tier-svelte-astro

Conversation

@zeppytoh

Copy link
Copy Markdown

What

Registers .svelte and .astro in CONTAINER_LANGS, alongside .vue.

{ name: "svelte", exts: [".svelte"], wasm: "svelte", block: "script_element", body: "raw_text",             inner: "typescript" },
{ name: "astro",  exts: [".astro"],  wasm: "astro",  block: "frontmatter",    body: "frontmatter_js_block", inner: "typescript" },

Both grammars already ship in the bundled tree-sitter-wasm, so this adds no dependency.

Why now

The registry comment asks for exactly one thing before these rows land:

Svelte and Astro are the same shape and would be a row each, but they are left out until someone has a repo to verify them against — a wrong body node type would produce silently misplaced spans.

This PR is that verification. I ran a patched build against a 155-component Astro site:

  • 86 of 86 extracted symbols landed on the correct line (checked exhaustively against the source, not sampled).
  • 58 edges from .astro components into src/lib now resolve — previously invisible.

That second number is the actual cost of the gap. graft callers <sym> on a module imported by components was silently under-reporting: it returned the .ts call sites and missed every component. On an Astro repo that is most of the callers, and the failure is quiet — you get a confident, incomplete answer right before a rename.

The span invariant

extractContainer uses const shift = body.startPosition.row, which is correct only when the body slice begins with the opening delimiter line's newline.

  • Svelte is Vue's shape exactly — script_element wrapping raw_text — so the same reasoning carries over unchanged.
  • Astro holds the same property for a different reason worth stating: frontmatter_js_block starts on the opening --- rather than after it, so its slice also begins with that newline and it shares the shift instead of needing a +1. Taking the outer frontmatter node as the body would look equivalent and move every symbol up one line.

One structural caveat I'd rather state than have you find: Astro frontmatter is always the first thing in the file, so startPosition.row is always 0 and no fixture can exercise a nonzero shift for it. The risk there is the delimiter off-by-one, so the Astro fixtures put symbols several lines into the block — either direction fails. Svelte does exercise a nonzero offset (markup above the script).

Scope

Astro's row indexes the --- frontmatter only, not <script> tags that may also appear in the template. The frontmatter is where imports, the Props interface and module-level code live, and it's the block whose edges make a component resolve into the rest of the graph. Client-side <script> blocks would be a follow-up, and ContainerLang takes a single block today.

Markup is still not indexed for any container language — unchanged from .vue.

Tests

Six new cases in test/container-extract.test.ts, mirroring the Vue ones: registry/-e claims, span fixtures for both formats, degradation to a file node when there's no usable block, the file node covering the whole component, an end-to-end build asserting a resolved .astro → .ts call edge, and a clean-build check (the #236 shape).

test/supported-extensions.test.ts used .svelte as its unsupported example and its header says that the day someone adds it, that file is where the substitution happens. Done — .hbs carries that side now.

Full suite: 1250 pass, 0 fail, 1 skipped.

Also

  • README gains a "Component formats" bullet — the container tier wasn't documented there at all, so .vue support was invisible to readers too.
  • CHANGELOG entry under Unreleased.

🤖 Generated with Claude Code

The registry comment asked for a repo to verify these against before
adding them; this is that verification. Both rows satisfy the invariant
extractContainer relies on — the body node starts on the row of the
block's opening delimiter, so its slice begins with that line's newline
and body.startPosition.row is the shift.

Svelte is Vue's shape exactly (script_element/raw_text). Astro holds the
same property for a different reason: frontmatter_js_block starts on the
opening --- rather than after it, so it shares the shift instead of
needing a +1. Astro's row indexes the --- frontmatter only, not the
<script> tags that may also appear in the template — the frontmatter is
where imports, the Props interface and module-level code live, and it is
the block whose edges make a component resolve into the graph.

Verified against a 155-component Astro site: all 86 extracted symbols
landed on the right line, and 58 edges from components into src/lib that
were previously invisible now resolve. That under-reporting was the real
cost — `graft callers <sym>` on a module imported by components silently
missed every component using it.

supported-extensions.test.ts used .svelte as its unsupported example and
said in its header that the day someone added it, that file is where the
substitution happens; .hbs carries that side now.

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

trailhq-graft Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🌱 graft blast radius

1 area changed → 5 areas can be affected. 12 dependent symbols, depth 2.
Tag: @anirudhkumar-nanonets — 5 of 6 areas · @shhdwi — 3 of 6 areas · @Frankie-Xu — Build Context

flowchart TB
  A0(("Dependency Graph<br/>6 symbols"))
  A1(("Build Review<br/>2 symbols"))
  A2(("CLI Engine<br/>2 symbols"))
  A3(("Build Context<br/>1 symbol"))
  A4(("MCP Tools<br/>1 symbol"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0,A1,A2,A3,A4 reached;
Loading
Can be affected Symbols Nearest hop Reached from
Dependency Graph 6 src/graph/build.ts:L1-L411 build.ts — imports, depth 1 Graph Container
Build Review 2 src/app/brain-build.ts:L1-L428 brain-build.ts — imports, depth 2 Graph Container
CLI Engine 2 src/cli.ts:L1-L1505 cli.ts — imports, depth 2 Graph Container
Build Context 1 src/context/build.ts:L1-L468 build.ts — imports, depth 2 Graph Container
MCP Tools 1 src/mcp/tools.ts:L1-L330 tools.ts — imports, depth 2 Graph Container
Who knows this code — 4 people across 6 areas
Area Who knows it
Graph Container · changed David Pruñonosa — 1 commit, last 1mo ago
Dependency Graph · affected @anirudhkumar-nanonets — 21 commits, last 24d ago · @shhdwi — 13 commits, last 1mo ago
Build Review · affected @anirudhkumar-nanonets — 9 commits, last 10d ago
CLI Engine · affected @anirudhkumar-nanonets — 44 commits, last 2d ago · @shhdwi — 24 commits, last 1mo ago
Build Context · affected @anirudhkumar-nanonets — 4 commits, last 1mo ago · @Frankie-Xu — 2 commits, last 20d ago
MCP Tools · affected @shhdwi — 14 commits, last 1mo ago · @anirudhkumar-nanonets — 7 commits, last 18d ago

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 12 dependent symbols, grouped by area

Dependency Graph — 6 symbols in 6 files

  • src/graph/build.ts:L1-L411 — build.ts (imports, depth 1)
    22: import { containerLangOf, extractContainer, warmContainerGrammars } from "./container.js";
  • src/graph/check.ts:L1-L221 — check.ts (imports, depth 1)
    25: import { containerLangOf, extractContainer, warmContainerGrammars } from "./container.js";
  • src/graph/source-files.ts:L1-L121 — source-files.ts (imports, depth 1)
    16: import { containerLangOf, containerExtensions } from "./container.js";
  • src/graph/fingerprint.ts:L1-L197 — fingerprint.ts (imports, depth 2)
  • src/graph/refresh.ts:L1-L274 — refresh.ts (imports, depth 2)
  • src/graph/workspace.ts:L1-L725 — workspace.ts (imports, depth 2)

Build Review — 2 symbols in 2 files

  • src/app/brain-build.ts:L1-L428 — brain-build.ts (imports, depth 2)
  • src/app/review.ts:L1-L174 — review.ts (imports, depth 2)

CLI Engine — 2 symbols in 2 files

  • src/cli.ts:L1-L1505 — cli.ts (imports, depth 2)
  • src/engine.ts:L1-L161 — engine.ts (imports, depth 2)

Build Context — 1 symbol in 1 file

  • src/context/build.ts:L1-L468 — build.ts (imports, depth 2)

MCP Tools — 1 symbol in 1 file

  • src/mcp/tools.ts:L1-L330 — tools.ts (imports, depth 2)
Test signal per changed area — 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 Container — 1 test file changed here: test/container-extract.test.ts
33 test suites also reference this code

33 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/context-only-dir.test.ts
  • test/context.test.ts
  • test/covers.test.ts
  • test/generic-extract.test.ts
  • test/graph-enrich-pending.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
  • test/graph-r.test.ts
  • …13 more

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

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

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

@shhdwi

shhdwi commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this! #444 adds the same Svelte/Astro container rows and additionally handles Astro <script> blocks, with tests, and it merges cleanly, while this branch now conflicts with main. Consolidating on #444, so closing this as a duplicate.

@shhdwi shhdwi closed this Sep 29, 2026
github-actions Bot added a commit that referenced this pull request Sep 29, 2026
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.

2 participants