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.
Show Page Annotation — Phase 1: Default Overlay, Control Surfaces, Authenticated Writes
Status: approved for implementation (owner sign-off 2026-07-20, design frames approved). Owner decisions baked in: snapDOM for capture, "workbench access = logged-in user" auth model, desktop header segmented control (collapsed by default), mobile popup mode picker with last-mode memory.
Summary
The annotation pipeline already exists end to end: show_session_events
persistence, transcript projection (metadata.source = "show_page"), optional
agent dispatch (payload.dispatch: true), SSE streaming, vibe show mark /
vibe show event CLI, and a feature-complete AnnotationOverlay
(smart/screenshot) in @avibe/show-sdk/react. What is missing is the product
surface: nothing mounts the overlay, nothing controls it, screenshot capture
depends on getDisplayMedia (unavailable on iOS), and event writes are
capability-token based rather than identity based.
Phase 1 closes exactly that gap:
- Every Show Page (private and public) automatically gets the annotation overlay via server-side HTML injection — no scaffold changes, old pages included.
- One annotation state machine with four control surfaces: chat header
control, in-page floating toolbar (standalone tabs),
windowAPI, and an agent-driven SSE control event (+ CLI). - Event writes carry an authenticated user identity. Public pages accept writes only from logged-in workbench users.
- Overlay visuals rebuilt to the approved design (design.pen frames
H8oicB,i6HVWm,kn94D,urZTa,WVGjSinavibe-docs/design.pen). - Screenshot capture switches to same-origin DOM rendering (snapDOM) with
getDisplayMediaas a desktop-only fallback.
Non-Goals (Phase 1)
- No screenshot attachment storage; the captured image still travels inside the event payload (Phase 3 moves it to attachments). Cap capture size (long edge ≤ 2048 px) to bound payload growth.
- No rich chat card rendering for
show_pagemessages (Phase 3). - No overlay theming; the overlay ships a self-contained fixed dark floating style (mint/violet accents) that works over light and dark pages.
- No freeze-mode entry point, no multiple screenshot drafts.
- The legacy
AgentationTogglein the main workbench UI stays untouched. - No role hierarchy; identity is recorded to make future roles possible.
Architecture
┌────────────────────────────────────────────┐
Chat header ────┤ postMessage: avibe:annotation:control/state │
(embedded host) └────────────────────────────────────────────┘
│ same-origin iframe
▼
Show Page HTML ── injected <script module> bootstrap ── mounts AnnotationOverlay
▲ (separate React root,
vibe show annotate ── SSE ───┘ portal to body)
(system.annotation.control)
- Injection point (avibe):
vibe/ui_server.pyalready injects the__AVIBE_SHOW__config script into private Show Page HTML (_inject_show_runtime_config). Phase 1 extends this to also inject a<script type="module">tag loading the runtime-served annotation bootstrap, and performs the same injection on public/p/HTML (config withoutwriteToken). - Bootstrap module (vibe-show-runtime): the runtime dev server exposes a
session-independent entry (e.g.
__show/annotation.jsresolved as a Vite virtual module / vendor asset) that imports the SDK overlay and mounts it in its own React root appended todocument.body. It must not touch the user app's module graph beyond sharing the runtime-managed React instance, and it must never crash the host page (top-level try/catch, bail silently). - Host detection (overlay, runtime side):
location.searchcontainsvibe-embed=1→embeddedhost (chat iframe): floating toolbar hidden, mode pill shown, controlled via postMessage. Otherwisestandalone: floating FAB/toolbar shown (bottom-right), full local control. - Auth-aware UI: overlay asks
GET <basePath>__show/me; whencanAnnotateis false (anonymous public visitor) the FAB stays hidden.
Frozen Interface Contracts
Field names below are frozen. Deviations route through the orchestrator, never lane-to-lane.
1. Injected config (extends existing __AVIBE_SHOW__)
globalThis.__AVIBE_SHOW__ = {
sessionId: string,
basePath: string,
eventsPath: string, // unchanged
streamPath: string, // unchanged
writeToken?: string, // private pages only (unchanged)
annotation: {
authenticated: boolean, // server-known auth state at render time
mePath: string, // "__show/me" relative to basePath
}
}
2. Overlay window API (runtime/SDK)
__AVIBE_SHOW__.annotation.api = {
enable(mode?: "smart" | "screenshot"): void, // no mode → last-used (localStorage), default "smart"
disable(): void,
setMode(mode: "smart" | "screenshot"): void,
getState(): { enabled: boolean; mode: "smart" | "screenshot"; available: boolean },
subscribe(cb: (s: ReturnType<typeof getState>) => void): () => void,
}
Mode memory: localStorage key avibe:annotation-mode:<sessionId>.
3. postMessage protocol (same-origin, chat parent ↔ iframe)
// parent → iframe
{ type: "avibe:annotation:control", action: "enable" | "disable" | "set-mode", mode?: "smart" | "screenshot" }
{ type: "avibe:annotation:query" }
// iframe → parent (on mount, on every state change, and in reply to query)
{ type: "avibe:annotation:state", enabled: boolean, mode: "smart" | "screenshot", available: boolean }
enable without mode uses the remembered mode. available:false means the
overlay is mounted but writes are not possible (anonymous public visitor).
4. Agent control event (SSE) + CLI
New event type accepted by the pipeline: system.annotation.control
(actor system), payload:
{ action: "enable" | "disable" | "set-mode", mode?: "smart" | "screenshot" }
- No transcript projection (
transcript_textempty ⇒ no chat message). - Never dispatches an agent turn.
- Reaches the page through the existing
show.eventSSE stream; the overlay subscribes and applies it in both hosts. - CLI:
vibe show annotate [--session-id <id>] (--on | --off | --mode smart|screenshot)→ posts this event via the existing CLI show-event path.--on --mode Xis one event withaction:"enable", mode:"X".
5. Authenticated writes
- Every accepted human event write records the author into the event payload and message metadata:
payload.author = { kind: "user" | "local", email?: string }
Remote (avibe.bot OAuth session): { kind: "user", email } — the email from
the validated OAuth session. Local LAN / same-machine (no OAuth configured):
{ kind: "local" }.
Contract note (revised 2026-07-20 after Lane A finding): role hierarchy
(owner/member/…) is a control-plane concept that does not exist on the
device today — the OAuth session carries only email/sub/instance_id,
and no role claim is issued anywhere. Recording the stable email IS the
forward-compatibility hook: a future role system maps emails to roles at
read time; stored events never need rewriting. Do not invent a role at
write time.
- Private
/show/<sid>/__show/eventsPOST: unchanged token requirement (X-Vibe-Show-Token), now additionally recordsauthor. - Public
/p/<share>/__show/eventsPOST (revised 2026-07-20 v2 after the Lane A security finding — all public shares are same-origin, so a cookie + static custom header can be forged by any same-origin page script against any other share). Requirements, all three:- a valid workbench OAuth session (unchanged), AND
X-Vibe-Show-Tokencarrying the share-scoped write token issued byGET /p/<share>/__show/me(see below) — an HMAC bound to this share, distinct from the private session token, AND- a
Refererwhose path starts with/p/<share>/; missing or mismatched →403 public_show_events_origin_mismatch. Anonymous / no-session →403 public_show_events_login_required. TheX-Vibe-Show-Clientheader requirement is DROPPED (superseded by the token).
- New endpoint on both surfaces:
GET <basePath>__show/me→{ authenticated: boolean, canAnnotate: boolean, writeToken?: string }.writeTokenis present iffcanAnnotateis true: on the public surface it is the share-scoped token above; on the private surface it equals the session write token (uniform overlay logic: injected token ?? me.writeToken). Anonymous GET is allowed and returnsfalse/falsewithout a token. - GET/stream visibility is unchanged (public stays redacted read-only).
- Accepted residual risk (recorded, not fixed in Phase 1): pages under
one origin are one browser trust domain — a page could
window.opena sibling page and drive its DOM/overlay. This matches the existing same-origin Show Page trust model (issue #577 decision: all page content is authored by this machine's agent). Revisit with origin isolation only if third-party-authored content ever becomes renderable.
6. Chat iframe host marker
The workbench chat appends vibe-embed=1 to the Show Page iframe src query
string. No other component may repurpose this parameter.
7. Bootstrap asset path
The injected tag is exactly
<script type="module" src="{basePath}__show/annotation.js"></script>.
Lane A guarantees __show/annotation.js is NOT treated as an events/API path
and proxies through to the runtime on both /show/ and /p/ surfaces (public
surface uses the same immutable-safe serving as other runtime assets). Lane R
guarantees the runtime serves a JS module at
/sessions/<sessionId>/app/__show/annotation.js for every session workspace,
including pre-existing ones.
Lane Split
Three lanes, mutually exclusive file scopes. Contracts above are the only coupling; no lane-to-lane negotiation.
Lane R — vibe-show-runtime (overlay, bootstrap, capture)
Scope: packages/sdk/**, packages/runtime/**, examples/** (optional demo),
docs touched only for README pointers. Do not touch packages/ui (SDK must not
depend on the UI package — CONTRIBUTING boundary).
- Visual rebuild of
AnnotationOverlay+CommentPopover+ markers to the approved design: dark floating chrome (#11111Csurfaces, mint#5BFFA0human accents, violet#7C5BFFagent accents), anchor chip + intent chips (评论/修改/疑问/批准 ⇒ intentcomment|change|question|approve), severity accents, numbered markers (user mint / resolved gray / agent violet bot), screenshot region chrome (dim masks, corner handles, numbered items, batch card), mode pill, mobile bottom-sheet comment card (touch targets ≥ 44 px), standalone FAB ⇄ pill-toolbar. Self-contained styles; no external CSS deps. - Host modes:
embedded(hide toolbar, show pill, obey postMessage) vsstandalone(FAB + toolbar) pervibe-embed=1detection. - Control plane: window API (contract §2), postMessage listener/broadcaster
(§3), SSE
system.annotation.controlhandling (§4), mode memory (localStorage key in §2), auth gating via__show/me(§5 v2) — hide FAB / show "login required" hint whencanAnnotateis false. Write token resolution is uniform: injected__AVIBE_SHOW__.writeToken??me.writeToken; every event POST sends it viaX-Vibe-Show-Tokenon both surfaces. - Bootstrap entry served by the runtime (contract "Bootstrap module"): mounts overlay automatically, resilient to user-page errors, no scaffold edits, works for existing session workspaces.
- Capture: add
@zumer/snapdomas a runtime-managed dependency, lazy-loaded on first screenshot-mode activation. Strategy: snapDOM same-origin DOM render (crop to region, long edge ≤ 2048) → fallbackgetDisplayMedia(desktop only) → error message. Keep the existing payload shape. - Tests:
npm run checkgreen; unit tests for control plane state machine, mode memory, host detection, and capture strategy selection (mock snapdom).
Lane A — avibe backend (injection, auth, control event, CLI)
Scope: vibe/ui_server.py, vibe/cli.py, vibe/i18n/**, core/show_pages.py,
core/show_session_events.py, storage/** (only if a migration is truly
needed — prefer payload-level author, no schema change), tests/**,
docs/plans/ updates. Do not touch ui/**.
- Extend HTML injection: annotation bootstrap
<script module>on private and public Show Page HTML; config gainsannotationblock (§1); public config carries nowriteToken. GET __show/meon both surfaces (§5 v2), including the share-scopedwriteTokenissuance whencanAnnotateis true.- Public events POST (§5 v2): OAuth session + share-scoped
X-Vibe-Show-Token+ Referer path-prefix check. Anonymous →public_show_events_login_required; missing/mismatched Referer →public_show_events_origin_mismatch; bad token →show_event_write_forbidden. Author recording on all accepted writes; private POST: author recording added. - New event type
system.annotation.control(§4): accepted, persisted, SSE-published, empty transcript, never dispatched. - CLI
vibe show annotate(§4) following existingvibe show markpatterns (session resolution,--json, live-UI post path). - Tests: extend
tests/test_show_pages*.py/test_show_session_events.py/test_ui_show_pages.pypatterns — injection on both surfaces, me endpoint matrix, anonymous vs logged-in public POST, author recording, control event no-transcript/no-dispatch, CLI arg handling.ruff checkon touched files.
Lane C — avibe chat UI (header control, bridge)
Scope: ui/src/** only (ChatPage, new components under
ui/src/components/workbench/, ui/src/i18n/en.json, ui/src/i18n/zh.json).
Do not touch vibe/**, core/**, tests/**.
- Header annotation control, visible only in Show Page mode, placed left of
the back-to-chat button (design frames
H8oicB/kn94D):- Desktop: collapsed = one 28 px icon button (
message-square-plus); active = segmented group (toggle + Smart + 截图) with mint accent. - Mobile (
mdbreakpoint down): single button opening a Popover (existinguiprimitive) per frameWVGjS: Smart / 截图 radio rows + "关闭标注" row; button itself toggles on with remembered mode.
- Desktop: collapsed = one 28 px icon button (
- postMessage bridge to the iframe (§3): send control, receive state, keep
button/segment state in sync, disable control until first
state(availablegating + tooltip when unavailable). - Append
vibe-embed=1to the iframe src (§6). - Reuse
ui/src/components/ui/primitives (Button, Popover, Tooltip …); all strings through i18n (en + zh). - Validation:
cd ui && npm run buildgreen; nosetStatein effect bodies (UI CI gate).
Sequencing & Integration
- All three lanes start in parallel; contracts are frozen by this document.
- Each lane: own worktree under
.worktrees/<repo>/<branch>/, branch from the repo default branch (avibe: master,vibe-show-runtime: main), non-draft PR, Codex review loop to zero unresolved threads, CI green. Lanes do not merge; the orchestrator gates and merges. - Merge order: R (runtime main) → A → C (A/C independent; R first so the bootstrap asset exists for regression source builds).
- End-to-end verification by the orchestrator in the local Incus regression environment (locally built runtime archive) against the acceptance list below.
Acceptance Criteria
- Chat visual mode (private page): header control enables Smart → click an
element → comment card → send → message appears in the chat transcript
(
source: show_page, author recorded) and triggers an agent reply streamed back; screenshot mode captures without any screen-share prompt. - Same flows on iPhone-class viewport: popover mode picker, bottom-sheet
comment card, snapDOM capture works (no
getDisplayMediadependency). - Standalone tab (
/show/<sid>/direct): FAB → toolbar controls everything; same event flows. vibe show annotate --on --mode screenshotflips the live page into screenshot mode;--offexits; no chat message is produced by control events.- Public
/p/<share>/: anonymous — markers/read-only visible, no compose affordance, POST rejected (public_show_events_login_required); after logging into the workbench in the same browser — annotation works and the recorded author identity matches the logged-in email. Negative cases: a POST replaying the OAuth cookie against a DIFFERENT share (wrong share-scoped token or wrong Referer path) is rejected (show_event_write_forbidden/public_show_events_origin_mismatch). - Esc exits annotation mode; while active, page controls do not fire; after disable, the page behaves exactly as before injection.
- Gates: runtime
npm run check; aviberuff check+ focused pytest;ui npm run build; Codex review clean on every PR.
References
- Design:
avibe-docs/design.penframesH8oicB(chat smart),i6HVWm(chat screenshot),kn94D(components & rules),urZTa(mobile sheet),WVGjS(mobile mode popup). - Existing pipeline:
core/show_session_events.py,vibe/ui_server.py(§ show events / show page serving),avibe/docs/plans/show-session-event-pipeline.md. - SDK inventory:
vibe-show-runtime/packages/sdk/src/{index.ts,react.tsx}, roadmapvibe-show-runtime/docs/agent-os-implementation-plan.md(this phase completes M6/M8.5 mounting + M12 auth posture). - Capture: snapDOM (
@zumer/snapdom), chosen 2026-07-20 (~42 KB gzip, zero deps; iOS Safari lacksgetDisplayMedia).