opencode-agent-orchestration-kit 1.0.27 → 1.0.29
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 +27 -14
- package/compatibility.json +19 -0
- package/docker/open-design/Dockerfile +2 -2
- package/docs/compatibility.md +104 -0
- package/docs/docker-open-design.md +8 -0
- package/docs/installation.md +13 -3
- package/docs/quickstart.md +6 -3
- package/docs/releases/v1.0.28.md +71 -0
- package/docs/releases/v1.0.29.md +78 -0
- package/docs/security.md +9 -0
- package/docs/superpowers/plans/2026-07-21-compatibility-matrix.md +1286 -0
- package/docs/superpowers/specs/2026-07-21-compatibility-matrix-design.md +452 -0
- package/docs/superpowers.md +11 -4
- package/docs/supply-chain.md +145 -0
- package/docs/workflows.md +15 -0
- package/opencode/opencode.json +1 -1
- package/opencode/package-lock.json +96 -96
- package/opencode/package.json +5 -1
- package/package.json +29 -3
- package/scripts/check-compatibility.mjs +676 -0
- package/scripts/check-compatibility.test.mjs +1467 -0
- package/scripts/check-supply-chain.mjs +635 -0
- package/scripts/check-supply-chain.test.mjs +944 -0
- package/scripts/check.sh +15 -5
- package/scripts/install-smoke.sh +1 -1
- package/scripts/opencode-compat-smoke.sh +264 -0
- package/scripts/package-smoke.mjs +357 -0
- package/scripts/package-smoke.sh +5 -0
- package/scripts/package-smoke.test.mjs +256 -0
- package/scripts/version.mjs +18 -5
- package/scripts/version.test.mjs +53 -3
- package/supply-chain.json +34 -0
- package/.github/CODEOWNERS +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -65
- package/.github/ISSUE_TEMPLATE/config.yml +0 -11
- package/.github/ISSUE_TEMPLATE/documentation.yml +0 -22
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -43
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -25
- package/.github/workflows/check.yml +0 -47
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
import { parseStableVersion } from "./version.mjs";
|
|
8
|
+
|
|
9
|
+
const SCRIPT_PATH = fileURLToPath(import.meta.url);
|
|
10
|
+
const REPOSITORY_ROOT = path.dirname(path.dirname(SCRIPT_PATH));
|
|
11
|
+
const EXACT_KEYS = {
|
|
12
|
+
root: ["schema_version", "external_refs", "npm_overrides"],
|
|
13
|
+
externalRefs: [
|
|
14
|
+
"superpowers",
|
|
15
|
+
"actions_checkout",
|
|
16
|
+
"actions_setup_node",
|
|
17
|
+
"open_design",
|
|
18
|
+
"node_image",
|
|
19
|
+
"pnpm",
|
|
20
|
+
"opencode_ai",
|
|
21
|
+
],
|
|
22
|
+
integration: ["release", "commit"],
|
|
23
|
+
action: ["release", "commit"],
|
|
24
|
+
commit: ["commit"],
|
|
25
|
+
image: ["tag", "digest"],
|
|
26
|
+
version: ["version"],
|
|
27
|
+
overrides: ["@babel/core", "uuid"],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const COMMIT = /^[0-9a-f]{40}$/;
|
|
31
|
+
const DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
32
|
+
const ACTION_RELEASE = /^v[1-9][0-9]*$/;
|
|
33
|
+
const NODE_IMAGE_TAG = /^[1-9][0-9]*-bookworm-slim$/;
|
|
34
|
+
const PACKAGE_FILES = [
|
|
35
|
+
"CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "NOTICE.md", "README.md",
|
|
36
|
+
"SECURITY.md", "compatibility.json", "docker/", "docs/", "doctor.sh",
|
|
37
|
+
"env.example", "install.sh", "opencode/", "rollback.sh", "scripts/",
|
|
38
|
+
"supply-chain.json", "uninstall.sh", "upgrade.sh",
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
function invalid(message) {
|
|
42
|
+
const error = new Error(message);
|
|
43
|
+
error.code = "INVALID_SUPPLY_CHAIN";
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function assertExactKeys(value, expected, label) {
|
|
48
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
49
|
+
throw invalid(`${label} must be an object`);
|
|
50
|
+
}
|
|
51
|
+
const actual = Object.keys(value).sort();
|
|
52
|
+
const wanted = [...expected].sort();
|
|
53
|
+
if (JSON.stringify(actual) !== JSON.stringify(wanted)) {
|
|
54
|
+
throw invalid(`${label} keys must be exactly: ${wanted.join(", ")}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function assertCommit(value, field) {
|
|
59
|
+
if (typeof value !== "string" || !COMMIT.test(value)) {
|
|
60
|
+
throw invalid(`${field} must be a lowercase 40-character commit`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function assertStableVersion(value, field) {
|
|
65
|
+
try {
|
|
66
|
+
parseStableVersion(value);
|
|
67
|
+
} catch {
|
|
68
|
+
throw invalid(`${field} must use canonical MAJOR.MINOR.PATCH syntax`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function validateSupplyChainData(data) {
|
|
73
|
+
assertExactKeys(data, EXACT_KEYS.root, "supply chain");
|
|
74
|
+
assertExactKeys(data.external_refs, EXACT_KEYS.externalRefs, "external_refs");
|
|
75
|
+
assertExactKeys(data.external_refs.superpowers, EXACT_KEYS.integration, "external_refs.superpowers");
|
|
76
|
+
assertExactKeys(data.external_refs.actions_checkout, EXACT_KEYS.action, "external_refs.actions_checkout");
|
|
77
|
+
assertExactKeys(data.external_refs.actions_setup_node, EXACT_KEYS.action, "external_refs.actions_setup_node");
|
|
78
|
+
assertExactKeys(data.external_refs.open_design, EXACT_KEYS.commit, "external_refs.open_design");
|
|
79
|
+
assertExactKeys(data.external_refs.node_image, EXACT_KEYS.image, "external_refs.node_image");
|
|
80
|
+
assertExactKeys(data.external_refs.pnpm, EXACT_KEYS.version, "external_refs.pnpm");
|
|
81
|
+
assertExactKeys(data.external_refs.opencode_ai, EXACT_KEYS.version, "external_refs.opencode_ai");
|
|
82
|
+
assertExactKeys(data.npm_overrides, EXACT_KEYS.overrides, "npm_overrides");
|
|
83
|
+
|
|
84
|
+
if (data.schema_version !== 1) throw invalid("schema_version must be 1");
|
|
85
|
+
|
|
86
|
+
const superpowers = data.external_refs.superpowers;
|
|
87
|
+
if (typeof superpowers.release !== "string" || !superpowers.release.startsWith("v")) {
|
|
88
|
+
throw invalid("external_refs.superpowers.release must use canonical vMAJOR.MINOR.PATCH syntax");
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
parseStableVersion(superpowers.release.slice(1));
|
|
92
|
+
} catch {
|
|
93
|
+
throw invalid("external_refs.superpowers.release must use canonical vMAJOR.MINOR.PATCH syntax");
|
|
94
|
+
}
|
|
95
|
+
assertCommit(superpowers.commit, "external_refs.superpowers.commit");
|
|
96
|
+
|
|
97
|
+
for (const field of ["actions_checkout", "actions_setup_node"]) {
|
|
98
|
+
const action = data.external_refs[field];
|
|
99
|
+
if (typeof action.release !== "string" || !ACTION_RELEASE.test(action.release)) {
|
|
100
|
+
throw invalid(`external_refs.${field}.release must use v<positive major>`);
|
|
101
|
+
}
|
|
102
|
+
assertCommit(action.commit, `external_refs.${field}.commit`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
assertCommit(data.external_refs.open_design.commit, "external_refs.open_design.commit");
|
|
106
|
+
|
|
107
|
+
const image = data.external_refs.node_image;
|
|
108
|
+
if (typeof image.tag !== "string" || !NODE_IMAGE_TAG.test(image.tag)) {
|
|
109
|
+
throw invalid("external_refs.node_image.tag must use <positive major>-bookworm-slim");
|
|
110
|
+
}
|
|
111
|
+
if (typeof image.digest !== "string" || !DIGEST.test(image.digest)) {
|
|
112
|
+
throw invalid("external_refs.node_image.digest must use sha256 plus 64 lowercase hexadecimal characters");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
assertStableVersion(data.external_refs.pnpm.version, "external_refs.pnpm.version");
|
|
116
|
+
assertStableVersion(data.external_refs.opencode_ai.version, "external_refs.opencode_ai.version");
|
|
117
|
+
assertStableVersion(data.npm_overrides["@babel/core"], "npm_overrides.@babel/core");
|
|
118
|
+
assertStableVersion(data.npm_overrides.uuid, "npm_overrides.uuid");
|
|
119
|
+
return data;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function readSupplyChain(root, fsOps) {
|
|
123
|
+
const relative = "supply-chain.json";
|
|
124
|
+
const full = path.join(root, relative);
|
|
125
|
+
let stat;
|
|
126
|
+
try {
|
|
127
|
+
stat = fsOps.lstatSync(full);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
130
|
+
throw invalid(`${relative} could not be inspected${error.code ? `: ${error.code}` : ""}`);
|
|
131
|
+
}
|
|
132
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
133
|
+
throw invalid(`${relative} must be a safe regular file`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const realRoot = fsOps.realpathSync(root);
|
|
138
|
+
const realFull = fsOps.realpathSync(full);
|
|
139
|
+
const resolvedRelative = path.relative(realRoot, realFull);
|
|
140
|
+
if (
|
|
141
|
+
resolvedRelative === ".."
|
|
142
|
+
|| resolvedRelative.startsWith(`..${path.sep}`)
|
|
143
|
+
|| path.isAbsolute(resolvedRelative)
|
|
144
|
+
) {
|
|
145
|
+
throw invalid(`${relative} must be a safe regular file`);
|
|
146
|
+
}
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error.code === "INVALID_SUPPLY_CHAIN") throw error;
|
|
149
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
150
|
+
throw invalid(`${relative} could not be resolved${error.code ? `: ${error.code}` : ""}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let contents;
|
|
154
|
+
try {
|
|
155
|
+
contents = fsOps.readFileSync(full, "utf8");
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
158
|
+
throw invalid(`${relative} could not be read${error.code ? `: ${error.code}` : ""}`);
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
return JSON.parse(contents);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw invalid(`${relative} is invalid JSON: ${error.message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function readJson(root, relative, fsOps) {
|
|
168
|
+
try {
|
|
169
|
+
return JSON.parse(fsOps.readFileSync(path.join(root, relative), "utf8"));
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
172
|
+
throw invalid(`${relative} is invalid JSON: ${error.message}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readText(root, relative, fsOps) {
|
|
177
|
+
try {
|
|
178
|
+
return fsOps.readFileSync(path.join(root, relative), "utf8");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
181
|
+
throw invalid(`${relative} could not be read${error.code ? `: ${error.code}` : ""}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function validatePackages(root, data, fsOps) {
|
|
186
|
+
const rootPackage = readJson(root, "package.json", fsOps);
|
|
187
|
+
if (JSON.stringify(rootPackage.files) !== JSON.stringify(PACKAGE_FILES)) {
|
|
188
|
+
throw invalid(`package.json files must be exactly: ${PACKAGE_FILES.join(", ")}`);
|
|
189
|
+
}
|
|
190
|
+
for (const [script, command] of [
|
|
191
|
+
["dependency-audit", "npm --prefix opencode audit --omit=dev --audit-level=low"],
|
|
192
|
+
["dependency-signature-audit", "npm --prefix opencode audit signatures"],
|
|
193
|
+
["package-smoke", "bash scripts/package-smoke.sh"],
|
|
194
|
+
]) {
|
|
195
|
+
if (rootPackage.scripts?.[script] !== command) {
|
|
196
|
+
throw invalid(`package.json ${script} must be exactly: ${command}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const hook of ["prepack", "prepare", "prepublish", "prepublishOnly"]) {
|
|
200
|
+
if (Object.hasOwn(rootPackage.scripts ?? {}, hook)) {
|
|
201
|
+
throw invalid(`package.json contains forbidden root lifecycle hook ${hook}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const relative of ["scripts/package-smoke.sh", "scripts/package-smoke.mjs"]) {
|
|
205
|
+
let stat;
|
|
206
|
+
try {
|
|
207
|
+
stat = fsOps.lstatSync(path.join(root, relative));
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (error.code === "ENOENT") throw invalid(`${relative} is missing`);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
213
|
+
throw invalid(`${relative} must be a regular non-symlink file`);
|
|
214
|
+
}
|
|
215
|
+
if (relative.endsWith(".sh") && !(stat.mode & 0o111)) {
|
|
216
|
+
throw invalid(`${relative} must be executable`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const [script, command] of Object.entries(rootPackage.scripts ?? {})) {
|
|
220
|
+
validateInstallLine(command, `package.json#scripts.${script}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const packaged = readJson(root, "opencode/package.json", fsOps);
|
|
224
|
+
assertExactKeys(packaged.overrides, EXACT_KEYS.overrides, "opencode/package.json overrides");
|
|
225
|
+
for (const dependency of EXACT_KEYS.overrides) {
|
|
226
|
+
if (packaged.overrides[dependency] !== data.npm_overrides[dependency]) {
|
|
227
|
+
throw invalid(
|
|
228
|
+
`opencode/package.json override ${dependency} must be exactly ${data.npm_overrides[dependency]}`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const lock = readJson(root, "opencode/package-lock.json", fsOps);
|
|
234
|
+
if (!lock.packages || typeof lock.packages !== "object" || Array.isArray(lock.packages)) {
|
|
235
|
+
throw invalid("opencode/package-lock.json packages must be an object");
|
|
236
|
+
}
|
|
237
|
+
for (const [name, entry] of Object.entries(lock.packages)) {
|
|
238
|
+
if (name === "") continue;
|
|
239
|
+
if (
|
|
240
|
+
!entry
|
|
241
|
+
|| typeof entry !== "object"
|
|
242
|
+
|| typeof entry.resolved !== "string"
|
|
243
|
+
|| !/^https:\/\/registry\.npmjs\.org\/[^?#\s]+$/.test(entry.resolved)
|
|
244
|
+
) {
|
|
245
|
+
throw invalid(`opencode/package-lock.json ${name} must include a canonical npm registry resolved URL`);
|
|
246
|
+
}
|
|
247
|
+
if (typeof entry.integrity !== "string" || !/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(entry.integrity)) {
|
|
248
|
+
throw invalid(`opencode/package-lock.json ${name} must include non-empty sha512 integrity`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const dependency of EXACT_KEYS.overrides) {
|
|
252
|
+
const entry = lock.packages?.[`node_modules/${dependency}`];
|
|
253
|
+
if (entry?.version !== data.npm_overrides[dependency]) {
|
|
254
|
+
throw invalid(
|
|
255
|
+
`opencode/package-lock.json ${dependency} must resolve to ${data.npm_overrides[dependency]}`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
if (typeof entry.resolved !== "string" || !entry.resolved.startsWith("https://registry.npmjs.org/")) {
|
|
259
|
+
throw invalid(`opencode/package-lock.json ${dependency} must use the npm registry`);
|
|
260
|
+
}
|
|
261
|
+
if (typeof entry.integrity !== "string" || !entry.integrity.startsWith("sha512-")) {
|
|
262
|
+
throw invalid(`opencode/package-lock.json ${dependency} must include sha512 integrity`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function maskQuotedData(line) {
|
|
268
|
+
let quote;
|
|
269
|
+
let escaped = false;
|
|
270
|
+
let masked = "";
|
|
271
|
+
for (const character of line) {
|
|
272
|
+
if (quote) {
|
|
273
|
+
if (character === "\n") {
|
|
274
|
+
escaped = false;
|
|
275
|
+
masked += character;
|
|
276
|
+
} else if (escaped) {
|
|
277
|
+
escaped = false;
|
|
278
|
+
masked += "_";
|
|
279
|
+
} else if (quote === '"' && character === "\\") {
|
|
280
|
+
escaped = true;
|
|
281
|
+
masked += "_";
|
|
282
|
+
} else if (character === quote) {
|
|
283
|
+
quote = undefined;
|
|
284
|
+
masked += character;
|
|
285
|
+
} else {
|
|
286
|
+
masked += "_";
|
|
287
|
+
}
|
|
288
|
+
} else if (character === "'" || character === '"') {
|
|
289
|
+
quote = character;
|
|
290
|
+
masked += character;
|
|
291
|
+
} else {
|
|
292
|
+
masked += character;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return masked;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function activeLine(line, { preserveQuoted = false } = {}) {
|
|
299
|
+
const masked = maskQuotedData(line);
|
|
300
|
+
const comment = masked.indexOf("#");
|
|
301
|
+
const end = comment === -1 ? line.length : comment;
|
|
302
|
+
return (preserveQuoted ? line : masked).slice(0, end);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function containsActiveToken(contents, token) {
|
|
306
|
+
return activeLogicalLines(contents).some((line) => activeLine(line).includes(token));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function activeLogicalLines(contents) {
|
|
310
|
+
const maskedPhysical = maskQuotedData(contents).split(/\r?\n/);
|
|
311
|
+
const logical = [];
|
|
312
|
+
for (let index = 0; index < maskedPhysical.length; index += 1) {
|
|
313
|
+
let line = maskedPhysical[index];
|
|
314
|
+
let comment = line.indexOf("#");
|
|
315
|
+
let active = line.slice(0, comment === -1 ? line.length : comment);
|
|
316
|
+
while (index + 1 < maskedPhysical.length && comment === -1 && active.endsWith("\\")) {
|
|
317
|
+
index += 1;
|
|
318
|
+
line = active.slice(0, -1) + maskedPhysical[index];
|
|
319
|
+
comment = line.indexOf("#");
|
|
320
|
+
active = line.slice(0, comment === -1 ? line.length : comment);
|
|
321
|
+
}
|
|
322
|
+
logical.push(active);
|
|
323
|
+
}
|
|
324
|
+
return logical;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function validateInstallLine(line, relative) {
|
|
328
|
+
let command = maskQuotedData(line).trim();
|
|
329
|
+
if (!command || command.startsWith("#")) return;
|
|
330
|
+
if (command.startsWith("run:")) command = command.slice("run:".length).trim();
|
|
331
|
+
command = command.replace(/\s+#.*$/, "");
|
|
332
|
+
for (const match of command.matchAll(/\bnpm(?:\s+--prefix\s+\S+)?\s+(ci|install)\b([^;&|]*)/g)) {
|
|
333
|
+
const prefix = command.slice(0, match.index);
|
|
334
|
+
if (!/(?:^|&&|\|\||;|\bthen\b|\bdo\b)\s*(?:if\s+)?(?:!\s*)?(?:[A-Za-z_][A-Za-z0-9_]*=[^\s;&|]*\s+)*(?:run_isolated\s+)?$/.test(prefix)) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (match[1] === "install") {
|
|
338
|
+
throw invalid(`${relative}: automated npm install is forbidden; use npm ci --ignore-scripts`);
|
|
339
|
+
}
|
|
340
|
+
if (!/(?:^|\s)--ignore-scripts(?:\s|$)/.test(match[2])) {
|
|
341
|
+
throw invalid(`${relative}: automated npm ci must include --ignore-scripts`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function validateAutomatedInstalls(root, fsOps) {
|
|
347
|
+
for (const relative of activeCommandFiles(root, fsOps)) {
|
|
348
|
+
const contents = fsOps.readFileSync(path.join(root, relative), "utf8");
|
|
349
|
+
for (const line of activeLogicalLines(contents)) validateInstallLine(line, relative);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function activeCommandFiles(root, fsOps) {
|
|
354
|
+
const files = [];
|
|
355
|
+
const collect = (relative, executableOnly) => {
|
|
356
|
+
const full = path.join(root, relative);
|
|
357
|
+
let entries;
|
|
358
|
+
try {
|
|
359
|
+
entries = fsOps.readdirSync(full, { withFileTypes: true });
|
|
360
|
+
} catch (error) {
|
|
361
|
+
if (error.code === "ENOENT") return;
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
for (const entry of entries) {
|
|
365
|
+
const child = path.join(relative, entry.name);
|
|
366
|
+
if (entry.isDirectory()) collect(child, executableOnly);
|
|
367
|
+
else if (entry.isFile() && (!executableOnly || (fsOps.statSync(path.join(root, child)).mode & 0o111))) {
|
|
368
|
+
files.push(child);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
collect(".github/workflows", false);
|
|
373
|
+
collect("scripts", true);
|
|
374
|
+
return files;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function validateStarterConfig(root, data, fsOps) {
|
|
378
|
+
const relative = "opencode/opencode.json";
|
|
379
|
+
const config = readJson(root, relative, fsOps);
|
|
380
|
+
const expected = `superpowers@git+https://github.com/obra/superpowers.git#${data.external_refs.superpowers.commit}`;
|
|
381
|
+
if (!Array.isArray(config.plugin)) {
|
|
382
|
+
throw invalid(`${relative} plugin must be an array containing the exact Superpowers full reviewed commit`);
|
|
383
|
+
}
|
|
384
|
+
if (config.plugin.filter((plugin) => plugin === expected).length !== 1) {
|
|
385
|
+
throw invalid(`${relative} superpowers plugin must use the exact full reviewed commit ${data.external_refs.superpowers.commit}`);
|
|
386
|
+
}
|
|
387
|
+
for (const plugin of config.plugin) {
|
|
388
|
+
if (typeof plugin !== "string") throw invalid(`${relative} plugin entries must be strings`);
|
|
389
|
+
if (plugin.includes("git+https") && plugin !== expected) {
|
|
390
|
+
throw invalid(`${relative} git+https plugin must use the exact full reviewed commit`);
|
|
391
|
+
}
|
|
392
|
+
if (plugin.includes("@latest")) {
|
|
393
|
+
throw invalid(`${relative} must not use @latest in a stable input`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function validateWorkflowActions(root, data, fsOps) {
|
|
399
|
+
const approved = new Map([
|
|
400
|
+
["actions/checkout", data.external_refs.actions_checkout],
|
|
401
|
+
["actions/setup-node", data.external_refs.actions_setup_node],
|
|
402
|
+
]);
|
|
403
|
+
for (const relative of [
|
|
404
|
+
".github/workflows/check.yml",
|
|
405
|
+
".github/workflows/compatibility-canary.yml",
|
|
406
|
+
]) {
|
|
407
|
+
const workflow = readText(root, relative, fsOps);
|
|
408
|
+
const seen = new Map([...approved.keys()].map((action) => [action, 0]));
|
|
409
|
+
for (const line of workflow.split("\n")) {
|
|
410
|
+
const match = line.match(/^\s*(?:-\s*)?uses:\s*([^\s#]+)(?:\s+#\s+(\S.*?))?\s*$/);
|
|
411
|
+
if (/^\s*(?:-\s*)?uses\s*:/.test(line) && !match) {
|
|
412
|
+
throw invalid(`${relative} Action uses syntax must include a full commit and release comment`);
|
|
413
|
+
}
|
|
414
|
+
if (!match) continue;
|
|
415
|
+
const use = match[1];
|
|
416
|
+
const separator = use.lastIndexOf("@");
|
|
417
|
+
const action = separator === -1 ? use : use.slice(0, separator);
|
|
418
|
+
const ref = separator === -1 ? "" : use.slice(separator + 1);
|
|
419
|
+
const inventory = approved.get(action);
|
|
420
|
+
if (!COMMIT.test(ref)) {
|
|
421
|
+
throw invalid(`${relative} Action ${action || use} must use a lowercase full commit`);
|
|
422
|
+
}
|
|
423
|
+
if (!inventory) {
|
|
424
|
+
throw invalid(`${relative} Action ${action} is not present in supply-chain.json`);
|
|
425
|
+
}
|
|
426
|
+
if (ref !== inventory.commit) {
|
|
427
|
+
throw invalid(`${relative} Action ${action} must match its supply-chain.json commit`);
|
|
428
|
+
}
|
|
429
|
+
if (match[2] !== inventory.release) {
|
|
430
|
+
throw invalid(`${relative} Action ${action} release comment must be exactly ${inventory.release}`);
|
|
431
|
+
}
|
|
432
|
+
seen.set(action, seen.get(action) + 1);
|
|
433
|
+
}
|
|
434
|
+
for (const [action, count] of seen) {
|
|
435
|
+
if (count === 0) throw invalid(`${relative} must use approved Action ${action}`);
|
|
436
|
+
}
|
|
437
|
+
if (containsActiveToken(workflow, "@latest")) {
|
|
438
|
+
throw invalid(`${relative} must not use @latest in a stable input`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function validateStableWorkflowCommands(root, fsOps) {
|
|
444
|
+
for (const relative of activeCommandFiles(root, fsOps)) {
|
|
445
|
+
const contents = readText(root, relative, fsOps);
|
|
446
|
+
for (const line of activeLogicalLines(contents)) {
|
|
447
|
+
const command = activeLine(line);
|
|
448
|
+
const clone = command.match(/\bgit\s+clone\b.*?(?:--branch(?:=|\s+)|-b\s+)([^\s;&|]+)/);
|
|
449
|
+
if (clone && !COMMIT.test(clone[1])) {
|
|
450
|
+
throw invalid(`${relative} must not use a mutable git clone --branch value`);
|
|
451
|
+
}
|
|
452
|
+
const mutableNpmCli = command.match(
|
|
453
|
+
/\b(npm\s+exec|npx)\s+(?:--\s+)?(?:@[^\s/@]+\/)?[^\s@/]+@v[1-9][0-9]*(?=\s|$)/,
|
|
454
|
+
);
|
|
455
|
+
if (mutableNpmCli) {
|
|
456
|
+
throw invalid(`${relative} ${mutableNpmCli[1]} must not use a mutable major tag`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function validateDockerfile(root, data, fsOps) {
|
|
463
|
+
const relative = "docker/open-design/Dockerfile";
|
|
464
|
+
const dockerfile = readText(root, relative, fsOps);
|
|
465
|
+
const activeDockerfile = dockerfile
|
|
466
|
+
.split("\n")
|
|
467
|
+
.map((line) => activeLine(line, { preserveQuoted: true }))
|
|
468
|
+
.filter((line) => line.trim())
|
|
469
|
+
.join("\n");
|
|
470
|
+
const fromLines = activeDockerfile.match(/^FROM\s+\S+[^\S\r\n]*$/gm) ?? [];
|
|
471
|
+
if (fromLines.length !== 1) {
|
|
472
|
+
throw invalid(`${relative} must contain exactly one FROM`);
|
|
473
|
+
}
|
|
474
|
+
const expectedFrom = `FROM node:${data.external_refs.node_image.tag}@${data.external_refs.node_image.digest}`;
|
|
475
|
+
if (fromLines[0].trimEnd() !== expectedFrom) {
|
|
476
|
+
throw invalid(`${relative} FROM must use the exact reviewed tag and digest`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
for (const [pattern, expected, label] of [
|
|
480
|
+
[/^ARG OPEN_DESIGN_REF=\S+[^\S\r\n]*$/gm, `ARG OPEN_DESIGN_REF=${data.external_refs.open_design.commit}`, "OPEN_DESIGN_REF"],
|
|
481
|
+
[/\bgit checkout\b[^\n]*/g, 'git checkout "$OPEN_DESIGN_REF"', "Open Design checkout"],
|
|
482
|
+
[/^ARG OPENCODE_AI_VERSION=\S+[^\S\r\n]*$/gm, `ARG OPENCODE_AI_VERSION=${data.external_refs.opencode_ai.version}`, "OPENCODE_AI_VERSION"],
|
|
483
|
+
[/\bnpm install -g\b[^\n]*/g, 'npm install -g "opencode-ai@$OPENCODE_AI_VERSION"', "OpenCode install"],
|
|
484
|
+
[/\bcorepack prepare pnpm@\S+ --activate\b/g, `corepack prepare pnpm@${data.external_refs.pnpm.version} --activate`, "pnpm version"],
|
|
485
|
+
[/\bpnpm install\b[^\n]*/g, "pnpm install --frozen-lockfile", "pnpm install must use exactly --frozen-lockfile"],
|
|
486
|
+
]) {
|
|
487
|
+
const matches = activeDockerfile.match(pattern) ?? [];
|
|
488
|
+
const normalized = matches[0]?.trim().replace(/\s+\\$/, "");
|
|
489
|
+
if (matches.length !== 1 || normalized !== expected) {
|
|
490
|
+
throw invalid(`${relative} must contain exactly one approved ${label}`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (containsActiveToken(dockerfile, "@latest")) {
|
|
494
|
+
throw invalid(`${relative} must not use @latest in a stable input`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function canonicalDocumentationPinBlock(data) {
|
|
499
|
+
return `<!-- supply-chain-pins:start -->
|
|
500
|
+
| Surface | Reviewed label | Immutable identifier |
|
|
501
|
+
|---|---|---|
|
|
502
|
+
| Superpowers | ${data.external_refs.superpowers.release} | \`${data.external_refs.superpowers.commit}\` |
|
|
503
|
+
| actions/checkout | ${data.external_refs.actions_checkout.release} | \`${data.external_refs.actions_checkout.commit}\` |
|
|
504
|
+
| actions/setup-node | ${data.external_refs.actions_setup_node.release} | \`${data.external_refs.actions_setup_node.commit}\` |
|
|
505
|
+
| Open Design | reviewed commit | \`${data.external_refs.open_design.commit}\` |
|
|
506
|
+
| Node image | ${data.external_refs.node_image.tag} | \`${data.external_refs.node_image.digest}\` |
|
|
507
|
+
| pnpm | ${data.external_refs.pnpm.version} | exact version |
|
|
508
|
+
| opencode-ai | ${data.external_refs.opencode_ai.version} | exact version |
|
|
509
|
+
| @babel/core override | ${data.npm_overrides["@babel/core"]} | exact version |
|
|
510
|
+
| uuid override | ${data.npm_overrides.uuid} | exact version |
|
|
511
|
+
<!-- supply-chain-pins:end -->`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function validateDocumentation(root, data, fsOps) {
|
|
515
|
+
const relative = "docs/supply-chain.md";
|
|
516
|
+
const policy = readText(root, relative, fsOps);
|
|
517
|
+
const start = "<!-- supply-chain-pins:start -->";
|
|
518
|
+
const end = "<!-- supply-chain-pins:end -->";
|
|
519
|
+
const starts = policy.match(/<!-- supply-chain-pins:start -->/g) ?? [];
|
|
520
|
+
const ends = policy.match(/<!-- supply-chain-pins:end -->/g) ?? [];
|
|
521
|
+
const startIndex = policy.indexOf(start);
|
|
522
|
+
const endIndex = policy.indexOf(end);
|
|
523
|
+
if (starts.length !== 1 || ends.length !== 1 || startIndex >= endIndex) {
|
|
524
|
+
throw invalid(`${relative} must contain one ordered supply-chain-pins block`);
|
|
525
|
+
}
|
|
526
|
+
const actualBlock = policy.slice(startIndex, endIndex + end.length);
|
|
527
|
+
if (actualBlock !== canonicalDocumentationPinBlock(data)) {
|
|
528
|
+
const rowPositions = [
|
|
529
|
+
"| Superpowers |",
|
|
530
|
+
"| actions/checkout |",
|
|
531
|
+
"| actions/setup-node |",
|
|
532
|
+
"| Open Design |",
|
|
533
|
+
"| Node image |",
|
|
534
|
+
"| pnpm |",
|
|
535
|
+
"| opencode-ai |",
|
|
536
|
+
"| @babel/core override |",
|
|
537
|
+
"| uuid override |",
|
|
538
|
+
].map((row) => actualBlock.indexOf(row));
|
|
539
|
+
const rowsAreOrdered = rowPositions.every(
|
|
540
|
+
(position, index) => position >= 0 && (index === 0 || position > rowPositions[index - 1]),
|
|
541
|
+
);
|
|
542
|
+
if (!rowsAreOrdered) {
|
|
543
|
+
throw invalid(`${relative} must contain one ordered supply-chain-pins block`);
|
|
544
|
+
}
|
|
545
|
+
throw invalid(`${relative} canonical pins must exactly match supply-chain.json in declared order`);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
for (const [required, message] of [
|
|
549
|
+
["npm ci --ignore-scripts", `${relative} must state the frozen install policy`],
|
|
550
|
+
[
|
|
551
|
+
"<64 lowercase hexadecimal characters> opencode-agent-orchestration-kit-<version>.tgz",
|
|
552
|
+
`${relative} must state the canonical checksum format`,
|
|
553
|
+
],
|
|
554
|
+
[
|
|
555
|
+
"Publication is never performed by checks and requires separate explicit authorization.",
|
|
556
|
+
`${relative} must warn that publication requires separate explicit authorization`,
|
|
557
|
+
],
|
|
558
|
+
]) {
|
|
559
|
+
if (!policy.includes(required)) throw invalid(message);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const expected = `superpowers@git+https://github.com/obra/superpowers.git#${data.external_refs.superpowers.commit}`;
|
|
563
|
+
const referencePattern = /superpowers@git\+https:\/\/github\.com\/obra\/superpowers\.git(?:#[A-Za-z0-9._-]+)?/g;
|
|
564
|
+
for (const activeDoc of ["README.md", "docs/superpowers.md"]) {
|
|
565
|
+
const references = readText(root, activeDoc, fsOps).match(referencePattern) ?? [];
|
|
566
|
+
if (references.length === 0 || references.some((reference) => reference !== expected)) {
|
|
567
|
+
throw invalid(`${activeDoc} active Superpowers reference must use the full reviewed commit`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const documentationRequirements = new Map([
|
|
572
|
+
["README.md", [["npm ci --ignore-scripts", "frozen install command"]]],
|
|
573
|
+
["docs/installation.md", [["npm ci --ignore-scripts", "frozen install command"]]],
|
|
574
|
+
["docs/quickstart.md", [
|
|
575
|
+
["npm ci --ignore-scripts", "frozen install command"],
|
|
576
|
+
["npm run check:release", "release gate"],
|
|
577
|
+
]],
|
|
578
|
+
["docs/compatibility.md", [
|
|
579
|
+
["core smoke", "core smoke contract"],
|
|
580
|
+
["default-config smoke", "default-config smoke contract"],
|
|
581
|
+
]],
|
|
582
|
+
["docs/security.md", [
|
|
583
|
+
["npm audit signatures", "signature audit"],
|
|
584
|
+
["package-smoked tarball", "package-smoked tarball"],
|
|
585
|
+
["SHA-256", "SHA-256 checksum"],
|
|
586
|
+
]],
|
|
587
|
+
["docs/workflows.md", [
|
|
588
|
+
["package artifact", "package artifact"],
|
|
589
|
+
["checksum", "checksum verification"],
|
|
590
|
+
["post-publication verification", "post-publication verification"],
|
|
591
|
+
]],
|
|
592
|
+
["docs/docker-open-design.md", [
|
|
593
|
+
[`node:${data.external_refs.node_image.tag}@${data.external_refs.node_image.digest}`, "Node image digest"],
|
|
594
|
+
[`OPEN_DESIGN_REF=${data.external_refs.open_design.commit}`, "Open Design commit"],
|
|
595
|
+
[`OPENCODE_AI_VERSION=${data.external_refs.opencode_ai.version}`, "OpenCode version"],
|
|
596
|
+
[`pnpm@${data.external_refs.pnpm.version}`, "pnpm version"],
|
|
597
|
+
["pnpm install --frozen-lockfile", "frozen pnpm install"],
|
|
598
|
+
]],
|
|
599
|
+
]);
|
|
600
|
+
for (const [activeDoc, requirements] of documentationRequirements) {
|
|
601
|
+
const contents = readText(root, activeDoc, fsOps);
|
|
602
|
+
for (const [fragment, label] of requirements) {
|
|
603
|
+
if (!contents.includes(fragment)) throw invalid(`${activeDoc} must retain its canonical ${label}`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function validateSurfaces(root, data, fsOps) {
|
|
609
|
+
validatePackages(root, data, fsOps);
|
|
610
|
+
validateAutomatedInstalls(root, fsOps);
|
|
611
|
+
validateStarterConfig(root, data, fsOps);
|
|
612
|
+
validateWorkflowActions(root, data, fsOps);
|
|
613
|
+
validateStableWorkflowCommands(root, fsOps);
|
|
614
|
+
validateDockerfile(root, data, fsOps);
|
|
615
|
+
validateDocumentation(root, data, fsOps);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export function checkSupplyChain(
|
|
619
|
+
root = REPOSITORY_ROOT,
|
|
620
|
+
{ fsOps = fs, surfaces = true } = {},
|
|
621
|
+
) {
|
|
622
|
+
const data = validateSupplyChainData(readSupplyChain(root, fsOps));
|
|
623
|
+
if (surfaces) validateSurfaces(root, data, fsOps);
|
|
624
|
+
return data;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (path.resolve(process.argv[1] ?? "") === SCRIPT_PATH) {
|
|
628
|
+
try {
|
|
629
|
+
checkSupplyChain(REPOSITORY_ROOT);
|
|
630
|
+
console.log("supply chain contract ok: immutable external refs and exact npm overrides");
|
|
631
|
+
} catch (error) {
|
|
632
|
+
console.error(`supply chain contract invalid: ${error.message}`);
|
|
633
|
+
process.exitCode = 1;
|
|
634
|
+
}
|
|
635
|
+
}
|