fix(hooks): skip tool_result messages when counting human exchanges#779
Open
arnoldwender wants to merge 2 commits intoMemPalace:developfrom
Open
fix(hooks): skip tool_result messages when counting human exchanges#779arnoldwender wants to merge 2 commits intoMemPalace:developfrom
arnoldwender wants to merge 2 commits intoMemPalace:developfrom
Conversation
7aa0be3 to
f26f695
Compare
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
Fixes #549 — exchange count was inflated by counting
tool_resultmessages as human turns.In Claude Code JSONL, every tool response (Bash, Read, Grep, subagent results) is emitted with
role: "user"andcontentas a list of{"type": "tool_result", ...}blocks. Both counting paths treated these as real human messages, so a session with 10 real turns but 50 tool calls was reported as 60 exchanges — causing premature save-hook triggers at the wrong frequency.Changes
mempalace/hooks_cli.py_count_human_messages(): In theelif isinstance(content, list):branch, added an earlycontinuethat fires when all blocks in the list have"type": "tool_result". The guard is placed before the existing<command-message>check, leaving that logic untouched.hooks/mempal_save_hook.sh: Added the identicaltool_resultguard to the inline Python script (also before the<command-message>check).Both changes are purely additive — no existing counting logic was modified, only a new
continuepath inserted fortool_result-only content lists.Test plan
tests/test_hooks_cli.pytests pass (verified locally)test_count_skips_tool_result_messagesshould be added to directly exercise the new guard — noted for follow-uptool_resultentries; confirm count returns 10, not 60