@dzhechkov/p-replicator 1.10.4 → 1.12.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 (68) hide show
  1. package/.dz-manifest.json +119 -47
  2. package/CHANGELOG.md +85 -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/README.md +1 -1
  9. package/README/ru/01_quickstart.md +3 -3
  10. package/README/ru/02_user_guide.md +1 -1
  11. package/README/ru/03_admin_guide.md +2 -2
  12. package/README/ru/04_api_reference.md +11 -5
  13. package/README/ru/README.md +1 -1
  14. package/README/ru/html/index.html +7 -7
  15. package/README.md +154 -38
  16. package/bin/cli.js +0 -0
  17. package/package.json +12 -10
  18. package/sbom.json +226 -46
  19. package/scripts/check-pipeline-gaps.sh +413 -0
  20. package/src/commands/doctor.js +94 -4
  21. package/src/rule-components.json +11 -0
  22. package/src/utils.js +3 -8
  23. package/templates/.claude/agents/harvest-coordinator.md +10 -1
  24. package/templates/.claude/commands/feature.md +57 -9
  25. package/templates/.claude/commands/go.md +11 -0
  26. package/templates/.claude/commands/harvest.md +41 -3
  27. package/templates/.claude/commands/myinsights.md +21 -26
  28. package/templates/.claude/commands/replicate.md +10 -1
  29. package/templates/.claude/commands/start.md +8 -0
  30. package/templates/.claude/hooks/check-ports.cjs +409 -20
  31. package/templates/.claude/hooks/session-insights.cjs +158 -25
  32. package/templates/.claude/hooks/statusline.cjs +2 -2
  33. package/templates/.claude/hooks/write-insight.cjs +253 -0
  34. package/templates/.claude/rules/cost-of-detection-ladder.md +96 -0
  35. package/templates/.claude/rules/docker-ports.md +41 -19
  36. package/templates/.claude/rules/feature-lifecycle.md +14 -3
  37. package/templates/.claude/rules/honest-configuration.md +54 -0
  38. package/templates/.claude/rules/insights-capture.md +10 -5
  39. package/templates/.claude/rules/replicate-pipeline.md +4 -2
  40. package/templates/.claude/rules/skill-interface-protocol.md +1 -0
  41. package/templates/.claude/rules/swarm-file-evidence.md +46 -0
  42. package/templates/.claude/settings.json +13 -1
  43. package/templates/.claude/skills/knowledge-extractor/modules/01-agent-review.md +16 -5
  44. package/templates/.claude/skills/sparc-prd-mini/SKILL.md +86 -16
  45. package/tests/e2e/lifecycle.test.js +55 -9
  46. package/tests/e2e/packed-insights-writer.test.js +308 -0
  47. package/tests/fixtures/prep-traceability-fixture/docs/features/order-refund/01_specification.md +29 -0
  48. package/tests/fixtures/prep-traceability-fixture/docs/features/order-refund/02_pseudocode.md +57 -0
  49. package/tests/snapshot/baseline.json +24 -20
  50. package/tests/snapshot/templates.test.js +47 -0
  51. package/tests/unit/absence-is-not-emptiness.test.js +15 -1
  52. package/tests/unit/check-pipeline-gaps.test.js +94 -0
  53. package/tests/unit/check-ports.test.js +729 -2
  54. package/tests/unit/db-port-rule.test.js +36 -5
  55. package/tests/unit/detection-ladder-contract.test.js +302 -0
  56. package/tests/unit/detection-ladder-registry.test.js +52 -0
  57. package/tests/unit/doctor-insight-flow.test.js +315 -0
  58. package/tests/unit/external-dependency-check.test.js +19 -19
  59. package/tests/unit/honest-failure-rules.test.js +492 -0
  60. package/tests/unit/hooks-project-anchored.test.js +67 -3
  61. package/tests/unit/insights-docs-tell-the-truth.test.js +52 -31
  62. package/tests/unit/insights-dz-delegation.test.js +197 -0
  63. package/tests/unit/insights-writer.test.js +285 -0
  64. package/tests/unit/shipped-suite-context.test.js +3 -1
  65. package/tests/unit/traceability-machine-ids.test.js +413 -0
  66. package/tests/unit/traceability-negative-fixture.test.js +322 -0
  67. package/tests/unit/utils.test.js +3 -2
  68. package/LICENSE +0 -21
@@ -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,22 @@ 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
+ #### Positive file receipt (required)
147
+
148
+ Before dispatch, allocate one `RUN_ID` and, for every independent unit, a unique `WORK_UNIT_ID`.
149
+ Resolve `TRACE_PATH` to an absolute path unique to `(RUN_ID, WORK_UNIT_ID)` and pass both fields.
150
+ Require the worker to write a substantive body ending in `Status: completed` or `Status: failed` to
151
+ `TRACE_PATH` before returning a one-line pointer. Before integration, verify each path is a regular
152
+ non-symlink file, non-whitespace, post-launch, and terminal. Narrative output or silence is not a
153
+ receipt. Name missing, stale, partial, unreadable, duplicate, failed, dead-PID, or probe-error units
154
+ and refuse merge/completion unless every required receipt is valid and completed. See
155
+ `.claude/rules/swarm-file-evidence.md` for mechanics and the bounded non-atomic-write exception.
109
156
 
110
157
  ### Phase 4: REVIEW (brutal-honesty-review)
111
158
 
@@ -123,6 +170,7 @@ Findings classified by severity. Critical (blocker | high) MUST be fixed.
123
170
 
124
171
  Skip per-phase user confirmations. Auto-decisions:
125
172
  - Phase 1: proceed if all docs exist
173
+ - Phase 1 traceability: proceed only when `check-pipeline-gaps.sh` exits `0`; preserve exit `1`/`2`
126
174
  - Phase 2: proceed if 🟢 or 🟡; auto-retry once on 🔴
127
175
  - Phase 3: proceed if tests + lint + build green
128
176
  - Phase 4: auto-fix `high` if straightforward; halt on `blocker`
@@ -73,6 +73,17 @@ 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 any selected pipeline that dispatches parallel work, allocate one `RUN_ID`, a unique
79
+ `WORK_UNIT_ID`, and an absolute `TRACE_PATH` per unit. Require each worker to write a substantive body
80
+ ending in `Status: completed` or `Status: failed` to `TRACE_PATH` before its one-line pointer. Before
81
+ the routed pipeline reports merge, synthesis, or completion, verify each path is a regular non-symlink
82
+ file, non-whitespace, post-launch, and terminal. Narrative output or silence is not a receipt. Name
83
+ missing, stale, partial, unreadable, duplicate, failed, dead-PID, or probe-error units and refuse
84
+ aggregation/completion unless every required receipt is valid and completed. The selected pipeline
85
+ owns the paths; this router never substitutes its own report. See `.claude/rules/swarm-file-evidence.md`.
86
+
76
87
  ## Step 6: Post-Implementation
77
88
 
78
89
  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,44 @@ 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
+ Before the five-agent dispatch, allocate one `RUN_ID`, then assign every perspective a unique
59
+ `WORK_UNIT_ID` and absolute `TRACE_PATH`. Require each agent to write a substantive body ending in
60
+ `Status: completed` or `Status: failed` to `TRACE_PATH` before returning a one-line pointer. Before
61
+ classification or synthesis, verify every path is a regular non-symlink file, non-whitespace,
62
+ post-launch, and terminal. Narrative output or silence is not a receipt. Name missing, stale, partial,
63
+ unreadable, duplicate, failed, dead-PID, or probe-error perspectives and refuse harvest completion
64
+ unless every required receipt is valid and completed. See `.claude/rules/swarm-file-evidence.md`.
65
+
66
+ ## REQUIRED INSIGHT PERSISTENCE GATE (quick/full only)
67
+
68
+ After Phase 4 and before the normal harvest completion report:
69
+
70
+ 1. Select one specific, reusable finding from this run. Populate all fields in this JSON object:
71
+ `date` (`YYYY-MM-DD`, owned by this caller), `title`, `tags` (array), `problem`, `solution`, and
72
+ `references` (array). Do not invent a generic record merely to satisfy the gate.
73
+ 2. If the run produced no candidate, write nothing and report exactly that insight capture remains
74
+ incomplete because no candidate was found. This is distinct from silently skipping the gate.
75
+ 3. Otherwise, write the JSON to a temporary UTF-8 file outside `.claude/insights/`, then pass its
76
+ bytes on stdin to the project-root helper `.claude/hooks/write-insight.cjs`. Do not put record
77
+ contents in shell arguments. The helper owns lazy carrier creation, append preservation, and
78
+ exact-repeat suppression. It establishes the Markdown source of truth first, then attempts a
79
+ best-effort idempotent `dz teach` duplicate.
80
+ 4. Require exit zero and parse exactly one JSON receipt. Only `created`, `appended`, or `duplicate`
81
+ is valid. Verify `.claude/insights/index.md` exists after `created` or `appended`. The nested
82
+ `teach.state` is optional-projection observability, not a second persistence receipt.
83
+ 5. Delete the temporary JSON only after a valid receipt. Include its status and `entryCount` in the
84
+ completion report, plus `teach.state` when present. A failed teach retains Markdown and does not
85
+ block completion. If the writer exits non-zero or its receipt is absent/malformed, MUST NOT report
86
+ the harvest as completed; show the persistence failure and keep the input for diagnosis.
87
+
88
+ `marker` mode is only a future-work marker: it does not invoke `write-insight.cjs`, does not create
89
+ `.claude/insights/`, and does not claim a completed quick/full harvest.
90
+
55
91
  ### Module References
56
92
 
57
93
  | Phase | Module |
@@ -97,6 +133,7 @@ Phase 4: INTEGRATE — write to toolkit, update index, harvest report
97
133
  - Decontextualize in Phase 3 (no project-specific references)
98
134
  - Assign maturity level to every artifact
99
135
  - Record provenance (source project, date)
136
+ - For quick/full with a real finding, persist one insight and validate the writer receipt before completion
100
137
 
101
138
  ### NEVER
102
139
  - Don't copy code verbatim — always decontextualize
@@ -104,3 +141,4 @@ Phase 4: INTEGRATE — write to toolkit, update index, harvest report
104
141
  - Don't extract library workarounds without expiry dates
105
142
  - Don't skip Phase 3 — undecontextualized artifacts are tech debt
106
143
  - Don't set maturity higher than 🔴 Alpha for first extraction
144
+ - 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.
@@ -329,6 +329,15 @@ Read the skill: `.claude/skills/requirements-validator/SKILL.md`
329
329
  The sixth lens is the only one that looks OUTSIDE the documents. The other five compare our own
330
330
  output with our own output, which cannot discover that a service does not do what we assumed.
331
331
 
332
+ **Positive file receipt (required).** Before dispatch, allocate one `RUN_ID` and give every
333
+ validation lens a unique `WORK_UNIT_ID` and absolute `TRACE_PATH`. Each validator must write a
334
+ substantive report fragment ending in `Status: completed` or `Status: failed` to `TRACE_PATH` before
335
+ its one-line pointer. Before AGGREGATE, verify every path is a regular non-symlink file,
336
+ non-whitespace, post-launch, and terminal. Narrative output or silence is not a receipt. Name
337
+ missing, stale, partial, unreadable, duplicate, failed, dead-PID, or probe-error lenses and refuse
338
+ aggregation/completion unless every required receipt is valid and completed. See
339
+ `.claude/rules/swarm-file-evidence.md`.
340
+
332
341
  **Process (iterative, max 3 iterations):**
333
342
 
334
343
  ```
@@ -475,7 +484,7 @@ Read the skill: `.claude/skills/cc-toolkit-generator-enhanced/SKILL.md`
475
484
  - **Pre-shipped by `npx p-replicator init` — do NOT overwrite or regenerate:**
476
485
  - All 10 skills in `.claude/skills/`
477
486
  - All 11 commands: `/replicate`, `/harvest`, `/start`, `/plan`, `/feature`, `/go`, `/run`, `/next`, `/myinsights`, `/docs`, `/deploy`
478
- - All 6 rules: `replicate-pipeline`, `skill-interface-protocol`, `git-workflow`, `insights-capture`, `feature-lifecycle`, `docker-ports`
487
+ - All 9 rules: `cost-of-detection-ladder`, `replicate-pipeline`, `skill-interface-protocol`, `git-workflow`, `insights-capture`, `feature-lifecycle`, `docker-ports`, `swarm-file-evidence`, `honest-configuration`
479
488
  - All 4 pipeline agents: `replicate-coordinator`, `product-discoverer`, `doc-validator`, `harvest-coordinator`
480
489
  - `.claude/settings.json` + cross-platform Node hook scripts in `.claude/hooks/`
481
490
  - Phase 3 generates ONLY project-specific artifacts derived from SPARC docs (see below).
@@ -69,6 +69,14 @@ Generate: src/<files>, tests/<files>, package.json, README.md
69
69
  Commits: one per logical group.
70
70
  ```
71
71
 
72
+ Before dispatch, allocate one `RUN_ID`, a unique `WORK_UNIT_ID`, and an absolute `TRACE_PATH` for
73
+ each package. Require each Task to write a substantive body ending in `Status: completed` or
74
+ `Status: failed` to `TRACE_PATH` before its one-line pointer. Before Phase 3 integration, verify every
75
+ path is a regular non-symlink file, non-whitespace, post-launch, and terminal. Narrative output or
76
+ silence is not a receipt. Name missing, stale, partial, unreadable, duplicate, failed, dead-PID, or
77
+ probe-error packages and refuse integration/completion unless every required receipt is valid and
78
+ completed. See `.claude/rules/swarm-file-evidence.md`.
79
+
72
80
  ### Phase 3: Integration (sequential)
73
81
 
74
82
  1. Verify cross-package imports