sdtk-code-kit 0.3.0 → 0.3.2
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 +479 -174
- 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 +266 -257
- 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 -112
- package/src/lib/agent-team-author.js +552 -0
- package/src/lib/agent-team-evidence.js +302 -0
- package/src/lib/agent-team-execute.js +892 -0
- package/src/lib/agent-team-export.js +411 -409
- package/src/lib/agent-team-plan.js +514 -514
- package/src/lib/agent-team-readiness.js +161 -0
- package/src/lib/agent-team-report.js +165 -0
- package/src/lib/agent-team-sleep-execute.js +524 -0
- package/src/lib/agent-team-sleep-session.js +278 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/model-provider.js +219 -0
- 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 +264 -185
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +58 -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
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const { URL } = require("url");
|
|
5
|
+
const { ValidationError } = require("./errors");
|
|
6
|
+
|
|
7
|
+
const MODEL_MAX_CALLS_PER_RUN = 1;
|
|
8
|
+
const MODEL_CALL_TIMEOUT_MS = 120000;
|
|
9
|
+
const MODEL_WALLCLOCK_TIMEOUT_MS = 300000;
|
|
10
|
+
const MODEL_MAX_OUTPUT_TOKENS = 16000;
|
|
11
|
+
const CONTEXT_MAX_FILES = 20;
|
|
12
|
+
const CONTEXT_MAX_BYTES = 262144;
|
|
13
|
+
const MODEL_EGRESS_ALLOWLIST = Object.freeze(["api.anthropic.com"]);
|
|
14
|
+
const MODEL_ID = "claude-sonnet-4-6";
|
|
15
|
+
const MODEL_PRICE_INPUT_USD_PER_MTOK = 3.00;
|
|
16
|
+
const MODEL_PRICE_OUTPUT_USD_PER_MTOK = 15.00;
|
|
17
|
+
const MODEL_PRICING_SOURCE_DATE = "2026-05-26";
|
|
18
|
+
const MODEL_MAX_COST_USD = 1.00;
|
|
19
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
20
|
+
const DEFAULT_PROVIDER = "claude";
|
|
21
|
+
|
|
22
|
+
const MODEL_PRICING = Object.freeze({
|
|
23
|
+
[MODEL_ID]: Object.freeze({
|
|
24
|
+
input_usd_per_mtok: MODEL_PRICE_INPUT_USD_PER_MTOK,
|
|
25
|
+
output_usd_per_mtok: MODEL_PRICE_OUTPUT_USD_PER_MTOK,
|
|
26
|
+
source_date: MODEL_PRICING_SOURCE_DATE,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function estimateTokensFromText(text) {
|
|
31
|
+
return Math.ceil(Buffer.byteLength(String(text || ""), "utf8") / 4);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function projectedCostUsd(modelId, inputTokenEstimate, maxOutputTokens) {
|
|
35
|
+
const pricing = MODEL_PRICING[modelId];
|
|
36
|
+
if (!pricing) {
|
|
37
|
+
throw new ValidationError(`FAIL_MODEL_PRICING_UNKNOWN: no pinned pricing for model_id ${modelId}`);
|
|
38
|
+
}
|
|
39
|
+
const inputCost = (Number(inputTokenEstimate || 0) / 1000000) * pricing.input_usd_per_mtok;
|
|
40
|
+
const outputCost = (Number(maxOutputTokens || 0) / 1000000) * pricing.output_usd_per_mtok;
|
|
41
|
+
return Number((inputCost + outputCost).toFixed(6));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function assertCostWithinCap(modelId, inputTokenEstimate, maxOutputTokens) {
|
|
45
|
+
const cost = projectedCostUsd(modelId, inputTokenEstimate, maxOutputTokens);
|
|
46
|
+
if (cost > MODEL_MAX_COST_USD) {
|
|
47
|
+
throw new ValidationError(`FAIL_MODEL_COST_CAP: projected model cost ${cost} exceeds cap ${MODEL_MAX_COST_USD}`);
|
|
48
|
+
}
|
|
49
|
+
return cost;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function assertAllowedHost(hostname) {
|
|
53
|
+
if (!MODEL_EGRESS_ALLOWLIST.includes(String(hostname || ""))) {
|
|
54
|
+
throw new ValidationError(`FAIL_EGRESS_HOST_NOT_ALLOWED: ${hostname || "(missing host)"}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseEndpoint(endpoint) {
|
|
59
|
+
const url = new URL(endpoint || "https://api.anthropic.com/v1/messages");
|
|
60
|
+
if (url.protocol !== "https:") {
|
|
61
|
+
throw new ValidationError("FAIL_EGRESS_HOST_NOT_ALLOWED: model egress requires https");
|
|
62
|
+
}
|
|
63
|
+
assertAllowedHost(url.hostname);
|
|
64
|
+
return url;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function defaultHttpsTransport(options, body, timeoutMs) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const req = https.request(options, (res) => {
|
|
70
|
+
let data = "";
|
|
71
|
+
res.setEncoding("utf8");
|
|
72
|
+
res.on("data", (chunk) => { data += chunk; });
|
|
73
|
+
res.on("end", () => resolve({
|
|
74
|
+
statusCode: res.statusCode || 0,
|
|
75
|
+
headers: res.headers || {},
|
|
76
|
+
body: data,
|
|
77
|
+
connectionHost: options.hostname,
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
req.setTimeout(timeoutMs, () => {
|
|
81
|
+
req.destroy(new Error("FAIL_MODEL_TIMEOUT: model call timed out"));
|
|
82
|
+
});
|
|
83
|
+
req.on("error", reject);
|
|
84
|
+
req.write(body);
|
|
85
|
+
req.end();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function responseText(payload) {
|
|
90
|
+
if (!payload || typeof payload !== "object") return "";
|
|
91
|
+
if (typeof payload.patch === "string") return payload.patch;
|
|
92
|
+
if (typeof payload.text === "string") return payload.text;
|
|
93
|
+
if (Array.isArray(payload.content)) {
|
|
94
|
+
return payload.content.map((part) => {
|
|
95
|
+
if (part && typeof part.text === "string") return part.text;
|
|
96
|
+
return "";
|
|
97
|
+
}).join("\n").trim();
|
|
98
|
+
}
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function usageFromPayload(payload) {
|
|
103
|
+
const usage = payload && typeof payload === "object" && payload.usage && typeof payload.usage === "object"
|
|
104
|
+
? payload.usage : {};
|
|
105
|
+
return {
|
|
106
|
+
input_tokens: typeof usage.input_tokens === "number" ? usage.input_tokens : null,
|
|
107
|
+
output_tokens: typeof usage.output_tokens === "number" ? usage.output_tokens : null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function callModelProvider(request, deps) {
|
|
112
|
+
const req = request || {};
|
|
113
|
+
const options = deps || {};
|
|
114
|
+
const modelId = req.model_id || MODEL_ID;
|
|
115
|
+
const provider = req.provider || DEFAULT_PROVIDER;
|
|
116
|
+
const maxOutputTokens = Number(req.max_output_tokens || MODEL_MAX_OUTPUT_TOKENS);
|
|
117
|
+
if (provider !== DEFAULT_PROVIDER) {
|
|
118
|
+
throw new ValidationError(`FAIL_EGRESS_HOST_NOT_ALLOWED: unsupported provider ${provider}`);
|
|
119
|
+
}
|
|
120
|
+
if (modelId !== MODEL_ID) {
|
|
121
|
+
projectedCostUsd(modelId, 0, maxOutputTokens);
|
|
122
|
+
}
|
|
123
|
+
if (maxOutputTokens > MODEL_MAX_OUTPUT_TOKENS) {
|
|
124
|
+
throw new ValidationError(`FAIL_MODEL_OUTPUT_TOKEN_CAP: max_output_tokens ${maxOutputTokens} exceeds ${MODEL_MAX_OUTPUT_TOKENS}`);
|
|
125
|
+
}
|
|
126
|
+
if (Number(req.call_count || 1) > MODEL_MAX_CALLS_PER_RUN) {
|
|
127
|
+
throw new ValidationError("FAIL_MODEL_CALL_LIMIT: only one model call is allowed per run");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const prompt = String(req.prompt || "");
|
|
131
|
+
const inputTokens = typeof req.input_token_estimate === "number" ? req.input_token_estimate : estimateTokensFromText(prompt);
|
|
132
|
+
const projectedCost = assertCostWithinCap(modelId, inputTokens, maxOutputTokens);
|
|
133
|
+
|
|
134
|
+
const env = options.env || process.env;
|
|
135
|
+
const apiKey = options.apiKey || env.ANTHROPIC_API_KEY;
|
|
136
|
+
if (!apiKey) {
|
|
137
|
+
throw new ValidationError("FAIL_MODEL_CREDENTIAL_MISSING: ANTHROPIC_API_KEY is required for --execute author mode");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const endpoint = parseEndpoint(req.endpoint || "https://api.anthropic.com/v1/messages");
|
|
141
|
+
const body = JSON.stringify({
|
|
142
|
+
model: modelId,
|
|
143
|
+
max_tokens: maxOutputTokens,
|
|
144
|
+
messages: [{ role: "user", content: prompt }],
|
|
145
|
+
});
|
|
146
|
+
const transport = options.transport || defaultHttpsTransport;
|
|
147
|
+
const transportOptions = {
|
|
148
|
+
protocol: "https:",
|
|
149
|
+
hostname: endpoint.hostname,
|
|
150
|
+
port: endpoint.port || 443,
|
|
151
|
+
method: "POST",
|
|
152
|
+
path: `${endpoint.pathname}${endpoint.search}`,
|
|
153
|
+
headers: {
|
|
154
|
+
"content-type": "application/json",
|
|
155
|
+
"content-length": Buffer.byteLength(body),
|
|
156
|
+
"x-api-key": apiKey,
|
|
157
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const response = await transport(transportOptions, body, MODEL_CALL_TIMEOUT_MS);
|
|
162
|
+
assertAllowedHost(response && response.connectionHost ? response.connectionHost : transportOptions.hostname);
|
|
163
|
+
const statusCode = Number(response && response.statusCode || 0);
|
|
164
|
+
if (statusCode >= 300 && statusCode < 400) {
|
|
165
|
+
const location = response.headers && response.headers.location;
|
|
166
|
+
if (location) {
|
|
167
|
+
const redirect = new URL(location, endpoint);
|
|
168
|
+
assertAllowedHost(redirect.hostname);
|
|
169
|
+
}
|
|
170
|
+
throw new ValidationError("FAIL_EGRESS_HOST_NOT_ALLOWED: redirects are not followed in D-2b");
|
|
171
|
+
}
|
|
172
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
173
|
+
throw new ValidationError(`FAIL_MODEL_PROVIDER_ERROR: provider status ${statusCode}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let payload;
|
|
177
|
+
try {
|
|
178
|
+
payload = JSON.parse(response.body || "{}");
|
|
179
|
+
} catch (_error) {
|
|
180
|
+
throw new ValidationError("FAIL_MODEL_PROVIDER_ERROR: provider returned invalid JSON");
|
|
181
|
+
}
|
|
182
|
+
const patch = responseText(payload);
|
|
183
|
+
const tokensUsed = usageFromPayload(payload);
|
|
184
|
+
if (tokensUsed.output_tokens != null && tokensUsed.output_tokens > MODEL_MAX_OUTPUT_TOKENS) {
|
|
185
|
+
throw new ValidationError(`FAIL_MODEL_OUTPUT_TOKEN_CAP: output tokens ${tokensUsed.output_tokens} exceeds ${MODEL_MAX_OUTPUT_TOKENS}`);
|
|
186
|
+
}
|
|
187
|
+
if (!patch) {
|
|
188
|
+
throw new ValidationError("FAIL_MODEL_PROVIDER_ERROR: provider returned no patch text");
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
provider,
|
|
192
|
+
model_id: modelId,
|
|
193
|
+
patch,
|
|
194
|
+
tokens_used: tokensUsed,
|
|
195
|
+
projected_cost_usd: projectedCost,
|
|
196
|
+
model_call_count: 1,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
module.exports = {
|
|
201
|
+
MODEL_MAX_CALLS_PER_RUN,
|
|
202
|
+
MODEL_CALL_TIMEOUT_MS,
|
|
203
|
+
MODEL_WALLCLOCK_TIMEOUT_MS,
|
|
204
|
+
MODEL_MAX_OUTPUT_TOKENS,
|
|
205
|
+
CONTEXT_MAX_FILES,
|
|
206
|
+
CONTEXT_MAX_BYTES,
|
|
207
|
+
MODEL_EGRESS_ALLOWLIST,
|
|
208
|
+
MODEL_ID,
|
|
209
|
+
MODEL_PRICE_INPUT_USD_PER_MTOK,
|
|
210
|
+
MODEL_PRICE_OUTPUT_USD_PER_MTOK,
|
|
211
|
+
MODEL_PRICING_SOURCE_DATE,
|
|
212
|
+
MODEL_MAX_COST_USD,
|
|
213
|
+
MODEL_PRICING,
|
|
214
|
+
estimateTokensFromText,
|
|
215
|
+
projectedCostUsd,
|
|
216
|
+
assertCostWithinCap,
|
|
217
|
+
assertAllowedHost,
|
|
218
|
+
callModelProvider,
|
|
219
|
+
};
|
package/src/lib/powershell.js
CHANGED
|
@@ -1,65 +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
|
-
};
|
|
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
|
+
};
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { ValidationError } = require("./errors");
|
|
6
|
-
|
|
7
|
-
const MAINTAINER_ROOT_MARKERS = [
|
|
8
|
-
"governance/ai/core/IMPROVEMENT_BACKLOG.md",
|
|
9
|
-
"products/sdtk-code/toolkit/install.ps1",
|
|
10
|
-
];
|
|
11
|
-
const PROTECTED_FILES = [
|
|
12
|
-
"AGENTS.md",
|
|
13
|
-
"CODEX.md",
|
|
14
|
-
"CLAUDE.md",
|
|
15
|
-
"sdtk-spec.config.json",
|
|
16
|
-
"sdtk-spec.config.profiles.example.json"
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
function isMaintainerRoot(projectPath) {
|
|
20
|
-
const resolved = path.resolve(projectPath);
|
|
21
|
-
return MAINTAINER_ROOT_MARKERS.every((marker) => fs.existsSync(path.join(resolved, marker)));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildMaintainerRootMessage(cliName, action, projectPath) {
|
|
25
|
-
const lines = [
|
|
26
|
-
`Refusing to refresh managed project files into the SDTK maintainer repo root: ${projectPath}`,
|
|
27
|
-
`The ${action} flow would overwrite repo-owned files such as ${PROTECTED_FILES.join(", ")}.`,
|
|
28
|
-
"Target a consumer project path instead of the SDTK maintainer monorepo root.",
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
if (action === "update") {
|
|
32
|
-
lines.push(`If you only need package/runtime refresh, rerun ${cliName} update with --skip-project-files.`);
|
|
33
|
-
} else {
|
|
34
|
-
lines.push(`If you only need runtime assets, use ${cliName} runtime install against the desired consumer project path instead of ${cliName} init.`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return lines.join("\n");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function assertProjectRefreshTargetAllowed(cliName, action, projectPath) {
|
|
41
|
-
if (!isMaintainerRoot(projectPath)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw new ValidationError(buildMaintainerRootMessage(cliName, action, projectPath));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
assertProjectRefreshTargetAllowed,
|
|
50
|
-
buildMaintainerRootMessage,
|
|
51
|
-
isMaintainerRoot,
|
|
52
|
-
};
|
|
53
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { ValidationError } = require("./errors");
|
|
6
|
+
|
|
7
|
+
const MAINTAINER_ROOT_MARKERS = [
|
|
8
|
+
"governance/ai/core/IMPROVEMENT_BACKLOG.md",
|
|
9
|
+
"products/sdtk-code/toolkit/install.ps1",
|
|
10
|
+
];
|
|
11
|
+
const PROTECTED_FILES = [
|
|
12
|
+
"AGENTS.md",
|
|
13
|
+
"CODEX.md",
|
|
14
|
+
"CLAUDE.md",
|
|
15
|
+
"sdtk-spec.config.json",
|
|
16
|
+
"sdtk-spec.config.profiles.example.json"
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function isMaintainerRoot(projectPath) {
|
|
20
|
+
const resolved = path.resolve(projectPath);
|
|
21
|
+
return MAINTAINER_ROOT_MARKERS.every((marker) => fs.existsSync(path.join(resolved, marker)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildMaintainerRootMessage(cliName, action, projectPath) {
|
|
25
|
+
const lines = [
|
|
26
|
+
`Refusing to refresh managed project files into the SDTK maintainer repo root: ${projectPath}`,
|
|
27
|
+
`The ${action} flow would overwrite repo-owned files such as ${PROTECTED_FILES.join(", ")}.`,
|
|
28
|
+
"Target a consumer project path instead of the SDTK maintainer monorepo root.",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (action === "update") {
|
|
32
|
+
lines.push(`If you only need package/runtime refresh, rerun ${cliName} update with --skip-project-files.`);
|
|
33
|
+
} else {
|
|
34
|
+
lines.push(`If you only need runtime assets, use ${cliName} runtime install against the desired consumer project path instead of ${cliName} init.`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return lines.join("\n");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertProjectRefreshTargetAllowed(cliName, action, projectPath) {
|
|
41
|
+
if (!isMaintainerRoot(projectPath)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new ValidationError(buildMaintainerRootMessage(cliName, action, projectPath));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
assertProjectRefreshTargetAllowed,
|
|
50
|
+
buildMaintainerRootMessage,
|
|
51
|
+
isMaintainerRoot,
|
|
52
|
+
};
|
|
53
|
+
|
package/src/lib/scope.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
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" || runtime === "codex";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function resolveCodexProjectHome(projectPath) {
|
|
17
|
-
return path.join(projectPath || process.cwd(), ".codex");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function resolveCodexUserHome() {
|
|
21
|
-
return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function resolveCodexHome(scope, projectPath) {
|
|
25
|
-
return scope === "project"
|
|
26
|
-
? resolveCodexProjectHome(projectPath)
|
|
27
|
-
: resolveCodexUserHome();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function resolveSkillsDir(runtime, scope, projectPath) {
|
|
31
|
-
if (runtime === "claude") {
|
|
32
|
-
if (scope === "user") {
|
|
33
|
-
return path.join(os.homedir(), ".claude", "skills");
|
|
34
|
-
}
|
|
35
|
-
return path.join(projectPath || process.cwd(), ".claude", "skills");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const codexHome = resolveCodexHome(scope, projectPath);
|
|
39
|
-
return path.join(codexHome, "skills");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const MANAGED_CLAUDE_SKILLS = [
|
|
43
|
-
"code-brainstorm",
|
|
44
|
-
"code-debug",
|
|
45
|
-
"code-discover",
|
|
46
|
-
"code-execute",
|
|
47
|
-
"code-finish",
|
|
48
|
-
"code-parallel",
|
|
49
|
-
"code-plan",
|
|
50
|
-
"code-review",
|
|
51
|
-
"code-ship",
|
|
52
|
-
"code-tdd",
|
|
53
|
-
"code-verify",
|
|
54
|
-
"code-worktree",
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const MANAGED_CODEX_SKILLS = MANAGED_CLAUDE_SKILLS.map((name) => `sdtk-${name}`);
|
|
58
|
-
|
|
59
|
-
function managedSkillNames(runtime) {
|
|
60
|
-
return runtime === "claude" ? MANAGED_CLAUDE_SKILLS : MANAGED_CODEX_SKILLS;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = {
|
|
64
|
-
VALID_SCOPES,
|
|
65
|
-
defaultScope,
|
|
66
|
-
isProjectScopeSupported,
|
|
67
|
-
resolveCodexHome,
|
|
68
|
-
resolveCodexProjectHome,
|
|
69
|
-
resolveCodexUserHome,
|
|
70
|
-
resolveSkillsDir,
|
|
71
|
-
managedSkillNames,
|
|
72
|
-
};
|
|
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" || runtime === "codex";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveCodexProjectHome(projectPath) {
|
|
17
|
+
return path.join(projectPath || process.cwd(), ".codex");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resolveCodexUserHome() {
|
|
21
|
+
return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveCodexHome(scope, projectPath) {
|
|
25
|
+
return scope === "project"
|
|
26
|
+
? resolveCodexProjectHome(projectPath)
|
|
27
|
+
: resolveCodexUserHome();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolveSkillsDir(runtime, scope, projectPath) {
|
|
31
|
+
if (runtime === "claude") {
|
|
32
|
+
if (scope === "user") {
|
|
33
|
+
return path.join(os.homedir(), ".claude", "skills");
|
|
34
|
+
}
|
|
35
|
+
return path.join(projectPath || process.cwd(), ".claude", "skills");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const codexHome = resolveCodexHome(scope, projectPath);
|
|
39
|
+
return path.join(codexHome, "skills");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MANAGED_CLAUDE_SKILLS = [
|
|
43
|
+
"code-brainstorm",
|
|
44
|
+
"code-debug",
|
|
45
|
+
"code-discover",
|
|
46
|
+
"code-execute",
|
|
47
|
+
"code-finish",
|
|
48
|
+
"code-parallel",
|
|
49
|
+
"code-plan",
|
|
50
|
+
"code-review",
|
|
51
|
+
"code-ship",
|
|
52
|
+
"code-tdd",
|
|
53
|
+
"code-verify",
|
|
54
|
+
"code-worktree",
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const MANAGED_CODEX_SKILLS = MANAGED_CLAUDE_SKILLS.map((name) => `sdtk-${name}`);
|
|
58
|
+
|
|
59
|
+
function managedSkillNames(runtime) {
|
|
60
|
+
return runtime === "claude" ? MANAGED_CLAUDE_SKILLS : MANAGED_CODEX_SKILLS;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
VALID_SCOPES,
|
|
65
|
+
defaultScope,
|
|
66
|
+
isProjectScopeSupported,
|
|
67
|
+
resolveCodexHome,
|
|
68
|
+
resolveCodexProjectHome,
|
|
69
|
+
resolveCodexUserHome,
|
|
70
|
+
resolveSkillsDir,
|
|
71
|
+
managedSkillNames,
|
|
72
|
+
};
|