Expand description
One connection: the upgrade, what the server says first, and the loop that answers what a client asks for.
Re-exportsยง
use std::path::Path;๐use std::sync::Arc;๐use std::sync::atomic::AtomicBool;๐use std::sync::atomic::Ordering;๐use std::time::Duration;๐use std::time::Instant;๐use axum::extract::ws::Message;๐use axum::extract::ws::WebSocketUpgrade;๐use axum::extract::ConnectInfo;๐use axum::extract::State;๐use axum::http::HeaderMap;๐use axum::http::StatusCode;๐use axum::http::header;๐use axum::response::IntoResponse as _;๐use axum::response::Response;๐use futures_util::SinkExt as _;๐use futures_util::StreamExt;๐use tokio::sync::mpsc;๐use tokio::sync::oneshot;๐use base64::Engine as _;๐use forge_primitives::SessionSlot;๐use forge_primitives::browser::BrowserFrame;๐use forge_primitives::browser::BrowserInputEvent;๐use forge_primitives::browser::BrowserTabList;๐use forge_primitives::browser::BrowserViewState;๐use forge_primitives::browser::MouseAction;๐use forge_primitives::document::DocumentRead;๐use forge_primitives::wire::COMPRESSED_JSON_TAG;๐use forge_workspace::browser::BrowserAttachment;๐use serde_json::json;๐use super::batch;๐use super::batch::Batch;๐use super::envelope::ClientMessage;๐use super::envelope::ClientSettings;๐use super::envelope::SeatFrameWire;๐use super::envelope::ServerMessage;๐use super::envelope::SettingsRefusal;๐use super::envelope::Subject;๐use super::frame::FrameTransport as _;๐use super::origin as origin_gate;๐use super::wire::FileContentWire;๐use super::wire::OpenTimings;๐use super::wire::ReviewedThreadWire;๐use super::wire::cap_message_record;๐use super::wire::cap_tool_records;๐use super::wire::conversation_for;๐use super::wire::encode_subject;๐use super::wire::encode_subject_timed;๐use super::wire::floor_cursor;๐use super::wire::page_within;๐use super::wire::placement_wire;๐use super::PROTOCOL_VERSION;๐use super::TransportState;๐use super::WRITE_BOUND;๐use super::WriteStalled;๐use super::write_within;๐use crate::live::Live;๐use crate::surface::DictateOutcome;๐use crate::surface::ViewSurface;๐use crate::Command;๐use crate::DispatchError;๐use crate::SeatUpdate;๐use crate::SessionUpdate;๐
Structsยง
- Abort
OnDrop ๐ - A task that is aborted when its handle drops, so a read nobody will answer does not outlive the subscription or the socket that asked for it.
- Answer
Lanes ๐ - The connectionโs own loop, so that every way out of it runs the detach above rather than only the clean one. The connectionโs answer lanes, bundled so the loopโs signature carries them as one piece of state rather than two.
- Arrival ๐
- A message on its way through the loop: who sent it, and when it reached this connection. The instant is the arrivalโs rather than the handlingโs, so an ask that queued behind an earlier read pays that wait in its open.
- Attached
Client ๐ - Counts this connection among the attached clients for as long as it
lives, so a document hand-off can tell a viewer exists to open on. A
guard, for the same reason
Holdsis one: the count must come back down however the connection ends, a dropped socket included. - Browser
Viewing ๐ - This connectionโs browser half: the tab it draws and the strip it follows.
- Caller ๐
- This connection as the log names it: the number its takes are told apart by, and the address it is attached from.
- Claim ๐
- One seatโs claim: the seat, and the generation of the take that holds it.
- Client
Socket ๐ - This connectionโs socket, with the one fact the write path needs from the upgrade: whether the client declared it can inflate a compressed frame.
- Connection
Life ๐ - What a connection leaves behind when it ends.
- Frame
Write ๐ - One frameโs write, measured: its size, the time the socket took it, and whether the write yielded at least once before it was done.
- Holds ๐
- The seats this connection is holding, each given back when this drops.
- Keepalive ๐
- One connectionโs keepalive: the ping it has out, if any.
- Open
Report ๐ - One subscribeโs open, as its write and its log state it.
- Peer
Vanished ๐ - The peer stopped answering the keepaliveโs ping, so the connection was ended from inside its own loop.
- Progress ๐
- The connectionโs own clock: one stamp per completed socket write, and the seat it last said it was showing.
- Read
Answer ๐ - One subscribe read finished off the loop.
- Read
Answer ๐Guard - Answers the loop if the read task ends without doing so. A panic in the encode must not leave the connection waiting on a record nobody owes: no answer leaves the read in flight for the connectionโs life, and every later subscribe queues behind it in silence.
- Reading ๐
- The subscribe read this connection is waiting on, and what arrived for it while it ran.
- Reads ๐
- The connectionโs subscribe reads: the one served off the loop, the asks that queued behind it, and the channel its task answers on.
- Sent
Words ๐ - The words a review write sends, the seat they were the readerโs in, and what the writeโs own reply says when it landed.
- Settings
Push ๐ - The settings push this connection follows: the watch it hears and the frame its greeting already wrote.
- Streaming ๐
- What this connection is streaming: the seats it has claimed takes for - a startโs seat is claimed as soon as its dispatch answers, so a refused one keeps its entry, and a frame that follows a start always finds the seat - and whether it is recording the read-aloud set. A dictation frame carries no seat of its own - and the recording carries none at all - so these are what address one.
- System
Clock ๐ - The shipping clock: the processโs own monotonic one.
- Terminal
Viewing ๐ - The terminal this connection is viewing.
- Terminal
Viewing ๐State - This connectionโs terminal half.
- Viewers ๐
- The viewer halves one connection carries: the browser tab it draws and the terminal it is attached to. One value rather than four arguments, because the read loop already carries the connectionโs whole mutable state and the pair would push every handler past the arity a reader can hold.
- Viewing ๐
- One tab this connection is viewing: its profile, its id, its frames and its state.
- Watching ๐
- What this connection is watching, and which of it is on screen.
- Wedge
Stalled ๐ - A connection task that stopped making progress.
Enumsยง
- Answer ๐
- What a task off this loop asks it to send.
- Ask ๐
- What a
moreasks for, out of the cursor it was sent. - Beat ๐
- What one beat should do.
- Below
Floor ๐ - What a paging read below the held windowโs floor resolves to.
- Frame
Route ๐ - Where one binary message went, decided without touching a take.
- Queued ๐
- An ask waiting behind the connectionโs read.
- Terminal
Event ๐ - What the terminal has for the loop.
- View
Event ๐ - What a viewer has to say to the loop.
Constantsยง
- BOUNDARY_
TRIES ๐ - How many of a windowโs rows a below-floor page tries to start from.
- COMPRESSED_
MIN_ ๐BYTES - The JSON bytes at which a frame crosses compressed, for a connection that declared the capability.
- HEARTBEAT_
DEAD ๐ - How long a ping may go unanswered before the connection is reaped. Four missed beats: long enough that a busy peer is never cut, short enough that a role is not held by a corpse for the minutes a TCP retransmission timeout takes. Chosen, not measured: the one number it changes for a person is how fast a call on a paused host fails (a tool callโs own bound is longer).
- HEARTBEAT_
EVERY ๐ - How often a connection is asked to prove it is still there.
- MAX_
CLIENT_ ๐MESSAGE_ BYTES - The largest message a client may send.
- MAX_
HELD_ ๐READ_ FRAMES - Frames held for a seat whose record is being read. The record is encoded after them, so everything below its seq is discarded by the client and the newest are the ones worth keeping; a read that never ends stays bounded.
- WEDGE_
DEAD ๐ - How long a connection may write nothing before a watchdog outside its future ends it.
Traitsยง
- Write
Clock ๐ - The clock a measured write reads.
Functionsยง
- answer_
ask ๐ - Answer one strip ask: through the reply it carried, or as the error frame when it carried none.
- answered ๐
- Dispatch one of those, and answer the client that asked.
- answers_
through_ ๐a_ reply - Whether a command reports its outcome through the reply rather than through an update on the subscription.
- attach_
terminal ๐ - Attach this connection to a seatโs terminal as a viewer.
- attach_
view ๐ - One viewerโs attach: the same body for a tab number and for a hand-offโs page, because everything after the resolution is identical.
- below_
the_ ๐floor - Two cursor forms, one walk. The windowโs newest page hands back the
frame index its front sits at; every page below the floor hands back a row
cursor (
r:<byte>[:<id>]) minted from the row it reached. A frame cursor cannot be resolved to a row, because the frames the CLI streams and never writes sit between the windowโs rows, so no arithmetic lines the two numberings up. It is answered from the windowโs oldest row the file resolves instead: overlap at worst, never a gap, and a walk from any cursor converges on the same descending chain. - boundary_
candidates ๐ - The rows a walk below the window may start from, the walkโs own stop first and the rest of the window behind it.
- call_
output ๐ - A callโs own output, read from the transportโs held copy of its seat.
- carries_
a_ ๐result - Whether a frame is a user row carrying a tool result - the frame a stop may not land on, because the call it answers sits just beneath it.
- cron_
names_ ๐off_ loop - The cron pairings a pageโs rows need, read off the connection loop.
- discrete_
gesture ๐ - Whether one gesture is worth its own record: a pointer move and a wheel are streams, so their refusal is the clickโs that follows and logging every one would bury the answer in it.
- dispatch_
answering ๐ - Dispatch one reply-carrying command and hand its answer to the connection.
- dispatch_
refusal ๐ - One refused dispatch, as the frame the asking client reads: the operation the refusal names, the coreโs own words, and the dispatch id the press that made it minted - echoed so a press can attribute this refusal to itself rather than to whatever was pressed last.
- dispatched ๐
- Which hand sent what (issue #2372: a parked hand-offโs answer arrived over the socket and could not be attributed - no dispatch named its connection). Logged where a command is actually dispatched: a refusal never was.
- document_
answer ๐ - One document readโs outcome, as the asking client reads it: the answer with the documentโs bytes base64, or the refusal under the seat that asked - the seat is what lets a client holding several seats drain only its own.
- drive ๐
- Read what a client sends, and hear what its subscriptions asked for.
- ending ๐
- Why a connection ended, for the teardown records that run after it: a wedge and a clean close leave the same marks to release, and a reader looking at one of them has to know which it was.
- finish ๐
- Everything a connection leaves behind, undone on every way out of it: a clean close, a failed read, and a connection the watchdog dropped.
- finish_
read ๐ - Answer a subscribe read that ran off the loop: its record, its refusal, or nothing when the client let the seat go while it ran.
- for_
a_ ๐client - The update as it crosses to a client.
- forward_
queued ๐ - The frames a subscribe read out of the stream it replaced: filtered for this connection, and bounded like every other path to a client (#2374).
- forwards ๐
- Whether this connection forwards one update.
- frame_
bytes ๐ - The bytes a frame carries, which is what the writeโs own record reports.
- frame_
for ๐ - One message as the frame this connection sends: text as it always was, or
a gzipped body behind
COMPRESSED_JSON_TAGwhen the client declared the capability and the body is over the threshold. - frame_
for_ ๐flag - frame_
route ๐ - Decide one binary messageโs destination.
- gesture_
kind ๐ - The gestureโs kind, for a record that names what was refused without carrying it. A typed text is never logged, only how long it was.
- greet ๐
- Greet, then serve the client until it goes.
- greeting_
for ๐ - The frame that tells a client it is speaking to a forge and carries the
[client]sets it draws with. Built when the connection opens, so a reload applies to the next connection. - gzipped ๐
- handle_
client ๐ - Answer one client message.
- handle_
message ๐ handle_clientwith the message already read, so a subscribe that queued behind a read off the loop takes the same path the socketโs own did.- is_
take_ ๐news - Whether this update is one of a takeโs own.
- log_
open ๐ - The openโs two records: the snapshotโs write, and the sessionโs slices.
- mint_
connection_ ๐id - The next number for a connection, unique for the processโs life.
- next_
tab_ ๐change - The next tab list this connection asked to follow, or a future that never
resolves while it follows none - the same shape
next_view_eventuses, so a connection with no strip parks rather than ending the loop. - next_
terminal_ ๐event - The next thing this connectionโs terminal has for the loop.
- next_
update ๐ - The streamโs next update, or a future that never resolves while there is none - which is what keeps the branch out of the way until the client has subscribed and the role is known.
- next_
view_ ๐event - The next thing this connectionโs viewer has for the loop.
- open_
stream ๐ - This connectionโs stream from the core, opened when the client first subscribes and registered with the role that subscribe declares.
- ours_
to_ ๐hear - Whether this connection is one of an updateโs readers.
- page_
of_ ๐span - The page a span of transcript rows answers with, cursors and all.
- refusal_
tag ๐ - The operation a dispatch refusal names, which a client routes by.
- refuse_
attach ๐ - Answer a refused attach: through the clientโs reply when it sent one, and as the protocolโs error frame otherwise.
- released_
subscribe ๐ - The answer a subscribe owes when the subject it named was released before any read for it could land.
- row_
cursor ๐ - The row a page below the floor is asked for, out of a cursor this server minted: the byte the walk reached next, and the id that row carries where it has one.
- row_
cursor_ ๐of - A row as the cursor a page below the floor hands back.
- row_id ๐
- The id a transcript row names a frame by, for the frames that carry one.
- rows_
below_ ๐floor - Answer a page below the held windowโs floor from the sessionโs transcript.
- run_
connection ๐ - send ๐
- send_
frame ๐ send, answering how many bytes the frame carried.- send_
frame_ ๐timed send_frame, timing the socketโs share of the write.- send_
terminal_ ๐view - Send the attached terminalโs screen as a VT stream, and where the stream continues from.
- send_
text ๐ - Write an already-encoded frame. The settings document is encoded once per reload and shared, so a connection writes its bytes rather than building the frame again.
- set_
showing ๐ - Move this connectionโs shown seat, spending exactly what that showing earns.
- spawn_
read ๐ - Spawn a subscribe read off the connectionโs loop, with its answer guard armed INSIDE the task: an encode that panics must still answer the loop, or its read stays in flight for the connectionโs life and every later subscribe queues behind it in silence.
- spend_
showing ๐ - Spend what showing
slotearns: its diamond, its failure mark and its death trace, and the home refresh a spent mark owes. - stamp ๐
- This connectionโs own stamp on the commands that carry one.
- submit_
landed ๐ - Whether a submitโs reply carries a sealed round, which
nulldoes not. - supervise ๐
- Run one connection under the wedge watchdog.
- take_
frame ๐ - Push one dictation frame into this connectionโs takes or its read-aloud recording, recording anything else.
- text_
chars ๐ - How many characters a refused text carried, and nothing of what they were.
- transcript_
frames ๐ - The frames a range ask is answered with once the seatโs own window has shed them: the conversationโs own rows, numbered to END at the rangeโs end.
- upgrade
- Take the upgrade and give the connection its own task.
- upsert_
landed ๐ - Whether an upsertโs reply says the store took the write.
- words_
sent ๐ - write_
snapshot ๐ - Write a subscribeโs snapshot, register the subject, log the open and spend the showing marks the snapshot completes.