feat(agent): GUI 工具目标发现、稳定引用与输入补齐(P1+P2) - #1335
Open
sheepbox8646 wants to merge 1 commit into
Open
sheepbox8646 wants to merge 1 commit into
sheepbox8646 wants to merge 1 commit into
Conversation
按 docs/computer-browser-capability-completion-plan.md 的 P1、P2 阶段实施, 基于 P0(#1328): - 新增 computer_context:get_state / list_apps / get_app / list_browsers / get_browser / documentation。应用经 a11y-cli apps 发现(app:<pid>), 浏览器按 --remote-debugging-port 发现(chrome-<port>);名称歧义返回候选, URL 只匹配现有标签页;launch=true 以独立 argv 启动并按 exec 审批治理。 - 所有浏览器调用接受 browser_id/tab_id(兼容 tab_index),桌面调用接受 app_id;缺省按 (bot, session) 保存,动作前冻结目标并回传 tab_source。 - ref 绑定 snapshot_id:浏览器把元素列表钉在页面上,导航/刷新使其失效; 桌面快照 id 写入 helper 引用索引(协议版本 3),跨快照 ref 被拒绝。 - 新增 set_value / paste / select_text / secondary_action,Browser 的 pages 滚动与 keydown/keyup 按键保持,Computer 的 xclip 剪贴板粘贴与恢复; 失败路径释放按住的按钮与修饰键;工作区镜像新增 xclip。 - 前端注册 computer_context 与新动作的图标和三语言标签;文档更新。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Sep 19, 2026
sheepbox8646
added this pull request to stack #1343
September 20, 2026 11:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Author
Type
Summary
Stacked PR,基于 #1328(P0)。实施
docs/computer-browser-capability-completion-plan.md的 P1(目标发现和稳定引用)与 P2(补齐输入和元素操作);P3–P5 将在后续 PR 中继续。合并顺序:#1328 → 本 PR。问题
ref只是重扫后的序号,页面变化后同一序号会落到别的元素上。改动
computer_context新工具(internal/agent/tool/computer_context.go)get_state:应用、浏览器、标签页与本会话选择,分域报错,不把一域失败伪装成空列表。list_apps/get_app:a11y-cli apps枚举无障碍总线上的应用,pid 由总线守护进程解析,app_id = app:<pid>;名称歧义返回候选 id;launch=true按 desktop entry / PATH / 绝对路径解析为独立 argv 启动(不拼 shell),并由审批策略按exec治理(approval.OperationForCall);启动后未注册到总线的进程(如 xterm)返回accessible: false的结构化结果。list_browsers/get_browser:按--remote-debugging-port发现 Chromium 实例,browser_id = chrome-<port>,只有默认工作区浏览器按需启动;URL 只用于匹配现有标签页,多个匹配返回候选而不猜测。documentation:返回生成 schema 所用的动作契约(同一份规范)、身份/坐标/时序说明与各后端能力(含哪些动作明确不支持)。gui_session.go、gui_browsers.go):所有浏览器调用接受browser_id/tab_id(兼容tab_index,二者互斥),所有桌面调用接受app_id;缺省来自 per-(bot, session) 内存状态,不同会话互不覆盖;动作前冻结目标并在结果里返回browser_id/tab_id/tab_source。browser_id必须是发现返回的 id,URL、命令名在校验层即被拒绝。snapshot_id,ref 只在同一快照、同一标签页、元素仍在文档中时解析;导航/刷新/历史使其失效,不重新编号。桌面快照的snapshot_id写入 helper 引用索引(协议版本升到 3),动作携带--snapshot,跨快照 ref 被拒绝;Go 侧还要求本会话最近快照覆盖所选应用。set_value(原生 setter + input/change;select 校验选项)、paste(真实paste事件携带 text/plain 与 text/html,未被消费时 contenteditable 走 insertHTML、字段走 insertText)、select_text(prefix+text+suffix唯一匹配,重复/缺失分别报错,支持选中与光标前后)、secondary_action(明确返回不支持)、scroll支持pages、keydown/keyup在会话内跟踪按住的键并作用于后续press;fill改为选中全部后经输入管线替换并回读校验;focus返回实际焦点。set_value(EditableText 或 Value 接口;按钮等控件明确不支持)、select_text(AT-SPI Text 选区/光标)、secondary_action(只执行快照actions=列出的动作,未列出返回可用列表)、paste(xclip 剪贴板:保存 → 写入 → 聚焦 → Ctrl+V → 恢复,粘贴期间被改动则保留,按 bot 串行;工作区镜像新增xclip)。快照行新增actions=与app_pid。press失败时释放本次按下的修饰键,mouseDrag中途失败也释放按钮;桌面drag失败补发释放,mouse_move/pointer保持的按钮在后续失败时释放。computer_context加入 GUI 工具集与工具调用标签(三语言),新动作补图标与 i18n。docs/agent-runtime.md补充目标身份、引用绑定与新输入动作说明;计划文档勾选 P1/P2 并附实施记录。Related Issues
依赖 #1328。
Validation
自动化
cargo fmt --check、cargo clippy --workspace --locked -D warnings、cargo test --workspace --locked:45 项通过。go test ./...:全量通过(internal/agent/tool新增契约、目标解析、会话隔离、快照绑定等测试;internal/agent/decision/approval新增 launch 按 exec 治理的测试)。golangci-lint run ./...:无问题。pnpm exec eslint变更的 TS 文件:无问题;vitest工具注册相关用例通过(panel-preview.test.ts与session-info-ring.test.ts两个失败在未改动的 main 上同样失败,与本 PR 无关)。真实运行环境
memoh-cua(Serverhttp://localhost:19880,Webhttp://localhost:19882),工作区镜像用scripts/prepare-dev-workspace-image.sh从本分支重建(含协议 3 的a11y-cli与xclip),server 重启重新导入,Bot 工作区重建后a11y_available: true。exec启动两台xfce4-terminal --disable-server与第二个 Chromium(端口 9223)→list_apps→get_app "xfce4-terminal"返回「2 running applications match … app:17257, app:17258」→get_app app:17257选中并返回应用级快照(45 个 ref)→get_app "xfce4-appfinder" launch=true通过工具启动并选中(130 个 ref,launched.source: desktop)→list_browsers列出 chrome-9222(default,7 个标签页)与 chrome-9223 → 两次tab_new返回稳定tab_id→get_browser chrome-9223后无参数get_title返回「second-browser」(tab_source: active)→get_browser url=…tab-two…因此前运行留下两个同 URL 标签页而返回 2 个候选、不猜测 →get_state→get_app "mousepad" launch=true返回「no installed application…」→get_app "xterm" launch=true返回accessible: false(进程在运行但无 AT-SPI 树)→documentation browser_id=chrome-9223。snapshot_idb1a0b86e94c8-1)→tab_new使会话默认切到另一标签页 → 带tab_id的fill仍写入标签页 A(tab_source: explicit,evaluate回读一致)→ 不带 tab_id 的fill ref=e1因会话标签页从未观察而被拒绝 →navigate标签页 A 后旧 ref 被拒绝(「no element refs exist on this page (it was navigated…)」)→ 重新 snapshot 得到新snapshot_id后,携带旧snapshot_id的 ref 被拒绝(「belongs to snapshot … but this page currently holds …」)→ 桌面连续两次 snapshot 后携带上一次snapshot_id的click被 helper 拒绝(「observe again before acting」)。set_value「设置的值 🚀」→select_text "的值"后keyboard_type "新"得「设置新 🚀」→select_text "hello"在无匹配与 2 次匹配时分别报错 →prefix:"world "+cursor_after后输入「!」得「hello world hello!」→paste format=html被页面 paste 处理器消费(via: paste_event)→paste format=text走insert_text→secondary_action明确不支持 →scroll pages=1于 120px 容器返回scroll_before 0 → scroll_after 120→keydown Shift后press a页面记录shift=true,keyup后为false(页面事件日志见截图)。exec预置剪贴板「user clipboard」并启动应用查找器 →get_app选中 →set_value「set-value-text」(via a11y)→select_text "value"返回 4–9 →type于光标处插入 →fill ""清空 →paste「粘贴 pasted 🚀」后clipboard: restored,随后exec xclip -o读回「user clipboard」→ 截图显示输入框内容为「粘贴 pasted 🚀」→secondary_action "no-such-action"返回「available: Activate」→ 对按钮set_value返回「exposes neither EditableText nor Value」。pkill -f <字面量>会匹配到执行它的 shell 自身(命令行含同一字面量)而使整条命令以 143 退出,这是验证脚本的问题,不是工具缺陷,已改为变量拼接。upload、pdf未在真实 UI 中重新触发。Screenshots / Recordings
截图托管在分支
computer-p0/assets(shots/p1p2/)。Human QA
🤖 Generated with Claude Code