pi-spine 1.1.0 → 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/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/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-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +16 -2
- package/bin/spine-worker-runner.mjs +10 -10
- package/bin/spine.mjs +49 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/references/contract-template.md +19 -0
- 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 +312 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-verify.mjs +140 -2
- package/src/batch/detached-start.mjs +66 -2
- 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 +135 -68
- package/src/batch/engine-lanes/merge.mjs +110 -82
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +11 -1
- package/src/batch/engine.mjs +79 -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 +73 -7
- package/src/batch/integrate.mjs +2 -4
- package/src/batch/journal.mjs +3 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lifecycle.mjs +130 -3
- package/src/batch/macro-phase.mjs +226 -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 +74 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +223 -0
- package/src/batch/post-merge-limbo.mjs +264 -8
- package/src/batch/reconcile.mjs +429 -54
- package/src/batch/resume-common.mjs +5 -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 +67 -6
- package/src/batch/resume-multi.mjs +9 -4
- package/src/batch/resume.mjs +52 -45
- package/src/batch/retry.mjs +56 -5
- package/src/batch/review-spawn.mjs +8 -2
- 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 +22 -10
- package/src/batch/worker-host.mjs +95 -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 +108 -0
- package/src/cli/settings-set.mjs +2 -21
- 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-init-constants.mjs +1 -0
- package/src/config/spine-preflight-lib.mjs +471 -16
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +223 -18
- package/src/dashboard/public/index.html +14 -2
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +215 -1
- package/src/dashboard/view.mjs +170 -17
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/run-doctor-checks.mjs +26 -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/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 +42 -1
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/templates/spine-config.json +8 -1
package/src/batch/evidence.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
8
9
|
import { runEvidenceCommand } from "./evidence-command.mjs";
|
|
9
10
|
import { readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
10
11
|
import { generateBatchPostMortem } from "./postmortem.mjs";
|
|
@@ -117,6 +118,22 @@ export function buildTaskScorecard(batchState) {
|
|
|
117
118
|
return `${lines.join("\n")}\n`;
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} projectRoot
|
|
123
|
+
* @param {string} batchId
|
|
124
|
+
*/
|
|
125
|
+
export function evidenceCompletePath(projectRoot, batchId) {
|
|
126
|
+
return path.join(evidenceDir(projectRoot, batchId), ".complete");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} projectRoot
|
|
131
|
+
* @param {string} batchId
|
|
132
|
+
*/
|
|
133
|
+
export function isEvidenceBundleComplete(projectRoot, batchId) {
|
|
134
|
+
return fs.existsSync(evidenceCompletePath(projectRoot, batchId));
|
|
135
|
+
}
|
|
136
|
+
|
|
120
137
|
/**
|
|
121
138
|
* @param {object} ctx
|
|
122
139
|
* @param {string} ctx.projectRoot
|
|
@@ -124,7 +141,7 @@ export function buildTaskScorecard(batchState) {
|
|
|
124
141
|
* @param {object|null} [ctx.batchState]
|
|
125
142
|
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
126
143
|
*/
|
|
127
|
-
export function
|
|
144
|
+
export function collectCoreEvidenceBundle(ctx) {
|
|
128
145
|
const { projectRoot, batchId, batchState = null, config = null } = ctx;
|
|
129
146
|
const dir = evidenceDir(projectRoot, batchId);
|
|
130
147
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -135,17 +152,46 @@ export function collectEvidenceBundle(ctx) {
|
|
|
135
152
|
const reconciliation = reconcileBatch({ projectRoot, batchState, verbose: true });
|
|
136
153
|
const journalTail = readJournalTail(readJournalEvents(projectRoot, batchId));
|
|
137
154
|
const summary = generateBatchPostMortem(batchState, journalTail, reconciliation, projectRoot);
|
|
138
|
-
|
|
155
|
+
writeTextAtomic(path.join(dir, "summary.md"), summary);
|
|
139
156
|
evidenceRefs.push("evidence/summary.md");
|
|
140
157
|
|
|
141
158
|
const baseBranch = batchState?.baseBranch ?? config?.baseBranch ?? "main";
|
|
142
159
|
const orchBranch = batchState?.orchBranch ?? null;
|
|
143
160
|
if (orchBranch) {
|
|
144
161
|
const diffStat = collectDiffStat(projectRoot, baseBranch, orchBranch);
|
|
145
|
-
|
|
162
|
+
writeTextAtomic(path.join(dir, "diff-stat.txt"), `${diffStat}\n`);
|
|
146
163
|
evidenceRefs.push("evidence/diff-stat.txt");
|
|
147
164
|
}
|
|
148
165
|
|
|
166
|
+
for (const ref of collectWorkerOutputEvidenceRefs(projectRoot, batchId)) {
|
|
167
|
+
evidenceRefs.push(ref);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const name of fs.readdirSync(dir)) {
|
|
171
|
+
if (name.startsWith("salvage-") && name.endsWith(".json")) {
|
|
172
|
+
evidenceRefs.push(`evidence/${name}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {object} ctx
|
|
181
|
+
* @param {string} ctx.projectRoot
|
|
182
|
+
* @param {string} ctx.batchId
|
|
183
|
+
* @param {object|null} [ctx.batchState]
|
|
184
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
185
|
+
* @param {string[]} [ctx.evidenceRefs]
|
|
186
|
+
*/
|
|
187
|
+
export function collectExtendedEvidenceBundle(ctx) {
|
|
188
|
+
const { projectRoot, batchId, batchState = null, config = null } = ctx;
|
|
189
|
+
const dir = evidenceDir(projectRoot, batchId);
|
|
190
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
191
|
+
|
|
192
|
+
/** @type {string[]} */
|
|
193
|
+
const evidenceRefs = [...(ctx.evidenceRefs ?? [])];
|
|
194
|
+
|
|
149
195
|
const gates = config?.gates ?? {};
|
|
150
196
|
const testing = resolveTestingCommands(config, projectRoot);
|
|
151
197
|
const collectTest = gates.collectTestEvidence !== false;
|
|
@@ -153,33 +199,50 @@ export function collectEvidenceBundle(ctx) {
|
|
|
153
199
|
|
|
154
200
|
if (collectTest && testing.test) {
|
|
155
201
|
const result = runEvidenceCommand(projectRoot, testing.test);
|
|
156
|
-
|
|
202
|
+
writeTextAtomic(path.join(dir, "test-output.txt"), `${result.output}\n`);
|
|
157
203
|
evidenceRefs.push("evidence/test-output.txt");
|
|
158
204
|
}
|
|
159
205
|
|
|
160
206
|
if (collectBuild && testing.build) {
|
|
161
207
|
const result = runEvidenceCommand(projectRoot, testing.build);
|
|
162
|
-
|
|
208
|
+
writeTextAtomic(path.join(dir, "build-output.txt"), `${result.output}\n`);
|
|
163
209
|
evidenceRefs.push("evidence/build-output.txt");
|
|
164
210
|
}
|
|
165
211
|
|
|
166
212
|
if (testing.testWithCoverage) {
|
|
167
213
|
const result = runEvidenceCommand(projectRoot, testing.testWithCoverage);
|
|
168
|
-
|
|
214
|
+
writeTextAtomic(path.join(dir, "coverage-output.txt"), `${result.output}\n`);
|
|
169
215
|
evidenceRefs.push("evidence/coverage-output.txt");
|
|
170
216
|
}
|
|
171
217
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
218
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
219
|
+
}
|
|
175
220
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} projectRoot
|
|
223
|
+
* @param {string} batchId
|
|
224
|
+
* @param {string[]} evidenceRefs
|
|
225
|
+
*/
|
|
226
|
+
export function finalizeEvidenceBundleComplete(projectRoot, batchId, evidenceRefs) {
|
|
227
|
+
const completePayload = `${JSON.stringify({
|
|
228
|
+
completedAt: new Date().toISOString(),
|
|
229
|
+
evidenceRefs,
|
|
230
|
+
})}\n`;
|
|
231
|
+
writeTextAtomic(evidenceCompletePath(projectRoot, batchId), completePayload);
|
|
232
|
+
}
|
|
181
233
|
|
|
182
|
-
|
|
234
|
+
/**
|
|
235
|
+
* @param {object} ctx
|
|
236
|
+
* @param {string} ctx.projectRoot
|
|
237
|
+
* @param {string} ctx.batchId
|
|
238
|
+
* @param {object|null} [ctx.batchState]
|
|
239
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
240
|
+
*/
|
|
241
|
+
export function collectEvidenceBundle(ctx) {
|
|
242
|
+
const core = collectCoreEvidenceBundle(ctx);
|
|
243
|
+
const extended = collectExtendedEvidenceBundle({ ...ctx, evidenceRefs: core.evidenceRefs });
|
|
244
|
+
finalizeEvidenceBundleComplete(ctx.projectRoot, ctx.batchId, extended.evidenceRefs);
|
|
245
|
+
return { evidenceDir: extended.evidenceDir, evidenceRefs: extended.evidenceRefs };
|
|
183
246
|
}
|
|
184
247
|
|
|
185
248
|
/**
|
package/src/batch/gate.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import crypto from "node:crypto";
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { writeJsonAtomic } from "../fs/atomic-write.mjs";
|
|
10
|
+
import { collectCoreEvidenceBundle, collectExtendedEvidenceBundle, finalizeEvidenceBundleComplete } from "./evidence.mjs";
|
|
10
11
|
import { appendJournalEvent } from "./journal.mjs";
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -39,15 +40,7 @@ export function loadGateRecord(projectRoot, batchId) {
|
|
|
39
40
|
*/
|
|
40
41
|
export function saveGateRecord(projectRoot, gate) {
|
|
41
42
|
const filePath = gateRecordPath(projectRoot, gate.batchId);
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(filePath, `${JSON.stringify(gate, null, 2)}\n`, "utf-8");
|
|
44
|
-
|
|
45
|
-
const fd = fs.openSync(filePath, "r");
|
|
46
|
-
try {
|
|
47
|
-
fs.fsyncSync(fd);
|
|
48
|
-
} finally {
|
|
49
|
-
fs.closeSync(fd);
|
|
50
|
-
}
|
|
43
|
+
writeJsonAtomic(filePath, gate);
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
/**
|
|
@@ -74,15 +67,18 @@ export function openIntegrateGate(ctx) {
|
|
|
74
67
|
return { gate: existing, opened: false, evidenceRefs: existing.evidenceRefs ?? [] };
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
const
|
|
70
|
+
const core = collectCoreEvidenceBundle({ projectRoot, batchId, batchState, config });
|
|
71
|
+
/** @type {string[]} */
|
|
72
|
+
let evidenceRefs = [...core.evidenceRefs];
|
|
73
|
+
|
|
78
74
|
const gate = {
|
|
79
75
|
gateId: crypto.randomUUID(),
|
|
80
76
|
batchId,
|
|
81
77
|
kind: "integrate",
|
|
82
78
|
status: "pending",
|
|
83
79
|
openedAt: new Date().toISOString(),
|
|
84
|
-
evidenceRefs
|
|
85
|
-
summary: formatGateSummary({ kind: "integrate", status: "pending", evidenceRefs
|
|
80
|
+
evidenceRefs,
|
|
81
|
+
summary: formatGateSummary({ kind: "integrate", status: "pending", evidenceRefs }),
|
|
86
82
|
};
|
|
87
83
|
|
|
88
84
|
saveGateRecord(projectRoot, gate);
|
|
@@ -93,7 +89,40 @@ export function openIntegrateGate(ctx) {
|
|
|
93
89
|
evidenceRefs: gate.evidenceRefs,
|
|
94
90
|
});
|
|
95
91
|
|
|
96
|
-
|
|
92
|
+
appendJournalEvent(projectRoot, batchId, "gate.evidence_collecting", {
|
|
93
|
+
stage: "extended",
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** @type {string | null} */
|
|
97
|
+
let extendedError = null;
|
|
98
|
+
try {
|
|
99
|
+
const extended = collectExtendedEvidenceBundle({
|
|
100
|
+
projectRoot,
|
|
101
|
+
batchId,
|
|
102
|
+
batchState,
|
|
103
|
+
config,
|
|
104
|
+
evidenceRefs,
|
|
105
|
+
});
|
|
106
|
+
evidenceRefs = extended.evidenceRefs;
|
|
107
|
+
appendJournalEvent(projectRoot, batchId, "gate.evidence_completed", {
|
|
108
|
+
evidenceRefCount: evidenceRefs.length,
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
extendedError = err instanceof Error ? err.message : String(err);
|
|
112
|
+
appendJournalEvent(projectRoot, batchId, "gate.evidence_failed", {
|
|
113
|
+
message: extendedError.slice(0, 500),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
gate.evidenceRefs = evidenceRefs;
|
|
118
|
+
gate.summary = formatGateSummary({ kind: "integrate", status: "pending", evidenceRefs: gate.evidenceRefs });
|
|
119
|
+
saveGateRecord(projectRoot, gate);
|
|
120
|
+
|
|
121
|
+
if (!extendedError) {
|
|
122
|
+
finalizeEvidenceBundleComplete(projectRoot, batchId, evidenceRefs);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return { gate, opened: true, evidenceRefs: gate.evidenceRefs, extendedError };
|
|
97
126
|
}
|
|
98
127
|
|
|
99
128
|
/**
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared git path helpers for spine batch merge and lane commit.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { gitExec } from "./git-exec.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} projectRoot
|
|
10
|
+
* @param {string[]} paths
|
|
11
|
+
* @returns {{ stageable: string[], skipped: string[] }}
|
|
12
|
+
*/
|
|
13
|
+
export function filterGitignoredPaths(projectRoot, paths) {
|
|
14
|
+
const normalized = [...new Set(paths.filter(Boolean))];
|
|
15
|
+
if (normalized.length === 0) {
|
|
16
|
+
return { stageable: [], skipped: [] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @type {Set<string>} */
|
|
20
|
+
let ignoredSet = new Set();
|
|
21
|
+
try {
|
|
22
|
+
const output = execFileSync("git", ["check-ignore", "--no-index", "--stdin"], {
|
|
23
|
+
cwd: projectRoot,
|
|
24
|
+
input: `${normalized.join("\n")}\n`,
|
|
25
|
+
encoding: "utf-8",
|
|
26
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
27
|
+
});
|
|
28
|
+
for (const line of output.split("\n")) {
|
|
29
|
+
const trimmed = line.trim();
|
|
30
|
+
if (trimmed) ignoredSet.add(trimmed);
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
const execErr = /** @type {NodeJS.ErrnoException & { status?: number }} */ (err);
|
|
34
|
+
if (execErr.status === 1) {
|
|
35
|
+
return { stageable: normalized, skipped: [] };
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @type {string[]} */
|
|
41
|
+
const stageable = [];
|
|
42
|
+
/** @type {string[]} */
|
|
43
|
+
const skipped = [];
|
|
44
|
+
for (const filePath of normalized) {
|
|
45
|
+
if (ignoredSet.has(filePath)) {
|
|
46
|
+
skipped.push(filePath);
|
|
47
|
+
} else {
|
|
48
|
+
stageable.push(filePath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { stageable, skipped };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Stage paths while skipping gitignored entries. Never throws solely because a path is ignored.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} cwd
|
|
58
|
+
* @param {string[]} paths
|
|
59
|
+
* @param {{ projectRoot?: string, throwOnError?: boolean }} [options]
|
|
60
|
+
* @returns {{ added: string[], skipped: string[] }}
|
|
61
|
+
*/
|
|
62
|
+
export function gitAddFilteredPaths(cwd, paths, { projectRoot, throwOnError = true } = {}) {
|
|
63
|
+
const identityRoot = projectRoot ?? cwd;
|
|
64
|
+
const { stageable, skipped } = filterGitignoredPaths(cwd, paths);
|
|
65
|
+
if (stageable.length > 0) {
|
|
66
|
+
try {
|
|
67
|
+
gitExec(cwd, ["add", "--", ...stageable], { projectRoot: identityRoot, throwOnError });
|
|
68
|
+
} catch (err) {
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
if (
|
|
71
|
+
throwOnError &&
|
|
72
|
+
skipped.length === 0 &&
|
|
73
|
+
(message.includes("ignored") || message.includes("check-ignore"))
|
|
74
|
+
) {
|
|
75
|
+
const gitignoredErr = new Error(message);
|
|
76
|
+
gitignoredErr.name = "MergeGitignoredAddError";
|
|
77
|
+
throw gitignoredErr;
|
|
78
|
+
}
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { added: stageable, skipped };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {unknown} err
|
|
87
|
+
*/
|
|
88
|
+
export function isGitignoredAddError(err) {
|
|
89
|
+
if (!(err instanceof Error)) return false;
|
|
90
|
+
if (err.name === "MergeGitignoredAddError") return true;
|
|
91
|
+
const message = err.message.toLowerCase();
|
|
92
|
+
return (
|
|
93
|
+
message.includes("ignored by one of your .gitignore files") ||
|
|
94
|
+
(message.includes("git add") && message.includes("ignored"))
|
|
95
|
+
);
|
|
96
|
+
}
|
package/src/batch/heartbeat.mjs
CHANGED
|
@@ -12,6 +12,7 @@ const DEFAULT_GRACE_AFTER_PROGRESS_MIN = 15;
|
|
|
12
12
|
const DEFAULT_HEARTBEAT_INTERVAL_MIN = 10;
|
|
13
13
|
const DEFAULT_CHECKPOINT_WARNING_MIN = 10;
|
|
14
14
|
const DEFAULT_POST_DONE_GRACE_MIN = 4;
|
|
15
|
+
const DEFAULT_PROGRESS_SNAPSHOT_INTERVAL_MIN = 2;
|
|
15
16
|
const POLL_INTERVAL_MS = 30_000;
|
|
16
17
|
|
|
17
18
|
const CHECKPOINT_WARNING_SUGGESTION =
|
|
@@ -44,6 +45,8 @@ export function resolveStallConfig(config = {}) {
|
|
|
44
45
|
Number(lanes.checkpointWarningMinutes) || DEFAULT_CHECKPOINT_WARNING_MIN;
|
|
45
46
|
const postDoneGraceMinutes =
|
|
46
47
|
Number(lanes.postDoneGraceMinutes) || DEFAULT_POST_DONE_GRACE_MIN;
|
|
48
|
+
const progressSnapshotIntervalMinutes =
|
|
49
|
+
Number(lanes.progressSnapshotIntervalMinutes) || DEFAULT_PROGRESS_SNAPSHOT_INTERVAL_MIN;
|
|
47
50
|
|
|
48
51
|
return {
|
|
49
52
|
stallTimeoutMs: stallTimeoutMinutes * 60 * 1000,
|
|
@@ -51,6 +54,7 @@ export function resolveStallConfig(config = {}) {
|
|
|
51
54
|
heartbeatIntervalMs: heartbeatIntervalMinutes * 60 * 1000,
|
|
52
55
|
checkpointWarningMs: checkpointWarningMinutes * 60 * 1000,
|
|
53
56
|
postDoneGraceMs: postDoneGraceMinutes * 60 * 1000,
|
|
57
|
+
progressSnapshotIntervalMs: progressSnapshotIntervalMinutes * 60 * 1000,
|
|
54
58
|
extendGraceOnFileScope: lanes.extendGraceOnFileScope === true,
|
|
55
59
|
pollIntervalMs: POLL_INTERVAL_MS,
|
|
56
60
|
};
|
|
@@ -297,13 +301,13 @@ export function shouldEmitCheckpointWarning({
|
|
|
297
301
|
return now - lastCheckpointAt >= stallConfig.checkpointWarningMs;
|
|
298
302
|
}
|
|
299
303
|
|
|
300
|
-
/**
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
/** @param {object} params @param {number} params.startedAt @param {number} params.lastProgressAt @param {number} [params.lastAliveAt] @param {ReturnType<typeof resolveStallConfig>} params.stallConfig */
|
|
305
|
+
export function computeStallDeadline({ startedAt, lastProgressAt, lastAliveAt, stallConfig }) {
|
|
306
|
+
const stallAnchorAt = lastAliveAt ?? startedAt;
|
|
307
|
+
return Math.max(
|
|
308
|
+
stallAnchorAt + stallConfig.stallTimeoutMs,
|
|
309
|
+
lastProgressAt + stallConfig.graceAfterProgressMs,
|
|
310
|
+
);
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
/**
|
|
@@ -352,6 +356,68 @@ export function buildHeartbeatPayloadFields(signals, workerPhase, heartbeatKind)
|
|
|
352
356
|
};
|
|
353
357
|
}
|
|
354
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Bounded lane.progress_snapshot payload (issue #48).
|
|
361
|
+
*
|
|
362
|
+
* @param {object} signals
|
|
363
|
+
* @param {WorkerPhase} workerPhase
|
|
364
|
+
*/
|
|
365
|
+
export function buildProgressSnapshotPayload(signals, workerPhase) {
|
|
366
|
+
return {
|
|
367
|
+
workerPhase,
|
|
368
|
+
dirtyPathCount: signals.dirtyPaths?.length ?? 0,
|
|
369
|
+
lastCommitAtMs: signals.lastCommitAtMs ?? null,
|
|
370
|
+
statusMtimeMs: signals.statusMtimeMs ?? null,
|
|
371
|
+
stepCompletedAtMs: signals.stepCompletedAtMs ?? null,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @param {object | null} prev
|
|
377
|
+
* @param {object} next
|
|
378
|
+
*/
|
|
379
|
+
export function progressSnapshotPayloadChanged(prev, next) {
|
|
380
|
+
if (!prev) return true;
|
|
381
|
+
if (prev.workerPhase !== next.workerPhase) return true;
|
|
382
|
+
if (prev.dirtyPathCount !== next.dirtyPathCount) return true;
|
|
383
|
+
if (prev.lastCommitAtMs !== next.lastCommitAtMs) return true;
|
|
384
|
+
if (prev.statusMtimeMs !== next.statusMtimeMs) return true;
|
|
385
|
+
if (prev.stepCompletedAtMs !== next.stepCompletedAtMs) return true;
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @param {object} params
|
|
391
|
+
* @param {number} params.now
|
|
392
|
+
* @param {number} params.lastEmittedAt
|
|
393
|
+
* @param {number} params.intervalMs
|
|
394
|
+
*/
|
|
395
|
+
export function shouldEmitProgressSnapshot({ now, lastEmittedAt, intervalMs }) {
|
|
396
|
+
if (!intervalMs || intervalMs <= 0) return false;
|
|
397
|
+
return now - lastEmittedAt >= intervalMs;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* @param {object} params
|
|
402
|
+
*/
|
|
403
|
+
export function recordLaneProgressSnapshot({
|
|
404
|
+
projectRoot,
|
|
405
|
+
batchId,
|
|
406
|
+
laneNumber,
|
|
407
|
+
taskId,
|
|
408
|
+
signals,
|
|
409
|
+
correlationId,
|
|
410
|
+
workerPhase = "unknown",
|
|
411
|
+
}) {
|
|
412
|
+
const snapshot = buildProgressSnapshotPayload(signals, workerPhase);
|
|
413
|
+
appendJournalEvent(projectRoot, batchId, "lane.progress_snapshot", {
|
|
414
|
+
laneNumber,
|
|
415
|
+
taskId,
|
|
416
|
+
correlationId,
|
|
417
|
+
...snapshot,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
355
421
|
/**
|
|
356
422
|
* @param {object} params
|
|
357
423
|
* @param {WorkerPhase} [params.workerPhase]
|
package/src/batch/integrate.mjs
CHANGED
|
@@ -5,10 +5,8 @@
|
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
6
|
import { gitExec } from "./git-exec.mjs";
|
|
7
7
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
tryAutoResolveRulesManifestMergeConflict,
|
|
11
|
-
} from "./engine-lanes.mjs";
|
|
8
|
+
import { tryAutoResolveRulesManifestMergeConflict } from "./engine-lanes.mjs";
|
|
9
|
+
import { resolveRulesManifestIntegrateDrift } from "./rules-manifest-drift.mjs";
|
|
12
10
|
import { checkIntegrateGate } from "./gate.mjs";
|
|
13
11
|
import { appendJournalEvent } from "./journal.mjs";
|
|
14
12
|
import { countCommitsAhead } from "./lane-commit.mjs";
|
package/src/batch/journal.mjs
CHANGED
|
@@ -275,6 +275,9 @@ export function summarizeJournalEvent(event) {
|
|
|
275
275
|
if (payload.error) parts.push(String(payload.error).slice(0, 80));
|
|
276
276
|
if (payload.classification) parts.push(String(payload.classification));
|
|
277
277
|
if (payload.workerPhase) parts.push(`phase ${payload.workerPhase}`);
|
|
278
|
+
if (payload.dirtyPathCount != null && event.type === "lane.progress_snapshot") {
|
|
279
|
+
parts.push(`${payload.dirtyPathCount} dirty path(s)`);
|
|
280
|
+
}
|
|
278
281
|
if (payload.workerOutputLogRef) parts.push(`→ ${payload.workerOutputLogRef}`);
|
|
279
282
|
if (payload.exitReason) parts.push(String(payload.exitReason));
|
|
280
283
|
if (payload.mergeCommit) parts.push(`merge ${String(payload.mergeCommit).slice(0, 8)}`);
|
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { filterGitignoredPaths, gitAddFilteredPaths } from "./git-helpers.mjs";
|
|
8
9
|
import { gitExec } from "./git-exec.mjs";
|
|
10
|
+
import { parseContract } from "../tasks/packet/parse-prompt.mjs";
|
|
11
|
+
import {
|
|
12
|
+
hasReleaseCriticalContract,
|
|
13
|
+
shouldEnforceStubContractAtLaneCommit,
|
|
14
|
+
verifyStubFileScopeMustChange,
|
|
15
|
+
} from "./contract-verify.mjs";
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
18
|
* @param {string} worktreePath
|
|
@@ -104,6 +111,31 @@ export function countCommitsAhead(projectRoot, baseRef, headRef) {
|
|
|
104
111
|
return Number.parseInt(count, 10) || 0;
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
/**
|
|
115
|
+
* @param {string} worktreePath
|
|
116
|
+
*/
|
|
117
|
+
function listIgnoredUntrackedPaths(worktreePath) {
|
|
118
|
+
const output = execFileSync("git", ["ls-files", "-o", "-i", "--exclude-standard"], {
|
|
119
|
+
cwd: worktreePath,
|
|
120
|
+
encoding: "utf-8",
|
|
121
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
122
|
+
}).trim();
|
|
123
|
+
if (!output) return [];
|
|
124
|
+
return output.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {string} porcelain
|
|
129
|
+
* @returns {string[]}
|
|
130
|
+
*/
|
|
131
|
+
function listPorcelainPaths(porcelain) {
|
|
132
|
+
if (!porcelain?.trim()) return [];
|
|
133
|
+
return porcelain
|
|
134
|
+
.split("\n")
|
|
135
|
+
.map((line) => extractPorcelainPath(line))
|
|
136
|
+
.filter((entry) => Boolean(entry));
|
|
137
|
+
}
|
|
138
|
+
|
|
107
139
|
/**
|
|
108
140
|
* Stage and commit uncommitted lane work when the worker left a `.DONE` marker.
|
|
109
141
|
*
|
|
@@ -114,13 +146,24 @@ export function countCommitsAhead(projectRoot, baseRef, headRef) {
|
|
|
114
146
|
* @param {string} params.batchId
|
|
115
147
|
* @param {string} params.taskFolder Absolute path to task folder (for `.DONE` check)
|
|
116
148
|
* @param {string} [params.projectRoot] Main repo root for git identity resolution
|
|
117
|
-
* @
|
|
149
|
+
* @param {string} [params.baseBranch] Base branch for stub contract diff (default main)
|
|
150
|
+
* @returns {{ ok: true, committed: boolean, commitSha?: string, skippedGitignoredPaths?: string[] } | { ok: false, error: string, failureClass: string, gitignoredPaths?: string[] }}
|
|
118
151
|
*/
|
|
119
|
-
export function commitLaneWorktree({
|
|
152
|
+
export function commitLaneWorktree({
|
|
153
|
+
worktreePath,
|
|
154
|
+
taskBranch,
|
|
155
|
+
taskId,
|
|
156
|
+
batchId,
|
|
157
|
+
taskFolder,
|
|
158
|
+
projectRoot,
|
|
159
|
+
baseBranch = "main",
|
|
160
|
+
}) {
|
|
120
161
|
const identityRoot = projectRoot ?? worktreePath;
|
|
121
162
|
try {
|
|
122
163
|
const porcelain = gitPorcelain(worktreePath);
|
|
123
|
-
|
|
164
|
+
const dirtyPaths = listPorcelainPaths(porcelain);
|
|
165
|
+
const ignoredUntrackedPaths = listIgnoredUntrackedPaths(worktreePath);
|
|
166
|
+
if (dirtyPaths.length === 0 && ignoredUntrackedPaths.length === 0) {
|
|
124
167
|
return { ok: true, committed: false };
|
|
125
168
|
}
|
|
126
169
|
|
|
@@ -133,15 +176,57 @@ export function commitLaneWorktree({ worktreePath, taskBranch, taskId, batchId,
|
|
|
133
176
|
};
|
|
134
177
|
}
|
|
135
178
|
|
|
179
|
+
if (shouldEnforceStubContractAtLaneCommit(donePath)) {
|
|
180
|
+
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
181
|
+
const parsedContract = fs.existsSync(promptPath)
|
|
182
|
+
? parseContract(fs.readFileSync(promptPath, "utf-8"))
|
|
183
|
+
: { fileScopeMustChange: [] };
|
|
184
|
+
if (hasReleaseCriticalContract(parsedContract)) {
|
|
185
|
+
const scopeCheck = verifyStubFileScopeMustChange(
|
|
186
|
+
worktreePath,
|
|
187
|
+
parsedContract,
|
|
188
|
+
baseBranch,
|
|
189
|
+
dirtyPaths,
|
|
190
|
+
);
|
|
191
|
+
if (!scopeCheck.ok) {
|
|
192
|
+
return {
|
|
193
|
+
ok: false,
|
|
194
|
+
error: `Stub worker completed without required file-scope changes: ${scopeCheck.failures.join("; ")}`,
|
|
195
|
+
failureClass: "stub",
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const { stageable, skipped: gitignoredDirtyPaths } = filterGitignoredPaths(worktreePath, dirtyPaths);
|
|
202
|
+
const gitignoredPaths = [...new Set([...gitignoredDirtyPaths, ...ignoredUntrackedPaths])];
|
|
203
|
+
if (stageable.length === 0 && gitignoredPaths.length > 0) {
|
|
204
|
+
const preview = gitignoredPaths.slice(0, 20).join(", ");
|
|
205
|
+
const suffix = gitignoredPaths.length > 20 ? "…" : "";
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
error:
|
|
209
|
+
`Lane worktree has gitignored dirty files only (${preview}${suffix}) — ` +
|
|
210
|
+
"remove from the index with git rm --cached on the task branch before resume",
|
|
211
|
+
failureClass: "GitignoredDirtyWorktree",
|
|
212
|
+
gitignoredPaths,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
136
216
|
const currentBranch = git(worktreePath, ["rev-parse", "--abbrev-ref", "HEAD"], identityRoot);
|
|
137
217
|
if (currentBranch !== taskBranch) {
|
|
138
218
|
git(worktreePath, ["checkout", taskBranch], identityRoot);
|
|
139
219
|
}
|
|
140
|
-
|
|
220
|
+
const addResult = gitAddFilteredPaths(worktreePath, stageable, { projectRoot: identityRoot });
|
|
141
221
|
const message = `feat(${taskId}): batch ${batchId} worker completion`;
|
|
142
222
|
git(worktreePath, ["commit", "-m", message], identityRoot);
|
|
143
223
|
const commitSha = git(worktreePath, ["rev-parse", "HEAD"], identityRoot);
|
|
144
|
-
return {
|
|
224
|
+
return {
|
|
225
|
+
ok: true,
|
|
226
|
+
committed: true,
|
|
227
|
+
commitSha,
|
|
228
|
+
skippedGitignoredPaths: [...addResult.skipped, ...gitignoredPaths],
|
|
229
|
+
};
|
|
145
230
|
} catch (err) {
|
|
146
231
|
const message = err instanceof Error ? err.message : String(err);
|
|
147
232
|
return {
|