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
+49
View File
@@ -0,0 +1,49 @@
// An agent's notify call for captures of the web notification paths. Off by
// default.
//
// `?agentNotice=<ms>` answers subscribe_notifications with no backlog, then
// <ms> after it pushes one `chat_notify` notification
// for the `ui-review` chat (add `ui-review=1` so the
// chat has its title). `agentNoticePriority=2|3|4`
// sets its priority (default 3).
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
Map<String, String> _params = const {};
void configureAgentNoticeFixture(Map<String, String> params) =>
_params = params;
/// The subscribe reply for [request], or null when the fixture is off or the
/// request is not a subscription. Schedules the push through [emit].
JsonMap? agentNoticeReply(JsonMap request, void Function(JsonMap) emit) {
if (request['type'] != 'subscribe_notifications') return null;
final delay = int.tryParse(_params['agentNotice'] ?? '');
if (delay != null) {
final priority = int.tryParse(_params['agentNoticePriority'] ?? '') ?? 3;
Timer(Duration(milliseconds: delay), () {
emit({
'type': 'notification',
'notification': {
'id': 'chat:ui-review:notify:shown_capture',
'kind': 'chat_notify',
'title': 'Build finished',
'message':
'All 412 tests pass. The release branch is ready to merge.',
'click': 'pipelines://chat/ui-review',
'priority': priority,
'tags': <String>[],
'created_at': DateTime.now().toUtc().toIso8601String(),
'group': 'chat:ui-review',
},
});
});
}
return {
'id': request['id'],
'type': 'notifications_subscribed',
'notifications': <JsonMap>[],
'ids': <String>[],
};
}
+7 -1
View File
@@ -44,6 +44,7 @@ import 'perf/chat_search_fixture.dart';
import 'perf/chat_shown_fixture.dart';
import 'perf/chat_claude_accounts_fixture.dart';
import 'perf/chat_question_fixture.dart';
import 'perf/agent_notice_fixture.dart';
import 'capture/window_probe.dart';
import 'perf/chat_scroll_fixture.dart';
import 'perf/perf_fixture.dart';
@@ -814,7 +815,11 @@ class _FixtureChannel implements WebSocketChannel {
}
});
}
final reply = probeReply(decoded);
final reply =
agentNoticeReply(decoded, (frame) {
if (!_incoming.isClosed) _incoming.add(jsonEncode(frame));
}) ??
probeReply(decoded);
final followUps = perfChatFollowUps(decoded);
final subscribe = decoded['chat_subscribe'];
if (subscribe is Map) {
@@ -927,6 +932,7 @@ Future<void> main() async {
return;
}
configurePerfFixture(params);
configureAgentNoticeFixture(params);
installSpeechFixture(params);
if (params['files'] == '1') {
probeMissingRememberedFolder = params['filesMissing'] == '1';