pi-spine 1.5.0 → 1.7.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-batch.mjs +3 -2
- package/bin/spine-wait.mjs +12 -0
- package/bin/spine.mjs +12 -0
- package/extensions/spine/slash-commands.ts +170 -1
- package/package.json +7 -4
- package/skills/spine-orchestrate-waves/SKILL.md +200 -0
- package/skills/spine-orchestrate-waves/references/outer-loop.md +165 -0
- package/skills/spine-release-operator/SKILL.md +371 -0
- package/skills/spine-release-operator/references/issue-intake-checklist.md +107 -0
- package/skills/spine-release-operator/references/issue-template.md +51 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +76 -0
- package/skills/spine-release-operator/references/release-profiles.md +100 -0
- package/src/batch/attached-runner.mjs +18 -7
- package/src/batch/batch-state-io.mjs +137 -0
- package/src/batch/contract-prelanded.mjs +116 -14
- package/src/batch/contract-task-start.mjs +12 -7
- package/src/batch/contract-verify.mjs +51 -3
- package/src/batch/detached-spawn.mjs +78 -0
- package/src/batch/detached-start.mjs +25 -71
- package/src/batch/diagnosis-alternatives.mjs +8 -0
- package/src/batch/diagnosis.mjs +53 -4
- package/src/batch/engine.mjs +10 -1
- package/src/batch/evidence.mjs +30 -250
- package/src/batch/gate-evidence-collect.mjs +172 -0
- package/src/batch/gate-evidence-read.mjs +145 -0
- package/src/batch/gate.mjs +28 -38
- package/src/batch/integrate-worktree.mjs +65 -15
- package/src/batch/lane-dirty-check.mjs +108 -1
- package/src/batch/lifecycle.mjs +16 -11
- package/src/batch/post-merge-limbo.mjs +1 -1
- package/src/batch/postmortem.mjs +1 -2
- package/src/batch/reconcile.mjs +255 -1
- package/src/batch/resume-common.mjs +7 -1
- package/src/batch/resume-multi-validate.mjs +25 -101
- package/src/batch/resume-validation.mjs +120 -0
- package/src/batch/sequence.mjs +11 -2
- package/src/batch/state.mjs +18 -1
- package/src/batch/supervisor-spawn.mjs +379 -0
- package/src/cli/batch-complete.mjs +16 -0
- package/src/cli/spine-wait.mjs +114 -0
- package/src/cli/sync-base.mjs +354 -0
- package/src/cli/wait.mjs +7 -43
- package/src/config/defaults.mjs +11 -1
- package/src/config/settings-fields.mjs +23 -0
- package/src/config/spine-config-load.mjs +6 -0
- package/src/config/spine-config-schema.mjs +121 -0
- package/src/config/spine-init-constants.mjs +19 -1
- package/src/config/spine-preflight-lib.mjs +146 -2
- package/src/config/worktree-setup-hook.mjs +221 -0
- package/src/doctor/agent-models.mjs +1 -0
- package/src/doctor/agents-model-inherit.mjs +318 -0
- package/src/doctor/run-doctor-checks.mjs +28 -0
- package/src/doctor/supervisor.mjs +66 -0
- package/src/doctor/worktree-health.mjs +1 -1
- package/templates/agents/supervisor.md +27 -18
- package/templates/spine-config.json +20 -1
- 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.
|
|
@@ -15,6 +15,13 @@ import { reconcileBatch } from "./reconcile.mjs";
|
|
|
15
15
|
import { readJournalEventsCached } from "./journal.mjs";
|
|
16
16
|
import { enforceOperatorPauseOnDisk } from "./pause.mjs";
|
|
17
17
|
import { loadSpineBatchState, readBatchEnginePid, saveSpineBatchState } from "./state.mjs";
|
|
18
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
19
|
+
import { resolveAttachedMilestonePollMs } from "../config/spine-config-schema.mjs";
|
|
20
|
+
|
|
21
|
+
export { DEFAULT_ATTACHED_MILESTONE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
22
|
+
|
|
23
|
+
/** @type {boolean} */
|
|
24
|
+
let attachedExitHandlersInstalled = false;
|
|
18
25
|
|
|
19
26
|
/** Journal types surfaced on attached stdout during the land loop. */
|
|
20
27
|
export const ATTACHED_LAND_LOOP_MILESTONE_TYPES = new Set([
|
|
@@ -33,11 +40,6 @@ export const ATTACHED_LAND_LOOP_MILESTONE_TYPES = new Set([
|
|
|
33
40
|
"batch.completed",
|
|
34
41
|
]);
|
|
35
42
|
|
|
36
|
-
const ATTACHED_MILESTONE_POLL_MS = 200;
|
|
37
|
-
|
|
38
|
-
/** @type {boolean} */
|
|
39
|
-
let attachedExitHandlersInstalled = false;
|
|
40
|
-
|
|
41
43
|
/**
|
|
42
44
|
* Install journal-aware SIGTERM/SIGINT handlers before attached engine exit (SP-378).
|
|
43
45
|
*
|
|
@@ -101,9 +103,18 @@ export function formatAttachedMilestoneLine(event) {
|
|
|
101
103
|
* @param {object} params
|
|
102
104
|
* @param {string} params.projectRoot
|
|
103
105
|
* @param {(line: string) => void} [params.write]
|
|
106
|
+
* @param {number} [params.pollIntervalMs]
|
|
104
107
|
* @returns {Promise<{ stop: () => Promise<void> }>}
|
|
105
108
|
*/
|
|
106
|
-
export async function startAttachedMilestoneReporter({
|
|
109
|
+
export async function startAttachedMilestoneReporter({
|
|
110
|
+
projectRoot,
|
|
111
|
+
write = (line) => process.stdout.write(line),
|
|
112
|
+
pollIntervalMs,
|
|
113
|
+
}) {
|
|
114
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
115
|
+
const resolvedPollMs =
|
|
116
|
+
pollIntervalMs ??
|
|
117
|
+
resolveAttachedMilestonePollMs({ config: configResult.config ?? {} });
|
|
107
118
|
/** @type {Set<string>} */
|
|
108
119
|
const printed = new Set();
|
|
109
120
|
let batchId = null;
|
|
@@ -126,7 +137,7 @@ export async function startAttachedMilestoneReporter({ projectRoot, write = (lin
|
|
|
126
137
|
write(formatAttachedMilestoneLine(event));
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
|
-
await sleep(
|
|
140
|
+
await sleep(resolvedPollMs);
|
|
130
141
|
}
|
|
131
142
|
};
|
|
132
143
|
|
|
@@ -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}
|
|
39
|
-
* @param {string}
|
|
40
|
-
* @param {string}
|
|
38
|
+
* @param {string} refA
|
|
39
|
+
* @param {string} refB
|
|
40
|
+
* @param {string} [pathspec]
|
|
41
41
|
*/
|
|
42
|
-
function
|
|
42
|
+
function listPathsChangedBetweenRefs(worktreePath, refA, refB, pathspec = "") {
|
|
43
43
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
@@ -98,9 +98,10 @@ function batchMatches(event, batchId) {
|
|
|
98
98
|
* @param {object[]} journal
|
|
99
99
|
* @param {string|null|undefined} laneId
|
|
100
100
|
* @param {number} beforeIndex
|
|
101
|
+
* @param {string|null|undefined} [excludeTaskId] Skip lane.committed for this task (SP-478 / issue #105).
|
|
101
102
|
* @returns {string|null}
|
|
102
103
|
*/
|
|
103
|
-
function resolvePriorLaneCommit(journal, laneId, beforeIndex) {
|
|
104
|
+
function resolvePriorLaneCommit(journal, laneId, beforeIndex, excludeTaskId) {
|
|
104
105
|
for (let index = beforeIndex - 1; index >= 0; index -= 1) {
|
|
105
106
|
const event = journal[index];
|
|
106
107
|
if (String(event?.type ?? "") !== "lane.committed") {
|
|
@@ -109,6 +110,9 @@ function resolvePriorLaneCommit(journal, laneId, beforeIndex) {
|
|
|
109
110
|
if (!lanesMatch(readEventLaneId(event), laneId)) {
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
113
|
+
if (excludeTaskId && readEventTaskId(event) === excludeTaskId) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
112
116
|
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
113
117
|
const sha = payload.commitSha ?? payload.mergeCommit;
|
|
114
118
|
if (typeof sha === "string" && sha.trim()) {
|
|
@@ -138,14 +142,15 @@ function resolveHeadAtTimestamp(worktreePath, timestampIso) {
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
/**
|
|
145
|
+
* First task.started for a task — stable baseline across retry/resume (SP-478 / issue #105).
|
|
146
|
+
*
|
|
141
147
|
* @param {object[]} journal
|
|
142
148
|
* @param {string} taskId
|
|
143
149
|
* @param {string|null|undefined} laneId
|
|
144
150
|
* @param {string|null|undefined} batchId
|
|
145
151
|
* @returns {{ event: object, index: number } | null}
|
|
146
152
|
*/
|
|
147
|
-
function
|
|
148
|
-
let match = null;
|
|
153
|
+
function findFirstTaskStarted(journal, taskId, laneId, batchId) {
|
|
149
154
|
for (let index = 0; index < journal.length; index += 1) {
|
|
150
155
|
const event = journal[index];
|
|
151
156
|
if (String(event?.type ?? "") !== "task.started") {
|
|
@@ -160,9 +165,9 @@ function findLastTaskStarted(journal, taskId, laneId, batchId) {
|
|
|
160
165
|
if (!batchMatches(event, batchId)) {
|
|
161
166
|
continue;
|
|
162
167
|
}
|
|
163
|
-
|
|
168
|
+
return { event, index };
|
|
164
169
|
}
|
|
165
|
-
return
|
|
170
|
+
return null;
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
/**
|
|
@@ -177,7 +182,7 @@ export function resolveTaskStartCommit({ journal, taskId, laneId, batchId, workt
|
|
|
177
182
|
return null;
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
const started =
|
|
185
|
+
const started = findFirstTaskStarted(journal, taskId, laneId, batchId);
|
|
181
186
|
if (!started) {
|
|
182
187
|
return null;
|
|
183
188
|
}
|
|
@@ -188,7 +193,7 @@ export function resolveTaskStartCommit({ journal, taskId, laneId, batchId, workt
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
const eventLaneId = readEventLaneId(started.event);
|
|
191
|
-
const priorLaneCommit = resolvePriorLaneCommit(journal, eventLaneId, started.index);
|
|
196
|
+
const priorLaneCommit = resolvePriorLaneCommit(journal, eventLaneId, started.index, taskId);
|
|
192
197
|
if (priorLaneCommit) {
|
|
193
198
|
return priorLaneCommit;
|
|
194
199
|
}
|