sdtk-code-kit 0.2.1 → 0.3.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 +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 +174 -0
- 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 +257 -244
- 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 -108
- package/src/lib/agent-team-export.js +409 -0
- package/src/lib/agent-team-plan.js +514 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- 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 +185 -166
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +35 -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
package/src/lib/sleep-plan.js
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { ValidationError } = require("./errors");
|
|
6
|
-
const { loadScopes } = require("./trust-file-scope");
|
|
7
|
-
|
|
8
|
-
const STOP_CONDITIONS = [
|
|
9
|
-
{
|
|
10
|
-
id: "scope_lock",
|
|
11
|
-
description: "Halt if action would touch a blocked file scope.",
|
|
12
|
-
default: "on",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: "destructive_deny",
|
|
16
|
-
description:
|
|
17
|
-
"Deny irreversible destructive operations (rm -rf, DROP TABLE, force-push main).",
|
|
18
|
-
default: "on",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: "deploy_confirm",
|
|
22
|
-
description:
|
|
23
|
-
"Pause at deploy_confirm_points and require explicit confirmation before deployment actions.",
|
|
24
|
-
default: "on",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: "secret_block",
|
|
28
|
-
description:
|
|
29
|
-
"Block any action that reads or writes secret material (.env, *.pem, credentials).",
|
|
30
|
-
default: "on",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "action_count_cap",
|
|
34
|
-
description: "Stop when action count reaches budgets.max_actions.",
|
|
35
|
-
default: "on",
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "test_evidence_required",
|
|
39
|
-
description: "Do not mark a slice done without test_obligations evidence.",
|
|
40
|
-
default: "on",
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: "unknown_risk_stop",
|
|
44
|
-
description: "Stop and escalate when risk is unclassified or cannot be assessed.",
|
|
45
|
-
default: "on",
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: "three_fix_escalation",
|
|
49
|
-
description: "Escalate to controller after three failed fix attempts on the same failure.",
|
|
50
|
-
default: "on",
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
const CHECKPOINT_SCHEMA = {
|
|
55
|
-
phase: null,
|
|
56
|
-
files_touched: [],
|
|
57
|
-
last_green_verify: null,
|
|
58
|
-
blocker: null,
|
|
59
|
-
next_safe_action: null,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* PURE — builds a sleep-plan.v1 object from crafted inputs; no fs calls.
|
|
64
|
-
* Defaults: max_actions=50, max_iterations=10.
|
|
65
|
-
*/
|
|
66
|
-
function buildSleepPlan(handoff, scopes, opts) {
|
|
67
|
-
const rawActions = opts.maxActions !== undefined ? Number(opts.maxActions) : 50;
|
|
68
|
-
const rawIterations = opts.maxIterations !== undefined ? Number(opts.maxIterations) : 10;
|
|
69
|
-
|
|
70
|
-
if (!Number.isInteger(rawActions) || rawActions <= 0) {
|
|
71
|
-
throw new ValidationError("--max-actions must be a positive integer.");
|
|
72
|
-
}
|
|
73
|
-
if (!Number.isInteger(rawIterations) || rawIterations <= 0) {
|
|
74
|
-
throw new ValidationError("--max-iterations must be a positive integer.");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
schema_version: "sdtk.sleep-plan.v1",
|
|
79
|
-
feature_key: handoff.feature_key,
|
|
80
|
-
source: {
|
|
81
|
-
code_handoff_path: handoff._handoff_path || null,
|
|
82
|
-
lane: handoff.recommended_lane || null,
|
|
83
|
-
},
|
|
84
|
-
ordered_steps: Array.isArray(handoff.implementation_slices)
|
|
85
|
-
? [...handoff.implementation_slices]
|
|
86
|
-
: [],
|
|
87
|
-
scope: {
|
|
88
|
-
allowed_file_scopes: scopes.allowed || [],
|
|
89
|
-
blocked_file_scopes: scopes.blocked || [],
|
|
90
|
-
declared: scopes.declared === true,
|
|
91
|
-
},
|
|
92
|
-
policy_profile: "sleep-preview",
|
|
93
|
-
budgets: {
|
|
94
|
-
max_actions: rawActions,
|
|
95
|
-
max_iterations: rawIterations,
|
|
96
|
-
},
|
|
97
|
-
test_obligations: Array.isArray(handoff.test_obligations)
|
|
98
|
-
? [...handoff.test_obligations]
|
|
99
|
-
: [],
|
|
100
|
-
stop_conditions: STOP_CONDITIONS,
|
|
101
|
-
deploy_confirm_points: [],
|
|
102
|
-
checkpoint_schema: CHECKPOINT_SCHEMA,
|
|
103
|
-
runtime: "agnostic",
|
|
104
|
-
generated_at: new Date().toISOString(),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Thin fs wrapper — reads CODE_HANDOFF + loadScopes, then calls buildSleepPlan.
|
|
110
|
-
* Fail-closed: missing/invalid handoff or not READY_FOR_SDTK_CODE → ValidationError(NEEDS_HANDOFF).
|
|
111
|
-
*/
|
|
112
|
-
function assembleSleepPlan(projectPath, featureKey, opts) {
|
|
113
|
-
opts = opts || {};
|
|
114
|
-
const resolved = path.resolve(projectPath || ".");
|
|
115
|
-
const handoffPath = path.join(
|
|
116
|
-
resolved,
|
|
117
|
-
"docs",
|
|
118
|
-
"dev",
|
|
119
|
-
`CODE_HANDOFF_${featureKey}.json`
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
let handoff;
|
|
123
|
-
try {
|
|
124
|
-
const raw = fs.readFileSync(handoffPath, "utf8");
|
|
125
|
-
handoff = JSON.parse(raw);
|
|
126
|
-
} catch (_err) {
|
|
127
|
-
throw new ValidationError(
|
|
128
|
-
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json not found or invalid at ${handoffPath}. ` +
|
|
129
|
-
"Ensure the feature has a valid READY_FOR_SDTK_CODE handoff before running sleep plan."
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (handoff.handoff_status !== "READY_FOR_SDTK_CODE") {
|
|
134
|
-
throw new ValidationError(
|
|
135
|
-
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json status is "${handoff.handoff_status}", ` +
|
|
136
|
-
'expected "READY_FOR_SDTK_CODE". Resolve open blockers first.'
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!Array.isArray(handoff.implementation_slices) || handoff.implementation_slices.length === 0) {
|
|
141
|
-
throw new ValidationError(
|
|
142
|
-
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json must have at least one implementation_slices entry.`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Attach path for source provenance in the plan (read by buildSleepPlan).
|
|
147
|
-
handoff._handoff_path = handoffPath;
|
|
148
|
-
|
|
149
|
-
const scopes = loadScopes(resolved, featureKey, opts.scopes || {});
|
|
150
|
-
|
|
151
|
-
return buildSleepPlan(handoff, scopes, {
|
|
152
|
-
maxActions: opts.maxActions,
|
|
153
|
-
maxIterations: opts.maxIterations,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Thin fs wrapper — writes plan to .sdtk/trust/sleep-plan.json; returns output path.
|
|
159
|
-
*/
|
|
160
|
-
function writeSleepPlan(projectPath, plan) {
|
|
161
|
-
const resolved = path.resolve(projectPath || ".");
|
|
162
|
-
const trustDir = path.join(resolved, ".sdtk", "trust");
|
|
163
|
-
fs.mkdirSync(trustDir, { recursive: true });
|
|
164
|
-
const outPath = path.join(trustDir, "sleep-plan.json");
|
|
165
|
-
fs.writeFileSync(outPath, JSON.stringify(plan, null, 2), "utf8");
|
|
166
|
-
return outPath;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports = {
|
|
170
|
-
STOP_CONDITIONS,
|
|
171
|
-
CHECKPOINT_SCHEMA,
|
|
172
|
-
buildSleepPlan,
|
|
173
|
-
assembleSleepPlan,
|
|
174
|
-
writeSleepPlan,
|
|
175
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { ValidationError } = require("./errors");
|
|
6
|
+
const { loadScopes } = require("./trust-file-scope");
|
|
7
|
+
|
|
8
|
+
const STOP_CONDITIONS = [
|
|
9
|
+
{
|
|
10
|
+
id: "scope_lock",
|
|
11
|
+
description: "Halt if action would touch a blocked file scope.",
|
|
12
|
+
default: "on",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "destructive_deny",
|
|
16
|
+
description:
|
|
17
|
+
"Deny irreversible destructive operations (rm -rf, DROP TABLE, force-push main).",
|
|
18
|
+
default: "on",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "deploy_confirm",
|
|
22
|
+
description:
|
|
23
|
+
"Pause at deploy_confirm_points and require explicit confirmation before deployment actions.",
|
|
24
|
+
default: "on",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "secret_block",
|
|
28
|
+
description:
|
|
29
|
+
"Block any action that reads or writes secret material (.env, *.pem, credentials).",
|
|
30
|
+
default: "on",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "action_count_cap",
|
|
34
|
+
description: "Stop when action count reaches budgets.max_actions.",
|
|
35
|
+
default: "on",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "test_evidence_required",
|
|
39
|
+
description: "Do not mark a slice done without test_obligations evidence.",
|
|
40
|
+
default: "on",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "unknown_risk_stop",
|
|
44
|
+
description: "Stop and escalate when risk is unclassified or cannot be assessed.",
|
|
45
|
+
default: "on",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "three_fix_escalation",
|
|
49
|
+
description: "Escalate to controller after three failed fix attempts on the same failure.",
|
|
50
|
+
default: "on",
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const CHECKPOINT_SCHEMA = {
|
|
55
|
+
phase: null,
|
|
56
|
+
files_touched: [],
|
|
57
|
+
last_green_verify: null,
|
|
58
|
+
blocker: null,
|
|
59
|
+
next_safe_action: null,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* PURE — builds a sleep-plan.v1 object from crafted inputs; no fs calls.
|
|
64
|
+
* Defaults: max_actions=50, max_iterations=10.
|
|
65
|
+
*/
|
|
66
|
+
function buildSleepPlan(handoff, scopes, opts) {
|
|
67
|
+
const rawActions = opts.maxActions !== undefined ? Number(opts.maxActions) : 50;
|
|
68
|
+
const rawIterations = opts.maxIterations !== undefined ? Number(opts.maxIterations) : 10;
|
|
69
|
+
|
|
70
|
+
if (!Number.isInteger(rawActions) || rawActions <= 0) {
|
|
71
|
+
throw new ValidationError("--max-actions must be a positive integer.");
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isInteger(rawIterations) || rawIterations <= 0) {
|
|
74
|
+
throw new ValidationError("--max-iterations must be a positive integer.");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
schema_version: "sdtk.sleep-plan.v1",
|
|
79
|
+
feature_key: handoff.feature_key,
|
|
80
|
+
source: {
|
|
81
|
+
code_handoff_path: handoff._handoff_path || null,
|
|
82
|
+
lane: handoff.recommended_lane || null,
|
|
83
|
+
},
|
|
84
|
+
ordered_steps: Array.isArray(handoff.implementation_slices)
|
|
85
|
+
? [...handoff.implementation_slices]
|
|
86
|
+
: [],
|
|
87
|
+
scope: {
|
|
88
|
+
allowed_file_scopes: scopes.allowed || [],
|
|
89
|
+
blocked_file_scopes: scopes.blocked || [],
|
|
90
|
+
declared: scopes.declared === true,
|
|
91
|
+
},
|
|
92
|
+
policy_profile: "sleep-preview",
|
|
93
|
+
budgets: {
|
|
94
|
+
max_actions: rawActions,
|
|
95
|
+
max_iterations: rawIterations,
|
|
96
|
+
},
|
|
97
|
+
test_obligations: Array.isArray(handoff.test_obligations)
|
|
98
|
+
? [...handoff.test_obligations]
|
|
99
|
+
: [],
|
|
100
|
+
stop_conditions: STOP_CONDITIONS,
|
|
101
|
+
deploy_confirm_points: [],
|
|
102
|
+
checkpoint_schema: CHECKPOINT_SCHEMA,
|
|
103
|
+
runtime: "agnostic",
|
|
104
|
+
generated_at: new Date().toISOString(),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Thin fs wrapper — reads CODE_HANDOFF + loadScopes, then calls buildSleepPlan.
|
|
110
|
+
* Fail-closed: missing/invalid handoff or not READY_FOR_SDTK_CODE → ValidationError(NEEDS_HANDOFF).
|
|
111
|
+
*/
|
|
112
|
+
function assembleSleepPlan(projectPath, featureKey, opts) {
|
|
113
|
+
opts = opts || {};
|
|
114
|
+
const resolved = path.resolve(projectPath || ".");
|
|
115
|
+
const handoffPath = path.join(
|
|
116
|
+
resolved,
|
|
117
|
+
"docs",
|
|
118
|
+
"dev",
|
|
119
|
+
`CODE_HANDOFF_${featureKey}.json`
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
let handoff;
|
|
123
|
+
try {
|
|
124
|
+
const raw = fs.readFileSync(handoffPath, "utf8");
|
|
125
|
+
handoff = JSON.parse(raw);
|
|
126
|
+
} catch (_err) {
|
|
127
|
+
throw new ValidationError(
|
|
128
|
+
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json not found or invalid at ${handoffPath}. ` +
|
|
129
|
+
"Ensure the feature has a valid READY_FOR_SDTK_CODE handoff before running sleep plan."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (handoff.handoff_status !== "READY_FOR_SDTK_CODE") {
|
|
134
|
+
throw new ValidationError(
|
|
135
|
+
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json status is "${handoff.handoff_status}", ` +
|
|
136
|
+
'expected "READY_FOR_SDTK_CODE". Resolve open blockers first.'
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!Array.isArray(handoff.implementation_slices) || handoff.implementation_slices.length === 0) {
|
|
141
|
+
throw new ValidationError(
|
|
142
|
+
`NEEDS_HANDOFF: CODE_HANDOFF_${featureKey}.json must have at least one implementation_slices entry.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Attach path for source provenance in the plan (read by buildSleepPlan).
|
|
147
|
+
handoff._handoff_path = handoffPath;
|
|
148
|
+
|
|
149
|
+
const scopes = loadScopes(resolved, featureKey, opts.scopes || {});
|
|
150
|
+
|
|
151
|
+
return buildSleepPlan(handoff, scopes, {
|
|
152
|
+
maxActions: opts.maxActions,
|
|
153
|
+
maxIterations: opts.maxIterations,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Thin fs wrapper — writes plan to .sdtk/trust/sleep-plan.json; returns output path.
|
|
159
|
+
*/
|
|
160
|
+
function writeSleepPlan(projectPath, plan) {
|
|
161
|
+
const resolved = path.resolve(projectPath || ".");
|
|
162
|
+
const trustDir = path.join(resolved, ".sdtk", "trust");
|
|
163
|
+
fs.mkdirSync(trustDir, { recursive: true });
|
|
164
|
+
const outPath = path.join(trustDir, "sleep-plan.json");
|
|
165
|
+
fs.writeFileSync(outPath, JSON.stringify(plan, null, 2), "utf8");
|
|
166
|
+
return outPath;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = {
|
|
170
|
+
STOP_CONDITIONS,
|
|
171
|
+
CHECKPOINT_SCHEMA,
|
|
172
|
+
buildSleepPlan,
|
|
173
|
+
assembleSleepPlan,
|
|
174
|
+
writeSleepPlan,
|
|
175
|
+
};
|