Build, audit, or incrementally refresh comprehensive project documentation in the `Docs/` folder. Generates a TOC-driven wiki with categorized pages (core, features, operations, api, design, runbooks), AUTOGEN markers for safe updates, evidence-based citations with line numbers, Mermaid diagrams, and a README index. Use after significant code changes, when onboarding a new repo, or to audit existing docs for staleness.
You are responsible for keeping Docs/ aligned with the codebase. This skill produces thorough, evidence-based documentation, not surface-level notes. Treat Docs/ as the canonical project wiki.
Docs/ (capital D) at the repo root.Docs/_toc.yaml is the source of truth for page IDs, source-file mappings, sections, and diagram requirements.<!-- PAGE_ID: ... --> and <!-- BEGIN:AUTOGEN ... --> / <!-- END:AUTOGEN ... --> markers so that incremental updates only rewrite generated regions, never manual notes.Docs/_meta/GENERATION.md (commit hash, branch, timestamp) and Docs/_meta/SUMMARY.md (coverage report).Docs/README.md, modeled on the supportforge layout (Quick Start table, then categorized tables).Docs/
├── README.md # Index: Quick Start + categorized tables
├── _toc.yaml # TOC: pages, sections, source mappings
├── _meta/
│ ├── GENERATION.md # commit, branch, timestamp
│ └── SUMMARY.md # coverage and validation report
├── core/ # Architecture, auth, data model, principles
├── api/ # API_REFERENCE.md and per-surface API docs
├── features/ # One page per major feature or integration
├── operations/ # Runbooks, monitoring, deploy, secrets
├── design-system/ # UI/UX standards (only for UI projects)
├── frontend/ # Frontend-specific guides (only when applicable)
├── plans/ # Active design / planning docs (manual)
└── archive/ # Historical docs (manual)
Omit folders that have no relevant pages. Add other folders only when the repo demands it (e.g., desktop-agent/, branding/).
The skill operates in one of three modes. Detect the mode from the user's argument, the state of Docs/, and the recency of generation metadata.
| Mode | When to use | Output |
|---|---|---|
| init | Docs/ does not exist, or Docs/_toc.yaml is missing | Full repo scan → TOC design → page generation → validation → index |
| update | Docs/_toc.yaml exists; user changed code since last generation | Git diff → affected pages → regenerate only those AUTOGEN sections |
| audit | User asks to "audit" / "check" docs, or wants a stale-references report only | Inventory + cross-reference + report; no rewrites |
If the argument is empty: pick init when no Docs/_toc.yaml, otherwise update.
Load these reference files before generating or updating any page. They contain the rules you must follow:
references/page-template.md — required page structure, markers, headingsreferences/citation-policy.md — evidence rules, source URL format, line numbersreferences/mermaid-policy.md — diagram syntax rules and validationreferences/toc-schema.md — _toc.yaml schema and ID conventionsreferences/doc-categories.md — when to create which page typereferences/incremental-update.md — safe AUTOGEN replacement rulesreferences/readme-template.md — Docs/README.md index structurePage templates live in templates/:
overview.md, architecture.md, api-reference.md, feature.md,
database-schema.md, module.md, data-flow.md, runbook.md,
getting-started.md, configuration.md, glossary.md, _toc.yaml.templateEach template defines required sections and minimum content expectations. Do not skip required sections; mark them _TBD_ with a reason if no source exists.
git rev-parse HEAD (commit hash)git rev-parse --abbrev-ref HEAD (branch)git config --get remote.origin.url (repo URL → derive repo_base_url)**/main.{ts,js,py,go,rs}, **/index.{ts,js,tsx}, **/cmd/**/main.gopackage.json, pyproject.toml, Cargo.toml, go.mod, Dockerfile*, docker-compose*, *.tf, .env.exampleMakefile, .github/workflows/*, turbo.json, nx.jsonREADME*, **/*.md outside Docs/ and node_modules/README.md, package.json (or equivalent), and 2-3 entry-point files to understand purpose, stack, and structure.Read references/toc-schema.md and references/doc-categories.md.
Pick page categories that match the project. Use the page-count guideline:
| Project size | Files | Pages |
|---|---|---|
| Small | < 10 | 3-5 |
| Medium | 10-50 | 5-8 |
| Large | 50-200 | 8-14 |
| Very Large | > 200 | 12-20 |
Group pages into folders (core/, features/, operations/, etc.) per the folder layout above.
For each page, decide:
id ({repo}_{NN}_{slug}), title, filename, descriptionsource_files (page-level glob patterns)sections[] with id, title, autogen: true, optional section-level source_files, diagrams_needed, diagram_typesrelated_pages[] for cross-linkingWrite Docs/_toc.yaml using templates/_toc.yaml.template as a starting point. Replace placeholders with real values.
For each page in _toc.yaml:
source_files (page-level + section-level) using Glob.templates/ based on the page category.Docs/{folder}/{filename} following references/page-template.md:
<!-- PAGE_ID: {id} --> at the very top# {title} H1> **Related Pages**: line linking to related_pagesSources: line--- separator between sectionsreferences/citation-policy.md:
Sources: summaryreferences/mermaid-policy.md when diagrams_needed: true. Use graph TD, quote all node text, no special chars in subgraph names.For large repos, generate pages in parallel by spawning explorer subagents per page. Each subagent receives: the page entry from TOC, the resolved source files, and the template path. Wait for all to complete before validation.
Write Docs/README.md using references/readme-template.md. Include:
CHANGELOG.md entries_toc.yamlREADME.md, agents.md, and CLAUDE.md if they existWrite Docs/_meta/GENERATION.md:
# Generation Metadata
- **Commit:** `{hash}`
- **Branch:** `{branch}`
- **Generated:** {ISO timestamp}
- **Mode:** init
- **Pages generated:** {count}
- **Sections generated:** {count}
Run validation in this order:
PAGE_ID marker matching the TOCautogen: true section has matched BEGIN:AUTOGEN / END:AUTOGEN markers with the correct ID[text](path) points to a file that existsmmdc is on PATH (which mmdc), extract each ```mermaid block and validate. If unavailable, skip with a note.references/mermaid-policy.md. If still invalid, comment the block out and add a <!-- TODO: invalid mermaid --> marker._toc.yaml patterns vs. files actually cited in pagesWrite Docs/_meta/SUMMARY.md per references/incremental-update.md (Summary section). Include: pages generated vs. expected, citations per page, diagrams per page, validation errors, uncovered files.
Docs/_meta/GENERATION.md (base_commit).git rev-parse HEAD (target_commit).git diff --name-status {base_commit}..{target_commit} (added / modified / deleted / renamed).Docs/_toc.yaml and resolve every page's source_files glob.For every changed file that does NOT match any TOC source pattern:
_toc.yaml accordingly.For each affected page:
source_files intersect the changed files):
<!-- BEGIN:AUTOGEN {section_id} --> and <!-- END:AUTOGEN {section_id} -->For each new TOC page: generate as in init Step 3.
For each deleted source file with no remaining coverage:
source_files is now empty, remove the AUTOGEN block from the page and delete the section from _toc.yaml._toc.yaml.Docs/README.md only if pages were added, removed, or renamed.Docs/_meta/GENERATION.md with the new commit, timestamp, and mode: update.Docs/README.md from new CHANGELOG.md entries since base_commit.Run the same validation sequence as init Step 6, scoped to changed files where possible.
Write Docs/_meta/SUMMARY.md listing: commit range, pages updated, sections regenerated, sections added, sections removed, validation results.
Use the legacy lightweight workflow. Do not rewrite anything.
Docs/**/*.md and any **/*.md outside Docs/.For each doc:
package.json / lockfilesWrite the audit report to stdout (not to a file unless asked). Format:
# Documentation Audit
## Summary
- Files scanned: N
- Issues: N (high: X, medium: Y, low: Z)
## Findings
[HIGH] Docs/api/API_REFERENCE.md:142 — references removed endpoint POST /v1/foo
[MED] Docs/core/AUTHENTICATION.md — example uses old `getSession()` signature
[LOW] Docs/README.md — internal link to features/old-feature.md (file does not exist)
## Missing Documentation
[NEEDS DOCS] src/api/routes/billing.ts — 8 routes with no doc page
[NEEDS DOCS] env var STRIPE_WEBHOOK_SECRET — referenced in code, not in docs
## Recommendations
1. Run `/doc-sync update` to regenerate stale sections.
2. Add a feature page for billing.
For init mode on medium/large repos, fan out page generation to explorer subagents in parallel. Each subagent prompt must include:
Docs/{folder}/{filename} and return only "DONE: {filename}" or an errorWait for all to complete, then run validation in the main session. Never run validation inside a subagent — it must see the whole output set.
For update mode, single-page jobs are usually fine without subagents. Spawn subagents only if more than 5 pages are affected.
_TBD_ with a one-line reason.BEGIN:AUTOGEN / END:AUTOGEN markers in update mode.Docs/ (the legacy README at the repo root is left alone unless the user asks).graph TD for flowcharts, quote all Mermaid node text, and validate diagrams when mmdc is available.Docs/_meta/GENERATION.md after a successful run so the next update knows the base commit.Docs/_toc.yaml and Docs/README.md in sync — every TOC page must appear in the README index, and every README link must point to a TOC-tracked file.Docs/_toc.yaml valid (unique IDs, kebab-case slugs, every page has ≥ 1 source file)references/page-template.mdDocs/README.md lists every generated pageDocs/_meta/GENERATION.md reflects the current commitDocs/_meta/SUMMARY.md written with coverage and validation results