Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): scope incoming share draft protection to new tasks
Chris77d9565b4b6e
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsxindex 2b7e9b814d..36f414018a 100644--- a/apps/mobile/app/sessions/new.tsx+++ b/apps/mobile/app/sessions/new.tsx@@ -962,7 +962,7 @@ export default function NewRemoteSessionScreen() {}), [auth.getAccessToken, discardAllPendingUploads]);const incomingShareBatch = useIncomingShareBatch();const incomingShareReceivedRef = useRef(false);- if (incomingShareBatch) incomingShareReceivedRef.current = true;+ if (incomingShareBatch?.destination === 'new') incomingShareReceivedRef.current = true;const isShareTargetFocused = useIsFocused();useAutoResumeNewSessionDraft({enabled: !(params.recoverySessionId || params.editSessionId || params.draft || params.suggestiondiff --git a/apps/mobile/src/__tests__/useNewSessionDraftRecovery.test.tsx b/apps/mobile/src/__tests__/useNewSessionDraftRecovery.test.tsxindex 2cabd184fb..bf891c2b8f 100644--- a/apps/mobile/src/__tests__/useNewSessionDraftRecovery.test.tsx+++ b/apps/mobile/src/__tests__/useNewSessionDraftRecovery.test.tsx@@ -1,5 +1,8 @@// @vitest-environment jsdomimport { act, useState } from 'react';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import ts from 'typescript';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, expect, it, vi } from 'vitest';import { getMobileAuthOwner, setMobileAuthOwner } from '@/auth/authOwnerGeneration';@@ -309,3 +312,37 @@ it.each(['edited', 'cleared', 'failed'] as const)('keeps the edit claim throughexpect(container.textContent).toBe('remaining textModel unavailableEdit');}});++// Execute the page's real latch against delayed durable recovery. A global+// share must not make this composer own input destined for another screen.+const newPage = ts.createSourceFile('new.tsx', readFileSync(resolve(process.cwd(), 'app/sessions/new.tsx'), 'utf8'),+ ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);+let shareLatchSource = '';+function findShareLatch(node: ts.Node) {+ if (ts.isIfStatement(node) && ts.isExpressionStatement(node.thenStatement)+ && ts.isBinaryExpression(node.thenStatement.expression)+ && node.thenStatement.expression.left.getText(newPage) === 'incomingShareReceivedRef.current') {+ shareLatchSource = node.getText(newPage);+ }+ ts.forEachChild(node, findShareLatch);+}+findShareLatch(newPage);+if (!shareLatchSource) throw new Error('Missing new-task share ownership latch');+const applyShareLatch = new Function('incomingShareBatch', 'incomingShareReceivedRef',+ ts.transpileModule(shareLatchSource, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText);++it.each([undefined, 'device/task', 'companion/task', 'new'])(+ 'only protects the new-task draft for its selected share destination: %s', async destination => {+ const received = { current: false };+ resume.hasInput = () => received.current;+ await renderBlank();+ applyShareLatch({ id: 'share' }, received);+ if (destination) applyShareLatch({ id: 'share', destination }, received);+ // Cancellation or successful handoff removes the global batch.+ applyShareLatch(null, received);+ await act(async () => ready());+ await notify();+ expect(container.textContent).toBe(destination === 'new' ? '' : 'device/task');+ expect(outbox.find).toHaveBeenCalledTimes(destination === 'new' ? 0 : 1);+ },+);