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,77 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: dark;
|
|
3
|
+
--bg: #0d1117;
|
|
4
|
+
--surface: #161b22;
|
|
5
|
+
--border: #30363d;
|
|
6
|
+
--text: #e6edf3;
|
|
7
|
+
--muted: #8b949e;
|
|
8
|
+
--accent: #58a6ff;
|
|
9
|
+
--running: #3fb950;
|
|
10
|
+
--paused: #d29922;
|
|
11
|
+
--integrate: #a371f7;
|
|
12
|
+
--action: #f0883e;
|
|
13
|
+
--warn: #e3b341;
|
|
14
|
+
--error: #f85149;
|
|
15
|
+
--idle: #6e7681;
|
|
16
|
+
--font-mono: ui-monospace, Menlo, Consolas, monospace;
|
|
17
|
+
--font-sans: system-ui, sans-serif;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font-sans); font-size: 14px; }
|
|
21
|
+
.page-header, .page-footer, .diagnosis-banner, .default-status-panels, .panels { max-width: 1100px; margin: 0 auto; padding: 1rem 1.25rem; }
|
|
22
|
+
.default-status-panels { padding-top: 0; margin-bottom: 1rem; display: flex; flex-direction: column; gap: 1rem; }
|
|
23
|
+
.default-status-panels .panel { margin: 0; }
|
|
24
|
+
.connection-status { margin: 0; color: var(--muted); font-size: 0.85rem; }
|
|
25
|
+
.connection-status[data-state="live"] { color: var(--running); }
|
|
26
|
+
.connection-status[data-state="error"] { color: var(--error); }
|
|
27
|
+
.diagnosis-banner { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; padding: 1rem; }
|
|
28
|
+
.banner-main { display: flex; gap: 0.75rem; align-items: flex-start; }
|
|
29
|
+
.banner-headline { margin: 0; font-size: 1.1rem; }
|
|
30
|
+
.banner-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0 0; }
|
|
31
|
+
.action-chip {
|
|
32
|
+
display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
|
|
33
|
+
padding: 0.4rem 0.65rem; border-radius: 6px; border: 1px solid var(--border);
|
|
34
|
+
background: #21262d; font-family: var(--font-mono); font-size: 0.8rem; color: var(--text);
|
|
35
|
+
cursor: pointer; text-align: left; max-width: 100%;
|
|
36
|
+
}
|
|
37
|
+
.action-chip:hover { border-color: var(--accent); }
|
|
38
|
+
.action-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
39
|
+
.action-chip-primary { border-color: var(--accent); background: rgba(88,166,255,0.08); }
|
|
40
|
+
.action-chip-label { font-size: 0.65rem; font-weight: 600; text-transform: uppercase; color: var(--muted); font-family: var(--font-sans); }
|
|
41
|
+
.action-chip-command { color: var(--accent); word-break: break-all; }
|
|
42
|
+
.action-chip-copied { border-color: var(--running); }
|
|
43
|
+
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; }
|
|
44
|
+
.badge-idle { background: #21262d; color: var(--idle); }
|
|
45
|
+
.badge-running { background: rgba(63,185,80,0.15); color: var(--running); }
|
|
46
|
+
.badge-paused { background: rgba(210,153,34,0.15); color: var(--paused); }
|
|
47
|
+
.badge-integrate { background: rgba(163,113,247,0.15); color: var(--integrate); }
|
|
48
|
+
.badge-action { background: rgba(240,136,62,0.15); color: var(--action); }
|
|
49
|
+
.badge-warn { background: rgba(227,179,65,0.15); color: var(--warn); }
|
|
50
|
+
.badge-success { background: rgba(63,185,80,0.1); color: var(--running); }
|
|
51
|
+
.badge-error { background: rgba(248,81,73,0.15); color: var(--error); }
|
|
52
|
+
.lane-alert-checkpoint { color: var(--warn); font-weight: 600; }
|
|
53
|
+
.lane-alert-stall { color: var(--error); font-weight: 600; }
|
|
54
|
+
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
|
|
55
|
+
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
|
|
56
|
+
.panel-wide { grid-column: 1 / -1; }
|
|
57
|
+
.panel h3 { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; }
|
|
58
|
+
.kv-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
|
|
59
|
+
.kv-grid dt { color: var(--muted); }
|
|
60
|
+
.kv-grid dd { margin: 0; font-family: var(--font-mono); font-size: 0.85rem; }
|
|
61
|
+
.wave-summary { font-family: var(--font-mono); }
|
|
62
|
+
.wave-list, .journal-list { margin: 0; padding-left: 1.25rem; font-family: var(--font-mono); font-size: 0.85rem; }
|
|
63
|
+
.wave-list li[data-status="active"] { color: var(--accent); }
|
|
64
|
+
.lane-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
|
|
65
|
+
.lane-table th, .lane-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
|
|
66
|
+
.lane-table th { color: var(--muted); }
|
|
67
|
+
.lane-table td { font-family: var(--font-mono); }
|
|
68
|
+
.lane-status-running { color: var(--running); }
|
|
69
|
+
.lane-status-stale { color: var(--warn); }
|
|
70
|
+
.lane-status-completed { color: var(--muted); }
|
|
71
|
+
.empty-hint { color: var(--muted); font-style: italic; }
|
|
72
|
+
.gate-status { font-weight: 600; text-transform: uppercase; font-size: 0.75rem; }
|
|
73
|
+
.gate-status-pending, .gate-status-missing { color: var(--warn); }
|
|
74
|
+
.gate-status-approved { color: var(--running); }
|
|
75
|
+
.gate-status-rejected { color: var(--error); }
|
|
76
|
+
.page-footer { color: var(--muted); font-size: 0.8rem; }
|
|
77
|
+
.snapshot-time { font-family: var(--font-mono); }
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { buildDashboardViewModel } from "/view.mjs";
|
|
2
|
+
|
|
3
|
+
/** @param {string} id */
|
|
4
|
+
const $ = (id) => document.getElementById(id);
|
|
5
|
+
|
|
6
|
+
/** @param {number|string|null|undefined} value */
|
|
7
|
+
function formatTs(value) {
|
|
8
|
+
if (value == null) return "—";
|
|
9
|
+
const d = typeof value === "number" ? new Date(value) : new Date(String(value));
|
|
10
|
+
return Number.isNaN(d.getTime()) ? String(value) : d.toISOString();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @param {number|null|undefined} age */
|
|
14
|
+
function formatHeartbeat(age) {
|
|
15
|
+
if (age == null) return "—";
|
|
16
|
+
return `${age}s`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @param {"connecting"|"live"|"error"} state @param {string} text */
|
|
20
|
+
function setConnection(state, text) {
|
|
21
|
+
const el = $("connection-status");
|
|
22
|
+
el.dataset.state = state;
|
|
23
|
+
el.textContent = text;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @param {string} command */
|
|
27
|
+
async function copyCommand(command) {
|
|
28
|
+
if (navigator.clipboard?.writeText) {
|
|
29
|
+
await navigator.clipboard.writeText(command);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const textarea = document.createElement("textarea");
|
|
33
|
+
textarea.value = command;
|
|
34
|
+
textarea.setAttribute("readonly", "");
|
|
35
|
+
textarea.style.position = "absolute";
|
|
36
|
+
textarea.style.left = "-9999px";
|
|
37
|
+
document.body.appendChild(textarea);
|
|
38
|
+
textarea.select();
|
|
39
|
+
document.execCommand("copy");
|
|
40
|
+
textarea.remove();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {HTMLElement} chip
|
|
45
|
+
* @param {string} command
|
|
46
|
+
*/
|
|
47
|
+
async function handleChipCopy(chip, command) {
|
|
48
|
+
try {
|
|
49
|
+
await copyCommand(command);
|
|
50
|
+
chip.classList.add("action-chip-copied");
|
|
51
|
+
chip.setAttribute("aria-label", `Copied: ${command}`);
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
chip.classList.remove("action-chip-copied");
|
|
54
|
+
chip.setAttribute("aria-label", `Copy command: ${command}`);
|
|
55
|
+
}, 1200);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error("Failed to copy command", err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>} vm */
|
|
62
|
+
function renderBanner(vm) {
|
|
63
|
+
const badge = $("banner-badge");
|
|
64
|
+
const headline = $("banner-headline");
|
|
65
|
+
const actions = $("banner-actions");
|
|
66
|
+
const banner = vm.banner;
|
|
67
|
+
|
|
68
|
+
headline.textContent = banner.headline;
|
|
69
|
+
|
|
70
|
+
if (!banner.diagnosis) {
|
|
71
|
+
badge.hidden = true;
|
|
72
|
+
badge.className = "badge badge-idle";
|
|
73
|
+
} else {
|
|
74
|
+
badge.hidden = false;
|
|
75
|
+
badge.className = `badge ${banner.badgeClass}`;
|
|
76
|
+
badge.textContent = banner.diagnosis.replace(/_/g, " ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
actions.replaceChildren();
|
|
80
|
+
const chips = banner.actionChips ?? [];
|
|
81
|
+
if (!chips.length) {
|
|
82
|
+
actions.hidden = true;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
actions.hidden = false;
|
|
87
|
+
for (const chip of chips) {
|
|
88
|
+
const btn = document.createElement("button");
|
|
89
|
+
btn.type = "button";
|
|
90
|
+
btn.className = chip.primary ? "action-chip action-chip-primary" : "action-chip";
|
|
91
|
+
btn.setAttribute("aria-label", `Copy command: ${chip.command}`);
|
|
92
|
+
|
|
93
|
+
const labelEl = document.createElement("span");
|
|
94
|
+
labelEl.className = "action-chip-label";
|
|
95
|
+
labelEl.textContent = chip.label;
|
|
96
|
+
|
|
97
|
+
const cmdEl = document.createElement("span");
|
|
98
|
+
cmdEl.className = "action-chip-command";
|
|
99
|
+
cmdEl.textContent = chip.command;
|
|
100
|
+
|
|
101
|
+
btn.append(labelEl, cmdEl);
|
|
102
|
+
btn.addEventListener("click", () => {
|
|
103
|
+
void handleChipCopy(btn, chip.command);
|
|
104
|
+
});
|
|
105
|
+
actions.appendChild(btn);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @param {HTMLDListElement} dl @param {string} key @param {string|number|null|undefined} value */
|
|
110
|
+
function appendKv(dl, key, value) {
|
|
111
|
+
if (value == null || value === "") return;
|
|
112
|
+
const dt = document.createElement("dt");
|
|
113
|
+
dt.textContent = key;
|
|
114
|
+
const dd = document.createElement("dd");
|
|
115
|
+
dd.textContent = String(value);
|
|
116
|
+
dl.appendChild(dt);
|
|
117
|
+
dl.appendChild(dd);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["batch"]} batch */
|
|
121
|
+
function renderBatch(batch) {
|
|
122
|
+
const dl = $("batch-summary");
|
|
123
|
+
dl.replaceChildren();
|
|
124
|
+
if (!batch) return;
|
|
125
|
+
appendKv(dl, "Batch ID", batch.batchId);
|
|
126
|
+
appendKv(dl, "Phase", batch.phase);
|
|
127
|
+
appendKv(dl, "Base", batch.baseBranch);
|
|
128
|
+
appendKv(dl, "Orch", batch.orchBranch);
|
|
129
|
+
appendKv(dl, "Started", formatTs(batch.startedAt));
|
|
130
|
+
appendKv(dl, "Ended", formatTs(batch.endedAt));
|
|
131
|
+
appendKv(
|
|
132
|
+
dl,
|
|
133
|
+
"Tasks",
|
|
134
|
+
`${batch.taskCounts.succeeded}/${batch.taskCounts.total} ok, ${batch.taskCounts.failed} failed`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["waves"]} waves */
|
|
139
|
+
function renderWaves(waves) {
|
|
140
|
+
$("wave-progress-summary").textContent =
|
|
141
|
+
waves.totalWaves > 0
|
|
142
|
+
? `Wave ${waves.currentWaveIndex + 1} of ${waves.totalWaves} — lane ≠ wave (see Lanes table)`
|
|
143
|
+
: "No waves";
|
|
144
|
+
const list = $("wave-list");
|
|
145
|
+
list.replaceChildren();
|
|
146
|
+
for (const wave of waves.waves) {
|
|
147
|
+
const li = document.createElement("li");
|
|
148
|
+
li.dataset.status = wave.status;
|
|
149
|
+
li.textContent = `Wave ${wave.index + 1} [${wave.status}]: ${wave.taskIds.join(", ") || "(empty)"}`;
|
|
150
|
+
list.appendChild(li);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["lanes"]} lanes */
|
|
155
|
+
function renderLanes(lanes) {
|
|
156
|
+
const tbody = $("lane-table-body");
|
|
157
|
+
tbody.replaceChildren();
|
|
158
|
+
if (!lanes.length) {
|
|
159
|
+
const tr = document.createElement("tr");
|
|
160
|
+
const td = document.createElement("td");
|
|
161
|
+
td.colSpan = 6;
|
|
162
|
+
td.className = "empty-hint";
|
|
163
|
+
td.textContent = "No lanes";
|
|
164
|
+
tr.appendChild(td);
|
|
165
|
+
tbody.appendChild(tr);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
for (const lane of lanes) {
|
|
169
|
+
const tr = document.createElement("tr");
|
|
170
|
+
const statusLabel =
|
|
171
|
+
lane.laneAlert === "checkpoint-warning"
|
|
172
|
+
? `${lane.status} · checkpoint warning`
|
|
173
|
+
: lane.laneAlert === "stall-killed"
|
|
174
|
+
? `${lane.status} · stall killed`
|
|
175
|
+
: lane.status;
|
|
176
|
+
const values = [
|
|
177
|
+
lane.laneId,
|
|
178
|
+
statusLabel,
|
|
179
|
+
(lane.activeTaskIds ?? []).join(", ") || "—",
|
|
180
|
+
(lane.taskIds ?? []).join(", ") || "—",
|
|
181
|
+
formatHeartbeat(lane.heartbeatDisplay ?? lane.heartbeatAgeSeconds),
|
|
182
|
+
lane.worktree ?? "—",
|
|
183
|
+
];
|
|
184
|
+
values.forEach((text, index) => {
|
|
185
|
+
const td = document.createElement("td");
|
|
186
|
+
td.textContent = text;
|
|
187
|
+
if (index === 1) {
|
|
188
|
+
td.className = `lane-status-${lane.status}`;
|
|
189
|
+
if (lane.laneAlert === "checkpoint-warning") td.classList.add("lane-alert-checkpoint");
|
|
190
|
+
if (lane.laneAlert === "stall-killed") td.classList.add("lane-alert-stall");
|
|
191
|
+
}
|
|
192
|
+
tr.appendChild(td);
|
|
193
|
+
});
|
|
194
|
+
tbody.appendChild(tr);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["journal"]} journal @param {HTMLElement} listEl */
|
|
199
|
+
function renderJournalList(listEl, journal) {
|
|
200
|
+
listEl.replaceChildren();
|
|
201
|
+
if (!journal.length) {
|
|
202
|
+
const li = document.createElement("li");
|
|
203
|
+
li.className = "empty-hint";
|
|
204
|
+
li.textContent = "No journal events";
|
|
205
|
+
listEl.appendChild(li);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
for (const entry of journal) {
|
|
209
|
+
const li = document.createElement("li");
|
|
210
|
+
li.textContent = `${formatTs(entry.timestamp)} · ${entry.type}: ${entry.summary}`;
|
|
211
|
+
listEl.appendChild(li);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["gateAffordance"]} gateAffordance */
|
|
216
|
+
function renderGatePanel(gateAffordance) {
|
|
217
|
+
const section = $("gate-panel-section");
|
|
218
|
+
const panel = $("gate-panel");
|
|
219
|
+
panel.replaceChildren();
|
|
220
|
+
|
|
221
|
+
if (!gateAffordance?.visible) {
|
|
222
|
+
section.hidden = true;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
section.hidden = false;
|
|
227
|
+
|
|
228
|
+
const status = document.createElement("p");
|
|
229
|
+
const statusClass =
|
|
230
|
+
gateAffordance.status === "approved"
|
|
231
|
+
? "gate-status-approved"
|
|
232
|
+
: gateAffordance.status === "rejected"
|
|
233
|
+
? "gate-status-rejected"
|
|
234
|
+
: "gate-status-pending";
|
|
235
|
+
status.innerHTML = `<span class="gate-status ${statusClass}">${gateAffordance.status}</span> · ${gateAffordance.kind ?? "integrate"}`;
|
|
236
|
+
panel.appendChild(status);
|
|
237
|
+
|
|
238
|
+
if (gateAffordance.summary) {
|
|
239
|
+
const summary = document.createElement("p");
|
|
240
|
+
summary.textContent = gateAffordance.summary;
|
|
241
|
+
panel.appendChild(summary);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (gateAffordance.openedAt) {
|
|
245
|
+
const opened = document.createElement("p");
|
|
246
|
+
opened.textContent = `Opened: ${formatTs(gateAffordance.openedAt)}`;
|
|
247
|
+
panel.appendChild(opened);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* FR-SHIP-07 phase 2: journal tail on default dashboard view (above active batch panels).
|
|
253
|
+
*
|
|
254
|
+
* @param {ReturnType<typeof buildDashboardViewModel>["journal"]} journal
|
|
255
|
+
* @param {boolean} showFullJournalLink
|
|
256
|
+
*/
|
|
257
|
+
function renderDefaultJournalTail(journal, showFullJournalLink) {
|
|
258
|
+
const section = $("default-journal-section");
|
|
259
|
+
const deepLink = $("default-journal-deep-link");
|
|
260
|
+
|
|
261
|
+
section.hidden = false;
|
|
262
|
+
renderJournalList($("default-journal-list"), journal);
|
|
263
|
+
deepLink.hidden = !showFullJournalLink;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Default view panels: integrate gate (when applicable) and journal tail for active batches.
|
|
268
|
+
*
|
|
269
|
+
* @param {ReturnType<typeof buildDashboardViewModel>} vm
|
|
270
|
+
*/
|
|
271
|
+
function renderDefaultStatusPanels(vm) {
|
|
272
|
+
const section = $("default-status-panels");
|
|
273
|
+
const showGate = vm.gateAffordance?.visible;
|
|
274
|
+
const showJournal = !vm.idle;
|
|
275
|
+
|
|
276
|
+
if (!showGate && !showJournal) {
|
|
277
|
+
section.hidden = true;
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
section.hidden = false;
|
|
282
|
+
renderGatePanel(vm.gateAffordance);
|
|
283
|
+
if (showJournal) {
|
|
284
|
+
renderDefaultJournalTail(vm.journal, true);
|
|
285
|
+
} else {
|
|
286
|
+
$("default-journal-section").hidden = true;
|
|
287
|
+
$("default-journal-deep-link").hidden = true;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** @param {ReturnType<typeof buildDashboardViewModel>["journal"]} journal */
|
|
292
|
+
function renderJournal(journal) {
|
|
293
|
+
renderJournalList($("journal-list"), journal);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** @param {object} snapshot */
|
|
297
|
+
export function renderSnapshot(snapshot) {
|
|
298
|
+
const vm = buildDashboardViewModel(snapshot);
|
|
299
|
+
$("active-panels").hidden = vm.idle;
|
|
300
|
+
renderBanner(vm);
|
|
301
|
+
renderDefaultStatusPanels(vm);
|
|
302
|
+
if (!vm.idle) {
|
|
303
|
+
renderBatch(vm.batch);
|
|
304
|
+
renderWaves(vm.waves);
|
|
305
|
+
renderLanes(vm.lanes);
|
|
306
|
+
renderJournal(vm.journal);
|
|
307
|
+
}
|
|
308
|
+
$("snapshot-time").textContent = vm.generatedAt ? `Snapshot: ${vm.generatedAt}` : "";
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let eventSource = null;
|
|
312
|
+
/** @type {ReturnType<typeof setTimeout>|null} */
|
|
313
|
+
let reconnectTimer = null;
|
|
314
|
+
|
|
315
|
+
function connectSse() {
|
|
316
|
+
if (eventSource) {
|
|
317
|
+
eventSource.close();
|
|
318
|
+
eventSource = null;
|
|
319
|
+
}
|
|
320
|
+
setConnection("connecting", "Connecting…");
|
|
321
|
+
eventSource = new EventSource("/api/events");
|
|
322
|
+
eventSource.onopen = () => {
|
|
323
|
+
setConnection("live", "Live · SSE");
|
|
324
|
+
if (reconnectTimer) {
|
|
325
|
+
clearTimeout(reconnectTimer);
|
|
326
|
+
reconnectTimer = null;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
eventSource.onmessage = (event) => {
|
|
330
|
+
try {
|
|
331
|
+
renderSnapshot(JSON.parse(event.data));
|
|
332
|
+
} catch (err) {
|
|
333
|
+
console.error("Failed to parse SSE snapshot", err);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
eventSource.onerror = () => {
|
|
337
|
+
setConnection("error", "Connection lost — reconnecting…");
|
|
338
|
+
eventSource?.close();
|
|
339
|
+
eventSource = null;
|
|
340
|
+
if (!reconnectTimer) {
|
|
341
|
+
reconnectTimer = setTimeout(() => {
|
|
342
|
+
reconnectTimer = null;
|
|
343
|
+
connectSse();
|
|
344
|
+
}, 2000);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
connectSse();
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>pi-spine dashboard</title>
|
|
7
|
+
<link rel="stylesheet" href="/dashboard.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<header class="page-header">
|
|
11
|
+
<h1>pi-spine dashboard</h1>
|
|
12
|
+
<p id="connection-status" class="connection-status" aria-live="polite">Connecting…</p>
|
|
13
|
+
</header>
|
|
14
|
+
|
|
15
|
+
<section id="diagnosis-banner" class="diagnosis-banner" aria-labelledby="banner-headline">
|
|
16
|
+
<div class="banner-main">
|
|
17
|
+
<span id="banner-badge" class="badge badge-idle" hidden></span>
|
|
18
|
+
<h2 id="banner-headline" class="banner-headline">Loading…</h2>
|
|
19
|
+
</div>
|
|
20
|
+
<div id="banner-actions" class="banner-actions" role="group" aria-label="Suggested CLI commands"></div>
|
|
21
|
+
</section>
|
|
22
|
+
|
|
23
|
+
<section id="default-status-panels" class="default-status-panels" hidden>
|
|
24
|
+
<section id="gate-panel-section" class="panel" aria-labelledby="gate-heading" hidden>
|
|
25
|
+
<h3 id="gate-heading">Integrate gate</h3>
|
|
26
|
+
<div id="gate-panel" class="gate-panel"></div>
|
|
27
|
+
</section>
|
|
28
|
+
<section id="default-journal-section" class="panel panel-wide" aria-labelledby="default-journal-heading" hidden>
|
|
29
|
+
<h3 id="default-journal-heading">Journal tail</h3>
|
|
30
|
+
<ol id="default-journal-list" class="journal-list"></ol>
|
|
31
|
+
<p id="default-journal-deep-link" class="journal-deep-link" hidden>
|
|
32
|
+
<a href="#journal-heading">View full journal</a>
|
|
33
|
+
</p>
|
|
34
|
+
</section>
|
|
35
|
+
</section>
|
|
36
|
+
|
|
37
|
+
<main class="panels" id="active-panels" hidden>
|
|
38
|
+
<section class="panel" aria-labelledby="batch-summary-heading">
|
|
39
|
+
<h3 id="batch-summary-heading">Batch summary</h3>
|
|
40
|
+
<dl id="batch-summary" class="kv-grid"></dl>
|
|
41
|
+
</section>
|
|
42
|
+
|
|
43
|
+
<section class="panel" aria-labelledby="wave-progress-heading">
|
|
44
|
+
<h3 id="wave-progress-heading">Wave progress</h3>
|
|
45
|
+
<p id="wave-progress-summary" class="wave-summary"></p>
|
|
46
|
+
<ol id="wave-list" class="wave-list"></ol>
|
|
47
|
+
</section>
|
|
48
|
+
|
|
49
|
+
<section class="panel panel-wide" aria-labelledby="lane-table-heading">
|
|
50
|
+
<h3 id="lane-table-heading">Lanes</h3>
|
|
51
|
+
<div class="table-wrap">
|
|
52
|
+
<table id="lane-table" class="lane-table">
|
|
53
|
+
<thead>
|
|
54
|
+
<tr>
|
|
55
|
+
<th scope="col">Lane</th>
|
|
56
|
+
<th scope="col">Status</th>
|
|
57
|
+
<th scope="col">Active tasks</th>
|
|
58
|
+
<th scope="col">Batch assignment</th>
|
|
59
|
+
<th scope="col">Heartbeat</th>
|
|
60
|
+
<th scope="col">Worktree</th>
|
|
61
|
+
</tr>
|
|
62
|
+
</thead>
|
|
63
|
+
<tbody id="lane-table-body"></tbody>
|
|
64
|
+
</table>
|
|
65
|
+
</div>
|
|
66
|
+
</section>
|
|
67
|
+
|
|
68
|
+
<section class="panel panel-wide" aria-labelledby="journal-heading">
|
|
69
|
+
<h3 id="journal-heading">Journal (last 20)</h3>
|
|
70
|
+
<ol id="journal-list" class="journal-list"></ol>
|
|
71
|
+
</section>
|
|
72
|
+
</main>
|
|
73
|
+
|
|
74
|
+
<footer class="page-footer">
|
|
75
|
+
<span id="snapshot-time" class="snapshot-time"></span>
|
|
76
|
+
</footer>
|
|
77
|
+
|
|
78
|
+
<script type="module" src="/dashboard.js"></script>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback-only dashboard HTTP server (PRD §16, SEC-04).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import http from "node:http";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { buildDashboardSnapshot } from "./snapshot.mjs";
|
|
10
|
+
import { formatSseDataFrame, writeSseHeaders } from "./sse.mjs";
|
|
11
|
+
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const PUBLIC_DIR = path.join(__dirname, "public");
|
|
14
|
+
|
|
15
|
+
export const DEFAULT_DASHBOARD_HOST = "127.0.0.1";
|
|
16
|
+
export const DEFAULT_DASHBOARD_PORT = 8109;
|
|
17
|
+
export const DEFAULT_DASHBOARD_POLL_MS = 2000;
|
|
18
|
+
|
|
19
|
+
const STATIC_ROUTES = {
|
|
20
|
+
"/": { file: "index.html", contentType: "text/html; charset=utf-8" },
|
|
21
|
+
"/dashboard.css": { file: "dashboard.css", contentType: "text/css; charset=utf-8" },
|
|
22
|
+
"/dashboard.js": { file: "dashboard.js", contentType: "text/javascript; charset=utf-8" },
|
|
23
|
+
"/view.mjs": { file: path.join("..", "view.mjs"), contentType: "text/javascript; charset=utf-8" },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} routePath
|
|
28
|
+
*/
|
|
29
|
+
export function resolveStaticAsset(routePath) {
|
|
30
|
+
const route = STATIC_ROUTES[routePath];
|
|
31
|
+
if (!route) return null;
|
|
32
|
+
const filePath = path.resolve(PUBLIC_DIR, route.file);
|
|
33
|
+
const allowedRoot = path.resolve(__dirname);
|
|
34
|
+
if (filePath !== allowedRoot && !filePath.startsWith(`${allowedRoot}${path.sep}`)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return { filePath, contentType: route.contentType };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {import("node:http").ServerResponse} res
|
|
42
|
+
* @param {string} routePath
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
export function serveStaticAsset(res, routePath) {
|
|
46
|
+
const asset = resolveStaticAsset(routePath);
|
|
47
|
+
if (!asset || !fs.existsSync(asset.filePath)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const body = fs.readFileSync(asset.filePath);
|
|
51
|
+
res.writeHead(200, { "Content-Type": asset.contentType });
|
|
52
|
+
res.end(body);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} host
|
|
58
|
+
*/
|
|
59
|
+
export function assertLoopbackHost(host) {
|
|
60
|
+
const normalized = String(host ?? "")
|
|
61
|
+
.trim()
|
|
62
|
+
.toLowerCase();
|
|
63
|
+
if (normalized !== "127.0.0.1" && normalized !== "localhost") {
|
|
64
|
+
throw new Error(`Dashboard must bind to loopback only (got ${host})`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {object} options
|
|
70
|
+
* @param {string} options.projectRoot
|
|
71
|
+
* @param {string} [options.host]
|
|
72
|
+
* @param {number} [options.port]
|
|
73
|
+
* @param {number} [options.pollIntervalMs]
|
|
74
|
+
*/
|
|
75
|
+
export function createDashboardServer({
|
|
76
|
+
projectRoot,
|
|
77
|
+
host = DEFAULT_DASHBOARD_HOST,
|
|
78
|
+
port = DEFAULT_DASHBOARD_PORT,
|
|
79
|
+
pollIntervalMs = DEFAULT_DASHBOARD_POLL_MS,
|
|
80
|
+
}) {
|
|
81
|
+
assertLoopbackHost(host);
|
|
82
|
+
|
|
83
|
+
/** @type {import("node:http").Server} */
|
|
84
|
+
const server = http.createServer((req, res) => {
|
|
85
|
+
const url = new URL(req.url ?? "/", `http://${host}:${port}`);
|
|
86
|
+
|
|
87
|
+
if (req.method === "GET" && serveStaticAsset(res, url.pathname)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (req.method === "GET" && url.pathname === "/api/snapshot") {
|
|
92
|
+
const snapshot = buildDashboardSnapshot(projectRoot);
|
|
93
|
+
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
|
|
94
|
+
res.end(JSON.stringify(snapshot));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (req.method === "GET" && url.pathname === "/api/events") {
|
|
99
|
+
writeSseHeaders(res);
|
|
100
|
+
let lastSerialized = "";
|
|
101
|
+
|
|
102
|
+
const pushSnapshot = () => {
|
|
103
|
+
if (res.writableEnded) return;
|
|
104
|
+
const snapshot = buildDashboardSnapshot(projectRoot);
|
|
105
|
+
const serialized = JSON.stringify(snapshot);
|
|
106
|
+
if (serialized !== lastSerialized) {
|
|
107
|
+
lastSerialized = serialized;
|
|
108
|
+
res.write(formatSseDataFrame(snapshot));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
pushSnapshot();
|
|
113
|
+
const timer = setInterval(pushSnapshot, pollIntervalMs);
|
|
114
|
+
req.on("close", () => {
|
|
115
|
+
clearInterval(timer);
|
|
116
|
+
if (!res.writableEnded) res.end();
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
|
122
|
+
res.end("Not found\n");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return server;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {object} options
|
|
130
|
+
* @param {import("node:http").Server} options.server
|
|
131
|
+
* @param {string} [options.host]
|
|
132
|
+
* @param {number} [options.port]
|
|
133
|
+
* @returns {Promise<{ url: string, host: string, port: number }>}
|
|
134
|
+
*/
|
|
135
|
+
export function listenDashboardServer({
|
|
136
|
+
server,
|
|
137
|
+
host = DEFAULT_DASHBOARD_HOST,
|
|
138
|
+
port = DEFAULT_DASHBOARD_PORT,
|
|
139
|
+
}) {
|
|
140
|
+
assertLoopbackHost(host);
|
|
141
|
+
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
server.once("error", reject);
|
|
144
|
+
server.listen(port, host, () => {
|
|
145
|
+
const address = server.address();
|
|
146
|
+
const resolvedPort =
|
|
147
|
+
typeof address === "object" && address ? address.port : port;
|
|
148
|
+
resolve({
|
|
149
|
+
host,
|
|
150
|
+
port: resolvedPort,
|
|
151
|
+
url: `http://${host === "localhost" ? "localhost" : host}:${resolvedPort}`,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|