The corpus-measured #1 blocker (~60% of RTL parse errors). Macro invocations (`NAME, `NAME(args), optional trailing ;) now parse wherever a module item or statement can appear; the invocation is an AST leaf (MacroCall{RawText, semi}) emitted verbatim with column- aware re-indent, semicolon reproduced only if written. Disambiguation is safe by construction: both readings emit identical token streams. The lexer's balanced-arg scan is hardened (strings, comments, 256-cap nesting counter, iterative). Corpus parse rate: 35.2% -> 57.1% (179 files gained, 0 regressed). Round 1 was rejected in review: QA proved the new verify.rs normalization could mask real corruption -- a string literal spanning lines inside a macro arg had its bytes changed by re-indent, with exit 0. The rework widened the finding to `define bodies and attributes (same pre-existing defect, same shared root) and fixed both sides: line_starts_inside_string, a lexer-mirroring scanner, is the single shared definition of "which line breaks are data" -- the verifier trims only outside strings, and the formatter emits any token with an in-string line break fully verbatim (idempotent by construction). Re-QA attacked the scanner on ten edge shapes and found no hole; corpus TSV byte-identical pre/post fix. Process consequence, codified as CLAUDE.md hard-invariant #4: any widening of verify.rs forgiveness ships with masked-corruption attack tests, dev-written and QA-re-attacked. Dev + rework: Opus agent; QA + re-QA: Sonnet agent; full history in docs/features/macro-items/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
89 lines
3.9 KiB
Markdown
89 lines
3.9 KiB
Markdown
# CLAUDE.md — rules for all agents working on vfmt
|
|
|
|
vfmt 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)
|
|
|
|
1. **Never corrupt code.** The formatter either produces verified-correct
|
|
output or emits the input unchanged with an error. No partial output.
|
|
2. **Idempotent.** `format(format(x)) == format(x)`, always.
|
|
3. **Comments are never dropped.**
|
|
4. **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 vfmt 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).
|
|
|
|
## Rust standards
|
|
|
|
- `cargo fmt` clean, `cargo clippy --all-targets` clean (no `#[allow]`
|
|
without a comment explaining why), `cargo test` green — all three
|
|
before declaring any work finished.
|
|
- No `unwrap()`/`expect()`/`panic!` in library code paths; return
|
|
`Result`. Tests and `main.rs` argument 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:
|
|
|
|
```markdown
|
|
# <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 commit` or `git 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).
|