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 pull request #886 from feat/session-worktree-option

MagicLizi8509c7a1c8c5
diff --cc apps/desktop/src/renderer/contexts/AuthContext.tsx
index 89a38c8dc8,a8e07ec10f..47b75b830b
--- a/apps/desktop/src/renderer/contexts/AuthContext.tsx
+++ b/apps/desktop/src/renderer/contexts/AuthContext.tsx
@@@ -32,7 -32,7 +32,8 @@@ import { isSidebarWindow } from '@/lib/
import { isGhostPanelWindow } from '@/lib/ghostPanelWindow';
import { setNewMakerDraftOwner } from '@/state/newMakerDraft';
import { setComposerDraftOwner } from '@/lib/composerDraftStore';
+import { setPendingHandoffOwner } from '@/state/pendingFirstMessage';
+ import { setDataOwnerGeneration } from './dataOwnerGeneration';
/**
* 登录态上下文:user / isAuthenticated / isCanary / deviceId 全部来自 main 的
@@@ -277,9 -281,10 +283,11 @@@ export function AuthProvider({ childre
}, []);
const enterLocalMode = useCallback(async () => {
+ setDataOwnerGeneration(null);
const state = await authServiceRef.current!.enterLocalMode();
+ setDataOwnerGeneration(state.dataOwnerId);
setComposerDraftOwner(state.dataOwnerId);
+ setPendingHandoffOwner(state.dataOwnerId);
setMode(state.mode);
setDataOwnerId(state.dataOwnerId);
setCanEnterApp(state.canEnterApp);
@@@ -288,9 -293,10 +296,11 @@@
}, []);
const exitLocalMode = useCallback(async () => {
+ setDataOwnerGeneration(null);
const state = await authServiceRef.current!.exitLocalMode();
+ setDataOwnerGeneration(state.dataOwnerId);
setComposerDraftOwner(state.dataOwnerId);
+ setPendingHandoffOwner(state.dataOwnerId);
setMode(state.mode);
setDataOwnerId(state.dataOwnerId);
setCanEnterApp(state.canEnterApp);
diff --cc apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
index bce05e52c3,384084d7a9..6720541f9a
--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
@@@ -2190,23 -2344,10 +2389,26 @@@ export function NewMakerDraftRoute()
nowIso: new Date().toISOString(),
logTag: 'draft send',
});
+ // 可恢复副本紧贴提交点落下,**排在下面的附件迁移 await 之前**(codex P2 第五轮)。
+ // 提交点之后每多一次 await,「对端会话已建好、正文却还没有第二份」的窗口就长一分;
+ // rehomeDraftAttachments 是本机 IPC,但含 base64 / 草稿缓存图片时并不快,期间
+ // 应用退出或崩溃,正文就没了。副本只存正文、不依赖附件迁移结果,所以可以先落。
+ rememberRecoverableHandoff(remoteSessionId, 'message', message);
+ // F-COLLAB / device-link:草稿开了协同 → **不在这里 await**,把「开协同」连同
+ // 首条消息一起交接给 SessionView(见 pendingFirstMessage.PendingRemoteCollab)。
+ //
+ // 两条约束只能这样同时满足(greptile P1 + codex P1/P2 三轮收敛的结论):
+ // · 首轮必须排在协同之后 —— 否则用户开了协同,首轮 Lead 却没有 cindy_orca 工具;
+ // · 提交点之后不得插入远程等待 —— 被控端起 Worker 是一次隧道往返,可能一路走到
+ // invoke 默认 30s 超时。挡在 navigate 前面,既让新建页凭空卡住半分钟,又把
+ // 「对端会话已建好、用户输入还只在内存 pending Map 里」的窗口拉到同样长度,
+ // 窗口内应用被关掉就永久丢消息、对端留下空会话。
+ // 交接出去之后,等待发生在**已经导航到的**会话视图里:UI 不卡,输入已在视图手里,
+ // 而首轮仍然由同一个 await 串在协同之后。
const rehydratedFiles = await rehomeDraftAttachments(files, remoteSessionId);
+ if (!isCurrentDataOwner()) {
+ throw new RemotePrecreatedWorktreeOwnerChangedError();
+ }
setPending(remoteSessionId, {
text: message,
files: rehydratedFiles,
diff --cc apps/desktop/src/renderer/i18n/locales/en/common.json
index 88f3e26da0,c888aadcab..100ef8c269
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@@ -5835,11 -5617,9 +5839,9 @@@
"remoteProviderUnsupported": "This provider is not supported in SSH remote sessions — pick another source",
"remoteNativeOauthUnavailable": "Claude.ai subscription is not connected — connect it first or pick a gateway model",
"deviceStillLoading": "Remote device is still loading, please wait",
- "worktreeMissingRepo": "Cannot create worktree: missing repository root for the current directory",
- "worktreeRepoHint": "Try re-selecting the working directory and wait for the folder badge to refresh, then retry",
"sessionInactive": "Session is no longer active",
"remoteProjectBanner": "New session in {{project}} on {{device}}",
- "remoteDialogueBanner": "New dialogue on {{device}} (no project)"
+ "remoteDialogueBanner": "New chat on {{device}} (no project)"
},
"jumpSession": {
"emptyId": "Enter a sessionId to jump to",
diff --cc apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index efde73b41e,0f03f8f54b..64f23587b3
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@@ -5819,7 -5601,8 +5822,8 @@@
}
},
"draft": {
- "createSessionFailed": "创建对话失败,请重试",
+ "createSessionFailed": "创建任务失败,请重试",
+ "remoteWorktreeCleanupPending": "上一次远程 worktree 仍待回收,请重新连接设备后再试。",
"remoteProviderUpdating": "供应商凭证正在更新,请稍后重试",
"remoteProviderUnsupported": "该供应商不支持 SSH 远程会话,请更换来源",
"remoteNativeOauthUnavailable": "未连接 Claude.ai 订阅,请先连接或选择网关模型",
diff --cc apps/desktop/src/renderer/state/newMakerDraft.ts
index 6f54901d41,bc89fe0157..d6bb2e345e
--- a/apps/desktop/src/renderer/state/newMakerDraft.ts
+++ b/apps/desktop/src/renderer/state/newMakerDraft.ts
@@@ -414,26 -644,18 +644,30 @@@ export function patchDraft(patch: Parti
next.deviceLinkDeviceId = null;
next.deviceLinkDeviceName = null;
}
- // device-link 草稿同样禁用协同(同 remoteHostId:worker 创建拿不到 deviceId)。
- if (next.deviceLinkDeviceId != null && next.collab.enabled) {
- next.collab = { ...next.collab, enabled: false };
+ // 换目标设备(含本机 ↔ 被控设备、被控设备 A ↔ B)→ 丢掉 Worker 富配置,只留
+ // enabled + worker。model / providerId / effort / fast 都是**设备作用域**的:被控端
+ // 装的模型目录、连的供应商都是它自己那一套,原样透传过去会撞被控端 main 的精确
+ // preflight(INVALID_PARAMS / PROVIDER_ROUTE_UNAVAILABLE),协同静默降级成单会话 ——
+ // 正是 issue #1170 抱怨的「入口能点但走不完」。清掉后由被控端按自己的默认值起
+ // Worker,与草稿里模型 pill 换设备重新校准的既有行为一致。
+ //
+ // 放在 store 层而不是 applyDraftTarget:换设备有四条路径(设备 pill、设备域浏览器、
+ // 工作区 picker、所选设备失效后的自动回落),挂在这里全部自动覆盖,新增第五条也不用
+ // 再对齐一格(与 NewMakerDraftRoute.applyDraftTarget 的「按什么变了而不是走了哪条
+ // 路径」同一思路)。
+ if (currentDraft.deviceLinkDeviceId !== next.deviceLinkDeviceId && next.collab.workerConfig) {
+ next.collab = { ...next.collab, workerConfig: undefined };
}
- // remote 项目 draft 的协同 codex / cc 均已接通(worker 创建已继承
- // remoteHostId,远端 MCP 注入两端落地),不再按 vendor 强制关闭。
+ // device-link 与 SSH remote 项目 draft 的协同都已接通(device-link 的 enableOrca /
+ // worker 创建 / 团队读写经隧道在被控端执行;SSH 的 worker 创建继承 remoteHostId、
+ // 远端 MCP 注入两端落地),不再按目标或 vendor 强制关闭。仍然关闭的只有「对话模式」
+ // (workingDir == null,见上方级联)与 Orca Worker 子会话(会话侧判定)。
currentDraft = next;
- scheduleWrite(currentDraft);
+ scheduleWrite({
+ preserveStoredWorktreePreference:
+ !('worktreeEnabled' in patch)
+ && !('worktreePreferenceCustomized' in patch),
+ });
emit();
}
diff --cc apps/mobile/app/_layout.tsx
index c33d0fe413,4de364e1d6..43d53c9e0e
--- a/apps/mobile/app/_layout.tsx
+++ b/apps/mobile/app/_layout.tsx
@@@ -7,8 -7,8 +7,8 @@@ import
useSegments,
} from 'expo-router';
import { StatusBar } from 'expo-status-bar';
- import { useEffect, useMemo, type ReactElement } from 'react';
- import { Alert, Platform, Pressable, StyleSheet, View } from 'react-native';
+ import { useCallback, useEffect, useMemo, useRef, type ReactElement } from 'react';
-import { Alert, AppState, Pressable, StyleSheet, View } from 'react-native';
++import { Alert, AppState, Platform, Pressable, StyleSheet, View } from 'react-native';
import { Text } from '@/components/AppText';
import {
fontWeight,
diff --cc apps/mobile/src/i18n/locales/zh-CN/session.json
index 9e200132cf,ac9183adc6..daaf3990de
--- a/apps/mobile/src/i18n/locales/zh-CN/session.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/session.json
@@@ -159,7 -155,16 +159,16 @@@
"previewAttachments": "附件:{{num}} 个",
"previewReadyTitle": "准备创建并发送",
"previewNotReadyTitle": "还不能创建",
- "previewReadySubtitle": "确认后会在被控设备创建任务,并把首条消息加入队列。"
- "previewReadySubtitle": "确认后会在被控设备创建对话,并把首条消息加入队列。",
++ "previewReadySubtitle": "确认后会在被控设备创建任务,并把首条消息加入队列。",
+ "useWorktree": "使用 worktree",
+ "worktreeDetecting": "检测环境中…",
+ "worktreeGitMissing": "未检测到 git,请先安装",
+ "worktreeNotGitRepo": "当前目录不是 git 仓库",
+ "worktreeAlreadyInWorktree": "已在 worktree 中,禁止嵌套",
+ "worktreeDetectFailed": "无法检测目录环境,可稍后重选目录再试",
+ "worktreeCreateFailed": "worktree 创建失败:{{message}}",
+ "worktreeRecoveryStateFailed": "无法保存 worktree 恢复状态,请重试。",
+ "worktreeCleanupPending": "上一次 worktree 仍待回收,请重新连接设备后再试。"
},
"menu": {
"chipPinned": "已置顶",