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-edit-tools
Lane M3 of the MCP block (TODO-MCP.md, docs/mcp/PLAN.md §4.3).
Goal
Give an agent lucisv's verified edits as single MCP calls: format,
fix_lint, rename, the six cursor refactorings (expand_wildcard,
convert_ports, organize_imports, inline_module, propagate_ports,
remove_port), add_port, extract_module, and the text-only
instantiate. An agent that renames a port across a design today reads and
edits every file that mentions it; here it makes one call, sees the diff
first if it wants (dry_run), and gets either the whole verified edit on
disk or a sentence saying why nothing was written. Every tool is a wrapper
over an engine that already verifies its own output (vlog_refactor,
vlog_formatter, vlog_linter); the one new piece is the write path,
src/apply.rs, which every tool shares.
Assumptions
- All-or-nothing, as far as a filesystem allows. An engine's
RefactorEditis all-or-nothing by construction;apply.rskeeps it so on disk: every file's new text is computed (edits applied last-first, refusing on overlap, a range past the end, or a split UTF-8 character) before anything is written; every target is checked to lie inside a root (an existing file by its canonical path; a created file by its parent's canonical path, and nothing — not even a dangling symlink — at its own path); then the write-freshness check (next point); thenwrite_atomicper file in path order. A write that fails after others landed is anisErrorresult: "written N of M: a.sv, b.sv; failed onc.sv: " — the CLI's posture: said, never hidden, never rolled back. - The write-freshness rule (the lead's ruling for QA's first attack):
immediately before the first write, every file the edit rewrites is
re-read and compared byte for byte with the text the plan was
computed against (the ruling says "content hash"; comparing the bytes
themselves costs the same read and cannot collide); a created file must
still not exist; a read-only file is refused here, where
write_atomicwould only refuse it later, after other files landed. One mismatch refuses the whole edit: "fchanged on disk since it was read; nothing written." The window that remains is between that check and each file'srename(2): the time to write the files already checked, a few milliseconds for a rename across three files. A writer that lands inside it is overwritten, which is the same exposurelucisv formathas between its read and its write. There is no lock, for the reasonlucisv_core::atomicgives: a lock would buy nothing between processes that do not take it. - Where the texts come from. A refactoring is handed the whole indexed
set plus the selected file, read from disk at call time
(
tools/source.rs::WholeSet::read, the one whole-set readreferencesshares) — M2's ruling forreferences, for the same reason: a use can resolve through a file that never spells its name, so no narrowing by name is sound, and a narrowed set turns an unresolvable use into a false refusal. Those same texts are what the freshness rule compares against, so the index is never trusted for bytes. Cost: one read and one parse of every indexed file per call — see the timings in the work log (a copy of opentitan'shw/ip/aes: 124 files) and, for all of opentitan, M2'sreferencesnumbers (1.6–2.6 s release, 3 944 files). M6 measuresrenameon the whole checkout; Handshake MCP-7'sKnownFactsvariant is the way down, as it is forreferences. - Files the index skipped are never edited around (QA finding 2, lead's
ruling). The index leaves out files over 1 MiB and files that are not
UTF-8 (M1's rules);
project/files.rsnow keeps the large ones' paths (FileSet::skipped) andProject::skipped()returns both kinds with the reason.WholeSet::readcarries that list beside the texts, plus any indexed file that no longer reads. Before an engine runs, each edit tool names what it changes —rename: the old name;remove_port: the port and its module;propagate_ports,expand_wildcard,inline_module: the instantiated module;convert_ports,extract_module,add_portby position: the enclosing module;add_portbymodule: that name;organize_imports: nothing (it edits only its own file'simports) — and when a skipped file's bytes spell one of those names as a whole word the edit is refused: "rtl/big.sv(skipped: over 1 MiB) may referenced; lucisv-mcp will not edit around a file it cannot index; nothing written." Whole-word rather than any substring (a refinement of the ruling's "bytes contain"): an identifier, escaped or not, is always written with a non-identifier byte on each side, so no reference is missed, while a one-letter port such asdwould otherwise refuse every edit on any tree holding one skipped file. Otherwise the skipped files are named once underwarnings:("not indexed, so not searched or edited: …", ten at most, then "and N more");referencesends its answer with the same line aswarning:(andstructuredContent.warning), since its census is then partial. The search is conservative: a skipped file that spells the name only in a comment still refuses. - Known limits.
vlog_refactor::renamedoes not rewrite a.*or.nameshorthand connection bound to the renamed name (QA finding 1: the design is silently rewired; the LSP's rename has the same limit). It is the engine's, fixed in lane M3.5; until then therenamedescription says so and tells the agent to checkdry_runon designs using them.extract_moduleinto a CRLF file writes its instantiation with LF (Handshake MCP-10). dry_run: nullmeans absent (lead's ruling on QA finding 4): JSON null is "not given" for every argument of every tool (M1's validation), so a nulldry_runis the default,false, and the edit is written;"true"and1are refused as non-booleans.- What
dry_runreturns: the summary with(dry run: nothing written), the warnings, thenlucisv_core::diff::unifiedper file, headed by the root-relative path (a created file diffs from empty).structuredContentcarries each file'sdifftoo. Nothing is written and nothing is re-read for freshness. A real run answers the summary only:files: N changed, M created, onepath +added -removedline per file (counted from the diff, whose resync is deliberately coarse — a count can include an unchanged line the resync re-emitted),unchanged:for files looked at and left alone (format), the tool's note (fix_lint), andwarnings:. Nothing to write answersunchanged. - Idempotency.
idempotentHint: trueonformat,fix_lint,expand_wildcard,convert_ports,organize_imports(the lead's list). A second identical call writes nothing:format,fix_lintandrenameanswerunchanged(forrename, when the name at the position already isnew_name— checked withvlog_refactor::rename_name_atbefore the engine runs);expand_wildcard,convert_portsandorganize_importsanswer the engine's own "nothing to do" sentence (writes no .* to expand,already declares its ports ANSI-style,already sorted, and every one of them is used) as a tool error. Turning those sentences intounchangedwould mean matching engine wording, which drifts; a refusal that writes nothing is idempotent in effect, which is what the hint promises. The wire test asserts "unchangedor a refusal, and not one byte moved". - The fence rule (
fix_lint): a fix is applied only when none of its edits touches a regionvlog_formatter::fence::protected_regionsreports (// lucisv: off/// verilog_format: off) — the CLI'sfixable_outside_fences, restated intools/format.rs::outside_fencesover the same library answer (the CLI's copy is in a binary crate and cannot be called). OnlyApplicability::Safefixes (apply_fixes(…, false)); up to the CLI's 10 fix-then-relint rounds; the run isdiagnostics's (Runs, the per-filelucisv.toml,[lint] select/ignore, options, external waivers, the index-backed oracle). The result is refused when its tolerant parse has more errors than the input's (the CLI does not check this; the brief asked for it). The note saysfixed: rule ×n, …; N findings left, counted as findings that disappeared per rule. formattakesfileor comma-separatedfiles(noTy::List: a comma string, as the brief allowed) andlineswith one file only (LineRanges::parse, thenformat_range). The config is the CLI'sOptions::config_withwith no flags:line-length,indent,[format] uvm-utils-indentfromDiscovery::for_file. One file the formatter refuses refuses the whole call ("fwas not formatted: <the safety net's reason>; nothing written."); a formatter panic is caught and refused the same way. A CRLF file comes back LF-normalised — the formatter's own behaviour (docs/features/alignment), soformatandlucisv formatwrite the same bytes (asserted by the CRLF wire test).- Selectors.
renametakesdefinition's selector (tools/select.rs) and, for a barename(+unit),nav::declaration_position— the one declarationreferenceswould pick. The six cursor tools takefile+linewithcolornamethrough the same selector;file+linealone means the line's first non-blank byte (organize_importswants a scope, not a token).add_porttakesmodule(ModuleRef::Name) orfile+line(ModuleRef::Atat the line's start), not both.extract_module's selection isstart_line's first byte toend_line's last (line ending excluded);homeisnew_file(default, the file isnew_name.svbeside the source, as the engine names it) orsame_file. instantiateisinstantiation_plan+render_withover the filevlog_refactor::module_definitionnames (one walk on a miss;filepicks among several declarations), with no site — so no auto-connect: every port is connected to a same-named placeholder.with_params: falsedrops the#(…);instancereplaces the instance hole and must be one identifier —[A-Za-z_][A-Za-z0-9_$]*and not a keyword, or an escaped identifier\nameending in its one space — else the call is refused naming the rule (QA finding 5);wildcardrenders with no ports and writes(.*). The indentation step is the first root'sindent. Read-only annotations.- Engine refusals are passed through as written. They are sentences
for a user already (
vlog_refactor's convention), and several speak of the refactoring by name, which is right here (unlikereferences, which borrows rename's resolution).
Handshakes
Consumed (public APIs only; no library crate's behaviour was changed):
| crate | items |
|---|---|
vlog_refactor |
RefactorEdit, TextEdit, rename, rename_name_at, expand_wildcard, convert_to_ansi, organize_imports, inline_module, propagate_ports, remove_port, add_port, ModuleRef, extract_module, Home, instantiation_plan, InstantiationPlan::{render_with, instance_name}, Layout, module_definition |
vlog_formatter |
format_source, format_range, LineRanges::parse, Config, fence::{protected_regions, is_protected, Region} |
vlog_linter |
apply_fixes, Fix, Violation (plus everything diagnostics already consumed) |
lucisv_core |
atomic::write_atomic, diff::unified (new, below), config::{Discovery::for_file, FileConfig} |
Handshake MCP-1 — delivered as a pure move (lead's ruling).
crates/lucisv/src/diff.rs (the CLI's --diff printer, 127 production
lines and its six tests) moved unchanged to crates/lucisv_core/src/diff.rs,
exposed as lucisv_core::diff::unified (pub mod diff; in
lucisv_core/src/lib.rs, the crate doc updated). The only edit to the moved
text is its module doc comment. crates/lucisv/src/diff.rs is now one line,
pub use lucisv_core::diff::unified;, so main.rs's two diff::unified
calls are untouched and --diff output is byte-identical (same function).
The six tests run in lucisv_core now; lucisv_core is still
dependency-free. docs/topo.md is the lead's to update (M6).
Edits outside this lane's files, each a one-liner forced by the lane:
crates/lucisv_mcp/src/tools/nav.rs:declaration_positionispub(super)(was private) sorenamepicks the same declaration for a barenamethatreferencesdoes — a copy would drift.crates/lucisv_mcp/src/tools/diagnostics.rs(allowed by the brief):Runs,Runs::new,Runs::for_file,Run,Mentions,Mentions::of_filearepub(super); the lint call insidefile_findingsbecamepub(super) fn violationssofix_lintlints exactly asdiagnosticsdoes.diagnostics' answers are unchanged (its wire and QA tests are green, unedited).crates/lucisv_mcp/tests/qa_m1.rs: the tool count inqa_everything_but_initialize_and_ping_waits_for_the_handshakegoes from 11 to 23 (M2 made the same one-line edit when it added five tools).- Rework (lead's rulings on QA findings 2 and 4):
project/files.rs(FileSet::skipped),project/mod.rs(unreadablekeeps paths;Project::skipped();unreadable()returns the same strings as before),tools/source.rs(WholeSet),tools/nav.rs(all_filesreplaced byWholeSet::read;references'warning:line),tests/qa_m3.rs(findings 2 and 5 un-ignored, 1 and 3 re-reasoned, 4's test rewritten to the ruling).
Requests:
- MCP-8 →
vlog_refactor(a false refusal, not a corruption):remove_portrefuses a port whose only "use" is a named connection to it from an instantiation in another module of the same file:spare(withinput logic unused_i) andspare_user(instantiatingspare u_s (.unused_i(1'b0), …)) in one file → "unused_iis still used insidespareat s.sv:15; remove those uses first." — line 15 isspare_user's connection. With the two modules in two files the removal succeeds and deletes the connection.ports/remove.rs::body_uses_inseems to count the file's connection text rather thanspare's body alone. The fixtures putspare_userin its own file. - MCP-9 →
vlog_refactor(candidate): the engines' "nothing to do" refusals (expand_wildcardrule 5,convert_to_ansi's "already ANSI-style",organize_imports' "already sorted") are indistinguishable from real refusals except by wording. A typedErr(or anOk(RefactorEdit::default())) for "already done" would let every front end answerunchangedfor an idempotent second call. - To M6 (instructions):
rpc.rs'sINSTRUCTIONS(M1's file) names only the read tools. A sentence such as "edit tools (rename, format, fix_lint, the port refactorings) verify before writing and takedry_runto show the diff first" belongs there; M6 revisesinstructionsfrom the census anyway. - MCP-10 →
vlog_refactor(non-blocking, QA finding 3):extract_moduleinto a CRLF file writes the instantiation it leaves in place with bare LF (extract/render.rsrenders\nonly), so the file ends up with mixed line endings; the created file is LF. Valid Verilog, nothing lost. The engine should render the source file's line ending. QA'sqa_extract_module_keeps_a_crlf_file_crlfstays ignored for it. - QA finding 1 → lane M3.5 (lead's ruling):
renameand.*/.nameshorthand connections — see Known limits. QA'sqa_rename_never_breaks_an_implicit_port_connectionstays ignored ("engine limit, fixed in M3.5"). - Done in the rework:
nav.rs::all_filesandedit.rs::sourcesmerged intosource::WholeSet::read(one function;nav.rscalls it).
Status / TODO
- MCP-1:
unifiedmoved tolucisv_core::diff, CLI re-exports it, tests moved, CLI--diffbyte-identical apply.rs: plan from aRefactorEdit(reverse-order application, overlap/bounds/char-boundary refusals); containment (existing and created targets); the write-freshness check before the first write;write_atomicin path order; "written N of M" on a late failure; dry-run diffs; the summary text and JSON- registry:
tools::Effect(read / edit, idempotent) drives the annotations; twelve tools registered format(file/files,lines, config ladder, whole-call refusal, panic contained),fix_lint(safe, fenced, rounds, parse check, per-rule note)rename(definition's selector, whole set,unchangedrepeat)expand_wildcard,convert_ports,organize_imports,inline_module,propagate_ports,remove_portadd_port(moduleorfile+line),extract_module(new file / same file),instantiate(named/wildcard, params, instance)- tests: every tool dry-run / real / repeat; three-file rename; refusals
leave the tree byte-identical; extract into a new file and over an
existing one;
fix_lintbeside a fence; CRLFformat; stale-file, created-file-appeared, read-only, late-failure and outside-root unit tests onapply - timings on a copy of
hw/ip/aes - gates through
tools/guard.sh; sizes
Work log
2026-09-23 (dev, M3).
Built: src/apply.rs (the write path), src/tools/edit.rs (dry_run, the
whole-set read, rename and the six cursor refactorings),
src/tools/format.rs (format, fix_lint), src/tools/refactor.rs
(add_port, extract_module, instantiate); tools/mod.rs gains
Effect and the twelve entries; main.rs gains mod apply;. Fixtures: a
new tree tests/fixtures/edit (14 files: a package, leaf instantiated
from mid.sv and top.sv for the three-file rename, a .* instance, a
partial instance, a non-ANSI module, a module in its own file to inline, a
port only another file connects, an extract target, a badly formatted
file); M1's design and M2's nav trees are untouched.
Decisions and deviations:
- Byte comparison instead of a content hash for the freshness rule — same read, no collision (Assumptions).
- A read-only target is refused in the pre-write pass, before any
file is written;
write_atomicwould refuse it too, but only after the files before it in path order had landed. - The "nothing to do" repeat of three engines is a refusal, not
unchanged(Assumptions, MCP-9). fix_linttakesrules(likediagnostics), so an agent can fix one rule's findings; not in the brief, one parameter on the sameRuns.instantiatetakesfileto pick among several declarations, the wayunit_interfacedoes.- CRLF:
formatnormalises to LF because the formatter does; the test pins "the same bytes asformat_source", not "CRLF kept". - The one-line edits outside the lane listed under Handshakes
(
nav.rsvisibility,qa_m1.rscount).
Timings (release build, macOS arm64, a cp -R of opentitan hw/ip/aes —
124 indexed files, 29 046 lines — into the session scratch directory; the
checkout was only read, and its git status is the same before and after —
three files modified before this lane started, none by it):
| call | wall (ms) |
|---|---|
| index build at the first call | 49–57 |
rename op_i → cipher_op_i at rtl/aes_cipher_core.sv:123, dry_run (3 files, 4 macro-argument warnings) |
136 first call, 76 warm |
the same rename, written |
75–79 |
the same position again (cipher_op_i → cipher_op_i) |
10 (unchanged, no engine run) |
expand_wildcard at dv/err_injection_if/fi_core_wrapper.sv:21 (fi_core_if fi_if (.*)), dry_run |
54–59 |
| the same, written | 54–67 |
| the same again | 51 (the engine's "fi_if writes no .* to expand") |
Each call re-reads and re-parses the 124 files (the whole-set rule); on the
whole opentitan checkout that is M2's 1.6–2.6 s per call, which M6 measures
for rename.
Tests: lucisv_mcp 151 → 166 (+1 ignored, the opentitan census) — 5
apply unit tests, 10 new wire tests, the tools/list wire test rewritten
for the edit annotations; lucisv_core gains the six
diff tests the CLI loses (count unchanged across the two crates).
Gates (each through tools/guard.sh, one cargo invocation at a time):
cargo fmt -p lucisv_mcp -p lucisv_core -p lucisv -- --check clean;
cargo clippy -p lucisv_mcp -p lucisv_core -p lucisv --all-targets clean;
cargo test -p lucisv_mcp 43 + 51 + 43 + 29 passed, 1 ignored;
cargo test -p lucisv -p lucisv_core 30 + 113 + 117 passed;
cargo test --workspace 4 625 passed, 0 failed, 47 ignored (4 610 before).
Sizes (production lines: non-blank, non-comment, before mod tests):
apply.rs 216, tools/edit.rs 194, tools/format.rs 220,
tools/refactor.rs 241, tools/mod.rs 176, tools/diagnostics.rs 330,
lucisv_core/src/diff.rs 127, lucisv/src/diff.rs 1. No function over 40
lines.
2026-09-23 (dev, M3 rework after QA's FAIL; lead's rulings).
- Finding 1 (blocking, engine; ruled out of lane → M3.5):
vlog_refactoruntouched. Therenamedescription (tools/edit.rs:126) gains "A.*or.nameshorthand connection bound to the renamed name is not rewritten yet (known engine limit, M3.5); checkdry_runon designs using them."; Assumptions gains Known limits. QA's test stays ignored, reason "QA finding 1: engine limit, fixed in M3.5". - Finding 2 (blocking, fixed):
project/files.rs:38FileSet::skippedkeeps the paths the size cap drops;project/mod.rs:256Project::skipped()returns them and the non-UTF-8 files with why (unreadablenow keeps paths;unreadable()answers the same strings).tools/source.rs:155WholeSetis the one whole-set read (read,mentioning,warning,word_in_bytes), replacing bothedit.rs::sourcesandnav.rs::all_files.tools/edit.rs:241whole_setrefuses when a skipped file spells a name the edit changes, andfinish(edit.rs:258) lists the skipped files underwarnings:; every edit tool names its stake (edit.rs:149–210,refactor.rs:134, 142, 183).referencesends with the same line aswarning:(nav.rs:311). Deviation: the byte search is whole-word (Assumptions). QA's test un-ignored; two new wire tests (a_file_the_index_skipped_is_never_edited_around: refusal wording,add_portby module, the warning line on a name no skipped file spells,references' warning) and one unit test (word_in_bytes). - Finding 3 (non-blocking, engine): Handshake MCP-10 filed; QA's test stays ignored with that reason.
- Finding 4 (ruled no change):
dry_run: nullis absent — Assumptions says so; QA's test renamedqa_a_null_dry_run_is_absent_and_a_non_boolean_is_refusedand asserts exactly that. - Finding 5 (fixed):
tools/refactor.rs:270identifier— a simple identifier that is not a keyword (vlog_parser::token::is_keyword), or an escaped one ending in its space; anything else is refused naming the rule. QA's test un-ignored; a wire test adds\u-xaccepted and1u,\u-x(no space) refused.
Gates (through tools/guard.sh, one at a time): fmt --check rc 0;
clippy over lucisv_mcp/lucisv_core/lucisv --all-targets clean;
cargo test -p lucisv_mcp 44 + 0 (1 ignored) + 51 + 43 + 27 (2 ignored) +
31 passed; cargo test --workspace 4 655 passed, 0 failed, 49 ignored
(QA's 4 649 + 3 un-ignored + 3 new; 52 − 3 ignored). Sizes (production
lines): apply.rs 216 (unchanged — QA's #[path] include still builds),
tools/edit.rs 222, tools/format.rs 220, tools/refactor.rs 261,
tools/mod.rs 176, tools/diagnostics.rs 330, tools/nav.rs 340,
tools/source.rs 185, project/mod.rs 242, project/files.rs 153.
2026-09-23 (lead, after the QA re-check). Two fixes applied by the lead
rather than a third dev round, both a few lines: every whole-set tool (the
nine edits over the indexed set and references) now walks the roots
before it answers (rewalk: true), so a file written in the last 5 s is in
the set — QA finding 6, its test un-ignored; and the size-cap branch of the
walk makes the same root check the indexed branch makes, so a large file
reached through a symlink out of the root is neither indexed nor recorded
as skipped (finding 7, un-ignored). Cost of the walk on opentitan hw/:
≈140 ms per edit call, against the 1.6–2.6 s the whole-set read already
costs. Gates re-run by the lead through tools/guard.sh.
2026-09-23 (dev, feedback-1). rename, remove_port and add_port add one warnings: entry listing the name's unresolved textual mentions, and unresolved_mentions to their JSON (handshake change); add_port takes after (placement re-done on the MCP side, verified against the engine's appending edit, src/tools/place.rs); remove_port no longer goes through at_cursor — docs/features/mcp-feedback-1.
QA log
2026-09-23 (QA, M3). Verdict: FAIL — two blocking findings (1 in
vlog_refactor::rename, inherited; 2 in this lane's whole-set read), three
non-blocking. Everything the lane itself promises about the write path
held under attack: no refusal moved a byte, no write left a root, no file
was ever torn, format/fix_lint are byte-identical to the CLI. The two
blockers are wrong answers — a "verified" rename that reports success and
leaves the design broken — which the brief ranks blocking wherever they come
from.
Tests: crates/lucisv_mcp/tests/qa_m3.rs — 19 qa_* tests green + 5
#[ignore = "QA finding N"] (each confirmed failing under --ignored). The
file includes the production src/apply.rs verbatim through #[path] over
two stand-ins (project::Project with roots/relative/open,
tools::Answer), so apply::commit is attacked directly with stale texts —
no black box can hook the gap between a tool's read and its write; the
dev's five apply unit tests therefore also run a second time in that
binary (counted in the 24 it reports).
What was attacked, and how (all green unless a finding says otherwise):
- Corruption hunt. Every tool (14 real calls: rename by position and by
name+unit, the six cursor tools,add_portboth ways, extract new-file and same-file,format,fix_lint): the files that move are exactly the reported ones; each reported+a -requals the signed lines of the dry-run diff; the dry-run diff equalslucisv_core::diff::unifiedof (before, what the real call wrote); the same call again answersunchangedor a refusal and moves nothing. 25 refusals across all twelve edit tools (engine, argument and path refusals) leave every byte and mode bit of the tree, and of an outside directory reachable by a symlink, identical. Comments beside every edited span survive (a port with a trailing comment renamed, a.*with leading/trailing/block comments expanded, a block with a leading comment and a trailing one extracted; each comment's count over the tree is unchanged).formatof a file the safety net refuses leaves the tree identical;fix_lintleaves// lucisv: offand// verilog_format: offregions byte-identical and never appliesalways-comb's unsafe fix, even withrules: "always-comb"(answersunchanged). - Write freshness. Directly: a stale first, middle and last file (same
length, one byte changed — no size or mtime shortcut could catch it), a
file deleted, a file replaced by a directory, a created path taken by a
dangling symlink or a directory, a read-only last file — each refused
naming the file, nothing written; a file rewritten with the same bytes
(new inode and mtime) is fresh by the byte rule and lands. Black box: a
renameback and forth for 80 rounds while a thread rewritesmid.svatomically every 50 ms (unrenamed/renamed text + a marker) — after every call each file is wholly one form or the other, every "changed on disk" refusal namesrtl/mid.sv, and real writes happen (asserted). The same race on acp -Rof opentitanhw/ip/aes(op_i↔cipher_op_i, 3 files, scratch script): writer at 50 ms — 300 calls, 178 freshness refusals namingrtl/aes_core.sv, 122 engine refusals (mixed tree), no torn file; writer at 400 ms — 200 calls, 77 written, 18 freshness refusals, no torn file. - Paths.
extract_modulenew names../evil,/tmp/evil,\../../evil,a/b, empty — refused by the engine's plain-identifier rule; a source reached through a symlinked directory inside the root, and an absolute path outside — "outside every root"; a dangling symlink (to outside) or a directory at the created path — "already exists"; a read-onlyrtl/top.sv(last of the rename's three) — "is read-only; nothing written." withleaf.sv/mid.svuntouched; the same forformatandfix_lint. A symlinked file alias:files: "alias.sv, real.sv"is one file, the real file is written and the link kept. Symlinked files/dirs pointing outside are not indexed (M1's rule), so a rename never reaches them. - Concurrency.
lucisv --checkin a loop over a 60-file tree while the server formats it five times (tree re-dirtied each round): every check exits 0/1, the final files equal the CLI's in-place output. On the aes copy (124 files, scratch script): 8 rounds of threelucisv --checkruns plus, every other round, an in-placelucisvracing the server's 124-fileformat— no crash, every round's final tree byte-identical to the CLI's output. format= the CLI's bytes. CRLF file (CRLF → LF, byte-identical tolucisvin place and--stdout); a nestedlucisv.toml(line-length = 40,indent = 4) — its config is used, as the CLI does; a fenced region;lines2,1-2,99,4,2,4-4,2-2,50-60(past EOF:unchanged),1-999— each equal tolucisv --lines;3-1refused; a duplicate infiles(w.sv, w.sv,./w.sv) diffs once. On the aes copy: the server'sformatof all 124 files (242 ms release) is byte-identical tolucisvon every file.rename. The fixture rename equalsvlog_refactor::renameover all files, file for file (in-test oracle); on aes theop_irename equals a throwaway oracle binary (scratch crate) on all three files. A barenamepicks the declarationreferencespicks (same file set); an ambiguousqis refused listingrtl/ext.sv:4andrtl/leaf.sv:4; a keyword, a name already declared, an escaped name (\a+b, the engine refuses escaped new names by policy) and an empty name are refused; a hit inside a macro's arguments surfaces the engine's warning inwarnings:. See findings 1 and 2.- Engine refusals are refusals. Two or more per tool, tree unchanged:
expand_wildcard(positional list; abindinstance),convert_ports(already ANSI ×2),organize_imports(a`definein scope; a line past the end),inline_module(positional;.*; no instance),propagate_ports(all connected;.*; positional),remove_port(port still used ×2),add_port(existing port; an ordered instantiation of the wrong length),extract_module(no item selected; a name already on disk). MCP-8 reproduced as filed (s.sv:9isspare_user's connection). dry_rundiffs. Dry-run diff = the diff of the real run (test 1). On aes, the three-file rename's dry-run diff applies withpatch -p0onto a fresh copy and reproduces the real run byte for byte; it lists all three files. Its hunks are coarser than GNUdiff -u(16 signed lines vs 12 for the same change; a two-line rename inleaf.svreports+4 -4) — the CLI's resync, documented in Assumptions; noted, not a finding.- MCP-1.
git worktreeof82bbba0in the scratch dir (removed afterwards), its releaselucisvbuilt there:--diffover the whole aes copy (36 498 lines) and overcorpus/picorv32/picorv32.v(6 226),corpus/common_cells/src/fifo_v3.sv(277),.../addr_decode.sv(96) is byte-identical old vs new, exit codes equal. The moved file differs from 82bbba0'scrates/lucisv/src/diff.rsonly in its module doc comment. - Sizes/style (production lines = non-blank, non-
//lines before#[cfg(test)]):apply.rs216,tools/edit.rs194,tools/format.rs220,tools/refactor.rs241,tools/mod.rs176,tools/diagnostics.rs330,tools/nav.rs343,lucisv_core/src/diff.rs127,lucisv/src/diff.rs1 — the dev's numbers. No function over 50 lines. Nounwrap/expect/panic!/#[allow]/unsafein the lane's production code (format.rs:66is the word "unsafe" in a description).cargo tree -p lucisv_core -e normal:lucisv_corealone. - Gates (each through
tools/guard.sh, one cargo invocation at a time):cargo fmt -p lucisv_mcp -p lucisv_core -p lucisv -- --checkrc 0;cargo clippy -p lucisv_mcp -p lucisv_core -p lucisv --all-targetsclean, rc 0;cargo test -p lucisv_mcp43 + 0 (1 ignored) + 51 + 43 + 24 (5 ignored) + 29 passed;cargo test -p lucisv -p lucisv_core30 + 113 + 117 passed;cargo test --workspace4 649 passed, 0 failed, 52 ignored (4 625 + 24; 47 + 5).
Findings:
- 1 — BLOCKING (engine, pre-existing;
vlog_refactor::rename, reached here and fromlucisv-server). Renaming a port bound by an implicit connection, or a net such a connection binds, writes a "verified" edit that silently rewires the design.leaf (input d),topinstantiatingleaf u_leaf (.*)with its ownd,top2withleaf u_leaf (.clk, .d, .q): (a) renameleaf.d→din:leaf.svrenamed,top.svuntouched —.*no longer binds the port (the engine's ownexpand_wildcardthen says "no net … nameddin… lucisv wrote it unconnected");top2.sv's.dbecomes.din, which now names a nettop2does not have; (b) renametop.d→x: only the declaration moves;.*stops bindingleaf.d; (c) renametop2.d→x:.dis left naming nothing. All answer success with no warning. Reproduced with a directvlog_refactor::renamecall (scratch oracle), so it is the engine's.check::verify's resolution identity (crates/vlog_refactor/src/check/ mod.rs:41) cannot see it: neither.*nor.namespells a reference the resolver records. Fix (vlog_refactor, outside this lane — a Handshake request): rewrite.nameas.new(old)/.old(new), and refuse (or expand first) a rename that changes a name a.*binds, the wayinline_modulerefuses.*andremove_portwarns about it. Test:qa_rename_never_breaks_an_implicit_port_connection. - 2 — BLOCKING (this lane;
tools/edit.rs:209sources). The whole-set read is "every indexed file", and the index skips files over 1 MiB (project/files.rs:100) and files that are not UTF-8 (M1's rule, named only inproject_overview). A rename whose uses sit in such a file writes the others and answers success without a word: a 1.08 MBbig.svwithleaf u_l (.clk(clk), .d(x), .q(y))keeps.d(x)afterleaf.d→din_i("files: 1 changed"); the same for a copy ofmid.svwith a Latin-1©in its header comment — common in vendor RTL. Every engine that edits instantiations (rename,remove_port,add_port,propagate_ports) is exposed the same way. Suggested fix: keep the skipped paths (FileSet::skipped_largeis a count today) and, before writing, refuse when a skipped file's bytes contain the name being changed (the old name forrename, the module name for the port tools): "rtl/big.svis not indexed (over 1 MiB) and spellsd; nothing written." — or at minimum list the skipped files underwarnings:. Test:qa_rename_says_so_when_a_skipped_file_mentions_the_name. - 3 — non-blocking (engine, pre-existing).
extract_moduleinto a CRLF file writes the instantiation with bare LF (adder u_adder (\n .a(a),\n …), leavingext.svmixed; the created file is LF. Valid Verilog, nothing lost;vlog_refactor/src/extract/render.rsrenders\nonly. Test:qa_extract_module_keeps_a_crlf_file_crlf. - 4 — non-blocking.
"dry_run": nullis read as absent and the edit is written, while"true"and1are refused as non-booleans. For a flag whose default is "write", an explicit null should be refused like any other non-boolean (Argsvalidation ofTy::Bool, M1's file). Test:qa_a_null_dry_run_writes_nothing. - 5 — non-blocking.
instantiatetakes anyinstancestring:""renderspm #(…) (.*);,é,a b,u_x); evil (andmodulerender text that does not parse (tools/refactor.rs,instantiate). It writes nothing, so nothing is corrupted, but the text is handed to an agent to paste; the engine's plain-identifier check would refuse these. Test:qa_instantiate_refuses_an_instance_name_that_is_not_an_identifier.
Observations (not findings): the formatter on a CRLF file with a fence (or
lines) keeps CRLF inside the fence and writes LF elsewhere — CLI
identical, the formatter's own behaviour; fix_lint's posix-eof fix adds
the final newline at the end of an unterminated // lucisv: off region —
CLI identical (fence::is_protected treats EOF as outside); lucisv check --help still says --unsafe-fixes "changes nothing" though always-comb
ships an unsafe fix — stale CLI help, out of lane. The opentitan checkout
was only copied from (its git status shows the same three pre-existing
modifications before and after).
2026-09-23 (QA, M3 re-check after the rework). Verdict: FAIL — one new blocking finding (6), a one-line-per-tool fix; everything the rulings asked for is verified. Finding 1 is not counted (lead's ruling: engine, lane M3.5; its test stays ignored with that reason). If the lead rules finding 6 a known limit instead, the rest of M3 passes.
Re-derived by hand (release build, scratch copies of tests/fixtures/edit):
- Finding 2 — fixed as ruled. A 1.08 MB
rtl/big.svand a Latin-1rtl/lat.sv, each withleaf u_l (.clk(clk), .d(x), .q(y)):renamed→din_i(dry run and real) is refused,`rtl/big.sv` (skipped: over 1 MiB) may reference `d`; … nothing written.(resp.not UTF-8 text), tree unchanged. The name only inside other words (data,d_q,dd,d$x,x$d,\dx,oddin a comment): written, three files, the skipped file named once underwarnings:, its bytes untouched. - The whole-word rule attacked.
das the file's first byte, as its last byte (no newline), in.d(1), inf(d), as the escaped\d(the same identifier), and between two\xa9bytes — all refused. An escaped declaration\a+b(the stake is spelled\a+b): the skipped file's\a+bended by a tab, a newline or EOF refuses;a+bas an expression and the longer\a+bcdo not. An escaped declaration\ddstakesdd, so a skipped.dd(1)refuses too. The per-tool stakes of the README's table: with a skipped file spelling onlycell old inv ext spare,expand_wildcard,propagate_ports,inline_module,convert_ports,remove_port(modulespare),add_port(by module and by position) andextract_moduleare each refused naming their stake;organize_importswrites and names the skipped file. - Leaving and entering the skipped set.
big.svrewritten small and UTF-8: the next call is still refused with the stale reason "(skipped: over 1 MiB)" — the skipped list is the last walk's, so it lags up toREWALK_AFTER(5 s), on the safe side; after 5.5 s the rename edits all four files and the warning is gone. The other way, an indexedmid.svgaining a Latin-1 byte is refused on the very next call (the stamp sweep loses it and walks). - The merge did not change
references. The pre-rework binary (82bbba0, built in a scratch worktree, removed after) and the reworked one answerreferencesidentically — text andstructuredContent— at all 165 identifier positions oftests/fixtures/navand at 600 random positions of the aes copy (158 answered, the rest the same refusals). In-suite: on the nav fixture with one skipped file added, every answer is the plain one plus exactly the trailingwarning:line andstructuredContent.warning. - Finding 5 — fixed.
"",a b,u_x); evil (,modulerefused (the un-ignored test); the dev's wire test covers\u-xaccepted. - Finding 4 test edit. Renamed to
qa_a_null_dry_run_is_absent_and_a_non_boolean_is_refused,#[ignore]removed, doc comment rewritten for the ruling, and the assertion swapped (null now assertsfmt/messy.svwritten). It is not only a swap: a loop was added asserting"true"and1are refused with nothing written — extra assertions matching the new name, nothing of mine weakened. The other un-ignored tests (2, 5) are byte-for-byte mine apart from rustfmt; finding 1 and 3's#[ignore]reasons were reworded as ruled. - Race.
qa_a_rename_racing_a_writer_never_tears_a_filegreen; the aes script once more at 50 ms: 150 calls, 82 freshness refusals all namingrtl/aes_core.sv, 68 engine refusals, no torn file.
New findings:
- 6 — BLOCKING (this lane; every whole-set edit tool's
rewalk: false,tools/edit.rs,tools/refactor.rs). The whole set is "every indexed file", and a file created since the last walk enters the index only afterREWALK_AFTER(5 s,project/mod.rs:23); the edit tools do not walk. Arenameright after an agent writesrtl/newer.svwithleaf u_l (.d(x))answers "files: 3 changed" and leaves.d(x)behind — the wrong answer of finding 2, reached through time instead of size; a brand-new over-1 MiB file escapes the skipped-file guard the same way (a dry run answered it at once with no refusal; the same call 5.5 s later was refused). Suggested fix:rewalk: trueon the whole-set edit tools (the flag andrefresh(force_walk)exist;project_overviewuses it). Cost measured on the opentitanhw/checkout (3 944 files, read only): a forced-walk call 139–146 ms against 9–11 ms without, next to the 1.6–2.6 s whole-set read each edit already pays. Test:qa_an_edit_sees_a_file_created_just_before_it. - 7 — non-blocking (
project/files.rs:103–105). The size-cap branch records a file's canonical path as skipped without the root-containment check the indexed branch makes, so an over-1 MiB file behind a symlink leading out of the root refuses edits inside it, and the refusal prints the file's absolute path outside the root. A small file behind the same link is dropped (M1). Safe side (a false refusal, nothing written). Test:qa_a_large_file_behind_a_link_out_of_the_root_is_not_in_the_skipped_set.
Tests: qa_m3.rs +8 — seven qa_recheck_* green (refusal naming file and
reason; substring-only written with the warning; whole-word edges; escaped
names; every tool's stake; leaving/entering the skipped set; references
gains only the warning line) and finding 6's; plus finding 7's ignored. Now
34 passed, 4 ignored (1, 3, 6, 7). Sizes (same method): apply.rs 216,
tools/edit.rs 222, tools/format.rs 220, tools/refactor.rs 261,
tools/source.rs 185, tools/nav.rs 340, project/mod.rs 242,
project/files.rs 153; no unwrap/expect/panic!/#[allow] in their
production code.
Gates (through tools/guard.sh, one at a time): cargo fmt -p lucisv_mcp -p lucisv_core -p lucisv -- --check rc 0; cargo clippy -p lucisv_mcp -p lucisv_core -p lucisv --all-targets 0 warnings, rc 0; cargo test -p lucisv_mcp 44 + 0 (1 ignored) + 51 + 43 + 34 (4 ignored) + 31 passed;
cargo test --workspace 4 662 passed, 0 failed, 51 ignored (4 655 + 7;
49 + 2). The M3 QA box in TODO-MCP.md stays open on finding 6.
Review
Lead, 2026-09-23. Read apply.rs and the three tool files. The write
path is the block's safety story and it held under QA's race, permission and
symlink attacks: all-or-nothing, re-read before the first write, write_atomic
inside the roots only. Rulings: a skipped file (over 1 MiB, non-UTF-8) that
spells a changed name as a whole word refuses the edit — lucisv-mcp will not
edit around a file it cannot see; dry_run: null is absent; every whole-set
tool re-walks first. MCP-1 delivered as a pure move (lucisv_core::diff;
CLI --diff byte-identical). The one blocking finding that stays open is
not this lane's: vlog_refactor::rename leaves .* and .name shorthand
connections broken when a port or its bound net is renamed — a real
corruption the LSP has had all along, now exposed to agents. It is fixed in
its own engine lane, M3.5, before M4; until it lands the rename tool says
so in its description. MCP-8 (a false remove_port refusal on same-file
instantiations) and MCP-10 (CRLF in extract_module) are engine findings
filed for the owner. Committed as M3.