# Protocol: session

The `session` commands a program sends to a running game, as the engine describes them: what each takes, what it answers and what it does. Back to [all commands](../protocol-commands.md).

## session.hello

`session.hello {who: text, kind: text, model?: text, tag?: text, mode?: text} -> {hand: integer, who: text, kind: text, mode: text}` · read, read-only

Says who this connection is, so that what it writes names it: blame answers its writes as this hand, and an editor can show an agent's hand and put its change on trial. Said once; said again, it renames. A connection that never says is hand 0, "a client". The session keeps its hands for its life: the same who on a new connection is the same hand again. Over MCP an agent never has to call it: initialize's clientInfo says it (frost mcp --join --who too).

| Parameters | Type | Meaning |
| --- | --- | --- |
| `who` | text | The name a person knows this client by, 1 to 64 characters: "Claude", "Ana". |
| `kind` | text | "person" for someone at the editor, "agent" for a program that acts for one. |
| `model?` | text | For an agent, the model it runs on, as it names it. Left out: none said, or the one said before. |
| `tag?` | text | The editor's own name for what this hand is doing (a conversation, a task), at most 64 characters: kept and given back by session.hands, never read. The same who with another tag is the same hand; the tag shown is the last said. Left out: the one said before. |
| `mode?` | text | "plan", "ask", "trial" or "free": the editor's mode for this hand (frost mcp --mode). The engine holds "plan": a planning hand's command that is not read-only is refused (E0447), and it stays planning under any name its connection says next and under its name on any connection, until the editor's session.mode changes it (E0448 for a hello that asks another). Left out: the one said before, or "free". |

| Result | Type | Meaning |
| --- | --- | --- |
| `hand` | integer | This connection's hand from now on: 1 and up, the same for the same who all session long. |
| `who` | text | The name, as kept. |
| `kind` | text | "person" or "agent". |
| `mode` | text | The hand's mode now. |

## session.hands

`session.hands {} -> {step: integer, hands: [record], clock: record}` · read, read-only

Lists everyone who said who they are in this session, connected or not, with what each last did to the game: for an editor to show who is at work on the game and what they changed.

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `hands` | [record] | One {hand, who, kind, model, tag, mode, connected, since, writes, last_write, last_change, last_run} per hand, in the order they first said hello. connected is whether a connection is that hand now. since is the step it first said hello at. writes is how many commands that write it has carried out. last_write is the field its last world.set wrote, {entity, component, field, step}, the entity as it named it, or null. last_change is the last of its script.reload, world.set, world.spawn, world.despawn, scene.load, tuning.set and save.set: {what, name, line, step, n, mode}, name being what it changed (the script, the entity, the scene, the tuning name or the save slot), line for a script.reload the first line, from 1, of the new code that is not as the code it replaced (null when that code is not known, or for another command), and n a count for the whole session of changes and runs, so that they can be put in order; or null. last_run is its last game.step, game.seek or game.try that left the game at the end of its recording (its replay's steps, or where the recorded input ends): {to_step, checksum, matches_replay, n}, checksum the world's there. matches_replay is true when the run comes to the run checksum the project's replay records and false when it does not, both only when nothing but the recording had moved the game from step 0 (no game.step on held input, world.set, input.set, script.reload, tuning.set or other change on the way); null otherwise, and when the game has no replay or was played past it. It is worked out the first time it is asked, by playing the recording again aside: a pane that asks once a second pays for it once a run. A last_run whose n is above its last_change's n is a run of the game after the change. |
| `clock` | record | Who moved the game to the step it is at: {hand, what, step, n}, the hand (0 for a connection that never said who it is), the command (game.step, game.seek, game.reset, game.try or game.restore), the step it left the game at and n as in last_change; null when nobody has. One game has one clock: requests are carried out one at a time in the order they arrive, so the later of two seeks wins, whoever sent each. An editor that sees another hand here knows the game was moved under the person's scrub. |

## session.writes

`session.writes {hand?: integer, since?: integer} -> {step: integer, writes: [record], next: integer, kept: integer, missed: integer}` · read, read-only

Lists every change the hands made since a point, oldest first: what session.hands gives as each hand's last_change, all of them, so that an editor can mark each edit of a hand and none is lost between two asks.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `hand?` | integer | Only this hand's changes. Left out: every hand's. |
| `since?` | integer | The `next` of the ask before: only the changes since. Left out: every change kept. |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `writes` | [record] | One {n, hand, what, name, line, step, mode, at_ms} per change, oldest first: n, what, name, line, step and mode (the hand's mode when it was made) as session.hands says last_change (n counts the session's changes and runs, so two hands' changes are in order); hand is whose; at_ms when it was made, in milliseconds from the first change kept, by the server's clock. |
| `next` | integer | What to send as `since` next time to get only what comes after. |
| `kept` | integer | How many changes are kept at most, the latest (4,096). |
| `missed` | integer | When `since` is older than the oldest change kept: about how many changes since it are gone (counted by n, so runs and clock moves are in it too); else null. |

## session.mode

`session.mode {hand: integer, mode: text} -> {hand: integer, who: text, mode: text}` · read, read-only

Sets a hand's mode, from the editor only: the program that started the session, on its standard streams (frost serve --stdio). A hand in "plan" reads and does not change the game: every command of it that is not read-only (a step, a seek, a try, a write, a restore, a reload, project.*) is refused with E0447, while reads, pictures and world.series stay open. A connection that came with the port's read-only token is planning under any name until this lets the hand it says it is (a mode other than plan), and planning again when this sets plan. Asked by any other connection: E0448.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `hand` | integer | The hand, as session.hands numbers it, from 1. |
| `mode` | text | "plan", "ask", "trial" or "free". Only "plan" changes what the engine does; the others are the editor's to show. |

| Result | Type | Meaning |
| --- | --- | --- |
| `hand` | integer | The hand. |
| `who` | text | Its name. |
| `mode` | text | Its mode now. |

## session.token

`session.token {tag: text, mode?: text} -> {tag: text, hand: integer, mode: text, file: text}` · read, read-only

Gives the hand of a tag a token of its own, from the editor only (the session's standard streams; E0448 from anyone else): writes a join file for that hand alone, for this user only and removed when the session ends, which frost mcp --join-file takes as it takes the session's. A connection that sends that token is that hand, before it says anything and under any name or tag it says, and no other connection is: a name never joins it. The hand changes the game or only reads it as its mode says: session.mode {hand, mode: "plan"} holds every connection that came by its token, the ones open and the ones made later, to reads (E0447 on the rest), and another mode lets them write again. Asked again for the same tag, it answers the same hand and token and writes the file again. The session's own token stays the editor's. A hand's token sent to a session that never gave it is refused at the port (E0458).

| Parameters | Type | Meaning |
| --- | --- | --- |
| `tag` | text | The editor's own name for the conversation or task this hand is, 1 to 64 characters: one hand and one token per tag. |
| `mode?` | text | "plan", "ask", "trial" or "free": the hand's mode from now. Left out: "free" for a new hand, as it is for one given before. |

| Result | Type | Meaning |
| --- | --- | --- |
| `tag` | text | The tag. |
| `hand` | integer | The tag's hand, as session.hands numbers it: what session.mode takes. |
| `mode` | text | Its mode now. |
| `file` | text | The join file written: the session's own join file's name with .handN after it, holding {address, token, game, engine, pid, read_only: false, tag, hand}. The token is in the file only. |
