pi-spine 2.24.0 → 2.25.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.
- package/bin/spine-worker-runner.mjs +2 -1
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +14 -0
- package/src/batch/batch-state-io.mjs +120 -45
- package/src/batch/engine-crash-guard.mjs +143 -0
- package/src/batch/engine-lanes/matrix-run.mjs +28 -2
- package/src/batch/engine-lanes/matrix.mjs +143 -8
- package/src/batch/integrate-dirty-overlap.mjs +35 -0
- package/src/batch/integrate-worktree.mjs +106 -13
- package/src/batch/integrate.mjs +34 -93
- package/src/batch/journal-checksum.mjs +26 -0
- package/src/batch/journal.mjs +32 -13
- package/src/batch/lifecycle-archive.mjs +8 -2
- package/src/batch/lifecycle.mjs +2 -2
- package/src/batch/reconcile-batch.mjs +13 -1
- package/src/batch/salvage-batch-integrate.mjs +13 -17
- package/src/batch/state.mjs +22 -1
- package/src/batch/worker-heartbeat.mjs +29 -8
- package/src/batch/worker-host.mjs +29 -4
- package/src/batch/worker-output.mjs +9 -6
- package/src/batch/worker-prompt.mjs +4 -2
- package/src/batch/worker-spawn.mjs +99 -12
- package/src/config/preflight/discovery.mjs +20 -12
- package/src/planner/scope.mjs +3 -1
- package/src/tasks/packet/discover.mjs +59 -3
package/src/batch/state.mjs
CHANGED
|
@@ -125,10 +125,24 @@ export function failBatchFromEngineError({
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
+
* Fail closed when the on-disk batch state must not be silently replaced.
|
|
129
|
+
*
|
|
130
|
+
* Corrupt spine-owned state is quarantined (never deleted) and start refuses
|
|
131
|
+
* with an actionable recovery message (SP-786 / #303). This gate runs even
|
|
132
|
+
* when preflight is skipped: the engine calls `assertNoActiveBatch`
|
|
133
|
+
* unconditionally on every start path. A Taskplane-owned `.pi/batch-state.json`
|
|
134
|
+
* is never modified — a corrupt one is reported instead.
|
|
135
|
+
*
|
|
128
136
|
* @param {string} projectRoot
|
|
129
137
|
*/
|
|
130
138
|
export function assertNoActiveBatch(projectRoot) {
|
|
131
|
-
clearStaleTerminalBatchStateForStart(projectRoot);
|
|
139
|
+
const clearResult = clearStaleTerminalBatchStateForStart(projectRoot);
|
|
140
|
+
if (clearResult.reason === "corrupt") {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Batch state was corrupt and has been quarantined to ${clearResult.quarantinedPath}. ` +
|
|
143
|
+
"Inspect it and the journal (spine status --diagnose), then run spine batch dismiss --force before starting a new batch.",
|
|
144
|
+
);
|
|
145
|
+
}
|
|
132
146
|
|
|
133
147
|
const spine = loadSpineBatchState(projectRoot);
|
|
134
148
|
if (spine.path && spine.raw) {
|
|
@@ -141,6 +155,13 @@ export function assertNoActiveBatch(projectRoot) {
|
|
|
141
155
|
}
|
|
142
156
|
|
|
143
157
|
const any = loadBatchStateFile(projectRoot);
|
|
158
|
+
if (any.path && any.parseError) {
|
|
159
|
+
// Corrupt Taskplane-owned state: reported, never modified by spine (SP-786 / #303).
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Batch state at ${any.path} is corrupt and was left unmodified by spine (${any.parseError}). ` +
|
|
162
|
+
"Inspect it (spine status --diagnose), then repair or remove it with the owning tool before starting a new batch.",
|
|
163
|
+
);
|
|
164
|
+
}
|
|
144
165
|
if (any.path && any.raw) {
|
|
145
166
|
const phase = String(any.raw.phase ?? "");
|
|
146
167
|
const active =
|
|
@@ -37,10 +37,20 @@ import { terminateProcessTree } from "../process/terminate-tree.mjs";
|
|
|
37
37
|
/**
|
|
38
38
|
* @param {number} ms
|
|
39
39
|
*/
|
|
40
|
-
function
|
|
40
|
+
function defaultSleep(ms) {
|
|
41
41
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Injectable timing for `pollWorkerUntilSettled` (SP-779 / #308). Tests pass a
|
|
46
|
+
* virtual clock so stall classification is wall-clock independent; production
|
|
47
|
+
* callers omit `deps` and keep the Date.now/setTimeout defaults.
|
|
48
|
+
*
|
|
49
|
+
* @typedef {object} WorkerPollDeps
|
|
50
|
+
* @property {() => number} [now] Clock read at the top of every poll (default `Date.now`).
|
|
51
|
+
* @property {(ms: number) => Promise<void>} [sleep] Inter-poll wait (default `setTimeout`).
|
|
52
|
+
*/
|
|
53
|
+
|
|
44
54
|
/**
|
|
45
55
|
* @typedef {object} WorkerPollState
|
|
46
56
|
* @property {number} stallAnchorAt
|
|
@@ -112,6 +122,7 @@ export function createWorkerPollState(startedAt, workerPhase) {
|
|
|
112
122
|
* signals?: object;
|
|
113
123
|
* }) => object} params.buildFailureResult
|
|
114
124
|
* @param {string} params.workerMode
|
|
125
|
+
* @param {WorkerPollDeps} [params.deps] Injectable timing; defaults preserve production behavior.
|
|
115
126
|
* @returns {Promise<
|
|
116
127
|
* | { kind: "settled"; postDoneTerminated: boolean }
|
|
117
128
|
* | { kind: "failure"; result: object }
|
|
@@ -139,7 +150,9 @@ export async function pollWorkerUntilSettled({
|
|
|
139
150
|
onHeartbeat,
|
|
140
151
|
buildFailureResult,
|
|
141
152
|
workerMode,
|
|
153
|
+
deps = {},
|
|
142
154
|
}) {
|
|
155
|
+
const { now: nowFn = Date.now, sleep: sleepFn = defaultSleep } = deps;
|
|
143
156
|
let {
|
|
144
157
|
stallAnchorAt,
|
|
145
158
|
lastCheckpointAt,
|
|
@@ -157,7 +170,7 @@ export async function pollWorkerUntilSettled({
|
|
|
157
170
|
|
|
158
171
|
while (true) {
|
|
159
172
|
const doneOnDisk = fs.existsSync(donePath);
|
|
160
|
-
const now =
|
|
173
|
+
const now = nowFn();
|
|
161
174
|
|
|
162
175
|
if (doneOnDisk && postDoneStartedAt === null) {
|
|
163
176
|
postDoneStartedAt = now;
|
|
@@ -208,7 +221,10 @@ export async function pollWorkerUntilSettled({
|
|
|
208
221
|
await terminateHungWorkerChild(workerChild, childDone);
|
|
209
222
|
break;
|
|
210
223
|
}
|
|
211
|
-
|
|
224
|
+
// #308: race the inter-poll wait against child exit so a worker that
|
|
225
|
+
// finishes right after writing .DONE is observed on its next wake
|
|
226
|
+
// instead of a full interval later.
|
|
227
|
+
await Promise.race([sleepFn(Math.min(stallConfig.pollIntervalMs, 5_000)), childDone]);
|
|
212
228
|
continue;
|
|
213
229
|
}
|
|
214
230
|
|
|
@@ -346,6 +362,15 @@ export async function pollWorkerUntilSettled({
|
|
|
346
362
|
lastHeartbeatAt = now;
|
|
347
363
|
}
|
|
348
364
|
|
|
365
|
+
// #308: observe child exit before the stall deadline. A worker that exits
|
|
366
|
+
// on its own between polls is settled work, never a stall — even when the
|
|
367
|
+
// next poll lands past the budget (the old order classified such exits
|
|
368
|
+
// `stall_timeout`). The bottom sleep races `childDone`, so exits are seen
|
|
369
|
+
// promptly; handles resolve `childDone` only after `exitCode` is set.
|
|
370
|
+
if (workerChild.exitCode !== null) {
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
|
|
349
374
|
const stallDeadline = computeStallDeadline({
|
|
350
375
|
startedAt,
|
|
351
376
|
lastProgressAt: lastCheckpointAt,
|
|
@@ -396,11 +421,7 @@ export async function pollWorkerUntilSettled({
|
|
|
396
421
|
};
|
|
397
422
|
}
|
|
398
423
|
|
|
399
|
-
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
await sleep(Math.min(stallConfig.pollIntervalMs, 5_000));
|
|
424
|
+
await Promise.race([sleepFn(Math.min(stallConfig.pollIntervalMs, 5_000)), childDone]);
|
|
404
425
|
}
|
|
405
426
|
|
|
406
427
|
return { kind: "settled", postDoneTerminated };
|
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
import { parseContract, parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
14
14
|
import { appendJournalEvent } from "./journal.mjs";
|
|
15
15
|
import { assertReviewToolAvailable } from "./review.mjs";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
finalizeWorkerOutput,
|
|
18
|
+
createWorkerLiveLogWriter,
|
|
19
|
+
resolveWorkerOutputConfig,
|
|
20
|
+
} from "./worker-output.mjs";
|
|
17
21
|
import { resolveWorkerBackend } from "../config/worker-backend.mjs";
|
|
18
22
|
import { commandExists } from "../util/command-exists.mjs";
|
|
19
23
|
import {
|
|
@@ -262,6 +266,7 @@ export async function runWorker({
|
|
|
262
266
|
childPastPreflight = true;
|
|
263
267
|
});
|
|
264
268
|
onWorkerPid?.(workerChild.pid ?? 0);
|
|
269
|
+
const outputConfig = resolveWorkerOutputConfig(config);
|
|
265
270
|
const liveLogWriter = createWorkerLiveLogWriter({
|
|
266
271
|
projectRoot,
|
|
267
272
|
batchId,
|
|
@@ -269,7 +274,7 @@ export async function runWorker({
|
|
|
269
274
|
taskId,
|
|
270
275
|
config,
|
|
271
276
|
});
|
|
272
|
-
const childDone = collectChildOutput(workerChild, liveLogWriter);
|
|
277
|
+
const childDone = collectChildOutput(workerChild, liveLogWriter, outputConfig.maxBytes);
|
|
273
278
|
|
|
274
279
|
const pollState = createWorkerPollState(startedAt, initialWorkerPhase);
|
|
275
280
|
const pollOutcome = await pollWorkerUntilSettled({
|
|
@@ -315,12 +320,32 @@ export async function runWorker({
|
|
|
315
320
|
|
|
316
321
|
const childResult = await Promise.race([childDone, sleep(CHILD_DONE_TIMEOUT_MS).then(() => null)]);
|
|
317
322
|
let exitCode, output;
|
|
323
|
+
/** @type {boolean} */
|
|
324
|
+
let spawnFailed = false;
|
|
318
325
|
if (childResult) {
|
|
319
|
-
({ exitCode, output } = childResult);
|
|
326
|
+
({ exitCode, output, spawnError: spawnFailed = false } = childResult);
|
|
320
327
|
} else {
|
|
321
328
|
// close event didn't fire — sub-processes likely hold stdio pipes open.
|
|
322
329
|
const fallback = await terminateHungWorkerChild(workerChild, childDone);
|
|
323
|
-
({ exitCode, output } = fallback);
|
|
330
|
+
({ exitCode, output, spawnError: spawnFailed = false } = fallback);
|
|
331
|
+
}
|
|
332
|
+
// SP-787 (#306): the child never spawned (EACCES/ENOENT/missing execPath).
|
|
333
|
+
// Report `launch_failed` for this lane through the standard failure path so
|
|
334
|
+
// the engine keeps running; no worker code ran, so .DONE cannot be honored.
|
|
335
|
+
if (spawnFailed) {
|
|
336
|
+
return buildWorkerFailureResult({
|
|
337
|
+
rawOutput: output,
|
|
338
|
+
classification: "launch_failed",
|
|
339
|
+
exitCode,
|
|
340
|
+
mode: workerMode,
|
|
341
|
+
doneFound: fs.existsSync(donePath),
|
|
342
|
+
projectRoot,
|
|
343
|
+
batchId,
|
|
344
|
+
laneNumber,
|
|
345
|
+
taskId,
|
|
346
|
+
laneCorrelationId,
|
|
347
|
+
config,
|
|
348
|
+
});
|
|
324
349
|
}
|
|
325
350
|
const doneFound = fs.existsSync(donePath);
|
|
326
351
|
if (postDoneTerminated && !doneFound) {
|
|
@@ -192,7 +192,9 @@ export function truncateLiveLogBytes(text, maxBytes) {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
-
* Append redacted worker output to the live log
|
|
195
|
+
* Append redacted worker output to the live log (SP-787 / #306). The hot path
|
|
196
|
+
* is a pure append — the file is never re-read per chunk. Only when it has
|
|
197
|
+
* grown past twice `workerLiveLogMaxBytes` is it truncated back to the cap.
|
|
196
198
|
*
|
|
197
199
|
* @param {object} params
|
|
198
200
|
* @param {string} params.logPath
|
|
@@ -205,12 +207,13 @@ export function appendWorkerLiveLogChunk({ logPath, rawChunk, outputConfig }) {
|
|
|
205
207
|
const redacted = redactWorkerOutput(String(rawChunk), outputConfig);
|
|
206
208
|
if (!redacted) return;
|
|
207
209
|
|
|
208
|
-
const prior = fs.existsSync(logPath) ? fs.readFileSync(logPath, "utf-8") : "";
|
|
209
|
-
const combined = `${prior}${redacted}`;
|
|
210
|
-
const capped = truncateLiveLogBytes(combined, outputConfig.workerLiveLogMaxBytes);
|
|
211
|
-
if (!capped) return;
|
|
212
|
-
|
|
213
210
|
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
|
211
|
+
fs.appendFileSync(logPath, redacted);
|
|
212
|
+
|
|
213
|
+
const size = fs.statSync(logPath, { throwIfNoEntry: false })?.size ?? 0;
|
|
214
|
+
if (size <= outputConfig.workerLiveLogMaxBytes * 2) return;
|
|
215
|
+
|
|
216
|
+
const capped = truncateLiveLogBytes(fs.readFileSync(logPath, "utf-8"), outputConfig.workerLiveLogMaxBytes);
|
|
214
217
|
writeTextAtomic(logPath, capped);
|
|
215
218
|
}
|
|
216
219
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { buildWorkerContextAsync } from "../config/worker-context.mjs";
|
|
9
|
+
import { taskIdFromFolderName } from "../tasks/packet/discover.mjs";
|
|
9
10
|
|
|
10
11
|
export function buildReviewLevelHint(reviewLevel) {
|
|
11
12
|
if (reviewLevel <= 0) {
|
|
@@ -44,7 +45,7 @@ export async function buildWorkerTailPrompt({
|
|
|
44
45
|
worktreePath,
|
|
45
46
|
taskFolder,
|
|
46
47
|
donePath,
|
|
47
|
-
taskIdHint =
|
|
48
|
+
taskIdHint = taskIdFromFolder(taskFolder),
|
|
48
49
|
reviewLevel = 0,
|
|
49
50
|
includePromptInclude = false,
|
|
50
51
|
config = {},
|
|
@@ -81,5 +82,6 @@ export async function buildWorkerTailPrompt({
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
export function taskIdFromFolder(taskFolder) {
|
|
84
|
-
|
|
85
|
+
// Shared pattern (SP-785, #300); keeps the TASK-ID fallback for unparseable names.
|
|
86
|
+
return taskIdFromFolderName(path.basename(taskFolder)) ?? "TASK-ID";
|
|
85
87
|
}
|
|
@@ -7,6 +7,7 @@ import path from "node:path";
|
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { startAgentSessionWorker } from "./agent-session-worker.mjs";
|
|
10
|
+
import { DEFAULT_MAX_BYTES } from "./worker-output.mjs";
|
|
10
11
|
import { resolveWorkerBackend } from "../config/worker-backend.mjs";
|
|
11
12
|
import { resolvePiSpineRoot } from "../config/pi-spine-root.mjs";
|
|
12
13
|
import { resolveSafeWorkerLaunchScript } from "../config/worker-launch-script.mjs";
|
|
@@ -215,12 +216,13 @@ export function spawnExecutionOnlyHandle({
|
|
|
215
216
|
config,
|
|
216
217
|
});
|
|
217
218
|
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
// Run the command, then create the .DONE marker. The path is passed as a
|
|
220
|
+
// positional parameter (`$1`) instead of being interpolated into the script
|
|
221
|
+
// string, so a task folder containing `"`, `$(`, or a backtick is never
|
|
222
|
+
// evaluated as shell code (SP-787 / #306). The third element is `$0`.
|
|
223
|
+
const donePath = path.join(taskFolder, ".DONE");
|
|
224
|
+
|
|
225
|
+
return spawn("/bin/sh", ["-c", `${command} && touch "$1"`, "sh", donePath], {
|
|
224
226
|
cwd: worktreePath,
|
|
225
227
|
env,
|
|
226
228
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -286,28 +288,113 @@ export async function terminateHungWorkerChild(child, childDone) {
|
|
|
286
288
|
}
|
|
287
289
|
|
|
288
290
|
/**
|
|
291
|
+
* Append `text` to a bounded tail buffer, keeping only the last `maxBytes`.
|
|
292
|
+
*
|
|
293
|
+
* @param {Buffer<ArrayBufferLike>} tail
|
|
294
|
+
* @param {string} text
|
|
295
|
+
* @param {number} maxBytes
|
|
296
|
+
* @returns {Buffer<ArrayBufferLike>}
|
|
297
|
+
*/
|
|
298
|
+
function appendToBoundedTail(tail, text, maxBytes) {
|
|
299
|
+
const chunk = Buffer.from(text, "utf-8");
|
|
300
|
+
if (maxBytes <= 0) return Buffer.alloc(0);
|
|
301
|
+
const combined = tail.byteLength === 0 ? chunk : Buffer.concat([tail, chunk]);
|
|
302
|
+
return combined.byteLength > maxBytes
|
|
303
|
+
? combined.subarray(combined.byteLength - maxBytes)
|
|
304
|
+
: combined;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Collect child stdout/stderr into a bounded tail (SP-787 / #306) and settle
|
|
309
|
+
* on either `close` or a spawn `error`, whichever comes first. A child that
|
|
310
|
+
* never spawned (EACCES/ENOENT, missing execPath) emits `error` and then a
|
|
311
|
+
* synthetic `close`, so the error path resolves once with `spawnError: true`
|
|
312
|
+
* and the conventional exit code 127; the close handler is guarded so the
|
|
313
|
+
* later close cannot override the spawn failure. Without the `error` listener
|
|
314
|
+
* the engine itself would crash on the unhandled event and lose every lane.
|
|
315
|
+
*
|
|
289
316
|
* @param {WorkerChildHandle} child
|
|
290
317
|
* @param {{ append: (rawChunk: string) => void } | null} [liveLogWriter]
|
|
318
|
+
* @param {number} [maxBytes] Byte cap for the collected output tail; defaults
|
|
319
|
+
* to the worker output cap. Memory stays bounded regardless of child runtime.
|
|
320
|
+
* @returns {Promise<{ exitCode: number; output: string; spawnError?: boolean }>}
|
|
291
321
|
*/
|
|
292
|
-
export function collectChildOutput(child, liveLogWriter) {
|
|
322
|
+
export function collectChildOutput(child, liveLogWriter, maxBytes) {
|
|
293
323
|
if ("wait" in child && typeof child.wait === "function") {
|
|
294
324
|
return child.wait();
|
|
295
325
|
}
|
|
326
|
+
const cap =
|
|
327
|
+
typeof maxBytes === "number" && Number.isFinite(maxBytes) && maxBytes > 0
|
|
328
|
+
? maxBytes
|
|
329
|
+
: DEFAULT_MAX_BYTES;
|
|
296
330
|
return new Promise((resolve) => {
|
|
297
|
-
|
|
298
|
-
let
|
|
331
|
+
/** @type {Buffer<ArrayBufferLike>} */
|
|
332
|
+
let stdoutTail = Buffer.alloc(0);
|
|
333
|
+
/** @type {Buffer<ArrayBufferLike>} */
|
|
334
|
+
let stderrTail = Buffer.alloc(0);
|
|
335
|
+
/** @type {string|null} */
|
|
336
|
+
let spawnErrorMessage = null;
|
|
337
|
+
let settled = false;
|
|
338
|
+
|
|
339
|
+
// stdout-then-stderr order as before; the combined string keeps the last
|
|
340
|
+
// `cap` bytes overall.
|
|
341
|
+
const combinedOutput = () => {
|
|
342
|
+
const combined = Buffer.concat([stdoutTail, stderrTail]);
|
|
343
|
+
const bounded =
|
|
344
|
+
combined.byteLength > cap
|
|
345
|
+
? combined.subarray(combined.byteLength - cap)
|
|
346
|
+
: combined;
|
|
347
|
+
return bounded.toString("utf-8");
|
|
348
|
+
};
|
|
349
|
+
const settle = (
|
|
350
|
+
/** @type {() => { exitCode: number; output: string; spawnError?: boolean }} */ build,
|
|
351
|
+
) => {
|
|
352
|
+
if (settled) return;
|
|
353
|
+
settled = true;
|
|
354
|
+
resolve(build());
|
|
355
|
+
};
|
|
356
|
+
const spawnFailureResult = () => ({
|
|
357
|
+
exitCode: 127,
|
|
358
|
+
output: `${combinedOutput()}${spawnErrorMessage ?? ""}`,
|
|
359
|
+
spawnError: true,
|
|
360
|
+
});
|
|
361
|
+
|
|
299
362
|
child.stdout?.on("data", (/** @type {Buffer | string} */ chunk) => {
|
|
300
363
|
const text = chunk.toString();
|
|
301
|
-
|
|
364
|
+
stdoutTail = appendToBoundedTail(stdoutTail, text, cap);
|
|
302
365
|
liveLogWriter?.append(text);
|
|
303
366
|
});
|
|
304
367
|
child.stderr?.on("data", (/** @type {Buffer | string} */ chunk) => {
|
|
305
368
|
const text = chunk.toString();
|
|
306
|
-
|
|
369
|
+
stderrTail = appendToBoundedTail(stderrTail, text, cap);
|
|
307
370
|
liveLogWriter?.append(text);
|
|
308
371
|
});
|
|
372
|
+
child.on?.("error", (/** @type {unknown} */ err) => {
|
|
373
|
+
spawnErrorMessage = String(err);
|
|
374
|
+
// A child that failed to spawn has no real exit status. Flag the handle
|
|
375
|
+
// as settled so poll loops keyed on `exitCode` stop polling — older
|
|
376
|
+
// runtimes leave `exitCode` null on failed spawns (Node ≥22 sets a
|
|
377
|
+
// negative errno instead). The property is a plain writable own field.
|
|
378
|
+
if (child.exitCode === null || child.exitCode < 0) {
|
|
379
|
+
try {
|
|
380
|
+
// exitCode is readonly on the Node ChildProcess type; a failed spawn
|
|
381
|
+
// has no real status, so flagging it is safe and intentional.
|
|
382
|
+
const writableExitCode = /** @type {{ exitCode: number | null }} */ (
|
|
383
|
+
/** @type {unknown} */ (child)
|
|
384
|
+
);
|
|
385
|
+
writableExitCode.exitCode = 127;
|
|
386
|
+
} catch {
|
|
387
|
+
// Read-only test double; the resolved promise still settles the host.
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
settle(spawnFailureResult);
|
|
391
|
+
});
|
|
309
392
|
child.on?.("close", (/** @type {number | null} */ code) => {
|
|
310
|
-
|
|
393
|
+
if (spawnErrorMessage !== null) {
|
|
394
|
+
settle(spawnFailureResult);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
settle(() => ({ exitCode: code ?? 1, output: combinedOutput() }));
|
|
311
398
|
});
|
|
312
399
|
});
|
|
313
400
|
}
|
|
@@ -6,13 +6,12 @@ import { loadSpineConfig } from "../spine-config-load.mjs";
|
|
|
6
6
|
import { missingConfigHint } from "../missing-config-hint.mjs";
|
|
7
7
|
import { resolveTasksRootPath } from "../env-overrides.mjs";
|
|
8
8
|
import { validateWorktreeSetupHookConfig } from "../worktree-setup-hook.mjs";
|
|
9
|
-
import { discoverTasks } from "../../tasks/packet/discover.mjs";
|
|
9
|
+
import { discoverTasks, TASK_ID_RE, taskIdFromFolderName } from "../../tasks/packet/discover.mjs";
|
|
10
10
|
import { NO_PENDING_TASKS_ERROR } from "../../planner/scope.mjs";
|
|
11
11
|
import { summarizePendingScope } from "../../planner/pending.mjs";
|
|
12
12
|
import { validatePrompt } from "../../tasks/packet/validate-prompt.mjs";
|
|
13
13
|
|
|
14
14
|
const DEPENDENCIES_SCHEMA_VERSION = 1;
|
|
15
|
-
const TASK_ID_PATTERN = /^[A-Z]{2,}-\d{3,}$/;
|
|
16
15
|
|
|
17
16
|
function makeCheck(id, ok, message, extra = {}) {
|
|
18
17
|
return { id, ok, message, ...extra };
|
|
@@ -31,24 +30,33 @@ export function resolveTasksRoot(projectRoot, configResult) {
|
|
|
31
30
|
return resolveTasksRootPath(projectRoot, loaded.config);
|
|
32
31
|
}
|
|
33
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Task ID from a folder name — delegates to the shared pattern (SP-785, #300).
|
|
35
|
+
*
|
|
36
|
+
* @param {string} folderName
|
|
37
|
+
* @returns {string | null}
|
|
38
|
+
*/
|
|
34
39
|
export function taskIdFromFolder(folderName) {
|
|
35
|
-
|
|
36
|
-
return match?.[1] ?? null;
|
|
40
|
+
return taskIdFromFolderName(folderName);
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Discoverable task folders (PREFIX-###-slug with PROMPT.md), numeric order.
|
|
45
|
+
* Delegates to the planner's discoverTasks so preflight and planner agree.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} tasksRootPath
|
|
48
|
+
* @returns {string[]}
|
|
49
|
+
*/
|
|
39
50
|
export function discoverTaskFolders(tasksRootPath) {
|
|
40
51
|
if (!tasksRootPath || !fs.existsSync(tasksRootPath)) return [];
|
|
41
52
|
|
|
42
|
-
return
|
|
43
|
-
.readdirSync(tasksRootPath, { withFileTypes: true })
|
|
44
|
-
.filter((entry) => entry.isDirectory())
|
|
45
|
-
.map((entry) => entry.name)
|
|
46
|
-
.filter((name) => fs.existsSync(path.join(tasksRootPath, name, "PROMPT.md")))
|
|
47
|
-
.sort();
|
|
53
|
+
return discoverTasks(tasksRootPath).map((task) => task.folderName);
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
export function discoverTaskIds(tasksRootPath) {
|
|
51
|
-
|
|
57
|
+
if (!tasksRootPath || !fs.existsSync(tasksRootPath)) return [];
|
|
58
|
+
|
|
59
|
+
return discoverTasks(tasksRootPath).map((task) => task.taskId);
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
/**
|
|
@@ -148,7 +156,7 @@ export function checkDependenciesJson(ctx) {
|
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
const taskIds = Object.keys(parsed.tasks);
|
|
151
|
-
const invalidIds = taskIds.filter((id) => !
|
|
159
|
+
const invalidIds = taskIds.filter((id) => !TASK_ID_RE.test(id));
|
|
152
160
|
if (invalidIds.length > 0) {
|
|
153
161
|
return makeCheck(
|
|
154
162
|
"dependencies-json",
|
package/src/planner/scope.mjs
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { summarizePendingScope } from './pending.mjs';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// Single source of truth (SP-785, #300): re-export the shared task-ID regex.
|
|
16
|
+
import { TASK_ID_RE } from '../tasks/packet/discover.mjs';
|
|
17
|
+
export { TASK_ID_RE };
|
|
16
18
|
|
|
17
19
|
export const NO_PENDING_TASKS_ERROR = 'No pending tasks (all discovered tasks have .DONE).';
|
|
18
20
|
|
|
@@ -1,12 +1,68 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Canonical task-ID discovery patterns (single source of truth).
|
|
6
|
+
* Closes #300: every discovery site (planner, preflight, worker runner)
|
|
7
|
+
* derives its patterns from here so SP-1000+ is found, sorted numerically,
|
|
8
|
+
* and non-task folders (`_explore`, `_authoring`, `_archive`) are excluded.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Source pattern for a task ID (PREFIX-###, three or more digits), for embedding in larger regexes. */
|
|
12
|
+
export const TASK_ID_PATTERN_SOURCE = "[A-Z][A-Z0-9]*-\\d{3,}";
|
|
13
|
+
|
|
14
|
+
/** Task ID: PREFIX-### (e.g. TP-007, SP-1000). Keeps the planner's existing prefix rule. */
|
|
15
|
+
export const TASK_ID_RE = new RegExp(`^${TASK_ID_PATTERN_SOURCE}$`);
|
|
16
|
+
|
|
4
17
|
/** Folder name: PREFIX-###-slug (e.g. TP-007-taskplane-parsers). */
|
|
5
|
-
export const TASK_FOLDER_RE =
|
|
18
|
+
export const TASK_FOLDER_RE = new RegExp(
|
|
19
|
+
`^(${TASK_ID_PATTERN_SOURCE})-([a-z0-9][a-z0-9-]*)$`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** Prefix + digits of a conforming task ID, for numeric comparison. */
|
|
23
|
+
const TASK_ID_PARTS_RE = /^([A-Z][A-Z0-9]*)-(\d{3,})$/;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Extract the task ID from a folder name (PREFIX-###-slug or bare PREFIX-###).
|
|
27
|
+
* Returns null when the name is not a task folder (e.g. `_explore`).
|
|
28
|
+
*
|
|
29
|
+
* @param {string} name Folder name or path segment
|
|
30
|
+
* @returns {string | null}
|
|
31
|
+
*/
|
|
32
|
+
export function taskIdFromFolderName(name) {
|
|
33
|
+
const base = String(name ?? "").split("/").pop() ?? "";
|
|
34
|
+
const folder = TASK_FOLDER_RE.exec(base);
|
|
35
|
+
if (folder) return folder[1];
|
|
36
|
+
const bare = TASK_ID_RE.exec(base);
|
|
37
|
+
return bare ? bare[0] : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Compare two task IDs: prefix first, then digits numerically.
|
|
42
|
+
* Non-conforming IDs sort after conforming ones, by string.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} a
|
|
45
|
+
* @param {string} b
|
|
46
|
+
* @returns {number}
|
|
47
|
+
*/
|
|
48
|
+
export function compareTaskIds(a, b) {
|
|
49
|
+
const pa = TASK_ID_PARTS_RE.exec(String(a ?? ""));
|
|
50
|
+
const pb = TASK_ID_PARTS_RE.exec(String(b ?? ""));
|
|
51
|
+
if (pa && pb) {
|
|
52
|
+
if (pa[1] !== pb[1]) return pa[1].localeCompare(pb[1]);
|
|
53
|
+
const da = Number(pa[2]);
|
|
54
|
+
const db = Number(pb[2]);
|
|
55
|
+
if (da !== db) return da - db;
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
if (pa) return -1;
|
|
59
|
+
if (pb) return 1;
|
|
60
|
+
return String(a ?? "").localeCompare(String(b ?? ""));
|
|
61
|
+
}
|
|
6
62
|
|
|
7
63
|
/**
|
|
8
64
|
* Discover Taskplane task packets under `{tasksRoot}/{PREFIX-###-slug}/PROMPT.md`.
|
|
9
|
-
* FR-TASK-01.
|
|
65
|
+
* FR-TASK-01. Results sort numerically: SP-099 < SP-999 < SP-1000.
|
|
10
66
|
*
|
|
11
67
|
* @param {string} tasksRoot Absolute or relative path to tasks root (e.g. spine-tasks)
|
|
12
68
|
* @returns {Array<{ taskId: string, slug: string, folderName: string, folderPath: string, promptPath: string }>}
|
|
@@ -35,6 +91,6 @@ export function discoverTasks(tasksRoot) {
|
|
|
35
91
|
});
|
|
36
92
|
}
|
|
37
93
|
|
|
38
|
-
tasks.sort((a, b) => a.taskId
|
|
94
|
+
tasks.sort((a, b) => compareTaskIds(a.taskId, b.taskId));
|
|
39
95
|
return tasks;
|
|
40
96
|
}
|