Skip to content

feat(lang): Nix language support (outline, semantic indexing, ast-grep) - #1370

Open
kido5217 wants to merge 1 commit into
cortexkit:mainfrom
kido5217:feat/nix-language-support
Open

kido5217 wants to merge 1 commit into
cortexkit:mainfrom
kido5217:feat/nix-language-support

Conversation

@kido5217

@kido5217 kido5217 commented Nov 4, 2026 •

Copy link
Copy Markdown

Approved issue

Approved issue: #492 (design-approved)

What changed

Rebased onto current main (the crates/aft-parse / crates/aft-base split): all implementation now lives in those crates — the forwarding shims under crates/aft/src/ are untouched. Adds Nix as a supported language for:

  • Outline — the entry is the file's top-level attrset: a lambda body, a let … in body (its let bindings are listed at file level too), an attrset reached through with/assert/parentheses, or an attrset reached by applying a function to an attrset (each unwrap step is an iterative walk, not recursion — see Checks). Only an application's final argument is traversed; earlier arguments and list/if/// expressions contribute nothing. The same rule applies to nested values, so config = lib.mkIf cond { … } nests its children. The outline lists the entry bindings, then exactly one level of nested attrsets or lambda bodies returning attrsets. Bindings are named by their dotted attrpath (config.services.demo.enable); function bindings carry a one-line header as the signature; inherit clauses are skipped; two top-level bindings with identical full names are both kept without expanding their children.
  • Zoom — resolves the same dotted paths, including paths through an enclosing outlined binding.
  • AST search/replace — AstGrepLang::Nix on tree-sitter-nix 0.3.0. Patterns are written with $NAME, which the _ expando rewrites to _NAME because the grammar rejects $ and µ as identifier characters. ast-grep's own registry makes the same choice for Nix (crates/language/src/registry.rs). Complete Nix expressions match through the normal path; a standalone binding or inherit clause is not an expression, so compile_pattern falls back to a contextual pattern that selects the sole binding-set member's own kind (binding, inherit, inherit_from). This keeps sibling bindings intact on replace (a whole-attrset pattern would delete them), and a wrapper mixing members — two bindings, or a binding plus an inherit — is rejected with a hint naming the language: nix pattern must contain one binding or one inherit clause. Because _ is also a legal Nix identifier start, a key written _ plus an all-uppercase name (_FOO) is read as a metavariable; _Foo, __functor, and _module.args stay literal.
  • Semantic indexing — .nix is in the extension policy and the chunk census label map (34 => "Nix", behind Luau's 33).
  • Formatter — nixfmt is the only formatter Nix resolves, and only through an explicit formatter.nix key (no auto-detection; formatter.nix = "none" still disables formatting). nixfmt is accepted by the Rust config resolver, both plugin config schemas, and the generated JSON schema. Checker validation stays unsupported.
  • Agent surface — nix added to both harness plugin AST enums and the regenerated subc_tool_schemas.json + tool-provider catalog goldens (and the refreshed direct-registration digest fixture, following the precedent of 8204e6731).
  • Registry sweep — indent (two spaces), inspect labels, callgraph-store labels (including join::language_id, even though Nix has no call edges).
  • Docs — README language row and Nix caveat, the formatter.nix key in docs/config.md, the Config::formatter doc comment, and accepted-language lists plus error messages in the AST tools now naming every canonical language.

Unsupported for now (approved scope): imports, refactor, call graph. The call graph reports no Nix edges.

Dependency

tree-sitter-nix = "0.3.0" (nix-community, MIT, ~45 KB, ABI 13, external scanner.c), linked into aft-parse like TOML/JSON/YAML — no download manifest or wasm distribution involved. numtide has no crates.io release yet, so this is the published pin the issue approved; switch when a numtide crate publishes. 0.3.0 predates the |> pipe operator and bare inherit;, so a file using them parses with ERROR nodes and may outline partially. The workspace's tree-sitter 0.26.7 has a minimum compatible ABI of 13, so the grammar loads at the floor.

Checks

On the rebased head 6e7f59628 (rustc via the repo's Nix toolchain):

  • cargo test -p aft-parse nix_ — green: outline/signature/depth/inherit/applied-entry/nested-application/collision unit tests, ast-grep contextual patterns (bindings, inherit clauses, multi-binding rejection), and the four pattern-hint tests pinning the wording above.
  • deep_nesting_tests! Nix cases — nix_deeply_nested_parens_extracts_binding_on_a_small_stack and nix_deeply_nested_formal_default_extracts_binding_on_a_small_stack: 10,000-deep nesting on the harness's 2 MiB stack thread, asserting the extracted binding names (not just is_ok). RED first on the recursive code (stack overflow, coredump-confirmed), green after converting nix_collect_entry's entry-unwrap chain to an iterative walk and nix_comment_ranges to an explicit Vec worklist.
  • cargo test -p agent-file-tools --features test-hooks --test integration nix_test — 8 passed: the content-record test (nix_indexing_yields_a_content_record, replacing the retired views-plane payload test) pins outline symbols, TODO markers, and empty import/call edges; plus outline/zoom/language label, ast search/replace sibling preservation, unsupported import/refactor, empty call-graph annotations, validation skip, dotted provider symbols, and the semantic-extension policy test.
  • cargo test -p agent-file-tools --lib -- store_diet — green with the new smoke-nix corpus entry (fixture + manifest).
  • grammar_tests (frozen builtin list now names nix), created_file_syntax, language_label_covers_nix (census decode), nix_is_excluded_from_duplicate_scanning, format nixfmt integration — all green.
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --features agent-file-tools/test-hooks — clean. cargo check -p agent-file-tools --features "wasm-grammars test-hooks" --all-targets — clean (Nix appears in no wasm/download path).
  • ./scripts/rust-test-gate.sh on a NixOS dev host: the port introduces zero new test failures — the full nextest-phase failure set on this head is a strict subset of the same-host failure set on clean main at b0f2b509f (411 pre-existing host-environmental failures: FHS-path fixtures like the /bin/cat deploy helper, nested-userns sandbox checks, daemon-timing watchers; all Nix tests pass under an FHS overlay). On stock Linux CI these classes do not arise.
  • Regeneration ran, not hand-editing: assets/aft.schema.json (bun run schema), the five tool-schema goldens (bun run build:tool-schemas, drift-checked with --check), the catalog goldens (ignored regen test), and full_catalog_goldens_and_digest_only_have_exact_identity green.
  • Plugin bun test tool-surface suites green under the overlay; residual plugin failures reproduce identically on pristine main (host state: absent /usr/bin/id, subc-core sibling checkout, production storage present).

Corpus validation

Against a local NixOS configuration corpus (121 .nix files, 494,563 bytes, 13,929 lines), re-measured on the rebased head with the same committed harness used pre-rebase:

Measure Result
Files parsed with no ERROR/MISSING nodes 121 of 121
Files whose files-mode outline entry reports language nix 120 of 121 (files mode honours .gitignore)
Outline symbols 2,344 — identical to the pre-rebase baseline
Files with at least one nested symbol 114 of 120 — identical
Files with zero symbols 0 of 120 outlined files
Structural-search matches 335 — identical
Write with validate: "full" Succeeds; validate_skipped_reason = unsupported_language

Only aggregate counts and size are reported. Corpus paths, file names, and content stay on the machine it was found on.

Release binary size

target/release/aft, cargo build --release -p agent-file-tools, same toolchain both sides:

Build target/release/aft bytes
main at b0f2b509f 159,554,968
this head 6e7f59628 159,673,752
delta +118,784 (+0.07%)

(The previous table measured against the stale 7ca30b526 base; ~2,700 merged main commits moved the absolute number, which is why both sides are rebuilt here.)

Notes

  • Recovery: the pre-rebase head is tagged pr-1370-pre-rebase (1cd536049) if review wants the old commits.
  • An existing integration-test helper deploys the binary via /bin/cat, which is absent on NixOS hosts; local verification ran it under a mount-namespace overlay. CI on stock Linux is unaffected.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with two non-blocking pattern-search issues remaining from the previous review.

Findings

  1. P2 Valid searches get wrong advice ▶
  2. P2 Block comments break binding searches ▶

Summary

Adds Nix support for outline, zoom, AST search and replace, and semantic indexing.

  • Nix files show dotted bindings in outlines and zoom.
  • AST tools search and replace Nix expressions and bindings.
  • Semantic indexing turns Nix bindings into searchable chunks.
  • Nix formatting runs through nixfmt when explicitly configured.

Reviews (15) · Last reviewed commit: "feat(lang): add Nix language support" · Reviewed by Greptile

@socket-security

socket-security Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​tree-sitter-nix@​0.3.091100100100100

View full report

@kido5217
kido5217 force-pushed the feat/nix-language-support branch 2 times, most recently from a0d0b15 to b45491b Compare November 4, 2026 16:20
@kido5217 kido5217 changed the title feat(lang): Nix language support (outline, zoom, ast-grep) feat(lang): Nix language support (outline, semantic indexing, ast-grep) Nov 4, 2026
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 58f5d36 to 0210429 Compare November 4, 2026 20:50
@kido5217
kido5217 marked this pull request as ready for review November 4, 2026 21:29

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 43 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread crates/aft/src/parser.rs Resolved
Comment thread crates/aft/tests/fixtures/flake.nix Resolved
Comment thread crates/aft/src/ast_grep_lang.rs Resolved
Comment thread crates/aft/src/ast_grep_lang.rs Resolved
Comment thread crates/aft/src/commands/ast_search.rs Resolved
Comment thread docs/config.md Resolved
Comment thread README.md Resolved
Comment thread crates/aft-base/src/config_resolve.rs Resolved

@aft-alfonso aft-alfonso Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, @kido5217, and sorry for the long wait. It's a careful implementation, and the corpus numbers and size measurement in the description were really helpful.

Dependency review: done, and clean. The published tree-sitter-nix 0.3.0 crate matches the v0.3.0 tag (ea1d87f) file for file, apart from Cargo's normalised Cargo.toml. parser.c, node-types.json, grammar.json and parser.h regenerate byte for byte with tree-sitter CLI 0.20.9 (the version the upstream flake pins) at --abi 13. build.rs and scanner.c only compile the grammar.

Tests at your head: we ran the Nix unit and integration tests, config parity, the catalog golden test and the census label test on an offline build machine at 1cd5360, and all pass. Our release-binary delta matches yours: +119,072 bytes (+0.09%).

We'd like to merge it. main moved a lot since you opened this, so a few things are needed first:

  1. Rebase onto current main. Eight files now conflict. In most of them main added Luau to the same match arms where you add Nix, so keep both. crates/aft/src/views/lazy_read_benchmark.rs was deleted along with the old views storage, so drop your edit there rather than restoring the file. Regenerate both catalog goldens and subc_tool_schemas.json (bun run --cwd packages/opencode-plugin build:tool-schemas) instead of picking either side's hashes.

  2. Two auto-merge traps. grammar_for now returns Result<Language, AftError>, so the nix_symbols test helper needs to unwrap it. LangId::Luau now sits after TOML, so append Nix after Luau, and update the census label in semantic_chunk_census.rs to Nix's new slot.

  3. Stack-safe walks (now required). Since you opened this, every syntax-tree walk on the indexing path keeps its depth on the heap. A crafted deep file used to overflow a 2 MiB scan thread and take down the whole aft process. Two Nix helpers still recurse without a bound:

    • nix_collect_entry, once per wrapper (parentheses, let, with, assert, lambda bodies, applications);
    • nix_comment_ranges, through nested default expressions in function formals.

    Please turn both into loops or explicit worklists, keeping the current output. Then add Nix cases to deeply_nested_files_extract_on_a_small_stack in crates/aft/src/data_layer/content.rs: deep outer wrappers, and deeply nested defaults with comments in a function's formals. Have them assert the extracted names, so a run that silently drops Nix doesn't pass. nix_emit_binding is bounded by the one-level outline limit and can stay as it is.

  4. The new index store. Outlines and symbols are now stored as content records (crates/aft/src/data_layer/content.rs), and the old views test no longer covers the path that serves them. Please replace nix_views_callgraph_payload_accepts_nix_label with a test that a .nix file produces a record with language nix, the expected outline and TODO markers, and empty import and call facts. No extractor-version bump is needed for a new language, because record keys already include the language name.

Optional, not blocking: when a pattern holds several bindings, the error is the generic "Fails to parse the pattern query". A hint that Nix patterns may contain one binding or inherit clause would help agents recover.

We're fine with the _UPPER metavariable trade-off as documented. Pascal makes the same one, and Nix's identifier grammar leaves no better sentinel. On our side, the parser and semantic-index changes go through our search-quality check when we merge, and nothing is needed from you there.

@aft-alfonso

aft-alfonso Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Hi @kido5217, checking in on this one. Since our review, the parser code moved into its own crate (crates/aft-parse), so the branch needs a rebase, along with a fix for the two recursive helpers we flagged. Are you still planning to pick it up? If you'd rather not, we can finish it on top of your commits and keep you as their author. If we don't hear back by 27 November, we'll go ahead that way.

@kido5217

Copy link
Copy Markdown
Author

Thanks for the detailed review — I'm picking this up. Plan: rebase onto current main (keep both Luau and Nix arms, drop the lazy_read_benchmark.rs edit, regenerate the catalog goldens and subc_tool_schemas.json), fix the grammar_for Result and LangId/census-slot traps, make nix_collect_entry and nix_comment_ranges heap-bounded with the small-stack Nix cases, and replace the views test with a content-record test. I'll also add the non-blocking suggestion: a Nix-specific hint on the generic pattern-parse error when a wrapper holds several bindings. Expect an update on #1370 before 27 November.

@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 1cd5360 to 6289dc2 Compare November 22, 2026 17:50
Comment thread crates/aft-parse/src/ast_grep_lang.rs Resolved
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 6289dc2 to 3bdb54e Compare November 22, 2026 18:44
@kido5217

kido5217 commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Rebased and hardened — squashed to one commit on current main (6e7f59628). Your four items, each with where it landed:

  1. Rebase. The crate split (aft-parse / aft-base) meant the branch's edits mostly moved homes, so this is a port to the live implementations, not a conflict merge: zero edits to forwarding shims (verified mechanically — the diff touches no file that only re-exports). The deleted benchmark file's edit is gone. All generated files are regenerated at the new head: the five build:tool-schemas goldens, the tool-provider catalog fixtures, and assets/aft.schema.json via its generator. The pre-rebase state is preserved as tag pr-1370-pre-rebase.

  2. Auto-merge traps. Test helpers unwrap the new grammar_for Result; LangId::Nix is appended after Luau (discriminant 34); the census decode arm is 34 => "Nix" — the branch-era 33 => "Nix" was replaced (33 is Luau now), not appended.

  3. Stack safety. nix_collect_entry converted from recursion to a loop (single-chain unwrap), nix_comment_ranges to an explicit Vec worklist (it branches). Two deep_nesting_tests! cases — 10k nested parentheses and 10k nested formal defaults — run on the 2 MiB-stack harness; the harness extension asserts the extracted binding name from the small-stack record rather than only is_ok(). Both were confirmed RED (stack-overflow SIGABRT inside the respective walkers) on the recursive code before conversion, GREEN after.

  4. New index store. nix_views_callgraph_payload_accepts_nix_label is deleted; its replacement nix_indexing_yields_a_content_record indexes the real module fixture through the content-record path and asserts: language nix, a Parsed record whose outline carries the dotted-path symbols, TODO markers read from # comments (todos.language == "nix"), and empty import/call/reference facts. Verified green on the exact command, plus a mutation check (stub the Nix extractor → the record test fails).

Plus the optional item you allowed: the multi-binding contextual-pattern rejection now appends nix pattern must contain one binding or one inherit clause on the PatternError, so the composed "Fails to parse the pattern query" message names the language — four tests (two-binding carries hint, binding+inherit carries hint, valid single-binding succeeds without it, composed error names nix).

Gate evidence at the new head: cargo fmt --all -- --check and cargo clippy --workspace --all-targets --features agent-file-tools/test-hooks clean; on a NixOS dev host the full ./scripts/rust-test-gate.sh nextest phase introduces zero new failures — the failure set at this head is a strict subset of the same-host set on clean main at b0f2b509f (all 411 are host-environmental FHS/nested-namespace classes; every Nix test passes there, and none of those classes arises on stock Linux CI); cargo check --all -- --check, cargo clippy --workspace --all-targets --features agent-file-tools/test-hooks, cargo check -p agent-file-tools --features "wasm-grammars test-hooks" -p agent-file-tools --features "wasm-grammars test-hooks" --all-targets clean (Nix appears in no wasm/download path — it is a linked grammar). The 121-file corpus re-run on the ported build reproduces the baseline aggregates exactly (121/121 parsed, 2,344 outline symbols, 114-of-120 nested-symbol files, 335 structural matches, 0 zero-symbol files). PR body refreshed against the new base, including a re-measured release-size delta.

kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 3bdb54e to 7f76161 Compare November 22, 2026 19:15
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 7f76161 to acfbe5c Compare November 22, 2026 20:30
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from acfbe5c to b54c2fd Compare November 22, 2026 21:04
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from b54c2fd to 41541ca Compare November 22, 2026 21:47
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 41541ca to e4c1b94 Compare November 22, 2026 22:44
Comment thread crates/aft-parse/src/ast_grep_lang.rs Resolved
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 22, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from e4c1b94 to 25d1fd9 Compare November 22, 2026 23:40
Comment on lines +243 to +246
if let Some(&c) = bytes.get(j) {
if c.is_ascii_alphabetic() || c == b'_' || c == b'$' || c == b'"' || c == b'\''
{
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Valid searches get wrong advice

A valid pattern such as let a = 1; in a triggers this hint because the scanner treats in after the semicolon as another binding. When the search finds no matches, ast_search incorrectly says the expression cannot parse and should be split apart. Users or agents following that advice may abandon the intended search.

Check that the pattern is an attrset-body fragment before giving this advice.

kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 25d1fd9 to 98bde65 Compare November 23, 2026 00:00
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 98bde65 to 6f52429 Compare November 23, 2026 00:33
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 6f52429 to c35c651 Compare November 23, 2026 00:58
@greptile-apps

greptile-apps Bot commented Nov 23, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from c35c651 to 3c2d7c7 Compare November 23, 2026 01:41
kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 3c2d7c7 to 1915cd0 Compare November 23, 2026 02:10
Comment on lines +250 to +254
if b == b'#' {
while i < bytes.len() && bytes[i] != b'\n' {
i += 1;
}
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Block comments break binding searches

The comment scanner rejects valid binding patterns containing # inside a Nix block comment. For example, a = /* # note */ true; reaches the contextual fallback, which removes everything from # onward. This leaves an unfinished block comment, so nix_wrapper_selector rejects the pattern. Users must remove the comment before searching or replacing.

Preserve block comments while stripping line comments, or use parsed comment ranges instead.

kido5217 added a commit to kido5217/aft that referenced this pull request Nov 23, 2026
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from 1915cd0 to cd44e0a Compare November 23, 2026 02:21
Registers Nix as a linked tree-sitter grammar (tree-sitter-nix 0.3.0 via
aft-parse) with structural outline extraction: attrsets and dotted
attrpaths become one-level symbols, lambda RHS bindings become Function
symbols with one-line signatures, inherit and dynamic imports are
exempted, and `_` is the ast-grep expando (Nix identifiers reject `$`).

Maintainer review items (cortexkit#1370):

- Rebase: ported onto the crates/aft-parse / crates/aft-base split; all
  implementation edits live in their new homes, zero forwarding-shim
  edits. grammar_for now returns Result; LangId::Nix is discriminant 34
  after Luau and the census decode map carries 34 => "Nix".
- Heap-bound recursion: nix_collect_entry entry-unwrap chain converted to
  an iterative walk and nix_comment_ranges to an explicit Vec worklist;
  both covered by deep_nesting_tests! cases (10k nesting on a 2 MiB
  stack) that additionally assert the extracted binding names.
- Content-record test: replaces the retired views-plane payload test —
  nix_indexing_yields_a_content_record pins the outline symbols
  (dotted paths), TODO markers, and empty import/call edges for the
  Nix fixtures.
- Pattern-error hint: multi-binding Nix pattern queries now fail with
  `nix pattern must contain one binding or one inherit clause` via the
  PatternError composition; four tests pin the wording and behavior.

Also: nixfmt as an explicit-only formatter, docs/README/schema entries,
plugin language/format enums, store-diet smoke fixture, and regenerated
tool-schema goldens.

Approved issue: cortexkit#492
@kido5217
kido5217 force-pushed the feat/nix-language-support branch from cd44e0a to 6e7f596 Compare November 23, 2026 02:36
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.

1 participant