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,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator verification CLIs (Phase exit audits).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
import { c, FAIL, OK } from "./shared.mjs";
|
|
11
|
+
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
|
|
14
|
+
/** Modules >500 LOC grandfathered until v2.3 split (FR-SHIP-02 partial — engine-lanes split done). */
|
|
15
|
+
export const PHASE23_GRANDFATHERED_OVER_500 = [
|
|
16
|
+
"src/batch/state.mjs",
|
|
17
|
+
"src/batch/worker-host.mjs",
|
|
18
|
+
"src/batch/reconcile.mjs",
|
|
19
|
+
"src/batch/detached-start.mjs",
|
|
20
|
+
"src/batch/review.mjs",
|
|
21
|
+
"src/batch/resume-multi-lanes.mjs",
|
|
22
|
+
"src/batch/resume.mjs",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const PHASE23_ENGINE_LANES_MAX = 500;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} projectRoot
|
|
29
|
+
*/
|
|
30
|
+
function listBatchModuleLineCounts(projectRoot) {
|
|
31
|
+
const batchDir = path.join(projectRoot, "src/batch");
|
|
32
|
+
if (!fs.existsSync(batchDir)) return [];
|
|
33
|
+
|
|
34
|
+
return fs
|
|
35
|
+
.readdirSync(batchDir)
|
|
36
|
+
.filter((name) => name.endsWith(".mjs"))
|
|
37
|
+
.map((name) => {
|
|
38
|
+
const relPath = path.posix.join("src/batch", name);
|
|
39
|
+
const absPath = path.join(batchDir, name);
|
|
40
|
+
const lines = fs.readFileSync(absPath, "utf-8").split(/\r?\n/).length;
|
|
41
|
+
return { relPath, lines };
|
|
42
|
+
})
|
|
43
|
+
.sort((left, right) => left.relPath.localeCompare(right.relPath));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {object} params
|
|
48
|
+
* @param {string} params.projectRoot
|
|
49
|
+
* @param {boolean} [params.skipTest]
|
|
50
|
+
*/
|
|
51
|
+
export function runPhase23ExitVerify({ projectRoot, skipTest = false }) {
|
|
52
|
+
/** @type {Array<{ id: string, ok: boolean, message: string }>} */
|
|
53
|
+
const checks = [];
|
|
54
|
+
|
|
55
|
+
if (!skipTest) {
|
|
56
|
+
const testResult = spawnSync("npm", ["run", "typecheck"], {
|
|
57
|
+
cwd: projectRoot,
|
|
58
|
+
encoding: "utf-8",
|
|
59
|
+
shell: true,
|
|
60
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
61
|
+
});
|
|
62
|
+
const typecheckOk = (testResult.status ?? 1) === 0;
|
|
63
|
+
checks.push({
|
|
64
|
+
id: "typecheck",
|
|
65
|
+
ok: typecheckOk,
|
|
66
|
+
message: typecheckOk
|
|
67
|
+
? "npm run typecheck passed"
|
|
68
|
+
: `npm run typecheck failed (exit ${testResult.status})`,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const stubTest = spawnSync("npm", ["test"], {
|
|
72
|
+
cwd: projectRoot,
|
|
73
|
+
encoding: "utf-8",
|
|
74
|
+
env: { ...process.env, SPINE_WORKER_STUB: "1" },
|
|
75
|
+
shell: true,
|
|
76
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
77
|
+
});
|
|
78
|
+
const stubOk = (stubTest.status ?? 1) === 0;
|
|
79
|
+
checks.push({
|
|
80
|
+
id: "stub-test",
|
|
81
|
+
ok: stubOk,
|
|
82
|
+
message: stubOk
|
|
83
|
+
? "SPINE_WORKER_STUB=1 npm test passed"
|
|
84
|
+
: `SPINE_WORKER_STUB=1 npm test failed (exit ${stubTest.status})`,
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
checks.push({
|
|
88
|
+
id: "stub-test",
|
|
89
|
+
ok: true,
|
|
90
|
+
message: "stub suite skipped (--skip-test)",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const modules = listBatchModuleLineCounts(projectRoot);
|
|
95
|
+
const engineLanes = modules.find((entry) => entry.relPath === "src/batch/engine-lanes.mjs");
|
|
96
|
+
const engineLanesOk = engineLanes != null && engineLanes.lines <= PHASE23_ENGINE_LANES_MAX;
|
|
97
|
+
checks.push({
|
|
98
|
+
id: "engine-lanes-loc",
|
|
99
|
+
ok: engineLanesOk,
|
|
100
|
+
message: engineLanesOk
|
|
101
|
+
? `engine-lanes.mjs within ${PHASE23_ENGINE_LANES_MAX} LOC (${engineLanes?.lines ?? 0})`
|
|
102
|
+
: `engine-lanes.mjs exceeds ${PHASE23_ENGINE_LANES_MAX} LOC (${engineLanes?.lines ?? "missing"})`,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const over500 = modules.filter((entry) => entry.lines > 500);
|
|
106
|
+
const ungrandfathered = over500.filter(
|
|
107
|
+
(entry) => !PHASE23_GRANDFATHERED_OVER_500.includes(entry.relPath),
|
|
108
|
+
);
|
|
109
|
+
const locPolicyOk = ungrandfathered.length === 0;
|
|
110
|
+
checks.push({
|
|
111
|
+
id: "batch-loc-policy",
|
|
112
|
+
ok: locPolicyOk,
|
|
113
|
+
message: locPolicyOk
|
|
114
|
+
? `batch module LOC policy ok (${over500.length} grandfathered >500)`
|
|
115
|
+
: `unexpected >500 LOC modules: ${ungrandfathered.map((entry) => `${entry.relPath} (${entry.lines})`).join(", ")}`,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const realPiWorkflow = path.join(projectRoot, ".github/workflows/real-pi.yml");
|
|
119
|
+
const realPiOk = fs.existsSync(realPiWorkflow);
|
|
120
|
+
checks.push({
|
|
121
|
+
id: "real-pi-workflow",
|
|
122
|
+
ok: realPiOk,
|
|
123
|
+
message: realPiOk
|
|
124
|
+
? ".github/workflows/real-pi.yml present"
|
|
125
|
+
: "real-pi workflow missing",
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const runbookPath = path.join(projectRoot, "docs/adoption/operator-runbook.md");
|
|
129
|
+
let runbookOk = fs.existsSync(runbookPath);
|
|
130
|
+
if (runbookOk) {
|
|
131
|
+
const runbook = fs.readFileSync(runbookPath, "utf-8");
|
|
132
|
+
runbookOk = /real-pi|SPINE_WORKER_STUB/i.test(runbook);
|
|
133
|
+
}
|
|
134
|
+
checks.push({
|
|
135
|
+
id: "real-pi-docs",
|
|
136
|
+
ok: runbookOk,
|
|
137
|
+
message: runbookOk
|
|
138
|
+
? "operator runbook documents real-pi / stub posture"
|
|
139
|
+
: "operator runbook missing real-pi skip guidance",
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const contextPath = path.join(projectRoot, "spine-tasks/CONTEXT.md");
|
|
143
|
+
let contextOk = fs.existsSync(contextPath);
|
|
144
|
+
if (contextOk) {
|
|
145
|
+
const context = fs.readFileSync(contextPath, "utf-8");
|
|
146
|
+
contextOk = /SP-205|Phase 23|Done/i.test(context);
|
|
147
|
+
}
|
|
148
|
+
checks.push({
|
|
149
|
+
id: "context-phase23",
|
|
150
|
+
ok: contextOk,
|
|
151
|
+
message: contextOk
|
|
152
|
+
? "CONTEXT.md references Phase 23 / SP-205+ status"
|
|
153
|
+
: "CONTEXT.md Phase 23 table not aligned",
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const readinessPath = path.join(projectRoot, "docs/adoption/real-project-readiness.md");
|
|
157
|
+
const readinessOk = fs.existsSync(readinessPath);
|
|
158
|
+
checks.push({
|
|
159
|
+
id: "readiness-doc",
|
|
160
|
+
ok: readinessOk,
|
|
161
|
+
message: readinessOk
|
|
162
|
+
? "docs/adoption/real-project-readiness.md present"
|
|
163
|
+
: "real-project-readiness.md missing (note path change in CONTEXT if relocated)",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const ok = checks.every((check) => check.ok);
|
|
167
|
+
return { ok, checks, exitCode: ok ? 0 : 1 };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {object} params
|
|
172
|
+
* @param {string} params.projectRoot
|
|
173
|
+
* @param {string[]} params.args
|
|
174
|
+
*/
|
|
175
|
+
export function runSpineVerify({ projectRoot, args }) {
|
|
176
|
+
const sub = args[0];
|
|
177
|
+
if (sub !== "phase23-exit") {
|
|
178
|
+
return {
|
|
179
|
+
exitCode: 1,
|
|
180
|
+
output: `Usage: spine verify phase23-exit [--skip-test] [--json]\n`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const skipTest = args.includes("--skip-test");
|
|
185
|
+
const json = args.includes("--json");
|
|
186
|
+
const result = runPhase23ExitVerify({ projectRoot, skipTest });
|
|
187
|
+
|
|
188
|
+
if (json) {
|
|
189
|
+
return { exitCode: result.exitCode, output: `${JSON.stringify(result, null, 2)}\n` };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const lines = ["", `${c.bold}Phase 23 exit verification${c.reset}`, ""];
|
|
193
|
+
for (const check of result.checks) {
|
|
194
|
+
const icon = check.ok ? OK : FAIL;
|
|
195
|
+
lines.push(` ${icon} ${check.message}`);
|
|
196
|
+
}
|
|
197
|
+
lines.push("", result.ok ? `${OK} Phase 23 exit criteria satisfied` : `${FAIL} Phase 23 exit criteria failed`, "");
|
|
198
|
+
return { exitCode: result.exitCode, output: lines.join("\n") };
|
|
199
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { applyEnvOverrides } from "../src/config/env-overrides.mjs";
|
|
5
|
+
import { applyConfigDefaults } from "../src/config/merge-defaults.mjs";
|
|
6
|
+
import { validateContractConfig } from "../src/config/contract.mjs";
|
|
7
|
+
import { validateWorkerBackendConfig } from "../src/config/worker-backend.mjs";
|
|
8
|
+
import { validateWorkerContextConfig } from "../src/config/worker-context.mjs";
|
|
9
|
+
import { validateWorkerLaunchScriptConfig } from "../src/config/worker-launch-script.mjs";
|
|
10
|
+
import { validateWorktreeSetupHookConfig } from "../src/config/worktree-setup-hook.mjs";
|
|
11
|
+
|
|
12
|
+
const REQUIRED_TOP_LEVEL = [
|
|
13
|
+
"configVersion",
|
|
14
|
+
"project",
|
|
15
|
+
"paths",
|
|
16
|
+
"baseBranch",
|
|
17
|
+
"testing",
|
|
18
|
+
"agents",
|
|
19
|
+
"lanes",
|
|
20
|
+
"gates",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Load spine-config.json from disk only (no FR-CFG-04 env overrides).
|
|
25
|
+
* Use for persistence paths (e.g. settings set) so env values are not written to file.
|
|
26
|
+
*/
|
|
27
|
+
export function loadSpineConfigFile(projectRoot) {
|
|
28
|
+
const configPath = path.join(projectRoot, ".spine", "spine-config.json");
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync(configPath)) {
|
|
31
|
+
return {
|
|
32
|
+
configPath,
|
|
33
|
+
config: null,
|
|
34
|
+
error: {
|
|
35
|
+
code: "CONFIG_MISSING",
|
|
36
|
+
message: ".spine/spine-config.json not found",
|
|
37
|
+
suggestedCommand: "spine init",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return {
|
|
47
|
+
configPath,
|
|
48
|
+
config: null,
|
|
49
|
+
error: {
|
|
50
|
+
code: "CONFIG_PARSE_ERROR",
|
|
51
|
+
message: `Cannot parse spine config: ${err.message}`,
|
|
52
|
+
suggestedCommand: "spine init --force",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const validationError = validateSpineConfig(parsed);
|
|
58
|
+
if (validationError) {
|
|
59
|
+
return {
|
|
60
|
+
configPath,
|
|
61
|
+
config: null,
|
|
62
|
+
error: validationError,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
configPath,
|
|
68
|
+
config: parsed,
|
|
69
|
+
error: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Load config with FR-CFG-04 env overrides applied (precedence: env > file).
|
|
75
|
+
*/
|
|
76
|
+
export function loadSpineConfig(projectRoot) {
|
|
77
|
+
const fileResult = loadSpineConfigFile(projectRoot);
|
|
78
|
+
if (fileResult.error) {
|
|
79
|
+
return fileResult;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const config = structuredClone(fileResult.config);
|
|
83
|
+
applyConfigDefaults(config);
|
|
84
|
+
|
|
85
|
+
const contractError = validateContractConfig(config);
|
|
86
|
+
if (contractError) {
|
|
87
|
+
return {
|
|
88
|
+
configPath: fileResult.configPath,
|
|
89
|
+
config: null,
|
|
90
|
+
error: contractError,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const envResult = applyEnvOverrides(config, projectRoot);
|
|
95
|
+
if (!envResult.ok) {
|
|
96
|
+
return {
|
|
97
|
+
configPath: fileResult.configPath,
|
|
98
|
+
config: null,
|
|
99
|
+
error: envResult.error,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
configPath: fileResult.configPath,
|
|
105
|
+
config: envResult.config,
|
|
106
|
+
fileConfig: config,
|
|
107
|
+
sources: envResult.sources,
|
|
108
|
+
envVars: envResult.envVars,
|
|
109
|
+
error: null,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function validateSpineConfig(config) {
|
|
114
|
+
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
115
|
+
return {
|
|
116
|
+
code: "CONFIG_SCHEMA_INVALID",
|
|
117
|
+
message: "spine-config.json must be a JSON object",
|
|
118
|
+
suggestedCommand: "spine init --force",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (config.configVersion !== 1) {
|
|
123
|
+
return {
|
|
124
|
+
code: "CONFIG_VERSION_UNSUPPORTED",
|
|
125
|
+
message: `configVersion must be 1 (found ${config.configVersion ?? "missing"})`,
|
|
126
|
+
suggestedCommand: "spine migrate-from-taskplane",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const key of REQUIRED_TOP_LEVEL) {
|
|
131
|
+
if (!(key in config)) {
|
|
132
|
+
return {
|
|
133
|
+
code: "CONFIG_SCHEMA_INVALID",
|
|
134
|
+
message: `Missing required field: ${key}`,
|
|
135
|
+
suggestedCommand: "spine init --force",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (typeof config.paths?.tasksRoot !== "string" || config.paths.tasksRoot.trim() === "") {
|
|
141
|
+
return {
|
|
142
|
+
code: "CONFIG_TASKS_ROOT_INVALID",
|
|
143
|
+
message: "paths.tasksRoot must be a non-empty string",
|
|
144
|
+
suggestedCommand: "spine init",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (typeof config.lanes?.maxParallel !== "number" || config.lanes.maxParallel < 1) {
|
|
149
|
+
return {
|
|
150
|
+
code: "CONFIG_LANES_INVALID",
|
|
151
|
+
message: "lanes.maxParallel must be a number >= 1",
|
|
152
|
+
suggestedCommand: "/spine-settings",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const workerBackendError = validateWorkerBackendConfig(config);
|
|
157
|
+
if (workerBackendError) {
|
|
158
|
+
return workerBackendError;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const workerContextError = validateWorkerContextConfig(config);
|
|
162
|
+
if (workerContextError) {
|
|
163
|
+
return workerContextError;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const launchScriptError = validateWorkerLaunchScriptConfig(config);
|
|
167
|
+
if (launchScriptError) {
|
|
168
|
+
return launchScriptError;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const setupHookError = validateWorktreeSetupHookConfig(config);
|
|
172
|
+
if (setupHookError) {
|
|
173
|
+
return setupHookError;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (config.worktreeSetupIgnorePaths != null) {
|
|
177
|
+
if (!Array.isArray(config.worktreeSetupIgnorePaths)) {
|
|
178
|
+
return {
|
|
179
|
+
code: "CONFIG_SETUP_IGNORE_INVALID",
|
|
180
|
+
message: "worktreeSetupIgnorePaths must be an array of strings when set",
|
|
181
|
+
suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
for (const entry of config.worktreeSetupIgnorePaths) {
|
|
185
|
+
if (typeof entry !== "string" || !entry.trim()) {
|
|
186
|
+
return {
|
|
187
|
+
code: "CONFIG_SETUP_IGNORE_INVALID",
|
|
188
|
+
message: "worktreeSetupIgnorePaths entries must be non-empty strings",
|
|
189
|
+
suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (
|
|
196
|
+
config.lanes?.autoCommitOnStall != null &&
|
|
197
|
+
typeof config.lanes.autoCommitOnStall !== "boolean"
|
|
198
|
+
) {
|
|
199
|
+
return {
|
|
200
|
+
code: "CONFIG_LANES_INVALID",
|
|
201
|
+
message: "lanes.autoCommitOnStall must be a boolean when set",
|
|
202
|
+
suggestedCommand: "spine settings set lanes.autoCommitOnStall false",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const contractError = validateContractConfig(config);
|
|
207
|
+
if (contractError) {
|
|
208
|
+
return contractError;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* pi-spine dashboard CLI (PRD §16).
|
|
4
|
+
* Usage: spine dashboard [--json] [--port N] [--host 127.0.0.1]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { loadSpineConfig } from "./spine-config.mjs";
|
|
8
|
+
import { buildDashboardSnapshot } from "../src/dashboard/snapshot.mjs";
|
|
9
|
+
import {
|
|
10
|
+
assertLoopbackHost,
|
|
11
|
+
createDashboardServer,
|
|
12
|
+
DEFAULT_DASHBOARD_HOST,
|
|
13
|
+
DEFAULT_DASHBOARD_PORT,
|
|
14
|
+
listenDashboardServer,
|
|
15
|
+
} from "../src/dashboard/server.mjs";
|
|
16
|
+
|
|
17
|
+
export { DEFAULT_DASHBOARD_HOST, DEFAULT_DASHBOARD_PORT };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {"cli"|"config"|"default"} portSource
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function formatPortSourceNote(portSource) {
|
|
24
|
+
if (portSource === "cli") {
|
|
25
|
+
return " (--port)";
|
|
26
|
+
}
|
|
27
|
+
if (portSource === "config") {
|
|
28
|
+
return " (dashboard.port in .spine/spine-config.json)";
|
|
29
|
+
}
|
|
30
|
+
return " (default)";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} projectRoot
|
|
35
|
+
* @param {number|undefined} cliPort
|
|
36
|
+
* @returns {{ port: number, portSource: "cli"|"config"|"default" }}
|
|
37
|
+
*/
|
|
38
|
+
export function resolveDashboardPortWithSource(projectRoot, cliPort) {
|
|
39
|
+
if (cliPort != null && !Number.isNaN(cliPort)) {
|
|
40
|
+
return { port: cliPort, portSource: "cli" };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
44
|
+
const fromConfig = configResult.config?.dashboard?.port;
|
|
45
|
+
if (fromConfig != null && !Number.isNaN(Number(fromConfig))) {
|
|
46
|
+
return { port: Number(fromConfig), portSource: "config" };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { port: DEFAULT_DASHBOARD_PORT, portSource: "default" };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {string} projectRoot
|
|
54
|
+
* @param {number|undefined} cliPort
|
|
55
|
+
*/
|
|
56
|
+
export function resolveDashboardPort(projectRoot, cliPort) {
|
|
57
|
+
return resolveDashboardPortWithSource(projectRoot, cliPort).port;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Taskplane-style operator block printed as soon as the dashboard is listening.
|
|
62
|
+
*
|
|
63
|
+
* @param {object} options
|
|
64
|
+
* @param {string} options.url
|
|
65
|
+
* @param {string} options.host
|
|
66
|
+
* @param {number} options.port
|
|
67
|
+
* @param {string} [options.projectRoot]
|
|
68
|
+
* @param {"cli"|"config"|"default"} [options.portSource]
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
export function formatDashboardStartupMessage({
|
|
72
|
+
url,
|
|
73
|
+
host,
|
|
74
|
+
port,
|
|
75
|
+
portSource = "default",
|
|
76
|
+
}) {
|
|
77
|
+
const base = url.endsWith("/") ? url.slice(0, -1) : url;
|
|
78
|
+
const portNote = formatPortSourceNote(portSource);
|
|
79
|
+
const browserUrl = `${base}/`;
|
|
80
|
+
|
|
81
|
+
const lines = [
|
|
82
|
+
"",
|
|
83
|
+
"pi-spine dashboard",
|
|
84
|
+
"",
|
|
85
|
+
` Open in browser: ${browserUrl}`,
|
|
86
|
+
` Listen: ${host}:${port}${portNote}`,
|
|
87
|
+
"",
|
|
88
|
+
" While running: keep this terminal open; dashboard updates via SSE (~2s)",
|
|
89
|
+
"",
|
|
90
|
+
" In another terminal:",
|
|
91
|
+
" spine status",
|
|
92
|
+
" spine batch start <task-id>",
|
|
93
|
+
"",
|
|
94
|
+
` → Open ${browserUrl} in your browser`,
|
|
95
|
+
"",
|
|
96
|
+
` API: ${base}/api/snapshot`,
|
|
97
|
+
` ${base}/api/events`,
|
|
98
|
+
"",
|
|
99
|
+
" Stop: Ctrl+C",
|
|
100
|
+
"",
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
return lines.join("\n");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Pi notify text for /spine-dashboard (background spawn).
|
|
108
|
+
*
|
|
109
|
+
* @param {object} options
|
|
110
|
+
* @param {string} options.host
|
|
111
|
+
* @param {number} options.port
|
|
112
|
+
* @param {"cli"|"config"|"default"} [options.portSource]
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
export function formatDashboardNotifyMessage({ host, port, portSource = "default" }) {
|
|
116
|
+
const browserUrl = `http://${host}:${port}/`;
|
|
117
|
+
const portHint =
|
|
118
|
+
portSource === "cli"
|
|
119
|
+
? " · this launch used --port"
|
|
120
|
+
: " · configure port in `.spine/spine-config.json` (`dashboard.port`, default 8109)";
|
|
121
|
+
|
|
122
|
+
return `pi-spine dashboard starting in the background.
|
|
123
|
+
|
|
124
|
+
Open in browser: ${browserUrl}
|
|
125
|
+
|
|
126
|
+
CLI: \`spine dashboard\`${portHint}.`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {object} options
|
|
131
|
+
* @param {string} options.projectRoot
|
|
132
|
+
* @param {string[]} [options.args]
|
|
133
|
+
*/
|
|
134
|
+
export async function runSpineDashboard({ projectRoot, args = [] }) {
|
|
135
|
+
const json = args.includes("--json");
|
|
136
|
+
const hostIdx = args.indexOf("--host");
|
|
137
|
+
const portIdx = args.indexOf("--port");
|
|
138
|
+
|
|
139
|
+
const host =
|
|
140
|
+
hostIdx >= 0 && args[hostIdx + 1] ? String(args[hostIdx + 1]) : DEFAULT_DASHBOARD_HOST;
|
|
141
|
+
const cliPort =
|
|
142
|
+
portIdx >= 0 && args[portIdx + 1] ? Number(args[portIdx + 1]) : undefined;
|
|
143
|
+
const { port, portSource } = resolveDashboardPortWithSource(projectRoot, cliPort);
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
assertLoopbackHost(host);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
return {
|
|
149
|
+
exitCode: 1,
|
|
150
|
+
output: `${err instanceof Error ? err.message : String(err)}\n`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (json) {
|
|
155
|
+
const snapshot = buildDashboardSnapshot(projectRoot);
|
|
156
|
+
return {
|
|
157
|
+
exitCode: 0,
|
|
158
|
+
output: `${JSON.stringify(snapshot, null, 2)}\n`,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const server = createDashboardServer({ projectRoot, host, port });
|
|
163
|
+
const { url } = await listenDashboardServer({ server, host, port });
|
|
164
|
+
|
|
165
|
+
process.stdout.write(
|
|
166
|
+
`${formatDashboardStartupMessage({ url, host, port, projectRoot, portSource })}\n`,
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
await new Promise((resolve) => {
|
|
170
|
+
const shutdown = () => {
|
|
171
|
+
server.close(() => resolve());
|
|
172
|
+
};
|
|
173
|
+
process.once("SIGINT", shutdown);
|
|
174
|
+
process.once("SIGTERM", shutdown);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return { exitCode: 0, output: "\nDashboard stopped.\n" };
|
|
178
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* spine deps
|
|
4
|
+
*
|
|
5
|
+
* Inspect task dependency graph without running a full batch plan.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { isCliEntrypoint } from './spine-cli/shared.mjs';
|
|
11
|
+
import { loadSpineConfig } from './spine-config.mjs';
|
|
12
|
+
import { buildDepsReport, formatDepsHuman } from '../src/cli/deps.mjs';
|
|
13
|
+
|
|
14
|
+
export async function runSpineDeps({
|
|
15
|
+
projectRoot = process.cwd(),
|
|
16
|
+
scope = 'all',
|
|
17
|
+
json = false,
|
|
18
|
+
} = {}) {
|
|
19
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
20
|
+
if (configResult.error) {
|
|
21
|
+
const err = new Error(configResult.error.message);
|
|
22
|
+
err.suggestedCommand = configResult.error.suggestedCommand;
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const report = buildDepsReport({
|
|
27
|
+
projectRoot,
|
|
28
|
+
scope,
|
|
29
|
+
config: configResult.config,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (json) {
|
|
33
|
+
return {
|
|
34
|
+
report,
|
|
35
|
+
exitCode: report.cycles.length > 0 ? 1 : 0,
|
|
36
|
+
output: JSON.stringify(report, null, 2) + '\n',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
report,
|
|
42
|
+
exitCode: report.cycles.length > 0 ? 1 : 0,
|
|
43
|
+
output: formatDepsHuman(report),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function main() {
|
|
48
|
+
const argv = process.argv.slice(2);
|
|
49
|
+
const json = argv.includes('--json');
|
|
50
|
+
const scope = argv.filter((a) => !a.startsWith('--')).join(' ') || 'all';
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const { output, exitCode } = await runSpineDeps({ projectRoot: process.cwd(), scope, json });
|
|
54
|
+
process.stdout.write(output);
|
|
55
|
+
if (exitCode !== 0) process.exit(exitCode);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
const msg = err?.message ?? String(err);
|
|
58
|
+
if (err?.suggestedCommand) {
|
|
59
|
+
console.error(`Error: ${msg}\nSuggested: ${err.suggestedCommand}`);
|
|
60
|
+
} else {
|
|
61
|
+
console.error(`Error: ${msg}`);
|
|
62
|
+
}
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
68
|
+
main();
|
|
69
|
+
}
|