@phamhungg2709/bigmancode-ai 0.0.0-dev-202606250731

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.
@@ -0,0 +1,10 @@
1
+ echo "Error: bigmancode-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/bigmancode-ai && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall bigmancode-ai without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@phamhungg2709/bigmancode-ai",
3
+ "bin": {
4
+ "bigmancode": "./bin/bigmancode.exe"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.0-dev-202606250731",
10
+ "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
20
+ "optionalDependencies": {
21
+ "@phamhungg2709/bigmancode-linux-x64": "0.0.0-dev-202606250731",
22
+ "@phamhungg2709/bigmancode-darwin-x64-baseline": "0.0.0-dev-202606250731",
23
+ "@phamhungg2709/bigmancode-darwin-x64": "0.0.0-dev-202606250731",
24
+ "@phamhungg2709/bigmancode-darwin-arm64": "0.0.0-dev-202606250731",
25
+ "@phamhungg2709/bigmancode-linux-x64-baseline": "0.0.0-dev-202606250731",
26
+ "@phamhungg2709/bigmancode-linux-arm64": "0.0.0-dev-202606250731",
27
+ "@phamhungg2709/bigmancode-linux-arm64-musl": "0.0.0-dev-202606250731",
28
+ "@phamhungg2709/bigmancode-windows-arm64": "0.0.0-dev-202606250731",
29
+ "@phamhungg2709/bigmancode-linux-x64-baseline-musl": "0.0.0-dev-202606250731",
30
+ "@phamhungg2709/bigmancode-linux-x64-musl": "0.0.0-dev-202606250731",
31
+ "@phamhungg2709/bigmancode-windows-x64-baseline": "0.0.0-dev-202606250731",
32
+ "@phamhungg2709/bigmancode-windows-x64": "0.0.0-dev-202606250731"
33
+ }
34
+ }
@@ -0,0 +1,196 @@
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
+
28
+ const parts = packageJson.name.split("/")
29
+ const scope = parts.length > 1 ? parts[0] : ""
30
+ const pkgName = parts.length > 1 ? parts[1] : parts[0]
31
+ const nameWithoutAi = pkgName.replace("-ai", "")
32
+ const name = nameWithoutAi
33
+
34
+ const base = scope ? `${scope}/${nameWithoutAi}-${platform}-${arch}` : `${nameWithoutAi}-${platform}-${arch}`
35
+ const sourceBinary = platform === "windows" ? `${nameWithoutAi}.exe` : nameWithoutAi
36
+ const targetBinary = path.join(__dirname, "bin", `${nameWithoutAi}.exe`)
37
+
38
+ function supportsAvx2() {
39
+ if (arch !== "x64") return false
40
+
41
+ if (platform === "linux") {
42
+ try {
43
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
44
+ } catch {
45
+ return false
46
+ }
47
+ }
48
+
49
+ if (platform === "darwin") {
50
+ try {
51
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
52
+ encoding: "utf8",
53
+ timeout: 1500,
54
+ })
55
+ if (result.status !== 0) return false
56
+ return (result.stdout || "").trim() === "1"
57
+ } catch {
58
+ return false
59
+ }
60
+ }
61
+
62
+ if (platform === "windows") {
63
+ const command =
64
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
65
+
66
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
67
+ try {
68
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
69
+ encoding: "utf8",
70
+ timeout: 3000,
71
+ windowsHide: true,
72
+ })
73
+ if (result.status !== 0) continue
74
+ const output = (result.stdout || "").trim().toLowerCase()
75
+ if (output === "true" || output === "1") return true
76
+ if (output === "false" || output === "0") return false
77
+ } catch {
78
+ continue
79
+ }
80
+ }
81
+ }
82
+
83
+ return false
84
+ }
85
+
86
+ function isMusl() {
87
+ if (platform !== "linux") return false
88
+
89
+ try {
90
+ if (fs.existsSync("/etc/alpine-release")) return true
91
+ } catch {
92
+ // Ignore filesystem probes that are blocked by the host.
93
+ }
94
+
95
+ try {
96
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
97
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
98
+ } catch {
99
+ return false
100
+ }
101
+ }
102
+
103
+ function packageNames() {
104
+ const baseline = arch === "x64" && !supportsAvx2()
105
+
106
+ if (platform === "linux") {
107
+ if (isMusl()) {
108
+ if (arch === "x64")
109
+ return baseline
110
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
111
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
112
+ return [`${base}-musl`, base]
113
+ }
114
+
115
+ if (arch === "x64")
116
+ return baseline
117
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
118
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
119
+ return [base, `${base}-musl`]
120
+ }
121
+
122
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
123
+ return [base]
124
+ }
125
+
126
+ function resolveBinary(name) {
127
+ const packageJsonPath = require.resolve(`${name}/package.json`)
128
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
129
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
130
+ return binaryPath
131
+ }
132
+
133
+ function installPackage(name) {
134
+ const version = packageJson.optionalDependencies?.[name]
135
+ if (!version) return
136
+
137
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), `${name}-install-`))
138
+ try {
139
+ const result = childProcess.spawnSync(
140
+ "npm",
141
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
142
+ { stdio: "inherit", windowsHide: true },
143
+ )
144
+ if (result.status !== 0) return
145
+ const packageDir = path.join(temp, "node_modules", name)
146
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
147
+ return true
148
+ } finally {
149
+ fs.rmSync(temp, { recursive: true, force: true })
150
+ }
151
+ }
152
+
153
+ function copyBinary(source, target) {
154
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
155
+ fs.mkdirSync(path.dirname(target), { recursive: true })
156
+ if (fs.existsSync(target)) fs.unlinkSync(target)
157
+ try {
158
+ fs.linkSync(source, target)
159
+ } catch {
160
+ fs.copyFileSync(source, target)
161
+ }
162
+ fs.chmodSync(target, 0o755)
163
+ }
164
+
165
+ function verifyBinary() {
166
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
167
+ encoding: "utf8",
168
+ stdio: "ignore",
169
+ windowsHide: true,
170
+ })
171
+ return result.status === 0
172
+ }
173
+
174
+ function main() {
175
+ for (const name of packageNames()) {
176
+ try {
177
+ copyBinary(resolveBinary(name), targetBinary)
178
+ if (verifyBinary()) return
179
+ } catch {
180
+ if (installPackage(name) && verifyBinary()) return
181
+ }
182
+ }
183
+
184
+ throw new Error(
185
+ `It seems your package manager failed to install the right ${name} CLI package. Try manually installing ${packageNames()
186
+ .map((name) => JSON.stringify(name))
187
+ .join(" or ")}.`,
188
+ )
189
+ }
190
+
191
+ try {
192
+ main()
193
+ } catch (error) {
194
+ console.error(error.message)
195
+ process.exit(1)
196
+ }