From cc56ea99a58ee4de3049b5c539cf3d921d0c3cfa Mon Sep 17 00:00:00 2001 From: fkDead Date: Wed, 11 Nov 2026 20:20:48 +0100 Subject: [PATCH] capri-tools: add README --- crates/capri-tools/README.md | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 crates/capri-tools/README.md diff --git a/crates/capri-tools/README.md b/crates/capri-tools/README.md new file mode 100644 index 0000000..9e2439d --- /dev/null +++ b/crates/capri-tools/README.md @@ -0,0 +1,97 @@ +# capri-tools + +Model tools other than memory, perception and computer control, ported from CapriCore 1.0.4: `filesystem_control`, `application_control`, +`time_control`, `settings_control`, `spotify_control`, plus host-side web search, action receipts, +the XDG application catalog and the matching settings pages. + +Names, descriptions and JSON schemas are Capri's, with Linux wording (Trash, text editor, Spotify +desktop app). Results keep Capri's shapes (`ok`, `error`, `cancelled`, `confirmation`...). + +## Integration + +### Build the tools (app start) + +```rust +let (events_tx, events_rx) = tokio::sync::mpsc::unbounded_channel::; +let external: capri_agent::tools::StateProvider = Arc::new(|| json!({ + "fullComputerAccess": computer.enabled, // computer-control crate + "screenObservation": screen.active, // perception crate + "glitchEnabled": ui.glitch, "glitchStrength": ui.glitch_strength, +})); +let tools = capri_tools::tools(store.clone, &paths, events_tx, external)?; +tools.time.clone.spawn; // 500 ms scheduler, inside the tokio runtime +engine_tools.extend(tools.list); // Vec> +// at exit: +tools.time.close; // checkpoints running clocks +``` + +`tools.list` holds, in order: `filesystem_control`, `application_control`, `time_control`, +`settings_control`, `spotify_control`. `spotify_control.available` is false unless Spotify is +enabled and Application access is on; the engine must re-check `available` per turn. + +### What the engine must do + +- Offer the tools only on owner desktop turns and apply the per-turn domain filter. +- Pass `ToolContext.call_id` = `sha256_hex(sessionKey + "\0" + sessionId + "\0" + modelCallId)`. Mutations are journaled by this id: a replay returns the stored result, a replay with + other arguments is refused, an interrupted one is never retried. +- Honour `Tool::timeout`: filesystem 105 s and settings 180 s, because approvals **block** the + call until the owner answers (`ctx.approvals.confirm`, 90 s card). A refused card returns + `{"ok":true,"cancelled":true}`; `needsApproval` is never returned with this blocking contract. + Approval kinds: `file.replace`, `file.trash`, `settings.notepad`, `settings.calculator`, + `settings.screenObservation`, `settings.spotify`, `settings.languages`, `settings.models`, + `settings.fullComputerAccess` (show this one as the danger modal with a 3 s delay). +- Receipts: after each tool result call + `capri_tools::factual_action_reply(tool, &args, &result) -> Option` (English key; translate). +- Internet mode (..39): before the model call, + `capri_tools::web_context(&owner_text, Some(lang)).await? -> WebContext { text, sources, status, message }`. + Append `text` to the owner message, put `capri_tools::WEB_SEARCH_INSTRUCTION` in the system + prompt, store `sources` (≤5 `{title,url}`) on the assistant message, show `message` when set. + Drop the future to cancel. `capri_tools::web::public_web_source_url` re-validates a URL before opening it. +- Dedicated music route: `capri_tools::spotify::{PLANNER_PROMPT, planner_format}` for the + Ollama `/api/chat` call, then `spotify::validate_command(&plan)` and `spotify_tool.call(plan, ctx)`. + The `spotify_control` result is already the model projection (`model_result`). +- Calculator fast path: call `application_control` with `{"action":"calculate","expression":…,"showWindow":false}`. + +### Events (`ToolEvent`) + +| Event | App action | +|---|---| +| `TimeDue(object)` | Show the due card; `notify(&reminder_notification(&o, locked).0, &….1).await`; speak `reminder_speech(&o)` unless voice is off (`wakeOnReminder` in the section). Delivered at least once (`object.deliveryId` dedupes). | +| `TimeChanged` | Refresh timers panel / stopwatch HUD. | +| `OpenPanel("screen" \| "applications" \| "languages" \| "models")` | Owner approved: open that settings page. | +| `Setting { name, value }` | Apply `glitchEnabled`, `glitchStrength` or `fullComputerAccess` (approved by the owner, or revoked). | + +### Other public API + +- `catalog -> Vec` and `launch(&AppEntry) -> Result<>`: XDG `.desktop` catalog for the + computer-control crate (Hidden/NoDisplay respected, field codes stripped, no shell, own session, + allow-listed environment). `apps::fixed_app("notepad" | "calculator", &entries)`. +- `notify(summary, body) -> Result`: `org.freedesktop.Notifications` (call from the app only). +- `files::Access` (scopes, `target` path validation, `grant`/`set_write`/`revoke`) and + `files::trash_file(path, home_trash)` for `desktop_control trash`. +- `settings_ui(ui, &Arc)`: Application access, Timers options, File access, Internet search. +- `timers_ui(ui, &TimeService)`: the Timers and reminders panel (create, list, pause/resume/snooze/dismiss). +- `TimeService::execute(call_id, args)` / `snapshot` for the UI and the elapsed-time fast path. + +### Settings and files + +- Section `tools` (`ToolsSettings`): `applicationAccess` (true), `notepad`, `calculator`, `spotify` + (false), `wakeOnReminder` (true), `folders: [{id, root, write}]` (default: installation scope + `ca9f1000-0000-4000-8000-000000000001`, stored with an empty root = the data dir, writable). +- `/desktop/time.sqlite`: Capri's exact schema (imports from Capri work as is). +- `/filesystem/operations.sqlite` + `recovery/`: file journal and replace/undo copies. +- Private (unreachable through any scope): config dir, cache dir, `/desktop`, `workspace`, + `agent`, `brain`, `workflows`, `secrets`, `filesystem`, `user-tool-definitions.json`. + +## Known limits (`shortcut:` comments) + +- Calculator uses f64 (15 significant digits), not 64-digit BigNumber; unit table is built in. +- `application_control focus/controls` are not available (need the computer-control window/AT-SPI layer); + `launch` does not verify the window. +- Spotify: volume is MPRIS `Volume` (not the PipeWire stream); play/search by name opens Spotify's + search page (`spotify:search:` via `OpenUri`) and does not start playback; `mute, seek, shuffle, + repeat, liked_songs, queue, queue_add, library` return `unsupported`; no oEmbed title check for links. +- Trash keeps no extra private recovery copy (the Trash is the recovery); no `openat2` sandboxing, + path checks are re-run before each step as in Capri. +- Folder grants are typed paths in the settings page (no portal picker yet); Spotify toggle has no modal. +- No web search rate limit (Capri had none).