Skip to content

fix(mcp): write tools stop echoing the record, search clips its matches - #36

Merged
riponcm merged 2 commits into
riponcm:mainfrom
bigfree:fix/terse-tool-replies
Nov 20, 2026
Merged

riponcm merged 2 commits into
riponcm:mainfrom
bigfree:fix/terse-tool-replies

Conversation

@bigfree

@bigfree bigfree commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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_events prints every match whole.

add_note       -> Recorded note → my-project: <the whole note the agent just wrote>
search_events  -> 20 KB for one query with 30 matches

Replaying the real calls from those transcripts, before and after this change:

Calls Before After
write tools (add_note, add_decision, log_issue, record_attempt, record_fix) 1,970 1.25 MB 0.10 MB (−92%)
search_events 330 1.61 MB 0.83 MB (−49%)

Together 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. A supersedes prefix is shown resolved to the full id.

Recorded note evt_1b4c9e0f2a7d83c51e6b → my-project
Recorded decision evt_77a0c2d9e81f4b36a5c0 → my-project (supersedes evt_3f0e2b9c4d1a8e7f6b5c)
Logged issue #0042 → my-project

The project name stays, as the global-mode instructions rely on it.

Search

search_events now goes through projectmem.search, the same matcher as pjm search (so it also matches location and files), and every match line shows:

  • type, issue number, event id and date (the docstring already promised the date);
  • the text clipped to RECORD_CHARS with the same clip_record as summary.md, but around the match when the match sits past the clip, and from notes when only the notes matched;
  • (superseded) on retired decisions, as pjm search already does, since this is now where an agent finds an id to supersede.
Found 2 match(es) for 'argon2':
  [decision] evt_53600b1c9e2f4a7d8b6e 2026-10-01: hash passwords with bcrypt @ src/auth.py (superseded)
  [note] evt_1b4c9e0f2a7d83c51e6b 2026-10-03: ...the argon2 migration broke logins on the old clients

full=True returns whole texts, still one match per line.

Also in this PR

  • An event line stored without an id (hand-edited or foreign events.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 (formerly summary._clip) moves next to RECORD_CHARS in storage.py.
  • Docstrings, the CLAUDE.md bridge and the README examples describe the new replies. The bridge said ids come from get_summary(), which prints none; it now points to the add_decision reply and search_events. The AI_INSTRUCTIONS.md template has the same sentence, but I left it alone because changing the template requires an INSTRUCTIONS_VERSION bump. It could ride along with the next one.

Tests

tests/test_tool_replies.py covers each write reply, a supersedes prefix, the superseded tag, a match past the clip, a match only in notes, and full=True with multi-line text. tests/test_models.py covers stable ids for id-less lines. test_mcp_record_fix_accepts_target_issue_id asserted the echo, so it now checks the exact reply shape. The full suite passes (391), and ruff reports no new findings.

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.
@riponcm
riponcm merged commit 0a82906 into riponcm:main Nov 20, 2026
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