@onescience/onecode 1.14.50-202606300908

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.
package/bin/onecode ADDED
@@ -0,0 +1,198 @@
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.ONECODE_BIN_PATH || process.env.OPENCODE_BIN_PATH
47
+
48
+ const scriptPath = fs.realpathSync(__filename)
49
+ const scriptDir = path.dirname(scriptPath)
50
+
51
+ const cached = path.join(scriptDir, ".onecode")
52
+
53
+ const platformMap = {
54
+ darwin: "darwin",
55
+ linux: "linux",
56
+ win32: "windows",
57
+ }
58
+ const archMap = {
59
+ x64: "x64",
60
+ arm64: "arm64",
61
+ arm: "arm",
62
+ }
63
+
64
+ let platform = platformMap[os.platform()]
65
+ if (!platform) {
66
+ platform = os.platform()
67
+ }
68
+ let arch = archMap[os.arch()]
69
+ if (!arch) {
70
+ arch = os.arch()
71
+ }
72
+ const base = "onecode-" + platform + "-" + arch
73
+ const binary = platform === "windows" ? "onecode.exe" : "onecode"
74
+
75
+ function supportsAvx2() {
76
+ if (arch !== "x64") return false
77
+
78
+ if (platform === "linux") {
79
+ try {
80
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
81
+ } catch {
82
+ return false
83
+ }
84
+ }
85
+
86
+ if (platform === "darwin") {
87
+ try {
88
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
89
+ encoding: "utf8",
90
+ timeout: 1500,
91
+ })
92
+ if (result.status !== 0) return false
93
+ return (result.stdout || "").trim() === "1"
94
+ } catch {
95
+ return false
96
+ }
97
+ }
98
+
99
+ if (platform === "windows") {
100
+ const cmd =
101
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
102
+
103
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
104
+ try {
105
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
106
+ encoding: "utf8",
107
+ timeout: 3000,
108
+ windowsHide: true,
109
+ })
110
+ if (result.status !== 0) continue
111
+ const out = (result.stdout || "").trim().toLowerCase()
112
+ if (out === "true" || out === "1") return true
113
+ if (out === "false" || out === "0") return false
114
+ } catch {
115
+ continue
116
+ }
117
+ }
118
+
119
+ return false
120
+ }
121
+
122
+ return false
123
+ }
124
+
125
+ const names = (() => {
126
+ const avx2 = supportsAvx2()
127
+ const baseline = arch === "x64" && !avx2
128
+
129
+ if (platform === "linux") {
130
+ const musl = (() => {
131
+ try {
132
+ if (fs.existsSync("/etc/alpine-release")) return true
133
+ } catch {
134
+ // ignore
135
+ }
136
+
137
+ try {
138
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
139
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
140
+ if (text.includes("musl")) return true
141
+ } catch {
142
+ // ignore
143
+ }
144
+
145
+ return false
146
+ })()
147
+
148
+ if (musl) {
149
+ if (arch === "x64") {
150
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
151
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
152
+ }
153
+ return [`${base}-musl`, base]
154
+ }
155
+
156
+ if (arch === "x64") {
157
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
158
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
159
+ }
160
+ return [base, `${base}-musl`]
161
+ }
162
+
163
+ if (arch === "x64") {
164
+ if (baseline) return [`${base}-baseline`, base]
165
+ return [base, `${base}-baseline`]
166
+ }
167
+ return [base]
168
+ })()
169
+
170
+ function findBinary(startDir) {
171
+ let current = startDir
172
+ for (;;) {
173
+ const modules = path.join(current, "node_modules")
174
+ if (fs.existsSync(modules)) {
175
+ for (const name of names) {
176
+ const candidate = path.join(modules, name, "bin", binary)
177
+ if (fs.existsSync(candidate)) return candidate
178
+ }
179
+ }
180
+ const parent = path.dirname(current)
181
+ if (parent === current) {
182
+ return
183
+ }
184
+ current = parent
185
+ }
186
+ }
187
+
188
+ const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
189
+ if (!resolved) {
190
+ console.error(
191
+ "It seems that your package manager failed to install the right version of the onecode CLI for your platform. You can try manually installing " +
192
+ names.map((n) => `\"${n}\"`).join(" or ") +
193
+ " package",
194
+ )
195
+ process.exit(1)
196
+ }
197
+
198
+ run(resolved)
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@onescience/onecode",
3
+ "version": "1.14.50-202606300908",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "description": "OneScience AI coding agent for the terminal.",
7
+ "bin": {
8
+ "onecode": "./bin/onecode"
9
+ },
10
+ "scripts": {
11
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
12
+ },
13
+ "optionalDependencies": {
14
+ "onecode-linux-x64": "1.14.50-202606300908"
15
+ }
16
+ }
@@ -0,0 +1,96 @@
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
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+ const product = "onecode"
12
+
13
+ function detectPlatformAndArch() {
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ let arch
31
+ switch (os.arch()) {
32
+ case "x64":
33
+ arch = "x64"
34
+ break
35
+ case "arm64":
36
+ arch = "arm64"
37
+ break
38
+ case "arm":
39
+ arch = "arm"
40
+ break
41
+ default:
42
+ arch = os.arch()
43
+ break
44
+ }
45
+
46
+ return { platform, arch }
47
+ }
48
+
49
+ function findBinary() {
50
+ const { platform, arch } = detectPlatformAndArch()
51
+ const packageName = `${product}-${platform}-${arch}`
52
+ const binaryName = platform === "windows" ? `${product}.exe` : product
53
+
54
+ try {
55
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
56
+ const packageDir = path.dirname(packageJsonPath)
57
+ const binaryPath = path.join(packageDir, "bin", binaryName)
58
+
59
+ if (!fs.existsSync(binaryPath)) {
60
+ throw new Error(`Binary not found at ${binaryPath}`)
61
+ }
62
+
63
+ return { binaryPath, binaryName }
64
+ } catch (error) {
65
+ throw new Error(`Could not find package ${packageName}: ${error.message}`, { cause: error })
66
+ }
67
+ }
68
+
69
+ async function main() {
70
+ try {
71
+ if (os.platform() === "win32") {
72
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
73
+ return
74
+ }
75
+
76
+ const { binaryPath } = findBinary()
77
+ const target = path.join(__dirname, "bin", `.${product}`)
78
+ if (fs.existsSync(target)) fs.unlinkSync(target)
79
+ try {
80
+ fs.linkSync(binaryPath, target)
81
+ } catch {
82
+ fs.copyFileSync(binaryPath, target)
83
+ }
84
+ fs.chmodSync(target, 0o755)
85
+ } catch (error) {
86
+ console.error(`Failed to setup ${product} binary:`, error.message)
87
+ process.exit(1)
88
+ }
89
+ }
90
+
91
+ try {
92
+ void main()
93
+ } catch (error) {
94
+ console.error("Postinstall script error:", error.message)
95
+ process.exit(0)
96
+ }