Repository navigation
refactor(architecture): decouple main state bridges and extract store transform helpers - #1084
Merged
Merged
Conversation
…bootstrap isolation Harden filesystem boundary enforcement, release checksum validation, and bootstrap scripting across Electron Main, BrowserView, and deployment scripts. Previously, browser-view.ts path containment checks did not resolve symlinks, which could allow workspace symlinks targeting files outside the workspace root to be loaded into the preview browser pane. In addition, attachment blob references and release checksum parsing relied on unconstrained segment lookups or loose falsy gates rather than strict hexadecimal SHA-256 schema validation. This change canonicalizes workspace paths with realpathSync, mandates exact 64-character hexadecimal SHA-256 formatting for attachments, restricts local bootstrap directories and tarballs to mode 700/600, eliminates TOCTOU checks in boot verification scripts, and updates git hygiene rules for certificates.
… transform helpers Decompose monolithic entrypoint and central store hotspots to comply with architectural line count and responsibility boundaries (AGENTS.md §7 and §8). In apps/desktop/electron/main/index.ts, more than 350 lines were dedicated to manual getter/setter bridges across 8 mutable state interfaces. In apps/desktop/src/stores/app-store.ts, pure workspace and session data transforms were mixed into the Zustand store definition. This change introduces MainProcessState in bootstrap/main-state.ts to encapsulate main runtime mutable state, extracts workspace git resolution into workspace-git.ts, centralizes error formatting in main-process-errors.ts, and extracts pure session and workspace transformations into stores/helpers/store-helpers.ts. This reduces index.ts from 1,484 to 1,029 lines and app-store.ts from 736 to 617 lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Decomposes
apps/desktop/electron/main/index.tsby extracting scattered mutable lifecycle bridges into a dedicatedMainProcessStatecontainer (apps/desktop/electron/main/bootstrap/main-state.ts), reducing the main entrypoint by over 450 lines of repetitive accessor boilerplate while strictly preserving contract semantics. In addition, pure data transforms are decoupled from the central Zustand store (apps/desktop/src/stores/app-store.ts).Key Changes
State Container Pattern (
bootstrap/main-state.ts):mainWindow,host,sidecar,quitting,closeBehavior,tray, etc.) into a cohesiveMainProcessStateclass.launcherState: LauncherStatewindowLifecycleState: WindowLifecycleStateruntimeState: RuntimeStateapplicationLifecycleState: ApplicationLifecycleStateapplicationAppearanceState: ApplicationAppearanceStateplanRuntimeState: PlanRuntimeStatestartupState: StartupStateshutdownState: ShutdownStateEntrypoint Simplification (
index.ts):index.tswith unified destructuring frommainState.Workspace Git Resolution Extraction (
workspace-git.ts):withGitBranchinto a dedicated workspace utility module.Error Formatting Centralization (
main-process-errors.ts):describeErrorinto the error-handling module alongsideinstallMainProcessErrorHandlers.Store Decoupling (
stores/helpers/store-helpers.ts&stores/app-store.ts):store-helpers.ts, droppingapp-store.tsfrom 736 to 617 lines (~16% reduction), complying with AGENTS.md §8 ("Pure transformation → Reducer / helper").Verification