refactor(bridges): extract shared codec_bridges core (A-19, Audit-A complete)#79
Merged
Conversation
…omplete) PR-3F, Option 1 (scoped). The audit's full BridgeRouter (unifying process_message) was high-risk/low-value: the headline call_llm dup was already fixed in #71, and the two process_message flows have intentionally drifted (telegram audio/Gemini/ briefing; imessage goals/intent) — forcing them into one pipeline would risk regressing a working channel. So this extracts ONLY the genuinely-identical helpers and leaves process_message per-bridge. New codec_bridges.py: - load_dispatch() / try_skill(text) — the lazy codec_dispatch loader + skill match (+ the _SKIP_SKILLS terminal/GUI set), one copy. - call_llm(channel, text, llm_cfg, ...) — the canonical bridge LLM call: persona selected by channel, routed through codec_llm.call, None-contract preserved, chat_template_kwargs filtered. - save_to_memory(channel, conv_id, user, assistant) — the memory.db write under session_id "<channel>-<conv_id>". codec_telegram + codec_imessage now `from codec_bridges import try_skill` and keep thin channel-injecting wrappers for call_llm / save_to_memory, so every process_message call site is unchanged (telegram audio + imessage goal-tracking untouched). Removed telegram's now-dead sqlite3 import. codec_bridges.py is the documented "add a channel" seed (CLAUDE.md §1: future WhatsApp/Discord). Updated 2 stale #71 source-invariants (the bridges now delegate via codec_bridges rather than calling codec_llm.call directly). Tests: tests/test_bridges.py (10 — call_llm persona/None/kwargs-filter/history+ override, try_skill skip-set/run/no-match, save_to_memory channel-prefixed session_id, source invariants). Full suite 1502 passing, 23 known-baseline failures, zero new. Net -148 LOC in the bridges. Zero net-new ruff. **Audit-A (Wave 3, code quality) is complete** — A-1..A-22 all closed or verified. Co-Authored-By: Claude Opus 4.7 <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.
Summary
PR-3F (Option 1, scoped) — the last Audit-A item. Design →
docs/PR3F-BRIDGE-UNIFICATION-DESIGN.md.The audit's full
BridgeRouter(unifyingprocess_message) was high-risk/low-value: the headlinecall_llmdup was already fixed in #71, and the twoprocess_messageflows have intentionally drifted (telegram audio/Gemini/briefing; imessage goals/intent) — forcing them into one pipeline would risk regressing a working channel. So this extracts only the genuinely-identical helpers and leavesprocess_messageper-bridge.New
codec_bridges.pyload_dispatch()/try_skill(text)— lazycodec_dispatchloader + skill match (+ the_SKIP_SKILLSterminal/GUI set).call_llm(channel, text, llm_cfg, …)— canonical bridge LLM call: persona by channel →codec_llm.call,None-contract preserved,chat_template_kwargsfiltered.save_to_memory(channel, conv_id, …)— memory.db write undersession_id "<channel>-<conv_id>".codec_telegram+codec_imessagenowfrom codec_bridges import try_skilland keep thin channel-injecting wrappers forcall_llm/save_to_memory, so everyprocess_messagecall site is unchanged (telegram audio + imessage goal-tracking untouched). Removed telegram's deadsqlite3import.codec_bridges.pyis the documented "add a channel" seed (CLAUDE.md §1).Updated 2 stale #71 source-invariants (bridges now delegate via
codec_bridges).Test plan
tests/test_bridges.py— 10 tests:call_llmpersona / None / kwargs-filter / history+override;try_skillskip-set / run / no-match;save_to_memorychannel-prefixedsession_id; source invariants.sqlite3).🎯 Audit-A (Wave 3, code quality) is complete
A-1..A-22 all closed or verified. The big threads this run: A-11 vision dedup (
codec_vision), A-12 LLM-call dedup (codec_llm— every text call site), PR-3D monolith decomposition (A-5/6/7), and A-19 bridge unification (codec_bridges).🤖 Generated with Claude Code