Initial scaffold: open-memory plugin for OpenCode
- Plugin entry point with hooks: experimental.session.compacting, experimental.chat.system.transform, event - Context tracker: SSE-based token tracking per session with green/yellow/red/critical thresholds - Tools: memory_context, memory_compact, memory_summary, memory_sessions, memory_messages, memory_search, memory_plans - History module: sqlite3 queries + markdown rendering - Compaction: improved prompt emphasizing self-continuity - Research docs: ARCHITECTURE.md + opencode-memory reference
This commit is contained in:
22
src/history/queries.ts
Normal file
22
src/history/queries.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export const runQuery = async (dbUri: string, sql: string): Promise<Record<string, unknown>[]> => {
|
||||
const proc = Bun.spawn(["sqlite3", "-json", dbUri, sql], {
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
const exitCode = await proc.exited;
|
||||
const stdout = await new Response(proc.stdout).text();
|
||||
const stderr = await new Response(proc.stderr).text();
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(`sqlite3 exited with code ${exitCode}: ${stderr}`);
|
||||
}
|
||||
|
||||
if (!stdout.trim()) return [];
|
||||
|
||||
try {
|
||||
return JSON.parse(stdout) as Record<string, unknown>[];
|
||||
} catch {
|
||||
throw new Error(`Failed to parse sqlite3 output: ${stdout.slice(0, 200)}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user