From e4917621e7787f8bfe668ae34d2aa9e4e9b6b18f Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Sun, 3 May 2026 12:52:05 -0700 Subject: [PATCH] =?UTF-8?q?feat(v2):=20close=204=20agent-dm=20UI=20gaps=20?= =?UTF-8?q?=E2=80=94=20read-only=20banner,=20system=20event=20card,=20A2A?= =?UTF-8?q?=20sub-section,=20fresh-room=20empty=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four small UX cuts to make agent-dm rooms feel intentional rather than half-built: 1. Read-only banner + composer-disable when the viewer can read an agent-dm pod via §3.7 (shares a pod with one of the bots) but isn't a formal member. Today the composer is enabled and `send` 401s silently — confusing. Banner explains: "Read-only — these two agents are talking. To engage, @-mention either in a shared team pod." 2. System event card for "🤝 X and Y started a DM". §3.8 already posts this announcement via commonly-bot, but the existing markdown `[view](/v2/pods/)` link rendered with `target=_blank` (every anchor in the message bubble does), so it'd pop a new tab for an internal route. New `.v2-syscard` row detects the announcement by content shape and renders a router-aware "Open conversation" button. 3. "Between agents · N" sub-section in the Private filter. Agent-dm rooms (bot↔bot, observer-only) used to fold under Private next to user↔agent rooms with only the AA icon as differentiator. Override chronological grouping when filter==='private': three buckets — Pinned, Direct messages, Between agents. Top-level tab would overstate it (humans don't own A2A rooms); sub-section catches the eye and the count badge ticks up live during the demo. 4. Empty-state copy for fresh agent-dm rooms. Generic "Talk to your team" replaced for bot↔bot rooms with "{Bot A} and {Bot B} haven't talked yet — they'll DM each other when one of them needs the other's help." Mixed/one-bot agent-dm gets a softer "No messages yet — say hello to get started." All four gaps verified against frontend `tsc --noEmit` clean. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/v2/components/V2MessageBubble.tsx | 51 ++++++++ frontend/src/v2/components/V2PodChat.tsx | 59 ++++++++- frontend/src/v2/components/V2PodsSidebar.tsx | 27 +++- frontend/src/v2/v2.css | 115 ++++++++++++++++++ 4 files changed, 249 insertions(+), 3 deletions(-) diff --git a/frontend/src/v2/components/V2MessageBubble.tsx b/frontend/src/v2/components/V2MessageBubble.tsx index b095c47d6f..ed663b214f 100644 --- a/frontend/src/v2/components/V2MessageBubble.tsx +++ b/frontend/src/v2/components/V2MessageBubble.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useNavigate } from 'react-router-dom'; import ReactMarkdown from 'react-markdown'; import V2Avatar from './V2Avatar'; import { V2Message } from '../hooks/useV2PodDetail'; @@ -224,8 +225,24 @@ const FilePill: React.FC<{ file: ParsedFile }> = ({ file }) => { ); }; +// Match the §3.8 agent-dm-created announcement posted by commonly-bot: +// "🤝 Pixel and codex started a DM — [view](/v2/pods/)" +// The full message body is the line above; capture the headline text and the +// target pod id so we can render a card with a router-aware navigation +// button instead of the raw markdown link (which would `target="_blank"` and +// pop a new tab — wrong for in-app navigation). +const AGENT_DM_EVENT_RE = /^🤝\s+(.+?)\s+—\s+\[view\]\(\/v2\/pods\/([a-f0-9]{24})\)\s*$/i; + +const parseAgentDmEvent = (content: string | undefined): { headline: string; targetPodId: string } | null => { + if (!content) return null; + const match = content.trim().match(AGENT_DM_EVENT_RE); + if (!match) return null; + return { headline: match[1], targetPodId: match[2] }; +}; + const V2MessageBubble: React.FC = ({ message, isLead, agentDisplayNames, agentAuthorKeys, onAuthorClick }) => { const { currentUser } = useAuth(); + const navigate = useNavigate(); const rawUsername = message.user?.username || 'Unknown'; const overriddenDisplay = agentDisplayNames?.get(rawUsername); const author = overriddenDisplay || rawUsername; @@ -234,6 +251,40 @@ const V2MessageBubble: React.FC = ({ message, isLead, agen const isClickable = !!onAuthorClick && !!agentAuthorKeys?.has(rawUsername.toLowerCase()); const handleAuthorClick = isClickable ? () => onAuthorClick?.(rawUsername) : undefined; const time = formatRelativeTime(message.created_at); + + // §3.8 system event card. Detected by content shape (commonly-bot only + // posts this exact form), so we don't depend on a metadata column the PG + // messages table doesn't have. Render a chrome-light card with a + // router-aware "Open conversation" button — never a new tab. + const dmEvent = parseAgentDmEvent(message.content); + if (dmEvent) { + return ( +
+
+ +
+
{dmEvent.headline}
+ {time &&
{time}
} +
+ +
+
+ ); + } + // Two-pass parse: reactions first (they live anywhere in the body), then // files. Order matters — files leave a trimmed body that we then read for // image rendering. diff --git a/frontend/src/v2/components/V2PodChat.tsx b/frontend/src/v2/components/V2PodChat.tsx index dabf597391..008b9a190b 100644 --- a/frontend/src/v2/components/V2PodChat.tsx +++ b/frontend/src/v2/components/V2PodChat.tsx @@ -9,6 +9,7 @@ import { import { useV2Api } from '../hooks/useV2Api'; import { UseV2PodsResult, V2PodMember } from '../hooks/useV2Pods'; import { useSocket } from '../../context/SocketContext'; +import { useAuth } from '../../context/AuthContext'; import { initialsFor } from '../utils/avatars'; const PLAN_MODE_KEY = 'v2.podMode'; @@ -135,6 +136,7 @@ const V2PodChat: React.FC = ({ detail, inspectorCollapsed, onTog const navigate = useNavigate(); const api = useV2Api(); const { socket, connected } = useSocket(); + const { currentUser } = useAuth(); const [draft, setDraft] = useState(''); const [sending, setSending] = useState(false); const [uploading, setUploading] = useState(false); @@ -443,6 +445,26 @@ const V2PodChat: React.FC = ({ detail, inspectorCollapsed, onTog ); } + // §3.7 read-access: humans can VIEW agent-dm rooms when they share a pod + // with one of the bots, but they cannot post unless they're a formal member + // (which they never are for bot↔bot rooms). Detect that case so we can + // swap the composer for an explanatory banner instead of letting the user + // type and silently 401. + const currentUserId = currentUser?._id || null; + const isPodMember = !!currentUserId && (members || []).some( + (m) => m && m._id === currentUserId, + ); + const isAgentDm = pod.type === 'agent-dm'; + const isReadOnly = isAgentDm && !isPodMember; + + // Bot-bot agent-dm — used to choose the "X and Y haven't talked yet" empty + // state and to phrase the read-only banner appropriately. + const botMembers = (members || []).filter((m) => m?.isBot); + const isBotToBot = isAgentDm && botMembers.length >= 2 && botMembers.length === (members || []).length; + const botPair = isBotToBot + ? botMembers.slice(0, 2).map((m) => m.username || 'Agent') + : null; + const handleSend = async () => { if (!draft.trim() || sending) return; setSending(true); @@ -600,8 +622,22 @@ const V2PodChat: React.FC = ({ detail, inspectorCollapsed, onTog )} {!loading && messages.length === 0 && (
-
Talk to your team
-
Type a message, or @-mention an agent to direct your first task.
+ {isBotToBot && botPair ? ( + <> +
{botPair[0]} and {botPair[1]} haven't talked yet
+
They'll DM each other when one of them needs the other's help.
+ + ) : isAgentDm ? ( + <> +
No messages yet
+
This is a private 1:1 conversation. Say hello to get started.
+ + ) : ( + <> +
Talk to your team
+
Type a message, or @-mention an agent to direct your first task.
+ + )}
)} {messages.map((m) => ( @@ -618,6 +654,24 @@ const V2PodChat: React.FC = ({ detail, inspectorCollapsed, onTog + {isReadOnly ? ( +
+ +
+
Read-only — you're observing this conversation
+
+ {isBotToBot && botPair + ? `${botPair[0]} and ${botPair[1]} are talking directly. To engage them, @-mention either in a shared team pod.` + : 'You can read this 1:1 but not post. To engage, @-mention the agent in a shared team pod.'} +
+
+
+ ) : (