App: agent notifications on the web (system notification, toast, tab title count)

The app subscribes to the notification stream on every connection and
delivers chat_notify notices: a toast when the page is focused (none if
that chat is in view), a browser notification titled '<chat>: <title>'
plus a '(n)' tab title count when it is not, and on insecure http pages a
toast, the title count and a short chime. Low priority posts only when
hidden. Replays within an hour show once; ids persist in the ledger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 16:02:47 +00:00
parent c8541f29b7
commit 150481b57b
17 changed files with 1197 additions and 23 deletions
+36 -9
View File
@@ -16,6 +16,10 @@ import '../shell/adaptive_shell.dart';
import '../shell/destination.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/notify/chat_question_notices.dart';
import '../features/attention/notify/agent_notices.dart';
import '../features/attention/notify/page_signals.dart';
import '../features/attention/ui/agent_notice_toast.dart';
import 'clipboard_failures.dart' show appScaffoldMessengerKey;
import '../features/attention/notify/notification_store.dart';
import '../features/notification_service/notification_service_bridge.dart';
import '../features/notification_service/notification_service_controller.dart';
@@ -268,6 +272,11 @@ class _PipelinesAppState extends State<PipelinesApp>
);
ChatQuestionNotices? _chatQuestionNotices;
/// Agents' notify calls on this device: a system notification, a toast, the
/// tab title count. Subscribed on every connection so missed ones replay.
AgentNotices? _agentNotices;
final PageSignals _pageSignals = createPageSignals();
/// One attention surface for the app: the Runs heading's bell draws from it
/// and the shell mirrors its count on the Runs tab, so the badge is visible
/// from every destination. The Runs list seeds the rows when it loads; pushed
@@ -472,18 +481,22 @@ class _PipelinesAppState extends State<PipelinesApp>
_chatQuestionNotices = ChatQuestionNotices(
gateway: _session.gateway,
canNotify: () => _notifications.canNotify,
activeChatSessionId: () {
final route = _delegate.shellRoute;
return route.kind == AppRouteKind.chat ? route.chatSessionId : null;
},
activeChatSessionId: _activeChatSessionId,
sessionTitle: _chatSessionTitle,
openChat: (id) {
if (!mounted) return;
widget.servers?.requestChatOpen(id);
_delegate.goTo(AppRoute.chatSession(id));
},
openChat: _openNotifiedChat,
bridge: _notifications.bridge,
);
_agentNotices = AgentNotices(
gateway: _session.gateway,
notifications: _notifications,
page: _pageSignals,
activeChatSessionId: _activeChatSessionId,
sessionTitle: _chatSessionTitle,
openChat: _openNotifiedChat,
showToast: (toast) =>
showAgentNoticeToast(appScaffoldMessengerKey.currentState, toast),
sendOnly: _session.client.sendOnly,
);
_config = RouterConfig<AppRoute>(
routeInformationParser: const AppRouteParser(),
routerDelegate: _delegate,
@@ -595,6 +608,8 @@ class _PipelinesAppState extends State<PipelinesApp>
_notifications.dispose();
_deliveryController.dispose();
_chatQuestionNotices?.dispose();
_agentNotices?.dispose();
_pageSignals.dispose();
if (identical(MachineElevation.defaultPrompt, _elevationPrompt)) {
MachineElevation.defaultPrompt = null;
}
@@ -666,6 +681,7 @@ class _PipelinesAppState extends State<PipelinesApp>
// Every connected transition sends acknowledgements queued while offline
// and re-reads the shared set, so a gap cannot leave this device stale.
if (_session.connected) unawaited(_ackSync.connected());
if (_session.connected) unawaited(_agentNotices?.connected());
}
/// Mirrors attention and independent status counts for the shell. The Runs list seeds
@@ -878,6 +894,17 @@ class _PipelinesAppState extends State<PipelinesApp>
setState(() => _pendingRunSearch = null);
}
String? _activeChatSessionId() {
final route = _delegate.shellRoute;
return route.kind == AppRouteKind.chat ? route.chatSessionId : null;
}
void _openNotifiedChat(String id) {
if (!mounted) return;
widget.servers?.requestChatOpen(id);
_delegate.goTo(AppRoute.chatSession(id));
}
Future<String?> _chatSessionTitle(String id) async {
id = widget.chatPool?.gateway.normalizeId(id) ?? id;
final reply = await (widget.chatPool?.gateway ?? _session.gateway).call(