refactor: split generation.ts and model.ts store slices below 250 lines#138
refactor: split generation.ts and model.ts store slices below 250 lines#138thedavidweng wants to merge 3 commits into
Conversation
…es (#53) Extract cohesive units from the two largest store slices to bring each under the 250-line target from #53, without splitting logic that would hurt maintainability. generation.ts: 352 → 204 lines - Extract applyGenerationEvent → generation-events.ts (event-to-state mapper) - Extract active task actions → generation-tasks.ts (refresh/resume/discard) model.ts: 423 → 196 lines - Extract MODEL_CATALOG constant → model-catalog.ts - Extract applyModelStatus computation → model-status-apply.ts - Extract backend provision actions → backend-provision-actions.ts - Extract model sync actions → model-sync-actions.ts (deleteAll/refresh) SettingsOverlay.tsx (209 lines) was already split into section components. model_manager/mod.rs (442 lines) was already split into submodules by #121. All existing tests pass with no regressions. Closes #53 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #138 +/- ##
=======================================
+ Coverage 71.9% 72.1% +0.2%
=======================================
Files 60 67 +7
Lines 2356 2406 +50
Branches 701 713 +12
=======================================
+ Hits 1696 1737 +41
- Misses 471 477 +6
- Partials 189 192 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Greptile SummaryThis PR refactors the two largest store slices —
Confidence Score: 5/5Safe to merge — this is a pure structural refactoring with no behavioral changes beyond one deliberate bug fix in refreshModelStatuses. All logic is a verbatim move from two large slices into focused helper modules. The one deviation from a pure refactor — correcting the dead ternary in refreshModelStatuses so a stale modelVariant is cleared to null after a refresh — is an intentional and correct fix. All tests pass (954 cases), typecheck and lint are clean, and no new API boundaries or data flow paths were introduced. No files require special attention. The model-status-apply.ts side-effect pattern (promises started during computation, then collected by the caller) is unusual but correctly handled in model.ts with .catch() error logging. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph generation["generation slice"]
G[generation.ts]
GE[generation-events.ts\napplyGenerationEvent]
GT[generation-tasks.ts\nrefreshActiveTasks\nresumeActiveTask\ndiscardActiveTask]
end
subgraph model["model slice"]
M[model.ts]
MC[model-catalog.ts\nMODEL_CATALOG]
MS[model-status-apply.ts\ncomputeModelStatusPatch]
BP[backend-provision-actions.ts\nprovisionBackend\nupdateBackend\nrefreshBackendProvisionStatus]
SY[model-sync-actions.ts\nrefreshModelStatuses\ndeleteAllModels]
end
G -->|imports applyGenerationEvent| GE
G -->|spreads createGenerationTaskActions| GT
M -->|initializes modelCatalog| MC
M -->|imports computeModelStatusPatch| MS
M -->|spreads createBackendProvisionActions| BP
M -->|spreads createModelSyncActions| SY
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
subgraph generation["generation slice"]
G[generation.ts]
GE[generation-events.ts\napplyGenerationEvent]
GT[generation-tasks.ts\nrefreshActiveTasks\nresumeActiveTask\ndiscardActiveTask]
end
subgraph model["model slice"]
M[model.ts]
MC[model-catalog.ts\nMODEL_CATALOG]
MS[model-status-apply.ts\ncomputeModelStatusPatch]
BP[backend-provision-actions.ts\nprovisionBackend\nupdateBackend\nrefreshBackendProvisionStatus]
SY[model-sync-actions.ts\nrefreshModelStatuses\ndeleteAllModels]
end
G -->|imports applyGenerationEvent| GE
G -->|spreads createGenerationTaskActions| GT
M -->|initializes modelCatalog| MC
M -->|imports computeModelStatusPatch| MS
M -->|spreads createBackendProvisionActions| BP
M -->|spreads createModelSyncActions| SY
Reviews (3): Last reviewed commit: "fix: surface errors from applyModelStatu..." | Re-trigger Greptile |
The ternary in refreshModelStatuses was tautological — both branches returned state.settings.modelVariant, so a selected model that was no longer downloaded would remain selected after a status refresh. Now correctly sets modelVariant to null when the selected variant is not in downloadedModels. Also fixes the bootstrapStatus call to use the corrected variant instead of the stale one. Addresses Greptile review on #138. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The for-loop over sideEffects used `void effect`, which discarded each setSetting promise without awaiting or handling errors — a rejected persistence call would silently vanish as an unhandled rejection. Attach a .catch logger (normalised via Promise.resolve so non-promise return values from mocks do not throw) to surface failures. Addresses Greptile P2 review comment on #138. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Extract cohesive units from the two largest store slices to bring each under the 250-line target from #53.
generation.ts: 352 to 204 lines
applyGenerationEventtogeneration-events.ts(event-to-state mapper, 8 cases)generation-tasks.ts(refresh/resume/discard)model.ts: 423 to 196 lines
MODEL_CATALOGconstant tomodel-catalog.tsapplyModelStatuscomputation tomodel-status-apply.tsbackend-provision-actions.tsmodel-sync-actions.ts(deleteAll/refresh)Already done
SettingsOverlay.tsx(209 lines) — already split into section componentsmodel_manager/mod.rs(442 lines) — already split into submodules by refactor(model-manager): split mod.rs into focused submodules (#53) #121Closes #53
Test plan
pnpm typecheckcleanpnpm lintcleanpnpm format:checkcleanpnpm test:run(954 passed, no regressions)Generated with Devin