diff --git a/bun.lock b/bun.lock index 7206b6f..03b28d6 100644 --- a/bun.lock +++ b/bun.lock @@ -8,7 +8,7 @@ "@opencode-ai/plugin": "1.16.2", "@opentui/core": "0.3.2", "@opentui/solid": "0.3.2", - "@four-bytes/opencode-plugin-lib": "github:four-bytes/opencode-plugin-lib", + "@four-bytes/opencode-plugin-lib": "github:four-bytes/opencode-plugin-lib#v0.2.0", "node-llama-cpp": "3.18.1", "solid-js": "1.9.13", "tree-sitter-javascript": "0.25.0", @@ -81,7 +81,7 @@ "@babel/types": ["@babel/types@7.29.7", "", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA=="], - "@four-bytes/opencode-plugin-lib": ["@four-bytes/opencode-plugin-lib@github:four-bytes/opencode-plugin-lib#5680406", { "peerDependencies": { "@opencode-ai/plugin": ">=1.16.0" } }, "four-bytes-opencode-plugin-lib-5680406", "sha512-9XIrIbrq52ErspssAdKzRCVkLTmNUXXmIzGZ7SRjpFsqGmPLHJYy7M2pQTfDcnPxbzoBPyb+UyvS47S+Ah+NHw=="], + "@four-bytes/opencode-plugin-lib": ["@four-bytes/opencode-plugin-lib@github:four-bytes/opencode-plugin-lib#6b8d915", { "peerDependencies": { "@opencode-ai/plugin": ">=1.16.0" } }, "four-bytes-opencode-plugin-lib-6b8d915", "sha512-bMnpphF9E+R0OuEyNKH5/ScuEXBKBJtgF0M+kigSAVEvypd1F2ZJvN6b97hSCtOqQwumLS0j/UivDnNEB4vIdw=="], "@huggingface/jinja": ["@huggingface/jinja@0.5.9", "", {}, "sha512-uWTG+l3VJRsl7EXxYizuL3P+cCPoc3cRqbWWRcQN0FhejRfbdq0RNhCmbY/YDtnTcz9icdLYuLDjsnz4d8JMuw=="], diff --git a/package.json b/package.json index 29625e7..b113898 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@four-bytes/four-opencode-brain", - "version": "1.4.1", + "version": "1.5.1", "description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base with content-hash dedup and per-session LRU cache", "license": "Apache-2.0", "type": "module", @@ -18,7 +18,7 @@ "four-bytes" ], "dependencies": { - "@four-bytes/opencode-plugin-lib": "github:four-bytes/opencode-plugin-lib", + "@four-bytes/opencode-plugin-lib": "github:four-bytes/opencode-plugin-lib#v0.2.0", "@opencode-ai/plugin": "1.16.2", "@opentui/core": "0.3.2", "@opentui/solid": "0.3.2", diff --git a/src/cache.ts b/src/cache.ts index 353112b..409f19b 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,58 +1,2 @@ -// --------------------------------------------------------------------------- -// Per-session LRU cache using Map (TTL = process lifetime) -// --------------------------------------------------------------------------- - -export class LRUCache { - private map = new Map(); - - constructor(private maxEntries: number = 1000) {} - - get(key: K): V | undefined { - const entry = this.map.get(key); - if (!entry) return undefined; - // Refresh LRU position - this.map.delete(key); - this.map.set(key, entry); - return entry.value; - } - - set(key: K, value: V): void { - if (this.map.has(key)) this.map.delete(key); - else if (this.map.size >= this.maxEntries) { - // Evict oldest (first key in insertion order) - const firstKey = this.map.keys().next().value; - if (firstKey !== undefined) this.map.delete(firstKey); - } - this.map.set(key, { value, ts: Date.now() }); - } - - has(key: K): boolean { - return this.map.has(key); - } - - clear(): void { - this.map.clear(); - } - - get size(): number { - return this.map.size; - } -} - -// --------------------------------------------------------------------------- -// Singleton session cache — reset on plugin init / opencode restart -// --------------------------------------------------------------------------- - -export const sessionCache = { - embeddings: new LRUCache(500), // text hash → embedding vector - search: new LRUCache(200), // query+filters serialized → results - chunks: new LRUCache(500), // chunk ID → chunk data - hashes: new LRUCache(2000), // content → sha256 hex - - reset(): void { - this.embeddings.clear(); - this.search.clear(); - this.chunks.clear(); - this.hashes.clear(); - }, -}; +// Re-exported from @four-bytes/opencode-plugin-lib +export { LRUCache, sessionCache } from "@four-bytes/opencode-plugin-lib"; diff --git a/src/logger.ts b/src/logger.ts index 38638f8..d43d3c7 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,5 +1,5 @@ // --------------------------------------------------------------------------- -// Throttled, rate-limited logger — no ANSI colors, compact single-line output +// Throttled, rate-limited console logger — captured by opencode session log // --------------------------------------------------------------------------- type LogLevel = "debug" | "info" | "warn" | "error"; @@ -23,11 +23,6 @@ function shouldLog(key: string, intervalMs: number = 60000): boolean { return false; } -/** - * Suppress all console output. Use after the initial version banner. - * When silent, only memory-based log aggregation happens — no console writes. - * Toggle back with setSilent(false) for debug mode. - */ export function setSilent(val: boolean): void { silent = val; } @@ -41,11 +36,9 @@ export function log( if (level === "debug" && process.env.BRAIN_DEBUG !== "true") return; if (level === "warn" || level === "info") { - // Throttle repetitive messages to once per 60s if (!shouldLog(key, 60000)) return; } - // Silent mode: skip all console output (errors still go to stderr) if (silent && level !== "error") return; const timestamp = new Date().toISOString(); @@ -55,5 +48,6 @@ export function log( if (level === "error") console.error(line); else if (level === "warn") console.warn(line); + else if (level === "debug") console.error(line); else console.log(line); }