refactor(main): extract anilist/mpv runtime composers

This commit is contained in:
2026-02-20 21:01:24 -08:00
parent 4fc34ec787
commit f8db9e7119
12 changed files with 967 additions and 225 deletions

View File

@@ -16,7 +16,7 @@ SubMiner uses a service-oriented Electron architecture with a composition-orient
```text
src/
main.ts # Entry point — delegates to src/main/ composition modules
main.ts # Entry point — delegates to runtime composers/domain modules
preload.ts # Electron preload bridge
types.ts # Shared type definitions
main/ # Composition root modules (extracted from main.ts)
@@ -31,6 +31,9 @@ src/
startup-lifecycle.ts # App-ready initialization sequence
state.ts # Application runtime state container
subsync-runtime.ts # Subsync command orchestration
runtime/
composers/ # Composition assembly clusters consumed by main.ts
domains/ # Domain barrel exports for runtime services
core/
services/ # ~60 focused service modules (see below)
utils/ # Pure helpers and coercion/config utilities
@@ -154,7 +157,7 @@ Most runtime code follows a dependency-injection pattern:
3. Build runtime deps in `src/main/` composition modules; extract an adapter/helper only when it adds meaningful behavior or reuse.
4. Call the service from lifecycle/command wiring points.
The composition root (`src/main.ts`) delegates to focused modules in `src/main/`:
The composition root (`src/main.ts`) delegates to focused modules in `src/main/` and `src/main/runtime/composers/`:
- `startup.ts` — argv/env processing and bootstrap flow
- `app-lifecycle.ts` — Electron lifecycle event registration
@@ -164,6 +167,8 @@ The composition root (`src/main.ts`) delegates to focused modules in `src/main/`
- `cli-runtime.ts` — CLI command parsing and dispatch
- `overlay-runtime.ts` — overlay window selection and modal state management
- `subsync-runtime.ts` — subsync command orchestration
- `runtime/composers/anilist-tracking-composer.ts` — AniList media tracking/probe/retry wiring
- `runtime/composers/mpv-runtime-composer.ts` — MPV event/factory/tokenizer/warmup wiring
This keeps side effects explicit and makes behavior easy to unit-test with fakes.
@@ -228,7 +233,7 @@ flowchart TD
## Extension Rules
- Add behavior to an existing service in `src/core/services/*` or create a new focused module in `src/main/` for composition-level logic — not as ad-hoc logic in `main.ts`.
- Add behavior to an existing service in `src/core/services/*` or create a focused composition module in `src/main/` / `src/main/runtime/composers/` — not as ad-hoc logic in `main.ts`.
- Keep service APIs explicit and narrowly scoped.
- Prefer additive changes that preserve existing CLI flags and IPC channel behavior.
- Add/update unit tests for each service extraction or behavior change.

View File

@@ -115,7 +115,7 @@ Run `make help` for a full list of targets. Key ones:
- To add or change a config option, update `src/config/definitions.ts` first. Defaults, runtime-option metadata, and generated `config.example.jsonc` are derived from this centralized source.
- Overlay window/visibility state is owned by `src/core/services/overlay-manager.ts`.
- Main process composition is now split across `src/main/` modules (`startup.ts`, `app-lifecycle.ts`, `startup-lifecycle.ts`, `state.ts`, `ipc-runtime.ts`, `cli-runtime.ts`, `overlay-runtime.ts`, `subsync-runtime.ts`).
- Main process composition is split across `src/main/` modules plus focused runtime composers under `src/main/runtime/composers/*` (for example AniList tracking and MPV runtime assembly clusters).
- Runtime domain imports for `src/main.ts` should route through `src/main/runtime/domains/*`; shared domain access point is `src/main/runtime/registry.ts`.
- Linux packaged desktop launches pass `--background` using electron-builder `build.linux.executableArgs` in `package.json`.
- MPV service has been split into transport, protocol, state, and properties layers in `src/core/services/`.

View File

@@ -31,3 +31,4 @@ Read first. Keep concise.
| `opencode-task95-config-20260221T031843Z-m4k9` | `opencode-task95-config` | `Implement TASK-95 config extraction for src/config/service.ts` | `done` | `docs/subagents/agents/opencode-task95-config-20260221T031843Z-m4k9.md` | `2026-02-21T03:26:57Z` |
| `codex-task95-anki-20260221T031836Z-6f3e` | `codex-task95-anki` | `Implement TASK-95 anki-integration extraction for field-grouping merge collaborator` | `done` | `docs/subagents/agents/codex-task95-anki-20260221T031836Z-6f3e.md` | `2026-02-21T03:26:55Z` |
| `opencode-task-94-20260221T033647Z-7ou2` | `opencode-task-94` | `Finish TASK-94 thin composition root refactor and close acceptance criteria` | `done` | `docs/subagents/agents/opencode-task-94-20260221T033647Z-7ou2.md` | `2026-02-21T04:12:45Z` |
| `codex-task71-round2-20260221T043541Z-k9t3` | `codex-task71-round2` | `Execute TASK-71 round 2 split of main.ts into domain runtime modules` | `done` | `docs/subagents/agents/codex-task71-round2-20260221T043541Z-k9t3.md` | `2026-02-21T04:57:00Z` |

View File

@@ -0,0 +1,46 @@
# Agent: codex-task71-round2-20260221T043541Z-k9t3
- alias: codex-task71-round2
- mission: Execute TASK-71 round 2 by further splitting main.ts wiring into domain runtime modules with focused tests/docs updates
- status: done
- branch: main
- started_at: 2026-02-21T04:35:41Z
- heartbeat_minutes: 5
## Current Work (newest first)
- [2026-02-21T04:57:00Z] completed: TASK-71 moved to Done in Backlog MCP; AC + DoD checked; notes/final summary recorded.
- [2026-02-21T04:55:00Z] verify: `bun run build`, `bun run check:main-fanin:strict`, `bun run test:fast` all passing.
- [2026-02-21T04:52:00Z] progress: added `src/main/runtime/composers/index.ts` barrel and rewired `src/main.ts` composer imports to recover strict fan-in gate (85 lines / 10 unique paths).
- [2026-02-21T04:49:00Z] progress: rewired `src/main.ts` AniList + MPV assembly clusters to `composeAnilistTrackingHandlers` + `composeMpvRuntimeHandlers`; added architecture/development docs updates.
- [2026-02-21T04:44:00Z] progress: parallel subagents delivered new composers + seam tests for AniList tracking and MPV runtime clusters.
- [2026-02-21T04:35:41Z] intent: load TASK-71 context from Backlog MCP, create plan via writing-plans, execute via executing-plans, no commit.
- [2026-02-21T04:35:41Z] planned files: `src/main.ts`, `src/main/runtime/composers/*`, `src/main/runtime/domains/*`, focused tests, `docs/architecture.md`, Backlog TASK-71 metadata via MCP tools only.
- [2026-02-21T04:35:41Z] assumptions: existing dirty tree includes prior TASK-94/TASK-95 work; preserve unrelated edits.
## Files Touched
- `docs/subagents/agents/codex-task71-round2-20260221T043541Z-k9t3.md`
- `docs/subagents/INDEX.md`
- `docs/subagents/collaboration.md`
- `docs/plans/2026-02-21-task-71-round2-main-runtime-modules.md`
- `src/main.ts`
- `src/main/runtime/composers/anilist-tracking-composer.ts`
- `src/main/runtime/composers/anilist-tracking-composer.test.ts`
- `src/main/runtime/composers/mpv-runtime-composer.ts`
- `src/main/runtime/composers/mpv-runtime-composer.test.ts`
- `src/main/runtime/composers/index.ts`
- `docs/architecture.md`
- `docs/development.md`
## Assumptions
- User requested direct plan+execution flow; no extra approval gate needed.
## Open Questions / Blockers
- none
## Next Step
- Handoff complete; await user direction (optional commit/push).

View File

@@ -29,3 +29,5 @@ Shared notes. Append-only.
- [2026-02-21T03:36:58Z] [opencode-task-94-20260221T033647Z-7ou2|opencode-task-94] starting TASK-94 finish pass: pull backlog context, write+execute plan via writing-plans/executing-plans, and close remaining AC without commit.
- [2026-02-21T04:11:57Z] [opencode-task-94-20260221T033647Z-7ou2|opencode-task-94] extracted IPC/shortcuts/startup-lifecycle/app-ready clusters behind composer modules, rewired `src/main.ts`, added focused composer tests, and revalidated build + `check:main-fanin` + `test:core:dist`.
- [2026-02-21T04:12:45Z] [opencode-task-94-20260221T033647Z-7ou2|opencode-task-94] TASK-94 finalized in Backlog MCP: AC checklist complete, notes+final summary recorded, status moved to Done.
- [2026-02-21T04:35:41Z] [codex-task71-round2-20260221T043541Z-k9t3|codex-task71-round2] overlap note: starting TASK-71 round 2 follow-up on `src/main.ts` + `src/main/runtime/composers/*` + docs; preserving prior TASK-94/TASK-95 edits.
- [2026-02-21T04:57:00Z] [codex-task71-round2-20260221T043541Z-k9t3|codex-task71-round2] completed TASK-71: extracted AniList tracking + MPV runtime composition into new composers, added seam tests, rewired `main.ts` + composer barrel, strict fan-in green, and finalized Backlog task as Done.