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): add tab filter and recaps to Find

tonydd123f0cf434
diff --git a/mobile/lib/phone/agent_recap.dart b/mobile/lib/phone/agent_recap.dart
new file mode 100644
index 000000000..81dce5161
--- /dev/null
+++ b/mobile/lib/phone/agent_recap.dart
@@ -0,0 +1,264 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/widgets/skeleton.dart';
+import 'package:harness_mobile/state/session_preview.dart';
+
+import 'tty.dart';
+import 'tty_controls.dart';
+
+/// What a session's last finished turn came to, as Find shows it under the
+/// session's row.
+class PhoneRecap {
+ const PhoneRecap({
+ required this.headline,
+ required this.body,
+ required this.bodyAddsMore,
+ });
+
+ /// One paragraph, markup and line breaks flattened out — what the folded row
+ /// shows, two lines at most.
+ final String headline;
+
+ /// The reply as it was written — what the row unfolds to.
+ final String body;
+
+ /// Whether [body] says anything [headline] does not, before [headline] is
+ /// even measured against the room it has: a turn's own recap is a line about
+ /// a reply that is usually much longer.
+ final bool bodyAddsMore;
+}
+
+/// How much of a reply is flattened into a headline. Two lines of a phone row
+/// hold a small part of this; the rest is only ever read unfolded.
+const _headlineSource = 600;
+
+/// The recap [previews] holds for [key], or null when it holds none.
+///
+/// The headline is the turn's own `recap` where it had one
+/// ([SessionPreview.recap]), paired with the reply that same summary carried —
+/// never with a reply from another turn. Otherwise it is the reply on record
+/// ([SessionPreview.response]), flattened: a provider that writes no recap has
+/// still said something, and what it said is the truest line to show.
+PhoneRecap? phoneRecap(SessionPreviewStore previews, SessionPreviewKey? key) {
+ if (key == null) return null;
+ final preview = previews.read(key);
+ if (preview == null) return null;
+ final headline = preview.recap;
+ final saved = preview.savedText;
+ if (headline != null && saved != null) {
+ final flat = flattenRecap(headline);
+ if (flat.isNotEmpty) {
+ return PhoneRecap(
+ headline: flat,
+ body: saved,
+ bodyAddsMore: _flattenHead(saved) != flat,
+ );
+ }
+ }
+ final body = preview.response;
+ if (body == null) return null;
+ final flat = _flattenHead(body);
+ if (flat.isEmpty) return null;
+ return PhoneRecap(
+ headline: flat,
+ body: body,
+ // Cut before flattening, so the headline cannot be all of it; and a reply
+ // laid out in lines or lists reads differently unfolded than run together.
+ bodyAddsMore: body.length > _headlineSource || body.contains('\n'),
+ );
+}
+
+String _flattenHead(String text) => flattenRecap(
+ text.length > _headlineSource ? text.substring(0, _headlineSource) : text,
+);
+
+/// [text] as one plain paragraph: no headings, list markers, quote marks,
+/// emphasis or code ticks, and every run of whitespace a single space.
+String flattenRecap(String text) => text
+ .replaceAll(
+ RegExp(r'^[ \t]*(?:#{1,6}[ \t]+|[-*+][ \t]+|>[ \t]?)', multiLine: true),
+ '',
+ )
+ .replaceAll(RegExp(r'\*\*|__|`'), '')
+ .replaceAll(RegExp(r'\s+'), ' ')
+ .trim();
+
+/// The recap under one of Find's rows: two lines folded, the whole reply
+/// unfolded.
+///
+/// ⚠️ **Its own tap target, beside the row's and not inside it.** A tap on the
+/// row opens the session; a tap here only folds or unfolds. Nested in the row,
+/// every tap on the recap would light the row as though it were about to open.
+///
+/// Folds only where there is more to see — a recap that already fits in two
+/// lines and says all its reply does draws no chevron and takes no tap.
+class AgentRecap extends StatelessWidget {
+ const AgentRecap({
+ super.key,
+ required this.recap,
+ required this.expanded,
+ required this.onToggle,
+ });
+
+ final PhoneRecap recap;
+ final bool expanded;
+ final VoidCallback onToggle;
+
+ static const _rule = 1.0;
+ static const _inset = 10.0;
+ static const _gap = 8.0;
+ static const _chevron = 14.0;
+
+ /// The row's own gutter, so the rule stands under the first letter of the
+ /// name above it.
+ static const _outer = EdgeInsets.fromLTRB(Tty.origin, 0, Tty.origin, 10);
+
+ static TextStyle _style(Tty tty, bool expanded) =>
+ tty.style(color: expanded ? tty.text : tty.faint, size: TtySize.meta);
+
+ static Color _ruleColor(Tty tty) => tty.text.withValues(alpha: 0.16);
+
+ /// Whether [headline] runs past two lines in [width].
+ static bool _clipped(
+ BuildContext context,
+ String headline,
+ TextStyle style,
+ double width,
+ ) {
+ if (width <= 0) return false;
+ final painter = TextPainter(
+ text: TextSpan(
+ text: headline,
+ style: DefaultTextStyle.of(context).style.merge(style),
+ ),
+ maxLines: 2,
+ textDirection: Directionality.of(context),
+ textScaler: MediaQuery.textScalerOf(context),
+ )..layout(maxWidth: width);
+ final clipped = painter.didExceedMaxLines;
+ painter.dispose();
+ return clipped;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ final style = _style(tty, expanded);
+ final motion = MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : AppMotion.fold;
+ return Padding(
+ padding: _outer,
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final textWidth =
+ constraints.maxWidth - _rule - _inset - _gap - _chevron;
+ final foldable =
+ expanded ||
+ recap.bodyAddsMore ||
+ _clipped(context, recap.headline, style, textWidth);
+ final framed = Container(
+ padding: const EdgeInsets.only(left: _inset),
+ decoration: BoxDecoration(
+ border: Border(
+ left: BorderSide(
+ width: _rule,
+ color: expanded ? tty.faint : _ruleColor(tty),
+ ),
+ ),
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: AnimatedSize(
+ duration: motion,
+ curve: AppMotion.curve,
+ alignment: Alignment.topLeft,
+ child: Text(
+ expanded ? recap.body : recap.headline,
+ maxLines: expanded ? null : 2,
+ overflow: expanded ? null : TextOverflow.ellipsis,
+ style: style,
+ ),
+ ),
+ ),
+ if (foldable) ...[
+ const SizedBox(width: _gap),
+ Padding(
+ padding: const EdgeInsets.only(top: 1),
+ child: AnimatedRotation(
+ turns: expanded ? 0.5 : 0,
+ duration: motion,
+ curve: AppMotion.curve,
+ child: Icon(
+ LucideIcons.chevronDown,
+ size: _chevron,
+ color: tty.faint,
+ ),
+ ),
+ ),
+ ] else
+ // Keeps a folded and an unfoldable recap the same width, so
+ // their lines break at the same place down the list.
+ const SizedBox(width: _gap + _chevron),
+ ],
+ ),
+ );
+ if (!foldable) return framed;
+ return Semantics(
+ button: true,
+ onTapHint: expanded ? 'Fold the recap' : 'Show the whole recap',
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ onToggle();
+ },
+ child: framed,
+ ),
+ );
+ },
+ ),
+ );
+ }
+}
+
+/// The recap's place held while it is being read, so the row does not grow
+/// under the reader's eye when it lands. Two lines, as a folded recap is.
+class AgentRecapPlaceholder extends StatelessWidget {
+ const AgentRecapPlaceholder({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ final style = AgentRecap._style(tty, false);
+ return Padding(
+ padding: AgentRecap._outer,
+ child: Container(
+ padding: const EdgeInsets.only(
+ left: AgentRecap._inset,
+ right: AgentRecap._gap + AgentRecap._chevron,
+ ),
+ decoration: BoxDecoration(
+ border: Border(
+ left: BorderSide(
+ width: AgentRecap._rule,
+ color: AgentRecap._ruleColor(tty),
+ ),
+ ),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SkeletonText(style: style),
+ SkeletonText(style: style, widthFactor: 0.6),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/desk_groups.dart b/mobile/lib/phone/desk_groups.dart
index b692cee1a..b84427c27 100644
--- a/mobile/lib/phone/desk_groups.dart
+++ b/mobile/lib/phone/desk_groups.dart
@@ -86,6 +86,63 @@ List<DeskGroup> deskGroups(AppNotifier notifier, List<AgentEntry> visible) {
];
}
+/// One tab as the Harnesses list narrows to it: its id, its name, and every
+/// agent it names.
+///
+/// ⚠️ **Not a [DeskGroup].** A group keeps only the agents with a terminal —
+/// what a swipe can land on — and this list also draws stopped work, which a
+/// tap resumes. A filter built from groups would hide a tab's stopped agents
+/// under that tab while All still showed them.
+class DeskTabFilter {
+ const DeskTabFilter({
+ required this.id,
+ required this.name,
+ required this.keys,
+ });
+
+ final String id;
+ final String name;
+
+ /// [DeskPaneRef.key] of every agent on the tab, reachable or not.
+ final Set<String> keys;
+
+ /// Whether the tab names no agent at all, as against naming agents this
+ /// phone cannot reach right now.
+ bool get isEmpty => keys.isEmpty;
+
+ bool holds(AgentEntry entry) => keys.contains(
+ DeskPaneRef(machineId: entry.machineId, agentId: entry.agent.id).key,
+ );
+}
+
+/// The desk's tabs, in the desk's order, each named as the tab strip names it.
+///
+/// Empty where the desk has no tabs or has not answered — and then there is
+/// nothing to narrow by, so the list draws no filter at all.
+List<DeskTabFilter> deskTabFilters(
+ AppNotifier notifier,
+ List<AgentEntry> visible,
+) {
+ final tabs = notifier.deskTabs;
+ if (tabs.isEmpty) return const [];
+ final known = {
+ for (final entry in visible)
+ DeskPaneRef(machineId: entry.machineId, agentId: entry.agent.id).key:
+ entry.agent,
+ };
+ return [
+ for (final tab in tabs)
+ DeskTabFilter(
+ id: tab.id,
+ name: deskTabName(
+ tab,
+ tab.panes.isEmpty ? null : known[tab.panes.first.key],
+ ),
+ keys: {for (final pane in tab.panes) pane.key},
+ ),
+ ];
+}
+
/// What a tab is called — the desktop's rule (`AppNotifier._syncAgentName`).
///
/// A name somebody gave it stands. Otherwise the tab is named after its first
diff --git a/mobile/lib/phone/desk_tab_filter_bar.dart b/mobile/lib/phone/desk_tab_filter_bar.dart
new file mode 100644
index 000000000..a9fa0b70e
--- /dev/null
+++ b/mobile/lib/phone/desk_tab_filter_bar.dart
@@ -0,0 +1,297 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/widgets/touch_target.dart';
+
+import 'tty.dart';
+import 'tty_controls.dart';
+
+/// One chip on [DeskTabFilterBar]: a desk tab, or — with a null [id] — every
+/// harness, whatever tab it is on or none.
+class DeskTabFilterChoice {
+ const DeskTabFilterChoice({
+ required this.id,
+ required this.name,
+ required this.count,
+ });
+
+ final String? id;
+ final String name;
+
+ /// How many harnesses picking it would list for the query as it stands.
+ final int count;
+}
+
+/// The chips under Find's field: All, then the desk's tabs in the desk's order.
+///
+/// Chips and not a tab strip. What they change is which rows of ONE list are
+/// drawn — the field above narrows the same list — and a strip of underlined
+/// tabs reads as pages to move between. Each chip counts what it would list for
+/// the query as typed, so a tab with nothing for that query says so before it
+/// is tapped.
+///
+/// ⚠️ **A chip with nothing behind it is dimmed, never hidden.** A tab whose
+/// machine is asleep holds nothing this phone can open, and a chip that vanished
+/// with it would read as a tab that was closed.
+class DeskTabFilterBar extends StatefulWidget {
+ const DeskTabFilterBar({
+ super.key,
+ required this.choices,
+ required this.selected,
+ required this.onSelected,
+ });
+
+ final List<DeskTabFilterChoice> choices;
+
+ /// The [DeskTabFilterChoice.id] picked; null is All.
+ final String? selected;
+
+ final ValueChanged<String?> onSelected;
+
+ /// Drawn height: a chip, and the gap under it.
+ static const double height = _chipHeight + 8;
+ static const double _chipHeight = 30;
+
+ @override
+ State<DeskTabFilterBar> createState() => _DeskTabFilterBarState();
+}
+
+class _DeskTabFilterBarState extends State<DeskTabFilterBar> {
+ final _scroll = ScrollController();
+
+ /// One per chip, so the picked one can be scrolled into view — which a pick
+ /// made from outside the bar needs: "Show all tabs" under an empty tab puts
+ /// All back while the rail may still be scrolled far past it.
+ final _chipKeys = <String?, GlobalKey>{};
+
+ /// Which ends of the rail have chips past them, and so fade out.
+ bool _moreBefore = false, _moreAfter = false;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) => _readEdges());
+ }
+
+ @override
+ void didUpdateWidget(DeskTabFilterBar old) {
+ super.didUpdateWidget(old);
+ final ids = {for (final choice in widget.choices) choice.id};
+ _chipKeys.removeWhere((id, _) => !ids.contains(id));
+ if (old.selected != widget.selected) {
+ final picked = widget.selected;
+ WidgetsBinding.instance.addPostFrameCallback((_) => _reveal(picked));
+ }
+ }
+
+ @override
+ void dispose() {
+ _scroll.dispose();
+ super.dispose();
+ }
+
+ /// Scrolls the chip for [id] into view, and only if it is not in view already.
+ ///
+ /// Both policies are asked for, and at most one of them moves anything: a chip
+ /// narrower than the rail can hang off one end, never both.
+ void _reveal(String? id) {
+ if (!mounted) return;
+ final chip = _chipKeys[id]?.currentContext;
+ if (chip == null) return;
+ final duration = MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : AppMotion.swap;
+ for (final policy in const [
+ ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
+ ScrollPositionAlignmentPolicy.keepVisibleAtStart,
+ ]) {
+ Scrollable.ensureVisible(
+ chip,
+ duration: duration,
+ curve: AppMotion.curve,
+ alignmentPolicy: policy,
+ );
+ }
+ }
+
+ void _readEdges([ScrollMetrics? metrics]) {
+ if (!mounted) return;
+ final read = metrics ?? (_scroll.hasClients ? _scroll.position : null);
+ if (read == null || !read.hasContentDimensions) return;
+ final before = read.extentBefore > 0.5;
+ final after = read.extentAfter > 0.5;
+ if (before == _moreBefore && after == _moreAfter) return;
+ setState(() {
+ _moreBefore = before;
+ _moreAfter = after;
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final choices = widget.choices;
+ // Always masked, even with nothing to fade: taking the mask away would
+ // re-parent the scroll view and throw away where it was scrolled to.
+ return SizedBox(
+ height: DeskTabFilterBar.height,
+ child: ShaderMask(
+ blendMode: BlendMode.dstIn,
+ shaderCallback: (bounds) {
+ // 24pt of fade at each end; none on a rail too narrow to spare it.
+ final edge = bounds.width <= 48 ? 0.0 : 24 / bounds.width;
+ const shown = Color(0xFF000000);
+ const gone = Color(0x00000000);
+ return LinearGradient(
+ colors: [
+ _moreBefore ? gone : shown,
+ shown,
+ shown,
+ _moreAfter ? gone : shown,
+ ],
+ stops: [0, edge, 1 - edge, 1],
+ ).createShader(bounds);
+ },
+ child: NotificationListener<ScrollMetricsNotification>(
+ onNotification: (notification) {
+ _readEdges(notification.metrics);
+ return false;
+ },
+ child: NotificationListener<ScrollNotification>(
+ onNotification: (notification) {
+ _readEdges(notification.metrics);
+ return false;
+ },
+ // A plain Row in a scroll view, not a lazy list: a desk has a
+ // handful of tabs, and every chip has to be built for [_reveal] to
+ // find it.
+ child: SingleChildScrollView(
+ controller: _scroll,
+ scrollDirection: Axis.horizontal,
+ // The rows' own gutter, so the first chip starts where their
+ // names do.
+ padding: const EdgeInsets.fromLTRB(Tty.origin, 0, Tty.origin, 8),
+ child: Row(
+ children: [
+ for (var i = 0; i < choices.length; i++) ...[
+ if (i > 0) const SizedBox(width: 6),
+ _FilterChip(
+ key: _chipKeys.putIfAbsent(choices[i].id, GlobalKey.new),
+ choice: choices[i],
+ selected: choices[i].id == widget.selected,
+ onTap: () => widget.onSelected(choices[i].id),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _FilterChip extends StatefulWidget {
+ const _FilterChip({
+ super.key,
+ required this.choice,
+ required this.selected,
+ required this.onTap,
+ });
+
+ final DeskTabFilterChoice choice;
+ final bool selected;
+ final VoidCallback onTap;
+
+ @override
+ State<_FilterChip> createState() => _FilterChipState();
+}
+
+class _FilterChipState extends State<_FilterChip> {
+ bool _pressed = false;
+
+ void _press(bool pressed) {
+ if (_pressed == pressed) return;
+ setState(() => _pressed = pressed);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ final choice = widget.choice;
+ final selected = widget.selected;
+ final empty = choice.count == 0;
+ // The picked chip is the one solid thing on the rail — the terminal's ink
+ // turned into ground — so which tab the list is showing is read without
+ // reading.
+ final ink = selected
+ ? tty.ground
+ : empty
+ ? tty.dim
+ : tty.text;
+ final countInk = selected
+ ? tty.ground.withValues(alpha: 0.62)
+ : empty
+ ? tty.dim
+ : tty.faint;
+ return Semantics(
+ button: true,
+ selected: selected,
+ label: '${choice.name}, ${choice.count}',
+ excludeSemantics: true,
+ child: TouchTarget(
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTapDown: (_) => _press(true),
+ onTapUp: (_) => _press(false),
+ onTapCancel: () => _press(false),
+ onTap: () {
+ HapticFeedback.selectionClick();
+ widget.onTap();
+ },
+ child: AnimatedContainer(
+ duration: AppMotion.press,
+ curve: AppMotion.curve,
+ height: DeskTabFilterBar._chipHeight,
+ constraints: const BoxConstraints(maxWidth: 200),
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ decoration: BoxDecoration(
+ color: selected
+ ? tty.text
+ : _pressed
+ ? ttyRaised(tty)
+ : Colors.transparent,
+ borderRadius: BorderRadius.circular(6),
+ border: Border.all(
+ color: selected
+ ? Colors.transparent
+ : tty.text.withValues(alpha: 0.16),
+ ),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // A long tab name gives way; the count after it never does.
+ Flexible(
+ child: Text(
+ choice.name,
+ maxLines: 1,
+ softWrap: false,
+ overflow: TextOverflow.ellipsis,
+ style: tty.style(color: ink, size: TtySize.meta),
+ ),
+ ),
+ const SizedBox(width: 7),
+ Text(
+ '${choice.count}',
+ style: tty.style(color: countInk, size: TtySize.meta),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dart
index ccf7bd41c..3fd0258c3 100644
--- a/mobile/lib/phone/phone_search_results.dart
+++ b/mobile/lib/phone/phone_search_results.dart
@@ -9,6 +9,9 @@ import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/state/external_session.dart';
import 'agent_index.dart';
+import 'agent_recap.dart';
+import 'desk_groups.dart';
+import 'desk_tab_filter_bar.dart';
import 'find_row.dart';
import 'fzf.dart' show fzfAge;
import 'phone_destination.dart';
@@ -81,12 +84,13 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
void openFirst() {
final search = widget.controller;
final showing = widget.showing;
+ final shown = _narrowed(search.rows, _tab(_tabs(search)));
final rows = search.matchQuery.trim().isEmpty && showing != null
? [
- for (final row in search.rows)
+ for (final row in shown)
if (!_isShowing(row, showing)) row,
]
- : search.rows;
+ : shown;
for (final row in rows) {
if (search.canSubmit(row)) {
_tap(row);
@@ -102,6 +106,15 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
/// person who only meant to open one.
String? _resuming;
+ /// The desk tab the list is narrowed to; null is All. Only ever a choice: a tab closed on another
+ /// computer while it was picked leaves the list on All ([_tab]) rather than on a filter nothing
+ /// on screen names.
+ String? _tabId;
+
+ /// The rows whose recap is unfolded, by [PhoneDestination.id]. Kept across a change of tab or
+ /// query, so a recap somebody opened is still open when they come back to it.
+ final _unfolded = <String>{};
+
/// The order Find opened with — each row's section (needs you, recent, the one on screen,
/// paused) and place in it, by id. Held while Find is open: a harness that starts or stops
/// asking, pauses, or does something new keeps its place and only its words change, so the row
@@ -150,27 +163,103 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
builder: (context, _) {
AppTheme.watch(context);
final search = widget.controller;
- return _find(search, search.rows);
+ final all = search.rows;
+ final tabs = _tabs(search);
+ final tab = _tab(tabs);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ // Under the field, and only over the plain list of harnesses: a mode lists commands,
+ // models or places, none of which is on a tab.
+ if (tabs.isNotEmpty)
+ DeskTabFilterBar(
+ choices: [
+ DeskTabFilterChoice(
+ id: null,
+ name: 'All',
+ count: _sessions(all),
+ ),
+ for (final each in tabs)
+ DeskTabFilterChoice(
+ id: each.id,
+ name: each.name,
+ count: all.where((row) => _inTab(each, row)).length,
+ ),
+ ],
+ selected: tab?.id,
+ onSelected: (id) => setState(() => _tabId = id),
+ ),
+ Expanded(
+ child: _find(
+ search,
+ _narrowed(all, tab),
+ tab: tab,
+ everywhere: _sessions(all),
+ ),
+ ),
+ ],
+ );
},
);
+ /// Whether this is Find's plain list of harnesses — no mode (`>`, `?`, a group, `:`) and not
+ /// walked into one project or machine. The only list the tab chips narrow.
+ static bool _plain(PhoneSearchController search) =>
+ !search.isCommandMode &&
+ !search.isHelpMode &&
+ !search.isGroupMode &&
+ !search.isModelMode &&
+ !search.canGoBack;
+
+ /// The desk's tabs as the chips offer them: none off the plain list, and none where the desk has
+ /// no tabs or has not answered — and then no chips are drawn at all.
+ List<DeskTabFilter> _tabs(PhoneSearchController search) => _plain(search)
+ ? deskTabFilters(widget.notifier, agentIndex(widget.notifier))
+ : const [];
+
+ /// The picked tab among [tabs]; null is All.
+ DeskTabFilter? _tab(List<DeskTabFilter> tabs) =>
+ tabs.where((tab) => tab.id == _tabId).firstOrNull;
+
+ static bool _inTab(DeskTabFilter tab, PhoneDestination row) {
+ final entry = row.entry;
+ return entry != null && tab.holds(entry);
+ }
+
+ /// [rows] narrowed to [tab] — to harnesses only, since a tab holds nothing else: a machine, a
+ /// project, a conversation Harness did not start are on no tab.
+ static List<PhoneDestination> _narrowed(
+ List<PhoneDestination> rows,
+ DeskTabFilter? tab,
+ ) => tab == null
+ ? rows
+ : [
+ for (final row in rows)
+ if (_inTab(tab, row)) row,
+ ];
+
+ /// The sessions among [rows] — harnesses and the conversations Harness did not start — which is
+ /// what All's chip counts.
+ static int _sessions(List<PhoneDestination> rows) =>
+ rows.where((row) => row.isAgent || row.external != null).length;
+
/// Find's list: grows down from the field at the top. With nothing typed, `needs you` (newest
/// question first) then `recent`, the harness on screen last, `+ New Harness` at the end; typed,
/// the matches in their order, then the commands that match, then `+ New Harness in <project>`.
/// See docs/plans/2026-09-26-003-mobile-find-new-spec.md.
- Widget _find(PhoneSearchController search, List<PhoneDestination> rows) {
+ Widget _find(
+ PhoneSearchController search,
+ List<PhoneDestination> rows, {
+ required DeskTabFilter? tab,
+ required int everywhere,
+ }) {
// The words, less any time ("dial last week" lights "dial").
final terms = phoneSearchTerms(search.wordsQuery);
final showing = widget.showing;
final now = DateTime.now();
final tty = Tty.of(context);
final typed = search.matchQuery.trim().isNotEmpty;
- final plain =
- !search.isCommandMode &&
- !search.isHelpMode &&
- !search.isGroupMode &&
- !search.isModelMode &&
- !search.canGoBack;
+ final plain = _plain(search);
bool asking(PhoneDestination row) => row.entry?.isWaiting ?? false;
DateTime since(PhoneDestination row) {
final entry = row.entry;
@@ -242,28 +331,52 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
final project = search.projectMatch;
final children = <Widget>[];
var index = 0;
- Widget row(PhoneDestination row) =>
- _findRow(row, terms, now, tty, selected: index++ == selectedAt);
+ // A row, and under it what its session last came to.
+ List<Widget> row(PhoneDestination row) => [
+ _findRow(row, terms, now, tty, selected: index++ == selectedAt),
+ ?_recap(row),
+ ];
if (needsYou.isNotEmpty) {
children.add(FindHeader('needs you', color: tty.yellow));
- children.addAll(needsYou.map(row));
+ children.addAll(needsYou.expand(row));
children.add(const FindHeader('recent'));
}
- children.addAll(rest.map(row));
- if (current != null) children.add(row(current));
+ children.addAll(rest.expand(row));
+ if (current != null) children.addAll(row(current));
// At the end and without a heading: each one's own word on the right says `paused`.
- children.addAll(pausedRows.map(row));
+ children.addAll(pausedRows.expand(row));
if (ordered.isEmpty) {
children.add(
Padding(
padding: const EdgeInsets.fromLTRB(Tty.origin, 20, Tty.origin, 8),
child: TtyText(
- search.total == 0 && !typed ? 'No harnesses running.' : 'No match.',
+ switch (tab) {
+ null =>
+ search.total == 0 && !typed
+ ? 'No harnesses running.'
+ : 'No match.',
+ _ when typed => 'No match in ${tab.name}.',
+ _ when tab.isEmpty => 'No harnesses in ${tab.name} yet.',
+ _ => 'Nothing in ${tab.name} can be reached right now.',
+ },
color: tty.faint,
size: TtySize.row,
),
),
);
+ // The way out of an empty tab, where the eye already is — rather than back up at a chip the
+ // rail may have scrolled away.
+ if (tab != null && (!typed || everywhere > 0)) {
+ children.add(
+ FindRow(
+ title: 'Show all tabs',
+ detail: typed
+ ? '$everywhere ${everywhere == 1 ? 'match' : 'matches'} in all tabs'
+ : null,
+ onTap: () => setState(() => _tabId = null),
+ ),
+ );
+ }
}
if (search.commandMatches.isNotEmpty) {
children.add(const FindHeader('commands'));
@@ -299,6 +412,28 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
);
}
+ /// What [row]'s session last came to, folded under it — or its place held while it is read, or
+ /// nothing for a row that is not a harness or a session that has not said anything yet.
+ Widget? _recap(PhoneDestination row) {
+ if (!row.isAgent) return null;
+ final previews = widget.notifier.sessionPreviews;
+ final key = row.previewKey;
+ final recap = phoneRecap(previews, key);
+ if (recap != null) {
+ return AgentRecap(
+ recap: recap,
+ expanded: _unfolded.contains(row.id),
+ onToggle: () => setState(() {
+ if (!_unfolded.remove(row.id)) _unfolded.add(row.id);
+ }),
+ );
+ }
+ if (key != null && previews.isReading(key)) {
+ return const AgentRecapPlaceholder();
+ }
+ return null;
+ }
+
/// One harness (or command) as a Find row — see [FindRow].
Widget _findRow(
PhoneDestination row,
@@ -573,10 +708,11 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
// The neighbours are the rows as drawn, not the Agents tab's list: swiping
// walks exactly what the query returned, in the order the person was
// looking at when they tapped.
+ final search = widget.controller;
openAgentPager(
context,
widget.notifier,
- phoneSearchAgentEntries(widget.controller.rows),
+ phoneSearchAgentEntries(_narrowed(search.rows, _tab(_tabs(search)))),
entry,
);
}
diff --git a/mobile/lib/state/session_preview.dart b/mobile/lib/state/session_preview.dart
index 599ee24e5..4f910d4dd 100644
--- a/mobile/lib/state/session_preview.dart
+++ b/mobile/lib/state/session_preview.dart
@@ -1,8 +1,10 @@
/// Ported from the desktop's `lib/state/session_preview.dart`, so a phone
/// search reaches the same session content the desktop's Open Agent picker
/// does. Keep the two in step; the additions here are
-/// [SessionPreview.searchParts], which the phone's result rows quote from, and
-/// [SessionPreviewStore.markStale], for turns a sleeping phone never heard.
+/// [SessionPreview.searchParts], which the phone's result rows quote from,
+/// [SessionPreviewStore.markStale], for turns a sleeping phone never heard, and
+/// [SessionPreview.recap] with [SessionPreviewStore.isReading], for the recap
+/// under each row of the Harnesses list.
library;
import 'dart:async';
@@ -28,6 +30,15 @@ class SessionPreview {
/// `notify/done_notice.dart` stays silent for it. Unlike [completedText] it
/// never carries over from an earlier turn.
String? turnReply;
+
+ /// The headline of the turn [savedText] came from — the `summary` event's
+ /// `recap`, one line of at most 200 characters on the wire — or null where
+ /// that turn had none.
+ ///
+ /// ⚠️ **Dropped the moment a turn this phone watched end says something.**
+ /// From then on the reply on record is that turn's, which this headline was
+ /// not written for; the next read brings the new turn's own.
+ String? recap;
String _streamText = '';
String? _searchText;
bool turnOpen = false,
@@ -84,6 +95,7 @@ class SessionPreview {
earlierRequest,
liveText,
responseExcerpt,
+ recap,
...earlierResponses,
activity,
}.whereType<String>().toList();
@@ -135,6 +147,15 @@ class SessionPreviewStore extends ChangeNotifier {
/// until [freshFor] runs out and something happens to warm it again.
void markStale(SessionPreviewKey key) => _records[key]?._attemptedAt = null;
+ /// Whether [key] is being read, or is queued to be — what lets a row hold a
+ /// placeholder for content on its way rather than grow when it lands.
+ ///
+ /// False for a key that can no longer be fetched: a queued read of it is
+ /// dropped without a word ([_drain]), and a placeholder waiting on it would
+ /// wait for ever.
+ bool isReading(SessionPreviewKey key) =>
+ (_inFlight.contains(key) || _queue.contains(key)) && canFetch(key);
+
SessionPreview _entry(SessionPreviewKey key) {
final entry = _records.remove(key) ?? SessionPreview();
entry._searchText = null;
@@ -207,16 +228,24 @@ class SessionPreviewStore extends ChangeNotifier {
final events = reply['events'];
if (events is List) {
final responses = <String>[];
+ String? headline;
for (final event in events.take(3)) {
if (event is! Map || event['kind'] != 'summary') continue;
final text =
previewText(event['fullText'], limit: 6000) ??
previewText(event['text'], limit: 6000) ??
previewText(event['recap'], limit: 6000);
- if (text != null && !responses.contains(text)) responses.add(text);
+ if (text == null || responses.contains(text)) continue;
+ // The headline of the event [savedText] is taken from, and of no
+ // other: an earlier turn's would sit over the wrong reply.
+ if (responses.isEmpty) {
+ headline = previewText(event['recap'], limit: 400);
+ }
+ responses.add(text);
}
if (responses.isNotEmpty) {
entry.savedText = responses.first;
+ entry.recap = headline;
entry.earlierResponses
..clear()
..addAll(responses.skip(1));
@@ -295,7 +324,10 @@ class SessionPreviewStore extends ChangeNotifier {
entry.turnOpen = false;
entry.interrupted = payload['aborted'] == true;
entry.turnReply = entry.liveText;
- if (entry.liveText != null) entry.completedText = entry.liveText;
+ if (entry.liveText != null) {
+ entry.completedText = entry.liveText;
+ entry.recap = null;
+ }
entry.liveText = null;
entry.activity = null;
}