Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): recheck subscribed authorization and guard credential actions
zqchris703270ddc534
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationHost.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationHost.test.tsindex c23bf59aa2..03665378c9 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationHost.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationHost.test.ts@@ -76,6 +76,17 @@ describe('authorization Host frozen plugin policy', () => {});});+ it.each(['oauth_connect', 'inline_form'] as const)('checks the action generation after asynchronous Host validation for %s', async (kind) => {+ const adapter = await state.deps.adapter('session', target);+ let current = true;+ const executing = adapter.execute({ id: 'connect', kind } as never, undefined,+ kind === 'inline_form' ? 'fake-secret' : undefined, undefined,+ () => { if (!current) throw new Error('card cleared or rewound'); });+ current = false;+ await expect(executing).rejects.toThrow('card cleared or rewound');+ expect(state.execute).not.toHaveBeenCalled();+ });+it('rejects a card prepared before a clear even when its timestamp is newer', async () => {let generation = 0;initializeBotAuthorizationHost(async () => {}, () => {diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationService.test.tsindex c8ce6bf5c8..53113bfbca 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationService.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botAuthorizationService.test.ts@@ -661,3 +661,19 @@ it('retires a cancelled entry when its terminal save fails so a later request isexpect(h.adapter.execute).toHaveBeenCalledTimes(1);await h.service.dispose();});++it('reassesses after saving the subscribed card when readiness changed before subscribe', async () => {+ const h = harness();+ const required = await h.adapter.assess();+ // Return a stale read while completing configuration before the caller attaches.+ h.adapter.assess = vi.fn<BotAuthorizationAdapter['assess']>(async () => {+ return { state: 'ready' as const, revision: 2, groups: [] };+ }).mockImplementationOnce(async () => {+ h.complete();+ return required;+ });+ await h.service.request('s', { kind: 'plugin', id: 'p' });+ expect(h.deps.resume).toHaveBeenCalledTimes(1);+ expect(h.card().snapshot.terminal).toBe(true);+ await h.service.dispose();+});diff --git a/apps/desktop/src/main/maker-ipc/botAuthorizationHost.ts b/apps/desktop/src/main/maker-ipc/botAuthorizationHost.tsindex d90ddb0f5d..8eb0f506ab 100644--- a/apps/desktop/src/main/maker-ipc/botAuthorizationHost.ts+++ b/apps/desktop/src/main/maker-ipc/botAuthorizationHost.ts@@ -156,8 +156,9 @@ export function initializeBotAuthorizationHost(};},subscribe: (wake) => bus.subscribe('host:grok', wake),- async execute(_action, _sender, _value, onAuthorizationUrl) {+ async execute(_action, _sender, _value, onAuthorizationUrl, assertCurrent) {await assertSession(sessionId);+ assertCurrent?.();const result = await runGrokOAuthLogin({ onAuthorizationUrl });await assertSession(sessionId);if (result.ok) {@@ -224,8 +225,9 @@ export function initializeBotAuthorizationHost(if (event.source === 'oauth') reconnected = true;wake();}),- async execute(action, sender, value, onAuthorizationUrl) {+ async execute(action, sender, value, onAuthorizationUrl, assertCurrent) {await validate();+ assertCurrent?.();const release = acquireGhostMutationLeaseForMcp(captureGhostMutationOwnerForMcp());try {if (action.kind === 'inline_form') {diff --git a/apps/desktop/src/main/maker-ipc/botAuthorizationService.ts b/apps/desktop/src/main/maker-ipc/botAuthorizationService.tsindex 4293f38b3f..f16e47c6ce 100644--- a/apps/desktop/src/main/maker-ipc/botAuthorizationService.ts+++ b/apps/desktop/src/main/maker-ipc/botAuthorizationService.ts@@ -54,6 +54,7 @@ export interface BotAuthorizationAdapter {sender?: GhostSetupInteractionResponseTarget,value?: string,onAuthorizationUrl?: (url: string) => void,+ assertCurrent?: () => void,): Promise<GhostSetupActionResult>;}export interface BotAuthorizationDeps {@@ -168,6 +169,8 @@ export class BotAuthorizationService {this.close(entry);throw error;}+ // subscribe() does not replay changes between the first read and attachment.+ await this.check(entry).catch(this.deps.warn);return this.waitingResult(card);}@@ -332,6 +335,11 @@ export class BotAuthorizationService {value?: string,) {if (entry.action) return;+ const assertBoundary = this.deps.captureRequestGuard?.(entry.card.sessionId);+ const assertCurrent = () => {+ if (entry.closed || entry.cancelled) throw new Error('Authorization action is no longer active');+ assertBoundary?.();+ };entry.action = (async () => {// Re-resolve the adapter at the action boundary: current owner, bot and plugin policy win.await this.deps.adapter(entry.card.sessionId, entry.card.target);@@ -360,7 +368,7 @@ export class BotAuthorizationService {entry.authorizationUrl = url;entry.card.snapshot.reopenActionId = 'reopen-authorization';void this.phase(entry, 'waiting_external', actionId).catch(this.deps.warn);- });+ }, assertCurrent);if (entry.closed) return;if (!result.ok) {this.stopPoll(entry);@@ -394,8 +402,10 @@ export class BotAuthorizationService {sender: GhostSetupInteractionResponseTarget | undefined,value: string | undefined,onUrl: (url: string) => void,+ assertCurrent: () => void,): Promise<GhostSetupActionResult> {- if (action.kind !== 'oauth_connect') return entry.adapter.execute(action, sender, value, onUrl);+ assertCurrent();+ if (action.kind !== 'oauth_connect') return entry.adapter.execute(action, sender, value, onUrl, assertCurrent);const key = `${entry.card.target.kind}:${entry.card.target.id}:${action.id}`;let flight = this.oauthFlights.get(key);if (!flight) {@@ -411,7 +421,7 @@ export class BotAuthorizationService {.execute(action, sender, value, (url) => {next.url = url;for (const listener of next.listeners) listener(url);- })+ }, assertCurrent).finally(() => this.oauthFlights.delete(key));flight = next;} else {