The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep a Bot Chat report expanded after a teammate answers this bot's dispatch
teknium1625070d5b78f
diff --git a/apps/desktop/src/components/assistant-ui/thread/agent-delivery.tsx b/apps/desktop/src/components/assistant-ui/thread/agent-delivery.tsxindex bbba05482cf..2d9d929d71b 100644--- a/apps/desktop/src/components/assistant-ui/thread/agent-delivery.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/agent-delivery.tsx@@ -19,6 +19,44 @@ export function deliveryTargetFromCommand(command: string): null | string {return match ? match[2].toLowerCase() : null}+/** `@Dr. Foo`, `scribe@laptop`, `peer/scribe` → `dr. foo` / `scribe`: the+ * routing alias a `message_agent` target and a "Message from" signature share. */+function agentKey(value: unknown): string {+ return typeof value === 'string' ? value.trim().replace(/^@/, '').replace(/@[^@]*$/, '').split('/').pop()!.toLowerCase() : ''+}++/**+ * Did THIS bot send a `message_agent` to `sender` in `earlier` (the thread up+ * to, not including, the inbound "Message from <sender>" row)? True means that+ * row is the teammate's answer to our dispatch — the round trip is complete and+ * the next assistant message addresses the human, not the teammate. Matching+ * the sender by handle OR display name (either may sign the inbound row) errs+ * towards "expanded": a missed fold shows content, a wrong fold hides it.+ */+export function dispatchedTo(earlier: readonly { content?: unknown; role?: string }[], sender: (string | undefined)[]): boolean {+ const keys = new Set(sender.map(agentKey).filter(Boolean))++ if (!keys.size) {+ return false+ }++ for (let i = earlier.length - 1; i >= 0; i--) {+ const row = earlier[i]++ if (row.role !== 'assistant' || !Array.isArray(row.content)) {+ continue+ }++ for (const part of row.content as { args?: { target?: unknown }; toolName?: string; type?: string }[]) {+ if (part?.type === 'tool-call' && part.toolName === 'message_agent' && keys.has(agentKey(part.args?.target))) {+ return true+ }+ }+ }++ return false+}+/** Extract the recipient's reply text from the terminal result payload. */export function replyTextFromResult(result: unknown): string {const container = (result ?? {}) as { content?: unknown; output?: unknown }diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsxindex b9d695ecc3b..b84405ce012 100644--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx@@ -13,6 +13,7 @@ import { useInRouterContext, useNavigate } from 'react-router'import { useSessionView } from '@/app/chat/session-view'import { SETTINGS_ROUTE } from '@/app/routes'+import { dispatchedTo } from '@/components/assistant-ui/thread/agent-delivery'import { ChangedFilesCard } from '@/components/assistant-ui/thread/changed-files-card'import {contentHasVisibleText,@@ -96,7 +97,12 @@ export const AssistantMessage: FC<AssistantMessageProps> = props => {// <sender>", expandable), mirroring the sender-side notice the previous// user message already renders as. Grok-bots parity: the transcript shows// events; the texts are one click away. Detection: the immediately- // preceding user message matches AGENT_MESSAGE_RE.+ // preceding user message matches AGENT_MESSAGE_RE — UNLESS that delivery+ // answers a `message_agent` dispatch this bot itself sent to the sender+ // earlier in the thread. Seen from the dispatching bot, the inbound row is+ // the teammate's answer and the next assistant message is the report to+ // the human (#114629); folding it hid the substance of the turn behind a+ // "Replied to" row nothing was ever sent through.const interAgentSender = useAuiState(s => {const messages = s.thread.messages@@ -115,7 +121,13 @@ export const AssistantMessage: FC<AssistantMessageProps> = props => {if (prev.role === 'user') {const match = AGENT_MESSAGE_RE.exec(messageContentText(prev.content as never).trim())- return match ? (match[1] || match[3] || 'agent').trim() : null+ if (!match) {+ return null+ }++ const sender = (match[1] || match[3] || 'agent').trim()++ return dispatchedTo(messages.slice(0, j), [match[1], match[2], match[3]]) ? null : sender}}diff --git a/apps/desktop/src/components/assistant-ui/thread/inter-agent-collapse.test.tsx b/apps/desktop/src/components/assistant-ui/thread/inter-agent-collapse.test.tsxindex 803d1f3bd47..6034090e120 100644--- a/apps/desktop/src/components/assistant-ui/thread/inter-agent-collapse.test.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/inter-agent-collapse.test.tsx@@ -82,7 +82,58 @@ function Harness({ messages }: { messages: ThreadMessage[] }) {const DELIVERY = 'Message from 🤖 Hermes (@hermes): please check the build'+/** This bot's own `message_agent` dispatch to a teammate (a Bot Chat turn). */+function dispatch(id: string, target: string): ThreadMessage {+ return {+ id,+ role: 'assistant',+ content: [+ {+ type: 'tool-call',+ toolCallId: `${id}-call`,+ toolName: 'message_agent',+ args: { target, message: 'send me the list' },+ argsText: JSON.stringify({ target, message: 'send me the list' })+ }+ ],+ status: { type: 'complete', reason: 'stop' },+ createdAt,+ metadata: assistantMetadata+ } as ThreadMessage+}+describe('inter-agent collapse gate', () => {+ it('keeps the report after a relayed answer to this bot\u2019s own dispatch expanded', async () => {+ // Bot Mode round trip seen from the DISPATCHING bot: it messaged @hermes,+ // the answer came back as an inbound "Message from" row, and the next+ // assistant message is its report to the human — not a reply to hermes.+ render(+ <Harness+ messages={[+ user('u1', 'ask hermes for the list'),+ dispatch('a0', '@Hermes'),+ user('u2', DELIVERY),+ assistant('a1', 'here is the list hermes sent', false)+ ]}+ />+ )++ await screen.findByText('here is the list hermes sent')+ expect(screen.queryByText(/Replied to/)).toBeNull()+ expect(screen.queryByText('show reply')).toBeNull()+ })++ it('still collapses the reply to an unsolicited delivery (dispatch went to another teammate)', async () => {+ render(+ <Harness+ messages={[dispatch('a0', 'scribe'), user('u2', DELIVERY), assistant('a1', 'build is green', false)]}+ />+ )++ expect(await screen.findByText(/Replied to/)).toBeTruthy()+ expect(screen.getByText('show reply')).toBeTruthy()+ })+it('collapses a settled reply to an inter-agent delivery', async () => {render(<Harness messages={[user('u1', DELIVERY), assistant('a1', 'build is green', false)]} />)