feat(ui): replace LiveLines with formatted LiveText, add log reload and start feedback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mika Kuns
2026-04-14 16:28:12 +02:00
parent 503fd69cd1
commit 0764bb30ab
3 changed files with 71 additions and 18 deletions

View File

@@ -1,8 +1,11 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using ClaudeDo.Data.Git;
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Ui.Helpers;
using ClaudeDo.Ui.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -37,14 +40,14 @@ public partial class TaskDetailViewModel : ViewModelBase
[ObservableProperty] private string _worktreeState = "";
// Live stream
public ObservableCollection<string> LiveLines { get; } = new();
[ObservableProperty] private string _liveText = "";
private StreamLineFormatter _formatter = new();
public ObservableCollection<TagEntity> Tags { get; } = new();
[ObservableProperty] private string _newTagInput = "";
private string? _taskId;
private string? _listId;
private bool _isLoading;
private const int MaxLiveLines = 500;
public event Action<string>? TaskChanged;
@@ -61,12 +64,15 @@ public partial class TaskDetailViewModel : ViewModelBase
worker.TaskMessageEvent += OnTaskMessage;
worker.WorktreeUpdatedEvent += OnWorktreeUpdated;
worker.TaskUpdatedEvent += OnTaskUpdated;
worker.RunNowRequestedEvent += OnRunNowRequested;
worker.TaskStartedEvent += OnTaskStarted;
}
public async Task LoadAsync(string taskId)
{
_taskId = taskId;
LiveLines.Clear();
LiveText = "";
_formatter = new StreamLineFormatter();
var task = await _taskRepo.GetByIdAsync(taskId);
if (task is null) return;
@@ -79,6 +85,13 @@ public partial class TaskDetailViewModel : ViewModelBase
Description = task.Description;
Result = task.Result;
LogPath = task.LogPath;
if (task.LogPath is not null
&& task.Status is Data.Models.TaskStatus.Done or Data.Models.TaskStatus.Failed
&& File.Exists(task.LogPath))
{
_formatter = new StreamLineFormatter();
LiveText = _formatter.FormatFile(task.LogPath);
}
StatusText = task.Status.ToString().ToLowerInvariant();
StatusChoice = task.Status.ToString();
CommitType = task.CommitType;
@@ -152,7 +165,8 @@ public partial class TaskDetailViewModel : ViewModelBase
LogPath = null;
StatusText = "";
HasWorktree = false;
LiveLines.Clear();
LiveText = "";
_formatter = new StreamLineFormatter();
Tags.Clear();
NewTagInput = "";
StatusChoice = "Manual";
@@ -259,9 +273,27 @@ public partial class TaskDetailViewModel : ViewModelBase
private void OnTaskMessage(string taskId, string line)
{
if (taskId != _taskId) return;
if (LiveLines.Count >= MaxLiveLines)
LiveLines.RemoveAt(0);
LiveLines.Add(line);
var formatted = _formatter.FormatLine(line);
if (formatted is not null)
{
LiveText += formatted;
if (LiveText.Length > 50_000)
LiveText = StreamLineFormatter.Trim(LiveText);
}
}
private void OnRunNowRequested(string taskId)
{
if (taskId != _taskId) return;
StatusText = "starting...";
LiveText = "";
_formatter = new StreamLineFormatter();
}
private void OnTaskStarted(string slot, string taskId, DateTime startedAt)
{
if (taskId != _taskId) return;
StatusText = "running";
}
private async void OnWorktreeUpdated(string taskId)

View File

@@ -107,17 +107,19 @@
<TextBlock Text="Live Output" FontWeight="SemiBold" FontSize="12"
Foreground="{StaticResource TextSecondaryBrush}" Margin="0,8,0,2"/>
<Border BorderBrush="{StaticResource BorderSubtleBrush}" BorderThickness="1"
CornerRadius="6" Padding="6" MaxHeight="200">
<ScrollViewer>
<ItemsControl ItemsSource="{Binding LiveLines}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontFamily="Consolas,Courier New,monospace"
FontSize="11" TextWrapping="NoWrap"
Foreground="{StaticResource TextPrimaryBrush}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
CornerRadius="6" Padding="6" MaxHeight="300">
<ScrollViewer x:Name="LiveOutputScroll">
<TextBox x:Name="LiveOutputBox"
Text="{Binding LiveText, Mode=OneWay}"
IsReadOnly="True"
AcceptsReturn="True"
TextWrapping="NoWrap"
FontFamily="Consolas,Courier New,monospace"
FontSize="11"
Foreground="{StaticResource TextPrimaryBrush}"
Background="Transparent"
BorderThickness="0"
Padding="0"/>
</ScrollViewer>
</Border>

View File

@@ -1,3 +1,4 @@
using System.ComponentModel;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
@@ -31,4 +32,22 @@ public partial class TaskDetailView : UserControl
{
this.FindControl<TextBox>("TitleBox")?.Focus();
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is TaskDetailViewModel vm)
{
vm.PropertyChanged += OnViewModelPropertyChanged;
}
}
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(TaskDetailViewModel.LiveText))
{
var scroll = this.FindControl<ScrollViewer>("LiveOutputScroll");
scroll?.ScrollToEnd();
}
}
}