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,700 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { loadSpineConfig } from "./spine-config.mjs";
|
|
5
|
+
import { resolveTasksRootPath } from "../src/config/env-overrides.mjs";
|
|
6
|
+
import { runDoctorChecks } from "./spine.mjs";
|
|
7
|
+
import { runReconciliationCheck } from "../src/batch/reconcile.mjs";
|
|
8
|
+
import { buildPlan } from "../src/planner/index.mjs";
|
|
9
|
+
import { formatPlanHuman } from "./spine-plan.mjs";
|
|
10
|
+
import { buildCoexistencePreflightCheck } from "../src/doctor/coexistence.mjs";
|
|
11
|
+
import { validatePiSpineRootConfig } from "../src/config/pi-spine-root.mjs";
|
|
12
|
+
import { resolveSafeWorkerLaunchScript } from "../src/config/worker-launch-script.mjs";
|
|
13
|
+
import { validateWorktreeSetupHookConfig } from "../src/config/worktree-setup-hook.mjs";
|
|
14
|
+
import {
|
|
15
|
+
isRulesManifestGeneratedAtOnlyDrift,
|
|
16
|
+
RULES_MANIFEST_REL_PATH,
|
|
17
|
+
} from "../src/config/cursor-rules/discover.mjs";
|
|
18
|
+
import { discoverTasks } from "../src/tasks/packet/discover.mjs";
|
|
19
|
+
import { NO_PENDING_TASKS_ERROR } from "../src/planner/scope.mjs";
|
|
20
|
+
import { summarizePendingScope } from "../src/planner/pending.mjs";
|
|
21
|
+
import { validatePrompt } from "../src/tasks/packet/validate-prompt.mjs";
|
|
22
|
+
|
|
23
|
+
const HEALTHY_ACTIVE_PHASES = new Set(["planning", "running", "paused"]);
|
|
24
|
+
const LIMBO_DIAGNOSES = new Set(["limbo_stale", "completed_manual"]);
|
|
25
|
+
const DEPENDENCIES_SCHEMA_VERSION = 1;
|
|
26
|
+
const TASK_ID_PATTERN = /^[A-Z]{2,}-\d{3,}$/;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} ctx
|
|
30
|
+
* @param {string} ctx.projectRoot
|
|
31
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
32
|
+
*/
|
|
33
|
+
export function resolveTasksRoot(projectRoot, configResult) {
|
|
34
|
+
const loaded = configResult ?? loadSpineConfig(projectRoot);
|
|
35
|
+
if (!loaded.config) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return resolveTasksRootPath(projectRoot, loaded.config);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isInsideGitRepo(dir) {
|
|
42
|
+
try {
|
|
43
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
44
|
+
cwd: dir,
|
|
45
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
46
|
+
timeout: 5000,
|
|
47
|
+
});
|
|
48
|
+
return true;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function taskIdFromFolder(folderName) {
|
|
55
|
+
const match = String(folderName).match(/^([A-Z]{2,}-\d{3,})/);
|
|
56
|
+
return match?.[1] ?? null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function discoverTaskFolders(tasksRootPath) {
|
|
60
|
+
if (!tasksRootPath || !fs.existsSync(tasksRootPath)) return [];
|
|
61
|
+
|
|
62
|
+
return fs
|
|
63
|
+
.readdirSync(tasksRootPath, { withFileTypes: true })
|
|
64
|
+
.filter((entry) => entry.isDirectory())
|
|
65
|
+
.map((entry) => entry.name)
|
|
66
|
+
.filter((name) => fs.existsSync(path.join(tasksRootPath, name, "PROMPT.md")))
|
|
67
|
+
.sort();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function discoverTaskIds(tasksRootPath) {
|
|
71
|
+
return [...new Set(discoverTaskFolders(tasksRootPath).map(taskIdFromFolder).filter(Boolean))].sort();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveBatchStatePath(projectRoot) {
|
|
75
|
+
const spinePath = path.join(projectRoot, ".spine", "batch-state.json");
|
|
76
|
+
if (fs.existsSync(spinePath)) return spinePath;
|
|
77
|
+
|
|
78
|
+
const piPath = path.join(projectRoot, ".pi", "batch-state.json");
|
|
79
|
+
if (fs.existsSync(piPath)) return piPath;
|
|
80
|
+
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function loadBatchState(batchStatePath) {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(fs.readFileSync(batchStatePath, "utf-8"));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
return { parseError: err.message };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isHealthyActiveBatch(batchState) {
|
|
93
|
+
if (!batchState || batchState.parseError) return false;
|
|
94
|
+
const phase = batchState.phase ?? batchState.status;
|
|
95
|
+
if (phase && HEALTHY_ACTIVE_PHASES.has(String(phase))) return true;
|
|
96
|
+
if (batchState.endedAt == null && batchState.batchId) return true;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function makeCheck(id, ok, message, extra = {}) {
|
|
101
|
+
return { id, ok, message, ...extra };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {object} ctx
|
|
106
|
+
* @param {string} ctx.projectRoot
|
|
107
|
+
* @param {() => ReturnType<typeof runDoctorChecks>} [ctx.runDoctor]
|
|
108
|
+
*/
|
|
109
|
+
export function checkDoctor(ctx) {
|
|
110
|
+
const runDoctor = ctx.runDoctor ?? (() => runDoctorChecks(ctx.projectRoot));
|
|
111
|
+
const doctor = runDoctor();
|
|
112
|
+
if (doctor.ok) {
|
|
113
|
+
return makeCheck("doctor", true, "spine doctor passed");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const failed = doctor.checks.filter((entry) => !entry.ok).map((entry) => entry.label);
|
|
117
|
+
return makeCheck("doctor", false, `spine doctor failed (${doctor.issueCount} issue(s))`, {
|
|
118
|
+
details: { failedChecks: failed, checks: doctor.checks },
|
|
119
|
+
suggestedCommand: "spine doctor",
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @param {object} ctx
|
|
125
|
+
* @param {string} ctx.projectRoot
|
|
126
|
+
*/
|
|
127
|
+
export function checkGitClean(ctx) {
|
|
128
|
+
if (!isInsideGitRepo(ctx.projectRoot)) {
|
|
129
|
+
return makeCheck("git-clean", false, "not inside a git repository", {
|
|
130
|
+
suggestedCommand: "git init",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let output = "";
|
|
135
|
+
try {
|
|
136
|
+
output = execFileSync("git", ["status", "--porcelain"], {
|
|
137
|
+
cwd: ctx.projectRoot,
|
|
138
|
+
encoding: "utf-8",
|
|
139
|
+
timeout: 5000,
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
return makeCheck("git-clean", false, `git status failed: ${err.message}`, {
|
|
143
|
+
suggestedCommand: "git status",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const dirtyPaths = output
|
|
148
|
+
.split(/\r?\n/)
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.map((line) => line.slice(3).trim() || line.trim());
|
|
151
|
+
|
|
152
|
+
if (dirtyPaths.length === 0) {
|
|
153
|
+
return makeCheck("git-clean", true, "working tree clean");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const manifestDrift = isRulesManifestGeneratedAtOnlyDrift(ctx.projectRoot, dirtyPaths);
|
|
157
|
+
if (manifestDrift.ok) {
|
|
158
|
+
return makeCheck(
|
|
159
|
+
"git-clean",
|
|
160
|
+
true,
|
|
161
|
+
`working tree clean (${RULES_MANIFEST_REL_PATH} generatedAt-only drift ignored)`,
|
|
162
|
+
{
|
|
163
|
+
details: {
|
|
164
|
+
manifestGeneratedAtDrift: true,
|
|
165
|
+
manifestPath: manifestDrift.manifestPath,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const listed = dirtyPaths.slice(0, 20);
|
|
172
|
+
const suffix =
|
|
173
|
+
dirtyPaths.length > listed.length ? ` (+${dirtyPaths.length - listed.length} more)` : "";
|
|
174
|
+
|
|
175
|
+
return makeCheck(
|
|
176
|
+
"git-clean",
|
|
177
|
+
false,
|
|
178
|
+
`working tree has ${dirtyPaths.length} uncommitted change(s)${suffix}`,
|
|
179
|
+
{
|
|
180
|
+
details: { dirtyPaths: listed, totalDirty: dirtyPaths.length },
|
|
181
|
+
suggestedCommand: "git status",
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {object} ctx
|
|
188
|
+
* @param {string} ctx.projectRoot
|
|
189
|
+
* @param {typeof runReconciliationCheck} [ctx.runReconciliation]
|
|
190
|
+
*/
|
|
191
|
+
export function checkNoActiveBatch(ctx) {
|
|
192
|
+
const batchStatePath = resolveBatchStatePath(ctx.projectRoot);
|
|
193
|
+
if (!batchStatePath) {
|
|
194
|
+
return makeCheck("no-active-batch", true, "no active batch state file");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const batchState = loadBatchState(batchStatePath);
|
|
198
|
+
if (batchState.parseError) {
|
|
199
|
+
return makeCheck("no-active-batch", false, `cannot parse batch state: ${batchState.parseError}`, {
|
|
200
|
+
details: { batchStatePath: path.relative(ctx.projectRoot, batchStatePath) },
|
|
201
|
+
suggestedCommand: "spine status --diagnose",
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const reconcile = ctx.runReconciliation ?? runReconciliationCheck;
|
|
206
|
+
const reconciliation = reconcile({
|
|
207
|
+
projectRoot: ctx.projectRoot,
|
|
208
|
+
batchState,
|
|
209
|
+
batchStatePath,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (LIMBO_DIAGNOSES.has(reconciliation.diagnosis)) {
|
|
213
|
+
return makeCheck(
|
|
214
|
+
"no-active-batch",
|
|
215
|
+
false,
|
|
216
|
+
reconciliation.headline ?? "stale batch requires dismissal",
|
|
217
|
+
{
|
|
218
|
+
details: {
|
|
219
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
220
|
+
diagnosis: reconciliation.diagnosis,
|
|
221
|
+
batchId: batchState.batchId ?? batchState.id ?? null,
|
|
222
|
+
headline: reconciliation.headline,
|
|
223
|
+
},
|
|
224
|
+
suggestedCommand: reconciliation.suggestedCommand ?? "spine batch dismiss",
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (reconciliation.diagnosis === "running") {
|
|
230
|
+
const batchId = batchState.batchId ?? batchState.id ?? "unknown";
|
|
231
|
+
return makeCheck(
|
|
232
|
+
"no-active-batch",
|
|
233
|
+
false,
|
|
234
|
+
reconciliation.headline ?? `batch ${batchId} is running`,
|
|
235
|
+
{
|
|
236
|
+
details: {
|
|
237
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
238
|
+
diagnosis: reconciliation.diagnosis,
|
|
239
|
+
batchId,
|
|
240
|
+
headline: reconciliation.headline,
|
|
241
|
+
},
|
|
242
|
+
suggestedCommand: reconciliation.suggestedCommand ?? "/spine-status --diagnose",
|
|
243
|
+
},
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (reconciliation.diagnosis === "paused") {
|
|
248
|
+
const batchId = batchState.batchId ?? batchState.id ?? "unknown";
|
|
249
|
+
return makeCheck(
|
|
250
|
+
"no-active-batch",
|
|
251
|
+
false,
|
|
252
|
+
reconciliation.headline ?? `batch ${batchId} is paused`,
|
|
253
|
+
{
|
|
254
|
+
details: {
|
|
255
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
256
|
+
diagnosis: reconciliation.diagnosis,
|
|
257
|
+
batchId,
|
|
258
|
+
headline: reconciliation.headline,
|
|
259
|
+
},
|
|
260
|
+
suggestedCommand: reconciliation.suggestedCommand ?? "/spine-resume --force",
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (isHealthyActiveBatch(batchState)) {
|
|
266
|
+
const batchId = batchState.batchId ?? batchState.id ?? "unknown";
|
|
267
|
+
const phase = batchState.phase ?? batchState.status ?? "unknown";
|
|
268
|
+
return makeCheck(
|
|
269
|
+
"no-active-batch",
|
|
270
|
+
false,
|
|
271
|
+
`healthy active batch ${batchId} (phase: ${phase})`,
|
|
272
|
+
{
|
|
273
|
+
details: {
|
|
274
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
275
|
+
batchId,
|
|
276
|
+
phase,
|
|
277
|
+
},
|
|
278
|
+
suggestedCommand: reconciliation.suggestedCommand ?? "spine status --diagnose",
|
|
279
|
+
},
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return makeCheck(
|
|
284
|
+
"no-active-batch",
|
|
285
|
+
false,
|
|
286
|
+
reconciliation.headline ?? "batch state file present",
|
|
287
|
+
{
|
|
288
|
+
details: {
|
|
289
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
290
|
+
diagnosis: reconciliation.diagnosis,
|
|
291
|
+
batchId: batchState.batchId ?? batchState.id ?? null,
|
|
292
|
+
},
|
|
293
|
+
suggestedCommand: reconciliation.suggestedCommand ?? "spine status --diagnose",
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @param {object} ctx
|
|
300
|
+
* @param {string} ctx.projectRoot
|
|
301
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
302
|
+
*/
|
|
303
|
+
export function checkPiSpineRoot(ctx) {
|
|
304
|
+
const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
|
|
305
|
+
const config = configResult?.config;
|
|
306
|
+
|
|
307
|
+
if (!config || configResult?.error) {
|
|
308
|
+
return makeCheck("pi-spine-root", true, "pi-spine root check skipped (config unavailable)");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const launchScript = resolveSafeWorkerLaunchScript(ctx.projectRoot, config);
|
|
312
|
+
const overrideConfigured = Boolean(config?.development?.piSpineRoot);
|
|
313
|
+
if (!launchScript && !overrideConfigured) {
|
|
314
|
+
return makeCheck("pi-spine-root", true, "pi-spine root not required (no custom worker launch script)");
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const validationError = validatePiSpineRootConfig(config, ctx.projectRoot);
|
|
318
|
+
if (validationError) {
|
|
319
|
+
return makeCheck("pi-spine-root", false, validationError.message, {
|
|
320
|
+
suggestedCommand: validationError.suggestedCommand,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return makeCheck(
|
|
325
|
+
"pi-spine-root",
|
|
326
|
+
true,
|
|
327
|
+
launchScript
|
|
328
|
+
? "pi-spine root valid for custom worker launch script"
|
|
329
|
+
: "development.piSpineRoot override valid",
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @param {object} ctx
|
|
335
|
+
* @param {string} ctx.projectRoot
|
|
336
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
337
|
+
*/
|
|
338
|
+
export function checkTasksRoot(ctx) {
|
|
339
|
+
const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
|
|
340
|
+
const tasksRootPath = resolveTasksRoot(ctx.projectRoot, configResult);
|
|
341
|
+
|
|
342
|
+
if (!tasksRootPath) {
|
|
343
|
+
return makeCheck("tasks-root", false, "tasks root not configured", {
|
|
344
|
+
suggestedCommand: "spine init",
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!fs.existsSync(tasksRootPath)) {
|
|
349
|
+
return makeCheck(
|
|
350
|
+
"tasks-root",
|
|
351
|
+
false,
|
|
352
|
+
`tasks root missing: ${path.relative(ctx.projectRoot, tasksRootPath)}`,
|
|
353
|
+
{
|
|
354
|
+
suggestedCommand: `mkdir -p ${path.relative(ctx.projectRoot, tasksRootPath)}`,
|
|
355
|
+
},
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const taskFolders = discoverTaskFolders(tasksRootPath);
|
|
360
|
+
if (taskFolders.length === 0) {
|
|
361
|
+
return makeCheck("tasks-root", false, "no discoverable task folders (PROMPT.md)", {
|
|
362
|
+
details: { tasksRootPath: path.relative(ctx.projectRoot, tasksRootPath) },
|
|
363
|
+
suggestedCommand: "spine init",
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return makeCheck(
|
|
368
|
+
"tasks-root",
|
|
369
|
+
true,
|
|
370
|
+
`tasks root valid (${taskFolders.length} task folder(s))`,
|
|
371
|
+
{
|
|
372
|
+
details: {
|
|
373
|
+
tasksRootPath: path.relative(ctx.projectRoot, tasksRootPath),
|
|
374
|
+
taskFolders,
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @param {object} ctx
|
|
382
|
+
* @param {string} ctx.projectRoot
|
|
383
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
384
|
+
*/
|
|
385
|
+
export function checkDependenciesJson(ctx) {
|
|
386
|
+
const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
|
|
387
|
+
const tasksRootPath = resolveTasksRoot(ctx.projectRoot, configResult);
|
|
388
|
+
|
|
389
|
+
if (!tasksRootPath) {
|
|
390
|
+
return makeCheck("dependencies-json", false, "tasks root not configured", {
|
|
391
|
+
suggestedCommand: "spine init",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const depsPath = path.join(tasksRootPath, "dependencies.json");
|
|
396
|
+
if (!fs.existsSync(depsPath)) {
|
|
397
|
+
return makeCheck(
|
|
398
|
+
"dependencies-json",
|
|
399
|
+
false,
|
|
400
|
+
`dependencies.json missing: ${path.relative(ctx.projectRoot, depsPath)}`,
|
|
401
|
+
{ suggestedCommand: "spine init" },
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
let parsed;
|
|
406
|
+
try {
|
|
407
|
+
parsed = JSON.parse(fs.readFileSync(depsPath, "utf-8"));
|
|
408
|
+
} catch (err) {
|
|
409
|
+
return makeCheck("dependencies-json", false, `cannot parse dependencies.json: ${err.message}`, {
|
|
410
|
+
suggestedCommand: "spine init",
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (parsed.version !== DEPENDENCIES_SCHEMA_VERSION) {
|
|
415
|
+
return makeCheck(
|
|
416
|
+
"dependencies-json",
|
|
417
|
+
false,
|
|
418
|
+
`dependencies.json version must be ${DEPENDENCIES_SCHEMA_VERSION} (found ${parsed.version ?? "missing"})`,
|
|
419
|
+
{ suggestedCommand: "spine init" },
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (typeof parsed.tasks !== "object" || parsed.tasks === null || Array.isArray(parsed.tasks)) {
|
|
424
|
+
return makeCheck("dependencies-json", false, "dependencies.json tasks must be an object", {
|
|
425
|
+
suggestedCommand: "spine init",
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const taskIds = Object.keys(parsed.tasks);
|
|
430
|
+
const invalidIds = taskIds.filter((id) => !TASK_ID_PATTERN.test(id));
|
|
431
|
+
if (invalidIds.length > 0) {
|
|
432
|
+
return makeCheck(
|
|
433
|
+
"dependencies-json",
|
|
434
|
+
false,
|
|
435
|
+
`dependencies.json has invalid task IDs: ${invalidIds.slice(0, 5).join(", ")}`,
|
|
436
|
+
{ details: { invalidIds }, suggestedCommand: "spine init --tasks-root taskplane-tasks" },
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const discovered = new Set(discoverTaskIds(tasksRootPath));
|
|
441
|
+
const unknownIds = taskIds.filter((id) => !discovered.has(id));
|
|
442
|
+
if (unknownIds.length > 0) {
|
|
443
|
+
return makeCheck(
|
|
444
|
+
"dependencies-json",
|
|
445
|
+
false,
|
|
446
|
+
`dependencies.json references unknown task folders: ${unknownIds.slice(0, 5).join(", ")}`,
|
|
447
|
+
{ details: { unknownIds }, suggestedCommand: "spine init --tasks-root taskplane-tasks" },
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return makeCheck(
|
|
452
|
+
"dependencies-json",
|
|
453
|
+
true,
|
|
454
|
+
`dependencies.json valid (${taskIds.length} task(s))`,
|
|
455
|
+
{ details: { path: path.relative(ctx.projectRoot, depsPath), taskIds } },
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* @param {object} ctx
|
|
461
|
+
* @param {string} ctx.projectRoot
|
|
462
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
463
|
+
*/
|
|
464
|
+
export function checkWorktreeSetupHook(ctx) {
|
|
465
|
+
const configResult = ctx.configResult ?? loadSpineConfig(ctx.projectRoot);
|
|
466
|
+
const config = configResult?.config;
|
|
467
|
+
if (!config || configResult?.error) {
|
|
468
|
+
return makeCheck("worktree-setup-hook", true, "worktree setup hook not configured");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const hookError = validateWorktreeSetupHookConfig(config, ctx.projectRoot);
|
|
472
|
+
if (hookError) {
|
|
473
|
+
return makeCheck("worktree-setup-hook", false, hookError.message, {
|
|
474
|
+
suggestedCommand: hookError.suggestedCommand,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (!config.worktreeSetupHook) {
|
|
479
|
+
return makeCheck("worktree-setup-hook", true, "worktree setup hook not configured");
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return makeCheck("worktree-setup-hook", true, "worktree setup hook path valid");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* @param {object} ctx
|
|
487
|
+
* @param {string} ctx.projectRoot
|
|
488
|
+
* @param {ReturnType<typeof loadSpineConfig>} [ctx.configResult]
|
|
489
|
+
*/
|
|
490
|
+
export function checkTasksValidate(ctx) {
|
|
491
|
+
const { projectRoot, configResult } = ctx;
|
|
492
|
+
const config = configResult?.config;
|
|
493
|
+
|
|
494
|
+
if (!config || configResult?.error) {
|
|
495
|
+
return makeCheck("tasks-validate", false, "cannot validate tasks without spine config", {
|
|
496
|
+
suggestedCommand: "spine init",
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
501
|
+
if (!tasksRootPath) {
|
|
502
|
+
return makeCheck("tasks-validate", false, "tasks root not configured", {
|
|
503
|
+
suggestedCommand: "spine init",
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
try {
|
|
508
|
+
const discovered = discoverTasks(tasksRootPath);
|
|
509
|
+
const { pendingIds } = summarizePendingScope(discovered, tasksRootPath);
|
|
510
|
+
if (pendingIds.length === 0) {
|
|
511
|
+
return makeCheck(
|
|
512
|
+
"tasks-validate",
|
|
513
|
+
true,
|
|
514
|
+
"no pending tasks (all discovered tasks have .DONE)",
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const selectedTaskIds = new Set(pendingIds);
|
|
519
|
+
/** @type {string[]} */
|
|
520
|
+
const failures = [];
|
|
521
|
+
|
|
522
|
+
for (const discoveredTask of discovered) {
|
|
523
|
+
if (!selectedTaskIds.has(discoveredTask.taskId)) continue;
|
|
524
|
+
const promptMarkdown = fs.readFileSync(
|
|
525
|
+
path.join(discoveredTask.folderPath, "PROMPT.md"),
|
|
526
|
+
"utf-8",
|
|
527
|
+
);
|
|
528
|
+
const validation = validatePrompt(promptMarkdown, {
|
|
529
|
+
taskId: discoveredTask.taskId,
|
|
530
|
+
contract: config.contract,
|
|
531
|
+
});
|
|
532
|
+
if (!validation.ok) {
|
|
533
|
+
failures.push(
|
|
534
|
+
`${discoveredTask.taskId}: ${validation.errors[0] ?? "invalid PROMPT packet"}`,
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (failures.length === 0) {
|
|
540
|
+
return makeCheck("tasks-validate", true, "pending task PROMPT packets valid");
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return makeCheck("tasks-validate", false, failures[0], {
|
|
544
|
+
suggestedCommand: "spine tasks validate pending",
|
|
545
|
+
details: { failures },
|
|
546
|
+
});
|
|
547
|
+
} catch (err) {
|
|
548
|
+
const message = err?.message ?? String(err);
|
|
549
|
+
if (message === NO_PENDING_TASKS_ERROR) {
|
|
550
|
+
return makeCheck(
|
|
551
|
+
"tasks-validate",
|
|
552
|
+
true,
|
|
553
|
+
"no pending tasks (all discovered tasks have .DONE)",
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return makeCheck("tasks-validate", false, `tasks validate failed: ${message}`, {
|
|
557
|
+
suggestedCommand: "spine tasks validate pending",
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @param {object} ctx
|
|
564
|
+
*/
|
|
565
|
+
export function runPreflightPlanCheck(ctx) {
|
|
566
|
+
const { projectRoot, configResult } = ctx;
|
|
567
|
+
const config = configResult?.config;
|
|
568
|
+
|
|
569
|
+
if (!config || configResult?.error) {
|
|
570
|
+
const msg = configResult?.error?.message ?? 'spine-config.json not initialized';
|
|
571
|
+
return {
|
|
572
|
+
status: "error",
|
|
573
|
+
message: `Cannot build plan: ${msg}`,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
578
|
+
if (!tasksRootPath) {
|
|
579
|
+
return {
|
|
580
|
+
status: "error",
|
|
581
|
+
message: "Cannot build plan: tasksRoot not configured",
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
try {
|
|
586
|
+
const discovered = discoverTasks(tasksRootPath);
|
|
587
|
+
const { pendingIds, excludedCount } = summarizePendingScope(discovered, tasksRootPath);
|
|
588
|
+
if (pendingIds.length === 0) {
|
|
589
|
+
const maxParallel = config.lanes?.maxParallel ?? 1;
|
|
590
|
+
return {
|
|
591
|
+
status: "ok",
|
|
592
|
+
message: [
|
|
593
|
+
"Spine plan — pending",
|
|
594
|
+
`0 task(s) · 0 wave(s) · maxParallel ${maxParallel}`,
|
|
595
|
+
`${excludedCount} excluded (.DONE on disk)`,
|
|
596
|
+
].join("\n"),
|
|
597
|
+
details: { waves: 0, pendingCount: 0, excludedCount },
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const plan = buildPlan({ scope: "pending", config, tasksRoot: tasksRootPath });
|
|
602
|
+
const waveCount = plan.waves?.length ?? 0;
|
|
603
|
+
return {
|
|
604
|
+
status: "ok",
|
|
605
|
+
message: `${formatPlanHuman(plan).trimEnd()}`,
|
|
606
|
+
details: { waves: waveCount },
|
|
607
|
+
};
|
|
608
|
+
} catch (err) {
|
|
609
|
+
const msg = err?.message ?? String(err);
|
|
610
|
+
if (msg === NO_PENDING_TASKS_ERROR) {
|
|
611
|
+
const maxParallel = config.lanes?.maxParallel ?? 1;
|
|
612
|
+
return {
|
|
613
|
+
status: "ok",
|
|
614
|
+
message: [
|
|
615
|
+
"Spine plan — pending",
|
|
616
|
+
`0 task(s) · 0 wave(s) · maxParallel ${maxParallel}`,
|
|
617
|
+
"All discovered tasks have .DONE on disk",
|
|
618
|
+
].join("\n"),
|
|
619
|
+
details: { waves: 0, pendingCount: 0 },
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
status: "error",
|
|
624
|
+
message: `Failed to build plan: ${msg}`,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* @param {object} options
|
|
631
|
+
* @param {string} options.projectRoot
|
|
632
|
+
* @param {boolean} [options.skipDoctor]
|
|
633
|
+
* @param {() => ReturnType<typeof runDoctorChecks>} [options.runDoctor]
|
|
634
|
+
* @param {typeof runReconciliationCheck} [options.runReconciliation]
|
|
635
|
+
*/
|
|
636
|
+
export function runBatchPreflight(options) {
|
|
637
|
+
const { projectRoot, skipDoctor = false } = options;
|
|
638
|
+
const ctx = { projectRoot, configResult: loadSpineConfig(projectRoot) };
|
|
639
|
+
const checks = [];
|
|
640
|
+
|
|
641
|
+
if (!skipDoctor) {
|
|
642
|
+
checks.push(
|
|
643
|
+
checkDoctor({
|
|
644
|
+
projectRoot,
|
|
645
|
+
runDoctor: options.runDoctor,
|
|
646
|
+
}),
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
checks.push(checkGitClean(ctx));
|
|
651
|
+
checks.push(
|
|
652
|
+
buildCoexistencePreflightCheck({
|
|
653
|
+
projectRoot,
|
|
654
|
+
runReconciliation: options.runReconciliation,
|
|
655
|
+
}),
|
|
656
|
+
);
|
|
657
|
+
checks.push(
|
|
658
|
+
checkNoActiveBatch({
|
|
659
|
+
projectRoot,
|
|
660
|
+
runReconciliation: options.runReconciliation,
|
|
661
|
+
}),
|
|
662
|
+
);
|
|
663
|
+
checks.push(checkTasksRoot(ctx));
|
|
664
|
+
checks.push(checkPiSpineRoot(ctx));
|
|
665
|
+
checks.push(checkDependenciesJson(ctx));
|
|
666
|
+
checks.push(checkWorktreeSetupHook(ctx));
|
|
667
|
+
checks.push(checkTasksValidate(ctx));
|
|
668
|
+
|
|
669
|
+
const plan = runPreflightPlanCheck(ctx);
|
|
670
|
+
checks.push(
|
|
671
|
+
makeCheck("plan", plan.status === "ok", plan.message, {
|
|
672
|
+
details: plan,
|
|
673
|
+
}),
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
const ok = checks.every((check) => check.ok);
|
|
677
|
+
return {
|
|
678
|
+
ok,
|
|
679
|
+
exitCode: ok ? 0 : 1,
|
|
680
|
+
checks,
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
export function formatPreflightHuman(result) {
|
|
685
|
+
const lines = ["\nBatch preflight\n"];
|
|
686
|
+
for (const check of result.checks) {
|
|
687
|
+
const icon = check.ok ? "✅" : "❌";
|
|
688
|
+
lines.push(` ${icon} ${check.id}: ${check.message}`);
|
|
689
|
+
if (!check.ok && check.suggestedCommand) {
|
|
690
|
+
lines.push(` → ${check.suggestedCommand}`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
lines.push("");
|
|
694
|
+
lines.push(
|
|
695
|
+
result.ok
|
|
696
|
+
? "✅ Preflight passed — ready to plan or start a batch.\n"
|
|
697
|
+
: "❌ Preflight failed.\n",
|
|
698
|
+
);
|
|
699
|
+
return lines.join("\n");
|
|
700
|
+
}
|