Skip to content

feat(ai): add AI-assisted conflict resolution#21

Merged
dubscode merged 2 commits into
mainfrom
feat/ai-resolve
Mar 8, 2026
Merged

feat(ai): add AI-assisted conflict resolution#21
dubscode merged 2 commits into
mainfrom
feat/ai-resolve

Conversation

@dubscode
Copy link
Copy Markdown
Contributor

@dubscode dubscode commented Mar 8, 2026

Summary

  • Adds dub ai resolve command that uses Gemini (via Vercel AI SDK) to analyze and resolve git merge conflicts during rebase/restack operations
  • Adds dub continue --ai shorthand that detects unresolved conflicts and invokes AI resolution before continuing
  • Interactive review flow: batch apply-all, per-file review (apply/skip/abort), or dry-run preview with unified diffs
  • Security: path traversal validation, duplicate path detection, fail-closed prompt loops
  • Resilience: scope warnings for large conflict sets, 1 automatic retry on continued conflicts, SIGINT-safe with conflict state preservation

New files

  • src/commands/ai-resolve.ts — core command orchestration
  • src/lib/conflict-context.ts — gathers conflict state (files, markers, git log, restack progress)
  • src/lib/conflict-ui.ts — diff computation, interactive prompts, resolution application

Test plan

  • 9 unit tests for ai-resolve (dry-run, abort, apply-all, review individually, scope warning, retry)
  • 5 integration tests for conflict-context (real git repos with actual rebase conflicts)
  • 9 unit tests for conflict-ui (diff computation, path validation, batch preview)
  • 2 tests for continue --ai flag
  • pnpm checks clean (biome lint + format)
  • pnpm typecheck clean
  • All 364 tests passing

Copilot AI review requested due to automatic review settings March 8, 2026 02:52
- `dub ai resolve` command w/ Gemini via Vercel AI SDK
- `dub continue --ai` shorthand for conflict detection + resolution
- Interactive batch/per-file review with unified diff preview
- Scope warnings for large conflict sets (>10 files, >5000 lines)
- Path traversal & duplicate resolution validation
- 1 automatic retry on continued conflicts, then hand back to user
- Dry-run mode and abort support
- SIGINT-safe with conflict state preservation
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an AI-assisted merge conflict resolver to DubStack, integrating Gemini via the Vercel AI SDK and wiring it into the CLI as dub ai resolve plus an optional dub continue --ai flow.

Changes:

  • Introduces dub ai resolve with interactive apply/review/abort and dry-run diff previews.
  • Adds conflict context collection (conflicted files, markers, relevant git log, restack progress) for prompting.
  • Extends dub continue with --ai to invoke AI resolution when unresolved conflicts are detected.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/lib/conflict-ui.ts Implements diff preview rendering, interactive prompting, path validation, and applying resolutions.
src/lib/conflict-ui.test.ts Adds unit tests for diffing, preview output, and applying resolutions.
src/lib/conflict-context.ts Collects conflict state and contextual metadata for AI prompting.
src/lib/conflict-context.test.ts Adds integration-style tests using real repos/rebase conflicts.
src/index.ts Registers dub ai resolve and adds dub continue --ai flag.
src/commands/continue.ts Implements --ai probe + delegation to AI resolver.
src/commands/continue.test.ts Tests continueCommand behavior with --ai.
src/commands/ai-resolve.ts Orchestrates AI streaming, parsing, interactive flow, retry, and continue/abort integration.
src/commands/ai-resolve.test.ts Adds unit tests for aiResolve orchestration and flows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/conflict-ui.ts
Comment thread src/lib/conflict-ui.ts Outdated
Comment thread src/lib/conflict-context.ts
Comment thread src/commands/continue.ts Outdated
Comment thread src/commands/ai-resolve.ts Outdated
Comment thread src/index.ts Outdated
Comment thread src/lib/conflict-ui.test.ts Outdated
…lidation

- Add symlink rejection + ENOENT check in applyResolution
- Add symlink/path.resolve guard in gatherConflictContext
- Cap computeDiff at 3000 lines to prevent OOM on large files
- Use `git add --` to prevent option injection from filenames
- Wrap --ai conflict probe in try/catch for consistent DubError
- Validate parseResolutions array elements are objects
- Fix --abort flag description to mention restack
@dubscode dubscode merged commit 2d1adce into main Mar 8, 2026
3 checks passed
@dubscode dubscode deleted the feat/ai-resolve branch March 8, 2026 03:01
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.

2 participants