Skip to content

fix(acp): hide other choice in question card when allow_other is false - #1131

Open
ana52070 wants to merge 4 commits into
spacering-net:mainfrom
ana52070:fix/ask-question-allow-other
Open

ana52070 wants to merge 4 commits into
spacering-net:mainfrom
ana52070:fix/ask-question-allow-other

Conversation

@ana52070

Copy link
Copy Markdown
Contributor

问题

在当前 Codeg 中,Antigravity 和 Pi Select 渠道通过 ACP 原生权限(session/request_permission)桥接会话提问交互。

  • ACP 权限响应协议仅支持传递预设选项的 optionId 枚举,底层运行时(如 Antigravity 内部的 localharness 和 agy_acp_server)会将传入的 option_id 转换为预设索引,无法承载自由文本。
  • 然而前端 AskQuestionCard 始终无差别渲染“其他”(Other)选项和输入框。
  • 当用户在 Antigravity 提问卡片中选择“其他”并输入自由文本后,后端 antigravity_option_id 无法匹配任何预设选项,Codeg 只能以 RequestPermissionOutcome::Cancelled 回应权限请求。
  • Antigravity 接收到 Cancelled 后直接视为用户放弃/未回复(unanswered=True),导致用户辛辛苦苦输入的文字被静默吞掉、当成交互取消。

改动

采用方案 A(标准协议与渲染解耦):在 QuestionSpec 中增加 allow_other 标识,仅允许支持自由文本的渠道显示“其他”,避免误导用户。

  1. 后端数据结构与解析适配(Rust / src-tauri):

    • 在 QuestionSpec 中增加 allow_other: bool 字段,通过 #[serde(default = "default_true")] 默认向后兼容为 true。
    • 在原生权限桥接 parse_antigravity_ask 与 parse_pi_select_ask 中,明确标记 allow_other: false。
    • 在支持自由文本的渠道(parse_questions、parse_grok_ext_questions、parse_form_questions、parse_cursor_ask_questions)中保持 allow_other: true。
    • 在历史卡片输入构造 grok_result_card_input 中透传 "allowOther": s.allow_other,确保历史消息与实时提问卡片表现一致。
  2. 前端卡片渲染与类型适配(TypeScript / React / src):

    • 在 QuestionSpec (src/lib/types.ts) 中补充 allow_other?: boolean;在 AskQuestion (src/lib/ask-question.ts) 中补充 allowOther?: boolean 并进行容错解析。
    • 在 AskQuestionCard (src/components/chat/ask-question-card.tsx) 中:
      • 单选分支:当 q.allow_other === false 时,隐藏 RadioGroup 中的“其他”条目及输入框。
      • 多选分支:当 q.allow_other === false 时,隐藏 Checkbox 中的“其他”条目及输入框。
      • 卡片高度估算 maxRows 动态根据 allow_other 状态计算,避免隐藏“其他”后留出多余空白。
    • 在 AskQuestionResultCard 中透传 allow_other 字段。
  3. 双端自动化测试:

    • 前端 Vitest:
      • src/components/chat/ask-question-card.test.tsx:新增单选和多选下 allow_other: false 时隐藏“其他”选项及输入框的断言,全量 33 个用例全部 PASS。
      • src/lib/ask-question.test.ts:兼容缺失与显式标记,57 个用例全部 PASS。
    • 后端 Rust (question.rs):增加 parse_antigravity_ask 和 parse_pi_select_ask 的 allow_other == false 断言,以及标准解析下的 allow_other == true 断言。

界面与效果展示

1. Antigravity 提问卡片(allow_other: false)

  • 界面仅展示预设选项,不再显示“其他”单选项和自定义文本输入框,引导用户从预设选项中选择,交互响应 100% 成功映射为原生 optionId。

2. 标准问答与 Codex 卡片(allow_other: true)

  • 保持既有行为不受任何影响,用户仍可正常选择“其他”并输入自由文本。

测试

  • 本地规范与双端构建自检:
    • git diff --check:无格式与空白冲突。
    • 前端自动化测试:pnpm test src/components/chat/ask-question-card.test.tsx (33 tests) 与 src/lib/ask-question.test.ts (57 tests) 全部 PASS。
    • TypeScript 类型检查:pnpm tsc --noEmit 0 错误。
    • 静态页面导出:pnpm build 37/37 个静态页面全量导出成功。
    • 后端 Rust 检查:
      • cargo check --bin codeg 成功(0 error)。
      • cargo check --no-default-features --features server-bin --bin codeg-server 成功。
      • cargo check --no-default-features --features mcp-bin --bin codeg-mcp 成功。
  • Fork GitHub Actions CI 全矩阵预检:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant