Skip to content

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

feat(conversations): render turn task cards inside assistant messages

Steven Enamakele2673c58dbdb
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
index 9303f6ffeb..2f2f27e95a 100644
--- a/app/src/components/assistant-ui/thread.tsx
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -96,6 +96,7 @@ export type ThreadGroupPart = MessagePrimitive.GroupedParts.GroupPart;
* `ToolFallback`.
*/
export type ThreadComponents = {
+ MessageTasks?: ComponentType | undefined;
AssistantMessage?: ComponentType | undefined;
Welcome?: ComponentType | undefined;
ToolFallback?: ToolCallMessagePartComponent | undefined;
@@ -1124,6 +1125,7 @@ const AssistantMessage: FC = () => {
ToolFallback: ToolFallbackComponent = ToolFallback,
ActivityGroup = DefaultActivityGroup,
SourceGroup,
+ MessageTasks,
} = useContext(ThreadComponentsContext);
const stopped = useAuiState(isStoppedRun);
@@ -1170,6 +1172,7 @@ const AssistantMessage: FC = () => {
<div
data-slot="aui_assistant-message-content"
className="text-foreground px-2 leading-relaxed wrap-break-word">
+ {MessageTasks && <MessageTasks />}
<MessagePrimitive.GroupedParts
groupBy={groupPartByType({
reasoning: ['group-activity'],
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsx
index ea4699ee74..c4bceb0b47 100644
--- a/app/src/features/conversations/Conversations.tsx
+++ b/app/src/features/conversations/Conversations.tsx
@@ -5,25 +5,19 @@ import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { type ChatSendError, chatSendError } from '../../chat/chatSendError';
import { checkPromptInjection, promptGuardMessage } from '../../chat/promptInjectionGuard';
import { trackAnalyticsEvent } from '../../components/analytics';
-import { AgentStatus } from '../../components/assistant-ui/elements/agent-status';
import ChatFilesChip from '../../components/chat/ChatFilesChip';
import WorkflowProposalCard from '../../components/chat/WorkflowProposalCard';
import { ConfirmationModal } from '../../components/intelligence/ConfirmationModal';
import { SidebarContent } from '../../components/layout/shell/SidebarSlot';
import { ArtifactCardAdapter } from '../../features/conversations/aui/ArtifactCardAdapter';
import { ContextUsage } from '../../features/conversations/aui/ContextUsage';
-import { PinnedTodoCard } from '../../features/conversations/aui/PinnedTodoCard';
import { PlanReviewCardCore } from '../../features/conversations/aui/PlanReviewPart';
-import { toAuiTodoItems } from '../../features/conversations/aui/TodoListPart';
import { useRunMode } from '../../features/conversations/aui/useRunMode';
import {
- formatTokens,
useLoadThreadGoal,
- useThreadGoal,
} from '../../features/conversations/aui/useThreadGoal';
import {
useLoadThreadTodos,
- useThreadTodos,
} from '../../features/conversations/aui/useThreadTodos';
import { AssistantUiChat } from '../../features/conversations/components/AssistantUiChat';
import { TranscriptOverlays } from '../../features/conversations/components/aui/TranscriptOverlays';
@@ -1782,8 +1776,6 @@ const Conversations = ({
// shows as a checklist ticking off while the agent works through it.
useLoadThreadTodos(selectedThreadId ?? null);
useLoadThreadGoal(selectedThreadId ?? null);
- const liveTodos = useThreadTodos(selectedThreadId ?? null);
- const threadGoal = useThreadGoal(selectedThreadId ?? null);
// A plan the orchestrator parked for interactive review (request_plan_review
// gate). When present, the PlanReviewCard renders above the composer and
// resolves the parked turn.
@@ -1943,40 +1935,6 @@ const Conversations = ({
// doubles up.
const agentGateCards = (
<>
- {/* Harness work state: the thread goal (as a compact `AgentStatus`
- pill) and the agent's live todo list. Both are read-only progress
- the agent wrote via its tools; they sit above the gate cards so a
- parked decision is always the closest thing to the composer. */}
- {selectedThreadId && threadGoal && (
- <AgentStatus
- data-testid="goal-banner"
- data-goal-status={threadGoal.status}
- state={
- threadGoal.status === 'complete'
- ? 'done'
- : threadGoal.status === 'active'
- ? 'working'
- : 'waiting'
- }
- label={threadGoal.objective}
- trailing={
- <span data-testid="goal-objective" className="text-[10px] tabular-nums">
- {threadGoal.token_budget !== undefined
- ? `${formatTokens(threadGoal.tokens_used)} / ${formatTokens(threadGoal.token_budget)}`
- : formatTokens(threadGoal.tokens_used)}
- </span>
- }
- className="mb-2 w-full [&_[data-slot=agent-status-label]]:max-w-none [&_[data-slot=agent-status-label]]:flex-1"
- />
- )}
- {selectedThreadId && liveTodos && liveTodos.length > 0 && (
- <PinnedTodoCard
- threadId={selectedThreadId}
- items={toAuiTodoItems(liveTodos)}
- className="mb-2"
- />
- )}
-
{/* Plan-mode review: the orchestrator parked the live turn on a
thread-scoped plan (request_plan_review gate). Surface it for the
user to Approve / Reject / send feedback on before anything
diff --git a/app/src/features/conversations/aui/TurnTaskCards.tsx b/app/src/features/conversations/aui/TurnTaskCards.tsx
new file mode 100644
index 0000000000..4c68e80f1d
--- /dev/null
+++ b/app/src/features/conversations/aui/TurnTaskCards.tsx
@@ -0,0 +1,70 @@
+import { useAuiState } from '@assistant-ui/react';
+import { createContext, useContext, useEffect, useState, type PropsWithChildren } from 'react';
+import { TaskCard } from '../../../components/assistant-ui/elements/task-card';
+import { TodoItems } from '../../../components/assistant-ui/elements/todo-list';
+import { useDisclosure } from '../../../components/assistant-ui/lib/useDisclosure';
+import { useT } from '../../../lib/i18n/I18nContext';
+import { useAuiThreadId } from '../../../providers/AssistantUiRuntimeProvider';
+import { userScopedStorage } from '../../../store/userScopedStorage';
+import { toAuiTodoItems } from './TodoListPart';
+import { useThreadTodos } from './useThreadTodos';
+import { useThreadGoal } from './useThreadGoal';
+import { taskFinished, updateTaskHistory, type TurnTask } from './taskCardHistory';
+
+const Tasks = createContext<TurnTask[]>([]);
+
+/** Presentation snapshots belong to turns, rather than the moving composer. */
+export function TurnTaskProvider({ children }: PropsWithChildren) {
+ const threadId = useAuiThreadId();
+ const todos = useThreadTodos(threadId);
+ const goal = useThreadGoal(threadId);
+ const anchor = useAuiState(s => s.thread.messages.filter(message => message.role === 'user').at(-1)?.id ?? s.thread.messages[0]?.id ?? '');
+ const [saved, setSaved] = useState<{ threadId: string | null; ready: boolean; cards: TurnTask[] }>({threadId: null, ready: false, cards: []});
+ useEffect(() => {
+ let cancelled = false;
+ setSaved({threadId, ready: false, cards: []});
+ if (!threadId) return;
+ void userScopedStorage.getItem(`chat-task-cards:${threadId}`).then(value => {
+ if (cancelled) return;
+ let cards: TurnTask[] = [];
+ try { const parsed: unknown = JSON.parse(value ?? '[]'); if (Array.isArray(parsed)) cards = parsed.filter(item => typeof item?.anchor === 'string' && Array.isArray(item?.todos)); } catch { /* Older or unavailable presentation cache. */ }
+ setSaved({threadId, ready: true, cards});
+ });
+ return () => { cancelled = true; };
+ }, [threadId]);
+ useEffect(() => {
+ if (!saved.ready || saved.threadId !== threadId || !threadId) return;
+ const cards = updateTaskHistory(saved.cards, {anchor, todos: todos ?? [], goal});
+ if (cards === saved.cards) return;
+ setSaved({...saved, cards});
+ void userScopedStorage.setItem(`chat-task-cards:${threadId}`, JSON.stringify(cards));
+ }, [anchor, todos, goal, saved, threadId]);
+ return <Tasks.Provider value={saved.threadId === threadId ? saved.cards : []}>{children}</Tasks.Provider>;
+}
+
+function TurnTaskCard({ task }: { task: TurnTask }) {
+ const { t } = useT();
+ const threadId = useAuiThreadId();
+ const done = taskFinished(task);
+ const [open, setOpen] = useDisclosure(`task:${threadId}:${task.anchor}`, !done);
+ const state = done ? 'done' : task.goal && task.goal.status !== 'active' ? 'waiting' : 'working';
+ return <TaskCard data-testid="todo-checklist" label={task.goal?.objective ?? t('conversations.runMode.plan')} state={state} open={open} onOpenChange={setOpen} className="max-w-none">
+ <TodoItems items={toAuiTodoItems(task.todos)} compact />
+ </TaskCard>;
+}
+
+/** Mount only on the first assistant response to the anchored user message. */
+export function TurnTaskCards() {
+ const cards = useContext(Tasks);
+ const anchor = useAuiState(s => {
+ const index = s.thread.messages.findIndex(message => message.id === s.message.id);
+ let user = '';
+ for (let i = 0; i < index; i++) {
+ const message = s.thread.messages[i];
+ if (message?.role === 'user') user = message.id;
+ else if (message?.role === 'assistant') user = '';
+ }
+ return user || (index === 0 ? s.message.id : '');
+ });
+ return <>{cards.filter(task => task.anchor === anchor).map(task => <TurnTaskCard key={task.anchor} task={task} />)}</>;
+}
diff --git a/app/src/features/conversations/components/AssistantUiChat.tsx b/app/src/features/conversations/components/AssistantUiChat.tsx
index 6015c689a8..19cf443cd7 100644
--- a/app/src/features/conversations/components/AssistantUiChat.tsx
+++ b/app/src/features/conversations/components/AssistantUiChat.tsx
@@ -1,3 +1,4 @@
+import { TurnTaskProvider, TurnTaskCards } from '../aui/TurnTaskCards';
import { ConversationMapAui } from '@/components/assistant-ui/elements/conversation-map.aui';
import { Thread, type ThreadComponents } from '@/components/assistant-ui/thread';
import { type AssistantState, useAui, useAuiState } from '@assistant-ui/react';
@@ -311,6 +312,7 @@ export function AssistantUiChat({
const components: ThreadComponents = useMemo(
() => ({
ToolFallback: ChatToolFallback,
+ MessageTasks: TurnTaskCards,
// `/` commands (builtins + core `commands_list` + registry actions) and
// `@` mentions (memory recall, thread files); see `aui/ComposerTriggers`.
ComposerTriggers,
@@ -370,6 +372,7 @@ export function AssistantUiChat({
return (
<AssistantUiRuntimeProvider>
<ComposerTextBridge value={inputValue} onChange={onInputValueChange} />
+ <TurnTaskProvider>
<ChatConversationMap>
<Thread
components={components}
@@ -381,6 +384,7 @@ export function AssistantUiChat({
composerPlaceholder={composerPlaceholder}
/>
</ChatConversationMap>
+ </TurnTaskProvider>
</AssistantUiRuntimeProvider>
);
}