Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): settle every turn but the live one in the agent transcript (#6575)
Eric Hayese22c07c5ed6d
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx b/apps/web/src/features/block-agent/component/AgentMessage.test.tsxindex 23b1c1e1a5..5f8102287c 100644--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx@@ -120,6 +120,7 @@ describe('Message tool grouping', () => {}),text('Done.'),])}+ inFlight={false}/>));const group = view.getByTestId('group');@@ -139,7 +140,10 @@ describe('Message tool grouping', () => {it('leaves a lone tool call as its own card', () => {const view = render(() => (- <Message message={message([text('Looking.'), tool('read')])} />+ <Message+ message={message([text('Looking.'), tool('read')])}+ inFlight={false}+ />));expect(view.queryByTestId('group')).toBeNull();expect(view.getByTestId('tool').dataset.index).toBe('1');@@ -155,6 +159,7 @@ describe('Message tool grouping', () => {tool('c'),tool('d'),])}+ inFlight={false}/>));expect(view.getAllByTestId('group').map((el) => el.dataset.count)).toEqual([@@ -168,16 +173,30 @@ describe('Message tool grouping', () => {const view = render(() => (<Messagemessage={message([tool('a'), tool('b', { status: 'running' })], null)}+ inFlight/>));expect(view.getByTestId('group').dataset.active).toBe('true');});+ it('settles a run the log left running once the turn is no longer live', () => {+ // A superseded turn keeps `stop: null` and its last call `running`+ // forever; a dead runtime leaves the tail the same way.+ const view = render(() => (+ <Message+ message={message([tool('a'), tool('b', { status: 'running' })], null)}+ inFlight={false}+ />+ ));+ expect(view.getByTestId('group').dataset.active).toBe('false');+ expect(view.queryByTestId('working')).toBeNull();+ });+it('keeps the group mounted as streamed calls extend the run', () => {const [store, setStore] = createStore({message: message([text('Looking.'), tool('a'), tool('b')], null),});- const view = render(() => <Message message={store.message} />);+ const view = render(() => <Message message={store.message} inFlight />);const group = view.getByTestId('group');expect(group.dataset.count).toBe('2');@@ -201,7 +220,7 @@ describe('Message tool grouping', () => {const [store, setStore] = createStore({message: message([text('Looking.'), tool('a')], null),});- const view = render(() => <Message message={store.message} />);+ const view = render(() => <Message message={store.message} inFlight />);expect(view.queryByTestId('group')).toBeNull();const prose = view.getByTestId('text');@@ -227,6 +246,7 @@ describe('Message thought shimmer', () => {[thought('why this file'), tool('read'), tool('edit')],null)}+ inFlight/>));expect(view.getByTestId('thought').dataset.active).toBe('false');@@ -248,6 +268,7 @@ describe('Message thought shimmer', () => {],null)}+ inFlight/>));const rows = view.getAllByTestId('thought');@@ -258,6 +279,49 @@ describe('Message thought shimmer', () => {expect(rows.map((el) => el.dataset.active)).toEqual(['false', 'true']);});+ it('settles the trailing thought of an unclosed turn the session is not working on', () => {+ const view = render(() => (+ <Message+ message={message(+ [thought('already decided'), tool('read'), thought('cut off here')],+ null+ )}+ inFlight={false}+ />+ ));+ expect(+ view.getAllByTestId('thought').map((el) => el.dataset.active)+ ).toEqual(['false', 'false']);+ });++ it('moves the tail thought from Thinking to Thought when the turn settles', () => {+ const [state, setState] = createStore({ inFlight: true });+ const view = render(() => (+ <Message+ message={message([tool('read'), thought('wrapping up')], null)}+ inFlight={state.inFlight}+ />+ ));+ expect(view.getByTestId('thought').dataset.active).toBe('true');++ setState('inFlight', false);+ expect(view.getByTestId('thought').dataset.active).toBe('false');+ });++ it('drops the working row when the turn settles with a call still open', () => {+ const [state, setState] = createStore({ inFlight: true });+ const view = render(() => (+ <Message+ message={message([tool('read', { status: 'running' })], null)}+ inFlight={state.inFlight}+ />+ ));+ expect(view.getByTestId('working')).toBeTruthy();++ setState('inFlight', false);+ expect(view.queryByTestId('working')).toBeNull();+ });+it('settles a thought once prose follows it', () => {const view = render(() => (<Message@@ -265,6 +329,7 @@ describe('Message thought shimmer', () => {[thought('weighing'), text('Here is the answer.')],null)}+ inFlight/>));expect(view.getByTestId('thought').dataset.active).toBe('false');@@ -272,7 +337,7 @@ describe('Message thought shimmer', () => {it('settles every thought once the turn has a stop reason', () => {const view = render(() => (- <Message message={message([thought('done thinking')])} />+ <Message message={message([thought('done thinking')])} inFlight={false} />));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.tsxindex 4515e6d3a5..f3a03e7e8b 100644--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx@@ -3,6 +3,10 @@* has its own component under `parts/` (the chat block's handler-per-tool* split), user prompts get the chat block's bubble treatment, and the tail* thought shimmers while the turn is in flight.+ *+ * Whether the turn is in flight is the caller's to say (`state/live-turn`):+ * a message's own `stop` reads several settled turns as live, and a+ * transcript that let each message decide showed every one of them working.*/import { messageSendMotion } from '@core/util/message-send-motion';@@ -88,7 +92,10 @@ function ToolGroupPart(props: {const parts = () => props.message.parts.slice(props.start, props.end);const calls = () =>parts().filter((part): part is ToolUsePart => part.kind === 'tool_use');- const active = () => calls().some((call) => isToolActive(call.status));+ // A call the log left running in a finished turn is over (see+ // `settledToolStatus`), so a settled turn's run is never "Calling".+ const active = () =>+ props.inFlight && calls().some((call) => isToolActive(call.status));return (<Show when={calls().at(-1)}>@@ -171,9 +178,12 @@ function UserMessage(props: { message: FoldedMessage }) {);}-export function Message(props: { message: FoldedMessage }) {- const inFlight = () =>- props.message.author.kind === 'agent' && props.message.stop == null;+export function Message(props: {+ message: FoldedMessage;+ /** This is the running turn's reply, by the session's one `working` truth. */+ inFlight: boolean;+}) {+ const inFlight = () => props.inFlight;const failure = () =>props.message.stop?.kind === 'failed'? props.message.stop.messagediff --git a/apps/web/src/features/block-agent/component/Transcript.test.tsx b/apps/web/src/features/block-agent/component/Transcript.test.tsxindex 3169f5ee45..cffb384a78 100644--- a/apps/web/src/features/block-agent/component/Transcript.test.tsx+++ b/apps/web/src/features/block-agent/component/Transcript.test.tsx@@ -9,6 +9,7 @@ import { Transcript } from './Transcript';const session = vi.hoisted(() => ({sessionId: () => 'session',messages: () => [] as FoldedMessage[],+ working: (): boolean => false,quoteSelection: vi.fn(),touch: false,top: () => 40,@@ -31,8 +32,11 @@ vi.mock('@ui', async () => ({...(await import('@ui/components/Layer')),}));vi.mock('./AgentMessage', () => ({- Message: (props: { message: FoldedMessage }) => (- <span data-message={`${props.message.turn}:${props.message.author.kind}`}>+ Message: (props: { message: FoldedMessage; inFlight: boolean }) => (+ <span+ data-in-flight={String(props.inFlight)}+ data-message={`${props.message.turn}:${props.message.author.kind}`}+ >{JSON.stringify(props.message.parts)}</span>),@@ -93,6 +97,7 @@ beforeEach(() => {viewport = 400;rowHeight = 96;session.touch = false;+ session.working = () => false;session.bottom = () => 80;vi.stubGlobal('ResizeObserver',@@ -178,6 +183,45 @@ function mount(initial: FoldedMessage[]) {return { ...view, scroller, setMessages };}+describe('Transcript live turn', () => {+ const inFlight = (view: { container: HTMLElement }) =>+ [...view.container.querySelectorAll<HTMLElement>('[data-message]')].map(+ (el) => `${el.dataset.message}=${el.dataset.inFlight}`+ );++ it('marks only the newest turn live, however many messages lack a stop', async () => {+ // Every one of these reads `stop: null`; a superseded turn keeps it.+ const [working, setWorking] = createSignal(true);+ session.working = working;+ const view = mount([message(0), message(1), message(2)]);+ await settle();+ expect(inFlight(view)).toEqual([+ '0:agent=false',+ '1:agent=false',+ '2:agent=true',+ ]);++ // The runtime went away: the block stops working, and so does the tail.+ setWorking(false);+ await settle();+ expect(inFlight(view)).toEqual([+ '0:agent=false',+ '1:agent=false',+ '2:agent=false',+ ]);+ });++ it('marks nothing live while the newest turn is a prompt awaiting its reply', async () => {+ session.working = () => true;+ const view = mount([+ message(0),+ { ...message(1), author: { kind: 'user', userId: 'u' } } as FoldedMessage,+ ]);+ await settle();+ expect(inFlight(view)).toEqual(['0:agent=false', '1:user=false']);+ });+});+describe('Transcript with the shared TanStack ThreadList', () => {it('positions a cold-link target after the initial latest layout commits', async () => {session.messages = () =>diff --git a/apps/web/src/features/block-agent/component/Transcript.tsx b/apps/web/src/features/block-agent/component/Transcript.tsxindex 7acf6c6a87..e1ff4dd24e 100644--- a/apps/web/src/features/block-agent/component/Transcript.tsx+++ b/apps/web/src/features/block-agent/component/Transcript.tsx@@ -18,11 +18,16 @@ import {} from 'solid-js';import { useAgentSession } from '../context/AgentSessionContext';import type { AgentMessageTarget } from '../core/search-location';+import { isLiveTurn, liveTurnMessage } from '../state/live-turn';import { Message } from './AgentMessage';import { ReplyToSelection } from './ReplyToSelection';export function Transcript(props: { searchTarget?: AgentMessageTarget }) {- const { messages, quoteSelection, sessionId } = useAgentSession();+ const { messages, quoteSelection, sessionId, working } = useAgentSession();+ // At most one turn runs, and the block's `working` is the one word on+ // whether it does — so which message shimmers is decided here, once, not+ // by each message from its own `stop` (see `state/live-turn`).+ const liveTurn = () => liveTurnMessage(messages(), working());const initialTarget = props.searchTarget;const initialSessionId = sessionId();const splitPanel = useSplitPanel();@@ -114,7 +119,10 @@ export function Transcript(props: { searchTarget?: AgentMessageTarget }) {classList={{ 'bg-accent/10': highlightedId() === id }}data-search-target={highlightedId() === id ? 'true' : undefined}>- <Message message={message()} />+ <Message+ message={message()}+ inFlight={isLiveTurn(message(), liveTurn())}+ /></div>)}</Show>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.tsxindex cab71e4976..a1e25a2b72 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@@ -6,6 +6,7 @@ import type { MessagePart } from '@service-agent-fold/generated/types';import { render } from '@solidjs/testing-library';import type { JSX } from 'solid-js';import { describe, expect, it, vi } from 'vitest';+import type { ToolCallContext } from './shared';import { ToolCallPart } from './ToolCallPart';// The chat block's tool renderer is mocked to a marker: it transitively pulls@@ -58,15 +59,21 @@ vi.mock('./TextPart', () => ({// ToolCard pulls in kobalte + svg sprites and PierreDiff pulls in the diff// engine — the layer under test here is the per-kind card components and the// dispatcher's routing/common-derivation, which render for real.-vi.mock('../../ui', () => ({+vi.mock('../../ui', async () => ({+ ...(await import('../../ui/types')),ToolCard: (props: {title: JSX.Element;subtitle?: string;trailing?: JSX.Element;+ status: string;muted?: boolean;children?: JSX.Element;}) => (- <div data-muted={String(props.muted ?? false)} data-testid="tool-card">+ <div+ data-muted={String(props.muted ?? false)}+ data-status={props.status}+ data-testid="tool-card"+ ><span data-testid="title">{props.title}</span><span data-testid="subtitle">{props.subtitle}</span><span data-testid="trailing">{props.trailing}</span>@@ -101,6 +108,14 @@ vi.mock('../../ui', () => ({type ToolUsePart = Extract<MessagePart, { kind: 'tool_use' }>;+/** Where a part sits in a turn that is (or is not) still running. */+const context = (inFlight: boolean): ToolCallContext => ({+ sessionId: 'session',+ messageId: 'session:0:agent',+ partIndex: 0,+ inFlight,+});+function toolUse(detail: ToolUsePart['detail'],overrides?: Partial<Omit<ToolUsePart, 'name'>> & { name?: string }@@ -214,12 +229,24 @@ describe('ToolCallPart Macro tools', () => {);it('renders a known Macro tool with the chat component', () => {- const rendered = render(() => <ToolCallPart part={readContent()} />);+ const rendered = render(() => (+ <ToolCallPart part={readContent()} context={context(true)} />+ ));expect(rendered.getByTestId('macro-tool').textContent).toBe('ReadContent');expect(rendered.getByTestId('macro-tool').dataset.complete).toBe('false');expect(rendered.queryByTestId('tool-card')).toBeNull();});+ it('does not leave a call the turn cut off streaming in the chat component', () => {+ // The turn ended with this call still `running` in the log; it settles+ // and, with no response to show, keeps the labelled card.+ const rendered = render(() => (+ <ToolCallPart part={readContent()} context={context(false)} />+ ));+ expect(rendered.queryByTestId('macro-tool')).toBeNull();+ expect(rendered.getByTestId('tool-card').dataset.status).toBe('completed');+ });+it('passes the unwrapped output as the chat response once complete', () => {const rendered = render(() => (<ToolCallPart@@ -642,6 +669,71 @@ describe('ToolCallPart subagents', () => {});});+describe('ToolCallPart settling', () => {+ const running = () =>+ toolUse(+ { kind: 'terminal', command: 'cargo test', output: null, exitCode: null },+ { name: 'Bash', status: 'running' }+ );++ it('keeps a running call active while its turn is live', () => {+ const rendered = render(() => (+ <ToolCallPart part={running()} context={context(true)} />+ ));+ expect(rendered.getByTestId('tool-card').dataset.status).toBe('running');+ });++ it('settles a running call once its turn is over, without calling it failed', () => {+ const rendered = render(() => (+ <ToolCallPart part={running()} context={context(false)} />+ ));+ expect(rendered.getByTestId('tool-card').dataset.status).toBe('completed');+ expect(rendered.getByTestId('tool-card').dataset.muted).toBe('false');+ expect(rendered.getByTestId('trailing').textContent).toBe('');+ });++ it('settles a call with no turn to place it in', () => {+ const rendered = render(() => <ToolCallPart part={running()} />);+ expect(rendered.getByTestId('tool-card').dataset.status).toBe('completed');+ });++ it('settles a subagent and its nested children with the turn', () => {+ 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: [+ toolUse(+ {+ kind: 'terminal',+ command: 'python3 -c "print(5+5)"',+ output: null,+ exitCode: null,+ },+ { id: 'child', name: 'Bash', status: 'running' }+ ),+ { kind: 'thought', text: 'still weighing this' },+ ],+ result: null,+ },+ { name: 'Agent', status: 'running' }+ )}+ context={context(false)}+ />+ ));+ expect(+ rendered.getAllByTestId('tool-card').map((el) => el.dataset.status)+ ).toEqual(['completed', 'completed']);+ expect(rendered.getByTestId('thought').dataset.active).toBe('false');+ });+});+describe('ToolCallPart failed treatment', () => {it('fades the row and shows a quiet Failed trailing label', () => {const rendered = render(() => (diff --git a/apps/web/src/features/block-agent/component/parts/ToolCallPart.tsx b/apps/web/src/features/block-agent/component/parts/ToolCallPart.tsxindex ad07735fec..545cbdf235 100644--- a/apps/web/src/features/block-agent/component/parts/ToolCallPart.tsx+++ b/apps/web/src/features/block-agent/component/parts/ToolCallPart.tsx@@ -11,6 +11,7 @@import type { JSX } from 'solid-js';import { match } from 'ts-pattern';+import { settledToolStatus } from '../../ui';import { EditToolCall } from './EditToolCall';import { MacroToolCall } from './MacroToolCall';import { OutputToolCall } from './OutputToolCall';@@ -32,12 +33,17 @@ export function ToolCallPart(props: {context?: ToolCallContext;}): JSX.Element {const failed = () => props.part.status === 'failed';+ // A call the log still has running once its turn is over is not running+ // (see `settledToolStatus`). Without a turn to place it in there is no+ // live turn either, so it settles too.+ const status = () =>+ settledToolStatus(props.part.status, props.context?.inFlight ?? false);// The chat block's failed-tool treatment: the same row, faded, with a quiet// trailing label — not a separate error card.const common = (): ToolCallCommon => ({id: props.part.id,label: toolLabel(props.part.name),- status: props.part.status,+ status: status(),muted: failed(),trailing: failed() ? <span class="text-ink">Failed</span> : undefined,});diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsxindex d6345f3700..06b5c4f525 100644--- a/apps/web/src/features/block-agent/debug/Gallery.tsx+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx@@ -149,7 +149,7 @@ function ReplyToSelectionDemo() {Select any of the message text, then click Reply to this.</p><div ref={setContainer} class="relative">- <Message message={FIXTURE_MESSAGE} />+ <Message message={FIXTURE_MESSAGE} inFlight={false} /><ReplyToSelectioncontainer={container()}onReply={(text) => quoteInsert?.(text)}@@ -403,6 +403,71 @@ const FIXTURE_IN_FLIGHT: FoldedMessage = {],};+/**+ * A turn the log never closed: `stop: null`, a call still `running`, a+ * trailing thought. The fold leaves a superseded turn exactly like this, and+ * so does a runtime that died mid-turn. Whether it reads as live is the+ * transcript's call, not the message's.+ */+const FIXTURE_UNCLOSED: FoldedMessage = {+ agentSessionId: 'demo',+ requestId: null,+ turn: 2,+ author: { kind: 'agent' },+ stop: null,+ parts: [+ {+ kind: 'thought',+ text: 'The tests pin the snapshot, so the fixture has to change with the fold.',+ },+ {+ kind: 'tool_use',+ id: 'unclosed-read',+ name: { kind: 'native', name: 'Read' },+ status: 'completed',+ detail: { kind: 'read', paths: ['crates/agent_fold/src/domain/test.rs'] },+ },+ {+ kind: 'tool_use',+ id: 'unclosed-bash',+ name: { kind: 'native', name: 'Bash' },+ status: 'running',+ detail: {+ kind: 'terminal',+ command: 'cargo insta test -p agent_fold',+ output: null,+ exitCode: null,+ },+ },+ {+ kind: 'thought',+ text: 'Waiting on the snapshot run before touching the fixture.',+ },+ ],+};++/**+ * The same unclosed turn, live or settled at the flip of a switch: the+ * active ? done transition every shimmer in a message goes through when the+ * session's `working` drops, whatever the message's own `stop` says.+ */+function LiveTurnDemo() {+ const [inFlight, setInFlight] = createSignal(true);+ return (+ <div class="flex flex-col gap-3">+ <label class="flex items-center gap-2 text-xs text-ink-muted">+ <input+ type="checkbox"+ checked={inFlight()}+ onChange={(event) => setInFlight(event.currentTarget.checked)}+ />+ Turn in flight+ </label>+ <Message message={FIXTURE_UNCLOSED} inFlight={inFlight()} />+ </div>+ );+}+/*** 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.@@ -809,7 +874,7 @@ export default function AgentUiGallery() {</Item><Item label="AgentMessage (end-to-end)">- <Message message={FIXTURE_MESSAGE} />+ <Message message={FIXTURE_MESSAGE} inFlight={false} /></Item><Item label="AgentMessage (Cursor turn in flight)">@@ -817,7 +882,11 @@ export default function AgentUiGallery() {Earlier reasoning has settled. Only the trailing thought stillsays Thinking.</p>- <Message message={FIXTURE_IN_FLIGHT} />+ <Message message={FIXTURE_IN_FLIGHT} inFlight />+ </Item>++ <Item label="AgentMessage (turn settles)">+ <LiveTurnDemo /></Item></div></div>diff --git a/apps/web/src/features/block-agent/state/live-turn.test.ts b/apps/web/src/features/block-agent/state/live-turn.test.tsnew file mode 100644index 0000000000..4ff5bf3d8a--- /dev/null+++ b/apps/web/src/features/block-agent/state/live-turn.test.ts@@ -0,0 +1,76 @@+import type { FoldedMessage } from '@service-agent-fold/generated/types';+import { describe, expect, it } from 'vitest';+import { isLiveTurn, liveTurnMessage } from './live-turn';++const agent = (turn: number, stop: FoldedMessage['stop']): FoldedMessage => ({+ agentSessionId: 'session',+ requestId: null,+ turn,+ author: { kind: 'agent' },+ parts: [{ kind: 'thought', text: 'hm' }],+ stop,+});+const user = (turn: number): FoldedMessage => ({+ agentSessionId: 'session',+ requestId: null,+ turn,+ author: { kind: 'user', userId: 'u' },+ parts: [{ kind: 'text', text: 'do it' }],+ stop: null,+});+const control = (turn: number): FoldedMessage => ({+ agentSessionId: 'session',+ requestId: 'r',+ turn,+ author: { kind: 'user', userId: 'u' },+ parts: [+ {+ kind: 'control',+ control: { kind: 'set_model', model: 'x' },+ outcome: { kind: 'accepted' },+ },+ ],+ stop: null,+});++describe('liveTurnMessage', () => {+ it('names the newest agent message while the session is working', () => {+ const tail = agent(1, null);+ expect(+ liveTurnMessage([user(0), agent(0, null), user(1), tail], true)+ ).toBe(tail);+ });++ it('names nothing once the session has stopped working, whatever stop says', () => {+ // A superseded turn keeps `stop: null`; a dead runtime never stamps one.+ expect(liveTurnMessage([user(0), agent(0, null)], false)).toBeUndefined();+ });++ it('names nothing while a prompt is still awaiting its reply', () => {+ expect(+ liveTurnMessage([user(0), agent(0, { kind: 'end_turn' }), user(1)], true)+ ).toBeUndefined();+ });++ it('looks past a trailing control to the turn behind it', () => {+ const tail = agent(0, null);+ expect(liveTurnMessage([user(0), tail, control(1)], true)).toBe(tail);+ });++ it('is empty for an empty transcript', () => {+ expect(liveTurnMessage([], true)).toBeUndefined();+ });+});++describe('isLiveTurn', () => {+ it('matches by turn and author, not identity', () => {+ const live = agent(3, null);+ expect(isLiveTurn({ ...live }, live)).toBe(true);+ expect(isLiveTurn(agent(2, null), live)).toBe(false);+ expect(isLiveTurn(user(3), live)).toBe(false);+ });++ it('is false when nothing is live', () => {+ expect(isLiveTurn(agent(0, null), undefined)).toBe(false);+ });+});diff --git a/apps/web/src/features/block-agent/state/live-turn.ts b/apps/web/src/features/block-agent/state/live-turn.tsnew file mode 100644index 0000000000..97631b8295--- /dev/null+++ b/apps/web/src/features/block-agent/state/live-turn.ts@@ -0,0 +1,42 @@+/**+ * Which message, if any, is the turn the agent is working on right now.+ *+ * A message's own `stop` cannot answer this. The fold leaves a superseded+ * turn's agent message at `stop: null` for good (`agent_fold`'s `begin_turn`+ * closes it with no reason to stamp), and a runtime that dies mid-turn never+ * stamps the tail either. Read per message, both look like a live turn — so+ * a session that had been through a few of them showed a shimmering+ * "Thinking", a "Calling N tools", and a working row under every one of+ * them at once.+ *+ * The block already has one answer to "is the agent working" — the+ * session's `working` accessor — and at most one turn can be running. So+ * the live turn is decided once, here: the block is working, and this is+ * the newest turn's agent message. Everything else has settled, whatever+ * its `stop` says.+ */++import type { FoldedMessage } from '@service-agent-fold/generated/types';+import { lastTurnMessage } from './control-message';++/** The agent message of the running turn, or nothing when no turn runs. */+export function liveTurnMessage(+ messages: readonly FoldedMessage[],+ working: boolean+): FoldedMessage | undefined {+ if (!working) return undefined;+ const last = lastTurnMessage(messages);+ return last?.author.kind === 'agent' ? last : undefined;+}++/** Whether `message` is the live turn `live` names. */+export function isLiveTurn(+ message: FoldedMessage,+ live: FoldedMessage | undefined+): boolean {+ return (+ live !== undefined &&+ message.turn === live.turn &&+ message.author.kind === live.author.kind+ );+}diff --git a/apps/web/src/features/block-agent/ui/index.ts b/apps/web/src/features/block-agent/ui/index.tsindex 30bbcaeff2..3ee51bb16d 100644--- a/apps/web/src/features/block-agent/ui/index.ts+++ b/apps/web/src/features/block-agent/ui/index.ts@@ -54,6 +54,7 @@ export {type AnsweredQuestion,type FileDiff,isToolActive,+ settledToolStatus,type TodoItem,type ToolStatus,} from './types';diff --git a/apps/web/src/features/block-agent/ui/types.ts b/apps/web/src/features/block-agent/ui/types.tsindex 68dd29a191..ada4382640 100644--- a/apps/web/src/features/block-agent/ui/types.ts+++ b/apps/web/src/features/block-agent/ui/types.ts@@ -32,3 +32,20 @@ export interface AnsweredQuestion {export function isToolActive(status: ToolStatus): boolean {return status === 'pending' || status === 'running';}++/**+ * A call's status as its row should read it, given whether its turn is+ * still running.+ *+ * A call still `pending` or `running` once the turn is over was cut off —+ * the harness never said how it ended, and never will — so it is not active,+ * whatever the log last recorded. It settles as completed: the call happened+ * and is over, which is all the row claims. A failure it never reported is+ * not one to invent.+ */+export function settledToolStatus(+ status: ToolStatus,+ inFlight: boolean+): ToolStatus {+ return !inFlight && isToolActive(status) ? 'completed' : status;+}diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 53c16f7942..efbfa1d1fc 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -380,10 +380,14 @@ Opening a session or expanding a group should leave the app responsive, evenwhen 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.+of the turn the session is working on. 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. Only the newest turn can be live: once the composer stops showing the+agent as working, every Thinking label, **Calling N tools** row, shimmering+tool title, and working row settles — earlier turns never shimmer, even ones+the runtime cut off mid-call. At most one shimmering row is ever expected.+### Sharing a sessionIn the Agents workspace, saved sessions use the shared top-bar controls: session