@dzhechkov/keysarium 1.3.0 → 1.5.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.
Files changed (105) hide show
  1. package/README.md +70 -10
  2. package/bin/cli.js +0 -0
  3. package/package.json +5 -3
  4. package/src/utils.js +1 -1
  5. package/templates/.claude/commands/analyst-manual.md +38 -0
  6. package/templates/.claude/commands/brain-export.md +2 -0
  7. package/templates/.claude/commands/bto-benchmark.md +302 -0
  8. package/templates/.claude/commands/casarium.md +55 -4
  9. package/templates/.claude/commands/feature-adr.md +8 -0
  10. package/templates/.claude/commands/harvest.md +28 -46
  11. package/templates/.claude/rules/trust-tiers.md +6 -0
  12. package/templates/.claude/shards/feature-adr.shard.md +64 -10
  13. package/templates/.claude/shards/phase-ai-factory.shard.md +109 -0
  14. package/templates/.claude/skills/ai-factory-mapper/README.md +90 -0
  15. package/templates/.claude/skills/ai-factory-mapper/SKILL.md +309 -0
  16. package/templates/.claude/skills/ai-factory-mapper/assets/report-template.md +123 -0
  17. package/templates/.claude/skills/ai-factory-mapper/references/catalog.md +230 -0
  18. package/templates/.claude/skills/ai-factory-mapper/references/coverage-formula.md +219 -0
  19. package/templates/.claude/skills/ai-factory-mapper/references/decomposition-checklist.md +183 -0
  20. package/templates/.claude/skills/ai-factory-mapper/references/pattern-library.md +312 -0
  21. package/templates/.claude/skills/ai-factory-mapper/scripts/build_docx_report.js +423 -0
  22. package/templates/.claude/skills/analyst-manual-full/SKILL.md +286 -0
  23. package/templates/.claude/skills/edu-site-generator/SKILL.md +254 -0
  24. package/templates/.claude/skills/edu-site-generator/examples/sample-course-structure.md +116 -0
  25. package/templates/.claude/skills/edu-site-generator/modules/00-content-analysis.md +84 -0
  26. package/templates/.claude/skills/edu-site-generator/modules/01-course-structure.md +75 -0
  27. package/templates/.claude/skills/edu-site-generator/modules/02-data-generation.md +186 -0
  28. package/templates/.claude/skills/edu-site-generator/modules/03-scaffold.md +249 -0
  29. package/templates/.claude/skills/edu-site-generator/modules/04-components.md +130 -0
  30. package/templates/.claude/skills/edu-site-generator/modules/05-gamification.md +163 -0
  31. package/templates/.claude/skills/edu-site-generator/modules/06-deploy.md +88 -0
  32. package/templates/.claude/skills/edu-site-generator/modules/07-verification.md +97 -0
  33. package/templates/.claude/skills/edu-site-generator/references/component-templates.md +436 -0
  34. package/templates/.claude/skills/edu-site-generator/references/data-schemas.md +164 -0
  35. package/templates/.claude/skills/edu-site-generator/references/exercise-catalog.md +110 -0
  36. package/templates/.claude/skills/edu-site-generator/references/tech-stack.md +69 -0
  37. package/templates/.claude/skills/feature-adr/SKILL.md +245 -59
  38. package/templates/.claude/skills/feature-adr/modules/03-adr.md +43 -0
  39. package/templates/.claude/skills/feature-adr/modules/03.5-ideation-swarm.md +180 -0
  40. package/templates/.claude/skills/feature-adr/modules/06-implementation-plan.md +56 -7
  41. package/templates/.claude/skills/feature-adr/modules/08-qe.md +87 -23
  42. package/templates/.claude/skills/feature-adr/modules/09-fleet-qe.md +305 -0
  43. package/templates/.claude/skills/feature-adr/references/agentic-qe/README.md +143 -0
  44. package/templates/.claude/skills/feature-adr/references/agentic-qe/brutal-honesty-review.md +240 -0
  45. package/templates/.claude/skills/feature-adr/references/agentic-qe/chaos-engineering-resilience.md +163 -0
  46. package/templates/.claude/skills/feature-adr/references/agentic-qe/code-goal-planner.md +446 -0
  47. package/templates/.claude/skills/feature-adr/references/agentic-qe/enterprise-integration-testing.md +111 -0
  48. package/templates/.claude/skills/feature-adr/references/agentic-qe/mutation-testing.md +236 -0
  49. package/templates/.claude/skills/feature-adr/references/agentic-qe/performance-testing.md +315 -0
  50. package/templates/.claude/skills/feature-adr/references/agentic-qe/qcsd-ideation-swarm.md +126 -0
  51. package/templates/.claude/skills/feature-adr/references/agentic-qe/qcsd-production-swarm.md +108 -0
  52. package/templates/.claude/skills/feature-adr/references/agentic-qe/qe-coverage-analysis.md +193 -0
  53. package/templates/.claude/skills/feature-adr/references/agentic-qe/qe-requirements-validation.md +254 -0
  54. package/templates/.claude/skills/feature-adr/references/agentic-qe/regression-testing.md +233 -0
  55. package/templates/.claude/skills/feature-adr/references/agentic-qe/risk-based-testing.md +212 -0
  56. package/templates/.claude/skills/feature-adr/references/agentic-qe/security-testing.md +311 -0
  57. package/templates/.claude/skills/feature-adr/references/agentic-qe/shift-left-testing.md +231 -0
  58. package/templates/.claude/skills/feature-adr/references/agentic-qe/tdd-london-chicago.md +249 -0
  59. package/templates/.claude/skills/knowledge-extractor/SKILL.md +254 -0
  60. package/templates/.claude/skills/knowledge-extractor/modules/01-extract.md +188 -0
  61. package/templates/.claude/skills/knowledge-extractor/modules/02-classify.md +99 -0
  62. package/templates/.claude/skills/knowledge-extractor/modules/03-gate.md +150 -0
  63. package/templates/.claude/skills/knowledge-extractor/modules/04-integrate.md +159 -0
  64. package/templates/.claude/skills/knowledge-extractor/references/artifact-categories.md +100 -0
  65. package/templates/.claude/skills/knowledge-extractor/references/maturity-model.md +94 -0
  66. package/templates/.claude/skills/knowledge-extractor/references/quality-gates.md +98 -0
  67. package/templates/.claude/skills/knowledge-extractor/templates/artifact-card.md +63 -0
  68. package/templates/.claude/skills/knowledge-extractor/templates/harvest-report.md +102 -0
  69. package/templates/.claude/skills/transcript-site-generator/SKILL.md +287 -0
  70. package/templates/.claude/skills/transcript-site-generator/examples/sample-text-only-site.md +123 -0
  71. package/templates/.claude/skills/transcript-site-generator/examples/sample-transcript-site.md +134 -0
  72. package/templates/.claude/skills/transcript-site-generator/modules/00-input-analysis.md +132 -0
  73. package/templates/.claude/skills/transcript-site-generator/modules/01-content-parsing.md +117 -0
  74. package/templates/.claude/skills/transcript-site-generator/modules/02-site-generation.md +293 -0
  75. package/templates/.claude/skills/transcript-site-generator/modules/03-interactivity.md +406 -0
  76. package/templates/.claude/skills/transcript-site-generator/modules/04-deploy.md +130 -0
  77. package/templates/.claude/skills/transcript-site-generator/modules/05-verification.md +155 -0
  78. package/templates/.claude/skills/transcript-site-generator/references/component-catalog.md +86 -0
  79. package/templates/.claude/skills/transcript-site-generator/references/data-schemas.md +123 -0
  80. package/templates/.claude/skills/transcript-site-generator/references/tech-stack.md +132 -0
  81. package/templates/CLAUDE.md +30 -9
  82. package/templates/docs/continuous-learning-guide.md +622 -0
  83. package/templates/docs/edu-site-generator/01-deployment-guide.md +911 -0
  84. package/templates/docs/edu-site-generator/02-admin-guide.md +901 -0
  85. package/templates/docs/edu-site-generator/03-user-guide.md +1008 -0
  86. package/templates/docs/edu-site-generator/04-infrastructure-requirements.md +489 -0
  87. package/templates/docs/edu-site-generator/05-architecture.md +902 -0
  88. package/templates/docs/edu-site-generator/06-user-flows.md +759 -0
  89. package/templates/docs/improvement-directions.md +8 -4
  90. package/templates/docs/keysarium-core/02-functionality.md +3 -1
  91. package/templates/docs/skills-bto/01-deployment-guide.md +1 -1
  92. package/templates/docs/skills-bto/02-admin-guide.md +4 -1
  93. package/templates/docs/skills-bto/03-user-guide.md +4 -3
  94. package/templates/docs/skills-bto/04-infrastructure-requirements.md +2 -1
  95. package/templates/docs/skills-bto/05-architecture.md +11 -11
  96. package/templates/docs/skills-bto/06-user-flows.md +2 -1
  97. package/templates/docs/transcript-site-generator/01-deployment-guide.md +1042 -0
  98. package/templates/docs/transcript-site-generator/02-admin-guide.md +918 -0
  99. package/templates/docs/transcript-site-generator/03-user-guide.md +925 -0
  100. package/templates/docs/transcript-site-generator/04-infrastructure-requirements.md +482 -0
  101. package/templates/docs/transcript-site-generator/05-architecture.md +1068 -0
  102. package/templates/docs/transcript-site-generator/06-user-flows.md +855 -0
  103. package/templates/lib/dream-engine.md +1 -1
  104. package/templates/lib/memory-protocol.md +6 -2
  105. package/templates/lib/reward-tracker.md +6 -3
@@ -0,0 +1,99 @@
1
+ # Classify Module — 7-Category Classification and Deduplication
2
+
3
+ ## Purpose
4
+
5
+ Assign each raw finding to one of 7 categories, deduplicate across agents, and cross-reference against existing toolkit entries.
6
+
7
+ ## Input
8
+
9
+ - Findings JSON file (from Module 01, status: `extracting` → set to `classifying`)
10
+ - `TOOLKIT_HARVEST.md` — existing entries to check for duplicates
11
+ - `references/artifact-categories.md` — category definitions and destination mapping
12
+
13
+ ## Protocol
14
+
15
+ ### Step 1: Load and Validate
16
+
17
+ 1. Read findings JSON file
18
+ 2. Verify all findings have status `raw`
19
+ 3. Set session status to `classifying`
20
+ 4. Read `references/artifact-categories.md` for category definitions
21
+
22
+ ### Step 2: Classify Each Finding
23
+
24
+ For each finding, assign a category based on content analysis:
25
+
26
+ | Category | Classification Signals |
27
+ |----------|----------------------|
28
+ | skills | Multi-step methodology, complete workflow, orchestrator + modules pattern |
29
+ | commands | Starts with `/` or describes a CLI invocation, has arguments/parameters |
30
+ | hooks | Triggered by an event, pre/post pattern, automation on lifecycle events |
31
+ | rules | Contains "must", "never", "always", constraints, anti-pattern tables |
32
+ | templates | Document skeleton, config file format, placeholder structure `{VAR}` |
33
+ | patterns | Architectural approach, design strategy, topology, reusable structure |
34
+ | snippets | Code block, function, component, < 50 lines, copy-paste ready |
35
+
36
+ **Tie-breaking rules:**
37
+ - If a finding could be both `patterns` and `skills` → prefer `patterns` unless it has modules/sub-components
38
+ - If a finding could be both `rules` and `patterns` → prefer `rules` if it's primarily a constraint
39
+ - If a finding could be both `templates` and `snippets` → prefer `templates` if it has placeholders, `snippets` if it's code
40
+
41
+ ### Step 3: Deduplicate
42
+
43
+ **Cross-agent dedup:** Compare all findings pairwise within the session using this algorithm:
44
+
45
+ 1. **Title similarity:** Normalize titles (lowercase, strip punctuation, remove stop words). Compute token overlap ratio: `shared_tokens / max(tokens_A, tokens_B)`.
46
+ 2. **Content similarity:** Extract the first 3 non-empty lines of each finding's `content` field. Compute 3-gram set overlap (Jaccard index): `|A ∩ B| / |A ∪ B|`.
47
+ 3. **Combined score:** `similarity = title_weight * title_sim + content_weight * content_sim` where `title_weight = 0.4`, `content_weight = 0.6`.
48
+ 4. **Threshold:** If `similarity >= 0.80` → duplicate. Keep the finding with higher confidence. Set the other's status to `removed`.
49
+ 5. Log: `"Dedup: #N removed (duplicate of #M, similarity: {score})"`
50
+
51
+ Note: Since an LLM is performing this comparison (not a deterministic function), the algorithm above provides guidance for consistent judgment. The orchestrator should evaluate each pair and apply the threshold consistently.
52
+
53
+ **Cross-toolkit dedup:** Compare findings against existing `TOOLKIT_HARVEST.md` entries:
54
+ 1. For each finding, scan TOOLKIT_HARVEST.md section headings and first paragraphs.
55
+ 2. If a finding's title matches an existing entry name (exact or near-match after normalization):
56
+ - Set finding's `duplicate_of` field to the existing entry name
57
+ - Flag for gate G6 (will be evaluated in Module 03)
58
+ 3. Near-duplicate range (0.70-0.85 similarity): propose a MERGE instead of flagging as duplicate.
59
+
60
+ ### Step 4: Cross-Reference
61
+
62
+ For each classified finding, check if it references or depends on existing toolkit items:
63
+ - If finding mentions a skill name → add cross-reference link
64
+ - If finding extends an existing pattern → note the relationship
65
+ - Record cross-references in the finding's metadata
66
+
67
+ ### Step 5: Write Results
68
+
69
+ 1. Update each finding in the JSON file with: `category`, `status: "classified"`
70
+ 2. Update session status
71
+ 3. Return classification summary for display
72
+
73
+ ## Output Format
74
+
75
+ The orchestrator displays classified findings grouped by category:
76
+
77
+ ```
78
+ ## patterns ({N} items)
79
+ #1 [0.85] Agent Swarm Topology — parallel agents with merge pattern
80
+ #4 [0.72] Event-Driven Pipeline — phase-to-phase data flow via files
81
+
82
+ ## rules ({N} items)
83
+ #2 [0.91] Domain Detection Rule — auto-detect domain from keywords
84
+ #7 [0.65] Regulatory Constraint — ФЗ-152 data isolation requirement
85
+
86
+ ## commands ({N} items)
87
+ ...
88
+
89
+ ## Removed by dedup: #5 (duplicate of #1), #9 (duplicate of #3)
90
+ ```
91
+
92
+ ## Anti-Patterns
93
+
94
+ | Anti-Pattern | Detection | Fix |
95
+ |-------------|-----------|-----|
96
+ | Everything classified as "patterns" | > 50% of findings in one category | Re-evaluate with stricter classification signals |
97
+ | Aggressive dedup removes valid findings | High similarity but different use cases | Compare "When to use" sections, not just content |
98
+ | Missing cross-references | Finding extends existing tool but no link | Check TOOLKIT_HARVEST.md entry names explicitly |
99
+ | Category mismatch with source lens | extractor-rules finding classified as pattern | Lens is a hint, not a binding — classify on content |
@@ -0,0 +1,150 @@
1
+ # Gate Module — 8 Quality Gates with 2-Pass Evaluation
2
+
3
+ ## Purpose
4
+
5
+ Evaluate each active finding against 8 quality gates using a two-pass approach: deterministic checks first (zero LLM cost), then semantic checks via haiku agent. Set finding status to `approved` or `blocked`.
6
+
7
+ ## Input
8
+
9
+ - Findings JSON file (from user checkpoint, active findings only)
10
+ - `references/quality-gates.md` — gate definitions, pass criteria, failure messages
11
+
12
+ ## Protocol
13
+
14
+ ### Step 1: Load Gate Definitions
15
+
16
+ ```
17
+ Read: references/quality-gates.md
18
+ ```
19
+
20
+ Load all 8 gate definitions with their type (deterministic/semantic) and pass criteria.
21
+
22
+ ### Step 2: Filter Active Findings
23
+
24
+ From the findings JSON, select only findings with status `classified` (not `removed` or `merged`).
25
+ These are the findings that survived the user checkpoint.
26
+
27
+ ### Step 3: Pass 1 — Deterministic Gates
28
+
29
+ For each active finding, evaluate deterministic gates. These are simple checks that require no LLM:
30
+
31
+ | Gate | Check Logic |
32
+ |------|------------|
33
+ | G1 | `finding.when_to_use` exists AND length > 10 characters |
34
+ | G2 | `finding.when_not_to_use` exists AND length > 10 characters |
35
+ | G5 | `finding.confidence >= 0.5` |
36
+ | G6 | `finding.duplicate_of` is null OR empty (set by Module 02) |
37
+ | G7 | `finding.maturity` is one of: `alpha`, `beta`, `stable` |
38
+
39
+ For each gate, record the result:
40
+ ```json
41
+ {
42
+ "gate_id": "G1",
43
+ "passed": true,
44
+ "evaluation_pass": "deterministic",
45
+ "reason": null
46
+ }
47
+ ```
48
+
49
+ If any deterministic gate fails, record the failure reason from `quality-gates.md`.
50
+
51
+ ### Step 4: Pass 2 — Semantic Gates
52
+
53
+ For findings that passed all deterministic gates (or for all findings if you want complete gate data), evaluate semantic gates using a haiku agent:
54
+
55
+ ```
56
+ Agent(
57
+ subagent_type="general-purpose",
58
+ model="haiku",
59
+ description="Harvest Gate Evaluator — semantic gates",
60
+ prompt="""
61
+ You are a quality gate evaluator. For each finding below, evaluate 3 semantic gates.
62
+ Be strict but fair. Err on the side of blocking rather than passing questionable findings.
63
+
64
+ ## Gates to Evaluate
65
+
66
+ **G3 — Decontextualized:**
67
+ Check if the finding contains project-specific references: variable names, file paths,
68
+ company names, dates, slugs, or any hardcoded values tied to the source project.
69
+ PASS if the finding is generic and reusable as-is.
70
+ FAIL if any project-specific detail remains.
71
+
72
+ **G4 — Concrete Example:**
73
+ Check if the finding includes at least one concrete, actionable example.
74
+ The example must show actual usage, not just describe it abstractly.
75
+ PASS if there is a real example with specifics.
76
+ FAIL if the example is vague, abstract, or missing.
77
+
78
+ **G8 — Brutal Honesty Review:**
79
+ Ask yourself: "Would a senior engineer actually find this useful in a different project?"
80
+ PASS only if the answer is genuinely yes — the finding adds real value.
81
+ FAIL if the finding is obvious, trivial, or too niche to be broadly useful.
82
+
83
+ ## Findings to Evaluate
84
+
85
+ {FINDINGS_LIST}
86
+
87
+ ## Required Output Format
88
+
89
+ For each finding, return:
90
+
91
+ Finding #N:
92
+ - G3: PASS/FAIL — [reason]
93
+ - G4: PASS/FAIL — [reason]
94
+ - G8: PASS/FAIL — [reason]
95
+ """
96
+ )
97
+ ```
98
+
99
+ ### Step 5: Set Approval Status
100
+
101
+ For each finding:
102
+ - If ALL 8 gates passed → status = `approved`
103
+ - If ANY gate failed → status = `blocked`, record failing gate IDs
104
+
105
+ Write results to findings JSON.
106
+
107
+ ### Step 6: Report Blocked Findings
108
+
109
+ The orchestrator displays blocked findings to the user:
110
+
111
+ ```
112
+ ✅ APPROVED: {N} findings passed all gates
113
+
114
+ ⚠️ BLOCKED: {M} findings failed quality gates:
115
+ #7 — G3 (project-specific references remain: mentions "bank-kc-automation")
116
+ #12 — G5 (confidence 0.35 < 0.5 threshold)
117
+ #14 — G4, G8 (no concrete example; fails brutal-honesty review)
118
+
119
+ Commands:
120
+ • "пропусти GN для #X" — override specific gate for specific finding
121
+ • "ок" — accept blocks, proceed with approved only
122
+ ```
123
+
124
+ ### Step 7: Apply Overrides (if any)
125
+
126
+ If user overrides a gate:
127
+ 1. Add gate ID to finding's `gate_overrides` array
128
+ 2. Recalculate: if all non-overridden gates pass → status = `approved`
129
+ 3. Log override for audit trail
130
+
131
+ ## Override Protocol
132
+
133
+ User command: `"пропусти G3 для #7"` (override G3 for finding #7)
134
+
135
+ Validation:
136
+ - Finding #7 must exist and be `blocked`
137
+ - G3 must be one of the failing gates for finding #7
138
+ - **G6 (Not Duplicate) and G8 (Brutal Honesty) CANNOT be overridden** — reject override attempts for these gates
139
+ - Record the override with timestamp
140
+
141
+ Multiple overrides: `"пропусти G3,G4 для #14"` — override multiple gates at once.
142
+
143
+ ## Anti-Patterns
144
+
145
+ | Anti-Pattern | Detection | Fix |
146
+ |-------------|-----------|-----|
147
+ | All findings pass all gates | 100% pass rate | Haiku semantic evaluator may be too lenient — add calibration examples |
148
+ | Gate G8 blocks everything | > 80% fail on G8 | Review extraction quality — if findings are genuinely weak, that's correct |
149
+ | Overriding all blocked gates | User overrides every block | Advisory: suggest improving extraction rather than overriding all gates |
150
+ | Semantic evaluator contradicts itself | G3 passes but content has project refs | Log discrepancy, flag for human review |
@@ -0,0 +1,159 @@
1
+ # Integrate Module — Auto-Placement and Harvest Report
2
+
3
+ ## Purpose
4
+
5
+ Place approved findings into their target directories as artifact cards, update TOOLKIT_HARVEST.md, generate the harvest report, and trigger post-harvest integrations (memory_store, dream cycles).
6
+
7
+ ## Input
8
+
9
+ - Findings JSON file (from Module 03, approved findings)
10
+ - `templates/artifact-card.md` — per-finding output template
11
+ - `templates/harvest-report.md` — session report template
12
+ - `TOOLKIT_HARVEST.md` — existing toolkit tracker
13
+
14
+ ## Protocol
15
+
16
+ ### Step 1: Load Approved Findings
17
+
18
+ 1. Read findings JSON file
19
+ 2. Filter findings with status `approved`
20
+ 3. Set session status to `integrating`
21
+ 4. Load artifact card template and harvest report template
22
+
23
+ ### Step 2: Render Artifact Cards
24
+
25
+ For each approved finding, render the artifact card by filling template placeholders:
26
+
27
+ | Placeholder | Source |
28
+ |-------------|--------|
29
+ | `{NAME}` | finding.title |
30
+ | `{CATEGORY}` | finding.category |
31
+ | `{MATURITY_BADGE}` | Lookup from maturity-model.md: alpha=🔴, beta=🟡, stable=🟢 |
32
+ | `{MATURITY_LEVEL}` | finding.maturity (capitalized) |
33
+ | `{CONFIDENCE}` | finding.confidence |
34
+ | `{SOURCE_PROJECT}` | session.slug |
35
+ | `{DATE}` | current date (YYYY-MM-DD) |
36
+ | `{DESCRIPTION}` | finding.content |
37
+ | `{WHEN_TO_USE}` | finding.when_to_use |
38
+ | `{WHEN_NOT_TO_USE}` | finding.when_not_to_use |
39
+ | `{EXAMPLE}` | finding.example |
40
+
41
+ ### Step 3: Auto-Place by Category
42
+
43
+ Place each rendered artifact card according to its category:
44
+
45
+ | Category | Placement Action |
46
+ |----------|-----------------|
47
+ | **skills** | Create `.claude/skills/{name}/SKILL.md` with the artifact card as initial skeleton. Add frontmatter (trust_tier: 0, trust_tier_label: "Advisory"). |
48
+ | **commands** | Create `.claude/commands/{name}.md` with `$ARGUMENTS` parameter reference and the artifact card content as the command body. |
49
+ | **hooks** | Append artifact card to TOOLKIT_HARVEST.md under `## Хуки` section. Create the section if it doesn't exist. |
50
+ | **rules** | Create `.claude/rules/{name}.md` with the artifact card content formatted as a rule table (anti-pattern detection format). |
51
+ | **templates** | Append artifact card to TOOLKIT_HARVEST.md under `## Шаблоны` section. |
52
+ | **patterns** | Append artifact card to TOOLKIT_HARVEST.md under `## Паттерны` section. |
53
+ | **snippets** | Append artifact card to TOOLKIT_HARVEST.md under `## Сниппеты` section. |
54
+
55
+ **Naming convention:** Convert finding title to kebab-case for file/directory names. Max 40 characters.
56
+
57
+ **Collision handling:** If a file already exists at the target path:
58
+ - Do NOT overwrite
59
+ - Log: "Skipped placement for #{N} — target already exists: {path}"
60
+ - Set finding status to `approved` (not `integrated`) and flag for manual review
61
+
62
+ ### Step 4: Update TOOLKIT_HARVEST.md
63
+
64
+ After placing all artifacts:
65
+
66
+ 1. Update the "Обработанные проекты" table:
67
+ ```markdown
68
+ | Проект | Дата harvest | Извлечено артефактов |
69
+ |--------|-------------|---------------------|
70
+ | {slug} | {date} | {approved_count} approved / {total_count} total |
71
+ ```
72
+
73
+ 2. Mark checked items in the relevant sections (skills, patterns, commands, etc.)
74
+
75
+ ### Step 5: Generate Harvest Report
76
+
77
+ Fill the harvest report template with computed metrics:
78
+
79
+ | Metric | Computation |
80
+ |--------|-------------|
81
+ | TOTAL_EXTRACTED | Count of all findings at creation |
82
+ | AFTER_DEDUP | Count after Module 02 dedup |
83
+ | USER_REMOVALS | Count where status = `removed` AND not from dedup |
84
+ | USER_MERGES | Count where merged_from is not null |
85
+ | APPROVED_COUNT | Count where status = `approved` or `integrated` |
86
+ | BLOCKED_COUNT | Count where status = `blocked` |
87
+ | OVERRIDE_COUNT | Sum of all gate_overrides arrays |
88
+ | PLACED_COUNT | Count where status = `integrated` |
89
+
90
+ Display the report to the user.
91
+
92
+ ### Step 6: Post-Harvest Integration
93
+
94
+ 1. **memory_store()** — Store harvest results:
95
+ ```json
96
+ {
97
+ "case_slug": "{slug}",
98
+ "domain": "{domain}",
99
+ "phase": "harvest",
100
+ "skill_used": "knowledge-extractor",
101
+ "reward": "{user_reward}",
102
+ "reward_label": "{label}",
103
+ "context": {
104
+ "patterns_loaded": "{count}",
105
+ "extractors_spawned": "{lens_list}",
106
+ "scope_filter": "{filter_or_null}"
107
+ },
108
+ "outcome": {
109
+ "artifacts_created": "{placed_files_list}",
110
+ "total_extracted": "{N}",
111
+ "total_approved": "{N}",
112
+ "total_placed": "{N}",
113
+ "gate_pass_rate": "{rate}"
114
+ }
115
+ }
116
+ ```
117
+
118
+ 2. **Dream trigger** — Update `.keysarium/insights/trigger-state.json`:
119
+ ```json
120
+ {
121
+ "event_type": "case_completion",
122
+ "timestamp": "ISO-8601",
123
+ "details": "Harvest completed for {slug}: {placed_count} artifacts placed"
124
+ }
125
+ ```
126
+
127
+ 3. **Clean up** — Delete the findings JSON file ONLY after confirming all placements succeeded and the harvest report was written. If any placement failed or the report could not be generated, keep the findings JSON as a recovery artifact and log: `"Findings JSON retained at {path} — manual review needed."`
128
+
129
+ ### Step 7: Final Display
130
+
131
+ Show the user a completion summary:
132
+
133
+ ```
134
+ ═══════════════════════════════════════════════════════
135
+ ✅ HARVEST COMPLETE: {SESSION_ID}
136
+
137
+ Extracted: {N} → Approved: {M} → Placed: {P}
138
+
139
+ Placed artifacts:
140
+ 📁 .claude/skills/agent-swarm-topology/SKILL.md
141
+ 📁 .claude/rules/domain-detection.md
142
+ 📄 TOOLKIT_HARVEST.md (3 entries added)
143
+
144
+ Gate pass rate: {rate}%
145
+ Memory reward stored: {score} ({label})
146
+
147
+ Run /bto-test on placed skills for promotion to Tier 2.
148
+ ═══════════════════════════════════════════════════════
149
+ ```
150
+
151
+ ## Anti-Patterns
152
+
153
+ | Anti-Pattern | Detection | Fix |
154
+ |-------------|-----------|-----|
155
+ | Overwriting existing files | Target file already exists | NEVER overwrite; skip and flag for manual review |
156
+ | Placing blocked findings | Finding status is `blocked` | Only place findings with status `approved` |
157
+ | Missing TOOLKIT_HARVEST.md sections | Section header doesn't exist yet | Create the section before appending |
158
+ | Forgetting to update "Обработанные проекты" | Table not updated after placement | Always update as the last TOOLKIT_HARVEST.md operation |
159
+ | Leaving findings JSON behind | Temp file not cleaned up | Delete after successful report generation |
@@ -0,0 +1,100 @@
1
+ # Artifact Categories Reference
2
+
3
+ Seven mutually exclusive categories for classifying extracted findings.
4
+ Every finding must be assigned exactly one category before passing through the quality gates.
5
+ If a finding spans multiple categories, split it or assign the primary category.
6
+
7
+ ## Category Taxonomy
8
+
9
+ | Category | Destination | Description | Examples | Agent Lens |
10
+ |----------|-------------|-------------|----------|------------|
11
+ | skills | .claude/skills/<name>/ | Complete skill bundles (SKILL.md + modules) | New analysis methodology, reusable research approach | All lenses (cross-cutting) |
12
+ | commands | .claude/commands/<name>.md | Slash commands for Claude Code | Pipeline phases, utility commands | extractor-commands |
13
+ | hooks | .claude/hooks/ or TOOLKIT_HARVEST.md | Event-driven automations, pre/post hooks | Pre-commit checks, post-phase triggers | extractor-commands |
14
+ | rules | .claude/rules/<name>.md | Constraints, quality gates, anti-patterns | Domain restrictions, naming conventions | extractor-rules |
15
+ | templates | TOOLKIT_HARVEST.md or lib/ | Document/config structure templates | ADR template, mermaid diagram template | extractor-templates |
16
+ | patterns | TOOLKIT_HARVEST.md or lib/ | Architecture and design patterns | Agent swarm topology, event-driven pipeline | extractor-patterns |
17
+ | snippets | TOOLKIT_HARVEST.md | Reusable code fragments | React components, utility functions, bash one-liners | extractor-snippets |
18
+
19
+ ## Category Descriptions
20
+
21
+ ### skills
22
+ A skill is a self-contained capability bundle that can be loaded by a Claude Code session.
23
+ It requires at minimum a SKILL.md with trigger conditions, usage instructions, and output specification.
24
+ Extract as a skill when the finding represents a repeatable methodology that warrants its own invocation pattern.
25
+ Destination: create a new directory under `.claude/skills/<name>/` with SKILL.md as the entry point.
26
+
27
+ ### commands
28
+ A command is a slash command definition — a markdown file in `.claude/commands/` that Claude Code exposes as `/command-name`.
29
+ Extract as a command when the finding defines a distinct user-facing workflow step or utility.
30
+ Destination: `.claude/commands/<name>.md`
31
+
32
+ ### hooks
33
+ A hook is an event-driven automation that fires on a specific lifecycle event (session start, phase completion, file save).
34
+ Extract as a hook when the finding describes behavior that should trigger automatically, not on user request.
35
+ Destination: `.claude/hooks/` directory if the project uses the hooks directory convention; otherwise document in TOOLKIT_HARVEST.md under the Hooks section.
36
+
37
+ ### rules
38
+ A rule is a constraint, convention, or quality gate that governs agent behavior.
39
+ Extract as a rule when the finding specifies what agents must or must not do, regardless of context.
40
+ Destination: `.claude/rules/<name>.md`
41
+
42
+ ### templates
43
+ A template is a document or configuration scaffold with placeholders that gets filled in for each use.
44
+ Extract as a template when the finding defines a repeatable document structure (not the content itself).
45
+ Destination: `lib/` if it will be referenced by multiple commands; otherwise TOOLKIT_HARVEST.md under Templates section.
46
+
47
+ ### patterns
48
+ A pattern is an architectural or design solution to a recurring structural problem.
49
+ Extract as a pattern when the finding describes how to compose components or agents, not what they contain.
50
+ Patterns are higher-level than snippets and lower-level than skills.
51
+ Destination: `lib/` if it has widespread applicability; otherwise TOOLKIT_HARVEST.md under Patterns section.
52
+
53
+ ### snippets
54
+ A snippet is a concrete, copy-paste-ready code or configuration fragment.
55
+ Extract as a snippet when the finding is language/framework-specific code that solves one small problem.
56
+ Destination: TOOLKIT_HARVEST.md under Snippets section, with language and framework tags.
57
+
58
+ ## Scope Filtering Mapping (category to agent lens for /harvest only X)
59
+
60
+ When the user invokes `/harvest only <scope>`, only the corresponding extractor agent lens runs.
61
+ All other lenses are suppressed to reduce cost and noise.
62
+
63
+ | User Scope Argument | Active Agent Lenses | Categories Produced |
64
+ |--------------------|---------------------|---------------------|
65
+ | `skills` | ALL 5 lenses (cross-cutting) | skills |
66
+ | `commands` | extractor-commands | commands, hooks |
67
+ | `rules` | extractor-rules | rules |
68
+ | `templates` | extractor-templates | templates |
69
+ | `patterns` | extractor-patterns | patterns |
70
+ | `snippets` | extractor-snippets | snippets |
71
+ | `code` | extractor-snippets | snippets |
72
+ | `all` (default) | All 5 lenses | All 7 categories |
73
+
74
+ Note: hooks are produced by extractor-commands because hooks are closely related to command lifecycle automation.
75
+ Note: skills scope spawns ALL 5 lenses because skills are cross-cutting — any lens may discover patterns worthy of promotion to a full skill bundle.
76
+
77
+ ## Deduplication Rules (per-category)
78
+
79
+ Deduplication is applied during gate G6 (Not Duplicate). The similarity threshold is 0.85.
80
+ Similarity is assessed by the orchestrator using structural comparison (not LLM) unless specified.
81
+
82
+ | Category | Deduplication Key | Comparison Method |
83
+ |----------|------------------|-------------------|
84
+ | skills | Skill name + trigger conditions | Exact name match OR semantic trigger overlap |
85
+ | commands | Command name (slug) | Exact slash-command name match |
86
+ | hooks | Event type + trigger condition | Exact event type + condition string match |
87
+ | rules | Rule title + first sentence of constraint | Normalized string similarity |
88
+ | templates | Template name + section headings list | Section heading set overlap |
89
+ | patterns | Pattern name + problem statement | Normalized string similarity on problem statement |
90
+ | snippets | Language + first 5 non-whitespace lines | Normalized code similarity |
91
+
92
+ When a near-duplicate is found (similarity 0.70–0.85), the extractor must decide:
93
+ - If the new finding improves the existing entry (adds a section, fixes an error): propose a MERGE, not a new entry.
94
+ - If the new finding is a different context of the same idea: add as a "variant" note under the existing entry.
95
+ - If similarity >= 0.85: treat as duplicate, reject via G6.
96
+
97
+ Merge proposals are surfaced in the harvest output as:
98
+ ```
99
+ MERGE PROPOSAL: Finding #{X} improves existing entry "{existing_name}" — {reason}
100
+ ```
@@ -0,0 +1,94 @@
1
+ # Maturity Model Reference
2
+
3
+ Three maturity levels are used to communicate how well-tested and battle-proven an extracted finding is.
4
+ Every finding must be assigned a maturity level at extraction time. The level is surfaced in the artifact card
5
+ and in TOOLKIT_HARVEST.md entries so consumers know how much trust to place in the finding.
6
+
7
+ ## Maturity Levels
8
+
9
+ | Level | Label | Criteria | Badge |
10
+ |-------|-------|----------|-------|
11
+ | Alpha | Alpha | First extraction, untested. Used in exactly 1 project. No validation. | 🔴 |
12
+ | Beta | Beta | Used in 2+ projects. Basic validation. May have rough edges. | 🟡 |
13
+ | Stable | Stable | Used in 3+ projects. Proven track record. Passed /bto-test or equivalent. | 🟢 |
14
+
15
+ ## Promotion Protocol
16
+
17
+ Promotion moves a finding from one maturity level to the next. Promotion requires evidence — it is not
18
+ self-declared. The `/harvest` command can suggest promotion but not enforce it; the user confirms.
19
+
20
+ ### Alpha to Beta
21
+
22
+ Required evidence (any one of the following):
23
+ - The same pattern, rule, template, or snippet was independently observed in a second project's harvest.
24
+ - A team member explicitly applied the finding in a second project and confirmed it worked.
25
+ - The finding was referenced in a command or skill that was used in a second research session.
26
+
27
+ Promotion action:
28
+ 1. Update the `maturity` field in the finding's TOOLKIT_HARVEST.md entry from `alpha` to `beta`.
29
+ 2. Add a `used_in` list to the entry noting the two (or more) projects.
30
+ 3. Log the promotion: `PROMOTED: "{name}" alpha -> beta — evidence: {source}`.
31
+
32
+ ### Beta to Stable
33
+
34
+ Required evidence (ALL of the following):
35
+ - Used in 3 or more distinct projects (verified by `used_in` list).
36
+ - At least one of the following validation signals exists:
37
+ - Passed `/bto-test` Layer 2 evaluation with score >= 7.0.
38
+ - Has a documented test case in a `references/` or `examples/` directory.
39
+ - Was reviewed and approved by a second human reviewer in a harvest session.
40
+
41
+ Promotion action:
42
+ 1. Update the `maturity` field from `beta` to `stable`.
43
+ 2. Record the validation signal: BTO score, test case path, or reviewer name.
44
+ 3. Add the finding to the summary table in TOOLKIT_HARVEST.md under the Stable Findings section.
45
+ 4. Log the promotion: `PROMOTED: "{name}" beta -> stable — validation: {signal}`.
46
+
47
+ ### Demotion Protocol
48
+
49
+ A stable or beta finding may be demoted if evidence of unreliability emerges:
50
+ - A project reports the finding caused errors or required significant modification.
51
+ - A `/bto-test` run scores the finding below 5.0.
52
+
53
+ Demotion action:
54
+ 1. Downgrade maturity by one level (stable -> beta, beta -> alpha).
55
+ 2. Add a `demotion_reason` note to the TOOLKIT_HARVEST.md entry.
56
+ 3. Log the demotion: `DEMOTED: "{name}" {from} -> {to} — reason: {reason}`.
57
+
58
+ ## Initial Assignment Rules
59
+
60
+ 1. The first extraction of any finding is ALWAYS assigned `alpha` maturity.
61
+ 2. Exception: if the finding describes a pattern that was already in use across multiple projects
62
+ prior to being formally extracted, it may be assigned `beta` at extraction time — but only if
63
+ the extractor can cite at least 2 distinct prior uses in the finding's `used_in` field.
64
+ 3. Exception: if the extracted finding is a verbatim copy of content that already exists in the
65
+ toolkit at beta or stable maturity (e.g., an updated version of a known pattern), inherit the
66
+ existing maturity level and propose a MERGE rather than a new entry.
67
+ 4. No finding may be assigned `stable` at first extraction, regardless of prior use.
68
+
69
+ ## Maturity in Artifact Card
70
+
71
+ Every finding written to TOOLKIT_HARVEST.md includes a maturity badge in its header card.
72
+
73
+ ### Format
74
+
75
+ ```
76
+ ## [Category] — {finding_name}
77
+ **Maturity:** [ALPHA | BETA | STABLE]
78
+ **Confidence:** {confidence_score}
79
+ **Used in:** {project_slug_1}, {project_slug_2}, ...
80
+ **Validated by:** {bto_score or test_path or reviewer or "not yet validated"}
81
+ ```
82
+
83
+ ### Display Rules
84
+
85
+ - Display maturity label in uppercase.
86
+ - If `used_in` has only one entry, display it as `{slug} (source project)`.
87
+ - If `validated_by` is empty, display `not yet validated`.
88
+ - Include the maturity badge on the same line as the finding name when embedding in summary tables:
89
+
90
+ ```
91
+ | {finding_name} [ALPHA] | {category} | {one-line description} |
92
+ ```
93
+
94
+ - In summary tables, badge order is: STABLE first, then BETA, then ALPHA (most trustworthy at top).