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,425 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { abortBatch } from "../src/batch/abort.mjs";
|
|
5
|
+
import {
|
|
6
|
+
resolveDefaultResumeWaitTerminal,
|
|
7
|
+
resumeBatchDetached,
|
|
8
|
+
startBatchDetached,
|
|
9
|
+
} from "../src/batch/detached-start.mjs";
|
|
10
|
+
import { completeBatch, dismissBatch } from "../src/batch/lifecycle.mjs";
|
|
11
|
+
import { forceMergeWave, startBatch } from "../src/batch/engine.mjs";
|
|
12
|
+
import { pauseBatch, resumeBatch } from "../src/batch/resume.mjs";
|
|
13
|
+
import { retryTask, skipTask } from "../src/batch/retry.mjs";
|
|
14
|
+
import { reconcileBatch } from "../src/batch/reconcile.mjs";
|
|
15
|
+
|
|
16
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {object} result
|
|
20
|
+
* @param {boolean} json
|
|
21
|
+
*/
|
|
22
|
+
export function formatLifecycleHuman(result, json = false) {
|
|
23
|
+
if (json) return `${JSON.stringify(result, null, 2)}\n`;
|
|
24
|
+
|
|
25
|
+
const lines = ["", result.ok ? "Batch lifecycle" : "Batch lifecycle failed", "", ` ${result.headline}`];
|
|
26
|
+
|
|
27
|
+
if (result.error) {
|
|
28
|
+
lines.push("", ` Error: ${result.error}`);
|
|
29
|
+
}
|
|
30
|
+
if (result.batchId) {
|
|
31
|
+
lines.push("", ` Batch: ${result.batchId}`);
|
|
32
|
+
}
|
|
33
|
+
if (result.diagnosis) {
|
|
34
|
+
lines.push(` Diagnosis: ${result.diagnosis}`);
|
|
35
|
+
}
|
|
36
|
+
if (result.archivePath) {
|
|
37
|
+
lines.push(` Archive: ${result.archivePath}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
lines.push("", ` → ${result.suggestedCommand}`);
|
|
41
|
+
|
|
42
|
+
if (result.alternatives?.length) {
|
|
43
|
+
lines.push("", " Alternatives:");
|
|
44
|
+
for (const alt of result.alternatives) {
|
|
45
|
+
lines.push(` • ${alt}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
lines.push("");
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {string[]} args
|
|
55
|
+
*/
|
|
56
|
+
export function parseBatchArgs(args) {
|
|
57
|
+
const flags = new Set(args.filter((a) => a.startsWith("--")));
|
|
58
|
+
|
|
59
|
+
let batchId = null;
|
|
60
|
+
const batchIdx = args.indexOf("--batch");
|
|
61
|
+
if (batchIdx >= 0 && args[batchIdx + 1]) {
|
|
62
|
+
batchId = args[batchIdx + 1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let reason = null;
|
|
66
|
+
const reasonIdx = args.indexOf("--reason");
|
|
67
|
+
if (reasonIdx >= 0 && args[reasonIdx + 1]) {
|
|
68
|
+
reason = args[reasonIdx + 1];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let waveIndex = 0;
|
|
72
|
+
const waveIdx = args.indexOf("--wave");
|
|
73
|
+
if (waveIdx >= 0 && args[waveIdx + 1]) {
|
|
74
|
+
waveIndex = Number(args[waveIdx + 1]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const dryRun = flags.has("--dry-run");
|
|
78
|
+
const skipPreflight = flags.has("--skip-preflight");
|
|
79
|
+
|
|
80
|
+
const subcommand =
|
|
81
|
+
args.find(
|
|
82
|
+
(t) =>
|
|
83
|
+
t === "dismiss" ||
|
|
84
|
+
t === "complete" ||
|
|
85
|
+
t === "abort" ||
|
|
86
|
+
t === "start" ||
|
|
87
|
+
t === "pause" ||
|
|
88
|
+
t === "resume" ||
|
|
89
|
+
t === "retry" ||
|
|
90
|
+
t === "skip" ||
|
|
91
|
+
t === "force-merge",
|
|
92
|
+
) ?? null;
|
|
93
|
+
|
|
94
|
+
const positional = args.filter((a) => !a.startsWith("--") && a !== subcommand);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
json: flags.has("--json"),
|
|
98
|
+
force: flags.has("--force"),
|
|
99
|
+
hard: flags.has("--hard"),
|
|
100
|
+
detectManualMerge: flags.has("--detect-manual-merge"),
|
|
101
|
+
attached: flags.has("--attached"),
|
|
102
|
+
waitTerminal: flags.has("--wait-terminal"),
|
|
103
|
+
noWaitTerminal: flags.has("--no-wait-terminal"),
|
|
104
|
+
dryRun,
|
|
105
|
+
skipPreflight,
|
|
106
|
+
batchId,
|
|
107
|
+
reason,
|
|
108
|
+
waveIndex,
|
|
109
|
+
subcommand,
|
|
110
|
+
taskId: subcommand === "retry" || subcommand === "skip" ? positional[0] ?? null : null,
|
|
111
|
+
scope: positional.join(" ") || "all",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {object} options
|
|
117
|
+
* @param {string} options.projectRoot
|
|
118
|
+
* @param {string[]} options.args
|
|
119
|
+
*/
|
|
120
|
+
export async function runSpineBatch(options) {
|
|
121
|
+
const { projectRoot, args } = options;
|
|
122
|
+
const parsed = parseBatchArgs(args);
|
|
123
|
+
|
|
124
|
+
if (parsed.subcommand === "dismiss") {
|
|
125
|
+
const result = dismissBatch({
|
|
126
|
+
projectRoot,
|
|
127
|
+
batchId: parsed.batchId,
|
|
128
|
+
reason: parsed.reason,
|
|
129
|
+
force: parsed.force,
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
133
|
+
output: formatLifecycleHuman(result, parsed.json),
|
|
134
|
+
result,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (parsed.subcommand === "abort") {
|
|
139
|
+
const result = abortBatch({
|
|
140
|
+
projectRoot,
|
|
141
|
+
batchId: parsed.batchId,
|
|
142
|
+
reason: parsed.reason,
|
|
143
|
+
hard: parsed.hard,
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
147
|
+
output: formatLifecycleHuman(result, parsed.json),
|
|
148
|
+
result,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (parsed.subcommand === "complete") {
|
|
153
|
+
const result = completeBatch({
|
|
154
|
+
projectRoot,
|
|
155
|
+
batchId: parsed.batchId,
|
|
156
|
+
detectManualMerge: parsed.detectManualMerge,
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
160
|
+
output: formatLifecycleHuman(result, parsed.json),
|
|
161
|
+
result,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (parsed.subcommand === "pause") {
|
|
166
|
+
const result = pauseBatch({ projectRoot });
|
|
167
|
+
if (parsed.json) {
|
|
168
|
+
return {
|
|
169
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
170
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
171
|
+
result,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
176
|
+
output: result.output ?? (result.ok ? "Batch paused.\n" : "Batch pause failed.\n"),
|
|
177
|
+
result,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (parsed.subcommand === "retry") {
|
|
182
|
+
if (!parsed.taskId) {
|
|
183
|
+
return {
|
|
184
|
+
exitCode: 1,
|
|
185
|
+
output: "Usage: spine batch retry <taskId> [--json]\n",
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const result = retryTask({ projectRoot, taskId: parsed.taskId });
|
|
189
|
+
if (parsed.json) {
|
|
190
|
+
return {
|
|
191
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
192
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
193
|
+
result,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const lines = [
|
|
197
|
+
"",
|
|
198
|
+
result.ok ? "Task retry" : "Task retry failed",
|
|
199
|
+
"",
|
|
200
|
+
result.output ?? result.error ?? "",
|
|
201
|
+
];
|
|
202
|
+
if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
|
|
203
|
+
if (result.taskId) lines.push(` Task: ${result.taskId}`);
|
|
204
|
+
if (result.pendingSegments != null) lines.push(` Pending segments: ${result.pendingSegments}`);
|
|
205
|
+
lines.push("");
|
|
206
|
+
return {
|
|
207
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
208
|
+
output: lines.join("\n"),
|
|
209
|
+
result,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (parsed.subcommand === "skip") {
|
|
214
|
+
if (!parsed.taskId) {
|
|
215
|
+
return {
|
|
216
|
+
exitCode: 1,
|
|
217
|
+
output: "Usage: spine batch skip <taskId> [--json]\n",
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const result = skipTask({ projectRoot, taskId: parsed.taskId });
|
|
221
|
+
if (parsed.json) {
|
|
222
|
+
return {
|
|
223
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
224
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
225
|
+
result,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const lines = [
|
|
229
|
+
"",
|
|
230
|
+
result.ok ? "Task skipped" : "Task skip failed",
|
|
231
|
+
"",
|
|
232
|
+
result.output ?? result.error ?? "",
|
|
233
|
+
];
|
|
234
|
+
if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
|
|
235
|
+
if (result.taskId) lines.push(` Task: ${result.taskId}`);
|
|
236
|
+
lines.push("");
|
|
237
|
+
return {
|
|
238
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
239
|
+
output: lines.join("\n"),
|
|
240
|
+
result,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (parsed.subcommand === "force-merge") {
|
|
245
|
+
const result = forceMergeWave({ projectRoot, waveIndex: parsed.waveIndex });
|
|
246
|
+
if (parsed.json) {
|
|
247
|
+
return {
|
|
248
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
249
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
250
|
+
result,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const lines = [
|
|
254
|
+
"",
|
|
255
|
+
result.ok ? "Force merge requested" : "Force merge failed",
|
|
256
|
+
"",
|
|
257
|
+
result.output ?? result.error ?? "",
|
|
258
|
+
];
|
|
259
|
+
if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
|
|
260
|
+
lines.push("");
|
|
261
|
+
return {
|
|
262
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
263
|
+
output: lines.join("\n"),
|
|
264
|
+
result,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (parsed.subcommand === "resume") {
|
|
269
|
+
if (!parsed.attached) {
|
|
270
|
+
const waitTerminal = resolveDefaultResumeWaitTerminal(
|
|
271
|
+
projectRoot,
|
|
272
|
+
parsed.waitTerminal,
|
|
273
|
+
parsed.noWaitTerminal,
|
|
274
|
+
);
|
|
275
|
+
const detached = await resumeBatchDetached({
|
|
276
|
+
projectRoot,
|
|
277
|
+
spineBin: path.join(__dirname, "spine.mjs"),
|
|
278
|
+
force: parsed.force,
|
|
279
|
+
waitTerminal,
|
|
280
|
+
json: parsed.json,
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
exitCode: detached.exitCode ?? (detached.ok ? 0 : 1),
|
|
284
|
+
output: detached.output,
|
|
285
|
+
result: detached.result,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const result = await resumeBatch({ projectRoot, force: parsed.force });
|
|
290
|
+
if (parsed.json) {
|
|
291
|
+
return {
|
|
292
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
293
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
294
|
+
result,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const lines = [
|
|
298
|
+
"",
|
|
299
|
+
result.ok ? "Batch resumed" : "Batch resume failed",
|
|
300
|
+
"",
|
|
301
|
+
result.output ?? result.error ?? "",
|
|
302
|
+
];
|
|
303
|
+
if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
|
|
304
|
+
if (result.taskId) lines.push(` Task: ${result.taskId}`);
|
|
305
|
+
lines.push("");
|
|
306
|
+
return {
|
|
307
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
308
|
+
output: lines.join("\n"),
|
|
309
|
+
result,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (parsed.subcommand === "start") {
|
|
314
|
+
const useAttached = parsed.attached || parsed.dryRun;
|
|
315
|
+
if (!useAttached) {
|
|
316
|
+
const detached = await startBatchDetached({
|
|
317
|
+
projectRoot,
|
|
318
|
+
spineBin: path.join(__dirname, "spine.mjs"),
|
|
319
|
+
scope: parsed.scope,
|
|
320
|
+
skipPreflight: parsed.skipPreflight,
|
|
321
|
+
waitTerminal: parsed.waitTerminal,
|
|
322
|
+
json: parsed.json,
|
|
323
|
+
});
|
|
324
|
+
return {
|
|
325
|
+
exitCode: detached.exitCode ?? (detached.ok ? 0 : 1),
|
|
326
|
+
output: detached.output,
|
|
327
|
+
result: detached.result,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const result = await startBatch({
|
|
332
|
+
projectRoot,
|
|
333
|
+
scope: parsed.scope,
|
|
334
|
+
dryRun: parsed.dryRun,
|
|
335
|
+
skipPreflight: parsed.skipPreflight,
|
|
336
|
+
});
|
|
337
|
+
if (parsed.json) {
|
|
338
|
+
return {
|
|
339
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
340
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
341
|
+
result,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const lines = [
|
|
345
|
+
"",
|
|
346
|
+
result.ok ? "Batch started" : "Batch start failed",
|
|
347
|
+
"",
|
|
348
|
+
result.output ?? result.error ?? "",
|
|
349
|
+
];
|
|
350
|
+
if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
|
|
351
|
+
if (result.taskId) lines.push(` Task: ${result.taskId}`);
|
|
352
|
+
lines.push("");
|
|
353
|
+
return {
|
|
354
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
355
|
+
output: lines.join("\n"),
|
|
356
|
+
result,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
exitCode: 1,
|
|
362
|
+
output:
|
|
363
|
+
"Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|abort|dismiss|complete [--batch ID] [--reason TEXT] [--hard] [--force] [--attached] [--dry-run] [--skip-preflight] [--detect-manual-merge] [--json]\n",
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @param {object} options
|
|
369
|
+
* @param {string} options.projectRoot
|
|
370
|
+
* @param {string[]} options.args
|
|
371
|
+
*/
|
|
372
|
+
export function runSpineNext(options) {
|
|
373
|
+
const { projectRoot, args } = options;
|
|
374
|
+
const execute = args.includes("--execute");
|
|
375
|
+
const json = args.includes("--json");
|
|
376
|
+
const reconciliation = reconcileBatch({ projectRoot });
|
|
377
|
+
|
|
378
|
+
if (json) {
|
|
379
|
+
return {
|
|
380
|
+
exitCode: 0,
|
|
381
|
+
output: `${JSON.stringify({ ...reconciliation, execute }, null, 2)}\n`,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (!execute) {
|
|
386
|
+
const lines = [
|
|
387
|
+
"",
|
|
388
|
+
"Suggested next action (dry-run)",
|
|
389
|
+
"",
|
|
390
|
+
` ${reconciliation.headline}`,
|
|
391
|
+
"",
|
|
392
|
+
` → ${reconciliation.suggestedCommand}`,
|
|
393
|
+
"",
|
|
394
|
+
" Run with --execute to run this command.",
|
|
395
|
+
"",
|
|
396
|
+
];
|
|
397
|
+
return { exitCode: 0, output: lines.join("\n") };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const command = reconciliation.suggestedCommand;
|
|
401
|
+
if (!command) {
|
|
402
|
+
return { exitCode: 1, output: "No suggested command available.\n" };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const tokens = command.split(/\s+/).filter(Boolean);
|
|
406
|
+
if (tokens[0] !== "spine") {
|
|
407
|
+
return {
|
|
408
|
+
exitCode: 1,
|
|
409
|
+
output: `Cannot execute non-spine command automatically: ${command}\nRun it manually in your shell.\n`,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const spineBin = path.join(__dirname, "spine.mjs");
|
|
414
|
+
const result = spawnSync(process.execPath, [spineBin, ...tokens.slice(1)], {
|
|
415
|
+
cwd: projectRoot,
|
|
416
|
+
encoding: "utf-8",
|
|
417
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
|
|
421
|
+
return {
|
|
422
|
+
exitCode: result.status ?? 1,
|
|
423
|
+
output: output || `Executed: ${command}\n`,
|
|
424
|
+
};
|
|
425
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadSpineConfig } from "../spine-config.mjs";
|
|
4
|
+
import { HANDOFF_DEFAULTS } from "../../src/config/defaults.mjs";
|
|
5
|
+
import { writeCommandResult } from "./shared.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string[]} args
|
|
9
|
+
*/
|
|
10
|
+
export async function handleBatch(args) {
|
|
11
|
+
const { runSpineBatch } = await import("../spine-batch.mjs");
|
|
12
|
+
const result = await runSpineBatch({ projectRoot: process.cwd(), args });
|
|
13
|
+
writeCommandResult(result);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string[]} args
|
|
18
|
+
*/
|
|
19
|
+
export async function handleRun(args) {
|
|
20
|
+
const { runSpineBatch } = await import("../spine-batch.mjs");
|
|
21
|
+
const result = await runSpineBatch({
|
|
22
|
+
projectRoot: process.cwd(),
|
|
23
|
+
args: ["start", ...args],
|
|
24
|
+
});
|
|
25
|
+
writeCommandResult(result);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string[]} args
|
|
30
|
+
*/
|
|
31
|
+
export async function handleNext(args) {
|
|
32
|
+
const projectRoot = process.cwd();
|
|
33
|
+
const { runSpineNext } = await import("../spine-batch.mjs");
|
|
34
|
+
const result = runSpineNext({ projectRoot, args });
|
|
35
|
+
|
|
36
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
37
|
+
const handoffRel =
|
|
38
|
+
configResult.config?.handoff?.path && typeof configResult.config.handoff.path === "string"
|
|
39
|
+
? configResult.config.handoff.path
|
|
40
|
+
: HANDOFF_DEFAULTS.path;
|
|
41
|
+
const handoffPath = path.join(projectRoot, handoffRel);
|
|
42
|
+
if (fs.existsSync(handoffPath) && !args.includes("--json")) {
|
|
43
|
+
result.output = `${result.output ?? ""}\nHandoff: ${handoffRel}\n`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
writeCommandResult(result);
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { writeCommandResult } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handleGate(args) {
|
|
7
|
+
const { runSpineGate } = await import("../spine-gate.mjs");
|
|
8
|
+
const result = runSpineGate({ projectRoot: process.cwd(), args });
|
|
9
|
+
writeCommandResult(result);
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { writeCommandResult } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handleIntegrate(args) {
|
|
7
|
+
const { runSpineIntegrate } = await import("../spine-integrate.mjs");
|
|
8
|
+
const result = runSpineIntegrate({ projectRoot: process.cwd(), args });
|
|
9
|
+
writeCommandResult(result);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { writeCommandResult } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handlePlan(args) {
|
|
7
|
+
const json = args.includes("--json");
|
|
8
|
+
const scope = args.filter((a) => !a.startsWith("--")).join(" ") || "all";
|
|
9
|
+
const { runSpinePlan } = await import("../spine-plan.mjs");
|
|
10
|
+
const result = await runSpinePlan({ projectRoot: process.cwd(), scope, json });
|
|
11
|
+
writeCommandResult(result);
|
|
12
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
export const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
|
|
9
|
+
|
|
10
|
+
export const c = {
|
|
11
|
+
reset: "\x1b[0m",
|
|
12
|
+
bold: "\x1b[1m",
|
|
13
|
+
dim: "\x1b[2m",
|
|
14
|
+
red: "\x1b[31m",
|
|
15
|
+
green: "\x1b[32m",
|
|
16
|
+
yellow: "\x1b[33m",
|
|
17
|
+
cyan: "\x1b[36m",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const OK = `${c.green}✅${c.reset}`;
|
|
21
|
+
export const WARN = `${c.yellow}⚠️${c.reset}`;
|
|
22
|
+
export const FAIL = `${c.red}❌${c.reset}`;
|
|
23
|
+
|
|
24
|
+
export function die(msg) {
|
|
25
|
+
console.error(`${FAIL} ${msg}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getPackageVersion() {
|
|
30
|
+
try {
|
|
31
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf-8"));
|
|
32
|
+
return pkg.version || "unknown";
|
|
33
|
+
} catch {
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getMinPiVersion() {
|
|
39
|
+
try {
|
|
40
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf-8"));
|
|
41
|
+
return pkg.pi?.minPiVersion ?? null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Write CLI module output and exit when the command failed.
|
|
49
|
+
* @param {{ output?: string, exitCode?: number }} result
|
|
50
|
+
*/
|
|
51
|
+
export function writeCommandResult(result) {
|
|
52
|
+
process.stdout.write(result.output ?? "");
|
|
53
|
+
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns true when this module is the Node CLI entrypoint.
|
|
58
|
+
* Uses fs.realpathSync so npm global bin symlinks resolve to the same file as import.meta.url.
|
|
59
|
+
* Falls back to path.resolve equality when realpath throws (missing path edge case).
|
|
60
|
+
* Requires Node >= 22 (see package engines).
|
|
61
|
+
*
|
|
62
|
+
* @param {string} importMetaUrl
|
|
63
|
+
* @param {string|undefined} [argv1=process.argv[1]]
|
|
64
|
+
*/
|
|
65
|
+
export function isCliEntrypoint(importMetaUrl, argv1 = process.argv[1]) {
|
|
66
|
+
if (!argv1) return false;
|
|
67
|
+
const modulePath = fileURLToPath(importMetaUrl);
|
|
68
|
+
try {
|
|
69
|
+
return fs.realpathSync(argv1) === fs.realpathSync(modulePath);
|
|
70
|
+
} catch {
|
|
71
|
+
return path.resolve(argv1) === path.resolve(modulePath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { writeCommandResult } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handleStatus(args) {
|
|
7
|
+
const json = args.includes("--json");
|
|
8
|
+
const diagnose = args.includes("--diagnose");
|
|
9
|
+
const verbose = args.includes("--verbose");
|
|
10
|
+
const { runSpineStatus } = await import("../spine-status.mjs");
|
|
11
|
+
const result = runSpineStatus({
|
|
12
|
+
projectRoot: process.cwd(),
|
|
13
|
+
json,
|
|
14
|
+
diagnose,
|
|
15
|
+
verbose,
|
|
16
|
+
});
|
|
17
|
+
writeCommandResult(result);
|
|
18
|
+
}
|