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): show the system banner while the app is open

tonydfca812bc5f6
diff --git a/mobile/lib/notify/agent_announcer.dart b/mobile/lib/notify/agent_announcer.dart
index ee59387c1..732efe67b 100644
--- a/mobile/lib/notify/agent_announcer.dart
+++ b/mobile/lib/notify/agent_announcer.dart
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:harness_mobile/core/last_opened_agent.dart';
+import 'package:harness_mobile/logging/app_log.dart';
import 'agent_notice.dart';
import 'agent_unread.dart';
@@ -69,7 +70,8 @@ class AgentAnnouncer {
/// 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.
+ /// Unknown counts as in front, which errs toward the agent on screen being
+ /// seen there rather than told about again.
static bool _appInFront() {
try {
final state = WidgetsBinding.instance.lifecycleState;
@@ -105,7 +107,10 @@ class AgentAnnouncer {
}) {
questionClosed(agent.ref);
_awaitingTier.remove(agent.ref)?.timer.cancel();
- if (!isNewsEnd(end)) return;
+ if (!isNewsEnd(end)) {
+ appLog.debug('notify', 'turn end · ${_short(agent.ref)} · not news');
+ return;
+ }
_awaitingTier[agent.ref] = (
agent: agent,
end: end,
@@ -121,6 +126,7 @@ class AgentAnnouncer {
final waiting = _awaitingTier.remove(ref);
if (waiting == null) return null;
waiting.timer.cancel();
+ appLog.debug('notify', 'tier · ${_short(ref)} · ${tier?.name ?? 'none'}');
// A question asked since — Command Code asks AFTER its turn — is what the
// person has to act on, and the daemon says no "done" over one either
// (cli `lib/agentNotifications.ts`).
@@ -141,15 +147,16 @@ class AgentAnnouncer {
required bool Function() watching,
}) {
final front = inFront;
- final notice = decideDoneNotice(
- end,
- inFront: front,
- watching: front && watching(),
- );
+ final seen = front && watching();
+ final notice = decideDoneNotice(end, inFront: front, watching: seen);
+ // Ids and decisions only: what the turn said stays out of the log.
+ appLog.debug('notify', 'done · ${_short(agent.ref)} · ${front ? 'front' : 'away'}${seen ? ' · watching' : ''} · ${notice.name}');
_deliver(agent, notice, NoticeKind.done, () => noticeBody(end.reply!));
return notice;
}
+ static String _short(AgentRef ref) => ref.agentId.length > 8 ? ref.agentId.substring(0, 8) : ref.agentId;
+
/// The agent stopped to ask the person [prompt]. [requestId] is the
/// daemon's id for it, which a re-announce repeats.
AgentNotice questionAsked(
@@ -159,11 +166,13 @@ class AgentAnnouncer {
required bool Function() watching,
}) {
final front = inFront;
+ final seen = front && watching();
final notice = decideQuestionNotice(
isNew: _asked.hear(agent.ref, requestId),
inFront: front,
- watching: front && watching(),
+ watching: seen,
);
+ appLog.debug('notify', 'question · ${_short(agent.ref)} · ${front ? 'front' : 'away'}${seen ? ' · watching' : ''} · ${notice.name}');
_deliver(agent, notice, NoticeKind.question, () => noticeBody(prompt));
return notice;
}
diff --git a/mobile/lib/notify/agent_notice.dart b/mobile/lib/notify/agent_notice.dart
index 5a12a7b4e..59552efec 100644
--- a/mobile/lib/notify/agent_notice.dart
+++ b/mobile/lib/notify/agent_notice.dart
@@ -8,8 +8,8 @@ library;
/// showing — the desktop's `AgentUnread` rule.
enum NoticeKind { done, question }
-/// How far one piece of news goes. [chime], [mark] and [alert] escalate, each
-/// doing everything the one before it does; [filed] is a mark on its own.
+/// How far one piece of news goes. [chime] and [alert] escalate, [alert]
+/// doing everything [chime] does; [filed] is a mark on its own.
enum AgentNotice {
/// Not news. Nothing at all.
none,
@@ -24,23 +24,22 @@ enum AgentNotice {
/// 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.
+ /// About an agent the person is not looking at — the app on another one, or
+ /// not in front at all. Chime, mark it, and post a system notification: the
+ /// OS's own banner, over this app too (owner, 2026-10-21: "notification dạng
+ /// truyền thống"). Until then the app in front got only the tap and the mark,
+ /// and a notice could only reach a phone in the second or two before iOS
+ /// suspends a backgrounded app — so it almost never reached one at all.
alert;
- bool get chimes => this == chime || this == mark || this == alert;
- bool get marks => this == filed || this == mark || this == alert;
+ bool get chimes => this == chime || this == alert;
+ bool get marks => this == filed || 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;
+ if (inFront && watching) return AgentNotice.chime;
+ return AgentNotice.alert;
}
diff --git a/mobile/test/notify/agent_announcer_test.dart b/mobile/test/notify/agent_announcer_test.dart
index e3f09b4b6..879180dc7 100644
--- a/mobile/test/notify/agent_announcer_test.dart
+++ b/mobile/test/notify/agent_announcer_test.dart
@@ -68,12 +68,13 @@ void main() {
expect(system.shown, isEmpty);
});
- test('elsewhere in the app: a chime and a mark, no notice', () {
+ test('elsewhere in the app: a chime, a mark and the notice, the banner over the app', () {
announcer.turnEnded(agent, news, watching: () => false);
expect(chimes, 1);
expect(announcer.unread.contains(ref), isTrue);
- expect(system.shown, isEmpty);
+ expect(system.shown, hasLength(1));
+ expect(system.shown.single.agent, ref);
});
test(
@@ -352,7 +353,15 @@ void main() {
});
test('never asks the OS to cancel a notice it did not post', () {
- announcer.turnEnded(agent, news, watching: () => false);
+ // A `list` turn: marked, and no notice posted.
+ announcer.turnEnded(agent, (
+ aborted: false,
+ replay: false,
+ subagent: false,
+ reply: news.reply,
+ tier: NoticeTier.list,
+ ), watching: () => false);
+ expect(system.shown, isEmpty);
announcer.seen(ref);
expect(announcer.unread.contains(ref), isFalse);
expect(system.cancelled, isEmpty);
@@ -417,11 +426,12 @@ void main() {
expect(announcer.unread.kindFor(ref), NoticeKind.done);
});
- test('a new question elsewhere: a chime and a question mark', () {
- expect(ask(), AgentNotice.mark);
+ test('a new question elsewhere: a chime, a question mark and the banner over the app', () {
+ expect(ask(), AgentNotice.alert);
expect(chimes, 1);
expect(announcer.unread.kindFor(ref), NoticeKind.question);
expect(announcer.unread.anyQuestion, isTrue);
+ expect(system.shown.single.kind, NoticeKind.question);
});
test('the same question heard again is not news', () {
@@ -432,7 +442,7 @@ void main() {
test('the dialog moving to its next page is a new question', () {
ask();
- expect(ask(id: 'q2'), AgentNotice.mark);
+ expect(ask(id: 'q2'), AgentNotice.alert);
});
test('away: one notice, of the question kind, saying the question', () {
@@ -481,7 +491,7 @@ void main() {
tier: null,
), watching: () => false);
expect(announcer.unread.contains(ref), isFalse);
- expect(ask(), AgentNotice.mark, reason: 'a new turn may ask it again');
+ expect(ask(), AgentNotice.alert, reason: 'a new turn may ask it again');
});
test('a deleted agent takes its mark and its notice with it', () {
diff --git a/mobile/test/notify/announcer_lifecycle_test.dart b/mobile/test/notify/announcer_lifecycle_test.dart
index b654ff14d..90a255111 100644
--- a/mobile/test/notify/announcer_lifecycle_test.dart
+++ b/mobile/test/notify/announcer_lifecycle_test.dart
@@ -29,7 +29,7 @@ void main() {
expect(announcer.inFront, isTrue);
});
- testWidgets('in front while resumed; a pocketed phone gets the notice', (
+ testWidgets('in front while resumed; an agent not on screen gets the notice, in front or pocketed', (
tester,
) async {
final system = _Recording();
@@ -38,13 +38,13 @@ void main() {
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
expect(announcer.inFront, isTrue);
- // In front, elsewhere: the haptic tap and a mark — the default chime must
- // never throw, even where no platform answers it.
+ // In front, elsewhere: the haptic tap, a mark and the OS's banner over the
+ // app — the default chime must never throw, even where no platform answers it.
expect(
announcer.turnEnded(agent, news, watching: () => false),
- AgentNotice.mark,
+ AgentNotice.alert,
);
- expect(system.shown, isEmpty);
+ expect(system.shown, hasLength(1));
for (final state in [
AppLifecycleState.inactive,
@@ -58,7 +58,8 @@ void main() {
announcer.turnEnded(agent, news, watching: () => true),
AgentNotice.alert,
);
- expect(system.shown.single.body, 'Fixed the login screen.');
+ expect(system.shown, hasLength(2));
+ expect(system.shown.last.body, 'Fixed the login screen.');
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
diff --git a/mobile/test/notify/done_notice_test.dart b/mobile/test/notify/done_notice_test.dart
index 0efca1592..4b3a12cba 100644
--- a/mobile/test/notify/done_notice_test.dart
+++ b/mobile/test/notify/done_notice_test.dart
@@ -44,11 +44,12 @@ void main() {
expect(notice.alerts, isFalse);
});
- test('in front on another agent: a mark, never a notice', () {
+ test('in front on another agent: marked and noticed, the banner over the app', () {
final notice = decide(end());
- expect(notice, AgentNotice.mark);
+ expect(notice, AgentNotice.alert);
expect(notice.chimes, isTrue);
- expect(notice.alerts, isFalse);
+ expect(notice.marks, isTrue);
+ expect(notice.alerts, isTrue);
});
test('away: marked and noticed, whatever was on screen', () {
@@ -172,7 +173,7 @@ void main() {
});
test('alert: as far as the phone\'s place allows', () {
- expect(decide(end(tier: NoticeTier.alert)), AgentNotice.mark);
+ expect(decide(end(tier: NoticeTier.alert)), AgentNotice.alert);
expect(
decide(end(tier: NoticeTier.alert), inFront: false),
AgentNotice.alert,
diff --git a/mobile/test/notify/question_notice_test.dart b/mobile/test/notify/question_notice_test.dart
index c6528b033..20782f101 100644
--- a/mobile/test/notify/question_notice_test.dart
+++ b/mobile/test/notify/question_notice_test.dart
@@ -52,7 +52,7 @@ void main() {
);
expect(
decideQuestionNotice(isNew: true, inFront: true, watching: false),
- AgentNotice.mark,
+ AgentNotice.alert,
);
expect(
decideQuestionNotice(isNew: true, inFront: false, watching: true),