lunos-ai 1.18.34

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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode
4
+ Copyright (c) 2026 ITService EOOD
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/bin/lunos.exe ADDED
@@ -0,0 +1,10 @@
1
+ echo "Error: lunos-ai's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when using --ignore-scripts during installation, or when using a" >&2
4
+ echo "package manager like pnpm that does not run postinstall scripts by default." >&2
5
+ echo "" >&2
6
+ echo "To fix this, run the postinstall script manually:" >&2
7
+ echo " cd node_modules/lunos-ai && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall lunos-ai without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "lunos-ai",
3
+ "bin": {
4
+ "lunos": "./bin/lunos.exe"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "1.18.34",
10
+ "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
20
+ "optionalDependencies": {
21
+ "lunos-linux-x64-musl": "1.18.34",
22
+ "lunos-linux-arm64": "1.18.34",
23
+ "lunos-windows-x64": "1.18.34",
24
+ "lunos-windows-arm64": "1.18.34",
25
+ "lunos-linux-x64": "1.18.34",
26
+ "lunos-darwin-x64-baseline": "1.18.34",
27
+ "lunos-linux-arm64-musl": "1.18.34",
28
+ "lunos-linux-x64-baseline-musl": "1.18.34",
29
+ "lunos-darwin-x64": "1.18.34",
30
+ "lunos-linux-x64-baseline": "1.18.34",
31
+ "lunos-darwin-arm64": "1.18.34",
32
+ "lunos-windows-x64-baseline": "1.18.34"
33
+ }
34
+ }
@@ -0,0 +1,199 @@
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
+ // Published brand identity, mirroring script/build.ts and script/publish.ts.
26
+ const brand = "lunos"
27
+
28
+ const platform = platformMap[os.platform()] ?? os.platform()
29
+ const arch = archMap[os.arch()] ?? os.arch()
30
+ // Platform sub-packages are published as `lunos-<platform>-<arch>` — must match the name
31
+ // build.ts writes into each dist/*/package.json.
32
+ const base = `${brand}-${platform}-${arch}`
33
+ // The binary *inside* the archive is still built as "opencode"; only the package and asset
34
+ // names carry the brand. The `install` script makes the same distinction (see install:346).
35
+ const sourceBinary = platform === "windows" ? "opencode.exe" : "opencode"
36
+ // Must match the `bin` entry in the generated package.json, which publish.ts writes as
37
+ // { lunos: "./bin/lunos.exe" }. Writing opencode.exe here would leave the `lunos` command
38
+ // pointing at the untouched "postinstall did not run" stub.
39
+ const targetBinary = path.join(__dirname, "bin", `${brand}.exe`)
40
+
41
+ function supportsAvx2() {
42
+ if (arch !== "x64") return false
43
+
44
+ if (platform === "linux") {
45
+ try {
46
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
47
+ } catch {
48
+ return false
49
+ }
50
+ }
51
+
52
+ if (platform === "darwin") {
53
+ try {
54
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
55
+ encoding: "utf8",
56
+ timeout: 1500,
57
+ })
58
+ if (result.status !== 0) return false
59
+ return (result.stdout || "").trim() === "1"
60
+ } catch {
61
+ return false
62
+ }
63
+ }
64
+
65
+ if (platform === "windows") {
66
+ const command =
67
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
68
+
69
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
70
+ try {
71
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
72
+ encoding: "utf8",
73
+ timeout: 3000,
74
+ windowsHide: true,
75
+ })
76
+ if (result.status !== 0) continue
77
+ const output = (result.stdout || "").trim().toLowerCase()
78
+ if (output === "true" || output === "1") return true
79
+ if (output === "false" || output === "0") return false
80
+ } catch {
81
+ continue
82
+ }
83
+ }
84
+ }
85
+
86
+ return false
87
+ }
88
+
89
+ function isMusl() {
90
+ if (platform !== "linux") return false
91
+
92
+ try {
93
+ if (fs.existsSync("/etc/alpine-release")) return true
94
+ } catch {
95
+ // Ignore filesystem probes that are blocked by the host.
96
+ }
97
+
98
+ try {
99
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
100
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
101
+ } catch {
102
+ return false
103
+ }
104
+ }
105
+
106
+ function packageNames() {
107
+ const baseline = arch === "x64" && !supportsAvx2()
108
+
109
+ if (platform === "linux") {
110
+ if (isMusl()) {
111
+ if (arch === "x64")
112
+ return baseline
113
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
114
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
115
+ return [`${base}-musl`, base]
116
+ }
117
+
118
+ if (arch === "x64")
119
+ return baseline
120
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
121
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
122
+ return [base, `${base}-musl`]
123
+ }
124
+
125
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
126
+ return [base]
127
+ }
128
+
129
+ function resolveBinary(name) {
130
+ const packageJsonPath = require.resolve(`${name}/package.json`)
131
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
132
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
133
+ return binaryPath
134
+ }
135
+
136
+ function installPackage(name) {
137
+ const version = packageJson.optionalDependencies?.[name]
138
+ if (!version) return
139
+
140
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
141
+ try {
142
+ const result = childProcess.spawnSync(
143
+ "npm",
144
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
145
+ { stdio: "inherit", windowsHide: true },
146
+ )
147
+ if (result.status !== 0) return
148
+ const packageDir = path.join(temp, "node_modules", name)
149
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
150
+ return true
151
+ } finally {
152
+ fs.rmSync(temp, { recursive: true, force: true })
153
+ }
154
+ }
155
+
156
+ function copyBinary(source, target) {
157
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
158
+ fs.mkdirSync(path.dirname(target), { recursive: true })
159
+ if (fs.existsSync(target)) fs.unlinkSync(target)
160
+ try {
161
+ fs.linkSync(source, target)
162
+ } catch {
163
+ fs.copyFileSync(source, target)
164
+ }
165
+ fs.chmodSync(target, 0o755)
166
+ }
167
+
168
+ function verifyBinary() {
169
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
170
+ encoding: "utf8",
171
+ stdio: "ignore",
172
+ windowsHide: true,
173
+ })
174
+ return result.status === 0
175
+ }
176
+
177
+ function main() {
178
+ for (const name of packageNames()) {
179
+ try {
180
+ copyBinary(resolveBinary(name), targetBinary)
181
+ if (verifyBinary()) return
182
+ } catch {
183
+ if (installPackage(name) && verifyBinary()) return
184
+ }
185
+ }
186
+
187
+ throw new Error(
188
+ `It seems your package manager failed to install the right Lunos CLI package. Try manually installing ${packageNames()
189
+ .map((name) => JSON.stringify(name))
190
+ .join(" or ")}.`,
191
+ )
192
+ }
193
+
194
+ try {
195
+ main()
196
+ } catch (error) {
197
+ console.error(error.message)
198
+ process.exit(1)
199
+ }