mirror of
https://github.com/block/buzz.git
synced 2026-11-07 01:41:06 +00:00
## Summary When you mention one of your agents in an ordinary channel on mobile, nothing in the channel showed that the agent was working until its reply landed. The agent answers in the mention's thread, so its typing (kind 20002) is thread-scoped, and the channel timeline hides thread typing. The header working dot that used to cover this was removed in #8052, #8075 and #8082. This change brings buzz-app's behaviour to mobile. In buzz-app, the thread summary under a message shows the viewer's own agents while they type in that thread (`MessageRow.tsx` `useThreadAgents`, described in `docs/agents.md`). Mobile now does the same. The root message's reply row shows the working agents' avatars and the typing dots, and the row appears even under a mention that has no replies yet. It then reads "View thread". Tapping it opens the thread. When the reply arrives and the typing ends, the dots go away and the row reads "1 reply". The details follow buzz-app: - Only your agents count. buzz-app's "your agents" (`agentChoices.identities`) are your agent inventory, which is the kind 30177 records you author with archived agents included, plus your local agents. It does not read the NIP-OA owner tag. Mobile uses the same inventory. An agent that only names you as owner in its profile does not count. People and other agents typing in a thread stay inside the thread view. - Working agents leave the participant stack for their own group: up to two agent-shaped avatars side by side, then "+N", then the dots. - The curved reply branch shows only when the message has replies. - buzz-app's channel indicator by the composer also includes your agents working in any thread ("Channel views include threads" in `current-activity.ts`). Mobile's channel-level surface is the typing row at the end of the timeline. In ordinary channels, that row now also shows your agents that are typing in a thread, with the agent avatar shape. It goes away when the agent's reply arrives. - The spoken labels use buzz-app's strings: "View thread: Morty is working", "View thread: 3 agents are working" and "View thread: 1 reply. Morty working". - Me and DMs already show thread typing inline, so they are unchanged. Code changes: - `TypingDots` is extracted from `AgentTypingBubble`, so the reply row and the bubble share one animation. It respects reduce motion. - `ReplySummaryLink` accepts a nullable summary and a list of working agents with their names. `SmallAvatar` gains an `agent` flag for the working group, and `InlineAgentTyping` a `knownAgents` set so the channel typing row gives inventory agents the agent shape. - `meAgentInventoryProvider` holds the inventory keys. It is read only while a thread in the channel has typing. Each read, failed ones included, is reused for 30 seconds, then read again if still watched, or dropped. So the inventory refreshes every 30 seconds while it is watched, and a short gap between an agent's messages does not query again. - The page selects a "pubkey root" key from channel typing, so typing expiry refreshes do not rebuild it. Less than buzz-app, not in this PR: - buzz-app prefers lifecycle evidence (local agent state and kind 24200 observer turns) and falls back to typing. Mobile uses typing only. So when an agent stops without replying, mobile keeps its dots until the typing expires (8 seconds). A second buzz-app device without that evidence behaves the same way. I found no 24200 publisher in buzz-app itself. buzz-app publishes typing (kind 20002) for the agents it runs. - The channel typing row reads "Morty is typing" where buzz-app's indicator says "working". It has no popover that names the thread and no tap action. It sits after the newest message, so it scrolls away with the timeline, while buzz-app's indicator stays by the composer. ### Related issue N/A. Reported in Buzz #buzz-bugs. Searched issues and PRs for duplicates: none found. ### Testing Android emulator, local relay, build of `3caa17a20`. Demo User mentions Morty. Morty, Summer, Jerry and Rick send thread typing: - Morty is a channel bot in Demo User's agent inventory. - Summer and Jerry are in the inventory but are ordinary members, so only the inventory gives them the agent shape. - Rick names Demo User as owner in his profile but is not in the inventory. In the video: 1. The root message shows Morty and Summer, "+1", the dots and "View thread", with no reply branch. The channel typing row reads "Morty and 2 others" with three agent avatars. Rick does not show. 2. Tapping "View thread" opens the thread before the first reply. Back to the channel. 3. Summer and Jerry stop. Their typing expires, and only Morty is left on both rows. 4. Morty replies. The typing row goes away, the reply branch shows, and the root row reads "1 reply". The UI tree confirmed "View thread: 3 agents are working", "Morty and 2 others are typing", "View thread: Morty is working", "Morty is typing" and "View thread: 1 reply". https://github.com/user-attachments/assets/2237e565-aa48-405a-84ca-39ab9a06b7a6 - The widget test "an agent working in a thread shows on its root message" (`channel_detail_page_test.dart`, Typing indicator group) covers these cases: - A person, and an agent outside the inventory that names you as owner, show no row and no channel typing row. - Inventory agents also show in the channel typing row ("Morty and 2 others are typing", checked in the semantics tree), with the agent shape. That row goes away when the reply arrives. - Three inventory agents show two avatars with the agent shape, "+1", "View thread", no branch, and "View thread: 3 agents are working". - The row opens the thread before the first reply. - After the reply, Morty shows once, the branch shows, and the label is "View thread: 1 reply. Morty working". - With Summer still typing, Morty removed from the inventory stops counting after the 30-second refresh. - Each check was made to fail on purpose by removing the code it guards. - `just mobile-check` and the full `just mobile-test` passed on `3caa17a20` (3996 passed, 28 skipped). - Auto and Cerveau reviewed it adversarially against buzz-app origin/main. Their findings are fixed, and their last pass found nothing. - Not yet tested on iOS or by a human. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
221 lines
7.7 KiB
Dart
221 lines
7.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import '../../shared/profile/user_cache_provider.dart';
|
|
import '../../shared/profile/user_profile.dart';
|
|
import '../../shared/theme/theme.dart';
|
|
import 'small_avatar.dart';
|
|
import 'timeline_message.dart';
|
|
import 'typing_dots.dart';
|
|
|
|
/// Desktop-style reply link with a curved branch below the message bubble.
|
|
class ReplySummaryLink extends ConsumerWidget {
|
|
const ReplySummaryLink({
|
|
super.key,
|
|
required this.summary,
|
|
required this.onTap,
|
|
this.hasReactions = false,
|
|
this.mirrored = false,
|
|
this.working = const [],
|
|
this.workingNames = const [],
|
|
});
|
|
|
|
/// Null while agents work on a message that has no replies yet.
|
|
final ThreadSummary? summary;
|
|
final VoidCallback onTap;
|
|
final bool hasReactions;
|
|
|
|
/// Agents working in this thread, shown with typing dots, as on desktop.
|
|
final List<String> working;
|
|
|
|
/// Display names for [working], in the same order, for the spoken label.
|
|
final List<String> workingNames;
|
|
|
|
/// Places the connector on the outgoing edge without reversing its contents.
|
|
final bool mirrored;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final summary = this.summary;
|
|
final workingKeys = {for (final pubkey in working) pubkey.toLowerCase()};
|
|
// As on desktop, working agents leave the participant stack for the
|
|
// working group: at most two avatars, then a count.
|
|
final participants = [
|
|
for (final pubkey in summary?.participantPubkeys ?? const <String>[])
|
|
if (!workingKeys.contains(pubkey.toLowerCase())) pubkey,
|
|
].take(3).toList();
|
|
final shownWorking = workingKeys.take(2).toList();
|
|
final hiddenWorking = workingKeys.length - shownWorking.length;
|
|
final userCache = ref.watch(userCacheProvider);
|
|
final label = summary == null
|
|
? 'View thread'
|
|
: summary.isCountPending
|
|
? 'Replies'
|
|
: '${summary.replyCount}${summary.isLowerBound ? '+' : ''} ${summary.replyCount == 1 ? 'reply' : 'replies'}';
|
|
// Desktop's spoken strings, in MessageRow's thread summary.
|
|
final spoken = switch (workingNames) {
|
|
[] => summary == null ? '' : label,
|
|
_ when summary != null => '$label. ${workingNames.join(', ')} working',
|
|
[final only] => '$only is working',
|
|
_ => '${workingNames.length} agents are working',
|
|
};
|
|
final connectorTop = hasReactions ? -Grid.half : Grid.half;
|
|
return Padding(
|
|
padding: EdgeInsets.only(
|
|
left: mirrored ? 0 : Grid.xxs,
|
|
right: mirrored ? Grid.xxs : 0,
|
|
),
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
// As on desktop, the branch joins existing replies only.
|
|
if (summary != null)
|
|
Positioned.fill(
|
|
top: connectorTop,
|
|
child: IgnorePointer(
|
|
child: CustomPaint(
|
|
painter: _ReplyConnector(
|
|
context.colors.outlineVariant,
|
|
mirrored ? TextDirection.rtl : TextDirection.ltr,
|
|
connectorTop,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: mirrored ? 0 : Grid.twelve,
|
|
right: mirrored ? Grid.twelve : 0,
|
|
),
|
|
child: Semantics(
|
|
button: true,
|
|
label: 'View thread: $spoken',
|
|
onTap: onTap,
|
|
excludeSemantics: true,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(Radii.container),
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(minHeight: 44),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(Grid.half),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (participants.isNotEmpty) ...[
|
|
_AvatarStack(participants, userCache),
|
|
const SizedBox(width: Grid.half),
|
|
],
|
|
if (shownWorking.isNotEmpty) ...[
|
|
// Working agents sit side by side, as on desktop.
|
|
for (final (i, pubkey) in shownWorking.indexed) ...[
|
|
if (i > 0) const SizedBox(width: Grid.xxs),
|
|
SmallAvatar(
|
|
pubkey: pubkey,
|
|
userCache: userCache,
|
|
agent: true,
|
|
),
|
|
],
|
|
if (hiddenWorking > 0) ...[
|
|
const SizedBox(width: Grid.xxs),
|
|
Text(
|
|
'+$hiddenWorking',
|
|
style: context.textTheme.labelMedium?.copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(width: Grid.xs),
|
|
const TypingDots(
|
|
key: ValueKey('thread-working-dots'),
|
|
dotSize: 5,
|
|
),
|
|
const SizedBox(width: Grid.half),
|
|
],
|
|
Flexible(
|
|
child: Text(
|
|
label,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: context.textTheme.labelMedium?.copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AvatarStack extends StatelessWidget {
|
|
const _AvatarStack(this.pubkeys, this.userCache);
|
|
final List<String> pubkeys;
|
|
final Map<String, UserProfile> userCache;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SizedBox(
|
|
width: Grid.gutter + (pubkeys.length - 1) * Grid.twelve,
|
|
height: Grid.gutter,
|
|
child: Stack(
|
|
children: [
|
|
for (var i = 0; i < pubkeys.length; i++)
|
|
PositionedDirectional(
|
|
start: i * Grid.twelve,
|
|
child: SmallAvatar(pubkey: pubkeys[i], userCache: userCache),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class _ReplyConnector extends CustomPainter {
|
|
const _ReplyConnector(this.color, this.direction, this.topOffset);
|
|
final Color color;
|
|
final TextDirection direction;
|
|
final double topOffset;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
canvas.save();
|
|
if (direction == TextDirection.rtl) {
|
|
canvas.translate(size.width, 0);
|
|
canvas.scale(-1, 1);
|
|
}
|
|
// Keep the endpoint aligned with the unchanged reply avatars.
|
|
final middle = (size.height - topOffset) / 2;
|
|
// Desktop uses a 12px outer corner with a 2px border: the stroke's
|
|
// centerline follows an 11px circular arc, rather than a tight elbow.
|
|
const radius = Grid.twelve - 1;
|
|
final path = Path()
|
|
..moveTo(1, 0)
|
|
..lineTo(1, middle - radius)
|
|
..arcToPoint(
|
|
Offset(Grid.twelve, middle),
|
|
radius: const Radius.circular(radius),
|
|
clockwise: false,
|
|
);
|
|
canvas.drawPath(
|
|
path,
|
|
Paint()
|
|
..color = color
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 2,
|
|
);
|
|
canvas.restore();
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(_ReplyConnector oldDelegate) =>
|
|
color != oldDelegate.color ||
|
|
direction != oldDelegate.direction ||
|
|
topOffset != oldDelegate.topOffset;
|
|
}
|