Compare commits
16 Commits
feat/plann
...
77f7cf1423
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77f7cf1423 | ||
|
|
84e6c2d5fc | ||
|
|
84b0ba8670 | ||
|
|
b6bec1e63c | ||
|
|
b32621a4e5 | ||
| 993851009b | |||
|
|
450e685580 | ||
|
|
0e116bec7b | ||
|
|
47b49743c0 | ||
|
|
506caa2c53 | ||
|
|
388a8c1fae | ||
|
|
42b208ff28 | ||
|
|
309f84b388 | ||
|
|
00608401aa | ||
|
|
229d4bbb2b | ||
| 845359b885 |
19
docs/open.md
19
docs/open.md
@@ -207,3 +207,22 @@ Preconditions: a working Gitea release at `git.kuns.dev/releases/ClaudeDo` with
|
|||||||
7. Repeat step 6 with **Continue anyway** → wizard opens without self-update.
|
7. Repeat step 6 with **Continue anyway** → wizard opens without self-update.
|
||||||
8. Repeat step 6 with **Cancel** → installer exits without any action.
|
8. Repeat step 6 with **Cancel** → installer exits without any action.
|
||||||
9. Kill network during startup in both app and installer → confirm silent fallback (no errors, no banner, wizard opens normally).
|
9. Kill network during startup in both app and installer → confirm silent fallback (no errors, no banner, wizard opens normally).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Planning Sessions — Manual Verification (Plan C UI)
|
||||||
|
|
||||||
|
Requires Plan B (worker hub endpoints) merged. Until then, only the UI structure/styling checks are meaningful.
|
||||||
|
|
||||||
|
1. Create a Manual task with a title and a TODO-ish description.
|
||||||
|
2. Right-click the task → **Open planning Session** — Windows Terminal opens with Claude CLI running (Plan B).
|
||||||
|
3. Ask Claude to create two child tasks via `mcp__claudedo__create_child_task`.
|
||||||
|
4. Watch the UI: drafts appear indented under the parent, italic, reduced opacity, with a `DRAFT` badge.
|
||||||
|
5. The parent shows a `PLANNING` badge. Click the chevron → children collapse; click again → children expand.
|
||||||
|
6. Ask Claude to `finalize` — drafts flip to Manual/Queued children; parent flips to `PLANNED` badge.
|
||||||
|
7. In a new planning task, close the terminal without finalize. Right-click the Planning task → the unfinished-session modal opens with Resume / Finalize now / Discard.
|
||||||
|
8. Attempt to delete a parent with children via the details panel — confirm the friendly error dialog appears and the task is NOT deleted.
|
||||||
|
|
||||||
|
**Known followups (non-blocking):**
|
||||||
|
- `Border.badge.planned` style (blue) is defined in `IslandStyles.axaml` but never applied — `TaskRowView` keeps the `planning` class for both Planning and Planned, so Planned gets the amber badge. Either make the view swap `Classes.planned` when status is Planned, or remove the unused style + brush.
|
||||||
|
- Dead `Instance` statics on `BoolToItalicConverter` and `BoolToDraftOpacityConverter` — App.axaml registers instances via the resource dictionary; the static members can be removed.
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
<converters:UpperCaseConverter x:Key="UpperCase"/>
|
<converters:UpperCaseConverter x:Key="UpperCase"/>
|
||||||
<converters:IconKeyConverter x:Key="IconKey"/>
|
<converters:IconKeyConverter x:Key="IconKey"/>
|
||||||
<converters:DotBrushConverter x:Key="DotBrush"/>
|
<converters:DotBrushConverter x:Key="DotBrush"/>
|
||||||
|
<converters:BoolToItalicConverter x:Key="BoolToItalic"/>
|
||||||
|
<converters:BoolToDraftOpacityConverter x:Key="BoolToDraftOpacity"/>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
@@ -8,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace ClaudeDo.Data.Migrations
|
namespace ClaudeDo.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(ClaudeDoDbContext))]
|
||||||
|
[Migration("20260416064948_InitialCreate")]
|
||||||
public partial class InitialCreate : Migration
|
public partial class InitialCreate : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace ClaudeDo.Data.Migrations
|
namespace ClaudeDo.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(ClaudeDoDbContext))]
|
||||||
|
[Migration("20260420075929_AddTaskFlagsAndNotes")]
|
||||||
public partial class AddTaskFlagsAndNotes : Migration
|
public partial class AddTaskFlagsAndNotes : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace ClaudeDo.Data.Migrations
|
namespace ClaudeDo.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(ClaudeDoDbContext))]
|
||||||
|
[Migration("20260421113614_AddAppSettings")]
|
||||||
public partial class AddAppSettings : Migration
|
public partial class AddAppSettings : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
@@ -5,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace ClaudeDo.Data.Migrations
|
namespace ClaudeDo.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(ClaudeDoDbContext))]
|
||||||
|
[Migration("20260422120000_AddTaskSortOrder")]
|
||||||
public partial class AddTaskSortOrder : Migration
|
public partial class AddTaskSortOrder : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
@@ -6,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace ClaudeDo.Data.Migrations
|
namespace ClaudeDo.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(ClaudeDoDbContext))]
|
||||||
|
[Migration("20260423154708_AddPlanningSupport")]
|
||||||
public partial class AddPlanningSupport : Migration
|
public partial class AddPlanningSupport : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<InternalsVisibleTo Include="ClaudeDo.Ui.Tests" />
|
<InternalsVisibleTo Include="ClaudeDo.Ui.Tests" />
|
||||||
|
<InternalsVisibleTo Include="ClaudeDo.Worker.Tests" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
15
src/ClaudeDo.Ui/Converters/BoolToDraftOpacityConverter.cs
Normal file
15
src/ClaudeDo.Ui/Converters/BoolToDraftOpacityConverter.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.Converters;
|
||||||
|
|
||||||
|
public sealed class BoolToDraftOpacityConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public static BoolToDraftOpacityConverter Instance { get; } = new();
|
||||||
|
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is true ? 0.7 : 1.0;
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> throw new NotSupportedException();
|
||||||
|
}
|
||||||
16
src/ClaudeDo.Ui/Converters/BoolToItalicConverter.cs
Normal file
16
src/ClaudeDo.Ui/Converters/BoolToItalicConverter.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.Converters;
|
||||||
|
|
||||||
|
public sealed class BoolToItalicConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public static BoolToItalicConverter Instance { get; } = new();
|
||||||
|
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is true ? FontStyle.Italic : FontStyle.Normal;
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> throw new NotSupportedException();
|
||||||
|
}
|
||||||
@@ -84,6 +84,11 @@
|
|||||||
<!-- Icon.Settings (gear) -->
|
<!-- Icon.Settings (gear) -->
|
||||||
<StreamGeometry x:Key="Icon.Settings">M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65a.5.5 0 0 0 .12-.64l-2-3.46a.5.5 0 0 0-.61-.22l-2.49 1a7.03 7.03 0 0 0-1.69-.98l-.38-2.65a.5.5 0 0 0-.5-.42h-4a.5.5 0 0 0-.5.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1a.5.5 0 0 0-.61.22l-2 3.46a.5.5 0 0 0 .12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65a.5.5 0 0 0-.12.64l2 3.46a.5.5 0 0 0 .61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65a.5.5 0 0 0 .5.42h4a.5.5 0 0 0 .5-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1a.5.5 0 0 0 .61-.22l2-3.46a.5.5 0 0 0-.12-.64l-2.11-1.65z</StreamGeometry>
|
<StreamGeometry x:Key="Icon.Settings">M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8z M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65a.5.5 0 0 0 .12-.64l-2-3.46a.5.5 0 0 0-.61-.22l-2.49 1a7.03 7.03 0 0 0-1.69-.98l-.38-2.65a.5.5 0 0 0-.5-.42h-4a.5.5 0 0 0-.5.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1a.5.5 0 0 0-.61.22l-2 3.46a.5.5 0 0 0 .12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65a.5.5 0 0 0-.12.64l2 3.46a.5.5 0 0 0 .61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65a.5.5 0 0 0 .5.42h4a.5.5 0 0 0 .5-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1a.5.5 0 0 0 .61-.22l2-3.46a.5.5 0 0 0-.12-.64l-2.11-1.65z</StreamGeometry>
|
||||||
|
|
||||||
|
<!-- Badge brushes -->
|
||||||
|
<SolidColorBrush x:Key="DraftBadgeBrush" Color="#4A5568"/>
|
||||||
|
<SolidColorBrush x:Key="PlanningBadgeBrush" Color="#D69E2E"/>
|
||||||
|
<SolidColorBrush x:Key="PlannedBadgeBrush" Color="#3182CE"/>
|
||||||
|
|
||||||
</Styles.Resources>
|
</Styles.Resources>
|
||||||
|
|
||||||
<!-- ============================================================ -->
|
<!-- ============================================================ -->
|
||||||
@@ -866,4 +871,31 @@
|
|||||||
<Setter Property="Foreground" Value="{StaticResource BloodBrush}" />
|
<Setter Property="Foreground" Value="{StaticResource BloodBrush}" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<!-- ============================================================ -->
|
||||||
|
<!-- PLANNING / DRAFT BADGES -->
|
||||||
|
<!-- ============================================================ -->
|
||||||
|
<Style Selector="Border.badge">
|
||||||
|
<Setter Property="CornerRadius" Value="3"/>
|
||||||
|
<Setter Property="Padding" Value="4,1"/>
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Border.badge > TextBlock">
|
||||||
|
<Setter Property="FontSize" Value="9"/>
|
||||||
|
<Setter Property="FontWeight" Value="Bold"/>
|
||||||
|
<Setter Property="Foreground" Value="White"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Border.badge.draft">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource DraftBadgeBrush}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Border.badge.planning">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource PlanningBadgeBrush}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Border.badge.planned">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource PlannedBadgeBrush}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
</Styles>
|
</Styles>
|
||||||
|
|||||||
11
src/ClaudeDo.Ui/Services/IWorkerClient.cs
Normal file
11
src/ClaudeDo.Ui/Services/IWorkerClient.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace ClaudeDo.Ui.Services;
|
||||||
|
|
||||||
|
public interface IWorkerClient
|
||||||
|
{
|
||||||
|
Task WakeQueueAsync();
|
||||||
|
Task StartPlanningSessionAsync(string taskId, CancellationToken ct = default);
|
||||||
|
Task ResumePlanningSessionAsync(string taskId, CancellationToken ct = default);
|
||||||
|
Task DiscardPlanningSessionAsync(string taskId, CancellationToken ct = default);
|
||||||
|
Task FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks = true, CancellationToken ct = default);
|
||||||
|
Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct = default);
|
||||||
|
}
|
||||||
18
src/ClaudeDo.Ui/Services/PlanningDtos.cs
Normal file
18
src/ClaudeDo.Ui/Services/PlanningDtos.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace ClaudeDo.Ui.Services;
|
||||||
|
|
||||||
|
public sealed record PlanningSessionFilesDto(
|
||||||
|
string SessionDirectory,
|
||||||
|
string McpConfigPath,
|
||||||
|
string SystemPromptPath,
|
||||||
|
string InitialPromptPath);
|
||||||
|
|
||||||
|
public sealed record PlanningSessionStartInfo(
|
||||||
|
string ParentTaskId,
|
||||||
|
string WorkingDir,
|
||||||
|
PlanningSessionFilesDto Files);
|
||||||
|
|
||||||
|
public sealed record PlanningSessionResumeInfo(
|
||||||
|
string ParentTaskId,
|
||||||
|
string WorkingDir,
|
||||||
|
string ClaudeSessionId,
|
||||||
|
string McpConfigPath);
|
||||||
@@ -25,7 +25,7 @@ sealed class IndefiniteRetryPolicy : IRetryPolicy
|
|||||||
_delays[Math.Min(retryContext.PreviousRetryCount, _delays.Length - 1)];
|
_delays[Math.Min(retryContext.PreviousRetryCount, _delays.Length - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class WorkerClient : ObservableObject, IAsyncDisposable
|
public partial class WorkerClient : ObservableObject, IAsyncDisposable, IWorkerClient
|
||||||
{
|
{
|
||||||
private readonly HubConnection _hub;
|
private readonly HubConnection _hub;
|
||||||
private CancellationTokenSource? _startCts;
|
private CancellationTokenSource? _startCts;
|
||||||
@@ -347,6 +347,33 @@ public partial class WorkerClient : ObservableObject, IAsyncDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PlanningSessionStartInfo> StartPlanningSessionAsync(string taskId, CancellationToken ct = default)
|
||||||
|
=> await _hub.InvokeAsync<PlanningSessionStartInfo>("StartPlanningSessionAsync", taskId, ct);
|
||||||
|
|
||||||
|
public async Task<PlanningSessionResumeInfo> ResumePlanningSessionAsync(string taskId, CancellationToken ct = default)
|
||||||
|
=> await _hub.InvokeAsync<PlanningSessionResumeInfo>("ResumePlanningSessionAsync", taskId, ct);
|
||||||
|
|
||||||
|
public async Task DiscardPlanningSessionAsync(string taskId, CancellationToken ct = default)
|
||||||
|
=> await _hub.InvokeAsync("DiscardPlanningSessionAsync", taskId, ct);
|
||||||
|
|
||||||
|
public async Task<int> FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks = true, CancellationToken ct = default)
|
||||||
|
=> await _hub.InvokeAsync<int>("FinalizePlanningSessionAsync", taskId, queueAgentTasks, ct);
|
||||||
|
|
||||||
|
public async Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct = default)
|
||||||
|
=> await _hub.InvokeAsync<int>("GetPendingDraftCountAsync", taskId, ct);
|
||||||
|
|
||||||
|
// IWorkerClient explicit implementations (drop typed return values)
|
||||||
|
async Task IWorkerClient.StartPlanningSessionAsync(string taskId, CancellationToken ct)
|
||||||
|
=> await StartPlanningSessionAsync(taskId, ct);
|
||||||
|
async Task IWorkerClient.ResumePlanningSessionAsync(string taskId, CancellationToken ct)
|
||||||
|
=> await ResumePlanningSessionAsync(taskId, ct);
|
||||||
|
async Task IWorkerClient.DiscardPlanningSessionAsync(string taskId, CancellationToken ct)
|
||||||
|
=> await DiscardPlanningSessionAsync(taskId, ct);
|
||||||
|
async Task IWorkerClient.FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks, CancellationToken ct)
|
||||||
|
=> await FinalizePlanningSessionAsync(taskId, queueAgentTasks, ct);
|
||||||
|
async Task<int> IWorkerClient.GetPendingDraftCountAsync(string taskId, CancellationToken ct)
|
||||||
|
=> await GetPendingDraftCountAsync(taskId, ct);
|
||||||
|
|
||||||
// DTOs for deserializing hub responses
|
// DTOs for deserializing hub responses
|
||||||
private sealed class ActiveTaskDto
|
private sealed class ActiveTaskDto
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
|||||||
// Set by the view so DeleteTaskCommand can prompt yes/no before deleting
|
// Set by the view so DeleteTaskCommand can prompt yes/no before deleting
|
||||||
public Func<string, System.Threading.Tasks.Task<bool>>? ConfirmAsync { get; set; }
|
public Func<string, System.Threading.Tasks.Task<bool>>? ConfirmAsync { get; set; }
|
||||||
|
|
||||||
|
// Set by the view so DeleteTaskCommand can show an error message
|
||||||
|
public Func<string, System.Threading.Tasks.Task>? ShowErrorAsync { get; set; }
|
||||||
|
|
||||||
public DetailsIslandViewModel(IDbContextFactory<ClaudeDoDbContext> dbFactory, WorkerClient worker, IServiceProvider services)
|
public DetailsIslandViewModel(IDbContextFactory<ClaudeDoDbContext> dbFactory, WorkerClient worker, IServiceProvider services)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
@@ -537,9 +540,20 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
|||||||
var ok = await ConfirmAsync($"Delete \"{row.Title}\"? This cannot be undone.");
|
var ok = await ConfirmAsync($"Delete \"{row.Title}\"? This cannot be undone.");
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
await using var ctx = _dbFactory.CreateDbContext();
|
await using var ctx = _dbFactory.CreateDbContext();
|
||||||
var repo = new TaskRepository(ctx);
|
var repo = new TaskRepository(ctx);
|
||||||
await repo.DeleteAsync(row.Id);
|
await repo.DeleteAsync(row.Id);
|
||||||
|
}
|
||||||
|
catch (DbUpdateException ex) when (
|
||||||
|
ex.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| ex.InnerException?.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase) == true)
|
||||||
|
{
|
||||||
|
if (ShowErrorAsync != null)
|
||||||
|
await ShowErrorAsync("This task has child tasks. Discard the planning session or delete child tasks first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (DeleteFromList != null)
|
if (DeleteFromList != null)
|
||||||
await DeleteFromList(row);
|
await DeleteFromList(row);
|
||||||
CloseDetail?.Invoke();
|
CloseDetail?.Invoke();
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public sealed partial class TaskRowViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private int _diffDeletions;
|
[ObservableProperty] private int _diffDeletions;
|
||||||
[ObservableProperty] private bool _dropHintAbove;
|
[ObservableProperty] private bool _dropHintAbove;
|
||||||
[ObservableProperty] private bool _dropHintBelow;
|
[ObservableProperty] private bool _dropHintBelow;
|
||||||
|
[ObservableProperty] private string? _parentTaskId;
|
||||||
|
[ObservableProperty] private bool _isExpanded = true;
|
||||||
|
|
||||||
public DateTime CreatedAt { get; init; }
|
public DateTime CreatedAt { get; init; }
|
||||||
public string CreatedAtFormatted => CreatedAt == default ? "—" : $"Created {CreatedAt:MMM d}";
|
public string CreatedAtFormatted => CreatedAt == default ? "—" : $"Created {CreatedAt:MMM d}";
|
||||||
@@ -31,6 +33,20 @@ public sealed partial class TaskRowViewModel : ViewModelBase
|
|||||||
public int StepsCount { get; init; }
|
public int StepsCount { get; init; }
|
||||||
public int StepsCompleted { get; init; }
|
public int StepsCompleted { get; init; }
|
||||||
|
|
||||||
|
public bool IsChild => !string.IsNullOrEmpty(ParentTaskId);
|
||||||
|
public bool IsPlanningParent => Status == TaskStatus.Planning || Status == TaskStatus.Planned;
|
||||||
|
public bool IsDraft => Status == TaskStatus.Draft;
|
||||||
|
|
||||||
|
public bool CanOpenPlanningSession => Status == TaskStatus.Manual && !IsChild;
|
||||||
|
public bool CanResumeOrDiscardPlanning => Status == TaskStatus.Planning;
|
||||||
|
|
||||||
|
public string? PlanningBadge => Status switch
|
||||||
|
{
|
||||||
|
TaskStatus.Planning => "PLANNING",
|
||||||
|
TaskStatus.Planned => "PLANNED",
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
public bool HasBranch => !string.IsNullOrWhiteSpace(Branch);
|
public bool HasBranch => !string.IsNullOrWhiteSpace(Branch);
|
||||||
public bool HasDiff => DiffAdditions > 0 || DiffDeletions > 0;
|
public bool HasDiff => DiffAdditions > 0 || DiffDeletions > 0;
|
||||||
public bool HasTags => Tags.Count > 0;
|
public bool HasTags => Tags.Count > 0;
|
||||||
@@ -60,6 +76,17 @@ public sealed partial class TaskRowViewModel : ViewModelBase
|
|||||||
OnPropertyChanged(nameof(IsRunning));
|
OnPropertyChanged(nameof(IsRunning));
|
||||||
OnPropertyChanged(nameof(IsQueued));
|
OnPropertyChanged(nameof(IsQueued));
|
||||||
OnPropertyChanged(nameof(HasLiveTail));
|
OnPropertyChanged(nameof(HasLiveTail));
|
||||||
|
OnPropertyChanged(nameof(IsPlanningParent));
|
||||||
|
OnPropertyChanged(nameof(PlanningBadge));
|
||||||
|
OnPropertyChanged(nameof(IsDraft));
|
||||||
|
OnPropertyChanged(nameof(CanOpenPlanningSession));
|
||||||
|
OnPropertyChanged(nameof(CanResumeOrDiscardPlanning));
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnParentTaskIdChanged(string? value)
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(IsChild));
|
||||||
|
OnPropertyChanged(nameof(CanOpenPlanningSession));
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void OnBranchChanged(string? value) => OnPropertyChanged(nameof(HasBranch));
|
partial void OnBranchChanged(string? value) => OnPropertyChanged(nameof(HasBranch));
|
||||||
@@ -91,6 +118,7 @@ public sealed partial class TaskRowViewModel : ViewModelBase
|
|||||||
DiffAdditions = add,
|
DiffAdditions = add,
|
||||||
DiffDeletions = del,
|
DiffDeletions = del,
|
||||||
CreatedAt = t.CreatedAt,
|
CreatedAt = t.CreatedAt,
|
||||||
|
ParentTaskId = t.ParentTaskId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using CommunityToolkit.Mvvm.Input;
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Models;
|
using ClaudeDo.Data.Models;
|
||||||
using ClaudeDo.Ui.Services;
|
using ClaudeDo.Ui.Services;
|
||||||
|
using ClaudeDo.Ui.ViewModels.Modals;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||||
|
|
||||||
@@ -13,7 +14,8 @@ namespace ClaudeDo.Ui.ViewModels.Islands;
|
|||||||
public sealed partial class TasksIslandViewModel : ViewModelBase
|
public sealed partial class TasksIslandViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||||
private readonly WorkerClient? _worker;
|
private readonly IWorkerClient? _worker;
|
||||||
|
private readonly Dictionary<string, bool> _expandedState = new();
|
||||||
private ListNavItemViewModel? _currentList;
|
private ListNavItemViewModel? _currentList;
|
||||||
private CancellationTokenSource? _loadCts;
|
private CancellationTokenSource? _loadCts;
|
||||||
|
|
||||||
@@ -41,7 +43,9 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private bool _showOpenLabel;
|
[ObservableProperty] private bool _showOpenLabel;
|
||||||
[ObservableProperty] private string _completedHeader = "COMPLETED";
|
[ObservableProperty] private string _completedHeader = "COMPLETED";
|
||||||
|
|
||||||
public TasksIslandViewModel(IDbContextFactory<ClaudeDoDbContext> dbFactory, WorkerClient? worker = null)
|
public Func<UnfinishedPlanningModalViewModel, Task>? ShowUnfinishedPlanningModal { get; set; }
|
||||||
|
|
||||||
|
public TasksIslandViewModel(IDbContextFactory<ClaudeDoDbContext> dbFactory, IWorkerClient? worker = null)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
_worker = worker;
|
_worker = worker;
|
||||||
@@ -105,14 +109,35 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
|
|||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Regroup()
|
internal void Regroup()
|
||||||
{
|
{
|
||||||
OverdueItems.Clear();
|
OverdueItems.Clear();
|
||||||
OpenItems.Clear();
|
OpenItems.Clear();
|
||||||
CompletedItems.Clear();
|
CompletedItems.Clear();
|
||||||
|
|
||||||
var today = DateTime.Today;
|
// Restore IsExpanded from saved state
|
||||||
foreach (var r in Items)
|
foreach (var r in Items)
|
||||||
|
{
|
||||||
|
if (_expandedState.TryGetValue(r.Id, out var saved))
|
||||||
|
r.IsExpanded = saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build hierarchy-aware flat list: top-level rows interleaved with visible children.
|
||||||
|
// Items is already ordered by SortOrder from the DB query.
|
||||||
|
var topLevel = Items.Where(r => !r.IsChild);
|
||||||
|
var flat = new List<TaskRowViewModel>();
|
||||||
|
foreach (var parent in topLevel)
|
||||||
|
{
|
||||||
|
flat.Add(parent);
|
||||||
|
if (parent.IsPlanningParent && parent.IsExpanded)
|
||||||
|
{
|
||||||
|
var children = Items.Where(r => r.ParentTaskId == parent.Id);
|
||||||
|
flat.AddRange(children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var today = DateTime.Today;
|
||||||
|
foreach (var r in flat)
|
||||||
{
|
{
|
||||||
if (r.Done)
|
if (r.Done)
|
||||||
CompletedItems.Add(r);
|
CompletedItems.Add(r);
|
||||||
@@ -356,6 +381,79 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void OpenListSettings() => OpenListSettingsRequested?.Invoke(this, EventArgs.Empty);
|
private void OpenListSettings() => OpenListSettingsRequested?.Invoke(this, EventArgs.Empty);
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task OpenPlanningSessionAsync(TaskRowViewModel? row)
|
||||||
|
{
|
||||||
|
if (row is null || row.Status != TaskStatus.Manual) return;
|
||||||
|
try { await _worker!.StartPlanningSessionAsync(row.Id); }
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task ResumePlanningSessionAsync(TaskRowViewModel? row)
|
||||||
|
{
|
||||||
|
if (row is null || !row.IsPlanningParent) return;
|
||||||
|
if (_worker is null) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var draftCount = await _worker.GetPendingDraftCountAsync(row.Id);
|
||||||
|
var modalVm = new UnfinishedPlanningModalViewModel
|
||||||
|
{
|
||||||
|
TaskTitle = row.Title,
|
||||||
|
DraftCount = draftCount,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ShowUnfinishedPlanningModal is null)
|
||||||
|
return;
|
||||||
|
await ShowUnfinishedPlanningModal(modalVm);
|
||||||
|
|
||||||
|
var choice = await modalVm.Result.Task;
|
||||||
|
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case UnfinishedPlanningModalResult.Resume:
|
||||||
|
await _worker.ResumePlanningSessionAsync(row.Id);
|
||||||
|
break;
|
||||||
|
case UnfinishedPlanningModalResult.FinalizeNow:
|
||||||
|
await _worker.FinalizePlanningSessionAsync(row.Id);
|
||||||
|
break;
|
||||||
|
case UnfinishedPlanningModalResult.Discard:
|
||||||
|
await _worker.DiscardPlanningSessionAsync(row.Id);
|
||||||
|
break;
|
||||||
|
case UnfinishedPlanningModalResult.Cancel:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task DiscardPlanningSessionAsync(TaskRowViewModel? row)
|
||||||
|
{
|
||||||
|
if (row is null) return;
|
||||||
|
try { await _worker!.DiscardPlanningSessionAsync(row.Id); }
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task FinalizePlanningSessionAsync(TaskRowViewModel? row)
|
||||||
|
{
|
||||||
|
if (row is null) return;
|
||||||
|
try { await _worker!.FinalizePlanningSessionAsync(row.Id, queueAgentTasks: true); }
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void ToggleExpand(TaskRowViewModel? row)
|
||||||
|
{
|
||||||
|
if (row is null) return;
|
||||||
|
var next = !(_expandedState.TryGetValue(row.Id, out var current) ? current : row.IsExpanded);
|
||||||
|
_expandedState[row.Id] = next;
|
||||||
|
row.IsExpanded = next;
|
||||||
|
Regroup();
|
||||||
|
}
|
||||||
|
|
||||||
partial void OnSelectedTaskChanged(TaskRowViewModel? value)
|
partial void OnSelectedTaskChanged(TaskRowViewModel? value)
|
||||||
{
|
{
|
||||||
foreach (var i in Items) i.IsSelected = ReferenceEquals(i, value);
|
foreach (var i in Items) i.IsSelected = ReferenceEquals(i, value);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.ViewModels.Modals;
|
||||||
|
|
||||||
|
public enum UnfinishedPlanningModalResult
|
||||||
|
{
|
||||||
|
Cancel,
|
||||||
|
Resume,
|
||||||
|
FinalizeNow,
|
||||||
|
Discard,
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed partial class UnfinishedPlanningModalViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
[ObservableProperty] private string _taskTitle = "";
|
||||||
|
[ObservableProperty] private int _draftCount;
|
||||||
|
|
||||||
|
public TaskCompletionSource<UnfinishedPlanningModalResult> Result { get; } = new();
|
||||||
|
public Action? CloseAction { get; set; }
|
||||||
|
|
||||||
|
[RelayCommand] private void Resume() { Result.TrySetResult(UnfinishedPlanningModalResult.Resume); CloseAction?.Invoke(); }
|
||||||
|
[RelayCommand] private void FinalizeNow() { Result.TrySetResult(UnfinishedPlanningModalResult.FinalizeNow); CloseAction?.Invoke(); }
|
||||||
|
[RelayCommand] private void Discard() { Result.TrySetResult(UnfinishedPlanningModalResult.Discard); CloseAction?.Invoke(); }
|
||||||
|
[RelayCommand] private void Cancel() { Result.TrySetResult(UnfinishedPlanningModalResult.Cancel); CloseAction?.Invoke(); }
|
||||||
|
}
|
||||||
@@ -45,9 +45,49 @@ public partial class DetailsIslandView : UserControl
|
|||||||
};
|
};
|
||||||
|
|
||||||
vm.ConfirmAsync = ShowConfirmAsync;
|
vm.ConfirmAsync = ShowConfirmAsync;
|
||||||
|
vm.ShowErrorAsync = ShowErrorDialogAsync;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async System.Threading.Tasks.Task ShowErrorDialogAsync(string message)
|
||||||
|
{
|
||||||
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||||
|
if (owner == null) return;
|
||||||
|
|
||||||
|
var ok = new Button { Content = "OK", MinWidth = 90 };
|
||||||
|
|
||||||
|
var dialog = new Window
|
||||||
|
{
|
||||||
|
Title = "Error",
|
||||||
|
Width = 360,
|
||||||
|
SizeToContent = SizeToContent.Height,
|
||||||
|
CanResize = false,
|
||||||
|
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||||
|
ShowInTaskbar = false,
|
||||||
|
Background = this.FindResource("SurfaceBrush") as IBrush,
|
||||||
|
Content = new StackPanel
|
||||||
|
{
|
||||||
|
Spacing = 16,
|
||||||
|
Margin = new Thickness(20),
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
|
||||||
|
new StackPanel
|
||||||
|
{
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
Spacing = 8,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Right,
|
||||||
|
Children = { ok }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ok.Click += (_, _) => dialog.Close();
|
||||||
|
|
||||||
|
await dialog.ShowDialog(owner);
|
||||||
|
}
|
||||||
|
|
||||||
private async System.Threading.Tasks.Task<bool> ShowConfirmAsync(string message)
|
private async System.Threading.Tasks.Task<bool> ShowConfirmAsync(string message)
|
||||||
{
|
{
|
||||||
var owner = TopLevel.GetTopLevel(this) as Window;
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||||
|
|||||||
@@ -15,7 +15,17 @@
|
|||||||
Background="{DynamicResource MossBrush}" CornerRadius="1"
|
Background="{DynamicResource MossBrush}" CornerRadius="1"
|
||||||
IsVisible="{Binding DropHintAbove}"/>
|
IsVisible="{Binding DropHintAbove}"/>
|
||||||
|
|
||||||
<Border Grid.Row="1" Classes="task-row"
|
<!-- Indent wrapper: col 0 = 24px child indent track, col 1 = content -->
|
||||||
|
<Grid Grid.Row="1" ColumnDefinitions="Auto,*">
|
||||||
|
|
||||||
|
<!-- Indent track (only visible for child tasks) -->
|
||||||
|
<Border Grid.Column="0" Width="24" IsVisible="{Binding IsChild}" VerticalAlignment="Stretch">
|
||||||
|
<Rectangle Width="1" Fill="{DynamicResource LineBrush}"
|
||||||
|
HorizontalAlignment="Right" Margin="0,4"/>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- Main task card -->
|
||||||
|
<Border Grid.Column="1" Classes="task-row"
|
||||||
Margin="0"
|
Margin="0"
|
||||||
Classes.selected="{Binding IsSelected}"
|
Classes.selected="{Binding IsSelected}"
|
||||||
Classes.done="{Binding Done}">
|
Classes.done="{Binding Done}">
|
||||||
@@ -28,16 +38,45 @@
|
|||||||
IsVisible="{Binding IsQueued}"
|
IsVisible="{Binding IsQueued}"
|
||||||
Click="OnRemoveFromQueueClick"/>
|
Click="OnRemoveFromQueueClick"/>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
|
<MenuItem Header="Open planning Session"
|
||||||
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).OpenPlanningSessionCommand}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
IsVisible="{Binding CanOpenPlanningSession}"/>
|
||||||
|
<MenuItem Header="Resume planning Session"
|
||||||
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ResumePlanningSessionCommand}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
IsVisible="{Binding CanResumeOrDiscardPlanning}"/>
|
||||||
|
<MenuItem Header="Discard planning session"
|
||||||
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).DiscardPlanningSessionCommand}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
IsVisible="{Binding CanResumeOrDiscardPlanning}"/>
|
||||||
|
<Separator/>
|
||||||
<MenuItem Header="Schedule for..." Click="OnScheduleForClick"/>
|
<MenuItem Header="Schedule for..." Click="OnScheduleForClick"/>
|
||||||
<MenuItem Header="Clear schedule"
|
<MenuItem Header="Clear schedule"
|
||||||
IsVisible="{Binding HasSchedule}"
|
IsVisible="{Binding HasSchedule}"
|
||||||
Click="OnClearScheduleClick"/>
|
Click="OnClearScheduleClick"/>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</Border.ContextMenu>
|
</Border.ContextMenu>
|
||||||
<Grid ColumnDefinitions="0,32,*,32" Margin="6,8,10,8">
|
<Grid ColumnDefinitions="0,18,32,*,Auto,32" Margin="6,8,10,8">
|
||||||
|
|
||||||
|
<!-- Chevron toggle (only for planning parent tasks) -->
|
||||||
|
<Button Grid.Column="1"
|
||||||
|
IsVisible="{Binding IsPlanningParent}"
|
||||||
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ToggleExpandCommand}"
|
||||||
|
CommandParameter="{Binding}"
|
||||||
|
Classes="icon-btn"
|
||||||
|
Width="18" Height="18"
|
||||||
|
VerticalAlignment="Center">
|
||||||
|
<Panel>
|
||||||
|
<TextBlock Text="▾" FontSize="10" IsVisible="{Binding IsExpanded}"
|
||||||
|
VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||||
|
<TextBlock Text="▸" FontSize="10" IsVisible="{Binding !IsExpanded}"
|
||||||
|
VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||||
|
</Panel>
|
||||||
|
</Button>
|
||||||
|
|
||||||
<!-- Done toggle -->
|
<!-- Done toggle -->
|
||||||
<Button Grid.Column="1" Classes="flat" VerticalAlignment="Top"
|
<Button Grid.Column="2" Classes="flat" VerticalAlignment="Top"
|
||||||
Margin="0,2,0,0"
|
Margin="0,2,0,0"
|
||||||
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ToggleDoneCommand}"
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ToggleDoneCommand}"
|
||||||
CommandParameter="{Binding}">
|
CommandParameter="{Binding}">
|
||||||
@@ -46,12 +85,26 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Title + chip row + live tail -->
|
<!-- Title + chip row + live tail -->
|
||||||
<StackPanel Grid.Column="2" Spacing="6" VerticalAlignment="Center">
|
<StackPanel Grid.Column="3" Spacing="6" VerticalAlignment="Center">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="4" VerticalAlignment="Center">
|
||||||
<TextBlock Classes="task-title"
|
<TextBlock Classes="task-title"
|
||||||
Text="{Binding Title}" FontSize="14"
|
Text="{Binding Title}" FontSize="14"
|
||||||
Foreground="{DynamicResource TextBrush}"
|
Foreground="{DynamicResource TextBrush}"
|
||||||
|
FontStyle="{Binding IsDraft, Converter={StaticResource BoolToItalic}}"
|
||||||
|
Opacity="{Binding IsDraft, Converter={StaticResource BoolToDraftOpacity}}"
|
||||||
TextDecorations="{Binding Done, Converter={StaticResource StrikeIfTrue}}"/>
|
TextDecorations="{Binding Done, Converter={StaticResource StrikeIfTrue}}"/>
|
||||||
|
|
||||||
|
<!-- Badges: DRAFT and planning session -->
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="4" VerticalAlignment="Center">
|
||||||
|
<Border Classes="badge draft" IsVisible="{Binding IsDraft}">
|
||||||
|
<TextBlock Text="DRAFT"/>
|
||||||
|
</Border>
|
||||||
|
<Border Classes="badge planning" IsVisible="{Binding IsPlanningParent}">
|
||||||
|
<TextBlock Text="{Binding PlanningBadge}"/>
|
||||||
|
</Border>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<!-- Chip row -->
|
<!-- Chip row -->
|
||||||
<StackPanel Orientation="Horizontal" Spacing="6">
|
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||||
|
|
||||||
@@ -134,7 +187,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- Star toggle -->
|
<!-- Star toggle -->
|
||||||
<Button Grid.Column="3" Classes="icon-btn star-btn"
|
<Button Grid.Column="5" Classes="icon-btn star-btn"
|
||||||
Classes.on="{Binding IsStarred}"
|
Classes.on="{Binding IsStarred}"
|
||||||
VerticalAlignment="Top" Margin="0,2,0,0"
|
VerticalAlignment="Top" Margin="0,2,0,0"
|
||||||
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ToggleStarCommand}"
|
Command="{Binding $parent[ItemsControl].((vm:TasksIslandViewModel)DataContext).ToggleStarCommand}"
|
||||||
@@ -144,6 +197,8 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<!-- Below-row indicator: only expands when visible (used for the last row of a section) -->
|
<!-- Below-row indicator: only expands when visible (used for the last row of a section) -->
|
||||||
<Grid Grid.Row="2" Height="6" IsVisible="{Binding DropHintBelow}">
|
<Grid Grid.Row="2" Height="6" IsVisible="{Binding DropHintBelow}">
|
||||||
<Border Height="2" VerticalAlignment="Center" Margin="4,0"
|
<Border Height="2" VerticalAlignment="Center" Margin="4,0"
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Avalonia.Input;
|
|||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
using ClaudeDo.Ui.ViewModels.Islands;
|
using ClaudeDo.Ui.ViewModels.Islands;
|
||||||
|
using ClaudeDo.Ui.ViewModels.Modals;
|
||||||
|
using ClaudeDo.Ui.Views.Modals;
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Views.Islands;
|
namespace ClaudeDo.Ui.Views.Islands;
|
||||||
|
|
||||||
@@ -19,7 +21,19 @@ public partial class TasksIslandView : UserControl
|
|||||||
DataContextChanged += (_, _) =>
|
DataContextChanged += (_, _) =>
|
||||||
{
|
{
|
||||||
if (DataContext is TasksIslandViewModel vm)
|
if (DataContext is TasksIslandViewModel vm)
|
||||||
|
{
|
||||||
vm.FocusAddTaskRequested += (_, _) => AddTaskBox.Focus();
|
vm.FocusAddTaskRequested += (_, _) => AddTaskBox.Focus();
|
||||||
|
vm.ShowUnfinishedPlanningModal = async (modalVm) =>
|
||||||
|
{
|
||||||
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||||
|
if (owner is null) { modalVm.CancelCommand.Execute(null); return; }
|
||||||
|
var modal = new UnfinishedPlanningModalView { DataContext = modalVm };
|
||||||
|
// Closing via the OS title-bar (if ever enabled) also resolves the TCS.
|
||||||
|
modal.Closed += (_, _) => modalVm.CancelCommand.Execute(null);
|
||||||
|
await modal.ShowDialog(owner);
|
||||||
|
// ShowDialog completes once the window is closed (CloseAction or OS close).
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="clr-namespace:ClaudeDo.Ui.ViewModels.Modals"
|
||||||
|
x:Class="ClaudeDo.Ui.Views.Modals.UnfinishedPlanningModalView"
|
||||||
|
x:DataType="vm:UnfinishedPlanningModalViewModel"
|
||||||
|
Title="Unfinished planning session"
|
||||||
|
Width="440" Height="200"
|
||||||
|
CanResize="False"
|
||||||
|
SystemDecorations="None"
|
||||||
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
Background="{DynamicResource SurfaceBrush}">
|
||||||
|
|
||||||
|
<Window.KeyBindings>
|
||||||
|
<KeyBinding Gesture="Escape" Command="{Binding CancelCommand}"/>
|
||||||
|
</Window.KeyBindings>
|
||||||
|
|
||||||
|
<Window.Styles>
|
||||||
|
<Style Selector="Button.primary">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource AccentBrush}"/>
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource DeepBrush}"/>
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||||
|
</Style>
|
||||||
|
</Window.Styles>
|
||||||
|
|
||||||
|
<Border Background="{DynamicResource SurfaceBrush}"
|
||||||
|
BorderBrush="{DynamicResource LineBrush}"
|
||||||
|
BorderThickness="1">
|
||||||
|
<Grid RowDefinitions="36,*,52">
|
||||||
|
|
||||||
|
<!-- Title bar -->
|
||||||
|
<Border Grid.Row="0"
|
||||||
|
x:Name="TitleBar"
|
||||||
|
Background="{DynamicResource DeepBrush}"
|
||||||
|
BorderBrush="{DynamicResource LineBrush}"
|
||||||
|
BorderThickness="0,0,0,1"
|
||||||
|
PointerPressed="TitleBar_PointerPressed">
|
||||||
|
<Grid ColumnDefinitions="*,Auto" Margin="14,0">
|
||||||
|
<TextBlock Text="UNFINISHED PLANNING SESSION"
|
||||||
|
FontFamily="{DynamicResource MonoFont}"
|
||||||
|
FontSize="11"
|
||||||
|
LetterSpacing="1.4"
|
||||||
|
Foreground="{DynamicResource TextBrush}"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
<Button Grid.Column="1"
|
||||||
|
Classes="icon-btn"
|
||||||
|
Content="✕"
|
||||||
|
FontSize="12"
|
||||||
|
Command="{Binding CancelCommand}"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- Body -->
|
||||||
|
<StackPanel Grid.Row="1" Margin="20,16" Spacing="8">
|
||||||
|
<TextBlock Text="{Binding TaskTitle}"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Foreground="{DynamicResource TextBrush}"
|
||||||
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
<TextBlock Foreground="{DynamicResource TextDimBrush}">
|
||||||
|
<Run Text="{Binding DraftCount}"/>
|
||||||
|
<Run Text=" draft task(s) waiting to be finalized."/>
|
||||||
|
</TextBlock>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<Border Grid.Row="2"
|
||||||
|
Background="{DynamicResource DeepBrush}"
|
||||||
|
BorderBrush="{DynamicResource LineBrush}"
|
||||||
|
BorderThickness="0,1,0,0">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8"
|
||||||
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
Margin="16,0">
|
||||||
|
<Button Content="Discard" Command="{Binding DiscardCommand}" MinWidth="80"/>
|
||||||
|
<Button Content="Finalize" Command="{Binding FinalizeNowCommand}" MinWidth="80"/>
|
||||||
|
<Button Content="Resume" Command="{Binding ResumeCommand}" Classes="primary" MinWidth="80"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.Views.Modals;
|
||||||
|
|
||||||
|
public partial class UnfinishedPlanningModalView : Window
|
||||||
|
{
|
||||||
|
public UnfinishedPlanningModalView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
DataContextChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
if (DataContext is ViewModels.Modals.UnfinishedPlanningModalViewModel vm)
|
||||||
|
vm.CloseAction = () => Close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TitleBar_PointerPressed(object? sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||||
|
BeginMoveDrag(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
|
||||||
|
<PackageReference Include="ModelContextProtocol" Version="1.2.0" />
|
||||||
|
<PackageReference Include="ModelContextProtocol.AspNetCore" Version="1.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
12
src/ClaudeDo.Worker/Planning/PlanningSessionContext.cs
Normal file
12
src/ClaudeDo.Worker/Planning/PlanningSessionContext.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace ClaudeDo.Worker.Planning;
|
||||||
|
|
||||||
|
public sealed record PlanningSessionStartContext(
|
||||||
|
string ParentTaskId,
|
||||||
|
string WorkingDir,
|
||||||
|
PlanningSessionFiles Files);
|
||||||
|
|
||||||
|
public sealed record PlanningSessionResumeContext(
|
||||||
|
string ParentTaskId,
|
||||||
|
string WorkingDir,
|
||||||
|
string ClaudeSessionId,
|
||||||
|
string McpConfigPath);
|
||||||
7
src/ClaudeDo.Worker/Planning/PlanningSessionFiles.cs
Normal file
7
src/ClaudeDo.Worker/Planning/PlanningSessionFiles.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace ClaudeDo.Worker.Planning;
|
||||||
|
|
||||||
|
public sealed record PlanningSessionFiles(
|
||||||
|
string SessionDirectory,
|
||||||
|
string McpConfigPath,
|
||||||
|
string SystemPromptPath,
|
||||||
|
string InitialPromptPath);
|
||||||
146
src/ClaudeDo.Worker/Planning/PlanningSessionManager.cs
Normal file
146
src/ClaudeDo.Worker/Planning/PlanningSessionManager.cs
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Worker.Planning;
|
||||||
|
|
||||||
|
public sealed class PlanningSessionManager
|
||||||
|
{
|
||||||
|
private const string McpServerUrl = "http://127.0.0.1:47821/mcp";
|
||||||
|
|
||||||
|
private readonly TaskRepository _tasks;
|
||||||
|
private readonly ListRepository _lists;
|
||||||
|
private readonly string _rootDirectory;
|
||||||
|
|
||||||
|
public PlanningSessionManager(TaskRepository tasks, ListRepository lists, string rootDirectory)
|
||||||
|
{
|
||||||
|
_tasks = tasks;
|
||||||
|
_lists = lists;
|
||||||
|
_rootDirectory = rootDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PlanningSessionStartContext> StartAsync(string taskId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var task = await _tasks.GetByIdAsync(taskId, ct)
|
||||||
|
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||||
|
if (task.ParentTaskId is not null)
|
||||||
|
throw new InvalidOperationException("Cannot start a planning session on a child task.");
|
||||||
|
if (task.Status != TaskStatus.Manual)
|
||||||
|
throw new InvalidOperationException($"Task is in status {task.Status}; only Manual can start planning.");
|
||||||
|
|
||||||
|
var token = GenerateToken();
|
||||||
|
_ = await _tasks.SetPlanningStartedAsync(taskId, token, ct)
|
||||||
|
?? throw new InvalidOperationException("Failed to transition task to Planning.");
|
||||||
|
|
||||||
|
var sessionDir = Path.Combine(_rootDirectory, taskId);
|
||||||
|
Directory.CreateDirectory(sessionDir);
|
||||||
|
|
||||||
|
var files = new PlanningSessionFiles(
|
||||||
|
sessionDir,
|
||||||
|
Path.Combine(sessionDir, "mcp.json"),
|
||||||
|
Path.Combine(sessionDir, "system-prompt.md"),
|
||||||
|
Path.Combine(sessionDir, "initial-prompt.txt"));
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(files.McpConfigPath, BuildMcpConfigJson(token), ct);
|
||||||
|
await File.WriteAllTextAsync(files.SystemPromptPath, BuildSystemPrompt(), ct);
|
||||||
|
await File.WriteAllTextAsync(files.InitialPromptPath, BuildInitialPrompt(task), ct);
|
||||||
|
|
||||||
|
var list = await _lists.GetByIdAsync(task.ListId, ct)
|
||||||
|
?? throw new InvalidOperationException($"List {task.ListId} not found.");
|
||||||
|
return new PlanningSessionStartContext(taskId, list.WorkingDir, files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> FinalizeAsync(string taskId, bool queueAgentTasks, CancellationToken ct)
|
||||||
|
=> _tasks.FinalizePlanningAsync(taskId, queueAgentTasks, ct);
|
||||||
|
|
||||||
|
public async Task DiscardAsync(string taskId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var ok = await _tasks.DiscardPlanningAsync(taskId, ct);
|
||||||
|
var sessionDir = Path.Combine(_rootDirectory, taskId);
|
||||||
|
if (Directory.Exists(sessionDir))
|
||||||
|
{
|
||||||
|
try { Directory.Delete(sessionDir, recursive: true); }
|
||||||
|
catch { /* best effort */ }
|
||||||
|
}
|
||||||
|
if (!ok)
|
||||||
|
throw new InvalidOperationException($"Task {taskId} was not in Planning state; nothing to discard.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PlanningSessionResumeContext> ResumeAsync(string taskId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var task = await _tasks.GetByIdAsync(taskId, ct)
|
||||||
|
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||||
|
if (task.Status != TaskStatus.Planning)
|
||||||
|
throw new InvalidOperationException($"Task is in status {task.Status}; resume requires Planning.");
|
||||||
|
if (string.IsNullOrEmpty(task.PlanningSessionId))
|
||||||
|
throw new InvalidOperationException("No Claude session ID captured yet; cannot resume.");
|
||||||
|
|
||||||
|
var sessionDir = Path.Combine(_rootDirectory, taskId);
|
||||||
|
var mcpConfigPath = Path.Combine(sessionDir, "mcp.json");
|
||||||
|
if (!File.Exists(mcpConfigPath))
|
||||||
|
throw new InvalidOperationException($"Session directory missing: {sessionDir}");
|
||||||
|
|
||||||
|
var list = await _lists.GetByIdAsync(task.ListId, ct)
|
||||||
|
?? throw new InvalidOperationException($"List {task.ListId} not found.");
|
||||||
|
return new PlanningSessionResumeContext(taskId, list.WorkingDir, task.PlanningSessionId, mcpConfigPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GenerateToken()
|
||||||
|
{
|
||||||
|
var bytes = RandomNumberGenerator.GetBytes(32);
|
||||||
|
return Convert.ToBase64String(bytes)
|
||||||
|
.Replace('+', '-')
|
||||||
|
.Replace('/', '_')
|
||||||
|
.TrimEnd('=');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildMcpConfigJson(string token)
|
||||||
|
{
|
||||||
|
var payload = new
|
||||||
|
{
|
||||||
|
mcpServers = new
|
||||||
|
{
|
||||||
|
claudedo = new
|
||||||
|
{
|
||||||
|
type = "http",
|
||||||
|
url = McpServerUrl,
|
||||||
|
headers = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
["Authorization"] = $"Bearer {token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return JsonSerializer.Serialize(payload, new JsonSerializerOptions { WriteIndented = true });
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildSystemPrompt() =>
|
||||||
|
"""
|
||||||
|
You are a planning assistant for ClaudeDo.
|
||||||
|
Your role is to help break down a task into smaller, actionable subtasks.
|
||||||
|
|
||||||
|
Use the available MCP tools (mcp__claudedo__*) to create child tasks.
|
||||||
|
When you are done planning, finalize the session.
|
||||||
|
|
||||||
|
Be concise and focused. Each subtask should be independently executable.
|
||||||
|
""";
|
||||||
|
|
||||||
|
private static string BuildInitialPrompt(TaskEntity task)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine($"# Task: {task.Title}");
|
||||||
|
if (!string.IsNullOrWhiteSpace(task.Description))
|
||||||
|
{
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.AppendLine(task.Description);
|
||||||
|
}
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.AppendLine("---");
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.AppendLine("Please analyze this task and break it down into concrete subtasks.");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,9 @@ public sealed class DbFixture : IDisposable
|
|||||||
public DbFixture()
|
public DbFixture()
|
||||||
{
|
{
|
||||||
DbPath = Path.Combine(Path.GetTempPath(), $"claudedo_test_{Guid.NewGuid():N}.db");
|
DbPath = Path.Combine(Path.GetTempPath(), $"claudedo_test_{Guid.NewGuid():N}.db");
|
||||||
// Apply migrations so the schema is created.
|
// EnsureCreated uses the current model directly — no Designer.cs needed.
|
||||||
using var ctx = CreateContext();
|
using var ctx = CreateContext();
|
||||||
ctx.Database.Migrate();
|
ctx.Database.EnsureCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClaudeDoDbContext CreateContext()
|
public ClaudeDoDbContext CreateContext()
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
using ClaudeDo.Data;
|
||||||
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using ClaudeDo.Worker.Planning;
|
||||||
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||||
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Worker.Tests.Planning;
|
||||||
|
|
||||||
|
public sealed class PlanningSessionManagerTests : IDisposable
|
||||||
|
{
|
||||||
|
private readonly DbFixture _db = new();
|
||||||
|
private readonly ClaudeDoDbContext _ctx;
|
||||||
|
private readonly TaskRepository _tasks;
|
||||||
|
private readonly ListRepository _lists;
|
||||||
|
private readonly string _rootDir;
|
||||||
|
private readonly PlanningSessionManager _sut;
|
||||||
|
|
||||||
|
public PlanningSessionManagerTests()
|
||||||
|
{
|
||||||
|
_ctx = _db.CreateContext();
|
||||||
|
_tasks = new TaskRepository(_ctx);
|
||||||
|
_lists = new ListRepository(_ctx);
|
||||||
|
_rootDir = Path.Combine(Path.GetTempPath(), $"cd_planning_{Guid.NewGuid():N}");
|
||||||
|
_sut = new PlanningSessionManager(_tasks, _lists, _rootDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_ctx.Dispose();
|
||||||
|
_db.Dispose();
|
||||||
|
try { Directory.Delete(_rootDir, recursive: true); } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<(string listId, string workingDir)> SeedListAsync()
|
||||||
|
{
|
||||||
|
var listId = Guid.NewGuid().ToString();
|
||||||
|
var wd = Path.Combine(Path.GetTempPath(), $"cd_wd_{Guid.NewGuid():N}");
|
||||||
|
Directory.CreateDirectory(wd);
|
||||||
|
await _lists.AddAsync(new ListEntity
|
||||||
|
{
|
||||||
|
Id = listId,
|
||||||
|
Name = "Test",
|
||||||
|
WorkingDir = wd,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
return (listId, wd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<TaskEntity> SeedManualTaskAsync(string listId)
|
||||||
|
{
|
||||||
|
var t = new TaskEntity
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
ListId = listId,
|
||||||
|
Title = "Brainstorm auth",
|
||||||
|
Description = "- review tokens\n- plan rollout",
|
||||||
|
Status = TaskStatus.Manual,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
CommitType = "feat",
|
||||||
|
};
|
||||||
|
await _tasks.AddAsync(t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task StartAsync_CreatesSessionFiles_AndTransitionsTaskToPlanning()
|
||||||
|
{
|
||||||
|
var (listId, wd) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
|
||||||
|
var ctx = await _sut.StartAsync(parent.Id, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal(parent.Id, ctx.ParentTaskId);
|
||||||
|
Assert.Equal(wd, ctx.WorkingDir);
|
||||||
|
Assert.True(File.Exists(ctx.Files.McpConfigPath));
|
||||||
|
Assert.True(File.Exists(ctx.Files.SystemPromptPath));
|
||||||
|
Assert.True(File.Exists(ctx.Files.InitialPromptPath));
|
||||||
|
|
||||||
|
var mcp = await File.ReadAllTextAsync(ctx.Files.McpConfigPath);
|
||||||
|
Assert.Contains("\"type\": \"http\"", mcp);
|
||||||
|
Assert.Contains("Bearer ", mcp);
|
||||||
|
|
||||||
|
var initial = await File.ReadAllTextAsync(ctx.Files.InitialPromptPath);
|
||||||
|
Assert.Contains("Brainstorm auth", initial);
|
||||||
|
Assert.Contains("review tokens", initial);
|
||||||
|
|
||||||
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
||||||
|
Assert.Equal(TaskStatus.Planning, loaded!.Status);
|
||||||
|
Assert.NotNull(loaded.PlanningSessionToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task StartAsync_TaskNotManual_Throws()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var queuedTask = new TaskEntity
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
ListId = listId,
|
||||||
|
Title = "x",
|
||||||
|
Status = TaskStatus.Queued,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
CommitType = "feat",
|
||||||
|
};
|
||||||
|
await _tasks.AddAsync(queuedTask);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||||
|
_sut.StartAsync(queuedTask.Id, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task StartAsync_ChildTask_Throws()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
await _tasks.SetPlanningStartedAsync(parent.Id, "t");
|
||||||
|
var child = await _tasks.CreateChildAsync(parent.Id, "c", null, null, null);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||||
|
_sut.StartAsync(child.Id, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ResumeAsync_ReturnsExistingSessionDetails()
|
||||||
|
{
|
||||||
|
var (listId, wd) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
var startCtx = await _sut.StartAsync(parent.Id, CancellationToken.None);
|
||||||
|
await _tasks.UpdatePlanningSessionIdAsync(parent.Id, "claude-session-42");
|
||||||
|
|
||||||
|
var resumeCtx = await _sut.ResumeAsync(parent.Id, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal(parent.Id, resumeCtx.ParentTaskId);
|
||||||
|
Assert.Equal(wd, resumeCtx.WorkingDir);
|
||||||
|
Assert.Equal("claude-session-42", resumeCtx.ClaudeSessionId);
|
||||||
|
Assert.Equal(startCtx.Files.McpConfigPath, resumeCtx.McpConfigPath);
|
||||||
|
Assert.True(File.Exists(resumeCtx.McpConfigPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ResumeAsync_NotPlanning_Throws()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
// did not start
|
||||||
|
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||||
|
_sut.ResumeAsync(parent.Id, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ResumeAsync_NoClaudeSessionId_Throws()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
await _sut.StartAsync(parent.Id, CancellationToken.None);
|
||||||
|
// UpdatePlanningSessionIdAsync not called
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||||
|
_sut.ResumeAsync(parent.Id, CancellationToken.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task FinalizeAsync_PromotesDraftsAndMarksPlanned()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
await _sut.StartAsync(parent.Id, CancellationToken.None);
|
||||||
|
await _tasks.CreateChildAsync(parent.Id, "c1", null, null, null);
|
||||||
|
await _tasks.CreateChildAsync(parent.Id, "c2", null, null, null);
|
||||||
|
|
||||||
|
var count = await _sut.FinalizeAsync(parent.Id, queueAgentTasks: true, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.Equal(2, count);
|
||||||
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
||||||
|
Assert.Equal(TaskStatus.Planned, loaded!.Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task DiscardAsync_DeletesSessionDirAndResetsTask()
|
||||||
|
{
|
||||||
|
var (listId, _) = await SeedListAsync();
|
||||||
|
var parent = await SeedManualTaskAsync(listId);
|
||||||
|
var startCtx = await _sut.StartAsync(parent.Id, CancellationToken.None);
|
||||||
|
Assert.True(Directory.Exists(startCtx.Files.SessionDirectory));
|
||||||
|
|
||||||
|
await _sut.DiscardAsync(parent.Id, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.False(Directory.Exists(startCtx.Files.SessionDirectory));
|
||||||
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
||||||
|
Assert.Equal(TaskStatus.Manual, loaded!.Status);
|
||||||
|
Assert.Null(loaded.PlanningSessionToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Ui.ViewModels.Islands;
|
||||||
|
using Xunit;
|
||||||
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Worker.Tests.UiVm;
|
||||||
|
|
||||||
|
public class TaskRowViewModelPlanningTests
|
||||||
|
{
|
||||||
|
private static TaskRowViewModel MakeRow(TaskStatus status, string? parentTaskId = null)
|
||||||
|
=> new TaskRowViewModel { Id = "t", Status = status, ParentTaskId = parentTaskId };
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Draft_Status_SetsIsChildFlag_WhenParentIdIsNotNull()
|
||||||
|
{
|
||||||
|
var vm = MakeRow(TaskStatus.Draft, "parent-id");
|
||||||
|
Assert.True(vm.IsChild);
|
||||||
|
Assert.False(vm.IsPlanningParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Planning_Status_SetsIsPlanningParent()
|
||||||
|
{
|
||||||
|
var vm = MakeRow(TaskStatus.Planning);
|
||||||
|
Assert.True(vm.IsPlanningParent);
|
||||||
|
Assert.False(vm.IsChild);
|
||||||
|
Assert.Equal("PLANNING", vm.PlanningBadge);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Planned_Status_ShowsPlannedBadge()
|
||||||
|
{
|
||||||
|
var vm = MakeRow(TaskStatus.Planned);
|
||||||
|
Assert.True(vm.IsPlanningParent);
|
||||||
|
Assert.Equal("PLANNED", vm.PlanningBadge);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void NonPlanningStatus_NoBadge()
|
||||||
|
{
|
||||||
|
var vm = MakeRow(TaskStatus.Manual);
|
||||||
|
Assert.False(vm.IsPlanningParent);
|
||||||
|
Assert.Null(vm.PlanningBadge);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
using ClaudeDo.Data;
|
||||||
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Ui.Services;
|
||||||
|
using ClaudeDo.Ui.ViewModels.Islands;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Xunit;
|
||||||
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Worker.Tests.UiVm;
|
||||||
|
|
||||||
|
// ── Fake worker client ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
sealed class FakeWorkerClient : IWorkerClient
|
||||||
|
{
|
||||||
|
public int StartPlanningCalls { get; private set; }
|
||||||
|
public int ResumePlanningCalls { get; private set; }
|
||||||
|
public int DiscardPlanningCalls { get; private set; }
|
||||||
|
public int FinalizePlanningCalls { get; private set; }
|
||||||
|
public int WakeQueueCalls { get; private set; }
|
||||||
|
|
||||||
|
public Task WakeQueueAsync() { WakeQueueCalls++; return Task.CompletedTask; }
|
||||||
|
public Task StartPlanningSessionAsync(string taskId, CancellationToken ct = default) { StartPlanningCalls++; return Task.CompletedTask; }
|
||||||
|
public Task ResumePlanningSessionAsync(string taskId, CancellationToken ct = default) { ResumePlanningCalls++; return Task.CompletedTask; }
|
||||||
|
public Task DiscardPlanningSessionAsync(string taskId, CancellationToken ct = default) { DiscardPlanningCalls++; return Task.CompletedTask; }
|
||||||
|
public Task FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks = true, CancellationToken ct = default) { FinalizePlanningCalls++; return Task.CompletedTask; }
|
||||||
|
public Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct = default) => Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Helper to build VM with pre-seeded Items ──────────────────────────────────
|
||||||
|
|
||||||
|
file static class VmFactory
|
||||||
|
{
|
||||||
|
// Minimal SQLite :memory: factory — never actually called in these tests
|
||||||
|
// (we seed Items directly), but required by the VM constructor.
|
||||||
|
private static IDbContextFactory<ClaudeDoDbContext> NullDbFactory()
|
||||||
|
{
|
||||||
|
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
||||||
|
.UseSqlite("DataSource=:memory:")
|
||||||
|
.Options;
|
||||||
|
return new NullDbContextFactory(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class NullDbContextFactory(DbContextOptions<ClaudeDoDbContext> opts)
|
||||||
|
: IDbContextFactory<ClaudeDoDbContext>
|
||||||
|
{
|
||||||
|
public ClaudeDoDbContext CreateDbContext() => new(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (TasksIslandViewModel vm, FakeWorkerClient worker) Create(
|
||||||
|
IEnumerable<TaskRowViewModel> rows)
|
||||||
|
{
|
||||||
|
var worker = new FakeWorkerClient();
|
||||||
|
var vm = new TasksIslandViewModel(NullDbFactory(), worker);
|
||||||
|
foreach (var r in rows)
|
||||||
|
vm.Items.Add(r);
|
||||||
|
vm.Regroup();
|
||||||
|
return (vm, worker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Tests ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
public class TasksIslandViewModelPlanningTests
|
||||||
|
{
|
||||||
|
private static TaskRowViewModel MakeRow(string id, TaskStatus status, string? parentId = null, int sortOrder = 0)
|
||||||
|
=> new TaskRowViewModel { Id = id, Status = status, ParentTaskId = parentId };
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToggleExpand_CollapsesChildrenOfPlanningParent()
|
||||||
|
{
|
||||||
|
var parent = MakeRow("p1", TaskStatus.Planning);
|
||||||
|
var child1 = MakeRow("c1", TaskStatus.Draft, "p1");
|
||||||
|
var child2 = MakeRow("c2", TaskStatus.Draft, "p1");
|
||||||
|
|
||||||
|
var (vm, _) = VmFactory.Create([parent, child1, child2]);
|
||||||
|
|
||||||
|
// Initially expanded — children visible in OpenItems
|
||||||
|
Assert.Contains(child1, vm.OpenItems);
|
||||||
|
Assert.Contains(child2, vm.OpenItems);
|
||||||
|
|
||||||
|
// Collapse the parent
|
||||||
|
vm.ToggleExpandCommand.Execute(parent);
|
||||||
|
|
||||||
|
// Children should no longer appear
|
||||||
|
Assert.DoesNotContain(child1, vm.OpenItems);
|
||||||
|
Assert.DoesNotContain(child2, vm.OpenItems);
|
||||||
|
// Parent still present
|
||||||
|
Assert.Contains(parent, vm.OpenItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task OpenPlanningSession_IgnoresNonManualRow()
|
||||||
|
{
|
||||||
|
var row = MakeRow("t1", TaskStatus.Queued);
|
||||||
|
var (vm, worker) = VmFactory.Create([row]);
|
||||||
|
|
||||||
|
await ((IAsyncRelayCommand<TaskRowViewModel?>)vm.OpenPlanningSessionCommand).ExecuteAsync(row);
|
||||||
|
|
||||||
|
Assert.Equal(0, worker.StartPlanningCalls);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task OpenPlanningSession_CallsWorkerForManualRow()
|
||||||
|
{
|
||||||
|
var row = MakeRow("t1", TaskStatus.Manual);
|
||||||
|
var (vm, worker) = VmFactory.Create([row]);
|
||||||
|
|
||||||
|
await ((IAsyncRelayCommand<TaskRowViewModel?>)vm.OpenPlanningSessionCommand).ExecuteAsync(row);
|
||||||
|
|
||||||
|
Assert.Equal(1, worker.StartPlanningCalls);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToggleExpand_ExpandsCollapsedParentAgain()
|
||||||
|
{
|
||||||
|
var parent = MakeRow("p1", TaskStatus.Planned);
|
||||||
|
var child = MakeRow("c1", TaskStatus.Draft, "p1");
|
||||||
|
|
||||||
|
var (vm, _) = VmFactory.Create([parent, child]);
|
||||||
|
|
||||||
|
// Collapse
|
||||||
|
vm.ToggleExpandCommand.Execute(parent);
|
||||||
|
Assert.DoesNotContain(child, vm.OpenItems);
|
||||||
|
|
||||||
|
// Re-expand
|
||||||
|
vm.ToggleExpandCommand.Execute(parent);
|
||||||
|
Assert.Contains(child, vm.OpenItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user