@opencode/cli 0.0.0-reserved → 2.0.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.
@@ -0,0 +1,5 @@
1
+ echo "Error: @opencode/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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log("opencode2 is now just opencode. run opencode")
4
+ process.exit(1)
package/package.json CHANGED
@@ -1,15 +1,39 @@
1
1
  {
2
2
  "name": "@opencode/cli",
3
- "version": "0.0.0-reserved",
4
- "description": "OpenCode package bootstrap — not a functional release",
3
+ "bin": {
4
+ "opencode": "./bin/opencode.exe",
5
+ "opencode2": "./bin/opencode2.cjs"
6
+ },
7
+ "scripts": {
8
+ "postinstall": "node ./postinstall.mjs"
9
+ },
10
+ "version": "2.0.0",
5
11
  "license": "MIT",
6
12
  "repository": {
7
13
  "type": "git",
8
14
  "url": "git+https://github.com/anomalyco/opencode.git"
9
15
  },
10
- "publishConfig": {
11
- "registry": "https://registry.npmjs.org",
12
- "access": "public",
13
- "tag": "reserved"
16
+ "os": [
17
+ "darwin",
18
+ "linux",
19
+ "win32"
20
+ ],
21
+ "cpu": [
22
+ "arm64",
23
+ "x64"
24
+ ],
25
+ "optionalDependencies": {
26
+ "@opencode/cli-linux-x64-musl": "2.0.0",
27
+ "@opencode/cli-darwin-x64-baseline": "2.0.0",
28
+ "@opencode/cli-linux-arm64": "2.0.0",
29
+ "@opencode/cli-windows-x64-baseline": "2.0.0",
30
+ "@opencode/cli-linux-arm64-musl": "2.0.0",
31
+ "@opencode/cli-darwin-arm64": "2.0.0",
32
+ "@opencode/cli-windows-x64": "2.0.0",
33
+ "@opencode/cli-darwin-x64": "2.0.0",
34
+ "@opencode/cli-windows-arm64": "2.0.0",
35
+ "@opencode/cli-linux-x64-baseline-musl": "2.0.0",
36
+ "@opencode/cli-linux-x64": "2.0.0",
37
+ "@opencode/cli-linux-x64-baseline": "2.0.0"
14
38
  }
15
- }
39
+ }
@@ -0,0 +1,176 @@
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
+ const sourceCommand = packageJson.opencodeSourceBinary ?? command
16
+
17
+ const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform()
18
+ const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch()
19
+ const sourceBinary = platform === "windows" ? `${sourceCommand}.exe` : sourceCommand
20
+ const targetBinary = path.resolve(directory, packageJson.bin[command])
21
+ const dependencies = packageJson.optionalDependencies ?? {}
22
+ const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`))
23
+ if (!base) throw new Error(`OpenCode does not provide a binary for ${platform}-${arch}`)
24
+
25
+ function supportsAvx2() {
26
+ if (arch !== "x64") return false
27
+ if (platform === "linux") {
28
+ try {
29
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
30
+ } catch {
31
+ return false
32
+ }
33
+ }
34
+ if (platform === "darwin") {
35
+ try {
36
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
37
+ encoding: "utf8",
38
+ timeout: 1500,
39
+ })
40
+ return result.status === 0 && (result.stdout || "").trim() === "1"
41
+ } catch {
42
+ return false
43
+ }
44
+ }
45
+ if (platform === "windows") {
46
+ const script =
47
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
48
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
49
+ try {
50
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", script], {
51
+ encoding: "utf8",
52
+ timeout: 3000,
53
+ windowsHide: true,
54
+ })
55
+ if (result.status !== 0) continue
56
+ const output = (result.stdout || "").trim().toLowerCase()
57
+ if (output === "true" || output === "1") return true
58
+ if (output === "false" || output === "0") return false
59
+ } catch {
60
+ continue
61
+ }
62
+ }
63
+ }
64
+ return false
65
+ }
66
+
67
+ function isMusl() {
68
+ if (platform !== "linux") return false
69
+ try {
70
+ if (fs.existsSync("/etc/alpine-release")) return true
71
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
72
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
73
+ } catch {
74
+ return false
75
+ }
76
+ }
77
+
78
+ function packageNames() {
79
+ const baseline = arch === "x64" && !supportsAvx2()
80
+ const names =
81
+ platform === "linux"
82
+ ? isMusl()
83
+ ? arch === "x64"
84
+ ? baseline
85
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
86
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
87
+ : [`${base}-musl`, base]
88
+ : arch === "x64"
89
+ ? baseline
90
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
91
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
92
+ : [base, `${base}-musl`]
93
+ : arch === "x64"
94
+ ? baseline
95
+ ? [`${base}-baseline`, base]
96
+ : [base, `${base}-baseline`]
97
+ : [base]
98
+ return names.filter((name) => dependencies[name])
99
+ }
100
+
101
+ function copyBinary(source) {
102
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
103
+ fs.mkdirSync(path.dirname(targetBinary), { recursive: true })
104
+ if (fs.existsSync(targetBinary)) {
105
+ try {
106
+ fs.unlinkSync(targetBinary)
107
+ } catch {}
108
+ }
109
+ try {
110
+ fs.linkSync(source, targetBinary)
111
+ } catch {
112
+ fs.copyFileSync(source, targetBinary)
113
+ }
114
+ fs.chmodSync(targetBinary, 0o755)
115
+ }
116
+
117
+ function resolveBinary(name) {
118
+ const packagePath = require.resolve(`${name}/package.json`)
119
+ return path.join(path.dirname(packagePath), "bin", sourceBinary)
120
+ }
121
+
122
+ function installPackage(name) {
123
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
124
+ try {
125
+ const result = childProcess.spawnSync(
126
+ "npm",
127
+ [
128
+ "install",
129
+ "--ignore-scripts",
130
+ "--no-save",
131
+ "--loglevel=error",
132
+ "--prefix",
133
+ temp,
134
+ `${name}@${dependencies[name]}`,
135
+ ],
136
+ { stdio: "inherit", windowsHide: true },
137
+ )
138
+ if (result.status !== 0) return false
139
+ copyBinary(path.join(temp, "node_modules", name, "bin", sourceBinary))
140
+ return true
141
+ } finally {
142
+ fs.rmSync(temp, { recursive: true, force: true })
143
+ }
144
+ }
145
+
146
+ function verifyBinary() {
147
+ return (
148
+ childProcess.spawnSync(targetBinary, ["--version"], {
149
+ stdio: "ignore",
150
+ windowsHide: true,
151
+ }).status === 0
152
+ )
153
+ }
154
+
155
+ function main() {
156
+ const names = packageNames()
157
+ for (const name of names) {
158
+ try {
159
+ copyBinary(resolveBinary(name))
160
+ if (verifyBinary()) return
161
+ } catch {
162
+ if (installPackage(name) && verifyBinary()) return
163
+ }
164
+ }
165
+
166
+ throw new Error(
167
+ `Failed to install OpenCode. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
168
+ )
169
+ }
170
+
171
+ try {
172
+ main()
173
+ } catch (error) {
174
+ console.error(error instanceof Error ? error.message : String(error))
175
+ process.exit(1)
176
+ }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # @opencode/cli
2
-
3
- Bootstrap placeholder for the official [OpenCode](https://opencode.ai) release pipeline.
4
-
5
- This version contains no implementation or executable. Do not use it as a functional release.