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.
Files changed (39) hide show
  1. package/README.md +27 -14
  2. package/compatibility.json +19 -0
  3. package/docker/open-design/Dockerfile +2 -2
  4. package/docs/compatibility.md +104 -0
  5. package/docs/docker-open-design.md +8 -0
  6. package/docs/installation.md +13 -3
  7. package/docs/quickstart.md +6 -3
  8. package/docs/releases/v1.0.28.md +71 -0
  9. package/docs/releases/v1.0.29.md +78 -0
  10. package/docs/security.md +9 -0
  11. package/docs/superpowers/plans/2026-07-21-compatibility-matrix.md +1286 -0
  12. package/docs/superpowers/specs/2026-07-21-compatibility-matrix-design.md +452 -0
  13. package/docs/superpowers.md +11 -4
  14. package/docs/supply-chain.md +145 -0
  15. package/docs/workflows.md +15 -0
  16. package/opencode/opencode.json +1 -1
  17. package/opencode/package-lock.json +96 -96
  18. package/opencode/package.json +5 -1
  19. package/package.json +29 -3
  20. package/scripts/check-compatibility.mjs +676 -0
  21. package/scripts/check-compatibility.test.mjs +1467 -0
  22. package/scripts/check-supply-chain.mjs +635 -0
  23. package/scripts/check-supply-chain.test.mjs +944 -0
  24. package/scripts/check.sh +15 -5
  25. package/scripts/install-smoke.sh +1 -1
  26. package/scripts/opencode-compat-smoke.sh +264 -0
  27. package/scripts/package-smoke.mjs +357 -0
  28. package/scripts/package-smoke.sh +5 -0
  29. package/scripts/package-smoke.test.mjs +256 -0
  30. package/scripts/version.mjs +18 -5
  31. package/scripts/version.test.mjs +53 -3
  32. package/supply-chain.json +34 -0
  33. package/.github/CODEOWNERS +0 -1
  34. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -65
  35. package/.github/ISSUE_TEMPLATE/config.yml +0 -11
  36. package/.github/ISSUE_TEMPLATE/documentation.yml +0 -22
  37. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -43
  38. package/.github/PULL_REQUEST_TEMPLATE.md +0 -25
  39. package/.github/workflows/check.yml +0 -47
package/scripts/check.sh CHANGED
@@ -19,8 +19,18 @@ upgrade.sh
19
19
  doctor.sh
20
20
  rollback.sh
21
21
  package.json
22
+ compatibility.json
23
+ supply-chain.json
22
24
  scripts/version.mjs
23
25
  scripts/version.test.mjs
26
+ scripts/check-compatibility.mjs
27
+ scripts/check-compatibility.test.mjs
28
+ scripts/check-supply-chain.mjs
29
+ scripts/check-supply-chain.test.mjs
30
+ scripts/package-smoke.sh
31
+ scripts/package-smoke.mjs
32
+ scripts/package-smoke.test.mjs
33
+ scripts/opencode-compat-smoke.sh
24
34
  scripts/manage-installation.mjs
25
35
  scripts/manage-installation.test.mjs
26
36
  docs/releases/v${kit_version}.md
@@ -52,11 +62,13 @@ docker/open-design/Dockerfile
52
62
  docker/open-design/docker-compose.yml
53
63
  docker/open-design/.env.example
54
64
  docker/open-design/opencode-od/opencode.json
65
+ docs/supply-chain.md
55
66
  CODE_OF_CONDUCT.md
56
67
  CONTRIBUTING.md
57
68
  .github/PULL_REQUEST_TEMPLATE.md
58
69
  .github/CODEOWNERS
59
70
  .github/workflows/check.yml
71
+ .github/workflows/compatibility-canary.yml
60
72
  .github/ISSUE_TEMPLATE/config.yml
61
73
  .github/ISSUE_TEMPLATE/bug_report.yml
62
74
  .github/ISSUE_TEMPLATE/feature_request.yml
@@ -67,11 +79,13 @@ for file in $required_files; do
67
79
  test -f "$file" || { echo "Missing required file: $file" >&2; exit 1; }
68
80
  done
69
81
 
70
- for file in install.sh uninstall.sh upgrade.sh doctor.sh rollback.sh scripts/check.sh; do
82
+ for file in install.sh uninstall.sh upgrade.sh doctor.sh rollback.sh scripts/check.sh scripts/opencode-compat-smoke.sh scripts/package-smoke.sh; do
71
83
  test -x "$file" || { echo "Not executable: $file" >&2; exit 1; }
72
84
  done
73
85
 
74
86
  node scripts/version.mjs --check
87
+ node scripts/check-compatibility.mjs
88
+ node scripts/check-supply-chain.mjs
75
89
 
76
90
  node -e "JSON.parse(require('fs').readFileSync('opencode/opencode.json','utf8')); JSON.parse(require('fs').readFileSync('docker/open-design/opencode-od/opencode.json','utf8')); console.log('json ok')"
77
91
  (cd opencode && node scripts/check-harness.mjs)
@@ -90,7 +104,6 @@ for (const dir of ['opencode/agents', 'opencode/commands', ...fs.readdirSync('op
90
104
  console.log('frontmatter ok')
91
105
  NODE
92
106
 
93
- grep -q 'superpowers@git+https://github.com/obra/superpowers.git' opencode/opencode.json
94
107
  grep -q '"default_agent": "lead"' opencode/opencode.json
95
108
  grep -q './plugins/token-tree-usage.tsx' opencode/tui.json
96
109
 
@@ -155,9 +168,6 @@ if (opencodePackage.dependencies?.['@opentui/solid'] !== '0.2.5') {
155
168
  if (opencodePackage.dependencies?.['solid-js'] !== '1.9.12') {
156
169
  throw new Error('opencode/package.json must pin solid-js to 1.9.12')
157
170
  }
158
- if (opencodePackage.overrides?.uuid !== '^14.0.0') {
159
- throw new Error('opencode/package.json must override uuid to ^14.0.0')
160
- }
161
171
  NODE
162
172
 
163
173
  grep -q 'Lead' opencode/plugins/token-tree-usage.tsx
@@ -103,7 +103,7 @@ fi
103
103
 
104
104
  (
105
105
  cd "$target"
106
- npm ci
106
+ npm ci --ignore-scripts
107
107
  node scripts/check-harness.mjs
108
108
  node --input-type=module -e "import('@opencode-ai/plugin').then(() => console.log('installed plugin import ok'))"
109
109
  )
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ canonical_version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
5
+
6
+ if [[ $# -ne 2 ]] \
7
+ || [[ "$1" != "core" && "$1" != "default" ]] \
8
+ || [[ "$2" != "latest" && ! "$2" =~ $canonical_version_re ]] \
9
+ || [[ "$1" == "default" && "$2" == "latest" ]]; then
10
+ echo "usage: $0 core MAJOR.MINOR.PATCH|latest | default MAJOR.MINOR.PATCH" >&2
11
+ exit 2
12
+ fi
13
+
14
+ mode="$1"
15
+ request="$2"
16
+ root="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
17
+ original_home="${HOME-}"
18
+ temp_base="${TMPDIR:-/tmp}"
19
+ temp_base="${temp_base%/}"
20
+ smoke_root=""
21
+
22
+ cleanup() {
23
+ if [[ -n "$smoke_root" ]]; then
24
+ case "$smoke_root" in
25
+ "$temp_base"/oak-opencode-compat.??????)
26
+ rm -rf -- "$smoke_root"
27
+ ;;
28
+ esac
29
+ fi
30
+ }
31
+ trap cleanup EXIT
32
+
33
+ smoke_root="$(mktemp -d "$temp_base/oak-opencode-compat.XXXXXX")"
34
+ mkdir -p \
35
+ "$smoke_root/home" \
36
+ "$smoke_root/config" \
37
+ "$smoke_root/data" \
38
+ "$smoke_root/cache" \
39
+ "$smoke_root/state" \
40
+ "$smoke_root/npm" \
41
+ "$smoke_root/pack" \
42
+ "$smoke_root/extracted"
43
+ diagnostics_file="$smoke_root/diagnostics"
44
+ : >"$diagnostics_file"
45
+ test -f "$diagnostics_file" && test ! -L "$diagnostics_file"
46
+
47
+ source_config="$root/opencode"
48
+ if [[ "$mode" == "default" ]]; then
49
+ pack_json="$smoke_root/pack.json"
50
+ if ! (
51
+ cd "$root"
52
+ env -i \
53
+ PATH="$PATH" \
54
+ HOME="$smoke_root/home" \
55
+ npm_config_cache="$smoke_root/npm" \
56
+ npm pack --json --pack-destination "$smoke_root/pack"
57
+ ) >"$pack_json" 2>>"$diagnostics_file"; then
58
+ fail_message="default npm pack failed"
59
+ else
60
+ fail_message=""
61
+ fi
62
+ if [[ -n "$fail_message" ]]; then
63
+ diagnostics="$(<"$diagnostics_file")"
64
+ if [[ -n "$original_home" && "$diagnostics" == *"$original_home"* ]] \
65
+ || [[ "$diagnostics" == *"$root"* ]]; then
66
+ echo "captured diagnostics contained a private path" >&2
67
+ else
68
+ echo "$fail_message" >&2
69
+ fi
70
+ exit 1
71
+ fi
72
+
73
+ if ! tarball_name="$(node - "$pack_json" <<'NODE'
74
+ const fs = require("node:fs");
75
+ const entries = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
76
+ if (!Array.isArray(entries) || entries.length !== 1) process.exit(1);
77
+ const name = entries[0]?.filename;
78
+ if (typeof name !== "string" || name === "" || require("node:path").basename(name) !== name) {
79
+ process.exit(1);
80
+ }
81
+ process.stdout.write(name);
82
+ NODE
83
+ )"; then
84
+ echo "npm pack must report exactly one tarball" >&2
85
+ exit 1
86
+ fi
87
+ tarball="$smoke_root/pack/$tarball_name"
88
+ if [[ ! -f "$tarball" || -L "$tarball" ]]; then
89
+ echo "npm pack did not produce one regular tarball" >&2
90
+ exit 1
91
+ fi
92
+ if ! tar -xzf "$tarball" -C "$smoke_root/extracted" 2>>"$diagnostics_file"; then
93
+ echo "default tarball extraction failed" >&2
94
+ exit 1
95
+ fi
96
+ source_config="$smoke_root/extracted/package/opencode"
97
+ fi
98
+
99
+ target_config="$smoke_root/config/opencode"
100
+ test ! -e "$target_config"
101
+
102
+ node - "$source_config" "$target_config" "$mode" <<'NODE'
103
+ const fs = require("node:fs");
104
+ const path = require("node:path");
105
+
106
+ const sourceRoot = process.argv[2];
107
+ const targetRoot = process.argv[3];
108
+ const mode = process.argv[4];
109
+
110
+ fs.cpSync(sourceRoot, targetRoot, {
111
+ recursive: true,
112
+ filter(source) {
113
+ const stat = fs.lstatSync(source);
114
+ if (stat.isSymbolicLink()) {
115
+ throw new Error("packaged OpenCode config must not contain symlinks");
116
+ }
117
+
118
+ const relative = path.relative(sourceRoot, source);
119
+ if (relative === "") return true;
120
+ return !relative.split(path.sep).some((component) =>
121
+ component === "node_modules"
122
+ || component === ".oak"
123
+ || (mode === "core" && component === "plugins")
124
+ );
125
+ },
126
+ });
127
+
128
+ const configPath = path.join(targetRoot, "opencode.json");
129
+ if (mode === "core") {
130
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
131
+ config.plugin = [];
132
+ fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
133
+ }
134
+ NODE
135
+
136
+ if [[ ! -f "$target_config/agents/lead.md" || -e "$target_config/opencode" ]]; then
137
+ echo "packaged OpenCode config has an invalid layout" >&2
138
+ exit 1
139
+ fi
140
+
141
+ node - "$target_config" "$mode" <<'NODE'
142
+ const fs = require("node:fs");
143
+ const path = require("node:path");
144
+ const root = process.argv[2];
145
+ const mode = process.argv[3];
146
+ const config = JSON.parse(fs.readFileSync(path.join(root, "opencode.json"), "utf8"));
147
+ const plugins = path.join(root, "plugins");
148
+ const superpowers = "superpowers@git+https://github.com/obra/superpowers.git#d884ae04edebef577e82ff7c4e143debd0bbec99";
149
+
150
+ if (mode === "core") {
151
+ if (!Array.isArray(config.plugin) || config.plugin.length !== 0 || fs.existsSync(plugins)) {
152
+ process.exit(1);
153
+ }
154
+ } else if (
155
+ !Array.isArray(config.plugin)
156
+ || config.plugin.length !== 1
157
+ || config.plugin[0] !== superpowers
158
+ || !fs.statSync(path.join(plugins, "token-tree-usage.tsx")).isFile()
159
+ ) {
160
+ process.exit(1);
161
+ }
162
+ NODE
163
+
164
+ run_isolated() (
165
+ cd "$smoke_root/home"
166
+ env -i \
167
+ PATH="$PATH" \
168
+ HOME="$smoke_root/home" \
169
+ XDG_CONFIG_HOME="$smoke_root/config" \
170
+ XDG_DATA_HOME="$smoke_root/data" \
171
+ XDG_CACHE_HOME="$smoke_root/cache" \
172
+ XDG_STATE_HOME="$smoke_root/state" \
173
+ npm_config_cache="$smoke_root/npm" \
174
+ OPENCODE_CONFIG_DIR="$target_config" \
175
+ "$@"
176
+ )
177
+
178
+ run_opencode() {
179
+ run_isolated npx --yes --package "opencode-ai@$request" opencode "$@"
180
+ }
181
+
182
+ contains_forbidden_path() {
183
+ local output="$1"
184
+ local forbidden
185
+ for forbidden in "$original_home" "$root"; do
186
+ if [[ -n "$forbidden" && "$output" == *"$forbidden"* ]]; then
187
+ return 0
188
+ fi
189
+ done
190
+ return 1
191
+ }
192
+
193
+ emit_safe_diagnostics() {
194
+ local line
195
+ while IFS= read -r line || [[ -n "$line" ]]; do
196
+ if [[ "$line" != *"$smoke_root"* ]]; then
197
+ printf '%s\n' "$line" >&2
198
+ fi
199
+ done <"$diagnostics_file"
200
+ }
201
+
202
+ fail_with_diagnostics() {
203
+ local message="$1"
204
+ local diagnostics
205
+ diagnostics="$(<"$diagnostics_file")"
206
+ if contains_forbidden_path "$diagnostics"; then
207
+ echo "captured diagnostics contained a private path" >&2
208
+ else
209
+ emit_safe_diagnostics
210
+ echo "$message" >&2
211
+ fi
212
+ exit 1
213
+ }
214
+
215
+ if ! run_isolated npm --prefix "$target_config" ci --ignore-scripts \
216
+ >/dev/null 2>>"$diagnostics_file"; then
217
+ fail_with_diagnostics "isolated npm install failed"
218
+ fi
219
+
220
+ if ! actual="$(run_opencode --version 2>>"$diagnostics_file")"; then
221
+ fail_with_diagnostics "OpenCode version command failed"
222
+ fi
223
+ if [[ "$request" == "latest" ]]; then
224
+ if [[ ! "$actual" =~ $canonical_version_re ]]; then
225
+ fail_with_diagnostics "latest OpenCode did not resolve to a canonical version"
226
+ fi
227
+ elif [[ "$actual" != "$request" ]]; then
228
+ fail_with_diagnostics "resolved OpenCode version did not match the request"
229
+ fi
230
+
231
+ if ! agent_json="$(run_opencode debug agent lead --pure 2>>"$diagnostics_file")"; then
232
+ fail_with_diagnostics "OpenCode lead debug command failed"
233
+ fi
234
+
235
+ for output in "$actual" "$agent_json"; do
236
+ if contains_forbidden_path "$output"; then
237
+ fail_with_diagnostics "OpenCode output contained a private path"
238
+ fi
239
+ done
240
+
241
+ if ! printf '%s' "$agent_json" | node -e '
242
+ let input = "";
243
+ process.stdin.setEncoding("utf8");
244
+ process.stdin.on("data", (chunk) => { input += chunk; });
245
+ process.stdin.on("end", () => {
246
+ let agent;
247
+ try {
248
+ agent = JSON.parse(input);
249
+ } catch {
250
+ process.exit(1);
251
+ }
252
+ if (agent?.name !== "lead" || agent?.mode !== "primary") process.exit(1);
253
+ });
254
+ '; then
255
+ fail_with_diagnostics "packaged lead did not resolve as a primary agent"
256
+ fi
257
+
258
+ diagnostics="$(<"$diagnostics_file")"
259
+ if contains_forbidden_path "$diagnostics"; then
260
+ echo "captured diagnostics contained a private path" >&2
261
+ exit 1
262
+ fi
263
+ emit_safe_diagnostics
264
+ printf 'opencode compatibility smoke ok: mode=%s requested=%s resolved=%s\n' "$mode" "$request" "$actual"
@@ -0,0 +1,357 @@
1
+ #!/usr/bin/env node
2
+
3
+ import crypto from "node:crypto";
4
+ import fs from "node:fs";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { spawnSync } from "node:child_process";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const SCRIPT_PATH = fileURLToPath(import.meta.url);
11
+ const REPOSITORY_ROOT = path.dirname(path.dirname(SCRIPT_PATH));
12
+ const REQUIRED_FILES = [
13
+ "package/package.json",
14
+ "package/supply-chain.json",
15
+ "package/install.sh",
16
+ "package/scripts/manage-installation.mjs",
17
+ "package/scripts/package-smoke.sh",
18
+ "package/scripts/package-smoke.mjs",
19
+ "package/opencode/opencode.json",
20
+ "package/opencode/package.json",
21
+ "package/opencode/package-lock.json",
22
+ "package/opencode/agents/lead.md",
23
+ "package/docs/installation.md",
24
+ "package/LICENSE",
25
+ "package/NOTICE.md",
26
+ ];
27
+
28
+ function smokeError(message) {
29
+ const error = new Error(message);
30
+ error.code = "INVALID_PACKAGE";
31
+ return error;
32
+ }
33
+
34
+ export function parseChecksumFile(text, basename) {
35
+ if (typeof text !== "string" || typeof basename !== "string" || path.basename(basename) !== basename) {
36
+ throw smokeError("checksum basename is invalid");
37
+ }
38
+ const match = text.match(/^([0-9a-f]{64}) ([^\s/\\]+)\n?$/);
39
+ if (!match) throw smokeError("checksum file must contain one canonical SHA-256 line");
40
+ if (match[2] !== basename) throw smokeError("checksum basename does not match the tarball basename");
41
+ return match[1];
42
+ }
43
+
44
+ function archiveNames(text) {
45
+ return text.split("\n").filter((line) => line !== "");
46
+ }
47
+
48
+ export function validateArchiveEntries(names, verboseLines) {
49
+ if (!Array.isArray(names) || !Array.isArray(verboseLines) || names.length !== verboseLines.length) {
50
+ throw smokeError("archive name and verbose listings disagree");
51
+ }
52
+ if (names.length === 0) throw smokeError("archive listing is empty");
53
+
54
+ for (let index = 0; index < names.length; index += 1) {
55
+ const name = names[index];
56
+ const type = verboseLines[index]?.[0];
57
+ if (typeof name !== "string" || name.includes("\\") || name.includes("\0")) {
58
+ throw smokeError("archive contains an unsafe entry name");
59
+ }
60
+ const components = name.split("/");
61
+ if (
62
+ name.startsWith("/")
63
+ || /^[A-Za-z]:/.test(name)
64
+ || components.includes("..")
65
+ || (name !== "package" && name !== "package/" && !name.startsWith("package/"))
66
+ ) {
67
+ throw smokeError("archive entry must stay below the single package/ root");
68
+ }
69
+ if (type !== "-" && type !== "d") {
70
+ throw smokeError(`archive entry type is forbidden for ${name}`);
71
+ }
72
+ if (type === "d" && !name.endsWith("/")) {
73
+ throw smokeError(`archive directory entry is malformed for ${name}`);
74
+ }
75
+ }
76
+ }
77
+
78
+ function forbiddenPackedName(name) {
79
+ const relative = name.startsWith("package/") ? name.slice("package/".length) : name;
80
+ const components = relative.split("/").filter(Boolean);
81
+ if (["dist", "release", "releases", "artifacts"].includes(components[0]?.toLowerCase())) return true;
82
+ return components.some((component) => {
83
+ const lower = component.toLowerCase();
84
+ return lower === ".env"
85
+ || (lower.startsWith(".env.") && lower !== ".env.example")
86
+ || lower.includes("credential")
87
+ || lower === ".npmrc"
88
+ || lower === ".gitignore"
89
+ || lower === ".npmignore"
90
+ || lower.includes("npm-token")
91
+ || lower === ".git"
92
+ || lower === ".github"
93
+ || lower === ".oak"
94
+ || lower === "node_modules"
95
+ || lower === ".cache"
96
+ || lower === "cache"
97
+ || lower === "caches"
98
+ || lower === ".npm"
99
+ || lower === "npm-cache"
100
+ || lower === ".pnpm-store"
101
+ || lower === "dist";
102
+ });
103
+ }
104
+
105
+ export function validatePackedFileSet(names) {
106
+ const files = new Set(names.filter((name) => !name.endsWith("/")));
107
+ for (const required of REQUIRED_FILES) {
108
+ if (!files.has(required)) throw smokeError(`packed file set is missing ${required.slice("package/".length)}`);
109
+ }
110
+ for (const name of names) {
111
+ if (forbiddenPackedName(name)) throw smokeError(`packed file set contains forbidden state: ${name}`);
112
+ }
113
+ }
114
+
115
+ function inspectRegularFile(file) {
116
+ let stat;
117
+ try {
118
+ stat = fs.lstatSync(file);
119
+ } catch {
120
+ throw smokeError(`${path.basename(file)} must be an existing regular file`);
121
+ }
122
+ if (stat.isSymbolicLink() || !stat.isFile()) {
123
+ throw smokeError(`${path.basename(file)} must be a regular non-symlink file`);
124
+ }
125
+ return stat;
126
+ }
127
+
128
+ function captureRegularFile(source, destination) {
129
+ let sourceFd;
130
+ let destinationFd;
131
+ try {
132
+ const initialStat = fs.lstatSync(source);
133
+ if (initialStat.isSymbolicLink() || !initialStat.isFile()) {
134
+ throw smokeError(`${path.basename(source)} must be a regular non-symlink file`);
135
+ }
136
+ sourceFd = fs.openSync(
137
+ source,
138
+ fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0),
139
+ );
140
+ const stat = fs.fstatSync(sourceFd);
141
+ if (!stat.isFile() || stat.dev !== initialStat.dev || stat.ino !== initialStat.ino) {
142
+ throw smokeError(`${path.basename(source)} changed before it could be captured safely`);
143
+ }
144
+ destinationFd = fs.openSync(
145
+ destination,
146
+ fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL,
147
+ 0o600,
148
+ );
149
+ const buffer = Buffer.allocUnsafe(64 * 1024);
150
+ for (;;) {
151
+ const bytesRead = fs.readSync(sourceFd, buffer, 0, buffer.length, null);
152
+ if (bytesRead === 0) break;
153
+ let written = 0;
154
+ while (written < bytesRead) {
155
+ written += fs.writeSync(destinationFd, buffer, written, bytesRead - written);
156
+ }
157
+ }
158
+ return fs.fstatSync(destinationFd);
159
+ } catch (error) {
160
+ if (error.code === "INVALID_PACKAGE") throw error;
161
+ throw smokeError(`${path.basename(source)} must be an existing regular non-symlink file`);
162
+ } finally {
163
+ if (destinationFd !== undefined) fs.closeSync(destinationFd);
164
+ if (sourceFd !== undefined) fs.closeSync(sourceFd);
165
+ }
166
+ }
167
+
168
+ function hashFile(file) {
169
+ const contents = fs.readFileSync(file);
170
+ return {
171
+ sha256: crypto.createHash("sha256").update(contents).digest("hex"),
172
+ sha1: crypto.createHash("sha1").update(contents).digest("hex"),
173
+ sha512: crypto.createHash("sha512").update(contents).digest("hex"),
174
+ };
175
+ }
176
+
177
+ function safeEnvironment(tempRoot) {
178
+ const home = path.join(tempRoot, "home");
179
+ const cache = path.join(tempRoot, "npm-cache");
180
+ fs.mkdirSync(home);
181
+ fs.mkdirSync(cache);
182
+ fs.writeFileSync(path.join(home, ".npmrc"), "");
183
+ return {
184
+ PATH: process.env.PATH ?? "",
185
+ HOME: home,
186
+ npm_config_cache: cache,
187
+ npm_config_userconfig: path.join(home, ".npmrc"),
188
+ CI: "true",
189
+ LANG: process.env.LANG ?? "C",
190
+ };
191
+ }
192
+
193
+ function runCommand(command, args, options = {}) {
194
+ const result = spawnSync(command, args, {
195
+ cwd: options.cwd,
196
+ env: options.env,
197
+ encoding: "utf8",
198
+ maxBuffer: 16 * 1024 * 1024,
199
+ });
200
+ if (result.status !== 0) throw smokeError(options.label ?? `${command} failed`);
201
+ return { stdout: result.stdout, stderr: result.stderr };
202
+ }
203
+
204
+ function makeTempRoot() {
205
+ const parent = (process.env.TMPDIR ?? os.tmpdir()).replace(/\/$/, "");
206
+ const root = fs.mkdtempSync(path.join(parent, "oak-package-smoke."));
207
+ return { parent, root };
208
+ }
209
+
210
+ function removeTempRoot(parent, root) {
211
+ const relative = path.relative(parent, root);
212
+ if (!relative.startsWith("oak-package-smoke.") || relative.includes(path.sep) || path.isAbsolute(relative)) {
213
+ throw smokeError("refusing unsafe package smoke cleanup");
214
+ }
215
+ fs.rmSync(root, { recursive: true, force: true });
216
+ }
217
+
218
+ function readRootPackage(repositoryRoot) {
219
+ try {
220
+ return JSON.parse(fs.readFileSync(path.join(repositoryRoot, "package.json"), "utf8"));
221
+ } catch {
222
+ throw smokeError("canonical package.json could not be read");
223
+ }
224
+ }
225
+
226
+ export async function smokeTarball(options = {}) {
227
+ const repositoryRoot = options.repositoryRoot ?? REPOSITORY_ROOT;
228
+ const input = options.tarball;
229
+ if (typeof input !== "string" || input === "") throw smokeError("tarball input is required");
230
+ const basename = path.basename(input);
231
+ const inspect = options.inspectRegularFile ?? inspectRegularFile;
232
+ const capture = options.captureTarball ?? captureRegularFile;
233
+ const hasher = options.hashFile ?? hashFile;
234
+ const run = options.run ?? ((command, args, commandOptions = {}) => runCommand(command, args, commandOptions));
235
+
236
+ const canonical = readRootPackage(repositoryRoot);
237
+ const expectedBasename = `${canonical.name}-${canonical.version}.tgz`;
238
+ if (basename !== expectedBasename) throw smokeError(`tarball filename must be ${expectedBasename}`);
239
+
240
+ const temporary = makeTempRoot();
241
+ try {
242
+ const capturedTarball = path.join(temporary.root, "captured.tgz");
243
+ const stat = capture(input, capturedTarball);
244
+ const hashes = hasher(capturedTarball);
245
+
246
+ if (options.checksumFile !== undefined) {
247
+ inspect(options.checksumFile);
248
+ let checksumText;
249
+ try {
250
+ checksumText = fs.readFileSync(options.checksumFile, "utf8");
251
+ } catch {
252
+ throw smokeError("checksum file could not be read");
253
+ }
254
+ const expected = parseChecksumFile(checksumText, basename);
255
+ if (expected !== hashes.sha256) throw smokeError("checksum mismatch; archive was not inspected or extracted");
256
+ }
257
+
258
+ const listing = run("tar", ["-tzf", capturedTarball], { label: "archive listing failed" });
259
+ const verbose = run("tar", ["-tvzf", capturedTarball], { label: "archive verbose listing failed" });
260
+ const names = archiveNames(listing.stdout);
261
+ const verboseLines = archiveNames(verbose.stdout);
262
+ validateArchiveEntries(names, verboseLines);
263
+ validatePackedFileSet(names);
264
+
265
+ const extracted = path.join(temporary.root, "extracted");
266
+ fs.mkdirSync(extracted);
267
+ const environment = safeEnvironment(temporary.root);
268
+ run("tar", ["-xzf", capturedTarball, "-C", extracted], { label: "archive extraction failed" });
269
+
270
+ let packed;
271
+ try {
272
+ packed = JSON.parse(fs.readFileSync(path.join(extracted, "package/package.json"), "utf8"));
273
+ } catch {
274
+ throw smokeError("packed package.json could not be read");
275
+ }
276
+ if (packed.name !== canonical.name || packed.version !== canonical.version) {
277
+ throw smokeError("packed package name and version must match the canonical package.json");
278
+ }
279
+
280
+ const packedRoot = path.join(extracted, "package");
281
+ const opencodeRoot = path.join(packedRoot, "opencode");
282
+ run("npm", ["ci", "--ignore-scripts"], {
283
+ cwd: opencodeRoot,
284
+ env: environment,
285
+ label: "packed npm ci failed",
286
+ });
287
+ run(process.execPath, ["--input-type=module", "-e", "import('@opencode-ai/plugin')"], {
288
+ cwd: opencodeRoot,
289
+ env: environment,
290
+ label: "packed SDK import failed",
291
+ });
292
+ run("bash", ["scripts/install-smoke.sh"], {
293
+ cwd: packedRoot,
294
+ env: environment,
295
+ label: "packed installation smoke failed",
296
+ });
297
+ return {
298
+ basename,
299
+ size: stat.size,
300
+ sha256: hashes.sha256,
301
+ sha1: hashes.sha1,
302
+ sha512: hashes.sha512,
303
+ };
304
+ } finally {
305
+ removeTempRoot(temporary.parent, temporary.root);
306
+ }
307
+ }
308
+
309
+ async function main(args) {
310
+ if (!(args.length === 0 || args.length === 1 || (args.length === 3 && args[0] === "--checksum"))) {
311
+ console.error("usage: package-smoke.sh [TARBALL | --checksum SHA256SUMS TARBALL]");
312
+ process.exitCode = 2;
313
+ return;
314
+ }
315
+
316
+ let temporary;
317
+ try {
318
+ let tarball;
319
+ let checksumFile;
320
+ if (args.length === 0) {
321
+ temporary = makeTempRoot();
322
+ const destination = path.join(temporary.root, "pack");
323
+ fs.mkdirSync(destination);
324
+ const environment = safeEnvironment(temporary.root);
325
+ const result = runCommand("npm", ["pack", "--json", "--pack-destination", destination], {
326
+ cwd: REPOSITORY_ROOT,
327
+ env: environment,
328
+ label: "npm pack failed",
329
+ });
330
+ let entries;
331
+ try {
332
+ entries = JSON.parse(result.stdout);
333
+ } catch {
334
+ throw smokeError("npm pack returned invalid JSON");
335
+ }
336
+ if (!Array.isArray(entries) || entries.length !== 1 || path.basename(entries[0]?.filename ?? "") !== entries[0]?.filename) {
337
+ throw smokeError("npm pack must report exactly one public tarball basename");
338
+ }
339
+ tarball = path.join(destination, entries[0].filename);
340
+ } else if (args.length === 1) {
341
+ [tarball] = args;
342
+ } else {
343
+ [, checksumFile, tarball] = args;
344
+ }
345
+ const evidence = await smokeTarball({ repositoryRoot: REPOSITORY_ROOT, tarball, checksumFile });
346
+ process.stdout.write(`${JSON.stringify(evidence)}\n`);
347
+ } catch (error) {
348
+ console.error(`package smoke failed: ${error.message}`);
349
+ process.exitCode = 1;
350
+ } finally {
351
+ if (temporary) removeTempRoot(temporary.parent, temporary.root);
352
+ }
353
+ }
354
+
355
+ if (path.resolve(process.argv[1] ?? "") === SCRIPT_PATH) {
356
+ await main(process.argv.slice(2));
357
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ root="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
5
+ exec node "$root/scripts/package-smoke.mjs" "$@"