refactor(desktop): share the repeated codec, engine and frontend helpers - #1326
refactor(desktop): share the repeated codec, engine and frontend helpers#1326bobzhang wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
The broad behavioral refactor spans many critical subsystems, and the final changed file’s diff is truncated, preventing a complete review.
Pull request overview
Refactors repeated codec, engine, host, worktree, and frontend logic into shared helpers while preserving existing behavior.
Changes:
- Consolidates JSON encoding/decoding and repeated lookup/error-handling patterns.
- Extracts common engine/worktree test fixtures and rollback/refusal helpers.
- Simplifies frontend state transitions, editor rendering, and UI construction.
File summaries
| File | Description |
|---|---|
desktop/internal/worktree/worktree.mbt |
Simplifies lookup and extracts worktree test setup. |
desktop/internal/protocol/text_search_codec.mbt |
Shares numeric and error-pair decoding. |
desktop/internal/protocol/semantic_search_codec.mbt |
Reuses shared codec validation helpers. |
desktop/internal/protocol/json_object.mbt |
Adds generic optional encoding and typed decoding. |
desktop/internal/protocol/git_protocol_codec.mbt |
Applies shared JSON helpers. |
desktop/internal/protocol/desktop_replies.mbt |
Consolidates optional field codecs. |
desktop/internal/protocol/desktop_messages.mbt |
Consolidates message encoders and decoders. |
desktop/internal/protocol/codex_commands.mbt |
Applies generic codec helpers. |
desktop/internal/protocol/agent_payload_codec.mbt |
Simplifies optional and array codecs. |
desktop/internal/moonbit/toolchain_paths.mbt |
Deduplicates fixture file creation. |
desktop/internal/host/update_check.mbt |
Consolidates update availability calculation. |
desktop/internal/host/text_search.mbt |
Extracts surrogate checking and first-line searches. |
desktop/internal/host/terminal_ops.mbt |
Removes redundant private payload types. |
desktop/internal/host/host.mbt |
Emits terminal payloads directly. |
desktop/internal/host/git_ops.mbt |
Shares Git output/error helpers and simplifies classification. |
desktop/internal/engine/worktree_seam_wbtest.mbt |
Reuses engine fixture and refusal helpers. |
desktop/internal/engine/ops.mbt |
Adds shared run-test fixture setup. |
desktop/internal/engine/follower.mbt |
Reuses refusal capture helper. |
desktop/internal/engine/engine.mbt |
Simplifies map initialization, collection, and event emission. |
desktop/internal/engine/config.mbt |
Reuses refusal capture helper. |
desktop/internal/engine/archive.mbt |
Shares rollback and test refusal logic. |
desktop/internal/engine/archive_lookup_wbtest.mbt |
Reuses refusal capture helper. |
desktop/internal/codex/actor.mbt |
Shares actor request submission flow. |
desktop/internal/auth/urls.mbt |
Extracts suffix removal. |
desktop/internal/auth/signin.mbt |
Reuses fallback and URL helpers. |
desktop/internal/auth/pkce.mbt |
Simplifies Base64URL conversion and URL handling. |
desktop/frontend/transcript/sessions.mbt |
Consolidates terminal projection control flow. |
desktop/frontend/transcript/component/view_tests.mbt |
Reuses base test input fixtures. |
desktop/frontend/transcript/component/tool_tabs.mbt |
Simplifies argument and output tab construction. |
desktop/frontend/storage.mbt |
Shares guarded local-storage mutation. |
desktop/frontend/skills/state.mbt |
Extracts preview cache/fetch transition. |
desktop/frontend/project_picker/requests.mbt |
Shares browse failure construction. |
desktop/frontend/model.mbt |
Simplifies searches and transcript reload transitions. |
desktop/frontend/goal.mbt |
Extracts repeated runtime-notice test setup. |
desktop/frontend/fileeditor/view.mbt |
Shares focus, surface, and graph rendering helpers. |
desktop/frontend/fileeditor/update.mbt |
Consolidates review reconciliation and test fixtures. |
desktop/frontend/fileeditor/semantic_review_view.mbt |
Shares semantic editor disposal. |
desktop/frontend/fileeditor/editor_panel.mbt |
Consolidates viewer-model cleanup. |
desktop/frontend/composer/component.mbt |
Merges repeated reconciliation and completion paths. |
desktop/frontend/composer/codex_request.mbt |
Shares request decision button construction. |
desktop/frontend/codex/bridge.mbt |
Shares textual mention fallback and request lookup. |
desktop/frontend/bridge.mbt |
Consolidates recovered-run and failure transitions. |
desktop/frontend/goal.mbt |
Diff excerpt is incomplete, preventing full review. |
Review details
- Files reviewed: 43/43 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| .to_array() | ||
| .map(pair => pair.0) | ||
| .filter(key => !desired_keys.contains(key)) | ||
| let stale = [ |
There was a problem hiding this comment.
[ for key,_ in ... if !desired_keys.containts => key]
There was a problem hiding this comment.
Applied. The stale keys are filtered in the comprehension, so the intermediate
array of every editor key is gone.
One wrinkle worth recording: written inline the line is long enough that
moon fmt wraps it, and a wrapped comprehension whose body is a bare
identifier gets reformatted to { key }, which the compiler then reads as a
struct literal (E4033, "There is no record definition with the fields: key").
Naming the predicate keeps it on one line and avoids that.
This is the half that needs a careful read: these hunks add or remove something SHARED, so correctness depends on code outside the hunk you are looking at. What to check, hardest first: 1. **An extracted helper must be equivalent at every call site it replaced.** The trap is a call site that passed a different argument, or read state at a different moment, than its neighbours. 2. **A merged or-pattern arm must have had identical bodies.** 3. **A reshaped loop must keep its iteration order and its early exits.** The purely local rewrites these were mixed with have been split into a separate pull request, so everything left here is shared-surface change. Verified on this branch alone, with no other part of the refactor applied: `moon fmt --check`, `moon check --target native --deny-warn`, `moon check --target js --deny-warn`, and the full native and JS test suites. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JiBNGzCsZpN6e5Y4p9pXdn
2ed968e to
db19ed6
Compare
This half needs a careful read. Every hunk here adds or removes something
SHARED, so correctness depends on code outside the hunk you are looking at. The
purely in-function rewrites this was mixed with have moved to a separate pull
request, so what is left is all shared-surface change.
What to check, hardest first:
The trap is a call site that passed a different argument, or read state at a
different moment, than its neighbours.
differed and the difference moved inside the arm, the fold buys less than it
appears to.
Scope:
desktop/. The largest pieces are the protocol codec readers and writers each boundary had copied, the engine's shared refusal and run-actor fixtures, and the frontend's repeated update transitions.Review comment addressed
[for key, _ in ... if !desired_keys.contains => key]— applied. The staleeditor keys are filtered in the comprehension, so the intermediate array of
every editor key is gone. The predicate is named rather than inline because
moon fmtwraps the longer form, and a wrapped comprehension whose body is abare identifier becomes
{ key }, which the compiler reads as a struct literal.Verified on this branch alone
moon fmt --check,moon check --target native --deny-warn,moon check --target js --deny-warn, and both full test suites, with no other part of therefactor applied. No
.mbtichanged.The refactor is split so each pull request asks one kind of question. Every file
appears in exactly one of them, each was verified on its own branch with no
other part applied, so they merge in any order.
desktop/editor/🤖 Generated with Claude Code
https://claude.ai/code/session_01JiBNGzCsZpN6e5Y4p9pXdn