Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(mobile): an agent asking something reaches the phone, as it reaches the dial

Dev jacob84aa18cca163
diff --git a/mobile/lib/notify/agent_announcer.dart b/mobile/lib/notify/agent_announcer.dart
new file mode 100644
index 000000000..40c7ec55c
--- /dev/null
+++ b/mobile/lib/notify/agent_announcer.dart
@@ -0,0 +1,154 @@
+import 'package:flutter/services.dart';
+import 'package:flutter/widgets.dart';
+
+import 'package:harness_mobile/core/last_opened_agent.dart';
+
+import 'agent_notice.dart';
+import 'agent_unread.dart';
+import 'done_notice.dart';
+import 'question_notice.dart';
+import 'system_notices.dart';
+
+/// Who the news is about, in the words the notice uses.
+typedef NoticeAgent = ({AgentRef ref, String name, String machine});
+
+/// Carries out the dial's two rules — [decideDoneNotice] and
+/// [decideQuestionNotice]: the chime, the unread mark, the system notice. The
+/// notifier says what happened; this decides what it is worth and does it, so
+/// none of the three can drift from the rule.
+class AgentAnnouncer {
+ AgentAnnouncer({
+ required this.system,
+ Future<void> Function()? chime,
+ bool Function()? inFront,
+ }) : _chime = chime ?? _haptic,
+ _inFront = inFront ?? _appInFront;
+
+ final SystemNotices system;
+ final unread = AgentUnread();
+ final _asked = AskedQuestions();
+ final Future<void> Function() _chime;
+ final bool Function() _inFront;
+
+ /// The dial's three tones, as a phone says them without a sound: a tap the
+ /// hand feels even with the ringer off. Never worth an error — a plain
+ /// `test()` has no binding to send it through.
+ static Future<void> _haptic() async {
+ try {
+ await HapticFeedback.mediumImpact();
+ } catch (_) {}
+ }
+
+ /// Whether the app is on screen. ⚠️ Tolerant of there being NO binding, as
+ /// the desktop's `lifecycle` is: plain `test()`s drive the notifier without
+ /// one, and `WidgetsBinding.instance` throws rather than answering null.
+ /// Unknown counts as in front, which errs toward a mark over a notice.
+ static bool _appInFront() {
+ try {
+ final state = WidgetsBinding.instance.lifecycleState;
+ return state == null || state == AppLifecycleState.resumed;
+ } catch (_) {
+ return true;
+ }
+ }
+
+ bool get inFront => _inFront();
+
+ /// One turn ended. [watching] is whether [agent] is the one on screen —
+ /// only asked when the app is in front.
+ AgentNotice turnEnded(
+ NoticeAgent agent,
+ TurnEnd end, {
+ required bool Function() watching,
+ }) {
+ // Whatever it was asking, the turn it asked in is over — and a turn that
+ // ends with nothing to say must not leave the question's mark standing.
+ questionClosed(agent.ref);
+ final front = inFront;
+ final notice = decideDoneNotice(
+ end,
+ inFront: front,
+ watching: front && watching(),
+ );
+ _deliver(agent, notice, NoticeKind.done, () => noticeBody(end.reply!));
+ return notice;
+ }
+
+ /// The agent stopped to ask the person [prompt]. [requestId] is the
+ /// daemon's id for it, which a re-announce repeats.
+ AgentNotice questionAsked(
+ NoticeAgent agent, {
+ required String requestId,
+ required String prompt,
+ required bool Function() watching,
+ }) {
+ final front = inFront;
+ final notice = decideQuestionNotice(
+ isNew: _asked.hear(agent.ref, requestId),
+ inFront: front,
+ watching: front && watching(),
+ );
+ _deliver(agent, notice, NoticeKind.question, () => noticeBody(prompt));
+ return notice;
+ }
+
+ /// The question is off the pane — answered here, by hand, on another client
+ /// or on the dial. Its mark and its notice go with it: news nobody can act
+ /// on any more is not news. A finished turn's mark is left alone.
+ void questionClosed(AgentRef ref, {String? requestId}) {
+ if (!_asked.forget(ref, requestId: requestId)) return;
+ if (unread.kindFor(ref) != NoticeKind.question) return;
+ unread.clear(ref, kind: NoticeKind.question);
+ system.cancel(ref);
+ }
+
+ /// The agent is gone. An agent that no longer exists cannot be gone to, and
+ /// a notice about it would open nothing.
+ void forgetAgent(AgentRef ref) {
+ _asked.forget(ref);
+ if (!unread.contains(ref)) return;
+ unread.clear(ref);
+ system.cancel(ref);
+ }
+
+ /// Signed out: nothing any of it was about is this person's any more.
+ void reset() {
+ unread.clearAll();
+ _asked.clear();
+ }
+
+ void _deliver(
+ NoticeAgent agent,
+ AgentNotice notice,
+ NoticeKind kind,
+ String Function() body,
+ ) {
+ if (notice.chimes && inFront) _chime();
+ if (notice.marks) unread.mark(agent.ref, kind);
+ if (!notice.alerts) return;
+ system.show((
+ agent: agent.ref,
+ kind: kind,
+ title: agent.name,
+ machine: agent.machine,
+ body: body(),
+ ));
+ }
+
+ /// [system] is left alone: the shell may still be letting go of its
+ /// [SystemNotices.opened] after the notifier has gone.
+ void dispose() => unread.dispose();
+}
+
+/// The text, cut to what a lock screen shows: its last paragraph — where an
+/// agent says what it did — on one line, at most [limit] characters.
+String noticeBody(String text, {int limit = 180}) {
+ final paragraphs = text
+ .trim()
+ .split(RegExp(r'\n\s*\n'))
+ .where((p) => p.trim().isNotEmpty);
+ final last = paragraphs.isEmpty ? text : paragraphs.last;
+ final line = last.replaceAll(RegExp(r'\s+'), ' ').trim();
+ if (line.length <= limit) return line;
+ return '${line.substring(0, limit - 1).trimRight()}…';
+}
diff --git a/mobile/lib/notify/agent_notice.dart b/mobile/lib/notify/agent_notice.dart
new file mode 100644
index 000000000..ef8a932b2
--- /dev/null
+++ b/mobile/lib/notify/agent_notice.dart
@@ -0,0 +1,41 @@
+/// What the phone says about an agent, and how loudly — shared by the two
+/// things the dial announces: a turn that finished (`done_notice.dart`) and a
+/// question waiting on the person (`question_notice.dart`).
+library;
+
+/// What the news is. The NEWEST kind wins on an agent: one that finished and
+/// then asked something is waiting on a person, and that is the mark worth
+/// showing — the desktop's `AgentUnread` rule.
+enum NoticeKind { done, question }
+
+/// How far one piece of news goes — escalating, each step doing everything the
+/// one before it does.
+enum AgentNotice {
+ /// Not news. Nothing at all.
+ none,
+
+ /// The person is looking straight at this agent. The tap still comes — the
+ /// dial's beep ALWAYS sounds — but nothing is filed for later: they are
+ /// already where the news is.
+ chime,
+
+ /// The app is in front of the person, on something else. Chime, and mark the
+ /// agent — the dial's badge.
+ mark,
+
+ /// The app is not in front of anybody. Mark it, and post a system
+ /// notification — the dial waking its dark panel.
+ alert;
+
+ bool get chimes => this != none;
+ bool get marks => this == mark || this == alert;
+ bool get alerts => this == alert;
+}
+
+/// How far news that IS news goes, by where the person is. [watching] — the
+/// agent on screen is the one it is about — only counts in front.
+AgentNotice escalate({required bool inFront, required bool watching}) {
+ if (!inFront) return AgentNotice.alert;
+ if (watching) return AgentNotice.chime;
+ return AgentNotice.mark;
+}
diff --git a/mobile/lib/notify/agent_unread.dart b/mobile/lib/notify/agent_unread.dart
index 42bac25f5..bfc654476 100644
--- a/mobile/lib/notify/agent_unread.dart
+++ b/mobile/lib/notify/agent_unread.dart
@@ -2,32 +2,51 @@ import 'package:flutter/foundation.dart';
import 'package:harness_mobile/core/last_opened_agent.dart';
-/// Which agents finished while the person was looking somewhere else.
+import 'agent_notice.dart';
+
+/// Which agents have news the person has not gone to yet, and what it is.
///
/// The phone's half of the desktop's `AgentUnread` (`desktop/lib/notify/
/// agent_alerts.dart`) and of the dial's bell badge: a mark that sits still
/// until somebody goes to that agent. Its own notifier rather than app state,
/// so a mark appearing redraws the rows that show it and nothing else.
class AgentUnread extends ChangeNotifier {
- final _unread = <String>{};
+ final _unread = <String, NoticeKind>{};
static String _key(AgentRef ref) => '${ref.machineId}/${ref.agentId}';
- /// How many agents are carrying news. Agents, not turns — the number answers
- /// "how many should I look at", and an agent that finished three turns is
- /// still one place to go.
+ /// How many agents are carrying news. Agents, not events — the number
+ /// answers "how many should I look at", and an agent that finished three
+ /// turns is still one place to go.
int get count => _unread.length;
- bool contains(AgentRef ref) => _unread.contains(_key(ref));
+ /// Whether any of them is waiting on the person, which is what the count's
+ /// colour says.
+ bool get anyQuestion => _unread.containsValue(NoticeKind.question);
+
+ bool contains(AgentRef ref) => _unread.containsKey(_key(ref));
+
+ /// What this agent's mark says, or null when it has none.
+ NoticeKind? kindFor(AgentRef ref) => _unread[_key(ref)];
- void mark(AgentRef ref) {
- if (_unread.add(_key(ref))) notifyListeners();
+ /// The NEWEST kind wins — see [NoticeKind].
+ void mark(AgentRef ref, NoticeKind kind) {
+ final key = _key(ref);
+ if (_unread[key] == kind) return;
+ _unread[key] = kind;
+ notifyListeners();
}
- /// The person went and looked. Silent when there was nothing to clear, so a
- /// pane being focused for any other reason does not redraw anything.
- void clear(AgentRef ref) {
- if (_unread.remove(_key(ref))) notifyListeners();
+ /// The person went and looked — or, with [kind], only that kind of news went
+ /// away: a question answered elsewhere takes its own mark down, and leaves a
+ /// finished turn's alone. Silent when there was nothing to clear, so a pane
+ /// being focused for any other reason does not redraw anything.
+ void clear(AgentRef ref, {NoticeKind? kind}) {
+ final key = _key(ref);
+ if (!_unread.containsKey(key)) return;
+ if (kind != null && _unread[key] != kind) return;
+ _unread.remove(key);
+ notifyListeners();
}
void clearAll() {
diff --git a/mobile/lib/notify/done_announcer.dart b/mobile/lib/notify/done_announcer.dart
deleted file mode 100644
index 1c5397c9f..000000000
--- a/mobile/lib/notify/done_announcer.dart
+++ /dev/null
@@ -1,95 +0,0 @@
-import 'package:flutter/services.dart';
-import 'package:flutter/widgets.dart';
-
-import 'package:harness_mobile/core/last_opened_agent.dart';
-
-import 'agent_unread.dart';
-import 'done_notice.dart';
-import 'system_notices.dart';
-
-/// Who finished, in the words the notice uses.
-typedef DoneAgent = ({AgentRef ref, String name, String machine});
-
-/// Carries out [decideDoneNotice]: the chime, the unread mark, the system
-/// notice. The notifier says what happened; this decides what it is worth and
-/// does it, so none of the three can drift from the rule.
-class DoneAnnouncer {
- DoneAnnouncer({
- required this.system,
- Future<void> Function()? chime,
- bool Function()? inFront,
- }) : _chime = chime ?? _haptic,
- _inFront = inFront ?? _appInFront;
-
- final SystemNotices system;
- final unread = AgentUnread();
- final Future<void> Function() _chime;
- final bool Function() _inFront;
-
- /// The dial's three tones, as a phone says them without a sound: a tap the
- /// hand feels even with the ringer off. Never worth an error — a plain
- /// `test()` has no binding to send it through.
- static Future<void> _haptic() async {
- try {
- await HapticFeedback.mediumImpact();
- } catch (_) {}
- }
-
- /// Whether the app is on screen. ⚠️ Tolerant of there being NO binding, as
- /// the desktop's `lifecycle` is: plain `test()`s drive the notifier without
- /// one, and `WidgetsBinding.instance` throws rather than answering null.
- /// Unknown counts as in front, which errs toward a mark over a notice.
- static bool _appInFront() {
- try {
- final state = WidgetsBinding.instance.lifecycleState;
- return state == null || state == AppLifecycleState.resumed;
- } catch (_) {
- return true;
- }
- }
-
- bool get inFront => _inFront();
-
- /// One turn ended. [watching] is whether [agent] is the one on screen —
- /// only asked when the app is in front.
- DoneNotice turnEnded(
- DoneAgent agent,
- TurnEnd end, {
- required bool Function() watching,
- }) {
- final front = inFront;
- final notice = decideDoneNotice(
- end,
- inFront: front,
- watching: front && watching(),
- );
- if (notice.chimes && front) _chime();
- if (notice.marks) unread.mark(agent.ref);
- if (notice.alerts) {
- system.show((
- agent: agent.ref,
- title: agent.name,
- machine: agent.machine,
- body: noticeBody(end.reply!),
- ));
- }
- return notice;
- }
-
- /// [system] is left alone: the shell may still be letting go of its
- /// [SystemNotices.opened] after the notifier has gone.
- void dispose() => unread.dispose();
-}
-
-/// The reply, cut to what a lock screen shows: its last paragraph — where an
-/// agent says what it did — on one line, at most [limit] characters.
-String noticeBody(String reply, {int limit = 180}) {
- final paragraphs = reply
- .trim()
- .split(RegExp(r'\n\s*\n'))
- .where((p) => p.trim().isNotEmpty);
- final last = paragraphs.isEmpty ? reply : paragraphs.last;
- final line = last.replaceAll(RegExp(r'\s+'), ' ').trim();
- if (line.length <= limit) return line;
- return '${line.substring(0, limit - 1).trimRight()}…';
-}
diff --git a/mobile/lib/notify/done_notice.dart b/mobile/lib/notify/done_notice.dart
index 22b34399e..8e058bcb4 100644
--- a/mobile/lib/notify/done_notice.dart
+++ b/mobile/lib/notify/done_notice.dart
@@ -6,6 +6,8 @@
/// step — a turn the dial stays quiet about must not make the phone buzz.
library;
+import 'agent_notice.dart';
+
/// One turn's end, as the machine socket reported it.
///
/// The flags come straight off the `turn_ended` frame. Every one of them is
@@ -45,45 +47,17 @@ TurnEnd turnEndFrom(
reply: reply,
);
-/// What the phone does about one finished turn — escalating, each step doing
-/// everything the one before it does.
-enum DoneNotice {
- /// Not news. Nothing at all.
- none,
-
- /// The person is looking straight at this agent. The tap still comes — the
- /// dial's beep ALWAYS sounds, because somebody reading the last reply is not
- /// watching for the next to end — but nothing is filed for later: they are
- /// already where the news is.
- chime,
-
- /// The app is in front of the person, on something else. Chime, and mark the
- /// agent unread — the dial's badge. Never more than that: an agent finishing
- /// elsewhere must not yank anybody off what they are doing.
- mark,
-
- /// The app is not in front of anybody. Mark it, and post a system
- /// notification — the dial waking its dark panel onto the drawer.
- alert;
-
- bool get chimes => this != none;
- bool get marks => this == mark || this == alert;
- bool get alerts => this == alert;
-}
-
/// Decides what one turn's end is worth.
///
/// [inFront] is whether the app is on screen at all; [watching] whether the
/// agent it is showing is the one that finished — only meaningful in front.
-DoneNotice decideDoneNotice(
+AgentNotice decideDoneNotice(
TurnEnd end, {
required bool inFront,
required bool watching,
}) {
- if (end.aborted || end.replay || end.subagent) return DoneNotice.none;
+ if (end.aborted || end.replay || end.subagent) return AgentNotice.none;
final reply = end.reply;
- if (reply == null || reply.trim().isEmpty) return DoneNotice.none;
- if (!inFront) return DoneNotice.alert;
- if (watching) return DoneNotice.chime;
- return DoneNotice.mark;
+ if (reply == null || reply.trim().isEmpty) return AgentNotice.none;
+ return escalate(inFront: inFront, watching: watching);
}
diff --git a/mobile/lib/notify/question_notice.dart b/mobile/lib/notify/question_notice.dart
new file mode 100644
index 000000000..a816e8ccc
--- /dev/null
+++ b/mobile/lib/notify/question_notice.dart
@@ -0,0 +1,70 @@
+/// The dial's rule for a question waiting on the person, on a phone.
+///
+/// Ported from `ui_question_show` / `ui_question_close` in
+/// `devices/harness-device/firmware/main/ui/ui_screens.c`, and the `question`
+/// frames in `firmware/main/cable_client.c`. Keep the two in step.
+///
+/// What the dial does: a NEW question wakes the panel, takes the screen and
+/// beeps; the same request heard again — the daemon re-announces every open
+/// question after a reconnect — does nothing; a question answered anywhere
+/// else is taken down. The phone takes the same three steps, except that it
+/// never takes the screen from the agent somebody is looking at: a phone's
+/// terminal is the whole screen, and swapping it out under a thumb is not a
+/// notice, it is losing your place. The mark and the count say where to go.
+library;
+
+import 'package:harness_mobile/core/last_opened_agent.dart';
+
+import 'agent_notice.dart';
+
+/// Which question each agent was last announced for.
+///
+/// Its own memory, and NOT the notifier's `blockedAgents`: that map is emptied
+/// whenever a machine's socket drops — which a phone does every time it goes
+/// into a pocket — and the daemon re-announces every open question on the way
+/// back. Read from there, each return to the app would buzz again for every
+/// question already known. Only the question's own end forgets it here.
+class AskedQuestions {
+ final _asked = <String, String>{};
+
+ static String _key(AgentRef ref) => '${ref.machineId}/${ref.agentId}';
+
+ /// Whether this is the first time [requestId] is heard for [ref], recording
+ /// it either way. A different request on the same agent — the dialog moved
+ /// on to its next page — is new.
+ bool hear(AgentRef ref, String requestId) {
+ final key = _key(ref);
+ if (_asked[key] == requestId) return false;
+ _asked[key] = requestId;
+ return true;
+ }
+
+ /// The question stopped being on screen — answered, or its turn ended. An
+ /// empty or null [requestId] means whichever one was open; a different one
+ /// is a stale close for a question already replaced, and is ignored.
+ ///
+ /// Returns whether anything was forgotten.
+ bool forget(AgentRef ref, {String? requestId}) {
+ final key = _key(ref);
+ final open = _asked[key];
+ if (open == null) return false;
+ if (requestId != null && requestId.isNotEmpty && requestId != open) {
+ return false;
+ }
+ _asked.remove(key);
+ return true;
+ }
+
+ void clear() => _asked.clear();
+}
+
+/// What a question is worth. Only a NEW one is news; after that it is the same
+/// escalation a finished turn gets.
+AgentNotice decideQuestionNotice({
+ required bool isNew,
+ required bool inFront,
+ required bool watching,
+}) {
+ if (!isNew) return AgentNotice.none;
+ return escalate(inFront: inFront, watching: watching);
+}
diff --git a/mobile/lib/notify/system_notices.dart b/mobile/lib/notify/system_notices.dart
index e5e0e471a..669305281 100644
--- a/mobile/lib/notify/system_notices.dart
+++ b/mobile/lib/notify/system_notices.dart
@@ -4,11 +4,14 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:harness_mobile/core/last_opened_agent.dart';
import 'package:harness_mobile/logging/app_log.dart';
-/// One "agent finished" notice, as the OS draws it: the agent's name, the
-/// machine it runs on, and what the turn said — the three lines of the dial's
-/// drawer row.
-typedef DoneNoticeMessage = ({
+import 'agent_notice.dart';
+
+/// One notice about one agent, as the OS draws it: the agent's name, the
+/// machine it runs on, and the news — what the turn said, or what it is asking
+/// — the three lines of the dial's drawer row.
+typedef AgentNoticeMessage = ({
AgentRef agent,
+ NoticeKind kind,
String title,
String machine,
String body,
@@ -23,7 +26,11 @@ abstract interface class SystemNotices {
/// remembers the answer; asking again is a no-op.
Future<void> requestPermission();
- Future<void> show(DoneNoticeMessage message);
+ Future<void> show(AgentNoticeMessage message);
+
+ /// Takes [agent]'s notice back down — its question was answered somewhere
+ /// else, so the lock screen must stop asking.
+ Future<void> cancel(AgentRef agent);
/// The agent whose notice was tapped last — what the shell opens. Reset to
/// null by whoever acts on it.
@@ -39,7 +46,10 @@ class SilentSystemNotices implements SystemNotices {
Future<void> requestPermission() async {}
@override
- Future<void> show(DoneNoticeMessage message) async {}
+ Future<void> show(AgentNoticeMessage message) async {}
+
+ @override
+ Future<void> cancel(AgentRef agent) async {}
}
/// The real centre, through flutter_local_notifications.
@@ -56,13 +66,21 @@ class LocalSystemNotices implements SystemNotices {
@override
final opened = ValueNotifier<AgentRef?>(null);
- static const _channel = AndroidNotificationDetails(
- 'agent-done',
- 'Agent finished',
- channelDescription: 'An agent finished its turn while Harness was away.',
- importance: Importance.high,
- priority: Priority.high,
- );
+ /// One Android channel per kind, so a person can silence finished turns and
+ /// still hear questions — the two are not equally urgent. Also the iOS
+ /// thread each kind is grouped under.
+ static const _channels = {
+ NoticeKind.done: (
+ id: 'agent-done',
+ name: 'Agent finished',
+ description: 'An agent finished its turn while Harness was away.',
+ ),
+ NoticeKind.question: (
+ id: 'agent-question',
+ name: 'Agent needs you',
+ description: 'An agent stopped to ask you something.',
+ ),
+ };
Future<void> _init() => _ready ??= _start();
@@ -113,28 +131,30 @@ class LocalSystemNotices implements SystemNotices {
}
@override
- Future<void> show(DoneNoticeMessage message) async {
+ Future<void> show(AgentNoticeMessage message) async {
+ final channel = _channels[message.kind]!;
try {
await _init();
await _plugin.show(
- // One per AGENT: a newer turn replaces its own last notice rather than
- // stacking beside it — the desktop banner's rule.
+ // One per AGENT: newer news replaces its own last notice rather than
+ // stacking beside it — the desktop banner's rule, and the unread
+ // mark's: a question after a finish is the one that stands.
id: noticeIdFor(message.agent),
title: message.title,
body: message.body,
payload: encodeAgentPayload(message.agent),
notificationDetails: NotificationDetails(
android: AndroidNotificationDetails(
- _channel.channelId,
- _channel.channelName,
- channelDescription: _channel.channelDescription,
- importance: _channel.importance,
- priority: _channel.priority,
+ channel.id,
+ channel.name,
+ channelDescription: channel.description,
+ importance: Importance.high,
+ priority: Priority.high,
subText: message.machine,
),
iOS: DarwinNotificationDetails(
subtitle: message.machine,
- threadIdentifier: 'agent-done',
+ threadIdentifier: channel.id,
),
),
);
@@ -142,6 +162,16 @@ class LocalSystemNotices implements SystemNotices {
appLog.warn('notify', 'notice failed', error: error);
}
}
+
+ @override
+ Future<void> cancel(AgentRef agent) async {
+ try {
+ await _init();
+ await _plugin.cancel(id: noticeIdFor(agent));
+ } catch (error) {
+ appLog.warn('notify', 'cancel failed', error: error);
+ }
+ }
}
/// A stable, positive id per agent, so a notice replaces the last one for the
diff --git a/mobile/lib/notify/unread_marks.dart b/mobile/lib/notify/unread_marks.dart
index 3df5d0741..b455d78cb 100644
--- a/mobile/lib/notify/unread_marks.dart
+++ b/mobile/lib/notify/unread_marks.dart
@@ -2,14 +2,25 @@ import 'package:flutter/material.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'agent_notice.dart';
import 'agent_unread.dart';
-/// The mark on one agent's row: it finished while you were elsewhere.
+/// A mark's colour says what the news is: amber for an agent waiting on you —
+/// the phone's "Waiting for you" tone — and the accent for one that finished.
+Color unreadColor(NoticeKind kind) => switch (kind) {
+ NoticeKind.question => AppPalette.warn,
+ NoticeKind.done => AppPalette.accent,
+};
+
+/// The mark on one agent's row: it finished, or asked something, while you
+/// were elsewhere.
///
-/// The row's own unread dot, iOS Mail's — small and in the accent, before the
-/// name, so it reads before the name does and never pushes anything else off.
+/// The row's own unread dot, iOS Mail's — small, before the name, so it reads
+/// before the name does and never pushes anything else off.
class UnreadDot extends StatelessWidget {
- const UnreadDot({super.key});
+ const UnreadDot({super.key, required this.kind});
+
+ final NoticeKind kind;
static const double diameter = 8;
@@ -19,10 +30,7 @@ class UnreadDot extends StatelessWidget {
width: diameter,
height: diameter,
margin: const EdgeInsets.only(right: 7),
- decoration: const BoxDecoration(
- color: AppPalette.accent,
- shape: BoxShape.circle,
- ),
+ decoration: BoxDecoration(color: unreadColor(kind), shape: BoxShape.circle),
);
}
@@ -55,7 +63,16 @@ class UnreadCountBadge extends StatelessWidget {
Positioned(
top: -4,
right: -4,
- child: IgnorePointer(child: _CountPill(count: count)),
+ child: IgnorePointer(
+ child: _CountPill(
+ count: count,
+ // Amber as soon as ONE of them is waiting on you: that is
+ // the one the count is there to send you to.
+ color: unreadColor(
+ unread.anyQuestion ? NoticeKind.question : NoticeKind.done,
+ ),
+ ),
+ ),
),
],
);
@@ -64,9 +81,10 @@ class UnreadCountBadge extends StatelessWidget {
}
class _CountPill extends StatelessWidget {
- const _CountPill({required this.count});
+ const _CountPill({required this.count, required this.color});
final int count;
+ final Color color;
@override
Widget build(BuildContext context) => Container(
@@ -76,7 +94,7 @@ class _CountPill extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 5),
alignment: Alignment.center,
decoration: BoxDecoration(
- color: AppPalette.accent,
+ color: color,
borderRadius: BorderRadius.circular(9),
),
child: Text(
diff --git a/mobile/lib/phone/desk_tabs_panel.dart b/mobile/lib/phone/desk_tabs_panel.dart
index dbe4c8027..7d90012b2 100644
--- a/mobile/lib/phone/desk_tabs_panel.dart
+++ b/mobile/lib/phone/desk_tabs_panel.dart
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/core/last_opened_agent.dart' show AgentRef;
+import 'package:harness_mobile/notify/agent_notice.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/state/app_state.dart';
@@ -284,7 +285,7 @@ class _DeskTabsPanelState extends State<DeskTabsPanel> {
// The unread marks have their own notifier — see `notify/agent_unread.dart`.
listenable: Listenable.merge([
widget.notifier,
- widget.notifier.doneNotices.unread,
+ widget.notifier.agentNotices.unread,
]),
builder: (context, _) => _panel(context),
);
@@ -379,7 +380,7 @@ class _DeskTabsPanelState extends State<DeskTabsPanel> {
final entry = group.entries[index];
return DeskAgentRow(
entry: entry,
- unread: widget.notifier.doneNotices.unread.contains(
+ unread: widget.notifier.agentNotices.unread.kindFor(
_refOf(entry),
),
onScreen:
@@ -410,13 +411,13 @@ class DeskAgentRow extends StatelessWidget {
required this.first,
required this.last,
required this.onTap,
- this.unread = false,
+ this.unread,
});
final AgentEntry entry;
- /// It finished a turn while you were elsewhere — see [SheetAgentTitle.unread].
- final bool unread;
+ /// Its news nobody has gone to yet — see [SheetAgentTitle.unread].
+ final NoticeKind? unread;
/// The agent on screen. It keeps its row — it is the one you came from, and
/// the list would read as missing an agent without it — and wears the check
diff --git a/mobile/lib/phone/phone_shell.dart b/mobile/lib/phone/phone_shell.dart
index 6127feaab..0eaf9f3e9 100644
--- a/mobile/lib/phone/phone_shell.dart
+++ b/mobile/lib/phone/phone_shell.dart
@@ -62,7 +62,7 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
- final notices = widget.notifier.doneNotices.system;
+ final notices = widget.notifier.agentNotices.system;
notices.opened.addListener(_openNoticedAgent);
// Signed in is the first moment a notice could be worth anything, so it is
// the moment to ask. The OS keeps the answer; every later ask is a no-op.
@@ -72,7 +72,7 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
- widget.notifier.doneNotices.system.opened.removeListener(_openNoticedAgent);
+ widget.notifier.agentNotices.system.opened.removeListener(_openNoticedAgent);
_linkedMachineId.dispose();
_openAgentRequest.dispose();
for (final controller in _heroControllers.values) {
@@ -149,7 +149,7 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {
/// A tapped "agent finished" notice: that agent, as the home screen — the
/// dial's drawer row opening its agent.
void _openNoticedAgent() {
- final opened = widget.notifier.doneNotices.system.opened;
+ final opened = widget.notifier.agentNotices.system.opened;
final agent = opened.value;
if (agent == null) return;
opened.value = null;
diff --git a/mobile/lib/phone/sheet_agent_lines.dart b/mobile/lib/phone/sheet_agent_lines.dart
index b0a98f73a..1296fe8cb 100644
--- a/mobile/lib/phone/sheet_agent_lines.dart
+++ b/mobile/lib/phone/sheet_agent_lines.dart
@@ -3,6 +3,7 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/core/agent_output_stats.dart';
import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/notify/agent_notice.dart';
import 'package:harness_mobile/notify/unread_marks.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
@@ -61,14 +62,14 @@ class SheetAgentTitle extends StatelessWidget {
required this.entry,
required this.name,
required this.now,
- this.unread = false,
+ this.unread,
});
final AgentEntry entry;
- /// Whether the agent finished a turn nobody has looked at yet — see
- /// `notify/done_notice.dart`. Marked with an [UnreadDot] before the name.
- final bool unread;
+ /// The news this agent carries that nobody has gone to yet — a finished
+ /// turn or a question — or null. Marked with an [UnreadDot] before the name.
+ final NoticeKind? unread;
/// The name as the caller draws it — plain in the tabs, with the query's hits in bold in search.
final Widget name;
@@ -82,7 +83,7 @@ class SheetAgentTitle extends StatelessWidget {
final attention = agentAttention(entry);
return Row(
children: [
- if (unread) const UnreadDot(),
+ if (unread case final kind?) UnreadDot(kind: kind),
Flexible(child: name),
if (activity != null)
Padding(
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 015ff6226..5099faed3 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -1393,7 +1393,7 @@ class _TerminalPageState extends State<TerminalPage>
session: session,
onSearch: _openSearch,
unread:
- widget.notifier.doneNotices.unread,
+ widget.notifier.agentNotices.unread,
),
),
],
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 95c338eda..df0b7e65e 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -34,7 +34,7 @@ import '../core/project_history.dart';
import '../core/retry.dart';
import '../logging/app_log.dart';
import '../logging/startup_trace.dart';
-import '../notify/done_announcer.dart';
+import '../notify/agent_announcer.dart';
import '../notify/done_notice.dart';
import '../notify/system_notices.dart';
import '../settings/config_store.dart';
@@ -410,9 +410,9 @@ class AppNotifier extends ChangeNotifier {
),
);
- /// What a finished turn is worth — a tap, an unread mark, a system notice —
- /// decided by the dial's rule (`notify/done_notice.dart`).
- final DoneAnnouncer doneNotices;
+ /// What a finished turn or a question is worth — a tap, an unread mark, a
+ /// system notice — decided by the dial's rules (`notify/`).
+ final AgentAnnouncer agentNotices;
SessionPreviewKey previewKey(String machineId, Agent agent) =>
(machineId: machineId, agentId: agent.id, sessionId: agent.sessionId);
@@ -602,8 +602,7 @@ class AppNotifier extends ChangeNotifier {
/// A tab renamed by hand, from a double tap on its name in the tabs panel.
/// See [PhoneDesk.renameTab].
- void renameDeskTab(String tabId, String name) =>
- _desk.renameTab(tabId, name);
+ void renameDeskTab(String tabId, String name) => _desk.renameTab(tabId, name);
/// An agent that already exists opens a tab of its own — the `+` on the tab
/// row. See [PhoneDesk.createTabFor].
@@ -1274,7 +1273,7 @@ class AppNotifier extends ChangeNotifier {
}) : _paneLayout = paneLayoutStore,
// On the same terms as the stores below: no layout store means a test,
// which must never reach the OS notification centre.
- doneNotices = DoneAnnouncer(
+ agentNotices = AgentAnnouncer(
system:
systemNotices ??
(paneLayoutStore == null
@@ -2837,7 +2836,7 @@ class AppNotifier extends ChangeNotifier {
// ever read after a sign-in that this clears the way for.
unawaited(_machineCache?.clear());
sessionPreviews.clear();
- doneNotices.unread.clearAll();
+ agentNotices.reset();
expandedMachines.clear();
selectedMachineId = null;
status = AppStatus.unauthenticated;
@@ -4367,8 +4366,7 @@ class AppNotifier extends ChangeNotifier {
.where((agent) => agent.id != agentId)
.toList();
sessionPreviews.removeAgent(machine.machine.machineId, agentId);
- // An agent that no longer exists cannot be gone to.
- doneNotices.unread.clear((
+ agentNotices.forgetAgent((
machineId: machine.machine.machineId,
agentId: agentId,
));
@@ -6953,6 +6951,11 @@ class AppNotifier extends ChangeNotifier {
known != null && known.sameAs(asked)
? asked.withSince(known.since)
: asked;
+ // Whether it is NEWS is the announcer's to say, not [known]'s:
+ // `blockedAgents` is emptied on every dropped socket, and the
+ // re-announce that follows is the same question — see
+ // `notify/question_notice.dart`.
+ _announceQuestion(machine, asked);
}
}
break;
@@ -6972,6 +6975,10 @@ class AppNotifier extends ChangeNotifier {
open.requestId == requestId)) {
machine.blockedAgents.remove(agentId);
}
+ agentNotices.questionClosed((
+ machineId: machine.machine.machineId,
+ agentId: agentId,
+ ), requestId: requestId is String ? requestId : null);
}
break;
case 'turn_started':
@@ -7071,7 +7078,7 @@ class AppNotifier extends ChangeNotifier {
/// The agent on screen, when the app is in front of anybody.
AgentRef? get _watchedAgent {
- if (!doneNotices.inFront) return null;
+ if (!agentNotices.inFront) return null;
final pane = focusedPane;
final agentId = pane?.agentId;
if (pane == null || agentId == null) return null;
@@ -7080,9 +7087,21 @@ class AppNotifier extends ChangeNotifier {
void _seeWatchedAgent() {
final watched = _watchedAgent;
- if (watched != null) doneNotices.unread.clear(watched);
+ if (watched != null) agentNotices.unread.clear(watched);
}
+ /// [agent] on [machine], as a notice names it.
+ NoticeAgent _noticeAgent(MachineState machine, Agent agent) => (
+ ref: (machineId: machine.machine.machineId, agentId: agent.id),
+ name: agent.displayName,
+ machine: machine.machine.displayName,
+ );
+
+ /// An agent this phone has not been told about is never announced: a notice
+ /// about it could not open anything.
+ Agent? _knownAgent(MachineState machine, String agentId) =>
+ machine.agents.where((a) => a.id == agentId).firstOrNull;
+
/// One agent's turn ended: tell the person as the dial would — see
/// `notify/done_notice.dart` for when that is a tap, a mark or a notice.
void _announceTurnEnd(
@@ -7091,19 +7110,33 @@ class AppNotifier extends ChangeNotifier {
Map<String, dynamic> event,
Map<String, dynamic> payload,
) {
- final agent = machine.agents.where((a) => a.id == agentId).firstOrNull;
+ final agent = _knownAgent(machine, agentId);
if (agent == null) return;
- final ref = (machineId: machine.machine.machineId, agentId: agentId);
- doneNotices.turnEnded(
- (ref: ref, name: agent.displayName, machine: machine.machine.displayName),
+ final who = _noticeAgent(machine, agent);
+ agentNotices.turnEnded(
+ who,
turnEndFrom(
event,
payload,
reply: sessionPreviews
- .read(previewKey(ref.machineId, agent))
+ .read(previewKey(who.ref.machineId, agent))
?.turnReply,
),
- watching: () => _watchedAgent == ref,
+ watching: () => _watchedAgent == who.ref,
+ );
+ }
+
+ /// An agent stopped to ask the person something — see
+ /// `notify/question_notice.dart`.
+ void _announceQuestion(MachineState machine, PendingQuestion asked) {
+ final agent = _knownAgent(machine, asked.agentId);
+ if (agent == null) return;
+ final who = _noticeAgent(machine, agent);
+ agentNotices.questionAsked(
+ who,
+ requestId: asked.requestId,
+ prompt: asked.prompt,
+ watching: () => _watchedAgent == who.ref,
);
}
@@ -7163,7 +7196,7 @@ class AppNotifier extends ChangeNotifier {
}
unawaited(_spokenTasks.close());
sessionPreviews.dispose();
- doneNotices.dispose();
+ agentNotices.dispose();
_desk.dispose();
super.dispose();
}
diff --git a/mobile/test/notify/agent_announcer_test.dart b/mobile/test/notify/agent_announcer_test.dart
new file mode 100644
index 000000000..4e9470191
--- /dev/null
+++ b/mobile/test/notify/agent_announcer_test.dart
@@ -0,0 +1,205 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:harness_mobile/core/last_opened_agent.dart';
+import 'package:harness_mobile/notify/agent_announcer.dart';
+import 'package:harness_mobile/notify/agent_notice.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+
+class _RecordingNotices implements SystemNotices {
+ final shown = <AgentNoticeMessage>[];
+ final cancelled = <AgentRef>[];
+
+ @override
+ final opened = ValueNotifier<AgentRef?>(null);
+
+ @override
+ Future<void> requestPermission() async {}
+
+ @override
+ Future<void> show(AgentNoticeMessage message) async => shown.add(message);
+
+ @override
+ Future<void> cancel(AgentRef agent) async => cancelled.add(agent);
+}
+
+void main() {
+ const ref = (machineId: 'm', agentId: 'a');
+ const agent = (ref: ref, name: 'Fix login', machine: 'MacBook');
+ const news = (
+ aborted: false,
+ replay: false,
+ subagent: false,
+ reply: 'Looked at the form.\n\nFixed the login screen and pushed.',
+ );
+
+ late _RecordingNotices system;
+ late int chimes;
+ late bool front;
+ late AgentAnnouncer announcer;
+
+ setUp(() {
+ system = _RecordingNotices();
+ chimes = 0;
+ front = true;
+ announcer = AgentAnnouncer(
+ system: system,
+ chime: () async => chimes++,
+ inFront: () => front,
+ );
+ addTearDown(announcer.dispose);
+ });
+
+ test('watching: a chime, no mark, no notice', () {
+ final notice = announcer.turnEnded(agent, news, watching: () => true);
+
+ expect(notice, AgentNotice.chime);
+ expect(chimes, 1);
+ expect(announcer.unread.count, 0);
+ expect(system.shown, isEmpty);
+ });
+
+ test('elsewhere in the app: a chime and a mark, no notice', () {
+ announcer.turnEnded(agent, news, watching: () => false);
+
+ expect(chimes, 1);
+ expect(announcer.unread.contains(ref), isTrue);
+ expect(system.shown, isEmpty);
+ });
+
+ test(
+ 'away: a mark and one notice naming the agent, its machine, its news',
+ () {
+ front = false;
+ announcer.turnEnded(agent, news, watching: () => true);
+
+ expect(chimes, 0, reason: 'nobody is holding a backgrounded app');
+ expect(announcer.unread.contains(ref), isTrue);
+ expect(system.shown, hasLength(1));
+ final shown = system.shown.single;
+ expect(shown.agent, ref);
+ expect(shown.title, 'Fix login');
+ expect(shown.machine, 'MacBook');
+ expect(shown.body, 'Fixed the login screen and pushed.');
+ },
+ );
+
+ test('a sub-agent turn does nothing at all, even away', () {
+ front = false;
+ announcer.turnEnded(agent, (
+ aborted: false,
+ replay: false,
+ subagent: true,
+ reply: 'x',
+ ), watching: () => false);
+
+ expect(chimes, 0);
+ expect(announcer.unread.count, 0);
+ expect(system.shown, isEmpty);
+ });
+
+ test('an agent is one mark however many turns it finished', () {
+ announcer.turnEnded(agent, news, watching: () => false);
+ announcer.turnEnded(agent, news, watching: () => false);
+
+ expect(announcer.unread.count, 1);
+ announcer.unread.clear(ref);
+ expect(announcer.unread.count, 0);
+ });
+
+ group('questions', () {
+ AgentNotice ask({String id = 'q1', bool watching = false}) =>
+ announcer.questionAsked(
+ agent,
+ requestId: id,
+ prompt: 'Which database?',
+ watching: () => watching,
+ );
+
+ test('a new question elsewhere: a chime and a question mark', () {
+ expect(ask(), AgentNotice.mark);
+ expect(chimes, 1);
+ expect(announcer.unread.kindFor(ref), NoticeKind.question);
+ expect(announcer.unread.anyQuestion, isTrue);
+ });
+
+ test('the same question heard again is not news', () {
+ ask();
+ expect(ask(), AgentNotice.none);
+ expect(chimes, 1);
+ });
+
+ test('the dialog moving to its next page is a new question', () {
+ ask();
+ expect(ask(id: 'q2'), AgentNotice.mark);
+ });
+
+ test('away: one notice, of the question kind, saying the question', () {
+ front = false;
+ ask();
+ final shown = system.shown.single;
+ expect(shown.kind, NoticeKind.question);
+ expect(shown.body, 'Which database?');
+ });
+
+ test('answered elsewhere: its mark and its notice come down', () {
+ front = false;
+ ask();
+ announcer.questionClosed(ref, requestId: 'q1');
+ expect(announcer.unread.contains(ref), isFalse);
+ expect(system.cancelled, [ref]);
+ });
+
+ test('a stale close leaves the question that replaced it', () {
+ ask();
+ ask(id: 'q2');
+ announcer.questionClosed(ref, requestId: 'q1');
+ expect(announcer.unread.kindFor(ref), NoticeKind.question);
+ expect(system.cancelled, isEmpty);
+ });
+
+ test('a close never takes down a finished turn\'s mark', () {
+ announcer.turnEnded(agent, news, watching: () => false);
+ announcer.questionClosed(ref);
+ expect(announcer.unread.kindFor(ref), NoticeKind.done);
+ });
+
+ test('the question after a finish is the mark that stands', () {
+ announcer.turnEnded(agent, news, watching: () => false);
+ ask();
+ expect(announcer.unread.kindFor(ref), NoticeKind.question);
+ });
+
+ test('its turn ending with nothing to say takes the question down', () {
+ ask();
+ announcer.turnEnded(agent, (
+ aborted: false,
+ replay: false,
+ subagent: false,
+ reply: null,
+ ), watching: () => false);
+ expect(announcer.unread.contains(ref), isFalse);
+ expect(ask(), AgentNotice.mark, reason: 'a new turn may ask it again');
+ });
+
+ test('a deleted agent takes its mark and its notice with it', () {
+ front = false;
+ ask();
+ announcer.forgetAgent(ref);
+ expect(announcer.unread.contains(ref), isFalse);
+ expect(system.cancelled, [ref]);
+ });
+ });
+
+ group('noticeBody', () {
+ test('keeps the last paragraph, on one line', () {
+ expect(noticeBody('a\n\nb c\nd'), 'b c d');
+ });
+
+ test('cuts a long reply with an ellipsis', () {
+ final body = noticeBody('x' * 400, limit: 20);
+ expect(body.length, 20);
+ expect(body.endsWith('…'), isTrue);
+ });
+ });
+}
diff --git a/mobile/test/notify/app_done_notice_test.dart b/mobile/test/notify/app_notice_test.dart
similarity index 55%
rename from mobile/test/notify/app_done_notice_test.dart
rename to mobile/test/notify/app_notice_test.dart
index 3cb08fbe3..867c5e276 100644
--- a/mobile/test/notify/app_done_notice_test.dart
+++ b/mobile/test/notify/app_notice_test.dart
@@ -1,5 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/agent_notice.dart';
import 'package:harness_mobile/state/app_state.dart';
import '../agent_pager_fixture.dart';
@@ -27,8 +28,33 @@ void main() {
await send('turn_ended', endPayload);
}
+ Future<void> ask(AppNotifier app, String agentId, {String id = 'q1'}) =>
+ app.handleEventForTest('m', {
+ 'type': 'commander_question',
+ 'agentId': agentId,
+ 'payload': {
+ 'requestId': id,
+ 'questions': [
+ {
+ 'q': 'Which database?',
+ 'options': ['Postgres', 'SQLite'],
+ },
+ ],
+ },
+ });
+
+ Future<void> closeQuestion(AppNotifier app, String agentId, String id) =>
+ app.handleEventForTest('m', {
+ 'type': 'commander_question_close',
+ 'agentId': agentId,
+ 'payload': {'requestId': id},
+ });
+
+ NoticeKind? kindOf(AppNotifier app, String agentId) =>
+ app.agentNotices.unread.kindFor((machineId: 'm', agentId: agentId));
+
bool unread(AppNotifier app, String agentId) =>
- app.doneNotices.unread.contains((machineId: 'm', agentId: agentId));
+ app.agentNotices.unread.contains((machineId: 'm', agentId: agentId));
late AppNotifier app;
@@ -41,7 +67,7 @@ void main() {
test('an agent finishing elsewhere is marked', () async {
await turn(app, 'b');
expect(unread(app, 'b'), isTrue);
- expect(app.doneNotices.unread.count, 1);
+ expect(app.agentNotices.unread.count, 1);
});
test('the agent on screen is never marked', () async {
@@ -54,12 +80,12 @@ void main() {
await turn(app, 'b', endPayload: {'aborted': true});
await turn(app, 'b', end: {'subagent': true});
await turn(app, 'b', end: {'replay': true});
- expect(app.doneNotices.unread.count, 0);
+ expect(app.agentNotices.unread.count, 0);
});
test('a turn with nothing to say does not borrow the last one', () async {
await turn(app, 'b');
- app.doneNotices.unread.clearAll();
+ app.agentNotices.unread.clearAll();
await turn(app, 'b', reply: null);
expect(unread(app, 'b'), isFalse);
});
@@ -79,4 +105,31 @@ void main() {
});
expect(unread(app, 'b'), isFalse);
});
+
+ group('questions', () {
+ test('a question elsewhere is marked as one', () async {
+ await ask(app, 'b');
+ expect(kindOf(app, 'b'), NoticeKind.question);
+ });
+
+ test('the agent on screen asking is never marked', () async {
+ await ask(app, 'a');
+ expect(unread(app, 'a'), isFalse);
+ });
+
+ test('answered elsewhere, the mark goes', () async {
+ await ask(app, 'b');
+ await closeQuestion(app, 'b', 'q1');
+ expect(unread(app, 'b'), isFalse);
+ });
+
+ test('a reconnect re-announcing it does not make it new', () async {
+ await ask(app, 'b');
+ app.agentNotices.unread.clearAll();
+ // The disconnect sweep empties `blockedAgents`; the daemon re-announces.
+ app.stateOf('m')!.blockedAgents.clear();
+ await ask(app, 'b');
+ expect(unread(app, 'b'), isFalse);
+ });
+ });
}
diff --git a/mobile/test/notify/done_announcer_test.dart b/mobile/test/notify/done_announcer_test.dart
deleted file mode 100644
index c727685db..000000000
--- a/mobile/test/notify/done_announcer_test.dart
+++ /dev/null
@@ -1,117 +0,0 @@
-import 'package:flutter/foundation.dart';
-import 'package:flutter_test/flutter_test.dart';
-
-import 'package:harness_mobile/core/last_opened_agent.dart';
-import 'package:harness_mobile/notify/done_announcer.dart';
-import 'package:harness_mobile/notify/done_notice.dart';
-import 'package:harness_mobile/notify/system_notices.dart';
-
-class _RecordingNotices implements SystemNotices {
- final shown = <DoneNoticeMessage>[];
-
- @override
- final opened = ValueNotifier<AgentRef?>(null);
-
- @override
- Future<void> requestPermission() async {}
-
- @override
- Future<void> show(DoneNoticeMessage message) async => shown.add(message);
-}
-
-void main() {
- const ref = (machineId: 'm', agentId: 'a');
- const agent = (ref: ref, name: 'Fix login', machine: 'MacBook');
- const news = (
- aborted: false,
- replay: false,
- subagent: false,
- reply: 'Looked at the form.\n\nFixed the login screen and pushed.',
- );
-
- late _RecordingNotices system;
- late int chimes;
- late bool front;
- late DoneAnnouncer announcer;
-
- setUp(() {
- system = _RecordingNotices();
- chimes = 0;
- front = true;
- announcer = DoneAnnouncer(
- system: system,
- chime: () async => chimes++,
- inFront: () => front,
- );
- addTearDown(announcer.dispose);
- });
-
- test('watching: a chime, no mark, no notice', () {
- final notice = announcer.turnEnded(agent, news, watching: () => true);
-
- expect(notice, DoneNotice.chime);
- expect(chimes, 1);
- expect(announcer.unread.count, 0);
- expect(system.shown, isEmpty);
- });
-
- test('elsewhere in the app: a chime and a mark, no notice', () {
- announcer.turnEnded(agent, news, watching: () => false);
-
- expect(chimes, 1);
- expect(announcer.unread.contains(ref), isTrue);
- expect(system.shown, isEmpty);
- });
-
- test(
- 'away: a mark and one notice naming the agent, its machine, its news',
- () {
- front = false;
- announcer.turnEnded(agent, news, watching: () => true);
-
- expect(chimes, 0, reason: 'nobody is holding a backgrounded app');
- expect(announcer.unread.contains(ref), isTrue);
- expect(system.shown, hasLength(1));
- final shown = system.shown.single;
- expect(shown.agent, ref);
- expect(shown.title, 'Fix login');
- expect(shown.machine, 'MacBook');
- expect(shown.body, 'Fixed the login screen and pushed.');
- },
- );
-
- test('a sub-agent turn does nothing at all, even away', () {
- front = false;
- announcer.turnEnded(agent, (
- aborted: false,
- replay: false,
- subagent: true,
- reply: 'x',
- ), watching: () => false);
-
- expect(chimes, 0);
- expect(announcer.unread.count, 0);
- expect(system.shown, isEmpty);
- });
-
- test('an agent is one mark however many turns it finished', () {
- announcer.turnEnded(agent, news, watching: () => false);
- announcer.turnEnded(agent, news, watching: () => false);
-
- expect(announcer.unread.count, 1);
- announcer.unread.clear(ref);
- expect(announcer.unread.count, 0);
- });
-
- group('noticeBody', () {
- test('keeps the last paragraph, on one line', () {
- expect(noticeBody('a\n\nb c\nd'), 'b c d');
- });
-
- test('cuts a long reply with an ellipsis', () {
- final body = noticeBody('x' * 400, limit: 20);
- expect(body.length, 20);
- expect(body.endsWith('…'), isTrue);
- });
- });
-}
diff --git a/mobile/test/notify/done_notice_test.dart b/mobile/test/notify/done_notice_test.dart
index 5e0716059..de98eb07f 100644
--- a/mobile/test/notify/done_notice_test.dart
+++ b/mobile/test/notify/done_notice_test.dart
@@ -1,5 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/agent_notice.dart';
import 'package:harness_mobile/notify/done_notice.dart';
/// The dial's rule for a finished turn — `firmware/main/cable_client.c`,
@@ -12,7 +13,7 @@ void main() {
String? reply = 'Fixed the login screen.',
}) => (aborted: aborted, replay: replay, subagent: subagent, reply: reply);
- DoneNotice decide(TurnEnd e, {bool inFront = true, bool watching = false}) =>
+ AgentNotice decide(TurnEnd e, {bool inFront = true, bool watching = false}) =>
decideDoneNotice(e, inFront: inFront, watching: watching);
test('a turn that is not news is silent wherever the phone is', () {
@@ -24,21 +25,21 @@ void main() {
end(reply: ' \n '),
]) {
for (final inFront in [true, false]) {
- expect(decide(e, inFront: inFront), DoneNotice.none, reason: '$e');
+ expect(decide(e, inFront: inFront), AgentNotice.none, reason: '$e');
}
}
});
test('watching the agent: the chime still comes, nothing is filed', () {
final notice = decide(end(), watching: true);
- expect(notice, DoneNotice.chime);
+ expect(notice, AgentNotice.chime);
expect(notice.marks, isFalse);
expect(notice.alerts, isFalse);
});
test('in front on another agent: a mark, never a notice', () {
final notice = decide(end());
- expect(notice, DoneNotice.mark);
+ expect(notice, AgentNotice.mark);
expect(notice.chimes, isTrue);
expect(notice.alerts, isFalse);
});
@@ -46,7 +47,7 @@ void main() {
test('away: marked and noticed, whatever was on screen', () {
for (final watching in [true, false]) {
final notice = decide(end(), inFront: false, watching: watching);
- expect(notice, DoneNotice.alert);
+ expect(notice, AgentNotice.alert);
expect(notice.marks, isTrue);
}
});
diff --git a/mobile/test/notify/question_notice_test.dart b/mobile/test/notify/question_notice_test.dart
new file mode 100644
index 000000000..e79961f85
--- /dev/null
+++ b/mobile/test/notify/question_notice_test.dart
@@ -0,0 +1,47 @@
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:harness_mobile/notify/agent_notice.dart';
+import 'package:harness_mobile/notify/question_notice.dart';
+
+/// The dial's rule for a question — `ui_question_show` / `ui_question_close`.
+void main() {
+ const a = (machineId: 'm', agentId: 'a');
+ const b = (machineId: 'm', agentId: 'b');
+
+ test('a request is news once per agent', () {
+ final asked = AskedQuestions();
+ expect(asked.hear(a, 'q1'), isTrue);
+ expect(asked.hear(a, 'q1'), isFalse);
+ expect(asked.hear(b, 'q1'), isTrue, reason: 'another agent');
+ expect(asked.hear(a, 'q2'), isTrue, reason: 'the next page');
+ });
+
+ test('only the open request, or any, can be forgotten', () {
+ final asked = AskedQuestions()..hear(a, 'q2');
+ expect(asked.forget(a, requestId: 'q1'), isFalse);
+ expect(asked.forget(a, requestId: ''), isTrue);
+ expect(asked.forget(a), isFalse, reason: 'already gone');
+ expect(asked.hear(a, 'q2'), isTrue, reason: 'asked again after its end');
+ });
+
+ test('a repeat is silent; a new one escalates like a finished turn', () {
+ for (final inFront in [true, false]) {
+ expect(
+ decideQuestionNotice(isNew: false, inFront: inFront, watching: false),
+ AgentNotice.none,
+ );
+ }
+ expect(
+ decideQuestionNotice(isNew: true, inFront: true, watching: true),
+ AgentNotice.chime,
+ );
+ expect(
+ decideQuestionNotice(isNew: true, inFront: true, watching: false),
+ AgentNotice.mark,
+ );
+ expect(
+ decideQuestionNotice(isNew: true, inFront: false, watching: true),
+ AgentNotice.alert,
+ );
+ });
+}