Status: 0.1. This is the protocol as Dormouse implements it. It may change before 1.0.
A Dor Tool is a command that runs in a terminal and serves a page. A host is a terminal that runs the command and shows its page in the same pane. Dormouse is the first host. This document is what a second host, or a Tool written without this repository's packages, needs to agree on.
A run is one execution of the command, from its start to its exit. Everything a Tool tells a host holds for that run alone, and the host forgets it when the run ends.
What this document says a host or a Tool does is a rule for all of them; what it says Dormouse does is that one host's choice. Every length is counted in UTF-8 bytes.
The two sides talk over four channels. Only the save request is answered:
| Channel | Direction | Carries |
|---|---|---|
| Escape sequences in the Tool's terminal output | Tool to host | everything the Tool tells the host |
| The URL of the page's first request | host to Tool | a state to restore |
| One HTTP request to the Tool's own port | host to Tool | "save now", and the Tool's answer |
| The terminal's interrupt | host to Tool | "stop now" |
flowchart LR
tool["Tool: a command and its server"]
host["Host: a terminal and a page view"]
tool -- "OSC 367: serve, state, open, dehydrate" --> host
host -- "GET the page, first URL carries rehydrate" --> tool
host -- "POST: save now" --> tool
host -- "interrupt: stop now" --> tool
What a host must do
A Tool never asks what its host supports. It sends the messages it has a use for, and a Tool that never sends one never sees what that message brings. So the burden is on the host: a host does everything a Tool would notice missing.
| A Tool sends | Every host |
|---|---|
serve with a port |
shows the page, once it has checked that the port is the Tool's |
state, and a save path |
marks the pane unsaved, asks before closing it, and can ask the Tool to save |
open |
opens the named file in a pane other than the Tool's |
open with place: "self" |
interrupts the Tool and puts the target in its pane, keeps a history, and offers Back and Forward once there is one |
open without trusted: true |
asks the user before opening a file that would run script of its own |
open with a fragment |
hands the fragment to the run it starts for the target |
dehydrate, on the host's interrupt |
hands that state to the run it starts in the Tool's place |
A host may leave out only what a Tool cannot notice:
| A Tool sends | A host may |
|---|---|
dehydrate: true |
stop the Tool while it is out of sight and start it again later with its state; a host that never does has left nothing out |
open with place: "preview" |
reuse one preview pane; a host without one opens the file as any other |
Messages
A Tool writes a message to its terminal as one escape sequence. The spaces here are for reading; none is written:
ESC ] 367 ; <verb> ; <json> BEL
<verb>isserve,state,open, ordehydrate.<json>is one JSON object of at most 4,096 bytes, with"v": 1. A host ignores a message without it, one whosevit does not speak, and any field it does not know.- The sequence ends at
BELor atESC \; a host accepts both. A Tool writes no raw control character inside it: JSON already escapes U+0000 to U+001F, and a Tool escapes U+007F to U+009F as\u00XXtoo, since one of those can end the sequence early. - A host consumes every
OSC 367sequence, including malformed ones and verbs it does not know, shows none of it, and never replies. - Version 1 only grows. New optional fields and new verbs may be added, and a host ignores the ones it does not know. A message a version 1 host would misread carries
"v": 2, and a Tool that sends one sends the version 1 form first. This document's own number, 0.1, counts its text and not the wire. - A host ignores a malformed message whole.
serveis the exception: a host ignores each invalid field of one and keeps the rest. - No other terminal uses the number. The published sequence lists of xterm, iTerm2, WezTerm, ConEmu, mintty and DomTerm, and the terminfo.dev table, were read in 2026-12; none assigns
OSC 367, and the nearest is mintty'sOSC 440. A terminal that is not a host ignores it, as terminals do everyOSCthey do not know.
Terminal output is not trusted. A file printed with cat, or a program on another machine, can write these bytes too. A host must act on a message only when it comes from the output of a command the host itself started as a Tool, during that run. It must treat every field as untrusted text: bound it, drop control characters, and never let a path name another machine.
serve
Written once the Tool's server is listening, and again whenever a field changes.
| Field | Type | Meaning |
|---|---|---|
port |
integer, 1 to 65535 | the loopback port to show |
path |
string | the path and query to open on that port; default / |
save |
string | the path and query on that port for the save request |
dehydrate |
boolean | true: this run can be stopped and started again from its arguments alone |
name |
string | reserved; hosts read and ignore it |
- Each
servereplaces the one before it. Apath,save, ordehydrateleft out returns to its default, so a Tool restates them each time. Aservewith noportleaves the page showing. - A changed
portorpathmoves the page there. An unchanged one never reloads the page, or undoes where the user went in it. pathandsaveare at most 2,048 bytes, start with exactly one/, and hold no backslash, space, or control character (C0, DEL, C1). Each needs aportin the same message.- A
servewith noportis valid when it statesdehydrate,trueorfalse: a Tool with no page can still say how it stops, and takes it back withfalse. - A host must show a port only if the Tool's own process tree is listening on it.
servechooses among the Tool's ports; it never grants access to another program's.
state
{"v": 1, "dirty": true}
Written whenever the Tool's unsaved state changes. A host starts each run not knowing, and takes the latest report. A report is never a save and never permission to stop the Tool.
open
{"v": 1, "path": "/abs/notes/todo.md", "place": "preview", "trusted": true}
{"v": 1, "path": "/abs/notes/other.md", "place": "self", "fragment": "second-heading"}
| Field | Type | Meaning |
|---|---|---|
path |
string | an absolute local path: starting with /, or a drive letter followed by :\ or :/; at most 2,048 bytes, with no control character (C0, DEL, C1) |
place |
"preview", "self", or "new" |
where it opens: the host's reusable preview pane, this Tool's own pane, or a pane other than this one, which may be one already showing the file; default "new" |
trusted |
boolean | true: the user picked this exact file in the Tool's page; default false |
fragment |
string | a place in the target, such as a link's fragment, decoded: the text after #; at most 2,048 bytes, with no control character |
placesays where, andtrustedsays who chose. A Tool setstrusted: trueonly for a file the user picked directly, as in a file listing. It leaves it out for a target that came from content, such as a link in a document, whose author chose it.- A host asks before it opens a target that is not trusted and would run script of its own, such as an HTML file, and opens nothing if the user declines. It does not ask for a trusted one. A host cannot check the claim: it protects a user from content passing through an honest Tool, and is no defence against the Tool itself.
- The Tool gets no answer. It cannot tell an
openthat worked from one the host refused or the user cancelled. - A host passes a
fragmentunread to the run it starts for the target, inrehydrate. It is lost when the host shows a pane that already has the target. - What a
fragmentnames is the target Tool's to decide. For a Markdown heading, use the rule GitHub does, so that two Tools agree: lowercase the heading's text, drop every character but letters, digits,_,-, and spaces, turn each space into-, and give a repeat-1,-2, and so on. place: "self"stops the sender. The host checks that it can open the target, asks the user if the Tool reporteddirty: true, then interrupts the Tool and puts the target in its pane. From a Tool that was not started on a file or folder, there is nothing for Back to return to, so the host opens the target in another pane and leaves the Tool running. It stops nothing when the Tool or another pane already shows the target; it shows that pane.
dehydrate
{"v": 1, "state": {"tab": "open", "scroll": 1240}}
A small state the Tool writes after the host's interrupt, just before it exits. state is any JSON value except null, and means nothing to the host. A Tool with nothing to restore writes {"v": 1} with no state, which tells the host not to wait for one. A host keeps a state only from a run that announced dehydrate: true, only when it is written after the host's own interrupt, and only the last. It keeps the state value and nothing else from the message. Restoring state has the size limit.
The page
- The host opens
http://<address>:<port><path>.<address>is the loopback address the Tool listens on,127.0.0.1or[::1], never the namelocalhost. - The Tool's server sees a
Hostheader naming that address and port. A request from the Tool's own page carries noOrigin, or one naming the same. - The page may run at another origin than the Tool's: Dormouse shows it through a proxy on a port of its own, which passes the Tool no cookies and refuses a service worker. A page uses relative URLs, and keeps what it must remember in its URL or its server.
- Guard the port. Any page open in the user's browser can send a request to a loopback port, and a hostile site can point its own name at
127.0.0.1. A Tool that shows anything private puts an unguessable token, made fresh each run, inpath, and refuses a request whoseHostis not its own address and port.
Saving
A Tool that announced a save path can be saved from the host's "unsaved changes" prompt.
- The host sends
POST <save>to the announced port, at the page's address, withContent-Type: application/json, the body{"v":1}, and noOriginheader. It sends nothing unless that port is still the Tool's own. - The Tool saves, then answers
200with{"v":1,"dirty":false}, or with{"v":1,"dirty":true,"error":"Disk full"}to say why it could not. - The host counts it saved only on a 2xx reply with
dirty: falseand noerror, and only if nodirty: truereport came while it waited. It waits at most 15 seconds, follows no redirect, and reads at most 4,096 bytes. It takes the reply'sdirtyas astatereport.
sequenceDiagram
participant P as Tool's page
participant T as Tool's process
participant H as Host
T->>H: serve, with a save path
P->>T: an edit
T->>H: state, dirty true
Note over H: marks the pane unsaved
Note over H: the user closes the pane and picks Save
H->>T: POST to the save path
T->>P: save, in the Tool's own way
alt saved
T-->>H: 200, dirty false
Note over H: closes the pane
else not saved
T-->>H: 200, dirty true, and an error
Note over H: keeps the pane and shows the error
end
Put an unguessable token in the save path, made fresh each run. It is all that keeps another page from asking. A browser always sends Origin on a cross-site POST, so a Tool also refuses a save request that carries one.
Stopping and restoring
A host stops a Tool with the terminal's interrupt, the one a person sends by pressing Ctrl+C at a running command: the Tool's process receives SIGINT, or CTRL_C_EVENT on Windows.
| A host interrupts a Tool | Only if |
|---|---|
| to stop it while it is out of sight | its latest serve says dehydrate: true, and it did not report dirty: true |
to replace it, after its own open with place: "self", or on Back or Forward |
the user agreed, when it reported dirty: true |
| to show another file in a preview pane | it did not report dirty: true |
- A Tool exits within one second of the interrupt. A host may give up on one that has not: Dormouse abandons a replacement after that second, and kills a Tool it stopped out of sight after three.
- This is not the copy shortcut. A key pressed in the Tool's page belongs to the page. A host never turns it into an interrupt, so copying in a page never stops a Tool.
- A Tool cannot tell the host's interrupt from a person's. Both mean stop.
- A Tool with a terminal interface that reads keys itself receives the interrupt as the byte
0x03, with no signal. If it announceddehydrate: trueit must treat that byte as stop, so it cannot use Ctrl+C for anything else.
A Tool that announced dehydrate: true promises that its command and arguments alone start it correctly: the host runs the same command again, in the same directory. A host that may stop such a Tool may also close its pane without asking. Such a Tool may write a dehydrate message before it exits. The state only adds fidelity: a scroll position, an open tab. It is never a document; unsaved work belongs to state and saving.
Restoring state
The run a host starts in a stopped Tool's place gets the state back in the URL of its page's first request. The host appends one query parameter to the path the Tool announced:
http://<address>:<port><path>?rehydrate=<base64url of JSON>
The host builds the JSON: {"v": 1}, with "state" when it holds one, and "fragment" when an open named one. The value is base64url of the JSON's UTF-8 bytes, with no padding, so it uses only letters, digits, -, and _. For a state of {"top": 40} and a fragment setup:
?rehydrate=eyJ2IjoxLCJzdGF0ZSI6eyJ0b3AiOjQwfSwiZnJhZ21lbnQiOiJzZXR1cCJ9
A path that already has a query gets the parameter after &, and before any #. A Tool's own path and save never have a rehydrate parameter; a host ignores one that does.
- A host puts it on the first load of that run only, and hands a state to one run. The URL it remembers for the pane, and any reload, never carries it. A browser may request that first URL more than once.
- A Tool reads it from the first request for its page only, keeps it in its server for later requests, and starts from its arguments when it is absent or unreadable. A value that is not base64url of JSON of this shape is never an error; it is nothing held.
- A Tool treats it as untrusted: whoever reaches the page first can write that URL.
- The value is at most 4,096 characters, which is 3,072 bytes of JSON. A host that holds more drops the state and keeps the fragment. A Tool with more to keep can write a file and put its path in the state. Since the state is untrusted, it reads only a path it wrote itself; what that file holds is the Tool's own risk.
- A Tool with no page gets nothing back. It can still announce
dehydrate: trueand be stopped; it starts from its arguments.
A Tool stopped while hidden, and shown again:
sequenceDiagram
participant T as Tool, first run
participant H as Host
participant N as Tool, next run
T->>H: serve, with a port and dehydrate true
H->>T: GET the page
Note over H: the pane goes out of sight
H->>T: interrupt
T->>H: dehydrate, with a state
Note over T: exits
Note over H: keeps the state
Note over H: the pane is shown again
H->>N: runs the same command
N->>H: serve
H->>N: GET the page, rehydrate on this first URL
Note over N: restores from the state
H->>N: any later load, no rehydrate
A link, then Back
A link from one document to a heading in another, then Back. Each run is its own process, and the two Tools need not be the same program:
sequenceDiagram
participant A as Tool on a.md
participant H as Host
participant B as Tool on b.md
Note over A: announced dehydrate true
Note over A: the user clicks a link to b.md#second
A->>H: open b.md, place self, fragment second
Note over H: checks it can open b.md, and asks first if a.md is unsaved
H->>A: interrupt
A->>H: dehydrate, with its position
Note over A: exits
Note over H: history is a.md with that state, then b.md
H->>B: runs the command for b.md in the same pane
B->>H: serve
H->>B: GET the page, rehydrate carries the fragment
Note over H: offers Back, and the user presses it
H->>B: interrupt
B->>H: dehydrate, with its position
Note over B: exits
H->>A: runs the command for a.md again
A->>H: serve
H->>A: GET the page, rehydrate carries the state a.md left
Not in 0.1
- Declaring and starting a Tool. Each host has its own way. Dormouse reads a
dormouse.ymland runsdor tool <name>; the README shows both. A second host may read the same file or not. key. Aservefield by which a running Tool changes the identity Dormouse reuses its pane under. Identity comes from how a Tool is declared, which is not in the protocol, so neither is this.- Theme. Dormouse gives a Tool's page its colors by rewriting the page as it passes through a proxy, publishing
--vscode-*CSS variables, a body class, and adormouse:themeevent. None of that is protocol yet. A page should give every variable a fallback and followprefers-color-schemewithout one. The theme enters the protocol in 0.2. X-Dormouse-Preserve-CSP. A response header that tells Dormouse's proxy to keep the page's own Content Security Policy. It goes with the theme.