Agent skill
sync-docs
Strategic documentation sync - review docs before implementation (pull context) OR export learnings after implementation (push to living docs). NOT bidirectional - two separate one-way operations at different phases.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/sync-docs
SKILL.md
Sync Documentation
You are executing the SpecWeave strategic documentation sync command. This handles phase-based documentation synchronization:
- Review mode: Pull strategic docs for pre-implementation context
- Update mode: Push implementation learnings to living docs
Note: This is NOT bidirectional sync (simultaneous two-way). It's two separate one-way operations at different project phases.
STEP 1: Parse Arguments and Detect Mode
Arguments provided: [user's arguments]
Parse the input:
- Check for explicit mode:
review,update, or none (auto-detect) - Check for increment ID:
0001,0002, etc., or none (sync all - NEW DEFAULT) - Check for
--allflag (explicit sync all)
DEFAULT BEHAVIOR:
- No arguments ā Sync all increments with spec.md (batch mode)
- Specific increment ID ā Sync that increment only
--allflag ā Sync all increments (explicit)
Auto-detect logic:
-
If no increment ID provided (NEW DEFAULT):
bash# Sync ALL increments with spec.md echo "š Syncing all increments..." npx specweave sync-specs # This will sync all non-archived increments -
If increment ID provided:
bash# Read the increment's spec.md to check status INCREMENT_PATH=".specweave/increments/{increment_id}" STATUS=$(grep "^status:" "$INCREMENT_PATH/spec.md" | cut -d: -f2 | tr -d ' ') -
Determine mode:
If no increment ID ā BATCH SYNC MODE (sync all) If increment ID provided: If status = "planned" ā REVIEW MODE If status = "in-progress" ā UPDATE MODE If status = "completed" ā UPDATE MODE If status = "closed" ā UPDATE MODE If explicit mode provided ā Use that mode
Output (Batch Mode):
š Syncing all increments...
š Syncing 0040-vitest-living-docs-mock-fixes ā FS-040...
ā
Synced 3 tasks to US-001
ā
Synced 0040 ā FS-040
š Syncing 0041-living-docs-test-fixes ā FS-041...
ā
Synced 2 tasks to US-001
ā
Synced 0041 ā FS-041
ā
Sync complete: 15 increments synced, 0 failed
Output (Single Mode):
š Detected increment: {increment_id}
š Status: {status}
šÆ Mode: {REVIEW or UPDATE}
Proceeding with {mode} mode...
STEP 2A: REVIEW MODE (Pre-Implementation)
Execute this if mode = REVIEW
Review Mode Purpose
Present strategic documentation to user for approval before implementation starts.
Execution Steps:
-
Locate increment folder:
bashINCREMENT_DIR=".specweave/increments/{increment_id}" -
Read all strategic documentation:
bash# Required files SPEC_MD="$INCREMENT_DIR/spec.md" # Optional files PM_ANALYSIS="$INCREMENT_DIR/pm-analysis.md" ARCHITECTURE="$INCREMENT_DIR/architecture.md" INFRASTRUCTURE="$INCREMENT_DIR/infrastructure.md" SECURITY="$INCREMENT_DIR/security.md" TEST_STRATEGY="$INCREMENT_DIR/test-strategy.md" PLAN="$INCREMENT_DIR/plan.md" -
Read related ADRs:
bash# Check for ADRs referenced in plan.md or architecture.md ADR_DIR=".specweave/docs/internal/architecture/adr" -
Present comprehensive summary:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š STRATEGIC DOCUMENTATION REVIEW
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Increment: {increment_id}
Title: {title from spec.md}
Priority: {priority from spec.md}
Status: {status from spec.md}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
PRODUCT SPECIFICATION (spec.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
[Summarize spec.md content - user stories, requirements, acceptance criteria]
{If pm-analysis.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
PRODUCT STRATEGY (pm-analysis.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
User Personas:
[List personas with needs and pain points]
Business Model:
[Revenue model, target metrics]
Feature Prioritization:
[P1/P2/P3 breakdown]
Success Metrics:
[Key metrics to track]
{If architecture.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
SYSTEM ARCHITECTURE (architecture.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Tech Stack:
[List detected or specified tech stack]
System Design:
[Show Mermaid diagram if present, or describe architecture]
Data Models:
[List key entities and relationships]
API Design:
[List key endpoints or interfaces]
Scalability Considerations:
[Performance targets, scaling strategy]
{If ADRs referenced:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ARCHITECTURE DECISIONS (ADRs)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
[For each ADR mentioned in plan.md:]
ADR {number}: {title}
- Decision: {what was decided}
- Rationale: {why}
- Trade-offs: {consequences}
{If infrastructure.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
INFRASTRUCTURE (infrastructure.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Platform: {platform choice}
Resources: {compute, storage, database specs}
Deployment: {deployment strategy}
Monitoring: {monitoring tools}
Cost Estimate: {monthly cost breakdown}
{If security.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
SECURITY (security.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Authentication: {auth strategy}
Authorization: {authz strategy}
Data Protection: {encryption, GDPR compliance}
Security Testing: {security test plan}
{If test-strategy.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
TEST STRATEGY (test-strategy.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Test Pyramid:
[E2E, Integration, Unit test breakdown]
Coverage Target: {target %}
Critical Paths:
[List critical user journeys to test]
{If plan.md exists:}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā±ļø IMPLEMENTATION PLAN (plan.md)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Total Tasks: {count}
Estimated Time: {estimate}
Phases:
[List implementation phases with task ranges]
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š° COST & TIMELINE SUMMARY
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Infrastructure: ${monthly cost}/month
External Services: ${services cost}/month
Total Monthly: ${total}/month
Development Time: {weeks} weeks
Launch Target: {date estimate}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Do you approve this plan?
Options:
ā
Type "approve" - Proceed with implementation
ā ļø Type "changes" - Request specific updates
š Type "questions" - Ask clarifying questions
š Type "regenerate" - Regenerate strategic analysis
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
- Wait for user response:
- If "approve" ā Say: "ā
Strategic documentation approved. Ready to proceed with
/docommand." - If "changes" ā Ask: "What would you like to change? (architecture/features/security/infrastructure/other)"
- If "questions" ā Ask: "What questions do you have?"
- If "regenerate" ā Ask: "Which section should I regenerate?"
- If "approve" ā Say: "ā
Strategic documentation approved. Ready to proceed with
STOP HERE for review mode - Do not proceed to update mode.
STEP 2B: UPDATE MODE (Post-Implementation)
Execute this if mode = UPDATE
Update Mode Purpose
Synchronize living documentation in .specweave/docs/ with learnings and decisions from completed or in-progress increment.
Execution Steps:
0. š SYNC LIVING SPECS (User Stories, ACs, Tasks) - CRITICAL FIRST STEP
šØ MANDATORY: This MUST run FIRST before syncing strategic docs!
Execute the living specs sync using the TypeScript CLI:
import { syncSpecs } from './dist/src/cli/commands/sync-specs.js';
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
console.log('š STEP 0: SYNCING LIVING SPECS');
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n');
console.log('š Syncing user stories, acceptance criteria, and tasks...\n');
// Call sync-specs to sync living docs structure
await syncSpecs(['{increment_id}']);
console.log('\nā
Living specs synced successfully!');
console.log(' - User stories created/updated in .specweave/docs/internal/specs/');
console.log(' - Acceptance criteria synchronized with completion status');
console.log(' - Tasks linked to user stories\n');
What this step does:
- ā Parses increment spec.md and extracts user stories with ACs
- ā Syncs AC completion status from spec.md to user story files
- ā Updates task mappings in user story files
- ā Creates/updates feature files and README
- ā Ensures living specs are in sync BEFORE strategic docs
Output:
šÆ Target increment: {increment_id}
š Increment path: .specweave/increments/{increment_id}
š Mode: Specs-only sync (Universal Hierarchy)
Processing...
š Syncing {increment_id} ā {FS-XXX}...
ā
Synced 3 tasks to US-001
ā
Synced 2 tasks to US-002
ā
Synced {increment_id} ā {FS-XXX}
Created: 5 files
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
CRITICAL: If this step fails, STOP and report error. Do not proceed to strategic docs sync.
1. Analyze Increment Artifacts
INCREMENT_DIR=".specweave/increments/{increment_id}"
# Read all increment files
SPEC="$INCREMENT_DIR/spec.md"
PLAN="$INCREMENT_DIR/plan.md"
ARCHITECTURE="$INCREMENT_DIR/architecture.md"
SECURITY="$INCREMENT_DIR/security.md"
INFRASTRUCTURE="$INCREMENT_DIR/infrastructure.md"
REPORTS_DIR="$INCREMENT_DIR/reports"
# List all report files
REPORTS=$(ls -1 "$REPORTS_DIR"/*.md 2>/dev/null)
Extract documentation updates:
Reading increment {increment_id}...
š Files found:
ā spec.md
{ā or ā for each optional file}
ā {count} reports in reports/
š Analyzing for documentation updates...
2. Identify Documentation Targets
Map increment content to living docs locations:
# Mapping rules:
spec.md (new features):
ā .specweave/docs/public/overview/features.md
ā .specweave/docs/public/guides/ (if guides section present)
spec.md (API changes):
ā .specweave/docs/public/api/ (if exists)
plan.md (architecture decisions):
ā .specweave/docs/internal/architecture/adr/NNNN-decision-name.md (create new ADR)
plan.md (tech stack changes):
ā .specweave/docs/internal/architecture/README.md
architecture.md:
ā .specweave/docs/internal/architecture/diagrams/ (extract diagrams)
ā .specweave/docs/internal/architecture/system-design.md
security.md:
ā .specweave/docs/internal/security/
infrastructure.md:
ā .specweave/docs/internal/operations/deployment.md
ā .specweave/docs/internal/operations/infrastructure.md
reports/*.md (learnings):
ā .specweave/docs/internal/delivery/guides/
ā .specweave/docs/internal/architecture/ (if architectural learnings)
test-strategy.md:
ā .specweave/docs/internal/testing/
Output:
š Documentation updates identified:
1. New ADR needed: {decision from plan.md}
Target: .specweave/docs/internal/architecture/adr/NNNN-{slug}.md
2. Feature list update: {feature from spec.md}
Target: .specweave/docs/public/overview/features.md
3. Architecture diagram update: {diagram from architecture.md}
Target: .specweave/docs/internal/architecture/diagrams/{name}.md
{... list all updates}
Total: {count} documentation updates
3. Detect Conflicts
For each target file that already exists:
- Read existing content
- Read new content from increment
- Compare and detect conflicts:
function detectConflict(existingContent, newContent, section) {
// Types of conflicts:
// 1. Addition (no conflict)
if (!existingContent.includes(section) && newContent.includes(section)) {
return { type: 'addition', conflict: false };
}
// 2. Enhancement (minor conflict - check if contradictory)
if (existingContent.includes(section) && newContent.includes(section)) {
// Check if new content contradicts existing
if (isContradictory(existingContent, newContent)) {
return { type: 'contradiction', conflict: true };
} else {
return { type: 'enhancement', conflict: false };
}
}
// 3. Removal (conflict)
if (existingContent.includes(section) && !newContent.includes(section)) {
return { type: 'removal', conflict: true };
}
return { type: 'no_change', conflict: false };
}
Conflict detection heuristics:
- Keywords that indicate contradiction: "instead of", "rather than", "changed from", "no longer", "deprecated"
- Architecture decisions with different choices (PostgreSQL vs MongoDB)
- Security policies with different rules
- API endpoints with different signatures
Output:
š Conflict detection results:
ā
No conflict: {count} additions/enhancements
ā ļø Conflicts found: {count} contradictions/removals
{If conflicts found, list them}
4. Resolve Conflicts (If Any)
For each conflict, present to user:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ļø CONFLICT #{n}/{total}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
File: {target_file_path}
Section: {section_name}
Conflict Type: {contradiction/removal}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š EXISTING CONTENT
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
{show existing content with context - 5 lines before/after}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š NEW CONTENT (from increment {increment_id})
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
{show new content with context}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā How should I resolve this?
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
A) Keep existing only
B) Replace with new only
C) Merge both (document the evolution)
D) Show me more context
E) Skip this update
{If architecture decision:}
š” Recommendation: Option C - Create new ADR documenting the change
Your choice (A/B/C/D/E):
Wait for user input, then record decision
5. Apply Updates
For each update (non-conflicting + resolved conflicts):
-
If creating new file:
bashTARGET_FILE="{path}" mkdir -p "$(dirname "$TARGET_FILE")" cat > "$TARGET_FILE" <<EOF {content} EOFOutput:
ā Created: {file_path} -
If updating existing file:
bash# Backup first cp "$TARGET_FILE" "$TARGET_FILE.backup" # Apply update (append, replace section, or merge) {update logic based on user choice}Output:
ā Updated: {file_path} -
If creating new ADR:
bash# Get next ADR number NEXT_ADR=$(ls -1 .specweave/docs/internal/architecture/adr/ | grep -E '^[0-9]{4}' | sort -r | head -1 | cut -d- -f1) NEXT_ADR=$((NEXT_ADR + 1)) NEXT_ADR=$(printf "%04d" $NEXT_ADR) ADR_FILE=".specweave/docs/internal/architecture/adr/${NEXT_ADR}-{slug}.md"ADR Template:
markdown# ADR-{number}: {Title} **Status**: Accepted **Date**: {current_date} **Deciders**: {team} **Supersedes**: {previous_adr if applicable} ## Context {describe the problem/decision point from increment} ## Decision {what was decided during implementation} ## Rationale {why this decision was made - from plan.md or reports/} ## Consequences ### Positive {benefits} ### Negative {trade-offs or limitations} ## Implementation {how it was implemented - reference increment {increment_id}} ## Related - Increment: {increment_id} - {other related ADRs}Output:
ā Created ADR: {adr_file}
6. Summary Report
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
DOCUMENTATION SYNC COMPLETE
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Increment: {increment_id} ({title})
Status: {status} ā Documentation Updated
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š LIVING SPECS SYNCED (Step 0)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
User Stories: {count} created/updated in .specweave/docs/internal/specs/
ā
Acceptance Criteria: Synchronized with completion status from spec.md
ā
Tasks: Linked to user stories with completion tracking
ā
Feature Files: Created/updated in .specweave/docs/internal/specs/{project}/
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š STRATEGIC DOCS CHANGES (Steps 1-5)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Created:
{list of new files with paths}
Total: {count} files
Updated:
{list of updated files with paths}
Total: {count} files
ADRs Generated:
{list of new ADRs}
Total: {count} ADRs
Skipped:
{list of skipped updates due to user choice}
Total: {count} updates
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š¾ BACKUPS
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
{If any files were updated:}
Backup files created: {count}
Location: {original_file}.backup
To restore: cp {file}.backup {file}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
šÆ NEXT STEPS
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
1. Review updated documentation:
- Living specs: .specweave/docs/internal/specs/
- Public docs: .specweave/docs/public/
- Internal docs: .specweave/docs/internal/
- New ADRs: .specweave/docs/internal/architecture/adr/
2. Verify living specs sync:
- Check user story files for updated AC checkboxes
- Verify tasks are linked correctly
- Confirm feature files are up to date
3. (Optional) Generate Docusaurus site:
- Use 'docusaurus' skill to publish updated docs
4. Commit changes:
git add .specweave/docs/
git commit -m "docs: sync from increment {increment_id}"
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ALL documentation is now in sync with increment {increment_id}! š
(Living specs + Strategic docs)
STEP 3: Configuration Support
Check for user configuration (optional):
If config exists, respect it. If not, use defaults shown above.
ERROR HANDLING
Error: Increment Not Found
ā Error: Increment '{increment_id}' not found
Available increments:
{list .specweave/increments/*/}
Usage: /sw:sync-docs [review|update] [increment_id]
Error: No Increment Files
ā Error: Increment '{increment_id}' has no spec.md
This increment may be incomplete. Expected files:
- spec.md (required)
- plan.md (optional)
- architecture.md (optional)
Cannot proceed with sync.
Error: Invalid Mode
ā Error: Invalid mode '{mode}'
Valid modes:
- review (pre-implementation doc review)
- update (post-implementation doc sync)
- [none] (auto-detect based on status)
Usage: /sw:sync-docs [review|update] [increment_id]
EXAMPLES
Example 1: Sync all increments (NEW DEFAULT)
User: /sw:sync-docs
Output:
š Syncing all increments...
š Syncing 0040-vitest-living-docs-mock-fixes ā FS-040...
ā
Synced 3 tasks to US-001
ā
Synced 0040 ā FS-040
š Syncing 0041-living-docs-test-fixes ā FS-041...
ā
Synced 2 tasks to US-001
ā
Synced 0041 ā FS-041
š Syncing 0042-test-infrastructure-cleanup ā FS-042...
ā
Synced 5 tasks to US-002
ā
Synced 0042 ā FS-042
ā
Sync complete: 15 increments synced, 0 failed
Example 2: Sync specific increment
User: /sw:sync-docs 0042
Output:
š Detected increment: 0042
š Status: completed
šÆ Mode: UPDATE
Proceeding with UPDATE mode...
{... executes update mode for 0042 only}
Example 3: Explicit review mode
User: /sw:sync-docs review 0003
Output:
š Increment: 0003
š Status: planned
šÆ Mode: REVIEW
{... shows strategic documentation summary}
Example 4: Explicit update mode with increment
User: /sw:sync-docs update 0002
Output:
š Increment: 0002
š Status: completed
šÆ Mode: UPDATE
{... executes update mode with conflict resolution}
IMPORTANT NOTES
- Always show progress: Keep user informed at each step
- Always ask on conflicts: Never overwrite without user approval
- Always create backups: Before modifying existing files
- Always provide summary: Show what changed at the end
- Never skip validation: Check files exist before reading
- Never assume structure: Verify .specweave/docs/ structure exists
You are now ready to execute this command. Follow the steps above precisely.
Didn't find tool you were looking for?