-
Notifications
You must be signed in to change notification settings - Fork 0
Fix summarizer hot path: capture on SessionEnd, drain in background #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eff682a
feat: add isEmptySummary predicate for husk detection
jamby77 f1f22a8
fix: never store an empty summary as a memory
jamby77 f5845c8
fix: remove summarization from the capture hook
jamby77 eaf00f9
feat: drain the ingest queue in a detached process
jamby77 6cf6aea
fix: capture on SessionEnd instead of every turn
jamby77 f08a0b1
fix: correct stale Stop label in install summary
jamby77 47ea421
test: recall by the embedded text, not the one-liner
jamby77 3479443
chore: ignore .idea/ editor directory
jamby77 c3c469b
fix: resolve the drain path via USERPROFILE when HOME is unset
jamby77 2e3e752
fix: fall back to the drain source when no binary is installed
jamby77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ dist/ | |
| .mcp.json | ||
| *.log | ||
| bun.lockb | ||
| .idea/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Events this plugin used to register on and no longer does. mergeHooks only | ||
| // touches events present in the current hook map, so without an explicit strip | ||
| // a stale registration would survive upgrades forever in a user's | ||
| // ~/.claude/settings.json. | ||
| const LEGACY_EVENTS = ["Stop"]; | ||
|
|
||
| /** | ||
| * `markers` identify an entry as ours. The default catches installed binaries | ||
| * under ~/.betterdb; dev registrations point at a plugin checkout whose path | ||
| * may not contain "betterdb", so callers pass that path as an extra marker. | ||
| */ | ||
| export function stripLegacyBetterdbHooks( | ||
| hooks: Record<string, unknown[]>, | ||
| markers: string[] = ["betterdb"], | ||
| ): Record<string, unknown[]> { | ||
| const out: Record<string, unknown[]> = { ...hooks }; | ||
|
|
||
| for (const event of LEGACY_EVENTS) { | ||
| const entries = out[event]; | ||
| if (!Array.isArray(entries)) { | ||
| continue; | ||
| } | ||
| // Only ours — a third party's hook on the same event must survive. | ||
| const kept = entries.filter((entry) => { | ||
| const json = JSON.stringify(entry); | ||
| return !markers.some((m) => { | ||
| return m.length > 0 && json.includes(m); | ||
| }); | ||
| }); | ||
| if (kept.length > 0) { | ||
| out[event] = kept; | ||
| } else { | ||
| delete out[event]; | ||
| } | ||
| } | ||
|
|
||
| return out; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { getValkeyClient } from "../client/valkey.js"; | ||
| import { getPluginMemoryStore } from "../client/memory-store.js"; | ||
| import { createModelClient } from "../client/model.js"; | ||
| import { AgingPipeline } from "../memory/aging.js"; | ||
| import { isConfigured } from "../config.js"; | ||
|
|
||
| // Detached drainer: summarizes and stores whatever the SessionEnd hook queued. | ||
| // Runs as its own process precisely so the LLM call is not on a hook's clock — | ||
| // nothing waits for this. | ||
| async function main(): Promise<void> { | ||
| if (!isConfigured()) { | ||
| return; | ||
| } | ||
|
|
||
| const valkeyClient = await getValkeyClient(); | ||
| const modelClient = await createModelClient(); | ||
| const store = await getPluginMemoryStore((t) => modelClient.embed(t)); | ||
| const pipeline = new AgingPipeline(valkeyClient, store, modelClient); | ||
|
|
||
| const { processed, skipped } = await pipeline.processIngestQueue(); | ||
| console.error(`[betterdb] drain: processed=${processed} skipped=${skipped}`); | ||
|
|
||
| await store.close(); | ||
| await valkeyClient.quit(); | ||
| } | ||
|
|
||
| main() | ||
| .catch((err: unknown) => { | ||
| console.error( | ||
| "[betterdb] drain failed:", | ||
| err instanceof Error ? err.message : String(err), | ||
| ); | ||
| }) | ||
| .finally(() => { | ||
| process.exit(0); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.