@finny-ai/finny-pro 0.1.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/bin/opencode +211 -0
- package/package.json +25 -0
- package/postinstall.mjs +194 -0
package/bin/opencode
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
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.FINNY_BIN_PATH ?? process.env.OPENCODE_BIN_PATH
|
|
47
|
+
|
|
48
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
49
|
+
const scriptDir = path.dirname(scriptPath)
|
|
50
|
+
|
|
51
|
+
// Derive the platform-package base from this wrapper's own name so the launcher
|
|
52
|
+
// resolves the published scoped packages (e.g. @finny-ai/finny-internal-darwin-arm64),
|
|
53
|
+
// not the legacy unscoped "opencode-*" names.
|
|
54
|
+
const wrapperName = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(fs.readFileSync(path.join(scriptDir, "..", "package.json"), "utf8")).name
|
|
57
|
+
} catch {
|
|
58
|
+
return "opencode"
|
|
59
|
+
}
|
|
60
|
+
})()
|
|
61
|
+
|
|
62
|
+
const platformMap = {
|
|
63
|
+
darwin: "darwin",
|
|
64
|
+
linux: "linux",
|
|
65
|
+
win32: "windows",
|
|
66
|
+
}
|
|
67
|
+
const archMap = {
|
|
68
|
+
x64: "x64",
|
|
69
|
+
arm64: "arm64",
|
|
70
|
+
arm: "arm",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let platform = platformMap[os.platform()]
|
|
74
|
+
if (!platform) {
|
|
75
|
+
platform = os.platform()
|
|
76
|
+
}
|
|
77
|
+
let arch = archMap[os.arch()]
|
|
78
|
+
if (!arch) {
|
|
79
|
+
arch = os.arch()
|
|
80
|
+
}
|
|
81
|
+
const base = wrapperName + "-" + platform + "-" + arch
|
|
82
|
+
const binary = platform === "windows" ? "opencode.exe" : "opencode"
|
|
83
|
+
|
|
84
|
+
// Fast path: the binary postinstall.mjs copies next to this launcher. Keep this
|
|
85
|
+
// filename in sync with postinstall.mjs's targetBinary.
|
|
86
|
+
const cached = path.join(scriptDir, platform === "windows" ? ".opencode.exe" : ".opencode")
|
|
87
|
+
|
|
88
|
+
function supportsAvx2() {
|
|
89
|
+
if (arch !== "x64") return false
|
|
90
|
+
|
|
91
|
+
if (platform === "linux") {
|
|
92
|
+
try {
|
|
93
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
94
|
+
} catch {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (platform === "darwin") {
|
|
100
|
+
try {
|
|
101
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
102
|
+
encoding: "utf8",
|
|
103
|
+
timeout: 1500,
|
|
104
|
+
})
|
|
105
|
+
if (result.status !== 0) return false
|
|
106
|
+
return (result.stdout || "").trim() === "1"
|
|
107
|
+
} catch {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (platform === "windows") {
|
|
113
|
+
const cmd =
|
|
114
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
115
|
+
|
|
116
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
117
|
+
try {
|
|
118
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
119
|
+
encoding: "utf8",
|
|
120
|
+
timeout: 3000,
|
|
121
|
+
windowsHide: true,
|
|
122
|
+
})
|
|
123
|
+
if (result.status !== 0) continue
|
|
124
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
125
|
+
if (out === "true" || out === "1") return true
|
|
126
|
+
if (out === "false" || out === "0") return false
|
|
127
|
+
} catch {
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return false
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const names = (() => {
|
|
139
|
+
const avx2 = supportsAvx2()
|
|
140
|
+
const baseline = arch === "x64" && !avx2
|
|
141
|
+
|
|
142
|
+
if (platform === "linux") {
|
|
143
|
+
const musl = (() => {
|
|
144
|
+
try {
|
|
145
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
146
|
+
} catch {
|
|
147
|
+
// ignore
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
152
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
153
|
+
if (text.includes("musl")) return true
|
|
154
|
+
} catch {
|
|
155
|
+
// ignore
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return false
|
|
159
|
+
})()
|
|
160
|
+
|
|
161
|
+
if (musl) {
|
|
162
|
+
if (arch === "x64") {
|
|
163
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
164
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
165
|
+
}
|
|
166
|
+
return [`${base}-musl`, base]
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (arch === "x64") {
|
|
170
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
171
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
172
|
+
}
|
|
173
|
+
return [base, `${base}-musl`]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (arch === "x64") {
|
|
177
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
178
|
+
return [base, `${base}-baseline`]
|
|
179
|
+
}
|
|
180
|
+
return [base]
|
|
181
|
+
})()
|
|
182
|
+
|
|
183
|
+
function findBinary(startDir) {
|
|
184
|
+
let current = startDir
|
|
185
|
+
for (;;) {
|
|
186
|
+
const modules = path.join(current, "node_modules")
|
|
187
|
+
if (fs.existsSync(modules)) {
|
|
188
|
+
for (const name of names) {
|
|
189
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
190
|
+
if (fs.existsSync(candidate)) return candidate
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const parent = path.dirname(current)
|
|
194
|
+
if (parent === current) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
current = parent
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
|
|
202
|
+
if (!resolved) {
|
|
203
|
+
console.error(
|
|
204
|
+
"It seems that your package manager failed to install the right version of the Finny CLI for your platform. You can try manually installing " +
|
|
205
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
206
|
+
" package",
|
|
207
|
+
)
|
|
208
|
+
process.exit(1)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
run(resolved)
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@finny-ai/finny-pro",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"finny": "./bin/opencode"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"postinstall": "node ./postinstall.mjs"
|
|
9
|
+
},
|
|
10
|
+
"optionalDependencies": {
|
|
11
|
+
"@finny-ai/finny-pro-darwin-arm64": "0.1.0",
|
|
12
|
+
"@finny-ai/finny-pro-darwin-x64": "0.1.0",
|
|
13
|
+
"@finny-ai/finny-pro-darwin-x64-baseline": "0.1.0",
|
|
14
|
+
"@finny-ai/finny-pro-linux-arm64": "0.1.0",
|
|
15
|
+
"@finny-ai/finny-pro-linux-arm64-musl": "0.1.0",
|
|
16
|
+
"@finny-ai/finny-pro-linux-x64": "0.1.0",
|
|
17
|
+
"@finny-ai/finny-pro-linux-x64-baseline": "0.1.0",
|
|
18
|
+
"@finny-ai/finny-pro-linux-x64-baseline-musl": "0.1.0",
|
|
19
|
+
"@finny-ai/finny-pro-linux-x64-musl": "0.1.0",
|
|
20
|
+
"@finny-ai/finny-pro-windows-arm64": "0.1.0",
|
|
21
|
+
"@finny-ai/finny-pro-windows-x64": "0.1.0",
|
|
22
|
+
"@finny-ai/finny-pro-windows-x64-baseline": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"license": "UNLICENSED"
|
|
25
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
|
|
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
|
+
// Platform packages are published as `${wrapperName}-<platform>-<arch>[...]`,
|
|
28
|
+
// e.g. @finny-ai/finny-internal-darwin-arm64. Derive the base from this
|
|
29
|
+
// package's own name so it stays correct across renames/scopes.
|
|
30
|
+
const base = `${packageJson.name}-${platform}-${arch}`
|
|
31
|
+
const sourceBinary = platform === "windows" ? "opencode.exe" : "opencode"
|
|
32
|
+
// Cache the platform binary next to the launcher. The filename must match the
|
|
33
|
+
// launcher's `cached` path in bin/opencode so `finny` actually executes it.
|
|
34
|
+
const targetBinary = path.join(__dirname, "bin", platform === "windows" ? ".opencode.exe" : ".opencode")
|
|
35
|
+
|
|
36
|
+
function supportsAvx2() {
|
|
37
|
+
if (arch !== "x64") return false
|
|
38
|
+
|
|
39
|
+
if (platform === "linux") {
|
|
40
|
+
try {
|
|
41
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
42
|
+
} catch {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (platform === "darwin") {
|
|
48
|
+
try {
|
|
49
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
50
|
+
encoding: "utf8",
|
|
51
|
+
timeout: 1500,
|
|
52
|
+
})
|
|
53
|
+
if (result.status !== 0) return false
|
|
54
|
+
return (result.stdout || "").trim() === "1"
|
|
55
|
+
} catch {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (platform === "windows") {
|
|
61
|
+
const command =
|
|
62
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
63
|
+
|
|
64
|
+
for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
65
|
+
try {
|
|
66
|
+
const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
timeout: 3000,
|
|
69
|
+
windowsHide: true,
|
|
70
|
+
})
|
|
71
|
+
if (result.status !== 0) continue
|
|
72
|
+
const output = (result.stdout || "").trim().toLowerCase()
|
|
73
|
+
if (output === "true" || output === "1") return true
|
|
74
|
+
if (output === "false" || output === "0") return false
|
|
75
|
+
} catch {
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isMusl() {
|
|
85
|
+
if (platform !== "linux") return false
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
89
|
+
} catch {
|
|
90
|
+
// Ignore filesystem probes that are blocked by the host.
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
95
|
+
return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
|
|
96
|
+
} catch {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function packageNames() {
|
|
102
|
+
const baseline = arch === "x64" && !supportsAvx2()
|
|
103
|
+
|
|
104
|
+
if (platform === "linux") {
|
|
105
|
+
if (isMusl()) {
|
|
106
|
+
if (arch === "x64")
|
|
107
|
+
return baseline
|
|
108
|
+
? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
109
|
+
: [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
110
|
+
return [`${base}-musl`, base]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (arch === "x64")
|
|
114
|
+
return baseline
|
|
115
|
+
? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
116
|
+
: [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
117
|
+
return [base, `${base}-musl`]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
|
|
121
|
+
return [base]
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function resolveBinary(name) {
|
|
125
|
+
const packageJsonPath = require.resolve(`${name}/package.json`)
|
|
126
|
+
const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
|
|
127
|
+
if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
|
|
128
|
+
return binaryPath
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function installPackage(name) {
|
|
132
|
+
const version = packageJson.optionalDependencies?.[name]
|
|
133
|
+
if (!version) return
|
|
134
|
+
|
|
135
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
|
|
136
|
+
try {
|
|
137
|
+
const result = childProcess.spawnSync(
|
|
138
|
+
"npm",
|
|
139
|
+
["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
|
|
140
|
+
{ stdio: "inherit", windowsHide: true },
|
|
141
|
+
)
|
|
142
|
+
if (result.status !== 0) return
|
|
143
|
+
const packageDir = path.join(temp, "node_modules", name)
|
|
144
|
+
copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
|
|
145
|
+
return true
|
|
146
|
+
} finally {
|
|
147
|
+
fs.rmSync(temp, { recursive: true, force: true })
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function copyBinary(source, target) {
|
|
152
|
+
if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
|
|
153
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
154
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
155
|
+
try {
|
|
156
|
+
fs.linkSync(source, target)
|
|
157
|
+
} catch {
|
|
158
|
+
fs.copyFileSync(source, target)
|
|
159
|
+
}
|
|
160
|
+
fs.chmodSync(target, 0o755)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function verifyBinary() {
|
|
164
|
+
const result = childProcess.spawnSync(targetBinary, ["--version"], {
|
|
165
|
+
encoding: "utf8",
|
|
166
|
+
stdio: "ignore",
|
|
167
|
+
windowsHide: true,
|
|
168
|
+
})
|
|
169
|
+
return result.status === 0
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function main() {
|
|
173
|
+
for (const name of packageNames()) {
|
|
174
|
+
try {
|
|
175
|
+
copyBinary(resolveBinary(name), targetBinary)
|
|
176
|
+
if (verifyBinary()) return
|
|
177
|
+
} catch {
|
|
178
|
+
if (installPackage(name) && verifyBinary()) return
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
throw new Error(
|
|
183
|
+
`It seems your package manager failed to install the right opencode CLI package. Try manually installing ${packageNames()
|
|
184
|
+
.map((name) => JSON.stringify(name))
|
|
185
|
+
.join(" or ")}.`,
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
main()
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error(error.message)
|
|
193
|
+
process.exit(1)
|
|
194
|
+
}
|