# cli-filelist ## Goal Give the `lucisv` CLI the same front door the server got in M1: `lucisv -f project.f` formats or lints exactly the files an EDA filelist names, reusing `lucisv_core::filelist::read` unchanged. M1 deliberately stopped at the config key and the language server — "a `lucisv -f` flag is its own change with its own exit-code questions" (`docs/features/filelist/README.md`, Status). This is that change: the flag, the answers to those questions, and nothing else. No new parsing, no new dependency, no version bump. ## Assumptions - **A filelist is an *input*, not a *mode*.** `-f` adds files to whatever the command line already names; it does not replace, filter or reorder them. So `lucisv -f a.f`, `lucisv rtl/` and `lucisv -f a.f rtl/ tb/top.sv` are all ordinary runs, and having neither positional inputs nor `-f` is still the usage error it always was. - **Listed paths are named paths.** `--exclude` and `.gitignore` filter *directory walks* only (`docs/features/parallel-files/README.md`: "a path named on the command line is never ignored"). A filelist path was written down by a human in a project file, which is at least as explicit as typing it as an argument, so the same rule applies: it is processed. The opposite choice would mean a `.gitignore` in a generated-RTL directory could silently shrink the build's own file set. - **Warnings are warnings.** Everything M1's parser reports as a warning — a listed file that no longer exists, an option lucisv has no table for, an unset `$VAR`, a repeated filelist, a `-f` chain past `MAX_NESTING_DEPTH` — goes to stderr as `warning: :: ` and leaves the exit code alone. This matches the server, which shows the same strings and keeps indexing. A stale line in a 400-file filelist must not fail CI; the run's exit code reports what happened to the files that *do* exist. - **The filelist itself is not.** `filelist::read`'s `Err` is reserved for the root file being unreadable, the one case where the caller learns nothing at all — a typo in the flag, or a path that CI did not generate. That is a hard error: exit 2, before the worker pool starts, with nothing processed and nothing written. Silently formatting only the positional inputs when the filelist is missing would be the worst of both worlds. - **Two names for one file are one file.** Dedup is by lexical absolute path (`.`/`..` folded, symlinks deliberately not resolved — the same rule `filelist::Reader::normalize` and `config::Discovery::absolute` already use), and the *first* spelling seen is the one lucisv reports, so `lucisv -f p.f rtl/a.sv` still says `rtl/a.sv` and not the absolute path the filelist produced. This also dedups repeats that have nothing to do with filelists (`lucisv rtl/ rtl/a.sv`), which previously formatted the file twice — see the Work log. - **The `filelist` key in `lucisv.toml` stays server-only.** Auto-consuming it would make `lucisv rtl/` process files that are not under `rtl/`, and `lucisv --check .` in CI change its file set because someone added a key for the editor's benefit. A CLI filelist is named on the command line, where it is visible in the CI log. `--help` says so in the CONFIGURATION section. - **An empty result is the existing empty-input error.** A filelist naming nothing that exists produces its warnings and then `no Verilog files found`, exit 2 — the same answer `lucisv empty-dir/` has always given. - **`-f` is not `-F`.** vcs's `-F` (paths relative to the *invoking* directory rather than to the filelist) is not supported, exactly as M1 left it. Nobody has asked. ## Handshakes ### Consumed - `lucisv_core::filelist::read(&Path) -> Result` — unchanged, used exactly as the server uses it. Only `files` and `warnings` are read: `incdirs` and `defines` are meaningless to a formatter that does not preprocess, and are dropped. - `lucisv_core::walk::collect_files` / `config::Discovery` — unchanged. Filelist files skip `collect_files` entirely (they are exact paths, and running them through it would only re-`is_file()` them), but they go through `Discovery::for_file` in the same loop as every other file, so a listed file is formatted with its *own* directory's `lucisv.toml`. ### Promised - **The frozen exit-code contract is untouched.** 0 nothing to do, 1 `--check`/`--diff` would reformat or `check` found violations, 2 error. Filelist warnings are none of those three; the only new exit-2 cases are usage errors (an unreadable filelist, `-f` with no value, `-` or `--lines` with `-f`). - **stdout stays machine-readable.** Every warning goes to stderr, so `lucisv check --output-format json -f p.f` still prints exactly one JSON array on stdout. Pinned by a test. - **`Options` gains `filelists: Vec`** (`crates/lucisv/src/args.rs`). Anything constructing an `Options` literal needs the field; nothing outside `crates/lucisv` does. ### Rejected combinations (all exit 2, all decided at parse time) | Command line | Why | |---|---| | `lucisv -f p.f -` | stdin is one anonymous buffer; a filelist is a set of paths on disk. Reading both would mean ignoring one. | | `lucisv --lines 3-9 -f p.f` | Same reason `--lines` rejects a directory: line numbers name lines of *a file*, and a filelist is a file set. | | `lucisv -f` | Missing flag value, like every other flag. | Everything else about a run is unchanged by `-f`: the cache, `--threads`, `--stdout`, `--diff`, `--fix`, config discovery and the summary line all behave exactly as they do for a file named as an argument. ## Status / TODO - [x] `-f ` on `lucisv`, `lucisv format`, `lucisv --check/--diff` and `lucisv check`; repeatable; combines with positional inputs - [x] Warnings to stderr as `warning: ...`, exit code unaffected; unreadable filelist is exit 2 with nothing processed - [x] Listed paths bypass `--exclude` and `.gitignore`, like named files - [x] Dedup across filelists, positional files and directory walks - [x] `-` and `--lines` rejected with `-f`; empty result is the existing "no Verilog files found" error - [x] `--help`: usage line, `-f` entry, a `FILELISTS:` section, `--lines` wording, and the CONFIGURATION note that the `filelist` key stays server-only - [x] `README.md`: `-f` in the CLI examples and in the configuration section - [x] Tests: 3 unit (2 `args.rs`, 1 `main.rs`) + 10 e2e (`crates/lucisv/tests/cli.rs`); `cargo fmt`, `cargo clippy --all-targets`, `cargo test --workspace` - [ ] Not done, deliberately: the `lucisv.toml` `filelist` key is still not read by the CLI (Assumptions), and `+incdir+`/`+define+` still feed nothing on this side — the formatter and the linter do not preprocess. - [ ] Not done, deliberately: no `-F`, and no quoting for paths containing whitespace (both inherited non-goals from `filelist`). ## Work log ### 2026-08-25 — dev agent, M13 Three files of code, all in `crates/lucisv`. - **`src/args.rs`** — `Options::filelists`, the `-f` arm (placed before the `s if s.starts_with('-')` catch-all so it is a flag, not an unknown option), the emptiness check widened to "no inputs *and* no filelists", and the two rejected combinations. Both rejections live in `parse_from` rather than in `gather`, so they are cheap unit tests and so `lucisv -f p.f -` cannot reach the stdin path at all: `is_stdin()` is checked before `gather` in `main`, and a run that read stdin while ignoring `-f` would be the silent-wrong answer this feature exists to avoid. - **`src/main.rs`** — `filelist_files` (read each list in flag order, print its warnings, collect its files), `dedup` and `absolute`, and three lines in `gather`. Filelist files are appended *after* the positional inputs' walk, so a file named both ways keeps the shorter spelling the user typed. - **`tests/cli.rs`** — the e2e block at the end of the file. Decisions worth recording: - **`gather` prints the warnings itself.** It is the only place in `gather` that says anything, and the doc comment says why: the warnings have to be visible on a run that *succeeds*, and returning them would mean changing `gather`'s signature and both of its callers to thread a `Vec` through to a printing site that does nothing else. `gather` already runs once, serially, before the pool exists, so there is no ordering hazard — every warning is on stderr before the first file is touched. - **Dedup is global, not filelist-vs-command-line.** It was tempting to dedup only across the two sources, but the same `HashSet` costs nothing and fixes a pre-existing sharp edge: `lucisv rtl/ rtl/a.sv` used to format `a.sv` twice and count it twice, and with `--threads > 1` two workers could hold the same path. **This is a behavior change beyond the flag** — a run naming one file twice now reports `1 file`, not `2` — and it is the only one. No existing test asserted the old count. - **A fourth copy of `normalize` was not written; a third one was.** `absolute` in `main.rs` is the same twelve lines as `filelist::Reader::normalize` and `config::Discovery::absolute`, which QA already examined once and accepted as deliberate duplication (filelist QA log, Finding 3). The alternative was widening `lucisv_core`'s public API with a `pub fn normalize(path, cwd)` for a single caller, which CLAUDE.md's "don't build the abstraction for a second user that doesn't exist" rule and the "don't touch files outside your feature's scope" rule both argue against. Recorded here so a future third caller knows to extract it. Unlike the other two, this copy is *only* a dedup key: the path lucisv reads, writes and reports is always the one it was given. - **`--lines` with `-f` is a new error, not a new behavior.** Today `--lines` only rejects a *directory*; a filelist would have been accepted and would have applied "line 12" to all 400 files. Rejecting matches the spirit of the existing rule, and the message is worded like it. - **The `+incdir+`/`+define+` a filelist carries are dropped without a word.** They are not warnings — `filelist::read` accepts them silently and the CLI simply has no use for them. Saying "ignoring +incdir+" on every run of every real filelist would be noise. **Files touched outside `crates/lucisv`**: two, both documentation this change makes untrue and both edited in the style each file already uses. `README.md` — the CLI example block and the configuration section's "the CLI does not consume it yet". `docs/features/filelist/README.md` — its Status item "the CLI does not consume `filelist` yet ... a `lucisv -f` flag is its own change", struck through and answered the same way that README already resolved its `+incdir+` item after M10. `TODO.md` and the umbrella checklist were left for the lead, per the brief — M13's box is still unchecked. **Verification.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` silent; `cargo test --workspace` green — 1556 tests, 13 of them new (2 unit in `args.rs`, 1 in `main.rs` pinning the dedup key, 10 e2e in `tests/cli.rs`: `crates/lucisv`'s two suites went 30 → 33 and 71 → 81). The e2e set covers: `-f` alone with a nested `-f` and relative resolution; `-f` plus positional files and a directory with triple dedup; two `-f` flags; a missing listed file (warning on stderr, others formatted, exit 0) and an unknown option; an unreadable filelist (exit 2, nothing written); `--check` with `-f` (exit 1, then exit 0 once formatted); `lucisv check -f` in text and JSON form (stdout is one array, warnings on stderr); a filelist named from an unrelated working directory; a listed file that both `--exclude` and `.gitignore` name; and the four usage errors. Also hand-driven against the built binary from two different working directories before the tests were written. ## QA log ### 2026-08-25 — QA agent, M13 **Gates.** `cargo fmt --all -- --check` clean, `cargo clippy --all-targets --workspace` silent, `cargo test --workspace` green — **1556 tests**, matching the Work log's count exactly (0 failed, 4 pre-existing `#[ignore]` elsewhere, unrelated to this feature). **Exit-code contract audit.** Built `target/release/lucisv` and drove the matrix by hand: clean file via `-f` → 0; would-reformat via `-f --check` → 1; lint violation via `check -f` → 1; a filelist naming only a missing file → warning + `no Verilog files found` → **2** (empty-after-skip, matching Assumptions' "An empty result is the existing empty-input error" — confirmed this is the answer, not a bare 0-with-warning); a missing file *alongside* a present one → warning + the present file processed, exit 0; unreadable root filelist → 2, nothing written (`nope.f` named in the message); a listed file with a genuine parse error → 2, `1 file failed to format`; `--check` with one file erroring and one that would reformat → 2, both lines printed, error outranks the would-reformat count in the exit code. All eight cells match `README.md`'s frozen 0/1/2 table exactly. Nothing here reaches an exit code outside {0,1,2}. **Claims verified directly, all pass:** - `-f` repeatable, combines with positional inputs, `-f` alone is a valid complete command line (`args.rs:378`, tested live). - Dedup: `lucisv --check rtl/ rtl/a.sv` reports `a.sv` exactly once and the summary reads `2 files would be reformatted` for a 2-file tree, not 3 — confirmed the behavior change is real and works as claimed. - First-spelling-wins is honored across sources, not just within one: `lucisv --check -f p.f rtl/a.sv` (filelist lists `rtl/a.sv`, positional arg also names it) reports `rtl/a.sv`, never the filelist's absolute resolution — matches the Assumptions' worked example verbatim. - Warnings go to stderr only, never touch the exit code: missing listed file, unknown `-y` flag, `$VAR`, filelist-lists-itself all produced `warning: ...` on stderr with the run otherwise succeeding. - `check -f --output-format json`: stdout is exactly one parseable JSON array (piped through `python3 -m json.load`, 2 entries) with the missing- file warning only on stderr. Text-mode `check -f` likewise. - `lucisv.toml`'s `filelist` key: `--help`'s CONFIGURATION section says "read by lucisv-server only" as claimed; the CLI never opens the key (unchanged from before this feature — not separately re-verified beyond reading the help text and the diff, since the CLI simply never reads `FileConfig::filelist` anywhere in `crates/lucisv`). - `-f` + `-`, `--lines` + `-f`, bare `-f`: all three rejected at parse time, exit 2, with the exact messages the README's Rejected-combinations table promises. - `--fix`, `--stdout` (multi-file, concatenated — pre-existing behavior, unaffected by `-f`), `--threads 1` vs default (`--stdout` output byte-identical across thread counts), and the cache (`--check -f` twice: second run reports `1 file from cache`) all behave exactly as they do for a file named directly, as promised. - CRLF filelist: works with no special-casing needed, `str::lines()` already strips `\r` (same as M1's own QA finding). - `$VAR` expansion to an absolute path: works (first attempt was a shell quoting mistake on my end, not a lucisv bug — corrected and re-run). - A filelist that `-f`s itself: one warning, no infinite loop, its own file still processed once. - Usage errors: `-f` with no value → `error: -f requires a value`, exit 2. Repeated identical `-f list.f -f list.f` → deduped, one file reported, not two. `lucisv -- -f` → `error: unknown option: --`, exit 2 — lucisv has no `--` end-of-options handling anywhere (pre-existing, not part of this feature's scope; noting only because the brief asked). **Finding 1 (Medium, not a blocker) — the dedup note overclaims what it fixes, and the underlying write is non-atomic; both predate M13.** `main.rs:344` dedups by **lexical** absolute path only (confirmed by reading `absolute()`, `main.rs:354-367`: pure `.`/`..` component folding, no `fs::canonicalize`, no symlink resolution — matches `filelist::Reader:: normalize` and `config::Discovery::absolute` exactly, as documented). Reproduced directly: a real file and a symlink alias to it, named through two different spellings (`rtl/a.sv` positional + `alias.sv` via `-f`, `alias.sv -> rtl/a.sv`), are **not** deduped — both are queued and both get formatted independently: ``` $ lucisv --check rtl/a.sv -f list.f # list.f names alias.sv, a symlink to rtl/a.sv would reformat: rtl/a.sv would reformat: /.../alias.sv 2 files would be reformatted ``` Separately, `process_file` (`main.rs:255`) and the `--fix` write path (`lint.rs:103`) both write with plain `std::fs::write(file, &out)` — open-truncate-write, **not** tempfile+rename. `cache.rs:91` sits right next to this code and *does* the atomic tempfile+rename dance, with a doc comment explicitly saying "Writes the cache back, atomically" — so the codebase already has the pattern, just not applied to the file the user actually asked lucisv to rewrite. Put together: two workers (`--threads > 1`) that land on the same inode through two spellings — a symlink pair being the realistic case, since lexical dedup already closes the plain-duplicate-path case this milestone set out to fix — can, if their `open(O_TRUNC)`/`write` calls interleave, produce a torn file that is neither worker's intended output. This is a real instance of the class of bug hard invariant 1 rules out ("never corrupt code... no partial output"), not a hypothetical. **Severity assessment, honestly:** this is **not new in M13** and **not worsened by it**. Before this milestone there was no dedup at all, so `lucisv a.sv a.sv` (no symlink needed) already put two workers on one path under `--threads > 1`, and a symlinked pair had exactly the same exposure `collect_files` never resolves symlinks either (`walk.rs`, confirmed by reading it — no `canonicalize`/`read_link` anywhere in `lucisv_core`). M13's dedup is a strict improvement: it closes the common, likely case (the same literal path named twice) that used to double-process on every run of `lucisv rtl/ rtl/a.sv`; it was never advertised as closing the symlink case, and the README's own Assumptions section says so precisely ("symlinks deliberately not resolved"). What I'd push back on is only the Work log's framing — "fixes a pre-existing sharp edge... two workers could hold the same path" reads as though the write-race is handled, when only its most common trigger is. I did not manage to force an actual observed corruption in a 15-round, 40-pair, 8-thread stress test (APFS on this machine appears to serialize small concurrent writes to one inode closely enough in practice that the window didn't get hit) — absence of a repro in a best-effort black-box run is not proof the window can't be hit on slower storage, larger files, or a different OS/filesystem, so I'm not downgrading this to "theoretical." **Not filing this as a blocking finding for M13** — it is outside this feature's stated scope (`process_file`/`lint.rs` weren't touched here, and CLAUDE.md's "don't touch files outside your feature's scope" cuts against fixing it inside this change), it predates M13, and M13 does not make it worse. Recommend two follow-ups for the backlog, independent of each other: (1) make the source-file write atomic (tempfile+rename, mirroring `cache.rs:91`) — this alone would make even a two-worker race benign, since a rename is atomic and both workers produce byte-identical content; (2) optionally widen the dedup key to a canonicalized path for a second line of defense. (1) is the one that actually satisfies hard invariant 1 under concurrent access; (2) only narrows how often (1) would matter. Suggest the Work log's "two workers could hold the same path" sentence be softened to say the fix is for the literal-duplicate case, not the general one, since a future reader could otherwise believe the race is closed. **Finding 2 (trivial, accepted, not filed as a real finding) — third copy of the lexical normalizer.** `main.rs:354-367`'s `absolute()` is confirmed byte-for-byte-equivalent in logic to `filelist::Reader::normalize` and `config::Discovery::absolute`. This is the same duplication QA already examined and accepted once (`docs/features/filelist/README.md`, QA Finding 3); the dev's Work log correctly cites that precedent, and CLAUDE.md's "don't build the abstraction for a second user that doesn't exist" cuts the same way here as it did there. Agree with leaving it; flag for extraction if and when a fourth caller appears, as the Work log itself already says. **+incdir+/+define+ silent drop: agree, reasoning holds for `check` too.** Verified by reading `filelist_files` (`main.rs:328-338`): only `list.files` and `list.warnings` are ever read; `list.incdirs`/`list.defines` are untouched anywhere in `crates/lucisv`. Checked whether any M12 lint rule (`crates/vlog_linter/src/rules/`) consults an include graph or any cross-file state — grepped the whole crate for `incdir`/`include_graph`/ `cross-file`/`workspace`: zero hits. Every existing linter rule operates on one file's own parse tree (confirmed by `context.rs`/`visit.rs` taking a single source and no include resolver). `` `include`` resolution using `incdirs` is M10's, and lives entirely in `lucisv_server` — the CLI has never resolved includes at all, filelist-fed or not. So the reasoning "lucisv doesn't preprocess, so incdirs genuinely don't matter" holds for the linter exactly as it does for the formatter; nothing in M12 would have consulted them even if they were threaded through. **No fixes applied.** Nothing here rose to "small unambiguous fix" — the overclaim is a wording issue in the Work log's prose (the lead's call whether to soften it), and the write-atomicity gap is a real but out-of-scope design change, not a typo. **Verdict: ship.** Every claim in the Handshakes/Status/Assumptions sections checks out against the code and against the exit-code contract under direct adversarial testing; all three gates are clean at the exact count claimed. Finding 1 is worth a backlog entry (atomic writes, mirroring the pattern already in `cache.rs`) but is pre-existing, not introduced or worsened by this milestone, and fixing it belongs to a change that touches `process_file`/`lint.rs`, which is outside `cli-filelist`'s scope. ## Review **2026-08-25 — lead.** Reviewed after QA's ship verdict; gates run independently (1556 tests, 0 failures). The semantics decisions are the right ones, each argued in place — listed paths bypassing exclude rules matches the positional-arg precedent exactly, the `--lines` + `-f` rejection prevents a silent 400-file surprise, and keeping the lucisv.toml key server-only respects the CLI user who never asked for it. QA's exit-code matrix confirms the frozen contract untouched, including both ambiguous cells. QA's medium find — lexical-only dedup plus non-atomic `fs::write`, a torn-file window that predates M13 and that M13 narrows rather than widens — is real and now filed in TODO.md §1 as its own correctness item (atomic tempfile+rename writes, mirroring cache.rs). The third normalizer copy is accepted per the no-abstraction-for-a- second-user rule, third time consistent. Accepted; M13 checked off.