@codegoblin-io/codegoblin 0.1.2
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 +22 -0
- package/README.md +20 -0
- package/bin/cg.mjs +42 -0
- package/bin/codegoblin.mjs +42 -0
- package/package.json +64 -0
- package/postinstall.mjs +194 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Shawn Isikli and CodeGoblin contributors
|
|
4
|
+
Copyright (c) 2025 opencode
|
|
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/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# CodeGoblin
|
|
2
|
+
|
|
3
|
+
Your local AI goblin for code, images, and agents.
|
|
4
|
+
|
|
5
|
+
CodeGoblin is an independent fork/customization of OpenCode and is not affiliated with OpenCode, Anomaly, or their maintainers.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @codegoblin-io/codegoblin@0.1.2
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
codegoblin --help
|
|
17
|
+
cg --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The npm package installs a small launcher plus the native CodeGoblin binary package for your platform.
|
package/bin/cg.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import childProcess from "child_process"
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import { fileURLToPath } from "url"
|
|
6
|
+
|
|
7
|
+
const binDir = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
const native = path.join(binDir, "codegoblin.exe")
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(native)) {
|
|
11
|
+
console.error("Error: CodeGoblin's native binary was not installed.")
|
|
12
|
+
console.error("")
|
|
13
|
+
console.error("This can happen when installing with --ignore-scripts or with a package manager")
|
|
14
|
+
console.error("that does not run postinstall scripts by default.")
|
|
15
|
+
console.error("")
|
|
16
|
+
console.error("To fix this, run:")
|
|
17
|
+
console.error(" cd node_modules/@codegoblin-io/codegoblin && node postinstall.mjs")
|
|
18
|
+
process.exit(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const child = childProcess.spawn(native, process.argv.slice(2), {
|
|
22
|
+
stdio: "inherit",
|
|
23
|
+
env: {
|
|
24
|
+
...process.env,
|
|
25
|
+
CODEGOBLIN: "1",
|
|
26
|
+
CODEGOBLIN_CLI_NAME: "cg",
|
|
27
|
+
OPENCODE: "1",
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
child.on("error", (error) => {
|
|
32
|
+
console.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
child.on("exit", (code, signal) => {
|
|
37
|
+
if (signal) {
|
|
38
|
+
process.kill(process.pid, signal)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
42
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import childProcess from "child_process"
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import { fileURLToPath } from "url"
|
|
6
|
+
|
|
7
|
+
const binDir = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
const native = path.join(binDir, "codegoblin.exe")
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(native)) {
|
|
11
|
+
console.error("Error: CodeGoblin's native binary was not installed.")
|
|
12
|
+
console.error("")
|
|
13
|
+
console.error("This can happen when installing with --ignore-scripts or with a package manager")
|
|
14
|
+
console.error("that does not run postinstall scripts by default.")
|
|
15
|
+
console.error("")
|
|
16
|
+
console.error("To fix this, run:")
|
|
17
|
+
console.error(" cd node_modules/@codegoblin-io/codegoblin && node postinstall.mjs")
|
|
18
|
+
process.exit(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const child = childProcess.spawn(native, process.argv.slice(2), {
|
|
22
|
+
stdio: "inherit",
|
|
23
|
+
env: {
|
|
24
|
+
...process.env,
|
|
25
|
+
CODEGOBLIN: "1",
|
|
26
|
+
CODEGOBLIN_CLI_NAME: "codegoblin",
|
|
27
|
+
OPENCODE: "1",
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
child.on("error", (error) => {
|
|
32
|
+
console.error(error.message)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
child.on("exit", (code, signal) => {
|
|
37
|
+
if (signal) {
|
|
38
|
+
process.kill(process.pid, signal)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
42
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codegoblin-io/codegoblin",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Your local AI goblin for code, images, and agents.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/shawnisikli/CodeGoblin"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/shawnisikli/CodeGoblin",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/shawnisikli/CodeGoblin/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ai",
|
|
16
|
+
"agent",
|
|
17
|
+
"cli",
|
|
18
|
+
"tui",
|
|
19
|
+
"codegoblin",
|
|
20
|
+
"local-first"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"codegoblin": "./bin/codegoblin.mjs",
|
|
24
|
+
"cg": "./bin/cg.mjs"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin",
|
|
28
|
+
"postinstall.mjs",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"postinstall": "node ./postinstall.mjs"
|
|
34
|
+
},
|
|
35
|
+
"os": [
|
|
36
|
+
"darwin",
|
|
37
|
+
"linux",
|
|
38
|
+
"win32"
|
|
39
|
+
],
|
|
40
|
+
"cpu": [
|
|
41
|
+
"arm64",
|
|
42
|
+
"x64"
|
|
43
|
+
],
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"codegoblin-windows-x64-baseline": "0.1.2",
|
|
46
|
+
"codegoblin-windows-x64": "0.1.2",
|
|
47
|
+
"codegoblin-windows-arm64": "0.1.2",
|
|
48
|
+
"codegoblin-linux-x64-musl": "0.1.2",
|
|
49
|
+
"codegoblin-linux-x64-baseline-musl": "0.1.2",
|
|
50
|
+
"codegoblin-linux-x64-baseline": "0.1.2",
|
|
51
|
+
"codegoblin-linux-x64": "0.1.2",
|
|
52
|
+
"codegoblin-linux-arm64-musl": "0.1.2",
|
|
53
|
+
"codegoblin-linux-arm64": "0.1.2",
|
|
54
|
+
"codegoblin-darwin-x64-baseline": "0.1.2",
|
|
55
|
+
"codegoblin-darwin-x64": "0.1.2",
|
|
56
|
+
"codegoblin-darwin-arm64": "0.1.2"
|
|
57
|
+
},
|
|
58
|
+
"nativeBinary": {
|
|
59
|
+
"product": "CodeGoblin",
|
|
60
|
+
"command": "codegoblin",
|
|
61
|
+
"sourceCommand": "codegoblin",
|
|
62
|
+
"packagePrefix": "codegoblin"
|
|
63
|
+
}
|
|
64
|
+
}
|
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
|
+
const nativeBinary = packageJson.nativeBinary || {}
|
|
14
|
+
const product = nativeBinary.product || "OpenCode"
|
|
15
|
+
const command = nativeBinary.command || "opencode"
|
|
16
|
+
const sourceCommand = nativeBinary.sourceCommand || command
|
|
17
|
+
const packagePrefix = nativeBinary.packagePrefix || "opencode"
|
|
18
|
+
|
|
19
|
+
const platformMap = {
|
|
20
|
+
darwin: "darwin",
|
|
21
|
+
linux: "linux",
|
|
22
|
+
win32: "windows",
|
|
23
|
+
}
|
|
24
|
+
const archMap = {
|
|
25
|
+
x64: "x64",
|
|
26
|
+
arm64: "arm64",
|
|
27
|
+
arm: "arm",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const platform = platformMap[os.platform()] ?? os.platform()
|
|
31
|
+
const arch = archMap[os.arch()] ?? os.arch()
|
|
32
|
+
const base = `${packagePrefix}-${platform}-${arch}`
|
|
33
|
+
const sourceBinary = platform === "windows" ? `${sourceCommand}.exe` : sourceCommand
|
|
34
|
+
const targetBinary = path.join(__dirname, "bin", `${command}.exe`)
|
|
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(), `${command}-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 ${product} 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
|
+
}
|