@dzhechkov/p-replicator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +314 -0
- package/bin/cli.js +4 -0
- package/package.json +62 -0
- package/src/cli.js +160 -0
- package/src/commands/doctor.js +151 -0
- package/src/commands/init.js +155 -0
- package/src/commands/list.js +133 -0
- package/src/commands/remove.js +111 -0
- package/src/commands/update.js +102 -0
- package/src/utils.js +280 -0
- package/templates/.claude/agents/doc-validator.md +92 -0
- package/templates/.claude/agents/harvest-coordinator.md +91 -0
- package/templates/.claude/agents/product-discoverer.md +57 -0
- package/templates/.claude/agents/replicate-coordinator.md +98 -0
- package/templates/.claude/commands/harvest.md +106 -0
- package/templates/.claude/commands/replicate.md +389 -0
- package/templates/.claude/rules/replicate-pipeline.md +92 -0
- package/templates/.claude/skills/brutal-honesty-review/README.md +218 -0
- package/templates/.claude/skills/brutal-honesty-review/SKILL.md +225 -0
- package/templates/.claude/skills/brutal-honesty-review/resources/assessment-rubrics.md +295 -0
- package/templates/.claude/skills/brutal-honesty-review/resources/review-template.md +102 -0
- package/templates/.claude/skills/brutal-honesty-review/scripts/assess-code.sh +179 -0
- package/templates/.claude/skills/brutal-honesty-review/scripts/assess-tests.sh +223 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/SKILL.md +374 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/claude-md-strategy.md +178 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/enhanced-recommendations.md +416 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/extended-mapping.md +370 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/automation-commands.md +733 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/ddd-agents.md +416 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/ddd-hooks-commands.md +524 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/ddd-skills.md +350 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/enhanced-claude-md.md +235 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-lifecycle-ent.md +400 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-lifecycle.md +325 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-suggestions.md +423 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/insights-system.md +349 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/mcp.md +274 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/start-command.md +283 -0
- package/templates/.claude/skills/explore/SKILL.md +215 -0
- package/templates/.claude/skills/explore/references/questioning-techniques.md +151 -0
- package/templates/.claude/skills/explore/references/task-brief-templates.md +355 -0
- package/templates/.claude/skills/goap-research-ed25519/SKILL.md +415 -0
- package/templates/.claude/skills/goap-research-ed25519/references/ed25519-verification.md +658 -0
- package/templates/.claude/skills/goap-research-ed25519/references/research-actions.md +544 -0
- package/templates/.claude/skills/goap-research-ed25519/references/source-evaluation.md +560 -0
- package/templates/.claude/skills/goap-research-ed25519/scripts/ed25519_verifier.py +662 -0
- package/templates/.claude/skills/goap-research-ed25519/scripts/goap_planner.py +720 -0
- package/templates/.claude/skills/knowledge-extractor/SKILL.md +412 -0
- package/templates/.claude/skills/knowledge-extractor/examples/rate-limiting-extraction.md +259 -0
- package/templates/.claude/skills/knowledge-extractor/modules/01-agent-review.md +192 -0
- package/templates/.claude/skills/knowledge-extractor/modules/02-classify.md +122 -0
- package/templates/.claude/skills/knowledge-extractor/modules/03-decontextualize.md +156 -0
- package/templates/.claude/skills/knowledge-extractor/modules/04-integrate.md +178 -0
- package/templates/.claude/skills/knowledge-extractor/references/artifact-categories.md +342 -0
- package/templates/.claude/skills/knowledge-extractor/references/decontextualization-guide.md +247 -0
- package/templates/.claude/skills/knowledge-extractor/references/maturity-model.md +153 -0
- package/templates/.claude/skills/knowledge-extractor/templates/artifact-card.md +60 -0
- package/templates/.claude/skills/knowledge-extractor/templates/harvest-report.md +70 -0
- package/templates/.claude/skills/knowledge-extractor/templates/toolkit-harvest.md +38 -0
- package/templates/.claude/skills/pipeline-forge/SKILL.md +523 -0
- package/templates/.claude/skills/pipeline-forge/examples/replicate-analysis.md +291 -0
- package/templates/.claude/skills/pipeline-forge/references/patterns-catalog.md +408 -0
- package/templates/.claude/skills/pipeline-forge/references/quality-gates.md +268 -0
- package/templates/.claude/skills/pipeline-forge/references/skill-anatomy.md +292 -0
- package/templates/.claude/skills/pipeline-forge/templates/agent-template.md +60 -0
- package/templates/.claude/skills/pipeline-forge/templates/command-template.md +80 -0
- package/templates/.claude/skills/pipeline-forge/templates/pipeline-template.md +137 -0
- package/templates/.claude/skills/pipeline-forge/templates/skill-template.md +132 -0
- package/templates/.claude/skills/problem-solver-enhanced/SKILL.md +562 -0
- package/templates/.claude/skills/requirements-validator/SKILL.md +121 -0
- package/templates/.claude/skills/requirements-validator/assets/templates/bdd-feature-template.feature +69 -0
- package/templates/.claude/skills/requirements-validator/references/bdd-patterns.md +184 -0
- package/templates/.claude/skills/requirements-validator/references/invest-criteria.md +121 -0
- package/templates/.claude/skills/requirements-validator/references/scoring-system.md +134 -0
- package/templates/.claude/skills/requirements-validator/references/smart-criteria.md +130 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/SKILL.md +194 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/examples/noom-cjm-example.md +100 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/examples/noom-module1-example.md +88 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/01-intelligence.md +328 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/02-product-customers.md +221 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/025-cjm-prototype.md +206 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/03-market-competition.md +402 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/04-business-finance.md +287 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/05-growth-engine.md +290 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/modules/06-playbook-synthesis.md +286 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/references/blue-ocean-canvas.md +39 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/references/industry-benchmarks.md +67 -0
- package/templates/.claude/skills/reverse-engineering-unicorn/references/jtbd-canvas.md +48 -0
- package/templates/.claude/skills/sparc-prd-mini/SKILL.md +955 -0
- package/templates/.claude/skills/sparc-prd-mini/references/sparc-methodology.md +360 -0
- package/templates/.claude/skills/sparc-prd-mini/templates/CLAUDE.md +91 -0
- package/templates/.claude/skills/sparc-prd-mini/templates/prd.md +336 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: knowledge-extractor
|
|
3
|
+
description: >
|
|
4
|
+
Systematic knowledge extraction from completed projects into reusable toolkit artifacts.
|
|
5
|
+
Converts project-specific code, patterns, and lessons into decontextualized, versioned,
|
|
6
|
+
composable artifacts (skills, commands, hooks, rules, templates, patterns, snippets).
|
|
7
|
+
Supports two extraction modes: continuous markers during work and dedicated harvest sessions.
|
|
8
|
+
Uses swarm agents for parallel extraction across artifact categories. Domain-agnostic —
|
|
9
|
+
works with any tech stack, language, or project type.
|
|
10
|
+
Triggers: "harvest", "extract knowledge", "toolkit harvest", "извлечь знания",
|
|
11
|
+
"ритуал извлечения", "harvest session", "что забрать в тулкит".
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Knowledge Extractor: Project → Reusable Toolkit Artifacts
|
|
15
|
+
|
|
16
|
+
Systematically extract valuable knowledge from completed projects and transform it into
|
|
17
|
+
reusable, decontextualized toolkit artifacts. Lightweight process — not a quarterly review,
|
|
18
|
+
but a natural part of every project/sprint lifecycle.
|
|
19
|
+
|
|
20
|
+
## Architecture
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
knowledge-extractor/
|
|
24
|
+
├── SKILL.md # Orchestrator (this file)
|
|
25
|
+
├── modules/
|
|
26
|
+
│ ├── 01-agent-review.md # Phase 1: AI-assisted project review
|
|
27
|
+
│ ├── 02-classify.md # Phase 2: Categorize into artifact types
|
|
28
|
+
│ ├── 03-decontextualize.md # Phase 3: Generalize before transfer
|
|
29
|
+
│ └── 04-integrate.md # Phase 4: Update toolkit index
|
|
30
|
+
├── references/
|
|
31
|
+
│ ├── artifact-categories.md # 7 artifact types with criteria
|
|
32
|
+
│ ├── maturity-model.md # Artifact lifecycle & versioning
|
|
33
|
+
│ └── decontextualization-guide.md # How to generalize artifacts
|
|
34
|
+
├── templates/
|
|
35
|
+
│ ├── toolkit-harvest.md # TOOLKIT_HARVEST.md for projects
|
|
36
|
+
│ ├── artifact-card.md # Universal artifact documentation
|
|
37
|
+
│ └── harvest-report.md # Harvest session output report
|
|
38
|
+
└── examples/
|
|
39
|
+
└── rate-limiting-extraction.md # End-to-end extraction example
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## External Dependencies (loaded via view() at runtime)
|
|
43
|
+
|
|
44
|
+
| Skill | When Used | Purpose |
|
|
45
|
+
|-------|-----------|---------|
|
|
46
|
+
| `explore` | Phase 1 (if scope unclear) | Clarify what to extract |
|
|
47
|
+
| `brutal-honesty-review` | Phase 3 (quality check) | BS-detect unworthy artifacts |
|
|
48
|
+
| `pipeline-forge` | Phase 4 (if creating new skills) | Structure new skills properly |
|
|
49
|
+
|
|
50
|
+
**Fallbacks:**
|
|
51
|
+
- `explore` unavailable → built-in 3 clarification questions
|
|
52
|
+
- `brutal-honesty-review` unavailable → built-in quality checklist
|
|
53
|
+
- `pipeline-forge` unavailable → use `templates/artifact-card.md` directly
|
|
54
|
+
|
|
55
|
+
## When to Use
|
|
56
|
+
|
|
57
|
+
**Trigger Patterns:**
|
|
58
|
+
- "harvest this project" / "extract knowledge"
|
|
59
|
+
- "toolkit harvest" / "harvest session"
|
|
60
|
+
- "что забрать в тулкит" / "ритуал извлечения"
|
|
61
|
+
- "обобщи паттерны из проекта"
|
|
62
|
+
- After merging final PR / tagging release / completing sprint
|
|
63
|
+
- When `TOOLKIT_HARVEST.md` exists in project
|
|
64
|
+
|
|
65
|
+
**Two Extraction Moments:**
|
|
66
|
+
|
|
67
|
+
| Moment | Effort | Duration | Output |
|
|
68
|
+
|--------|--------|----------|--------|
|
|
69
|
+
| **During work** | 30 seconds per marker | Continuous | `TOOLKIT_HARVEST.md` markers |
|
|
70
|
+
| **After completion** | Dedicated session | 30-60 minutes | Generalized toolkit artifacts |
|
|
71
|
+
|
|
72
|
+
## Operating Modes
|
|
73
|
+
|
|
74
|
+
| Mode | Triggers | Checkpoints | Time |
|
|
75
|
+
|------|----------|-------------|------|
|
|
76
|
+
| **MARKER** | "mark for harvest", "пометь" | 0 | ~30 sec |
|
|
77
|
+
| **QUICK** | "quick harvest", "auto" | 1 | ~15 min |
|
|
78
|
+
| **FULL** | "full harvest", "harvest session" | 4 | ~45 min |
|
|
79
|
+
| **AUDIT** | "audit toolkit", "check maturity" | 1 | ~10 min |
|
|
80
|
+
|
|
81
|
+
## Pipeline
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
INPUT: Project codebase + TOOLKIT_HARVEST.md (optional)
|
|
85
|
+
↓
|
|
86
|
+
MODE: MARKER ──→ Append to TOOLKIT_HARVEST.md ──→ DONE
|
|
87
|
+
↓
|
|
88
|
+
PHASE 1: AGENT REVIEW (swarm)
|
|
89
|
+
Parallel agents scan: code, patterns, commands, errors, workarounds
|
|
90
|
+
→ Raw Findings List
|
|
91
|
+
⏸️ CHECKPOINT 1
|
|
92
|
+
↓
|
|
93
|
+
PHASE 2: CLASSIFY
|
|
94
|
+
Map findings to 7 artifact categories
|
|
95
|
+
Filter: what belongs, what doesn't
|
|
96
|
+
→ Classified Artifact List
|
|
97
|
+
⏸️ CHECKPOINT 2
|
|
98
|
+
↓
|
|
99
|
+
PHASE 3: DECONTEXTUALIZE
|
|
100
|
+
Generalize each artifact: remove project specifics
|
|
101
|
+
Document: when to use, prerequisites, maturity
|
|
102
|
+
Quality check: is it truly reusable?
|
|
103
|
+
→ Generalized Artifacts
|
|
104
|
+
⏸️ CHECKPOINT 3
|
|
105
|
+
↓
|
|
106
|
+
PHASE 4: INTEGRATE
|
|
107
|
+
Write artifacts to toolkit structure
|
|
108
|
+
Update toolkit index (CLAUDE.md or manifest)
|
|
109
|
+
Set maturity level, record provenance
|
|
110
|
+
→ Updated Toolkit
|
|
111
|
+
⏸️ CHECKPOINT 4 (FINAL)
|
|
112
|
+
↓
|
|
113
|
+
OUTPUT: Harvest Report + Updated Toolkit
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Execution Protocol
|
|
117
|
+
|
|
118
|
+
### Mode: MARKER (continuous, during work)
|
|
119
|
+
|
|
120
|
+
When user notices something worth extracting:
|
|
121
|
+
|
|
122
|
+
1. Check if `TOOLKIT_HARVEST.md` exists in project root
|
|
123
|
+
2. If not, create from `templates/toolkit-harvest.md`
|
|
124
|
+
3. Append the marker under the appropriate category
|
|
125
|
+
4. Done — no interruption to workflow
|
|
126
|
+
|
|
127
|
+
**Example:**
|
|
128
|
+
```markdown
|
|
129
|
+
## Паттерны
|
|
130
|
+
- [ ] Retry с exponential backoff — получился универсальнее, см. src/utils/retry.ts
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### Phase 1: AGENT REVIEW
|
|
136
|
+
|
|
137
|
+
Read module: `modules/01-agent-review.md`
|
|
138
|
+
|
|
139
|
+
**Goal:** Find all extractable knowledge in the project using parallel agents.
|
|
140
|
+
|
|
141
|
+
**Swarm Strategy — 5 parallel extraction agents:**
|
|
142
|
+
|
|
143
|
+
| Agent | Scope | What It Looks For |
|
|
144
|
+
|-------|-------|-------------------|
|
|
145
|
+
| `extractor-patterns` | Architecture & code patterns | Reusable architectural patterns, middleware, error handling |
|
|
146
|
+
| `extractor-commands` | Scripts & CLI utilities | Slash commands, build scripts, dev utilities |
|
|
147
|
+
| `extractor-rules` | Constraints & workarounds | Edge cases, "don't do X because Y", library quirks |
|
|
148
|
+
| `extractor-templates` | File structures & configs | Reusable configs, project templates, scaffolds |
|
|
149
|
+
| `extractor-snippets` | Code fragments | Universal functions, helpers, one-liners |
|
|
150
|
+
|
|
151
|
+
**Each agent:**
|
|
152
|
+
1. Scans relevant parts of the codebase
|
|
153
|
+
2. Reads `TOOLKIT_HARVEST.md` markers (if exists)
|
|
154
|
+
3. Returns list of candidates with file references
|
|
155
|
+
|
|
156
|
+
**Merge strategy:** Deduplicate, combine related findings.
|
|
157
|
+
|
|
158
|
+
**Output — Raw Findings List:**
|
|
159
|
+
```markdown
|
|
160
|
+
## Raw Findings
|
|
161
|
+
|
|
162
|
+
| # | Finding | Source File | Category (tentative) | Agent |
|
|
163
|
+
|---|---------|------------|---------------------|-------|
|
|
164
|
+
| 1 | Universal retry with backoff | src/utils/retry.ts | Pattern | extractor-patterns |
|
|
165
|
+
| 2 | /db-migrate command | scripts/migrate.sh | Command | extractor-commands |
|
|
166
|
+
| 3 | Don't use nested generics >3 | multiple | Rule | extractor-rules |
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Checkpoint:**
|
|
170
|
+
```
|
|
171
|
+
═══════════════════════════════════════════════════════════════
|
|
172
|
+
✅ PHASE 1: AGENT REVIEW COMPLETE
|
|
173
|
+
Found: [N] candidates from [M] agents
|
|
174
|
+
⏸️ "ок" — classify | "добавь [finding]" | "убери #N"
|
|
175
|
+
═══════════════════════════════════════════════════════════════
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### Phase 2: CLASSIFY
|
|
181
|
+
|
|
182
|
+
Read module: `modules/02-classify.md`
|
|
183
|
+
|
|
184
|
+
**Goal:** Map each finding to one of 7 artifact categories and filter out non-extractables.
|
|
185
|
+
|
|
186
|
+
**7 Artifact Categories:**
|
|
187
|
+
|
|
188
|
+
| Category | Directory | What Goes Here | Example |
|
|
189
|
+
|----------|-----------|---------------|---------|
|
|
190
|
+
| **Skills** | `skills/` | New or improved SKILL.md | Better DB migration technique |
|
|
191
|
+
| **Commands** | `commands/` | Slash commands for Claude Code | `/api-endpoint` generates CRUD |
|
|
192
|
+
| **Hooks** | `hooks/` | Pre-commit, post-task automation | Auto-validate OpenAPI schema |
|
|
193
|
+
| **Rules** | `rules/` | Constraints and limitations | "Don't use X pattern because Y" |
|
|
194
|
+
| **Templates** | `templates/` | Reusable file/project structures | Updated Dockerfile template |
|
|
195
|
+
| **Patterns** | `patterns/` | Architectural approaches as docs | Event sourcing + CQRS pattern |
|
|
196
|
+
| **Snippets** | `snippets/` | Small ready-to-use code fragments | Universal error handler |
|
|
197
|
+
|
|
198
|
+
See `references/artifact-categories.md` for detailed criteria.
|
|
199
|
+
|
|
200
|
+
**Exclusion Filter — Do NOT extract:**
|
|
201
|
+
- Domain-specific code that doesn't generalize
|
|
202
|
+
- Patterns used once and unvalidated
|
|
203
|
+
- Library-specific workarounds (they age badly)
|
|
204
|
+
- Secrets, credentials, API keys
|
|
205
|
+
- Hardcoded business logic
|
|
206
|
+
|
|
207
|
+
**Output — Classified Artifact List:**
|
|
208
|
+
```markdown
|
|
209
|
+
## Classified Artifacts
|
|
210
|
+
|
|
211
|
+
### ✅ Extract (N artifacts)
|
|
212
|
+
| # | Artifact | Category | Confidence | Notes |
|
|
213
|
+
|---|----------|----------|------------|-------|
|
|
214
|
+
| 1 | Retry with backoff | Pattern | HIGH | Universal, works with any HTTP client |
|
|
215
|
+
| 2 | /db-migrate | Command | MEDIUM | Needs decontextualization |
|
|
216
|
+
|
|
217
|
+
### ❌ Skip (M items)
|
|
218
|
+
| # | Finding | Reason |
|
|
219
|
+
|---|---------|--------|
|
|
220
|
+
| 3 | Auth middleware | Domain-specific, not generalizable |
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Checkpoint:**
|
|
224
|
+
```
|
|
225
|
+
═══════════════════════════════════════════════════════════════
|
|
226
|
+
✅ PHASE 2: CLASSIFICATION COMPLETE
|
|
227
|
+
Extract: [N] artifacts | Skip: [M] items
|
|
228
|
+
Categories: Skills [X], Commands [Y], Patterns [Z], ...
|
|
229
|
+
⏸️ "ок" — decontextualize | "переклассифицируй #N" | "верни #M"
|
|
230
|
+
═══════════════════════════════════════════════════════════════
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### Phase 3: DECONTEXTUALIZE
|
|
236
|
+
|
|
237
|
+
Read module: `modules/03-decontextualize.md`
|
|
238
|
+
|
|
239
|
+
**Goal:** Transform project-specific artifacts into reusable, documented toolkit entries.
|
|
240
|
+
|
|
241
|
+
**The 3-Step Decontextualization:**
|
|
242
|
+
|
|
243
|
+
1. **Remove project specifics** — replace concrete names, paths, configs with parameters/placeholders
|
|
244
|
+
2. **Document usage** — when to use, when NOT to use, prerequisites, variants
|
|
245
|
+
3. **Version & provenance** — maturity level, source project, changelog
|
|
246
|
+
|
|
247
|
+
See `references/decontextualization-guide.md` for detailed process.
|
|
248
|
+
|
|
249
|
+
**Quality Gate (per artifact):**
|
|
250
|
+
|
|
251
|
+
| Check | Threshold | Blocking? |
|
|
252
|
+
|-------|-----------|-----------|
|
|
253
|
+
| No project-specific references | 0 remaining | Yes |
|
|
254
|
+
| "When to use" section present | Must exist | Yes |
|
|
255
|
+
| At least 1 usage variant | Must exist | No |
|
|
256
|
+
| Code compiles/runs standalone | Must pass | Yes (for code) |
|
|
257
|
+
| Maturity level assigned | Must exist | Yes |
|
|
258
|
+
|
|
259
|
+
**If `brutal-honesty-review` available:**
|
|
260
|
+
Apply Bach-mode BS detection: "Is this actually reusable, or are we fooling ourselves?"
|
|
261
|
+
|
|
262
|
+
**Output — Generalized Artifacts:**
|
|
263
|
+
Each artifact documented using `templates/artifact-card.md` format.
|
|
264
|
+
|
|
265
|
+
**Checkpoint:**
|
|
266
|
+
```
|
|
267
|
+
═══════════════════════════════════════════════════════════════
|
|
268
|
+
✅ PHASE 3: DECONTEXTUALIZATION COMPLETE
|
|
269
|
+
Generalized: [N] artifacts
|
|
270
|
+
Quality gate: [M] passed, [K] need fixes
|
|
271
|
+
⏸️ "ок" — integrate | "доработай #N" | "покажи #N"
|
|
272
|
+
═══════════════════════════════════════════════════════════════
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
### Phase 4: INTEGRATE
|
|
278
|
+
|
|
279
|
+
Read module: `modules/04-integrate.md`
|
|
280
|
+
|
|
281
|
+
**Goal:** Write artifacts to toolkit and update the index.
|
|
282
|
+
|
|
283
|
+
**Process:**
|
|
284
|
+
1. For each artifact, write to appropriate toolkit location
|
|
285
|
+
2. If artifact already exists → merge (update version, add variants)
|
|
286
|
+
3. Update toolkit index (CLAUDE.md or manifest file)
|
|
287
|
+
4. Record provenance (source project, date, version)
|
|
288
|
+
5. Generate Harvest Report
|
|
289
|
+
|
|
290
|
+
**Maturity Assignment:**
|
|
291
|
+
See `references/maturity-model.md`
|
|
292
|
+
|
|
293
|
+
| Level | Symbol | Meaning |
|
|
294
|
+
|-------|--------|---------|
|
|
295
|
+
| Alpha | 🔴 | First extraction, untested outside source project |
|
|
296
|
+
| Beta | 🟡 | Used in 2+ projects, edge cases found |
|
|
297
|
+
| Stable | 🟢 | Used in 3+ projects, documented, trustworthy |
|
|
298
|
+
|
|
299
|
+
**Toolkit Index Format:**
|
|
300
|
+
```markdown
|
|
301
|
+
## Toolkit Index
|
|
302
|
+
|
|
303
|
+
### Skills
|
|
304
|
+
| Skill | Maturity | Last Updated | Source |
|
|
305
|
+
|-------|----------|-------------|--------|
|
|
306
|
+
|
|
307
|
+
### Patterns
|
|
308
|
+
| Pattern | Maturity | Last Updated | Source |
|
|
309
|
+
|---------|----------|-------------|--------|
|
|
310
|
+
|
|
311
|
+
### Commands
|
|
312
|
+
| Command | Maturity | Last Updated | Source |
|
|
313
|
+
|---------|----------|-------------|--------|
|
|
314
|
+
|
|
315
|
+
[... for each category]
|
|
316
|
+
|
|
317
|
+
Last harvest: [DATE]
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Output — Harvest Report:**
|
|
321
|
+
See `templates/harvest-report.md`
|
|
322
|
+
|
|
323
|
+
**Final Checkpoint:**
|
|
324
|
+
```
|
|
325
|
+
═══════════════════════════════════════════════════════════════
|
|
326
|
+
✅ HARVEST COMPLETE
|
|
327
|
+
|
|
328
|
+
📊 Results:
|
|
329
|
+
- Scanned: [N] files
|
|
330
|
+
- Found: [M] candidates
|
|
331
|
+
- Extracted: [K] artifacts
|
|
332
|
+
- Skills: [X] | Patterns: [Y] | Commands: [Z]
|
|
333
|
+
- Rules: [A] | Templates: [B] | Snippets: [C] | Hooks: [D]
|
|
334
|
+
- Maturity: 🔴 Alpha: [N] | 🟡 Beta: [M] | 🟢 Stable: [K]
|
|
335
|
+
|
|
336
|
+
📁 Written to: [toolkit path]
|
|
337
|
+
📋 Report: [report path]
|
|
338
|
+
|
|
339
|
+
🔄 Automation tip:
|
|
340
|
+
Add to git hooks or CI to remind about harvest on release.
|
|
341
|
+
═══════════════════════════════════════════════════════════════
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Automation Hook
|
|
347
|
+
|
|
348
|
+
To ensure harvest happens naturally, add this to project's `.claude/settings.json`:
|
|
349
|
+
|
|
350
|
+
```json
|
|
351
|
+
{
|
|
352
|
+
"hooks": {
|
|
353
|
+
"PostToolUse": [
|
|
354
|
+
{
|
|
355
|
+
"matcher": "Bash",
|
|
356
|
+
"pattern": "git tag v",
|
|
357
|
+
"command": "echo '🌾 Release tagged. Consider running /harvest for toolkit extraction.'"
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Or as a git hook reminder:
|
|
365
|
+
```bash
|
|
366
|
+
# .git/hooks/post-merge (on merge to main)
|
|
367
|
+
echo "🌾 Merge to main complete. Run '/harvest' to extract reusable knowledge."
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Integration with Other Skills
|
|
371
|
+
|
|
372
|
+
| Skill | Integration Point | Purpose |
|
|
373
|
+
|-------|-------------------|---------|
|
|
374
|
+
| `explore` | Phase 1 (scope) | Clarify what's worth extracting |
|
|
375
|
+
| `brutal-honesty-review` | Phase 3 (quality) | BS-detect unworthy artifacts |
|
|
376
|
+
| `pipeline-forge` | Phase 4 (skills) | Properly structure new skills |
|
|
377
|
+
| `requirements-validator` | Phase 3 (validation) | Validate extracted requirements |
|
|
378
|
+
| `problem-solver-enhanced` | Phase 3 (conflicts) | Resolve generalization conflicts via TRIZ |
|
|
379
|
+
|
|
380
|
+
## Anti-Patterns
|
|
381
|
+
|
|
382
|
+
❌ **Just copying** — artifacts must be decontextualized, not copy-pasted
|
|
383
|
+
❌ **Extracting everything** — if it's domain-specific, it doesn't belong
|
|
384
|
+
❌ **No documentation** — undocumented artifacts become technical debt
|
|
385
|
+
❌ **Skipping maturity** — trust level must be explicit
|
|
386
|
+
❌ **One-time use patterns** — wait for 2+ projects before promoting to Beta
|
|
387
|
+
❌ **Library workarounds** — they expire; only add as temporary rules with review dates
|
|
388
|
+
❌ **Heroic quarterly reviews** — extract continuously, harvest frequently
|
|
389
|
+
❌ **No provenance** — always record source project and date
|
|
390
|
+
|
|
391
|
+
## Quality Standards
|
|
392
|
+
|
|
393
|
+
- [ ] Every artifact has "When to use" section
|
|
394
|
+
- [ ] Every artifact has maturity level (🔴/🟡/🟢)
|
|
395
|
+
- [ ] No project-specific references in generalized artifacts
|
|
396
|
+
- [ ] Toolkit index is up to date
|
|
397
|
+
- [ ] Exclusion list applied (no domain code, no unvalidated patterns)
|
|
398
|
+
- [ ] Provenance recorded (source project, version, date)
|
|
399
|
+
- [ ] At least one usage variant documented
|
|
400
|
+
|
|
401
|
+
## Checkpoint Commands
|
|
402
|
+
|
|
403
|
+
| Command | Action | Available |
|
|
404
|
+
|---------|--------|-----------|
|
|
405
|
+
| `ок` / `далее` | Next phase | All |
|
|
406
|
+
| `добавь [finding]` | Add manual finding | Phase 1 |
|
|
407
|
+
| `убери #N` | Remove finding | Phase 1-2 |
|
|
408
|
+
| `переклассифицируй #N` | Change category | Phase 2 |
|
|
409
|
+
| `верни #M` | Un-skip excluded item | Phase 2 |
|
|
410
|
+
| `доработай #N` | Improve artifact | Phase 3 |
|
|
411
|
+
| `покажи #N` | Preview artifact | Phase 3-4 |
|
|
412
|
+
| `стоп` | Pause with save | All |
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Example: Rate Limiting Pattern Extraction
|
|
2
|
+
|
|
3
|
+
End-to-end example of extracting a rate limiting middleware from a project
|
|
4
|
+
into a reusable toolkit artifact.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Source: auth-service project
|
|
9
|
+
|
|
10
|
+
### Original Code
|
|
11
|
+
|
|
12
|
+
```rust
|
|
13
|
+
// auth-service/src/middleware/rate_limit.rs
|
|
14
|
+
use crate::config::AuthConfig;
|
|
15
|
+
use crate::models::User;
|
|
16
|
+
|
|
17
|
+
pub struct RateLimiter {
|
|
18
|
+
max_requests: u32,
|
|
19
|
+
window_secs: u64,
|
|
20
|
+
store: HashMap<UserId, Vec<Timestamp>>,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
pub fn rate_limit(config: &AuthConfig) -> RateLimiter {
|
|
24
|
+
RateLimiter::new(config.max_requests, config.window_secs)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl RateLimiter {
|
|
28
|
+
pub fn check(&mut self, user: &User) -> Result<(), RateLimitError> {
|
|
29
|
+
let now = Utc::now();
|
|
30
|
+
let window_start = now - Duration::seconds(self.window_secs as i64);
|
|
31
|
+
|
|
32
|
+
let requests = self.store
|
|
33
|
+
.entry(user.id)
|
|
34
|
+
.or_default();
|
|
35
|
+
|
|
36
|
+
// Remove expired entries
|
|
37
|
+
requests.retain(|ts| *ts > window_start);
|
|
38
|
+
|
|
39
|
+
if requests.len() >= self.max_requests as usize {
|
|
40
|
+
return Err(RateLimitError::TooManyRequests {
|
|
41
|
+
user_id: user.id,
|
|
42
|
+
limit: self.max_requests,
|
|
43
|
+
retry_after: self.window_secs,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
requests.push(now);
|
|
48
|
+
Ok(())
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### TOOLKIT_HARVEST.md Marker (during work)
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
## Patterns
|
|
57
|
+
- [ ] Rate limiting middleware — получился универсальнее чем обычно, см. src/middleware/rate_limit.rs
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Phase 1: Agent Review
|
|
63
|
+
|
|
64
|
+
**extractor-patterns** found:
|
|
65
|
+
```
|
|
66
|
+
- Name: Rate Limiting Middleware
|
|
67
|
+
- File: src/middleware/rate_limit.rs:1-35
|
|
68
|
+
- Description: Sliding window rate limiter with per-user tracking
|
|
69
|
+
- Reusability: HIGH
|
|
70
|
+
- Why reusable: Core algorithm is generic, only config is project-specific
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Phase 2: Classify
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Category: Pattern (architectural approach, multiple implementations possible)
|
|
77
|
+
Secondary: Snippet (core algorithm is <50 lines)
|
|
78
|
+
Confidence: HIGH
|
|
79
|
+
Note: Needs decontextualization — currently tied to AuthConfig and User model
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Phase 3: Decontextualize
|
|
83
|
+
|
|
84
|
+
### Step 1: Remove project specifics
|
|
85
|
+
|
|
86
|
+
| Before | After |
|
|
87
|
+
|--------|-------|
|
|
88
|
+
| `AuthConfig` | `RateLimitConfig` trait |
|
|
89
|
+
| `User` / `UserId` | `SubjectId: String` |
|
|
90
|
+
| `crate::config` import | Standalone |
|
|
91
|
+
| `crate::models` import | Standalone |
|
|
92
|
+
|
|
93
|
+
### Step 2: Document usage
|
|
94
|
+
|
|
95
|
+
See final artifact below.
|
|
96
|
+
|
|
97
|
+
### Step 3: Version & provenance
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Maturity: 🔴 Alpha
|
|
101
|
+
Used in: auth-service
|
|
102
|
+
Extracted: 2026-03-01
|
|
103
|
+
Version: v1.0
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Quality gate:
|
|
107
|
+
|
|
108
|
+
| Check | Status |
|
|
109
|
+
|-------|--------|
|
|
110
|
+
| No project-specific names | ✅ |
|
|
111
|
+
| No hardcoded paths | ✅ |
|
|
112
|
+
| "When to use" present | ✅ |
|
|
113
|
+
| "When NOT to use" present | ✅ |
|
|
114
|
+
| Prerequisites documented | ✅ |
|
|
115
|
+
| At least 1 variant | ✅ (Redis) |
|
|
116
|
+
| Code compiles standalone | ✅ |
|
|
117
|
+
| Maturity assigned | ✅ |
|
|
118
|
+
|
|
119
|
+
## Phase 4: Integrate
|
|
120
|
+
|
|
121
|
+
### Final Artifact: `patterns/rate-limiting.md`
|
|
122
|
+
|
|
123
|
+
```markdown
|
|
124
|
+
# Pattern: Rate Limiting
|
|
125
|
+
|
|
126
|
+
## Maturity: 🔴 Alpha
|
|
127
|
+
## Used in: auth-service
|
|
128
|
+
## Extracted: 2026-03-01
|
|
129
|
+
## Last updated: 2026-03-01
|
|
130
|
+
## Version: v1.0
|
|
131
|
+
|
|
132
|
+
## When to Use
|
|
133
|
+
|
|
134
|
+
- Any HTTP API exposed to external clients
|
|
135
|
+
- Services with expensive operations that need throttling
|
|
136
|
+
- Multi-tenant systems with per-tenant quotas
|
|
137
|
+
- APIs that call rate-limited external services
|
|
138
|
+
|
|
139
|
+
## When NOT to Use
|
|
140
|
+
|
|
141
|
+
- Internal service-to-service calls (use circuit breaker instead)
|
|
142
|
+
- Read-only cache endpoints (overhead not worth it)
|
|
143
|
+
- WebSocket connections (use connection-level limits instead)
|
|
144
|
+
|
|
145
|
+
## Prerequisites
|
|
146
|
+
|
|
147
|
+
- A way to identify the request subject (user ID, API key, IP)
|
|
148
|
+
- Storage for request counts (in-memory or distributed)
|
|
149
|
+
- Configurable limits (per-subject or global)
|
|
150
|
+
|
|
151
|
+
## Implementation
|
|
152
|
+
|
|
153
|
+
### Core Algorithm: Sliding Window
|
|
154
|
+
|
|
155
|
+
```rust
|
|
156
|
+
pub trait RateLimitConfig {
|
|
157
|
+
fn max_requests(&self) -> u32;
|
|
158
|
+
fn window_duration(&self) -> Duration;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub struct SlidingWindowLimiter<K: Hash + Eq> {
|
|
162
|
+
config: Box<dyn RateLimitConfig>,
|
|
163
|
+
windows: HashMap<K, Vec<Instant>>,
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
impl<K: Hash + Eq> SlidingWindowLimiter<K> {
|
|
167
|
+
pub fn check(&mut self, subject: &K) -> Result<(), RateLimitError> {
|
|
168
|
+
let now = Instant::now();
|
|
169
|
+
let window_start = now - self.config.window_duration();
|
|
170
|
+
|
|
171
|
+
let requests = self.windows.entry(subject.clone()).or_default();
|
|
172
|
+
requests.retain(|ts| *ts > window_start);
|
|
173
|
+
|
|
174
|
+
if requests.len() >= self.config.max_requests() as usize {
|
|
175
|
+
return Err(RateLimitError::Exceeded {
|
|
176
|
+
limit: self.config.max_requests(),
|
|
177
|
+
retry_after: self.config.window_duration(),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
requests.push(now);
|
|
182
|
+
Ok(())
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Variants
|
|
188
|
+
|
|
189
|
+
### Variant A: In-Memory (single instance)
|
|
190
|
+
|
|
191
|
+
Use the implementation above. Good for:
|
|
192
|
+
- Single-server deployments
|
|
193
|
+
- Development environments
|
|
194
|
+
- Low-traffic services
|
|
195
|
+
|
|
196
|
+
Trade-off: Resets on restart, doesn't share across instances.
|
|
197
|
+
|
|
198
|
+
### Variant B: Redis-backed (distributed)
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
import redis
|
|
202
|
+
import time
|
|
203
|
+
|
|
204
|
+
class RedisRateLimiter:
|
|
205
|
+
def __init__(self, redis_client, max_requests, window_seconds):
|
|
206
|
+
self.redis = redis_client
|
|
207
|
+
self.max_requests = max_requests
|
|
208
|
+
self.window = window_seconds
|
|
209
|
+
|
|
210
|
+
def check(self, subject_id: str) -> bool:
|
|
211
|
+
key = f"ratelimit:{subject_id}"
|
|
212
|
+
now = time.time()
|
|
213
|
+
pipe = self.redis.pipeline()
|
|
214
|
+
pipe.zremrangebyscore(key, 0, now - self.window)
|
|
215
|
+
pipe.zadd(key, {str(now): now})
|
|
216
|
+
pipe.zcard(key)
|
|
217
|
+
pipe.expire(key, self.window)
|
|
218
|
+
_, _, count, _ = pipe.execute()
|
|
219
|
+
return count <= self.max_requests
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Good for: distributed systems, multi-instance deployments.
|
|
223
|
+
|
|
224
|
+
### Variant C: Token Bucket
|
|
225
|
+
|
|
226
|
+
Better for bursty traffic patterns. Allows short bursts while
|
|
227
|
+
maintaining average rate.
|
|
228
|
+
|
|
229
|
+
## Gotchas
|
|
230
|
+
|
|
231
|
+
- In-memory variant resets on restart — clients may see sudden burst of allowed requests
|
|
232
|
+
- Redis variant needs MULTI/EXEC for atomicity
|
|
233
|
+
- Don't forget to set TTL on Redis keys to prevent memory leak
|
|
234
|
+
- Consider returning `Retry-After` header with the rate limit response
|
|
235
|
+
|
|
236
|
+
## Related Artifacts
|
|
237
|
+
|
|
238
|
+
- Circuit Breaker pattern — complementary, for downstream protection
|
|
239
|
+
- Rule: "Sequential API calls for rate-limited services" — client-side rate limiting
|
|
240
|
+
|
|
241
|
+
## Changelog
|
|
242
|
+
- v1.0: Initial extraction from auth-service project
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Harvest Report Entry
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
| 1 | Rate Limiting | Pattern | 🔴 Alpha | v1.0 | patterns/rate-limiting.md |
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Key Takeaways
|
|
254
|
+
|
|
255
|
+
1. Original code: 35 lines, tightly coupled to AuthConfig + User
|
|
256
|
+
2. Extracted artifact: 100+ lines of docs, 3 variants, standalone
|
|
257
|
+
3. The PRINCIPLE (sliding window rate limiting) is universal
|
|
258
|
+
4. The IMPLEMENTATION needed generics/traits to decontextualize
|
|
259
|
+
5. Adding Redis variant immediately increased value
|