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
@@ -12,16 +12,165 @@ import {
12
12
  validatePrompt as validatePromptStructure,
13
13
  } from "./parse-prompt.mjs";
14
14
  import { validateContract } from "./validate-contract.mjs";
15
+ import { collectExecuteReviewLevelWarnings } from "../validate-contract-warn.mjs";
16
+ import { resolveEffectiveReviewer } from "../../config/agent-model-resolve.mjs";
17
+ import { isSameModelFamily } from "../../config/model-family.mjs";
18
+ import { PROMPT_PROFILE_NAME_RE } from "./parse-prompt.mjs";
19
+ import { parseReviewLevel } from "../../batch/review-shared.mjs";
15
20
 
16
21
  /** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
17
22
  export const STALE_FILE_SCOPE_AMENDMENT_HINT =
18
23
  "Amend PROMPT.md ## Contract before batch start (e.g. point fileScopeMustChange at delivery artifacts such as STATUS.md, or add an ## Amendments note documenting pre-landed implementation)";
19
24
 
25
+ /**
26
+ * @param {unknown} value
27
+ * @returns {value is Record<string, any>}
28
+ */
29
+ function isRecord(value) {
30
+ return value !== null && typeof value === "object" && !Array.isArray(value);
31
+ }
32
+
33
+ /**
34
+ * Per-type reviewer model pin (type-specific wins over top-level; `inherit` is no pin).
35
+ *
36
+ * @param {Record<string, any>} reviewer
37
+ * @param {"plan"|"code"|"final"} reviewType
38
+ * @returns {string|null}
39
+ */
40
+ function pickReviewerModel(reviewer, reviewType) {
41
+ for (const candidate of [reviewer[reviewType]?.model, reviewer.model]) {
42
+ if (typeof candidate === "string" && candidate !== "" && candidate !== "inherit") {
43
+ return candidate;
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
49
+ /**
50
+ * Warnings for per-task agent fields on `**Type:** execute` tasks (no LLM worker/reviewer).
51
+ *
52
+ * @param {ReturnType<typeof validatePromptStructure>["prompt"]} prompt
53
+ * @returns {string[]}
54
+ */
55
+ function collectExecuteAgentFieldWarnings(prompt) {
56
+ if (prompt.type !== "execute") return [];
57
+ /** @type {string[]} */
58
+ const warnings = [];
59
+ for (const [label, value] of [
60
+ ["Profile", prompt.profile],
61
+ ["Thinking", prompt.thinking],
62
+ ["Reviewer Profile", prompt.reviewerProfile],
63
+ ]) {
64
+ if (value !== null) {
65
+ warnings.push(
66
+ `**${label}:** is ignored on a **Type:** execute task (no LLM worker or reviewer to configure)`,
67
+ );
68
+ }
69
+ }
70
+ return warnings;
71
+ }
72
+
73
+ /**
74
+ * Config-aware checks of `**Profile:**` / `**Reviewer Profile:**` against `agents` (SP-833 / #355).
75
+ * Skipped by callers when no `agents` option is supplied (planner, queue).
76
+ *
77
+ * @param {ReturnType<typeof validatePromptStructure>["prompt"]} prompt
78
+ * @param {Record<string, any>} agents Effective `config.agents`
79
+ * @returns {{ errors: string[], warnings: string[] }}
80
+ */
81
+ function collectAgentProfileFindings(prompt, agents) {
82
+ /** @type {string[]} */
83
+ const errors = [];
84
+ /** @type {string[]} */
85
+ const warnings = [];
86
+ if (prompt.type === "execute") return { errors, warnings };
87
+ if (prompt.profile === null && prompt.reviewerProfile === null) return { errors, warnings };
88
+
89
+ const profiles = isRecord(agents.profiles) ? agents.profiles : {};
90
+ const definedNames = Object.keys(profiles);
91
+ const known = (name) => PROMPT_PROFILE_NAME_RE.test(name) && Object.hasOwn(profiles, name);
92
+ const hint = definedNames.length > 0 ? ` (defined: ${definedNames.join(", ")})` : " (none defined)";
93
+
94
+ const wellFormed = (name) => name === null || PROMPT_PROFILE_NAME_RE.test(name);
95
+ let resolvable = true;
96
+ if (prompt.profile !== null && wellFormed(prompt.profile) && !known(prompt.profile)) {
97
+ errors.push(`**Profile:** "${prompt.profile}" is not defined in agents.profiles${hint}`);
98
+ resolvable = false;
99
+ }
100
+ if (prompt.reviewerProfile !== null && wellFormed(prompt.reviewerProfile)) {
101
+ if (!known(prompt.reviewerProfile)) {
102
+ errors.push(
103
+ `**Reviewer Profile:** "${prompt.reviewerProfile}" is not defined in agents.profiles${hint}`,
104
+ );
105
+ resolvable = false;
106
+ } else if (!isRecord(profiles[prompt.reviewerProfile]?.reviewer)) {
107
+ warnings.push(
108
+ `**Reviewer Profile:** "${prompt.reviewerProfile}" has no reviewer block; it falls back to the next reviewer precedence level`,
109
+ );
110
+ }
111
+ }
112
+
113
+ // Malformed names already fail structural validation; unknown names already errored above.
114
+ if (!resolvable || !wellFormed(prompt.profile) || !wellFormed(prompt.reviewerProfile)) {
115
+ return { errors, warnings };
116
+ }
117
+
118
+ const workerModel =
119
+ (prompt.profile !== null ? profiles[prompt.profile]?.worker?.model : null) ??
120
+ agents.worker?.model ??
121
+ null;
122
+ /** @type {Array<"plan"|"code"|"final">} */
123
+ const reviewTypes = [];
124
+ /** @type {Set<string>} */
125
+ const models = new Set();
126
+ let subject = "effective reviewer";
127
+ const reviewerBlock =
128
+ prompt.reviewerProfile !== null ? profiles[prompt.reviewerProfile]?.reviewer : null;
129
+ if (prompt.reviewerProfile !== null && isRecord(reviewerBlock)) {
130
+ // The named profile itself must be cross-family; fallback candidates do not rescue it.
131
+ subject = `**Reviewer Profile:** "${prompt.reviewerProfile}"`;
132
+ for (const reviewType of ["plan", "code", "final"]) {
133
+ const model = pickReviewerModel(reviewerBlock, reviewType);
134
+ if (isSameModelFamily(model, workerModel)) {
135
+ reviewTypes.push(reviewType);
136
+ models.add(model);
137
+ }
138
+ }
139
+ } else {
140
+ const resolved = resolveEffectiveReviewer(
141
+ { agents },
142
+ {
143
+ promptReviewerProfile: prompt.reviewerProfile,
144
+ workerProfile: prompt.profile,
145
+ workerModel,
146
+ },
147
+ );
148
+ for (const entry of resolved.blocked) {
149
+ if (entry.reason === "same_model_family") {
150
+ reviewTypes.push(entry.reviewType);
151
+ models.add(resolved[entry.reviewType].model);
152
+ } else if (entry.reason === "unknown_reviewer_profile") {
153
+ errors.push(
154
+ "Reviewer profile resolution failed: a referenced reviewerProfile is not defined in agents.profiles",
155
+ );
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ if (reviewTypes.length > 0) {
161
+ errors.push(
162
+ `${subject} uses model "${[...models].join(", ")}" in the same model family as the worker model "${workerModel}" (${reviewTypes.join(", ")} review); pick a cross-family reviewer`,
163
+ );
164
+ }
165
+ return { errors, warnings };
166
+ }
167
+
20
168
  /**
21
169
  * Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
22
170
  *
23
171
  * @param {string} markdown PROMPT.md contents
24
- * @param {{ mode?: string, legacyTaskIdPrefixes?: string[], contract?: { mode?: string, legacyTaskIdPrefixes?: string[] } }} [options]
172
+ * @param {{ mode?: string, legacyTaskIdPrefixes?: string[], contract?: { mode?: string, legacyTaskIdPrefixes?: string[] }, agents?: Record<string, any> }} [options]
173
+ * `agents` (effective `config.agents`) enables profile-name and reviewer-family checks (SP-833).
25
174
  * @returns {{ ok: boolean, errors: string[], warnings: string[], prompt: ReturnType<typeof parsePrompt>, contract: ReturnType<typeof parseContract> }}
26
175
  */
27
176
  export function validatePrompt(markdown, options = {}) {
@@ -46,10 +195,26 @@ export function validatePrompt(markdown, options = {}) {
46
195
 
47
196
  errors.push(...contractValidation.errors);
48
197
 
198
+ const warnings = [...contractValidation.warnings];
199
+ warnings.push(
200
+ ...collectExecuteReviewLevelWarnings({
201
+ type: structure.prompt.type,
202
+ reviewLevel: parseReviewLevel(markdown),
203
+ }),
204
+ );
205
+
206
+ warnings.push(...collectExecuteAgentFieldWarnings(structure.prompt));
207
+
208
+ if (isRecord(options.agents)) {
209
+ const findings = collectAgentProfileFindings(structure.prompt, options.agents);
210
+ errors.push(...findings.errors);
211
+ warnings.push(...findings.warnings);
212
+ }
213
+
49
214
  return {
50
215
  ok: errors.length === 0,
51
216
  errors,
52
- warnings: contractValidation.warnings,
217
+ warnings,
53
218
  prompt: structure.prompt,
54
219
  contract,
55
220
  };
@@ -22,6 +22,22 @@ export const TEST_COMMAND_LINT_MISSING_FIX_HINT =
22
22
  const PATCH_TASK_SIZES = new Set(["S", "M"]);
23
23
  const LINT_IN_TEST_COMMAND_RE = /\b(?:lint|eslint|analyze)\b/;
24
24
 
25
+ /**
26
+ * Warn when an execute packet declares a Review Level above 0 (SP-827 / #336):
27
+ * execute tasks run no reviewers, so the declared level is misleading.
28
+ *
29
+ * @param {{ type: string, reviewLevel: number }} options
30
+ * @returns {string[]}
31
+ */
32
+ export function collectExecuteReviewLevelWarnings({ type, reviewLevel }) {
33
+ if (type !== "execute" || reviewLevel <= 0) {
34
+ return [];
35
+ }
36
+ return [
37
+ `Type: execute task declares Review Level ${reviewLevel}; execute tasks run no reviewers — set Review Level 0.`,
38
+ ];
39
+ }
40
+
25
41
  /**
26
42
  * @param {string | null | undefined} testCommand
27
43
  * @returns {boolean}
@@ -53,7 +53,7 @@ Include contract verification results from the review request when judging PASS
53
53
 
54
54
  Write the review file using the `write` tool. Include:
55
55
 
56
- 1. `### Verdict: APPROVE` or `### Verdict: REVISE`
56
+ 1. `### Verdict: APPROVE` or `### Verdict: REVISE` (plan/code); `### Verdict: PASS`, `### Verdict: REVISE`, or `### Verdict: REPLAN` (final)
57
57
  2. `### Summary` with 2–3 sentences
58
58
  3. A fenced JSON block (required — the batch engine parses this):
59
59
 
@@ -61,6 +61,8 @@ Write the review file using the `write` tool. Include:
61
61
  {"verdict":"APPROVE","feedback":"..."}
62
62
  ```
63
63
 
64
+ Final reviews use `{"verdict":"PASS","feedback":"..."}` (or `REVISE` / `REPLAN`). The engine rejects `APPROVE` on a final review.
65
+
64
66
  ### REVISE structure (FR-REV-03)
65
67
 
66
68
  When returning **REVISE**, add a `### Blocking issues` section. Each blocking item must cite:
@@ -53,7 +53,7 @@ Spine documents honest `.DONE` + lane auto-commit behavior below — `.DONE` mea
53
53
 
54
54
  | Tool | When to use |
55
55
  |------|-------------|
56
- | `spine_review_step` | Plan review at step checkpoints when Review Level ≥ 1 (`type=plan` only) |
56
+ | `spine_review_step` | Engine-run in real-pi batches; in-worker calls are skipped (do not call it from the worker) |
57
57
  | `spine_report_progress` | After completing a step — emits `task.step_completed` for stall detection |
58
58
  | `spine_request_gate` | Rare — request operator attention (v1.1 returns `not_supported`; integrate gates are automatic) |
59
59
 
@@ -66,40 +66,36 @@ Task packets declare a **Review Level** (0–3) in `PROMPT.md`. Read it at task
66
66
  | Level | Label | When to call `spine_review_step` |
67
67
  |-------|-------|----------------------------------|
68
68
  | 0 | None | Never — reviewer is not spawned |
69
- | 1 | Plan Only | Plan review before each step (or at `**Plan-review checkpoint**` markers) |
70
- | 2 | Plan + Code | **Plan review in worker** at step boundaries; **code review runs on the engine** after `.DONE` |
71
- | 3 | Full | Plan review in worker; code + final review run on the **engine** after `.DONE` |
69
+ | 1 | Plan Only | Never from the worker — the engine runs plan review (and final review) after `.DONE` |
70
+ | 2 | Plan + Code | Never from the worker — the engine runs plan + code review after `.DONE` |
71
+ | 3 | Full | Never from the worker — the engine runs plan, code, and final review after `.DONE` |
72
72
 
73
- **FR-WORK-07:** when Review Level ≥ 1, call **`spine_review_step`** (Pi tool) or `spine review step --step N --type plan` at plan-review checkpoints in PROMPT. **Do not** spawn code or final reviewers from inside the worker (SP-194/SP-195) — the batch engine runs those phases after you create `.DONE`.
73
+ **FR-WORK-07:** when Review Level ≥ 1, plan, code (Level ≥ 2), and final reviews run in the **batch engine** after you create `.DONE` (SP-194/SP-195/SP-695). **Do not** call `spine_review_step` / `spine review step` from inside the worker — in real-pi batches every in-worker call is skipped.
74
74
 
75
- Checkpoint markers in PROMPT (`**Plan-review checkpoint**`, `**Code review checkpoint**`) consolidate reviews on single-deliverable tasks; otherwise default is per-step reviews when steps are independent.
75
+ Checkpoint markers in PROMPT (`**Plan-review checkpoint**`, `**Code review checkpoint**`) tell the engine which step to review; they are not instructions to call the review tool yourself.
76
76
 
77
- ## Level 2+ order of operations
77
+ ## Order of operations
78
78
 
79
- For tasks at **Review Level ≥ 2**, complete **each step** in this strict order:
79
+ For tasks at **Review Level ≥ 1**, complete **each step** in this strict order:
80
80
 
81
81
  1. **Finish step work** — all outcomes for this step in PROMPT.
82
82
  2. **Update outcome checkboxes** in `STATUS.md` as each outcome completes (immediate checkbox rule).
83
83
  3. **Commit** step work on the lane branch: `feat(TASK-ID): complete Step N — {step title}`
84
- 4. **Request plan review** — `spine_review_step` with `type=plan` when PROMPT requires a plan-review checkpoint (all levels ≥ 1).
85
- 5. **On APPROVE only** — set the step **Status** to complete in `STATUS.md`, advance `Current Step`, then call **`spine_report_progress`**.
84
+ 4. **Do not request review from the worker** — the engine reviews after `.DONE`.
85
+ 5. **Mark the step complete** — set the step **Status** to complete in `STATUS.md`, advance `Current Step`, then call **`spine_report_progress`**.
86
86
 
87
- **While review is pending:** do **not** mark the step **Status** complete or advance to the next step. Outcome checkboxes may already be checked.
87
+ **On REVISE (FR-REV-03):** the engine re-runs the worker with feedback in `{taskFolder}/.reviews/`; address it, re-commit, and recreate `.DONE`.
88
88
 
89
- **On REVISE (FR-REV-03):** address feedback in `{taskFolder}/.reviews/`; re-commit if needed; call `spine_review_step` again. Do **not** start the next step until you receive **APPROVE**.
90
-
91
- **On review spawn failure (FR-REV-06):** exit with a **non-zero** status — fail closed. Do not mark the step complete, advance `Current Step`, or create `.DONE`.
92
-
93
- For **Review Level 0**, skip `spine_review_step`. For **Level 1**, follow PROMPT plan-review markers; still commit at step boundaries and mark step **Status** complete only after plan review **APPROVE** when a review was required for that step.
89
+ For **Review Level 0**, no reviewer runs. For **Level 1+**, still commit at step boundaries; reviews happen on the engine after `.DONE`.
94
90
 
95
91
  ## Checkpoint discipline
96
92
 
97
93
  1. Update `STATUS.md` **before starting** each step (`Current Step`, step status → in progress).
98
94
  2. Mark **outcome** checkboxes **immediately** when each outcome completes (see Checkbox discipline).
99
95
  3. **Commit** at step boundaries when you change files: `feat(TASK-ID): complete Step N — {step title}`
100
- 4. When Review Level ≥ 2, follow **Level 2+ order of operations** (commit → review → APPROVE → mark step Status complete). When Review Level is 1, call **`spine_review_step`** for required plan reviews before marking the step complete.
101
- 5. On **REVISE**, fix feedback and re-request review; do not advance step **Status** or `Current Step` until **APPROVE**.
102
- 6. Call **`spine_report_progress`** after the step is marked complete (after review **APPROVE** when review level > 0).
96
+ 4. Follow the **order of operations** above (finish → checkboxes → commit → mark step Status complete). Do **not** call `spine_review_step` from the worker; the engine reviews after `.DONE`.
97
+ 5. On **REVISE** feedback from a resumed run, fix it before recreating `.DONE`.
98
+ 6. Call **`spine_report_progress`** after the step is marked complete.
103
99
  7. Run **`./scripts/worker-verify.sh`** (or `npm run typecheck && SPINE_WORKER_STUB=1 npm test`) before creating `.DONE`.
104
100
  8. Create `.DONE` only when every completion criterion in PROMPT is satisfied (tests pass, STATUS current). The **engine** runs contract verification, code review (RL ≥ 2), and final review (RL ≥ 1) **after** `.DONE` — do not spawn those reviewers yourself.
105
101
  9. **After `.DONE`:** exit immediately. No further tool calls, commits, or reviewer spawns (prevents SP-190-class wedges).
@@ -36,7 +36,7 @@
36
36
  "workerOutputMaxBytes": 262144,
37
37
  "workerOutputTailLines": 200,
38
38
  "retainWorkerOutputOnSuccess": false,
39
- "streamWorkerOutputLive": false,
39
+ "streamWorkerOutputLive": true,
40
40
  "workerLiveLogMaxBytes": 262144,
41
41
  "stallTimeoutMinutes": 120,
42
42
  "stallGraceAfterProgressMinutes": 30,