Skip to content

Commit b2e1775

Browse files
IM.codesclaude
andcommitted
feat: pg_trgm memory recall endpoint + timeline-store performance fix
Server: - Add migration 040: enable pg_trgm extension + GIN trigram index on shared_context_projections.summary for fuzzy similarity search - Add POST /:id/shared-context/memory/recall endpoint — searches personal + enterprise memory using pg_trgm similarity(), merges and ranks results - Import resolveServerRole for recall endpoint auth Daemon: - Rewrite timeline-store read() to use reverse file reading (readTailLines) instead of readFileSync + split on entire file. 16MB/43K-line JSONL files no longer block the event loop on every history request. - Add getLatest() using readTailLines (reads last 5 lines, not entire file) - Add truncateAll() to cap all session JSONL files at 5000 events - Call truncateAll() on daemon startup to prevent unbounded growth - Remove premature local memory injection from process agent send path (transport agents already have complete unified injection via dispatchSharedContextSend; process agents need proper architecture) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2f93a74 commit b2e1775

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

src/daemon/command-handler.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,9 +1685,6 @@ async function handleSend(cmd: Record<string, unknown>, serverLink: ServerLink):
16851685
sendText = await rewritePathsForSandbox(sessionName, finalText);
16861686
}
16871687

1688-
// Auto-inject relevant memories from local processed context
1689-
sendText = await injectLocalMemoryIfAvailable(sendText, sessionName);
1690-
16911688
await sendShellAwareCommand(sessionName, sendText, agentType);
16921689
const payload: Record<string, unknown> = { text };
16931690
if (attachments.length > 0) payload.attachments = attachments;
@@ -3946,33 +3943,3 @@ async function handleMemorySearch(cmd: Record<string, unknown>, serverLink: Serv
39463943
});
39473944
}
39483945

3949-
// ── Memory auto-inject for process agent sends ───────────────────────────
3950-
3951-
const MEMORY_INJECT_MIN_QUERY_LENGTH = 10;
3952-
const MEMORY_INJECT_MAX_RESULTS = 5;
3953-
const MEMORY_INJECT_HEADER = '[Related past work from memory]';
3954-
3955-
async function injectLocalMemoryIfAvailable(prompt: string, sessionName: string): Promise<string> {
3956-
// Skip very short messages (greetings, confirmations, etc.)
3957-
if (prompt.length < MEMORY_INJECT_MIN_QUERY_LENGTH) return prompt;
3958-
3959-
try {
3960-
const record = getSession(sessionName);
3961-
const projectId = record?.projectName ?? undefined;
3962-
const { searchLocalMemory } = await import('../context/memory-search.js');
3963-
const result = searchLocalMemory({
3964-
query: prompt.slice(0, 200), // use first 200 chars as search query
3965-
repo: projectId,
3966-
limit: MEMORY_INJECT_MAX_RESULTS,
3967-
});
3968-
if (result.items.length === 0) return prompt;
3969-
3970-
const memories = result.items
3971-
.map((item) => `- [${item.projectId}] ${item.summary.split('\n')[0].slice(0, 200)}`)
3972-
.join('\n');
3973-
return `${MEMORY_INJECT_HEADER}\n${memories}\n\n${prompt}`;
3974-
} catch {
3975-
// Non-fatal — send the original prompt if memory search fails
3976-
return prompt;
3977-
}
3978-
}

0 commit comments

Comments
 (0)