feat(ui): add conflict resolution dialog for planning merge-all

Opens a modal when PlanningMergeConflict fires, listing conflicted files
with options to open in VS Code, continue, or abort the merge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-04-24 18:08:45 +02:00
parent a6ebff3f34
commit bc788e1e0f
7 changed files with 382 additions and 1 deletions

View File

@@ -55,6 +55,8 @@ public partial class WorkerClient : ObservableObject, IAsyncDisposable, IWorkerC
public event Action<string>? PlanningMergeAbortedEvent; public event Action<string>? PlanningMergeAbortedEvent;
public event Action<string>? PlanningCompletedEvent; public event Action<string>? PlanningCompletedEvent;
public string? LastMergeAllTarget { get; private set; }
public WorkerClient(string signalRUrl) public WorkerClient(string signalRUrl)
{ {
_hub = new HubConnectionBuilder() _hub = new HubConnectionBuilder()
@@ -420,6 +422,7 @@ public partial class WorkerClient : ObservableObject, IAsyncDisposable, IWorkerC
public async Task MergeAllPlanningAsync(string planningTaskId, string targetBranch) public async Task MergeAllPlanningAsync(string planningTaskId, string targetBranch)
{ {
LastMergeAllTarget = targetBranch;
await _hub.InvokeAsync("MergeAllPlanning", planningTaskId, targetBranch); await _hub.InvokeAsync("MergeAllPlanning", planningTaskId, targetBranch);
} }

View File

@@ -4,9 +4,12 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using ClaudeDo.Data;
using ClaudeDo.Data.Models; using ClaudeDo.Data.Models;
using ClaudeDo.Ui.Services; using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Islands; using ClaudeDo.Ui.ViewModels.Islands;
using ClaudeDo.Ui.ViewModels.Planning;
using Microsoft.EntityFrameworkCore;
namespace ClaudeDo.Ui.ViewModels; namespace ClaudeDo.Ui.ViewModels;
@@ -27,6 +30,10 @@ public sealed partial class IslandsShellViewModel : ViewModelBase
private readonly UpdateCheckService _updateCheck; private readonly UpdateCheckService _updateCheck;
private readonly InstallerLocator _installerLocator; private readonly InstallerLocator _installerLocator;
private readonly IDbContextFactory<ClaudeDoDbContext>? _dbFactory;
// Set by MainWindow to open the conflict resolution dialog.
public Func<ConflictResolutionViewModel, Task>? ShowConflictDialog { get; set; }
[ObservableProperty] private bool _isUpdateBannerVisible; [ObservableProperty] private bool _isUpdateBannerVisible;
[ObservableProperty] private string? _updateBannerLatestVersion; [ObservableProperty] private string? _updateBannerLatestVersion;
@@ -84,6 +91,47 @@ public sealed partial class IslandsShellViewModel : ViewModelBase
WorkerLogText = null; WorkerLogText = null;
} }
private void OnPlanningMergeConflict(string planningTaskId, string subtaskId, IReadOnlyList<string> conflictedFiles)
{
// Already on UI thread (WorkerClient dispatches via Dispatcher.UIThread.Post).
_ = OpenConflictDialogAsync(planningTaskId, subtaskId, conflictedFiles);
}
private async Task OpenConflictDialogAsync(string planningTaskId, string subtaskId, IReadOnlyList<string> conflictedFiles)
{
if (ShowConflictDialog == null || _dbFactory == null) return;
string subtaskTitle = subtaskId;
string worktreePath = System.Environment.CurrentDirectory;
string targetBranch = Worker?.LastMergeAllTarget ?? "main";
try
{
await using var ctx = await _dbFactory.CreateDbContextAsync();
var entity = await ctx.Tasks
.Include(t => t.Worktree)
.AsNoTracking()
.FirstOrDefaultAsync(t => t.Id == subtaskId);
if (entity != null)
{
subtaskTitle = entity.Title;
if (entity.Worktree?.Path is { } p)
worktreePath = p;
}
}
catch { /* Non-fatal: fall back to subtaskId and cwd */ }
var vm = new ConflictResolutionViewModel(
Worker!,
planningTaskId,
subtaskTitle,
targetBranch,
conflictedFiles,
worktreePath);
await ShowConflictDialog(vm);
}
// For tests only — does NOT wire up events. // For tests only — does NOT wire up events.
internal IslandsShellViewModel() { } internal IslandsShellViewModel() { }
@@ -93,11 +141,13 @@ public sealed partial class IslandsShellViewModel : ViewModelBase
DetailsIslandViewModel details, DetailsIslandViewModel details,
WorkerClient worker, WorkerClient worker,
UpdateCheckService updateCheck, UpdateCheckService updateCheck,
InstallerLocator installerLocator) InstallerLocator installerLocator,
IDbContextFactory<ClaudeDoDbContext> dbFactory)
{ {
Lists = lists; Tasks = tasks; Details = details; Worker = worker; Lists = lists; Tasks = tasks; Details = details; Worker = worker;
_updateCheck = updateCheck; _updateCheck = updateCheck;
_installerLocator = installerLocator; _installerLocator = installerLocator;
_dbFactory = dbFactory;
Lists.SelectionChanged += (_, _) => Tasks.LoadForList(Lists.SelectedList); Lists.SelectionChanged += (_, _) => Tasks.LoadForList(Lists.SelectedList);
Tasks.SelectionChanged += (_, _) => Details.Bind(Tasks.SelectedTask); Tasks.SelectionChanged += (_, _) => Details.Bind(Tasks.SelectedTask);
Tasks.TasksChanged += (_, _) => _ = Lists.RefreshCountsAsync(); Tasks.TasksChanged += (_, _) => _ = Lists.RefreshCountsAsync();
@@ -122,6 +172,7 @@ public sealed partial class IslandsShellViewModel : ViewModelBase
} }
}; };
Worker.WorkerLogReceivedEvent += OnWorkerLogReceived; Worker.WorkerLogReceivedEvent += OnWorkerLogReceived;
Worker.PlanningMergeConflictEvent += OnPlanningMergeConflict;
_clearTimer.Elapsed += (_, _) => _clearTimer.Elapsed += (_, _) =>
{ {
if (Dispatcher.UIThread.CheckAccess()) if (Dispatcher.UIThread.CheckAccess())

View File

@@ -0,0 +1,83 @@
using System.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ClaudeDo.Ui.Services;
namespace ClaudeDo.Ui.ViewModels.Planning;
public sealed partial class ConflictResolutionViewModel : ObservableObject
{
private readonly IWorkerClient _worker;
private readonly string _planningTaskId;
private readonly string _worktreePath;
public string SubtaskTitle { get; }
public string TargetBranch { get; }
public IReadOnlyList<string> ConflictedFiles { get; }
[ObservableProperty] private string? _vsCodeError;
[ObservableProperty] private string? _actionError;
public Action? CloseRequested { get; set; }
public ConflictResolutionViewModel(
IWorkerClient worker,
string planningTaskId,
string subtaskTitle,
string targetBranch,
IReadOnlyList<string> conflictedFiles,
string worktreePath)
{
_worker = worker;
_planningTaskId = planningTaskId;
_worktreePath = worktreePath;
SubtaskTitle = subtaskTitle;
TargetBranch = targetBranch;
ConflictedFiles = conflictedFiles;
}
[RelayCommand]
private void OpenInVsCode()
{
try
{
var args = string.Join(" ", ConflictedFiles.Select(f => $"\"{f}\""));
Process.Start(new ProcessStartInfo
{
FileName = "code",
Arguments = args,
WorkingDirectory = _worktreePath,
UseShellExecute = true,
});
VsCodeError = null;
}
catch (Exception ex)
{
VsCodeError = $"Could not launch VS Code: {ex.Message}. Paths are listed above — copy them manually.";
}
}
[RelayCommand]
private async Task ContinueAsync()
{
ActionError = null;
try
{
await _worker.ContinuePlanningMergeAsync(_planningTaskId);
CloseRequested?.Invoke();
}
catch (Exception ex) { ActionError = ex.Message; }
}
[RelayCommand]
private async Task AbortAsync()
{
ActionError = null;
try
{
await _worker.AbortPlanningMergeAsync(_planningTaskId);
CloseRequested?.Invoke();
}
catch (Exception ex) { ActionError = ex.Message; }
}
}

View File

@@ -1,6 +1,7 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using ClaudeDo.Ui.ViewModels; using ClaudeDo.Ui.ViewModels;
using ClaudeDo.Ui.Views.Planning;
namespace ClaudeDo.Ui.Views; namespace ClaudeDo.Ui.Views;
@@ -10,6 +11,19 @@ public partial class MainWindow : Window
{ {
InitializeComponent(); InitializeComponent();
KeyDown += OnWindowKeyDown; KeyDown += OnWindowKeyDown;
DataContextChanged += OnDataContextChanged;
}
private void OnDataContextChanged(object? sender, EventArgs e)
{
if (DataContext is IslandsShellViewModel vm)
{
vm.ShowConflictDialog = async (conflictVm) =>
{
var modal = new ConflictResolutionView { DataContext = conflictVm };
await modal.ShowDialog(this);
};
}
} }
private void OnWindowKeyDown(object? sender, KeyEventArgs e) private void OnWindowKeyDown(object? sender, KeyEventArgs e)

View File

@@ -0,0 +1,65 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Planning"
x:DataType="vm:ConflictResolutionViewModel"
x:Class="ClaudeDo.Ui.Views.Planning.ConflictResolutionView"
Title="Merge conflict"
Width="560" SizeToContent="Height"
SystemDecorations="None"
ExtendClientAreaToDecorationsHint="True"
WindowStartupLocation="CenterOwner"
Background="{StaticResource SurfaceBrush}">
<Window.KeyBindings>
<KeyBinding Gesture="Escape" Command="{Binding AbortCommand}"/>
</Window.KeyBindings>
<Border Background="{StaticResource SurfaceBrush}"
BorderBrush="{StaticResource LineBrush}"
BorderThickness="1">
<Grid RowDefinitions="36,*">
<!-- Title bar / drag handle -->
<Border Grid.Row="0"
x:Name="TitleBar"
Background="{StaticResource Surface2Brush}"
BorderBrush="{StaticResource LineBrush}"
BorderThickness="0,0,0,1"
PointerPressed="TitleBar_PointerPressed">
<Grid ColumnDefinitions="*,Auto" Margin="14,0">
<TextBlock Text="Merge conflict"
VerticalAlignment="Center"
FontFamily="{StaticResource MonoFamily}"
FontSize="12"
Foreground="{StaticResource TextDimBrush}"/>
</Grid>
</Border>
<!-- Content -->
<StackPanel Grid.Row="1" Spacing="12" Margin="16" MinWidth="520">
<TextBlock FontWeight="SemiBold" FontSize="16"
Text="{Binding SubtaskTitle, StringFormat='Conflicts in subtask: {0}'}"/>
<TextBlock Text="{Binding TargetBranch, StringFormat='Merging into: {0}'}" Opacity="0.7"/>
<ItemsControl ItemsSource="{Binding ConflictedFiles}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontFamily="Consolas,Menlo,monospace"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Text="{Binding VsCodeError}" Foreground="OrangeRed"
IsVisible="{Binding VsCodeError, Converter={x:Static ObjectConverters.IsNotNull}}"
TextWrapping="Wrap"/>
<TextBlock Text="{Binding ActionError}" Foreground="OrangeRed"
IsVisible="{Binding ActionError, Converter={x:Static ObjectConverters.IsNotNull}}"
TextWrapping="Wrap"/>
<StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right" Margin="0,4,0,4">
<Button Content="Open all in VS Code" Command="{Binding OpenInVsCodeCommand}"/>
<Button Content="I've resolved — continue" Command="{Binding ContinueCommand}"/>
<Button Content="Abort this merge" Command="{Binding AbortCommand}"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Window>

View File

@@ -0,0 +1,26 @@
using Avalonia.Controls;
using Avalonia.Input;
using ClaudeDo.Ui.ViewModels.Planning;
namespace ClaudeDo.Ui.Views.Planning;
public partial class ConflictResolutionView : Window
{
public ConflictResolutionView()
{
InitializeComponent();
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is ConflictResolutionViewModel vm)
vm.CloseRequested = Close;
}
private void TitleBar_PointerPressed(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
}

View File

@@ -0,0 +1,139 @@
using System.ComponentModel;
using ClaudeDo.Data.Models;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Planning;
namespace ClaudeDo.Ui.Tests.ViewModels;
public class ConflictResolutionViewModelTests
{
// ------------------------------------------------------------------ fake
private sealed class FakeWorker : IWorkerClient
{
public bool IsConnected => false;
public string? ContinueCalledWith { get; private set; }
public string? AbortCalledWith { get; private set; }
public Exception? ContinueThrows { get; set; }
public Exception? AbortThrows { get; set; }
public event PropertyChangedEventHandler? PropertyChanged;
public event Action<string, string, DateTime>? TaskStartedEvent;
public event Action<string, string, string, DateTime>? TaskFinishedEvent;
public event Action<string>? TaskUpdatedEvent;
public event Action<string>? WorktreeUpdatedEvent;
public event Action<string, string>? TaskMessageEvent;
public event Action<string, string>? PlanningMergeStartedEvent;
public event Action<string, string>? PlanningSubtaskMergedEvent;
public event Action<string, string, IReadOnlyList<string>>? PlanningMergeConflictEvent;
public event Action<string>? PlanningMergeAbortedEvent;
public event Action<string>? PlanningCompletedEvent;
public Task WakeQueueAsync() => Task.CompletedTask;
public Task RunNowAsync(string taskId) => Task.CompletedTask;
public Task ContinueTaskAsync(string taskId, string followUpPrompt) => Task.CompletedTask;
public Task ResetTaskAsync(string taskId) => Task.CompletedTask;
public Task CancelTaskAsync(string taskId) => Task.CompletedTask;
public Task<List<AgentInfo>> GetAgentsAsync() => Task.FromResult(new List<AgentInfo>());
public Task<ListConfigDto?> GetListConfigAsync(string listId) => Task.FromResult<ListConfigDto?>(null);
public Task UpdateTaskAgentSettingsAsync(UpdateTaskAgentSettingsDto dto) => Task.CompletedTask;
public Task StartPlanningSessionAsync(string taskId, CancellationToken ct = default) => Task.CompletedTask;
public Task ResumePlanningSessionAsync(string taskId, CancellationToken ct = default) => Task.CompletedTask;
public Task DiscardPlanningSessionAsync(string taskId, CancellationToken ct = default) => Task.CompletedTask;
public Task FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks = true, CancellationToken ct = default) => Task.CompletedTask;
public Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct = default) => Task.FromResult(0);
public Task<MergeTargetsDto?> GetMergeTargetsAsync(string taskId) => Task.FromResult<MergeTargetsDto?>(null);
public Task<IReadOnlyList<SubtaskDiffDto>> GetPlanningAggregateAsync(string planningTaskId) =>
Task.FromResult<IReadOnlyList<SubtaskDiffDto>>(Array.Empty<SubtaskDiffDto>());
public Task<CombinedDiffResultDto?> BuildPlanningIntegrationBranchAsync(string planningTaskId, string targetBranch) =>
Task.FromResult<CombinedDiffResultDto?>(null);
public Task MergeAllPlanningAsync(string planningTaskId, string targetBranch) => Task.CompletedTask;
public Task ContinuePlanningMergeAsync(string planningTaskId)
{
ContinueCalledWith = planningTaskId;
if (ContinueThrows is not null) throw ContinueThrows;
return Task.CompletedTask;
}
public Task AbortPlanningMergeAsync(string planningTaskId)
{
AbortCalledWith = planningTaskId;
if (AbortThrows is not null) throw AbortThrows;
return Task.CompletedTask;
}
}
private static ConflictResolutionViewModel BuildVm(FakeWorker worker, string planningTaskId = "plan-1") =>
new ConflictResolutionViewModel(
worker,
planningTaskId,
subtaskTitle: "My subtask",
targetBranch: "main",
conflictedFiles: new[] { "src/Foo.cs", "src/Bar.cs" },
worktreePath: "C:/worktrees/plan-1");
// ------------------------------------------------------------------ tests
[Fact]
public async Task ContinueAsync_CallsHub_AndClosesOnSuccess()
{
var worker = new FakeWorker();
var vm = BuildVm(worker, "plan-42");
bool closeCalled = false;
vm.CloseRequested = () => closeCalled = true;
await vm.ContinueCommand.ExecuteAsync(null);
Assert.Equal("plan-42", worker.ContinueCalledWith);
Assert.True(closeCalled);
Assert.Null(vm.ActionError);
}
[Fact]
public async Task ContinueAsync_HubThrows_ShowsActionErrorAndStaysOpen()
{
var worker = new FakeWorker { ContinueThrows = new InvalidOperationException("hub down") };
var vm = BuildVm(worker);
bool closeCalled = false;
vm.CloseRequested = () => closeCalled = true;
await vm.ContinueCommand.ExecuteAsync(null);
Assert.False(closeCalled);
Assert.Equal("hub down", vm.ActionError);
}
[Fact]
public async Task AbortAsync_CallsHub_AndClosesOnSuccess()
{
var worker = new FakeWorker();
var vm = BuildVm(worker, "plan-99");
bool closeCalled = false;
vm.CloseRequested = () => closeCalled = true;
await vm.AbortCommand.ExecuteAsync(null);
Assert.Equal("plan-99", worker.AbortCalledWith);
Assert.True(closeCalled);
Assert.Null(vm.ActionError);
}
[Fact]
public async Task AbortAsync_HubThrows_ShowsActionError()
{
var worker = new FakeWorker { AbortThrows = new InvalidOperationException("abort failed") };
var vm = BuildVm(worker);
bool closeCalled = false;
vm.CloseRequested = () => closeCalled = true;
await vm.AbortCommand.ExecuteAsync(null);
Assert.False(closeCalled);
Assert.Equal("abort failed", vm.ActionError);
}
// OpenInVsCode is not unit-tested here because abstracting Process.Start
// would require an indirection layer that isn't part of the approved design.
// The error path is covered by the VsCodeError property being set on catch.
}