Documentation
Documentation explains WHY, not WHAT. Code shows what was built; documentation explains why it was built that way.
Customization
Before executing, check for user customizations at:
${PAI_USER_DIR}/SKILLCUSTOMIZATIONS/Documentation/
Workflow Routing
| Workflow |
Trigger |
File |
| WriteADR |
"write ADR", "document decision", "architecture decision" |
Workflows/WriteADR.md |
| DocHealth |
"doc health", "check docs", "fix doc drift", "doc maintenance", "stale docs" |
Workflows/DocHealth.md |
| CodebaseToCourse |
"codebase to course", "interactive tutorial", "teach code", "code walkthrough" |
CodebaseToCourse/SKILL.md |
Comment Guidelines
When to Comment
- Non-obvious intent — why this approach was chosen over the obvious one
- Known gotchas — "this looks wrong but it's intentional because..."
- Business rules — logic that comes from domain requirements, not technical necessity
- Workarounds — temporary fixes with references to the real issue
When NOT to Comment
- Restating code —
// increment counter above counter++ adds nothing
- Commented-out code — git has history. Delete it.
- TODO without a ticket — either create a Beads issue / ADR or don't write the TODO
- Obvious types —
// string above a name: string declaration
The Self-Documenting Code Myth
"Self-documenting code" is only self-documenting for its author, briefly.
Good names and clear structure reduce the need for comments, but they can't explain:
- Why this algorithm was chosen over a simpler one
- What business rule drives this branching logic
- Why this seemingly redundant check exists
- What happens if you remove this "unnecessary" code
Architecture Decision Records (ADRs)
Convention: See ${PAI_HOME}/RULES/adr-convention.md for full details.
Quick reference:
- Format:
NNNN-kebab-title.md
- Sections: Status, Date, Context, Decision, Alternatives Considered, Consequences
- Never delete old ADRs — supersede with Status: Superseded by ADR-XXXX
- Two levels: global (PAI-wide in
~/projects/Pai-Exploration/docs/decisions/) and per-project (docs/decisions/)
- Algorithm LEARN phase checks if session warrants an ADR
API Documentation
TypeScript (JSDoc)
/**
* Validates an email address against format rules and MX records.
*
* @param email - The email address to validate
* @returns Validation result with error message if invalid
*
* @example
* const result = await validateEmail('user@example.com');
* if (!result.valid) console.error(result.error);
*/
export async function validateEmail(email: string): Promise<ValidationResult> {
When to use JSDoc:
- Public API functions (exported from a module)
- Complex parameters that aren't obvious from types alone
- Functions with non-obvious side effects
- Anything other developers (or agents) will call
REST/HTTP APIs (OpenAPI)
For HTTP endpoints, maintain OpenAPI/Swagger spec alongside the code:
- Request/response schemas with examples
- Error response shapes
- Authentication requirements
- Rate limiting information
Project Documentation Checklist
Examples
Example 1: Document a technical decision
User: "We chose SQLite over PostgreSQL — document why"
→ Invokes WriteADR workflow
→ Creates ADR with context, decision, alternatives, consequences
→ Saves to docs/decisions/NNNN-sqlite-over-postgres.md
Example 2: Comment guidelines question
User: "Should I comment this function?"
→ Checks against comment guidelines
→ If non-obvious intent or business rule: yes, explain WHY
→ If code is clear from names and types: no comment needed
Example 3: API documentation
User: "Document the webhook endpoint"
→ References JSDoc/OpenAPI patterns
→ Adds parameter descriptions, return types, examples, error shapes
Integration
Works with:
- ADR convention rule — this skill references and extends it
- Algorithm LEARN — LEARN phase triggers ADR creation for architectural decisions
- CodeReview — reviews check for documentation quality (axis 2: readability)
- GitWorkflow — commit messages are documentation (explain WHY)
1---2name: documentation3description: Documentation practices — comment guidelines, ADR conventions, API documentation, inline docs philosophy, doc health scanning and maintenance. USE WHEN documentation, write docs, comment guidelines, ADR, architecture decision, API docs, JSDoc, OpenAPI, document code, when to comment, how to document, self-documenting code, README, doc health, doc drift, stale docs, fix docs, doc maintenance, check docs.4---56# Documentation78Documentation explains WHY, not WHAT. Code shows what was built; documentation explains why it was built that way.910## Customization1112**Before executing, check for user customizations at:**13`${PAI_USER_DIR}/SKILLCUSTOMIZATIONS/Documentation/`1415<!-- ## Voice Notification16```bash17curl -s -X POST http://localhost:8888/notify \18 -H "Content-Type: application/json" \19 -d '{"message": "Running WORKFLOWNAME in Documentation to ACTION"}' \20 > /dev/null 2>&1 &21```22-->2324## Workflow Routing2526| Workflow | Trigger | File |27|----------|---------|------|28| **WriteADR** | "write ADR", "document decision", "architecture decision" | `Workflows/WriteADR.md` |29| **DocHealth** | "doc health", "check docs", "fix doc drift", "doc maintenance", "stale docs" | `Workflows/DocHealth.md` |30| **CodebaseToCourse** | "codebase to course", "interactive tutorial", "teach code", "code walkthrough" | `CodebaseToCourse/SKILL.md` |3132## Comment Guidelines3334### When to Comment3536- **Non-obvious intent** — why this approach was chosen over the obvious one37- **Known gotchas** — "this looks wrong but it's intentional because..."38- **Business rules** — logic that comes from domain requirements, not technical necessity39- **Workarounds** — temporary fixes with references to the real issue4041### When NOT to Comment4243- **Restating code** — `// increment counter` above `counter++` adds nothing44- **Commented-out code** — git has history. Delete it.45- **TODO without a ticket** — either create a Beads issue / ADR or don't write the TODO46- **Obvious types** — `// string` above a `name: string` declaration4748### The Self-Documenting Code Myth4950> "Self-documenting code" is only self-documenting for its author, briefly.5152Good names and clear structure reduce the need for comments, but they can't explain:53- Why this algorithm was chosen over a simpler one54- What business rule drives this branching logic55- Why this seemingly redundant check exists56- What happens if you remove this "unnecessary" code5758## Architecture Decision Records (ADRs)5960**Convention:** See `${PAI_HOME}/RULES/adr-convention.md` for full details.6162**Quick reference:**63- Format: `NNNN-kebab-title.md`64- Sections: Status, Date, Context, Decision, Alternatives Considered, Consequences65- **Never delete old ADRs** — supersede with Status: Superseded by ADR-XXXX66- Two levels: global (PAI-wide in `~/projects/Pai-Exploration/docs/decisions/`) and per-project (`docs/decisions/`)67- Algorithm LEARN phase checks if session warrants an ADR6869## API Documentation7071### TypeScript (JSDoc)7273```typescript74/**75 * Validates an email address against format rules and MX records.76 *77 * @param email - The email address to validate78 * @returns Validation result with error message if invalid79 *80 * @example81 * const result = await validateEmail('user@example.com');82 * if (!result.valid) console.error(result.error);83 */84export async function validateEmail(email: string): Promise<ValidationResult> {85```8687**When to use JSDoc:**88- Public API functions (exported from a module)89- Complex parameters that aren't obvious from types alone90- Functions with non-obvious side effects91- Anything other developers (or agents) will call9293### REST/HTTP APIs (OpenAPI)9495For HTTP endpoints, maintain OpenAPI/Swagger spec alongside the code:96- Request/response schemas with examples97- Error response shapes98- Authentication requirements99- Rate limiting information100101## Project Documentation Checklist102103- [ ] README with quick start and architecture overview104- [ ] ADRs for major technical decisions105- [ ] CLAUDE.md with project conventions for AI agents106- [ ] API documentation (JSDoc for functions, OpenAPI for HTTP)107- [ ] Inline comments for non-obvious intent and gotchas108109## Examples110111**Example 1: Document a technical decision**112```113User: "We chose SQLite over PostgreSQL — document why"114→ Invokes WriteADR workflow115→ Creates ADR with context, decision, alternatives, consequences116→ Saves to docs/decisions/NNNN-sqlite-over-postgres.md117```118119**Example 2: Comment guidelines question**120```121User: "Should I comment this function?"122→ Checks against comment guidelines123→ If non-obvious intent or business rule: yes, explain WHY124→ If code is clear from names and types: no comment needed125```126127**Example 3: API documentation**128```129User: "Document the webhook endpoint"130→ References JSDoc/OpenAPI patterns131→ Adds parameter descriptions, return types, examples, error shapes132```133134## Integration135136**Works with:**137- **ADR convention rule** — this skill references and extends it138- **Algorithm LEARN** — LEARN phase triggers ADR creation for architectural decisions139- **CodeReview** — reviews check for documentation quality (axis 2: readability)140- **GitWorkflow** — commit messages are documentation (explain WHY)