Knowledge Compounding Command
You are a knowledge engineer who extracts valuable learnings from development sessions. You identify patterns, mistakes, solutions, and insights that will benefit future work, then document them in a structured format for searchable retrieval.
Topic/Context: $ARGUMENTS
Workflow
Phase 1: Session Analysis
# Find the current session transcript echo "=== Session Context ===" echo "Working directory: $(pwd)" echo "Git branch: $(git branch --show-current 2>/dev/null || echo 'not in git repo')" # Get recent git activity echo "" echo "=== Recent Git Activity ===" git log --oneline -10 2>/dev/null || echo "No git history" # Check for error patterns in recent commands echo "" echo "=== Recent Files Modified ===" git diff --name-only HEAD~5 2>/dev/null | head -20 || find . -type f -mmin -60 -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null | head -20 # Determine learnings directory LEARNINGS_DIR="./docs/learnings" if [ ! -d "$LEARNINGS_DIR" ]; then echo "" echo "Creating learnings directory: $LEARNINGS_DIR" mkdir -p "$LEARNINGS_DIR" fi
Phase 2: Signal Detection
Analyze the session for high-value signals:
### Signal Analysis
**Error Signals:**
- [ ] Tool errors encountered (is_error: true)
- [ ] Build/test failures
- [ ] Type errors
- [ ] Runtime exceptions
**Rework Signals:**
- [ ] Same file edited 3+ times
- [ ] Reverted changes
- [ ] Multiple approaches tried
**User Feedback Signals:**
- [ ] Negative sentiment ("broke", "wrong", "not what I wanted")
- [ ] Corrections requested
- [ ] Clarifications needed
**Success Signals:**
- [ ] Clean implementation first try
- [ ] Tests passing immediately
- [ ] Positive feedback
**Pattern Signals:**
- [ ] Novel solution found
- [ ] Non-obvious gotcha discovered
- [ ] Framework quirk identified
Phase 3: Learning Extraction
Based on session analysis, extract structured learnings:
### Learning Categories 1. **Build Errors**: Compilation, bundling, transpilation issues 2. **Test Failures**: Test framework, mocking, assertion issues 3. **Runtime Errors**: Exceptions, crashes, undefined behavior 4. **Performance**: Slow queries, memory leaks, rendering issues 5. **Security**: Vulnerabilities, auth issues, data exposure 6. **Database**: Schema issues, migration problems, query issues 7. **UI**: Styling, responsiveness, accessibility issues 8. **Integration**: API issues, third-party service problems 9. **Logic**: Business logic bugs, edge cases, race conditions
Phase 4: Learning Document Generation
Generate a learning document with proper frontmatter:
## Learning Document Template \`\`\`markdown --- title: [Short descriptive title - max 60 chars] category: [build-errors|test-failures|runtime-errors|performance|security|database|ui|integration|logic] tags: [relevant, technology, keywords] severity: [critical|high|medium|low] date: [YYYY-MM-DD] applicable_to: [project|universal] --- # [Title] ## Summary [2-3 sentence description of what was learned] ## Context [What were you trying to do when this was discovered?] ## Problem [What went wrong or what was non-obvious?] ## Root Cause [Why did this happen?] ## Solution [How was it fixed/handled?] ## Prevention [How to avoid this in the future?] ## Evidence [Code snippets, error messages, or other supporting information] \`\`\`code [relevant code or error] \`\`\` ## Related - Related learning: [link if applicable] - Documentation: [external link if applicable] - Issue: [GitHub issue if applicable] \`\`\`
Phase 4.5: Validation Gate (BLOCKING)
Before saving, validate the learning document. DO NOT proceed to Phase 5 until all checks pass.
### Required Fields Check - [ ] `title` present and ≤ 60 characters - [ ] `category` is one of: build-errors, test-failures, runtime-errors, performance, security, database, ui, integration, logic - [ ] `tags` is a non-empty array - [ ] `severity` is one of: critical, high, medium, low - [ ] `date` is valid YYYY-MM-DD format - [ ] `applicable_to` is one of: project, universal ### Content Quality Check - [ ] Summary section present (2-3 sentences) - [ ] Problem section present - [ ] Solution section present - [ ] Prevention section present
If validation fails:
# Auto-fix what's possible
DATE=${DATE:-$(date +"%Y-%m-%d")}
SEVERITY=${SEVERITY:-"medium"}
APPLICABLE_TO=${APPLICABLE_TO:-"project"}
# Validate category
VALID_CATEGORIES="build-errors test-failures runtime-errors performance security database ui integration logic"
if ! echo "$VALID_CATEGORIES" | grep -qw "$CATEGORY"; then
echo "ERROR: Invalid category '$CATEGORY'"
echo "Valid categories: $VALID_CATEGORIES"
echo "Please specify a valid category."
# Re-prompt for category — DO NOT proceed
fi
# Validate title length
TITLE_LENGTH=${#TITLE}
if [ "$TITLE_LENGTH" -gt 60 ]; then
echo "WARNING: Title exceeds 60 characters ($TITLE_LENGTH chars)"
echo "Truncating to 60 characters..."
TITLE="${TITLE:0:60}"
fi
# Validate required content sections
MISSING_SECTIONS=""
[ -z "$SUMMARY" ] && MISSING_SECTIONS="$MISSING_SECTIONS Summary"
[ -z "$PROBLEM" ] && MISSING_SECTIONS="$MISSING_SECTIONS Problem"
[ -z "$SOLUTION" ] && MISSING_SECTIONS="$MISSING_SECTIONS Solution"
[ -z "$PREVENTION" ] && MISSING_SECTIONS="$MISSING_SECTIONS Prevention"
if [ -n "$MISSING_SECTIONS" ]; then
echo "ERROR: Missing required sections:$MISSING_SECTIONS"
echo "Please provide content for all required sections."
# Re-prompt for missing sections — DO NOT proceed
fi
echo "✅ Validation passed — proceeding to save"
Phase 5: Save Learning
# Generate filename
CATEGORY="${CATEGORY:-general}"
DATE=$(date +"%Y-%m-%d")
TITLE_SLUG=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | cut -c1-50)
FILENAME="${DATE}-${TITLE_SLUG}.md"
# Ensure category directory exists
mkdir -p "$LEARNINGS_DIR/$CATEGORY"
# Save learning document
LEARNING_PATH="$LEARNINGS_DIR/$CATEGORY/$FILENAME"
echo "Saving learning to: $LEARNING_PATH"
Phase 6: Contribution Prompt
If the learning is universal (not project-specific):
### Universal Learning Detected This learning appears to be applicable beyond this project. **Contribution Opportunity:** - Learning could benefit other projects using this plugin - Consider running `/contribute-pattern` to share with plugin repository **Criteria for Universal Learning:** - ✅ Not specific to this project's domain - ✅ Related to common frameworks/tools - ✅ Addresses a non-obvious gotcha - ✅ Provides reusable solution pattern
Output Format
When completed, output:
## 📝 Learning Captured **Title:** [Learning title] **Category:** [Category] **Severity:** [Severity] **Saved to:** `./docs/learnings/[category]/[filename].md` ### Summary [Brief summary of the learning] ### Key Takeaway > [One-sentence key insight] ### Next Steps - [ ] Review learning for accuracy - [ ] Add additional context if needed - [ ] Consider `/contribute-pattern` if universal
Auto-Prompt Triggers
This command should be auto-suggested after sessions with:
- •High error count (3+ tool errors)
- •High rework (same file edited 5+ times)
- •Long duration (>2x average for command type)
- •User frustration signals (negative feedback detected)
- •Novel solutions (unique patterns not in knowledge base)
Examples
Example 1: Build Error Learning
/compound "TypeScript strict mode breaking existing code"
Example 2: Performance Learning
/compound "N+1 query in user dashboard"
Example 3: Integration Learning
/compound "OAuth token refresh race condition"
Example 4: Auto-invoked (no argument)
/compound
→ Analyzes recent session for learnings automatically
Success Criteria
- •✅ Session analyzed for high-value signals
- •✅ Learning extracted with proper structure
- •✅ Document saved to correct category
- •✅ Frontmatter complete and valid
- •✅ Contribution opportunity assessed
Remember: Knowledge compounds over time. Today's learning prevents tomorrow's bug. Every documented pattern saves future debugging hours.