Skip to content

Architecture

Introduction

Ocman is a single Go binary that serves a React SPA and acts as a control plane for coding-agent sessions. The main diagrams cover the system context (what ocman talks to), the backend composition (the Go packages), the session/event data flow, frontend composition, and plugin action flow. Detail lives in the text below each diagram. Session and event data flow and Conversation history and session identity expand on the core data paths, and feature-specific designs live on their feature pages.

Usage collection describes opt-out daily installation reporting, distinct from user-configured diagnostic OpenTelemetry.

    flowchart LR
    UI[Foreground UI time] --> Analytics[analytics credit]
    Analytics --> Reporter[usagecollection worker]
    Settings[Privacy settings] --> Reporter
    Reporter -->|ID, UTC day, release version| Relay[relay /v1/usage]
    Relay --> Forwarder[usageforward OTLP logs]
    Forwarder --> Backend[Operator OTEL backend]
  
  • internal/usagecollection owns the local ID, daily acknowledgement, pending date and opt-out setting. It reads no conversation or account data.
  • internal/usagewire bounds and validates the three-field report.
  • internal/relay rate-limits requests and forwards usage and separate IP security events through internal/usageforward, without local usage storage. The OTEL backend owns distinct-installation queries, access and retention.

Named platform connections describes owner-local persistence, setup, startup composition and connection-scoped session routing.

New conversations persist an application draft and accepted first prompt before native setup. The same Ocman ID stays in the route and sidebar when the owner binds a native execution. The session/event flow describes asynchronous setup, delivery receipts and held follow-ups.

1. System context

Everything external that the ocman process touches.

    flowchart LR
    Browser[Browser SPA<br/>REST + SSE] --> Ocman[ocman<br/>Go binary :8228<br/>embedded public assets]
    Agent[Local MCP clients] -->|/mcp| Ocman
    Ocman -->|HTTP/SSE or CLI protocols| Platforms[Local OpenCode, Claude Code<br/>and opt-in Codex]
    Platforms --> Native[(Native databases,<br/>transcripts and rollouts)]
    Native -->|owner-local ingestion| Ocman
    Ocman --> Stores[(state.db + state_conv.db<br/>runtime state, encrypted secrets and history)]
    Ocman <-->|startup migration and setting reads/writes| Config[config.yaml<br/>declarative settings and secret references]
    Ocman -->|owner-routed execution| Tools[git, tmux and host tools]
    Browser -->|virtual one-off project or Option+O, then normal draft| Ocman
    Browser -->|Activity resources and durable<br/>session background-count reads| Ocman
    Ocman <-->|supervised NDJSON,<br/>UI bundles, scoped sessions and tool callbacks| Plugins[Trusted native plugins]
    Plugins -.->|standard asset/read: inert SVG icons| Ocman
    Ocman -->|bounded HTTP + Web Push| Services[Forge, preview, reviewer<br/>and notification services]
    Ocman <-->|authenticated gRPC:<br/>sessions, PR workflows, tasks and resource streams| Remotes[Remote ocman instances]
    Ocman -->|encrypted shares + webhook poll| Relay[ocman-relay]
    Ocman -.->|optional OTLP| Otel[Telemetry collector]
  
  • MCP session creation resolves hidden per-call caller context from the local session catalogue, separately from destination routing. OpenCode supplies native request metadata; managed Claude and Codex sessions use session-specific MCP headers. Indexed identity reads avoid conversation scans and runtime probes. Unproven context blocks creation. See MCP caller provenance .

  • Plugin-owned session tools. The session broker pins deny-all permissions with one MCP dispatcher exception. Short-lived bindings route bounded tool calls back to the owning plugin, rechecking grants before dispatch. Plugin code owns validation and operation semantics. See session tools .

  • Plugin agent tools. Approved tool.v1 plugins declare tools that the plugins module mirrors into the shared MCP server before each list and call. Built-in tools win name collisions. Each call is validated against the declared schema, authorized under the plugin lifecycle lock and rechecked on return. Consent requests are held in memory and decided only in the browser, in a card under the tool call or in Settings. Tools are owner-local. See plugin agent tools and ADR 0012.

  • Prepared source sessions. Plugins may prepare source under their private model workspace and request a read-only session with the separately approved session.source grant. The owner resolves a contained subpath and pins exact file-read permissions before creation and prompt delivery. Approved plugins can follow up on their latest completed turn through the same session queue, with durable admission receipts and unchanged permissions. Queued follow-ups persist a preserve-selections policy so delivery does not apply project model defaults or provider fallthrough. Other tools remain denied. Creation receipts, platforms and the completion outbox are reused; the host does not interpret the source or its output schema.

  • Configuration. internal/configfile owns the versioned YAML document, comment-preserving atomic edits and provider-based secret resolution. internal/app applies startup options before CLI parsing; internal/state migrates allowlisted settings once and routes existing setting APIs to the file while preserving old database rows as a backup. Canonical adapters pass an effective archive-policy loader to the compact sidebar reader, so local and remote views do not use the retained preference. Encrypted ocman-managed secret slots and their stable key remain owner-local database state; external credentials are never copied there. Dedicated feature tables still need provisioning adapters. See configuration file .

  • Browser SPA. The only UI. It talks REST/SSE to the hub, never to remotes directly. :8228 is the production -addr default; in dev the Vite server on :8228 proxies /api to the air backend on :8229. Embedded content-hashed /assets/ files use immutable caching; HTML, client-route fallbacks and stable /plugin-shared/ entries revalidate. The optional Caddy proxy compresses only public asset GET/HEAD requests, leaving API, SSE, signed resources and relay responses outside that scope. Beta-setting and sidebar-draft periodic reads pause while hidden and reconcile on visibility return, focus and page-resume signals without overlapping reads. Draft persistence and cross-tab subscriptions stay active. Message-link safety scans existing content once, then coalesces added subtrees rather than rescanning the historical thread. The composer accepts text and attachments. Voice input belongs to external tools; ocman does not capture microphones or provide transcription endpoints. Answer read-aloud uses browser speech synthesis independently. Hub-local plugins may add in-app UI: the SPA imports their checksum-verified bundle from /api/plugins/ui/bundle, and the bundle shares the SPA’s React, router, query client and @ocman/plugin-ui through /plugin-shared/ entries (ADR 0009). Optional plugin navigation icons are metadata. Built-in names use the bundled Bootstrap font. SVG reads use the standard no-grant asset/read method over supervised NDJSON and authenticated owner routing. The host validates bounded inert geometry before serving it; the SPA uses an image-backed currentColor mask, never inline plugin SVG. See plugins .

  • One-off sessions. The virtual one-off project choice and Option+O allocate a private temporary directory through POST /api/sessions/one-off and the explicitly selected hostsvc.Host. Remote allocation uses the authenticated Call RPC and fails closed when disconnected. The browser opens a normal durable draft in that directory; no project selection, Git initialization or agent launch happens during allocation. Archiving does not remove its files. The operating system may clean temporary directories, so move files elsewhere to keep them. See one-off sessions .

  • Owner-local background work. prworkflow routes session PR operations through the resolved Platform’s optional PullRequestWorkflow interface. The session owner stores links, polls the forge and queues updates; the hub reads watch counts by platform for session completion indicators. Composer counters use GET /api/session/{id}/pull-requests?background=true for an owner-local database-only read, without forge refreshes or the sweep mutex. Each link exposes a derived backgroundTask flag using the sidebar’s lifecycle: active watch or an undelivered update for a nonterminal PR, counted once. Native task counts still come from the conversation stream. Details distinguish watching from queued delivery; private prompt content stays hidden. Legacy hub links transfer with durable import receipts before polling, preserving checkpoints and preventing retries from resurrecting owner-deleted links. Watch readiness and queue delivery resolve saved native-kind references to the session’s recorded owner/source connection, never the current default. taskmod aggregates read-only tasksvc.Reader observations through the owning Host’s optional BackgroundTaskHost interface. Remote RPCs expose only closed PR operations and task reads, never arbitrary HTTP forwarding or task submission. See multi-remote .

  • Live process resources. The navigation’s Activity modal combines existing background tasks with a resource viewer. resourcemod resolves the owning hostsvc.Host and reads its optional ResourceViewer interface. The local host samples ps CPU-time deltas and resident memory for ocman’s descendants, the dedicated agent and browser-terminal tmux trees and the registered OpenCode service. Executable names, full command lines, PIDs and parent PIDs are returned. resourcemod matches explicit session identity arguments against the owning machine’s canonical session catalogue; ambiguous, unknown or purged bindings have no link. Child processes inherit a known parent’s session association, title and directory-derived project name. Managed worktree directories fold back to the project root before deriving its name. Samples are request-driven, shared for 750 ms and retained in memory for up to 60 points, including each process’s CPU and memory for stacked area graphs. Missing process samples and collection gaps remain blank; isolated samples render as dots, not fabricated full-width areas. Selecting an area or process isolates its graphs and pins its current row; selection, sorting and the flat/tree toggle are URL-backed. Tree mode keeps parents above children and sorts siblings; missing parents become roots and cyclic ancestry is broken so every sampled process appears once. Background tasks use a stable five-group table with URL-backed pagination, status filters and selection. A selected group’s adjacent panel holds progress, counters, schedules and recent run details, stacking below the table on phones. The Resources tab polls once per second only while mounted and the document is visible. A URL-backed machine selector, shown when remotes are configured, sends an explicit remoteId; switching machines clears its project, session and process filters. Remote hosts forward the read through the closed Resources RPC to the owner’s local sampler, and the hub links sessions against its catalogue for that owner. Disconnected remotes, and older owners without the RPC, return 503 rather than falling back.

  • Remote published resources. Transcript embeds and artifact links retain their session owner. Authenticated /api/remote-resources/<owner>/… reads resolve the owning Host’s optional published-resource seam and stream over gRPC. A closed route allowlist permits artifact metadata/files and signed-file refresh only; remote cookies and arbitrary HTTP routes never cross it. File signatures are checked on the owner, with inert/interactive CSP and range semantics preserved. Disconnected owners fail closed.

  • Conversation PR previews. The backend caches metadata by viewer, owner and resource; cards for that resource share updates in the browser. Merged cards stop background revalidation, but their per-card refresh still works. The browser bundles simultaneous lookups by owner, deduplicates identical requests, and cancels a shared request only after its last reader leaves. /api/previews/resolve accepts up to 32 lookups per batch with independent results. Provider calls still use bounded concurrency, grant budgets and backoff. GitHub also retains its credential-scoped request budget; batching browser requests does not bypass GitHub’s limits or turn REST reads into one upstream call. Other provider metadata keeps its normal cache. If a remote owner is disconnected, its visible cards share a temporary /api/previews/availability probe against ocman only. Once connected, each waiting card can retry once through the normal provider budget and backoff.

  • Public web pages. The hub reads Open Graph metadata on delayed markdown link hover and proxies preview images. Provider-specific cards take priority.

  • Browser push services. Opt-in device subscriptions receive encrypted Web Push alerts even with the page closed. The browser service worker displays session-context notifications and opens an owner-qualified session route on click.

  • Telemetry collector. Optional OTLP/HTTP export of traces, metrics, and batched Logrus logs through internal/telemetry. Logs retain structured fields and span context, console output stays enabled, and shutdown flushes all three signals. The bundled LGTM stack routes logs to Loki. SQLite handles opened after startup explicitly disables telemetry use the unwrapped driver. Callers supplying their own OTel providers before startup retain instrumentation. Enabled SQL instrumentation caches immutable fingerprints and summaries in a bounded 256-entry cache, without caching statements longer than 4 KiB.

  • UI usage. Authenticated browsers send active foreground intervals once a minute and on focus/visibility changes. The hub unions overlapping tabs and devices in one state.db transaction, retains two minutes of deduplication history, and stores UTC daily totals. Newly committed seconds increment ocman.ui.active_time through the existing OTel exporter without client or date attributes. Dashboard graphs read SQLite, so collector outages cannot erase their history. Five minutes without interaction stops counting; long timer gaps do not count sleep. This is installation-wide, not named-user data.

  • opencode.db. Foreign data, opened read-only. Ocman never writes it. Ocman requires OpenCode v2. Each connection gets TEMP views named session, message and part over v2’s session_v2/session_message tables, so every query keeps its v1-shaped SQL (internal/db/v2views.go). A database OpenCode has not migrated yet is read through its physical v1 tables.

  • state.db. Ocman’s own state: archive flags, routines and run history, permission approval provenance, live session commit observations, settings, Factory records, Inbox items, artifact metadata, remote tokens, and canonical session identity bindings. Artifact file bytes sit beside it in a SHA-256 content-addressed artifacts/blobs/ directory. Inbox sends are owner-local and persist until recalled or archived by the user. Permission Inbox routing resolves named connections separately from the stable notification namespace. Legacy workflow_* rows remain inert for manual recovery.

  • state_conv.db. internal/statev2 owns a separate conversation schema with immutable platform-instance identities, historical sessions/messages/parts, ingestion checkpoints and a change outbox. Storage, ingestion and historical reads are always enabled; development targets in the Makefile use isolated paths. The file sits beside state.db unless -conversations-db or OCMAN_CONVERSATIONS_DB names another path. -statev2-db and OCMAN_STATEV2_DB remain compatibility aliases. Owner-local ingestion supplies settled conversations, project statistics, plugin project-directory evidence, local text search and analytics. Native reads belong to platform ingestion or live execution, never application fallback readers. Agent and model catalogues are live configuration and go through platform capabilities rather than native database queries. The persisted project-list cache lives here too, not in application state. On first use of this filename, startup preserves an adjacent statev2.db through a SQLite-consistent snapshot, retaining the original. A per-path adoption marker in state.db prevents a later explicit reset from importing the retired file again. An existing destination always wins. Source deletion retains history. Supported upgrades apply append-only migrations; unsupported schema versions fail closed and never reset stored history. Stream ingestion classifies display metadata, attention inputs and accounting facts separately. Metadata-only updates copy compact sidebar/analytics fields without rescanning message attention or rebuilding hourly accounting. Missing projections are repaired synchronously; all projection writes, revisions and checkpoints remain in the same FULL-durability transaction. The read-only sidebar reader exposes the ready-catalogue nonempty native-ID invariant to SQLite’s partial binding index for live/prompt joins. Eligibility stays before pagination; browsing never runs ANALYZE or maintains statistics. Database-size analytics include this store as a separate conversation-history series, including while its initial import is pending.

  • Application analytics and background token/cost metrics use validated statev2 snapshots. Startup no longer creates or syncs analytics-cache.db; existing cache files are unused and left untouched. Database-size sampling measures Ocman’s state and conversation stores plus the local platforms that advertise StorageSizer, as described below.

  • Claude Code (-platforms claudecode). Ocman reads the transcripts under ~/.claude/projects (or $CLAUDE_CONFIG_DIR) into the disposable claude-index.db beside state.db and drives sessions it starts or adopts by spawning the user’s own claude binary with pipes (stream-json and the control protocol), so every call runs under the user’s own account. Ocman installs or refreshes its hook plugin at startup with claude plugin. History hooks journal transcript changes in every session; status hooks run ocman only for the injected OCMAN_MANAGED=1 marker. Hooks have a 1 s timeout and always exit 0. Sending to an external root session records ownership and resumes its transcript through its project supervisor. Owner observations are shared as advisory files under claude-external beside state.db; they produce non-blocking session warnings, not admission locks. See Claude Code .

  • Codex (-platforms codex, opt-in). A separate read-only app-server supplies native history and catalogs for ingestion. A machine-wide tmux supervisor hosts another app-server for live thread operations; it starts on first use. Only rollout token accounting reads native files. Execution uses the user’s own Codex login. Browsing uses retained history after ingestion, just like other platforms. See Codex .

  • Provider usage. /provider-usage asks enabled platform adapters for their account and quota windows. Codex reads its installed app-server; Claude reads its own CLI account and observed rate-limit events. OpenCode V2 reads its own Go allowances and Console budgets through the running service’s /api/experimental/usage/limits, including spent and remaining USD. Unsupported versions omit the account. Unavailable apps report unavailable; Ocman never reads provider credentials or falls back to another platform’s login. Each connection has at most one live-usage refresh in flight, and its result is fresh for one minute. The request waits at most one second for the batch, then returns the last successful snapshots or an unavailable status for connections without a snapshot. refreshedAt records when it was fetched. Refreshes can complete after the response; failures leave cached usage intact. Removed platforms disappear immediately. The browser receives usage, not credentials or workspace IDs. An analytics worker also probes each enabled local platform at startup and every five minutes, independent of the dashboard and telemetry. Fresh normalized account snapshots are stored in the analytics-owned subscription_usage_samples table in state.db, one row per platform and five-minute bucket for the latest 30 days. Older complete UTC hours keep only their latest actual snapshot indefinitely, without averaging across resets. Each response identifies the resolution of its samples. Failed probes retain only their status, not error details or fabricated zero usage. Unsupported platforms and remote adapters are skipped. /api/provider-usage/history?days=7 is localhost-only and accepts 1 to 365 days, or 0 for all history. The page’s History view plots quota and budget utilization, with gaps at failures, unreported metrics, resets, plan changes and extended downtime. Analytics → Models uses the same history endpoint for seven-day subscription limit graphs. The current-usage page, popover and account settings retain their progress indicators. History is per platform on this machine, not a cumulative token estimate. /api/provider-usage also reads the analytics-owned provider_usage ledger in state.db. The server injects a recorder into auto-approve so keyed requests to TypeSafe’s hosted System One API retain only model, timestamp, token counts and estimated USD. The page shows a rolling seven-day local estimate at the documented Jev 1.13/1.14 input price, not account-wide billing. Unknown prices or missing counts stay unpriced, not zero. Other apps and pre-update requests cannot be backfilled. The TypeSafe lookup shares the response budget; a failed lookup does not prevent platform usage from being returned. Old records expire on the next recorded request. Provider tokens and account identifiers never reach the browser. The old /subscription-usage page path remains an alias for bookmarks.

  • Custom reviewer APIs. internal/autoapprove can send permission judgments directly to a user-configured OpenAI-compatible chat-completions or TypeSafe-compatible System One endpoint instead of a temporary OpenCode session. The endpoint’s own Bearer key stays in this instance’s state.db and is never returned by settings reads. These calls use a separate HTTP client from OpenCode authentication, reject redirects, bound response sizes, and fall through to human review on failures. TypeSafe requests separate environment facts, retained user messages, and untrusted tool input. Named Noul probabilities feed a Go rule evaluator with hard-deny precedence and soft-deny exceptions or exact consent. Missing context or failed history reads require human review before sending any endpoint request, with a specific context failure reason. Stored user prose is scanned without a message-count cutoff. A 32,000-byte window keeps the newest text for oversized histories and explicitly marks omissions. Limited-context reviews may grant approval under the same rules; their explanations warn that earlier instructions may be omitted. Jev bypasses command-cache reuse and rechecks context before approval. Each authorization read awaits a bounded session-specific ingestion refresh receipt. A full-history digest detects changes outside the submitted window; missing ingestion or refresh failure cannot reuse retained consent. Other endpoint verdicts retain their configuration-scoped cache. Jev approval records are context-bound, so worktree inheritance does not turn them into standing allow rules. Existing approvals retain their previous behavior.

        flowchart LR
        Call[Pending tool call] --> Rules[Static and manual rules]
        History[Freshness receipt<br/>and stored user prose] --> Context[Context and byte-budget check]
        Rules --> Context
        Context -->|Complete or explicitly windowed| Jev[Named Noul questions]
        Context -->|Unavailable| Human[Human review with reason]
        Jev --> Policy[Go precedence evaluator]
        Policy --> Check[Recheck current context]
        Check --> Decision[Approve once<br/>or human review]
      
  • Native plugin executables. Startup and explicit rescans describe direct executables from the local plugin directory. Each describe has a fresh token, minimal environment, bounded output, and a fifteen-second deadline. Duplicate identities conflict; changed binaries lose approval. Discovery itself executes trusted code. Grants minimize brokered context, not operating-system access. ui.v1 plugins stream an approved browser bundle over the same NDJSON connection; the hub serves it only for its own installations. See Plugins for installation and operations.

  • Remote ocman instances. The hub dials remotes over gRPC and re-exposes their sessions and hosts transparently. Unary JSON operations share one generic Call RPC dispatched by method name on the owner; typed RPCs remain for the handshake, typed session reads and streams. The owning remote enriches session detail with its persisted approvals and tees synthetic approval events into the gRPC event stream before the hub forwards them to the browser. Plugin catalog, management, health, actions and artifact reads use the same authenticated connection. Each machine discovers its own binaries and stores its own configuration and secrets. The hub never installs remote binaries. A remote started with -remote-managed instead uses the auto-approve settings the hub sends over Call on connect and after each change. It stores them in state.db as a separate layer above its own values.

  • Project identity. Each owner enriches its project snapshot with Git fetch remotes inside the existing singleflight refresh. Loaded snapshots return immediately while background discovery runs; inventory projection reuses the enriched rows without running Git. Per-directory discovery also coalesces concurrent callers and caches successful results for five minutes. A failed refresh preserves the previous keys and snapshot and can retry immediately. Credential-free upstream keys normalize SSH and HTTP transport syntax, .git suffixes, host casing and default ports. The hub assigns a shared projectKey to checkouts connected by any common upstream, including chains through a checkout with multiple remotes. /api/projects returns one final project per group, with summed counts and costs, latest activity, and archive state true only when every member is archived. Checkout rows and merge metadata stay private to the backend. The browser resolves its existing session and draft directories through POST /api/projects/resolve, which returns final identities in request order. Project detail includes sessions from every matching host. Actions still target a specific owner and directory. Repositories without network remotes fall back to owner-scoped directories, with the existing worktree folding. Local filesystem remotes never identify cross-host projects. The dashboard’s merge action saves owner-qualified source-checkout to target-checkout mappings in the hub’s state.db setting projects.merges. /api/projects applies it after upstream grouping, resolving the checkouts’ current keys so Git remote changes do not undo saved merges, and uses the selected target checkout for display. Dashboard totals, sidebar groups and project session lists share this identity. Merge chains follow the final target, and a transaction rejects cycles. Upstream memberships and saved checkout edges form connected components, so crossed upstream groups keep all saved merge members together. If a component has multiple saved destinations, the lowest stable checkout key selects its display representative independently of inventory order. Session directories, owners and transcripts stay intact. Successful merges publish ocman.projects.changed so other browsers refresh their project list and identity lookups. Directory scopes filter final projects, not private checkout rows. Archiving a final project updates every member on the backend.

    flowchart LR
    Inventory[Owner project snapshots] --> Catalog[Hub project catalog]
    Merges[(Saved checkout mappings)] --> Catalog
    Catalog -->|GET /api/projects| Projects[Final projects and totals]
    Directories[Session and draft directories] -->|POST /api/projects/resolve| Catalog
    Catalog -->|final identities only| Browser[Selectors and session grouping]
    Projects --> Browser
  

The hub retains checkout membership for merges and archive operations. Neither project response requires the browser to reconstruct upstream or manual merges.

  • Encrypted webhooks. Providers submit plaintext to the relay’s ingestion URL, where ocman encrypts a versioned age X25519 envelope. The envelope format lives in internal/share, which both the relay server and the webhook poller use; the poller never imports the relay server. The relay persists ciphertext plus visible size/timing metadata; the owning local or remote ocman decrypts it, durably accepts it in state.db, claims routine dispatches, then acknowledges the relay. A lost acknowledgment is retried without duplicate scheduling. Successful delivery polls renew the inbox’s 30-day inactivity window, including when empty. Separate plaintext receipt timestamps let the relay expire unacknowledged ciphertext after 48 hours; acknowledgment removes ciphertext and its timestamp immediately.

Relay enrollment

    flowchart LR
    Dashboard[Ocman dashboard] -->|start and poll connection| Owner[Owner-local webhook module]
    Owner -->|private polling credential| Relay[Relay relayauth]
    Dashboard -->|open sign-in link| Browser[Relay sign-in page]
    Browser -->|choose provider and sign in| Relay
    Relay -->|OAuth code and PKCE| Identity[Configured GitHub or Google apps]
    Relay -->|hashed user and credential| Store[Relay disk store]
    Relay -->|enrollment token, once| Owner
    Owner -->|token and relay binding| State[Owner state.db or configured secret storage]
  

internal/relayauth owns the relay’s configurable provider list, short-lived connection requests, browser-bound OAuth state and PKCE, automatic enrollment after successful sign-in, credential hashing, expiry, revocation and sign-in rate limits. It does not retain provider access tokens. internal/relay accepts either these credentials or the operator’s legacy enrollment token when registering an inbox. internal/webhook starts and polls enrollment through owner-local guarded routes and persists the returned credential with its relay binding. The dashboard sees only the sign-in link, expiry and connection status, never the polling or enrollment token. Relay SSO providers do not depend on the owner’s coding-tool accounts or link-preview grants.

Remotes advertise enabled local platform ids in Hello. The hub registers one adapter per platform under r-<instanceId>:<platform>, sharing one host adapter and connection. Older remotes without the list remain OpenCode-only. Duplicate instance ids are rejected for the whole remote, even when the advertised platforms differ.

Browser resource boundaries

    flowchart LR
    Policy[httpx browser policy] --> Hub[Hub dashboard]
    Policy --> Relay[Relay viewer]
    Hub -->|local and embedded images| Gallery[Native image gallery]
    Hub -->|per-image user consent| Wrapper[previews external-image wrapper]
    Wrapper --> Frame[Opaque script-free iframe]
    Frame -->|image requests to one origin only| Image[External image origin]
    Hub -->|owner host and port only| Socket[Ocman WebSocket]
    Relay -->|remote images blocked| Shared[Read-only shared content]
  
  • internal/httpx owns the shared browser CSP and validates URL authorities before adding origin-scoped WebSocket sources. Forwarded headers cannot widen the browser’s connection policy. Hub and relay responses block external images by default; local, data and blob images remain available.
  • internal/previews serves an authenticated, stateless external-image HTML wrapper after frontend consent. It performs no server-side fetch. The frame has no script or same-origin grant, sends no referrer, and its own CSP allows images only from the selected origin. The UI warns about IP/cookie disclosure and does not persist consent. Public shares disable this private-endpoint path.
  • Inert HTML file responses use a separate default-deny CSP, including for external subresources and forms. Interactive artifact previews retain their existing script-only sandbox and documented self-navigation limitation.

Provider account usage

    flowchart LR
    UI[Provider usage] -->|one-second wait| Cache[Live usage cache]
    Cache -->|one refresh per connection| Registry[Enabled platform adapters]
    Cache --> Ledger[Local TypeSafe estimate ledger]
    Analytics[Analytics sampler] --> Registry
    Registry --> Codex[Installed Codex app-server]
    Registry --> Claude[Claude CLI account and observed limits]
    Registry --> OpenCode[OpenCode service usage limits]
    Analytics -->|five-minute snapshots, hourly after 30 days| History[Subscription history in state.db]
    UI -->|History view| HistoryAPI[Local history endpoint]
    Models[Analytics Models graphs] -->|last seven days| HistoryAPI
    HistoryAPI --> History
  

Account reads stay inside each platform integration. The analytics module only normalizes the returned quota windows and budgets; it has no provider tokens or direct provider HTTP clients. Local API estimates remain explicitly separate from account-reported allowances and budgets.

Feature architecture

Feature-specific designs live with their feature documentation:

  • Conversation sharing. Owners seal completed turns and artifact snapshots with AES-256-GCM and publish them to the standalone ocman-relay, which stores only ciphertext; keys stay in URL fragments. See Conversation sharing .
  • Native permissions and ocman review. Native platform approval modes and ocman’s auto-approval judge are separate controls. See Session permissions .
  • Agent-generated results. internal/agentui validates restricted A2UI render_ui results that the browser renders with shared controls; actions only send user-confirmed messages. See MCP .
  • Session PR workflow. sourcecontrol owns forge credentials and prworkflow owns session PR links, feedback drafts and opt-in watches that queue follow-ups. Durable changes invalidate browser PR and task views through the existing owner-qualified session-change SSE channel. Explicit linked-PR refreshes reuse fetched metadata to process active watches immediately on the session owner, without waiting for the periodic sweep. Checks and due feedback are refreshed too; forge rate-limit deadlines still apply. Owner-local invalidations cross the authenticated StreamSessionChanges gRPC stream before the hub publishes them with connection-qualified identity. A newly loaded link missing from its matching project PR list triggers one cache-bypassing list fetch, scoped by owner, forge host and repository. See Pull requests .

Conversation history and session identity

Each owner imports its platforms’ history into state_conv.db through internal/conversationingest and internal/statev2; settled conversations, analytics and the compact sidebar read that retained history, while live execution stays platform-owned. internal/sessioncatalog and internal/platforms/owned give every session a stable ocm_<uuid> identity and keep native IDs behind the adapter boundary. internal/tasksvc reports ingestion and preparation progress as background tasks. See Conversation history and session identity . Scheduled maintenance uses inline, owner-local task observations without consuming bounded execution slots. The Background tasks page shows the latest recurring receipt and next-check hint. See Scheduled maintenance for tracked jobs and excluded internal timers.

2. Backend composition

Archived checkout maintenance belongs to internal/worktreecleanup. Its hourly worker uses persisted archive/activity timestamps, owner-side safety checks and the shared session mutation fence. Dedicated Host/gRPC cleanup and restoration operations retain branches and conversation history. See archived worktree cleanup . Session/terminal directory admission records an owner-scoped directory watermark without reading platform inventories. The sweep and final owner-side removal check apply that watermark under the same fence.

Native safety probes use platforms.WorktreeRuntimeReader through the canonical adapter, separately from startup identity migration. Missing native history or unreachable supervisors block cleanup without changing fresh-install migration. The shared provider transport reads persisted runtime handles from state and checks liveness through ocruntime before omitting an unreadable endpoint. Both attached and persisted supervisors are checked; draining owners block maintenance. Ordinary Codex lifecycle reads retain complete native message identity through the history converter without starting an execution supervisor.

Server shutdown cancels and joins its owned background loops before returning, so closing the databases cannot race a pending refresh.

The Go package graph, collapsed to the seams that matter.

    flowchart TD
    Main[main.go<br/>embedded skills + build version] --> App[internal/app<br/>startup + composition]
    App --> Server
    App --> Registry
    Server[internal/server<br/>HTTP, SSE, handlers] --> Registry[platforms.Registry<br/>session seam]
    Server --> Router[hostsvc.Router<br/>host/dir + runtime seam]
    Server --> AutoApprove[internal/autoapprove<br/>session rules, safe-command cache + Judge seam]
    Browser -->|/permissions: session policy + request history| AutoApprove
    AutoApprove -->|per-permission backend selection| Judge[OpenCode judge, else<br/>claude -p haiku judge]
    Server -->|"modules(): routes, Start, Launch, Run, Close, Finalize, tools, Bus"| Modules[feature modules<br/>autoapprove, queuemod, factorymod, pluginsmod, routines, sessiontitles, webhook, artifacts, inbox, sharing, notifications, snooze, favorites, projectsmod, autoarchive, tmuxmod, filesystem, projectforge, previews, analytics, termmod, gitmod, remotesmod, platformsettings]
    Modules --> Lifecycle[internal/sessionlifecycle<br/>prepare, start + direct actions]
    Lifecycle -->|mutations + first delivery callback| Sessions[internal/sessionsvc<br/>shared agent mutations]
    Modules -->|"queuemod: bounded preparation, then admitted delivery"| Sessions
    Lifecycle -->|creation, streamed attachments, restart + reload| Router
    Server --> Recovery[internal/sessionrecovery<br/>interruption history + replacement fences]
    Recovery -->|owner-local lifecycle reads| Registry
    Recovery --> State
    Modules --> Routines[internal/routines<br/>saved prompts + schedules<br/>fixed or launch-time project]
    Server -->|injects project catalog + owner/account selection| Routines
    Modules -->|"factorymod: routes, tools, launchers, control sessions"| Factory[internal/factory<br/>YAML workflows + Issue dispatch]
    Factory --> FactoryModel[internal/factory/model<br/>shared persistence records]
    Factory -->|graph + action Inbox reconciliation| State
    State --> FactoryModel
    Factory --> Registry
    Factory --> Router
    Factory -->|Project Delivery validation + merge observation| Forge
    Routines --> Registry
    Routines --> Router
    Modules -->|"tmuxmod, termmod, gitmod, worktreecleanup: host operations"| Router
    Routines --> State
    Server --> MCP[internal/mcp<br/>MCP tools]
    Modules -->|module tools| MCP
    Modules --> Inbox[internal/inbox<br/>state + owner routing]
    Modules -->|notifications: subscriptions + durable delivery receipts| State
    Modules -->|snooze: archive deadlines + atomic wake-up| State
    MCP --> Registry
    MCP -->|agent envelope via existing-session direct send| Sessions
    MCP -->|creator provenance before first prompt| State
    State -->|creator reference on REST and MCP detail reads| MCP
    State -->|batched creator links for sidebar nesting| Browser
    Registry --> OC[platforms/opencode/provider + internal/db<br/>adapter and read-only queries]
    Registry --> ClaudePlatform[platforms/claude/transport<br/>native-session runtime bindings]
    ClaudePlatform --> Provider[platforms/provider<br/>per-instance socket adapter]
    Provider -->|providerprotocol: HTTP + SSE over unix socket, leased snapshot + replay| Supervisor[providersupervisor<br/>sequenced spool, ack, drain]
    Local -.->|ocruntime.BackendRuntime in tmux, one per project| Supervisor
    Modules -->|idleprojects: idle timeout through hostsvc.IdleProjectRuntime| ClaudePlatform
    Supervisor --> Claude[platforms/claude/provider + launch<br/>index, converter, SDK-compatible claude children]
    Registry --> CodexPlatform[platforms/codex/transport<br/>machine-wide supervisor + history app-server]
    CodexPlatform -->|execute and drain idle owners| Provider
    Supervisor --> Codex[platforms/codex/provider + appserver<br/>ACP execution, native history + converter]
    Registry -->|SessionEventSink: status + idle| Server
    Modules -->|Factory + routine usage via platforms.UsageReader| OC
    Modules -->|"analytics: Stats/Usage reads, size samples, OTel gauges"| OC
    Registry -->|session detail, summary, lifecycle + usage reads| RP[internal/remote<br/>platform adapter + owner RPCs]
    Router --> Local[hostsvc/local + composerattachments<br/>host operations, canonical roots + attachments]
    Browser -->|semantic host capabilities| Server
    Browser -->|platform settings catalog + setup notes| Modules
    Modules -->|platform setup: local-only check/install| Router
    Router -->|streamed attachment writes on owner| RP
    Server --> State[internal/state<br/>state.db]
    Modules --> HistoryImport[internal/conversationingest<br/>owner-local import + repairs]
    HistoryImport --> HistoryStore[internal/statev2<br/>state_conv.db]
    Inbox --> State
    Inbox -.->|remote RPC| Router
    Server --> Forge[forge + integrations<br/>GitHub/Forgejo clients]
    Modules -->|"projectforge: PR/issue lists, checks, handle via owner Host"| Forge
    Modules -->|"previews: forge credentials only (Deps.Forges)"| Forge
    State -.->|registration types| Plugins[sdk/protocol<br/>protocol, supervision, capability brokers]
    Modules -->|"pluginsmod: routes, supervision, conversation + session outboxes"| Plugins
    Plugins -->|token-bound NDJSON + private configuration fd| PluginExec[External plugin process]
    Modules -->|owner-routed PluginOperation RPC| RP
    Modules -->|"remotesmod: /api/remotes CRUD, remote-access settings, inventory loop"| RP
    PluginSDK[sdk/plugin<br/>public Go SDK module] -->|canonical DTO aliases + validators| Plugins
  
  • MCP session sends retain an agent-message envelope in native history through the normal owner-routed send path. The browser displays these as agent messages without treating the envelope as authentication or user authority. See MCP .

  • MCP session creation saves a platform- and machine-scoped creator reference in the serving instance’s state.db before first delivery, for both worktree and regular launches. This application provenance can cross projects and is independent of native subagent hierarchy, permissions and lifecycle. REST and MCP detail reads expose this serving-instance provenance as an optional creator reference without changing native parentId or the tree. Compact sidebar reads batch creator references for the returned rows. The browser uses these links only for display nesting and filtering, preserving native ancestry and keeping independent sessions as full nested cards.

  • internal/app. Application startup owns flags, database selection, authentication, logging, platform registration and HTTP/desktop composition. It disables the OpenCode platform when the installed binary is older than v2. The root entrypoint only supplies embedded skills and the build version. internal/gui links Wails only under the gui build tag, which make build-desktop and wails.json pass; headless builds reject -gui.

  • platforms/claude/transport. The Claude adapter composes the browsing and per-project supervisors, routes session operations by native session ID, and recovers/drains project runtimes. Creation chooses a project runtime; after binding, SSE, sends and prompt replies use the same session-to-supervisor association, even when the working directory changes. Recovery discovers active native IDs from process-owned status, never shared transcript listings, and rejects conflicting active claims or incomplete discovery. Failed probes permit recovery only when an independent check proves the tracked supervisor is dead. Local deadlines never authorize fallback execution. Verified corrections persist under the shared ownership lock without changing session metadata, so restarts keep the corrected association. Correcting a binding ends that session’s old stream so it reconnects. Its constructor receives skills and the MCP address explicitly. Provider and hook subcommands live in the same module.

  • platforms/opencode/provider. Creation or a successful native-ID probe pins the session’s runtime port. Reconstruction checks the native session identity before using a runtime; directory metadata alone cannot select an SSE or mutation target. Both platforms retain the owner/source-scoped Ocman-to-native mapping in platforms/owned; a project change never allocates another identity.

  • platforms/codex. platforms/codex/appserver is a JSON-RPC client for codex app-server over stdio. It reads history, catalogs and the account, sets titles and refuses server requests. An in-process fake lives in appserver/codextest. platforms/codex/provider converts Codex thread items into v1 messages and parts through one converter shared by stored and live items. Its supervisor drives a shared installed codex-acp process through platforms/acp by default. Native app-server connections supply history and account metadata and persist title changes. They never resume ACP-owned threads for execution. ACP chunks preserve native item IDs, seed the native reply group and reconcile the final stored turn and rollout accounting before idle. Approvals and scoped form questions use Ocman’s prompt lifecycle; their resolution is spooled before the ACP callback returns. Steering opts into promptRequired, preventing an idle steer from starting an untracked turn. Failed events and terminal writes retain admission until durable publication recovers. codex/transport still registers the opt-in codex platform, launches its machine-wide supervisor through ocruntime.BackendRuntime and reattaches after dashboard restarts. Browsing uses a separate native reader and never starts execution. All paths share the captured canonical Codex home; CODEX_PATH selects the same CLI. Adapter executable, home, CLI, backend identity and MCP listener form the supervisor launch identity. Changing them drains and replaces it while prompt replies and abort remain routed to the old supervisor. ACP offers no raw shell, fork-at-message or native loaded-writer probe. Those capabilities are disabled, not implemented through a second native writer. Native execution routes, notifications and loaded-writer recovery have been removed. Other owners, including older Ocman supervisors, are never stopped. Adapter errors never trigger native execution fallback or automatic prompt replay.

  • internal/server. The HTTP mux, SSE broadcast and fanout, around 60 handler files, plus tmux launcher and terminal host wiring. Its session paths (SSE tee, notify, permission replies) still drive the auto-approve pipeline. It is the composition root for feature modules.

  • Feature modules (internal/module). Auto-approve (internal/autoapprove: per-session toggle, approved-permission notices, judge settings, judge-delay seed and the headless watcher), follow-up delivery (internal/queuemod: queue routes, native inbox coordination, idle flush and sweep workers, model quota cooldown, continuation notices and fallthrough settings), Factory (internal/factorymod), plugins (internal/pluginsmod), the /api/tmux controls (internal/tmuxmod: sessions and launches through the owner’s hostsvc.Host, client list and switch on this machine’s tmux), the browser terminals (internal/termmod: window controls and the WebSocket bridge, attached through the owner’s hostsvc.Host), remote management (internal/remotesmod: /api/remotes CRUD + reconnect, this instance’s /api/settings/remote-access status and token reveal, and the inventory refresh loop among the joined workers; the remote.Manager, its gRPC transport and Start/Stop, the registry, the host router and owner resolution stay core), routines, webhooks, artifacts, the Inbox, conversation sharing and read-only file browsing (internal/filesystem: directory picker, signed /api/file/ embeds, owner-routed repository file reads), link previews (internal/previews: /api/previews/*, link rules and sign-in apps; it sees the hub forge clients only as credentials through Deps.Forges, and app access through Deps.Access), git and worktrees (internal/gitmod: status, branches, checkout, diffs and worktree list/base ref/remove/create-and-launch through the owner’s hostsvc.Host; permission inheritance and the first send are injected server paths) each own their routes, background loops, MCP tools and event subscriptions. The server lists them once in modules() and hands each narrow Deps (store, guards, lookups); modules never import the server or each other. Webhooks dispatch to routines through an interface. Modules are built once on first use via the server’s generic lazy[T] field. Sharing and Factory’s dispatch wake-up react to the typed, synchronous module.Bus SessionIdle event. sessionsvc publishes FirstPromptAdded once after a new conversation’s first successful input. sessiontitles handles it only on the owning machine: Claude’s adapter runs a tool-free, non-persisted Haiku helper, then a guarded rename updates the title without adding a turn or overwriting a manual name. The server launches Factory once the MCP listener is up, because its sessions verify their ocman MCP connection, and closes it after the HTTP and MCP listeners stop. Analytics (internal/analytics) owns the Stats/Usage endpoints, UI-usage recording, provider usage and its cost ledger, and the database-size sampler, stats gauges and LLM-turn scanner, all joined in its Run. Accounting reads use statev2 projections through internal/db. The session snapshot, client-activity demand leases, /api/system/stats and the server’s own OTel instruments stay in core.

  • Platform settings (internal/platformsettings). The backend catalog supplies selectable platform IDs, labels and setup eligibility. Setup notes and install commands come from hostsvc.PlatformSetup; the browser renders these without platform identity checks. Host flags gate worktree launches, judge model selection and MCP configuration. Remote capability exchange retains the opencodeLaunch alias for sessionLaunch on the current protocol. Selecting Codex in Settings first checks prerequisites through the local host’s optional hostsvc.PlatformSetupManager. Localhost-guarded setup/install routes delegate to hostsvc/local; only an explicit install POST runs the fixed pinned adapter command, with a timeout, bounded output and serialized installation. The modal rechecks on dismissal and enables the toggle only when prerequisites pass. Settings saves the local startup selection in state.db. Application startup reads it before opening the OpenCode database or registering adapters; an explicit -platforms flag takes precedence. Saving fences new local turns while active turns, pending prompts and existing queues drain. internal/app.reloadBackend then rebuilds the backend on the same address and process, including databases, analytics and prompt watchers. The desktop window stays open; browser SSE reconnection refreshes capabilities and session data. HTTP/SSE and inbound gRPC contexts belong to that composition; listener cleanup is joined before its databases close. Explicit or generated OpenCode credentials are resolved once per process and reused by every replacement composition. Claude’s platforms.ReloadIdleReader checks project supervisors independently of best-effort browsing, including persisted supervisors still recovering.

  • Idle projects (internal/idleprojects). An owner-local module holds the configurable idle timeout and minute sweep. It checks archive state, live sessions, queued messages, and active background work before calling hostsvc.IdleProjectRuntime on the provider adapter. Membership uses the launch resolver, including arbitrary linked worktrees and subdirectories. Deleted session directories use historical identity in the existing claude-sessions.json ownership snapshot; unmanaged retained transcripts cannot disable cleanup for unrelated projects. Only Claude supervisors are stopped. OpenCode’s server is machine-wide, so it is excluded. Claude fences new turns with /drain-idle before stopping its supervisor. Token-scoped rollback and recovery preserve replacement drains if cleanup is cancelled. Routine dispatch already ensures its runtime before creating or reusing a session, so future schedules do not keep idle projects running.

  • Snooze (internal/snooze). Owns POST /api/session/snooze and a joined minute-interval worker that wakes expired conversations immediately on startup and during operation. Validation and SSE broadcasting are injected from core. Archive rows, snooze deadlines and auto-archive protection remain in internal/state, shared with manual archive and unarchive operations.

  • Favorites (internal/favorites). Owns /api/favorites, the per-platform favorite models. The platform registry check is injected from core; the model_favorite rows remain in internal/state.

  • Auto-archive (internal/autoarchive). Owns /api/settings/auto-archive and a joined daily worker, started with the other session consumers, that archives sessions and local projects inactive beyond the configured TTL. A slow platform read is cut off after ten seconds so the project pass still runs; recent unarchives and concurrent snoozes are preserved. Composer upload cleanup is its own joined daily worker (composerattachments.Sweeper).

  • Project forge (internal/projectforge). The PRs & Issues pane: /api/project/{upstreams,prs,issues,pr-checks,pr-mergeability,forge-user, handle} and /api/settings/prompt-templates. Every /api/project/* route takes an explicit owner, resolved by the server’s resolveOwner (503 remote_not_connected for a disconnected remote); the owner’s hostsvc.Host detects upstreams and fetches cross-fork heads, while the hub classifies remotes and calls the forge with its own clients (ResolveForge, KnowsForgejo, read at call time). The module keeps the bounded, collapsed upstream-detection cache and launches through the shared session path on the owner’s compound platform. Prompt templates stay hub-wide settings, not owner-scoped. Project archive and quick settings belong to internal/projectsmod. Session start belongs to internal/sessionlifecycle.

  • Projects (internal/projectsmod). Owns GET /api/projects, POST /api/projects/resolve, POST /api/project/{archive,merge} and /api/project/settings. It lists the local host’s projects plus the remote inventory, applies archive state, worktree folding, upstream keys and saved merges, and builds the final project catalog. Owner resolution, the remote inventory, broadcasts, the default agent and the queue’s project-model cache are injected from core. The projects index loop stays in the server; rows stay in internal/state.

  • Session lifecycle (internal/sessionlifecycle). Owns prepare/start, progress broadcasts, first delivery, attachment uploads, direct mutations, reload and confirmed restart. Preparation reads catalogs without launching; creation validates the owner and backend before launch and applies permission defaults before publication or delivery. Host operations use the owning hostsvc.Host; shared mutations stay in sessionsvc. Direct send is an injected callback, shared with the queue. The server retains list/detail/SSE transport, auth, owner resolution, permission/question audit orchestration and queue/cooldown/idle ordering. Compatibility handler wrappers delegate to the module, whose routes are registered through modules(). Submitted setup can be archived through POST /api/session-drafts/{id}/archive without discarding its payload or stopping its worker. An injected archive callback writes the normal session marker for the stable Ocman ID. Draft reads expose that marker across tabs and reloads. A versioned failure acknowledgement allows an existing delivery error to be dismissed without hiding a later identical error. Archival and durable completion share bounded outcome locks; terminal sessions read their update watermark from the owner rather than borrowing the hub’s clock. Archive resurfacing, including compact local and remote reads, checks setup admission before treating a newly bound idle session as complete; permission and question prompts still resurface immediately.

  • Conversation stream (internal/convstream). Serves GET /api/session/{id}/stream, the Ocman conversation event (OCE) stream from spec/conversation-events/design.md. One Hub keeps one upstream per session for every subscriber, a bounded and compacted replay log with an epoch:seq cursor, and the live overlay that stream.hello restates. It settles idle edges through LifecycleReader, derives waiting and turn edges, and resets slow consumers. It is the only per-session browser stream. Conversation load resilience describes bounded lifecycle and display readers, transactional projection checks, reconnect backoff and pool/work diagnostics. Until native sources exist, its live source runs the owner pipeline: ProxyEvents through the auto-approve tee and sinks, then internal/convevents/v1map. Remote sessions are bridged on the hub from the owner’s forwarded bytes, where the hub also observes git command hints. Sequence admission occurs before mapping, once per source frame. Mapper anchors keep bounded UTF-16 lengths rather than full conversation text. A cursorless refresh is display-only; unpositioned deltas wait for an ordered upstream upsert. Descendant prompts resolve through the owning platform’s metadata, never the hub’s local database. Reconnect seeds invalidate pending settle generations before opening the new epoch, and every browser write/flush has a deadline. Upstream failures are visible even when browser keepalives continue. Every non-resumed hello, including the first, triggers fenced recovery. The browser replaces REST-owned history, preserves the separate stream-owned live content and prompt/task ledger, and replays events received after the request fence. Failed history reads retry with exponential backoff capped at 15 seconds, retaining the recovery fence until success. Authentication and permanent client errors require explicit retry. A busy conversation with no content events for five seconds reconciles history even if transport keepalives continue. Content resets this timer; waiting and terminal states stop it. These repairs only read history, never resend input. Stored history is ingested after the live stream, so the browser-facing hub composes conversation reads; the browser never merges the two by guesswork:

        flowchart LR
        Source[Live source] --> Hub[convstream hub]
        Hub --> Ledger[Unconfirmed ledger]
        Ingest[History ingestion] --> History[(state_conv.db)]
        History -->|commit observer| Owner[Owner stream:<br/>ocman.history.committed]
        Owner --> Hub
        History --> Read[GET /api/session/id]
        Ledger --> Read
        Read -->|snapshot + stream.cursor| Browser
        Hub -->|events after cursor, history.committed| Browser
      
    • The hub’s per-session ledger holds streamed messages and parts that history has not stored. It survives idle edges, source restarts and detaching. A turn’s entries settle at its idle edge, terminal status, an idle reconnect seed, a settled lifecycle read or detach. Stream removals leave tombstones; rewrites discard ended turns.
    • Streamed values are kept once and appended in place, with their UTF-16 length tracked, so a chunk costs constant work. Each ledger caps settled parts and messages by count. All ledgers share a 64 MB budget counting messages and parts: ended message groups go first (confirmed ones, then sessions nobody streams, oldest first). Running turns are evicted only past a hard ceiling of twice the budget. Ten minutes without change is a backstop expiry for content no read confirms.
    • GET /api/session/{id} (newest page) begins a read before querying history, lays the ledger over the stored read and returns stream.cursor, the hub position it covers, and stream.composedMessageIds. Older-history paging offsets count only messages a read returned as stored history. Only the cursor is read under the session lock; merging runs on a ledger capture, and only entries unchanged since the capture are confirmed.
    • A read that stores a settled entry at least as completely, or stores its message as completed, confirms it. History only moves forward, so reads that begin later skip confirmed entries, reads that began earlier still overlay them, and they leave once no earlier read is open. Tombstones clear the same way once a read no longer holds the row, so history can re-add it. No timer is involved. A settled message missing from a read that stores later messages is forgotten, not tombstoned, since ingestion order is not guaranteed. Remote owners return history uncomposed; the hub that streams the session composes it once.
    • statev2.DB.OnCommitted notifies the owner after each commit. Owner session streams forward a coalesced ocman.history.committed synthetic frame, mapped to history.committed, including through remote tunnels.
    • Every browser read replays only the content events after its cursor, so older stream copies never overwrite newer stored metadata. Metadata, child and status events always replay; the read does not compose them. A settled conversation rereads on history.committed, which backfills content the stream missed.
  • Session recovery (internal/sessionrecovery). A workerless service owns interruption history, replacement membership, admission and stop fences, and confirmed-stop reconciliation. Runtime hooks and history reads call it through thin server adapters. Persistence stays in internal/state; callbacks resolve the current local host and platform. OpenCode machine-server replacement uses this service, and every OpenCode session is a member of a replacement; Claude supervisor recovery stays in platforms/claude/transport.

  • autoapprove.Judge. The safe-command cache runs before backend selection. Each uncached permission selects a judge through Deps.SelectJudge, defaulting to the registered OpenCode adapter’s port discovery. When no OpenCode instance is reachable and claudecode is enabled, autoapprove.ClaudeJudge runs claude -p --model haiku with no tools. With neither, an explicit needs-user verdict leaves the prompt unanswered.

  • Session approval rules. /permissions reads request history and edits Ocman-only allow/ask/deny patterns through the auto-approve module. Rules are keyed by platform and session in state.db, apply to native nested subagents, and precede native-mode auto-approvals, cached verdicts and the AI judge. A final reply check serializes with saves so an older judge cannot bypass a newly saved ask/deny. Remote platform adapters forward policy reads and writes to the owner over SessionPermissionPolicy RPC. Rules and rule-based replies never enter native agent settings or worktree permission inheritance.

  • Session summary reads. Pinned sessions outside the recent window use platforms.SummaryReader, served from the statev2 list projection. Remotes return the owner-local row through SessionSummary and stamp its compound platform on the hub. Older owners fall back to session detail. Session-list SSE invalidations trail by 150 ms with a 500 ms maximum wait, finish existing reads before refreshing, and retain one follow-up when another event arrives during the refresh.

  • Factory usage. /api/factory/epics/{id}/usage joins durable attempt identities to platforms.UsageReader. Canonical adapters sum descendant usage from statev2 and reuse token and pricing calculations. The Factory module deduplicates owner-qualified session IDs for Epic phase totals, retains retry history per Attempt, and flags unavailable reads as incomplete. Epic and Queue views poll these totals every ten seconds.

  • Owner-local session usage. Both Factory and routine statistics read platforms.UsageReader. Remote adapters forward to the owner’s SessionUsage operation over the existing token-authenticated connection, returning the owner’s recorded and estimated costs keyed by session ID, including descendants. Owners that answer Unimplemented report usage unsupported without falling back to hub-local sessions. Routine stats retain all-run counts and average duration and refresh billing at most every 30 seconds while their tab is open.

  • Follow-up queue. internal/queuemod owns delivery coordination over internal/queuesvc, which drains one held message per turn. Queueing remains an explicit composer gesture. Native backend inboxes are preferred only when no durable hub backlog exists; uncertain native sends are surfaced without replaying into the hub queue. Direct send and runtime recovery are injected server functions shared with the other session paths. Each decision uses platforms.LifecycleReader for settled status and the latest message identity. The local adapter reads one session and its newest message, without parts, tree or costs. Remotes settle on the owner and return that same bounded DTO through SessionLifecycle. Older owners without the RPC fall back to session detail. A guarded sweep reads lifecycle under the session lock and checks guard generation before reusing that read. Idle-edge flushes still trust the edge regardless of the status read. The server records model-provider cooldown through the module before admitting a flush and publishing module.SessionIdle to ordered bus subscribers. A continuation consumes that edge so held follow-ups wait for its turn to end. Retry resets and notices use compound platform/session identities. The module’s Run stops admission on cancellation and joins accepted sends and the worker dispatcher, allowing durable dequeue receipts to finish before state.db closes. Owner-side cooldown reads run outside the admission mutex with a lifetime-bound deadline. Shutdown joins admitted idle handlers before closing the dispatcher; a cancelled read leaves its queued payload held for recovery. Sweep iteration and pre-send lifecycle/model reads stay cancellable and bounded. Only actual admitted delivery and durable dequeue/failure receipts detach cancellation, so a stalled owner read cannot hold shutdown open indefinitely. sessionsvc.PrepareSendMessage resolves the adapter, model and first-prompt metadata before returning a mutation-only delivery callback. Shared runtime recovery still reads through the preparation lifetime, including before retry. Project model settings and provider cooldown persistence retain their existing state tables; the combined project-defaults route invalidates the module cache.

  • platforms.SessionEventSink. The registry installs status and idle callbacks on lifecycle-producing adapters, including adapters registered later. OpenCode’s watcher feeds the same server callbacks. Adapters update their live view before calling the sink; idle means a completed turn. A limited session carries resetsAt in Unix milliseconds and stays non-idle for queue sweeps, routine completion and plugin replies. The status patch updates the browser’s list and header without a new protocol or polling loop.

  • platforms/provider. The generic adapter negotiates capabilities and protocol versions through /hello. Shared DTOs in internal/providerprotocol define the socket contract. Each adapter owns its session, live-status and pending-prompt caches; WatchEvents replays sequenced v1 events and feeds the shared status and idle sinks even without a browser. Runtime management owns the watch context.

  • providersupervisor / ocruntime.BackendRuntime. A supervisor wraps a platform backend and serves it on a private unix socket. Claude browsing runs inside the ocman process, one per machine. Sessions ocman launches run in ocman provider claudecode, which ocruntime.BackendRuntime hosts in tmux, one per repository root, persisted in managed_provider and re-probed with /hello on recovery, so turns and prompts survive an ocman restart. Out-of-range versions stop new turns through /drain and are replaced only after all sessions settle. Each outbound event is appended and synced to its session spool before publication. The headless watcher acknowledges completed turns; browser snapshots pin replay cursors until their stream attaches, so truncation cannot erase the REST-to-SSE gap.

  • platforms/claude/provider. The claudecode platform’s backend. The in-process browsing supervisor indexes <CLAUDE_CONFIG_DIR or ~/.claude>/projects into the disposable claude-index.db beside state.db (path, mtime and size keys; list projection, per-message byte offsets, subagent links), kept current by directory watches plus a 5 s mtime sweep. Detail pages read only their byte range through the single Claude to v1 converter; subagents are child sessions linked from their Task/Agent part. Sessions ocman launches are driven by pooled claude children in the project supervisors (pipes, cap 20 across the machine, 10 min idle, --resume on the next send) started with --permission-prompt-tool stdio: each can_use_tool becomes a v1 permission.asked/question.asked, decided first by the adapter’s ocman-side provider.Rules store, then by the autoapprove pipeline and the user. Their children initialize before the first prompt and acknowledge model/interrupt controls. internal/platforms/claude/launch supplies the shared Agent SDK environment to sessions and helpers. Their status follows Claude’s foreground session-state and result events, independently of delegated background tasks; terminal sessions use the transcript tail settled by db.SettleSessionStatus.

  • sdk/protocol. External wire DTOs, bounded NDJSON, version negotiation, handshake and stream-order validation, executable discovery, and description validation. It lives in the public github.com/ocman/ocman/sdk module (nested in sdk/, standard library only, tagged sdk/vX.Y.Z); the host imports it directly, so the protocol has a single definition. internal/pluginsmod mounts it: its Start scans once (right after auto-approve seeds the judge delay, before the other modules); RescanPlugins repeats the scan and records identities, checksums, and conflicts in state. Its Run drives the conversation reply pump and reconciliation; the server stops its processes after the listeners and Factory close, before workers are joined. The module supervises one serve process per enabled local plugin from its private data directory, with bounded calls/output, cancellation, restart cutoff and process-group shutdown. Process health is durable; sensitive stderr stays bounded in local memory. Authenticated management routes expose catalog, health, grant approval and revocation, configuration validation/update, restart/retry, and data removal. Mutations and redacted stderr reads require localhost and safe browser origins. Configuration reaches the child on a private inherited descriptor before readiness; failed activation restores the last working public and secret values. Authenticated action list/invoke/download endpoints use the action broker. It filters context by each action’s approved grants, requires host-issued confirmation tokens when declared, and returns only typed results. Grant changes serialize with dispatch and are checked again before results or artifact bytes are returned. See the wire contract . The remote PluginOperation RPC accepts a closed set of host operations, never raw stdio messages. Both transports use the same lifecycle and action broker. Catalog identities are (ownerId, description.id); nested capabilities and instances inherit that owner. Management and artifact endpoints take ownerId. Project-scoped workspace homepages read typed documents for known projects. Plugin-local homepages instead list configurations with one owner-routed read, without enumerating projects. Editors reuse the app project picker for owner-local multi-project fields; plugin responses remain data, never UI code. Action requests distinguish the installation ownerId from context.ownerId. Project/session listings combine the owner’s owner-scoped actions with the hub’s hub-scoped actions. Owner-scoped actions run on the owner; hub-scoped actions run only on the hub. Global placements always resolve to the hub. Explicit disconnected project owners fail closed. Remote secret updates pass through without hub persistence, and responses contain secret presence only. Configuration writes are capped at 1 MiB of canonical JSON; catalog responses are capped at 16 MiB on both transports.

  • sdk/plugin. Optional public Go lifecycle and action helpers reuse the canonical protocol DTOs and validators. sdk/plugin/conformance runs black-box executable tests, including host-broker grant checks. sdk/examples/ocman-plugin-fixture is the deterministic executable used by the supervisor integration tests. Plugins in other languages can implement the same NDJSON contract directly.

  • Plugin persistence. internal/state stores discovered identities, capability instances, enablement, grants, health and public configuration in schema v91. Schema v92 adds operation receipts committed before action dispatch, preventing replay after a host restart even when the original outcome is unknown. Secret snapshots use separate 0600 files beside the configured database; plugin-owned data uses its own directory. Configuration checkpoints restore public values and secret references together. Disable and removal retain data; permanent deletion is explicit. Catalog reads expose secret-presence flags only.

  • internal/factory. The independent Software Factory boundary. It stores Epics, Mols, typed Issues, dependencies, attempts, Formula revisions, Plan revisions, approvals, and materialization provenance in state.db. YAML Formulas declare named steps with prompts, configuration, and needs. They compile to canonical JSON; historical TOML revisions remain readable. Poured steps keep their frozen definitions in factory_workflow_step. Implementation is a group whose required children must succeed before checks or later approvals can proceed. Verification and delivery expand per changed project; dependent steps wait for every project instance of each prerequisite. A Plan session is instructed not to modify files, but its configurable permission rules may allow shell commands for research; approval of an exact revision automatically materializes the proposed Implementation Issues and dependencies atomically. As defined by ADR 0008 , an Epic owns an admitted local project set, each executable Issue targets one project, and each project has an independent shared branch, checkpoint, and Delivery lineage. Ready Issues launch configured worktree sessions in their target project. Each implementation handoff records the clean, pushed commit in its Attempt result; the next Attempt for that project freezes the checkpoint and target branch in its policy. Workflow Project Deliveries follow the declared checks and approvals before publishing each project’s PR. Legacy revisions create deliveries progressively as their required project work completes. Forge observations satisfy merge-gated cross-project dependencies; a recorded merge makes later work create a successor instead of refreshing the Delivery. Delivery retries preserve completed implementation Issues. Each Epic has one read-only control session that receives every new decision Factory needs. Its factory_control MCP tool only records proposals for planning, plan decisions, recovery, permission and project gates, graph mutation, pause, resume, delivery, and stop. The user’s Confirm on the rendered card runs them over REST. Stop aborts workers before atomically cancelling unfinished work and closing the Epic, preserving partial files. Confirmed controls reconcile the action Inbox and retire stale alternatives. Existing control sessions receive new protocol instructions once on their next opening or Factory update. Implementation agents can also pause behind a durable project-admission gate; human REST approval adopts the local project, records execution acknowledgement, and launches an additive scoped Plan, while rejection resumes the same session with feedback. The browser uses REST while agents use MCP. Routines are not involved.

  • Factory persistence. Native factory_* tables own the graph and its provenance in state.db; they do not reference or alter routine tables.

  • internal/factory/model. Dependency-neutral persistence records shared by internal/factory and internal/state. Factory owns their meaning; state only stores them, which avoids making Factory depend on its SQLite adapter.

  • platforms.Registry. The session-scoped seam. One adapter per platform; remotes register as compound-ID platforms so handlers can’t tell local from remote. platforms/identity holds built-in IDs without depending on adapters or databases; the compound-ID helpers and ErrRemoteOffline live in internal/platforms, so modules never import the gRPC client to parse one.

  • hostsvc.Router. The directory-scoped seam (git, worktrees, tmux, projects and forge-repository detection/fetch). It resolves the owning host and delegates, the same transparency trick as the registry. Create requests carry a platform, defaulted from platform.default independently of the model. Routines and Factory Epics persist that choice. EnsureRuntime(ctx, platform, dir) selects the owner’s runtime; adapters can implement hostsvc.RuntimeEnsurer for non-OpenCode runtimes. Optional hostsvc.RuntimeAvailability reports native launch prerequisites separately from browsing. Claude requires its resolved CLI and tmux; missing either leaves transcript browsing available. EnsureRuntimeResult carries an endpoint and an opaque ocruntime.Instance; Port() is empty for non-TCP endpoints. OpenCode worktrees still share one project instance, or the v2 machine server, with a per-session working directory. There is no process per worktree. The old EnsureProjectOpencode gRPC method remains an OpenCode alias for one release. Only tracked instances are reused; persisted entries must pass an API identity probe after restart. The only external instance adopted is OpenCode v2’s registered background service, and only when reading the default database. Ocman authenticates it using the service configuration’s password unless credentials were explicitly configured. Authentication rejection returns an error without launching a competing server; a busy service is awaited. The service is never persisted, stopped or restarted by ocman. The local Host probes the machine runtime at startup and every minute, with a two-second deadline. Inventory reads use the validated in-memory routing map without network probes. Definite failures revoke routing but retain cleanup handles; inconclusive probes preserve warm authorization. Launches and routing changes invalidate discovery immediately through the Host’s RuntimeInventoryChanged hook (internal/tmux knows nothing about the adapter), and stale scans cannot repopulate an invalidated port cache. Discovery state is an opencode.Discovery owned by each OpenCode adapter, so a backend reload’s new adapter starts with no stale ports or affinity. The server joins the health worker before closing databases. RestartProjectOpencode stops and relaunches the tracked instance. Owner-local replacement callbacks use machine-wide membership: replacing the shared OpenCode server affects sessions in every project and worktree, without launching a server or requiring a new RPC. ReloadOpencode requires a readable, matching server-default v2 location directory for managed servers. The registered service uses its registration and credentials instead, since ocman did not choose its launch directory. Reload calls the owning machine’s v2 /api/location/reload endpoint through the same Host/gRPC seam, retaining the process and running turns while refreshing configuration and the owner’s cached catalogs. Pending permission and question prompts are cancelled. Terminal hook installation and removal target the local Host through the optional HookPluginManager seam; hook status events still reach the platform.

  • internal/composerattachments. Owner-local attachment cache storage and seven-day cleanup. HTTP uploads stream through Host.SaveComposerAttachment; remote owners receive a metadata packet followed by bounded byte chunks over gRPC, avoiding the unary message limit. Only the owner writes the file, and its returned path is referenced in the prompt. Interrupted/oversize uploads remove their partial file; multipart bodies are not spooled on the hub.

  • internal/ocruntime. The runtime abstraction behind the managed launch path. A Runtime interface (Launch/Probe/Stop) hides how a project’s opencode is hosted; the native-tmux implementation runs headless opencode serve --port N on tmux -L ocman-agents -f /dev/null, isolated from the user’s tmux server and configuration. One server runs per machine, kept up by RunMachineSupervisor, preferring the registered service on the default database. A managed launch whose health probe stays inconclusive is retained and probed again, not killed. The runtime uses an ocman-allocated loopback port and probes authenticated GET {endpoint}/config for health. It is where the container runtime (epic #375) plugs in as a second implementation.

  • platforms/opencode/apiv2. OpenCode v2 compatibility. ocapi.Auth.Transport wraps every OpenCode HTTP client in ocv2.Wrap. On a machine whose opencode is v2, the wrapper answers v1 routes (sessions, messages, prompts, permissions, questions as v2 forms, catalogs, /event and /global/event) with v2 /api/* calls. The SSE translator re-projects v2’s typed events into v1 message.*/session.* events. ConvertMessage is the single v2→v1 message converter: the HTTP layer, the event translator and internal/db’s TEMP views over session_v2/session_message all use it, so part ids agree everywhere. v1 servers are never probed.

  • platforms/opencode. Wraps the read-only DB queries (internal/db) plus an HTTP client that attaches to managed instances or the registered v2 service. The local Host supplies the tracked runtime inventory after API identity validation; other external processes are never scanned or adopted. One process-wide /global/event stream per instance keeps pending permission and question state in memory across all session directories. The same live stream captures completed bash parts containing Git commit summaries and stores immutable observations in state.db; transcript reads never trigger capture.

  • internal/routines. Validates and stores manual, timeout, one-time and cron routines. Manual and scheduled dispatch share the durable occurrence claim, launch a fresh managed session through hostsvc.Router and sessionsvc, and leave the run active until platform-neutral session status reports success or failure. Startup resumes observation of linked runs. Timeout schedules become an absolute due time when saved. Cron schedules use a five-field expression and IANA timezone. Webhook polling is an independent owner-local/remote delivery loop. Unbound routines resolve a launch-time directory or repository URL against the owning Host’s project index. Canonical keys use the projects module’s final catalog through an injected callback, preserving merge representatives and owner checks. Runs atomically snapshot its directory in the run claim. The dashboard prompts for a project; webhook subscriptions can extract it from a configured JSON pointer. Fixed routine projects cannot be overridden, and webhook targets stay owner-local.

  • internal/notifications. Authenticated, same-origin push subscription routes and joined observation/delivery workers. Slow sends do not stall snapshots; failed or stale owner reads preserve the baseline. It reuses the server’s notification projection, identifies completions by the bounded platform lifecycle read, and persists VAPID keys, subscriptions and delivery receipts under its module schema. webpush-go handles encryption and signing. Known browser push-service hosts are allowlisted, redirects are refused, and transient sends have bounded retries. The page confirms server subscription state before suppressing local alerts. Shared notification snapshots and push payloads update the installed app’s numeric attention badge. Notification routes carry an explicit owner and reveal the conversation even when a mobile overlay was already open. The owner’s ListPermissions RPC annotates cloned prompts with its judge deferral decision, so the hub does not guess remote notification eligibility. See Notifications .

  • Legacy Workflow storage. The workflow_* tables remain in state.db as inert historical data. No API, MCP tool, UI, or scheduler reads them. A DAG cannot be converted losslessly to one routine prompt, so recovery is a manual read-only SQLite export.

  • internal/mcp. The MCP server exposes read-only session inspection, session creation, existing-session messaging and embed_file, plus the tools modules contribute: action-based factory and proposal-only factory_control (Factory), inbox, webhooks, routines and artifacts. File embedding uses signed tokens whose key is persisted in state.db; internal/filesystem mints and serves them. Session messaging resolves the recipient’s canonical identity or unambiguous platform, then uses the shared sendNow and sessionsvc path. It never creates a session or touches the held queue.

  • internal/mcpauth. The dedicated loopback MCP listener (/mcp, /hook) requires a per-install bearer token. mcpauth generates it once, seals it in state.db and publishes it 0600 as <state dir>/mcp-token. OpenCode’s installed entry references that file through {file:...}; the Claude and Codex supervisors and ocman hook read it themselves, so the token never appears in argv, URLs or opencode.json.

  • Inbox. The inbox MCP tool is deliberately limited to help, send, and recall. Sends write the owning host’s state.db; remote sends and recalls cross the owner-routed gRPC seam. The browser alone lists, reads, and archives Inbox state through REST. Messages carry Permission, Factory, Routine, or Primary categories. The headless permission watcher creates owner-local actionable messages even when auto-approval is disabled. Successful replies, including TUI and automatic replies, archive them; a periodic reconciliation handles missed events and aborted requests. Permission replies use the existing session service with an explicit platform, including remote compound IDs. Routine completion writes its notification in the same transaction as the run outcome, and Factory deliveries explicitly use the Factory category. After dispatch, Factory reconciles outstanding human actions into durable, deduplicated Inbox items and archives resolved ones. The browser’s shared Inbox query polls in the background for new Factory actions, displaying in-app toasts and opt-in system notifications without replaying its initial snapshot.

  • internal/opencodeskills. Extracts binary-embedded ocman skills into XDG data and installs only ocman-owned symlinks for OpenCode discovery. Retirement unlinks only the exact verified symlink and preserves extracted data.

  • internal/state. Ocman’s writable SQLite store: migrations, settings, routines and their immutable run snapshots, legacy inert Workflow rows, and the independent native Factory Issue graph. Open runs two batches. The core sequence (schema_version, append-only, v1 onwards) covers every table whose queries live in this package, including the tables of today’s feature modules. Each module’s own tables use a state.ModuleSchema and the module_schema_version (module, version) ledger. The server lists these schemas in ModuleSchemas(). Each batch is transactional and fails closed. An existing database is backed up once per Open before anything changes: module migrations reuse the core batch’s backup when it ran and take their own only when the core schema was already current. A fresh database gets none.

  • forge and integrations. Forge-agnostic types in internal/forge, per-forge HTTP clients in internal/forge/{github,forgejo}. PR/Issue handlers obtain repository identity from the owner Host, then use the hub clients for metadata.

  • internal/previewauth. Machine-level credentials for private link previews. ocman is a personal tool, so every token and grant belongs to the hub machine (one fixed viewer ID, machine, keyed by this instance’s ID), usable by any request with app access (auth cookie, or a direct un-proxied loopback client when auth is off). Personal tokens are pasted in Settings (POST /api/previews/token), checked with the provider’s identify call and stored without expiry; OAuth sign-in (Slack, Jira, or any provider with an app) uses a one-time state, PKCE when supported, one exact redirect URI (<public base>/api/previews/oauth/callback) and same-origin return paths. Client secrets stay server-side; tokens are AES-GCM sealed per owner/provider/workspace with the row key as associated data, refreshed under a per-grant singleflight, and deleted on invalid_grant, a 401 or removal.

  • Preview ownership across remotes. The hub holds every credential and makes every provider call, also for a remote’s sessions; nothing is routed to the remote. An explicit remoteId that is not connected fails closed with a bare 503 before any credential or cache is touched.

  • internal/linkpreview. Normalized previews behind POST /api/previews/resolve (text in, Preview list out; TS mirror in frontend/src/lib/previews.ts). Only configured providers register a Resolver; resolvers recognize known direct URLs and custom link rules carrying a provider (the rule’s replacement link stays the client-side fallback), deduped by resource and capped at 20 per text. Metadata fetches go through linkpreview.API: the resolver’s fixed API hosts, validated path segments, the stored token, no redirects, 1 MiB bodies, 10 s timeouts. Results are cached per owner/provider/workspace/resource with in-flight dedup, 4 concurrent fetches, a 60/min per-grant budget and Retry-After backoff. With several workspaces for one provider the service tries each and returns the first that previews. GET /api/previews/providers is the browser’s whole view: each supported provider, whether it is configured, its link hosts, account display names, and the rule patterns routed to a configured provider. useProviderPreviews only posts text with a link on a configured host or a routed-rule match, so unconfigured links never cost a request. Explicit markdown-link hover requests can also resolve public Open Graph metadata, as described below. Cards carry no connect flow; Settings → Link previews manages tokens and sign-ins, and ocman:preview-auth-changed reloads previews.

  • Open Graph hover previews. Markdown links wait 500 ms on hover or keyboard focus, then resolve through the same endpoint with openGraph: true. A rich provider result wins; otherwise one public HTTP(S) page supplies og:title, og:description, og:site_name and og:image. This explicit fallback requires app access and shares the metadata cache, aggregate fetch budget and concurrency limit. Upstream backoff is origin-scoped and honors bounded Retry-After values. Its credential-free client validates DNS addresses before dialing and on every redirect, rejects private networks and nonstandard ports, and bounds HTML to 1 MiB. Images go through /api/previews/image, with the same address checks, a 2 MiB limit and raster-only responses. The browser never fetches the image host directly. Missing metadata leaves the original link alone.

  • Forge previews (linkpreview.Forge, internal/previews/forges.go). GitHub, every https Forgejo host (tea logins, saved-token hosts and app hosts) and GitLab hosts (gitlab.com, saved-token and app hosts) resolve PR/issue/commit links. A saved token or sign-in wins; without one the resolver is a linkpreview.Fallback with the machine’s env/CLI token (anonymous for GitLab), which previews private repositories for any request with app access (WithOwnerAccess) and public ones otherwise (repository visibility is checked before the resource is read). GitHub/Forgejo PR metadata includes headSha. A resolve request with checksSha accepts exactly one recognized PR URL and a validated SHA, then uses the same forge checks clients as the sidebar with the preview’s selected credential and redirect-disabled HTTP client. These checks calls use the clients’ 8 MiB response bound instead of linkpreview.API’s 1 MiB. The preview service caches checks for 15 seconds and retains its per-grant budget, concurrency limit and rate-limit backoff. Visible unfinished checks poll every 5 seconds with a cache bypass. Explicit refresh reloads PR metadata and bypasses the checks snapshot for its current head while retaining grant and rate controls. Checks HTTP 401 and ordinary 403 retain their status for token revocation and denial classification, and provider retry deadlines reach the backoff. Quota/secondary-limit 403 responses are classified as rate limits instead.

  • Slack previews (linkpreview.Slack, opt-in via OCMAN_SLACK_PREVIEW_CLIENT_ID/_SECRET). A dedicated OAuth app yields a machine-wide user token (user_scope, bot tokens refused); conversation.v1 bot tokens and grants are never used. /archives/{channel}/p{ts} links (plus thread_ts replies) resolve only when auth.test’s workspace URL matches the link host, and channels Slack reports private/DM/MPIM are denied before any message is read. Slack ok:false codes map onto the shared 401 (grant forgotten) / 403 / 404 / 429 handling.

  • Notion previews (linkpreview.Notion, opt-in via OCMAN_NOTION_PREVIEW_CLIENT_ID/_SECRET). A public connection (owner=user, JSON token/revoke bodies with Basic auth) stores one grant per Notion workspace (or an internal integration token, identified via GET /v1/users/me); the shared pages are the whole permission model. Page links on notion.so / notion.com / app.notion.com / *.notion.site resolve by page ID to the API-returned URL; routed ticket identifiers run POST /v1/search and match titles by whole token. Several matches become Choices (state ambiguous), none is not_found. An unshared page is a 404 once the cache expires; a removed connection is a 401 and forgets the grant.

  • Linear previews (linkpreview.Linear, opt-in via OCMAN_LINEAR_PREVIEW_CLIENT_ID). Authorization code + PKCE with the read scope; the rotating refresh token is stored per Linear organization; a personal API key (lin_api_…, sent without Bearer) works without an app. One GraphQL query returns the organization and the issue; a link whose workspace urlKey differs from the grant’s is not_found. GraphQL error codes (AUTHENTICATION_ERROR, FORBIDDEN, RATELIMITED, often on HTTP 400) map onto the shared 401 / 403 / 429 handling.

  • Jira previews (linkpreview.Jira, opt-in via OCMAN_JIRA_PREVIEW_CLIENT_ID). Atlassian 3LO authorization code with read:jira-work read:me offline_access; one grant per Atlassian account (one rotating refresh token spans its sites). Each fetch lists oauth/token/accessible-resources and calls api.atlassian.com/ex/jira/{cloudid} for the site matching the link host, which is never contacted itself. An identifier found on several sites becomes Choices.

  • GitLab previews (linkpreview.GitLab; gitlab.com by default, other hosts once they have a token or an OCMAN_GITLAB_PREVIEW_APPS app). One provider gitlab:<host> per instance (authorization code + PKCE, read_api), so grants never cross instances. Project paths are sent as one %2F-escaped segment (API.WithEncodedSlashes). Public projects preview anonymously after a visibility check; every call dials through a resolve-once, address-checked dialer (no loopback/link-local; no private ranges for gitlab.com).

Platform package dependencies

    flowchart LR
    App[Application] --> Claude[claude/transport]
    App --> OpenCode[opencode/provider]
    App --> CodexT[codex/transport]
    Claude --> Socket[platforms/provider]
    CodexT --> Socket
    Supervisor --> CodexB[codex/provider]
    CodexB --> AppServer[codex/appserver]
    Socket -->|Unix socket| Supervisor[providersupervisor]
    Supervisor --> Backend[claude/provider]
    Backend --> Launch[claude/launch]
    OpenCode --> API[opencode/api]
    OpenCode --> V1[opencode/apiv1]
    API --> V2[opencode/apiv2]
  
  • Platform-specific packages live under internal/platforms/claude, internal/platforms/codex or internal/platforms/opencode. The platform IDs are claudecode, codex and opencode; persisted identities, commands and wire formats are unchanged.
  • Codex’s transport has no per-project routing: one supervisor serves every directory, and its history reads go to Codex directly, not through the socket.
  • Claude’s transport selects the owning backend and retains session routing, runtime recovery and history-ingestion orchestration. The provider owns native child execution and transcript indexing. Shared socket serving and durable event replay stay in the generic protocol packages.
  • OpenCode’s provider uses apiv1 for bounded HTTP operations and error decoding. Shared authentication in api composes the v2 compatibility transport from apiv2. The v2 translator is not a standalone replacement client.
  • Shared runtime operations still go through ocruntime and the owning Host. Native data access supplies ingestion and live execution; application browsing reads continue to use the canonical history store.

Codex uses the shared ACP execution transport inside its existing supervisor:

    flowchart LR
    Executor[codex/provider<br/>ACP execution] --> ACP[platforms/acp]
    ACP --> SDK[coder/acp-go-sdk<br/>JSON-RPC framing + subagent extension]
    SDK -->|stdio| Adapter[Installed codex-acp]
    Adapter --> Writer[Codex execution app-server]
    Executor --> Reader[Native history + title metadata]
    Executor --> Converter[Single Codex converter]
    Reader --> Converter
    Converter --> Spool[Existing supervisor spool]
    ACP -->|verified native child identities + live status| Spool
    ACP -->|available_commands_update| Executor
  
  • platforms/acp launches an explicit executable, negotiates capabilities and supports new/load/resume, prompts and cancellation. It preserves native IDs.
  • Slash-command catalogs stay owner-routed through the Platform. Codex’s existing supervisor caches ACP command announcements, scoped to loaded sessions and their directory; transport merges these with read-only skills without starting execution for browsing. Claude uses an attached supervisor verified against the session’s recorded execution owner to include its session-init command names; shared runtime-directory membership alone never grants ownership. Without an attached owner it uses the browsing probe. OpenCode supplies its command and skill APIs. The composer refreshes on menu open and reserves Ocman built-in names, descriptions and execution over all platform catalogs. Terminal-only commands are not synthesized.
  • Its event callback must finish recording each update before returning. A failed callback disconnects execution; permissions fail closed without a handler.
  • The wire dispatcher retains session/tool fields on form elicitation requests that the SDK’s generated form union omits. Questions cannot borrow another session’s context. Only supported, non-secret form fields reach the UI.
  • Codex negotiates ACP v1 subagent_update notifications. The supervisor decodes the adapter’s child-session wrapper and verifies each native thread’s immediate parent through the read-only app-server before publishing its identity. Native child status enters the existing spool, runtime inventory and canonical sidebar observations. A root turn ending does not settle its children; losing the ACP connection interrupts their live observations. Child permission and question requests use native IDs, and native children cannot be resumed as root sessions.
  • The client does not register a platform, install adapters, ingest history or replace owner routing and supervisor recovery. Codex retains these native integrations; OpenCode and Claude execution are unchanged. Tests use the disposable codex/acptest peer and native history fixture.

3. Session and event data flow

See Session and event data flow for the sequence diagram covering session reads, SSE activity updates, remote streams, and routine dispatch. Sidebar activity updates arrive over global SSE without changing row order. internal/sessionupdates coalesces owner-qualified compact row reads before fan-out; complete row events include durable ordering times and avoid browser sidebar/detail refetches. Older owners and failed compact reads retain invalidation/reconciliation. Sidebar and count reads share committed process-local observations for sparse live state, with indexed SQL retained for dense snapshots and durable facts. See the companion event-flow page for bounds, generation fences and recovery behavior.

    flowchart LR
    Tabs[Browser tabs] -->|stable relative windows + conditional GET| Snapshots[Bounded HTTP snapshots]
    Tabs -->|Sessions: empty recent list, one all-time row| Snapshots
    Lineage[Open Lineage pane] -->|compact global page| Snapshots
    Detail[Conversation detail and stream] -->|native session tree| Lineage
    Snapshots -->|one request-owned refresh per query| Sidebar[Authoritative sidebar reader]
    Sidebar -->|directory or global recency index| Local[Local compact projection]
    Sidebar --> Remotes[Owner-routed remote reads]
    Mutations[Session/project/preferences writes] -->|fence publication + invalidate| Snapshots
    Events[Global session/state events] -->|invalidate| Snapshots
    Events -->|compact rows| Tabs
    Push[Strict Web Push snapshot] -->|bypasses partial browser cache| Sidebar
  
  • Browser sidebar and notification HTTP responses share immutable serialized snapshots per exact query. Relative sinceHours windows produce stable keys; explicit since values retain exact semantics. Entries expire five seconds after the authoritative read starts, independently of event delivery. Refreshes run in the initiating request, join concurrent consumers, and never return stale content on error. Retention is bounded to 64 entries and 32 MiB.
  • On /sessions, an empty recent list triggers a compact all-time read limited to one row. This distinguishes first use from an empty time window without loading the full history. Failed reads offer Retry instead of onboarding.
  • ETags combine a server-local epoch and content digest. Conditional reads skip unchanged response bodies. Mutations and state broadcasts invalidate snapshots; a mutation during a read prevents that response acquiring a reusable version. Missing backend invalidations still recover through expiration. Browser partial owner results are never reused by strict Web Push delivery.
  • Complete compact events update eligible existing cached list rows without another SQL read. Unknown rows and native child membership reconcile authoritatively; bounded lists also reconcile removals and backwards moves; accounting queries retain authoritative reads. Request-scoped fences prevent older HTTP responses overwriting newer event rows. List/notification polling retain their five-/ten-second freshness budgets: the server reports snapshot age, which is subtracted from the next polling delay rather than adding another full interval. Retries have a 250 ms floor. Existing reconnect/resume reconciliation remains unchanged.
  • PR-watch archive overlays read only watched archive identities and the resurfacing mode, not the full historical seen/pinned preference maps.
  • Bounded local directory pages seek (directory, updated_at DESC, id) rather than walking unrelated global history. Global pages keep global recency; unbounded inventories retain their existing query plan. Owner/publication, visibility and origin filters still run before pagination. The directory index is added by an append-only history migration without rewriting stored content.
  • The Lineage pane combines the active conversation’s native tree with the most recent 500 compact catalog rows, fetched only when the pane is open. It uses a recorded creator when a session has no native parent, matches relationships by connection and session ID, and keeps native links visible if the catalog lookup fails. Older catalog-only relatives may not appear. Each visible row reads its saved PR links with pull-requests?background=true, which skips forge lookups, and names the project only when it differs from the active conversation’s project.

Session list/detail responses carry factoryAttemptId from a single state.db attempt lookup. The sidebar filters these tagged rows and their descendants without requesting /api/factory/epics. Only tagged conversations mount Factory recovery queries. On mobile, closed drawers disable sidebar list/git reads and unmount the closed mobile details drawer. Document visibility pauses reads without unmounting open panes or recovery controls, preserving fullscreen diffs, pagination, expanded previews and unsent guidance. Resuming refreshes the visible content, including the artifact pages already opened by the user. Activity’s Resources view polls backend uptime through /api/system/stats every five seconds while visible, independently of process sampling. The session sidebar does not poll or display runtime stats. Sidebar branch/worktree metadata batches checkouts per owner rather than the active conversation’s machine, retaining known same-owner labels during refreshes. Conversation archive and keyboard navigation load their candidates on demand when the mobile sidebar is closed, without restarting sidebar polling. Archive changes broadcast to every client and close the affected open conversation; browser reloads preserve the archive instead of treating it as a reopen. Artifact pagination and resume refreshes share a serialized read chain. Settled agent bash commands also produce ocman.git.command refresh hints for the owning project’s PR/Issue pane.

4. Frontend composition

Each production frontend build embeds the same build hash in its JavaScript and /build-hash.json. The authenticated shell checks this static file with browser caching disabled every three visible minutes and on visibility/online recovery. A different valid hash opens a persistent update notice with Refresh now and a 60-second wall-clock countdown to reload. Missing files, malformed responses and network errors do not trigger reloads. Development HMR does not run the checker.

    flowchart LR
    Chunk[Failed lazy import] --> Recovery[preloadRecovery]
    Recovery --> Probe[build-hash.json]
    Probe --> Budget[sessionStorage retry budget]
    Budget --> Safety[automaticReload]
    Notice[BuildUpdateNotice countdown] --> Budget
    Drafts[Draft stores and automaticReloadGuards] --> Safety
    Safety -->|safe| Reload[Page reload]
  
  • preloadRecovery probes the deployed hash after vite:preloadError. Only a different valid build can trigger recovery. Its tab-local history keeps eight attempts, refuses repeated source or target builds, and permits at most two reloads per minute. Unavailable or malformed session storage fails closed. The update countdown shares this budget so it cannot bypass loop protection. The obsolete lifetime-wide ocman:preload-reloaded marker is ignored.
  • automaticReload blocks both chunk recovery and the update countdown while composer text, prepared drafts, pending attachments, full failed-send payloads or an unsaved-editor unload guard need the current page. The countdown then pauses with a save/send reminder. Explicit Refresh now remains user-controlled. Recovery checks safety again after its asynchronous probe and leaves import errors visible to the existing ErrorBoundary when it cannot safely reload. Mounted composers register live readers through automaticReloadGuards: textarea values are checked before the autosave debounce, and existing-session attachment snapshots update synchronously before reads/uploads or React commits. Removal/send releases the attachment blocker; unmount unregisters that local owner. Controlled prepared drafts keep their existing store-owned lifetime, including protection after the composer unmounts.
    flowchart TD
    Shell[App routes, MainNav, routeTitle, Settings] -->|routes, navigation, settings sections by category| Features[features/<br/>static registry]
    Features --> Pages
    Shell --> Pages
    Pages[pages/<br/>routes] --> Comp[components/<br/>shared controls + feature UI]
    Pages --> Stores[Client state<br/>TanStack Query + Zustand]
    Pages -->|pending prompt, before HTTP acknowledgment| Comp
    Stores --> Persistence[Browser persistence<br/>IndexedDB drafts, text + receipts]
    Stores -->|beta opt-in: route gates, navigation + Factory analytics| Shell
    Comp -->|owner-scoped PR queries + repository/SHA checks persistence| Stores
    Comp -->|plugin Settings + palette actions: explicit ownerId| API
    Comp -->|delayed markdown hover: provider or Open Graph card, proxied image| API
    Comp -->|first execution: resolve workspace, then dispatch on same owner| API
    Stores -->|visible pane reads; session rows carry Factory tags| API[lib/ API client]
    Stores --> SSE[SSE subscription]
    Stores -->|shared notify snapshot: badge + grouped-view attention| Comp
    Stores -->|recent Home badge: intersect notify with current eligible sidebar rows| Shell
    Pages --> Scopes[Ref-counted activity scopes]
    Comp --> Scopes
    Scopes --> Reporter[Client activity lease reporter]
    Reporter --> API
    API -->|/api| Hub[ocman backend]
    Hub -->|state.db beta flag: UI sync + MCP tool filtering| Stores
    SSE -->|events| Hub
    Hub -->|ocman.settings.changed: advance settings query generation| Stores
    Hub -->|foreground status + independent background shell/agent details| Stores
    Hub -->|GET /api/keybindings: shared cached binding catalog| Stores
    Comp -->|owner-routed task stop + task/service override| API
    Comp --> Caps[useCapabilities<br/>capability gating]
    Comp --> Speech[Browser speech synthesis<br/>local or online voice]
    Comp <-->|image preview query, Back/Forward| Shell
  
  • Shared query cache. PR checks and review status use the application QueryClient for request deduplication, polling and last-reader cancellation. Inactive rows unsubscribe; poll deadlines survive viewport and tab changes. Settled checks retain the bounded repository/SHA localStorage cache. Project settings use owner/project/generation query keys, so invalidation cannot let an older in-flight read restore stale settings.
  • Keyboard bindings. internal/keybindings serves the hub-owned catalog at authenticated GET /api/keybindings. defaults.json is embedded in the binary; reading an external user config file is not implemented yet. The browser loads the catalog through one shared QueryClient entry, cached for the page lifetime. React components register action IDs, handlers, scopes and availability, not key combinations. Dispatch, shortcut help and hints use the loaded bindings. The response maps stable action IDs to arrays of physical-key bindings such as {"code":"KeyJ","alt":true}. Only code, alt and shift are supported. Missing IDs and empty binding arrays disable actions; unknown IDs cannot add handlers. Until loading succeeds, shortcuts stay inactive. Failed requests use the shared retry and focus/reconnect recovery policy, with no frontend defaults.
  • Conversation derivations. Immutable part snapshots share a WeakMap parser in lib/parsePart.ts. Conversion caches belong to one platform/session and depend only on referenced task snapshots and that message’s failure fields. Turn accounting retains unchanged aggregates and attaches them to converted message metadata. Existing assistant-ui message selectors publish accounting, lifecycle and content together, without a separate full-map context or store. The browser’s optional collapsed activity view keeps user-facing Markdown inline and groups tool calls and reasoning between replies and questions. Question wait time is excluded when answer timing is available. A pending send can start the timer before the first reply; the acknowledged prompt keeps the same disclosure identity. Questions, interactive results and turn errors stay outside the work disclosure. A background shell result after a completed reply starts a separate follow-up turn. The shell result belongs to that turn’s disclosure when it has a reply. Transcript text does not invalidate sidebar project/draft derivations or row actions; list, prompt, owner and live-status inputs still do.
    flowchart LR
    Stream[Immutable conversation snapshots] --> Parse[Shared parsed parts]
    Parse --> Convert[Per-message conversion]
    Parse --> Stats[Per-turn accounting cache]
    Stats --> Convert
    Convert --> Select[Existing per-message runtime selectors]
    Select --> Thread[Conversation UI]
    Thread --> Activity[Optional work disclosure and timer]
    Stream --> Answers[Indexed completed answers]
    Answers --> Text[Markdown tree to speech text]
    Text --> Speech[Browser speech synthesis]
  
  • Session attention. The app badge and the grouped sidebar’s Needs attention group share the notify snapshot and one owner-qualified eligibility rule. Notification metadata renders directly without loading individual conversations. The sidebar query includes unarchived and resurfaced sessions outside the history window. The flat view renders all origins as normal session rows and never injects notification-only rows. Attention rows in grouped view bypass history filters and collapsed projects. Sessions already visible in ordinary rows are not repeated; hidden rows leave the group when the shared snapshot acknowledges or resolves them. In recent view, desktop and phone Home badges intersect that snapshot with the current owner-qualified sidebar rows and shared visibility filters. Missing, hidden, viewed or now-running rows cannot leave an orphaned completion count. Finite background tasks defer completion counts; declared services do not.

  • Feature registry. src/features/index.tsx is a static list in which Factory, routines and artifacts contribute their routes, with layout tier and header titles, plus their main-nav link. Plugins, auto-approve, sharing and webhooks contribute Settings sections alongside the core sections. Each declares its category and stays mounted either always or only while its category is active. Settings has seven categories with visible section headings; legacy tab links map to their new category, and search opens the category before revealing the row. App’s routes, MainNav, routeTitle and SettingsTab iterate the registry at fixed slots between their core entries. The registry is static, while heavy Factory pages use lazyComponent to defer their imports. Backend plugins remain separate and reach the UI only through plugin panes and palette actions. The command palette and the session right-panel tabs still keep their own lists.

  • Beta features. Settings under App & notifications includes a default-off Factory toggle persisted instance-wide in state.db as beta.factory, served by /api/settings/beta-features. The retired browser-local opt-in is ignored. The registry’s beta metadata gates every Factory route before mounting its page and hides desktop and phone navigation links. The same flag hides its analytics cards, session filters, Inbox category and messages, badge setting, notifications and interactive conversation cards. Settings events, focus and periodic reads synchronize browsers. Direct links show a generic unavailable page. The MCP handler applies each module’s ToolFilter for discovery and invocation, so Factory hides and rejects its tools and the Inbox omits its disabled category without a restart. Factory dispatch starts only while the flag is on: saving it starts or stops the dispatch loop, and startup recovery runs once, when dispatch first starts. REST mutations wake this same gated worker instead of dispatching synchronously. Disabling leaves running sessions alone and does not restrict REST access or delete stored data.

  • Background task notice. OpenCode v2’s session-owned running shells and active native child agents, plus managed Claude Code’s tracked background tasks, publish absolute counts through ocman.session.background, including live task IDs and descriptions. The composer shows the count only above zero. Click opens the shared popover with individual Stop buttons gated by backgroundTaskStop. OpenCode restores counts in server.connected.backgroundTasks; Claude includes the count in its leased session snapshot. REST refreshes preserve live counts, and foreground idle preserves them. OpenCode also restores descriptions through server.connected.backgroundTaskDetails. Counts are not inferred from transcript tools. Task stops go through sessionlifecycle and sessionsvc as task-scoped Abort requests, preserving the compound platform owner over gRPC. Every adapter boundary rejects task stops without the capability, including older backends. OpenCode verifies shell ownership before deleting that shell; Claude verifies the live task ledger before sending the SDK stop_task control request. Neither falls back to aborting the whole session, and completion events remain authoritative for removing rows. OpenCode’s disposable live activity tracker follows native parent links from active sessions, restores them before stream headers on reconnect, and reports session status from foreground execution only. Shells and child agents do not hold an idle session Working. Finite background tasks do prevent completion-based archive resurfacing; explicitly declared persistent services do not. Managed Claude likewise settles foreground results independently of its background-task ledger. It never uses ocman’s independent worktree links. Child completion updates ancestor counts without changing ancestor status; a running parent stays Working while it processes the result. Agent rows carry kind: "agent" and do not offer the shell-only Stop action. Unknown lifecycle declarations default to task, without command-name or duration heuristics. OpenCode shell metadata.lifecycle: "service" declares a persistent service. The popover’s Task/Service control, gated by backgroundTaskLifecycle, saves an owner-local per-session/task override through sessionlifecycle, sessionsvc and the owning Platform, including over gRPC. Only headless event consumers update archive activity; browser replay cannot resurrect completed tasks. The sidebar worker checkpoints task/service counts before broadcasting their changes, including the final task finishing without a foreground status change. Lists, conversation reads, remote overlays and notification polling share db.ShouldResurfaceSession; pending permissions and questions bypass background completion gating. Activity-based resurfacing is unchanged.

  • Shared controls. Control provides buttons, button groups, text inputs, textareas, search inputs, and selects with native form semantics and shared focus, disabled, and invalid styles. IconButton, RefreshButton, and CopyButton add action feedback; copying is confirmed only after success. Pagination shares previous/next controls while callers own indexing, page boundaries, totals, and requests.

  • Image previews. Markdown images and conversation attachments register with the app’s ImagePreviewProvider. The image query parameter selects a mounted image using message/source fingerprints and a within-message duplicate number, never an arbitrary image URL. Links reopen when the matching image mounts. Previous and next buttons and arrow keys follow page order, retain owner parameters and URL fragments, and replace the preview history entry. The shared zoomable modal retains wheel/pinch zoom and Escape-to-close. Linking a preview does not grant access to the conversation or its files.

  • Existing-conversation sends. usePendingSend records the prompt immediately. OcmanRuntimeProvider appends its text and images to the display messages only, leaving the server transcript untouched. The pending prompt stays visible until the server user message has parts; failed sends retain the retry controls. Backend send preparation shares its project-model session read with first-input detection, avoiding a second transcript-page request after restart.

  • New-conversation settings. Settings → Sessions → Default agent starts at build and uses the shared searchable agent picker. Options come from agent-only reads of running local instances, scoped to their discovered directories and known local session directories. This includes project-defined agents on v2’s single machine server without launching an instance. Hidden helpers and subagent-only agents are excluded. With no reachable instance, build, plan, and the saved preference remain selectable; remote-only catalogs are not read. Catalog discovery uses up to eight concurrent waiters within a five-second overall deadline, with a four-second per-target wait, and stops scheduling directories on cancellation. A stalled target does not block healthy catalogs or fallback choices. Shared port scans have an independent ten-second deadline; canceling a caller only cancels its wait, preserving other clients’ live status. Shared agent fetches acquire one of eight global slots inside the singleflight leader and hold it through the HTTP response. Their two-second fetch deadline is independent of callers; slot admission waits at most ten seconds. Leaving Settings cannot cancel a composer’s joined catalog read. Direct catalog callers also cancel only their own singleflight wait, without waiting for admission or the shared fetch to finish. A failed scan preserves the last successful snapshot for liveness readers and the auto-approval watcher for at most one minute without renewing the cache TTL. Sustained failure then expires old membership so stopped sessions lose stale busy status. A successful empty scan still removes disappeared instances. An explicit composer selection wins. projectSettingsCache shares the project settings fetch across conversations and sibling worktrees, keyed by owner and project root. Successful global or project setting saves broadcast ocman.settings.changed, which clears every cached project setting and refreshes mounted composers. Reconnecting SSE also clears the cache to recover missed saves; in-flight reads cannot restore stale settings after invalidation. The preference is stored in the hub’s state.db. The header’s project button opens ProjectQuickSettings, which reads the directory catalog without launching an instance and saves model, agent, and worktree defaults through /api/project/settings. These defaults use a separate owner-and-project-root setting key, preserving the ordered model fallback list. New conversations apply them after preparation; explicit composer selections win, including selections made while preparation waits.

  • Selection and overlays. SegmentedControl uses native radios for filters. Popover shares the usage popover’s compact, square-cornered shell with project quick settings. It portals to the document body, focuses the panel, handles outside-click and Escape dismissal, and restores trigger focus on Escape. Each caller positions the shell beside its trigger. Tabs and DropdownMenu wrap Radix UI for keyboard navigation, focus, and accessible associations, styled with the app’s CSS. Tabs activate on click, Enter, or Space and unmount inactive content by default. Menu actions that open dialogs wait for the menu to restore focus so the dialog records a stable opener. ModalHeader and ModalFooter compose the existing Modal, IconButton, and ButtonGroup; Modal retains dismissal and focus handling.

  • Loading and errors. LoadingState pairs a decorative Spinner with one status announcement and respects reduced-motion preferences. Structured skeletons remain separate. InlineAlert announces errors and can show a busy-aware retry button; EmptyState renders empty messages. Callers own loading, stale-data, error, and empty-state decisions.

  • Capability gating. The UI never branches on platform identity. Features toggle via /api/capabilities, enforced by a lint script.

  • PR checks. lib/usePRChecks polls only visible rows/cards until every check settles, or three empty reads spaced 30s apart confirm no CI. Errors back off from 5s to 60s across viewport changes. Sidebar polls respect forge rate-limit deadlines; cards rely on resolver-side upstream backoff. Hidden documents pause polling. Both views use lib/prChecksCache’s bounded localStorage cache, keyed by host/repository/SHA. Sidebar refresh also restarts checks on mounted conversation cards. Preview checks use the existing preview resolver endpoint so the conversation owner and preview credentials remain authoritative, including PR links outside the active project’s repository.

  • New session target. A new conversation gets an Ocman draft ID at /session/{id}?dir=…. Autosave can create a draft record, but it never creates a native session or worktree. NewConversation calls POST /api/sessions/prepare, which reads the directory’s agent, command and model catalogs (Platform.DirectoryCatalog, routed over gRPC for remotes). The composer’s useDraftCatalog requests selectedOnly to open the submission gate, then loads the full model inventory independently. Optional failures cannot block submission, and late inventory only enriches the picker, never replaces the prepared defaults. Changing owner or directory cancels both reads. POST /api/session-drafts/{id}/start stores the first prompt and its chosen target together. It creates the draft record if autosave never succeeded and does not wait for an autosave or draft revision check. Initial file uploads also use the chosen target rather than requiring saved draft metadata. Native OpenCode creation receives permissions and initial agent/model/variant together through the owner-routed CreationIdentity. Its acknowledged configuration receipt avoids the permission PATCH/readback; the initial send still checks live selections before prompting, skipping unchanged switches. The preparation flow is:

        flowchart LR
        Composer --> Selected[Selected catalog + project settings]
        Selected --> Ready[Submission ready]
         Ready --> Admit[Persist first prompt and target]
         Admit --> Create[Owner-local configured creation]
         Create --> Prompt[Live selection check + first prompt]
         Create -->|Proven pre-allocation failure| Saved[Saved message + explicit retry]
         Saved -->|retry-setup, same ID and payload| Create
         Create -->|Archive during setup| Archive[Stable session archive marker]
         Prompt -->|Completion or pending prompt| Resurface[Normal archive resurfacing]
         Archive --> Resurface
        Selected --> Inventory[Optional full model inventory]
        Inventory --> Picker[Model picker enrichment]
      

    Durable setup failures keep the submitted message and attachments visible, with long error details collapsed and a copy action for the message text. POST /api/session-drafts/{id}/retry-setup atomically claims an explicit retry only after a persisted clone, worktree or runtime failure proves native allocation was not reached. It preserves the ID, complete request and held queue; duplicate retries cannot start a second worker. Aggregate remote worktree errors and uncertain allocation are not replayed. A confirmed session instead uses retry-delivery, so first-message retry never allocates again.

    useWorktreeEligibility reads the git-info branch, the owner’s worktree list, and its verified default base ref to decide whether “New worktree” is offered. A repository without a usable base commit uses the current checkout, and automatic creation rejects it before launching OpenCode. Named bases use fully qualified refs to avoid branch/tag name collisions. Git probe failures propagate to the eligibility retry controls. useSessionCreation prefetches the owner’s main checkout while an existing session or draft/setup route is open, reusing that promise for Option/Alt+C and Option/Alt+T without requiring a native session or running platform, rather than starting a worktree-list request on each press. Directory or owner changes and unmounts cancel the lookup and suppress stale navigation; an early press shares the in-flight lookup so external worktree layouts still resolve correctly. Factory removes the exact namespace when recording a forge target branch. A detached default uses verified local main or master for delivery, otherwise preparation requires an explicit named target. Legacy recovery uses the same preparation path. The machine selector re-points the route; the target selector changes client state. Neither creates a session. All browser-local draft state lives in one IndexedDB database, ocman.drafts.v1 (lib/draftDb), with three stores: composer text per session or draft id (lib/composerDraft), prepared-conversation metadata (owner, directory, target, selections; lib/newConversationDrafts), and start/first-delivery receipts (lib/draftStartClaims). Every lifecycle step is one readwrite transaction over the stores it touches. IndexedDB runs overlapping readwrite transactions one at a time in creation order, so each check and its write are atomic across tabs, and an aborted transaction leaves nothing half-applied. Each tab keeps a synchronous in-memory snapshot (a Map for text, Zustand for drafts and receipts), hydrated in one transaction before the app renders. After a commit, BroadcastChannel tells other tabs which keys changed and they re-read them; a per-key local edit counter stops a database read from overwriting a newer local edit. Hydration imports the pre-IndexedDB ocman.composerDrafts.v1 localStorage map once without overwriting stored text. Failed autosaves retain the unsaved live text across refreshes and report the failure in the composer; another edit retries persistence. Synchronizing an untouched composer updates presentation without dispatching input or saving. Without IndexedDB, drafts live in memory only and starts fail closed. Text records carry a revision that only grows. An autosave writes only if the stored revision is not newer, so a stale autosave cannot land after a discard in another tab. Clearing sent text clears only the exact text and revision this tab saw. Discard increments the revision, and emptying the composer applies it at the input gesture. A composer that is still empty shows text restored later, such as a failed start recovered by another tab; a user edit always wins. SidebarConversationDrafts lists these prepared conversations in both sidebar views, including empty drafts, and lets the user reopen or discard one. Opening another new conversation allocates another draft id; switching machines retains the current id. The first submission claims the draft in one transaction: a pending or completed receipt refuses a second claim in any tab, and a committed metadata tombstone refuses a start on a discarded identity. The pending receipt holds the prompt so reopened composers show it; terminal receipts drop it. A failure this tab knows but could not store is repaired inside the next claim. Completion is one transaction. It records the created session and retires the draft when its owner, route, revision, text and selections still match what the initiating composer submitted. Otherwise it moves the newer edits (text, owner, target or selections) to a fresh identity. The submitted selections are captured from that composer, so peer changes made before submission are kept. The retired identity becomes a tombstone, so a late metadata write cannot resurrect it. If that transaction fails (for example at quota), a receipt-only write records the session with a relocation error. The draft stays untouched and a retry re-runs the same idempotent transaction. If even that write fails, the outcome stays visible in this tab and reconciliation repairs it. A failure is recorded in one transaction that restores the prompt only when no newer edit or discard happened. A created session is never downgraded to a failure. Sidebar discard waits for its transaction to commit before navigating or releasing live attachments; failure keeps the draft and exposes a retry. Identity-less bookmarked URLs get a fresh canonical draft id before mounting, with a transactional move of the legacy new text. Pending images and browser Files live in a shared draft-keyed Zustand snapshot, restored after navigation and a failed start. Mounted composers read it directly, including outstanding processing counts, so a remount cannot unlock submission before accepted files are ready. Attachment cancellation has its own identity, separate from text revisions. A completion or peer retirement transfers the snapshot and its pending batch owner to the replacement before clearing the retired identity. Catalog defaults are derived for display and submission, not saved as user edits. PreparedDraftLifecycle follows completed starts to their session or replacement and replaces an externally discarded identity. Its navigation guard remounts per draft identity. Lifecycle redirects replace history entries, so browser Back reaches the page before the retired draft. The first submission calls POST /api/sessions/start, which creates the session at the chosen target (an automatically named session-<suffix> worktree, or the current checkout), delivers a plain prompt server-side in the same request, and returns the real id; the client then navigates once. Until then the prompt renders as the conversation’s first message with the server-reported start steps beneath it (ocman.session.start.progress, see the event flow); a failure removes only that request’s prompt. Custom slash commands and shell submissions create the session the same way and run on it from the client; ocman built-ins need an existing conversation. A failed first send retains text, images, selections and error in the existing failed-send recovery path. Complete failed payloads stay in shared memory and notify mounted session views; only the best-effort localStorage copy is size-capped. Start locks are scoped to the draft generation so an older request cannot discard or unlock a newer draft’s submission. Non-image files are retained until creation, uploaded to the real session, then sent; file/command/shell execution lives in child-keyed retry state, independently of the child’s draft. First-delivery lifecycle is owned by firstSubmission: an atomic reservation in the shared draft database’s receipt store must succeed before upload/command execution or completion publication. Child composers remain locked until they read that record. BroadcastChannel carries notification hints, never authority; a missed notification cannot unlock peers. Known live terminal outcomes override stale pending records and reconciliation repairs their persistence. Retry execution remains in the originating tab, which repairs its known failure before claiming another attempt and retains the execution by attempt identity when a reservation is refused. Every write adopts the authoritative transaction result, fenced against newer live attempts. Equivalent durable terminal values are adopted without another write or notification, so IndexedDB’s cloned objects cannot cause cross-tab ping-pong. Receipt-read failures preserve the current payload/execution and cannot expose release controls for an active delivery. Rejections are fenced against newer lifecycle and view state. The originating tab owns the browser Files or command closure. An owner-presence probe detects a closed/reloaded tab. The unknown outcome remains blocked until the user explicitly releases the first-delivery lock; neither reload nor recovery resends the payload. Uncertain creation is never automatically replayed, and a late completion cannot override a newer route or clear its draft. Prepare/start preserve the localhost host-control guard. Afterwards the host has the title agent (its configured small_model, otherwise the agent’s selected model, in a temporary tool-denied session) name the delimited task under branch-naming instructions and renames the branch to that slug in place; the session title is left to OpenCode’s own first-message titling. Naming failures keep session-<suffix>. Non-repository directories and directories already inside a linked worktree use the current checkout. Existing linked worktrees are also selectable. New conversations started from a worktree session open on the owner’s main checkout, so every target stays available. Composer layout, dialogs, and props live in separate modules.

  • Read aloud. Turn-end controls select original final-answer text parts and use browser speech synthesis. Opt-in autoplay waits for the idle reconciliation in the focused session tab. Voice preferences stay in browser storage; audio does not pass through the ocman backend.

  • Plugin Settings. Settings uses shared setting rows and each host’s pluginManagement capability. The hub probes remote plugin support with a bounded available RPC. Catalog, lifecycle, configuration, and stderr calls carry the selected ownerId; switching owners clears the previous view. Enabling requires checksum and grant review. Secret inputs are write-only, and failed configuration activation reloads persisted configuration and health.

  • Client state. Shared Zustand stores hold broad session state. The session detail mirrors fresh REST/SSE status into the owner-qualified sidebar row, so navigation keeps the same status. Cached metadata stays unconfirmed after a failed refresh until a successful read or status-bearing live event arrives. List reconciliation fences against owner-qualified status-update revisions, including transitions returning to the starting status; subsequent fresh reads remain authoritative. The Routines page polls definitions (each with its latest run) and webhook inboxes over REST, pages history only for the open drawer, and keeps its form and selected edits locally.

  • Plugin actions. The command palette merges action.v1 contributions for global, project, and session contexts. It sends opaque IDs and core route names through the authenticated backend, resolving older contexts independently of the recent-session search cache. Host dialogs render confirmation text and typed results, including owner-routed artifact downloads. Confirmation reuses the operation ID; failures and timeouts never trigger automatic invocation retries. Plugins supply no browser JavaScript or HTML.

  • Activity leases. Mounted data subscriptions ref-count their scopes. One authenticated reporter renews the visible tab’s lease, allowing the backend to skip view-serving session, project and metrics refreshes when every tab is hidden or gone. Scheduled routines and auto-approve do not consult these leases.

  • Plugin panes. The right panel lists the active owner’s enabled pane.v1 declarations through /api/plugins/panes. Catalog reads never invoke the plugin. Each listed pane carries the plugin’s own icon descriptor, which the tab strip and pane header render so plugin panes identify their owner the same way navigation does. An open pane mounts its data query, calling /api/plugins/panes/read through the owner-routed PluginOperation RPC and the owner’s grant checks. Closing it unmounts the query and cancels an outstanding read. Core renders bounded tree nodes as plain text. The optional Beads plugin owns all bd execution and parsing; no Beads operation remains on hostsvc.Host.

  • Factory. /factory presents actionable approval Gates, Epics, Issues, Queue, and Configuration through TanStack Query. Browser mutations create native Epics, pour Mols, decide exact Plan revisions, and explicitly close completed containers. Each Epic links to its control session, where approved changes return through the scoped factory_control tool. The dispatcher records attempts before launching the prompt-constrained planning or configured implementation session. Factory MCP results can carry [[ocman:card ...]] markers. The tool-call renderer (and the markdown renderer, for markers in assistant text) turns them into creation or human-action cards using the same TanStack Query state and REST mutations as the Factory pages. Resolved actions disappear on refresh; rendering a marker never executes it.

5. Plugin action and remote projection flow

    sequenceDiagram
    participant B as Browser palette / Settings / sidebar
    participant H as Hub HTTP handlers
    participant O as Installation owner
    participant A as sdk/protocol action broker
    participant D as Owner state.db
    participant P as External plugin process

    B->>H: Catalog / management with ownerId
    H->>O: Local call or authenticated PluginOperation RPC
    O-->>B: Via hub: owner-qualified catalog, safe health, secret presence
    B->>H: List actions for placement and context owner
    H->>O: Owner-scoped actions; merge hub-scoped actions
    H-->>B: Typed action declarations
    B->>H: Invoke with installation ownerId and stable operationId
    H->>O: Route to installation owner
    O->>A: Validate enablement, scope, grants, confirmation
    opt Confirmation required
        A-->>B: Via owner and hub: confirmation text and bound token
        B->>H: Same invocation and operationId plus confirmed token
        H->>O: Route confirmed invocation
        O->>A: Revalidate and admit
    end
    A->>D: Commit operation receipt before dispatch
    A->>P: NDJSON action.v1 invoke with minimized context
    P-->>A: One typed terminal result
    A-->>B: Via owner and hub: authorized results / artifact handles
    B->>H: Download artifact with installation ownerId
    H->>O: Recheck grants and read owner-local artifact
    O-->>B: Via hub: attachment bytes
    B->>H: List enabled pane declarations with ownerId
    H->>O: Read approved pane metadata, no plugin invocation
    O-->>B: Via hub: owner-qualified pane declarations
    opt Sidebar pane open
        B->>H: Read pane with ownerId and directory
        H->>O: Route read, verify enablement and pane.project grant
        O->>P: NDJSON pane.v1 read
        P-->>O: Typed tree, no markup
        O-->>B: Via hub: validated and reauthorized tree
    end
  
  • The installation owner supervises the process and owns its configuration, secret files, operation receipts, and in-memory results. The hub projects remote operations through a closed RPC, never raw plugin stdio.
  • The browser can target a hub installation while carrying a remote project’s context. These are separate owner identities; disconnected explicit project owners fail closed. Global placements resolve to the hub.
  • Confirmation and result rendering belong to ocman. Calls are not replayed after crashes, and durable receipts prevent uncertain side effects from being repeated after host restart. Downloads recheck the installation’s current grants.
  • Shipped capabilities are action.v1, pane.v1, conversation.v1, and session.v1. Platform-provider, iframe UI, relay inbox capability, registry/updates, signatures, sandboxing, and plugin-provided platforms remain future work. Existing core Inbox and webhook services do not imply a plugin capability for either.

See Plugins for the operator and authoring guide.

6. Plugin session requests and completion delivery

Plugin workspace navigation and configuration

    flowchart LR
    Registry[Feature registry] --> Navigation[Desktop navigation and phone More]
    Navigation --> Catalog[Owner-qualified page declarations]
    Navigation --> Page[Host-rendered root-page tabs<br/>one entry per plugin and owner]
    Page --> API[Authenticated read/save API<br/>project, item and cursor identities]
    Page --> Models[Owner/platform model catalogs<br/>no project or runtime launch]
    API --> Owner[Executing owner authorization<br/>project lookup only for explicit IDs]
    Owner --> Process[Plugin read/validate/save<br/>host static rules before save]
    Process --> Files[Plugin-private target configuration]
    Page --> Actions[Existing action confirmation and results]
  
  • page.v1 contributes inert field schemas and trees. The frontend registry owns one generic route and a navigation entry per plugin/owner. Declared root pages become host-generated tabs, with the plugin display name in navigation and page labels on tabs. The registry contains no pentest-specific storage or executable plugin content.
  • Page 1.1 adds bounded collections and detail properties rendered with shared tables and controls. Item links preserve owner/project identity. The owner reads the current schema, checks the revision and static rules, then runs an optional validation hook before saving. Errors retain browser drafts; failed validation never dispatches a save. See the contribution guide .
  • Page 1.2 adds plugin-local homepages with the page.plugin grant. These read one plugin-owned registry without project enumeration. Collection links can enter an owner-validated project editor; project actions retain their existing authorization and model-session context. Project-scoped pages remain unchanged.
  • Page 1.3 model fields reuse the native searchable picker. Model catalog reads use owner-routed PluginOperation calls and each platform’s directory-free catalog, preserving platform-qualified selections and failing closed offline.
  • Page 1.4 adds bounded summary cells with secondary text and additional-item counts, plus enumerated severity badges. The host owns presentation and links first-column summaries to existing item routes, or an opt-in right drawer. Drawers fetch owner/project-qualified item details only while open, cancel pending reads on close, and preserve the underlying list and pagination. Older minors reject these displays and the drawer preference.
  • Independent workspace editors use opaque workspace IDs instead of project ownership. Workspace actions run on the explicit plugin owner. Session 1.2 model-only turns use host-created private workspace directories with tools denied, while linked repositories remain many-to-many scan sources.
  • The owner checks approved declarations, enablement and the page’s page.project or page.plugin grant under the lifecycle lock and resolves explicit opaque project IDs locally. Disabled, revoked and offline owners cannot silently reuse another owner’s data.
  • Plugins own private storage and secret redaction. Browser drafts remain local to the selected owner/project. Save is explicit and never automatically retried; the pentest consumer uses revision checks and atomic mode-0600 writes.
  • Scan controls use the existing action broker, including disclosure and consent. Result trees use the existing bounded tree renderer.

Managed session requests

    sequenceDiagram
    participant U as Settings client
    participant P as Owner-local plugin process
    participant T as NDJSON supervisor
    participant B as SessionBroker
    participant S as Session service and queue
    participant D as Owner state.db
    participant O as Completion pump
    participant R as Owner project registry

    U->>D: Permission-profile CRUD through core HTTP API
    P->>T: Call session/run, caller request ID and operation ID
    T->>B: Deadline-bound unary request
    B->>D: Read enabled installation, grants and optional scalar project
    B->>R: Session 1.1 projectId, resolve owner-local root after session.project grant
    opt Session 1.6 workspace attribution
        B->>R: Resolve associatedProjectId on the same owner after session.associate grant
    end
    B->>B: Reject traversal and resolved symlink escape
    B->>D: Reserve plugin and operation ID, or return stored result
    B->>D: Resolve named profile rules, or pin all-tools-denied for noTools
    B->>D: Reserve provisional directory attribution, if requested
    B->>S: CreateConfigured with pinned rules
    B->>D: Commit attribution after creation, release own claim on confirmed failure
    B->>D: Link session to plugin
    B->>S: Enqueue prompt with exact agent/model
    B->>D: Persist run result
    B-->>P: Result on caller request ID, sessionId or safe error
    opt Session 1.8 and stream true on this request
        S-->>B: Live assistant text events for the linked session
        B-->>P: Coalesced partial snapshot after grant check
    end
    S->>D: Completed assistant text and observed usage, idempotent outbox append
    O->>D: Claim due head per session
    O->>P: Call session/completed with usage, stable sess-out row ID
    P-->>O: Empty object acknowledgement
    O->>D: Mark done, or retain and schedule retry
  
  • internal/pluginsmod/session.go handles admission and the immediate result. The supervisor keeps separate request-ID sequences in each direction; IDs can overlap without confusing a run reply with a completed-turn reply. session_runs.go reserves each plugin’s operation ID durably before creation and keeps its result across reloads. Conflicting payloads are rejected; pending receipts never start another session after an uncertain crash.
  • Named permission profiles live in owner state. CreateConfigured applies their exact rules before the queue receives the plugin’s prompt. Unknown or deleted names return not_found to the caller without creating a session.
  • Session 1.1 can resolve an opaque owner-local project ID with the additional session.project grant instead of requiring a global project setting. It does not infer ownership from directories or fall back to another machine. noTools overrides profile rules with an all-tools-denied rule before prompt admission. Blank agent/model values preserve host defaults.
  • Session 1.6 associatedProjectId resolves through that same owner-local catalog under session.associate, independently of the private execution directory. pluginsmod/session_projects.go owns the append-only schema migration and immutable directory association. Provisional operation-qualified claims fence concurrent creation and stay out of inventories. Confirmed pre-creation errors release only that claim; creation commits attribution independently of caller cancellation, and later delivery failures cannot erase it. Uncertain native outcomes and abandoned claims remain fenced. The owner overlays committed attribution during project-index refresh, including zero-stat targets without history. Remote inventories carry the association; shared upstream groups and browser project identities retain source statistics but select real project directories for display and launch. Permissions and session directories never change, and source cleanup cannot erase the association. Historical unassociated runs need an explicit merge.
  • internal/pluginsmod/session_outbox.go records and pumps completions. The durable mapping and AUTOINCREMENT outbox ID survive reopen. Pending deliveries replay after a crash, including one after the consumer’s effect but before host ack. Consumers must durably deduplicate the stable operation ID.
  • internal/pluginsmod/session_partial.go watches the owned session’s event stream for runs and follow-ups that negotiate session 1.8 and request stream. It ignores initial state frames, keeps only the latest text snapshot, rechecks grants before dispatch, and does not write to the outbox. The final assistant message’s receipt key supplies the matching turn ID on durable delivery.
  • Observed tokens and cost are stored with the completion in the same outbox insert. Missing usage remains unknown across retries; it is never synthesized as free inference. The v2 compatibility converter marks synthesized UI defaults as unavailable, so a display zero cannot become observed zero-dollar usage. A new append-only module migration adds the metadata column.
  • Only an empty JSON object acknowledges completion. Revocation pauses delivery without consuming attempts. Six failures retain a dead letter and block that session. Session retry/discard controls are still missing, so operator recovery does not yet match the conversation outbox’s guarantees.