refactor: Claude Code recall is a thin shim over hooklib#12
Open
rainxchzed wants to merge 1 commit into
Open
Conversation
…e fork) The visibility review's HIGH architectural finding: the Claude Code adapter reimplemented the whole recall core inline instead of using the shared hooklib that Codex consumes cleanly — and the compaction feature (PR #9) got bolted onto that stranded fork, so the richer of the two recall cores was the off-spec one. This collapses the fork by LIFTING the Claude-Code-only behaviors INTO hooklib (not deleting them — that would regress the 0.5.0 fixes), then making Claude Code a thin shim like Codex. Pure refactor: full suite 383 passed / 1 skip, identical to before. Lifted into hooklib (all opt-in, so Codex's existing calls are unchanged): - read_stdin_json() now has the 4MB cap (Codex gains the hardening for free) - build_recall_block(..., fresh=True) — fresh=False skips the project reindex + 500-row pool re-mirror (the compaction perf path) - classify_event(payload, default_event) — event/source, default_event wins - emit(obj, *, note, event) — event-aware (suppress JSON on PostCompact) + pipe-safe (swallow BrokenPipe); defaults preserve every existing caller - emit_recall(block, event, is_compaction) — format-per-event (additionalContext vs plain stdout) with the compaction framing - compaction_already_served / record_compaction_served — the dedup guard + state.json breadcrumb, host-agnostic (uses paths_mod.read_state/update_state) claude_code/hook_recall.py: 360 → 175 lines. main() now orchestrates via hooklib; the duplicated _merged_store / _mirror_pool_into_index / _read_stdin_json / _emit / _emit_block / _classify_event / dedup bodies are gone. The background pool-sync cadence (_maybe_sync_pool/_sync_due/run_sync) stays local — it's Claude-Code config, not the duplicated recall core. The "never break the session" guards (recall-failure _note, emit broken-pipe) are preserved exactly. hook_compact still passes default_event="PostCompact". Also: codex/paths.py gains read_state() (parity, so the lifted dedup works for any host); hook_capture.py references hooklib._MAX_STDIN_BYTES. Tests: re-pointed the moved-symbol references in test_compaction_fixes.py at their new home (hooklib.classify_event/emit/read_stdin_json/_MAX_STDIN_BYTES, and the fresh= behavior via build_recall_block) — the behavioral assertions are unchanged. All existing compaction/visibility/distill/Codex suites pass against the refactor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Collapses the architect's HIGH finding from the visibility review: the Claude Code adapter reimplemented the whole recall core inline instead of using the shared
hooklibthat Codex consumes as a 5-line shim — and the compaction feature got bolted onto that fork, so the richer recall core was the off-spec one.This lifts the Claude-Code-only behaviors into
hooklib(rather than deleting them, which would regress the 0.5.0 fixes), then makes Claude Code a thin shim like Codex.Pure refactor — behavior-neutral. Full suite 383 passed / 1 skip, identical to before.
Lifted into hooklib (all opt-in; Codex's existing calls unchanged)
read_stdin_json()gains the 4MB cap → Codex gets the hardening for freebuild_recall_block(..., fresh=True)—fresh=Falseskips the project reindex + 500-row pool re-mirror (the compaction perf path)classify_event(payload, default_event)—default_eventwins over a missinghook_event_nameemit(obj, *, note, event)— event-aware (suppress JSON on PostCompact's verbatim-stdout channel) + pipe-safe (swallow BrokenPipe); defaults preserve every calleremit_recall(block, event, is_compaction)— format-per-event (additionalContext vs plain stdout) with the compaction framingcompaction_already_served/record_compaction_served— the dedup guard +state.jsonbreadcrumb, host-agnosticResult
claude_code/hook_recall.py: 360 → 175 lines.main()orchestrates via hooklib; the duplicated_merged_store/_mirror_pool_into_index/_read_stdin_json/_emit/_emit_block/_classify_event/ dedup bodies are gone. The "never break the session" guards (recall-failure_note, emit broken-pipe) are preserved exactly.hook_compactstill passesdefault_event="PostCompact".Also:
codex/paths.pygainsread_state()(parity, so the lifted dedup works for any host);hook_capture.pyreferenceshooklib._MAX_STDIN_BYTES.Tests
Re-pointed the moved-symbol references in
test_compaction_fixes.pyat their new home (hooklib.classify_event/emit/read_stdin_json/_MAX_STDIN_BYTES, and thefresh=behavior viabuild_recall_block) — the behavioral assertions are unchanged. Every existing compaction/visibility/distill/Codex suite passes against the refactor; that's the regression guarantee for a pure refactor.This is the first of the deferred 0.5.0-architecture items; directory-split storage + the smaller ones land as separate PRs before 0.5.0 ships.
🤖 Generated with Claude Code