Opening a web service in a browser whose window sat on another i3 workspace failed with "I could not select the intended window": the window list only covered visible workspaces, so the browser window was never found nor activated. - i3: leaves carry their workspace; hidden_leaves() lists windows on other workspaces and in the scratchpad. - KWin: the list script reports the desktop of non-current windows and activation switches to that desktop first. - Desktop::state(true) now includes those windows (minimized = true, desktop = workspace/desktop name), after the on-screen ones; state(false) is unchanged, so input and capture still only target visible windows. - App window lists given to the model tag them with otherDesktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
capri-perception
Spec 06 (perception, awareness, initiative, resources) in pure Rust, plus the Linux platform layer shared with capri-computer: KWin scripting over D-Bus, i3 IPC, window/output listing, pixel capture.
| Module | What |
|---|---|
platform |
Platform::detect (KDE Wayland vs X11/i3), Desktop (window list + activation via KWin script or i3 IPC + XRes), process identity helpers |
kwin, i3 |
KWin one-shot and persistent scripts reporting to Capri's own D-Bus object; i3 IPC codec, tree leaves |
capture |
KWin ScreenShot2 (raw pipe), Spectacle fallback, X11 GetImage; active_display, frame(source) (<= 1280x720, mosaic for all monitors) |
policy |
consent state machine: opaque source tokens, UserGesture, armed 10 s single-use grant, watch lease, revocation, no fallback |
screen |
ScreenController: snapshot previews, observation loop (2/5 s ticks, 64x36 change detection, 12 s background analysis), per-turn foreground analysis, clips |
observation, visual, identity, llm |
scene-summary request, observation text, one-shot visual turn prompt/budget/failure texts/commit pair, CAPRI_SCREEN_SELF, loopback-only JSON model calls |
clip |
is_clip_command, private screenshot files, last-screenshot receipt, shutter asset lookup + procedural shutter |
awareness |
metadata-only events: foreground app (KWin persistent script / i3 events + _NET_ACTIVE_WINDOW), lock, suspend, shutdown, idle (ScreenSaver ms / MIT-SCREEN-SAVER) |
initiative |
settings, gates in Capri's order, budget persistence, scheduler service, generation request/parse |
resources |
/proc CPU and process-tree load, hwmon temperature, meminfo, nvidia-smi, AMD sysfs, warning hysteresis |
settings, ui |
Sections and plain egui pages |
Integration
Startup
let desktop = capri_perception::platform::Desktop::connect.await?; // KDE or X11/i3
let screen = ScreenController::new(Arc::new(desktop.clone), host_flags, paths.data.clone, paths.state);
screen.set_model(LocalModel::new(&settings.ollama_base_url, &model, capabilities, options).ok); // None = vision off
host_flags: Arc<dyn Fn -> HostState> reports busy/typing/speaking/user speech/offline/hidden.
Per chat turn (engine)
- Before the model call:
let ctx = screen.prepare_turn(&user_text, &turn_cancel).await;(fresh frame + analysis while observing; never fails the turn). - Append
screen.observation_context(&user_text)to the turn context (empty when off). StateProvider: mergescreen.state_json→screenObservation,screenVisionAvailable(only when false),previousScreenshotSaved.- Clip: if
clip::is_clip_command(text, Some(&wake_finder))→screen.clip(turn_uuid, locked).await(18 s overall deadline is the caller's), sayclip::CLIPPED, playclip::shutter_sound(..)orclip::procedural_shutter(rate)with rodio. Failure texts:clip::CANCELLED/clip::FAILED. - Snapshot "Ask Capri":
screen.take_preview(id)→visual::messages(&VisualPrompt{..})→ stream withcapri_llm::Ollama::chat(num_predict = visual::output_budget(..)), then storevisual::commit_pair(..)(text only).
UI
- Buttons create
UserGesture::owner_clickedinside the click handler and callscreen.discover,capture_snapshot(token, gesture),start_observation(token, interval, duration, gesture),stop.ui::settings_uireturns these asScreenRequests. screen.status(watch) carries{capture, observation}for the REC/OBS indicator;screen.indicatorgives kind/label/watch.- Hide, lock, suspend, model sleep, quit:
screen.discard(StopReason::…). Display change:screen.topology_changed. Owner activity:screen.activity.
Awareness and initiative
let (aw, mut events) = Awareness::start(desktop.clone, vec![]).await?; // only when initiative level != off and Capri is visible
let ini = InitiativeService::new(host, store.section, saved_budget.as_ref); ini.spawn_scheduler;
while let Some(e) = events.recv.await { match e { Some(ev) => ini.observe(&ev), None => screen.topology_changed } }
InitiativeHost: flags, generate (use initiative::generation_body + generate_with(&model, …)), commit (append an assistant message labelled with Comment.label, before delivery), deliver (UI + voice), persist_budget → <state>/initiative-state.json. Call ini.activity(3000) on keystrokes/mic/send, ini.activity(45_000) after a completed turn, ini.cancel on hide/sleep/lock, ini.configure(new) on settings change, ini.tick(true) for "Try initiative", ini.dismiss/restore.
Resources
resources::memory_status(&mut cpu_sampler, Some(&mut process_load)).await every 3/5/10 s while the HUD is visible; ResourceWarnings::update(device, metric, value, sampled_at).
Settings sections
screenObservation (intervalMs, durationMs), initiative (Capri's nine keys; Linux process names added to excludedApps), resources (memoryMonitor, processGraphs, memoryStyle, memoryIntervalSeconds).
Permissions (owner, once)
- KDE window capture: KWin only serves
ScreenShot2to binaries whose installed desktop file declares it. Installcapture::kwin_desktop_entry(¤t_exe)as~/.local/share/applications/capri.desktop(Exec= the real binary path; runkbuildsycoca6if KWin still refuses). Without it, monitor captures fall back tospectacle(installed with Plasma) and window sources fail closed. - i3/X11: nothing (X11
GetImage, XRes and MIT-SCREEN-SAVER are standard Xorg extensions). Lock events need a locker that uses logind (xss-lock/loginctl lock-session). - No uinput, no udev rule, no Python.
Not done
Time service/reminders (..42, owned by capri-tools), mosaic captions use a 5x7 bitmap font, KDE awareness has no 1 s fallback poll (the KWin script pushes changes), Capri process load does not count an Ollama started by systemd.