feat(ui): merge action and robust jump-to-task in worktrees overview

Add Merge entry to the worktrees overview context menu wiring the existing
MergeModalViewModel, replace fire-and-forget list selection with a
collection-change-aware JumpToTaskHelper, and propagate list renames to
visible task rows via a new ListUpdated event.

Harden worktree state changes: WorkerHub.SetWorktreeState now rejects
invalid transitions, WorktreeMaintenanceService only drops the DB row when
the on-disk worktree was actually removed, and Cleanup/Reset broadcast
WorktreeUpdated for affected tasks. SetWorktreeStateAsync returns the hub
error message so the modal can surface it.

Also: de-duplicate the worktrees overview modal opener, hook
OnParentTaskIdChanged to refresh IsDraft, fix MergeModal CanExecute
notifications, and add WorktreeStateHubTests for the transition rules.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-05-27 13:43:39 +02:00
parent 2223839595
commit 967e0cd319
18 changed files with 416 additions and 53 deletions

View File

@@ -0,0 +1,42 @@
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using ClaudeDo.Ui.ViewModels;
namespace ClaudeDo.Ui.Views;
internal static class JumpToTaskHelper
{
// Selects the list, then waits for the matching task row to appear in Tasks.Items.
// Listens to CollectionChanged so it works regardless of how long LoadForListAsync takes;
// bounded by a hard timeout so we never hang if the task is filtered out.
public static async Task SelectAsync(IslandsShellViewModel s, string listId, string taskId)
{
if (s.Lists is null || s.Tasks is null) return;
var item = s.Lists.UserLists.FirstOrDefault(l => l.Id == $"user:{listId}");
if (item is null) return;
s.Lists.SelectedList = item;
var existing = s.Tasks.Items.FirstOrDefault(r => r.Id == taskId);
if (existing is not null) { s.Tasks.SelectedTask = existing; return; }
var tcs = new TaskCompletionSource<bool>();
void OnChanged(object? _, NotifyCollectionChangedEventArgs __)
{
var row = s.Tasks!.Items.FirstOrDefault(r => r.Id == taskId);
if (row is not null) tcs.TrySetResult(true);
}
s.Tasks.Items.CollectionChanged += OnChanged;
try
{
await Task.WhenAny(tcs.Task, Task.Delay(5000));
var row = s.Tasks.Items.FirstOrDefault(r => r.Id == taskId);
if (row is not null) s.Tasks.SelectedTask = row;
}
finally
{
s.Tasks.Items.CollectionChanged -= OnChanged;
}
}
}