|
| 1 | +--- |
| 2 | +title: "feat: Add documentation workflow command" |
| 3 | +type: feat |
| 4 | +date: 2026-02-13 |
| 5 | +--- |
| 6 | + |
| 7 | +# feat: Add documentation workflow command |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +Add a `/workflows:document` command that updates project documentation after a feature is implemented and reviewed. This fills the gap between `/workflows:review` and `/workflows:compound` in the workflow chain: |
| 12 | + |
| 13 | +``` |
| 14 | +Research → Brainstorm → Plan → Work → Review → Document → Compound |
| 15 | +``` |
| 16 | + |
| 17 | +**Brainstorm:** [docs/brainstorms/2026-02-13-documentation-workflow-brainstorm.md](../brainstorms/2026-02-13-documentation-workflow-brainstorm.md) |
| 18 | + |
| 19 | +## Problem Statement |
| 20 | + |
| 21 | +The workflow chain has no step for updating user-facing documentation. Features ship without corresponding doc updates because it's left as a manual afterthought. A structured, propose-then-confirm workflow would make documentation a natural part of the development cycle. |
| 22 | + |
| 23 | +## Proposed Solution |
| 24 | + |
| 25 | +A single workflow command file at `plugins/compound-engineering/commands/workflows/document.md` that follows the established phase-based pattern. Three phases: Discovery → Proposal → Execution. |
| 26 | + |
| 27 | +## Implementation |
| 28 | + |
| 29 | +### File to create |
| 30 | + |
| 31 | +#### `plugins/compound-engineering/commands/workflows/document.md` |
| 32 | + |
| 33 | +The workflow command. Structure: |
| 34 | + |
| 35 | +```yaml |
| 36 | +--- |
| 37 | +name: workflows:document |
| 38 | +description: Update project documentation after implementation and review |
| 39 | +argument-hint: "[optional: path to brainstorm or plan doc, or PR number]" |
| 40 | +--- |
| 41 | +``` |
| 42 | + |
| 43 | +**Phase 1: Discovery** |
| 44 | + |
| 45 | +Gather context about what was built and what docs exist: |
| 46 | + |
| 47 | +1. **Determine diff base** — Check for PR (via `gh pr view`), fall back to `main`/`master` |
| 48 | +2. **Git diff analysis** — Run `git diff <base>...HEAD --stat` then read changed files to understand what was built. Filter out test files, generated code, and lock files to keep scope manageable |
| 49 | +3. **Chain doc lookup** — Search `docs/brainstorms/` and `docs/plans/` for recent documents matching the current feature (by date, branch name, or topic). If `$ARGUMENTS` provides a path, use that directly. If nothing found, proceed with diff-only mode |
| 50 | +4. **Doc inventory** — Use Glob to find existing documentation files: `README*`, `CHANGELOG*`, `docs/**/*.md`, `API.md`, `GUIDE.md`, any `**/README.md` in subdirectories. Note their last-modified dates and sizes |
| 51 | +5. **Gap analysis** — Compare what was built (from diff + chain docs) against what's documented. Identify: new features not mentioned in README, missing CHANGELOG entry, outdated API docs, new public APIs without docstrings |
| 52 | + |
| 53 | +**Phase 2: Proposal** |
| 54 | + |
| 55 | +Present a structured update plan to the user: |
| 56 | + |
| 57 | +- For each doc file that needs changes, show: file path, what kind of update (new section, updated section, new entry), and a 1-line summary of the change |
| 58 | +- Flag any new docs that should be created (e.g., "No CHANGELOG exists — create one?") |
| 59 | +- Flag docs that might need deletion or archival (if features were removed) |
| 60 | +- Use `AskUserQuestion` with options: |
| 61 | + 1. **Approve all** — Execute all proposed updates |
| 62 | + 2. **Select items** — Choose which updates to apply (use multiSelect) |
| 63 | + 3. **Skip documentation** — Exit without changes |
| 64 | + 4. **Refine proposal** — Ask for adjustments |
| 65 | + |
| 66 | +**Guardrails to prevent overwriting user content:** |
| 67 | +- Only modify sections relevant to the changed code — never rewrite entire files |
| 68 | +- When updating an existing section, show the diff preview before applying |
| 69 | +- Detect and preserve custom sections (anything not generated by this workflow) |
| 70 | +- For README: append new feature sections, don't restructure existing content |
| 71 | + |
| 72 | +**Phase 3: Execution** |
| 73 | + |
| 74 | +Make the approved changes: |
| 75 | + |
| 76 | +1. For each approved update, read the target file, make the change, write it back |
| 77 | +2. Match existing doc style (detect heading levels, tone, formatting from surrounding content) |
| 78 | +3. For CHANGELOG: use Keep a Changelog format if one exists, otherwise detect existing format |
| 79 | +4. After all updates, show a summary: files changed, sections added/updated |
| 80 | +5. Offer handoff via `AskUserQuestion`: |
| 81 | + 1. **Continue to `/workflows:compound`** — Document solved problems for team knowledge |
| 82 | + 2. **Review changes** — Load `document-review` skill for quality pass |
| 83 | + 3. **Done** — Documentation complete |
| 84 | + |
| 85 | +### Edge cases to handle |
| 86 | + |
| 87 | +- **No existing docs:** Offer to scaffold a minimal doc structure (README + CHANGELOG) rather than silently failing |
| 88 | +- **No git diff:** If on main with no changes, check `$ARGUMENTS` for a PR number. If nothing, tell the user and exit |
| 89 | +- **Doc-only changes in diff:** Detect and exit early — "Changes are documentation-only, nothing additional to document" |
| 90 | +- **Massive diffs (50+ files):** Summarize by directory/component rather than file-by-file. Focus on public API changes |
| 91 | +- **No chain docs found:** Proceed with diff-only mode, mention that brainstorm/plan context would improve results |
| 92 | + |
| 93 | +### Files to update (plugin metadata) |
| 94 | + |
| 95 | +After creating the command, update these files per the plugin's versioning requirements: |
| 96 | + |
| 97 | +- [ ] `plugins/compound-engineering/.claude-plugin/plugin.json` — bump minor version, update command count in description |
| 98 | +- [ ] `.claude-plugin/marketplace.json` — update description with new command count |
| 99 | +- [ ] `plugins/compound-engineering/README.md` — add `/workflows:document` to commands list |
| 100 | +- [ ] `plugins/compound-engineering/CHANGELOG.md` — add entry under new version |
| 101 | + |
| 102 | +### Optional: Update review workflow handoff |
| 103 | + |
| 104 | +Update `plugins/compound-engineering/commands/workflows/review.md` to offer `/workflows:document` as a next step after review completes. Add an option in the final handoff section. |
| 105 | + |
| 106 | +## Acceptance Criteria |
| 107 | + |
| 108 | +- [ ] `/workflows:document` command exists and loads correctly |
| 109 | +- [ ] Phase 1 discovers changed files via git diff and finds chain docs when available |
| 110 | +- [ ] Phase 2 presents a clear proposal listing each doc update needed |
| 111 | +- [ ] User can approve all, select specific items, or skip |
| 112 | +- [ ] Phase 3 makes only approved changes without overwriting unrelated content |
| 113 | +- [ ] Handoff to `/workflows:compound` works |
| 114 | +- [ ] Plugin metadata (version, counts, changelog) updated correctly |
| 115 | +- [ ] Works in diff-only mode when no chain docs exist |
| 116 | + |
| 117 | +## References |
| 118 | + |
| 119 | +- Workflow pattern: `plugins/compound-engineering/commands/workflows/work.md` |
| 120 | +- Handoff pattern: `plugins/compound-engineering/commands/workflows/compound.md` |
| 121 | +- Doc style skills: `plugins/compound-engineering/skills/document-review/`, `plugins/compound-engineering/skills/every-style-editor/` |
| 122 | +- Plugin versioning: `docs/solutions/plugin-versioning-requirements.md` |
0 commit comments