Webview API¶
The seam between the cockpit frontend (and the mini-apps inside it) and the agentctl
backend: an HTTP surface under /api/…, plus a WebSocket frame protocol.
How X-User-Email is established:
The webview gateway § Identity and scope.
What a cockpit session reaches:
Security model.
Scopes¶
Every request's scope comes from X-User-Email, resolved through the gateway's
user_email → agent ledger into one agent name. No request value anywhere in the chain is a
scope claim.
| scope | how it arises | reaches |
|---|---|---|
| admin | the header maps to an agent holding the admin role | every agent on the host, plus the agent-less host surfaces |
| owner | the header maps to exactly one agent | that agent only |
| nobody | the header maps to no ledger entry, or there is no header at all | nothing — deny-all |
There is no unfiltered scope. A missing header is the deny-all scope, indistinguishable in authority from an unknown address.
Supervisor is a separate role (ledger supervisor: true), independent of admin: an admin
is not implicitly a supervisor, and a supervisor is not implicitly an admin. It admits an
identity to the fleet-wide activity rollup and nothing else.
The gate column in the tables below names which check a route applies.
| gate | passes for |
|---|---|
| agent | the named agent's owner; an admin for any agent on the host; the empty scope never, including for an empty agent name |
| admin | admin role only; on /api/snapshot and /events it also decides how the snapshot is filtered |
| supervisor | supervisor role only |
Both admin and supervisor rosters are read at gateway start, so granting either role takes effect on the next apply.
Session, transcript and turns¶
agent is a query parameter on the GETs and a body field on the POSTs. session selects a
subsession lane; empty means the primary lane. host is accepted and ignored on every
per-agent route that takes it. There are exactly two transports — op-relay to a dialed-in
agent, or a local read — and the choice is made by asking the dial-in registry, never by
resolving a host. The one HOST-scoped read, /api/def?kind=hostcron with no agent, is the
exception and does compare host — see /api/def below.
The local read is not a fallback that always works. It is taken only when the gateway is
itself on the agent's host, which the gateway checks per agent by statting the display env
file apply writes for every local agent. An agent that is neither dialed in nor local gets
502 with the agent name and the remedy in the body, on every per-agent read route below.
That window is the few seconds after a connector drops — agentctl apply <agent> restarts
it, so every apply opens one — and a local read during it would serve the gateway host's
state. Because an absent home, an absent unit and an empty sidecar directory are
indistinguishable from a fresh agent, those answers are empty rather than failed, which is
why the refusal is explicit instead of inferable from the body.
The local read is not a fallback that always works. It is taken only when the gateway is
itself on the agent's host, which the gateway checks per agent by statting the display env
file apply writes for every local agent. An agent that is neither dialed in nor local gets
502 with the agent name and the remedy in the body, on every per-agent read route below.
That window is the few seconds after a connector drops — agentctl apply <agent> restarts
it, so every apply opens one — and a local read during it would serve the gateway host's
state. Because an absent home, an absent unit and an empty sidecar directory are
indistinguishable from a fresh agent, those answers are empty rather than failed, which is
why the refusal is explicit instead of inferable from the body.
| route | method | request | response | gate |
|---|---|---|---|---|
/api/snapshot |
GET | — | fleet snapshot JSON | admin; an owner's copy is filtered to their own card, an admin's is verbatim |
/events |
GET | — | SSE, snapshot deltas | admin, same filtering |
/watch |
GET | agent |
SSE, one JSON event per frame, 12-event seed | agent |
/api/transcript |
GET | agent, session, subagent |
the same SSE feed, 200-event seed | agent |
/api/history |
GET | agent, before, limit, session|subagent |
JSON page of older events | agent; before must match the cursor grammar <digits>[:<digits>]; a malformed session/subagent is a 400, never ignored |
/api/pending |
GET | agent, session |
JSON array of turns sent but not yet in the transcript | agent |
/api/sessions |
GET | agent |
JSON session registry, main + subs | agent |
/api/subagents |
GET | agent, session |
JSON running/finished subagents | agent |
/api/session/list |
GET | agent, since, limit |
JSON sessions active in a window | agent |
/api/session/timeline |
GET | agent, session |
JSON tool-call waterfall | agent |
/api/fsevents |
GET | agent, session |
SSE, one fs_event frame per line |
agent; gateway-mode only, 501 otherwise |
/api/inject |
POST | {agent, host, text, session, uploads[], message_id} |
{ok, …} |
agent, resolved before the agent name is used to read any path |
/api/permission |
POST | {agent, session, request_id, behavior}, behavior allow|deny |
{ok, …} |
agent; gateway-mode only |
/api/agentmsg/engage |
POST | {agent, …} |
{ok, …} |
agent — checked on the receiving agent; it grants the sender nothing |
/api/authping |
GET | — | "ok" |
authenticated session; carries no scope check and returns a constant. The cockpit's pre-flight before a risky send or attach |
/api/inject takes JSON only. Attachments are named by tus upload id, never inlined.
Scroll-back is scoped to the lane that asks for it¶
/api/history has two readings, and the stream it pairs with decides which:
| request | pages |
|---|---|
agent alone |
the agent's whole merged timeline — every main-lane session plus the cron, recorded-send, lifecycle and agent-message card lanes, interleaved on one clock. Subsession transcripts are excluded, so a background lane can never surface in the owner's conversation. |
agent + session=<lane> |
that subsession's own transcript chain and nothing else — the lane's initial transcript plus each compaction rollover. No card lanes. |
agent + subagent=<id> |
that spawned subagent's own transcript and nothing else. |
The two selectors are the ones /api/transcript already takes, spelled identically, because
a pane must scroll back through the same lane it is streaming. They are mutually exclusive
(400), and a malformed one is refused rather than dropped — dropping it would answer a
lane-scoped request with the agent's whole timeline.
Why the scoped readings exist at all: every lane shares one live-seed cap of 200 events, so
without them a subsession or subagent pane showed its newest ~200 events and everything older
was unreachable. The cursor grammar is the same <millis>:<ord> on all three, so the browser
runs one scroll-back loop over every lane.
Subsession control¶
Five routes, all POST {agent, title, new_title?}, all gated agent, all gateway-mode
only. Each op-relays a subsession verb to the agent, which routes it to its own local
agentd.
| route | effect |
|---|---|
/api/subsession/start |
start a subsession |
/api/subsession/resume |
resume it |
/api/subsession/clear |
stop, keep transcript |
/api/subsession/rm |
deregister, keep transcript |
/api/subsession/rename |
label only — sid, unit and transcript untouched |
Workspace¶
Read routes run locally or over the agent's dial-in; mutating routes are op-relayed to the
agent, which executes them as itself. All gate agent over the agent parameter.
| route | method | request | response | notes |
|---|---|---|---|---|
/api/ls |
GET | agent, path |
JSON directory listing | the file tree's seed; /api/fsevents is the follow |
/api/file |
GET | agent, path, hash=1 |
text/plain, or JSON when hash=1 |
|
/api/raw |
GET/HEAD | agent, path, dl |
file bytes, content-type by extension | serves Range requests; caches byte length only, never content |
/api/render |
GET | agent, path |
text/html |
server-side render: Markdown, CSV/JSONL as a table, syntax highlighting for JSON and a fixed set of code extensions; anything else falls back to an escaped <pre> |
/api/inbox |
GET/HEAD | agent, file | fileid |
inbound-attachment bytes | chat thumbnails |
/api/write |
POST | agent, path, base |
JSON | base is the optimistic-concurrency precondition |
/api/mkdir |
POST | agent, path |
JSON | |
/api/rm |
POST | agent, path, recursive=1 |
JSON | |
/api/mv |
POST | agent, src, dst |
JSON |
Uploads — /api/tus/¶
The only upload path. tus 2.x resumable protocol.
| method | effect |
|---|---|
POST |
create an upload |
HEAD |
report offset |
PATCH |
append |
DELETE |
discard |
OPTIONS |
report capabilities |
| detail | behaviour |
|---|---|
| scope check | runs outside tusd's own middleware; no request reaches the store before scope is checked |
X-HTTP-Method-Override |
refused with 400, not emulated |
| unresolvable upload id | 404, not 403 — the endpoint is not an oracle for which ids exist |
Office viewer¶
| route | method | effect |
|---|---|---|
/api/office/open |
POST | stage a workspace docx/xlsx/pptx into OneDrive |
/api/office/pdf |
GET | PDF bytes for the <embed> |
/api/office/preview |
GET | Office-for-web embed URL |
/api/office/pullback |
POST | reconcile edited bytes back to the local file, on blur/close/beacon |
All four take agent + path and gate agent. The cockpit tracks which files a live
session has open, so the main-SSE close reconciles them if the browser disappears.
Mini-apps and the data plane¶
| route | method | request | response | gate |
|---|---|---|---|---|
/api/apps |
GET | agent |
JSON active apps (installed × wired) | agent, then admin-app filtering |
/api/apps/<id>/bundle.js |
GET | agent |
the app's component JS | agent |
/api/mcp/wired |
GET | agent |
JSON wired-MCP set | agent |
/api/mcp/read |
POST | {agent, mcp, tool, args} |
raw tool JSON | agent, then the tool gate |
/api/mcp/call |
POST | {agent, mcp, tool, args, timeout} |
raw tool JSON | agent, then the tool gate |
A manifest's admin: true only filters the launcher — it hides an icon. The endpoints an
admin app reads are gated independently.
The two endpoints are one plane. Each runs the tool gate in the handler and again in the
verb the op-relay carries, and the two verbs (mcp read, mcp call) are one implementation.
No read-only tool-name predicate stands in front of either, and a manifest's actions: true
is ignored. The only differences are the optional timeout on /call and which ctx method
an app author writes.
The tool gate, in order:
| gate | rule |
|---|---|
| risk catalog | a tool declared under risk: block in its mcp.yaml is refused. 26 tools across three MCPs are declared this way (see below) |
| turnless-only exclusions | browser.evaluate_script and browser.upload_file, whatever their tier |
| batch-payload methods | a tool listed under payload_method_tools is refused when its payload carries, at any depth, an HTTP method its MCP declares block under api_method_tiers — so ms365.graph-batch cannot carry a DELETE to reach what the per-tool rules block |
| per-tool argument narrowing | a narrowed tool may carry only its listed argument keys — take_screenshot without filePath, ADO's PR write without bypassReason |
The shipped catalog's block tier covers every irreversible delete on the three MCPs that
have one:
| MCP | tools declared block |
|---|---|
ms365 |
13 — delete-mail-message, delete-mail-folder, delete-calendar-event, delete-specific-calendar-event, delete-calendar, delete-onedrive-file, delete-todo-task-list, delete-group, delete-team-channel, delete-online-meeting, delete-planner-bucket, delete-sharepoint-list-column, delete-sharepoint-list-item |
google-workspace |
9 — gmail_delete_email, gmail_batch_delete_emails, gmail_delete_filter, gmail_delete_label, drive_delete_item, calendar_delete_event, sheets_delete_sheet, sheets_delete_range, slides_delete |
atlassian |
4 — executeDestructive, deleteJiraIssue, deleteJiraComment, deleteJiraIssueAttachment |
block is unappealable: there is no confirmation that admits it, on this plane or in an agent
turn. Everything else — every other MCP, every other tool, risk: ask and undeclared alike —
is reachable from both endpoints, mutating or not.
Both planes are turnless: they op-relay to the connected agent, which invokes the tool over
its own MCP socket, with no agent turn and no root daemon hop. A tool declared risk: ask is
reachable here with no confirmation step — see
Security model.
Both return 502 with {"ok":false,"msg":"agent not connected"} when the agent has no live
dial-in.
Connections¶
The agent's OAuth-capable MCPs and the one control that starts a login. All four gate agent.
| route | method | request | effect |
|---|---|---|---|
/api/connections |
GET | agent |
JSON per-provider connection state for the agent's wired MCPs; Cache-Control: no-store |
/api/connections/start |
POST | {agent, provider} |
begin a login. provider must be one the broker knows, or claude |
/api/connections/exchange |
POST | {agent, provider, code} |
complete a login. provider must be claude; a missing code is a 400 |
/api/connections/disconnect |
POST | {agent, provider} |
drop stored tokens for one provider |
Secrets and skills¶
| route | method | request | gate |
|---|---|---|---|
/api/secrets/set |
POST | {agent, key, value, scope} |
scope: self → agent; scope: shared → admin |
/api/secrets/remove |
POST | {agent, key, scope} |
same split |
/api/skills/remove |
POST | {agent, skill} |
agent |
There is no read half and no get route for secrets. The cockpit's panel shows key names
only — those arrive on /api/snapshot, which never carries a value — and the op-relay's own
whitelist admits secret set and secret remove but not get or list. A set with an
empty value is a 400: removing a key is remove's job.
The two scopes pick which agent's connector carries the op frame, because that connector's
uid is what agentd's self-scope check reads. self rides the viewed agent's connector with
--agent self; shared rides the caller's own connector with no --agent, so an admin
viewing another agent's cockpit still writes shared secrets as themselves.
/api/skills/remove op-relays agents skills remove <skill> self. The skill name must match
[a-z0-9][a-z0-9_-]{0,39}, so neither the verb's * selector nor a path can reach it from a
browser. There is no add route — activating a skill means choosing from the catalog, which
this panel does not surface.
Transport tunnels¶
/browser/ and /terminal/ are proxies, not JSON APIs. Both take the same two-step entry.
| request | behaviour |
|---|---|
GET /<mount>/enter?agent=<name> |
gate agent, resolve the transport, then mint a session token and Set-Cookie |
| — no reachable transport | 404, returned before any cookie is minted |
GET /<mount>/exit |
drop the session, clear the cookie, 204 |
GET /<mount>/<anything else> |
proxied to the agent's transport, prefix stripped |
| — no cookie | 403, not 404 — a prober learns nothing about the agent, port or display |
The browser cookie is HttpOnly and SameSite=Strict. Secure is set only when the request
arrived over TLS. What sits behind these two routes, and the root-owned admin marker
/terminal/ additionally requires, is in
Security model.
Host and fleet routes¶
/api/agents/restart-self (POST) derives its target from the login identity; a request that
resolves to no agent is refused, and a client-sent name is ignored with the resolved one
echoed back.
/api/agents/restart (POST {agent, host}) restarts one named agent and gates admin
before the body is read. Name validation rejects the selector keywords all, self and
shared.
The remaining host routes are the add wizard and the catalog authoring surface. Each shells an
agentctl verb against the on-box daemon. Every one gates admin before the body is read
or, for the /api/host/<host>/… group, before the path is even split.
| route | method | response | gate |
|---|---|---|---|
/api/agents/add |
POST | NDJSON progress (phase/step/log/progress/done/error) |
admin |
/api/apply-all |
POST | NDJSON, {"t":"hosts"} first, per-host events tagged host, {"t":"all-done"} last |
admin |
/api/host/<host>/capabilities |
GET | JSON | admin |
/api/host/<host>/catalog |
GET | JSON catalog browse | admin |
/api/host/<host>/catalog/add |
POST | {ok, msg} |
admin |
/api/host/<host>/catalog/remove |
POST | {ok, msg} |
admin |
/api/host/<host>/defaults |
GET | JSON | admin |
/api/host/<host>/defaults/set |
POST | JSON | admin |
/api/host/<host>/gateway/install |
POST | NDJSON | admin |
/api/host/<host>/slack-gateway/install |
POST | NDJSON | admin |
The /api/host/<host>/… group shares one dispatcher and the gate sits there rather than in
each of the eight handlers, so a tail added later is gated by construction. The cockpit hides
the buttons that reach these routes — they ship hidden and are clicked only by the fleet
mini-app — but the server-side check is the enforcement.
/api/def (GET agent, kind, name, host, path=1|json=1|catalog=1) gates
agent first. For the two agent-less lookups that ignore name and read host-global files
— catalog=1 and kind=hostcron — it re-checks admin. A scoped owner is refused despite
clearing the per-agent gate; a stranger is denied twice.
Its local read arm has two preconditions, because the route is called two ways:
- with an
agent(every kind,hostcronincluded — the cockpit's own reads always send one): the per-agent rule above. Not dialed in and not local → 502. This holds forhostcrontoo:fleet.ResolveDefignores the agent when resolving a host timer, but the agent still picks the transport, and relaying onto that agent's host is what resolves the unit on the right machine. - with no
agent(kind=hostcronalone — a true host-scope read):hostis compared against this process's own hostname. A different host → 404, naming both. It is a 404 and not a 502 because nothing is coming back: there is no host-scoped read relay, so this process is simply not the machine asked about. An omittedhoststill means "this host".
catalog=1 takes neither. A catalog item's source is the repo overlay or the shipped tree,
which apply distributes by git to every host, so the read is host-agnostic by construction
and host is ignored on it.
Diagnostics¶
| route | method | request | response | gate |
|---|---|---|---|---|
/logs |
GET | agent, host |
SSE, one frame per journal line | agent |
/api/pii-log |
GET | agent, host, session |
JSON array of PII redaction records | agent |
/api/activity-protocol |
GET/HEAD | path |
file bytes from the host's consolidated activity store | supervisor |
/logs follows the agent's systemd unit — two branches: journalctl -f op-relayed to the
agent's own host when it is dialed in, otherwise a local delegation that routes through
agentd for a non-root cockpit, so it reads the unit journal and not the caller's own. The
stream ends when the browser closes the drawer.
The local branch needs the unit to be on this host, and nothing about journalctl says
otherwise: journalctl -u on a unit that never existed here exits 0 and prints nothing,
which renders as a healthy idle agent. So this route refuses with 502 before opening the
stream when the agent is neither dialed in nor local — the refusal is a status rather than a
frame because EventSource exposes no status once the stream is open.
/api/pii-log is a disclosure endpoint. Each record pairs a real PII value with the
placeholder the pi PII filter substituted for it, read from a 0600 side-log the filter
extension writes as it redacts. It holds the same per-agent line as the rest of the surface: a
scoped viewer reaches only their own agent's log, capped at 500 records, with
Cache-Control: no-store. There is no write half — the verb underneath is self-scoped and
read-only, and which agent's log is read is decided by the connector, never by a parameter a
caller can point elsewhere.
/api/activity-protocol reads local disk only. The gateway host already holds the whole
fleet's consolidated store; this route never reaches across hosts. It is not agent-scoped,
which is why it takes the supervisor role rather than an agent parameter. A directory or a
path outside the store is a 404 or a 400.
PWA and static routes¶
/, /manifest.webmanifest, /sw.js, /icons/ and /fonts/.
| surface | behaviour |
|---|---|
| index | resolves scope and injects window.__WV_SCOPE__ = {agent, admin} to paint with; grants nothing |
| authenticated principal with no ledger entry | 403 page — no cockpit shell, no scope injection, no version string, no boot gate |
| that 403 page | echoes the identity, HTML-escaped |
/manifest.webmanifest |
per-agent — name and start URL follow the scoped agent |
| login proxy | passes four prefixes through unauthenticated, deleting any X-User-Email: /manifest.webmanifest, /sw.js, /icons/, /fonts/. / itself is not on this list — it is authenticated like everything else |
Every handler re-derives scope per request. See The webview gateway § Cockpit login.
WS frames¶
Two frame families share these sockets, discriminated on different keys. They have separate vocabularies, separate validation and separate demultiplexers, so they are counted separately below.
The t family¶
Frames are newline-delimited JSON, one per line. The admission set holds 33 names, and the
connector's inbound path drops anything not in it. Validation checks that t is a known
kind, and nothing deeper.
Seven of the 33 are the durable host-operation family, routed by the connectors rather than by
the gateway: host_op_sync, host_op_dispatch, host_op_cancel, host_op_receipt,
host_op_output, host_op_terminal, host_op_advertise.
That leaves 26 live t kinds:
inbound, inbound_ack, outbound, permission_request, permission_reply,
attachment_fetch, attachment_result, register, hello, reject, ping, pong,
op, op_result, op_cancel, fs_event, browser_tunnel, terminal_tunnel,
host_shell_tunnel, oauth_callback, oauth_callback_result, agent_message,
agent_roster, agent_message_result, agent_message_deliver, agent_message_ack.
reject is the Teams gateway's refusal frame; the webview gateway neither emits nor handles
it.
host_op_request and host_op_result are not in the admission set. The connector drops
either on arrival, and the gateway drops the pair by name as well rather than fanning it to a
lane's browser subscribers: a host_op_request carries a signed short-lived capability and a
host_op_result carries relayed command output.
The type family — host jobs and agent administration¶
host_job_request|dispatch|ack|event and
agent_admin_request|dispatch|ack|event|body_chunk — nine envelopes — are not t
kinds. They travel as {"type":"…"}, and the host dial-in read loop demultiplexes them on
type ahead of the t decode: agent_admin_* by prefix first, then the host-job router.
They are absent from the t admission set. A t frame has no type key, so it decodes with
an empty type and falls through to the original path untouched.
The host dial-in socket additionally carries host_status (host → gateway) and
host_status_request (gateway → host) on t. These are not in the admission set, which
governs the agent connector's inbound path rather than the host connector's.
An unrecognised kind in either family is ignored rather than refused.
| group | kinds | carries |
|---|---|---|
| op-relay | op, op_result, op_cancel |
every workspace, MCP and subsession route above; results route back by sequence id |
| — chunks | base64-encoded, so binary ws raw and ws render output survives the JSON frame |
|
| host jobs | host_job_request, host_job_dispatch, host_job_ack, host_job_event |
a verb run as root on another host; survives a gateway restart and a target reconnect |
| agent administration | agent_admin_request, agent_admin_dispatch, agent_admin_ack, agent_admin_event, agent_admin_body_chunk |
a verb run as one agent's own uid on its own host; the body chunk carries ws write and inject payloads |
| tunnels | browser_tunnel, terminal_tunnel, host_shell_tunnel |
the transports /browser/ and /terminal/ redeem |
| agent-to-agent | agent_message*, agent_roster |
agent_message_deliver paints a card; only /api/agentmsg/engage makes it a turn |
| delivery receipt | inbound_ack |
one per inbound carrying a meta.message_id; correlates on that id. The gateway waits for it before /api/inject answers {"ok":true}, but only from a peer whose register carried acks: true |
| liveness | ping, pong |
the agent's own application-level probe, in the direction the gateway's WebSocket control-frame ping cannot cover: that one is answered by the peer's TCP stack without its application seeing it |
For what the cross-host kinds carry, see Architecture § Reaching another host.
register carries the authoritative routing key and is the frame the gateway authorises a
dial-in on — see
The webview gateway § Dial-in: how an agent registers.
For lanes, see
Channels § Lanes.