# AGENTS.md Guidance for AI coding agents working in this repository. ## What this is `deck-it` turns an Android tablet into a second monitor, a stream-deck and an always-on control surface for a Slackware Hyprland desktop. The PC serves a web page on a Unix socket and exposes it to the tablet with `adb reverse`; `wayvnc` streams a headless output to AVNC. Python 3.11+ standard library, plus `websocket-client` for obs-websocket. Plain HTML/CSS/JS frontend, bash launcher. Keep the server dependency-free apart from that one package. ## How it fits together - `deckit/server.py` is the stdlib HTTP server: it listens on `$XDG_RUNTIME_DIR/deck-it/http.sock`, serves `static/`, `/theme.css`, `/icons/.svg` and `/api/[/]`. - A module is `deckit/modules/.py` exporting `make(cfg) -> Module`; the registry discovers files lazily. `state()` is read, `actions` are allow-listed, and the client sends ids, never commands. - The page shell (`static/app.js`) builds tabs from each panel's `tab` property, mounts those panels and polls `/api/`. The Dashboard tab is `static/dashboard.js`: one fixed screen with no drag, resize or fold. A top band of chips (stats, Claude usage from `llm`, tablet battery and Wi-Fi), music and spending (`llm`) always on, a running row of chips for one to three busy modules. A panel that can be running exports `busy(state)` and `slot(state, el)` (`k1c.js`, `sbbuilder.js`, `obs.js`); a slot builds its markup once and then only sets text, so its scrolling lines are not restarted. The slot, and an optional `detail(state, el)` under it (`sbbuilder.js`: the job, the VM, the plan package by package), is drawn into a centred `` a tap on its chip opens (a tap outside closes it, a tap inside opens the tab); the chip copies the slot's `.sic`, `.pct` and `.bar`. Hyprland's border colours (`--udt-border-1..3`) colour the trend lines and progress bars. - `stats` also carries `updates`, keystone's "to install" count from `updatesctl` (`[dashboard] updates`, empty hides it), re-read in a thread every 5 min so its NFS reads never stall the 1s poll. - `actions` has no state and no actions, only a watcher: it checks `pidof hyprlock` every 2s and sends the tablet `KEYCODE_SLEEP` on lock and `KEYCODE_WAKEUP` on unlock. (Its Dashboard icons were dropped; the name stays because keystone's module toggle uses it.) - `todo` reads Vikunja (`[todo] url`, an API token in `~/.config/deck-it/vikunja-token`) every 60s: open tasks due today or overdue or whose reminder passed (`/api/v2/tasks` filter), minus any with a reminder still ahead, so a snooze hides one until it fires. Actions, for an id the last state listed: `open` (`xdg-open` on the PC, Vikunja's `frontend_url`), `done` and `snooze` (merge-patch; snooze keeps the old reminders and adds one at now+30m), each re-reading the list. The Dashboard's `.dash-todo` row exists only while there are tasks: tap opens, hold marks done, a swipe right snoozes. - `deckit/theme.py` reads UDT's palette (`~/.config/rofi/udt/palette.rasi`) and `~/.cache/udt/udt-border.lua`; the frontend uses only those CSS variables. Text size is keystone's (`~/.config/keystone/fonts.json`, `override.deckit` else `base`) as `--udt-font-size` on `html`, so `deck.css` sizes text in `rem`. The shell re-reads `/theme.css` every 5s, so changes reach an open page. - Launcher icons follow the icon theme Keystone sets (`gsettings org.gnome.desktop.interface icon-theme`); window icons resolve through the `.desktop` `Icon`/`StartupWMClass` mapping. - `deckit/display.py` creates the headless output, centres it under the first monitor for `position = "auto-below"`, and paints it with the first monitor's swaybg image. - The launcher (`deck-it`) handles USB and Wi-Fi (`pair`/`wifi`), the tunnels, wayvnc and AVNC. `adb mdns` may be unsupported; `deck-it wifi ` or `[wifi] address` gives an explicit one; otherwise the last address that worked (`~/.config/deck-it/last-wifi`, kept across `stop` and reboots). `[display] enabled = false` skips the headless output, wayvnc and AVNC. `deck-it status` prints one JSON line for keystone's page; keep its keys. - Config: `deckit/config.py` merges `~/.config/deck-it/config.toml` over the shipped `config.toml` per key within each table (a list is replaced whole). Keystone's deck-it page (quickshell repo, `desktop/modules/deckit`) writes that sparse file and reads the defaults from `deck-it defaults`; keep that JSON shape stable. - A panel whose source can be switched off (OBS, build VM, LLM, K1C) shows `static/offline.js`'s card, not raw error text; the error goes in its tooltip. - `k1c` reads a Klipper printer through Moonraker (`[k1c] url`); its one action is the emergency stop, a press-and-hold button on the tab. While the printer is off it backs off 10s between tries. The camera snapshot and the slicer thumbnail are loaded by the tablet straight from the printer. - `vm` drives libvirt's default connection (qemu:///system) through `virsh`: `domstats` each poll, `dominfo`/`snapshot-list`/agent `domifaddr` in a thread every 10s and after an action. A vm or snapshot name must be one the last state listed. `ssh` opens `ssh ` as a tab in the first `$XDG_RUNTIME_DIR/kitty-` that answers `kitty @` and focuses it, else spawns kitty. `ready` is sshd answering at `ssh -G `'s host and port (the agent IP when no alias), re-read every 2s for 5 min while a VM boots. The tile's screen is `virsh screenshot` through ffmpeg at `/api/vm/image/`, running VMs only. `vm.js`: one column, a running VM's tile as tall as the tab (no card look when it is the only one), shut-off ones short cards below. A tile has its screen, power: tap gentle, hold force; SSH; CPU/RAM trends from `dashboard.js`'s `line`/`area`; a `` sheet with every action and the snapshot timeline. Buttons are Nerd Font glyphs. - `static/hold.js` is the one press and hold (K1C stop, VM buttons): it vibrates the tablet when it fires; `buzz()` also marks the Windows long-press. - `sbbuilder` has no tab, only a running slot. It reads `sbb-remote jobs --active` (sb-builder 0.13.1+); a running build's `progress` (done of total with dependencies, the package building, its ETA, the estimated end, failures) replaces the busy bar. - `tablet` reads the tablet's battery (`dumpsys battery`) and Wi-Fi (`cmd wifi status`, Android 11+) over adb, from the device whose reverse carries the dashboard socket; reads are cached 10s. - `xbox` reads Xbox Live with the user's own Azure app (`[xbox] client_id`, a public client for personal accounts): device code sign-in started from the tab, the refresh token in `~/.config/deck-it/xbox-token.json` (0600), the MS → user token → XSTS chain in memory. A thread reads presence and the consoles (`xccs`) every 30s, profile, recent titles (titlehub, minutes from userstats), the last achievements, friends and each console's installed titles (`xccs` installedApps) every 10 min and on a title change; an endpoint that refuses keeps its last data. Installed titles join the recent ones in one games list (titlehub batch by pfn for those not recent), marked `installed`, most recently played first. The slow read also takes the uploaded screenshots and clips (mediahub `screenshots`/`gameclips` search, `OwnerXuid eq `); their CDN URIs are signed, so the tab shows and downloads them straight from Microsoft, in a `` outside the redrawn part. Its "Save to PC" is the `save` action: the PC downloads a listed capture into `xdg-user-dir` PICTURES/Xbox or VIDEOS/Xbox and answers the path; a capture whose file is there is `saved` (a check on its tile). mediahub's DELETE refuses our token (403 `errorCode` 10401, tried 2026-11-28): it seems to want the Xbox app's device and title tokens, so captures are deleted on the console. Only captures the console uploaded appear; Xbox keeps them 90 days (`expirationDate`). Xbox Live has no system software version. The profile and console cards share `.xb-hero`, whose background is the gamerpic (Xbox's own profile background is it blurred) in greyscale, blurred and multiplied over `--udt-accent` under a `--udt-base` fade, so UDT keeps every colour. Xbox Live exposes no download queue and no pending updates (probed 2026-11-18). `_http` sends `User-Agent: deck-it`: xccs's gateway answers 403 to urllib's default. A foreground title that titlehub calls a Game is `playing`: `$XDG_RUNTIME_DIR/status.xbox` gets 1 (keystone ORs it into presentation) and `xbox.js`'s `peek` returns `Infinity` once per `session`, which `app.js` reads as "show and stay". Console actions are `xccs` commands (power: tap wakes, hold turns off; media and volume), for a console id the last state listed. Endpoints and bodies follow xbox-webapi-python; Microsoft documents none of them. - `assistant` is a client of desktop-assistant's socket (`$XDG_RUNTIME_DIR/desktop-assistant.sock`, JSON lines; every client sees every event); a reader thread folds events into the state the tab polls every 0.5s. Presets, ops and paths come from quickshell's `qs -p <[assistant] shell> ipc call assistant catalog`. Files are picked on the PC with qarma, never named by the tablet. Voice is a WAV upload (`Module.uploads`, a raw body with its own size limit) written to the run dir and asked with `audio`. The tab's icons are the Nerd Font (Propo, so a glyph's advance is its ink and centring works) the server serves at `/fonts/nerd-propo.ttf`, cached a day: rename the URL when the font changes; Markdown goes through `static/md.js` (vendored `marked`, HTML escaped, images never fetched). - The page holds a Screen Wake Lock while visible, so the tablet never sleeps over the dashboard. After `[tablet] dim_after` seconds untouched, `app.js` covers the page with `#dimmer` and `tablet`'s `dim` action sets the backlight to `dim_brightness` over adb (auto brightness off meanwhile); the touch on the cover calls `undim`, which puts both back, as does the module's `stop`. The cover's time and date fonts are keystone's Fonts page: `family` `deckit-clock` and `deckit-date` in its `fonts.json`, each a family installed on the PC that the server finds with `fc-match` and serves at `/fonts/`; their px sizes are its `deckit:clock` and `deckit:date` overrides (else deck.css's 8rem and 1.6rem); theme.css carries the rules, so a change reaches an open page. The font file never enters the repo, so a personal-use font is fine. Before a suspend, poweroff or reboot `deckit/sleep.py` (an elogind delay inhibitor plus `dbus-monitor` on PrepareForSleep/PrepareForShutdown) marks answers with `X-Deckit-Sleep: asleep|shutting down` for 2s, and `app.js` covers the page with "The PC is " and drops the lock (a shutdown then runs `deck-it stop`; login starts it again), so the tablet sleeps too; 15s with no answer at all gives the same overlay as "The PC is not answering". The first plain answer takes both back. - The Windows tab's previews are `grim -T ` (Hyprland's stableId is the ext-foreign-toplevel identifier), served at `/api/windows/image/` through `Module.image`, only for a window the last state listed; the URL changes every 5s so the browser cache answers in between. The cards sit in horizontal strips: one (All), or one per workspace or app class, the choice kept in `localStorage`; a strip is not rebuilt while a finger is on it or it scrolled in the last second, and keeps its scroll. Workspace icons come from keystone's `Workspaces.qml` map (`[windows] workspace_icons`). - A panel may export `peek(state)`; when it returns seconds > 0 `app.js` shows that tab that long and then goes back, unless the page is touched or the tab changed meanwhile. `windows.js` peeks on a window id the last poll lacked, for `[windows] peek` seconds (0 off), unless it is a dialog (floating, its pid already has a window; Hyprland gives no parent). - `music` drives any MPRIS player through `playerctl` (playerctld picks the last active one). A `data:` cover, or a local video with no cover (Haruna sends none), is served at `/api/music/image/`, a video as an `ffmpeg` frame; only the current track's key answers. - `games` finds a PC game among `hyprctl clients`: class `steam_app_`, or `pcsx2`/`duckstation` with a window title other than the emulator's name. Steam's name, cover and minutes come from its appmanifest, librarycache and localconfig.vdf; an emulator's from the title, matched in its `cache/gamelist.cache` for the serial, then `covers/` and `playtime.dat`. The cover is served at `/api/games/image/`, current game only. The Dashboard's music card (`music.js` `pickGame`) shows a PC game, else the Xbox's `playing`, instead of the track. - Launchers are `[launch] apps`, desktop ids run with `gtk-launch`; label and icon come from the `.desktop` file. The client sends the id, which must be configured and installed. ## Conventions - New behaviour goes in a module under `deckit/modules/`, not in the server. - Panels keep their scoped wrapper class (`.music`, `.k1c`, `.windows`) because the CSS is scoped to it. - Hyprland Lua: a dispatcher must be wrapped in `hl.dispatch(...)` to execute. `hyprctl eval` alone only builds the dispatcher object. - No personal data in code, docs, tests or commits; use placeholders. ## Testing python3 -m unittest discover -s tests `node --check` any changed JS file. The `tests/test_*.mjs` node checks run inside the suite through `tests/test_js.py`. The real hardware paths (wayvnc, adb, OBS, the tablet) are manual. ## Repo facts - License: GPLv2 only (`LICENSE`, header in each source file). - Work directly on master.