[Refactor] Extract @clawwork/core package with port-based DI#178
Merged
[Refactor] Extract @clawwork/core package with port-based DI#178
Conversation
Move stores, session sync, gateway dispatcher, protocol parsing, and error classification into a new @clawwork/core package. Desktop stores become thin re-exports wired through an ElectronPlatformAdapter. - Port interfaces: PersistencePort, GatewayTransportPort, SettingsPort, NotificationsPort - Factory functions: createMessageStore, createTaskStore, createUiStore, createSessionSync, createGatewayDispatcher - Protocol pure functions extracted from useGatewayDispatcher and session-sync (extractText, normalizeAssistantTurns, etc.) - Main process ws-handlers imports parseToolArgs from core - Preload types derive IpcResult/ChatAttachment from @clawwork/shared - Zero consumer file changes (28+ component imports unchanged) - Viewport-based panel width defaults preserved via getViewportWidth dep - Dispatcher reset() on unmount preserves remount/HMR lifecycle semantics
Contributor
|
Hi @samzong, DetailsInstructions for interacting with me using comments are available here. |
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
Extract a new
@clawwork/corepackage that holds all platform-agnostic business logic — stores, session sync, gateway event dispatching, protocol parsing, and error classification. Desktop stores become thin re-exports wired through anElectronPlatformAdapter. This is the foundation for a future PWA package that can share core logic without reimplementing it.Type of change
[Refactor]internal cleanupWhy is this needed?
ClawWork's renderer code directly calls
window.clawwork.*from stores, hooks, and services. This couples all business logic to Electron, making it impossible to reuse in a PWA or test without mocking the entire bridge. This refactor introduces port-based dependency injection so core defines interfaces (ports) and desktop implements them (adapters).What changed?
packages/core/with port interfaces (PersistencePort,GatewayTransportPort,SettingsPort,NotificationsPort)createMessageStore,createTaskStore,createUiStoreaccepting port depscreateSessionSyncfactory replacing directwindow.clawworkcalls in session-synccreateGatewayDispatcherfactory withreset()for clean remount lifecycleuseGatewayDispatcherandsession-sync(extractText,normalizeAssistantTurns, etc.)ElectronPlatformAdaptermappingwindow.clawworkto port interfaces with lazy init (Proxy-based, test-safe)ws-handlers.tsimportsparseToolArgsfrom core (eliminates duplication)clawwork.d.tsderivesIpcResult/ChatAttachmentfrom@clawwork/sharedcheck-architecture.mjsandcheck-i18n.mjsupdated to scan core packageknip.json,pnpm-workspace.yaml, rootpackage.jsontypecheck script updatedArchitecture impact
packages/core(platform-agnostic), changes in renderer + main + preloadparseToolArgsfrom@clawwork/core;electron.vite.config.tsupdated to bundle core for main/preloaddocs/architecture-invariants.md:persistMessagecallswindow.clawworkaccess boundary: now concentrated inplatform/electron-adapter.tsandplatform/index.ts(two escape hatches:rebuildMenu,getDeviceId)Linked issues
Part of PWA preparation. Next PR: extract chat composer service, then create
packages/pwa.Validation
pnpm lintpnpm testpnpm check:ui-contractpnpm check(full suite: lint + architecture + ui-contract + renderer-copy + i18n + dead-code + format + typecheck + test)pnpm --filter @clawwork/desktop buildCommands, screenshots, or notes:
Screenshots or recordings
No UI changes. All existing component imports unchanged.
Release note
NONE.Checklist
[Refactor]