The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): /compress reaches the canonical authority and repaints the transcript
teknium1a233addd2445
diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.tsindex 77fe8a0804d..225928a7ee7 100644--- a/apps/desktop/src/api/canonical-protocol.test.ts+++ b/apps/desktop/src/api/canonical-protocol.test.ts@@ -114,3 +114,36 @@ test('acknowledging a turn lost across a restart presents the unknown row\'s ownprotocol.event({ type: 'session.info', session_id: 's', payload: { pending: [{ admission_id: 'next', status: 'started', execution_generation: 10, text: 'NEXT' }], execution_generation: 10 } })expect(() => protocol.prepare('prompt.resolve_unknown', { session_id: 's', admission_id: 'lost' })).toThrow('unknown')})++test('the dedicated compress action becomes a fenced canonical mutation and settles with the resumed transcript', async () => {+ const protocol = new CanonicalDesktopProtocol()+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 4, execution_generation: 9 })++ const prepared = protocol.prepare('session.compress', { session_id: 's', focus_topic: 'billing' })+ expect(prepared).toEqual({ session_id: 's', request_id: expect.any(String), expected_revision: 4, expected_generation: 9, operation: 'compress', payload: { focus: 'billing' } })+ expect(protocol.prepare('session.compress', { session_id: 's' }).payload).toEqual({})+ expect(protocol.wire('session.compress', prepared)).toBe('session.mutate')+ expect(() => protocol.result('session.compress', prepared, { session_id: 'other', revision: 5, operation: 'compress' })).toThrow('destination')++ const calls: Array<[string, Record<string, unknown>]> = []+ const resumed = { session_id: 's', messages: [{ role: 'assistant', content: 'summary' }], info: { title: 'T' } }++ const fakeRequest = async (method: string, params: Record<string, unknown>) => { calls.push([method, params]);++ return resumed }++ const receipt = protocol.result('session.compress', prepared, { session_id: 's', revision: 5, operation: 'compress', target_session_id: 's', message_count: 3 })+ const settled = await protocol.settle('session.compress', prepared, receipt, fakeRequest)++ expect(settled.messages).toEqual(resumed.messages)+ expect(settled.info).toEqual(resumed.info)+ expect(settled.host_ack.output).toContain('3')+ expect(calls).toEqual([['session.resume', { session_id: 's' }]])+ // Acknowledged: the next compress presents the refreshed revision under a new request id.+ expect(protocol.prepare('session.compress', { session_id: 's', focus_topic: 'billing' })).toMatchObject({ expected_revision: 5 })+ expect(protocol.prepare('session.compress', { session_id: 's', focus_topic: 'billing' }).request_id).not.toBe(prepared.request_id)++ const untouched = { session_id: 's', ok: true }+ expect(await protocol.settle('session.title', { session_id: 's' }, untouched, fakeRequest)).toBe(untouched)+ expect(calls).toHaveLength(1)+})diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.tsindex 8f9da66cbda..9e3fc82ffdc 100644--- a/apps/desktop/src/api/canonical-protocol.ts+++ b/apps/desktop/src/api/canonical-protocol.ts@@ -35,6 +35,9 @@ function mutationSummary(operation: string, value: Record<string, unknown>): strreturn `${operation}: ok`}+// Explicit desktop methods that travel as canonical `session.mutate`.+const MUTATION_METHODS = new Set(['session.title', 'session.archive', 'session.branch', 'session.compress'])+export class CanonicalDesktopProtocol {private creates = new Map<string, string>()private revisions = new Map<string, number>()@@ -56,9 +59,10 @@ export class CanonicalDesktopProtocol {// Wire method for a prepared request: composer metadata, branch and the// typed `/model <name>` / `/branch [title]` / `/compress [focus]` directives- // all travel as canonical `session.mutate`; everything else keeps its name.+ // and the dedicated compress action all travel as canonical `session.mutate`;+ // everything else keeps its name.wire(method: string, prepared: Record<string, unknown> = {}): string {- if (method === 'session.title' || method === 'session.archive' || method === 'session.branch') { return 'session.mutate' }+ if (MUTATION_METHODS.has(method)) { return 'session.mutate' }return method === 'slash.exec' && typeof prepared.operation === 'string' ? 'session.mutate' : method}@@ -88,7 +92,13 @@ export class CanonicalDesktopProtocol {if (field) { return this.retainedMutation(params.session_id, field === 'title' ? 'rename' : 'archive', { [field]: params[field] }, false) }- if (method === 'session.branch') { return this.retainedMutation(params.session_id, 'branch', {}, true) }+ // Branch and compress fence the execution generation like the slash directives.+ const fenced = ({+ 'session.branch': () => ({ operation: 'branch', payload: {} }),+ 'session.compress': () => ({ operation: 'compress', payload: params.focus_topic ? { focus: String(params.focus_topic) } : {} })+ } as Record<string, () => { operation: string; payload: Record<string, unknown> }>)[method]?.()++ if (fenced) { return this.retainedMutation(params.session_id, fenced.operation, fenced.payload, true) }if (method === 'slash.exec') {const directive = slashMutation(String(params.command ?? ''))@@ -190,7 +200,7 @@ export class CanonicalDesktopProtocol {this.revisions.set(value.session_id, value.revision)}- if (method === 'session.title' || method === 'session.archive' || method === 'session.branch' || (method === 'slash.exec' && typeof params.operation === 'string')) {+ if (MUTATION_METHODS.has(method) || (method === 'slash.exec' && typeof params.operation === 'string')) {if (value.session_id !== params.session_id) { throw new Error('Metadata receipt destination mismatch') }for (const [key, mutation] of this.mutations) { if (mutation.request_id === params.request_id) { this.mutations.delete(key) } }@@ -246,4 +256,14 @@ export class CanonicalDesktopProtocol {return value}++ // The canonical compress receipt carries counts, not the retained transcript;+ // the compress action repaints only from `messages`, so resume the session+ // through the normal request path (which also re-primes revision/generation).+ async settle(method: string, params: Record<string, unknown>, value: any, request: (method: string, params: Record<string, unknown>) => Promise<any>): Promise<any> {+ if (method !== 'session.compress') { return value }+ const resumed = await request('session.resume', { session_id: params.session_id })++ return { ...value, messages: resumed.messages, info: resumed.info, host_ack: { output: `compressed context: ${value.message_count} messages retained` } }+ }}diff --git a/apps/desktop/src/api/client.ts b/apps/desktop/src/api/client.tsindex 9a4993d5d7e..10bacb1502c 100644--- a/apps/desktop/src/api/client.ts+++ b/apps/desktop/src/api/client.ts@@ -54,7 +54,7 @@ export class HermesGateway extends JsonRpcGatewayClient {try {const result = await super.request<T>(wireMethod, prepared, timeoutMs, signal)- return this.protocol.result(method, prepared, result) as T+ return this.protocol.settle(method, prepared, this.protocol.result(method, prepared, result), (m, p) => this.request(m, p)) as T} catch (error) {this.protocol.failure(prepared, error)throw error