Draft Docs
by @anderskev
Generate first-draft technical documentation from code analysis
clawhub install draft-docsπ About This Skill
name: draft-docs description: Generate first-draft technical documentation from code analysis disable-model-invocation: true
Draft Docs
Generate Reference or How-To documentation drafts to docs/drafts/ for review before publishing.
Arguments
Mode 1: Generate Draft
/beagle-docs:draft-docs "Document the authentication middleware"
Step 0: Gather Context
Before parsing input, gather project context:
# Check for existing docs structure
ls -la docs/ 2>/dev/null || echo "No docs/ directory found"Identify documentation framework
ls docs/navigation.json docs/mint.json docs/docusaurus.config.js docs/mkdocs.yml 2>/dev/null | head -1Check for existing drafts
ls docs/drafts/*.md 2>/dev/null || echo "No existing drafts"Get recent code changes for context
git diff --name-only $(git merge-base HEAD main)..HEAD 2>/dev/null | head -20
Capture:
docs/ subdirectories presentnavigation.json, mint.json, or other configStep 1: Parse Input
Extract from the prompt:
1. Topic: What to document (e.g., "authentication middleware") 2. Content type: Detect from keywords:
| Keywords | Type | Skill |
|----------|------|-------|
| "how to", "guide", "steps", "configure", "set up" | How-To | howto-docs |
| "API", "reference", "parameters", "function", "endpoint" | Reference | reference-docs |
If ambiguous, ask: "Should this be a Reference doc (technical lookup) or How-To guide (task completion)?"
Step 2: Load Skills
Always load both:
1. beagle-docs:docs-style - Core writing principles
2. Detected type skill:
- beagle-docs:reference-docs for Reference
- beagle-docs:howto-docs for How-To
Step 3: Analyze Code
Search the codebase for relevant code:
1. Symbol search: Find functions, classes, types matching the topic 2. File search: Locate related files by name patterns 3. Reference search: Find usage examples
Gather:
Step 4: Generate Draft
Apply the loaded skills to generate documentation:
For Reference docs:
reference-docs template structureFor How-To docs:
howto-docs template structureStep 5: Write Draft
1. Create output path:
- docs/drafts/{slug}.md
- Slug from topic: "WebSocket API" β websocket-api.md
2. Ensure directory exists:
mkdir -p docs/drafts
3. Write the draft file (see Hard gates β Write gate: confirm file on disk before the next step)
4. Report to user:
## Draft Created File: docs/drafts/{slug}.md
Type: Reference | How-To
Based on: [list of analyzed symbols/files]
### Next Steps
1. Review the draft for accuracy
2. Add any missing context or examples
3. When ready, publish with:
/beagle-docs:draft-docs --publish docs/drafts/{slug}.md
Step 6: End-of-Run Verification
Verify draft generation completed successfully:
# Confirm draft file exists
ls -la docs/drafts/{slug}.mdValidate frontmatter (YAML header)
head -10 docs/drafts/{slug}.md | grep -E "^---$|^title:|^description:"Check markdown syntax (if markdownlint available)
markdownlint docs/drafts/{slug}.md 2>/dev/null || echo "markdownlint not available"
Verification Checklist:
docs/drafts/{slug}.mdtitle and descriptionIf any verification fails, report the specific issue and offer to regenerate.
Mode 2: Publish Draft
/beagle-docs:draft-docs --publish docs/drafts/websocket-api.md
Step 1: Read Draft
Read the draft file and extract:
Step 2: Determine Destination
Ask user which section:
Where should this document go?1. API Reference β docs/api/{slug}.md
2. Guides β docs/guides/{slug}.md
3. How-To β docs/how-to/{slug}.md
4. Other β Specify path
Step 3: Move File
mv docs/drafts/{slug}.md {destination}/{slug}.md
Step 4: Update Navigation
Check for docs/navigation.json and update navigation:
1. Read current navigation.json 2. Find appropriate navigation group 3. Add new page entry 4. Write updated navigation.json
Example update:
{
"navigation": [
{
"group": "API Reference",
"pages": [
"api/existing-page",
"api/websocket-api"
]
}
]
}
Step 5: Report
## PublishedFrom: docs/drafts/{slug}.md
To: {destination}/{slug}.md
Navigation: Updated docs/navigation.json
The document is now live in your docs.
Step 6: End-of-Run Verification
Verify publish completed successfully:
# Confirm file moved to destination
ls -la {destination}/{slug}.mdConfirm draft removed
ls docs/drafts/{slug}.md 2>/dev/null && echo "WARNING: Draft still exists" || echo "Draft cleaned up"Verify navigation updated
grep -q "{slug}" docs/navigation.json && echo "Navigation includes new page" || echo "WARNING: Navigation may need manual update"Check markdown syntax at final location
markdownlint {destination}/{slug}.md 2>/dev/null || echo "markdownlint not available"
Verification Checklist:
{destination}/{slug}.mddocs/drafts/If any verification fails, report the specific issue and offer remediation steps.
Content Type Detection
Reference Indicators
How-To Indicators
Rules
docs-style skill for every draftdocs/drafts/ - never directly to final locationHard gates (sequenced)
Do not skip ahead: each Pass must be true before the next step. Use commands or explicit artifactsβnot internal assurance.
Generate draft (Mode 1)
1. Context gate β Pass: Step 0 commands ran (or equivalent) and you recorded at least one concrete outcome: e.g. docs/ listing snippet, or explicit note that docs/ is missing and will be created.
2. Type gate β Pass: Reference vs How-To is decided using the keyword table or the userβs explicit answer (quote or paraphrase with βuser chose β¦β). Do not start Step 3: Analyze Code until this is locked.
3. Skills gate β Pass: Before analysis, both are in play: beagle-docs:docs-style and the type skill (beagle-docs:reference-docs or beagle-docs:howto-docs). In your run, name the two skills loaded (IDs/paths)βnot βI reviewed writing guidelines.β
4. Write gate β Pass: After writing the draft, test -f docs/drafts/{slug}.md succeeds (or ls shows the file). Only then emit the Draft Created block.
Publish draft (Mode 2)
1. Destination gate β Pass: User chose a destination (from the menu or a specific path). Resolve {destination} to a full path; Pass when the parent directory exists (test -d "$(dirname "$path")" or project-appropriate check) and you are not overwriting an existing file without explicit user approval.
2. Move gate β Pass: After mv, the file exists at {destination}/{slug}.md (test -f) and navigation updates (if applicable) are applied before claiming Published.
π Constraints
docs-style skill for every draftdocs/drafts/ - never directly to final location