pi-spine 1.0.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/LICENSE +21 -0
- package/README.md +563 -0
- package/bin/get-version.mjs +35 -0
- package/bin/spine-batch.mjs +425 -0
- package/bin/spine-cli/batch.mjs +47 -0
- package/bin/spine-cli/gate.mjs +10 -0
- package/bin/spine-cli/integrate.mjs +10 -0
- package/bin/spine-cli/plan.mjs +12 -0
- package/bin/spine-cli/shared.mjs +73 -0
- package/bin/spine-cli/status.mjs +18 -0
- package/bin/spine-cli/verify.mjs +199 -0
- package/bin/spine-config.mjs +212 -0
- package/bin/spine-dashboard.mjs +178 -0
- package/bin/spine-deps.mjs +69 -0
- package/bin/spine-doctor.mjs +468 -0
- package/bin/spine-gate.mjs +137 -0
- package/bin/spine-init.mjs +398 -0
- package/bin/spine-integrate.mjs +77 -0
- package/bin/spine-journal.mjs +198 -0
- package/bin/spine-migrate-from-taskplane.mjs +136 -0
- package/bin/spine-plan.mjs +83 -0
- package/bin/spine-preflight.mjs +700 -0
- package/bin/spine-report-progress.d.mts +28 -0
- package/bin/spine-report-progress.mjs +126 -0
- package/bin/spine-review-step.d.mts +24 -0
- package/bin/spine-review-step.mjs +124 -0
- package/bin/spine-rules.mjs +35 -0
- package/bin/spine-settings.mjs +186 -0
- package/bin/spine-state.mjs +110 -0
- package/bin/spine-status.mjs +79 -0
- package/bin/spine-tasks.mjs +293 -0
- package/bin/spine-worker-runner.mjs +314 -0
- package/bin/spine.mjs +404 -0
- package/extensions/spine/settings-slash.ts +20 -0
- package/extensions/spine/slash-commands.ts +806 -0
- package/extensions/spine/worker-tools.ts +279 -0
- package/extensions/spine-orchestrator.ts +12 -0
- package/package.json +72 -0
- package/skills/.gitkeep +0 -0
- package/skills/create-spine-tasks/SKILL.md +375 -0
- package/skills/create-spine-tasks/references/context-template.md +25 -0
- package/skills/create-spine-tasks/references/contract-template.md +98 -0
- package/skills/create-spine-tasks/references/explore-template.md +63 -0
- package/skills/create-spine-tasks/references/prompt-template.md +276 -0
- package/src/batch/abort.mjs +272 -0
- package/src/batch/agent-session-worker.mjs +297 -0
- package/src/batch/batch-state-io.mjs +53 -0
- package/src/batch/contract-verify.mjs +310 -0
- package/src/batch/detached-start.mjs +778 -0
- package/src/batch/diagnosis.mjs +378 -0
- package/src/batch/engine-lanes/merge.mjs +632 -0
- package/src/batch/engine-lanes/queue.mjs +208 -0
- package/src/batch/engine-lanes/review.mjs +970 -0
- package/src/batch/engine-lanes.mjs +388 -0
- package/src/batch/engine-scope.mjs +251 -0
- package/src/batch/engine.mjs +445 -0
- package/src/batch/evidence-command.mjs +157 -0
- package/src/batch/evidence.mjs +203 -0
- package/src/batch/gate.mjs +359 -0
- package/src/batch/git-commit-env.mjs +46 -0
- package/src/batch/git-exec.mjs +26 -0
- package/src/batch/heartbeat.mjs +430 -0
- package/src/batch/integrate.mjs +414 -0
- package/src/batch/journal-rebuild.mjs +388 -0
- package/src/batch/journal.mjs +373 -0
- package/src/batch/lane-commit.mjs +153 -0
- package/src/batch/lifecycle.mjs +364 -0
- package/src/batch/metrics.mjs +265 -0
- package/src/batch/orphan-detect.mjs +210 -0
- package/src/batch/post-merge-limbo.mjs +80 -0
- package/src/batch/postmortem.mjs +296 -0
- package/src/batch/readers/spine-state.mjs +95 -0
- package/src/batch/readers/taskplane-state.mjs +136 -0
- package/src/batch/reconcile.mjs +729 -0
- package/src/batch/resume-common.mjs +104 -0
- package/src/batch/resume-engine.mjs +66 -0
- package/src/batch/resume-multi-lanes.mjs +479 -0
- package/src/batch/resume-multi-validate.mjs +187 -0
- package/src/batch/resume-multi.mjs +254 -0
- package/src/batch/resume.mjs +475 -0
- package/src/batch/retry.mjs +257 -0
- package/src/batch/review-scope.mjs +136 -0
- package/src/batch/review.mjs +1045 -0
- package/src/batch/salvage.mjs +332 -0
- package/src/batch/state.mjs +680 -0
- package/src/batch/task-stall-budget.mjs +88 -0
- package/src/batch/worker-host.mjs +683 -0
- package/src/batch/worker-output.mjs +253 -0
- package/src/batch/worker-prompt.mjs +84 -0
- package/src/batch/worktree.mjs +290 -0
- package/src/cli/deps.mjs +141 -0
- package/src/cli/handoff.mjs +364 -0
- package/src/cli/rules.mjs +429 -0
- package/src/cli/settings-set.mjs +171 -0
- package/src/cli/settings-show.mjs +140 -0
- package/src/cli/settings-slash.mjs +107 -0
- package/src/config/contract.mjs +56 -0
- package/src/config/cursor-rules/discover.mjs +416 -0
- package/src/config/cursor-rules/index.mjs +39 -0
- package/src/config/cursor-rules/match-globs.mjs +132 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
- package/src/config/cursor-rules/priority.mjs +26 -0
- package/src/config/cursor-rules/profile.mjs +403 -0
- package/src/config/cursor-rules/select.mjs +259 -0
- package/src/config/defaults.mjs +36 -0
- package/src/config/env-overrides.mjs +207 -0
- package/src/config/merge-defaults.mjs +47 -0
- package/src/config/pi-spine-root.mjs +93 -0
- package/src/config/reviewer-context.mjs +243 -0
- package/src/config/settings-fields.mjs +265 -0
- package/src/config/worker-backend.mjs +116 -0
- package/src/config/worker-context.mjs +402 -0
- package/src/config/worker-launch-script.mjs +130 -0
- package/src/config/worktree-setup-hook.mjs +122 -0
- package/src/dashboard/public/dashboard.css +77 -0
- package/src/dashboard/public/dashboard.js +349 -0
- package/src/dashboard/public/index.html +80 -0
- package/src/dashboard/server.mjs +155 -0
- package/src/dashboard/snapshot.mjs +414 -0
- package/src/dashboard/sse.mjs +15 -0
- package/src/dashboard/view.mjs +292 -0
- package/src/doctor/agent-model-inherit.mjs +101 -0
- package/src/doctor/batch-size-guidance.mjs +72 -0
- package/src/doctor/coexistence.mjs +312 -0
- package/src/doctor/rules-manifest.mjs +133 -0
- package/src/doctor/stale-path.mjs +156 -0
- package/src/doctor/stall-config.mjs +108 -0
- package/src/doctor/suggest-max-parallel.mjs +53 -0
- package/src/doctor/task-packet-size.mjs +110 -0
- package/src/doctor/worktree-health.mjs +71 -0
- package/src/migrate/taskplane-config.mjs +116 -0
- package/src/planner/cycles.mjs +63 -0
- package/src/planner/format-plan.mjs +132 -0
- package/src/planner/graph.mjs +99 -0
- package/src/planner/index.mjs +125 -0
- package/src/planner/lanes.mjs +111 -0
- package/src/planner/pending.mjs +39 -0
- package/src/planner/scope.mjs +142 -0
- package/src/process/liveness.mjs +21 -0
- package/src/tasks/packet/discover.mjs +40 -0
- package/src/tasks/packet/index.mjs +81 -0
- package/src/tasks/packet/merge-deps.mjs +79 -0
- package/src/tasks/packet/parse-prompt.mjs +445 -0
- package/src/tasks/packet/parse-status.mjs +118 -0
- package/src/tasks/packet/validate-contract.mjs +115 -0
- package/src/tasks/packet/validate-prompt.mjs +99 -0
- package/src/worker-tools/report-progress.d.mts +18 -0
- package/src/worker-tools/report-progress.mjs +59 -0
- package/src/worker-tools/request-gate.d.mts +17 -0
- package/src/worker-tools/request-gate.mjs +54 -0
- package/templates/agents/reviewer.md +123 -0
- package/templates/agents/supervisor.md +59 -0
- package/templates/agents/worker.md +122 -0
- package/templates/rules-profile.json +27 -0
- package/templates/spine-config.json +64 -0
- package/templates/tasks/CONTEXT.md +30 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard snapshot builder (PRD §16, NFR-OBS-04).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
classifyTasks,
|
|
7
|
+
loadBatchStateFile,
|
|
8
|
+
parseBatchState,
|
|
9
|
+
reconcileBatch,
|
|
10
|
+
} from "../batch/reconcile.mjs";
|
|
11
|
+
import { loadGateRecord, formatGateSummary } from "../batch/gate.mjs";
|
|
12
|
+
import {
|
|
13
|
+
readJournalEvents,
|
|
14
|
+
readJournalTail,
|
|
15
|
+
summarizeJournalEvent,
|
|
16
|
+
} from "../batch/journal.mjs";
|
|
17
|
+
import { resolveStallConfig } from "../batch/heartbeat.mjs";
|
|
18
|
+
import { loadSpineConfig } from "../../bin/spine-config.mjs";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string|null|undefined} worktreePath
|
|
22
|
+
*/
|
|
23
|
+
export function truncateWorktreePath(worktreePath) {
|
|
24
|
+
if (!worktreePath) return null;
|
|
25
|
+
const parts = String(worktreePath).split(/[/\\]/).filter(Boolean);
|
|
26
|
+
if (parts.length <= 3) return parts.join("/");
|
|
27
|
+
return parts.slice(-3).join("/");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {number|string|null|undefined} lastHeartbeatAt
|
|
32
|
+
* @param {number} [now]
|
|
33
|
+
*/
|
|
34
|
+
export function heartbeatAgeSeconds(lastHeartbeatAt, now = Date.now()) {
|
|
35
|
+
if (lastHeartbeatAt == null) return null;
|
|
36
|
+
const ts =
|
|
37
|
+
typeof lastHeartbeatAt === "number"
|
|
38
|
+
? lastHeartbeatAt
|
|
39
|
+
: new Date(lastHeartbeatAt).getTime();
|
|
40
|
+
if (Number.isNaN(ts)) return null;
|
|
41
|
+
return Math.max(0, Math.floor((now - ts) / 1000));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {object} params
|
|
46
|
+
* @param {object} params.lane
|
|
47
|
+
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} params.classifiedTasks
|
|
48
|
+
* @param {ReturnType<typeof resolveStallConfig>} params.stallConfig
|
|
49
|
+
* @param {number} [params.now]
|
|
50
|
+
*/
|
|
51
|
+
export function classifyLaneStatus({ lane, classifiedTasks, stallConfig, now = Date.now() }) {
|
|
52
|
+
const taskIds = lane.taskIds ?? [];
|
|
53
|
+
const tasks = classifiedTasks.filter((task) => taskIds.includes(task.taskId));
|
|
54
|
+
|
|
55
|
+
if (taskIds.length === 0) {
|
|
56
|
+
return "completed";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const allDone =
|
|
60
|
+
tasks.length > 0 && tasks.every((task) => task.classification === "terminal-success");
|
|
61
|
+
if (allDone) return "completed";
|
|
62
|
+
|
|
63
|
+
const hasActive = tasks.some(
|
|
64
|
+
(task) => task.classification === "running" || task.classification === "pending",
|
|
65
|
+
);
|
|
66
|
+
if (!hasActive) return "completed";
|
|
67
|
+
|
|
68
|
+
let referenceMs = null;
|
|
69
|
+
if (lane.lastHeartbeatAt != null) {
|
|
70
|
+
referenceMs =
|
|
71
|
+
typeof lane.lastHeartbeatAt === "number"
|
|
72
|
+
? lane.lastHeartbeatAt
|
|
73
|
+
: new Date(lane.lastHeartbeatAt).getTime();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (referenceMs == null || Number.isNaN(referenceMs)) {
|
|
77
|
+
const startedAts = tasks
|
|
78
|
+
.map((task) => task.startedAt)
|
|
79
|
+
.filter((value) => value != null)
|
|
80
|
+
.map((value) =>
|
|
81
|
+
typeof value === "number" ? value : new Date(/** @type {string} */ (value)).getTime(),
|
|
82
|
+
)
|
|
83
|
+
.filter((value) => !Number.isNaN(value));
|
|
84
|
+
referenceMs = startedAts.length ? Math.max(...startedAts) : now;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (now - referenceMs > stallConfig.stallTimeoutMs) {
|
|
88
|
+
return "stale";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return "running";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Tasks running or pending in the current wave on this physical lane (tick-active subset).
|
|
96
|
+
*
|
|
97
|
+
* @param {object} params
|
|
98
|
+
* @param {object} params.lane
|
|
99
|
+
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} params.classifiedTasks
|
|
100
|
+
* @param {string[]} [params.currentWaveTaskIds]
|
|
101
|
+
*/
|
|
102
|
+
export function computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWaveTaskIds }) {
|
|
103
|
+
if (!currentWaveTaskIds?.length) return [];
|
|
104
|
+
const waveSet = new Set(currentWaveTaskIds.map(String));
|
|
105
|
+
return classifiedTasks
|
|
106
|
+
.filter((task) => task.laneNumber === lane.laneNumber)
|
|
107
|
+
.filter((task) => waveSet.has(task.taskId))
|
|
108
|
+
.filter(
|
|
109
|
+
(task) =>
|
|
110
|
+
task.classification === "running" ||
|
|
111
|
+
task.classification === "pending" ||
|
|
112
|
+
task.status === "running" ||
|
|
113
|
+
task.status === "pending",
|
|
114
|
+
)
|
|
115
|
+
.map((task) => task.taskId);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {object} params
|
|
120
|
+
* @param {object[]} params.lanes
|
|
121
|
+
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} params.classifiedTasks
|
|
122
|
+
* @param {ReturnType<typeof resolveStallConfig>} params.stallConfig
|
|
123
|
+
* @param {string[]} [params.currentWaveTaskIds]
|
|
124
|
+
* @param {number} [params.now]
|
|
125
|
+
*/
|
|
126
|
+
const LANE_ALERT_RECENT_MS = 30 * 60 * 1000;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {number} laneNumber
|
|
130
|
+
* @param {ReturnType<typeof formatJournalTailEntry>[]} journalTail
|
|
131
|
+
* @param {number} now
|
|
132
|
+
*/
|
|
133
|
+
export function resolveLaneAlert(laneNumber, journalTail, now = Date.now()) {
|
|
134
|
+
const laneId = `lane-${laneNumber}`;
|
|
135
|
+
for (let i = journalTail.length - 1; i >= 0; i -= 1) {
|
|
136
|
+
const entry = journalTail[i];
|
|
137
|
+
if (entry.laneId && entry.laneId !== laneId) continue;
|
|
138
|
+
const ts = Date.parse(entry.timestamp);
|
|
139
|
+
if (Number.isNaN(ts) || now - ts > LANE_ALERT_RECENT_MS) continue;
|
|
140
|
+
if (entry.type === "lane.stall_killed") return "stall-killed";
|
|
141
|
+
if (entry.type === "lane.checkpoint_warning") return "checkpoint-warning";
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @param {number} laneNumber
|
|
148
|
+
* @param {object[]} journalEvents
|
|
149
|
+
*/
|
|
150
|
+
export function resolveLaneHeartbeatMeta(laneNumber, journalEvents) {
|
|
151
|
+
const laneId = `lane-${laneNumber}`;
|
|
152
|
+
for (let i = journalEvents.length - 1; i >= 0; i -= 1) {
|
|
153
|
+
const event = journalEvents[i];
|
|
154
|
+
if (event.type !== "lane.heartbeat") continue;
|
|
155
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
156
|
+
if (payload.laneNumber != null && payload.laneNumber !== laneNumber) continue;
|
|
157
|
+
if (event.laneId && event.laneId !== laneId) continue;
|
|
158
|
+
return {
|
|
159
|
+
heartbeatKind:
|
|
160
|
+
typeof payload.heartbeatKind === "string" ? payload.heartbeatKind : null,
|
|
161
|
+
workerPhase: typeof payload.workerPhase === "string" ? payload.workerPhase : null,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return { heartbeatKind: null, workerPhase: null };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @param {object} params
|
|
169
|
+
* @param {string|null|undefined} params.workerPhase
|
|
170
|
+
* @param {number|null|undefined} params.heartbeatAgeSeconds
|
|
171
|
+
*/
|
|
172
|
+
export function formatLaneHeartbeatDisplay({ workerPhase, heartbeatAgeSeconds }) {
|
|
173
|
+
if (workerPhase === "launching") return "launching";
|
|
174
|
+
if (heartbeatAgeSeconds == null) return "—";
|
|
175
|
+
return `${heartbeatAgeSeconds}s`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {object} params
|
|
180
|
+
* @param {object[]} params.lanes
|
|
181
|
+
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} params.classifiedTasks
|
|
182
|
+
* @param {ReturnType<typeof resolveStallConfig>} params.stallConfig
|
|
183
|
+
* @param {string[]} [params.currentWaveTaskIds]
|
|
184
|
+
* @param {number} [params.now]
|
|
185
|
+
* @param {object[]} [params.journalEvents]
|
|
186
|
+
*/
|
|
187
|
+
export function buildLaneRows({
|
|
188
|
+
lanes,
|
|
189
|
+
classifiedTasks,
|
|
190
|
+
stallConfig,
|
|
191
|
+
currentWaveTaskIds = [],
|
|
192
|
+
journalTail = [],
|
|
193
|
+
journalEvents = [],
|
|
194
|
+
now = Date.now(),
|
|
195
|
+
}) {
|
|
196
|
+
return (lanes ?? []).map((lane) => {
|
|
197
|
+
const heartbeatMeta = resolveLaneHeartbeatMeta(lane.laneNumber, journalEvents);
|
|
198
|
+
const heartbeatAgeSecondsValue = heartbeatAgeSeconds(lane.lastHeartbeatAt, now);
|
|
199
|
+
return {
|
|
200
|
+
laneId: lane.laneId ?? `lane-${lane.laneNumber}`,
|
|
201
|
+
laneNumber: lane.laneNumber,
|
|
202
|
+
status: classifyLaneStatus({ lane, classifiedTasks, stallConfig, now }),
|
|
203
|
+
activeTaskIds: computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWaveTaskIds }),
|
|
204
|
+
taskIds: lane.taskIds ?? [],
|
|
205
|
+
heartbeatAgeSeconds: heartbeatAgeSecondsValue,
|
|
206
|
+
heartbeatKind: heartbeatMeta.heartbeatKind,
|
|
207
|
+
workerPhase: heartbeatMeta.workerPhase,
|
|
208
|
+
heartbeatDisplay: formatLaneHeartbeatDisplay({
|
|
209
|
+
workerPhase: heartbeatMeta.workerPhase,
|
|
210
|
+
heartbeatAgeSeconds: heartbeatAgeSecondsValue,
|
|
211
|
+
}),
|
|
212
|
+
worktree: truncateWorktreePath(lane.worktreePath),
|
|
213
|
+
laneAlert: resolveLaneAlert(lane.laneNumber, journalTail, now),
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @param {import("../batch/reconcile.mjs").NormalizedBatchState | Record<string, unknown> | null} batchState
|
|
220
|
+
*/
|
|
221
|
+
export function buildWaveProgress(batchState) {
|
|
222
|
+
const raw =
|
|
223
|
+
batchState && typeof batchState === "object" && "raw" in batchState
|
|
224
|
+
? /** @type {Record<string, unknown>} */ (batchState.raw)
|
|
225
|
+
: /** @type {Record<string, unknown>} */ (batchState ?? {});
|
|
226
|
+
|
|
227
|
+
const wavePlan = Array.isArray(raw.wavePlan) ? raw.wavePlan : [];
|
|
228
|
+
const currentWaveIndex = Number(raw.currentWaveIndex ?? 0);
|
|
229
|
+
const totalWaves = Number(raw.totalWaves ?? wavePlan.length);
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
currentWaveIndex,
|
|
233
|
+
totalWaves,
|
|
234
|
+
waves: wavePlan.map((entry, index) => ({
|
|
235
|
+
index,
|
|
236
|
+
taskIds: Array.isArray(entry) ? entry.map(String) : [],
|
|
237
|
+
status:
|
|
238
|
+
index < currentWaveIndex ? "completed" : index === currentWaveIndex ? "active" : "pending",
|
|
239
|
+
})),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {object} event
|
|
245
|
+
*/
|
|
246
|
+
export function formatJournalTailEntry(event) {
|
|
247
|
+
return {
|
|
248
|
+
eventId: event.eventId,
|
|
249
|
+
type: event.type,
|
|
250
|
+
timestamp: event.timestamp,
|
|
251
|
+
laneId: event.laneId ?? null,
|
|
252
|
+
taskId: event.taskId ?? null,
|
|
253
|
+
summary: summarizeJournalEvent(event),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @param {import("../batch/reconcile.mjs").NormalizedBatchState | null} batch
|
|
259
|
+
*/
|
|
260
|
+
function summarizeBatch(batch) {
|
|
261
|
+
if (!batch) return null;
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
batchId: batch.batchId,
|
|
265
|
+
phase: batch.phase,
|
|
266
|
+
baseBranch: batch.baseBranch,
|
|
267
|
+
orchBranch: batch.orchBranch,
|
|
268
|
+
startedAt: batch.startedAt,
|
|
269
|
+
endedAt: batch.endedAt,
|
|
270
|
+
failedTasks: batch.failedTasks,
|
|
271
|
+
succeededTasks: batch.succeededTasks,
|
|
272
|
+
totalTasks: batch.totalTasks,
|
|
273
|
+
currentWaveIndex:
|
|
274
|
+
batch.raw && typeof batch.raw === "object"
|
|
275
|
+
? /** @type {{ currentWaveIndex?: number }} */ (batch.raw).currentWaveIndex ?? 0
|
|
276
|
+
: 0,
|
|
277
|
+
totalWaves:
|
|
278
|
+
batch.raw && typeof batch.raw === "object"
|
|
279
|
+
? /** @type {{ totalWaves?: number }} */ (batch.raw).totalWaves ??
|
|
280
|
+
(Array.isArray(/** @type {{ wavePlan?: unknown[] }} */ (batch.raw).wavePlan)
|
|
281
|
+
? /** @type {{ wavePlan: unknown[] }} */ (batch.raw).wavePlan.length
|
|
282
|
+
: 0)
|
|
283
|
+
: 0,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Default dashboard view (FR-SHIP-07): reconciliation headline/commands plus gate affordance
|
|
289
|
+
* without requiring CLI `--diagnose`.
|
|
290
|
+
*
|
|
291
|
+
* @param {object} reconciliation
|
|
292
|
+
* @param {object|null} gate
|
|
293
|
+
*/
|
|
294
|
+
export function buildDefaultViewStatus(reconciliation, gate) {
|
|
295
|
+
const diagnosis = reconciliation?.diagnosis ?? null;
|
|
296
|
+
const gateApplicable = diagnosis === "needs_integrate" || gate != null;
|
|
297
|
+
|
|
298
|
+
let gateAffordance = null;
|
|
299
|
+
if (gate) {
|
|
300
|
+
gateAffordance = {
|
|
301
|
+
visible: true,
|
|
302
|
+
gateId: gate.gateId,
|
|
303
|
+
kind: gate.kind,
|
|
304
|
+
status: gate.status,
|
|
305
|
+
summary: gate.summary,
|
|
306
|
+
openedAt: gate.openedAt,
|
|
307
|
+
pending: gate.status === "pending",
|
|
308
|
+
};
|
|
309
|
+
} else if (diagnosis === "needs_integrate") {
|
|
310
|
+
gateAffordance = {
|
|
311
|
+
visible: true,
|
|
312
|
+
gateId: null,
|
|
313
|
+
kind: "integrate",
|
|
314
|
+
status: "missing",
|
|
315
|
+
summary: "Integrate gate not opened yet — wait for engine or run spine batch resume",
|
|
316
|
+
openedAt: null,
|
|
317
|
+
pending: true,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
diagnosis,
|
|
323
|
+
headline: reconciliation?.headline ?? "",
|
|
324
|
+
suggestedCommand: reconciliation?.suggestedCommand ?? "",
|
|
325
|
+
alternatives: reconciliation?.alternatives ?? [],
|
|
326
|
+
gateApplicable,
|
|
327
|
+
gate: gateAffordance,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @param {string} projectRoot
|
|
333
|
+
*/
|
|
334
|
+
export function buildDashboardSnapshot(projectRoot) {
|
|
335
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
336
|
+
const stallConfig = resolveStallConfig(configResult.config ?? {});
|
|
337
|
+
const reconciliation = reconcileBatch({ projectRoot, verbose: true });
|
|
338
|
+
|
|
339
|
+
let batch = null;
|
|
340
|
+
if (reconciliation.batchStatePath) {
|
|
341
|
+
const loaded = loadBatchStateFile(projectRoot, reconciliation.batchStatePath);
|
|
342
|
+
if (loaded.raw) {
|
|
343
|
+
batch = parseBatchState(loaded.raw, loaded.path ?? reconciliation.batchStatePath);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const classifiedTasks =
|
|
348
|
+
reconciliation.signals?.tasks ??
|
|
349
|
+
(batch ? classifyTasks(batch, null) : []);
|
|
350
|
+
|
|
351
|
+
let gate = null;
|
|
352
|
+
if (reconciliation.batchId) {
|
|
353
|
+
const record = loadGateRecord(projectRoot, reconciliation.batchId);
|
|
354
|
+
if (record) {
|
|
355
|
+
gate = {
|
|
356
|
+
gateId: record.gateId,
|
|
357
|
+
batchId: record.batchId,
|
|
358
|
+
kind: record.kind,
|
|
359
|
+
status: record.status,
|
|
360
|
+
openedAt: record.openedAt,
|
|
361
|
+
summary: formatGateSummary(record),
|
|
362
|
+
evidenceRefs: record.evidenceRefs ?? [],
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
let journalTail = [];
|
|
368
|
+
let journalEvents = [];
|
|
369
|
+
if (reconciliation.batchId) {
|
|
370
|
+
journalEvents = readJournalEvents(projectRoot, reconciliation.batchId);
|
|
371
|
+
journalTail = readJournalTail(journalEvents, 20).map(formatJournalTailEntry);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const now = Date.now();
|
|
375
|
+
const rawBatch =
|
|
376
|
+
batch?.raw && typeof batch.raw === "object"
|
|
377
|
+
? /** @type {Record<string, unknown>} */ (batch.raw)
|
|
378
|
+
: {};
|
|
379
|
+
const currentWaveIndex = Number(rawBatch.currentWaveIndex ?? 0);
|
|
380
|
+
const wavePlan = Array.isArray(rawBatch.wavePlan) ? rawBatch.wavePlan : [];
|
|
381
|
+
const currentWaveTaskIds = Array.isArray(wavePlan[currentWaveIndex])
|
|
382
|
+
? wavePlan[currentWaveIndex].map(String)
|
|
383
|
+
: [];
|
|
384
|
+
|
|
385
|
+
const lanes = buildLaneRows({
|
|
386
|
+
lanes: batch?.lanes ?? [],
|
|
387
|
+
classifiedTasks,
|
|
388
|
+
stallConfig,
|
|
389
|
+
currentWaveTaskIds,
|
|
390
|
+
journalTail,
|
|
391
|
+
journalEvents,
|
|
392
|
+
now,
|
|
393
|
+
});
|
|
394
|
+
const waves = buildWaveProgress(batch);
|
|
395
|
+
const defaultView = buildDefaultViewStatus(reconciliation, gate);
|
|
396
|
+
|
|
397
|
+
return {
|
|
398
|
+
generatedAt: new Date(now).toISOString(),
|
|
399
|
+
defaultView,
|
|
400
|
+
diagnosis: reconciliation.diagnosis,
|
|
401
|
+
headline: reconciliation.headline,
|
|
402
|
+
suggestedCommand: reconciliation.suggestedCommand,
|
|
403
|
+
alternatives: reconciliation.alternatives ?? [],
|
|
404
|
+
batchId: reconciliation.batchId,
|
|
405
|
+
phase: reconciliation.phase,
|
|
406
|
+
batchStatePath: reconciliation.batchStatePath,
|
|
407
|
+
reconciliation,
|
|
408
|
+
batch: summarizeBatch(batch),
|
|
409
|
+
lanes,
|
|
410
|
+
gate,
|
|
411
|
+
journalTail,
|
|
412
|
+
waves,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-Sent Events helpers for dashboard (PRD §16).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function formatSseDataFrame(payload) {
|
|
6
|
+
return `data: ${JSON.stringify(payload)}\n\n`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function writeSseHeaders(res) {
|
|
10
|
+
res.writeHead(200, {
|
|
11
|
+
'Content-Type': 'text/event-stream',
|
|
12
|
+
'Cache-Control': 'no-cache',
|
|
13
|
+
Connection: 'keep-alive',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard view model (PRD §16.1) — pure functions for browser + tests.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const DIAGNOSIS_BADGE_CLASS = {
|
|
6
|
+
running: "badge-running",
|
|
7
|
+
paused: "badge-paused",
|
|
8
|
+
needs_retry: "badge-action",
|
|
9
|
+
needs_merge: "badge-action",
|
|
10
|
+
needs_integrate: "badge-integrate",
|
|
11
|
+
completed: "badge-success",
|
|
12
|
+
completed_manual: "badge-warn",
|
|
13
|
+
limbo_stale: "badge-warn",
|
|
14
|
+
failed: "badge-error",
|
|
15
|
+
aborted: "badge-error",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const PRIMARY_ACTION_LABEL = {
|
|
19
|
+
limbo_stale: "Dismiss",
|
|
20
|
+
aborted: "Dismiss",
|
|
21
|
+
completed_manual: "Complete",
|
|
22
|
+
needs_integrate: "Integrate",
|
|
23
|
+
needs_retry: "Retry",
|
|
24
|
+
failed: "Retry",
|
|
25
|
+
needs_merge: "Resume",
|
|
26
|
+
paused: "Resume",
|
|
27
|
+
running: "Status",
|
|
28
|
+
completed: "Preflight",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string|null|undefined} diagnosis
|
|
33
|
+
*/
|
|
34
|
+
export function diagnosisBadgeClass(diagnosis) {
|
|
35
|
+
if (!diagnosis) return "badge-idle";
|
|
36
|
+
return DIAGNOSIS_BADGE_CLASS[diagnosis] ?? "badge-action";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string|null|undefined} diagnosis
|
|
41
|
+
*/
|
|
42
|
+
export function primaryActionLabel(diagnosis) {
|
|
43
|
+
if (!diagnosis) return null;
|
|
44
|
+
return PRIMARY_ACTION_LABEL[diagnosis] ?? "Diagnose";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {object} snapshot
|
|
49
|
+
*/
|
|
50
|
+
export function isIdleSnapshot(snapshot) {
|
|
51
|
+
return snapshot?.diagnosis == null && snapshot?.batchId == null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} command
|
|
56
|
+
*/
|
|
57
|
+
export function alternativeActionLabel(command) {
|
|
58
|
+
const cmd = String(command ?? "").trim();
|
|
59
|
+
if (!cmd) return "Action";
|
|
60
|
+
if (/dismiss/i.test(cmd)) return "Dismiss";
|
|
61
|
+
if (/complete/i.test(cmd)) return "Complete";
|
|
62
|
+
if (/integrate/i.test(cmd)) return "Integrate";
|
|
63
|
+
if (/retry/i.test(cmd)) return "Retry";
|
|
64
|
+
if (/resume/i.test(cmd)) return "Resume";
|
|
65
|
+
if (/pause/i.test(cmd)) return "Pause";
|
|
66
|
+
if (/abort/i.test(cmd)) return "Abort";
|
|
67
|
+
if (/preflight/i.test(cmd)) return "Preflight";
|
|
68
|
+
if (/plan/i.test(cmd)) return "Plan";
|
|
69
|
+
if (/skip/i.test(cmd)) return "Skip";
|
|
70
|
+
if (/gate/i.test(cmd)) return "Gate";
|
|
71
|
+
if (/status|diagnose/i.test(cmd)) return "Status";
|
|
72
|
+
return cmd.replace(/^\//, "").split(/\s+/)[0] || "Action";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Copyable CLI chips for the diagnosis banner (§16.1). No HTTP mutations.
|
|
77
|
+
*
|
|
78
|
+
* @param {object} snapshot
|
|
79
|
+
* @returns {{ label: string, command: string, primary: boolean }[]}
|
|
80
|
+
*/
|
|
81
|
+
export function buildActionChips(snapshot) {
|
|
82
|
+
const chips = [];
|
|
83
|
+
const diagnosis = snapshot?.diagnosis ?? null;
|
|
84
|
+
const suggested = snapshot?.suggestedCommand ?? "";
|
|
85
|
+
const primaryLabel = primaryActionLabel(diagnosis);
|
|
86
|
+
|
|
87
|
+
if (suggested) {
|
|
88
|
+
chips.push({
|
|
89
|
+
label: primaryLabel ?? (diagnosis ? "Diagnose" : "Preflight"),
|
|
90
|
+
command: suggested,
|
|
91
|
+
primary: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const alt of snapshot?.alternatives ?? []) {
|
|
96
|
+
if (!alt || alt === suggested) continue;
|
|
97
|
+
chips.push({
|
|
98
|
+
label: alternativeActionLabel(alt),
|
|
99
|
+
command: alt,
|
|
100
|
+
primary: false,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return chips;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {object} snapshot
|
|
109
|
+
*/
|
|
110
|
+
export function buildBannerModel(snapshot) {
|
|
111
|
+
const diagnosis = snapshot?.diagnosis ?? null;
|
|
112
|
+
return {
|
|
113
|
+
headline: snapshot?.headline ?? "",
|
|
114
|
+
suggestedCommand: snapshot?.suggestedCommand ?? "",
|
|
115
|
+
alternatives: snapshot?.alternatives ?? [],
|
|
116
|
+
diagnosis,
|
|
117
|
+
badgeClass: diagnosisBadgeClass(diagnosis),
|
|
118
|
+
primaryAction: primaryActionLabel(diagnosis),
|
|
119
|
+
actionChips: buildActionChips(snapshot),
|
|
120
|
+
idle: isIdleSnapshot(snapshot),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {object|null|undefined} batch
|
|
126
|
+
*/
|
|
127
|
+
export function buildBatchSummaryModel(batch) {
|
|
128
|
+
if (!batch) return null;
|
|
129
|
+
return {
|
|
130
|
+
batchId: batch.batchId,
|
|
131
|
+
phase: batch.phase,
|
|
132
|
+
baseBranch: batch.baseBranch,
|
|
133
|
+
orchBranch: batch.orchBranch,
|
|
134
|
+
startedAt: batch.startedAt,
|
|
135
|
+
endedAt: batch.endedAt,
|
|
136
|
+
taskCounts: {
|
|
137
|
+
succeeded: batch.succeededTasks ?? 0,
|
|
138
|
+
failed: batch.failedTasks ?? 0,
|
|
139
|
+
total: batch.totalTasks ?? 0,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {object} snapshot
|
|
146
|
+
*/
|
|
147
|
+
export function buildWaveModel(snapshot) {
|
|
148
|
+
const waves = snapshot?.waves ?? { currentWaveIndex: 0, totalWaves: 0, waves: [] };
|
|
149
|
+
return {
|
|
150
|
+
currentWaveIndex: waves.currentWaveIndex ?? 0,
|
|
151
|
+
totalWaves: waves.totalWaves ?? 0,
|
|
152
|
+
waves: (waves.waves ?? []).map((wave) => ({
|
|
153
|
+
index: wave.index,
|
|
154
|
+
taskIds: wave.taskIds ?? [],
|
|
155
|
+
status: wave.status,
|
|
156
|
+
})),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {object} lane
|
|
162
|
+
*/
|
|
163
|
+
export function formatLaneHeartbeatDisplay(lane) {
|
|
164
|
+
if (lane?.workerPhase === "launching") return "launching";
|
|
165
|
+
if (lane?.heartbeatAgeSeconds == null) return "—";
|
|
166
|
+
return `${lane.heartbeatAgeSeconds}s`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @param {object} snapshot
|
|
171
|
+
*/
|
|
172
|
+
export function buildLaneTableModel(snapshot) {
|
|
173
|
+
return (snapshot?.lanes ?? []).map((lane) => ({
|
|
174
|
+
laneId: lane.laneId,
|
|
175
|
+
status: lane.status,
|
|
176
|
+
activeTaskIds: lane.activeTaskIds ?? [],
|
|
177
|
+
taskIds: lane.taskIds ?? [],
|
|
178
|
+
heartbeatAgeSeconds: lane.heartbeatAgeSeconds,
|
|
179
|
+
heartbeatKind: lane.heartbeatKind ?? null,
|
|
180
|
+
workerPhase: lane.workerPhase ?? null,
|
|
181
|
+
heartbeatDisplay: lane.heartbeatDisplay ?? formatLaneHeartbeatDisplay(lane),
|
|
182
|
+
worktree: lane.worktree,
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {object|null|undefined} gate
|
|
188
|
+
*/
|
|
189
|
+
export function buildGateModel(gate) {
|
|
190
|
+
if (!gate) return null;
|
|
191
|
+
return {
|
|
192
|
+
gateId: gate.gateId,
|
|
193
|
+
kind: gate.kind,
|
|
194
|
+
status: gate.status,
|
|
195
|
+
summary: gate.summary,
|
|
196
|
+
openedAt: gate.openedAt,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Gate affordance for the default dashboard view (FR-SHIP-07).
|
|
202
|
+
*
|
|
203
|
+
* @param {object} snapshot
|
|
204
|
+
*/
|
|
205
|
+
export function buildGateAffordanceModel(snapshot) {
|
|
206
|
+
const defaultView = snapshot?.defaultView;
|
|
207
|
+
if (defaultView?.gate?.visible) {
|
|
208
|
+
return defaultView.gate;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const gate = snapshot?.gate;
|
|
212
|
+
if (gate) {
|
|
213
|
+
return {
|
|
214
|
+
visible: true,
|
|
215
|
+
gateId: gate.gateId,
|
|
216
|
+
kind: gate.kind,
|
|
217
|
+
status: gate.status,
|
|
218
|
+
summary: gate.summary,
|
|
219
|
+
openedAt: gate.openedAt,
|
|
220
|
+
pending: gate.status === "pending",
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (snapshot?.diagnosis === "needs_integrate") {
|
|
225
|
+
return {
|
|
226
|
+
visible: true,
|
|
227
|
+
gateId: null,
|
|
228
|
+
kind: "integrate",
|
|
229
|
+
status: "missing",
|
|
230
|
+
summary: "Integrate gate not opened yet — wait for engine or run spine batch resume",
|
|
231
|
+
openedAt: null,
|
|
232
|
+
pending: true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {object} snapshot
|
|
241
|
+
*/
|
|
242
|
+
export function shouldShowGateAffordance(snapshot) {
|
|
243
|
+
return buildGateAffordanceModel(snapshot) != null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @param {object} snapshot
|
|
248
|
+
*/
|
|
249
|
+
export function buildJournalModel(snapshot) {
|
|
250
|
+
return (snapshot?.journalTail ?? []).map((entry) => ({
|
|
251
|
+
eventId: entry.eventId,
|
|
252
|
+
type: entry.type,
|
|
253
|
+
timestamp: entry.timestamp,
|
|
254
|
+
summary: entry.summary,
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @param {object} snapshot
|
|
260
|
+
*/
|
|
261
|
+
export function buildDashboardViewModel(snapshot) {
|
|
262
|
+
return {
|
|
263
|
+
generatedAt: snapshot?.generatedAt ?? null,
|
|
264
|
+
idle: isIdleSnapshot(snapshot),
|
|
265
|
+
banner: buildBannerModel(snapshot),
|
|
266
|
+
batch: buildBatchSummaryModel(snapshot?.batch),
|
|
267
|
+
waves: buildWaveModel(snapshot),
|
|
268
|
+
lanes: buildLaneTableModel(snapshot),
|
|
269
|
+
gate: buildGateModel(snapshot?.gate),
|
|
270
|
+
gateAffordance: buildGateAffordanceModel(snapshot),
|
|
271
|
+
showGateAffordance: shouldShowGateAffordance(snapshot),
|
|
272
|
+
journal: buildJournalModel(snapshot),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Banner must not use running/green styling when diagnosis is needs_integrate
|
|
278
|
+
* even if batch.phase is completed (AC-7.3 / TP-025).
|
|
279
|
+
*
|
|
280
|
+
* @param {object} snapshot
|
|
281
|
+
*/
|
|
282
|
+
export function bannerUsesDiagnosisNotPhase(snapshot) {
|
|
283
|
+
const diagnosis = snapshot?.diagnosis;
|
|
284
|
+
const phase = snapshot?.batch?.phase;
|
|
285
|
+
if (diagnosis === "needs_integrate" && phase === "completed") {
|
|
286
|
+
return diagnosisBadgeClass(diagnosis) === "badge-integrate";
|
|
287
|
+
}
|
|
288
|
+
if (diagnosis === "running") {
|
|
289
|
+
return diagnosisBadgeClass(diagnosis) === "badge-running";
|
|
290
|
+
}
|
|
291
|
+
return diagnosisBadgeClass(diagnosis) !== "badge-running" || diagnosis === "running";
|
|
292
|
+
}
|