Skip to content

Add a select hook: a plugin may narrow a read, once, after the read policy - #21

Merged
Yanir-R merged 1 commit into
mainfrom
claude/project-thread-mxe275
Nov 24, 2026
Merged

Yanir-R merged 1 commit into
mainfrom
claude/project-thread-mxe275

Conversation

@Yanir-R

@Yanir-R Yanir-R commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Requested by Yanir · project thread

What changed

A third extension point, select. Once per read, after the read policy, a plugin may narrow the relevant servable memories to fewer.

  • retrieve.search(..., select=None, client=""): select(question, context, memories, client) sees the relevant memories that may be served, best first. It returns the ones to serve, or None to leave the read unchanged.
  • It can only narrow. A memory it was not offered is ignored, the core's order and the limit stay, and more counts after it.
  • Restricted and archived memories never reach it, and it is not called when nothing is relevant.
  • personakit serve passes the name the assistant connected with (MCP clientInfo.name), or "" when unknown.
  • Hooks.select defaults to None. A non-callable value is refused at load.
  • Docs: PLUGINS, ARCHITECTURE, PRIVACY (a select plugin receives memory text), CHANGELOG (Unreleased) and the review log.

Why

A relevance score can only order memories, and with a context it is called twice per read. A plugin that decides which of the candidates actually answer the question needs one call per read, with the question and the context together. It also needs to know which assistant is asking.

How to verify

pip install -e ".[mcp]" ruff coverage
ruff check .
python -m coverage run -m unittest discover -s tests -t . && python -m coverage report

New tests:

  • SelectTest in tests/test_retrieve.py: only servable memories are offered, once; None changes nothing; it cannot widen; the order stays the core's; an empty selection serves nothing.
  • tests/test_plugins.py: the hook loads, and a broken one is refused.
  • tests/test_mcp_server.py: the client name arrives through a real in-memory MCP session.

Locally with mcp 1.30: 190 tests, coverage 97%, ruff clean, hygiene passed.

Checklist

  • Every commit is signed off (git commit -s), see CONTRIBUTING.md: not signed off. DCO sign-off is the maintainer's to give.
  • No personal data, real paths, hostnames or credentials in code, tests, fixtures or docs
  • Test fixtures use invented data only
  • No duplicated logic; the change respects the module boundaries in docs/ARCHITECTURE.md
  • Docs updated if behavior or privacy claims changed

Generated by Claude Code

…olicy

retrieve.search takes an optional select(question, context, memories,
client). It runs once per read, after the read policy, on the relevant
servable memories best first. It may only narrow: memories it was not
offered are ignored, the core's order and the limit stay, None leaves
the read unchanged. Restricted and archived memories never reach it.

personakit serve passes the name the assistant connected with (MCP
clientInfo), or "" when unknown. Hooks.select defaults to None.
PLUGINS, ARCHITECTURE, PRIVACY, CHANGELOG and the review log updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014dGcvUc3LqzKojYnqVGCjK
@Yanir-R
Yanir-R merged commit 43a80c2 into main Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants