opencode-ai 1.14.51 → 1.15.1

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.
@@ -0,0 +1,10 @@
1
+ echo "Error: opencode-ai's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when using --ignore-scripts during installation, or when using a" >&2
4
+ echo "package manager like pnpm that does not run postinstall scripts by default." >&2
5
+ echo "" >&2
6
+ echo "To fix this, run the postinstall script manually:" >&2
7
+ echo " cd node_modules/opencode-ai && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall opencode-ai without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json CHANGED
@@ -1,25 +1,34 @@
1
1
  {
2
2
  "name": "opencode-ai",
3
3
  "bin": {
4
- "opencode": "./bin/opencode"
4
+ "opencode": "./bin/opencode.exe"
5
5
  },
6
6
  "scripts": {
7
- "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
7
+ "postinstall": "node ./postinstall.mjs"
8
8
  },
9
- "version": "1.14.51",
9
+ "version": "1.15.1",
10
10
  "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
11
20
  "optionalDependencies": {
12
- "opencode-linux-x64-baseline": "1.14.51",
13
- "opencode-windows-x64-baseline": "1.14.51",
14
- "opencode-darwin-arm64": "1.14.51",
15
- "opencode-linux-x64-baseline-musl": "1.14.51",
16
- "opencode-windows-arm64": "1.14.51",
17
- "opencode-darwin-x64": "1.14.51",
18
- "opencode-linux-arm64-musl": "1.14.51",
19
- "opencode-linux-x64-musl": "1.14.51",
20
- "opencode-windows-x64": "1.14.51",
21
- "opencode-linux-arm64": "1.14.51",
22
- "opencode-darwin-x64-baseline": "1.14.51",
23
- "opencode-linux-x64": "1.14.51"
21
+ "opencode-windows-x64": "1.15.1",
22
+ "opencode-windows-x64-baseline": "1.15.1",
23
+ "opencode-linux-x64-baseline": "1.15.1",
24
+ "opencode-linux-arm64": "1.15.1",
25
+ "opencode-windows-arm64": "1.15.1",
26
+ "opencode-linux-x64-musl": "1.15.1",
27
+ "opencode-linux-x64": "1.15.1",
28
+ "opencode-darwin-x64-baseline": "1.15.1",
29
+ "opencode-linux-x64-baseline-musl": "1.15.1",
30
+ "opencode-darwin-x64": "1.15.1",
31
+ "opencode-linux-arm64-musl": "1.15.1",
32
+ "opencode-darwin-arm64": "1.15.1"
24
33
  }
25
34
  }
package/postinstall.mjs CHANGED
@@ -1,102 +1,189 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import childProcess from "child_process"
3
4
  import fs from "fs"
4
- import path from "path"
5
5
  import os from "os"
6
- import { fileURLToPath } from "url"
6
+ import path from "path"
7
7
  import { createRequire } from "module"
8
+ import { fileURLToPath } from "url"
8
9
 
9
10
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
11
  const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
13
+
14
+ const platformMap = {
15
+ darwin: "darwin",
16
+ linux: "linux",
17
+ win32: "windows",
18
+ }
19
+ const archMap = {
20
+ x64: "x64",
21
+ arm64: "arm64",
22
+ arm: "arm",
23
+ }
24
+
25
+ const platform = platformMap[os.platform()] ?? os.platform()
26
+ const arch = archMap[os.arch()] ?? os.arch()
27
+ const base = `opencode-${platform}-${arch}`
28
+ const sourceBinary = platform === "windows" ? "opencode.exe" : "opencode"
29
+ const targetBinary = path.join(__dirname, "bin", "opencode.exe")
30
+
31
+ function supportsAvx2() {
32
+ if (arch !== "x64") return false
33
+
34
+ if (platform === "linux") {
35
+ try {
36
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
37
+ } catch {
38
+ return false
39
+ }
40
+ }
11
41
 
12
- function detectPlatformAndArch() {
13
- // Map platform names
14
- let platform
15
- switch (os.platform()) {
16
- case "darwin":
17
- platform = "darwin"
18
- break
19
- case "linux":
20
- platform = "linux"
21
- break
22
- case "win32":
23
- platform = "windows"
24
- break
25
- default:
26
- platform = os.platform()
27
- break
42
+ if (platform === "darwin") {
43
+ try {
44
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
45
+ encoding: "utf8",
46
+ timeout: 1500,
47
+ })
48
+ if (result.status !== 0) return false
49
+ return (result.stdout || "").trim() === "1"
50
+ } catch {
51
+ return false
52
+ }
28
53
  }
29
54
 
30
- // Map architecture names
31
- let arch
32
- switch (os.arch()) {
33
- case "x64":
34
- arch = "x64"
35
- break
36
- case "arm64":
37
- arch = "arm64"
38
- break
39
- case "arm":
40
- arch = "arm"
41
- break
42
- default:
43
- arch = os.arch()
44
- break
55
+ if (platform === "windows") {
56
+ const command =
57
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
58
+
59
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
60
+ try {
61
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
62
+ encoding: "utf8",
63
+ timeout: 3000,
64
+ windowsHide: true,
65
+ })
66
+ if (result.status !== 0) continue
67
+ const output = (result.stdout || "").trim().toLowerCase()
68
+ if (output === "true" || output === "1") return true
69
+ if (output === "false" || output === "0") return false
70
+ } catch {
71
+ continue
72
+ }
73
+ }
45
74
  }
46
75
 
47
- return { platform, arch }
76
+ return false
48
77
  }
49
78
 
50
- function findBinary() {
51
- const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `opencode-${platform}-${arch}`
53
- const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
79
+ function isMusl() {
80
+ if (platform !== "linux") return false
54
81
 
55
82
  try {
56
- // Use require.resolve to find the package
57
- const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
- const packageDir = path.dirname(packageJsonPath)
59
- const binaryPath = path.join(packageDir, "bin", binaryName)
83
+ if (fs.existsSync("/etc/alpine-release")) return true
84
+ } catch {
85
+ // Ignore filesystem probes that are blocked by the host.
86
+ }
60
87
 
61
- if (!fs.existsSync(binaryPath)) {
62
- throw new Error(`Binary not found at ${binaryPath}`)
88
+ try {
89
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
90
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
91
+ } catch {
92
+ return false
93
+ }
94
+ }
95
+
96
+ function packageNames() {
97
+ const baseline = arch === "x64" && !supportsAvx2()
98
+
99
+ if (platform === "linux") {
100
+ if (isMusl()) {
101
+ if (arch === "x64")
102
+ return baseline
103
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
104
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
105
+ return [`${base}-musl`, base]
63
106
  }
64
107
 
65
- return { binaryPath, binaryName }
66
- } catch (error) {
67
- throw new Error(`Could not find package ${packageName}: ${error.message}`, { cause: error })
108
+ if (arch === "x64")
109
+ return baseline
110
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
111
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
112
+ return [base, `${base}-musl`]
68
113
  }
114
+
115
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
116
+ return [base]
117
+ }
118
+
119
+ function resolveBinary(name) {
120
+ const packageJsonPath = require.resolve(`${name}/package.json`)
121
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
122
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
123
+ return binaryPath
69
124
  }
70
125
 
71
- async function main() {
126
+ function installPackage(name) {
127
+ const version = packageJson.optionalDependencies?.[name]
128
+ if (!version) return
129
+
130
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
72
131
  try {
73
- if (os.platform() === "win32") {
74
- // On Windows, the .exe is already included in the package and bin field points to it
75
- // No postinstall setup needed
76
- console.log("Windows detected: binary setup not needed (using packaged .exe)")
77
- return
78
- }
132
+ const result = childProcess.spawnSync(
133
+ "npm",
134
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
135
+ { stdio: "inherit", windowsHide: true },
136
+ )
137
+ if (result.status !== 0) return
138
+ const packageDir = path.join(temp, "node_modules", name)
139
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
140
+ return true
141
+ } finally {
142
+ fs.rmSync(temp, { recursive: true, force: true })
143
+ }
144
+ }
79
145
 
80
- // On non-Windows platforms, just verify the binary package exists
81
- // Don't replace the wrapper script - it handles binary execution
82
- const { binaryPath } = findBinary()
83
- const target = path.join(__dirname, "bin", ".opencode")
84
- if (fs.existsSync(target)) fs.unlinkSync(target)
146
+ function copyBinary(source, target) {
147
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
148
+ fs.mkdirSync(path.dirname(target), { recursive: true })
149
+ if (fs.existsSync(target)) fs.unlinkSync(target)
150
+ try {
151
+ fs.linkSync(source, target)
152
+ } catch {
153
+ fs.copyFileSync(source, target)
154
+ }
155
+ fs.chmodSync(target, 0o755)
156
+ }
157
+
158
+ function verifyBinary() {
159
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
160
+ encoding: "utf8",
161
+ stdio: "ignore",
162
+ windowsHide: true,
163
+ })
164
+ return result.status === 0
165
+ }
166
+
167
+ function main() {
168
+ for (const name of packageNames()) {
85
169
  try {
86
- fs.linkSync(binaryPath, target)
170
+ copyBinary(resolveBinary(name), targetBinary)
171
+ if (verifyBinary()) return
87
172
  } catch {
88
- fs.copyFileSync(binaryPath, target)
173
+ if (installPackage(name) && verifyBinary()) return
89
174
  }
90
- fs.chmodSync(target, 0o755)
91
- } catch (error) {
92
- console.error("Failed to setup opencode binary:", error.message)
93
- process.exit(1)
94
175
  }
176
+
177
+ throw new Error(
178
+ `It seems your package manager failed to install the right opencode CLI package. Try manually installing ${packageNames()
179
+ .map((name) => JSON.stringify(name))
180
+ .join(" or ")}.`,
181
+ )
95
182
  }
96
183
 
97
184
  try {
98
- void main()
185
+ main()
99
186
  } catch (error) {
100
- console.error("Postinstall script error:", error.message)
101
- process.exit(0)
187
+ console.error(error.message)
188
+ process.exit(1)
102
189
  }
package/bin/opencode DELETED
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const childProcess = require("child_process")
4
- const fs = require("fs")
5
- const path = require("path")
6
- const os = require("os")
7
-
8
- const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
9
-
10
- function run(target) {
11
- const child = childProcess.spawn(target, process.argv.slice(2), {
12
- stdio: "inherit",
13
- })
14
-
15
- child.on("error", (error) => {
16
- console.error(error.message)
17
- process.exit(1)
18
- })
19
-
20
- const forwarders = {}
21
- for (const signal of forwardedSignals) {
22
- forwarders[signal] = () => {
23
- try {
24
- child.kill(signal)
25
- } catch {
26
- // The child may have already exited.
27
- }
28
- }
29
- process.on(signal, forwarders[signal])
30
- }
31
-
32
- child.on("exit", (code, signal) => {
33
- for (const forwardedSignal of forwardedSignals) {
34
- process.removeListener(forwardedSignal, forwarders[forwardedSignal])
35
- }
36
-
37
- if (signal) {
38
- process.kill(process.pid, signal)
39
- return
40
- }
41
-
42
- process.exit(typeof code === "number" ? code : 0)
43
- })
44
- }
45
-
46
- const envPath = process.env.OPENCODE_BIN_PATH
47
-
48
- const scriptPath = fs.realpathSync(__filename)
49
- const scriptDir = path.dirname(scriptPath)
50
-
51
- //
52
- const cached = path.join(scriptDir, ".opencode")
53
-
54
- const platformMap = {
55
- darwin: "darwin",
56
- linux: "linux",
57
- win32: "windows",
58
- }
59
- const archMap = {
60
- x64: "x64",
61
- arm64: "arm64",
62
- arm: "arm",
63
- }
64
-
65
- let platform = platformMap[os.platform()]
66
- if (!platform) {
67
- platform = os.platform()
68
- }
69
- let arch = archMap[os.arch()]
70
- if (!arch) {
71
- arch = os.arch()
72
- }
73
- const base = "opencode-" + platform + "-" + arch
74
- const binary = platform === "windows" ? "opencode.exe" : "opencode"
75
-
76
- function supportsAvx2() {
77
- if (arch !== "x64") return false
78
-
79
- if (platform === "linux") {
80
- try {
81
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
82
- } catch {
83
- return false
84
- }
85
- }
86
-
87
- if (platform === "darwin") {
88
- try {
89
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
90
- encoding: "utf8",
91
- timeout: 1500,
92
- })
93
- if (result.status !== 0) return false
94
- return (result.stdout || "").trim() === "1"
95
- } catch {
96
- return false
97
- }
98
- }
99
-
100
- if (platform === "windows") {
101
- const cmd =
102
- '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
103
-
104
- for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
105
- try {
106
- const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
107
- encoding: "utf8",
108
- timeout: 3000,
109
- windowsHide: true,
110
- })
111
- if (result.status !== 0) continue
112
- const out = (result.stdout || "").trim().toLowerCase()
113
- if (out === "true" || out === "1") return true
114
- if (out === "false" || out === "0") return false
115
- } catch {
116
- continue
117
- }
118
- }
119
-
120
- return false
121
- }
122
-
123
- return false
124
- }
125
-
126
- const names = (() => {
127
- const avx2 = supportsAvx2()
128
- const baseline = arch === "x64" && !avx2
129
-
130
- if (platform === "linux") {
131
- const musl = (() => {
132
- try {
133
- if (fs.existsSync("/etc/alpine-release")) return true
134
- } catch {
135
- // ignore
136
- }
137
-
138
- try {
139
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
140
- const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
141
- if (text.includes("musl")) return true
142
- } catch {
143
- // ignore
144
- }
145
-
146
- return false
147
- })()
148
-
149
- if (musl) {
150
- if (arch === "x64") {
151
- if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
152
- return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
153
- }
154
- return [`${base}-musl`, base]
155
- }
156
-
157
- if (arch === "x64") {
158
- if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
159
- return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
160
- }
161
- return [base, `${base}-musl`]
162
- }
163
-
164
- if (arch === "x64") {
165
- if (baseline) return [`${base}-baseline`, base]
166
- return [base, `${base}-baseline`]
167
- }
168
- return [base]
169
- })()
170
-
171
- function findBinary(startDir) {
172
- let current = startDir
173
- for (;;) {
174
- const modules = path.join(current, "node_modules")
175
- if (fs.existsSync(modules)) {
176
- for (const name of names) {
177
- const candidate = path.join(modules, name, "bin", binary)
178
- if (fs.existsSync(candidate)) return candidate
179
- }
180
- }
181
- const parent = path.dirname(current)
182
- if (parent === current) {
183
- return
184
- }
185
- current = parent
186
- }
187
- }
188
-
189
- const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
190
- if (!resolved) {
191
- console.error(
192
- "It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing " +
193
- names.map((n) => `\"${n}\"`).join(" or ") +
194
- " package",
195
- )
196
- process.exit(1)
197
- }
198
-
199
- run(resolved)