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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ test-*.cjs
test-*.mjs

# Benchmark results
benchmark-results/
benchmark-results/
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"aarch64-apple-darwin",
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"aarch64-unknown-linux-musl",
"x86_64-pc-windows-msvc"
]
},
Expand Down Expand Up @@ -99,5 +101,4 @@
"optional": true
}
}

}
}
24 changes: 22 additions & 2 deletions src/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ function getNativeBinding() {
const platform = os.platform();
const arch = os.arch();

// Detect musl vs glibc on Linux
const isMusl = () => {
try {
const lddVersion = require("child_process").execSync("ldd --version", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] });
return lddVersion.includes("musl") || lddVersion.includes("MUSL");
} catch {
// Fallback: check if /etc/alpine-release exists (Alpine = musl)
try {
require("fs").accessSync("/etc/alpine-release");
return true;
} catch {
return false;
}
}
};

// Cache the result
const musl = isMusl();
const libc = musl ? "musl" : "gnu";

let bindingName: string;

if (platform === "darwin" && arch === "arm64") {
bindingName = "codebase-index-native.darwin-arm64.node";
} else if (platform === "darwin" && arch === "x64") {
bindingName = "codebase-index-native.darwin-x64.node";
} else if (platform === "linux" && arch === "x64") {
bindingName = "codebase-index-native.linux-x64-gnu.node";
bindingName = `codebase-index-native.linux-x64-${libc}.node`;
} else if (platform === "linux" && arch === "arm64") {
bindingName = "codebase-index-native.linux-arm64-gnu.node";
bindingName = `codebase-index-native.linux-arm64-${libc}.node`;
} else if (platform === "win32" && arch === "x64") {
bindingName = "codebase-index-native.win32-x64-msvc.node";
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export const index_codebase: ToolDefinition = tool({
async execute(args, context) {
const indexer = getIndexer();

// Guard: use noop if context is not provided
const safeContext = context || { metadata: () => {} };

if (args.estimateOnly) {
const estimate = await indexer.estimateCost();
return formatCostEstimate(estimate);
Expand All @@ -75,7 +78,7 @@ export const index_codebase: ToolDefinition = tool({
}

const stats = await indexer.index((progress) => {
context.metadata({
safeContext.metadata({
title: formatProgressTitle(progress),
metadata: {
phase: progress.phase,
Expand Down
Loading