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
@@ -13,7 +13,7 @@ import path from 'node:path';
13
13
  import { summarizePendingScope } from './pending.mjs';
14
14
 
15
15
  // Single source of truth (SP-785, #300): re-export the shared task-ID regex.
16
- import { TASK_ID_RE } from '../tasks/packet/discover.mjs';
16
+ import { TASK_ID_RE, compareTaskIds } from '../tasks/packet/discover.mjs';
17
17
  export { TASK_ID_RE };
18
18
 
19
19
  export const NO_PENDING_TASKS_ERROR = 'No pending tasks (all discovered tasks have .DONE).';
@@ -74,7 +74,7 @@ function tokenizeScope(scope) {
74
74
  * @returns {{ mode: 'all'|'pending'|'ids'|'glob'|'custom', taskIds: string[], excludedCount?: number }}
75
75
  */
76
76
  export function parseScope(scopeArg, { tasksRoot, discoveredTasks }) {
77
- const allTaskIds = discoveredTasks.map((t) => t.taskId).sort();
77
+ const allTaskIds = discoveredTasks.map((t) => t.taskId).sort(compareTaskIds);
78
78
  const tasksRootPosix = String(tasksRoot).replace(/\\/g, '/');
79
79
  const tasksRootBase = path.posix.basename(tasksRootPosix);
80
80
 
@@ -135,7 +135,7 @@ export function parseScope(scopeArg, { tasksRoot, discoveredTasks }) {
135
135
 
136
136
  const resolved = Array.from(selected)
137
137
  .filter((id) => allTaskIds.includes(id))
138
- .sort();
138
+ .sort(compareTaskIds);
139
139
 
140
140
  if (resolved.length === 0) {
141
141
  throw new Error(`Scope did not match any discovered task(s): ${String(scopeArg)}`);
@@ -144,6 +144,31 @@ export function formatRefusedContractMetacharMessage(command) {
144
144
  const issue = findContractCommandMetacharIssue(String(command ?? "").trim());
145
145
  return `Contract testCommand refused before spawn: ${issue ?? "shell metacharacters"} (command: ${command}). Contract testCommand runs through a shell; remove $, backticks, ;, |, || or lone & — && chains are allowed (#268).`;
146
146
  }
147
+ /** Allowed `**Thinking:**` levels (SP-833 / #340). */
148
+ export const PROMPT_THINKING_LEVELS = Object.freeze([
149
+ "off",
150
+ "minimal",
151
+ "low",
152
+ "medium",
153
+ "high",
154
+ "xhigh",
155
+ ]);
156
+ /** Profile names accepted by `**Profile:**` / `**Reviewer Profile:**`. */
157
+ export const PROMPT_PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
158
+ const PROFILE_LINE_RE = /^\*\*Profile:\*\*[ \t]*(.*?)[ \t]*$/im;
159
+ const THINKING_LINE_RE = /^\*\*Thinking:\*\*[ \t]*(.*?)[ \t]*$/im;
160
+ const REVIEWER_PROFILE_LINE_RE = /^\*\*Reviewer Profile:\*\*[ \t]*(.*?)[ \t]*$/im;
161
+
162
+ /**
163
+ * @param {RegExp} re
164
+ * @param {string} markdown
165
+ * @returns {string|null} Trimmed value, or null when absent/empty
166
+ */
167
+ function parseHeaderValue(re, markdown) {
168
+ const value = re.exec(markdown)?.[1]?.trim();
169
+ return value ? value : null;
170
+ }
171
+
147
172
  export const SEE_FILE_SCOPE_RE = /^see\s+file\s+scope$/i;
148
173
  const CONTRACT_EM_DASH_PLACEHOLDER_RE = /^[—\-]$/;
149
174
  const CONTRACT_NONE_VALUES = new Set([
@@ -177,6 +202,9 @@ export function parsePrompt(markdown) {
177
202
  const size = parseSizeLineFromMarkdown(markdown);
178
203
  const typeMatch = /^\*\*Type:\*\*\s*(llm|execute)\s*$/im.exec(markdown);
179
204
  const type = typeMatch ? typeMatch[1].toLowerCase() : "llm";
205
+ const profile = parseHeaderValue(PROFILE_LINE_RE, markdown);
206
+ const thinking = parseHeaderValue(THINKING_LINE_RE, markdown);
207
+ const reviewerProfile = parseHeaderValue(REVIEWER_PROFILE_LINE_RE, markdown);
180
208
 
181
209
  let matrix = null;
182
210
  let matrixColumns = null;
@@ -193,6 +221,9 @@ export function parsePrompt(markdown) {
193
221
  title,
194
222
  size,
195
223
  type,
224
+ profile,
225
+ thinking,
226
+ reviewerProfile,
196
227
  headingLine,
197
228
  sections,
198
229
  steps,
@@ -237,6 +268,22 @@ export function validatePrompt(markdown) {
237
268
 
238
269
  errors.push(...collectDuplicateStepNumberErrors(prompt.steps));
239
270
 
271
+ if (prompt.thinking !== null && !PROMPT_THINKING_LEVELS.includes(prompt.thinking)) {
272
+ errors.push(
273
+ `**Thinking:** must be one of ${PROMPT_THINKING_LEVELS.join("|")} (got "${prompt.thinking}")`,
274
+ );
275
+ }
276
+ for (const [label, value] of [
277
+ ["Profile", prompt.profile],
278
+ ["Reviewer Profile", prompt.reviewerProfile],
279
+ ]) {
280
+ if (value !== null && !PROMPT_PROFILE_NAME_RE.test(value)) {
281
+ errors.push(
282
+ `**${label}:** malformed profile name "${value}" (allowed characters: A-Z a-z 0-9 . _ -)`,
283
+ );
284
+ }
285
+ }
286
+
240
287
  if (prompt.type === "execute") {
241
288
  const contract = parseContract(markdown);
242
289
  if (!contract.testCommand && !contract.runCommand) {
@@ -13,17 +13,164 @@ import {
13
13
  } from "./parse-prompt.mjs";
14
14
  import { validateContract } from "./validate-contract.mjs";
15
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";
16
19
  import { parseReviewLevel } from "../../batch/review-shared.mjs";
17
20
 
18
21
  /** Operator-facing hint when fileScopeMustChange may already be satisfied on main. */
19
22
  export const STALE_FILE_SCOPE_AMENDMENT_HINT =
20
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)";
21
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
+
22
168
  /**
23
169
  * Validate PROMPT.md structure and ## Contract per contract.mode (handoff §3.1, §4.4).
24
170
  *
25
171
  * @param {string} markdown PROMPT.md contents
26
- * @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).
27
174
  * @returns {{ ok: boolean, errors: string[], warnings: string[], prompt: ReturnType<typeof parsePrompt>, contract: ReturnType<typeof parseContract> }}
28
175
  */
29
176
  export function validatePrompt(markdown, options = {}) {
@@ -56,6 +203,14 @@ export function validatePrompt(markdown, options = {}) {
56
203
  }),
57
204
  );
58
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
+
59
214
  return {
60
215
  ok: errors.length === 0,
61
216
  errors,
@@ -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).