@dingmenghua/opencode-max 1.15.3-max.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ echo "Error: opencode-max'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-max && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall opencode-max without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@dingmenghua/opencode-max",
3
+ "bin": {
4
+ "opencode-max": "./bin/opencode-max.exe"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "1.15.3-max.0",
10
+ "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
20
+ "optionalDependencies": {
21
+ "opencode-max-linux-arm64-musl": "1.15.3-max.0",
22
+ "opencode-max-linux-x64-baseline-musl": "1.15.3-max.0",
23
+ "opencode-max-darwin-arm64": "1.15.3-max.0",
24
+ "opencode-max-windows-arm64": "1.15.3-max.0",
25
+ "opencode-max-windows-x64": "1.15.3-max.0",
26
+ "opencode-max-darwin-x64": "1.15.3-max.0",
27
+ "opencode-max-linux-arm64": "1.15.3-max.0",
28
+ "opencode-max-linux-x64-baseline": "1.15.3-max.0",
29
+ "opencode-max-darwin-x64-baseline": "1.15.3-max.0",
30
+ "opencode-max-linux-x64-musl": "1.15.3-max.0"
31
+ },
32
+ "opencodeMax": {
33
+ "distributionName": "opencode-max",
34
+ "commandName": "opencode-max"
35
+ }
36
+ }
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "child_process"
4
+ import fs from "fs"
5
+ import os from "os"
6
+ import path from "path"
7
+ import { createRequire } from "module"
8
+ import { fileURLToPath } from "url"
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
13
+ const distributionName = packageJson.opencodeMax?.distributionName ?? packageJson.name
14
+ const commandName = packageJson.opencodeMax?.commandName ?? packageJson.name.split("/").pop()
15
+
16
+ const platformMap = {
17
+ darwin: "darwin",
18
+ linux: "linux",
19
+ win32: "windows",
20
+ }
21
+ const archMap = {
22
+ x64: "x64",
23
+ arm64: "arm64",
24
+ arm: "arm",
25
+ }
26
+
27
+ const platform = platformMap[os.platform()] ?? os.platform()
28
+ const arch = archMap[os.arch()] ?? os.arch()
29
+ const base = `${distributionName}-${platform}-${arch}`
30
+ const sourceBinary = platform === "windows" ? "opencode.exe" : "opencode"
31
+ const targetBinary = path.join(__dirname, "bin", `${commandName}.exe`)
32
+
33
+ function supportsAvx2() {
34
+ if (arch !== "x64") return false
35
+
36
+ if (platform === "linux") {
37
+ try {
38
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
39
+ } catch {
40
+ return false
41
+ }
42
+ }
43
+
44
+ if (platform === "darwin") {
45
+ try {
46
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
47
+ encoding: "utf8",
48
+ timeout: 1500,
49
+ })
50
+ if (result.status !== 0) return false
51
+ return (result.stdout || "").trim() === "1"
52
+ } catch {
53
+ return false
54
+ }
55
+ }
56
+
57
+ if (platform === "windows") {
58
+ const command =
59
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
60
+
61
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
62
+ try {
63
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
64
+ encoding: "utf8",
65
+ timeout: 3000,
66
+ windowsHide: true,
67
+ })
68
+ if (result.status !== 0) continue
69
+ const output = (result.stdout || "").trim().toLowerCase()
70
+ if (output === "true" || output === "1") return true
71
+ if (output === "false" || output === "0") return false
72
+ } catch {
73
+ continue
74
+ }
75
+ }
76
+ }
77
+
78
+ return false
79
+ }
80
+
81
+ function isMusl() {
82
+ if (platform !== "linux") return false
83
+
84
+ try {
85
+ if (fs.existsSync("/etc/alpine-release")) return true
86
+ } catch {
87
+ // Ignore filesystem probes that are blocked by the host.
88
+ }
89
+
90
+ try {
91
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
92
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
93
+ } catch {
94
+ return false
95
+ }
96
+ }
97
+
98
+ function packageNames() {
99
+ const baseline = arch === "x64" && !supportsAvx2()
100
+
101
+ if (platform === "linux") {
102
+ if (isMusl()) {
103
+ if (arch === "x64")
104
+ return baseline
105
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
106
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
107
+ return [`${base}-musl`, base]
108
+ }
109
+
110
+ if (arch === "x64")
111
+ return baseline
112
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
113
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
114
+ return [base, `${base}-musl`]
115
+ }
116
+
117
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
118
+ return [base]
119
+ }
120
+
121
+ function resolveBinary(name) {
122
+ const packageJsonPath = require.resolve(`${name}/package.json`)
123
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
124
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
125
+ return binaryPath
126
+ }
127
+
128
+ function installPackage(name) {
129
+ const version = packageJson.optionalDependencies?.[name]
130
+ if (!version) return
131
+
132
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), `${distributionName}-install-`))
133
+ try {
134
+ const result = childProcess.spawnSync(
135
+ "npm",
136
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
137
+ { stdio: "inherit", windowsHide: true },
138
+ )
139
+ if (result.status !== 0) return
140
+ const packageDir = path.join(temp, "node_modules", name)
141
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
142
+ return true
143
+ } finally {
144
+ fs.rmSync(temp, { recursive: true, force: true })
145
+ }
146
+ }
147
+
148
+ function copyBinary(source, target) {
149
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
150
+ fs.mkdirSync(path.dirname(target), { recursive: true })
151
+ if (fs.existsSync(target)) fs.unlinkSync(target)
152
+ try {
153
+ fs.linkSync(source, target)
154
+ } catch {
155
+ fs.copyFileSync(source, target)
156
+ }
157
+ fs.chmodSync(target, 0o755)
158
+ }
159
+
160
+ function verifyBinary() {
161
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
162
+ encoding: "utf8",
163
+ stdio: "ignore",
164
+ windowsHide: true,
165
+ })
166
+ return result.status === 0
167
+ }
168
+
169
+ function main() {
170
+ for (const name of packageNames()) {
171
+ try {
172
+ copyBinary(resolveBinary(name), targetBinary)
173
+ if (verifyBinary()) return
174
+ } catch {
175
+ if (installPackage(name) && verifyBinary()) return
176
+ }
177
+ }
178
+
179
+ throw new Error(
180
+ `It seems your package manager failed to install the right ${commandName} CLI package. Try manually installing ${packageNames()
181
+ .map((name) => JSON.stringify(name))
182
+ .join(" or ")}.`,
183
+ )
184
+ }
185
+
186
+ try {
187
+ main()
188
+ } catch (error) {
189
+ console.error(error.message)
190
+ process.exit(1)
191
+ }