From b702ecab6fb2fa2799a37e882a9a127406c7d3c6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 12:57:54 +0000 Subject: [PATCH] fix: pass UserRules to NotificationCategorizer in OpenClawGatewayClient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NotificationCategorizer.Classify() method accepts an optional userRules parameter so custom notification rules (step 3 in the categorization pipeline) are applied. However, both call sites in OpenClawGatewayClient — EmitNotification and EmitChatNotification — called Classify() without passing user rules, making the UserRules setting completely non-functional. Changes: - Add _userRules field to OpenClawGatewayClient - Add SetUserRules(IReadOnlyList?) method - Pass _userRules to both Classify() call sites - Call SetUserRules() in App.xaml.cs when initializing the gateway client so rules from settings take effect immediately Closes #93 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/OpenClaw.Shared/OpenClawGatewayClient.cs | 15 +++++++++++++-- src/OpenClaw.Tray.WinUI/App.xaml.cs | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/OpenClaw.Shared/OpenClawGatewayClient.cs b/src/OpenClaw.Shared/OpenClawGatewayClient.cs index 0e21836..c4987b6 100644 --- a/src/OpenClaw.Shared/OpenClawGatewayClient.cs +++ b/src/OpenClaw.Shared/OpenClawGatewayClient.cs @@ -22,6 +22,7 @@ public class OpenClawGatewayClient : WebSocketClientBase private bool _usageCostUnsupported; private bool _sessionPreviewUnsupported; private bool _nodeListUnsupported; + private IReadOnlyList? _userRules; private void ResetUnsupportedMethodFlags() { @@ -31,6 +32,16 @@ private void ResetUnsupportedMethodFlags() _nodeListUnsupported = false; } + /// + /// Provides user-defined notification rules to the categorizer so custom rules + /// are applied when classifying incoming gateway notifications. + /// Call after construction and whenever settings change. + /// + public void SetUserRules(IReadOnlyList? rules) + { + _userRules = rules; + } + protected override int ReceiveBufferSize => 16384; protected override string ClientRole => "gateway"; @@ -851,7 +862,7 @@ private void EmitChatNotification(string text) Message = displayText, IsChat = true }; - var (title, type) = _categorizer.Classify(notification); + var (title, type) = _categorizer.Classify(notification, _userRules); notification.Title = title; notification.Type = type; NotificationReceived?.Invoke(this, notification); @@ -1556,7 +1567,7 @@ private void EmitNotification(string text) { Message = text.Length > 200 ? text[..200] + "…" : text }; - var (title, type) = _categorizer.Classify(notification); + var (title, type) = _categorizer.Classify(notification, _userRules); notification.Title = title; notification.Type = type; NotificationReceived?.Invoke(this, notification); diff --git a/src/OpenClaw.Tray.WinUI/App.xaml.cs b/src/OpenClaw.Tray.WinUI/App.xaml.cs index de0780f..f22e2ad 100644 --- a/src/OpenClaw.Tray.WinUI/App.xaml.cs +++ b/src/OpenClaw.Tray.WinUI/App.xaml.cs @@ -1085,6 +1085,7 @@ private void InitializeGatewayClient() UnsubscribeGatewayEvents(); _gatewayClient = new OpenClawGatewayClient(_settings.GatewayUrl, _settings.Token, new AppLogger()); + _gatewayClient.SetUserRules(_settings.UserRules.Count > 0 ? _settings.UserRules : null); _gatewayClient.StatusChanged += OnConnectionStatusChanged; _gatewayClient.ActivityChanged += OnActivityChanged; _gatewayClient.NotificationReceived += OnNotificationReceived;