Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(chat): toolbar and steer-work labels align with rendered assistant content (#4958)

Harsh Kumarc08033aaebdc
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
index e98212851..08c8ca3f5 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
@@ -16,8 +16,11 @@ import {
} from "@/components/chat/standalone/message-content";
import {
buildCollapsedSteerRenderItems,
+ hasAssistantTextBody,
getMessageIntentLabel,
+ isNormalUserMessage,
isSteeredAssistantMessage,
+ hasRenderableAssistantBody,
} from "@/lib/chat/message-rendering";
import { cn } from "@/lib/utils";
import type { ContentBlock, Message } from "@/lib/chat/types";
@@ -106,8 +109,7 @@ export function ChatMessageList({
{(() => {
const visibleMessages = messages.filter((m) => {
if (m.role !== "assistant") return true;
- if (m.content === "Processing..." && !m.contentBlocks?.length && !m.stoppedByUser) return false;
- if (!m.content && !m.contentBlocks?.length && !isSteeredAssistantMessage(m) && !m.stoppedByUser) return false;
+ if (!hasRenderableAssistantBody(m) && !isSteeredAssistantMessage(m)) return false;
return true;
});
@@ -131,6 +133,26 @@ export function ChatMessageList({
activeSourceFooterMessageId ??
(lastVisibleAssistantId === lastAssistantId ? lastVisibleAssistantId : undefined);
+ // Find parent assistant IDs whose steered child is currently streaming.
+ // Walk backwards from the active streaming assistant to find the
+ // preceding non-steered assistant in the same turn — that's the parent
+ // whose ToolCallGroup should also show "Working".
+ const steerChildActiveParentIds = new Set<string>();
+ if ((isLoading || isStreaming) && activeAssistantMessageId) {
+ const activeIdx = visibleMessages.findIndex((m) => m.id === activeAssistantMessageId);
+ const activeMsg = activeIdx >= 0 ? visibleMessages[activeIdx] : undefined;
+ if (activeMsg && isSteeredAssistantMessage(activeMsg)) {
+ for (let j = activeIdx - 1; j >= 0; j -= 1) {
+ const prev = visibleMessages[j];
+ if (prev.role === "user" && prev.intent !== "steer") break;
+ if (prev.role === "assistant" && !isSteeredAssistantMessage(prev)) {
+ steerChildActiveParentIds.add(prev.id);
+ break;
+ }
+ }
+ }
+ }
+
return renderItems.map((item) => {
if (item.type === "collapsed-steer-work") {
const expanded = expandedSteerWorkIds.has(item.id);
@@ -156,12 +178,14 @@ export function ChatMessageList({
const canEditMessage = message.role === "user" && !isSteerUserMessage && !isLoading;
const canShowMessageActions = !item.showActionsWhenExpandedBy ||
expandedSteerWorkIds.has(item.showActionsWhenExpandedBy);
+ const hasActiveSteerChild = steerChildActiveParentIds.has(message.id);
const isActiveStreamingAssistantMessage =
message.role === "assistant" &&
(isLoading || isStreaming) &&
- message.id === activeAssistantMessageId;
+ (message.id === activeAssistantMessageId || hasActiveSteerChild);
+ const shouldShowAssistantActions = message.role !== "assistant" || hasAssistantTextBody(message);
const shouldShowMessageActionBar =
- canShowMessageActions && !isActiveStreamingAssistantMessage;
+ canShowMessageActions && !isActiveStreamingAssistantMessage && shouldShowAssistantActions;
const nextAssistant = visibleMessages
.slice(messageIndex + 1)
.find((candidate) => candidate.role === "assistant");
@@ -171,6 +195,23 @@ export function ChatMessageList({
!message.content &&
!message.contentBlocks?.length
);
+ // Hide retry/branch on any assistant that has a steered assistant
+ // after it *within the same turn segment*. A normal (non-steer) user
+ // message starts a new segment, so stop searching there.
+ let nextSameSegmentAssistant: Message | undefined;
+ if (message.role === "assistant") {
+ const tail = visibleMessages.slice(messageIndex + 1);
+ for (const candidate of tail) {
+ if (isNormalUserMessage(candidate)) break; // new turn
+ if (candidate.role === "assistant") {
+ nextSameSegmentAssistant = candidate;
+ break;
+ }
+ }
+ }
+ const hasFollowingSteeredAssistant = Boolean(
+ nextSameSegmentAssistant && isSteeredAssistantMessage(nextSameSegmentAssistant)
+ );
const turnAggregatedCitations = citationPlan.aggregatedAfter.get(message.id);
return [
@@ -298,6 +339,12 @@ export function ChatMessageList({
citationPlan.deferredMessageIds.has(message.id) ||
message.id === activeSourceFooterMessageId
}
+ hideToolSummary={item.hideToolSummary || isSteeredAssistantMessage(message)}
+ forceCollapseTools={
+ item.collapseToolsWithSteerWork
+ ? !expandedSteerWorkIds.has(item.collapseToolsWithSteerWork)
+ : false
+ }
onImageClick={onOpenImageViewer}
onRetry={(prompt) => sendMessage(prompt)}
onOpenViewerPath={openFilePreview}
@@ -344,7 +391,7 @@ export function ChatMessageList({
<Pencil className="h-3 w-3" />
</button>
)}
- {message.role === "assistant" && !isLoading && (
+ {message.role === "assistant" && !isLoading && !hasFollowingSteeredAssistant && (
<button
onClick={() => onRetryAssistantMessage(message.id)}
className="p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground"
@@ -353,7 +400,7 @@ export function ChatMessageList({
<RefreshCw className="h-3 w-3" />
</button>
)}
- {message.role === "assistant" && (
+ {message.role === "assistant" && !hasFollowingSteeredAssistant && (
<Popover
open={openMessageMenuId === message.id}
onOpenChange={(open) => onMessageMenuOpenChange(message.id, open)}
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/collapsed-steer-work-row.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/collapsed-steer-work-row.tsx
index a50eaa3d4..51aeda782 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/collapsed-steer-work-row.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/collapsed-steer-work-row.tsx
@@ -7,6 +7,7 @@ import { ChevronDown, ChevronRight } from "lucide-react";
import { motion } from "framer-motion";
import {
collapsedSteerWorkDuration,
+ collapsedSteerFailedCount,
type ChatRenderItem,
} from "@/lib/chat/message-rendering";
@@ -22,6 +23,7 @@ export function CollapsedSteerWorkRow({
onToggle,
}: CollapsedSteerWorkRowProps) {
const label = collapsedSteerWorkDuration(item);
+ const failedCount = collapsedSteerFailedCount(item);
return (
<motion.div
@@ -39,7 +41,12 @@ export function CollapsedSteerWorkRow({
onClick={onToggle}
className="inline-flex items-center gap-1 py-0.5 text-left text-muted-foreground/70 hover:text-muted-foreground transition-colors"
>
- <span className="text-xs leading-none">{label}</span>
+ <span className="text-xs leading-none">
+ {label}
+ {failedCount > 0 && (
+ <span className="ml-1.5 text-muted-foreground/50">· {failedCount} failed</span>
+ )}
+ </span>
{expanded ? <ChevronDown className="h-3 w-3" /> : <ChevronRight className="h-3 w-3" />}
</button>
<div className="mt-0.5 w-full border-t border-border/20" />
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-steering-transport.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-steering-transport.ts
index 1a8d690a6..99b61f72b 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-steering-transport.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-steering-transport.ts
@@ -460,7 +460,12 @@ export function usePiSteeringTransport(
combinedImages.length > 0 ? combinedImages : null,
)
.then((result) => {
- if (result.status !== "ok") {
+ if (result.status === "ok") {
+ // Clear the flag — this stop was an internal steering redirect,
+ // not a user-initiated stop. Without this the steered response
+ // inherits stoppedByUser=true when it completes.
+ piActiveStopRequestedRef.current = false;
+ } else {
console.warn("[steer] piSteer returned non-ok:", result);
revertFailedComposerSteer(
batch,
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
index 126f3abc5..0ec42a607 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
@@ -16,7 +16,7 @@ import { cn } from "@/lib/utils";
import type { Message, ToolCall, ContentBlock } from "@/lib/chat/types";
import type { ConnectionListItem } from "@/lib/chat/connection-suggestions";
import type { InlineConnectStatus } from "@/lib/connections/inline-connect";
-import { formatDurationParts, formatStoppedWorkDuration, formatWorkDuration } from "@/lib/chat/message-rendering";
+import { formatDurationParts, formatStoppedWorkDuration, formatWorkDuration, hasAssistantToolWorkBody } from "@/lib/chat/message-rendering";
import {
classifyCurl,
endpointFamily,
@@ -1082,17 +1082,6 @@ function WorkSummaryText({
);
}
-function WorkStatusHeader({ label }: { label: string }) {
- return (
- <div className="w-full min-w-0">
- <div className="py-1 text-xs font-mono text-foreground/50">
- {label}
- </div>
- <div className="w-full min-w-full border-t border-border/50" />
- </div>
- );
-}
-
function ToolCallGroup({
toolCalls,
defaultExpanded = false,
@@ -1100,6 +1089,8 @@ function ToolCallGroup({
preferSummaryOverride = false,
summaryOverride,
workStartedAtMs,
+ hideSummary = false,
+ forceCollapsed = false,
}: {
toolCalls: ToolCall[];
defaultExpanded?: boolean;
@@ -1107,6 +1098,8 @@ function ToolCallGroup({
preferSummaryOverride?: boolean;
summaryOverride?: string;
workStartedAtMs?: number;
+ hideSummary?: boolean;
+ forceCollapsed?: boolean;
}) {
const [manualExpand, setManualExpand] = useState<boolean | null>(null);
const [runningSummary, setRunningSummary] = useState("Working");
@@ -1161,40 +1154,46 @@ function ToolCallGroup({
// When done → auto-collapse (user can re-expand). `defaultExpanded`
// keeps it open even when done for messages whose entire output is
// tool calls (typical pipe-runs without a final prose response).
- const isExpanded = isWorking
- ? true
- : manualExpand !== null ? manualExpand : defaultExpanded;
+ const isExpanded = forceCollapsed
+ ? false
+ : hideSummary
+ ? true
+ : isWorking
+ ? true
+ : manualExpand !== null ? manualExpand : defaultExpanded;
return (
<div className="w-full min-w-0 self-stretch">
- <div className="mb-2 w-full min-w-full">
- {/* Header — plain text while working, clickable with chevron when done */}
- {isWorking ? (
- <div className="w-full flex items-center gap-1.5 py-1 text-left min-w-0">
- <span className="truncate text-xs font-mono text-foreground/50">
- <WorkSummaryText text={runningSummary} animateRunningDuration />
- </span>
- </div>
- ) : (
- <button
- onClick={() => setManualExpand(isExpanded ? false : true)}
- className="w-full flex items-center gap-1.5 py-1 text-left min-w-0 group cursor-pointer"
- >
- <span className="truncate text-xs font-mono text-foreground/50 group-hover:text-foreground/80 transition-colors duration-150">
- <WorkSummaryText text={summary || `${total} steps`} animateRunningDuration={false} />
- {hasError && (
- <span className="ml-1.5 text-foreground/30">· {toolCalls.filter(tc => tc.isError).length} failed</span>
+ {!hideSummary && (
+ <div className="mb-2 w-full min-w-full">
+ {/* Header — plain text while working, clickable with chevron when done */}
+ {isWorking ? (
+ <div className="w-full flex items-center gap-1.5 py-1 text-left min-w-0">
+ <span className="truncate text-xs font-mono text-foreground/50">
+ <WorkSummaryText text={runningSummary} animateRunningDuration />
+ </span>
+ </div>
+ ) : (
+ <button
+ onClick={() => setManualExpand(isExpanded ? false : true)}
+ className="w-full flex items-center gap-1.5 py-1 text-left min-w-0 group cursor-pointer"
+ >
+ <span className="truncate text-xs font-mono text-foreground/50 group-hover:text-foreground/80 transition-colors duration-150">
+ <WorkSummaryText text={summary || `${total} steps`} animateRunningDuration={false} />
+ {hasError && (
+ <span className="ml-1.5 text-foreground/30">· {toolCalls.filter(tc => tc.isError).length} failed</span>
+ )}
+ </span>
+ {isExpanded ? (
+ <ChevronDown className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
+ ) : (
+ <ChevronRight className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
)}
- </span>
- {isExpanded ? (
- <ChevronDown className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
- ) : (
- <ChevronRight className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
- )}
- </button>
- )}
- <div className="w-full min-w-full border-t border-border/50" />
- </div>
+ </button>
+ )}
+ <div className="w-full min-w-full border-t border-border/50" />
+ </div>
+ )}
{/* Expanded rail view */}
<AnimatePresence>
@@ -1233,6 +1232,8 @@ export function MessageContent({
message,
isGenerating = false,
deferSourceFooter = false,
+ hideToolSummary = false,
+ forceCollapseTools = false,
connectionItems = [],
onImageClick,
onRetry,
@@ -1245,6 +1246,8 @@ export function MessageContent({
message: Message;
isGenerating?: boolean;
deferSourceFooter?: boolean;
+ hideToolSummary?: boolean;
+ forceCollapseTools?: boolean;
connectionItems?: ConnectionListItem[];
onImageClick?: (images: string[], index: number) => void;
onRetry?: (prompt: string) => void;
@@ -1384,35 +1387,20 @@ export function MessageContent({
const collapsed = collapseHiddenWorkGroups(grouped);
const displayGroups = mergeWorkAndIntermediateText(collapsed);
- // If all blocks were absorbed (e.g. thinking-only message with no tool
- // calls), show a "Thought for Xs" header so the bubble isn't blank.
- // Skip while still generating — the loader handles that state.
- if (displayGroups.length === 0 && !isGenerating) {
- const thinkingMs = grouped
- .filter((g): g is Extract<GroupedBlock, { type: "thinking" }> => g.type === "thinking")
- .reduce((sum, g) => sum + (g.durationMs ?? 0), 0);
- const fallbackLabel = thinkingMs > 0
- ? formatWorkDuration(thinkingMs)
- : message.workDurationMs
- ? formatWorkDuration(message.workDurationMs)
- : "thought";
- return (
- <div className="space-y-2 min-w-0 w-full overflow-hidden">
- <WorkStatusHeader label={fallbackLabel} />
- {sourceFooter}
- {retryCta}
- </div>
- );
+ // If all blocks were absorbed (for example, thinking-only output with no
+ // visible text or tool work), render nothing. The loader covers the active
+ // case and an empty stopped turn should not invent a finished state.
+ if (displayGroups.length === 0 && !isGenerating && !sourceFooter && !retryCta) {
+ return null;
}
- const hasText = grouped.some((g) => g.type === "text");
- const stoppedSummary = message.stoppedByUser
+ const hasFinalText = displayGroups.some((g) => g.type === "text");
+ const hasToolWorkGroup = hasAssistantToolWorkBody(message);
+ const stoppedSummary = message.stoppedByUser && hasToolWorkGroup
? formatStoppedWorkDuration(message.workDurationMs)
: undefined;
- const hasWorkStatusGroup = displayGroups.some((g) => g.type === "tool-group" || g.type === "work-group");
return (
<div className="space-y-2 min-w-0 w-full overflow-hidden">
- {stoppedSummary && !hasWorkStatusGroup ? <WorkStatusHeader label={stoppedSummary} /> : null}
{displayGroups.map((group) => {
if (group.type === "text") {
return (
@@ -1462,11 +1450,13 @@ export function MessageContent({
<ToolCallGroup
key={`tools-${group.key}`}
toolCalls={group.toolCalls}
- defaultExpanded={!hasText}
+ defaultExpanded={!hasFinalText}
isGenerating={isGenerating && !message.workDurationMs}
preferSummaryOverride={Boolean(stoppedSummary)}
summaryOverride={stoppedSummary || (message.workDurationMs ? formatWorkDuration(message.workDurationMs) : undefined)}
workStartedAtMs={message.timestamp}
+ hideSummary={hideToolSummary}
+ forceCollapsed={forceCollapseTools}
/>
);
}
@@ -1480,11 +1470,13 @@ export function MessageContent({
<ToolCallGroup
key={`work-${group.key}`}
toolCalls={group.toolCalls}
- defaultExpanded={!hasText}
+ defaultExpanded={!hasFinalText}
isGenerating={isGenerating && !message.workDurationMs}
preferSummaryOverride={Boolean(stoppedSummary)}
summaryOverride={stoppedSummary || formatWorkDuration(durationMs)}
workStartedAtMs={message.timestamp}
+ hideSummary={hideToolSummary}
+ forceCollapsed={forceCollapseTools}
/>
);
}
@@ -1503,14 +1495,15 @@ export function MessageContent({
const displayText = !isUser && message.content.startsWith("Error: ")
? message.content.slice("Error: ".length)
: message.content;
- const stoppedSummary = !isUser && message.stoppedByUser
- ? formatStoppedWorkDuration(message.workDurationMs)
- : undefined;
+ const hasMeaningfulText = Boolean(displayText && displayText !== "Processing...");
+
+ if (!isUser && !hasMeaningfulText && !attachmentsRow && !sourceFooter && !retryCta) {
+ return null;
+ }
return (
<div className="space-y-2 min-w-0 w-full">
{attachmentsRow}
- {stoppedSummary ? <WorkStatusHeader label={stoppedSummary} /> : null}
{displayText ? (
<MarkdownBlock
text={displayText}
diff --git a/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts b/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
index 1c16338dd..728dc8c53 100644
--- a/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
+++ b/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
@@ -7,13 +7,17 @@ import type { Message } from "../types";
import {
buildCollapsedSteerRenderItems,
collapsedSteerWorkDuration,
+ collapsedSteerFailedCount,
formatDurationParts,
formatStoppedWorkDuration,
formatWorkDuration,
+ hasAssistantTextBody,
+ hasAssistantToolWorkBody,
getMessageIntentLabel,
hasRenderableAssistantBody,
isPlaceholderConversationTitle,
isSteeredAssistantMessage,
+ type ChatRenderItem,
} from "../message-rendering";
function message(overrides: Partial<Message> & Pick<Message, "id" | "role">): Message {
@@ -48,7 +52,7 @@ describe("message rendering helpers", () => {
it("treats assistant content blocks as renderable body", () => {
expect(hasRenderableAssistantBody(message({ id: "a1", role: "assistant", content: "Processing..." }))).toBe(false);
- expect(hasRenderableAssistantBody(message({ id: "a-stopped", role: "assistant", stoppedByUser: true }))).toBe(true);
+ expect(hasRenderableAssistantBody(message({ id: "a-stopped", role: "assistant", stoppedByUser: true }))).toBe(false);
expect(
hasRenderableAssistantBody(
message({
@@ -59,6 +63,134 @@ describe("message rendering helpers", () => {
})
)
).toBe(true);
+ expect(
+ hasRenderableAssistantBody(
+ message({
+ id: "a3",
+ role: "assistant",
+ content: "",
+ contentBlocks: [{ type: "thinking", text: "ponder", isThinking: false }],
+ })
+ )
+ ).toBe(false);
+ });
+
+ it("only treats assistant rows with final text as actionable", () => {
+ expect(
+ hasAssistantTextBody(
+ message({
+ id: "a1",
+ role: "assistant",
+ contentBlocks: [{ type: "text", text: "done" }],
+ })
+ )
+ ).toBe(true);
+ expect(
+ hasAssistantTextBody(
+ message({
+ id: "a2b",
+ role: "assistant",
+ contentBlocks: [
+ { type: "text", text: "hidden draft" },
+ {
+ type: "connection_action",
+ connectionId: "notion",
+ connectionName: "Notion",
+ },
+ ],
+ })
+ )
+ ).toBe(true);
+ expect(
+ hasAssistantTextBody(
+ message({
+ id: "a2",
+ role: "assistant",
+ contentBlocks: [
+ { type: "text", text: "hidden draft" },
+ {
+ type: "tool",
+ toolCall: {
+ id: "t-hidden",
+ toolName: "read",
+ args: {},
+ isRunning: false,
+ },
+ },
+ ],
+ })
+ )
+ ).toBe(false);
+ expect(
+ hasAssistantTextBody(
+ message({
+ id: "a2c",
+ role: "assistant",
+ contentBlocks: [
+ {
+ type: "tool",
+ toolCall: {
+ id: "t-visible",
+ toolName: "read",
+ args: {},
+ isRunning: false,
+ },
+ },
+ { type: "text", text: "final answer" },
+ ],
+ })
+ )
+ ).toBe(true);
+ expect(
+ hasAssistantTextBody(
+ message({
+ id: "a3",
+ role: "assistant",
+ contentBlocks: [{ type: "thinking", text: "ponder", isThinking: false }],
+ })
+ )
+ ).toBe(false);
+ });
+
+ it("only treats assistant rows with tool blocks as work", () => {
+ expect(
+ hasAssistantToolWorkBody(
+ message({
+ id: "a1",
+ role: "assistant",
+ contentBlocks: [{ type: "text", text: "done" }],
+ })
+ )
+ ).toBe(false);
+ expect(
+ hasAssistantToolWorkBody(
+ message({
+ id: "a2",
+ role: "assistant",
+ contentBlocks: [{ type: "thinking", text: "ponder", isThinking: false }],
+ })
+ )
+ ).toBe(false);
+ expect(
+ hasAssistantToolWorkBody(
+ message({
+ id: "a3",
+ role: "assistant",
+ contentBlocks: [
+ { type: "thinking", text: "ponder", isThinking: false },
+ {
+ type: "tool",
+ toolCall: {
+ id: "t1",
+ toolName: "read",
+ args: {},
+ isRunning: false,
+ },
+ },
+ ],
+ })
+ )
+ ).toBe(true);
});
it("collapses completed steer work while keeping hidden messages addressable", () => {
@@ -104,11 +236,158 @@ describe("message rendering helpers", () => {
message({ id: "u1", role: "user", content: "root", timestamp: 0 }),
message({ id: "a1", role: "assistant", content: "draft", timestamp: 20_000 }),
message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 40_000 }),
- message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", timestamp: 75_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", steeredResponse: true, timestamp: 75_000 }),
],
{ canCollapseSteerWork: true }
).filter((renderItem) => renderItem.type === "collapsed-steer-work");
expect(collapsedSteerWorkDuration(item)).toBe("Worked for 1 min 15 sec");
});
+
+ it("sets hideToolSummary and collapseToolsWithSteerWork on all assistants in a steered segment", () => {
+ const items = buildCollapsedSteerRenderItems(
+ [
+ message({ id: "u1", role: "user", content: "root", timestamp: 1_000 }),
+ message({ id: "a1", role: "assistant", content: "draft", timestamp: 2_000 }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 3_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", timestamp: 4_000 }),
+ ],
+ { canCollapseSteerWork: true }
+ );
+
+ const a1Item = items.find((i) => i.type === "message" && i.message.id === "a1") as Extract<ChatRenderItem, { type: "message" }>;
+ const a2Item = items.find((i) => i.type === "message" && i.message.id === "a2") as Extract<ChatRenderItem, { type: "message" }>;
+
+ // Hidden assistant (a1) gets both flags
+ expect(a1Item.hideToolSummary).toBe(true);
+ expect(a1Item.collapseToolsWithSteerWork).toBe("collapsed-steer-u1");
+
+ // Final assistant (a2) also gets both flags
+ expect(a2Item.hideToolSummary).toBe(true);
+ expect(a2Item.collapseToolsWithSteerWork).toBe("collapsed-steer-u1");
+
+ // Steer user message should NOT have these flags set to truthy values
+ const u2Item = items.find((i) => i.type === "message" && i.message.id === "u2") as Extract<ChatRenderItem, { type: "message" }>;
+ expect(u2Item.hideToolSummary).toBeFalsy();
+ expect(u2Item.collapseToolsWithSteerWork).toBeFalsy();
+ });
+
+ it("keeps completed steered segments collapsed when canCollapseSteerWork is false and segment is not active", () => {
+ const messages: Message[] = [
+ // First turn: completed steered segment
+ message({ id: "u1", role: "user", content: "root", timestamp: 1_000 }),
+ message({ id: "a1", role: "assistant", content: "draft", timestamp: 2_000 }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 3_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", timestamp: 4_000 }),
+ // Second turn: new normal message (makes first segment non-active)
+ message({ id: "u3", role: "user", content: "hi", timestamp: 5_000 }),
+ ];
+
+ // canCollapseSteerWork=false simulates loading/streaming state
+ const items = buildCollapsedSteerRenderItems(messages, { canCollapseSteerWork: false });
+
+ // The first segment should still be collapsed (not active)
+ expect(items.some((i) => i.type === "collapsed-steer-work")).toBe(true);
+ const collapsedItem = items.find((i) => i.type === "collapsed-steer-work");
+ expect(collapsedItem).toMatchObject({ id: "collapsed-steer-u1" });
+ });
+
+ it("does not collapse the active segment when canCollapseSteerWork is false", () => {
+ const messages: Message[] = [
+ message({ id: "u1", role: "user", content: "root", timestamp: 1_000 }),
+ message({ id: "a1", role: "assistant", content: "draft", timestamp: 2_000 }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 3_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", timestamp: 4_000 }),
+ ];
+
+ // Active segment (extends to end of messages) should NOT collapse
+ const items = buildCollapsedSteerRenderItems(messages, { canCollapseSteerWork: false });
+
+ expect(items.every((i) => i.type === "message")).toBe(true);
+ expect(items.some((i) => i.type === "collapsed-steer-work")).toBe(false);
+ });
+
+ it("shows 'Worked' when only the parent (non-steered) assistant has stoppedByUser", () => {
+ const [item] = buildCollapsedSteerRenderItems(
+ [
+ message({ id: "u1", role: "user", content: "root", timestamp: 0 }),
+ message({ id: "a1", role: "assistant", content: "draft", stoppedByUser: true, timestamp: 10_000 }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 20_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", steeredResponse: true, timestamp: 30_000 }),
+ ],
+ { canCollapseSteerWork: true }
+ ).filter((renderItem) => renderItem.type === "collapsed-steer-work");
+
+ // Parent was stopped internally by steering — steered assistant is fine
+ expect(collapsedSteerWorkDuration(item)).toBe("Worked for 30s");
+ });
+
+ it("shows 'You stopped' when the last steered assistant was stopped by user", () => {
+ const [item] = buildCollapsedSteerRenderItems(
+ [
+ message({ id: "u1", role: "user", content: "root", timestamp: 0 }),
+ message({ id: "a1", role: "assistant", content: "draft", stoppedByUser: true, timestamp: 10_000 }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 20_000 }),
+ message({ id: "a2", role: "assistant", content: "partial", turnIntentId: "t1", steeredResponse: true, stoppedByUser: true, timestamp: 30_000 }),
+ ],
+ { canCollapseSteerWork: true }
+ ).filter((renderItem) => renderItem.type === "collapsed-steer-work");
+
+ // Last steered assistant stopped — user explicitly stopped the workflow
+ expect(collapsedSteerWorkDuration(item)).toBe("You stopped after 30s");
+ });
+
+ it("counts failed tool calls across segment messages", () => {
+ const [item] = buildCollapsedSteerRenderItems(
+ [
+ message({ id: "u1", role: "user", content: "root", timestamp: 1_000 }),
+ message({
+ id: "a1",
+ role: "assistant",
+ content: "draft",
+ timestamp: 2_000,
+ contentBlocks: [
+ { type: "tool", toolCall: { id: "t1", toolName: "read", args: {}, isRunning: false, isError: true } },
+ { type: "tool", toolCall: { id: "t2", toolName: "write", args: {}, isRunning: false } },
+ ],
+ }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 3_000 }),
+ message({
+ id: "a2",
+ role: "assistant",
+ content: "final",
+ turnIntentId: "t1",
+ timestamp: 4_000,
+ contentBlocks: [
+ { type: "tool", toolCall: { id: "t3", toolName: "sql", args: {}, isRunning: false, isError: true } },
+ ],
+ }),
+ ],
+ { canCollapseSteerWork: true }
+ ).filter((renderItem) => renderItem.type === "collapsed-steer-work");
+
+ expect(collapsedSteerFailedCount(item)).toBe(2);
+ });
+
+ it("returns zero failed count when no tool calls have errors", () => {
+ const [item] = buildCollapsedSteerRenderItems(
+ [
+ message({ id: "u1", role: "user", content: "root", timestamp: 1_000 }),
+ message({
+ id: "a1",
+ role: "assistant",
+ content: "draft",
+ timestamp: 2_000,
+ contentBlocks: [
+ { type: "tool", toolCall: { id: "t1", toolName: "read", args: {}, isRunning: false } },
+ ],
+ }),
+ message({ id: "u2", role: "user", content: "steer", intent: "steer", turnIntentId: "t1", timestamp: 3_000 }),
+ message({ id: "a2", role: "assistant", content: "final", turnIntentId: "t1", timestamp: 4_000 }),
+ ],
+ { canCollapseSteerWork: true }
+ ).filter((renderItem) => renderItem.type === "collapsed-steer-work");
+
+ expect(collapsedSteerFailedCount(item)).toBe(0);
+ });
});
diff --git a/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts b/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
index ff8efd748..003ee5bdb 100644
--- a/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
+++ b/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
@@ -44,9 +44,36 @@ export function isSteeredAssistantMessage(message: Message): boolean {
export function hasRenderableAssistantBody(message: Message): boolean {
if (message.role !== "assistant") return false;
- if (message.stoppedByUser) return true;
if (message.content && message.content !== "Processing...") return true;
- return Boolean(message.contentBlocks?.length);
+ if (message.contentBlocks?.length) {
+ return message.contentBlocks.some((block) => block.type !== "thinking");
+ }
+ return false;
+}
+
+export function hasAssistantTextBody(message: Message): boolean {
+ if (message.role !== "assistant") return false;
+ if (message.contentBlocks?.length) {
+ // Only count prose that survives rendering.
+ // Intermediate narration before the last tool call is hidden, but text
+ // after the final tool call (including text followed by connection cards)
+ // stays visible and should keep the toolbar available.
+ let lastToolIndex = -1;
+ for (let i = 0; i < message.contentBlocks.length; i += 1) {
+ if (message.contentBlocks[i].type === "tool") {
+ lastToolIndex = i;
+ }
+ }
+ return message.contentBlocks
+ .slice(lastToolIndex + 1)
+ .some((block) => block.type === "text" && Boolean(block.text.trim()));
+ }
+ return Boolean(message.content && message.content !== "Processing...");
+}
+
+export function hasAssistantToolWorkBody(message: Message): boolean {
+ if (message.role !== "assistant") return false;
+ return Boolean(message.contentBlocks?.some((block) => block.type === "tool"));
}
export function isNormalUserMessage(message: Message): boolean {
@@ -60,6 +87,8 @@ export type ChatRenderItem =
hideWhenCollapsedBy?: string;
hideIntentLabelWhenCollapsedBy?: string;
showActionsWhenExpandedBy?: string;
+ hideToolSummary?: boolean;
+ collapseToolsWithSteerWork?: string;
}
| {
type: "collapsed-steer-work";
@@ -89,7 +118,11 @@ export function buildCollapsedSteerRenderItems(
const segment = messages.slice(i, end);
const steerUsers = segment.filter((message) => message.role === "user" && message.intent === "steer");
- if (steerUsers.length === 0 || !options.canCollapseSteerWork) {
+ // Only disable collapsing for the currently-active segment (the last one
+ // that extends to the end of the message list). Completed segments from
+ // earlier turns should always stay collapsed.
+ const isActiveSegment = end >= messages.length;
+ if (steerUsers.length === 0 || (!options.canCollapseSteerWork && isActiveSegment)) {
items.push(...segment.map((message) => ({ type: "message" as const, message })));
i = end - 1;
continue;
@@ -146,6 +179,8 @@ export function buildCollapsedSteerRenderItems(
type: "message",
message,
hideWhenCollapsedBy: collapsedWorkId,
+ hideToolSummary: message.role === "assistant",
+ collapseToolsWithSteerWork: message.role === "assistant" ? collapsedWorkId : undefined,
});
continue;
}
@@ -159,6 +194,8 @@ export function buildCollapsedSteerRenderItems(
showActionsWhenExpandedBy: message.role === "user" && message.intent === "steer" && hiddenAssistants.length > 0
? collapsedWorkId
: undefined,
+ hideToolSummary: message.role === "assistant",
+ collapseToolsWithSteerWork: message.role === "assistant" ? collapsedWorkId : undefined,
});
}
pushCollapsedWork();
@@ -170,10 +207,35 @@ export function buildCollapsedSteerRenderItems(
}
export function collapsedSteerWorkDuration(item: Extract<ChatRenderItem, { type: "collapsed-steer-work" }>): string {
+ // Steering sets piActiveStopRequestedRef internally, so intermediate
+ // assistants always end up with stoppedByUser=true. Only treat the
+ // segment as user-stopped when the last *steered* assistant was stopped —
+ // that means the user explicitly hit stop on the steering workflow.
+ // The parent (non-steered) assistant also gets stoppedByUser from the
+ // internal stop so we must only check steered assistants.
+ const steeredAssistants = item.segmentMessages.filter(
+ (m) => m.role === "assistant" && (m.intent === "steer" || m.steeredResponse === true)
+ );
+ const lastSteered = steeredAssistants[steeredAssistants.length - 1];
+ const userStopped = Boolean(lastSteered?.stoppedByUser);
const timestamps = item.segmentMessages
.map((message) => message.timestamp)
.filter((timestamp) => Number.isFinite(timestamp));
- if (timestamps.length < 2) return "Worked";
+ if (timestamps.length < 2) return userStopped ? "You stopped" : "Worked";
const durationMs = Math.max(...timestamps) - Math.min(...timestamps);
- return formatWorkDuration(durationMs);
+ return userStopped ? formatStoppedWorkDuration(durationMs) : formatWorkDuration(durationMs);
+}
+
+export function collapsedSteerFailedCount(item: Extract<ChatRenderItem, { type: "collapsed-steer-work" }>): number {
+ let count = 0;
+ for (const message of item.segmentMessages) {
+ if (message.contentBlocks) {
+ for (const block of message.contentBlocks) {
+ if (block.type === "tool" && block.toolCall.isError) {
+ count += 1;
+ }
+ }
+ }
+ }
+ return count;
}