diff --git a/.gitignore b/.gitignore index fffb76b..689124f 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,4 @@ test-*.cjs test-*.mjs # Benchmark results -benchmark-results/ \ No newline at end of file +benchmark-results/ diff --git a/package-lock.json b/package-lock.json index 8b1e086..849561a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opencode-codebase-index", - "version": "0.4.1", + "version": "0.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opencode-codebase-index", - "version": "0.4.1", + "version": "0.5.1", "license": "MIT", "dependencies": { "chokidar": "^5.0.0", diff --git a/package.json b/package.json index a161651..efa2678 100644 --- a/package.json +++ b/package.json @@ -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" ] }, @@ -99,5 +101,4 @@ "optional": true } } - -} \ No newline at end of file +} diff --git a/src/native/index.ts b/src/native/index.ts index c59dd5f..4759432 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -6,6 +6,26 @@ 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") { @@ -13,9 +33,9 @@ function getNativeBinding() { } 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 { diff --git a/src/tools/index.ts b/src/tools/index.ts index e689b3b..3649a41 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -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); @@ -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,