sdtk-code-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/assets/manifest/toolkit-bundle.manifest.json +147 -0
- package/assets/manifest/toolkit-bundle.sha256.txt +28 -0
- package/assets/toolkit/toolkit/AGENTS.md +210 -0
- package/assets/toolkit/toolkit/install.ps1 +126 -0
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -0
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +127 -0
- package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -0
- package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +53 -0
- package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -0
- package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -0
- package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +56 -0
- package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +297 -0
- package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +69 -0
- package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -0
- package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +75 -0
- package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +206 -0
- package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +65 -0
- package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +27 -0
- package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +114 -0
- package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +62 -0
- package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +86 -0
- package/assets/toolkit/toolkit/skills/code-review/SKILL.md +80 -0
- package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +126 -0
- package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +147 -0
- package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +53 -0
- package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +379 -0
- package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +300 -0
- package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +145 -0
- package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +229 -0
- package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +112 -0
- package/bin/sdtk-code.js +14 -0
- package/package.json +44 -0
- package/src/commands/build.js +53 -0
- package/src/commands/generate.js +11 -0
- package/src/commands/help.js +169 -0
- package/src/commands/init.js +86 -0
- package/src/commands/plan.js +52 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/ship.js +54 -0
- package/src/commands/start.js +89 -0
- package/src/commands/verify.js +57 -0
- package/src/index.js +70 -0
- package/src/lib/args.js +107 -0
- package/src/lib/errors.js +41 -0
- package/src/lib/powershell.js +65 -0
- package/src/lib/scope.js +55 -0
- package/src/lib/toolkit-payload.js +72 -0
- package/src/lib/workflow-artifact.js +453 -0
- package/src/lib/workflow-build.js +127 -0
- package/src/lib/workflow-handoff.js +427 -0
- package/src/lib/workflow-intake.js +100 -0
- package/src/lib/workflow-plan.js +96 -0
- package/src/lib/workflow-ship.js +163 -0
- package/src/lib/workflow-verify.js +212 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const HANDOFF_SCHEMA_VERSION = "0.1";
|
|
7
|
+
const HANDOFF_STATUSES = new Set(["READY_FOR_SDTK_CODE", "BLOCKED_FOR_SDTK_CODE"]);
|
|
8
|
+
const HANDOFF_LANES = new Set(["feature", "bugfix"]);
|
|
9
|
+
|
|
10
|
+
function normalizePathForDoc(projectPath, targetPath) {
|
|
11
|
+
return path.relative(projectPath, targetPath).split(path.sep).join("/");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function buildPathEntry(key, projectPath, relativePath) {
|
|
15
|
+
const normalized = relativePath.split("/").join(path.sep);
|
|
16
|
+
const fullPath = path.join(projectPath, normalized);
|
|
17
|
+
return {
|
|
18
|
+
key,
|
|
19
|
+
path: fullPath,
|
|
20
|
+
exists: fs.existsSync(fullPath),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function uniquePathEntries(entries) {
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
const result = [];
|
|
27
|
+
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const key = `${entry.key}::${entry.path}`;
|
|
30
|
+
if (seen.has(key)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
seen.add(key);
|
|
34
|
+
result.push(entry);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getSuggestedEngineSkills(lane, blocked) {
|
|
41
|
+
if (blocked) {
|
|
42
|
+
return ["code-discover"];
|
|
43
|
+
}
|
|
44
|
+
if (lane === "feature") {
|
|
45
|
+
return ["code-plan", "code-brainstorm (if ambiguity remains)"];
|
|
46
|
+
}
|
|
47
|
+
return ["code-debug (when reproducing failure)", "code-tdd", "code-execute"];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createIntakeResult({
|
|
51
|
+
projectPath,
|
|
52
|
+
featureKey,
|
|
53
|
+
lane,
|
|
54
|
+
requiredInputs,
|
|
55
|
+
optionalInputs,
|
|
56
|
+
missingInputs,
|
|
57
|
+
blocked,
|
|
58
|
+
intakeOutcome,
|
|
59
|
+
nextPhase,
|
|
60
|
+
phaseStatus,
|
|
61
|
+
blockingState,
|
|
62
|
+
intakeSource,
|
|
63
|
+
handoffStatus,
|
|
64
|
+
compatibilityWarnings = [],
|
|
65
|
+
blockingMessage,
|
|
66
|
+
blockingDetails = [],
|
|
67
|
+
}) {
|
|
68
|
+
return {
|
|
69
|
+
requiredInputs: uniquePathEntries(requiredInputs || []),
|
|
70
|
+
optionalInputs: uniquePathEntries(optionalInputs || []),
|
|
71
|
+
missingInputs: uniquePathEntries(missingInputs || []),
|
|
72
|
+
blocked,
|
|
73
|
+
intakeOutcome,
|
|
74
|
+
nextPhase,
|
|
75
|
+
phaseStatus,
|
|
76
|
+
blockingState,
|
|
77
|
+
suggestedEngineSkills: getSuggestedEngineSkills(lane, blocked),
|
|
78
|
+
normalizePath: (targetPath) => normalizePathForDoc(projectPath, targetPath),
|
|
79
|
+
intakeSource,
|
|
80
|
+
handoffStatus,
|
|
81
|
+
compatibilityWarnings,
|
|
82
|
+
blockingMessage,
|
|
83
|
+
blockingDetails,
|
|
84
|
+
featureKey,
|
|
85
|
+
lane,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function createBlockedFormalIntake({
|
|
90
|
+
projectPath,
|
|
91
|
+
featureKey,
|
|
92
|
+
lane,
|
|
93
|
+
handoffStatus,
|
|
94
|
+
requiredInputs,
|
|
95
|
+
optionalInputs,
|
|
96
|
+
blockingState,
|
|
97
|
+
blockingMessage,
|
|
98
|
+
blockingDetails = [],
|
|
99
|
+
compatibilityWarnings = [],
|
|
100
|
+
}) {
|
|
101
|
+
const missingInputs = (requiredInputs || []).filter((entry) => !entry.exists);
|
|
102
|
+
|
|
103
|
+
return createIntakeResult({
|
|
104
|
+
projectPath,
|
|
105
|
+
featureKey,
|
|
106
|
+
lane,
|
|
107
|
+
requiredInputs,
|
|
108
|
+
optionalInputs,
|
|
109
|
+
missingInputs,
|
|
110
|
+
blocked: true,
|
|
111
|
+
intakeOutcome: "BLOCKED_UPSTREAM_HANDOFF",
|
|
112
|
+
nextPhase: "blocked",
|
|
113
|
+
phaseStatus: "blocked",
|
|
114
|
+
blockingState,
|
|
115
|
+
intakeSource: "formal_handoff",
|
|
116
|
+
handoffStatus,
|
|
117
|
+
compatibilityWarnings,
|
|
118
|
+
blockingMessage,
|
|
119
|
+
blockingDetails,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isNonEmptyString(value) {
|
|
124
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function normalizeRelativePath(value, label) {
|
|
128
|
+
if (!isNonEmptyString(value)) {
|
|
129
|
+
throw new Error(`${label} must be a non-empty repo-relative forward-slash path.`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const trimmed = value.trim();
|
|
133
|
+
if (trimmed.includes("\\")) {
|
|
134
|
+
throw new Error(`${label} must use repo-relative forward-slash paths: ${trimmed}`);
|
|
135
|
+
}
|
|
136
|
+
if (trimmed.startsWith("/")) {
|
|
137
|
+
throw new Error(`${label} must be repo-relative, not absolute: ${trimmed}`);
|
|
138
|
+
}
|
|
139
|
+
if (/^[A-Za-z]:/.test(trimmed)) {
|
|
140
|
+
throw new Error(`${label} must be repo-relative, not drive-qualified: ${trimmed}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return trimmed;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function requireArray(payload, key) {
|
|
147
|
+
if (!Array.isArray(payload[key])) {
|
|
148
|
+
throw new Error(`${key} must be an array.`);
|
|
149
|
+
}
|
|
150
|
+
return payload[key];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function collectSoftWarnings(payload) {
|
|
154
|
+
const warnings = [];
|
|
155
|
+
|
|
156
|
+
if (payload.generated_by !== "sdtk-dev") {
|
|
157
|
+
warnings.push(
|
|
158
|
+
`Formal handoff compatibility warning: generated_by is ${JSON.stringify(
|
|
159
|
+
payload.generated_by
|
|
160
|
+
)}; expected "sdtk-dev".`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!isNonEmptyString(payload.generated_at)) {
|
|
165
|
+
warnings.push("Formal handoff compatibility warning: generated_at is missing or empty.");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return warnings;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function validateRequiredRefCoverage(requiredRefs, implementationSlices, featureKey) {
|
|
172
|
+
const archPath = `docs/architecture/ARCH_DESIGN_${featureKey}.md`;
|
|
173
|
+
const backlogPath = `docs/product/BACKLOG_${featureKey}.md`;
|
|
174
|
+
|
|
175
|
+
for (const mustHave of [archPath, backlogPath]) {
|
|
176
|
+
if (!requiredRefs.includes(mustHave)) {
|
|
177
|
+
throw new Error(`required_refs must include: ${mustHave}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const sliceText = implementationSlices.map((entry) => String(entry).toLowerCase()).join(" || ");
|
|
182
|
+
if (!sliceText) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (/\b(api|endpoint|contract|service|backend)\b/.test(sliceText)) {
|
|
187
|
+
if (!requiredRefs.some((entry) => entry.startsWith("docs/api/"))) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
"implementation_slices reference API or backend scope, so required_refs must include at least one docs/api/* source."
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (/\b(database|migration|schema|table|sql|db)\b/.test(sliceText)) {
|
|
195
|
+
if (!requiredRefs.some((entry) => entry.startsWith("docs/database/"))) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
"implementation_slices reference database scope, so required_refs must include at least one docs/database/* source."
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (/\b(ui|screen|frontend|page|form|layout)\b/.test(sliceText)) {
|
|
203
|
+
if (!requiredRefs.some((entry) => entry.startsWith("docs/design/"))) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
"implementation_slices reference UI scope, so required_refs must include at least one docs/design/* source."
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (/\b(flow|interaction)\b/.test(sliceText)) {
|
|
211
|
+
if (!requiredRefs.some((entry) => entry.startsWith("docs/specs/") && entry.endsWith("_FLOW_ACTION_SPEC.md"))) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"implementation_slices reference flow scope, so required_refs must include docs/specs/[FEATURE_KEY]_FLOW_ACTION_SPEC.md."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function buildInputEntries(projectPath, payload, featureKey, handoffPath) {
|
|
220
|
+
const requiredInputs = [
|
|
221
|
+
{
|
|
222
|
+
key: "CODE_HANDOFF",
|
|
223
|
+
path: handoffPath,
|
|
224
|
+
exists: true,
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
const optionalInputs = [];
|
|
228
|
+
|
|
229
|
+
if (isNonEmptyString(payload.feature_impl_plan_path)) {
|
|
230
|
+
requiredInputs.push(buildPathEntry("FEATURE_IMPL_PLAN", projectPath, payload.feature_impl_plan_path.trim()));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (isNonEmptyString(payload.repo_config_ref)) {
|
|
234
|
+
requiredInputs.push(buildPathEntry("SDTK_CONFIG", projectPath, payload.repo_config_ref.trim()));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (Array.isArray(payload.required_refs)) {
|
|
238
|
+
payload.required_refs.forEach((entry, index) => {
|
|
239
|
+
if (isNonEmptyString(entry)) {
|
|
240
|
+
requiredInputs.push(buildPathEntry(`REQUIRED_REF_${index + 1}`, projectPath, entry.trim()));
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (Array.isArray(payload.optional_refs)) {
|
|
246
|
+
payload.optional_refs.forEach((entry, index) => {
|
|
247
|
+
if (isNonEmptyString(entry)) {
|
|
248
|
+
optionalInputs.push(buildPathEntry(`OPTIONAL_REF_${index + 1}`, projectPath, entry.trim()));
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
requiredInputs: uniquePathEntries(requiredInputs),
|
|
255
|
+
optionalInputs: uniquePathEntries(optionalInputs),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function resolveFormalHandoffIntake(projectPath, featureKey, lane) {
|
|
260
|
+
const handoffPath = path.join(projectPath, "docs", "dev", `CODE_HANDOFF_${featureKey}.json`);
|
|
261
|
+
if (!fs.existsSync(handoffPath)) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let payload;
|
|
266
|
+
try {
|
|
267
|
+
payload = JSON.parse(fs.readFileSync(handoffPath, "utf-8"));
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return createBlockedFormalIntake({
|
|
270
|
+
projectPath,
|
|
271
|
+
featureKey,
|
|
272
|
+
lane,
|
|
273
|
+
handoffStatus: "INVALID_JSON",
|
|
274
|
+
requiredInputs: [
|
|
275
|
+
{
|
|
276
|
+
key: "CODE_HANDOFF",
|
|
277
|
+
path: handoffPath,
|
|
278
|
+
exists: true,
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
optionalInputs: [],
|
|
282
|
+
blockingState: "invalid_handoff_contract",
|
|
283
|
+
blockingMessage: `SDTK-CODE handoff contract is invalid: failed to parse JSON (${error.message}).`,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const compatibilityWarnings = collectSoftWarnings(payload);
|
|
288
|
+
const { requiredInputs, optionalInputs } = buildInputEntries(projectPath, payload, featureKey, handoffPath);
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
292
|
+
throw new Error("Formal handoff root value must be a JSON object.");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (payload.schema_version !== HANDOFF_SCHEMA_VERSION) {
|
|
296
|
+
throw new Error(`schema_version must be "${HANDOFF_SCHEMA_VERSION}".`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!isNonEmptyString(payload.feature_key)) {
|
|
300
|
+
throw new Error("feature_key must be a non-empty string.");
|
|
301
|
+
}
|
|
302
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(payload.feature_key.trim())) {
|
|
303
|
+
throw new Error("feature_key must use UPPER_SNAKE_CASE.");
|
|
304
|
+
}
|
|
305
|
+
if (payload.feature_key.trim() !== featureKey) {
|
|
306
|
+
throw new Error(`feature_key must match CLI --feature-key: ${featureKey}`);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (!HANDOFF_STATUSES.has(payload.handoff_status)) {
|
|
310
|
+
throw new Error('handoff_status must be "READY_FOR_SDTK_CODE" or "BLOCKED_FOR_SDTK_CODE".');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (!HANDOFF_LANES.has(payload.recommended_lane)) {
|
|
314
|
+
throw new Error('recommended_lane must be "feature" or "bugfix".');
|
|
315
|
+
}
|
|
316
|
+
if (payload.recommended_lane !== lane) {
|
|
317
|
+
throw new Error(`recommended_lane must match CLI --lane: ${lane}`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const featureImplPlanPath = normalizeRelativePath(
|
|
321
|
+
payload.feature_impl_plan_path,
|
|
322
|
+
"feature_impl_plan_path"
|
|
323
|
+
);
|
|
324
|
+
const expectedPlanPath = `docs/dev/FEATURE_IMPL_PLAN_${featureKey}.md`;
|
|
325
|
+
if (featureImplPlanPath !== expectedPlanPath) {
|
|
326
|
+
throw new Error(`feature_impl_plan_path must match the current feature key: ${expectedPlanPath}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const repoConfigRef = normalizeRelativePath(payload.repo_config_ref, "repo_config_ref");
|
|
330
|
+
if (repoConfigRef !== "sdtk-spec.config.json") {
|
|
331
|
+
throw new Error('repo_config_ref must be exactly "sdtk-spec.config.json".');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const requiredRefs = requireArray(payload, "required_refs").map((entry, index) =>
|
|
335
|
+
normalizeRelativePath(entry, `required_refs[${index}]`)
|
|
336
|
+
);
|
|
337
|
+
const optionalRefs = requireArray(payload, "optional_refs").map((entry, index) =>
|
|
338
|
+
normalizeRelativePath(entry, `optional_refs[${index}]`)
|
|
339
|
+
);
|
|
340
|
+
const openBlockers = requireArray(payload, "open_blockers").map((entry) => String(entry).trim()).filter(Boolean);
|
|
341
|
+
const implementationSlices = requireArray(payload, "implementation_slices")
|
|
342
|
+
.map((entry) => String(entry).trim())
|
|
343
|
+
.filter(Boolean);
|
|
344
|
+
const testObligations = requireArray(payload, "test_obligations")
|
|
345
|
+
.map((entry) => String(entry).trim())
|
|
346
|
+
.filter(Boolean);
|
|
347
|
+
|
|
348
|
+
validateRequiredRefCoverage(requiredRefs, implementationSlices, featureKey);
|
|
349
|
+
|
|
350
|
+
const missingInputs = requiredInputs.filter((entry) => !entry.exists);
|
|
351
|
+
const missingOptional = optionalInputs.filter((entry) => !entry.exists);
|
|
352
|
+
if (missingInputs.length > 0) {
|
|
353
|
+
const missingList = missingInputs
|
|
354
|
+
.map((entry) => normalizePathForDoc(projectPath, entry.path))
|
|
355
|
+
.join(", ");
|
|
356
|
+
throw new Error(`formal handoff references missing required paths: ${missingList}`);
|
|
357
|
+
}
|
|
358
|
+
if (missingOptional.length > 0) {
|
|
359
|
+
const missingList = missingOptional
|
|
360
|
+
.map((entry) => normalizePathForDoc(projectPath, entry.path))
|
|
361
|
+
.join(", ");
|
|
362
|
+
throw new Error(`formal handoff references missing optional paths: ${missingList}`);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (payload.handoff_status === "READY_FOR_SDTK_CODE") {
|
|
366
|
+
if (openBlockers.length > 0) {
|
|
367
|
+
throw new Error("READY_FOR_SDTK_CODE requires empty open_blockers.");
|
|
368
|
+
}
|
|
369
|
+
if (implementationSlices.length === 0) {
|
|
370
|
+
throw new Error("READY_FOR_SDTK_CODE requires at least one implementation_slices entry.");
|
|
371
|
+
}
|
|
372
|
+
if (testObligations.length === 0) {
|
|
373
|
+
throw new Error("READY_FOR_SDTK_CODE requires at least one test_obligations entry.");
|
|
374
|
+
}
|
|
375
|
+
} else if (openBlockers.length === 0) {
|
|
376
|
+
throw new Error("BLOCKED_FOR_SDTK_CODE requires at least one open_blockers entry.");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (payload.handoff_status === "BLOCKED_FOR_SDTK_CODE") {
|
|
380
|
+
return createBlockedFormalIntake({
|
|
381
|
+
projectPath,
|
|
382
|
+
featureKey,
|
|
383
|
+
lane,
|
|
384
|
+
handoffStatus: payload.handoff_status,
|
|
385
|
+
requiredInputs,
|
|
386
|
+
optionalInputs,
|
|
387
|
+
blockingState: "blocked_upstream_handoff",
|
|
388
|
+
blockingMessage: "SDTK-CODE handoff is blocked by upstream /dev blockers:",
|
|
389
|
+
blockingDetails: openBlockers,
|
|
390
|
+
compatibilityWarnings,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return createIntakeResult({
|
|
395
|
+
projectPath,
|
|
396
|
+
featureKey,
|
|
397
|
+
lane,
|
|
398
|
+
requiredInputs,
|
|
399
|
+
optionalInputs,
|
|
400
|
+
missingInputs: [],
|
|
401
|
+
blocked: false,
|
|
402
|
+
intakeOutcome: lane === "feature" ? "READY_FOR_PLAN" : "READY_FOR_BUILD_BUGFIX",
|
|
403
|
+
nextPhase: lane === "feature" ? "plan" : "build",
|
|
404
|
+
phaseStatus: "completed",
|
|
405
|
+
blockingState: "clear",
|
|
406
|
+
intakeSource: "formal_handoff",
|
|
407
|
+
handoffStatus: payload.handoff_status,
|
|
408
|
+
compatibilityWarnings,
|
|
409
|
+
});
|
|
410
|
+
} catch (error) {
|
|
411
|
+
return createBlockedFormalIntake({
|
|
412
|
+
projectPath,
|
|
413
|
+
featureKey,
|
|
414
|
+
lane,
|
|
415
|
+
handoffStatus: payload && payload.handoff_status ? String(payload.handoff_status) : "INVALID_CONTRACT",
|
|
416
|
+
requiredInputs,
|
|
417
|
+
optionalInputs,
|
|
418
|
+
blockingState: "invalid_handoff_contract",
|
|
419
|
+
blockingMessage: `SDTK-CODE handoff contract is invalid: ${error.message}`,
|
|
420
|
+
compatibilityWarnings,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
module.exports = {
|
|
426
|
+
resolveFormalHandoffIntake,
|
|
427
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { resolveFormalHandoffIntake } = require("./workflow-handoff");
|
|
6
|
+
|
|
7
|
+
function normalizePathForDoc(projectPath, targetPath) {
|
|
8
|
+
return path.relative(projectPath, targetPath).split(path.sep).join("/");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function buildRequiredInputs(projectPath, featureKey) {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
key: "FEATURE_IMPL_PLAN",
|
|
15
|
+
path: path.join(projectPath, "docs", "dev", `FEATURE_IMPL_PLAN_${featureKey}.md`),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: "SDTK_CONFIG",
|
|
19
|
+
path: path.join(projectPath, "sdtk-spec.config.json"),
|
|
20
|
+
},
|
|
21
|
+
].map((entry) => ({
|
|
22
|
+
...entry,
|
|
23
|
+
exists: fs.existsSync(entry.path),
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function buildOptionalInputs(projectPath, featureKey) {
|
|
28
|
+
const candidates = [
|
|
29
|
+
{ key: "ARCH_DESIGN", path: path.join(projectPath, "docs", "architecture", `ARCH_DESIGN_${featureKey}.md`) },
|
|
30
|
+
{ key: "API_DESIGN_DETAIL", path: path.join(projectPath, "docs", "api", `${featureKey}_API_DESIGN_DETAIL.md`) },
|
|
31
|
+
{ key: "DATABASE_SPEC", path: path.join(projectPath, "docs", "database", `DATABASE_SPEC_${featureKey}.md`) },
|
|
32
|
+
{ key: "FLOW_ACTION_SPEC", path: path.join(projectPath, "docs", "design", `FLOW_ACTION_SPEC_${featureKey}.md`) },
|
|
33
|
+
{ key: "DESIGN_LAYOUT", path: path.join(projectPath, "docs", "design", `DESIGN_LAYOUT_${featureKey}.md`) },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
return candidates
|
|
37
|
+
.filter((entry) => fs.existsSync(entry.path))
|
|
38
|
+
.map((entry) => ({
|
|
39
|
+
...entry,
|
|
40
|
+
exists: true,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getSuggestedEngineSkills(lane, blocked) {
|
|
45
|
+
if (blocked) {
|
|
46
|
+
return ["code-discover"];
|
|
47
|
+
}
|
|
48
|
+
if (lane === "feature") {
|
|
49
|
+
return ["code-plan", "code-brainstorm (if ambiguity remains)"];
|
|
50
|
+
}
|
|
51
|
+
return ["code-debug (when reproducing failure)", "code-tdd", "code-execute"];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildLegacyCompatibilityWarnings(featureKey, lane) {
|
|
55
|
+
const warnings = [
|
|
56
|
+
"Formal SDTK-SPEC handoff missing. Using legacy compatibility intake from FEATURE_IMPL_PLAN + sdtk-spec.config.json.",
|
|
57
|
+
];
|
|
58
|
+
if (lane === "feature") {
|
|
59
|
+
warnings.push(
|
|
60
|
+
`Preferred feature-lane intake is docs/dev/CODE_HANDOFF_${featureKey}.json from upstream SDTK-SPEC /dev.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return warnings;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function runIntake(projectPath, featureKey, lane) {
|
|
67
|
+
const formalHandoff = resolveFormalHandoffIntake(projectPath, featureKey, lane);
|
|
68
|
+
if (formalHandoff) {
|
|
69
|
+
return formalHandoff;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const requiredInputs = buildRequiredInputs(projectPath, featureKey);
|
|
73
|
+
const optionalInputs = buildOptionalInputs(projectPath, featureKey);
|
|
74
|
+
const missingInputs = requiredInputs.filter((entry) => !entry.exists);
|
|
75
|
+
const blocked = missingInputs.length > 0;
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
requiredInputs,
|
|
79
|
+
optionalInputs,
|
|
80
|
+
missingInputs,
|
|
81
|
+
blocked,
|
|
82
|
+
intakeOutcome: blocked
|
|
83
|
+
? "BLOCKED_MISSING_INPUTS"
|
|
84
|
+
: lane === "feature"
|
|
85
|
+
? "READY_FOR_PLAN"
|
|
86
|
+
: "READY_FOR_BUILD_BUGFIX",
|
|
87
|
+
nextPhase: blocked ? "blocked" : lane === "feature" ? "plan" : "build",
|
|
88
|
+
phaseStatus: blocked ? "blocked" : "completed",
|
|
89
|
+
blockingState: blocked ? "blocked_missing_inputs" : "clear",
|
|
90
|
+
suggestedEngineSkills: getSuggestedEngineSkills(lane, blocked),
|
|
91
|
+
normalizePath: (targetPath) => normalizePathForDoc(projectPath, targetPath),
|
|
92
|
+
intakeSource: "legacy_compatibility",
|
|
93
|
+
handoffStatus: "missing",
|
|
94
|
+
compatibilityWarnings: blocked ? [] : buildLegacyCompatibilityWarnings(featureKey, lane),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
runIntake,
|
|
100
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ValidationError } = require("./errors");
|
|
4
|
+
const { createOrUpdateWorkflowArtifact, loadWorkflowArtifactState } = require("./workflow-artifact");
|
|
5
|
+
|
|
6
|
+
function normalizeEntries(entries) {
|
|
7
|
+
return (entries || []).map((entry) => entry.trim()).filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getBuildEngineSkills(lane) {
|
|
11
|
+
if (lane === "bugfix") {
|
|
12
|
+
return ["code-debug (if failure reproduction is needed)", "code-tdd", "code-execute"];
|
|
13
|
+
}
|
|
14
|
+
return ["code-worktree", "code-tdd", "code-execute", "code-parallel (if tasks are independent)"];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function validatePlanState(state) {
|
|
18
|
+
if (state.phaseStatus === "blocked" || state.intakeOutcome === "BLOCKED_MISSING_INPUTS") {
|
|
19
|
+
throw new ValidationError(
|
|
20
|
+
"Workflow artifact is blocked by missing upstream inputs. Re-run \"sdtk-code start\" after the handoff inputs are ready."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (state.currentPhase !== "start" && state.currentPhase !== "plan") {
|
|
25
|
+
throw new ValidationError(
|
|
26
|
+
`Cannot run "plan" from current phase "${state.currentPhase}". Re-run the next legal workflow step instead.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (state.lane === "feature" && state.intakeOutcome !== "READY_FOR_PLAN") {
|
|
31
|
+
throw new ValidationError(
|
|
32
|
+
`Feature-lane workflow is not ready for "plan". Current intake outcome: ${state.intakeOutcome}.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (state.lane === "bugfix" && state.intakeOutcome !== "READY_FOR_BUILD_BUGFIX") {
|
|
37
|
+
throw new ValidationError(
|
|
38
|
+
`Bugfix-lane workflow is not eligible for optional planning. Current intake outcome: ${state.intakeOutcome}.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function buildPlanPayload(flags, lane) {
|
|
44
|
+
const payload = {
|
|
45
|
+
inScope: normalizeEntries(flags["in-scope"]),
|
|
46
|
+
outScope: normalizeEntries(flags["out-scope"]),
|
|
47
|
+
assumptions: normalizeEntries(flags.assumption),
|
|
48
|
+
risks: normalizeEntries(flags.risk),
|
|
49
|
+
slices: normalizeEntries(flags.slice),
|
|
50
|
+
planNotes: normalizeEntries(flags.note),
|
|
51
|
+
planningMode: lane === "bugfix" ? "bugfix-light" : "feature-standard",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (lane === "feature" && payload.slices.length === 0) {
|
|
55
|
+
throw new ValidationError('Feature-lane planning requires at least one "--slice" entry.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (lane === "bugfix" && payload.slices.length === 0) {
|
|
59
|
+
payload.slices = ["Targeted bugfix path remains lightweight; proceed to focused build and regression checks."];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return payload;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function runPlan(projectPath, featureKey, flags) {
|
|
66
|
+
const state = loadWorkflowArtifactState(projectPath, featureKey);
|
|
67
|
+
validatePlanState(state);
|
|
68
|
+
|
|
69
|
+
const planPayload = buildPlanPayload(flags, state.lane);
|
|
70
|
+
const artifactPath = createOrUpdateWorkflowArtifact({
|
|
71
|
+
projectPath,
|
|
72
|
+
featureKey,
|
|
73
|
+
lane: state.lane,
|
|
74
|
+
currentPhase: "plan",
|
|
75
|
+
phaseStatus: "completed",
|
|
76
|
+
intakeOutcome: state.intakeOutcome,
|
|
77
|
+
nextPhase: "build",
|
|
78
|
+
blockingState: "clear",
|
|
79
|
+
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
80
|
+
managedBlocks: ["METADATA", "PLAN", "STATUS"],
|
|
81
|
+
...planPayload,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
artifactPath,
|
|
86
|
+
lane: state.lane,
|
|
87
|
+
nextPhase: "build",
|
|
88
|
+
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
89
|
+
planningMode: planPayload.planningMode,
|
|
90
|
+
sliceCount: planPayload.slices.length,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = {
|
|
95
|
+
runPlan,
|
|
96
|
+
};
|