Doc Rigor
Overview
Produce documentation that lets a new reader grok the code without reading every
line, then verify every claim against code reality with a fresh agent. Treat
comments as first-class: explain intent, invariants, and trade-offs, not syntax.
The writer and verifier never share context — the verifier only sees the code and
whatever the writer produced, not what the writer intended.
When to Use
- After writing or modifying code that needs documentation
- To improve comments, docstrings, or module-level docs
- To explain algorithms, design choices, or non-obvious reasoning
- Before merging branches that touch public APIs or complex internals
When NOT to Use
- Reviewing code logic — use
/review-dispatch
- Verifying dist-sys claims — use
/dist-sys-auditor
- Checking API ergonomics — use
/interface-design-review
- Only verifying existing docs (no writing) — use
/doc-verify directly
Invocation
/doc-rigor [files]
- With no argument: target recently changed files (unstaged + staged)
- With file paths: target those specific files
- With a directory: target all
.rs files in that directory
Flags
| Flag |
Effect |
--skip-verify |
Skip verification phase (write only, no agent 2) |
--code-only |
Passed to verify phase: skip external claim verification |
--strict |
Passed to verify phase: promote all WARNs to BLOCKs |
--summary |
Passed to verify phase: output only the summary table |
Phase 1: Scope Resolution (Invoking Agent)
The invoking agent performs these steps before launching subagents:
1. Identify Target Files
- If files are specified: use those
- If no argument: run
git diff --name-only HEAD and git diff --cached --name-only
to find recently changed .rs files
- Filter to
.rs files only
2. Read File Contents
- Read each target file in full
- Read adjacent module files (siblings in the same directory) for context —
the writer needs surrounding types, traits, and functions
3. Parse Flags
Extract any flags from the invocation. Route --skip-verify, --code-only,
--strict, and --summary to the appropriate phase.
4. Check for References
If the project has references/documentation-style.md, read it — it will be
passed to the doc-writing agent as a style reference.
Phase 2: Doc Writing (Agent 1 — general-purpose subagent)
Launch 1 agent using the Task tool with subagent_type="general-purpose".
Writer Agent Prompt
Include in the prompt:
- Full contents of every target file
- Full contents of adjacent module files (marked as context, not to be edited)
- Style reference (if
references/documentation-style.md exists)
- The complete writer instructions below
Writer Instructions
You are a documentation specialist. Your job is to write and improve
documentation for Rust code following the doc-rigor methodology.
## Target Files
{FULL_FILE_CONTENTS}
## Adjacent Context (for reference, do NOT edit these)
{ADJACENT_FILE_CONTENTS}
{STYLE_REFERENCE — include only if references/documentation-style.md exists}
## Your Task
Produce documentation that lets a new reader grok the code without reading
every line. Treat comments as first-class: explain intent, invariants, and
trade-offs, not syntax.
### Workflow
1. **Read for intent** — Identify the core problem, invariants, and boundaries
of each module/type/function. Mark non-obvious logic, algorithms, and design
decisions that need explanation.
2. **Draft a documentation map** — Decide which scopes need docs: module-level,
type-level, function-level, or inline. Prefer fewer, richer comments over
many shallow ones.
3. **Write documentation in layers**:
- Module-level docs: purpose, invariants, high-level algorithm, references.
- Type/function docs: guarantees, preconditions, side effects, errors,
complexity.
- Inline comments only for local, tricky reasoning (why now, why this order,
why this bound).
4. **Enforce rigor**:
- Remove comments that restate code or obvious control flow.
- Check for consistency with code and tests; update docs when behavior
changes.
- Call out any missing context you cannot infer.
### Comment Content Checklist
Every doc you write should cover the applicable items:
- Problem statement and scope
- Invariants and safety/soundness rules
- Algorithm overview with key steps and why they matter
- Design trade-offs (why this approach vs alternatives)
- Edge cases and failure modes
- Complexity or performance constraints when relevant
- Concrete examples when behavior is subtle
### Rust-Specific Guidance
- Use `//!` for module-level docs, `///` for items, `//` for inline reasoning
- For unsafe code, add a `# Safety` section describing required invariants
- Include `# Examples` in public APIs if usage is non-obvious
### Rules
- Edit the target files directly using the Edit tool
- Do NOT edit adjacent context files
- Do NOT add tracking IDs, issue references, or external tracker info in comments
- Do NOT add version suffixes, deprecated annotations, or compatibility shims
- Focus on WHY, not WHAT — do not restate what the code already says
- Be factually precise — every claim in a doc comment must be true
### Output
After editing all files, provide a summary listing:
- Files edited
- Types of docs added/improved (module, type, function, inline)
- Any gaps you could not fill due to missing context
Collecting Writer Results
When the writer agent completes:
- Capture its summary (files edited, docs added, gaps noted)
- Re-read the target files from disk — the writer has edited them, and the
verifier needs the updated contents, not the pre-edit versions
- Also re-read adjacent module files (they were not edited but provide context
for verification)
Phase 3: Doc Verification (Agent 2 — fresh general-purpose subagent)
Skip this entire phase if --skip-verify flag is active.
Agent Isolation — Non-Negotiable
Invoking Agent (orchestrator)
|
+--> Agent 1: Doc-Rigor Writer (writes/improves docs)
| |
| [docs are written to files]
|
+--> Agent 2: Doc-Verify Checker (verifies docs against code)
|
[verification report]
- Agent 2 runs as a separate
general-purpose subagent with zero
knowledge of what Agent 1 intended. It receives only the current file
contents (code + docs as they exist on disk after Agent 1's edits) and
verifies every claim against code reality.
- Why: The verifier must not know what the writer meant to say — only what
they did say. This eliminates confirmation bias. A writer who knows they
intended "returns None on empty" will not catch that the code actually panics.
A fresh verifier will.
- Never inline both phases in the same agent context. Always use two
separate Task agents.
Verification Agent Prompt
Include in the prompt:
- Full contents of every target file (post-edit, re-read from disk)
- Full contents of adjacent module files
- Active flags (
--code-only, --strict, --summary)
- The complete verification instructions from
references/verification-methodology.md
The verification agent follows Steps A through E from the methodology reference:
- Extract all testable claims from doc comments, categorized across 11
claim types (Behavioral, Invariant, Type/Structural, Count, Relationship,
Precondition/Postcondition, Complexity, Performance, Safety, External,
Negative)
- Verify code-level claims by tracing actual code paths, counting real
fields/variants, checking call graphs, and validating safety invariants
- Identify external claims referencing algorithms, papers, libraries,
standards, or cryptographic properties
- Verify external claims against authoritative sources (unless
--code-only)
- Produce findings with severity classification and structured report
See references/verification-methodology.md for the complete procedure,
category definitions, verification steps per category, and output format template.
Severity Tiers
- BLOCK: Factually wrong, incorrect safety comment, false external claim,
count off by more than 1, behavioral claim opposite of reality
- WARN: Misleading, stale count (off by 1), stale structural claim,
unverifiable external, ambiguous invariant, unenforced precondition
- INFO: Imprecise language, slightly stale wording, missing doc
Verdict
- FAIL: Any BLOCKs exist
- PASS WITH WARNINGS: WARNs but no BLOCKs
- PASS: All claims verified correct
Phase 4: Presentation (Invoking Agent)
After both agents complete, present a combined report to the user.
1. Writer Summary
Briefly state what the doc-rigor agent did:
- Which files were edited
- What types of documentation were added or improved
- Any gaps the writer noted
2. Verification Report
Present the verification agent's findings directly. Do not filter or soften them.
- If verdict is FAIL: Highlight all BLOCKs at the top. Emphasize that the
documentation edits contain factual errors that must be corrected.
- If verdict is PASS WITH WARNINGS: Note warnings that should be addressed.
- If verdict is PASS: Confirm that all documentation claims verified against
code reality.
If --skip-verify was active, note that verification was skipped and recommend
running /doc-verify separately.
3. Next Steps
Based on the verification result:
- FAIL: Suggest running
/execute-review-findings to fix BLOCKs, then
re-running /doc-verify to confirm fixes.
- PASS WITH WARNINGS: List the WARNs as follow-up items.
- PASS: Documentation is ready.
Use References
- Read
references/documentation-style.md for documentation patterns and
templates when the user wants high-rigor style or asks to mirror a
well-documented crate.
- Read
references/verification-methodology.md for the complete verification
procedure including claim categories, per-category verification steps, severity
definitions, and output format template.
Related Skills
/doc-verify — standalone verification against code reality. Use when docs
already exist and only need accuracy checking (no writing phase).
/execute-review-findings — implements fixes for BLOCK findings from
verification reports.
/review-dispatch — multi-lens code review (broader than docs).
/dist-sys-auditor — specialized for distributed systems claims with
citations.
1---2name: doc-rigor3description: Write-then-verify documentation pipeline. Use when a user asks to improve comments or docs, explain algorithms or design choices, write or upgrade docstrings, or raise documentation quality for a codebase (especially Rust crates). Writes docs, then automatically verifies every claim against code reality using a fresh agent to eliminate confirmation bias.4---5
6# Doc Rigor
7
8## Overview
9
10Produce documentation that lets a new reader grok the code without reading every
11line, then verify every claim against code reality with a fresh agent. Treat
12comments as first-class: explain intent, invariants, and trade-offs, not syntax.
13The writer and verifier never share context — the verifier only sees the code and
14whatever the writer produced, not what the writer intended.
15
16## When to Use
17
18- After writing or modifying code that needs documentation
19- To improve comments, docstrings, or module-level docs
20- To explain algorithms, design choices, or non-obvious reasoning
21- Before merging branches that touch public APIs or complex internals
22
23## When NOT to Use
24
25- **Reviewing code logic** — use `/review-dispatch`
26- **Verifying dist-sys claims** — use `/dist-sys-auditor`
27- **Checking API ergonomics** — use `/interface-design-review`
28- **Only verifying existing docs** (no writing) — use `/doc-verify` directly
29
30---
31
32## Invocation
33
34```
35/doc-rigor [files]
36```
37
38- With no argument: target recently changed files (unstaged + staged)
39- With file paths: target those specific files
40- With a directory: target all `.rs` files in that directory
41
42### Flags
43
44| Flag | Effect |
45|------|--------|
46| `--skip-verify` | Skip verification phase (write only, no agent 2) |
47| `--code-only` | Passed to verify phase: skip external claim verification |
48| `--strict` | Passed to verify phase: promote all WARNs to BLOCKs |
49| `--summary` | Passed to verify phase: output only the summary table |
50
51---
52
53## Phase 1: Scope Resolution (Invoking Agent)
54
55The invoking agent performs these steps before launching subagents:
56
57### 1. Identify Target Files
58
59- If files are specified: use those
60- If no argument: run `git diff --name-only HEAD` and `git diff --cached --name-only`
61 to find recently changed `.rs` files
62- Filter to `.rs` files only
63
64### 2. Read File Contents
65
66- Read each target file in full
67- Read adjacent module files (siblings in the same directory) for context —
68 the writer needs surrounding types, traits, and functions
69
70### 3. Parse Flags
71
72Extract any flags from the invocation. Route `--skip-verify`, `--code-only`,
73`--strict`, and `--summary` to the appropriate phase.
74
75### 4. Check for References
76
77If the project has `references/documentation-style.md`, read it — it will be
78passed to the doc-writing agent as a style reference.
79
80---
81
82## Phase 2: Doc Writing (Agent 1 — general-purpose subagent)
83
84Launch **1 agent** using the Task tool with `subagent_type="general-purpose"`.
85
86### Writer Agent Prompt
87
88Include in the prompt:
89- Full contents of every target file
90- Full contents of adjacent module files (marked as context, not to be edited)
91- Style reference (if `references/documentation-style.md` exists)
92- The complete writer instructions below
93
94### Writer Instructions
95
96```
97You are a documentation specialist. Your job is to write and improve
98documentation for Rust code following the doc-rigor methodology.
99
100## Target Files
101
102{FULL_FILE_CONTENTS}
103
104## Adjacent Context (for reference, do NOT edit these)
105
106{ADJACENT_FILE_CONTENTS}
107
108{STYLE_REFERENCE — include only if references/documentation-style.md exists}
109
110## Your Task
111
112Produce documentation that lets a new reader grok the code without reading
113every line. Treat comments as first-class: explain intent, invariants, and
114trade-offs, not syntax.
115
116### Workflow
117
1181. **Read for intent** — Identify the core problem, invariants, and boundaries
119 of each module/type/function. Mark non-obvious logic, algorithms, and design
120 decisions that need explanation.
121
1222. **Draft a documentation map** — Decide which scopes need docs: module-level,
123 type-level, function-level, or inline. Prefer fewer, richer comments over
124 many shallow ones.
125
1263. **Write documentation in layers**:
127 - Module-level docs: purpose, invariants, high-level algorithm, references.
128 - Type/function docs: guarantees, preconditions, side effects, errors,
129 complexity.
130 - Inline comments only for local, tricky reasoning (why now, why this order,
131 why this bound).
132
1334. **Enforce rigor**:
134 - Remove comments that restate code or obvious control flow.
135 - Check for consistency with code and tests; update docs when behavior
136 changes.
137 - Call out any missing context you cannot infer.
138
139### Comment Content Checklist
140
141Every doc you write should cover the applicable items:
142
143- Problem statement and scope
144- Invariants and safety/soundness rules
145- Algorithm overview with key steps and why they matter
146- Design trade-offs (why this approach vs alternatives)
147- Edge cases and failure modes
148- Complexity or performance constraints when relevant
149- Concrete examples when behavior is subtle
150
151### Rust-Specific Guidance
152
153- Use `//!` for module-level docs, `///` for items, `//` for inline reasoning
154- For unsafe code, add a `# Safety` section describing required invariants
155- Include `# Examples` in public APIs if usage is non-obvious
156
157### Rules
158
159- Edit the target files directly using the Edit tool
160- Do NOT edit adjacent context files
161- Do NOT add tracking IDs, issue references, or external tracker info in comments
162- Do NOT add version suffixes, deprecated annotations, or compatibility shims
163- Focus on WHY, not WHAT — do not restate what the code already says
164- Be factually precise — every claim in a doc comment must be true
165
166### Output
167
168After editing all files, provide a summary listing:
169- Files edited
170- Types of docs added/improved (module, type, function, inline)
171- Any gaps you could not fill due to missing context
172```
173
174### Collecting Writer Results
175
176When the writer agent completes:
177
1781. Capture its summary (files edited, docs added, gaps noted)
1792. **Re-read the target files from disk** — the writer has edited them, and the
180 verifier needs the updated contents, not the pre-edit versions
1813. Also re-read adjacent module files (they were not edited but provide context
182 for verification)
183
184---
185
186## Phase 3: Doc Verification (Agent 2 — fresh general-purpose subagent)
187
188**Skip this entire phase if `--skip-verify` flag is active.**
189
190### Agent Isolation — Non-Negotiable
191
192```
193Invoking Agent (orchestrator)
194 |
195 +--> Agent 1: Doc-Rigor Writer (writes/improves docs)
196 | |
197 | [docs are written to files]
198 |
199 +--> Agent 2: Doc-Verify Checker (verifies docs against code)
200 |
201 [verification report]
202```
203
204- **Agent 2** runs as a **separate** `general-purpose` subagent with **zero
205 knowledge** of what Agent 1 intended. It receives only the current file
206 contents (code + docs as they exist on disk after Agent 1's edits) and
207 verifies every claim against code reality.
208- **Why**: The verifier must not know what the writer *meant* to say — only what
209 they *did* say. This eliminates confirmation bias. A writer who knows they
210 intended "returns None on empty" will not catch that the code actually panics.
211 A fresh verifier will.
212- **Never** inline both phases in the same agent context. **Always** use two
213 separate Task agents.
214
215### Verification Agent Prompt
216
217Include in the prompt:
218- Full contents of every target file (post-edit, re-read from disk)
219- Full contents of adjacent module files
220- Active flags (`--code-only`, `--strict`, `--summary`)
221- The complete verification instructions from `references/verification-methodology.md`
222
223The verification agent follows Steps A through E from the methodology reference:
224
2251. **Extract all testable claims** from doc comments, categorized across 11
226 claim types (Behavioral, Invariant, Type/Structural, Count, Relationship,
227 Precondition/Postcondition, Complexity, Performance, Safety, External,
228 Negative)
2292. **Verify code-level claims** by tracing actual code paths, counting real
230 fields/variants, checking call graphs, and validating safety invariants
2313. **Identify external claims** referencing algorithms, papers, libraries,
232 standards, or cryptographic properties
2334. **Verify external claims** against authoritative sources (unless `--code-only`)
2345. **Produce findings** with severity classification and structured report
235
236See `references/verification-methodology.md` for the complete procedure,
237category definitions, verification steps per category, and output format template.
238
239### Severity Tiers
240
241- **BLOCK**: Factually wrong, incorrect safety comment, false external claim,
242 count off by more than 1, behavioral claim opposite of reality
243- **WARN**: Misleading, stale count (off by 1), stale structural claim,
244 unverifiable external, ambiguous invariant, unenforced precondition
245- **INFO**: Imprecise language, slightly stale wording, missing doc
246
247### Verdict
248
249- **FAIL**: Any BLOCKs exist
250- **PASS WITH WARNINGS**: WARNs but no BLOCKs
251- **PASS**: All claims verified correct
252
253---
254
255## Phase 4: Presentation (Invoking Agent)
256
257After both agents complete, present a combined report to the user.
258
259### 1. Writer Summary
260
261Briefly state what the doc-rigor agent did:
262- Which files were edited
263- What types of documentation were added or improved
264- Any gaps the writer noted
265
266### 2. Verification Report
267
268Present the verification agent's findings directly. Do not filter or soften them.
269
270- **If verdict is FAIL**: Highlight all BLOCKs at the top. Emphasize that the
271 documentation edits contain factual errors that must be corrected.
272- **If verdict is PASS WITH WARNINGS**: Note warnings that should be addressed.
273- **If verdict is PASS**: Confirm that all documentation claims verified against
274 code reality.
275
276If `--skip-verify` was active, note that verification was skipped and recommend
277running `/doc-verify` separately.
278
279### 3. Next Steps
280
281Based on the verification result:
282
283- **FAIL**: Suggest running `/execute-review-findings` to fix BLOCKs, then
284 re-running `/doc-verify` to confirm fixes.
285- **PASS WITH WARNINGS**: List the WARNs as follow-up items.
286- **PASS**: Documentation is ready.
287
288---
289
290## Use References
291
292- Read `references/documentation-style.md` for documentation patterns and
293 templates when the user wants high-rigor style or asks to mirror a
294 well-documented crate.
295- Read `references/verification-methodology.md` for the complete verification
296 procedure including claim categories, per-category verification steps, severity
297 definitions, and output format template.
298
299---
300
301## Related Skills
302
303- `/doc-verify` — standalone verification against code reality. Use when docs
304 already exist and only need accuracy checking (no writing phase).
305- `/execute-review-findings` — implements fixes for BLOCK findings from
306 verification reports.
307- `/review-dispatch` — multi-lens code review (broader than docs).
308- `/dist-sys-auditor` — specialized for distributed systems claims with
309 citations.