refactor(main): finish TASK-94 composition-root extraction

Move IPC, shortcuts, startup lifecycle, and app-ready assembly behind dedicated runtime composers so main.ts stays focused on boot wiring while preserving behavior and test coverage.
This commit is contained in:
2026-02-20 20:14:39 -08:00
parent 8ad8ff1671
commit 23b88bf20e
13 changed files with 1421 additions and 890 deletions

View File

@@ -1,10 +1,10 @@
---
id: TASK-94
title: Reduce main.ts to thin composition root
status: In Progress
status: Done
assignee: []
created_date: '2026-02-20 12:06'
updated_date: '2026-02-21 03:40'
updated_date: '2026-02-21 04:12'
labels:
- architecture
- refactor
@@ -44,12 +44,38 @@ priority: high
## Acceptance Criteria
<!-- AC:BEGIN -->
- [ ] #1 `src/main.ts` is composition-focused (boot/runtime wiring only; no broad deps-builder clusters).
- [x] #1 `src/main.ts` is composition-focused (boot/runtime wiring only; no broad deps-builder clusters).
- [x] #2 Runtime import paths in `src/main.ts` stay domain-registry oriented (no relapse to per-leaf runtime imports).
- [x] #3 `check:main-fanin` passes under updated threshold.
- [x] #4 `bun run test:core:dist` passes with no CLI/IPC behavior regressions.
<!-- AC:END -->
## Implementation Plan
<!-- SECTION:PLAN:BEGIN -->
1) Extract IPC composition from src/main.ts into src/main/runtime/composers/ipc-runtime-composer.ts with focused tests (handler deps build, runtime handler creation, registration wiring).
2) Rewire src/main.ts IPC command and IPC registration blocks to consume the IPC composer while preserving existing helper wrappers and behavior.
3) Extract shortcuts composition from src/main.ts into src/main/runtime/composers/shortcuts-runtime-composer.ts with focused tests (global shortcuts runtime, numeric sessions, overlay shortcuts lifecycle).
4) Rewire src/main.ts shortcut runtime block to consume shortcuts composer while preserving downstream callsites.
5) Run targeted composer tests + check:main-fanin + test:core:dist; update TASK-94 notes with before/after metrics and finalize AC/status if all green.
<!-- SECTION:PLAN:END -->
## Implementation Notes
<!-- SECTION:NOTES:BEGIN -->
2026-02-21: finished extraction pass by moving IPC command/registration, shortcuts runtime wiring, startup lifecycle wiring, and app-ready startup composition from `src/main.ts` into dedicated composer modules under `src/main/runtime/composers/*`.
Metrics: `src/main.ts` reduced from 3043 LOC to 2955 LOC in this pass; `check:main-fanin` import lines improved from 99 to 90 while remaining under enforced threshold.
<!-- SECTION:NOTES:END -->
## Final Summary
<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Completed TASK-94 composition-root finish pass by extracting remaining large assembly clusters from `src/main.ts` into dedicated composer modules: IPC runtime (`ipc-runtime-composer`), shortcuts runtime (`shortcuts-runtime-composer`), startup lifecycle (`startup-lifecycle-composer`), and app-ready bootstrap (`app-ready-composer`). Main process behavior was preserved while reducing direct deps-builder orchestration in `main.ts` and keeping runtime wiring through domain/composer boundaries.
Added focused composer tests for each new module and reran project gates. Verification run: `bun run build`, `bun test src/main/runtime/composers/ipc-runtime-composer.test.ts`, `bun test src/main/runtime/composers/shortcuts-runtime-composer.test.ts`, `bun test src/main/runtime/composers/startup-lifecycle-composer.test.ts`, `bun test src/main/runtime/composers/app-ready-composer.test.ts`, `bun run check:main-fanin`, and `bun run test:core:dist` (all passing).
<!-- SECTION:FINAL_SUMMARY:END -->
## Definition of Done
<!-- DOD:BEGIN -->
- [x] #1 `src/main.ts` LOC and fan-in metrics improve from pre-task baseline and are recorded in task notes.