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(pro): scrolling a Lead's message scrolls its Swarm chat in the app (#1648)

0xdiego25b7bb65d77097
diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.ts
index 6be7d79f1..c327016f9 100644
--- a/cli/src/cable/cableHost.ts
+++ b/cli/src/cable/cableHost.ts
@@ -115,8 +115,8 @@ export interface CableHostWiring {
swarmSay?: (harnessId: string, text: string) => Promise<boolean>
/** A device picked a Lead: the window opens that Swarm tab and project. */
superTabSelected?: (superTabId: string, projectId: string) => void
- /** A finger on the dial's glass, in pieces, while it is down. */
- scrolled?: (phase: 'down' | 'move' | 'up', dy: number, velocity: number) => void
+ /** A finger on the dial's glass, in pieces, while it is down; `superTabId` when it scrolls that Swarm's chat (a Pro's Lead view). */
+ scrolled?: (phase: 'down' | 'move' | 'up', dy: number, velocity: number, superTabId?: string) => void
/** The dial came, went, or started taking an update — see CableSession's onDialStatus. */
dialStatus?: (status: DialStatus) => void
appFocus?: CableHost['appFocus']
@@ -680,7 +680,7 @@ export class DaemonCableHost implements CableHost {
return { machineId: this.machineOf(agentId), agentId }
}
- scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number): void {
+ scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number, superTabId?: string): void {
// THE ENDS ARE LOGGED, THE MIDDLE IS NOT. A stroke is a `down`, a dozen `move`s and an `up`, several
// times a second: logging the middle buries every other line in the file. But the failure this
// protocol is most exposed to is a stroke that never CLOSES — the far side then holds a drag forever
@@ -690,7 +690,8 @@ export class DaemonCableHost implements CableHost {
this.wiring.log(phase === 'down' ? 'cable: scroll ↓' : `cable: scroll ↑ (v=${velocity})`)
}
- this.wiring.scrolled?.(phase, dy, velocity)
+ if (superTabId) this.wiring.scrolled?.(phase, dy, velocity, superTabId)
+ else this.wiring.scrolled?.(phase, dy, velocity)
}
updateAgent(agentId: string, model?: string, effort?: string): void {
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index 595f87285..10a482842 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -3913,6 +3913,23 @@ describe('swarm cards', () => {
} finally { await session.stop() }
})
+ it('names the Swarm of the open Lead on a scroll, so the window scrolls that Swarm\'s chat; none once it closed', async () => {
+ const host = cardHost({ cards: [card('st1')] })
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'scroll', phase: 'move', dy: 5 }); await settle()
+ expect(host.scrolled).toHaveBeenLastCalledWith('move', 5, 0)
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle()
+ port.say({ t: 'scroll', phase: 'move', dy: -12 }); await settle()
+ expect(host.scrolled).toHaveBeenLastCalledWith('move', -12, 0, 'st1')
+ port.say({ t: 'supertab.open', tab: 'st1', lead: '' }); await settle()
+ port.say({ t: 'scroll', phase: 'up', dy: 0, v: 300 }); await settle()
+ expect(host.scrolled).toHaveBeenLastCalledWith('up', 0, 300)
+ } finally { await session.stop() }
+ })
+
it('an unplugged Pro with a recap open closes it for the core', async () => {
const host = cardHost({ cards: [card('st1')] })
const { session, port } = await connect(host)
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index 9a70da7f3..828f1a8b9 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -403,8 +403,9 @@ export interface CableHost {
* that took a morning to explain. Optional, so a host that cannot answer simply says nothing.
*/
knows?(agentId: string): boolean
- /** A finger moving on the dial's glass, on its way to whatever window is open on this computer. */
- scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number): void
+ /** A finger moving on the dial's glass, on its way to whatever window is open on this computer. `superTabId`: the device has a Lead
+ * of that Swarm open (a Pro's Lead view), so the window scrolls that Swarm's chat rather than a pane. */
+ scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number, superTabId?: string): void
updateAgent(agentId: string, model?: string, effort?: string): void
/** PCM is 16-bit mono at `sampleRate`; the daemon owns the credential this needs. */
transcribe(pcm: Buffer, sampleRate: number, lang: string): Promise<string>
@@ -1459,7 +1460,8 @@ export class CableSession {
if (phase !== 'down' && phase !== 'move' && phase !== 'up') return
const dy = typeof msg.dy === 'number' ? msg.dy : 0
const v = typeof msg.v === 'number' ? msg.v : 0
- this.host.scrolled(phase, dy, v)
+ if (this.openLead) this.host.scrolled(phase, dy, v, this.openLead.tabId)
+ else this.host.scrolled(phase, dy, v)
return
}
case 'selection': {
diff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.ts
index 6a6ec80db..a8674ed9d 100644
--- a/cli/src/services/devices.spec.ts
+++ b/cli/src/services/devices.spec.ts
@@ -292,6 +292,7 @@ describe('the dial\'s host, wired to the core', () => {
w.focused!('m1', 'a1')
w.swarmSelected!('t2')
w.scrolled!('move', 4, 120)
+ w.scrolled!('move', -6, 0, 'st1')
w.dialStatus!({ attached: true, fw: '1.2.3' })
w.dialStatus!({ attached: false })
expect(vi.mocked(core.clients.sendLocal).mock.calls.map(([frame]) => frame)).toEqual([
@@ -302,6 +303,7 @@ describe('the dial\'s host, wired to the core', () => {
{ type: 'dial_focus', payload: { machineId: 'm1', agentId: 'a1' } },
{ type: 'dial_swarm', payload: { swarmId: 't2' } },
{ type: 'dial_scroll', payload: { phase: 'move', dy: 4, velocity: 120 } },
+ { type: 'dial_scroll', payload: { phase: 'move', dy: -6, velocity: 0, superTabId: 'st1' } },
{ type: 'dial_status', payload: { attached: true, fw: '1.2.3' } },
{ type: 'dial_status', payload: { attached: false } },
])
diff --git a/cli/src/services/devices.ts b/cli/src/services/devices.ts
index 866bd6f4a..f22d3c797 100644
--- a/cli/src/services/devices.ts
+++ b/cli/src/services/devices.ts
@@ -233,7 +233,7 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)
swarmSay: async (harnessId, text) => (await askCards({ action: 'cardSay', harnessId, text })).said === true,
// The Pro picked a Lead: the window opens that Swarm tab and project. Harmless with no window.
superTabSelected: (superTabId, projectId) => core.clients.sendLocal({ type: 'dial_super_tab', payload: { superTabId, projectId } }),
- scrolled: (phase, dy, velocity) => core.clients.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity } }),
+ scrolled: (phase, dy, velocity, superTabId) => core.clients.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity, ...(superTabId ? { superTabId } : {}) } }),
// Gestures stay at this desk. The device inventory and its settings also reach the owner's other
// machines, through the encrypted device-management event.
dialStatus: (status) => {
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index f7b7d71e9..3e99cdef5 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -4722,6 +4722,24 @@ class AppNotifier extends ChangeNotifier {
};
}
+ /// Dial scroll handlers of the mounted Swarm chats, by Super Tab: a device with
+ /// one of that Swarm's Leads open (a Pro's Lead view) scrolls its chat.
+ final _superTabScrollHandlers =
+ <String, void Function(int phase, int dy, int velocity)>{};
+
+ /// Called by a Swarm's chat while mounted; returns how to withdraw it.
+ VoidCallback registerSuperTabScroll(
+ String superTabId,
+ void Function(int phase, int dy, int velocity) handler,
+ ) {
+ _superTabScrollHandlers[superTabId] = handler;
+ return () {
+ if (identical(_superTabScrollHandlers[superTabId], handler)) {
+ _superTabScrollHandlers.remove(superTabId);
+ }
+ };
+ }
+
bool get canAddPane => panes.length < maxPanes;
Iterable<TerminalPane> panesFor(String machineId) =>
@@ -20516,6 +20534,11 @@ class AppNotifier extends ChangeNotifier {
if (phase == 0) _requestDeviceWindow(machine);
final dy = (payload['dy'] as num?)?.round() ?? 0;
final velocity = (payload['velocity'] as num?)?.round() ?? 0;
+ // A Lead's view on the device: that Swarm's chat scrolls, never a pane.
+ if (payload['superTabId'] case final String superTabId) {
+ _superTabScrollHandlers[superTabId]?.call(phase, dy, velocity);
+ return;
+ }
final pane = focusedPane;
final cloudScroll = pane?.agentId == null
? null
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index 297cdadd4..32a1518b0 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -28,6 +28,7 @@ import 'work_details.dart';
import 'project_sidebar.dart';
import 'project_options.dart';
import 'pane_layout.dart';
+import '../widgets/dial_list_scroll.dart';
typedef _ComposerChoice = ({String label, String? detail, VoidCallback choose});
@@ -93,6 +94,15 @@ class _SuperTabViewState extends State<SuperTabView>
String? _completionPrefix;
final _completionKeys = List.generate(6, (_) => GlobalKey());
SuperTabController get c => widget.controller;
+
+ /// A device with a Lead of this Swarm open scrolls the chat on screen.
+ late final _dial = DialListScroll(() => _scroll[c.selectedId]);
+ VoidCallback? _unregisterDial;
+ void _registerDial() {
+ _unregisterDial?.call();
+ _unregisterDial = widget.app?.registerSuperTabScroll(c.tabId, _dial.handle);
+ }
+
bool get _devicesVisible =>
c.devicesSelected &&
widget.app?.devicesEnabled == true &&
@@ -116,6 +126,7 @@ class _SuperTabViewState extends State<SuperTabView>
WidgetsBinding.instance.addObserver(this);
_composer.addListener(_composerMoved);
c.addListener(_changed);
+ _registerDial();
_changed();
}
@@ -136,6 +147,10 @@ class _SuperTabViewState extends State<SuperTabView>
@override
void didUpdateWidget(SuperTabView oldWidget) {
super.didUpdateWidget(oldWidget);
+ if (oldWidget.controller != c || oldWidget.app != widget.app) {
+ _dial.cancel();
+ _registerDial();
+ }
if (oldWidget.controller != c) {
oldWidget.controller.removeListener(_changed);
c.addListener(_changed);
@@ -180,6 +195,7 @@ class _SuperTabViewState extends State<SuperTabView>
if (_selected != id) {
_scrollRequest++;
_jumpingToEnd = false;
+ _dial.cancel(); // a fling from the last conversation never scrolls this one
}
if (_selected != id || _composer.text != draft) {
_composer.value = TextEditingValue(
@@ -301,6 +317,8 @@ class _SuperTabViewState extends State<SuperTabView>
void dispose() {
WidgetsBinding.instance.removeObserver(this);
c.removeListener(_changed);
+ _unregisterDial?.call();
+ _dial.cancel();
_composer.dispose();
_focus.dispose();
_pullRequestsFocus.dispose();
diff --git a/desktop/lib/widgets/cloud_chat_pane.dart b/desktop/lib/widgets/cloud_chat_pane.dart
index 836cfc049..0df1dacc1 100644
--- a/desktop/lib/widgets/cloud_chat_pane.dart
+++ b/desktop/lib/widgets/cloud_chat_pane.dart
@@ -1,5 +1,4 @@
import 'dart:async';
-import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -13,6 +12,7 @@ import '../terminal/terminal_theme.dart';
import '../terminal/terminal_theme_store.dart';
import '../theme/app_theme.dart';
import 'agent_drag.dart';
+import 'dial_list_scroll.dart';
import 'harness_activity_mark.dart';
import 'engine_identity.dart';
import 'pane_header_actions.dart';
@@ -72,69 +72,19 @@ class _CloudChatPaneState extends State<CloudChatPane> {
String? _error;
int _readAt = -1;
- // The dial scrolls this conversation as it scrolls a terminal (same scale, speed
- // and fling decay as terminal_panel.dart), except that this list is reversed:
- // its offset grows toward OLDER messages, so the sign flips to keep the
- // direction on screen the same.
- static const _dialScale = 2.5;
- static const _dialStopVelocity = 40.0;
- static const _dialDecayPerSecond = 0.002;
+ // The dial scrolls this conversation as it scrolls a terminal (DialListScroll).
+ late final _dial = DialListScroll(() => _scroll);
VoidCallback? _unregisterDial;
- Timer? _dialInertia;
- double _dialVelocity = 0;
- int? _lastInertiaMicros;
void _registerDial() {
_unregisterDial?.call();
_unregisterDial = widget.notifier.registerCloudScroll(
widget.machineId,
widget.agent.id,
- _dialScroll,
+ _dial.handle,
);
}
- void _dialScroll(int phase, int dy, int velocity) {
- if (phase == 0) _cancelDialInertia();
- if (dy != 0) _applyDialDelta(dy * _dialScale);
- if (phase == 2) _startDialInertia(velocity.toDouble());
- }
-
- void _applyDialDelta(double delta) {
- if (!_scroll.hasClients) return;
- final position = _scroll.position;
- position.jumpTo(
- (position.pixels + delta)
- .clamp(position.minScrollExtent, position.maxScrollExtent)
- .toDouble(),
- );
- }
-
- void _startDialInertia(double velocity) {
- _cancelDialInertia();
- if (velocity.abs() < _dialStopVelocity) return;
- _dialVelocity = velocity;
- _lastInertiaMicros = DateTime.now().microsecondsSinceEpoch;
- _dialInertia = Timer.periodic(const Duration(milliseconds: 16), (_) {
- if (!mounted) {
- _cancelDialInertia();
- return;
- }
- final now = DateTime.now().microsecondsSinceEpoch;
- final elapsed = math.min((now - (_lastInertiaMicros ?? now)) / 1e6, 0.05);
- _lastInertiaMicros = now;
- _applyDialDelta(_dialVelocity * elapsed * _dialScale);
- _dialVelocity *= math.pow(_dialDecayPerSecond, elapsed).toDouble();
- if (_dialVelocity.abs() < _dialStopVelocity) _cancelDialInertia();
- });
- }
-
- void _cancelDialInertia() {
- _dialInertia?.cancel();
- _dialInertia = null;
- _dialVelocity = 0;
- _lastInertiaMicros = null;
- }
-
@override
void initState() {
super.initState();
@@ -148,7 +98,7 @@ class _CloudChatPaneState extends State<CloudChatPane> {
if (old.agent.id != widget.agent.id ||
old.machineId != widget.machineId ||
old.notifier != widget.notifier) {
- _cancelDialInertia();
+ _dial.cancel();
_registerDial();
}
// The frame says how many messages its conversation holds: read again when that moves.
@@ -161,7 +111,7 @@ class _CloudChatPaneState extends State<CloudChatPane> {
@override
void dispose() {
_unregisterDial?.call();
- _cancelDialInertia();
+ _dial.cancel();
_prompt.dispose();
_promptFocus.dispose();
_scroll.dispose();
diff --git a/desktop/lib/widgets/dial_list_scroll.dart b/desktop/lib/widgets/dial_list_scroll.dart
new file mode 100644
index 000000000..0e9181f0e
--- /dev/null
+++ b/desktop/lib/widgets/dial_list_scroll.dart
@@ -0,0 +1,66 @@
+import 'dart:async';
+import 'dart:math' as math;
+
+import 'package:flutter/widgets.dart';
+
+/// The dial's drag on a conversation list (a cloud harness's pane, a Swarm's
+/// chat), as it scrolls a terminal: the same scale, speed and fling decay as
+/// terminal_panel.dart. A positive dy shows earlier lines, here older messages,
+/// whichever way the list runs: a reversed list's offset grows toward them, a
+/// forward one's shrinks, so the sign follows the list to keep the direction on
+/// screen the same. The owner calls [cancel] when it goes.
+class DialListScroll {
+ DialListScroll(this._list);
+
+ /// The list on screen now (null or unattached: the dial moves nothing).
+ final ScrollController? Function() _list;
+
+ static const _scale = 2.5;
+ static const _stopVelocity = 40.0;
+ static const _decayPerSecond = 0.002;
+ Timer? _inertia;
+ double _velocity = 0;
+ int? _lastInertiaMicros;
+
+ /// One piece of a stroke: phase 0 down, 1 move, 2 up (with its velocity).
+ void handle(int phase, int dy, int velocity) {
+ if (phase == 0) cancel();
+ if (dy != 0) _apply(dy * _scale);
+ if (phase == 2) _fling(velocity.toDouble());
+ }
+
+ void _apply(double delta) {
+ final list = _list();
+ if (list == null || !list.hasClients) return;
+ final position = list.position;
+ final older = position.axisDirection == AxisDirection.up ? 1 : -1;
+ position.jumpTo(
+ (position.pixels + delta * older)
+ .clamp(position.minScrollExtent, position.maxScrollExtent)
+ .toDouble(),
+ );
+ }
+
+ void _fling(double velocity) {
+ cancel();
+ if (velocity.abs() < _stopVelocity) return;
+ _velocity = velocity;
+ _lastInertiaMicros = DateTime.now().microsecondsSinceEpoch;
+ _inertia = Timer.periodic(const Duration(milliseconds: 16), (_) {
+ final now = DateTime.now().microsecondsSinceEpoch;
+ final elapsed = math.min((now - (_lastInertiaMicros ?? now)) / 1e6, 0.05);
+ _lastInertiaMicros = now;
+ _apply(_velocity * elapsed * _scale);
+ _velocity *= math.pow(_decayPerSecond, elapsed).toDouble();
+ if (_velocity.abs() < _stopVelocity) cancel();
+ });
+ }
+
+ /// Stops a fling still running.
+ void cancel() {
+ _inertia?.cancel();
+ _inertia = null;
+ _velocity = 0;
+ _lastInertiaMicros = null;
+ }
+}
diff --git a/desktop/test/super_tab_dial_scroll_test.dart b/desktop/test/super_tab_dial_scroll_test.dart
new file mode 100644
index 000000000..c9aba3c29
--- /dev/null
+++ b/desktop/test/super_tab_dial_scroll_test.dart
@@ -0,0 +1,137 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/app_state.dart';
+import 'package:harness/super_tabs/view.dart';
+
+import 'support/super_tab_fixture.dart';
+import 'swarm_state_test.dart' show createApp;
+
+void main() {
+ // A Pro with a Lead of this Swarm open scrolls the Swarm's chat in the app, the way an agent screen scrolls its pane.
+ testWidgets(
+ 'the dial scrolls the chat of the Swarm whose Lead the device has open',
+ (tester) async {
+ final app = createApp(connected: true);
+ addTearDown(app.dispose);
+ final server = ConversationServer();
+ for (var i = 0; i < 60; i++) {
+ server.append('message $i');
+ }
+ final c = server.controller();
+ addTearDown(c.dispose);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: SuperTabView(
+ controller: c,
+ app: app,
+ onInvite: () {},
+ onAddAgent: (_) {},
+ onOpenTerminal: (_) {},
+ machineName: (_) => 'Team Mac',
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ ScrollPosition position() => tester
+ .widget<ListView>(
+ find.byKey(const PageStorageKey('super-messages-tab-lead')),
+ )
+ .controller!
+ .position;
+ final end = position().pixels;
+ expect(end, position().maxScrollExtent);
+ expect(end, greaterThan(100));
+
+ Future<void> dial(AppNotifier app, Map<String, dynamic> p) =>
+ app.handleEventForTest('m', {'type': 'dial_scroll', 'payload': p});
+ await dial(app, {'phase': 'down', 'dy': 0, 'superTabId': 'tab'});
+ // Terminal convention: a positive dy shows earlier lines, here older messages.
+ await dial(app, {'phase': 'move', 'dy': 20, 'superTabId': 'tab'});
+ expect(position().pixels, end - 50);
+ await dial(app, {'phase': 'move', 'dy': -8, 'superTabId': 'tab'});
+ expect(position().pixels, end - 30);
+ await dial(app, {'phase': 'move', 'dy': -100, 'superTabId': 'tab'});
+ expect(position().pixels, end, reason: 'clamped at the newest message');
+ await dial(app, {
+ 'phase': 'up',
+ 'dy': 0,
+ 'velocity': 0,
+ 'superTabId': 'tab',
+ });
+
+ // Another Swarm's scroll, or one that names none, leaves this chat alone.
+ await dial(app, {'phase': 'move', 'dy': 20, 'superTabId': 'other'});
+ await dial(app, {'phase': 'move', 'dy': 20});
+ expect(position().pixels, end);
+
+ // Gone from the screen, the chat no longer takes the dial.
+ await tester.pumpWidget(const SizedBox());
+ await dial(app, {'phase': 'move', 'dy': 20, 'superTabId': 'tab'});
+ },
+ );
+
+ // A Lead swipe on the device selects another conversation: a fling still running from the last one stops, it never scrolls the new chat.
+ testWidgets(
+ 'a running fling stops when the Swarm selects another conversation',
+ (tester) async {
+ final app = createApp(connected: true);
+ addTearDown(app.dispose);
+ final server = ConversationServer();
+ for (var i = 0; i < 60; i++) {
+ server.append('lead $i');
+ server.append('offline $i', conversationId: 'offline');
+ }
+ final c = server.controller();
+ addTearDown(c.dispose);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: SuperTabView(
+ controller: c,
+ app: app,
+ onInvite: () {},
+ onAddAgent: (_) {},
+ onOpenTerminal: (_) {},
+ machineName: (_) => 'Team Mac',
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ Future<void> dial(Map<String, dynamic> p) => app.handleEventForTest('m', {
+ 'type': 'dial_scroll',
+ 'payload': {...p, 'superTabId': 'tab'},
+ });
+ await dial({'phase': 'down', 'dy': 0});
+ await dial({'phase': 'move', 'dy': 20});
+ await dial({'phase': 'up', 'dy': 0, 'velocity': 2000});
+ c.select('offline');
+ await tester.pumpAndSettle();
+ ScrollPosition position() => tester
+ .widget<ListView>(
+ find.byKey(const PageStorageKey('super-messages-tab-offline')),
+ )
+ .controller!
+ .position;
+ final shown = position().pixels;
+ expect(shown, position().maxScrollExtent);
+ // Inertia reads the wall clock: let it pass, then pump the timers a fling would run on.
+ await tester.runAsync(
+ () => Future<void>.delayed(const Duration(milliseconds: 20)),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ expect(
+ position().pixels,
+ shown,
+ reason: 'the old fling does not move the new chat',
+ );
+ },
+ );
+}
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.c b/devices/harness-pro/firmware/main/app/pod_glue.c
index b92252aa1..d6d77bbb8 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.c
+++ b/devices/harness-pro/firmware/main/app/pod_glue.c
@@ -248,11 +248,12 @@ static bool scrolls(const pod_ui_t *u)
// Home pages sideways; the Inbox and a long Lead message scroll by rows; on a room or a recap a drag scrolls the host's pane
return f->view == POD_V_INBOX || f->view == POD_V_LEAD || f->view == POD_V_AGENT || f->view == POD_V_RECAP;
}
-// Whether a vertical drag on this screen scrolls the host's terminal pane (the scroll sink): Agent and Recap. The top band and the bottom zone keep their swipes (u->bar, u->edge).
+// Whether a vertical drag on this screen also goes to the host (the scroll sink): Agent and Recap scroll the agent's pane, a Lead's view the Swarm chat
+// the desktop has open (its own rows move too). The top band and the bottom zone keep their swipes (u->bar, u->edge).
static bool host_scrolls(const pod_ui_t *u)
{
const pod_frame_t *f = top(u);
- return f && (f->view == POD_V_AGENT || f->view == POD_V_RECAP);
+ return f && (f->view == POD_V_AGENT || f->view == POD_V_RECAP || f->view == POD_V_LEAD);
}
// A horizontal swipe on the Agent, Recap and Talking screens steps panes, as on the round dial (swipe left = next, right =
// previous): travel >= POD_SW_MIN_PX, |dx| > 1.5 |dy|, released within POD_SW_MS or leaving at POD_SW_FLICK px/s.
@@ -972,7 +973,7 @@ static void apply_lead_focus(pod_ui_t *u)
static void sup_sync(pod_ui_t *u)
{
pod_model_t *m = &u->model;
- if (!m->linked) { u->sup_tab[0] = u->sup_lead[0] = 0; return; }
+ if (!m->linked) { u->sup_tab[0] = u->sup_lead[0] = u->sup_close[0] = 0; return; } // the daemon forgets an unplugged device's open Lead
const pod_frame_t *f = top(u);
const bool on = f && f->swarm[0] && (f->view == POD_V_LEAD || f->view == POD_V_TALK);
const pod_swarm_t *sw = NULL;
@@ -980,7 +981,10 @@ static void sup_sync(pod_ui_t *u)
if (on && !l) return; // its Lead is not in the model (yet): neither open nor closed, wait for it
const char *lead = l ? l->id : "";
if (!strcmp(u->sup_lead, lead) && (!l || !strcmp(u->sup_tab, sw->id))) { // already what the daemon was told: a frame that may have been lost is re-sent
- if (!l) return;
+ if (!l) { // nothing open: a close the link dropped goes again
+ if (u->sup_close[0] && sup_push(u, "supertab.open", u->sup_close, "")) u->sup_close[0] = 0;
+ return;
+ }
const uint32_t now_ms = m->clock_ms;
if ((uint32_t)(now_ms - u->sup_at) < POD_SUPERTAB_RETRY_MS || u->sup_qn + 2 > POD_SUPERTAB_OUT_MAX) return;
if (l->recap == POD_RECAP_LOADING) { // no reply yet: ask again, a few times; then the "…" stays and nothing more is sent
@@ -1013,6 +1017,7 @@ static void sup_sync(pod_ui_t *u)
}
pod_copy_str(u->sup_tab, sizeof u->sup_tab, tab);
pod_copy_str(u->sup_lead, sizeof u->sup_lead, lead);
+ u->sup_close[0] = 0; // the open replaces any close still owed
u->sup_at = m->clock_ms;
u->sup_tries = 0;
u->sup_reopened = false;
@@ -1028,9 +1033,15 @@ int pod_ui_take_supertab(pod_ui_t *u, pod_supertab_out_t out[], int max)
return n;
}
-void pod_ui_supertab_unsent(pod_ui_t *u, const char *t)
+void pod_ui_supertab_unsent(pod_ui_t *u, const pod_supertab_out_t *frame)
{
- if (!t || !u->sup_lead[0]) return;
+ if (!frame || !frame->t) return;
+ const char *t = frame->t;
+ if (!strcmp(t, "supertab.open") && !frame->lead[0]) { // the close: the daemon would keep the Lead open and send every later drag to its chat
+ if (!u->sup_lead[0]) pod_copy_str(u->sup_close, sizeof u->sup_close, frame->tab);
+ return;
+ }
+ if (!u->sup_lead[0]) return;
if (!strcmp(t, "supertab.recap.get")) {
if (u->sup_tries) u->sup_tries--; // a failed retry does not use one up
u->sup_at = u->model.clock_ms; // and the next waits the usual 3 s
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.h b/devices/harness-pro/firmware/main/app/pod_glue.h
index 2ee969a51..db82ce927 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.h
+++ b/devices/harness-pro/firmware/main/app/pod_glue.h
@@ -96,6 +96,7 @@ typedef struct {
// The Swarm cards' Lead view (see pod_ui_take_supertab): the Lead the daemon was last told is open (empty: none), the frames waiting to go, and when a
// supertab.focus began waiting for its Swarm list.
char sup_tab[ID_MAX], sup_lead[ID_MAX];
+ char sup_close[ID_MAX]; // a "closed" frame the link dropped, owed for this Swarm until sent (empty: none), unless a Lead opens first
pod_supertab_out_t sup_q[POD_SUPERTAB_OUT_MAX];
uint8_t sup_qn;
uint32_t sup_at; // when the open Lead was last (re)sent to the daemon, at the model's clock
@@ -153,8 +154,9 @@ pod_out_t pod_ui_focus(pod_ui_t *, const char *agent_id, uint32_t now_ms);
// the list not back yet) nothing is sent; a link drop forgets what was open, so the view re-sends open and get when its Lead is back.
// Returns how many frames were written to out (at most max).
int pod_ui_take_supertab(pod_ui_t *, pod_supertab_out_t out[], int max);
-// A frame taken by pod_ui_take_supertab that could not be sent (the link was busy): open / recap.get count as not sent, so the retry comes again (a failed retry is not counted).
-void pod_ui_supertab_unsent(pod_ui_t *, const char *t);
+// A frame taken by pod_ui_take_supertab that could not be sent (the link was busy): open / recap.get count as not sent, so the retry comes again (a failed retry is not counted);
+// the closing open (no lead) is owed until it is sent, unless a Lead opened since.
+void pod_ui_supertab_unsent(pod_ui_t *, const pod_supertab_out_t *frame);
// The start, armed by a real link down -> up (pod_ui_link): once swarms of this link have arrived, if the stack is at the
// root (TABS) and tab 0 has agents, enter tab 0 on its first agent (POD_A_ENTER_TAB). It is device-local: no AGENT_OPEN
diff --git a/devices/harness-pro/firmware/main/app/pro_app.c b/devices/harness-pro/firmware/main/app/pro_app.c
index b9b8958d3..0f4a50600 100644
--- a/devices/harness-pro/firmware/main/app/pro_app.c
+++ b/devices/harness-pro/firmware/main/app/pro_app.c
@@ -169,7 +169,7 @@ static __attribute__((noinline)) void send_supertabs(void)
for (int i = 0; i < n; i++) any |= lost[i] = !pro_cable_supertab_send(q[i].t, q[i].tab, q[i].lead);
if (!any) return;
pro_app_lock(); // a frame the link dropped is owed again (open / recap.get are retried)
- for (int i = 0; i < n; i++) if (lost[i]) pod_ui_supertab_unsent(&s_pod, q[i].t);
+ for (int i = 0; i < n; i++) if (lost[i]) pod_ui_supertab_unsent(&s_pod, &q[i]);
pro_app_unlock();
}
diff --git a/devices/harness-pro/firmware/main/pod/home/ph_lead.c b/devices/harness-pro/firmware/main/pod/home/ph_lead.c
index c8266ff19..1ae3b08f8 100644
--- a/devices/harness-pro/firmware/main/pod/home/ph_lead.c
+++ b/devices/harness-pro/firmware/main/pod/home/ph_lead.c
@@ -5,7 +5,7 @@
// ("working . m:ss" green, "needs you" orange, "stuck" red, "done" grey), a remote Lead adding its owner in a smaller muted line.
// A Lead that needs you has an 8 px orange inner left edge on the bubble (stuck: red). States of the text: LOADING draws "..." in a bubble of its own; EMPTY draws no
// bubble, "No message yet" muted in the middle and the pet resting; LOADED the text. A long message shows 7 rows at a time and scrolls by rows (the frame's
-// scroll; a vertical drag, pod_scroll_pitch / pod_scroll_max), the last visible row lighter while more follows. No hit: a tap anywhere talks to a local Lead's
+// scroll; a vertical drag, pod_scroll_pitch / pod_scroll_max; the same drag scrolls the desktop's Swarm chat), the last visible row lighter while more follows. No hit: a tap anywhere talks to a local Lead's
// harness (the glue), a horizontal swipe steps to the previous / next Lead (pod_nav_act PREV / NEXT). No page dots.
#include <stdio.h>
#include <string.h>
diff --git a/devices/harness-pro/firmware/test/test_ph_glue.c b/devices/harness-pro/firmware/test/test_ph_glue.c
index 5d7130dc5..251846a83 100644
--- a/devices/harness-pro/firmware/test/test_ph_glue.c
+++ b/devices/harness-pro/firmware/test/test_ph_glue.c
@@ -1805,8 +1805,8 @@ static void lead_retry(void) {
CHECK(take() == 3);
render(6000);
CHECK(take() == 2);
- pod_ui_supertab_unsent(&U, Q[0].t);
- pod_ui_supertab_unsent(&U, Q[1].t);
+ pod_ui_supertab_unsent(&U, &Q[0]);
+ pod_ui_supertab_unsent(&U, &Q[1]);
render(8999);
CHECK(take() == 0);
render(9000);
@@ -1825,7 +1825,7 @@ static void lead_retry(void) {
CHECK(take() == 2);
render(6000);
CHECK(take() == 1);
- pod_ui_supertab_unsent(&U, Q[0].t);
+ pod_ui_supertab_unsent(&U, &Q[0]);
render(9000);
CHECK(take() == 1 && is_q(0, "supertab.open", "sw1", "l2"));
// a full queue records nothing: the next sync sends the whole of it
@@ -1897,7 +1897,8 @@ static void lead_scrolls(void) {
render(3500);
CHECK(pod_scroll_max(&U.nav, &U.model) > 1 && top()->scroll == 0);
t_(true, 360, 500, 4000); t_(true, 360, 400, 4100); t_(true, 360, 300, 4200); t_(false, 360, 300, 4250);
- CHECK(top()->view == POD_V_LEAD && top()->scroll >= 1 && top()->lead == 0 && sc_events == 0 && take() == 0); // the drag moved the text, not the host's pane, and sent nothing
+ CHECK(top()->view == POD_V_LEAD && top()->scroll >= 1 && top()->lead == 0 && take() == 0); // the drag moved the text and sent no Swarm frame
+ CHECK(sc_down == 1 && sc_move > 0 && sc_up == 1); // and the desktop's chat follows it, as an agent screen's drag scrolls its pane
t_(true, 360, 300, 5000); t_(true, 360, 500, 5100); t_(true, 360, 700, 5200); t_(false, 360, 700, 5250);
CHECK(top()->scroll == 0);
}
diff --git a/devices/harness-pro/firmware/test/test_pro_app.py b/devices/harness-pro/firmware/test/test_pro_app.py
index c75166c84..7b6ad314e 100644
--- a/devices/harness-pro/firmware/test/test_pro_app.py
+++ b/devices/harness-pro/firmware/test/test_pro_app.py
@@ -368,6 +368,77 @@ static void lead_view_via_app(void) {
CHECK(top() == POD_V_LEAD && U.model.swarms[0].leads[0].recap == POD_RECAP_LOADING);
CHECK(pro_app_test_take_dirty() || true);
}
+// A long Lead message on the device: a vertical drag through the finger's path scrolls it by rows (the drawn rows move), a local Lead's tap-to-talk
+// does not take the drag, and the horizontal swipe still steps Leads.
+static const char *LONG_LEAD = "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty "
+ "twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty thirty-one thirty-two "
+ "thirty-three thirty-four thirty-five thirty-six thirty-seven thirty-eight thirty-nine forty";
+static int first_text_y(const char *word) { // the y of the drawn run that starts with word, -1 when none is drawn
+ for (int i = 0; i < S.count; i++) if (S.runs[i].text[0] && !strncmp(S.runs[i].text, word, strlen(word))) return S.runs[i].y;
+ return -1;
+}
+static void lead_view_scrolls_via_app(void) {
+ setup();
+ swarm_feed(3);
+ pod_swarm_t *sw = (pod_swarm_t *)pod_model_swarm(&U.model, "sw1");
+ snprintf(sw->leads[1].local, ID_MAX, "a1"); // a Lead whose harness runs here: a tap on its view talks
+ swarm_home_page();
+ tap(POD_A_LEAD, 1);
+ CHECK(top() == POD_V_LEAD && !strcmp(U.nav.stack[1].agent, "a1"));
+ pro_app_supertab_recap("sw1", "l1", LONG_LEAD, 1792560000u, false);
+ render();
+ CHECK(pod_scroll_max(&U.nav, &U.model) >= 2 && first_text_y("one") >= 0);
+ now += 2000;
+ memset(&SC, 0, sizeof SC);
+ drag(360, 480, 360, 200, 20); // finger up: the text moves up
+ CHECK(top() == POD_V_LEAD && !pod_ui_talking(&U) && U.nav.stack[1].scroll >= 2 && !strcmp(U.nav.stack[1].lead_id, "l1"));
+ CHECK(first_text_y("one") < 0); // the first row is scrolled out of the bubble
+ CHECK(SC.n >= 3 && SC.phase[0] == HT_SCROLL_DOWN && SC.phase[SC.n - 1] == HT_SCROLL_UP); // and the desktop's chat is told, sent after the lock
+ int total = 0;
+ for (int i = 0; i < SC.n; i++) if (SC.phase[i] != HT_SCROLL_DOWN) total += SC.dy[i];
+ CHECK(total == -280); // every pixel of the finger's travel
+ now += 2000;
+ drag(360, 200, 360, 600, 20); // and back down
+ CHECK(U.nav.stack[1].scroll == 0 && first_text_y("one") >= 0);
+ now += 2000;
+ swipe_next();
+ CHECK(top() == POD_V_LEAD && !strcmp(U.nav.stack[1].lead_id, "l2"));
+}
+// The Lead view closing on a busy link: the "closed" frame the link dropped is owed until it is sent. A daemon that still thinks the Lead is open would
+// keep sending every later drag on an agent screen to the Swarm chat.
+static void lead_close_owed_on_busy_link(void) {
+ setup();
+ swarm_feed(3);
+ swarm_home_page();
+ tap(POD_A_LEAD, 1);
+ CHECK(top() == POD_V_LEAD);
+ memset(&SUP, 0, sizeof SUP);
+ SUP.fail = true; // the link is busy: every Swarm frame is refused
+ pro_app_button_press(); // Home: the Lead view closes
+ CHECK(top() == POD_V_TABS && SUP.n == 0);
+ SUP.fail = false;
+ now += 100;
+ pro_app_tick(); // the next pass sends what is owed
+ CHECK(SUP.n == 1 && !strcmp(SUP.t[0], "supertab.open") && !strcmp(SUP.tab[0], "sw1") && !SUP.lead[0][0]);
+ memset(&SUP, 0, sizeof SUP);
+ now += 100;
+ pro_app_tick(); // and only once
+ CHECK(SUP.n == 0);
+ // a close still owed when another Lead is opened goes first, never after: the daemon ends with the new Lead open
+ swarm_home_page();
+ tap(POD_A_LEAD, 2);
+ memset(&SUP, 0, sizeof SUP);
+ SUP.fail = true;
+ pro_app_button_press();
+ swarm_home_page();
+ SUP.fail = false;
+ tap(POD_A_LEAD, 0);
+ CHECK(top() == POD_V_LEAD && SUP.n >= 2);
+ int open_at = -1;
+ for (int i = 0; i < SUP.n; i++) if (!strcmp(SUP.t[i], "supertab.open") && !strcmp(SUP.lead[i], "l0")) open_at = i;
+ CHECK(open_at >= 0);
+ for (int i = open_at; i < SUP.n; i++) CHECK(SUP.lead[i][0]); // no close after the new open
+}
static void lead_view_relink_and_focus(void) {
setup();
swarm_feed(3);
@@ -2544,7 +2615,7 @@ int main(int argc, char **argv) {
{"library_fills_other_tabs", library_fills_other_tabs}, {"sweep_schedule", sweep_schedule},
{"notice_shows_three_seconds", notice_shows_three_seconds}, {"link_drop_keeps_the_stack", link_drop_keeps_the_stack}, {"orphan_recording_is_discarded", orphan_recording_is_discarded}, {"side_button_discards_hands_free", side_button_discards_hands_free},
{"send_before_recorder_started", send_before_recorder_started}, {"cap_leaves_talking", cap_leaves_talking},
- {"lead_view_via_app", lead_view_via_app}, {"lead_view_relink_and_focus", lead_view_relink_and_focus}, {"tap_resolves_by_id", tap_resolves_by_id}, {"utf8_cuts", utf8_cuts}, {"clock_wrap", clock_wrap}, {"small_cable_stack", small_cable_stack},
+ {"lead_view_via_app", lead_view_via_app}, {"lead_view_scrolls_via_app", lead_view_scrolls_via_app}, {"lead_close_owed_on_busy_link", lead_close_owed_on_busy_link}, {"lead_view_relink_and_focus", lead_view_relink_and_focus}, {"tap_resolves_by_id", tap_resolves_by_id}, {"utf8_cuts", utf8_cuts}, {"clock_wrap", clock_wrap}, {"small_cable_stack", small_cable_stack},
{"activity_text_is_stable_through_the_real_cadence", activity_text_is_stable_through_the_real_cadence},
{"follow_from_tabs", follow_from_tabs}, {"follow_from_another_agent", follow_from_another_agent}, {"follow_same_agent_is_a_no_op", follow_same_agent_is_a_no_op},
{"follow_ignored_while_talking", follow_ignored_while_talking}, {"follow_waits_out_the_users_touch", follow_waits_out_the_users_touch},