---
name: "Split whatsapp.rs into focused modules"
retry_count: 2
blocked: true
---

# Refactor 409: Split whatsapp.rs into focused modules

## Current State

- TBD

## Desired State

whatsapp.rs is 2000+ lines making it expensive for agents to navigate and edit. Split into focused modules under chat/transport/whatsapp/.

## Acceptance Criteria

- [x] mod.rs contains webhook handlers, WebhookContext, and re-exports
- [x] meta.rs contains WhatsAppTransport, ChatTransport impl, and Graph API structs/calls
- [x] twilio.rs contains TwilioWhatsAppTransport, ChatTransport impl, and Twilio structs/calls
- [x] history.rs contains WhatsAppConversationHistory, load/save_whatsapp_history, and MessagingWindowTracker
- [x] commands.rs contains handle_incoming_message, handle_llm_message, and all async command dispatch
- [x] format.rs contains markdown_to_whatsapp and chunk_for_whatsapp
- [x] All existing tests pass
- [x] No behaviour changes — pure structural refactor

## Out of Scope

- TBD

## Test Results

<!-- huskies-test-results: {"unit":[{"name":"whatsapp::format::tests::chunk_short_message_returns_single_chunk","status":"pass","details":null},{"name":"whatsapp::format::tests::chunk_exactly_at_limit_returns_single_chunk","status":"pass","details":null},{"name":"whatsapp::format::tests::chunk_splits_on_paragraph_boundary","status":"pass","details":null},{"name":"whatsapp::format::tests::chunk_splits_on_line_boundary_when_no_paragraph_break","status":"pass","details":null},{"name":"whatsapp::format::tests::chunk_hard_splits_continuous_text","status":"pass","details":null},{"name":"whatsapp::format::tests::chunk_empty_string_returns_single_empty","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_converts_headers_to_bold","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_converts_bold","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_converts_bold_italic","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_converts_strikethrough","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_converts_links","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_removes_horizontal_rules","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_preserves_inline_code","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_preserves_code_blocks","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_mixed_message","status":"pass","details":null},{"name":"whatsapp::format::tests::md_to_wa_passthrough_plain_text","status":"pass","details":null},{"name":"whatsapp::history::tests::messaging_window_tracker_basics","status":"pass","details":null},{"name":"whatsapp::history::tests::messaging_window_tracker_expiry","status":"pass","details":null},{"name":"whatsapp::history::tests::messaging_window_tracker_reset","status":"pass","details":null},{"name":"whatsapp::history::tests::load_empty_history","status":"pass","details":null},{"name":"whatsapp::history::tests::save_and_load_history","status":"pass","details":null},{"name":"whatsapp::twilio::tests::parse_twilio_form_valid","status":"pass","details":null},{"name":"whatsapp::twilio::tests::parse_twilio_form_missing_body","status":"pass","details":null},{"name":"whatsapp::twilio::tests::parse_twilio_form_missing_from","status":"pass","details":null},{"name":"whatsapp::commands::tests::parse_command_help","status":"pass","details":null},{"name":"whatsapp::commands::tests::parse_command_status","status":"pass","details":null},{"name":"whatsapp::commands::tests::parse_command_unknown","status":"pass","details":null},{"name":"whatsapp::mod::tests::webhook_context_basics","status":"pass","details":null}],"integration":[]} -->

### Unit Tests (28 passed, 0 failed)

- ✅ whatsapp::format::tests::chunk_short_message_returns_single_chunk
- ✅ whatsapp::format::tests::chunk_exactly_at_limit_returns_single_chunk
- ✅ whatsapp::format::tests::chunk_splits_on_paragraph_boundary
- ✅ whatsapp::format::tests::chunk_splits_on_line_boundary_when_no_paragraph_break
- ✅ whatsapp::format::tests::chunk_hard_splits_continuous_text
- ✅ whatsapp::format::tests::chunk_empty_string_returns_single_empty
- ✅ whatsapp::format::tests::md_to_wa_converts_headers_to_bold
- ✅ whatsapp::format::tests::md_to_wa_converts_bold
- ✅ whatsapp::format::tests::md_to_wa_converts_bold_italic
- ✅ whatsapp::format::tests::md_to_wa_converts_strikethrough
- ✅ whatsapp::format::tests::md_to_wa_converts_links
- ✅ whatsapp::format::tests::md_to_wa_removes_horizontal_rules
- ✅ whatsapp::format::tests::md_to_wa_preserves_inline_code
- ✅ whatsapp::format::tests::md_to_wa_preserves_code_blocks
- ✅ whatsapp::format::tests::md_to_wa_mixed_message
- ✅ whatsapp::format::tests::md_to_wa_passthrough_plain_text
- ✅ whatsapp::history::tests::messaging_window_tracker_basics
- ✅ whatsapp::history::tests::messaging_window_tracker_expiry
- ✅ whatsapp::history::tests::messaging_window_tracker_reset
- ✅ whatsapp::history::tests::load_empty_history
- ✅ whatsapp::history::tests::save_and_load_history
- ✅ whatsapp::twilio::tests::parse_twilio_form_valid
- ✅ whatsapp::twilio::tests::parse_twilio_form_missing_body
- ✅ whatsapp::twilio::tests::parse_twilio_form_missing_from
- ✅ whatsapp::commands::tests::parse_command_help
- ✅ whatsapp::commands::tests::parse_command_status
- ✅ whatsapp::commands::tests::parse_command_unknown
- ✅ whatsapp::mod::tests::webhook_context_basics

### Integration Tests (0 passed, 0 failed)

*No integration tests recorded.*
