Skip to content

refactor: split large files into focused modules and subcomponents#377

Merged
matt2e merged 5 commits intomainfrom
long-files-refactor
Mar 12, 2026
Merged

refactor: split large files into focused modules and subcomponents#377
matt2e merged 5 commits intomainfrom
long-files-refactor

Conversation

@matt2e
Copy link
Contributor

@matt2e matt2e commented Mar 12, 2026

Summary

  • Backend (lib.rs): Split the 2000+ line monolithic lib.rs into 7 focused domain modules: diff_commands, github_commands, image_commands, note_commands, review_commands, timeline, and util_commands
  • Frontend (BranchCard.svelte): Extracted 3 subcomponents from the 2300+ line BranchCard.svelte: BranchCardActionsBar, BranchCardPrButton, and BranchCardSessionManager
  • No functional changes — purely structural refactoring for maintainability

Test plan

  • Verify all existing tests pass (CI ran on push)
  • Smoke test branch card UI interactions (actions bar, PR button, session management)
  • Verify Tauri commands still work end-to-end (diffs, GitHub, images, notes, reviews, timeline)

🤖 Generated with Claude Code

@matt2e matt2e requested review from baxen and wesbillman as code owners March 12, 2026 04:37
matt2e and others added 3 commits March 12, 2026 15:39
Extract ~1,700 lines from lib.rs (3,247 → 1,605 lines) into focused
domain modules:

- diff_commands.rs (484 lines) — diff computation for local/remote branches
- review_commands.rs (143 lines) — code review CRUD operations
- timeline.rs (371 lines) — branch timeline construction and commit/review deletion
- image_commands.rs (255 lines) — image upload, retrieval, and management
- note_commands.rs (90 lines) — note CRUD for branches and projects
- github_commands.rs (139 lines) — GitHub/git API wrappers for the frontend
- util_commands.rs (212 lines) — open-in-app, preferences, blox auth, etc.

What stays in lib.rs:
- Managed state (DbState, StoreIncompatibility)
- Database migration helpers
- Store status commands (get_store_status, confirm_reset_store)
- Project commands (CRUD, repo management, delete with cleanup)
- Action commands (repo action CRUD)
- Frontend-facing timeline types (BranchTimeline, etc.)
- get_store helper (now pub(crate))
- Tauri app setup (run function)
- Tests for cleanup_project_branches_best_effort

All invoke_handler paths updated to use module-qualified names.
No functional changes — just reorganization.
Extract ~2,150 lines from BranchCard.svelte (3,161 → 1,000 lines) into
focused components and a reactive module:

- BranchCardActionsBar.svelte (~860 lines) — running action buttons,
  primary run action button/pill, more dropdown menu with Actions and
  Open In submenus, action status event listeners
- BranchCardPrButton.svelte (~540 lines) — PR creation/push button,
  PR status polling, push/PR error/force-push dialogs, option-key
  tracking for draft PRs
- BranchCardSessionManager.svelte.ts (~285 lines) — session creation
  logic, pending session items, auto review adoption/cancellation,
  new session modal state

BranchCard.svelte remains as the coordinator (~1,000 lines):
- Props and local/remote derivation
- Timeline loading and review detail fetching
- Central session-status-changed event listener (dispatches to child
  components via refs/callbacks)
- Timeline item click/delete handlers and modal state
- Drag-and-drop handling
- Card layout template and remaining styles

No functional changes — pure reorganization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The BranchCardPrButton extraction changed the unpushed commits effect
to depend on `hasCodeChanges` (a boolean) instead of `timeline` (the
full object). This meant the check wouldn't re-trigger on every
timeline refresh, diverging from the original behavior. Pass `timeline`
as a prop and use it as the effect dependency, matching the original.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e82899fe92

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (foundUrl) {
const prNumber = extractPrNumber(foundUrl);
if (prNumber) {
commands.updateBranchPr(branch.id, prNumber);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Await PR persistence before marking PR created

In handlePrSessionComplete, commands.updateBranchPr(branch.id, prNumber) is no longer awaited, so failures to persist the PR number are silently ignored while prStateStore.setPrCreated still runs. If that write fails (for example due to a transient DB error), the UI reports a created PR but the branch record is left without pr_number, which breaks PR linkage after reload and leaves status refresh paths inconsistent.

Useful? React with 👍 / 👎.

`PR creation session ${status === 'error' ? 'failed' : 'was cancelled'}.`
);
}
prStateStore.clearSessionTracking(branch.id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer clearing PR session tracking until completion work ends

prStateStore.clearSessionTracking(branch.id) runs immediately after kicking off async message parsing, but this component also has fallback polling (commands.getSession in the $effect above) and the parent completion listener can call handlePrSessionComplete too. A second completion callback that arrives while the first promise is still in flight will see sid as null and take the cancellation error path, producing incorrect error state despite a successful PR session.

Useful? React with 👍 / 👎.

- Narrow mime_type_for_extension to private (only used in image_commands)
- Narrow build_branch_timeline to private (only used in timeline)
- Revert unintentional rename_all addition on delete_project command
- Remove dead onPrSessionComplete/onPushSessionComplete props and call
  sites from BranchCardPrButton (parent uses bind:this instead)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@matt2e matt2e force-pushed the long-files-refactor branch from e82899f to aff06f2 Compare March 12, 2026 04:45
- Await `commands.updateBranchPr` in `handlePrSessionComplete` so DB
  write failures propagate to the error state instead of being silently
  ignored, preventing PR linkage from breaking after reload.
- Add re-entrance guards (`prCompletionInFlight` / `pushCompletionInFlight`)
  to both completion handlers so a second callback arriving while the
  first is still in-flight is dropped rather than seeing a null session
  ID and incorrectly entering the cancellation/error path.
- Convert both handlers from fire-and-forget `.then()` chains to
  async/await with try/finally for clearer control flow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@matt2e matt2e merged commit ba06535 into main Mar 12, 2026
3 checks passed
@matt2e matt2e deleted the long-files-refactor branch March 12, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant