pi-spine 1.6.0 → 1.7.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-wait.mjs +12 -0
- package/package.json +2 -2
- package/skills/spine-release-operator/SKILL.md +37 -7
- package/src/batch/attached-runner.mjs +18 -7
- package/src/batch/contract-task-start.mjs +12 -7
- package/src/batch/contract-verify.mjs +25 -1
- package/src/batch/detached-spawn.mjs +78 -0
- package/src/batch/detached-start.mjs +25 -71
- package/src/batch/diagnosis.mjs +25 -2
- package/src/batch/evidence.mjs +30 -250
- package/src/batch/gate-evidence-collect.mjs +172 -0
- package/src/batch/gate-evidence-read.mjs +145 -0
- package/src/batch/gate.mjs +28 -38
- package/src/batch/lane-dirty-check.mjs +102 -0
- package/src/batch/lifecycle.mjs +6 -5
- package/src/batch/post-merge-limbo.mjs +1 -1
- package/src/batch/postmortem.mjs +1 -2
- package/src/batch/reconcile.mjs +1 -1
- package/src/batch/resume-common.mjs +7 -1
- package/src/batch/resume-multi-validate.mjs +25 -101
- package/src/batch/resume-validation.mjs +120 -0
- package/src/batch/sequence.mjs +11 -2
- package/src/batch/supervisor-spawn.mjs +379 -0
- package/src/cli/spine-wait.mjs +114 -0
- package/src/cli/wait.mjs +7 -43
- package/src/config/defaults.mjs +4 -1
- package/src/config/settings-fields.mjs +23 -0
- package/src/config/spine-config-load.mjs +6 -0
- package/src/config/spine-config-schema.mjs +121 -0
- package/src/config/spine-init-constants.mjs +19 -1
- package/src/config/worktree-setup-hook.mjs +221 -0
- package/src/doctor/agent-models.mjs +1 -0
- package/src/doctor/run-doctor-checks.mjs +14 -0
- package/src/doctor/supervisor.mjs +66 -0
- package/src/doctor/worktree-health.mjs +1 -1
- package/templates/agents/supervisor.md +27 -18
- package/templates/spine-config.json +16 -1
package/src/batch/evidence.mjs
CHANGED
|
@@ -1,137 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Integrate gate evidence bundle (PRD §12.2, FR-GATE).
|
|
3
|
+
* Collection orchestration lives in gate.mjs; path readers in gate-evidence-read.mjs (SP-432 / #83-D).
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { execFileSync } from "node:child_process";
|
|
8
|
-
import { writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
9
|
-
import { runEvidenceCommand } from "./evidence-command.mjs";
|
|
10
|
-
import { readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
11
|
-
import { generateBatchPostMortem } from "./postmortem.mjs";
|
|
12
6
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {ReturnType<typeof loadSpineConfig>["config"]} config
|
|
41
|
-
* @param {string} projectRoot
|
|
42
|
-
*/
|
|
43
|
-
export function resolveTestingCommands(config, projectRoot) {
|
|
44
|
-
const spineTesting = config?.testing ?? {};
|
|
45
|
-
const taskplane = readTaskplaneTestingCommands(projectRoot) ?? {};
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
test:
|
|
49
|
-
(typeof spineTesting.test === "string" && spineTesting.test.trim()) ||
|
|
50
|
-
(typeof taskplane.unit === "string" && taskplane.unit.trim()) ||
|
|
51
|
-
(typeof taskplane.test === "string" && taskplane.test.trim()) ||
|
|
52
|
-
"",
|
|
53
|
-
build:
|
|
54
|
-
(typeof spineTesting.build === "string" && spineTesting.build.trim()) ||
|
|
55
|
-
(typeof taskplane.build === "string" && taskplane.build.trim()) ||
|
|
56
|
-
"",
|
|
57
|
-
testWithCoverage:
|
|
58
|
-
(typeof spineTesting.testWithCoverage === "string" && spineTesting.testWithCoverage.trim()) ||
|
|
59
|
-
(typeof taskplane.testWithCoverage === "string" && taskplane.testWithCoverage.trim()) ||
|
|
60
|
-
"",
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {string} projectRoot
|
|
66
|
-
* @param {string} baseBranch
|
|
67
|
-
* @param {string} orchBranch
|
|
68
|
-
*/
|
|
69
|
-
function collectDiffStat(projectRoot, baseBranch, orchBranch) {
|
|
70
|
-
try {
|
|
71
|
-
return execFileSync("git", ["diff", "--stat", `${baseBranch}..${orchBranch}`], {
|
|
72
|
-
cwd: projectRoot,
|
|
73
|
-
encoding: "utf-8",
|
|
74
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
75
|
-
}).trim();
|
|
76
|
-
} catch (err) {
|
|
77
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
78
|
-
return `(git diff --stat failed: ${message})`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @param {object|null|undefined} batchState
|
|
84
|
-
*/
|
|
85
|
-
export function buildTaskScorecard(batchState) {
|
|
86
|
-
const tasks = Array.isArray(batchState?.tasks) ? batchState.tasks : [];
|
|
87
|
-
const lines = [
|
|
88
|
-
"# Batch evidence summary",
|
|
89
|
-
"",
|
|
90
|
-
`| Field | Value |`,
|
|
91
|
-
`|-------|-------|`,
|
|
92
|
-
`| Batch ID | ${batchState?.batchId ?? batchState?.id ?? "—"} |`,
|
|
93
|
-
`| Phase | ${batchState?.phase ?? "—"} |`,
|
|
94
|
-
`| Base branch | ${batchState?.baseBranch ?? "—"} |`,
|
|
95
|
-
`| Orch branch | ${batchState?.orchBranch ?? "—"} |`,
|
|
96
|
-
`| Tasks (total) | ${batchState?.totalTasks ?? tasks.length} |`,
|
|
97
|
-
`| Succeeded | ${batchState?.succeededTasks ?? "—"} |`,
|
|
98
|
-
`| Failed | ${batchState?.failedTasks ?? "—"} |`,
|
|
99
|
-
"",
|
|
100
|
-
"## Task scorecard",
|
|
101
|
-
"",
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
if (tasks.length === 0) {
|
|
105
|
-
lines.push("_No task rows in batch state._");
|
|
106
|
-
} else {
|
|
107
|
-
lines.push("| Task | Status | Done file |");
|
|
108
|
-
lines.push("|------|--------|-----------|");
|
|
109
|
-
for (const task of tasks) {
|
|
110
|
-
lines.push(
|
|
111
|
-
`| ${task.taskId ?? "—"} | ${task.status ?? "—"} | ${task.doneFileFound ? "yes" : "no"} |`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
lines.push("", "_Generated by pi-spine integrate gate (TP-021)._");
|
|
117
|
-
return `${lines.join("\n")}\n`;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @param {string} projectRoot
|
|
122
|
-
* @param {string} batchId
|
|
123
|
-
*/
|
|
124
|
-
export function evidenceCompletePath(projectRoot, batchId) {
|
|
125
|
-
return path.join(evidenceDir(projectRoot, batchId), ".complete");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @param {string} projectRoot
|
|
130
|
-
* @param {string} batchId
|
|
131
|
-
*/
|
|
132
|
-
export function isEvidenceBundleComplete(projectRoot, batchId) {
|
|
133
|
-
return fs.existsSync(evidenceCompletePath(projectRoot, batchId));
|
|
134
|
-
}
|
|
7
|
+
import {
|
|
8
|
+
buildTaskScorecard,
|
|
9
|
+
evidenceCompletePath,
|
|
10
|
+
evidenceDir,
|
|
11
|
+
isEvidenceBundleComplete,
|
|
12
|
+
resolveTestingCommands,
|
|
13
|
+
} from "./gate-evidence-read.mjs";
|
|
14
|
+
import {
|
|
15
|
+
collectCoreEvidenceBundle as gateCollectCoreEvidenceBundle,
|
|
16
|
+
collectExtendedEvidenceBundle as gateCollectExtendedEvidenceBundle,
|
|
17
|
+
collectEvidenceBundle as gateCollectEvidenceBundle,
|
|
18
|
+
finalizeEvidenceBundleComplete as gateFinalizeEvidenceBundleComplete,
|
|
19
|
+
} from "./gate-evidence-collect.mjs";
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
buildTaskScorecard,
|
|
23
|
+
evidenceCompletePath,
|
|
24
|
+
evidenceDir,
|
|
25
|
+
isEvidenceBundleComplete,
|
|
26
|
+
resolveTestingCommands,
|
|
27
|
+
};
|
|
135
28
|
|
|
136
29
|
/**
|
|
137
30
|
* @param {object} ctx
|
|
@@ -139,128 +32,15 @@ export function isEvidenceBundleComplete(projectRoot, batchId) {
|
|
|
139
32
|
* @param {string} ctx.batchId
|
|
140
33
|
* @param {object|null} [ctx.batchState]
|
|
141
34
|
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
35
|
+
* @param {object} [ctx.reconciliation]
|
|
142
36
|
*/
|
|
143
37
|
export function collectCoreEvidenceBundle(ctx) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/** @type {string[]} */
|
|
149
|
-
const evidenceRefs = [];
|
|
150
|
-
|
|
151
|
-
const reconciliation = reconcileBatch({ projectRoot, batchState, verbose: true });
|
|
152
|
-
const journalTail = readJournalTail(readJournalEvents(projectRoot, batchId));
|
|
153
|
-
const summary = generateBatchPostMortem(batchState, journalTail, reconciliation, projectRoot);
|
|
154
|
-
writeTextAtomic(path.join(dir, "summary.md"), summary);
|
|
155
|
-
evidenceRefs.push("evidence/summary.md");
|
|
156
|
-
|
|
157
|
-
const baseBranch = batchState?.baseBranch ?? config?.baseBranch ?? "main";
|
|
158
|
-
const orchBranch = batchState?.orchBranch ?? null;
|
|
159
|
-
if (orchBranch) {
|
|
160
|
-
const diffStat = collectDiffStat(projectRoot, baseBranch, orchBranch);
|
|
161
|
-
writeTextAtomic(path.join(dir, "diff-stat.txt"), `${diffStat}\n`);
|
|
162
|
-
evidenceRefs.push("evidence/diff-stat.txt");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
for (const ref of collectWorkerOutputEvidenceRefs(projectRoot, batchId)) {
|
|
166
|
-
evidenceRefs.push(ref);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
for (const name of fs.readdirSync(dir)) {
|
|
170
|
-
if (name.startsWith("salvage-") && name.endsWith(".json")) {
|
|
171
|
-
evidenceRefs.push(`evidence/${name}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return { evidenceDir: dir, evidenceRefs };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @param {object} ctx
|
|
180
|
-
* @param {string} ctx.projectRoot
|
|
181
|
-
* @param {string} ctx.batchId
|
|
182
|
-
* @param {object|null} [ctx.batchState]
|
|
183
|
-
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
184
|
-
* @param {string[]} [ctx.evidenceRefs]
|
|
185
|
-
*/
|
|
186
|
-
export function collectExtendedEvidenceBundle(ctx) {
|
|
187
|
-
const { projectRoot, batchId, config = null } = ctx;
|
|
188
|
-
const dir = evidenceDir(projectRoot, batchId);
|
|
189
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
190
|
-
|
|
191
|
-
/** @type {string[]} */
|
|
192
|
-
const evidenceRefs = [...(ctx.evidenceRefs ?? [])];
|
|
193
|
-
|
|
194
|
-
const gates = config?.gates ?? {};
|
|
195
|
-
const testing = resolveTestingCommands(config, projectRoot);
|
|
196
|
-
const collectTest = gates.collectTestEvidence !== false;
|
|
197
|
-
const collectBuild = gates.collectBuildEvidence === true;
|
|
198
|
-
|
|
199
|
-
if (collectTest && testing.test) {
|
|
200
|
-
const result = runEvidenceCommand(projectRoot, testing.test);
|
|
201
|
-
writeTextAtomic(path.join(dir, "test-output.txt"), `${result.output}\n`);
|
|
202
|
-
evidenceRefs.push("evidence/test-output.txt");
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (collectBuild && testing.build) {
|
|
206
|
-
const result = runEvidenceCommand(projectRoot, testing.build);
|
|
207
|
-
writeTextAtomic(path.join(dir, "build-output.txt"), `${result.output}\n`);
|
|
208
|
-
evidenceRefs.push("evidence/build-output.txt");
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (testing.testWithCoverage) {
|
|
212
|
-
const result = runEvidenceCommand(projectRoot, testing.testWithCoverage);
|
|
213
|
-
writeTextAtomic(path.join(dir, "coverage-output.txt"), `${result.output}\n`);
|
|
214
|
-
evidenceRefs.push("evidence/coverage-output.txt");
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return { evidenceDir: dir, evidenceRefs };
|
|
38
|
+
const reconciliation =
|
|
39
|
+
ctx.reconciliation ??
|
|
40
|
+
reconcileBatch({ projectRoot: ctx.projectRoot, batchState: ctx.batchState ?? null, verbose: true });
|
|
41
|
+
return gateCollectCoreEvidenceBundle({ ...ctx, reconciliation });
|
|
218
42
|
}
|
|
219
43
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
* @param {string[]} evidenceRefs
|
|
224
|
-
*/
|
|
225
|
-
export function finalizeEvidenceBundleComplete(projectRoot, batchId, evidenceRefs) {
|
|
226
|
-
const completePayload = `${JSON.stringify({
|
|
227
|
-
completedAt: new Date().toISOString(),
|
|
228
|
-
evidenceRefs,
|
|
229
|
-
})}\n`;
|
|
230
|
-
writeTextAtomic(evidenceCompletePath(projectRoot, batchId), completePayload);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* @param {object} ctx
|
|
235
|
-
* @param {string} ctx.projectRoot
|
|
236
|
-
* @param {string} ctx.batchId
|
|
237
|
-
* @param {object|null} [ctx.batchState]
|
|
238
|
-
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
239
|
-
*/
|
|
240
|
-
export function collectEvidenceBundle(ctx) {
|
|
241
|
-
const core = collectCoreEvidenceBundle(ctx);
|
|
242
|
-
const extended = collectExtendedEvidenceBundle({ ...ctx, evidenceRefs: core.evidenceRefs });
|
|
243
|
-
finalizeEvidenceBundleComplete(ctx.projectRoot, ctx.batchId, extended.evidenceRefs);
|
|
244
|
-
return { evidenceDir: extended.evidenceDir, evidenceRefs: extended.evidenceRefs };
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* @param {string} projectRoot
|
|
249
|
-
* @param {string} batchId
|
|
250
|
-
*/
|
|
251
|
-
function collectWorkerOutputEvidenceRefs(projectRoot, batchId) {
|
|
252
|
-
const lanesDir = path.join(projectRoot, ".spine", "runtime", batchId, "lanes");
|
|
253
|
-
if (!fs.existsSync(lanesDir)) return [];
|
|
254
|
-
|
|
255
|
-
/** @type {string[]} */
|
|
256
|
-
const refs = [];
|
|
257
|
-
for (const laneDir of fs.readdirSync(lanesDir)) {
|
|
258
|
-
if (!laneDir.startsWith("lane-")) continue;
|
|
259
|
-
const lanePath = path.join(lanesDir, laneDir);
|
|
260
|
-
for (const name of fs.readdirSync(lanePath)) {
|
|
261
|
-
if (!name.startsWith("worker-output-") || !name.endsWith(".log")) continue;
|
|
262
|
-
refs.push(path.join(".spine", "runtime", batchId, "lanes", laneDir, name));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return refs.sort();
|
|
266
|
-
}
|
|
44
|
+
export const collectExtendedEvidenceBundle = gateCollectExtendedEvidenceBundle;
|
|
45
|
+
export const finalizeEvidenceBundleComplete = gateFinalizeEvidenceBundleComplete;
|
|
46
|
+
export const collectEvidenceBundle = gateCollectEvidenceBundle;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integrate gate evidence collection (SP-432 / #83-D).
|
|
3
|
+
* Split from gate.mjs to keep gate FSM under phase-23 LOC policy.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
10
|
+
import { runEvidenceCommand } from "./evidence-command.mjs";
|
|
11
|
+
import {
|
|
12
|
+
evidenceCompletePath,
|
|
13
|
+
evidenceDir,
|
|
14
|
+
resolveTestingCommands,
|
|
15
|
+
} from "./gate-evidence-read.mjs";
|
|
16
|
+
import { readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
17
|
+
import { generateBatchPostMortem } from "./postmortem.mjs";
|
|
18
|
+
import { reconcileBatch } from "./reconcile.mjs";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} projectRoot
|
|
22
|
+
* @param {string} baseBranch
|
|
23
|
+
* @param {string} orchBranch
|
|
24
|
+
*/
|
|
25
|
+
function collectDiffStat(projectRoot, baseBranch, orchBranch) {
|
|
26
|
+
try {
|
|
27
|
+
return execFileSync("git", ["diff", "--stat", `${baseBranch}..${orchBranch}`], {
|
|
28
|
+
cwd: projectRoot,
|
|
29
|
+
encoding: "utf-8",
|
|
30
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
31
|
+
}).trim();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
34
|
+
return `(git diff --stat failed: ${message})`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} projectRoot
|
|
40
|
+
* @param {string} batchId
|
|
41
|
+
*/
|
|
42
|
+
function collectWorkerOutputEvidenceRefs(projectRoot, batchId) {
|
|
43
|
+
const lanesDir = path.join(projectRoot, ".spine", "runtime", batchId, "lanes");
|
|
44
|
+
if (!fs.existsSync(lanesDir)) return [];
|
|
45
|
+
|
|
46
|
+
/** @type {string[]} */
|
|
47
|
+
const refs = [];
|
|
48
|
+
for (const laneDir of fs.readdirSync(lanesDir)) {
|
|
49
|
+
if (!laneDir.startsWith("lane-")) continue;
|
|
50
|
+
const lanePath = path.join(lanesDir, laneDir);
|
|
51
|
+
for (const name of fs.readdirSync(lanePath)) {
|
|
52
|
+
if (!name.startsWith("worker-output-") || !name.endsWith(".log")) continue;
|
|
53
|
+
refs.push(path.join(".spine", "runtime", batchId, "lanes", laneDir, name));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return refs.sort();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {object} ctx
|
|
61
|
+
* @param {string} ctx.projectRoot
|
|
62
|
+
* @param {string} ctx.batchId
|
|
63
|
+
* @param {object|null} [ctx.batchState]
|
|
64
|
+
* @param {ReturnType<typeof import("../config/spine-config-load.mjs").loadSpineConfig>["config"]} [ctx.config]
|
|
65
|
+
* @param {object} ctx.reconciliation
|
|
66
|
+
*/
|
|
67
|
+
export function collectCoreEvidenceBundle(ctx) {
|
|
68
|
+
const { projectRoot, batchId, batchState = null, config = null, reconciliation } = ctx;
|
|
69
|
+
const dir = evidenceDir(projectRoot, batchId);
|
|
70
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
71
|
+
|
|
72
|
+
/** @type {string[]} */
|
|
73
|
+
const evidenceRefs = [];
|
|
74
|
+
|
|
75
|
+
const journalTail = readJournalTail(readJournalEvents(projectRoot, batchId));
|
|
76
|
+
const summary = generateBatchPostMortem(batchState, journalTail, reconciliation, projectRoot);
|
|
77
|
+
writeTextAtomic(path.join(dir, "summary.md"), summary);
|
|
78
|
+
evidenceRefs.push("evidence/summary.md");
|
|
79
|
+
|
|
80
|
+
const baseBranch = batchState?.baseBranch ?? config?.baseBranch ?? "main";
|
|
81
|
+
const orchBranch = batchState?.orchBranch ?? null;
|
|
82
|
+
if (orchBranch) {
|
|
83
|
+
const diffStat = collectDiffStat(projectRoot, baseBranch, orchBranch);
|
|
84
|
+
writeTextAtomic(path.join(dir, "diff-stat.txt"), `${diffStat}\n`);
|
|
85
|
+
evidenceRefs.push("evidence/diff-stat.txt");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const ref of collectWorkerOutputEvidenceRefs(projectRoot, batchId)) {
|
|
89
|
+
evidenceRefs.push(ref);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const name of fs.readdirSync(dir)) {
|
|
93
|
+
if (name.startsWith("salvage-") && name.endsWith(".json")) {
|
|
94
|
+
evidenceRefs.push(`evidence/${name}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {object} ctx
|
|
103
|
+
* @param {string} ctx.projectRoot
|
|
104
|
+
* @param {string} ctx.batchId
|
|
105
|
+
* @param {object|null} [ctx.batchState]
|
|
106
|
+
* @param {ReturnType<typeof import("../config/spine-config-load.mjs").loadSpineConfig>["config"]} [ctx.config]
|
|
107
|
+
* @param {string[]} [ctx.evidenceRefs]
|
|
108
|
+
*/
|
|
109
|
+
export function collectExtendedEvidenceBundle(ctx) {
|
|
110
|
+
const { projectRoot, batchId, config = null } = ctx;
|
|
111
|
+
const dir = evidenceDir(projectRoot, batchId);
|
|
112
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
+
|
|
114
|
+
/** @type {string[]} */
|
|
115
|
+
const evidenceRefs = [...(ctx.evidenceRefs ?? [])];
|
|
116
|
+
|
|
117
|
+
const gates = config?.gates ?? {};
|
|
118
|
+
const testing = resolveTestingCommands(config, projectRoot);
|
|
119
|
+
const collectTest = gates.collectTestEvidence !== false;
|
|
120
|
+
const collectBuild = gates.collectBuildEvidence === true;
|
|
121
|
+
|
|
122
|
+
if (collectTest && testing.test) {
|
|
123
|
+
const result = runEvidenceCommand(projectRoot, testing.test);
|
|
124
|
+
writeTextAtomic(path.join(dir, "test-output.txt"), `${result.output}\n`);
|
|
125
|
+
evidenceRefs.push("evidence/test-output.txt");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (collectBuild && testing.build) {
|
|
129
|
+
const result = runEvidenceCommand(projectRoot, testing.build);
|
|
130
|
+
writeTextAtomic(path.join(dir, "build-output.txt"), `${result.output}\n`);
|
|
131
|
+
evidenceRefs.push("evidence/build-output.txt");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (testing.testWithCoverage) {
|
|
135
|
+
const result = runEvidenceCommand(projectRoot, testing.testWithCoverage);
|
|
136
|
+
writeTextAtomic(path.join(dir, "coverage-output.txt"), `${result.output}\n`);
|
|
137
|
+
evidenceRefs.push("evidence/coverage-output.txt");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {string} projectRoot
|
|
145
|
+
* @param {string} batchId
|
|
146
|
+
* @param {string[]} evidenceRefs
|
|
147
|
+
*/
|
|
148
|
+
export function finalizeEvidenceBundleComplete(projectRoot, batchId, evidenceRefs) {
|
|
149
|
+
const completePayload = `${JSON.stringify({
|
|
150
|
+
completedAt: new Date().toISOString(),
|
|
151
|
+
evidenceRefs,
|
|
152
|
+
})}\n`;
|
|
153
|
+
writeTextAtomic(evidenceCompletePath(projectRoot, batchId), completePayload);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {object} ctx
|
|
158
|
+
* @param {string} ctx.projectRoot
|
|
159
|
+
* @param {string} ctx.batchId
|
|
160
|
+
* @param {object|null} [ctx.batchState]
|
|
161
|
+
* @param {ReturnType<typeof import("../config/spine-config-load.mjs").loadSpineConfig>["config"]} [ctx.config]
|
|
162
|
+
* @param {object} [ctx.reconciliation]
|
|
163
|
+
*/
|
|
164
|
+
export function collectEvidenceBundle(ctx) {
|
|
165
|
+
const reconciliation =
|
|
166
|
+
ctx.reconciliation ??
|
|
167
|
+
reconcileBatch({ projectRoot: ctx.projectRoot, batchState: ctx.batchState ?? null, verbose: true });
|
|
168
|
+
const core = collectCoreEvidenceBundle({ ...ctx, reconciliation });
|
|
169
|
+
const extended = collectExtendedEvidenceBundle({ ...ctx, evidenceRefs: core.evidenceRefs });
|
|
170
|
+
finalizeEvidenceBundleComplete(ctx.projectRoot, ctx.batchId, extended.evidenceRefs);
|
|
171
|
+
return { evidenceDir: extended.evidenceDir, evidenceRefs: extended.evidenceRefs };
|
|
172
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate and evidence path readers — leaf module (SP-432 / #83-D).
|
|
3
|
+
* No imports from evidence, gate, reconcile, or postmortem.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
const TASKPLANE_CONFIG_PATH = ".pi/taskplane-config.json";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} projectRoot
|
|
13
|
+
* @param {string} batchId
|
|
14
|
+
*/
|
|
15
|
+
export function gateRecordPath(projectRoot, batchId) {
|
|
16
|
+
return path.join(projectRoot, ".spine", "runtime", batchId, "gate.json");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} projectRoot
|
|
21
|
+
* @param {string} batchId
|
|
22
|
+
* @returns {object|null}
|
|
23
|
+
*/
|
|
24
|
+
export function loadGateRecord(projectRoot, batchId) {
|
|
25
|
+
const filePath = gateRecordPath(projectRoot, batchId);
|
|
26
|
+
if (!fs.existsSync(filePath)) return null;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} gate
|
|
37
|
+
*/
|
|
38
|
+
export function formatGateSummary(gate) {
|
|
39
|
+
const status = String(gate.status ?? "unknown");
|
|
40
|
+
const kind = String(gate.kind ?? "integrate");
|
|
41
|
+
const evidenceCount = Array.isArray(gate.evidenceRefs) ? gate.evidenceRefs.length : 0;
|
|
42
|
+
return `${kind} gate ${status} (${evidenceCount} evidence artifact(s))`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} projectRoot
|
|
47
|
+
* @param {string} batchId
|
|
48
|
+
*/
|
|
49
|
+
export function evidenceDir(projectRoot, batchId) {
|
|
50
|
+
return path.join(projectRoot, ".spine", "runtime", batchId, "evidence");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {string} projectRoot
|
|
55
|
+
* @param {string} batchId
|
|
56
|
+
*/
|
|
57
|
+
export function evidenceCompletePath(projectRoot, batchId) {
|
|
58
|
+
return path.join(evidenceDir(projectRoot, batchId), ".complete");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} projectRoot
|
|
63
|
+
* @param {string} batchId
|
|
64
|
+
*/
|
|
65
|
+
export function isEvidenceBundleComplete(projectRoot, batchId) {
|
|
66
|
+
return fs.existsSync(evidenceCompletePath(projectRoot, batchId));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {object|null|undefined} batchState
|
|
71
|
+
*/
|
|
72
|
+
export function buildTaskScorecard(batchState) {
|
|
73
|
+
const tasks = Array.isArray(batchState?.tasks) ? batchState.tasks : [];
|
|
74
|
+
const lines = [
|
|
75
|
+
"# Batch evidence summary",
|
|
76
|
+
"",
|
|
77
|
+
`| Field | Value |`,
|
|
78
|
+
`|-------|-------|`,
|
|
79
|
+
`| Batch ID | ${batchState?.batchId ?? batchState?.id ?? "—"} |`,
|
|
80
|
+
`| Phase | ${batchState?.phase ?? "—"} |`,
|
|
81
|
+
`| Base branch | ${batchState?.baseBranch ?? "—"} |`,
|
|
82
|
+
`| Orch branch | ${batchState?.orchBranch ?? "—"} |`,
|
|
83
|
+
`| Tasks (total) | ${batchState?.totalTasks ?? tasks.length} |`,
|
|
84
|
+
`| Succeeded | ${batchState?.succeededTasks ?? "—"} |`,
|
|
85
|
+
`| Failed | ${batchState?.failedTasks ?? "—"} |`,
|
|
86
|
+
"",
|
|
87
|
+
"## Task scorecard",
|
|
88
|
+
"",
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
if (tasks.length === 0) {
|
|
92
|
+
lines.push("_No task rows in batch state._");
|
|
93
|
+
} else {
|
|
94
|
+
lines.push("| Task | Status | Done file |");
|
|
95
|
+
lines.push("|------|--------|-----------|");
|
|
96
|
+
for (const task of tasks) {
|
|
97
|
+
lines.push(
|
|
98
|
+
`| ${task.taskId ?? "—"} | ${task.status ?? "—"} | ${task.doneFileFound ? "yes" : "no"} |`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
lines.push("", "_Generated by pi-spine integrate gate (TP-021)._");
|
|
104
|
+
return `${lines.join("\n")}\n`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {string} projectRoot
|
|
109
|
+
*/
|
|
110
|
+
function readTaskplaneTestingCommands(projectRoot) {
|
|
111
|
+
const configPath = path.join(projectRoot, TASKPLANE_CONFIG_PATH);
|
|
112
|
+
if (!fs.existsSync(configPath)) return null;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
116
|
+
return parsed?.taskRunner?.testing?.commands ?? null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} config
|
|
124
|
+
* @param {string} projectRoot
|
|
125
|
+
*/
|
|
126
|
+
export function resolveTestingCommands(config, projectRoot) {
|
|
127
|
+
const spineTesting = config?.testing ?? {};
|
|
128
|
+
const taskplane = readTaskplaneTestingCommands(projectRoot) ?? {};
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
test:
|
|
132
|
+
(typeof spineTesting.test === "string" && spineTesting.test.trim()) ||
|
|
133
|
+
(typeof taskplane.unit === "string" && taskplane.unit.trim()) ||
|
|
134
|
+
(typeof taskplane.test === "string" && taskplane.test.trim()) ||
|
|
135
|
+
"",
|
|
136
|
+
build:
|
|
137
|
+
(typeof spineTesting.build === "string" && spineTesting.build.trim()) ||
|
|
138
|
+
(typeof taskplane.build === "string" && taskplane.build.trim()) ||
|
|
139
|
+
"",
|
|
140
|
+
testWithCoverage:
|
|
141
|
+
(typeof spineTesting.testWithCoverage === "string" && spineTesting.testWithCoverage.trim()) ||
|
|
142
|
+
(typeof taskplane.testWithCoverage === "string" && taskplane.testWithCoverage.trim()) ||
|
|
143
|
+
"",
|
|
144
|
+
};
|
|
145
|
+
}
|