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.
Files changed (50) 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 +174 -0
  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 +257 -244
  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 -108
  24. package/src/lib/agent-team-export.js +409 -0
  25. package/src/lib/agent-team-plan.js +514 -0
  26. package/src/lib/args.js +107 -107
  27. package/src/lib/errors.js +41 -41
  28. package/src/lib/powershell.js +65 -65
  29. package/src/lib/project-target-guard.js +53 -53
  30. package/src/lib/scope.js +72 -72
  31. package/src/lib/ship-readiness.js +281 -281
  32. package/src/lib/sleep-plan.js +175 -175
  33. package/src/lib/sleep-report.js +229 -229
  34. package/src/lib/toolkit-payload.js +72 -72
  35. package/src/lib/trust-events.js +185 -166
  36. package/src/lib/trust-file-scope.js +154 -154
  37. package/src/lib/trust-policy.js +212 -212
  38. package/src/lib/trust-redact.js +35 -35
  39. package/src/lib/trust-trace.js +179 -179
  40. package/src/lib/update.js +344 -344
  41. package/src/lib/workflow-artifact.js +503 -503
  42. package/src/lib/workflow-build.js +127 -127
  43. package/src/lib/workflow-doctor.js +83 -83
  44. package/src/lib/workflow-handoff.js +1029 -1029
  45. package/src/lib/workflow-intake.js +101 -101
  46. package/src/lib/workflow-plan.js +193 -193
  47. package/src/lib/workflow-review-packet.js +650 -650
  48. package/src/lib/workflow-ship.js +213 -213
  49. package/src/lib/workflow-state.js +438 -438
  50. package/src/lib/workflow-verify.js +393 -393
@@ -1,212 +1,212 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { ValidationError } = require("./errors");
6
-
7
- // Default allow/ask/deny pack (BK-240 §5), derived from the reference harness
8
- // settings.json command classes. Patterns starting with "^" are treated as
9
- // anchored regular expressions; all other patterns are case-sensitive
10
- // substring matches against the command string. NO shell execution: this is
11
- // advisory classification only.
12
- const DEFAULT_POLICY = {
13
- deny: [
14
- "^rm -rf",
15
- "^rm -fr",
16
- "^sudo ",
17
- "git reset --hard",
18
- "git push --force",
19
- "git push -f",
20
- "mkfs",
21
- "^dd ",
22
- ".env",
23
- ".pem",
24
- "secrets/",
25
- "^psql",
26
- "^mysql",
27
- "^mongod",
28
- ],
29
- ask: [
30
- "npm install",
31
- "npm publish",
32
- "npm exec",
33
- "npx",
34
- "git merge",
35
- "git rebase",
36
- "git clean -fd",
37
- "git clean -fx",
38
- "git clean -fdx",
39
- ],
40
- allow: [
41
- "git status",
42
- "git diff",
43
- "git log",
44
- "git branch",
45
- "git show",
46
- "npm test",
47
- "npm run test",
48
- "npm run lint",
49
- "npm run build",
50
- "pytest",
51
- "python -m unittest",
52
- "rg ",
53
- "ls ",
54
- "node --check",
55
- ],
56
- // limits.max_actions is omitted by default; callers may add it (and supply
57
- // --action-count) to enable the action-count cap.
58
- limits: {},
59
- };
60
-
61
- function assertPatternArray(value, label) {
62
- if (!Array.isArray(value)) {
63
- throw new ValidationError(
64
- `Invalid trust policy: "${label}" must be an array of string patterns.`
65
- );
66
- }
67
- value.forEach((entry, index) => {
68
- if (typeof entry !== "string") {
69
- throw new ValidationError(
70
- `Invalid trust policy: "${label}[${index}]" must be a string pattern.`
71
- );
72
- }
73
- });
74
- }
75
-
76
- function validatePolicy(obj) {
77
- if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
78
- throw new ValidationError("Invalid trust policy: expected a JSON object.");
79
- }
80
- assertPatternArray(obj.deny, "deny");
81
- assertPatternArray(obj.ask, "ask");
82
- assertPatternArray(obj.allow, "allow");
83
-
84
- if (obj.limits !== undefined && obj.limits !== null) {
85
- if (typeof obj.limits !== "object" || Array.isArray(obj.limits)) {
86
- throw new ValidationError('Invalid trust policy: "limits" must be an object.');
87
- }
88
- if (
89
- obj.limits.max_actions !== undefined &&
90
- typeof obj.limits.max_actions !== "number"
91
- ) {
92
- throw new ValidationError(
93
- 'Invalid trust policy: "limits.max_actions" must be a number.'
94
- );
95
- }
96
- }
97
- return obj;
98
- }
99
-
100
- function policyFile(projectPath) {
101
- return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "policy.json");
102
- }
103
-
104
- function loadPolicy(projectPath) {
105
- const file = policyFile(projectPath);
106
- if (!fs.existsSync(file)) {
107
- return DEFAULT_POLICY;
108
- }
109
- let parsed;
110
- try {
111
- parsed = JSON.parse(fs.readFileSync(file, "utf8"));
112
- } catch (error) {
113
- throw new ValidationError(
114
- `Invalid trust policy: ${file} is not valid JSON (${error.message}).`
115
- );
116
- }
117
- return validatePolicy(parsed);
118
- }
119
-
120
- // Match a single pattern against the command string. "^"-prefixed patterns are
121
- // anchored regexes; everything else is a case-sensitive substring match. A
122
- // malformed regex pattern is treated as a non-match so classify never crashes.
123
- function matchesPattern(pattern, command) {
124
- if (typeof pattern !== "string" || pattern.length === 0) {
125
- return false;
126
- }
127
- if (pattern.startsWith("^")) {
128
- try {
129
- return new RegExp(pattern).test(command);
130
- } catch (_error) {
131
- return false;
132
- }
133
- }
134
- return command.includes(pattern);
135
- }
136
-
137
- function firstMatch(patterns, command) {
138
- if (!Array.isArray(patterns)) {
139
- return null;
140
- }
141
- for (const pattern of patterns) {
142
- if (matchesPattern(pattern, command)) {
143
- return pattern;
144
- }
145
- }
146
- return null;
147
- }
148
-
149
- // Classify a command as allow/ask/deny against a policy. Most-restrictive-wins,
150
- // deterministic. Stateless: the caller supplies opts.actionCount; trust-policy
151
- // performs no session counting. Never executes the command.
152
- function classifyCommand(policy, command, opts) {
153
- const cmd = typeof command === "string" ? command : "";
154
- const options = opts && typeof opts === "object" ? opts : {};
155
- const limits = policy && policy.limits && typeof policy.limits === "object" ? policy.limits : {};
156
-
157
- // 1. action-count cap.
158
- if (
159
- typeof options.actionCount === "number" &&
160
- typeof limits.max_actions === "number" &&
161
- options.actionCount >= limits.max_actions
162
- ) {
163
- return {
164
- verdict: "deny",
165
- reason: `action-count cap reached (${options.actionCount}/${limits.max_actions})`,
166
- matchedRule: { bucket: "limit", pattern: "limits.max_actions" },
167
- };
168
- }
169
-
170
- // 2. deny → 3. ask → 4. allow (first match wins per bucket).
171
- const denyHit = firstMatch(policy && policy.deny, cmd);
172
- if (denyHit) {
173
- return {
174
- verdict: "deny",
175
- reason: `denied by policy rule: ${denyHit}`,
176
- matchedRule: { bucket: "deny", pattern: denyHit },
177
- };
178
- }
179
-
180
- const askHit = firstMatch(policy && policy.ask, cmd);
181
- if (askHit) {
182
- return {
183
- verdict: "ask",
184
- reason: `requires confirmation by policy rule: ${askHit}`,
185
- matchedRule: { bucket: "ask", pattern: askHit },
186
- };
187
- }
188
-
189
- const allowHit = firstMatch(policy && policy.allow, cmd);
190
- if (allowHit) {
191
- return {
192
- verdict: "allow",
193
- reason: `allowed by policy rule: ${allowHit}`,
194
- matchedRule: { bucket: "allow", pattern: allowHit },
195
- };
196
- }
197
-
198
- // 5. no match → conservative ask.
199
- return {
200
- verdict: "ask",
201
- reason: "no matching allow rule; defaulting to ask (conservative)",
202
- matchedRule: null,
203
- };
204
- }
205
-
206
- module.exports = {
207
- DEFAULT_POLICY,
208
- loadPolicy,
209
- classifyCommand,
210
- validatePolicy,
211
- policyFile,
212
- };
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { ValidationError } = require("./errors");
6
+
7
+ // Default allow/ask/deny pack (BK-240 §5), derived from the reference harness
8
+ // settings.json command classes. Patterns starting with "^" are treated as
9
+ // anchored regular expressions; all other patterns are case-sensitive
10
+ // substring matches against the command string. NO shell execution: this is
11
+ // advisory classification only.
12
+ const DEFAULT_POLICY = {
13
+ deny: [
14
+ "^rm -rf",
15
+ "^rm -fr",
16
+ "^sudo ",
17
+ "git reset --hard",
18
+ "git push --force",
19
+ "git push -f",
20
+ "mkfs",
21
+ "^dd ",
22
+ ".env",
23
+ ".pem",
24
+ "secrets/",
25
+ "^psql",
26
+ "^mysql",
27
+ "^mongod",
28
+ ],
29
+ ask: [
30
+ "npm install",
31
+ "npm publish",
32
+ "npm exec",
33
+ "npx",
34
+ "git merge",
35
+ "git rebase",
36
+ "git clean -fd",
37
+ "git clean -fx",
38
+ "git clean -fdx",
39
+ ],
40
+ allow: [
41
+ "git status",
42
+ "git diff",
43
+ "git log",
44
+ "git branch",
45
+ "git show",
46
+ "npm test",
47
+ "npm run test",
48
+ "npm run lint",
49
+ "npm run build",
50
+ "pytest",
51
+ "python -m unittest",
52
+ "rg ",
53
+ "ls ",
54
+ "node --check",
55
+ ],
56
+ // limits.max_actions is omitted by default; callers may add it (and supply
57
+ // --action-count) to enable the action-count cap.
58
+ limits: {},
59
+ };
60
+
61
+ function assertPatternArray(value, label) {
62
+ if (!Array.isArray(value)) {
63
+ throw new ValidationError(
64
+ `Invalid trust policy: "${label}" must be an array of string patterns.`
65
+ );
66
+ }
67
+ value.forEach((entry, index) => {
68
+ if (typeof entry !== "string") {
69
+ throw new ValidationError(
70
+ `Invalid trust policy: "${label}[${index}]" must be a string pattern.`
71
+ );
72
+ }
73
+ });
74
+ }
75
+
76
+ function validatePolicy(obj) {
77
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
78
+ throw new ValidationError("Invalid trust policy: expected a JSON object.");
79
+ }
80
+ assertPatternArray(obj.deny, "deny");
81
+ assertPatternArray(obj.ask, "ask");
82
+ assertPatternArray(obj.allow, "allow");
83
+
84
+ if (obj.limits !== undefined && obj.limits !== null) {
85
+ if (typeof obj.limits !== "object" || Array.isArray(obj.limits)) {
86
+ throw new ValidationError('Invalid trust policy: "limits" must be an object.');
87
+ }
88
+ if (
89
+ obj.limits.max_actions !== undefined &&
90
+ typeof obj.limits.max_actions !== "number"
91
+ ) {
92
+ throw new ValidationError(
93
+ 'Invalid trust policy: "limits.max_actions" must be a number.'
94
+ );
95
+ }
96
+ }
97
+ return obj;
98
+ }
99
+
100
+ function policyFile(projectPath) {
101
+ return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "policy.json");
102
+ }
103
+
104
+ function loadPolicy(projectPath) {
105
+ const file = policyFile(projectPath);
106
+ if (!fs.existsSync(file)) {
107
+ return DEFAULT_POLICY;
108
+ }
109
+ let parsed;
110
+ try {
111
+ parsed = JSON.parse(fs.readFileSync(file, "utf8"));
112
+ } catch (error) {
113
+ throw new ValidationError(
114
+ `Invalid trust policy: ${file} is not valid JSON (${error.message}).`
115
+ );
116
+ }
117
+ return validatePolicy(parsed);
118
+ }
119
+
120
+ // Match a single pattern against the command string. "^"-prefixed patterns are
121
+ // anchored regexes; everything else is a case-sensitive substring match. A
122
+ // malformed regex pattern is treated as a non-match so classify never crashes.
123
+ function matchesPattern(pattern, command) {
124
+ if (typeof pattern !== "string" || pattern.length === 0) {
125
+ return false;
126
+ }
127
+ if (pattern.startsWith("^")) {
128
+ try {
129
+ return new RegExp(pattern).test(command);
130
+ } catch (_error) {
131
+ return false;
132
+ }
133
+ }
134
+ return command.includes(pattern);
135
+ }
136
+
137
+ function firstMatch(patterns, command) {
138
+ if (!Array.isArray(patterns)) {
139
+ return null;
140
+ }
141
+ for (const pattern of patterns) {
142
+ if (matchesPattern(pattern, command)) {
143
+ return pattern;
144
+ }
145
+ }
146
+ return null;
147
+ }
148
+
149
+ // Classify a command as allow/ask/deny against a policy. Most-restrictive-wins,
150
+ // deterministic. Stateless: the caller supplies opts.actionCount; trust-policy
151
+ // performs no session counting. Never executes the command.
152
+ function classifyCommand(policy, command, opts) {
153
+ const cmd = typeof command === "string" ? command : "";
154
+ const options = opts && typeof opts === "object" ? opts : {};
155
+ const limits = policy && policy.limits && typeof policy.limits === "object" ? policy.limits : {};
156
+
157
+ // 1. action-count cap.
158
+ if (
159
+ typeof options.actionCount === "number" &&
160
+ typeof limits.max_actions === "number" &&
161
+ options.actionCount >= limits.max_actions
162
+ ) {
163
+ return {
164
+ verdict: "deny",
165
+ reason: `action-count cap reached (${options.actionCount}/${limits.max_actions})`,
166
+ matchedRule: { bucket: "limit", pattern: "limits.max_actions" },
167
+ };
168
+ }
169
+
170
+ // 2. deny → 3. ask → 4. allow (first match wins per bucket).
171
+ const denyHit = firstMatch(policy && policy.deny, cmd);
172
+ if (denyHit) {
173
+ return {
174
+ verdict: "deny",
175
+ reason: `denied by policy rule: ${denyHit}`,
176
+ matchedRule: { bucket: "deny", pattern: denyHit },
177
+ };
178
+ }
179
+
180
+ const askHit = firstMatch(policy && policy.ask, cmd);
181
+ if (askHit) {
182
+ return {
183
+ verdict: "ask",
184
+ reason: `requires confirmation by policy rule: ${askHit}`,
185
+ matchedRule: { bucket: "ask", pattern: askHit },
186
+ };
187
+ }
188
+
189
+ const allowHit = firstMatch(policy && policy.allow, cmd);
190
+ if (allowHit) {
191
+ return {
192
+ verdict: "allow",
193
+ reason: `allowed by policy rule: ${allowHit}`,
194
+ matchedRule: { bucket: "allow", pattern: allowHit },
195
+ };
196
+ }
197
+
198
+ // 5. no match → conservative ask.
199
+ return {
200
+ verdict: "ask",
201
+ reason: "no matching allow rule; defaulting to ask (conservative)",
202
+ matchedRule: null,
203
+ };
204
+ }
205
+
206
+ module.exports = {
207
+ DEFAULT_POLICY,
208
+ loadPolicy,
209
+ classifyCommand,
210
+ validatePolicy,
211
+ policyFile,
212
+ };
@@ -1,35 +1,35 @@
1
- "use strict";
2
-
3
- const PRIVATE_TAG_PATTERN = /<private>[\s\S]*?<\/private>/gi;
4
-
5
- const SECRET_PATTERNS = [
6
- /(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{20,}["']?/gi,
7
- /Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi,
8
- /sk-proj-[A-Za-z0-9\-_]{20,}/g,
9
- /(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g,
10
- /sk-ant-[A-Za-z0-9\-_]{20,}/g,
11
- /gh[pus]_[A-Za-z0-9]{36,}/g,
12
- /github_pat_[A-Za-z0-9_]{22,}/g,
13
- /xoxb-[A-Za-z0-9\-]+/g,
14
- /AKIA[0-9A-Z]{16}/g,
15
- /AIza[A-Za-z0-9\-_]{35}/g,
16
- /eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
17
- /npm_[A-Za-z0-9]{36}/g,
18
- /glpat-[A-Za-z0-9\-_]{20,}/g,
19
- /dop_v1_[A-Za-z0-9]{64}/g,
20
- ];
21
-
22
- function redact(input) {
23
- if (typeof input !== "string") {
24
- return "";
25
- }
26
-
27
- let result = input.replace(PRIVATE_TAG_PATTERN, "[REDACTED]");
28
- for (const source of SECRET_PATTERNS) {
29
- const pattern = new RegExp(source.source, source.flags);
30
- result = result.replace(pattern, "[REDACTED_SECRET]");
31
- }
32
- return result;
33
- }
34
-
35
- module.exports = { redact, SECRET_PATTERNS };
1
+ "use strict";
2
+
3
+ const PRIVATE_TAG_PATTERN = /<private>[\s\S]*?<\/private>/gi;
4
+
5
+ const SECRET_PATTERNS = [
6
+ /(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{20,}["']?/gi,
7
+ /Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi,
8
+ /sk-proj-[A-Za-z0-9\-_]{20,}/g,
9
+ /(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g,
10
+ /sk-ant-[A-Za-z0-9\-_]{20,}/g,
11
+ /gh[pus]_[A-Za-z0-9]{36,}/g,
12
+ /github_pat_[A-Za-z0-9_]{22,}/g,
13
+ /xoxb-[A-Za-z0-9\-]+/g,
14
+ /AKIA[0-9A-Z]{16}/g,
15
+ /AIza[A-Za-z0-9\-_]{35}/g,
16
+ /eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
17
+ /npm_[A-Za-z0-9]{36}/g,
18
+ /glpat-[A-Za-z0-9\-_]{20,}/g,
19
+ /dop_v1_[A-Za-z0-9]{64}/g,
20
+ ];
21
+
22
+ function redact(input) {
23
+ if (typeof input !== "string") {
24
+ return "";
25
+ }
26
+
27
+ let result = input.replace(PRIVATE_TAG_PATTERN, "[REDACTED]");
28
+ for (const source of SECRET_PATTERNS) {
29
+ const pattern = new RegExp(source.source, source.flags);
30
+ result = result.replace(pattern, "[REDACTED_SECRET]");
31
+ }
32
+ return result;
33
+ }
34
+
35
+ module.exports = { redact, SECRET_PATTERNS };