@chinaresoft/resoftcode 0.1.0
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/bin/kilo +251 -0
- package/bin/bin/resoft +257 -0
- package/bin/kilo +251 -0
- package/bin/resoft +257 -0
- package/chinaresoft-resoftcode-0.1.0.tgz +0 -0
- package/package.json +25 -0
- package/postinstall.mjs +192 -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
|
+
# Resoft 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 @chinaresoft/resoftcode
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run directly with npx:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx --package @chinaresoft/resoftcode resoftcode
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
Run `resoftcode` in any project directory to launch the interactive TUI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
resoftcode
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run a one-off task:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
resoftcode 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 configure a local model
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
| Command | Description |
|
|
44
|
+
| --------------------- | -------------------------- |
|
|
45
|
+
| `resoftcode` | Launch interactive TUI |
|
|
46
|
+
| `resoftcode run "<task>"` | Run a one-off task |
|
|
47
|
+
| `resoftcode auth` | Manage authentication |
|
|
48
|
+
| `resoftcode models` | List available models |
|
|
49
|
+
| `resoftcode mcp` | Manage MCP servers |
|
|
50
|
+
| `resoftcode session list` | List sessions |
|
|
51
|
+
| `resoftcode session delete` | Delete a session |
|
|
52
|
+
| `resoftcode export` | Export session transcripts |
|
|
53
|
+
|
|
54
|
+
Run `resoftcode --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/softctwo/Resoftcode/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/softctwo/Resoftcode)
|
|
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/bin/kilo
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
|
11
|
+
function configureTreeSitterResources(target) {
|
|
12
|
+
const wasmDir = path.join(path.dirname(target), "tree-sitter")
|
|
13
|
+
if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
|
|
14
|
+
process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// kilocode_change end
|
|
18
|
+
|
|
19
|
+
function run(target, fallback) {
|
|
20
|
+
// kilocode_change - preserve cached binary fallback
|
|
21
|
+
configureTreeSitterResources(target) // kilocode_change
|
|
22
|
+
// kilocode_change start - fall through if the cached binary cannot be spawned
|
|
23
|
+
const child = (() => {
|
|
24
|
+
try {
|
|
25
|
+
return childProcess.spawn(target, process.argv.slice(2), {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
})
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (fallback) {
|
|
30
|
+
run(fallback)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
console.error(error.message)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
})()
|
|
37
|
+
if (!child) return
|
|
38
|
+
// kilocode_change end
|
|
39
|
+
|
|
40
|
+
const forwarders = {}
|
|
41
|
+
const clear = () => {
|
|
42
|
+
// kilocode_change - remove listeners before cached binary fallback
|
|
43
|
+
for (const signal of forwardedSignals) {
|
|
44
|
+
process.removeListener(signal, forwarders[signal])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
child.on("error", (error) => {
|
|
49
|
+
clear() // kilocode_change
|
|
50
|
+
// kilocode_change start - fall through to findBinary() if cached binary fails
|
|
51
|
+
if (fallback) {
|
|
52
|
+
run(fallback)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
// kilocode_change end
|
|
56
|
+
console.error(error.message)
|
|
57
|
+
process.exit(1)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
for (const signal of forwardedSignals) {
|
|
61
|
+
forwarders[signal] = () => {
|
|
62
|
+
try {
|
|
63
|
+
child.kill(signal)
|
|
64
|
+
} catch {
|
|
65
|
+
// The child may have already exited.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
process.on(signal, forwarders[signal])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
child.on("exit", (code, signal) => {
|
|
72
|
+
clear() // kilocode_change
|
|
73
|
+
|
|
74
|
+
if (signal) {
|
|
75
|
+
process.kill(process.pid, signal)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const envPath = process.env.KILO_BIN_PATH
|
|
84
|
+
|
|
85
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
86
|
+
const scriptDir = path.dirname(scriptPath)
|
|
87
|
+
|
|
88
|
+
const cached = path.join(scriptDir, ".kilo")
|
|
89
|
+
|
|
90
|
+
const platformMap = {
|
|
91
|
+
darwin: "darwin",
|
|
92
|
+
linux: "linux",
|
|
93
|
+
win32: "windows",
|
|
94
|
+
}
|
|
95
|
+
const archMap = {
|
|
96
|
+
x64: "x64",
|
|
97
|
+
arm64: "arm64",
|
|
98
|
+
arm: "arm",
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let platform = platformMap[os.platform()]
|
|
102
|
+
if (!platform) {
|
|
103
|
+
platform = os.platform()
|
|
104
|
+
}
|
|
105
|
+
let arch = archMap[os.arch()]
|
|
106
|
+
if (!arch) {
|
|
107
|
+
arch = os.arch()
|
|
108
|
+
}
|
|
109
|
+
// resoft_change start - canonical China Resoft scope with legacy fallbacks
|
|
110
|
+
const base = "@chinaresoft/resoftcode-" + platform + "-" + arch
|
|
111
|
+
const scopeBase = "@chinaresoft/cli-" + platform + "-" + arch
|
|
112
|
+
const priorBase = "@resoft/cli-" + platform + "-" + arch
|
|
113
|
+
const legacyBase = "@kilocode/cli-" + platform + "-" + arch
|
|
114
|
+
// resoft_change end
|
|
115
|
+
// resoft_change start - prefer resoft binary, fall back to legacy kilo
|
|
116
|
+
const primaryBinary = platform === "windows" ? "resoftcode.exe" : "resoftcode"
|
|
117
|
+
const scopeBinary = platform === "windows" ? "resoft.exe" : "resoft"
|
|
118
|
+
const legacyBinary = platform === "windows" ? "kilo.exe" : "kilo"
|
|
119
|
+
// resoft_change end
|
|
120
|
+
|
|
121
|
+
function supportsAvx2() {
|
|
122
|
+
if (arch !== "x64") return false
|
|
123
|
+
|
|
124
|
+
if (platform === "linux") {
|
|
125
|
+
try {
|
|
126
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
127
|
+
} catch {
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (platform === "darwin") {
|
|
133
|
+
try {
|
|
134
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
135
|
+
encoding: "utf8",
|
|
136
|
+
timeout: 1500,
|
|
137
|
+
})
|
|
138
|
+
if (result.status !== 0) return false
|
|
139
|
+
return (result.stdout || "").trim() === "1"
|
|
140
|
+
} catch {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (platform === "windows") {
|
|
146
|
+
const cmd =
|
|
147
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
148
|
+
|
|
149
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
150
|
+
try {
|
|
151
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
152
|
+
encoding: "utf8",
|
|
153
|
+
timeout: 3000,
|
|
154
|
+
windowsHide: true,
|
|
155
|
+
})
|
|
156
|
+
if (result.status !== 0) continue
|
|
157
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
158
|
+
if (out === "true" || out === "1") return true
|
|
159
|
+
if (out === "false" || out === "0") return false
|
|
160
|
+
} catch {
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const names = (() => {
|
|
172
|
+
// resoft_change start - prefer @chinaresoft/resoftcode-* and keep prior scopes as fallbacks
|
|
173
|
+
const expand = (prefix) => {
|
|
174
|
+
const avx2 = supportsAvx2()
|
|
175
|
+
const baseline = arch === "x64" && !avx2
|
|
176
|
+
|
|
177
|
+
if (platform === "linux") {
|
|
178
|
+
const musl = (() => {
|
|
179
|
+
try {
|
|
180
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
181
|
+
} catch {
|
|
182
|
+
// ignore
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
187
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
188
|
+
if (text.includes("musl")) return true
|
|
189
|
+
} catch {
|
|
190
|
+
// ignore
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return false
|
|
194
|
+
})()
|
|
195
|
+
|
|
196
|
+
if (musl) {
|
|
197
|
+
if (arch === "x64") {
|
|
198
|
+
if (baseline) return [`${prefix}-baseline-musl`, `${prefix}-musl`, `${prefix}-baseline`, prefix]
|
|
199
|
+
return [`${prefix}-musl`, `${prefix}-baseline-musl`, prefix, `${prefix}-baseline`]
|
|
200
|
+
}
|
|
201
|
+
return [`${prefix}-musl`, prefix]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (arch === "x64") {
|
|
205
|
+
if (baseline) return [`${prefix}-baseline`, prefix, `${prefix}-baseline-musl`, `${prefix}-musl`]
|
|
206
|
+
return [prefix, `${prefix}-baseline`, `${prefix}-musl`, `${prefix}-baseline-musl`]
|
|
207
|
+
}
|
|
208
|
+
return [prefix, `${prefix}-musl`]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (arch === "x64") {
|
|
212
|
+
if (baseline) return [`${prefix}-baseline`, prefix]
|
|
213
|
+
return [prefix, `${prefix}-baseline`]
|
|
214
|
+
}
|
|
215
|
+
return [prefix]
|
|
216
|
+
}
|
|
217
|
+
return [...expand(base), ...expand(scopeBase), ...expand(priorBase), ...expand(legacyBase)]
|
|
218
|
+
// resoft_change end
|
|
219
|
+
})()
|
|
220
|
+
|
|
221
|
+
function findBinary(startDir) {
|
|
222
|
+
let current = startDir
|
|
223
|
+
for (;;) {
|
|
224
|
+
const modules = path.join(current, "node_modules")
|
|
225
|
+
if (fs.existsSync(modules)) {
|
|
226
|
+
for (const name of names) {
|
|
227
|
+
for (const binaryName of [primaryBinary, scopeBinary, legacyBinary]) {
|
|
228
|
+
const candidate = path.join(modules, name, "bin", binaryName)
|
|
229
|
+
if (fs.existsSync(candidate)) return candidate
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const parent = path.dirname(current)
|
|
234
|
+
if (parent === current) {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
current = parent
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
|
|
242
|
+
if (!resolved) {
|
|
243
|
+
console.error(
|
|
244
|
+
"It seems that your package manager failed to install the right version of the Resoft CLI for your platform. You can try manually installing " +
|
|
245
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
246
|
+
" package",
|
|
247
|
+
)
|
|
248
|
+
process.exit(1)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
run(resolved, resolved === cached ? findBinary(scriptDir) : undefined) // kilocode_change - preserve cached binary fallback
|
package/bin/bin/resoft
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
process.env.RESOFT_CLI = "1"
|
|
11
|
+
|
|
12
|
+
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
|
13
|
+
function configureTreeSitterResources(target) {
|
|
14
|
+
const wasmDir = path.join(path.dirname(target), "tree-sitter")
|
|
15
|
+
if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
|
|
16
|
+
process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// kilocode_change end
|
|
20
|
+
|
|
21
|
+
function run(target, fallback) {
|
|
22
|
+
// kilocode_change - preserve cached binary fallback
|
|
23
|
+
configureTreeSitterResources(target) // kilocode_change
|
|
24
|
+
// kilocode_change start - fall through if the cached binary cannot be spawned
|
|
25
|
+
const child = (() => {
|
|
26
|
+
try {
|
|
27
|
+
return childProcess.spawn(target, process.argv.slice(2), {
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
})
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (fallback) {
|
|
32
|
+
run(fallback)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
console.error(error.message)
|
|
36
|
+
process.exit(1)
|
|
37
|
+
}
|
|
38
|
+
})()
|
|
39
|
+
if (!child) return
|
|
40
|
+
// kilocode_change end
|
|
41
|
+
|
|
42
|
+
const forwarders = {}
|
|
43
|
+
const clear = () => {
|
|
44
|
+
// kilocode_change - remove listeners before cached binary fallback
|
|
45
|
+
for (const signal of forwardedSignals) {
|
|
46
|
+
process.removeListener(signal, forwarders[signal])
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
child.on("error", (error) => {
|
|
51
|
+
clear() // kilocode_change
|
|
52
|
+
// kilocode_change start - fall through to findBinary() if cached binary fails
|
|
53
|
+
if (fallback) {
|
|
54
|
+
run(fallback)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
// kilocode_change end
|
|
58
|
+
console.error(error.message)
|
|
59
|
+
process.exit(1)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
for (const signal of forwardedSignals) {
|
|
63
|
+
forwarders[signal] = () => {
|
|
64
|
+
try {
|
|
65
|
+
child.kill(signal)
|
|
66
|
+
} catch {
|
|
67
|
+
// The child may have already exited.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
process.on(signal, forwarders[signal])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
child.on("exit", (code, signal) => {
|
|
74
|
+
clear() // kilocode_change
|
|
75
|
+
|
|
76
|
+
if (signal) {
|
|
77
|
+
process.kill(process.pid, signal)
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const envPath = process.env.KILO_BIN_PATH
|
|
86
|
+
|
|
87
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
88
|
+
const scriptDir = path.dirname(scriptPath)
|
|
89
|
+
|
|
90
|
+
// resoft_change start - prefer the Resoft cache link and retain the Kilo link as fallback
|
|
91
|
+
const cached = path.join(scriptDir, ".resoft")
|
|
92
|
+
const legacyCached = path.join(scriptDir, ".kilo")
|
|
93
|
+
// resoft_change end
|
|
94
|
+
|
|
95
|
+
const platformMap = {
|
|
96
|
+
darwin: "darwin",
|
|
97
|
+
linux: "linux",
|
|
98
|
+
win32: "windows",
|
|
99
|
+
}
|
|
100
|
+
const archMap = {
|
|
101
|
+
x64: "x64",
|
|
102
|
+
arm64: "arm64",
|
|
103
|
+
arm: "arm",
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let platform = platformMap[os.platform()]
|
|
107
|
+
if (!platform) {
|
|
108
|
+
platform = os.platform()
|
|
109
|
+
}
|
|
110
|
+
let arch = archMap[os.arch()]
|
|
111
|
+
if (!arch) {
|
|
112
|
+
arch = os.arch()
|
|
113
|
+
}
|
|
114
|
+
// resoft_change start - canonical China Resoft scope with legacy fallbacks
|
|
115
|
+
const base = "@chinaresoft/resoftcode-" + platform + "-" + arch
|
|
116
|
+
const scopeBase = "@chinaresoft/cli-" + platform + "-" + arch
|
|
117
|
+
const priorBase = "@resoft/cli-" + platform + "-" + arch
|
|
118
|
+
const legacyBase = "@kilocode/cli-" + platform + "-" + arch
|
|
119
|
+
// resoft_change end
|
|
120
|
+
// resoft_change start - prefer resoft binary, fall back to legacy kilo
|
|
121
|
+
const primaryBinary = platform === "windows" ? "resoftcode.exe" : "resoftcode"
|
|
122
|
+
const scopeBinary = platform === "windows" ? "resoft.exe" : "resoft"
|
|
123
|
+
const legacyBinary = platform === "windows" ? "kilo.exe" : "kilo"
|
|
124
|
+
// resoft_change end
|
|
125
|
+
|
|
126
|
+
function supportsAvx2() {
|
|
127
|
+
if (arch !== "x64") return false
|
|
128
|
+
|
|
129
|
+
if (platform === "linux") {
|
|
130
|
+
try {
|
|
131
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
132
|
+
} catch {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (platform === "darwin") {
|
|
138
|
+
try {
|
|
139
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
140
|
+
encoding: "utf8",
|
|
141
|
+
timeout: 1500,
|
|
142
|
+
})
|
|
143
|
+
if (result.status !== 0) return false
|
|
144
|
+
return (result.stdout || "").trim() === "1"
|
|
145
|
+
} catch {
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (platform === "windows") {
|
|
151
|
+
const cmd =
|
|
152
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
153
|
+
|
|
154
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
155
|
+
try {
|
|
156
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
157
|
+
encoding: "utf8",
|
|
158
|
+
timeout: 3000,
|
|
159
|
+
windowsHide: true,
|
|
160
|
+
})
|
|
161
|
+
if (result.status !== 0) continue
|
|
162
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
163
|
+
if (out === "true" || out === "1") return true
|
|
164
|
+
if (out === "false" || out === "0") return false
|
|
165
|
+
} catch {
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const names = (() => {
|
|
177
|
+
// resoft_change start - prefer @chinaresoft/resoftcode-* and keep prior scopes as fallbacks
|
|
178
|
+
const expand = (prefix) => {
|
|
179
|
+
const avx2 = supportsAvx2()
|
|
180
|
+
const baseline = arch === "x64" && !avx2
|
|
181
|
+
|
|
182
|
+
if (platform === "linux") {
|
|
183
|
+
const musl = (() => {
|
|
184
|
+
try {
|
|
185
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
186
|
+
} catch {
|
|
187
|
+
// ignore
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
192
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
193
|
+
if (text.includes("musl")) return true
|
|
194
|
+
} catch {
|
|
195
|
+
// ignore
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return false
|
|
199
|
+
})()
|
|
200
|
+
|
|
201
|
+
if (musl) {
|
|
202
|
+
if (arch === "x64") {
|
|
203
|
+
if (baseline) return [`${prefix}-baseline-musl`, `${prefix}-musl`, `${prefix}-baseline`, prefix]
|
|
204
|
+
return [`${prefix}-musl`, `${prefix}-baseline-musl`, prefix, `${prefix}-baseline`]
|
|
205
|
+
}
|
|
206
|
+
return [`${prefix}-musl`, prefix]
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (arch === "x64") {
|
|
210
|
+
if (baseline) return [`${prefix}-baseline`, prefix, `${prefix}-baseline-musl`, `${prefix}-musl`]
|
|
211
|
+
return [prefix, `${prefix}-baseline`, `${prefix}-musl`, `${prefix}-baseline-musl`]
|
|
212
|
+
}
|
|
213
|
+
return [prefix, `${prefix}-musl`]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (arch === "x64") {
|
|
217
|
+
if (baseline) return [`${prefix}-baseline`, prefix]
|
|
218
|
+
return [prefix, `${prefix}-baseline`]
|
|
219
|
+
}
|
|
220
|
+
return [prefix]
|
|
221
|
+
}
|
|
222
|
+
return [...expand(base), ...expand(scopeBase), ...expand(priorBase), ...expand(legacyBase)]
|
|
223
|
+
// resoft_change end
|
|
224
|
+
})()
|
|
225
|
+
|
|
226
|
+
function findBinary(startDir) {
|
|
227
|
+
let current = startDir
|
|
228
|
+
for (;;) {
|
|
229
|
+
const modules = path.join(current, "node_modules")
|
|
230
|
+
if (fs.existsSync(modules)) {
|
|
231
|
+
for (const name of names) {
|
|
232
|
+
for (const binaryName of [primaryBinary, scopeBinary, legacyBinary]) {
|
|
233
|
+
const candidate = path.join(modules, name, "bin", binaryName)
|
|
234
|
+
if (fs.existsSync(candidate)) return candidate
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const parent = path.dirname(current)
|
|
239
|
+
if (parent === current) {
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
current = parent
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const resolved =
|
|
247
|
+
envPath || (fs.existsSync(cached) ? cached : fs.existsSync(legacyCached) ? legacyCached : findBinary(scriptDir))
|
|
248
|
+
if (!resolved) {
|
|
249
|
+
console.error(
|
|
250
|
+
"It seems that your package manager failed to install the right version of the Resoft CLI for your platform. You can try manually installing " +
|
|
251
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
252
|
+
" package",
|
|
253
|
+
)
|
|
254
|
+
process.exit(1)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
run(resolved, resolved === cached || resolved === legacyCached ? findBinary(scriptDir) : undefined) // kilocode_change - preserve cached binary fallback
|
package/bin/kilo
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
|
11
|
+
function configureTreeSitterResources(target) {
|
|
12
|
+
const wasmDir = path.join(path.dirname(target), "tree-sitter")
|
|
13
|
+
if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
|
|
14
|
+
process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// kilocode_change end
|
|
18
|
+
|
|
19
|
+
function run(target, fallback) {
|
|
20
|
+
// kilocode_change - preserve cached binary fallback
|
|
21
|
+
configureTreeSitterResources(target) // kilocode_change
|
|
22
|
+
// kilocode_change start - fall through if the cached binary cannot be spawned
|
|
23
|
+
const child = (() => {
|
|
24
|
+
try {
|
|
25
|
+
return childProcess.spawn(target, process.argv.slice(2), {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
})
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (fallback) {
|
|
30
|
+
run(fallback)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
console.error(error.message)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
})()
|
|
37
|
+
if (!child) return
|
|
38
|
+
// kilocode_change end
|
|
39
|
+
|
|
40
|
+
const forwarders = {}
|
|
41
|
+
const clear = () => {
|
|
42
|
+
// kilocode_change - remove listeners before cached binary fallback
|
|
43
|
+
for (const signal of forwardedSignals) {
|
|
44
|
+
process.removeListener(signal, forwarders[signal])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
child.on("error", (error) => {
|
|
49
|
+
clear() // kilocode_change
|
|
50
|
+
// kilocode_change start - fall through to findBinary() if cached binary fails
|
|
51
|
+
if (fallback) {
|
|
52
|
+
run(fallback)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
// kilocode_change end
|
|
56
|
+
console.error(error.message)
|
|
57
|
+
process.exit(1)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
for (const signal of forwardedSignals) {
|
|
61
|
+
forwarders[signal] = () => {
|
|
62
|
+
try {
|
|
63
|
+
child.kill(signal)
|
|
64
|
+
} catch {
|
|
65
|
+
// The child may have already exited.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
process.on(signal, forwarders[signal])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
child.on("exit", (code, signal) => {
|
|
72
|
+
clear() // kilocode_change
|
|
73
|
+
|
|
74
|
+
if (signal) {
|
|
75
|
+
process.kill(process.pid, signal)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const envPath = process.env.KILO_BIN_PATH
|
|
84
|
+
|
|
85
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
86
|
+
const scriptDir = path.dirname(scriptPath)
|
|
87
|
+
|
|
88
|
+
const cached = path.join(scriptDir, ".kilo")
|
|
89
|
+
|
|
90
|
+
const platformMap = {
|
|
91
|
+
darwin: "darwin",
|
|
92
|
+
linux: "linux",
|
|
93
|
+
win32: "windows",
|
|
94
|
+
}
|
|
95
|
+
const archMap = {
|
|
96
|
+
x64: "x64",
|
|
97
|
+
arm64: "arm64",
|
|
98
|
+
arm: "arm",
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let platform = platformMap[os.platform()]
|
|
102
|
+
if (!platform) {
|
|
103
|
+
platform = os.platform()
|
|
104
|
+
}
|
|
105
|
+
let arch = archMap[os.arch()]
|
|
106
|
+
if (!arch) {
|
|
107
|
+
arch = os.arch()
|
|
108
|
+
}
|
|
109
|
+
// resoft_change start - canonical China Resoft scope with legacy fallbacks
|
|
110
|
+
const base = "@chinaresoft/resoftcode-" + platform + "-" + arch
|
|
111
|
+
const scopeBase = "@chinaresoft/cli-" + platform + "-" + arch
|
|
112
|
+
const priorBase = "@resoft/cli-" + platform + "-" + arch
|
|
113
|
+
const legacyBase = "@kilocode/cli-" + platform + "-" + arch
|
|
114
|
+
// resoft_change end
|
|
115
|
+
// resoft_change start - prefer resoft binary, fall back to legacy kilo
|
|
116
|
+
const primaryBinary = platform === "windows" ? "resoftcode.exe" : "resoftcode"
|
|
117
|
+
const scopeBinary = platform === "windows" ? "resoft.exe" : "resoft"
|
|
118
|
+
const legacyBinary = platform === "windows" ? "kilo.exe" : "kilo"
|
|
119
|
+
// resoft_change end
|
|
120
|
+
|
|
121
|
+
function supportsAvx2() {
|
|
122
|
+
if (arch !== "x64") return false
|
|
123
|
+
|
|
124
|
+
if (platform === "linux") {
|
|
125
|
+
try {
|
|
126
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
127
|
+
} catch {
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (platform === "darwin") {
|
|
133
|
+
try {
|
|
134
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
135
|
+
encoding: "utf8",
|
|
136
|
+
timeout: 1500,
|
|
137
|
+
})
|
|
138
|
+
if (result.status !== 0) return false
|
|
139
|
+
return (result.stdout || "").trim() === "1"
|
|
140
|
+
} catch {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (platform === "windows") {
|
|
146
|
+
const cmd =
|
|
147
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
148
|
+
|
|
149
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
150
|
+
try {
|
|
151
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
152
|
+
encoding: "utf8",
|
|
153
|
+
timeout: 3000,
|
|
154
|
+
windowsHide: true,
|
|
155
|
+
})
|
|
156
|
+
if (result.status !== 0) continue
|
|
157
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
158
|
+
if (out === "true" || out === "1") return true
|
|
159
|
+
if (out === "false" || out === "0") return false
|
|
160
|
+
} catch {
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const names = (() => {
|
|
172
|
+
// resoft_change start - prefer @chinaresoft/resoftcode-* and keep prior scopes as fallbacks
|
|
173
|
+
const expand = (prefix) => {
|
|
174
|
+
const avx2 = supportsAvx2()
|
|
175
|
+
const baseline = arch === "x64" && !avx2
|
|
176
|
+
|
|
177
|
+
if (platform === "linux") {
|
|
178
|
+
const musl = (() => {
|
|
179
|
+
try {
|
|
180
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
181
|
+
} catch {
|
|
182
|
+
// ignore
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
187
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
188
|
+
if (text.includes("musl")) return true
|
|
189
|
+
} catch {
|
|
190
|
+
// ignore
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return false
|
|
194
|
+
})()
|
|
195
|
+
|
|
196
|
+
if (musl) {
|
|
197
|
+
if (arch === "x64") {
|
|
198
|
+
if (baseline) return [`${prefix}-baseline-musl`, `${prefix}-musl`, `${prefix}-baseline`, prefix]
|
|
199
|
+
return [`${prefix}-musl`, `${prefix}-baseline-musl`, prefix, `${prefix}-baseline`]
|
|
200
|
+
}
|
|
201
|
+
return [`${prefix}-musl`, prefix]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (arch === "x64") {
|
|
205
|
+
if (baseline) return [`${prefix}-baseline`, prefix, `${prefix}-baseline-musl`, `${prefix}-musl`]
|
|
206
|
+
return [prefix, `${prefix}-baseline`, `${prefix}-musl`, `${prefix}-baseline-musl`]
|
|
207
|
+
}
|
|
208
|
+
return [prefix, `${prefix}-musl`]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (arch === "x64") {
|
|
212
|
+
if (baseline) return [`${prefix}-baseline`, prefix]
|
|
213
|
+
return [prefix, `${prefix}-baseline`]
|
|
214
|
+
}
|
|
215
|
+
return [prefix]
|
|
216
|
+
}
|
|
217
|
+
return [...expand(base), ...expand(scopeBase), ...expand(priorBase), ...expand(legacyBase)]
|
|
218
|
+
// resoft_change end
|
|
219
|
+
})()
|
|
220
|
+
|
|
221
|
+
function findBinary(startDir) {
|
|
222
|
+
let current = startDir
|
|
223
|
+
for (;;) {
|
|
224
|
+
const modules = path.join(current, "node_modules")
|
|
225
|
+
if (fs.existsSync(modules)) {
|
|
226
|
+
for (const name of names) {
|
|
227
|
+
for (const binaryName of [primaryBinary, scopeBinary, legacyBinary]) {
|
|
228
|
+
const candidate = path.join(modules, name, "bin", binaryName)
|
|
229
|
+
if (fs.existsSync(candidate)) return candidate
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const parent = path.dirname(current)
|
|
234
|
+
if (parent === current) {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
current = parent
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
|
|
242
|
+
if (!resolved) {
|
|
243
|
+
console.error(
|
|
244
|
+
"It seems that your package manager failed to install the right version of the Resoft CLI for your platform. You can try manually installing " +
|
|
245
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
246
|
+
" package",
|
|
247
|
+
)
|
|
248
|
+
process.exit(1)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
run(resolved, resolved === cached ? findBinary(scriptDir) : undefined) // kilocode_change - preserve cached binary fallback
|
package/bin/resoft
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
process.env.RESOFT_CLI = "1"
|
|
11
|
+
|
|
12
|
+
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
|
13
|
+
function configureTreeSitterResources(target) {
|
|
14
|
+
const wasmDir = path.join(path.dirname(target), "tree-sitter")
|
|
15
|
+
if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
|
|
16
|
+
process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// kilocode_change end
|
|
20
|
+
|
|
21
|
+
function run(target, fallback) {
|
|
22
|
+
// kilocode_change - preserve cached binary fallback
|
|
23
|
+
configureTreeSitterResources(target) // kilocode_change
|
|
24
|
+
// kilocode_change start - fall through if the cached binary cannot be spawned
|
|
25
|
+
const child = (() => {
|
|
26
|
+
try {
|
|
27
|
+
return childProcess.spawn(target, process.argv.slice(2), {
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
})
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (fallback) {
|
|
32
|
+
run(fallback)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
console.error(error.message)
|
|
36
|
+
process.exit(1)
|
|
37
|
+
}
|
|
38
|
+
})()
|
|
39
|
+
if (!child) return
|
|
40
|
+
// kilocode_change end
|
|
41
|
+
|
|
42
|
+
const forwarders = {}
|
|
43
|
+
const clear = () => {
|
|
44
|
+
// kilocode_change - remove listeners before cached binary fallback
|
|
45
|
+
for (const signal of forwardedSignals) {
|
|
46
|
+
process.removeListener(signal, forwarders[signal])
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
child.on("error", (error) => {
|
|
51
|
+
clear() // kilocode_change
|
|
52
|
+
// kilocode_change start - fall through to findBinary() if cached binary fails
|
|
53
|
+
if (fallback) {
|
|
54
|
+
run(fallback)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
// kilocode_change end
|
|
58
|
+
console.error(error.message)
|
|
59
|
+
process.exit(1)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
for (const signal of forwardedSignals) {
|
|
63
|
+
forwarders[signal] = () => {
|
|
64
|
+
try {
|
|
65
|
+
child.kill(signal)
|
|
66
|
+
} catch {
|
|
67
|
+
// The child may have already exited.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
process.on(signal, forwarders[signal])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
child.on("exit", (code, signal) => {
|
|
74
|
+
clear() // kilocode_change
|
|
75
|
+
|
|
76
|
+
if (signal) {
|
|
77
|
+
process.kill(process.pid, signal)
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
process.exit(typeof code === "number" ? code : 0)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const envPath = process.env.KILO_BIN_PATH
|
|
86
|
+
|
|
87
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
88
|
+
const scriptDir = path.dirname(scriptPath)
|
|
89
|
+
|
|
90
|
+
// resoft_change start - prefer the Resoft cache link and retain the Kilo link as fallback
|
|
91
|
+
const cached = path.join(scriptDir, ".resoft")
|
|
92
|
+
const legacyCached = path.join(scriptDir, ".kilo")
|
|
93
|
+
// resoft_change end
|
|
94
|
+
|
|
95
|
+
const platformMap = {
|
|
96
|
+
darwin: "darwin",
|
|
97
|
+
linux: "linux",
|
|
98
|
+
win32: "windows",
|
|
99
|
+
}
|
|
100
|
+
const archMap = {
|
|
101
|
+
x64: "x64",
|
|
102
|
+
arm64: "arm64",
|
|
103
|
+
arm: "arm",
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let platform = platformMap[os.platform()]
|
|
107
|
+
if (!platform) {
|
|
108
|
+
platform = os.platform()
|
|
109
|
+
}
|
|
110
|
+
let arch = archMap[os.arch()]
|
|
111
|
+
if (!arch) {
|
|
112
|
+
arch = os.arch()
|
|
113
|
+
}
|
|
114
|
+
// resoft_change start - canonical China Resoft scope with legacy fallbacks
|
|
115
|
+
const base = "@chinaresoft/resoftcode-" + platform + "-" + arch
|
|
116
|
+
const scopeBase = "@chinaresoft/cli-" + platform + "-" + arch
|
|
117
|
+
const priorBase = "@resoft/cli-" + platform + "-" + arch
|
|
118
|
+
const legacyBase = "@kilocode/cli-" + platform + "-" + arch
|
|
119
|
+
// resoft_change end
|
|
120
|
+
// resoft_change start - prefer resoft binary, fall back to legacy kilo
|
|
121
|
+
const primaryBinary = platform === "windows" ? "resoftcode.exe" : "resoftcode"
|
|
122
|
+
const scopeBinary = platform === "windows" ? "resoft.exe" : "resoft"
|
|
123
|
+
const legacyBinary = platform === "windows" ? "kilo.exe" : "kilo"
|
|
124
|
+
// resoft_change end
|
|
125
|
+
|
|
126
|
+
function supportsAvx2() {
|
|
127
|
+
if (arch !== "x64") return false
|
|
128
|
+
|
|
129
|
+
if (platform === "linux") {
|
|
130
|
+
try {
|
|
131
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
132
|
+
} catch {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (platform === "darwin") {
|
|
138
|
+
try {
|
|
139
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
140
|
+
encoding: "utf8",
|
|
141
|
+
timeout: 1500,
|
|
142
|
+
})
|
|
143
|
+
if (result.status !== 0) return false
|
|
144
|
+
return (result.stdout || "").trim() === "1"
|
|
145
|
+
} catch {
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (platform === "windows") {
|
|
151
|
+
const cmd =
|
|
152
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
153
|
+
|
|
154
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
155
|
+
try {
|
|
156
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
157
|
+
encoding: "utf8",
|
|
158
|
+
timeout: 3000,
|
|
159
|
+
windowsHide: true,
|
|
160
|
+
})
|
|
161
|
+
if (result.status !== 0) continue
|
|
162
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
163
|
+
if (out === "true" || out === "1") return true
|
|
164
|
+
if (out === "false" || out === "0") return false
|
|
165
|
+
} catch {
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const names = (() => {
|
|
177
|
+
// resoft_change start - prefer @chinaresoft/resoftcode-* and keep prior scopes as fallbacks
|
|
178
|
+
const expand = (prefix) => {
|
|
179
|
+
const avx2 = supportsAvx2()
|
|
180
|
+
const baseline = arch === "x64" && !avx2
|
|
181
|
+
|
|
182
|
+
if (platform === "linux") {
|
|
183
|
+
const musl = (() => {
|
|
184
|
+
try {
|
|
185
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
186
|
+
} catch {
|
|
187
|
+
// ignore
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
192
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
193
|
+
if (text.includes("musl")) return true
|
|
194
|
+
} catch {
|
|
195
|
+
// ignore
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return false
|
|
199
|
+
})()
|
|
200
|
+
|
|
201
|
+
if (musl) {
|
|
202
|
+
if (arch === "x64") {
|
|
203
|
+
if (baseline) return [`${prefix}-baseline-musl`, `${prefix}-musl`, `${prefix}-baseline`, prefix]
|
|
204
|
+
return [`${prefix}-musl`, `${prefix}-baseline-musl`, prefix, `${prefix}-baseline`]
|
|
205
|
+
}
|
|
206
|
+
return [`${prefix}-musl`, prefix]
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (arch === "x64") {
|
|
210
|
+
if (baseline) return [`${prefix}-baseline`, prefix, `${prefix}-baseline-musl`, `${prefix}-musl`]
|
|
211
|
+
return [prefix, `${prefix}-baseline`, `${prefix}-musl`, `${prefix}-baseline-musl`]
|
|
212
|
+
}
|
|
213
|
+
return [prefix, `${prefix}-musl`]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (arch === "x64") {
|
|
217
|
+
if (baseline) return [`${prefix}-baseline`, prefix]
|
|
218
|
+
return [prefix, `${prefix}-baseline`]
|
|
219
|
+
}
|
|
220
|
+
return [prefix]
|
|
221
|
+
}
|
|
222
|
+
return [...expand(base), ...expand(scopeBase), ...expand(priorBase), ...expand(legacyBase)]
|
|
223
|
+
// resoft_change end
|
|
224
|
+
})()
|
|
225
|
+
|
|
226
|
+
function findBinary(startDir) {
|
|
227
|
+
let current = startDir
|
|
228
|
+
for (;;) {
|
|
229
|
+
const modules = path.join(current, "node_modules")
|
|
230
|
+
if (fs.existsSync(modules)) {
|
|
231
|
+
for (const name of names) {
|
|
232
|
+
for (const binaryName of [primaryBinary, scopeBinary, legacyBinary]) {
|
|
233
|
+
const candidate = path.join(modules, name, "bin", binaryName)
|
|
234
|
+
if (fs.existsSync(candidate)) return candidate
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const parent = path.dirname(current)
|
|
239
|
+
if (parent === current) {
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
current = parent
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const resolved =
|
|
247
|
+
envPath || (fs.existsSync(cached) ? cached : fs.existsSync(legacyCached) ? legacyCached : findBinary(scriptDir))
|
|
248
|
+
if (!resolved) {
|
|
249
|
+
console.error(
|
|
250
|
+
"It seems that your package manager failed to install the right version of the Resoft CLI for your platform. You can try manually installing " +
|
|
251
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
252
|
+
" package",
|
|
253
|
+
)
|
|
254
|
+
process.exit(1)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
run(resolved, resolved === cached || resolved === legacyCached ? findBinary(scriptDir) : undefined) // kilocode_change - preserve cached binary fallback
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chinaresoft/resoftcode",
|
|
3
|
+
"bin": {
|
|
4
|
+
"resoftcode": "bin/resoft",
|
|
5
|
+
"resoft": "bin/resoft",
|
|
6
|
+
"kilo": "bin/kilo",
|
|
7
|
+
"kilocode": "bin/kilo"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
|
|
11
|
+
},
|
|
12
|
+
"version": "0.1.0",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"optionalDependencies": {
|
|
15
|
+
"@chinaresoft/resoftcode-darwin-arm64": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/softctwo/Resoftcode.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/softctwo/Resoftcode#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/softctwo/Resoftcode/issues"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
// resoft_change start - canonical China Resoft scope with legacy fallbacks
|
|
80
|
+
const base = `@chinaresoft/resoftcode-${platform}-${arch}`
|
|
81
|
+
const scopeBase = `@chinaresoft/cli-${platform}-${arch}`
|
|
82
|
+
const priorBase = `@resoft/cli-${platform}-${arch}`
|
|
83
|
+
const legacyBase = `@kilocode/cli-${platform}-${arch}`
|
|
84
|
+
// resoft_change end
|
|
85
|
+
const avx2 = supportsAvx2()
|
|
86
|
+
const baseline = arch === "x64" && !avx2
|
|
87
|
+
|
|
88
|
+
if (platform === "linux") {
|
|
89
|
+
const musl = isMusl()
|
|
90
|
+
if (musl) {
|
|
91
|
+
if (arch === "x64") {
|
|
92
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base, `${scopeBase}-baseline-musl`, `${scopeBase}-musl`, `${scopeBase}-baseline`, scopeBase, `${priorBase}-baseline-musl`, `${priorBase}-musl`, `${priorBase}-baseline`, priorBase, `${legacyBase}-baseline-musl`, `${legacyBase}-musl`, `${legacyBase}-baseline`, legacyBase]
|
|
93
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`, `${scopeBase}-musl`, `${scopeBase}-baseline-musl`, scopeBase, `${scopeBase}-baseline`, `${priorBase}-musl`, `${priorBase}-baseline-musl`, priorBase, `${priorBase}-baseline`, `${legacyBase}-musl`, `${legacyBase}-baseline-musl`, legacyBase, `${legacyBase}-baseline`]
|
|
94
|
+
}
|
|
95
|
+
return [`${base}-musl`, base, `${scopeBase}-musl`, scopeBase, `${priorBase}-musl`, priorBase, `${legacyBase}-musl`, legacyBase]
|
|
96
|
+
}
|
|
97
|
+
if (arch === "x64") {
|
|
98
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`, `${scopeBase}-baseline`, scopeBase, `${scopeBase}-baseline-musl`, `${scopeBase}-musl`, `${priorBase}-baseline`, priorBase, `${priorBase}-baseline-musl`, `${priorBase}-musl`, `${legacyBase}-baseline`, legacyBase, `${legacyBase}-baseline-musl`, `${legacyBase}-musl`]
|
|
99
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`, scopeBase, `${scopeBase}-baseline`, `${scopeBase}-musl`, `${scopeBase}-baseline-musl`, priorBase, `${priorBase}-baseline`, `${priorBase}-musl`, `${priorBase}-baseline-musl`, legacyBase, `${legacyBase}-baseline`, `${legacyBase}-musl`, `${legacyBase}-baseline-musl`]
|
|
100
|
+
}
|
|
101
|
+
return [base, `${base}-musl`, scopeBase, `${scopeBase}-musl`, priorBase, `${priorBase}-musl`, legacyBase, `${legacyBase}-musl`]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (arch === "x64") {
|
|
105
|
+
if (baseline) return [`${base}-baseline`, base, `${scopeBase}-baseline`, scopeBase, `${priorBase}-baseline`, priorBase, `${legacyBase}-baseline`, legacyBase]
|
|
106
|
+
return [base, `${base}-baseline`, scopeBase, `${scopeBase}-baseline`, priorBase, `${priorBase}-baseline`, legacyBase, `${legacyBase}-baseline`]
|
|
107
|
+
}
|
|
108
|
+
return [base, scopeBase, priorBase, legacyBase]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function findBinary() {
|
|
112
|
+
const { platform } = detectPlatformAndArch()
|
|
113
|
+
// resoft_change start - prefer resoftcode binary, fall back to prior names
|
|
114
|
+
const binaryName = platform === "windows" ? "resoftcode.exe" : "resoftcode"
|
|
115
|
+
const scopeBinaryName = platform === "windows" ? "resoft.exe" : "resoft"
|
|
116
|
+
const legacyBinaryName = platform === "windows" ? "kilo.exe" : "kilo"
|
|
117
|
+
// resoft_change end
|
|
118
|
+
const names = getPackageNames()
|
|
119
|
+
|
|
120
|
+
for (const packageName of names) {
|
|
121
|
+
try {
|
|
122
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
123
|
+
const packageDir = path.dirname(packageJsonPath)
|
|
124
|
+
const binaryPath = path.join(packageDir, "bin", binaryName)
|
|
125
|
+
|
|
126
|
+
if (fs.existsSync(binaryPath)) {
|
|
127
|
+
return { binaryPath, binaryName }
|
|
128
|
+
}
|
|
129
|
+
const scopePath = path.join(packageDir, "bin", scopeBinaryName)
|
|
130
|
+
if (fs.existsSync(scopePath)) {
|
|
131
|
+
return { binaryPath: scopePath, binaryName: scopeBinaryName }
|
|
132
|
+
}
|
|
133
|
+
// resoft_change start - try the legacy binary name in the same package
|
|
134
|
+
const legacyPath = path.join(packageDir, "bin", legacyBinaryName)
|
|
135
|
+
if (fs.existsSync(legacyPath)) {
|
|
136
|
+
return { binaryPath: legacyPath, binaryName: legacyBinaryName }
|
|
137
|
+
}
|
|
138
|
+
// resoft_change end
|
|
139
|
+
} catch {
|
|
140
|
+
// package not installed, try next variant
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
throw new Error(`Could not find any binary package. Tried: ${names.map((n) => `"${n}"`).join(", ")}`)
|
|
145
|
+
}
|
|
146
|
+
// kilocode_change end
|
|
147
|
+
|
|
148
|
+
// kilocode_change start - copy tree-sitter WASM resources next to cached binary
|
|
149
|
+
function copyTreeSitterResources(binaryPath) {
|
|
150
|
+
const source = path.join(path.dirname(binaryPath), "tree-sitter")
|
|
151
|
+
const target = path.join(__dirname, "bin", "tree-sitter")
|
|
152
|
+
const runtime = path.join(source, "tree-sitter.wasm")
|
|
153
|
+
|
|
154
|
+
if (!fs.existsSync(runtime)) return
|
|
155
|
+
|
|
156
|
+
fs.rmSync(target, { recursive: true, force: true })
|
|
157
|
+
fs.cpSync(source, target, { recursive: true })
|
|
158
|
+
}
|
|
159
|
+
// kilocode_change end
|
|
160
|
+
|
|
161
|
+
function main() {
|
|
162
|
+
if (os.platform() === "win32") {
|
|
163
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
164
|
+
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { binaryPath, binaryName } = findBinary()
|
|
169
|
+
// resoft_change start - publish to both .resoft (canonical) and .kilo (legacy alias)
|
|
170
|
+
const targets = [
|
|
171
|
+
path.join(__dirname, "bin", ".resoft"),
|
|
172
|
+
path.join(__dirname, "bin", ".kilo"),
|
|
173
|
+
]
|
|
174
|
+
for (const target of targets) {
|
|
175
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
176
|
+
try {
|
|
177
|
+
fs.linkSync(binaryPath, target)
|
|
178
|
+
} catch {
|
|
179
|
+
fs.copyFileSync(binaryPath, target)
|
|
180
|
+
}
|
|
181
|
+
fs.chmodSync(target, 0o755)
|
|
182
|
+
}
|
|
183
|
+
copyTreeSitterResources(binaryPath) // kilocode_change
|
|
184
|
+
// resoft_change end
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
void main()
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error("Failed to setup resoft binary:", error.message)
|
|
191
|
+
process.exit(1)
|
|
192
|
+
}
|