Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge remote-tracking branch 'upstream/main' (d1fd9c91e) into fix/session-move-worktree-bound

Zhang Yunjin8d4a81acffda
diff --cc apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index c333d9a776,af3c02db66..7091207766
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@@ -150,9 -155,9 +156,10 @@@ import
registerSessionIpc,
resumeDeletedPiSubagentCleanup,
setSessionRuntimeCleanup,
+ setSessionWorktreeBindingLookup,
setSessionWorktreeRecycle,
updateSessionInDb,
+ touchUserSendInDb,
} from '../sessions';
import { retireDeletedPiSubagentState } from '../piSubagentDeletion';
import { setSessionRouteLockImplementation } from '../../sessionRouteLock';
diff --cc apps/desktop/src/main/localDb/ipc/sessions.ts
index 676c4fbe83,39601ac572..4c0b720af6
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@@ -66,11 -64,10 +64,15 @@@ import
DESKTOP_VISIBLE_SESSION_SOURCES,
isRetainableProjectSessionSource,
} from '../../../shared/sessionSource.js';
- import { normalizeWorkingDirForStorage, workingDirEquals } from '../../../shared/workingDir.js';
+ import {
+ normalizeWorkingDirForProjectSettings,
+ normalizeWorkingDirForStorage,
++ workingDirEquals,
+ } from '../../../shared/workingDir.js';
+import {
+ WORKTREE_MOVE_BLOCKED_CODE,
+ WORKTREE_MOVE_BLOCKED_MESSAGE,
+} from '../../../shared/worktreeMoveGuardError.js';
import { assertRendererSessionSourceAllowed } from './sessionSourceGuard.js';
import type { SessionReference } from '../../../shared/sessionReference.js';
import * as broadcastTap from '../../device-link/broadcast-tap.js';
diff --cc apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index 6d7ff34afa,c865de4b04..6aeae5e9ca
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@@ -346,25 -346,13 +347,26 @@@ export interface MakerSendTransactionDe
opts?: { suppressMissingBroadcast?: boolean },
): Promise<boolean>;
resolveRecoveredWorkingDir?(sessionId: string, workingDir: string): string;
+ isPersistedWorktreeFallback?(workingDir: string): boolean;
/**
- * 读 DB 里既有会话的权威 working_dir(行不存在 → null)。lazy-create /
- * rehydrate 在 caller 传入的 workingDir 校验失败时用它兜底——输入队列崩溃
- * 快照等缓存的 createOpts 可能内嵌已被启动 sweep 改写掉的老路径。
+ * 纯文件系统探测(不做 recovery / mkdir / 广播)。判断 DB 里的 working_dir 是否
+ * **真实存在** —— 会话移动后 runtime cwd 与 DB 漂移时,只有确认 DB 目录真实存在
+ * 才重建 runtime,不能把不存在的目录"恢复"成空文件夹。
+ */
+ statDirectory(dir: string): Promise<{ isDirectory(): boolean }>;
+ /**
+ * 读 DB 里既有会话的权威 working_dir(行不存在 → null)。lazy-create 把它当唯一
+ * 真源直接采纳;rehydrate 只在 caller 传入的 workingDir 校验失败时用它兜底——
+ * 输入队列崩溃快照等缓存的 createOpts 可能内嵌已被启动 sweep 改写掉的老路径。
*/
readSessionWorkingDirFromDb(sessionId: string): Promise<string | null>;
+ /**
+ * 区分「没有这一行」与「行在但 working_dir 被显式清空」:DB 返回空目录时,
+ * lazy-create 用它判断能不能沿用 caller 快照(行在=DB 说这个会话没有目录)。
+ */
+ readSessionWorkingDirState?(
+ sessionId: string,
+ ): Promise<{ exists: boolean; workingDir: string | null }>;
isOrcaMcpHydrated(sessionId: string): boolean;
buildCreateOptsWithStderr(opts: CreateOpts): CreateOpts;
synthesizeOrcaVendorOptionsFromDb(sessionId: string, opts: CreateOpts): Promise<boolean>;
@@@ -686,38 -662,15 +688,47 @@@ export function createMakerSendTransact
});
return null;
});
+ if (
+ opts?.preferDbWorkingDir &&
+ !dbDir &&
+ !createOpts.remoteHostId &&
+ createOpts.workingDir &&
+ deps.readSessionWorkingDirState
+ ) {
+ // DB 行存在但 working_dir 已被清空:DB 明确说这个会话没有目录,排队/重试快照
+ // 里的旧目录不能把它复活 —— 否则又是「库里没有目录、runtime 却在旧项目里跑」。
+ // 行不存在(首次 lazy-create)时才沿用 caller 快照。
+ const state = await deps.readSessionWorkingDirState(sessionId).catch(() => null);
+ if (state?.exists) {
+ deps.log.warn('send: lazy-create dropped stale caller workingDir because DB row has none', {
+ sessionId,
+ staleWorkingDir: createOpts.workingDir,
+ });
+ return false;
+ }
+ }
+ // A queued runtime cwd may be a recovery directory from a previous process.
+ // Start from the durable binding so the new process retries Git restoration
+ // and, if still unavailable, supplies a fresh recovery note. In-process
+ // recovery.resolve continues to preserve the already selected fallback.
+ if (!createOpts.remoteHostId && createOpts.workingDir &&
+ deps.isPersistedWorktreeFallback?.(createOpts.workingDir)) {
+ if (!dbDir) return false;
+ createOpts.workingDir = dbDir;
+ }
+ if (opts?.preferDbWorkingDir && dbDir && dbDir !== createOpts.workingDir) {
+ const adopted = createOpts.remoteHostId
+ ? dbDir
+ : deps.resolveRecoveredWorkingDir?.(sessionId, dbDir) ?? dbDir;
+ if (adopted !== createOpts.workingDir) {
+ deps.log.info('send: lazy-create adopted DB working_dir over stale caller snapshot', {
+ sessionId,
+ staleWorkingDir: createOpts.workingDir,
+ workingDir: adopted,
+ });
+ createOpts.workingDir = adopted;
+ }
+ }
const fallbackDir = dbDir && dbDir !== createOpts.workingDir ? dbDir : null;
if (fallbackDir) deps.workdirDiagnostics?.info('workdir DB fallback candidate', {
...workdirDiagnosticContext(sessionId, createOpts.workingDir), source: 'bootstrap',
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index 652a8420e1,0be37965b6..fd55d73ef4
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -12166,7 -12180,8 +12181,9 @@@ export function registerMakerIpc(maker
},
checkWorkDirExists,
resolveRecoveredWorkingDir: (sessionId, dir) => workingDirectoryRecovery.resolve(sessionId, dir),
+ statDirectory: (dir) => statWorkingDirectory(dir),
+ isPersistedWorktreeFallback: (dir) => path.dirname(path.resolve(dir)) ===
+ path.join(dialogueWorkspaceRootDir(), 'worktree-recovery'),
preflightBotRuntimeResources: async (opts) => { await preflightBotRuntimeResources(opts); },
readWorkingDirectoryRecoveryCreateOpts: async (sessionId) => {
const [row] = await getDbClient().drizzle.select().from(sessions)
diff --cc apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index ea3f522716,19b6b5f35a..9ebbc62b44
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@@ -2762,24 -2781,16 +2788,15 @@@ function ExpandedView(
if (expandedProjectKey && wasExpandedProjectCollapsed) {
collapse.setCollapsed(expandedProjectKey, true);
}
- toast.error(
- t(
- target.kind === 'dialogue'
- ? 'ccAgent.sidebar.sessionMenu.moveToDialogueFailed'
- : 'ccAgent.sidebar.sessionMenu.moveToProjectFailed',
- ),
- );
+ // 归属守卫在主进程唯一权威地拒绝跨根移动(在关 runtime / 写库 / 转录迁移之前,
+ // 不留部分写入);被它拒绝时给产品既定的「暂不支持移出 worktree」说明,其它
+ // 失败照旧用通用报错文案。
+ const feedback = sessionMoveFailureFeedback(target.kind, err);
+ if (feedback.level === 'warning') toast.warning(t(feedback.key));
+ else toast.error(t(feedback.key));
}
},
- // 同理只依赖用到的三个成员,不要整个 collapse —— useCollapsedProjects 也返回
- // 新对象字面量。collapsed 是 Set,仅用户手动折叠/展开时换引用,频率可忽略。
- [
- collapse.collapsed,
- collapse.expand,
- collapse.setCollapsed,
- effectiveRunningSessionIds,
- patchLocal,
- t,
- ],
+ [collapse.expand, collapse.setCollapsed, effectiveRunningSessionIds, patchLocal, t],
);
/* ---- Delete / Archive / Unarchive action handlers ----