pi-spine 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -489
- package/bin/get-version.mjs +1 -13
- package/bin/spine-batch.mjs +5 -1
- package/bin/spine-config.mjs +1 -212
- package/bin/spine-doctor.mjs +2 -418
- package/bin/spine-init.mjs +1 -398
- package/bin/spine-preflight.mjs +1 -700
- package/bin/spine-review-step.mjs +6 -4
- package/bin/spine-tasks.mjs +96 -11
- package/bin/spine-worker-runner.mjs +14 -4
- package/bin/spine.mjs +3 -1
- package/extensions/spine/worker-tools.ts +14 -12
- package/package.json +5 -2
- package/skills/create-spine-tasks/SKILL.md +135 -6
- package/skills/create-spine-tasks/references/clarify-template.md +73 -0
- package/skills/create-spine-tasks/references/prompt-template.md +2 -0
- package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
- package/src/batch/abort.mjs +1 -1
- package/src/batch/detached-start.mjs +41 -7
- package/src/batch/diagnosis.mjs +51 -6
- package/src/batch/engine-lanes/merge.mjs +70 -7
- package/src/batch/engine-lanes/review.mjs +32 -74
- package/src/batch/engine-scope.mjs +31 -4
- package/src/batch/engine.mjs +40 -48
- package/src/batch/evidence.mjs +3 -2
- package/src/batch/gate.mjs +3 -3
- package/src/batch/integrate.mjs +1 -1
- package/src/batch/journal.mjs +22 -0
- package/src/batch/lifecycle.mjs +1 -1
- package/src/batch/merge/adoption-doc-merge.mjs +160 -0
- package/src/batch/merge/wave-merge-state.mjs +105 -0
- package/src/batch/post-merge-limbo.mjs +87 -15
- package/src/batch/reconcile.mjs +50 -2
- package/src/batch/resume-common.mjs +1 -1
- package/src/batch/resume-engine.mjs +58 -1
- package/src/batch/resume-multi-validate.mjs +82 -3
- package/src/batch/resume-multi.mjs +36 -40
- package/src/batch/resume.mjs +20 -10
- package/src/batch/review-shared.mjs +196 -0
- package/src/batch/review-spawn.mjs +320 -0
- package/src/batch/review.mjs +178 -212
- package/src/batch/task-stall-budget.mjs +72 -0
- package/src/batch/worker-host.mjs +94 -34
- package/src/batch/worktree.mjs +10 -0
- package/src/cli/handoff.mjs +1 -1
- package/src/cli/rules.mjs +1 -1
- package/src/cli/settings-set.mjs +1 -1
- package/src/cli/settings-slash.mjs +27 -5
- package/src/config/spine-config-load.mjs +221 -0
- package/src/config/spine-init-constants.mjs +423 -0
- package/src/config/spine-preflight-lib.mjs +725 -0
- package/src/dashboard/public/dashboard.js +4 -25
- package/src/dashboard/public/index.html +1 -7
- package/src/dashboard/snapshot.mjs +172 -5
- package/src/dashboard/view.mjs +2 -0
- package/src/doctor/run-doctor-checks.mjs +458 -0
- package/src/doctor/stale-path.mjs +22 -0
- package/src/migrate/taskplane-config.mjs +1 -1
- package/src/planner/pending.mjs +92 -1
- package/src/tasks/analyze/index.mjs +453 -0
- package/src/util/command-exists.mjs +19 -0
- package/templates/docs/constitution.md +61 -0
- package/templates/spine-config.json +1 -1
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor check orchestration — library surface for preflight and CLI.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
8
|
+
|
|
9
|
+
import { commandExists } from "../util/command-exists.mjs";
|
|
10
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
11
|
+
import { PACKAGE_ROOT, SPINE_GITIGNORE_ENTRIES } from "../config/spine-init-constants.mjs";
|
|
12
|
+
import {
|
|
13
|
+
buildMaxParallelDoctorCheck,
|
|
14
|
+
detectCpuCount,
|
|
15
|
+
} from "./suggest-max-parallel.mjs";
|
|
16
|
+
import { buildStalePathDoctorCheck } from "./stale-path.mjs";
|
|
17
|
+
import { buildCoexistenceDoctorCheck } from "./coexistence.mjs";
|
|
18
|
+
import { buildTaskPacketSizeDoctorCheck } from "./task-packet-size.mjs";
|
|
19
|
+
import {
|
|
20
|
+
buildPiWorkerTimeoutDoctorCheck,
|
|
21
|
+
buildStallConfigDoctorCheck,
|
|
22
|
+
} from "./stall-config.mjs";
|
|
23
|
+
import { buildRulesManifestDoctorCheck } from "./rules-manifest.mjs";
|
|
24
|
+
import { buildWorktreeHealthDoctorCheck } from "./worktree-health.mjs";
|
|
25
|
+
import { buildWorkerBackendDoctorCheck } from "../config/worker-backend.mjs";
|
|
26
|
+
import { buildAgentModelInheritDoctorCheck } from "./agent-model-inherit.mjs";
|
|
27
|
+
import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
|
|
28
|
+
import { RULES_PROFILE_REL_PATH } from "../config/cursor-rules/profile.mjs";
|
|
29
|
+
import {
|
|
30
|
+
formatConfigSourceDetail,
|
|
31
|
+
resolveTasksRootPath,
|
|
32
|
+
} from "../config/env-overrides.mjs";
|
|
33
|
+
|
|
34
|
+
const MIN_NODE_MAJOR = 22;
|
|
35
|
+
const nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
|
|
36
|
+
|
|
37
|
+
const SPINE_CLI_ENTRY = path.join(PACKAGE_ROOT, "bin", "spine.mjs");
|
|
38
|
+
|
|
39
|
+
const REQUIRED_AGENT_FILES = ["worker.md", "reviewer.md", "supervisor.md"];
|
|
40
|
+
|
|
41
|
+
function getVersion(cmd, flag = "--version") {
|
|
42
|
+
let result;
|
|
43
|
+
try {
|
|
44
|
+
result = spawnSync(cmd, [flag], {
|
|
45
|
+
encoding: "utf-8",
|
|
46
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!result || result.error || result.status !== 0) return null;
|
|
53
|
+
|
|
54
|
+
const stdout = (result.stdout ?? "").toString().trim();
|
|
55
|
+
const stderr = (result.stderr ?? "").toString().trim();
|
|
56
|
+
if (stdout) return stdout;
|
|
57
|
+
if (stderr) return stderr;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getPackageVersion() {
|
|
62
|
+
try {
|
|
63
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf-8"));
|
|
64
|
+
return pkg.version || "unknown";
|
|
65
|
+
} catch {
|
|
66
|
+
return "unknown";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getMinPiVersion() {
|
|
71
|
+
try {
|
|
72
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf-8"));
|
|
73
|
+
return pkg.pi?.minPiVersion ?? null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseSemver(versionText) {
|
|
80
|
+
const match = String(versionText ?? "")
|
|
81
|
+
.trim()
|
|
82
|
+
.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
83
|
+
if (!match) return null;
|
|
84
|
+
return {
|
|
85
|
+
major: Number(match[1]),
|
|
86
|
+
minor: Number(match[2]),
|
|
87
|
+
patch: Number(match[3]),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function compareSemver(a, b) {
|
|
92
|
+
if (!a || !b) return null;
|
|
93
|
+
if (a.major !== b.major) return a.major - b.major;
|
|
94
|
+
if (a.minor !== b.minor) return a.minor - b.minor;
|
|
95
|
+
return a.patch - b.patch;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isInsideGitRepo(dir) {
|
|
99
|
+
try {
|
|
100
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
101
|
+
cwd: dir,
|
|
102
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
103
|
+
timeout: 5000,
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function gitSupportsWorktrees() {
|
|
112
|
+
try {
|
|
113
|
+
execFileSync("git", ["worktree", "--help"], {
|
|
114
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
115
|
+
timeout: 5000,
|
|
116
|
+
});
|
|
117
|
+
return true;
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parsePiListModelsOutput(output) {
|
|
124
|
+
const lines = output.split(/\r?\n/).filter(Boolean);
|
|
125
|
+
let providerCol = 0;
|
|
126
|
+
let modelCol = 1;
|
|
127
|
+
let headerSeen = false;
|
|
128
|
+
|
|
129
|
+
for (const line of lines) {
|
|
130
|
+
const trimmed = line.trim();
|
|
131
|
+
if (!headerSeen && /^provider\b/i.test(trimmed)) {
|
|
132
|
+
headerSeen = true;
|
|
133
|
+
const lowerHeader = trimmed.toLowerCase().split(/\s+/);
|
|
134
|
+
const providerIdx = lowerHeader.indexOf("provider");
|
|
135
|
+
const modelIdx = lowerHeader.indexOf("model");
|
|
136
|
+
if (providerIdx >= 0) providerCol = providerIdx;
|
|
137
|
+
if (modelIdx >= 0) modelCol = modelIdx;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const parts = trimmed.split(/\s+/);
|
|
142
|
+
const provider = String(parts[providerCol] ?? parts[0] ?? "").trim();
|
|
143
|
+
const id = String(parts[modelCol] ?? parts[1] ?? "").trim();
|
|
144
|
+
if (!provider || !id) continue;
|
|
145
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(provider)) continue;
|
|
146
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(id)) continue;
|
|
147
|
+
return { provider, id };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function checkModelProvider() {
|
|
154
|
+
if (!commandExists("pi")) {
|
|
155
|
+
return { ok: false, detail: "pi not installed", suggestedCommand: "https://pi.dev" };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const result = spawnSync("pi", ["--list-models"], {
|
|
160
|
+
encoding: "utf-8",
|
|
161
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
162
|
+
timeout: 30_000,
|
|
163
|
+
});
|
|
164
|
+
if (result.error) throw result.error;
|
|
165
|
+
const output = `${result.stdout ?? ""}
|
|
166
|
+
${result.stderr ?? ""}`.trim();
|
|
167
|
+
const model = parsePiListModelsOutput(output);
|
|
168
|
+
if (!model) {
|
|
169
|
+
return {
|
|
170
|
+
ok: false,
|
|
171
|
+
detail: "no models available",
|
|
172
|
+
suggestedCommand: "pi login",
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
detail: `${model.provider}/${model.id}`,
|
|
178
|
+
};
|
|
179
|
+
} catch (err) {
|
|
180
|
+
return {
|
|
181
|
+
ok: false,
|
|
182
|
+
detail: err.message,
|
|
183
|
+
suggestedCommand: "pi login",
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function resolveTasksRoot(projectRoot, configResult) {
|
|
189
|
+
if (!configResult.config) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return resolveTasksRootPath(projectRoot, configResult.config);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function isTestingCommandEmpty(command) {
|
|
196
|
+
return !command || String(command).trim() === "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Warn when evidence gates expect commands that are missing (SP-112).
|
|
201
|
+
*
|
|
202
|
+
* @param {object} [config]
|
|
203
|
+
* @returns {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>}
|
|
204
|
+
*/
|
|
205
|
+
export function buildTestingEvidenceDoctorChecks(config = {}) {
|
|
206
|
+
const gates = config.gates ?? {};
|
|
207
|
+
const testing = config.testing ?? {};
|
|
208
|
+
const checks = [];
|
|
209
|
+
|
|
210
|
+
if (gates.collectBuildEvidence === true && isTestingCommandEmpty(testing.build)) {
|
|
211
|
+
checks.push({
|
|
212
|
+
label: "testing.build (evidence gate)",
|
|
213
|
+
ok: true,
|
|
214
|
+
warning: true,
|
|
215
|
+
detail: "collectBuildEvidence enabled but testing.build is empty — integrate evidence will skip build proof",
|
|
216
|
+
suggestedCommand: "spine settings set testing.build \"npm run typecheck\"",
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (gates.collectTestEvidence !== false && isTestingCommandEmpty(testing.test)) {
|
|
221
|
+
checks.push({
|
|
222
|
+
label: "testing.test (evidence gate)",
|
|
223
|
+
ok: true,
|
|
224
|
+
warning: true,
|
|
225
|
+
detail: "collectTestEvidence enabled but testing.test is empty — integrate evidence will skip test proof",
|
|
226
|
+
suggestedCommand: "spine settings set testing.test \"npm test\"",
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return checks;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
234
|
+
const checks = [];
|
|
235
|
+
let issueCount = 0;
|
|
236
|
+
|
|
237
|
+
const record = (label, ok, extra = {}) => {
|
|
238
|
+
checks.push({ label, ok, ...extra });
|
|
239
|
+
if (!ok) issueCount++;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
record("Node.js >= 22.0.0", nodeMajor >= MIN_NODE_MAJOR, {
|
|
243
|
+
detail: `v${process.versions.node}`,
|
|
244
|
+
});
|
|
245
|
+
record("git installed", commandExists("git"), { detail: getVersion("git") });
|
|
246
|
+
record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
|
|
247
|
+
record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
|
|
248
|
+
|
|
249
|
+
const piVersionText = getVersion("pi");
|
|
250
|
+
const minPiVersion = getMinPiVersion();
|
|
251
|
+
if (piVersionText && minPiVersion) {
|
|
252
|
+
const current = parseSemver(piVersionText);
|
|
253
|
+
const minimum = parseSemver(minPiVersion);
|
|
254
|
+
const cmp = compareSemver(current, minimum);
|
|
255
|
+
if (cmp === null) {
|
|
256
|
+
checks.push({
|
|
257
|
+
label: "pi version supported",
|
|
258
|
+
ok: true,
|
|
259
|
+
warning: true,
|
|
260
|
+
detail: `could not parse pi version (${piVersionText})`,
|
|
261
|
+
});
|
|
262
|
+
} else if (cmp < 0) {
|
|
263
|
+
checks.push({
|
|
264
|
+
label: "pi version supported",
|
|
265
|
+
ok: true,
|
|
266
|
+
warning: true,
|
|
267
|
+
detail: `${piVersionText} is below supported minimum ${minPiVersion}`,
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
checks.push({
|
|
271
|
+
label: "pi version supported",
|
|
272
|
+
ok: true,
|
|
273
|
+
detail: `>= ${minPiVersion}`,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const pkgVersion = getPackageVersion();
|
|
279
|
+
const isProjectLocal = PACKAGE_ROOT.includes(".pi");
|
|
280
|
+
const installType = isProjectLocal ? "project-local" : "development";
|
|
281
|
+
checks.push({
|
|
282
|
+
label: "pi-spine package",
|
|
283
|
+
ok: true,
|
|
284
|
+
detail: `v${pkgVersion}, ${installType}`,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
checks.push(
|
|
288
|
+
buildStalePathDoctorCheck({
|
|
289
|
+
packageRoot: PACKAGE_ROOT,
|
|
290
|
+
runningSpinePath: SPINE_CLI_ENTRY,
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const coexistenceCheck = buildCoexistenceDoctorCheck({ projectRoot });
|
|
295
|
+
checks.push(coexistenceCheck);
|
|
296
|
+
if (!coexistenceCheck.ok) issueCount++;
|
|
297
|
+
|
|
298
|
+
record("git repository detected", isInsideGitRepo(projectRoot));
|
|
299
|
+
|
|
300
|
+
const modelCheck = checkModelProvider();
|
|
301
|
+
record("model provider configured", modelCheck.ok, {
|
|
302
|
+
detail: modelCheck.detail,
|
|
303
|
+
suggestedCommand: modelCheck.suggestedCommand,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
307
|
+
if (configResult.error) {
|
|
308
|
+
record(".spine/spine-config.json valid", false, {
|
|
309
|
+
detail: configResult.error.message,
|
|
310
|
+
code: configResult.error.code,
|
|
311
|
+
suggestedCommand: configResult.error.suggestedCommand,
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
const tasksRootDetail = formatConfigSourceDetail(
|
|
315
|
+
configResult.sources,
|
|
316
|
+
configResult.envVars,
|
|
317
|
+
"paths.tasksRoot",
|
|
318
|
+
configResult.config.paths?.tasksRoot,
|
|
319
|
+
);
|
|
320
|
+
const maxParallelDetail = formatConfigSourceDetail(
|
|
321
|
+
configResult.sources,
|
|
322
|
+
configResult.envVars,
|
|
323
|
+
"lanes.maxParallel",
|
|
324
|
+
configResult.config.lanes?.maxParallel,
|
|
325
|
+
);
|
|
326
|
+
record(".spine/spine-config.json valid", true, {
|
|
327
|
+
detail: `project: ${configResult.config.project.name}`,
|
|
328
|
+
});
|
|
329
|
+
checks.push({
|
|
330
|
+
label: "paths.tasksRoot (effective)",
|
|
331
|
+
ok: true,
|
|
332
|
+
detail: tasksRootDetail,
|
|
333
|
+
});
|
|
334
|
+
checks.push({
|
|
335
|
+
label: "lanes.maxParallel (effective)",
|
|
336
|
+
ok: true,
|
|
337
|
+
detail: maxParallelDetail,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const configuredMaxParallel = configResult.config.lanes?.maxParallel ?? 3;
|
|
341
|
+
checks.push(
|
|
342
|
+
buildMaxParallelDoctorCheck({
|
|
343
|
+
configured: configuredMaxParallel,
|
|
344
|
+
cpuCount: detectCpuCount(),
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
checks.push(buildStallConfigDoctorCheck({ config: configResult.config }));
|
|
348
|
+
checks.push(buildPiWorkerTimeoutDoctorCheck({ config: configResult.config }));
|
|
349
|
+
checks.push(buildAgentModelInheritDoctorCheck({
|
|
350
|
+
config: configResult.config,
|
|
351
|
+
projectRoot,
|
|
352
|
+
}));
|
|
353
|
+
const worktreeHealthCheck = buildWorktreeHealthDoctorCheck({
|
|
354
|
+
projectRoot,
|
|
355
|
+
config: configResult.config,
|
|
356
|
+
});
|
|
357
|
+
checks.push(worktreeHealthCheck);
|
|
358
|
+
if (!worktreeHealthCheck.ok) issueCount++;
|
|
359
|
+
const workerBackendCheck = buildWorkerBackendDoctorCheck(configResult.config);
|
|
360
|
+
checks.push(workerBackendCheck);
|
|
361
|
+
if (!workerBackendCheck.ok) issueCount++;
|
|
362
|
+
for (const testingCheck of buildTestingEvidenceDoctorChecks(configResult.config)) {
|
|
363
|
+
checks.push(testingCheck);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
for (const agentFile of REQUIRED_AGENT_FILES) {
|
|
368
|
+
const relPath = `.spine/agents/${agentFile}`;
|
|
369
|
+
record(`${relPath} exists`, fs.existsSync(path.join(projectRoot, relPath)), {
|
|
370
|
+
suggestedCommand: "spine init",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
375
|
+
const metricsPath = path.join(
|
|
376
|
+
projectRoot,
|
|
377
|
+
configResult.config?.metrics?.path ?? ".spine/run-metrics.jsonl",
|
|
378
|
+
);
|
|
379
|
+
if (fs.existsSync(metricsPath)) {
|
|
380
|
+
try {
|
|
381
|
+
const lines = fs
|
|
382
|
+
.readFileSync(metricsPath, "utf-8")
|
|
383
|
+
.trim()
|
|
384
|
+
.split("\n")
|
|
385
|
+
.filter(Boolean);
|
|
386
|
+
checks.push({
|
|
387
|
+
label: "run metrics available",
|
|
388
|
+
ok: true,
|
|
389
|
+
detail: `${lines.length} record(s) in ${path.relative(projectRoot, metricsPath)}`,
|
|
390
|
+
suggestedCommand: "spine metrics show",
|
|
391
|
+
});
|
|
392
|
+
} catch {
|
|
393
|
+
checks.push({
|
|
394
|
+
label: "run metrics available",
|
|
395
|
+
ok: true,
|
|
396
|
+
warning: true,
|
|
397
|
+
detail: `present but unreadable: ${path.relative(projectRoot, metricsPath)}`,
|
|
398
|
+
suggestedCommand: "spine metrics show",
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (tasksRootPath) {
|
|
404
|
+
record("tasks root exists", fs.existsSync(tasksRootPath), {
|
|
405
|
+
detail: path.relative(projectRoot, tasksRootPath),
|
|
406
|
+
suggestedCommand: `mkdir -p ${path.relative(projectRoot, tasksRootPath)}`,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
const contextPath = path.join(tasksRootPath, "CONTEXT.md");
|
|
410
|
+
checks.push({
|
|
411
|
+
label: "CONTEXT.md exists",
|
|
412
|
+
ok: true,
|
|
413
|
+
warning: !fs.existsSync(contextPath),
|
|
414
|
+
optional: true,
|
|
415
|
+
detail: fs.existsSync(contextPath) ? "present" : "missing (optional)",
|
|
416
|
+
});
|
|
417
|
+
checks.push(buildTaskPacketSizeDoctorCheck({ tasksRoot: tasksRootPath }));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (isInsideGitRepo(projectRoot)) {
|
|
421
|
+
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
422
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
423
|
+
checks.push({
|
|
424
|
+
label: ".gitignore has spine runtime entries",
|
|
425
|
+
ok: true,
|
|
426
|
+
warning: true,
|
|
427
|
+
detail: ".gitignore missing",
|
|
428
|
+
suggestedCommand: "spine init",
|
|
429
|
+
});
|
|
430
|
+
} else {
|
|
431
|
+
const content = fs.readFileSync(gitignorePath, "utf-8");
|
|
432
|
+
const existingLines = new Set(content.split(/\r?\n/).map((line) => line.trim()));
|
|
433
|
+
const missing = SPINE_GITIGNORE_ENTRIES.filter((entry) => !existingLines.has(entry));
|
|
434
|
+
checks.push({
|
|
435
|
+
label: ".gitignore has spine runtime entries",
|
|
436
|
+
ok: true,
|
|
437
|
+
warning: missing.length > 0,
|
|
438
|
+
detail:
|
|
439
|
+
missing.length === 0
|
|
440
|
+
? "complete"
|
|
441
|
+
: `missing ${missing.length} entr${missing.length === 1 ? "y" : "ies"}`,
|
|
442
|
+
suggestedCommand: missing.length > 0 ? "spine init" : undefined,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const rulesRootPath = path.join(projectRoot, CURSOR_RULES_ROOT_REL);
|
|
448
|
+
const rulesProfilePath = path.join(projectRoot, RULES_PROFILE_REL_PATH);
|
|
449
|
+
if (fs.existsSync(rulesRootPath) || fs.existsSync(rulesProfilePath)) {
|
|
450
|
+
checks.push(buildRulesManifestDoctorCheck(projectRoot));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
ok: issueCount === 0,
|
|
455
|
+
issueCount,
|
|
456
|
+
checks,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
@@ -154,3 +154,25 @@ export function buildStalePathDoctorCheck({
|
|
|
154
154
|
suggestedCommand: `cd ${packageRoot} && npm link`,
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* True when PATH `spine` exists but is not the checkout binary (version or mtime drift).
|
|
160
|
+
* Used by batch preflight to fail closed before a stale global CLI reproduces SP-306.
|
|
161
|
+
*
|
|
162
|
+
* @param {ReturnType<typeof buildStalePathDoctorCheck>} check
|
|
163
|
+
*/
|
|
164
|
+
export function isStalePathSpineBlocking(check) {
|
|
165
|
+
return check.warning === true && String(check.label ?? "").includes("stale");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Preflight blocks only on PATH vs package **version** mismatch (issue #12 / SP-308).
|
|
170
|
+
* Mtime-only drift remains a doctor warning so linked checkouts are not blocked.
|
|
171
|
+
*
|
|
172
|
+
* @param {ReturnType<typeof buildStalePathDoctorCheck>} check
|
|
173
|
+
*/
|
|
174
|
+
export function isStalePathSpinePreflightBlocking(check) {
|
|
175
|
+
return (
|
|
176
|
+
check.warning === true && String(check.detail ?? "").includes("vs package")
|
|
177
|
+
);
|
|
178
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { loadSpineConfigTemplate } from "
|
|
2
|
+
import { loadSpineConfigTemplate } from "../config/spine-init-constants.mjs";
|
|
3
3
|
|
|
4
4
|
export const DEFAULT_TASKPLANE_SOURCE_PATH = ".pi/taskplane-config.json";
|
|
5
5
|
export const defaultTaskplaneSourcePath = DEFAULT_TASKPLANE_SOURCE_PATH;
|
package/src/planner/pending.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { TASK_ID_RE } from "./scope.mjs";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {Array<{ taskId: string, folderPath: string }>} discoveredTasks
|
|
@@ -16,7 +17,8 @@ export function filterPendingTaskIds(discoveredTasks, tasksRoot) {
|
|
|
16
17
|
for (const task of discoveredTasks) {
|
|
17
18
|
const folderPath = task.folderPath ?? path.join(tasksRoot, `${task.taskId}-unknown`);
|
|
18
19
|
const donePath = path.join(folderPath, ".DONE");
|
|
19
|
-
|
|
20
|
+
const supersededPath = path.join(folderPath, ".SUPERSEDED");
|
|
21
|
+
if (!fs.existsSync(donePath) && !fs.existsSync(supersededPath)) {
|
|
20
22
|
pending.push(task.taskId);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -37,3 +39,92 @@ export function summarizePendingScope(discoveredTasks, tasksRoot) {
|
|
|
37
39
|
excludedCount: allIds.length - pendingIds.length,
|
|
38
40
|
};
|
|
39
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse replacement task IDs from a `.SUPERSEDED` marker body.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} content
|
|
47
|
+
* @returns {string[]}
|
|
48
|
+
*/
|
|
49
|
+
export function parseSupersededReplacementIds(content) {
|
|
50
|
+
const match = /Superseded by\s+([^\n]+)/i.exec(String(content ?? ""));
|
|
51
|
+
if (!match) return [];
|
|
52
|
+
|
|
53
|
+
return match[1]
|
|
54
|
+
.split(/[,;]+/)
|
|
55
|
+
.flatMap((segment) => segment.trim().split(/\s+/))
|
|
56
|
+
.map((token) => token.trim())
|
|
57
|
+
.filter((token) => TASK_ID_RE.test(token));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Fail closed when explicit batch start requests superseded task IDs.
|
|
62
|
+
*
|
|
63
|
+
* @param {string[]} taskIds
|
|
64
|
+
* @param {string} tasksRoot
|
|
65
|
+
* @param {Array<{ taskId: string, folderPath: string }>} discoveredTasks
|
|
66
|
+
* @param {{ forceSuperseded?: boolean }} [options]
|
|
67
|
+
*/
|
|
68
|
+
export function assertBatchStartTasksNotSuperseded(
|
|
69
|
+
taskIds,
|
|
70
|
+
tasksRoot,
|
|
71
|
+
discoveredTasks,
|
|
72
|
+
options = {},
|
|
73
|
+
) {
|
|
74
|
+
if (options.forceSuperseded) {
|
|
75
|
+
return { ok: true };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const folderById = new Map(
|
|
79
|
+
discoveredTasks.map((task) => [
|
|
80
|
+
task.taskId,
|
|
81
|
+
task.folderPath ?? path.join(tasksRoot, `${task.taskId}-unknown`),
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
/** @type {Array<{ taskId: string, replacements: string[] }>} */
|
|
86
|
+
const superseded = [];
|
|
87
|
+
|
|
88
|
+
for (const taskId of taskIds) {
|
|
89
|
+
const folderPath = folderById.get(taskId);
|
|
90
|
+
if (!folderPath) continue;
|
|
91
|
+
|
|
92
|
+
const supersededPath = path.join(folderPath, ".SUPERSEDED");
|
|
93
|
+
if (!fs.existsSync(supersededPath)) continue;
|
|
94
|
+
|
|
95
|
+
const content = fs.readFileSync(supersededPath, "utf-8");
|
|
96
|
+
superseded.push({
|
|
97
|
+
taskId,
|
|
98
|
+
replacements: parseSupersededReplacementIds(content),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (superseded.length === 0) {
|
|
103
|
+
return { ok: true };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const lines = [
|
|
107
|
+
"Batch start rejected: requested task(s) are superseded (.SUPERSEDED marker present).",
|
|
108
|
+
"",
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
for (const entry of superseded) {
|
|
112
|
+
const replacementHint =
|
|
113
|
+
entry.replacements.length > 0 ? ` → use ${entry.replacements.join(", ")}` : "";
|
|
114
|
+
lines.push(` ${entry.taskId}${replacementHint}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
lines.push(
|
|
118
|
+
"",
|
|
119
|
+
"Prefer task IDs from: spine plan pending",
|
|
120
|
+
"To rerun superseded tasks deliberately: spine batch start <ids> --force-superseded",
|
|
121
|
+
"",
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
error: "superseded_tasks",
|
|
127
|
+
output: lines.join("\n"),
|
|
128
|
+
supersededTaskIds: superseded.map((entry) => entry.taskId),
|
|
129
|
+
};
|
|
130
|
+
}
|