Skip to content

feat(domain): add git rebase-on-main with agent-powered conflict resolution and sync-main#396

Merged
arielshad merged 25 commits intomainfrom
feat/git-rebase-sync
Mar 22, 2026
Merged

feat(domain): add git rebase-on-main with agent-powered conflict resolution and sync-main#396
arielshad merged 25 commits intomainfrom
feat/git-rebase-sync

Conversation

@arielshad
Copy link
Contributor

@arielshad arielshad commented Mar 16, 2026

Summary

  • Rebase feature on main — adds rebaseOnMain() to IGitPrService that rebases a feature branch onto origin/<baseBranch> with automatic agent-powered conflict resolution. Before rebasing, the system syncs the remote-tracking ref and verifies the worktree is clean. When conflicts are detected, an AI agent iteratively resolves them (up to 3 retries per commit), validates no conflict markers remain, stages resolved files, and continues the rebase. Falls back to git rebase --abort if the agent cannot resolve.
  • Sync main with remote — adds syncMain() to IGitPrService that fetches the latest remote state. Works from any branch: uses git fetch origin <baseBranch> when on a feature branch (updates only origin/<baseBranch>, avoids touching the local branch ref), or git pull --ff-only when on the base branch. This design prevents the "refusing to fetch into branch checked out at..." error when main is checked out in another worktree.
  • New error codes — extends GitPrErrorCode enum with REBASE_CONFLICT and SYNC_FAILED for precise programmatic error handling.
  • Use cases — adds RebaseFeatureOnMainUseCase (resolves feature, worktree path, invokes sync + rebase with conflict resolution) and SyncRepositoryMainUseCase (resolves repository, invokes sync).
  • Agent-powered conflict resolutionConflictResolutionService orchestrates agentic resolution via IAgentExecutorProvider: detects conflicted files, invokes AI agent with conflict context (file contents, branch info, markers), validates resolution, retries up to 3 times per commit, aborts on exhaustion.
  • Web UI support — adds server actions (rebaseFeature, syncRepository), action hooks, and UI buttons. Feature drawer overview tab shows a "Rebase on Main" button under a BRANCH SYNC section. Repository drawer shows a "Sync Main" button under GIT OPERATIONS. Both actions delegate to existing use cases via DI.
  • Feature flag gated — all git rebase & sync UI is hidden behind the gitRebaseSync feature flag, configurable from the Settings page.
  • Full spec lifecycle — includes spec analysis, requirements, research with technology decisions, implementation plan, task breakdown, and implementation across all four architecture layers (domain, application, infrastructure, presentation).

Key Fix (Iteration 4)

The syncMain method previously used git fetch origin main:main which fails with fatal: refusing to fetch into branch 'refs/heads/main' checked out at '/path/to/repo' when the main branch is checked out in the primary worktree. Now uses git fetch origin main (updates only the remote-tracking ref origin/main) and rebaseOnMain targets origin/<baseBranch> directly. This correctly supports git worktree workflows where the main branch is checked out in the primary repo.

Evidence

Feature Flag in Settings

Settings feature flag

Repository Drawer — Sync Main

Repository drawer with Sync Main

Feature Drawer — Branch Sync Status & Rebase on Main

Behind (with Rebase button) Up to Date Rebasing Rebase Error
Behind Up to date Rebasing Rebase error

Overview Tab with Rebase Action

Overview tab with branch sync and rebase

Loading State

Loading sync status

Test Evidence

  • Unit tests — 63 tests passing across 5 feature-specific test files: GitPrService rebase/sync (34), ConflictResolutionService (6), conflict resolution prompt builder (10), RebaseFeatureOnMainUseCase (9), SyncRepositoryMainUseCase (4)
  • Integration tests — 16 tests passing against real temporary git repos: syncMain (6, including worktree-safe fetch and diverged-from-feature-branch), rebaseOnMain (7), helper methods (3)
  • Full test suite — 318 unit test files (4082 tests), 42 integration test files (500 tests), zero regressions
  • Validation — lint, format, typecheck, TypeSpec compilation all pass
  • Build — compiles without errors

Test plan

  • Unit tests for GitPrService.rebaseOnMain: clean rebase, conflict detection, dirty worktree rejection, rebases onto origin/main
  • Unit tests for GitPrService.syncMain: fetch from feature branch (worktree-safe), pull from main, diverged rejection, error classification
  • Unit tests for ConflictResolutionService: successful resolution, retry logic, abort on max retries
  • Unit tests for RebaseFeatureOnMainUseCase: happy path, feature not found, sync failure, conflict resolution flow
  • Unit tests for SyncRepositoryMainUseCase: happy path, repo not found, sync failure propagation
  • Integration tests: syncMain succeeds from feature branch even when local main diverged (new test), rebase uses origin/main
  • Web UI: server actions, hooks, and action buttons for rebase and sync wired correctly
  • Storybook stories updated for BranchSyncStatus (all states), OverviewTab (rebase with sync), RepositoryDrawer (with git operations)
  • All existing unit and integration tests continue to pass (no regressions)
  • Build compiles without errors
  • Lint passes with zero warnings

🤖 Generated with Claude Code

@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.123.0-pr396.f99e785 npm install -g @shepai/cli@1.123.0-pr396.f99e785

Published from commit cf9bf25 | View CI

@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.123.0-pr396.ac74a97 npm install -g @shepai/cli@1.123.0-pr396.ac74a97

Published from commit 4d9ad80 | View CI

@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.123.0-pr396.072b95e npm install -g @shepai/cli@1.123.0-pr396.072b95e

Published from commit abe495f | View CI

@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.124.0-pr396.2dd2ae6 npm install -g @shepai/cli@1.124.0-pr396.2dd2ae6

Published from commit 74bd52f | View CI

arielshad and others added 17 commits March 17, 2026 18:25
…-sync

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ents

Address rejection feedback: conflict resolution should be automatic with
agents instead of abort-and-report. Updated question 2 to use agent-powered
resolution with iterative retry loop and abort fallback. Added new FRs for
agent conflict resolution (FR-6 through FR-13), new NFR for cost control,
new open question for max retries, and bumped size estimate to L.
…base-sync

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ebase-sync

Populates research.yaml with 8 structured technology decisions covering
conflict resolution architecture, agent invocation patterns, git operations
layer, error handling strategy, sync main strategy, prompt design, worktree
support, and retry strategy. Each decision includes context, options with
pros/cons, chosen option, and rationale grounded in codebase patterns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend GitPrErrorCode with REBASE_CONFLICT and SYNC_FAILED codes for
rebase conflict detection and sync failure classification. Add six new
method signatures to IGitPrService: syncMain, rebaseOnMain,
getConflictedFiles, stageFiles, rebaseContinue, rebaseAbort. Add stub
implementations to GitPrService for compilation. Update interface tests
to cover all 11 error codes and 26 methods. Update all test mocks that
type-check against IGitPrService.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement syncMain, rebaseOnMain, getConflictedFiles, stageFiles,
rebaseContinue, and rebaseAbort methods on GitPrService. Extend
parseGitError with REBASE_CONFLICT and SYNC_FAILED classification.
Add comprehensive unit tests covering all methods and error paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e and sync

Add application layer for git rebase-on-main and sync-main operations:
- ConflictResolutionService with iterative agent-powered conflict
  resolution loop (3 retries per commit, abort fallback)
- RebaseFeatureOnMainUseCase with auto-sync, worktree support, and
  conflict resolution delegation
- SyncRepositoryMainUseCase with repo resolution and default branch
  detection
- DI container registrations with class and string-token aliases
- Conflict resolution prompt builder following merge-prompts pattern
- 29 unit tests covering all new code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Integration tests for syncMain and rebaseOnMain against real temporary
git repositories. Covers clean sync, diverged main, idempotent sync,
clean rebase, conflict detection, dirty worktree, branch-not-found,
conflict resolution helpers, and linear history verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-rebase-sync

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ations

Add server actions, action hooks, and UI buttons for rebase-on-main and
sync-main operations in the web UI. Feature drawer overview tab shows a
"Rebase on Main" button under GIT OPERATIONS. Repository drawer shows a
"Sync Main" button. Both actions wire through existing use cases via DI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…actions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ktrees

syncMain now uses `git fetch origin <branch>` instead of
`git fetch origin <branch>:<branch>` when on a different branch,
avoiding the "refusing to fetch into branch checked out at..." error
when main is checked out in another worktree. rebaseOnMain now targets
`origin/<baseBranch>` instead of the local ref, ensuring the rebase
always uses the freshly-fetched remote state. Also adds detection for
the "Not possible to fast-forward" error message from git pull.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `as unknown as` casts to IFeatureRepository and IWorktreeService
mocks in rebase use case test to prevent type errors when the
interfaces are extended by other branches during CI merge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tibility

Add syncMain, rebaseOnMain, getConflictedFiles, stageFiles,
rebaseContinue, rebaseAbort mocks to adopt-branch test and
findByRemoteUrl, update mocks to sync-repository test to match
extended interfaces after rebase onto main.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arielshad arielshad force-pushed the feat/git-rebase-sync branch from e07e490 to 469cb84 Compare March 17, 2026 16:29
@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.129.2-pr396.29a046b npm install -g @shepai/cli@1.129.2-pr396.29a046b

Published from commit 469cb84 | View CI

Add a new git-rebase-sync feature flag (disabled by default) that controls
visibility of the rebase on main and sync main ui operations. The flag
is configurable from the settings page under feature flags. When disabled,
the git operations sections are hidden from feature and repository drawers.

Changes span all layers: typespec model, sqlite migration (042), settings
mapper, defaults factory, feature-flags lib and context, settings page ui,
drawer components, and all related tests and stories.

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

Dev Release Published

Artifact Version Install
npm 1.129.3-pr396.d3c115b npm install -g @shepai/cli@1.129.3-pr396.d3c115b

Published from commit fcd777f | View CI

the get-graph-data cache skipped computing behindCount when
currentBranch === defaultBranch, always setting it to 0. this
meant local main behind origin/main was never shown in the ui.
remove the branch equality guard so rev-list runs for all branches
including main itself. also remove the sha-based early return so
behind count is recomputed on every ttl refresh even when head
has not changed.

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

Dev Release Published

Artifact Version Install
npm 1.129.4-pr396.5d604d5 npm install -g @shepai/cli@1.129.4-pr396.5d604d5

Published from commit dfd3edd | View CI

@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.130.1-pr396.844e95f npm install -g @shepai/cli@1.130.1-pr396.844e95f

Published from commit 3ba9a7d | View CI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t version

Port fixes from main to resolve E2E Docker test failure: the generated
next.config.mjs was missing output:"standalone" causing Next.js server
startup crash in production, and the next dependency is pinned to 16.1.6
to prevent unexpected breaking changes from minor updates.

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

Dev Release Published

Artifact Version Install
npm 1.134.1-pr396.fe65c43 npm install -g @shepai/cli@1.134.1-pr396.fe65c43

Published from commit 5107a96 | View CI

arielshad and others added 2 commits March 20, 2026 22:57
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add getBranchSyncStatus method to IGitPrService interface and GitPrService
- Create GetBranchSyncStatusUseCase with remote sync before status check
- Register use case in DI container with string-token alias
- Create server action and storybook mock for get-branch-sync-status
- Add rebase phase timing to RebaseFeatureOnMainUseCase (standalone agent run)
- Add 'rebase' to NODE_TO_PHASE map in activity tab
- Create useBranchSyncStatus hook with 30s TTL module-level cache
- Create BranchSyncStatus component replacing FeatureGitOperations
- Update overview-tab, feature-drawer-tabs, and feature-drawer-client
- Auto-refresh sync status after successful rebase
- Add unit tests for service, use case, and component

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.136.0-pr396.e077930 npm install -g @shepai/cli@1.136.0-pr396.e077930

Published from commit b603e44 | View CI

…ature

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

Dev Release Published

Artifact Version Install
npm 1.136.0-pr396.3419613 npm install -g @shepai/cli@1.136.0-pr396.3419613

Published from commit 53b6247 | View CI

@arielshad arielshad merged commit d4cfb72 into main Mar 22, 2026
34 of 35 checks passed
@arielshad arielshad deleted the feat/git-rebase-sync branch March 22, 2026 11:43
blackpc pushed a commit that referenced this pull request Mar 22, 2026
# [1.137.0](v1.136.1...v1.137.0) (2026-03-22)

### Features

* **domain:** add git rebase-on-main with agent-powered conflict resolution and sync-main ([#396](#396)) ([d4cfb72](d4cfb72))
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