pi-spine 1.4.0 → 1.6.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 (36) hide show
  1. package/bin/spine-batch.mjs +3 -2
  2. package/bin/spine.mjs +12 -0
  3. package/extensions/spine/slash-commands.ts +170 -1
  4. package/package.json +6 -3
  5. package/skills/create-spine-tasks/SKILL.md +13 -1
  6. package/skills/create-spine-tasks/references/contract-template.md +6 -3
  7. package/skills/create-spine-tasks/references/requirements-checklist-template.md +1 -0
  8. package/skills/spine-orchestrate-waves/SKILL.md +200 -0
  9. package/skills/spine-orchestrate-waves/references/outer-loop.md +165 -0
  10. package/skills/spine-release-operator/SKILL.md +341 -0
  11. package/skills/spine-release-operator/references/issue-intake-checklist.md +107 -0
  12. package/skills/spine-release-operator/references/issue-template.md +51 -0
  13. package/skills/spine-release-operator/references/release-manifest-template.md +76 -0
  14. package/skills/spine-release-operator/references/release-profiles.md +100 -0
  15. package/src/batch/batch-state-io.mjs +137 -0
  16. package/src/batch/contract-prelanded.mjs +116 -14
  17. package/src/batch/contract-verify.mjs +48 -2
  18. package/src/batch/diagnosis-alternatives.mjs +8 -0
  19. package/src/batch/diagnosis.mjs +28 -2
  20. package/src/batch/engine-lanes/commit.mjs +6 -0
  21. package/src/batch/engine.mjs +10 -1
  22. package/src/batch/integrate-worktree.mjs +65 -15
  23. package/src/batch/lane-dirty-check.mjs +124 -0
  24. package/src/batch/lifecycle.mjs +10 -6
  25. package/src/batch/reconcile.mjs +254 -0
  26. package/src/batch/sequence-waves.mjs +221 -0
  27. package/src/batch/sequence.mjs +117 -4
  28. package/src/batch/state.mjs +18 -1
  29. package/src/cli/batch-complete.mjs +16 -0
  30. package/src/cli/sync-base.mjs +354 -0
  31. package/src/config/defaults.mjs +8 -1
  32. package/src/config/spine-preflight-lib.mjs +146 -2
  33. package/src/doctor/agents-model-inherit.mjs +318 -0
  34. package/src/doctor/run-doctor-checks.mjs +14 -0
  35. package/templates/spine-config.json +4 -0
  36. package/templates/spine-worktree-setup-flutter.sh +44 -0
@@ -0,0 +1,76 @@
1
+ # Release manifest — v{TARGET_VERSION}
2
+
3
+ **Created:** {YYYY-MM-DD}
4
+ **Current version:** {from package.json}
5
+ **Target version:** v{TARGET_VERSION}
6
+ **Bump type:** patch | minor | major
7
+ **Profile:** patch | minor | major
8
+ **Operator approved scope:** no | yes ({date})
9
+
10
+ ---
11
+
12
+ ## Composition audit
13
+
14
+ | Bucket | Selected | Profile limit | Status |
15
+ |--------|----------|---------------|--------|
16
+ | Documentation | {n} | {profile limit} | PASS / WARN |
17
+ | Bug fixes | {n} | 3–5 | PASS / WARN |
18
+ | Enhancements | {n} | {profile limit} | PASS / WARN |
19
+ | **Total tasks** | {n} | {profile cap} | PASS / WARN |
20
+
21
+ **Profile audit:** PASS | PASS with operator override | FAIL (do not proceed)
22
+
23
+ ---
24
+
25
+ ## Selected tasks
26
+
27
+ | SP-ID | Issue | Bucket | Size | Title | Notes |
28
+ |-------|-------|--------|------|-------|-------|
29
+ | SP-### | #NNN | doc / bug / enh | S/M | … | Closes / Partial |
30
+
31
+ **Release scope ID:** comma-separated SP-IDs for `spine plan` / `spine batch start` (e.g. `SP-483,SP-460,SP-438`)
32
+
33
+ ---
34
+
35
+ ## Gaps requiring new packets
36
+
37
+ | Issue | Bucket | Proposed SP-ID | Author with |
38
+ |-------|--------|----------------|-------------|
39
+ | #90 | doc | SP-### | create-spine-tasks (lean) |
40
+
41
+ ---
42
+
43
+ ## Wave plan snapshot
44
+
45
+ ```text
46
+ (paste output of: spine plan <release-scope>)
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Deferred backlog
52
+
53
+ | Item | Type | Rationale |
54
+ |------|------|-----------|
55
+ | SP-### / #NNN | enh | Exceeds patch profile; defer to v1.6.0 |
56
+ | #117 | epic | v2.3 module split — out of minor scope |
57
+
58
+ ---
59
+
60
+ ## Risks and blockers
61
+
62
+ - {e.g. 7 M-sized tasks in full pending plan — release scope excludes them}
63
+ - {e.g. #156 release CI gate — separate enhancement}
64
+
65
+ ---
66
+
67
+ ## Publish checklist (Phase 5–6)
68
+
69
+ - [ ] All release-scoped tasks `.DONE` on `main`
70
+ - [ ] `spine preflight` green
71
+ - [ ] `npm run release:check` green (typecheck, lint, tests, coverage — CI parity)
72
+ - [ ] `git status` clean
73
+ - [ ] Operator approved publish bump type: patch | minor | major
74
+ - [ ] `npm version <bump>` + `git push && git push --tags`
75
+ - [ ] `release.yml` succeeded
76
+ - [ ] Post-publish smoke per `docs/release/npm-publish.md`
@@ -0,0 +1,100 @@
1
+ # Release profiles (semver-driven scope)
2
+
3
+ Use at **Phase 2** after parsing the operator's target version. Compare `package.json` version to the target to derive bump type.
4
+
5
+ ## Derive bump type
6
+
7
+ | Current → Target | Bump type | Profile |
8
+ |------------------|-----------|---------|
9
+ | `1.5.0` → `1.5.1` | **patch** | `patch` |
10
+ | `1.5.0` → `1.6.0` | **minor** | `minor` |
11
+ | `1.5.0` → `2.0.0` | **major** | `major` |
12
+
13
+ If the operator says only `patch` / `minor` / `major` without a version, compute the next version from `package.json` and record both in the manifest.
14
+
15
+ ## Invocation parsing
16
+
17
+ | Operator says | Profile |
18
+ |---------------|---------|
19
+ | "release for v1.5.1", "patch release", "hotfix release" | `patch` |
20
+ | "release for v1.6.0", "minor release", "feature release" | `minor` |
21
+ | "release for v2.0.0", "major release", "breaking release" | `major` |
22
+ | "run a spine release cycle" (no version) | **Ask** operator for target version or bump type |
23
+
24
+ ## Profile budgets
25
+
26
+ ### Patch (`patch`)
27
+
28
+ Stability and correctness focus. Smallest release window.
29
+
30
+ | Bucket | Target | Hard limits |
31
+ |--------|--------|-------------|
32
+ | Documentation | 1–2 small fixes/clarifications | No new feature docs; defer large doc epics |
33
+ | Bug fixes | 3–5 | Primary focus; prefer S-sized |
34
+ | Enhancements | **0** | Defer all; warn if operator insists without override |
35
+ | Total tasks | **5–8** | Warn if >8 without override |
36
+ | Max waves | 1–2 | Prefer single wave when possible |
37
+ | Task sizes | **S only** | Split any M/L before inclusion |
38
+
39
+ **Defer by default:** all enhancements, M/L tasks, epics, roadmap items, skill authoring clusters unless trivial typo fixes.
40
+
41
+ ### Minor (`minor`)
42
+
43
+ Balance new capability with stability.
44
+
45
+ | Bucket | Target | Hard limits |
46
+ |--------|--------|-------------|
47
+ | Documentation | 2–4 | Include docs for the chosen enhancement |
48
+ | Bug fixes | 3–5 | Same as patch |
49
+ | Enhancements | **1–2** | At most one M if split into safe waves |
50
+ | Total tasks | **10–15** | Warn if >15 without override |
51
+ | Max waves | 2–4 | ≤4 M-sized tasks per wave |
52
+ | Task sizes | S/M | Split L/XL before inclusion |
53
+
54
+ **Defer by default:** epics (#117 v2.3 module split), multi-enhancement batches, tasks requiring >4 waves.
55
+
56
+ ### Major (`major`)
57
+
58
+ Breaking changes and large migrations. Operator-defined epic scope.
59
+
60
+ | Bucket | Target | Hard limits |
61
+ |--------|--------|-------------|
62
+ | Documentation | Migration guides + comprehensive pass | Required for breaking changes |
63
+ | Bug fixes | 3–5 critical | Prioritize regressions blocking migration |
64
+ | Enhancements | Multiple allowed | Breaking API changes OK with migration path |
65
+ | Total tasks | Operator-defined | Manifest must list explicit epic boundaries |
66
+ | Max waves | Planned in manifest | Expect multi-cycle execution |
67
+
68
+ **Require:** explicit operator approval of epic scope before Phase 3. Do not auto-select major scope from backlog alone.
69
+
70
+ ## Selection order (all profiles)
71
+
72
+ Apply in this order; stop when profile budget is full:
73
+
74
+ 1. **Documentation** — `label:documentation`, `skill:create-spine-tasks` doc issues, pending docs-only SP-* tasks
75
+ 2. **Bug fixes** — open `label:bug` with user impact; prefer already-tasked or quick S
76
+ 3. **Enhancements** — only if profile allows; one user-visible improvement per minor release
77
+
78
+ ## Profile audit (must pass before Phase 3)
79
+
80
+ Fill the composition audit table in the manifest. Fail or warn when:
81
+
82
+ | Check | Patch | Minor | Major |
83
+ |-------|-------|-------|-------|
84
+ | Enhancement count | >0 without override | >2 without override | — |
85
+ | Bug count | <3 or >5 without override | <3 or >5 without override | <3 without override |
86
+ | Total tasks | >8 without override | >15 without override | — |
87
+ | M/L tasks in patch | any without override | — | — |
88
+ | Doc paths in File Scope | required for doc tasks (#144) | required | required |
89
+
90
+ Record `Profile audit: PASS` or `PASS with operator override` before proceeding.
91
+
92
+ ## Version ↔ publish alignment
93
+
94
+ The bump type chosen in Phase 2 must match `npm version` in Phase 6:
95
+
96
+ - `patch` profile → `npm version patch`
97
+ - `minor` profile → `npm version minor`
98
+ - `major` profile → `npm version major`
99
+
100
+ If the operator changes bump type at publish gate, update the manifest and confirm scope still fits the new profile.
@@ -4,9 +4,23 @@
4
4
 
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
+ import { isProcessAlive } from "../process/liveness.mjs";
7
8
  import { parseSpineBatchState } from "./readers/spine-state.mjs";
8
9
  import { parseTaskplaneBatchState } from "./readers/taskplane-state.mjs";
9
10
 
11
+ /** Terminal phases safe to clear before a new batch start (SP-441 / #94). */
12
+ const TERMINAL_PHASES_FOR_HANDOFF = new Set(["completed", "failed", "aborted", "merge_blocked"]);
13
+
14
+ /** Phases that block batch start while still active on disk. */
15
+ const ACTIVE_PHASES_FOR_HANDOFF = new Set([
16
+ "planning",
17
+ "running",
18
+ "paused",
19
+ "merging",
20
+ "executing",
21
+ "stopped",
22
+ ]);
23
+
10
24
  /**
11
25
  * @param {string} projectRoot
12
26
  */
@@ -51,3 +65,126 @@ export function parseBatchState(raw, batchStatePath) {
51
65
  }
52
66
  return parseSpineBatchState(raw) ?? parseTaskplaneBatchState(raw);
53
67
  }
68
+
69
+ /**
70
+ * @param {unknown} raw
71
+ * @returns {string}
72
+ */
73
+ export function readBatchStateId(raw) {
74
+ if (!raw || typeof raw !== "object") return "";
75
+ /** @type {Record<string, unknown>} */
76
+ const state = /** @type {Record<string, unknown>} */ (raw);
77
+ return String(state.batchId ?? state.id ?? "").trim();
78
+ }
79
+
80
+ /**
81
+ * @param {unknown} raw
82
+ * @returns {string}
83
+ */
84
+ export function readBaseBranchHeadAtStart(raw) {
85
+ if (!raw || typeof raw !== "object") return "";
86
+ return String(/** @type {{ baseBranchHeadAtStart?: string }} */ (raw).baseBranchHeadAtStart ?? "").trim();
87
+ }
88
+
89
+ /**
90
+ * @param {unknown} raw
91
+ * @returns {string}
92
+ */
93
+ export function readIntegrateWorktreePath(raw) {
94
+ if (!raw || typeof raw !== "object") return "";
95
+ return String(/** @type {{ integrateWorktreePath?: string }} */ (raw).integrateWorktreePath ?? "").trim();
96
+ }
97
+
98
+ /**
99
+ * @param {unknown} raw
100
+ * @returns {number|null}
101
+ */
102
+ export function readBatchStateEnginePid(raw) {
103
+ if (!raw || typeof raw !== "object") return null;
104
+ /** @type {Record<string, unknown>} */
105
+ const state = /** @type {Record<string, unknown>} */ (raw);
106
+ const resilience =
107
+ state.resilience && typeof state.resilience === "object"
108
+ ? /** @type {Record<string, unknown>} */ (state.resilience)
109
+ : null;
110
+ const fromResilience = Number(resilience?.enginePid);
111
+ if (Number.isFinite(fromResilience) && fromResilience > 0) return fromResilience;
112
+ const topLevel = Number(state.enginePid);
113
+ if (Number.isFinite(topLevel) && topLevel > 0) return topLevel;
114
+ return null;
115
+ }
116
+
117
+ /**
118
+ * Remove active batch-state only when on-disk batch matches expected (SP-441 / #94).
119
+ * Prevents complete/dismiss from clearing a newer batch after a concurrent start handoff.
120
+ *
121
+ * @param {string|null} batchStatePath
122
+ * @param {string} expectedBatchId
123
+ * @returns {{ cleared: boolean, reason?: string, activeBatchId?: string }}
124
+ */
125
+ export function clearActiveBatchStateIfMatches(batchStatePath, expectedBatchId) {
126
+ if (!batchStatePath || !fs.existsSync(batchStatePath)) {
127
+ return { cleared: false, reason: "missing" };
128
+ }
129
+
130
+ try {
131
+ const onDisk = JSON.parse(fs.readFileSync(batchStatePath, "utf-8"));
132
+ const onDiskBatchId = readBatchStateId(onDisk);
133
+ if (onDiskBatchId && onDiskBatchId !== expectedBatchId) {
134
+ return {
135
+ cleared: false,
136
+ reason: "batch_id_mismatch",
137
+ activeBatchId: onDiskBatchId,
138
+ };
139
+ }
140
+ } catch {
141
+ // Corrupt active state — remove so a new batch can start cleanly.
142
+ }
143
+
144
+ fs.unlinkSync(batchStatePath);
145
+ return { cleared: true };
146
+ }
147
+
148
+ /**
149
+ * Clear a terminal completed batch-state pointer before spine batch start (SP-441 / #94).
150
+ *
151
+ * @param {string} projectRoot
152
+ * @returns {{ cleared: boolean, reason?: string, batchId?: string }}
153
+ */
154
+ export function clearStaleTerminalBatchStateForStart(projectRoot) {
155
+ const resolved = resolveBatchStatePath(projectRoot);
156
+ if (!resolved || !fs.existsSync(resolved)) {
157
+ return { cleared: false, reason: "missing" };
158
+ }
159
+
160
+ /** @type {unknown} */
161
+ let raw;
162
+ try {
163
+ raw = JSON.parse(fs.readFileSync(resolved, "utf-8"));
164
+ } catch {
165
+ fs.unlinkSync(resolved);
166
+ return { cleared: true, reason: "corrupt" };
167
+ }
168
+
169
+ const batchId = readBatchStateId(raw);
170
+ const phase = String(/** @type {{ phase?: string }} */ (raw)?.phase ?? "");
171
+ const ownerPid = readBatchStateEnginePid(raw);
172
+
173
+ if (ACTIVE_PHASES_FOR_HANDOFF.has(phase) && !/** @type {{ endedAt?: unknown }} */ (raw)?.endedAt) {
174
+ return { cleared: false, reason: "active", batchId };
175
+ }
176
+
177
+ if (ownerPid && isProcessAlive(ownerPid)) {
178
+ throw new Error(
179
+ `Active batch ${batchId || "(unknown)"} engine still running (pid=${ownerPid}). ` +
180
+ "Wait for it to exit or run spine batch dismiss before spine batch start.",
181
+ );
182
+ }
183
+
184
+ if (TERMINAL_PHASES_FOR_HANDOFF.has(phase) || /** @type {{ endedAt?: unknown }} */ (raw)?.endedAt) {
185
+ fs.unlinkSync(resolved);
186
+ return { cleared: true, reason: "stale_terminal", batchId };
187
+ }
188
+
189
+ return { cleared: false, reason: "idle", batchId };
190
+ }
@@ -35,22 +35,22 @@ function gitFirstCommitTouchingPath(worktreePath, relPath) {
35
35
 
36
36
  /**
37
37
  * @param {string} worktreePath
38
- * @param {string} sinceCommit
39
- * @param {string} baseRef
40
- * @param {string} pattern
38
+ * @param {string} refA
39
+ * @param {string} refB
40
+ * @param {string} [pathspec]
41
41
  */
42
- function listPathsChangedSinceCommit(worktreePath, sinceCommit, baseRef, pattern) {
42
+ function listPathsChangedBetweenRefs(worktreePath, refA, refB, pathspec = "") {
43
43
  try {
44
- const output = execFileSync(
45
- "git",
46
- ["diff", "--name-only", `${sinceCommit}..${baseRef}`, "--", pattern],
47
- {
48
- cwd: worktreePath,
49
- encoding: "utf-8",
50
- stdio: ["ignore", "pipe", "pipe"],
51
- timeout: 10_000,
52
- },
53
- );
44
+ const args = ["diff", "--name-only", `${refA}..${refB}`];
45
+ if (pathspec) {
46
+ args.push("--", pathspec);
47
+ }
48
+ const output = execFileSync("git", args, {
49
+ cwd: worktreePath,
50
+ encoding: "utf-8",
51
+ stdio: ["ignore", "pipe", "pipe"],
52
+ timeout: 10_000,
53
+ });
54
54
  return output
55
55
  .split(/\r?\n/)
56
56
  .map((line) => line.trim())
@@ -60,6 +60,27 @@ function listPathsChangedSinceCommit(worktreePath, sinceCommit, baseRef, pattern
60
60
  }
61
61
  }
62
62
 
63
+ /**
64
+ * @param {string} file
65
+ * @param {string} pattern
66
+ */
67
+ function matchesScopePattern(file, pattern) {
68
+ if (pattern.endsWith("/")) {
69
+ return file.startsWith(pattern);
70
+ }
71
+ return matchesPattern(file, pattern);
72
+ }
73
+
74
+ /**
75
+ * @param {string} worktreePath
76
+ * @param {string} sinceCommit
77
+ * @param {string} baseRef
78
+ * @param {string} pattern
79
+ */
80
+ function listPathsChangedSinceCommit(worktreePath, sinceCommit, baseRef, pattern) {
81
+ return listPathsChangedBetweenRefs(worktreePath, sinceCommit, baseRef, pattern);
82
+ }
83
+
63
84
  /**
64
85
  * @param {string} worktreePath
65
86
  * @param {string[]} changedFiles
@@ -178,3 +199,84 @@ export function isStubPrelandedFileScopeSatisfied(worktreePath, pattern, changed
178
199
  baseBranch,
179
200
  );
180
201
  }
202
+
203
+ /**
204
+ * @param {string} worktreePath
205
+ * @param {string} ref
206
+ * @param {string} pattern
207
+ */
208
+ function listPathsOnRef(worktreePath, ref, pattern) {
209
+ try {
210
+ const output = execFileSync("git", ["ls-tree", "-r", "--name-only", ref, "--", pattern], {
211
+ cwd: worktreePath,
212
+ encoding: "utf-8",
213
+ stdio: ["ignore", "pipe", "pipe"],
214
+ timeout: 10_000,
215
+ });
216
+ return output
217
+ .split(/\r?\n/)
218
+ .map((line) => line.trim())
219
+ .filter(Boolean);
220
+ } catch {
221
+ return [];
222
+ }
223
+ }
224
+
225
+ /**
226
+ * True when base branch already contains scope changes and the lane has no diff for the pattern
227
+ * (issue #105 SP-014, SP-462).
228
+ *
229
+ * @param {string} worktreePath
230
+ * @param {string} pattern
231
+ * @param {string[]} changedFiles
232
+ * @param {string} baseBranch
233
+ */
234
+ export function isBaseScopeSatisfied(worktreePath, pattern, changedFiles, baseBranch, config = {}) {
235
+ const matchedInLane = changedFiles.some((file) => matchesScopePattern(file, pattern));
236
+ if (matchedInLane) {
237
+ return false;
238
+ }
239
+ const tasksRoot = config.paths?.tasksRoot ?? DEFAULT_TASKS_ROOT;
240
+ if (!hasSpineTaskDeliveryChanges(changedFiles, tasksRoot)) {
241
+ return false;
242
+ }
243
+ const laneDiffVsBase = listPathsChangedBetweenRefs(worktreePath, baseBranch, "HEAD", pattern);
244
+ if (laneDiffVsBase.some((filePath) => matchesScopePattern(filePath, pattern))) {
245
+ return false;
246
+ }
247
+ const onBase = listPathsOnRef(worktreePath, baseBranch, pattern);
248
+ return onBase.some((filePath) => matchesScopePattern(filePath, pattern));
249
+ }
250
+
251
+ /**
252
+ * @param {string} worktreePath
253
+ * @param {string} pattern
254
+ * @param {string[]} changedFiles
255
+ * @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
256
+ * @param {string} baseBranch
257
+ * @param {{ testCommandOk: boolean }} delivery
258
+ * @param {(worktreePath: string, artifactPath: string) => boolean} artifactExists
259
+ */
260
+ export function isBaseFileScopeSatisfied(
261
+ worktreePath,
262
+ pattern,
263
+ changedFiles,
264
+ parsedContract,
265
+ baseBranch,
266
+ delivery,
267
+ artifactExists,
268
+ config = {},
269
+ ) {
270
+ if (!isBaseScopeSatisfied(worktreePath, pattern, changedFiles, baseBranch, config)) {
271
+ return false;
272
+ }
273
+ if (parsedContract.testCommand && !delivery.testCommandOk) {
274
+ return false;
275
+ }
276
+ for (const artifactPath of parsedContract.artifactsMustExist ?? []) {
277
+ if (!artifactExists(worktreePath, artifactPath)) {
278
+ return false;
279
+ }
280
+ }
281
+ return true;
282
+ }
@@ -9,6 +9,8 @@ import micromatch from "micromatch";
9
9
  import { parseAggregateLineCoverage } from "../../scripts/coverage-parse.mjs";
10
10
  import { resolveContractMode } from "../tasks/packet/validate-contract.mjs";
11
11
  import {
12
+ isBaseFileScopeSatisfied,
13
+ isBaseScopeSatisfied,
12
14
  isPrelandedFileScopeSatisfied,
13
15
  isStubPrelandedFileScopeSatisfied,
14
16
  } from "./contract-prelanded.mjs";
@@ -25,6 +27,33 @@ export const CONTRACT_TEST_DEFAULT_RETRIES = 1;
25
27
  /** Default delay in ms between testCommand retry attempts. */
26
28
  export const CONTRACT_TEST_RETRY_DELAY_MS = 5000;
27
29
 
30
+ /**
31
+ * Worker-only env keys stripped from contract testCommand subprocesses so full-suite
32
+ * tests match operator re-run outside worker-host (SP-491, issue #155).
33
+ */
34
+ export const CONTRACT_TEST_WORKER_ENV_KEYS = ["SPINE_IS_WORKER"];
35
+
36
+ /**
37
+ * Build env for contract testCommand subprocess — omits worker-only keys inherited from
38
+ * worker-host.mjs that would false-fail batch-spawn integration tests (SP-482 guard).
39
+ * Preserves parent batch id as SPINE_PARENT_BATCH_ID so nested-spawn guard can block
40
+ * live engines in lane worktrees while still allowing isolated fixture tests (#162).
41
+ *
42
+ * @param {NodeJS.ProcessEnv} [sourceEnv]
43
+ * @returns {NodeJS.ProcessEnv}
44
+ */
45
+ export function buildContractTestEnv(sourceEnv = process.env) {
46
+ const env = { ...sourceEnv };
47
+ for (const key of CONTRACT_TEST_WORKER_ENV_KEYS) {
48
+ delete env[key];
49
+ }
50
+ if (env.SPINE_BATCH_ID && !env.SPINE_PARENT_BATCH_ID) {
51
+ env.SPINE_PARENT_BATCH_ID = env.SPINE_BATCH_ID;
52
+ }
53
+ delete env.SPINE_BATCH_ID;
54
+ return env;
55
+ }
56
+
28
57
  /**
29
58
  * @param {string} taskId
30
59
  * @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
@@ -197,6 +226,9 @@ export function verifyStubFileScopeMustChange(
197
226
  if (isStubPrelandedFileScopeSatisfied(worktreePath, pattern, changedFiles, config, baseBranch)) {
198
227
  continue;
199
228
  }
229
+ if (isBaseScopeSatisfied(worktreePath, pattern, changedFiles, baseBranch, config)) {
230
+ continue;
231
+ }
200
232
  failures.push(`Contract fileScopeMustChange: no matching changes for ${pattern}`);
201
233
  }
202
234
  return { ok: failures.length === 0, failures };
@@ -324,6 +356,7 @@ export function runContractTestCommand(worktreePath, command, options = {}) {
324
356
  const shellFlag = process.platform === "win32" ? "/c" : "-c";
325
357
  const result = spawnSync(shell, [shellFlag, trimmed], {
326
358
  cwd: worktreePath,
359
+ env: buildContractTestEnv(),
327
360
  encoding: "utf-8",
328
361
  stdio: ["ignore", "pipe", "pipe"],
329
362
  timeout: 10 * 60 * 1000,
@@ -521,7 +554,18 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
521
554
  { testCommandOk },
522
555
  (worktree, artifactPath) => findArtifactMatch(worktree, artifactPath).ok,
523
556
  );
524
- const ok = matched || prelanded;
557
+ const baseSatisfied = !matched && !prelanded &&
558
+ isBaseFileScopeSatisfied(
559
+ worktreePath,
560
+ pattern,
561
+ changedFiles,
562
+ parsedContract,
563
+ baseBranch,
564
+ { testCommandOk },
565
+ (worktree, artifactPath) => findArtifactMatch(worktree, artifactPath).ok,
566
+ config,
567
+ );
568
+ const ok = matched || prelanded || baseSatisfied;
525
569
  checks.push({
526
570
  field: "fileScopeMustChange",
527
571
  ok,
@@ -529,7 +573,9 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
529
573
  ? `fileScopeMustChange matched: ${pattern}`
530
574
  : prelanded
531
575
  ? `fileScopeMustChange pre-landed on ${baseBranch}: ${pattern}`
532
- : `Contract fileScopeMustChange: no matching changes for ${pattern}`,
576
+ : baseSatisfied
577
+ ? `fileScopeMustChange satisfied on ${baseBranch}: ${pattern}`
578
+ : `Contract fileScopeMustChange: no matching changes for ${pattern}`,
533
579
  });
534
580
  }
535
581
 
@@ -16,6 +16,14 @@ export function buildAlternatives(diagnosis, ctx = {}) {
16
16
  return ["spine batch complete --detect-manual-merge", ...common];
17
17
  case "completed_manual":
18
18
  return ["spine batch complete --detect-manual-merge", "spine batch dismiss", ...common];
19
+ case "human_base_diverged":
20
+ return [
21
+ "See operator-runbook §4.1 orch-first recovery",
22
+ "git merge main",
23
+ ...common,
24
+ ];
25
+ case "integrate_isolated_ok":
26
+ return ["git pull", "spine batch complete", ...common];
19
27
  case "needs_retry":
20
28
  return ["spine batch abort", "/spine-skip-task", "/spine-resume --force", ...common];
21
29
  case "worker_orphaned":
@@ -50,11 +50,19 @@ export const DIAGNOSIS_TAXONOMY = [
50
50
  "completed",
51
51
  "completed_manual",
52
52
  "limbo_stale",
53
+ "human_base_diverged",
54
+ "integrate_isolated_ok",
53
55
  "failed",
54
56
  "aborted",
55
57
  ];
56
58
 
57
- const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate", "engine_orphaned"]);
59
+ const NO_PAUSE_DIAGNOSES = new Set([
60
+ "limbo_stale",
61
+ "completed_manual",
62
+ "needs_integrate",
63
+ "engine_orphaned",
64
+ "integrate_isolated_ok",
65
+ ]);
58
66
  const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
59
67
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
60
68
  "code_review_spawn_failed",
@@ -140,7 +148,13 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
140
148
  case "completed_manual":
141
149
  return "spine batch dismiss";
142
150
  case "state_drift":
143
- return "spine batch retry --force";
151
+ if (ctx.failedTaskId) {
152
+ if (ctx.phase === "running") {
153
+ return `spine batch pause && spine batch retry ${ctx.failedTaskId}`;
154
+ }
155
+ return `spine batch retry ${ctx.failedTaskId}`;
156
+ }
157
+ return "spine status --diagnose";
144
158
  case "needs_retry":
145
159
  if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
146
160
  return buildStubFailureSuggestedCommand(ctx);
@@ -222,6 +236,10 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
222
236
  return "spine batch dismiss";
223
237
  case "completed":
224
238
  return "spine preflight";
239
+ case "human_base_diverged":
240
+ return "spine sync-base";
241
+ case "integrate_isolated_ok":
242
+ return "spine sync-base";
225
243
  default:
226
244
  return "spine status --diagnose";
227
245
  }
@@ -371,6 +389,14 @@ export function buildHeadline(diagnosis, ctx = {}) {
371
389
  return `${batchLabel} was aborted`;
372
390
  case "completed":
373
391
  return `${batchLabel} completed successfully`;
392
+ case "human_base_diverged": {
393
+ const overlapCount = Array.isArray(ctx.overlapPaths) ? ctx.overlapPaths.length : 0;
394
+ return overlapCount > 0
395
+ ? `${batchLabel} — human commits on base overlap orch land (${overlapCount} path(s))`
396
+ : `${batchLabel} — human commits on base overlap orch land`;
397
+ }
398
+ case "integrate_isolated_ok":
399
+ return `${batchLabel} — isolated integrate landed; sync human checkout with base`;
374
400
  default:
375
401
  return `${batchLabel} requires attention (phase: ${ctx.phase ?? "unknown"})`;
376
402
  }
@@ -6,6 +6,7 @@ import { appendJournalEvent } from "../journal.mjs";
6
6
  import { commitLaneWorktree, gitPorcelain } from "../lane-commit.mjs";
7
7
  import {
8
8
  resolvePostLaneCommitPorcelain,
9
+ sanitizeGitignoredArtifactsBeforeLaneCommit,
9
10
  sanitizeOutOfScopeCoverageBeforeLaneCommit,
10
11
  } from "../lane-dirty-check.mjs";
11
12
  import {
@@ -53,6 +54,11 @@ export function commitLaneAndValidateWorktree({
53
54
  config,
54
55
  }) {
55
56
  const preCommitPorcelain = gitPorcelain(worktreePath);
57
+ sanitizeGitignoredArtifactsBeforeLaneCommit(worktreePath, {
58
+ projectRoot,
59
+ porcelain: preCommitPorcelain,
60
+ enabled: config?.lanes?.autoCleanGitignoredArtifacts !== false,
61
+ });
56
62
  sanitizeOutOfScopeCoverageBeforeLaneCommit(worktreePath, fileScopePaths, {
57
63
  projectRoot,
58
64
  porcelain: preCommitPorcelain,