notes

The terminal contract

Milestone 28. This is the interface a terminal presents, written down so that the programs on either side of it can be built independently and swapped without either one knowing. Milestones 29 (the display terminal) and 31 (the capability shell) implement against this contract rather than against line_editor, the particular component that satisfies it today.

A terminal sits between two driver endpoints and an application:

  input driver ──OPERATION_BYTES──►┌──────────┐──text──► console server ──► UART
                            │ terminal │
       application ◄─lines──└──────────┘◄─OPERATION_WRITE / OPERATION_READLINE── application

Nobody in that picture can name anyone else. The input driver holds "a rendezvous I send wire bytes to." The application holds "a rendezvous that prints text and reads lines." The console server holds "a rendezvous requests arrive on." Rendezvous-only naming (nifeos/nife:notes/ipc-naming.md) is the whole point: rewire the rendezvouses and no client can tell the terminal changed, which is milestone 23 (a capability-routed component OS with live replacement)'s hot-swap claim in component form. See nifeos/nife:notes/line-discipline.md for the component that implements this today and why it was built rather than ported.

The two halves of the contract

A contract has a wire half and an IPC half, and they are independent.

The protocol is a userspace protocol, not kernel ABI. The kernel routes these words the way it routes any IPC (§10, §12); it never reads an opcode. Adding an opcode is a change to this note and to terminal_contract, not a change to the system call surface.

The IPC protocol

Every request is an endpoint CALL (DECISIONS §12): the client sends two words and blocks until the terminal replies through the one-shot Reply capability the kernel mints. The first word packs an opcode in bits 63:56 and a length or count in the low 32; bits 55:32 are reserved and zero. proto::req(op, len) builds it; proto::op and proto::len take it apart.

Bulk data never rides in the words. It travels in pages the client shares with the terminal, one outbound and one inbound, exactly the §10 split: control by message, data by shared memory. A client maps an output page (it writes, the terminal reads) and an input page (the terminal writes, it reads).

Opcode Direction First word Second word Reply r0 Reply r1
OPERATION_WRITE app → terminal req(OPERATION_WRITE, len) 0 bytes consumed 0
OPERATION_READLINE app → terminal req(OPERATION_READLINE, plen) 0 line length flags
OPERATION_BYTES driver → terminal req(OPERATION_BYTES, n) n bytes, packed LE 0 0
OPERATION_INTRCOUNT app → terminal req(OPERATION_INTRCOUNT, 0) 0 ^C count so far 0
OPERATION_PRINT adapter → terminal req(OPERATION_PRINT, len) len bytes, packed LE bytes consumed 0
OPERATION_RAWMODE app → terminal req(OPERATION_RAWMODE, 0|1) 0 0 0
OPERATION_READRAW app → terminal req(OPERATION_READRAW, 0) 0 byte count (1..=8) bytes, packed LE
OPERATION_QUIESCE supervisor → terminal req(OPERATION_QUIESCE, 0) 0 QUIESCED 0

OPERATION_QUIESCE (milestone 23, a capability-routed component OS with live replacement; calef's ruling of 2026-09-26) stops a terminal so a replacement can take over. It rides the terminal endpoint, so the endpoint's FIFO does the draining. A parked OPERATION_READLINE or OPERATION_READRAW is answered FLAG_RETRY first, because the reply capability naming that reader cannot leave the terminal. The terminal then waits on a control endpoint for CTL_RESUME or CTL_QUIT. A terminal started with no control endpoint refuses it with BAD_REQUEST. The boot's own line_editor has one, because terminal_supervisor builds it.

Only the supervisor may send it (§232 (the line_editor swap contract)). The supervisor sends it through a copy of the endpoint badged proto::SUPERVISOR_BADGE, and a terminal refuses a quiesce on any other copy with BAD_REQUEST, the unbadged one every client holds included, and refuses everything but a quiesce on that badge. Minting it takes GRANT on the unbadged endpoint. system_initializer, terminal_supervisor and login hold that, and login only to hand sessions a WRITE-only copy. No program a person runs holds it: the shell, the input driver and every session hold WRITE alone. Honored from anyone else, a quiesce would stop the terminal until a CTL_RESUME nobody sends. line_editor's whole badge table is proto::admits.

Read flags

A client that speaks the contract handles all three flags; swish, the one reader in the tree, re-issues on FLAG_RETRY. The shell's response is the model: on FLAG_INTERRUPTED it discards and reprompts, on FLAG_EOF it notes there is nowhere to exit to and reprompts. Neither flag carries a signal or a process identity; the terminal reports a fact about the read, and what to do with it is the client's business.

BAD_REQUEST

proto::BAD_REQUEST (u64::MAX) is the reply r0 to a request whose opcode the terminal does not implement, to one the badge on the caller's copy does not admit, and to a second concurrent read. A sentinel rather than silence, so a confused client fails fast instead of hanging on a reply that will never come.

Badged copies

A terminal endpoint capability with a non-zero badge is served by the badge's value, and every request outside that badge's set is refused with BAD_REQUEST. An unbadged capability is served everything except OPERATION_READ_LINE_BYTES and OPERATION_QUIESCE, and that is every holder the boot wires: the input driver, the shell and login. The badge is the kernel's word on every receive (§230 (badged endpoint capabilities)), and a badged copy cannot be re-badged, so a holder cannot widen it back.

What a terminal owes a program, and what it does not

Owes:

Does not owe:

A known race, carried forward from milestone 10

The first byte of input piped in a single burst at boot can be lost once. The input driver arms its receive interrupt a few instructions after the FIFO already holds the piped text, and the leading byte can fall in that window. An interactive user typing after the prompt never hits it, and every line after the first is intact. Fully closing it needs the driver armed before any input arrives. Noted, not papered over; see shell.md.

For milestones 29 and 31