peaks-cli 1.3.7 → 1.3.9

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 (98) hide show
  1. package/dist/src/cli/commands/core-artifact-commands.js +119 -14
  2. package/dist/src/cli/commands/project-commands.js +58 -1
  3. package/dist/src/cli/commands/request-commands.js +124 -4
  4. package/dist/src/cli/commands/retrospective-commands.d.ts +3 -0
  5. package/dist/src/cli/commands/retrospective-commands.js +113 -0
  6. package/dist/src/cli/program.js +2 -0
  7. package/dist/src/services/artifacts/request-artifact-service.d.ts +16 -0
  8. package/dist/src/services/artifacts/request-artifact-service.js +18 -2
  9. package/dist/src/services/memory/project-memory-service.d.ts +19 -0
  10. package/dist/src/services/memory/project-memory-service.js +33 -0
  11. package/dist/src/services/retrospective/migrate-from-md.d.ts +37 -0
  12. package/dist/src/services/retrospective/migrate-from-md.js +528 -0
  13. package/dist/src/services/retrospective/retrospective-index.d.ts +37 -0
  14. package/dist/src/services/retrospective/retrospective-index.js +110 -0
  15. package/dist/src/services/retrospective/retrospective-show.d.ts +40 -0
  16. package/dist/src/services/retrospective/retrospective-show.js +109 -0
  17. package/dist/src/services/session/caller-binding-service.d.ts +70 -0
  18. package/dist/src/services/session/caller-binding-service.js +148 -0
  19. package/dist/src/services/session/caller-id-types.d.ts +77 -0
  20. package/dist/src/services/session/caller-id-types.js +46 -0
  21. package/dist/src/services/session/index.d.ts +4 -0
  22. package/dist/src/services/session/index.js +5 -0
  23. package/dist/src/services/session/platform-fallbacks.d.ts +31 -0
  24. package/dist/src/services/session/platform-fallbacks.js +35 -0
  25. package/dist/src/services/session/resolve-caller-id.d.ts +57 -0
  26. package/dist/src/services/session/resolve-caller-id.js +88 -0
  27. package/dist/src/services/skills/skill-presence-service.d.ts +11 -0
  28. package/dist/src/services/skills/skill-presence-service.js +59 -0
  29. package/dist/src/shared/format-md-compact.d.ts +32 -0
  30. package/dist/src/shared/format-md-compact.js +297 -0
  31. package/dist/src/shared/stale-policy.d.ts +67 -0
  32. package/dist/src/shared/stale-policy.js +85 -0
  33. package/dist/src/shared/version.d.ts +1 -1
  34. package/dist/src/shared/version.js +1 -1
  35. package/package.json +1 -1
  36. package/skills/peaks-qa/SKILL.md +86 -515
  37. package/skills/peaks-qa/references/artifact-per-request.md +7 -79
  38. package/skills/peaks-qa/references/browser-validation-contracts.md +51 -0
  39. package/skills/peaks-qa/references/codegraph-regression-focus.md +5 -0
  40. package/skills/peaks-qa/references/external-capability-guidance.md +9 -0
  41. package/skills/peaks-qa/references/qa-compact-handoff.md +3 -0
  42. package/skills/peaks-qa/references/qa-context-governance.md +24 -0
  43. package/skills/peaks-qa/references/qa-fanout-contract.md +8 -0
  44. package/skills/peaks-qa/references/qa-gstack-integration.md +7 -0
  45. package/skills/peaks-qa/references/qa-local-artifacts.md +3 -0
  46. package/skills/peaks-qa/references/qa-matt-pocock-integration.md +9 -0
  47. package/skills/peaks-qa/references/qa-refactor-role.md +3 -0
  48. package/skills/peaks-qa/references/qa-runbook.md +74 -0
  49. package/skills/peaks-qa/references/qa-skill-presence.md +22 -0
  50. package/skills/peaks-qa/references/qa-standards-preflight.md +8 -0
  51. package/skills/peaks-qa/references/qa-sub-agent-dispatch.md +38 -0
  52. package/skills/peaks-qa/references/qa-transition-gates.md +79 -0
  53. package/skills/peaks-qa/references/requirement-boundary-recheck.md +9 -0
  54. package/skills/peaks-qa/references/test-case-generation.md +27 -0
  55. package/skills/peaks-qa/references/test-report-output.md +14 -0
  56. package/skills/peaks-rd/SKILL.md +85 -732
  57. package/skills/peaks-rd/references/artifact-and-standards-output.md +9 -0
  58. package/skills/peaks-rd/references/artifact-per-request.md +20 -0
  59. package/skills/peaks-rd/references/browser-self-test-contracts.md +29 -0
  60. package/skills/peaks-rd/references/codegraph-project-analysis.md +5 -0
  61. package/skills/peaks-rd/references/compact-handoff.md +3 -0
  62. package/skills/peaks-rd/references/external-references.md +11 -0
  63. package/skills/peaks-rd/references/frontend-project-generation.md +11 -0
  64. package/skills/peaks-rd/references/library-version-awareness.md +30 -0
  65. package/skills/peaks-rd/references/mandatory-perf-baseline.md +40 -0
  66. package/skills/peaks-rd/references/mandatory-tech-doc.md +18 -0
  67. package/skills/peaks-rd/references/matt-pocock-integration.md +11 -0
  68. package/skills/peaks-rd/references/mock-data-placement.md +40 -0
  69. package/skills/peaks-rd/references/parallel-review-fanout.md +81 -0
  70. package/skills/peaks-rd/references/rd-context-governance.md +36 -0
  71. package/skills/peaks-rd/references/rd-gstack-integration.md +16 -0
  72. package/skills/peaks-rd/references/rd-runbook.md +125 -0
  73. package/skills/peaks-rd/references/rd-standards-preflight.md +8 -0
  74. package/skills/peaks-rd/references/rd-sub-agent-dispatch.md +39 -0
  75. package/skills/peaks-rd/references/rd-transition-gates.md +148 -0
  76. package/skills/peaks-rd/references/skill-presence-and-title.md +22 -0
  77. package/skills/peaks-solo/SKILL.md +87 -786
  78. package/skills/peaks-solo/references/anchoring-and-session-info.md +25 -0
  79. package/skills/peaks-solo/references/boundaries.md +21 -0
  80. package/skills/peaks-solo/references/codegraph-orchestration.md +5 -0
  81. package/skills/peaks-solo/references/completion-handoff.md +16 -0
  82. package/skills/peaks-solo/references/context-governance.md +51 -0
  83. package/skills/peaks-solo/references/external-references.md +17 -0
  84. package/skills/peaks-solo/references/frontend-only-mode.md +87 -0
  85. package/skills/peaks-solo/references/gstack-integration.md +7 -0
  86. package/skills/peaks-solo/references/local-artifact-workspace.md +79 -0
  87. package/skills/peaks-solo/references/micro-cycle.md +68 -0
  88. package/skills/peaks-solo/references/mode-selection.md +21 -0
  89. package/skills/peaks-solo/references/openspec-workflow.md +43 -0
  90. package/skills/peaks-solo/references/project-memory-loading.md +17 -0
  91. package/skills/peaks-solo/references/project-scan-checklist.md +136 -0
  92. package/skills/peaks-solo/references/quality-gate-cheatsheet.md +13 -0
  93. package/skills/peaks-solo/references/resume-detection.md +63 -0
  94. package/skills/peaks-solo/references/runbook.md +1 -1
  95. package/skills/peaks-solo/references/skill-presence-and-title.md +31 -0
  96. package/skills/peaks-solo/references/standards-preflight.md +23 -0
  97. package/skills/peaks-solo/references/sub-agent-dispatch.md +46 -0
  98. package/skills/peaks-solo/references/swarm-dispatch-contract.md +56 -0
@@ -7,31 +7,7 @@ description: Research and development skill for Peaks. Use for engineering analy
7
7
 
8
8
  > **Read once at the top of this file; the rest of the skill is written against it.**
9
9
 
10
- The `.peaks/` workspace is partitioned by **two orthogonal axes**. Every path in this SKILL.md uses one of them; mixing them is the original `.peaks/<sid>/` / `.peaks/_runtime/<sid>/` bug class this slice corrects.
11
-
12
- | Axis | Path root | Holds | When to use |
13
- |---|---|---|---|
14
- | **change-id axis** (reviewable artifacts) | `.peaks/<changeId>/...` | PRD, RD plan, code-review, security-review, test-cases, handoff capsules, gate targets | The artifact should be reviewable on its own and survives across sessions for the same change. Change-id is the unit of work. |
15
- | **session-id axis** (ephemeral state) | `.peaks/_runtime/<sessionId>/...` | Session bindings (`.peaks/_runtime/session.json`), live in-flight state, the per-session project-scan and tech-doc scaffold while the session is open | The artifact is session-scoped and only meaningful while the parent session is live. |
16
- | **sub-agent axis** | `.peaks/_sub_agents/<sessionId>/...` | Sub-agent dispatch records, sub-agent heartbeats, per-sub-agent shared channel entries, sub-agent artifact outputs | A sub-agent ran in a parent session. The axis nests under the parent session-id; sub-agent outputs are flushed into the change-id root on commit. |
17
-
18
- **Which CLI commands operate on which axis:**
19
-
20
- - **change-id axis** (reviewable artifacts): `peaks request init`, `peaks request transition`, `peaks request show`, `peaks request lint`, `peaks request repair-status`, `peaks scan diff-vs-scope`, `peaks scan acceptance-coverage`. Inputs reference `.peaks/<changeId>/...`.
21
- - **session-id axis** (ephemeral state): `peaks session info`, `peaks session start`, `peaks session finish`, `peaks session list`. Reads/writes `.peaks/_runtime/<sessionId>/session.json`.
22
- - **sub-agent axis** (under parent session-id): `peaks sub-agent dispatch`, `peaks sub-agent heartbeat`, `peaks sub-agent share`, `peaks sub-agent shared-read`. All output paths are under `.peaks/_sub_agents/<sessionId>/...`.
23
-
24
- **Placeholder convention used in this file:**
25
-
26
- - `<changeId>` / `<change-id>` — the change-id axis. Use when describing a path that lives at `.peaks/<changeId>/...` (root-level, NOT inside `_runtime/`).
27
- - `<sessionId>` / `<session-id>` — the session-id axis. Use when describing a path that lives at `.peaks/_runtime/<sessionId>/...` or `.peaks/_sub_agents/<sessionId>/...`. The long form `<session-id>` is used inside bash / shell examples where `<sessionId>` would break parsing.
28
- - The bare `<sid>` placeholder is **forbidden** in new content — it is ambiguous between the two axes. Legacy occurrences are replaced by this convention; new content must use the right axis label.
29
-
30
- **Cross-references:**
31
-
32
- - Slice `2026-06-05-change-id-as-unit-of-work` (commits `48958fc` + `928eb53`) — established the change-id axis as the canonical root for reviewable artifacts (`src/shared/change-id.ts:131,335`, `src/services/scan/acceptance-coverage-service.ts:155`).
33
- - Slice `005-session-runtime-dir-regression` (commit `178a47e`) — added the `getSessionDir()` resolver at `src/services/session/getSessionDir.ts` and routed 4 stragglers that were constructing `.peaks/${sessionId}` (no `_runtime/`) through the canonical resolver. Defense-in-depth scan: `tests/unit/services/session/session-dir-canonical.test.ts`.
34
- - Slice `006-5th-writer-changeid-path` (this slice) — disambiguates the SKILL.md placeholders and adds the regression test `tests/unit/skills/skills-skill-md-naming.test.ts` that mechanically enforces (a) zero bare `<sid>`, (b) every `.peaks/<X>/` reference has an axis label, (c) the "Two-axis naming convention" callout is present in `peaks-solo`, `peaks-rd`, `peaks-qa`.
10
+ The `.peaks/` workspace is partitioned by **two orthogonal axes**: **change-id** (reviewable artifacts at `.peaks/<changeId>/...`) and **session-id** (ephemeral state at `.peaks/_runtime/<sessionId>/...`), with a nested **sub-agent axis** under `.peaks/_sub_agents/<sessionId>/...`. Use `<changeId>` / `<sessionId>` placeholders (NEVER bare `<sid>`). CLI axis mapping: change-id → `peaks request *` / `peaks scan *`; session-id → `peaks session *`; sub-agent → `peaks sub-agent *`. Regression test `tests/unit/skills/skills-skill-md-naming.test.ts` enforces (a) zero bare `<sid>`, (b) every `.peaks/<X>/` has an axis label, (c) this callout is present.
35
11
 
36
12
  # Peaks-Cli RD
37
13
 
@@ -39,94 +15,23 @@ Peaks-Cli RD owns engineering analysis, implementation planning, and refactor ex
39
15
 
40
16
  ## Hard contracts for browser self-test (BLOCKING — read before any browser_take_screenshot / login flow)
41
17
 
42
- For frontend or UI-affecting slices, RD's self-test uses the Playwright MCP headed browser to verify the implementation behaves correctly before handing off to QA. The two contracts below are identical in spirit to `peaks-qa`'s contracts — RD and QA share the same headed-browser path and the same evidence conventions; only the role differs.
43
-
44
- ### Contract 1 — Self-test screenshots must land under .peaks/_runtime/<sessionId>/qa/screenshots/
45
-
46
- Even though RD runs the self-test, **the screenshot evidence is QA's** by convention (the test report under `.peaks/_runtime/<sessionId>/qa/test-reports/` cites these paths). Therefore RD's Playwright screenshot tool calls (the LLM invokes `browser_take_screenshot` directly when the the Playwright MCP tools are present in the LLM's tool list) MUST pass `filename` (in the args object) whose absolute path is inside `.peaks/_runtime/<sessionId>/qa/screenshots/`, exactly the same contract QA enforces. Do not let Playwright fall back to the project root. If the the Playwright MCP tools are absent from the tool list, STOP and tell the user: `claude mcp add playwright -- npx @playwright/mcp@latest` (Claude Code) or consult the IDE's MCP install docs.
47
-
48
- ### Contract 2 — Login / CAPTCHA / SSO / MFA wall is a hard block, not a skip
49
-
50
- When the headed browser hits an auth wall, RD does **not** skip the browser gate. The skill must surface the wall with `AskUserQuestion` and pick one of three paths:
18
+ For frontend or UI-affecting slices, RD's self-test uses the Playwright MCP headed browser. Two contracts (1) self-test screenshots land under `.peaks/_runtime/<sessionId>/qa/screenshots/`, (2) login / CAPTCHA / SSO / MFA is a hard block — surface with `AskUserQuestion` and pick one of three paths. The full contract is identical in spirit to `peaks-qa`'s; RD and QA share the headed-browser path.
51
19
 
52
- ```
53
- AskUserQuestion({
54
- question: "Headed browser hit a login wall at <URL>. How should RD self-test proceed?",
55
- options: [
56
- { label: "I am logged in / I'll log in now",
57
- description: "Pause RD. The visible browser is already open; the user completes login in-place, then types 'logged in' or equivalent. RD resumes browser_navigate + browser_snapshot from the post-login page." },
58
- { label: "Skip browser self-test, hand off to QA",
59
- description: "Mark the slice's browser self-test as deferred. Do NOT mark the slice as RD-done; transition to qa-handoff with browser-gate=blocked reason=login-required, and let QA's gate machinery surface the wall to the user again." },
60
- { label: "Cancel the workflow",
61
- description: "Stop RD. Emit a blocked TXT handoff so peaks-solo can surface the auth wall to the user. Do not modify code paths that the browser gate would have covered." }
62
- ]
63
- })
64
- ```
65
-
66
- The full hard-block contract is defined in `peaks-qa` (see "Hard contracts for browser validation" there); RD inherits the same rules. Without an explicit decision from the user, RD does not advance past the wall.
20
+ → see `references/browser-self-test-contracts.md` for the full contract + AskUserQuestion options.
67
21
 
68
22
  ## Sub-agent dispatch (when launched by peaks-solo swarm)
69
23
 
70
- When this skill is launched as a sub-agent via `peaks sub-agent dispatch <role>` (then the LLM executes the returned toolCall) from `peaks-solo`, the following sections of THIS skill are **suspended** for the sub-agent run:
71
-
72
- - **Session id** — use the parent's sid (read `.peaks/_runtime/session.json` or pass `--session-id <parent-sid>` to any session-creating CLI). Do NOT spawn your own session. The new `peaks session info --active` reads the canonical binding for you.
73
- - **Skill presence (MANDATORY first action)** — do NOT call `peaks skill presence:set peaks-rd`. The sub-agent must not overwrite `.peaks/.active-skill.json`; the main Solo loop owns that file. If you need to mark your own state, write a marker file at `.peaks/_runtime/<sessionId>/system/sub-agent-rd.json` and only that.
74
- - **Workspace initialization** — Solo has already run `peaks workspace init` before fan-out. Do not re-run it.
75
- - **Mode selection** — Solo has already chosen the mode. Read it from the prompt arguments (or from `.peaks/.active-skill.json` if you can, but do not write it).
76
- - **Statusline install** — already done by Solo at session startup; do not re-run.
77
-
78
- What the sub-agent **MUST** still do, from this skill's contract:
79
-
80
- 0. **Do NOT call `peaks request init`** — Solo has already initialised the request artefact slot in the main loop before fan-out (the runbook has the exact `peaks request init --role rd --id <rid> --project <repo> --apply --type <type> --json` call). The sub-agent reads the slot via `peaks request show <rid> --role rd --project <repo> --json` if it needs to. Note: `peaks request init` is **dry-run by default**. Pass `--apply` to actually create the artifact.
81
- 2. `peaks request show <rid> --role prd --project <repo> --json` (and `--role ui` if UI is in the swarm plan).
82
- 3. Standards preflight (dry-run only; Solo owns the apply step).
83
- 4. Project-scan read; create `rd/project-scan.md` only if Solo flagged it missing in the dispatch prompt.
84
- 5. Write the planning artefact: `rd/tech-doc.md` (feature/refactor) or `rd/bug-analysis.md` (bugfix). If `--type` is `config|docs|chore`, **no planning artefact is required** — return immediately with `{"role":"rd-planning","status":"skipped","reason":"type=<type>"}`.
85
- 6. Return only a compact JSON envelope — Solo will run the convergence gate (`ls` checks):
86
-
87
- ```json
88
- {
89
- "role": "rd-planning",
90
- "rid": "<rid>",
91
- "status": "ok" | "blocked" | "skipped",
92
- "artefacts": [".peaks/_runtime/<sessionId>/rd/tech-doc.md"],
93
- "warnings": [],
94
- "blockedReason": null
95
- }
96
- ```
24
+ When this skill is launched as a sub-agent via `peaks sub-agent dispatch <role>` (then the LLM executes the returned toolCall) from `peaks-solo`, the following sections of THIS skill are **suspended** for the sub-agent run: Session id (use parent's), Skill presence (do NOT call `peaks skill presence:set peaks-rd`), Workspace initialization (already done by Solo), Mode selection, Statusline install.
97
25
 
98
- **Hard prohibitions** (sub-agent context, in addition to general red lines):
26
+ What the sub-agent MUST still do: read PRD via `peaks request show`, run standards preflight (dry-run only), write planning artefact (`rd/tech-doc.md` for feature/refactor; `rd/bug-analysis.md` for bugfix; skip for config/docs/chore), return compact JSON envelope.
99
27
 
100
- - Do NOT call `Skill(skill="...")` from inside the sub-agent that defeats the fan-out.
101
- - Do NOT call `peaks skill presence:set` — Solo owns the active-skill file.
102
- - Do NOT commit, push, install hooks, or apply settings.json mutations.
103
- - Do NOT ask the user interactive questions. If you need clarification, return `{"status":"blocked","blockedReason":"<text>"}` and let Solo handle the user message.
104
- - Do NOT modify code (the Swarm phase is planning only; code edits happen in the RD implementation phase, which is a separate sub-agent or inline run after Gate B).
105
-
106
- After returning, Solo re-checks Gate B (`ls .peaks/_runtime/<sessionId>/rd/tech-doc.md` etc.) and proceeds to RD implementation, which is a different sub-agent or inline run.
28
+ see `references/rd-sub-agent-dispatch.md` for the full contract + hard prohibitions.
107
29
 
108
30
  ## Skill presence (MANDATORY first action — main-loop context only)
109
31
 
110
- When this skill is running in the main Claude session (not as a sub-agent — i.e. user invoked `peaks-rd` directly, or `peaks-solo` is executing the role inline in assisted/strict mode), before any analysis or tool call, immediately run:
111
-
112
- ```bash
113
- peaks skill presence:set peaks-rd --project <repo> --mode <mode> --gate startup
114
- ```
115
-
116
- On the first presence:set in a project, ensure the out-of-band status bar is installed so the user can see at a glance that Peaks is orchestrating — it renders the active skill in Claude Code's terminal status line, independent of model output:
117
-
118
- ```bash
119
- peaks statusline install --project <repo> # idempotent; skips if already installed
120
- ```
121
-
122
- Read persistent project memory via CLI (durable, LLM-authored memories):
32
+ When this skill is running in the main Claude session (not as a sub-agent — i.e. user invoked `peaks-rd` directly, or `peaks-solo` is executing the role inline in assisted/strict mode), before any analysis or tool call, immediately run `peaks skill presence:set peaks-rd --project <repo> --mode <mode> --gate startup`. Install statusline on first run. Read durable project memory via `peaks project memories --project <repo> --json`.
123
33
 
124
- ```bash
125
- peaks project memories --project <repo> --json
126
- ```
127
-
128
- This returns durable memories from `.peaks/memory` — decisions, conventions, modules, and rules captured in past sessions. Filter with `--kind <decision|convention|module|rule|reference|project>`. (`.peaks/PROJECT.md` is a human-readable session timeline only.)
129
- Then display: `Peaks-Cli Skill: peaks-rd | Peaks-Cli Gate: startup | Next: <one short action>`. Update with `peaks skill presence:set peaks-rd --project <repo> --mode <mode> --gate <gate>` when gates change. When the role's work ends, run `peaks skill presence:clear --project <repo>`.
34
+ → see `references/skill-presence-and-title.md` for the full contract.
130
35
 
131
36
  ## Responsibilities
132
37
 
@@ -141,569 +46,83 @@ Then display: `Peaks-Cli Skill: peaks-rd | Peaks-Cli Gate: startup | Next: <one
141
46
 
142
47
  Every RD invocation — feature, bug, refactor, clarification — must write a durable artifact at `.peaks/_runtime/<sessionId>/rd/requests/<request-id>.md`. This is the canonical engineering record for that request; handoff to QA/SC is blocked while the artifact is missing or its state is `draft` or `spec-locked` without implementation evidence.
143
48
 
144
- Use the `<request-id>` PRD assigned. RD companion artifacts (task graph, scan report, coverage evidence, slice spec, dry-run output, MCP call results) live alongside this file under the same `rd/` workspace and are linked from it.
145
-
146
- Concrete template and rules: `references/artifact-per-request.md`.
147
-
148
- ## Two RD artifact files — do not confuse them
49
+ see `references/artifact-per-request.md` for the template + the "two RD artifact files" rule (per-slice vs per-session scope).
149
50
 
150
- RD has two distinct artifact files, and the most common regression is to write the per-slice content into the per-session file. They serve different readers and live in different places:
51
+ ## Default runbook
151
52
 
152
- | File | Scope | Reader | Required content |
153
- |---|---|---|---|
154
- | `.peaks/_runtime/<sessionId>/rd/tech-doc.md` | per-session — the whole RD plan for the session, all slices | Solo, future LLM, the human scrolling the session | Architecture, slice graph, mock strategy, cross-cutting decisions. **Not** the place for per-slice implementation evidence. |
155
- | `.peaks/_runtime/<sessionId>/rd/requests/<rid>.md` | per-slice — one request, one planning artifact | QA, SC, the lint gate | Red-line scope, in-scope / out-of-scope, unit-test requirements, **Implementation evidence** (file list, `pnpm test` output, git diff excerpts), MCP usage, handoff, status. **This is the file the lint gate checks for placeholders.** |
156
- | `.peaks/_runtime/<sessionId>/rd/code-review.md` | per-session — the engineering review | QA, the human reviewer | Code review findings + fixes. |
157
- | `.peaks/_runtime/<sessionId>/rd/security-review.md` | per-session — the security review | QA | Security review findings + fixes. |
53
+ The default sequence the RD skill should execute for a code-touching request. Skip steps that do not apply to the request type; do not skip the artifact, coverage gate, or red-line scope steps. The full 9-step runbook (steps #0–#8) with every CLI invocation, project-scan BLOCKING rule, component-library detection, CSS framework conflict check, and 6 transition gates is in the references file.
158
54
 
159
- **Failure mode the lint gate catches**: the LLM writes the actual implementation content into `rd/tech-doc.md` and leaves `rd/requests/<rid>.md` as the default template (with placeholder sections like "Implementation evidence: 留待 RD 实施阶段补充" and "MCP usage: N/A"). The lint gate then fails the slice with 6+ lint errors on the `<rid>.md` template even though the actual content lives in `tech-doc.md`.
55
+ see `references/rd-runbook.md` for the full runbook.
160
56
 
161
- **Rule**:
162
- - **Per-slice content** (red-line scope, in-scope / out-of-scope, the implementation evidence list, the unit-test assertions, the handoff) → **belongs in `rd/requests/<rid>.md`**.
163
- - **Per-session content** (the architecture overview, the slice roadmap, the cross-cutting concerns, the mock strategy for the whole session) → **belongs in `rd/tech-doc.md`**.
164
- - When in doubt: copy the per-slice content into the `<rid>.md` artifact's "Implementation evidence" section after writing it to `tech-doc.md`. The two files can carry overlapping context; the gate only enforces that `<rid>.md` is not empty placeholders.
57
+ ## RD gate index
165
58
 
166
- Concrete template and rules: `references/artifact-per-request.md`.
59
+ You cannot declare a phase complete from memory. Each gate below is a `ls` or `grep` command you **MUST run** and whose output you **MUST see** before proceeding. CLI enforcement: the gates are ALSO enforced by `peaks request transition`, which fails with `code: PREREQUISITES_MISSING` if any are absent. Per-type required files: see the table at the top of `references/rd-transition-gates.md`.
167
60
 
168
- ## Default runbook
61
+ Gate index: A (project-scan), A2 (tech-doc path verification), A3 (CLAUDE.md + .claude/rules), B (tech-doc + request artifact), B2 (unit tests on changed surface), B3 (code-review.md), B4 (security-review.md), B5 (lint — no unfilled placeholders), B6 (request-type-sanity), B7 (repair-status — 3-cycle cap), B8 (diff-vs-scope), B9 (perf-baseline).
169
62
 
170
- The default sequence the RD skill should execute for a code-touching request. Skip steps that do not apply to the request type; do not skip the artifact, coverage gate, or red-line scope steps.
171
-
172
- ```bash
173
- # 0. confirm RD's own runbook integrity before any code edit
174
- peaks skill runbook peaks-rd --json
175
- peaks skill presence:set peaks-rd --project <repo> # show persistent skill presence every turn
176
-
177
- # 1. capture the RD request artifact and read upstream PRD / UI scope
178
- peaks request init --role rd --id <request-id> --project <repo> --apply --json
179
- peaks request show <request-id> --role prd --project <repo> --json
180
- peaks request show <request-id> --role ui --project <repo> --json # if UI involved
181
-
182
- # 2. standards preflight before planning any code edit
183
- peaks standards init --project <repo> --dry-run --json
184
- peaks standards update --project <repo> --dry-run --json
185
-
186
- # 3. pull OpenSpec context when openspec/ exists in the repo
187
- peaks openspec list --project <repo> --json
188
- peaks openspec show <change-id> --project <repo> --json
189
- peaks openspec validate <change-id> --project <repo> --json # entry gate
190
- peaks openspec to-rd <change-id> --project <repo> --json # acceptance + commit boundaries
191
-
192
- # 4. project-analysis evidence — MANDATORY before implementation
193
- peaks understand status --project <repo> --json
194
- peaks understand show --project <repo> --json # when UA artifact exists
195
- peaks codegraph context --project <repo> "<task>"
196
- peaks codegraph affected --project <repo> <changed-files...> --json
197
-
198
- # 4.1 read project-scan from Solo's pre-RD scan — BLOCKING if missing
199
- # **STOP if .peaks/_runtime/<sessionId>/rd/project-scan.md does not exist.**
200
- # **Do not write any code, do not plan any implementation, do not pass go.**
201
- # **Create the project-scan first, then proceed.**
202
- # NOTE: project-scan.md is a session-scoped singleton. Check if it already exists
203
- # before regenerating (e.g. via `ls .peaks/<changeId>/rd/project-scan.md`). If it exists
204
- # and is complete (has `## Archetype` and `## Project mode` sections), reuse it.
205
- # Required sections in project-scan:
206
- # - build tool and framework
207
- # - component library (antd, MUI, shadcn, etc.) and version
208
- # - CSS solution (Less, Sass, TailwindCSS, CSS-in-JS) and conflicts
209
- # - state management, routing, data fetching libraries
210
- #
211
- # After writing project-scan, embed durable memory markers for stable project facts.
212
- # Append one <!-- peaks-memory:start --> block per fact at the end of project-scan.md:
213
- #
214
- # <!-- peaks-memory:start -->
215
- # title: <component library>
216
- # kind: module
217
- # ---
218
- # <Library> <version> — detected from package.json and source imports.
219
- # <!-- peaks-memory:end -->
220
- #
221
- # Embed markers for: component library, CSS solution, build tool, state management,
222
- # routing, data fetching, and any legacy constraints. These facts are session-invariant
223
- # and valuable for future sessions. Do NOT embed secrets, credentials, or transient state.
224
-
225
- # 4.2 component library detection — verify against package.json, not assumptions
226
- # WRONG: "looks like a React project, let me use shadcn/ui"
227
- # RIGHT: check package.json for antd/@mui/@shadcn/etc., match imports in source files
228
-
229
- # 4.3 CSS framework conflict check (CRITICAL)
230
- # Detect conflicts BEFORE adding any CSS dependency:
231
- # - TailwindCSS + antd → HIGH conflict (preflight reset vs antd base styles)
232
- # - TailwindCSS + MUI → HIGH conflict (utility classes vs sx/system props)
233
- # - Adding a second CSS-in-JS lib to a project that already has one → BLOCK
234
- # - Adding Less/Sass to a CSS-in-JS project → wasteful, not conflicting
235
- # If a conflict is detected, DO NOT add the conflicting dependency.
236
- # Record the conflict in the RD artifact and propose a compatible alternative.
237
-
238
- # 4.4 source-code component import verification
239
- # grep source files for actual component imports to confirm library usage:
240
- # grep -r "from 'antd'" src/ --include="*.tsx" --include="*.ts"
241
- # grep -r "from '@mui/material'" src/ --include="*.tsx"
242
- # grep -r "from '@/components/ui'" src/ --include="*.tsx"
243
-
244
- # 4.5 mock data strategy — MANDATORY for frontend-only projects
245
- # Check project-scan for the detected build tool:
246
- # Umi → use mock/*.ts (Umi's built-in mock directory)
247
- # Vite → use src/mock/ (service-layer mock files)
248
- # Next.js → match existing project pattern
249
- # NEVER write mock data inline in component files.
250
- # See "Mock data placement rules" section for the full framework mapping.
251
-
252
- # 5. optional library docs lookup through the LLM's own tool list (Context7 MCP)
253
- # If the Context7 MCP is present in the tool list, invoke the
254
- # tool directly (resolve-library-id / query-docs / etc.). If absent, skip
255
- # library docs and rely on existing project knowledge — do NOT hand-edit
256
- # `~/.claude/settings.json` to install MCPs.
257
-
258
- # 6. record red-line scope, slice contract, coverage status into the RD artifact, then implement
259
-
260
- # 6.5 BEFORE tech-doc: verify EVERY path in the tech-doc against actual project structure (Peaks-Cli Gate A2)
261
- # ls every directory path in the tech-doc — zero "No such file" allowed
262
- # This is the most common RD failure mode. Do not skip it.
263
-
264
- # 6.6 BEFORE implementation: verify CLAUDE.md + .claude/rules/ exist (Peaks-Cli Gate A3)
265
- # Missing standards files → run `peaks standards init --project .` first
266
- # Without project rules, security review and code review triggers won't fire.
267
-
268
- # 7. AFTER implementation, BEFORE QA handoff — RUN THESE GATES:
269
- # Peaks-Cli Gate B2: unit tests exist and pass for the changed surface → npx vitest run --changed (or project equivalent; the changed-only mode is the peaks slice check default as of run 017; use --run-tests for the full suite, or invoke /peaks-solo-test to run the full suite standalone)
270
- # Peaks-Cli Gate B3: code review evidence → .peaks/<changeId>/rd/code-review.md
271
- # Peaks-Cli Gate B4: security review evidence → .peaks/<changeId>/rd/security-review.md
272
- # Peaks-Cli Gate B5 (NEW): RD artifact body has no unfilled placeholders.
273
- peaks request lint <rid> --role rd --project <repo> --session-id <session-id> --json
274
- # Peaks-Cli Gate B6 (NEW): declared --type still matches the actual diff after implementation.
275
- peaks scan request-type-sanity --project <repo> --type <type> --json
276
- # Peaks-Cli Gate B7 (NEW, repair cycles only): we have not exceeded the 3-cycle cap.
277
- peaks request repair-status <rid> --project <repo> --session-id <session-id> --json
278
- # Peaks-Cli Gate B8 (NEW): every changed file matches the RD red-line scope (no out-of-bounds writes).
279
- peaks scan diff-vs-scope --rid <rid> --project <repo> --session-id <session-id> --json
280
- # All six non-zero → BLOCKED. Fix and re-check before attempting the qa-handoff transition.
281
-
282
- # 7. self-validate before QA handoff
283
- peaks openspec validate <change-id> --project <repo> --json # exit gate (re-run)
284
-
285
- # 8. hand off to QA via the cross-linked request id
286
- peaks request init --role qa --id <request-id> --project <repo> --apply --json
287
- peaks request show <request-id> --role rd --project <repo> --json
288
- peaks project memories:extract --session-id <session-id> --project <repo> --json # extract durable memories
289
- peaks skill presence:clear --project <repo> # handoff complete, remove presence indicator
290
- ```
291
-
292
- For refactor work, the coverage ≥ 95% gate in `Refactor hard gates` still applies and must be recorded in the artifact before slicing begins.
293
-
294
- ### Transition verification gates (MANDATORY — run the command, see the output)
295
-
296
- You cannot declare a phase complete from memory. Each gate below is a `ls` or `grep` command you **MUST run** and whose output you **MUST see** before proceeding. If any file shows "No such file" or any command returns empty, the phase is incomplete.
297
-
298
- > **CLI enforcement (NEW)**: the gates below are now ALSO enforced by `peaks request transition`. The CLI checks the same files before allowing the transition and fails with `code: PREREQUISITES_MISSING` if any are absent. The exact required files depend on the request type chosen at `peaks request init --type <feature|bugfix|refactor|docs|config|chore>` (default `feature`):
299
- >
300
- > | Type | rd:implemented requires | rd:qa-handoff also requires |
301
- > |---|---|---|
302
- > | feature / refactor | `rd/tech-doc.md` | `rd/code-review.md` + `rd/security-review.md` + `rd/perf-baseline.md` (filled Results table, or `N/A — no perf surface` in Notes) + **`qa/test-cases/<rid>.md`** (added in slice 004; pre-drafted by the 4th sub-agent in the parallel fan-out) |
303
- > | bugfix | `rd/bug-analysis.md` (lighter than tech-doc; root cause + fix + regression test plan) | `rd/code-review.md` + `rd/security-review.md` + **`qa/test-cases/<rid>.md`**; `rd/perf-baseline.md` only when the bug is performance-shaped (matches the L449-452 "When this applies" criteria) |
304
- > | config | (none) | `rd/security-review.md` only |
305
- > | docs / chore | (none) | (none) |
306
- >
307
- > The escape hatch `--allow-incomplete --reason "<text>"` still exists for one-off exceptions; the bypass is recorded in the artifact transition note.
308
-
309
- **Peaks-Cli Gate A — After project-scan read (before any implementation):**
310
- ```bash
311
- ls .peaks/<changeId>/rd/project-scan.md
312
- # Expected output: .peaks/<changeId>/rd/project-scan.md
313
- # "No such file" → STOP, create the project-scan first. Do not write code.
314
- ```
315
-
316
- **Peaks-Cli Gate A2 — Before tech-doc write: project structure verified (PATH CORRECTNESS — CRITICAL):**
317
- ```bash
318
- # Verify EVERY file path and directory in the tech-doc exists in the actual project.
319
- # Do not assume paths. Do not guess directory structures. Open the files and verify.
320
- # Example verification (adapt paths to the actual tech-doc):
321
- ls <every-single-directory-path-in-tech-doc> 2>&1 | grep -c "No such file"
322
- # Expected: 0 (zero "No such file" errors)
323
- # Any "No such file" → WRONG PATH. Fix the tech-doc BEFORE writing another word.
324
- # This gate exists because a tech-doc with wrong paths wastes QA time,
325
- # breaks the implementation, and forces the user to correct the engineer.
326
- ```
327
-
328
- **Peaks-Cli Gate A3 — Before implementation: project standards files exist (CLAUDE.md + .claude/rules/):**
329
- ```bash
330
- ls CLAUDE.md .claude/rules/common/coding-style.md .claude/rules/common/code-review.md .claude/rules/common/security.md 2>&1 | grep -c "No such file"
331
- # Expected: 0 (all four files exist)
332
- # Any missing → BLOCKED. Run `peaks standards init --project .` to generate them FIRST.
333
- # Do not write a single line of implementation code without standards files in place.
334
- # Without CLAUDE.md and .claude/rules/, code review and security review triggers won't fire.
335
- ```
336
-
337
- **Peaks-Cli Gate B — Before QA handoff:**
338
- ```bash
339
- ls .peaks/<changeId>/rd/requests/<rid>.md \
340
- .peaks/<changeId>/rd/tech-doc.md
341
- # Both must exist. Missing either → BLOCKED, do not hand off to QA
342
- ```
343
-
344
- **Peaks-Cli Gate B2 — Before QA handoff: unit tests exist and pass for the changed surface:**
345
- ```bash
346
- # Run the project's test command against changed files. Record the output.
347
- # Example (adapt to project test runner):
348
- npx vitest run --changed --reporter=verbose 2>&1 | tail -20
349
- # Expected: exit code 0, all changed-surface tests passing, coverage for new/changed code recorded
350
- # Any failing test or zero tests for new code → BLOCKED. Write tests, then re-run.
351
- #
352
- # To run the FULL suite (slower; not the default for `peaks slice check`),
353
- # drop `--changed` or use `npx vitest run --reporter=verbose`. The peaks-solo-test
354
- # skill is the user-facing wrapper for the full suite; the slice check's
355
- # `--run-tests` flag is the CLI opt-in.
356
- ```
357
-
358
- **Peaks-Cli Gate B3 — Before QA handoff: code review evidence exists:**
359
- ```bash
360
- ls .peaks/<changeId>/rd/code-review.md 2>&1
361
- # Expected: .peaks/<changeId>/rd/code-review.md
362
- # "No such file" → BLOCKED. Run code review (use code-reviewer agent or equivalent),
363
- # record findings, fix CRITICAL/HIGH issues, then re-check.
364
- ```
365
-
366
- **Peaks-Cli Gate B4 — Before QA handoff: security review evidence exists:**
367
- ```bash
368
- ls .peaks/<changeId>/rd/security-review.md 2>&1
369
- # Expected: .peaks/<changeId>/rd/security-review.md
370
- # "No such file" → BLOCKED. Run security review (use security-reviewer agent or equivalent),
371
- # fix CRITICAL/HIGH issues, record findings, then re-check.
372
- ```
373
-
374
- **Peaks-Cli Gate B5 — RD artifact body has no unfilled placeholders:**
375
- ```bash
376
- peaks request lint <rid> --role rd --project <repo> --session-id <session-id> --json
377
- # Expected: ok=true. exit 0.
378
- # ok=false → BLOCKED. The lint output lists every <placeholder>, "- ..." stub,
379
- # and TBD/TODO marker with line numbers. Fill them in before attempting handoff.
380
- ```
381
-
382
- **Peaks-Cli Gate B6 — Declared --type matches the actual diff:**
383
- ```bash
384
- peaks scan request-type-sanity --project <repo> --type <type> --json
385
- # Expected: consistent=true. exit 0.
386
- # consistent=false → BLOCKED. Either the implementation scope-creeped beyond what
387
- # the declared type covers, or the type was mis-classified at PRD time. Re-classify
388
- # (`peaks request init` with the corrected --type) or trim the scope.
389
- ```
390
-
391
- **Peaks-Cli Gate B7 — Repair cycle cap (only relevant during RD↔QA repair loop):**
392
- ```bash
393
- peaks request repair-status <rid> --project <repo> --session-id <session-id> --json
394
- # Expected: atCap=false. exit 0.
395
- # atCap=true → BLOCKED. Three repair cycles already attempted; emit a blocked TXT
396
- # handoff via Solo rather than entering a fourth cycle.
397
- ```
398
-
399
- **Peaks-Cli Gate B8 — Diff stays inside the declared red-line scope:**
400
- ```bash
401
- peaks scan diff-vs-scope --rid <rid> --project <repo> --session-id <session-id> --json
402
- # Expected: ok=true. exit 0.
403
- # violations[] non-empty → BLOCKED. A changed file matches an explicit out-of-scope
404
- # pattern. Revert it, or — only with PRD approval — expand the RD red-line scope.
405
- # unclassified[] non-empty → BLOCKED. A changed file does not match any declared
406
- # in-scope pattern. Either add it to the in-scope list (intentional widening, requires
407
- # PRD approval) or revert the change.
408
- # patternsDeclared=false → BLOCKED. The RD artifact's `## Red-line scope` section has
409
- # no concrete path or glob patterns. Fill it in with paths like `src/services/login/**`
410
- # before re-running. Auto-allowed paths (test files, .peaks/, __mocks__/) never need a pattern.
411
- ```
412
-
413
- **Peaks-Cli Gate B9 — RD-side perf-baseline output present (when slice has a user-perceivable perf surface):**
414
- ```bash
415
- ls .peaks/<changeId>/rd/perf-baseline.md 2>&1
416
- # Expected: .peaks/<changeId>/rd/perf-baseline.md
417
- # "No such file" + slice is feature / refactor / bugfix-when-perf → BLOCKED.
418
- # Run the perf-baseline sub-agent from "Parallel review fan-out" below (or
419
- # `peaks perf baseline --apply` inline), then fill in the Results table
420
- # with measurements (lighthouse / k6 / autocannon / project-local bench —
421
- # the CLI does not run these; that is the RD's job), then re-verify.
422
- # "No such file" + slice is docs / chore / pure-bugfix-no-perf → OK to proceed;
423
- # this gate does not apply to those slice types.
424
- # File exists but Results table is empty (only the header row, no data rows) →
425
- # BLOCKED. The sub-agent scaffolds the file; the main RD loop must fill in
426
- # the Path / route | Workload | Tool | Metric | Baseline | Threshold table
427
- # with actual numbers before handoff.
428
- # File contains the marker `N/A — no perf surface` in its Notes section →
429
- # OK to proceed. This is the explicit opt-out the sub-agent writes when
430
- # the slice has no user-perceivable perf surface (e.g. a feature that only
431
- # adds an internal flag with no runtime cost, or a refactor that does not
432
- # alter any hot path).
433
- #
434
- # The CLI enforcement table below the section header also gates this at the
435
- # `peaks request transition rd:qa-handoff` call, so a missing or empty file
436
- # is rejected by the CLI with `code: PREREQUISITES_MISSING`.
437
- ```
63
+ see `references/rd-transition-gates.md` for the full per-gate contract + `ls` / `grep` shell snippets.
438
64
 
439
65
  ## Project standards preflight
440
66
 
441
- Before RD planning or implementation work in a code repository, call the Peaks-Cli CLI:
67
+ Before RD planning or implementation work in a code repository, call `peaks standards init --project <path> --dry-run` and `peaks standards update --project <path> --dry-run`. If `CLAUDE.md` is missing, treat creation as the preferred path. Apply only when write authorization exists; otherwise keep the CLI output as a preflight next action.
442
68
 
443
- - `peaks standards init --project <path> --dry-run`
444
- - `peaks standards update --project <path> --dry-run`
445
-
446
- If `CLAUDE.md` is missing, treat creation as the preferred path. If `CLAUDE.md` already exists, use `standards update` to decide whether to append a managed index block or surface review-only suggestions. Apply only when write authorization exists; otherwise keep the CLI output as a preflight next action. Do not hand-write standards file mutations inside the skill.
69
+ see `references/rd-standards-preflight.md` for the full preflight contract.
447
70
 
448
71
  ## Library version awareness (3rd-party breaking-change gate)
449
72
 
450
- After `peaks scan libraries` lands the dependency list under `## Library versions` in `rd/project-scan.md`, RD MUST cross-check the slice's diff against `schemas/library-breaking-changes.data.json` before writing any 3rd-party API call. Concretely:
451
-
452
- 1. **Read the project's `## Library versions` section** in `.peaks/_runtime/<sessionId>/rd/project-scan.md`. Identify the `name` + `major` of every dependency the slice imports from.
453
- 2. **Open `schemas/library-breaking-changes.data.json`** (LLM reads via the `Read` tool). For each library where the installed `major` matches a `toMajor` in the table, load the corresponding `breakingChanges[]` list.
454
- 3. **For each `import` statement in the slice's diff** (e.g. `import { Drawer } from 'antd'`), check whether the imported symbol or its prop signature matches any `breakingChanges[].api` entry for the library's installed major.
455
- 4. **On a hit**:
456
- - **Warn the LLM in the slice's handoff**: in `.peaks/_runtime/<sessionId>/rd/requests/<rid>.md` under `## Implementation evidence`, append a one-line note per hit: `- [lib-version] <library> <installed version> imports <api>; breaking-change rule says use <replacement> instead.`
457
- - **Persist a `lesson` memory** at the END of `.peaks/_runtime/<sessionId>/rd/project-scan.md` (or the tech-doc, or the handoff — any of these is read by future RD runs):
458
- ```
459
- <!-- peaks-memory:start -->
460
- title: <library> <installed major> requires <api> → <replacement>
461
- kind: lesson
462
- ---
463
- Observed in slice <rid>: project is on <library>@<major> and the diff imported <api> which is on the breaking-changes list. Use <replacement> instead. Source: schemas/library-breaking-changes.data.json.
464
- <!-- peaks-memory:end -->
465
- ```
466
- - The next RD run will see this lesson in `peaks project memories` and skip the same drift.
467
-
468
- **Why this exists**: the LLM's training data lags the latest major versions. The user hit `[antd: Drawer] width is deprecated. Please use size instead` in an antv6 project because the LLM wrote v5-style code. The breaking-changes table is the canonical place for "library X at major Y has these known migrations" so the LLM doesn't have to guess.
469
-
470
- **Out of scope**: the breaking-changes table is hand-curated; auto-syncing from upstream changelogs (Context7, etc.) is a follow-up slice. Per-slice the LLM only reads the table — it does NOT maintain it.
471
-
472
- **Data freshness check (read schemas/library-breaking-changes.meta.json first)**:
473
- - Before reading `schemas/library-breaking-changes.data.json`, also read `schemas/library-breaking-changes.meta.json`.
474
- - Compute `ageInDays = (today - meta.lastUpdated)`. The LLM is responsible for this date math.
475
- - If `ageInDays > meta.freshnessPolicyDays` (default 180 days), surface a **freshness warning** in the handoff: `- [data-staleness] library-breaking-changes.data.json is ${ageInDays} days old (last touched ${meta.lastUpdated}); the breaking-changes below may miss library X's recent major. Re-verify against the library's official changelog before relying on these substitutions.`
476
- - The warning is **informational**, not blocking. A stale table is better than no table. The LLM still applies the entries it has, just with the caveat.
477
- - When a row in the table matches an `import` in the diff AND the table is fresh, proceed without the warning.
478
-
479
- ## GStack integration and code dry-runs
73
+ After `peaks scan libraries` lands the dependency list under `## Library versions` in `rd/project-scan.md`, RD MUST cross-check the slice's diff against `schemas/library-breaking-changes.data.json` before writing any 3rd-party API call. On a hit, warn in the handoff + persist a `lesson` memory. Check `schemas/library-breaking-changes.meta.json` for freshness before reading the data.
480
74
 
481
- Use gstack as a concrete engineering workflow reference for `Think Plan Build Review → Test → Ship → Reflect`:
75
+ see `references/library-version-awareness.md` for the full 4-step process + data-freshness check.
482
76
 
483
- - map plan engineering review to Peaks-Cli RD risk matrices, task graphs, and slice contracts;
484
- - map build/review discipline to strict spec-first implementation and code-review gates;
485
- - map investigate/careful/guard concepts to root-cause analysis, risky-action confirmation, and scoped edit boundaries;
486
- - adapt gstack concepts into Peaks-Cli artifacts rather than invoking gstack commands as runtime dependencies.
77
+ ## GStack integration and code dry-runs
487
78
 
488
- When Peaks-Cli RD produces or changes code, dry-run repeatedly instead of only during preflight:
79
+ Map gstack stages to Peaks-Cli RD risk matrices, task graphs, and slice contracts. Adapt gstack concepts into Peaks-Cli artifacts rather than invoking gstack commands as runtime dependencies. Dry-run repeatedly: before planning, after each implementation slice, after tests/CR/security, before handoff.
489
80
 
490
- 1. run standards dry-runs before planning or implementation;
491
- 2. run the relevant Peaks-Cli dry-run again after each meaningful implementation slice or standards-affecting decision;
492
- 3. after implementation, run required unit tests, code review, and security review before any completion claim;
493
- 4. only after those checks pass, run the relevant Peaks-Cli dry-run before handoff, review, or retention-boundary work;
494
- 5. record commands, results, coverage evidence, reviewer/security findings, dry-run result, and remaining action in the RD handoff capsule.
81
+ see `references/rd-gstack-integration.md` for the full integration contract.
495
82
 
496
83
  ## Requirement boundary red-line self-check
497
84
 
498
85
  Before every code or mock change, RD must write and then enforce a red-line scope check in the RD artifact:
499
86
 
500
- 1. name the exact product requirement, route, UI surface, API path, data model, and **path/glob patterns** that are in scope. Write them under the RD artifact's `## Red-line scope` section as bullets. Use `In-scope:` / `Out-of-scope:` subheaders when both lists are non-trivial, or wrap paths in backticks for clarity (e.g. `` `src/services/login/**` ``);
501
- 2. name adjacent surfaces that are explicitly out of scope, especially list pages, delete/update flows, unrelated API endpoints, existing data records, authentication, permissions, and shared runtime configuration;
87
+ 1. name the exact product requirement, route, UI surface, API path, data model, and path/glob patterns that are in scope (write under `## Red-line scope` with `In-scope:` / `Out-of-scope:` subheaders);
88
+ 2. name adjacent surfaces explicitly out of scope (list pages, delete/update flows, unrelated API endpoints, existing data records, auth, permissions, shared runtime config);
502
89
  3. reject any implementation that modifies, deletes, mocks, or replaces out-of-scope behavior just to make validation pass;
503
- 4. for API/mock work, mock only the exact request path and method required by the approved slice, and do not override broader collection/list endpoints unless the requirement explicitly includes them;
504
- 5. before handoff, run `peaks scan diff-vs-scope --rid <rid> --project <repo>` to deterministically verify the diff against the declared patterns (this is **Peaks-Cli Gate B8**). The CLI auto-allows test files and `.peaks/` artifacts; any other unclassified or out-of-scope file blocks RD completion until the diff is trimmed OR the scope is widened with PRD approval.
505
-
506
- ## Mandatory tech-doc output
90
+ 4. for API/mock work, mock only the exact request path and method required by the approved slice;
91
+ 5. before handoff, run `peaks scan diff-vs-scope --rid <rid> --project <repo>` (Peaks-Cli Gate B8). The CLI auto-allows test files and `.peaks/` artifacts.
507
92
 
508
- **BLOCKING Do not hand off to QA without this file.** Every RD invocation that touches code MUST produce a tech-doc artifact at `.peaks/_runtime/<sessionId>/rd/tech-doc.md`. If this file is missing at QA handoff, the handoff is invalid. The request artifact links to it; QA and SC read it for verification context.
93
+ ## Mandatory tech-doc output (RD-side)
509
94
 
510
- **Minimum tech-doc sections:**
95
+ **BLOCKING — Do not hand off to QA without this file.** Every RD invocation that touches code MUST produce a tech-doc artifact at `.peaks/_runtime/<sessionId>/rd/tech-doc.md`. If this file is missing at QA handoff, the handoff is invalid.
511
96
 
512
- 1. **Architecture decisions** what changed, why, tradeoffs considered, alternatives rejected
513
- 2. **Component changes** — files added/modified/deleted with role (new component, refactor, bug fix)
514
- - **CRITICAL: Every file path in this section must be verified against the actual project.** Run `ls` on every directory path before writing it. A wrong path is worse than no tech-doc — it sends QA and future developers to non-existent files.
515
- 3. **Data flow** — how data moves through the changed surface (props, API calls, state updates, events)
516
- 4. **CSS/Style changes** — what CSS files or style blocks changed, which component-library tokens were used, any CSS framework interactions
517
- 5. **API contract changes** — new/modified request paths, request/response shapes, error states
518
- 6. **Dependencies** — new packages added, versions, why each was needed, license check
519
-
520
- **CSS framework change rules:**
521
- - When a component library (antd, MUI, etc.) is already in use, prefer its built-in styling APIs (antd's `token`/`className`/`styles` props, MUI's `sx`/`styled`/`theme`) over adding TailwindCSS classes
522
- - Never add `tailwindcss` to a project that already uses a component library with its own CSS-in-JS solution unless the project-scan explicitly approves it
523
- - If TailwindCSS is already present, use it consistently with the project's existing utility patterns; do not mix TailwindCSS utility classes with component-library `style` prop overrides on the same element
97
+ → see `references/mandatory-tech-doc.md` for the minimum sections (architecture / component / data flow / CSS / API / dependencies) + CSS framework change rules.
524
98
 
525
99
  ## Mandatory perf-baseline output (RD-side perf gate)
526
100
 
527
- **BLOCKING — Do not hand off to QA without a perf-baseline file when the slice has a user-visible performance surface.** The QA stage's Gate A4 (performance check) needs a stable reference to diff against; without an RD-side baseline, the first time Gate A4 runs it has nothing to compare against and any regression it finds is a blind-side surprise. The user-facing pain of leaving perf to QA only has historically been a 3-cycle repair loop ("QA returns for perf", "RD ships a fix", "QA returns for perf again", "RD ships another fix", ...). The RD-side baseline closes that loop.
528
-
529
- **When this applies:**
530
- - feature / refactor slices that touch a route, hook, API, or any user-perceivable surface
531
- - bugfix slices where the bug is performance-shaped (slow render, hot loop, N+1)
532
- - any slice where the PRD mentions a number (LCP / FCP / TBT / p95 / rps / etc.)
533
-
534
- **When this does NOT apply:**
535
- - docs / chore slices
536
- - pure bugfixes whose fix is "remove the bug" (no perf surface)
537
- - any slice where the slice is documentation-only or otherwise has no perf surface — in that case write `N/A — no perf surface` in the file's "Notes" section and surface that fact in the RD handoff
538
-
539
- **How to produce the file:**
540
-
541
- ```bash
542
- # 1. dry-run preview (default)
543
- peaks perf baseline --project <repo>
544
- # → ok: true, data.plannedWrites shows the file path, no files written
101
+ **BLOCKING — Do not hand off to QA without a perf-baseline file when the slice has a user-visible performance surface.** The QA stage's Gate A4 (performance check) needs a stable reference to diff against; without an RD-side baseline, the first time Gate A4 runs it has nothing to compare against.
545
102
 
546
- # 2. apply scaffolds the file at .peaks/_runtime/<sessionId>/rd/perf-baseline.md
547
- peaks perf baseline --project <repo> --apply --reason "capturing baseline for Gate A4 diff"
548
- # → ok: true, data.writtenFiles includes the path
549
-
550
- # 3. fill in the file's Results table
551
- # (lighthouse / k6 / autocannon / project-local bench — the
552
- # CLI does not call any of these; that is the RD's job)
553
- # open .peaks/_runtime/<sessionId>/rd/perf-baseline.md and complete the
554
- # "Path / route | Workload | Tool | Metric | Baseline | Threshold"
555
- # table
556
-
557
- # 4. hand off to QA. The QA stage reads the file's Results
558
- # table as the input to Gate A4 — see peaks-qa SKILL.md
559
- # Gate A4.
560
- ```
561
-
562
- **Idempotency:** re-running `peaks perf baseline --apply` on a session where the file already exists is a no-op (the CLI does not overwrite hand-edited content). This is the normal RD retry pattern (re-measurement, threshold adjustment, etc.). If the RD really does want to overwrite, delete the file first and re-run.
563
-
564
- **The role of the CLI vs. the actual measurement:** the CLI is the *scaffolding*. It writes the file, exposes the path, and keeps the file's structure stable so QA can rely on it. The CLI does NOT call lighthouse / k6 / autocannon — those are project-shape dependent and the right tool is a project-local concern, not a peaks-cli concern. The CLI is justified (4-grounds check): it gates the QA-side decision on a stable artefact, it requires --apply for a destructive write, and it is invokable from a hook on session init. It is *not* a machine-enforced gate that prose cannot enforce — the measurement is the RD's responsibility.
103
+ see `references/mandatory-perf-baseline.md` for the full "when this applies" + `peaks perf baseline --apply` workflow.
565
104
 
566
105
  ## Implementation completion gates
567
106
 
568
- RD cannot mark a development slice complete until all of these are true. Each gate below maps to a hard verification gate in the Transition Verification Gates section — run the corresponding command, see the output.
569
-
570
- 0. the project-scan (`.peaks/_runtime/<sessionId>/rd/project-scan.md`) has been read and its component-library, CSS-framework, and build-tool findings have been applied — no implementation may start before this; **→ verified by Peaks-Cli Gate A**
571
- 0.5. NO wrong paths in tech-doc — every directory and file path has been verified with `ls` against the actual project; **→ verified by Peaks-Cli Gate A2**
572
- 0.6. CLAUDE.md and `.claude/rules/common/{coding-style,code-review,security}.md` exist in the project root; **→ verified by Peaks-Cli Gate A3**
573
- 1. OpenSpec change artifacts exist and are linked for non-trivial work when the target repo already has `openspec/`, or the user has approved adding it;
574
- 2. unit tests covering the new or changed behavior have been added or updated and run successfully; **→ verified by Peaks-Cli Gate B2**
575
- 3. if the repository is legacy and total UT coverage is below the project target, do not block on historical coverage, but require coverage evidence for newly added or changed code;
576
- 4. for frontend or UI-affecting slices, RD self-test has launched the app and used the Playwright MCP for real browser end-to-end validation with visible-browser confirmation (the LLM checks its own tool list for any Playwright MCP entry in the LLM tool list; if absent, the user installs via `claude mcp add playwright -- npx @playwright/mcp@latest` — RD does NOT hand-edit `~/.claude/settings.json` or auto-install on the user's behalf); navigate with `browser_navigate`, capture with `browser_snapshot` / `browser_take_screenshot` / `browser_console_messages` / `browser_network_requests`, sanitize route/actions and observations before retention, record acceptance result, close with `browser_close`; if login, CAPTCHA, SSO, or MFA appears, the headed browser is already visible — wait for the user to complete login and explicitly confirm completion before continuing;
577
- 5. code review has been performed with findings recorded and CRITICAL/HIGH issues fixed before progression; unresolved CRITICAL/HIGH findings only allow a blocked handoff; **→ verified by Peaks-Cli Gate B3** — evidence file must exist at `.peaks/<changeId>/rd/code-review.md`
578
- 6. security review has been performed for the changed surface, with CRITICAL/HIGH issues fixed before progression and particular attention to user input, file system access, external calls, auth, secrets, and dependency changes; **→ verified by Peaks-Cli Gate B4** — evidence file must exist at `.peaks/<changeId>/rd/security-review.md`
579
- 6.5. perf-baseline output is in place for any slice with a user-perceivable performance surface — `peaks perf baseline --apply` has been run and `.peaks/_runtime/<sessionId>/rd/perf-baseline.md` exists with the Results table filled in with measurements (or `N/A — no perf surface` in Notes for slices without a perf surface). For docs / chore / pure-bugfix-no-perf, the file is not required. Run the fan-out from "Parallel review fan-out" below; **→ verified by Peaks-Cli Gate B9** — evidence file must exist at `.peaks/<changeId>/rd/perf-baseline.md` and contain a non-empty Results table or the N/A marker.
580
- 7. the post-check dry-run has passed and is linked in the handoff;
581
- 8. the tech-doc artifact (`.peaks/_runtime/<sessionId>/rd/tech-doc.md`) is written and linked from the request artifact. **→ verified by Peaks-Cli Gate B**
582
- 9. the RD request artifact body has no unfilled placeholders, TBD markers, or bare-bullet stubs (`peaks request lint <rid> --role rd`). **→ verified by Peaks-Cli Gate B5**
583
- 10. the declared `--type` is still consistent with the actual git diff (`peaks scan request-type-sanity --type <type>`). **→ verified by Peaks-Cli Gate B6**
584
- 11. the repair-cycle counter is below the cap before a repeat handoff (`peaks request repair-status <rid>`). **→ verified by Peaks-Cli Gate B7**
585
- 12. every changed file matches the RD red-line scope (no out-of-bounds writes); auto-allowed files (tests, .peaks artifacts) don't need an explicit pattern (`peaks scan diff-vs-scope --rid <rid>`). **→ verified by Peaks-Cli Gate B8**
107
+ RD cannot mark a development slice complete until all of these are true. Each gate below maps to a hard verification gate in the Transition Verification Gates section — run the corresponding command, see the output. The gates (0, 0.5, 0.6, 1, 2, 3, 4, 5, 6, 6.5, 7, 8, 9, 10, 11, 12) are listed in `references/rd-runbook.md` §7.
586
108
 
587
109
  If any gate fails, return to development for fixes or hand off as blocked. Do not describe the work as done, shippable, or ready for QA.
588
110
 
589
111
  ## Parallel review fan-out (code-review + security-review + perf-baseline + qa-test-cases)
590
112
 
591
- **When RD reaches the end of implementation, the four review activities (code review, security review, perf baseline, AND QA test-cases draft) run in parallel via `peaks sub-agent dispatch <role>` (then executing the returned toolCall), not sequentially.** This is the same fan-out pattern peaks-solo uses for the post-PRD swarm (see `peaks-solo/SKILL.md` "Peaks-Cli Swarm parallel phase" L659-764). RD itself, when it is the main loop, behaves as a sub-agent orchestrator: it issues 4 `peaks sub-agent dispatch` calls in a single message and waits for all to return before aggregating findings and transitioning to `qa-handoff`.
592
-
593
- **Why 4 sub-agents (added in slice 004):** the original 3-way fan-out (code-review + security-review + perf-baseline) cut the RDQA wall-clock by running 3 LLM writes in parallel, but `qa/test-cases/<rid>.md` was still written sequentially by QA's main loop AFTER the RD handoff landed. Drafting QA test-cases in the same fan-out means the QA main loop's first action is "execute the pre-drafted test plan + write test-report" instead of "draft a test plan from scratch + execute + write report". Wall-clock drop: ~30-40% on the RD→QA-verdict segment for `feature` / `refactor` / `bugfix` slices.
594
-
595
- **When to fan out:**
596
- - Feature / refactor slices: all four sub-agents always run.
597
- - Bugfix slices: code-review + security-review + qa-test-cases always run; perf-baseline runs only when the bug is performance-shaped (matches the "When this applies" criteria in the perf-baseline section above).
598
- - Config / docs / chore slices: no fan-out (no review surface). Document N/A in the request artifact. (qa-test-cases also skipped — config / docs / chore have no acceptance surface to validate.)
599
-
600
- **The dispatch template (mirror of peaks-solo L705-717):**
601
-
602
- ```
603
- peaks sub-agent dispatch <role> \
604
- --prompt "<role contract below>, plus runtime args: project=<repo>, session-id=<session-id>, request-id=<rid>.
605
- Write your evidence file at .peaks/_runtime/<sessionId>/<evidence-path> and return ONLY the path.
606
- Do not call Skill(...). Do not set presence. Do not prompt the user. Do not commit, push,
607
- install hooks, or mutate settings.json. Do not edit any source file — review only.
608
- While running, call peaks sub-agent heartbeat --record <dispatchRecordPath>
609
- --status running --progress <pct> --note \"<text>\" at least every 30 seconds;
610
- on completion call --status done --progress 100 --note 'completed'." \
611
- --request-id <rid> --session-id <session-id> --project <repo> --json
612
- ```
613
-
614
- Note: sub-agents 1-3 write to `rd/<evidence-path>`, sub-agent 4 writes to `qa/test-cases/<rid>.md` (QA's dir). The role name in the description differentiates them.
615
-
616
- **Sub-agent 1 — code-reviewer (always runs for feature / refactor / bugfix):**
617
- - Read the git diff for this slice (`git diff main...HEAD` or equivalent).
618
- - Read `.peaks/_runtime/<sessionId>/rd/tech-doc.md` for slice intent.
619
- - Inspect for: correctness, type safety, error handling, mutation patterns, file-size, naming, dead code, regressions, contract drift.
620
- - Output: `.peaks/_runtime/<sessionId>/rd/code-review.md` with sections: Summary, Findings (CRITICAL/HIGH/MEDIUM/LOW with file:line), Required Fixes (CRITICAL+HIGH only), Recommended (MEDIUM+LOW), Verdict (pass | return-to-rd | blocked).
621
- - Required for Gate B3.
622
-
623
- **Sub-agent 2 — security-reviewer (always runs for feature / refactor / bugfix):**
624
- - Read the git diff and the file list.
625
- - Read `.peaks/_runtime/<sessionId>/rd/tech-doc.md` for the slice's threat model.
626
- - Inspect for: hardcoded secrets, unsanitized input, path traversal, SQL injection, XSS, missing auth, dependency changes, external API surface, command injection via Bash guards.
627
- - Output: `.peaks/_runtime/<sessionId>/rd/security-review.md` with the same shape (Summary, Findings, Required Fixes, Recommended, Verdict).
628
- - Required for Gate B4.
629
-
630
- **Sub-agent 3 — perf-baseline-reviewer (feature / refactor / bugfix-when-perf only):**
631
- - Read the git diff and the slice's PRD/tech-doc for any mentioned numbers (LCP / FCP / TBT / p95 / rps).
632
- - Run `peaks perf baseline --project <repo> --apply --reason "parallel fan-out for rid=<rid>"` to scaffold `.peaks/_runtime/<sessionId>/rd/perf-baseline.md` (idempotent: re-run is a no-op per `src/services/perf/perf-baseline-service.ts:188-201`).
633
- - Inspect the slice for a user-perceivable performance surface (route, hook, API, render, hot loop, N+1).
634
- - Decide: perf surface exists → leave the scaffold in place for the main RD loop to fill in the Results table with actual measurements (lighthouse / k6 / autocannon / project-local bench — the CLI does NOT run these). No perf surface → write `N/A — no perf surface` in the file's Notes section and return.
635
- - Output: `.peaks/_runtime/<sessionId>/rd/perf-baseline.md` (scaffolded, or N/A stub), plus a one-line return string: `perf-baseline: scaffolded — main loop must fill Results table` OR `perf-baseline: N/A — no perf surface`.
636
- - Required for Gate B9. The Results-table-filling happens in the main RD loop AFTER the fan-out returns and BEFORE `rd:qa-handoff` transition.
637
-
638
- **Sub-agent 4 — qa-test-cases-writer (always runs for feature / refactor / bugfix; added in slice 004):**
639
- - Read the git diff for this slice.
640
- - Read `.peaks/_runtime/<sessionId>/rd/tech-doc.md` (or `bug-analysis.md` for bugfix) for the slice's acceptance criteria.
641
- - Read `.peaks/_runtime/<sessionId>/prd/requests/<rid>.md` for the user's "Acceptance criteria" section.
642
- - Draft the test plan: enumerate every acceptance criterion from the PRD as a separate test case; for each, write a `ts` test snippet (using vitest, jest, or the project's test framework per the existing test files), assert the expected outcome, and link the test to the PRD criterion by ID or section reference.
643
- - Include the standard test plan sections: ## Test cases (with `ts` code blocks), ## Test case summary (table), ## Mandatory validation gates (units / API / browser / security / performance), ## Regression matrix, ## Verdict.
644
- - The test cases do NOT need to be executed by this sub-agent — execution is the QA main loop's job, AFTER the RD handoff lands. The sub-agent's contract is: "produce a runnable, exhaustive, type-correct test plan that QA can execute verbatim."
645
- - Output: `.peaks/_runtime/<sessionId>/qa/test-cases/<rid>.md`.
646
- - Required for Gate C (RD-side qa-handoff transition, added in slice 004). When this file is present at RD's qa-handoff transition, QA's main loop can skip its own "draft test plan" step and proceed directly to "execute pre-drafted test plan + write test-report + security-findings + performance-findings + verdict".
647
- - Failure mode: if the PRD is missing or the acceptance criteria are too vague to enumerate, this sub-agent returns `blocked` with a `blockedReason` like `prd-missing` or `acceptance-criteria-vague`; the main RD loop then escalates via AskUserQuestion before falling back to inline QA test-case drafting.
648
-
649
- **Hard prohibitions on all 4 sub-agents (mirror of peaks-solo L729-734):**
650
- - Do NOT call `Skill(skill="...")` — would re-enter RD or another skill and break the fan-out.
651
- - Do NOT call `peaks skill presence:set` — only the main RD loop owns presence.
652
- - Do NOT open interactive user prompts. If something is unclear, return `blocked` and let the main loop handle the user.
653
- - Do NOT commit, push, install hooks, or mutate `~/.claude/settings.json` or `.claude/settings.json`. Only the main RD loop holds those permissions.
654
- - Do NOT edit any source file under `src/`, `tests/`, `skills/`, `bin/`, `scripts/`, `docs/`, `schemas/`. Review only. (Sub-agent 4, qa-test-cases-writer, may write test code in the test plan body, but does NOT write to `tests/` files on disk — that is the QA main loop's job, after the verdict is issued.)
655
-
656
- **Aggregation (after all 4 sub-agents return):**
657
-
658
- 1. Restore presence: `peaks skill presence:set peaks-rd --project <repo> --gate review-fan-out-converged`
659
- 2. Run the 4 `ls` checks (Gate B3 code-review, Gate B4 security-review, Gate B9 perf-baseline, Gate C2 qa-test-cases — the last one is a new check added in slice 004).
660
- 3. Read each evidence file. Aggregate CRITICAL/HIGH across code-review + security-review.
661
- 4. If any CRITICAL or HIGH finding exists in code-review.md or security-review.md: fix in the main RD loop, then re-launch ONLY the affected sub-agent(s) to verify the fix. Loop until clean, or mark as blocked if the issue cannot be resolved.
662
- 5. For perf-baseline: if scaffolded, run the project's perf measurement tool, fill in the Results table (Path / route | Workload | Tool | Metric | Baseline | Threshold), and `git diff` the file to confirm the table has data (not just the header row). If N/A, no measurement needed.
663
- 6. For qa-test-cases: the file is now pre-drafted by sub-agent 4. The main RD loop does NOT re-draft it; it only verifies (a) the file exists, (b) every PRD acceptance criterion is enumerated, (c) every `ts` test snippet is syntactically valid (the sub-agent's contract guarantees the last two; the main loop's job is just the `ls` check). If the sub-agent's draft is incomplete, fix it inline in the main RD loop (small edits only) OR re-launch the sub-agent (large re-drafts).
664
- 7. Re-run all 4 `ls` checks to confirm the evidence files are present and not empty.
665
- 8. Only then transition `peaks request transition <rid> --role rd --state qa-handoff --project <repo> --json`.
666
-
667
- **Degradation when a sub-agent fails or returns blocked:**
668
- - code-review sub-agent fails: fall back to inline RD code review (the L486-506 Gate B3 is still required; only the fan-out is degraded). TXT handoff note: `code-review-subagent-degraded-to-inline`.
669
- - security-review sub-agent fails: same fallback. TXT note: `security-review-subagent-degraded-to-inline`.
670
- - perf-baseline sub-agent fails: same fallback. TXT note: `perf-baseline-subagent-degraded-to-inline`.
671
- - qa-test-cases sub-agent fails: fall back to inline QA test-case drafting at the start of QA's main loop (i.e. QA drafts the test cases itself, instead of receiving the pre-drafted file). TXT note: `qa-test-cases-subagent-degraded-to-inline-qa-draft`. The wall-clock win is reduced but not eliminated — QA's drafting is still faster than writing from scratch because the test plan can be drafted from the PRD + tech-doc directly.
672
- - 2 or more fail: do not hand off as clean; transition to `qa-handoff` with `--allow-incomplete --reason "<degradation>"` OR block.
673
-
674
- **Why this works (3-loop repair closure):** the original 3-loop repair pain (`qa return for perf → rd fix → qa return for perf again → ...`) was caused by perf being QA-only. This fan-out moves perf measurement to the RD side AND runs it in parallel with the other reviews, so the RD handoff is complete on the first attempt instead of after several cycles. **Slice 004 extends the same pattern to QA test-cases** so the QA→verdict loop is also faster on the first attempt.
113
+ **When RD reaches the end of implementation, the four review activities run in parallel via `peaks sub-agent dispatch <role>`, not sequentially.** This is the same fan-out pattern peaks-solo uses for the post-PRD swarm. Feature / refactor: all four. Bugfix: code-review + security-review + qa-test-cases always; perf-baseline only when perf-shaped. Config / docs / chore: no fan-out.
114
+
115
+ see `references/parallel-review-fanout.md` for the dispatch template + the 4 sub-agents' contracts + aggregation + degradation.
675
116
 
676
117
  ## Refactor hard gates
677
118
 
678
- If a request is refactor, cleanup, architecture adjustment, module split, or technical debt work:
119
+ If a request is refactor, cleanup, architecture adjustment, module split, or technical debt work: scan project structure and existing standards; locate or run UT coverage; block implementation unless coverage is >= 95%; treat missing, unknown, or unverifiable coverage as failing; generate intermediate artifacts before implementation; call or consume peaks-prd and peaks-qa artifacts even in direct RD mode; require strict slice spec before each slice; require 100% acceptance for the slice; require code changes and intermediate artifacts to be traceable in local `.peaks/_runtime/<sessionId>/` storage before continuing.
679
120
 
680
- 1. scan project structure and existing standards;
681
- 2. locate or run UT coverage;
682
- 3. block implementation unless coverage is >= 95%;
683
- 4. treat missing, unknown, or unverifiable coverage as failing;
684
- 5. generate intermediate artifacts before implementation;
685
- 6. call or consume peaks-prd and peaks-qa artifacts even in direct RD mode;
686
- 7. require strict slice spec before each slice;
687
- 8. require 100% acceptance for the slice;
688
- 9. require code changes and intermediate artifacts to be traceable in local `.peaks/_runtime/<sessionId>/` storage before continuing; commit or sync artifacts only when explicitly authorized.
121
+ → see `references/refactor-workflow.md` for the full workflow + required artifacts list.
689
122
 
690
123
  ## Unit-test coverage red line
691
124
 
692
- The 100% coverage target on testable files is meaningful coverage, not a score to chase. RD must not write coverage-padding tests.
693
-
694
- Rules:
695
-
696
- 1. If a missing line or branch is a **defensive guard for an unreachable case** (caller invariant, type system, upstream contract), remove the guard rather than write a test that fabricates the impossible. Simpler code beats higher line count.
697
- 2. If a missing line or branch is **IO / platform glue that cannot be tested cleanly** (real process spawn, homedir-default paths, registry side effects), add the file to `coverage.exclude` in `vitest.config.ts` with a one-line comment explaining why. This is the established Peaks-Cli pattern (`mcp-stdio-transport.ts`, `*-types.ts`, `doctor-service.ts`, `artifact-service.ts`, `workspace-service.ts`).
698
- 3. If a missing line or branch is **real behavior a caller relies on**, write the test — but frame the assertion around the user-visible behavior ("uses the wall clock when no clock is injected and writes a real timestamp into the artifact body"), not the implementation branch ("covers the `?? defaultClock` fallback"). A test that would only fail if someone deleted a single branch is a smell.
699
- 4. When the only way to reach 100% is to write a test that documents nothing a future maintainer would care about, the right answer is to **lower the target for that file via `coverage.exclude`** or to **simplify the production code to remove the dead branch**, never to write the padding test.
700
- 5. Test names must describe behavior, not coverage targets. Tests titled like "covers line 73" or "exercises the default factory branch" are red flags during code review and must be rewritten or deleted.
701
-
702
- RD slice handoff must record the coverage verdict in the RD request artifact with one of:
703
-
704
- - `pass: <percent>%, no exclusions added in this slice` — clean 100%
705
- - `pass: <percent>%, added <file> to coverage.exclude — reason: <one-line>` — exclusion was the right call
706
- - `blocked: <percent>% with no meaningful path to 100%` — escalate; do not write padding to clear the gate
125
+ The 100% coverage target on testable files is meaningful coverage, not a score to chase. RD must not write coverage-padding tests. Rules: defensive guards for unreachable cases → remove the guard; IO/platform glue that cannot be tested cleanly → add to `coverage.exclude`; real behavior a caller relies on → write a behavior-framed test; if the only way to 100% is a padding test, lower the target or simplify the production code. Test names must describe behavior, not coverage targets. RD slice handoff must record the coverage verdict in the RD request artifact.
707
126
 
708
127
  ## OpenSpec usage
709
128
 
@@ -715,143 +134,77 @@ OpenSpec artifacts are durable project specification files, not Peaks-Cli runtim
715
134
 
716
135
  Peaks-Cli PRD/RD/QA gates remain authoritative: OpenSpec structures the durable spec, while Peaks-Cli artifacts still carry role handoffs, coverage gates, QA evidence, swarm coordination, and execution state.
717
136
 
137
+ → see `references/openspec-cli.md` for the CLI recipes.
138
+
718
139
  ## Mock data placement rules (BLOCKING — framework-aware)
719
140
 
720
141
  When the project-scan in `.peaks/<changeId>/rd/project-scan.md` identifies a frontend framework, mock data MUST follow the framework's built-in mock mechanism. **Never write mock data inline in component files.**
721
142
 
722
- ### Framework-to-mock-directory mapping
723
-
724
- | Project-scan finding | Mock location | Notes |
725
- |---|---|---|
726
- | Umi (`@umijs/max`, `.umirc.ts`) | `mock/*.ts` | Umi's built-in mock directory. Zero config, auto-reload. Write `export default { 'GET /api/...': (req, res) => { ... } }` |
727
- | Next.js (`next.config.*`) | `__mocks__/` or MSW handlers | Match the project's existing pattern |
728
- | Vite (`vite.config.*`) | `src/mock/` | Service-layer mock files with typed fixtures |
729
- | CRA / Webpack | `src/__mocks__/` | Match the project's existing pattern |
730
-
731
- ### Hard rules
732
-
733
- 1. **Umi project → `mock/*.ts`**: If the project-scan says the build tool is Umi, mock data MUST go in the `mock/` directory at project root. This is Umi's built-in feature — it intercepts requests matching the defined path and method. Do NOT write `Promise.resolve(mockData)` in component files or service files for Umi projects.
734
-
735
- 2. **Never inline mock data in component files**: Mock data, fixture objects, and stub responses belong in dedicated mock files. Components should receive data through their normal channels (props, API calls via services). Writing `const mockData = [...]` inside a `.tsx` file is prohibited.
736
-
737
- 3. **Mock files must export TypeScript interfaces**: Every mock response type must be exported so RD implementation and QA test-cases can import the same contract. See peaks-solo's "Frontend-only development mode" for the full mock-to-real migration pattern.
738
-
739
- 4. **Every mock file must be marked**: Add `// MOCK: Replace with real API call when swagger.json is available` at the top of every mock file.
740
-
741
- 5. **Mock data must be realistic**: No `"test"`, `"foo"`, `"123"` values. Use plausible content that resembles production data.
742
-
743
- ### Verification gate (after mock creation)
744
-
745
- ```bash
746
- # If project-scan detected Umi, verify mock/ directory was used
747
- ls mock/*.ts 2>&1
748
- # Expected: one or more .ts files in mock/
749
- # "No such file" → BLOCKED. Umi projects must use mock/ directory.
750
-
751
- # Verify no inline mock data in component files
752
- grep -r "const mock\|mockData\|mock_data\|MOCK_DATA" src/ --include="*.tsx" --include="*.ts" -l 2>&1
753
- # Expected: no matches (or only in dedicated mock files / test files)
754
- # Any match in a component → BLOCKED. Move to mock/ (Umi) or src/mock/ (Vite).
755
- ```
143
+ see `references/mock-data-placement.md` for the full framework-to-mock-directory mapping + hard rules + verification gate.
756
144
 
757
145
  ## Frontend project generation
758
146
 
759
- When RD work creates a frontend application and the user has not specified a technology stack, and the current scan plus existing project standards still do not establish a frontend stack, default to React + Vite + shadcn/ui with:
760
-
761
- - `peaks shadcn init --preset [CODE] --template vite`
147
+ When RD work creates a frontend application and the user has not specified a technology stack, default to React + Vite + shadcn/ui with `peaks shadcn init --preset [CODE] --template vite`. Application projects generated through this skill must not contain JavaScript source or config files. Generate TypeScript only.
762
148
 
763
- `[CODE]` is the preset code supplied by the shadcn registry or user workflow; if it is unknown, stop and resolve the intended preset before scaffolding.
764
-
765
- If the user specifies a frontend stack or scaffold command, use the specified technology. If the scaffold emits JavaScript, convert generated application files to TypeScript before continuing; if conversion is not practical, ask for a TypeScript-compatible scaffold.
766
-
767
- Application projects generated through this skill must not contain JavaScript source or config files. Generate TypeScript only (`.ts`, `.tsx`, and TypeScript config equivalents), including when adapting examples from libraries or templates.
149
+ → see `references/frontend-project-generation.md` for the full scaffold protocol.
768
150
 
769
151
  ## Artifact and standards output
770
152
 
771
- When project identification or scanning produces reports, matrices, maps, plans, or validation files, write them under the configured Peaks-Cli artifact workspace. By default, use local non-git storage at `.peaks/_runtime/<sessionId>/rd/` in the target project or the Peaks-Cli CLI-provided local workspace. If the artifact workspace is unknown, create or request `.peaks/_runtime/<sessionId>/` before writing generated outputs. Use one session directory consistently so generated outputs stay grouped.
772
-
773
- Do not default to a git-backed artifact repository, external artifact sync, or automatic commits for intermediate artifacts. Git inclusion or sync requires explicit user confirmation or an active profile that clearly authorizes it. Browser evidence must be sanitized before retention: do not store login URLs, cookies, headers, tokens, storage state, browser traces, or screenshots/logs containing PII or SSO/MFA material.
153
+ When project identification or scanning produces reports, matrices, maps, plans, or validation files, write them under the configured Peaks-Cli artifact workspace (default: `.peaks/_runtime/<sessionId>/rd/`). Do not default to a git-backed artifact repository or external artifact sync. Route standards mutations through `peaks standards init/update`; do not hand-write. Do not update user-global `~/.claude/rules/**` from this workflow.
774
154
 
775
- When project-local `CLAUDE.md` or project-local `.claude/rules/**` is created or updated, route the mutation through `peaks standards init` or `peaks standards update`; do not hand-write standards mutations. Derive the content from the current scan results and existing project standards. Keep only the rules that match the project's languages, frameworks, tooling, and repository layout. Do not emit generic templates, copy-pasted boilerplate, or rules unrelated to the current scan evidence. Do not update user-global `~/.claude/rules/**` from this workflow.
776
-
777
- If the scan results are insufficient to justify a rule, leave it out or surface a review-only suggestion instead of writing it into project standards.
155
+ see `references/artifact-and-standards-output.md` for the full contract.
778
156
 
779
157
  ## Compact handoff
780
158
 
781
159
  Before RD work stops, finishes, blocks, or hands off to another role, emit a short resumable capsule: mode, scope, coverage status, validated decisions, current slice, artifact paths, blockers, and next action. Link to scan reports, matrices, plans, and task graphs instead of restating them.
782
160
 
783
- ## External references
161
+ see `references/compact-handoff.md`.
784
162
 
785
- **Matt Pocock skills** (`diagnose`, `triage`, `tdd`, `improve-codebase-architecture`, `prototype`): Engineering references only. Inspect before applying; Peaks-Cli RD gates remain authoritative.
786
-
787
- ## Matt Pocock skills integration
788
-
789
- Engineering methods from `mattpocock/skills` can inform RD work but never replace Peaks-Cli gates. Inspect upstream skill content before applying any method.
790
-
791
- - `diagnose` — root-cause investigation before fixing
792
- - `triage` — prioritize bug surface area
793
- - `tdd` — drive implementation from failing tests
794
- - `improve-codebase-architecture` — opportunistic refactor framing
795
- - `prototype` — throwaway exploration before committing to a slice
796
-
797
- These are references only; Peaks-Cli RD gates remain authoritative for handoff, acceptance, and slice closure.
798
-
799
- **Understand Anything**: Consume via `peaks understand status/show --json`. Fall back to `peaks codegraph context` or local project scan when absent.
800
-
801
- **Codegraph**: Optional local analysis via `peaks codegraph context/affected`. Output as untrusted supporting evidence; never commit `.codegraph/` artifacts.
802
-
803
- ## Codegraph project analysis
804
-
805
- RD may use `peaks codegraph affected --project <path> <changed-files...> --json` as local project-analysis evidence to inform red-line scope boundaries before writing tech-doc or starting implementation. Treat the output as untrusted supporting evidence — verify against the actual code before relying on it.
806
-
807
- Do not run upstream installer flows, mutate agent settings, or commit `.codegraph/` artifacts. Peaks-Cli RD gates remain authoritative for handoff and acceptance.
163
+ ## External references
808
164
 
809
- **Other external resources** (Context7, SearchCode, everything-claude-code, GitNexus, etc.): Use `peaks capabilities --source access-repo/mcp-server --json` for capability discovery before recommending. References only do not execute upstream installers, do not install upstream resources, do not persist sensitive examples. Peaks-Cli RD gates remain authoritative.
165
+ Matt Pocock skills (diagnose / triage / tdd / improve-codebase-architecture / prototype): engineering references only. Inspect before applying; Peaks-Cli RD gates remain authoritative. Understand Anything: `peaks understand status/show --json`. Codegraph: local analysis only, never commit `.codegraph/` artifacts. Other external resources: `peaks capabilities --source access-repo/mcp-server --json` for capability discovery.
810
166
 
811
- **OpenSpec CLI**: Route through Peaks-Cli CLI (`peaks openspec show/to-rd/render`). Do not hand-edit `openspec/changes/**`. Recipes: `references/openspec-cli.md`. (MCP CLI was retired in slice #016; the LLM's own tool list is the source of truth for which MCPs are installed.)
167
+ see `references/external-references.md` + `references/matt-pocock-integration.md` + `references/codegraph-project-analysis.md`.
812
168
 
813
169
  ## Boundaries
814
170
 
815
171
  Do not bypass PRD/QA artifacts. Do not install hooks, agents, MCP, or settings. Ask the Peaks-Cli CLI to handle runtime side effects.
816
172
 
817
- Do not bypass the parallel review fan-out when the slice has a code-review / security-review / perf-baseline surface — see `## Parallel review fan-out` above for the contract. The three review activities are fan-out, not sequential; sequential re-implementation of the same logic by the main RD loop defeats the wall-clock benefit and is treated as a red-line violation.
818
-
819
- Reference: `references/refactor-workflow.md`.
173
+ Do not bypass the parallel review fan-out when the slice has a code-review / security-review / perf-baseline surface — see `## Parallel review fan-out` above. The three review activities are fan-out, not sequential; sequential re-implementation of the same logic by the main RD loop defeats the wall-clock benefit and is treated as a red-line violation.
820
174
 
821
175
  ## Sub-agent context governance (G7 + G7.7 + G8 + G9 — slice #010)
822
176
 
823
- > Slice #010 implements the G7 + G7.7 + G8 + G9 red lines from slice #009 closeout. RD sub-agent prompt template MUST include the G7 path convention + G8.6 share protocol. Detailed protocol: `skills/peaks-solo/references/context-governance.md` + `skills/peaks-solo/references/headroom-integration.md`.
824
-
825
- ### G7 RD sub-agent protocol
826
-
827
- 1. Write artifact to `.peaks/_sub_agents/<sessionId>/artifacts/<rid>-rd-001.md` (path convention mandatory).
828
- 2. Call `peaks sub-agent dispatch --write-artifact <path>` (or via the dispatch CLI flag) to register ArtifactMeta.
829
- 3. The dispatch record stores only `path + size + sha256 + status + contentInlined:false + summary` — main LLM sees ~200 chars/sub-agent.
830
-
831
- ### G8.6 RD sub-agent prompt template (mandatory)
832
-
833
- Sub-agent prompts dispatched by peaks-rd must include:
834
-
835
- ```
836
- You are sub-agent role rd, batch <batchId>.
837
-
838
- PROTOCOL (mandatory):
839
- 1. On start: peek at shared channel: `peaks sub-agent shared-read --batch <batchId> --json`
840
- to see what other sub-agents in this batch have shared so far.
841
- 2. While running: if you find a blocker or partial work, write share entry
842
- `peaks sub-agent share --key "rd.found-blocker" --value {"reason": "..."}`.
843
- 3. On completion: write share entry
844
- `peaks sub-agent share --key "rd.completed" --value <artifact-meta>` BEFORE the
845
- final `peaks sub-agent heartbeat --status done` heartbeat (RL-23 strong constraint).
846
- 4. The shared channel is your only visibility into sibling sub-agents.
847
- Do NOT attempt to read other sub-agents' dispatch records directly.
848
- ```
849
-
850
- ### G9 RD prompt size self-check
851
-
852
- Before dispatching a sub-agent, RD self-checks prompt size:
853
- - < 50%: pass through.
854
- - 50-75%: soft warn (consider `--use-headroom`).
855
- - 75-80%: soft warn + `warnings: ["CONTEXT_NEAR_LIMIT"]` (mandatory suggest `--use-headroom`).
856
- - 80%+: reject (CLI 兜底 returns `code: "PROMPT_TOO_LARGE"`). Use `--force` at CLI only when overriding; hook layer will still reject (RL-30).
857
-
177
+ RD sub-agent prompt template MUST include the G7 path convention + G8.6 share protocol. Detailed protocol: `skills/peaks-solo/references/context-governance.md` + `skills/peaks-solo/references/headroom-integration.md`.
178
+
179
+ see `references/rd-context-governance.md` for the full G7 / G8.6 / G9 protocol + RD sub-agent prompt template.
180
+
181
+ ## References
182
+
183
+ Index of every `references/` file in this skill. Read on demand.
184
+
185
+ | File | Coverage |
186
+ |---|---|
187
+ | `references/artifact-and-standards-output.md` | Artifact + standards output contract. |
188
+ | `references/artifact-contracts.md` | Sub-agent handoff artifact contracts. |
189
+ | `references/artifact-per-request.md` | RD per-request artifact + per-slice vs per-session scope. |
190
+ | `references/browser-self-test-contracts.md` | Browser self-test contracts (1) + (2). |
191
+ | `references/codegraph-project-analysis.md` | Codegraph local analysis (untrusted evidence). |
192
+ | `references/command-migration.md` | Legacy command migration map. |
193
+ | `references/compact-handoff.md` | RD compact handoff capsule. |
194
+ | `references/external-references.md` | External 3rd-party inventory. |
195
+ | `references/frontend-project-generation.md` | React + Vite + shadcn/ui default. |
196
+ | `references/library-version-awareness.md` | Breaking-change gate + freshness check. |
197
+ | `references/mandatory-perf-baseline.md` | RD-side perf baseline + `peaks perf baseline` workflow. |
198
+ | `references/mandatory-tech-doc.md` | RD tech-doc minimum sections + CSS rules. |
199
+ | `references/matt-pocock-integration.md` | Matt Pocock skills as references. |
200
+ | `references/mock-data-placement.md` | Framework-to-mock-directory mapping + rules. |
201
+ | `references/openspec-cli.md` | OpenSpec CLI recipes. |
202
+ | `references/parallel-review-fanout.md` | 4-way parallel review fan-out. |
203
+ | `references/rd-context-governance.md` | G7 + G8.6 + G9 RD sub-agent protocol. |
204
+ | `references/rd-gstack-integration.md` | GStack Peaks mapping + dry-run cadence. |
205
+ | `references/rd-runbook.md` | Default 9-step runbook (steps #0–#8). |
206
+ | `references/rd-standards-preflight.md` | Standards preflight dry-run contract. |
207
+ | `references/rd-sub-agent-dispatch.md` | Sub-agent suspended sections + contract. |
208
+ | `references/rd-transition-gates.md` | Per-gate A-A3-B-B9 contract. |
209
+ | `references/refactor-workflow.md` | Refactor hard gates + required artifacts. |
210
+ | `references/skill-presence-and-title.md` | RD skill presence (main loop only). |