diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 19:46:18 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 19:46:18 +0100 |
| commit | 6c7f59dbff8937210106bafd8a261284dcd33662 (patch) | |
| tree | b3b87e1798011c1bfc2c60a1217a7e3bf8c3bb28 | |
| parent | 4816439602c07c310bfebe121a636ba3222a5f32 (diff) | |
| download | deck-it-6c7f59dbff8937210106bafd8a261284dcd33662.tar.gz deck-it-6c7f59dbff8937210106bafd8a261284dcd33662.zip | |
docs: dashboard redesign implementation plan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | docs/superpowers/plans/2026-11-10-dashboard.md | 1263 |
1 files changed, 1263 insertions, 0 deletions
diff --git a/docs/superpowers/plans/2026-11-10-dashboard.md b/docs/superpowers/plans/2026-11-10-dashboard.md new file mode 100644 index 0000000..7dd17ad --- /dev/null +++ b/docs/superpowers/plans/2026-11-10-dashboard.md @@ -0,0 +1,1263 @@ +# Dashboard Redesign Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Replace the draggable card grid on the Dashboard tab with one fixed screen (chips, music, spending, running slots, action icons), and make the tablet sleep and wake with the PC's lock. + +**Architecture:** A new server module `actions` runs the dashboard's fixed commands and watches `hyprlock` to send the tablet `KEYCODE_SLEEP`/`KEYCODE_WAKEUP` over adb. A new frontend file `static/dashboard.js` draws the whole Dashboard tab from the existing module APIs; panels that can be "running" (`k1c.js`, `sbbuilder.js`, `obs.js`) export `busy(state)` and `slot(state, el)`. `app.js` loses Gridstack and mounts `dashboard.js`. + +**Tech Stack:** Python 3.11 stdlib (unittest), plain ES modules and CSS, node for the pure-JS checks, QML for keystone (quickshell repo). + +**Spec:** `docs/superpowers/specs/2026-11-10-dashboard-design.md` + +**Conventions (from AGENTS.md):** GPLv2 header in every new source file (copy it from an existing file, `Copyright (C) 2026 Danilo M. <danix@danix.xyz>`); no personal data in code, tests or commits; commits are GPG-signed (never disable signing) and end with `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`; work on master. Run the full suite with `python3 -m unittest discover -s tests` and `node --check` every changed JS file. A `[hidden]` attribute is overridden by any `display:` rule: every element toggled with `hidden` that also gets a `display` needs an explicit `[hidden] { display: none }`. + +--- + +## File structure + +| File | Change | Responsibility | +|------|--------|----------------| +| `deckit/config.py` | modify | `ACTION_IDS`, validate `[dashboard] actions` | +| `config.toml` | modify | `[modules] actions = true`, `[dashboard] actions` | +| `deckit/modules/actions.py` | create | action buttons' state and commands; lock watcher | +| `tests/test_actions.py` | create | actions module and watcher | +| `tests/test_config.py` | modify | dashboard actions validation | +| `static/modules/k1c.js` | modify | export `busy`, `slot` | +| `static/modules/obs.js` | modify | export `busy`, `slot` | +| `static/modules/sbbuilder.js` | rewrite | only `interval`, `busy`, `slot` (no card) | +| `static/dashboard.js` | create | the Dashboard tab | +| `tests/test_dashboard.mjs` | create | pure helpers and busy checks | +| `static/app.js` | rewrite | tabs and polling, no Gridstack | +| `static/index.html` | modify | drop Gridstack tags | +| `static/deck.css` | modify | dashboard styles; drop grid/card/llm/stats-card styles | +| `static/modules/stats.js`, `tablet.js`, `llm.js` | delete | drawn by `dashboard.js` now | +| `static/vendor/gridstack/` | delete | unused | +| `tests/test_frontend.py` | modify | new shell expectations | +| `AGENTS.md`, `README.md` | modify | describe the new dashboard | +| `~/Programming/GIT/quickshell/desktop/modules/deckit/DeckItPage.qml` | modify | "Dashboard actions" toggles | + +--- + +### Task 1: Config: the dashboard's action list + +**Files:** +- Modify: `deckit/config.py` +- Modify: `config.toml` +- Test: `tests/test_config.py` + +- [ ] **Step 1: Write the failing test** + +In `tests/test_config.py`, add to the `bad` list in `test_rejects_bad_values`: + +```python + {"dashboard": {"actions": ["screenshot", "rm -rf"]}}, + {"dashboard": {"actions": "lock"}}, +``` + +and add this test to the `Config` class: + +```python + def test_dashboard_actions(self): + self.assertIsNone(config.config_error({"dashboard": {"actions": []}})) + self.assertIsNone(config.config_error({"dashboard": {"actions": ["lock", "screenshot"]}})) + self.assertEqual(config.ACTION_IDS, ("screenshot", "lock")) +``` + +- [ ] **Step 2: Run it to see it fail** + +Run: `python3 -m unittest tests.test_config -v` +Expected: FAIL (`AttributeError: ... ACTION_IDS`, and the bad dashboard values pass validation). + +- [ ] **Step 3: Implement** + +In `deckit/config.py`, after `DESKTOP_ID = ...`: + +```python +# The dashboard's action buttons; deckit/modules/actions.py maps each to its command. +ACTION_IDS = ("screenshot", "lock") +``` + +In `config_error`, before `return None`: + +```python + acts = cfg.get("dashboard", {}).get("actions", []) + if not isinstance(acts, list) or not all(a in ACTION_IDS for a in acts): + return f"dashboard.actions must be a list of: {', '.join(ACTION_IDS)}" +``` + +In `config.toml`, add `actions = true` at the end of the `[modules]` list (after `assistant = true`), and add this table after the `[launch]` table: + +```toml +[dashboard] +# Icon buttons at the bottom of the Dashboard, in order. Each id runs a fixed +# command on the PC: screenshot opens qar-scrotmenu.sh, lock runs lock.sh. +actions = ["screenshot", "lock"] +``` + +- [ ] **Step 4: Run the tests** + +Run: `python3 -m unittest tests.test_config -v` +Expected: PASS (all, including `test_default_config_is_valid`). + +- [ ] **Step 5: Commit** + +```bash +git add deckit/config.py config.toml tests/test_config.py +git commit -m "feat(config): the dashboard's action list + +Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>" +``` + +--- + +### Task 2: The actions module and the lock watcher + +**Files:** +- Create: `deckit/modules/actions.py` +- Test: `tests/test_actions.py` + +- [ ] **Step 1: Write the failing test** + +Create `tests/test_actions.py` (GPL header first, as in the other tests): + +```python +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + +import subprocess +import unittest + +import deckit.config as config +from deckit.module import ModuleError +from deckit.modules import actions + + +class Actions(unittest.TestCase): + def test_ids_match_the_config(self): + self.assertEqual(tuple(actions.ACTIONS), config.ACTION_IDS) + + def test_state_lists_the_configured_actions_in_order(self): + m = actions.make({"dashboard": {"actions": ["lock", "screenshot"]}}) + self.assertEqual([a["id"] for a in m.state()["actions"]], ["lock", "screenshot"]) + self.assertEqual(set(m.state()["actions"][0]), {"id", "label", "icon"}) + + def test_only_configured_actions_run(self): + calls = [] + m = actions.make({"dashboard": {"actions": ["lock"]}, "popen": calls.append}) + m.actions["lock"]({}) + self.assertEqual(calls, [["lock.sh"]]) + self.assertNotIn("screenshot", m.actions) + + def test_screenshot_opens_the_menu(self): + calls = [] + m = actions.make({"dashboard": {"actions": ["screenshot"]}, "popen": calls.append}) + m.actions["screenshot"]({}) + self.assertEqual(calls, [["qar-scrotmenu.sh"]]) + + def test_missing_command_is_a_module_error(self): + def missing(cmd): + raise FileNotFoundError(cmd[0]) + m = actions.make({"dashboard": {"actions": ["lock"]}, "popen": missing}) + with self.assertRaises(ModuleError): + m.actions["lock"]({}) + + +class Follow(unittest.TestCase): + def test_sleeps_on_lock_and_wakes_on_unlock(self): + keys = [] + was = actions.follow(lambda: True, keys.append, False) + was = actions.follow(lambda: True, keys.append, was) + was = actions.follow(lambda: False, keys.append, was) + self.assertEqual(keys, ["KEYCODE_SLEEP", "KEYCODE_WAKEUP"]) + self.assertFalse(was) + + def test_nothing_while_unchanged(self): + keys = [] + actions.follow(lambda: False, keys.append, False) + self.assertEqual(keys, []) + + def test_adb_failure_is_ignored(self): + def boom(code): + raise subprocess.CalledProcessError(1, "adb") + self.assertTrue(actions.follow(lambda: True, boom, False)) + + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run it to see it fail** + +Run: `python3 -m unittest tests.test_actions -v` +Expected: FAIL (`ImportError: cannot import name 'actions'`). + +- [ ] **Step 3: Implement** + +Create `deckit/modules/actions.py` (GPL header first, `# deck-it - actions module`): + +```python +"""The Dashboard's action icons, and the tablet following the PC's lock. + +Each action id runs one fixed command; the client sends the id. A watcher +checks for hyprlock every POLL seconds and sends the tablet KEYCODE_SLEEP when +it appears and KEYCODE_WAKEUP when it goes, so every lock (the button, +SUPER+L, hypridle) takes the tablet with it. +""" + +import subprocess +import threading + +from ..module import Module, ModuleError +from .tablet import _adb, _find_tablet + +ACTIONS = { + "screenshot": {"label": "Screenshot", "icon": "", "cmd": ["qar-scrotmenu.sh"]}, + "lock": {"label": "Lock", "icon": "", "cmd": ["lock.sh"]}, +} +POLL = 2 + + +def _popen(cmd): + subprocess.Popen(cmd, start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +def _locked(): + return subprocess.run(["pidof", "hyprlock"], capture_output=True).returncode == 0 + + +def _key(code): + serial = _find_tablet() + if serial: + _adb("-s", serial, "shell", "input", "keyevent", code, timeout=5) + + +def follow(locked, key, was): + """One watcher step: a change of lock state sends the tablet to sleep or + wakes it. Returns the state seen; an adb failure waits for the next change.""" + now = locked() + if now != was: + try: + key("KEYCODE_SLEEP" if now else "KEYCODE_WAKEUP") + except (subprocess.SubprocessError, OSError): + pass + return now + + +def make(cfg: dict) -> Module: + ids = [i for i in cfg.get("dashboard", {}).get("actions", list(ACTIONS)) if i in ACTIONS] + popen = cfg.get("popen", _popen) + locked = cfg.get("locked", _locked) + key = cfg.get("key", _key) + stop = threading.Event() + + def run(cmd): + def action(body): + try: + popen(cmd) + except OSError as e: + raise ModuleError(f"{cmd[0]}: {e.strerror or e}") from e + return action + + def watch(): + was = locked() # a server started while locked does not sleep the tablet + while not stop.wait(POLL): + was = follow(locked, key, was) + + return Module( + name="actions", title="Actions", + state=lambda: {"actions": [{"id": i, "label": ACTIONS[i]["label"], "icon": ACTIONS[i]["icon"]} + for i in ids]}, + actions={i: run(ACTIONS[i]["cmd"]) for i in ids}, + start=lambda: threading.Thread(target=watch, daemon=True).start(), + stop=stop.set, + ) +``` + +Note: `FileNotFoundError` is an `OSError`, so a missing command becomes a `ModuleError`, which the server already answers as an error. + +- [ ] **Step 4: Run the tests** + +Run: `python3 -m unittest tests.test_actions -v` +Expected: PASS (8 tests). + +- [ ] **Step 5: Commit** + +```bash +git add deckit/modules/actions.py tests/test_actions.py +git commit -m "feat(actions): dashboard actions and the tablet following the lock + +Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>" +``` + +--- + +### Task 3: Running slots in the k1c, obs and sbbuilder panels + +**Files:** +- Modify: `static/modules/k1c.js` +- Modify: `static/modules/obs.js` +- Rewrite: `static/modules/sbbuilder.js` + +Each slot builds its markup once and then only sets text, so the scrolling +lines (Task 4) are not restarted every poll. Long lines are `<span +class="what"><span>…</span></span>` and `<span class="meta"><span>…</span></span>`: +the inner span is what scrolls. + +- [ ] **Step 1: k1c.js** + +Add after the `armHold` function (it reuses `dur`, `temp` and `armHold` from the same file): + +```js +// The dashboard's running slot: file, percent, time left, layer and +// temperatures, the press-and-hold stop and a progress bar. Wide slots show +// the slicer thumbnail in place of the icon (deck.css container query). +export const busy = (st) => !st.offline && (st.state === "printing" || st.state === "paused"); + +export function slot(st, el) { + if (!el.firstChild) { + el.innerHTML = `<i class="nf sic"></i><img class="sthumb" alt="" hidden> + <span class="what"><span></span></span><span class="pct num"></span> + <span class="meta"><span></span></span> + <button class="estop act" aria-label="Emergency stop: press and hold"> + <span class="estop-label">Emergency stop</span><span class="estop-hint">hold</span> + </button> + <div class="bar"><i></i></div>`; + armHold(el.querySelector(".estop")); + } + const p = st.progress ?? 0; + const name = (st.file ?? "").split("/").pop(); + el.querySelector(".what > span").textContent = st.state === "paused" ? `Paused · ${name}` : name; + el.querySelector(".pct").textContent = `${Math.round(p * 100)}%`; + el.querySelector(".meta > span").textContent = [ + `${dur(st.remaining)} left`, + st.layers ? `layer ${st.layer ?? "?"}/${st.layers}` : null, + `${temp(st.extruder)} / ${temp(st.bed)}`, + ].filter(Boolean).join(" · "); + el.querySelector(".bar i").style.width = `${p * 100}%`; + const thumb = el.querySelector(".sthumb"); + thumb.hidden = !st.thumbnail; + if (st.thumbnail && thumb.getAttribute("src") !== st.thumbnail) thumb.src = st.thumbnail; +} +``` + +- [ ] **Step 2: obs.js** + +Add after the `post` function: + +```js +// The dashboard's running slot: what is live, the scene and the elapsed +// time, and a stop for it. +export const busy = (st) => Boolean(st.connected && (st.recording || st.streaming)); + +export function slot(st, el) { + if (!el.firstChild) { + el.innerHTML = `<i class="nf sic rec"></i> + <span class="what"><span></span></span><span class="pct num"></span> + <span class="meta"><span></span></span> + <button class="act">Stop</button>`; + } + const what = st.recording ? (st.paused ? "Recording paused" : "Recording") : "Streaming"; + el.querySelector(".what > span").textContent = `${what} · ${st.currentScene ?? ""}`; + el.querySelector(".pct").textContent = st.recording ? clock(st.recordingTime) : "live"; + el.querySelector(".meta > span").textContent = + [st.recording ? "recording" : null, st.streaming ? "streaming" : null].filter(Boolean).join(" + "); + el.querySelector(".act").onclick = () => + post(st.recording ? "record" : "stream", { on: false }); +} +``` + +- [ ] **Step 3: sbbuilder.js** + +Replace the whole file (keep the GPL header, first line `// deck-it - the build VM's running slot`) with: + +```js +// The build VM has no tab: on the Dashboard it is a running slot while a job +// is active, and nothing otherwise. + +export const interval = 10; // each poll is an ssh round trip + +const ACTIVE = ["running", "busy", "starting"]; +const active = (st) => (st.jobs ?? []).filter((j) => ACTIVE.includes(j.status)); + +export const busy = (st) => !st.offline && active(st).length > 0; + +export function slot(st, el) { + if (!el.firstChild) { + el.innerHTML = `<i class="nf sic"></i> + <span class="what"><span></span></span><span class="pct num"></span> + <span class="meta"><span></span></span> + <div class="bar busy"><i></i></div>`; + } + const jobs = active(st); + const load = st.stats?.load; + el.querySelector(".what > span").textContent = `Build VM · ${jobs[0]?.kind || "job"}`; + el.querySelector(".pct").textContent = jobs.length > 1 ? `${jobs.length} jobs` : ""; + el.querySelector(".meta > span").textContent = + [jobs[0]?.status, load ? `load ${load[0].toFixed(2)}` : null].filter(Boolean).join(" · "); +} +``` + +- [ ] **Step 4: Check syntax** + +Run: `for f in static/modules/k1c.js static/modules/obs.js static/modules/sbbuilder.js; do node --check $f || echo FAIL $f; done` +Expected: no output. + +(No commit yet: `sbbuilder.js` no longer has a card, so the Dashboard is broken until Task 5. Tasks 3 to 5 are committed together.) + +--- + +### Task 4: dashboard.js and its checks + +**Files:** +- Create: `static/dashboard.js` +- Create: `tests/test_dashboard.mjs` + +- [ ] **Step 1: Write the failing node check** + +Create `tests/test_dashboard.mjs` (GPL header as `//` comments, as in `tests/test_wav.mjs`): + +```js +import assert from "node:assert/strict"; +import { area, push, spendParts, batteryGlyph, HISTORY } from "../static/dashboard.js"; +import { busy as printing } from "../static/modules/k1c.js"; +import { busy as building } from "../static/modules/sbbuilder.js"; +import { busy as live } from "../static/modules/obs.js"; + +// push keeps the last HISTORY samples +const h = []; +for (let i = 0; i < HISTORY + 5; i++) push(h, i); +assert.equal(h.length, HISTORY); +assert.equal(h[0], 5); + +// area: empty without samples; closed path from the bottom edge to the right edge +assert.equal(area([], 10), ""); +const d = area([0, 10], 10); +assert.match(d, /^M[\d.]+,100 /); +assert.match(d, / L120,100 Z$/); +assert.ok(d.includes(",12"), "the max sample sits at 12% from the top"); + +// spendParts: top 3 paid models, then "other" with the rest +const models = [5, 4, 3, 2, 1, 0].map((c, i) => ({ model: `m${i}`, cost: c })); +assert.deepEqual(spendParts(models).map((m) => [m.model, m.cost]), + [["m0", 5], ["m1", 4], ["m2", 3], ["other", 3]]); +assert.deepEqual(spendParts([{ model: "free", cost: 0 }]), []); + +// batteryGlyph: level steps, bolt while charging or full +assert.equal(batteryGlyph({ level: 3, status: "discharging" }), ""); +assert.equal(batteryGlyph({ level: 50, status: "discharging" }), ""); +assert.equal(batteryGlyph({ level: 100, status: "discharging" }), ""); +assert.equal(batteryGlyph({ level: 40, status: "charging" }), "\u{f0084}"); + +// busy checks +assert.equal(printing({ state: "printing" }), true); +assert.equal(printing({ state: "standby" }), false); +assert.equal(printing({ offline: true }), false); +assert.equal(building({ jobs: [{ status: "running" }] }), true); +assert.equal(building({ jobs: [{ status: "done" }] }), false); +assert.equal(live({ connected: true, recording: true }), true); +assert.equal(live({ connected: true, recording: false, streaming: false }), false); +``` + +- [ ] **Step 2: Run it to see it fail** + +Run: `node tests/test_dashboard.mjs` +Expected: FAIL (`Cannot find module .../static/dashboard.js`). + +- [ ] **Step 3: Create static/dashboard.js** + +GPL header first (`// deck-it - the Dashboard: one fixed screen`), then: + +```js +// The Dashboard tab: a top band of chips, music and spending always on, a +// row of one to three busy modules, and the action icons. The page keeps the +// trend history; the modules' APIs are the existing ones. + +import { offline } from "./offline.js"; + +export const HISTORY = 120; // trend samples: two minutes at 1 s +const RUNNING = ["k1c", "sbbuilder", "obs"]; // the running row's order + +const G = { cpu: "", mem: "\u{f035b}", gpu: "\u{f08ae}", net: "\u{f04e1}", + wifi: "", charging: "\u{f0084}", tux: "" }; +const BATTERY = ["", "", "", "", ""]; +// Nerd Font distro logos by os-release ID. +const DISTRO = { + slackware: "", arch: "", debian: "", fedora: "", + ubuntu: "", gentoo: "", opensuse: "", void: "", +}; +const SPEND = ["var(--udt-accent)", "var(--udt-blue, #89b4fa)", "var(--udt-green, #a6e3a1)"]; +const OTHER = "var(--udt-surface2)"; + +const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`); +const rate = (b) => (b >= 1048576 ? `${(b / 1048576).toFixed(1)}M` : `${Math.round((b ?? 0) / 1024)}k`); +const gib = (b) => (b / 2 ** 30).toFixed(1); +const money = (v) => (v == null ? "—" : `$${Number(v).toFixed(2)}`); +const tok = (n) => (n >= 1e9 ? `${(n / 1e9).toFixed(1)}B` : n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` + : n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n ?? 0)); +const pct = (v) => (v == null ? "—" : `${Math.round(v)}%`); +const short = (m) => String(m ?? "").split("/").pop(); +const uptime = (s) => { + const d = Math.floor(s / 86400), h = Math.floor((s % 86400) / 3600); + return d ? `${d}d ${h}h` : `${h}h`; +}; + +export function push(list, v, n = HISTORY) { + list.push(v); + if (list.length > n) list.shift(); + return list; +} + +// A filled area over a 120x100 viewBox, the newest sample at the right edge; +// the largest value reaches 12% from the top. +export function area(samples, max, n = HISTORY) { + if (!samples.length) return ""; + const x = (i) => ((n - samples.length + i) * 120) / (n - 1); + const y = (v) => 100 - Math.min(1, v / (max || 1)) * 88; + return `M${x(0)},100 ` + samples.map((v, i) => `L${x(i)},${y(v)}`).join(" ") + " L120,100 Z"; +} + +// The top 3 paid models (llm.py sorts them by cost), then the rest as "other". +export function spendParts(models) { + const paid = (models ?? []).filter((m) => m.cost > 0); + const rest = paid.slice(3).reduce((a, m) => a + m.cost, 0); + return rest > 0 ? [...paid.slice(0, 3), { model: "other", cost: rest }] : paid.slice(0, 3); +} + +export function batteryGlyph(b) { + if (b?.status === "charging" || b?.status === "full") return G.charging; + return BATTERY[Math.min(4, Math.max(0, Math.round((b?.level ?? 0) / 25)))]; +} + +// A line too long for its slot slides to its end and back (deck.css .marq); +// one that fits stays still. Only changed values are written, so the +// animation is not restarted by every poll. +function marquee(el) { + for (const line of el.querySelectorAll(".what, .meta")) { + const over = line.firstElementChild.offsetWidth - line.clientWidth; + line.classList.toggle("marq", over > 0); + const d = `${-Math.max(0, over)}px`; + if (line.style.getPropertyValue("--d") !== d) { + line.style.setProperty("--d", d); + line.style.setProperty("--t", `${2 + Math.max(0, over) / 30}s`); // ~30 px/s plus the pauses + } + } +} + +const SKELETON = ` + <svg class="dash-defs" width="0" height="0" aria-hidden="true"><defs> + <linearGradient id="hyline"><stop offset="0" style="stop-color:var(--udt-border-1)"/> + <stop offset=".5" style="stop-color:var(--udt-border-2)"/><stop offset="1" style="stop-color:var(--udt-border-3)"/></linearGradient> + <linearGradient id="hyfill" x1="0" y1="0" x2="0" y2="1"> + <stop offset="0" style="stop-color:var(--udt-border-2);stop-opacity:.45"/> + <stop offset="1" style="stop-color:var(--udt-border-1);stop-opacity:.05"/></linearGradient> + </defs></svg> + <section class="dash-top"> + <div class="dash-id"><i class="nf logo"></i><b class="os"></b><span class="kernel"></span> + <span class="sep">·</span><span class="up"></span></div> + <div class="chips sys"> + <div class="chip c-cpu"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/></svg> + <i class="nf ic">${G.cpu}</i><span class="col"><span class="n"></span><span class="v num"></span></span><span class="s"></span></div> + <div class="chip c-mem"><i class="fill"></i><i class="nf ic">${G.mem}</i><span class="v num"></span><span class="s"></span></div> + <div class="chip c-gpu"><i class="fill"></i> + <i class="nf ic">${G.gpu}</i><span class="col"><span class="n"></span><span class="v num"></span></span><span class="s"></span></div> + <div class="chip c-net"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/><path class="up"/></svg> + <i class="nf ic">${G.net}</i><span class="v num"></span></div> + </div> + <div class="chips aux"> + <div class="chip c-ctx"><i class="fill"></i><span class="brand claude ic"></span><span class="v num"></span><span class="k">context</span></div> + <div class="chip c-5h"><i class="fill"></i><span class="brand claude ic"></span><span class="v num"></span><span class="k">5h</span></div> + <div class="chip c-7d"><i class="fill"></i><span class="brand claude ic"></span><span class="v num"></span><span class="k">7d</span></div> + <div class="chip c-bat"><i class="fill"></i><i class="nf ic"></i><span class="v num"></span></div> + <div class="chip c-wifi"><i class="fill"></i><i class="nf ic">${G.wifi}</i><span class="v num"></span><span class="s"></span></div> + </div> + </section> + <section class="dash-mid"> + <div class="dash-always"><div class="card dash-music"></div><div class="card dash-spend"></div></div> + <div class="dash-running" hidden></div> + </section> + <section class="dash-acts"></section>`; + +export default { + // names: the enabled modules; poll(name, seconds, update) and open(tab) + // come from app.js. + mount(section, names, { poll, open }) { + const on = new Set(names); + const root = document.createElement("div"); + root.className = "dash"; + root.innerHTML = SKELETON; + section.append(root); + const $ = (s) => root.querySelector(s); + const chip = (sel, v, s, fill, warn) => { + const c = $(sel); + c.querySelector(".v").textContent = v; + if (s != null) c.querySelector(".s").textContent = s; + if (fill != null) c.querySelector(".fill").style.width = `${Math.max(0, Math.min(100, fill))}%`; + c.classList.toggle("warn", Boolean(warn)); + }; + + // A disabled module's parts are left out. + $(".dash-id").hidden = !on.has("stats"); + $(".chips.sys").hidden = !on.has("stats"); + for (const c of [".c-ctx", ".c-5h", ".c-7d"]) $(c).hidden = !on.has("llm"); + $(".dash-spend").hidden = !on.has("llm"); + $(".c-bat").hidden = $(".c-wifi").hidden = !on.has("tablet"); + $(".dash-music").hidden = !on.has("music"); + + const hist = { cpu: [], down: [], up: [] }; + if (on.has("stats")) poll("stats", 1, (st) => { + $(".logo").textContent = DISTRO[st.os?.id] ?? G.tux; + $(".os").textContent = st.os?.name ?? ""; + $(".kernel").textContent = [st.os?.codename, `Linux ${st.os?.kernel ?? ""}`].filter(Boolean).join(" · "); + $(".up").textContent = `up ${uptime(st.uptime)}`; + push(hist.cpu, st.cpu); push(hist.down, st.net.down); push(hist.up, st.net.up); + $(".c-cpu .n").textContent = st.cpuName ?? ""; + $(".c-cpu path").setAttribute("d", area(hist.cpu, Math.max(25, ...hist.cpu))); + chip(".c-cpu", `${st.cpu}%`, st.cpuTemp != null ? `${st.cpuTemp}°C` : "", null, st.cpuTemp >= 85); + chip(".c-mem", gib(st.memUsed * 1024), `/ ${Math.round(st.memTotal / 1048576)} GiB`, + (100 * st.memUsed) / st.memTotal); + const g = st.gpu; + $(".c-gpu").hidden = !g; + if (g) { + $(".c-gpu .n").textContent = g.name ?? ""; + chip(".c-gpu", g.temp != null ? `${g.temp}°C` : "—", + g.memTotal ? `${gib(g.memUsed)} / ${Math.round(g.memTotal / 2 ** 30)} GiB` : `${gib(g.memUsed)} GiB`, + g.memTotal ? (100 * g.memUsed) / g.memTotal : 0, g.temp >= 85); + } + const max = Math.max(1, ...hist.down, ...hist.up); + const [down, up] = $(".c-net").querySelectorAll("path"); + down.setAttribute("d", area(hist.down, max)); + up.setAttribute("d", area(hist.up, max)); + chip(".c-net", `↓${rate(st.net.down)} ↑${rate(st.net.up)}`); + }); + + const program = (title, p) => { + const model = `<span class="model">${esc(p.model ? short(p.model) : "—")}</span>`; + if (!(p.cost > 0)) { // local or free models: tokens, not dollars + return `<div class="prog row"><h3>${esc(title)}</h3>${model} + <span class="tok"><span class="lbl">session</span><b class="num">${tok(p.session_tokens)}</b></span> + <span class="tok"><span class="lbl">total</span><b class="num">${tok(p.tokens)}</b></span></div>`; + } + const parts = spendParts(p.models); + const total = parts.reduce((a, m) => a + m.cost, 0); + const color = (m, i) => (m.model === "other" ? OTHER : SPEND[i]); + return `<div class="prog"><header><h3>${esc(title)}</h3>${model}</header> + <div class="nums"> + <div><div class="lbl">session</div><div class="big num">${money(p.session_cost)}</div> + <div class="sub">${tok(p.session_tokens)} · ${p.session_calls ?? 0} calls</div></div> + <div><div class="lbl">total</div><div class="big num">${money(p.cost)}</div> + <div class="sub">${tok(p.tokens)} · ${p.calls ?? 0} calls</div></div> + </div> + <div class="stack">${parts.map((m, i) => + `<i style="width:${(100 * m.cost) / total}%;background:${color(m, i)}"></i>`).join("")}</div> + <div class="legend">${parts.map((m, i) => + `<span style="--c:${color(m, i)}">${esc(short(m.model))} ${money(m.cost)}</span>`).join("")}</div> + </div>`; + }; + if (on.has("llm")) poll("llm", 5, (st) => { + const spend = $(".dash-spend"); + if (st.offline) { + offline(spend, { icon: "/logos/claude.svg", title: "Usage dashboard is off", + detail: "Start llm-cost-dashboard and the spending appears here." }); + for (const c of [".c-ctx", ".c-5h", ".c-7d"]) chip(c, "—", null, 0); + return; + } + const c = st.claude ?? {}; + chip(".c-ctx", pct(c.context_pct), null, c.context_pct, c.context_pct >= 80); + chip(".c-5h", pct(c.five_hour_pct), null, c.five_hour_pct, c.five_hour_pct >= 80); + chip(".c-7d", pct(c.seven_day_pct), null, c.seven_day_pct, c.seven_day_pct >= 80); + spend._offline = null; + spend.innerHTML = program("opencode", st.opencode ?? {}) + program("Local Agent", st.assistant ?? {}); + }); + + if (on.has("tablet")) poll("tablet", 10, (t) => { + const b = t.battery ?? {}, w = t.wifi ?? {}; + const charging = b.status === "charging" || b.status === "full"; + $(".c-bat .ic").textContent = batteryGlyph(b); + chip(".c-bat", b.level != null ? `${b.level}%` : "—", null, b.level, b.level < 20 && !charging); + chip(".c-wifi", w.rssi != null ? `${w.rssi} dBm` : "—", w.band ?? "", + w.rssi == null ? 0 : 2 * (w.rssi + 100)); // -100 dBm empty, -50 full + }); + + if (on.has("music")) import("./modules/music.js").then(({ default: music }) => { + const el = $(".dash-music"); + music.mount(el); + poll("music", music.interval ?? 2, (st) => music.update(st, el)); + }); + + // The running row: slots are created now, in RUNNING order, and shown + // while their module is busy. + const row = $(".dash-running"); + for (const name of RUNNING.filter((n) => on.has(n))) { + const el = document.createElement("div"); + el.className = `card slot slot-${name}`; + el.hidden = true; + row.append(el); + import(`./modules/${name}.js`).then((mod) => { + if (!mod.busy || !mod.slot) return; + const tab = mod.default?.tab; + el.addEventListener("click", (e) => { if (tab && !e.target.closest("button")) open(tab); }); + // ponytail: the K1C and OBS tabs poll the same API; two polls a second, one cache if it matters. + poll(name, mod.interval ?? mod.default?.interval ?? 2, (st) => { + el.hidden = !mod.busy(st); + if (!el.hidden) { + mod.slot(st, el); + marquee(el); + } + row.hidden = !row.querySelector(".slot:not([hidden])"); + }); + }); + } + + if (on.has("actions")) poll("actions", 30, (st) => { + const acts = $(".dash-acts"); + const key = (st.actions ?? []).map((a) => a.id).join(","); + if (acts._key === key) return; + acts._key = key; + acts.textContent = ""; + for (const a of st.actions ?? []) { + const b = document.createElement("button"); + b.className = "nf"; + b.textContent = a.icon; + b.title = a.label; + b.setAttribute("aria-label", a.label); + b.onclick = async () => { + let ok = false; + try { + ok = (await fetch(`/api/actions/${a.id}`, { + method: "POST", headers: { "Content-Type": "application/json" }, body: "{}" })).ok; + } catch {} + if (!ok) { + b.classList.add("fail"); + setTimeout(() => b.classList.remove("fail"), 1500); + } + }; + acts.append(b); + } + }); + }, +}; +``` + +- [ ] **Step 4: Run the node check** + +Run: `node --check static/dashboard.js && node tests/test_dashboard.mjs && echo OK` +Expected: `OK`. + +--- + +### Task 5: The shell, the page and the styles + +**Files:** +- Rewrite: `static/app.js` +- Modify: `static/index.html` +- Modify: `static/deck.css` +- Delete: `static/modules/stats.js`, `static/modules/tablet.js`, `static/modules/llm.js`, `static/vendor/gridstack/` +- Modify: `tests/test_frontend.py` + +- [ ] **Step 1: Update the frontend tests first** + +In `tests/test_frontend.py`: + +Replace `test_page_references_assets` body's asset tuple with `("app.js", "deck.css")` and add, at the end of that test: + +```python + self.assertNotIn("gridstack", text) +``` + +Replace `test_vendor_assets_served` with: + +```python + def test_vendor_gridstack_is_gone(self): + self.assertEqual(self.get("/vendor/gridstack/gridstack-all.js")[0], 404) +``` + +Replace `test_panel_for_every_module` with: + +```python + def test_panels(self): + # Tabs and the music card have panels; stats, tablet, llm and actions + # are drawn by dashboard.js; k1c, sbbuilder and obs give it a slot. + for name in ("music", "k1c", "obs", "windows", "assistant"): + self.assert_panel(name) + for name in ("k1c", "sbbuilder", "obs"): + text = self.get(f"/modules/{name}.js")[1].decode() + self.assertIn("export const busy", text, name) + self.assertIn("export function slot", text, name) + self.assertEqual(self.get("/dashboard.js")[0], 200) +``` + +In `test_panels_have_their_scoped_wrapper` delete the `sbbuilder` line. + +Replace `test_layout_is_browser_local` with: + +```python + def test_dashboard_is_one_fixed_screen(self): + text = self.get("/app.js")[1].decode() + self.assertIn("dashboard.js", text) + for gone in ("GridStack", "deckit.layout", "deckit.folded"): + self.assertNotIn(gone, text) +``` + +Run: `python3 -m unittest tests.test_frontend -v` +Expected: FAIL on the new expectations. + +- [ ] **Step 2: Rewrite static/app.js** + +Replace the whole file with (keep the existing GPL header block, changing its first line to `// deck-it - the page shell: tabs and polling`): + +```js +// The shell: discover modules, sort them into tabs, mount each panel and poll +// its state. A module with a tab is static/modules/<name>.js exporting default +// {title, tab, interval, mount(el), update(state, el)}. The Dashboard tab is +// static/dashboard.js, which draws the modules without a tab. + +const tabBar = document.getElementById("tabs"); +document.getElementById("reload").onclick = () => location.reload(); +const tabBody = document.getElementById("tab-body"); +const refreshers = []; +const TAB_KEY = "deckit.tab"; +const tabs = {}; + +// Tab icons, Font Awesome glyphs in the Nerd Font the server serves; a tab +// not listed shows its name. The name also shows next to the active one. +const TAB_ICONS = { Dashboard: "", Windows: "", OBS: "", Assistant: "", K1C: "" }; + +function ensureTab(name) { + if (tabs[name]) return tabs[name]; + const button = document.createElement("button"); + button.dataset.tab = name; + button.setAttribute("aria-label", name); + button.title = name; + button.innerHTML = `<i class="nf"></i><span></span>`; + button.firstElementChild.textContent = TAB_ICONS[name] ?? ""; + button.lastElementChild.textContent = name; + if (!TAB_ICONS[name]) button.classList.add("named"); + button.onclick = () => showTab(name); + tabBar.append(button); + const section = document.createElement("section"); + section.className = "tab-panel"; + section.dataset.tab = name; + section.hidden = true; + tabBody.append(section); + tabs[name] = { button, section }; + return tabs[name]; +} + +const TAB_ORDER = ["Dashboard", "Windows", "OBS"]; + +function sortTabs() { + const rank = (name) => { + const at = TAB_ORDER.indexOf(name); + return at === -1 ? TAB_ORDER.length : at; + }; + for (const name of Object.keys(tabs).sort((a, b) => rank(a) - rank(b))) { + tabBar.append(tabs[name].button); + tabBody.append(tabs[name].section); + } +} + +function showTab(name) { + for (const [n, tab] of Object.entries(tabs)) { + tab.section.hidden = n !== name; + tab.button.classList.toggle("active", n === name); + } + try { + localStorage.setItem(TAB_KEY, name); + } catch {} +} + +const dashboard = ensureTab("Dashboard"); +dashboard.section.hidden = false; +dashboard.button.classList.add("active"); + +// Polls /api/<name> every `seconds` and hands the state to update. The first +// poll is not awaited: a slow source (the build VM over ssh, a printer that +// is off) must not hold back the others. +function poll(name, seconds, update) { + const tick = async () => { + try { + const r = await fetch(`/api/${name}`); + if (r.headers.get("X-Deckit-Sleep")) return goodnight("The PC is asleep"); + awake(); + if (r.ok) update(await r.json()); + } catch { + // keep the last state; the next tick retries + } + }; + refreshers.push(tick); + tick(); + setInterval(tick, seconds * 1000); +} + +function mountTab(name, panel, section) { + const wrap = document.createElement("div"); + wrap.className = "tab-content"; + section.append(wrap); + panel.mount?.(wrap); + poll(name, panel.interval ?? 1, (st) => panel.update?.(st, wrap)); +} + +async function boot() { + const r = await fetch("/api/modules"); + if (!r.ok) return; + // Every panel's code at once; then mount in the server's order, so the + // tabs do not shuffle with whichever import lands first. + const names = (await r.json()).map(({ name }) => name); + const loaded = await Promise.all(names.map((name) => + import(`./modules/${name}.js`).then((m) => m.default, () => null))); + names.forEach((name, i) => { + const panel = loaded[i]; + if (!panel?.tab) return; // no tab: drawn by the Dashboard, if at all + try { + mountTab(name, panel, ensureTab(panel.tab).section); + } catch { + // a broken panel must not take down the rest of the page + } + }); + try { + const { default: dash } = await import("./dashboard.js"); + dash.mount(dashboard.section, names, { poll, open: showTab }); + } catch { + // the other tabs still work + } + sortTabs(); + const saved = localStorage.getItem(TAB_KEY); + showTab(tabs[saved] ? saved : "Dashboard"); +} + +function stepTab(dir) { + const names = [...tabBar.children].map((button) => button.dataset.tab); + const at = names.findIndex((name) => !tabs[name]?.section.hidden); + const next = at + dir; + if (at !== -1 && next >= 0 && next < names.length) showTab(names[next]); +} +``` + +Then copy, unchanged, the rest of the current file from the comment `// Swipe the content sideways to change tab` to the `visibilitychange` listener's end, with one edit in the swipe's `pointerdown`: the selector becomes `"input, select, textarea"` and the comment's first lines read: + +```js +// Swipe the content sideways to change tab, from anywhere but sliders and +// text fields, whose sideways drags are theirs. +``` + +End the file with: + +```js +boot(); +``` + +(`boot()` must stay the last line: `poll` calls `goodnight`/`awake`, which use `asleep`, declared above it with `const`.) + +Check with `grep -n "boot()" static/app.js`: exactly two lines, the definition and the last line. + +- [ ] **Step 3: index.html** + +Delete these two lines from `static/index.html`: + +```html +<link rel="stylesheet" href="vendor/gridstack/gridstack.min.css"> +<script src="vendor/gridstack/gridstack-all.js"></script> +``` + +- [ ] **Step 4: Delete the replaced files** + +```bash +git rm -q static/modules/stats.js static/modules/tablet.js static/modules/llm.js +git rm -rq static/vendor/gridstack +``` + +- [ ] **Step 5: deck.css: remove the grid and card styles** + +Delete these rule blocks from `static/deck.css` (search each selector; delete the whole rule): + +- `.grid-stack-item-content.panel { … }` and `.grid-stack-item-content.panel::before { … }`, but **move** the `::before` rule's body (the masked rotating gradient) to the new `.dash-acts button::before` rule below; keep `@property --border-angle` and `@keyframes border-rotate`. +- `.panel-head`, `.panel-dot`, `.panel .panel-head h2`, `.panel-drag`, `.panel-drag:hover`, `.panel-fold`, `.panel-fold:hover`, `.grid-stack > .grid-stack-item > .grid-stack-item-content.panel.folded`, `.panel.folded .panel-body`, `.panel.folded .panel-head`, `.panel-body`, `.grid-stack-item .ui-resizable-se`, `.grid-stack-item:hover .ui-resizable-se`. +- `.llm`, `.llm-sec`, `.llm-head` and its children rules, `.brand-nf`, `.gauges`, `.gauge` and its children rules, `.lbig`, `.lpair`. +- `.tablet .bars`, `.tablet .bars .lit`, `.msys` and its children rules, `.mfoot`. +- The `.sbb …` rules. + +Keep `.stats`, `.mtile`, `.mlabel`, `.mvalue`, `.msub`, `.gbar` (the K1C tab uses them) and `.brand`, `.brand.claude`. + +Verify nothing still uses a removed class: + +```bash +for c in panel-head panel-body panel-drag panel-fold grid-stack llm-sec lpair lbig gauge msys mfoot sbb brand-nf; do + grep -rln "$c" static --include=*.js --include=*.html && echo "STILL USED: $c"; done +``` + +Expected: no `STILL USED` lines. + +- [ ] **Step 6: deck.css: add the dashboard styles** + +Append to `static/deck.css`: + +```css +/* The Dashboard: one fixed screen (static/dashboard.js). */ +.tab-panel[data-tab="Dashboard"] { height: 100%; box-sizing: border-box; padding-top: 18px; } +.dash { height: 100%; display: grid; grid-template-rows: 25% 1fr 10%; gap: 10px; } +.dash [hidden] { display: none !important; } +.dash-defs { position: absolute; } + +.dash-top { display: grid; grid-template-rows: auto 1fr 1fr; gap: 8px; min-height: 0; } +.dash-id { display: flex; align-items: center; gap: 14px; font-size: 0.857rem; color: var(--udt-subtext0); white-space: nowrap; overflow: hidden; } +.dash-id .logo { font-size: 1.15rem; color: var(--udt-accent); } +.dash-id b { color: var(--udt-text); font-weight: 600; } +.dash-id .sep { color: var(--udt-surface2); } +.dash .chips { display: grid; gap: 8px; min-height: 0; } +.dash .chips.sys { grid-template-columns: 1fr 1fr 1fr 1.3fr; } +.dash .chips.aux { grid-template-columns: 1fr 1fr 1fr 1fr 1.3fr; } +.dash .chip { position: relative; overflow: hidden; border-radius: 10px; background: var(--udt-surface0); + border: 1px solid var(--udt-surface1); display: flex; align-items: center; gap: 10px; padding: 0 14px; min-width: 0; } +.dash .chip.warn { border-color: var(--udt-accent); } +.dash .chip svg, .dash .chip .fill { position: absolute; inset: 0; pointer-events: none; } +.dash .chip svg { width: 100%; height: 100%; } +.dash .chip svg path { stroke-width: 1.5; vector-effect: non-scaling-stroke; } +.dash .chip svg path.hy { fill: url(#hyfill); stroke: url(#hyline); } +.dash .chip svg path.up { fill: color-mix(in srgb, var(--udt-text) 8%, transparent); stroke: color-mix(in srgb, var(--udt-text) 30%, transparent); } +.dash .chip .fill { right: auto; width: 0; background: color-mix(in srgb, var(--udt-accent) 20%, transparent); transition: width .4s; } +.dash .chip .ic { position: relative; flex: none; width: 1.4rem; font-size: 1.25rem; line-height: 1; color: var(--udt-overlay1); } +.dash .chip .brand.ic { width: 20px; height: 20px; } +.dash .chip .col { position: relative; display: flex; flex-direction: column; min-width: 0; } +.dash .chip .n { font-size: 0.714rem; color: var(--udt-overlay1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.dash .chip .v { position: relative; font-size: 1.35rem; font-weight: 600; white-space: nowrap; line-height: 1.1; } +.dash .chip .k { position: relative; font-size: 0.714rem; text-transform: uppercase; letter-spacing: .08em; color: var(--udt-overlay1); } +.dash .chip .s { position: relative; font-size: 0.786rem; color: var(--udt-subtext0); white-space: nowrap; margin-left: auto; } + +.dash-mid { display: flex; flex-direction: column; gap: 12px; min-height: 0; } +.dash-always { display: flex; gap: 12px; flex: 1; min-height: 0; } +.dash .card { min-height: 0; min-width: 0; overflow: hidden; padding: 14px 16px; border-radius: 14px; + background: var(--udt-mantle); border: 1px solid var(--udt-surface1); } +.dash-music { flex: 1; } +.dash-spend { flex: 1.4; display: flex; flex-direction: column; gap: 10px; } +.dash-music .music .top { margin-bottom: 6px; } +.dash-music .music .art { width: 52px; height: 52px; border-radius: 10px; } +.dash-music .music .title { font-size: 1rem; } +.dash-music .music .album { display: none; } +.dash-music .music .seek { margin: 4px 0 8px; } +.dash-music .music .controls { flex-wrap: nowrap; } +.dash-music .music .controls button { min-height: 38px; min-width: 40px; font-size: 1rem; padding: 0; } +.dash-music .music .vol { min-width: 0; } + +.dash .prog { display: flex; flex-direction: column; gap: 6px; } +.dash .prog header { display: flex; align-items: baseline; gap: 10px; } +.dash .prog h3 { margin: 0; font-size: 0.857rem; text-transform: uppercase; letter-spacing: .08em; color: var(--udt-subtext0); } +.dash .prog .model { margin-left: auto; font-size: 0.786rem; color: var(--udt-overlay0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.dash .prog .nums { display: flex; gap: 22px; align-items: baseline; } +.dash .prog .big { font-size: 1.25rem; font-weight: 600; } +.dash .prog .lbl { font-size: 0.714rem; text-transform: uppercase; letter-spacing: .08em; color: var(--udt-overlay0); } +.dash .prog .sub { font-size: 0.786rem; color: var(--udt-subtext0); } +.dash .prog.row { flex-direction: row; align-items: baseline; gap: 12px; padding-top: 10px; border-top: 1px solid var(--udt-surface1); } +.dash .prog.row .model { margin-left: 0; flex: 1; } +.dash .prog.row .tok b { font-size: 1.1rem; font-weight: 600; margin-left: 4px; } +.dash .stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--udt-surface0); } +.dash .stack i { display: block; height: 100%; } +.dash .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.75rem; color: var(--udt-subtext0); } +.dash .legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); } + +/* The running row: one to three slots in equal columns. A line too long for + its slot slides to its end and back (dashboard.js sets --d and --t). */ +.dash-running { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 12px; flex: none; height: 118px; } +.dash .slot { container: slot / inline-size; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto 1fr; + column-gap: 14px; row-gap: 4px; align-items: center; padding: 10px 16px 12px; cursor: pointer; } +.dash .slot .sic { grid-column: 1; grid-row: 1 / 3; font-size: 1.9rem; width: 2.4rem; color: var(--udt-accent); } +.dash .slot .rec { color: var(--udt-red); } +.dash .slot .what { grid-column: 2; font-weight: 600; white-space: nowrap; overflow: hidden; } +.dash .slot .pct { grid-column: 3; justify-self: end; font-size: 1.25rem; font-weight: 600; white-space: nowrap; } +.dash .slot .meta { grid-column: 2; font-size: 0.786rem; color: var(--udt-subtext0); white-space: nowrap; overflow: hidden; } +.dash .slot .what > span, .dash .slot .meta > span { display: inline-block; } +.dash .slot .marq { -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent); + mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent); } +.dash .slot .marq > span { animation: marq var(--t) ease-in-out infinite alternate; } +@keyframes marq { 0%, 15% { transform: translateX(0); } 85%, 100% { transform: translateX(var(--d)); } } +.dash .slot .act { grid-column: 3; grid-row: 2; justify-self: end; min-height: 0; height: 26px; padding: 0 10px; border-radius: 10px; + font-size: 0.786rem; background: transparent; border: 1px solid var(--udt-red); color: var(--udt-red); } +.dash .slot .estop.act { width: auto; flex-direction: row; gap: 6px; } +.dash .slot .estop.act .estop-label { font-size: 0.714rem; } +.dash .slot .bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--udt-surface0); overflow: hidden; align-self: end; } +.dash .slot .bar i { display: block; height: 100%; width: 0; + background: linear-gradient(90deg, var(--udt-border-1), var(--udt-border-2), var(--udt-border-3)); } +.dash .slot .bar.busy i { width: 30%; animation: slot-busy 1.6s ease-in-out infinite alternate; } +@keyframes slot-busy { from { margin-left: 0; } to { margin-left: 70%; } } +.dash .slot .sthumb { display: none; } +@container slot (min-width: 700px) { + .dash .slot .sthumb:not([hidden]) { display: block; grid-column: 1; grid-row: 1 / 3; width: 56px; height: 56px; object-fit: contain; } + .dash .slot:has(.sthumb:not([hidden])) .sic { display: none; } +} + +/* Action icons, each in Hyprland's rotating border. */ +.dash-acts { display: flex; justify-content: center; align-items: center; gap: 28px; min-height: 0; } +.dash-acts button { position: relative; height: 100%; max-height: 64px; aspect-ratio: 1; border-radius: 16px; font-size: 1.7rem; line-height: 1; + background: var(--udt-surface0); border: 0; color: var(--udt-text); } +.dash-acts button.fail { color: var(--udt-red); } +.dash-acts button::before { + /* paste here the body of the old .grid-stack-item-content.panel::before rule (Step 5) */ +} +``` + +Then replace the comment inside `.dash-acts button::before { … }` with the moved declarations (content, position, inset, border-radius, padding, background gradient, both masks, pointer-events, animation), unchanged. + +- [ ] **Step 7: Run all checks** + +Run: + +```bash +for f in static/app.js static/dashboard.js static/modules/*.js; do node --check $f || echo FAIL $f; done +python3 -m unittest discover -s tests 2>&1 | tail -3 +``` + +Expected: no `FAIL`; the suite ends with `OK`. + +- [ ] **Step 8: Commit (Tasks 3 to 5)** + +```bash +git add -A static tests/test_dashboard.mjs tests/test_frontend.py +git commit -m "feat(dashboard): one fixed screen for the tablet + +The Dashboard tab drops the draggable card grid for a fixed layout: a +top band of system, Claude and tablet chips with trend and fill +backgrounds, music and spending always on, a row of one to three busy +modules (printer, build VM, OBS) that scroll long lines, and the +action icons in Hyprland's rotating border. The stats, tablet and llm +panels and the vendored Gridstack go. + +Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>" +``` + +--- + +### Task 6: Keystone's Dashboard actions toggles + +**Files:** +- Modify: `~/Programming/GIT/quickshell/desktop/modules/deckit/DeckItPage.qml` (separate repo: commit there) + +- [ ] **Step 1: Add the list helpers** + +Next to `readonly property var apps: …` and `function setApps(list) …`, add: + +```qml + // The dashboard's action icons: every id deck-it knows is in the + // defaults' list; the file keeps the ones switched on, in that order. + readonly property var allActions: col.def("dashboard", "actions") ?? [] + readonly property var actions: col.st.value("dashboard", "actions") ?? col.allActions + function setAction(id, on) { + col.st.put("dashboard", "actions", + col.allActions.filter(a => a === id ? on : col.actions.includes(a))); + } +``` + +- [ ] **Step 2: Add the section** + +Before `Heading { text: "Modules" }`, add: + +```qml + Heading { objectName: "dashboard/actions"; text: "Dashboard actions" } + Small { text: "Icon buttons at the bottom of the tablet's dashboard." } + Repeater { + model: col.allActions + Item { + id: act + required property string modelData + width: col.width + height: 34 + Text { + id: actLabel + anchors { left: parent.left; verticalCenter: parent.verticalCenter } + width: 160 + text: act.modelData + color: Theme.subtext + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 } + } + Switch { + anchors { left: actLabel.right; leftMargin: 8; verticalCenter: parent.verticalCenter } + checked: col.actions.includes(act.modelData) + onToggled: on => col.setAction(act.modelData, on) + } + } + } +``` + +`Switch` and `Theme` are the same components `BoolSetting.qml` uses; if the page does not already import their directory, add the same import line `BoolSetting.qml` has (`import "../.."` relative to that file; adjust the relative path for `desktop/modules/deckit/`). + +- [ ] **Step 3: Check it** + +Restart the desktop shell (`qs -p ~/Programming/GIT/quickshell/desktop` as it is normally run, or its reload), open keystone's deck-it page and confirm: the section lists `screenshot` and `lock`, both on; switching `lock` off writes `actions = ["screenshot"]` under `[dashboard]` in `~/.config/deck-it/config.toml`; switching it back writes `["screenshot", "lock"]`. Check the shell's log for QML errors. + +- [ ] **Step 4: Commit in the quickshell repo** + +```bash +cd ~/Programming/GIT/quickshell +git add desktop/modules/deckit/DeckItPage.qml +git commit -m "feat(deckit): toggles for the dashboard's action icons + +Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>" +cd - +``` + +--- + +### Task 7: Docs + +**Files:** +- Modify: `AGENTS.md` +- Modify: `README.md` + +- [ ] **Step 1: AGENTS.md** + +Replace the bullet starting `- The page shell (\`static/app.js\`) builds tabs` with: + +```markdown +- The page shell (`static/app.js`) builds tabs from each panel's `tab` property, + mounts those panels and polls `/api/<module>`. 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 one to three busy + modules, and the action icons. 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. Hyprland's border colours (`--udt-border-1..3`) colour + the trend lines and progress bars and rotate around the action icons. +- `actions` serves the Dashboard's icons: `[dashboard] actions`, ids from + `config.ACTION_IDS`, each a fixed command (`screenshot` runs + `qar-scrotmenu.sh`, `lock` runs `lock.sh`). Its watcher checks `pidof + hyprlock` every 2s and sends the tablet `KEYCODE_SLEEP` on lock and + `KEYCODE_WAKEUP` on unlock, for every lock, not only the button. +``` + +In the Conventions section, replace `(\`.music\`, \`.sbb\`, \`.llm\`, \`.windows\`)` with `(\`.music\`, \`.k1c\`, \`.windows\`)`. + +- [ ] **Step 2: README.md** + +Run `grep -n -i "drag\|fold\|resiz\|gridstack\|card" README.md` and rewrite each matching sentence about the Dashboard to describe the fixed screen: the chips, music and spending, the running row and the action icons, and that the tablet sleeps and wakes with the PC's lock. Keep the "Development Approach" section last and unchanged. + +- [ ] **Step 3: Commit** + +```bash +git add AGENTS.md README.md +git commit -m "docs: the fixed dashboard and the actions module + +Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>" +``` + +--- + +### Task 8: Check it on the tablet + +Restart only the server (the tunnel survives): + +```bash +pid=$(pgrep -f '[p]ython3 -m deckit$'); kill $pid; (setsid python3 -m deckit >server.log 2>&1 &) +adb shell am start -a android.intent.action.VIEW -d http://127.0.0.1:8765/ +``` + +Screenshots: `adb exec-out screencap -p > <scratch>/x.png`. **Never swipe across the music card's sliders** to scroll or switch tabs: start gestures in the top band or on empty space. + +- [ ] **Step 1:** Screenshot the Dashboard: three bands fill the screen with no scrollbar; identity line, both chip rows, music, spending (opencode top 3 plus other, Local Agent one row), action icons with rotating borders. +- [ ] **Step 2:** Running row: with nothing busy it is absent. If the printer, build VM or OBS can be made busy (start an OBS recording, if OBS is running), confirm the slot appears, a long line scrolls, and a tap opens the tab; stop the recording afterwards from the slot's Stop button. +- [ ] **Step 3:** Tap the screenshot icon: the scrot menu opens on the PC; close it. +- [ ] **Step 4:** Lock: ask the user before pressing it (it locks their PC). With their go-ahead, tap the lock icon: the PC locks, the tablet's screen goes off within 2s; unlocking the PC wakes the tablet within 2s. +- [ ] **Step 5:** Other tabs (Windows, OBS, Assistant, K1C) still mount and swiping between tabs still works. + +Report what was checked and what could not be (for example, no busy module available). |
