5.2 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies, priority
| id | title | status | assignee | created_date | updated_date | labels | dependencies | priority | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TASK-71 | Split main.ts into domain runtime modules round 2 | Done |
|
2026-02-18 11:35 | 2026-02-21 04:57 |
|
high |
Description
src/main.ts remains >3k LOC and still mixes composition, runtime state mutation, domain workflows (Jellyfin, AniList), tray/UI setup, and IPC wiring. This creates high cognitive load and broad change blast radius.
Progress Notes
- Added runtime domain barrels under
src/main/runtime/domains/*and composed registry entrypoint atsrc/main/runtime/registry.ts. - Migrated
src/main.tsruntime imports from per-file runtime modules to domain barrel import paths. - Added
scripts/check-main-runtime-fanin.tsguardrail and package scripts (check:main-fanin,check:main-fanin:strict). - 2026-02-21: extracted jellyfin/anilist deps-builder clusters into composer modules (
src/main/runtime/composers/jellyfin-remote-composer.ts,src/main/runtime/composers/anilist-setup-composer.ts) and replaced inlinemain.tsorchestration with composer invocations. - 2026-02-21: tightened fan-in guard defaults to
import lines <= 110andunique runtime paths <= 11; strict mode passing. - Remaining TASK-71 scope: finish startup/overlay/ipc/shortcuts composer extraction to fully thin
src/main.ts.
Action Steps
- Extract cohesive runtime modules:
- AniList runtime orchestration
- Jellyfin runtime orchestration
- tray runtime
- MPV event binding/runtime hooks
- Keep
main.tsas composition root only (state wiring + module registration). - Define narrow service/deps interfaces per module to reduce closure capture.
- Add/adjust unit tests for extracted modules.
- Preserve existing CLI/IPC behavior exactly.
- Update architecture docs with new ownership boundaries.
Acceptance Criteria
- #1
src/main.tsresponsibilities reduced to composition/wiring concerns - #2 Extracted runtime modules have focused interfaces and isolated tests
- #3 No CLI/IPC regressions in existing test suite
- #4 Docs reflect new module boundaries
Implementation Plan
- Extract AniList tracking composition from src/main.ts (refresh/guess/probe/retry/update handler assembly) into src/main/runtime/composers/anilist-tracking-composer.ts with focused seam tests.
- Extract MPV runtime composition from src/main.ts (bind event handlers, MPV client factory, subtitle render metrics, tokenizer warmups) into src/main/runtime/composers/mpv-runtime-composer.ts with focused seam tests.
- Rewire src/main.ts to consume both composers while preserving existing local helper contracts and downstream behavior.
- Update architecture docs to reflect composition boundary under src/main/runtime/composers/*.
- Run verification gate (build + check:main-fanin + test:core:dist), then record TASK-71 notes/AC/DoD and finalize if green.
Implementation Notes
2026-02-21: extracted two remaining high-noise main-process composition clusters from src/main.ts into dedicated runtime composers: src/main/runtime/composers/anilist-tracking-composer.ts (AniList media tracking/probe/retry/update assembly) and src/main/runtime/composers/mpv-runtime-composer.ts (MPV event binding/factory/metrics/tokenizer/warmups assembly).
Rewired src/main.ts to consume composer outputs while preserving existing helper contracts/call sites (refreshAnilistClientSecretState, processNextAnilistRetryUpdate, maybeRunAnilistPostWatchUpdate, createMpvClientRuntimeService, updateMpvSubtitleRenderMetrics, tokenizeSubtitle, startBackgroundWarmups).
Added focused seam tests: src/main/runtime/composers/anilist-tracking-composer.test.ts and src/main/runtime/composers/mpv-runtime-composer.test.ts.
Added src/main/runtime/composers/index.ts barrel and updated main imports to keep runtime fan-in strict gate green.
Docs updated for new boundaries in docs/architecture.md and docs/development.md.
Verification: bun run build, bun test src/main/runtime/composers/anilist-tracking-composer.test.ts src/main/runtime/composers/mpv-runtime-composer.test.ts, bun run check:main-fanin:strict (85 import lines / 10 unique runtime paths, pass), and bun run test:fast (pass).
src/main.ts LOC reduced from 2956 to 2875 in this pass.
Final Summary
Completed TASK-71 round 2 by extracting AniList tracking and MPV runtime assembly clusters out of src/main.ts into dedicated composer modules with focused seam tests, then rewiring the composition root to consume those modules without changing runtime behavior. Added a composers barrel to reduce runtime import fan-in and updated architecture/development docs to reflect composer-first boundaries; verification gates (build, check:main-fanin:strict, composer tests, test:fast) all pass.
Definition of Done
- #1
bun run test:fastpasses - #2 Architecture docs updated