feat(daily-prep): add live prep-output mode to the Details island

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-06-04 08:14:09 +02:00
parent 7676ecf0d4
commit a8670ee23a
5 changed files with 160 additions and 13 deletions

View File

@@ -54,6 +54,14 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
private readonly INotesApi _notesApi;
[ObservableProperty] private bool _isNotesMode;
[ObservableProperty] private bool _isPrepMode;
[ObservableProperty] private bool _isPrepRunning;
public ObservableCollection<LogLineViewModel> PrepLog { get; } = new();
public bool IsTaskDetailVisible => !IsNotesMode && !IsPrepMode;
partial void OnIsNotesModeChanged(bool value) => OnPropertyChanged(nameof(IsTaskDetailVisible));
partial void OnIsPrepModeChanged(bool value) => OnPropertyChanged(nameof(IsTaskDetailVisible));
public NotesEditorViewModel Notes { get; private set; } = null!;
// Current task row (set by IslandsShellViewModel via Bind)
@@ -207,6 +215,7 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
// Claude CLI stream-json parser + buffer for partial text deltas
private readonly StreamLineFormatter _formatter = new();
private readonly StringBuilder _claudeBuf = new();
private readonly StringBuilder _prepClaudeBuf = new();
// The task ID we are currently subscribed to for live log messages
private string? _subscribedTaskId;
@@ -285,6 +294,9 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
// Subscribe once; filter by current task id inside the handler
_worker.TaskMessageEvent += OnTaskMessage;
_worker.PrepStartedEvent += OnPrepStarted;
_worker.PrepLineEvent += OnPrepLine;
_worker.PrepFinishedEvent += OnPrepFinished;
// Re-evaluate CanExecute when worker connection flips.
_worker.PropertyChanged += (_, e) =>
@@ -345,9 +357,7 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
if (line.StartsWith("[stdout]", StringComparison.OrdinalIgnoreCase))
{
var body = line["[stdout]".Length..].TrimStart();
var formatted = _formatter.FormatLine(body);
if (formatted is null) return; // filter noise (message_start, etc.)
AppendClaudeText(formatted);
AppendStdoutLine(Log, body);
return;
}
@@ -363,20 +373,40 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
Log.Add(new LogLineViewModel { Kind = kind, Text = line });
}
private void AppendClaudeText(string chunk)
private void AppendStdoutLine(ObservableCollection<LogLineViewModel> target, string line)
{
_claudeBuf.Append(chunk);
var formatted = _formatter.FormatLine(line);
if (formatted is null) return;
var buf = ReferenceEquals(target, Log) ? _claudeBuf : _prepClaudeBuf;
AppendClaudeText(formatted, target, buf);
}
private void OnPrepStarted()
{
PrepLog.Clear();
IsPrepRunning = true;
}
private void OnPrepLine(string line) => AppendStdoutLine(PrepLog, line);
private void OnPrepFinished(bool success) => IsPrepRunning = false;
private void AppendClaudeText(string chunk) => AppendClaudeText(chunk, Log, _claudeBuf);
private static void AppendClaudeText(string chunk, ObservableCollection<LogLineViewModel> target, StringBuilder buf)
{
buf.Append(chunk);
// Emit a log entry for every completed line; keep the trailing remainder buffered.
while (true)
{
var text = _claudeBuf.ToString();
var text = buf.ToString();
var nl = text.IndexOf('\n');
if (nl < 0) break;
var piece = text[..nl].TrimEnd('\r');
if (!string.IsNullOrWhiteSpace(piece))
Log.Add(new LogLineViewModel { Kind = LogKind.Claude, Text = piece });
_claudeBuf.Clear();
_claudeBuf.Append(text[(nl + 1)..]);
target.Add(new LogLineViewModel { Kind = LogKind.Claude, Text = piece });
buf.Clear();
buf.Append(text[(nl + 1)..]);
}
}
@@ -478,13 +508,22 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
public void ShowNotes()
{
Bind(null);
IsPrepMode = false;
IsNotesMode = true;
_ = Notes.LoadDayAsync(DateOnly.FromDateTime(DateTime.Today));
}
public void ShowPrep()
{
Bind(null);
IsNotesMode = false;
IsPrepMode = true;
}
public void Bind(TaskRowViewModel? row)
{
IsNotesMode = false;
IsPrepMode = false;
_loadCts?.Cancel();
_loadCts?.Dispose();
_loadCts = new CancellationTokenSource();