pi-spine 2.14.1 → 2.16.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/package.json +2 -2
- package/skills/spine-release-operator/SKILL.md +60 -7
- package/skills/spine-release-operator/references/issue-intake-checklist.md +1 -1
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +1 -0
- package/src/batch/abort.mjs +82 -68
- package/src/batch/batch-id.mjs +103 -0
- package/src/batch/batch-state-lock.mjs +357 -0
- package/src/batch/contract-exec.mjs +12 -8
- package/src/batch/diagnosis.mjs +12 -7
- package/src/batch/engine-lanes/review-code.mjs +224 -0
- package/src/batch/engine-lanes/review-final.mjs +318 -0
- package/src/batch/engine-lanes/review-plan.mjs +315 -0
- package/src/batch/engine-lanes/review-poll.mjs +427 -0
- package/src/batch/engine-lanes/review-stub.mjs +146 -0
- package/src/batch/engine-lanes/review.mjs +4 -1532
- package/src/batch/engine.mjs +1 -1
- package/src/batch/journal.mjs +9 -32
- package/src/batch/lifecycle.mjs +106 -95
- package/src/batch/metrics.mjs +13 -26
- package/src/batch/reconcile-orphan.mjs +3 -2
- package/src/batch/salvage-batch-list.mjs +12 -1
- package/src/batch/state-guards.mjs +26 -3
- package/src/batch/state-io.mjs +101 -29
- package/src/batch/state.mjs +7 -13
- package/src/batch/worker-output.mjs +5 -16
- package/src/cli/handoff.mjs +10 -27
- package/src/cli/journal-follow.mjs +11 -2
- package/src/cli/lane-logs.mjs +9 -1
- package/src/config/cursor-rules/profile.mjs +5 -1
- package/src/config/defaults.mjs +10 -1
- package/src/config/settings-fields.mjs +14 -0
- package/src/planner/file-scope.mjs +109 -7
- package/src/process/liveness.mjs +188 -1
- package/src/tasks/analyze/index.mjs +14 -27
- package/src/tasks/packet/parse-prompt.mjs +138 -3
- package/src/util/secret-redact.mjs +140 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-spine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"description": "Orchestration spine for long-running pi development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
|
|
35
35
|
"verify:reconcile-fixtures": "node scripts/verify-reconcile-test-fixtures.mjs",
|
|
36
36
|
"pretest": "npm run verify:reconcile-fixtures",
|
|
37
|
-
"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/metrics/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
|
|
37
|
+
"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/metrics/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs tests/arch/*.test.mjs tests/fs/*.test.mjs",
|
|
38
38
|
"test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
|
|
39
39
|
"test:core": "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/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",
|
|
40
40
|
"test:coverage": "node scripts/run-coverage.mjs --report-only",
|
|
@@ -35,7 +35,8 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
35
35
|
4. `spine preflight` green; **`npm run release:check` green (blocking gate)** on current `main`
|
|
36
36
|
5. **CI workflow green on release commit** (release-safe profile — parity with `ci.yml`) before tag push
|
|
37
37
|
6. Operator explicitly approved publish; version bumped and tag pushed (if approved)
|
|
38
|
-
7.
|
|
38
|
+
7. Every release-scoped `Closes #NNN` / `Closes: #NNN` issue is **CLOSED** on GitHub once its fix is on `main` (close after each land — do not wait for publish)
|
|
39
|
+
8. Final report with composition table, issues closed/deferred, verification output
|
|
39
40
|
|
|
40
41
|
## Hard rules
|
|
41
42
|
|
|
@@ -57,6 +58,7 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
57
58
|
- **Never** mid-release-edit `.spine/spine-config.json` agent pins (`agents.worker.model` / `agents.reviewer.model`) while a batch is running or integrated work is still unpublished. Pin **one worker** per release; escalate models **only** on content/contract failure — never on quota/403 or launch storms, which make releases worse (F7, [#248](https://github.com/beettlle/pi-spine/issues/248)). To override mid-release, first record the reason and date in the release manifest
|
|
58
59
|
- **Heed** the doctor/preflight **quota-risk advisory** ([#251](https://github.com/beettlle/pi-spine/issues/251)): `spine doctor` surfaces `ok: true, warning: true` when escalate/hard worker pins target quota-constrained pools without headroom evidence, or recent run-metrics show launch-storm / quota-abort patterns. It is advisory only — never fails preflight — and does not change the mid-release pin-thrash ban above
|
|
59
60
|
- **Always** push/sync `main` to `origin` after each land loop once the post-integrate regression gate is green — do not let `main` drift far ahead of `origin` during a release (F8, [#249](https://github.com/beettlle/pi-spine/issues/249))
|
|
61
|
+
- **Always** close GitHub issues linked as `Closes #NNN` / `Closes: #NNN` **as soon as that task's work is on `main`** (after integrate + post-integrate `release:check` green) — do **not** defer closing until Phase 6 publish. Leave `Partial #NNN` / `Partial: #NNN` open. Phase 6 is only a final sweep for any still-open `Closes` links (v2.15.0 left #257–#261, #263 open after ship — avoid that)
|
|
60
62
|
- **Do not** start a second batch while another batch is **running** on this repo
|
|
61
63
|
- **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
|
|
62
64
|
- **Release and agent batches:** use **detached** `spine batch start|resume` (omit `--attached`); monitor with MonitorCreate, `spine wait`, or `spine status --diagnose` ([#163](https://github.com/beettlle/pi-spine/issues/163), [#185](https://github.com/beettlle/pi-spine/issues/185)) — see [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md)
|
|
@@ -149,7 +151,7 @@ spine tasks analyze pending
|
|
|
149
151
|
**Map issues to tasks:**
|
|
150
152
|
|
|
151
153
|
```bash
|
|
152
|
-
rg 'Closes:|Partial:' spine-tasks/*/PROMPT.md
|
|
154
|
+
rg 'Closes #|Closes:|Partial #|Partial:' spine-tasks/*/PROMPT.md
|
|
153
155
|
```
|
|
154
156
|
|
|
155
157
|
Read `spine-tasks/CONTEXT.md` for `Next Task ID`.
|
|
@@ -205,7 +207,7 @@ Require explicit **"approve release scope"** before Phase 3.
|
|
|
205
207
|
For issues in manifest without SP-*:
|
|
206
208
|
|
|
207
209
|
- Follow **`create-spine-tasks`** (lean mode default)
|
|
208
|
-
- Mission: `Closes
|
|
210
|
+
- Mission: `Closes #NNN` (or `Closes: #NNN`) — use `Partial #NNN` / `Partial: #NNN` when scoped
|
|
209
211
|
- Size S/M; ≤4 impl steps; Contract + Testing step
|
|
210
212
|
- Update `dependencies.json`, `CONTEXT.md`, increment `Next Task ID`
|
|
211
213
|
|
|
@@ -349,6 +351,42 @@ git push origin main
|
|
|
349
351
|
|
|
350
352
|
Do not let `main` drift far ahead of `origin` between waves — v2.12.1 ran **24 commits ahead** of `origin` at Phase 5 (F8, [#249](https://github.com/beettlle/pi-spine/issues/249)). Local-only releases may defer this push; record the deferral in the manifest publish checklist.
|
|
351
353
|
|
|
354
|
+
### 4.3c Close GitHub issues for landed tasks (blocking hygiene)
|
|
355
|
+
|
|
356
|
+
After §4.3a is green (and §4.3b push when remote publish is the goal), **close every open issue fully resolved by tasks that just landed** — same wave, same land loop. Do not wait for Phase 6 or npm publish.
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Issues linked from the wave's newly-.DONE tasks:
|
|
360
|
+
rg -n 'Closes #|Closes: #' spine-tasks/SP-*/PROMPT.md
|
|
361
|
+
|
|
362
|
+
# For each Closes #NNN (not Partial) whose SP-* is .DONE on main and still OPEN:
|
|
363
|
+
gh issue view NNN --repo beettlle/pi-spine --json state,title
|
|
364
|
+
gh issue close NNN --repo beettlle/pi-spine --reason completed --comment "$(cat <<EOF
|
|
365
|
+
Fixed on \`main\` by **SP-XXX** (release v{TARGET}).
|
|
366
|
+
|
|
367
|
+
- Commit(s): \`<sha>\` — <subject>
|
|
368
|
+
- Batch: <batchId> (integrated)
|
|
369
|
+
EOF
|
|
370
|
+
)"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
| Link in PROMPT Mission | Action after land |
|
|
374
|
+
|------------------------|-------------------|
|
|
375
|
+
| `Closes #NNN` / `Closes: #NNN` | **Close** when that task's `.DONE` is on `main` and §4.3a passed |
|
|
376
|
+
| `Partial #NNN` / `Partial: #NNN` | **Leave open** — note progress in a comment if useful |
|
|
377
|
+
| Manifest-mapped issue with no `Closes` line | Close only if acceptance criteria are fully met; otherwise comment + leave open |
|
|
378
|
+
|
|
379
|
+
**Fail closed before next wave / Phase 5:** every release-scoped `Closes #NNN` for tasks already `.DONE` on `main` must show `state: CLOSED`. Re-check:
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# Example: verify still-open Closes targets for release-scoped DONE tasks
|
|
383
|
+
for n in $(rg -o 'Closes:? #([0-9]+)' -r '$1' spine-tasks/SP-*/PROMPT.md | sort -u); do
|
|
384
|
+
gh issue view "$n" --repo beettlle/pi-spine --json number,state -q '"\(.number) \(.state)"'
|
|
385
|
+
done
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Record closed issue numbers in the release manifest intake / composition notes.
|
|
389
|
+
|
|
352
390
|
### 4.4 Recovery
|
|
353
391
|
|
|
354
392
|
Always: `spine status --diagnose`
|
|
@@ -489,20 +527,33 @@ If retries exhaust, **STOP** — treat it as a real missing-version failure and
|
|
|
489
527
|
|
|
490
528
|
Update `spine-tasks/CONTEXT.md` release note (version + date).
|
|
491
529
|
|
|
492
|
-
Close GitHub issues
|
|
530
|
+
### Close remaining GitHub issues (final sweep)
|
|
531
|
+
|
|
532
|
+
§4.3c should already have closed each `Closes #NNN` when its task landed. Before the final report, **sweep** any still-open issues that release-scoped DONE tasks fully resolve:
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
rg -n 'Closes #|Closes: #' spine-tasks/SP-*/PROMPT.md
|
|
536
|
+
# For each still-OPEN Closes #NNN whose SP-* is .DONE on main:
|
|
537
|
+
gh issue close NNN --repo beettlle/pi-spine --reason completed --comment "…"
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
Include the published version/tag in the close comment when closing at Phase 6 (e.g. `Shipped in **v{TARGET}**`). Leave `Partial #NNN` open.
|
|
541
|
+
|
|
542
|
+
**Fail closed:** do not mark the release cycle complete while any release-scoped `Closes #NNN` issue remains OPEN.
|
|
493
543
|
|
|
494
544
|
---
|
|
495
545
|
|
|
496
546
|
## Final report (required)
|
|
497
547
|
|
|
498
548
|
1. **Release manifest** — path, target version, profile, composition table
|
|
499
|
-
2. **Tasks completed** — SP-IDs, waves, issues closed
|
|
500
|
-
3. **Deferred backlog** — count and top items for next release
|
|
549
|
+
2. **Tasks completed** — SP-IDs, waves, issues closed (list `#NNN` CLOSED with close time or comment URL)
|
|
550
|
+
3. **Deferred backlog** — count and top items for next release (issues left OPEN + rationale)
|
|
501
551
|
4. **Authoring changes** — new SP-* created, splits/fixes in Phase 3
|
|
502
552
|
5. **Issues filed** — pi-spine GitHub links or "none"
|
|
503
553
|
6. **Recovery actions** — aborts, retries, contract fixes
|
|
504
554
|
7. **Verification** — paste `spine preflight` tail, **`npm run release:check` output** (or log path), test/coverage output
|
|
505
555
|
8. **Publish** — version bumped (Y/N), tag pushed (Y/N), workflow URL, or "awaiting operator approval"
|
|
556
|
+
9. **Issue tracker hygiene** — confirm every release-scoped `Closes #NNN` is CLOSED (paste `gh issue view` states or list)
|
|
506
557
|
|
|
507
558
|
---
|
|
508
559
|
|
|
@@ -527,6 +578,8 @@ preflight → for each wave: MonitorCreate batch start (or foreground) → onDon
|
|
|
527
578
|
gate approve → integrate → npm install → batch complete →
|
|
528
579
|
post-integrate release:check (exit 0 required; no tail-only verification) →
|
|
529
580
|
git push origin main when remote publish is the goal (F8) →
|
|
530
|
-
|
|
581
|
+
close Closes #NNN issues for tasks that just landed (§4.3c; do not wait for publish) →
|
|
582
|
+
MonitorCreate release:check → HARD STOP if non-zero (fix on main, re-run) → only if exit 0: verify ci.yml green on HEAD (gh run list/watch) → HARD STOP if not green → only then: STOP for publish approval →
|
|
583
|
+
after publish: Phase 6 issue sweep for any still-open Closes links → final report must list CLOSED issue numbers.
|
|
531
584
|
resume --attached --force stays foreground. Post final report with composition table.
|
|
532
585
|
```
|
|
@@ -71,7 +71,7 @@ Prefer when:
|
|
|
71
71
|
|
|
72
72
|
Exclude when:
|
|
73
73
|
|
|
74
|
-
- Fixed on `main` but issue not closed
|
|
74
|
+
- Fixed on `main` but issue not closed — **unless** this release will close it immediately (hygiene debt from a prior land; close in §4.3c / Phase 6 sweep before selecting new work for the same issue)
|
|
75
75
|
- Requires external repo reproduction without minimal repro
|
|
76
76
|
- Blocked by epic infrastructure not in this release
|
|
77
77
|
|
|
@@ -15,6 +15,7 @@ Run on current `main` after:
|
|
|
15
15
|
3. **Before next wave** — do not start wave N+1 until gate passes on `main`
|
|
16
16
|
4. **Before first `git push origin main`** during a release cycle
|
|
17
17
|
5. **Before `npm version`** — Phase 5 `release:check` (same command; re-run if `main` moved)
|
|
18
|
+
6. **After gate green** — close GitHub `Closes #NNN` issues for tasks that just landed (spine-release-operator §4.3c); do not defer until publish
|
|
18
19
|
|
|
19
20
|
---
|
|
20
21
|
|
package/src/batch/abort.mjs
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
9
|
+
import { writeJsonAtomic } from "../fs/atomic-write.mjs";
|
|
9
10
|
import { archiveBatchStatePath } from "./lifecycle.mjs";
|
|
10
11
|
import { appendJournalEvent, journalPath, readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
11
12
|
import { loadBatchStateFile } from "./reconcile.mjs";
|
|
12
13
|
import { appendBatchHistoryEntry } from "./state.mjs";
|
|
14
|
+
import { withBatchStateLock } from "./batch-state-lock.mjs";
|
|
13
15
|
import { removeLaneWorktrees, maxLaneNumberFromBatchState } from "./worktree.mjs";
|
|
14
16
|
import { terminateLaneWorkers } from "./worker-host.mjs";
|
|
15
17
|
|
|
@@ -36,15 +38,21 @@ export function readAbortSignal(projectRoot, batchId) {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/**
|
|
41
|
+
* Write the abort signal atomically under the global batch-state lock
|
|
42
|
+
* (SP-722 / #264) so a concurrent engine heartbeat never observes a
|
|
43
|
+
* half-written signal.
|
|
44
|
+
*
|
|
39
45
|
* @param {string} projectRoot
|
|
40
46
|
* @param {string} batchId
|
|
41
47
|
* @param {object} payload
|
|
42
48
|
*/
|
|
43
49
|
export function writeAbortSignal(projectRoot, batchId, payload) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
return withBatchStateLock(projectRoot, () => {
|
|
51
|
+
const signalPath = abortSignalPath(projectRoot, batchId);
|
|
52
|
+
fs.mkdirSync(path.dirname(signalPath), { recursive: true });
|
|
53
|
+
writeJsonAtomic(signalPath, payload);
|
|
54
|
+
return signalPath;
|
|
55
|
+
});
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
/**
|
|
@@ -211,77 +219,83 @@ export function abortBatch(ctx) {
|
|
|
211
219
|
};
|
|
212
220
|
}
|
|
213
221
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
// Terminal abort write section runs under the global batch-state lock
|
|
223
|
+
// (SP-722 / #264): abort signal, archive, history entry, and clearing the
|
|
224
|
+
// active state must not interleave with a concurrent engine save or a
|
|
225
|
+
// concurrent complete/resume writer.
|
|
226
|
+
return withBatchStateLock(projectRoot, () => {
|
|
227
|
+
const snapshot = buildAbortedSnapshot(loaded.raw, reason);
|
|
228
|
+
writeAbortSignal(projectRoot, batchId, {
|
|
229
|
+
hard,
|
|
230
|
+
reason: reason ?? null,
|
|
231
|
+
requestedAt: new Date().toISOString(),
|
|
232
|
+
});
|
|
220
233
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
234
|
+
if (hard) {
|
|
235
|
+
killLaneWorkers(snapshot.lanes, true);
|
|
236
|
+
}
|
|
224
237
|
|
|
225
|
-
|
|
238
|
+
const archivePath = writeBatchArchive(projectRoot, batchId, snapshot);
|
|
226
239
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
240
|
+
const eventsBefore = readJournalEvents(projectRoot, batchId);
|
|
241
|
+
const journalTail = readJournalTail(eventsBefore);
|
|
242
|
+
appendJournalEvent(projectRoot, batchId, "batch.aborted", {
|
|
243
|
+
reason: reason ?? null,
|
|
244
|
+
hard,
|
|
245
|
+
archivePath: path.relative(projectRoot, archivePath),
|
|
246
|
+
journalEventsBeforeAbort: eventsBefore.length,
|
|
247
|
+
journalTailEventTypes: journalTail.map((event) => event.type),
|
|
248
|
+
});
|
|
236
249
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
250
|
+
const journalFile = journalPath(projectRoot, batchId);
|
|
251
|
+
if (!fs.existsSync(journalFile)) {
|
|
252
|
+
return {
|
|
253
|
+
ok: false,
|
|
254
|
+
exitCode: 1,
|
|
255
|
+
error: "journal_missing_after_abort",
|
|
256
|
+
headline: "Abort archived state but journal file is missing",
|
|
257
|
+
suggestedCommand: "spine status --diagnose",
|
|
258
|
+
batchId,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
248
261
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
appendBatchHistoryEntry(projectRoot, {
|
|
263
|
+
batchId,
|
|
264
|
+
action: "aborted",
|
|
265
|
+
endedAt: snapshot.endedAt,
|
|
266
|
+
hard,
|
|
267
|
+
reason: reason ?? null,
|
|
268
|
+
archivePath: path.relative(projectRoot, archivePath),
|
|
269
|
+
});
|
|
257
270
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
271
|
+
if (hard) {
|
|
272
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
273
|
+
const config = configResult.config ?? {};
|
|
274
|
+
if (shouldCleanupWorktreesOnHardAbort(config)) {
|
|
275
|
+
const laneCount = maxLaneNumberFromBatchState(snapshot);
|
|
276
|
+
removeLaneWorktrees(projectRoot, batchId, laneCount);
|
|
277
|
+
appendJournalEvent(projectRoot, batchId, "batch.worktrees_cleaned", {
|
|
278
|
+
batchId,
|
|
279
|
+
laneCount,
|
|
280
|
+
reason: "hard_abort",
|
|
281
|
+
});
|
|
282
|
+
}
|
|
269
283
|
}
|
|
270
|
-
}
|
|
271
284
|
|
|
272
|
-
|
|
285
|
+
clearActiveBatchState(loaded.path);
|
|
273
286
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
return {
|
|
288
|
+
ok: true,
|
|
289
|
+
exitCode: 0,
|
|
290
|
+
batchId,
|
|
291
|
+
diagnosis: "aborted",
|
|
292
|
+
hard,
|
|
293
|
+
headline: hard
|
|
294
|
+
? `Batch ${batchId} hard-aborted and archived`
|
|
295
|
+
: `Batch ${batchId} aborted and archived`,
|
|
296
|
+
suggestedCommand: "spine preflight",
|
|
297
|
+
alternatives: ["spine batch dismiss", "spine status --diagnose"],
|
|
298
|
+
archivePath,
|
|
299
|
+
};
|
|
300
|
+
});
|
|
287
301
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Batch ID validation and uniquified generation (SP-714, issue #258).
|
|
4
|
+
*
|
|
5
|
+
* Batch IDs become directory names under `.spine/runtime/{batchId}` and are
|
|
6
|
+
* also accepted from operators via CLI `--batch`. Validation is allowlist-based
|
|
7
|
+
* so path traversal (`..`, `/`, `\`, NUL, empty, absolute paths) is rejected at
|
|
8
|
+
* the CLI boundary before any `path.join`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import crypto from "node:crypto";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Allowlist pattern for batch IDs.
|
|
17
|
+
*
|
|
18
|
+
* The first character must be alphanumeric so `.`, `..`, and hidden relative
|
|
19
|
+
* segments can never pass; the remainder permits `.`, `_`, and `-` for
|
|
20
|
+
* backward compatibility with archived timestamp IDs (`YYYYMMDDTHHMMSS`) and
|
|
21
|
+
* the uniquified `YYYYMMDDTHHMMSS-xxxx` form. Slashes, backslashes, colons,
|
|
22
|
+
* and NUL are excluded, which also rejects absolute and UNC paths.
|
|
23
|
+
*/
|
|
24
|
+
export const BATCH_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {unknown} batchId
|
|
28
|
+
* @returns {string|null} rejection reason, or null when the ID is valid
|
|
29
|
+
*/
|
|
30
|
+
export function batchIdRejectionReason(batchId) {
|
|
31
|
+
if (typeof batchId !== "string" || batchId.length === 0) {
|
|
32
|
+
return "must be a non-empty string";
|
|
33
|
+
}
|
|
34
|
+
if (batchId.includes("\0")) {
|
|
35
|
+
return "must not contain NUL bytes";
|
|
36
|
+
}
|
|
37
|
+
if (!BATCH_ID_PATTERN.test(batchId)) {
|
|
38
|
+
return (
|
|
39
|
+
`must match ${BATCH_ID_PATTERN} ` +
|
|
40
|
+
"(letters, digits, dot, underscore, dash; must start with a letter or digit; no path separators)"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (batchId.includes("..")) {
|
|
44
|
+
return 'must not contain ".." path traversal sequences';
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {unknown} batchId
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
53
|
+
export function isValidBatchId(batchId) {
|
|
54
|
+
return batchIdRejectionReason(batchId) === null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Assert a batch ID is safe to join under `.spine/runtime/`; throw otherwise.
|
|
59
|
+
*
|
|
60
|
+
* @param {unknown} batchId
|
|
61
|
+
* @returns {string} the validated batch ID
|
|
62
|
+
*/
|
|
63
|
+
export function validateBatchId(batchId) {
|
|
64
|
+
const reason = batchIdRejectionReason(batchId);
|
|
65
|
+
if (reason) {
|
|
66
|
+
throw new Error(`Invalid batch ID ${JSON.stringify(String(batchId))}: ${reason}`);
|
|
67
|
+
}
|
|
68
|
+
return /** @type {string} */ (batchId);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const MAX_UNIQUIFY_ATTEMPTS = 64;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Generate a collision-resistant batch ID `{YYYYMMDD}T{HHmmss}-{hex4}` (UTC).
|
|
75
|
+
*
|
|
76
|
+
* The random 4-hex suffix keeps concurrent calls distinct; when `projectRoot`
|
|
77
|
+
* is provided the loop also re-draws while `.spine/runtime/{id}` exists, so a
|
|
78
|
+
* stale runtime/archive directory can never be reused.
|
|
79
|
+
*
|
|
80
|
+
* @param {Date} [now]
|
|
81
|
+
* @param {string|null} [projectRoot] when set, loop until the runtime dir is absent
|
|
82
|
+
* @param {(() => string)|null} [randomSuffix] injectable suffix source for tests
|
|
83
|
+
* @returns {string}
|
|
84
|
+
*/
|
|
85
|
+
export function generateBatchId(now = new Date(), projectRoot = null, randomSuffix = null) {
|
|
86
|
+
const y = now.getUTCFullYear();
|
|
87
|
+
const m = String(now.getUTCMonth() + 1).padStart(2, "0");
|
|
88
|
+
const d = String(now.getUTCDate()).padStart(2, "0");
|
|
89
|
+
const h = String(now.getUTCHours()).padStart(2, "0");
|
|
90
|
+
const min = String(now.getUTCMinutes()).padStart(2, "0");
|
|
91
|
+
const s = String(now.getUTCSeconds()).padStart(2, "0");
|
|
92
|
+
const base = `${y}${m}${d}T${h}${min}${s}`;
|
|
93
|
+
const draw = randomSuffix ?? (() => crypto.randomBytes(2).toString("hex"));
|
|
94
|
+
|
|
95
|
+
for (let attempt = 0; attempt < MAX_UNIQUIFY_ATTEMPTS; attempt += 1) {
|
|
96
|
+
const id = `${base}-${draw()}`;
|
|
97
|
+
if (!projectRoot) return id;
|
|
98
|
+
if (!fs.existsSync(path.join(projectRoot, ".spine", "runtime", id))) return id;
|
|
99
|
+
}
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Unable to generate a unique batch ID after ${MAX_UNIQUIFY_ATTEMPTS} attempts`,
|
|
102
|
+
);
|
|
103
|
+
}
|