Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 补送 #540 的 review 修复(合并竞态漏掉) (#657)
Dash454bde89f091
diff --git a/apps/mobile/src/__tests__/interactionModel.test.ts b/apps/mobile/src/__tests__/interactionModel.test.tsindex b2b3e344fb..99640d2aff 100644--- a/apps/mobile/src/__tests__/interactionModel.test.ts+++ b/apps/mobile/src/__tests__/interactionModel.test.ts@@ -217,11 +217,18 @@ describe('interactionModel', () => {// 取消出口:没有出口 + 卡接管输入框 = 会话锁死(线上已复现)。expect(interactionPanelSource).toContain("if (kind === 'plugin_setup')");expect(interactionPanelSource).toContain('buildPluginSetupCancelDecision(item.request)');- expect(interactionPanelSource).toContain('interaction.unsupported.cancelButton');- // 未知 kind 仍回退到 UnsupportedCard 的合并摘要:每行各自 numberOfLines 会把- // 总高度放大成 6 × 行数。- expect(interactionPanelSource).toContain("const summaryText = (summaryLines ?? [contentToPreview(request)])");+ // testID 与 UnsupportedCard 区分开,UI 测试才能精确定位这张卡的取消按钮(#540 review)。+ expect(interactionPanelSource).toContain('interaction.pluginSetup.cancelButton');+ expect(interactionPanelSource).not.toContain('interaction.unsupported.cancelButton');+ // 未知 kind 仍回退到 UnsupportedCard 的 request 预览,整段一次限行:每行各自+ // numberOfLines 会把总高度放大成 6 × 行数。+ expect(interactionPanelSource).toContain('const summaryText = contentToPreview(request);');expect(interactionPanelSource).not.toContain('lines.map((line, index)');+ // plugin_setup 移出 UnsupportedCard 后,当初为它加的形参不能留成没人走的分支。+ // 钉形参声明与 JSX 传参本身,不做全文匹配——注释里可以照常说明这段历史。+ for (const dead of ['summaryLines?:', 'summaryLines={', 'kindLabel?:', 'kindLabel={']) {+ expect(interactionPanelSource, dead).not.toContain(dead);+ }// 取消由被控端按 expectedRevision 裁决,不能乐观撤卡(撤了可能其实没取消);// 但仍要按该 revision 封顶抑制,否则取消前发出的慢快照会把卡写回来。expect(interactionPanelSource).toContain('optimisticDismiss: false');@@ -288,6 +295,8 @@ describe('interactionModel', () => {'interaction.pluginSetup.desktopActionHint','interaction.pluginSetup.inlineFormAction','interaction.pluginSetup.inlineFormActionGeneric',+ // 读屏聚合分隔符:硬编码「,」会让非中文 locale 念出中文标点(#540 review)+ 'interaction.pluginSetup.a11ySeparator',]) {expect(i18n.t(key), `${locale} ${key}`).not.toBe(key);}diff --git a/apps/mobile/src/i18n/locales/en/interaction.json b/apps/mobile/src/i18n/locales/en/interaction.jsonindex 3353028f1b..8f63ebe1b4 100644--- a/apps/mobile/src/i18n/locales/en/interaction.json+++ b/apps/mobile/src/i18n/locales/en/interaction.json@@ -182,9 +182,9 @@"pluginSetup": {"completeOnDesktop": "Complete this setup on the controlled desktop. This card will update automatically.","chooseOne": "Choose one setup method",- "stepsHeading": "Setup steps","progress": "{{satisfied}}/{{total}} completed","desktopActionHint": "On your computer: {{action}}",+ "a11ySeparator": ", ","phase": {"pending": "Pending","action_running": "In progress…",diff --git a/apps/mobile/src/i18n/locales/ja/interaction.json b/apps/mobile/src/i18n/locales/ja/interaction.jsonindex 72494a76c8..d2d8cde8b2 100644--- a/apps/mobile/src/i18n/locales/ja/interaction.json+++ b/apps/mobile/src/i18n/locales/ja/interaction.json@@ -182,9 +182,9 @@"pluginSetup": {"completeOnDesktop": "操作対象のデスクトップで設定を完了してください。このカードは自動的に更新されます。","chooseOne": "設定方法を1つ選択してください",- "stepsHeading": "設定手順","progress": "{{satisfied}}/{{total}} 完了","desktopActionHint": "パソコンで{{action}}",+ "a11ySeparator": "、","phase": {"pending": "設定待ち","action_running": "処理中…",diff --git a/apps/mobile/src/i18n/locales/ko/interaction.json b/apps/mobile/src/i18n/locales/ko/interaction.jsonindex 105d42cddb..882e648904 100644--- a/apps/mobile/src/i18n/locales/ko/interaction.json+++ b/apps/mobile/src/i18n/locales/ko/interaction.json@@ -182,9 +182,9 @@"pluginSetup": {"completeOnDesktop": "제어 중인 데스크톱에서 설정을 완료하세요. 이 카드는 자동으로 업데이트됩니다.","chooseOne": "설정 방법을 하나 선택하세요",- "stepsHeading": "설정 단계","progress": "{{satisfied}}/{{total}} 완료","desktopActionHint": "컴퓨터에서 {{action}}",+ "a11ySeparator": ", ","phase": {"pending": "설정 대기","action_running": "진행 중…",diff --git a/apps/mobile/src/i18n/locales/zh-CN/interaction.json b/apps/mobile/src/i18n/locales/zh-CN/interaction.jsonindex 4f5f0f26d9..9ce495b523 100644--- a/apps/mobile/src/i18n/locales/zh-CN/interaction.json+++ b/apps/mobile/src/i18n/locales/zh-CN/interaction.json@@ -182,9 +182,9 @@"pluginSetup": {"completeOnDesktop": "请在被控桌面完成设置,本卡片会自动更新状态。","chooseOne": "选择一种配置方式",- "stepsHeading": "配置步骤","progress": "{{satisfied}}/{{total}} 已完成","desktopActionHint": "在电脑端{{action}}",+ "a11ySeparator": ",","phase": {"pending": "待设置","action_running": "进行中…",diff --git a/apps/mobile/src/session/InteractionPanel.tsx b/apps/mobile/src/session/InteractionPanel.tsxindex 400ff89f49..50d3972996 100644--- a/apps/mobile/src/session/InteractionPanel.tsx+++ b/apps/mobile/src/session/InteractionPanel.tsx@@ -407,7 +407,6 @@ function InteractionItem({if (!requestId) {return (<UnsupportedCard- kind={kind}message={t('interaction.panel.missingRequestId')}request={item.request}touchLayout={touchLayout}@@ -450,7 +449,6 @@ function InteractionItem({if (kind === 'issue_confirm') {return (<UnsupportedCard- kind={kind}message={t('interaction.panel.issueConfirmUnsupported')}request={item.request}touchLayout={touchLayout}@@ -488,7 +486,6 @@ function InteractionItem({}return (<UnsupportedCard- kind={kind}message={t('interaction.panel.unsupportedType')}request={item.request}touchLayout={touchLayout}@@ -1417,7 +1414,7 @@ function PluginSetupCard({onPress={cancel.onPress}requestId={requestId}touchStyle={resolveButtonLayoutStyle(touchLayout, 'secondary')}- testID="interaction.unsupported.cancelButton"+ testID="interaction.pluginSetup.cancelButton"variant="secondary"/></View>@@ -1458,10 +1455,11 @@ function PluginSetupStepRow({ step }: { step: RemotePluginSetupStep }) {return (<View// 聚合成一个读屏单元:标题 / 状态 / 待办 / 错误分开念会把一步拆成四条碎片。+ // 分隔符走文案目录:硬编码「,」会让 en / ja / ko 的读屏念出中文标点。accessibleaccessibilityLabel={[step.title, phaseText, step.description, visibleActionHint, errorText].filter((part): part is string => !!part)- .join(',')}+ .join(t('interaction.pluginSetup.a11ySeparator'))}style={styles.pluginSetupStep}testID="interaction.pluginSetup.step">@@ -1486,60 +1484,31 @@ function PluginSetupStepRow({ step }: { step: RemotePluginSetupStep }) {);}+/**+ * 本端既处理不了、也没有可用出口的卡:缺 requestId 的残卡、issue_confirm,以及+ * 任何未知 kind。纯展示——`plugin_setup` 自 PluginSetupCard 起不再走这里,当时+ * 为它加的 cancel / busy / kindLabel / summaryLines 形参已随之失去调用方,一并+ * 移除,避免留下没人走的分支。+ */function UnsupportedCard({- busy = false,- cancel = null,- kind,- kindLabel,message,request,- requestId = null,- summaryLines,touchLayout,}: {- busy?: boolean;- /** 本端唯一能做的动作(目前只有 plugin_setup 的取消);null = 纯展示卡。 */- cancel?: { accessibilityLabel: string; label: string; onPress(): void } | null;- kind: string;- /** eyebrow 覆写;缺省是「暂不支持」。 */- kindLabel?: string;message: string;request: PendingInteraction['request'];- requestId?: string | null;- /**- * 可读摘要。**未提供**时才回退成 request 预览(未知类型只能这样交底);提供了- * 空数组表示「这类卡本来就该只显示标题」,不能再掉回 raw JSON —— 那正是本次要- * 消灭的展示(#530 review)。- */- summaryLines?: string[];touchLayout: InteractionTouchLayout;}) {const styles = useThemedStyles(makeStyles);const { t } = useTranslation();- // 合并成一段带换行的文本再限行:每行各自 numberOfLines={6} 会把总可见行数放大成- // 6 × 行数,步骤多时把卡撑得很高(#530 review)。- const summaryText = (summaryLines ?? [contentToPreview(request)])- .filter((line) => line.length > 0)- .join('\n');+ // 未知类型只能靠 request 预览交底;整段一次限行,不按行各自限行(每行各自+ // numberOfLines={6} 会把总可见行数放大成 6 × 行数,#530 review)。+ const summaryText = contentToPreview(request);return (<View style={cardStyle(styles, touchLayout)} testID="interaction.unsupported.card">- <Text style={styles.kind}>{kindLabel ?? t('interaction.panel.unsupportedKind')}</Text>+ <Text style={styles.kind}>{t('interaction.panel.unsupportedKind')}</Text><Text style={styles.cardTitle}>{message}</Text>{summaryText ? <Text style={styles.body} numberOfLines={6}>{summaryText}</Text> : null}- {cancel ? (- <View style={actionsStyle(styles, touchLayout)}>- <ResolveButton- accessibilityLabel={cancel.accessibilityLabel}- busy={busy}- label={cancel.label}- onPress={cancel.onPress}- requestId={requestId}- touchStyle={resolveButtonLayoutStyle(touchLayout, 'secondary')}- testID="interaction.unsupported.cancelButton"- variant="secondary"- />- </View>- ) : null}</View>);}diff --git a/packages/maker-shared/src/__tests__/interaction.test.ts b/packages/maker-shared/src/__tests__/interaction.test.tsindex 2a10a546f2..1dc56be1ac 100644--- a/packages/maker-shared/src/__tests__/interaction.test.ts+++ b/packages/maker-shared/src/__tests__/interaction.test.ts@@ -695,7 +695,7 @@ describe('interaction shared model', () => {expect(presentation.terminal).toBe(true);expect(presentation.stepCount).toBe(1);expect(presentation.groups).toEqual([{- id: 'a-group',+ id: 'ungrouped-0',anyOf: false,steps: [{id: 'a',@@ -715,6 +715,35 @@ describe('interaction shared model', () => {ghost: { id: 'g', name: 'G', iconDataUrl: 'https://example.com/icon.png' },}).iconDataUrl).toBeNull();+ // 远端重复用同一个 step id 且都缺 groupId 时,仍必须各自成组——只按 step.id 造+ // fallback key 会把它们并回一组,与「缺 groupId 各自成组」的语义矛盾(#540 review)。+ const duplicated = buildRemotePluginSetupPresentation({+ kind: 'plugin_setup',+ requestId: 's1',+ steps: [+ { id: 'same', title: '第一步' },+ { id: 'same', title: '第二步' },+ ],+ });+ expect(duplicated.groups.map((g) => g.id)).toEqual(['ungrouped-0', 'ungrouped-1']);+ expect(duplicated.groups.map((g) => g.steps.length)).toEqual([1, 1]);++ // 合成身份与被控端真实 groupId 共用命名空间:撞名时绝不能并组,否则两批互不+ // 相关的要求会被当成「二选一」,用户漏做另一半(#657 review)。+ const collided = buildRemotePluginSetupPresentation({+ kind: 'plugin_setup',+ requestId: 's1',+ steps: [+ { id: 'a', title: '无组步骤' },+ { id: 'b', title: '真实组步骤', groupId: 'ungrouped-0', groupMode: 'any_of' },+ ],+ });+ expect(collided.groups.map((g) => g.steps.map((s) => s.title))).toEqual([['无组步骤'], ['真实组步骤']]);+ // 展示 id 仍去重,渲染层拿它当 list key。+ expect(collided.groups.map((g) => g.id)).toEqual(['ungrouped-0', 'ungrouped-0-2']);+ // 撞名的真实组只有 1 步 → any_of 收敛为 false,不会误显示「任选其一」。+ expect(collided.groups.map((g) => g.anyOf)).toEqual([false, false]);+// 换个 kind 传进来必须返回空投影,而不是从任意 request 上刮字段让误用「看起来正常」。expect(buildRemotePluginSetupPresentation({kind: 'permission',diff --git a/packages/maker-shared/src/interaction.ts b/packages/maker-shared/src/interaction.tsindex 2e447f5041..78028a0567 100644--- a/packages/maker-shared/src/interaction.ts+++ b/packages/maker-shared/src/interaction.ts@@ -596,20 +596,28 @@ export function buildRemotePluginSetupPresentation(stepCount += 1;if (phase === 'satisfied') satisfiedCount += 1;- // 分组按首次出现顺序保留;groupId 缺失的步骤各自成组,不并进同一个「空组」。- const groupId = trimmedOrNull(rawStep.groupId) ?? `${step.id}-group`;- const existing = groupsById.get(groupId);+ // 分组按首次出现顺序保留。+ const rawGroupId = trimmedOrNull(rawStep.groupId);+ if (rawGroupId === null) {+ // 缺 groupId 的步骤各自成组,并且**不进 groupsById**:合成的 id 与被控端真实+ // groupId 共用一个命名空间,一旦撞名(远端某组恰好就叫合成出来的那个名字),+ // 两批互不相关的配置要求会被并成一组、还套上 any_of 语义,让用户以为「二选+ // 一」而漏做另一半(#657 review)。生成身份只用于本地展示,不参与查表。+ groups.push({ id: `ungrouped-${index}`, anyOf: false, steps: [step] });+ return;+ }+ const existing = groupsById.get(rawGroupId);if (existing) {existing.steps.push(step);if (rawStep.groupMode === 'any_of') existing.anyOf = true;return;}const group: RemotePluginSetupGroup = {- id: groupId,+ id: rawGroupId,anyOf: rawStep.groupMode === 'any_of',steps: [step],};- groupsById.set(groupId, group);+ groupsById.set(rawGroupId, group);groups.push(group);});@@ -618,13 +626,32 @@ export function buildRemotePluginSetupPresentation(iconDataUrl: inlineImageDataUrl(ghost?.iconDataUrl),intro: trimmedOrNull(request.intro),// 单项组没有「任选其一」的语义,提示只会让用户困惑。- groups: groups.map((group) => ({ ...group, anyOf: group.anyOf && group.steps.length > 1 })),+ groups: dedupeGroupIds(groups).map((group) => ({+ ...group,+ anyOf: group.anyOf && group.steps.length > 1,+ })),satisfiedCount,stepCount,terminal: request.terminal === true,};}+/**+ * 保证组 id 在本次投影内唯一(渲染层拿它当 list key)。+ *+ * 合成的 `ungrouped-*` 已经不参与合并,但仍可能与被控端某个真实 groupId 撞名;+ * 那只是展示身份重复,不该退化成重复 key。id 不回传被控端,改写是安全的。+ */+function dedupeGroupIds(groups: RemotePluginSetupGroup[]): RemotePluginSetupGroup[] {+ const used = new Set<string>();+ return groups.map((group) => {+ let id = group.id;+ for (let suffix = 2; used.has(id); suffix += 1) id = `${group.id}-${suffix}`;+ used.add(id);+ return id === group.id ? group : { ...group, id };+ });+}+function trimmedOrNull(value: unknown): string | null {if (typeof value !== 'string') return null;const trimmed = value.trim();