Docs Generator
Generate accurate, low-drift documentation by reading the code, not by guessing.
Core principles
- Read before writing. Open the actual files (types, signatures, call sites) before producing any prose. Never document from memory.
- Match existing style. If the repo already has JSDoc, Google-style pydoc, or TSDoc — follow that exact format. If unsure, ask.
- One source of truth. Prefer extracting from code comments + signatures. Avoid restating behavior that the code already expresses; explain why, not what.
- No hallucinated examples. Every code example must compile against the current codebase. If you can't verify, mark it
<!-- unverified --> and tell the user.
- Keep it in sync. When the user edits code, offer to update the related docs. When the user edits docs, check that the referenced symbols still exist.
Workflow
- Scope. Ask (or infer) what to document: a single function, a module, a package, or the whole repo.
- Inventory. List the public surface: exported symbols, public classes, HTTP routes, CLI commands, config keys. Use
Grep/Glob, not memory.
- Read. Open each relevant file. Note signatures, types, defaults, side effects, and existing comments.
- Draft. Produce docs in the format the user asked for (see Formats below). Keep prose tight; let signatures carry detail.
- Verify. Re-check every symbol name, parameter, and path against the source. Fix any mismatch.
- Write. Save to the agreed location. If a file exists, edit it; otherwise create it.
- Report. Summarize what was generated, what was skipped, and any symbols you couldn't verify.
Formats
README section / file
## `functionName(args)`
Short one-line purpose.
Why it exists or when to use it. Any non-obvious behavior, edge cases,
or performance notes.
\`\`\`ts
import { functionName } from "./module";
functionName(input, { option: true });
\`\`\`
JSDoc / TSDoc
/**
* One-line summary.
*
* Longer explanation when needed. Mention side effects, async behavior,
* or throws conditions.
*
* @param name - What it is. Required/optional.
* @returns What comes back, including shape and null/undefined cases.
* @throws {ErrorName} When this can happen.
*/
Python docstring (Google style)
def fn(name, *, strict=False):
"""One-line summary.
Optional longer description.
Args:
name: Description.
strict: Description. Defaults to False.
Returns:
Description of return value.
Raises:
ValueError: When ...
"""
API reference (REST)
For each endpoint: method, path, auth requirement, request body schema, response schema, example request/response, error codes.
Architecture overview
Module map (one sentence each), data flow, key invariants, where to look for X.
Anti-patterns
- Restating the implementation line-by-line.
- Documenting private helpers unless asked.
- Examples that import symbols that don't exist or aren't exported.
- "See documentation" links that point nowhere.
- Generating docs for code you haven't actually opened in this session.
Additional resources
- For complete format templates (REST, CLI, JSDoc tags, NumPy style, changelog), see reference.md.
- For before/after examples, see examples.md.
Verification checklist
Before finishing, confirm:
1---2name: docs-generator3description: Generate and keep documentation in sync with source code. Produces README sections, API references, JSDoc/docstrings, and architecture overviews directly from the codebase. Use when the user asks to "document this code", "generate API docs", "write a README", "add docstrings", "describe the module", or when new code lands without docs. Also use proactively after non-trivial public API changes.4---56# Docs Generator78Generate accurate, low-drift documentation by reading the code, not by guessing.910## Core principles11121. **Read before writing.** Open the actual files (types, signatures, call sites) before producing any prose. Never document from memory.132. **Match existing style.** If the repo already has JSDoc, Google-style pydoc, or TSDoc — follow that exact format. If unsure, ask.143. **One source of truth.** Prefer extracting from code comments + signatures. Avoid restating behavior that the code already expresses; explain *why*, not *what*.154. **No hallucinated examples.** Every code example must compile against the current codebase. If you can't verify, mark it `<!-- unverified -->` and tell the user.165. **Keep it in sync.** When the user edits code, offer to update the related docs. When the user edits docs, check that the referenced symbols still exist.1718## Workflow19201. **Scope.** Ask (or infer) what to document: a single function, a module, a package, or the whole repo.212. **Inventory.** List the public surface: exported symbols, public classes, HTTP routes, CLI commands, config keys. Use `Grep`/`Glob`, not memory.223. **Read.** Open each relevant file. Note signatures, types, defaults, side effects, and existing comments.234. **Draft.** Produce docs in the format the user asked for (see Formats below). Keep prose tight; let signatures carry detail.245. **Verify.** Re-check every symbol name, parameter, and path against the source. Fix any mismatch.256. **Write.** Save to the agreed location. If a file exists, edit it; otherwise create it.267. **Report.** Summarize what was generated, what was skipped, and any symbols you couldn't verify.2728## Formats2930### README section / file3132```markdown33## `functionName(args)`3435Short one-line purpose.3637Why it exists or when to use it. Any non-obvious behavior, edge cases,38or performance notes.3940\`\`\`ts41import { functionName } from "./module";42functionName(input, { option: true });43\`\`\`44```4546### JSDoc / TSDoc4748```ts49/**50 * One-line summary.51 *52 * Longer explanation when needed. Mention side effects, async behavior,53 * or throws conditions.54 *55 * @param name - What it is. Required/optional.56 * @returns What comes back, including shape and null/undefined cases.57 * @throws {ErrorName} When this can happen.58 */59```6061### Python docstring (Google style)6263```python64def fn(name, *, strict=False):65 """One-line summary.6667 Optional longer description.6869 Args:70 name: Description.71 strict: Description. Defaults to False.7273 Returns:74 Description of return value.7576 Raises:77 ValueError: When ...78 """79```8081### API reference (REST)8283For each endpoint: method, path, auth requirement, request body schema, response schema, example request/response, error codes.8485### Architecture overview8687Module map (one sentence each), data flow, key invariants, where to look for X.8889## Anti-patterns9091- Restating the implementation line-by-line.92- Documenting private helpers unless asked.93- Examples that import symbols that don't exist or aren't exported.94- "See documentation" links that point nowhere.95- Generating docs for code you haven't actually opened in this session.9697## Additional resources9899- For complete format templates (REST, CLI, JSDoc tags, NumPy style, changelog), see [reference.md](reference.md).100- For before/after examples, see [examples.md](examples.md).101102## Verification checklist103104Before finishing, confirm:105106- [ ] Every documented symbol exists in the current source.107- [ ] Parameter names, types, and defaults match the source.108- [ ] Examples use real import paths and valid signatures.109- [ ] No documented behavior contradicts the code.110- [ ] Style matches existing docs in the repo.