desktop-hub
Provides macOS desktop automation capabilities: full-screen screenshots, window listing and state inspection via the accessibility tree, background app launching, mouse/keyboard actions (click, type, scroll, drag, hotkeys), region zoom, deterministic state verification, and AppleScript/JXA script execution via osascript.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
desktop-hub
A compact facade MCP server for macOS desktop automation. It exposes just 11 hand-written tools (~3.4k tokens of definitions) and lazily proxies to two full-featured computer-use MCP servers — cua-driver (56 tools, ~37k tokens as of 0.28.2; 61 tools and a third more text as of 0.55.0) and computer-use-mcp (64 tools, ~21k tokens) — plus native osascript. You keep every tool of both, but your context window pays ~3.4k tokens instead of ~58k or more — and the results come back as compact text the hub renders itself (a browser window's tree in ~5% of the characters of the upstream JSON).
中文说明在下方 · Gitee mirror 国内镜像 · Works with Claude Code and any MCP client.
Why
Registering both upstream servers directly costs ~58k context tokens or more per session just for tool definitions, while the high-frequency surface is small. This facade keeps the hot path cheap and the long tail reachable:
MCP client ──stdio──> desktop-hub (this server, 11 compact tools)
├─ lazy stdio child ──> cua-driver mcp (background desktop control, no cursor/focus steal)
├─ lazy stdio child ──> computer-use-mcp (AX tree, find_element, fill_form, Spaces…; spawned on first use)
└─ local osascript (AppleScript/JXA, true background scripting)Related MCP server: Computer Use MCP Server
Tools
Tool | What it does |
| Full-display screenshot, true screen pixels (→ cua |
| One line per titled window, on-screen first; |
| Launch an app in the background without stealing focus (→ cua) |
| One window as compact text: |
| click / double_click / right_click / type / key / hotkey / scroll / drag / set_value / menu. Targets by token, by |
| Up to 8 act steps in ONE round-trip, validated up front; stops at the first failure or doubtful effect and says which steps took effect |
| Deterministic assertions on window/element state after acting (→ cua |
| Cropped close-up of a window region for small text (→ cua) |
| AppleScript/JXA via local |
| Escape hatch: call ANY of the underlying tools directly |
| On-demand catalog / full JSON schema of underlying tools (tokens spent only when needed) |
Prerequisites
macOS (Apple Silicon or Intel), Node.js 18+ (developed on Node 26).
cua-driver — the macOS driver from the trycua/cua project (
libs/cua-driver). Install with their official one-liner, which placesCuaDriver.appin/Applicationsand symlinks~/.local/bin/cua-driver(exactly this hub's default path — no config needed):/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"Docs: https://cua.ai/docs/how-to-guides/driver/install. By default the current installer also connects Claude Code, Codex and Cursor to cua-driver directly and ends with
cua-driver test; its--no-connectand--no-testflags (orCUA_DRIVER_NO_CONNECT=1,CUA_DRIVER_NO_TEST=1) turn both off. Developed against cua-driver 0.28.2; on 2026-11-20 the whole suite and the live check intest/live/were also run against 0.55.0 (cua-driver --version). The driver ships a new version almost daily and its replies change between them (row grammar, refusal shapes, default limits; see Design notes): after a driver upgrade runnpm testand the live check.computer-use-mcp needs no manual install —
npxfetches@zavora-ai/computer-use-mcp@7.0.0automatically on firstdesk_call server:"oss"(one-time network access; a few seconds of spawn latency thereafter — the handshake timeout is already widened to 180s). Users in mainland China may want an npm registry mirror configured.
macOS permissions
Grant Accessibility and Screen Recording (System Settings → Privacy & Security) to CuaDriver.app — run
cua-driver permissions grantso the dialogs attribute to the app identity (grants then survive upgrades). Without them every screenshot/AX call fails with opaque errors.Grant the same two to your terminal / MCP host app — the oss backend runs as a plain node child of the host and inherits its TCC identity.
run_scripttriggers macOS's one-time Automation (Apple Events) prompt per target app on first use.
Install & register
git clone https://github.com/zty552252kevin-code/desktop-hub.git
cd desktop-hub
npm ci # not `npm install` — the code relies on SDK 1.30.0 internals pinned in the lockfile
claude mcp add desktop-hub -s user -- node "$(pwd)/server.mjs" # path must be absoluteMainland China mirror (kept in sync): git clone https://gitee.com/zty552252kevin/desktop-hub.git
If cua-driver or computer-use-mcp is also registered as a standalone MCP server — from an earlier setup, or by the cua installer's connect step — disable or remove that entry (claude mcp list shows it; e.g. disabledMcpServers in ~/.claude.json) so this hub takes over.
Verify
npm test # unit tests (pure, no desktop) then the end-to-end suite; the latter spawns the real driver for a few read-only calls and runs osascript
DESKTOP_HUB_TEST_OSS=1 npm test # also exercises the oss backend (slow first npx spawn, needs network)
node test/live/calc.mjs "$(pwd)/server.mjs" # optional live check: drives Calculator in the background (28 steps), then quit it yourself.
# Its button labels are the zh-CN ones; on another system language edit them (see the file header)The suite requires cua-driver installed with permissions granted — failures without them are setup issues, not hub bugs.
Environment variables
Var | Meaning | Default |
| Path to the cua-driver binary |
|
| npx spec for the oss backend (pinned deliberately; bump consciously) |
|
| Cap on the rendered window tree per result |
|
|
| off |
Design notes & pitfalls (hard-won)
What the model sees
Results are text the hub writes, not upstream JSON. Claude Code hands the model
structuredContentas raw JSON and drops thecontenttext blocks whenever a result carries one. A pass-throughwindow_statetherefore delivered the same tree twice (elements[]plustree_markdown, ~385 chars per element), silently lost every note the hub appended, and 27 of 191 real calls ran past the host's 50,000-character line and were spilled to a file the model then had to read with another tool.window_state,list_windows,actandact_batchnow return hub-rendered text only. Measured on 26 real browser trees: 2.8M chars of JSON become 140k (5%), the largest single tree 7.9k.Row format.
[n] Role "label" = "value"is AX-pressable;(n) …is indexed but inert — a third of real web rows, and an AX click on one is a silent no-op that still reports success. Rows without a number are static text. The app's menu bar (half of every tree, including the Apple menu's recent documents) is hidden unlessmenus:true. Output is cut at 20,000 chars (DESKTOP_HUB_MAX_TREE_CHARS) with a count of what was left out, never handed to the host to spill.The hub always walks the whole window;
queryfilters locally."a|b"or an array means any term. Matching is case-insensitive substring, tried as written first and, only if that finds nothing, ignoring whitespace (antd renders 确定 as确 定; but"创作 "with a trailing space is a deliberate way to exclude继续创作). The menu bar is not searched by default: a query for 关机 once matched the Apple menu's Shut Down instead of the page's button. Zero hits return the whole window when it is small, else the closest rows. With one to three hits in a large window each hit comes with the rest of its row or card (a loneDD0350says little without the cells beside it, and in a window too long to print no other call could fetch them).diff:truemeans "since you last saw the whole window", per window, independent of the query. The old baseline was keyed by query, so a model that varied its query — it always does — never had one; diff was used once in a month. A view the caller narrowed (query,max_depth,max_elements) does not advance the baseline; a whole-window look cut by the size cap does — otherwise a window past the cap would be re-sent in full on everydiff:true. When there is none, or most of the page changed, the full tree comes back with the reason in the first line.list_windowsprints one line per titled window, on-screen first; a typical desktop has ~90 windows of which ~75 are untitled helper surfaces (cursor overlays, autofill popovers). 20k chars became 1.1k. Each line carries size and top-left corner, and a window on another Space is markedother-Space.pid:<pid>lists every window of one process — the way to find an untitled sheet.Latency is mostly outside the hub — design for round trips, not milliseconds. Measured over 495 real hub calls: the tools themselves took 27 minutes in total, the model turns between them 137. A result that carries an image is followed by a turn about twice as long (median 19.5 s vs 10.5 s), whatever the image size; text volume barely moves it (10.0 s at <500 chars, 11.8 s at >12k) — its cost is context and spills. Hence: text first, screenshots as checkpoints (
tree:falseis a screenshot without an AX walk), several steps per call, and action replies that already say what changed. Downscaling or transcoding screenshots was evaluated and deliberately NOT done.
Tokens
cua retires a window's element tokens on every walk — the hub's own included (verified on 0.28.2: a newer
get_window_state, filtered or not, makes older tokensstale, and nothing executes; a walk under another session label or from another connection does the same, so there is no way to walk on the side. On 0.55.0, measured withtest/live/session_probe.mjs, a snapshot belongs to the session that read it: a walk under another label or from another connection leaves it valid, but a second walk in the same session — which is what the hub's own looks are — still retires it). Since every action reply now includes a fresh look, a naive hub would kill the model's tokens on each call. Instead the hub keeps the snapshots it showed, and which rows of each, and carries an older token over to the newest tree — under two conditions.Condition one: the model has seen every change since. Three designs that tried to recognise "the same control" from what surrounds it were each broken in review (by coordinates: delete a table row and the next row's button sits at the old spot; by the text of the nearest group: an actions column holds the same
[Edit][Delete]in every row; by a widening text signature: a confirm box that now names another project still holds the only[Delete]). The last one cannot be fixed by looking harder — the button really is the same button, it just acts on something else now. So the hub tracks, per snapshot, how far the model's knowledge reaches: a reply that lists every change (an uncut action report, an uncutdiff:true, or a look that found nothing changed) moves it forward. Aquerylook appends the changes too when they are few (a page with a ticking clock would otherwise cost a refusal on every second look). A token from a snapshot the model is not up to date on is refused once — nothing is sent — and the refusal itself lists what changed; the same step sent again is then accepted. Changes too large to list say so and ask for a fresh look. A snapshot is retired outright when the window changed unseen and the model was then handed the whole tree again. "Lists every change" is meant literally: a change line prints the first difference of a long text, so a value that changed in two places (a timestamp at the top, the payee at the end) counts as not listed, and tokens stay on hold; so does a new row whose text is longer than a row prints, and an unlabeled field whose tooltip and value changed together. A changed window title is an ordinary, listed change — a dirty marker or an unread count in the title must not void every token.Condition two: the control cannot be mistaken for another. A token is carried in exactly two cases. Either the newest walk is identical to the one the token came from, row for row — then it keeps its position. Or the control's name (role and label; the tooltip for an unlabeled icon) is the only one of its kind in the window, in the old tree and in the new one, the control is still there, and its ancestors are still its ancestors (old and new tree are aligned as two sequences by a longest common subsequence over row keys, never by coordinates). A control whose name repeats — the
[Delete]of every table row, the unlabeled fields of a form, the same icon on every card — is not followed across any change at all: the step is refused, nothing is sent, and the refusal lists up to six current candidates, nearest to the old position first, each with the text of its row or card. The earlier rule did follow such controls, by asking whether the record around them was still intact, and review kept finding a layout where "intact" was not enough: a slot that got another customer whose amount and date happened to match, a card holding a list of its own, a carousel that keeps slot numbers while the items rotate. A changed label is a different control (a toggle that already flipped) and is refused with the new name. On 22 pairs of real adjacent browser snapshots 63% of pressable rows carry over (854 of 1,345), none onto a row with another name, and none of the 789 rows whose name is unique was refused; what gets refused is 417 look-alikes and 74 rows that were renamed or gone.Controls are addressed by content:
findwithnear.find:{label:"删除", near:"DD1005"}is resolved on a fresh walk and keeps only the matches for which that text can be shown to sit next to the control. Which texts belong to a control is a fact about the page's meaning, and the tree only hints at it. Every rule that inferred it from containment was made to press the wrong row in review, one per round: "the largest container holding no other control of that name" (a lone[取消订单]owned its whole table), "no words on the control's side" (a schedule cell took its neighbour's text), "a container that repeats" (two sections and two panes look exactly like two cards), "the only one in its sheet" (a sheet holding a table). What survived are the two kinds of evidence that infer nothing about containers, andnearaccepts nothing else.Line: the text is a leaf row (or another control's label) on the control's visual line, with nothing from another line between them in reading order. The label of the group around a whole card is on nobody's line. A text taller than the control counts only when the control lies within its top and bottom, and never when it is more than twice as tall: a button level with the lower half of the next card's two-line title is not beside that title (round 10 pressed the left card's
删除that way; round 9 had done it with a three-line title). Text one or two pixels high — screen-reader-only labels — is skipped, and more than two hundred things at one height are no line at all — for every same-named control on that line or for none: one that sits a few pixels lower than its neighbours, or inside a clickable chip, scans a shorter line, and until round 13 it alone kept its line evidence there, so a text between it and the next one matched it alone and was pressed with no ambiguity reported. Several look-alikes on one line: a text between two of them counts for both and is reported as ambiguity, and when the line has words at both ends as well (张伟 [移除] 李四 [移除] 王五) the end texts count for nobody, because one record there has no control and the line does not say which. Round 8 still read the line's shape ("text, control, text, control" gives each the text in front); round 9 broke that with昵称 [编辑] 待审核 签名 [编辑].Row: the text is in the control's
AXRow, provided the control's own cell says nothing of its own (a cell that does is a record by itself — a calendar, a schedule) or the table repeats the control in that column.Matching is by whole words:
DD100is not found inDD1001,DD100-2,DD100-A,DD100_2orDD100.pdf,200not in¥1,200,张伟not in张伟明; what the user typed into a field is not a record's text (a search box holdingDD1005vouches for nothing beside it). There is no ranking among matches: two controls that both qualify are an ambiguity, and whennearmatches nothing,nthdoes not reach into some other list. Everything else — cards, panes, dialogs, pages without frames — is refused, nothing is sent, and the candidates are listed as tokens with their place in reading order (after "…"), for the model to pick one.Names. A row whose label IS the wanted text wins over rows that merely contain it (
密码vs确认密码) — as written first, then but for spacing and width forms: antd renders 确定 as确 定, and before round 10 a link确定并继续添加on the same page took the click because only it contained the label as written. Each step of that preference holds only if one of the rows it prefers is something the action can use. A heading删除over the buttons取 消删 除, or the word 评论 inside the tab评论 12, does not keep the click from the button (round 11: it went to the heading, or the button was not even listed); a heading设置above a button打开设置, or a text姓名beside a field请输入姓名, is an ambiguity and both are listed. "Can use", for a click, includes two kinds of row without a press action: a field (the click focuses it) and, outside web content, the text of a list or table row (the click selects it — a mail sidebar's 收件箱 has no press action at all). Among rows of ONE name the action's kind chooses: for a click an inert or disabled row gives way to a pressable one, and a value goes into the field of that name (text fields, pop-ups, sliders, number and date fields), not the button — and when that field is disabled, into nothing: both are listed. A label that matches two differently named things — the text订单 DD1005and the button删除 DD1005— is an ambiguity. A same-named row the action cannot use (a disabled[移除], marked[disabled]in every list) still divides its line, with or without words at the line's ends, and aneartext that sits beside it is refused with that said; the row's own title in front of the control (通知 · 有新订单时发短信 · [通知] · 全天) is not such a rival.One control or two. The inert text or icon inside a pressable match is that control when the match is its nearest pressable ancestor — a click on a link's text is a click on the link — and so is a control inside it that only repeats its name. A
[删除]button inside a row that is itself one big link is a control of its own, and so is a field. A bare text inside an unnamed clickable wrapper that holds nothing else (<span onclick>删除</span>in such a row) stays a candidate, and the press goes to the wrapper; the reply says so.Replies print whole tokens (
s0000012a:34 AXButton "删除" near "张伟 · DD1005"), never a bare row number, and what they print afternearcan be sent back asnearas it stands (a · basks for both; a long text printed cut with…means "starts with", and a page text that itself ends in…matches as it is).nthcounts from 0 in the candidate list a refused find prints — after the narrowing above, which is not the list ofqueryhits.Measured on 28 stored real browser trees: of 584 repeated controls, the printed text selected its own control for 293 (110 of them alone, the rest together with look-alikes on the same line) and another control for none; 291 have no usable text on their line. Of 724 controls with a unique name,
nearaccepts nothing at all for 489 and for the rest only texts on their own line — in round 7 the median such control still accepted 93% of the window. Real web pages arrive mostly flat (Chromium prunes generic containers: 2AXRowin 4,025 rows), so the line rule carries almost all of it; recovering cards beyond that needs the DOM, not the AX tree. Known limits, on the accepting side: several records on one visual line or in one flattenedAXRowwith a single such control among them; a cell that spans rows is seen in its first row only; a neighbouring card's one-line text exactly level with the button.
A
findthat only names a control is held when the hub knows the model is behind. It walks afresh and would press whatever carries the name now. Two things hold it — nothing sent, the reply says where the control sits and why, the same step again goes through; when both apply, one reply names both.A sheet or dialog nobody showed the model, or another page address. A sheet is known by all of its words: its title, its texts, the names of its controls, the values of controls the model cannot change (payee and amount in disabled fields are content, and so is the state of a tick box it cannot untick) and the rows of a list in it. Not by the values of controls the model can edit (it types there itself), nor by how far a progress bar has come. A tick box that becomes changeable is another sheet as well, even reading what it read (a wizard page done loading, a licence countdown over): one held call, the reply prints the sheet, the same step again goes. Rounds 13 to 15 handed the "shown" mark on when a box was released with the state it had, and three times a changed state got through as that — a look-alike matched by its folded text (
最近 7 天,最近 30 天), then by a place that a nameless icon button had shifted, then by a place an empty value had freed — so the hub stopped telling the two apart. Counts are folded only in a sheet with a busy or progress indicator (3/20,45%,00:12,5 秒,1.3 GB), and a countdown in a disabled button's name (重新发送(55s)) always. A sheet with a progress BAR — anAXProgressIndicatorthat has a numeric value, not a spinner and not a password-strength meter — is an operation running: its texts change by themselves (the file being copied), and so do the stage ticks some installers show as disabled tick boxes; neither is part of what it is, so working in a window while it copies does not cost a held call per step (round 12 had put the state of every disabled tick box into what a sheet is, and each stage of an installer became another sheet). Pressing one of that sheet's own buttons is different:停止stops whatever it says now, so that press is held once when its texts are not the ones the model was shown (round 12: any indicator had counted as a bar, and a keychain sheet with a strength meter passed as the one shown after it named another keychain). That holds for every step of a call — a later step is judged by what the sheet said before the call sent anything, so what its own earlier step changed does not count against it — and a change list makes the present texts "shown" only when it starts from texts the model had been shown — its own whole view of the window (one cut by the size cap counts when the cut came after the sheet's rows), or the texts a reply last printed: a report that compares with a walk nobody saw, and lists the bar moving, says nothing about the file name that changed before that walk, also when the same report lists a button of the sheet that now reads otherwise, or its bar turning indeterminate (both were ways around the rule until round 14; round 15 found the test refusing lists that did start from the model's own view). Round 9 folded digits everywhere and took "转账 ¥100.00 到尾号 1234" and "¥90000.00 到尾号 9876" for one sheet; round 10 showed that the narrower patterns still made one sheet of改到 11/21 15:00and改到 12/30 08:00, and of a 5% and a 95% discount. "Shown" means a reply printed what the sheet says: its title, its texts, its disabled fields and tick boxes with their values, and the rows of a short list in it (three customers to delete, in however many columns; not a file browser — a list of more than eight rows, or one the reply has no room for, is left out and the hold says so:+ a list of 9 rows not printed here); failing all of those, its rows with words. Its bare line (max_depth:1), or one of its buttons that aqueryhappened to match, says a sheet is up, not what it asks; afindthat matched nothing walked the window but showed nothing; a screenshot-only look vouches for the sheets of a walk the hub made moments before it, not for one that came up after the picture. A complete change list carries "shown" over: after下一步in a wizard the reply lists the two texts that changed, and the dialog as it is now has been shown (before, every step cost a held call although the model had read every word). The refusal of an old token that names the new sheet in full counts too. The hold itself prints up to twelve of those, 160 characters each (收款人 = 李四(尾号 9876)), then its buttons; a sheet that does not fit is not marked as shown by that reply. A sheet the model may have dismissed, with no walk after it, is not known to be the one that is up later under the same words. What can dismiss: a click on a button or link in it, return, escape or space (sent to one of its fields too), a key with a modifier other than shift, a hotkey, a menu item, a pixel click. Typing into its fields or ticking its boxes cannot, nor can an editing key sent to one of its text fields (select all, copy, cut, paste, undo, the caret by word or line:cmd+a,cmd+v; a combo box is a text field here), and a walk made moments after that action — not after a later one — that finds the sheet still up settles it (round 11: every step of a login sheet was held as "not shown"; round 12: typing a few characters after the click that dismissed it cleared the doubt, because the typing's report walked the window). A change list does not settle it either: for a sheet that stood before the list too, the list says nothing (round 13: the typing's report listed the one value typed behind the sheet, and that cleared the doubt). Input sent throughdesk_callis judged the same way, by what it can do — typed text, a set value, a scroll or a plain key cannot dismiss a sheet, a click or a hotkey can — and an upstream error that is not a refusal (a timeout) counts as sent, as it does foract. A key name the hub does not know, or modifiers in a form it cannot read (actrefuses both,desk_callpasses them on), counts as able to dismiss. A hold that names the sheet settles the doubt even when the sheet is a progress sheet too long to print whole; otherwise every later step in that window would be held. Its own buttons stay guarded by its texts, as above. The same step again, for the same control in the same place, passes once — within a minute, and only if nothing else was done or looked at in that window in between — so a copy dialog that names another file on every walk costs one extra call, not one per call, and the reply of the step that goes through names the sheet up now. Not held: right after the model's own unobserved action (click 删除withobserve:false, thenfind 确认删除), and for a sheet that came up after an earlier step of the same call — one that was already up when the call first walked the window is not that, unless the call itself dismissed it and brought one of the same words back. The address counts as shown when a reply printed its row; a reply that did not (aqueryview, an outline) ends with a line giving the new address. Another path is another page every time; an address that keeps moving under one path (a time parameter, a hash that follows the scroll position) is held once, and for a minute after — on as long as it keeps moving — the reply states the new address instead. That is about the path the model was last shown: an address back under a path it was shown before that one is another page again.Changes the model was not told. An earlier reply had to leave changes out (a report cut at its cap, an outline of a page that changed wholesale, a
querylook with more news than fits). The question is then whether the hub knows more about this control than the model does. The hub goes back through what showed the model the control together with the texts beside it, newest first by when it was shown: replies that located it byfindand said where it sat (a hold, orfind → … near …), its last four looks, its last two action reports, its last full view — a full view cut at the size cap vouches only for the rows it printed, and a view that printed the control bare (an outline listing[通过]) settles nothing. That view, moved on by every complete change list since, is what the model knows. If it is also all the hub knew when the call began — its newest walk, made after the last action sent to the window — the step goes: what the page did by itself since is not something the hub could have told (a countdown beside the button; the same is true of a token of the newest snapshot, which goes out without a walk). Otherwise the control must stand as it does now — same ancestors, the same texts beside it, one for one — and for afindwithnth, the same find must count to it there. When a queue's head moves up behind a cut report,[通过]stands next to an order number the old view also held, one line lower; a check that asked "was this text there before" let it through, and so didnth:0, until round 10. The hold says what differs (beside it now: "DD1005" (it was "DD1003")), and that reply is itself a view, which is why the resend goes through and why another unobserved action that changes the text again is held again. A view that printed only a text beside the control (aqueryfor选中shows选中:客户 张伟, not the[删除]next to it) settles nothing either — unless that text is not beside the control now: then the model's newest knowledge of the spot is another record, whatever an older view agrees with. A view newer still overrides that in turn when it printed, as it reads now, each text the older view shows differently, and whatever else stands beside the control stands as it did in the older view: with two observed key steps between presses, the report before last shows the previous selection and the last one the current, and round 11's rule held every press. (A text that did not change is in no report and need not be: round 12's repair asked for everything beside the control to have been printed anew, and still held every press of a删除with状态:待审next to the record.) While the model is behind, an action report ends with where thefindit just used lands now (find {"label":"通过","nth":0} now lands on … near "DD1005"); when it lands on the control just pressed — the same role and name, or, for a find that named only part of the label (通过for通过 DD1001,通过下一条 (剩 3)), the next one that also only contains it — that line is a view too, so approving a queue order by order costs one call each (round 10's rewrite had made it two, and round 12's exact-name test did again for names that carry the order); when the last通过is used up and the same find would now reach a link通过记录, the line says so and settles nothing. An action counts as one whether or not it named a window (a key sent with a pid only, a click at desktop coordinates), whether or not its outcome is known, and whether it went throughactor as input throughdesk_call. Not held: a control that an earlier step of the same call brought out (a form opened and filled in one batch) — which takes a walk made by this call, before it sent anything to the window, that lacks the control; when the first step needs no walk (a key), the hub makes one. A call whose token step comes before its firstfindgets no such walk — it would retire the token — and the hub's newest tree from before the call stands in: a control that appeared by itself between that tree and the call is then taken for one the call brought out (a known limit). A token step after thefindis retired by the find's own walk whatever the hub does, so that call is walked like any other (round 13: it was not, and a confirm sheet that had come up by itself was pressed as the batch's own doing). A window whose record the hub dropped — to bound memory, or because the driver restarted — is not treated as never looked at: the firstfindthere is held once with that said (and a sheet up there counts as not shown); after that notice, or after any look, the hub starts afresh on it.What is compared as "beside". The control's line or row, as for
near; where that holds no descriptive text, the texts just before it in reading order and those that follow inside its own container. A line too long to be evidence fornearstill counts here by its nearest part, up to two hundred items either way (round 13: on a 244-item line the record text three cells before删除was no longer compared, and a record the page swapped in by itself was deleted by name). What follows a control on a flat page is not compared: under a tab bar or a toolbar that is the page's first line, and every tab would cost a held call. That leaves a known gap — a button on a flat page with its record on the next line — where the reply at least says both what precedes and what follows the control it pressed. A batch takes all of this per window, before any step runs: a step addressed to another window than the call's own is judged by that window's state.Known cost. After the model's own unobserved action (
observe:false), a control whose neighbouring text is different by then is held once each time — the hub cannot tell a countdown from a record that changed. A report or aquerylook in between avoids it. An earlier version compared the text beside the control with the model's last view on every call; review walked around it five ways and it charged a held call for every ticking clock.
Further refusals, all before anything is sent: a snapshot id the hub never showed; a row number that was not printed under that id (so
<newest id>:<old row>cannot click a neighbour) — every token a reply prints, afterfind →or in a candidate list, counts as shown; a pid or window that does not own the snapshot; a changed page address (the text field in front of web content, when it holds a URL — a file name in a save panel is not one); a native sheet or dialog that opened since (the refusal names it and its buttons). If upstream still answersstale(another session shares the driver daemon), the hub re-walks and re-sends once, and only if that walk is identical to the tree the token was resolved in. A change in the application's menu bar alone (Undo becoming "Undo Refresh") does not count as a change of the window. Ondesk_callan element token is passed on only if its snapshot was walked through this hub for that pid (a walk made throughdesk_callcounts and is parsed for this), and never for a menu-bar item of that walk; cua itself was checked too (0.28.2): a token sent under another process's pid is refused asstale_element_token, one with another window id asconflicting_element_target. A driver restart is recognised by its counter: a walk that started after a higher snapshot id had arrived and comes back with a lower one can only be a new daemon, and everything stored is dropped.
Actions
Every action reply says what changed. 131 of 133 real clicks came back
effect=unverifiable— identical whether they landed or not — and 80% of single actions were followed by a separate observation turn. After the last step the hub waits (wait_ms, default 300 ms), walks the window once and appends the delta since its look right before the call, capped at 1,500 chars; a new on-screen window (a file panel, a dialog) is reported too.observe:falseskips it; an object asks for awindow_state-style look instead."No change" after a press is a stop sign. The reply says so, and pressing the same control again is refused until the model has looked (any
window_stateof that window, or another action in between) or the step carriesagain:true: a toggle that did flip with a late UI update gets flipped back by a blind repeat.actandact_batchare one engine. 37 of 80 real batches had a single step — written as batches only to getfind,wait_msorobserve.acttakes all of them now.Strict parameters, validated before anything runs. A field the action does not understand is an error, not silently dropped: dropping let a PreToolUse guard and the hub disagree about what a call does (a
hotkeycarrying a straykeyno longer matched the guard's cmd+q rule while the hub still sent cmd+q). The same goes for spellings: key names come from one short vocabulary (the modifiers cmd/shift/option/ctrl/fn, a dozen named keys, f1–f20, or one printable ASCII character), each as its own array element. The vocabulary also takes the aliasescommand,alt,control,enter,esc,backspaceandforwarddelete, in any letter case, and passes them on as written — a guard has to fold those the same way before it compares. Outside the vocabulary nothing is sent:"cmd+q","cmd-q","⌘", a full-widthqor a nested array used to compare unequal to the guard's rule and pass.delivery_modeandscopemust be exactly their enum values (" foreground"was "not foreground" to a guard), text and values must be strings. Window-scope actions need an integerpid(cua refuses without one even when a token is given).repeatis for scroll and navigation keys only — twenty blind returns or deletes land on whatever holds focus.extramay add driver parameters the facade does not model but never restate one it does (extra:{delivery_mode:"foreground"}would slip past every check on the regular parameter). Text beyond U+FFFF is refused up front: cua's key path drops such characters and its "retry the suffix" advice drops them again.Menu-bar items are invoked through
menu, never clicked as elements: the path is what a guard can review.Effect lines.
unverifiable, andeffect_unconfirmedon web content (26 of 26 web typings carried it and all had landed), are routine and print no warning.suspected_noop,delivery_failed, a partial delivery, or an upstream escalation to the foreground were right 4 times out of 4: they print ⚠, and the batch stops there instead of typing into whatever holds focus.Failure summaries are literal. "nothing took effect" when the first step failed; otherwise how many steps did take effect and must not be re-issued; the failing step is marked
not executed,PARTIALLY executedoroutcome UNKNOWN.act:double_click/right_click/set_value/menuhave no desktop scope; a desktop or pixel double-click isaction:"click"withcount:2.scope:"desktop"must not carrypid/window_id— the facade strips them. Target-less scroll sends arrow/Page keys to the focused control; pass a target orx,yto wheel-scroll a spot.A locked screen makes every AX tree unreadable and every background action refused. The hub checks for it when a tree comes back degraded and says so, instead of letting the model try ten other routes. A window on another Space is the same story for one window: while the user is on a different desktop or in a full-screen app, AX lists no windows for that process at all (cua 0.28.x; not measured again on 0.55), so the window can be screenshotted but neither read nor driven in the background.
list_windowsmarks such windowsother-Space, and a degraded read or a refused action says exactly that and tells the model to stop rather than go foreground (which would pull the user over to that Space). In a head-to-head on three tasks this was the first thing that separated the hub from a driver that can reach across Spaces. Two more driver limits surfaced in the same run and are now explained in the reply instead of rediscovered: with a second top-level window open in the app, cua 0.28 refuses every background keystroke (same_pid_keyboard_ambiguity); and a purely numeric string written into a web<input>through AX leaves the field empty (888,12.5,-5are dropped;888aand1,000stick). The first of the two is gone on 0.55.0 where it was measured again (TextEdit with two documents: typing, a key and a shortcut each reached the window they were sent to, the other document untouched, the frontmost app unchanged). 0.55 in turn sends a menu only through the app's main window — the refusal names it, and the hub says whichwindow_idto use — and cannot use the items macOS disables while an app is in the background (File > Close is one). The numeric one has not been measured again.
Plumbing
Crashed backends are auto-evicted and respawned on next call (via
client.onclose—transport.onclosegets overwritten by the SDK). All evictions are generation-guarded so a lateonclosefrom an old process can never delete a freshly respawned client.Bounded memory. The snapshots kept per window are capped by count (64) and by rows (40,000, or eight times the window's own size if that is more), and across windows by rows (160,000). The ones in use go last: the whole-window view, the model's last four looks (on a large window it works from two or three
queryviews in turn), the last reply that placed a control, and the snapshot whose tokens were used most recently. With the fixed 40,000 a 7,000-row window dropped the first of threequeryviews while the model was still using its token. The cache of alignments between walks is weak on both trees. It used to hold each walk's successor strongly, so every action report chained its walk to the one before and none was ever freed: 68 actions on a 3,000-row window ran a hub with a 256 MB heap out of memory, whatever the caps above said. A window dropped here leaves a marker, so a laterfindin it is held once instead of running as if the model had never looked.Cancellation is not a hang. The SDK wraps every abort — the host's Esc, the batch's 50 s budget — into the same
RequestTimeoutas a real timeout, and the hub used to evict and kill the backend on it: every token, baseline and named session died because someone pressed Esc. Only the hub's own 180 s timeout evicts now; after a budget cut-off a cheap read-only probe checks that the backend is not actually hung.Backend outputSchema validation is deliberately disarmed. cua-driver returns envelopes that violate its own declared outputSchema, and the SDK client arms validation lazily — only after
listTools(). With a real validator every cua tool works until the firstdesk_describe, then every call throws-32602after the upstream action already executed. The injected validator returnsundefinedrather than an always-pass function: the SDK's sibling check (-32600) fires on any truthy cached validator.Host exit (stdin EOF / SIGTERM / SIGINT) cascades shutdown to both backends, bounded at 5s. Host-side cancellation genuinely aborts: the signal is threaded into upstream
callTooland kills theosascriptchild.Expired cua lifecycle sessions are auto-revived (
start_session+ one retry) with a note that older tokens may be stale. The rejection must name the exact tool just called; if the retry itself dies mid-flight the hub reports outcome UNKNOWN. A named session minted by a previous hub/backend process cannot be revived — the hub says to use a new label. A 0.55 driver restarts an idle session by itself and refuses only one that was ended (end_session, a revocation, a closed connection); that refusal is revived the same way, and since such a driver retires an ended session's snapshots, a token read under it is then re-identified on a fresh walk or refused.desk_callpasses arguments through verbatim, apart from the refusals listed under Tokens and under the foreground switch below, with two additions: an upstream parameter-validation error gets the tool's required and accepted parameters appended (saving adesk_describeround trip), and a result that carries bothstructuredContentand a hub note is folded into one text block so the note is not dropped by the host. A pixel click throughdesk_callis routed exactly likeact's — it is not a way around a dead click.Later drivers. cua ≥ 0.34 answers
get_window_statewith compact markdown only: the hub detects a reply withoutelementsand asks again withfull_output:true, then keeps asking that way. 0.55 also stops a walk after one second by default and returns what it reached; once a reply says so, the hub asks for 20 s on every walk. A walk the driver still cannot finish is shown as far as it got and marked:findis refused on it (part of a window shows neither "the only one" nor "absent"), and diffs, queries and carried tokens say that a row they miss may only not have been reached. A walk that stops at the driver's node cap (2,000 rows) is treated as on 0.28, where the cut falls on the same row every time. Both things are learnt from the shape of a reply, not from a version string —cua-driver mcpis a proxy whose reported version can differ from the daemon's — and forgotten when the driver process is replaced, so an upgrade or a rollback needs no restart of the hub. 0.55 refuses with a code instructuredContent; the hub goes by the code, takes an error that says the action may have run (execution_state: "unknown") as outcome unknown, and says of a refusedtypethat the driver tried through accessibility first that the text may be in the field. 0.55 also puts a hint and a summary on every action result; the hub passes them on only when something is off. Developed against 0.28.2; on 2026-11-20 the suite and the live check were run against 0.55.0, where a click with its report took about 1.3 s against 3.0 s.Optional foreground switch. If
/var/db/desktop-hub/exists,delivery_mode:"foreground"is refused unless it holds a valid, unexpired, root-ownedfg-switch.json— so the rule does not rest on a host-side hook alone. Without the directory nothing is enforced. The file is{"v":1,"opened_at":<epoch seconds>,"expires_at":<epoch seconds>}, open for at most two hours; it must be a regular file owned by root, not writable by group or others, with a single link — in other words something only asudocommand the user runs can put there (the hub ships no helper for it). Foreground input goes to the real screen, where cua neither tieswindow_idtopidnor keeps a point inside the window (it does both in the background): before a foreground step — throughactor throughdesk_call, where the switch is asked forscope:"desktop"as well anddelivery_modemust be spelled exactly — the hub looks the window up, refuses when it belongs to another process, and refuses a point or a drag end outside its frame. That needs the window's pixel scale, so a foreground pixel click is refused until the hub has seen a screenshot of the window; zoom coordinates are refused in the foreground.Coordinate spaces:
desktop_screenshotreturns true screen pixels (2x on Retina) for cuascope:"desktop"; oss pointer tools viadesk_calluse logical points (1x).frames:trueprints element centres in window-screenshot px once a screenshot told the hub the scale.run_script: language is case-insensitive with unknown values rejected; output past 1MB/stream is drained (the script runs to completion) while the returned body is clipped to 8KB.Known blind spots, stated in the tool descriptions (the last one in the error message instead) so the model does not rediscover them: background typing bypasses the IME; there is no background hover; in web rich-text editors a selection must be deleted before typing and the caret moves only with arrow keys; iPad-ported apps ignore synthetic scroll/drag (only the oss HID pointer tools work, and they move the real cursor);
verifyreturnsunknownfor web content by design; the system Open/Save panel belongs to a helper process and is not reachable in the background.window_state's screenshot can lag the live frame. For "right now" evidence take a freshdesktop_screenshot.Reviewed adversarially, round after round. v0.3.0 was driven by a month of transcripts — 495 hub calls, 28% of them spent recovering from failures — and its token rule went through six versions: a design review whose three lenses each rejected the first, an implementation review that broke the second, and three attack passes that broke the third, fourth and fifth with end-to-end repros. Each of those tried to recognise a repeated control by what surrounds it; the sixth stopped trying and gave the model a way to say which one it means instead. Three further rounds then attacked that way of saying it (
find+near) and the bookkeeping around it. The first found a lone control owning its page, ids matched inside longer ids, a change list that missed a second difference, and tokens the hub printed but would not take back; the second showed that the repaired containment rule still let a lone control on a flat page accept nearly every text in the window, after whichnearwas rebuilt on positive evidence only; a third then broke every kind of evidence that still inferred something (repeating containers, sheets, a page-wide reading direction, ranking exact over partial matches) and left the two that do not, which is allnearkeeps. The repros are section 7.6i. Eight more rounds (9 to 16) went at the two holds above and at how names resolve; each of the last seven also found what the fixes of the round before it had broken (a queue approved order by order at two calls each, a login sheet held at every step, a strength meter taken for a progress bar, a line limit that left one control alone with line evidence, a released tick box matched by its text instead of its place, then by a place a nameless button could shift, then by one an empty value could free — at which point that mechanism was taken out rather than mended a fourth time), so their repros stay in the suite: sections 7.6j, 7.6l, 7.6n, 7.6o, 7.6p and 7.6k. From round 13 on a round read nothing but the diff of the one before, and the diffs got smaller: 409 lines, 195, 165, 134, 81. A last pass over the version with that mechanism removed (two reviewers, about 250 scenarios against the versions before it) found nothing it had made worse. Unit tests intest/unit.mjs, end-to-end intest/smoke.mjsagainst a fake driver that enforces cua's stale-token rule (earlier attack repros: 7.6a2 and 7.6h), live checks intest/live/.
Third-party tools
desktop-hub is a facade that launches two independently developed tools as separate MCP server processes; they are not included in this repo and are installed separately by you:
cua-driver (
CuaDriver.app,com.trycua.driver) — MIT, © Cua AI, Inc. — https://github.com/trycua/cua@zavora-ai/computer-use-mcp — MIT, © Zavora Technologies Ltd. — https://github.com/zavora-ai/computer-use-mcp
"cua", "CuaDriver" and "Zavora" are names/marks of their respective owners, used nominatively to identify the tools; this project is not affiliated with or endorsed by either.
License
中文说明
macOS 桌面自动化的精简聚合 MCP 服务器:用约 3.4k token 的 11 个工具定义,替代 cua-driver(0.28.2 是 56 个工具 ~37k token;0.55.0 是 61 个,定义文本多了三分之一)+ computer-use-mcp(64 工具 ~21k token)合计 ~58k token 起的上下文占用,底层工具一个不少(长尾经 desk_call 直达、schema 用 desk_describe 按需取)。
安装
前置:macOS、Node 18+、cua-driver(用 trycua/cua 官方一键脚本装,见上方英文 Prerequisites,装完默认路径即本 hub 默认路径;现在的安装器默认还会把 cua-driver 直接接进 Claude Code、Codex 和 Cursor,并在最后跑一遍 cua-driver test,加 --no-connect、--no-test 可以关掉);oss 后端无需手装,首次 desk_call server:"oss" 时 npx 自动拉取 @zavora-ai/computer-use-mcp@7.0.0(首次需联网,大陆用户建议配 npm 镜像)。
git clone https://github.com/zty552252kevin-code/desktop-hub.git
cd desktop-hub
npm ci
claude mcp add desktop-hub -s user -- node "$(pwd)/server.mjs" # 必须绝对路径国内镜像(同步更新):git clone https://gitee.com/zty552252kevin/desktop-hub.git
权限:给 CuaDriver.app 授予「辅助功能」+「屏幕录制」(推荐 cua-driver permissions grant 让弹窗归属到 App 身份,升级不掉权限);oss 后端跟随宿主终端的 TCC 身份,终端也要授同样两项;run_script 首次对每个目标 App 会弹一次「自动化」授权。
如果 cua/oss 还单独注册成了 MCP 服务器(以前自己加的,或者 cua 安装器的 connect 步骤加的),把那一项 disable 或删掉,由本 hub 接管;claude mcp list 能看到有没有。
验证:npm test(先跑不碰桌面的单元测试,再跑端到端测试;后者会连真实的 cua 做几次只读调用并执行 osascript;DESKTOP_HUB_TEST_OSS=1 另加 oss 后端检查)。想看实机效果:node test/live/calc.mjs "$(pwd)/server.mjs",它在后台驱动计算器走 28 步,跑完自己把计算器退掉即可(脚本里按的是中文系统上的控件名,别的系统语言要改,见文件开头)。环境变量见上方英文表格。
设计取舍与坑(都是实测换来的)
模型看到什么
结果是 hub 自己写的文本,不是上游的 JSON。 结果里只要带
structuredContent,Claude Code 给模型看的就是它的 JSON 原文,content里的文本块被丢掉。所以透传的window_state把同一棵树送了两遍(elements[]加tree_markdown,每个元素约 385 字符),hub 追加的提示一条也到不了模型;真实的 191 次调用里有 27 次超过宿主 5 万字符的线,被落盘成文件,模型还得另起一个工具去读。现在window_state、list_windows、act、act_batch只回 hub 渲染的文本。在 26 份真实浏览器整树上实测:280 万字符的 JSON 变成 14 万(5%),单份最大 7.9k。行格式。
[n] Role "标题" = "值"是可按的;(n) …是带序号但按不动的,真实网页里占三分之一,对它做 AX 点击什么都不会发生,却照样报成功。不带序号的行是静态文本。App 的菜单栏默认隐藏(每棵树有一半是它,苹果菜单里还带着最近打开的文稿名),menus:true才显示。输出在 2 万字符处截断(DESKTOP_HUB_MAX_TREE_CHARS),写明还有多少没给,不交给宿主去落盘。hub 每次都取整窗,
query在本地过滤。"a|b"或数组表示任一词。匹配不分大小写、按子串;先按原样匹配,一个都没命中才忽略空白再配一遍(antd 把「确定」渲染成「确 定」;而带尾空格的"创作 "是有意用空格排除「继续创作」)。默认不搜菜单栏:曾有一次查「关机」命中了苹果菜单的关机,而不是页面上的按钮。零命中时,小窗口直接回整窗,大窗口回最接近的几行。大窗口里只命中一到三处时,每处命中连同它所在的那一行或那张卡片一起给(单独一个DD0350说明不了什么,要看它旁边的单元格;窗口长到印不全时,也没有别的调用能把这些格子取出来)。diff:true指「相对你上次看到整窗」的变化,按窗口记,和 query 无关。旧版基线按 query 分开存,而模型几乎每次都换 query,等于永远没有基线,一个月里 diff 只被用过一次。调用方自己收窄过的观察(query、max_depth、max_elements)不推进基线;整窗观察即使被长度上限截断也算基线,否则超过上限的窗口每次diff:true都会整份重发。没有基线、或页面大半都变了,就回整树,并在第一行写明原因。list_windows一行一个有标题的窗口,在屏上的排前面。一台普通的桌面约有 90 个窗口,其中 75 个左右是没有标题的辅助层(光标覆盖层、自动填充浮层),原来 2 万字符,现在 1.1k。每行带窗口大小和左上角坐标,在另一个桌面空间的窗口标other-Space。pid:<pid>列出该进程的全部窗口,找无标题的弹出面板用它。慢在 hub 外面,设计要省往返而不是省毫秒。 495 次真实调用实测:工具本身合计 27 分钟,夹在中间的模型轮次合计 137 分钟。结果里带图,下一轮大约慢一倍(中位 19.5 秒对 10.5 秒),和图片大小无关;文本多少对轮次耗时几乎没有影响(不到 500 字符 10.0 秒,1.2 万以上 11.8 秒),它的代价在上下文占用和落盘。所以:文本优先,截图只当检查点(
tree:false是只截图、不走树),一次调用放几步,动作回执里直接带变化。截图降采样和转码评估过,刻意不做。
token
cua 每走一次树,就让这个窗口此前的元素 token 全部作废,hub 自己走的也算(在 0.28.2 上实测:只要有更新的
get_window_state,带不带过滤都一样,旧 token 报stale,动作不执行;换一个 session 标签、换一条连接去走,结果相同,没有「悄悄看一眼」的办法。0.55.0 上用test/live/session_probe.mjs实测,快照归读它的那个 session:换一个标签或换一条连接去走,旧快照还有效;同一个 session 里再走一次,旧的照样作废,而 hub 自己每次看一眼正是这种情况)。现在每次动作回执都会再看一眼窗口,照直做的话每调用一次,模型手里的 token 就全废了。所以 hub 记着自己展示过哪些快照、每份快照展示过哪些行,把旧 token 带到最新的树上。带过去有两个条件。条件一:这之后的每一处变化,模型都看过。 靠「周围长什么样」去认同一个控件的做法试过三版,三版都在评审里被攻破:按坐标认,表格删掉一行,下一行的按钮正好落在原来的位置;按最近一层容器的文字认,操作列每一行都是同样的「编辑」「删除」;按逐级放宽的文字签名认,确认框换成了另一个项目,里面仍然只有那一个「删除」。最后这种情形再怎么细看也没用:按钮确实还是那个按钮,只是它现在作用在别的东西上。所以 hub 按快照记着模型知道到哪一步:一条把变化列全了的回复(没被截断的动作回执、没被截断的
diff:true,或者一次什么都没变的观察)会把它往前推。带query的观察在变化不多时也会顺带列出来(否则页面上有个跳动的计时器,每看两眼就要多挨一次拒绝)。模型还没跟上的快照,它的 token 第一次用会被拒绝,什么都不发,拒绝信息里直接列出变了什么;同一步原样再发一次就放行。变化多到列不下就明说,请模型重新看一眼。窗口在模型没看到的情况下变过、随后模型又拿到了整棵新树,这种旧快照直接作废。「把变化列全」是字面意思:一条变化行只印长文本里的第一处不同,所以一个值同时改了两处(开头的时间、结尾的收款人)就算没列全,旧 token 继续扣着;新出现的一行文字长过一行能印的长度,或者一个没有标签的输入框 tooltip 和值一起变了,也一样。窗口标题变了按普通变化处理,照常列出,不能因为标题上的「已编辑」标记或未读数就让全部 token 作废。条件二:这个控件不会和别的认混。 旧 token 只在两种情况下带过去。一种是最新走到的树和 token 出处的那棵逐行相同,这时按原位置认。另一种是这个控件的名字(角色加标签,没有标签的图标用 tooltip)在窗口里独一份,新旧两棵树里都是,控件还在,各级祖先也还是原来那些(新旧两棵树按文档顺序当成两个序列对齐,用行键上的最长公共子序列,不看坐标)。名字重复的控件,比如表格每一行的「删除」、表单里一排没有标签的输入框、每张卡片上同一个图标,窗口只要有一处变化就不再跟:这一步被拒绝,什么都不发,拒绝信息里列出最多六个现在的候选,离原位置近的排前面,每个都带着它所在行或卡片上的文字。之前的规则是跟的,办法是看控件所在的那条记录是否原样还在,而评审每一轮都能找出「原样还在」不够用的版式:一格换成了另一位客户,金额和日期碰巧相同;卡片里自己又套着一个列表;轮播的槽位号不变,里面的条目在转。标签变了算另一个控件(比如开关已经切过去了),拒绝并报出新名字。在 22 对真实浏览器相邻快照上,可按的行有 63% 能带过去(1,345 个里 854 个),没有一例落到名字不同的行上,名字独一份的 789 行没有一例被拒;被拒的是 417 个同名控件,另有 74 行是改了名或者已经不在了。
控件按内容来指:
find加near。find:{label:"删除", near:"DD1005"}在一次新走的树上解析,只留下能证明这段文字就在它旁边的匹配。哪些文字属于哪个控件,是页面含义上的事,树只给得出线索。凡是靠「包含关系」去推断的规则,评审里都被做出了按错行的例子,一轮一个:按「不含第二个同名控件的最大容器」算,五行表格里唯一的「取消订单」把整张表都算成自己的;按「控件这一侧没有别的字」算,课程表里一格的按钮吃进了邻格的文字;按「重复出现的容器」算,两个分区、两个窗格和两张卡片长得一模一样;按「对话框里唯一的那个」算,对话框里放着一张表。留下来的只有两种不对容器做任何推断的证据,near只认这两种。同一行:文字是一行叶子文本(或者另一个控件的标签),和控件在同一条视觉行上,按阅读顺序中间没有夹着别的行的内容。包着整张卡片的那个分组的标签不算在谁的行上。比控件高的文字,要控件整个落在它的上下沿之内才算,高出一倍以上的一律不算:按钮只和旁边那张卡片两行标题的下半截齐平,不算挨着那个标题(第十轮就是这样按到了左边卡片的「删除」,第九轮用三行标题做到过同样的事)。只有一两个像素高的文字(给读屏软件看的标签)直接跳过;同一高度上排了两百个以上的东西,就不当成一行,而且这一行上的同名控件要么都有行证据,要么都没有:比邻居低几个像素、或者包在一个可点的小标签里的那一个,扫到的行比邻居短,第十三轮之前只有它还留着行证据,夹在它和下一个之间的文字于是只命中它一个,没报歧义就按了下去。一行上有好几个同名控件时,夹在两个控件之间的文字两边都算,按歧义报出;这一行两头又都有字的话(
张伟 [移除] 李四 [移除] 王五),两头的字谁也不算,因为这里有一条记录没有控件,是头一条还是末一条,行里看不出来。第八轮还在按这一行的排法来分(「文字、控件、文字、控件」各取前面的文字),第九轮拿昵称 [编辑] 待审核 签名 [编辑]就攻破了。同一表格行:文字在控件所在的
AXRow里,条件是控件自己那一格没有别的字(有字的格子自己就是一条记录,比如日历、课程表),或者这张表在这一列重复出现这个控件。怎么算对上:按整词匹配。
DD100对不上DD1001、DD100-2、DD100-A、DD100_2、DD100.pdf,200对不上¥1,200,「张伟」对不上「张伟明」;用户敲进输入框里的字不算记录的文字(搜索框里写着DD1005,不能替它旁边的按钮作证)。匹配之间不排名次:两个控件都成立就是歧义;near一个都对不上时,nth也不会改到别的清单里去数。其余情形,包括卡片、窗格、对话框、没有 frame 的页面,一律拒绝,什么都不发,把候选列成 token,各自注明在阅读顺序里排在哪段文字之后(after "…"),由模型挑一个。名字。标签就是要找的那几个字的行,优先于只是包含它的行(「密码」对「确认密码」):先看原样相等的,再看去掉空格和全半角差别之后相等的。antd 把「确定」画成
确 定,第十轮之前,同一页上的链接「确定并继续添加」因为只有它原样包含这两个字,把点击拿走了。这条优先的每一级都有个前提:被优先的行里得有这个动作用得上的。标题文字「删除」底下是按钮取 消、删 除,或者页签「评论 12」里面有「评论」两个字,都挡不住点击落到那个按钮上(第十一轮查出:点击原先落在标题上,或者按钮连候选都进不了);标题「设置」下面有个按钮「打开设置」,或者文字「姓名」旁边是输入框「请输入姓名」,这种算歧义,两边都列出来。对点击来说,「用得上」还包括两种没有按下动作的行:输入框(点一下是聚焦),以及网页内容之外列表或表格行里的文字(点一下是选中这一行,邮件侧栏里的「收件箱」根本没有按下动作)。名字相同的几行之间,才按动作的种类来选:点击时按不动的、置灰的让位给按得动的,填值时进这个名字的输入控件(文本框、下拉、滑块、数字框、日期框),不进同名的按钮;那个输入控件要是置灰的,就哪儿也不进,两边都列出来。一个标签同时命中两个名字不同的东西,比如文字「订单 DD1005」和按钮「删除 DD1005」,算歧义。同名但这个动作用不了的行(置灰的「移除」,各种清单里都标[disabled])照样把所在的行隔开,这一行两头有没有字都一样,near的文字如果挨着的是它,这一步被拒绝并说明原因;排在控件前面的、它自己那一行的标题(通知 · 有新订单时发短信 · [通知] · 全天)不算这样的对手。算一个还是两个。可按的匹配项里面那些按不动的文字和图标,在它是离得最近的可按祖先时,就算它本身(点链接里的字等于点链接),里面只是重复它名字的控件也算。整行本身是一个大链接、里面另有一个「删除」按钮时,这个按钮自己算一个控件,输入框也一样。一段光秃秃的文字包在一个没有名字的可点容器里,容器里又没有别的内容(这种行里的
<span onclick>删除</span>),这段文字仍是候选,点击发给那个容器,回执里写明。回执印的都是完整 token(
s0000012a:34 AXButton "删除" near "张伟 · DD1005"),不印裸行号;near后面印的文字可以原样发回来当near用(a · b表示两段都要有;长文字以…截短,表示「以此开头」;页面上的字自己就以…结尾的,原样也对得上)。nth从 0 数,数的是被拒绝的find列出的那张候选清单,也就是经过上面这些筛选之后的,不是query命中的那几行。实测:28 份真实落盘的浏览器树上,584 个同名控件里,印出的文字有 293 个选回了自己(其中 110 个是唯一选中,其余是和同一行上的同名控件一起命中),选到别的控件的一个也没有;另外 291 个所在的行上没有可用的文字。名字独一份的 724 个控件里,489 个
near什么文字都不接受,剩下的只接受自己那一行上的;而在第七轮复查时,这类控件的中位数还能接受窗口里 93% 的文字。真实网页送到这里多半已经是平铺的(Chromium 会剪掉没有语义的容器,4,025 行里只有 2 个AXRow),所以绝大部分靠「同一行」这一条;再往上要恢复卡片,得靠 DOM,AX 树给不了。已知的局限都在「接受」这一侧:一条视觉行上或一个被压平的AXRow里排了好几条记录,其中只有一个这样的控件;跨行的单元格只算在它的第一行里;旁边那张卡片的一行文字正好和按钮一样高。
只报名字的
find,在 hub 知道模型没跟上的时候先扣一次。 它是重新走树,当下谁叫这个名字就按谁。两种情况下先扣(什么都不发,回复里写明控件现在在哪、为什么扣,同一步原样再发就放行);两种同时成立时,一条回复把两个原因都写上。有个对话框没人给模型看过,或者页面地址变了。 对话框按它的全部文字来认:标题、里面的文字、控件的名字、模型改不了的控件的值(置灰输入框里的收款人和金额是内容,置灰复选框勾没勾也是)、里面列表的各行。模型自己能改的控件的值不算(那是它自己敲进去的),进度条走到哪也不算。置灰的复选框变成能改的了,也算换了一个对话框,哪怕勾选状态没变(向导的一页加载完了,许可协议的倒计时结束了):扣一次,回复里印出对话框,原样重发就过。第十三到十五轮曾经在「放开时状态没变」的情况下把「看过」的标记传给新的对话框,结果连着三轮都有变了的状态冒充成没变的混过去:先是数字折叠后文字相同的邻居(「最近 7 天」「最近 30 天」),再是一个没名字的图标按钮消失后错开的位置,然后是空值腾出来的位置。hub 于是不再分辨这两种情况。计数只在带转圈或进度指示的对话框里折叠(
3/20、45%、00:12、5 秒、1.3 GB),置灰按钮名字里的倒计时(重新发送(55s))一律折叠。带进度条的对话框(指有数值的AXProgressIndicator,转圈和密码强度条不算)是一个正在进行的操作,里面的文字自己会变(正在拷贝哪个文件),有些安装器用置灰复选框表示的阶段勾选也一样,这两样都不算它是谁的一部分,所以它在拷贝的时候去操作同一个窗口,不会每一步都多扣一次(第十二轮把所有置灰复选框的状态都算进了对话框是谁,安装器每走一个阶段就成了另一个对话框)。按它自己的按钮是另一回事:「停止」停的是它此刻写着的那件事,文字和给模型看过的不一样,这一下就先扣一次(第十二轮查出:原先任何指示器都算进度条,带密码强度条的钥匙串对话框换成了另一个钥匙串,仍被当成看过的那个)。一次调用里的每一步都这样判:后面的步骤按这次调用发出任何动作之前对话框写的是什么来比,它自己前面的步骤改出来的不算;变化清单要从给模型看过的文字起算,才算把现在的文字给它看了,起点可以是模型自己那份整窗视图(被长度上限截断的,只要截在对话框各行之后,也算),也可以是某条回复最后印出的那些文字。拿一次没人看过的走树当起点的回执,只列出进度条往前走了,对那次走树之前就换掉的文件名什么都没说;同一条回执里顺带列出对话框有个按钮改了名,或者进度条变成了不确定进度,也一样(这两条在第十四轮之前都能绕开上面的规则;第十五轮又查出这道检查把确实从模型自己视图起算的清单也拒了)。第九轮是数字一律折掉,于是「向尾号 1234 转账 ¥100.00」和「向尾号 9876 转账 ¥90000.00」成了同一个对话框;第十轮又查出,收窄之后的写法仍然把「改到 11/21 15:00」和「改到 12/30 08:00」、5% 折扣和 95% 折扣各当成一个。「给模型看过」指有一条回复把对话框说的话印出来了:标题、文字、带着值的置灰输入框和复选框,以及里面短列表的各行(要删除的三位客户算,每位占几列都一样;文件浏览器不算。超过八行、或者这条回复印不下的列表不印,扣留时写明+ a list of 9 rows not printed here);这些一样都没有的话,就是它里面带字的行。只印出对话框自己那一行(max_depth:1),或者query碰巧只命中了它的一个按钮,只说明有个对话框,没说它问的是什么;一次什么都没找到的find虽然走了树,却什么都没给模型看;只截图的观察,能替 hub 在截图前一刻走树时已经在的对话框作证,截图之后才弹出来的不算。变化列全了的回复会把「看过」带过去:向导里按了「下一步」,回执列出变了的两段文字,现在这个样子的对话框就算看过了(之前每一步都要多扣一次,而模型明明每个字都读过)。旧 token 被拒时,拒绝信息里把新对话框完整写出来的,也算。扣留的那条回复自己最多印其中十二段,每段 160 字(收款人 = 李四(尾号 9876)),后面是它的按钮;印不下的对话框,不因为这条回复就算看过。模型可能已经把一个对话框关掉了,之后 hub 没再走树,过后又有一个同样文字的在那里,不认它就是先前那个。能关掉对话框的动作是:点它里面的按钮或链接,按回车、Esc、空格(发给它里面某个输入框的也算),带 shift 以外修饰键的按键,快捷键,菜单项,像素点击。往它的输入框里打字、勾它的复选框关不掉它,发给它里面文本框的编辑键也关不掉(全选、拷贝、剪切、粘贴、撤销、按词按行移动光标,比如cmd+a、cmd+v;组合框在这里也算文本框);那个动作之后片刻内走的一次树里它还在,也就认定没关,更晚的动作之后走的树不算(第十一轮查出:登录框里每一步都被当成「没给看过」扣下;第十二轮查出:点掉对话框之后再打几个字,打字回执走的那次树就把疑点消掉了)。变化清单也消不掉这个疑点:清单之前就在的对话框,清单对它什么都没说(第十三轮查出:打字回执列出了对话框后面那个刚打进去的值,疑点就被消掉了)。经desk_call发的输入按同样的办法判,看它能做什么:打字、设值、滚动、普通按键关不掉对话框,点击和快捷键能;上游回的错误只要不是明确拒绝(比如超时),就当作已经发出去了,和act一样。hub 不认识的键名、读不懂的修饰键写法(act会直接拒绝,desk_call原样转发),按能关掉算。扣留的回复点了这个对话框的名,疑点就算消了,哪怕它是个长得印不全的进度对话框;不然这个窗口里之后每一步都要被扣。它自己的按钮仍由上面说的文字那一道把着。同一步对同一个位置上的同一个控件原样再发,放行一次,限一分钟之内,而且中间没有在这个窗口上做过别的动作、看过别的内容。所以拷贝对话框每次走树都换一个文件名,多花的是一次调用,不会每次都被扣;放行的那一步,回执里写出当下是哪个对话框。不扣的情形:模型自己刚做过一个没看结果的动作(observe:false点了「删除」,接着find找「确认删除」);同一次调用里前面的步骤之后才弹出来的对话框。这次调用头一回走这个窗口时就已经在的,不算后一种,除非是这次调用自己把它关掉、又带出一个同样文字的。地址以回复印出过地址栏那一行为准;没印的回复(query视图、提纲)末尾会加一行,写出新地址。路径变了,每次都算换了页面;同一路径下一直在动的地址(时间参数、跟着滚动位置走的锚点)只扣一次,之后一分钟内(只要它还在动就一直顺延)改成在回执里写出新地址。这说的是模型最后被告知的那个路径:地址回到更早给它看过的另一个路径下,仍然算换了页面。有变化没告诉模型。 先前有一条回复没能把变化列全(回执被长度上限截断;页面整个换了、只给了提纲;
query观察时新变化多得列不下)。这时要问的是:关于这个控件,hub 知道的是不是比模型多。hub 按给模型看的先后,从新到旧去找把这个控件连同旁边的文字一起给它看过的那一份:用find找到它并写了位置的回复(一次扣留,或者find → … near …)、最近四次观察、最近两条动作回执、上一次整窗视图。被长度上限截断的整窗视图只替它印出来的那些行作证;只印了控件本身的视图(提纲里列出一个「通过」)什么也定不了。找到的那一份,加上之后每一份列全了的变化,就是模型知道的样子。如果 hub 在这次调用开始时知道的也只有这些(它最新一次走树晚于发给这个窗口的最后一个动作),这一步就放行:页面在那之后自己变了什么,hub 本来也无从告知(按钮旁边的倒计时就是这样;最新快照的 token 不重新走树就发出去,是同一个道理)。否则,控件现在的样子必须和模型知道的一样:各级祖先相同,旁边的文字一对一相同;find带nth的,同一条find在那份视图里也得数到它。审核队列的队首在一条被截断的回执背后往上挪了一位,「通过」旁边换成的订单号在旧视图里也有,只是原先在下一行,只问「这段文字以前有没有」的比法就把它放过去了,nth:0也一样,到第十轮才堵上。扣留的回复写明哪里不一样(beside it now: "DD1005" (it was "DD1003")),这条回复本身也算给模型看过一次,所以原样重发能过;之后模型又做了一个没看结果的动作、旁边的字再变,就再扣一次。只印了控件旁边那段文字、没印控件本身的视图(query查「选中」,印出「选中:客户 张伟」,没印旁边的「删除」)同样定不了什么,除非那段文字现在已经不在控件旁边:这说明模型对这个位置最新的了解是另一条记录,更早的视图对得上也不算。反过来,旧视图里印得和现在不一样的每一段文字,更新的视图要是都按现在的样子印过了,控件旁边其余的文字又和旧视图里一样,这一条就不再否决:两次按键之间隔着两步带回执的按键时,倒数第二条回执印的是上一条选中项,最后一条印的是现在的,第十一轮的规则却每一轮都扣。(没变的文字不会出现在任何回执里,也用不着出现:第十二轮的修法要求控件旁边的文字全都重新印过,「删除」旁边除了记录还有一段「状态:待审」时照旧每一轮都扣。)模型没跟上的时候,动作回执末尾会写出刚用过的那条find现在落在哪(find {"label":"通过","nth":0} now lands on … near "DD1005"),落点就是刚按过的那个控件时(角色和名字都相同;find只写了名字的一部分,比如用「通过」去找「通过 DD1001」「通过下一条 (剩 3)」,那么名字里同样只是含有它的下一个也算),这一行也算一次给模型看过,所以逐条通过队列时每条只花一次调用(第十轮改写后曾经变成两次,第十二轮要求名字完全相同,名字里带订单号的队列又变成两次);最后一个「通过」用完了、同一条find接下来会落到链接「通过记录」上,这一行照样写出来,但不算看过。动作不管带没带窗口号(只带 pid 的按键、按桌面坐标的点击)、结果明不明确、走的是act还是经desk_call发的输入,都算做过动作。不扣的情形:同一次调用里前面的步骤才带出来的控件(一批里打开表单并填完)。认定「带出来的」要有凭据:这次调用在往这个窗口发任何动作之前走过一次树,里面没有这个控件;第一步不需要走树的(按键),hub 先走一次。这次调用里第一条find之前还有用 token 的步骤的,不走这一次(一走 token 就废了),改拿 hub 在调用之前最新的那棵树顶替:在那棵树和这次调用之间自己冒出来的控件,会被当成这次调用带出来的(已知局限)。token 步骤排在find后面的,find自己走树时那个 token 反正要废,所以这种调用照常先走一次(第十三轮查出:原先没走,自己弹出来的确认框被当成这一批带出来的,按了下去)。hub 丢掉了某个窗口的记录(为了控制内存,或者驱动重启了),不把它当成从没看过的窗口:在那里的第一条find扣一次并说明原因(那里开着的对话框也算没看过);说过这一次,或者模型自己再看一眼之后,这个窗口就从头算起。「旁边」比的是什么。 和
near一样,是控件所在的行或表格行;那里没有描述性文字时,再算上阅读顺序里紧挨在它前面的文字,和它所在容器里跟在它后面的文字。长到不能给near作证的行,在这里仍然取离控件最近的那一段来比,左右各不超过两百项(第十三轮查出:244 项的一行上,「删除」前面隔三格的记录文字不再参与比较,页面自己换上来的记录被按名字删掉了)。平铺页面上跟在控件后面的文字不比:标签栏、工具栏后面就是页面正文的第一行,比的话每翻一次标签都要扣一回。这就留下一个已知的口子:平铺页面上按钮在上一行、它的记录在下一行。这种情况下,回执至少会把被按控件前面和后面的文字都写出来。一批步骤里,这些状态都是按窗口、在任何一步执行之前取的:某一步指向的窗口和这次调用的窗口不同,就按那个窗口自己的状态来判。已知的代价。 模型自己做了一个没看结果的动作(
observe:false)之后,旁边文字已经不同的控件,每次都会被扣一次,因为 hub 分不清那是倒计时在走,还是记录换了。中间有一条回执或者一次query观察就不会。更早的一版是每次调用都拿控件旁边的文字和模型上次看到的做比较,评审从五个方向绕了过去,而且页面上只要有个跳动的时钟,每次调用都要被扣一回。
另外几种情形也在发出之前就拒绝: hub 没展示过的快照号;那份快照里没印出过的行号(所以拿「最新快照号加旧行号」拼不出邻居的 token),回执里印过的 token 都算展示过,
find →后面的和候选列表里的也算;pid 或窗口不是这份快照的主人;页面地址变了(指网页内容前面那个文本框里的网址,保存面板里的文件名不算);之后弹出了系统对话框(拒绝信息里写出是哪个对话框、上面有哪些按钮)。上游仍然回stale时(别的会话共用同一个守护进程),hub 重新走树再发一次,前提是这次走到的树和解析 token 时用的那棵完全一样。只有应用菜单栏变了(「撤销」变成「撤销 刷新」),不算窗口有变化。desk_call上的元素 token,只有快照是经这个 hub 为这个 pid 走出来的才往下传(经desk_call走的树也算,hub 会为此解析它),那次走树里属于菜单栏的项一律不传;cua 自己也实测过(0.28.2):token 配上别的进程的 pid 会被拒为stale_element_token,配上别的窗口号会被拒为conflicting_element_target。驱动重启靠它的计数器认:一次走树开始的时候已经收到过更大的快照号,回来的号却更小,那只能是换了新的守护进程,此前存的全部丢弃。
动作
每次动作的回执都写明什么变了。 133 次真实点击里 131 次的返回是
effect=unverifiable,点上没点上一个样;单步动作有八成紧跟着一次单独的观察。现在最后一步之后 hub 等一下(wait_ms,没给就 300 毫秒),走一次树,把「这次调用开始前到现在」的变化附在回执里,1,500 字符封顶;屏上新出现的窗口(文件面板、对话框)也会报。observe:false不做这一步;传对象则换成一次window_state式的观察。按完「没有变化」,就不要接着再按。 回执会这么说,而且紧接着对同一个控件再按会被拒绝,直到模型看过一眼(对这个窗口调一次
window_state,或者中间做过别的动作),或者这一步带上again:true。开关其实已经切过去、只是界面更新得晚,再按一次就又切回来了。act和act_batch是同一个引擎。 80 个真实的批里有 37 个只放了 1 步,写成批只是为了用find、wait_ms或observe。现在act这些都有。参数从严,全部校验完才开始执行。 动作不认识的字段直接报错,不再悄悄丢掉:丢掉会让守卫钩子和 hub 对同一次调用的理解不一致(hotkey 里夹带一个
key,钩子的 cmd+q 规则就对不上了,而 hub 照样把 cmd+q 发出去)。写法也一样从严:键名只认一张很短的词表(修饰键 cmd、shift、option、ctrl、fn,十几个有名字的键,f1 到 f20,或者单个可打印的 ASCII 字符),每个键单独占数组的一项。词表里还收几个别名(command、alt、control、enter、esc、backspace、forwarddelete),大小写不限,原样发给上游,守卫钩子比对之前要按同样的办法归一。词表之外的一律不发:"cmd+q"、"cmd-q"、"⌘"、全角的q、套了一层的数组,以前都会因为和钩子的规则对不上而被放过。delivery_mode和scope必须和枚举值一字不差(" foreground"在钩子眼里曾经「不是前台」),文本和值必须是字符串。窗口内的动作必须带整数pid(就算给了 token,cua 不带 pid 也不收)。repeat只给滚动和导航键,连按二十次回车或删除,落在哪儿全看当时焦点在哪儿。extra可以带 facade 没有建模的驱动参数,但不能重复已有的常规参数(extra:{delivery_mode:"foreground"}会绕过对常规参数做的全部检查)。文本里有 U+FFFF 以上的字符就预先拒绝:cua 的按键通道会把这种字丢掉,它建议的「重发剩余部分」会再丢一次。菜单栏的项一律走
menu,不能当普通元素去点,因为菜单路径才是钩子审得了的东西。效果行。
unverifiable,以及网页内容上的effect_unconfirmed(26 次网页打字 26 次都带,文字其实全进去了),属于常态,不加警告。suspected_noop、delivery_failed、部分送达、上游擅自升级成前台,这几种在真实数据里 4 次 4 次都是真的没成:加 ⚠,并且批到此为止,不再往当前焦点里接着打字。失败摘要照实写。 第一步就失败,写「什么都没生效」;否则写清前面几步已经生效、不要重发;失败那一步标明「未执行」「部分执行」还是「结果未知」。
act:double_click、right_click、set_value、menu没有桌面坐标模式;桌面或像素双击用action:"click"加count:2。scope:"desktop"不能带 pid 和 window_id,facade 会自动去掉。不给目标的 scroll 是往焦点控件发方向键或翻页键,要滚指定区域得给目标或x,y。锁屏时所有窗口的 AX 树都读不到,后台动作全部被拒。树退化时 hub 会查一下是不是锁屏,是就直说,免得模型换十种办法去试。窗口在另一个桌面空间时是同一回事,只是范围小到一个窗口:用户在别的桌面或者全屏应用里的时候,AX 对那个进程一个窗口都不列(cua 0.28.x;0.55 上没有重测),这个窗口能截图,但后台既读不了也操作不了。
list_windows会给这种窗口标上other-Space;读树退化或者动作被拒时,hub 直接说明是这个原因,叫模型停下,不要改走前台(那会把用户拽到那个空间去)。拿三个任务做对照测试时,最先把 hub 和能跨空间操作的驱动区分开的就是这一条。同一次对照里还撞上驱动的另外两个限制,现在回复里直接说明,不用模型自己再摸一遍:应用里还开着第二个顶层窗口时,cua 0.28 拒绝一切后台按键(same_pid_keyboard_ambiguity);通过 AX 往网页的<input>里写纯数字,输入框会变空(888、12.5、-5被丢掉,888a、1,000能留下)。前一条在 0.55.0 上重测时已经没有了(文本编辑开两个文稿:键入、按键、快捷键都送到了指定的那个窗口,另一个文稿没被动,前台应用没变)。0.55 换了一条限制:菜单只经应用的主窗口发,发错窗口时拒绝信息里写着主窗口是哪个,hub 会指出该用哪个window_id;应用在后台时被 macOS 置灰的菜单项用不了(「文件 → 关闭」就是)。纯数字那一条没有重测。
底层
后端崩溃自动清理、下次调用重生(靠
client.onclose,transport.onclose会被 SDK 覆写)。所有驱逐都带代际守卫,旧进程迟到的 onclose 不会误删刚重生的新 client。内存有上限。 每个窗口保留的快照按份数(64)和总行数两头封顶(4 万行,窗口自身行数的八倍更大时取后者),所有窗口合计再按行数封顶(16 万)。正在用的排在最后淘汰:整窗观察、模型最近四次观察(大窗口上它是轮着用两三份
query视图的)、最近一条给控件写了位置的回复、最近一次用过 token 的那份快照。原来固定 4 万行时,7,000 行的窗口上三份query视图的第一份会在模型还用着它的 token 时被淘汰。两次走树之间的对齐结果,缓存对新旧两棵树都是弱引用。原先它强引用着后一棵树,每条动作回执都把这次走到的树挂在上一棵后面,一棵也释放不掉:3,000 行的窗口上做 68 次动作,256 MB 堆上限的 hub 就内存耗尽,上面几道上限形同虚设。在这里被丢掉的窗口会留一个记号,之后在它上面的find先扣一次,不会当成模型从没看过这个窗口。取消不等于卡死。 SDK 把一切中止(宿主按 Esc、批的 50 秒预算到点)都包成和真超时一样的
RequestTimeout,hub 以前见到它就驱逐并杀掉后端,于是按一下 Esc,所有 token、基线和具名 session 就都没了。现在只有 hub 自己的 180 秒超时才驱逐;预算到点之后另发一个很轻的只读探测,确认后端不是真的卡死。对后端的 outputSchema 校验是刻意解除的。cua-driver 的返回信封违反它自己声明的 outputSchema,而 SDK 客户端的校验是懒生效的,
listTools()之后才武装。用真校验器的话,cua 的工具一切正常,直到第一次desk_describe,之后每次调用都抛-32602,而这时上游动作已经执行了。注入的校验器返回undefined,不是「永远通过」的函数:SDK 还有一个姊妹检查(-32600),只要缓存的校验器为真值就会触发。宿主退出(stdin EOF、SIGTERM、SIGINT)时级联关停两个后端,5 秒封顶。宿主的取消是真的中止:信号一直传到上游的 callTool,也会杀掉 osascript 子进程。
cua 的生命周期 session 过期后自动复活(
start_session加重试一次),并提示旧 token 可能已失效。拒绝信息必须点名刚才调用的那个工具才触发;重试自己半路死掉时,hub 报结果未知。上一个 hub 或后端进程建的具名 session 救不回来,hub 会提示换一个新标签。0.55 的驱动自己会把闲置的 session 重新起来,只拒绝被结束掉的(end_session、被吊销、连接关闭);这种拒绝照样复活重试,而这版驱动会把已结束 session 的快照一并作废,所以在它名下读到的 token 要重新走一次树来认,认不准就拒绝。desk_call仍然原样透传参数(Tokens 一节和下面前台开关一节列出的那些拒绝除外),另多两件事:上游报参数校验错时,把这个工具的必填项和可用参数附在后面(省一次desk_describe);结果里既有structuredContent又有 hub 的提示时,折成一个文本块,免得提示被宿主丢掉。经desk_call做像素点击,走的路和act完全一样,绕不开点不动的问题。较新的驱动。 cua 0.34 及以后,
get_window_state默认只回紧凑 markdown:hub 发现应答里没有elements就带full_output:true再要一次,之后一直这样要。0.55 还默认走树一秒就停,把走到的部分交回来;应答里一旦这样说,hub 之后每次走树都要 20 秒。20 秒还走不完的,照走到的地方展示并标明:在这样的树上find一律拒绝(半个窗口既证明不了「只有这一个」,也证明不了「没有」),差异、查询、沿用旧 token 时都会说明缺的那一行可能只是没走到。停在驱动节点上限(2,000 行)的走树按 0.28 的老办法对待,那种截断每次都落在同一行。这两件事都从应答的形态里学,不看版本号(cua-driver mcp只是代理,它报的版本可能和真正干活的守护进程不一样),驱动进程一换就忘掉重学,所以升级或回退驱动都不用重启 hub。0.55 的拒绝带着代码放在structuredContent里,hub 按代码判断;应答说动作可能已经执行(execution_state: "unknown")的报错算结果未知;type被拒而驱动其实先试过无障碍写入的,会说明文字可能已经在输入框里。0.55 给每个动作结果都附一段提示和摘要,hub 只在结果不正常时转述。开发在 0.28.2 上做;2026-11-20 整套测试和实机检查在 0.55.0 上跑过,那边点一下连同回执大约 1.3 秒,原来是 3.0 秒。可选的前台开关。
/var/db/desktop-hub/这个目录存在时,delivery_mode:"foreground"必须有一份有效、未过期、root 属主的fg-switch.json才放行,这条规矩就不只靠宿主那边的钩子守着。没有这个目录,就什么都不管。文件内容是{"v":1,"opened_at":<epoch 秒>,"expires_at":<epoch 秒>},一次最多开两小时;它必须是普通文件、root 属主、组和其他人不可写、只有一个硬链接,也就是只有用户自己用sudo才放得进去(hub 不附带写这个文件的工具)。前台输入是打到真实屏幕上的,cua 在前台既不核对window_id是不是这个pid的,也不管坐标是否落在窗口里(后台时两样都管)。所以前台的每一步发出之前(走act还是走desk_call都一样;desk_call带scope:"desktop"时同样要过开关,delivery_mode的写法必须一字不差),hub 先查一遍这个窗口:属于别的进程就拒绝,点击的位置或拖拽的终点落在窗口外面也拒绝。判断落点要知道窗口的像素比例,所以 hub 没见过这个窗口的截图之前,前台的像素点击一律拒绝;前台也不接受 zoom 图上的坐标。坐标系:
desktop_screenshot回的是屏幕真像素(Retina 是 2 倍),给 cua 的scope:"desktop"用;经desk_call调 oss 的指针工具用逻辑坐标(1 倍)。frames:true印的是元素中心点,hub 从截图得知比例之后,单位是窗口截图像素。run_script:language 不分大小写,不认识的值直接报错;每路输出超过 1MB 的部分只排空不保留(脚本会跑完),回给模型的正文截到 8KB。已知做不到的事都写进了工具描述(最后一条写在报错里),免得模型每次重新摸一遍:后台键入不经过输入法;没有后台悬停;网页富文本编辑器里要先删掉选区再打字,挪光标只能用方向键;iPad 移植的 App 不理合成的滚动和拖拽(只有 oss 的 HID 指针工具管用,它会动真光标);
verify对网页内容按设计就是返回unknown;系统的打开、保存面板属于另一个辅助进程,后台够不着。window_state附带的截图可能不是最新一帧。要「此刻」的证据,另拍一张desktop_screenshot。对抗评审做了一轮又一轮。v0.3.0 的依据是一个月的真实转录:495 次调用,其中 28% 花在失败后的恢复上。这一版里 token 的规则前后有过六版:设计评审的三个视角各自否掉了第一版,实现审查攻破了第二版,之后三轮攻击复查用端到端的复现依次攻破了第三、四、五版。这几版都想靠周围的样子认出同名控件,第六版不再认,改成让模型自己说清要的是哪一个。随后又有三轮专门去攻「说清是哪一个」的办法(
find加near)和它周围的记账。头一轮查出来的有:孤零零的控件把整页算成自己的,编号在更长的编号里被匹配上,变化清单漏掉第二处不同,hub 自己印出来的 token 自己不认;后一轮证明修补过的包含关系规则在平铺页面上仍然让孤零零的控件接受窗口里几乎所有的文字,near于是改成只认正面证据,重写了一遍;再后一轮把其中仍带推断的几种证据(重复出现的容器、对话框、全页统一的阅读方向、完全相等优先于部分命中)逐个攻破,剩下不做推断的两种,near现在只留这两种。这些复现在 7.6i 小节。之后又有八轮(第九到十六轮)去攻上面两种扣留和名字的解析;后七轮每一轮都同时查出上一轮的修补改坏的地方(逐条通过队列变成每条两次调用、登录框每一步都被扣、密码强度条被当成进度条、行长上限让某一个控件独占了行证据、放开的复选框按文字而不是按位置去认、没名字的按钮能把位置挤错、空值又能把位置腾出来,到这一步就把这个机制整个拿掉了,没有再补第四次),这些复现因此都留在测试里:7.6j、7.6l、7.6n、7.6o、7.6p 和 7.6k 小节。从第十三轮起,每一轮只读上一轮的差异,差异一轮比一轮小:409 行、195 行、165 行、134 行、81 行。拿掉那个机制之后又过了最后一遍(两个审查视角,约 250 个场景,和之前几版逐一对比),没有查出比上一版变差的地方。单元测试在test/unit.mjs,端到端测试在test/smoke.mjs(假后端照 cua 的规矩让旧 token 失效,前几轮攻击复查的复现在 7.6a2 和 7.6h 小节),实机检查在test/live/。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for progressive tool usage at any scale (see https://klavis.ai)
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceAn experimental MCP server providing full control over the macOS user interface through mouse, keyboard, and window management tools. It enables AI assistants to automate desktop tasks by utilizing native accessibility APIs and OCR for real-time screen comprehension.7Creative Commons Zero v1.0 Universal
- AlicenseNot gradedqualityDmaintenanceA production-grade macOS MCP server exposing 33 tools for full desktop automation, including mouse, keyboard, screenshot, clipboard, and window control.1MIT
- AlicenseNot gradedqualityAmaintenanceA lightweight MCP server that bridges AI agents and macOS, enabling automation of file navigation, application control, UI interaction, browser automation, and system operations.244MIT
- AlicenseAqualityDmaintenanceA local MCP server that exposes macOS automation actions (AppleScript + CLIs) as tools, enabling MCP clients on your Mac to control apps, system settings, and more.39MIT