The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope the remembered local workspace cwd per profile
Brooklyn Nicholson5d4d8aa6d36e
diff --git a/apps/desktop/src/store/session.test.ts b/apps/desktop/src/store/session.test.tsindex cf9d4c9aa13..4ff61f34649 100644--- a/apps/desktop/src/store/session.test.ts+++ b/apps/desktop/src/store/session.test.ts@@ -1057,6 +1057,8 @@ describe('workspaceCwdForNewSession', () => {$currentCwd.set('')$activeSessionId.set(null)window.localStorage.removeItem('hermes.desktop.workspace-cwd')+ window.localStorage.removeItem('hermes.desktop.workspace-cwd.profile.profile-a')+ window.localStorage.removeItem('hermes.desktop.workspace-cwd.profile.profile-b')window.localStorage.removeItem('hermes.desktop.workspace-cwd.remote.http%3A%2F%2Fbackend-a.default')window.localStorage.removeItem('hermes.desktop.workspace-cwd.remote.http%3A%2F%2Fbackend-b.default')delete (window as { hermesDesktop?: unknown }).hermesDesktop@@ -1204,6 +1206,41 @@ describe('workspaceCwdForNewSession', () => {expect($currentCwd.get()).toBe('')})+ it('scopes the local workspace memory per profile, keeping the bare key for default (#96834)', () => {+ $connection.set({ baseUrl: '', mode: 'local', profile: 'default' } as never)+ setCurrentCwd('/home/user/default-project')+ expect(window.localStorage.getItem('hermes.desktop.workspace-cwd')).toBe('/home/user/default-project')++ $connection.set({ baseUrl: '', mode: 'local', profile: 'profile-a' } as never)+ expect(getRememberedWorkspaceCwd()).toBe('')+ setCurrentCwd('/home/user/project-a')+ expect(window.localStorage.getItem('hermes.desktop.workspace-cwd.profile.profile-a')).toBe('/home/user/project-a')++ $connection.set({ baseUrl: '', mode: 'local', profile: 'profile-b' } as never)+ expect(getRememberedWorkspaceCwd()).toBe('')++ $connection.set({ baseUrl: '', mode: 'local', profile: 'default' } as never)+ expect(getRememberedWorkspaceCwd()).toBe('/home/user/default-project')+ })++ it('switching to a local profile with no memory clears the outgoing profile folder (#96834)', async () => {+ ;(window as { hermesDesktop?: unknown }).hermesDesktop = {+ sanitizeWorkspaceCwd: vi.fn(async (cwd: string) => ({ cwd })),+ settings: { getDefaultProjectDir: vi.fn(async () => ({ defaultLabel: '', dir: '', resolvedCwd: '' })) }+ }++ $connection.set({ baseUrl: '', mode: 'local', profile: 'profile-a' } as never)+ setCurrentCwd('/home/user/project-a')++ $connection.set({ baseUrl: '', mode: 'local', profile: 'profile-b' } as never)+ await ensureDefaultWorkspaceCwd(() => true)+ expect($currentCwd.get()).toBe('')++ $connection.set({ baseUrl: '', mode: 'local', profile: 'profile-a' } as never)+ await ensureDefaultWorkspaceCwd(() => true)+ expect($currentCwd.get()).toBe('/home/user/project-a')+ })+it('remembers only the workspace the user picked, not the one they looked at', () => {// The reported bug (#77496 / #80213): every session resume used to write// the remembered-workspace key — so opening a project chat silently moveddiff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.tsindex 6f848f5fc55..9291146d194 100644--- a/apps/desktop/src/store/session.ts+++ b/apps/desktop/src/store/session.ts@@ -328,14 +328,19 @@ export function setRememberedRoute(path: null | string, profile: string): void {let configuredDefaultProjectDir = ''function workspaceCwdKey(connection: HermesConnection | null = $connection.get()): string {+ const profile = connection?.profile?.trim() || 'default'+if (connection?.mode !== 'remote') {- return WORKSPACE_CWD_KEY+ // One desktop runs several local profiles, and one shared key let the last+ // profile's project leak into every other profile's new chats (#96834).+ // The default profile keeps the bare key — byte-identical for+ // single-profile users, the connection-scoped.ts contract.+ return profile === 'default' ? WORKSPACE_CWD_KEY : `${WORKSPACE_CWD_KEY}.profile.${encodeURIComponent(profile)}`}const base = encodeURIComponent(connection.baseUrl || 'remote')- const profile = encodeURIComponent(connection.profile || 'default')- return `${WORKSPACE_CWD_KEY}.remote.${base}.${profile}`+ return `${WORKSPACE_CWD_KEY}.remote.${base}.${encodeURIComponent(profile)}`}export const getRememberedWorkspaceCwd = (): string => storedString(workspaceCwdKey())?.trim() || ''@@ -412,9 +417,13 @@ export async function ensureDefaultWorkspaceCwd(shouldPublish: () => boolean = (return}- if (remembered) {- const { cwd } = await sanitize(remembered)- seedLiveCwd(cwd)+ // An empty memory is meaningful here too: on a local profile switch the+ // live cwd still belongs to the outgoing profile, so clear it rather than+ // let the incoming profile's new chats start there (#96834).+ const { cwd } = remembered ? await sanitize(remembered) : { cwd: '' }++ if (shouldPublish() && !$activeSessionId.get()) {+ setCurrentCwdTransient(cwd)}}