pi-spine 2.3.0 → 2.3.2
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.
- package/bin/spine-batch.mjs +10 -2
- package/bin/spine-cli/verify.mjs +13 -27
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +18 -1
- package/skills/spine-autonomous-operator/SKILL.md +3 -1
- package/src/batch/abort.mjs +28 -1
- package/src/batch/detached-run.mjs +2 -0
- package/src/batch/diagnosis.mjs +50 -6
- package/src/batch/engine-lanes/orch-sync.mjs +126 -0
- package/src/batch/engine-lanes.mjs +69 -0
- package/src/batch/reconcile-batch.mjs +14 -2
- package/src/batch/resume-multi-validate.mjs +29 -4
- package/src/batch/salvage-batch-list.mjs +47 -14
- package/src/batch/worker-heartbeat.mjs +8 -1
- package/src/batch/worker-host.mjs +6 -7
- package/src/batch/worker-spawn.mjs +15 -4
- package/src/batch/worktree.mjs +68 -0
- package/src/config/preflight/integrate-plan.mjs +6 -1
- package/src/config/preflight/loc-capstone.mjs +274 -0
- package/src/config/spine-preflight-lib.mjs +14 -0
- package/src/planner/index.mjs +14 -3
- package/src/process/terminate-tree.mjs +154 -0
package/bin/spine-batch.mjs
CHANGED
|
@@ -38,7 +38,8 @@ const BATCH_FLAG_VALUE_TAKERS = new Set([
|
|
|
38
38
|
*/
|
|
39
39
|
export function printBatchHelp() {
|
|
40
40
|
return (
|
|
41
|
-
"Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n"
|
|
41
|
+
"Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n" +
|
|
42
|
+
" abort --dry-run Preview abort (reason/archive target); does not archive, journal, or clear live batch\n"
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -113,8 +114,14 @@ export function formatLifecycleHuman(result, json = false) {
|
|
|
113
114
|
if (result.diagnosis) {
|
|
114
115
|
lines.push(` Diagnosis: ${result.diagnosis}`);
|
|
115
116
|
}
|
|
117
|
+
if (result.dryRun) {
|
|
118
|
+
lines.push(` Dry-run: true (no mutation)`);
|
|
119
|
+
}
|
|
116
120
|
if (result.archivePath) {
|
|
117
|
-
lines.push(` Archive: ${result.archivePath}`);
|
|
121
|
+
lines.push(result.dryRun ? ` Would archive: ${result.archivePath}` : ` Archive: ${result.archivePath}`);
|
|
122
|
+
}
|
|
123
|
+
if (result.reason) {
|
|
124
|
+
lines.push(` Reason: ${result.reason}`);
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
lines.push("", ` → ${result.suggestedCommand}`);
|
|
@@ -300,6 +307,7 @@ export async function runSpineBatch(options) {
|
|
|
300
307
|
batchId: parsed.batchId,
|
|
301
308
|
reason: parsed.reason,
|
|
302
309
|
hard: parsed.hard,
|
|
310
|
+
dryRun: parsed.dryRun,
|
|
303
311
|
});
|
|
304
312
|
return {
|
|
305
313
|
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
package/bin/spine-cli/verify.mjs
CHANGED
|
@@ -8,6 +8,11 @@ import { spawnSync } from "node:child_process";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
|
|
10
10
|
import { c, FAIL, OK } from "./shared.mjs";
|
|
11
|
+
import {
|
|
12
|
+
BATCH_MODULE_LOC_LIMIT,
|
|
13
|
+
evaluateBatchLocPolicy,
|
|
14
|
+
listBatchModuleLineCounts,
|
|
15
|
+
} from "../../src/config/preflight/loc-capstone.mjs";
|
|
11
16
|
|
|
12
17
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
18
|
|
|
@@ -16,24 +21,7 @@ export const PHASE23_GRANDFATHERED_OVER_500 = [];
|
|
|
16
21
|
|
|
17
22
|
const PHASE23_ENGINE_LANES_MAX = 500;
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
* @param {string} projectRoot
|
|
21
|
-
*/
|
|
22
|
-
function listBatchModuleLineCounts(projectRoot) {
|
|
23
|
-
const batchDir = path.join(projectRoot, "src/batch");
|
|
24
|
-
if (!fs.existsSync(batchDir)) return [];
|
|
25
|
-
|
|
26
|
-
return fs
|
|
27
|
-
.readdirSync(batchDir)
|
|
28
|
-
.filter((name) => name.endsWith(".mjs"))
|
|
29
|
-
.map((name) => {
|
|
30
|
-
const relPath = path.posix.join("src/batch", name);
|
|
31
|
-
const absPath = path.join(batchDir, name);
|
|
32
|
-
const lines = fs.readFileSync(absPath, "utf-8").split(/\r?\n/).length;
|
|
33
|
-
return { relPath, lines };
|
|
34
|
-
})
|
|
35
|
-
.sort((left, right) => left.relPath.localeCompare(right.relPath));
|
|
36
|
-
}
|
|
24
|
+
export { listBatchModuleLineCounts, evaluateBatchLocPolicy, BATCH_MODULE_LOC_LIMIT };
|
|
37
25
|
|
|
38
26
|
/**
|
|
39
27
|
* @param {object} params
|
|
@@ -94,17 +82,15 @@ export function runPhase23ExitVerify({ projectRoot, skipTest = false }) {
|
|
|
94
82
|
: `engine-lanes.mjs exceeds ${PHASE23_ENGINE_LANES_MAX} LOC (${engineLanes?.lines ?? "missing"})`,
|
|
95
83
|
});
|
|
96
84
|
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
101
|
-
const locPolicyOk = ungrandfathered.length === 0;
|
|
85
|
+
const locPolicy = evaluateBatchLocPolicy(projectRoot, {
|
|
86
|
+
grandfathered: PHASE23_GRANDFATHERED_OVER_500,
|
|
87
|
+
});
|
|
102
88
|
checks.push({
|
|
103
89
|
id: "batch-loc-policy",
|
|
104
|
-
ok:
|
|
105
|
-
message:
|
|
106
|
-
? `batch module LOC policy ok (${
|
|
107
|
-
: `unexpected
|
|
90
|
+
ok: locPolicy.ok,
|
|
91
|
+
message: locPolicy.ok
|
|
92
|
+
? `batch module LOC policy ok (${locPolicy.overLimit.length} grandfathered >${BATCH_MODULE_LOC_LIMIT})`
|
|
93
|
+
: `unexpected >${BATCH_MODULE_LOC_LIMIT} LOC modules: ${locPolicy.ungrandfathered.map((entry) => `${entry.relPath} (${entry.lines})`).join(", ")}`,
|
|
108
94
|
});
|
|
109
95
|
|
|
110
96
|
const realPiWorkflow = path.join(projectRoot, ".github/workflows/real-pi.yml");
|
package/package.json
CHANGED
|
@@ -191,6 +191,7 @@ Run **after Step A.5 — Clarify** and **before Step B — Slice**. Authoring-on
|
|
|
191
191
|
| **Step numbering** | Number steps sequentially starting at 0 with **no duplicates** (`### Step N:`). `spine tasks validate` rejects duplicate step numbers (see issue #148 / SP-435). |
|
|
192
192
|
| **Two-deliverable test** | If your Steps can be grouped into two clusters with no data dependency between them, split into separate tasks even if the step count is ≤4. The #1 sizing mistake is bundling two independent deliverables in one M task. |
|
|
193
193
|
| **Parallel waves** | Prefer **≤4** M-sized tasks per wave; 8-task mega-waves stall pi workers (see Phase 15 / SP-086–088). |
|
|
194
|
+
| **False deps** | Edge only for **real data deps** (B needs A's output on disk). Preference-order or "nice to finish first" is **not** a dep — it forces size-1 waves and empty parallel lanes. Independent deliverables → same wave + disjoint File Scope. |
|
|
194
195
|
| **Scope** | One deliverable per task; disjoint **File Scope** when tasks can run in parallel. |
|
|
195
196
|
| **IDs** | Use `Next Task ID` from CONTEXT.md; increment after each new task. Greenfield spine projects typically use `SP-###`; Taskplane migrants may keep `TP-###`. |
|
|
196
197
|
| **Waves** | Order via `## Dependencies` and `{tasksRoot}/dependencies.json`. |
|
|
@@ -246,7 +247,7 @@ After creating packets:
|
|
|
246
247
|
2. **`{tasksRoot}/dependencies.json`** — add edges for every dependency (machine-parseable)
|
|
247
248
|
3. Report launch commands: `spine tasks validate pending` (fix contract/PROMPT errors first), `spine tasks analyze pending` (structural checks — wave sizing, deps drift, explore refs), `spine plan pending`, then `spine batch start <id>`
|
|
248
249
|
|
|
249
|
-
**Example
|
|
250
|
+
**Example — serial when data deps are real** (handlers import schema; tests call handlers):
|
|
250
251
|
|
|
251
252
|
| Task | Mission | Deps |
|
|
252
253
|
|------|---------|------|
|
|
@@ -254,6 +255,17 @@ After creating packets:
|
|
|
254
255
|
| `SP-011-api-handlers` | Implement routes using schema | SP-010 |
|
|
255
256
|
| `SP-012-api-tests` | Integration tests + docs | SP-011 |
|
|
256
257
|
|
|
258
|
+
`spine plan` correctly shows one lane per wave here — serial is required.
|
|
259
|
+
|
|
260
|
+
**Counter-example — parallel when deliverables are independent** (no shared output; disjoint File Scope):
|
|
261
|
+
|
|
262
|
+
| Task | Mission | Deps | File Scope |
|
|
263
|
+
|------|---------|------|------------|
|
|
264
|
+
| `SP-020-skill-dor` | Tighten skill DoR checklist | None | `skills/create-spine-tasks/SKILL.md` |
|
|
265
|
+
| `SP-021-runbook-note` | Add operator recovery note | None | `docs/adoption/operator-runbook.md` |
|
|
266
|
+
|
|
267
|
+
Same wave, no edges → `spine plan` should report **`2 lanes in parallel`**. If it collapses to `1 lane`, check overlapping scopes or accidental deps — do not "fix" with preference-order edges.
|
|
268
|
+
|
|
257
269
|
---
|
|
258
270
|
|
|
259
271
|
## Single-Task Creation Workflow
|
|
@@ -461,6 +473,8 @@ Task IDs in JSON use the **folder slug** (full `SP-011-api-handlers`) or bare ID
|
|
|
461
473
|
|
|
462
474
|
When decomposing a PRD, assign non-overlapping file scopes to tasks that should run in parallel.
|
|
463
475
|
|
|
476
|
+
**Shared docs / hot files collapse lanes:** Shared `CONTEXT.md`, `README.md`, area docs, or hot modules (e.g. `bin/spine.mjs`, `src/batch/engine.mjs`) in multiple same-wave File Scopes pack those tasks onto one virtual lane. Keep shared-doc edits **serial** (dependency edge or separate wave) or **out of** parallel mates' scopes — do not list the same shared path on two intended-parallel tasks.
|
|
477
|
+
|
|
464
478
|
**`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).
|
|
465
479
|
|
|
466
480
|
**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.
|
|
@@ -544,6 +558,8 @@ Before reporting launch commands:
|
|
|
544
558
|
- [ ] S/M patch Contract uses scoped `node --test` — not `npm test` or `npm test -- path` ([#141](https://github.com/beettlle/pi-spine/issues/141), SP-522)
|
|
545
559
|
- [ ] Shared-module behavior change: `rg` old strings in `tests/`; all hit files in `testCommand` or documented for post-integrate `release:check` ([post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md))
|
|
546
560
|
- [ ] Plan waves ≤8 tasks when possible — `spine plan` warns when exceeded ([#143](https://github.com/beettlle/pi-spine/issues/143), SP-524)
|
|
561
|
+
- [ ] When parallelism is intended: `spine plan` shows `N lanes in parallel` for that wave — or document why overlapping scopes / real deps forced serial collapse ([#193](https://github.com/beettlle/pi-spine/issues/193))
|
|
562
|
+
- [ ] No false deps: edges only for real data dependencies; preference-order edges that force size-1 waves are rejected ([#193](https://github.com/beettlle/pi-spine/issues/193))
|
|
547
563
|
- [ ] `### Step N: Testing & Verification` present inside `## Steps` before `## Completion Criteria` (required even for docs-only Review Level 0)
|
|
548
564
|
- [ ] STATUS.md with matching steps (hydration markers where needed)
|
|
549
565
|
- [ ] `dependencies.json` updated when task has deps
|
|
@@ -575,6 +591,7 @@ Hydration commits (STATUS.md expansions) may happen mid-step for crash recovery.
|
|
|
575
591
|
- **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.
|
|
576
592
|
- **Documentation in every task** — "Must Update" / "Check If Affected" prevent doc drift.
|
|
577
593
|
- **Concrete deliverables** — name files to create/modify; avoid shortcuttable vague steps.
|
|
594
|
+
- **False deps defeat parallelism** — edge only when B needs A's output; independent work gets disjoint File Scope and no edge. Verify intended parallel waves with `spine plan` (`N lanes in parallel`) before handoff ([#193](https://github.com/beettlle/pi-spine/issues/193)).
|
|
578
595
|
- **Local install** — skill ships with pi-spine; `pi install /path/to/pi-spine -l` loads `./skills`.
|
|
579
596
|
|
|
580
597
|
---
|
|
@@ -84,7 +84,9 @@ For each pending `spine-tasks/{SP-###-slug}/PROMPT.md`:
|
|
|
84
84
|
|
|
85
85
|
- [ ] `dependencies.json` matches PROMPT `## Dependencies`
|
|
86
86
|
- [ ] Same-wave tasks have **disjoint** `fileScopeMustChange`
|
|
87
|
-
- [ ] Hot shared files are serial (e.g. `src/batch/heartbeat.mjs`, `bin/spine.mjs`)
|
|
87
|
+
- [ ] Hot shared files / shared docs are serial (e.g. `src/batch/heartbeat.mjs`, `bin/spine.mjs`, `CONTEXT.md`) — overlapping shared paths collapse lanes
|
|
88
|
+
- [ ] No false (preference-order) deps that force size-1 waves when deliverables are independent
|
|
89
|
+
- [ ] When parallelism is intended: `spine plan` shows `N lanes in parallel` for that wave — or explain why scopes/deps forced serial collapse
|
|
88
90
|
- [ ] No directory paths with trailing `/` in contracts — use explicit files
|
|
89
91
|
- [ ] No parenthetical comments in contract paths (e.g. `file.ts (Step 2 only)`)
|
|
90
92
|
- [ ] Pre-landed code on `main` → point `fileScopeMustChange` at `spine-tasks/{task}/STATUS.md` + `## Amendments`
|
package/src/batch/abort.mjs
CHANGED
|
@@ -131,12 +131,13 @@ function buildAbortedSnapshot(raw, reason) {
|
|
|
131
131
|
* @param {object} ctx
|
|
132
132
|
* @param {string} ctx.projectRoot
|
|
133
133
|
* @param {boolean} [ctx.hard]
|
|
134
|
+
* @param {boolean} [ctx.dryRun]
|
|
134
135
|
* @param {string|null} [ctx.reason]
|
|
135
136
|
* @param {string|null} [ctx.batchId]
|
|
136
137
|
* @param {string|null} [ctx.batchStatePath]
|
|
137
138
|
*/
|
|
138
139
|
export function abortBatch(ctx) {
|
|
139
|
-
const { projectRoot, hard = false, reason = null } = ctx;
|
|
140
|
+
const { projectRoot, hard = false, reason = null, dryRun = false } = ctx;
|
|
140
141
|
const loaded = loadBatchStateFile(projectRoot, ctx.batchStatePath ?? null);
|
|
141
142
|
|
|
142
143
|
if (!loaded.path || !loaded.raw) {
|
|
@@ -147,6 +148,7 @@ export function abortBatch(ctx) {
|
|
|
147
148
|
suggestedCommand: "spine preflight",
|
|
148
149
|
alternatives: ["spine status --diagnose"],
|
|
149
150
|
batchId: null,
|
|
151
|
+
dryRun,
|
|
150
152
|
};
|
|
151
153
|
}
|
|
152
154
|
|
|
@@ -158,6 +160,7 @@ export function abortBatch(ctx) {
|
|
|
158
160
|
headline: `Cannot parse batch state: ${loaded.parseError}`,
|
|
159
161
|
suggestedCommand: "spine status --diagnose",
|
|
160
162
|
batchId: null,
|
|
163
|
+
dryRun,
|
|
161
164
|
};
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -170,6 +173,7 @@ export function abortBatch(ctx) {
|
|
|
170
173
|
headline: "Active batch state has no batchId",
|
|
171
174
|
suggestedCommand: "spine status --diagnose",
|
|
172
175
|
batchId: null,
|
|
176
|
+
dryRun,
|
|
173
177
|
};
|
|
174
178
|
}
|
|
175
179
|
|
|
@@ -181,6 +185,29 @@ export function abortBatch(ctx) {
|
|
|
181
185
|
headline: `Batch ID mismatch — active batch is ${batchId}`,
|
|
182
186
|
suggestedCommand: "spine status --diagnose",
|
|
183
187
|
batchId,
|
|
188
|
+
dryRun,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const previewArchivePath = archiveBatchStatePath(projectRoot, batchId);
|
|
193
|
+
|
|
194
|
+
// Dry-run previews abort without writing archive, journal, signal, or clearing live state.
|
|
195
|
+
if (dryRun) {
|
|
196
|
+
const abortCmd = hard ? "spine batch abort --hard" : "spine batch abort";
|
|
197
|
+
return {
|
|
198
|
+
ok: true,
|
|
199
|
+
exitCode: 0,
|
|
200
|
+
dryRun: true,
|
|
201
|
+
batchId,
|
|
202
|
+
hard,
|
|
203
|
+
reason: reason ?? null,
|
|
204
|
+
diagnosis: "abort_preview",
|
|
205
|
+
archivePath: previewArchivePath,
|
|
206
|
+
headline: hard
|
|
207
|
+
? `Would hard-abort and archive batch ${batchId}`
|
|
208
|
+
: `Would abort and archive batch ${batchId}`,
|
|
209
|
+
suggestedCommand: abortCmd,
|
|
210
|
+
alternatives: ["spine status --diagnose"],
|
|
184
211
|
};
|
|
185
212
|
}
|
|
186
213
|
|
|
@@ -265,6 +265,8 @@ export async function resumeBatchDetached({
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
prepareDetachedResumeEngineHandoff(projectRoot);
|
|
268
|
+
// SP-613: validateMultiTaskResume already admits pidless terminal-success + pending
|
|
269
|
+
// wave merge (#196); spawn the attached engine argv in detached mode (no --attached).
|
|
268
270
|
const argv = buildAttachedBatchResumeArgv({ force });
|
|
269
271
|
const { enginePid, logPath } = spawnDetachedBatchEngine({ projectRoot, spineBin, argv });
|
|
270
272
|
releaseResumeLock?.();
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -56,6 +56,25 @@ export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "
|
|
|
56
56
|
|
|
57
57
|
const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Gate-ready batches must not headline historical merge/gitignored blockers (#195 / FR-REL231-01).
|
|
61
|
+
*
|
|
62
|
+
* @param {string} diagnosis
|
|
63
|
+
* @param {object} [ctx]
|
|
64
|
+
* @param {boolean} [ctx.allTasksTerminalSuccess]
|
|
65
|
+
* @param {boolean} [ctx.integrateGateOpen]
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
export function isGateReadyHeadlineContext(diagnosis, ctx = {}) {
|
|
69
|
+
if (diagnosis === "needs_integrate") {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (ctx.allTasksTerminalSuccess === true && ctx.integrateGateOpen === true) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
59
78
|
/**
|
|
60
79
|
* Retry suggestions must include a task id; journal salvage payloads may be stale.
|
|
61
80
|
*
|
|
@@ -121,10 +140,16 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
|
121
140
|
* @param {string[]|null} [ctx.gitignoredPaths]
|
|
122
141
|
*/
|
|
123
142
|
export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
124
|
-
|
|
143
|
+
const preferGateReady = isGateReadyHeadlineContext(diagnosis, ctx);
|
|
144
|
+
// Prefer gate-approve / land-loop next step over recovered merge/gitignored repair (#195).
|
|
145
|
+
if (ctx.mergeGitignoredFailure && !preferGateReady) {
|
|
125
146
|
return buildGitignoredMergeRepairCommand(ctx.taskBranch, ctx.gitignoredPaths);
|
|
126
147
|
}
|
|
127
|
-
if (
|
|
148
|
+
if (
|
|
149
|
+
ctx.mergeFailed &&
|
|
150
|
+
!preferGateReady &&
|
|
151
|
+
(diagnosis === "failed" || diagnosis === "needs_retry")
|
|
152
|
+
) {
|
|
128
153
|
return "spine batch resume --force";
|
|
129
154
|
}
|
|
130
155
|
if (ctx.phase === "merge_blocked") {
|
|
@@ -136,9 +161,18 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
136
161
|
case "completed_manual":
|
|
137
162
|
return "spine batch dismiss";
|
|
138
163
|
case "state_drift":
|
|
164
|
+
// Agent-safe detached recovery (#196 / SP-613) — never suggest --attached.
|
|
165
|
+
if (
|
|
166
|
+
ctx.phase === "running" ||
|
|
167
|
+
ctx.staleEnginePid === true ||
|
|
168
|
+
ctx.engineDead === true ||
|
|
169
|
+
ctx.allTasksTerminalSuccess === true
|
|
170
|
+
) {
|
|
171
|
+
return "spine batch resume --force";
|
|
172
|
+
}
|
|
139
173
|
if (ctx.failedTaskId) {
|
|
140
174
|
const driftStatus = String(ctx.driftTaskStatus ?? "").toLowerCase();
|
|
141
|
-
if (driftStatus === "running"
|
|
175
|
+
if (driftStatus === "running") {
|
|
142
176
|
return "spine batch resume --force";
|
|
143
177
|
}
|
|
144
178
|
return `spine batch retry ${ctx.failedTaskId}`;
|
|
@@ -199,12 +233,16 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
199
233
|
case "engine_orphaned": {
|
|
200
234
|
const parentExitCommand = buildEngineOrphanParentExitSuggestedCommand(ctx);
|
|
201
235
|
if (parentExitCommand) return parentExitCommand;
|
|
236
|
+
// Terminal-success / doneInLane heal with dead engine — detached resume (#196 / #163).
|
|
237
|
+
if (ctx.allTasksTerminalSuccess === true) {
|
|
238
|
+
return "spine batch resume --force";
|
|
239
|
+
}
|
|
202
240
|
return ctx.failedTaskId
|
|
203
241
|
? `spine batch retry ${ctx.failedTaskId}`
|
|
204
242
|
: "spine batch resume --attached";
|
|
205
243
|
}
|
|
206
244
|
case "needs_merge":
|
|
207
|
-
return "
|
|
245
|
+
return "spine batch resume --force";
|
|
208
246
|
case "needs_integrate":
|
|
209
247
|
if (ctx.postMergeLimbo && ctx.phase === "running") {
|
|
210
248
|
if (ctx.integrateGateOpen) {
|
|
@@ -263,12 +301,18 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
263
301
|
*/
|
|
264
302
|
export function buildHeadline(diagnosis, ctx = {}) {
|
|
265
303
|
const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
|
|
304
|
+
const preferGateReady = isGateReadyHeadlineContext(diagnosis, ctx);
|
|
266
305
|
|
|
267
|
-
|
|
306
|
+
// Historical merge/gitignored signals stay in diagnose signals — not the primary headline (#195).
|
|
307
|
+
if (ctx.mergeGitignoredFailure && !preferGateReady) {
|
|
268
308
|
return `${batchLabel} merge blocked by gitignored paths on a lane branch — drop cached ignored files, then resume`;
|
|
269
309
|
}
|
|
270
310
|
|
|
271
|
-
if (
|
|
311
|
+
if (
|
|
312
|
+
ctx.mergeFailed &&
|
|
313
|
+
!preferGateReady &&
|
|
314
|
+
(diagnosis === "failed" || diagnosis === "needs_retry")
|
|
315
|
+
) {
|
|
272
316
|
return buildMergeFailureHeadline(batchLabel, ctx);
|
|
273
317
|
}
|
|
274
318
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Orch→lane sync when satisfied deps share File Scope (FR-REL231-03 / #191).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { resolveTasksRootPath } from "../../config/env-overrides.mjs";
|
|
9
|
+
import { discoverTasks, loadDependenciesJson } from "../../tasks/packet/index.mjs";
|
|
10
|
+
import { loadTaskFileScopePaths } from "./queue.mjs";
|
|
11
|
+
import { syncLaneWorktreeFromOrch } from "../worktree.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} projectRoot
|
|
15
|
+
* @param {object} [config]
|
|
16
|
+
*/
|
|
17
|
+
function resolveBatchTasksRoot(projectRoot, config) {
|
|
18
|
+
return resolveTasksRootPath(projectRoot, config) ?? path.join(projectRoot, "spine-tasks");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} tasksRoot
|
|
23
|
+
* @param {string} taskId
|
|
24
|
+
* @param {object[]} [stateTasks]
|
|
25
|
+
*/
|
|
26
|
+
function resolveTaskFolderPath(tasksRoot, taskId, stateTasks = []) {
|
|
27
|
+
const fromState = stateTasks.find((entry) => entry?.taskId === taskId)?.taskFolder;
|
|
28
|
+
if (typeof fromState === "string" && fromState.trim() && fs.existsSync(fromState)) {
|
|
29
|
+
return fromState;
|
|
30
|
+
}
|
|
31
|
+
if (!fs.existsSync(tasksRoot)) return null;
|
|
32
|
+
const match = discoverTasks(tasksRoot).find((entry) => entry.taskId === taskId);
|
|
33
|
+
return match?.folderPath ?? null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Satisfied deps that share at least one File Scope path with the current task.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} params
|
|
40
|
+
* @param {string} params.projectRoot
|
|
41
|
+
* @param {object} params.state
|
|
42
|
+
* @param {string} params.taskId
|
|
43
|
+
* @param {string[]} params.fileScopePaths
|
|
44
|
+
* @param {object} [params.config]
|
|
45
|
+
* @returns {Array<{ depId: string, overlap: string[] }>}
|
|
46
|
+
*/
|
|
47
|
+
export function collectSharedScopeSatisfiedDeps({
|
|
48
|
+
projectRoot,
|
|
49
|
+
state,
|
|
50
|
+
taskId,
|
|
51
|
+
fileScopePaths,
|
|
52
|
+
config = {},
|
|
53
|
+
}) {
|
|
54
|
+
if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return [];
|
|
55
|
+
|
|
56
|
+
const tasksRoot = resolveBatchTasksRoot(projectRoot, config);
|
|
57
|
+
const deps = loadDependenciesJson(tasksRoot).tasks?.[taskId] ?? [];
|
|
58
|
+
if (!Array.isArray(deps) || deps.length === 0) return [];
|
|
59
|
+
|
|
60
|
+
const scopeSet = new Set(fileScopePaths);
|
|
61
|
+
const stateTasks = Array.isArray(state?.tasks) ? state.tasks : [];
|
|
62
|
+
/** @type {Array<{ depId: string, overlap: string[] }>} */
|
|
63
|
+
const shared = [];
|
|
64
|
+
|
|
65
|
+
for (const depId of deps) {
|
|
66
|
+
const depTask = stateTasks.find((entry) => entry?.taskId === depId);
|
|
67
|
+
if (!depTask || depTask.status !== "succeeded") continue;
|
|
68
|
+
|
|
69
|
+
const depFolder = resolveTaskFolderPath(tasksRoot, depId, stateTasks);
|
|
70
|
+
if (!depFolder) continue;
|
|
71
|
+
|
|
72
|
+
const scopeResult = loadTaskFileScopePaths(depFolder);
|
|
73
|
+
if (!scopeResult.ok) continue;
|
|
74
|
+
|
|
75
|
+
const overlap = (scopeResult.fileScopePaths ?? []).filter((filePath) =>
|
|
76
|
+
scopeSet.has(filePath),
|
|
77
|
+
);
|
|
78
|
+
if (overlap.length > 0) {
|
|
79
|
+
shared.push({ depId, overlap });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return shared;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {object} params
|
|
88
|
+
* @returns {{ ok: true, synced: boolean, skipped?: boolean, sharedDeps: Array<{ depId: string, overlap: string[] }>, headSha?: string } | { ok: false, error: string, sharedDeps: Array<{ depId: string, overlap: string[] }> }}
|
|
89
|
+
*/
|
|
90
|
+
export function ensureLaneSyncedForSharedScopeDeps({
|
|
91
|
+
projectRoot,
|
|
92
|
+
state,
|
|
93
|
+
taskId,
|
|
94
|
+
fileScopePaths,
|
|
95
|
+
worktreePath,
|
|
96
|
+
config = {},
|
|
97
|
+
}) {
|
|
98
|
+
const sharedDeps = collectSharedScopeSatisfiedDeps({
|
|
99
|
+
projectRoot,
|
|
100
|
+
state,
|
|
101
|
+
taskId,
|
|
102
|
+
fileScopePaths,
|
|
103
|
+
config,
|
|
104
|
+
});
|
|
105
|
+
if (sharedDeps.length === 0) {
|
|
106
|
+
return { ok: true, synced: false, skipped: true, sharedDeps };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const result = syncLaneWorktreeFromOrch({
|
|
111
|
+
worktreePath,
|
|
112
|
+
orchBranch: state?.orchBranch,
|
|
113
|
+
projectRoot,
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
synced: !result.skipped,
|
|
118
|
+
skipped: result.skipped,
|
|
119
|
+
sharedDeps,
|
|
120
|
+
headSha: result.headSha,
|
|
121
|
+
};
|
|
122
|
+
} catch (err) {
|
|
123
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
124
|
+
return { ok: false, error: message, sharedDeps };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "./state.mjs";
|
|
23
23
|
import { runWorker } from "./worker-host.mjs";
|
|
24
24
|
import { runCodeReviewPhase, runFinalReviewPhase } from "./engine-lanes/review.mjs";
|
|
25
|
+
import { ensureLaneSyncedForSharedScopeDeps } from "./engine-lanes/orch-sync.mjs";
|
|
25
26
|
|
|
26
27
|
export {
|
|
27
28
|
buildTasksAndLanesFromPlan,
|
|
@@ -46,6 +47,12 @@ export {
|
|
|
46
47
|
tryAutoResolveRulesManifestMergeConflict,
|
|
47
48
|
} from "./engine-lanes/merge.mjs";
|
|
48
49
|
|
|
50
|
+
export { syncLaneWorktreeFromOrch } from "./worktree.mjs";
|
|
51
|
+
export {
|
|
52
|
+
collectSharedScopeSatisfiedDeps,
|
|
53
|
+
ensureLaneSyncedForSharedScopeDeps,
|
|
54
|
+
} from "./engine-lanes/orch-sync.mjs";
|
|
55
|
+
|
|
49
56
|
/**
|
|
50
57
|
* @param {string} fromPhase
|
|
51
58
|
* @param {string} toPhase
|
|
@@ -121,6 +128,68 @@ export async function runTaskOnLane({
|
|
|
121
128
|
}
|
|
122
129
|
const fileScopePaths = scopeResult.fileScopePaths;
|
|
123
130
|
|
|
131
|
+
const syncResult = ensureLaneSyncedForSharedScopeDeps({
|
|
132
|
+
projectRoot,
|
|
133
|
+
state,
|
|
134
|
+
taskId,
|
|
135
|
+
fileScopePaths,
|
|
136
|
+
worktreePath: wt,
|
|
137
|
+
config,
|
|
138
|
+
});
|
|
139
|
+
if (!syncResult.ok) {
|
|
140
|
+
task.status = "failed";
|
|
141
|
+
task.endedAt = Date.now();
|
|
142
|
+
task.exitReason = "orch_sync_failed";
|
|
143
|
+
if (!task.startedAt) task.startedAt = Date.now();
|
|
144
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
145
|
+
recomputeTaskCounters(state);
|
|
146
|
+
saveEngineBatchState(projectRoot, state);
|
|
147
|
+
appendJournalEvent(projectRoot, batchId, "lane.orch_sync_failed", {
|
|
148
|
+
taskId,
|
|
149
|
+
laneNumber,
|
|
150
|
+
laneId: lane.laneId,
|
|
151
|
+
correlationId: laneCorrelationId,
|
|
152
|
+
error: syncResult.error,
|
|
153
|
+
sharedDeps: syncResult.sharedDeps,
|
|
154
|
+
});
|
|
155
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
156
|
+
taskId,
|
|
157
|
+
laneNumber,
|
|
158
|
+
laneId: lane.laneId,
|
|
159
|
+
correlationId: laneCorrelationId,
|
|
160
|
+
classification: "orch_sync_failed",
|
|
161
|
+
exitCode: 1,
|
|
162
|
+
output: syncResult.error,
|
|
163
|
+
});
|
|
164
|
+
recordLaneTaskMetric({
|
|
165
|
+
projectRoot,
|
|
166
|
+
batchId,
|
|
167
|
+
task,
|
|
168
|
+
config,
|
|
169
|
+
taskFolder: taskFolderInWorktree,
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
workerResult: {
|
|
174
|
+
ok: false,
|
|
175
|
+
classification: "orch_sync_failed",
|
|
176
|
+
output: syncResult.error,
|
|
177
|
+
exitCode: 1,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (syncResult.synced) {
|
|
182
|
+
appendJournalEvent(projectRoot, batchId, "lane.orch_synced", {
|
|
183
|
+
taskId,
|
|
184
|
+
laneNumber,
|
|
185
|
+
laneId: lane.laneId,
|
|
186
|
+
correlationId: laneCorrelationId,
|
|
187
|
+
orchBranch: state.orchBranch,
|
|
188
|
+
headSha: syncResult.headSha,
|
|
189
|
+
sharedDeps: syncResult.sharedDeps,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
124
193
|
task.status = "running";
|
|
125
194
|
if (!task.startedAt) task.startedAt = Date.now();
|
|
126
195
|
updateSegmentForTask(state, taskId, "running");
|
|
@@ -10,6 +10,7 @@ import { deriveMacroPhase, macroPhaseLabel } from "./macro-phase.mjs";
|
|
|
10
10
|
import {
|
|
11
11
|
buildDiagnosisOutput,
|
|
12
12
|
inferMergeGitignoredFailure,
|
|
13
|
+
isGateReadyHeadlineContext,
|
|
13
14
|
} from "./diagnosis.mjs";
|
|
14
15
|
import {
|
|
15
16
|
classifyTasks,
|
|
@@ -344,7 +345,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
344
345
|
diagnosis === "worker_orphaned" &&
|
|
345
346
|
findPlanReviewNestedSpawnBlockedFailure(journalEvents, failedTaskId);
|
|
346
347
|
|
|
347
|
-
const
|
|
348
|
+
const mergeGitignoredFailureInferred = inferMergeGitignoredFailure({
|
|
348
349
|
exitReason,
|
|
349
350
|
failureClass: batch.raw?.mergeResults?.find((entry) => entry?.failureClass)?.failureClass ?? null,
|
|
350
351
|
lastError: batch.raw?.lastError ?? null,
|
|
@@ -359,6 +360,17 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
359
360
|
signals.failedWaveIndex = mergeFailureSummary.failedWaveIndex;
|
|
360
361
|
signals.failedLane = mergeFailureSummary.failedLane;
|
|
361
362
|
signals.lastError = mergeFailureSummary.lastError;
|
|
363
|
+
// Keep historical gitignored merge evidence in signals; demote for headline once gate-ready (#195).
|
|
364
|
+
signals.mergeGitignoredFailure = mergeGitignoredFailureInferred;
|
|
365
|
+
const gateReadyHeadline = isGateReadyHeadlineContext(diagnosis, {
|
|
366
|
+
allTasksTerminalSuccess: signals.allTasksTerminalSuccess === true,
|
|
367
|
+
integrateGateOpen,
|
|
368
|
+
});
|
|
369
|
+
const mergeGitignoredFailure = gateReadyHeadline ? false : mergeGitignoredFailureInferred;
|
|
370
|
+
const mergeFailedForHeadline = gateReadyHeadline ? false : mergeFailureSummary.mergeFailed;
|
|
371
|
+
if (ctx.verbose && gateReadyHeadline && mergeGitignoredFailureInferred) {
|
|
372
|
+
signals.mergeGitignoredFailureSuperseded = true;
|
|
373
|
+
}
|
|
362
374
|
const gitignoredPaths = extractGitignoredPathsFromJournal(journalEvents, failedTaskId);
|
|
363
375
|
const taskBranch =
|
|
364
376
|
failedTaskId != null
|
|
@@ -406,7 +418,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
406
418
|
stalePathSpine,
|
|
407
419
|
planReviewNestedSpawnBlocked,
|
|
408
420
|
mergeGitignoredFailure,
|
|
409
|
-
mergeFailed:
|
|
421
|
+
mergeFailed: mergeFailedForHeadline,
|
|
410
422
|
failedWaveIndex: mergeFailureSummary.failedWaveIndex,
|
|
411
423
|
failedLane: mergeFailureSummary.failedLane,
|
|
412
424
|
lastError: mergeFailureSummary.lastError,
|