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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user