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,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { parseFlags, requireFlag, validatePattern } = require("../lib/args");
|
|
5
|
+
const { ValidationError } = require("../lib/errors");
|
|
6
|
+
const { runVerify } = require("../lib/workflow-verify");
|
|
7
|
+
|
|
8
|
+
const FLAG_DEFS = {
|
|
9
|
+
"feature-key": { type: "string" },
|
|
10
|
+
"project-path": { type: "string" },
|
|
11
|
+
evidence: { type: "string", multiple: true },
|
|
12
|
+
"spec-status": { type: "string" },
|
|
13
|
+
"spec-note": { type: "string", multiple: true },
|
|
14
|
+
"quality-status": { type: "string" },
|
|
15
|
+
"quality-note": { type: "string", multiple: true },
|
|
16
|
+
"debug-note": { type: "string", multiple: true },
|
|
17
|
+
complete: { type: "boolean" },
|
|
18
|
+
blocked: { type: "boolean" },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const FEATURE_KEY_RE = /^[A-Z0-9_]+$/;
|
|
22
|
+
|
|
23
|
+
function cmdVerify(args) {
|
|
24
|
+
const { flags, positional } = parseFlags(args, FLAG_DEFS);
|
|
25
|
+
if (positional.length > 0) {
|
|
26
|
+
throw new ValidationError('Unexpected positional arguments. Use flags only for "verify".');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const featureKey = requireFlag(flags, "feature-key", "feature-key");
|
|
30
|
+
validatePattern(
|
|
31
|
+
featureKey,
|
|
32
|
+
FEATURE_KEY_RE,
|
|
33
|
+
"feature-key",
|
|
34
|
+
"Must use UPPER_SNAKE_CASE, for example ORDER_MGMT."
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const projectPath = flags["project-path"] ? path.resolve(flags["project-path"]) : process.cwd();
|
|
38
|
+
const result = runVerify(projectPath, featureKey, flags);
|
|
39
|
+
|
|
40
|
+
console.log("SDTK-CODE workflow verify");
|
|
41
|
+
console.log(` Feature key: ${featureKey}`);
|
|
42
|
+
console.log(` Lane: ${result.lane}`);
|
|
43
|
+
console.log(` Status: ${result.phaseStatus}`);
|
|
44
|
+
console.log(` Artifact: ${result.artifactPath}`);
|
|
45
|
+
console.log(` Evidence: ${result.evidenceCount}`);
|
|
46
|
+
console.log(
|
|
47
|
+
` Gates: evidence=${result.evidenceGate}, spec=${result.specGateStatus}, quality=${result.qualityGateStatus}`
|
|
48
|
+
);
|
|
49
|
+
console.log(` Next phase: ${result.nextPhase}`);
|
|
50
|
+
console.log(` Engine: ${result.suggestedEngineSkills.join(", ")}`);
|
|
51
|
+
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
cmdVerify,
|
|
57
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { cmdBuild } = require("./commands/build");
|
|
4
|
+
const { cmdHelp } = require("./commands/help");
|
|
5
|
+
const { cmdInit } = require("./commands/init");
|
|
6
|
+
const { cmdPlan } = require("./commands/plan");
|
|
7
|
+
const { cmdRuntime } = require("./commands/runtime");
|
|
8
|
+
const { cmdShip } = require("./commands/ship");
|
|
9
|
+
const { cmdStart } = require("./commands/start");
|
|
10
|
+
const { cmdVerify } = require("./commands/verify");
|
|
11
|
+
const { ValidationError } = require("./lib/errors");
|
|
12
|
+
|
|
13
|
+
function getVersion() {
|
|
14
|
+
const pkg = require("../package.json");
|
|
15
|
+
return pkg.version;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function parseCommand(argv) {
|
|
19
|
+
if (!argv || argv.length === 0) {
|
|
20
|
+
return { command: "help", args: [] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [first, ...rest] = argv;
|
|
24
|
+
if (first === "-h" || first === "--help") {
|
|
25
|
+
return { command: "help", args: [] };
|
|
26
|
+
}
|
|
27
|
+
if (first === "-v" || first === "--version") {
|
|
28
|
+
return { command: "version", args: [] };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { command: first, args: rest };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const COMMANDS = new Set(["help", "version", "init", "runtime", "start", "plan", "build", "verify", "ship"]);
|
|
35
|
+
|
|
36
|
+
async function run(argv) {
|
|
37
|
+
const { command, args } = parseCommand(argv);
|
|
38
|
+
|
|
39
|
+
if (!COMMANDS.has(command)) {
|
|
40
|
+
throw new ValidationError(
|
|
41
|
+
`Unknown command: "${command}". Run "sdtk-code --help" for available commands.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
switch (command) {
|
|
46
|
+
case "help":
|
|
47
|
+
return cmdHelp();
|
|
48
|
+
case "version":
|
|
49
|
+
console.log(`sdtk-code-kit ${getVersion()}`);
|
|
50
|
+
return 0;
|
|
51
|
+
case "init":
|
|
52
|
+
return cmdInit(args);
|
|
53
|
+
case "runtime":
|
|
54
|
+
return cmdRuntime(args);
|
|
55
|
+
case "start":
|
|
56
|
+
return cmdStart(args);
|
|
57
|
+
case "plan":
|
|
58
|
+
return cmdPlan(args);
|
|
59
|
+
case "build":
|
|
60
|
+
return cmdBuild(args);
|
|
61
|
+
case "verify":
|
|
62
|
+
return cmdVerify(args);
|
|
63
|
+
case "ship":
|
|
64
|
+
return cmdShip(args);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
run,
|
|
70
|
+
};
|
package/src/lib/args.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ValidationError } = require("./errors");
|
|
4
|
+
|
|
5
|
+
function parseFlags(argv, defs) {
|
|
6
|
+
const flags = {};
|
|
7
|
+
const positional = [];
|
|
8
|
+
const aliasMap = {};
|
|
9
|
+
|
|
10
|
+
for (const [name, def] of Object.entries(defs)) {
|
|
11
|
+
if (def.alias) {
|
|
12
|
+
aliasMap[def.alias] = name;
|
|
13
|
+
}
|
|
14
|
+
if (def.type === "boolean") {
|
|
15
|
+
flags[name] = false;
|
|
16
|
+
} else if (def.multiple) {
|
|
17
|
+
flags[name] = [];
|
|
18
|
+
} else {
|
|
19
|
+
flags[name] = undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < argv.length) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
|
|
27
|
+
if (!arg.startsWith("-")) {
|
|
28
|
+
positional.push(arg);
|
|
29
|
+
i++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let key;
|
|
34
|
+
let inlineValue;
|
|
35
|
+
if (arg.includes("=")) {
|
|
36
|
+
const eqIdx = arg.indexOf("=");
|
|
37
|
+
key = arg.slice(0, eqIdx);
|
|
38
|
+
inlineValue = arg.slice(eqIdx + 1);
|
|
39
|
+
} else {
|
|
40
|
+
key = arg;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const stripped = key.replace(/^-{1,2}/, "");
|
|
44
|
+
const resolved = aliasMap[stripped] || stripped;
|
|
45
|
+
if (!(resolved in defs)) {
|
|
46
|
+
throw new ValidationError(`Unknown flag: ${key}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const def = defs[resolved];
|
|
50
|
+
if (def.type === "boolean") {
|
|
51
|
+
flags[resolved] = true;
|
|
52
|
+
i++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let value = inlineValue;
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
i++;
|
|
59
|
+
if (i >= argv.length) {
|
|
60
|
+
throw new ValidationError(`Flag ${key} requires a value.`);
|
|
61
|
+
}
|
|
62
|
+
value = argv[i];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (def.multiple) {
|
|
66
|
+
flags[resolved].push(value);
|
|
67
|
+
} else {
|
|
68
|
+
flags[resolved] = value;
|
|
69
|
+
}
|
|
70
|
+
i++;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { flags, positional };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function requireFlag(flags, name, label) {
|
|
77
|
+
const value = flags[name];
|
|
78
|
+
if (value === undefined || value === null || value === "") {
|
|
79
|
+
throw new ValidationError(`Missing required flag: --${label || name}`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function validateChoice(value, choices, label) {
|
|
85
|
+
if (!choices.includes(value)) {
|
|
86
|
+
throw new ValidationError(
|
|
87
|
+
`Invalid value for --${label}: "${value}". Must be one of: ${choices.join(", ")}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function validatePattern(value, regex, label, hint) {
|
|
94
|
+
if (!regex.test(value)) {
|
|
95
|
+
throw new ValidationError(
|
|
96
|
+
`Invalid value for --${label}: "${value}". ${hint || `Must match ${regex}`}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
parseFlags,
|
|
104
|
+
requireFlag,
|
|
105
|
+
validateChoice,
|
|
106
|
+
validatePattern,
|
|
107
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class CliError extends Error {
|
|
4
|
+
constructor(message, exitCode = 4) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = this.constructor.name;
|
|
7
|
+
this.exitCode = exitCode;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class ValidationError extends CliError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class DependencyError extends CliError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message, 2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class IntegrityError extends CliError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message, 3);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class InternalError extends CliError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message, 4);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
CliError,
|
|
37
|
+
ValidationError,
|
|
38
|
+
DependencyError,
|
|
39
|
+
IntegrityError,
|
|
40
|
+
InternalError,
|
|
41
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { execFile } = require("child_process");
|
|
4
|
+
const { DependencyError } = require("./errors");
|
|
5
|
+
|
|
6
|
+
function findPowerShell() {
|
|
7
|
+
if (process.platform === "win32") {
|
|
8
|
+
return "powershell.exe";
|
|
9
|
+
}
|
|
10
|
+
return "pwsh";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function runScript(scriptPath, params = {}, options = {}) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const psExe = findPowerShell();
|
|
16
|
+
const args = [
|
|
17
|
+
"-ExecutionPolicy",
|
|
18
|
+
"Bypass",
|
|
19
|
+
"-NoProfile",
|
|
20
|
+
"-NonInteractive",
|
|
21
|
+
"-File",
|
|
22
|
+
scriptPath,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
for (const [key, value] of Object.entries(params)) {
|
|
26
|
+
if (value === true) {
|
|
27
|
+
args.push(`-${key}`);
|
|
28
|
+
} else if (value === false || value === undefined || value === null) {
|
|
29
|
+
continue;
|
|
30
|
+
} else {
|
|
31
|
+
args.push(`-${key}`);
|
|
32
|
+
args.push(String(value));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
execFile(psExe, args, { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
37
|
+
if (error && error.code === "ENOENT") {
|
|
38
|
+
reject(
|
|
39
|
+
new DependencyError(
|
|
40
|
+
`PowerShell not found. Ensure PowerShell is installed and available in PATH.\nTried: ${psExe}`
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const exitCode = error ? error.code || 1 : 0;
|
|
47
|
+
const result = {
|
|
48
|
+
exitCode: typeof exitCode === "number" ? exitCode : 1,
|
|
49
|
+
stdout: stdout || "",
|
|
50
|
+
stderr: stderr || "",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (!options.silent && result.stdout) {
|
|
54
|
+
process.stdout.write(result.stdout);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
resolve(result);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
findPowerShell,
|
|
64
|
+
runScript,
|
|
65
|
+
};
|
package/src/lib/scope.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const VALID_SCOPES = ["project", "user"];
|
|
7
|
+
|
|
8
|
+
function defaultScope(runtime) {
|
|
9
|
+
return runtime === "claude" ? "project" : "user";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isProjectScopeSupported(runtime) {
|
|
13
|
+
return runtime === "claude";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveSkillsDir(runtime, scope, projectPath) {
|
|
17
|
+
if (runtime === "claude") {
|
|
18
|
+
if (scope === "user") {
|
|
19
|
+
return path.join(os.homedir(), ".claude", "skills");
|
|
20
|
+
}
|
|
21
|
+
return path.join(projectPath || process.cwd(), ".claude", "skills");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
25
|
+
return path.join(codexHome, "skills");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const MANAGED_CLAUDE_SKILLS = [
|
|
29
|
+
"code-brainstorm",
|
|
30
|
+
"code-debug",
|
|
31
|
+
"code-discover",
|
|
32
|
+
"code-execute",
|
|
33
|
+
"code-finish",
|
|
34
|
+
"code-parallel",
|
|
35
|
+
"code-plan",
|
|
36
|
+
"code-review",
|
|
37
|
+
"code-ship",
|
|
38
|
+
"code-tdd",
|
|
39
|
+
"code-verify",
|
|
40
|
+
"code-worktree",
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const MANAGED_CODEX_SKILLS = MANAGED_CLAUDE_SKILLS.map((name) => `sdtk-${name}`);
|
|
44
|
+
|
|
45
|
+
function managedSkillNames(runtime) {
|
|
46
|
+
return runtime === "claude" ? MANAGED_CLAUDE_SKILLS : MANAGED_CODEX_SKILLS;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
VALID_SCOPES,
|
|
51
|
+
defaultScope,
|
|
52
|
+
isProjectScopeSupported,
|
|
53
|
+
resolveSkillsDir,
|
|
54
|
+
managedSkillNames,
|
|
55
|
+
};
|
|
@@ -0,0 +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
|
+
};
|