Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(update): 更新器真正启动前再复核账号与版本;渠道身份结论优先于私聊默认
Dash962dbb0de2fa
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex 8e294610ed..aa0021ccc0 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -555,6 +555,29 @@ describe('agent-facing managed app update check', () => {}});+ it('re-checks the caller condition right before the updater spawns', async () => {+ download.mockImplementation(async ({ targetPath }: { targetPath: string }) => {+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });+ fs.writeFileSync(targetPath, 'update');+ return { path: targetPath, size: 123 };+ });+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);+ const service = await freshUpdateService('darwin');+ const beforeSpawn = vi.fn(() => false);+ try {+ await expect(service.applyConfirmedAppUpdateForAgent({+ expectedVersion: '0.0.65', beforeRelaunch: async () => true, beforeSpawn,+ })).resolves.toMatchObject({ status: 'failed', errorCode: 'relaunch_cancelled' });+ expect(beforeSpawn).toHaveBeenCalledOnce();+ expect(spawnProcess).not.toHaveBeenCalled();+ expect(exitSpy).not.toHaveBeenCalled();+ expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'ready', targetVersion: '0.0.65' });+ } finally {+ service.stopUpdateService();+ exitSpy.mockRestore();+ }+ });+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 af6b8aaa06..41d5b03f0b 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@@ -124,6 +124,8 @@ describe('Agent app update install', () => {expect(deps.apply).toHaveBeenCalledOnce();expect(deps.waitForCallerTurnToEnd).toHaveBeenCalledWith(caller);expect(deps.apply).toHaveBeenCalledWith(expect.objectContaining({ expectedVersion: '0.1.90' }));+ const { beforeSpawn } = vi.mocked(deps.apply).mock.calls[0]![0];+ expect(beforeSpawn?.()).toBe(true);expect(deps.marker.write).toHaveBeenCalledWith(ownerA,expect.objectContaining({diff --git a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.tsindex b17ac5acdb..20cf01391b 100644--- a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts+++ b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts@@ -91,6 +91,7 @@ export interface AgentAppUpdateDeps {apply(options: {expectedVersion?: string;beforeRelaunch: () => Promise<boolean>;+ beforeSpawn?: () => boolean;}): Promise<AgentAppUpdateApplyResult>;readAutoUpdate(): boolean;writeAutoUpdate(enabled: boolean): boolean;@@ -266,6 +267,8 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {// Logout or an account switch cancels the restart; the patch stays staged.return deps.isOwnerCurrent(owner);},+ // Re-checked again after the updater's Subagent reclaim, right before spawn.+ beforeSpawn: () => deps.isOwnerCurrent(owner),});// A relaunch ends this process; the next start reports from the marker.if (result.status === 'relaunching') return;diff --git a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.tsindex affc4aab3a..1912e0086c 100644--- a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts@@ -97,7 +97,12 @@ describe('messageHandler !stop routing', () => {let consumePendingOpenerAsCard: ReturnType<typeof vi.fn>;let deliver: (event: IMMessageEvent) => void;- function wire(threadScoped: boolean, notificationSessionId?: string, prepareAgentTurnText?: ImChannelAdapter['prepareAgentTurnText']): void {+ function wire(+ threadScoped: boolean,+ notificationSessionId?: string,+ prepareAgentTurnText?: ImChannelAdapter['prepareAgentTurnText'],+ turnPermissionPolicyFor?: ImChannelAdapter['turnPermissionPolicyFor'],+ ): void {stopActiveTurn = vi.fn(async () => ({ stopped: true, droppedQueued: 0 }));runAgentTurn = vi.fn(async () => undefined);handleSlashCommand = vi.fn(async () => true);@@ -129,6 +134,7 @@ describe('messageHandler !stop routing', () => {ui: slackUi,threadScoped,...(prepareAgentTurnText ? { prepareAgentTurnText } : {}),+ ...(turnPermissionPolicyFor ? { turnPermissionPolicyFor } : {}),} as unknown as ImChannelAdapter;const attach = createMessageHandler(@@ -204,6 +210,18 @@ describe('messageHandler !stop routing', () => {expect(runAgentTurn.mock.calls[0][0].requesterIsOwner).toBe(owner);});+ it.each(['unknown', 'guest'] as const)('lets a channel policy identity (%s) override the private-chat default', async (requesterAuthority) => {+ wire(true, undefined, undefined, () => ({+ origin: { kind: 'im', channel: 'wechat', taskId: 't' },+ autoReviewContext: { requesterAuthority, source: 'direct' },+ confirmationSurface: 'channel',+ forceConfirmToolCall: () => false,+ }));+ deliver(makeEvent({ text: '更新 Cindy' }));+ await vi.waitFor(() => expect(runAgentTurn).toHaveBeenCalledTimes(1));+ expect(runAgentTurn.mock.calls[0][0].requesterIsOwner).toBe(false);+ });+it('still drops an empty event without a summon, quote or attachment', async () => {deliver(makeEvent({ text: '' }));await flushMicrotasks();diff --git a/apps/desktop/src/main/im/shared/messageHandler.ts b/apps/desktop/src/main/im/shared/messageHandler.tsindex 60f80ee71c..e243be9ca7 100644--- a/apps/desktop/src/main/im/shared/messageHandler.ts+++ b/apps/desktop/src/main/im/shared/messageHandler.ts@@ -408,8 +408,11 @@ export function createMessageHandler(userId: event.senderId,userMessageId: event.messageId,sourceDescription: describeInteractionSource(event),- // Same owner predicate as control commands: DMs passed the channel's owner gate.- requesterIsOwner: isCommandAuthorized(event),+ // A channel policy's own identity verdict wins (personal WeChat is always+ // `unknown`); otherwise the control-command owner check applies.+ requesterIsOwner: turnPermissionPolicy?.autoReviewContext+ ? turnPermissionPolicy.autoReviewContext.requesterAuthority === 'owner'+ : isCommandAuthorized(event),...(channelNoteSource ? { channelNoteSource } : {}),text: event.text,// 受保护群的触发消息照常起 turn, 但不进会话存档(渠道侧已挡住群历史池,diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex b2b23ed3bd..6383f4b3c5 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -1896,10 +1896,18 @@ function executeUpdateLinux(debPath: string, installation: LinuxUserInstallation});}-async function executeRelaunch(theme: 'light' | 'dark'): Promise<void> {+interface RelaunchOptions {+ /**+ * Last check after Subagent reclaim, immediately before the platform updater+ * spawns. Returning false keeps the patch staged and does not restart.+ */+ shouldProceed?: () => boolean;+}++async function executeRelaunch(theme: 'light' | 'dark', options?: RelaunchOptions): Promise<void> {if (isCindyPersonalRuntime()) return;try {- await executeRelaunchUnguarded(theme);+ await executeRelaunchUnguarded(theme, options);} catch (err) {log.error('executeRelaunch() failed: %s', err instanceof Error ? err.stack ?? err.message : String(err));try {@@ -1919,7 +1927,10 @@ async function executeRelaunch(theme: 'light' | 'dark'): Promise<void> {}}-async function executeRelaunchUnguarded(theme: 'light' | 'dark'): Promise<void> {+async function executeRelaunchUnguarded(+ theme: 'light' | 'dark',+ options?: RelaunchOptions,+): Promise<void> {if (isRelaunching) {log.info('executeRelaunch() skipped — already in progress');return;@@ -2033,6 +2044,16 @@ async function executeRelaunchUnguarded(theme: 'light' | 'dark'): Promise<void>return;}+ // The reclaim above can wait several seconds; a caller-bound condition (an+ // Agent install's confirming account) is re-checked after it, at the last+ // point where not restarting is still possible.+ if (options?.shouldProceed && !options.shouldProceed()) {+ log.info('executeRelaunch() cancelled by caller condition; patch remains staged');+ isRelaunching = false;+ autoRelaunchInProgress = false;+ return;+ }+log.info('Executing relaunch with file: %s (%s bytes)',maskPath(readyFilePath), fs.statSync(readyFilePath).size,@@ -2173,6 +2194,8 @@ export type AgentConfirmedAppUpdateResult =export async function applyConfirmedAppUpdateForAgent(options: {expectedVersion?: string;beforeRelaunch: () => Promise<boolean>;+ /** Re-checked inside the relaunch, after Subagent reclaim and right before the updater spawns. */+ beforeSpawn?: () => boolean;}): Promise<AgentConfirmedAppUpdateResult> {const versionChanged = (): AgentConfirmedAppUpdateResult | null =>options.expectedVersion && readyVersion !== options.expectedVersion@@ -2205,7 +2228,18 @@ export async function applyConfirmedAppUpdateForAgent(options: {const changedBeforeRelaunch = versionChanged();if (changedBeforeRelaunch) return changedBeforeRelaunch;const targetVersion = readyVersion;- await executeRelaunch(resolvedRelaunchTheme);+ // Both bindings are re-checked once more inside the relaunch, after its+ // Subagent reclaim wait: the confirmed version and the caller's condition.+ let cancelledBeforeSpawn: AgentConfirmedAppUpdateResult | null = null;+ await executeRelaunch(resolvedRelaunchTheme, {+ shouldProceed: () => {+ cancelledBeforeSpawn = versionChanged() ?? (options.beforeSpawn?.() === false+ ? { status: 'failed', reason: '更新已下载,但本次没有重启。', errorCode: 'relaunch_cancelled' }+ : null);+ return cancelledBeforeSpawn === null;+ },+ });+ if (cancelledBeforeSpawn) return cancelledBeforeSpawn;// 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