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
fix(appshot): let a gallery drag reach the chat and name the dragged file
rubenluetke10-beep2c07a125a834
diff --git a/jarvis/appshot/library.py b/jarvis/appshot/library.pyindex 703b3ea2bc..66179e9035 100644--- a/jarvis/appshot/library.py+++ b/jarvis/appshot/library.py@@ -14,10 +14,14 @@ pictures are the finished, privacy-filtered appshots, never a raw frame.Layout, one folder per appshot under ``<data dir>/appshots/``::- <id>/meta.json what the page shows (no pixels)- <id>/original.<ext> the appshot as captured- <id>/edited.png the last edit saved in the editor, when there is one- <id>/thumb-*.jpg gallery thumbnails, made on first view+ <id>/meta.json what the page shows (no pixels)+ <id>/appshot-<taken>.<ext> the appshot as captured+ <id>/appshot-<taken>-edited.png the last edit saved in the editor+ <id>/thumb-*.jpg gallery thumbnails, made on first view++The picture files carry the capture time in their names because a drag hands+the file itself to a chat, a terminal agent or another app, where+``appshot-20261003-114747.png`` says what it is and ``original.png`` does not.Nothing here is imported at boot (AP-26)."""@@ -130,14 +134,38 @@ def _write_meta(folder: Path, meta: dict[str, object]) -> None:tmp.replace(folder / "meta.json")-def _original_file(folder: Path) -> Path | None:- for ext in _MIMES:+def _stem(taken_at: float) -> str:+ return time.strftime("appshot-%Y%m%d-%H%M%S", time.localtime(taken_at))+++def _named(folder: Path, meta: dict[str, object], key: str) -> Path | None:+ """The picture ``meta[key]`` names, when it is a plain file name that exists."""+ name = meta.get(key)+ if not isinstance(name, str) or not name or Path(name).name != name:+ return None+ candidate = folder / name+ return candidate if candidate.is_file() else None+++def _original_file(folder: Path, meta: dict[str, object]) -> Path | None:+ named = _named(folder, meta, "file")+ if named is not None:+ return named+ for ext in _MIMES: # entries written before the files carried their timecandidate = folder / f"original.{ext}"if candidate.is_file():return candidatereturn None+def _edited_file(folder: Path, meta: dict[str, object]) -> Path | None:+ named = _named(folder, meta, "edited_file")+ if named is not None:+ return named+ legacy = folder / "edited.png"+ return legacy if legacy.is_file() else None++def _drop_thumbs(folder: Path, variant: Variant) -> None:for thumb in folder.glob(f"thumb-{variant}*.jpg"):try:@@ -163,9 +191,11 @@ def save(shot: Appshot) -> bool:ext = _EXTENSIONS.get(shot.mime, "jpg")with _lock:folder.mkdir(parents=True, exist_ok=True)- (folder / f"original.{ext}").write_bytes(shot.image)+ name = f"{_stem(shot.taken_at)}.{ext}"+ (folder / name).write_bytes(shot.image)meta = {**_base_meta(shot),+ "file": name,"mime": shot.mime,"width": shot.width,"height": shot.height,@@ -188,10 +218,15 @@ def save_edit(shot: Appshot) -> bool:folder = _folder(shot.id)with _lock:folder.mkdir(parents=True, exist_ok=True)- (folder / "edited.png").write_bytes(shot.image)meta = _read_meta(folder) or _base_meta(shot)+ taken = meta.get("taken_at")+ name = (+ f"{_stem(taken if isinstance(taken, (int, float)) else shot.taken_at)}-edited.png"+ )+ (folder / name).write_bytes(shot.image)meta.update({+ "edited_file": name,"edited_at": time.time(),"edited_width": shot.width,"edited_height": shot.height,@@ -219,9 +254,9 @@ def _items_for(folder: Path, meta: dict[str, object]) -> list[LibraryItem]:"taken_at": _num("taken_at"),}items: list[LibraryItem] = []- edited = folder / "edited.png"- has_edit = edited.is_file()- if has_edit:+ edited = _edited_file(folder, meta)+ has_edit = edited is not None+ if edited is not None:items.append(LibraryItem(variant="edited",@@ -234,7 +269,7 @@ def _items_for(folder: Path, meta: dict[str, object]) -> list[LibraryItem]:**common, # type: ignore[arg-type]))- original = _original_file(folder)+ original = _original_file(folder, meta)if original is not None:items.append(LibraryItem(@@ -346,8 +381,11 @@ def delete(shot_id: str, variant: Variant) -> bool:with _lock:if not folder.is_dir():return False- edited = folder / "edited.png"- if variant == "edited" and _original_file(folder) is not None:+ meta = _read_meta(folder) or {}+ if variant == "edited" and _original_file(folder, meta) is not None:+ edited = _edited_file(folder, meta)+ if edited is None:+ return Falsetry:edited.unlink()except FileNotFoundError: # already gone: the route answers 404diff --git a/jarvis/ui/web/frontend/src/lib/appshotApi.ts b/jarvis/ui/web/frontend/src/lib/appshotApi.tsindex c1b0eed123..f8c4b45466 100644--- a/jarvis/ui/web/frontend/src/lib/appshotApi.ts+++ b/jarvis/ui/web/frontend/src/lib/appshotApi.ts@@ -208,16 +208,9 @@ export function appshotLibraryImageUrl(item: AppshotLibraryItem, thumb = false):return `/api/appshot/library/${encodeURIComponent(item.id)}/image?${params.toString()}`;}-/** A file name for a dragged-out picture: `appshot-20261003-114747(-edited).png`. */+/** The picture's own file name (`appshot-20261003-114747(-edited).png`), for a drag out. */export function appshotLibraryFileName(item: AppshotLibraryItem): string {- const fromPath = item.path.split(/[\\/]/).pop() ?? "";- const extension = fromPath.includes(".") ? fromPath.split(".").pop() : "png";- const stamp = new Date(item.taken_at * 1000)- .toISOString()- .replace(/[-:]/g, "")- .replace(/\..*$/, "")- .replace("T", "-");- return `appshot-${stamp}${item.variant === "edited" ? "-edited" : ""}.${extension}`;+ return item.path.split(/[\\/]/).pop() || `appshot-${item.id}.png`;}/**diff --git a/jarvis/ui/web/frontend/src/views/AppshotLibrary.test.tsx b/jarvis/ui/web/frontend/src/views/AppshotLibrary.test.tsxindex 22586a33e3..683638945d 100644--- a/jarvis/ui/web/frontend/src/views/AppshotLibrary.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotLibrary.test.tsx@@ -11,7 +11,7 @@ import { AppshotLibrary } from "@/views/AppshotLibrary";const ORIGINAL: AppshotLibraryItem = {id: "a1",variant: "original",- path: "C:\\Jarvis\\data\\appshots\\a1\\original.png",+ path: "C:\\Jarvis\\data\\appshots\\a1\\appshot-20260921-120000.png",mime: "image/png",width: 1280,height: 720,@@ -25,7 +25,7 @@ const ORIGINAL: AppshotLibraryItem = {const EDITED: AppshotLibraryItem = {...ORIGINAL,variant: "edited",- path: "C:\\Jarvis\\data\\appshots\\a1\\edited.png",+ path: "C:\\Jarvis\\data\\appshots\\a1\\appshot-20260921-120000-edited.png",edited_at: 1_790_000_100,has_edit: false,};@@ -106,6 +106,15 @@ describe("AppshotLibrary", () => {expect(extractPaneDrop(dt as unknown as DataTransfer).paths).toEqual([EDITED.path]);});+ it("lifts the Settings dialog out of the way while a tile is dragged", async () => {+ render(<AppshotLibrary enabled refreshKey="" />);+ const [tile] = await screen.findAllByTestId("appshot-library-tile");+ fireEvent.dragStart(tile, { dataTransfer: new FakeDataTransfer() });+ await waitFor(() => expect(document.documentElement.dataset.appshotDrag).toBe("1"));+ fireEvent.dragEnd(tile);+ expect(document.documentElement.dataset.appshotDrag).toBeUndefined();+ });+it("deletes only the edit from an edited tile", async () => {render(<AppshotLibrary enabled refreshKey="" />);await waitFor(() => expect(screen.getAllByTestId("appshot-library-tile")).toHaveLength(3));diff --git a/jarvis/ui/web/frontend/src/views/AppshotLibrary.tsx b/jarvis/ui/web/frontend/src/views/AppshotLibrary.tsxindex 29e585b708..16c0ba4645 100644--- a/jarvis/ui/web/frontend/src/views/AppshotLibrary.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotLibrary.tsx@@ -28,6 +28,11 @@ import { useEventStore } from "@/store/events";* composer attaches it and a terminal pane hands it to its agent — the drop* targets need no appshot-specific code. Inside the desktop shell the grip* starts a native file drag instead, which reaches any other app as well.+ *+ * The gallery sits in the Settings dialog, which covers the chat and the+ * terminals — the very fields a picture is dragged into. So while a tile is+ * being dragged the dialog steps aside (`html[data-appshot-drag]`, see+ * LIFT_DIALOG_CSS) and comes back the moment the drag ends.*/type Filter = "all" | "edited";@@ -37,6 +42,29 @@ const PAGE = 48;const tileKey = (item: AppshotLibraryItem) => `${item.id}:${item.variant}`;+/**+ * While a tile is dragged: the Settings dialog and its dim fade out and let+ * the drag through to the app behind. Radix keeps `pointer-events: none` on+ * the body while a modal is open, which would hide every drop target, so the+ * body is opened up for exactly as long as the drag lasts. The dim is the+ * element right before the dialog — only that one: the dialog is a child of+ * <body>, so a looser sibling match would hide the whole app (#root).+ */+const LIFT_DIALOG_CSS = `+html[data-appshot-drag] body { pointer-events: auto !important; }+html[data-appshot-drag] [data-testid="settings-hub-dialog"],+html[data-appshot-drag] [data-state]:has(+ [data-testid="settings-hub-dialog"]) {+ opacity: 0;+ pointer-events: none !important;+ transition: opacity 120ms ease-out;+}`;++function liftDialog(lifted: boolean): void {+ const root = document.documentElement;+ if (lifted) root.dataset.appshotDrag = "1";+ else delete root.dataset.appshotDrag;+}+function when(item: AppshotLibraryItem): string {return new Date((item.edited_at || item.taken_at) * 1000).toLocaleString([], {day: "numeric",@@ -76,12 +104,16 @@ function Tile({const absoluteUrl = new URL(appshotLibraryImageUrl(item), window.location.href).toString();dt.setData("DownloadURL", `${item.mime}:${appshotLibraryFileName(item)}:${absoluteUrl}`);if (imageRef.current) dt.setDragImage(imageRef.current, 24, 24);+ // Not in this tick: hiding the drag source before the browser has taken+ // its picture cancels the drag in Chromium.+ window.setTimeout(() => liftDialog(true), 0);};return (<lidraggableonDragStart={onDragStart}+ onDragEnd={() => liftDialog(false)}data-testid="appshot-library-tile"data-variant={item.variant}className="group relative flex cursor-grab flex-col overflow-hidden rounded-lg border border-border bg-background active:cursor-grabbing"@@ -211,6 +243,22 @@ export function AppshotLibrary({[],);+ // Backstops for a drag whose `dragend` never reaches the tile (the drop+ // landed in another window, or the tile re-rendered): any drop or drag end+ // on the page, any pointer or key event afterwards (none fire during a+ // drag), and leaving the window all bring the dialog back. Unmounting too.+ useEffect(() => {+ const settle = () => {+ if (document.documentElement.dataset.appshotDrag) liftDialog(false);+ };+ const events = ["drop", "dragend", "pointermove", "pointerdown", "keydown", "blur"] as const;+ for (const name of events) window.addEventListener(name, settle, true);+ return () => {+ for (const name of events) window.removeEventListener(name, settle, true);+ liftDialog(false);+ };+ }, []);+const editedCount = useMemo(() => (items ?? []).filter((item) => item.variant === "edited").length,[items],@@ -284,6 +332,7 @@ export function AppshotLibrary({className="mt-5 rounded-xl border border-border bg-card p-5"aria-labelledby="appshot-library-title">+ <style>{LIFT_DIALOG_CSS}</style><div className="flex flex-wrap items-start justify-between gap-x-6 gap-y-3"><div className="min-w-[min(100%,16rem)] flex-1"><p id="appshot-library-title" className="text-base font-medium text-foreground">diff --git a/tests/unit/appshot/test_appshot_library.py b/tests/unit/appshot/test_appshot_library.pyindex d7bf1ca770..c118e69d30 100644--- a/tests/unit/appshot/test_appshot_library.py+++ b/tests/unit/appshot/test_appshot_library.py@@ -42,6 +42,9 @@ def test_a_kept_appshot_lists_without_its_screen_text() -> None:[item] = library.list_items()assert (item.id, item.variant, item.width, item.app_name) == ("a1", "original", 64, "Editor")+ assert item.path.name.startswith("appshot-") and item.path.suffix == ".png", (+ "a dragged file says what it is"+ )assert item.path.read_bytes() == _shot().imagestored = "".join(p.read_text("utf-8") for p in item.path.parent.glob("*.json"))assert "secret on-screen text" not in stored, "the scrubbed UI text never reaches disk"@@ -57,6 +60,7 @@ def test_an_edit_sits_right_before_its_original_and_newest_comes_first() -> Noneassert rows == [("new", "original"), ("old", "edited"), ("old", "original")]edit = library.get_item("old", "edited")assert edit is not None and edit.path.read_bytes() == edited+ assert edit.path.name.endswith("-edited.png")assert library.get_item("old", "original").has_edit@@ -171,3 +175,18 @@ def test_the_gallery_can_be_deleted(client) -> None:assert client.delete("/api/appshot/library/a1").status_code == 404assert client.delete("/api/appshot/library").json() == {"ok": True, "removed": 1}assert client.get("/api/appshot/library").json()["items"] == []+++def test_an_entry_written_with_the_old_file_names_still_lists(tmp_path) -> None:+ folder = library.library_root() / "legacy"+ folder.mkdir(parents=True)+ (folder / "original.png").write_bytes(_png())+ (folder / "edited.png").write_bytes(_png(8, 8))+ (folder / "meta.json").write_text('{"taken_at": 5, "width": 64, "height": 48}', "utf-8")++ assert [(i.variant, i.path.name) for i in library.list_items()] == [+ ("edited", "edited.png"),+ ("original", "original.png"),+ ]+ assert library.delete("legacy", "edited")+ assert [i.variant for i in library.list_items()] == ["original"]