Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
docs(spec): specify granted computer use for voice control
vastsaa28e792ce88e
diff --git a/docs/adr/0340-os-computer-use-capability.md b/docs/adr/0340-os-computer-use-capability.mdnew file mode 100644index 000000000..8f163c6e0--- /dev/null+++ b/docs/adr/0340-os-computer-use-capability.md@@ -0,0 +1,196 @@+# ADR 0340: Built-in computer use is a host-owned capability behind a user-picked scope grant++- Status: Proposed+- Date: 2026-11-04+- Deciders: PI-Desktop core+- Related: [ADR 0170](0170-work-panel-browser-as-bundled-plugin.md) ·+ [ADR 0211](0211-plan-safe-plugin-actions.md) ·+ [ADR 0310](0310-local-permission-approvals-without-deadline.md) ·+ [ADR 0313](0313-live-voice-default-session-target.md) ·+ [ADR 0315](0315-live-voice-spoken-asktool-answers.md) ·+ [03-runtime/computer-use](../spec/03-runtime/computer-use.md) ·+ [03-runtime/03-tools-and-permissions](../spec/03-runtime/03-tools-and-permissions.md) ·+ [05-security/01-security](../spec/05-security/01-security.md)++## Context++The agent can drive web content: `pi.browser` owns a `WebContentsView` guest and+the bundled `Browser` tool reaches it over an allowlisted subset of CDP, using+the accessibility tree for element identity and `click(uid)` / `fill(uid)` for+input. Everything outside that guest is unreachable. The agent cannot read a+native window, cannot drive a desktop application, and cannot finish a task that+leaves the browser.++Live Voice is already a full real-time voice path with a work binding: a spoken+request reaches a session through `delegate_to_work_session`, a read-only+classifier routes it, and the existing Agent Runtime executes it under the+target session's model and permission policy. What a user can ask for by voice+is therefore exactly the set of tools the agent has — which stops at the+workspace and the embedded browser.++"Computer Use browser takeover" is item 9 of the MVP non-goals. That list froze+what the *MVP* would not ship; the product is now released software at `0.21.0`+with a plugin permission matrix, a durable permission broker, an audit log, and+a floating call surface. The request is no longer "let the model take over the+browser" but "give the agent a bounded, revocable, auditable way to operate the+machine, and let the user ask for it out loud".++Nothing in the repository supports it today. There is no screen capture, no+synthetic input, no window enumeration, and no accessibility client on any+platform; `enigo`, `robotjs`, and `nut-js` are absent by design. So this is not+an extension of an existing boundary — it is a new one, and the dangerous part+is not the capture. It is that synthetic input is indistinguishable from the+user: it can approve dialogs, including this application's own permission cards.++## Decision++1. **Computer use is a host-core capability, not a plugin, a renderer feature,+ or a Live Voice feature.** `crates/host-core` gains a `computer.*` RPC domain+ and owns window enumeration, accessibility inspection, event synthesis,+ screen capture, the grant broker, and the audit record. Electron main keeps+ exactly two jobs: it renders the host-driven target picker and the grant+ indicator, and it forwards `tools.execute`. The renderer never receives a+ window handle, a native element reference, or an input primitive, and the+ agent sidecar reaches the capability only through the existing `host.proxy`+ `tools.execute` allowlist entry — no new proxy method is introduced.++2. **One high-risk builtin tool, `Computer`.** It is a builtin like `Bash`, not+ a bundled-plugin tool, because its blast radius must not be expressible as a+ plugin permission a plugin author can request. `computer.*` is not a public+ plugin host API and is not added to the plugin permissions matrix. The tool+ exposes `inspect`, `screenshot`, `act`, `wait`, and `describe_scope`; it+ exposes no "list windows", no "focus application", and no "switch target".++3. **Accessibility first, pixels as an explicit fallback.** `inspect` returns a+ structured tree for the granted scope — role, name, value presence, enabled,+ focused, bounds, and a per-grant opaque `uid` — and `act` addresses elements+ by `uid`, dispatched through the platform accessibility action where one+ exists (`AXUIElement` actions, UIA patterns, AT-SPI actions). Coordinate+ input exists only as `act` with a `basis`: a token minted by a `screenshot`+ of the same scope, carrying the scope revision and the measured window+ geometry. The host re-validates the basis immediately before synthesis and+ refuses a stale one. A model can therefore never dispatch a blind click, and+ a window that moved between capture and action fails closed instead of+ clicking whatever took its place.++4. **A scope grant is the unit of authority, and only the user can mint one.**+ A grant names exactly one target — one window, or one application's windows —+ chosen by the user in a host-driven picker. It carries a revision, an action+ budget, an idle expiry, and an input policy. The model cannot name, request+ by title, enumerate, or widen a target; a tool call outside the granted scope+ is an error, not a prompt to expand. There is at most one active grant per+ desktop instance, mirroring the single Live Voice call slot, and a grant is+ bound to the session and the turn chain that owns it, so a subagent inherits+ the active grant but cannot create a second one.++5. **Two refusals are absolute and not reachable by any permission mode,+ setting, grant, or `auto` policy.** First, the capability never targets+ PI-Desktop's own windows — its approval cards, its settings, its secrets+ surfaces, its Live Voice widget — because synthetic input into this+ application is a direct permission-broker bypass. Second, capture and+ synthesis both refuse while the OS reports a secure input state or the+ focused element is a password field. A user-editable application denylist+ sits on top of these two, and the built-in credential-surface entries in it+ cannot be removed.++6. **The permission mode governs the grant, not each keystroke.** Creating a+ grant is always an explicit desktop-UI decision with no deadline, like every+ other local approval (ADR 0310); `auto` does not mint grants, and a spoken+ request cannot. Within an active grant, `inspect` and `screenshot` need no+ further approval. Input actions follow the grant's input policy:+ `confirm-each` (the default, and the only option under `ask`) raises an+ approval card per input batch, while `autonomous-in-scope` requires explicit+ opt-in at grant time and is offered only under `accept-edits` and `auto`.+ Both policies stay inside the action budget, the idle expiry, the scope+ re-validation, and a kill switch the user can always reach: the indicator's+ Stop, a global shortcut, and revoking the grant.++7. **Plan and Goal hard-deny `Computer` before permission evaluation**, exactly+ like `Write` and `Edit`. It is not plan-safe: it mutates state outside the+ workspace that the host cannot snapshot, diff, or roll back.++8. **Voice reaches computer use only through the path that already exists.**+ Live Voice stays a voice interface with no new authority: a spoken request+ becomes `delegate_to_work_session`, the classifier routes it, and the Agent+ turn calls `Computer` under the target session's policy. Grant creation and+ every approval card remain desktop-UI decisions, consistent with ADR 0315; a+ call may *request* a grant, which surfaces in the main window while the+ floating call bar reports that the app needs attention. Progress and results+ are spoken through the existing work-feedback channel. Voice-driven computer+ use is therefore task-level delegation, not per-frame teleoperation, and the+ spec says so rather than implying a latency it cannot deliver.++9. **Supported platforms are declared, and the unsupported ones fail closed.**+ macOS uses ScreenCaptureKit and `AXUIElement` behind the Screen Recording+ and Accessibility TCC grants. Windows uses UI Automation and `SendInput`, and+ refuses a window owned by a higher-integrity process instead of silently+ dropping events. Linux/X11 is best-effort over AT-SPI and XTEST. Wayland has+ no portable synthetic input, so input is refused there with an explicit code+ while capture stays available through the portal. Every one of these is a+ distinct error code, never a hang and never a no-op reported as success.++10. **Every grant and every action is audited; content is not.** The existing+ `audit.*` sink records the grant identity, target identity, action kind,+ element role and `uid`, and outcome. Typed text is recorded as a length, not+ a value, and pixels are never written to the audit log. Screenshots that+ reach the model are tool images and follow the existing lossless tool-image+ storage path, cropped to the granted scope and downscaled; an `a11y-only`+ grant captures no pixels at all, and the grant card states which of the two+ the user is approving before they approve it.++11. **Delivery is staged, and each stage is independently shippable.** Stage 1:+ host capability, grant broker, indicator, audit, `inspect`/`act` on macOS.+ Stage 2: `screenshot` and basis-bound coordinate input. Stage 3: Windows+ UIA, then Linux/X11. Stage 4: the voice-facing refinements — spoken grant+ requests, spoken progress, and the call-bar attention state. Non-goal item 9+ is amended, not deleted: unattended full-desktop takeover and any+ model-chosen target remain non-goals.++## Consequences++- A new, genuinely dangerous privilege enters the product. It is mitigated by+ structure rather than by prompting: a single user-picked target, a revision+ checked per action, two absolute refusals, a budget, an expiry, one grant per+ instance, and an audit trail. The two refusals in decision 5 are the ones that+ must be covered by tests before any of this ships.+- host-core gains its first platform-specific native surface beyond process+ spawning, and with it three per-OS implementations and new native+ dependencies, against a supply-chain rule that prefers few reviewed deps. The+ capability must compile to a clean "unsupported on this platform" on any+ target that is not implemented yet.+- The product acquires OS permission prompts it never had. A doctor view has to+ report Screen Recording and Accessibility state per platform, because a denied+ TCC grant is indistinguishable from a broken feature from the user's side.+- Screenshots of the user's desktop can now enter a session transcript and+ therefore SQLite. That is a real privacy change; `a11y-only` grants exist so a+ user can take the capability without it.+- Live Voice gains no code-level authority, but it does gain a reachable+ consequence: a sentence spoken into a call can move a mouse. The call surface+ must make the active grant visible from the floating bar.+- Four UX surfaces are added: the target picker, the grant indicator with Stop,+ the grant card with its policy and capture choice, and the settings doctor.+ Their component-level wording lands with the implementing change, not here.++## Alternatives++- **Extend the `Browser` tool to the whole desktop.** It is a bundled plugin on+ a public permission; any plugin declaring `browser.cdp` would inherit desktop+ input. Rejected.+- **Expose computer use as a plugin host API.** It makes the most dangerous+ privilege in the product requestable by a third-party manifest, and plugin+ grants are reviewed once at install rather than per target. Rejected.+- **Pixels only, with a computer-use provider model choosing coordinates.** It+ works anywhere, including canvas and custom-drawn UI, but every step ships the+ user's screen to a provider, costs a vision call per action, and breaks on any+ reflow. Kept as the explicit fallback in decision 3 instead of the default.+- **Accessibility only, with no capture at all.** Safest, and it is exactly what+ an `a11y-only` grant is. As the only mode it cannot operate canvas apps,+ remote desktops, or custom toolkits, so the capability would under-deliver on+ the request. Rejected as the sole mode.+- **A real-time voice teleoperation loop driving input directly from Live+ Voice.** Lowest latency, and it bypasses the classifier, the session policy,+ the approval cards, and the transcript — the entire reason the work path is+ safe. Rejected.+- **Let the model pick the target window.** Removes the picker friction, and+ with it the only guarantee that the agent operates on what the user meant.+ Rejected.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex aeda72433..6dfbfe2e6 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -400,3 +400,4 @@ Each ADR includes:| model-reasoning-effort-override | [Model reasoning effort override](model-reasoning-effort-override.md) | Proposed || 0339 | [Let a granted plugin reach every session, not only its imports](0339-plugin-session-all-scope.md) | Accepted (D680; amends ADR 0200 and ADR 0323) |+| 0340 | [Built-in computer use is a host-owned capability behind a user-picked scope grant](0340-os-computer-use-capability.md) | Proposed (D681; amends non-goal 9) |diff --git a/docs/spec/01-product/02-non-goals.md b/docs/spec/01-product/02-non-goals.mdindex bf449c8b6..9061ae554 100644--- a/docs/spec/01-product/02-non-goals.md+++ b/docs/spec/01-product/02-non-goals.md@@ -11,7 +11,11 @@6. Mobile clients7. Multi-user auth systems8. Billing/subscription modules-9. Computer Use browser takeover+9. Computer Use browser takeover *(amended by ADR 0340)* — browser takeover and+ unattended full-desktop control remain non-goals, and the model may never+ choose its own target. Bounded native application control through a+ user-picked, revocable, audited scope grant is an accepted capability; see+ [03-runtime/computer-use](../03-runtime/computer-use.md)10. Unconfirmed full-disk high privilege mode11. Non-English as the primary source language12. A second planner Agent, planner service, planner model, or separatediff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.mdindex 708eee919..fceb766bf 100644--- a/docs/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/spec/03-runtime/03-tools-and-permissions.md@@ -103,10 +103,10 @@ See [ordered preparation](../../adr/parallel-read-batches.md) and| Topic | Decision ||---|---|| Default mode | Agent |-| Agent tools | Read / Glob / Grep / Write / Edit / Bash + registered plugin tools + optional Jev classifier |+| Agent tools | Read / Glob / Grep / Write / Edit / Bash + Computer under an active scope grant + registered plugin tools + optional Jev classifier || Plan tools | Read / Glob / Grep / BrowserPreview / Bash / SubmitPlan + plugin tools that declare plan-safe actions || Goal tools | Read / Glob / Grep / BrowserPreview / Bash / SubmitGoal + plugin tools that declare plan-safe actions |-| Plan and Goal hard deny | Write / Edit / plugin tools without `planSafeActions` / unknown tools / the other kind's submit tool |+| Plan and Goal hard deny | Write / Edit / Computer / plugin tools without `planSafeActions` / unknown tools / the other kind's submit tool || Plugin `planSafeActions` | Non-empty array of `action` strings; runtime hides plugin tools without one in Plan/Goal, host admits listed tools, plugin-runtime rejects any action outside the list (ADR 0211) || Local permission approval | No automatic deadline; explicit decision or cancellation required || allow-session scope | toolName |@@ -134,6 +134,7 @@ Let the agent get things done, but stay under control by default.| `Write` | high | Create/overwrite files; returns the post-write `tag` || `Edit` | high | Modify files through line-anchored ops against a verified `tag` ([18](18-line-anchored-edit-contract.md)) || `Bash` | high | Execute commands |+| `Computer` | high | Inspect and operate the one native window or application the user granted; disabled without an active scope grant ([computer-use](computer-use.md), ADR 0340) || `asktool` | low | Ask one or more user questions and return the submitted answers as tool output || `TodoWrite` | low | Replace the current Agent session checklist; host validates and persists the full ordered snapshot |@@ -777,6 +778,12 @@ Rules:- `allow-session` grants continue to work under `ask` and stay scoped to thesession; under `accept-edits`/`auto` they are simply never needed.- Scratch-directory writes (D114) stay prompt-free in every mode.+- `Computer` is governed by its scope grant, not by the mode alone: creating a+ grant is always an explicit desktop-UI decision, `auto` never mints one, and+ no `allow-session` grant exists for it. Within an active grant, inspection+ auto-allows and input follows the grant's `confirm-each` (the only policy+ under `ask`) or `autonomous-in-scope` policy. Plan and Goal deny the tool+ outright ([computer-use](computer-use.md)).- UI: Settings → segmented global default; composer shows a per-session chip inAgent, Plan, and Goal whose menu offers the three effective modes without aseparate global-default/inherit entry. The chip and selected menu itemdiff --git a/docs/spec/03-runtime/05-host-core-rust.md b/docs/spec/03-runtime/05-host-core-rust.mdindex c86dbad26..4f38de6ff 100644--- a/docs/spec/03-runtime/05-host-core-rust.md+++ b/docs/spec/03-runtime/05-host-core-rust.md@@ -29,6 +29,9 @@ It does **not** replace pi. It provides safe host capabilities to:collaboration ledger)10. Secrets storage integration points11. Audit logging for sensitive actions+12. Computer-use capability: window enumeration, accessibility inspection,+ event synthesis, scoped screen capture, and the scope-grant broker+ ([computer-use](computer-use.md), ADR 0340)## 3. Non-responsibilities@@ -91,6 +94,7 @@ Domains:- `settings.*` (adapter level)- `secrets.*`- `audit.*`+- `computer.*` (scope grants, accessibility inspection, synthesis, capture)Example:@@ -127,6 +131,10 @@ notification.listthe active plugin invocation, target permission ceilings are rechecked atturn admission, callbacks are at-most-once, and restart recovery neverreplays an interrupted delivery+11. Computer use runs only inside a user-minted scope grant the host owns: the+ target is never request-supplied, the grant revision and geometry are+ re-validated before every synthesis, PI-Desktop's own windows and a secure+ input state are refused unconditionally, and grants are never persisted## 7. Packagingdiff --git a/docs/spec/03-runtime/08-error-codes.md b/docs/spec/03-runtime/08-error-codes.mdindex 393087826..e2972cdeb 100644--- a/docs/spec/03-runtime/08-error-codes.md+++ b/docs/spec/03-runtime/08-error-codes.md@@ -350,6 +350,36 @@ does not trigger automatic provider or billing fallback.| `LIVE_AUDIO_BACKPRESSURE` | no | bounded PCM or playback credits were exhausted || `LIVE_EXECUTION_NOT_CONNECTED` | no | a provider requested an unsupported function/delegation execution path |+### 3.10 Computer use (ADR 0340)++Computer-use errors are returned as `Computer` tool failures and host+`computer.*` responses. Each refusal is separately attributable: a missing+capability is never a hang and never a no-op reported as success. Retriable+means the same call may succeed after the stated condition clears — it never+means the host will retry, and it never widens a scope.++| code | retriable | meaning |+|---|---|---|+| `COMPUTER_DISABLED` | no | computer use is disabled in settings |+| `COMPUTER_NO_GRANT` | no | no active scope grant owns this session and turn chain |+| `COMPUTER_GRANT_IN_USE` | no | another session or turn chain holds the single active grant |+| `COMPUTER_GRANT_EXPIRED` | no | the grant hit its idle expiry, was revoked, or its target closed |+| `COMPUTER_BUDGET_EXHAUSTED` | no | the grant's remaining input-action budget reached zero |+| `COMPUTER_SCOPE_VIOLATION` | no | the request resolved outside the granted window or application |+| `COMPUTER_SELF_TARGET_REFUSED` | no | the target is a PI-Desktop window; refused under every mode |+| `COMPUTER_TARGET_DENYLISTED` | no | the target is on the credential-surface or user denylist |+| `COMPUTER_SECURE_INPUT_REFUSED` | no | the OS reports secure input or a password field holds focus |+| `COMPUTER_STALE_BASIS` | yes | the coordinate basis does not match a current capture of this scope |+| `COMPUTER_STALE_REVISION` | yes | the grant revision changed; re-inspect before acting |+| `COMPUTER_ELEMENT_NOT_FOUND` | yes | the `uid` is unknown, detached, or no longer in the scope |+| `COMPUTER_ELEMENT_NOT_ACTIONABLE` | no | the element exists but offers no accessibility action for this request |+| `COMPUTER_INPUT_POLICY_DENIED` | no | the grant's input policy or the user's approval decision refused this batch |+| `COMPUTER_OS_PERMISSION_MISSING` | no | Screen Recording, Accessibility, or the accessibility bus is not granted |+| `COMPUTER_TARGET_ELEVATED` | no | the target window is owned by a higher-integrity process |+| `COMPUTER_PLATFORM_UNSUPPORTED` | no | this platform or session type offers no supported inspection, synthesis, or capture path |+| `COMPUTER_CAPTURE_UNAVAILABLE` | no | an `a11y-only` grant or an unavailable capture backend forbids pixels |+| `COMPUTER_TIMEOUT` | yes | a bounded inspection, wait, synthesis, or capture stage timed out |+## 4. Mapping rules### Host RPC numeric → AppError.codediff --git a/docs/spec/03-runtime/README.md b/docs/spec/03-runtime/README.mdindex 0977eed25..29f00be1a 100644--- a/docs/spec/03-runtime/README.md+++ b/docs/spec/03-runtime/README.md@@ -23,6 +23,7 @@| [19-remote-agent-control-protocol.md](19-remote-agent-control-protocol.md) | Remote Agent Control Protocol || [20-speech.md](20-speech.md) | Host speech (ASR/TTS) || [live-voice.md](live-voice.md) | App-owned real-time voice calls |+| [computer-use.md](computer-use.md) | Granted native application control |- [Image generation and editing](21-image-generation.md)- [Portable configuration sync](22-config-sync.md)diff --git a/docs/spec/03-runtime/computer-use.md b/docs/spec/03-runtime/computer-use.mdnew file mode 100644index 000000000..5faca4eed--- /dev/null+++ b/docs/spec/03-runtime/computer-use.md@@ -0,0 +1,227 @@+# Computer Use v1++> Status: Design accepted, not implemented. This page is the authoritative+> contract for the capability described in+> [ADR 0340](../../adr/0340-os-computer-use-capability.md). No code in the+> repository implements it yet.++## Scope++Computer Use lets the agent read and operate a native application the user has+explicitly handed to it. It is disabled by default, it is separate from the+embedded `Browser` tool, and it never operates the whole desktop at once: every+call runs against one user-picked scope.++It is reachable by voice. Live Voice remains a voice interface with no new+authority — a spoken request becomes a work request on the bound session+([Live Voice Work Session Integration](live-work-session.md)), the existing+Agent turn calls the tool, and the session's model, permission mode, and+approval cards apply unchanged. Voice-driven computer use is task delegation,+not per-frame teleoperation; a spoken instruction is answered by an agent turn+with observable progress, not by a continuous control loop.++| Surface | Owner | Reach |+|---|---|---|+| `Browser` tool (`pi.browser`, ADR 0170) | Bundled plugin over allowlisted CDP | The embedded `WebContentsView` guest only |+| `Computer` tool (this page) | host-core builtin | One granted native window or application |+| Live Voice | Electron main and renderer | Audio, transcript, and work delegation; no input synthesis |++## Ownership and process model++```text+Renderer (picker UI, indicator)+ → Preload IPC → Electron Main (thin: picker, indicator, tools.execute relay)+ → Rust host-core `computer.*` (windows, accessibility, synthesis, capture,+ grant broker, audit)+```++host-core owns window enumeration, accessibility inspection, event synthesis,+screen capture, the grant broker, the action budget, and the audit record. The+renderer never receives a native window handle, a native element reference, or+an input primitive; it receives only the picker's display list and the+indicator's grant view. The agent sidecar reaches the capability exclusively+through `tools.execute` on the existing `host.proxy` allowlist — no new proxy+method is added, and `computer.*` is not a plugin host API and does not appear+in the plugin permissions matrix.++## Grant and scope++A **scope grant** is the unit of authority. Only the user mints one, and only+through the host-driven picker.++| Field | Meaning |+|---|---|+| `grantId` | Identity of this grant; appears in every tool result and audit row |+| `target` | Exactly one window, or one application's windows, chosen in the picker |+| `revision` | Incremented whenever the measured target geometry or identity changes |+| `inputPolicy` | `confirm-each` or `autonomous-in-scope` |+| `capture` | `a11y-only` or `a11y-and-pixels` |+| `actionBudget` | Remaining input actions before the grant closes |+| `idleExpiry` | Wall-clock bound; a grant with no action closes itself |++Rules:++- The model cannot name, enumerate, request by title, or widen a target. There+ is no "list windows" and no "switch target" action. A call that resolves+ outside the granted scope is an error, not a prompt to expand.+- There is at most one active grant per desktop instance, mirroring the single+ Live Voice call slot. A grant belongs to the session and turn chain that owns+ it; a subagent inherits the active grant and cannot create a second one.+- Creating a grant is an explicit desktop-UI decision with no automatic+ deadline (ADR 0310). Permission mode `auto` does not mint grants, and a+ spoken request cannot: a call may ask for one, which raises the card in the+ main window while the floating call bar reports that the app needs attention.+- The user can always revoke: the indicator's Stop, the global shortcut, closing+ the target, or disabling the feature. Revocation is immediate and terminates+ an in-flight action's remaining steps.+- Grants are never persisted. A restart, a renderer reload, or a window+ navigation leaves no grant behind.++## Absolute refusals++These two refusals are not reachable by any permission mode, setting, grant+option, or `auto` policy:++1. **The capability never targets PI-Desktop's own windows** — approval cards,+ settings, secrets surfaces, the Live Voice widget, plugin views. Synthetic+ input into this application is a direct permission-broker bypass.+2. **Capture and synthesis both refuse while the OS reports a secure input+ state, or while the focused element is a password field.** The refusal is+ reported as a code; the field's content never reaches a snapshot, a+ screenshot, or a log.++A user-editable application denylist sits on top of these. Its built-in+credential-surface entries — the platform keychain and credential UI, and the+OS authentication dialogs — cannot be removed.++## Tool contract++`Computer` is a builtin high-risk tool, not a plugin tool, so its blast radius+cannot be expressed as a permission a plugin author may request. Plan and Goal+hard-deny it before permission evaluation, exactly like `Write` and `Edit`: it+mutates state outside the workspace that the host cannot snapshot, diff, or roll+back.++| Action | Risk | Behavior |+|---|---|---|+| `describe_scope` | low | Returns the grant view: target label, revision, policy, capture mode, remaining budget |+| `inspect` | low | Structured accessibility tree of the scope: role, name, value presence, enabled, focused, bounds, per-grant opaque `uid` |+| `screenshot` | low | Scope-cropped, downscaled image plus a `basis` token; refused under an `a11y-only` grant |+| `act` | high | One bounded batch of input addressed by `uid`, or by coordinates against a `basis` |+| `wait` | low | Bounded wait for a scope condition (element present, enabled, text changed) with an explicit timeout |++`act` supports `click`, `double_click`, `right_click`, `set_value`,+`press_keys`, `scroll`, and `select`. Each is dispatched through the platform+accessibility action when one exists, and falls back to synthesis only when it+does not.++Element identity is accessibility-first. A `uid` is opaque, minted per grant,+and invalidated by a revision change. `inspect` returns no element values, only+whether a value is present, so reading a field's content is an explicit+`inspect` result field the user can see in the transcript rather than a side+effect of enumeration.++### Coordinates and freshness++Coordinate input exists only as `act` with a `basis`: a token minted by a+`screenshot` of the same scope, carrying the grant revision and the measured+window geometry. The host re-validates the basis immediately before synthesis+and refuses a stale one. Therefore:++- A model can never dispatch a blind click. Without a capture there is no basis,+ and without a basis there are no coordinates.+- A target that moved, resized, changed revision, or lost focus between capture+ and action fails closed instead of clicking whatever took its place.+- Coordinates are scope-relative and clamped to the measured window bounds. A+ coordinate outside them is an error, not a clamped click.++## Permission flow++The permission mode governs the grant, not each keystroke.++| Stage | `ask` | `accept-edits` | `auto` |+|---|---|---|---|+| Create a grant | confirm (desktop UI) | confirm (desktop UI) | confirm (desktop UI) |+| `inspect`, `screenshot`, `describe_scope` in an active grant | allow | allow | allow |+| `act` under `confirm-each` | confirm per batch | confirm per batch | confirm per batch |+| `act` under `autonomous-in-scope` | unavailable | allow | allow |+| Plan / Goal | hard deny | hard deny | hard deny |++`confirm-each` is the default and the only input policy available under `ask`.+`autonomous-in-scope` requires explicit opt-in at grant time. Both policies stay+inside the action budget, the idle expiry, the per-action scope re-validation,+and the kill switch. An `allow-session` grant for `Computer` does not exist: the+scope grant already is the session-scoped decision, and a tool-name grant would+outlive the target it was approved for.++## Platform support++| Platform | Inspection and input | Capture | Notes |+|---|---|---|---|+| macOS | `AXUIElement` behind the Accessibility TCC grant | ScreenCaptureKit behind the Screen Recording TCC grant | Secure input state refuses both |+| Windows | UI Automation plus `SendInput` | Desktop Duplication / window capture | A window owned by a higher-integrity process is refused, never silently dropped |+| Linux / X11 | AT-SPI plus XTEST, best effort | X11 capture | Requires an accessibility bus; absent toolkit support is reported, not guessed |+| Linux / Wayland | Input refused | Portal screen cast | No portable synthetic input exists; capture stays available |++Any platform or stage that is not implemented reports an explicit unsupported+code. A missing capability is never a hang and never a no-op reported as+success.++## Settings and UX surface++- Computer Use is off by default. Enabling it does not create a grant, request+ an OS permission, capture a frame, or enumerate a window.+- A doctor view reports per-platform OS permission state (Screen Recording,+ Accessibility, accessibility bus, session type) and distinguishes "not+ requested", "denied", and "unsupported on this platform". A denied TCC grant+ must not be presented as a broken feature.+- The target picker is host-driven and shows the display list only while it is+ open. It is the only way to choose a target.+- The grant indicator is visible for the whole life of a grant, names the+ target, shows the remaining budget and the capture mode, and carries Stop. It+ stays visible while the app is in the background, and the Live Voice call bar+ reflects an active grant.+- The grant card states, before approval, which capture mode is being approved+ and that `a11y-and-pixels` means screenshots of the target may enter the+ session transcript.++Component-level wording for the picker, the indicator, the grant card, and the+doctor view lands with the implementing change.++## Audit and privacy++Every grant and every action is audited through the existing `audit.*` sink:+grant identity, target identity, action kind, element role and `uid`, and+outcome. Typed text is recorded as a length, never as a value. Pixels are never+written to the audit log.++Screenshots that reach the model are tool images on the existing lossless+tool-image storage path, cropped to the granted scope and downscaled; under+`a11y-and-pixels` they therefore persist in the session transcript, which is+why `a11y-only` exists and why the grant card names the choice. Captured pixels,+accessibility values, and typed text are untrusted input: text read from a+window is data, never an instruction that can change the agent's scope, tools,+grant, or permissions.++## Error codes++Codes are registered in [08-error-codes](08-error-codes.md) §3.10 under the+`COMPUTER_` prefix. The contract is that each distinct refusal is separately+attributable: feature disabled, no grant, scope violation, stale basis, stale+revision, budget exhausted, grant expired, self-target refused, secure input+refused, denylisted target, OS permission missing, elevated target, platform+unsupported, element not found or not actionable, and timeout.++## Verification and limits++- Automated coverage must include, before any of this ships: the self-target+ refusal, the secure-input refusal, stale-basis and stale-revision rejection,+ coordinate clamping, budget and expiry closure, single-grant exclusivity,+ Plan/Goal denial, and the unsupported-platform path.+- The accessibility tree, the synthesis path, and the capture path are+ platform-specific and cannot be proven by fixtures. Real-device acceptance+ per platform is a separate, explicitly authorized matrix, and a green fixture+ suite is not a device pass.+- E2E scenarios are listed in+ [04-e2e-test-plan](../06-delivery/04-e2e-test-plan.md) under the+ `E2E-COMPUTER-USE-` prefix.diff --git a/docs/spec/03-runtime/live-voice.md b/docs/spec/03-runtime/live-voice.mdindex 6eb8a40e7..df3dc175b 100644--- a/docs/spec/03-runtime/live-voice.md+++ b/docs/spec/03-runtime/live-voice.md@@ -32,6 +32,14 @@ question itself offered; permission and Plan/Goal approvals remain desktop-UIdecisions (see [Live Voice Work Session Integration](live-work-session.md) and[ADR 0315](../../adr/0315-live-voice-spoken-asktool-answers.md)).+Live Voice holds no computer-use authority of its own. A spoken request can+reach the `Computer` tool only as an ordinary work request on the bound session,+executed by the Agent turn under that session's policy; minting a scope grant+stays a desktop-UI decision, which a call may ask for but never make, and the+call bar only reports that the app needs attention. Voice-driven computer use is+task delegation, not per-frame teleoperation+([Computer Use](computer-use.md), [ADR 0340](../../adr/0340-os-computer-use-capability.md)).+## Ownership and securityElectron Main owns the one-call slot, selected account, credential resolution,diff --git a/docs/spec/03-runtime/live-work-session.md b/docs/spec/03-runtime/live-work-session.mdindex 79864024d..4ee190081 100644--- a/docs/spec/03-runtime/live-work-session.md+++ b/docs/spec/03-runtime/live-work-session.md@@ -33,6 +33,11 @@ target session's current model and permission policy.read for classification; changing target changes the eligible session.When disabled, no prior session messages are read. Context consent grants noexecution authority and is not persisted.+- A work request may reach the `Computer` tool, but only as the target session's+ own Agent turn and only inside a scope grant the user already minted in the+ desktop UI. A spoken request can ask for a grant and never mint one, cannot+ choose or widen the target, and is refused outright in Plan and Goal+ ([Computer Use](computer-use.md)).## Candidate and routing flowdiff --git a/docs/spec/05-security/01-security.md b/docs/spec/05-security/01-security.mdindex d880ecd0f..7e6ddc579 100644--- a/docs/spec/05-security/01-security.md+++ b/docs/spec/05-security/01-security.md@@ -350,6 +350,7 @@ host-core. They do not change the loopback-only rule above.| Dependency poisoning | lockfiles, few deps, native-module review || Malicious local plugin | declared permissions, no secret access, process isolation tracked post-MVP (ADR 0008) || Skill market SSRF via user source URL | public-HTTPS classifier + DNS + per-hop redirect checks in main; renderer CSP forbids the fetch (ADR 0243) |+| Synthetic input approving this app's own dialogs | computer use refuses PI-Desktop windows and credential surfaces unconditionally; scope grant is user-picked and host-owned (ADR 0340) |## 11. Security acceptance gates@@ -370,6 +371,10 @@ host-core. They do not change the loopback-only rule above.10. Local MCP control is loopback-only, bearer-authenticated, opt-in, bounded,excludes secret writes and native pickers, and requires confirmation forsession permission-mode changes+11. Computer use cannot run without a user-minted scope grant, cannot target+ PI-Desktop's own windows or a secure input state under any mode, refuses a+ stale basis or revision instead of synthesizing input, and is denied+ outright in Plan and Goal## 12. Native Pi session boundary (ADR 0254)@@ -407,3 +412,33 @@ the parent's session directory (fsync, then a no-clobber hardlink to the finalname); cleanup removes only files whose device/inode and content still matchwhat this operation created, and unexpected filesystem failures cross thepreload boundary only as a path-free classified error.++## 13. Computer-use boundary (ADR 0340)++Synthetic input is indistinguishable from the user, so the boundary is+structural rather than advisory. The capability lives in host-core; the+renderer never holds a window handle, a native element reference, or an input+primitive, and the sidecar reaches it only through the existing `host.proxy`+`tools.execute` allowlist entry. `computer.*` is not a plugin host API and is+not requestable in a plugin manifest.++Authority is one user-minted scope grant naming one window or application. The+model cannot name, enumerate, or widen a target, there is at most one active+grant per desktop instance, and grants are never persisted. Every input action+re-validates the grant revision and the measured geometry; coordinate input+requires a `basis` minted by a capture of the same scope, and a stale basis is+refused rather than replayed against whatever now occupies those pixels.++Two refusals hold under every permission mode, setting, and grant option: the+capability never targets PI-Desktop's own windows — approval cards, settings,+secrets surfaces, the Live Voice widget, plugin views — and both capture and+synthesis refuse while the OS reports a secure input state or a password field+holds focus. A user-editable application denylist sits above them, and its+built-in credential-surface entries cannot be removed.++Captured pixels, accessibility values, and text read from a window are untrusted+input: they are data, never instructions that can change the agent's scope,+tools, grant, or permissions. The audit log records grant and action identity+with typed text reduced to a length and no pixels; screenshots reaching the+model are scope-cropped tool images, and an `a11y-only` grant captures none.+See [03-runtime/computer-use](../03-runtime/computer-use.md).diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex f061b51f9..428d84064 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -19586,3 +19586,101 @@ their separate platform acceptance.`apps/desktop/test/plugin-projects.test.mjs` covers pin-independent ordering,group lookup failure, missing project providers, failed/malformed lookup,rename identity, and stale results after Host replacement.++## Computer use (ADR 0340)++These scenarios are specified before implementation. Every one of them is a+landing gate for the capability described in+[03-runtime/computer-use](../03-runtime/computer-use.md); none is implemented+yet, and all are `NOT RUN`.++### E2E-COMPUTER-USE-grant-is-user-minted-and-revocable++- **Preconditions**: Isolated desktop profile, computer use enabled, OS+ permissions granted on the platform under test, one fixture target+ application, no provider account needed.+- **Steps**: Ask the agent to operate the target before any grant exists. Mint a+ grant through the picker, run `describe_scope`, `inspect`, and one `act`.+ Press Stop in the indicator mid-task. Mint a second grant from another session+ while the first is active. Let a grant idle past its expiry, and exhaust an+ action budget.+- **Expected**: The first request fails `COMPUTER_NO_GRANT` without an OS prompt+ or capture. The grant appears in the indicator with target, budget, and+ capture mode, and stays visible while the app is backgrounded. Stop terminates+ the remaining steps immediately. The second grant is refused+ `COMPUTER_GRANT_IN_USE`. Idle expiry and budget exhaustion close the grant with+ their own codes, and no grant survives a restart.+- **Specs**: [Computer Use](../03-runtime/computer-use.md),+ [03-tools-and-permissions](../03-runtime/03-tools-and-permissions.md).+- **Status**: NOT RUN — capability not implemented.++### E2E-COMPUTER-USE-self-target-and-secure-input-refused++- **Preconditions**: Isolated desktop profile with an active grant, a PI-Desktop+ window with a pending approval card, and a fixture window containing a+ password field.+- **Steps**: Attempt to inspect, capture, and act on a PI-Desktop window,+ including its approval card and the Live Voice widget, under every permission+ mode including `auto` and under an `autonomous-in-scope` grant. Focus the+ password field and attempt `inspect`, `screenshot`, and `set_value`. Attempt a+ target on the built-in credential denylist and try to remove that entry.+- **Expected**: Every self-target attempt fails `COMPUTER_SELF_TARGET_REFUSED`;+ no synthetic event reaches any PI-Desktop window and no approval card is+ dismissed. Secure input refuses capture and synthesis with+ `COMPUTER_SECURE_INPUT_REFUSED`, and no field content appears in a snapshot,+ image, tool result, or log. The built-in denylist entry cannot be removed.+- **Specs**: [Computer Use](../03-runtime/computer-use.md),+ [05-security/01-security](../05-security/01-security.md) §13.+- **Status**: NOT RUN — capability not implemented.++### E2E-COMPUTER-USE-stale-basis-and-revision-fail-closed++- **Preconditions**: Isolated desktop profile, an `a11y-and-pixels` grant, and a+ fixture window that can be moved, resized, and re-stacked on demand.+- **Steps**: Capture a `screenshot`, move the target, then act on the stale+ basis. Resize the target between `inspect` and `act` on a `uid`. Act with a+ coordinate outside the measured bounds. Act with a basis minted for a+ different grant. Act under an `a11y-only` grant with coordinates.+- **Expected**: `COMPUTER_STALE_BASIS`, `COMPUTER_STALE_REVISION`,+ `COMPUTER_SCOPE_VIOLATION`, and `COMPUTER_CAPTURE_UNAVAILABLE` respectively;+ no event is dispatched in any of them, nothing is clamped silently, and the+ target application observes no input.+- **Specs**: [Computer Use](../03-runtime/computer-use.md),+ [08-error-codes](../03-runtime/08-error-codes.md) §3.10.+- **Status**: NOT RUN — capability not implemented.++### E2E-COMPUTER-USE-voice-request-cannot-mint-a-grant++- **Preconditions**: Isolated desktop profile, a Live Voice fixture adapter with+ a bound work session, computer use enabled with no active grant, no real+ provider account or microphone.+- **Steps**: Deliver a spoken request that asks the agent to operate an+ application. Repeat after a user mints a grant in the desktop UI. Repeat with+ the session in Plan and in Goal.+- **Expected**: The first request produces a desktop-UI grant request, not a+ grant: the card appears in the main window, the call bar reports that the app+ needs attention, and no capture or synthesis happens before the user decides.+ After a grant exists, the request runs as an ordinary Agent turn under the+ session's policy, with progress spoken through the existing work-feedback+ channel. Plan and Goal deny the tool before permission evaluation.+- **Specs**: [Computer Use](../03-runtime/computer-use.md),+ [live-voice](../03-runtime/live-voice.md),+ [live-work-session](../03-runtime/live-work-session.md).+- **Status**: NOT RUN — capability not implemented.++### E2E-COMPUTER-USE-platform-support-is-explicit++- **Preconditions**: One run per supported platform plus a Wayland session and a+ platform with the OS permission denied.+- **Steps**: Enable the feature and open the doctor view on each platform. Mint a+ grant and act. On Windows, target a window owned by a higher-integrity+ process. On Wayland, attempt input and then capture. On a platform with Screen+ Recording or Accessibility denied, attempt inspection and capture.+- **Expected**: The doctor view distinguishes "not requested", "denied", and+ "unsupported on this platform". Input on Wayland fails+ `COMPUTER_PLATFORM_UNSUPPORTED` while portal capture still works; an elevated+ Windows target fails `COMPUTER_TARGET_ELEVATED` rather than dropping events; a+ denied OS permission fails `COMPUTER_OS_PERMISSION_MISSING`. No path hangs and+ none reports success without acting.+- **Specs**: [Computer Use](../03-runtime/computer-use.md).+- **Status**: NOT RUN — capability not implemented.diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex bf3b96286..afbdbde5c 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -8189,3 +8189,52 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.`apps/desktop/test/plugin-session-api.test.mjs`. See ADR 0339, ADR 0200'samendment, ADR 0323's corrected alternative, `03-plugin-api.md` §plugin-ownedand host-wide sessions, `13-plugin-permissions-matrix.md` §2, and E2E-268.++## 2026-11-04 — Computer use is a host-owned capability behind a scope grant (D681)++- D681 / ADR 0340 accepts bounded native application control as a design. The+ agent could already drive the embedded browser guest over allowlisted CDP and+ nothing else; there is no screen capture, synthetic input, window enumeration,+ or accessibility client anywhere in the repository. This decision records the+ contract, not an implementation: no code ships with it.+- The capability lives in `crates/host-core` as a `computer.*` domain and+ reaches the agent as one high-risk builtin tool, `Computer`. It is deliberately+ not a plugin host API, so the most dangerous privilege in the product cannot be+ requested by a third-party manifest. Electron main stays thin — the picker, the+ indicator, and the `tools.execute` relay — and the sidecar needs no new+ `host.proxy` method.+- Authority is one user-minted scope grant naming one window or application,+ with a revision, an action budget, an idle expiry, an input policy, and a+ capture mode. The model cannot name, enumerate, or widen a target; there is at+ most one active grant per desktop instance; grants are never persisted.+- Identity is accessibility-first: `inspect` returns roles, names, bounds and+ per-grant opaque `uid`s, and `act` dispatches platform accessibility actions.+ Coordinates exist only against a `basis` minted by a capture of the same+ scope, re-validated immediately before synthesis, so a blind click is+ unexpressible and a moved window fails closed.+- Two refusals hold under every mode, setting and grant option: the capability+ never targets PI-Desktop's own windows, because synthetic input into this app+ is a permission-broker bypass, and both capture and synthesis refuse under a+ secure input state or a focused password field. The built-in+ credential-surface denylist entries cannot be removed.+- Permission mode governs the grant rather than each keystroke. Minting is+ always an explicit desktop-UI decision with no deadline; `auto` mints nothing+ and a spoken request cannot. Within a grant, inspection auto-allows and input+ follows `confirm-each` (the only policy under `ask`) or an opt-in+ `autonomous-in-scope`. Plan and Goal hard-deny the tool, and no+ `allow-session` grant exists for it.+- Voice gains no authority: a spoken request reaches `Computer` only as a work+ request on the bound session through the existing delegate/classifier path,+ executed by the Agent turn. Voice-driven computer use is task delegation, not+ per-frame teleoperation.+- macOS (`AXUIElement`, ScreenCaptureKit) and Windows (UIA, `SendInput`, with+ higher-integrity targets refused) are the supported platforms; Linux/X11 is+ best-effort over AT-SPI and XTEST; Wayland refuses input and keeps portal+ capture. Every unsupported path has its own code, never a hang or a silent+ no-op.+- Non-goal 9 is amended rather than deleted: browser takeover, unattended+ full-desktop control, and any model-chosen target remain non-goals.+- Specified, not built: `03-runtime/computer-use.md`,+ `08-error-codes.md` §3.10 (`COMPUTER_*`), `05-host-core-rust.md` §2/§5b/§6,+ `05-security/01-security.md` §13, `03-tools-and-permissions.md` §0/§2/§6, and+ the five `E2E-COMPUTER-USE-*` landing gates, all `NOT RUN`.diff --git a/docs/spec/NAV.md b/docs/spec/NAV.mdindex a9031129c..1c16dd8b8 100644--- a/docs/spec/NAV.md+++ b/docs/spec/NAV.md@@ -45,6 +45,7 @@- [20-speech.md](03-runtime/20-speech.md)- [live-voice.md](03-runtime/live-voice.md)- [live-work-session.md](03-runtime/live-work-session.md)+- [computer-use.md](03-runtime/computer-use.md)- [21-image-generation.md](03-runtime/21-image-generation.md)- [22-config-sync.md](03-runtime/22-config-sync.md)- [svg-attachment-input.md](03-runtime/svg-attachment-input.md)diff --git a/docs/zh-CN/adr/index.md b/docs/zh-CN/adr/index.mdindex 819244994..6e0e866fb 100644--- a/docs/zh-CN/adr/index.md+++ b/docs/zh-CN/adr/index.md@@ -317,6 +317,7 @@ ADR 记录那些不应被静默改变的架构选择。中文入口与英文索| 0312 | [会话级 Todo 清单](/adr/0312-session-scoped-todo-checklist) | 已接受实施 || registry-header-variable-spelling | [Remote header variables accept the registry's `{name}` spelling](/adr/registry-header-variable-spelling) | Proposed || 0339 | [插件可访问任意会话(新增 .all 权限)](/adr/0339-plugin-session-all-scope) | 已接受(修订 ADR 0200、ADR 0323;D680) |+| 0340 | [内置电脑操作是宿主拥有、以用户挑选的作用域授权为门的能力](/adr/0340-os-computer-use-capability) | 提议中(D681;修订非目标第 9 条) |## 什么时候看 ADRdiff --git a/docs/zh-CN/spec/01-product/02-non-goals.md b/docs/zh-CN/spec/01-product/02-non-goals.mdindex 8b631365d..f47fc7055 100644--- a/docs/zh-CN/spec/01-product/02-non-goals.md+++ b/docs/zh-CN/spec/01-product/02-non-goals.md@@ -14,7 +14,10 @@6. 移动客户端7. 多用户认证系统8.Billing/subscription 模块-9.计算机使用浏览器接管+9.计算机使用浏览器接管 *(由 ADR 0340 修订)*——浏览器接管与无人看管的+ 全桌面控制仍是非目标,模型也永不自行选择目标。通过用户挑选、可撤销、+ 有审计的作用域授权来实现有界的原生应用操作是已接受的能力,见+ [03-runtime/computer-use](/zh-CN/spec/03-runtime/computer-use)10、未确认的全盘高权限模式11. 非英语作为主要源语言12. 第二个规划器 Agent、规划器服务、规划器模型或单独的diff --git a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.mdindex acf69d1b9..f3982aa05 100644--- a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md@@ -76,10 +76,10 @@ ToolBudget 一次授予全部资源和容量;等待前驱或资源不占槽位| 主题 | 决定 ||---|---|| 默认模式 | Agent |-| Agent 工具 | 读取 / Glob / Grep / 写入 / 编辑 / Bash + 已注册的插件工具 |+| Agent 工具 | 读取 / Glob / Grep / 写入 / 编辑 / Bash + 活动作用域授权下的 Computer + 已注册的插件工具 || Plan 工具 | 读取 / Glob / Grep / BrowserPreview / Bash / SubmitPlan + 声明 plan-safe 动作的插件工具 || Goal 工具 | 读取 / Glob / Grep / BrowserPreview / Bash / SubmitGoal + 声明 plan-safe 动作的插件工具 |-| Plan 和 Goal 硬拒绝 | 写入 / 编辑 / 没有 `planSafeActions` 的插件工具 / 未知工具 / 另一类的提交工具 |+| Plan 和 Goal 硬拒绝 | 写入 / 编辑 / Computer / 没有 `planSafeActions` 的插件工具 / 未知工具 / 另一类的提交工具 || 插件 `planSafeActions` | 非空的 `action` 字符串数组;运行时在 Plan/Goal 中隐藏没有该列表的插件工具,host 放行已列出的工具,plugin-runtime 拒绝列表外的任何动作(ADR 0211) || 本地权限确认 | 无自动截止时间;必须明确决定或取消 || 允许会话范围 | 工具名称 |@@ -107,6 +107,7 @@ ToolBudget 一次授予全部资源和容量;等待前驱或资源不占槽位| `Write` | 高 | Create/overwrite 文件;返回写入后的 `tag` || `Edit` | 高 | 通过针对已校验 `tag` 的行锚定操作修改文件([18](18-line-anchored-edit-contract.md)) || `Bash` | 高 | 执行命令 |+| `Computer` | 高 | 检查并操作用户授权的那一个原生窗口或应用;没有活动作用域授权时不可用([computer-use](computer-use.md),ADR 0340) || `asktool` | 低 | 询问一个或多个用户问题并将提交的答案作为工具输出返回 || `TodoWrite` | 低 | 替换当前 Agent 会话清单;由主机校验并持久化完整有序快照 |@@ -591,6 +592,11 @@ MCP 工具调用会显示审批卡片,原因为 "MCP server tool requires appr- `allow-session` 赠款继续在 `ask` 下运作,范围仅限于会议;在 `BrowserPreview`/`ask` 下,根本不需要它们。- 暂存目录写入 (D114) 在每种模式下都保持无提示。+- `Computer` 由它的作用域授权治理,而不只由模式治理:创建授权始终是桌面 UI+ 的显式决定,`auto` 从不签发授权,该工具也不存在 `allow-session` 授权。+ 在活动授权内,检查类动作自动允许,输入遵循授权的 `confirm-each`(`ask`+ 下唯一可用的策略)或 `autonomous-in-scope` 策略。Plan 与 Goal 直接拒绝该+ 工具([computer-use](computer-use.md))。- UI:设置→分段全局默认;输入框在中显示每个会话的芯片Agent、Plan 和 Goal 的菜单提供了三种有效模式,无需单独的 global-default/inherit 条目。芯片和选定的菜单项diff --git a/docs/zh-CN/spec/03-runtime/05-host-core-rust.md b/docs/zh-CN/spec/03-runtime/05-host-core-rust.mdindex 803cb6195..a416b6d56 100644--- a/docs/zh-CN/spec/03-runtime/05-host-core-rust.md+++ b/docs/zh-CN/spec/03-runtime/05-host-core-rust.md@@ -31,6 +31,8 @@和执行字段,以及持久通知收件箱)10. 密钥存储集成点11.敏感操作的审核日志记录+12. 电脑操作能力:窗口枚举、无障碍检查、事件合成、作用域内屏幕截取,+ 以及作用域授权中介([computer-use](computer-use.md),ADR 0340)## 3. 非责任@@ -92,6 +94,7 @@ EOF 或不可恢复的管道错误。无法创建任一控制线程- `settings.*`(适配器级别)- `secrets.*`- `audit.*`+- `computer.*`(作用域授权、无障碍检查、合成、截取)示例:@@ -124,6 +127,9 @@ notification.list8. 秘密永远不会返回到渲染器日志中9. 插件、shell 或批准路径中的崩溃失败关闭并且不授予或重放执行+10. 电脑操作只在用户签发、由宿主持有的作用域授权内运行:目标永不由请求+ 提供,每次合成前都重新校验授权 revision 与几何,PI-Desktop 自身窗口+ 与安全输入状态一律拒绝,授权从不持久化## 7. 包装diff --git a/docs/zh-CN/spec/03-runtime/08-error-codes.md b/docs/zh-CN/spec/03-runtime/08-error-codes.mdindex 921056861..6f4363815 100644--- a/docs/zh-CN/spec/03-runtime/08-error-codes.md+++ b/docs/zh-CN/spec/03-runtime/08-error-codes.md@@ -343,6 +343,34 @@ ADR 0285)。渲染进程除了一个标识徽章外看不到本地/远程之| `LIVE_AUDIO_BACKPRESSURE` | 否 | PCM 或播放 credit 的有界容量已耗尽 || `LIVE_EXECUTION_NOT_CONNECTED` | 否 | Provider 请求了当前不支持的函数/delegation 执行路径 |+### 3.10 电脑操作(ADR 0340)++电脑操作错误以 `Computer` 工具失败和宿主 `computer.*` 响应的形式返回。每一种拒绝+都可单独归因:缺失的能力永不表现为挂起,也永不以成功回报空操作。可重试表示同一+次调用在所述条件解除后可能成功——它从不意味着宿主会自动重试,也从不扩大作用域。++| code | 可重试 | 含义 |+|---|---|---|+| `COMPUTER_DISABLED` | 否 | 设置中关闭了电脑操作 |+| `COMPUTER_NO_GRANT` | 否 | 没有活动作用域授权属于该会话与轮次链 |+| `COMPUTER_GRANT_IN_USE` | 否 | 另一个会话或轮次链持有唯一的活动授权 |+| `COMPUTER_GRANT_EXPIRED` | 否 | 授权空闲过期、被撤销,或目标已关闭 |+| `COMPUTER_BUDGET_EXHAUSTED` | 否 | 授权剩余的输入动作预算已归零 |+| `COMPUTER_SCOPE_VIOLATION` | 否 | 请求解析到被授权窗口或应用之外 |+| `COMPUTER_SELF_TARGET_REFUSED` | 否 | 目标是 PI-Desktop 窗口;任何模式下都拒绝 |+| `COMPUTER_TARGET_DENYLISTED` | 否 | 目标在凭据界面名单或用户拒绝名单上 |+| `COMPUTER_SECURE_INPUT_REFUSED` | 否 | 操作系统报告安全输入,或密码字段持有焦点 |+| `COMPUTER_STALE_BASIS` | 是 | 坐标 `basis` 与该作用域的当前截取不匹配 |+| `COMPUTER_STALE_REVISION` | 是 | 授权 revision 已变化;请先重新 inspect 再动作 |+| `COMPUTER_ELEMENT_NOT_FOUND` | 是 | `uid` 未知、已分离,或已不在作用域内 |+| `COMPUTER_ELEMENT_NOT_ACTIONABLE` | 否 | 元素存在,但对该请求没有可用的无障碍动作 |+| `COMPUTER_INPUT_POLICY_DENIED` | 否 | 授权的输入策略或用户的审批决定拒绝了这一批 |+| `COMPUTER_OS_PERMISSION_MISSING` | 否 | 屏幕录制、无障碍或无障碍总线未被授权 |+| `COMPUTER_TARGET_ELEVATED` | 否 | 目标窗口由更高完整性级别的进程拥有 |+| `COMPUTER_PLATFORM_UNSUPPORTED` | 否 | 该平台或会话类型没有受支持的检查、合成或截取路径 |+| `COMPUTER_CAPTURE_UNAVAILABLE` | 否 | `a11y-only` 授权或不可用的截取后端禁止像素 |+| `COMPUTER_TIMEOUT` | 是 | 有界的检查、等待、合成或截取阶段超时 |+## 4. 映射规则### 主机 RPC 数字 → AppError.codediff --git a/docs/zh-CN/spec/03-runtime/README.md b/docs/zh-CN/spec/03-runtime/README.mdindex 15693e8d1..5ab357b06 100644--- a/docs/zh-CN/spec/03-runtime/README.md+++ b/docs/zh-CN/spec/03-runtime/README.md@@ -26,5 +26,6 @@| [19-remote-agent-control-protocol.md](/zh-CN/spec/03-runtime/19-remote-agent-control-protocol) | 远程 Agent 控制协议 || [20-speech.md](/zh-CN/spec/03-runtime/20-speech) | 宿主语音(转写/朗读) || [live-voice.md](/zh-CN/spec/03-runtime/live-voice) | 应用托管的实时语音通话 |+| [computer-use.md](/zh-CN/spec/03-runtime/computer-use) | 受授权的原生应用操作 |- [图片生成与编辑](/zh-CN/spec/03-runtime/21-image-generation)diff --git a/docs/zh-CN/spec/03-runtime/computer-use.md b/docs/zh-CN/spec/03-runtime/computer-use.mdnew file mode 100644index 000000000..3d5bb6161--- /dev/null+++ b/docs/zh-CN/spec/03-runtime/computer-use.md@@ -0,0 +1,134 @@+# 电脑操作 v1++> **翻译说明:** 本页与[英文源规格](/spec/03-runtime/computer-use)一一对应。代码、协议字段和标识符保留原文;如翻译与英文源事实存在差异,以英文版本为准。++> 状态:设计已接受,尚未实现。本页是 [ADR 0340](../../../adr/0340-os-computer-use-capability.md) 所述能力的权威契约,仓库中目前没有任何代码实现它。++## 范围++电脑操作让 Agent 读取并操作用户明确交给它的某一个原生应用。该能力默认关闭,与内置 `Browser` 工具相互独立,且永不同时操作整个桌面:每次调用都只在一个由用户挑选的作用域内执行。++它可以通过语音触达。实时语音仍然只是语音接口,不获得任何新权限——一句口述请求会变成绑定会话上的工作请求(见[实时语音工作会话集成](/zh-CN/spec/03-runtime/live-work-session)),由现有 Agent 轮次调用工具,会话的模型、权限模式和审批卡片完全不变。语音驱动的电脑操作是任务委派,不是逐帧遥控:一句口述由一个带可见进度的 Agent 轮次来回答,而不是一条持续的控制回路。++| 界面 | 所有者 | 可达范围 |+|---|---|---|+| `Browser` 工具(`pi.browser`,ADR 0170) | 走白名单 CDP 的内置插件 | 仅限内嵌 `WebContentsView` 宿体 |+| `Computer` 工具(本页) | host-core 内置工具 | 一个被授权的原生窗口或应用 |+| 实时语音 | Electron Main 与 Renderer | 音频、转录与工作委派;不做输入合成 |++## 所有权与进程模型++```text+Renderer(挑选器 UI、指示器)+ → Preload IPC → Electron Main(薄层:挑选器、指示器、tools.execute 转发)+ → Rust host-core `computer.*`(窗口、无障碍、合成、截取、+ 授权中介、审计)+```++host-core 拥有窗口枚举、无障碍检查、事件合成、屏幕截取、授权中介、动作预算与审计记录。Renderer 永不拿到原生窗口句柄、原生元素引用或输入原语;它只拿到挑选器的展示列表和指示器的授权视图。Agent sidecar 只能通过现有 `host.proxy` 白名单中的 `tools.execute` 触达该能力——不新增代理方法;`computer.*` 不是插件宿主 API,也不出现在插件权限矩阵中。++## 授权与作用域++**作用域授权(scope grant)** 是权限单位。只有用户能签发,且只能通过宿主驱动的挑选器签发。++| 字段 | 含义 |+|---|---|+| `grantId` | 本次授权的身份;出现在每个工具结果和审计行中 |+| `target` | 恰好一个窗口,或一个应用的窗口集合,由挑选器选定 |+| `revision` | 目标的测量几何或身份变化时递增 |+| `inputPolicy` | `confirm-each` 或 `autonomous-in-scope` |+| `capture` | `a11y-only` 或 `a11y-and-pixels` |+| `actionBudget` | 授权关闭前剩余的输入动作数 |+| `idleExpiry` | 墙钟上限;长时间无动作的授权自行关闭 |++规则:++- 模型不能命名、枚举、按标题请求或扩大目标。没有"列出窗口",也没有"切换目标"动作。解析到授权作用域之外的调用是错误,不是扩权提示。+- 每个桌面实例最多只有一个活动授权,与实时语音的单通话槽位一致。授权属于签发它的会话与轮次链;子 Agent 继承活动授权,但不能创建第二个。+- 创建授权始终是桌面 UI 的显式决定,且没有自动截止期限(ADR 0310)。权限模式 `auto` 不签发授权,口述请求也不能:通话可以请求授权,于是卡片出现在主窗口,而悬浮通话条只提示应用需要关注。+- 用户随时可以撤销:指示器的"停止"、全局快捷键、关闭目标,或关闭该功能。撤销立即生效,并终止进行中动作的剩余步骤。+- 授权从不持久化。重启、Renderer 重载或窗口导航都不会留下授权。++## 绝对拒绝++以下两条拒绝不可通过任何权限模式、设置、授权选项或 `auto` 策略触达:++1. **该能力永不以 PI-Desktop 自身窗口为目标**——审批卡片、设置、密钥界面、实时语音悬浮件、插件视图。向本应用合成输入等于直接绕过权限中介。+2. **当操作系统报告安全输入状态,或焦点落在密码字段时,截取与合成一律拒绝。** 拒绝以错误码上报;该字段内容永不进入快照、截图或日志。++在这两条之上还有一份用户可编辑的应用拒绝名单。其中内置的凭据界面条目——平台钥匙串与凭据 UI、操作系统认证对话框——不可移除。++## 工具契约++`Computer` 是内置高风险工具而非插件工具,因此它的影响面无法被表达成插件作者可以申请的权限。Plan 与 Goal 在权限评估之前就硬拒绝它,与 `Write`、`Edit` 相同:它改变的是工作区之外、宿主无法快照、比对或回滚的状态。++| 动作 | 风险 | 行为 |+|---|---|---|+| `describe_scope` | low | 返回授权视图:目标名称、revision、策略、截取模式、剩余预算 |+| `inspect` | low | 作用域的结构化无障碍树:role、name、是否有值、是否可用、是否聚焦、bounds、按授权生成的不透明 `uid` |+| `screenshot` | low | 裁剪到作用域并缩小的图像,附带 `basis` 令牌;`a11y-only` 授权下被拒绝 |+| `act` | high | 一批有界输入,按 `uid` 寻址,或按坐标配合 `basis` 寻址 |+| `wait` | low | 带显式超时地等待作用域条件(元素出现、变为可用、文本改变) |++`act` 支持 `click`、`double_click`、`right_click`、`set_value`、`press_keys`、`scroll` 与 `select`。每一项都优先通过平台无障碍动作派发,只有在不存在对应动作时才回退到合成。++元素身份以无障碍为先。`uid` 不透明、按授权生成,并在 revision 变化时失效。`inspect` 不返回元素取值,只返回是否有值,因此读取字段内容是一个用户能在转录中看到的显式 `inspect` 结果字段,而不是枚举的副作用。++### 坐标与新鲜度++坐标输入只以 `act` 配合 `basis` 的形式存在:`basis` 由同一作用域的 `screenshot` 签发,携带授权 revision 与测得的窗口几何。宿主在合成前立即重新校验 `basis`,并拒绝过期值。因此:++- 模型永远无法派发盲点击。没有截取就没有 `basis`,没有 `basis` 就没有坐标。+- 目标在截取与动作之间移动、改变尺寸、revision 变化或失去焦点时失败关闭,而不是点击此刻占据那片像素的东西。+- 坐标相对作用域,并被夹到测得的窗口边界内。越界坐标是错误,不是被夹紧后照样点击。++## 权限流程++权限模式治理的是授权,不是每一次按键。++| 阶段 | `ask` | `accept-edits` | `auto` |+|---|---|---|---|+| 创建授权 | 确认(桌面 UI) | 确认(桌面 UI) | 确认(桌面 UI) |+| 活动授权内的 `inspect`、`screenshot`、`describe_scope` | 允许 | 允许 | 允许 |+| `confirm-each` 下的 `act` | 每批确认 | 每批确认 | 每批确认 |+| `autonomous-in-scope` 下的 `act` | 不可用 | 允许 | 允许 |+| Plan / Goal | 硬拒绝 | 硬拒绝 | 硬拒绝 |++`confirm-each` 是默认值,也是 `ask` 下唯一可用的输入策略。`autonomous-in-scope` 需要在授权时显式选择。两种策略都受动作预算、空闲过期、每动作作用域重校验以及终止开关约束。`Computer` 不存在 `allow-session` 授权:作用域授权本身就是会话级决定,而按工具名授权会活得比它被批准针对的那个目标更久。++## 平台支持++| 平台 | 检查与输入 | 截取 | 说明 |+|---|---|---|---|+| macOS | `AXUIElement`,需 Accessibility TCC 授权 | ScreenCaptureKit,需屏幕录制 TCC 授权 | 安全输入状态会同时拒绝两者 |+| Windows | UI Automation 加 `SendInput` | 桌面复制 / 窗口截取 | 由更高完整性级别进程拥有的窗口被拒绝,绝不静默丢弃 |+| Linux / X11 | AT-SPI 加 XTEST,尽力而为 | X11 截取 | 需要无障碍总线;工具包不支持时如实上报,不做猜测 |+| Linux / Wayland | 拒绝输入 | 门户屏幕投送 | 不存在可移植的合成输入;截取仍可用 |++任何尚未实现的平台或阶段都返回明确的不支持错误码。缺失的能力永不表现为挂起,也永不以成功回报空操作。++## 设置与 UX 界面++- 电脑操作默认关闭。打开开关不会创建授权、申请操作系统权限、截取画面或枚举窗口。+- 体检视图按平台报告操作系统权限状态(屏幕录制、无障碍、无障碍总线、会话类型),并区分"未申请"、"已拒绝"与"本平台不支持"。被拒绝的 TCC 授权不得呈现为功能损坏。+- 目标挑选器由宿主驱动,仅在打开期间展示列表。它是选择目标的唯一方式。+- 授权指示器在授权存续期间始终可见,标明目标、剩余预算与截取模式,并带有"停止"。应用退到后台时它仍然可见,实时语音通话条也会反映活动授权。+- 授权卡片在批准之前说明正在批准哪种截取模式,并说明 `a11y-and-pixels` 意味着目标的截图可能进入会话转录。++挑选器、指示器、授权卡片与体检视图的组件级措辞随实现变更落地,不在本页。++## 审计与隐私++每一次授权与每一个动作都通过现有 `audit.*` 落盘:授权身份、目标身份、动作类型、元素 role 与 `uid`、以及结果。键入的文本只记录长度,绝不记录取值。像素永不写入审计日志。++进入模型的截图走现有的无损工具图片存储路径,裁剪到授权作用域并缩小;因此在 `a11y-and-pixels` 下它们会留存在会话转录里——这正是 `a11y-only` 存在的原因,也是授权卡片要点明该选择的原因。被截取的像素、无障碍取值与从窗口读到的文本都是不可信输入:它们是数据,绝不是能改变 Agent 作用域、工具、授权或权限的指令。++## 错误码++错误码登记在 [08-error-codes](/zh-CN/spec/03-runtime/08-error-codes) §3.10,统一使用 `COMPUTER_` 前缀。契约是每一种拒绝都可单独归因:功能关闭、无授权、作用域越界、`basis` 过期、revision 过期、预算耗尽、授权过期、拒绝自我目标、拒绝安全输入、目标在拒绝名单上、缺少操作系统权限、目标提权、平台不支持、元素未找到或不可操作,以及超时。++## 验证与限制++- 在任何部分交付之前,自动化覆盖必须包含:自我目标拒绝、安全输入拒绝、`basis` 与 revision 过期拒绝、坐标夹取、预算与过期关闭、单授权互斥、Plan/Goal 拒绝,以及不支持平台的路径。+- 无障碍树、合成路径与截取路径都与平台相关,无法用 fixture 证明。各平台的真机验收是单独且需显式授权的矩阵;fixture 全绿不等于真机通过。+- E2E 场景列在 [04-e2e-test-plan](/zh-CN/spec/06-delivery/04-e2e-test-plan) 的 `E2E-COMPUTER-USE-` 前缀下。diff --git a/docs/zh-CN/spec/03-runtime/live-voice.md b/docs/zh-CN/spec/03-runtime/live-voice.mdindex 9474b083b..ad69d4a11 100644--- a/docs/zh-CN/spec/03-runtime/live-voice.md+++ b/docs/zh-CN/spec/03-runtime/live-voice.md@@ -14,6 +14,8 @@独立作用域的 Live Work 通话也可以解决绑定会话唯一一个待回答的 AskTool 提问,但只能从该提问自己提供的选项标签中选择;权限与 Plan/Goal 审批仍然只在桌面 UI 中决定(见[实时语音工作会话接入](live-work-session.md)与 [ADR 0315](../../../adr/0315-live-voice-spoken-asktool-answers.md))。+实时语音自身不持有任何电脑操作权限。一句口述只能作为绑定会话上的普通工作请求触达 `Computer` 工具,由该会话策略下的 Agent 轮次执行;签发作用域授权仍然是桌面 UI 的决定,通话可以请求但永不自行做出,通话条只提示应用需要关注。语音驱动的电脑操作是任务委派,不是逐帧遥控(见[电脑操作](computer-use.md)与 [ADR 0340](../../../adr/0340-os-computer-use-capability.md))。+公开设置为 `liveVoice: { enabled, selectedBindingId?, bindings }`。它只包含 Provider ID、模型/音色选择和协议 profile,不保存凭证。现有 `voice` 和 `speech` 设置保持原义。持久化 JSON 由 Host Core 所有;它会将 Live 设置与其他设置合并。没有工作绑定的纯语音 Live profile 不会创建 Agent turn、调用 AgentHost 或 MCP、访问工作区文件、执行模型生成的函数、保存录音或持久化字幕。字幕只保存在本次通话的有界 Renderer 内存缓冲区中。除非用户明确开启独立作用域的 Live Work 通话,否则 Provider delegation/function-call 请求会被拒绝或导致协议错误;Live Work 的执行与权限合同见[实时语音工作会话接入](live-work-session.md)。diff --git a/docs/zh-CN/spec/03-runtime/live-work-session.md b/docs/zh-CN/spec/03-runtime/live-work-session.mdindex edc3c5941..90221c373 100644--- a/docs/zh-CN/spec/03-runtime/live-work-session.md+++ b/docs/zh-CN/spec/03-runtime/live-work-session.md@@ -14,6 +14,7 @@ Live Voice 可以通过现有后端向 PI-Desktop 会话提交有界工作请求- 不需要逐通开启“允许工作请求”,也不要求开始前先语音列出并选择会话。语音工作请求仍只是候选请求;目标后端继续执行原有身份、准入、权限和审批规则。Provider 工具请求不能指定原始会话 ID、项目路径、模型、模式或权限。- 语音切换目标只影响后续请求;既有操作仍关联原会话。打开另一个会话供界面查看,不会暗中改变工作目标。- 上下文共享仍是独立、默认关闭的通话同意。启用后,分类器只可读取当前工作目标中有界的纯文本历史;切换目标后,可读取的会话随之改变。关闭后不读取历史消息。该同意不授予执行权限,也不会持久化。+- 工作请求可以触达 `Computer` 工具,但只能作为目标会话自己的 Agent 轮次,且只能在用户已于桌面 UI 签发的作用域授权内进行。口述请求可以请求授权而永不签发授权,不能选择或扩大目标,并在 Plan 与 Goal 中被直接拒绝(见[电脑操作](computer-use.md))。## 候选请求与路由diff --git a/docs/zh-CN/spec/05-security/01-security.md b/docs/zh-CN/spec/05-security/01-security.mdindex 2f311d244..69f798007 100644--- a/docs/zh-CN/spec/05-security/01-security.md+++ b/docs/zh-CN/spec/05-security/01-security.md@@ -228,6 +228,7 @@ MCP 市场只接受无凭据的公网 HTTPS 源和目录端点。Main 在每一| 依赖性中毒 | 锁定文件、几个 dep、本机模块审查 || 恶意本地插件 | 声明的权限、无秘密访问、MVP 后跟踪的进程隔离 (ADR 0008) || 技能市场 SSRF(用户源 URL) | 主进程公网 HTTPS 分类器 + DNS + 逐跳 redirect;渲染层 CSP 禁止该 fetch(ADR 0243) |+| 合成输入批准本应用自己的对话框 | 电脑操作无条件拒绝 PI-Desktop 窗口与凭据界面;作用域授权由用户挑选、宿主持有(ADR 0340) |## 11. 安检门@@ -247,3 +248,28 @@ approve/reject-only 和计划的 Plan 在 artifact/queue 工作之前被拒绝单独和 timeout/abort 杀死完整的进程树10. 本地 MCP 控制只允许回环、经过 bearer 认证、默认关闭且有界,不能暴露密钥写入或原生选择器,并且更改会话权限模式需要确认+11. 电脑操作在没有用户签发的作用域授权时无法运行,在任何模式下都不能以+ PI-Desktop 自身窗口或安全输入状态为目标,遇到过期 `basis` 或 revision+ 时拒绝而不是照样合成输入,并在 Plan 与 Goal 中被直接拒绝++## 13. 电脑操作边界(ADR 0340)++合成输入与用户本人不可区分,因此这条边界是结构性的,而不是靠提示。能力住在+host-core;Renderer 永不持有窗口句柄、原生元素引用或输入原语,sidecar 只能通过+现有 `host.proxy` 白名单中的 `tools.execute` 触达它。`computer.*` 不是插件宿主+API,也不能在插件清单中申请。++权限是一份由用户签发、指向一个窗口或一个应用的作用域授权。模型不能命名、枚举或+扩大目标;每个桌面实例最多一个活动授权;授权从不持久化。每次输入动作都会重新+校验授权 revision 与测得的几何;坐标输入必须携带由同一作用域的截取签发的+`basis`,过期的 `basis` 会被拒绝,而不是对此刻占据那片像素的东西重放。++两条拒绝在任何权限模式、设置与授权选项下都成立:该能力永不以 PI-Desktop 自身+窗口为目标——审批卡片、设置、密钥界面、实时语音悬浮件、插件视图——并且在操作+系统报告安全输入状态或密码字段持有焦点时,截取与合成一律拒绝。其上还有一份用户+可编辑的应用拒绝名单,其中内置的凭据界面条目不可移除。++被截取的像素、无障碍取值与从窗口读到的文本都是不可信输入:它们是数据,绝不是能+改变 Agent 作用域、工具、授权或权限的指令。审计日志记录授权与动作身份,键入文本+只记长度且不记像素;进入模型的截图是裁剪到作用域的工具图片,`a11y-only` 授权则+完全不截取像素。见 [03-runtime/computer-use](/zh-CN/spec/03-runtime/computer-use)。diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex f06c35687..e2eb45062 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -10159,3 +10159,84 @@ PluginPack 产物的解包目录,仅用于开发验证。验收 #1711 前需event/result agreement, batch rejection and delegate restoration.- **Status**: Automated offline; native UI clicking and live providers areoutside this fixture's coverage.++## 电脑操作(ADR 0340)++以下场景在实现之前先行确定。每一条都是+[03-runtime/computer-use](/zh-CN/spec/03-runtime/computer-use)+所述能力的落地闸门;目前全部未实现,状态均为 `NOT RUN`。++### E2E-COMPUTER-USE-grant-is-user-minted-and-revocable++- **前置条件**:隔离的桌面 profile,电脑操作已开启,被测平台的操作系统权限已授予,+ 一个 fixture 目标应用,无需 Provider 账号。+- **步骤**:在没有任何授权时请求 Agent 操作目标。通过挑选器签发授权,执行+ `describe_scope`、`inspect` 与一次 `act`。任务进行中按下指示器的"停止"。在第一个+ 授权仍活动时从另一个会话签发第二个授权。让授权空闲超过过期时间,并耗尽动作预算。+- **预期**:首个请求以 `COMPUTER_NO_GRANT` 失败,不触发操作系统提示也不截取画面。+ 授权出现在指示器中并标明目标、预算与截取模式,应用退到后台时仍可见。"停止"立刻+ 终止剩余步骤。第二个授权以 `COMPUTER_GRANT_IN_USE` 被拒。空闲过期与预算耗尽各以+ 自己的错误码关闭授权,且没有授权能活过重启。+- **规格**:[电脑操作](/zh-CN/spec/03-runtime/computer-use)、+ [03-tools-and-permissions](/zh-CN/spec/03-runtime/03-tools-and-permissions)。+- **状态**:NOT RUN —— 能力尚未实现。++### E2E-COMPUTER-USE-self-target-and-secure-input-refused++- **前置条件**:隔离的桌面 profile,已有活动授权,一个带待处理审批卡片的+ PI-Desktop 窗口,以及一个包含密码字段的 fixture 窗口。+- **步骤**:在包括 `auto` 的每种权限模式下、以及在 `autonomous-in-scope` 授权下,+ 尝试对 PI-Desktop 窗口(含审批卡片与实时语音悬浮件)做检查、截取与动作。让密码+ 字段获得焦点,尝试 `inspect`、`screenshot` 与 `set_value`。尝试一个位于内置凭据+ 拒绝名单上的目标,并尝试移除该条目。+- **预期**:每次自我目标尝试都以 `COMPUTER_SELF_TARGET_REFUSED` 失败;没有任何+ 合成事件到达任何 PI-Desktop 窗口,也没有审批卡片被关闭。安全输入以+ `COMPUTER_SECURE_INPUT_REFUSED` 拒绝截取与合成,字段内容不出现在快照、图像、+ 工具结果或日志中。内置拒绝名单条目无法移除。+- **规格**:[电脑操作](/zh-CN/spec/03-runtime/computer-use)、+ [05-security/01-security](/zh-CN/spec/05-security/01-security) §13。+- **状态**:NOT RUN —— 能力尚未实现。++### E2E-COMPUTER-USE-stale-basis-and-revision-fail-closed++- **前置条件**:隔离的桌面 profile,一个 `a11y-and-pixels` 授权,以及一个可按需+ 移动、改变尺寸与改变层叠顺序的 fixture 窗口。+- **步骤**:先 `screenshot`,移动目标,再基于过期 `basis` 动作。在对某个 `uid` 的+ `inspect` 与 `act` 之间改变目标尺寸。用超出测得边界的坐标动作。用另一个授权签发的+ `basis` 动作。在 `a11y-only` 授权下用坐标动作。+- **预期**:分别返回 `COMPUTER_STALE_BASIS`、`COMPUTER_STALE_REVISION`、+ `COMPUTER_SCOPE_VIOLATION` 与 `COMPUTER_CAPTURE_UNAVAILABLE`;其中任何一种都不+ 派发事件,不静默夹取,目标应用观察不到任何输入。+- **规格**:[电脑操作](/zh-CN/spec/03-runtime/computer-use)、+ [08-error-codes](/zh-CN/spec/03-runtime/08-error-codes) §3.10。+- **状态**:NOT RUN —— 能力尚未实现。++### E2E-COMPUTER-USE-voice-request-cannot-mint-a-grant++- **前置条件**:隔离的桌面 profile,带绑定工作会话的实时语音 fixture 适配器,电脑+ 操作已开启但没有活动授权,无真实 Provider 账号与麦克风。+- **步骤**:口述一条要求 Agent 操作某个应用的请求。在用户于桌面 UI 签发授权后重复。+ 在会话处于 Plan 与 Goal 时分别重复。+- **预期**:首个请求产生的是桌面 UI 的授权请求而不是授权:卡片出现在主窗口,通话条+ 提示应用需要关注,用户决定之前不发生截取或合成。授权存在后,该请求作为普通 Agent+ 轮次在会话策略下运行,进度通过现有工作反馈通道朗读。Plan 与 Goal 在权限评估之前+ 拒绝该工具。+- **规格**:[电脑操作](/zh-CN/spec/03-runtime/computer-use)、+ [live-voice](/zh-CN/spec/03-runtime/live-voice)、+ [live-work-session](/zh-CN/spec/03-runtime/live-work-session)。+- **状态**:NOT RUN —— 能力尚未实现。++### E2E-COMPUTER-USE-platform-support-is-explicit++- **前置条件**:每个受支持平台各跑一次,另加一个 Wayland 会话,以及一台操作系统+ 权限被拒绝的机器。+- **步骤**:在每个平台上开启该功能并打开体检视图。签发授权并动作。在 Windows 上以+ 由更高完整性级别进程拥有的窗口为目标。在 Wayland 上先尝试输入再尝试截取。在屏幕+ 录制或无障碍被拒绝的平台上尝试检查与截取。+- **预期**:体检视图区分"未申请"、"已拒绝"与"本平台不支持"。Wayland 上的输入以+ `COMPUTER_PLATFORM_UNSUPPORTED` 失败而门户截取仍可用;提权的 Windows 目标以+ `COMPUTER_TARGET_ELEVATED` 失败而不是丢弃事件;被拒绝的操作系统权限以+ `COMPUTER_OS_PERMISSION_MISSING` 失败。没有路径挂起,也没有路径在未动作的情况下+ 回报成功。+- **规格**:[电脑操作](/zh-CN/spec/03-runtime/computer-use)。+- **状态**:NOT RUN —— 能力尚未实现。diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.mdindex 9eb6219f1..4bc7b830b 100644--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@ -5720,3 +5720,38 @@ Markdown 源码,不是 `text/html` 负载;对禁用行内 HTML 的外部编`apps/desktop/test/plugin-session-api.test.mjs`。见 ADR 0339、ADR 0200 修订、ADR 0323 更正后的备选方案、`03-plugin-api.md` §插件拥有与全量会话、`13-plugin-permissions-matrix.md` 第 2 节与 E2E-268。++## 2026-11-04 —— 电脑操作是宿主拥有、以作用域授权为门的能力(D681)++- D681 / ADR 0340 以设计形式接受有界的原生应用操作。Agent 此前只能通过白名单+ CDP 驱动内嵌浏览器宿体,除此之外一无所能;仓库里没有任何屏幕截取、合成输入、+ 窗口枚举或无障碍客户端。本决定记录的是契约而不是实现:没有任何代码随之交付。+- 该能力住在 `crates/host-core`,作为 `computer.*` 域存在,并以唯一一个高风险+ 内置工具 `Computer` 触达 Agent。它刻意不是插件宿主 API,因此产品中最危险的+ 权限无法被第三方清单申请。Electron Main 保持为薄层——挑选器、指示器和+ `tools.execute` 转发——sidecar 不需要新的 `host.proxy` 方法。+- 权限是一份由用户签发、指向一个窗口或一个应用的作用域授权,带 revision、动作+ 预算、空闲过期、输入策略与截取模式。模型不能命名、枚举或扩大目标;每个桌面+ 实例最多一个活动授权;授权从不持久化。+- 身份以无障碍为先:`inspect` 返回 role、name、bounds 与按授权生成的不透明+ `uid`,`act` 派发平台无障碍动作。坐标只在配合 `basis`(由同一作用域的截取签发)+ 时存在,并在合成前立即重新校验,因此盲点击无法被表达,移动过的窗口失败关闭。+- 两条拒绝在任何模式、设置与授权选项下都成立:该能力永不以 PI-Desktop 自身窗口+ 为目标——向本应用合成输入等于绕过权限中介——并且在安全输入状态或焦点落在密码+ 字段时,截取与合成一律拒绝。内置的凭据界面拒绝名单条目不可移除。+- 权限模式治理授权而非每次按键。签发始终是桌面 UI 的显式决定且无截止期限;+ `auto` 不签发任何授权,口述请求也不能。在授权内,检查类动作自动允许,输入遵循+ `confirm-each`(`ask` 下唯一策略)或需显式选择的 `autonomous-in-scope`。+ Plan 与 Goal 硬拒绝该工具,且它不存在 `allow-session` 授权。+- 语音不获得新权限:一句口述只能经由现有委派/分类器路径成为绑定会话上的工作+ 请求,由 Agent 轮次执行。语音驱动的电脑操作是任务委派,不是逐帧遥控。+- 受支持平台为 macOS(`AXUIElement`、ScreenCaptureKit)与 Windows(UIA、+ `SendInput`,提权目标被拒绝);Linux/X11 基于 AT-SPI 与 XTEST 尽力而为;+ Wayland 拒绝输入并保留门户截取。每条不支持路径都有自己的错误码,绝不挂起,+ 也绝不静默空操作。+- 非目标第 9 条是修订而非删除:浏览器接管、无人看管的全桌面控制,以及任何由+ 模型自行选择目标,仍然是非目标。+- 只定规格未落实现:`03-runtime/computer-use.md`、`08-error-codes.md` §3.10+ (`COMPUTER_*`)、`05-host-core-rust.md` §2/§5b/§6、+ `05-security/01-security.md` §13、`03-tools-and-permissions.md` §0/§2/§6,+ 以及五条 `E2E-COMPUTER-USE-*` 落地闸门,全部为 `NOT RUN`。diff --git a/docs/zh-CN/spec/NAV.md b/docs/zh-CN/spec/NAV.mdindex c16841a3b..4eb73d2ee 100644--- a/docs/zh-CN/spec/NAV.md+++ b/docs/zh-CN/spec/NAV.md@@ -48,6 +48,7 @@- [20-speech.md](/zh-CN/spec/03-runtime/20-speech)- [live-voice.md](/zh-CN/spec/03-runtime/live-voice)- [live-work-session.md](/zh-CN/spec/03-runtime/live-work-session)+- [computer-use.md](/zh-CN/spec/03-runtime/computer-use)- [21-image-generation.md](/zh-CN/spec/03-runtime/21-image-generation)- [22-config-sync.md](/zh-CN/spec/03-runtime/22-config-sync)- [svg-attachment-input.md](/zh-CN/spec/03-runtime/svg-attachment-input)