peaks-loop 4.1.5 → 4.1.7

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 (104) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +67 -0
  3. package/README-en.md +47 -183
  4. package/README.md +24 -188
  5. package/dist/cli/commands/best-practice-scan-command.d.ts +11 -6
  6. package/dist/cli/commands/best-practice-scan-command.js +35 -20
  7. package/dist/cli/commands/best-practice-scan-helpers.d.ts +47 -0
  8. package/dist/cli/commands/best-practice-scan-helpers.js +88 -5
  9. package/dist/cli/commands/best-practice-scan-lookup-results.d.ts +13 -0
  10. package/dist/cli/commands/best-practice-scan-lookup-results.js +237 -0
  11. package/dist/cli/commands/core/skill-registry-commands.js +9 -4
  12. package/dist/cli/commands/dispatch-command-spec.js +1 -1
  13. package/dist/cli/commands/dispatch-isolation-lease.d.ts +1 -1
  14. package/dist/cli/commands/dispatch-isolation-lease.js +6 -53
  15. package/dist/cli/commands/dispatch-prompt-blocks.d.ts +1 -1
  16. package/dist/cli/commands/dispatch-prompt-composition.d.ts +1 -1
  17. package/dist/cli/commands/dispatch-record-write.d.ts +1 -1
  18. package/dist/cli/commands/dispatch-tool-call.d.ts +1 -1
  19. package/dist/cli/commands/openspec-command-shared.js +2 -2
  20. package/dist/cli/commands/request-transition-failures.js +31 -4
  21. package/dist/cli/commands/request-transition-preflight.js +1 -1
  22. package/dist/cli/commands/slice-decompose-artifacts.js +2 -1
  23. package/dist/cli/commands/verdict-aggregate-command.js +2 -1
  24. package/dist/cli/commands/workflow-gate-commands.js +4 -4
  25. package/dist/cli/program.js +0 -2
  26. package/dist/services/artifacts/artifact-contract-block.js +21 -2
  27. package/dist/services/artifacts/artifact-prerequisites.d.ts +1 -0
  28. package/dist/services/artifacts/artifact-prerequisites.js +11 -99
  29. package/dist/services/artifacts/backcompat-acceptance.d.ts +66 -0
  30. package/dist/services/artifacts/backcompat-acceptance.js +220 -0
  31. package/dist/services/artifacts/prerequisite-checks.d.ts +8 -0
  32. package/dist/services/artifacts/prerequisite-checks.js +7 -2
  33. package/dist/services/artifacts/prerequisite-path-resolver.d.ts +39 -0
  34. package/dist/services/artifacts/prerequisite-path-resolver.js +110 -0
  35. package/dist/services/artifacts/rd-transition-gates.d.ts +33 -0
  36. package/dist/services/artifacts/rd-transition-gates.js +71 -0
  37. package/dist/services/artifacts/request-artifact-service.js +22 -20
  38. package/dist/services/artifacts/request-artifact-state-helpers.d.ts +9 -1
  39. package/dist/services/artifacts/request-artifact-state-helpers.js +6 -4
  40. package/dist/services/audit-independent/judged-declaration-check.d.ts +1 -0
  41. package/dist/services/audit-independent/judged-declaration-check.js +62 -1
  42. package/dist/services/context/build-dispatch-system-prompt.d.ts +5 -9
  43. package/dist/services/context/build-dispatch-system-prompt.js +11 -11
  44. package/dist/services/context/post-compact-reinjection.js +1 -1
  45. package/dist/services/dispatch/test-tool-detection.d.ts +17 -1
  46. package/dist/services/dispatch/test-tool-detection.js +12 -1
  47. package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.d.ts +15 -0
  48. package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.js +53 -0
  49. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.d.ts +38 -0
  50. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.js +243 -0
  51. package/dist/services/doctor/doctor-service/plugin-registry.js +4 -0
  52. package/dist/services/doctor/doctor-service/types.d.ts +12 -0
  53. package/dist/services/evidence/evidence-generator.js +8 -4
  54. package/dist/services/openspec/coverage-evidence-reader.d.ts +9 -9
  55. package/dist/services/openspec/coverage-evidence-reader.js +8 -8
  56. package/dist/services/openspec/openspec-archive-service.d.ts +1 -1
  57. package/dist/services/openspec/openspec-archive-service.js +6 -6
  58. package/dist/services/scan/file-size-baseline.d.ts +13 -6
  59. package/dist/services/scan/file-size-baseline.js +54 -31
  60. package/dist/services/scan/file-size-scan.d.ts +7 -14
  61. package/dist/services/scan/file-size-scan.js +6 -1
  62. package/dist/services/scan/type-corroboration.d.ts +32 -0
  63. package/dist/services/scan/type-corroboration.js +51 -0
  64. package/dist/services/scan/type-sanity-service.d.ts +14 -0
  65. package/dist/services/scan/type-sanity-service.js +10 -19
  66. package/dist/services/security/safe-settings-path.d.ts +5 -0
  67. package/dist/services/security/safe-settings-path.js +64 -8
  68. package/dist/services/skill/resume-detector.js +8 -8
  69. package/dist/services/workflow/pipeline-verify-gate-support.d.ts +28 -9
  70. package/dist/services/workflow/pipeline-verify-gate-support.js +40 -117
  71. package/dist/services/workflow/pipeline-verify-qa-phase.d.ts +102 -0
  72. package/dist/services/workflow/pipeline-verify-qa-phase.js +176 -0
  73. package/dist/services/workflow/pipeline-verify-rd-phase.d.ts +67 -0
  74. package/dist/services/workflow/pipeline-verify-rd-phase.js +122 -0
  75. package/dist/services/workflow/pipeline-verify-service.js +42 -44
  76. package/dist/services/workflow/request-type-resolution.d.ts +99 -0
  77. package/dist/services/workflow/request-type-resolution.js +130 -0
  78. package/dist/services/workflow/workflow-skip-service.d.ts +1 -0
  79. package/dist/services/workflow/workflow-skip-service.js +19 -21
  80. package/dist/services/workflow/workflow-state-store.d.ts +9 -0
  81. package/dist/services/workflow/workflow-state-store.js +26 -1
  82. package/dist/services/workspace/workspace-service.js +4 -16
  83. package/dist/shared/incrementing-number.d.ts +23 -2
  84. package/dist/shared/incrementing-number.js +57 -15
  85. package/package.json +5 -7
  86. package/schemas/doctor-report.schema.json +2 -2
  87. package/skills/bee/peaks-prd/SKILL.md +3 -2
  88. package/skills/peaks-code/SKILL.md +32 -15
  89. package/dist/cli/commands/vm-command-shared.d.ts +0 -23
  90. package/dist/cli/commands/vm-command-shared.js +0 -23
  91. package/dist/cli/commands/vm-commands.d.ts +0 -3
  92. package/dist/cli/commands/vm-commands.js +0 -45
  93. package/dist/cli/commands/vm-hypervisor-probe.d.ts +0 -27
  94. package/dist/cli/commands/vm-hypervisor-probe.js +0 -78
  95. package/dist/cli/commands/vm-hypervisor-runtime.d.ts +0 -15
  96. package/dist/cli/commands/vm-hypervisor-runtime.js +0 -64
  97. package/dist/cli/commands/vm-release-command.d.ts +0 -5
  98. package/dist/cli/commands/vm-release-command.js +0 -101
  99. package/dist/cli/commands/vm-spawn-command.d.ts +0 -5
  100. package/dist/cli/commands/vm-spawn-command.js +0 -177
  101. package/dist/cli/commands/vm-status-command.d.ts +0 -3
  102. package/dist/cli/commands/vm-status-command.js +0 -50
  103. package/dist/services/vm/vm-lease.d.ts +0 -40
  104. package/dist/services/vm/vm-lease.js +0 -160
@@ -9,24 +9,26 @@
9
9
  import { existsSync, readFileSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
  import { getPrerequisitesFor } from '../artifacts/artifact-prerequisites.js';
12
+ import * as qaPhase from './pipeline-verify-qa-phase.js';
13
+ import { rdEvidenceProbe, rdGatesForType } from './pipeline-verify-rd-phase.js';
12
14
  import { prerequisiteBodyViolations } from '../artifacts/prerequisite-checks.js';
13
15
  import { showRequestArtifact } from '../artifacts/request-artifact-service.js';
14
16
  import { readArtifactState } from '../artifacts/request-artifact-state-helpers.js';
15
17
  export function extractState(markdown) {
16
18
  return readArtifactState(markdown) ?? 'unknown';
17
19
  }
18
- /**
19
- * scope is the change-id (the `.peaks/_runtime/<sessionId>/` dir the file lives
20
- * in), NOT the session-id. We resolve the on-disk location via
21
- * `showRequestArtifact` (which scans all top-level dirs and returns the
22
- * actual dir the file was found in) instead of assuming
23
- * `.peaks/_runtime/<sessionId>/<role>/requests/`.
24
- */
25
- export async function findRequestFile(projectRoot, role, rid) {
20
+ /** The rid's artifact file, read from ONE session: `sessionId` is required, and
21
+ * `null` — no resolvable scope — means NO CARRIER, never a scan (that branch
22
+ * reads every directory under `.peaks/_runtime/` and takes the first name that
23
+ * sorts). The dir the file was FOUND in comes back as `sessionId`. */
24
+ export async function findRequestFile(projectRoot, role, rid, sessionId) {
25
+ if (sessionId === null)
26
+ return null;
26
27
  const artifact = await showRequestArtifact({
27
28
  projectRoot,
28
29
  role: role,
29
- requestId: rid
30
+ requestId: rid,
31
+ sessionId
30
32
  });
31
33
  if (artifact === null)
32
34
  return null;
@@ -110,99 +112,30 @@ function contractBodyViolations(role, state, requestType, probeName, absolutePat
110
112
  return [];
111
113
  return prerequisiteBodyViolations(prerequisite, readFileSync(absolutePath, 'utf8'));
112
114
  }
113
- export function rdGatesForType(requestType) {
114
- const gates = [
115
- {
116
- name: 'rd-request-exists',
117
- description: 'RD request artifact created',
118
- passed: false,
119
- detail: ''
120
- }
121
- ];
122
- // This slot used to pin a `tech-doc` gate to `rd/tech-doc.md`, an artifact
123
- // failed trees `peaks request transition` accepts (QA repair cycle 1). The
124
- // design / scope record the contract DOES name at `rd:qa-handoff` is
125
- // `prd/handoff.md`, so that is the gate: table-derived, like the others.
126
- // (`rd/tech-doc.md` still has two non-gate readers — final-review's evidence
127
- // budget and the resume detector. Neither is served by failing a compliant
128
- // slice.)
129
- if (contractEvidencePaths('rd', 'qa-handoff', requestType, 'prd/handoff.md') !== null) {
130
- gates.push({
131
- name: 'prd-handoff',
132
- description: 'PRD handoff capsule (approved scope + non-goals)',
133
- passed: false,
134
- detail: ''
135
- });
136
- }
137
- if (requestType === 'bugfix') {
138
- gates.push({
139
- name: 'bug-analysis',
140
- description: 'Bug root-cause analysis',
141
- passed: false,
142
- detail: ''
143
- });
144
- }
145
- if (requestType !== 'docs' && requestType !== 'chore' && requestType !== 'config') {
146
- gates.push({
147
- name: 'code-review',
148
- description: 'Code review evidence',
149
- passed: false,
150
- detail: ''
151
- });
152
- }
153
- if (requestType === 'feature' ||
154
- requestType === 'refactor' ||
155
- requestType === 'bugfix' ||
156
- requestType === 'config') {
157
- gates.push({
158
- name: 'security-review',
159
- description: 'Security review evidence',
160
- passed: false,
161
- detail: ''
162
- });
163
- }
164
- // The perf evidence the contract requires at `rd:qa-handoff` is `AUDIT_PERF`
165
- // — `audit/perf-<rid>.md`, with `audit/perf.md` and `rd/perf-baseline.md` as
166
- // side as `performance-findings`, checking `qa/performance-findings-<rid>.md`
167
- // — a path the v2.11.0 D1/D4 trim dropped. Relocating the gate (rather than
168
- // deleting it) is what keeps AC3's control meaningful: perf evidence that is
169
- // genuinely absent must still fail.
170
- if (contractEvidencePaths('rd', 'qa-handoff', requestType, 'rd/perf-baseline.md') !== null) {
171
- gates.push({
172
- name: 'perf-baseline',
173
- description: 'Performance audit evidence',
174
- passed: false,
175
- detail: ''
176
- });
177
- }
178
- return gates;
179
- }
115
+ /** Re-exported so existing importers keep one import path; the builder and the
116
+ * table it filters live in `pipeline-verify-rd-phase.ts`. */
117
+ export { rdGatesForType };
118
+ /**
119
+ * The QA phase's gate list for one type.
120
+ *
121
+ * Both halves are read off the type's own table. WHICH EVIDENCE the phase owes is
122
+ * the type's `qa:` row, resolved through the same contract accessor
123
+ * `rdGatesForType` uses — a row the contract carries builds its gate, a row it
124
+ * does not carry builds none. WHETHER the phase exists at all is
125
+ * `typeRequiresQaPhase`, the same call the checker makes, which is the part that
126
+ * used to be a list of three request types named here. The derivation and the
127
+ * arming that keeps it total are `pipeline-verify-qa-phase.ts`.
128
+ *
129
+ * Two of the six types are why this reads the table instead of naming its
130
+ * members. The minimal table — docs and chore — carries no `qa:` row, so those
131
+ * types owe no QA evidence and get an empty list; that is how both the checker
132
+ * and the commit-time carrier learn there is no phase to report. Config carries
133
+ * exactly one QA row instead: a test report, and no test cases. The member list
134
+ * was wrong about both, in opposite directions: one type was asked for a phase it
135
+ * does not owe, and the other never for the evidence its transition requires.
136
+ */
180
137
  export function qaGatesForType(requestType) {
181
- const gates = [
182
- {
183
- name: 'qa-request-exists',
184
- description: 'QA request artifact created',
185
- passed: false,
186
- detail: ''
187
- }
188
- ];
189
- if (requestType === 'feature' || requestType === 'refactor' || requestType === 'bugfix') {
190
- gates.push({ name: 'test-cases', description: 'QA test cases', passed: false, detail: '' });
191
- gates.push({
192
- name: 'test-report',
193
- description: 'QA test report with execution results',
194
- passed: false,
195
- detail: ''
196
- });
197
- }
198
- // The `security-findings` / `performance-findings` gates were removed here
199
- // security review or performance review — `peaks-qa/SKILL.md` says so, and
200
- // the v2.11.0 D1/D4 trim dropped both from every `qa:verdict-issued` table.
201
- // The evidence they used to demand is now checked on the RD side, at the
202
- // paths the contract actually names (`audit/security-<rid>.md`,
203
- // `audit/perf.md` and `rd/security-review.md` / `rd/perf-baseline.md` as the
204
- // declared legacy tiers behind them).
205
- return gates;
138
+ return qaPhase.qaPhaseGates(qaPhase.typeRequiresQaPhase(requestType), qaPhase.QA_EVIDENCE_GATES.filter((gate) => qaPhase.QA_STATES.some((state) => contractEvidencePaths('qa', state, requestType, gate.relativePath) !== null)));
206
139
  }
207
140
  export const RD_QA_HANDOFF_STATES = new Set(['qa-handoff', 'handed-off', 'implemented']);
208
141
  export const QA_COMPLETE_STATES = new Set(['verdict-issued']);
@@ -211,21 +144,13 @@ export const QA_COMPLETE_STATES = new Set(['verdict-issued']);
211
144
  * gate.detail fields in place and pushes violations / nextActions. Returns the
212
145
  * updated tracker. Verbatim-move from `pipeline-verify-service.ts`. */
213
146
  export function resolveRdEvidencePaths(gates, rdEvidenceDir, projectRoot, rid, requestType, violations, nextActions, tracker) {
214
- // The path each gate is about. The contract is consulted first — see
215
- // `contractEvidencePaths`; `rdGatesForType` only builds a gate when the
216
- // contract carries its prerequisite, so this is the name the gate stands
217
- // for, not a second path table.
218
- const RD_EVIDENCE_PROBE = {
219
- 'prd-handoff': 'prd/handoff.md',
220
- 'bug-analysis': 'rd/bug-analysis.md',
221
- 'code-review': 'rd/code-review.md',
222
- 'security-review': 'rd/security-review.md',
223
- 'perf-baseline': 'rd/perf-baseline.md'
224
- };
147
+ // The path each gate is about, read off the table that declared the gate —
148
+ // not a second path table. The contract is consulted first — see
149
+ // `contractEvidencePaths`.
225
150
  let anyEvidenceResolved = tracker.anyEvidenceResolved;
226
151
  let allResolvedPathsCanonical = tracker.allResolvedPathsCanonical;
227
152
  for (const gate of gates.slice(1)) {
228
- const probeName = RD_EVIDENCE_PROBE[gate.name];
153
+ const probeName = rdEvidenceProbe(gate.name);
229
154
  const relativePaths = (contractEvidencePaths('rd', 'qa-handoff', requestType, probeName) ?? [probeName]).map((relative) => relative.replace('<rid>', rid));
230
155
  const primaryRelativePath = relativePaths[0];
231
156
  const canonicalPath = join(projectRoot, '.peaks', '_runtime', rdEvidenceDir, primaryRelativePath);
@@ -293,10 +218,8 @@ export function resolveRdEvidencePaths(gates, rdEvidenceDir, projectRoot, rid, r
293
218
  * at the contract's own paths (`audit/security-<rid>.md`,
294
219
  * `audit/perf-<rid>.md`). */
295
220
  export function resolveQaEvidencePaths(gates, projectRoot, rdEvidenceDir, requestType, rid, violations, nextActions, tracker) {
296
- const QA_EVIDENCE_PROBE = {
297
- 'test-cases': 'qa/test-cases/<rid>.md',
298
- 'test-report': 'qa/test-reports/<rid>.md'
299
- };
221
+ // Derived from the declared gates — a restatement could resolve a renamed path.
222
+ const QA_EVIDENCE_PROBE = Object.fromEntries(qaPhase.QA_EVIDENCE_GATES.map((gate) => [gate.name, gate.relativePath]));
300
223
  let anyEvidenceResolved = tracker.anyEvidenceResolved;
301
224
  let allResolvedPathsCanonical = tracker.allResolvedPathsCanonical;
302
225
  for (const gate of gates.slice(1)) {
@@ -0,0 +1,102 @@
1
+ /**
2
+ * peaks-workflow — the QA phase, derived from the type tables.
3
+ *
4
+ * WHY THIS IS A MODULE OF ITS OWN. A measured budget, not taste: the file-size
5
+ * census records the gated excess by EQUALITY, and `pipeline-verify-gate-support`
6
+ * already carries its share of that sum. A file under its cap adds nothing to it,
7
+ * so the reasoning below — which a contributor has to be able to find — is paid
8
+ * for here, at zero census cost.
9
+ *
10
+ * WHY A DERIVATION AT ALL. Two layers answered one question — *does this request
11
+ * need a QA phase?* — and gave different answers, because neither read the answer
12
+ * off the type tables that define the contract. One named three request types;
13
+ * the other asked unconditionally. A request whose table carries no QA row at all
14
+ * therefore satisfied every prerequisite its own contract lists and was then
15
+ * refused at commit time for a phase that contract never asked for.
16
+ *
17
+ * The tables are the authority. `MINIMAL_TABLE` carries no `qa:` row, which is
18
+ * what "these types have no QA phase" has always meant, and what
19
+ * `request transition --role qa --state verdict-issued` has always enforced
20
+ * against the same table.
21
+ *
22
+ * WHY IT IS ARMED. A derivation nobody checks is a restatement with better
23
+ * manners. A table row can name a QA artifact no gate stands for, and that row
24
+ * would then build no gate and say nothing about it — the same drift, one layer
25
+ * down. So the declared gate list is reconciled against every type's QA rows once
26
+ * per process, and a mismatch THROWS. The cost is deliberate and wider than it
27
+ * looks: the CLI registers every command eagerly, so an unrepresentable row does
28
+ * not merely fail `verify-pipeline` — it fails EVERY `peaks` invocation that
29
+ * reaches this module, the commit leg and `workflow verdict-aggregate` included.
30
+ * That is the fail-closed
31
+ * direction, and naming the row keeps the repair one line.
32
+ */
33
+ import { type RequestType } from '../artifacts/artifact-prerequisites.js';
34
+ import type { PipelineGate } from './pipeline-verify-types.js';
35
+ /**
36
+ * Every state the QA role can be in, taken from the repository's own state model
37
+ * rather than restated here.
38
+ *
39
+ * WHY IT IS NOT JUST `verdict-issued`. The terminal state is the one the phase's
40
+ * evidence is resolved at, so an earlier version keyed both the derivation and the
41
+ * reconciliation to it alone — which left the `qa:running` row a feature's table
42
+ * already carries outside the arming. A row at any other state would have been
43
+ * silently unrepresentable. The arming is total over the state axis instead.
44
+ */
45
+ export declare const QA_STATES: readonly import("../artifacts/request-artifact-state-helpers.js").RequestArtifactState[];
46
+ /**
47
+ * Every QA evidence gate the checker can build, each naming the contract path it
48
+ * stands for. The NAME is the checker's own — `peaks workflow skip` takes gate
49
+ * names and the violation text prints the description — while the PATH is the
50
+ * contract's, and it is the half that makes a gate list derivable instead of
51
+ * restated beside the tables it is supposed to be read from.
52
+ */
53
+ export declare const QA_EVIDENCE_GATES: ReadonlyArray<{
54
+ name: string;
55
+ description: string;
56
+ relativePath: string;
57
+ }>;
58
+ /**
59
+ * Does this type's table carry a QA phase?
60
+ *
61
+ * One derivation, so the gate list and the checker's verdict cannot disagree: the
62
+ * phase exists for a type exactly when its table carries a QA prerequisite —
63
+ * counted across every QA state, so a type whose only QA row sits at a
64
+ * non-terminal state is not read as having no phase at all.
65
+ */
66
+ export declare function typeRequiresQaPhase(requestType: RequestType): boolean;
67
+ /**
68
+ * The request types whose table carries NO QA phase — the set a skip may cover.
69
+ *
70
+ * DERIVED, not listed. The skip allowlist used to spell `['docs', 'config', 'chore']`,
71
+ * and `config` carries a QA phase (its table demands `SECURITY_REVIEW` and
72
+ * `TEST_REPORT`), so a plantable record could bypass a phase the contract requires.
73
+ * Reading the answer off the same derivation the pipeline uses means a table change
74
+ * moves the allowlist with it — in both directions, without anyone remembering.
75
+ */
76
+ export declare const QA_FREE_TYPES: ReadonlyArray<RequestType>;
77
+ /**
78
+ * Fill in the QA request gate for a phase that HAS one.
79
+ *
80
+ * A type whose table carries no QA row has no QA gate to fill, and that is not a
81
+ * special case to handle at the call site: the artifact is still honoured — its
82
+ * state and its location are read either way — so a tree that ran QA for a type
83
+ * whose table does not demand it keeps passing.
84
+ */
85
+ export declare function markQaRequestGate(gates: PipelineGate[], artifactPath: string): void;
86
+ /**
87
+ * The QA phase's gate list for one type: the phase gate when the phase exists,
88
+ * then one gate per piece of evidence the caller resolved from the contract. An
89
+ * empty list IS the answer for a type with no QA phase.
90
+ *
91
+ * The `security-findings` / `performance-findings` gates were removed here
92
+ * security review or performance review — `peaks-qa/SKILL.md` says so, and the
93
+ * v2.11.0 D1/D4 trim dropped both from every `qa:verdict-issued` table. The
94
+ * evidence they used to demand is now checked on the RD side, at the paths the
95
+ * contract actually names (`audit/security-<rid>.md`, `audit/perf.md` and
96
+ * `rd/security-review.md` / `rd/perf-baseline.md` as the declared legacy tiers
97
+ * behind them).
98
+ */
99
+ export declare function qaPhaseGates(required: boolean, evidence: ReadonlyArray<{
100
+ name: string;
101
+ description: string;
102
+ }>): PipelineGate[];
@@ -0,0 +1,176 @@
1
+ /**
2
+ * peaks-workflow — the QA phase, derived from the type tables.
3
+ *
4
+ * WHY THIS IS A MODULE OF ITS OWN. A measured budget, not taste: the file-size
5
+ * census records the gated excess by EQUALITY, and `pipeline-verify-gate-support`
6
+ * already carries its share of that sum. A file under its cap adds nothing to it,
7
+ * so the reasoning below — which a contributor has to be able to find — is paid
8
+ * for here, at zero census cost.
9
+ *
10
+ * WHY A DERIVATION AT ALL. Two layers answered one question — *does this request
11
+ * need a QA phase?* — and gave different answers, because neither read the answer
12
+ * off the type tables that define the contract. One named three request types;
13
+ * the other asked unconditionally. A request whose table carries no QA row at all
14
+ * therefore satisfied every prerequisite its own contract lists and was then
15
+ * refused at commit time for a phase that contract never asked for.
16
+ *
17
+ * The tables are the authority. `MINIMAL_TABLE` carries no `qa:` row, which is
18
+ * what "these types have no QA phase" has always meant, and what
19
+ * `request transition --role qa --state verdict-issued` has always enforced
20
+ * against the same table.
21
+ *
22
+ * WHY IT IS ARMED. A derivation nobody checks is a restatement with better
23
+ * manners. A table row can name a QA artifact no gate stands for, and that row
24
+ * would then build no gate and say nothing about it — the same drift, one layer
25
+ * down. So the declared gate list is reconciled against every type's QA rows once
26
+ * per process, and a mismatch THROWS. The cost is deliberate and wider than it
27
+ * looks: the CLI registers every command eagerly, so an unrepresentable row does
28
+ * not merely fail `verify-pipeline` — it fails EVERY `peaks` invocation that
29
+ * reaches this module, the commit leg and `workflow verdict-aggregate` included.
30
+ * That is the fail-closed
31
+ * direction, and naming the row keeps the repair one line.
32
+ */
33
+ import { getPrerequisitesFor, VALID_REQUEST_TYPES } from '../artifacts/artifact-prerequisites.js';
34
+ import { allowedStatesForRole } from '../artifacts/request-artifact-state-helpers.js';
35
+ /**
36
+ * Every state the QA role can be in, taken from the repository's own state model
37
+ * rather than restated here.
38
+ *
39
+ * WHY IT IS NOT JUST `verdict-issued`. The terminal state is the one the phase's
40
+ * evidence is resolved at, so an earlier version keyed both the derivation and the
41
+ * reconciliation to it alone — which left the `qa:running` row a feature's table
42
+ * already carries outside the arming. A row at any other state would have been
43
+ * silently unrepresentable. The arming is total over the state axis instead.
44
+ */
45
+ export const QA_STATES = allowedStatesForRole('qa');
46
+ /**
47
+ * Every QA evidence gate the checker can build, each naming the contract path it
48
+ * stands for. The NAME is the checker's own — `peaks workflow skip` takes gate
49
+ * names and the violation text prints the description — while the PATH is the
50
+ * contract's, and it is the half that makes a gate list derivable instead of
51
+ * restated beside the tables it is supposed to be read from.
52
+ */
53
+ export const QA_EVIDENCE_GATES = [
54
+ { name: 'test-cases', description: 'QA test cases', relativePath: 'qa/test-cases/<rid>.md' },
55
+ {
56
+ name: 'test-report',
57
+ description: 'QA test report with execution results',
58
+ relativePath: 'qa/test-reports/<rid>.md'
59
+ }
60
+ ];
61
+ /**
62
+ * Every QA prerequisite this type's table carries, at any state the QA role can
63
+ * be in.
64
+ *
65
+ * THE REFUSAL IS NAMED ON PURPOSE. `getPrerequisitesFor` reads a record keyed by
66
+ * type, so a non-member reaches `undefined` and throws a bare `TypeError` — before
67
+ * the derivation existed, a list of names answered such a caller with a gate list
68
+ * instead. A value that no longer works must say what it wanted, which value it
69
+ * got, and what the alternatives are.
70
+ */
71
+ function qaPrerequisitesOfType(requestType) {
72
+ if (!VALID_REQUEST_TYPES.includes(requestType)) {
73
+ throw new Error(`pipeline-verify: "${String(requestType)}" is not a request type — expected one of ${VALID_REQUEST_TYPES.join(', ')}`);
74
+ }
75
+ return QA_STATES.flatMap((state) => getPrerequisitesFor('qa', state, requestType));
76
+ }
77
+ /**
78
+ * Does this type's table carry a QA phase?
79
+ *
80
+ * One derivation, so the gate list and the checker's verdict cannot disagree: the
81
+ * phase exists for a type exactly when its table carries a QA prerequisite —
82
+ * counted across every QA state, so a type whose only QA row sits at a
83
+ * non-terminal state is not read as having no phase at all.
84
+ */
85
+ export function typeRequiresQaPhase(requestType) {
86
+ return qaPrerequisitesOfType(requestType).length > 0;
87
+ }
88
+ /**
89
+ * The request types whose table carries NO QA phase — the set a skip may cover.
90
+ *
91
+ * DERIVED, not listed. The skip allowlist used to spell `['docs', 'config', 'chore']`,
92
+ * and `config` carries a QA phase (its table demands `SECURITY_REVIEW` and
93
+ * `TEST_REPORT`), so a plantable record could bypass a phase the contract requires.
94
+ * Reading the answer off the same derivation the pipeline uses means a table change
95
+ * moves the allowlist with it — in both directions, without anyone remembering.
96
+ */
97
+ export const QA_FREE_TYPES = Object.freeze(VALID_REQUEST_TYPES.filter((requestType) => !typeRequiresQaPhase(requestType)));
98
+ /**
99
+ * Fill in the QA request gate for a phase that HAS one.
100
+ *
101
+ * A type whose table carries no QA row has no QA gate to fill, and that is not a
102
+ * special case to handle at the call site: the artifact is still honoured — its
103
+ * state and its location are read either way — so a tree that ran QA for a type
104
+ * whose table does not demand it keeps passing.
105
+ */
106
+ export function markQaRequestGate(gates, artifactPath) {
107
+ const requestGate = gates[0];
108
+ if (requestGate === undefined)
109
+ return;
110
+ requestGate.passed = true;
111
+ requestGate.detail = `found at ${artifactPath}`;
112
+ }
113
+ /**
114
+ * The QA phase's gate list for one type: the phase gate when the phase exists,
115
+ * then one gate per piece of evidence the caller resolved from the contract. An
116
+ * empty list IS the answer for a type with no QA phase.
117
+ *
118
+ * The `security-findings` / `performance-findings` gates were removed here
119
+ * security review or performance review — `peaks-qa/SKILL.md` says so, and the
120
+ * v2.11.0 D1/D4 trim dropped both from every `qa:verdict-issued` table. The
121
+ * evidence they used to demand is now checked on the RD side, at the paths the
122
+ * contract actually names (`audit/security-<rid>.md`, `audit/perf.md` and
123
+ * `rd/security-review.md` / `rd/perf-baseline.md` as the declared legacy tiers
124
+ * behind them).
125
+ */
126
+ export function qaPhaseGates(required, evidence) {
127
+ if (!required)
128
+ return [];
129
+ const gates = [
130
+ {
131
+ name: 'qa-request-exists',
132
+ description: 'QA request artifact created',
133
+ passed: false,
134
+ detail: ''
135
+ }
136
+ ];
137
+ for (const gate of evidence) {
138
+ gates.push({ name: gate.name, description: gate.description, passed: false, detail: '' });
139
+ }
140
+ return gates;
141
+ }
142
+ /**
143
+ * THE ARM — the reconciliation behind the load-time refusal below.
144
+ *
145
+ * `prerequisitesOfType` is a parameter rather than a direct call so an arm can
146
+ * drive this with a table of its own. That is the only way to show the refusal is
147
+ * reachable: a check that can only ever run against the table it already agrees
148
+ * with cannot be observed to fail.
149
+ *
150
+ * It is handed EVERY QA state's rows — `qaPrerequisitesOfType` above, whose
151
+ * `QA_STATES` is the repository's own model — so a `qa:` row at a state the phase
152
+ * does not end in is armed too. Keying only the terminal state is how the
153
+ * `qa:running` row went unarmed.
154
+ */
155
+ function qaGateReconciliationFailures(types, prerequisitesOfType) {
156
+ const failures = [];
157
+ for (const requestType of types) {
158
+ for (const prerequisite of prerequisitesOfType(requestType)) {
159
+ // The same path set the contract resolver matches on, so a row accepted
160
+ // through a legacy tier is covered by the gate that tier stands behind.
161
+ const contractPaths = [
162
+ prerequisite.relativePath,
163
+ ...(prerequisite.legacyRelativePath !== undefined ? [prerequisite.legacyRelativePath] : []),
164
+ ...(prerequisite.legacyRelativePaths ?? [])
165
+ ];
166
+ if (QA_EVIDENCE_GATES.some((gate) => contractPaths.includes(gate.relativePath)))
167
+ continue;
168
+ failures.push(`the "${requestType}" table carries the QA prerequisite ${prerequisite.relativePath} and no gate in QA_EVIDENCE_GATES stands for it`);
169
+ }
170
+ }
171
+ return failures;
172
+ }
173
+ const QA_GATE_RECONCILIATION_FAILURES = qaGateReconciliationFailures(VALID_REQUEST_TYPES, qaPrerequisitesOfType);
174
+ if (QA_GATE_RECONCILIATION_FAILURES.length > 0) {
175
+ throw new Error(`pipeline-verify: the QA gate list does not follow the type tables — ${QA_GATE_RECONCILIATION_FAILURES.join('; ')}`);
176
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * peaks-workflow — the RD evidence gates, derived from the type tables.
3
+ *
4
+ * WHY THIS IS A MODULE OF ITS OWN. The same measured budget as
5
+ * `pipeline-verify-qa-phase.ts`: the file-size census records gated excess by
6
+ * EQUALITY, and `pipeline-verify-gate-support` already carries its share of that
7
+ * sum. A file under its cap adds nothing to it, so the reasoning below is paid
8
+ * for here at zero census cost.
9
+ *
10
+ * WHY A DERIVATION AT ALL. `rdGatesForType` answered "which evidence does RD
11
+ * owe" with three hand-written type lists — `=== 'bugfix'`, `!== 'docs' &&
12
+ * !== 'chore' && !== 'config'`, and a four-name union — none of which read the
13
+ * `artifact-prerequisites.ts` table that `peaks request transition` enforces.
14
+ * The table is the authority: a type whose `rd:qa-handoff` row carries the
15
+ * prerequisite owes that evidence, and a type whose row does not owes none.
16
+ *
17
+ * WHY THE `relativePath`s ARE THE BARE NAMES. Each row's path is the probe name
18
+ * the contract accessor is asked about, and each is a path the contract accepts.
19
+ * `rd/security-review.md` is load-bearing: it is the legacy tier of BOTH the
20
+ * fanout `AUDIT_SECURITY` row (feature / bugfix / refactor) and the
21
+ * `SECURITY_REVIEW` row config uses. The canonical `audit/security-<rid>.md` is
22
+ * carried only by the former, so deriving off it would silently drop config's
23
+ * security gate — the six-type table in `pipeline-verify-rd-gates.test.ts` pins
24
+ * that.
25
+ */
26
+ import type { RequestType } from '../artifacts/artifact-prerequisites.js';
27
+ import type { PipelineGate } from './pipeline-verify-types.js';
28
+ /**
29
+ * Every RD evidence gate the checker can build, each naming the contract path it
30
+ * stands for. The NAME and DESCRIPTION are the checker's own — `peaks workflow
31
+ * skip` takes gate names and the violation text prints the description — while
32
+ * the PATH is the contract's, and it is the half that makes a gate list
33
+ * derivable instead of restated beside the tables it is supposed to be read from.
34
+ */
35
+ export declare const RD_EVIDENCE_GATES: ReadonlyArray<{
36
+ name: string;
37
+ description: string;
38
+ relativePath: string;
39
+ }>;
40
+ /** What a type's table carries for one probe name, or null when it carries none. */
41
+ export type RdEvidenceLookup = (requestType: RequestType, relativePath: string) => readonly string[] | null;
42
+ /**
43
+ * The RD gate list for one type: the request gate, then one gate per evidence
44
+ * row this type's table carries.
45
+ *
46
+ * `lookup` is a parameter rather than a direct call so an arm can drive the
47
+ * derivation with a contract of its own. That is the only way to show a null
48
+ * drops a gate: a check that only ever runs against the table it already agrees
49
+ * with cannot be observed to drop anything.
50
+ */
51
+ export declare function deriveRdGates(requestType: RequestType, lookup: RdEvidenceLookup): PipelineGate[];
52
+ /**
53
+ * The production binding: the type's own `rd:qa-handoff` table is the lookup.
54
+ *
55
+ * `lookup` is an optional overrides seam, not configuration: the arm drives this
56
+ * binding with a synthetic contract so a restatement inside the default cannot
57
+ * stay green. Production passes one argument and gets the real table.
58
+ */
59
+ export declare function rdGatesForType(requestType: RequestType, lookup?: RdEvidenceLookup): PipelineGate[];
60
+ /**
61
+ * The contract path the gate named `gateName` stands for.
62
+ *
63
+ * `resolveRdEvidencePaths` iterates exactly the gate list this module built, so
64
+ * a miss would be a name invented outside the table; it refuses by name rather
65
+ * than dereferencing nothing.
66
+ */
67
+ export declare function rdEvidenceProbe(gateName: string): string;