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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(chat): hide thinking blocks, clean up work groups (#4897)
Harsh Kumarc810be19fbdf
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.tsxindex 1aa260a81..e98212851 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@@ -429,13 +429,10 @@ export function ChatMessageList({const blocks = lastAssistant?.contentBlocks;let loaderPhase: LoaderPhase = "analyzing";let toolName: string | undefined;- const thinkingSecs: number | undefined = undefined;if (blocks && blocks.length > 0) {const lastBlock = blocks[blocks.length - 1];- if (lastBlock.type === "thinking" && lastBlock.isThinking) {- loaderPhase = "thinking";- } else if (lastBlock.type === "tool" && lastBlock.toolCall.isRunning) {+ if (lastBlock.type === "tool" && lastBlock.toolCall.isRunning) {loaderPhase = "tool";toolName = lastBlock.toolCall.toolName;} else if (lastBlock.type === "text" && lastBlock.text) {@@ -459,7 +456,6 @@ export function ChatMessageList({<GridDissolveLoaderphase={loaderPhase}toolName={toolName}- thinkingSecs={thinkingSecs}/></motion.div>);diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsxindex 26963b0ee..126f3abc5 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx@@ -11,7 +11,6 @@ import { SourceCitationFooter } from "@/components/chat/source-citation-footer";import { MarkdownBlock } from "@/components/chat/markdown-block";import { getFaviconUrl } from "@/components/rewind/timeline/favicon-utils";import { IntegrationIcon } from "@/components/settings/connections-section";-import { useSettings } from "@/lib/hooks/use-settings";import { useFeedbackStore } from "@/lib/stores/feedback-store";import { cn } from "@/lib/utils";import type { Message, ToolCall, ContentBlock } from "@/lib/chat/types";@@ -58,7 +57,7 @@ function MermaidDiagramBlock({ chart }: { chart: string }) {}// Animation phase for the grid dissolve loader.-export type LoaderPhase = "analyzing" | "thinking" | "tool" | "streaming";+export type LoaderPhase = "analyzing" | "tool" | "streaming";// Grid dissolve loading indicator — 5x4 grid of cells with animation patterns// that shift based on what the model is doing. Geometric, screen-capture themed.@@ -66,12 +65,10 @@ export function GridDissolveLoader({phase = "analyzing",label,toolName,- thinkingSecs,}: {phase?: LoaderPhase;label?: string;toolName?: string;- thinkingSecs?: number;}) {const ROWS = 3;const COLS = 5;@@ -104,7 +101,7 @@ export function GridDissolveLoader({const fill = tick % (ROWS + 1);return row <= fill || row === scanRow % ROWS;}- // analyzing / thinking: scan line is bright, other cells flicker+ // analyzing: scan line is bright, other cells flickerif (row === scanRow % ROWS) return true;return Math.random() > 0.6;});@@ -115,7 +112,6 @@ export function GridDissolveLoader({}, [phase]);const displayLabel = label ?? (- phase === "thinking" ? `thinking${thinkingSecs != null ? ` ${thinkingSecs}s` : ""}...` :phase === "tool" ? (toolName ?? "running tool...") :phase === "streaming" ? "writing..." :"analyzing..."@@ -527,42 +523,6 @@ function ToolCallRailItem({ toolCall, isLast }: { toolCall: ToolCall; isLast: bo);}-function ThinkingBlock({ text, isThinking, durationMs, defaultExpanded = false }: { text: string; isThinking: boolean; durationMs?: number; defaultExpanded?: boolean }) {- const [expanded, setExpanded] = useState(defaultExpanded);- const [elapsed, setElapsed] = useState(0);- const startRef = useRef(Date.now());-- useEffect(() => {- if (!isThinking) return;- const id = window.setInterval(() => setElapsed(Math.floor((Date.now() - startRef.current) / 1000)), 1000);- return () => window.clearInterval(id);- }, [isThinking]);-- const seconds = isThinking ? elapsed : durationMs ? Math.round(durationMs / 1000) : 0;-- return (- <div className="rounded-lg border border-border/30 bg-muted/20 text-xs overflow-hidden max-w-full">- <button- onClick={() => setExpanded(!expanded)}- className="w-full flex items-center gap-2 px-3 py-2 hover:bg-muted/40 transition-colors text-left"- >- <div className={cn("h-2 w-2 rounded-full", isThinking ? "bg-foreground/60 animate-pulse" : "bg-foreground/30")} />- <span className="font-mono text-muted-foreground">- {isThinking ? `thinking... (${seconds}s)` : `thought for ${seconds}s`}- </span>- <span className="ml-auto text-muted-foreground">{expanded ? "▾" : "▸"}</span>- </button>- {expanded && text.trim() && (- <div className="px-3 py-2 border-t border-border/30">- <div className="pl-3 border-l-2 border-border/40 text-muted-foreground font-mono whitespace-pre-wrap break-words max-h-[300px] overflow-y-auto text-[11px] leading-relaxed">- {text}- </div>- </div>- )}- </div>- );-}-// --- App stats helpers ---const APP_STAT_COLORS = [@@ -816,12 +776,10 @@ function groupContentBlocks(blocks: ContentBlock[]): GroupedBlock[] {return result;}-function collapseHiddenWorkGroups(grouped: GroupedBlock[], hideThinkingBlocks: boolean): GroupedBlock[] {- // Run always: collapsing consecutive tool-groups into a single- // "Worked for X min" rail is useful regardless of the thinking-block- // visibility setting. `hideThinkingBlocks` only controls whether- // thinking blocks get absorbed into the work-group (true) or shown- // as separate pills (false).+function collapseHiddenWorkGroups(grouped: GroupedBlock[]): GroupedBlock[] {+ // Collapse consecutive tool-groups into a single "Worked for X min"+ // rail. Thinking blocks are always absorbed — their duration folds+ // into the work-group and they never render as separate pills.const out: GroupedBlock[] = [];let pendingToolCalls: ToolCall[] = [];@@ -864,15 +822,9 @@ function collapseHiddenWorkGroups(grouped: GroupedBlock[], hideThinkingBlocks: b}if (group.type === "thinking") {- if (hideThinkingBlocks) {- pendingDurationMs += group.durationMs ?? 0;- pendingKey ??= group.key;- continue;- }- // Show thinking pills inline — flush pending tool work first so- // ordering is preserved and the thinking pill renders separately.- flushPending();- out.push(group);+ // Always absorb thinking duration into the pending work-group+ pendingDurationMs += group.durationMs ?? 0;+ pendingKey ??= group.key;continue;}@@ -884,6 +836,66 @@ function collapseHiddenWorkGroups(grouped: GroupedBlock[], hideThinkingBlocks: breturn out;}+/**+ * Merge all tool/work groups into a single "Worked for Xs" rail at the top.+ * Intermediate narration text between tool calls is dropped — only the+ * final text block (the actual response after all tools finish) renders+ * as visible prose. Connection-action blocks always render outside.+ */+function mergeWorkAndIntermediateText(groups: GroupedBlock[]): GroupedBlock[] {+ // Find the last work/tool group — everything up to that boundary is+ // "work". Text after is the final response.+ let lastWorkIdx = -1;+ for (let i = groups.length - 1; i >= 0; i--) {+ if (groups[i].type === "work-group" || groups[i].type === "tool-group") {+ lastWorkIdx = i;+ break;+ }+ }++ // No tool calls at all → nothing to merge, show text as-is.+ if (lastWorkIdx === -1) return groups;++ // Accumulate all tool calls and duration into one work group.+ // Intermediate text (model narration between tools) is dropped.+ const allToolCalls: ToolCall[] = [];+ let totalDurationMs = 0;+ let firstKey: number | null = null;+ const finalBlocks: GroupedBlock[] = [];++ for (let i = 0; i <= lastWorkIdx; i++) {+ const g = groups[i];+ if (g.type === "work-group") {+ firstKey ??= g.key;+ allToolCalls.push(...g.toolCalls);+ totalDurationMs += g.durationMs;+ } else if (g.type === "tool-group") {+ firstKey ??= g.key;+ allToolCalls.push(...g.toolCalls);+ } else if (g.type === "connection-action") {+ finalBlocks.push(g);+ }+ // text and thinking blocks before the boundary are dropped+ }++ // Build the merged work group+ if (allToolCalls.length > 0) {+ finalBlocks.unshift({+ type: "work-group",+ toolCalls: allToolCalls,+ durationMs: totalDurationMs,+ key: firstKey ?? 0,+ });+ }++ // Everything after lastWorkIdx is the final response+ for (let i = lastWorkIdx + 1; i < groups.length; i++) {+ finalBlocks.push(groups[i]);+ }++ return finalBlocks;+}+function InlineConnectionActionCard({block,connected,@@ -1145,38 +1157,42 @@ function ToolCallGroup({}}, [isWorking, runningSummary]);- // Auto-expand while running, auto-collapse when done (user can override).- // `defaultExpanded` keeps the group open even when done — used for- // messages whose entire output is tool calls (typical pipe-runs)- // where the tool result is the whole story.- const isExpanded = manualExpand !== null ? manualExpand : (hasRunningTool || defaultExpanded);+ // While working → always expanded, no user toggle.+ // 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;return (<div className="w-full min-w-0 self-stretch"><div className="mb-2 w-full min-w-full">- {/* Header bar — clickable to toggle */}- <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"- >- {/* Summary text */}- <span className="truncate text-xs font-mono text-foreground/50 group-hover:text-foreground/80 transition-colors duration-150">- <WorkSummaryText- text={isWorking ? runningSummary : summary || `${total} steps`}- animateRunningDuration={isWorking}- />- {hasError && allDone && (- <span className="ml-1.5 text-foreground/30">· {toolCalls.filter(tc => tc.isError).length} failed</span>+ {/* 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>-- {/* Expand chevron */}- {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>+ </button>+ )}<div className="w-full min-w-full border-t border-border/50" /></div>@@ -1239,8 +1255,6 @@ export function MessageContent({onDismissConnectionAction?: (messageId: string, connectionId: string) => void;}) {const isUser = message.role === "user";- const { settings } = useSettings();- const hideThinkingBlocks = settings?.hideThinkingBlocks ?? true;const sourceCitations = isUser ? [] : sourceCitationsFromMessage(message);const sourceFooter = !deferSourceFooter && sourceCitations.length > 0 ? (<SourceCitationFooter citations={sourceCitations} onOpenFile={onOpenViewerPath} />@@ -1367,13 +1381,30 @@ export function MessageContent({// Group consecutive tool blocks into collapsible containersif (message.contentBlocks && message.contentBlocks.length > 0) {const grouped = groupContentBlocks(message.contentBlocks);- const displayGroups = collapseHiddenWorkGroups(grouped, hideThinkingBlocks);- // When the message has no rendered prose (no text block — common for- // pipe-run executions whose entire output is thinking + tool calls),- // expand thinking blocks by default. Otherwise the collapsed- // "thought for 0s" pill is the only visible thing on the message- // and the chat panel reads as empty even though there's real- // content to see.+ 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>+ );+ }+const hasText = grouped.some((g) => g.type === "text");const stoppedSummary = message.stoppedByUser? formatStoppedWorkDuration(message.workDurationMs)@@ -1403,13 +1434,9 @@ export function MessageContent({);}if (group.type === "thinking") {- // Settings → Display → Hide Thinking Blocks (default true). Even- // when shown the block starts collapsed: the "thought for Xs"- // pill is enough signal that the assistant did chain-of-thought- // work — auto-expanding (the c092166e0 behavior) drew the eye- // to raw reasoning instead of the response.- if (hideThinkingBlocks) return null;- return <ThinkingBlock key={`thinking-${group.key}`} text={group.text} isThinking={group.isThinking} durationMs={group.durationMs} />;+ // Thinking blocks are always hidden — guard until+ // collapseHiddenWorkGroups absorbs them fully.+ return null;}if (group.type === "connection-action") {const liveConnection = connectionItems.find((connection) => connection.id === group.block.connectionId);diff --git a/apps/screenpipe-app-tauri/components/settings/display-section.tsx b/apps/screenpipe-app-tauri/components/settings/display-section.tsxindex 4a14d6f21..77d459400 100644--- a/apps/screenpipe-app-tauri/components/settings/display-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/display-section.tsx@@ -276,30 +276,6 @@ export function DisplaySection() {</CardContent></Card>- <Card className="border-border bg-card">- <CardContent className="px-3 py-2.5">- <div className="flex items-center justify-between">- <div className="flex items-center space-x-2.5">- <MessageSquare className="h-4 w-4 text-muted-foreground shrink-0" />- <div>- <h3 className="text-sm font-medium text-foreground flex items-center gap-1.5">- Hide Thinking Blocks- <HelpTooltip text="Don't render the collapsible model-reasoning blocks in chat. The model still emits them; this just hides them from the transcript." />- </h3>- <p className="text-xs text-muted-foreground">Hide model reasoning in chat transcript</p>- </div>- </div>- <Switch- checked={settings?.hideThinkingBlocks ?? true}- onCheckedChange={(checked) =>- handleSettingsChange({ hideThinkingBlocks: checked })- }- className="ml-4"- />- </div>- </CardContent>- </Card>-<Card className="border-border bg-card"><CardContent className="px-3 py-2.5"><div className="flex items-center justify-between">diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex 9ef9f84f7..4bd8df043 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -321,8 +321,6 @@ export type Settings = SettingsStore & {localRetentionMode?: "media" | "lean" | "all";/** Apply macOS vibrancy effect to sidebar for a translucent glass look */translucentSidebar?: boolean;- /** Hide model "thinking" reasoning blocks in chat (default: true) */- hideThinkingBlocks?: boolean;/** Show the chat suggestion chips above the input — the "follow up"* questions and the connection-aware suggested prompts. The single inline* X on the chips flips this to false; re-enable from Settings → Display.diff --git a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.tsindex 16089b483..439fbeaef 100644--- a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts+++ b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts@@ -177,6 +177,20 @@ export function parsePipeNdjsonToMessages(raw: string, pipeName?: string): ChatMpendingLastTs = msgTs;}const toolBlocks = Array.isArray(content) ? extractToolCalls(content, i) : [];+ // Extract thinking blocks from the content array so their+ // duration is absorbed by collapseHiddenWorkGroups+ if (Array.isArray(content)) {+ for (const block of content) {+ if (block.type === "thinking") {+ pendingBlocks.push({+ type: "thinking",+ text: block.thinking || block.text || "",+ isThinking: false,+ durationMs: undefined,+ });+ }+ }+ }if (text.trim()) {pendingBlocks.push({ type: "text", text: text.trim() });pendingTexts.push(text.trim());diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.tsindex 83d150fcd..80a08a3cf 100644--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts@@ -3178,12 +3178,6 @@ showRestartNotifications?: boolean;* When true, apply macOS vibrancy effect to the sidebar for a translucent look.*/translucentSidebar?: boolean;-/**- * When true (default), hide model "thinking" reasoning blocks in the chat- * transcript. The model still emits them server-side; we just don't- * render the collapsible block in the UI.- */-hideThinkingBlocks?: boolean;/*** UI theme: "light", "dark", or "system".*/diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rsindex 05421eb5d..e4202840e 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs@@ -973,12 +973,6 @@ pub struct SettingsStore {#[serde(rename = "translucentSidebar", default)]pub translucent_sidebar: bool,- /// When true (default), hide model "thinking" reasoning blocks in the chat- /// transcript. The model still emits them server-side; we just don't- /// render the collapsible block in the UI.- #[serde(rename = "hideThinkingBlocks", default = "default_true")]- pub hide_thinking_blocks: bool,-/// UI theme: "light", "dark", or "system".#[serde(rename = "uiTheme", default = "default_ui_theme")]pub ui_theme: String,@@ -1403,7 +1397,6 @@ Rules:translucent_sidebar: true,#[cfg(not(target_os = "macos"))]translucent_sidebar: false,- hide_thinking_blocks: true,ui_theme: "system".to_string(),minimize_to_tray_on_close: false,extra: std::collections::HashMap::new(),