Contextual memory injection hook (UserPromptSubmit + PreToolUse)#76
Merged
Conversation
… to contextual-memory spec
…s + per-task confidence)
…e) in installer + docs
There was a problem hiding this comment.
🟢 Claude BugBot Analysis
No bugs found in the changes. The contextual_inject hook, retrieve_relevant service, keyword extraction helpers, config resolver, and installation registration are all correctly implemented. Backend method signatures (retrieve, semantic_list) match the call sites, the build_backend import is valid, the oversized-stdin sentinel pattern is correct, the with closing(conn) block properly scopes the database connection, and the two-pass remove-then-add approach in merge_settings_json preserves idempotency for the new UserPromptSubmit and PreToolUse entries.
No bugs were detected in this PR.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Surfaces the relevant curated memories (semantic + reflections, project + general) at the moment they matter, by whole-word keyword-matching against the current prompt / tool-input — closing the "loaded once at SessionStart, then ignored" gap. No new deps, no embeddings, no schema migration.
What's added
services/keywords.py— keyword extraction + whole-word matching (pure, no deps).services/relevant.py—retrieve_relevant(backend, …)fetches the small, already-ranked sets through theStorageBackendabstraction (works sqlite + agentcore), keyword-filters, ranks by (#hits, managed order), caps;format_relevant()renders theadditionalContextblock.hooks/contextual_inject.py—UserPromptSubmit+PreToolUsehook; never raises, always exits 0.config.py—BETTER_MEMORY_CONTEXT_INJECT_MODE(userprompt|pretool|both(default)|off).cli/install_hooks.py— registers both events (matcherSkill|Task|Write).docs/hooks-setup.md,README.md,website/configuration.md.Design notes
UserPromptSubmit/PreToolUseadditionalContextis injected as a system reminder Claude reads. WhetherPreToolUsefires for the built-inSkill/Tasktools is environment-dependent (probe deferred) —UserPromptSubmitis the reliable backbone.Testing
pytest(100 affected tests green),ruff(zero net-new; pre-existing debt untouched),pyright(0 on new modules). End-to-end smoke: piping a "write the plan" prompt surfaces the planning-guardrails reflection (conf 0.90).Spec:
docs/superpowers/specs/2026-06-14-contextual-memory-injection-hook-design.mdPlan:
docs/superpowers/plans/2026-06-14-contextual-memory-injection-hook.md🤖 Generated with Claude Code