Skip to content

docs: 修正 AGENT_RULES / AGENT_EVAL_GUIDE 中与 api_data / inputSchema 不符的 API 与代码#1

Open
2836603852 wants to merge 1 commit into
ascript-cn:mainfrom
2836603852:fix/agent-docs-api-accuracy
Open

docs: 修正 AGENT_RULES / AGENT_EVAL_GUIDE 中与 api_data / inputSchema 不符的 API 与代码#1
2836603852 wants to merge 1 commit into
ascript-cn:mainfrom
2836603852:fix/agent-docs-api-accuracy

Conversation

@2836603852
Copy link
Copy Markdown

背景

docs/AGENT_RULES.mddocs/AGENT_EVAL_GUIDE.md 会被原样粘进 AI 的 agent rules,所以其中的 API / 代码错误会随每个用 ascript-mcp 的 AI 一起“出货”。本 PR 只改能用本仓库自己的源证伪src/ascript_mcp/api_data/*.jsonsrc/ascript_mcp/local.py 的 inputSchema、src/ascript_mcp/device.py)的客观错误,纯文档、不动代码。两份文档里所有 Python 片段改后仍 ast.parse 通过。

AGENT_EVAL_GUIDE.md(eval 片段)

片段 问题 证据
A / C / F Ocr.find_all() 返回 list[dict](键 text/rect/center_x/center_y),但片段按对象访问 t.text / t.region_position.*AttributeError(C、F 未捕获直接崩,A 被外层 try 吞成空 OCR,静默失效)。已改为 dict 取值 android.jsonOcr.find_all docstring:Returns: list[dict]同文档片段 D 自己就用 r["center_x"](dict 取值),自相矛盾
F 节点框用 n.bounds(原注释即写 # 假设有 left/top/right/bottom);真实属性是 node.rect.left/top/right/bottom boundsandroid.json 中 0 命中

AGENT_RULES.md

改动 证据
§3.5 “globals 共享 / 不要 re-import” → 每次调用全新 globals,必须每次 re-import 与本仓库 AGENT_EVAL_GUIDE.md(“每次调用新建独立 globals 字典 … 变量不会跨调用保留”)及 device.py docstring(“请求级 fresh globals”)一致;原 §3.5 与这两处直接矛盾
§1.2 / §2.1 等(5 处) search_api(keyword=)search_api(query=) local.py search_api inputSchema 必填字段是 query
§2.1 get_code_example(scenario)(task, platform) local.py inputSchema required: ["task","platform"],无 scenario
§2.1 / §3.3 get_plugin_detail(id)(plugin_id) local.py inputSchema required: ["plugin_id"]
§1.2.1 Device.batteryDevice.battery() android.json Device.batterystaticmethod(漏括号会得到方法对象)
§4.4 / §4.6 Android Selector().className(...).type(...) android.json Selector 方法集有 type、无 className
§3.2 iOS Selector().text(...).label(...)Android .text() 保留不动 ios.json Selector 字段是 label/value/name/type、无 text
§4.6 m.rect.x1/.y1/.x2/.y2m.rect.left/.top/.right/.bottom 节点矩形属性为 left/top/right/bottom
§3.1 删除虚构常量 MODE_ACC_FILTERED=2 与“位掩码”说法,保留数字 mode=2/3 行为说明 android.json Selector 常量只有 MODE_ACC_SIMPLE/MODE_ACC_ALL/MODE_ASS/MODE_ROOT

另外注意到(本 PR 未改,供参考)

  • §1.2 / 平台速记 教 AI search_api("intent"/"broadcast"/"ContentProvider"),但这些在 android.json 中不存在(0 命中);真实间接通道是 system.open/browser/open_app_setting/shell + shizuku
  • §3.3 / 平台速记 写 “Windows 暂缺”,但 windows.json 已是完整平台(window.Selector、原生 Mouse/Keyboard、RapidOCR 等)。
  • §3.3 称 iOS “没有原生点击能力”,但 ios.jsonaction.click / Ocr.click(WDA 原生点击,仅“易被检测”)。

以上三处更偏设计/措辞,留给维护者决定,本 PR 未改。


🤖 Generated with Claude Code

…VAL_GUIDE

These docs get pasted into agent rules verbatim, so the bugs ship to every
AI coding against ascript-mcp. Each fix is verified against this repo's own
api_data/*.json, src/ascript_mcp/local.py inputSchemas, and device.py.

AGENT_EVAL_GUIDE.md (eval snippets A/C/F):
- Ocr.find_all() returns list[dict] (text/rect/center_x/center_y), not objects
  with .text/.region_position -> AttributeError (C/F crash uncaught, A silently
  drops OCR). Switch to dict keys. Evidence: android.json Ocr.find_all docstring
  "Returns: list[dict]"; snippet D already uses r["center_x"].
- Snippet F node box used n.bounds ("# 假设有..."); real attr is
  node.rect.left/top/right/bottom. Evidence: "bounds" absent from android.json.

AGENT_RULES.md:
- 3.5 "globals shared / don't re-import" -> fresh globals per call. Contradicts
  AGENT_EVAL_GUIDE.md ("每次调用新建独立 globals") and device.py docstring
  ("请求级 fresh globals").
- search_api(keyword=) -> search_api(query=)  [local.py inputSchema]
- get_code_example(scenario) -> (task, platform); get_plugin_detail(id) ->
  (plugin_id)  [local.py required inputSchema fields]
- Device.battery -> Device.battery()  [android.json: staticmethod]
- Android Selector.className() -> .type()  [android.json Selector has type, no className]
- iOS Selector.text() -> .label()  [ios.json Selector has label/value/name, no text]
- 4.6 m.rect.x1 -> m.rect.left  [node rect uses left/top/right/bottom]
- 3.1 drop invented constant MODE_ACC_FILTERED (only SIMPLE/ALL/ASS/ROOT exist)

All Python snippets in both docs still parse (ast.parse). Docs-only; no code change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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