sdtk-code-kit 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -185
- package/assets/manifest/toolkit-bundle.manifest.json +49 -49
- package/assets/manifest/toolkit-bundle.sha256.txt +24 -24
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -78
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +150 -150
- package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -62
- package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +82 -82
- package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -12
- package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +55 -55
- package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +68 -68
- package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +74 -74
- package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +205 -205
- package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +64 -64
- package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +26 -26
- package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +113 -113
- package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +61 -61
- package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +85 -85
- package/assets/toolkit/toolkit/skills/code-review/SKILL.md +79 -79
- package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +125 -125
- package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +146 -146
- package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +52 -52
- package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +299 -299
- package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +144 -144
- package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +13 -13
- package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +140 -112
- package/bin/sdtk-code.js +14 -14
- package/package.json +4 -4
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +52 -0
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +123 -0
- package/src/commands/help.js +28 -4
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -0
- package/src/commands/resume.js +62 -0
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +78 -0
- package/src/commands/verify.js +71 -66
- package/src/index.js +32 -1
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/powershell.js +65 -65
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -0
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +166 -0
- package/src/lib/trust-file-scope.js +154 -0
- package/src/lib/trust-policy.js +212 -0
- package/src/lib/trust-redact.js +35 -0
- package/src/lib/trust-trace.js +179 -0
- package/src/lib/workflow-artifact.js +503 -496
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +84 -0
- package/src/lib/workflow-handoff.js +1029 -937
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +89 -0
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +439 -0
- package/src/lib/workflow-verify.js +43 -6
|
@@ -1,101 +1,101 @@
|
|
|
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 bounded compatibility intake from FEATURE_IMPL_PLAN + sdtk-spec.config.json.",
|
|
57
|
-
"Upstream SDTK-SPEC /dev still owns implementation-readiness planning and formal CODE_HANDOFF scope.",
|
|
58
|
-
];
|
|
59
|
-
if (lane === "feature") {
|
|
60
|
-
warnings.push(
|
|
61
|
-
`Preferred feature-lane intake is docs/dev/CODE_HANDOFF_${featureKey}.json from upstream SDTK-SPEC /dev.`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return warnings;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function runIntake(projectPath, featureKey, lane) {
|
|
68
|
-
const formalHandoff = resolveFormalHandoffIntake(projectPath, featureKey, lane);
|
|
69
|
-
if (formalHandoff) {
|
|
70
|
-
return formalHandoff;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const requiredInputs = buildRequiredInputs(projectPath, featureKey);
|
|
74
|
-
const optionalInputs = buildOptionalInputs(projectPath, featureKey);
|
|
75
|
-
const missingInputs = requiredInputs.filter((entry) => !entry.exists);
|
|
76
|
-
const blocked = missingInputs.length > 0;
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
requiredInputs,
|
|
80
|
-
optionalInputs,
|
|
81
|
-
missingInputs,
|
|
82
|
-
blocked,
|
|
83
|
-
intakeOutcome: blocked
|
|
84
|
-
? "BLOCKED_MISSING_INPUTS"
|
|
85
|
-
: lane === "feature"
|
|
86
|
-
? "READY_FOR_PLAN"
|
|
87
|
-
: "READY_FOR_BUILD_BUGFIX",
|
|
88
|
-
nextPhase: blocked ? "blocked" : lane === "feature" ? "plan" : "build",
|
|
89
|
-
phaseStatus: blocked ? "blocked" : "completed",
|
|
90
|
-
blockingState: blocked ? "blocked_missing_inputs" : "clear",
|
|
91
|
-
suggestedEngineSkills: getSuggestedEngineSkills(lane, blocked),
|
|
92
|
-
normalizePath: (targetPath) => normalizePathForDoc(projectPath, targetPath),
|
|
93
|
-
intakeSource: "legacy_compatibility",
|
|
94
|
-
handoffStatus: "missing",
|
|
95
|
-
compatibilityWarnings: blocked ? [] : buildLegacyCompatibilityWarnings(featureKey, lane),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = {
|
|
100
|
-
runIntake,
|
|
101
|
-
};
|
|
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 bounded compatibility intake from FEATURE_IMPL_PLAN + sdtk-spec.config.json.",
|
|
57
|
+
"Upstream SDTK-SPEC /dev still owns implementation-readiness planning and formal CODE_HANDOFF scope.",
|
|
58
|
+
];
|
|
59
|
+
if (lane === "feature") {
|
|
60
|
+
warnings.push(
|
|
61
|
+
`Preferred feature-lane intake is docs/dev/CODE_HANDOFF_${featureKey}.json from upstream SDTK-SPEC /dev.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return warnings;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function runIntake(projectPath, featureKey, lane) {
|
|
68
|
+
const formalHandoff = resolveFormalHandoffIntake(projectPath, featureKey, lane);
|
|
69
|
+
if (formalHandoff) {
|
|
70
|
+
return formalHandoff;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const requiredInputs = buildRequiredInputs(projectPath, featureKey);
|
|
74
|
+
const optionalInputs = buildOptionalInputs(projectPath, featureKey);
|
|
75
|
+
const missingInputs = requiredInputs.filter((entry) => !entry.exists);
|
|
76
|
+
const blocked = missingInputs.length > 0;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
requiredInputs,
|
|
80
|
+
optionalInputs,
|
|
81
|
+
missingInputs,
|
|
82
|
+
blocked,
|
|
83
|
+
intakeOutcome: blocked
|
|
84
|
+
? "BLOCKED_MISSING_INPUTS"
|
|
85
|
+
: lane === "feature"
|
|
86
|
+
? "READY_FOR_PLAN"
|
|
87
|
+
: "READY_FOR_BUILD_BUGFIX",
|
|
88
|
+
nextPhase: blocked ? "blocked" : lane === "feature" ? "plan" : "build",
|
|
89
|
+
phaseStatus: blocked ? "blocked" : "completed",
|
|
90
|
+
blockingState: blocked ? "blocked_missing_inputs" : "clear",
|
|
91
|
+
suggestedEngineSkills: getSuggestedEngineSkills(lane, blocked),
|
|
92
|
+
normalizePath: (targetPath) => normalizePathForDoc(projectPath, targetPath),
|
|
93
|
+
intakeSource: "legacy_compatibility",
|
|
94
|
+
handoffStatus: "missing",
|
|
95
|
+
compatibilityWarnings: blocked ? [] : buildLegacyCompatibilityWarnings(featureKey, lane),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = {
|
|
100
|
+
runIntake,
|
|
101
|
+
};
|
package/src/lib/workflow-plan.js
CHANGED
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { ValidationError } = require("./errors");
|
|
4
|
-
const {
|
|
5
|
-
createOrUpdateWorkflowArtifact,
|
|
6
|
-
extractManagedBlock,
|
|
7
|
-
loadWorkflowArtifactState,
|
|
8
|
-
} = require("./workflow-artifact");
|
|
9
|
-
|
|
10
|
-
function normalizeEntries(entries) {
|
|
11
|
-
return (entries || []).map((entry) => entry.trim()).filter(Boolean);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function uniqueEntries(entries) {
|
|
15
|
-
const seen = new Set();
|
|
16
|
-
const results = [];
|
|
17
|
-
for (const entry of entries) {
|
|
18
|
-
if (!entry || seen.has(entry)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
seen.add(entry);
|
|
22
|
-
results.push(entry);
|
|
23
|
-
}
|
|
24
|
-
return results;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function escapeRegExp(value) {
|
|
28
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function parseBulletSection(planBlock, heading) {
|
|
32
|
-
if (!planBlock) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const regex = new RegExp(`### ${escapeRegExp(heading)}\\r?\\n([\\s\\S]*?)(?=\\r?\\n### |$)`);
|
|
37
|
-
const match = planBlock.match(regex);
|
|
38
|
-
if (!match) {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return match[1]
|
|
43
|
-
.split(/\r?\n/)
|
|
44
|
-
.map((line) => line.trim())
|
|
45
|
-
.filter((line) => line.startsWith("- "))
|
|
46
|
-
.map((line) => line.slice(2).trim())
|
|
47
|
-
.filter(Boolean);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getSeededPlanContext(state) {
|
|
51
|
-
const planBlock = extractManagedBlock(state.text, "PLAN");
|
|
52
|
-
const candidateSlices = parseBulletSection(planBlock, "Seeded Candidate Slices From Formal Handoff")
|
|
53
|
-
.filter((entry) => entry !== "No candidate slices seeded from the formal handoff.");
|
|
54
|
-
const candidatePlanningNotes = parseBulletSection(planBlock, "Planning Notes").filter(
|
|
55
|
-
(entry) => entry !== "No additional planning notes recorded."
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
candidateSlices,
|
|
60
|
-
candidatePlanningNotes,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getBuildEngineSkills(lane) {
|
|
65
|
-
if (lane === "bugfix") {
|
|
66
|
-
return ["code-debug (if failure reproduction is needed)", "code-tdd", "code-execute"];
|
|
67
|
-
}
|
|
68
|
-
return ["code-worktree", "code-tdd", "code-execute", "code-parallel (if tasks are independent)"];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function validatePlanState(state) {
|
|
72
|
-
if (state.phaseStatus === "blocked" || state.intakeOutcome === "BLOCKED_MISSING_INPUTS") {
|
|
73
|
-
throw new ValidationError(
|
|
74
|
-
"Workflow artifact is blocked by missing upstream inputs. Re-run \"sdtk-code start\" after the handoff inputs are ready."
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (state.currentPhase !== "start" && state.currentPhase !== "plan") {
|
|
79
|
-
throw new ValidationError(
|
|
80
|
-
`Cannot run "plan" from current phase "${state.currentPhase}". Re-run the next legal workflow step instead.`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (state.lane === "feature" && state.intakeOutcome !== "READY_FOR_PLAN") {
|
|
85
|
-
throw new ValidationError(
|
|
86
|
-
`Feature-lane workflow is not ready for "plan". Current intake outcome: ${state.intakeOutcome}.`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (state.lane === "bugfix" && state.intakeOutcome !== "READY_FOR_BUILD_BUGFIX") {
|
|
91
|
-
throw new ValidationError(
|
|
92
|
-
`Bugfix-lane workflow is not eligible for optional planning. Current intake outcome: ${state.intakeOutcome}.`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function buildPlanPayload(flags, state) {
|
|
98
|
-
const lane = state.lane;
|
|
99
|
-
const useSeededCandidates = Boolean(flags["use-seeded-candidates"]);
|
|
100
|
-
const payload = {
|
|
101
|
-
inScope: normalizeEntries(flags["in-scope"]),
|
|
102
|
-
outScope: normalizeEntries(flags["out-scope"]),
|
|
103
|
-
assumptions: normalizeEntries(flags.assumption),
|
|
104
|
-
risks: normalizeEntries(flags.risk),
|
|
105
|
-
slices: normalizeEntries(flags.slice),
|
|
106
|
-
planNotes: normalizeEntries(flags.note),
|
|
107
|
-
planningMode: lane === "bugfix" ? "bugfix-light" : "feature-standard",
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (lane !== "feature" && useSeededCandidates) {
|
|
111
|
-
throw new ValidationError('"--use-seeded-candidates" is only valid for feature-lane planning.');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (lane === "feature") {
|
|
115
|
-
const seededContext = getSeededPlanContext(state);
|
|
116
|
-
|
|
117
|
-
if (useSeededCandidates && state.currentPhase !== "start") {
|
|
118
|
-
throw new ValidationError(
|
|
119
|
-
'"--use-seeded-candidates" can only be used while confirming seeded handoff slices from the "start" phase.'
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (useSeededCandidates && payload.slices.length > 0) {
|
|
124
|
-
throw new ValidationError(
|
|
125
|
-
'Feature-lane planning must choose exactly one slice-confirmation path: explicit "--slice" entries or "--use-seeded-candidates".'
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (useSeededCandidates) {
|
|
130
|
-
if (seededContext.candidateSlices.length === 0) {
|
|
131
|
-
throw new ValidationError(
|
|
132
|
-
'No seeded candidate slices are available in the workflow artifact. Re-run "sdtk-code start" from a formal SDTK-SPEC handoff or use explicit "--slice" entries.'
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
payload.slices = seededContext.candidateSlices;
|
|
137
|
-
payload.planNotes = uniqueEntries([
|
|
138
|
-
"Confirmed seeded candidate slices from the formal SDTK-SPEC handoff via `--use-seeded-candidates`.",
|
|
139
|
-
...payload.planNotes,
|
|
140
|
-
...seededContext.candidatePlanningNotes,
|
|
141
|
-
]);
|
|
142
|
-
payload.planningMode = "feature-seeded-confirmed";
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (payload.slices.length === 0) {
|
|
146
|
-
if (seededContext.candidateSlices.length > 0) {
|
|
147
|
-
throw new ValidationError(
|
|
148
|
-
'Feature-lane planning requires explicit "--slice" entries or "--use-seeded-candidates" to confirm the seeded handoff slice set.'
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
throw new ValidationError('Feature-lane planning requires at least one "--slice" entry.');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (lane === "bugfix" && payload.slices.length === 0) {
|
|
156
|
-
payload.slices = ["Targeted bugfix path remains lightweight; proceed to focused build and regression checks."];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return payload;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function runPlan(projectPath, featureKey, flags) {
|
|
163
|
-
const state = loadWorkflowArtifactState(projectPath, featureKey);
|
|
164
|
-
validatePlanState(state);
|
|
165
|
-
|
|
166
|
-
const planPayload = buildPlanPayload(flags, state);
|
|
167
|
-
const artifactPath = createOrUpdateWorkflowArtifact({
|
|
168
|
-
projectPath,
|
|
169
|
-
featureKey,
|
|
170
|
-
lane: state.lane,
|
|
171
|
-
currentPhase: "plan",
|
|
172
|
-
phaseStatus: "completed",
|
|
173
|
-
intakeOutcome: state.intakeOutcome,
|
|
174
|
-
nextPhase: "build",
|
|
175
|
-
blockingState: "clear",
|
|
176
|
-
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
177
|
-
managedBlocks: ["METADATA", "PLAN", "STATUS"],
|
|
178
|
-
...planPayload,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
artifactPath,
|
|
183
|
-
lane: state.lane,
|
|
184
|
-
nextPhase: "build",
|
|
185
|
-
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
186
|
-
planningMode: planPayload.planningMode,
|
|
187
|
-
sliceCount: planPayload.slices.length,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
module.exports = {
|
|
192
|
-
runPlan,
|
|
193
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ValidationError } = require("./errors");
|
|
4
|
+
const {
|
|
5
|
+
createOrUpdateWorkflowArtifact,
|
|
6
|
+
extractManagedBlock,
|
|
7
|
+
loadWorkflowArtifactState,
|
|
8
|
+
} = require("./workflow-artifact");
|
|
9
|
+
|
|
10
|
+
function normalizeEntries(entries) {
|
|
11
|
+
return (entries || []).map((entry) => entry.trim()).filter(Boolean);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function uniqueEntries(entries) {
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (!entry || seen.has(entry)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
seen.add(entry);
|
|
22
|
+
results.push(entry);
|
|
23
|
+
}
|
|
24
|
+
return results;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function escapeRegExp(value) {
|
|
28
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseBulletSection(planBlock, heading) {
|
|
32
|
+
if (!planBlock) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const regex = new RegExp(`### ${escapeRegExp(heading)}\\r?\\n([\\s\\S]*?)(?=\\r?\\n### |$)`);
|
|
37
|
+
const match = planBlock.match(regex);
|
|
38
|
+
if (!match) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return match[1]
|
|
43
|
+
.split(/\r?\n/)
|
|
44
|
+
.map((line) => line.trim())
|
|
45
|
+
.filter((line) => line.startsWith("- "))
|
|
46
|
+
.map((line) => line.slice(2).trim())
|
|
47
|
+
.filter(Boolean);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getSeededPlanContext(state) {
|
|
51
|
+
const planBlock = extractManagedBlock(state.text, "PLAN");
|
|
52
|
+
const candidateSlices = parseBulletSection(planBlock, "Seeded Candidate Slices From Formal Handoff")
|
|
53
|
+
.filter((entry) => entry !== "No candidate slices seeded from the formal handoff.");
|
|
54
|
+
const candidatePlanningNotes = parseBulletSection(planBlock, "Planning Notes").filter(
|
|
55
|
+
(entry) => entry !== "No additional planning notes recorded."
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
candidateSlices,
|
|
60
|
+
candidatePlanningNotes,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getBuildEngineSkills(lane) {
|
|
65
|
+
if (lane === "bugfix") {
|
|
66
|
+
return ["code-debug (if failure reproduction is needed)", "code-tdd", "code-execute"];
|
|
67
|
+
}
|
|
68
|
+
return ["code-worktree", "code-tdd", "code-execute", "code-parallel (if tasks are independent)"];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function validatePlanState(state) {
|
|
72
|
+
if (state.phaseStatus === "blocked" || state.intakeOutcome === "BLOCKED_MISSING_INPUTS") {
|
|
73
|
+
throw new ValidationError(
|
|
74
|
+
"Workflow artifact is blocked by missing upstream inputs. Re-run \"sdtk-code start\" after the handoff inputs are ready."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (state.currentPhase !== "start" && state.currentPhase !== "plan") {
|
|
79
|
+
throw new ValidationError(
|
|
80
|
+
`Cannot run "plan" from current phase "${state.currentPhase}". Re-run the next legal workflow step instead.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (state.lane === "feature" && state.intakeOutcome !== "READY_FOR_PLAN") {
|
|
85
|
+
throw new ValidationError(
|
|
86
|
+
`Feature-lane workflow is not ready for "plan". Current intake outcome: ${state.intakeOutcome}.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (state.lane === "bugfix" && state.intakeOutcome !== "READY_FOR_BUILD_BUGFIX") {
|
|
91
|
+
throw new ValidationError(
|
|
92
|
+
`Bugfix-lane workflow is not eligible for optional planning. Current intake outcome: ${state.intakeOutcome}.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function buildPlanPayload(flags, state) {
|
|
98
|
+
const lane = state.lane;
|
|
99
|
+
const useSeededCandidates = Boolean(flags["use-seeded-candidates"]);
|
|
100
|
+
const payload = {
|
|
101
|
+
inScope: normalizeEntries(flags["in-scope"]),
|
|
102
|
+
outScope: normalizeEntries(flags["out-scope"]),
|
|
103
|
+
assumptions: normalizeEntries(flags.assumption),
|
|
104
|
+
risks: normalizeEntries(flags.risk),
|
|
105
|
+
slices: normalizeEntries(flags.slice),
|
|
106
|
+
planNotes: normalizeEntries(flags.note),
|
|
107
|
+
planningMode: lane === "bugfix" ? "bugfix-light" : "feature-standard",
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (lane !== "feature" && useSeededCandidates) {
|
|
111
|
+
throw new ValidationError('"--use-seeded-candidates" is only valid for feature-lane planning.');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (lane === "feature") {
|
|
115
|
+
const seededContext = getSeededPlanContext(state);
|
|
116
|
+
|
|
117
|
+
if (useSeededCandidates && state.currentPhase !== "start") {
|
|
118
|
+
throw new ValidationError(
|
|
119
|
+
'"--use-seeded-candidates" can only be used while confirming seeded handoff slices from the "start" phase.'
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (useSeededCandidates && payload.slices.length > 0) {
|
|
124
|
+
throw new ValidationError(
|
|
125
|
+
'Feature-lane planning must choose exactly one slice-confirmation path: explicit "--slice" entries or "--use-seeded-candidates".'
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (useSeededCandidates) {
|
|
130
|
+
if (seededContext.candidateSlices.length === 0) {
|
|
131
|
+
throw new ValidationError(
|
|
132
|
+
'No seeded candidate slices are available in the workflow artifact. Re-run "sdtk-code start" from a formal SDTK-SPEC handoff or use explicit "--slice" entries.'
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
payload.slices = seededContext.candidateSlices;
|
|
137
|
+
payload.planNotes = uniqueEntries([
|
|
138
|
+
"Confirmed seeded candidate slices from the formal SDTK-SPEC handoff via `--use-seeded-candidates`.",
|
|
139
|
+
...payload.planNotes,
|
|
140
|
+
...seededContext.candidatePlanningNotes,
|
|
141
|
+
]);
|
|
142
|
+
payload.planningMode = "feature-seeded-confirmed";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (payload.slices.length === 0) {
|
|
146
|
+
if (seededContext.candidateSlices.length > 0) {
|
|
147
|
+
throw new ValidationError(
|
|
148
|
+
'Feature-lane planning requires explicit "--slice" entries or "--use-seeded-candidates" to confirm the seeded handoff slice set.'
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
throw new ValidationError('Feature-lane planning requires at least one "--slice" entry.');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (lane === "bugfix" && payload.slices.length === 0) {
|
|
156
|
+
payload.slices = ["Targeted bugfix path remains lightweight; proceed to focused build and regression checks."];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return payload;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function runPlan(projectPath, featureKey, flags) {
|
|
163
|
+
const state = loadWorkflowArtifactState(projectPath, featureKey);
|
|
164
|
+
validatePlanState(state);
|
|
165
|
+
|
|
166
|
+
const planPayload = buildPlanPayload(flags, state);
|
|
167
|
+
const artifactPath = createOrUpdateWorkflowArtifact({
|
|
168
|
+
projectPath,
|
|
169
|
+
featureKey,
|
|
170
|
+
lane: state.lane,
|
|
171
|
+
currentPhase: "plan",
|
|
172
|
+
phaseStatus: "completed",
|
|
173
|
+
intakeOutcome: state.intakeOutcome,
|
|
174
|
+
nextPhase: "build",
|
|
175
|
+
blockingState: "clear",
|
|
176
|
+
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
177
|
+
managedBlocks: ["METADATA", "PLAN", "STATUS"],
|
|
178
|
+
...planPayload,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
artifactPath,
|
|
183
|
+
lane: state.lane,
|
|
184
|
+
nextPhase: "build",
|
|
185
|
+
suggestedEngineSkills: getBuildEngineSkills(state.lane),
|
|
186
|
+
planningMode: planPayload.planningMode,
|
|
187
|
+
sliceCount: planPayload.slices.length,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = {
|
|
192
|
+
runPlan,
|
|
193
|
+
};
|