Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/keep-answered-questions-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@truefoundry/trueforge-ui": patch
---

Keep answered user questions visible outside the collapsed Agent steps, without delaying the reply or repeating step counts.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { withSessionProps } from '../analytics/sessionProps.js';
import { useSlowActivityLabel } from '../hooks/useSlowActivityLabel.js';
import { useOptionalShellMode } from '../server/ShellModeContext.js';
import { useSlot } from '../theme/SlotsProvider.js';
import { computeAgentStepsSplit } from '../utils/computeAgentStepsSplit.js';
import { computeAgentStepsSplit, countAgentSteps } from '../utils/computeAgentStepsSplit.js';
import {
isParallelToolGroupPart,
parallelGroupKeyForPart,
readParallelToolGroups,
} from '../utils/parallelToolGroups.js';
import { loaderActivityKey, loaderActivityProgress, resolveLoaderLabel } from '../utils/resolveActivityLabel.js';
import { ASK_USER_TOOL_NAME, getAskUserAnswerResult } from '../utils/toolCallParsing.js';
import { AgentStepsContainer } from './AgentStepsContainer.js';
import { AssistantLeafPartContainer } from './AssistantLeafPartContainer.js';
import { AssistantTextContainer } from './AssistantTextContainer.js';
Expand Down Expand Up @@ -83,7 +84,13 @@ export function AssistantMessageContainer() {
isCancelled && !isSessionReplay && cancellationReason === TURN_CANCELLATION_REASON.CANCELLED_FOR_NEXT_TURN;
const cancelledBanner = isCancelled && !hideCancelled ? cancellationLabel(cancellationReason) : undefined;

const { cutIndex, hasFinal, toolCount, thinkingCount } = computeAgentStepsSplit(parts, isMessageRunning);
const stepParts = parts.map(p => ({
type: p.type,
text: p.type === 'text' ? p.text : undefined,
name: p.type === 'data' ? p.name : undefined,
hidden: isAnsweredAskUser(p),
}));
const { cutIndex, hasFinal } = computeAgentStepsSplit(stepParts, isMessageRunning);

// Built-in indicator modes hide the loader while reasoning streams; we want it there too.
// Hide when resume is unavailable (message stays "running" but no events arrive) or the
Expand All @@ -105,6 +112,8 @@ export function AssistantMessageContainer() {
}

if (index < cutIndex) {
// Answered user questions stay visible: render them outside the collapsible Agent steps.
if (isAnsweredAskUser(part)) return null;
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Held-back reply splits into empty accordion

Medium Severity

Ungrouping an answered question splits Agent steps, so while the 500-character holdback is still active the trailing reply is grouped into a new accordion after the question. Earlier tools still count as steps before the cut, so cutIndex stays at the end of the message and that second accordion can show 0 tool calls with the streaming text muted inside it until 500 characters arrive or the turn finishes.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4820108. Configure here.

if (part.type === 'reasoning') {
return ['group-agentSteps', 'group-reasoning'];
}
Expand Down Expand Up @@ -136,12 +145,14 @@ export function AssistantMessageContainer() {
<MessagePrimitive.GroupedParts groupBy={groupBy} indicator="never">
{({ part, children }) => {
switch (part.type) {
case 'group-agentSteps':
case 'group-agentSteps': {
const { toolCount, thinkingCount } = countAgentSteps(part.indices.flatMap(i => stepParts[i] ?? []));
return (
<AgentStepsContainer toolCount={toolCount} thinkingCount={thinkingCount} hasFinal={hasFinal}>
{children}
</AgentStepsContainer>
);
}
case 'group-reasoning':
return <ReasoningContainer group={part as ThreadGroupPart} />;
case 'text': {
Expand Down Expand Up @@ -174,3 +185,9 @@ export function AssistantMessageContainer() {
</MessagePrimitive.Root>
);
}

function isAnsweredAskUser(part: PartState): boolean {
return (
part.type === 'tool-call' && part.toolName === ASK_USER_TOOL_NAME && getAskUserAnswerResult(part.result) != null
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
]}
onSubmit={() => {}}
readOnly
className="mb-2"
/>
);
}
Expand Down
35 changes: 18 additions & 17 deletions packages/trueforge-ui/src/utils/computeAgentStepsSplit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ export type AgentStepPart = {
type: PartState['type'];
text?: string;
name?: string;
/** Rendered outside the Agent steps group (e.g. answered user questions); not counted. */
hidden?: boolean;
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
};

function isAgentStepPart(part: AgentStepPart): boolean {
if (part.hidden) return false;
return (
part.type === 'tool-call' ||
part.type === 'reasoning' ||
Expand All @@ -18,8 +21,21 @@ function isAgentStepPart(part: AgentStepPart): boolean {
export interface AgentStepsSplitResult {
cutIndex: number;
hasFinal: boolean;
toolCount: number;
thinkingCount: number;
}

/** Counts per accordion, so groups split by a visible part do not repeat message-wide totals. */
export function countAgentSteps(parts: readonly AgentStepPart[]): { toolCount: number; thinkingCount: number } {
let toolCount = 0;
let thinkingCount = 0;
for (const part of parts) {
if (part.hidden) continue;
if (part.type === 'tool-call') {
toolCount++;
} else if (part.type === 'reasoning') {
thinkingCount++;
}
}
return { toolCount, thinkingCount };
}

export function computeAgentStepsSplit(parts: readonly AgentStepPart[], isRunning: boolean): AgentStepsSplitResult {
Expand Down Expand Up @@ -57,23 +73,8 @@ export function computeAgentStepsSplit(parts: readonly AgentStepPart[], isRunnin

const actualCutIndex = finalConfirmed ? cutIdx : parts.length;

let toolCount = 0;
let thinkingCount = 0;
for (let i = 0; i < actualCutIndex; i++) {
const part = parts[i];
if (!part) continue;

if (part.type === 'tool-call') {
toolCount++;
} else if (part.type === 'reasoning') {
thinkingCount++;
}
}

return {
cutIndex: actualCutIndex,
hasFinal: finalConfirmed,
toolCount,
thinkingCount,
};
}
19 changes: 16 additions & 3 deletions packages/trueforge-ui/test/utils/computeAgentStepsSplit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';

import { computeAgentStepsSplit, type AgentStepPart } from '@/index.js';
import { countAgentSteps } from '@/utils/computeAgentStepsSplit.js';

function text(content: string): AgentStepPart {
return { type: 'text', text: content };
Expand All @@ -24,7 +25,6 @@ describe('computeAgentStepsSplit', () => {
const result = computeAgentStepsSplit(parts, true);
expect(result.cutIndex).toBe(0);
expect(result.hasFinal).toBe(true);
expect(result.toolCount).toBe(0);
});

it('holds back short trailing text while running when tools precede it', () => {
Expand All @@ -39,8 +39,7 @@ describe('computeAgentStepsSplit', () => {
const result = computeAgentStepsSplit(parts, true);
expect(result.hasFinal).toBe(true);
expect(result.cutIndex).toBe(2);
expect(result.toolCount).toBe(1);
expect(result.thinkingCount).toBe(1);
expect(countAgentSteps(parts.slice(0, result.cutIndex))).toEqual({ toolCount: 1, thinkingCount: 1 });
});

it('confirms final when not running', () => {
Expand All @@ -56,4 +55,18 @@ describe('computeAgentStepsSplit', () => {
expect(result.hasFinal).toBe(false);
expect(result.cutIndex).toBe(parts.length);
});

it('does not hold back text after an answered question that is the only tool call', () => {
const parts = [{ ...tool(), hidden: true }, text('hi')];
const result = computeAgentStepsSplit(parts, true);
expect(result.hasFinal).toBe(true);
expect(result.cutIndex).toBe(1);
});

it('excludes hidden parts from counts', () => {
expect(countAgentSteps([tool(), { ...tool(), hidden: true }, reasoning()])).toEqual({
toolCount: 1,
thinkingCount: 1,
});
});
});
Loading