# Resources and operation preview

Resources lists every target a conversation uses, by type. One chat preview follows the target the viewed branch operated on last. Agent-opened Pages stay in the background and add no top tabs.

Related: [Session resources](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/resources/session-resources.html), [Resource panel and preview interaction](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/resources/resource-panel-preview-plan.html), [Browser control surfaces](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/browser-control-surfaces.html), [Agent control overlay](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/agent-control-overlay.html).

## Actions on a resource

| Action | Preview | Page and tabs |
| --- | --- | --- |
| Click a row | Shows the target in chat. Auto or Fixed preview is unchanged. | Current tab stays |
| Preview in conversation (icon) | Same as a row click; restores a hidden preview. From a webpage in the center, activates the owning session without changing the viewed branch. | Exact existing Page, no top tab |
| Open page | Hides the preview and its reserved space. Returning to the conversation restores it unless the user hid it. | Same Page as an ordinary top tab; repeats reuse it |
| Expand, drag, resize | Same target, new presentation | No copy, no reload; a native application is not raised |
| Close preview (hide) | Stays hidden; later events cannot reopen it. There is no Show preview control. | Page, background work and rows stay; capture stops |
| Close webpage | Unavailable state | Closes the real Page; lists affected references first |

Resources has no Pin control and no search field. Explicitly pinned or user-opened top pages remain ordinary views; migration does not close them.

## Following

- **Scope**: At most one preview per App window. Preferences belong to the viewed conversation and branch, and resource selection never changes that branch.
- **Trigger**: Only host-admitted operation events in that branch, including observe. Opening a resource, status polling or a screenshot does not switch.
- **Auto preview**: The More checkbox *Automatically show what the Agent is using* turns it on and returns to the latest admitted operation. A clicked target stays until the next operated Page replaces it.
- **Fixed preview**: Checkbox off: the current Page stays. The Agent continues and cannot replace it. Not persisted across reloads.
- **Child agents**: A parent follows its own and its child executions in host dispatch order, naming the active agent. A child window follows only its branch.
- **Changing branch**: Restores that branch's preference; a new one follows its latest target, its unavailable state, or an empty state. Other branches keep running but cannot replace the preview.
- **Closed target**: Clears Operating and shows unavailable or last frame until a newer admitted operation or a new selection. It never falls back to an older resource.
- **Other branch's resource**: Inspecting neither checks that branch out nor grants write access.

**App windows, terminals and applications**

Every kind the Agent uses shows in the same chat preview, with the web page preview's frame, gestures and header: drag, resize, dock, Open in tab, More (Auto preview, Show actions) and Close preview. Open in tab shows the same object in a tab of its own, never a copy.

| Kind | Moves the preview | Inside the preview | Open in tab |
| --- | --- | --- | --- |
| Another app's window | A function result naming `window` (`window_id`, `pid`, `app_name`); a GUI step in an agentic subprocess is forwarded to the worker and attributed to the owning conversation | In the desktop App, the live window fitted to the preview, without moving or resizing it; pointer, wheel and keys go to the window where the platform allows (see [Embedded windows](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/desktop/embedded-windows.html)). Elsewhere, the screenshot the Agent last took, kept in memory per conversation and served at `/api/session/{id}/native-window/frame`. | A window tab holding that window; an existing tab for it is focused |
| Terminal | Starting to run or receiving input | The terminal's screen; typing goes to it while it runs | A terminal tab bound to that terminal; closing the tab leaves the terminal running |
| Built-in application | An open, observe or act on an application instance (`application.used`) | The application instance itself, as in its tab | The application's tab for that instance |

Pinning keeps only Pages. A window shown in a tab can be handed to the Agent by naming it with `@` in the composer, which writes its title, the target `app` and its `window_id` into the message.

## Target types

| Target | Background and preview | Human entry | Limits |
| --- | --- | --- | --- |
| Browser Page | Exact Page/CDP target with its document, login and navigation state; previewing does not activate it | The live tab: readable, scrollable, interactive | Closed pages, lost ownership and stale frames stop writes. Reopening a URL is a new resource. |
| Native application window | Exact process and window; capture and verified background input where available. Shows Background control, Preview only or Foreground required. | The original application, even when background automation is unsupported | Background control of every application is not promised. Minimized, locked, missing permission and uncertain identity each explain themselves. Raising needs explicit selection. |
| Host desktop | A display and its coordinates; no input environment independent of the user | The real keyboard and mouse | Global input can affect the user's work. Never labelled background control. Layout changes invalidate coordinates. |
| VM display | Guest display and input without a foreground host console; VM, guest session and display service must run | OpenProgram guest console or an authorized VNC/RDP console | Missing session, locked guest or lost display have explicit states. Reconnecting never replays uncertain input. Docker is optional. |
| External browser, read-only stream | Needs a verified tab binding; matching URLs do not identify a tab | Open in original browser, View only, Reconnect required or Closed | Screenshots are never input surfaces. Recreating a target is separate. |

**Popups of a Page**

| Aspect | Rule |
| --- | --- |
| Agent Page's popup | Loads in the background, registers under the opener's conversation, branch and execution (`webtab_popup`) |
| Telling the Agent | Listed in the result of the action that opened it; the Agent operates it by its tab id |
| Following | Switches only when an operation targets it |
| User Page's popup | Opens in front and is not adopted |
| Desktop | Builds the popup's Page on the WebContents Chromium created, so `window.opener` keeps working |

## Live page and human use

| Rule | Behaviour |
| --- | --- |
| Exclusive surfaces | A Page shows as the live tab or the chat preview, never both: one native `WebContentsView` cannot occupy two rectangles. No screenshot beside or over the Page, no dimming, no blocking layer. |
| Preview image | Read-only: never forwards clicks, keys or scrolling. Never cropped or zoomed to enlarge it. |
| Human use | Clicking, typing, scrolling and navigating in the real page reach the page directly and do not pause the Agent. Only the task's Pause and Stop do. |
| Old observations | A page the human changed, hover included, invalidates the Agent's earlier observation; it observes again before acting. |
| Not claimed | Zero overlap: dispatched operations may not be retractable, and late results are recorded and observed again. Human changes are not undone. |

| Internal state | Toolbar and preview text |
| --- | --- |
| `active`, `yielding`, `stop_unconfirmed` | Active while the conversation runs, otherwise Ready to use |
| `paused`, `idle`, `closed` | Ready to use |
| `waiting` | Needs your confirmation, with Review request |
| `unknown` | No text while the state is read again |

A stop request unacknowledged for 5 seconds becomes `stop_unconfirmed`; new Agent dispatch stays closed. That timeout does not prove stopping.

**Preview chrome**

- One row that never wraps, at the 240px minimum, the 300×198.75 default (300×168.75 image plus header) and the 720px expanded width: ellipsized title, status, Open page (Open in tab for other kinds), More, Close preview.
- Show actions and Operation history are in More.
- Failure text is reachable through the status indicator, title tooltip and `aria-live`.
- Resizes from four edges and four corners.
- On narrow product layouts a Resources drawer selects the target while chat and preview stay reachable.

**Capture and geometry**

- A never-shown Page starts with a 1920×1080 CSS-pixel viewport at normal page zoom. Preview bounds and layout zoom follow the preview size. A Page returned to the background keeps its last native bounds.
- Desktop preview is the native Page with live rendering, including while dragged. Plain-browser previews use a separate sandboxed iframe, under browser embedding limits.
- Only the visible preview subscribes to frames. Each frame carries resource ID, connection generation, sequence and capture time; frames from an old binding are rejected.
- Delayed or failed capture is labelled Last frame, with its age; no image shows No frame.
- Drag caches container bounds on pointer down and moves by transform on animation frames, without layout reads or state writes. Pointer up, cancel or lost capture writes one clamped position. Unmount, live-loss or a resource switch discards the drag.
- Capture pauses during a drag. A capture begun before the pause is discarded, and only one capture is ever in flight.
- Rapid target changes coalesce over about 200ms and render only the latest frame.

## Operation cues

| Cue | Rule |
| --- | --- |
| Where | OpenProgram surfaces only: hosted webpage frame and toolbar, guest console, preview layer. Foreign applications, the host desktop and external VNC/RDP clients are never decorated. |
| Edge | On the visible surface: subtle 1px outer glow, blue for Active, no glow otherwise. No dimming, layout or hit-area change, no flashing. |
| Markers | Rings for clicks, paths for drags, arrows for scrolling; typing names the field without secrets; shortcuts as text. The user's cursor never moves. Reduced motion uses brief static marks. |
| Show actions | On by default, most recent action only. Hides markers, not edges, execution or history. |
| Operation history | Click, type, scroll, drag, navigation and verification, in order, from trusted host receipts: attempted, dispatched, acknowledged, failed, unknown. |
| Coordinates | Bound to resource ID, generation, frame and viewport mapping, with content bounds, DPR, zoom, scroll and iframe offsets. Stale geometry removes live markers; history keeps old-frame labels. Without a precise point: element bounds or text. |
| Layer | Host-owned, `pointer-events:none`; nothing injected into external pages. Yielding clears markers; late receipts go to history only. |

## Ownership and concurrency

- **Descriptor**: Resource ID, type, sanitized target, actual owner, lifecycle, connection generation, preview capability. Handles and leases stay in the host and are not restorable.
- **Association**: Originating invocation, branch, child agent, sharing mode, keyed on stable branch identity or verifiable fork lineage. Forking does not duplicate external page state.
- **Identity**: Distinct Pages with one URL stay distinct; rows for one actual Page merge. Titles and secret query values never establish ownership, and secret query parameters are not stored.
- **Child agents**: Listed under the originating parent branch with their actual owner. Later work cannot rewrite provenance, and a shared group grants no access.
- **Branch writes**: Ancestor resources show Referenced from. A browser write defaults to an independent Page, without claiming site or login isolation. Native windows and VMs need explicit transfer or another target.
- **Write leases**: Exclude conflicts at the input scope. A second writer gets `busy`, with no queueing or preemption. A child's lease ends with it; the parent does not inherit it.
- **Events**: Carry session, branch, resource, generation and monotonic sequence. Stale ones are discarded after branch change, reconnection or revocation.
- **Legacy records**: Without provable branch ownership they sit in Unassigned, with no guessed migration.

## Lifetime and closing

| Event | Effect |
| --- | --- |
| Task completes | Python, input leases and temporary observations are released. Pages and VMs stay idle; declared temporary resources follow their policy. |
| Disconnect window | Never quits the application, user-opened or agent-opened. Quit application is separate. |
| Disconnect VM | Releases transport; guest and display keep running. Stop VM is separate and never follows from hiding. |
| Remove reference | Detaches an idle association only |
| Closing a used target | Shows affected executions, requests stopping, waits for lease release. Until confirmed it stays Stopping. Closed records collapse into an unavailable group, outside default counts. |
| Disconnect, revocation | Last frame marked stale, remote input off. Unknown identity stops writes and clears Operating. Reconnection is read-only and only to a verifiable identical instance. |
| App restart | Restores grouping and preview preferences, never remote input connections or write leases. Page crash and VM reboot need identity validation. |
| Failed native focus or result check | Input failed: writes revoked, evidence kept, no background retry |
| Legacy adapter | Executing, operation state unverified; no operating dot |
| Memory pressure | Offers explicit release; forms and VMs are never silently dropped |

Operating runs from validated adapter dispatch to receipt, confirmed cancellation or failure. Idle targets keep their connection without high-frequency capture; host applications are not scanned.

**List and row appearance**

- Files, Activity and Resources stay the vertical navigation at the top of the right sidebar. No bordered card per resource.
- Group headings reuse the left sidebar's SectionHeader: 14px secondary text, a 16px chevron after the title, count as trailing action; Enter or Space folds that group only.
- Rows are about 44–48px: title, then type, state and child-agent name when needed. Long titles truncate; details show full title, sanitized origin and identity.
- Operating and selection are distinct, with text as well as colour.
- Webpage rows have three Lucide icon buttons: Preview in conversation, Open in tab, Close webpage (24px target, 14px glyph, PiP toolbar treatment).

**Later review and learning**

- Existing receipts hold task, branch, resource, before and after observation, target, parameters, order, outcome and human corrections. Visible cues use the same source.
- With user approval a later task may read selected sanitized excerpts to analyze targeting errors or propose reusable rules.
- Record my next demonstration is a separate opt-in with explicit start, stop, scope, preview and deletion. Secret fields, passwords, secure input and credential-bearing URLs are never kept.
- Images persist only after permission and redaction checks; otherwise only content-free metadata stays.
- Task-local review, saved steps and model training are separate stages. Nothing trains or uploads automatically; proposed rules are validated on independent test targets.

## Tool activity in the conversation

A `computer_use` call appears in the timeline by target and step: application and action, an action on the screen, Page action and URL, or code run on a target; a target on another machine carries the machine's name, and Chrome and Edge their own.

Calls from the earlier GUI tools (`gui_agent`, `computer_use`, `browser_use`, `vm_use`) open the Details panel with a GUI activity card above the raw parameters and output.

| Part | Content |
| --- | --- |
| Outcome | Running, Action applied, Succeeded, Failed, Needs takeover, Cancelled, Interrupted, Paused or Result unavailable, shared by card and timeline. Replaces the transport Status badge. No explicit status: Result unavailable. |
| Takeover | Recorded blocker and user action emphasized; a summary repeating them is omitted. Task text only in raw parameters. |
| Steps | Capability, target, status, in recorded order; failed and stopped steps add a two-line reason. Taken from result history, or while running from visible capability children without nested planner calls. A direct capability call has no step list. |
| Ownership | A detail carries its conversation id and never replaces one from another conversation with the same call path. A failed output fetch shows its error without failing the call. |
| Screenshots | Not offered: capture paths are temporary and outside the readable attachment roots. |

## Implementation status

| Part | Status |
| --- | --- |
| In place | Type grouping, click-to-preview, Preview in conversation, Auto and Fixed preview, closing semantics, exclusive surfaces, native window frames, edge cues, Show actions, receipt history |
| Planned: joint display | A webpage tab and its small chat preview shown together, in sync on one Page |
| Planned: adapters | Native application and VM control, each advertised only after real-target acceptance; zero-overlap automatic takeover |
| Planned: learning | Demonstration recording, trace review |

**Acceptance cases**

- One branch opens five pages: no extra top tabs, all listed, operations select the preview. Preview in conversation on a never-opened Page adds no tab and enters Fixed preview.
- Two branches and their children run concurrently: provenance kept, no rebinding.
- Inspecting A while the Agent operates B: A stays, B shows Operating, enabling automatic display returns to B, tab focus never moves.
- Close preview, resizing and group collapse neither reload pages, stop VMs, grant control nor destroy targets.
- Closing an active target, revocation, late frames, restart and disconnection have explicit states; unconfirmed stopping is not a confirmed pause.
- Opening a tab fills the content area; undimmed content stays interactive and focus alone does not pause.
- Markers never intercept input or draw from stale geometry.
- Same-process windows, concurrent user input and two VMs verify conflict scopes independently. Successful capture does not establish background input.

Sources: `session-resources-panel.tsx`, `session-resources.ts`, `use-session-resources.ts`, `web-tab-pip-store.ts`, `web-tab-pane.tsx`, `web-tab-pip.tsx`, `desktop-bridge.ts`, `openprogram/host/resources/session.py`, `apps/desktop/main.js`.
