Forge
csharpd39635e2
1using System.Collections.ObjectModel;
2using Avalonia.Threading;
3using CascadeIDE.ViewModels;
4using CommunityToolkit.Mvvm.ComponentModel;
5
6namespace CascadeIDE.Features.Instrumentation;
7
8/// <summary>
9/// Состояние инструментирования: трасса агента, таймлайн событий, очередь задач, тесты, отладка MCP.
10/// </summary>
11public sealed partial class InstrumentationPanelViewModel : ViewModelBase
12{
13 public InstrumentationPanelViewModel()
14 {
15 AgentToolCalls.CollectionChanged += (_, _) => OnPropertyChanged(nameof(HasAgentToolCalls));
16 AgentTraceSteps.CollectionChanged += (_, _) => OnPropertyChanged(nameof(HasAgentTraceSteps));
17 PowerTaskQueueItems.CollectionChanged += (_, _) => OnPropertyChanged(nameof(HasPowerTaskQueueItems));
18 EventTimeline.CollectionChanged += (_, _) => OnPropertyChanged(nameof(HasEventTimeline));
19 DebugStackFrames.CollectionChanged += (_, _) => OnDebugCollectionsChanged();
20 DebugVariableRoots.CollectionChanged += (_, _) => OnDebugCollectionsChanged();
21 }
22
23 private void OnDebugCollectionsChanged()
24 {
25 OnPropertyChanged(nameof(IsDebugPanelVisible));
26 }
27
28 public ObservableCollection<string> AgentToolCalls { get; } = [];
29 public ObservableCollection<AgentTraceStepViewModel> AgentTraceSteps { get; } = [];
30 public ObservableCollection<string> EventTimeline { get; } = [];
31 public ObservableCollection<PowerTaskQueueItemViewModel> PowerTaskQueueItems { get; } = [];
32
33 public bool HasAgentToolCalls => AgentToolCalls.Count > 0;
34 public bool HasAgentTraceSteps => AgentTraceSteps.Count > 0;
35 public bool HasPowerTaskQueueItems => PowerTaskQueueItems.Count > 0;
36 public bool HasEventTimeline => EventTimeline.Count > 0;
37
38 public ObservableCollection<DebugStackFrameViewModel> DebugStackFrames { get; } = [];
39 public ObservableCollection<DebugVariableNodeViewModel> DebugVariableRoots { get; } = [];
40
41 public bool IsDebugPanelVisible => DebugStackFrames.Count > 0 || DebugVariableRoots.Count > 0;
42
43 /// <summary>Накопленный текстовый лог прогонов тестов для вкладки «Тесты».</summary>
44 [ObservableProperty]
45 private string _testResultsOutput = "";
46
47 /// <summary>Добавить шаг в Agent Trace Timeline (Power); потокобезопасно.</summary>
48 public void AppendAgentTraceStep(string kind, string text, string status, DateTimeOffset? at = null)
49 {
50 void Add()
51 {
52 AgentTraceSteps.Add(new AgentTraceStepViewModel(kind, text, status, at));
53 while (AgentTraceSteps.Count > 200)
54 AgentTraceSteps.RemoveAt(0);
55 }
56
57 if (UiScheduler.Default.CheckAccess())
58 Add();
59 else
60 UiScheduler.Default.Post(Add);
61 }
62}
63
View only · write via MCP/CIDE