Skip to content

refactor(bridge): split BridgeManager into focused modules#32

Merged
y49 merged 5 commits into
mainfrom
refactor/architecture-split
Apr 6, 2026
Merged

refactor(bridge): split BridgeManager into focused modules#32
y49 merged 5 commits into
mainfrom
refactor/architecture-split

Conversation

@y49

@y49 y49 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Summary

Split the monolithic BridgeManager (1138 lines) into 4 focused modules + thin orchestrator:

Module Responsibility Lines
CallbackRouter All IM button callback handling 204
SDKEngine SDK conversation flow (Claude + Codex) 463
HookEngine Hook notification formatting & delivery 89
MessageRouter Auth, attachment buffering, permission text, hook reply routing 301
BridgeManager Lifecycle + orchestration (down from 1138) 230
  • Pure refactoring — no behavior changes, no API changes
  • Constructor DI with callback functions, matching existing CommandRouter pattern
  • Provider-agnostic: works with both Claude SDK and Codex via LLMProvider interface
  • HookNotificationData re-exported for backward compatibility

Tests

  • All 443 existing tests pass unchanged (through BridgeManager delegation)
  • Added 63 new unit tests for extracted modules:
    • callback-router.test.ts (24 tests) — all callback types
    • message-router.test.ts (22 tests) — auth, buffering, permissions, hook routing
    • hook-engine.test.ts (17 tests) — notification formatting, context, URLs
  • TODO: sdk-engine.test.ts — SDK flow unit tests (complex mock setup, will follow up)

Test plan

  • npm test — 506/506 passed
  • tsc --noEmit — clean
  • npm run build — success
  • Manual testing via tlive with linked local build

y49 added 5 commits April 6, 2026 15:41
Move all button callback handling (~180 lines) into a dedicated
CallbackRouter class. Uses constructor DI with callback functions,
matching existing CommandRouter pattern.
Move SDK conversation flow (~400 lines) into a dedicated SDKEngine class.
Owns ConversationEngine, activeControls, SDK question state maps.
Provider-agnostic — works with both Claude SDK and Codex via LLMProvider.
Move hook notification formatting and delivery (~80 lines) into a
dedicated HookEngine class. Re-exports HookNotificationData for
backward compatibility with existing consumers.
Move auth check, attachment buffering, permission text resolution,
AskQuestion text replies, and hook reply routing (~250 lines) into
a dedicated MessageRouter class. BridgeManager.handleInboundMessage
is now a thin orchestrator delegating to MessageRouter, CallbackRouter,
CommandRouter, and SDKEngine.
- callback-router.test.ts: 24 tests covering all 13+ callback types
- message-router.test.ts: 22 tests for auth, buffering, permissions, hook routing
- hook-engine.test.ts: 17 tests for notification formatting, context, URLs

Total: 506 tests (up from 443)
@y49 y49 merged commit f637332 into main Apr 6, 2026
3 checks passed
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.

1 participant