Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): put a finished delegation's report in the card's disclosure

M3gA-Mind10b5e37391bb
diff --git a/app/src/features/conversations/aui/SubagentTaskCard.test.tsx b/app/src/features/conversations/aui/SubagentTaskCard.test.tsx
index cfe9fc7baa..517e88829a 100644
--- a/app/src/features/conversations/aui/SubagentTaskCard.test.tsx
+++ b/app/src/features/conversations/aui/SubagentTaskCard.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { type SubagentActivity, subagentCancelResolved } from '../../../store/chatRuntimeSlice';
@@ -87,11 +87,11 @@ describe('SubagentTaskCard', () => {
'data-status',
'failed'
);
- // Unlike a completed report, a failure's output is kept on the card.
+ // A failure's output stays visible on the card.
expect(screen.getByText('Validation failed.')).toBeInTheDocument();
});
- it('hides a completed report and ignores legacy worktree fields', () => {
+ it('keeps a completed report collapsed and ignores legacy worktree fields', () => {
const legacyActivity: SubagentActivity & {
worktreePath: string;
changedFiles: string[];
@@ -123,20 +123,64 @@ describe('SubagentTaskCard', () => {
'data-status',
'success'
);
- expect(screen.getByText('Delegated to Researcher')).toBeInTheDocument();
- expect(screen.queryByText('Research is complete.')).toBeNull();
- expect(
- screen.getByTestId('assistant-ui-subagent-call').querySelector('[data-slot="task-card-result"]')
- ).toBeNull();
- // The transcript stays one click away.
expect(screen.getByRole('button', { name: /Delegated to Researcher/i })).toHaveAttribute(
'aria-expanded',
'false'
);
+ expect(screen.queryByTestId('subagent-report')).toBeNull();
+ expect(screen.queryByText('Research is complete.')).toBeNull();
expect(screen.queryByTestId('worktree-actions')).toBeNull();
expect(screen.queryByText(/worker/)).toBeNull();
});
+ it('toggles the completed report open and closed, rendered as markdown', async () => {
+ render(
+ <SubagentTaskCard
+ type="tool-call"
+ toolName="task"
+ toolCallId="sub-report"
+ args={{} as never}
+ argsText="{}"
+ result={
+ {
+ status: 'complete',
+ activity: {
+ ...activity,
+ status: 'success',
+ output: '**Answer:** saved the flow.\n\n- trigger updated\n- step 2 shortened',
+ },
+ } as never
+ }
+ status={{ type: 'complete' }}
+ addResult={() => {}}
+ resume={() => {}}
+ respondToApproval={async () => {}}
+ />
+ );
+
+ const header = screen.getByRole('button', { name: /Delegated to Researcher/i });
+ fireEvent.click(header);
+ expect(header).toHaveAttribute('aria-expanded', 'true');
+
+ const report = await screen.findByTestId('subagent-report');
+ const strong = await within(report).findByText('Answer:');
+ expect(strong.tagName).toBe('STRONG');
+ expect(within(report).getAllByRole('listitem').map(li => li.textContent)).toEqual([
+ 'trigger updated',
+ 'step 2 shortened',
+ ]);
+ expect(report.textContent).not.toContain('**');
+
+ // The same button collapses it again.
+ fireEvent.click(header);
+ expect(header).toHaveAttribute('aria-expanded', 'false');
+ expect(screen.queryByTestId('subagent-report')).toBeNull();
+
+ fireEvent.click(header);
+ expect(header).toHaveAttribute('aria-expanded', 'true');
+ expect(await screen.findByTestId('subagent-report')).toBeInTheDocument();
+ });
+
it('renders the awaiting-user reply box and lets the answer through the composer path', async () => {
render(
<SubagentTaskCard
diff --git a/app/src/features/conversations/aui/SubagentTaskCard.tsx b/app/src/features/conversations/aui/SubagentTaskCard.tsx
index ce0f0ba9a9..e3136a74b5 100644
--- a/app/src/features/conversations/aui/SubagentTaskCard.tsx
+++ b/app/src/features/conversations/aui/SubagentTaskCard.tsx
@@ -19,12 +19,17 @@
* (`elements/task-card.tsx`) + `utils/task.ts` pieces instead, with those
* actions supplied explicitly.
*/
-import { type ToolCallMessagePartComponent, useAui } from '@assistant-ui/react';
+import {
+ TextMessagePartProvider,
+ type ToolCallMessagePartComponent,
+ useAui,
+} from '@assistant-ui/react';
import { useCallback, useState } from 'react';
import { TaskCard, type TaskCardState } from '../../../components/assistant-ui/elements/task-card';
import { TaskTranscript } from '../../../components/assistant-ui/elements/task-card.aui';
import { useDisclosure } from '../../../components/assistant-ui/lib/useDisclosure';
+import { MarkdownText } from '../../../components/assistant-ui/markdown-text';
import { formatElapsed } from '../../../components/assistant-ui/utils/task';
import { Button } from '../../../components/ui';
import { useT } from '../../../lib/i18n/I18nContext';
@@ -245,14 +250,22 @@ export const SubagentTaskCard: ToolCallMessagePartComponent = ({
</div>
) : undefined;
- // A finished delegation's report is not shown: the parent's own reply
- // presents the same result right after, so the card stays a header row
- // (its transcript is still one click away). A failure keeps its output,
- // which nothing else in the thread repeats.
+ // A failure's output stays on the card. A finished report goes inside the
+ // disclosure instead, rendered as markdown with the chat's own renderer:
+ // the parent's reply presents the same result, so the card stays a header
+ // row until the user expands it.
const resultNode =
resolved.output && state === 'failed' ? (
<p className="m-0 whitespace-pre-wrap">{resolved.output}</p>
) : undefined;
+ const report =
+ resolved.output && state === 'done' ? (
+ <div data-testid="subagent-report" className="text-sm">
+ <TextMessagePartProvider text={resolved.output} isRunning={false}>
+ <MarkdownText />
+ </TextMessagePartProvider>
+ </div>
+ ) : null;
// `messages` (the part's own nested transcript, built by `subagentMessages`)
// is preferred over recomputing it here — it is the SAME data, but reusing
@@ -284,6 +297,7 @@ export const SubagentTaskCard: ToolCallMessagePartComponent = ({
/>
</div>
) : undefined}
+ {report}
</TaskCard>
);
};