Repository navigation
fix(mcp): write tools stop echoing the record, search clips its matches - #36
Merged
Merged
Conversation
Every write tool replied with the full text the agent had just sent, and search_events printed each match whole. Replayed over two months of real sessions on one project, write replies were 1.25 MB and search replies 1.61 MB, about 35% of everything projectmem returned. Write tools now reply with what the agent does not already know: the issue id, or for notes and decisions the event id, which add_decision's supersedes needs. Search lists each match with its event id and date, clipped to RECORD_CHARS like summary.md; full=True returns whole texts once the query is narrow.
…matched Review of the terse replies found that MCP search_events kept its own matcher, showed no (superseded) tag although pjm search does, could clip away the text that matched, and printed raw newlines with full=True. search_events now goes through projectmem.search with a project root and a shared match_line: issue number, event id, date, the text clipped around the match (or the notes when only they matched), a normalized location and the (superseded) tag. add_decision replies with the resolved id of the event it retires, not the prefix it was given. clip_record moves next to RECORD_CHARS in storage. An event line stored without an id now gets an id derived from its content, so the id search shows stays the same on the next read. Docstrings, the CLAUDE.md bridge and the README examples describe the new replies. The AI_INSTRUCTIONS.md template keeps its wording, since changing it requires an INSTRUCTIONS_VERSION bump.
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.
I went through two months of Claude Code transcripts on one project (797 transcripts, 4,607 projectmem calls) and measured what each tool returned. Two things stood out: every write tool sends the agent's own text straight back, and
search_eventsprints every match whole.Replaying the real calls from those transcripts, before and after this change:
add_note,add_decision,log_issue,record_attempt,record_fix)search_eventsTogether that is 1.9 MB less, about 23% of everything projectmem returned in that period (8.2 MB).
Write replies
Write tools reply with what the agent does not already know: the issue id, or for notes and decisions the event id. The id is what
add_decision(supersedes=...)needs later, and until now it had to be found with a search. Asupersedesprefix is shown resolved to the full id.The project name stays, as the global-mode instructions rely on it.
Search
search_eventsnow goes throughprojectmem.search, the same matcher aspjm search(so it also matcheslocationandfiles), and every match line shows:RECORD_CHARSwith the sameclip_recordassummary.md, but around the match when the match sits past the clip, and fromnoteswhen only the notes matched;(superseded)on retired decisions, aspjm searchalready does, since this is now where an agent finds an id to supersede.full=Truereturns whole texts, still one match per line.Also in this PR
id(hand-edited or foreignevents.jsonl) used to get a new random id on every read. It now gets an id derived from its content, so an id that search shows still works on the next call.clip_record(formerlysummary._clip) moves next toRECORD_CHARSinstorage.py.get_summary(), which prints none; it now points to theadd_decisionreply andsearch_events. TheAI_INSTRUCTIONS.mdtemplate has the same sentence, but I left it alone because changing the template requires anINSTRUCTIONS_VERSIONbump. It could ride along with the next one.Tests
tests/test_tool_replies.pycovers each write reply, asupersedesprefix, the superseded tag, a match past the clip, a match only in notes, andfull=Truewith multi-line text.tests/test_models.pycovers stable ids for id-less lines.test_mcp_record_fix_accepts_target_issue_idasserted the echo, so it now checks the exact reply shape. The full suite passes (391), andruffreports no new findings.