Skip to content

The agent that grows with you

fix(desktop): an open chat's cwd change maps onto the owner's workspace operation

Tekniumdbc538547fcd
diff --git a/apps/desktop/src/api/canonical-producer-contract.test.ts b/apps/desktop/src/api/canonical-producer-contract.test.ts
index 7c5da20fa8d..e9d992b21db 100644
--- a/apps/desktop/src/api/canonical-producer-contract.test.ts
+++ b/apps/desktop/src/api/canonical-producer-contract.test.ts
@@ -184,6 +184,12 @@ const SITES: Array<[string, string, Record<string, unknown>, string[] | RegExp]>
{ cwd: '/repo', session_key: 's' },
['session.mutate']
],
+ [
+ 'use-cwd-actions.ts changeSessionCwd (composer folder picker on an open chat)',
+ 'session.cwd.set',
+ { session_id: 's', cwd: '/repo' },
+ ['session.mutate']
+ ],
[
'connector-tool.tsx in-chat connect',
'connectors.connect',
@@ -225,8 +231,9 @@ test.each(SITES)('%s: the canonical frame fits the generated contract', async (_
const address = server.address() as { port: number }
await client.connect(`ws://127.0.0.1:${address.port}/api/ws?native_dial=fixture&ticket=one-use`)
- // Typed /reasoning and the keybind act on the open (attached) session, as the model picker does.
- if (method === 'config.set' && params.key === 'reasoning') {
+ // Typed /reasoning, the keybind and the composer's folder picker act on the open (attached)
+ // session, as the model picker does.
+ if ((method === 'config.set' && params.key === 'reasoning') || method === 'session.cwd.set') {
await client.request('session.resume', { session_id: 's' })
}
diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.ts
index 1af3d725bdb..1ad5920d873 100644
--- a/apps/desktop/src/api/canonical-protocol.ts
+++ b/apps/desktop/src/api/canonical-protocol.ts
@@ -176,9 +176,14 @@ function policyEdit(method: string, params: Record<string, unknown>): { session:
return { session: params.session_id, operation: 'reasoning', payload: { effort } }
}
+ // The composer's folder picker on an open chat (main's session.cwd.set) is the same re-home.
+ if (method === 'session.cwd.set') { return { session: params.session_id, operation: 'workspace', payload: { cwd: params.cwd } } }
+
return method === 'session.workspace.move' ? { session: params.session_key, operation: 'workspace', payload: { cwd: params.cwd } } : null
}
+// Desktop methods that become `session.mutate` once prepareMutation chose an operation.
+const POLICY_EDIT_METHODS = new Set(['slash.exec', 'config.set', 'session.workspace.move', 'session.cwd.set'])
const BRANCH_METHODS = new Set(['session.branch', 'session.branch_stored', 'session.branch_whole'])
// Value-setting mutations: re-applying one is harmless, so a later acknowledged edit retires it.
const VALUE_OPERATIONS = new Set(['rename', 'archive', 'model', 'reasoning', 'workspace'])
@@ -230,7 +235,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' || method === 'config.set' || method === 'session.workspace.move') && typeof prepared.operation === 'string' ? 'session.mutate' : method
+ return POLICY_EDIT_METHODS.has(method) && typeof prepared.operation === 'string' ? 'session.mutate' : method
}
private retainedMutation(sessionId: unknown, profile: unknown, operation: string, payload: Record<string, unknown>, withGeneration: boolean): Record<string, unknown> {
@@ -474,7 +479,7 @@ export class CanonicalDesktopProtocol {
result(method: string, params: Record<string, unknown>, value: any): any {
if (!value || typeof value !== 'object') { return value }
- const mutation = MUTATION_METHODS.has(method) || ((method === 'slash.exec' || method === 'config.set' || method === 'session.workspace.move') && typeof params.operation === 'string')
+ const mutation = MUTATION_METHODS.has(method) || (POLICY_EDIT_METHODS.has(method) && typeof params.operation === 'string')
this.adoptRevision(params, value, mutation)
if (mutation) { return this.mutationReceipt(method, params, value) }
diff --git a/apps/desktop/src/app/session/hooks/use-cwd-actions.ts b/apps/desktop/src/app/session/hooks/use-cwd-actions.ts
index 1474cf192d7..1dc3c353466 100644
--- a/apps/desktop/src/app/session/hooks/use-cwd-actions.ts
+++ b/apps/desktop/src/app/session/hooks/use-cwd-actions.ts
@@ -1,6 +1,6 @@
import { type MutableRefObject, useCallback } from 'react'
-import { useI18n } from '@/i18n'
+import { translateNow, useI18n } from '@/i18n'
import { notify, notifyError } from '@/store/notifications'
import {
$currentCwd,
@@ -107,7 +107,9 @@ export function useCwdActions({ activeSessionIdRef, onSessionRuntimeInfo, reques
const message = err instanceof Error ? err.message : String(err)
if (!message.includes('unknown method')) {
- notifyError(err, copy.cwdChangeFailed)
+ // The shared owner refuses a re-home while a turn runs (its frozen policy would change under it).
+ const busy = (err as { data?: { reason?: string } })?.data?.reason === 'session_busy'
+ notifyError(busy ? new Error(translateNow('sidebar.projects.moveBusy')) : err, copy.cwdChangeFailed)
return
}