Files
lucioandClaude Fable 5.1 4671b91704
ci / checks (push) Successful in 1m30s
ci / corpus (push) Successful in 32s
MCP feedback-1: unresolved mentions on references and the edit tools, a smaller catalogue, hierarchy/references routing, add_port after, temp sweep; census round 1 written up
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]>
2026-09-23 20:44:06 -07:00
..

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 RefactorEdit is all-or-nothing by construction; apply.rs keeps 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); then write_atomic per file in path order. A write that fails after others landed is an isError result: "written N of M: a.sv, b.sv; failed on c.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_atomic would only refuse it later, after other files landed. One mismatch refuses the whole edit: "f changed on disk since it was read; nothing written." The window that remains is between that check and each file's rename(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 exposure lucisv format has between its read and its write. There is no lock, for the reason lucisv_core::atomic gives: 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 read references shares) — M2's ruling for references, 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's hw/ip/aes: 124 files) and, for all of opentitan, M2's references numbers (1.6–2.6 s release, 3 944 files). M6 measures rename on the whole checkout; Handshake MCP-7's KnownFacts variant is the way down, as it is for references.
  • 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.rs now keeps the large ones' paths (FileSet::skipped) and Project::skipped() returns both kinds with the reason. WholeSet::read carries 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_port by position: the enclosing module; add_port by module: that name; organize_imports: nothing (it edits only its own file's imports) — 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 reference d; 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 as d would otherwise refuse every edit on any tree holding one skipped file. Otherwise the skipped files are named once under warnings: ("not indexed, so not searched or edited: …", ten at most, then "and N more"); references ends its answer with the same line as warning: (and structuredContent.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::rename does not rewrite a .* or .name shorthand 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 the rename description says so and tells the agent to check dry_run on designs using them. extract_module into a CRLF file writes its instantiation with LF (Handshake MCP-10).
  • dry_run: null means absent (lead's ruling on QA finding 4): JSON null is "not given" for every argument of every tool (M1's validation), so a null dry_run is the default, false, and the edit is written; "true" and 1 are refused as non-booleans.
  • What dry_run returns: the summary with (dry run: nothing written), the warnings, then lucisv_core::diff::unified per file, headed by the root-relative path (a created file diffs from empty). structuredContent carries each file's diff too. Nothing is written and nothing is re-read for freshness. A real run answers the summary only: files: N changed, M created, one path +added -removed line 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), and warnings:. Nothing to write answers unchanged.
  • Idempotency. idempotentHint: true on format, fix_lint, expand_wildcard, convert_ports, organize_imports (the lead's list). A second identical call writes nothing: format, fix_lint and rename answer unchanged (for rename, when the name at the position already is new_name — checked with vlog_refactor::rename_name_at before the engine runs); expand_wildcard, convert_ports and organize_imports answer 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 into unchanged would 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 "unchanged or a refusal, and not one byte moved".
  • The fence rule (fix_lint): a fix is applied only when none of its edits touches a region vlog_formatter::fence::protected_regions reports (// lucisv: off / // verilog_format: off) — the CLI's fixable_outside_fences, restated in tools/format.rs::outside_fences over the same library answer (the CLI's copy is in a binary crate and cannot be called). Only Applicability::Safe fixes (apply_fixes(…, false)); up to the CLI's 10 fix-then-relint rounds; the run is diagnostics's (Runs, the per-file lucisv.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 says fixed: rule ×n, …; N findings left, counted as findings that disappeared per rule.
  • format takes file or comma-separated files (no Ty::List: a comma string, as the brief allowed) and lines with one file only (LineRanges::parse, then format_range). The config is the CLI's Options::config_with with no flags: line-length, indent, [format] uvm-utils-indent from Discovery::for_file. One file the formatter refuses refuses the whole call ("f was 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), so format and lucisv format write the same bytes (asserted by the CRLF wire test).
  • Selectors. rename takes definition's selector (tools/select.rs) and, for a bare name (+unit), nav::declaration_position — the one declaration references would pick. The six cursor tools take file + line with col or name through the same selector; file + line alone means the line's first non-blank byte (organize_imports wants a scope, not a token). add_port takes module (ModuleRef::Name) or file + line (ModuleRef::At at the line's start), not both. extract_module's selection is start_line's first byte to end_line's last (line ending excluded); home is new_file (default, the file is new_name.sv beside the source, as the engine names it) or same_file.
  • instantiate is instantiation_plan + render_with over the file vlog_refactor::module_definition names (one walk on a miss; file picks among several declarations), with no site — so no auto-connect: every port is connected to a same-named placeholder. with_params: false drops the #(…); instance replaces the instance hole and must be one identifier — [A-Za-z_][A-Za-z0-9_$]* and not a keyword, or an escaped identifier \name ending in its one space — else the call is refused naming the rule (QA finding 5); wildcard renders with no ports and writes (.*). The indentation step is the first root's indent. 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 (unlike references, 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_position is pub(super) (was private) so rename picks the same declaration for a bare name that references does — 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_file are pub(super); the lint call inside file_findings became pub(super) fn violations so fix_lint lints exactly as diagnostics does. diagnostics' answers are unchanged (its wire and QA tests are green, unedited).
  • crates/lucisv_mcp/tests/qa_m1.rs: the tool count in qa_everything_but_initialize_and_ping_waits_for_the_handshake goes 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 (unreadable keeps paths; Project::skipped(); unreadable() returns the same strings as before), tools/source.rs (WholeSet), tools/nav.rs (all_files replaced by WholeSet::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_port refuses a port whose only "use" is a named connection to it from an instantiation in another module of the same file: spare (with input logic unused_i) and spare_user (instantiating spare u_s (.unused_i(1'b0), …)) in one file → "unused_i is still used inside spare at s.sv:15; remove those uses first." — line 15 is spare_user's connection. With the two modules in two files the removal succeeds and deletes the connection. ports/remove.rs::body_uses_in seems to count the file's connection text rather than spare's body alone. The fixtures put spare_user in its own file.
  • MCP-9 → vlog_refactor (candidate): the engines' "nothing to do" refusals (expand_wildcard rule 5, convert_to_ansi's "already ANSI-style", organize_imports' "already sorted") are indistinguishable from real refusals except by wording. A typed Err (or an Ok(RefactorEdit::default())) for "already done" would let every front end answer unchanged for an idempotent second call.
  • To M6 (instructions): rpc.rs's INSTRUCTIONS (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 take dry_run to show the diff first" belongs there; M6 revises instructions from the census anyway.
  • MCP-10 → vlog_refactor (non-blocking, QA finding 3): extract_module into a CRLF file writes the instantiation it leaves in place with bare LF (extract/render.rs renders \n only), 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's qa_extract_module_keeps_a_crlf_file_crlf stays ignored for it.
  • QA finding 1 → lane M3.5 (lead's ruling): rename and .*/.name shorthand connections — see Known limits. QA's qa_rename_never_breaks_an_implicit_port_connection stays ignored ("engine limit, fixed in M3.5").
  • Done in the rework: nav.rs::all_files and edit.rs::sources merged into source::WholeSet::read (one function; nav.rs calls it).

Status / TODO

  • MCP-1: unified moved to lucisv_core::diff, CLI re-exports it, tests moved, CLI --diff byte-identical
  • apply.rs: plan from a RefactorEdit (reverse-order application, overlap/bounds/char-boundary refusals); containment (existing and created targets); the write-freshness check before the first write; write_atomic in 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, unchanged repeat)
  • expand_wildcard, convert_ports, organize_imports, inline_module, propagate_ports, remove_port
  • add_port (module or file+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_lint beside a fence; CRLF format; stale-file, created-file-appeared, read-only, late-failure and outside-root unit tests on apply
  • 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:

  1. Byte comparison instead of a content hash for the freshness rule — same read, no collision (Assumptions).
  2. A read-only target is refused in the pre-write pass, before any file is written; write_atomic would refuse it too, but only after the files before it in path order had landed.
  3. The "nothing to do" repeat of three engines is a refusal, not unchanged (Assumptions, MCP-9).
  4. fix_lint takes rules (like diagnostics), so an agent can fix one rule's findings; not in the brief, one parameter on the same Runs.
  5. instantiate takes file to pick among several declarations, the way unit_interface does.
  6. CRLF: format normalises to LF because the formatter does; the test pins "the same bytes as format_source", not "CRLF kept".
  7. The one-line edits outside the lane listed under Handshakes (nav.rs visibility, qa_m1.rs count).

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_refactor untouched. The rename description (tools/edit.rs:126) gains "A .* or .name shorthand connection bound to the renamed name is not rewritten yet (known engine limit, M3.5); check dry_run on 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:38 FileSet::skipped keeps the paths the size cap drops; project/mod.rs:256 Project::skipped() returns them and the non-UTF-8 files with why (unreadable now keeps paths; unreadable() answers the same strings). tools/source.rs:155 WholeSet is the one whole-set read (read, mentioning, warning, word_in_bytes), replacing both edit.rs::sources and nav.rs::all_files. tools/edit.rs:241 whole_set refuses when a skipped file spells a name the edit changes, and finish (edit.rs:258) lists the skipped files under warnings:; every edit tool names its stake (edit.rs:149–210, refactor.rs:134, 142, 183). references ends with the same line as warning: (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_port by 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: null is absent — Assumptions says so; QA's test renamed qa_a_null_dry_run_is_absent_and_a_non_boolean_is_refused and asserts exactly that.
  • Finding 5 (fixed): tools/refactor.rs:270 identifier — 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-x accepted and 1u, \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):

  1. Corruption hunt. Every tool (14 real calls: rename by position and by name+unit, the six cursor tools, add_port both ways, extract new-file and same-file, format, fix_lint): the files that move are exactly the reported ones; each reported +a -r equals the signed lines of the dry-run diff; the dry-run diff equals lucisv_core::diff::unified of (before, what the real call wrote); the same call again answers unchanged or 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). format of a file the safety net refuses leaves the tree identical; fix_lint leaves // lucisv: off and // verilog_format: off regions byte-identical and never applies always-comb's unsafe fix, even with rules: "always-comb" (answers unchanged).
  2. 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 rename back and forth for 80 rounds while a thread rewrites mid.sv atomically 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 names rtl/mid.sv, and real writes happen (asserted). The same race on a cp -R of opentitan hw/ip/aes (op_i ↔ cipher_op_i, 3 files, scratch script): writer at 50 ms — 300 calls, 178 freshness refusals naming rtl/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.
  3. Paths. extract_module new 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-only rtl/top.sv (last of the rename's three) — "is read-only; nothing written." with leaf.sv/mid.sv untouched; the same for format and fix_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.
  4. Concurrency. lucisv --check in 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 three lucisv --check runs plus, every other round, an in-place lucisv racing the server's 124-file format — no crash, every round's final tree byte-identical to the CLI's output.
  5. format = the CLI's bytes. CRLF file (CRLF → LF, byte-identical to lucisv in place and --stdout); a nested lucisv.toml (line-length = 40, indent = 4) — its config is used, as the CLI does; a fenced region; lines 2,1-2,99, 4,2, 4-4,2-2, 50-60 (past EOF: unchanged), 1-999 — each equal to lucisv --lines; 3-1 refused; a duplicate in files (w.sv, w.sv,./w.sv) diffs once. On the aes copy: the server's format of all 124 files (242 ms release) is byte-identical to lucisv on every file.
  6. rename. The fixture rename equals vlog_refactor::rename over all files, file for file (in-test oracle); on aes the op_i rename equals a throwaway oracle binary (scratch crate) on all three files. A bare name picks the declaration references picks (same file set); an ambiguous q is refused listing rtl/ext.sv:4 and rtl/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 in warnings:. See findings 1 and 2.
  7. Engine refusals are refusals. Two or more per tool, tree unchanged: expand_wildcard (positional list; a bind instance), convert_ports (already ANSI ×2), organize_imports (a `define in 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:9 is spare_user's connection).
  8. dry_run diffs. Dry-run diff = the diff of the real run (test 1). On aes, the three-file rename's dry-run diff applies with patch -p0 onto a fresh copy and reproduces the real run byte for byte; it lists all three files. Its hunks are coarser than GNU diff -u (16 signed lines vs 12 for the same change; a two-line rename in leaf.sv reports +4 -4) — the CLI's resync, documented in Assumptions; noted, not a finding.
  9. MCP-1. git worktree of 82bbba0 in the scratch dir (removed afterwards), its release lucisv built there: --diff over the whole aes copy (36 498 lines) and over corpus/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's crates/lucisv/src/diff.rs only in its module doc comment.
  10. Sizes/style (production lines = non-blank, non-// lines before #[cfg(test)]): apply.rs 216, tools/edit.rs 194, tools/format.rs 220, tools/refactor.rs 241, tools/mod.rs 176, tools/diagnostics.rs 330, tools/nav.rs 343, lucisv_core/src/diff.rs 127, lucisv/src/diff.rs 1 — the dev's numbers. No function over 50 lines. No unwrap/expect/panic!/#[allow]/unsafe in the lane's production code (format.rs:66 is the word "unsafe" in a description). cargo tree -p lucisv_core -e normal: lucisv_core alone.
  11. Gates (each through tools/guard.sh, one cargo invocation 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 clean, rc 0; cargo test -p lucisv_mcp 43 + 0 (1 ignored) + 51 + 43 + 24 (5 ignored) + 29 passed; cargo test -p lucisv -p lucisv_core 30 + 113 + 117 passed; cargo test --workspace 4 649 passed, 0 failed, 52 ignored (4 625 + 24; 47 + 5).

Findings:

  • 1 — BLOCKING (engine, pre-existing; vlog_refactor::rename, reached here and from lucisv-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), top instantiating leaf u_leaf (.*) with its own d, top2 with leaf u_leaf (.clk, .d, .q): (a) rename leaf.d → din: leaf.sv renamed, top.sv untouched — .* no longer binds the port (the engine's own expand_wildcard then says "no net … named din … lucisv wrote it unconnected"); top2.sv's .d becomes .din, which now names a net top2 does not have; (b) rename top.d → x: only the declaration moves; .* stops binding leaf.d; (c) rename top2.d → x: .d is left naming nothing. All answer success with no warning. Reproduced with a direct vlog_refactor::rename call (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 .name spells a reference the resolver records. Fix (vlog_refactor, outside this lane — a Handshake request): rewrite .name as .new(old) / .old(new), and refuse (or expand first) a rename that changes a name a .* binds, the way inline_module refuses .* and remove_port warns about it. Test: qa_rename_never_breaks_an_implicit_port_connection.
  • 2 — BLOCKING (this lane; tools/edit.rs:209 sources). 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 in project_overview). A rename whose uses sit in such a file writes the others and answers success without a word: a 1.08 MB big.sv with leaf u_l (.clk(clk), .d(x), .q(y)) keeps .d(x) after leaf.d → din_i ("files: 1 changed"); the same for a copy of mid.sv with 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_large is a count today) and, before writing, refuse when a skipped file's bytes contain the name being changed (the old name for rename, the module name for the port tools): "rtl/big.sv is not indexed (over 1 MiB) and spells d; nothing written." — or at minimum list the skipped files under warnings:. Test: qa_rename_says_so_when_a_skipped_file_mentions_the_name.
  • 3 — non-blocking (engine, pre-existing). extract_module into a CRLF file writes the instantiation with bare LF (adder u_adder (\n .a(a),\n …), leaving ext.sv mixed; the created file is LF. Valid Verilog, nothing lost; vlog_refactor/src/extract/render.rs renders \n only. Test: qa_extract_module_keeps_a_crlf_file_crlf.
  • 4 — non-blocking. "dry_run": null is read as absent and the edit is written, while "true" and 1 are refused as non-booleans. For a flag whose default is "write", an explicit null should be refused like any other non-boolean (Args validation of Ty::Bool, M1's file). Test: qa_a_null_dry_run_writes_nothing.
  • 5 — non-blocking. instantiate takes any instance string: "" renders pm #(…) (.*);, é, a b, u_x); evil ( and module render 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.sv and a Latin-1 rtl/lat.sv, each with leaf u_l (.clk(clk), .d(x), .q(y)): rename d → 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 , odd in a comment): written, three files, the skipped file named once under warnings:, its bytes untouched.
  • The whole-word rule attacked. d as the file's first byte, as its last byte (no newline), in .d(1), in f(d), as the escaped \d (the same identifier), and between two \xa9 bytes — all refused. An escaped declaration \a+b (the stake is spelled \a+b): the skipped file's \a+b ended by a tab, a newline or EOF refuses; a+b as an expression and the longer \a+bc do not. An escaped declaration \dd stakes dd, so a skipped .dd(1) refuses too. The per-tool stakes of the README's table: with a skipped file spelling only cell old inv ext spare, expand_wildcard, propagate_ports, inline_module, convert_ports, remove_port (module spare), add_port (by module and by position) and extract_module are each refused naming their stake; organize_imports writes and names the skipped file.
  • Leaving and entering the skipped set. big.sv rewritten 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 to REWALK_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 indexed mid.sv gaining 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 answer references identically — text and structuredContent — at all 165 identifier positions of tests/fixtures/nav and 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 trailing warning: line and structuredContent.warning.
  • Finding 5 — fixed. "", a b, u_x); evil (, module refused (the un-ignored test); the dev's wire test covers \u-x accepted.
  • 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 asserts fmt/messy.sv written). It is not only a swap: a loop was added asserting "true" and 1 are 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_file green; the aes script once more at 50 ms: 150 calls, 82 freshness refusals all naming rtl/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 after REWALK_AFTER (5 s, project/mod.rs:23); the edit tools do not walk. A rename right after an agent writes rtl/newer.sv with leaf 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: true on the whole-set edit tools (the flag and refresh(force_walk) exist; project_overview uses it). Cost measured on the opentitan hw/ 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.