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.
Files changed (56) hide show
  1. package/README.md +204 -204
  2. package/assets/manifest/toolkit-bundle.manifest.json +147 -147
  3. package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
  4. package/bin/sdtk-code.js +14 -14
  5. package/package.json +44 -44
  6. package/src/commands/agent-team.js +425 -174
  7. package/src/commands/build.js +53 -53
  8. package/src/commands/doctor.js +51 -51
  9. package/src/commands/generate.js +11 -11
  10. package/src/commands/guardrails.js +215 -215
  11. package/src/commands/help.js +264 -257
  12. package/src/commands/init.js +98 -98
  13. package/src/commands/plan.js +53 -53
  14. package/src/commands/readiness.js +77 -77
  15. package/src/commands/resume.js +61 -61
  16. package/src/commands/runtime.js +224 -224
  17. package/src/commands/ship.js +59 -59
  18. package/src/commands/sleep.js +132 -132
  19. package/src/commands/start.js +89 -89
  20. package/src/commands/status.js +77 -77
  21. package/src/commands/update.js +11 -11
  22. package/src/commands/verify.js +71 -71
  23. package/src/index.js +112 -112
  24. package/src/lib/agent-team-author.js +521 -0
  25. package/src/lib/agent-team-evidence.js +302 -0
  26. package/src/lib/agent-team-execute.js +892 -0
  27. package/src/lib/agent-team-export.js +411 -409
  28. package/src/lib/agent-team-plan.js +514 -514
  29. package/src/lib/agent-team-readiness.js +161 -0
  30. package/src/lib/agent-team-report.js +165 -0
  31. package/src/lib/args.js +107 -107
  32. package/src/lib/errors.js +41 -41
  33. package/src/lib/model-provider.js +219 -0
  34. package/src/lib/powershell.js +65 -65
  35. package/src/lib/project-target-guard.js +53 -53
  36. package/src/lib/scope.js +72 -72
  37. package/src/lib/ship-readiness.js +281 -281
  38. package/src/lib/sleep-plan.js +175 -175
  39. package/src/lib/sleep-report.js +229 -229
  40. package/src/lib/toolkit-payload.js +72 -72
  41. package/src/lib/trust-events.js +252 -185
  42. package/src/lib/trust-file-scope.js +154 -154
  43. package/src/lib/trust-policy.js +212 -212
  44. package/src/lib/trust-redact.js +58 -35
  45. package/src/lib/trust-trace.js +179 -179
  46. package/src/lib/update.js +344 -344
  47. package/src/lib/workflow-artifact.js +503 -503
  48. package/src/lib/workflow-build.js +127 -127
  49. package/src/lib/workflow-doctor.js +83 -83
  50. package/src/lib/workflow-handoff.js +1029 -1029
  51. package/src/lib/workflow-intake.js +101 -101
  52. package/src/lib/workflow-plan.js +193 -193
  53. package/src/lib/workflow-review-packet.js +650 -650
  54. package/src/lib/workflow-ship.js +213 -213
  55. package/src/lib/workflow-state.js +438 -438
  56. package/src/lib/workflow-verify.js +393 -393
@@ -1,229 +1,229 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { ValidationError } = require("./errors");
6
- const { computeReadiness, gatherSignals } = require("./ship-readiness");
7
-
8
- const REPORT_SCHEMA = "sdtk.sleep-report.v1";
9
- const PLAN_SCHEMA = "sdtk.sleep-plan.v1";
10
- const SCOPE_BLOCKER =
11
- "Scope not declared — the agent could touch any file; `scope_lock` has nothing to enforce.";
12
- const DRY_RUN_DISCLAIMER =
13
- "This is a pre-flight projection of the plan — nothing was executed.";
14
-
15
- function list(value) {
16
- return Array.isArray(value) ? [...value] : [];
17
- }
18
-
19
- function planScope(plan) {
20
- return plan && plan.scope && typeof plan.scope === "object" ? plan.scope : {};
21
- }
22
-
23
- function readinessComponentNotes(readiness) {
24
- if (!readiness || !Array.isArray(readiness.components)) {
25
- return [];
26
- }
27
- return readiness.components
28
- .filter((component) => component && typeof component.note === "string" && component.note.length > 0)
29
- .map((component) => `${component.name}: ${component.note}`);
30
- }
31
-
32
- function failingComponentNames(readiness) {
33
- if (!readiness || !Array.isArray(readiness.components)) {
34
- return [];
35
- }
36
- return readiness.components
37
- .filter((component) => Number(component.points) < Number(component.max))
38
- .map((component) => component.name)
39
- .filter((name) => typeof name === "string" && name.length > 0);
40
- }
41
-
42
- function projectSleepReport(plan, signals) {
43
- const readiness = computeReadiness(signals);
44
- const blockers = [];
45
- const notes = [];
46
- const scope = planScope(plan);
47
- const orderedSteps = list(plan && plan.ordered_steps);
48
- const testObligations = list(plan && plan.test_obligations);
49
- const deployConfirmPoints = list(plan && plan.deploy_confirm_points);
50
-
51
- if (!plan || plan.schema_version !== PLAN_SCHEMA || orderedSteps.length === 0) {
52
- blockers.push("Invalid sleep plan — expected sdtk.sleep-plan.v1 with at least one ordered step.");
53
- }
54
-
55
- if (scope.declared !== true) {
56
- blockers.push(SCOPE_BLOCKER);
57
- }
58
-
59
- if (readiness.verdict === "FAIL") {
60
- const failing = failingComponentNames(readiness);
61
- blockers.push(
62
- failing.length > 0
63
- ? `Ship-readiness FAIL. Failing components: ${failing.join(", ")}.`
64
- : "Ship-readiness FAIL."
65
- );
66
- }
67
-
68
- if (readiness.verdict === "ENV_BLOCKED") {
69
- blockers.push("Readiness signals unavailable (ENV_BLOCKED).");
70
- }
71
-
72
- if (testObligations.length === 0) {
73
- notes.push("No test obligations carried — `test_evidence_required` has nothing to check.");
74
- }
75
-
76
- if (readiness.verdict === "PASS_WITH_NOTES") {
77
- const warnings = Array.isArray(readiness.warnings) ? readiness.warnings : [];
78
- if (warnings.length > 0) {
79
- notes.push(...warnings);
80
- } else {
81
- notes.push("Ship-readiness PASS_WITH_NOTES.");
82
- }
83
- }
84
-
85
- const verdict = blockers.length > 0
86
- ? "NOT_READY"
87
- : notes.length > 0
88
- ? "READY_WITH_NOTES"
89
- : "READY_TO_SLEEP";
90
-
91
- const reason = blockers.length > 0
92
- ? blockers[0]
93
- : notes.length > 0
94
- ? notes[0]
95
- : "The sleep plan is bounded, readiness is PASS, and test obligations are present.";
96
-
97
- return {
98
- schema_version: REPORT_SCHEMA,
99
- feature_key: plan && plan.feature_key,
100
- verdict,
101
- reason,
102
- readiness,
103
- sections: {
104
- can_i_sleep: { verdict, reason },
105
- what_it_can_touch: {
106
- declared: scope.declared === true,
107
- allowed_file_scopes: list(scope.allowed_file_scopes),
108
- blocked_file_scopes: list(scope.blocked_file_scopes),
109
- warning: scope.declared === true ? null : "scope_lock cannot enforce undeclared scope.",
110
- },
111
- when_it_will_stop: {
112
- stop_conditions: list(plan && plan.stop_conditions).map((condition) => {
113
- if (condition && typeof condition === "object" && typeof condition.id === "string") {
114
- return condition.id;
115
- }
116
- return condition;
117
- }),
118
- budgets: plan && plan.budgets && typeof plan.budgets === "object" ? { ...plan.budgets } : {},
119
- },
120
- what_proves_done: {
121
- test_obligations: testObligations,
122
- readiness_components: readinessComponentNotes(readiness),
123
- },
124
- what_needs_you: {
125
- deploy_confirm_points: deployConfirmPoints,
126
- blockers: [...blockers],
127
- notes: [...notes],
128
- },
129
- },
130
- blockers,
131
- notes,
132
- dry_run: true,
133
- generated_at: new Date().toISOString(),
134
- };
135
- }
136
-
137
- function bulletList(items, fallback) {
138
- if (!Array.isArray(items) || items.length === 0) {
139
- return `- ${fallback}`;
140
- }
141
- return items.map((item) => `- ${String(item)}`).join("\n");
142
- }
143
-
144
- function renderSleepReportMarkdown(report) {
145
- const touch = report.sections.what_it_can_touch;
146
- const stop = report.sections.when_it_will_stop;
147
- const proves = report.sections.what_proves_done;
148
- const needs = report.sections.what_needs_you;
149
-
150
- return [
151
- `# Sleep Readiness Report — ${report.feature_key}`,
152
- "",
153
- DRY_RUN_DISCLAIMER,
154
- "",
155
- "## Can I sleep?",
156
- "",
157
- `- Verdict: ${report.verdict}`,
158
- `- Reason: ${report.reason}`,
159
- `- Readiness: ${report.readiness.score}/${report.readiness.max} — ${report.readiness.verdict}`,
160
- "",
161
- "## What it can touch",
162
- "",
163
- `- Scope declared: ${touch.declared ? "yes" : "no"}`,
164
- "- Allowed file scopes:",
165
- bulletList(touch.allowed_file_scopes, "none declared"),
166
- "- Blocked file scopes:",
167
- bulletList(touch.blocked_file_scopes, "none declared"),
168
- touch.warning ? `- Warning: ${touch.warning}` : "- Warning: none",
169
- "",
170
- "## When it will stop",
171
- "",
172
- "- Stop conditions:",
173
- bulletList(stop.stop_conditions, "none declared"),
174
- "- Budgets:",
175
- `- max_actions: ${stop.budgets.max_actions !== undefined ? stop.budgets.max_actions : "not declared"}`,
176
- `- max_iterations: ${stop.budgets.max_iterations !== undefined ? stop.budgets.max_iterations : "not declared"}`,
177
- "",
178
- "## What proves it's done",
179
- "",
180
- "- Test obligations:",
181
- bulletList(proves.test_obligations, "none carried"),
182
- "- Readiness components:",
183
- bulletList(proves.readiness_components, "none"),
184
- "",
185
- "## What needs you",
186
- "",
187
- "- Deploy confirm points:",
188
- bulletList(needs.deploy_confirm_points, "none declared"),
189
- "- Blockers:",
190
- bulletList(needs.blockers, "none"),
191
- "- Notes:",
192
- bulletList(needs.notes, "none"),
193
- "",
194
- ].join("\n");
195
- }
196
-
197
- function loadSleepPlan(projectPath) {
198
- const resolved = path.resolve(projectPath || ".");
199
- const planPath = path.join(resolved, ".sdtk", "trust", "sleep-plan.json");
200
- try {
201
- return JSON.parse(fs.readFileSync(planPath, "utf8"));
202
- } catch (_error) {
203
- throw new ValidationError(
204
- `NEEDS_PLAN: no sleep plan found at ${planPath}; ` +
205
- "run `sdtk-code sleep plan --feature-key <KEY>` first."
206
- );
207
- }
208
- }
209
-
210
- function gatherReportSignals(projectPath, featureKey) {
211
- return gatherSignals(projectPath, featureKey);
212
- }
213
-
214
- function writeSleepReport(projectPath, featureKey, markdown) {
215
- const resolved = path.resolve(projectPath || ".");
216
- const outDir = path.join(resolved, "docs", "trust");
217
- fs.mkdirSync(outDir, { recursive: true });
218
- const outPath = path.join(outDir, `SLEEP_REPORT_${featureKey}.md`);
219
- fs.writeFileSync(outPath, markdown, "utf8");
220
- return outPath;
221
- }
222
-
223
- module.exports = {
224
- projectSleepReport,
225
- renderSleepReportMarkdown,
226
- loadSleepPlan,
227
- gatherReportSignals,
228
- writeSleepReport,
229
- };
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { ValidationError } = require("./errors");
6
+ const { computeReadiness, gatherSignals } = require("./ship-readiness");
7
+
8
+ const REPORT_SCHEMA = "sdtk.sleep-report.v1";
9
+ const PLAN_SCHEMA = "sdtk.sleep-plan.v1";
10
+ const SCOPE_BLOCKER =
11
+ "Scope not declared — the agent could touch any file; `scope_lock` has nothing to enforce.";
12
+ const DRY_RUN_DISCLAIMER =
13
+ "This is a pre-flight projection of the plan — nothing was executed.";
14
+
15
+ function list(value) {
16
+ return Array.isArray(value) ? [...value] : [];
17
+ }
18
+
19
+ function planScope(plan) {
20
+ return plan && plan.scope && typeof plan.scope === "object" ? plan.scope : {};
21
+ }
22
+
23
+ function readinessComponentNotes(readiness) {
24
+ if (!readiness || !Array.isArray(readiness.components)) {
25
+ return [];
26
+ }
27
+ return readiness.components
28
+ .filter((component) => component && typeof component.note === "string" && component.note.length > 0)
29
+ .map((component) => `${component.name}: ${component.note}`);
30
+ }
31
+
32
+ function failingComponentNames(readiness) {
33
+ if (!readiness || !Array.isArray(readiness.components)) {
34
+ return [];
35
+ }
36
+ return readiness.components
37
+ .filter((component) => Number(component.points) < Number(component.max))
38
+ .map((component) => component.name)
39
+ .filter((name) => typeof name === "string" && name.length > 0);
40
+ }
41
+
42
+ function projectSleepReport(plan, signals) {
43
+ const readiness = computeReadiness(signals);
44
+ const blockers = [];
45
+ const notes = [];
46
+ const scope = planScope(plan);
47
+ const orderedSteps = list(plan && plan.ordered_steps);
48
+ const testObligations = list(plan && plan.test_obligations);
49
+ const deployConfirmPoints = list(plan && plan.deploy_confirm_points);
50
+
51
+ if (!plan || plan.schema_version !== PLAN_SCHEMA || orderedSteps.length === 0) {
52
+ blockers.push("Invalid sleep plan — expected sdtk.sleep-plan.v1 with at least one ordered step.");
53
+ }
54
+
55
+ if (scope.declared !== true) {
56
+ blockers.push(SCOPE_BLOCKER);
57
+ }
58
+
59
+ if (readiness.verdict === "FAIL") {
60
+ const failing = failingComponentNames(readiness);
61
+ blockers.push(
62
+ failing.length > 0
63
+ ? `Ship-readiness FAIL. Failing components: ${failing.join(", ")}.`
64
+ : "Ship-readiness FAIL."
65
+ );
66
+ }
67
+
68
+ if (readiness.verdict === "ENV_BLOCKED") {
69
+ blockers.push("Readiness signals unavailable (ENV_BLOCKED).");
70
+ }
71
+
72
+ if (testObligations.length === 0) {
73
+ notes.push("No test obligations carried — `test_evidence_required` has nothing to check.");
74
+ }
75
+
76
+ if (readiness.verdict === "PASS_WITH_NOTES") {
77
+ const warnings = Array.isArray(readiness.warnings) ? readiness.warnings : [];
78
+ if (warnings.length > 0) {
79
+ notes.push(...warnings);
80
+ } else {
81
+ notes.push("Ship-readiness PASS_WITH_NOTES.");
82
+ }
83
+ }
84
+
85
+ const verdict = blockers.length > 0
86
+ ? "NOT_READY"
87
+ : notes.length > 0
88
+ ? "READY_WITH_NOTES"
89
+ : "READY_TO_SLEEP";
90
+
91
+ const reason = blockers.length > 0
92
+ ? blockers[0]
93
+ : notes.length > 0
94
+ ? notes[0]
95
+ : "The sleep plan is bounded, readiness is PASS, and test obligations are present.";
96
+
97
+ return {
98
+ schema_version: REPORT_SCHEMA,
99
+ feature_key: plan && plan.feature_key,
100
+ verdict,
101
+ reason,
102
+ readiness,
103
+ sections: {
104
+ can_i_sleep: { verdict, reason },
105
+ what_it_can_touch: {
106
+ declared: scope.declared === true,
107
+ allowed_file_scopes: list(scope.allowed_file_scopes),
108
+ blocked_file_scopes: list(scope.blocked_file_scopes),
109
+ warning: scope.declared === true ? null : "scope_lock cannot enforce undeclared scope.",
110
+ },
111
+ when_it_will_stop: {
112
+ stop_conditions: list(plan && plan.stop_conditions).map((condition) => {
113
+ if (condition && typeof condition === "object" && typeof condition.id === "string") {
114
+ return condition.id;
115
+ }
116
+ return condition;
117
+ }),
118
+ budgets: plan && plan.budgets && typeof plan.budgets === "object" ? { ...plan.budgets } : {},
119
+ },
120
+ what_proves_done: {
121
+ test_obligations: testObligations,
122
+ readiness_components: readinessComponentNotes(readiness),
123
+ },
124
+ what_needs_you: {
125
+ deploy_confirm_points: deployConfirmPoints,
126
+ blockers: [...blockers],
127
+ notes: [...notes],
128
+ },
129
+ },
130
+ blockers,
131
+ notes,
132
+ dry_run: true,
133
+ generated_at: new Date().toISOString(),
134
+ };
135
+ }
136
+
137
+ function bulletList(items, fallback) {
138
+ if (!Array.isArray(items) || items.length === 0) {
139
+ return `- ${fallback}`;
140
+ }
141
+ return items.map((item) => `- ${String(item)}`).join("\n");
142
+ }
143
+
144
+ function renderSleepReportMarkdown(report) {
145
+ const touch = report.sections.what_it_can_touch;
146
+ const stop = report.sections.when_it_will_stop;
147
+ const proves = report.sections.what_proves_done;
148
+ const needs = report.sections.what_needs_you;
149
+
150
+ return [
151
+ `# Sleep Readiness Report — ${report.feature_key}`,
152
+ "",
153
+ DRY_RUN_DISCLAIMER,
154
+ "",
155
+ "## Can I sleep?",
156
+ "",
157
+ `- Verdict: ${report.verdict}`,
158
+ `- Reason: ${report.reason}`,
159
+ `- Readiness: ${report.readiness.score}/${report.readiness.max} — ${report.readiness.verdict}`,
160
+ "",
161
+ "## What it can touch",
162
+ "",
163
+ `- Scope declared: ${touch.declared ? "yes" : "no"}`,
164
+ "- Allowed file scopes:",
165
+ bulletList(touch.allowed_file_scopes, "none declared"),
166
+ "- Blocked file scopes:",
167
+ bulletList(touch.blocked_file_scopes, "none declared"),
168
+ touch.warning ? `- Warning: ${touch.warning}` : "- Warning: none",
169
+ "",
170
+ "## When it will stop",
171
+ "",
172
+ "- Stop conditions:",
173
+ bulletList(stop.stop_conditions, "none declared"),
174
+ "- Budgets:",
175
+ `- max_actions: ${stop.budgets.max_actions !== undefined ? stop.budgets.max_actions : "not declared"}`,
176
+ `- max_iterations: ${stop.budgets.max_iterations !== undefined ? stop.budgets.max_iterations : "not declared"}`,
177
+ "",
178
+ "## What proves it's done",
179
+ "",
180
+ "- Test obligations:",
181
+ bulletList(proves.test_obligations, "none carried"),
182
+ "- Readiness components:",
183
+ bulletList(proves.readiness_components, "none"),
184
+ "",
185
+ "## What needs you",
186
+ "",
187
+ "- Deploy confirm points:",
188
+ bulletList(needs.deploy_confirm_points, "none declared"),
189
+ "- Blockers:",
190
+ bulletList(needs.blockers, "none"),
191
+ "- Notes:",
192
+ bulletList(needs.notes, "none"),
193
+ "",
194
+ ].join("\n");
195
+ }
196
+
197
+ function loadSleepPlan(projectPath) {
198
+ const resolved = path.resolve(projectPath || ".");
199
+ const planPath = path.join(resolved, ".sdtk", "trust", "sleep-plan.json");
200
+ try {
201
+ return JSON.parse(fs.readFileSync(planPath, "utf8"));
202
+ } catch (_error) {
203
+ throw new ValidationError(
204
+ `NEEDS_PLAN: no sleep plan found at ${planPath}; ` +
205
+ "run `sdtk-code sleep plan --feature-key <KEY>` first."
206
+ );
207
+ }
208
+ }
209
+
210
+ function gatherReportSignals(projectPath, featureKey) {
211
+ return gatherSignals(projectPath, featureKey);
212
+ }
213
+
214
+ function writeSleepReport(projectPath, featureKey, markdown) {
215
+ const resolved = path.resolve(projectPath || ".");
216
+ const outDir = path.join(resolved, "docs", "trust");
217
+ fs.mkdirSync(outDir, { recursive: true });
218
+ const outPath = path.join(outDir, `SLEEP_REPORT_${featureKey}.md`);
219
+ fs.writeFileSync(outPath, markdown, "utf8");
220
+ return outPath;
221
+ }
222
+
223
+ module.exports = {
224
+ projectSleepReport,
225
+ renderSleepReportMarkdown,
226
+ loadSleepPlan,
227
+ gatherReportSignals,
228
+ writeSleepReport,
229
+ };
@@ -1,72 +1,72 @@
1
- "use strict";
2
-
3
- const crypto = require("crypto");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const { IntegrityError } = require("./errors");
7
-
8
- const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
9
- const ASSETS_DIR = path.join(PACKAGE_ROOT, "assets", "toolkit");
10
- const MANIFEST_PATH = path.join(
11
- PACKAGE_ROOT,
12
- "assets",
13
- "manifest",
14
- "toolkit-bundle.manifest.json"
15
- );
16
-
17
- function loadManifest() {
18
- if (!fs.existsSync(MANIFEST_PATH)) {
19
- throw new IntegrityError(
20
- `SDTK-CODE toolkit manifest not found: ${MANIFEST_PATH}\nRun "npm run build:payload" to sync toolkit assets.`
21
- );
22
- }
23
-
24
- try {
25
- return JSON.parse(fs.readFileSync(MANIFEST_PATH, "utf-8"));
26
- } catch (error) {
27
- throw new IntegrityError(`Failed to parse SDTK-CODE toolkit manifest: ${error.message}`);
28
- }
29
- }
30
-
31
- function hashFile(filePath) {
32
- return crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
33
- }
34
-
35
- function verify() {
36
- const manifest = loadManifest();
37
- if (!Array.isArray(manifest.files)) {
38
- throw new IntegrityError("SDTK-CODE toolkit manifest has no files array.");
39
- }
40
-
41
- const errors = [];
42
- for (const entry of manifest.files) {
43
- const filePath = path.join(ASSETS_DIR, entry.path);
44
- if (!fs.existsSync(filePath)) {
45
- errors.push(`MISSING: ${entry.path}`);
46
- continue;
47
- }
48
-
49
- const actualHash = hashFile(filePath);
50
- if (actualHash !== entry.sha256) {
51
- errors.push(
52
- `HASH MISMATCH: ${entry.path}\n expected: ${entry.sha256}\n actual: ${actualHash}`
53
- );
54
- }
55
- }
56
-
57
- if (errors.length > 0) {
58
- throw new IntegrityError(`SDTK-CODE toolkit payload integrity check failed:\n${errors.join("\n")}`);
59
- }
60
- }
61
-
62
- function resolvePayloadFile(relativePath) {
63
- return path.join(ASSETS_DIR, relativePath);
64
- }
65
-
66
- module.exports = {
67
- ASSETS_DIR,
68
- loadManifest,
69
- hashFile,
70
- resolvePayloadFile,
71
- verify,
72
- };
1
+ "use strict";
2
+
3
+ const crypto = require("crypto");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { IntegrityError } = require("./errors");
7
+
8
+ const PACKAGE_ROOT = path.resolve(__dirname, "..", "..");
9
+ const ASSETS_DIR = path.join(PACKAGE_ROOT, "assets", "toolkit");
10
+ const MANIFEST_PATH = path.join(
11
+ PACKAGE_ROOT,
12
+ "assets",
13
+ "manifest",
14
+ "toolkit-bundle.manifest.json"
15
+ );
16
+
17
+ function loadManifest() {
18
+ if (!fs.existsSync(MANIFEST_PATH)) {
19
+ throw new IntegrityError(
20
+ `SDTK-CODE toolkit manifest not found: ${MANIFEST_PATH}\nRun "npm run build:payload" to sync toolkit assets.`
21
+ );
22
+ }
23
+
24
+ try {
25
+ return JSON.parse(fs.readFileSync(MANIFEST_PATH, "utf-8"));
26
+ } catch (error) {
27
+ throw new IntegrityError(`Failed to parse SDTK-CODE toolkit manifest: ${error.message}`);
28
+ }
29
+ }
30
+
31
+ function hashFile(filePath) {
32
+ return crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
33
+ }
34
+
35
+ function verify() {
36
+ const manifest = loadManifest();
37
+ if (!Array.isArray(manifest.files)) {
38
+ throw new IntegrityError("SDTK-CODE toolkit manifest has no files array.");
39
+ }
40
+
41
+ const errors = [];
42
+ for (const entry of manifest.files) {
43
+ const filePath = path.join(ASSETS_DIR, entry.path);
44
+ if (!fs.existsSync(filePath)) {
45
+ errors.push(`MISSING: ${entry.path}`);
46
+ continue;
47
+ }
48
+
49
+ const actualHash = hashFile(filePath);
50
+ if (actualHash !== entry.sha256) {
51
+ errors.push(
52
+ `HASH MISMATCH: ${entry.path}\n expected: ${entry.sha256}\n actual: ${actualHash}`
53
+ );
54
+ }
55
+ }
56
+
57
+ if (errors.length > 0) {
58
+ throw new IntegrityError(`SDTK-CODE toolkit payload integrity check failed:\n${errors.join("\n")}`);
59
+ }
60
+ }
61
+
62
+ function resolvePayloadFile(relativePath) {
63
+ return path.join(ASSETS_DIR, relativePath);
64
+ }
65
+
66
+ module.exports = {
67
+ ASSETS_DIR,
68
+ loadManifest,
69
+ hashFile,
70
+ resolvePayloadFile,
71
+ verify,
72
+ };