From 3604d90fa4331d49bfc52fe1dc9e01bed9f18885 Mon Sep 17 00:00:00 2001 From: fkDead Date: Wed, 11 Nov 2026 20:20:49 +0100 Subject: [PATCH] docs: add spec 06-perception-awareness --- docs/spec/06-perception-awareness.md | 1014 ++++++++++++++++++++++++++ 1 file changed, 1014 insertions(+) create mode 100644 docs/spec/06-perception-awareness.md diff --git a/docs/spec/06-perception-awareness.md b/docs/spec/06-perception-awareness.md new file mode 100644 index 0000000..0b1f099 --- /dev/null +++ b/docs/spec/06-perception-awareness.md @@ -0,0 +1,1014 @@ +# 06 — Perception, awareness, initiative, resources and time + +Status: behavioral specification for the Rust rewrite (Arch Linux, KDE Plasma 6.8 Wayland + XWayland, i3 4.25 / X11). +Source of truth: CapriCore 1.0.4 tree at `~/Capri` (read-only). Line numbers refer to that tree. +Feature ID prefix: `PER-`. Priorities: **P0** core (companion broken or unsafe without it), **P1** expected by a Capri user, **P2** optional/niche. + +All examples in this document are synthetic. No owner data was copied. + +--- + +## 1. Purpose and scope + +This subsystem owns everything Capri *perceives* about the desktop and *time*: + +1. **Screen perception** — owner-selected window/monitor capture with a gesture-bound consent model, one-shot "snapshot + question", bounded periodic observation with change detection, all-monitor mosaics, visual (multimodal) inference requests, self-identification of Capri in images, the explicit "Capri, clip that" screenshot command and its files. +2. **Window/app awareness** — metadata-only foreground-app, fullscreen, idle/return, lock/unlock, suspend/resume and session-end events. +3. **Initiative** — when and how Capri speaks on her own (deterministic gates, budgets, tool-free generation, commit, delivery). +4. **Resources monitor** — Capri process-tree CPU/RAM/VRAM, system CPU utilisation/temperature, and the HUD polling/warning contract (GPU/RAM sampling is shared with the hardware spec). +5. **Time** — persistent timers, reminders, stopwatches (`time_control` tool), due detection with an outbox, reminder notification and spoken delivery, elapsed-time fast path, stopwatch HUD. + +### 1.1 File map + +| Capri file | Role | Rust home (recommended) | +|---|---|---| +| `apps/desktop/screen-capture-policy.mjs` (443 l.) | Source catalog, gesture-bound grant state machine, monitor sets, revocation | `capri-perception::screen::policy` | +| `apps/desktop/screen-observation.mjs` (308) | Observation scheduler, per-turn screen context, `observationText` | `capri-perception::screen::observation` | +| `apps/desktop/screen-observer-model.mjs` (103) | Background/foreground scene-summary request to Ollama | `capri-perception::vision::observer` | +| `apps/desktop/visual-service.mjs` (321) | One-shot visual dialogue (streaming) + attachments; PNG bounds | `capri-perception::vision::dialogue` | +| `apps/desktop/screen-identity.mjs` (11) | Capri self-reference prompt constants | `capri-perception::vision::identity` | +| `apps/desktop/screen-clip-frames.mjs` (52) | Request a fresh frame from the active selected-source lease | `capri-perception::screen::frames` | +| `apps/desktop/screenshot-files.mjs` (80) | Fixed screenshot folder, exclusive PNG writes | `capri-perception::screen::files` | +| `apps/desktop/main/screen-ipc.mjs` (156) | IPC surface for all screen operations | replaced by direct calls (UI ↔ `ScreenController`) | +| `apps/desktop/main/screen-form-state.mjs` (52) | Settings-window mirror of the screen form | UI shared state (no IPC) | +| `apps/desktop/renderer/screen-panel.mjs` (498), `screen-watch.mjs` (263), `screen-change.mjs` (30), `screen-mosaic.mjs` (86) | Renderer: picker, preview, tick loop, 64×36 luma sampling, mosaic | `capri-perception::screen::{watch,change,mosaic}` + `capri-ui` panel | +| `apps/desktop/renderer/screen-geometry.mjs` (12) | CRT lens inverse mapping (UI effect, unrelated to capture) | `capri-ui` | +| `apps/desktop/renderer/recording-indicator.{html,css,mjs}` + `recording-indicator-preload.cjs` | "RECORDING ACTIONS · ESC" chip for workflow recording | `capri-ui` overlay window | +| `apps/desktop/windows-observer.mjs` (151), `awareness-sync.mjs` (12), `integrations/awareness/native/WindowsEvents.cs` (57), `integrations/awareness/provision.mjs` | Awareness helper process, protocol, lifecycle | `capri-platform::{session,desktop}` + `capri-perception::awareness` | +| `apps/desktop/initiative-{settings,policy,service,generator}.mjs` | Initiative | `capri-perception::initiative` | +| `apps/desktop/process-load.mjs` (197), `apps/desktop/native/CapriProcessLoad.cs` (193) | Capri process-tree CPU/RAM/VRAM | `capri-perception::resources::process` | +| `apps/desktop/system-resources.mjs` (91) | System CPU utilisation + CPU temperature | `capri-perception::resources::cpu` | +| `packages/runtime/src/time/service.mjs` (415) | TimeService (SQLite, outbox, idempotent ops) | `capri-tools::time::service` | +| `apps/desktop/reminder-delivery.mjs` (177), `reminder-playback.mjs` (57) | Reminder visual/spoken delivery state machine | `capri-tools::time::delivery` | +| `apps/desktop/companion-actions.mjs` (213) | Main-process tool dispatcher (owns TimeService; `settings_control` screen request) | `capri-tools::dispatch` | +| `apps/desktop/main/resources.mjs` (200) | Explicit renderer asset table for `capri://` | obsolete (egui embeds assets) | +| `integrations/perception/{index,context-service}.mjs`, `openclaw.plugin.json` | Text-only visual-turn commit journal (OpenClaw plugin) | `capri-perception::vision::commit` over the Rust conversation store | +| `integrations/perception/native/capture-display.ps1` | Native foreground-monitor capture (clip, computer control) | `capri-platform::capture` | +| Related, not owned but followed: `apps/desktop/main.mjs` wiring, `clip-command.mjs`, `native-screenshot.mjs`, `time-conversation.mjs`, `visual-response.mjs`, `renderer/{time-panel,stopwatch-hud,initiative-panel,memory-hud,wake-feedback}.mjs`, `packages/runtime/src/hardware/memory.mjs`, `apps/desktop/diagnostics/resources.mjs`, `apps/desktop/chat-service.mjs` (prompt lines 48–65), `apps/desktop/turn-context.mjs`, `integrations/companion-tools/index.mjs` (tool registration) | | | +| Linux adaptation (FWS-LINUX-BRIDGE): `integrations/desktop-actions/native/linux/capri_linux/{awareness,capture,kwin,x11,common}.py`, `native-screenshot.mjs` `captureLinux`, `provision.mjs` `ensureLinuxAwareness` | Python reference for KDE/i3 | replaced by `capri-platform` | +| Docs: `docs/screen-snapshot.md`, `docs/screen-observation.md`, `docs/screen-clips.md`, `docs/initiative.md`, `docs/timers-and-actions.md`, `docs/local-fixes-2026-11-01-screen-observation.md`, `docs/bugs/0.6.4-amd-monitoring.md` | | | + +### 1.2 Out of scope (owned by other specs, referenced here) + +Conversation store/agent loop, persona/memory, avatar sprites and the avatar stream marker parser, voice/TTS engine, microphone/ASR and wake phrase matching, approval cards (`ActionApprovals`), external API proxy (`inference-api.mjs`), file attachments (they share `VisualService`), computer control (it shares the native capture backend), tray/settings window shell, i18n tables. + +### 1.3 Shared vocabulary + +- **Source**: one window, one monitor, or the virtual "All monitors" set. +- **Token** (`SourceToken`): opaque random UUID that the UI sees instead of native IDs. +- **Grant / lease / capture**: the single active `capture` object in the policy (`id`, `phase`, `mode`, `expiresAt`, …). At most one exists. +- **One-shot** vs **watch** (observation) modes. +- **Owner frame / user gesture**: in Electron, the companion main frame and `userGesture === true` on the display-media request. In Rust: a `UserGesture` value created only by a click/keypress handler of Capri's own UI. +- **Signature**: 64×36 = 2304-byte luminance sample of a frame. +- **Foreground** (screen context): the per-chat-turn fresh analysis, which has priority over background analysis. + +--- + +## 2. Feature catalog + +### 2.A Screen capture consent and sources + +#### PER-01 — Source discovery and selection catalog · P1 +Source: `screen-capture-policy.mjs:84-206, 247-260`; IPC `main/screen-ipc.mjs:66-74`; native picker `main.mjs:4714-4734`. + +- `discover()` increments `epoch`, clears the catalog, **stops any active capture** (`stop()` reason `cancelled`), enumerates `['window','screen']` with **zero-size thumbnails and no window icons**. Enumeration must never collect pixels: if any source carries a non-empty thumbnail → error `Screen source enumeration must not include image thumbnails`. +- Cancellation: if another `discover()`/`clear()` ran meanwhile (`epoch` changed) → `Screen source selection was cancelled`. +- Limits: list must be an array of ≤ 200 sources, else `Screen source list is unavailable`. Only IDs matching `^window:\d+:\d+$` or `^screen:\d+:\d+$` are kept (Rust: native window/output references, see §8). +- Label: `name` with control chars `[\x00-\x1f]` removed, truncated to 160 chars, default `Selected source`. +- Token stability: a previously issued token is reused when `nativeId` and label are identical (selection survives refresh); otherwise a new `randomUUID()`. Each entry expires **30 s** after discovery (`expiresAt = now + 30000`). +- "All monitors" virtual entry: added when the monitor layout is valid (PER-05) and the display epoch did not change during enumeration; token reused when the serialized layout (`layoutKey`) is identical. +- Returned list: `[{ id: token, label, type: 'window' | 'monitor' | 'monitors' }]` (never native IDs). +- `renewSelection(token)`: re-enumerates only the token's type; fails with `The selected source is no longer available` if the epoch changed, the token entry changed, the window/monitor vanished, or (monitor set) the layout differs; on success extends the token by 30 s. Called before every `prepare`. +- UI labels (`renderer/screen-panel.mjs:19-23`): placeholder `Choose a window or monitor…`; `Window: