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): #730 review 收口——权限阶段手势取消、录音中创建豁免收窄 (#737)

Dash93b591527c11
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 9bf0354df0..fb871f4f49 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -3697,6 +3697,19 @@ export default function SessionScreen() {
return () => subscription.remove();
}, [cancelVoiceForAppBackground]);
+ // 手势被系统/滚动终止时的撤销:比 app 后台版多一步——同时作废还开着的麦克风
+ // 权限请求。后台版必须让权限弹窗存活(见上方 AppState 注释:权限弹窗会短暂
+ // 触发 background),手势取消恰相反:首次使用时按下即录会先弹权限,此时
+ // startupInFlight/controller 都还是 false,只作废预热不够——权限批准归来后
+ // 启动会继续、麦克风开录,而那次按下早已被取消(review P1)。
+ const cancelVoiceForGestureTermination = useCallback(() => {
+ voicePermissionRequestSeqRef.current += 1;
+ voicePermissionRequestAbortRef.current?.abort();
+ voicePermissionRequestAbortRef.current = null;
+ voicePermissionRequestInFlightRef.current = false;
+ cancelVoiceForAppBackground();
+ }, [cancelVoiceForAppBackground]);
+
useEffect(() => {
return () => {
const controller = voiceControllerSessionRef.current;
@@ -3882,7 +3895,7 @@ export default function SessionScreen() {
// 正常松手(含拖出按钮后松开)不走这里,对齐桌面「pointercancel 才撤销」。
if (!voiceStartedOnPressInRef.current) return;
voiceStartedOnPressInRef.current = false;
- cancelVoiceForAppBackground();
+ cancelVoiceForGestureTermination();
}}
style={[
styles.composerInlineToolButton,
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index fbab0ecdcf..19d0bd26b1 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -135,6 +135,7 @@ import {
buildRecentWorkspaceOptions,
filterRemoteDirectoryEntries,
normalizeCreateSessionResult,
+ isNewSessionDraftMissingPayloadOnly,
parseNewSessionDeviceOptions,
pickAgentDefaultRuntime,
pickInitialNewSessionWorkspace,
@@ -782,10 +783,22 @@ export default function NewRemoteSessionScreen() {
const deviceSelectorDisabled = creating || voiceIsProcessing || !deviceHasChoices;
// 上传中不再挡创建:附件走乐观管线(pendingUploads),create() 内部会 await 全部
// 在途上传落定后再组首条消息,抢点创建不会丢图(#589 的 attachmentBusy 门由此取代)。
- // listening 时豁免「缺正文/附件」校验:此刻点创建 = 结束录音并用转写创建
- // (create() 的 listening 分支),最终转写在 create() 内部重新校验;不豁免的话
- // 空草稿录音期间创建按钮永远按不动,「点创建停录并创建」形同虚设(review P1)。
- const canCreate = (!createValidation || voiceIsListening) && !creating && !voiceIsProcessing;
+ // listening 时**只**豁免「缺正文/附件」这一条校验:此刻点创建 = 结束录音并用
+ // 转写创建(create() 的 listening 分支),最终转写在 create() 内部重新校验;
+ // 不豁免的话空草稿录音期间创建按钮永远按不动。缺项目路径/模型等其它校验不
+ // 豁免——那些不会被转写补上,放行只会「可点但必失败」(review 二轮收窄)。
+ // validateNewSessionDraft 的校验顺序是 路径→模型→正文,命中缺正文文案即代表
+ // 前两项都已通过。
+ // 结构化判定,不比对本地化文案:locale 异步恢复(如深链直达后语言落地)时
+ // memo 住的旧语言校验文案与新 t() 输出不等,字符串比对会让豁免静默失效
+ // (review 三轮收口)。
+ const createValidationIsMissingPayload = useMemo(
+ () => isNewSessionDraftMissingPayloadOnly(draft, draftContent),
+ [draft, draftContent],
+ );
+ const canCreate = (!createValidation || (voiceIsListening && createValidationIsMissingPayload))
+ && !creating
+ && !voiceIsProcessing;
const voiceIsBusy = voiceIsListening || voiceIsProcessing;
// 录音计时(红点+m:ss 胶囊,与会话页/桌面同形态);pillWidth 同步驱动工具排占位。
// counting 只认真实采集,启动链路(权限弹窗等)不计入时长,pending 期显示 0:00。
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index fdb98e6f11..117b383667 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -863,8 +863,14 @@ describe('new session composer surface', () => {
// 语音生命周期内创建按钮常驻(2026-07-25 对齐桌面):录音中点创建=结束录音并
// 用转写创建;否则首段转写落地瞬间按钮冒出来会把语音胶囊整格推左。
expect(newSource).toContain("|| voiceStartPending\n || voiceState === 'listening'\n || voiceState === 'submitting'\n || voiceState === 'refining';");
- // listening 时豁免缺正文校验:点创建 = 停录并用最终转写创建(review P1)。
- expect(newSource).toContain('const canCreate = (!createValidation || voiceIsListening) && !creating && !voiceIsProcessing;');
+ // listening 时只豁免「缺正文/附件」校验(路径/模型等其它校验不放行,
+ // 否则按钮可点但必失败):点创建 = 停录并用最终转写创建(review 二轮收窄)。
+ // 判定必须是结构化的 isNewSessionDraftMissingPayloadOnly,禁止比对本地化
+ // 文案——locale 异步恢复时字符串比对会静默失效(review 三轮收口)。
+ expect(newSource).toContain('isNewSessionDraftMissingPayloadOnly(draft, draftContent)');
+ expect(newSource).not.toContain("=== t('session.new.enterFirstMessageOrAttachment')");
+ expect(newSource).toContain('const canCreate = (!createValidation || (voiceIsListening && createValidationIsMissingPayload))');
+ expect(newSource).not.toContain('(!createValidation || voiceIsListening) &&');
expect(newSource).toContain('const composerShowCreateButton = composerHasMessage');
expect(newSource).toContain('const deviceSelectorDisabled = creating || voiceIsProcessing || !deviceHasChoices;');
// 按下即录(pressIn 起录):同一手势的松手由 voiceStartedOnPressInRef 吞掉,
diff --git a/apps/mobile/src/session/newSession.ts b/apps/mobile/src/session/newSession.ts
index 6ee8c44fe6..9392a7919e 100644
--- a/apps/mobile/src/session/newSession.ts
+++ b/apps/mobile/src/session/newSession.ts
@@ -159,6 +159,22 @@ export function validateNewSessionDraft(
return null;
}
+/**
+ * 校验失败是否**仅**缺正文/附件(项目路径与模型均已通过)。
+ * 语音听写中「点创建 = 停录并用转写创建」的豁免判定:只有这一类失败会被
+ * 最终转写补上,才允许放行。结构化判定,与 validateNewSessionDraft 同模块
+ * 同顺序维护——不要在调用方比对本地化文案(locale 异步恢复时 memo 住的
+ * 旧语言文案与新 t() 输出不等,豁免会静默失效)。
+ */
+export function isNewSessionDraftMissingPayloadOnly(
+ draft: NewSessionDraft,
+ content: NewSessionDraftContentState = {},
+): boolean {
+ if (draft.workspaceKind === 'project' && !draft.workingDir.trim()) return false;
+ if (!draft.model.trim()) return false;
+ return !hasFirstMessagePayload(draft, content);
+}
+
export function summarizeNewSessionDraft(
draft: NewSessionDraft,
content: NewSessionDraftContentState = {},