Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 装了 worktree 绑定查询时不再回落到 cwd 推导归属
Zhang Yunjin2adf760aacf8
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.tsindex 99bc9c3d1c..cfa4dbc327 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts@@ -1131,6 +1131,20 @@ describe('local-db:sessions:update handler wiring', () => {.toEqual({ working_dir: worktreeDir.replace(/\\/g, '/') });});+ it('allows moving a session whose worktree was already recycled', async () => {+ const worktreeDir = path.join(h.userDataDir!, '.cindy-worktrees', 'recycled-name');+ // 回收后 store 里没有绑定(注入查询返回 null),但 cwd 与快照仍留着历史 worktree 路径:+ // 归属以 store 为准,这类会话不能被永久拦死。+ h.sqlite!.prepare('UPDATE sessions SET working_dir = ?, worktree_path = ? WHERE id = ?')+ .run(worktreeDir, worktreeDir, 'cc-local');+ setSessionWorktreeBindingLookup(() => null);++ await invokeUpdate('cc-local', { workingDir: '/another/project' });++ expect(h.sqlite!.prepare('SELECT working_dir FROM sessions WHERE id = ?').get('cc-local'))+ .toEqual({ working_dir: '/another/project' });+ });+it('does not treat a recycled worktree snapshot as a live binding', async () => {const worktreeDir = path.join(h.userDataDir!, '.cindy-worktrees', 'recycled-name');// 回收后 worktreeStore 删条目但保留 DB 快照(徽标以 store 为准):这类行不应被拦住。diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.tsindex a3200debe5..9c8fcda2da 100644--- a/apps/desktop/src/main/localDb/ipc/sessions.ts+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts@@ -1839,10 +1839,16 @@ export async function updateSessionInDb((requestedWorkingDir !== null || clearsWorkingDir) &&(clearsWorkingDir || !workingDirEquals(requestedWorkingDir, beforeMove.workingDir))) {- const boundWorktreePath = sessionWorktreeBindingLookup?.(sid) ?? null;- const ownedWorktreeRoot =- (boundWorktreePath ? managedWorktreeRoot(boundWorktreePath) : null) ??- (beforeMove.workingDir ? managedWorktreeRoot(beforeMove.workingDir) : null);+ // 归属真源:装了绑定查询(生产路径)就以 store 的答案为唯一依据 —— 返回 null 就是+ // **没有活绑定**(worktree 已被回收的会话仍会留着历史 worktree 路径),此时不能再+ // 从 cwd 反推,否则这些会话会被永久拦死;未装查询的场景(单测/裁剪引导)才退回 cwd。+ let ownedWorktreeRoot: string | null = null;+ if (sessionWorktreeBindingLookup) {+ const liveWorktreePath = sessionWorktreeBindingLookup(sid);+ ownedWorktreeRoot = liveWorktreePath ? managedWorktreeRoot(liveWorktreePath) : null;+ } else if (beforeMove.workingDir) {+ ownedWorktreeRoot = managedWorktreeRoot(beforeMove.workingDir);+ }const targetWorktreeRoot = requestedWorkingDir? managedWorktreeRoot(requestedWorkingDir): null;