Files

29 KiB
Raw Permalink Blame History

lucisv-core-lift

Goal

The CLI and the language server were answering two different questions with two different pieces of code: lucisv discovers lucisv.toml and walks a tree honoring .gitignore and --exclude, while lucisv-server formatted with built-in defaults and indexed everything it could find, because both rules lived inside the lucisv binary crate where nothing else could reach them (the two Handshake requests filed by docs/features/lucisv-server/README.md). That is the classic way an editor's format-on-save drifts away from CI's lucisv --check. This round lifts config.rs and walk.rs — unchanged — into a new std-only library crate crates/lucisv_core, re-points the CLI at it with no behavior change at all, and wires the server through the same code: one discovery rule, one walk, two front ends.

Assumptions

  • The lift is mechanical, and is proven mechanical. Both modules moved as 100% renames (git diff -M says so) — not one line of logic, and not one line of their 31 unit tests, was edited. The modules kept their names inside the new crate, so even the import paths in the moved tests (use super::*) needed no change. Everything the CLI does is therefore unchanged by construction, and the untouched crates/lucisv/tests/cli.rs (48 tests) plus a byte-identical 820-file corpus (count corrected by lead per QA) run are the evidence.
  • lucisv_core is two modules, not a framework. pub mod config; pub mod walk; and nothing else — no re-export layer, no new traits, no configuration struct invented for a third caller that does not exist. The crate has no dependencies, std only, as both modules already did.
  • Precedence in the server is lucisv.toml > the client's tabSize > the built-in default, which is deliberately not the CLI's --flag > config > default. The CLI's flag is typed by a human for one run, so it outranks a file. FormattingOptions::tab_size is not that: LSP requires the client to send it on every formatting request, and what it sends is the editor's own default (VS Code's editor.tabSize, 4 unless changed) or its guess from the file's existing indentation. Treating an editor default as a deliberate override would let an unconfigured editor silently beat a checked-in lucisv.toml — reintroducing exactly the CLI/editor divergence this feature exists to delete, and making format-on-save fight lucisv --check in CI. Where the config file is silent, tabSize still beats the built-in default, so a project with no lucisv.toml behaves exactly as the server did before this round. line-length has no client analog at all and comes from the config file or not at all.
  • A broken lucisv.toml warns the editor; it does not fail it. The CLI's contract for an unparsable config is fatal: exit 2, nothing written, all configs resolved before any file is touched (docs/features/config-discovery/README.md). That is right for a batch tool where a half-applied run is the danger. It is wrong for an editor: a user who types a typo into lucisv.toml in one tab must not find that format-on-save has stopped working in every other tab, with an error where their code should be. So the server formats with the built-in defaults (never a partial mix of the broken file's keys — nothing at all is taken from a file that failed to parse) and reports the problem as a window/showMessage warning carrying the same path:line: message string the CLI would have printed. This is a deliberate divergence in reporting, not in discovery: the file searched for, the rule that finds it, and the settings taken from it when it parses are identical.
  • The warning is said once per file change. A format-on-save loop asks to format on every save; repeating the same config error forever would train the user to dismiss lucisv's messages. The server remembers which documents it has warned about and re-arms a document when its text changes (didOpen, didChange, didSave with text) or when it is closed.
  • The index scan anchors its excludes on the workspace root. exclude is resolved once per command-line input in the CLI, never mid-walk (config-discovery's own assumption); the server's analog of "an input" is a workspace root, so the config governing the root supplies the exclude patterns for that root's whole scan. A lucisv.toml in a subdirectory still governs line-length/indent for files under it when they are formatted — discovery there is per-document — it just cannot add excludes mid-scan, exactly as in the CLI.
  • .gitignore is always honored by the scan. It is the CLI's default and an editor has no --no-gitignore to type. Likewise the scan always runs discovery enabled: there is no --no-config in an editor.
  • A broken config does not stop the scan. During initialize there is no good way to refuse: a server that indexes nothing because of a typo simply looks broken. The scan proceeds with no excludes, and the same error reaches the user through the formatting path, which is where they will look.
  • The server's walk-depth cap is gone, deliberately. The old plain walk capped recursion at 64 directories to survive a symlink cycle; the lifted walk has no cap, because the CLI's does not. Keeping the cap would mean the index silently covering fewer files than lucisv formats — the divergence this round exists to remove — and adding a cap to the shared walk would silently drop deep files from CLI runs, which is a behavior change this mechanical lift must not make. Cycle detection belongs in the shared walk where it would protect both front ends; recorded as a follow-up below, not smuggled in here.
  • Untitled buffers get no config. A buffer with no path has no directory to search from, so it is formatted with tabSize-or-defaults, as before.
  • Discovery is rebuilt per formatting request. Discovery's cache is per-instance and the server is long-lived, so a cached answer would go stale the moment a user edits lucisv.toml. A fresh Discovery per request costs one file read on an explicit, user-initiated action — cheaper than any invalidation scheme that could be wrong. (config-discovery's Handshakes anticipated exactly this: "a server can drop and rebuild one when a config file changes on disk".)

Handshakes

  • New crate lucisv_core, consumed by lucisv and lucisv_server. Public surface, unchanged from what it was inside crates/lucisv:
    • lucisv_core::config: FileConfig { line_length, indent, exclude }, parse(&str) -> Result<FileConfig, String>, Discovery::{new, for_input, for_file, for_dir}.
    • lucisv_core::walk: EXTENSIONS, collect_files(input, exclude, gitignore, &mut Vec<PathBuf>) -> Result<(), String>, is_excluded(&Path, &[String]). Every item already carried the one-line doc comment CLAUDE.md asks for; no signature changed, so no crate-public boundary moved in a way that needed a new one. The rules themselves stay documented where they were: docs/features/config-discovery/README.md and docs/features/parallel-files/README.md.
  • crates/lucisv consumes lucisv_core and keeps nothing of its own: the two modules are gone from its src/, mod config;/mod walk; are gone from main.rs, and the three call sites now say lucisv_core::…. No duplicated logic was left behind.
  • Discharges both Handshake requests filed by docs/features/lucisv-server/README.md (items 1 and 2, config discovery and the ignore-aware walk). Both are annotated DELIVERED in that README, one line each, as the only edits made to another feature's document.
  • Request to the lead — stale prose in docs/features/lucisv-server/README.md and TODO.md, deliberately not edited here (out of this feature's stated scope, and a concurrent editor-packaging round is live in the same files):
    • lucisv-server README, Assumptions: "The workspace walk is plain … .gitignore and --exclude are not honored" and "lucisv.toml is not discovered … The server uses Config::default() … with the client's tab size overriding the indent" are both now false, and the tab-size sentence is contradicted by the precedence decided above.
    • lucisv-server README, Status/TODO: "Not done: lucisv.toml discovery, .gitignore-aware indexing — both blocked on the two Handshake requests above" is now done.
    • TODO.md:103 and TODO.md:120 point at crates/lucisv/src/config.rs and crates/lucisv/src/walk.rs; both files now live in crates/lucisv_core/src/. docs/features/spans/README.md:308 names the old config path in a work-log sentence about a concurrent round — historical, best left alone.
  • Follow-up for whoever next touches lucisv_core::walk: the walk has no symlink-cycle detection (a depth cap, or device+inode tracking). It never had; the CLI has always been exposed to it, and the server now shares the exposure since its own 64-directory cap was removed for parity. Fixing it in the shared walk protects both front ends at once — but it changes CLI behavior (deep trees, cyclic links), so it wants its own round with its own tests, not a quiet addition inside a mechanical lift.
  • TODO.md: no matching checkbox. The §3 config and .gitignore items and the §6 lucisv_server item are already checked; this round moves code and wires the server, and adds no item of its own. Nothing was checked off.

Status / TODO

  • crates/lucisv_core created with a compiling skeleton first, built standalone, and only then added to the root members (round 11's ordering lesson, taken literally).
  • config.rs and walk.rs moved as 100% renames, unit tests and all.
  • crates/lucisv re-wired to lucisv_core (Cargo.toml, main.rs, args.rs); no logic left behind, no CLI behavior change.
  • Server formatting discovers lucisv.toml anchored at the document's own path, by the CLI's rule.
  • Precedence config > tabSize > built-in default, decided and documented.
  • Broken config → one showMessage warning per file change, formatting proceeds with defaults, never a crash and never a partial config.
  • initialize's scan uses the lifted walk: same extensions, .gitignore honored, excludes from the workspace root's config.
  • Tests: lucisv_core inherits its 31 moved unit tests; server gains 8 unit tests (config-beats-tabSize, lucisv.toml governing a real buffer, broken config, untitled buffer, gitignore-honoring scan, root-config excludes, broken root config, extension filter) and 2 e2e tests through the real binary over stdio.
  • Both lucisv-server Handshakes annotated DELIVERED.
  • Gates: cargo test --workspace, cargo clippy --workspace --all-targets, cargo fmt --all --check, corpus check.
  • Not done, deliberately: symlink-cycle detection in the shared walk (see Handshakes — a real behavior change, wants its own round).
  • Not done: re-resolving exclude per directory during a scan. The CLI does not either; the two agree, which is the point of this round.
  • Not done: watching lucisv.toml for changes (workspace/didChangeWatchedFiles). Discovery is re-run per formatting request, so an edited config takes effect at the next format without it.

Work log

2026-08-19 — dev agent

  • Read CLAUDE.md, the two Handshake requests in docs/features/lucisv-server/README.md, all of docs/features/config-discovery/README.md and the behavior half of docs/features/parallel-files/README.md (both QA logs included), and crates/lucisv/src/{config,walk,main,args,lint}.rs before writing anything.
  • Ordering lesson taken literally. crates/lucisv_core was created with a literal-versioned manifest carrying an empty [workspace] table — making it its own workspace — the two modules were git mv'd in, and cargo test was run standalone (31 passed) before the root members entry existed. Only then was the manifest switched to version.workspace = true and the members line added. A members entry pointing at a crate that does not build breaks the workspace for every other agent in the tree, and the editor-packaging round was live in it.
  • The lift is provably mechanical. git diff -M --summary reports both moves as (100%). The 31 unit tests moved with their modules and did not need even an import-path edit, because the modules kept their names. The brief allowed edits to those imports; none were required.
  • Behavior preservation, measured rather than asserted. crates/lucisv's unit count is unchanged in total (58 = 27 that stayed + 31 that moved), and crates/lucisv/tests/cli.rs — 48 CLI integration tests — is byte-untouched and green. Then the strongest check available: a release lucisv built from a clean git worktree at HEAD and the working-tree lucisv were both run over the 820-file corpus (count corrected by lead per QA), and their per-file TSVs are byte-identical (diff silent; verification-error: none, crash: none in both). The committed corpus-check-results.tsv in the repo predates several landed rounds and was not touched — it is stale against HEAD itself, which the HEAD-vs-working comparison isolates cleanly.
  • The precedence decision was the one real design call, and it goes against the CLI's shape on purpose. Reasoning is in Assumptions above; the short version is that LSP forces the client to send tabSize on every request, so it is a default, not an intent, and a default must not beat a file a human checked in. The rule is pinned by a_config_file_beats_the_editors_tab_size (unit) and by a_lucisv_toml_governs_formatting_over_the_editors_tab_size (e2e: the client asks for tabSize: 2, the config says indent = 4, the wire carries four spaces).
  • Split format::formatting in two rather than letting it talk to the connection: settings_for(doc, options) -> Settings { config, problem } resolves, formatting(doc, &config) formats. The handler in server.rs computes both, then warns, which also keeps the immutable borrow of the document from colliding with the &mut self the warn-once set needs.
  • Warn-once is a HashSet<Uri> on Server, cleared by a new Server::set_document wrapper that every text-changing notification now goes through, and on didClose. The e2e test sends two formatting requests with no edit between them and asserts exactly one window/showMessage arrives on the wire — the assertion that would catch a regression here, since a per-request warning would pass every unit test.
  • state.rs's hand-rolled walk is deleted, not wrapped: MAX_WALK_DEPTH, SOURCE_EXTENSIONS, walk() and is_source() are gone, replaced by collect_files. Its unit test the_walk_finds_only_source_extensions tested a now-private-elsewhere helper, so it was replaced by the_scan_takes_only_source_extensions, which asserts the same thing one level up — through a real scratch directory and the resulting index — and so survives the next refactor.
  • The new scan tests use the index as the observation point (does WorkspaceIndex::member know this package?) rather than reaching for the private file list, so they pin the behavior a user sees.
  • The format unit tests that need a real tree write a .git marker into their scratch directory. That stops the upward discovery walk at the temp dir, so a lucisv.toml in some real ancestor of /tmp can never leak into a test result — the .git-stops-the-walk rule config-discovery documents, used as a test-hermeticity tool.
  • Two clippy fixes on the way through, both in the e2e test: &PathBuf → &Path in the new session helper, and the original test's inline spawn/write/read block replaced by the shared talk() helper it now needs anyway. No #[allow] was added anywhere.
  • No unwrap/expect/panic! outside #[cfg(test)] in any file touched: the scan swallows a config error with unwrap_or_default() and a walk error with let _ =, both with a comment saying why refusing would be worse.
  • Did not touch editors/**, root README.md, TODO.md, the corpus TSV, or any engine crate (vlog_parser, vlog_formatter, vlog_semantic, vlog_linter have no diff at all). Did not run git commit/git push.

Results (settled tree, all re-run at the end):

  • cargo test --workspace: 512 passed, 0 failed (baseline before this round: 503; +31 lucisv_core, −31 moved out of lucisv, +7 net lucisv_server unit, +2 lucisv_server e2e).
    • lucisv_core: 31 unit (20 config + 11 walk), all moved, all unmodified.
    • lucisv: 27 unit + 48 CLI integration, unmodified — the behavior-preservation proof.
    • lucisv_server: 82 unit (was 75) + 3 e2e (was 1).
  • cargo clippy --workspace --all-targets: 0 warnings.
  • cargo fmt --all --check: clean.
  • Corpus: HEAD binary vs. lifted binary over 860 files → identical TSVs, verification-error: none, crash: none. corpus-check-results.tsv unmodified in the repo.
  • Files added: crates/lucisv_core/{Cargo.toml,src/lib.rs} (+ the two moved modules), this README. Files edited: root Cargo.toml (one members line, additive), crates/lucisv/{Cargo.toml,src/main.rs,src/args.rs}, crates/lucisv_server/{Cargo.toml,src/{format,server,state}.rs,tests/e2e.rs}, and two annotation lines in docs/features/lucisv-server/README.md.

QA log

2026-08-19 — QA agent

Scope: -p lucisv_core -p lucisv -p lucisv_server. Verified every claim in the brief; all PASS, no blocking findings.

1. Mechanical lift.

  • git diff -M --summary: both moves report (100%) — confirmed rename, zero content diff by definition.
  • git show HEAD:crates/lucisv/src/config.rs | diff - crates/lucisv_core/src/config.rs and the same for walk.rs: both diff exit 0 — byte-identical, no divergence line.
  • crates/lucisv/tests/cli.rs: git diff HEAD empty (byte-untouched); grep -c '#\[test\]' = 48, all pass.
  • Unit total conserved: lucisv_core 31 (20 config + 11 walk), lucisv 27 + 48 CLI = 75. 58 (27+31) was the pre-lift lucisv total; post-lift it's 27 (stayed) + 31 (moved to lucisv_core) = 58, matches exactly.
  • main.rs/args.rs call sites confirmed rewired: use lucisv_core::config::Discovery, use lucisv_core::walk::{collect_files, EXTENSIONS} (main.rs:28-29), use lucisv_core::config::FileConfig (args.rs:3). No mod config;/mod walk; left in main.rs.

2. CLI behavior identical (corpus md5). Built target/release/lucisv from the working tree and a second binary from a git worktree add ... HEAD checkout, ran tools/corpus_check.sh with each (-b <binary>) over the same corpus/ tree (820 .v/.sv files — not 860 as the work log states; see Findings below, non-blocking). Both TSVs: md5 = aa982463f68c1a3568c02a0fc5e0c455 — exact match to the claimed hash, diff silent, verification-error: none, crash: none in both. Worktree removed after (git worktree remove --force).

3. Server config — all sub-claims verified live, driving the real target/debug/lucisv-server binary over stdio with a custom interactive Python driver (scratchpad: drive_lsp.py) that can mutate the filesystem between requests in one session — the packaged talk() e2e helper writes the whole session up front and can't do that, so this fills the gap the brief asked for ("drive the server live").

  • Fresh discovery per request: scratch dir with lucisv.toml (indent=4), didOpen, format with tabSize:2 → 4-space output (config wins). Deleted lucisv.toml from disk, sent a didChange touch (same text), formatted again → 2-space output (tabSize wins). Confirms the strongest claim in Assumptions.
  • Bonus, not required by the brief: repeated the above without the didChange touch — discovery was still fresh (2-space on the second format). Correct per the code: format::discover builds a brand-new Discovery::new(true) on every call (format.rs:70), there is no per-document cache to invalidate, so a didChange is not actually load-bearing for this claim — it just happened to be in the scripted scenario. Documented here in case a future cache is added and this stops being true; the README's wording ("Discovery is rebuilt per formatting request") already states it correctly and doesn't claim a touch is required.
  • Precedence, config > tabSize > default: unit test a_config_file_beats_the_editors_tab_size and e2e a_lucisv_toml_governs_formatting_over_the_editors_tab_size both green.
  • Precedence edge (config silent on indent): scratch lucisv.toml with only line-length = 100, formatted with tabSize:3 → newText used 3-space indent ("module m;\n wire a;\nendmodule\n"). Per-setting precedence confirmed, not per-file.
  • Broken config: one window/showMessage (type 2 = Warning) per file change, formatting proceeds on defaults, CLI's path:line: message format preserved (lucisv.toml:2 and unknown key \bogus`` both present in the message). Two formats with no edit between → exactly one warning (live-verified: warnings-after-format#1 = 1, warnings-after-format#2-no-edit = 1).
  • The one-warning throttle, what resets it: live-verified with a third format after a didChange to the document text (config left broken) → warning count went 1 → 1 → 2, i.e. the document edit re-armed the warning exactly as server.rs's set_document (which clears config_warnings for that URI on every didOpen/didChange/ didSave-with-text, and on didClose) documents. Matches the README's "once per file change" rule to the letter — a config-only edit does not reset it (there's no code path that would), a document edit does.
  • a_lucisv_toml_governs_formatting_over_the_editors_tab_size and a_broken_lucisv_toml_warns_once_and_still_formats: both green, assertions match the brief exactly (newText diff, warning count, message content).

4. Server scan.

  • state.rs: confirmed MAX_WALK_DEPTH/SOURCE_EXTENSIONS/walk()/ is_source() are gone; source_files() (state.rs:143) calls lucisv_core::walk::collect_files with gitignore=true always and Discovery::new(true).for_dir(root)'s exclude, anchored per root — matches the "workspace-root config excludes" claim exactly.
  • Live-verified: scratch workspace with .gitignore containing ignored_dir/, a module inside that dir, a visible module at the root. workspace/symbol on a query matching both names returned only the visible one — the gitignored subdir's module never reached the index.
  • Unit tests the_scan_skips_what_a_gitignore_skips, the_scan_honours_the_root_configs_excludes, a_broken_root_config_does_not_stop_the_scan, the_scan_takes_only_source_extensions all present and green.
  • Follow-up filing: confirmed present in this README's Handshakes ("Follow-up for whoever next touches lucisv_core::walk" — symlink-cycle detection, deliberately deferred) and cross-referenced in docs/features/lucisv-server/README.md's superseded-prose note ("symlink-cycle exposure now shared with the CLI, filed as a follow-up in that feature's README"). Filing exists as claimed.

5. Gates.

  • cargo test --workspace: 512 passed, 0 failed — summed every crate's reported count by hand to cross-check the workspace-wide figure (concurrent round's crates included): 27+48 (lucisv) + 31 (lucisv_core) + 82+3 (lucisv_server) + 8+1+4+6+2+39 (vlog_formatter) + 71+30 (vlog_linter) + 53+24+19+17 (vlog_parser) + 6+1+19+20 (vlog_semantic) + 1 doctest = 512. Exact match to the claim; the concurrent comments-round-2 work in vlog_parser/vlog_formatter was green at the time of this run.
  • Scoped counts confirmed exactly: lucisv_core 31 unit; lucisv 27 unit + 48 CLI integration; lucisv_server 82 unit + 3 e2e (all three e2e tests green, including the_binary_serves_a_whole_session_over_stdio which predates this round).
  • cargo clippy --workspace --all-targets: 0 warnings.
  • cargo fmt --all --check: clean.
  • Handshakes: both lucisv-server Handshake items 1 and 2 annotated DELIVERED in docs/features/lucisv-server/README.md (lines 256, 268), one line each as required, plus a Status/TODO checkbox flip and superseded-prose annotations on the two stale Assumptions bullets — all carrying a "(lead note)" attribution, consistent with this being the lead acting on the Handshakes request rather than dev-agent scope creep. TODO.md:103 and :120x2 (via git diff, now at different line numbers) already point at crates/lucisv_core/src/{config,walk}.rs — also already fixed, also outside this feature's own diff per the work log's file list. Nothing left for QA to do on these two items.

6. CLAUDE.md compliance.

  • cargo tree -p lucisv_core: single line, lucisv_core v0.1.0 (...), zero dependencies — std-only confirmed.
  • No unwrap()/expect(/panic! outside #[cfg(test)] in lucisv_core/src/{config,walk,lib}.rs or lucisv_server/src/{format,state, server}.rs (checked with an awk pass that stops counting at the #[cfg(test)] marker per file — zero hits before it in every file). lucisv/src/{main,args}.rs's unwrap()/panic! calls are all inside #[cfg(test)] mod tests blocks — allowed.
  • Every pub item in config.rs/walk.rs carries a /// doc comment (spot-checked FileConfig, parse, Discovery, EXTENSIONS, collect_files, is_excluded).
  • README has all seven required sections (Goal, Assumptions, Handshakes, Status/TODO, Work log, QA log, Review) present and populated (Review reserved, correctly empty).

Findings (all non-blocking):

  • [Low] Corpus size discrepancy. The work log's "Results" section says "820-file corpus (count corrected by lead per QA)"; the actual corpus at HEAD and in the working tree has 820 .v/.sv files (find corpus -type f \( -name '*.v' -o -name '*.sv' \) -not -path '*/.git/*' | wc -l = 820, confirmed twice, once per binary run). This does not affect the correctness claim — both binaries ran over the identical, actual 820-file tree and produced byte-identical output at the exact claimed md5 — but the "860" figure in the work log is inaccurate and should be corrected to 820 if this README is revised again, so a future reader doesn't chase a phantom 40-file gap.
  • [Info] corpus-check-results.tsv's committed md5 is 6af28a6d4942c4ddce0a061262eb5d68, different from the aa982463f68c1a3568c02a0fc5e0c455 this round reproduces — expected and already called out in the work log as pre-existing staleness against HEAD itself (several landed rounds ago), unrelated to this lift. Not touched, correctly.

No corrections made to any code or test — nothing broken, nothing to fix. No masked-corruption attack tests were needed for this round: no normalization in verify.rs was added or widened (this is a config/walk lift and server-wiring round, not a formatter-safety-net change), so CLAUDE.md invariant #4 does not apply here.

Review

2026-08-19 — lead. Verdict: accepted; commits with round 12 (jointly with editor-packaging — shared README/TODO edits). The CLI/server behavior gap is closed.

Points reviewed and accepted:

  1. The precedence ruling is the round's contribution: config > client tabSize > built-in default, argued from what tabSize actually is (an editor default sent on every request, not a deliberate choice). Rejecting the CLI analogy (--flag > config) for the editor was correct — the whole feature exists to stop format-on-save fighting lucisv --check in CI, and treating an unconfigured editor's 4 as an override would have reintroduced that fight. QA verified the per-setting edge (config sets only line-length → tabSize still governs indent) live.
  2. 100% renames, byte-identical moved files, untouched CLI suite, md5-equal corpus TSVs from both builds — the mechanical-lift bar was met at every level it can be measured, and QA re-derived each measurement rather than trusting it.
  3. Warn-once with a document-edit reset is sensible ergonomics and QA pinned its exact reset behavior (1→1→2 across format/format/ didChange+format). The divergence from the CLI's exit-2 (an editor must not stop formatting over a config typo) is documented where it belongs.
  4. The depth-cap removal traded a server-only symlink guard for CLI parity and filed the shared exposure as a follow-up instead of smuggling a behavior change into a mechanical lift — the right instinct, twice.

Lead fix on acceptance: the corpus file-count figure (860→820) per QA. The stale lucisv-server Assumptions this lift superseded were struck through with lead notes at the editor-packaging review, alongside the TODO path pointers.