pi-spine 1.1.0 → 1.3.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 +4 -4
- package/bin/spine-batch.mjs +160 -53
- 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/verify.mjs +3 -0
- package/bin/spine-cli/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-plan.mjs +49 -1
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +16 -2
- package/bin/spine-worker-runner.mjs +144 -12
- package/bin/spine.mjs +49 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +7 -2
- package/skills/create-spine-tasks/references/contract-template.md +114 -3
- package/src/batch/abort.mjs +2 -11
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +388 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-stub-delivery.mjs +110 -0
- package/src/batch/contract-task-start.mjs +204 -0
- package/src/batch/contract-verify.mjs +195 -10
- package/src/batch/detached-start.mjs +137 -3
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-launch-failure.mjs +114 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-primary-failure.mjs +89 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -0
- package/src/batch/diagnosis-tail-state.mjs +57 -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 +140 -164
- package/src/batch/engine-lanes/commit.mjs +145 -0
- package/src/batch/engine-lanes/merge.mjs +110 -82
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +67 -87
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +21 -78
- package/src/batch/engine-scope.mjs +11 -1
- package/src/batch/engine.mjs +125 -24
- package/src/batch/evidence.mjs +78 -15
- package/src/batch/gate.mjs +43 -14
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +75 -9
- package/src/batch/integrate-assert.mjs +69 -0
- package/src/batch/integrate-worktree.mjs +354 -0
- package/src/batch/integrate.mjs +193 -102
- package/src/batch/journal-rebuild.mjs +48 -2
- package/src/batch/journal.mjs +66 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lane-dirty-check.mjs +437 -0
- package/src/batch/lifecycle.mjs +130 -3
- package/src/batch/limbo-detect.mjs +34 -0
- package/src/batch/macro-phase.mjs +302 -0
- package/src/batch/merge/adoption-doc-merge.mjs +93 -10
- package/src/batch/merge/wave-merge-state.mjs +3 -0
- package/src/batch/metrics.mjs +76 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +234 -0
- package/src/batch/post-merge-limbo.mjs +259 -28
- package/src/batch/reconcile.mjs +508 -63
- package/src/batch/resume-common.mjs +32 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +67 -1
- package/src/batch/resume-multi-validate.mjs +67 -6
- package/src/batch/resume-multi.mjs +11 -4
- package/src/batch/resume.mjs +59 -45
- package/src/batch/retry.mjs +97 -15
- package/src/batch/review-spawn.mjs +8 -2
- package/src/batch/rules-manifest-drift.mjs +198 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence-state.mjs +290 -0
- package/src/batch/sequence.mjs +516 -0
- package/src/batch/state.mjs +34 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +22 -10
- package/src/batch/worker-host.mjs +96 -7
- package/src/batch/worker-output.mjs +196 -3
- 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/sequence.mjs +121 -0
- package/src/cli/settings-set.mjs +35 -24
- 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/model-id.mjs +103 -0
- package/src/config/settings-fields.mjs +48 -0
- package/src/config/spine-init-constants.mjs +2 -0
- package/src/config/spine-preflight-lib.mjs +494 -17
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +234 -18
- package/src/dashboard/public/index.html +14 -2
- package/src/dashboard/running-tail-state.mjs +31 -0
- package/src/dashboard/server.mjs +8 -0
- package/src/dashboard/snapshot.mjs +472 -26
- package/src/dashboard/view.mjs +282 -19
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/agent-models.mjs +53 -0
- package/src/doctor/batch-size-guidance.mjs +30 -2
- package/src/doctor/pi-extension-conflict.mjs +169 -0
- package/src/doctor/run-doctor-checks.mjs +32 -1
- package/src/doctor/sequence-safety.mjs +57 -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/planner/file-scope.mjs +246 -0
- package/src/planner/format-plan.mjs +9 -7
- package/src/planner/index.mjs +6 -2
- package/src/planner/scope.mjs +5 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +73 -2
- package/src/tasks/packet/validate-contract.mjs +108 -0
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/templates/spine-config.json +8 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { die } from "./shared.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string[]} args
|
|
5
|
+
*/
|
|
6
|
+
export async function handleWait(args) {
|
|
7
|
+
const { parseWaitArgs, runSpineWait } = await import("../../src/cli/wait.mjs");
|
|
8
|
+
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = parseWaitArgs(args);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
14
|
+
die(
|
|
15
|
+
`${message}\nRun spine wait --until DIAG[,DIAG...] [--timeout DURATION] [--interval SEC] [--json] for usage.`,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result = await runSpineWait({
|
|
20
|
+
projectRoot: process.cwd(),
|
|
21
|
+
untilDiagnoses: parsed.until,
|
|
22
|
+
intervalSec: parsed.intervalSec,
|
|
23
|
+
timeoutMs: parsed.timeoutMs,
|
|
24
|
+
json: parsed.json,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (result.exitCode !== 0) {
|
|
28
|
+
process.exit(result.exitCode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* GitHub issue draft CLI (issue #60 Tier 1c).
|
|
4
|
+
* Usage: spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
|
|
11
|
+
import { buildIssueDraftBody } from "../src/cli/issue-draft.mjs";
|
|
12
|
+
import { commandExists } from "../src/util/command-exists.mjs";
|
|
13
|
+
import { c, die, isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_OUT_PATH = ".spine/issue-draft.md";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string[]} argv
|
|
19
|
+
*/
|
|
20
|
+
export function parseIssueDraftArgs(argv) {
|
|
21
|
+
/** @type {{ issueType: "bug"|"enhancement"|"question", title: string|null, json: boolean, outPath: string, create: boolean }} */
|
|
22
|
+
const args = {
|
|
23
|
+
issueType: "bug",
|
|
24
|
+
title: null,
|
|
25
|
+
json: false,
|
|
26
|
+
outPath: DEFAULT_OUT_PATH,
|
|
27
|
+
create: false,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const arg = argv[i];
|
|
32
|
+
if (arg === "--type") {
|
|
33
|
+
const value = argv[++i];
|
|
34
|
+
if (value !== "bug" && value !== "enhancement" && value !== "question") {
|
|
35
|
+
die(`Invalid --type value: ${value ?? "(missing)"}\nExpected bug, enhancement, or question.`);
|
|
36
|
+
}
|
|
37
|
+
args.issueType = value;
|
|
38
|
+
} else if (arg === "--title") {
|
|
39
|
+
args.title = argv[++i] ?? null;
|
|
40
|
+
} else if (arg === "--json") {
|
|
41
|
+
args.json = true;
|
|
42
|
+
} else if (arg === "--out") {
|
|
43
|
+
args.outPath = argv[++i] ?? DEFAULT_OUT_PATH;
|
|
44
|
+
} else if (arg === "--create") {
|
|
45
|
+
args.create = true;
|
|
46
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
47
|
+
return { ...args, help: true };
|
|
48
|
+
} else {
|
|
49
|
+
die(`Unknown argument: ${arg}\nRun ${c.cyan}spine issue draft --help${c.reset} for usage.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function printIssueDraftHelp() {
|
|
57
|
+
console.log(`
|
|
58
|
+
${c.bold}spine issue draft${c.reset} — build a GitHub issue draft from project state
|
|
59
|
+
|
|
60
|
+
${c.bold}Usage:${c.reset}
|
|
61
|
+
spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]
|
|
62
|
+
|
|
63
|
+
${c.bold}Options:${c.reset}
|
|
64
|
+
--type TYPE Issue type label: bug (default), enhancement, or question
|
|
65
|
+
--title TITLE Override issue title (default: diagnosis headline)
|
|
66
|
+
--json Print { title, body, labels, draftPath? } as JSON
|
|
67
|
+
--out PATH Write markdown body to PATH (default: ${DEFAULT_OUT_PATH})
|
|
68
|
+
--create Create GitHub issue via gh CLI (requires gh on PATH)
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {object} options
|
|
74
|
+
* @param {string} options.projectRoot
|
|
75
|
+
* @param {string[]} [options.args]
|
|
76
|
+
*/
|
|
77
|
+
export function runSpineIssueDraft(options) {
|
|
78
|
+
const { projectRoot, args: argv = [] } = options;
|
|
79
|
+
const parsed = parseIssueDraftArgs(argv);
|
|
80
|
+
if ("help" in parsed && parsed.help) {
|
|
81
|
+
printIssueDraftHelp();
|
|
82
|
+
return { exitCode: 0, output: "" };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let draft;
|
|
86
|
+
try {
|
|
87
|
+
draft = buildIssueDraftBody({
|
|
88
|
+
projectRoot,
|
|
89
|
+
issueType: parsed.issueType,
|
|
90
|
+
title: parsed.title ?? undefined,
|
|
91
|
+
});
|
|
92
|
+
} catch (err) {
|
|
93
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
94
|
+
return { exitCode: 1, output: `ERROR: ${message}\n` };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const draftPath = path.resolve(projectRoot, parsed.outPath);
|
|
98
|
+
let wroteDraft = false;
|
|
99
|
+
if (!parsed.json) {
|
|
100
|
+
fs.mkdirSync(path.dirname(draftPath), { recursive: true });
|
|
101
|
+
fs.writeFileSync(draftPath, draft.body, "utf-8");
|
|
102
|
+
wroteDraft = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (parsed.create) {
|
|
106
|
+
if (!commandExists("gh")) {
|
|
107
|
+
return {
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
output:
|
|
110
|
+
"ERROR: gh CLI not found on PATH. Install GitHub CLI or omit --create.\n",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const bodyFilePath = wroteDraft ? draftPath : path.join(projectRoot, ".spine", ".issue-draft-body.tmp.md");
|
|
115
|
+
if (!wroteDraft) {
|
|
116
|
+
fs.mkdirSync(path.dirname(bodyFilePath), { recursive: true });
|
|
117
|
+
fs.writeFileSync(bodyFilePath, draft.body, "utf-8");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const ghArgs = [
|
|
121
|
+
"issue",
|
|
122
|
+
"create",
|
|
123
|
+
"--title",
|
|
124
|
+
draft.title,
|
|
125
|
+
"--body-file",
|
|
126
|
+
bodyFilePath,
|
|
127
|
+
];
|
|
128
|
+
for (const label of draft.labels) {
|
|
129
|
+
ghArgs.push("--label", label);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const ghResult = spawnSync("gh", ghArgs, {
|
|
133
|
+
cwd: projectRoot,
|
|
134
|
+
encoding: "utf-8",
|
|
135
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!wroteDraft && bodyFilePath.endsWith(".issue-draft-body.tmp.md")) {
|
|
139
|
+
try {
|
|
140
|
+
fs.unlinkSync(bodyFilePath);
|
|
141
|
+
} catch {
|
|
142
|
+
// Best-effort cleanup of temp body file.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (ghResult.status !== 0) {
|
|
147
|
+
const stderr = (ghResult.stderr ?? "").trim();
|
|
148
|
+
return {
|
|
149
|
+
exitCode: ghResult.status ?? 1,
|
|
150
|
+
output: stderr ? `ERROR: ${stderr}\n` : "ERROR: gh issue create failed\n",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (parsed.json) {
|
|
156
|
+
const payload = {
|
|
157
|
+
title: draft.title,
|
|
158
|
+
body: draft.body,
|
|
159
|
+
labels: draft.labels,
|
|
160
|
+
};
|
|
161
|
+
if (wroteDraft) {
|
|
162
|
+
payload.draftPath = path.relative(projectRoot, draftPath);
|
|
163
|
+
}
|
|
164
|
+
return { exitCode: 0, output: `${JSON.stringify(payload, null, 2)}\n` };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const humanOutput = [`# ${draft.title}`, "", draft.body, ""].join("\n");
|
|
168
|
+
return { exitCode: 0, output: humanOutput };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {object} options
|
|
173
|
+
* @param {string} options.projectRoot
|
|
174
|
+
* @param {string[]} [options.args]
|
|
175
|
+
*/
|
|
176
|
+
export function runSpineIssue(options) {
|
|
177
|
+
const { projectRoot, args: argv = [] } = options;
|
|
178
|
+
const sub = argv[0];
|
|
179
|
+
if (sub !== "draft") {
|
|
180
|
+
return {
|
|
181
|
+
exitCode: 1,
|
|
182
|
+
output:
|
|
183
|
+
`Usage: spine issue draft [--type bug|enhancement|question] [--title TITLE] [--json] [--out PATH] [--create]\n`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return runSpineIssueDraft({ projectRoot, args: argv.slice(1) });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
190
|
+
const { exitCode, output } = runSpineIssue({
|
|
191
|
+
projectRoot: process.cwd(),
|
|
192
|
+
args: process.argv.slice(2),
|
|
193
|
+
});
|
|
194
|
+
process.stdout.write(output ?? "");
|
|
195
|
+
process.exit(exitCode);
|
|
196
|
+
}
|
package/bin/spine-journal.mjs
CHANGED
|
@@ -81,6 +81,7 @@ export function formatJournalReplayTable(events) {
|
|
|
81
81
|
const JOURNAL_USAGE =
|
|
82
82
|
"Usage:\n" +
|
|
83
83
|
" spine journal replay --batch {id} [--json]\n" +
|
|
84
|
+
" spine journal follow [--batch {id}] [--lane lane-N] [--json]\n" +
|
|
84
85
|
" spine journal export --batch {id} --format markdown|jsonl [--output path]\n";
|
|
85
86
|
|
|
86
87
|
/**
|
package/bin/spine-plan.mjs
CHANGED
|
@@ -30,6 +30,39 @@ function writePlanArtifact({ projectRoot, plan }) {
|
|
|
30
30
|
return artifactPath;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Format a friendly informational message when pending scope has zero tasks.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ excludedCount?: number, discoveredCount?: number }} meta
|
|
37
|
+
* @param {{ maxParallel?: number }} laneConfig
|
|
38
|
+
* @param {{ json?: boolean }} options
|
|
39
|
+
*/
|
|
40
|
+
function formatEmptyPendingResult({ excludedCount = 0, discoveredCount = 0 }, laneConfig, { json = false } = {}) {
|
|
41
|
+
if (json) {
|
|
42
|
+
const syntheticPlan = {
|
|
43
|
+
generatedAt: new Date().toISOString(),
|
|
44
|
+
scope: { mode: 'pending', taskIds: [] },
|
|
45
|
+
laneConfig,
|
|
46
|
+
waves: [],
|
|
47
|
+
tasks: {},
|
|
48
|
+
metadata: { tasksDiscovered: discoveredCount, tasksSelected: 0, tasksExcluded: excludedCount },
|
|
49
|
+
};
|
|
50
|
+
return { plan: syntheticPlan, artifactPath: null, output: JSON.stringify(syntheticPlan, null, 2) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const lines = [
|
|
54
|
+
'Spine plan — pending',
|
|
55
|
+
`0 task(s) · 0 wave(s) · maxParallel ${laneConfig.maxParallel ?? 1}`,
|
|
56
|
+
`${excludedCount} excluded (.DONE on disk)`,
|
|
57
|
+
'',
|
|
58
|
+
'No pending tasks — all discovered tasks have .DONE on disk.',
|
|
59
|
+
'',
|
|
60
|
+
'\u2192 spine plan all',
|
|
61
|
+
'',
|
|
62
|
+
];
|
|
63
|
+
return { plan: null, artifactPath: null, output: lines.join('\n') };
|
|
64
|
+
}
|
|
65
|
+
|
|
33
66
|
export async function runSpinePlan({
|
|
34
67
|
projectRoot = process.cwd(),
|
|
35
68
|
scope = 'all',
|
|
@@ -49,7 +82,22 @@ export async function runSpinePlan({
|
|
|
49
82
|
err.suggestedCommand = 'spine init';
|
|
50
83
|
throw err;
|
|
51
84
|
}
|
|
52
|
-
|
|
85
|
+
|
|
86
|
+
let plan;
|
|
87
|
+
try {
|
|
88
|
+
plan = buildPlan({ scope, config, tasksRoot });
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if (err?.code === 'NO_PENDING_TASKS') {
|
|
91
|
+
const laneConfig = { maxParallel: config.lanes?.maxParallel ?? 1 };
|
|
92
|
+
return formatEmptyPendingResult(
|
|
93
|
+
{ excludedCount: err.excludedCount, discoveredCount: err.discoveredCount },
|
|
94
|
+
laneConfig,
|
|
95
|
+
{ json },
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
|
|
53
101
|
const artifactPath = writePlanArtifact({ projectRoot, plan });
|
|
54
102
|
|
|
55
103
|
if (json) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Route `spine run` subcommands.
|
|
8
|
+
* - `spine run sequence <scope>` — planner wave sequence (GitHub #54 Tier 2)
|
|
9
|
+
* - `spine run <scope>` — alias for `spine batch start <scope>` (TP-024)
|
|
10
|
+
*
|
|
11
|
+
* @param {object} options
|
|
12
|
+
* @param {string} options.projectRoot
|
|
13
|
+
* @param {string[]} options.args
|
|
14
|
+
*/
|
|
15
|
+
export async function runSpineRun({ projectRoot, args }) {
|
|
16
|
+
if (args[0] === "sequence") {
|
|
17
|
+
const { runSpineSequence } = await import("../src/cli/sequence.mjs");
|
|
18
|
+
return runSpineSequence({
|
|
19
|
+
projectRoot,
|
|
20
|
+
args: args.slice(1),
|
|
21
|
+
spineBin: path.join(__dirname, "spine.mjs"),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { runSpineBatch } = await import("./spine-batch.mjs");
|
|
26
|
+
return runSpineBatch({
|
|
27
|
+
projectRoot,
|
|
28
|
+
args: ["start", ...args],
|
|
29
|
+
});
|
|
30
|
+
}
|
package/bin/spine-status.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { loadBatchStateFile } from "../src/batch/reconcile.mjs";
|
|
|
2
2
|
import { generateBatchPostMortem } from "../src/batch/postmortem.mjs";
|
|
3
3
|
import { readJournalEvents, readJournalTail } from "../src/batch/journal.mjs";
|
|
4
4
|
import { reconcileBatch } from "../src/batch/reconcile.mjs";
|
|
5
|
+
import { formatStatusJson } from "../src/batch/status-json.mjs";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @param {object} options
|
|
@@ -17,7 +18,7 @@ export function runSpineStatus(options) {
|
|
|
17
18
|
if (json) {
|
|
18
19
|
return {
|
|
19
20
|
exitCode: 0,
|
|
20
|
-
output:
|
|
21
|
+
output: formatStatusJson(result),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -32,10 +33,27 @@ export function runSpineStatus(options) {
|
|
|
32
33
|
if (result.diagnosis) {
|
|
33
34
|
lines.push(` Diagnosis: ${result.diagnosis}`);
|
|
34
35
|
}
|
|
36
|
+
if (result.macroPhase) {
|
|
37
|
+
lines.push(` Macro phase: ${result.macroPhaseLabel ?? result.macroPhase}`);
|
|
38
|
+
}
|
|
35
39
|
|
|
36
40
|
lines.push("", ` ${result.headline}`, "");
|
|
37
41
|
lines.push(` → ${result.suggestedCommand}`);
|
|
38
42
|
|
|
43
|
+
if (diagnose && result.mergeFailed) {
|
|
44
|
+
lines.push("");
|
|
45
|
+
lines.push(` Merge failed: ${result.failedMerges} wave(s)`);
|
|
46
|
+
if (result.failedWaveIndex != null) {
|
|
47
|
+
lines.push(` Failed wave: ${Number(result.failedWaveIndex) + 1} (index ${result.failedWaveIndex})`);
|
|
48
|
+
}
|
|
49
|
+
if (result.failedLane != null) {
|
|
50
|
+
lines.push(` Failed lane: ${result.failedLane}`);
|
|
51
|
+
}
|
|
52
|
+
if (result.lastError) {
|
|
53
|
+
lines.push(` Last error: ${result.lastError}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
39
57
|
if (result.alternatives?.length) {
|
|
40
58
|
lines.push("", " Alternatives:");
|
|
41
59
|
for (const alt of result.alternatives) {
|
package/bin/spine-tasks.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* FR-UXB-02: validate task PROMPT packets for a planner scope.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import path from 'node:path';
|
|
8
9
|
import { c, isCliEntrypoint, writeCommandResult } from './spine-cli/shared.mjs';
|
|
9
10
|
import { loadSpineConfig } from './spine-config.mjs';
|
|
10
11
|
import { resolveTasksRootPath } from '../src/config/env-overrides.mjs';
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
loadDependenciesJson,
|
|
17
18
|
loadTaskPacket,
|
|
18
19
|
} from '../src/tasks/packet/index.mjs';
|
|
20
|
+
import { collectStaleFileScopeMustChangeWarnings } from '../src/tasks/packet/validate-prompt.mjs';
|
|
19
21
|
import { parseScope } from '../src/planner/scope.mjs';
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -50,9 +52,10 @@ export function formatTasksValidateHuman({
|
|
|
50
52
|
* @param {object} packet
|
|
51
53
|
* @param {{ taskId: string, folderName: string }} discoveredTask
|
|
52
54
|
* @param {{ tasks?: Record<string, string[]> }} depsJson
|
|
55
|
+
* @param {string} [projectRoot]
|
|
53
56
|
* @returns {string[]}
|
|
54
57
|
*/
|
|
55
|
-
export function collectTaskAdvisoryWarnings(packet, discoveredTask, depsJson) {
|
|
58
|
+
export function collectTaskAdvisoryWarnings(packet, discoveredTask, depsJson, projectRoot) {
|
|
56
59
|
/** @type {string[]} */
|
|
57
60
|
const warnings = [];
|
|
58
61
|
|
|
@@ -84,6 +87,17 @@ export function collectTaskAdvisoryWarnings(packet, discoveredTask, depsJson) {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
if (projectRoot && packet.promptPath && packet.validation?.contract) {
|
|
91
|
+
const promptRelPath = path.relative(projectRoot, packet.promptPath);
|
|
92
|
+
warnings.push(
|
|
93
|
+
...collectStaleFileScopeMustChangeWarnings(
|
|
94
|
+
projectRoot,
|
|
95
|
+
packet.validation.contract,
|
|
96
|
+
promptRelPath,
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
return warnings;
|
|
88
102
|
}
|
|
89
103
|
|
|
@@ -207,7 +221,7 @@ export async function runSpineTasksValidate({
|
|
|
207
221
|
/** @type {string[]} */
|
|
208
222
|
const warnings = warningsOnly
|
|
209
223
|
? [
|
|
210
|
-
...collectTaskAdvisoryWarnings(packet, discoveredTask, depsJson),
|
|
224
|
+
...collectTaskAdvisoryWarnings(packet, discoveredTask, depsJson, projectRoot),
|
|
211
225
|
...(packet.validation?.warnings ?? []),
|
|
212
226
|
]
|
|
213
227
|
: [];
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* SPINE_TASK_FOLDER — absolute path to taskplane-tasks/TP-NNN-…/
|
|
9
9
|
* SPINE_WORKTREE — lane git worktree root
|
|
10
10
|
* SPINE_PROJECT_ROOT — pi-spine project root (journal + gate paths)
|
|
11
|
+
* SPINE_RULES_PROJECT_ROOT — lane worktree for rules manifest reads (SP-317)
|
|
11
12
|
* SPINE_BATCH_ID — active batch id
|
|
12
13
|
* SPINE_TASK_ID — e.g. TP-038
|
|
13
14
|
* SPINE_LANE_NUMBER — 1-based lane index
|
|
@@ -28,8 +29,31 @@ import {
|
|
|
28
29
|
import { reportTaskProgress } from "../src/worker-tools/report-progress.mjs";
|
|
29
30
|
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
30
31
|
import { loadSpineConfig } from "./spine-config.mjs";
|
|
32
|
+
import { isStubDeliveryOnlyScope } from "../src/batch/contract-stub-delivery.mjs";
|
|
33
|
+
import { writeWorkerDoneMarker } from "../src/batch/worker-output.mjs";
|
|
31
34
|
import { buildWorkerTailPrompt, taskIdFromFolder } from "../src/batch/worker-prompt.mjs";
|
|
32
|
-
import {
|
|
35
|
+
import { DEFAULT_TASKS_ROOT } from "../src/config/spine-init-constants.mjs";
|
|
36
|
+
import {
|
|
37
|
+
isPiExtensionConflictOutput,
|
|
38
|
+
shouldWorkerUsePiNoExtensions,
|
|
39
|
+
} from "../src/doctor/pi-extension-conflict.mjs";
|
|
40
|
+
import { parseContract, parsePrompt } from "../src/tasks/packet/parse-prompt.mjs";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Actionable hint when pi worker spawn fails on duplicate extension tool registration.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} output
|
|
46
|
+
* @returns {string|null}
|
|
47
|
+
*/
|
|
48
|
+
export function formatPiExtensionConflictHint(output) {
|
|
49
|
+
if (!isPiExtensionConflictOutput(output)) return null;
|
|
50
|
+
return [
|
|
51
|
+
"pi extension tool conflict detected (often duplicate pi-web-access npm + local checkout).",
|
|
52
|
+
"Batch workers pass pi -ne only when spine doctor detects duplicate pi-web-access sources.",
|
|
53
|
+
"Fix pi settings with `pi remove npm:pi-web-access -l` or remove the local path from",
|
|
54
|
+
"~/.pi/agent/settings.json, then retry the task.",
|
|
55
|
+
].join(" ");
|
|
56
|
+
}
|
|
33
57
|
|
|
34
58
|
function buildReviewJournal() {
|
|
35
59
|
return resolveBatchJournalContext();
|
|
@@ -75,7 +99,13 @@ export async function buildWorkerPiArgs({
|
|
|
75
99
|
? path.join(worktreePath, ".spine", "agents", "worker.md")
|
|
76
100
|
: null;
|
|
77
101
|
|
|
78
|
-
const
|
|
102
|
+
const projectRoot =
|
|
103
|
+
process.env.SPINE_RULES_PROJECT_ROOT || worktreePath || process.env.SPINE_PROJECT_ROOT || process.cwd();
|
|
104
|
+
const piArgs = [];
|
|
105
|
+
if (shouldWorkerUsePiNoExtensions({ projectRoot })) {
|
|
106
|
+
piArgs.push("-ne");
|
|
107
|
+
}
|
|
108
|
+
piArgs.push("-p", "--no-session");
|
|
79
109
|
if (workerAgentPath && fs.existsSync(workerAgentPath)) {
|
|
80
110
|
piArgs.push("--append-system-prompt", workerAgentPath);
|
|
81
111
|
}
|
|
@@ -83,7 +113,6 @@ export async function buildWorkerPiArgs({
|
|
|
83
113
|
piArgs.push(`@${promptPath}`);
|
|
84
114
|
}
|
|
85
115
|
appendWorkerAgentModelArgs(piArgs, spineConfig);
|
|
86
|
-
const projectRoot = process.env.SPINE_PROJECT_ROOT || worktreePath || process.cwd();
|
|
87
116
|
const taskFileScope = resolveTaskFileScope(taskFolder);
|
|
88
117
|
const tailPrompt = await buildWorkerTailPrompt({
|
|
89
118
|
worktreePath,
|
|
@@ -105,6 +134,105 @@ export async function buildWorkerPiArgs({
|
|
|
105
134
|
* @param {string} taskFolder
|
|
106
135
|
* @returns {string[]}
|
|
107
136
|
*/
|
|
137
|
+
const STUB_DELIVERY_CURRENT_STEP = "Complete";
|
|
138
|
+
const STUB_DELIVERY_STATUS = "✅ Complete";
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Update STATUS.md header lines or append a minimal stub delivery block.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} [existingContent]
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
146
|
+
export function applyStubDeliveryStatusBlock(existingContent = "") {
|
|
147
|
+
const lines = String(existingContent ?? "").split("\n");
|
|
148
|
+
let foundCurrentStep = false;
|
|
149
|
+
let foundStatus = false;
|
|
150
|
+
const updated = lines.map((line) => {
|
|
151
|
+
if (/^\*\*Current Step:\*\*/.test(line)) {
|
|
152
|
+
foundCurrentStep = true;
|
|
153
|
+
return `**Current Step:** ${STUB_DELIVERY_CURRENT_STEP}`;
|
|
154
|
+
}
|
|
155
|
+
if (/^\*\*Status:\*\*/.test(line)) {
|
|
156
|
+
foundStatus = true;
|
|
157
|
+
return `**Status:** ${STUB_DELIVERY_STATUS}`;
|
|
158
|
+
}
|
|
159
|
+
return line;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const additions = [];
|
|
163
|
+
if (!foundCurrentStep) {
|
|
164
|
+
additions.push(`**Current Step:** ${STUB_DELIVERY_CURRENT_STEP}`);
|
|
165
|
+
}
|
|
166
|
+
if (!foundStatus) {
|
|
167
|
+
additions.push(`**Status:** ${STUB_DELIVERY_STATUS}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (additions.length === 0) {
|
|
171
|
+
return updated.join("\n");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const titleIdx = updated.findIndex((line) => /^#\s/.test(line));
|
|
175
|
+
if (titleIdx >= 0) {
|
|
176
|
+
let insertAt = titleIdx + 1;
|
|
177
|
+
if (insertAt < updated.length && updated[insertAt].trim() === "") {
|
|
178
|
+
insertAt += 1;
|
|
179
|
+
}
|
|
180
|
+
updated.splice(insertAt, 0, ...additions, "");
|
|
181
|
+
return updated.join("\n");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (updated.length > 0 && updated[updated.length - 1].trim() !== "") {
|
|
185
|
+
updated.push("");
|
|
186
|
+
}
|
|
187
|
+
updated.push(...additions, "");
|
|
188
|
+
return updated.join("\n");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @param {string[]} patterns
|
|
193
|
+
*/
|
|
194
|
+
function stubDeliveryRequiresStatusTouch(patterns) {
|
|
195
|
+
return patterns.some((pattern) => {
|
|
196
|
+
const normalized = String(pattern ?? "").replace(/\\/g, "/").trim();
|
|
197
|
+
if (normalized.includes("STATUS.md")) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
if (normalized.endsWith("/**")) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* When stub mode has delivery-only fileScopeMustChange, write STATUS.md before .DONE.
|
|
209
|
+
*
|
|
210
|
+
* @param {object} options
|
|
211
|
+
* @param {string} options.taskFolder
|
|
212
|
+
* @param {string} [options.tasksRoot]
|
|
213
|
+
* @returns {boolean} Whether STATUS.md was updated
|
|
214
|
+
*/
|
|
215
|
+
export function writeStubDeliveryStatusIfNeeded({ taskFolder, tasksRoot = DEFAULT_TASKS_ROOT }) {
|
|
216
|
+
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
217
|
+
if (!fs.existsSync(promptPath)) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const parsed = parseContract(fs.readFileSync(promptPath, "utf-8"));
|
|
222
|
+
const patterns = parsed.fileScopeMustChange ?? [];
|
|
223
|
+
if (!isStubDeliveryOnlyScope(patterns, tasksRoot)) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (!stubDeliveryRequiresStatusTouch(patterns)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const statusPath = path.join(taskFolder, "STATUS.md");
|
|
231
|
+
const existing = fs.existsSync(statusPath) ? fs.readFileSync(statusPath, "utf-8") : "";
|
|
232
|
+
fs.writeFileSync(statusPath, applyStubDeliveryStatusBlock(existing), "utf-8");
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
|
|
108
236
|
function resolveTaskFileScope(taskFolder) {
|
|
109
237
|
const envScope = process.env.SPINE_TASK_FILE_SCOPE;
|
|
110
238
|
if (envScope) {
|
|
@@ -161,25 +289,25 @@ async function runWorkerRunner() {
|
|
|
161
289
|
const mode = process.argv.includes("--stub") ? "stub" : "pi";
|
|
162
290
|
|
|
163
291
|
if (mode === "stub") {
|
|
164
|
-
const
|
|
292
|
+
const parsedTaskId = path.basename(taskFolder).match(/^([A-Z]+-\d+)/)?.[1] ?? "";
|
|
165
293
|
const failTasks = String(process.env.SPINE_WORKER_STUB_FAIL_TASKS ?? "")
|
|
166
294
|
.split(/[,\s]+/)
|
|
167
295
|
.filter(Boolean);
|
|
168
|
-
if (failTasks.includes(
|
|
296
|
+
if (failTasks.includes(parsedTaskId)) {
|
|
169
297
|
const dirtyRel = process.env.SPINE_WORKER_STUB_DIRTY_FILE;
|
|
170
298
|
if (dirtyRel && worktreePath) {
|
|
171
299
|
const dirtyPath = path.join(worktreePath, dirtyRel);
|
|
172
300
|
fs.mkdirSync(path.dirname(dirtyPath), { recursive: true });
|
|
173
301
|
fs.writeFileSync(dirtyPath, `stub dirty ${new Date().toISOString()}\n`, "utf-8");
|
|
174
302
|
}
|
|
175
|
-
console.error(`stub worker forced failure for ${
|
|
303
|
+
console.error(`stub worker forced failure for ${parsedTaskId}`);
|
|
176
304
|
process.exit(1);
|
|
177
305
|
}
|
|
178
306
|
|
|
179
307
|
if (process.env.SPINE_WORKER_STUB_SAT020 === "1") {
|
|
180
308
|
const journal = buildReviewJournal();
|
|
181
309
|
const laneNumber = Number(process.env.SPINE_LANE_NUMBER || 1);
|
|
182
|
-
const taskId = process.env.SPINE_TASK_ID ||
|
|
310
|
+
const taskId = process.env.SPINE_TASK_ID || parsedTaskId;
|
|
183
311
|
const correlationId = process.env.SPINE_LANE_CORRELATION_ID;
|
|
184
312
|
// Let the host poll once before checkpoint signals land.
|
|
185
313
|
spawnSync("sleep", ["1"], { stdio: "ignore" });
|
|
@@ -256,12 +384,11 @@ async function runWorkerRunner() {
|
|
|
256
384
|
|
|
257
385
|
await enforceStubReviewIfConfigured(taskFolder, worktreePath);
|
|
258
386
|
|
|
387
|
+
writeStubDeliveryStatusIfNeeded({ taskFolder });
|
|
388
|
+
|
|
259
389
|
const donePath = path.join(taskFolder, ".DONE");
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
`Completed: ${new Date().toISOString()}\nTask: stub\n`,
|
|
263
|
-
"utf-8",
|
|
264
|
-
);
|
|
390
|
+
const stubTaskId = process.env.SPINE_TASK_ID || taskIdFromFolder(taskFolder) || "stub";
|
|
391
|
+
writeWorkerDoneMarker(donePath, { taskId: stubTaskId });
|
|
265
392
|
process.exit(0);
|
|
266
393
|
}
|
|
267
394
|
|
|
@@ -306,6 +433,11 @@ async function runWorkerRunner() {
|
|
|
306
433
|
}
|
|
307
434
|
|
|
308
435
|
if (result.status !== 0) {
|
|
436
|
+
const combined = `${result.stderr ?? ""}${result.stdout ?? ""}`;
|
|
437
|
+
const conflictHint = formatPiExtensionConflictHint(combined);
|
|
438
|
+
if (conflictHint) {
|
|
439
|
+
console.error(conflictHint);
|
|
440
|
+
}
|
|
309
441
|
process.stderr.write(result.stderr ?? "");
|
|
310
442
|
process.stdout.write(result.stdout ?? "");
|
|
311
443
|
process.exit(result.status ?? 1);
|