sdtk-code-kit 0.3.0 → 0.3.2
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 +204 -204
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/agent-team.js +479 -174
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -215
- package/src/commands/help.js +266 -257
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -132
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +112 -112
- package/src/lib/agent-team-author.js +552 -0
- package/src/lib/agent-team-evidence.js +302 -0
- package/src/lib/agent-team-execute.js +892 -0
- package/src/lib/agent-team-export.js +411 -409
- package/src/lib/agent-team-plan.js +514 -514
- package/src/lib/agent-team-readiness.js +161 -0
- package/src/lib/agent-team-report.js +165 -0
- package/src/lib/agent-team-sleep-execute.js +524 -0
- package/src/lib/agent-team-sleep-session.js +278 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/model-provider.js +219 -0
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -175
- package/src/lib/sleep-report.js +229 -229
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +264 -185
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +58 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
|
@@ -1,439 +1,439 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const {
|
|
5
|
-
extractManagedBlock,
|
|
6
|
-
getWorkflowArtifactPath,
|
|
7
|
-
parseManagedField,
|
|
8
|
-
} = require("./workflow-artifact");
|
|
9
|
-
|
|
10
|
-
const VALID_PHASES = new Set(["start", "plan", "build", "verify", "ship"]);
|
|
11
|
-
const VALID_PHASE_STATUSES = new Set(["pending", "in_progress", "completed", "blocked"]);
|
|
12
|
-
const VALID_NEXT_PHASES = new Set(["plan", "build", "verify", "ship", "none", "blocked"]);
|
|
13
|
-
const PLACEHOLDER_SLICES = new Set([
|
|
14
|
-
"Pending confirmation during workflow planning.",
|
|
15
|
-
"Pending lane-specific planning or build guidance.",
|
|
16
|
-
"Lightweight bugfix planning not recorded yet.",
|
|
17
|
-
"No active build slices recorded yet.",
|
|
18
|
-
"Pending build-phase execution.",
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
function quotePathForCommand(projectPath) {
|
|
22
|
-
const normalized = String(projectPath || ".");
|
|
23
|
-
return /\s/.test(normalized) ? `"${normalized}"` : normalized;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function normalizeNextPhase(rawValue) {
|
|
27
|
-
const normalized = String(rawValue || "").trim();
|
|
28
|
-
if (!normalized) {
|
|
29
|
-
return "unknown";
|
|
30
|
-
}
|
|
31
|
-
if (/^none\s*\(workflow closed\)$/i.test(normalized)) {
|
|
32
|
-
return "none";
|
|
33
|
-
}
|
|
34
|
-
return normalized;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function parseBulletSection(blockText, heading) {
|
|
38
|
-
if (!blockText) {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const escapedHeading = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43
|
-
const match = blockText.match(new RegExp(`### ${escapedHeading}\\r?\\n([\\s\\S]*?)(?=\\r?\\n### |$)`));
|
|
44
|
-
if (!match) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return match[1]
|
|
49
|
-
.split(/\r?\n/)
|
|
50
|
-
.map((line) => line.trim())
|
|
51
|
-
.filter((line) => line.startsWith("- "))
|
|
52
|
-
.map((line) => line.slice(2).trim())
|
|
53
|
-
.filter(Boolean);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function parseInlinePlanSlices(planBlock) {
|
|
57
|
-
if (!planBlock) {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const match = planBlock.match(/## 4\. Plan \/ Slices\r?\n([\s\S]*?)(?=\r?\n### Planning Notes)/);
|
|
62
|
-
if (!match) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return match[1]
|
|
67
|
-
.split(/\r?\n/)
|
|
68
|
-
.map((line) => line.trim())
|
|
69
|
-
.filter((line) => line.startsWith("- "))
|
|
70
|
-
.map((line) => line.slice(2).trim())
|
|
71
|
-
.filter(Boolean);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function uniqueNonPlaceholder(values) {
|
|
75
|
-
const seen = new Set();
|
|
76
|
-
const result = [];
|
|
77
|
-
for (const value of values || []) {
|
|
78
|
-
const normalized = String(value || "").trim();
|
|
79
|
-
if (!normalized || PLACEHOLDER_SLICES.has(normalized) || seen.has(normalized)) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
seen.add(normalized);
|
|
83
|
-
result.push(normalized);
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function parsePlanSlices(planBlock) {
|
|
89
|
-
const finalized = parseBulletSection(planBlock, "Finalized Slices After `plan`");
|
|
90
|
-
if (finalized.length > 0) {
|
|
91
|
-
return uniqueNonPlaceholder(finalized);
|
|
92
|
-
}
|
|
93
|
-
return uniqueNonPlaceholder(parseInlinePlanSlices(planBlock));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function parseBuildActiveSlices(buildBlock) {
|
|
97
|
-
return uniqueNonPlaceholder(parseBulletSection(buildBlock, "Active Slices"));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function buildCommandTemplates(featureKey, projectPath, lane) {
|
|
101
|
-
const projectPathArg = quotePathForCommand(projectPath);
|
|
102
|
-
return {
|
|
103
|
-
start: `sdtk-code start --lane <feature|bugfix> --feature-key ${featureKey} --project-path ${projectPathArg}`,
|
|
104
|
-
plan:
|
|
105
|
-
lane === "feature"
|
|
106
|
-
? `sdtk-code plan --feature-key ${featureKey} --project-path ${projectPathArg} --slice "<approved-slice>"`
|
|
107
|
-
: `sdtk-code plan --feature-key ${featureKey} --project-path ${projectPathArg} --note "<planning-note>"`,
|
|
108
|
-
build: `sdtk-code build --feature-key ${featureKey} --project-path ${projectPathArg} --active-slice "<active-slice>"`,
|
|
109
|
-
verify:
|
|
110
|
-
`sdtk-code verify --feature-key ${featureKey} --project-path ${projectPathArg}` +
|
|
111
|
-
` --evidence "check|summary|pass|docs/dev/evidence/${featureKey}/file.txt" --spec-status <pending|pass|partial|fail>` +
|
|
112
|
-
" --quality-status <pending|pass|partial|fail>",
|
|
113
|
-
ship:
|
|
114
|
-
`sdtk-code ship --feature-key ${featureKey} --project-path ${projectPathArg}` +
|
|
115
|
-
` --decision <ship|finish> --preflight "check|summary|pass|docs/dev/evidence/${featureKey}/file.txt"`,
|
|
116
|
-
doctor: `sdtk-code doctor --feature-key ${featureKey} --project-path ${projectPathArg}`,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function deriveExpectedNextPhase(lane, currentPhase, phaseStatus) {
|
|
121
|
-
if (!VALID_PHASES.has(currentPhase) || !VALID_PHASE_STATUSES.has(phaseStatus)) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (currentPhase === "start") {
|
|
126
|
-
if (phaseStatus === "blocked") {
|
|
127
|
-
return "blocked";
|
|
128
|
-
}
|
|
129
|
-
if (phaseStatus === "completed") {
|
|
130
|
-
return lane === "bugfix" ? "build" : "plan";
|
|
131
|
-
}
|
|
132
|
-
return "start";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (currentPhase === "plan") {
|
|
136
|
-
return phaseStatus === "completed" ? "build" : "plan";
|
|
137
|
-
}
|
|
138
|
-
if (currentPhase === "build") {
|
|
139
|
-
return phaseStatus === "completed" ? "verify" : "build";
|
|
140
|
-
}
|
|
141
|
-
if (currentPhase === "verify") {
|
|
142
|
-
return phaseStatus === "completed" ? "ship" : "verify";
|
|
143
|
-
}
|
|
144
|
-
if (currentPhase === "ship") {
|
|
145
|
-
return phaseStatus === "completed" ? "none" : "ship";
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function deriveExpectedBlockingState(currentPhase, phaseStatus, intakeOutcome) {
|
|
152
|
-
if (phaseStatus === "blocked") {
|
|
153
|
-
if (currentPhase === "start") {
|
|
154
|
-
if (intakeOutcome === "BLOCKED_MISSING_INPUTS") {
|
|
155
|
-
return "blocked_missing_inputs";
|
|
156
|
-
}
|
|
157
|
-
if (intakeOutcome === "BLOCKED_UPSTREAM_HANDOFF") {
|
|
158
|
-
return "blocked_upstream_handoff|invalid_handoff_contract";
|
|
159
|
-
}
|
|
160
|
-
return "blocked_missing_inputs|blocked_upstream_handoff|invalid_handoff_contract";
|
|
161
|
-
}
|
|
162
|
-
if (currentPhase === "build") {
|
|
163
|
-
return "blocked_build_issue";
|
|
164
|
-
}
|
|
165
|
-
if (currentPhase === "verify") {
|
|
166
|
-
return "blocked_verify_issue";
|
|
167
|
-
}
|
|
168
|
-
if (currentPhase === "ship") {
|
|
169
|
-
return "blocked_ship_issue";
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (phaseStatus === "in_progress") {
|
|
174
|
-
if (currentPhase === "verify") {
|
|
175
|
-
return "review_in_progress";
|
|
176
|
-
}
|
|
177
|
-
if (currentPhase === "ship") {
|
|
178
|
-
return "ship_preflight_in_progress";
|
|
179
|
-
}
|
|
180
|
-
return "clear";
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (phaseStatus === "completed" || phaseStatus === "pending") {
|
|
184
|
-
return "clear";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function parseEvidenceEntries(verifyBlock) {
|
|
191
|
-
const entries = [];
|
|
192
|
-
if (!verifyBlock) {
|
|
193
|
-
return entries;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const pattern = /^- `([^`]+)` \| `([^`]+)` \| ([^\r\n]+?) \| Raw output: `([^`]+)`$/gm;
|
|
197
|
-
let match;
|
|
198
|
-
while ((match = pattern.exec(verifyBlock)) !== null) {
|
|
199
|
-
entries.push({
|
|
200
|
-
checkName: match[1],
|
|
201
|
-
result: match[2],
|
|
202
|
-
summary: match[3].trim(),
|
|
203
|
-
rawOutputRef: match[4],
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return entries;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function evaluateContradictions(snapshot) {
|
|
211
|
-
const issues = [];
|
|
212
|
-
const expectedNext = deriveExpectedNextPhase(snapshot.lane, snapshot.currentPhase, snapshot.phaseStatus);
|
|
213
|
-
const expectedBlocking = deriveExpectedBlockingState(
|
|
214
|
-
snapshot.currentPhase,
|
|
215
|
-
snapshot.phaseStatus,
|
|
216
|
-
snapshot.intakeOutcome
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
if (snapshot.currentPhase && !VALID_PHASES.has(snapshot.currentPhase)) {
|
|
220
|
-
issues.push(`Current phase is invalid: ${snapshot.currentPhase}`);
|
|
221
|
-
}
|
|
222
|
-
if (snapshot.phaseStatus && !VALID_PHASE_STATUSES.has(snapshot.phaseStatus)) {
|
|
223
|
-
issues.push(`Phase status is invalid: ${snapshot.phaseStatus}`);
|
|
224
|
-
}
|
|
225
|
-
if (snapshot.nextPhase && !VALID_NEXT_PHASES.has(snapshot.nextPhase)) {
|
|
226
|
-
issues.push(`Next recommended phase is invalid: ${snapshot.nextPhase}`);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (expectedNext && snapshot.nextPhase && expectedNext !== snapshot.nextPhase) {
|
|
230
|
-
issues.push(
|
|
231
|
-
`Current phase/status expects next phase "${expectedNext}", but STATUS block reports "${snapshot.nextPhaseRaw}".`
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (
|
|
236
|
-
snapshot.currentPhase === "verify" &&
|
|
237
|
-
snapshot.phaseStatus === "completed" &&
|
|
238
|
-
snapshot.evidenceEntries.length === 0
|
|
239
|
-
) {
|
|
240
|
-
issues.push("Workflow claims verify completed, but VERIFY evidence summary has no recorded evidence entries.");
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (snapshot.nextPhase === "none" && snapshot.currentPhase !== "ship") {
|
|
244
|
-
issues.push("STATUS reports workflow closed (next phase none), but current phase is not ship.");
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (snapshot.phaseStatus === "blocked" && snapshot.blockingState === "clear") {
|
|
248
|
-
issues.push("Phase status is blocked, but blocking state is clear.");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (snapshot.phaseStatus !== "blocked" && /^blocked_/.test(snapshot.blockingState || "")) {
|
|
252
|
-
issues.push(`Blocking state "${snapshot.blockingState}" is blocked_* while phase status is not blocked.`);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (expectedBlocking && snapshot.blockingState) {
|
|
256
|
-
if (expectedBlocking.includes("|")) {
|
|
257
|
-
const allowed = expectedBlocking.split("|");
|
|
258
|
-
if (!allowed.includes(snapshot.blockingState)) {
|
|
259
|
-
issues.push(
|
|
260
|
-
`Blocking state "${snapshot.blockingState}" is not legal for ${snapshot.currentPhase}/${snapshot.phaseStatus}. Expected one of: ${allowed.join(
|
|
261
|
-
", "
|
|
262
|
-
)}.`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
} else if (expectedBlocking !== snapshot.blockingState) {
|
|
266
|
-
issues.push(
|
|
267
|
-
`Blocking state "${snapshot.blockingState}" does not match expected "${expectedBlocking}" for ${snapshot.currentPhase}/${snapshot.phaseStatus}.`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return [...new Set(issues)];
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function evaluateResumeDecision(state) {
|
|
276
|
-
const templates = state.commandTemplates;
|
|
277
|
-
|
|
278
|
-
if (!state.exists) {
|
|
279
|
-
return {
|
|
280
|
-
allowed: false,
|
|
281
|
-
mode: "not_started",
|
|
282
|
-
reason: "Workflow artifact is missing. Resume is unavailable until start initializes the workflow.",
|
|
283
|
-
nextCommand: templates.start,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (state.contradictions.length > 0) {
|
|
288
|
-
return {
|
|
289
|
-
allowed: false,
|
|
290
|
-
mode: "invalid",
|
|
291
|
-
reason: "Workflow state is contradictory. Resume is fail-closed until doctor reports a clean state.",
|
|
292
|
-
nextCommand: templates.doctor,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (state.phaseStatus === "blocked" || state.nextPhase === "blocked") {
|
|
297
|
-
return {
|
|
298
|
-
allowed: false,
|
|
299
|
-
mode: "blocked",
|
|
300
|
-
reason: "Workflow is blocked. Resume is fail-closed for blocked states in BK-047-lite.",
|
|
301
|
-
nextCommand: templates.doctor,
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (state.nextPhase === "none") {
|
|
306
|
-
return {
|
|
307
|
-
allowed: false,
|
|
308
|
-
mode: "closed",
|
|
309
|
-
reason: "Workflow is already closed (next phase is none). There is nothing to resume.",
|
|
310
|
-
nextCommand: null,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
state.nextPhase === "build" &&
|
|
316
|
-
state.phaseStatus === "completed" &&
|
|
317
|
-
(state.currentPhase === "start" || state.currentPhase === "plan")
|
|
318
|
-
) {
|
|
319
|
-
const resumeBuildSlices =
|
|
320
|
-
Array.isArray(state.buildActiveSlices) && state.buildActiveSlices.length > 0
|
|
321
|
-
? state.buildActiveSlices
|
|
322
|
-
: state.planSlices;
|
|
323
|
-
|
|
324
|
-
if (!Array.isArray(resumeBuildSlices) || resumeBuildSlices.length === 0) {
|
|
325
|
-
return {
|
|
326
|
-
allowed: false,
|
|
327
|
-
mode: "manual",
|
|
328
|
-
reason:
|
|
329
|
-
"Resume cannot auto-dispatch build because no slice context was found in the workflow artifact. Provide explicit --active-slice entries manually.",
|
|
330
|
-
nextCommand: templates.build,
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
allowed: true,
|
|
336
|
-
mode: "auto_build",
|
|
337
|
-
reason: "Safe auto-resume is available for build from a completed pre-build phase.",
|
|
338
|
-
dispatchCommand: templates.build,
|
|
339
|
-
resumeBuildSlices,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (state.nextPhase === "plan") {
|
|
344
|
-
return {
|
|
345
|
-
allowed: false,
|
|
346
|
-
mode: "manual",
|
|
347
|
-
reason: "Resume is fail-closed for plan because operator slice confirmation is still required.",
|
|
348
|
-
nextCommand: templates.plan,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (state.nextPhase === "verify") {
|
|
353
|
-
return {
|
|
354
|
-
allowed: false,
|
|
355
|
-
mode: "manual",
|
|
356
|
-
reason: "Resume is fail-closed for verify because operator evidence and gate inputs are required.",
|
|
357
|
-
nextCommand: templates.verify,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (state.nextPhase === "ship") {
|
|
362
|
-
return {
|
|
363
|
-
allowed: false,
|
|
364
|
-
mode: "manual",
|
|
365
|
-
reason: "Resume is fail-closed for ship because operator decision and preflight inputs are required.",
|
|
366
|
-
nextCommand: templates.ship,
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
allowed: false,
|
|
372
|
-
mode: "manual",
|
|
373
|
-
reason: "Resume is fail-closed because the next legal action still requires explicit operator input.",
|
|
374
|
-
nextCommand: templates.build,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function loadWorkflowState(projectPath, featureKey) {
|
|
379
|
-
const artifactPath = getWorkflowArtifactPath(projectPath, featureKey);
|
|
380
|
-
const commandTemplates = buildCommandTemplates(featureKey, projectPath);
|
|
381
|
-
|
|
382
|
-
if (!fs.existsSync(artifactPath)) {
|
|
383
|
-
const missingSnapshot = {
|
|
384
|
-
featureKey,
|
|
385
|
-
projectPath,
|
|
386
|
-
artifactPath,
|
|
387
|
-
exists: false,
|
|
388
|
-
commandTemplates,
|
|
389
|
-
contradictions: [],
|
|
390
|
-
};
|
|
391
|
-
missingSnapshot.resumeDecision = evaluateResumeDecision(missingSnapshot);
|
|
392
|
-
return missingSnapshot;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const text = fs.readFileSync(artifactPath, "utf-8");
|
|
396
|
-
const metadataBlock = extractManagedBlock(text, "METADATA");
|
|
397
|
-
const statusBlock = extractManagedBlock(text, "STATUS");
|
|
398
|
-
const planBlock = extractManagedBlock(text, "PLAN");
|
|
399
|
-
const buildBlock = extractManagedBlock(text, "BUILD");
|
|
400
|
-
const verifyBlock = extractManagedBlock(text, "VERIFY");
|
|
401
|
-
const shipBlock = extractManagedBlock(text, "SHIP");
|
|
402
|
-
const lane = parseManagedField(metadataBlock, "Lane") || "unknown";
|
|
403
|
-
const rawNextPhase = parseManagedField(statusBlock, "Next recommended phase") || "unknown";
|
|
404
|
-
|
|
405
|
-
const snapshot = {
|
|
406
|
-
featureKey,
|
|
407
|
-
projectPath,
|
|
408
|
-
artifactPath,
|
|
409
|
-
exists: true,
|
|
410
|
-
text,
|
|
411
|
-
blocks: {
|
|
412
|
-
METADATA: metadataBlock,
|
|
413
|
-
STATUS: statusBlock,
|
|
414
|
-
PLAN: planBlock,
|
|
415
|
-
BUILD: buildBlock,
|
|
416
|
-
VERIFY: verifyBlock,
|
|
417
|
-
SHIP: shipBlock,
|
|
418
|
-
},
|
|
419
|
-
lane,
|
|
420
|
-
currentPhase: parseManagedField(metadataBlock, "Current phase") || "unknown",
|
|
421
|
-
phaseStatus: parseManagedField(metadataBlock, "Phase status") || "unknown",
|
|
422
|
-
intakeOutcome: parseManagedField(metadataBlock, "Intake outcome") || "unknown",
|
|
423
|
-
nextPhaseRaw: rawNextPhase,
|
|
424
|
-
nextPhase: normalizeNextPhase(rawNextPhase),
|
|
425
|
-
blockingState: parseManagedField(statusBlock, "Blocking state") || "unknown",
|
|
426
|
-
planSlices: parsePlanSlices(planBlock),
|
|
427
|
-
buildActiveSlices: parseBuildActiveSlices(buildBlock),
|
|
428
|
-
evidenceEntries: parseEvidenceEntries(verifyBlock),
|
|
429
|
-
commandTemplates: buildCommandTemplates(featureKey, projectPath, lane),
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
snapshot.contradictions = evaluateContradictions(snapshot);
|
|
433
|
-
snapshot.resumeDecision = evaluateResumeDecision(snapshot);
|
|
434
|
-
return snapshot;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
module.exports = {
|
|
438
|
-
loadWorkflowState,
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const {
|
|
5
|
+
extractManagedBlock,
|
|
6
|
+
getWorkflowArtifactPath,
|
|
7
|
+
parseManagedField,
|
|
8
|
+
} = require("./workflow-artifact");
|
|
9
|
+
|
|
10
|
+
const VALID_PHASES = new Set(["start", "plan", "build", "verify", "ship"]);
|
|
11
|
+
const VALID_PHASE_STATUSES = new Set(["pending", "in_progress", "completed", "blocked"]);
|
|
12
|
+
const VALID_NEXT_PHASES = new Set(["plan", "build", "verify", "ship", "none", "blocked"]);
|
|
13
|
+
const PLACEHOLDER_SLICES = new Set([
|
|
14
|
+
"Pending confirmation during workflow planning.",
|
|
15
|
+
"Pending lane-specific planning or build guidance.",
|
|
16
|
+
"Lightweight bugfix planning not recorded yet.",
|
|
17
|
+
"No active build slices recorded yet.",
|
|
18
|
+
"Pending build-phase execution.",
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
function quotePathForCommand(projectPath) {
|
|
22
|
+
const normalized = String(projectPath || ".");
|
|
23
|
+
return /\s/.test(normalized) ? `"${normalized}"` : normalized;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeNextPhase(rawValue) {
|
|
27
|
+
const normalized = String(rawValue || "").trim();
|
|
28
|
+
if (!normalized) {
|
|
29
|
+
return "unknown";
|
|
30
|
+
}
|
|
31
|
+
if (/^none\s*\(workflow closed\)$/i.test(normalized)) {
|
|
32
|
+
return "none";
|
|
33
|
+
}
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseBulletSection(blockText, heading) {
|
|
38
|
+
if (!blockText) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const escapedHeading = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43
|
+
const match = blockText.match(new RegExp(`### ${escapedHeading}\\r?\\n([\\s\\S]*?)(?=\\r?\\n### |$)`));
|
|
44
|
+
if (!match) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return match[1]
|
|
49
|
+
.split(/\r?\n/)
|
|
50
|
+
.map((line) => line.trim())
|
|
51
|
+
.filter((line) => line.startsWith("- "))
|
|
52
|
+
.map((line) => line.slice(2).trim())
|
|
53
|
+
.filter(Boolean);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseInlinePlanSlices(planBlock) {
|
|
57
|
+
if (!planBlock) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const match = planBlock.match(/## 4\. Plan \/ Slices\r?\n([\s\S]*?)(?=\r?\n### Planning Notes)/);
|
|
62
|
+
if (!match) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return match[1]
|
|
67
|
+
.split(/\r?\n/)
|
|
68
|
+
.map((line) => line.trim())
|
|
69
|
+
.filter((line) => line.startsWith("- "))
|
|
70
|
+
.map((line) => line.slice(2).trim())
|
|
71
|
+
.filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function uniqueNonPlaceholder(values) {
|
|
75
|
+
const seen = new Set();
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const value of values || []) {
|
|
78
|
+
const normalized = String(value || "").trim();
|
|
79
|
+
if (!normalized || PLACEHOLDER_SLICES.has(normalized) || seen.has(normalized)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
seen.add(normalized);
|
|
83
|
+
result.push(normalized);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function parsePlanSlices(planBlock) {
|
|
89
|
+
const finalized = parseBulletSection(planBlock, "Finalized Slices After `plan`");
|
|
90
|
+
if (finalized.length > 0) {
|
|
91
|
+
return uniqueNonPlaceholder(finalized);
|
|
92
|
+
}
|
|
93
|
+
return uniqueNonPlaceholder(parseInlinePlanSlices(planBlock));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function parseBuildActiveSlices(buildBlock) {
|
|
97
|
+
return uniqueNonPlaceholder(parseBulletSection(buildBlock, "Active Slices"));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function buildCommandTemplates(featureKey, projectPath, lane) {
|
|
101
|
+
const projectPathArg = quotePathForCommand(projectPath);
|
|
102
|
+
return {
|
|
103
|
+
start: `sdtk-code start --lane <feature|bugfix> --feature-key ${featureKey} --project-path ${projectPathArg}`,
|
|
104
|
+
plan:
|
|
105
|
+
lane === "feature"
|
|
106
|
+
? `sdtk-code plan --feature-key ${featureKey} --project-path ${projectPathArg} --slice "<approved-slice>"`
|
|
107
|
+
: `sdtk-code plan --feature-key ${featureKey} --project-path ${projectPathArg} --note "<planning-note>"`,
|
|
108
|
+
build: `sdtk-code build --feature-key ${featureKey} --project-path ${projectPathArg} --active-slice "<active-slice>"`,
|
|
109
|
+
verify:
|
|
110
|
+
`sdtk-code verify --feature-key ${featureKey} --project-path ${projectPathArg}` +
|
|
111
|
+
` --evidence "check|summary|pass|docs/dev/evidence/${featureKey}/file.txt" --spec-status <pending|pass|partial|fail>` +
|
|
112
|
+
" --quality-status <pending|pass|partial|fail>",
|
|
113
|
+
ship:
|
|
114
|
+
`sdtk-code ship --feature-key ${featureKey} --project-path ${projectPathArg}` +
|
|
115
|
+
` --decision <ship|finish> --preflight "check|summary|pass|docs/dev/evidence/${featureKey}/file.txt"`,
|
|
116
|
+
doctor: `sdtk-code doctor --feature-key ${featureKey} --project-path ${projectPathArg}`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function deriveExpectedNextPhase(lane, currentPhase, phaseStatus) {
|
|
121
|
+
if (!VALID_PHASES.has(currentPhase) || !VALID_PHASE_STATUSES.has(phaseStatus)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (currentPhase === "start") {
|
|
126
|
+
if (phaseStatus === "blocked") {
|
|
127
|
+
return "blocked";
|
|
128
|
+
}
|
|
129
|
+
if (phaseStatus === "completed") {
|
|
130
|
+
return lane === "bugfix" ? "build" : "plan";
|
|
131
|
+
}
|
|
132
|
+
return "start";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (currentPhase === "plan") {
|
|
136
|
+
return phaseStatus === "completed" ? "build" : "plan";
|
|
137
|
+
}
|
|
138
|
+
if (currentPhase === "build") {
|
|
139
|
+
return phaseStatus === "completed" ? "verify" : "build";
|
|
140
|
+
}
|
|
141
|
+
if (currentPhase === "verify") {
|
|
142
|
+
return phaseStatus === "completed" ? "ship" : "verify";
|
|
143
|
+
}
|
|
144
|
+
if (currentPhase === "ship") {
|
|
145
|
+
return phaseStatus === "completed" ? "none" : "ship";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function deriveExpectedBlockingState(currentPhase, phaseStatus, intakeOutcome) {
|
|
152
|
+
if (phaseStatus === "blocked") {
|
|
153
|
+
if (currentPhase === "start") {
|
|
154
|
+
if (intakeOutcome === "BLOCKED_MISSING_INPUTS") {
|
|
155
|
+
return "blocked_missing_inputs";
|
|
156
|
+
}
|
|
157
|
+
if (intakeOutcome === "BLOCKED_UPSTREAM_HANDOFF") {
|
|
158
|
+
return "blocked_upstream_handoff|invalid_handoff_contract";
|
|
159
|
+
}
|
|
160
|
+
return "blocked_missing_inputs|blocked_upstream_handoff|invalid_handoff_contract";
|
|
161
|
+
}
|
|
162
|
+
if (currentPhase === "build") {
|
|
163
|
+
return "blocked_build_issue";
|
|
164
|
+
}
|
|
165
|
+
if (currentPhase === "verify") {
|
|
166
|
+
return "blocked_verify_issue";
|
|
167
|
+
}
|
|
168
|
+
if (currentPhase === "ship") {
|
|
169
|
+
return "blocked_ship_issue";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (phaseStatus === "in_progress") {
|
|
174
|
+
if (currentPhase === "verify") {
|
|
175
|
+
return "review_in_progress";
|
|
176
|
+
}
|
|
177
|
+
if (currentPhase === "ship") {
|
|
178
|
+
return "ship_preflight_in_progress";
|
|
179
|
+
}
|
|
180
|
+
return "clear";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (phaseStatus === "completed" || phaseStatus === "pending") {
|
|
184
|
+
return "clear";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function parseEvidenceEntries(verifyBlock) {
|
|
191
|
+
const entries = [];
|
|
192
|
+
if (!verifyBlock) {
|
|
193
|
+
return entries;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const pattern = /^- `([^`]+)` \| `([^`]+)` \| ([^\r\n]+?) \| Raw output: `([^`]+)`$/gm;
|
|
197
|
+
let match;
|
|
198
|
+
while ((match = pattern.exec(verifyBlock)) !== null) {
|
|
199
|
+
entries.push({
|
|
200
|
+
checkName: match[1],
|
|
201
|
+
result: match[2],
|
|
202
|
+
summary: match[3].trim(),
|
|
203
|
+
rawOutputRef: match[4],
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return entries;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function evaluateContradictions(snapshot) {
|
|
211
|
+
const issues = [];
|
|
212
|
+
const expectedNext = deriveExpectedNextPhase(snapshot.lane, snapshot.currentPhase, snapshot.phaseStatus);
|
|
213
|
+
const expectedBlocking = deriveExpectedBlockingState(
|
|
214
|
+
snapshot.currentPhase,
|
|
215
|
+
snapshot.phaseStatus,
|
|
216
|
+
snapshot.intakeOutcome
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (snapshot.currentPhase && !VALID_PHASES.has(snapshot.currentPhase)) {
|
|
220
|
+
issues.push(`Current phase is invalid: ${snapshot.currentPhase}`);
|
|
221
|
+
}
|
|
222
|
+
if (snapshot.phaseStatus && !VALID_PHASE_STATUSES.has(snapshot.phaseStatus)) {
|
|
223
|
+
issues.push(`Phase status is invalid: ${snapshot.phaseStatus}`);
|
|
224
|
+
}
|
|
225
|
+
if (snapshot.nextPhase && !VALID_NEXT_PHASES.has(snapshot.nextPhase)) {
|
|
226
|
+
issues.push(`Next recommended phase is invalid: ${snapshot.nextPhase}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (expectedNext && snapshot.nextPhase && expectedNext !== snapshot.nextPhase) {
|
|
230
|
+
issues.push(
|
|
231
|
+
`Current phase/status expects next phase "${expectedNext}", but STATUS block reports "${snapshot.nextPhaseRaw}".`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
snapshot.currentPhase === "verify" &&
|
|
237
|
+
snapshot.phaseStatus === "completed" &&
|
|
238
|
+
snapshot.evidenceEntries.length === 0
|
|
239
|
+
) {
|
|
240
|
+
issues.push("Workflow claims verify completed, but VERIFY evidence summary has no recorded evidence entries.");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (snapshot.nextPhase === "none" && snapshot.currentPhase !== "ship") {
|
|
244
|
+
issues.push("STATUS reports workflow closed (next phase none), but current phase is not ship.");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (snapshot.phaseStatus === "blocked" && snapshot.blockingState === "clear") {
|
|
248
|
+
issues.push("Phase status is blocked, but blocking state is clear.");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (snapshot.phaseStatus !== "blocked" && /^blocked_/.test(snapshot.blockingState || "")) {
|
|
252
|
+
issues.push(`Blocking state "${snapshot.blockingState}" is blocked_* while phase status is not blocked.`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (expectedBlocking && snapshot.blockingState) {
|
|
256
|
+
if (expectedBlocking.includes("|")) {
|
|
257
|
+
const allowed = expectedBlocking.split("|");
|
|
258
|
+
if (!allowed.includes(snapshot.blockingState)) {
|
|
259
|
+
issues.push(
|
|
260
|
+
`Blocking state "${snapshot.blockingState}" is not legal for ${snapshot.currentPhase}/${snapshot.phaseStatus}. Expected one of: ${allowed.join(
|
|
261
|
+
", "
|
|
262
|
+
)}.`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
} else if (expectedBlocking !== snapshot.blockingState) {
|
|
266
|
+
issues.push(
|
|
267
|
+
`Blocking state "${snapshot.blockingState}" does not match expected "${expectedBlocking}" for ${snapshot.currentPhase}/${snapshot.phaseStatus}.`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return [...new Set(issues)];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function evaluateResumeDecision(state) {
|
|
276
|
+
const templates = state.commandTemplates;
|
|
277
|
+
|
|
278
|
+
if (!state.exists) {
|
|
279
|
+
return {
|
|
280
|
+
allowed: false,
|
|
281
|
+
mode: "not_started",
|
|
282
|
+
reason: "Workflow artifact is missing. Resume is unavailable until start initializes the workflow.",
|
|
283
|
+
nextCommand: templates.start,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (state.contradictions.length > 0) {
|
|
288
|
+
return {
|
|
289
|
+
allowed: false,
|
|
290
|
+
mode: "invalid",
|
|
291
|
+
reason: "Workflow state is contradictory. Resume is fail-closed until doctor reports a clean state.",
|
|
292
|
+
nextCommand: templates.doctor,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (state.phaseStatus === "blocked" || state.nextPhase === "blocked") {
|
|
297
|
+
return {
|
|
298
|
+
allowed: false,
|
|
299
|
+
mode: "blocked",
|
|
300
|
+
reason: "Workflow is blocked. Resume is fail-closed for blocked states in BK-047-lite.",
|
|
301
|
+
nextCommand: templates.doctor,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (state.nextPhase === "none") {
|
|
306
|
+
return {
|
|
307
|
+
allowed: false,
|
|
308
|
+
mode: "closed",
|
|
309
|
+
reason: "Workflow is already closed (next phase is none). There is nothing to resume.",
|
|
310
|
+
nextCommand: null,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (
|
|
315
|
+
state.nextPhase === "build" &&
|
|
316
|
+
state.phaseStatus === "completed" &&
|
|
317
|
+
(state.currentPhase === "start" || state.currentPhase === "plan")
|
|
318
|
+
) {
|
|
319
|
+
const resumeBuildSlices =
|
|
320
|
+
Array.isArray(state.buildActiveSlices) && state.buildActiveSlices.length > 0
|
|
321
|
+
? state.buildActiveSlices
|
|
322
|
+
: state.planSlices;
|
|
323
|
+
|
|
324
|
+
if (!Array.isArray(resumeBuildSlices) || resumeBuildSlices.length === 0) {
|
|
325
|
+
return {
|
|
326
|
+
allowed: false,
|
|
327
|
+
mode: "manual",
|
|
328
|
+
reason:
|
|
329
|
+
"Resume cannot auto-dispatch build because no slice context was found in the workflow artifact. Provide explicit --active-slice entries manually.",
|
|
330
|
+
nextCommand: templates.build,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
allowed: true,
|
|
336
|
+
mode: "auto_build",
|
|
337
|
+
reason: "Safe auto-resume is available for build from a completed pre-build phase.",
|
|
338
|
+
dispatchCommand: templates.build,
|
|
339
|
+
resumeBuildSlices,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (state.nextPhase === "plan") {
|
|
344
|
+
return {
|
|
345
|
+
allowed: false,
|
|
346
|
+
mode: "manual",
|
|
347
|
+
reason: "Resume is fail-closed for plan because operator slice confirmation is still required.",
|
|
348
|
+
nextCommand: templates.plan,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (state.nextPhase === "verify") {
|
|
353
|
+
return {
|
|
354
|
+
allowed: false,
|
|
355
|
+
mode: "manual",
|
|
356
|
+
reason: "Resume is fail-closed for verify because operator evidence and gate inputs are required.",
|
|
357
|
+
nextCommand: templates.verify,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (state.nextPhase === "ship") {
|
|
362
|
+
return {
|
|
363
|
+
allowed: false,
|
|
364
|
+
mode: "manual",
|
|
365
|
+
reason: "Resume is fail-closed for ship because operator decision and preflight inputs are required.",
|
|
366
|
+
nextCommand: templates.ship,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
allowed: false,
|
|
372
|
+
mode: "manual",
|
|
373
|
+
reason: "Resume is fail-closed because the next legal action still requires explicit operator input.",
|
|
374
|
+
nextCommand: templates.build,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function loadWorkflowState(projectPath, featureKey) {
|
|
379
|
+
const artifactPath = getWorkflowArtifactPath(projectPath, featureKey);
|
|
380
|
+
const commandTemplates = buildCommandTemplates(featureKey, projectPath);
|
|
381
|
+
|
|
382
|
+
if (!fs.existsSync(artifactPath)) {
|
|
383
|
+
const missingSnapshot = {
|
|
384
|
+
featureKey,
|
|
385
|
+
projectPath,
|
|
386
|
+
artifactPath,
|
|
387
|
+
exists: false,
|
|
388
|
+
commandTemplates,
|
|
389
|
+
contradictions: [],
|
|
390
|
+
};
|
|
391
|
+
missingSnapshot.resumeDecision = evaluateResumeDecision(missingSnapshot);
|
|
392
|
+
return missingSnapshot;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const text = fs.readFileSync(artifactPath, "utf-8");
|
|
396
|
+
const metadataBlock = extractManagedBlock(text, "METADATA");
|
|
397
|
+
const statusBlock = extractManagedBlock(text, "STATUS");
|
|
398
|
+
const planBlock = extractManagedBlock(text, "PLAN");
|
|
399
|
+
const buildBlock = extractManagedBlock(text, "BUILD");
|
|
400
|
+
const verifyBlock = extractManagedBlock(text, "VERIFY");
|
|
401
|
+
const shipBlock = extractManagedBlock(text, "SHIP");
|
|
402
|
+
const lane = parseManagedField(metadataBlock, "Lane") || "unknown";
|
|
403
|
+
const rawNextPhase = parseManagedField(statusBlock, "Next recommended phase") || "unknown";
|
|
404
|
+
|
|
405
|
+
const snapshot = {
|
|
406
|
+
featureKey,
|
|
407
|
+
projectPath,
|
|
408
|
+
artifactPath,
|
|
409
|
+
exists: true,
|
|
410
|
+
text,
|
|
411
|
+
blocks: {
|
|
412
|
+
METADATA: metadataBlock,
|
|
413
|
+
STATUS: statusBlock,
|
|
414
|
+
PLAN: planBlock,
|
|
415
|
+
BUILD: buildBlock,
|
|
416
|
+
VERIFY: verifyBlock,
|
|
417
|
+
SHIP: shipBlock,
|
|
418
|
+
},
|
|
419
|
+
lane,
|
|
420
|
+
currentPhase: parseManagedField(metadataBlock, "Current phase") || "unknown",
|
|
421
|
+
phaseStatus: parseManagedField(metadataBlock, "Phase status") || "unknown",
|
|
422
|
+
intakeOutcome: parseManagedField(metadataBlock, "Intake outcome") || "unknown",
|
|
423
|
+
nextPhaseRaw: rawNextPhase,
|
|
424
|
+
nextPhase: normalizeNextPhase(rawNextPhase),
|
|
425
|
+
blockingState: parseManagedField(statusBlock, "Blocking state") || "unknown",
|
|
426
|
+
planSlices: parsePlanSlices(planBlock),
|
|
427
|
+
buildActiveSlices: parseBuildActiveSlices(buildBlock),
|
|
428
|
+
evidenceEntries: parseEvidenceEntries(verifyBlock),
|
|
429
|
+
commandTemplates: buildCommandTemplates(featureKey, projectPath, lane),
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
snapshot.contradictions = evaluateContradictions(snapshot);
|
|
433
|
+
snapshot.resumeDecision = evaluateResumeDecision(snapshot);
|
|
434
|
+
return snapshot;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
module.exports = {
|
|
438
|
+
loadWorkflowState,
|
|
439
439
|
};
|