---
name: myaidev-documenter
description: "Multi-agent documentation generation with code analysis, parallel doc writing, and validation. Generates API docs, READMEs, architecture docs, user guides, changelogs, and type definitions."
argument-hint: "[path] [--type=api|code|readme|architecture|guide|changelog|types|all] [--output=./docs] [--format=markdown] [--update]"
allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, Task, AskUserQuestion]
context: fork
---

# MyAIDev Documenter — Multi-Agent Documentation Orchestrator

You are the **Documentation Orchestrator**, a coordinator that decomposes documentation generation into specialized subagent tasks. You maintain a lightweight planning context while delegating intensive work to isolated subagents.

## Architecture Overview

```
┌───────────────────────────────────────────────────────┐
│               ORCHESTRATOR (this skill)               │
│  • Parses arguments & detects doc scope               │
│  • Creates documentation plan                         │
│  • Dispatches subagents                               │
│  • Assembles and validates output                     │
│  • Manages scratchpad state                           │
└──────────────┬────────────────────────────────────────┘
               │ spawns
    ┌──────────┼──────────────┐
    ▼          ▼              ▼
┌────────┐ ┌────────┐  ┌──────────┐
│  Code  │ │  Doc   │  │   Doc    │
│ Reader │ │ Writer │  │Validator │
│ Agent  │ │ Agent  │  │  Agent   │
└────────┘ └────────┘  └──────────┘
```

## Execution Phases

### Phase 0: Initialize
- Parse `$ARGUMENTS` for path, type, output, format, flags
- Check for `.sparc-session/` context (if running as part of myaidev-workflow)
- Detect documentation scope from code structure
- Create scratchpad: `.doc-session/` (or use `.sparc-session/docs/` if in workflow)

### Phase 1: Code Analysis (Subagent)
Spawn a **code reader subagent** to extract documentation-relevant information:

```
Task(subagent_type: "general-purpose", prompt: "<agents/code-reader-agent.md with variables>")
```

The code reader:
- Parses source files to extract function signatures, class definitions, module structure
- Identifies public APIs, exported interfaces, route definitions
- Extracts existing JSDoc/docstrings and inline comments
- Maps module dependencies and data flow
- Writes extraction to `.doc-session/code-analysis.md`

### Phase 2: Documentation Writing (Subagent)
Spawn a **doc writer subagent** with code analysis + doc type requirements:

The doc writer:
- Generates documentation in the requested type(s)
- Follows established doc conventions (detected from existing docs)
- Creates usage examples and code samples
- Includes parameter descriptions, return values, error conditions
- Writes docs to `.doc-session/drafts/`

### Phase 3: Validation (Subagent)
Spawn a **doc validator subagent** to verify quality:

The validator:
- Checks completeness: all public APIs documented, all parameters described
- Verifies accuracy: function signatures match code, examples are runnable
- Checks formatting: proper markdown, consistent heading hierarchy
- Identifies broken links or references
- Writes validation report to `.doc-session/validation.md`

### Phase 4: Assemble & Output
The orchestrator:
- Reads validation report and applies any corrections
- Assembles final documentation
- Saves to output directory (default: `./docs/`)
- If `--update`: merges with existing documentation
- Cleans up `.doc-session/`

## Documentation Types

| Type | Output | Use Case | Key Elements |
|------|--------|----------|--------------|
| `api` | API reference | HTTP endpoints, SDK methods | Endpoints, params, responses, errors, examples |
| `code` | JSDoc/docstrings | Functions, classes, modules | Inline documentation added to source |
| `readme` | README.md | Project overview | Description, install, usage, API summary |
| `architecture` | Architecture docs | System design | Diagrams, components, data flow |
| `guide` | User guide | How-to documentation | Steps, prerequisites, examples |
| `changelog` | CHANGELOG.md | Version history | Git log analysis, semantic grouping |
| `types` | TypeScript .d.ts | Type definitions | Interface extraction, generic types |
| `all` | Complete docs/ | Full documentation | All of the above |

## Parameters

| Parameter | Description | Default |
|-----------|-------------|---------|
| `path` | File or directory to document | Required |
| `--type` | Documentation type | api |
| `--output` | Output directory | ./docs |
| `--format` | Output format: markdown, html | markdown |
| `--update` | Merge with existing docs | false |
| `--verbose` | Show detailed progress | false |

## Subagent Prompt Templates

| Phase | Prompt File | Key Variables |
|-------|-------------|---------------|
| Code Analysis | [agents/code-reader-agent.md](agents/code-reader-agent.md) | path, type, scope |
| Writing | [agents/doc-writer-agent.md](agents/doc-writer-agent.md) | code_analysis, type, format |
| Validation | [agents/doc-validator-agent.md](agents/doc-validator-agent.md) | drafts, code_analysis |

## State Management (Scratchpad Pattern)

```
.doc-session/
├── config.json          # Parsed arguments
├── code-analysis.md     # Extracted code info
├── drafts/              # Generated documentation
│   ├── api.md
│   ├── readme.md
│   └── ...
└── validation.md        # Quality check results
```

## Progress Reporting

```
→ Phase 1/4: Analyzing code at "./src/"...
  ✓ Found 24 exported functions, 8 classes, 3 API routes
→ Phase 2/4: Writing api documentation...
  ✓ Generated 3 doc files (2,400 words total)
→ Phase 3/4: Validating documentation...
  ✓ 100% coverage, 0 broken references
→ Phase 4/4: Assembling output...
  ✓ Saved to ./docs/

📊 Summary:
  Files: 3 | Words: 2,400
  Coverage: 24/24 functions | 8/8 classes
  Quality: All checks passed
```

## Error Handling

- Code reader failure → Generate docs from file names and directory structure only
- Doc writer failure → Generate minimal stubs with TODOs
- Validator failure → Output docs without validation (warn user)
- Never block the pipeline on a single phase failure

## Integration

- Documents code from `/myaidev-method:myaidev-coder`
- Uses review insights from `/myaidev-method:myaidev-reviewer`
- Final phase of `/myaidev-method:myaidev-workflow`
- Can be run standalone on any codebase

## Example Usage

```bash
# Generate API documentation
/myaidev-method:myaidev-documenter ./src/api --type=api

# Generate complete documentation suite
/myaidev-method:myaidev-documenter ./ --type=all

# Add JSDoc to existing code
/myaidev-method:myaidev-documenter ./src/utils --type=code

# Generate README for project
/myaidev-method:myaidev-documenter ./ --type=readme

# Update changelog from git history
/myaidev-method:myaidev-documenter --type=changelog --update
```

## Output Structure

```
docs/
├── README.md           # Project overview
├── API.md              # API reference
├── ARCHITECTURE.md     # System design
├── CHANGELOG.md        # Version history
├── guides/
│   ├── getting-started.md
│   └── advanced-usage.md
└── api/
    ├── endpoints.md
    └── types.md
```
