Skip to content

The agent that grows with you

fix: hydrate canonical Ink history independently of live events

Teknium971ff7f362b6
diff --git a/ui-tui/src/__tests__/canonicalHistory.test.ts b/ui-tui/src/__tests__/canonicalHistory.test.ts
new file mode 100644
index 00000000000..1fe8b525e21
--- /dev/null
+++ b/ui-tui/src/__tests__/canonicalHistory.test.ts
@@ -0,0 +1,23 @@
+import { expect, it } from 'vitest'
+import { canonicalResult } from '../canonicalGateway.js'
+import { toTranscriptMessages } from '../domain/messages.js'
+
+it('hydrates canonical persisted replies through the same transcript path as resumed sessions', () => {
+ const messages = [
+ { role: 'user', content: 'Pick a color', api_content: 'private model-only context' },
+ { role: 'assistant', content: '', tool_calls: [{ function: { name: 'clarify' } }] },
+ { role: 'tool', content: 'private tool result', tool_name: 'clarify' },
+ { role: 'assistant', content: 'CLARIFY_FINISHED', timestamp: 123 },
+ { role: 'session_meta', content: null },
+ ]
+ for (const method of ['session.create', 'session.resume', 'session.activate']) {
+ const snapshot = canonicalResult(method, { messages, authority_epoch: 1, execution_generation: 2 })
+ const rendered = toTranscriptMessages(snapshot.messages)
+ expect(rendered.filter(row => row.role === 'user').map(row => row.text)).toEqual(['Pick a color'])
+ expect(rendered.filter(row => row.role === 'assistant')).toEqual([
+ { role: 'assistant', text: 'CLARIFY_FINISHED', createdAt: 123, tools: expect.any(Array) },
+ ])
+ expect(JSON.stringify(rendered)).not.toContain('private')
+ expect(messages[0]).not.toHaveProperty('text')
+ }
+})
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index bce5df1c23e..b683c836b58 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -35,7 +35,14 @@ export function canonicalResult(method: string, value: any, request: Record<stri
return { ...value, input_id: request.input_id, target_profile_home: value.ref.profile_id, target_session_id: value.ref.session_id }
}
if (['session.create', 'session.resume', 'session.activate'].includes(method)) {
- return { ...value, info: { ...value.info, stored_session_id: value.stored_session_id,
+ // Canonical snapshots contain stored conversation rows (`content`), not
+ // the legacy TUI's display rows (`text`). Without this translation only
+ // live events render, making reconnect depend on catching the final delta.
+ const messages = Array.isArray(value.messages) ? value.messages.map((row: any) =>
+ row && typeof row === 'object'
+ ? { ...row, text: row.content, name: row.tool_name }
+ : row) : value.messages
+ return { ...value, messages, info: { ...value.info, stored_session_id: value.stored_session_id,
execution_epoch: String(value.authority_epoch), execution_generation: value.execution_generation,
running: value.running } }
}