Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(update): 确认卡必须绑定具体版本,自动重试不算主人输入,等待更新器真正启动
Dash23eabd9da62b
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex 29b7f9e7e0..8e294610ed 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -495,6 +495,66 @@ describe('agent-facing managed app update check', () => {}});+ it('reports the version being downloaded instead of an unknown target', async () => {+ let finishDownload!: () => void;+ download.mockImplementation(({ targetPath }: { targetPath: string }) => new Promise((resolve) => {+ finishDownload = () => {+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });+ fs.writeFileSync(targetPath, 'update');+ resolve({ path: targetPath, size: 123 });+ };+ }));+ const service = await freshUpdateService('darwin');+ try {+ const staging = service.checkForUpdate();+ await vi.waitFor(() => { expect(download).toHaveBeenCalledOnce(); });+ await expect(service.checkAppUpdateForAgent()).resolves.toMatchObject({+ status: 'downloading', targetVersion: '0.0.65',+ });+ finishDownload();+ await staging;+ } finally {+ service.stopUpdateService();+ }+ });++ it('reports a Windows updater spawn failure instead of claiming a relaunch', async () => {+ download.mockImplementation(async ({ targetPath }: { targetPath: string }) => {+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });+ fs.writeFileSync(targetPath, 'update');+ return { path: targetPath, size: 123 };+ });+ const service = await freshUpdateService('win32');+ const resourcesPath = path.join(TEST_ROOT, 'resources');+ fs.mkdirSync(resourcesPath, { recursive: true });+ fs.writeFileSync(path.join(resourcesPath, 'cindy-updater.exe'), 'updater');+ const resourcesDescriptor = Object.getOwnPropertyDescriptor(process, 'resourcesPath');+ Object.defineProperty(process, 'resourcesPath', { value: resourcesPath, configurable: true });+ const tmpdirSpy = vi.spyOn(os, 'tmpdir').mockReturnValue(TEST_ROOT);+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);+ const childListeners = new Map<string, (...args: unknown[]) => void>();+ spawnProcess.mockImplementationOnce(() => ({+ unref: vi.fn(),+ on: vi.fn((event: string, listener: (...args: unknown[]) => void) => { childListeners.set(event, listener); }),+ }));+ try {+ const pending = service.applyConfirmedAppUpdateForAgent({+ expectedVersion: '0.0.65', beforeRelaunch: async () => true,+ });+ await vi.waitFor(() => { expect(childListeners.has('error')).toBe(true); });+ childListeners.get('error')?.(Object.assign(new Error('spawn denied'), { code: 'EACCES' }));+ await vi.advanceTimersByTimeAsync(200);+ await expect(pending).resolves.toMatchObject({ status: 'failed', errorCode: 'updater_spawn_failed' });+ expect(exitSpy).not.toHaveBeenCalled();+ } finally {+ service.stopUpdateService();+ tmpdirSpy.mockRestore();+ exitSpy.mockRestore();+ if (resourcesDescriptor) Object.defineProperty(process, 'resourcesPath', resourcesDescriptor);+ else Reflect.deleteProperty(process, 'resourcesPath');+ }+ });+it('does not relaunch when the download fails or the build is unsupported', async () => {download.mockRejectedValue(new Error('network'));const service = await freshUpdateService('darwin');diff --git a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.tsindex d198cfb835..10ec252e2d 100644--- a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts+++ b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts@@ -274,6 +274,15 @@ describe('Agent app update install', () => {expect(harness.deps.marker.write).not.toHaveBeenCalled();});+ it('never raises a card without a concrete target version', async () => {+ const { deps, service } = setup({+ check: vi.fn(async () => ({ status: 'downloading', currentVersion: '0.1.86' })),+ });+ await expect(service.install(caller)).resolves.toMatchObject({ status: 'target_unknown' });+ expect(deps.requestHostPermission).not.toHaveBeenCalled();+ expect(deps.apply).not.toHaveBeenCalled();+ });+it('mentions the Linux password prompt only on Linux', async () => {const { deps, service } = setup({ platform: 'linux', countOtherRunningTasks: vi.fn(() => 0) });await service.install(caller);diff --git a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.tsindex 8cbd4a74f7..d5dfa3b2ec 100644--- a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts+++ b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts@@ -300,10 +300,18 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {try {const check = await deps.check();if (!UPDATABLE_STATUSES.has(check.status)) return { ...check };+ // Every confirmation names a concrete version; the updater installs only that one.+ if (!check.targetVersion) {+ return {+ status: 'target_unknown',+ currentVersion: check.currentVersion,+ message:+ '暂时无法确定要安装的版本(可能无法读取当前渠道信息),未弹出确认;请稍后再试。',+ };+ }const from = check.currentVersion;- // A first background download has no staged version yet.- const to = check.targetVersion ?? text('update.agentInstall.latestVersion');- flow.targetVersion = check.targetVersion;+ const to = check.targetVersion;+ flow.targetVersion = to;const outcome = await decide(caller, buildInstallCard(caller, from, to));if (outcome !== 'allow') return declined(outcome);// The user may have stopped or replaced the task while the card was open.@@ -316,18 +324,18 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {requestId: randomUUID(),sessionId: caller.sessionId,fromVersion: from,- ...(check.targetVersion ? { targetVersion: check.targetVersion } : {}),+ targetVersion: to,requestedAt: deps.now(),pid: deps.pid,};deps.marker.write(owner, marker);- flow = { kind: 'installing', targetVersion: check.targetVersion };+ flow = { kind: 'installing', targetVersion: to };started = true;void runInstall(caller, owner, marker);return {status: 'started',currentVersion: from,- targetVersion: check.targetVersion,+ targetVersion: to,message:'Cindy 正在通过内置更新器下载并安装更新,本轮回复结束后会自动重启;重启后结果会写回本任务。请简短告知用户,不要再执行其他操作。',};diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.tsindex da65970336..84ed0dfad7 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts@@ -1861,6 +1861,7 @@ describe('AgentInputCoordinator send transaction', () => {['a plugin', { sourcePlugin: { pluginId: 'p', name: 'P' } }, false],['a shared-task guest', { sharedTaskAuthor: { sharedTaskId: 't', sessionId: 'owner-authored-input', memberId: 'm', accountId: 'guest', displayName: 'G' } }, false],['an automatic resume', { autoResume: true }, false],+ ['an automatic retry of a typed message', { autoResume: true, retrySourceClientId: 'typed-1' }, false],['a synthetic UI trigger', { autoReviewUserText: '[UI_ACTION_TRIGGER] continue' }, false],['a delegated continuation', { autoReviewUserText: { kind: 'delegated-continuation' as const } }, false],])('decides whether %s counts as owner-authored for owner-only Host actions', async (_label, patch, expected) => {diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex 9cb55c22fc..fee5d1a1d4 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -1308,7 +1308,8 @@ export class AgentInputCoordinator {if (!item || (originKind !== undefined && originKind !== 'desktop')) return false;if (item.sourcePlugin || item.sharedTaskAuthor || item.botTaskCoordination) return false;if (item.clientId.startsWith('plugin-task:') || item.originalSyntheticTrigger) return false;- if (item.autoResume && !item.retrySourceClientId) return false;+ // Automatic continuations and zero-output retries are never fresh owner input.+ if (item.autoResume) return false;const text = item.autoReviewUserText;return typeof text === 'string' && !!text.trim() && !text.startsWith('[UI_ACTION_TRIGGER]');}diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex d10eadfbf2..696f7d3871 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -2113,7 +2113,15 @@ export async function checkAppUpdateForAgent(): Promise<{const unsupported = agentUpdateUnsupportedReason();if (unsupported) return { status: 'unsupported', currentVersion, reason: unsupported };if (currentStatus === 'downloading' || currentStatus === 'superseding') {- return { status: 'downloading', currentVersion, targetVersion: readyVersion };+ // `readyVersion` is unset during a first download and still names the old+ // patch while superseding; read the version being downloaded from the+ // manifest (read-only) so a confirmation is always bound to a concrete version.+ const manifest = await fetchManifest();+ const downloading = manifest+ && compareAppUpdateVersions(manifest.app?.version, currentVersion) === 'newer'+ && resolveUpdateAsset(manifest)+ ? manifest.app.version : undefined;+ return { status: 'downloading', currentVersion, targetVersion: downloading };}if (currentStatus === 'ready' && readyVersion) {return { status: 'ready', currentVersion, targetVersion: readyVersion };@@ -2136,6 +2144,9 @@ export async function checkAppUpdateForAgent(): Promise<{};}+/** Longer than the Windows / Linux updater spawn timeout (5 s). */+const AGENT_RELAUNCH_SETTLE_MS = 10_000;+const AGENT_UPDATE_FAILURE_REASONS: Record<Exclude<CheckForUpdateResult, 'ready'>, string> = {manifest_failed: '无法读取当前渠道的更新信息。',download_failed: '下载更新失败,请稍后重试。',@@ -2193,9 +2204,15 @@ export async function applyConfirmedAppUpdateForAgent(options: {const changedBeforeRelaunch = versionChanged();if (changedBeforeRelaunch) return changedBeforeRelaunch;const targetVersion = readyVersion;- // macOS / Linux exit inside this call once the updater is spawned; Windows- // returns with `isRelaunching` still set and exits from its own callbacks.await executeRelaunch(resolvedRelaunchTheme);+ // macOS exits inside the call. Windows and Linux return with `isRelaunching`+ // still set and settle within their 5 s spawn timeout: success exits via+ // forceQuit(), failure clears the flag in handleApplyFailure(). Wait for that+ // outcome so a failed spawn is reported now rather than after a later restart.+ const settleDeadline = Date.now() + AGENT_RELAUNCH_SETTLE_MS;+ while (isRelaunching && process.platform !== 'darwin' && Date.now() < settleDeadline) {+ await new Promise((resolve) => setTimeout(resolve, 100));+ }if (isRelaunching) return { status: 'relaunching', targetVersion };return {status: 'failed',diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 80f1f06688..8d68e8021d 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -8053,7 +8053,6 @@"thisTask": "This task restarts with {{appName}} after the current reply finishes.","remote": "Phones and other remote connections disconnect briefly during the restart. Reconnect to see the result in this task.","linuxAuth": "Installing requires your system password on this computer.",- "latestVersion": "the new version","succeeded": "{{appName}} is updated to {{version}} (was {{from}}).","failed": "The {{appName}} update did not finish. This computer is still on {{version}}.","retryHint": "Ask me to try again later, or check for updates in Settings → About."diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex b60024688f..a5d9502033 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -8045,7 +8045,6 @@"thisTask": "このタスクは現在の返信が終わった後、{{appName}} とともに再起動します。","remote": "再起動中はスマートフォンなどのリモート接続が一時的に切断されます。再接続後、このタスクで結果を確認できます。","linuxAuth": "インストールにはこのコンピューターでのシステムパスワード入力が必要です。",- "latestVersion": "新しいバージョン","succeeded": "{{appName}} を {{version}} に更新しました(以前は {{from}})。","failed": "{{appName}} の更新は完了しませんでした。現在も {{version}} です。","retryHint": "後でもう一度依頼するか、「設定 → 情報」で更新を確認してください。"diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 2131c93050..5e0110643d 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -8045,7 +8045,6 @@"thisTask": "이 작업은 현재 답변이 끝난 뒤 {{appName}}과(와) 함께 다시 시작됩니다.","remote": "다시 시작하는 동안 휴대폰 등 원격 연결이 잠시 끊깁니다. 다시 연결되면 이 작업에서 결과를 확인할 수 있습니다.","linuxAuth": "설치하려면 이 컴퓨터에서 시스템 비밀번호를 입력해야 합니다.",- "latestVersion": "새 버전","succeeded": "{{appName}}이(가) {{version}}(으)로 업데이트되었습니다(이전 버전 {{from}}).","failed": "{{appName}} 업데이트가 완료되지 않았습니다. 현재 버전은 여전히 {{version}}입니다.","retryHint": "나중에 다시 요청하거나 \"설정 → 정보\"에서 업데이트를 확인하세요."diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 1fb473445c..ebebdf14f3 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -8045,7 +8045,6 @@"thisTask": "本任务会在这轮回复结束后随 {{appName}} 重启。","remote": "重启期间手机等远程连接会暂时断开,重连后可在本任务中查看更新结果。","linuxAuth": "安装时需要在这台电脑上输入系统密码。",- "latestVersion": "新版本","succeeded": "{{appName}} 已更新到 {{version}}(原版本 {{from}})。","failed": "{{appName}} 更新没有完成,当前仍是 {{version}}。","retryHint": "可以稍后再让我更新,或在「设置 → 关于」中检查更新。"diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 03fedc65e1..87f7cdbd6b 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -8045,7 +8045,6 @@"thisTask": "本任務會在這輪回覆結束後隨 {{appName}} 重新啟動。","remote": "重新啟動期間手機等遠端連線會暫時中斷,重新連線後可在本任務中查看更新結果。","linuxAuth": "安裝時需要在這台電腦上輸入系統密碼。",- "latestVersion": "新版本","succeeded": "{{appName}} 已更新到 {{version}}(原版本 {{from}})。","failed": "{{appName}} 更新沒有完成,目前仍是 {{version}}。","retryHint": "可以稍後再讓我更新,或在「設定 → 關於」中檢查更新。"diff --git a/docs/product-rules/agent-app-update.md b/docs/product-rules/agent-app-update.mdindex 1fe7b92110..fbafc03e83 100644--- a/docs/product-rules/agent-app-update.md+++ b/docs/product-rules/agent-app-update.md@@ -15,7 +15,8 @@ Agent 只能反复引导用户去点「检查更新」;那次收紧的起因安装卡写明从哪个版本到哪个版本、Cindy 会重启、另有几个任务正在运行会被中断(重启后在任务里点「继续」恢复)、本任务在这轮回复后重启、远程连接会短暂断开;Linux 另提示需要输入系统密码。- 确认后走「设置 → 关于」同一条更新状态机:`checkForUpdate()` 下载(单飞,重复调用不重复下载),- 等调用任务这轮回复结束(最多 2 分钟)后 `executeRelaunch()` 重启。安装只认卡片上确认的版本:+ 等调用任务这轮回复结束(最多 2 分钟)后 `executeRelaunch()` 重启;Windows / Linux 会等更新器真正启动+ (5 秒内成功即退出、失败即写回原因)再收尾。确认卡总是写明具体目标版本(后台首次下载中也读渠道版本;读不到就不弹卡),安装只认卡片上确认的版本:渠道期间换了新版本时不安装,提示重新发起。安装绑定确认时的账号:退出或切换账号会取消重启,标记与结果消息只写回该账号,绝不写进后来的账号。拒绝、超时或卡片未送达都不下载、不重启。同一时刻只有一个安装请求;确认卡等待中或已开始安装时再次调用直接返回当前状态。@@ -33,7 +34,7 @@ Agent 只能反复引导用户去点「检查更新」;那次收紧的起因只有主人本人发起的轮次能触发,没有正面证据一律拒绝(`OWNER_TURN_REQUIRED`):- 桌面与同账号手机:输入协调器里当前轮次的输入必须是主人亲手输入的文字;自动化、其他任务- (`send_to_session`)、Orca、插件、共享任务访客、自动续跑、合成指令都不算。+ (`send_to_session`)、Orca、插件、共享任务访客、自动续跑(含零输出自动重试)、合成指令都不算。- 个人 IM:沿用控制命令的主人判据(私聊已过渠道 owner 门;群里看发言人 `isOwner`)。- 个人微信:私聊联系人无法证明是主人(其权限策略本就记为 `requesterAuthority: unknown`),一律拒绝,主人可在桌面、手机或其他已验证主人的渠道发起。