Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/quiet-ripgrep-packaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kilocode/cli": patch
"kilo-code": patch
---

Use an installed ripgrep binary for codebase search in packaged Kilo builds.
2 changes: 2 additions & 0 deletions packages/core/src/ripgrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface GrepInput {
}

export interface Interface {
readonly filepath: Effect.Effect<string, globalThis.Error> // kilocode_change - share Kilo's managed binary with bundled integrations
readonly find: (input: FindInput) => Effect.Effect<readonly Entry[], Error>
readonly glob: (input: GlobInput) => Effect.Effect<SearchResult<Entry>, Error> // kilocode_change
readonly grep: (input: GrepInput) => Effect.Effect<SearchResult<Match>, Error | InvalidPatternError> // kilocode_change
Expand Down Expand Up @@ -176,6 +177,7 @@ export const layer = Layer.effect(
}

return Service.of({
filepath: binary.filepath, // kilocode_change - share Kilo's managed binary with bundled integrations
glob: (input) =>
run<string>({
cwd: input.cwd,
Expand Down
13 changes: 12 additions & 1 deletion packages/opencode/script/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bun

import { $ } from "bun"
import type { BunPlugin } from "bun" // kilocode_change
import fs from "fs"
import os from "os" // kilocode_change
import path from "path"
Expand Down Expand Up @@ -31,6 +32,16 @@ const baselineFlag = process.argv.includes("--baseline")
const skipInstall = process.argv.includes("--skip-install")
const sourcemapsFlag = process.argv.includes("--sourcemaps")
const plugin = createSolidTransformPlugin()
// kilocode_change start - packaged CLIs have no node_modules tree for Morph's optional platform package
const morphRipgrepPlugin: BunPlugin = {
name: "kilocode-morph-ripgrep",
setup(build) {
build.onResolve({ filter: /^@vscode\/ripgrep$/ }, () => ({
path: path.join(dir, "src/kilocode/morph-ripgrep.ts"),
}))
},
}
// kilocode_change end

// kilocode_change start - codebase indexing
async function copyTreeSitterWasms(outputDir: string) {
Expand Down Expand Up @@ -267,7 +278,7 @@ for (const item of targets) {
await Bun.build({
conditions: ["bun", "node"], // kilocode_change - port anomalyco/opencode#30873; current form from #31566
tsconfig: "./tsconfig.json",
plugins: [plugin],
plugins: [plugin, morphRipgrepPlugin], // kilocode_change - use Morph's system-rg fallback in packaged CLIs
// kilocode_change start - skip sourcemaps for release builds (each .js.map adds ~50 MB per target → ~600 MB total)
sourcemap: Script.release ? "none" : "external",
external: ["node-gyp", ...LanceDBRuntime.external],
Expand Down
10 changes: 10 additions & 0 deletions packages/opencode/src/kilocode/morph-ripgrep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import path from "path"
import { Global } from "@opencode-ai/core/global"
import { which } from "@opencode-ai/core/util/which"

// Morph's local provider imports this path directly, but compiled Kilo binaries
// do not ship its optional @vscode/ripgrep platform package. Kilo's codebase
// search preflights its ripgrep layer, so the managed fallback exists before
// Morph's first spawn. Avoid Git-for-Windows' potentially incompatible MSYS rg.
const system = process.platform === "win32" ? null : which("rg")
export const rgPath = system ?? path.join(Global.Path.bin, process.platform === "win32" ? "rg.exe" : "rg")
3 changes: 3 additions & 0 deletions packages/opencode/src/tool/warpgrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Telemetry } from "@kilocode/kilo-telemetry" // kilocode_change
import { Instance } from "../kilocode/instance" // kilocode_change
import { EventV2Bridge } from "@/event-v2-bridge" // kilocode_change
import { TuiEvent } from "@/server/tui-event" // kilocode_change
import { Ripgrep } from "@opencode-ai/core/ripgrep" // kilocode_change
import DESCRIPTION from "./warpgrep.txt"

// FREE_PERIOD_TODO: Remove KILO_WARPGREP_PROXY_URL constant and the proxy
Expand All @@ -22,6 +23,7 @@ export const CodebaseSearchTool = Tool.define(
"codebase_search",
Effect.gen(function* () {
const events = yield* EventV2Bridge.Service // kilocode_change
const ripgrep = yield* Ripgrep.Service // kilocode_change - reuse Kilo's managed binary for Morph search
return {
description: DESCRIPTION,
parameters: Parameters,
Expand All @@ -45,6 +47,7 @@ export const CodebaseSearchTool = Tool.define(
timeout: 60_000,
})

yield* ripgrep.filepath // kilocode_change - ensure Morph's replacement path exists before its first spawn
Comment thread
Hardik180704 marked this conversation as resolved.
const result = yield* Effect.promise(() =>
client.execute({
searchTerm: params.query,
Expand Down
Loading