The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): move a session to another project from its row menu
Brooklyn Nicholsonedae3eed10dc
diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsxindex d3e197958f1..559d648407b 100644--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx@@ -22,7 +22,14 @@ vi.mock('@/i18n', () => ({t: {common: { cancel: 'Cancel', close: 'Close', delete: 'Delete', save: 'Save' },sidebar: {- projects: { menuAppearance: 'Appearance', noColor: 'No color' },+ projects: {+ menuAppearance: 'Appearance',+ moveFailed: 'Could not move session',+ moveNoProjects: 'No other projects',+ movedTo: (name: string) => `Moved to ${name}`,+ moveToProject: 'Move to project',+ noColor: 'No color'+ },row: {archive: 'Archive',branchFrom: 'Branch from here',@@ -50,6 +57,12 @@ vi.mock('@/lib/profile-color', () => ({ PROFILE_SWATCHES: [] }))vi.mock('@/lib/session-export', () => ({ exportSession: vi.fn() }))vi.mock('@/store/gateway', () => ({ activeGateway: vi.fn(() => null) }))vi.mock('@/store/notifications', () => ({ notify: vi.fn(), notifyError: vi.fn() }))+vi.mock('@/store/projects', () => ({+ $projectTree: atom<unknown[]>([]),+ moveSessionToProject: vi.fn(),+ projectIdForCwd: vi.fn(() => null),+ projectRootCwd: vi.fn(() => '')+}))vi.mock('@/store/session', () => ({$activeSessionId: atom<null | string>(null),$selectedStoredSessionId: atom<null | string>(null),diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsxindex 57d8a9f9623..0a32e1881f8 100644--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx@@ -30,6 +30,7 @@ import { PROFILE_SWATCHES } from '@/lib/profile-color'import { exportSession } from '@/lib/session-export'import { activeGateway } from '@/store/gateway'import { notify, notifyError } from '@/store/notifications'+import { $projectTree, moveSessionToProject, projectIdForCwd, projectRootCwd } from '@/store/projects'import {$activeSessionId,$selectedStoredSessionId,@@ -133,6 +134,44 @@ function SessionColorSwatches({ sessionId }: { sessionId: string }) {)}+// The project list inside the session menu's "Move to project" submenu. Its own+// component so only an OPEN submenu subscribes to the stores (same reasoning as+// SessionColorSwatches). Re-homes the session's workspace at the target+// project's root — the fix for a chat created in the wrong folder. The current+// owner and folderless projects (the Home bucket) are excluded: there is+// nothing to move into.+function MoveToProjectItems({ kit, sessionId, profile }: { kit: MenuKit; sessionId: string; profile?: string }) {+ const { t } = useI18n()+ const p = t.sidebar.projects+ const tree = useStore($projectTree)+ const session = useStore($sessions).find(s => sessionMatchesStoredId(s, sessionId))+ const cwd = session?.cwd?.trim() || ''+ const currentProjectId = cwd ? projectIdForCwd(cwd) : null+ const targets = tree.filter(node => node.id !== currentProjectId && !node.isNoProject && projectRootCwd(node))++ if (targets.length === 0) {+ return <kit.Item disabled>{p.moveNoProjects}</kit.Item>+ }++ return (+ <>+ {targets.map(node => (+ <kit.Item+ key={node.id}+ onSelect={() => {+ triggerHaptic('selection')+ moveSessionToProject(sessionId, node.id, profile)+ .then(() => notify({ durationMs: 2_000, kind: 'success', message: p.movedTo(node.label) }))+ .catch(err => notifyError(err, p.moveFailed))+ }}+ >+ {node.label}+ </kit.Item>+ ))}+ </>+ )+}+function useSessionActions({sessionId,title,@@ -355,6 +394,15 @@ function useSessionActions({/><kit.Separator />{workItems.map(item => renderActionItem(kit, item))}+ <kit.Sub>+ <kit.SubTrigger disabled={!sessionId}>+ <Codicon name="folder" size="0.875rem" />+ <span>{t.sidebar.projects.moveToProject}</span>+ </kit.SubTrigger>+ <kit.SubContent>+ <MoveToProjectItems kit={kit} profile={profile} sessionId={sessionId} />+ </kit.SubContent>+ </kit.Sub>{tabItems.length > 0 && (<><kit.Separator />diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 2ec60d2859a..a79e4d5b293 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -1876,6 +1876,11 @@ export const en: Translations = {menuAddFolder: 'Add folder',menuSetActive: 'Set active',menuDelete: 'Delete',+ moveToProject: 'Move to project',+ movedTo: name => `Moved to ${name}`,+ moveFailed: 'Could not move session',+ moveNoFolder: 'That project has no folder to move into',+ moveNoProjects: 'No other projects',reveal: 'Reveal in folder',copyPath: 'Copy path',removeFromSidebar: 'Hide from sidebar',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex e2a49f4234d..9b0204c054e 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -1573,6 +1573,11 @@ export interface Translations {menuAddFolder: stringmenuSetActive: stringmenuDelete: string+ moveToProject: string+ movedTo: (name: string) => string+ moveFailed: string+ moveNoFolder: string+ moveNoProjects: stringreveal: stringcopyPath: stringremoveFromSidebar: stringdiff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 79a9a1c143e..c176ed0d912 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -2070,6 +2070,11 @@ export const zh: Translations = {menuAddFolder: '添加文件夹',menuSetActive: '设为活动',menuDelete: '删除',+ moveToProject: '移动到项目',+ movedTo: name => `已移动到 ${name}`,+ moveFailed: '无法移动会话',+ moveNoFolder: '该项目没有可移入的文件夹',+ moveNoProjects: '没有其他项目',reveal: '在文件夹中显示',copyPath: '复制路径',removeFromSidebar: '从侧边栏移除',diff --git a/apps/desktop/src/store/projects.ts b/apps/desktop/src/store/projects.tsindex 2ba0d7e59bb..6bb3451a88b 100644--- a/apps/desktop/src/store/projects.ts+++ b/apps/desktop/src/store/projects.ts@@ -22,6 +22,7 @@ import {$sessions,idsShareLineage,sessionMatchesStoredId,+ setSessions,workspaceCwdForNewSession} from '@/store/session'import { $focusedSessionState, $focusedStoredSessionId } from '@/store/session-states'@@ -173,7 +174,7 @@ export function exitProjectScope(): void {// one. Empty for the path-less Home bucket. (The sidebar's `projectTreeCwd` is// the same rule over the same tree — this is the store-side copy so the store// doesn't reach into the sidebar's React module.)-const projectRootCwd = (project: SidebarProjectTree | undefined): string =>+export const projectRootCwd = (project: SidebarProjectTree | undefined): string =>(project?.path || project?.repos.find(repo => repo.path)?.path || '').trim()// ⌘K "go to project": flip the sidebar into grouped mode and enter the project@@ -520,6 +521,45 @@ export async function fetchProjectSessions(projectId: string): Promise<SidebarPr}}+interface WorkspaceMovePayload {+ branch?: null | string+ cwd?: string+ git_repo_root?: null | string+}++// Re-home a stored session into another project's root folder — the fix for a+// chat created in the wrong directory. The backend replaces cwd + git identity+// (so the tree's grouping follows) and re-anchors any live agent bound to the+// row; here we mirror the move into the `$sessions` cache so both the flat list+// and the grouped tree reflect it before the next authoritative refresh.+export async function moveSessionToProject(+ sessionId: string,+ projectId: string,+ profile?: null | string+): Promise<void> {+ const cwd = projectRootCwd($projectTree.get().find(node => node.id === projectId))++ if (!cwd) {+ throw new Error(translateNow('sidebar.projects.moveNoFolder'))+ }++ const res = await gatewayRequest<WorkspaceMovePayload>('session.workspace.move', {+ cwd,+ session_key: sessionId,+ ...(profile ? { profile } : {})+ })++ const moved = res.cwd || cwd+ setSessions(prev =>+ prev.map(s =>+ sessionMatchesStoredId(s, sessionId)+ ? { ...s, cwd: moved, git_branch: res.branch ?? null, git_repo_root: res.git_repo_root ?? null }+ : s+ )+ )+ void refreshProjectTree()+}+export interface RepoDiscoveryPolicy {enabled: booleanroots: string[]