opencode-agent-orchestration-kit 1.0.28 → 1.0.30

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 (49) hide show
  1. package/README.md +32 -9
  2. package/docker/open-design/Dockerfile +2 -2
  3. package/docs/compatibility.md +28 -8
  4. package/docs/docker-open-design.md +8 -0
  5. package/docs/installation.md +9 -3
  6. package/docs/quickstart.md +6 -3
  7. package/docs/releases/v1.0.29.md +78 -0
  8. package/docs/releases/v1.0.30.md +64 -0
  9. package/docs/security.md +9 -0
  10. package/docs/superpowers.md +11 -4
  11. package/docs/supply-chain.md +145 -0
  12. package/docs/workflows.md +15 -0
  13. package/opencode/docs/ai/evolution/README.md +15 -2
  14. package/opencode/docs/ai/evolution/benchmarks/replay-fixtures.jsonl +14 -0
  15. package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +14 -8
  16. package/opencode/docs/ai/harness/checks.md +29 -2
  17. package/opencode/docs/ai/harness/evidence.md +29 -0
  18. package/opencode/opencode.json +1 -1
  19. package/opencode/package-lock.json +92 -95
  20. package/opencode/package.json +2 -1
  21. package/opencode/scripts/check-harness.mjs +369 -29
  22. package/opencode/scripts/check-harness.test.mjs +377 -14
  23. package/opencode/scripts/collect-session-evidence.mjs +14 -0
  24. package/opencode/scripts/collect-session-evidence.test.mjs +142 -6
  25. package/opencode/scripts/replay-routing.mjs +1012 -0
  26. package/opencode/scripts/replay-routing.test.mjs +1454 -0
  27. package/opencode/scripts/run-routing-live-replay.mjs +1180 -0
  28. package/opencode/scripts/run-routing-live-replay.test.mjs +1906 -0
  29. package/package.json +25 -3
  30. package/scripts/check-compatibility.mjs +65 -12
  31. package/scripts/check-compatibility.test.mjs +228 -32
  32. package/scripts/check-supply-chain.mjs +635 -0
  33. package/scripts/check-supply-chain.test.mjs +944 -0
  34. package/scripts/check.sh +9 -5
  35. package/scripts/install-smoke.sh +1 -1
  36. package/scripts/opencode-compat-smoke.sh +97 -7
  37. package/scripts/package-smoke.mjs +357 -0
  38. package/scripts/package-smoke.sh +5 -0
  39. package/scripts/package-smoke.test.mjs +256 -0
  40. package/scripts/version.test.mjs +2 -2
  41. package/supply-chain.json +34 -0
  42. package/.github/CODEOWNERS +0 -1
  43. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -65
  44. package/.github/ISSUE_TEMPLATE/config.yml +0 -11
  45. package/.github/ISSUE_TEMPLATE/documentation.yml +0 -22
  46. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -43
  47. package/.github/PULL_REQUEST_TEMPLATE.md +0 -25
  48. package/.github/workflows/check.yml +0 -92
  49. package/.github/workflows/compatibility-canary.yml +0 -28
package/scripts/check.sh CHANGED
@@ -20,10 +20,16 @@ doctor.sh
20
20
  rollback.sh
21
21
  package.json
22
22
  compatibility.json
23
+ supply-chain.json
23
24
  scripts/version.mjs
24
25
  scripts/version.test.mjs
25
26
  scripts/check-compatibility.mjs
26
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
27
33
  scripts/opencode-compat-smoke.sh
28
34
  scripts/manage-installation.mjs
29
35
  scripts/manage-installation.test.mjs
@@ -56,6 +62,7 @@ docker/open-design/Dockerfile
56
62
  docker/open-design/docker-compose.yml
57
63
  docker/open-design/.env.example
58
64
  docker/open-design/opencode-od/opencode.json
65
+ docs/supply-chain.md
59
66
  CODE_OF_CONDUCT.md
60
67
  CONTRIBUTING.md
61
68
  .github/PULL_REQUEST_TEMPLATE.md
@@ -72,12 +79,13 @@ for file in $required_files; do
72
79
  test -f "$file" || { echo "Missing required file: $file" >&2; exit 1; }
73
80
  done
74
81
 
75
- for file in install.sh uninstall.sh upgrade.sh doctor.sh rollback.sh scripts/check.sh scripts/opencode-compat-smoke.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
76
83
  test -x "$file" || { echo "Not executable: $file" >&2; exit 1; }
77
84
  done
78
85
 
79
86
  node scripts/version.mjs --check
80
87
  node scripts/check-compatibility.mjs
88
+ node scripts/check-supply-chain.mjs
81
89
 
82
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')"
83
91
  (cd opencode && node scripts/check-harness.mjs)
@@ -96,7 +104,6 @@ for (const dir of ['opencode/agents', 'opencode/commands', ...fs.readdirSync('op
96
104
  console.log('frontmatter ok')
97
105
  NODE
98
106
 
99
- grep -q 'superpowers@git+https://github.com/obra/superpowers.git' opencode/opencode.json
100
107
  grep -q '"default_agent": "lead"' opencode/opencode.json
101
108
  grep -q './plugins/token-tree-usage.tsx' opencode/tui.json
102
109
 
@@ -161,9 +168,6 @@ if (opencodePackage.dependencies?.['@opentui/solid'] !== '0.2.5') {
161
168
  if (opencodePackage.dependencies?.['solid-js'] !== '1.9.12') {
162
169
  throw new Error('opencode/package.json must pin solid-js to 1.9.12')
163
170
  }
164
- if (opencodePackage.overrides?.uuid !== '^14.0.0') {
165
- throw new Error('opencode/package.json must override uuid to ^14.0.0')
166
- }
167
171
  NODE
168
172
 
169
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
  )
@@ -3,12 +3,16 @@ set -euo pipefail
3
3
 
4
4
  canonical_version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
5
5
 
6
- if [[ $# -ne 1 ]] || [[ "$1" != "latest" && ! "$1" =~ $canonical_version_re ]]; then
7
- echo "usage: $0 MAJOR.MINOR.PATCH|latest" >&2
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
8
11
  exit 2
9
12
  fi
10
13
 
11
- request="$1"
14
+ mode="$1"
15
+ request="$2"
12
16
  root="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
13
17
  original_home="${HOME-}"
14
18
  temp_base="${TMPDIR:-/tmp}"
@@ -33,21 +37,75 @@ mkdir -p \
33
37
  "$smoke_root/data" \
34
38
  "$smoke_root/cache" \
35
39
  "$smoke_root/state" \
36
- "$smoke_root/npm"
40
+ "$smoke_root/npm" \
41
+ "$smoke_root/pack" \
42
+ "$smoke_root/extracted"
37
43
  diagnostics_file="$smoke_root/diagnostics"
38
44
  : >"$diagnostics_file"
39
45
  test -f "$diagnostics_file" && test ! -L "$diagnostics_file"
40
46
 
41
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
+
42
99
  target_config="$smoke_root/config/opencode"
43
100
  test ! -e "$target_config"
44
101
 
45
- node - "$source_config" "$target_config" <<'NODE'
102
+ node - "$source_config" "$target_config" "$mode" <<'NODE'
46
103
  const fs = require("node:fs");
47
104
  const path = require("node:path");
48
105
 
49
106
  const sourceRoot = process.argv[2];
50
107
  const targetRoot = process.argv[3];
108
+ const mode = process.argv[4];
51
109
 
52
110
  fs.cpSync(sourceRoot, targetRoot, {
53
111
  recursive: true,
@@ -60,10 +118,19 @@ fs.cpSync(sourceRoot, targetRoot, {
60
118
  const relative = path.relative(sourceRoot, source);
61
119
  if (relative === "") return true;
62
120
  return !relative.split(path.sep).some((component) =>
63
- component === "node_modules" || component === ".oak"
121
+ component === "node_modules"
122
+ || component === ".oak"
123
+ || (mode === "core" && component === "plugins")
64
124
  );
65
125
  },
66
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
+ }
67
134
  NODE
68
135
 
69
136
  if [[ ! -f "$target_config/agents/lead.md" || -e "$target_config/opencode" ]]; then
@@ -71,6 +138,29 @@ if [[ ! -f "$target_config/agents/lead.md" || -e "$target_config/opencode" ]]; t
71
138
  exit 1
72
139
  fi
73
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
+
74
164
  run_isolated() (
75
165
  cd "$smoke_root/home"
76
166
  env -i \
@@ -171,4 +261,4 @@ if contains_forbidden_path "$diagnostics"; then
171
261
  exit 1
172
262
  fi
173
263
  emit_safe_diagnostics
174
- printf 'opencode compatibility smoke ok: requested=%s resolved=%s\n' "$request" "$actual"
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" "$@"