Census round 1 (mcp_analysis.md, Sonnet arms on the opentitan clone): the mcp arm used more tokens than plain file tools on all three tasks (+18/+25/+20 %) and was incomplete on the rename — the `rename` tool renamed what the engine sees and warned about the macro argument, but nothing listed the old name still spelled as text (a DV force path built as the string ".state_q"), which the base arm's broad search found. Fixes (crates/lucisv_mcp/src/tools/{mentions,place,place/slot,place/verify}.rs + descriptions): `references`, `rename`, `remove_port` and `add_port` end with every whole-word spelling of the name in strings, comments, macro text, define bodies and macro-rooted paths that no engine answer accounted for, ranked edited-files-first, capped at 50, computed on the texts as written; `hierarchy` leads with "who instantiates a module", `references` routes a module name there, `instructions` say so; `tools/list` 30.2 kB → 18.0 kB with every argument still documented; `add_port` takes `after` — the engine appends, the placer moves the header element and each instance's connection to after the anchor in the neighbours' layout, refuses any list holding an unreadable element (an `(* attr *)` port the parser keeps as text would otherwise make the next port inherit the new type — QA's blocking find), and a checker compares every port's declaration text and pairs each comment with its anchoring name against the engine's result; stale `index-cache-mcp.*.tmp` files older than 10 min swept before a write. QA (Opus, two rounds): 23 qa_f1 tests. Gates through tools/guard.sh: fmt, clippy, workspace 4 918 passed.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
mcp-feedback-1
Lane feedback-1 of the MCP block: the changes the first token-census
round asked for (mcp_analysis.md, Round 1 → "Changes for round 2").
Tracked in TODO-MCP.md → "Feedback rounds".
Goal
Round 1 showed that lucisv-mcp's answers were correct but not complete
enough, and not discoverable enough, to beat plain file tools: a rename left
a DV force-path string and a macro-rooted probe behind without a word, the
census agent asked references for "who instantiates X" instead of
hierarchy up, add_port could not place a port where the task wanted it,
and the tool catalogue cost every session ~7 500 tokens before any work.
This lane makes the answers say what the engines could not see (unresolved
mentions), points the agent at the right tool (descriptions and
instructions), makes a positioned port insertion one verified call
(add_port's after), cuts the catalogue by 40 %, and sweeps the orphaned
temporary store M6 QA found.
Assumptions
- What a mention is. A whole-word spelling of the name (not glued to an
identifier character on either side,
source::word_in) that lies in: a comment (every token'sleading/trailingtrivia), aStringtoken, a macro call's text after the macro's own name (every word — arguments, strings and comments inside them alike), a`definebody after the macro name and formal list (a define whose formals spell the name is skipped: the formal shadows it), or an identifier ending a dotted path whose head is a macro token (`X_HIER.u_a[0].name,`SPI(1).u.name). A file that does not lex lists every spelling astext. Plain identifiers elsewhere are never mentions: they belong to some declaration the engines resolve (another module's ownstate_qis not noise here).`ifdef nameand attributes are not searched. - Accounted for. A spelling inside a span the engine returned —
references' hits, or any edit range of the rename/remove_port/add_portedit — is not a mention. The engines' own macro warnings (rename's "appears in the arguments of…") still appear; the mentions list repeats those sites, deliberately: it is the one complete list. - Why not
macro_spellings.item/macros.rs::macro_spellingsanswers "is this identifier used here", so it skips strings inside macro text (`define P ".state_q") — exactly the round-1 miss. The mentions scanner word-searches the raw macro/define text instead. - Order and cap. Listed nearest first: files the engine touched, then
lines spelling the declaring unit's name (catches
u_<unit>on a macro path), then by how many leading path components the file shares with the declaration's file; file and line within. One mention per line. At most 50 (mentions::CAP), then… and N more; lines capped at 160 characters. On opentitanstate_q(entropy_src main_sm) the three round-1 sites are lines 1, 2 and 4 of 415. - Cost. No new reads: the engines already hold every indexed file's text
(
WholeSet). Each text isstr::contains-filtered; only a text spelling the name is lexed. The index word censuses (files_mentioning,files_naming_in_macros) cannot narrow further — comments and strings are not in them — so they are not used. Measured on the eval clone (~/.cache/lucisv-eval/ot/hw, 3 944 files, release builds, same session warm, two runs each), r1 binary → this lane:call r1 feedback-1 mentions referencesstate_q(entropy_src_main_sm.sv:42)1.98 s 2.04–2.09 s 415 (50 listed) referencesclk_i(aes_core.sv:30)2.37–2.39 s 2.60–2.69 s 50 listed renamestate_qdry run2.17–2.24 s 2.34–2.39 s 415 (50 listed) i.e. +0.06–0.3 s on a 2–2.7 s whole-set call. referencespaging. The section is on the first page only (offset0); later pages repeat nothing.- Descriptions.
tools/listmeasured as the compact JSON of theresultobject: 30 221 B before, 17 981 B after (−40.5 %). Tool descriptions 9 095 → ~2 700 B, argument descriptions 7 621 → ~2 500 B,annotations.titledropped (it repeatedtitle). Every argument keeps a description. The position rules left the descriptions forINSTRUCTIONS(896 characters, under qa_m6's 900 cap). - Temp sweep. Before writing its store,
cache::write_ownremovesindex-cache-mcp.<digits>.tmpfiles older than 10 minutes (STALE_TEMP); a younger one may be a live concurrent writer's, and no other file is touched.
add_port after — exactly what happens
vlog_refactor::add_port only appends (header and connections), so it runs
first, unchanged; its verified edit is the reference. tools/place.rs then:
- Header (MCP side). The module's ANSI port named
afteris the anchor; its index counts every element of the list, asListDirective::beforedoes. Refused, in this order: a non-ANSI/empty list; an unknownafter(the ports are named); an anchor inside an`ifdefarm; a list holding an element the parser could not read ((* keep *) b— its text is named; lucisv cannot see what it inherits); a next port that would inherit from the new one — no direction and no type (inherits both), or a type but no direction when the new port's direction differs from the anchor's (a modport port,bus_if.mp bus, has no direction to inherit and is placed after). The engine's header edits (those inside the port list's parens) are dropped and the new element goes into the slot after the anchor's separator (place/slot.rs), never at the anchor's end:- anchor followed by
,and the next element starting a later line: a new line at the end of the comma's line (past a comment on it, and past a block comment that closes on a later line),element,; ,with the next element on the same line (a, b, a leading-comma list, input c):element,right after the comma;- a last anchor with
)starting a later line:,at the anchor's end, a new line at the end of the anchor's line (past its comments); - a last anchor with
)on its line:, elementat the anchor's end, or — a comment between —,at the anchor's end andelementbefore the). A new line takes the anchor's line ending (CRLF kept); when the anchor is alone on its line, its indentation and column layout (direction, type, name at the anchor's columns when they fit), else the next element's indentation and the declaration on one line.
- anchor followed by
- Connections. For each instance of the module that the engine gave a
connection edit: a positional list is refused unless
afteris the last port (then the engine's appended connection stands); a list holding an unreadable element is refused (its text named); a named list whose.after(…)sits outside any`ifdefarm (full-list index) gets the engine's expression (read back from its appended.port(expr),/* TODO: connect */included) in the same slot after.after(…)'s separator, aligned ((and)at the anchor's columns when they fit) or inline. Otherwise the engine's appended connection stands and a warning names the instance (root-relative) and why. - Verification (
place/verify.rs, the refusal names the failed check): the placed edit applied must, file by file, be the engine's result with elements moved: the same sorted multiset of tokens (kind + text); every comment attached to the same identifier — the nearest one before it for a comment on its token's line (a,is never an anchor), the nearest one after it for a comment on lines of its own; no more parse diagnostics; the module's port list with every element (unreadable ones by text) in the engine's order with the new port moved afterafter, each port's declaration text (blanks collapsed) the engine's, and the port after the new one not inheriting from it; every instance's connections the same (named: sortedname(expr)with blanks squeezed; positional: in order; unreadable elements by text). Then the one write path,apply::run.
Handshakes
- Consumed:
vlog_parser::{tokenize, parse_source_tolerant, LineIndex}, AST port/instance types;vlog_refactor::{add_port, remove_port, rename, find_references, rename_name_at, enclosing_module, module_definition, RefactorEdit, TextEdit};apply::Plan::from_refactor(applies and checks edits, used as-is byplace::verify). - Promised (answer shapes):
referencestext gains the sectionunresolved mentions (strings, comments, macro text — not resolved by lucisv):withfile:line kind: textlines;rename,remove_portandadd_portgain onewarnings:entry — "<lead>as text at these places lucisv does not resolve (strings, comments, macro text; N in all); check whether these are references:" with the same lines indented four. All four add"unresolved_mentions": [{file, line, text, kind}]to their JSON (empty when none);kind∈comment,string,macro,define,path,text.add_porttakesafter.tools/listno longer carriesannotations.title. - Flag for the lead (ownership):
src/tools/place.rsis a new file not in the lane's list —refactor.rswould have gone from 291 to ~770 lines with it. It is only used byrefactor.rs. The rework split it intoplace.rs(driver and refusals),place/slot.rs(where and how an element is written) andplace/verify.rs(the move-checker), all new. - Mentions after an edit (QA finding 4):
finish_tellingruns the mentions pass on the texts as written (the plan's new text for an edited file, the read text otherwise), with the edit's ranges shifted into the written text, sofile:linenames the file as it is after the write — and, for a dry run, the diff's new side.
Status / TODO
src/tools/mentions.rs— the scanner, ranking, renderingreferencessection + JSON;rename/remove_port/add_portwarning + JSON (edit::finish_telling)- descriptions and
INSTRUCTIONS(hierarchy/references wording; ≤ 18 kB) add_portafter(src/tools/place.rs), with attack tests on its verifier- stale temp-store sweep;
qa_an_orphaned_temp_file_is_swept_by_the_next_writeun-ignored - wire tests (mentions on
references/rename,afterbyte-exact on anaes_core-shaped fixture, last-port and unknown-anchor, catalogue size, sweep) - opentitan cost measured (above)
Work log
2026-09-23 (dev, Opus).
mentions.rs(212 production lines):findover theWholeSettexts,spellingsper file (comments, strings, macro text, define bodies, macro-rooted paths), ranking,Mentions::{lines, json, warning}.nav.rs:referencescomputes mentions before handing texts toTexts; the section follows the hits;unresolved_mentionsin JSON.edit.rs:finish_telling(accounted = the edit's ranges);renameandremove_port(no longer throughat_cursor) use it.refactor.rs:add_porttakesafter, resolves the module's file (module_definitionor the given file), runsplace::after, and finishes throughfinish_tellingwith the new port's name.place.rs(479 production lines): see "exactly what happens" above. Decision: re-placing the engine's verified edit and verifying the moved result against it, rather than asking for an engine change — no Handshake onvlog_refactorneeded.- Descriptions: all 26 rewritten;
mod.rsdropsannotations.title. 30 221 → 17 981 B. cache.rs:sweep_stale_tempsbefore each own-store write.- Tests: unit tests in
mentions.rs(4) andplace.rs(6, three of them attacks/refusals on the verifier); 7 wire tests; fixturetests/fixtures/feedback/.
2026-09-23 (dev, Opus) — rework on the QA verdict and the lead's
rulings. All six qa_f1 tests un-ignored; none contradicted a ruling
(5b's expects the ifdef refusal for an anchor inside an arm next to an
unreadable element, so the arm is checked before the unreadable-element
refusal — both refuse).
- 5 (blocking):
place.rsheaderrefuses a port list with an unreadable element (named), after theifdefcheck;afterrefuses an affected instance whose connection list holds one;balanced_beforeis handed full-list indices on both sides;verifycompares the whole port list, unreadable elements by text, each port asname: declaration(blanks collapsed) against the engine's — the type-swap pair is a unit test (place/verify.rs), refused. - 1 (major): insertion moved to the slot after the separator
(
place/slot.rs, unit-tested ona /* about a */,, a leading-comma list, a last port with a block comment, a block comment spanning the comma's line, CRLF);verifypairs each comment with its identifier (attacks: a comment glued to the anchor's comma, a leading-comma list, the anchor line's comment taken by the new line). Deviation from the ruling's letter, for the reason: the ruling pairs every comment with its preceding token; for a comment on lines of its own that would forbid the placement round 1 asked for (rst_ni,⏎ blank ⏎// Data⏎data_i— the new port goes right afterrst_ni, so// Data's preceding name changes although it still sits abovedata_i). Such a comment is paired with the identifier after it instead; a same-line comment with the one before it (never a,). Both catch QA's attacks. - 2: every file
place.rsnames goes throughSpec::show(project.relative). - 3:
inherits: no direction and no type → inherits both (refused); a type but no direction → inherits the direction, refused only when the new port's direction differs from the anchor's; a modport type (x.y) → never. Stricter than the ruling's "both absent" in one case (output logic a, logic [3:0] bwith a newinput:bwould turn input), unit-tested. - 4:
edit.rs::finish_tellingscans the written texts;mentions::findnow takes(path, text)pairs;written_rangesshifts the edit ranges.
QA log
2026-09-23 (QA, Opus) — verdict: REWORK (1 blocking, 1 major, 3 low).
Attacks in crates/lucisv_mcp/tests/qa_f1.rs (real binary over scratch
trees; placements byte-exact, refusals with the tree byte-identical under
dry_run and for real): 11 pass, 6 #[ignore = "QA finding N"] pin the
findings below (each fails today, run with --ignored).
Verified, holds:
afterbyte-exact on: an anchor with a//comment on its line (stays there), the last port with a trailing/* */(comma before the comment, the new line has none), tab indentation, CRLF (kept on the new line), one-per-line aligned connections, two instances in one statement, an instance in a generate block, an instance in the module's own file (file+lineselector), a positional instance withafter= last (appended) and elsewhere (refused, nothing written), an anchor just before and just after an`ifdefarm (placed outside), an anchor in an arm (refused), a parameter asafter(refused, ports listed), a connection anchor in an arm (engine's append kept, warning names the instance),.*instances (the engine's warning; nothing placed), the same call twice (engine refuses, nothing written).dry_run's diff, applied to the old text, is byte-for-byte what the real run writes (forafter= first, middle, last).- Mentions: a hierarchical path in a comment, a string inside a macro's
arguments, a
`definebody listed and a`definewith the name as formal not, a macro-rooted path through[2], an escaped\namein a comment,state_q_d/xstate_q/a path ending instate_q_d/the name as an index not listed; CRLF line numbers right and no\rin the text; JSON keys exactlyfile, kind, line, text;offset> 0 has no section and[]; the cap (60 far mentions + the edited file's: 50 listed, edited file first, "65 in all", "… and 15 more"); a renamed file's hits excluded and its other mentions kept. opentitan (eval clone, release, through the shim):references clk_iat aes_core.sv:30 — r1 4.00 s / 4.00 s, feedback-1 4.21 s / 4.22 s (+0.21 s, within the recorded +0.06–0.3 s); 801 mentions, 50 listed; the clone left clean. - Catalogue:
tools/list17 981 B (≤ 18 000), 26 tools, every argument described, no argument lost against HEAD (onlyafteradded; checked per file bygit show HEAD:),titlekept at tool level and absent fromannotations, the three hints booleans;instructions896 chars, everysnake_caseword it names is a tool (bardry_run). - Sweep: an hour-old
index-cache-mcp.1.tmpgoes;..tmp,.12a.tmp,.12.tmp.bak,index-cache.12.tmp,xindex-cache-mcp.12.tmp(all an hour old) and an old directoryindex-cache-mcp.77.tmpstay; the own store is still written (plus the dev's young-file test).
Findings:
- Major — a comment re-attached to the new port, forgiven by the
checker. An anchor whose comment sits between it and its comma
(
input logic a /* about a */,), or on its line before a leading-comma next element (input logic b // about b⏎, input logic c), is not "alone on its line", soinlineinserts at the anchor's end (place.rs:173, :256):input logic a, input logic en /* about a */,and.a (a), .en(en) /* conn a */,— the comment now documentsen.verifycompares comment texts as a sorted multiset (place.rs:529–540), so the move passes. Repro:qa_a_comment_between_the_anchor_and_its_comma_stays_with_the_anchor. Fix: insert, elementat the start of the token after the anchor when it is,or)(past the trivia), else at the anchor's end; and inverify, compare each comment paired with its preceding non-,token. - Low — absolute paths. The warnings and refusals
place.rswrites usepath.display()(place.rs:84, :221):`u_n` in /private/var/…/rtl/top.sv: the connection …; every other answer is root-relative. Repro:qa_place_names_files_relative_to_the_root. - Low — false refusal. A modport port after the anchor
(
bus_if.mp bus) has no direction and inherits none, but place.rs:155 refuses "takes its direction and type from the port before it". Repro:qa_a_modport_port_after_the_anchor_does_not_refuse. (A barebus_if busis ambiguous with a type; refusing that one is right.) - Low — stale mention lines after a write.
finish_telling(edit.rs, thementions::findoverset.files) lists mentions with the pre-edit line numbers; after a realadd_port(lines added),remove_port(removed) or arenamethat writes out.*bindings, a mention below the edit in an edited file names the wrong line (rtl/m.sv:6 comment: // en gates y— line 6 is now);). Repro:qa_mention_lines_name_the_file_as_written. Fix: shift each mention by the net newlines the file's edits insert before its offset, when not a dry run. - BLOCKING — an unreadable port-list element defeats the placer and the
checker (masked corruption, written to disk).
place.rsreads the header throughListElem::ok(ansi_ports, place.rs:128–133) and so doesverify(ports_in_order, place.rs:542–564). An element the parser could not read —(* keep *) b, legal SV, an attribute on a port — is invisible to both:- a)
input logic [7:0] a,⏎(* keep *) b,withafter: "a": the newinput logic enlands between them, sobnow inheritsinput logic— 8 bits become 1 — and it is written (same tokens, same parse-error count, same well-formed port order). Repro:qa_a_port_hidden_by_a_parse_error_does_not_change_its_inherited_type. - b)
balanced_beforegets the anchor's index among the well-formed elements, butListDirective::beforecounts all of them (place.rs:161; the connection side has the same shape at :241–244). With(* keep *) input logic dbefore an`ifdef Xarm,after: "b"(inside the arm) passes: the port is written inside the arm while the connection is unconditional, and the engine's warning in the same answer says it was added "outside every conditional arm". Repro:qa_an_unreadable_element_does_not_let_an_anchor_in_an_ifdef_arm_through. Fix: refuseafterwhen the port list (or the anchor instance's connection list) holds anyListElem::Error, or index the raw list everywhere (the anchor's raw index forbalanced_before, the raw next element must beOkwith a direction).verifyshould re-derive the same on the placed tree with raw indices, and compare each port's declaration text (blanks squeezed) by name with the engine's: today a craftedinput logic [7:0] a, input logic en→input logic a, input logic [7:0] en(a type swapped between the anchor and the new port) has the same tokens, names in order, parse and connections, andverifywould accept it. These attack pairs belong inplace.rs's unit tests next toverify_refuses_a_placement_that_is_not_a_move(verifyis private; QA cannot reach it fromtests/).
- a)
Observations (no test; for the lead):
- Layout: a multi-line anchor (
input logic⏎[7:0] e,) measures its name column across the newline (place.rs:339), so the new line's name is pushed far right. Cosmetic. - Ranking ignores kind: 60 comments in one file push that file's
macro-rooted path — the round-1 miss class — past the cap. Ranking
path/string/define/macroabovecommentwithin a rank would keep the valuable ones listed. - Out of lane (engine / parser, pre-existing):
vlog_refactor::add_portappends a connection inside an`elsearm when the list's tail is conditional (.y ()⏎`endif); the parser reads(* attr *)on an ANSI port as an error element (after: "d"answers "no portd"); the unified diff re-lists unchanged lines as-/+near a file end without a final newline.
Gates (all through tools/guard.sh):
cargo fmt --all -- --check— exit 0, no output.cargo clippy --all-targets—Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.96s, no warnings.cargo test -p lucisv_mcp— 347 passed, 0 failed, 9 ignored (qa_f1:test result: ok. 11 passed; 0 failed; 6 ignored).cargo test --workspace— 4 903 passed, 0 failed, 56 ignored (4 892 + 11).
2026-09-23 (QA, Opus) — re-check of the rework: PASS (findings 1–5 closed; one new low, finding 6, left for the lead).
Re-derived by hand over stdio (the eval shim mcp_call.sh on the debug
binary, scratch trees): 5a (* keep *) b after an 8-bit a — refused,
"m's port list holds (* keep *) b…; nothing written", both files
byte-identical (md5); 5b anchor b inside the arm behind an unreadable
d — refused "inside an ifdef arm", and after: "a"in the same list refused by the unreadable-element rule; 5c the type swap cannot be built through the tool (the placer writes the declaration verbatim), so confirmed as the unit testplace::verify::tests::a_type_swapped_between_the_anchor_and_the_new_port_is_refused(passes); 1a /* about a /,→ the new line below it, the comment ona's line; .a (a) / conn a */,likewise;b // about b⏎, input logic c→, input logic en, input logic c`. The six pinned
tests (findings 1–5) pass un-ignored and unchanged.
New attacks (qa_r_* in tests/qa_f1.rs, all byte-exact or tree
byte-identical): an unreadable connection (..q (p)) in another module's
instance and in an untouched .* instance of m — placed, not refused;
in the instance placed into — refused, named rtl/top.sv; own-line
comments above the last anchor and closing the list — both stay, header
and connections; a /* c1 */, // c2 — the new line goes below, both
comments on a's line; a last anchor with /* c */ before ) on its
line — y, /* c */ input logic en); a leading-comma list; a typed
undirected logic [3:0] b after the anchor — placed under input,
refused under output (nothing written); a rename writing out a .*
binding (one line added above the mentions) — each listed line is the
line on disk after the write (off-by-none).
- Low — dry-run mention lines name a file that is not on disk. The
rework computes mentions on the texts as they would be written, under
dry_runtoo: in the.*rename above, the dry run listsrtl/top.sv:6 comment: // a feeds u_m, and line 6 on disk is the$display(the comment is at 5 until the edit is written). The text is shown beside the line, so an agent can recover; but a dry run's diff and lines otherwise describe the file on disk. Repro:qa_r_dry_run_mention_lines_name_the_file_on_disk(ignored). Either use the pre-edit lines underdry_run, or say "lines as written" in the warning — the lead's call.
Gates (all through tools/guard.sh, one at a time):
cargo fmt --all -- --check— exit 0, no output.cargo clippy --all-targets—Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.21s, no warnings.cargo test -p lucisv_mcp— 362 passed, 0 failed, 4 ignored (unit:test result: ok. 73 passed; qa_f1:test result: ok. 22 passed; 0 failed; 1 ignored).cargo test --workspace— 4 918 passed, 0 failed, 51 ignored (4 913 + 5 new).
Review
Lead, 2026-09-24 (feedback-1). The first census round's lesson was
discoverability and completeness of what the server says, not the
correctness of what it answers, and this lane changes exactly that: an
"unresolved mentions" section on references and the edit tools (the DV
string path round 1 missed is now line 4 of the list on opentitan), a
catalogue 40 % smaller, hierarchy/references descriptions that route
"who instantiates X" to the right tool, and a positioned add_port. The
last is the one piece of new text-moving logic, and QA's first round found
the classic hole — an unreadable port element the placer could not see, so
the next port inherited the new one's type — fixed by refusing any list
with an unreadable element, full-list positions, and a checker that
compares every port's declaration text and pairs each comment with its
anchoring name. Ruling on QA's finding 6: under dry_run the mention line
numbers describe the file as it would be written; the line text beside
each number is the recovery, and the wording stays. Committed; the round-2
binary is frozen from this commit.