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.

Keep creature click target still when counts clear (#429)

Dee60f6bec74dd7
diff --git a/desktop/design/daemons.md b/desktop/design/daemons.md
index 612075b2e..4a3dcc024 100644
--- a/desktop/design/daemons.md
+++ b/desktop/design/daemons.md
@@ -250,6 +250,8 @@ brain the done count is its `daemon_state.done.count` (every machine; the toolti
names the last few) and a look sends `daemon_presence { doneSeen: true }`;
without one the window counts what it sees (a turn in the pane in front of you
is already seen). Native lays out again only when the tally's width changes.
+While the pointer is over the creature, clearing a count retains its former
+space so the click target stays still. That space collapses on pointer exit.
![The native bar separates Git from labeled creature counts](images/daemon-status-counts.png)
diff --git a/desktop/design/workspace-status-bar.md b/desktop/design/workspace-status-bar.md
index eff856f84..e4623ef56 100644
--- a/desktop/design/workspace-status-bar.md
+++ b/desktop/design/workspace-status-bar.md
@@ -286,6 +286,8 @@ status bar). A shiny daemon's `*` sits in the left gutter. After the sprite, dim
show labeled counts: `3 done, 1 egg`. The creature separates its counts from
the Git branch count; never put an unlabeled `+N` beside the branch context.
Done means turns finished since you looked, and eggs means unhatched eggs.
+Keep the creature's click target still while hovered, retaining cleared count
+space until the pointer leaves.
Its name and progress belong in the tooltip and panel, never beside the
sprite. Clicking a ready egg hatches it; otherwise a click boops the daemon and
opens its panel. When something needs you or failed, its one line replaces the
diff --git a/desktop/lib/daemons/daemon_face.dart b/desktop/lib/daemons/daemon_face.dart
index 1149db504..359a594c4 100644
--- a/desktop/lib/daemons/daemon_face.dart
+++ b/desktop/lib/daemons/daemon_face.dart
@@ -464,6 +464,21 @@ class DaemonFace extends ChangeNotifier {
].join(', ');
}
+ bool _pointerInside = false;
+ int _heldTallyCells = 0;
+
+ /// Keep the click target still when looking clears a count. Empty space
+ /// is released once the pointer leaves; new counts can still grow it.
+ int get tallyCells =>
+ _heldTallyCells > tally.length ? _heldTallyCells : tally.length;
+
+ void setPointerInside(bool inside) {
+ if (_pointerInside == inside) return;
+ _pointerInside = inside;
+ _heldTallyCells = inside ? tally.length : 0;
+ _update(force: true);
+ }
+
/// `tim: bell in codex@office: run the migration?` while it speaks; a line
/// from the pair brain exactly as sent (`[y/n/g] api@office: npm test`).
String? get voice => _voice.value;
@@ -1287,6 +1302,12 @@ class DaemonFace extends ChangeNotifier {
void _update({DaemonMood? before, bool force = false}) {
if (_disposed) return;
+ if (!visible) {
+ _pointerInside = false;
+ _heldTallyCells = 0;
+ } else if (_pointerInside && tally.length > _heldTallyCells) {
+ _heldTallyCells = tally.length;
+ }
final now = mood;
_runMotion(now);
final glyph = this.glyph;
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index ac94702d0..1d4fcd2a2 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -1901,10 +1901,15 @@ class _SwarmScreenState extends State<SwarmScreen> {
}
if (call.method == 'daemonLook') {
if (!_zoo.loaded) return;
+ _face.setPointerInside(true);
_face.look();
_face.seen();
return;
}
+ if (call.method == 'daemonLeave') {
+ _face.setPointerInside(false);
+ return;
+ }
if (call.method == 'daemonAnswer') {
final key = (call.arguments as Map?)?['key'];
if (key is String && _shortcutsEnabled && _zoo.loaded) {
@@ -3253,6 +3258,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
// the gutter), followed by the labeled tally (`3 done, 1 egg`).
'cell': _face.cell,
'tally': _face.tally,
+ 'tallyCells': _face.tallyCells,
'foreground': daemonSlotInk(_face, theme).withValues(alpha: 1).toARGB32(),
'tallyColor': daemonDimInk(theme).toARGB32(),
'patch': daemonSlotPatch(_face, theme)?.toARGB32(),
@@ -6246,12 +6252,12 @@ class _SwarmScreenState extends State<SwarmScreen> {
];
// No space is kept for the slot until it is shown: off (or not decided
// yet) the bar is exactly the one it was before daemons existed.
- final tally = _slotShown ? _face.tally : '';
+ final tallyCells = _slotShown ? _face.tallyCells : 0;
final daemonSpace = _slotShown
? cell.width *
(_face.roster.rules.statusCells +
2 +
- (tally.isEmpty ? 0 : tally.length + 1))
+ (tallyCells == 0 ? 0 : tallyCells + 1))
: 0.0;
final toolHeight = workspaceBarControlHeight(context);
final pr = _pullRequest.value;
diff --git a/desktop/lib/widgets/daemon_slot.dart b/desktop/lib/widgets/daemon_slot.dart
index e317fd278..f0fae4c13 100644
--- a/desktop/lib/widgets/daemon_slot.dart
+++ b/desktop/lib/widgets/daemon_slot.dart
@@ -307,9 +307,11 @@ class DaemonSlotButton extends StatelessWidget {
final patch = daemonSlotPatch(face, theme);
return MouseRegion(
onEnter: (_) {
+ face.setPointerInside(true);
face.look();
face.seen();
},
+ onExit: (_) => face.setPointerInside(false),
child: Semantics(
value: face.detail,
child: WorkspaceBarControl(
@@ -354,19 +356,25 @@ class DaemonSlotButton extends StatelessWidget {
],
),
),
- if (tally.isNotEmpty) ...[
- Text(
- tally,
- key: const ValueKey('daemon-slot-tally'),
- maxLines: 1,
- softWrap: false,
- style: workspaceBarTextStyle(
- color: daemonDimInk(theme),
- emphasized: emphasized,
- ).copyWith(fontFeatures: daemonTextFeatures),
+ if (face.tallyCells > 0)
+ SizedBox(
+ width: cell.width * (face.tallyCells + 1),
+ child: tally.isEmpty
+ ? null
+ : Align(
+ alignment: Alignment.centerLeft,
+ child: Text(
+ tally,
+ key: const ValueKey('daemon-slot-tally'),
+ maxLines: 1,
+ softWrap: false,
+ style: workspaceBarTextStyle(
+ color: daemonDimInk(theme),
+ emphasized: emphasized,
+ ).copyWith(fontFeatures: daemonTextFeatures),
+ ),
+ ),
),
- SizedBox(width: cell.width),
- ],
],
),
),
diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swift
index 1287dc3d1..5038e5848 100644
--- a/desktop/macos/Runner/SwarmTitlebar.swift
+++ b/desktop/macos/Runner/SwarmTitlebar.swift
@@ -1270,6 +1270,7 @@ private final class SwarmSymbolButton: SwarmIconButton {
/// sprite (so a baton never moves the face) and a shiny `*` in the left gutter.
var cells = ""
var tally = ""
+ var tallyCells = 0
let columns = 8
/// A hatch in flight or its reveal running: drawn at full ink, not clickable.
var busy = false
@@ -1279,10 +1280,12 @@ private final class SwarmSymbolButton: SwarmIconButton {
var patch: NSColor?
/// The pointer arrived: "I see you". Never moves keyboard focus.
var onEnter: (() -> Void)?
+ var onExit: (() -> Void)?
private var textFont: NSFont { font ?? NSFont.monospacedSystemFont(ofSize: 13, weight: .regular) }
private var cellWidth: CGFloat { ceil(workspaceBarTextWidth("m", font: textFont)) }
var preferredWidth: CGFloat {
- cellWidth * CGFloat(columns + 2 + (tally.isEmpty ? 0 : tally.count + 1))
+ let count = max(tally.count, tallyCells)
+ return cellWidth * CGFloat(columns + 2 + (count == 0 ? 0 : count + 1))
}
override func mouseEntered(with event: NSEvent) {
@@ -1290,6 +1293,11 @@ private final class SwarmSymbolButton: SwarmIconButton {
if !isHidden { onEnter?() }
}
+ override func mouseExited(with event: NSEvent) {
+ super.mouseExited(with: event)
+ onExit?()
+ }
+
override func draw(_ dirtyRect: NSRect) {
guard !glyph.isEmpty || !cells.isEmpty else { return }
let ink = isEnabled || busy ? foreground : foreground.withAlphaComponent(0.35)
@@ -1501,6 +1509,10 @@ private final class SwarmTabStrip: NSView {
guard let self, self.actionsEnabled, !self.daemonButton.isHidden else { return }
self.emit?("daemonLook", nil)
}
+ daemonButton.onExit = { [weak self] in
+ guard let self, !self.daemonButton.isHidden else { return }
+ self.emit?("daemonLeave", nil)
+ }
addSubview(daemonButton)
shareButton.isBordered = false
shareButton.title = "[ Share ]"
@@ -1680,6 +1692,8 @@ private final class SwarmTabStrip: NSView {
let previousWidth = daemonButton.preferredWidth
daemonButton.cells = validDaemonText(state["cell"] as? String, cells: daemonButton.columns + 2) ?? ""
daemonButton.tally = validDaemonText(state["tally"] as? String, cells: 24) ?? ""
+ let heldCells = (state["tallyCells"] as? NSNumber)?.intValue ?? 0
+ daemonButton.tallyCells = max(daemonButton.tally.count, min(24, max(0, heldCells)))
daemonButton.foreground = statusColor(state["foreground"], fallback: terminalForeground)
daemonButton.tallyColor = statusColor(state["tallyColor"], fallback: terminalForeground.withAlphaComponent(0.62))
daemonButton.patch = state["patch"] is NSNumber ? statusColor(state["patch"], fallback: .black) : nil
diff --git a/desktop/test/daemon_workspace_test.dart b/desktop/test/daemon_workspace_test.dart
index 96db7a593..51163bafa 100644
--- a/desktop/test/daemon_workspace_test.dart
+++ b/desktop/test/daemon_workspace_test.dart
@@ -4,6 +4,7 @@ import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
+import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/core/models.dart';
@@ -802,8 +803,22 @@ void main() {
reason: 'the creature separates its counts from Git context',
);
expect(find.byKey(const ValueKey('daemon-voice')), findsNothing);
- await tester.tap(slot);
+ final glyphTarget = find.byKey(const ValueKey('daemon-slot-glyph'));
+ final beforeHover = tester.getRect(glyphTarget);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: Offset.zero);
+ addTearDown(mouse.removePointer);
+ await mouse.moveTo(beforeHover.center);
+ await tester.pump();
+ expect(find.byKey(const ValueKey('daemon-slot-tally')), findsNothing);
+ expect(tester.getRect(glyphTarget), beforeHover,
+ reason: 'reading a count must not move the creature away from the click');
+ await tester.tapAt(beforeHover.center);
+ await tester.pump();
+ await mouse.moveTo(Offset.zero);
await tester.pump();
+ expect(tester.getRect(glyphTarget).left, greaterThan(beforeHover.left),
+ reason: 'the unused count space is released after the pointer leaves');
expect(find.byKey(const ValueKey('daemon-slot-tally')), findsNothing);
// The switches are on the settings tab: 4.
await key(tester, LogicalKeyboardKey.digit4);
diff --git a/desktop/test/daemons/daemon_face_test.dart b/desktop/test/daemons/daemon_face_test.dart
index 09b1390d6..f0b419451 100644
--- a/desktop/test/daemons/daemon_face_test.dart
+++ b/desktop/test/daemons/daemon_face_test.dart
@@ -918,8 +918,10 @@ void main() {
);
face.sync(const DaemonWatch(doneCount: 1));
expect(face.tally, '1 done, 2 eggs');
+ face.setPointerInside(true);
face.sync(const DaemonWatch(doneCount: 1234));
expect(face.tally, '999+ done, 2 eggs');
+ final heldCells = face.tallyCells;
expect(face.tooltip, contains('1234'));
expect(face.detail, contains('1234 finished'));
face.seen();
@@ -928,6 +930,12 @@ void main() {
'2 eggs',
reason: 'looking clears work, never unhatched eggs',
);
+ expect(face.tallyCells, heldCells, reason: 'hover keeps the click target still');
+ face.setPointerInside(false);
+ expect(face.tallyCells, '2 eggs'.length);
+ face.setPointerInside(true);
+ zoo.bind(null);
+ expect(face.tallyCells, 0, reason: 'off reserves no space');
await settle(tester);
});
diff --git a/desktop/tool/swarm_titlebar_checks.swift b/desktop/tool/swarm_titlebar_checks.swift
index 3f96320cf..a858e9dd9 100644
--- a/desktop/tool/swarm_titlebar_checks.swift
+++ b/desktop/tool/swarm_titlebar_checks.swift
@@ -398,7 +398,8 @@ private extension SwarmTabStrip {
daemonButton.mouseEntered(with: pointer)
daemonButton.mouseExited(with: pointer)
daemonButton.mouseEntered(with: pointer)
- try checkTitlebar(events == ["daemonLook", "daemonLook"], "Each hover entry emits one look")
+ try checkTitlebar(events == ["daemonLook", "daemonLeave", "daemonLook"],
+ "Each hover entry emits one look and each exit releases the held count width")
daemonButton.mouseExited(with: pointer)
// Voice: tmux's message line replaces the status, and nothing moves.
daemon["voice"] = "pip: two agents idle. nothing needs you."
@@ -534,6 +535,19 @@ private extension SwarmTabStrip {
try checkTitlebar(!brightColumns.isEmpty && !mutedColumns.isEmpty &&
brightColumns.max()! < Int(cellWidth * 10) && mutedColumns.min()! >= Int(cellWidth * 10),
"The native creature draws before its dim counts, separating them from Git")
+ let countedFrame = daemonButton.frame
+ daemon["tallyCells"] = 13
+ daemon["tally"] = "1 egg"
+ updateDaemon(daemon)
+ try checkTitlebar(daemonButton.frame == countedFrame,
+ "Clearing done on hover preserves the native creature's click target")
+ events.removeAll()
+ daemonButton.mouseExited(with: pointer)
+ try checkTitlebar(events == ["daemonLeave"], "Pointer exit lets Flutter release the held count width")
+ daemon["tallyCells"] = nil
+ updateDaemon(daemon)
+ try checkTitlebar(daemonButton.frame.width < countedFrame.width,
+ "The count's empty space is released when hover ends")
daemon["tally"] = "999+ done, 999+ eggs"
updateDaemon(daemon)
try checkTitlebar(daemonButton.tally == "999+ done, 999+ eggs",
@@ -574,8 +588,8 @@ private extension SwarmTabStrip {
daemonButton.performClick(nil)
daemonButton.mouseEntered(with: pointer)
daemonButton.mouseExited(with: pointer)
- try checkTitlebar(events.isEmpty && !daemonButton.isEnabled,
- "A modal disables the daemon's click and look")
+ try checkTitlebar(events == ["daemonLeave"] && !daemonButton.isEnabled,
+ "A modal disables the daemon's click and look but still releases held width on exit")
update([:])
try checkTitlebar(daemonButton.isHidden && !daemonButton.isEnabled && voiceLabel.isHidden,
"Workspace teardown hides the daemon")
@@ -1011,9 +1025,10 @@ private extension SwarmTabStrip {
let beforeLook = messenger.calls.count, pendingReplies = messenger.replies.count
daemonButton.mouseEntered(with: hover)
daemonButton.mouseExited(with: hover)
- try checkTitlebar(messenger.calls.count == beforeLook + 1 && messenger.calls.last?.method == "daemonLook" &&
+ try checkTitlebar(messenger.calls.count == beforeLook + 2 &&
+ messenger.calls.suffix(2).map(\.method) == ["daemonLook", "daemonLeave"] &&
messenger.replies.count == pendingReplies && window.firstResponder === window.contentInput,
- "Hovering the daemon sends one look and never moves keyboard focus")
+ "Hovering the daemon sends entry and exit without moving keyboard focus")
updateDaemon([:])
let current = tabs[0].accessibilityChildren()!.first as! NSButton
window.makeFirstResponder(current)