sdtk-code-kit 0.3.0 → 0.3.1
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 +425 -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 +264 -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 +521 -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/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 +252 -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,503 +1,503 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { IntegrityError, ValidationError } = require("./errors");
|
|
6
|
-
const { resolvePayloadFile } = require("./toolkit-payload");
|
|
7
|
-
|
|
8
|
-
const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
|
|
9
|
-
const PRODUCT_ROOT = path.resolve(PACKAGE_ROOT, "..", "..");
|
|
10
|
-
const SOURCE_TEMPLATE_PATH = path.join(
|
|
11
|
-
PRODUCT_ROOT,
|
|
12
|
-
"toolkit",
|
|
13
|
-
"templates",
|
|
14
|
-
"CODE_WORKFLOW_TEMPLATE.md"
|
|
15
|
-
);
|
|
16
|
-
const PAYLOAD_TEMPLATE_PATH = resolvePayloadFile("toolkit/templates/CODE_WORKFLOW_TEMPLATE.md");
|
|
17
|
-
const DEFAULT_MANAGED_BLOCKS = ["METADATA", "INPUTS", "PLAN", "BUILD", "STATUS"];
|
|
18
|
-
const LEGACY_PLAN_SECTION_RE =
|
|
19
|
-
/## 3\. Scope Lock[\s\S]*?(?=<!-- SDTK-CODE:STATUS:START -->|## 5\. Status Checklist)/;
|
|
20
|
-
const STATUS_BLOCK_RE = /(?=<!-- SDTK-CODE:STATUS:START -->)/;
|
|
21
|
-
const LEGACY_VERIFY_SECTION_RE =
|
|
22
|
-
/## 6\. Evidence And Review Notes[\s\S]*?(?=## 7\. Ship \/ Finish Decision)/;
|
|
23
|
-
const LEGACY_SHIP_SECTION_RE = /## 7\. Ship \/ Finish Decision[\s\S]*$/;
|
|
24
|
-
|
|
25
|
-
function resolveWorkflowTemplatePath() {
|
|
26
|
-
if (fs.existsSync(PAYLOAD_TEMPLATE_PATH)) {
|
|
27
|
-
return PAYLOAD_TEMPLATE_PATH;
|
|
28
|
-
}
|
|
29
|
-
if (fs.existsSync(SOURCE_TEMPLATE_PATH)) {
|
|
30
|
-
return SOURCE_TEMPLATE_PATH;
|
|
31
|
-
}
|
|
32
|
-
throw new IntegrityError(
|
|
33
|
-
`SDTK-CODE workflow template not found. Expected ${PAYLOAD_TEMPLATE_PATH} or ${SOURCE_TEMPLATE_PATH}.`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getWorkflowArtifactPath(projectPath, featureKey) {
|
|
38
|
-
return path.join(projectPath, "docs", "dev", `CODE_WORKFLOW_${featureKey}.md`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function renderCheckboxList(entries, formatter, emptyText) {
|
|
42
|
-
if (!entries || entries.length === 0) {
|
|
43
|
-
return `- ${emptyText}`;
|
|
44
|
-
}
|
|
45
|
-
return entries.map((entry) => formatter(entry)).join("\n");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function renderRequiredInputs(requiredInputs, normalizePath) {
|
|
49
|
-
return renderCheckboxList(
|
|
50
|
-
requiredInputs,
|
|
51
|
-
(entry) => `- [${entry.exists ? "x" : " "}] ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
52
|
-
"No required inputs recorded."
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function renderOptionalInputs(optionalInputs, normalizePath) {
|
|
57
|
-
return renderCheckboxList(
|
|
58
|
-
optionalInputs,
|
|
59
|
-
(entry) => `- ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
60
|
-
"No additional inputs discovered yet."
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function renderMissingInputs(missingInputs, normalizePath) {
|
|
65
|
-
return renderCheckboxList(
|
|
66
|
-
missingInputs,
|
|
67
|
-
(entry) => `- ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
68
|
-
"None."
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function renderBulletList(entries, emptyText) {
|
|
73
|
-
if (!entries || entries.length === 0) {
|
|
74
|
-
return `- ${emptyText}`;
|
|
75
|
-
}
|
|
76
|
-
return entries.map((entry) => `- ${entry}`).join("\n");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function humanizeIntakeSource(intakeSource) {
|
|
80
|
-
switch (intakeSource) {
|
|
81
|
-
case "formal_handoff":
|
|
82
|
-
return "formal SDTK-SPEC handoff";
|
|
83
|
-
case "legacy_compatibility":
|
|
84
|
-
return "legacy compatibility intake";
|
|
85
|
-
default:
|
|
86
|
-
return intakeSource || "unknown";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function renderPlanBlock(data) {
|
|
91
|
-
const planningNotes = [];
|
|
92
|
-
if (data.planningMode === "bugfix-light") {
|
|
93
|
-
planningNotes.push(
|
|
94
|
-
"Bugfix lane normally skips `plan`; this lightweight planning step was recorded as an explicit deviation."
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
if (Array.isArray(data.planNotes) && data.planNotes.length > 0) {
|
|
98
|
-
planningNotes.push(...data.planNotes);
|
|
99
|
-
}
|
|
100
|
-
const candidateSlices = Array.isArray(data.candidateSlices) ? data.candidateSlices : [];
|
|
101
|
-
const candidatePlanningNotes = Array.isArray(data.candidatePlanningNotes)
|
|
102
|
-
? data.candidatePlanningNotes
|
|
103
|
-
: [];
|
|
104
|
-
const shouldRenderSeededCandidates =
|
|
105
|
-
data.currentPhase === "start" &&
|
|
106
|
-
data.lane === "feature" &&
|
|
107
|
-
data.slices.length === 0 &&
|
|
108
|
-
candidateSlices.length > 0;
|
|
109
|
-
|
|
110
|
-
if (shouldRenderSeededCandidates) {
|
|
111
|
-
planningNotes.unshift(...candidatePlanningNotes);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const lines = [
|
|
115
|
-
"<!-- SDTK-CODE:PLAN:START -->",
|
|
116
|
-
"## 3. Scope Lock",
|
|
117
|
-
"### In Scope",
|
|
118
|
-
renderBulletList(data.inScope, "Pending confirmation during workflow planning."),
|
|
119
|
-
"",
|
|
120
|
-
"### Out Of Scope",
|
|
121
|
-
renderBulletList(data.outScope, "Pending confirmation during workflow planning."),
|
|
122
|
-
"",
|
|
123
|
-
"### Assumptions",
|
|
124
|
-
renderBulletList(data.assumptions, "No explicit planning assumptions recorded."),
|
|
125
|
-
"",
|
|
126
|
-
"### Risks",
|
|
127
|
-
renderBulletList(data.risks, "No explicit planning risks recorded."),
|
|
128
|
-
"",
|
|
129
|
-
"## 4. Plan / Slices",
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
if (shouldRenderSeededCandidates) {
|
|
133
|
-
lines.push(
|
|
134
|
-
"### Seeded Candidate Slices From Formal Handoff",
|
|
135
|
-
renderBulletList(candidateSlices, "No candidate slices seeded from the formal handoff."),
|
|
136
|
-
"",
|
|
137
|
-
"### Finalized Slices After `plan`",
|
|
138
|
-
renderBulletList(data.slices, "Pending confirmation during workflow planning."),
|
|
139
|
-
""
|
|
140
|
-
);
|
|
141
|
-
} else {
|
|
142
|
-
lines.push(
|
|
143
|
-
renderBulletList(
|
|
144
|
-
data.slices,
|
|
145
|
-
data.lane === "bugfix"
|
|
146
|
-
? "Lightweight bugfix planning not recorded yet."
|
|
147
|
-
: "Pending lane-specific planning or build guidance."
|
|
148
|
-
),
|
|
149
|
-
""
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
lines.push(
|
|
154
|
-
"### Planning Notes",
|
|
155
|
-
renderBulletList(planningNotes, "No additional planning notes recorded."),
|
|
156
|
-
"<!-- SDTK-CODE:PLAN:END -->"
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
return lines.join("\n");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function renderBuildBlock(data) {
|
|
163
|
-
const currentPhase = data.currentPhase || "start";
|
|
164
|
-
const buildStatus = currentPhase === "build" ? data.phaseStatus : "pending";
|
|
165
|
-
const executionMode = data.parallelReason ? "parallel" : "sequential";
|
|
166
|
-
|
|
167
|
-
return [
|
|
168
|
-
"<!-- SDTK-CODE:BUILD:START -->",
|
|
169
|
-
"### Build Progress",
|
|
170
|
-
`- Build status: \`${buildStatus}\``,
|
|
171
|
-
`- Execution mode: \`${executionMode}\``,
|
|
172
|
-
"",
|
|
173
|
-
"### Active Slices",
|
|
174
|
-
renderBulletList(
|
|
175
|
-
data.activeSlices,
|
|
176
|
-
currentPhase === "build"
|
|
177
|
-
? "No active build slices recorded yet."
|
|
178
|
-
: "Pending build-phase execution."
|
|
179
|
-
),
|
|
180
|
-
"",
|
|
181
|
-
"### Build Notes",
|
|
182
|
-
renderBulletList(data.buildNotes, "No build notes recorded yet."),
|
|
183
|
-
"",
|
|
184
|
-
"### Debug Notes",
|
|
185
|
-
renderBulletList(data.debugNotes, "No debug notes recorded."),
|
|
186
|
-
"",
|
|
187
|
-
"### Parallelization Justification",
|
|
188
|
-
renderBulletList(
|
|
189
|
-
data.parallelReason ? [data.parallelReason] : [],
|
|
190
|
-
"Not using explicit parallel execution in this build pass."
|
|
191
|
-
),
|
|
192
|
-
"<!-- SDTK-CODE:BUILD:END -->",
|
|
193
|
-
].join("\n");
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function renderEvidenceList(entries, emptyText = "No summarized verification evidence recorded yet.") {
|
|
197
|
-
if (!entries || entries.length === 0) {
|
|
198
|
-
return `- ${emptyText}`;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return entries
|
|
202
|
-
.map(
|
|
203
|
-
(entry) =>
|
|
204
|
-
`- \`${entry.checkName}\` | \`${entry.result}\` | ${entry.summary} | Raw output: \`${entry.rawOutputRef}\``
|
|
205
|
-
)
|
|
206
|
-
.join("\n");
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function renderVerifyBlock(data) {
|
|
210
|
-
return [
|
|
211
|
-
"<!-- SDTK-CODE:VERIFY:START -->",
|
|
212
|
-
"## 6. Evidence And Review Notes",
|
|
213
|
-
"### Review Packet",
|
|
214
|
-
data.reviewPacketPath
|
|
215
|
-
? `- Review packet: \`${data.reviewPacketPath}\``
|
|
216
|
-
: "- Review packet not generated yet.",
|
|
217
|
-
"",
|
|
218
|
-
"### Evidence Summary",
|
|
219
|
-
renderEvidenceList(data.evidenceEntries),
|
|
220
|
-
"",
|
|
221
|
-
"### Raw Output References",
|
|
222
|
-
`- Store raw command output under \`docs/dev/evidence/${data.featureKey}/\` and reference it from this section.`,
|
|
223
|
-
"",
|
|
224
|
-
"### Review Gate Status",
|
|
225
|
-
`- Evidence gate: \`${data.evidenceGate}\``,
|
|
226
|
-
`- Spec/compliance gate: \`${data.specGateStatus}\``,
|
|
227
|
-
`- Quality gate: \`${data.qualityGateStatus}\``,
|
|
228
|
-
"",
|
|
229
|
-
"### Spec / Compliance Notes",
|
|
230
|
-
renderBulletList(data.specNotes, "No spec/compliance notes recorded yet."),
|
|
231
|
-
"",
|
|
232
|
-
"### Quality Notes",
|
|
233
|
-
renderBulletList(data.qualityNotes, "No quality review notes recorded yet."),
|
|
234
|
-
"",
|
|
235
|
-
"### Debug Follow-Up",
|
|
236
|
-
renderBulletList(data.verifyDebugNotes, "No reactive debug follow-up recorded."),
|
|
237
|
-
"<!-- SDTK-CODE:VERIFY:END -->",
|
|
238
|
-
].join("\n");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function renderShipBlock(data) {
|
|
242
|
-
return [
|
|
243
|
-
"<!-- SDTK-CODE:SHIP:START -->",
|
|
244
|
-
"## 7. Ship / Finish Decision",
|
|
245
|
-
"### Final Decision",
|
|
246
|
-
`- Decision: \`${data.shipDecision}\``,
|
|
247
|
-
`- Ship status: \`${data.shipStatus}\``,
|
|
248
|
-
"",
|
|
249
|
-
"### Preflight Summary",
|
|
250
|
-
renderEvidenceList(data.preflightEntries, "No ship preflight entries recorded yet."),
|
|
251
|
-
"",
|
|
252
|
-
"### Follow-Up Items",
|
|
253
|
-
renderBulletList(data.shipFollowUps, "No follow-up items recorded."),
|
|
254
|
-
"",
|
|
255
|
-
"### Ship Notes",
|
|
256
|
-
renderBulletList(data.shipNotes, "No additional ship notes recorded."),
|
|
257
|
-
"",
|
|
258
|
-
"### Debug Follow-Up",
|
|
259
|
-
renderBulletList(data.shipDebugNotes, "No reactive debug follow-up recorded."),
|
|
260
|
-
"<!-- SDTK-CODE:SHIP:END -->",
|
|
261
|
-
].join("\n");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function renderManagedBlocks(data) {
|
|
265
|
-
const currentPhase = data.currentPhase || "start";
|
|
266
|
-
const isClosedWorkflow = data.nextPhase === "none";
|
|
267
|
-
const suggestedEngine =
|
|
268
|
-
isClosedWorkflow || !Array.isArray(data.suggestedEngineSkills) || data.suggestedEngineSkills.length === 0
|
|
269
|
-
? "none (workflow closed)"
|
|
270
|
-
: data.suggestedEngineSkills.map((value) => `\`${value}\``).join(", ");
|
|
271
|
-
|
|
272
|
-
return {
|
|
273
|
-
METADATA: [
|
|
274
|
-
"<!-- SDTK-CODE:METADATA:START -->",
|
|
275
|
-
"## 1. Metadata",
|
|
276
|
-
`- Feature key: \`${data.featureKey}\``,
|
|
277
|
-
`- Lane: \`${data.lane}\``,
|
|
278
|
-
`- Current phase: \`${currentPhase}\``,
|
|
279
|
-
`- Phase status: \`${data.phaseStatus}\``,
|
|
280
|
-
`- Intake outcome: \`${data.intakeOutcome}\``,
|
|
281
|
-
`- Last updated: \`${data.lastUpdated}\``,
|
|
282
|
-
"<!-- SDTK-CODE:METADATA:END -->",
|
|
283
|
-
].join("\n"),
|
|
284
|
-
INPUTS: [
|
|
285
|
-
"<!-- SDTK-CODE:INPUTS:START -->",
|
|
286
|
-
"## 2. Inputs",
|
|
287
|
-
"### Intake Source",
|
|
288
|
-
`- Source: \`${humanizeIntakeSource(data.intakeSource)}\``,
|
|
289
|
-
`- Formal handoff status: \`${data.handoffStatus}\``,
|
|
290
|
-
"",
|
|
291
|
-
"### Intake Notes",
|
|
292
|
-
renderBulletList(data.compatibilityWarnings, "No compatibility notes recorded."),
|
|
293
|
-
"",
|
|
294
|
-
"### Required Inputs",
|
|
295
|
-
renderRequiredInputs(data.requiredInputs, data.normalizePath),
|
|
296
|
-
"",
|
|
297
|
-
"### Additional Discovered Inputs",
|
|
298
|
-
renderOptionalInputs(data.optionalInputs, data.normalizePath),
|
|
299
|
-
"",
|
|
300
|
-
"### Missing Required Inputs",
|
|
301
|
-
renderMissingInputs(data.missingInputs, data.normalizePath),
|
|
302
|
-
"<!-- SDTK-CODE:INPUTS:END -->",
|
|
303
|
-
].join("\n"),
|
|
304
|
-
PLAN: renderPlanBlock(data),
|
|
305
|
-
BUILD: renderBuildBlock(data),
|
|
306
|
-
VERIFY: renderVerifyBlock(data),
|
|
307
|
-
SHIP: renderShipBlock(data),
|
|
308
|
-
STATUS: [
|
|
309
|
-
"<!-- SDTK-CODE:STATUS:START -->",
|
|
310
|
-
"## 5. Status Checklist",
|
|
311
|
-
`- Current phase: \`${currentPhase}\``,
|
|
312
|
-
`- Next recommended phase: \`${data.nextPhase}\``,
|
|
313
|
-
`- Suggested engine entrypoints: ${suggestedEngine}`,
|
|
314
|
-
`- Blocking state: \`${data.blockingState}\``,
|
|
315
|
-
"<!-- SDTK-CODE:STATUS:END -->",
|
|
316
|
-
].join("\n"),
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function renderNewArtifact(templateText, data) {
|
|
321
|
-
const blocks = renderManagedBlocks(data);
|
|
322
|
-
const replacements = {
|
|
323
|
-
"__FEATURE_KEY__": data.featureKey,
|
|
324
|
-
"__LANE__": data.lane,
|
|
325
|
-
"__PHASE_STATUS__": data.phaseStatus,
|
|
326
|
-
"__INTAKE_OUTCOME__": data.intakeOutcome,
|
|
327
|
-
"__LAST_UPDATED__": data.lastUpdated,
|
|
328
|
-
"__REQUIRED_INPUTS__": renderRequiredInputs(data.requiredInputs, data.normalizePath),
|
|
329
|
-
"__ADDITIONAL_INPUTS__": renderOptionalInputs(data.optionalInputs, data.normalizePath),
|
|
330
|
-
"__MISSING_INPUTS__": renderMissingInputs(data.missingInputs, data.normalizePath),
|
|
331
|
-
"__NEXT_PHASE__": data.nextPhase,
|
|
332
|
-
"__SUGGESTED_ENGINE__": data.suggestedEngineSkills.map((value) => `\`${value}\``).join(", "),
|
|
333
|
-
"__BLOCKING_STATE__": data.blockingState,
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
let rendered = templateText;
|
|
337
|
-
for (const [token, value] of Object.entries(replacements)) {
|
|
338
|
-
rendered = rendered.split(token).join(value);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
for (const [name, block] of Object.entries(blocks)) {
|
|
342
|
-
const regex = new RegExp(
|
|
343
|
-
`<!-- SDTK-CODE:${name}:START -->[\\s\\S]*?<!-- SDTK-CODE:${name}:END -->`
|
|
344
|
-
);
|
|
345
|
-
rendered = rendered.replace(regex, block);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return rendered;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function replaceManagedBlock(text, blockName, replacement) {
|
|
352
|
-
const regex = new RegExp(
|
|
353
|
-
`<!-- SDTK-CODE:${blockName}:START -->[\\s\\S]*?<!-- SDTK-CODE:${blockName}:END -->`
|
|
354
|
-
);
|
|
355
|
-
if (!regex.test(text)) {
|
|
356
|
-
if (blockName === "PLAN" && LEGACY_PLAN_SECTION_RE.test(text)) {
|
|
357
|
-
return text.replace(LEGACY_PLAN_SECTION_RE, `${replacement}\n\n`);
|
|
358
|
-
}
|
|
359
|
-
if (blockName === "BUILD" && STATUS_BLOCK_RE.test(text)) {
|
|
360
|
-
return text.replace(STATUS_BLOCK_RE, `${replacement}\n\n`);
|
|
361
|
-
}
|
|
362
|
-
if (blockName === "VERIFY" && LEGACY_VERIFY_SECTION_RE.test(text)) {
|
|
363
|
-
return text.replace(LEGACY_VERIFY_SECTION_RE, `${replacement}\n\n`);
|
|
364
|
-
}
|
|
365
|
-
if (blockName === "SHIP" && LEGACY_SHIP_SECTION_RE.test(text)) {
|
|
366
|
-
return text.replace(LEGACY_SHIP_SECTION_RE, replacement);
|
|
367
|
-
}
|
|
368
|
-
throw new ValidationError(
|
|
369
|
-
`Existing workflow artifact is missing managed block ${blockName}. Re-run with --force to reinitialize it.`
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
return text.replace(regex, replacement);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function extractManagedBlock(text, blockName) {
|
|
376
|
-
const regex = new RegExp(
|
|
377
|
-
`<!-- SDTK-CODE:${blockName}:START -->([\\s\\S]*?)<!-- SDTK-CODE:${blockName}:END -->`
|
|
378
|
-
);
|
|
379
|
-
const match = text.match(regex);
|
|
380
|
-
return match ? match[1] : null;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function parseMetadataField(metadataBlock, label) {
|
|
384
|
-
const escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
385
|
-
const regex = new RegExp(`- ${escapedLabel}: \`([^\\r\\n\`]+)\``);
|
|
386
|
-
const match = metadataBlock.match(regex);
|
|
387
|
-
return match ? match[1] : null;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function parseManagedField(blockText, label) {
|
|
391
|
-
if (!blockText) {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
return parseMetadataField(blockText, label);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function loadWorkflowArtifactState(projectPath, featureKey) {
|
|
398
|
-
const artifactPath = getWorkflowArtifactPath(projectPath, featureKey);
|
|
399
|
-
if (!fs.existsSync(artifactPath)) {
|
|
400
|
-
throw new ValidationError(
|
|
401
|
-
`Workflow artifact not found: ${artifactPath}. Run "sdtk-code start --lane <feature|bugfix> --feature-key ${featureKey}" first.`
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const text = fs.readFileSync(artifactPath, "utf-8");
|
|
406
|
-
const metadataBlock = extractManagedBlock(text, "METADATA");
|
|
407
|
-
if (!metadataBlock) {
|
|
408
|
-
throw new ValidationError(
|
|
409
|
-
`Workflow artifact is missing the METADATA block: ${artifactPath}. Re-run "sdtk-code start --force" to reinitialize it.`
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const state = {
|
|
414
|
-
artifactPath,
|
|
415
|
-
text,
|
|
416
|
-
featureKey: parseMetadataField(metadataBlock, "Feature key"),
|
|
417
|
-
lane: parseMetadataField(metadataBlock, "Lane"),
|
|
418
|
-
currentPhase: parseMetadataField(metadataBlock, "Current phase"),
|
|
419
|
-
phaseStatus: parseMetadataField(metadataBlock, "Phase status"),
|
|
420
|
-
intakeOutcome: parseMetadataField(metadataBlock, "Intake outcome"),
|
|
421
|
-
lastUpdated: parseMetadataField(metadataBlock, "Last updated"),
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
for (const [key, value] of Object.entries(state)) {
|
|
425
|
-
if (key === "artifactPath" || key === "text" || key === "lastUpdated") {
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
if (!value) {
|
|
429
|
-
throw new ValidationError(
|
|
430
|
-
`Workflow artifact is missing required metadata field "${key}": ${artifactPath}. Re-run "sdtk-code start --force" to repair it.`
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return state;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function createOrUpdateWorkflowArtifact(options) {
|
|
439
|
-
const templatePath = resolveWorkflowTemplatePath();
|
|
440
|
-
const templateText = fs.readFileSync(templatePath, "utf-8");
|
|
441
|
-
const artifactPath = getWorkflowArtifactPath(options.projectPath, options.featureKey);
|
|
442
|
-
const artifactDir = path.dirname(artifactPath);
|
|
443
|
-
fs.mkdirSync(artifactDir, { recursive: true });
|
|
444
|
-
|
|
445
|
-
const data = {
|
|
446
|
-
...options,
|
|
447
|
-
currentPhase: options.currentPhase || "start",
|
|
448
|
-
inScope: options.inScope || [],
|
|
449
|
-
outScope: options.outScope || [],
|
|
450
|
-
assumptions: options.assumptions || [],
|
|
451
|
-
risks: options.risks || [],
|
|
452
|
-
slices: options.slices || [],
|
|
453
|
-
planNotes: options.planNotes || [],
|
|
454
|
-
candidateSlices: options.candidateSlices || [],
|
|
455
|
-
candidatePlanningNotes: options.candidatePlanningNotes || [],
|
|
456
|
-
activeSlices: options.activeSlices || [],
|
|
457
|
-
buildNotes: options.buildNotes || [],
|
|
458
|
-
debugNotes: options.debugNotes || [],
|
|
459
|
-
parallelReason: options.parallelReason || null,
|
|
460
|
-
evidenceEntries: options.evidenceEntries || [],
|
|
461
|
-
evidenceGate: options.evidenceGate || "pending",
|
|
462
|
-
specGateStatus: options.specGateStatus || "pending",
|
|
463
|
-
qualityGateStatus: options.qualityGateStatus || "pending",
|
|
464
|
-
specNotes: options.specNotes || [],
|
|
465
|
-
qualityNotes: options.qualityNotes || [],
|
|
466
|
-
verifyDebugNotes: options.verifyDebugNotes || [],
|
|
467
|
-
shipDecision: options.shipDecision || "pending",
|
|
468
|
-
shipStatus: options.shipStatus || "pending",
|
|
469
|
-
preflightEntries: options.preflightEntries || [],
|
|
470
|
-
shipFollowUps: options.shipFollowUps || [],
|
|
471
|
-
shipNotes: options.shipNotes || [],
|
|
472
|
-
shipDebugNotes: options.shipDebugNotes || [],
|
|
473
|
-
reviewPacketPath: options.reviewPacketPath || null,
|
|
474
|
-
intakeSource: options.intakeSource || "legacy_compatibility",
|
|
475
|
-
handoffStatus: options.handoffStatus || "missing",
|
|
476
|
-
compatibilityWarnings: options.compatibilityWarnings || [],
|
|
477
|
-
lastUpdated: new Date().toISOString(),
|
|
478
|
-
};
|
|
479
|
-
const managedBlocks = options.managedBlocks || DEFAULT_MANAGED_BLOCKS;
|
|
480
|
-
|
|
481
|
-
let nextText;
|
|
482
|
-
if (!fs.existsSync(artifactPath) || options.force) {
|
|
483
|
-
nextText = renderNewArtifact(templateText, data);
|
|
484
|
-
} else {
|
|
485
|
-
nextText = fs.readFileSync(artifactPath, "utf-8");
|
|
486
|
-
const blocks = renderManagedBlocks(data);
|
|
487
|
-
for (const blockName of managedBlocks) {
|
|
488
|
-
nextText = replaceManagedBlock(nextText, blockName, blocks[blockName]);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
fs.writeFileSync(artifactPath, nextText, "utf-8");
|
|
493
|
-
return artifactPath;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
module.exports = {
|
|
497
|
-
createOrUpdateWorkflowArtifact,
|
|
498
|
-
extractManagedBlock,
|
|
499
|
-
getWorkflowArtifactPath,
|
|
500
|
-
loadWorkflowArtifactState,
|
|
501
|
-
parseManagedField,
|
|
502
|
-
resolveWorkflowTemplatePath,
|
|
503
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { IntegrityError, ValidationError } = require("./errors");
|
|
6
|
+
const { resolvePayloadFile } = require("./toolkit-payload");
|
|
7
|
+
|
|
8
|
+
const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
|
|
9
|
+
const PRODUCT_ROOT = path.resolve(PACKAGE_ROOT, "..", "..");
|
|
10
|
+
const SOURCE_TEMPLATE_PATH = path.join(
|
|
11
|
+
PRODUCT_ROOT,
|
|
12
|
+
"toolkit",
|
|
13
|
+
"templates",
|
|
14
|
+
"CODE_WORKFLOW_TEMPLATE.md"
|
|
15
|
+
);
|
|
16
|
+
const PAYLOAD_TEMPLATE_PATH = resolvePayloadFile("toolkit/templates/CODE_WORKFLOW_TEMPLATE.md");
|
|
17
|
+
const DEFAULT_MANAGED_BLOCKS = ["METADATA", "INPUTS", "PLAN", "BUILD", "STATUS"];
|
|
18
|
+
const LEGACY_PLAN_SECTION_RE =
|
|
19
|
+
/## 3\. Scope Lock[\s\S]*?(?=<!-- SDTK-CODE:STATUS:START -->|## 5\. Status Checklist)/;
|
|
20
|
+
const STATUS_BLOCK_RE = /(?=<!-- SDTK-CODE:STATUS:START -->)/;
|
|
21
|
+
const LEGACY_VERIFY_SECTION_RE =
|
|
22
|
+
/## 6\. Evidence And Review Notes[\s\S]*?(?=## 7\. Ship \/ Finish Decision)/;
|
|
23
|
+
const LEGACY_SHIP_SECTION_RE = /## 7\. Ship \/ Finish Decision[\s\S]*$/;
|
|
24
|
+
|
|
25
|
+
function resolveWorkflowTemplatePath() {
|
|
26
|
+
if (fs.existsSync(PAYLOAD_TEMPLATE_PATH)) {
|
|
27
|
+
return PAYLOAD_TEMPLATE_PATH;
|
|
28
|
+
}
|
|
29
|
+
if (fs.existsSync(SOURCE_TEMPLATE_PATH)) {
|
|
30
|
+
return SOURCE_TEMPLATE_PATH;
|
|
31
|
+
}
|
|
32
|
+
throw new IntegrityError(
|
|
33
|
+
`SDTK-CODE workflow template not found. Expected ${PAYLOAD_TEMPLATE_PATH} or ${SOURCE_TEMPLATE_PATH}.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getWorkflowArtifactPath(projectPath, featureKey) {
|
|
38
|
+
return path.join(projectPath, "docs", "dev", `CODE_WORKFLOW_${featureKey}.md`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function renderCheckboxList(entries, formatter, emptyText) {
|
|
42
|
+
if (!entries || entries.length === 0) {
|
|
43
|
+
return `- ${emptyText}`;
|
|
44
|
+
}
|
|
45
|
+
return entries.map((entry) => formatter(entry)).join("\n");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function renderRequiredInputs(requiredInputs, normalizePath) {
|
|
49
|
+
return renderCheckboxList(
|
|
50
|
+
requiredInputs,
|
|
51
|
+
(entry) => `- [${entry.exists ? "x" : " "}] ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
52
|
+
"No required inputs recorded."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renderOptionalInputs(optionalInputs, normalizePath) {
|
|
57
|
+
return renderCheckboxList(
|
|
58
|
+
optionalInputs,
|
|
59
|
+
(entry) => `- ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
60
|
+
"No additional inputs discovered yet."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function renderMissingInputs(missingInputs, normalizePath) {
|
|
65
|
+
return renderCheckboxList(
|
|
66
|
+
missingInputs,
|
|
67
|
+
(entry) => `- ${entry.key}: \`${normalizePath(entry.path)}\``,
|
|
68
|
+
"None."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function renderBulletList(entries, emptyText) {
|
|
73
|
+
if (!entries || entries.length === 0) {
|
|
74
|
+
return `- ${emptyText}`;
|
|
75
|
+
}
|
|
76
|
+
return entries.map((entry) => `- ${entry}`).join("\n");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function humanizeIntakeSource(intakeSource) {
|
|
80
|
+
switch (intakeSource) {
|
|
81
|
+
case "formal_handoff":
|
|
82
|
+
return "formal SDTK-SPEC handoff";
|
|
83
|
+
case "legacy_compatibility":
|
|
84
|
+
return "legacy compatibility intake";
|
|
85
|
+
default:
|
|
86
|
+
return intakeSource || "unknown";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function renderPlanBlock(data) {
|
|
91
|
+
const planningNotes = [];
|
|
92
|
+
if (data.planningMode === "bugfix-light") {
|
|
93
|
+
planningNotes.push(
|
|
94
|
+
"Bugfix lane normally skips `plan`; this lightweight planning step was recorded as an explicit deviation."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(data.planNotes) && data.planNotes.length > 0) {
|
|
98
|
+
planningNotes.push(...data.planNotes);
|
|
99
|
+
}
|
|
100
|
+
const candidateSlices = Array.isArray(data.candidateSlices) ? data.candidateSlices : [];
|
|
101
|
+
const candidatePlanningNotes = Array.isArray(data.candidatePlanningNotes)
|
|
102
|
+
? data.candidatePlanningNotes
|
|
103
|
+
: [];
|
|
104
|
+
const shouldRenderSeededCandidates =
|
|
105
|
+
data.currentPhase === "start" &&
|
|
106
|
+
data.lane === "feature" &&
|
|
107
|
+
data.slices.length === 0 &&
|
|
108
|
+
candidateSlices.length > 0;
|
|
109
|
+
|
|
110
|
+
if (shouldRenderSeededCandidates) {
|
|
111
|
+
planningNotes.unshift(...candidatePlanningNotes);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const lines = [
|
|
115
|
+
"<!-- SDTK-CODE:PLAN:START -->",
|
|
116
|
+
"## 3. Scope Lock",
|
|
117
|
+
"### In Scope",
|
|
118
|
+
renderBulletList(data.inScope, "Pending confirmation during workflow planning."),
|
|
119
|
+
"",
|
|
120
|
+
"### Out Of Scope",
|
|
121
|
+
renderBulletList(data.outScope, "Pending confirmation during workflow planning."),
|
|
122
|
+
"",
|
|
123
|
+
"### Assumptions",
|
|
124
|
+
renderBulletList(data.assumptions, "No explicit planning assumptions recorded."),
|
|
125
|
+
"",
|
|
126
|
+
"### Risks",
|
|
127
|
+
renderBulletList(data.risks, "No explicit planning risks recorded."),
|
|
128
|
+
"",
|
|
129
|
+
"## 4. Plan / Slices",
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
if (shouldRenderSeededCandidates) {
|
|
133
|
+
lines.push(
|
|
134
|
+
"### Seeded Candidate Slices From Formal Handoff",
|
|
135
|
+
renderBulletList(candidateSlices, "No candidate slices seeded from the formal handoff."),
|
|
136
|
+
"",
|
|
137
|
+
"### Finalized Slices After `plan`",
|
|
138
|
+
renderBulletList(data.slices, "Pending confirmation during workflow planning."),
|
|
139
|
+
""
|
|
140
|
+
);
|
|
141
|
+
} else {
|
|
142
|
+
lines.push(
|
|
143
|
+
renderBulletList(
|
|
144
|
+
data.slices,
|
|
145
|
+
data.lane === "bugfix"
|
|
146
|
+
? "Lightweight bugfix planning not recorded yet."
|
|
147
|
+
: "Pending lane-specific planning or build guidance."
|
|
148
|
+
),
|
|
149
|
+
""
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
lines.push(
|
|
154
|
+
"### Planning Notes",
|
|
155
|
+
renderBulletList(planningNotes, "No additional planning notes recorded."),
|
|
156
|
+
"<!-- SDTK-CODE:PLAN:END -->"
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return lines.join("\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function renderBuildBlock(data) {
|
|
163
|
+
const currentPhase = data.currentPhase || "start";
|
|
164
|
+
const buildStatus = currentPhase === "build" ? data.phaseStatus : "pending";
|
|
165
|
+
const executionMode = data.parallelReason ? "parallel" : "sequential";
|
|
166
|
+
|
|
167
|
+
return [
|
|
168
|
+
"<!-- SDTK-CODE:BUILD:START -->",
|
|
169
|
+
"### Build Progress",
|
|
170
|
+
`- Build status: \`${buildStatus}\``,
|
|
171
|
+
`- Execution mode: \`${executionMode}\``,
|
|
172
|
+
"",
|
|
173
|
+
"### Active Slices",
|
|
174
|
+
renderBulletList(
|
|
175
|
+
data.activeSlices,
|
|
176
|
+
currentPhase === "build"
|
|
177
|
+
? "No active build slices recorded yet."
|
|
178
|
+
: "Pending build-phase execution."
|
|
179
|
+
),
|
|
180
|
+
"",
|
|
181
|
+
"### Build Notes",
|
|
182
|
+
renderBulletList(data.buildNotes, "No build notes recorded yet."),
|
|
183
|
+
"",
|
|
184
|
+
"### Debug Notes",
|
|
185
|
+
renderBulletList(data.debugNotes, "No debug notes recorded."),
|
|
186
|
+
"",
|
|
187
|
+
"### Parallelization Justification",
|
|
188
|
+
renderBulletList(
|
|
189
|
+
data.parallelReason ? [data.parallelReason] : [],
|
|
190
|
+
"Not using explicit parallel execution in this build pass."
|
|
191
|
+
),
|
|
192
|
+
"<!-- SDTK-CODE:BUILD:END -->",
|
|
193
|
+
].join("\n");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function renderEvidenceList(entries, emptyText = "No summarized verification evidence recorded yet.") {
|
|
197
|
+
if (!entries || entries.length === 0) {
|
|
198
|
+
return `- ${emptyText}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return entries
|
|
202
|
+
.map(
|
|
203
|
+
(entry) =>
|
|
204
|
+
`- \`${entry.checkName}\` | \`${entry.result}\` | ${entry.summary} | Raw output: \`${entry.rawOutputRef}\``
|
|
205
|
+
)
|
|
206
|
+
.join("\n");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function renderVerifyBlock(data) {
|
|
210
|
+
return [
|
|
211
|
+
"<!-- SDTK-CODE:VERIFY:START -->",
|
|
212
|
+
"## 6. Evidence And Review Notes",
|
|
213
|
+
"### Review Packet",
|
|
214
|
+
data.reviewPacketPath
|
|
215
|
+
? `- Review packet: \`${data.reviewPacketPath}\``
|
|
216
|
+
: "- Review packet not generated yet.",
|
|
217
|
+
"",
|
|
218
|
+
"### Evidence Summary",
|
|
219
|
+
renderEvidenceList(data.evidenceEntries),
|
|
220
|
+
"",
|
|
221
|
+
"### Raw Output References",
|
|
222
|
+
`- Store raw command output under \`docs/dev/evidence/${data.featureKey}/\` and reference it from this section.`,
|
|
223
|
+
"",
|
|
224
|
+
"### Review Gate Status",
|
|
225
|
+
`- Evidence gate: \`${data.evidenceGate}\``,
|
|
226
|
+
`- Spec/compliance gate: \`${data.specGateStatus}\``,
|
|
227
|
+
`- Quality gate: \`${data.qualityGateStatus}\``,
|
|
228
|
+
"",
|
|
229
|
+
"### Spec / Compliance Notes",
|
|
230
|
+
renderBulletList(data.specNotes, "No spec/compliance notes recorded yet."),
|
|
231
|
+
"",
|
|
232
|
+
"### Quality Notes",
|
|
233
|
+
renderBulletList(data.qualityNotes, "No quality review notes recorded yet."),
|
|
234
|
+
"",
|
|
235
|
+
"### Debug Follow-Up",
|
|
236
|
+
renderBulletList(data.verifyDebugNotes, "No reactive debug follow-up recorded."),
|
|
237
|
+
"<!-- SDTK-CODE:VERIFY:END -->",
|
|
238
|
+
].join("\n");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function renderShipBlock(data) {
|
|
242
|
+
return [
|
|
243
|
+
"<!-- SDTK-CODE:SHIP:START -->",
|
|
244
|
+
"## 7. Ship / Finish Decision",
|
|
245
|
+
"### Final Decision",
|
|
246
|
+
`- Decision: \`${data.shipDecision}\``,
|
|
247
|
+
`- Ship status: \`${data.shipStatus}\``,
|
|
248
|
+
"",
|
|
249
|
+
"### Preflight Summary",
|
|
250
|
+
renderEvidenceList(data.preflightEntries, "No ship preflight entries recorded yet."),
|
|
251
|
+
"",
|
|
252
|
+
"### Follow-Up Items",
|
|
253
|
+
renderBulletList(data.shipFollowUps, "No follow-up items recorded."),
|
|
254
|
+
"",
|
|
255
|
+
"### Ship Notes",
|
|
256
|
+
renderBulletList(data.shipNotes, "No additional ship notes recorded."),
|
|
257
|
+
"",
|
|
258
|
+
"### Debug Follow-Up",
|
|
259
|
+
renderBulletList(data.shipDebugNotes, "No reactive debug follow-up recorded."),
|
|
260
|
+
"<!-- SDTK-CODE:SHIP:END -->",
|
|
261
|
+
].join("\n");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function renderManagedBlocks(data) {
|
|
265
|
+
const currentPhase = data.currentPhase || "start";
|
|
266
|
+
const isClosedWorkflow = data.nextPhase === "none";
|
|
267
|
+
const suggestedEngine =
|
|
268
|
+
isClosedWorkflow || !Array.isArray(data.suggestedEngineSkills) || data.suggestedEngineSkills.length === 0
|
|
269
|
+
? "none (workflow closed)"
|
|
270
|
+
: data.suggestedEngineSkills.map((value) => `\`${value}\``).join(", ");
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
METADATA: [
|
|
274
|
+
"<!-- SDTK-CODE:METADATA:START -->",
|
|
275
|
+
"## 1. Metadata",
|
|
276
|
+
`- Feature key: \`${data.featureKey}\``,
|
|
277
|
+
`- Lane: \`${data.lane}\``,
|
|
278
|
+
`- Current phase: \`${currentPhase}\``,
|
|
279
|
+
`- Phase status: \`${data.phaseStatus}\``,
|
|
280
|
+
`- Intake outcome: \`${data.intakeOutcome}\``,
|
|
281
|
+
`- Last updated: \`${data.lastUpdated}\``,
|
|
282
|
+
"<!-- SDTK-CODE:METADATA:END -->",
|
|
283
|
+
].join("\n"),
|
|
284
|
+
INPUTS: [
|
|
285
|
+
"<!-- SDTK-CODE:INPUTS:START -->",
|
|
286
|
+
"## 2. Inputs",
|
|
287
|
+
"### Intake Source",
|
|
288
|
+
`- Source: \`${humanizeIntakeSource(data.intakeSource)}\``,
|
|
289
|
+
`- Formal handoff status: \`${data.handoffStatus}\``,
|
|
290
|
+
"",
|
|
291
|
+
"### Intake Notes",
|
|
292
|
+
renderBulletList(data.compatibilityWarnings, "No compatibility notes recorded."),
|
|
293
|
+
"",
|
|
294
|
+
"### Required Inputs",
|
|
295
|
+
renderRequiredInputs(data.requiredInputs, data.normalizePath),
|
|
296
|
+
"",
|
|
297
|
+
"### Additional Discovered Inputs",
|
|
298
|
+
renderOptionalInputs(data.optionalInputs, data.normalizePath),
|
|
299
|
+
"",
|
|
300
|
+
"### Missing Required Inputs",
|
|
301
|
+
renderMissingInputs(data.missingInputs, data.normalizePath),
|
|
302
|
+
"<!-- SDTK-CODE:INPUTS:END -->",
|
|
303
|
+
].join("\n"),
|
|
304
|
+
PLAN: renderPlanBlock(data),
|
|
305
|
+
BUILD: renderBuildBlock(data),
|
|
306
|
+
VERIFY: renderVerifyBlock(data),
|
|
307
|
+
SHIP: renderShipBlock(data),
|
|
308
|
+
STATUS: [
|
|
309
|
+
"<!-- SDTK-CODE:STATUS:START -->",
|
|
310
|
+
"## 5. Status Checklist",
|
|
311
|
+
`- Current phase: \`${currentPhase}\``,
|
|
312
|
+
`- Next recommended phase: \`${data.nextPhase}\``,
|
|
313
|
+
`- Suggested engine entrypoints: ${suggestedEngine}`,
|
|
314
|
+
`- Blocking state: \`${data.blockingState}\``,
|
|
315
|
+
"<!-- SDTK-CODE:STATUS:END -->",
|
|
316
|
+
].join("\n"),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function renderNewArtifact(templateText, data) {
|
|
321
|
+
const blocks = renderManagedBlocks(data);
|
|
322
|
+
const replacements = {
|
|
323
|
+
"__FEATURE_KEY__": data.featureKey,
|
|
324
|
+
"__LANE__": data.lane,
|
|
325
|
+
"__PHASE_STATUS__": data.phaseStatus,
|
|
326
|
+
"__INTAKE_OUTCOME__": data.intakeOutcome,
|
|
327
|
+
"__LAST_UPDATED__": data.lastUpdated,
|
|
328
|
+
"__REQUIRED_INPUTS__": renderRequiredInputs(data.requiredInputs, data.normalizePath),
|
|
329
|
+
"__ADDITIONAL_INPUTS__": renderOptionalInputs(data.optionalInputs, data.normalizePath),
|
|
330
|
+
"__MISSING_INPUTS__": renderMissingInputs(data.missingInputs, data.normalizePath),
|
|
331
|
+
"__NEXT_PHASE__": data.nextPhase,
|
|
332
|
+
"__SUGGESTED_ENGINE__": data.suggestedEngineSkills.map((value) => `\`${value}\``).join(", "),
|
|
333
|
+
"__BLOCKING_STATE__": data.blockingState,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
let rendered = templateText;
|
|
337
|
+
for (const [token, value] of Object.entries(replacements)) {
|
|
338
|
+
rendered = rendered.split(token).join(value);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
for (const [name, block] of Object.entries(blocks)) {
|
|
342
|
+
const regex = new RegExp(
|
|
343
|
+
`<!-- SDTK-CODE:${name}:START -->[\\s\\S]*?<!-- SDTK-CODE:${name}:END -->`
|
|
344
|
+
);
|
|
345
|
+
rendered = rendered.replace(regex, block);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return rendered;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function replaceManagedBlock(text, blockName, replacement) {
|
|
352
|
+
const regex = new RegExp(
|
|
353
|
+
`<!-- SDTK-CODE:${blockName}:START -->[\\s\\S]*?<!-- SDTK-CODE:${blockName}:END -->`
|
|
354
|
+
);
|
|
355
|
+
if (!regex.test(text)) {
|
|
356
|
+
if (blockName === "PLAN" && LEGACY_PLAN_SECTION_RE.test(text)) {
|
|
357
|
+
return text.replace(LEGACY_PLAN_SECTION_RE, `${replacement}\n\n`);
|
|
358
|
+
}
|
|
359
|
+
if (blockName === "BUILD" && STATUS_BLOCK_RE.test(text)) {
|
|
360
|
+
return text.replace(STATUS_BLOCK_RE, `${replacement}\n\n`);
|
|
361
|
+
}
|
|
362
|
+
if (blockName === "VERIFY" && LEGACY_VERIFY_SECTION_RE.test(text)) {
|
|
363
|
+
return text.replace(LEGACY_VERIFY_SECTION_RE, `${replacement}\n\n`);
|
|
364
|
+
}
|
|
365
|
+
if (blockName === "SHIP" && LEGACY_SHIP_SECTION_RE.test(text)) {
|
|
366
|
+
return text.replace(LEGACY_SHIP_SECTION_RE, replacement);
|
|
367
|
+
}
|
|
368
|
+
throw new ValidationError(
|
|
369
|
+
`Existing workflow artifact is missing managed block ${blockName}. Re-run with --force to reinitialize it.`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return text.replace(regex, replacement);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function extractManagedBlock(text, blockName) {
|
|
376
|
+
const regex = new RegExp(
|
|
377
|
+
`<!-- SDTK-CODE:${blockName}:START -->([\\s\\S]*?)<!-- SDTK-CODE:${blockName}:END -->`
|
|
378
|
+
);
|
|
379
|
+
const match = text.match(regex);
|
|
380
|
+
return match ? match[1] : null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function parseMetadataField(metadataBlock, label) {
|
|
384
|
+
const escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
385
|
+
const regex = new RegExp(`- ${escapedLabel}: \`([^\\r\\n\`]+)\``);
|
|
386
|
+
const match = metadataBlock.match(regex);
|
|
387
|
+
return match ? match[1] : null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function parseManagedField(blockText, label) {
|
|
391
|
+
if (!blockText) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
return parseMetadataField(blockText, label);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function loadWorkflowArtifactState(projectPath, featureKey) {
|
|
398
|
+
const artifactPath = getWorkflowArtifactPath(projectPath, featureKey);
|
|
399
|
+
if (!fs.existsSync(artifactPath)) {
|
|
400
|
+
throw new ValidationError(
|
|
401
|
+
`Workflow artifact not found: ${artifactPath}. Run "sdtk-code start --lane <feature|bugfix> --feature-key ${featureKey}" first.`
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const text = fs.readFileSync(artifactPath, "utf-8");
|
|
406
|
+
const metadataBlock = extractManagedBlock(text, "METADATA");
|
|
407
|
+
if (!metadataBlock) {
|
|
408
|
+
throw new ValidationError(
|
|
409
|
+
`Workflow artifact is missing the METADATA block: ${artifactPath}. Re-run "sdtk-code start --force" to reinitialize it.`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const state = {
|
|
414
|
+
artifactPath,
|
|
415
|
+
text,
|
|
416
|
+
featureKey: parseMetadataField(metadataBlock, "Feature key"),
|
|
417
|
+
lane: parseMetadataField(metadataBlock, "Lane"),
|
|
418
|
+
currentPhase: parseMetadataField(metadataBlock, "Current phase"),
|
|
419
|
+
phaseStatus: parseMetadataField(metadataBlock, "Phase status"),
|
|
420
|
+
intakeOutcome: parseMetadataField(metadataBlock, "Intake outcome"),
|
|
421
|
+
lastUpdated: parseMetadataField(metadataBlock, "Last updated"),
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
for (const [key, value] of Object.entries(state)) {
|
|
425
|
+
if (key === "artifactPath" || key === "text" || key === "lastUpdated") {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (!value) {
|
|
429
|
+
throw new ValidationError(
|
|
430
|
+
`Workflow artifact is missing required metadata field "${key}": ${artifactPath}. Re-run "sdtk-code start --force" to repair it.`
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return state;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function createOrUpdateWorkflowArtifact(options) {
|
|
439
|
+
const templatePath = resolveWorkflowTemplatePath();
|
|
440
|
+
const templateText = fs.readFileSync(templatePath, "utf-8");
|
|
441
|
+
const artifactPath = getWorkflowArtifactPath(options.projectPath, options.featureKey);
|
|
442
|
+
const artifactDir = path.dirname(artifactPath);
|
|
443
|
+
fs.mkdirSync(artifactDir, { recursive: true });
|
|
444
|
+
|
|
445
|
+
const data = {
|
|
446
|
+
...options,
|
|
447
|
+
currentPhase: options.currentPhase || "start",
|
|
448
|
+
inScope: options.inScope || [],
|
|
449
|
+
outScope: options.outScope || [],
|
|
450
|
+
assumptions: options.assumptions || [],
|
|
451
|
+
risks: options.risks || [],
|
|
452
|
+
slices: options.slices || [],
|
|
453
|
+
planNotes: options.planNotes || [],
|
|
454
|
+
candidateSlices: options.candidateSlices || [],
|
|
455
|
+
candidatePlanningNotes: options.candidatePlanningNotes || [],
|
|
456
|
+
activeSlices: options.activeSlices || [],
|
|
457
|
+
buildNotes: options.buildNotes || [],
|
|
458
|
+
debugNotes: options.debugNotes || [],
|
|
459
|
+
parallelReason: options.parallelReason || null,
|
|
460
|
+
evidenceEntries: options.evidenceEntries || [],
|
|
461
|
+
evidenceGate: options.evidenceGate || "pending",
|
|
462
|
+
specGateStatus: options.specGateStatus || "pending",
|
|
463
|
+
qualityGateStatus: options.qualityGateStatus || "pending",
|
|
464
|
+
specNotes: options.specNotes || [],
|
|
465
|
+
qualityNotes: options.qualityNotes || [],
|
|
466
|
+
verifyDebugNotes: options.verifyDebugNotes || [],
|
|
467
|
+
shipDecision: options.shipDecision || "pending",
|
|
468
|
+
shipStatus: options.shipStatus || "pending",
|
|
469
|
+
preflightEntries: options.preflightEntries || [],
|
|
470
|
+
shipFollowUps: options.shipFollowUps || [],
|
|
471
|
+
shipNotes: options.shipNotes || [],
|
|
472
|
+
shipDebugNotes: options.shipDebugNotes || [],
|
|
473
|
+
reviewPacketPath: options.reviewPacketPath || null,
|
|
474
|
+
intakeSource: options.intakeSource || "legacy_compatibility",
|
|
475
|
+
handoffStatus: options.handoffStatus || "missing",
|
|
476
|
+
compatibilityWarnings: options.compatibilityWarnings || [],
|
|
477
|
+
lastUpdated: new Date().toISOString(),
|
|
478
|
+
};
|
|
479
|
+
const managedBlocks = options.managedBlocks || DEFAULT_MANAGED_BLOCKS;
|
|
480
|
+
|
|
481
|
+
let nextText;
|
|
482
|
+
if (!fs.existsSync(artifactPath) || options.force) {
|
|
483
|
+
nextText = renderNewArtifact(templateText, data);
|
|
484
|
+
} else {
|
|
485
|
+
nextText = fs.readFileSync(artifactPath, "utf-8");
|
|
486
|
+
const blocks = renderManagedBlocks(data);
|
|
487
|
+
for (const blockName of managedBlocks) {
|
|
488
|
+
nextText = replaceManagedBlock(nextText, blockName, blocks[blockName]);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
fs.writeFileSync(artifactPath, nextText, "utf-8");
|
|
493
|
+
return artifactPath;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
module.exports = {
|
|
497
|
+
createOrUpdateWorkflowArtifact,
|
|
498
|
+
extractManagedBlock,
|
|
499
|
+
getWorkflowArtifactPath,
|
|
500
|
+
loadWorkflowArtifactState,
|
|
501
|
+
parseManagedField,
|
|
502
|
+
resolveWorkflowTemplatePath,
|
|
503
|
+
};
|