Skip to content

Commit 915b8b3

Browse files
committed
refactor(backend): extract shared cores and align mobile RPC parity
1 parent 3f6a4d7 commit 915b8b3

20 files changed

Lines changed: 4791 additions & 3678 deletions

docs/mobile-ios-cloudflare-blueprint.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ This document is the canonical implementation plan for shipping CodexMonitor on
1818
- `app-server-event`
1919
- `terminal-output`
2020
- `terminal-exit`
21-
- Daemon RPC surface does not match full local Tauri command surface yet (major parity gap).
21+
- Mobile UI scope is the existing app layout in mobile form-factor (no separate mobile-only feature surface).
22+
- Shared-core parity refactor is in place for prompts, local usage, codex utility helpers, git/github UI helpers, and workspace actions.
23+
- Daemon RPC parity for the current mobile scope is complete.
24+
- `terminal_*` and `dictation_*` command parity are intentionally out of scope for this mobile phase.
2225

2326
## Target Architecture
2427

@@ -214,32 +217,37 @@ Behavior:
214217
- Outbound WS to Worker.
215218
- Translate bridge envelopes <-> existing RPC handler + event bus.
216219

217-
## 6) Command parity completion (blocking)
220+
## 6) Command parity scope (mobile phase)
218221

219-
Remote mode must support the full local command surface used by UI.
222+
Remote mode must support all commands exercised by the current mobile UI surface.
220223

221-
Implement missing daemon methods and/or remote routing for at least:
224+
Implemented in shared core + daemon/app adapters:
222225

223-
- Git commands:
226+
- Git + GitHub UI commands:
224227
- `list_git_roots`, `get_git_status`, `get_git_diffs`, `get_git_log`, `get_git_commit_diff`, `get_git_remote`
225228
- `list_git_branches`, `checkout_git_branch`, `create_git_branch`
226229
- `stage_git_file`, `stage_git_all`, `unstage_git_file`
227230
- `revert_git_file`, `revert_git_all`
228231
- `commit_git`, `push_git`, `pull_git`, `fetch_git`, `sync_git`
229-
- GitHub API commands for issues/PRs/comments/diff
230-
- Terminal commands:
231-
- `terminal_open`, `terminal_write`, `terminal_resize`, `terminal_close`
232+
- GitHub issues/PRs/comments/diff commands
232233
- Prompts commands:
233234
- `prompts_list`, `prompts_create`, `prompts_update`, `prompts_delete`, `prompts_move`, `prompts_workspace_dir`, `prompts_global_dir`
234-
- Dictation commands:
235-
- `dictation_model_status`, `dictation_download_model`, `dictation_cancel_download`, `dictation_remove_model`, `dictation_start`, `dictation_request_permission`, `dictation_stop`, `dictation_cancel`
236235
- Workspace/app extras:
237236
- `add_clone`, `apply_worktree_changes`, `open_workspace_in`, `get_open_app_icon`
238237
- Utility commands:
239238
- `codex_doctor`, `get_commit_message_prompt`, `generate_commit_message`, `generate_run_metadata`, `local_usage_snapshot`, `send_notification_fallback`, `is_macos_debug_build`, `menu_set_accelerators`
240239

241-
Add CI guard:
242-
- Script that parses `generate_handler![]` and daemon RPC dispatch and fails on mismatch.
240+
Out of scope for this mobile phase:
241+
242+
- Terminal commands:
243+
- `terminal_open`, `terminal_write`, `terminal_resize`, `terminal_close`
244+
- Dictation commands:
245+
- `dictation_model_status`, `dictation_download_model`, `dictation_cancel_download`, `dictation_remove_model`, `dictation_start`, `dictation_request_permission`, `dictation_stop`, `dictation_cancel`
246+
247+
Validation policy:
248+
249+
- No CI parity guard is required for this phase.
250+
- Validate parity locally before merge (build/tests + remote-mode smoke checks).
243251

244252
## Frontend Plan
245253

@@ -423,17 +431,18 @@ cargo test
423431
3. Connect workspace.
424432
4. Start thread, send messages, interrupt turn.
425433
5. Git diff panel operations.
426-
6. Terminal open/write/resize/close.
427-
7. Prompts CRUD.
428-
8. Background iOS app, resume, ensure state resync.
429-
9. macOS runner restart, iOS auto-reconnect.
434+
6. Prompts CRUD.
435+
7. Verify terminal UI is not exposed in mobile mode.
436+
8. Verify dictation UI is not exposed in mobile mode.
437+
9. Background iOS app, resume, ensure state resync.
438+
10. macOS runner restart, iOS auto-reconnect.
430439

431440
## Implementation Milestones
432441

433442
1. Milestone A: iOS compile baseline + mobile-safe stubs.
434443
2. Milestone B: Cloudflare Worker + DO bridge deployed + tested with mock clients.
435444
3. Milestone C: remote_backend transport refactor + runner bridge mode.
436-
4. Milestone D: daemon parity closure + CI parity guard.
445+
4. Milestone D: daemon parity closure for mobile scope (excluding terminal/dictation).
437446
5. Milestone E: settings UX/service manager + pairing UX.
438447
6. Milestone F: full E2E validation and TestFlight beta.
439448

@@ -452,7 +461,7 @@ cargo test
452461
2. Implement Milestone A first and ensure local iOS dev build works.
453462
3. Implement Cloudflare bridge in isolation (mock runner/client).
454463
4. Refactor `remote_backend` to transport abstraction.
455-
5. Complete daemon parity and add parity CI guard.
464+
5. Complete daemon parity for mobile scope and validate locally.
456465
6. Build settings UX and runner service controls.
457466
7. Validate full manual checklist on simulator and physical device.
458467
8. Ship behind feature flag, then remove flag after beta validation.

memory/decisions.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,52 @@ Type: preference
141141
Event: User explicitly requested to ignore PR #31 and CloudKit for mobile architecture planning.
142142
Action: Canonical mobile plan now targets Cloudflare bridge only, with no dependency on CloudKit or PR #31 implementation details.
143143
Rule: Do not propose CloudKit/PR31-based mobile backend patterns unless user re-requests them.
144+
145+
## 2026-02-07 15:11
146+
Context: Mobile UI scope confirmation
147+
Type: preference
148+
Event: User confirmed iOS should reuse the current app layout's mobile variant instead of introducing a separate mobile-only UI surface.
149+
Action: Treat mobile work as backend/connectivity enablement for existing mobile-responsive UI flows.
150+
Rule: For iOS rollout, prioritize backend/transport parity for existing UI flows before designing net-new mobile-specific screens.
151+
152+
## 2026-02-07 15:26
153+
Context: App/daemon parity refactor quality bar
154+
Type: preference
155+
Event: User requested parity work avoid repeated logical code between app and daemon, with shared implementations as the default.
156+
Action: Current in-progress daemon parity changes must be completed by extracting/using shared core helpers instead of duplicating logic in daemon-specific functions.
157+
Rule: For app/daemon parity, keep domain logic in shared modules and restrict app/daemon code to thin adapters.
158+
159+
## 2026-02-07 15:42
160+
Context: Daemon parity implementation scope for mobile wiring
161+
Type: preference
162+
Event: User explicitly excluded terminal and dictation from current mobile/remote parity work.
163+
Action: Implemented daemon RPC parity for non-terminal/non-dictation methods and validated parity gap now contains only `terminal_*` and `dictation_*` commands.
164+
Rule: For current mobile remote-mode rollout, treat terminal and dictation RPC parity as out of scope unless the user re-enables them.
165+
166+
## 2026-02-07 16:58
167+
Context: App/daemon parity dedup for mobile remote-mode backend
168+
Type: decision
169+
Event: Refactored duplicated prompt/local-usage/codex-utility/git logic into shared core modules and switched app/daemon code to adapter-only wrappers.
170+
Action: Added `shared/prompts_core.rs`, `shared/local_usage_core.rs`, `shared/codex_aux_core.rs`, and `shared/git_ui_core.rs`; rewired `prompts.rs`, `local_usage.rs`, `git/mod.rs`, `codex/mod.rs`, and daemon method handlers to call shared functions.
171+
Rule: Keep user-facing git/prompt/local-usage/codex utility behavior in shared cores and keep app/daemon files limited to transport/wiring responsibilities.
172+
173+
## 2026-02-07 17:22
174+
Context: Remaining workspace-action parity dedup
175+
Type: decision
176+
Event: `add_clone`, `apply_worktree_changes`, `open_workspace_in`, and `get_open_app_icon` still duplicated between app and daemon after first parity refactor pass.
177+
Action: Moved those behaviors into `shared/workspaces_core.rs` (`add_clone_core`, `apply_worktree_changes_core`, `open_workspace_in_core`, `get_open_app_icon_core`) and rewired both app (`workspaces/commands.rs`) and daemon (`codex_monitor_daemon.rs`) to thin adapters.
178+
Rule: Keep workspace action behavior shared-first; app and daemon should only pass environment dependencies and transport payloads.
179+
180+
## 2026-02-07 17:26
181+
Context: Backend test-target dead code warnings
182+
Type: decision
183+
Event: `cargo test` warnings came from a truly unused test hook and a test helper compiled in targets that do not reference it.
184+
Action: Removed unused `set_window_appearance_override` from `window.rs`; added `#[allow(dead_code)]` to `workspaces/settings.rs::sort_workspaces` (test-only helper used in lib tests but not daemon test target).
185+
Rule: Remove genuinely unused test hooks; for cross-target test helpers, use narrow `#[allow(dead_code)]` instead of broad warning suppression.
186+
187+
## 2026-02-07 17:32
188+
Context: Mobile parity verification policy
189+
Type: preference
190+
Event: User explicitly requested no CI parity guard for this phase and to rely on local validation.
191+
Action: Updated mobile Cloudflare blueprint to remove CI parity guard requirements and require local parity validation only.
192+
Rule: For current mobile/remote scope, do not add CI parity guardrails unless user requests them again.

memory/mistakes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ Rule: Avoid redefining primitive-owned positioning styles in migrated feature sh
2121
Root cause: `.settings-window { position: relative; }` overrode `.ds-modal-card` absolute centering because `settings.css` loads after `ds-modal.css`.
2222
Fix applied: Removed `position` and `z-index` from `.settings-window` so DS card positioning controls centering.
2323
Prevention rule: When migrating existing shell classes onto DS primitives, avoid redeclaring layout-positioning properties (`position/top/left/transform`) already owned by the primitive.
24+
25+
## 2026-02-07 16:58
26+
Context: Codex utility dedup refactor (`src-tauri/src/codex/mod.rs`)
27+
Type: mistake
28+
Event: A bulk file rewrite command truncated `codex/mod.rs` during refactor, temporarily dropping unrelated command handlers.
29+
Action: Restored file from `HEAD` immediately and reapplied refactor using targeted replacements/patches only.
30+
Rule: For large Rust modules, avoid full-file/head-tail rewrites unless line boundaries are verified; prefer function-scoped `apply_patch` edits.
31+
Root cause: Used brittle line-count/head-tail rewrite workflow while file contents were changing.
32+
Fix applied: Recovered from git snapshot and switched to explicit function-level patching.
33+
Prevention rule: Use patch hunks anchored on function signatures for high-churn files and verify file length/function inventory after each structural edit.

memory/todo.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
- [x] Complete phase-2 design-system migration cleanup for targeted families (modals, toasts, panel shells, diff theme defaults).
99
- [x] Add lint/codemod automation for DS primitive adoption (`modal-shell`, `panel-shell`, `toast-shell`) as defined in `docs/design-system-migration-plan.md`.
1010
- [x] Run manual visual parity QA checklist for migrated modal/toast/panel/diff families and delete remaining unreferenced legacy selectors.
11+
- [x] 2026-02-07: Replace daemon `local_usage_snapshot` temporary zeroed snapshot implementation with shared real session-log scanner parity.
12+
- [x] 2026-02-07: Extract newly mirrored daemon git/github/prompts/codex utility logic into shared core modules to eliminate remaining app/daemon duplication.
13+
- [x] 2026-02-07: Replace daemon `local_usage_snapshot` temporary implementation by sharing real local usage scanner logic in `shared/local_usage_core.rs`.
14+
- [x] 2026-02-07: Eliminate app/daemon duplication for git/github/prompt/codex utility behavior via shared cores (`git_ui_core`, `prompts_core`, `codex_aux_core`).
15+
- [x] 2026-02-07: Move remaining duplicated workspace-action logic (`add_clone`, `apply_worktree_changes`, `open_workspace_in`, `get_open_app_icon`) into shared core helpers.

0 commit comments

Comments
 (0)