pi-spine 1.0.2 → 1.2.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 +162 -51
- package/bin/spine-cli/batch.mjs +3 -3
- package/bin/spine-cli/lane-logs.mjs +24 -0
- package/bin/spine-cli/scenarios.mjs +298 -0
- package/bin/spine-cli/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-config.mjs +1 -212
- package/bin/spine-doctor.mjs +2 -418
- package/bin/spine-init.mjs +1 -398
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-preflight.mjs +1 -700
- package/bin/spine-review-step.mjs +6 -4
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +112 -13
- package/bin/spine-worker-runner.mjs +24 -14
- package/bin/spine.mjs +52 -2
- 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/contract-template.md +19 -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 +3 -12
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +312 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-verify.mjs +140 -2
- package/src/batch/detached-start.mjs +105 -7
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -0
- package/src/batch/diagnosis-task-done.mjs +110 -0
- package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
- package/src/batch/diagnosis.mjs +174 -62
- package/src/batch/engine-lanes/merge.mjs +168 -77
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +32 -74
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +42 -5
- package/src/batch/engine.mjs +115 -68
- package/src/batch/evidence.mjs +81 -17
- package/src/batch/gate.mjs +46 -17
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +73 -7
- package/src/batch/integrate.mjs +3 -5
- package/src/batch/journal.mjs +25 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lifecycle.mjs +131 -4
- package/src/batch/macro-phase.mjs +226 -0
- package/src/batch/merge/adoption-doc-merge.mjs +243 -0
- package/src/batch/merge/wave-merge-state.mjs +108 -0
- package/src/batch/metrics.mjs +74 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +223 -0
- package/src/batch/post-merge-limbo.mjs +345 -17
- package/src/batch/reconcile.mjs +473 -50
- package/src/batch/resume-common.mjs +6 -2
- package/src/batch/resume-engine.mjs +58 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +56 -1
- package/src/batch/resume-multi-validate.mjs +148 -8
- package/src/batch/resume-multi.mjs +45 -44
- package/src/batch/resume.mjs +64 -47
- package/src/batch/retry.mjs +56 -5
- package/src/batch/review-shared.mjs +196 -0
- package/src/batch/review-spawn.mjs +326 -0
- package/src/batch/review.mjs +178 -212
- package/src/batch/rules-manifest-drift.mjs +157 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence.mjs +454 -0
- package/src/batch/state.mjs +18 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +94 -10
- package/src/batch/worker-host.mjs +185 -37
- package/src/batch/worker-output.mjs +196 -3
- package/src/batch/worktree.mjs +10 -0
- package/src/cli/handoff.mjs +1 -1
- package/src/cli/issue-draft.mjs +180 -0
- package/src/cli/journal-follow.mjs +239 -0
- package/src/cli/lane-logs.mjs +291 -0
- package/src/cli/rules.mjs +1 -1
- package/src/cli/sequence.mjs +108 -0
- package/src/cli/settings-set.mjs +3 -22
- package/src/cli/settings-slash.mjs +27 -5
- package/src/cli/wait.mjs +187 -0
- package/src/cli/watch.mjs +160 -0
- package/src/config/agent-model-resolve.mjs +48 -0
- package/src/config/cursor-rules/discover.mjs +3 -21
- package/src/config/defaults.mjs +7 -1
- package/src/config/settings-fields.mjs +48 -0
- package/src/config/spine-config-load.mjs +221 -0
- package/src/config/spine-init-constants.mjs +424 -0
- package/src/config/spine-preflight-lib.mjs +1180 -0
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +224 -40
- package/src/dashboard/public/index.html +15 -9
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +387 -6
- package/src/dashboard/view.mjs +170 -15
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/run-doctor-checks.mjs +483 -0
- package/src/doctor/sequence-safety.mjs +57 -0
- package/src/doctor/stale-path.mjs +22 -0
- package/src/doctor/stale-worktrees.mjs +102 -0
- package/src/fixtures/scenario-registry.mjs +194 -0
- package/src/fs/atomic-write.mjs +49 -0
- package/src/migrate/taskplane-config.mjs +1 -1
- package/src/planner/file-scope.mjs +246 -0
- package/src/planner/format-plan.mjs +9 -7
- package/src/planner/index.mjs +6 -2
- package/src/planner/pending.mjs +92 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/analyze/index.mjs +453 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +42 -1
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/src/util/command-exists.mjs +19 -0
- package/templates/docs/constitution.md +61 -0
- package/templates/spine-config.json +9 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { die } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handleWatch(args) {
|
|
7
|
+
const { parseWatchArgs, runSpineWatch } = await import("../../src/cli/watch.mjs");
|
|
8
|
+
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = parseWatchArgs(args);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
14
|
+
die(`${message}\nRun spine watch [--interval SEC] [--json] [--once] for usage.`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = await runSpineWatch({
|
|
18
|
+
projectRoot: process.cwd(),
|
|
19
|
+
intervalSec: parsed.intervalSec,
|
|
20
|
+
json: parsed.json,
|
|
21
|
+
once: parsed.once,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (result.exitCode !== 0) {
|
|
25
|
+
process.exit(result.exitCode);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/bin/spine-config.mjs
CHANGED
|
@@ -1,212 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
export * from "../src/config/spine-config-load.mjs";
|
package/bin/spine-doctor.mjs
CHANGED
|
@@ -2,432 +2,16 @@
|
|
|
2
2
|
* spine doctor — installation and project configuration checks (SP-093 manifest warnings).
|
|
3
3
|
*/
|
|
4
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, getVersion } from "./get-version.mjs";
|
|
10
|
-
import { loadSpineConfig } from "./spine-config.mjs";
|
|
11
|
-
import { SPINE_GITIGNORE_ENTRIES } from "./spine-init.mjs";
|
|
12
5
|
import {
|
|
13
6
|
c,
|
|
14
7
|
FAIL,
|
|
15
|
-
getMinPiVersion,
|
|
16
|
-
getPackageVersion,
|
|
17
8
|
isCliEntrypoint,
|
|
18
9
|
OK,
|
|
19
|
-
PACKAGE_ROOT,
|
|
20
10
|
WARN,
|
|
21
11
|
} from "./spine-cli/shared.mjs";
|
|
22
|
-
import {
|
|
23
|
-
buildMaxParallelDoctorCheck,
|
|
24
|
-
detectCpuCount,
|
|
25
|
-
} from "../src/doctor/suggest-max-parallel.mjs";
|
|
26
|
-
import { buildStalePathDoctorCheck } from "../src/doctor/stale-path.mjs";
|
|
27
|
-
import { buildCoexistenceDoctorCheck } from "../src/doctor/coexistence.mjs";
|
|
28
|
-
import { buildTaskPacketSizeDoctorCheck } from "../src/doctor/task-packet-size.mjs";
|
|
29
|
-
import {
|
|
30
|
-
buildPiWorkerTimeoutDoctorCheck,
|
|
31
|
-
buildStallConfigDoctorCheck,
|
|
32
|
-
} from "../src/doctor/stall-config.mjs";
|
|
33
|
-
import { buildRulesManifestDoctorCheck } from "../src/doctor/rules-manifest.mjs";
|
|
34
|
-
import { buildWorktreeHealthDoctorCheck } from "../src/doctor/worktree-health.mjs";
|
|
35
|
-
import { buildWorkerBackendDoctorCheck } from "../src/config/worker-backend.mjs";
|
|
36
|
-
import { buildAgentModelInheritDoctorCheck } from "../src/doctor/agent-model-inherit.mjs";
|
|
37
|
-
import { CURSOR_RULES_ROOT_REL } from "../src/config/cursor-rules/discover.mjs";
|
|
38
|
-
import { RULES_PROFILE_REL_PATH } from "../src/config/cursor-rules/profile.mjs";
|
|
39
|
-
import {
|
|
40
|
-
formatConfigSourceDetail,
|
|
41
|
-
resolveTasksRootPath,
|
|
42
|
-
} from "../src/config/env-overrides.mjs";
|
|
43
|
-
|
|
44
|
-
const MIN_NODE_MAJOR = 22;
|
|
45
|
-
const nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
|
|
46
|
-
|
|
47
|
-
const SPINE_CLI_ENTRY = path.join(PACKAGE_ROOT, "bin", "spine.mjs");
|
|
48
|
-
|
|
49
|
-
const REQUIRED_AGENT_FILES = ["worker.md", "reviewer.md", "supervisor.md"];
|
|
50
|
-
|
|
51
|
-
function parseSemver(versionText) {
|
|
52
|
-
const match = String(versionText ?? "")
|
|
53
|
-
.trim()
|
|
54
|
-
.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
55
|
-
if (!match) return null;
|
|
56
|
-
return {
|
|
57
|
-
major: Number(match[1]),
|
|
58
|
-
minor: Number(match[2]),
|
|
59
|
-
patch: Number(match[3]),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function compareSemver(a, b) {
|
|
64
|
-
if (!a || !b) return null;
|
|
65
|
-
if (a.major !== b.major) return a.major - b.major;
|
|
66
|
-
if (a.minor !== b.minor) return a.minor - b.minor;
|
|
67
|
-
return a.patch - b.patch;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isInsideGitRepo(dir) {
|
|
71
|
-
try {
|
|
72
|
-
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
73
|
-
cwd: dir,
|
|
74
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
75
|
-
timeout: 5000,
|
|
76
|
-
});
|
|
77
|
-
return true;
|
|
78
|
-
} catch {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function gitSupportsWorktrees() {
|
|
84
|
-
try {
|
|
85
|
-
execFileSync("git", ["worktree", "--help"], {
|
|
86
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
87
|
-
timeout: 5000,
|
|
88
|
-
});
|
|
89
|
-
return true;
|
|
90
|
-
} catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function parsePiListModelsOutput(output) {
|
|
96
|
-
const lines = output.split(/\r?\n/).filter(Boolean);
|
|
97
|
-
let providerCol = 0;
|
|
98
|
-
let modelCol = 1;
|
|
99
|
-
let headerSeen = false;
|
|
100
|
-
|
|
101
|
-
for (const line of lines) {
|
|
102
|
-
const trimmed = line.trim();
|
|
103
|
-
if (!headerSeen && /^provider\b/i.test(trimmed)) {
|
|
104
|
-
headerSeen = true;
|
|
105
|
-
const lowerHeader = trimmed.toLowerCase().split(/\s+/);
|
|
106
|
-
const providerIdx = lowerHeader.indexOf("provider");
|
|
107
|
-
const modelIdx = lowerHeader.indexOf("model");
|
|
108
|
-
if (providerIdx >= 0) providerCol = providerIdx;
|
|
109
|
-
if (modelIdx >= 0) modelCol = modelIdx;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const parts = trimmed.split(/\s+/);
|
|
114
|
-
const provider = String(parts[providerCol] ?? parts[0] ?? "").trim();
|
|
115
|
-
const id = String(parts[modelCol] ?? parts[1] ?? "").trim();
|
|
116
|
-
if (!provider || !id) continue;
|
|
117
|
-
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(provider)) continue;
|
|
118
|
-
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(id)) continue;
|
|
119
|
-
return { provider, id };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function checkModelProvider() {
|
|
126
|
-
if (!commandExists("pi")) {
|
|
127
|
-
return { ok: false, detail: "pi not installed", suggestedCommand: "https://pi.dev" };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
const result = spawnSync("pi", ["--list-models"], {
|
|
132
|
-
encoding: "utf-8",
|
|
133
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
134
|
-
timeout: 30_000,
|
|
135
|
-
});
|
|
136
|
-
if (result.error) throw result.error;
|
|
137
|
-
const output = `${result.stdout ?? ""}
|
|
138
|
-
${result.stderr ?? ""}`.trim();
|
|
139
|
-
const model = parsePiListModelsOutput(output);
|
|
140
|
-
if (!model) {
|
|
141
|
-
return {
|
|
142
|
-
ok: false,
|
|
143
|
-
detail: "no models available",
|
|
144
|
-
suggestedCommand: "pi login",
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
ok: true,
|
|
149
|
-
detail: `${model.provider}/${model.id}`,
|
|
150
|
-
};
|
|
151
|
-
} catch (err) {
|
|
152
|
-
return {
|
|
153
|
-
ok: false,
|
|
154
|
-
detail: err.message,
|
|
155
|
-
suggestedCommand: "pi login",
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function resolveTasksRoot(projectRoot, configResult) {
|
|
161
|
-
if (!configResult.config) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
return resolveTasksRootPath(projectRoot, configResult.config);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function isTestingCommandEmpty(command) {
|
|
168
|
-
return !command || String(command).trim() === "";
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Warn when evidence gates expect commands that are missing (SP-112).
|
|
173
|
-
*
|
|
174
|
-
* @param {object} [config]
|
|
175
|
-
* @returns {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>}
|
|
176
|
-
*/
|
|
177
|
-
export function buildTestingEvidenceDoctorChecks(config = {}) {
|
|
178
|
-
const gates = config.gates ?? {};
|
|
179
|
-
const testing = config.testing ?? {};
|
|
180
|
-
const checks = [];
|
|
181
|
-
|
|
182
|
-
if (gates.collectBuildEvidence === true && isTestingCommandEmpty(testing.build)) {
|
|
183
|
-
checks.push({
|
|
184
|
-
label: "testing.build (evidence gate)",
|
|
185
|
-
ok: true,
|
|
186
|
-
warning: true,
|
|
187
|
-
detail: "collectBuildEvidence enabled but testing.build is empty — integrate evidence will skip build proof",
|
|
188
|
-
suggestedCommand: "spine settings set testing.build \"npm run typecheck\"",
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (gates.collectTestEvidence !== false && isTestingCommandEmpty(testing.test)) {
|
|
193
|
-
checks.push({
|
|
194
|
-
label: "testing.test (evidence gate)",
|
|
195
|
-
ok: true,
|
|
196
|
-
warning: true,
|
|
197
|
-
detail: "collectTestEvidence enabled but testing.test is empty — integrate evidence will skip test proof",
|
|
198
|
-
suggestedCommand: "spine settings set testing.test \"npm test\"",
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return checks;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
206
|
-
const checks = [];
|
|
207
|
-
let issueCount = 0;
|
|
208
|
-
|
|
209
|
-
const record = (label, ok, extra = {}) => {
|
|
210
|
-
checks.push({ label, ok, ...extra });
|
|
211
|
-
if (!ok) issueCount++;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
record("Node.js >= 22.0.0", nodeMajor >= MIN_NODE_MAJOR, {
|
|
215
|
-
detail: `v${process.versions.node}`,
|
|
216
|
-
});
|
|
217
|
-
record("git installed", commandExists("git"), { detail: getVersion("git") });
|
|
218
|
-
record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
|
|
219
|
-
record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
|
|
220
|
-
|
|
221
|
-
const piVersionText = getVersion("pi");
|
|
222
|
-
const minPiVersion = getMinPiVersion();
|
|
223
|
-
if (piVersionText && minPiVersion) {
|
|
224
|
-
const current = parseSemver(piVersionText);
|
|
225
|
-
const minimum = parseSemver(minPiVersion);
|
|
226
|
-
const cmp = compareSemver(current, minimum);
|
|
227
|
-
if (cmp === null) {
|
|
228
|
-
checks.push({
|
|
229
|
-
label: "pi version supported",
|
|
230
|
-
ok: true,
|
|
231
|
-
warning: true,
|
|
232
|
-
detail: `could not parse pi version (${piVersionText})`,
|
|
233
|
-
});
|
|
234
|
-
} else if (cmp < 0) {
|
|
235
|
-
checks.push({
|
|
236
|
-
label: "pi version supported",
|
|
237
|
-
ok: true,
|
|
238
|
-
warning: true,
|
|
239
|
-
detail: `${piVersionText} is below supported minimum ${minPiVersion}`,
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
checks.push({
|
|
243
|
-
label: "pi version supported",
|
|
244
|
-
ok: true,
|
|
245
|
-
detail: `>= ${minPiVersion}`,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const pkgVersion = getPackageVersion();
|
|
251
|
-
const isProjectLocal = PACKAGE_ROOT.includes(".pi");
|
|
252
|
-
const installType = isProjectLocal ? "project-local" : "development";
|
|
253
|
-
checks.push({
|
|
254
|
-
label: "pi-spine package",
|
|
255
|
-
ok: true,
|
|
256
|
-
detail: `v${pkgVersion}, ${installType}`,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
checks.push(
|
|
260
|
-
buildStalePathDoctorCheck({
|
|
261
|
-
packageRoot: PACKAGE_ROOT,
|
|
262
|
-
runningSpinePath: SPINE_CLI_ENTRY,
|
|
263
|
-
}),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const coexistenceCheck = buildCoexistenceDoctorCheck({ projectRoot });
|
|
267
|
-
checks.push(coexistenceCheck);
|
|
268
|
-
if (!coexistenceCheck.ok) issueCount++;
|
|
269
|
-
|
|
270
|
-
record("git repository detected", isInsideGitRepo(projectRoot));
|
|
271
|
-
|
|
272
|
-
const modelCheck = checkModelProvider();
|
|
273
|
-
record("model provider configured", modelCheck.ok, {
|
|
274
|
-
detail: modelCheck.detail,
|
|
275
|
-
suggestedCommand: modelCheck.suggestedCommand,
|
|
276
|
-
});
|
|
12
|
+
import { runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
|
|
277
13
|
|
|
278
|
-
|
|
279
|
-
if (configResult.error) {
|
|
280
|
-
record(".spine/spine-config.json valid", false, {
|
|
281
|
-
detail: configResult.error.message,
|
|
282
|
-
code: configResult.error.code,
|
|
283
|
-
suggestedCommand: configResult.error.suggestedCommand,
|
|
284
|
-
});
|
|
285
|
-
} else {
|
|
286
|
-
const tasksRootDetail = formatConfigSourceDetail(
|
|
287
|
-
configResult.sources,
|
|
288
|
-
configResult.envVars,
|
|
289
|
-
"paths.tasksRoot",
|
|
290
|
-
configResult.config.paths?.tasksRoot,
|
|
291
|
-
);
|
|
292
|
-
const maxParallelDetail = formatConfigSourceDetail(
|
|
293
|
-
configResult.sources,
|
|
294
|
-
configResult.envVars,
|
|
295
|
-
"lanes.maxParallel",
|
|
296
|
-
configResult.config.lanes?.maxParallel,
|
|
297
|
-
);
|
|
298
|
-
record(".spine/spine-config.json valid", true, {
|
|
299
|
-
detail: `project: ${configResult.config.project.name}`,
|
|
300
|
-
});
|
|
301
|
-
checks.push({
|
|
302
|
-
label: "paths.tasksRoot (effective)",
|
|
303
|
-
ok: true,
|
|
304
|
-
detail: tasksRootDetail,
|
|
305
|
-
});
|
|
306
|
-
checks.push({
|
|
307
|
-
label: "lanes.maxParallel (effective)",
|
|
308
|
-
ok: true,
|
|
309
|
-
detail: maxParallelDetail,
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
const configuredMaxParallel = configResult.config.lanes?.maxParallel ?? 3;
|
|
313
|
-
checks.push(
|
|
314
|
-
buildMaxParallelDoctorCheck({
|
|
315
|
-
configured: configuredMaxParallel,
|
|
316
|
-
cpuCount: detectCpuCount(),
|
|
317
|
-
}),
|
|
318
|
-
);
|
|
319
|
-
checks.push(buildStallConfigDoctorCheck({ config: configResult.config }));
|
|
320
|
-
checks.push(buildPiWorkerTimeoutDoctorCheck({ config: configResult.config }));
|
|
321
|
-
checks.push(buildAgentModelInheritDoctorCheck({
|
|
322
|
-
config: configResult.config,
|
|
323
|
-
projectRoot,
|
|
324
|
-
}));
|
|
325
|
-
const worktreeHealthCheck = buildWorktreeHealthDoctorCheck({
|
|
326
|
-
projectRoot,
|
|
327
|
-
config: configResult.config,
|
|
328
|
-
});
|
|
329
|
-
checks.push(worktreeHealthCheck);
|
|
330
|
-
if (!worktreeHealthCheck.ok) issueCount++;
|
|
331
|
-
const workerBackendCheck = buildWorkerBackendDoctorCheck(configResult.config);
|
|
332
|
-
checks.push(workerBackendCheck);
|
|
333
|
-
if (!workerBackendCheck.ok) issueCount++;
|
|
334
|
-
for (const testingCheck of buildTestingEvidenceDoctorChecks(configResult.config)) {
|
|
335
|
-
checks.push(testingCheck);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
for (const agentFile of REQUIRED_AGENT_FILES) {
|
|
340
|
-
const relPath = `.spine/agents/${agentFile}`;
|
|
341
|
-
record(`${relPath} exists`, fs.existsSync(path.join(projectRoot, relPath)), {
|
|
342
|
-
suggestedCommand: "spine init",
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
347
|
-
const metricsPath = path.join(
|
|
348
|
-
projectRoot,
|
|
349
|
-
configResult.config?.metrics?.path ?? ".spine/run-metrics.jsonl",
|
|
350
|
-
);
|
|
351
|
-
if (fs.existsSync(metricsPath)) {
|
|
352
|
-
try {
|
|
353
|
-
const lines = fs
|
|
354
|
-
.readFileSync(metricsPath, "utf-8")
|
|
355
|
-
.trim()
|
|
356
|
-
.split("\n")
|
|
357
|
-
.filter(Boolean);
|
|
358
|
-
checks.push({
|
|
359
|
-
label: "run metrics available",
|
|
360
|
-
ok: true,
|
|
361
|
-
detail: `${lines.length} record(s) in ${path.relative(projectRoot, metricsPath)}`,
|
|
362
|
-
suggestedCommand: "spine metrics show",
|
|
363
|
-
});
|
|
364
|
-
} catch {
|
|
365
|
-
checks.push({
|
|
366
|
-
label: "run metrics available",
|
|
367
|
-
ok: true,
|
|
368
|
-
warning: true,
|
|
369
|
-
detail: `present but unreadable: ${path.relative(projectRoot, metricsPath)}`,
|
|
370
|
-
suggestedCommand: "spine metrics show",
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (tasksRootPath) {
|
|
376
|
-
record("tasks root exists", fs.existsSync(tasksRootPath), {
|
|
377
|
-
detail: path.relative(projectRoot, tasksRootPath),
|
|
378
|
-
suggestedCommand: `mkdir -p ${path.relative(projectRoot, tasksRootPath)}`,
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const contextPath = path.join(tasksRootPath, "CONTEXT.md");
|
|
382
|
-
checks.push({
|
|
383
|
-
label: "CONTEXT.md exists",
|
|
384
|
-
ok: true,
|
|
385
|
-
warning: !fs.existsSync(contextPath),
|
|
386
|
-
optional: true,
|
|
387
|
-
detail: fs.existsSync(contextPath) ? "present" : "missing (optional)",
|
|
388
|
-
});
|
|
389
|
-
checks.push(buildTaskPacketSizeDoctorCheck({ tasksRoot: tasksRootPath }));
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (isInsideGitRepo(projectRoot)) {
|
|
393
|
-
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
394
|
-
if (!fs.existsSync(gitignorePath)) {
|
|
395
|
-
checks.push({
|
|
396
|
-
label: ".gitignore has spine runtime entries",
|
|
397
|
-
ok: true,
|
|
398
|
-
warning: true,
|
|
399
|
-
detail: ".gitignore missing",
|
|
400
|
-
suggestedCommand: "spine init",
|
|
401
|
-
});
|
|
402
|
-
} else {
|
|
403
|
-
const content = fs.readFileSync(gitignorePath, "utf-8");
|
|
404
|
-
const existingLines = new Set(content.split(/\r?\n/).map((line) => line.trim()));
|
|
405
|
-
const missing = SPINE_GITIGNORE_ENTRIES.filter((entry) => !existingLines.has(entry));
|
|
406
|
-
checks.push({
|
|
407
|
-
label: ".gitignore has spine runtime entries",
|
|
408
|
-
ok: true,
|
|
409
|
-
warning: missing.length > 0,
|
|
410
|
-
detail:
|
|
411
|
-
missing.length === 0
|
|
412
|
-
? "complete"
|
|
413
|
-
: `missing ${missing.length} entr${missing.length === 1 ? "y" : "ies"}`,
|
|
414
|
-
suggestedCommand: missing.length > 0 ? "spine init" : undefined,
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const rulesRootPath = path.join(projectRoot, CURSOR_RULES_ROOT_REL);
|
|
420
|
-
const rulesProfilePath = path.join(projectRoot, RULES_PROFILE_REL_PATH);
|
|
421
|
-
if (fs.existsSync(rulesRootPath) || fs.existsSync(rulesProfilePath)) {
|
|
422
|
-
checks.push(buildRulesManifestDoctorCheck(projectRoot));
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return {
|
|
426
|
-
ok: issueCount === 0,
|
|
427
|
-
issueCount,
|
|
428
|
-
checks,
|
|
429
|
-
};
|
|
430
|
-
}
|
|
14
|
+
export { buildTestingEvidenceDoctorChecks, runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
|
|
431
15
|
|
|
432
16
|
export function cmdDoctor() {
|
|
433
17
|
const projectRoot = process.cwd();
|