Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(apps): resolve Show Page icons via Vite publicDir root-mapping (§7.1j) (#917)
Call Whitec52f1a5979dd
diff --git a/core/show_pages.py b/core/show_pages.pyindex 1aa7ad7cf..a770f8bac 100644--- a/core/show_pages.py+++ b/core/show_pages.py@@ -747,6 +747,23 @@ def _resolve_icon_candidate(page_dir: Path, relative: str) -> tuple[Path, str] |return candidate, content_type+def _public_mapped_icon_relative(relative: str) -> str | None:+ """The Vite publicDir root-mapping of a declared icon href, or None.++ Vite serves ``public/*`` at the SITE ROOT, so a browser-valid relative href like+ ``./icon.png`` (which the page resolves against the site root) can live on disk at+ ``public/icon.png`` — while our resolution is against the workspace root, so the exact+ on-disk path ``<ws>/icon.png`` misses. This returns the ``public/``-prefixed relative+ to try AFTER the exact path. None when the path is already under ``public/`` (the+ exact-path probe covers it — no ``public/public/…``). The result is a plain relative+ that still flows through :func:`_resolve_icon_candidate`, so the realpath / whitelist /+ size guards apply to the mapped path too (a hostile ``..`` href is already rejected by+ :func:`_extract_icon_path`, and the realpath check re-guards the mapped candidate)."""+ if relative.startswith("public/"):+ return None+ return f"public/{relative}"++def resolve_show_page_icon(session_id: str) -> tuple[Path, str] | None:"""The absolute path + Content-Type of a Show Page's own icon, or None.@@ -756,8 +773,11 @@ def resolve_show_page_icon(session_id: str) -> tuple[Path, str] | None:the serving layer just streams the file. An explicit ``<link rel="icon">`` WINS;when the page declares none, it falls back to the workspace-conventional faviconfiles (root then ``public/``) so agent-built pages — which rarely add a link —- still get an icon (§7.1h). Returns None for any missing workspace / no icon /- policy rejection — the caller answers 404 and the frontend uses the letter avatar.+ still get an icon (§7.1h). A declared href also honors Vite's **publicDir+ root-mapping** (§7.1j): an exact ``<ws>/<path>`` miss falls back to+ ``<ws>/public/<path>`` (Vite serves ``public/*`` at the site root) before the+ conventions. Returns None for any missing workspace / no icon / policy rejection —+ the caller answers 404 and the frontend uses the letter avatar."""page_dir = show_page_dir(session_id)link = _extract_icon_path(page_dir)@@ -765,7 +785,19 @@ def resolve_show_page_icon(session_id: str) -> tuple[Path, str] | None:# explicit link that resolves to nothing (missing file / rejected) must not strand# the page icon-less when a conventional favicon exists — fall through to the# conventions after it, so coverage is maximized (Codex §7.1h).- relatives = (link, *_CONVENTIONAL_ICON_RELATIVES) if link else _CONVENTIONAL_ICON_RELATIVES+ #+ # For the declared link, probe the EXACT on-disk path first, then the Vite publicDir+ # mapping (``public/<path>``): a fully-compliant ``./icon.png`` can live at+ # ``public/icon.png`` because Vite serves ``public/*`` at the site root while we+ # resolve against the workspace root on disk, so the exact path misses even though the+ # browser loads it fine (owner-reported §7.1j). The mapped candidate still goes through+ # _resolve_icon_candidate, so whitelist/size/traversal-realpath guards apply to it too.+ if link:+ mapped = _public_mapped_icon_relative(link)+ link_candidates = (link, mapped) if mapped else (link,)+ relatives = (*link_candidates, *_CONVENTIONAL_ICON_RELATIVES)+ else:+ relatives = _CONVENTIONAL_ICON_RELATIVESfor relative in relatives:resolved = _resolve_icon_candidate(page_dir, relative)if resolved is not None:diff --git a/docs/plans/dock-pinned-show-page-apps.md b/docs/plans/dock-pinned-show-page-apps.mdindex 85c11e2eb..34148c679 100644--- a/docs/plans/dock-pinned-show-page-apps.md+++ b/docs/plans/dock-pinned-show-page-apps.md@@ -695,6 +695,18 @@ alongside §7.1h item 3), in `AppWindow.tsx` + `WindowManagerContext.tsx`:archived session with `session_archived` (the store's `is_archived` check is promoted topublic), matching every other Show Page mutator's archived guard.+**Amendment (owner-reported bug, 2026-07-16 — Vite publicDir root-mapping):** the icon+resolver resolved a declared `<link rel=icon href="./icon.png">` only against `<ws>/icon.png`+on disk, so a fully-compliant page whose icon lives at `public/icon.png` (Vite serves+`public/*` at the SITE ROOT, so the browser loads `./icon.png` fine) was deemed unusable →+letter avatar. Fix: when the declared href misses at the exact path, also try+`<ws>/public/<path>` before falling through. Precedence: **exact path first, then the+`public/` mapping**, then the conventional fallback (unchanged). The mapped candidate runs+through the same `_resolve_icon_candidate` chokepoint, so the whitelist / 2 MiB cap /+traversal-realpath guards apply to it too (a hostile `..` href is already rejected by the+href policy before mapping), and `icon_version` hashes the resolved (mapped) file so it stays+content-correct. The mapping is LINK-scoped — it is not a blanket scan of `public/`.+### 7.2 Becoming an app: the ladder (owner Q&A 2026-07-13)Pinning **is** installing — no separate ceremony. Two entrances, one action:diff --git a/tests/test_show_pages.py b/tests/test_show_pages.pyindex df46d54ae..8435f3729 100644--- a/tests/test_show_pages.py+++ b/tests/test_show_pages.py@@ -1165,6 +1165,107 @@ def test_resolve_icon_none_without_link_or_conventional(monkeypatch, tmp_path):assert resolve_show_page_icon("sesnone") is None+def test_resolve_icon_link_maps_to_vite_public_dir(monkeypatch, tmp_path):+ # §7.1j: a fully-compliant `./icon.png` whose file lives at public/icon.png (Vite+ # serves public/* at the SITE ROOT) must resolve — the exact <ws>/icon.png misses, so+ # the resolver falls back to the publicDir mapping instead of the letter avatar.+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import resolve_show_page_icon++ page_dir = ensure_show_page_dir("sespub")+ (page_dir / "index.html").write_text(+ '<link rel="icon" type="image/png" sizes="180x180" href="./icon.png">', encoding="utf-8"+ )+ (page_dir / "public").mkdir(parents=True, exist_ok=True)+ (page_dir / "public" / "icon.png").write_bytes(b"PUBLIC-PNG")++ resolved = resolve_show_page_icon("sespub")+ assert resolved is not None+ assert resolved[0] == (page_dir / "public" / "icon.png").resolve()+ assert resolved[1] == "image/png"+++def test_resolve_icon_link_exact_path_wins_over_public_mapping(monkeypatch, tmp_path):+ # Precedence: when the declared href exists at BOTH the exact on-disk path and the+ # publicDir mapping, the exact path (root) wins (§7.1j).+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import resolve_show_page_icon++ page_dir = ensure_show_page_dir("sesboth")+ (page_dir / "index.html").write_text('<link rel="icon" href="./icon.png">', encoding="utf-8")+ (page_dir / "icon.png").write_bytes(b"ROOT-PNG")+ (page_dir / "public").mkdir(parents=True, exist_ok=True)+ (page_dir / "public" / "icon.png").write_bytes(b"PUBLIC-PNG")++ resolved = resolve_show_page_icon("sesboth")+ assert resolved is not None+ assert resolved[0] == (page_dir / "icon.png").resolve() # exact/root wins over public/+++def test_resolve_icon_public_mapping_does_not_bypass_traversal(monkeypatch, tmp_path):+ # The publicDir mapping must not open a traversal hole: a hostile `..` href is rejected+ # by the href policy (so the mapping is never reached from it), and an outside file is+ # never served — the mapping only ever prepends `public/` to an already-clean path.+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import resolve_show_page_icon++ page_dir = ensure_show_page_dir("sestrav")+ (tmp_path / "outside.png").write_bytes(b"OUTSIDE")+ for href in ("./../outside.png", "./..%2foutside.png", r".\..\outside.png", "public/../../outside.png"):+ (page_dir / "index.html").write_text(f'<link rel="icon" href="{href}">', encoding="utf-8")+ assert resolve_show_page_icon("sestrav") is None, href+++def test_resolve_icon_conventional_order_unchanged_after_unusable_link(monkeypatch, tmp_path):+ # (d) The publicDir mapping is LINK-scoped and runs before the conventions; it must not+ # perturb the conventional order. An unusable link (no exact, no public mapping) falls+ # through, and the conventions still resolve root-before-public.+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import resolve_show_page_icon++ page_dir = ensure_show_page_dir("sesorder2")+ (page_dir / "index.html").write_text('<link rel="icon" href="missing.svg">', encoding="utf-8")+ (page_dir / "public").mkdir(parents=True, exist_ok=True)+ (page_dir / "public" / "favicon.svg").write_bytes(b"PUB")+ (page_dir / "favicon.svg").write_bytes(b"ROOT")++ resolved = resolve_show_page_icon("sesorder2")+ assert resolved is not None+ assert resolved[0] == (page_dir / "favicon.svg").resolve() # root convention still wins+++def test_resolve_icon_public_mapping_is_link_scoped(monkeypatch, tmp_path):+ # The mapping only applies to a DECLARED link, not a blanket scan of public/: a+ # non-conventionally-named file in public/ with NO link that points at it is not an+ # icon (so it stays the letter avatar) — this keeps the fallback rules tight.+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import resolve_show_page_icon++ page_dir = ensure_show_page_dir("seslinkscope")+ (page_dir / "index.html").write_text("<title>no link</title>", encoding="utf-8")+ (page_dir / "public").mkdir(parents=True, exist_ok=True)+ (page_dir / "public" / "icon.png").write_bytes(b"UNREFERENCED") # not a favicon name, no link+ assert resolve_show_page_icon("seslinkscope") is None+++def test_icon_version_follows_public_mapped_file(monkeypatch, tmp_path):+ # (e) icon_version hashes the RESOLVED (mapped) file's content, so overwriting+ # public/icon.png changes the token — the content-versioned URL stays correct.+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ from core.show_pages import show_page_icon_version++ page_dir = ensure_show_page_dir("sespubver")+ (page_dir / "index.html").write_text('<link rel="icon" href="./icon.png">', encoding="utf-8")+ (page_dir / "public").mkdir(parents=True, exist_ok=True)+ (page_dir / "public" / "icon.png").write_bytes(b"V1")+ v1 = show_page_icon_version("sespubver")+ assert v1++ (page_dir / "public" / "icon.png").write_bytes(b"V2-different-bytes")+ v2 = show_page_icon_version("sespubver")+ assert v2 and v2 != v1++def test_read_show_page_icon_enforces_the_token(monkeypatch, tmp_path):# ?v= is a content assertion: the correct token yields the bytes; a wrong/empty# token is None (→ 404), so `immutable` caching is honest (URL ⇒ one content).