@fabriccode/cli 0.0.0-main-202603030001
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 +82 -0
- package/bin/fabric +173 -0
- package/bin/kilo +188 -0
- package/package.json +19 -0
- package/postinstall.mjs +152 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kilo Code
|
|
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,82 @@
|
|
|
1
|
+
# Kilo Code CLI
|
|
2
|
+
|
|
3
|
+
The AI coding agent built for the terminal. Generate code from natural language, automate tasks, and run terminal commands -- powered by 500+ AI models.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @kilocode/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run directly with npx:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx --package @kilocode/cli kilo
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
Run `kilo` in any project directory to launch the interactive TUI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
kilo
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run a one-off task:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
kilo run "add input validation to the signup form"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Code generation** -- describe what you want in natural language
|
|
34
|
+
- **Terminal commands** -- the agent can run shell commands on your behalf
|
|
35
|
+
- **500+ AI models** -- use models from OpenAI, Anthropic, Google, and more
|
|
36
|
+
- **MCP servers** -- extend agent capabilities with the Model Context Protocol
|
|
37
|
+
- **Multiple modes** -- Plan with Architect, code with Coder, debug with Debugger, or create your own
|
|
38
|
+
- **Sessions** -- resume previous conversations and export transcripts
|
|
39
|
+
- **API keys optional** -- bring your own keys or use Kilo credits
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
| Command | Description |
|
|
44
|
+
| --------------------- | -------------------------- |
|
|
45
|
+
| `kilo` | Launch interactive TUI |
|
|
46
|
+
| `kilo run "<task>"` | Run a one-off task |
|
|
47
|
+
| `kilo auth` | Manage authentication |
|
|
48
|
+
| `kilo models` | List available models |
|
|
49
|
+
| `kilo mcp` | Manage MCP servers |
|
|
50
|
+
| `kilo session list` | List sessions |
|
|
51
|
+
| `kilo session delete` | Delete a session |
|
|
52
|
+
| `kilo export` | Export session transcripts |
|
|
53
|
+
|
|
54
|
+
Run `kilo --help` for the full list.
|
|
55
|
+
|
|
56
|
+
## Alternative Installation
|
|
57
|
+
|
|
58
|
+
### Homebrew (macOS/Linux)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
brew install Kilo-Org/tap/kilo
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### GitHub Releases
|
|
65
|
+
|
|
66
|
+
Download pre-built binaries from the [Releases page](https://github.com/Fabric-Pro/fabric-code/releases).
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
- [Docs](https://kilo.ai/docs)
|
|
71
|
+
- [Getting Started](https://kilo.ai/docs/getting-started)
|
|
72
|
+
|
|
73
|
+
## Links
|
|
74
|
+
|
|
75
|
+
- [GitHub](https://github.com/Fabric-Pro/fabric-code)
|
|
76
|
+
- [Discord](https://kilo.ai/discord)
|
|
77
|
+
- [VS Code Extension](https://kilo.ai/vscode-marketplace)
|
|
78
|
+
- [Website](https://kilo.ai)
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
package/bin/fabric
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
function run(target) {
|
|
9
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
})
|
|
12
|
+
if (result.error) {
|
|
13
|
+
console.error(result.error.message)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
17
|
+
process.exit(code)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const envPath = process.env.FABRIC_BIN_PATH
|
|
21
|
+
if (envPath) {
|
|
22
|
+
run(envPath)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const platformMap = {
|
|
26
|
+
darwin: "darwin",
|
|
27
|
+
linux: "linux",
|
|
28
|
+
win32: "windows",
|
|
29
|
+
}
|
|
30
|
+
const archMap = {
|
|
31
|
+
x64: "x64",
|
|
32
|
+
arm64: "arm64",
|
|
33
|
+
arm: "arm",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let platform = platformMap[os.platform()]
|
|
37
|
+
if (!platform) {
|
|
38
|
+
platform = os.platform()
|
|
39
|
+
}
|
|
40
|
+
let arch = archMap[os.arch()]
|
|
41
|
+
if (!arch) {
|
|
42
|
+
arch = os.arch()
|
|
43
|
+
}
|
|
44
|
+
const base = "@fabriccode/cli-" + platform + "-" + arch
|
|
45
|
+
const binary = platform === "windows" ? "fabric.exe" : "fabric"
|
|
46
|
+
|
|
47
|
+
function supportsAvx2() {
|
|
48
|
+
if (arch !== "x64") return false
|
|
49
|
+
|
|
50
|
+
if (platform === "linux") {
|
|
51
|
+
try {
|
|
52
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
53
|
+
} catch {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (platform === "darwin") {
|
|
59
|
+
try {
|
|
60
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
61
|
+
encoding: "utf8",
|
|
62
|
+
timeout: 1500,
|
|
63
|
+
})
|
|
64
|
+
if (result.status !== 0) return false
|
|
65
|
+
return (result.stdout || "").trim() === "1"
|
|
66
|
+
} catch {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (platform === "windows") {
|
|
72
|
+
const cmd =
|
|
73
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
74
|
+
|
|
75
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
76
|
+
try {
|
|
77
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
78
|
+
encoding: "utf8",
|
|
79
|
+
timeout: 3000,
|
|
80
|
+
windowsHide: true,
|
|
81
|
+
})
|
|
82
|
+
if (result.status !== 0) continue
|
|
83
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
84
|
+
if (out === "true" || out === "1") return true
|
|
85
|
+
if (out === "false" || out === "0") return false
|
|
86
|
+
} catch {
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const names = (() => {
|
|
98
|
+
const avx2 = supportsAvx2()
|
|
99
|
+
const baseline = arch === "x64" && !avx2
|
|
100
|
+
|
|
101
|
+
if (platform === "linux") {
|
|
102
|
+
const musl = (() => {
|
|
103
|
+
try {
|
|
104
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
105
|
+
} catch {
|
|
106
|
+
// ignore
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
111
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
112
|
+
if (text.includes("musl")) return true
|
|
113
|
+
} catch {
|
|
114
|
+
// ignore
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return false
|
|
118
|
+
})()
|
|
119
|
+
|
|
120
|
+
if (musl) {
|
|
121
|
+
if (arch === "x64") {
|
|
122
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
123
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
124
|
+
}
|
|
125
|
+
return [`${base}-musl`, base]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (arch === "x64") {
|
|
129
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
130
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
131
|
+
}
|
|
132
|
+
return [base, `${base}-musl`]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (arch === "x64") {
|
|
136
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
137
|
+
return [base, `${base}-baseline`]
|
|
138
|
+
}
|
|
139
|
+
return [base]
|
|
140
|
+
})()
|
|
141
|
+
|
|
142
|
+
function findBinary(startDir) {
|
|
143
|
+
let current = startDir
|
|
144
|
+
for (;;) {
|
|
145
|
+
const modules = path.join(current, "node_modules")
|
|
146
|
+
if (fs.existsSync(modules)) {
|
|
147
|
+
for (const name of names) {
|
|
148
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
149
|
+
if (fs.existsSync(candidate)) return candidate
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const parent = path.dirname(current)
|
|
153
|
+
if (parent === current) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
current = parent
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
161
|
+
const scriptDir = path.dirname(scriptPath)
|
|
162
|
+
|
|
163
|
+
const resolved = findBinary(scriptDir)
|
|
164
|
+
if (!resolved) {
|
|
165
|
+
console.error(
|
|
166
|
+
"It seems that your package manager failed to install the right version of Fabric Code for your platform. You can try manually installing " +
|
|
167
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
168
|
+
" package",
|
|
169
|
+
)
|
|
170
|
+
process.exit(1)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
run(resolved)
|
package/bin/kilo
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
function run(target) {
|
|
9
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
})
|
|
12
|
+
if (result.error) {
|
|
13
|
+
console.error(result.error.message)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
17
|
+
process.exit(code)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const envPath = process.env.KILO_BIN_PATH
|
|
21
|
+
if (envPath) {
|
|
22
|
+
run(envPath)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
26
|
+
const scriptDir = path.dirname(scriptPath)
|
|
27
|
+
|
|
28
|
+
// kilocode_change start - fall through to findBinary() if cached binary fails
|
|
29
|
+
const cached = path.join(scriptDir, ".kilo")
|
|
30
|
+
if (fs.existsSync(cached)) {
|
|
31
|
+
const result = childProcess.spawnSync(cached, process.argv.slice(2), {
|
|
32
|
+
stdio: "inherit",
|
|
33
|
+
})
|
|
34
|
+
if (!result.error) {
|
|
35
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
36
|
+
process.exit(code)
|
|
37
|
+
}
|
|
38
|
+
// cached binary failed (e.g. wrong platform/arch, missing dynamic linker),
|
|
39
|
+
// fall through to findBinary() which has better variant detection
|
|
40
|
+
}
|
|
41
|
+
// kilocode_change end
|
|
42
|
+
|
|
43
|
+
const platformMap = {
|
|
44
|
+
darwin: "darwin",
|
|
45
|
+
linux: "linux",
|
|
46
|
+
win32: "windows",
|
|
47
|
+
}
|
|
48
|
+
const archMap = {
|
|
49
|
+
x64: "x64",
|
|
50
|
+
arm64: "arm64",
|
|
51
|
+
arm: "arm",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let platform = platformMap[os.platform()]
|
|
55
|
+
if (!platform) {
|
|
56
|
+
platform = os.platform()
|
|
57
|
+
}
|
|
58
|
+
let arch = archMap[os.arch()]
|
|
59
|
+
if (!arch) {
|
|
60
|
+
arch = os.arch()
|
|
61
|
+
}
|
|
62
|
+
const base = "@fabriccode/cli-" + platform + "-" + arch
|
|
63
|
+
const binary = platform === "windows" ? "fabric.exe" : "fabric" // kilocode_change: binary is built as "fabric" not "kilo"
|
|
64
|
+
|
|
65
|
+
function supportsAvx2() {
|
|
66
|
+
if (arch !== "x64") return false
|
|
67
|
+
|
|
68
|
+
if (platform === "linux") {
|
|
69
|
+
try {
|
|
70
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
71
|
+
} catch {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (platform === "darwin") {
|
|
77
|
+
try {
|
|
78
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
79
|
+
encoding: "utf8",
|
|
80
|
+
timeout: 1500,
|
|
81
|
+
})
|
|
82
|
+
if (result.status !== 0) return false
|
|
83
|
+
return (result.stdout || "").trim() === "1"
|
|
84
|
+
} catch {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (platform === "windows") {
|
|
90
|
+
const cmd =
|
|
91
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
92
|
+
|
|
93
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
94
|
+
try {
|
|
95
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
96
|
+
encoding: "utf8",
|
|
97
|
+
timeout: 3000,
|
|
98
|
+
windowsHide: true,
|
|
99
|
+
})
|
|
100
|
+
if (result.status !== 0) continue
|
|
101
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
102
|
+
if (out === "true" || out === "1") return true
|
|
103
|
+
if (out === "false" || out === "0") return false
|
|
104
|
+
} catch {
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const names = (() => {
|
|
116
|
+
const avx2 = supportsAvx2()
|
|
117
|
+
const baseline = arch === "x64" && !avx2
|
|
118
|
+
|
|
119
|
+
if (platform === "linux") {
|
|
120
|
+
const musl = (() => {
|
|
121
|
+
try {
|
|
122
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
123
|
+
} catch {
|
|
124
|
+
// ignore
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
129
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
130
|
+
if (text.includes("musl")) return true
|
|
131
|
+
} catch {
|
|
132
|
+
// ignore
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false
|
|
136
|
+
})()
|
|
137
|
+
|
|
138
|
+
if (musl) {
|
|
139
|
+
if (arch === "x64") {
|
|
140
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
141
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
142
|
+
}
|
|
143
|
+
return [`${base}-musl`, base]
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (arch === "x64") {
|
|
147
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
148
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
149
|
+
}
|
|
150
|
+
return [base, `${base}-musl`]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (arch === "x64") {
|
|
154
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
155
|
+
return [base, `${base}-baseline`]
|
|
156
|
+
}
|
|
157
|
+
return [base]
|
|
158
|
+
})()
|
|
159
|
+
|
|
160
|
+
function findBinary(startDir) {
|
|
161
|
+
let current = startDir
|
|
162
|
+
for (;;) {
|
|
163
|
+
const modules = path.join(current, "node_modules")
|
|
164
|
+
if (fs.existsSync(modules)) {
|
|
165
|
+
for (const name of names) {
|
|
166
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
167
|
+
if (fs.existsSync(candidate)) return candidate
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const parent = path.dirname(current)
|
|
171
|
+
if (parent === current) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
current = parent
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const resolved = findBinary(scriptDir)
|
|
179
|
+
if (!resolved) {
|
|
180
|
+
console.error(
|
|
181
|
+
"It seems that your package manager failed to install the right version of the Kilo CLI for your platform. You can try manually installing " +
|
|
182
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
183
|
+
" package",
|
|
184
|
+
)
|
|
185
|
+
process.exit(1)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
run(resolved)
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fabriccode/cli",
|
|
3
|
+
"bin": {
|
|
4
|
+
"fabric": "./bin/fabric",
|
|
5
|
+
"fabriccode": "./bin/fabric"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.0.0-main-202603030001",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"@fabriccode/cli-linux-x64": "0.0.0-main-202603030001"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Fabric-Pro/fabric-code"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import os from "os"
|
|
6
|
+
import childProcess from "child_process"
|
|
7
|
+
import { fileURLToPath } from "url"
|
|
8
|
+
import { createRequire } from "module"
|
|
9
|
+
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const require = createRequire(import.meta.url)
|
|
12
|
+
|
|
13
|
+
// kilocode_change start - variant detection matching bin/kilo logic
|
|
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
|
+
function detectPlatformAndArch() {
|
|
26
|
+
const platform = platformMap[os.platform()] || os.platform()
|
|
27
|
+
const arch = archMap[os.arch()] || os.arch()
|
|
28
|
+
return { platform, arch }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function supportsAvx2() {
|
|
32
|
+
const { platform, arch } = detectPlatformAndArch()
|
|
33
|
+
if (arch !== "x64") return false
|
|
34
|
+
|
|
35
|
+
if (platform === "linux") {
|
|
36
|
+
try {
|
|
37
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
38
|
+
} catch {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (platform === "darwin") {
|
|
44
|
+
try {
|
|
45
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
timeout: 1500,
|
|
48
|
+
})
|
|
49
|
+
if (result.status !== 0) return false
|
|
50
|
+
return (result.stdout || "").trim() === "1"
|
|
51
|
+
} catch {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isMusl() {
|
|
60
|
+
try {
|
|
61
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
62
|
+
} catch {
|
|
63
|
+
// ignore
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
68
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
69
|
+
if (text.includes("musl")) return true
|
|
70
|
+
} catch {
|
|
71
|
+
// ignore
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getPackageNames() {
|
|
78
|
+
const { platform, arch } = detectPlatformAndArch()
|
|
79
|
+
const base = `@fabriccode/cli-${platform}-${arch}`
|
|
80
|
+
const avx2 = supportsAvx2()
|
|
81
|
+
const baseline = arch === "x64" && !avx2
|
|
82
|
+
|
|
83
|
+
if (platform === "linux") {
|
|
84
|
+
const musl = isMusl()
|
|
85
|
+
if (musl) {
|
|
86
|
+
if (arch === "x64") {
|
|
87
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
88
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
89
|
+
}
|
|
90
|
+
return [`${base}-musl`, base]
|
|
91
|
+
}
|
|
92
|
+
if (arch === "x64") {
|
|
93
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
94
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
95
|
+
}
|
|
96
|
+
return [base, `${base}-musl`]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (arch === "x64") {
|
|
100
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
101
|
+
return [base, `${base}-baseline`]
|
|
102
|
+
}
|
|
103
|
+
return [base]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function findBinary() {
|
|
107
|
+
const { platform } = detectPlatformAndArch()
|
|
108
|
+
const binaryName = platform === "windows" ? "fabric.exe" : "fabric" // kilocode_change: binary is built as "fabric" not "kilo"
|
|
109
|
+
const names = getPackageNames()
|
|
110
|
+
|
|
111
|
+
for (const packageName of names) {
|
|
112
|
+
try {
|
|
113
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
114
|
+
const packageDir = path.dirname(packageJsonPath)
|
|
115
|
+
const binaryPath = path.join(packageDir, "bin", binaryName)
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(binaryPath)) {
|
|
118
|
+
return { binaryPath, binaryName }
|
|
119
|
+
}
|
|
120
|
+
} catch {
|
|
121
|
+
// package not installed, try next variant
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
throw new Error(`Could not find any binary package. Tried: ${names.map((n) => `"${n}"`).join(", ")}`)
|
|
126
|
+
}
|
|
127
|
+
// kilocode_change end
|
|
128
|
+
|
|
129
|
+
function main() {
|
|
130
|
+
if (os.platform() === "win32") {
|
|
131
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
132
|
+
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { binaryPath } = findBinary()
|
|
137
|
+
const target = path.join(__dirname, "bin", ".kilo") // kilocode_change
|
|
138
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
139
|
+
try {
|
|
140
|
+
fs.linkSync(binaryPath, target)
|
|
141
|
+
} catch {
|
|
142
|
+
fs.copyFileSync(binaryPath, target)
|
|
143
|
+
}
|
|
144
|
+
fs.chmodSync(target, 0o755)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
main()
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Failed to setup fabric binary:", error.message) // kilocode_change
|
|
151
|
+
process.exit(1)
|
|
152
|
+
}
|