fix(hooks): reset reminder counters after a successful Codex Serena call

Codex's documented hook wiring only routes `serena-hooks remind` through
PreToolUse on the `Bash` matcher, so `ToolUseCounter.update()`'s
reset-on-Serena-tool-use branch is never reached there: it only fires when
`remind` itself is invoked for a `mcp__serena__*` tool name, which the
Bash-only matcher excludes. Reminder counters therefore never clear after a
successful Serena call, and an unrelated grep/read burst afterwards can trip
the deny threshold on state that should have been reset.

Add a `serena-hooks reset` command, wired to PostToolUse on Serena's own
tools, that resets the counters after a successful call. Gated on the call
having succeeded (`tool_response` carrying no `isError: true`, the MCP
`tools/call` result shape) so a failed Serena call does not mask a real
grep/read streak, per the issue's own acceptance criteria. The symbolic-tool
classification is shared with the existing PreToolUse hook via a small
extracted helper so both agree on what counts as a Serena tool.

Fixes #1852
This commit is contained in:
Amir Fathi authored and Dr. Dominik Jain committed 2026-09-02 13:21:42 +02:00
1 parent 9f4a2b4830
commit 47c0a4bb66
4 files changed
+296 -20

No files matched your search

+18 -2
View File
@@ -344,6 +344,17 @@ Then create `~/.codex/hooks.json` with the following content:
]
}
],
"PostToolUse": [
{
"matcher": "^mcp__serena__.*$",
"hooks": [
{
"type": "command",
"command": "serena-hooks reset --client=codex"
}
]
}
],
"SessionStart": [
{
"matcher": "startup|resume",
@@ -381,10 +392,15 @@ The hooks will:
when a Codex session starts or resumes.
- **`remind`**: Nudge the agent to use Serena's symbolic tools when it makes too many consecutive
code-search or code-file-read calls without using Serena tools in between.
- **`reset`**: Clear the reminder counters after a successful Serena symbolic tool call, so using
Serena's tools starts a fresh count instead of leaving the prior grep/read streak in place.
- **`cleanup`**: Clean up hook session data when the session ends.
The `PreToolUse` matcher is intentionally restricted to `Bash`. The Serena reminder hook for Codex
tracks shell-based grep and code-file reads, so running it for every tool call is unnecessary.
The `PreToolUse` matcher is intentionally restricted to `Bash`: the reminder hook tracks shell-based
grep and code-file reads, so running it for every tool call is unnecessary. That matcher never sees
`mcp__serena__*` tool names, though, so it cannot also perform the counter reset on Serena tool use
the way it does for clients whose `PreToolUse` hook observes every tool call. The separate `reset`
hook above, matched to `PostToolUse` on Serena's own tools, covers that case for Codex instead.
## Grok