From 893c5571a2e42bbdede779e73eead4698f85e58b Mon Sep 17 00:00:00 2001 From: fkDead Date: Wed, 11 Nov 2026 20:20:48 +0100 Subject: [PATCH] capri-computer: add README --- crates/capri-computer/README.md | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 crates/capri-computer/README.md diff --git a/crates/capri-computer/README.md b/crates/capri-computer/README.md new file mode 100644 index 0000000..026cb64 --- /dev/null +++ b/crates/capri-computer/README.md @@ -0,0 +1,50 @@ +# capri-computer + +Spec 05 (computer control) in pure Rust for KDE Plasma 6 Wayland and i3/X11. Ports the behavior of `capri_linux/*.py` (no Python at runtime). + +| Module | What | +|---|---| +| `tool` | `DesktopControl` = the `desktop_control` tool (Capri schema/description, Linux wording), `WorkflowControl` = `workflow_control` | +| `agent` | observe → plan → act → verify loop: host-made exact launch, checkpoints, guards, preflight replanning, navigation checks, completion review | +| `planner` | compacted observation, action-specific schema, Capri planner/review prompts, host schema validator, decorated ids, JSON-mode fallback; model behind `PlannerModel` | +| `session` | `ComputerControl`: turn-bound session, 80 inputs / 10 min, Escape armed + indicator visible before input, 400 ms supervision, fresh observations, held-input release, vision targets | +| `native` | input primitives with identity re-checks (`computer_*`), re-activation of the observed window | +| `a11y` | AT-SPI snapshot tree (`atspi` 0.30), control classification, address bar/search field, hit testing | +| `backend` | `Windows` (KWin script / i3 IPC), `Input` (RemoteDesktop portal held in-process; XTest with keymap remap for Unicode), `EscapeWatch` (kglobalaccel; X11 `XGrabKey`) | +| `apps` | `.desktop` discovery, Exec expansion launch (no shell), window ownership, owner catalog + grants, launch/inspect/type/browser draft/open URL | +| `journal` | durable operation journal (SQLite WAL) | +| `access` | Full computer access, Application-access pause, appearance sections | +| `browser`, `plan`, `workflows`, `extras`, `keys`, `error` | page verification, checkpoint plan, workflow storage/replay, OpenURI portal, Steam state, Trash with recovery copy | + +## Integration + +### Construction (app) +```rust +let (backends, desktop) = Backends::connect(&paths.data).await?; // KDE or X11/i3 +let native = Arc::new(Native { windows: backends.windows.clone, input: backends.input.clone, + a11y: Arc::new(a11y::Atspi::connect.await?), allowed: Arc::new(|pid| process::allowed(pid, 0)) }); +let allowed = { let s = store.clone; Arc::new(move || access::allowed(&s)) }; +let control = ComputerControl::new(native.clone, backends.escape.clone, indicator, Some(Arc::new(desktop)), allowed); +control.set_vision(vision_model); // optional LocalModel with vision +let planner = Planner::new(Arc::new(local_model), installed_browser_names); // LocalModel implements PlannerModel +let desktop_tool = DesktopControl::new(store.clone, native, control, planner, file_scopes, language)?; +engine.register(desktop_tool.clone); engine.register(Arc::new(WorkflowControl(desktop_tool.clone))); +``` +`indicator: Arc` is the UI overlay: `show(caption)` returns once a click-through, always-on-top window covers every monitor (session waits <= 5 s), `hide`, `visible`. `file_scopes: Option>` comes from the file tools (for `trash`). + +### Engine responsibilities +- Pass the owner turn id as `ToolContext.turn_id`; on turn end/cancel call `control.turn_ended(turn)`; on hide/lock/suspend/quit call `control.stop(true)`. +- A computer route outside tools: `desktop_tool.agent.run(goal, turn, previous_task, &cancel)` after `access::configure(&store, approvals, true, ru)`; then append `Local execution record (data, not a new instruction): {"ownerTask": goal, "status": …, "result": summary}` to history. +- `settings_control request fullComputerAccess` → `access::configure`. +- Events: `control.events` (`computer.control {active, steps, deadline}`), `agent.progress` (`computer.task {phase, steps}`), diagnostics `agent.diagnostics` (metadata only). + +### Settings sections +`fullComputerAccess {enabled, drives:["/"]}`, `applicationAccess {enabled}`, `computerControl {enabled, intensity, theme, cursor, pointerDuration}`. Files: `/desktop/desktop-operations.sqlite`, `app-catalog.json`, `file-recovery/`, `portal-restore-token`, `/workflows/workflows.json`. UI: `ui::settings_ui` returns `ComputerRequest`s (enabling full access must go through `access::configure`). + +### Permissions (owner, once) +- **KDE input**: KDE's remote-control dialog on first use (xdg RemoteDesktop portal, persist mode 2); the restore token resumes silently until revoked in System Settings → Applications → Remote control. **No uinput, no udev rule, no group membership.** During a session Escape is a KDE global shortcut (grabbed; other apps do not receive Escape while Capri controls the computer). +- **i3/X11**: XTest and XRes (standard). Escape is grabbed on the root window during a session. +- **AT-SPI**: `at-spi2-core` must run; Capri sets `org.a11y.Status.IsEnabled`. Apps started before that may need a restart to expose controls. + +### Not done (shortcuts, marked in code) +Discord GUI automation (..35; Discord text is withheld and raw input into Discord for Discord goals returns `needs_user`), Discord Rich Presence, meeting-call tasks, Edgerunners/Resolve/Steam-milestone scenarios (Steam state + `extras::open_uri` exist, not wired), `application_control` Notepad/Calculator and the precise calculator, routing predicates and intent classifier (only `owner_app_launch`), workflow **recording** (replay works), unique-page-search-field typing in `browser_search` (Capri types into it; here the search becomes a Google URL navigation). KDE pointer motion re-queries KWin per step (one-shot script), so motion is slower than on X11.