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。

fix(mobile): preserve shared drafts and avoid competing share navigation

Chrisc086ed6a526b
diff --git a/apps/mobile/app/+native-intent.ts b/apps/mobile/app/+native-intent.ts
index 085d967b84..8aef3e24ae 100644
--- a/apps/mobile/app/+native-intent.ts
+++ b/apps/mobile/app/+native-intent.ts
@@ -3,7 +3,7 @@
// auth-server 回调 cindycn://auth / cindy://auth 与 Share Extension 的
// cindycn://expo-sharing / cindy://expo-sharing 都没有对应路由页,默认会落到
// expo-router 的 +not-found(「Unmatched Route」白屏)。这里在冷启动时把认证回跳重定向到首页,热回跳保留当前页面;分享跳到
-// 新建任务页;分享 payload 由根级 IncomingShareBridge 独立领取。
+// 目标选择页由根级 IncomingShareBridge 在确认待领取 payload 后统一打开。
//
// 实际的 PKCE code 交换**不依赖路由**:由 src/auth/AuthContext.tsx 的 Linking.addEventListener /
// getInitialURL 监听器独立捕获原始 URL 并完成(见其 handleDeepLink)。本文件只负责别让路由 404。
@@ -45,7 +45,8 @@ export function redirectSystemPath({ path, initial }: { path: string; initial: b
if (pathname === '/auth') return initial ? '/' : null;
// A restored launch URL is not proof of an unconsumed share. On cold start,
// let IncomingShareBridge navigate only after reading an actual pending batch.
- if (pathname === '/expo-sharing') return initial ? '/' : '/sessions/new';
+ // Warm callbacks must not race that bridge with a second navigation.
+ if (pathname === '/expo-sharing') return initial ? '/' : null;
// Invalid invitations must not leave secrets in router state or diagnostics.
if (pathname === '/shared-session' || pathname === '/shared-task/join') {
clearSharedTaskInvitationIntent();
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index 9f9dd72d37..2b7e9b814d 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -971,12 +971,6 @@ export default function NewRemoteSessionScreen() {
hasInput: hasRecoveryInput,
onResume: next => router.setParams(next),
});
- useIncomingShareComposer({
- destination: 'new', ready: isShareTargetFocused && newSessionPreferencesLoaded && !creating,
- appendText: text => setDraft(current => ({ ...current, firstMessage: [current.firstMessage, text].filter(Boolean).join('\n\n') })),
- attachmentCount: attachments.length,
- enqueueUploads, getPendingUploadCount, onError: setAttachmentError,
- });
const pendingGoalSkillRef = useRef<string | null>(null);
useEffect(() => {
pendingGoalSkillRef.current = null;
@@ -1922,6 +1916,13 @@ export default function NewRemoteSessionScreen() {
voiceDictionaryLearningTrackerRef.current?.inspectDraft(value);
}, [editRecoveredDraft]);
+ useIncomingShareComposer({
+ destination: 'new', ready: isShareTargetFocused && newSessionPreferencesLoaded && !creating,
+ appendText: text => setFirstMessageDraft(current => [current, text].filter(Boolean).join('\n\n')),
+ attachmentCount: attachments.length,
+ enqueueUploads, getPendingUploadCount, onError: setAttachmentError,
+ });
+
const handleFirstMessageInputContentSizeChange = useCallback((event: TextInputContentSizeChangeEvent) => {
const nextHeight = Math.max(
MOBILE_COMPOSER_INPUT_SINGLE_LINE_HEIGHT,
diff --git a/apps/mobile/src/__tests__/nativeIntent.test.ts b/apps/mobile/src/__tests__/nativeIntent.test.ts
index c86474732e..c161623194 100644
--- a/apps/mobile/src/__tests__/nativeIntent.test.ts
+++ b/apps/mobile/src/__tests__/nativeIntent.test.ts
@@ -136,7 +136,7 @@ describe('mobile native deep-link redirects', () => {
}
});
- it('waits for a pending batch on cold start and preserves the warm share handoff', () => {
+ it('lets the pending-batch bridge own cold and warm share navigation', () => {
expect(redirectSystemPath({
path: 'cindycn://expo-sharing',
initial: true,
@@ -144,7 +144,7 @@ describe('mobile native deep-link redirects', () => {
expect(redirectSystemPath({
path: '/expo-sharing?source=share-extension',
initial: false,
- })).toBe('/sessions/new');
+ })).toBeNull();
});
it.each(['cindy://auth?code=fixture&state=fixture', 'cindycn://auth?error=access_denied&state=fixture', '/auth?code=fixture'])('keeps the current route for warm OAuth callbacks: %s', path => {
diff --git a/apps/mobile/src/__tests__/newSessionIncomingShare.test.ts b/apps/mobile/src/__tests__/newSessionIncomingShare.test.ts
index eb45002928..11129c295c 100644
--- a/apps/mobile/src/__tests__/newSessionIncomingShare.test.ts
+++ b/apps/mobile/src/__tests__/newSessionIncomingShare.test.ts
@@ -50,3 +50,46 @@ it.each([['', false], ['new-host', false], ['old-host', true]] as const)(
else expect(bindings.setAttachments).not.toHaveBeenCalled();
},
);
+
+it('keeps shared text when opening plugins without typing first', async () => {
+ const { appendComposerPluginTrigger } = await import('@/session/composerPlugins');
+ const { textComposerDocument, composerDocumentProjectedText } = await import('@/session/composerDocument');
+ const names = ['setFirstMessageDraft', 'patchDraft', 'openPluginPalette'];
+ const declarations: string[] = [];
+ let appendText = '';
+ function collect(node: ts.Node) {
+ if (ts.isVariableDeclaration(node) && names.includes(node.name.getText(page))
+ && node.initializer && ts.isCallExpression(node.initializer)) {
+ declarations.push(`const ${node.name.getText(page)} = ${node.initializer.arguments[0].getText(page)};`);
+ }
+ if (ts.isCallExpression(node) && node.expression.getText(page) === 'useIncomingShareComposer') {
+ const options = node.arguments[0];
+ if (ts.isObjectLiteralExpression(options)) {
+ const property = options.properties.find(p => ts.isPropertyAssignment(p) && p.name.getText(page) === 'appendText');
+ if (property && ts.isPropertyAssignment(property)) appendText = property.initializer.getText(page);
+ }
+ }
+ ts.forEachChild(node, collect);
+ }
+ collect(page);
+ expect(appendText).not.toBe('');
+ let draft = { firstMessage: 'Existing instruction' };
+ const ref = { current: draft.firstMessage };
+ const bindings = {
+ firstMessageRef: ref, creatingRef: { current: false }, editRecoveredDraft: vi.fn(),
+ voiceDictionaryLearningTrackerRef: { current: null },
+ setDraft: (update: (current: typeof draft) => typeof draft) => { draft = update(draft); },
+ appendComposerPluginTrigger, textComposerDocument, composerDocumentProjectedText,
+ firstMessageSelectionRef: { current: null }, setFirstMessageSelection: vi.fn(),
+ composerPillOpen: { onCollapsedPress: vi.fn() },
+ };
+ const source = ts.transpileModule(`${declarations.join('\n')}\nconst appendText = ${appendText};`, {
+ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None },
+ }).outputText;
+ const actions = new Function(...Object.keys(bindings), `${source}; return { appendText, openPluginPalette };`)(...Object.values(bindings));
+ actions.appendText('Shared webpage instruction');
+ actions.openPluginPalette();
+ expect(draft.firstMessage).toContain('Existing instruction\n\nShared webpage instruction');
+ expect(ref.current).toBe(draft.firstMessage);
+ expect(bindings.editRecoveredDraft).toHaveBeenCalledWith({ firstMessage: draft.firstMessage });
+});