Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,7 +52,7 @@ The plugin also auto-registers (OpenCode only):
| **Keyword (ripgrep)** | `@vscode/ripgrep` | Exact-match + phrase lookup over files |
| **Semantic (rag-cli)** | `@mathew-cf/rag-cli` | Similarity search via local embeddings |

Both are declared as **required dependencies**: installing the plugin pulls in prebuilt binaries for your platform automatically (macOS ARM64/x64, Linux x64/ARM64; ripgrep additionally covers Windows and FreeBSD). No Rust toolchain, no `brew install`, no `$PATH` plumbing.
Both are declared as **required dependencies**: installing the plugin pulls in prebuilt binaries for your platform automatically (macOS ARM64/x64, Linux x64/ARM64, Windows x64). ripgrep additionally covers Windows and FreeBSD. No Rust toolchain, no `brew install`, no `$PATH` plumbing.

Pre-cache the embedding model once (~90MB) to make the first semantic search instant:

Expand Down
36 changes: 34 additions & 2 deletions src/lib/rag.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,25 @@ export interface RagStatus {
*/
export function resolveRagBinary(): string | null {
try {
// Prefer the platform binary directly. On Windows, Bun cannot exec
// a .js shim via CreateProcess, so resolving the binary avoids a
// silent "Executable not found in $PATH" error.
try {
const platform = require("@mathew-cf/rag-cli/src/platform") as {
platformKey(p: string, a: string): string;
isSupported(key: string): boolean;
subpackageName(key: string): string;
binaryFilename(p: string): string;
};
const key = platform.platformKey(process.platform, process.arch);
if (platform.isSupported(key)) {
return require.resolve(
`${platform.subpackageName(key)}/bin/${platform.binaryFilename(process.platform)}`,
);
}
} catch {
// Fall through to the JS shim.
}
return require.resolve("@mathew-cf/rag-cli/bin/rag.js");
} catch {
return null;
Expand DownExpand Up@@ -74,7 +93,7 @@ export function installGuidance(): string {
"",
"Usually this means one of:",
" - Your host platform isn't covered by the prebuilt binaries",
" (supported: macOS ARM64/x64, Linux x64/ARM64).",
" (supported: macOS ARM64/x64, Linux x64/ARM64, Windows x64).",
" - `npm install` or the equivalent plugin install skipped",
" optionalDependencies.",
"",
Expand DownExpand Up@@ -104,6 +123,10 @@ export async function ragSearch(args: {
if (!shim) return "";
const k = String(args.topK ?? 15);
return Bun.$`${shim} search ${args.query} -i ${args.indexDir} -k ${k} --json`
.env({
...process.env,
HOME: process.env.HOME || process.env.USERPROFILE,
})
.text()
.catch(() => "");
}
Expand All@@ -125,6 +148,10 @@ export function spawnRagIndex(args: {
Bun.spawn([shim, "index", args.memoryDir, "-o", args.indexDir], {
stdout: "ignore",
stderr: "ignore",
env: {
...process.env,
HOME: process.env.HOME || process.env.USERPROFILE,
},
});
return true;
}
Expand All@@ -139,7 +166,12 @@ export async function downloadModel(): Promise<string> {
if (!shim) return installGuidance();

try {
const out = await Bun.$`${shim} download`.text();
const out = await Bun.$`${shim} download`
.env({
...process.env,
HOME: process.env.HOME || process.env.USERPROFILE,
})
.text();
return out.trim() || "Model downloaded.";
} catch (err) {
return `rag download failed: ${String(err)}`;
Expand Down