@kilocode/cli 7.0.30 → 7.0.33

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.
Files changed (3) hide show
  1. package/bin/kilo +19 -4
  2. package/package.json +12 -12
  3. package/postinstall.mjs +111 -84
package/bin/kilo CHANGED
@@ -22,6 +22,24 @@ if (envPath) {
22
22
  run(envPath)
23
23
  }
24
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
+
25
43
  const platformMap = {
26
44
  darwin: "darwin",
27
45
  linux: "linux",
@@ -157,9 +175,6 @@ function findBinary(startDir) {
157
175
  }
158
176
  }
159
177
 
160
- const scriptPath = fs.realpathSync(__filename)
161
- const scriptDir = path.dirname(scriptPath)
162
-
163
178
  const resolved = findBinary(scriptDir)
164
179
  if (!resolved) {
165
180
  console.error(
@@ -170,4 +185,4 @@ if (!resolved) {
170
185
  process.exit(1)
171
186
  }
172
187
 
173
- run(resolved)
188
+ run(resolved)
package/package.json CHANGED
@@ -7,20 +7,20 @@
7
7
  "scripts": {
8
8
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
9
9
  },
10
- "version": "7.0.30",
10
+ "version": "7.0.33",
11
11
  "license": "MIT",
12
12
  "optionalDependencies": {
13
- "@kilocode/cli-linux-arm64": "7.0.30",
14
- "@kilocode/cli-linux-x64-musl": "7.0.30",
15
- "@kilocode/cli-darwin-arm64": "7.0.30",
16
- "@kilocode/cli-linux-arm64-musl": "7.0.30",
17
- "@kilocode/cli-windows-x64": "7.0.30",
18
- "@kilocode/cli-linux-x64-baseline-musl": "7.0.30",
19
- "@kilocode/cli-linux-x64": "7.0.30",
20
- "@kilocode/cli-darwin-x64-baseline": "7.0.30",
21
- "@kilocode/cli-darwin-x64": "7.0.30",
22
- "@kilocode/cli-windows-x64-baseline": "7.0.30",
23
- "@kilocode/cli-linux-x64-baseline": "7.0.30"
13
+ "@kilocode/cli-linux-arm64": "7.0.33",
14
+ "@kilocode/cli-linux-x64-musl": "7.0.33",
15
+ "@kilocode/cli-darwin-arm64": "7.0.33",
16
+ "@kilocode/cli-linux-arm64-musl": "7.0.33",
17
+ "@kilocode/cli-windows-x64": "7.0.33",
18
+ "@kilocode/cli-linux-x64-baseline-musl": "7.0.33",
19
+ "@kilocode/cli-linux-x64": "7.0.33",
20
+ "@kilocode/cli-darwin-x64-baseline": "7.0.33",
21
+ "@kilocode/cli-darwin-x64": "7.0.33",
22
+ "@kilocode/cli-windows-x64-baseline": "7.0.33",
23
+ "@kilocode/cli-linux-x64-baseline": "7.0.33"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
package/postinstall.mjs CHANGED
@@ -3,123 +3,150 @@
3
3
  import fs from "fs"
4
4
  import path from "path"
5
5
  import os from "os"
6
+ import childProcess from "child_process"
6
7
  import { fileURLToPath } from "url"
7
8
  import { createRequire } from "module"
8
9
 
9
10
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
11
  const require = createRequire(import.meta.url)
11
12
 
12
- function detectPlatformAndArch() {
13
- // Map platform names
14
- let platform
15
- switch (os.platform()) {
16
- case "darwin":
17
- platform = "darwin"
18
- break
19
- case "linux":
20
- platform = "linux"
21
- break
22
- case "win32":
23
- platform = "windows"
24
- break
25
- default:
26
- platform = os.platform()
27
- break
28
- }
29
-
30
- // Map architecture names
31
- let arch
32
- switch (os.arch()) {
33
- case "x64":
34
- arch = "x64"
35
- break
36
- case "arm64":
37
- arch = "arm64"
38
- break
39
- case "arm":
40
- arch = "arm"
41
- break
42
- default:
43
- arch = os.arch()
44
- break
45
- }
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
+ }
46
24
 
25
+ function detectPlatformAndArch() {
26
+ const platform = platformMap[os.platform()] || os.platform()
27
+ const arch = archMap[os.arch()] || os.arch()
47
28
  return { platform, arch }
48
29
  }
49
30
 
50
- function findBinary() {
31
+ function supportsAvx2() {
51
32
  const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `@kilocode/cli-${platform}-${arch}`
53
- const binaryName = platform === "windows" ? "kilo.exe" : "kilo"
54
-
55
- try {
56
- // Use require.resolve to find the package
57
- const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
- const packageDir = path.dirname(packageJsonPath)
59
- const binaryPath = path.join(packageDir, "bin", binaryName)
33
+ if (arch !== "x64") return false
60
34
 
61
- if (!fs.existsSync(binaryPath)) {
62
- throw new Error(`Binary not found at ${binaryPath}`)
35
+ if (platform === "linux") {
36
+ try {
37
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
38
+ } catch {
39
+ return false
63
40
  }
41
+ }
64
42
 
65
- return { binaryPath, binaryName }
66
- } catch (error) {
67
- throw new Error(`Could not find package ${packageName}: ${error.message}`)
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
+ }
68
54
  }
69
- }
70
55
 
71
- function prepareBinDirectory(binaryName) {
72
- const binDir = path.join(__dirname, "bin")
73
- const targetPath = path.join(binDir, binaryName)
56
+ return false
57
+ }
74
58
 
75
- // Ensure bin directory exists
76
- if (!fs.existsSync(binDir)) {
77
- fs.mkdirSync(binDir, { recursive: true })
59
+ function isMusl() {
60
+ try {
61
+ if (fs.existsSync("/etc/alpine-release")) return true
62
+ } catch {
63
+ // ignore
78
64
  }
79
65
 
80
- // Remove existing binary/symlink if it exists
81
- if (fs.existsSync(targetPath)) {
82
- fs.unlinkSync(targetPath)
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
83
72
  }
84
73
 
85
- return { binDir, targetPath }
74
+ return false
86
75
  }
87
76
 
88
- function symlinkBinary(sourcePath, binaryName) {
89
- const { targetPath } = prepareBinDirectory(binaryName)
90
-
91
- fs.symlinkSync(sourcePath, targetPath)
92
- console.log(`kilo binary symlinked: ${targetPath} -> ${sourcePath}`)
77
+ function getPackageNames() {
78
+ const { platform, arch } = detectPlatformAndArch()
79
+ const base = `@kilocode/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
+ }
93
98
 
94
- // Verify the file exists after operation
95
- if (!fs.existsSync(targetPath)) {
96
- throw new Error(`Failed to symlink binary to ${targetPath}`)
99
+ if (arch === "x64") {
100
+ if (baseline) return [`${base}-baseline`, base]
101
+ return [base, `${base}-baseline`]
97
102
  }
103
+ return [base]
98
104
  }
99
105
 
100
- async function main() {
101
- try {
102
- if (os.platform() === "win32") {
103
- // On Windows, the .exe is already included in the package and bin field points to it
104
- // No postinstall setup needed
105
- console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
- return
106
+ function findBinary() {
107
+ const { platform } = detectPlatformAndArch()
108
+ const binaryName = platform === "windows" ? "kilo.exe" : "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
107
122
  }
123
+ }
124
+
125
+ throw new Error(`Could not find any binary package. Tried: ${names.map((n) => `"${n}"`).join(", ")}`)
126
+ }
127
+ // kilocode_change end
108
128
 
109
- // On non-Windows platforms, just verify the binary package exists
110
- // Don't replace the wrapper script - it handles binary execution
111
- const { binaryPath } = findBinary()
112
- console.log(`Platform binary verified at: ${binaryPath}`)
113
- console.log("Wrapper script will handle binary execution")
114
- } catch (error) {
115
- console.error("Failed to setup kilo binary:", error.message)
116
- process.exit(1)
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)
117
143
  }
144
+ fs.chmodSync(target, 0o755)
118
145
  }
119
146
 
120
147
  try {
121
148
  main()
122
149
  } catch (error) {
123
- console.error("Postinstall script error:", error.message)
124
- process.exit(0)
150
+ console.error("Failed to setup kilo binary:", error.message)
151
+ process.exit(1)
125
152
  }