Skip to content

The agent that grows with you

fix(desktop): do not paint opaque reasoning carriers as Thought

686f6c617418dcb23be1
diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.ts
index eca3421954c..5d37f0d7c18 100644
--- a/apps/desktop/src/lib/chat-messages.test.ts
+++ b/apps/desktop/src/lib/chat-messages.test.ts
@@ -57,6 +57,63 @@ describe('withUniqueToolCallIdsWithinMessage', () => {
})
describe('toChatMessages', () => {
+ it('does not render an opaque native_assistant reasoning_details carrier as Thought (#126588)', () => {
+ const carrier = JSON.stringify([
+ {
+ type: 'claude-subscription-directsdk-experimental.native_assistant',
+ version: 1,
+ messages: [
+ {
+ content: [
+ { type: 'thinking', thinking: '', signature: 'sigabc' },
+ { type: 'text', text: 'Public answer' }
+ ]
+ }
+ ],
+ projection: { content: 'Public answer', tool_calls: [] }
+ }
+ ])
+
+ const [message] = toChatMessages([
+ {
+ role: 'assistant',
+ content: 'Public answer',
+ reasoning: null,
+ reasoning_content: null,
+ reasoning_details: carrier,
+ timestamp: 1
+ }
+ ])
+
+ expect(message.parts.filter(part => part.type === 'reasoning')).toHaveLength(0)
+ expect(chatMessageText(message)).toContain('Public answer')
+ const rendered = JSON.stringify(message.parts)
+ expect(rendered).not.toContain('sigabc')
+ expect(rendered).not.toContain('native_assistant')
+ })
+
+ it('shows readable reasoning text from a serialized reasoning_details envelope', () => {
+ const [message] = toChatMessages([
+ {
+ role: 'assistant',
+ content: 'Answer',
+ reasoning_details: JSON.stringify([
+ { type: 'reasoning.summary', summary: 'Checked the lock.' },
+ {
+ type: 'demo.native_assistant',
+ messages: [{ content: [{ type: 'thinking', thinking: 'Nested thought.', signature: 'sigxyz' }] }]
+ }
+ ]),
+ timestamp: 1
+ }
+ ])
+
+ const reasoning = message.parts.find(part => part.type === 'reasoning')
+
+ expect(reasoning && 'text' in reasoning ? reasoning.text : '').toBe('Checked the lock.\n\nNested thought.')
+ expect(JSON.stringify(message.parts)).not.toContain('sigxyz')
+ })
+
it('rebuilds the full command from a gateway tool row carrying args', () => {
// Gateway watch-window hydration projects tool rows as
// {role:'tool', name, context, args?}. `context` is an 80-char preview;
diff --git a/apps/desktop/src/lib/chat-messages/parts.ts b/apps/desktop/src/lib/chat-messages/parts.ts
index 9f6d595b930..c2214029faa 100644
--- a/apps/desktop/src/lib/chat-messages/parts.ts
+++ b/apps/desktop/src/lib/chat-messages/parts.ts
@@ -32,20 +32,64 @@ export function reasoningTextFromDetails(details: unknown): string {
const text: string[] = []
+ const push = (value: unknown) => {
+ if (typeof value !== 'string') return
+
+ const prose = value.trim()
+
+ if (prose && !text.includes(prose)) text.push(prose)
+ }
+
+ // Nested carrier internals: only genuinely readable reasoning kinds. A
+ // native `.native_assistant` carrier wraps signed thinking plus the public
+ // answer inside `messages[].content[]`; its `text` blocks are the answer, not
+ // reasoning, and signatures/projections/data are opaque replay fields.
+ const walkNested = (node: unknown): void => {
+ if (Array.isArray(node)) {
+ for (const item of node) walkNested(item)
+ return
+ }
+
+ if (!node || typeof node !== 'object') return
+
+ const record = node as Record<string, unknown>
+ const kind = typeof record.type === 'string' ? record.type : ''
+
+ if (kind === 'reasoning.summary') {
+ push(record.summary)
+ } else if (kind === 'reasoning.text') {
+ push(record.text)
+ } else if (typeof record.thinking === 'string') {
+ push(record.thinking)
+ }
+
+ for (const [key, value] of Object.entries(record)) {
+ if (key === 'signature' || key === 'projection' || key === 'data' || key === 'type') continue
+
+ if (value && typeof value === 'object') walkNested(value)
+ }
+ }
+
for (const block of Array.isArray(blocks) ? blocks : [blocks]) {
if (typeof block === 'string') {
- if (block.trim()) text.push(block)
+ push(block)
continue
}
if (!block || typeof block !== 'object') continue
+ // Top-level blocks are provider reasoning-detail entries; recognized
+ // prose fields (summary, thinking, content, text) are display text.
const record = block as Record<string, unknown>
const value = [record.summary, record.thinking, record.content, record.text].find(
candidate => typeof candidate === 'string' && candidate.trim()
)
- if (typeof value === 'string') text.push(value)
+ push(value)
+
+ // A provider-native replay carrier keeps readable reasoning only in
+ // nested blocks, never in its own opaque fields.
+ walkNested(block)
}
return text.join('\n\n').trim()