pi-spine 2.27.0 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/bin/spine-batch.mjs +46 -4
  2. package/bin/spine-tasks.mjs +1 -0
  3. package/bin/spine-worker-runner.mjs +17 -3
  4. package/package.json +1 -1
  5. package/skills/create-spine-tasks/SKILL.md +60 -33
  6. package/skills/create-spine-tasks/references/authoring-evidence.md +58 -0
  7. package/skills/create-spine-tasks/references/contract-template.md +52 -7
  8. package/skills/create-spine-tasks/references/prompt-template.md +77 -8
  9. package/skills/spine-release-operator/SKILL.md +43 -52
  10. package/skills/spine-release-operator/references/issue-intake-checklist.md +3 -1
  11. package/skills/spine-release-operator/references/pi-async-orchestration.md +13 -9
  12. package/skills/spine-release-operator/references/post-integrate-regression-gate.md +8 -1
  13. package/skills/spine-release-operator/references/publish-recovery.md +62 -0
  14. package/src/batch/contract-task-start.mjs +23 -1
  15. package/src/batch/diagnosis-alternatives.mjs +16 -1
  16. package/src/batch/diagnosis-handoff-packet.mjs +18 -0
  17. package/src/batch/diagnosis-pending-lane.mjs +18 -0
  18. package/src/batch/diagnosis-review-infra.mjs +144 -0
  19. package/src/batch/diagnosis-suggested-command.mjs +9 -0
  20. package/src/batch/diagnosis.mjs +19 -20
  21. package/src/batch/engine-lanes/merge.mjs +0 -8
  22. package/src/batch/engine-lanes/quota-fallback-run.mjs +11 -0
  23. package/src/batch/engine-lanes/quota-fallback-state.mjs +155 -8
  24. package/src/batch/engine-lanes/review-code.mjs +20 -0
  25. package/src/batch/engine-lanes/review-final.mjs +10 -2
  26. package/src/batch/engine-lanes/review-poll.mjs +37 -1
  27. package/src/batch/engine-lanes/task-agent-profile.mjs +324 -0
  28. package/src/batch/engine-lanes.mjs +18 -18
  29. package/src/batch/gate-posture-approve.mjs +154 -15
  30. package/src/batch/integrate-path-delete.mjs +85 -0
  31. package/src/batch/integrate-worktree.mjs +20 -27
  32. package/src/batch/journal.mjs +5 -3
  33. package/src/batch/metrics-rollup.mjs +98 -4
  34. package/src/batch/metrics.mjs +134 -9
  35. package/src/batch/provider-quota.mjs +156 -7
  36. package/src/batch/quota-fallback.mjs +87 -6
  37. package/src/batch/reconcile-diagnosis.mjs +24 -77
  38. package/src/batch/resume-lane-reviews.mjs +11 -10
  39. package/src/batch/retry-profile.mjs +77 -0
  40. package/src/batch/retry.mjs +32 -1
  41. package/src/batch/review-artifacts.mjs +3 -2
  42. package/src/batch/review-level-effective.mjs +19 -0
  43. package/src/batch/review-spawn.mjs +12 -1
  44. package/src/batch/review-step-run.mjs +18 -2
  45. package/src/batch/review-step.mjs +1 -0
  46. package/src/batch/reviewer-provider-error.mjs +153 -0
  47. package/src/batch/worker-heartbeat.mjs +10 -2
  48. package/src/batch/worker-host.mjs +1 -1
  49. package/src/batch/worker-prompt.mjs +9 -7
  50. package/src/cli/deps.mjs +3 -2
  51. package/src/config/agent-model-resolve.mjs +144 -8
  52. package/src/config/cursor-rules/discover.mjs +38 -1
  53. package/src/config/model-family.mjs +60 -0
  54. package/src/config/preflight/discovery.mjs +1 -0
  55. package/src/config/settings-fields.mjs +11 -0
  56. package/src/config/spine-config-schema.mjs +87 -0
  57. package/src/doctor/agent-model-inherit.mjs +78 -1
  58. package/src/doctor/pi-extension-hooks.mjs +322 -0
  59. package/src/doctor/run-doctor-checks.mjs +18 -2
  60. package/src/metrics/quota-cli.mjs +16 -0
  61. package/src/metrics/quota-probes.mjs +228 -31
  62. package/src/metrics/quota-snapshot.mjs +21 -2
  63. package/src/planner/graph.mjs +7 -5
  64. package/src/planner/pending.mjs +2 -2
  65. package/src/planner/scope.mjs +3 -3
  66. package/src/tasks/packet/parse-prompt.mjs +47 -0
  67. package/src/tasks/packet/validate-prompt.mjs +167 -2
  68. package/src/tasks/validate-contract-warn.mjs +16 -0
  69. package/templates/agents/reviewer.md +3 -1
  70. package/templates/agents/worker.md +15 -19
  71. package/templates/spine-config.json +1 -1
@@ -3,13 +3,17 @@
3
3
  * Agent model/thinking pin resolution for reviewer spawns (issue #53 / SP-369).
4
4
  */
5
5
 
6
+ import { isSameModelFamily } from "./model-family.mjs";
7
+
8
+ /** @type {readonly ("plan"|"code"|"final")[]} */
9
+ const REVIEW_TYPES = ["plan", "code", "final"];
10
+
6
11
  /**
7
- * @param {object} config
12
+ * @param {unknown} reviewer A reviewer block (`agents.reviewer` or `profile.reviewer`).
8
13
  * @param {"plan"|"code"|"final"} reviewType
9
- * @returns {string|null} Pin value or null to omit `--model`
14
+ * @returns {string|null}
10
15
  */
11
- export function resolveReviewerModelPin(config, reviewType) {
12
- const reviewer = config?.agents?.reviewer;
16
+ function pickModelPin(reviewer, reviewType) {
13
17
  if (!reviewer) return null;
14
18
 
15
19
  const typePin = reviewer[reviewType]?.model;
@@ -26,12 +30,11 @@ export function resolveReviewerModelPin(config, reviewType) {
26
30
  }
27
31
 
28
32
  /**
29
- * @param {object} config
33
+ * @param {unknown} reviewer A reviewer block (`agents.reviewer` or `profile.reviewer`).
30
34
  * @param {"plan"|"code"|"final"} reviewType
31
- * @returns {string|null} Pin value or null to omit `--thinking`
35
+ * @returns {string|null}
32
36
  */
33
- export function resolveReviewerThinkingPin(config, reviewType) {
34
- const reviewer = config?.agents?.reviewer;
37
+ function pickThinkingPin(reviewer, reviewType) {
35
38
  if (!reviewer) return null;
36
39
 
37
40
  const typePin = reviewer[reviewType]?.thinking;
@@ -47,3 +50,136 @@ export function resolveReviewerThinkingPin(config, reviewType) {
47
50
 
48
51
  return null;
49
52
  }
53
+
54
+ /**
55
+ * @param {object} config
56
+ * @param {"plan"|"code"|"final"} reviewType
57
+ * @returns {string|null} Pin value or null to omit `--model`
58
+ */
59
+ export function resolveReviewerModelPin(config, reviewType) {
60
+ return pickModelPin(config?.agents?.reviewer, reviewType);
61
+ }
62
+
63
+ /**
64
+ * @param {object} config
65
+ * @param {"plan"|"code"|"final"} reviewType
66
+ * @returns {string|null} Pin value or null to omit `--thinking`
67
+ */
68
+ export function resolveReviewerThinkingPin(config, reviewType) {
69
+ return pickThinkingPin(config?.agents?.reviewer, reviewType);
70
+ }
71
+
72
+ /**
73
+ * @param {unknown} value
74
+ * @returns {string|null} Trimmed non-empty string, else null
75
+ */
76
+ function nonEmptyName(value) {
77
+ if (typeof value !== "string") return null;
78
+ const trimmed = value.trim();
79
+ return trimmed === "" ? null : trimmed;
80
+ }
81
+
82
+ /**
83
+ * Resolve the effective reviewer (model + thinking) per review type (SP-832 / #355).
84
+ *
85
+ * Candidate order (first cross-family usable candidate wins, per review type):
86
+ * 1. `promptReviewerProfile`
87
+ * 2. `agents.profiles[workerProfile].reviewerProfile`
88
+ * 3. `agents.reviewerProfile`
89
+ * 4. the already-merged `agents.reviewer` block
90
+ *
91
+ * A named profile that does not exist is reported in `blocked` (`unknown_reviewer_profile`);
92
+ * one without a `reviewer` block is skipped with a warning. A candidate whose model shares a
93
+ * family with `workerModel` is skipped for that review type; when none is cross-family the
94
+ * type is reported in `blocked` (`same_model_family`) and the last candidate's pins are kept.
95
+ *
96
+ * Pure: no I/O, never mutates `config`.
97
+ *
98
+ * @param {object} config Effective config (active profile already merged into `agents.reviewer`).
99
+ * @param {object} [options]
100
+ * @param {string|null} [options.promptReviewerProfile]
101
+ * @param {string|null} [options.workerProfile]
102
+ * @param {string|null} [options.workerModel]
103
+ * @returns {{
104
+ * plan: { model: string|null, thinking: string|null, profile: string|null, source: string },
105
+ * code: { model: string|null, thinking: string|null, profile: string|null, source: string },
106
+ * final: { model: string|null, thinking: string|null, profile: string|null, source: string },
107
+ * warnings: string[],
108
+ * blocked: Array<{ reviewType: "plan"|"code"|"final", reason: string }>,
109
+ * }}
110
+ */
111
+ export function resolveEffectiveReviewer(
112
+ config,
113
+ { promptReviewerProfile = null, workerProfile = null, workerModel = null } = {},
114
+ ) {
115
+ const agents = config?.agents ?? {};
116
+ const profiles = agents.profiles && typeof agents.profiles === "object" ? agents.profiles : {};
117
+ const workerProfileName = nonEmptyName(workerProfile);
118
+ /** @type {string[]} */
119
+ const warnings = [];
120
+ /** @type {Array<{ reviewType: "plan"|"code"|"final", reason: string }>} */
121
+ const blocked = [];
122
+
123
+ /** @type {Array<{ profile: string|null, source: string, reviewer: unknown }>} */
124
+ const candidates = [];
125
+ /** @type {Set<string>} */
126
+ const seenNames = new Set();
127
+ /** @type {Array<[string|null, string]>} */
128
+ const named = [
129
+ [nonEmptyName(promptReviewerProfile), "prompt.reviewerProfile"],
130
+ [
131
+ workerProfileName ? nonEmptyName(profiles[workerProfileName]?.reviewerProfile) : null,
132
+ `agents.profiles.${workerProfileName}.reviewerProfile`,
133
+ ],
134
+ [nonEmptyName(agents.reviewerProfile), "agents.reviewerProfile"],
135
+ ];
136
+ for (const [name, source] of named) {
137
+ if (name === null || seenNames.has(name)) continue;
138
+ seenNames.add(name);
139
+ const profile = Object.hasOwn(profiles, name) ? profiles[name] : undefined;
140
+ if (!profile || typeof profile !== "object") {
141
+ for (const reviewType of REVIEW_TYPES) {
142
+ blocked.push({ reviewType, reason: "unknown_reviewer_profile" });
143
+ }
144
+ warnings.push(`reviewer profile "${name}" (${source}) is not defined in agents.profiles`);
145
+ continue;
146
+ }
147
+ if (!profile.reviewer || typeof profile.reviewer !== "object") {
148
+ warnings.push(`reviewer profile "${name}" has no reviewer block; falling back`);
149
+ continue;
150
+ }
151
+ candidates.push({ profile: name, source, reviewer: profile.reviewer });
152
+ }
153
+ candidates.push({ profile: null, source: "agents.reviewer", reviewer: agents.reviewer });
154
+
155
+ /** @type {Record<string, { model: string|null, thinking: string|null, profile: string|null, source: string }>} */
156
+ const resolved = {};
157
+ for (const reviewType of REVIEW_TYPES) {
158
+ let chosen = null;
159
+ let sameFamily = false;
160
+ for (const candidate of candidates) {
161
+ const model = pickModelPin(candidate.reviewer, reviewType);
162
+ chosen = {
163
+ model,
164
+ thinking: pickThinkingPin(candidate.reviewer, reviewType),
165
+ profile: candidate.profile,
166
+ source: candidate.source,
167
+ };
168
+ sameFamily = isSameModelFamily(model, workerModel);
169
+ if (!sameFamily) break;
170
+ warnings.push(
171
+ `${reviewType} reviewer "${model}" (${candidate.source}) shares a model family with worker "${workerModel}"; skipping`,
172
+ );
173
+ }
174
+ if (sameFamily) blocked.push({ reviewType, reason: "same_model_family" });
175
+ resolved[reviewType] = chosen;
176
+ }
177
+
178
+ return {
179
+ plan: resolved.plan,
180
+ code: resolved.code,
181
+ final: resolved.final,
182
+ warnings: [...new Set(warnings)],
183
+ blocked,
184
+ };
185
+ }
@@ -181,6 +181,31 @@ export function writeRulesManifestAtomic(projectRoot, manifest) {
181
181
  return manifestPath;
182
182
  }
183
183
 
184
+ /**
185
+ * Read an existing rules manifest for fingerprint comparison. Returns null when
186
+ * the file is missing, unreadable, or not a parseable manifest — the caller then
187
+ * falls through to a normal write.
188
+ *
189
+ * @param {string} manifestPath
190
+ * @returns {CursorRulesManifest | null}
191
+ */
192
+ function loadExistingManifestForFingerprint(manifestPath) {
193
+ try {
194
+ const parsed = parseRulesManifestJson(fs.readFileSync(manifestPath, "utf-8"));
195
+ if (
196
+ !parsed.ok ||
197
+ !Array.isArray(parsed.manifest?.rules) ||
198
+ !Array.isArray(parsed.manifest?.excluded) ||
199
+ typeof parsed.manifest.generatedAt !== "string"
200
+ ) {
201
+ return null;
202
+ }
203
+ return parsed.manifest;
204
+ } catch {
205
+ return null;
206
+ }
207
+ }
208
+
184
209
  /**
185
210
  * @param {object} params
186
211
  * @param {string} params.projectRoot
@@ -256,7 +281,19 @@ export function discoverCursorRules({ projectRoot, profile, writeManifest = true
256
281
  /** @type {DiscoverCursorRulesResult} */
257
282
  const result = { ok: true, manifest };
258
283
  if (writeManifest) {
259
- result.manifestPath = writeRulesManifestAtomic(projectRoot, manifest);
284
+ const manifestPath = path.join(projectRoot, RULES_MANIFEST_REL_PATH);
285
+ const existing = loadExistingManifestForFingerprint(manifestPath);
286
+ if (
287
+ existing &&
288
+ fingerprintRulesManifest(existing) === fingerprintRulesManifest(manifest)
289
+ ) {
290
+ // Unchanged rules set: skip the write and keep the existing `generatedAt`
291
+ // so `spine rules sync` is idempotent (#315).
292
+ result.manifest = { ...manifest, generatedAt: existing.generatedAt };
293
+ result.manifestPath = manifestPath;
294
+ } else {
295
+ result.manifestPath = writeRulesManifestAtomic(projectRoot, manifest);
296
+ }
260
297
  }
261
298
  return result;
262
299
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Model family classification for reviewer/worker independence checks (SP-832 / #355).
3
+ *
4
+ * Families are coarser than providers (`cursor/gemini-3.1-pro` and `google/gemini-2.5-pro`
5
+ * are both "gemini"). Do not reuse `resolvePoolId` from quota-snapshot — that is provider-keyed.
6
+ */
7
+
8
+ /** @typedef {"gemini"|"claude"|"glm"|"kimi"|"gpt"|"qwen"|"unknown"} ModelFamily */
9
+
10
+ /** @type {ReadonlyArray<readonly [RegExp, ModelFamily]>} */
11
+ const NAME_FAMILY_RULES = Object.freeze([
12
+ [/^gemini/, "gemini"],
13
+ [/^claude/, "claude"],
14
+ [/^glm/, "glm"],
15
+ [/^kimi/, "kimi"],
16
+ [/^k\d/, "kimi"],
17
+ [/^gpt/, "gpt"],
18
+ [/^o\d/, "gpt"],
19
+ [/^qwen/, "qwen"],
20
+ ]);
21
+
22
+ /** @type {Readonly<Record<string, ModelFamily>>} */
23
+ const PROVIDER_FAMILY = Object.freeze({
24
+ google: "gemini",
25
+ anthropic: "claude",
26
+ zai: "glm",
27
+ "kimi-coding": "kimi",
28
+ });
29
+
30
+ /**
31
+ * @param {unknown} model Model id such as `google/gemini-2.5-pro`, `inherit`, or null.
32
+ * @returns {ModelFamily}
33
+ */
34
+ export function resolveModelFamily(model) {
35
+ if (typeof model !== "string") return "unknown";
36
+ const normalized = model.trim().toLowerCase();
37
+ if (normalized === "") return "unknown";
38
+
39
+ const slash = normalized.indexOf("/");
40
+ const provider = slash === -1 ? "" : normalized.slice(0, slash);
41
+ const name = normalized.slice(normalized.lastIndexOf("/") + 1);
42
+
43
+ for (const [pattern, family] of NAME_FAMILY_RULES) {
44
+ if (pattern.test(name)) return family;
45
+ }
46
+ return PROVIDER_FAMILY[provider] ?? "unknown";
47
+ }
48
+
49
+ /**
50
+ * True only when both models resolve to the same known family.
51
+ *
52
+ * @param {unknown} a
53
+ * @param {unknown} b
54
+ * @returns {boolean}
55
+ */
56
+ export function isSameModelFamily(a, b) {
57
+ const familyA = resolveModelFamily(a);
58
+ if (familyA === "unknown") return false;
59
+ return familyA === resolveModelFamily(b);
60
+ }
@@ -311,6 +311,7 @@ export function checkTasksValidate(ctx) {
311
311
  const validation = validatePrompt(promptMarkdown, {
312
312
  taskId: discoveredTask.taskId,
313
313
  contract: config.contract,
314
+ agents: config.agents,
314
315
  });
315
316
  if (!validation.ok) {
316
317
  failures.push(
@@ -86,6 +86,11 @@ export const SETTINGS_FIELDS = Object.freeze([
86
86
  type: "enum",
87
87
  enum: ["off", "low", "medium", "high", "inherit"],
88
88
  },
89
+ {
90
+ path: "agents.reviewer.loadUserExtensions",
91
+ label: "Reviewer loads user pi extensions",
92
+ type: "boolean",
93
+ },
89
94
  {
90
95
  path: "agents.reviewer.plan.model",
91
96
  label: "Plan reviewer model",
@@ -157,6 +162,12 @@ export const SETTINGS_FIELDS = Object.freeze([
157
162
  type: "string",
158
163
  optional: true,
159
164
  },
165
+ {
166
+ path: "agents.reviewerProfile",
167
+ label: "Reviewer agent model profile (cross-family review)",
168
+ type: "string",
169
+ optional: true,
170
+ },
160
171
  {
161
172
  path: "dashboard.port",
162
173
  label: "Dashboard port",
@@ -235,6 +235,31 @@ function validateAgentSectionModelTypes(agents, label) {
235
235
  return null;
236
236
  }
237
237
 
238
+ /**
239
+ * SP-819 / #334: type-check `reviewer.loadUserExtensions` (boolean, default false) wherever
240
+ * a reviewer section appears: the base `agents.reviewer` and any
241
+ * `agents.profiles.<name>.reviewer`. Absent values are valid (defaults to false).
242
+ *
243
+ * @param {any} reviewer A reviewer-shaped section (may be undefined or a non-object).
244
+ * @param {string} label Dotted path used in the error message.
245
+ * @param {string} suggestedCommand Repair hint shown to the operator.
246
+ * @returns {null | { code: string; message: string; suggestedCommand: string }}
247
+ */
248
+ function validateReviewerLoadUserExtensions(reviewer, label, suggestedCommand) {
249
+ if (
250
+ isPlainObject(reviewer) &&
251
+ reviewer.loadUserExtensions != null &&
252
+ typeof reviewer.loadUserExtensions !== "boolean"
253
+ ) {
254
+ return {
255
+ code: "CONFIG_AGENT_PROFILE_INVALID",
256
+ message: `${label}.loadUserExtensions must be a boolean when set`,
257
+ suggestedCommand,
258
+ };
259
+ }
260
+ return null;
261
+ }
262
+
238
263
  /**
239
264
  * Validate `agents.profiles`, `agents.activeProfile`, and `agents.escalatePolicy`.
240
265
  *
@@ -251,6 +276,13 @@ export function validateAgentProfilesConfig(config) {
251
276
  return null;
252
277
  }
253
278
 
279
+ const reviewerLoadError = validateReviewerLoadUserExtensions(
280
+ agents.reviewer,
281
+ "agents.reviewer",
282
+ "spine settings set agents.reviewer.loadUserExtensions false",
283
+ );
284
+ if (reviewerLoadError) return reviewerLoadError;
285
+
254
286
  const profiles = agents.profiles;
255
287
  if (profiles != null) {
256
288
  if (!isPlainObject(profiles)) {
@@ -270,6 +302,37 @@ export function validateAgentProfilesConfig(config) {
270
302
  }
271
303
  const shapeError = validateAgentSectionModelTypes(profile, `agents.profiles.${name}`);
272
304
  if (shapeError) return shapeError;
305
+ const profileReviewerError = validateReviewerLoadUserExtensions(
306
+ profile.reviewer,
307
+ `agents.profiles.${name}.reviewer`,
308
+ "spine init --force",
309
+ );
310
+ if (profileReviewerError) return profileReviewerError;
311
+ // SP-832 / #355: profile-level reviewer profile; must name another defined profile.
312
+ if (profile.reviewerProfile != null) {
313
+ if (typeof profile.reviewerProfile !== "string") {
314
+ return {
315
+ code: "CONFIG_AGENT_PROFILE_INVALID",
316
+ message: `agents.profiles.${name}.reviewerProfile must be a string when set`,
317
+ suggestedCommand: "spine init --force",
318
+ };
319
+ }
320
+ const reviewerTarget = profile.reviewerProfile.trim();
321
+ if (reviewerTarget !== "" && reviewerTarget === name) {
322
+ return {
323
+ code: "CONFIG_AGENT_PROFILE_INVALID",
324
+ message: `agents.profiles.${name}.reviewerProfile must not name the profile itself`,
325
+ suggestedCommand: "spine settings set agents.reviewerProfile default",
326
+ };
327
+ }
328
+ if (reviewerTarget !== "" && !Object.prototype.hasOwnProperty.call(profiles, reviewerTarget)) {
329
+ return {
330
+ code: "CONFIG_AGENT_PROFILE_INVALID",
331
+ message: `agents.profiles.${name}.reviewerProfile "${reviewerTarget}" does not match a defined agents.profiles entry`,
332
+ suggestedCommand: "spine settings set agents.reviewerProfile default",
333
+ };
334
+ }
335
+ }
273
336
  }
274
337
  }
275
338
 
@@ -320,6 +383,30 @@ export function validateAgentProfilesConfig(config) {
320
383
  }
321
384
  }
322
385
 
386
+ // SP-832 / #355: profile whose reviewer block reviews all workers; same membership rule as quotaFallbackProfile.
387
+ const reviewerProfile = agents.reviewerProfile;
388
+ if (reviewerProfile != null) {
389
+ if (typeof reviewerProfile !== "string") {
390
+ return {
391
+ code: "CONFIG_AGENT_PROFILE_INVALID",
392
+ message: "agents.reviewerProfile must be a string when set",
393
+ suggestedCommand: "spine settings set agents.reviewerProfile default",
394
+ };
395
+ }
396
+ const reviewerTarget = reviewerProfile.trim();
397
+ // An empty string unsets the reviewer profile; otherwise it must name a real profile.
398
+ if (
399
+ reviewerTarget !== "" &&
400
+ (!isPlainObject(profiles) || !Object.prototype.hasOwnProperty.call(profiles, reviewerTarget))
401
+ ) {
402
+ return {
403
+ code: "CONFIG_AGENT_PROFILE_INVALID",
404
+ message: `agents.reviewerProfile "${reviewerTarget}" does not match a defined agents.profiles entry`,
405
+ suggestedCommand: "spine settings set agents.reviewerProfile default",
406
+ };
407
+ }
408
+ }
409
+
323
410
  const escalatePolicy = agents.escalatePolicy;
324
411
  if (escalatePolicy != null) {
325
412
  if (!isPlainObject(escalatePolicy)) {
@@ -9,6 +9,7 @@ import os from "node:os";
9
9
  import path from "node:path";
10
10
 
11
11
  import {
12
+ resolveEffectiveReviewer,
12
13
  resolveReviewerModelPin,
13
14
  resolveReviewerThinkingPin,
14
15
  } from "../config/agent-model-resolve.mjs";
@@ -100,14 +101,90 @@ export function formatReviewerEffectivePins(config = {}) {
100
101
  }
101
102
 
102
103
  /**
104
+ * @param {unknown} value
105
+ * @returns {string|null}
106
+ */
107
+ function nonEmptyString(value) {
108
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : null;
109
+ }
110
+
111
+ /**
112
+ * Worker pairings to report: active profile, quota fallback, escalate target (deduped, in that order).
113
+ *
114
+ * @param {object} config
115
+ * @returns {Array<{ profile: string|null, label: string, workerModel: string|null }>}
116
+ */
117
+ function listWorkerPairings(config) {
118
+ const agents = config?.agents ?? {};
119
+ const profiles = agents.profiles ?? {};
120
+ const active = nonEmptyString(agents.activeProfile);
121
+ const names = [active];
122
+ names.push(nonEmptyString(agents.quotaFallbackProfile));
123
+ if (agents.escalatePolicy?.toProfile != null) {
124
+ names.push(nonEmptyString(agents.escalatePolicy.toProfile));
125
+ }
126
+
127
+ const seen = new Set();
128
+ const pairings = [];
129
+ for (const [index, name] of names.entries()) {
130
+ if (index > 0 && name === null) continue;
131
+ const key = name ?? "";
132
+ if (seen.has(key)) continue;
133
+ seen.add(key);
134
+ // The active profile is already merged into agents.worker; other profiles overlay their own worker pin.
135
+ const profileWorkerModel = name && name !== active ? profiles[name]?.worker?.model : undefined;
136
+ const workerModel = nonEmptyString(profileWorkerModel) ?? nonEmptyString(agents.worker?.model);
137
+ pairings.push({
138
+ profile: name,
139
+ label: name ?? "default",
140
+ workerModel: workerModel === "inherit" ? null : workerModel,
141
+ });
142
+ }
143
+ return pairings;
144
+ }
145
+
146
+ /**
147
+ * Effective reviewer per worker pairing (SP-832 / #355). Fails when a pairing is blocked
148
+ * (same model family or unknown reviewer profile); warnings keep the check `ok`.
149
+ *
103
150
  * @param {object} params
104
151
  * @param {object} [params.config]
105
152
  */
106
153
  export function buildReviewerPerTypePinsDoctorCheck({ config = {} } = {}) {
154
+ const details = [];
155
+ const warnings = [];
156
+ const problems = [];
157
+
158
+ for (const pairing of listWorkerPairings(config)) {
159
+ const effective = resolveEffectiveReviewer(config, {
160
+ workerProfile: pairing.profile,
161
+ workerModel: pairing.workerModel,
162
+ });
163
+ const pins = REVIEW_TYPES.map((reviewType) => {
164
+ const entry = effective[reviewType];
165
+ return `${reviewType}=${entry.model ?? "inherit"}/${entry.thinking ?? "inherit"}`;
166
+ }).join(", ");
167
+ details.push(`${pairing.label}: worker=${pairing.workerModel ?? "inherit"} → ${pins}`);
168
+ warnings.push(...effective.warnings);
169
+ for (const entry of effective.blocked) {
170
+ problems.push(`${pairing.label}: ${entry.reviewType} reviewer blocked (${entry.reason})`);
171
+ }
172
+ }
173
+
174
+ const detail = [...details, ...warnings.map((w) => `warning: ${w}`)].join("; ");
175
+ if (problems.length > 0) {
176
+ return {
177
+ label: "reviewer model pins (per-type)",
178
+ ok: false,
179
+ detail: `${detail}; ${[...new Set(problems)].join("; ")}`,
180
+ suggestedCommand: "spine settings set agents.reviewerProfile <name>",
181
+ };
182
+ }
107
183
  return {
108
184
  label: "reviewer model pins (per-type)",
109
185
  ok: true,
110
- detail: formatReviewerEffectivePins(config),
186
+ ...(warnings.length > 0 ? { warning: true } : {}),
187
+ detail,
111
188
  };
112
189
  }
113
190