pi-spine 1.2.0 → 1.4.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 (76) hide show
  1. package/README.md +4 -4
  2. package/bin/spine-cli/verify.mjs +6 -0
  3. package/bin/spine-deps.mjs +0 -2
  4. package/bin/spine-plan.mjs +49 -1
  5. package/bin/spine-rules.mjs +0 -2
  6. package/bin/spine-settings.mjs +0 -2
  7. package/bin/spine-worker-runner.mjs +136 -4
  8. package/bin/spine.mjs +2 -5
  9. package/package.json +2 -2
  10. package/skills/create-spine-tasks/SKILL.md +7 -2
  11. package/skills/create-spine-tasks/references/contract-template.md +95 -3
  12. package/src/batch/attached-engine-handoff.mjs +0 -1
  13. package/src/batch/attached-runner.mjs +81 -5
  14. package/src/batch/contract-stub-delivery.mjs +110 -0
  15. package/src/batch/contract-task-start.mjs +204 -0
  16. package/src/batch/contract-verify.mjs +160 -16
  17. package/src/batch/detached-start.mjs +72 -2
  18. package/src/batch/diagnosis-launch-failure.mjs +114 -0
  19. package/src/batch/diagnosis-primary-failure.mjs +89 -0
  20. package/src/batch/diagnosis-retry-limbo.mjs +1 -1
  21. package/src/batch/diagnosis-tail-state.mjs +57 -0
  22. package/src/batch/diagnosis.mjs +22 -114
  23. package/src/batch/engine-lanes/commit.mjs +145 -0
  24. package/src/batch/engine-lanes/merge.mjs +1 -2
  25. package/src/batch/engine-lanes/review.mjs +124 -121
  26. package/src/batch/engine-lanes.mjs +21 -81
  27. package/src/batch/engine.mjs +46 -1
  28. package/src/batch/evidence.mjs +1 -2
  29. package/src/batch/git-exec.mjs +5 -2
  30. package/src/batch/heartbeat.mjs +2 -2
  31. package/src/batch/integrate-assert.mjs +69 -0
  32. package/src/batch/integrate-worktree.mjs +354 -0
  33. package/src/batch/integrate.mjs +195 -102
  34. package/src/batch/journal-rebuild.mjs +158 -3
  35. package/src/batch/journal.mjs +63 -0
  36. package/src/batch/lane-commit.mjs +6 -5
  37. package/src/batch/lane-dirty-check.mjs +513 -0
  38. package/src/batch/limbo-detect.mjs +34 -0
  39. package/src/batch/macro-phase.mjs +76 -0
  40. package/src/batch/metrics.mjs +2 -0
  41. package/src/batch/pause.mjs +18 -7
  42. package/src/batch/post-merge-limbo.mjs +3 -28
  43. package/src/batch/reconcile.mjs +79 -10
  44. package/src/batch/resume-common.mjs +27 -0
  45. package/src/batch/resume-multi-lanes.mjs +11 -0
  46. package/src/batch/resume-multi.mjs +3 -1
  47. package/src/batch/resume.mjs +8 -4
  48. package/src/batch/retry.mjs +41 -10
  49. package/src/batch/review-spawn.mjs +1 -1
  50. package/src/batch/review.mjs +0 -4
  51. package/src/batch/rules-manifest-drift.mjs +43 -2
  52. package/src/batch/sequence-state.mjs +290 -0
  53. package/src/batch/sequence.mjs +113 -51
  54. package/src/batch/state.mjs +16 -0
  55. package/src/batch/worker-host.mjs +14 -5
  56. package/src/cli/deps.mjs +0 -2
  57. package/src/cli/sequence.mjs +14 -1
  58. package/src/cli/settings-set.mjs +33 -3
  59. package/src/config/contract.mjs +10 -0
  60. package/src/config/model-id.mjs +103 -0
  61. package/src/config/spine-init-constants.mjs +1 -0
  62. package/src/config/spine-preflight-lib.mjs +23 -1
  63. package/src/dashboard/public/dashboard.css +8 -0
  64. package/src/dashboard/public/dashboard.js +36 -9
  65. package/src/dashboard/running-tail-state.mjs +31 -0
  66. package/src/dashboard/server.mjs +4 -0
  67. package/src/dashboard/snapshot.mjs +260 -29
  68. package/src/dashboard/view.mjs +112 -2
  69. package/src/doctor/agent-models.mjs +53 -0
  70. package/src/doctor/batch-size-guidance.mjs +30 -2
  71. package/src/doctor/pi-extension-conflict.mjs +169 -0
  72. package/src/doctor/run-doctor-checks.mjs +6 -0
  73. package/src/planner/scope.mjs +5 -1
  74. package/src/tasks/packet/parse-prompt.mjs +31 -1
  75. package/src/tasks/packet/validate-contract.mjs +108 -0
  76. package/src/tasks/packet/validate-prompt.mjs +0 -1
package/README.md CHANGED
@@ -4,14 +4,14 @@
4
4
 
5
5
  **Orchestration spine for long-running pi development.**
6
6
 
7
- pi-spine is a [pi](https://pi.dev) package for parallel, multi-day agent batches on real codebases. It combines Taskplane-style task packets, Babysitter-grade audit history, and pi-conductor-style human gates in one pi-native flow — **compose, don't merge** three orchestrators into a fourth monolith.
7
+ pi-spine is a [pi](https://pi.dev) package for parallel, multi-day agent batches on real codebases. It combines Taskplane-style task packets, Babysitter-grade audit history, and ~~pi-conductor~~-inspired human gates in one pi-native flow — **compose, don't merge** the best patterns into a single pi-native spine.
8
8
 
9
9
  | pi-spine is | pi-spine is not |
10
10
  |-------------|-----------------|
11
11
  | A pi extension + CLI (`spine`) for batch orchestration | A replacement for pi itself |
12
12
  | Compatible with Taskplane `PROMPT.md` / `STATUS.md` packets | A fork of Taskplane |
13
13
  | An append-only **orchestration journal** for control-plane events | A full Babysitter process-definition engine |
14
- | **Human gates** before integrate/merge | A clone of pi-conductor's external control-plane DB |
14
+ | **Human gates** before integrate/merge | A clone of ~~pi-conductor's~~ external control-plane DB (archived upstream) |
15
15
  | Worktree-isolated parallel lanes | Cross-harness routing (Cursor, Codex, etc.) in v1 |
16
16
 
17
17
  ## Feature summary
@@ -28,7 +28,7 @@ pi-spine is a [pi](https://pi.dev) package for parallel, multi-day agent batches
28
28
 
29
29
  ## Inspired by
30
30
 
31
- pi-spine builds on ideas from [Taskplane](https://pi.dev/packages/taskplane), [Babysitter](https://github.com/a5c-ai/babysitter), and [pi-conductor](https://www.npmjs.com/package/@feniix/pi-conductor). For comparisons, trade-offs, and when to use each tool alone, see **[Why pi-spine?](docs/adoption/why-pi-spine.md)**.
31
+ pi-spine builds on ideas from [Taskplane](https://pi.dev/packages/taskplane), [Babysitter](https://github.com/a5c-ai/babysitter), and [pi-conductor](https://www.npmjs.com/package/@feniix/pi-conductor) (archived). For comparisons, trade-offs, and when to use each tool alone, see **[Why pi-spine?](docs/adoption/why-pi-spine.md)**.
32
32
 
33
33
  ## Honest limits
34
34
 
@@ -138,7 +138,7 @@ CI runs on every push and PR: typecheck, tests, coverage, and CLI smoke checks
138
138
  | [docs/PRD.md](docs/PRD.md) | Product requirements and implementation contract |
139
139
  | [docs/QUICK-REFERENCE.md](docs/QUICK-REFERENCE.md) | Operator command reference |
140
140
  | [docs/EXECUTION-FLOW.md](docs/EXECUTION-FLOW.md) | Batch lifecycle and scheduling |
141
- | [docs/adoption/why-pi-spine.md](docs/adoption/why-pi-spine.md) | Positioning vs Taskplane, Babysitter, pi-conductor |
141
+ | [docs/adoption/why-pi-spine.md](docs/adoption/why-pi-spine.md) | Positioning vs Taskplane, Babysitter, pi-conductor (archived) |
142
142
  | [docs/adoption/operator-runbook.md](docs/adoption/operator-runbook.md) | Daily operator procedures |
143
143
  | [docs/adoption/bootstrap-checklist.md](docs/adoption/bootstrap-checklist.md) | First-time setup |
144
144
 
@@ -13,6 +13,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
13
 
14
14
  /** Modules >500 LOC grandfathered until v2.3 split (FR-SHIP-02 partial — engine-lanes split done). */
15
15
  export const PHASE23_GRANDFATHERED_OVER_500 = [
16
+ "src/batch/engine.mjs",
17
+ "src/batch/integrate.mjs",
16
18
  "src/batch/state.mjs",
17
19
  "src/batch/worker-host.mjs",
18
20
  "src/batch/reconcile.mjs",
@@ -20,6 +22,10 @@ export const PHASE23_GRANDFATHERED_OVER_500 = [
20
22
  "src/batch/review.mjs",
21
23
  "src/batch/resume-multi-lanes.mjs",
22
24
  "src/batch/resume.mjs",
25
+ "src/batch/sequence.mjs",
26
+ "src/batch/contract-verify.mjs",
27
+ "src/batch/journal-rebuild.mjs",
28
+ "src/batch/lane-dirty-check.mjs",
23
29
  ];
24
30
 
25
31
  const PHASE23_ENGINE_LANES_MAX = 500;
@@ -5,8 +5,6 @@
5
5
  * Inspect task dependency graph without running a full batch plan.
6
6
  */
7
7
 
8
- import path from 'node:path';
9
-
10
8
  import { isCliEntrypoint } from './spine-cli/shared.mjs';
11
9
  import { loadSpineConfig } from './spine-config.mjs';
12
10
  import { buildDepsReport, formatDepsHuman } from '../src/cli/deps.mjs';
@@ -30,6 +30,39 @@ function writePlanArtifact({ projectRoot, plan }) {
30
30
  return artifactPath;
31
31
  }
32
32
 
33
+ /**
34
+ * Format a friendly informational message when pending scope has zero tasks.
35
+ *
36
+ * @param {{ excludedCount?: number, discoveredCount?: number }} meta
37
+ * @param {{ maxParallel?: number }} laneConfig
38
+ * @param {{ json?: boolean }} options
39
+ */
40
+ function formatEmptyPendingResult({ excludedCount = 0, discoveredCount = 0 }, laneConfig, { json = false } = {}) {
41
+ if (json) {
42
+ const syntheticPlan = {
43
+ generatedAt: new Date().toISOString(),
44
+ scope: { mode: 'pending', taskIds: [] },
45
+ laneConfig,
46
+ waves: [],
47
+ tasks: {},
48
+ metadata: { tasksDiscovered: discoveredCount, tasksSelected: 0, tasksExcluded: excludedCount },
49
+ };
50
+ return { plan: syntheticPlan, artifactPath: null, output: JSON.stringify(syntheticPlan, null, 2) };
51
+ }
52
+
53
+ const lines = [
54
+ 'Spine plan — pending',
55
+ `0 task(s) · 0 wave(s) · maxParallel ${laneConfig.maxParallel ?? 1}`,
56
+ `${excludedCount} excluded (.DONE on disk)`,
57
+ '',
58
+ 'No pending tasks — all discovered tasks have .DONE on disk.',
59
+ '',
60
+ '\u2192 spine plan all',
61
+ '',
62
+ ];
63
+ return { plan: null, artifactPath: null, output: lines.join('\n') };
64
+ }
65
+
33
66
  export async function runSpinePlan({
34
67
  projectRoot = process.cwd(),
35
68
  scope = 'all',
@@ -49,7 +82,22 @@ export async function runSpinePlan({
49
82
  err.suggestedCommand = 'spine init';
50
83
  throw err;
51
84
  }
52
- const plan = buildPlan({ scope, config, tasksRoot });
85
+
86
+ let plan;
87
+ try {
88
+ plan = buildPlan({ scope, config, tasksRoot });
89
+ } catch (err) {
90
+ if (err?.code === 'NO_PENDING_TASKS') {
91
+ const laneConfig = { maxParallel: config.lanes?.maxParallel ?? 1 };
92
+ return formatEmptyPendingResult(
93
+ { excludedCount: err.excludedCount, discoveredCount: err.discoveredCount },
94
+ laneConfig,
95
+ { json },
96
+ );
97
+ }
98
+ throw err;
99
+ }
100
+
53
101
  const artifactPath = writePlanArtifact({ projectRoot, plan });
54
102
 
55
103
  if (json) {
@@ -8,8 +8,6 @@
8
8
  * spine rules sync [--json]
9
9
  */
10
10
 
11
- import path from "node:path";
12
-
13
11
  import { isCliEntrypoint } from "./spine-cli/shared.mjs";
14
12
  import { printRulesHelp, runSpineRules } from "../src/cli/rules.mjs";
15
13
 
@@ -8,8 +8,6 @@
8
8
  * spine settings set <path> <value> [--dry-run] [--json]
9
9
  */
10
10
 
11
- import path from "node:path";
12
-
13
11
  import { isCliEntrypoint } from "./spine-cli/shared.mjs";
14
12
  import { loadSpineConfig, loadSpineConfigFile } from "./spine-config.mjs";
15
13
  import { formatSettingsShow } from "../src/cli/settings-show.mjs";
@@ -29,9 +29,31 @@ import {
29
29
  import { reportTaskProgress } from "../src/worker-tools/report-progress.mjs";
30
30
  import { isCliEntrypoint } from "./spine-cli/shared.mjs";
31
31
  import { loadSpineConfig } from "./spine-config.mjs";
32
+ import { isStubDeliveryOnlyScope } from "../src/batch/contract-stub-delivery.mjs";
32
33
  import { writeWorkerDoneMarker } from "../src/batch/worker-output.mjs";
33
34
  import { buildWorkerTailPrompt, taskIdFromFolder } from "../src/batch/worker-prompt.mjs";
34
- import { parsePrompt } from "../src/tasks/packet/parse-prompt.mjs";
35
+ import { DEFAULT_TASKS_ROOT } from "../src/config/spine-init-constants.mjs";
36
+ import {
37
+ isPiExtensionConflictOutput,
38
+ shouldWorkerUsePiNoExtensions,
39
+ } from "../src/doctor/pi-extension-conflict.mjs";
40
+ import { parseContract, parsePrompt } from "../src/tasks/packet/parse-prompt.mjs";
41
+
42
+ /**
43
+ * Actionable hint when pi worker spawn fails on duplicate extension tool registration.
44
+ *
45
+ * @param {string} output
46
+ * @returns {string|null}
47
+ */
48
+ export function formatPiExtensionConflictHint(output) {
49
+ if (!isPiExtensionConflictOutput(output)) return null;
50
+ return [
51
+ "pi extension tool conflict detected (often duplicate pi-web-access npm + local checkout).",
52
+ "Batch workers pass pi -ne only when spine doctor detects duplicate pi-web-access sources.",
53
+ "Fix pi settings with `pi remove npm:pi-web-access -l` or remove the local path from",
54
+ "~/.pi/agent/settings.json, then retry the task.",
55
+ ].join(" ");
56
+ }
35
57
 
36
58
  function buildReviewJournal() {
37
59
  return resolveBatchJournalContext();
@@ -77,7 +99,13 @@ export async function buildWorkerPiArgs({
77
99
  ? path.join(worktreePath, ".spine", "agents", "worker.md")
78
100
  : null;
79
101
 
80
- const piArgs = ["-p", "--no-session"];
102
+ const projectRoot =
103
+ process.env.SPINE_RULES_PROJECT_ROOT || worktreePath || process.env.SPINE_PROJECT_ROOT || process.cwd();
104
+ const piArgs = [];
105
+ if (shouldWorkerUsePiNoExtensions({ projectRoot })) {
106
+ piArgs.push("-ne");
107
+ }
108
+ piArgs.push("-p", "--no-session");
81
109
  if (workerAgentPath && fs.existsSync(workerAgentPath)) {
82
110
  piArgs.push("--append-system-prompt", workerAgentPath);
83
111
  }
@@ -85,8 +113,6 @@ export async function buildWorkerPiArgs({
85
113
  piArgs.push(`@${promptPath}`);
86
114
  }
87
115
  appendWorkerAgentModelArgs(piArgs, spineConfig);
88
- const projectRoot =
89
- process.env.SPINE_RULES_PROJECT_ROOT || worktreePath || process.env.SPINE_PROJECT_ROOT || process.cwd();
90
116
  const taskFileScope = resolveTaskFileScope(taskFolder);
91
117
  const tailPrompt = await buildWorkerTailPrompt({
92
118
  worktreePath,
@@ -108,6 +134,105 @@ export async function buildWorkerPiArgs({
108
134
  * @param {string} taskFolder
109
135
  * @returns {string[]}
110
136
  */
137
+ const STUB_DELIVERY_CURRENT_STEP = "Complete";
138
+ const STUB_DELIVERY_STATUS = "✅ Complete";
139
+
140
+ /**
141
+ * Update STATUS.md header lines or append a minimal stub delivery block.
142
+ *
143
+ * @param {string} [existingContent]
144
+ * @returns {string}
145
+ */
146
+ export function applyStubDeliveryStatusBlock(existingContent = "") {
147
+ const lines = String(existingContent ?? "").split("\n");
148
+ let foundCurrentStep = false;
149
+ let foundStatus = false;
150
+ const updated = lines.map((line) => {
151
+ if (/^\*\*Current Step:\*\*/.test(line)) {
152
+ foundCurrentStep = true;
153
+ return `**Current Step:** ${STUB_DELIVERY_CURRENT_STEP}`;
154
+ }
155
+ if (/^\*\*Status:\*\*/.test(line)) {
156
+ foundStatus = true;
157
+ return `**Status:** ${STUB_DELIVERY_STATUS}`;
158
+ }
159
+ return line;
160
+ });
161
+
162
+ const additions = [];
163
+ if (!foundCurrentStep) {
164
+ additions.push(`**Current Step:** ${STUB_DELIVERY_CURRENT_STEP}`);
165
+ }
166
+ if (!foundStatus) {
167
+ additions.push(`**Status:** ${STUB_DELIVERY_STATUS}`);
168
+ }
169
+
170
+ if (additions.length === 0) {
171
+ return updated.join("\n");
172
+ }
173
+
174
+ const titleIdx = updated.findIndex((line) => /^#\s/.test(line));
175
+ if (titleIdx >= 0) {
176
+ let insertAt = titleIdx + 1;
177
+ if (insertAt < updated.length && updated[insertAt].trim() === "") {
178
+ insertAt += 1;
179
+ }
180
+ updated.splice(insertAt, 0, ...additions, "");
181
+ return updated.join("\n");
182
+ }
183
+
184
+ if (updated.length > 0 && updated[updated.length - 1].trim() !== "") {
185
+ updated.push("");
186
+ }
187
+ updated.push(...additions, "");
188
+ return updated.join("\n");
189
+ }
190
+
191
+ /**
192
+ * @param {string[]} patterns
193
+ */
194
+ function stubDeliveryRequiresStatusTouch(patterns) {
195
+ return patterns.some((pattern) => {
196
+ const normalized = String(pattern ?? "").replace(/\\/g, "/").trim();
197
+ if (normalized.includes("STATUS.md")) {
198
+ return true;
199
+ }
200
+ if (normalized.endsWith("/**")) {
201
+ return true;
202
+ }
203
+ return false;
204
+ });
205
+ }
206
+
207
+ /**
208
+ * When stub mode has delivery-only fileScopeMustChange, write STATUS.md before .DONE.
209
+ *
210
+ * @param {object} options
211
+ * @param {string} options.taskFolder
212
+ * @param {string} [options.tasksRoot]
213
+ * @returns {boolean} Whether STATUS.md was updated
214
+ */
215
+ export function writeStubDeliveryStatusIfNeeded({ taskFolder, tasksRoot = DEFAULT_TASKS_ROOT }) {
216
+ const promptPath = path.join(taskFolder, "PROMPT.md");
217
+ if (!fs.existsSync(promptPath)) {
218
+ return false;
219
+ }
220
+
221
+ const parsed = parseContract(fs.readFileSync(promptPath, "utf-8"));
222
+ const patterns = parsed.fileScopeMustChange ?? [];
223
+ if (!isStubDeliveryOnlyScope(patterns, tasksRoot)) {
224
+ return false;
225
+ }
226
+ if (!stubDeliveryRequiresStatusTouch(patterns)) {
227
+ return false;
228
+ }
229
+
230
+ const statusPath = path.join(taskFolder, "STATUS.md");
231
+ const existing = fs.existsSync(statusPath) ? fs.readFileSync(statusPath, "utf-8") : "";
232
+ fs.writeFileSync(statusPath, applyStubDeliveryStatusBlock(existing), "utf-8");
233
+ return true;
234
+ }
235
+
111
236
  function resolveTaskFileScope(taskFolder) {
112
237
  const envScope = process.env.SPINE_TASK_FILE_SCOPE;
113
238
  if (envScope) {
@@ -259,6 +384,8 @@ async function runWorkerRunner() {
259
384
 
260
385
  await enforceStubReviewIfConfigured(taskFolder, worktreePath);
261
386
 
387
+ writeStubDeliveryStatusIfNeeded({ taskFolder });
388
+
262
389
  const donePath = path.join(taskFolder, ".DONE");
263
390
  const stubTaskId = process.env.SPINE_TASK_ID || taskIdFromFolder(taskFolder) || "stub";
264
391
  writeWorkerDoneMarker(donePath, { taskId: stubTaskId });
@@ -306,6 +433,11 @@ async function runWorkerRunner() {
306
433
  }
307
434
 
308
435
  if (result.status !== 0) {
436
+ const combined = `${result.stderr ?? ""}${result.stdout ?? ""}`;
437
+ const conflictHint = formatPiExtensionConflictHint(combined);
438
+ if (conflictHint) {
439
+ console.error(conflictHint);
440
+ }
309
441
  process.stderr.write(result.stderr ?? "");
310
442
  process.stdout.write(result.stdout ?? "");
311
443
  process.exit(result.status ?? 1);
package/bin/spine.mjs CHANGED
@@ -25,12 +25,9 @@ import { handlePlan } from "./spine-cli/plan.mjs";
25
25
  import {
26
26
  c,
27
27
  die,
28
- FAIL,
29
28
  getPackageVersion,
30
29
  isCliEntrypoint,
31
- OK,
32
30
  PACKAGE_ROOT,
33
- WARN,
34
31
  } from "./spine-cli/shared.mjs";
35
32
  import { handleStatus } from "./spine-cli/status.mjs";
36
33
  import { handleLane } from "./spine-cli/lane-logs.mjs";
@@ -38,9 +35,9 @@ import { handleWatch } from "./spine-cli/watch.mjs";
38
35
  import { handleWait } from "./spine-cli/wait.mjs";
39
36
  import { handleScenarios } from "./spine-cli/scenarios.mjs";
40
37
  import { loadSpineConfig } from "./spine-config.mjs";
41
- import { cmdInit, SPINE_GITIGNORE_ENTRIES } from "./spine-init.mjs";
38
+ import { cmdInit } from "./spine-init.mjs";
42
39
  import { cmdMigrateFromTaskplane } from "./spine-migrate-from-taskplane.mjs";
43
- import { runDoctorChecks, cmdDoctor } from "./spine-doctor.mjs";
40
+ import { cmdDoctor } from "./spine-doctor.mjs";
44
41
 
45
42
  export { runDoctorChecks } from "./spine-doctor.mjs";
46
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "scripts": {
30
30
  "doctor": "node bin/spine.mjs doctor",
31
- "lint": "eslint src bin tests scripts",
31
+ "lint": "eslint --max-warnings 0 src bin tests scripts",
32
32
  "typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
33
33
  "test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
34
34
  "test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
@@ -285,7 +285,7 @@ Use [references/prompt-template.md](references/prompt-template.md). Spine-specif
285
285
  - **Worker tools** — when Review Level > 0, steps must note `spine_review_step` after each step
286
286
  - **Testing step (required for all tasks)** — every packet MUST include `### Step N: Testing & Verification` inside `## Steps`, placed **before** `## Completion Criteria`. This applies to **docs-only Review Level 0 tasks** as well — omitting the step causes `prompt_parse_failed` at batch launch (SP-075). Docs-only tasks still run the full test suite; they may omit the coverage-gate checkbox when no application code changes.
287
287
  - **Coverage gate** — when the task changes application code, add a coverage verification checkbox in the Testing step using `testing.testWithCoverage` (≥77% line coverage policy)
288
- - **Contract (required for new SP-\* tasks)** — add `## Contract` after `## File Scope` using [references/contract-template.md](references/contract-template.md). Include `testCommand` for code tasks; use `` `true` `` for docs-only S tasks. Legacy `TP-*` packets may omit Contract when `contract.legacyTaskIdPrefixes` includes `TP-`.
288
+ - **Contract (required for new SP-\* tasks)** — add `## Contract` after `## File Scope` using [references/contract-template.md](references/contract-template.md). Include `testCommand` for code tasks; use `` `true` `` for docs-only S tasks. When using `fileScopeMustNotChange`, follow parallel-only semantics and never ban `spine-tasks/**` (see contract template and [File Scope and parallel batches](#file-scope-and-parallel-batches)). Legacy `TP-*` packets may omit Contract when `contract.legacyTaskIdPrefixes` includes `TP-`.
289
289
  - **Completion** — worker creates `{task-folder}/.DONE`; batch engine may auto-commit remaining work
290
290
 
291
291
  ### Step 5: Create STATUS.md
@@ -438,6 +438,10 @@ Task IDs in JSON use the **folder slug** (full `SP-011-api-handlers`) or bare ID
438
438
 
439
439
  When decomposing a PRD, assign non-overlapping file scopes to tasks that should run in parallel.
440
440
 
441
+ **`fileScopeMustNotChange` (parallel lanes only):** When a packet includes `fileScopeMustNotChange` in `## Contract`, use it only to guard **product paths that concurrent tasks on different lanes** must not edit in the same wave — not to isolate paths touched by **prior serialized tasks** on the same lane. When `spine plan` reports `File scope overlaps (tasks serialized to the same lane)`, those tasks run sequentially on one lane; use disjoint `fileScopeMustChange` paths instead of relying on must-not-change. Full semantics and examples: [references/contract-template.md](references/contract-template.md#filescopemustnotchange-semantics).
442
+
443
+ **Never ban `spine-tasks/**`:** Do **not** list `spine-tasks/**` or the **current task folder** in `fileScopeMustNotChange`. Workers must update `STATUS.md`, create `.DONE`, and may write `.reviews/` — banning those paths causes `contract.verified` failures even when implementation is correct.
444
+
441
445
  **Worker rules:** File Scope also drives **glob-matched Cursor rules** injected into batch workers (FR-WORK-05). Tasks touching `**/*.{js,mjs}` activate JS standards; Swift/Python tasks need scope paths that match those rule globs. Keep scope precise — wide scope pulls more rules and increases prompt byte usage.
442
446
 
443
447
  **Reviewer rules (FR-REV-08):** Plan reviews use the same File Scope for glob matching; code reviews use changed paths from `git diff`. Final reviews load always-on rules only. Worker-only packs (`taskplane-worker-cursor.mdc`) are excluded from reviewer context by default.
@@ -483,7 +487,8 @@ Hydration commits (STATUS.md expansions) may happen mid-step for crash recovery.
483
487
 
484
488
  ## Key Principles
485
489
 
486
- - **Self-contained PROMPT.md** — the worker has no memory of this conversation.
490
+ - **Self-contained PROMPT.md** — the worker has no memory of this conversation. Cross-model reviewers receive a **fresh spawn** (FR-REV-04) with only the review request, diff, and Contract — not `referenceDocs` or worker rules. Place acceptance criteria and spec references in PROMPT `## Mission`, `## Contract`, and step checkboxes.
491
+ - **Scoped `testCommand` for cross-model batches** — lane worktrees differ from dev checkouts; broad `flutter test` / `npm test` can fail in lanes even when targeted tests pass. See [cross-model authoring guidance](references/contract-template.md#cross-model-authoring-worker--reviewer) for the `testCommand` decision table.
487
492
  - **Testing step required (never omit)** — every task packet needs `### Step N: Testing & Verification` inside `## Steps`, before `## Completion Criteria`. **Do not skip this for docs-only or Review Level 0 tasks** — the worker rejects packets without a Testing step. Use `testing.test` from spine config; for **code deliverables**, also include `testing.testWithCoverage` and a **≥77% line coverage** checkbox (see prompt template). Docs-only tasks may omit the coverage checkbox.
488
493
  - **Documentation in every task** — "Must Update" / "Check If Affected" prevent doc drift.
489
494
  - **Concrete deliverables** — name files to create/modify; avoid shortcuttable vague steps.
@@ -22,6 +22,14 @@ Normative schema: [PRD v2.0 implementation handoff §4](../../docs/PRD-v2.0-impl
22
22
  | artifactsMustExist | `tests/batch/final-verdict.test.mjs` |
23
23
  ```
24
24
 
25
+ **Path list formatting:** wrap each path in its own backticks. Do **not** put multiple comma-separated paths inside one pair:
26
+
27
+ ```markdown
28
+ | fileScopeMustChange | `bin/a.mjs`, `bin/b.mjs` |
29
+ ```
30
+
31
+ Avoid `` `bin/a.mjs,bin/b.mjs` `` — `tasks validate` warns (or errors in required mode) and the parser must recover for legacy packets.
32
+
25
33
  ---
26
34
 
27
35
  ## Field guidance
@@ -29,10 +37,10 @@ Normative schema: [PRD v2.0 implementation handoff §4](../../docs/PRD-v2.0-impl
29
37
  | Field | When to include | Value format |
30
38
  |-------|-----------------|--------------|
31
39
  | `testCommand` | **Required** for code tasks (Review Level ≥ 1, Size M/L, or implementation steps) | Shell command in backticks; max 500 chars; no newlines. Use `` `true` `` for docs-only S tasks with no code changes. |
32
- | `fileScopeMustChange` | When you need proof specific paths were touched | Comma-separated paths/globs relative to repo root |
33
- | `fileScopeMustNotChange` | When parallel tasks must not collide | Comma-separated paths/globs |
40
+ | `fileScopeMustChange` | When you need proof specific paths were touched | Comma-separated paths/globs relative to repo root; **one backtick per path** (not `` `a.mjs,b.mjs` ``). Trailing `/` means directory prefix match (e.g. `src/domain/types/` matches any file under that directory). |
41
+ | `fileScopeMustNotChange` | When **parallel lanes** must not collide on product paths (see semantics below) | Comma-separated paths/globs relative to repo root; **one backtick per path** |
34
42
  | `minLineCoverage` | When task changes application code | Integer 0–100 (pi-spine policy: **77**) |
35
- | `artifactsMustExist` | When deliverables must exist on disk | Comma-separated file paths |
43
+ | `artifactsMustExist` | When deliverables must exist on disk | Comma-separated file paths; **one backtick per path** |
36
44
  | `stallTimeoutMinutes` | Long external jobs (operator matrix, CI arms) exceeding global/size stall budget | Positive integer minutes; engine uses `max(global, size floor, contract)` |
37
45
  | `extendGraceOnFileScope` | STATUS-only progress during long external work | `true` or `false`; when `true`, file-scope mtime extends stall grace for this task |
38
46
 
@@ -40,6 +48,50 @@ Unknown field names produce **warnings** at validate time (not errors). Duplicat
40
48
 
41
49
  ---
42
50
 
51
+ ## `fileScopeMustNotChange` semantics
52
+
53
+ **Parallel lanes only.** Use this field to guard product paths that **concurrent tasks on different lanes** must not edit in the same wave. It is **not** for isolating paths touched by **prior serialized tasks** on the same lane.
54
+
55
+ **How verify works today:** Final contract verify compares changed files on the lane branch against each pattern (currently `main...HEAD` cumulative diff until per-task scoping lands in SP-416). On a serialized lane, commits from earlier tasks remain in that diff — so `fileScopeMustNotChange` can fail even when the current worker behaved correctly.
56
+
57
+ **Planner overlap warning:** When `spine plan` reports:
58
+
59
+ ```text
60
+ File scope overlaps (tasks serialized to the same lane):
61
+ Wave N: SP-AAA ↔ SP-BBB
62
+ ```
63
+
64
+ those tasks run **sequentially on one lane**, not in parallel. Do **not** rely on `fileScopeMustNotChange` to separate them; use distinct `fileScopeMustChange` paths or accept cumulative diff semantics until per-task verify ships. The overlap warning means **concurrency is already prevented** — `fileScopeMustNotChange` targets **different lanes** editing the same product path in the same wave.
65
+
66
+ ### Never ban `spine-tasks/**`
67
+
68
+ Workers **must** update `STATUS.md`, create `.DONE`, and may write `.reviews/`. These orchestration artifacts are not product-code scope violations.
69
+
70
+ - **Never** list `spine-tasks/**` in `fileScopeMustNotChange`.
71
+ - **Never** list the **current task folder** (e.g. `spine-tasks/SP-410-*/**`) — it blocks required worker outputs.
72
+
73
+ **Good** (parallel collision guard on product paths):
74
+
75
+ ```markdown
76
+ | fileScopeMustNotChange | `extension/**`, `.spine/**` |
77
+ ```
78
+
79
+ **Bad** (blocks required worker artifacts — fails `contract.verified` even when implementation is correct):
80
+
81
+ ```markdown
82
+ | fileScopeMustNotChange | `extension/**`, `.spine/**`, `spine-tasks/**` |
83
+ ```
84
+
85
+ **Bad** (blocks current task's `STATUS.md` and `.DONE`):
86
+
87
+ ```markdown
88
+ | fileScopeMustNotChange | `spine-tasks/SP-410-contract-template-parallel-semantics/**` |
89
+ ```
90
+
91
+ Symptom in journal: `testCommand` passes but `fileScopeMustNotChange` fails with messages like `forbidden change spine-tasks/SP-001/STATUS.md` or `.DONE`.
92
+
93
+ ---
94
+
43
95
  ## Examples
44
96
 
45
97
  ### Minimal S task (code change)
@@ -106,6 +158,46 @@ Recommended: **240** minutes for jobs expected to run 2+ hours. Size S floor (90
106
158
 
107
159
  ---
108
160
 
161
+ ## Cross-model authoring (worker ≠ reviewer)
162
+
163
+ When the worker model differs from the reviewer model (e.g. worker `cursor/auto`, reviewer `google/gemini-3.1-pro-preview`), contract shape directly affects review outcomes. The most common cross-model failure is `review_exhausted` caused by broad `testCommand` or missing context — not reviewer rejection of code quality.
164
+
165
+ ### Scoped `testCommand`
166
+
167
+ Lane worktrees are **not** identical to the developer checkout. Worktree setup hooks, missing assets, pre-existing test failures, and Flutter/monorepo full-suite pollution can cause a scoped worker to pass targeted tests while the unscoped `testCommand` in Contract fails at final verify.
168
+
169
+ | Avoid | Prefer |
170
+ |-------|--------|
171
+ | `` `flutter test` `` / `` `npm test` `` (full suite in lane worktree) | Targeted command matching the Testing step: `` `flutter test test/unit/services/foo_test.dart` `` |
172
+ | Same command in Contract and global `testing.test` without verifying lane compatibility | Document when to use `` `true` `` (docs-only) vs scoped shell proof |
173
+ | Unscoped command producing >10 MB stdout (SP-426 `maxBuffer`) | Narrow test scope; prefer `npm test -- tests/feature.test.mjs` |
174
+
175
+ **Engine-side lane fixes:** [#78](https://github.com/beettlle/pi-spine/issues/78), [#80](https://github.com/beettlle/pi-spine/issues/80) track worktree setup hook and analyzer hygiene — docs alone cannot fix lane environment drift.
176
+
177
+ ### Self-contained PROMPT for independent reviewers
178
+
179
+ Reviewers spawn as **fresh sessions** with no memory of the worker session (FR-REV-04). Cross-model reviewers receive:
180
+
181
+ | Worker sees | Reviewer sees |
182
+ |-------------|---------------|
183
+ | `taskplane-worker-cursor.mdc`, glob-matched language standards | Bounded rule subset via `profile.reviewer.*` (FR-REV-08); worker/authoring rules excluded |
184
+ | `referenceDocs` (e.g. `docs/constitution.md`) | **Not** auto-loaded; 16 KiB rule cap |
185
+ | Full PROMPT + STATUS in session, accumulated context | Fresh spawn; review request + diff + Contract only |
186
+
187
+ **Authoring implication:** Place acceptance criteria, spec references, and "done means" in PROMPT `## Mission`, `## Contract`, and step checkboxes — do not assume the reviewer read `IMPLEMENTATION.md`, domain plans, or `referenceDocs` unless quoted verbatim in PROMPT.
188
+
189
+ ### `testCommand` decision table
190
+
191
+ | Task type | Recommended `testCommand` |
192
+ |-----------|---------------------------|
193
+ | Docs-only, no code changes | `` `true` `` |
194
+ | Single module, targeted tests exist | `` `npm test -- tests/feature.test.mjs` `` or `` `flutter test test/unit/services/foo_test.dart` `` |
195
+ | Full-suite safe in lane worktree | `` `npm run typecheck && SPINE_WORKER_STUB=1 npm test` `` |
196
+ | Coverage gate required (pi-spine ≥77%) | `` `npm run coverage:check` `` |
197
+ | Long external job (>2h) | Scoped command + `stallTimeoutMinutes` and `extendGraceOnFileScope` in Contract (see SP-314 example above) |
198
+
199
+ ---
200
+
109
201
  ## Validate before plan
110
202
 
111
203
  After authoring packets, run:
@@ -14,7 +14,6 @@ import {
14
14
  import { loadGateRecord } from "./gate.mjs";
15
15
  import { appendJournalEvent } from "./journal.mjs";
16
16
  import {
17
- finalizeBatchForIntegrate,
18
17
  isPostMergeLimbo,
19
18
  tryFinalizePostMergeLimbo,
20
19
  } from "./post-merge-limbo.mjs";