Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(agents): stop thinking shimmers after a Cursor thought finishes (#6488)

Wolf Mermelstein9912d34f59ab
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
index 6676ca55cf..23b1c1e1a5 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
@@ -45,8 +45,10 @@ vi.mock('./parts/ElicitationPart', () => ({ ElicitationPart: () => null }));
vi.mock('../ui', () => ({
isToolActive: (status: string) =>
status === 'pending' || status === 'running',
- Thought: (props: { text: string }) => (
- <div data-testid="thought">{props.text}</div>
+ Thought: (props: { text: string; active?: boolean }) => (
+ <div data-active={String(props.active ?? false)} data-testid="thought">
+ {props.text}
+ </div>
),
WorkingLine: () => <div data-testid="working" />,
ActionLine: (props: { label: string }) => <div>{props.label}</div>,
@@ -211,3 +213,67 @@ describe('Message tool grouping', () => {
expect(view.getByTestId('text')).toBe(prose);
});
});
+
+describe('Message thought shimmer', () => {
+ const thought = (value: string): MessagePart => ({
+ kind: 'thought',
+ text: value,
+ });
+
+ it('keeps grouped thoughts at their real indices when the group opens', () => {
+ const view = render(() => (
+ <Message
+ message={message(
+ [thought('why this file'), tool('read'), tool('edit')],
+ null
+ )}
+ />
+ ));
+ expect(view.getByTestId('thought').dataset.active).toBe('false');
+ expect(view.getByTestId('thought').textContent).toBe('why this file');
+ expect(view.getAllByTestId('tool').map((el) => el.dataset.index)).toEqual([
+ '1',
+ '2',
+ ]);
+ });
+
+ it('shimmers only the trailing thought of an open turn', () => {
+ const view = render(() => (
+ <Message
+ message={message(
+ [
+ thought('already decided'),
+ tool('read'),
+ thought('still weighing this'),
+ ],
+ null
+ )}
+ />
+ ));
+ const rows = view.getAllByTestId('thought');
+ expect(rows.map((el) => el.textContent)).toEqual([
+ 'already decided',
+ 'still weighing this',
+ ]);
+ expect(rows.map((el) => el.dataset.active)).toEqual(['false', 'true']);
+ });
+
+ it('settles a thought once prose follows it', () => {
+ const view = render(() => (
+ <Message
+ message={message(
+ [thought('weighing'), text('Here is the answer.')],
+ null
+ )}
+ />
+ ));
+ expect(view.getByTestId('thought').dataset.active).toBe('false');
+ });
+
+ it('settles every thought once the turn has a stop reason', () => {
+ const view = render(() => (
+ <Message message={message([thought('done thinking')])} />
+ ));
+ expect(view.getByTestId('thought').dataset.active).toBe('false');
+ });
+});
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsx
index 83e433c1f9..4515e6d3a5 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx
@@ -1,8 +1,8 @@
/**
* Renders one folded agent-session message. Pure composition: each part kind
* has its own component under `parts/` (the chat block's handler-per-tool
- * split), user prompts get the chat block's bubble treatment, and thoughts
- * shimmer while the turn is in flight.
+ * split), user prompts get the chat block's bubble treatment, and the tail
+ * thought shimmers while the turn is in flight.
*/
import { messageSendMotion } from '@core/util/message-send-motion';
@@ -14,6 +14,7 @@ import { UserMessageBubble } from '@ui';
import { For, Index, type JSX, Show } from 'solid-js';
import { match } from 'ts-pattern';
import { isControlMessage } from '../state/control-message';
+import { thoughtIsStreaming } from '../state/thought-streaming';
import { segmentParts } from '../state/tool-groups';
import {
ActionLine,
@@ -35,7 +36,7 @@ function AgentMessagePart(props: {
message: FoldedMessage;
/** The part's index within its message, for the tool render context. */
index: number;
- /** The turn is still in flight — thoughts read "Thinking" and shimmer. */
+ /** The turn is still in flight — the tail thought reads "Thinking". */
inFlight: boolean;
}): JSX.Element {
return match(props.part)
@@ -43,7 +44,14 @@ function AgentMessagePart(props: {
<TextPart text={part.text} inFlight={props.inFlight} />
))
.with({ kind: 'thought' }, (part) => (
- <Thought text={part.text} active={props.inFlight} />
+ <Thought
+ text={part.text}
+ active={thoughtIsStreaming(
+ props.inFlight,
+ props.index,
+ props.message.parts.length
+ )}
+ />
))
.with({ kind: 'tool_use' }, (part) => (
<ToolCallPart
@@ -66,8 +74,9 @@ function AgentMessagePart(props: {
}
/**
- * A run of consecutive tool calls (see `segmentParts`), folded to one row
- * that opens to the calls themselves, each at its original part index.
+ * A run of consecutive tool calls and their accompanying thoughts (see
+ * `segmentParts`), folded to one row that opens to those parts, each at
+ * its original index.
*/
function ToolGroupPart(props: {
message: FoldedMessage;
@@ -76,10 +85,9 @@ function ToolGroupPart(props: {
end: number;
inFlight: boolean;
}): JSX.Element {
+ const parts = () => props.message.parts.slice(props.start, props.end);
const calls = () =>
- props.message.parts
- .slice(props.start, props.end)
- .filter((part): part is ToolUsePart => part.kind === 'tool_use');
+ parts().filter((part): part is ToolUsePart => part.kind === 'tool_use');
const active = () => calls().some((call) => isToolActive(call.status));
return (
@@ -93,7 +101,7 @@ function ToolGroupPart(props: {
detail: toolCallDetail(latest()),
}}
>
- <For each={calls()}>
+ <For each={parts()}>
{(part, offset) => (
<AgentMessagePart
part={part}
diff --git a/apps/web/src/features/block-agent/component/parts/SubagentToolCall.tsx b/apps/web/src/features/block-agent/component/parts/SubagentToolCall.tsx
index 2b33c0e5f9..2d19a46381 100644
--- a/apps/web/src/features/block-agent/component/parts/SubagentToolCall.tsx
+++ b/apps/web/src/features/block-agent/component/parts/SubagentToolCall.tsx
@@ -11,6 +11,7 @@ import type {
} from '@service-agent-fold/generated/types';
import { For, type JSX, Show } from 'solid-js';
import { match } from 'ts-pattern';
+import { thoughtIsStreaming } from '../../state/thought-streaming';
import { FoldedOutput, Thought, ToolCard } from '../../ui';
import type { ToolCallCommon, ToolCallContext } from './shared';
import { TextPart } from './TextPart';
@@ -45,6 +46,7 @@ function resultSummary(result: SubagentResult): string | undefined {
function ChildPart(props: {
part: MessagePart;
index: number;
+ childCount: number;
context?: ToolCallContext;
}) {
const inFlight = () => props.context?.inFlight ?? false;
@@ -52,7 +54,10 @@ function ChildPart(props: {
match(props.part)
.with({ kind: 'text' }, (part) => <TextPart text={part.text} />)
.with({ kind: 'thought' }, (part) => (
- <Thought text={part.text} active={inFlight()} />
+ <Thought
+ text={part.text}
+ active={thoughtIsStreaming(inFlight(), props.index, props.childCount)}
+ />
))
.with({ kind: 'tool_use' }, (part) => (
<ToolCallPart
@@ -129,6 +134,7 @@ export function SubagentToolCall(props: {
<ChildPart
part={child}
index={index()}
+ childCount={props.detail.children.length}
context={childContext()}
/>
)}
diff --git a/apps/web/src/features/block-agent/component/parts/ToolCallPart.test.tsx b/apps/web/src/features/block-agent/component/parts/ToolCallPart.test.tsx
index f6fa6c55c3..cab71e4976 100644
--- a/apps/web/src/features/block-agent/component/parts/ToolCallPart.test.tsx
+++ b/apps/web/src/features/block-agent/component/parts/ToolCallPart.test.tsx
@@ -92,8 +92,10 @@ vi.mock('../../ui', () => ({
FoldedPathList: (props: { paths: string[] }) => (
<div data-testid="path-list">{props.paths.join(',')}</div>
),
- Thought: (props: { text: string }) => (
- <div data-testid="thought">{props.text}</div>
+ Thought: (props: { text: string; active?: boolean }) => (
+ <div data-active={String(props.active ?? false)} data-testid="thought">
+ {props.text}
+ </div>
),
}));
@@ -570,6 +572,50 @@ describe('ToolCallPart subagents', () => {
);
});
+ it('shimmers only a trailing child thought while the subagent is live', () => {
+ const rendered = render(() => (
+ <ToolCallPart
+ part={toolUse(
+ {
+ kind: 'subagent',
+ title: 'Add 5+5 with Python',
+ agentType: 'general-purpose',
+ description: 'Add 5+5 with Python',
+ prompt: 'Run python and report the output.',
+ background: false,
+ children: [
+ { kind: 'thought', text: 'already decided' },
+ toolUse(
+ {
+ kind: 'terminal',
+ command: 'python3 -c "print(5+5)"',
+ output: '10',
+ exitCode: 0,
+ },
+ { id: 'child', name: 'Bash' }
+ ),
+ { kind: 'thought', text: 'still weighing this' },
+ ],
+ result: null,
+ },
+ { name: 'Agent', status: 'running' }
+ )}
+ context={{
+ sessionId: 'session',
+ messageId: 'session:0:agent',
+ partIndex: 0,
+ inFlight: true,
+ }}
+ />
+ ));
+ const rows = rendered.getAllByTestId('thought');
+ expect(rows.map((el) => el.textContent)).toEqual([
+ 'already decided',
+ 'still weighing this',
+ ]);
+ expect(rows.map((el) => el.dataset.active)).toEqual(['false', 'true']);
+ });
+
it('shows a failed subagent faded with its error', () => {
const rendered = render(() => (
<ToolCallPart
diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsx
index fb864f6a8a..d6345f3700 100644
--- a/apps/web/src/features/block-agent/debug/Gallery.tsx
+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx
@@ -366,6 +366,43 @@ const FIXTURE_MESSAGE: FoldedMessage = {
],
};
+/** A live Cursor-shaped turn: earlier reasoning has settled, the tail has not. */
+const FIXTURE_IN_FLIGHT: FoldedMessage = {
+ agentSessionId: 'demo',
+ requestId: null,
+ turn: 1,
+ author: { kind: 'agent' },
+ stop: null,
+ parts: [
+ {
+ kind: 'thought',
+ text: 'The batch fold re-derives every message per frame; switch to the incremental machine.',
+ },
+ {
+ kind: 'tool_use',
+ id: 'live-read',
+ name: { kind: 'native', name: 'Read' },
+ status: 'completed',
+ detail: { kind: 'read', paths: ['crates/agent_fold/src/domain/fold.rs'] },
+ },
+ {
+ kind: 'tool_use',
+ id: 'live-search',
+ name: { kind: 'native', name: 'Search' },
+ status: 'completed',
+ detail: {
+ kind: 'search',
+ paths: ['crates/agent_fold/src'],
+ output: 'fold.rs:12: fn fold(log: &[Frame]) -> Vec<Message>',
+ },
+ },
+ {
+ kind: 'thought',
+ text: 'The incremental machine already handles this. Next I will edit fold.rs.',
+ },
+ ],
+};
+
/**
* The Claude Code colour question after the fold collapsed its custom pair,
* plus one of every other field type, so the form's controls can be eyeballed.
@@ -774,6 +811,14 @@ export default function AgentUiGallery() {
<Item label="AgentMessage (end-to-end)">
<Message message={FIXTURE_MESSAGE} />
</Item>
+
+ <Item label="AgentMessage (Cursor turn in flight)">
+ <p class="text-xs text-ink-muted">
+ Earlier reasoning has settled. Only the trailing thought still
+ says Thinking.
+ </p>
+ <Message message={FIXTURE_IN_FLIGHT} />
+ </Item>
</div>
</div>
</StaticMarkdownContext>
diff --git a/apps/web/src/features/block-agent/state/thought-streaming.test.ts b/apps/web/src/features/block-agent/state/thought-streaming.test.ts
new file mode 100644
index 0000000000..e054e0e83e
--- /dev/null
+++ b/apps/web/src/features/block-agent/state/thought-streaming.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest';
+import { thoughtIsStreaming } from './thought-streaming';
+
+describe('thoughtIsStreaming', () => {
+ it('is true only for the last part of an open turn', () => {
+ expect(thoughtIsStreaming(true, 2, 3)).toBe(true);
+ expect(thoughtIsStreaming(true, 0, 1)).toBe(true);
+ });
+
+ it('settles earlier thoughts while the turn is still running', () => {
+ expect(thoughtIsStreaming(true, 0, 3)).toBe(false);
+ expect(thoughtIsStreaming(true, 1, 3)).toBe(false);
+ });
+
+ it('settles every thought once the turn has a stop reason', () => {
+ expect(thoughtIsStreaming(false, 0, 1)).toBe(false);
+ expect(thoughtIsStreaming(false, 2, 3)).toBe(false);
+ });
+
+ it('is false for an empty parts list', () => {
+ expect(thoughtIsStreaming(true, 0, 0)).toBe(false);
+ });
+});
diff --git a/apps/web/src/features/block-agent/state/thought-streaming.ts b/apps/web/src/features/block-agent/state/thought-streaming.ts
new file mode 100644
index 0000000000..c8b65ef206
--- /dev/null
+++ b/apps/web/src/features/block-agent/state/thought-streaming.ts
@@ -0,0 +1,15 @@
+/**
+ * A thought shimmers only while it is the tail of an open turn — the same
+ * rule production chat uses for `ThinkingBlock`.
+ *
+ * Keying `active` off the whole turn is what made Cursor sessions look stuck:
+ * a long think → tool → think loop kept every earlier "Thinking" row sweeping
+ * for minutes after that reasoning had already finished.
+ */
+export function thoughtIsStreaming(
+ inFlight: boolean,
+ partIndex: number,
+ partCount: number
+): boolean {
+ return inFlight && partCount > 0 && partIndex === partCount - 1;
+}
diff --git a/apps/web/src/features/block-agent/state/tool-groups.test.ts b/apps/web/src/features/block-agent/state/tool-groups.test.ts
index 5e67e06b99..c04ab87626 100644
--- a/apps/web/src/features/block-agent/state/tool-groups.test.ts
+++ b/apps/web/src/features/block-agent/state/tool-groups.test.ts
@@ -75,7 +75,24 @@ describe('segmentParts', () => {
it('groups consecutive thinking blocks with tool calls', () => {
expect(
segmentParts([thought(), tool(), thought(), tool(), thought()])
- ).toEqual([{ kind: 'tools', start: 0, end: 5 }]);
+ ).toEqual([
+ { kind: 'tools', start: 0, end: 4 },
+ { kind: 'part', start: 4, end: 5 },
+ ]);
+ });
+
+ it('leaves a trailing thought out of a tool run', () => {
+ expect(segmentParts([thought(), tool(), thought()])).toEqual([
+ { kind: 'tools', start: 0, end: 2 },
+ { kind: 'part', start: 2, end: 3 },
+ ]);
+ });
+
+ it('leaves a thought after a single tool as its own part', () => {
+ expect(segmentParts([tool(), thought()])).toEqual([
+ { kind: 'part', start: 0, end: 1 },
+ { kind: 'part', start: 1, end: 2 },
+ ]);
});
it('keeps a lone thinking block as its own part', () => {
diff --git a/apps/web/src/features/block-agent/state/tool-groups.ts b/apps/web/src/features/block-agent/state/tool-groups.ts
index 9b70b80cbd..d6924d49cd 100644
--- a/apps/web/src/features/block-agent/state/tool-groups.ts
+++ b/apps/web/src/features/block-agent/state/tool-groups.ts
@@ -4,6 +4,11 @@
* everything else as itself. A lone call stays a card of its own — a group of
* one would hide the call behind a count that says nothing the card did not.
*
+ * A thought at the tail of a run stays out of the group. That row is the
+ * current (or last) reasoning, and burying it in "Called N tools" is what
+ * made a live Cursor turn look finished — or, once expanded, like every
+ * earlier thought was still happening.
+ *
* Segments are half-open index ranges into the parts array, so a grouped call
* keeps its position for the tool render context.
*/
@@ -28,6 +33,9 @@ export function segmentParts(parts: readonly MessagePart[]): PartSegment[] {
let end = start + 1;
if (isGroupable(parts[start])) {
while (isGroupable(parts[end])) end += 1;
+ if (end - start >= 2 && parts[end - 1]?.kind === 'thought') {
+ end -= 1;
+ }
}
segments.push({
kind: end - start >= 2 ? 'tools' : 'part',
diff --git a/apps/web/src/features/block-agent/ui/Thought.tsx b/apps/web/src/features/block-agent/ui/Thought.tsx
index 0c85be7094..a1efa2d567 100644
--- a/apps/web/src/features/block-agent/ui/Thought.tsx
+++ b/apps/web/src/features/block-agent/ui/Thought.tsx
@@ -2,7 +2,9 @@
* The agent's reasoning, modeled on the chat block's `ThinkingBlock`
* (`@core/component/AI/component/message/ThinkingBlock.tsx`): a bare,
* borderless row — caret, then a "Thinking"/"Thought" label that shimmers
- * while the turn is in flight — expanding to the reasoning text.
+ * while this thought is still the tail of an open turn — expanding to the
+ * reasoning text. Earlier thoughts settle the moment the next part arrives,
+ * the same rule production chat uses for `ThinkingBlock`.
*/
import CaretRight from '@phosphor/caret-right.svg';
@@ -11,7 +13,7 @@ import { TextShimmer } from './TextShimmer';
export interface ThoughtProps {
text: string;
- /** The turn is still in flight: label reads "Thinking" and shimmers. */
+ /** This thought is still the tail of an open turn: "Thinking" and shimmer. */
active?: boolean;
defaultOpen?: boolean;
}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index 22762d3e64..fd0f9168e8 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -272,6 +272,12 @@ only when their card opens; syntax highlighting may appear after the diff text.
Opening a session or expanding a group should leave the app responsive, even
when the session contains many file edits.
+A thought row reads **Thinking** and shimmers only while it is the last part
+of an open turn. Earlier thoughts settle to **Thought** as soon as a tool or
+answer follows, including during long Cursor turns. A trailing thought stays
+outside the tool group so the live reasoning row stays visible. Do not wait
+for every Thinking label to disappear — only the tail one is in flight.
+
### Sharing a session
Saved sessions have **Share** and **Copy Share Link** in the desktop header;