9.2 KiB
CLAUDE.md — rules for all agents working on lucisv
lucisv is a ruff-style Verilog/SystemVerilog formatter/linter in Rust.
Read README.md for architecture and TODO.md for the backlog before
doing anything.
Hard invariants (never break these)
- Never corrupt code. The formatter either produces verified-correct output or emits the input unchanged with an error. No partial output.
- Idempotent.
format(format(x)) == format(x), always. - Comments are never dropped.
- Any widening of
verify.rs's forgiveness is guilty until proven innocent. Every new or broadened normalization in the safety net ships WITH masked-corruption attack tests (crafted (input, corrupted output) pairs the normalization could plausibly forgive, asserted rejected) — written by the dev, re-attacked by QA. History: the one real corruption lucisv ever produced (macro-items, 2026-08-19) slipped through a normalization added without such tests.
Simplicity first
- Prefer the boring, obvious implementation. If you're building an abstraction for a second user that doesn't exist yet, stop.
- Standard library first. Adding a dependency requires a written justification in the feature README.
- Small functions, descriptive names, shallow nesting. Code should be readable top-to-bottom without jumping around.
- Match the style of the surrounding code (comment density, naming, module layout).
File and function size
Files and functions are sized for a human reader, not a compiler.
- Target 300–600 production lines per file. At 800, consider
splitting. Above 1,200, an explicit reason not to split goes in the
feature README. Test lines do not count, but a
#[cfg(test)]block that dwarfs its file moves to its own module ortests/file. - Functions: 10–50 lines. Investigate anything over 80; anything over 150 needs a reason in a comment (a dispatch table over an enum is the usual one).
- Looser for declarative tables, generated code, snapshots and repetitive tests. Complexity matters more than the count: 800 lines of grammar productions read more easily than 250 lines of state.
- The real test is one sentence. A human should be able to say what a file is responsible for in one sentence and predict which parts a change touches. Several "and" clauses mean the file wants to be several modules.
- A split is a pure move: public paths stay the same (re-export from
the old
mod), behaviour and output stay byte-identical, the test count does not drop. Measured, not asserted — the corpus and opentitan byte-identity gates are the proof.
Measured 2026-09-02 (production lines): vlog_parser/src/parser.rs
8 786, vlog_formatter/src/format.rs 5 444, vlog_parser/src/ast.rs
3 313, lucisv_server/src/server.rs 2 559 (+6 300 test),
vlog_semantic/src/bind.rs 2 378, vlog_semantic/src/workspace.rs
1 975, vlog_refactor/src/ports.rs 1 778,
lucisv_server/src/completion.rs 1 716 — thirteen files over 800.
Every one of them was where feature lanes collided, which is the other
reason to split them. Decomposed the same day by TODO §28 (four
lanes, pure moves, output byte-identical): parser/ (19 modules) and
ast/ (8), format/ (15), server/ (11 + tests) and completion/
(6), bind/ (8), workspace/ (5), ports/ (6), rename/ (4). Measured
after the round (non-blank, non-comment, outside tests): two files over
600 — lucisv_server/src/perf.rs 895 (one cohesive subsystem; the reason
is in the decomposition-server README) and vlog_parser/src/lexer.rs
762 — and 183 under it. Nothing new may push a file back over the
thresholds: a dev adding to a file near 600 puts the code in a new
module.
Re-measured 2026-09-07 at 0.49.0 (same rule, before mod tests): four
files over 600 — lucisv_server/src/state.rs 958 (grew across §37–§49;
a decomposition is filed as TODO §55: scope/widen, the document store,
the source selectors are three sentences), perf.rs 900 (reasoned),
lexer.rs 763, vlog_formatter/src/format/stmt.rs 604 (at the mark; the
next statement arm goes in a new module) — and everything else under it.
Rust standards
cargo fmtclean,cargo clippy --all-targetsclean (no#[allow]without a comment explaining why),cargo testgreen — all three before declaring any work finished.- No
unwrap()/expect()/panic!in library code paths; returnResult. Tests andmain.rsargument handling may use them. - Public items get a one-line doc comment. Doc comments say what/why, not how.
- No
unsafe.
Document-based development
Every feature lives in docs/features/<feature-name>/README.md. That
README is the single source of truth for the feature and must contain
these sections:
# <feature name>
## Goal — one paragraph, what and why
## Assumptions — everything you assumed that isn't enforced by code
## Handshakes — interfaces/contracts with other modules: what you
consume from them, what you promise to them
## Status / TODO — checklist; keep current as you work
## Work log — dated entries by the dev agent: what was done, key
decisions, deviations from plan
## QA log — dated entries by the QA agent: what was verified,
how, and findings
## Review — reserved for the lead; do not write here
Rules:
- Dev agents: create/update the feature README as you work, not at the end. Finished TODOs get checked off in the same README. If you change a handshake another module depends on, say so explicitly in Handshakes and in the work log.
- QA agents: you verify, you don't redesign. Run the checks, try to break the feature, record everything in the QA log. File concrete findings (file:line, reproduction) — not opinions. Small unambiguous fixes (typos, missing test assertion) you may fix directly and note it.
- Review section is written only by the lead agent after examining the work. Respond to review comments by fixing and logging in the work log, not by editing the Review section.
Workflow
- Do not run
git commitorgit push— the lead reviews and commits all work. - Do not touch files outside your feature's stated scope. If you need a change in another module, write it as a request in your README's Handshakes section and stop.
- New behavior needs tests in the same change. Every formatter change
must keep the snapshot + idempotency suite green
(
cargo test -p vlog_formatter). - Update
TODO.md: check items your feature completes (leave the item text intact).
Runaway guard (never run a suite or sweep bare)
On 2026-09-03 a background test run consumed 100 GB and crashed the
machine. macOS enforces no memory cap, so the cap is ours:
tools/guard.sh [-m GB] [-t SECONDS] -- <command> kills a command's
process tree when its resident set or wall clock exceeds the limits
(defaults 8 GB / 30 min).
- Every
cargo test, every fuzzer, every corpus or opentitan sweep, and everylucisv/lucisv-serverrun over a tree goes throughtools/guard.sh— dev, QA and lead alike, foreground or background. - A guard kill is a finding: report the command and the limit it hit; do not raise the limit to make it pass.
Parallel lanes (the 2-agent loop)
Up to two dev/QA lanes may run concurrently when — and only when —
their features do not collide in docs/topo.md: no shared edge between them
(no ──▶, no ◀──▶, and neither touching the same open handshake in
§2.9), and disjoint file sets. docs/topo.md is the authority; if the
collision question is not answerable from it, the features are not
proven independent and run serially. Rules for a parallel wave:
- The lead plans the lanes before anything is dispatched: one brief per lane with an explicit file-ownership list. That list is the merge contract — a lane touches nothing outside it. A needed change to a file the other lane owns (or to any unlisted file) is a Handshake request in the lane's README plus a flag in its report, never a silent edit; the lead rules on it at merge.
- Each lane works in its own git worktree branched from the same trunk commit. Never two agents in one tree. Trunk stays untouched while lanes are in flight; the lead merges each lane back only after that lane's QA verdict and lead review, and re-runs the full gates on the merged tree before pushing.
- Roles per lane are unchanged: one dev (Opus), then one QA (Sonnet) in the same worktree, then the lead's review — so at most 2 devs + 2 QA agents exist at once, and a lane's QA starts only when its own dev is done. A QA rework loops inside its lane without blocking the other lane.
- Tracking lives in
TODO.md: the lead writes the wave's section (one subsection per lane, each item naming its files) on trunk before branching; each lane ticks only its own lines. Shared-by-nature files (TODO.md,docs/perf/README.md) may be appended to by both lanes in their own sections — the lead resolves the trivially-parallel merge; anything worse than trivially-parallel means the lanes were not actually independent, which is a planning failure to record. - After merging, the lead updates
docs/topo.mdfor any edge a lane added or amended, so the next wave plans against reality.