Files
lucisv/docs/features/mcp-navigation/README.md
T
lucioandClaude Fable 5.1 82bbba04be MCP M2: definition, references, hierarchy, diagnostics, defines and the lucisv:// resources
Five navigation tools on the M1 transport (crates/lucisv_mcp/src/tools/{nav,select,hierarchy,diagnostics,defines,source}.rs, src/resources.rs): one selector for definition/references (file+line+col in 1-based bytes, file+line+name with the name chosen by token — never by text, so comments, strings and macro arguments cannot stand in — file+name refused when its uses resolve to different declarations, or a bare name with an optional unit); definition walks the server's ladder (include beside the file, macro, local table, workspace overlay computed per call) and lists every site with its byte-checked source line; references hands vlog_refactor::find_references the WHOLE indexed set — the plan's word-census narrowing was the lead's and QA proved it drops uses that resolve through a file never spelling the name (a two-level tail, a class-handle chain), so it is gone and MCP-7 asks vlog_refactor for a KnownFacts variant (≈2 s per call on opentitan's 3 944 files, recorded); hierarchy is the index's instantiation census down (default every top module) or up, depth 1..=20 in the schema, recursion and node caps, overrides sliced per statement; diagnostics is what `lucisv check .` reports — parse errors first, then lint under each file's lucisv.toml [lint] select/ignore/options/waivers through an index-backed MentionOracle, unused waivers in the whole-project form, the CLI's JSON field names; defines lists one file's, one macro's or the project's table. Resources: lucisv://overview, lucisv://rules, lucisv://unit/{name}, lucisv://file/{path}/outline. M1 QA finding 11 (a bare escaped name ending in @digits) fixed in read_item.

QA (Opus, two rounds): 43 qa_m2 tests; four wrong answers (the narrowing, a macro-argument occurrence answered as the macro, per-instance overrides in one statement, file+name guessing among declarations) and seven smaller findings fixed under the lead's rulings. opentitan census as an #[ignore] test (LUCISV_OPENTITAN): entropy_masking_req lists aes_bind.sv, state_q lists entropy_src_core.sv, top_earlgrey → u_aes : aes, parity with the LSP at every symbol — plus three real aes instantiations in the *_pd_main.sv tops the LSP omits (MCP-6, to file in TODO.md). Checkout untouched. Gates through tools/guard.sh: fmt, clippy, workspace 4 610 passed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-23 05:46:19 -07:00

767 lines
46 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# mcp-navigation
TODO-MCP.md **M2** — the navigation, diagnostics and resource half of
`lucisv-mcp`: tools `definition`, `references`, `hierarchy`, `diagnostics`,
`defines`, and the `lucisv://` resources. Design: `docs/mcp/PLAN.md` §4.2,
§4.3 and §4.5. The transport and `Project` they run on are
`docs/features/mcp-transport`; the rendering contract is
`docs/features/mcp-read-tools`'s.
## Goal
Let an agent ask the questions it otherwise answers by grepping and reading
whole files — where is this declared, who uses it, what instantiates what,
what does `lucisv check` say about this file, what does this macro expand
from — and get a compact, root-relative answer in one call. Every answer is
a composition of existing library queries (`vlog_semantic`'s index and
overlay, `vlog_refactor::find_references`, `vlog_linter`'s run); no language
knowledge lives in the MCP crate. The same answers the read tools give are
also addressable as `lucisv://` resources for a host that attaches context
instead of calling tools.
## Assumptions
- **One selector for `definition` and `references`** (`tools/select.rs`):
`file` + `line` + `col` (1-based, **byte** column — the crate's one column
unit; a column past the line's end is refused naming the line's length,
one past the last byte is the end and allowed); or `file` + `line` +
`name` — the first **token** on that line spelling `name` (an identifier,
or a macro use when written `` `NAME``), so a comment or a string never
stands in for the code; a name found only inside a macro call's argument
text is refused ("inside a macro argument, which lucisv does not resolve;
give `col` on a plain use"); or `file` + `name` — the name's one
declaration in that file; else, when the file declares none, its uses,
provided they all resolve to one declaration (uses naming different
declarations are refused listing a line per target, "`sig` on line 2 →
leaf.sv:1, line 6 → other.sv:1; add `line`"); else its first macro use; a
name declared twice in the file is refused listing the lines; or a bare
`name` with an optional `unit`, looked up in the index. `unit` with
`file` is refused (two selectors at once); `line`/`col` without `file` is
refused.
- **`definition` is the language server's ladder** (`nav.rs::at_position`):
an `` `include`` line → the named file **beside the including file only**
(no include-directory ladder: the MCP has no `+incdir` configuration to
honour, and a miss says so); a macro use → the file's own last
`` `define`` when it has one, else every indexed definition (the include
graph is not modelled, so none is picked); then the file's symbol table,
then the workspace overlay (`resolve_external` computed per call against
the current index — never cached, because the index moves under an
unchanged file). A local declaration answers its completing declaration
first (a non-ANSI port's body line), then its name, then every
redeclaration the binder folded into it (`Semantics::duplicates`, so
`output y; wire y;` lists the port *and* the net — the "both a port and
an internal net" case), one site per line. By name: the unit declarations,
the connection-surface members (`workspace_symbols` filtered to the exact
name), and the hierarchical-only members (`hierarchical_declarations`);
with `unit`, `member_in(unit, name, Surface::Hierarchical)`; `` `NAME``
(or a name nothing else declares) answers the macro definitions. The
by-name form reports what the index records — a redeclaration inside a
unit is visible only through the position form, which has the file's own
table. Ambiguity is always a list.
- **Every indexed span is re-checked against the bytes before it is
printed** (`tools/source.rs::checked_site`): the site is shown only when
the file still spells the name there, so a stale index omits a site,
never mislocates one (the `spells_exactly` rule of
`docs/features/references-hierarchical-surface`). One read per file per
call (`source::Texts`).
- **`references` hands the engine the whole indexed file set, always**
(lead's ruling on QA finding 1, replacing the M2 narrowing rule): every
indexed file plus the selected one, read from disk at call time
(`nav.rs::all_files`). A use resolves through files that never spell its
name — `u_a.u_b.sig` needs the file declaring `u_b`, `e.s.count` needs the
class declaring `s` — so no narrowing by the name's census is sound, and a
narrowed set also turned an unresolvable use into the false refusal
"declared outside the files lucisv indexes". **Measured cost** (release,
whole opentitan checkout, 3 944 files, after the index exists; each call
re-reads and re-parses the set): `entropy_masking_req` 1.62 s, `state_q`
from `entropy_src_main_sm.sv` 1.89–1.92 s, the `aes` instantiation in
`tb.sv` 1.70 s, `clk_i` from `prim_fifo_sync.sv` 2.55 s (83 hits); peak
RSS of the session ~0.98 GB. Handshake MCP-7 is the way down. The
engine's refusals are said as ours: prefixed "lucisv cannot follow this
position: ", and the rename wording they share with `rename` replaced
(`nav.rs::engine_refusal`). A macro use — by position or by a bare name
that only a `` `define`` declares — is refused with a pointer to
`defines` (the engine follows declarations, not macros).
- **`hierarchy` is the textual instance census** (`WorkspaceIndex::
instantiations()`, the edges the editor's hierarchy view and call
hierarchy read): `generate` and `` `ifdef`` branches all appear; an
instantiation at file scope (a `bind`) is not an edge, so a bound module
is a "top". Down: `instance : module #(overrides)`, a module instantiated
N times under one parent listed N times; a module the index does not hold
is marked `(not indexed)`; a module declared more than once is marked
`(declared N times)` and **not expanded** (which declaration an instance
means is the elaborator's choice); a module already on the path is marked
`(recursive)` and not expanded (a self-instantiating `generate` tree
terminates at once); `depth` defaults to 3 and the schema accepts 1..=20
(`Ty::Range`, so `inputSchema` carries `maximum: 20` and 21 is refused
naming `depth`); the walk stops at 50 000 nodes and says so. Up: `parent.instance #(overrides) file:line`
per instantiation of `root`, recursively. Without `root`, down starts at
every module nothing instantiates (a module that only instantiates itself
is therefore not a default root; name it).
- **Override slicing**: the text between the instantiated module's name at
the site (`InstantiationEdge::site_span`) and the statement's **first**
instance name (`edge.instances[0].name_span` — the `#(...)` belongs to the
whole statement), read from the file now, comments
dropped (`source::without_comments`, strings kept), whitespace collapsed,
kept only when it starts with `#` and the file still spells the module
name at the site. The text line caps it at 200 characters with `…`
(opentitan's `earlgrey_pd_main` instance carries hundreds of overrides);
`structuredContent.nodes[].overrides` carries all of it. `leaf #(.W(2))
u_a (), u_b ();` shows `#(.W(2))` on both instances.
- **Structured `hierarchy`** is a flat, pageable node list in tree order,
each `{depth, instance, module, parent, file, line, overrides, note}`
(`module` is always the instantiated module; `parent` is set in the `up`
direction) — a nested tree cannot be paged with `limit`/`offset`, and the
depth field reconstructs it.
- **`diagnostics` answers what `lucisv check .` — the whole-tree run, CI's
run — reports** (lead's ruling on QA finding 5): the cross-file rules
(`unknown-port`, `unused-signal`, …) always run, also when one `file` is
asked for, so one file's answer is that file's share of the whole-tree
run, not `lucisv check <file>` (which, holding one file, runs none of
them). The tool description says so. The config ladder is `lucisv
check`'s, per file:
`Discovery::for_file` finds the `lucisv.toml` governing it; its `[lint]
select` is the base set unless the `rules` argument is given (which
replaces it, like `--select`); `[lint] ignore` then removes; the run is
`select_rules(select, ignore, workspace = true)`; `[lint.<rule>]` options
go through `RuleOptions::set_raw` (a bad one is refused naming
`file:line`, as the CLI fails); `[lint] waivers` files are read with
`ExternalWaivers::read` and applied by `lint_with`; the line length and
tab width are `line-length`/`indent` else the formatter's defaults (100,
2). `severity` filters the findings afterwards. The workspace rules'
cross-file questions are answered by the project index (`Mentions`, the
server's `IndexMentions`): one file asks `mentioned_outside` directly; the
whole-project form builds a word → (file count, first file) census once
per call from `FileFacts::words`, because the per-question walk over
3 944 records would cost minutes. Parse errors come first as rule
`parse-error`, severity `error`, from the tolerant parse the file's
analysis already holds; the JSON array uses the CLI's field names
(`filename`, `rule`, `severity`, `message`, `location{line,column}`,
`end_location`, `range{start,end}`, `fix`) with `filename`
root-relative. **Missing-closer warnings are not offered**: they are the
language server's `pairs::missing_end_diagnostics`, not a library API,
and the tolerant tree's diagnostics alone do not carry them. The
whole-project form lints every indexed file (1.9 s on opentitan, 2 100
findings) and returns the first `limit` (default 200) with the total.
**Unused external waivers**: the whole-project form, being a complete
run, reports each `[lint] waivers` directive that suppressed nothing as an
`unused-waiver` finding against the waiver file (`ExternalWaivers::unused`
over the usage every file's `lint_with` returned, per config; the
severity the linter stamps, as the CLI does), when `unused-waiver` is
among the run's rules. The single-file form cannot know — a directive may
fire in a file it did not lint — and reports none.
- **`defines`**: `file` → that file's table as on disk (its `` `undef``s
included); `name` → every indexed definition of it (`find_define`); neither
→ every indexed `` `define``, paged. Each row `line `define NAME(params)
body`, the body one-lined and cut at 200 characters (UVM macro bodies run
to hundreds of lines). **One-step expansion with `args` is not offered**:
the server's `expand.rs` is ~260 production lines of argument splitting,
default parameters, string/escape handling and token pasting — not the
~60 lines the lane allowed, and a second copy of it is exactly the
duplication CLAUDE.md forbids. See Handshakes.
- **Resources** (`src/resources.rs`): `lucisv://overview` (`text/plain`,
`project_overview`'s text, walking first as the tool does) and
`lucisv://rules` (`text/markdown`, `vlog_linter::rules_markdown()`, no
index needed) in `resources/list`; `lucisv://unit/{name}` (`unit_interface`'s
text) and `lucisv://file/{path}/outline` (`outline`'s text, `path`
root-relative, `%XX` decoded) in `resources/templates/list`. A read runs
the read tool's own handler, so the two can never disagree. Any other
URI, and one naming nothing (an unknown unit, a path outside the roots),
is JSON-RPC `-32002` "resource not found: <uri> (<reason>)"; a missing
`uri` is `-32602`. `initialize` already declared `resources: {}`; no
`subscribe`/`listChanged` is offered.
- **A boolean argument type** (`tools::Ty::Bool`) was added to the registry
for `include_declaration`; it validates like the others (`true or false`
in the refusal).
- **`Analysis` now keeps the tokens and the `` `define`` table**
(`project/analysis.rs`): the lint context and the macro lookups need the
tokens the parse consumed, so they are cloned once before the parse.
## Handshakes
Consumed (public APIs only; no library crate was modified):
- `vlog_semantic`: `Semantics::{symbols_named, symbol, symbol_at,
reference_at, reference_id_at, references, duplicates, scope}`,
`resolve_external`, `ExternalResolutions::{definition_of, get}`,
`ExternalTarget::best`, `WorkspaceIndex::{units, member_in,
workspace_symbols, hierarchical_declarations, files_mentioning,
files_naming_in_macros, mentioned_outside, find_define, defines,
instantiations, instantiations_of, instantiable_units, members_of,
facts_for, file_id, files, path}`, `FileFacts::words`,
`PackageExports::exports`.
- `vlog_parser`: `defines::{collect_defines, DefineTable, Define,
DefineKind}`, `token::{Token, TokenKind}`, `LineIndex::{offset,
line_range, line_col}`.
- `vlog_refactor::find_references`.
- `vlog_linter`: `LintContext::{from_parse, with_semantics, with_options,
with_line_length, with_tab_width, with_oracle}`, `lint_with`,
`select_rules`, `RuleOptions::set_raw`, `ExternalWaivers::{read, absorb}`,
`MentionOracle`, `ModuleInterface`, `rules_markdown`.
- `lucisv_core::config::{Discovery::for_file, FileConfig}`;
`vlog_formatter::Config::default` (the line-length and indent defaults).
Requests (none blocking):
- **MCP-7 → `vlog_refactor`: a `find_references` variant taking `&dyn
KnownFacts`** (as `rename_traced_with` does), so a caller holding a
current `FileFacts` record per text — M6's cache, or the MCP's own index —
can skip re-parsing the whole set. Until then every `references` call
parses all 3 944 opentitan files (~1.6–2.6 s release): the price of a
correct answer (QA finding 1).
- **MCP-5 → `vlog_parser` (candidate): lift the server's `expand.rs`
(`single_step`, `has_macro_use`, `CAP`) into `vlog_parser::defines`** as a
pure move, so `defines` can offer the one-step expansion the plan lists
and hover keeps its own. Until then `defines` answers the table only.
- **MCP-6 → `lucisv_server` (informational, a candidate finding):** on
opentitan, `textDocument/references` at the `aes` instantiation and its
`.clk_i` connection in `hw/ip/aes/dv/tb/tb.sv` answers 11 and 9
locations; `references` here answers 14 and 12 — the same locations plus
the three top-level instantiations in
`hw/top_{earlgrey,darjeeling,englishbreakfast}/rtl/autogen/*_pd_main.sv`
(`aes #(` at 2069/1521/933 and their `.clk_i(clkmgr_clocks_i.clk_main_aes)`),
which are real (`hierarchy` `up` from `aes` lists `earlgrey_pd_main.u_aes`).
Stable after a 30 s settle, so not an indexing race. Not investigated in
this lane.
- **Resource wording**: `lucisv://unit/{name}` for a unit declared twice
answers `-32002` with `unit_interface`'s sentence, its "pass `file`"
replaced by "call the unit_interface tool with its file argument to pick
one" (`resources.rs`), since a URI has no `file` argument.
- **MCP-3 (PLAN §7) stays a candidate:** `hierarchy` walks
`instantiations()` keyed by the owner's `(FileId, name_span.start)`
exactly as `design_hierarchy::snapshot` does; they agree on the fixtures
and on `top_earlgrey`.
- Wanted but worked around: a `Semantics::symbol_id(&Symbol)` would save
`local_sites` a `symbol_at` lookup.
## Status / TODO
- [x] `definition`: position / line+name / file+name / bare name (+`unit`)
selector; `` `include`` line; macro use; local (detail, name,
redeclarations); cross-file overlay; by-name units, members,
hierarchical members, macros; lists, never guesses
- [x] `references`: `find_references` over the whole indexed set; grouped,
`line:col text`, `limit`/`offset`, `include_declaration`; one-
declaration rule for a bare name; macro refusal
- [x] `hierarchy`: down (default: every top) / up, `depth` (3, cap 20),
overrides, `(not indexed)`, `(declared N times)`, `(recursive)`,
node cap, flat structured list
- [x] `diagnostics`: parse errors + lint under the per-file `lucisv.toml`,
`rules`, `severity`, waivers, index oracle, census for the workspace
form, CLI JSON names, `limit`/`offset`
- [x] `defines`: file / name / project table, body capped; expansion not
offered (MCP-5)
- [x] resources: list, templates, read, `-32002`
- [x] QA rework: findings 1–11 fixed or ruled, `qa_m2.rs` 32/32 green
- [x] carry-over: M1 QA finding 11 (`read_item` `\a@12`) fixed; the QA test
un-ignored
- [x] wire tests over the new `tests/fixtures/nav` tree; the opentitan
census (`tests/opentitan.rs`, `#[ignore]`)
- [x] gates through `tools/guard.sh`; sizes
## Work log
**2026-09-23 (dev, M2).**
Built: `src/tools/nav.rs` (selector, `definition`, `references`),
`src/tools/hierarchy.rs`, `src/tools/diagnostics.rs`, `src/tools/defines.rs`,
`src/tools/source.rs` (per-call file texts, checked sites, the word finder,
comment stripping and capping shared by the four), `src/resources.rs`;
`tools/mod.rs` registers the five tools and gains `Ty::Bool`/`Args::flag`;
`rpc.rs` answers the three `resources/*` methods from `resources.rs`;
`project/analysis.rs` keeps tokens and defines and computes the overlay on
request (`Analysis::external`), with `token_at` and `line_text`.
Decisions and deviations from PLAN/TODO:
1. **A new fixture tree `tests/fixtures/nav`** instead of extending
`tests/fixtures/design`: M1's wire and QA tests pin that tree's file
count, unit counts, top modules and paging (`… and 6 more`), and a
lucisv.toml with `[lint]` there would change them. The new tree has every
case the brief listed: a `bind` connecting a bare net (`core_bind.sv`), a
`u_core0.state_q` tail (`top.sv`), a port that is also a net
(`dual.sv`), a class member used through a handle in another file
(`tb/sb.sv`, `tb/env.sv`), macros defined in an included `.svh` and used
in two files, `core` instantiated twice under `top` with different
`#(...)`, a self-instantiating `generate` tree (`tree.sv`), a five-deep
chain ending in a missing module (`chain.sv`), and a `lucisv.toml` with
`[lint] select`, `[lint.line-length] length = 40` and a waiver file.
2. **Two files beyond the brief's list**: `src/tools/defines.rs` (PLAN put
`defines` in `read.rs`, M1's file) and `src/tools/source.rs` (helpers
the four tools share; without it `hierarchy.rs` and `defines.rs` would
import from `nav.rs`). `src/main.rs` gained the one line `mod
resources;` — unavoidable for a new top-level module.
3. **Two edits to existing tests, both forced by the lane**: `wire.rs`'s
`tools_list_describes_every_tool_for_the_agent` lists the eleven tools;
`qa_m1.rs`'s `qa_everything_but_initialize_and_ping_waits_for_the_handshake`
asserted `tools/list` has 6 entries, now 11 (with a comment). Neither
weakens an assertion.
4. **The selector grew `file` + `line` + `name` and `file` + `name`**
beyond the plan's `file,line,col | name,unit?` — agents rarely know byte
columns. `col` stays exact.
5. **`references` refuses a macro use** (the engine would say "no symbol to
rename", which reads wrong in a references answer) and points at
`defines`.
6. **`hierarchy` takes `limit`/`offset`** and a 50 000-node cap (PLAN §4.5:
every list is capped) and does not expand a module declared more than
once (opentitan's technology variants: `pinmux_jtag_breakout` ×4).
7. **Missing-closer warnings and one-step expansion are not offered**
(Assumptions; MCP-5).
8. **Carry-over, M1 QA finding 11** (`tools/read_item.rs::select`): when
the `@LINE` reading matches nothing and the name starts with `\`, the
whole spelling (after an optional `kind:`) is tried as the name; the
first refusal stands if that fails too. Unit test
`an_escaped_name_ending_in_at_digits_is_its_own_name_when_no_line_matches`;
`qa_rework_an_escaped_name_ending_in_at_digits_is_selectable_by_itself`
un-ignored and green.
The opentitan census (`tests/opentitan.rs`, one session over the whole
checkout, read-only). Wall time per call, debug build (the test) / release
build (the same calls through a stdio driver):
| call | debug | release |
|---|---|---|
| first call (index build, 3 944 files) | 10.1–10.4 s | 1.9 s |
| `references` `entropy_masking_req` from `aes.sv` | 62 ms | 18 ms |
| `references` `state_q` from `entropy_src_main_sm.sv:42` | 928 ms | 165 ms |
| `references` `aes` at `tb.sv:45` | 266 ms | ~50 ms |
| `references` `.clk_i` at `tb.sv:46` | 10.0 s | 1.6 s |
| `references` `clk_i` from `prim_fifo_sync.sv` | 9.9 s | 1.6 s |
| `hierarchy` down `top_earlgrey` depth 2 | 22–384 ms | 10 ms |
| `hierarchy` up `prim_fifo_sync` depth 1 (77 instances) | 21 ms | 7 ms |
| `definition` `prim_fifo_sync` | 21 ms | 8 ms |
| `diagnostics` `hw/ip/aes/rtl/aes.sv` | 8 ms | 7 ms |
| `diagnostics` whole project (2 102 findings) | — | 1.9 s |
Parity with the language server (release `lucisv-server` rebuilt at this
commit, same checkout, `textDocument/references`/`definition` at the same
positions): `entropy_masking_req` 6 = 6 locations (`aes_bind.sv:45,54`
included); `state_q` 5 = 5 (`entropy_src_core.sv:3092` included); `aes` 14
⊇ 11 and `.clk_i` 12 ⊇ 9 (MCP-6); every `definition` equal. `hierarchy`
down from `top_earlgrey` depth 2 lists `earlgrey_pd_main :
earlgrey_pd_main` and under it `u_aes : aes #(...)`. `diagnostics` on
`aes.sv` finds nothing, as `lucisv check` does; `uartdpi.sv`'s three
`wire-reg-mixup` findings match the CLI's. `git -C opentitan status
--porcelain` was byte-identical before and after (the owner's three
modified files, untouched).
Tests: unit 28 → 37 (source 3, defines 2, resources 1, analysis 1,
read_item 1, tools/mod 1 extended; hierarchy 1); `wire.rs` 11 → 19;
`qa_m1.rs` 50 + 1 ignored → 51 + 0; `opentitan.rs` 1 (ignored).
Sizes (production lines: non-blank, non-comment, before `#[cfg(test)]`):
`tools/nav.rs` 446, `tools/hierarchy.rs` 311, `tools/diagnostics.rs` 293,
`tools/defines.rs` 158, `tools/source.rs` 134, `resources.rs` 112,
`tools/mod.rs` 146, `rpc.rs` 241, `project/analysis.rs` 77,
`tools/read_item.rs` 213, `main.rs` 68. No function over 50 lines.
Gates (all through `tools/guard.sh`, one cargo invocation at a time):
`cargo fmt -p lucisv_mcp -- --check` exit 0; `cargo clippy -p lucisv_mcp
--all-targets` `Finished`, no warnings; `cargo test -p lucisv_mcp` unit 37
passed, `opentitan` 0 passed / 1 ignored, `qa_m1` 51 passed, `wire` 19
passed; `cargo test --workspace` exit 0 in 238 s, **4 566 passed, 0 failed,
47 ignored** (4 548 before). The ignored census, run by hand as above:
1 passed in 32 s.
**2026-09-23 (dev, M2 rework after QA).** The lead's rulings on the QA
findings, as applied; every `qa_m2.rs` test is un-ignored and green (32).
- **1 (blocking) — ruled: the whole set.** `tools/nav.rs::all_files`
replaces `in_scope`; `leaves_file` and `spelled_at` are gone (nothing else
used them). The false "declared outside the files lucisv indexes"
refusal went with the narrowing. Wire test
`references_reach_bind_connections_hierarchical_tails_and_class_members`
now also asks from the use sites (`top.sv:8` tail, `env.sv:4` handle
chain) and asserts the declaration's answer. Handshake MCP-7 filed;
opentitan timings below.
- **2 + 3 (blocking) — fixed.** The selector moved to a new
`tools/select.rs` (nav.rs had reached 446 lines); `select.rs::on_line`
picks by token and refuses a name found only in a macro argument.
- **4 (blocking) — fixed.** `hierarchy.rs`: `Child::first` (the statement's
first instance name) ends the override slice; `Child::of` builds both
directions' children. Unit test extended with `#(.W(2)) u_a (), u_b ()`.
- **5 — ruled: whole-tree semantics kept.** Tool description and
Assumptions say so; no code change. `qa_finding_5_…` was written to
assert single-file parity "delete it if the project-wide semantics is
kept": I rewrote it (renamed
`qa_finding_5_one_files_diagnostics_match_lucisv_check_of_the_whole_tree`)
to assert the ruling — `unknown-port` reported for `top.sv` alone —
rather than delete it, so the ruling stays pinned.
- **6 — fixed.** `diagnostics.rs`: `Run::used` (a `RefCell<WaiverUse>`)
merges every file's usage; `Runs::unused_waivers` reports after the
whole-project loop; `lint_finding` takes a `LineIndex` so a waiver file's
findings render like any other. `Runs::held` became a `BTreeMap` so the
order is stable.
- **7 — fixed.** `tools/mod.rs`: `Ty::Range { min, max }` (schema
`minimum`/`maximum`, refusal "an integer from 1 to 20"); `hierarchy`'s
`depth` uses it and the silent `.min(MAX_DEPTH)` is gone. `wire.rs`'s
depth-99 call became 20 plus a 21-is-refused assertion; `tools/mod.rs`
unit test pins the schema.
- **8 — fixed.** `select.rs::at_column` refuses "line N is L bytes long;
`col` C is past its end".
- **9 — fixed.** `nav.rs::engine_refusal` prefixes and rewords the
engine's six rename-worded sentences (`vlog_refactor` untouched); unit
test `engine_refusals_are_prefixed_and_never_speak_of_renaming`. A bare
macro-only `name` is now refused as a macro too (QA's side note).
- **10 — fixed.** `resources.rs` rewrites the "pass `file`" clause.
QA's test asserts the message does not contain `` `file` `` (backticked),
so the wording is "with its file argument" rather than the lead's
backticked `` `file` `` — same meaning, test and ruling both honoured.
- **11 (blocking) — fixed.** `select.rs::one_use` resolves every use of the
name in a file that declares none (`Analysis::external` +
`definition_of`); two or more distinct targets are refused listing a
line per target.
Whole-set `references` on opentitan (release, stdio driver, after the
index): `entropy_masking_req` 1.62 s, `state_q` 1.92 s / 1.89 s, `aes` at
`tb.sv:45` 1.70 s, `clk_i` from `prim_fifo_sync.sv` 2.55 s; debug (the
census test): 9.8 s, 12.1 s, 10.9 s, 14.2–14.6 s. Answers unchanged from
the narrowed ones on every census symbol (6, 5, 14, 12 hits; the census
test's assertions still pass). The census test: 1 passed in 72 s; `git
status --porcelain` of the checkout byte-identical before and after.
Sizes after the rework (same awk rule): `tools/nav.rs` 343,
`tools/select.rs` 177 (new), `tools/hierarchy.rs` 316,
`tools/diagnostics.rs` 313, `tools/mod.rs` 151, `resources.rs` 118; the
rest unchanged. No function over 45 lines.
Gates (through `tools/guard.sh`, one cargo invocation at a time):
`cargo fmt -p lucisv_mcp -- --check` exit 0; `cargo clippy -p lucisv_mcp
--all-targets` `Finished`, no warnings; `cargo test -p lucisv_mcp` unit 38
passed, `opentitan` 1 ignored, `qa_m1` 51 passed, `qa_m2` 32 passed,
`wire` 19 passed; `cargo test --workspace` exit 0 in 254 s, **4 599
passed, 0 failed, 47 ignored**.
## QA log
**2026-09-23 (QA, M2). Verdict: rework needed** — four blocking findings
(1, 2, 4, 11: wrong or partial answers), seven non-blocking. No crash, no
hang, no write: every attack was answered, the server kept answering after
each refusal, and opentitan's `git status --porcelain` was byte-identical
before and after the whole session (the owner's three modified files).
Method: every attack against the real binary over scratch trees
(`crates/lucisv_mcp/tests/qa_m2.rs`, 32 tests: 20 green, 12
`#[ignore = "QA finding N"]` asserting the correct behaviour, each confirmed
failing for the stated reason with `--ignored`). Where "the right answer"
was in question, the oracle was `vlog_refactor::find_references` over the
*whole* file set (a throwaway binary in the QA scratch directory, not in the
tree) and `target/release/lucisv check` for diagnostics.
### Findings
**Blocking**
1. **`references` omits uses reached through a resolution-only file, and
refuses from the use with a false sentence** (`tools/nav.rs:444-464`,
`in_scope`). (a) `top2.sv: wire w2 = u_a.u_b.sig2;` where `mid.sv`
(`leaf u_b`) never writes `sig2`: `references {name: sig2, unit: leaf}`
answers only `leaf.sv:2:9`; the whole-set engine also lists
`top2.sv:4:21` (and drops it when `mid.sv` is removed from its set — the
narrowing is the cause). (b) The class case the brief lists: `e.s.count`
in `t.sv`, with `env.sv` (`sb s;`) never writing `count` — same omission.
From the use (`{file: t.sv, line: 4, name: count}`) `references` is
refused: "`count` is declared outside the files lucisv indexes, so a
rename here would only be half a rename" — the declaration *is* indexed
(`definition` finds it). The README's known limit names only a struct
typedef; multi-level hierarchical tails and UVM handle chains
(`cfg.agent_cfg.x`) are the common case. Tests
`qa_finding_1_a_two_level_tail_to_an_internal_net_is_a_reference`,
`qa_finding_1_a_class_handle_chain_through_a_third_file_is_a_reference`.
Suggested fix (for the lead to rule, it touches the narrowing ruling):
add the files that resolve the path — for a member of a unit, the
up-closure of the unit's instantiating files (`instantiations_of(owner)`
→ `edge.file`, recursively over `edge.owner.name`); for a class member,
the files declaring the types/classes the selected files name, to a
fixed point — or fall back to the whole indexed set for names off the
connection surface. At minimum an engine refusal on a narrowed set must
not be reported as "declared outside the files lucisv indexes".
2. **`file` + `line` + `name` inside a macro call's argument answers the
macro's `define`** (`tools/nav.rs:142-149` via `source::word_in`, then
`at_position:233-239`). `top.sv:5` is ``assign peek = `ID(u_core0.state_q);``;
`definition {file: top.sv, line: 5, name: state_q}` answers
`defs.svh:1:9 define: `define ID(x) x` — a declaration of a different
name. Test `qa_finding_2_…`. Fix: pick the occurrence by token — the
first identifier token on the line spelling `name` (a macro token only
when `name` is `` `NAME``); when the word is only inside a macro token,
refuse naming the macro. The same change fixes finding 3.
4. **`hierarchy` overrides of the 2nd+ instance of one statement include
the earlier instances** (`tools/hierarchy.rs:359-367`). `leaf #(.W(2))
u_a (), u_b ();` → `u_b : leaf #(.W(2)) u_a (),` (down, and `ov.u_b
#(.W(2)) u_a (), ov.sv:4` up; the JSON `overrides` likewise). The
README's "`sub u1 (), u2 ();` shows the one `#(...)` on both instances"
holds only when there are no overrides. Test `qa_finding_4_…`. Fix: end
the slice at the edge's *first* instance name (carry it in `Child`), or
take the balanced `#( … )` after the module name.
11. **`file` + `name` guesses when the file's uses resolve to different
declarations** (`tools/nav.rs:178-181`, `first_occurrence`). `top3.sv`
declares no `sig`; `u.sig` names `leaf`'s and `v.sig` names `other`'s.
`definition {file: top3.sv, name: sig}` answers `leaf.sv:1:27` alone
and `references` lists only `leaf`'s — a pick, where the brief and the
tool description say "ambiguity is a list, never a guess". Test
`qa_finding_11_…`. Fix: when the file declares nothing, resolve every
use of `name`; more than one distinct target → refuse listing the lines
(as the declared-twice rule does).
**Non-blocking**
3. `file` + `line` + `name` takes the first *textual* occurrence, so one in
a comment or string hides the code one: `/* q */ assign q = a;` →
"nothing at m.sv:2:6 names a declaration" (also `"a" == a`). Same place
and fix as 2. Test `qa_finding_3_…`.
5. **One file's `diagnostics` ≠ `lucisv check <file>`** — the brief's
parity criterion. `diagnostics.rs:149` always passes `workspace = true`
to `select_rules`, so the workspace rules (`unknown-port`,
`unused-signal`, `undeclared-identifier`, …) run for one file, where the
CLI runs them only when its run holds more than one file. Differences on
opentitan: `hw/ip/aes/dv/sva/aes_idle_check.sv` 17:28 unused-signal,
`hw/ip/aes/pre_dv/aes_sbox_tb/rtl/aes_sbox_tb.sv` 118:6 unknown-port,
`hw/ip/i3c/rtl/i3c_dat.sv` 134:17 unused-signal,
`hw/ip/kmac/rtl/sha3pad.sv` 776:37 unused-signal,
`hw/ip/entropy_src/pre_dv/entropy_src_tb.sv` 339:9 and 340:9
unknown-port — each one exactly what `lucisv check .` reports for that
file. Arguably the better answer (the project exists); it needs a lead
ruling and a sentence in the tool description and README either way.
Test `qa_finding_5_…` (asserts CLI single-file parity; delete it if the
project-wide semantics is kept).
6. **Unused external waivers are not reported** (`diagnostics.rs:215`
discards `lint_with`'s used-waiver answer). A `[lint] waivers` directive
matching nothing: `lucisv check .` (and `check m.sv`) report
`w.waiver:1:1 unused-waiver`; `diagnostics` says "no findings". Test
`qa_finding_6_…`.
7. `hierarchy` `depth` above 20 is silently the same as 20: the schema has
no `maximum` (`Ty::Int` has only `min`), and a node cut by the depth
limit looks like a leaf. `hierarchy.rs:50-55,120`. Test `qa_finding_7_…`.
The brief's "depth 21 → schema refusal" is not what happens; 0 and
negative are refused.
8. A `col` past the end of its line is clamped to the line end
(`LineIndex::offset`), and the refusal names the clamped column
(`col: 99` → "nothing at clamp.sv:2:15 …"). `nav.rs:135-141`. No wrong
answer found (the clamped offset sits after the last token), but the
agent is told about a position it did not ask for. Test `qa_finding_8_…`.
9. `references` refusals pass the rename engine's sentences through: "there
is no symbol to rename at this position" (whitespace, a keyword, a
comment) and "… a rename here would only be half a rename".
`nav.rs:394`. Test `qa_finding_9_…`. Also a by-name `references
{name: ONLY_MAC}` says "no declaration … is indexed" where the position
form says "is a macro … (`defines` lists …)".
10. `lucisv://unit/{name}` for an ambiguous unit is `-32002` (correct) but
the reason says "pass `file` to pick one", which a URI cannot.
`resources.rs:94` (the text is `unit_interface`'s). Test
`qa_finding_10_…`.
### Verified (green `qa_*` tests)
- Selectors: a package member through `import p::*` and through `p::PW`
(definition + 4 references from either end); a `bind` connection's bare
name (`bind core chk u_chk (.s(state_q))` → `core.sv:2:9`, 4 uses from
the bind side and the declaration side); one- and two-level tails to a
*port* (`u_a.u_b.sig` → `leaf.sv:1:44`, listed in references); the
port-that-is-a-net lists header, body and `wire` (never picks), references
4; a class member declared in two classes lists both, `references`
refuses naming both, `unit` picks; a name declared twice in one file is
refused with its lines; an escaped identifier by name and by position;
a macro-only name by name, `` `NAME`` and position, `references` refuses
it with the pointer to `defines`; whitespace, a keyword, a comment:
clean refusals; `line: 0` a schema refusal; past EOF and `5 000 000 000`
refused; a column inside the two bytes of `é` refused (no panic, server
alive); byte columns after a multibyte comment (`zz` at 29, not 27) and
in a CRLF file; `unit` that does not exist refused naming it.
- `references`: a comment and a string in a third file never reported;
paging `limit`/`offset` with `total` constant and an offset past the end
empty; `include_declaration: false` (also cross-file, from the use).
- `hierarchy`: a `generate`-self-instantiation and mutual recursion
terminate (`(recursive)`, both directions); a 30-deep chain stops at 20;
`depth` 0, -1, 2.5, "3" and `direction` `Up`/`sideways`/`""` refused by
the schema; a package, a class and an unknown name as `root` refused; a
module declared twice marked `(declared 2 times)` and not expanded; `up`
from a leaf with two parents lists both; overrides with a `/* … ) … */`
comment, a `// … )` comment, `c#(4)::N` and a string holding `u_x (` are
sliced right; 250 × 250 instances stop at 50 000 nodes with `cut: true`.
- `diagnostics`: `[lint] select`, `ignore`, `[lint.line-length] length`
and a waiver file honoured under the root config, and a file under
`b/lucisv.toml` gets that config's own select and top-level
`line-length = 60`; `rules` replaces select while the config's `ignore`
still applies (as the CLI's `pick`); `severity` filters; parse errors
first, then lint, in a file with both; the project form's pages
concatenate to the whole list with a constant `total`; a bad option
(`length = 30`) refused naming `lucisv.toml:5`; an unknown rule refused.
Every expected string was checked against `lucisv check` on the same tree.
- `defines`: a macro defined in two files lists both (and `definition` at
a use lists both, never picks); a parameterised multi-line body
one-lined; an unknown name "no defines"; `file` + `name` filters that
file's table (with its `` `undef``); a missing file refused.
- Resources: `resources/templates/list` entries carry `uriTemplate`, `name`,
`mimeType` (and `title`, `description`); `%20`, `%C3%BC` and `%25` decode;
an ambiguous unit, a bad escape (`%`, `%FF`), `..%2F..`, an absolute path
outside the root, a directory, a symlink leading out, `LUCISV://`, a query
string: all `-32002`, never a crash; a non-string `uri` `-32602`.
- Freshness: an edit shows in the next `references` and `hierarchy`; a
deleted declaring file makes the root refused and its instance
`(not indexed)`; a new file is seen after a miss-walk (M1's 5 s rule
otherwise).
### CLI-vs-MCP diagnostics (opentitan, release builds, no lucisv.toml)
- Single files, (rule, line, col) sets: `hw/ip/aes/rtl/aes.sv` 0 = 0,
`aes_core.sv`, `aes_cipher_core.sv`, `uart_core.sv`, `prim_fifo_sync.sv`,
`aes_env_pkg.sv`, `tb.sv` 0 = 0; `aes_scoreboard.sv` 4 = 4,
`uartdpi.sv` 4 = 4, `aes_env_cfg.sv`, `dv_utils_pkg.sv`,
`aes_base_vseq.sv` 1 = 1 — identical. The five files of finding 5 differ.
- Whole project: MCP `diagnostics` 2 102 in 1.77 s vs `lucisv check .`
1 158 in 0.92 s. Lint findings identical except the symlink
`hw/ip/tlul/rtl/tlul_adapter_shim.sv → tlul_adapter_vh.sv` (the MCP
lints the canonical path, M1's ruling, so the CLI's `module-filename` on
the shim name has no MCP twin). The other 941 are `parse-error`, which
`lucisv check` does not report at all (by the plan).
### opentitan (release, 3 944 files)
Index 1.8 s; `references clk_i` from `prim_fifo_sync.sv` 1.60 s (83 hits)
and from `tb.sv` (first occurrence = `key_sideload_if`'s port, 5 hits)
1.58 s — the huge-census case is bounded as the README says. The generate-
scope path `aes_bind.sv:58 …gen_masks.u_aes_prng_masking.u_prim_bivium.
state_q` is not among `prim_trivium`'s `state_q` references, but the
whole-set engine over 472 aes/prim/tlul files does not list it either: an
engine limit, not the narrowing. The dev's census test: 1 passed in
32.7 s (debug).
### Sizes and style
Production lines (non-blank, not starting with `//`, before the first
`#[cfg(test)]`, one awk rule for all): `tools/nav.rs` 446,
`tools/hierarchy.rs` 311, `tools/diagnostics.rs` 293, `tools/defines.rs`
158, `tools/source.rs` 134, `resources.rs` 112, `tools/mod.rs` 146,
`rpc.rs` 241, `project/analysis.rs` 77, `tools/read_item.rs` 213,
`main.rs` 68 — the dev's numbers, all under 600. No function over 40 lines
(brace-matched scan). No `unwrap`/`expect`/`panic!` outside `#[cfg(test)]`,
no `#[allow]`, no `unsafe`.
### Gates (through `tools/guard.sh`, one cargo invocation at a time)
- `cargo fmt -p lucisv_mcp -- --check` → exit 0
- `cargo clippy -p lucisv_mcp --all-targets` → `Finished`, no warnings
- `cargo test -p lucisv_mcp` → unit 37 passed; `opentitan` 0 passed, 1
ignored; `qa_m1` 51 passed; `qa_m2` 20 passed, 12 ignored; `wire` 19
passed
- `cargo test --workspace` (before finding 11's ignored test was added) →
exit 0, **4 586 passed, 0 failed, 58 ignored** (4 566 + 20 QA; 47 + 11)
- `LUCISV_OPENTITAN=… cargo test -p lucisv_mcp --test opentitan --
--ignored` → 1 passed in 32.7 s; checkout status byte-identical
- No guard kill.
TODO-MCP M2 QA box left unticked (rework needed).
**2026-09-23 (QA, M2 re-check after the rework). Verdict: pass.** All
eleven findings are fixed or pinned under the lead's rulings; no new
finding. Every earlier `qa_finding_*` test is un-ignored and green with
its assertion unchanged, except finding 5's, which the dev rewrote to pin
the ruling. It now asserts that one file's `diagnostics` reports
`unknown-port` for `top.sv`, as `lucisv check .` does and `lucisv check
top.sv` does not. That is exactly the ruling. QA added
`qa_recheck_one_files_diagnostics_are_its_lines_of_lucisv_check_dot`, which
pins the whole text line (`2:12 error … [unknown-port]`, and nothing for
`leaf.sv`) rather than a substring. Finding 10's new wording, "call the
unit_interface tool with its file argument to pick one", is acceptable: it
names the tool that can pick, and it no longer suggests that the URI takes
an argument.
Re-derived by hand (release binary, scratch trees, then pinned):
- **1**: the two-level tail `u_a.u_b.sig2` gives the same 3 locations
(`leaf.sv:2:9`, `top2.sv:3:21`, `top2.sv:4:21`) from the bare name, from
the declaration, and from each of the two uses. The class chain gives the
same 4 (`sb.sv:2:7`, `sb.sv:3:24`, `t.sv:4:9`, `t2.sv:3:33`) from the bare
name, the declaring file's own use, `e.s.count` and `e2.s.count`. Both
lists equal the whole-set oracle (`find_references` over every file).
- **2+3**: in `/* q */ initial $display("q"); assign r = `ID(q); assign q = a; // q`
the selector picks the code `q` at column 60. `references` lists it with
the declaration and the two uses on line 5. A line whose `q` is only in
strings: "not written on line 6". `` `ID(q)`` alone on its line and `a`
only inside `` `ID(a)`` are refused as "inside a macro argument" by both
tools, while `q` elsewhere on line 5 and `` `ID`` are still found.
- **4**: three instances in one statement with overrides (`#(.W(2)) u_a,
u_b, u_c`) each show `#(.W(2))`. Three without overrides show none. A
statement whose `#(` … `)` spans three lines, with a `// three` comment,
a `/* between ) , */` comment between instances and the last instance
after a leading comma, shows `#( .W(3) )` on all three, down and up. Two
separate statements of the same module in one owner keep their own
`#(.W(4))`/`#(.W(5))`, and an instance array has none.
- **11**: three uses naming three declarations (`l1`, `l2`, `l3`) are
refused by both tools with "`sig` on line 3 → l1.sv:1, line 7 → l2.sv:1,
line 12 → l3.sv:1; add `line`". `line: 7` then answers `l2.sv:1:25`. Two
uses of one declaration answer it. A use of a module declared twice lists
both declarations. On opentitan, `references {file: hw/ip/aes/dv/tb/tb.sv,
name: clk_i}` now refuses, naming `key_sideload_if.sv:8` (line 35) and
`aes.sv:42` (line 46). Before the rework it silently picked the first.
New attacks (11 `qa_recheck_*` tests, all green): the four hand
derivations above; `depth` schema `minimum` 1 / `maximum` 20, where 20
walks 20 levels and 21 is refused "from 1 to 20"; `col` on the last byte
and one past it are positions, two past is refused "line 2 is 13 bytes
long" (CRLF line) or "line 3 is 9 bytes long" (a last line with no
newline); `references` from a file the walk skips (a gitignored `.sv` and
a `notes.txt`) answers the real uses, including the file asked from,
while the by-name answer stays the indexed files, and a path that does not
exist is refused naming it, never a crash; whole-set `references` after
deleting one file mid-session drops its hit, and after deleting the
declaring file the refusal is prefixed "lucisv cannot follow this position:"
with no "rename"; unused waivers match `lucisv check .` (one
`unused-waiver` at `w.waiver:1:1`; a waiver file named by two configs is
read once; `rules: no-tabs` reports nothing, as `--select no-tabs .` does;
the per-file form reports none, as ruled).
Observation for the lead (not a finding): the coordinator's brief expected
`references` from a file that is not indexed to be a clean refusal. It
answers instead. That is consistent with M1's path rule (`outline`,
`definition` and `diagnostics` all read any file inside a root), and the
answer is correct. If a refusal is wanted, that is a ruling for all the
tools, not a fix in `references`.
opentitan (release, whole-set `references`): `clk_i` from
`prim_fifo_sync.sv` 2.37 s, 83 hits, the same count as the narrowed answer.
The dev's census test: 1 passed in 73.1 s (debug; per-call 9.8–14.9 s for
the five `references` calls). `git status --porcelain` of the checkout was
byte-identical before and after, and identical to the first QA pass's
snapshot.
Sizes (same awk rule): `tools/nav.rs` 343, `tools/select.rs` 177,
`tools/hierarchy.rs` 316, `tools/diagnostics.rs` 313, `tools/mod.rs` 151,
`resources.rs` 118. The rest are unchanged. No function over 45 lines. No
`unwrap`/`expect`/`panic!`/`#[allow]`/`unsafe` outside `#[cfg(test)]`.
Gates (through `tools/guard.sh`, one cargo invocation at a time, no guard
kill):
- `cargo fmt -p lucisv_mcp -- --check` → exit 0
- `cargo clippy -p lucisv_mcp --all-targets` → `Finished`, no warnings
- `cargo test -p lucisv_mcp` → unit 38 passed; `opentitan` 1 ignored;
`qa_m1` 51 passed; `qa_m2` 43 passed, 0 ignored; `wire` 19 passed
- `cargo test --workspace` → exit 0, **4 610 passed, 0 failed, 47 ignored**
(the dev's 4 599 + 11 re-check tests)
- `LUCISV_OPENTITAN=… cargo test -p lucisv_mcp --test opentitan --
--ignored` → 1 passed in 73.1 s; checkout status byte-identical
TODO-MCP M2 QA box ticked.
## Review
**Lead, 2026-09-23.** Read every source file after the rework. The one
ruling worth restating: the reference-narrowing rule in PLAN §2.1 was
mine and it was wrong — a two-level tail or a class-handle chain resolves
through files that never spell the name, so `references` now hands the
engine the whole indexed set (≈ 2 s on opentitan) and MCP-7 asks
`vlog_refactor` for a `KnownFacts` variant so M6 can feed cached records.
Correctness first; the census will show whether 2 s matters to an agent.
Other rulings: `diagnostics` matches `lucisv check .` (the whole-tree
run — "what will CI say"); a name on a line is chosen by token, never by
text; `hierarchy` overrides belong to the statement, so every instance of
one statement shows them; `depth` is 1..=20 in the schema; every read
tool reads any file inside a root, indexed or not (QA's closing question —
kept, the answer is correct and the rule is M1's). Missing-closer warnings
and one-step macro expansion are not offered (server-only code; MCP-5
filed). MCP-6 — the LSP omits three real `aes` instantiations in the
`*_pd_main.sv` tops — is a possible LSP bug to file in TODO.md at the end
of the block. Committed as M2.