Skip to content

The agent that grows with you

fix(desktop): route the composer model picker to the canonical model mutation

Teknium276c7d7bca52
diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.ts
index 8e7e63f53d4..d94f89f1242 100644
--- a/apps/desktop/src/api/canonical-protocol.test.ts
+++ b/apps/desktop/src/api/canonical-protocol.test.ts
@@ -209,3 +209,20 @@ test('the dedicated compress action becomes a fenced canonical mutation and sett
expect(await protocol.settle('session.title', { session_id: 's' }, untouched, fakeRequest)).toBe(untouched)
expect(calls).toHaveLength(1)
})
+
+test('the composer model picker travels as the canonical model mutation, not an unsupported config.set', () => {
+ const protocol = new CanonicalDesktopProtocol()
+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 3, execution_generation: 2 })
+
+ for (const value of ['gpt-5 --provider openrouter', 'gpt-5 --provider openrouter --session']) {
+ const pick = protocol.prepare('config.set', { session_id: 's', key: 'model', value })
+ expect(protocol.wire('config.set', pick)).toBe('session.mutate')
+ expect(pick).toEqual({ session_id: 's', request_id: expect.any(String), expected_revision: 3, expected_generation: 2, operation: 'model', payload: { model: 'gpt-5', provider: 'openrouter' } })
+ expect(protocol.result('config.set', pick, { session_id: 's', revision: 4, operation: 'model', model: 'gpt-5', provider: 'openrouter' })).toMatchObject({ ok: true, model: 'gpt-5' })
+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 3, execution_generation: 2 })
+ }
+
+ // Other preferences, and model flags the mutation has no field for, keep their own route.
+ expect(protocol.wire('config.set', protocol.prepare('config.set', { session_id: 's', key: 'busy', value: 'queue' }))).toBe('config.set')
+ expect(protocol.wire('config.set', protocol.prepare('config.set', { session_id: 's', key: 'model', value: 'gpt-5 --global' }))).toBe('config.set')
+})
diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.ts
index 6e7ecc77b87..d969505e866 100644
--- a/apps/desktop/src/api/canonical-protocol.ts
+++ b/apps/desktop/src/api/canonical-protocol.ts
@@ -38,6 +38,22 @@ export function slashMutation(command: string): { operation: string; payload: Re
return { operation: name, payload: arg ? { [field]: arg } : {} }
}
+// The composer picker's `config.set key=model` value: `<model> --provider <id> [--session]`. The
+// canonical model mutation is always session-scoped policy (the authority never rewrites
+// config.yaml from it), so `--session` carries no extra meaning; any other flag has no canonical
+// field and stays on config.set for the authority to refuse explicitly.
+export function pickerModelMutation(value: unknown): { model: string; provider: string } | null {
+ const [model, ...flags] = String(value ?? '').trim().split(/\s+/)
+ const sessionOnly = flags.at(-1) === '--session'
+ const rest = sessionOnly ? flags.slice(0, -1) : flags
+
+ if (!model || model.startsWith('-') || rest.length !== 2 || rest[0] !== '--provider' || !rest[1] || rest[1].startsWith('-')) {
+ return null
+ }
+
+ return { model, provider: rest[1] }
+}
+
function mutationSummary(operation: string, value: Record<string, unknown>): string {
if (operation === 'model') { return `model: ${value.model}${value.provider ? ` (${value.provider})` : ''}` }
@@ -93,7 +109,7 @@ export class CanonicalDesktopProtocol {
// rebinds the live event transport and returns the same snapshot shape.
if (method === 'session.activate') { return 'session.resume' }
- return method === 'slash.exec' && typeof prepared.operation === 'string' ? 'session.mutate' : method
+ return (method === 'slash.exec' || method === 'config.set') && typeof prepared.operation === 'string' ? 'session.mutate' : method
}
private retainedMutation(sessionId: unknown, profile: unknown, operation: string, payload: Record<string, unknown>, withGeneration: boolean): Record<string, unknown> {
@@ -179,6 +195,12 @@ export class CanonicalDesktopProtocol {
return this.retainedMutation(parent, params.profile, 'branch', payload, true)
}
+ if (method === 'config.set' && params.key === 'model') {
+ const pick = pickerModelMutation(params.value)
+
+ if (pick) { return this.retainedMutation(params.session_id, params.profile, 'model', pick, true) }
+ }
+
if (method === 'slash.exec') {
const directive = slashMutation(String(params.command ?? ''))
@@ -277,7 +299,7 @@ export class CanonicalDesktopProtocol {
this.revisions.set(canonicalSessionKey(value.session_id, params.profile), value.revision)
}
- if (MUTATION_METHODS.has(method) || (method === 'slash.exec' && typeof params.operation === 'string')) {
+ if (MUTATION_METHODS.has(method) || ((method === 'slash.exec' || method === 'config.set') && typeof params.operation === 'string')) {
return this.mutationReceipt(method, params, value)
}