Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(appshot): stack the corner cards and fly a saved edit back to the bottom
rubenluetke10-beepaed1e367e86d
diff --git a/docs/appshots.md b/docs/appshots.mdindex 23b0bdcf18..8fe44846da 100644--- a/docs/appshots.md+++ b/docs/appshots.md@@ -59,6 +59,14 @@ screen and rests there as a card — CleanShot X's Quick Access Overlay. Howlong is `[appshot].card_seconds` (Settings → Appshots → *Corner card*: 3, 6,10 or 30 seconds, or until you close it); the pointer on it keeps it.+Several appshots **stack**, as in CleanShot X: the newest always lands at the+bottom and the cards already there glide up to make room; when a card goes,+the ones above it glide down. Up to five cards stay (the oldest leaves first,+or earlier when the screen has no room). Every card belongs to its own+appshot, so Copy, Save, Copy text, Edit and a drag on an older card reach+that card's picture (`AppshotStore` keeps the last five, each for+`[screen_context].deck_preview_s`).+- **Hover** frosts the picture and shows **Copy** and **Save** stacked inthe middle, plus four round chips in the corners: **Pin** (top left),**Close** (top right), **Edit** (bottom left) and **Copy text** (bottom@@ -73,8 +81,10 @@ long is `[appshot].card_seconds` (Settings → Appshots → *Corner card*: 3, 6,front of you; the app behind keeps its size and what it shows. Without adesktop shell (a browser, a headless host) the editor opens over the app'spage instead. See [The editor](#the-editor).-- **Done** or **Close** in the editor window slides the picture back into- the corner — the edited one after Done — so it stays at hand.+- **Save** or **Done** in the editor flies the edited picture from the+ editor back to the bottom of the stack (the shutter's flight, without the+ flash or a sound); **Close** slides the unchanged picture in from the edge.+ Either way it stays at hand.- **Drag** the card into any app that accepts files or images (chat, mail,Explorer/Finder) to drop the picture there. As in CleanShot X, a smallerrounded copy lifts off and stays where you grabbed it, and a green "+"diff --git a/jarvis/appshot/card_actions.py b/jarvis/appshot/card_actions.pyindex 745ca599c1..df46326905 100644--- a/jarvis/appshot/card_actions.py+++ b/jarvis/appshot/card_actions.py@@ -2,7 +2,8 @@The card (a PySide6 window in the indicator sidecar) shows Copy, Save andCopy text on hover. The sidecar only reports the press; the work happens here-in the main process, on the held appshot itself:+in the main process, on the card's own appshot (every card in the corner+stack names its appshot id; the last appshot when none is named):* **Copy** goes through :mod:`jarvis.platform.clipboard_image`, which owns theclipboard natively on every OS. A Qt clipboard in the sidecar would lose the@@ -12,9 +13,10 @@ in the main process, on the held appshot itself:the clipboard — CleanShot's upload chip, swapped for what an assistant appreads off the screen anyway.-And when the editor closes, :func:`return_to_corner` slides the (edited)-appshot back into the corner, so it stays at hand — CleanShot X's Quick Access-Overlay. Every function here returns a result and never raises.+And when the editor closes, :func:`return_to_corner` brings the (edited)+appshot back to the bottom of the corner stack, so it stays at hand —+CleanShot X's Quick Access Overlay. Every function here returns a result and+never raises."""from __future__ import annotations@@ -121,14 +123,21 @@ def save_to_downloads(png: bytes, *, folder: Path | None = None, now: float | Noreturn path-async def run_card_action(action: str) -> str:- """Do ``copy``, ``save`` or ``copy_text`` on the held appshot; the card's status line."""+def _held(shot_id: str):+ """The card's appshot: by id when the card names one, else the last one."""from jarvis.appshot.store import get_store # noqa: PLC0415++ store = get_store()+ return store.get(shot_id) if shot_id else store.latest()+++async def run_card_action(action: str, shot_id: str = "") -> str:+ """Do ``copy``, ``save`` or ``copy_text`` on a card's appshot; the card's status line."""from jarvis.core.config import load_config # noqa: PLC0415config = await asyncio.to_thread(load_config)labels = card_labels(config)- shot = get_store().latest()+ shot = _held(shot_id)if shot is None:return labels["gone"]try:@@ -156,21 +165,21 @@ async def run_card_action(action: str) -> str:return labels["failed"]-async def return_to_corner(fly_from: list[float] | None = None) -> bool:- """Bring the held appshot back into the corner card. ``False`` = not shown.+async def return_to_corner(fly_from: list[float] | None = None, *, shot_id: str = "") -> bool:+ """Bring an appshot back into the corner card stack. ``False`` = not shown.+ ``shot_id`` is the appshot the editor had open (the last one when empty).``fly_from`` (``[x, y, w, h]``, global logical pixels) is where the- editor showed the picture: it then flies from there into the corner,- like after the shutter. Without it the card slides in from the edge.+ editor showed the picture: it then flies from there to the bottom of the+ stack, like after the shutter. Without it the card slides in from the edge."""try:from jarvis.appshot.effect import card_hint, thumbnail_from_image # noqa: PLC0415- from jarvis.appshot.store import get_store # noqa: PLC0415from jarvis.core.config import load_config # noqa: PLC0415from jarvis.cu.indicator.controller import get_indicator_controller # noqa: PLC0415controller = get_indicator_controller()- shot = get_store().latest()+ shot = _held(shot_id)if controller is None or shot is None:return Falseconfig = await asyncio.to_thread(load_config)@@ -186,6 +195,7 @@ async def return_to_corner(fly_from: list[float] | None = None) -> bool:rest_ms=card_rest_ms(config),labels=card_labels(config),fly_from=fly_from,+ shot_id=shot.id,))except Exception: # noqa: BLE001 - the card is a convenience, never a failurediff --git a/jarvis/appshot/effect.py b/jarvis/appshot/effect.pyindex 2f7106920d..66ecd78b2e 100644--- a/jarvis/appshot/effect.py+++ b/jarvis/appshot/effect.py@@ -100,15 +100,19 @@ async def _play(log.warning("appshot: shutter effect failed", exc_info=True)-async def attach_card_image(image: bytes) -> None:- """Give the resting card the finished picture, so a drag can share it."""+async def attach_card_image(image: bytes, shot_id: str = "") -> None:+ """Give the resting card the finished picture, so a drag can share it.++ ``shot_id`` ties the card to its appshot, so Copy, Save and Edit on an+ older card in the corner stack reach that card's own picture.+ """try:from jarvis.cu.indicator.controller import get_indicator_controller # noqa: PLC0415controller = get_indicator_controller()if controller is None:return- await controller.snap_image(base64.b64encode(image).decode("ascii"))+ await controller.snap_image(base64.b64encode(image).decode("ascii"), shot_id=shot_id)except Exception: # noqa: BLE001 - without it the card still opens the editorlog.warning("appshot: could not hand the picture to the card", exc_info=True)diff --git a/jarvis/appshot/service.py b/jarvis/appshot/service.pyindex c1f3966e73..6932fdbd8e 100644--- a/jarvis/appshot/service.py+++ b/jarvis/appshot/service.py@@ -210,7 +210,7 @@ async def _attach_to_card(shot: Appshot, config: Any) -> None:returnfrom jarvis.appshot.effect import attach_card_image # noqa: PLC0415- await attach_card_image(shot.image)+ await attach_card_image(shot.image, shot.id)async def _deliver(shot: Appshot, *, target: str, ttl_s: float) -> str:diff --git a/jarvis/appshot/store.py b/jarvis/appshot/store.pyindex 59c695e333..7fc69e0f90 100644--- a/jarvis/appshot/store.py+++ b/jarvis/appshot/store.py@@ -5,9 +5,11 @@ Two slots, with two different promises:* **pending** — the appshot waiting for the next message. Single use: thefirst turn (or the chat composer) that takes it removes it, and it expiresafter ``[screen_context].ttl_s`` like any other unconsumed capture.-* **latest** — the one picture the Appshots page may show, so the user can see- what the assistant was shown. Replaced by the next appshot and dropped after- ``[screen_context].deck_preview_s`` (``0`` = never kept).+* **recent** — the last few appshots (``MAX_RECENT``), newest first, each+ dropped after ``[screen_context].deck_preview_s`` (``0`` = never kept). The+ newest is the picture the Appshots page shows (:meth:`AppshotStore.latest`);+ the others are the older cards still stacked in the screen corner, so their+ Copy, Save and Edit reach their own picture (:meth:`AppshotStore.get`).Both hold bytes, never paths (the Screen Context retention contract)."""@@ -18,6 +20,9 @@ import threadingimport timefrom dataclasses import dataclass, replace+#: How many appshots stay at hand — as many as the corner card stack shows.+MAX_RECENT = 5+@dataclass(frozen=True, slots=True)class Appshot:@@ -57,24 +62,24 @@ class Appshot:class AppshotStore:- """Thread-safe pending + latest slots with monotonic expiry."""+ """Thread-safe pending + recent slots with monotonic expiry."""def __init__(self, *, clock=time.monotonic) -> None:self._clock = clockself._lock = threading.Lock()self._pending: Appshot | None = Noneself._pending_until = 0.0- self._latest: Appshot | None = None- self._latest_until = 0.0+ #: ``(shot, keep until)``, newest first, at most ``MAX_RECENT``.+ self._recent: list[tuple[Appshot, float]] = []def remember(self, shot: Appshot, *, keep_s: float) -> None:- """Make ``shot`` the picture the Appshots page shows."""+ """Make ``shot`` the newest picture (the one the Appshots page shows)."""with self._lock:if keep_s <= 0:- self._latest = None+ self._recent.clear()return- self._latest = shot- self._latest_until = self._clock() + keep_s+ kept = [(s, until) for s, until in self._recent if s.id != shot.id]+ self._recent = [(shot, self._clock() + keep_s), *kept][:MAX_RECENT]def park(self, shot: Appshot, *, ttl_s: float) -> None:"""Hold ``shot`` for the next message, replacing an older one."""@@ -97,27 +102,34 @@ class AppshotStore:def latest(self) -> Appshot | None:with self._lock:- if self._latest is not None and self._clock() >= self._latest_until:- self._latest = None- return self._latest+ recent = self._live_recent()+ return recent[0][0] if recent else None++ def get(self, shot_id: str) -> Appshot | None:+ """A still-kept appshot by id — an older card's own picture."""+ with self._lock:+ for shot, _until in self._live_recent():+ if shot.id == shot_id:+ return shot+ return Nonedef replace_image(self, shot_id: str, image: bytes, mime: str, width: int, height: int) -> Appshot | None:"""Swap in the user's edited picture for appshot ``shot_id``.- Updates the last appshot and, when it is still waiting for the next+ Updates that kept appshot and, when it is still waiting for the nextmessage, the pending one too — so that message carries the edit.``None`` when that appshot is no longer held."""with self._lock:- latest = self._latest- if latest is not None and self._clock() >= self._latest_until:- latest = self._latest = None- if latest is None or latest.id != shot_id:+ recent = self._live_recent()+ index = next((i for i, (s, _) in enumerate(recent) if s.id == shot_id), None)+ if index is None:return None- edited = replace(latest, image=image, mime=mime, width=width, height=height)- self._latest = edited+ shot, until = recent[index]+ edited = replace(shot, image=image, mime=mime, width=width, height=height)+ recent[index] = (edited, until)pending = self._live_pending()if pending is not None and pending.id == shot_id:self._pending = replace(pending, image=image, mime=mime, width=width, height=height)@@ -125,13 +137,19 @@ class AppshotStore:def mark_delivered(self, shot_id: str, delivered_to: str) -> None:with self._lock:- if self._latest is not None and self._latest.id == shot_id:- self._latest = replace(self._latest, delivered_to=delivered_to)+ for index, (shot, until) in enumerate(self._recent):+ if shot.id == shot_id:+ self._recent[index] = (replace(shot, delivered_to=delivered_to), until)def clear(self) -> None:with self._lock:self._pending = None- self._latest = None+ self._recent.clear()++ def _live_recent(self) -> list[tuple[Appshot, float]]:+ now = self._clock()+ self._recent = [(s, until) for s, until in self._recent if now < until]+ return self._recentdef _live_pending(self) -> Appshot | None:if self._pending is not None and self._clock() >= self._pending_until:@@ -146,4 +164,4 @@ def get_store() -> AppshotStore:return _STORE-__all__ = ["Appshot", "AppshotStore", "get_store"]+__all__ = ["MAX_RECENT", "Appshot", "AppshotStore", "get_store"]diff --git a/jarvis/cu/indicator/controller.py b/jarvis/cu/indicator/controller.pyindex 199d98d93a..8a6e480247 100644--- a/jarvis/cu/indicator/controller.py+++ b/jarvis/cu/indicator/controller.py@@ -117,12 +117,14 @@ class CUIndicatorController:# Monotonic deadline until which an appshot effect owns the sidecar.self._snap_until = 0.0self._idle_quit_task: asyncio.Task | None = None- # The appshot card in the corner is up (hover / click / drag).+ # At least one appshot card in the corner stack is up.self._card_open = Falseself._loop: asyncio.AbstractEventLoop | None = None# The finished picture for the current card. It can be ready before the# effect reached the sidecar, so ``snap`` re-sends it after the card.self._card_image_b64: str | None = None+ #: The appshot that picture belongs to — the card's id in the stack.+ self._card_image_id = ""#: The monitor the last shutter played on — where a card comes back.self._card_monitor: list[int] | None = None@@ -275,6 +277,7 @@ class CUIndicatorController:"""self._snap_until = max(self._snap_until, time.monotonic() + _SNAP_LIFETIME_S)self._card_image_b64 = None # a new capture: the old picture is not its picture+ self._card_image_id = ""async def snap(self,@@ -319,7 +322,11 @@ class CUIndicatorController:image = self._card_image_b64if shown and image:await asyncio.to_thread(- self._send_and_wait, protocol.CMD_SNAP_IMAGE, _SHOW_ACK_TIMEOUT_S, image=image+ self._send_and_wait,+ protocol.CMD_SNAP_IMAGE,+ _SHOW_ACK_TIMEOUT_S,+ image=image,+ id=self._card_image_id,)self._schedule_idle_quit()return shown@@ -333,11 +340,14 @@ class CUIndicatorController:rest_ms: int = 6000,labels: dict[str, str] | None = None,fly_from: list[float] | None = None,+ shot_id: str = "",) -> bool:- """Put a picture straight back into the corner card — no flash, no flight.+ """Put a picture back at the bottom of the corner card stack — no flash.- Used when the editor closes: the (edited) appshot slides back into the- corner of the screen its shutter played on, so it stays at hand.+ Used when the editor closes: the (edited) appshot comes back into the+ corner of the screen its shutter played on, so it stays at hand. With+ ``fly_from`` it flies there from the editor, otherwise it slides in.+ ``shot_id`` names the card, replacing a card of the same appshot."""ok, reason = self._border_capability()if not ok:@@ -347,6 +357,7 @@ class CUIndicatorController:async with self._lock:self.hold_for_snap()self._card_image_b64 = image_b64 or None+ self._card_image_id = shot_idawait asyncio.to_thread(self._spawn_sidecar)if self._proc is None:return False@@ -360,6 +371,7 @@ class CUIndicatorController:hint=hint,rest_ms=int(rest_ms),labels=dict(labels or {}),+ id=shot_id,**({"from": list(fly_from)} if fly_from else {}),)if shown and image_b64:@@ -368,22 +380,29 @@ class CUIndicatorController:protocol.CMD_SNAP_IMAGE,_SHOW_ACK_TIMEOUT_S,image=image_b64,+ id=shot_id,)self._schedule_idle_quit()return shown- async def snap_image(self, image_b64: str) -> bool:- """Hand the finished picture to the resting card, for a drag out.+ async def snap_image(self, image_b64: str, shot_id: str = "") -> bool:+ """Hand the finished picture to the newest card, for a drag out.- Kept for the effect still on its way (``snap`` sends it after the card);- sent at once when the sidecar already runs. The picture never starts a- process of its own.+ ``shot_id`` becomes that card's id, so its buttons reach its own+ appshot once newer cards stack below it. Kept for the effect still on+ its way (``snap`` sends it after the card); sent at once when the+ sidecar already runs. The picture never starts a process of its own."""self._card_image_b64 = image_b64+ self._card_image_id = shot_idif self._proc is None or self._proc.poll() is not None:return Falsereturn await asyncio.to_thread(- self._send_and_wait, protocol.CMD_SNAP_IMAGE, _SHOW_ACK_TIMEOUT_S, image=image_b64+ self._send_and_wait,+ protocol.CMD_SNAP_IMAGE,+ _SHOW_ACK_TIMEOUT_S,+ image=image_b64,+ id=shot_id,)def _on_sidecar_event(self, payload: dict[str, Any]) -> None:@@ -402,26 +421,33 @@ class CUIndicatorController:self._schedule_idle_quit()elif event == protocol.EVENT_SNAP_OPEN:# _open_editor logs its own failures; nothing awaits this task.- asyncio.get_running_loop().create_task(self._open_editor(), name="appshot-card-open")+ asyncio.get_running_loop().create_task(+ self._open_editor(str(payload.get("id", ""))), name="appshot-card-open"+ )elif event == protocol.EVENT_CARD_ACTION:action = str(payload.get("action", ""))if action in protocol.CARD_ACTIONS:asyncio.get_running_loop().create_task(- self._card_action(action), name="appshot-card-action"+ self._card_action(action, str(payload.get("id", ""))),+ name="appshot-card-action",)- async def _card_action(self, action: str) -> None:- """Copy, save or copy text from the card, then tell the card how it went."""+ async def _card_action(self, action: str, shot_id: str = "") -> None:+ """Copy, save or copy text from a card, then tell that card how it went."""from jarvis.appshot.card_actions import run_card_action # noqa: PLC0415- status = await run_card_action(action)+ status = await run_card_action(action, shot_id)if self._proc is None or self._proc.poll() is not None:returnawait asyncio.to_thread(- self._send_and_wait, protocol.CMD_CARD_STATUS, _SHOW_ACK_TIMEOUT_S, text=status+ self._send_and_wait,+ protocol.CMD_CARD_STATUS,+ _SHOW_ACK_TIMEOUT_S,+ text=status,+ id=shot_id,)- async def _open_editor(self) -> None:+ async def _open_editor(self, shot_id: str = "") -> None:"""The card was clicked: open the appshot editor in front of the user.In its own window where the desktop shell can open one, so the app@@ -436,7 +462,9 @@ class CUIndicatorController:ShowWindowRequested,)- shot = get_store().latest()+ store = get_store()+ # The clicked card's own appshot; the last one for a card without an id.+ shot = store.get(shot_id) if shot_id else store.latest()if shot is not None and await open_editor_window(shot.id):returnawait self._bus.publish(diff --git a/jarvis/cu/indicator/protocol.py b/jarvis/cu/indicator/protocol.pyindex 0f67c2287b..18ea0b61ec 100644--- a/jarvis/cu/indicator/protocol.py+++ b/jarvis/cu/indicator/protocol.py@@ -12,8 +12,17 @@ One JSON object per line on the sidecar's stdin::"rect": [fx, fy, fw, fh], # flash the captured rect and"thumb": "<base64 jpeg>", # fly its thumbnail to a corner,"hint": "Click to edit · Drag to share"} # where it rests as a card- {"cmd": "snap_image", "image": "<b64>"} # the finished (redacted) picture- # a drag from the card hands out+ {"cmd": "snap_image", "image": "<b64>", # the finished (redacted) picture+ "id": "<appshot id>"} # a drag from the card hands out;+ # the newest card without an id+ # (or the card with it) takes it+ {"cmd": "card", "thumb": "<b64>", # the editor closed: the picture+ "id": "<appshot id>", "from": [x,y,w,h]} # comes back (flies from "from")+ {"cmd": "card_status", "text": "Copied", # a short line on that card+ "id": "<appshot id>"}++Cards stack in the corner: a new one lands at the bottom and the older ones+move up; at most ``MAX_CARDS`` stay, the oldest leaves first.The sidecar answers each command with one JSON line on stdout::@@ -21,8 +30,10 @@ The sidecar answers each command with one JSON line on stdout::and reports what the user does with the resting card::- {"event": "card", "open": true|false} # keep the sidecar alive meanwhile- {"event": "snap_open"} # the card was clicked: edit it+ {"event": "card", "open": true|false} # any card up? keep the sidecar alive+ {"event": "snap_open", "id": "<appshot>"} # a card was clicked: edit it+ {"event": "card_action", "action": "copy", # a card's hover button+ "id": "<appshot>"}and exits on stdin EOF (parent death) even without a ``quit``. Everythingis best-effort: the controller treats a missing/late ack as "sidecar gone"@@ -66,6 +77,9 @@ EVENT_SNAP_OPEN = "snap_open"EVENT_CARD_ACTION = "card_action"#: What the main process does for the card; pin and close stay in the sidecar.CARD_ACTIONS = frozenset({"copy", "save", "copy_text"})+#: How many cards the corner stack holds — as many appshots as the store keeps+#: (``jarvis.appshot.store.MAX_RECENT``), so every card's buttons still work.+MAX_CARDS = 5ALL_EVENTS = frozenset({EVENT_CARD, EVENT_SNAP_OPEN, EVENT_CARD_ACTION})#: Sidecar exit code when no usable GUI stack exists (PySide6 missing or@@ -141,6 +155,7 @@ __all__ = ["EVENT_SNAP_OPEN","CMD_UNBLANK","EXIT_NO_GUI",+ "MAX_CARDS","decode_ack","decode_command","encode_ack",diff --git a/jarvis/cu/indicator/renderer.py b/jarvis/cu/indicator/renderer.pyindex db17eddcdb..75f7ddfac1 100644--- a/jarvis/cu/indicator/renderer.py+++ b/jarvis/cu/indicator/renderer.py@@ -205,6 +205,10 @@ class _GlowWindow(QWidget):# card (``_CardWindow``): hovering keeps it, a click asks the app to open the# editor, a drag hands the finished picture to any app that takes a file, a# right-click dismisses it. The flight canvas itself stays click-through.+#+# Cards stack like CleanShot X's: the newest always lands at the bottom and+# the older ones glide up to make room; when one goes, the ones above it+# glide down. At most ``protocol.MAX_CARDS`` stay, the oldest leaves first.# ---------------------------------------------------------------------------_SNAP_FLASH_MS = 200@@ -228,6 +232,9 @@ _CARD_STATUS_MS = 1600_CARD_BUTTON_H = 30.0_CARD_ROUND = 28.0_CARD_INSET = 8.0+#: The corner stack: the gap between two cards and how long a card glides.+_CARD_STACK_GAP = 12.0+_CARD_MOVE_MS = 220#: Drag files older than this are removed the next time one is written._DRAG_FILE_MAX_AGE_S = 3600@@ -292,6 +299,14 @@ def _match_screen(monitor: list[float]):return best+def _screen_named(name: str):+ """The screen a card sits on, by name; primary when it went away."""+ for screen in QGuiApplication.screens():+ if screen.name() == name:+ return screen+ return QGuiApplication.primaryScreen()++def _paint_card(painter: QPainter, rect: QRectF, thumb: QImage, radius: float, ring: float) -> None:"""The thumbnail with rounded corners and a white ring — flight and card."""clip = QPainterPath()@@ -343,6 +358,10 @@ class _SnapWindow(QWidget):self._thumb = thumbself._on_landed = on_landedself._on_done = on_done+ #: Which appshot is flying and its finished picture (``snap_image``),+ #: handed to the card it becomes.+ self.appshot_id = ""+ self.image: QImage | None = None# No flash when the picture is not a fresh capture (back from the# editor): only the flight into the corner.self._flash = flash@@ -383,6 +402,20 @@ class _SnapWindow(QWidget):self._anim.stop()self._finish()+ def land_now(self) -> None:+ """Skip the rest of the flight: the card appears in the corner at once."""+ self._anim.stop()+ self._landed()++ @property+ def landing_height(self) -> float:+ """How tall the card it becomes is — the slot the stack keeps free."""+ return float(self._dst.height())++ @property+ def screen_name(self) -> str:+ return self.screen().name() if self.screen() is not None else ""+def _on_tick(self, value) -> None:self._t = float(value)self.update()@@ -391,7 +424,7 @@ class _SnapWindow(QWidget):landed, self._on_landed = self._on_landed, Noneif landed is not None and not self._thumb.isNull():top_left = self._screen_geo.topLeft()- landed(self._dst.translated(top_left.x(), top_left.y()), self._thumb)+ landed(self._dst.translated(top_left.x(), top_left.y()), self._thumb, self)self._finish()def _finish(self) -> None:@@ -557,6 +590,30 @@ def _card_rect(screen, thumb: QImage) -> QRectF:return QRectF(right - tw - _SNAP_MARGIN, bottom - th - _SNAP_MARGIN, tw, th)+def _stack_tops(+ bottom: float, top_limit: float, heights: list[float], *, gap: float, reserve: float = 0.0+) -> list[float | None]:+ """The top edge of every card in a corner stack; ``None`` = no room left.++ ``heights`` are newest first: the newest card sits on ``bottom`` and each+ older one ``gap`` above the card below it. ``reserve`` keeps that much+ space free at the bottom for a picture still flying in. Once one card no+ longer fits under ``top_limit``, no older card does either.+ """+ tops: list[float | None] = []+ cursor = bottom - reserve+ full = False+ for height in heights:+ top = cursor - height+ if full or top < top_limit:+ full = True+ tops.append(None)+ continue+ tops.append(top)+ cursor = top - gap+ return tops++#: Default card wording; the main process sends the user's language._CARD_LABELS = {"edit": "Edit",@@ -578,6 +635,10 @@ class _CardWindow(QWidget):the on-screen text the appshot read). A click anywhere else edits, a dragshares the picture, a right-click dismisses it. ``rest_ms`` is how long itstays untouched — ``0`` keeps it until the user closes it.++ Each card belongs to one appshot (``appshot_id``) and holds its own+ finished picture (``image``), so in a stack every card copies, saves,+ drags and edits its own appshot. :meth:`move_to` glides it to its place."""_PAD = 12 # transparent margin that holds the soft shadow@@ -591,6 +652,9 @@ class _CardWindow(QWidget):*,rest_ms: int = _CARD_REST_MS,labels: dict[str, str] | None = None,+ appshot_id: str = "",+ image: QImage | None = None,+ screen_name: str = "",) -> None:super().__init__(None)self.setWindowFlags(@@ -600,6 +664,13 @@ class _CardWindow(QWidget):| Qt.WindowType.Tool| Qt.WindowType.NoDropShadowWindowHint)+ self.appshot_id = appshot_id+ #: The finished (redacted) picture a drag and Copy text need; ``None``+ #: until ``snap_image`` arrived, and for good when none may be kept.+ self.image = image+ self.screen_name = screen_name+ #: The picture's size; the window is larger by ``_PAD`` on every side.+ self.card_size = (float(rect.width()), float(rect.height()))self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating)if sys.platform == "darwin":@@ -640,12 +711,25 @@ class _CardWindow(QWidget):self._in.setEndValue(0.0)self._in.setDuration(_CARD_OUT_MS)self._in.valueChanged.connect(self._on_out)+ # Position = place in the stack (``_origin``) + the sideways slide of+ # coming in / going out (``_slide``), so both can run at once.self._origin = self.pos()+ self._slide = 0.0+ self._target = self.pos()+ self._move_from = self.pos()+ self._move = QVariantAnimation(self)+ self._move.setStartValue(0.0)+ self._move.setEndValue(1.0)+ self._move.setDuration(_CARD_MOVE_MS)+ self._move.valueChanged.connect(self._on_move)++ @property+ def leaving(self) -> bool:+ return self._leavingdef start(self, *, slide_in: bool = False) -> None:if slide_in:# Back from the editor: slide in from the edge it leaves through.- self._origin = self.pos()self._on_out(1.0)self.show()self._in.start()@@ -653,6 +737,25 @@ class _CardWindow(QWidget):self.show()self._arm_dismiss(self._rest_ms)+ def move_to(self, top_left: QPoint) -> None:+ """Glide to a new place in the stack (``top_left`` of the window)."""+ if top_left == self._target:+ return+ self._target = QPoint(top_left)+ self._move.stop()+ if not self.isVisible():+ self._origin = QPoint(top_left)+ self._apply_position()+ return+ self._move_from = QPoint(self._origin)+ self._move.start()++ def _on_move(self, value) -> None:+ t = _ease_out_cubic(float(value))+ a, b = self._move_from, self._target+ self._origin = QPoint(round(_lerp(a.x(), b.x(), t)), round(_lerp(a.y(), b.y(), t)))+ self._apply_position()+def _arm_dismiss(self, ms: int) -> None:if self._rest_ms > 0 and not self._leaving and not self._pinned:self._dismiss.start(ms)@@ -665,7 +768,6 @@ class _CardWindow(QWidget):self._leaving = Trueself._dismiss.stop()self._in.stop()- self._origin = self.pos()self._out.start()def finish_now(self) -> None:@@ -673,12 +775,16 @@ class _CardWindow(QWidget):self._dismiss.stop()self._in.stop()self._out.stop()+ self._move.stop()self._gone()def _on_out(self, value) -> None:- t = _ease_out_cubic(float(value))- self.move(self._origin + QPoint(int(48 * t), 0))- self.setWindowOpacity(1.0 - t)+ self._slide = _ease_out_cubic(float(value))+ self._apply_position()++ def _apply_position(self) -> None:+ self.move(self._origin + QPoint(int(48 * self._slide), 0))+ self.setWindowOpacity(1.0 - self._slide)def _gone(self) -> None:self.hide()@@ -757,14 +863,14 @@ class _CardWindow(QWidget):self._dismiss.stop() # the pointer is on the card; leaving re-arms itself.update()elif pressed in ("copy", "save", "copy_text"):- if self._owner.card_image is not None:- self._owner.card_action(pressed)+ if self.image is not None:+ self._owner.card_action(self, pressed)else: # "edit" or the picture itselfself._owner.card_clicked(self)def _start_drag(self, grab: QPointF) -> None:owner = self._owner- image = owner.card_image if owner is not None else None+ image = self.imageif owner is None or image is None or image.isNull():# Only the finished, privacy-filtered picture may leave this# process; the thumbnail is cut from the raw frame.@@ -814,7 +920,7 @@ class _CardWindow(QWidget):"close": QRectF(right, top, d, d),"edit": QRectF(left, bottom, d, d),}- if self._owner is not None and self._owner.card_image is not None:+ if self._owner is not None and self.image is not None:# Only with a kept, finished appshot — the same rule as the drag.buttons["copy_text"] = QRectF(right, bottom, d, d)metrics = QFontMetricsF(_pill_font())@@ -1082,12 +1188,11 @@ class Renderer(QObject):self._app = appself._windows: list[_GlowWindow] = []self._snaps: list[_SnapWindow] = []- self._card: _CardWindow | None = None+ #: The corner stack, oldest first; the newest sits at the bottom.+ self._cards: list[_CardWindow] = []self._card_hint = ""self._card_rest_ms = _CARD_REST_MSself._card_labels: dict[str, str] = {}- #: The finished (redacted) picture a drag from the card hands out.- self.card_image: QImage | None = Noneself._hint = ""self._active = False # "show" was requested and not yet "hide"self._blanked = False # capture guard currently hiding the border@@ -1152,8 +1257,9 @@ class Renderer(QObject):elif cmd == protocol.CMD_CARD:self._card_cmd(payload)elif cmd == protocol.CMD_CARD_STATUS:- if self._card is not None:- self._card.show_status(str(payload.get("text", "")))+ card = self._card_for(str(payload.get("id", "") or ""))+ if card is not None:+ card.show_status(str(payload.get("text", "")))elif cmd == protocol.CMD_QUIT:_ack(cmd)self._app.quit()@@ -1198,16 +1304,15 @@ class Renderer(QObject):screen = _match_screen(monitor if isinstance(monitor, list) else [])if screen is None:return- # One effect at a time: a second appshot replaces the resting card.+ # A flight still under way lands at once and joins the stack; the+ # cards already there glide up to keep the bottom slot for this one.for old in list(self._snaps):- old.finish_now()- if self._card is not None:- self._card.finish_now()- self.card_image = None+ old.land_now()self._card_hint = str(payload.get("hint", "") or "")self._take_card_options(payload)win = _SnapWindow(screen, rect, thumb, self._snap_landed, self._snap_done)self._snaps.append(win)+ self._relayout()win.start()def _snap_done(self, win) -> None:@@ -1224,7 +1329,16 @@ class Renderer(QObject):{str(k): str(v) for k, v in labels.items()} if isinstance(labels, dict) else {})- def _new_card(self, rect: QRectF, thumb: QImage) -> _CardWindow:+ def _new_card(+ self,+ rect: QRectF,+ thumb: QImage,+ *,+ screen_name: str,+ appshot_id: str = "",+ image: QImage | None = None,+ ) -> _CardWindow:+ """A new card at the bottom of the stack; the older ones move up."""card = _CardWindow(rect,thumb,@@ -1232,13 +1346,72 @@ class Renderer(QObject):self,rest_ms=self._card_rest_ms,labels=self._card_labels,+ appshot_id=appshot_id,+ image=image,+ screen_name=screen_name,)- self._card = card+ self._cards.append(card)_emit(protocol.EVENT_CARD, open=True)+ self._relayout()return card- def _snap_landed(self, rect: QRectF, thumb: QImage) -> None:- self._new_card(rect, thumb).start()+ def _snap_landed(self, rect: QRectF, thumb: QImage, flight: _SnapWindow) -> None:+ # The flight no longer holds the bottom slot: its card takes it.+ self._snap_done(flight)+ self._new_card(+ rect,+ thumb,+ screen_name=flight.screen_name,+ appshot_id=flight.appshot_id,+ image=flight.image,+ ).start()++ def _relayout(self) -> None:+ """Put every card in its place: newest at the bottom, older ones above.++ Per screen; a flight still on its way keeps the bottom slot free.+ Cards beyond ``MAX_CARDS``, or without room on the screen, leave.+ """+ staying = [card for card in self._cards if not card.leaving]+ for card in staying[: max(0, len(staying) - protocol.MAX_CARDS)]:+ card.leave()+ staying = staying[-protocol.MAX_CARDS :]+ by_screen: dict[str, list[_CardWindow]] = {}+ for card in reversed(staying): # newest first+ by_screen.setdefault(card.screen_name, []).append(card)+ for name, cards in by_screen.items():+ screen = _screen_named(name)+ if screen is None:+ continue+ avail = screen.availableGeometry()+ reserve = sum(+ snap.landing_height + _CARD_STACK_GAP+ for snap in self._snaps+ if snap.screen_name == name+ )+ tops = _stack_tops(+ float(avail.bottom() + 1) - _SNAP_MARGIN,+ float(avail.top()) + _SNAP_MARGIN,+ [card.card_size[1] for card in cards],+ gap=_CARD_STACK_GAP,+ reserve=reserve,+ )+ right = float(avail.right() + 1) - _SNAP_MARGIN+ pad = float(_CardWindow._PAD)+ for card, top in zip(cards, tops, strict=True):+ if top is None:+ card.leave()+ continue+ width, height = card.card_size+ place = QRectF(right - width, top, width, height).adjusted(-pad, -pad, pad, pad)+ card.move_to(place.toAlignedRect().topLeft())++ def _card_for(self, appshot_id: str) -> _CardWindow | None:+ """The card of that appshot; the newest card when no id is named."""+ live = [card for card in self._cards if not card.leaving] or self._cards+ if not appshot_id:+ return live[-1] if live else None+ return next((card for card in reversed(live) if card.appshot_id == appshot_id), None)def _card_cmd(self, payload: dict) -> None:"""The editor closed: slide the (edited) picture back into the corner."""@@ -1252,46 +1425,72 @@ class Renderer(QObject):screen = _match_screen(monitor if isinstance(monitor, list) else [])if screen is None:return+ appshot_id = str(payload.get("id", "") or "")for old in list(self._snaps):+ old.land_now()+ # The same appshot never shows twice: its old card makes way.+ for old in [c for c in self._cards if appshot_id and c.appshot_id == appshot_id]:old.finish_now()- if self._card is not None:- self._card.finish_now()- self.card_image = Noneself._card_hint = str(payload.get("hint", "") or "")self._take_card_options(payload)origin = _flight_origin(payload.get("from"))if origin is not None:- # Saved in the editor: the picture flies from the editor into- # the corner, the same flight as after the shutter.+ # Saved in the editor: the picture flies from the editor to the+ # bottom of the stack, the same flight as after the shutter.fly_screen, frac = originwin = _SnapWindow(fly_screen, frac, thumb, self._snap_landed, self._snap_done, flash=False)+ win.appshot_id = appshot_idself._snaps.append(win)+ self._relayout()win.start()return- self._new_card(_card_rect(screen, thumb), thumb).start(slide_in=True)+ self._new_card(+ _card_rect(screen, thumb), thumb, screen_name=screen.name(), appshot_id=appshot_id+ ).start(slide_in=True)- def card_action(self, action: str) -> None:- """A hover button: the main process copies or saves the held appshot."""- _emit(protocol.EVENT_CARD_ACTION, action=action)+ def card_action(self, card: _CardWindow, action: str) -> None:+ """A hover button: the main process copies or saves that card's appshot."""+ _emit(protocol.EVENT_CARD_ACTION, action=action, id=card.appshot_id)def _snap_image(self, payload: dict) -> None:+ """The finished picture: to the card (or flight) of its appshot.++ Without a card of that id, the newest one that has no appshot yet+ takes it — the shutter's card, whose id is only known after the+ capture. A picture nobody waits for is dropped; the controller sends+ it again after the next ``snap``.+ """raw = payload.get("image")if not isinstance(raw, str) or not raw:returnimage = QImage()- if image.loadFromData(QByteArray.fromBase64(raw.encode("ascii"))):- self.card_image = image+ if not image.loadFromData(QByteArray.fromBase64(raw.encode("ascii"))):+ return+ appshot_id = str(payload.get("id", "") or "")+ holders = [*reversed(self._snaps), *(c for c in reversed(self._cards) if not c.leaving)]+ holder = next(+ (h for h in holders if appshot_id and h.appshot_id == appshot_id),+ None,+ ) or next((h for h in holders if not h.appshot_id and h.image is None), None)+ if holder is None:+ return+ holder.appshot_id = holder.appshot_id or appshot_id+ holder.image = image+ if isinstance(holder, _CardWindow):+ holder.update()def card_gone(self, card: _CardWindow) -> None:- if self._card is card:- self._card = None- self.card_image = None+ with suppress(ValueError):+ self._cards.remove(card)+ if not self._cards:_emit(protocol.EVENT_CARD, open=False)+ return+ self._relayout() # the cards above it glide downdef card_clicked(self, card: _CardWindow) -> None:- _emit(protocol.EVENT_SNAP_OPEN)+ _emit(protocol.EVENT_SNAP_OPEN, id=card.appshot_id)card.leave()@staticmethod@@ -1319,10 +1518,12 @@ class Renderer(QObject):def _blank(self) -> None:# A resting thumbnail must never end up inside the next capture.+ # A flight still on its way lands now, so a quick next appshot only+ # stacks it instead of losing it; then every card hides.for snap in list(self._snaps):- snap.finish_now()- if self._card is not None:- self._card.hide()+ snap.land_now()+ for card in self._cards:+ card.hide()if not self._active:returnself._blanked = True@@ -1330,8 +1531,9 @@ class Renderer(QObject):win.hide()def _unblank(self) -> None:- if self._card is not None and not self._card.isVisible():- self._card.show()+ for card in self._cards:+ if not card.isVisible():+ card.show()if not self._active or not self._blanked:returnself._blanked = Falsediff --git a/jarvis/ui/web/appshot_routes.py b/jarvis/ui/web/appshot_routes.pyindex 8f85509bab..102751313f 100644--- a/jarvis/ui/web/appshot_routes.py+++ b/jarvis/ui/web/appshot_routes.py@@ -9,7 +9,7 @@ Endpoints (mounted by the WebServer in ``_build_app()``):GET /api/appshot/latest/image → its picture (never cached).PUT /api/appshot/latest/image → replace it with the editor's version andhand that to the assistant (deliver_edit).- POST /api/appshot/latest/card → slide it back into the corner card.+ POST /api/appshot/latest/card → bring it back into the corner card stack.POST /api/appshot/open-editor → open the editor in its own window.POST /api/appshot/clipboard → copy the editor's PNG natively (desktop only).POST /api/appshot/drag-file → write it for a native drag out (desktop only).@@ -205,10 +205,18 @@ async def latest() -> dict[str, Any]:@router.get("/latest/image")-async def latest_image() -> Response:+async def latest_image(id: str = "") -> Response: # noqa: A002+ """The last appshot's picture — or, with ``id``, that kept appshot's.++ An older card in the corner stack opens the editor on its own picture;+ an unknown id falls back to the last appshot, as before ids were sent.+ """from jarvis.appshot.store import get_store # noqa: PLC0415- shot = await asyncio.to_thread(get_store().latest)+ store = get_store()+ shot = (await asyncio.to_thread(store.get, id) if id else None) or await asyncio.to_thread(+ store.latest+ )if shot is None:raise HTTPException(status_code=404, detail="No appshot is being kept right now.")return Response(content=shot.image, media_type=shot.mime, headers=_NO_STORE)@@ -262,6 +270,8 @@ class ReturnCardRequest(BaseModel):#: Where the editor showed the picture, ``[x, y, w, h]`` in global#: logical pixels: the saved picture flies from there into the corner.fly_from: list[float] | None = Field(default=None, min_length=4, max_length=4)+ #: The appshot the editor had open; empty = the last one.+ id: str = Field(default="", max_length=64)@router.post("/latest/card")@@ -269,13 +279,15 @@ async def return_card(body: ReturnCardRequest | None = None) -> dict[str, Any]:"""Bring the held (edited) appshot back into the corner card.The editor calls this when it closes, so the picture stays at hand- like after the shutter; after a save it flies there from the editor.- ``shown: false`` where no overlay can run.+ like after the shutter; after a save it flies there from the editor and+ lands at the bottom of the corner stack. ``shown: false`` where no+ overlay can run."""from jarvis.appshot.card_actions import return_to_corner # noqa: PLC0415- fly_from = body.fly_from if body is not None else None- return {"shown": await return_to_corner(fly_from)}+ if body is None:+ return {"shown": await return_to_corner(None)}+ return {"shown": await return_to_corner(body.fly_from, shot_id=body.id)}def _png_size(data: bytes) -> tuple[int, int] | None:diff --git a/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.tsx b/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.tsxindex edd19ae50b..b7390421af 100644--- a/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.tsx+++ b/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.tsx@@ -19,11 +19,11 @@ const AppshotEditor = lazy(() =>* the editor. Escape and outside presses are left to the editor itself, which* cancels a stroke or asks before discarding edits.*/-function returnToCorner(flyFrom: [number, number, number, number]) {+function returnToCorner(id: string, flyFrom: [number, number, number, number]) {void fetch("/api/appshot/latest/card", {method: "POST",headers: { "content-type": "application/json" },- body: JSON.stringify({ fly_from: flyFrom }),+ body: JSON.stringify({ id, fly_from: flyFrom }),}).catch(() => undefined);}@@ -50,8 +50,8 @@ export function AppshotEditorHost() {key={openId}appshotId={openId}onClose={(exit) => {- // Saved or used: the picture flies back into the corner card.- if (exit?.flyFrom) returnToCorner(exit.flyFrom);+ // Saved or used: the picture flies back to the bottom of the card stack.+ if (exit?.flyFrom) returnToCorner(openId, exit.flyFrom);close();}}onApplied={applied}diff --git a/jarvis/ui/web/frontend/src/lib/appshotApi.ts b/jarvis/ui/web/frontend/src/lib/appshotApi.tsindex fd5bf60ce1..42a8e5aa96 100644--- a/jarvis/ui/web/frontend/src/lib/appshotApi.ts+++ b/jarvis/ui/web/frontend/src/lib/appshotApi.ts@@ -83,9 +83,10 @@ export function fetchLatestAppshot(): Promise<{ appshot: AppshotMeta | null }> {}export function latestAppshotImageUrl(id: string, revision = 0): string {- // The id (and the edit revision) only bust the <img> cache; the server keeps one.+ // The id picks that kept appshot (an older card in the corner stack); with+ // the edit revision it also busts the <img> cache.const v = revision ? `${id}-${revision}` : id;- return `/api/appshot/latest/image?v=${encodeURIComponent(v)}`;+ return `/api/appshot/latest/image?id=${encodeURIComponent(id)}&v=${encodeURIComponent(v)}`;}export function takeAppshot(diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsxindex e2149a1198..6a59ad5e86 100644--- a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx@@ -88,11 +88,13 @@ describe("the appshot editor window", () => {}),);const flights: unknown[] = [];+ const ids: string[] = [];const closeWindow = vi.fn(async () => undefined);render(<AppshotEditorWindowdeps={{- returnCard: async (flyFrom) => {+ returnCard: async (id, flyFrom) => {+ ids.push(id);flights.push(flyFrom);},closeWindow,@@ -106,6 +108,7 @@ describe("the appshot editor window", () => {await waitFor(() => expect(closeWindow).toHaveBeenCalledTimes(1));expect(calls).toContain("PUT /api/appshot/latest/image?id=a1b2c3d4");expect(flights).toHaveLength(1);+ expect(ids).toEqual(["a1b2c3d4"]);const from = flights[0] as number[];expect(Array.isArray(from) && from.length === 4).toBe(true);vi.restoreAllMocks();diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsxindex d142e52eca..6a0b925d1b 100644--- a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx@@ -11,8 +11,9 @@ import { AppshotEditor, type EditorExit } from "@/views/AppshotEditor";** When it closes the appshot goes back into the screen corner* (`POST /api/appshot/latest/card`), so it stays at hand — after Save or Done- * it flies there from where the editor showed it, after Close it slides in —- * and then the window closes itself through the shell+ * it flies there from where the editor showed it, after Close it slides in;+ * either way it lands at the bottom of the card stack — and then the window+ * closes itself through the shell* (`POST /api/window/reattach`), which only hides it: the window stays loaded* so the next click opens the editor at once.*/@@ -31,16 +32,16 @@ export function isAppshotEditorWindow(search: string): boolean {}export interface EditorWindowDeps {- returnCard: (flyFrom?: EditorExit["flyFrom"]) => Promise<unknown>;+ returnCard: (id: string, flyFrom?: EditorExit["flyFrom"]) => Promise<unknown>;closeWindow: () => Promise<unknown>;}const browserDeps: EditorWindowDeps = {- returnCard: (flyFrom) =>+ returnCard: (id, flyFrom) =>fetch("/api/appshot/latest/card", {method: "POST",headers: { "content-type": "application/json" },- body: JSON.stringify(flyFrom ? { fly_from: flyFrom } : {}),+ body: JSON.stringify(flyFrom ? { id, fly_from: flyFrom } : { id }),}),closeWindow: () =>fetch("/api/window/reattach", {@@ -88,13 +89,13 @@ export function AppshotEditorWindow({ deps = browserDeps }: { deps?: EditorWindo// request down with it. Then forget the picture, so the hidden window// never flashes the previous appshot when it is shown again.void deps- .returnCard(exit?.flyFrom)+ .returnCard(appshotId, exit?.flyFrom).catch(() => undefined).finally(() => {setAppshotId("");void deps.closeWindow().catch(() => undefined);});- }, [deps]);+ }, [appshotId, deps]);return (<div className="h-screen w-screen overflow-hidden bg-popover" data-testid="appshot-editor-window">diff --git a/tests/unit/appshot/test_appshot_editor.py b/tests/unit/appshot/test_appshot_editor.pyindex 1f2e6c5cd6..d464f463aa 100644--- a/tests/unit/appshot/test_appshot_editor.py+++ b/tests/unit/appshot/test_appshot_editor.py@@ -55,6 +55,46 @@ def test_an_edit_for_a_gone_or_other_appshot_changes_nothing() -> None:assert AppshotStore().replace_image("s1", b"png", "image/png", 1, 1) is None+# -- several appshots at hand: the corner card stack ---------------------------+++def test_the_store_keeps_the_last_few_newest_first() -> None:+ from jarvis.appshot.store import MAX_RECENT++ store = AppshotStore()+ for n in range(MAX_RECENT + 1):+ store.remember(_shot(f"s{n}"), keep_s=60)++ assert store.latest().id == f"s{MAX_RECENT}"+ assert store.get("s1") is not None and store.get("s1").id == "s1"+ assert store.get("s0") is None, "the oldest beyond the stack is dropped"+++def test_an_older_appshot_can_be_edited_and_marked() -> None:+ store = AppshotStore()+ store.remember(_shot("old"), keep_s=60)+ store.remember(_shot("new"), keep_s=60)++ assert store.replace_image("old", b"png", "image/png", 4, 3) is not None+ store.mark_delivered("old", "voice")++ assert store.get("old").image == b"png" and store.get("old").delivered_to == "voice"+ assert store.latest().id == "new" and store.latest().image == b"jpeg"+++def test_each_kept_appshot_expires_on_its_own() -> None:+ now = [0.0]+ store = AppshotStore(clock=lambda: now[0])+ store.remember(_shot("old"), keep_s=10)+ now[0] = 5.0+ store.remember(_shot("new"), keep_s=10)+ now[0] = 11.0++ assert store.get("old") is None and store.get("new") is not None+ store.remember(_shot("x"), keep_s=0)+ assert store.latest() is None, "keeping nothing forgets every picture"++@pytest.fixturedef client():from jarvis.ui.web.appshot_routes import router@@ -79,6 +119,15 @@ def test_the_route_takes_a_png_and_serves_it_back(client) -> None:assert served.content == png and served.headers["content-type"] == "image/png"+def test_the_route_serves_an_older_card_its_own_picture(client) -> None:+ get_store().remember(_shot("s2"), keep_s=60)+ assert client.put("/api/appshot/latest/image?id=s1", content=_png()).status_code == 200++ assert client.get("/api/appshot/latest/image?id=s1").content == _png()+ assert client.get("/api/appshot/latest/image").content == b"jpeg", "the last one by default"+ assert client.get("/api/appshot/latest/image?id=gone").content == b"jpeg"++@pytest.mark.parametrize(("body", "status"),[(b"", 413), (b"not an image", 400)],@@ -254,8 +303,8 @@ def test_the_card_route_hands_the_flight_start_through(monkeypatch: pytest.Monkeseen: list = []- async def fake_return(fly_from=None):- seen.append(fly_from)+ async def fake_return(fly_from=None, *, shot_id=""):+ seen.append((fly_from, shot_id))return Truemonkeypatch.setattr(card_actions, "return_to_corner", fake_return)@@ -263,11 +312,13 @@ def test_the_card_route_hands_the_flight_start_through(monkeypatch: pytest.Monkeapp.include_router(router)client = TestClient(app)- saved = client.post("/api/appshot/latest/card", json={"fly_from": [100, 80, 640, 400]})+ saved = client.post(+ "/api/appshot/latest/card", json={"id": "a1b2c3d4", "fly_from": [100, 80, 640, 400]}+ )closed = client.post("/api/appshot/latest/card")assert saved.json() == {"shown": True} and closed.json() == {"shown": True}- assert seen == [[100.0, 80.0, 640.0, 400.0], None]+ assert seen == [([100.0, 80.0, 640.0, 400.0], "a1b2c3d4"), (None, "")]assert client.post("/api/appshot/latest/card", json={"fly_from": [1, 2]}).status_code == 422diff --git a/tests/unit/cu/indicator/test_appshot_card.py b/tests/unit/cu/indicator/test_appshot_card.pyindex 1b5d62bad7..f1f70dc1f4 100644--- a/tests/unit/cu/indicator/test_appshot_card.py+++ b/tests/unit/cu/indicator/test_appshot_card.py@@ -113,7 +113,7 @@ async def test_a_picture_that_may_not_be_kept_is_never_handed_to_the_card(monkeysent: list[bytes] = []- async def attach(image: bytes) -> None:+ async def attach(image: bytes, shot_id: str = "") -> None:sent.append(image)monkeypatch.setattr(effect, "attach_card_image", attach)diff --git a/tests/unit/cu/indicator/test_card_stack.py b/tests/unit/cu/indicator/test_card_stack.pynew file mode 100644index 0000000000..7e7acf984f--- /dev/null+++ b/tests/unit/cu/indicator/test_card_stack.py@@ -0,0 +1,281 @@+"""Appshot cards stack in the screen corner, each one tied to its own appshot.++The newest card lands at the bottom and the older ones move up; a gone card+lets the ones above it move down. Runs the real sidecar renderer on Qt's+offscreen platform; auto-skips without PySide6 (a [desktop] extra).+"""++from __future__ import annotations++import asyncio+import base64+import importlib.util+import os++import pytest++from jarvis.cu.indicator import protocol+from jarvis.cu.indicator.controller import CUIndicatorController++_HAS_QT = importlib.util.find_spec("PySide6") is not None+needs_qt = pytest.mark.skipif(+ not _HAS_QT, reason="PySide6 not installed (indicator sidecar is a [desktop] extra)"+)++[email protected](scope="module")+def qt():+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")+ from PySide6.QtWidgets import QApplication # noqa: PLC0415++ app = QApplication.instance() or QApplication([])+ from jarvis.cu.indicator import renderer # noqa: PLC0415++ yield renderer, app+ del app+++def _b64_png(width: int, height: int) -> str:+ from PySide6.QtCore import QBuffer, QByteArray, QIODevice # noqa: PLC0415+ from PySide6.QtGui import QColor, QImage # noqa: PLC0415++ image = QImage(width, height, QImage.Format.Format_ARGB32)+ image.fill(QColor(90, 140, 210))+ data = QByteArray()+ buffer = QBuffer(data)+ buffer.open(QIODevice.OpenModeFlag.WriteOnly)+ image.save(buffer, "PNG")+ return base64.b64encode(bytes(data.data())).decode("ascii")+++def renderer(qt, monkeypatch):+ module, app = qt+ events: list[dict] = []+ monkeypatch.setattr(+ module, "_emit", lambda event, **fields: events.append({"event": event, **fields})+ )+ monkeypatch.setattr(module, "_ack", lambda _cmd: None)+ r = module.Renderer(app)+ yield r, events+ for card in list(r._cards):+ card.finish_now()+ for snap in list(r._snaps):+ snap.finish_now()+++def _shutter(r, shot_id: str, size: tuple[int, int] = (400, 240)) -> None:+ """One appshot: the shutter flight, its finished picture, then it lands."""+ r.on_line(protocol.encode_command(+ protocol.CMD_SNAP, monitor=[], rect=[0.1, 0.1, 0.5, 0.5], thumb=_b64_png(*size)+ ))+ r.on_line(protocol.encode_command(protocol.CMD_SNAP_IMAGE, image=_b64_png(*size), id=shot_id))+ for snap in list(r._snaps):+ snap.land_now()+++def _tops(r) -> list[int]:+ """Window top of every card, oldest first (where each card is headed)."""+ return [card._target.y() for card in r._cards]+++# -- the layout rule ----------------------------------------------------------+++def test_the_newest_card_sits_at_the_bottom_and_older_ones_climb() -> None:+ pytest.importorskip("PySide6")+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")+ from jarvis.cu.indicator.renderer import _stack_tops++ assert _stack_tops(1000.0, 0.0, [200.0, 100.0, 150.0], gap=10.0) == [800.0, 690.0, 530.0]+++def test_a_flight_on_its_way_keeps_the_bottom_slot_free() -> None:+ pytest.importorskip("PySide6")+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")+ from jarvis.cu.indicator.renderer import _stack_tops++ assert _stack_tops(1000.0, 0.0, [200.0], gap=10.0, reserve=210.0) == [590.0]+++def test_cards_without_room_drop_out_oldest_first() -> None:+ pytest.importorskip("PySide6")+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")+ from jarvis.cu.indicator.renderer import _stack_tops++ tops = _stack_tops(500.0, 0.0, [200.0, 200.0, 100.0, 10.0], gap=10.0)+ assert tops == [300.0, 90.0, None, None], "once one does not fit, no older one squeezes in"+++# -- the real renderer ----------------------------------------------------------+++@needs_qt+def test_a_second_appshot_stacks_below_the_first(renderer) -> None:+ r, events = renderer+ _shutter(r, "aaaa1111")+ first_top = _tops(r)[0]+ _shutter(r, "bbbb2222")++ assert [card.appshot_id for card in r._cards] == ["aaaa1111", "bbbb2222"]+ older, newer = _tops(r)+ assert newer == first_top, "the new card takes the bottom slot"+ assert older < newer, "the older card moved up"+ assert all(card.image is not None for card in r._cards), "each card keeps its own picture"+ assert [e for e in events if e["event"] == "card"] == [+ {"event": "card", "open": True},+ {"event": "card", "open": True},+ ]+++@needs_qt+def test_the_stack_moves_up_while_the_next_picture_flies_in(renderer) -> None:+ r, _ = renderer+ _shutter(r, "aaaa1111")+ resting = _tops(r)[0]+ r.on_line(protocol.encode_command(+ protocol.CMD_SNAP, monitor=[], rect=[0.1, 0.1, 0.5, 0.5], thumb=_b64_png(400, 240)+ ))+ assert len(r._snaps) == 1+ assert _tops(r)[0] < resting, "the bottom slot is free before the flight lands"+++@needs_qt+def test_a_gone_card_lets_the_ones_above_it_move_down(renderer) -> None:+ r, events = renderer+ _shutter(r, "aaaa1111")+ bottom = _tops(r)[0]+ _shutter(r, "bbbb2222")++ r._cards[1].finish_now() # the bottom (newest) card goes++ assert [card.appshot_id for card in r._cards] == ["aaaa1111"]+ assert _tops(r) == [bottom]+ r._cards[0].finish_now()+ assert events[-1] == {"event": "card", "open": False}, "only the last card closes the stack"+++@needs_qt+def test_the_stack_holds_at_most_max_cards(renderer) -> None:+ r, _ = renderer+ for n in range(protocol.MAX_CARDS + 1):+ _shutter(r, f"{n:08x}", size=(400, 60))+ staying = [card.appshot_id for card in r._cards if not card.leaving]+ assert len(staying) == protocol.MAX_CARDS+ assert "00000000" not in staying, "the oldest card leaves first"+++@needs_qt+def test_buttons_and_clicks_name_their_own_card(renderer) -> None:+ r, events = renderer+ _shutter(r, "aaaa1111")+ _shutter(r, "bbbb2222")+ older = r._cards[0]++ r.card_action(older, "copy")+ r.card_clicked(older)++ assert {"event": "card_action", "action": "copy", "id": "aaaa1111"} in events+ assert {"event": "snap_open", "id": "aaaa1111"} in events+++@needs_qt+def test_a_saved_edit_comes_back_as_the_newest_card(renderer) -> None:+ r, _ = renderer+ _shutter(r, "aaaa1111")+ _shutter(r, "bbbb2222")++ # The older one was edited and saved: it flies back to the bottom.+ r.on_line(protocol.encode_command(+ protocol.CMD_CARD, monitor=[], thumb=_b64_png(400, 240), id="aaaa1111",+ **{"from": [40, 40, 400, 240]},+ ))+ r.on_line(+ protocol.encode_command(protocol.CMD_SNAP_IMAGE, image=_b64_png(400, 240), id="aaaa1111")+ )+ for snap in list(r._snaps):+ snap.land_now()++ live = [card for card in r._cards if not card.leaving]+ assert [card.appshot_id for card in live] == ["bbbb2222", "aaaa1111"]+ assert live[1].image is not None, "the edited picture reached its card"+ assert _tops(r)[-1] > _tops(r)[0]+++# -- the controller names the card's appshot -------------------------------------+++class _Bus:+ def __init__(self) -> None:+ self.events: list = []++ async def publish(self, event) -> None:+ self.events.append(event)++ def subscribe(self, *_args) -> None:+ return None+++async def test_a_card_action_and_its_status_go_to_that_card(monkeypatch) -> None:+ from jarvis.appshot import card_actions++ class _Proc:+ @staticmethod+ def poll() -> None:+ return None++ seen: list[tuple[str, str]] = []++ async def fake_action(action: str, shot_id: str = "") -> str:+ seen.append((action, shot_id))+ return "Copied"++ monkeypatch.setattr(card_actions, "run_card_action", fake_action)+ ctl = CUIndicatorController(_Bus())+ ctl._proc = _Proc()+ sent: list[tuple[str, dict]] = []+ monkeypatch.setattr(ctl, "_send_and_wait", lambda cmd, _t, **f: sent.append((cmd, f)) or True)++ await ctl._card_action("copy", "aaaa1111")++ assert seen == [("copy", "aaaa1111")]+ assert sent == [(protocol.CMD_CARD_STATUS, {"text": "Copied", "id": "aaaa1111"})]+++async def test_a_click_on_an_older_card_opens_its_own_appshot(monkeypatch) -> None:+ from jarvis.appshot import editor_window+ from jarvis.appshot.store import Appshot, get_store++ store = get_store()+ store.clear()+ for shot_id in ("aaaa1111", "bbbb2222"):+ store.remember(+ Appshot(+ id=shot_id, image=b"jpeg", mime="image/jpeg", width=1, height=1, label="",+ app_name="", note="", ui_text="", trigger="hotkey", taken_at=0.0,+ ),+ keep_s=60,+ )+ opened: list[str] = []++ async def fake_open(shot_id: str) -> bool:+ opened.append(shot_id)+ return True++ monkeypatch.setattr(editor_window, "open_editor_window", fake_open)+ ctl = CUIndicatorController(_Bus())+ ctl._loop = asyncio.get_running_loop()+ try:+ ctl._handle_sidecar_event({"event": "snap_open", "id": "aaaa1111"})+ await asyncio.sleep(0.01)+ finally:+ store.clear()+ assert opened == ["aaaa1111"]+++async def test_the_finished_picture_names_its_appshot() -> None:+ ctl = CUIndicatorController(_Bus())+ assert await ctl.snap_image("b64", shot_id="aaaa1111") is False, "no sidecar yet"+ assert (ctl._card_image_b64, ctl._card_image_id) == ("b64", "aaaa1111")+ ctl.hold_for_snap()+ assert (ctl._card_image_b64, ctl._card_image_id) == (None, "")