Watch
The watch page is a browser over the sessions this process holds. It runs on a separate
listener at 127.0.0.1:8081 by default. Enable native passkey login, GitHub OAuth, Cloudflare
Access, or any combination. With zero providers, the watch listener stays closed. /mcp on
both HTTP listeners requires x-terret-key. The local listener and stdio offer no watch UI.
Open /watch/login for native passkey or GitHub sign-in. After GitHub redirects back, choose
Open watch. A verified Cloudflare Access assertion opens /watch directly. Native and GitHub
sessions offer Sign out. To end a Cloudflare session, sign out through Cloudflare Access.
terret.passkey.mcpStepUp does not affect native passkey sign-in, steering, or enrollment.
See Config for the keys and Operations
for setup.
Reading
GET /watch lists sessions. GET /watch/{id} shows that session. An id that is not a session
is the same generic denial as a missing token: status 401, body access denied, and the value
is not echoed. Running and open sessions stay listed. An ended session stays listed while
inactive is show (the default) and its id is not in gone. inactive=hide drops ended
sessions from the list and leaves the journal alone.
View controls are GET links. The query is the shareable view. Absent keys mean the defaults.
An unknown key, a value past its cap, or more than 16 keys is status 400, body bad query, and
the value is not echoed. after and datastar are reserved for the live feed and are not view
keys.
| Key | Default | Meaning |
|---|---|---|
kinds | every kind except Thought and Turn | Comma-separated event kinds. A name that is not a kind is a bad query. |
tool | unset | Keep rows for that tool. |
status | unset | Keep rows for that status. |
q | unset | A search string. It is CSS-escaped into a nonce'd style, so it cannot close the style element. |
layout | tree | tree, timeline, or panel. |
output | 64k | 20, 64k, or full. |
inactive | show | show or hide. |
keys | vim | vim or plain. The page client uses this table for keyboard navigation. |
open | empty | Row ids whose details are expanded. |
gone | empty | Ended session ids hidden from the list. |
row | unset | The row the page scrolls to. |
A row's details control is a GET link that adds or removes that id in open. Child rows stay
under their parent. Text, tool names, and statuses are redacted before they are written into the
page, and the markup escapes them.
GET /watch/{id}/events is the live feed, text/event-stream. The cursor is Last-Event-ID
when that header is present, otherwise after. Both are exclusive. A negative, non-numeric, or
oversized cursor is a bad query. The first frame marks the feed live. Later frames replace the
feed element. A heartbeat is a comment, not an event. Eight streams per viewer, then status 429,
body too many streams. Terret identifies a viewer by their signed-in provider or by a hash of
its verified Access JWT. Closing the stream releases the slot. Interrupting the feed leaves the turn running.
cancel is still the only stop.
/watch.js is the linked Scala.js client for this page, built with ascent's DOM on the same
Scala.js toolchain as the session card. The app build links the client and packages it as the
classpath resource terret/watch-client.js. The client scrolls the feed, moves focus, and calls location.assign only for a picker
value that starts with /watch, for the current URL with the q parameter set or removed, or
for the href of the selected row, or for a validated watch destination after approval. It opens
an EventSource on the feed's data-stream
attribute and applies datastar-patch-elements frames. It also handles mutating watch forms with
same-origin fetch and WebAuthn approval, as described below. It calls no MCP tools. /watch.css
is the style. Both are script-src 'self' and
style-src 'self'. The document adds a per-response nonce for its own style. The page does not
inline the client.
MCP approvals
Mutating MCP tools require a fresh passkey assertion when terret.passkey.mcpStepUp is true
(default false). With a configured watch listener and a compatible passkey origin,
authenticated HTTP MCP calls that need approval can wait while you review them out of band in
/watch. A headless MCP client makes its normal tool call; the browser handles WebAuthn for that
call, using Touch ID on supported Macs or another enrolled passkey. Open /watch on the
configured passkey origin, for example terret.earlyeffect.rocks/watch,
and sign in as the owner.
Pending MCP approvals shows each tool, its workspace or session when present, a short argument preview, and when the request expires. Large values are shortened and arbitrary downstream tool arguments are hidden. The page renders the current queue on load and uses a server-sent event stream for changes; it works even with no session selected.
Approve (Touch ID) asks the browser to verify an enrolled passkey for that one call. The waiting MCP client receives the normal tool result after execution. The watch page stays open.
Deny ends the call with
approval_deniedand requires no passkey ceremony.Expiry ends the call with
approval_timeoutand awatchUrl. Open the watch page and retry the call to create a fresh request. The server defaults to 120 seconds; see Config.
The queue holds up to 32 pending calls. When full it returns approval_queue_full. Calls and
approvals are held in memory for the lifetime of the running process. Each call must be approved
separately. See Security for inline clients and challenge binding.
Steering
Steering is POST, on the tunnel listener only. Each request requires a fresh passkey assertion
in x-terret-step-up, plus the synchronizer token in the form field csrf. A request without
an assertion returns 403 with approval_required and a single-use challenge. The challenge binds
watch_mutation to the method, path, rendered query, and UTF-8 form body, including csrf.
The Security page specifies the header and assertion format.
Ordinary watch forms use the Scala.js client to complete approval:
Submitting captures the action URL, query, and URL-encoded form once. The capture includes
csrf, the keyboard mode, and the actual submit button, so Stop and send keepsmode=stop.The client sends that request without an assertion. Status 403 with
approval_requiredsupplies the single-use challenge, configured relying-party id, and user-verification policy. No action has run yet.The browser asks for an enrolled passkey through WebAuthn. The client sends the assertion in
x-terret-step-upon one retry with the same URL and body.The client requests
application/json. An approved action returns status 200 with alocationfield, and the client navigates to that same-origin watch destination. Signed clients that omit JSON negotiation keep the existing status 303 response.
The client disables redirect following on fetches, accepts only same-origin watch actions, and checks the destination before navigation. Duplicate submissions are blocked while approval is pending. Changing a field during approval leaves that edit for a later submission. Failures keep the fields and show a safe message, including cancellation, unavailable WebAuthn, and an unenrolled passkey. A refusal ends that attempt. The client performs no unsigned fallback or automatic approval loop. Closing the page releases its listeners and cancels pending requests and ceremonies. An approved POST may already have executed when its response is lost. Check the session before submitting again; the client never resends an uncertain mutation. Returning to a document held in the browser's back-forward cache reloads it so approval and the live feed get fresh scoped workers.
Enroll a passkey
When native login starts with an empty credential file, Terret prints a one-time enrollment code.
Open /watch/login, enter the code, and choose Enroll passkey within ten minutes. The code
unlocks first-key enrollment only. After enrollment, sign in with the new passkey. A GitHub or
Cloudflare Access owner can sign in and enroll the first key directly from /watch.
Your browser asks your device, password manager, or hardware key to create an ES256 discoverable passkey. For each additional key, approve enrollment with an existing passkey when prompted. Use a different authenticator if your current one already holds the passkey.
The client sends two URL-encoded requests with csrf. POST /watch/passkeys/begin issues the
registration challenge and creation options. POST /watch/passkeys/complete submits the challenge,
credential ID, client data, and attestation. Once a credential is enrolled, completion requires a
fresh x-terret-step-up assertion bound to those exact fields. A cancelled approval can leave
a credential on the device that Terret never enrolled. The page reports success only after the
server confirms it.
Configure terret.passkey.rpId, terret.passkey.origins, and terret.passkey.userVerification
for the watch origin. The default empty origin set disables enrollment and denies assertions.
terret.passkey.file persists enrolled public keys; omitting it keeps the keys only until the
process exits. Reading and the live feed remain available without passkeys. See
Config and Security for the policy and storage contract.
| Path | What it does |
|---|---|
POST /watch/open | Open a session. Fields are workspace, model, allow, and mcp. There is no worktree field. A path that leaves a configured root is refused. |
POST /watch/{id}/run | prompt, and mode send or stop. The buttons are Send and Stop and send. send starts the prompt, or queues it while a turn is running. stop cancels the running turn and starts this prompt ahead of the queue. |
POST /watch/{id}/cancel | Stop the turn. |
POST /watch/{id}/resume | Resume. It does not send a prompt. |
POST /watch/{id}/queue/{item} | Replace that queued prompt. |
POST /watch/{id}/queue/{item}/drop | Drop that queued prompt. |
An empty prompt is status 400, body empty prompt. A prompt over 16384 characters is status
400, body bad prompt. A busy session is status 409. An unknown session, an unknown queue
item's session, and a missing token are the same generic denial, and the steer action is not
called. A queued prompt is edited or dropped only when that item is still queued.
Requests that change state
Steering checks each request in this order. Enrollment uses the same ingress and CSRF checks, then requires step-up at completion when the store already has a passkey.
Sec-Fetch-Site: cross-site, or anOriginwhose host is not the requestHost, is status 403, bodyaccess denied. This check also covers/mcp. A client that sends neither header still reaches the later checks.A watch POST must send
Sec-Fetch-Siteofsame-originorsame-site, and anOriginwhose host equalsHost. Without that pair the response is 403.The body must be
application/x-www-form-urlencoded. Another type is status 415. A body that is not a form is a bad query.A configured provider must authenticate the owner.
A fresh passkey assertion in
x-terret-step-upmust approve this exact request. Missing, malformed, expired, replayed, or unenrolled assertions return 403 before steering.The
csrffield, or theX-CSRF-Tokenheader, must be the token this process minted for that viewer. One token is kept per viewer, so a second tab reuses it. The compare does not stop at the first differing byte. A missing or wrong token is the generic denial.
The page sets Content-Security-Policy (default-src 'self', script-src 'self',
style-src 'self' plus the document nonce, base-uri 'self', form-action 'self',
frame-ancestors 'none'), X-Content-Type-Options: nosniff, X-Frame-Options: DENY,
Referrer-Policy: strict-origin, and Cache-Control: no-store. The tunnel listener also sets
Strict-Transport-Security. Referrer-Policy is strict-origin so a same-origin form POST
still sends Origin.
Session card
open is the launch tool for a read-only MCP App. tools/list puts
_meta.ui.resourceUri of ui://terret/session on open and on no other tool. open is visible
to the model only, so the card is not granted a tool. resources/read of that uri returns one
static document, text/html;profile=mcp-app. Heddle also publishes the document's script hash on
the resource. The card asks for no network origins and no browser permissions, and for an opaque
origin, a fresh one per mount.
The document is the same bytes for every session. Its script is the linked Scala.js view, rendered
with ascent's DOM and inlined so the resource carries that script's hash. That link is build
output and is not stored in the repository. It does not contain an
access key, an Access JWT, a workspace path, or a session id. The host paints the first view from
the open tool result (ui/notifications/tool-result). The card calls no tools and uses no
polling. The Security page covers passkey assertions and resource authorization.
A host that advertises experimental.serverResources.subscribe can relay resources/subscribe
for terret://session-states. It must have a session-capable MCP connection and forward
notifications/resources/updated. The card reads once after subscribing, then after matching
notifications, and updates only the launch session's phase. Unsupported hosts and rejected
subscriptions keep the initial result and show not live.
The view attempts to unsubscribe on teardown. Heddle releases membership on disconnect, and a reconnected host must subscribe again. A host that shares one MCP session across mounted views must keep their subscriptions independently scoped or reference-count the shared resource.
The view posts only to its parent, with target origin *. It assumes an opaque origin (null)
and accepts messages only from that parent, by window identity. It does not learn the host's
origin, and it does not embed one. The host's CSP is the policy the card asks for: no network
origins, no browser permissions, and a script pinned by the published hash.