pi-spine 2.27.1 → 2.28.1

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 (64) hide show
  1. package/bin/spine-batch.mjs +46 -4
  2. package/bin/spine-cli/cli-args.mjs +117 -0
  3. package/bin/spine-gate.mjs +28 -21
  4. package/bin/spine-integrate.mjs +28 -7
  5. package/bin/spine-issue.mjs +2 -1
  6. package/bin/spine-settings.mjs +7 -9
  7. package/bin/spine-tasks.mjs +1 -0
  8. package/bin/spine-worker-runner.mjs +21 -8
  9. package/bin/spine.mjs +10 -3
  10. package/package.json +1 -1
  11. package/skills/create-spine-tasks/references/prompt-template.md +5 -0
  12. package/skills/spine-release-operator/SKILL.md +14 -2
  13. package/src/batch/contract-exec.mjs +2 -3
  14. package/src/batch/contract-task-start.mjs +23 -1
  15. package/src/batch/diagnosis-handoff-packet.mjs +18 -0
  16. package/src/batch/diagnosis-primary-failure.mjs +35 -0
  17. package/src/batch/engine-lanes/matrix-run.mjs +2 -0
  18. package/src/batch/engine-lanes/quota-fallback-run.mjs +11 -0
  19. package/src/batch/engine-lanes/quota-fallback-state.mjs +155 -8
  20. package/src/batch/engine-lanes/review-code.mjs +20 -0
  21. package/src/batch/engine-lanes/review-final.mjs +10 -2
  22. package/src/batch/engine-lanes/review-poll.mjs +33 -0
  23. package/src/batch/engine-lanes/task-agent-profile.mjs +324 -0
  24. package/src/batch/engine-lanes.mjs +18 -17
  25. package/src/batch/evidence-command.mjs +18 -21
  26. package/src/batch/evidence-exec.mjs +79 -0
  27. package/src/batch/journal.mjs +5 -3
  28. package/src/batch/metrics-rollup.mjs +98 -4
  29. package/src/batch/metrics.mjs +134 -9
  30. package/src/batch/provider-quota.mjs +174 -6
  31. package/src/batch/quota-fallback.mjs +87 -6
  32. package/src/batch/reconcile-classify.mjs +28 -1
  33. package/src/batch/reconcile-diagnosis-context.mjs +2 -0
  34. package/src/batch/resume-lane-reviews.mjs +11 -10
  35. package/src/batch/retry-profile.mjs +77 -0
  36. package/src/batch/retry.mjs +32 -1
  37. package/src/batch/review-step-run.mjs +4 -0
  38. package/src/batch/review-step.mjs +1 -0
  39. package/src/batch/sequence-wait.mjs +7 -5
  40. package/src/batch/state-io.mjs +29 -3
  41. package/src/batch/worker-heartbeat.mjs +10 -2
  42. package/src/batch/worker-host.mjs +1 -1
  43. package/src/batch/worker-prompt.mjs +4 -5
  44. package/src/cli/deps.mjs +3 -2
  45. package/src/config/agent-model-resolve.mjs +144 -8
  46. package/src/config/contract.mjs +20 -0
  47. package/src/config/model-family.mjs +60 -0
  48. package/src/config/preflight/discovery.mjs +1 -0
  49. package/src/config/settings-fields.mjs +15 -0
  50. package/src/config/spine-config-schema.mjs +49 -0
  51. package/src/doctor/agent-model-inherit.mjs +78 -1
  52. package/src/doctor/agent-template-drift.mjs +65 -0
  53. package/src/doctor/run-doctor-checks.mjs +8 -1
  54. package/src/doctor/stet-capacity.mjs +171 -0
  55. package/src/metrics/quota-cli.mjs +16 -0
  56. package/src/metrics/quota-probes.mjs +228 -31
  57. package/src/metrics/quota-snapshot.mjs +21 -2
  58. package/src/planner/graph.mjs +7 -5
  59. package/src/planner/pending.mjs +2 -2
  60. package/src/planner/scope.mjs +3 -3
  61. package/src/tasks/packet/parse-prompt.mjs +47 -0
  62. package/src/tasks/packet/validate-prompt.mjs +156 -1
  63. package/templates/agents/reviewer.md +3 -1
  64. package/templates/agents/worker.md +15 -19
@@ -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
+ }
@@ -6,6 +6,10 @@
6
6
  /** @type {readonly string[]} */
7
7
  export const CONTRACT_MODES = Object.freeze(["required", "optional", "legacy"]);
8
8
 
9
+ /** Bounds for `contract.testTimeoutMs` (#369): 1 second to 4 hours. */
10
+ export const CONTRACT_TEST_TIMEOUT_MIN_MS = 1000;
11
+ export const CONTRACT_TEST_TIMEOUT_MAX_MS = 4 * 60 * 60 * 1000;
12
+
9
13
  /**
10
14
  * @param {unknown} config
11
15
  * @returns {{ code: string, message: string, suggestedCommand: string } | null}
@@ -44,6 +48,22 @@ export function validateContractConfig(config) {
44
48
  }
45
49
  }
46
50
 
51
+ if (contract.testTimeoutMs != null) {
52
+ const timeoutMs = contract.testTimeoutMs;
53
+ const isValid =
54
+ typeof timeoutMs === "number" &&
55
+ Number.isInteger(timeoutMs) &&
56
+ timeoutMs >= CONTRACT_TEST_TIMEOUT_MIN_MS &&
57
+ timeoutMs <= CONTRACT_TEST_TIMEOUT_MAX_MS;
58
+ if (!isValid) {
59
+ return {
60
+ code: "CONFIG_CONTRACT_TEST_TIMEOUT_INVALID",
61
+ message: `contract.testTimeoutMs must be an integer between ${CONTRACT_TEST_TIMEOUT_MIN_MS} and ${CONTRACT_TEST_TIMEOUT_MAX_MS} when set`,
62
+ suggestedCommand: "spine settings set contract.testTimeoutMs 1200000",
63
+ };
64
+ }
65
+ }
66
+
47
67
  if (contract.legacyTaskIdPrefixes != null) {
48
68
  if (!Array.isArray(contract.legacyTaskIdPrefixes)) {
49
69
  return {
@@ -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(
@@ -8,6 +8,8 @@
8
8
  * Only `lanes.maxParallel` is editable via `spine settings set`; tasks root is env/file only.
9
9
  */
10
10
 
11
+ import { CONTRACT_TEST_TIMEOUT_MAX_MS, CONTRACT_TEST_TIMEOUT_MIN_MS } from "./contract.mjs";
12
+
11
13
  /** @typedef {"boolean" | "number" | "string" | "enum"} SettingFieldType */
12
14
 
13
15
  /**
@@ -62,6 +64,13 @@ export const SETTINGS_FIELDS = Object.freeze([
62
64
  min: 1,
63
65
  max: 10,
64
66
  },
67
+ {
68
+ path: "contract.testTimeoutMs",
69
+ label: "Contract testCommand timeout per attempt (ms; default 600000)",
70
+ type: "number",
71
+ min: CONTRACT_TEST_TIMEOUT_MIN_MS,
72
+ max: CONTRACT_TEST_TIMEOUT_MAX_MS,
73
+ },
65
74
  {
66
75
  path: "agents.worker.model",
67
76
  label: "Worker model",
@@ -162,6 +171,12 @@ export const SETTINGS_FIELDS = Object.freeze([
162
171
  type: "string",
163
172
  optional: true,
164
173
  },
174
+ {
175
+ path: "agents.reviewerProfile",
176
+ label: "Reviewer agent model profile (cross-family review)",
177
+ type: "string",
178
+ optional: true,
179
+ },
165
180
  {
166
181
  path: "dashboard.port",
167
182
  label: "Dashboard port",
@@ -308,6 +308,31 @@ export function validateAgentProfilesConfig(config) {
308
308
  "spine init --force",
309
309
  );
310
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
+ }
311
336
  }
312
337
  }
313
338
 
@@ -358,6 +383,30 @@ export function validateAgentProfilesConfig(config) {
358
383
  }
359
384
  }
360
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
+
361
410
  const escalatePolicy = agents.escalatePolicy;
362
411
  if (escalatePolicy != null) {
363
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
 
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Agent prompt drift check: `.spine/agents/*.md` vs the packaged
3
+ * `templates/agents/*.md` the CLI ships.
4
+ *
5
+ * Workers, reviewers and the supervisor read the project copy, not the template.
6
+ * FR-WORK-08 lets a project append overrides after the base template, so a copy
7
+ * is current when it starts with the template text; anything else means template
8
+ * fixes (for example the final PASS/REVISE/REPLAN verdict shape) never reach the
9
+ * agents. Advisory only: the operator decides how to merge local edits.
10
+ */
11
+
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+
15
+ import { AGENT_STUB_FILES, TEMPLATE_PATHS } from "../config/spine-init-constants.mjs";
16
+
17
+ /** @param {string} text */
18
+ function normalizeAgentText(text) {
19
+ return text.replace(/\r\n/g, "\n").trimEnd();
20
+ }
21
+
22
+ /**
23
+ * @param {object} params
24
+ * @param {string} params.projectRoot
25
+ * @param {Array<{ templateKey: string, destName: string }>} [params.agentFiles]
26
+ * @param {Record<string, string>} [params.templatePaths] templateKey → absolute template path
27
+ * @returns {{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }}
28
+ */
29
+ export function buildAgentTemplateDriftDoctorCheck({
30
+ projectRoot,
31
+ agentFiles = AGENT_STUB_FILES,
32
+ templatePaths = TEMPLATE_PATHS.agents,
33
+ }) {
34
+ /** @type {string[]} */
35
+ const drifted = [];
36
+ let compared = 0;
37
+
38
+ for (const { templateKey, destName } of agentFiles) {
39
+ const projectPath = path.join(projectRoot, ".spine", "agents", destName);
40
+ const templatePath = templatePaths[templateKey];
41
+ if (!templatePath || !fs.existsSync(projectPath) || !fs.existsSync(templatePath)) continue;
42
+ compared += 1;
43
+ const projectText = normalizeAgentText(fs.readFileSync(projectPath, "utf-8"));
44
+ const templateText = normalizeAgentText(fs.readFileSync(templatePath, "utf-8"));
45
+ if (!projectText.startsWith(templateText)) {
46
+ drifted.push(`.spine/agents/${destName}`);
47
+ }
48
+ }
49
+
50
+ if (drifted.length === 0) {
51
+ return {
52
+ label: "agent prompts match templates",
53
+ ok: true,
54
+ detail: compared === 0 ? "no agent files to compare" : `${compared} agent file(s) start with the packaged template`,
55
+ };
56
+ }
57
+
58
+ return {
59
+ label: "agent prompts match templates",
60
+ ok: true,
61
+ warning: true,
62
+ detail: `${drifted.join(", ")} no longer start with the packaged template; template fixes do not reach these agents`,
63
+ suggestedCommand: `diff templates/agents/<file> .spine/agents/<file> — rebase local edits after the template (or spine init --force to reset)`,
64
+ };
65
+ }
@@ -23,6 +23,8 @@ import {
23
23
  buildStallConfigDoctorCheck,
24
24
  } from "./stall-config.mjs";
25
25
  import { buildRulesManifestDoctorCheck } from "./rules-manifest.mjs";
26
+ import { buildAgentTemplateDriftDoctorCheck } from "./agent-template-drift.mjs";
27
+ import { buildStetCapacityDoctorCheck } from "./stet-capacity.mjs";
26
28
  import { buildWorktreeHealthDoctorCheck } from "./worktree-health.mjs";
27
29
  import { buildGitignoredPubspecAssetsDoctorCheck } from "../config/worktree-setup-hook.mjs";
28
30
  import { buildStaleWorktreesDoctorCheck } from "./stale-worktrees.mjs";
@@ -460,7 +462,10 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
460
462
  );
461
463
  checks.push(buildStallConfigDoctorCheck({ config: configResult.config }));
462
464
  checks.push(buildPiWorkerTimeoutDoctorCheck({ config: configResult.config }));
463
- checks.push(buildReviewerPerTypePinsDoctorCheck({ config: configResult.config }));
465
+ const reviewerPinsCheck = buildReviewerPerTypePinsDoctorCheck({ config: configResult.config });
466
+ checks.push(reviewerPinsCheck);
467
+ // SP-832 / #355: same-family worker/reviewer pairing blocks doctor and (via doctor) preflight.
468
+ if (!reviewerPinsCheck.ok) issueCount++;
464
469
  checks.push(buildAgentModelInheritDoctorCheck({
465
470
  config: configResult.config,
466
471
  projectRoot,
@@ -533,6 +538,8 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
533
538
  suggestedCommand: "spine init",
534
539
  });
535
540
  }
541
+ checks.push(buildAgentTemplateDriftDoctorCheck({ projectRoot }));
542
+ checks.push(buildStetCapacityDoctorCheck());
536
543
 
537
544
  const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
538
545
  const metricsPath = path.join(