From 7f979dbfdd8cbd571daf5dd537fa3783dc4e1393 Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Wed, 20 May 2026 22:45:44 +0200 Subject: [PATCH] fix(cli): preserve tree-sitter installer resources --- install | 4 ++++ packages/opencode/bin/kilo | 11 ++++++++--- .../test/kilocode/bin-tree-sitter-env.test.ts | 13 ++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/install b/install index d7dbd69e5e..f78cbc8d1b 100755 --- a/install +++ b/install @@ -348,6 +348,10 @@ download_and_install() { # kilocode_change start mv "$tmp_dir/kilo" "$INSTALL_DIR" + rm -rf "${INSTALL_DIR}/tree-sitter" + if [ -d "$tmp_dir/tree-sitter" ]; then + mv "$tmp_dir/tree-sitter" "$INSTALL_DIR" + fi chmod 755 "${INSTALL_DIR}/kilo" # kilocode_change end rm -rf "$tmp_dir" diff --git a/packages/opencode/bin/kilo b/packages/opencode/bin/kilo index 1b12be67fe..c31c7c635f 100755 --- a/packages/opencode/bin/kilo +++ b/packages/opencode/bin/kilo @@ -5,13 +5,17 @@ const fs = require("fs") const path = require("path") const os = require("os") -function run(target) { - // kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources +// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources +function configureTreeSitterResources(target) { const wasmDir = path.join(path.dirname(target), "tree-sitter") if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) { process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir } - // kilocode_change end +} +// kilocode_change end + +function run(target) { + configureTreeSitterResources(target) // kilocode_change const result = childProcess.spawnSync(target, process.argv.slice(2), { stdio: "inherit", }) @@ -34,6 +38,7 @@ const scriptDir = path.dirname(scriptPath) // kilocode_change start - fall through to findBinary() if cached binary fails const cached = path.join(scriptDir, ".kilo") if (fs.existsSync(cached)) { + configureTreeSitterResources(cached) const result = childProcess.spawnSync(cached, process.argv.slice(2), { stdio: "inherit", }) diff --git a/packages/opencode/test/kilocode/bin-tree-sitter-env.test.ts b/packages/opencode/test/kilocode/bin-tree-sitter-env.test.ts index 08a50ba121..308368046d 100644 --- a/packages/opencode/test/kilocode/bin-tree-sitter-env.test.ts +++ b/packages/opencode/test/kilocode/bin-tree-sitter-env.test.ts @@ -18,25 +18,28 @@ describe("bin/kilo tree-sitter resources", () => { await writeFile(join(wasm, "tree-sitter.wasm"), "wasm") await writeFile(bin, "binary") - return { bin, log, wasm } + return { bin, log, wasm, wrapper: join(dir, "kilo") } } - async function run(root: string, bin: string, log: string) { + async function run(root: string, bin: string | undefined, log: string, wrapper?: string) { const capture = ` const kiloFs = require("fs") const kiloChild = require("child_process") const log = process.argv[1] +const wrapper = process.argv[2] +const realpathSync = kiloFs.realpathSync +kiloFs.realpathSync = (file) => wrapper && file === __filename ? wrapper : realpathSync(file) kiloChild.spawnSync = () => { kiloFs.writeFileSync(log, process.env.KILO_TREE_SITTER_WASM_DIR || "") return { status: 0 } } ` const source = (await Bun.file(script).text()).replace(/^#!.*\n/, "") - return Bun.spawnSync(["node", "--input-type=commonjs", "--eval", capture + source, log], { + return Bun.spawnSync(["node", "--input-type=commonjs", "--eval", capture + source, log, wrapper ?? ""], { cwd: root, env: { PATH: process.env.PATH ?? "", - KILO_BIN_PATH: bin, + ...(bin ? { KILO_BIN_PATH: bin } : {}), }, }) } @@ -58,7 +61,7 @@ kiloChild.spawnSync = () => { const root = await mkdtemp(join(tmpdir(), "kilo-bin-tree-sitter-")) try { const item = await setup(root, false) - const proc = await run(root, item.bin, item.log) + const proc = await run(root, undefined, item.log, item.wrapper) expect(proc.exitCode).toBe(0) expect(await Bun.file(item.log).text()).toBe(item.wasm)