Skip to content

Commit 84ceee1

Browse files
bkudiessCopilot
andcommitted
Rebuild Debug page as task-oriented Diagnostics page (rebased on single-app-model)
Replaces the legacy raw-Expander Debug page with a Fluent-style "Diagnostics" surface composed of CommunityToolkit SettingsCard / SettingsExpander, an in-page detail view, and a preview-then-share diagnostics bundle dialog. The internal route stays Tag="debug" so every existing command-palette / deep-link alias keeps working. Rebased onto Ranjesh's single-app-model branch (user/ranjeshj/singleappmodel). The page now observes AppState directly per docs/DATA_FLOW_ARCHITECTURE.md and routes user intents through IAppCommands — no HubWindow dependency: - DebugPage.Initialize() takes no arguments; pulls AppState + ConnectionManager from ((App)Application.Current) and subscribes to AppState.PropertyChanged for live Status / GatewaySelf updates. - "Manage on Connection page" hyperlink calls ((IAppCommands)CurrentApp).Navigate("connection"). - "Reconfigure..." confirmation calls ((IAppCommands)CurrentApp).ShowOnboarding() after the ContentDialog returns Primary. - Diagnostics-bundle preview pulls the GatewayCommandCenterState via App.BuildCommandCenterState() (made internal so pages can call it without the now-deleted HubWindow.GetCommandCenterStateAction). - DiagnosticsBundleDialog gets its parent HWND via the new App.GetHubWindowHandle() (mirrors App.GetOnboardingWindowHandle). - AboutPage.OnCopySupportClick unifies on the same BuildCommandCenterState path; "More diagnostics ->" hyperlink uses IAppCommands.Navigate("debug"). ## Page - Renames the nav-item label "Debug" -> "Diagnostics" (resw HubWindow_NavigationViewItem_145.Content). The Tag, route table, and command palette aliases ("debug", "connectionstatus", "log", "supportcontext", "debugbundle", "browsersetup", "portdiagnostics", "capabilitydiagnostics") are unchanged. - Three task-oriented sections instead of an inventory of features: 1. Share diagnostics with support — primary "Create diagnostics bundle" SettingsCard opens a preview ContentDialog (Copy / Save to file / Close). Four previously invisible diagnostic-text commands (debug bundle, browser setup, port diagnostics, capability diagnostics) are surfaced behind a "Copy specific diagnostic text" SettingsExpander. 2. Inspect local diagnostics — Connection event timeline + Recent log cards (both open the new in-page detail view), plus a Device identity SettingsExpander with click-to-copy Device ID and Public key. 3. Developer tools — Warning InfoBar, Chat surface overrides SettingsExpander, Open chat explorations, and Reconfigure... (canonical verb per naming.md) with ContentDialog confirmation. - All cards live in a single centered Width=900 StackPanel so the title block and cards share the exact same column and left edge. ## In-page detail view - Replaces the separate ConnectionStatusWindow entry on this page with an in-page detail view that swaps in via Visibility, matching ConnectionPage.AddGatewayPanel. - Two modes share a single RichTextBlock body: - Timeline — subscribes to ConnectionDiagnostics.EventRecorded and renders live state-machine / websocket / handshake / credential events with the same direction-arrow + category tag + severity coloring used by ConnectionStatusWindow. - Log — reads the last 200 lines of openclaw-tray.log and colors each line by severity ([info]/[warn]/[error]/[debug]/ [trace] + legacy uppercase forms) with the timestamp prefix rendered dim. - Both modes resolve their severity brushes from system theme tokens (SystemFillColorCritical/Caution/Attention/Success + TextFillColorSecondary) so the colors track light/dark/HC. ## Design-reference compliance (docs/design/*) - Eight new Segoe Fluent Icons constants in FluentIconCatalog (Bug, Briefcase, Folder, Copy, Document, Refresh, Clear, Develop), pinned in FluentIconCatalogTests, used via {x:Bind helpers:FluentIconCatalog.X, Mode=OneTime}. - Canonical "Reconfigure..." verb (with ellipsis) per naming.md. ## Hanselman dual-model review fixes (Opus + Codex consensus) - #1 OnNavigatedFrom + Unloaded both unsubscribe the ConnectionDiagnostics.EventRecorded handler so the page can no longer leak its subscription when the user navigates away. - #2 ReadLogTail uses FileStream with FileShare.ReadWrite to coexist with Logger.cs:109's active writer; the previous File.ReadLines silently failed on every Logger-active read. - #3 Timeline subscribes before snapshotting and dedupes via HashSet<ConnectionDiagnosticEvent> (records use value equality) so events arriving during the snapshot/subscribe window are not dropped. - #4 Log tail reads on a background thread via Task.Run so a large rotated log doesn't stall the UI thread. - #5 RichTextBlock.Blocks + plain-text Queue<string> mirror are capped at MaxTimelineRows=500 (matches ConnectionDiagnostics capacity). - #6 DiagnosticsBundleDialog.OnSaveClick drops the dead GetDeferral/ContinueWith path; the dialog stays open after Save (mirrors Copy). ## Wiring - App.BuildCommandCenterState() is now `internal` so pages can pull the GatewayCommandCenterState directly without going through HubWindow. - App.GetHubWindowHandle() new helper for parenting file pickers from in-Hub pages (mirrors GetOnboardingWindowHandle). - HubWindow loses GetCommandCenterStateAction (was only used for the now-removed forwarding chain). ## Tests - DiagnosticsPageContractTests (17 source-level guards) updated for the new pattern: asserts CurrentApp / AppState observation, no HubWindow dependency, Width=900 column, and BuildCommandCenterState internal accessor. - FluentIconCatalogTests.ExpectedConstants extended with the eight new constants. - Required validation per AGENTS.md is green: ./build.ps1 -> all four projects build dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore -> 1620 passed, 28 skipped dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore -> 984 passed Co-authored-by: Copilot <[email protected]>
1 parent 4ab640f commit 84ceee1

13 files changed

Lines changed: 1734 additions & 288 deletions

‎src/OpenClaw.Tray.WinUI/App.xaml.cs‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ public IntPtr GetOnboardingWindowHandle()
190190
? WinRT.Interop.WindowNative.GetWindowHandle(_onboardingWindow)
191191
: IntPtr.Zero;
192192

193+
/// <summary>
194+
/// Returns the HWND of the Hub window, or IntPtr.Zero if it isn't open.
195+
/// Used by pages hosted in the Hub that need to parent a file picker
196+
/// or other Win32-style dialog. Pages should not hold a reference to
197+
/// the HubWindow directly (single-app-model rule); they call this
198+
/// when they need the handle and discard it afterwards.
199+
/// Guards against the close-window race where `_hubWindow != null`
200+
/// but the window is mid-teardown — every other call site in this
201+
/// file pairs the null check with `!IsClosed` (Hanselman v2 #4).
202+
/// </summary>
203+
public IntPtr GetHubWindowHandle()
204+
=> _hubWindow != null && !_hubWindow.IsClosed
205+
? WinRT.Interop.WindowNative.GetWindowHandle(_hubWindow)
206+
: IntPtr.Zero;
207+
193208
private SettingsManager? _settings;
194209
private ConnectionSettingsSnapshot? _previousSettingsSnapshot;
195210
private SshTunnelService? _sshTunnelService;
@@ -2584,8 +2599,19 @@ private void OnSettingsSaved(object? sender, EventArgs e)
25842599
AutoStartManager.SetAutoStart(_settings.AutoStart);
25852600

25862601
// Notify ad-hoc listeners (e.g. ChatWindow may be alive but not
2587-
// owned by the hub) that settings have changed.
2588-
SettingsChanged?.Invoke(this, EventArgs.Empty);
2602+
// owned by the hub) that settings have changed. Marshal onto the
2603+
// UI thread because IAppCommands.NotifySettingsSaved is a public
2604+
// entry point that may be invoked from background work; existing
2605+
// handlers (DebugPage, ChatWindow) update UI directly and would
2606+
// crash if dispatched from a non-UI thread (Hanselman v2 #7).
2607+
if (_dispatcherQueue != null && !_dispatcherQueue.HasThreadAccess)
2608+
{
2609+
_dispatcherQueue.TryEnqueue(() => SettingsChanged?.Invoke(this, EventArgs.Empty));
2610+
}
2611+
else
2612+
{
2613+
SettingsChanged?.Invoke(this, EventArgs.Empty);
2614+
}
25892615
}
25902616

25912617
private void ShowWebChat()
@@ -2745,7 +2771,7 @@ private void UpdateStatusDetailWindow()
27452771
// Tray status detail window reads from AppState too.
27462772
}
27472773

2748-
private GatewayCommandCenterState BuildCommandCenterState() =>
2774+
internal GatewayCommandCenterState BuildCommandCenterState() =>
27492775
new CommandCenterStateBuilder(CaptureSnapshot()).Build();
27502776

27512777
private AppStateSnapshot CaptureSnapshot() => new AppStateSnapshot

‎src/OpenClaw.Tray.WinUI/Helpers/FluentIconCatalog.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ public static class FluentIconCatalog
7171
// ── Brand placeholder (lobster emoji currently retained) ───────
7272
public const string Brand = "🦞";
7373

74+
// ── Diagnostics page glyphs ────────────────────────────────────
75+
// Added 2026-05 for the Diagnostics surface
76+
// (src/OpenClaw.Tray.WinUI/Pages/DebugPage.xaml). Keep these here
77+
// rather than as XAML literals so the icon catalog stays the
78+
// single source of truth and FluentIconCatalogTests pins each one.
79+
public const string Bug = "\uEBE8"; // BugSolid — nav item glyph for Diagnostics
80+
public const string Briefcase = "\uE7B8"; // Briefcase — diagnostics bundle action
81+
public const string Folder = "\uE8DA"; // OpenLocal — open folder action
82+
public const string Copy = "\uE8C8"; // Copy — copy-to-clipboard affordance
83+
public const string Document = "\uE8A5"; // Document — recent log / log file
84+
public const string Refresh = "\uE72C"; // Refresh — re-read a snapshot (distinct from Sync E895)
85+
public const string Clear = "\uE74D"; // Delete — clear/reset a buffer
86+
public const string Develop = "\uE943"; // Code — engineering / explorations action
87+
7488
/// <summary>
7589
/// Builds a <see cref="FontIcon"/> for the given PUA glyph using the
7690
/// system-resolved <c>SymbolThemeFontFamily</c> so the icon honors

‎src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.1839" />
6161
<PackageReference Include="WinUIEx" Version="2.9.0" />
6262
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
63+
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.3.260402-preview2" />
6364
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="10.0.0" />
6465
<PackageReference Include="System.Drawing.Common" Version="10.0.7" />
6566
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="10.0.0" />

‎src/OpenClaw.Tray.WinUI/Pages/AboutPage.xaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
<Button x:Uid="CheckUpdatesButton" x:Name="CheckUpdatesButton" Content="Check for Updates"
8181
Click="OnCheckUpdatesClick"/>
8282
</StackPanel>
83+
<HyperlinkButton x:Uid="AboutPage_MoreDiagnosticsLink"
84+
Content="More diagnostics →"
85+
Click="OnMoreDiagnosticsClick"
86+
Padding="0,4,0,0"/>
8387
</StackPanel>
8488
</Border>
8589

‎src/OpenClaw.Tray.WinUI/Pages/AboutPage.xaml.cs‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.ComponentModel;
77
using System.Diagnostics;
8+
using System.Threading.Tasks;
89

910
namespace OpenClawTray.Pages;
1011

@@ -94,13 +95,27 @@ private async void OnCopySupportClick(object sender, RoutedEventArgs e)
9495
{
9596
try
9697
{
97-
var context = $"OpenClaw Hub v0.1.0\n"
98-
+ $"OS: {Environment.OSVersion}\n"
99-
+ $"Runtime: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}\n"
100-
+ $"Connection: {CurrentApp.AppState?.Status}\n"
101-
+ $"Gateway: {CurrentApp.Settings?.GetEffectiveGatewayUrl() ?? "n/a"}\n";
98+
// Unified with the richer CommandCenterTextHelper.BuildSupportContext
99+
// that the Diagnostics page uses, sourced from App's authoritative
100+
// CommandCenterState builder. Falls back to a minimal local
101+
// string only when the state isn't available yet (cold start).
102+
string context;
103+
var state = CurrentApp.BuildCommandCenterState();
104+
if (state != null)
105+
{
106+
context = OpenClawTray.Helpers.CommandCenterTextHelper.BuildSupportContext(state);
107+
}
108+
else
109+
{
110+
context = $"OpenClaw Hub v0.1.0\n"
111+
+ $"OS: {Environment.OSVersion}\n"
112+
+ $"Runtime: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}\n"
113+
+ $"Connection: {CurrentApp.AppState?.Status}\n"
114+
+ $"Gateway: {CurrentApp.Settings?.GetEffectiveGatewayUrl() ?? "n/a"}\n";
115+
}
102116

103117
ClipboardHelper.CopyText(context);
118+
await Task.CompletedTask;
104119
}
105120
catch (Exception ex)
106121
{
@@ -113,6 +128,11 @@ private void OnCheckUpdatesClick(object sender, RoutedEventArgs e)
113128
((IAppCommands)CurrentApp).CheckForUpdates();
114129
}
115130

131+
private void OnMoreDiagnosticsClick(object sender, RoutedEventArgs e)
132+
{
133+
((IAppCommands)CurrentApp).Navigate("debug");
134+
}
135+
116136
private void OnDocumentationClick(object sender, RoutedEventArgs e)
117137
{
118138
try

0 commit comments

Comments
 (0)