opencode-ai 1.0.62 → 1.0.63
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/bin/opencode +84 -61
- package/package.json +12 -13
- package/postinstall.mjs +33 -46
- package/bin/opencode.cmd +0 -58
- package/preinstall.mjs +0 -44
package/bin/opencode
CHANGED
|
@@ -1,61 +1,84 @@
|
|
|
1
|
-
#!/bin/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
function run(target) {
|
|
9
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
})
|
|
12
|
+
if (result.error) {
|
|
13
|
+
console.error(result.error.message)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
17
|
+
process.exit(code)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const envPath = process.env.OPENCODE_BIN_PATH
|
|
21
|
+
if (envPath) {
|
|
22
|
+
run(envPath)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
26
|
+
const scriptDir = path.dirname(scriptPath)
|
|
27
|
+
|
|
28
|
+
const platformMap = {
|
|
29
|
+
darwin: "darwin",
|
|
30
|
+
linux: "linux",
|
|
31
|
+
win32: "windows",
|
|
32
|
+
}
|
|
33
|
+
const archMap = {
|
|
34
|
+
x64: "x64",
|
|
35
|
+
arm64: "arm64",
|
|
36
|
+
arm: "arm",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let platform = platformMap[os.platform()]
|
|
40
|
+
if (!platform) {
|
|
41
|
+
platform = os.platform()
|
|
42
|
+
}
|
|
43
|
+
let arch = archMap[os.arch()]
|
|
44
|
+
if (!arch) {
|
|
45
|
+
arch = os.arch()
|
|
46
|
+
}
|
|
47
|
+
const base = "opencode-" + platform + "-" + arch
|
|
48
|
+
const binary = platform === "windows" ? "opencode.exe" : "opencode"
|
|
49
|
+
|
|
50
|
+
function findBinary(startDir) {
|
|
51
|
+
let current = startDir
|
|
52
|
+
for (;;) {
|
|
53
|
+
const modules = path.join(current, "node_modules")
|
|
54
|
+
if (fs.existsSync(modules)) {
|
|
55
|
+
const entries = fs.readdirSync(modules)
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (!entry.startsWith(base)) {
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
const candidate = path.join(modules, entry, "bin", binary)
|
|
61
|
+
if (fs.existsSync(candidate)) {
|
|
62
|
+
return candidate
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const parent = path.dirname(current)
|
|
67
|
+
if (parent === current) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
current = parent
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const resolved = findBinary(scriptDir)
|
|
75
|
+
if (!resolved) {
|
|
76
|
+
console.error(
|
|
77
|
+
'It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "' +
|
|
78
|
+
base +
|
|
79
|
+
'" package',
|
|
80
|
+
)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
run(resolved)
|
package/package.json
CHANGED
|
@@ -4,21 +4,20 @@
|
|
|
4
4
|
"opencode": "./bin/opencode"
|
|
5
5
|
},
|
|
6
6
|
"scripts": {
|
|
7
|
-
"preinstall": "bun ./preinstall.mjs || node ./preinstall.mjs",
|
|
8
7
|
"postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
|
|
9
8
|
},
|
|
10
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.63",
|
|
11
10
|
"optionalDependencies": {
|
|
12
|
-
"opencode-linux-arm64": "1.0.
|
|
13
|
-
"opencode-linux-x64": "1.0.
|
|
14
|
-
"opencode-linux-x64-baseline": "1.0.
|
|
15
|
-
"opencode-linux-arm64-musl": "1.0.
|
|
16
|
-
"opencode-linux-x64-musl": "1.0.
|
|
17
|
-
"opencode-linux-x64-baseline-musl": "1.0.
|
|
18
|
-
"opencode-darwin-arm64": "1.0.
|
|
19
|
-
"opencode-darwin-x64": "1.0.
|
|
20
|
-
"opencode-darwin-x64-baseline": "1.0.
|
|
21
|
-
"opencode-windows-x64": "1.0.
|
|
22
|
-
"opencode-windows-x64-baseline": "1.0.
|
|
11
|
+
"opencode-linux-arm64": "1.0.63",
|
|
12
|
+
"opencode-linux-x64": "1.0.63",
|
|
13
|
+
"opencode-linux-x64-baseline": "1.0.63",
|
|
14
|
+
"opencode-linux-arm64-musl": "1.0.63",
|
|
15
|
+
"opencode-linux-x64-musl": "1.0.63",
|
|
16
|
+
"opencode-linux-x64-baseline-musl": "1.0.63",
|
|
17
|
+
"opencode-darwin-arm64": "1.0.63",
|
|
18
|
+
"opencode-darwin-x64": "1.0.63",
|
|
19
|
+
"opencode-darwin-x64-baseline": "1.0.63",
|
|
20
|
+
"opencode-windows-x64": "1.0.63",
|
|
21
|
+
"opencode-windows-x64-baseline": "1.0.63"
|
|
23
22
|
}
|
|
24
23
|
}
|
package/postinstall.mjs
CHANGED
|
@@ -50,79 +50,66 @@ function detectPlatformAndArch() {
|
|
|
50
50
|
function findBinary() {
|
|
51
51
|
const { platform, arch } = detectPlatformAndArch()
|
|
52
52
|
const packageName = `opencode-${platform}-${arch}`
|
|
53
|
-
const
|
|
53
|
+
const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
|
|
54
54
|
|
|
55
55
|
try {
|
|
56
56
|
// Use require.resolve to find the package
|
|
57
57
|
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
58
58
|
const packageDir = path.dirname(packageJsonPath)
|
|
59
|
-
const binaryPath = path.join(packageDir, "bin",
|
|
59
|
+
const binaryPath = path.join(packageDir, "bin", binaryName)
|
|
60
60
|
|
|
61
61
|
if (!fs.existsSync(binaryPath)) {
|
|
62
62
|
throw new Error(`Binary not found at ${binaryPath}`)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
return binaryPath
|
|
65
|
+
return { binaryPath, binaryName }
|
|
66
66
|
} catch (error) {
|
|
67
67
|
throw new Error(`Could not find package ${packageName}: ${error.message}`)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
function prepareBinDirectory(binaryName) {
|
|
72
|
+
const binDir = path.join(__dirname, "bin")
|
|
73
|
+
const targetPath = path.join(binDir, binaryName)
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// npm_config_global is string | undefined
|
|
79
|
-
// if it exists, the value is true
|
|
80
|
-
const isGlobal = process.env.npm_config_global === "true" || pkgPath.includes(path.join("npm", "node_modules"))
|
|
81
|
-
|
|
82
|
-
// The npm rebuild command does 2 things - Execute lifecycle scripts and rebuild bin links
|
|
83
|
-
// We want to skip lifecycle scripts to avoid infinite loops, so we use --ignore-scripts
|
|
84
|
-
const cmd = `npm rebuild opencode-ai --ignore-scripts${isGlobal ? " -g" : ""}`
|
|
85
|
-
const opts = {
|
|
86
|
-
stdio: "inherit",
|
|
87
|
-
shell: true,
|
|
88
|
-
...(isGlobal ? {} : { cwd: path.join(pkgPath, "..", "..") }), // For local, run from project root
|
|
89
|
-
}
|
|
75
|
+
// Ensure bin directory exists
|
|
76
|
+
if (!fs.existsSync(binDir)) {
|
|
77
|
+
fs.mkdirSync(binDir, { recursive: true })
|
|
78
|
+
}
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
// Remove existing binary/symlink if it exists
|
|
81
|
+
if (fs.existsSync(targetPath)) {
|
|
82
|
+
fs.unlinkSync(targetPath)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { binDir, targetPath }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function symlinkBinary(sourcePath, binaryName) {
|
|
89
|
+
const { targetPath } = prepareBinDirectory(binaryName)
|
|
90
|
+
|
|
91
|
+
fs.symlinkSync(sourcePath, targetPath)
|
|
92
|
+
console.log(`opencode binary symlinked: ${targetPath} -> ${sourcePath}`)
|
|
93
|
+
|
|
94
|
+
// Verify the file exists after operation
|
|
95
|
+
if (!fs.existsSync(targetPath)) {
|
|
96
|
+
throw new Error(`Failed to symlink binary to ${targetPath}`)
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
async function main() {
|
|
101
101
|
try {
|
|
102
102
|
if (os.platform() === "win32") {
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
await regenerateWindowsCmdWrappers()
|
|
107
|
-
} else {
|
|
108
|
-
console.log("Windows detected but not npm, skipping postinstall")
|
|
109
|
-
}
|
|
103
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
104
|
+
// No postinstall setup needed
|
|
105
|
+
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
|
110
106
|
return
|
|
111
107
|
}
|
|
112
108
|
|
|
113
|
-
const binaryPath = findBinary()
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// Remove existing bin script if it exists
|
|
117
|
-
if (fs.existsSync(binScript)) {
|
|
118
|
-
fs.unlinkSync(binScript)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Create symlink to the actual binary
|
|
122
|
-
fs.symlinkSync(binaryPath, binScript)
|
|
123
|
-
console.log(`opencode binary symlinked: ${binScript} -> ${binaryPath}`)
|
|
109
|
+
const { binaryPath, binaryName } = findBinary()
|
|
110
|
+
symlinkBinary(binaryPath, binaryName)
|
|
124
111
|
} catch (error) {
|
|
125
|
-
console.error("Failed to
|
|
112
|
+
console.error("Failed to setup opencode binary:", error.message)
|
|
126
113
|
process.exit(1)
|
|
127
114
|
}
|
|
128
115
|
}
|
package/bin/opencode.cmd
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
setlocal enabledelayedexpansion
|
|
3
|
-
|
|
4
|
-
if defined OPENCODE_BIN_PATH (
|
|
5
|
-
set "resolved=%OPENCODE_BIN_PATH%"
|
|
6
|
-
goto :execute
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
rem Get the directory of this script
|
|
10
|
-
set "script_dir=%~dp0"
|
|
11
|
-
set "script_dir=%script_dir:~0,-1%"
|
|
12
|
-
|
|
13
|
-
rem Detect platform and architecture
|
|
14
|
-
set "platform=windows"
|
|
15
|
-
|
|
16
|
-
rem Detect architecture
|
|
17
|
-
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
|
18
|
-
set "arch=x64"
|
|
19
|
-
) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
|
|
20
|
-
set "arch=arm64"
|
|
21
|
-
) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
|
|
22
|
-
set "arch=x86"
|
|
23
|
-
) else (
|
|
24
|
-
set "arch=x64"
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
set "name=opencode-!platform!-!arch!"
|
|
28
|
-
set "binary=opencode.exe"
|
|
29
|
-
|
|
30
|
-
rem Search for the binary starting from script location
|
|
31
|
-
set "resolved="
|
|
32
|
-
set "current_dir=%script_dir%"
|
|
33
|
-
|
|
34
|
-
:search_loop
|
|
35
|
-
set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
|
|
36
|
-
if exist "%candidate%" (
|
|
37
|
-
set "resolved=%candidate%"
|
|
38
|
-
goto :execute
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
rem Move up one directory
|
|
42
|
-
for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
|
|
43
|
-
set "parent_dir=%parent_dir:~0,-1%"
|
|
44
|
-
|
|
45
|
-
rem Check if we've reached the root
|
|
46
|
-
if "%current_dir%"=="%parent_dir%" goto :not_found
|
|
47
|
-
set "current_dir=%parent_dir%"
|
|
48
|
-
goto :search_loop
|
|
49
|
-
|
|
50
|
-
:not_found
|
|
51
|
-
echo It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "%name%" package >&2
|
|
52
|
-
exit /b 1
|
|
53
|
-
|
|
54
|
-
:execute
|
|
55
|
-
rem Execute the binary with all arguments in the same console window
|
|
56
|
-
rem Use start /b /wait to ensure it runs in the current shell context for all shells
|
|
57
|
-
start /b /wait "" "%resolved%" %*
|
|
58
|
-
exit /b %ERRORLEVEL%
|
package/preinstall.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs"
|
|
4
|
-
import path from "path"
|
|
5
|
-
import os from "os"
|
|
6
|
-
import { fileURLToPath } from "url"
|
|
7
|
-
|
|
8
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
-
|
|
10
|
-
function main() {
|
|
11
|
-
if (os.platform() !== "win32") {
|
|
12
|
-
console.log("Non-Windows platform detected, skipping preinstall")
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
console.log("Windows detected: Modifying package.json bin entry")
|
|
17
|
-
|
|
18
|
-
// Read package.json
|
|
19
|
-
const packageJsonPath = path.join(__dirname, "package.json")
|
|
20
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
|
|
21
|
-
|
|
22
|
-
// Modify bin to point to .cmd file on Windows
|
|
23
|
-
packageJson.bin = {
|
|
24
|
-
opencode: "./bin/opencode.cmd",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Write it back
|
|
28
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
29
|
-
console.log("Updated package.json bin to use opencode.cmd")
|
|
30
|
-
|
|
31
|
-
// Now you can also remove the Unix script if you want
|
|
32
|
-
const unixScript = path.join(__dirname, "bin", "opencode")
|
|
33
|
-
if (fs.existsSync(unixScript)) {
|
|
34
|
-
console.log("Removing Unix shell script")
|
|
35
|
-
fs.unlinkSync(unixScript)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
main()
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error("Preinstall script error:", error.message)
|
|
43
|
-
process.exit(0)
|
|
44
|
-
}
|