@opencode-ai/cli 0.0.0-dev-202608141824 → 0.0.0-dev-17471

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,5 @@
1
+ echo "Error: @opencode-ai/cli's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when installation scripts are disabled." >&2
4
+ echo "Run the package postinstall script or reinstall with scripts enabled." >&2
5
+ exit 1
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@opencode-ai/cli",
3
3
  "bin": {
4
- "lildax": "./bin/lildax"
4
+ "opencode2": "./bin/opencode2.exe"
5
5
  },
6
- "version": "0.0.0-dev-202608141824",
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.0-dev-17471",
7
10
  "license": "MIT",
8
11
  "repository": {
9
12
  "type": "git",
@@ -19,17 +22,17 @@
19
22
  "x64"
20
23
  ],
21
24
  "optionalDependencies": {
22
- "@opencode-ai/cli-darwin-x64-baseline": "0.0.0-dev-202608141824",
23
- "@opencode-ai/cli-windows-arm64": "0.0.0-dev-202608141824",
24
- "@opencode-ai/cli-linux-arm64": "0.0.0-dev-202608141824",
25
- "@opencode-ai/cli-linux-x64-musl": "0.0.0-dev-202608141824",
26
- "@opencode-ai/cli-darwin-arm64": "0.0.0-dev-202608141824",
27
- "@opencode-ai/cli-darwin-x64": "0.0.0-dev-202608141824",
28
- "@opencode-ai/cli-windows-x64-baseline": "0.0.0-dev-202608141824",
29
- "@opencode-ai/cli-linux-x64-baseline": "0.0.0-dev-202608141824",
30
- "@opencode-ai/cli-windows-x64": "0.0.0-dev-202608141824",
31
- "@opencode-ai/cli-linux-x64": "0.0.0-dev-202608141824",
32
- "@opencode-ai/cli-linux-arm64-musl": "0.0.0-dev-202608141824",
33
- "@opencode-ai/cli-linux-x64-baseline-musl": "0.0.0-dev-202608141824"
25
+ "@opencode-ai/cli-linux-x64-musl": "0.0.0-dev-17471",
26
+ "@opencode-ai/cli-windows-arm64": "0.0.0-dev-17471",
27
+ "@opencode-ai/cli-linux-arm64": "0.0.0-dev-17471",
28
+ "@opencode-ai/cli-linux-x64-baseline": "0.0.0-dev-17471",
29
+ "@opencode-ai/cli-darwin-arm64": "0.0.0-dev-17471",
30
+ "@opencode-ai/cli-linux-x64": "0.0.0-dev-17471",
31
+ "@opencode-ai/cli-linux-x64-baseline-musl": "0.0.0-dev-17471",
32
+ "@opencode-ai/cli-darwin-x64-baseline": "0.0.0-dev-17471",
33
+ "@opencode-ai/cli-windows-x64": "0.0.0-dev-17471",
34
+ "@opencode-ai/cli-linux-arm64-musl": "0.0.0-dev-17471",
35
+ "@opencode-ai/cli-windows-x64-baseline": "0.0.0-dev-17471",
36
+ "@opencode-ai/cli-darwin-x64": "0.0.0-dev-17471"
34
37
  }
35
38
  }
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "node:child_process"
4
+ import fs from "node:fs"
5
+ import os from "node:os"
6
+ import path from "node:path"
7
+ import { createRequire } from "node:module"
8
+ import { fileURLToPath } from "node:url"
9
+
10
+ const directory = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"))
13
+ const command = Object.keys(packageJson.bin ?? {})[0]
14
+ if (!command) throw new Error("OpenCode package does not declare a binary")
15
+
16
+ const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform()
17
+ const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch()
18
+ const sourceBinary = platform === "windows" ? `${command}.exe` : command
19
+ const targetBinary = path.resolve(directory, packageJson.bin[command])
20
+ const dependencies = packageJson.optionalDependencies ?? {}
21
+ const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`))
22
+ if (!base) throw new Error(`OpenCode does not provide a binary for ${platform}-${arch}`)
23
+
24
+ function supportsAvx2() {
25
+ if (arch !== "x64") return false
26
+ if (platform === "linux") {
27
+ try {
28
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
29
+ } catch {
30
+ return false
31
+ }
32
+ }
33
+ if (platform === "darwin") {
34
+ try {
35
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
36
+ encoding: "utf8",
37
+ timeout: 1500,
38
+ })
39
+ return result.status === 0 && (result.stdout || "").trim() === "1"
40
+ } catch {
41
+ return false
42
+ }
43
+ }
44
+ if (platform === "windows") {
45
+ const script =
46
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
47
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
48
+ try {
49
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", script], {
50
+ encoding: "utf8",
51
+ timeout: 3000,
52
+ windowsHide: true,
53
+ })
54
+ if (result.status !== 0) continue
55
+ const output = (result.stdout || "").trim().toLowerCase()
56
+ if (output === "true" || output === "1") return true
57
+ if (output === "false" || output === "0") return false
58
+ } catch {
59
+ continue
60
+ }
61
+ }
62
+ }
63
+ return false
64
+ }
65
+
66
+ function isMusl() {
67
+ if (platform !== "linux") return false
68
+ try {
69
+ if (fs.existsSync("/etc/alpine-release")) return true
70
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
71
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
72
+ } catch {
73
+ return false
74
+ }
75
+ }
76
+
77
+ function packageNames() {
78
+ const baseline = arch === "x64" && !supportsAvx2()
79
+ const names =
80
+ platform === "linux"
81
+ ? isMusl()
82
+ ? arch === "x64"
83
+ ? baseline
84
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
85
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
86
+ : [`${base}-musl`, base]
87
+ : arch === "x64"
88
+ ? baseline
89
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
90
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
91
+ : [base, `${base}-musl`]
92
+ : arch === "x64"
93
+ ? baseline
94
+ ? [`${base}-baseline`, base]
95
+ : [base, `${base}-baseline`]
96
+ : [base]
97
+ return names.filter((name) => dependencies[name])
98
+ }
99
+
100
+ function copyBinary(source) {
101
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
102
+ fs.mkdirSync(path.dirname(targetBinary), { recursive: true })
103
+ if (fs.existsSync(targetBinary)) fs.unlinkSync(targetBinary)
104
+ try {
105
+ fs.linkSync(source, targetBinary)
106
+ } catch {
107
+ fs.copyFileSync(source, targetBinary)
108
+ }
109
+ fs.chmodSync(targetBinary, 0o755)
110
+ }
111
+
112
+ function resolveBinary(name) {
113
+ const packagePath = require.resolve(`${name}/package.json`)
114
+ return path.join(path.dirname(packagePath), "bin", sourceBinary)
115
+ }
116
+
117
+ function installPackage(name) {
118
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
119
+ try {
120
+ const result = childProcess.spawnSync(
121
+ "npm",
122
+ [
123
+ "install",
124
+ "--ignore-scripts",
125
+ "--no-save",
126
+ "--loglevel=error",
127
+ "--prefix",
128
+ temp,
129
+ `${name}@${dependencies[name]}`,
130
+ ],
131
+ { stdio: "inherit", windowsHide: true },
132
+ )
133
+ if (result.status !== 0) return false
134
+ copyBinary(path.join(temp, "node_modules", name, "bin", sourceBinary))
135
+ return true
136
+ } finally {
137
+ fs.rmSync(temp, { recursive: true, force: true })
138
+ }
139
+ }
140
+
141
+ function verifyBinary() {
142
+ return (
143
+ childProcess.spawnSync(targetBinary, ["--version"], {
144
+ stdio: "ignore",
145
+ windowsHide: true,
146
+ }).status === 0
147
+ )
148
+ }
149
+
150
+ function main() {
151
+ const names = packageNames()
152
+ for (const name of names) {
153
+ try {
154
+ copyBinary(resolveBinary(name))
155
+ if (verifyBinary()) return
156
+ } catch {
157
+ if (installPackage(name) && verifyBinary()) return
158
+ }
159
+ }
160
+
161
+ throw new Error(
162
+ `Failed to install OpenCode. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
163
+ )
164
+ }
165
+
166
+ try {
167
+ main()
168
+ } catch (error) {
169
+ console.error(error instanceof Error ? error.message : String(error))
170
+ process.exit(1)
171
+ }
package/bin/lildax DELETED
@@ -1,130 +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), { stdio: "inherit" })
12
- child.on("error", (error) => {
13
- console.error(error.message)
14
- process.exit(1)
15
- })
16
- const forwarders = {}
17
- for (const signal of forwardedSignals) {
18
- forwarders[signal] = () => {
19
- try {
20
- child.kill(signal)
21
- } catch {}
22
- }
23
- process.on(signal, forwarders[signal])
24
- }
25
- child.on("exit", (code, signal) => {
26
- for (const forwardedSignal of forwardedSignals) process.removeListener(forwardedSignal, forwarders[forwardedSignal])
27
- if (signal) return process.kill(process.pid, signal)
28
- process.exit(typeof code === "number" ? code : 0)
29
- })
30
- }
31
-
32
- const envPath = process.env.OPENCODE_BIN_PATH
33
- const scriptDir = path.dirname(fs.realpathSync(__filename))
34
- const cached = path.join(scriptDir, ".lildax")
35
- const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] || os.platform()
36
- const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] || os.arch()
37
- const base = "@opencode-ai/cli-" + platform + "-" + arch
38
- const binary = platform === "windows" ? "lildax.exe" : "lildax"
39
-
40
- function supportsAvx2() {
41
- if (arch !== "x64") return false
42
- if (platform === "linux") {
43
- try {
44
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
45
- } catch {
46
- return false
47
- }
48
- }
49
- if (platform === "darwin") {
50
- try {
51
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], { encoding: "utf8", timeout: 1500 })
52
- return result.status === 0 && (result.stdout || "").trim() === "1"
53
- } catch {
54
- return false
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
- for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
61
- try {
62
- const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
63
- encoding: "utf8",
64
- timeout: 3000,
65
- windowsHide: true,
66
- })
67
- if (result.status !== 0) continue
68
- const output = (result.stdout || "").trim().toLowerCase()
69
- if (output === "true" || output === "1") return true
70
- if (output === "false" || output === "0") return false
71
- } catch {
72
- continue
73
- }
74
- }
75
- }
76
- return false
77
- }
78
-
79
- const names = (() => {
80
- const baseline = arch === "x64" && !supportsAvx2()
81
- if (platform === "linux") {
82
- const musl = (() => {
83
- try {
84
- if (fs.existsSync("/etc/alpine-release")) return true
85
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
86
- return ((result.stdout || "") + (result.stderr || "")).toLowerCase().includes("musl")
87
- } catch {
88
- return false
89
- }
90
- })()
91
- if (musl)
92
- return arch === "x64"
93
- ? baseline
94
- ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
95
- : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
96
- : [`${base}-musl`, base]
97
- return arch === "x64"
98
- ? baseline
99
- ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
100
- : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
101
- : [base, `${base}-musl`]
102
- }
103
- return arch === "x64" ? (baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]) : [base]
104
- })()
105
-
106
- function findBinary(startDir) {
107
- let current = startDir
108
- for (;;) {
109
- const modules = path.join(current, "node_modules")
110
- if (fs.existsSync(modules))
111
- for (const name of names) {
112
- const candidate = path.join(modules, name, "bin", binary)
113
- if (fs.existsSync(candidate)) return candidate
114
- }
115
- const parent = path.dirname(current)
116
- if (parent === current) return
117
- current = parent
118
- }
119
- }
120
-
121
- const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
122
- if (!resolved) {
123
- console.error(
124
- "It seems that your package manager failed to install the right lildax CLI package. Try manually installing " +
125
- names.map((name) => `"${name}"`).join(" or ") +
126
- " package",
127
- )
128
- process.exit(1)
129
- }
130
- run(resolved)