diff --git a/package.json b/package.json index 88ea709..27560ef 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "@four-bytes/four-opencode-brain", - "version": "1.7.1", + "version": "1.7.2", "description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base", "license": "Apache-2.0", "type": "module", "scripts": { "build": "NODE_ENV=production bun run scripts/build.ts", - "postinstall": "ln -sf node_modules/node-llama-cpp/llama llama && rm -rf node_modules/node-llama-cpp/bins/linux-x64 && cp -r node_modules/@node-llama-cpp/linux-x64/bins/linux-x64 node_modules/node-llama-cpp/bins/linux-x64", + "postinstall": "if [ \"$BRAIN_EMBED_ENABLE\" = \"true\" ] || [ \"$BRAIN_EMBED_ENABLE\" = \"1\" ]; then ln -sf node_modules/node-llama-cpp/llama llama && rm -rf node_modules/node-llama-cpp/bins/linux-x64 && cp -r node_modules/@node-llama-cpp/linux-x64/bins/linux-x64 node_modules/node-llama-cpp/bins/linux-x64; fi", "test": "bun test" }, "keywords": [ diff --git a/scripts/build.ts b/scripts/build.ts index b0d295a..014a0f1 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -4,11 +4,15 @@ import { rmSync, renameSync } from "node:fs"; rmSync("dist", { recursive: true, force: true }); // 2. Server build: Bun bundler on clean dist (FIRST — no stale artifacts) +const externals = ["@opencode-ai/*"]; +if (process.env.BRAIN_EMBED_ENABLE === "true" || process.env.BRAIN_EMBED_ENABLE === "1") { + externals.push("@node-llama-cpp/*"); +} const server = await Bun.build({ entrypoints: ["src/four-opencode-brain.ts"], outdir: "dist", target: "bun", - external: ["@opencode-ai/*", "@node-llama-cpp/*"], + external: externals, minify: process.env.NODE_ENV === "production", }); diff --git a/src/embed/embeddingService.ts b/src/embed/embeddingService.ts index 36472a1..3376d91 100644 --- a/src/embed/embeddingService.ts +++ b/src/embed/embeddingService.ts @@ -105,8 +105,14 @@ export class EmbeddingService { if (this.initialized) return; if (this.initPromise) return this.initPromise; + log("debug", "embedding-service", "initialize() called", { + brainEmbedEnable: process.env.BRAIN_EMBED_ENABLE ?? "(unset)", + caller: new Error().stack?.split("\n")[2]?.trim().slice(0, 120), + }); + this.initPromise = (async () => { if (process.env.BRAIN_EMBED_ENABLE !== "true" && process.env.BRAIN_EMBED_ENABLE !== "1") { + log("info", "embedding-service", "BRAIN_EMBED_ENABLE not set — skipping real embedding model, using pseudo-embeddings"); this.initialized = true; this._available = false; return; @@ -127,6 +133,7 @@ export class EmbeddingService { this.model = await llama.loadModel({ modelPath: resolvedModelPath }); this.ctx = await this.model.createEmbeddingContext(); this._available = true; + log("info", "embedding-service", "BRAIN_EMBED_ENABLE=1 — real embedding model initialized successfully", { dimensions: this.dimensions || "lazy" }); log("info", "embedding-service", "Real embedding model loaded successfully"); } catch (err) { this._available = false;