peaks-loop 4.1.7 → 4.1.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 (85) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +72 -0
  3. package/config/eslint/tsconfig.lint.json +1 -0
  4. package/dist/cli/commands/code-gate-step-08-command.js +21 -11
  5. package/dist/cli/commands/code-gate-step-08-remedy.d.ts +17 -0
  6. package/dist/cli/commands/code-gate-step-08-remedy.js +76 -0
  7. package/dist/cli/commands/code-job-shape-commands.js +21 -5
  8. package/dist/cli/commands/dispatch-from-dag.js +17 -0
  9. package/dist/cli/commands/job-commands.js +15 -5
  10. package/dist/cli/commands/job-init-status-commands.js +45 -5
  11. package/dist/cli/commands/lint-baseline-command.d.ts +15 -0
  12. package/dist/cli/commands/lint-baseline-command.js +64 -0
  13. package/dist/cli/commands/lint-commands.js +27 -51
  14. package/dist/cli/commands/request-command-options.d.ts +6 -0
  15. package/dist/cli/commands/request-commands.js +2 -0
  16. package/dist/cli/commands/request-mark-qa-initiated-command.d.ts +3 -0
  17. package/dist/cli/commands/request-mark-qa-initiated-command.js +80 -0
  18. package/dist/cli/commands/request-transition-failures.js +1 -0
  19. package/dist/cli/commands/reviewer-commands.d.ts +6 -6
  20. package/dist/cli/commands/reviewer-commands.js +154 -56
  21. package/dist/cli/commands/reviewer-config-commands.d.ts +9 -0
  22. package/dist/cli/commands/reviewer-config-commands.js +133 -0
  23. package/dist/services/artifacts/artifact-lint-service.js +102 -27
  24. package/dist/services/artifacts/artifact-prerequisites.d.ts +1 -0
  25. package/dist/services/artifacts/artifact-prerequisites.js +13 -13
  26. package/dist/services/artifacts/artifact-template-bodies.d.ts +7 -1
  27. package/dist/services/artifacts/artifact-template-bodies.js +14 -3
  28. package/dist/services/artifacts/artifact-templates.d.ts +6 -1
  29. package/dist/services/artifacts/artifact-templates.js +8 -5
  30. package/dist/services/artifacts/backcompat-acceptance.js +7 -5
  31. package/dist/services/artifacts/prerequisite-checks.d.ts +34 -9
  32. package/dist/services/artifacts/prerequisite-checks.js +28 -9
  33. package/dist/services/artifacts/qa-initiated-marker.d.ts +24 -0
  34. package/dist/services/artifacts/qa-initiated-marker.js +36 -0
  35. package/dist/services/artifacts/request-artifact-metadata.d.ts +9 -0
  36. package/dist/services/artifacts/request-artifact-metadata.js +9 -0
  37. package/dist/services/artifacts/request-artifact-service.js +6 -10
  38. package/dist/services/artifacts/request-artifact-state-helpers.d.ts +2 -1
  39. package/dist/services/artifacts/request-artifact-state-helpers.js +6 -3
  40. package/dist/services/code/job-shape-provisional.d.ts +51 -0
  41. package/dist/services/code/job-shape-provisional.js +80 -0
  42. package/dist/services/code/step-08-gate.d.ts +24 -12
  43. package/dist/services/code/step-08-gate.js +54 -97
  44. package/dist/services/code/step-08-session-readers.d.ts +27 -0
  45. package/dist/services/code/step-08-session-readers.js +105 -0
  46. package/dist/services/dispatch/isolation-lease.d.ts +3 -2
  47. package/dist/services/dispatch/isolation-lease.js +15 -6
  48. package/dist/services/job/subagent-job-wrapper.d.ts +20 -7
  49. package/dist/services/job/subagent-job-wrapper.js +53 -5
  50. package/dist/services/lint/eslint-report.d.ts +19 -0
  51. package/dist/services/lint/eslint-report.js +60 -0
  52. package/dist/services/lint/eslint-runner-support.d.ts +18 -1
  53. package/dist/services/lint/eslint-runner-support.js +35 -2
  54. package/dist/services/lint/eslint-runner-types.d.ts +21 -1
  55. package/dist/services/lint/eslint-runner.js +43 -33
  56. package/dist/services/prd/gate-evidence-derivation.d.ts +2 -4
  57. package/dist/services/prd/gate-evidence-derivation.js +3 -1
  58. package/dist/services/qa/bdd-test-style-contract.d.ts +17 -0
  59. package/dist/services/qa/bdd-test-style-contract.js +41 -0
  60. package/dist/services/qa/bdd-test-style-verifier.d.ts +9 -6
  61. package/dist/services/qa/bdd-test-style-verifier.js +24 -37
  62. package/dist/services/rd/reviewer-dispatch-policy.d.ts +18 -14
  63. package/dist/services/rd/reviewer-dispatch-policy.js +14 -11
  64. package/dist/services/release/release-state.js +20 -5
  65. package/dist/services/reviewer/model-family.js +1 -1
  66. package/dist/services/reviewer/reviewer-artifacts.d.ts +12 -0
  67. package/dist/services/reviewer/reviewer-artifacts.js +67 -0
  68. package/dist/services/reviewer/reviewer-config-write.d.ts +18 -0
  69. package/dist/services/reviewer/reviewer-config-write.js +71 -0
  70. package/dist/services/reviewer/reviewer-config.d.ts +33 -5
  71. package/dist/services/reviewer/reviewer-config.js +102 -46
  72. package/dist/services/reviewer/reviewer-envelopes.d.ts +8 -0
  73. package/dist/services/reviewer/reviewer-envelopes.js +53 -0
  74. package/dist/services/reviewer/reviewer-service.d.ts +7 -4
  75. package/dist/services/reviewer/reviewer-service.js +46 -52
  76. package/dist/services/reviewer/reviewer-types.d.ts +9 -1
  77. package/dist/services/session/getSessionDir.js +16 -7
  78. package/dist/services/web/daemon-registry.d.ts +6 -4
  79. package/dist/services/web/daemon-registry.js +92 -17
  80. package/package.json +5 -5
  81. package/schemas/reviewer-envelope.schema.json +1 -1
  82. package/skills/bee/peaks-reviewer/SKILL.md +20 -4
  83. package/skills/bee/peaks-reviewer/references/reviewer-schema.md +12 -7
  84. package/skills/bee/peaks-security-audit/SKILL.md +20 -0
  85. package/skills/peaks-code/references/step-0-8-gate.md +2 -1
@@ -41,7 +41,7 @@
41
41
  import { readFileSync } from 'node:fs';
42
42
  import { resolve } from 'node:path';
43
43
  import ts from 'typescript';
44
- import { matchesBddTriple, hasWhenOrShould } from './bdd-test-style-contract.js';
44
+ import { leadingBddComments, matchesBddTriple, hasWhenOrShould } from './bdd-test-style-contract.js';
45
45
  /** Test runners whose first string-arg is the test description. */
46
46
  const TEST_NAMES = new Set(['it', 'test']);
47
47
  /**
@@ -55,12 +55,15 @@ const TEST_NAMES = new Set(['it', 'test']);
55
55
  * here because the description itself is a literal — there is
56
56
  * no nested template literal to misread.
57
57
  * 2. The callback body (the second argument when it is an arrow /
58
- * function expression with a block) MUST have a `// given:`,
59
- * `// when:`, `// then:` triple at the top, in that order,
60
- * within the first 3 leading-comment ranges before the first
61
- * statement. The `// arrange:` / `// act:` / `// assert:` AAA
62
- * legacy is NOT accepted — the contract is given-when-then
63
- * only.
58
+ * function expression with a block) MUST start with the
59
+ * `// given:` / `// when:` / `// then:` triple, in that order. The
60
+ * unit is the leading COMMENT, not the source line: a keyword
61
+ * comment plus any hanging-indented continuation lines counts as
62
+ * one, so a wrapped `// given:` does not shift `// when:` into a
63
+ * later slot. Before any executable code the body must hold exactly
64
+ * those three comments — a fourth leading comment is refused. The
65
+ * `// arrange:` / `// act:` / `// assert:` AAA legacy is NOT
66
+ * accepted — the contract is given-when-then only.
64
67
  *
65
68
  * Returns the FIRST failure encountered (file order, then
66
69
  * top-to-bottom line order). A structured `BddStyleFail` is what the
@@ -210,41 +213,25 @@ function getCallbackBlock(call) {
210
213
  return null;
211
214
  }
212
215
  function checkBlockLeadingComments(block, sourceFile, relPath) {
213
- // TypeScript's `getLeadingCommentRanges` API is unreliable for
214
- // comment-only blocks: with `setParentNodes: true`, an empty
215
- // block (no statements, only comments) has no anchor to attach
216
- // the comments to, so the API returns zero ranges. To get a
217
- // deterministic answer, we scan the block's text directly and
218
- // pick the first three non-empty lines.
219
- //
220
- // The block's text spans `{` ... `}`. We extract the body,
221
- // split on lines, and check the first three non-empty lines for
222
- // the BDD triple. This is AST-driven (we use the block's source
223
- // range from the SourceFile, not a global regex) and survives
224
- // both empty-body and populated-body cases.
225
- const blockStart = block.getStart(sourceFile) + 1; // skip `{`
226
- const blockEnd = block.end - 1; // skip `}`
227
- const body = sourceFile.text.slice(blockStart, blockEnd);
228
- const lines = body.split(/\r?\n/);
229
- const nonEmpty = [];
230
- for (const line of lines) {
231
- if (line.trim().length === 0)
232
- continue;
233
- nonEmpty.push(line);
234
- if (nonEmpty.length === 3)
235
- break;
236
- }
237
- if (nonEmpty.length < 3 || !matchesBddTriple(nonEmpty)) {
216
+ const body = sourceFile.text.slice(block.getStart(sourceFile) + 1, block.end - 1);
217
+ // `matchesBddTriple` also refuses anything other than three comments, so
218
+ // the contract's "exactly three leading comments" needs no second count.
219
+ if (!matchesBddTriple(leadingBddComments(body))) {
238
220
  return makeMissingCommentFailure(block, sourceFile, relPath);
239
221
  }
240
222
  return null;
241
223
  }
242
224
  function makeMissingCommentFailure(block, sourceFile, relPath) {
243
- // Report the line of the opening `{` + 1 — the line that should
244
- // contain the first comment of the BDD triple. This gives the
245
- // caller a stable pointer even when the block is empty.
246
- const pos = block.getStart(sourceFile) + 1;
247
- const { line } = sourceFile.getLineAndCharacterOfPosition(pos);
225
+ // Point at the first line the author must change: the first
226
+ // non-whitespace character inside the braces (where the triple belongs),
227
+ // or just inside the braces when the block is empty. Anchoring on
228
+ // `getStart() + 1` reported the `{` — and with it the `it(` line — one
229
+ // line too early.
230
+ const bodyStart = block.getStart(sourceFile) + 1;
231
+ const bodyEnd = block.end - 1;
232
+ const firstContent = sourceFile.text.slice(bodyStart, bodyEnd).search(/\S/);
233
+ const anchor = firstContent === -1 ? bodyEnd : bodyStart + firstContent;
234
+ const { line } = sourceFile.getLineAndCharacterOfPosition(anchor);
248
235
  return {
249
236
  ok: false,
250
237
  reason: 'missing-given-when-then',
@@ -32,23 +32,26 @@
32
32
  * mechanism — an LLM reads prose, not TypeScript exports — and that is the
33
33
  * reason every export below sat at zero importers until slice F2.
34
34
  *
35
- * Pinning is half-done. The two test files this block used to cite —
36
- * element pinning) and
37
- * back-compat cases) — were both deleted in `f17aa377`. The **predicate
38
- * half** was re-pinned by `tests/unit/rd/reviewer-dispatch-policy.test.ts`
39
- * (`7191140f`, 6 cases: `RD_DEPRECATED_REVIEWERS` + `isDeprecatedReviewer`).
35
+ * Pinning is complete. The two test files this block used to cite were
36
+ * both deleted in `f17aa377`. The **predicate half**
37
+ * (`RD_DEPRECATED_REVIEWERS` + `isDeprecatedReviewer`) was re-pinned by
38
+ * `tests/unit/rd/reviewer-dispatch-policy.test.ts` (`7191140f`, 6 cases).
40
39
  * The **decision-table half** — `RD_FANOUT_REVIEWERS`' 3-element
41
40
  * membership, `reviewerListFor`, `karpathySlotIndex`,
42
- * `shouldDispatchKarpathy` — still has no pin.
41
+ * `shouldDispatchKarpathy` — is pinned by
42
+ * `tests/unit/rd/reviewer-dispatch-policy-decision-table.test.ts`,
43
+ * including the 5→3 relationship: the fanout request types are exactly
44
+ * the review request types `isFanoutTriggerType` accepts, and no
45
+ * deprecated reviewer appears in the returned list.
43
46
  *
44
47
  * `src/cli/commands/sub-agent-shared.ts` (`deprecatedReviewerWarnings`),
45
48
  * invoked from the dispatch chokepoint in
46
49
  * `src/cli/commands/dispatch-commands.ts` and pinned by
47
- * `tests/unit/cli/sub-agent-dispatch-deprecated-reviewer.test.ts`. Before
48
- * that, all 13 exports had zero importers across src/ + packages/ +
49
- * scripts/, so nothing rejected or rerouted `security-reviewer` /
50
- * `perf-baseline-reviewer` on the way in. That import is still the only
51
- * one: the other 12 exports below remain unreferenced in this repo.
50
+ * `tests/unit/cli/sub-agent-dispatch-deprecated-reviewer.test.ts`, is the
51
+ * only runtime importer. The decision-table exports are pinned by tests
52
+ * rather than imported, which is the point of the table. The three type
53
+ * aliases derived from the tuple constants are module-internal: no
54
+ * importer names them, so they are not exported.
52
55
  *
53
56
  * For `config | docs | chore` request types, the slice already skips
54
57
  * the entire fanout (SKILL.md line 132 says "Config / docs / chore: no
@@ -75,7 +78,7 @@
75
78
  * does not disagree with the prereq side about the same deprecation.
76
79
  */
77
80
  export declare const RD_REVIEW_REQUEST_TYPES: readonly ["feat", "bugfix", "refactor", "config", "docs", "chore"];
78
- export type RdReviewRequestType = (typeof RD_REVIEW_REQUEST_TYPES)[number];
81
+ type RdReviewRequestType = (typeof RD_REVIEW_REQUEST_TYPES)[number];
79
82
  /**
80
83
  * The 3-sub-agent fanout triggered at the end of RD implementation
81
84
  * (v2.12.0). In v2.11.x this was a 5-element list; the
@@ -83,7 +86,7 @@ export type RdReviewRequestType = (typeof RD_REVIEW_REQUEST_TYPES)[number];
83
86
  * the standalone `peaks-security-audit` / `peaks-perf-audit` skills.
84
87
  */
85
88
  export declare const RD_FANOUT_REVIEWERS: readonly ["code-reviewer", "qa-test-cases-writer", "karpathy-reviewer"];
86
- export type RdFanoutReviewer = (typeof RD_FANOUT_REVIEWERS)[number];
89
+ type RdFanoutReviewer = (typeof RD_FANOUT_REVIEWERS)[number];
87
90
  /**
88
91
  * Reviewer roles removed from the v2.11.x 5-way fanout. Exposed as a
89
92
  * separate constant so:
@@ -101,7 +104,7 @@ export declare const RD_DEPRECATED_REVIEWERS: readonly ["security-reviewer", "pe
101
104
  export type RdDeprecatedReviewer = (typeof RD_DEPRECATED_REVIEWERS)[number];
102
105
  /** Subset of request types that fire the 3-way fanout. */
103
106
  export declare const RD_FANOUT_REQUEST_TYPES: readonly ["feat", "bugfix", "refactor"];
104
- export type RdFanoutRequestType = (typeof RD_FANOUT_REQUEST_TYPES)[number];
107
+ type RdFanoutRequestType = (typeof RD_FANOUT_REQUEST_TYPES)[number];
105
108
  /**
106
109
  * True iff the karpathy-reviewer sub-agent should be dispatched for
107
110
  * this request type. For `config | docs | chore` the entire 3-way
@@ -144,3 +147,4 @@ export declare function karpathySlotIndex(type: RdReviewRequestType): number;
144
147
  * list.
145
148
  */
146
149
  export declare function isDeprecatedReviewer(name: string): name is RdDeprecatedReviewer;
150
+ export {};
@@ -32,23 +32,26 @@
32
32
  * mechanism — an LLM reads prose, not TypeScript exports — and that is the
33
33
  * reason every export below sat at zero importers until slice F2.
34
34
  *
35
- * Pinning is half-done. The two test files this block used to cite —
36
- * element pinning) and
37
- * back-compat cases) — were both deleted in `f17aa377`. The **predicate
38
- * half** was re-pinned by `tests/unit/rd/reviewer-dispatch-policy.test.ts`
39
- * (`7191140f`, 6 cases: `RD_DEPRECATED_REVIEWERS` + `isDeprecatedReviewer`).
35
+ * Pinning is complete. The two test files this block used to cite were
36
+ * both deleted in `f17aa377`. The **predicate half**
37
+ * (`RD_DEPRECATED_REVIEWERS` + `isDeprecatedReviewer`) was re-pinned by
38
+ * `tests/unit/rd/reviewer-dispatch-policy.test.ts` (`7191140f`, 6 cases).
40
39
  * The **decision-table half** — `RD_FANOUT_REVIEWERS`' 3-element
41
40
  * membership, `reviewerListFor`, `karpathySlotIndex`,
42
- * `shouldDispatchKarpathy` — still has no pin.
41
+ * `shouldDispatchKarpathy` — is pinned by
42
+ * `tests/unit/rd/reviewer-dispatch-policy-decision-table.test.ts`,
43
+ * including the 5→3 relationship: the fanout request types are exactly
44
+ * the review request types `isFanoutTriggerType` accepts, and no
45
+ * deprecated reviewer appears in the returned list.
43
46
  *
44
47
  * `src/cli/commands/sub-agent-shared.ts` (`deprecatedReviewerWarnings`),
45
48
  * invoked from the dispatch chokepoint in
46
49
  * `src/cli/commands/dispatch-commands.ts` and pinned by
47
- * `tests/unit/cli/sub-agent-dispatch-deprecated-reviewer.test.ts`. Before
48
- * that, all 13 exports had zero importers across src/ + packages/ +
49
- * scripts/, so nothing rejected or rerouted `security-reviewer` /
50
- * `perf-baseline-reviewer` on the way in. That import is still the only
51
- * one: the other 12 exports below remain unreferenced in this repo.
50
+ * `tests/unit/cli/sub-agent-dispatch-deprecated-reviewer.test.ts`, is the
51
+ * only runtime importer. The decision-table exports are pinned by tests
52
+ * rather than imported, which is the point of the table. The three type
53
+ * aliases derived from the tuple constants are module-internal: no
54
+ * importer names them, so they are not exported.
52
55
  *
53
56
  * For `config | docs | chore` request types, the slice already skips
54
57
  * the entire fanout (SKILL.md line 132 says "Config / docs / chore: no
@@ -50,6 +50,14 @@ const STATE_FILE = '.peaks/release-state.json';
50
50
  export function getReleaseStatePath(projectRoot) {
51
51
  return resolve(projectRoot, STATE_FILE);
52
52
  }
53
+ /** A persisted record is only as trustworthy as its stage: `currentStage` is
54
+ * typed `ReleaseStage`, but it comes out of a JSON file nothing validated. */
55
+ function hasValidStage(value) {
56
+ if (typeof value !== 'object' || value === null)
57
+ return false;
58
+ const stage = value.currentStage;
59
+ return typeof stage === 'string' && isReleaseStage(stage);
60
+ }
53
61
  export function readReleaseState(projectRoot) {
54
62
  const path = getReleaseStatePath(projectRoot);
55
63
  if (!existsSync(path))
@@ -59,11 +67,18 @@ export function readReleaseState(projectRoot) {
59
67
  const parsed = JSON.parse(raw);
60
68
  if (parsed.version !== 1)
61
69
  return EMPTY_RELEASE_STATE;
62
- return {
63
- version: 1,
64
- active: parsed.active ?? null,
65
- history: Array.isArray(parsed.history) ? parsed.history : []
66
- };
70
+ const active = parsed.active ?? null;
71
+ const history = Array.isArray(parsed.history) ? parsed.history : [];
72
+ // Fail closed, exactly as the version check and the catch above do: a state
73
+ // file naming a stage this table no longer has (e.g. the dropped
74
+ // 'hotfixed') is a file this build cannot interpret. `transitionRelease`
75
+ // would otherwise throw on it (its error message indexes the stage table),
76
+ // so the reader is where an unknown stage has to stop.
77
+ if (active !== null && !hasValidStage(active))
78
+ return EMPTY_RELEASE_STATE;
79
+ if (!history.every(hasValidStage))
80
+ return EMPTY_RELEASE_STATE;
81
+ return { version: 1, active, history };
67
82
  }
68
83
  catch {
69
84
  return EMPTY_RELEASE_STATE;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * model-family.ts — derive `modelFamily` from a `modelId` for the G4
3
- * `third-party-review.json.modelFamily !== karpathy-review.json.modelFamily`,
3
+ * `third-party-review-<rid>.json.modelFamily !== karpathy-review.json.modelFamily`,
4
4
  * so the family bucket must be stable, provider-distinguishing, and
5
5
  * version-tolerant (e.g. `claude-opus-4-8` and `claude-haiku-4-5` both
6
6
  * bucket to `claude`, while `gpt-4o-mini` and `gpt-3.5-turbo` bucket
@@ -0,0 +1,12 @@
1
+ import type { ReviewerEnvelope } from './reviewer-types.js';
2
+ export type ReviewerArtifactPaths = {
3
+ markdown: string;
4
+ json: string;
5
+ };
6
+ export declare function renderReviewerMarkdown(rid: string, envelope: ReviewerEnvelope): string;
7
+ export declare function writeReviewerArtifacts(input: {
8
+ projectRoot: string;
9
+ sessionId: string;
10
+ rid: string;
11
+ envelope: ReviewerEnvelope;
12
+ }): ReviewerArtifactPaths;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * reviewer-artifacts.ts — the producer side of the G4 reviewer: writes
3
+ * `rd/third-party-review-<rid>.md` and `rd/third-party-review-<rid>.json` under
4
+ * the session's `.peaks/_runtime/<sessionId>/rd/`.
5
+ *
6
+ * Only a real verdict reaches here. The caller must not call this with a
7
+ * skip envelope (backlog §7.10 ④): a skip stays a skip.
8
+ */
9
+ import { mkdirSync, writeFileSync } from 'node:fs';
10
+ import { join } from 'node:path';
11
+ import { isUnsafePathInput } from '../../shared/path-safety.js';
12
+ import { REQUEST_ID_PATTERN } from '../artifacts/request-artifact-service.js';
13
+ /** One table cell: newlines and pipes from the model cannot break the table. */
14
+ function cell(value) {
15
+ return value.replace(/\r?\n/g, ' ').replace(/\|/g, '\\|');
16
+ }
17
+ export function renderReviewerMarkdown(rid, envelope) {
18
+ const violations = envelope.violations.length === 0
19
+ ? 'None.'
20
+ : envelope.violations
21
+ .map((v) => `- \`${cell(v.kind)}\` — ${cell(v.file)}:${String(v.line)} — ${cell(v.hint)}`)
22
+ .join('\n');
23
+ return [
24
+ `# third-party-review — ${cell(rid)}`,
25
+ '',
26
+ 'Schema-validated ReviewerEnvelope produced by `peaks reviewer run`.',
27
+ `The JSON sibling \`third-party-review-${cell(rid)}.json\` carries the same envelope.`,
28
+ '',
29
+ '| Field | Value |',
30
+ '| --- | --- |',
31
+ `| reviewerId | ${cell(envelope.reviewerId)} |`,
32
+ `| modelId | ${cell(envelope.modelId)} |`,
33
+ `| modelFamily | ${cell(envelope.modelFamily)} |`,
34
+ `| passed | ${String(envelope.passed)} |`,
35
+ `| gateAction | ${cell(envelope.gateAction)} |`,
36
+ `| reason | ${cell(envelope.reason)} |`,
37
+ '',
38
+ '## Violations',
39
+ '',
40
+ violations,
41
+ ''
42
+ ].join('\n');
43
+ }
44
+ export function writeReviewerArtifacts(input) {
45
+ // `isUnsafePathInput` is a traversal guard, not a single-segment guard: it
46
+ // admits `a/b`. The session id is ONE directory name under `_runtime/`, so
47
+ // the separator axes are refused here as well.
48
+ if (isUnsafePathInput(input.sessionId) ||
49
+ input.sessionId.includes('/') ||
50
+ input.sessionId.includes('\\')) {
51
+ throw new Error(`Invalid session id: ${input.sessionId} (must be a single path segment)`);
52
+ }
53
+ // The rid becomes a filename below, so the repo's own request-id guard runs
54
+ // before the first mkdir — a `..` segment must not reach `join`.
55
+ if (!REQUEST_ID_PATTERN.test(input.rid)) {
56
+ throw new Error(`Invalid request id: ${input.rid} (expected letters, digits, dots, underscores, or dashes)`);
57
+ }
58
+ const dir = join(input.projectRoot, '.peaks', '_runtime', input.sessionId, 'rd');
59
+ mkdirSync(dir, { recursive: true });
60
+ const paths = {
61
+ markdown: join(dir, `third-party-review-${input.rid}.md`),
62
+ json: join(dir, `third-party-review-${input.rid}.json`)
63
+ };
64
+ writeFileSync(paths.markdown, renderReviewerMarkdown(input.rid, input.envelope), 'utf8');
65
+ writeFileSync(paths.json, JSON.stringify(input.envelope, null, 2), 'utf8');
66
+ return paths;
67
+ }
@@ -0,0 +1,18 @@
1
+ import { type ReviewerConfig, type ReviewerProviderConfig } from './reviewer-config.js';
2
+ /** Providers `reviewer-service.ts` can actually dispatch to. */
3
+ export declare const DISPATCHABLE_PROVIDER_NAMES: ReadonlyArray<string>;
4
+ export type ReviewerConfigWriteResult = {
5
+ ok: true;
6
+ path: string;
7
+ } | {
8
+ ok: false;
9
+ reason: 'unreadable-config';
10
+ message: string;
11
+ };
12
+ /** Null when valid; otherwise the reason the section cannot be written. */
13
+ export declare function validateReviewerSection(config: ReviewerConfig): string | null;
14
+ export declare function writeReviewerConfig(config: ReviewerConfig, options?: {
15
+ path?: string;
16
+ }): ReviewerConfigWriteResult;
17
+ /** `name:model`; the first colon splits, so `llama3.2:8b` survives. */
18
+ export declare function parseProviderSpec(spec: string): ReviewerProviderConfig | null;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * reviewer-config-write.ts — write the `reviewer` section to
3
+ * `~/.peaks/config.json` on the user's behalf (backlog §7.10 ①).
4
+ *
5
+ * The LLM runs the CLI; the user never hand-authors JSON. The writer
6
+ * merges into the existing file so unrelated keys survive, and it refuses
7
+ * to overwrite a file it cannot parse rather than clobbering it.
8
+ */
9
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
10
+ import { dirname } from 'node:path';
11
+ import { defaultReviewerConfigPath } from './reviewer-config.js';
12
+ /** Providers `reviewer-service.ts` can actually dispatch to. */
13
+ export const DISPATCHABLE_PROVIDER_NAMES = ['ollama', 'anthropic', 'openai'];
14
+ function isRecord(value) {
15
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
16
+ }
17
+ /** Null when valid; otherwise the reason the section cannot be written. */
18
+ export function validateReviewerSection(config) {
19
+ if (config.providers.length < 2) {
20
+ return `at least 2 providers are required (got ${config.providers.length})`;
21
+ }
22
+ for (const provider of config.providers) {
23
+ if (!DISPATCHABLE_PROVIDER_NAMES.includes(provider.name)) {
24
+ return `unsupported provider "${provider.name}" (accepted: ${DISPATCHABLE_PROVIDER_NAMES.join(', ')})`;
25
+ }
26
+ if (provider.model.trim().length === 0) {
27
+ return `provider "${provider.name}" has an empty model id`;
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+ export function writeReviewerConfig(config, options = {}) {
33
+ const path = options.path ?? defaultReviewerConfigPath();
34
+ let existing = {};
35
+ if (existsSync(path)) {
36
+ let parsed;
37
+ try {
38
+ parsed = JSON.parse(readFileSync(path, 'utf8'));
39
+ }
40
+ catch {
41
+ return {
42
+ ok: false,
43
+ reason: 'unreadable-config',
44
+ message: `${path} is not valid JSON; refusing to overwrite it`
45
+ };
46
+ }
47
+ if (!isRecord(parsed)) {
48
+ return {
49
+ ok: false,
50
+ reason: 'unreadable-config',
51
+ message: `${path} does not contain a JSON object; refusing to overwrite it`
52
+ };
53
+ }
54
+ existing = parsed;
55
+ }
56
+ const next = { ...existing, reviewer: config };
57
+ mkdirSync(dirname(path), { recursive: true });
58
+ writeFileSync(path, JSON.stringify(next, null, 2), 'utf8');
59
+ return { ok: true, path };
60
+ }
61
+ /** `name:model`; the first colon splits, so `llama3.2:8b` survives. */
62
+ export function parseProviderSpec(spec) {
63
+ const separator = spec.indexOf(':');
64
+ if (separator <= 0)
65
+ return null;
66
+ const name = spec.slice(0, separator).trim();
67
+ const model = spec.slice(separator + 1).trim();
68
+ if (name.length === 0 || model.length === 0)
69
+ return null;
70
+ return { name, model };
71
+ }
@@ -1,6 +1,7 @@
1
1
  export type ReviewerProviderName = 'ollama' | 'anthropic' | 'openai' | 'bedrock' | 'azure';
2
2
  export type ReviewerProviderConfig = {
3
- name: ReviewerProviderName | string;
3
+ /** A {@link ReviewerProviderName}, or any future provider name. */
4
+ name: string;
4
5
  model: string;
5
6
  endpoint?: string | undefined;
6
7
  apiKeyEnv?: string | undefined;
@@ -15,19 +16,46 @@ export type ReviewerConfig = {
15
16
  fallbackOnError: ReviewerFallbackMode;
16
17
  schemaPath: string;
17
18
  };
19
+ /** A4.1 — the reviewer needs at least two provider families to be usable. */
20
+ export declare const MIN_REVIEWER_PROVIDERS = 2;
21
+ /**
22
+ * Three states, so `peaks reviewer status` can tell "nothing configured"
23
+ * apart from "configured, but not enough providers" (backlog §7.10 ③).
24
+ * `providerCount` is the number of VALID entries after parsing, which is
25
+ * what the >=2 requirement is measured on.
26
+ */
18
27
  export type ReviewerConfigStatus = {
19
28
  ok: true;
20
29
  config: ReviewerConfig;
21
30
  } | {
22
31
  ok: false;
23
- reason: 'no-reviewer-config';
32
+ reason: 'no-reviewer-config' | 'insufficient-providers';
33
+ providerCount: number;
34
+ requiredProviders: number;
24
35
  };
25
36
  export declare function defaultReviewerConfigPath(): string;
37
+ /** Where a resolved ReviewerEnvelope schema came from. */
38
+ export type ReviewerSchemaSource = 'absolute' | 'project' | 'package';
39
+ export type ReviewerSchemaResolution = {
40
+ ok: true;
41
+ path: string;
42
+ source: ReviewerSchemaSource;
43
+ } | {
44
+ ok: false;
45
+ searched: string[];
46
+ };
47
+ /**
48
+ * Resolve the configured ReviewerEnvelope schema: an absolute path as-is,
49
+ * else the project-root copy (a project may override), else the copy bundled
50
+ * with the peaks-loop package — a consumer project does NOT ship `schemas/`,
51
+ * so the packaged copy is what makes the default path work there. When
52
+ * nothing resolves, every candidate is returned for the refusal message.
53
+ */
54
+ export declare function resolveReviewerSchema(projectRoot: string, schemaPath: string): ReviewerSchemaResolution;
26
55
  /**
27
56
  * Read + parse `~/.peaks/config.json` (or override path) and return the
28
- * `reviewer` section if present. NEVER throws on missing file — returns
29
- * `{ ok: false, reason: 'no-reviewer-config' }` instead so the CLI can
30
- * record the skip reason in the envelope.
57
+ * `reviewer` section if present. NEVER throws on missing file — the CLI
58
+ * records the skip reason in the envelope instead.
31
59
  */
32
60
  export declare function loadReviewerConfig(options?: {
33
61
  path?: string;