@dzhechkov/p-replicator 1.10.4 → 1.13.1

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 (136) hide show
  1. package/.dz-manifest.json +312 -76
  2. package/CHANGELOG.md +232 -0
  3. package/MULTIPLATFORM_ROADMAP.md +1 -1
  4. package/README/eng/01_quickstart.md +3 -3
  5. package/README/eng/02_user_guide.md +1 -1
  6. package/README/eng/03_admin_guide.md +2 -2
  7. package/README/eng/04_api_reference.md +11 -5
  8. package/README/eng/05_architecture.md +1 -1
  9. package/README/eng/README.md +2 -1
  10. package/README/ru/01_quickstart.md +3 -3
  11. package/README/ru/02_user_guide.md +1 -1
  12. package/README/ru/03_admin_guide.md +2 -2
  13. package/README/ru/04_api_reference.md +11 -5
  14. package/README/ru/05_architecture.md +1 -1
  15. package/README/ru/README.md +2 -1
  16. package/README/ru/html/index.html +9 -9
  17. package/README.md +278 -39
  18. package/package.json +5 -4
  19. package/sbom.json +665 -75
  20. package/scripts/check-pipeline-gaps.sh +413 -0
  21. package/src/commands/doctor.js +94 -4
  22. package/src/commands/init.js +1 -1
  23. package/src/rule-components.json +15 -0
  24. package/src/utils.js +35 -11
  25. package/templates/.claude/agents/harvest-coordinator.md +10 -1
  26. package/templates/.claude/agents/product-discoverer.md +38 -0
  27. package/templates/.claude/agents/replicate-coordinator.md +11 -1
  28. package/templates/.claude/commands/feature.md +81 -9
  29. package/templates/.claude/commands/go.md +9 -0
  30. package/templates/.claude/commands/harvest.md +39 -3
  31. package/templates/.claude/commands/myinsights.md +21 -26
  32. package/templates/.claude/commands/replicate.md +171 -37
  33. package/templates/.claude/commands/start.md +29 -0
  34. package/templates/.claude/hooks/capture-source-path.cjs +795 -0
  35. package/templates/.claude/hooks/check-canon.cjs +493 -0
  36. package/templates/.claude/hooks/check-embed-contract.cjs +374 -0
  37. package/templates/.claude/hooks/check-external-deps.cjs +288 -0
  38. package/templates/.claude/hooks/check-file-ownership.cjs +424 -0
  39. package/templates/.claude/hooks/check-handoff-manifest.cjs +367 -0
  40. package/templates/.claude/hooks/check-job-contract.cjs +501 -0
  41. package/templates/.claude/hooks/check-look-origin.cjs +240 -0
  42. package/templates/.claude/hooks/check-look-trace.cjs +385 -0
  43. package/templates/.claude/hooks/check-metric-source.cjs +296 -0
  44. package/templates/.claude/hooks/check-model-cost.cjs +470 -0
  45. package/templates/.claude/hooks/check-ports.cjs +434 -24
  46. package/templates/.claude/hooks/check-source-version.cjs +312 -0
  47. package/templates/.claude/hooks/check-swarm-receipts.cjs +197 -0
  48. package/templates/.claude/hooks/check-webhook-contract.cjs +535 -0
  49. package/templates/.claude/hooks/session-insights.cjs +158 -25
  50. package/templates/.claude/hooks/statusline.cjs +2 -2
  51. package/templates/.claude/hooks/write-insight.cjs +253 -0
  52. package/templates/.claude/rules/cost-of-detection-ladder.md +96 -0
  53. package/templates/.claude/rules/docker-ports.md +41 -19
  54. package/templates/.claude/rules/embeddable-widget.md +73 -0
  55. package/templates/.claude/rules/feature-lifecycle.md +13 -3
  56. package/templates/.claude/rules/honest-configuration.md +54 -0
  57. package/templates/.claude/rules/incoming-webhooks.md +99 -0
  58. package/templates/.claude/rules/insights-capture.md +10 -5
  59. package/templates/.claude/rules/long-running-job.md +73 -0
  60. package/templates/.claude/rules/model-call-cost.md +85 -0
  61. package/templates/.claude/rules/replicate-pipeline.md +123 -52
  62. package/templates/.claude/rules/skill-interface-protocol.md +1 -0
  63. package/templates/.claude/rules/swarm-file-evidence.md +46 -0
  64. package/templates/.claude/settings.json +13 -1
  65. package/templates/.claude/skills/brutal-honesty-review/SKILL.md +9 -0
  66. package/templates/.claude/skills/cc-toolkit-generator-enhanced/SKILL.md +4 -0
  67. package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/03-generate-p0.md +46 -1
  68. package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/04-generate-p1.md +7 -1
  69. package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/06-package-deliver.md +20 -2
  70. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/claude-md-strategy.md +7 -0
  71. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/automation-commands.md +17 -0
  72. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-lifecycle-ent.md +43 -5
  73. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-lifecycle.md +43 -7
  74. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/start-command.md +19 -1
  75. package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/swarm-file-evidence.md +151 -0
  76. package/templates/.claude/skills/goap-research-ed25519/SKILL.md +37 -22
  77. package/templates/.claude/skills/goap-research-ed25519/references/negative-results.md +94 -0
  78. package/templates/.claude/skills/goap-research-ed25519/scripts/check_report_evidence.py +368 -4
  79. package/templates/.claude/skills/goap-research-ed25519/scripts/ed25519_verifier.py +122 -5
  80. package/templates/.claude/skills/goap-research-ed25519/scripts/evidence_fetch.py +33 -16
  81. package/templates/.claude/skills/goap-research-ed25519/scripts/quote_provenance.py +342 -0
  82. package/templates/.claude/skills/goap-research-ed25519/scripts/test_ed25519_verifier.py +60 -0
  83. package/templates/.claude/skills/goap-research-ed25519/scripts/test_evidence_provenance.py +139 -6
  84. package/templates/.claude/skills/goap-research-ed25519/scripts/test_quote_provenance.py +274 -0
  85. package/templates/.claude/skills/goap-research-ed25519/scripts/test_suite_completeness.py +2 -1
  86. package/templates/.claude/skills/knowledge-extractor/SKILL.md +4 -0
  87. package/templates/.claude/skills/knowledge-extractor/modules/01-agent-review.md +16 -5
  88. package/templates/.claude/skills/pipeline-forge/SKILL.md +18 -23
  89. package/templates/.claude/skills/pipeline-forge/examples/replicate-analysis.md +7 -2
  90. package/templates/.claude/skills/pipeline-forge/references/patterns-catalog.md +19 -1
  91. package/templates/.claude/skills/pipeline-forge/references/self-extracted-patterns.md +17 -6
  92. package/templates/.claude/skills/pipeline-forge/references/skill-anatomy.md +0 -1
  93. package/templates/.claude/skills/reverse-engineering-unicorn/modules/025-cjm-prototype.md +21 -1
  94. package/templates/.claude/skills/sparc-prd-mini/SKILL.md +234 -716
  95. package/tests/e2e/lifecycle.test.js +55 -9
  96. package/tests/e2e/packed-insights-writer.test.js +308 -0
  97. package/tests/fixtures/prep-traceability-fixture/docs/features/order-refund/01_specification.md +29 -0
  98. package/tests/fixtures/prep-traceability-fixture/docs/features/order-refund/02_pseudocode.md +57 -0
  99. package/tests/snapshot/baseline.json +72 -46
  100. package/tests/snapshot/templates.test.js +47 -0
  101. package/tests/unit/absence-is-not-emptiness.test.js +15 -1
  102. package/tests/unit/capture-source-path.test.js +492 -0
  103. package/tests/unit/check-canon.test.js +403 -0
  104. package/tests/unit/check-embed-contract.test.js +422 -0
  105. package/tests/unit/check-external-deps.test.js +363 -0
  106. package/tests/unit/check-file-ownership.test.js +388 -0
  107. package/tests/unit/check-handoff-manifest.test.js +410 -0
  108. package/tests/unit/check-job-contract.test.js +514 -0
  109. package/tests/unit/check-look-origin.test.js +180 -0
  110. package/tests/unit/check-look-trace.test.js +420 -0
  111. package/tests/unit/check-metric-source.test.js +325 -0
  112. package/tests/unit/check-model-cost.test.js +425 -0
  113. package/tests/unit/check-pipeline-gaps.test.js +94 -0
  114. package/tests/unit/check-ports.test.js +773 -2
  115. package/tests/unit/check-source-version.test.js +344 -0
  116. package/tests/unit/check-swarm-receipts.test.js +231 -0
  117. package/tests/unit/check-webhook-contract.test.js +536 -0
  118. package/tests/unit/db-port-rule.test.js +43 -6
  119. package/tests/unit/detection-ladder-contract.test.js +302 -0
  120. package/tests/unit/detection-ladder-registry.test.js +52 -0
  121. package/tests/unit/doctor-insight-flow.test.js +315 -0
  122. package/tests/unit/external-dependency-check.test.js +19 -19
  123. package/tests/unit/generator-swarm-contract.test.js +287 -0
  124. package/tests/unit/guard-honest-input-meta.test.js +64 -0
  125. package/tests/unit/honest-failure-rules.test.js +574 -0
  126. package/tests/unit/hooks-project-anchored.test.js +67 -3
  127. package/tests/unit/insights-docs-tell-the-truth.test.js +52 -31
  128. package/tests/unit/insights-dz-delegation.test.js +197 -0
  129. package/tests/unit/insights-writer.test.js +285 -0
  130. package/tests/unit/look-phase-contract.test.js +231 -0
  131. package/tests/unit/negative-conclusion-gate.test.js +300 -0
  132. package/tests/unit/quote-provenance.test.js +122 -0
  133. package/tests/unit/shipped-suite-context.test.js +3 -1
  134. package/tests/unit/traceability-machine-ids.test.js +413 -0
  135. package/tests/unit/traceability-negative-fixture.test.js +322 -0
  136. package/tests/unit/utils.test.js +40 -2
@@ -46,8 +46,46 @@ Product Discovery Brief — structured markdown passed as pre-filled context to
46
46
 
47
47
  ### Key Insights for PRD
48
48
  [Top 3-5 insights that should inform product planning]
49
+
50
+ ## Манифест передачи
51
+
52
+ **Фаза 0 выполнена:** да
53
+ **Проверка манифеста:** ВЫПОЛНЕНА
54
+ **Причина:** —
55
+
56
+ | Выход | Идентификатор | Модуль |
57
+ |---|---|---|
58
+ | [what this run actually produced] | PD-INSIGHT-001 | M5 |
49
59
  ```
50
60
 
61
+ ### The manifest is REQUIRED, and it is the last thing written
62
+
63
+ The brief's six sections are passed onward through a CLOSED list of four fields
64
+ (`target_segments`, `key_competitors`, `differentiation`, `monetization`). Two of the six therefore
65
+ have no field at all — «Key Insights for PRD» has none, and «Growth Channels» travels only through
66
+ the separate `FR-GROWTH` seed. The artifact is written, it is on disk, and the next phase has no
67
+ input through which it could reach a decision: «used» and «silently dropped» look identical from
68
+ every side, because nobody is obliged to answer by list.
69
+
70
+ The manifest is that list. Three rules, and each of them is what makes it checkable rather than
71
+ ceremonial:
72
+
73
+ 1. **Only ENUMERABLE outputs of the REAL run**, each with a stable identifier `PD-WORD-nnn`
74
+ (uppercase, three digits, never reused). Free prose cannot be answered by list, and answering by
75
+ list is the entire cure.
76
+ 2. **A module that did not run owes NOTHING.** Do not invent rows for modules you skipped — a
77
+ manifest padded to look complete is worse than a short one, because it makes the check pass while
78
+ describing work nobody did.
79
+ 3. **Phase 1 answers every row**: cite the id in a Phase-1 document, or reject it WITH A REASON in
80
+ the same line. Silence is neither, and it is the only outcome the check refuses to interpret
81
+ charitably.
82
+
83
+ Deterministic half: `node .claude/hooks/check-handoff-manifest.cjs .` — `0` every output answered ·
84
+ `1` a defect is PROVEN and NAMED (an output nobody answered for, a rejection with no reason, an
85
+ empty manifest) · `2` THE CHECK DID NOT RUN (no brief — Phase 0 never ran, `--from-docs` skips it —
86
+ no manifest section, no Phase-1 documents, a malformed or duplicated id, or the honest «НЕ
87
+ ВЫПОЛНЕНА» with a reason). Exit `2` never means "all clear".
88
+
51
89
  ## Anti-Hallucination Rules
52
90
 
53
91
  - Search first — never answer from memory for facts
@@ -8,9 +8,19 @@ Activated automatically by the `/replicate` command. Do NOT invoke directly.
8
8
 
9
9
  ## Responsibilities
10
10
 
11
- 1. **Phase Management** — ensure correct phase sequence (0 → 1 → 2 → 3 → 4)
11
+ 1. **Phase Management** — ensure correct phase sequence (0 → 0.5 → 1 → 2 → 3 → 4).
12
+ Phase 0 is OPTIONAL and is skipped entirely by the `--from-docs` / `--skip-discovery` entry;
13
+ **Phase 0.5 (Source Product Profile) is MANDATORY and runs in every case**, which is why it is a
14
+ separate phase rather than a module inside Phase 0.
12
15
  2. **Context Passing** — carry forward outputs between phases:
13
16
  - Phase 0 → Phase 1: Product Discovery Brief
17
+ - Phase 0.5 → Phase 1: Source Product Profile (`docs/source-product-profile.md`) — a capture
18
+ status PER AXIS (`облик` and `путь` each answer `СНЯТ` / `НЕ ИЗМЕРЕНО` + reason /
19
+ `ИСТОЧНИКА НЕТ`, because they fail apart) plus the `FR-LOOK-nnn` seed rows of ONE family. A
20
+ `СНЯТ` profile's palette SUPERSEDES the industry palette of `025-cjm-prototype.md`; in the
21
+ other two states that table is a LABELLED fallback. The `путь` axis is captured by
22
+ `.claude/hooks/capture-source-path.cjs` (browser click-through; Playwright is an external
23
+ prerequisite, and its absence is the outcome `no-browser`, never a stalled run)
14
24
  - Phase 1 → Phase 2: 11 SPARC documents
15
25
  - Phase 2 → Phase 3: Validated docs + test-scenarios
16
26
  - Phase 3 → Phase 4: Complete toolkit
@@ -70,11 +70,46 @@ implementation diffs.
70
70
  Read: `.claude/skills/sparc-prd-mini/SKILL.md`
71
71
 
72
72
  Generate per-feature SPARC docs in `docs/features/<feature>/`:
73
- - `01_specification.md` — requirements + acceptance criteria
74
- - `02_pseudocode.md` algorithms + data flow
75
- - `03_architecture.md` — component placement + dependencies
76
- - `04_refinement.md` edge cases + error paths
77
- - `05_completion.md` testing + deployment notes
73
+
74
+ ### Phase 1 document role map
75
+
76
+ `/feature` owns these per-feature filenames. Pass the complete map to `sparc-prd-mini`; the skill
77
+ addresses the documents by role and must not redeclare these names.
78
+
79
+ ```yaml
80
+ TARGET_CATALOG: docs/features/<feature>/
81
+ DOCUMENT_ROLE_MAP:
82
+ specification: 01_specification.md
83
+ pseudocode: 02_pseudocode.md
84
+ architecture: 03_architecture.md
85
+ refinement: 04_refinement.md
86
+ completion: 05_completion.md
87
+ ```
88
+
89
+ - `specification` — requirements + acceptance criteria
90
+ - `pseudocode` — algorithms + data flow
91
+ - `architecture` — component placement + dependencies
92
+ - `refinement` — edge cases + error paths
93
+ - `completion` — testing + deployment notes
94
+
95
+ #### Blocking machine-key traceability gate
96
+
97
+ After all five role targets are written, but before emitting the Phase 1 checkpoint or starting
98
+ Phase 2, run the installed package utility from the project root:
99
+
100
+ ```bash
101
+ CHECK_PIPELINE_GAPS="$(node -p "require.resolve('@dzhechkov/p-replicator/scripts/check-pipeline-gaps.sh')")" || {
102
+ printf 'NOT-ESTABLISHED packaged checker could not be resolved\n' >&2
103
+ exit 2
104
+ }
105
+ bash "$CHECK_PIPELINE_GAPS" "${CLAUDE_PROJECT_DIR:-.}" --traceability
106
+ ```
107
+
108
+ Preserve its status and diagnostic verbatim. Exit `0` is the only advancing result. Exit `1` means
109
+ named `specification->pseudocode` or `pseudocode->specification` gaps and returns to Phase 1 for
110
+ repair. Exit `2` means the role map or document evidence is not established and stops the pipeline
111
+ until that input is repaired. This rule is identical in MANUAL and AUTO modes; never turn either
112
+ non-zero status into a warning.
78
113
 
79
114
  **Checkpoint:**
80
115
  ```
@@ -102,10 +137,46 @@ Output: `docs/features/<feature>/validation-report.md`
102
137
 
103
138
  1. Read SPARC docs from Phase 1
104
139
  2. Identify independent work units
105
- 3. Spawn parallel `Task` tool calls, one per unit
106
- 4. Each Task: implement + write tests + commit
107
- 5. Coordinator merges/integrates after Tasks complete
108
- 6. Run full test suite
140
+ 3. Establish the positive file receipt contract below
141
+ 4. Spawn parallel `Task` tool calls, one per unit
142
+ 5. Each Task: implement + write tests + commit + deliver its trace
143
+ 6. Coordinator validates every trace before merge/integration
144
+ 7. Run full test suite
145
+
146
+ #### Canon before dispatch (required)
147
+
148
+ **The canon MUST be frozen BEFORE dispatch.** Parallel units are N writers deriving names and
149
+ numbers from one source; the collision exists ONLY IN THE UNION, so no worker can see it and no
150
+ receipt can catch it. The coordinator records `docs/dispatch-plan.md` — the canon path and its
151
+ sha256 — or runs the units sequentially.
152
+
153
+ The same plan MUST assign OWNERSHIP: exactly one writer per file, the coordinator included, and a
154
+ file born by SPLITTING another gets its owner AT CREATION — ownership never travels by itself.
155
+
156
+ Every EDIT and every VERDICT MUST declare the sha256 of the source it was built on; a
157
+ mismatch with the live file is a refusal WITHOUT mutation — a read copy is a snapshot of the moment
158
+ of reading, not of the file.
159
+
160
+ Field forms and closed value lists are in the checkers' headers:
161
+
162
+ ```bash
163
+ node .claude/hooks/check-canon.cjs .
164
+ node .claude/hooks/check-file-ownership.cjs .
165
+ node .claude/hooks/check-source-version.cjs .
166
+ ```
167
+
168
+ `0` frozen and intact · `1` a defect is PROVEN and named · `2` **THE CHECK DID NOT RUN**, which is
169
+ never "all clear".
170
+
171
+ #### Positive file receipt (required)
172
+
173
+ Before dispatch, allocate one `RUN_ID` and, for every independent unit, a unique `WORK_UNIT_ID`.
174
+ Resolve `TRACE_PATH` to an absolute path unique to `(RUN_ID, WORK_UNIT_ID)` and pass both fields.
175
+ Require the worker to write a substantive body ending in `Status: completed` or `Status: failed` to
176
+ `TRACE_PATH` before its one-line pointer. Before integration, MUST verify a regular, non-symlink,
177
+ substantive, post-launch file with a terminal status. Narrative/chat/silence is never a receipt; any
178
+ invalid receipt MUST block merge/completion. Full rule and bounded exception:
179
+ `.claude/rules/swarm-file-evidence.md`.
109
180
 
110
181
  ### Phase 4: REVIEW (brutal-honesty-review)
111
182
 
@@ -123,6 +194,7 @@ Findings classified by severity. Critical (blocker | high) MUST be fixed.
123
194
 
124
195
  Skip per-phase user confirmations. Auto-decisions:
125
196
  - Phase 1: proceed if all docs exist
197
+ - Phase 1 traceability: proceed only when `check-pipeline-gaps.sh` exits `0`; preserve exit `1`/`2`
126
198
  - Phase 2: proceed if 🟢 or 🟡; auto-retry once on 🔴
127
199
  - Phase 3: proceed if tests + lint + build green
128
200
  - Phase 4: auto-fix `high` if straightforward; halt on `blocker`
@@ -73,6 +73,15 @@ CHECK: feature_ent_available = fileExists(".claude/commands/feature-ent.md")
73
73
  Same as `/feature` but with idea2prd-manual + DDD coherence + ADR consistency
74
74
  + 7-agent validation + 6-agent review.
75
75
 
76
+ ### Delegated parallel-work receipt (required)
77
+
78
+ For parallel work, assign each unit a unique `WORK_UNIT_ID` and unique absolute `TRACE_PATH`. The worker
79
+ MUST write a substantive body ending in `Status: completed` or `Status: failed` to `TRACE_PATH` before
80
+ its one-line pointer. Before merge/synthesis/completion, the selected pipeline MUST verify a regular,
81
+ non-symlink, substantive, post-launch file with a terminal status. Narrative/chat/silence is never a
82
+ receipt; any invalid receipt MUST block merge/completion, and this router never substitutes its report.
83
+ Full rule: `.claude/rules/swarm-file-evidence.md`.
84
+
76
85
  ## Step 6: Post-Implementation
77
86
 
78
87
  1. Update roadmap: feature `status: done`, `files: [actually-touched]`
@@ -39,9 +39,9 @@ Read the skill: `.claude/skills/knowledge-extractor/SKILL.md`
39
39
 
40
40
  1. Determine mode from $ARGUMENTS (default: quick)
41
41
  2. Read skill: `.claude/skills/knowledge-extractor/SKILL.md`
42
- 3. If mode == marker: create/append TOOLKIT_HARVEST.md, done
43
- 4. If mode == quick: run all 4 phases without checkpoints
44
- 5. If mode == full: run with checkpoints after each phase
42
+ 3. If mode == marker: create/append TOOLKIT_HARVEST.md; marker does not invoke `write-insight.cjs`; done
43
+ 4. If mode == quick: run all 4 phases without checkpoints, then run the required insight gate
44
+ 5. If mode == full: run with checkpoints after each phase, then run the required insight gate
45
45
 
46
46
  ### Phase Summary
47
47
 
@@ -50,8 +50,42 @@ Phase 1: AGENT REVIEW — scan codebase with 5 parallel agents
50
50
  Phase 2: CLASSIFY — categorize into 7 artifact types, filter exclusions
51
51
  Phase 3: DECONTEXTUALIZE — generalize, document, version
52
52
  Phase 4: INTEGRATE — write to toolkit, update index, harvest report
53
+ Gate 5: PERSIST INSIGHT — quick/full must receive a valid writer receipt before completion
53
54
  ```
54
55
 
56
+ ### Phase 1 positive file receipts (required)
57
+
58
+ Assign each perspective a unique `WORK_UNIT_ID` and unique absolute `TRACE_PATH`. Its agent MUST write
59
+ a substantive body ending in `Status: completed` or `Status: failed` to `TRACE_PATH` before its one-line
60
+ pointer. Before classification/synthesis, verify a regular, non-symlink, substantive, post-launch file
61
+ with a terminal status. Narrative/chat/silence is never a receipt; any invalid receipt MUST block
62
+ harvest completion. Full rule: `.claude/rules/swarm-file-evidence.md`.
63
+
64
+ ## REQUIRED INSIGHT PERSISTENCE GATE (quick/full only)
65
+
66
+ After Phase 4 and before the normal harvest completion report:
67
+
68
+ 1. Select one specific, reusable finding from this run. Populate all fields in this JSON object:
69
+ `date` (`YYYY-MM-DD`, owned by this caller), `title`, `tags` (array), `problem`, `solution`, and
70
+ `references` (array). Do not invent a generic record merely to satisfy the gate.
71
+ 2. If the run produced no candidate, write nothing and report exactly that insight capture remains
72
+ incomplete because no candidate was found. This is distinct from silently skipping the gate.
73
+ 3. Otherwise, write the JSON to a temporary UTF-8 file outside `.claude/insights/`, then pass its
74
+ bytes on stdin to the project-root helper `.claude/hooks/write-insight.cjs`. Do not put record
75
+ contents in shell arguments. The helper owns lazy carrier creation, append preservation, and
76
+ exact-repeat suppression. It establishes the Markdown source of truth first, then attempts a
77
+ best-effort idempotent `dz teach` duplicate.
78
+ 4. Require exit zero and parse exactly one JSON receipt. Only `created`, `appended`, or `duplicate`
79
+ is valid. Verify `.claude/insights/index.md` exists after `created` or `appended`. The nested
80
+ `teach.state` is optional-projection observability, not a second persistence receipt.
81
+ 5. Delete the temporary JSON only after a valid receipt. Include its status and `entryCount` in the
82
+ completion report, plus `teach.state` when present. A failed teach retains Markdown and does not
83
+ block completion. If the writer exits non-zero or its receipt is absent/malformed, MUST NOT report
84
+ the harvest as completed; show the persistence failure and keep the input for diagnosis.
85
+
86
+ `marker` mode is only a future-work marker: it does not invoke `write-insight.cjs`, does not create
87
+ `.claude/insights/`, and does not claim a completed quick/full harvest.
88
+
55
89
  ### Module References
56
90
 
57
91
  | Phase | Module |
@@ -97,6 +131,7 @@ Phase 4: INTEGRATE — write to toolkit, update index, harvest report
97
131
  - Decontextualize in Phase 3 (no project-specific references)
98
132
  - Assign maturity level to every artifact
99
133
  - Record provenance (source project, date)
134
+ - For quick/full with a real finding, persist one insight and validate the writer receipt before completion
100
135
 
101
136
  ### NEVER
102
137
  - Don't copy code verbatim — always decontextualize
@@ -104,3 +139,4 @@ Phase 4: INTEGRATE — write to toolkit, update index, harvest report
104
139
  - Don't extract library workarounds without expiry dates
105
140
  - Don't skip Phase 3 — undecontextualized artifacts are tech debt
106
141
  - Don't set maturity higher than 🔴 Alpha for first extraction
142
+ - Don't report quick/full completion after a failed or unestablished insight write
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Capture and recall development insights. Append a new insight to `.claude/insights/index.md` with structured fields (problem, solution, tags). The three most recent are injected into context at SessionStart.
2
+ description: Capture and recall development insights. Markdown remains the source of truth; UserPromptSubmit uses armed dz recall with a local last-three fallback.
3
3
  argument-hint: '[recall <query> | <free-form insight>]'
4
4
  ---
5
5
 
@@ -10,22 +10,19 @@ argument-hint: '[recall <query> | <free-form insight>]'
10
10
  Build a project-local knowledge base of "грабли" (rakes) — errors, workarounds,
11
11
  discoveries — so they don't have to be re-learned.
12
12
 
13
- **What actually happens, stated exactly.** The `SessionStart` hook
14
- (`.claude/hooks/session-insights.cjs`, wired in `.claude/settings.json`) reads
15
- `.claude/insights/index.md` and injects the **three most recent entries**, by their
16
- order in the file. It prints them under the heading *"Recent project insights"* —
17
- which is what they are.
13
+ **What actually happens, stated exactly.** `.claude/insights/index.md` is the Markdown
14
+ source of truth. Capture establishes it first, then the writer makes a best-effort,
15
+ idempotent `dz teach` duplicate. Missing or failed dz never changes the Markdown receipt.
18
16
 
19
- **There is no tag matching, and it is not an omission.** The hook fires at
20
- `SessionStart`, BEFORE you have said anything, so there is no current task to match
21
- tags against. Tags remain useful for a human reading or grepping the file, and for
22
- `/myinsights recall <query>`, which searches on demand when a query exists.
17
+ On `UserPromptSubmit`, `.claude/hooks/session-insights.cjs` queries with the actual prompt.
18
+ Only a successful, non-empty `dz recall` result from the insight domain suppresses local
19
+ delivery. Absent, failing, or empty recall falls back to the three most recent Markdown
20
+ entries; a present-but-failing recall is named, while ordinary absence and empty output are
21
+ quiet. `SessionStart` only keeps the missing-carrier hint.
23
22
 
24
- **The consequence, so nobody is surprised by it.** The file is append-only and the
25
- hook takes the LAST three. As a project accumulates entries `insights-capture.md`
26
- plans for 50+ earlier ones stop being injected. Selection by relevance would need
27
- to happen at a moment when a task is known; that is a separate design question, and
28
- it is filed rather than quietly implied here.
23
+ **Fallback consequence.** The Markdown file is append-only, and local fallback takes the
24
+ last three entries by file order. In that fallback, earlier ones stop being injected as the
25
+ project grows. The dz path can rank older entries without replacing the durable carrier.
29
26
 
30
27
  ## Modes
31
28
 
@@ -68,22 +65,20 @@ Process:
68
65
 
69
66
  ## Storage
70
67
 
71
- `.claude/insights/index.md` — chronological log, Markdown format. One file per
72
- project to keep recall trivial.
68
+ `.claude/insights/index.md` — chronological Markdown source of truth. The optional
69
+ best-effort dz projection is derived from it and can be rebuilt by replay.
73
70
 
74
- ## Auto-injection on SessionStart
71
+ ## Prompt-time injection on UserPromptSubmit
75
72
 
76
73
  The default `.claude/settings.json` configures `node .claude/hooks/session-insights.cjs`
77
- which: (1) reads recent insights, (2) prints them to stdout, (3) Claude Code
78
- captures stdout and injects into the initial context.
79
-
80
- This is what makes insights compounding: every session benefits from past
81
- mistakes without manual recall.
74
+ for `UserPromptSubmit`. It emits one hook envelope from either armed dz recall or local
75
+ fallback, never both. The same script remains on `SessionStart` only to reveal a missing
76
+ Markdown carrier before the first capture.
82
77
 
83
78
  ## Related
84
79
 
85
80
  - `.claude/rules/insights-capture.md` — when/how to capture
86
81
  - `.claude/hooks/session-insights.cjs` — session injection
87
- - `/harvest` — extracts reusable knowledge at project end. **Honest limit:** it does
88
- NOT read `.claude/insights/index.md` today (`grep -ci insight` over `harvest.md`
89
- returns 0). The capture→harvest link is a stated intention, not a wired path.
82
+ - `/harvest` — quick/full runs and `/myinsights` share the same Markdown carrier at
83
+ `.claude/insights/index.md`. Harvest capture is a required final persistence gate when the run
84
+ produced a reusable finding; manual capture remains available at any time. Both stay append-only.