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.
5.4 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies, priority
| id | title | status | assignee | created_date | updated_date | labels | dependencies | priority | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TASK-94 | Reduce main.ts to thin composition root | Done | 2026-02-20 12:06 | 2026-02-21 04:12 |
|
|
high |
Description
src/main.ts still contains heavy deps-builder orchestration and high import concentration. Complete the composition-root refactor so main.ts owns boot wiring only and domain assembly moves behind registry/domain composer modules.
Action Steps
- Baseline current
main.tsfan-in (check:main-fanin,check:file-budgets,wc -l src/main.ts). - Introduce domain composer modules for repeated build-handler clusters (startup, overlay, jellyfin, anilist, ipc/shortcuts).
- Move
createBuild*MainDepsHandlercall clusters out ofmain.tsinto domain composer modules with narrow typed inputs. - Replace inline assembly in
main.tswith single-call composer invocations per domain. - Add/adjust unit tests for new composer modules to lock shape and wiring.
- Tighten
check:main-faninthresholds after refactor to prevent regression. - Re-run full config/core test gates and update
TASK-71progress.
Progress Notes
- 2026-02-21 baseline:
src/main.ts= 3129 LOC;check:main-fanin= 105 import lines / 9 unique runtime paths. - 2026-02-21 extraction slice: added composer modules
src/main/runtime/composers/jellyfin-remote-composer.tsandsrc/main/runtime/composers/anilist-setup-composer.ts; moved correspondingcreateBuild*MainDepsHandlerorchestration out ofmain.ts. - 2026-02-21 tests: added focused composer shape tests at
src/main/runtime/composers/jellyfin-remote-composer.test.tsandsrc/main/runtime/composers/anilist-setup-composer.test.ts. - 2026-02-21 guardrail tighten:
scripts/check-main-runtime-fanin.tsdefaults tightened toimport lines <= 110andunique runtime paths <= 11. - 2026-02-21 post-slice metrics:
src/main.ts= 3042 LOC;check:main-fanin --strict= 103 import lines / 11 unique runtime paths. - Remaining gap: startup/overlay/ipc/shortcuts composer extraction still required to fully meet thin composition-root target.
Acceptance Criteria
- #1
src/main.tsis composition-focused (boot/runtime wiring only; no broad deps-builder clusters). - #2 Runtime import paths in
src/main.tsstay domain-registry oriented (no relapse to per-leaf runtime imports). - #3
check:main-faninpasses under updated threshold. - #4
bun run test:core:distpasses with no CLI/IPC behavior regressions.
Implementation Plan
- 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).
- Rewire src/main.ts IPC command and IPC registration blocks to consume the IPC composer while preserving existing helper wrappers and behavior.
- 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).
- Rewire src/main.ts shortcut runtime block to consume shortcuts composer while preserving downstream callsites.
- 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.
Implementation Notes
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.
Final Summary
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).
Definition of Done
- #1
src/main.tsLOC and fan-in metrics improve from pre-task baseline and are recorded in task notes. - #2 New composer modules are covered by focused tests.
- #3
TASK-71andTASK-85progress notes reflect completed slice and remaining gap.