Saved from branch feature/email-dispatcher-restructure (commit b88022ea1, 2026-07-06) before deleting it. The plan was committed but never carried out: no PR was opened, and as of 2026-09-23 lib/dispatchers/email-dispatcher.zsh on dev is still a single file, now 3,406 lines (the plan below says 3,214). There's no lib/dispatchers/email/ or em/ folder and no characterization test. The em PRs since then (#493, #497, #509) were bug fixes, not this split.
Spec it cites: docs/specs/SPEC-flow-cli-restructure-2026-07-06.md (on dev). The plan names the module folder as email/ in exit criterion 2 but em/ in section B; pick one before starting. The branch had no PR, so once it is deleted this issue is the only copy of the plan: the full file follows, unchanged.
ORCHESTRATE: Email Dispatcher Restructure
Spec: docs/specs/SPEC-flow-cli-restructure-2026-07-06.md
Branch: feature/email-dispatcher-restructure
Base: dev
Goal: Apply the same modular split pattern used for teach to email-dispatcher.zsh.
Exit Criteria
lib/dispatchers/email-dispatcher.zsh < 1,500 lines (from 3,214).
lib/dispatchers/email/ exists with 3-6 module files.
tests/test-em-dispatcher-characterization.zsh exists and passes (routing checks for all public em subcommands).
./tests/run-all.sh reports 0 failures.
mkdocs build --strict clean.
- Man-page version-sync guard 12/12.
Work Breakdown
A. Characterization tests for email-dispatcher.zsh
- Add
tests/test-em-dispatcher-characterization.zsh.
- Source
flow.plugin.zsh with FLOW_QUIET=1 FLOW_ATLAS_ENABLED=no.
- Mock action functions (
_em_hml_*, _em_create_calendar_event, _em_create_reminder, _em_ai_*, etc.) and verify routing for:
- send/reply/forward/draft
- star/thread/snooze/digest
- delete/move/restore/flag/todo/event/create-folder
- pick
- ai/catch/prompt
- backend
- help / no-args
- unknown command
B. Split email-dispatcher.zsh
Target modules in lib/dispatchers/em/:
| Module |
Responsibility |
Functions |
em-main.zsh |
Entry point, help, backend toggling |
em(), _em_help(), _em_backend() |
em-send.zsh |
Compose/send/reply/forward/draft |
send/reply/forward/draft helpers |
em-organize.zsh |
Star/thread/snooze/digest |
organize helpers |
em-manage.zsh |
Delete/move/restore/flag/todo/event/folder |
manage helpers |
em-pick.zsh |
em pick multi-select UI |
pick helpers |
em-ai.zsh |
AI-backed commands (ai, catch, prompt) |
ai helpers |
lib/dispatchers/email-dispatcher.zsh becomes a thin loader that sources lib/dispatchers/em/*.zsh in order.
- Preserve comments by splitting on function boundaries (do not use
functions[$fn] extraction).
C. Update dependent tests
- If any test greps
email-dispatcher.zsh directly, update it to search the loader + modules (use the same TEACH_DISPATCHER_FILES pattern).
- Run
./tests/run-all.sh and fix regressions.
Verification Plan
After every atomic commit:
./tests/run-all.sh
zsh tests/test-manpage-version-sync.zsh
mkdocs build --strict 2>&1 | head
Final PR checklist:
Risks & Rollback
| Risk |
Mitigation |
| Comments lost during split |
Split by line ranges, not by functions[$fn] extraction |
| Routing behavior drift |
Characterization tests must pass before and after split |
Man-page coverage detector misses em |
Already updated in previous PR to scan subdirectories |
Rollback trigger: If characterization tests cannot be made green within the first two commits, revert the split and keep the monolithic file.
Next Actions After ORCHESTRATE Commit
- Implement A (characterization tests).
- Implement B (email dispatcher split).
- Implement C (test fixes).
- Final verification and PR to
dev.
ORCHESTRATE: Email Dispatcher Restructure
Spec:
docs/specs/SPEC-flow-cli-restructure-2026-07-06.mdBranch:
feature/email-dispatcher-restructureBase:
devGoal: Apply the same modular split pattern used for
teachtoemail-dispatcher.zsh.Exit Criteria
lib/dispatchers/email-dispatcher.zsh< 1,500 lines (from 3,214).lib/dispatchers/email/exists with 3-6 module files.tests/test-em-dispatcher-characterization.zshexists and passes (routing checks for all publicemsubcommands)../tests/run-all.shreports 0 failures.mkdocs build --strictclean.Work Breakdown
A. Characterization tests for
email-dispatcher.zshtests/test-em-dispatcher-characterization.zsh.flow.plugin.zshwithFLOW_QUIET=1 FLOW_ATLAS_ENABLED=no._em_hml_*,_em_create_calendar_event,_em_create_reminder,_em_ai_*, etc.) and verify routing for:B. Split
email-dispatcher.zshTarget modules in
lib/dispatchers/em/:em-main.zshem(),_em_help(),_em_backend()em-send.zshem-organize.zshem-manage.zshem-pick.zshem pickmulti-select UIem-ai.zshlib/dispatchers/email-dispatcher.zshbecomes a thin loader that sourceslib/dispatchers/em/*.zshin order.functions[$fn]extraction).C. Update dependent tests
email-dispatcher.zshdirectly, update it to search the loader + modules (use the sameTEACH_DISPATCHER_FILESpattern)../tests/run-all.shand fix regressions.Verification Plan
After every atomic commit:
Final PR checklist:
mkdocs build --strictclean.STATUSupdated with email split completionRisks & Rollback
functions[$fn]extractionemRollback trigger: If characterization tests cannot be made green within the first two commits, revert the split and keep the monolithic file.
Next Actions After ORCHESTRATE Commit
dev.