mit einem Klick
kn-extract
// Use when extracting reusable patterns, decisions, failures, or knowledge into documentation
// Use when extracting reusable patterns, decisions, failures, or knowledge into documentation
Use when debugging errors, test failures, build issues, or blocked tasks — structured triage to fix to learn
Use when working with Knowns documentation - viewing, searching, creating, or updating docs
Use when implementing all tasks from an approved spec in one continuous run without manual review gates
Use when implementing a task - follow the plan, check ACs, track progress
Use at the start of a new session to read project docs, understand context, and see current state
Use when creating an implementation plan for a task
| name | kn-extract |
| description | Use when extracting reusable patterns, decisions, failures, or knowledge into documentation |
Announce: "Using kn-extract to extract knowledge."
Core principle: EXTRACT PATTERNS + DECISIONS + FAILURES → COMPOUND LEARNINGS.
--compound flag for full 3-category analysis--consolidate flag to review and consolidate all existing learningsCheck $ARGUMENTS:
--consolidate → Go to "Consolidation Mode" sectionlearnings/critical-patterns for future kn-init sessionsmcp_knowns_tasks({ "action": "get", "taskId": "$ARGUMENTS" })
Look for three categories:
| Category | What to look for |
|---|---|
| Patterns | Reusable code patterns, architecture approaches, integration techniques |
| Decisions | Good calls, bad calls, trade-offs, surprises |
| Failures | Bugs, wrong assumptions, wasted effort, missing prerequisites |
mcp_knowns_search({ "action": "search", "query": "<pattern/topic>", "type": "doc" })
Don't duplicate. Update existing docs when possible.
Identify reusable patterns:
Identify significant decisions:
Identify failures and wasted effort:
mcp_knowns_docs({ "action": "create", "title": "Pattern: <Name>",
"description": "Reusable pattern for <purpose>",
"tags": ["pattern", "<domain>"],
"folder": "patterns"
})
mcp_knowns_docs({ "action": "create", "title": "Learning: <feature/domain>",
"description": "Learnings from <task/feature>",
"tags": ["learning", "<domain>"],
"folder": "learnings",
"content": "<see template below>"
})
Learning doc template:
## Patterns
### <Pattern Name>
- **What:** <description>
- **When to use:** <applicable conditions>
- **Source:** @task-<id>
## Decisions
### <Decision>
- **Chose:** <what was chosen>
- **Over:** <what was rejected>
- **Tag:** GOOD_CALL / BAD_CALL / SURPRISE / TRADEOFF
- **Outcome:** <how it played out>
- **Recommendation:** <for future work>
## Failures
### <Failure>
- **What went wrong:** <description>
- **Root cause:** <not just symptom>
- **Time lost:** <estimate>
- **Prevention:** <what to do differently>
For each extracted pattern or decision worth quick recall, save a concise memory entry alongside the doc:
mcp_knowns_memory({ "action": "add", "title": "<pattern/decision name>",
"content": "<2-3 sentence summary>. Full reference: @doc/<path>",
"layer": "project",
"category": "<pattern|decision|convention|failure>",
"tags": ["<domain>"]
})
Memory = fast agent recall in future sessions. Doc = full structured reference. Do NOT duplicate the entire doc content — store a summary and link to the doc. Skip this step if the extraction produced nothing generalizable.
mcp_knowns_templates({ "action": "create", "name": "<pattern-name>",
"description": "Generate <what>",
"doc": "patterns/<pattern-name>"
})
For any finding that meets ALL criteria:
Check if critical-patterns doc exists:
mcp_knowns_search({ "action": "search", "query": "critical patterns", "type": "doc", "tag": "learning" })
If exists — append:
mcp_knowns_docs({ "action": "update", "path": "learnings/critical-patterns",
"appendContent": "\n\n## [Date] <Learning Title>\n**Category:** pattern / decision / failure\n**Source:** @task-<id>\n**Tags:** [tag1, tag2]\n\n<2-4 sentence summary and what to do differently>\n\n**Full entry:** @doc/learnings/<slug>"
})
If not exists — create:
mcp_knowns_docs({ "action": "create", "title": "Critical Patterns",
"description": "Promoted learnings that save the most time. Read at session start.",
"folder": "learnings",
"tags": ["learning", "critical"],
"content": "# Critical Patterns\n\nPromoted learnings from completed work. Read this at the start of every session via `kn-init`. These are lessons that cost the most to learn and save the most by knowing.\n\n---"
})
Calibration: Do NOT promote everything. If critical-patterns grows past 20-30 entries it becomes noise. Only promote learnings that would have saved ≥30 minutes if known in advance.
CRITICAL: After creating doc/template, validate to catch broken refs:
mcp_knowns_validate({ "entity": "<doc-path>" })
If errors found, fix before continuing.
mcp_knowns_tasks({ "action": "update", "taskId": "$ARGUMENTS",
"appendNotes": "📚 Extracted to @doc/<path>"
})
When $ARGUMENTS contains --consolidate:
Announce: "Using kn-extract --consolidate to review and consolidate learnings."
Scan all existing learnings docs, merge duplicates, flag outdated entries, and promote new critical patterns. Run on-demand when the learnings folder feels messy or after a batch of completed work.
mcp_knowns_docs({ "action": "list", "tag": "learning" })
Read each learning doc:
mcp_knowns_docs({ "action": "get", "path": "<path>", "smart": true })
For each learning doc, check:
For each issue found, present to user:
Consolidation findings:
1. MERGE: "Learning: auth token" + "Learning: JWT refresh" → same root cause
→ Merge into "Learning: auth token handling"?
2. OUTDATED: "Learning: webpack config" — references webpack.config.js which was removed
→ Mark outdated or delete?
3. PROMOTE: "Learning: Go test race conditions" — saved 2h on 3 separate tasks
→ Promote to critical-patterns?
4. ORPHAN: "Learning: SSE reconnect" — references @task-abc123 which doesn't exist
→ Keep content, remove broken ref?
Apply all? (yes / review each / skip)
If "review each": present one at a time, apply user's choice. If "yes": apply all suggested changes.
Consolidation complete:
- Merged: X docs
- Updated: X docs
- Promoted: X to critical-patterns
- Orphans fixed: X
- Total learnings: X docs
Required order for the final user-facing response:
For kn-extract, the key details should cover:
When the extraction leads to a clear follow-up, include the best next command. If the correct outcome is a no-op or a completed doc update with no obvious continuation, stop after the result and key details.
If the work is too specific to generalize, say so explicitly and do not force a new doc.
Do NOT fabricate findings. If the task ran smoothly with no surprises, write that. A short learning with 2 genuine entries is better than a long doc with invented ones.
| Source | Extract As | Template? |
|---|---|---|
| Code pattern | Pattern doc | ✅ Yes |
| API pattern | Integration guide | ✅ Yes |
| Decision (good/bad) | Learning doc | ❌ No |
| Failure / debugging | Learning doc | ❌ No |
| Error solution | Troubleshooting | ❌ No |
| Security approach | Guidelines | ❌ No |