peaks-loop 4.1.6 → 4.1.8

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 (90) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +78 -0
  3. package/config/eslint/tsconfig.lint.json +1 -0
  4. package/dist/cli/commands/core/skill-registry-commands.js +9 -4
  5. package/dist/cli/commands/dispatch-from-dag.js +17 -0
  6. package/dist/cli/commands/job-commands.js +15 -5
  7. package/dist/cli/commands/lint-baseline-command.d.ts +15 -0
  8. package/dist/cli/commands/lint-baseline-command.js +64 -0
  9. package/dist/cli/commands/lint-commands.js +27 -51
  10. package/dist/cli/commands/request-command-options.d.ts +6 -0
  11. package/dist/cli/commands/request-commands.js +2 -0
  12. package/dist/cli/commands/request-mark-qa-initiated-command.d.ts +3 -0
  13. package/dist/cli/commands/request-mark-qa-initiated-command.js +80 -0
  14. package/dist/cli/commands/request-transition-failures.js +1 -0
  15. package/dist/cli/commands/reviewer-commands.d.ts +6 -6
  16. package/dist/cli/commands/reviewer-commands.js +154 -56
  17. package/dist/cli/commands/reviewer-config-commands.d.ts +9 -0
  18. package/dist/cli/commands/reviewer-config-commands.js +133 -0
  19. package/dist/services/artifacts/artifact-lint-service.js +102 -27
  20. package/dist/services/artifacts/artifact-prerequisites.d.ts +2 -0
  21. package/dist/services/artifacts/artifact-prerequisites.js +22 -110
  22. package/dist/services/artifacts/artifact-template-bodies.d.ts +7 -1
  23. package/dist/services/artifacts/artifact-template-bodies.js +14 -3
  24. package/dist/services/artifacts/artifact-templates.d.ts +6 -1
  25. package/dist/services/artifacts/artifact-templates.js +8 -5
  26. package/dist/services/artifacts/backcompat-acceptance.d.ts +66 -0
  27. package/dist/services/artifacts/backcompat-acceptance.js +222 -0
  28. package/dist/services/artifacts/prerequisite-checks.d.ts +42 -9
  29. package/dist/services/artifacts/prerequisite-checks.js +35 -11
  30. package/dist/services/artifacts/prerequisite-path-resolver.d.ts +39 -0
  31. package/dist/services/artifacts/prerequisite-path-resolver.js +110 -0
  32. package/dist/services/artifacts/qa-initiated-marker.d.ts +24 -0
  33. package/dist/services/artifacts/qa-initiated-marker.js +36 -0
  34. package/dist/services/artifacts/request-artifact-metadata.d.ts +9 -0
  35. package/dist/services/artifacts/request-artifact-metadata.js +9 -0
  36. package/dist/services/artifacts/request-artifact-service.js +6 -10
  37. package/dist/services/artifacts/request-artifact-state-helpers.d.ts +2 -1
  38. package/dist/services/artifacts/request-artifact-state-helpers.js +6 -3
  39. package/dist/services/dispatch/isolation-lease.d.ts +3 -2
  40. package/dist/services/dispatch/isolation-lease.js +15 -6
  41. package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.d.ts +15 -0
  42. package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.js +53 -0
  43. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.d.ts +38 -0
  44. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.js +243 -0
  45. package/dist/services/doctor/doctor-service/plugin-registry.js +4 -0
  46. package/dist/services/doctor/doctor-service/types.d.ts +12 -0
  47. package/dist/services/job/subagent-job-wrapper.d.ts +20 -7
  48. package/dist/services/job/subagent-job-wrapper.js +53 -5
  49. package/dist/services/lint/eslint-report.d.ts +19 -0
  50. package/dist/services/lint/eslint-report.js +60 -0
  51. package/dist/services/lint/eslint-runner-support.d.ts +18 -1
  52. package/dist/services/lint/eslint-runner-support.js +35 -2
  53. package/dist/services/lint/eslint-runner-types.d.ts +21 -1
  54. package/dist/services/lint/eslint-runner.js +43 -33
  55. package/dist/services/prd/gate-evidence-derivation.d.ts +2 -4
  56. package/dist/services/prd/gate-evidence-derivation.js +3 -1
  57. package/dist/services/qa/bdd-test-style-contract.d.ts +17 -0
  58. package/dist/services/qa/bdd-test-style-contract.js +41 -0
  59. package/dist/services/qa/bdd-test-style-verifier.d.ts +9 -6
  60. package/dist/services/qa/bdd-test-style-verifier.js +24 -37
  61. package/dist/services/rd/reviewer-dispatch-policy.d.ts +18 -14
  62. package/dist/services/rd/reviewer-dispatch-policy.js +14 -11
  63. package/dist/services/release/release-state.js +20 -5
  64. package/dist/services/reviewer/model-family.js +1 -1
  65. package/dist/services/reviewer/reviewer-artifacts.d.ts +12 -0
  66. package/dist/services/reviewer/reviewer-artifacts.js +67 -0
  67. package/dist/services/reviewer/reviewer-config-write.d.ts +18 -0
  68. package/dist/services/reviewer/reviewer-config-write.js +71 -0
  69. package/dist/services/reviewer/reviewer-config.d.ts +33 -5
  70. package/dist/services/reviewer/reviewer-config.js +102 -46
  71. package/dist/services/reviewer/reviewer-envelopes.d.ts +8 -0
  72. package/dist/services/reviewer/reviewer-envelopes.js +53 -0
  73. package/dist/services/reviewer/reviewer-service.d.ts +7 -4
  74. package/dist/services/reviewer/reviewer-service.js +46 -52
  75. package/dist/services/reviewer/reviewer-types.d.ts +9 -1
  76. package/dist/services/session/getSessionDir.js +16 -7
  77. package/dist/services/web/daemon-registry.d.ts +6 -4
  78. package/dist/services/web/daemon-registry.js +92 -17
  79. package/dist/services/workflow/pipeline-verify-gate-support.d.ts +4 -1
  80. package/dist/services/workflow/pipeline-verify-gate-support.js +8 -79
  81. package/dist/services/workflow/pipeline-verify-rd-phase.d.ts +67 -0
  82. package/dist/services/workflow/pipeline-verify-rd-phase.js +122 -0
  83. package/dist/services/workflow/pipeline-verify-service.js +16 -17
  84. package/dist/services/workspace/workspace-service.js +4 -16
  85. package/package.json +5 -5
  86. package/schemas/doctor-report.schema.json +2 -2
  87. package/schemas/reviewer-envelope.schema.json +1 -1
  88. package/skills/bee/peaks-reviewer/SKILL.md +20 -4
  89. package/skills/bee/peaks-reviewer/references/reviewer-schema.md +12 -7
  90. package/skills/bee/peaks-security-audit/SKILL.md +20 -0
@@ -4,7 +4,7 @@
4
4
  * WRITE goes through `assertUnder` first — the slice-wide guard against an
5
5
  * artifact escaping `<root>/.peaks/_runtime/<sid>/web/` (AC1).
6
6
  */
7
- import { existsSync, mkdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
7
+ import { constants, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
8
8
  import { dirname } from 'node:path';
9
9
  import { assertUnder, webDaemonDir, webDaemonInfoPath, webSpawnLockPath } from './web-artifact-paths.js';
10
10
  import { parseDaemonInfo } from './web-protocol.js';
@@ -115,38 +115,111 @@ export function isProcessAlive(pid) {
115
115
  return error.code === 'EPERM';
116
116
  }
117
117
  }
118
+ const SPAWN_LOCK_ATTEMPTS = 3;
118
119
  /**
119
- * Take the cold-start lock (O_EXCL create). Returns `false` when another
120
- * process holds a live lock, and reclaims a STALE one — owner pid dead, or
121
- * older than `SPAWN_LOCK_STALE_MS` — before retrying once (tech-doc §1.4).
120
+ * Take the cold-start lock. Returns `false` when another process holds a live
121
+ * lock; reclaims a STALE one by renaming it to a per-call quarantine. Unlink-
122
+ * then-create is not atomic (two callers could both return true), so the
123
+ * replacement is created and identity-verified, and a moved fresh lock is
124
+ * restored rather than replaced.
122
125
  */
123
126
  export function acquireSpawnLock(projectRoot, sessionId) {
124
127
  const target = webSpawnLockPath(projectRoot, sessionId);
125
128
  assertUnder(target, webDaemonDir(projectRoot, sessionId));
126
129
  mkdirSync(dirname(target), { recursive: true, mode: DAEMON_DIR_MODE });
127
- if (tryCreateSpawnLock(target)) {
128
- return true;
130
+ let mine = null;
131
+ for (let attempt = 0; attempt < SPAWN_LOCK_ATTEMPTS; attempt += 1) {
132
+ const created = tryCreateSpawnLock(target);
133
+ if (created !== null) {
134
+ mine = created;
135
+ if (ownsLockFile(target, created))
136
+ return true;
137
+ continue;
138
+ }
139
+ const existing = readSpawnLock(target);
140
+ if (isOwnLock(existing, mine))
141
+ return true;
142
+ if (isSpawnLockHeld(target, existing))
143
+ return false;
144
+ return reclaimSpawnLock(target, existing);
129
145
  }
130
- const existing = readSpawnLock(target);
131
- const ageMs = existing === null ? Number.NaN : Date.now() - Date.parse(existing.startedAt);
132
- if (existing !== null && isProcessAlive(existing.pid) && ageMs <= SPAWN_LOCK_STALE_MS) {
146
+ return false;
147
+ }
148
+ function isOwnLock(existing, mine) {
149
+ return (existing !== null &&
150
+ mine !== null &&
151
+ existing.pid === mine.pid &&
152
+ existing.startedAt === mine.startedAt);
153
+ }
154
+ /** Unreadable is held while young; readable is held while its owner is alive and young. */
155
+ function isSpawnLockHeld(target, existing) {
156
+ if (existing === null) {
157
+ return lockFileAgeMs(target) <= SPAWN_LOCK_STALE_MS;
158
+ }
159
+ return (isProcessAlive(existing.pid) &&
160
+ Date.now() - Date.parse(existing.startedAt) <= SPAWN_LOCK_STALE_MS);
161
+ }
162
+ /** True only when `target` still holds the exact body this call created. */
163
+ function ownsLockFile(target, created) {
164
+ const now = readSpawnLock(target);
165
+ return now !== null && now.pid === created.pid && now.startedAt === created.startedAt;
166
+ }
167
+ let reclaimSerial = 0; // one quarantine per call, so reclaimers never share a path
168
+ /**
169
+ * Take a stale lock by renaming it to this call's quarantine; true only when
170
+ * the verified replacement was created.
171
+ */
172
+ function reclaimSpawnLock(target, existing) {
173
+ reclaimSerial += 1;
174
+ const quarantine = `${target}.reclaim-${String(process.pid)}-${String(reclaimSerial)}`;
175
+ try {
176
+ renameSync(target, quarantine);
177
+ }
178
+ catch {
133
179
  return false;
134
180
  }
181
+ const moved = readSpawnLock(quarantine);
182
+ const movedIsStale = existing === null
183
+ ? moved === null && lockFileAgeMs(quarantine) > SPAWN_LOCK_STALE_MS
184
+ : moved !== null && moved.pid === existing.pid && moved.startedAt === existing.startedAt;
185
+ if (!movedIsStale) {
186
+ restoreQuarantinedLock(quarantine, target);
187
+ return false;
188
+ }
189
+ rmSync(quarantine, { force: true });
190
+ const created = tryCreateSpawnLock(target);
191
+ return created !== null && ownsLockFile(target, created);
192
+ }
193
+ /** Put a freshly-moved lock back without ever replacing a lock that now owns the path. */
194
+ function restoreQuarantinedLock(quarantine, target) {
135
195
  try {
136
- unlinkSync(target);
196
+ copyFileSync(quarantine, target, constants.COPYFILE_EXCL);
197
+ rmSync(quarantine, { force: true });
198
+ }
199
+ catch (error) {
200
+ if (error.code !== 'EEXIST')
201
+ throw error;
202
+ rmSync(quarantine, { force: true });
203
+ }
204
+ }
205
+ /** File age, used only when the body cannot be read; `Infinity` when it vanished. */
206
+ function lockFileAgeMs(target) {
207
+ try {
208
+ return Date.now() - statSync(target).mtimeMs;
137
209
  }
138
210
  catch {
139
- // Racers: whoever wins the unlink still has to win the O_EXCL create below.
211
+ return Number.POSITIVE_INFINITY;
140
212
  }
141
- return tryCreateSpawnLock(target);
142
213
  }
143
- /** Release the spawn lock, but only when this process is its owner. */
214
+ /** Release the spawn lock, but only when this process provably owns it. */
144
215
  export function releaseSpawnLock(projectRoot, sessionId) {
145
216
  const target = webSpawnLockPath(projectRoot, sessionId);
146
217
  const existing = readSpawnLock(target);
147
- if (existing !== null && existing.pid !== process.pid) {
218
+ if (existing !== null && existing.pid !== process.pid)
219
+ return;
220
+ // A young unreadable body may be a live creator mid-write; do not unlink it.
221
+ if (existing === null && lockFileAgeMs(target) <= SPAWN_LOCK_STALE_MS)
148
222
  return;
149
- }
150
223
  try {
151
224
  unlinkSync(target);
152
225
  }
@@ -166,15 +239,17 @@ export function listSessionDaemons(projectRoot, sessionId) {
166
239
  }
167
240
  function tryCreateSpawnLock(target) {
168
241
  const body = { pid: process.pid, startedAt: new Date().toISOString() };
242
+ let created;
169
243
  try {
170
244
  writeFileSync(target, JSON.stringify(body), { flag: 'wx', encoding: 'utf8' });
171
- return true;
245
+ created = true;
172
246
  }
173
247
  catch {
174
248
  // `EEXIST` (held) and any other write failure both mean "not acquired".
175
249
  // The caller either waits for the holder or surfaces a readiness timeout.
176
- return false;
250
+ created = false;
177
251
  }
252
+ return created ? body : null;
178
253
  }
179
254
  function readSpawnLock(target) {
180
255
  try {
@@ -7,6 +7,7 @@
7
7
  *
8
8
  */
9
9
  import { type ArtifactPrerequisite, type RequestType } from '../artifacts/artifact-prerequisites.js';
10
+ import { rdGatesForType } from './pipeline-verify-rd-phase.js';
10
11
  import type { RequestArtifactRole, RequestArtifactState } from '../artifacts/request-artifact-service.js';
11
12
  import type { PipelineGate } from './pipeline-verify-types.js';
12
13
  export declare function extractState(markdown: string): string;
@@ -50,7 +51,9 @@ export declare function findRequestFile(projectRoot: string, role: string, rid:
50
51
  */
51
52
  export declare function contractPrerequisite(role: RequestArtifactRole, state: RequestArtifactState, requestType: RequestType, probeName: string): ArtifactPrerequisite | null;
52
53
  export declare function contractEvidencePaths(role: RequestArtifactRole, state: RequestArtifactState, requestType: RequestType, probeName: string): string[] | null;
53
- export declare function rdGatesForType(requestType: RequestType): PipelineGate[];
54
+ /** Re-exported so existing importers keep one import path; the builder and the
55
+ * table it filters live in `pipeline-verify-rd-phase.ts`. */
56
+ export { rdGatesForType };
54
57
  /**
55
58
  * The QA phase's gate list for one type.
56
59
  *
@@ -10,6 +10,7 @@ import { existsSync, readFileSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
  import { getPrerequisitesFor } from '../artifacts/artifact-prerequisites.js';
12
12
  import * as qaPhase from './pipeline-verify-qa-phase.js';
13
+ import { rdEvidenceProbe, rdGatesForType } from './pipeline-verify-rd-phase.js';
13
14
  import { prerequisiteBodyViolations } from '../artifacts/prerequisite-checks.js';
14
15
  import { showRequestArtifact } from '../artifacts/request-artifact-service.js';
15
16
  import { readArtifactState } from '../artifacts/request-artifact-state-helpers.js';
@@ -111,73 +112,9 @@ function contractBodyViolations(role, state, requestType, probeName, absolutePat
111
112
  return [];
112
113
  return prerequisiteBodyViolations(prerequisite, readFileSync(absolutePath, 'utf8'));
113
114
  }
114
- export function rdGatesForType(requestType) {
115
- const gates = [
116
- {
117
- name: 'rd-request-exists',
118
- description: 'RD request artifact created',
119
- passed: false,
120
- detail: ''
121
- }
122
- ];
123
- // This slot used to pin a `tech-doc` gate to `rd/tech-doc.md`, an artifact
124
- // failed trees `peaks request transition` accepts (QA repair cycle 1). The
125
- // design / scope record the contract DOES name at `rd:qa-handoff` is
126
- // `prd/handoff.md`, so that is the gate: table-derived, like the others.
127
- // (`rd/tech-doc.md` still has two non-gate readers — final-review's evidence
128
- // budget and the resume detector. Neither is served by failing a compliant
129
- // slice.)
130
- if (contractEvidencePaths('rd', 'qa-handoff', requestType, 'prd/handoff.md') !== null) {
131
- gates.push({
132
- name: 'prd-handoff',
133
- description: 'PRD handoff capsule (approved scope + non-goals)',
134
- passed: false,
135
- detail: ''
136
- });
137
- }
138
- if (requestType === 'bugfix') {
139
- gates.push({
140
- name: 'bug-analysis',
141
- description: 'Bug root-cause analysis',
142
- passed: false,
143
- detail: ''
144
- });
145
- }
146
- if (requestType !== 'docs' && requestType !== 'chore' && requestType !== 'config') {
147
- gates.push({
148
- name: 'code-review',
149
- description: 'Code review evidence',
150
- passed: false,
151
- detail: ''
152
- });
153
- }
154
- if (requestType === 'feature' ||
155
- requestType === 'refactor' ||
156
- requestType === 'bugfix' ||
157
- requestType === 'config') {
158
- gates.push({
159
- name: 'security-review',
160
- description: 'Security review evidence',
161
- passed: false,
162
- detail: ''
163
- });
164
- }
165
- // The perf evidence the contract requires at `rd:qa-handoff` is `AUDIT_PERF`
166
- // — `audit/perf-<rid>.md`, with `audit/perf.md` and `rd/perf-baseline.md` as
167
- // side as `performance-findings`, checking `qa/performance-findings-<rid>.md`
168
- // — a path the v2.11.0 D1/D4 trim dropped. Relocating the gate (rather than
169
- // deleting it) is what keeps AC3's control meaningful: perf evidence that is
170
- // genuinely absent must still fail.
171
- if (contractEvidencePaths('rd', 'qa-handoff', requestType, 'rd/perf-baseline.md') !== null) {
172
- gates.push({
173
- name: 'perf-baseline',
174
- description: 'Performance audit evidence',
175
- passed: false,
176
- detail: ''
177
- });
178
- }
179
- return gates;
180
- }
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 };
181
118
  /**
182
119
  * The QA phase's gate list for one type.
183
120
  *
@@ -207,21 +144,13 @@ export const QA_COMPLETE_STATES = new Set(['verdict-issued']);
207
144
  * gate.detail fields in place and pushes violations / nextActions. Returns the
208
145
  * updated tracker. Verbatim-move from `pipeline-verify-service.ts`. */
209
146
  export function resolveRdEvidencePaths(gates, rdEvidenceDir, projectRoot, rid, requestType, violations, nextActions, tracker) {
210
- // The path each gate is about. The contract is consulted first — see
211
- // `contractEvidencePaths`; `rdGatesForType` only builds a gate when the
212
- // contract carries its prerequisite, so this is the name the gate stands
213
- // for, not a second path table.
214
- const RD_EVIDENCE_PROBE = {
215
- 'prd-handoff': 'prd/handoff.md',
216
- 'bug-analysis': 'rd/bug-analysis.md',
217
- 'code-review': 'rd/code-review.md',
218
- 'security-review': 'rd/security-review.md',
219
- 'perf-baseline': 'rd/perf-baseline.md'
220
- };
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`.
221
150
  let anyEvidenceResolved = tracker.anyEvidenceResolved;
222
151
  let allResolvedPathsCanonical = tracker.allResolvedPathsCanonical;
223
152
  for (const gate of gates.slice(1)) {
224
- const probeName = RD_EVIDENCE_PROBE[gate.name];
153
+ const probeName = rdEvidenceProbe(gate.name);
225
154
  const relativePaths = (contractEvidencePaths('rd', 'qa-handoff', requestType, probeName) ?? [probeName]).map((relative) => relative.replace('<rid>', rid));
226
155
  const primaryRelativePath = relativePaths[0];
227
156
  const canonicalPath = join(projectRoot, '.peaks', '_runtime', rdEvidenceDir, primaryRelativePath);
@@ -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;
@@ -0,0 +1,122 @@
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
+ // A LIVE-BINDING CYCLE: `pipeline-verify-gate-support` re-exports
27
+ // `rdGatesForType` from this module while this module reads its
28
+ // `contractEvidencePaths`. Both are function declarations, which ESM initialises
29
+ // during instantiation, so the binding is safe — but only while nothing here
30
+ // CALLS it at module load. The derivation is function-only and the default
31
+ // parameter below resolves per call. A leaf-module split would have to move
32
+ // `contractPrerequisite` / `contractBodyViolations` with the accessor and expand
33
+ // this diff, so the cycle stays bounded to these two files.
34
+ import { contractEvidencePaths } from './pipeline-verify-gate-support.js';
35
+ /**
36
+ * Every RD evidence gate the checker can build, each naming the contract path it
37
+ * stands for. The NAME and DESCRIPTION are the checker's own — `peaks workflow
38
+ * skip` takes gate names and the violation text prints the description — while
39
+ * the PATH is the contract's, and it is the half that makes a gate list
40
+ * derivable instead of restated beside the tables it is supposed to be read from.
41
+ */
42
+ export const RD_EVIDENCE_GATES = [
43
+ // The contract's design / scope record at `rd:qa-handoff`. The retired
44
+ // `rd/tech-doc.md` slot this gate replaced has no prerequisite in any table.
45
+ {
46
+ name: 'prd-handoff',
47
+ description: 'PRD handoff capsule (approved scope + non-goals)',
48
+ relativePath: 'prd/handoff.md'
49
+ },
50
+ {
51
+ name: 'bug-analysis',
52
+ description: 'Bug root-cause analysis',
53
+ relativePath: 'rd/bug-analysis.md'
54
+ },
55
+ { name: 'code-review', description: 'Code review evidence', relativePath: 'rd/code-review.md' },
56
+ {
57
+ name: 'security-review',
58
+ description: 'Security review evidence',
59
+ relativePath: 'rd/security-review.md'
60
+ },
61
+ // `AUDIT_PERF`'s legacy tier. Relocating the gate (rather than deleting it) is
62
+ // what keeps AC3's control meaningful: genuinely absent perf evidence fails.
63
+ {
64
+ name: 'perf-baseline',
65
+ description: 'Performance audit evidence',
66
+ relativePath: 'rd/perf-baseline.md'
67
+ }
68
+ ];
69
+ /**
70
+ * The RD gate list for one type: the request gate, then one gate per evidence
71
+ * row this type's table carries.
72
+ *
73
+ * `lookup` is a parameter rather than a direct call so an arm can drive the
74
+ * derivation with a contract of its own. That is the only way to show a null
75
+ * drops a gate: a check that only ever runs against the table it already agrees
76
+ * with cannot be observed to drop anything.
77
+ */
78
+ export function deriveRdGates(requestType, lookup) {
79
+ const gates = [
80
+ {
81
+ name: 'rd-request-exists',
82
+ description: 'RD request artifact created',
83
+ passed: false,
84
+ detail: ''
85
+ }
86
+ ];
87
+ for (const evidence of RD_EVIDENCE_GATES) {
88
+ if (lookup(requestType, evidence.relativePath) === null)
89
+ continue;
90
+ gates.push({
91
+ name: evidence.name,
92
+ description: evidence.description,
93
+ passed: false,
94
+ detail: ''
95
+ });
96
+ }
97
+ return gates;
98
+ }
99
+ /**
100
+ * The production binding: the type's own `rd:qa-handoff` table is the lookup.
101
+ *
102
+ * `lookup` is an optional overrides seam, not configuration: the arm drives this
103
+ * binding with a synthetic contract so a restatement inside the default cannot
104
+ * stay green. Production passes one argument and gets the real table.
105
+ */
106
+ export function rdGatesForType(requestType, lookup = (type, relativePath) => contractEvidencePaths('rd', 'qa-handoff', type, relativePath)) {
107
+ return deriveRdGates(requestType, lookup);
108
+ }
109
+ /**
110
+ * The contract path the gate named `gateName` stands for.
111
+ *
112
+ * `resolveRdEvidencePaths` iterates exactly the gate list this module built, so
113
+ * a miss would be a name invented outside the table; it refuses by name rather
114
+ * than dereferencing nothing.
115
+ */
116
+ export function rdEvidenceProbe(gateName) {
117
+ const gate = RD_EVIDENCE_GATES.find((entry) => entry.name === gateName);
118
+ if (gate === undefined) {
119
+ throw new Error(`pipeline-verify: "${gateName}" is not an RD evidence gate — expected one of ${RD_EVIDENCE_GATES.map((entry) => entry.name).join(', ')}`);
120
+ }
121
+ return gate.relativePath;
122
+ }
@@ -15,6 +15,7 @@ import { markQaRequestGate, typeRequiresQaPhase } from './pipeline-verify-qa-pha
15
15
  import { NO_SESSION_SCOPE, mayHonourSkip, resolveRequestType } from './request-type-resolution.js';
16
16
  import { readSkipState } from './workflow-state-store.js';
17
17
  import { getSessionIdCanonical } from '../session/session-manager.js';
18
+ import { checkExpiredBackCompatCommitGate } from '../artifacts/artifact-prerequisites.js';
18
19
  import { listPromotionExempt, listUnpromotedFeedback } from '../feedback/feedback-promotion-service.js';
19
20
  import { QA_COMPLETE_STATES, RD_QA_HANDOFF_STATES, extractState, findRequestFile, qaGatesForType, rdGatesForType, resolveQaEvidencePaths, resolveRdEvidencePaths } from './pipeline-verify-gate-support.js';
20
21
  export async function verifyPipeline(options) {
@@ -126,6 +127,14 @@ export async function verifyPipeline(options) {
126
127
  const qaTracker = resolveQaEvidencePaths(rdEvidenceDir === '' ? [] : qaGates, options.projectRoot, rdEvidenceDir, requestType, options.rid, violations, nextActions, rdTracker);
127
128
  const anyEvidenceResolved = qaTracker.anyEvidenceResolved;
128
129
  const allResolvedPathsCanonical = qaTracker.allResolvedPathsCanonical;
130
+ const backcompatExpiry = await checkExpiredBackCompatCommitGate({
131
+ projectRoot: options.projectRoot,
132
+ sessionId: rdEvidenceDir === '' ? undefined : rdEvidenceDir,
133
+ requestType,
134
+ requestId: options.rid
135
+ });
136
+ violations.push(...backcompatExpiry.violations);
137
+ nextActions.push(...backcompatExpiry.warnings);
129
138
  // Check if QA reached verdict-issued
130
139
  if (qaInvoked && !QA_COMPLETE_STATES.has(qaState)) {
131
140
  violations.push(`QA not complete: state is "${qaState}" — must reach "verdict-issued" (functional + performance + security checks done)`);
@@ -135,12 +144,9 @@ export async function verifyPipeline(options) {
135
144
  // values are only final after the post-process pass. We track the
136
145
  // decision with a placeholder here and resolve it below.
137
146
  const rdInvokedWithoutQaRaw = rdInvoked && !qaInvoked;
138
- // the user marked as skipped, override the evaluation result. The
139
- // boolean `passed` is set to true so the gate counts as satisfied;
140
- // the new `status: 'skipped'` field signals the bypass to
141
- // downstream consumers. Violations and nextActions pushed for
142
- // skipped gates are filtered out (the user explicitly chose to
143
- // skip — the missing-evidence message is no longer actionable).
147
+ // A skipped gate counts as satisfied (`passed = true`); its `status: 'skipped'`
148
+ // signals the bypass downstream, and its missing-evidence violations and
149
+ // nextActions are filtered out because the user chose the skip.
144
150
  for (const gate of [...rdGates, ...qaGates]) {
145
151
  if (skippedGateNames.has(gate.name)) {
146
152
  markIfSkipped(gate);
@@ -230,6 +236,7 @@ export async function verifyPipeline(options) {
230
236
  allRdGatesPassed &&
231
237
  allQaGatesPassed &&
232
238
  allFeedbackGatesPassed &&
239
+ backcompatExpiry.violations.length === 0 &&
233
240
  RD_QA_HANDOFF_STATES.has(rdState);
234
241
  // 'suffixed' when the contract's current path served the file and 'legacy'
235
242
  // when the deprecated fallback did; 'none' if neither gate passed.
@@ -251,17 +258,9 @@ export async function verifyPipeline(options) {
251
258
  : 'suffixed';
252
259
  const gateC = allQaGatesPassed ? 'pass' : 'fail';
253
260
  const gateH = allFeedbackGatesPassed ? 'pass' : 'fail';
254
- // every gate resolved on the canonical path; `false` when at least
255
- // one fell back to a legacy form. QA / TXT surface the value so the
256
- // user knows the legacy content must be moved into the canonical
257
- // location (the legacy `peaks workspace migrate-change-scope` helper
258
- // was removed in v2.19.0; use `peaks workspace migrate` to relocate
259
- // misplaced content).
260
- //
261
- // If NO evidence file resolved (e.g. all gates missing), the field is
262
- // `true` — there is nothing non-canonical to worry about. If every
263
- // resolved gate was skipped via `peaks workflow skip`, the field is
264
- // `true` — the user opted out of the canonical/legacy decision.
261
+ // `true` when every resolved gate used the canonical path (or nothing resolved,
262
+ // or every gate was skipped). `false` when one fell back to a legacy form; QA /
263
+ // TXT surface it so the user moves the content with `peaks workspace migrate`.
265
264
  const allGatesSkipped = [...rdGates, ...qaGates].every((g) => g.status === 'skipped');
266
265
  const usedCanonicalPath = !anyEvidenceResolved || allGatesSkipped || allResolvedPathsCanonical;
267
266
  return {
@@ -7,6 +7,7 @@ import { updateCallerBindingSessionId } from '../session/caller-binding-service.
7
7
  import { resolveCallerProjection } from '../session/resolve-caller-id.js';
8
8
  import { normalizePath } from '../../shared/path-utils.js';
9
9
  import { assertWritableProjectRoot } from '../config/config-safety.js';
10
+ import { seedBackCompatAcceptance } from '../artifacts/backcompat-acceptance.js';
10
11
  /**
11
12
  * calling process's own per-caller binding at the session id this init just
12
13
  * bound. `getSessionIdCanonical` reads `callers/<callerId>.json` FIRST, so a
@@ -46,22 +47,6 @@ function listPeaksRuntimeSiblings(projectRoot) {
46
47
  return [];
47
48
  }
48
49
  }
49
- /**
50
- * `.peaks/_runtime/` so the legacy sibling-dir guard can enumerate
51
- * date-stamped residue dirs at the runtime layer. Returns `[]` when
52
- * the `.peaks/_runtime/` dir does not exist.
53
- */
54
- function listRuntimeSiblings(projectRoot) {
55
- const runtimeDir = join(projectRoot, '.peaks', '_runtime');
56
- if (!existsSync(runtimeDir))
57
- return [];
58
- try {
59
- return readdirSync(runtimeDir);
60
- }
61
- catch {
62
- return [];
63
- }
64
- }
65
50
  /**
66
51
  * basename matches the auto-generated session-id shape
67
52
  * `YYYY-MM-DD-<slug>` (the v2.8.3 hard-ban target). Bare dates
@@ -365,6 +350,9 @@ export async function initWorkspace(options) {
365
350
  // last regenerate this project", not "when did the bytes change". See
366
351
  // `generated-artifacts-stamp.ts`.
367
352
  writeGeneratedArtifactsStamp(options.projectRoot);
353
+ // The commit-leg expiry gate is opt-in by the presence of this tracked list;
354
+ // seeding it here (idempotently) is how a project opts in.
355
+ seedBackCompatAcceptance(options.projectRoot);
368
356
  return {
369
357
  sessionId: options.sessionId,
370
358
  sessionRoot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peaks-loop",
3
- "version": "4.1.6",
3
+ "version": "4.1.8",
4
4
  "description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
5
5
  "author": "SquabbyZ",
6
6
  "keywords": [
@@ -129,10 +129,10 @@
129
129
  "picomatch": "4.0.4",
130
130
  "yaml": "^2.9.0",
131
131
  "zod": "^4.4.3",
132
- "peaks-loop-internal-runtime": "0.0.46",
133
- "peaks-loop-mut": "0.1.60",
134
- "peaks-loop-shared": "0.0.95",
135
- "peaks-loop-shared-channel": "0.0.63"
132
+ "peaks-loop-internal-runtime": "0.0.48",
133
+ "peaks-loop-mut": "0.1.62",
134
+ "peaks-loop-shared-channel": "0.0.65",
135
+ "peaks-loop-shared": "0.0.97"
136
136
  },
137
137
  "devDependencies": {
138
138
  "@changesets/cli": "2.31.1",
@@ -13,8 +13,8 @@
13
13
  "properties": {
14
14
  "id": {
15
15
  "type": "string",
16
- "pattern": "^(skill|skill-name|skill-parse|skill-runbook|skill-apply-note|skill-presence|statusline|schema|config|doctor-self|capability|build|integration|L3):[A-Za-z0-9][A-Za-z0-9._-]*$",
17
- "description": "Stable check id. Known prefixes: skill:<name> (required skill present), skill-name:<dir> (directory matches declared name), skill-parse:<dir> (skill metadata parsed), skill-runbook:<name> (Default runbook section exists), skill-apply-note:<name> (destructive --apply lines carry an authorization/--dry-run note), skill-presence:<topic> (status of .peaks/.active-skill.json — current/freshness/workspace), statusline:<topic> (out-of-band Claude Code statusLine — install/runtime), schema:<file> (schema file exists and is valid JSON), config:<scope> (optional config locations), doctor-self:<topic> (doctor validates its own output against this schema), capability:<name> (third-party capability is resolvable at the pinned version), build:<topic> (build-hygiene checks — dist/source version consistency), integration:<name> (third-party integration probe — e.g. gateguard-fact-force PreToolUse hook conflict on .peaks/**)."
16
+ "pattern": "^(?:(?:skill|skill-name|skill-parse|skill-runbook|skill-apply-note|skill-presence|statusline|schema|config|doctor-self|capability|build|integration|L3):[A-Za-z0-9][A-Za-z0-9._-]*|skills:[A-Za-z0-9][A-Za-z0-9._-]*(?::[A-Za-z0-9][A-Za-z0-9._-]*)+)$",
17
+ "description": "Stable check id. Known prefixes: skill:<name> (required skill present), skill-name:<dir> (directory matches declared name), skill-parse:<dir> (skill metadata parsed), skill-runbook:<name> (Default runbook section exists), skill-apply-note:<name> (destructive --apply lines carry an authorization/--dry-run note), skill-presence:<topic> (status of .peaks/.active-skill.json — current/freshness/workspace), skills:<topic>:<ide>:<skill> (canonical-store vs IDE skill-tree parity — a file present on one side and absent on the other; topic store means the canonical store is absent), statusline:<topic> (out-of-band Claude Code statusLine — install/runtime), schema:<file> (schema file exists and is valid JSON), config:<scope> (optional config locations), doctor-self:<topic> (doctor validates its own output against this schema), capability:<name> (third-party capability is resolvable at the pinned version), build:<topic> (build-hygiene checks — dist/source version consistency), integration:<name> (third-party integration probe — e.g. gateguard-fact-force PreToolUse hook conflict on .peaks/**)."
18
18
  },
19
19
  "ok": { "type": "boolean" },
20
20
  "message": { "type": "string", "minLength": 1 }
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "passed": {
34
34
  "type": "boolean",
35
- "description": "True when reviewer found no blocking violations."
35
+ "description": "True only when a review RAN and found no blocking violations. False when it found violations, and also false on every skip path (no config, provider error, non-conforming JSON) — a review that never produced a verdict is never a pass."
36
36
  },
37
37
  "violations": {
38
38
  "type": "array",