pi-spine 1.1.0 → 1.3.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/README.md +4 -4
- package/bin/spine-batch.mjs +160 -53
- package/bin/spine-cli/batch.mjs +3 -3
- package/bin/spine-cli/lane-logs.mjs +24 -0
- package/bin/spine-cli/scenarios.mjs +298 -0
- package/bin/spine-cli/verify.mjs +3 -0
- package/bin/spine-cli/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-plan.mjs +49 -1
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +16 -2
- package/bin/spine-worker-runner.mjs +144 -12
- package/bin/spine.mjs +49 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +7 -2
- package/skills/create-spine-tasks/references/contract-template.md +114 -3
- package/src/batch/abort.mjs +2 -11
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +388 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-stub-delivery.mjs +110 -0
- package/src/batch/contract-task-start.mjs +204 -0
- package/src/batch/contract-verify.mjs +195 -10
- package/src/batch/detached-start.mjs +137 -3
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-launch-failure.mjs +114 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-primary-failure.mjs +89 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -0
- package/src/batch/diagnosis-tail-state.mjs +57 -0
- package/src/batch/diagnosis-task-done.mjs +110 -0
- package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
- package/src/batch/diagnosis.mjs +140 -164
- package/src/batch/engine-lanes/commit.mjs +145 -0
- package/src/batch/engine-lanes/merge.mjs +110 -82
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +67 -87
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +21 -78
- package/src/batch/engine-scope.mjs +11 -1
- package/src/batch/engine.mjs +125 -24
- package/src/batch/evidence.mjs +78 -15
- package/src/batch/gate.mjs +43 -14
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +75 -9
- package/src/batch/integrate-assert.mjs +69 -0
- package/src/batch/integrate-worktree.mjs +354 -0
- package/src/batch/integrate.mjs +193 -102
- package/src/batch/journal-rebuild.mjs +48 -2
- package/src/batch/journal.mjs +66 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lane-dirty-check.mjs +437 -0
- package/src/batch/lifecycle.mjs +130 -3
- package/src/batch/limbo-detect.mjs +34 -0
- package/src/batch/macro-phase.mjs +302 -0
- package/src/batch/merge/adoption-doc-merge.mjs +93 -10
- package/src/batch/merge/wave-merge-state.mjs +3 -0
- package/src/batch/metrics.mjs +76 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +234 -0
- package/src/batch/post-merge-limbo.mjs +259 -28
- package/src/batch/reconcile.mjs +508 -63
- package/src/batch/resume-common.mjs +32 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +67 -1
- package/src/batch/resume-multi-validate.mjs +67 -6
- package/src/batch/resume-multi.mjs +11 -4
- package/src/batch/resume.mjs +59 -45
- package/src/batch/retry.mjs +97 -15
- package/src/batch/review-spawn.mjs +8 -2
- package/src/batch/rules-manifest-drift.mjs +198 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence-state.mjs +290 -0
- package/src/batch/sequence.mjs +516 -0
- package/src/batch/state.mjs +34 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +22 -10
- package/src/batch/worker-host.mjs +96 -7
- package/src/batch/worker-output.mjs +196 -3
- package/src/cli/issue-draft.mjs +180 -0
- package/src/cli/journal-follow.mjs +239 -0
- package/src/cli/lane-logs.mjs +291 -0
- package/src/cli/sequence.mjs +121 -0
- package/src/cli/settings-set.mjs +35 -24
- package/src/cli/wait.mjs +187 -0
- package/src/cli/watch.mjs +160 -0
- package/src/config/agent-model-resolve.mjs +48 -0
- package/src/config/cursor-rules/discover.mjs +3 -21
- package/src/config/defaults.mjs +7 -1
- package/src/config/model-id.mjs +103 -0
- package/src/config/settings-fields.mjs +48 -0
- package/src/config/spine-init-constants.mjs +2 -0
- package/src/config/spine-preflight-lib.mjs +494 -17
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +234 -18
- package/src/dashboard/public/index.html +14 -2
- package/src/dashboard/running-tail-state.mjs +31 -0
- package/src/dashboard/server.mjs +8 -0
- package/src/dashboard/snapshot.mjs +472 -26
- package/src/dashboard/view.mjs +282 -19
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/agent-models.mjs +53 -0
- package/src/doctor/batch-size-guidance.mjs +30 -2
- package/src/doctor/pi-extension-conflict.mjs +169 -0
- package/src/doctor/run-doctor-checks.mjs +32 -1
- package/src/doctor/sequence-safety.mjs +57 -0
- package/src/doctor/stale-worktrees.mjs +102 -0
- package/src/fixtures/scenario-registry.mjs +194 -0
- package/src/fs/atomic-write.mjs +49 -0
- package/src/planner/file-scope.mjs +246 -0
- package/src/planner/format-plan.mjs +9 -7
- package/src/planner/index.mjs +6 -2
- package/src/planner/scope.mjs +5 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +73 -2
- package/src/tasks/packet/validate-contract.mjs +108 -0
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/templates/spine-config.json +8 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alternative operator commands per diagnosis (extracted for module size budget).
|
|
3
|
+
*/
|
|
4
|
+
import { buildWorkerDoneMissingAlternatives } from "./diagnosis-worker-done-missing.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} diagnosis
|
|
8
|
+
* @param {object} [ctx]
|
|
9
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
10
|
+
*/
|
|
11
|
+
export function buildAlternatives(diagnosis, ctx = {}) {
|
|
12
|
+
const common = ["spine status --diagnose"];
|
|
13
|
+
|
|
14
|
+
switch (diagnosis) {
|
|
15
|
+
case "limbo_stale":
|
|
16
|
+
return ["spine batch complete --detect-manual-merge", ...common];
|
|
17
|
+
case "completed_manual":
|
|
18
|
+
return ["spine batch complete --detect-manual-merge", "spine batch dismiss", ...common];
|
|
19
|
+
case "needs_retry":
|
|
20
|
+
return ["spine batch abort", "/spine-skip-task", "/spine-resume --force", ...common];
|
|
21
|
+
case "worker_orphaned":
|
|
22
|
+
return ["spine batch abort", "spine batch resume --force", ...common];
|
|
23
|
+
case "worker_done_missing":
|
|
24
|
+
return buildWorkerDoneMissingAlternatives(ctx, common);
|
|
25
|
+
case "engine_orphaned":
|
|
26
|
+
return ctx.failedTaskId
|
|
27
|
+
? [`spine batch retry ${ctx.failedTaskId}`, "spine batch abort", ...common]
|
|
28
|
+
: ["spine batch abort", "spine batch resume --force", ...common];
|
|
29
|
+
case "needs_merge":
|
|
30
|
+
return ["/spine-status --diagnose", ...common];
|
|
31
|
+
case "needs_integrate":
|
|
32
|
+
return ["/spine-integrate", "/spine-gate", ...common];
|
|
33
|
+
case "needs_replan":
|
|
34
|
+
return ctx.failedTaskId
|
|
35
|
+
? [`spine batch skip ${ctx.failedTaskId}`, "spine handoff", ...common]
|
|
36
|
+
: ["spine handoff", ...common];
|
|
37
|
+
case "running":
|
|
38
|
+
return ["/spine-pause", "/spine-abort", ...common];
|
|
39
|
+
case "paused":
|
|
40
|
+
return ["spine batch resume --force", "spine status --diagnose", ...common];
|
|
41
|
+
case "failed":
|
|
42
|
+
return ["/spine-retry-task", ...common];
|
|
43
|
+
default:
|
|
44
|
+
return common;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker launch failure inference for diagnosis headlines (SP-105, SP-421).
|
|
3
|
+
*/
|
|
4
|
+
import { isPrimaryTaskFailureExitReason } from "./diagnosis-primary-failure.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} haystack
|
|
8
|
+
* @param {object} [hints]
|
|
9
|
+
* @param {boolean} [hints.launchingPhase]
|
|
10
|
+
* @returns {string|null}
|
|
11
|
+
*/
|
|
12
|
+
function classifyLaunchFailureHaystack(haystack, hints = {}) {
|
|
13
|
+
const normalized = haystack.toLowerCase();
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
normalized.includes("dirtyworktree") ||
|
|
17
|
+
normalized.includes("gitignoreddirtyworktree") ||
|
|
18
|
+
normalized.includes("lane_commit_failed")
|
|
19
|
+
) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (hints.launchingPhase) {
|
|
24
|
+
if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
|
|
25
|
+
return "pi_spine_root";
|
|
26
|
+
}
|
|
27
|
+
return "launch_failed";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
|
|
31
|
+
return "pi_spine_root";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
normalized.includes("not a git repository") ||
|
|
36
|
+
normalized.includes("worktree") ||
|
|
37
|
+
normalized.includes("worktreeunhealthy")
|
|
38
|
+
) {
|
|
39
|
+
return "worktree_unhealthy";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {object|null} failedEvent
|
|
47
|
+
* @param {string|null} exitReason
|
|
48
|
+
* @returns {string|null}
|
|
49
|
+
*/
|
|
50
|
+
function classifyLaunchFailureFromEvent(failedEvent, exitReason) {
|
|
51
|
+
const payload = failedEvent?.payload && typeof failedEvent.payload === "object" ? failedEvent.payload : {};
|
|
52
|
+
const haystack = [
|
|
53
|
+
exitReason,
|
|
54
|
+
payload.classification,
|
|
55
|
+
payload.output,
|
|
56
|
+
payload.exitReason,
|
|
57
|
+
].filter(Boolean).join("\n");
|
|
58
|
+
|
|
59
|
+
return classifyLaunchFailureHaystack(haystack, {
|
|
60
|
+
launchingPhase:
|
|
61
|
+
payload.workerPhase === "launching" || payload.classification === "launch_failed",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {string|null|undefined} outputText
|
|
67
|
+
* @returns {string|null}
|
|
68
|
+
*/
|
|
69
|
+
export function inferLaunchFailureFromWorkerOutputTail(outputText) {
|
|
70
|
+
if (!outputText || !String(outputText).trim()) return null;
|
|
71
|
+
return classifyLaunchFailureHaystack(String(outputText));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {object} ctx
|
|
76
|
+
* @param {string|null} [ctx.exitReason]
|
|
77
|
+
* @param {object[]} [ctx.journalEvents]
|
|
78
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
79
|
+
* @returns {string|null}
|
|
80
|
+
*/
|
|
81
|
+
export function inferLaunchFailureKind(ctx = {}) {
|
|
82
|
+
const { exitReason, journalEvents, failedTaskId } = ctx;
|
|
83
|
+
if (isPrimaryTaskFailureExitReason(exitReason)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (exitReason === "launch_failed" || exitReason === "worker_launch_failed") {
|
|
87
|
+
return "launch_failed";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const kinds = [];
|
|
91
|
+
if (Array.isArray(journalEvents)) {
|
|
92
|
+
const taskFailedEvents = journalEvents.filter((event) => event.type === "task.failed");
|
|
93
|
+
const prioritized = failedTaskId
|
|
94
|
+
? [
|
|
95
|
+
...taskFailedEvents.filter(
|
|
96
|
+
(event) => (event.taskId ?? event.payload?.taskId) === failedTaskId,
|
|
97
|
+
),
|
|
98
|
+
...taskFailedEvents.filter(
|
|
99
|
+
(event) => (event.taskId ?? event.payload?.taskId) !== failedTaskId,
|
|
100
|
+
),
|
|
101
|
+
]
|
|
102
|
+
: taskFailedEvents;
|
|
103
|
+
|
|
104
|
+
for (const failedEvent of prioritized) {
|
|
105
|
+
const kind = classifyLaunchFailureFromEvent(failedEvent, exitReason);
|
|
106
|
+
if (kind) kinds.push(kind);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (kinds.includes("pi_spine_root")) return "pi_spine_root";
|
|
111
|
+
if (kinds.includes("launch_failed")) return "launch_failed";
|
|
112
|
+
if (kinds.includes("worktree_unhealthy")) return "worktree_unhealthy";
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wave merge failure diagnosis helpers (SP-338 / GitHub #29).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {unknown[]} mergeResults
|
|
7
|
+
* @param {string|null|undefined} lastError
|
|
8
|
+
* @returns {{
|
|
9
|
+
* mergeFailed: boolean,
|
|
10
|
+
* failedMerges: number,
|
|
11
|
+
* failedWaveIndex: number | null,
|
|
12
|
+
* failedLane: number | null,
|
|
13
|
+
* lastError: string | null,
|
|
14
|
+
* }}
|
|
15
|
+
*/
|
|
16
|
+
export function summarizeMergeFailures(mergeResults, lastError = null) {
|
|
17
|
+
const results = Array.isArray(mergeResults) ? mergeResults : [];
|
|
18
|
+
const failedEntries = results.filter(
|
|
19
|
+
(entry) => String(entry?.status ?? "").toLowerCase() === "failed",
|
|
20
|
+
);
|
|
21
|
+
if (failedEntries.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
mergeFailed: false,
|
|
24
|
+
failedMerges: 0,
|
|
25
|
+
failedWaveIndex: null,
|
|
26
|
+
failedLane: null,
|
|
27
|
+
lastError: lastError ? String(lastError) : null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const latestFailed = failedEntries.reduce((latest, entry) => {
|
|
32
|
+
const waveIndex = Number(entry?.waveIndex);
|
|
33
|
+
if (!Number.isFinite(waveIndex)) return latest;
|
|
34
|
+
if (!latest) return entry;
|
|
35
|
+
return Number(latest.waveIndex) > waveIndex ? latest : entry;
|
|
36
|
+
}, null);
|
|
37
|
+
|
|
38
|
+
const failedWaveIndex = Number(latestFailed?.waveIndex);
|
|
39
|
+
const failedLaneRaw = latestFailed?.failedLane;
|
|
40
|
+
const failedLane =
|
|
41
|
+
failedLaneRaw == null || failedLaneRaw === ""
|
|
42
|
+
? null
|
|
43
|
+
: Number(failedLaneRaw);
|
|
44
|
+
const resolvedLastError =
|
|
45
|
+
lastError ??
|
|
46
|
+
latestFailed?.failureReason ??
|
|
47
|
+
latestFailed?.error ??
|
|
48
|
+
null;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
mergeFailed: true,
|
|
52
|
+
failedMerges: failedEntries.length,
|
|
53
|
+
failedWaveIndex: Number.isFinite(failedWaveIndex) ? failedWaveIndex : null,
|
|
54
|
+
failedLane: Number.isFinite(failedLane) ? failedLane : null,
|
|
55
|
+
lastError: resolvedLastError ? String(resolvedLastError) : null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} batchLabel
|
|
61
|
+
* @param {object} ctx
|
|
62
|
+
* @param {number|null} [ctx.failedWaveIndex]
|
|
63
|
+
* @param {number|null} [ctx.failedLane]
|
|
64
|
+
* @param {string|null} [ctx.lastError]
|
|
65
|
+
* @param {number} [ctx.succeededTasks]
|
|
66
|
+
* @param {number} [ctx.totalTasks]
|
|
67
|
+
*/
|
|
68
|
+
export function buildMergeFailureHeadline(batchLabel, ctx = {}) {
|
|
69
|
+
const waveNumber =
|
|
70
|
+
ctx.failedWaveIndex == null ? "?" : String(Number(ctx.failedWaveIndex) + 1);
|
|
71
|
+
const laneLabel =
|
|
72
|
+
ctx.failedLane == null ? "unknown lane" : `lane-${ctx.failedLane}`;
|
|
73
|
+
const progress =
|
|
74
|
+
ctx.totalTasks != null && ctx.succeededTasks != null
|
|
75
|
+
? ` (${ctx.succeededTasks}/${ctx.totalTasks} tasks succeeded)`
|
|
76
|
+
: "";
|
|
77
|
+
const errorSuffix = ctx.lastError ? `: ${ctx.lastError}` : "";
|
|
78
|
+
return `${batchLabel} failed: wave ${waveNumber} merge conflict on ${laneLabel}${progress}${errorSuffix}`;
|
|
79
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primary task failure headlines and commands (SP-421 / GitHub #74).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const PRIMARY_TASK_FAILURE_EXIT_REASONS = new Set([
|
|
6
|
+
"DirtyWorktree",
|
|
7
|
+
"GitignoredDirtyWorktree",
|
|
8
|
+
"lane_commit_failed",
|
|
9
|
+
"review_exhausted",
|
|
10
|
+
"contract_failed",
|
|
11
|
+
"needs_replan",
|
|
12
|
+
"prompt_parse_failed",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string|null|undefined} exitReason
|
|
19
|
+
*/
|
|
20
|
+
export function isPrimaryTaskFailureExitReason(exitReason) {
|
|
21
|
+
return PRIMARY_TASK_FAILURE_EXIT_REASONS.has(exitReason ?? "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} batchLabel
|
|
26
|
+
* @param {object} ctx
|
|
27
|
+
* @param {string|null} [ctx.exitReason]
|
|
28
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
29
|
+
* @param {boolean} [ctx.mergeGitignoredFailure]
|
|
30
|
+
*/
|
|
31
|
+
export function buildPrimaryFailureHeadline(batchLabel, ctx = {}) {
|
|
32
|
+
if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
33
|
+
if (ctx.exitReason === "GitignoredDirtyWorktree" || ctx.mergeGitignoredFailure) {
|
|
34
|
+
return ctx.failedTaskId
|
|
35
|
+
? `${batchLabel} task ${ctx.failedTaskId} left gitignored dirty files on the lane branch`
|
|
36
|
+
: `${batchLabel} lane commit refused gitignored-only dirty files`;
|
|
37
|
+
}
|
|
38
|
+
if (ctx.exitReason === "DirtyWorktree") {
|
|
39
|
+
return ctx.failedTaskId
|
|
40
|
+
? `${batchLabel} task ${ctx.failedTaskId} left dirty lane worktree after completion — clean coverage artifacts, then retry`
|
|
41
|
+
: `${batchLabel} lane worktree dirty after completion — clean coverage artifacts, then retry`;
|
|
42
|
+
}
|
|
43
|
+
return ctx.failedTaskId
|
|
44
|
+
? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
|
|
45
|
+
: `${batchLabel} completed but lane commit failed`;
|
|
46
|
+
}
|
|
47
|
+
if (ctx.exitReason === "review_exhausted") {
|
|
48
|
+
return ctx.failedTaskId
|
|
49
|
+
? `${batchLabel} task ${ctx.failedTaskId} exhausted final review attempts — fix scope or implementation, then retry`
|
|
50
|
+
: `${batchLabel} review attempts exhausted — fix scope or implementation, then retry`;
|
|
51
|
+
}
|
|
52
|
+
if (ctx.exitReason === "contract_failed") {
|
|
53
|
+
return ctx.failedTaskId
|
|
54
|
+
? `${batchLabel} task ${ctx.failedTaskId} failed contract verification — fix PROMPT.md scope, then retry`
|
|
55
|
+
: `${batchLabel} contract verification failed — fix PROMPT.md scope, then retry`;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {object} ctx
|
|
62
|
+
* @param {string|null} [ctx.exitReason]
|
|
63
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
64
|
+
* @param {string} [ctx.tasksRoot]
|
|
65
|
+
*/
|
|
66
|
+
export function buildPrimaryFailureSuggestedCommand(ctx = {}) {
|
|
67
|
+
if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
68
|
+
if (ctx.exitReason === "DirtyWorktree") {
|
|
69
|
+
return ctx.failedTaskId
|
|
70
|
+
? `git checkout -- extension/coverage && spine batch retry ${ctx.failedTaskId}`
|
|
71
|
+
: "git checkout -- extension/coverage && spine batch retry";
|
|
72
|
+
}
|
|
73
|
+
return ctx.failedTaskId
|
|
74
|
+
? `spine batch retry ${ctx.failedTaskId}`
|
|
75
|
+
: "spine status --diagnose";
|
|
76
|
+
}
|
|
77
|
+
if (ctx.exitReason === "review_exhausted") {
|
|
78
|
+
return ctx.failedTaskId
|
|
79
|
+
? `spine batch retry ${ctx.failedTaskId}`
|
|
80
|
+
: "spine status --diagnose";
|
|
81
|
+
}
|
|
82
|
+
if (ctx.exitReason === "contract_failed") {
|
|
83
|
+
const tasksRoot = ctx.tasksRoot ?? "spine-tasks";
|
|
84
|
+
return ctx.failedTaskId
|
|
85
|
+
? `edit ${tasksRoot}/${ctx.failedTaskId}/PROMPT.md then spine batch retry ${ctx.failedTaskId}`
|
|
86
|
+
: "spine status --diagnose";
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failed-phase limbo after retry clears failed tasks but phase stays failed (GitHub #25).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {object} ctx
|
|
7
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
8
|
+
* @param {number} [ctx.failedTasks]
|
|
9
|
+
* @param {number} [ctx.pendingTaskCount]
|
|
10
|
+
* @param {string|null} [ctx.phase]
|
|
11
|
+
*/
|
|
12
|
+
export function isFailedPhasePendingOnlyLimbo(ctx = {}) {
|
|
13
|
+
return (
|
|
14
|
+
String(ctx.phase ?? "") === "failed" &&
|
|
15
|
+
(ctx.failedTasks ?? 0) === 0 &&
|
|
16
|
+
(ctx.pendingTaskCount ?? 0) > 0 &&
|
|
17
|
+
!ctx.failedTaskId
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} batchLabel
|
|
23
|
+
* @param {object} ctx
|
|
24
|
+
*/
|
|
25
|
+
export function buildFailedPhasePendingOnlyHeadline(batchLabel, ctx = {}) {
|
|
26
|
+
return `${batchLabel} failed with pending task(s) and no failed tasks — resume to continue`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {object} ctx
|
|
31
|
+
*/
|
|
32
|
+
export function buildFailedPhasePendingOnlySuggestedCommand(_ctx = {}) {
|
|
33
|
+
return "spine batch resume --force";
|
|
34
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub worker completion diagnosis helpers (SP-349 / GitHub #33, #40).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { isLegacyStubDoneMarker } from "./contract-verify.mjs";
|
|
8
|
+
import { parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
9
|
+
|
|
10
|
+
export const STUB_EXIT_REASONS = new Set(["stub"]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Surface `exitReason: stub` when legacy `.DONE` contains `Task: stub` on M/L implementation tasks.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} promptMarkdown
|
|
16
|
+
* @param {string} doneContent
|
|
17
|
+
* @returns {string|null}
|
|
18
|
+
*/
|
|
19
|
+
export function inferStubExitReasonFromDoneMarker(promptMarkdown, doneContent) {
|
|
20
|
+
if (!isLegacyStubDoneMarker(doneContent)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const parsed = parsePrompt(promptMarkdown);
|
|
24
|
+
if (parsed.size !== "M" && parsed.size !== "L") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return "stub";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} tasksRoot
|
|
32
|
+
* @param {string} taskId
|
|
33
|
+
* @param {string|null} [taskFolder]
|
|
34
|
+
* @returns {string|null}
|
|
35
|
+
*/
|
|
36
|
+
function resolveTaskFolder(tasksRoot, taskId, taskFolder = null) {
|
|
37
|
+
if (taskFolder) {
|
|
38
|
+
const direct = path.join(tasksRoot, taskFolder);
|
|
39
|
+
if (fs.existsSync(direct)) return direct;
|
|
40
|
+
}
|
|
41
|
+
if (!tasksRoot || !fs.existsSync(tasksRoot)) return null;
|
|
42
|
+
const match = fs
|
|
43
|
+
.readdirSync(tasksRoot, { withFileTypes: true })
|
|
44
|
+
.filter((entry) => entry.isDirectory() && entry.name.startsWith(`${taskId}-`))
|
|
45
|
+
.map((entry) => path.join(tasksRoot, entry.name))[0];
|
|
46
|
+
return match ?? null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Read on-disk PROMPT/.DONE for a task and infer stub exitReason when applicable.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} tasksRoot
|
|
53
|
+
* @param {string} taskId
|
|
54
|
+
* @param {string|null} [taskFolder]
|
|
55
|
+
* @returns {string|null}
|
|
56
|
+
*/
|
|
57
|
+
export function inferStubExitReasonForTask(tasksRoot, taskId, taskFolder = null) {
|
|
58
|
+
const folderPath = resolveTaskFolder(tasksRoot, taskId, taskFolder);
|
|
59
|
+
if (!folderPath) return null;
|
|
60
|
+
const donePath = path.join(folderPath, ".DONE");
|
|
61
|
+
const promptPath = path.join(folderPath, "PROMPT.md");
|
|
62
|
+
if (!fs.existsSync(donePath) || !fs.existsSync(promptPath)) return null;
|
|
63
|
+
return inferStubExitReasonFromDoneMarker(
|
|
64
|
+
fs.readFileSync(promptPath, "utf-8"),
|
|
65
|
+
fs.readFileSync(donePath, "utf-8"),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Find a succeeded task whose legacy `.DONE` marks stub completion on M/L work.
|
|
71
|
+
*
|
|
72
|
+
* @param {string|null} tasksRoot
|
|
73
|
+
* @param {Array<{ taskId: string, classification?: string, taskFolder?: string|null }>} tasks
|
|
74
|
+
* @returns {string|null}
|
|
75
|
+
*/
|
|
76
|
+
export function findStubMarkedSucceededTask(tasksRoot, tasks) {
|
|
77
|
+
if (!tasksRoot || !Array.isArray(tasks)) return null;
|
|
78
|
+
for (const task of tasks) {
|
|
79
|
+
if (task.classification !== "terminal-success") continue;
|
|
80
|
+
const stubReason = inferStubExitReasonForTask(
|
|
81
|
+
tasksRoot,
|
|
82
|
+
task.taskId,
|
|
83
|
+
task.taskFolder ?? null,
|
|
84
|
+
);
|
|
85
|
+
if (stubReason) return task.taskId;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} batchLabel
|
|
92
|
+
* @param {object} ctx
|
|
93
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
94
|
+
*/
|
|
95
|
+
export function buildStubFailureHeadline(batchLabel, ctx = {}) {
|
|
96
|
+
return ctx.failedTaskId
|
|
97
|
+
? `${batchLabel} task ${ctx.failedTaskId} stub-completed without file-scope changes`
|
|
98
|
+
: `${batchLabel} stub worker completed without file-scope changes`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {object} ctx
|
|
103
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
104
|
+
*/
|
|
105
|
+
export function buildStubFailureSuggestedCommand(ctx = {}) {
|
|
106
|
+
return ctx.failedTaskId
|
|
107
|
+
? `unset SPINE_WORKER_STUB && spine batch retry ${ctx.failedTaskId}`
|
|
108
|
+
: "unset SPINE_WORKER_STUB && spine batch resume";
|
|
109
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Running diagnosis headlines when batch phase is active but no workers are scheduled (GitHub #68).
|
|
3
|
+
*/
|
|
4
|
+
import { isRunningWithoutActiveWorkers } from "../dashboard/running-tail-state.mjs";
|
|
5
|
+
import { macroPhaseLabel } from "./macro-phase.mjs";
|
|
6
|
+
|
|
7
|
+
export { isRunningWithoutActiveWorkers };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} batchLabel
|
|
11
|
+
* @param {object} ctx
|
|
12
|
+
* @returns {string|null}
|
|
13
|
+
*/
|
|
14
|
+
export function buildRunningTailHeadline(batchLabel, ctx = {}) {
|
|
15
|
+
if (!isRunningWithoutActiveWorkers(ctx)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const macroPhase = ctx.macroPhase ?? null;
|
|
20
|
+
|
|
21
|
+
if (ctx.postMergeLimbo || macroPhase === "gating") {
|
|
22
|
+
if (ctx.integrateGateOpen) {
|
|
23
|
+
return `${batchLabel} gate opened — approve to continue land loop`;
|
|
24
|
+
}
|
|
25
|
+
if (ctx.stalePathSpine) {
|
|
26
|
+
return `${batchLabel} merged but gate not opened — use node bin/spine.mjs batch resume --attached (PATH spine may be stale)`;
|
|
27
|
+
}
|
|
28
|
+
return `${batchLabel} finalizing land loop — opening integrate gate…`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (macroPhase === "integrating") {
|
|
32
|
+
return `${batchLabel} integrating orch branch to main…`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (macroPhase === "merging" || ctx.phase === "merging") {
|
|
36
|
+
return `${batchLabel} tasks done — merging lane branches…`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (macroPhase === "reviewing") {
|
|
40
|
+
return `${batchLabel} running reviews — no workers scheduled`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (macroPhase === "planning") {
|
|
44
|
+
return `${batchLabel} planning — no workers scheduled`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (macroPhase != null && macroPhase !== "executing") {
|
|
48
|
+
const label = macroPhaseLabel(macroPhase);
|
|
49
|
+
return `${batchLabel} ${label.toLowerCase()} — finalizing batch`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (ctx.gitMerged === false || ctx.allTasksTerminalSuccess === true) {
|
|
53
|
+
return `${batchLabel} tasks done — merging lane branches…`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return `${batchLabel} finalizing batch — no active workers`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-task done-marker semantics for reconcile / status JSON (SP-344 / GitHub #35).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { laneWorktreePath } from "./worktree.mjs";
|
|
8
|
+
|
|
9
|
+
/** Documented task done-flag field names for status JSON. */
|
|
10
|
+
export const TASK_DONE_FLAG_FIELD_NAMES = ["doneFileFound", "doneOnMain", "doneInLane"];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} tasksRoot
|
|
14
|
+
* @param {string} taskId
|
|
15
|
+
* @param {string|null|undefined} taskFolder
|
|
16
|
+
* @returns {string|null}
|
|
17
|
+
*/
|
|
18
|
+
export function resolveTaskFolderPath(tasksRoot, taskId, taskFolder) {
|
|
19
|
+
if (taskFolder) {
|
|
20
|
+
const direct = path.join(tasksRoot, taskFolder);
|
|
21
|
+
if (fs.existsSync(direct)) return direct;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!tasksRoot || !fs.existsSync(tasksRoot)) return null;
|
|
25
|
+
|
|
26
|
+
const match = fs
|
|
27
|
+
.readdirSync(tasksRoot, { withFileTypes: true })
|
|
28
|
+
.filter((entry) => entry.isDirectory() && entry.name.startsWith(`${taskId}-`))
|
|
29
|
+
.map((entry) => path.join(tasksRoot, entry.name))[0];
|
|
30
|
+
|
|
31
|
+
return match ?? null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} projectRoot
|
|
36
|
+
* @param {string} batchId
|
|
37
|
+
* @param {unknown[]} lanes
|
|
38
|
+
* @param {object} task
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function resolveTaskLaneWorktreePath(projectRoot, batchId, lanes, task) {
|
|
42
|
+
const laneNumber = Number(task.laneNumber ?? 1);
|
|
43
|
+
const lane = Array.isArray(lanes)
|
|
44
|
+
? lanes.find((entry) => Number(entry.laneNumber) === laneNumber)
|
|
45
|
+
: null;
|
|
46
|
+
if (lane && typeof lane.worktreePath === "string" && lane.worktreePath) {
|
|
47
|
+
return path.isAbsolute(lane.worktreePath)
|
|
48
|
+
? lane.worktreePath
|
|
49
|
+
: path.join(projectRoot, lane.worktreePath);
|
|
50
|
+
}
|
|
51
|
+
return laneWorktreePath(projectRoot, batchId, laneNumber);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string|null} folderPath
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
function doneMarkerExists(folderPath) {
|
|
59
|
+
return Boolean(folderPath && fs.existsSync(path.join(folderPath, ".DONE")));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Classify per-task done semantics for reconcile / status JSON.
|
|
64
|
+
*
|
|
65
|
+
* - `doneFileFound`: batch-state / journal records worker completion.
|
|
66
|
+
* - `doneOnMain`: `.DONE` exists under the integration checkout tasks root.
|
|
67
|
+
* - `doneInLane`: `.DONE` exists in the lane worktree copy (pre-merge).
|
|
68
|
+
*
|
|
69
|
+
* @param {object} task
|
|
70
|
+
* @param {object} ctx
|
|
71
|
+
* @param {string|null} [ctx.tasksRoot]
|
|
72
|
+
* @param {string} [ctx.projectRoot]
|
|
73
|
+
* @param {string} [ctx.batchId]
|
|
74
|
+
* @param {unknown[]} [ctx.lanes]
|
|
75
|
+
*/
|
|
76
|
+
export function classifyTaskDoneSemantics(task, ctx = {}) {
|
|
77
|
+
const { tasksRoot, projectRoot, batchId, lanes = [] } = ctx;
|
|
78
|
+
const mainFolderPath =
|
|
79
|
+
tasksRoot && task.taskId
|
|
80
|
+
? resolveTaskFolderPath(tasksRoot, task.taskId, task.taskFolder ?? null)
|
|
81
|
+
: null;
|
|
82
|
+
const doneOnMain = doneMarkerExists(mainFolderPath);
|
|
83
|
+
const doneFileFound = Boolean(task.doneFileFound);
|
|
84
|
+
|
|
85
|
+
let doneInLane = false;
|
|
86
|
+
if (projectRoot && batchId && tasksRoot && task.taskId) {
|
|
87
|
+
const laneWorktree = resolveTaskLaneWorktreePath(projectRoot, batchId, lanes, task);
|
|
88
|
+
const tasksRootRel = path.relative(projectRoot, tasksRoot);
|
|
89
|
+
const laneTasksRoot = path.join(laneWorktree, tasksRootRel);
|
|
90
|
+
const laneFolderPath = resolveTaskFolderPath(
|
|
91
|
+
laneTasksRoot,
|
|
92
|
+
task.taskId,
|
|
93
|
+
task.taskFolder ?? null,
|
|
94
|
+
);
|
|
95
|
+
doneInLane = doneMarkerExists(laneFolderPath);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let classification = task.classification;
|
|
99
|
+
if (doneOnMain || doneInLane || doneFileFound) {
|
|
100
|
+
classification = "terminal-success";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...task,
|
|
105
|
+
doneFileFound,
|
|
106
|
+
doneOnMain,
|
|
107
|
+
doneInLane,
|
|
108
|
+
classification,
|
|
109
|
+
};
|
|
110
|
+
}
|