# Installer and Setup Conversations

---

# The MSIP Rust Library

_Peios / Developing for Peios / Installer and Setup Conversations_

> Library responsibilities, caller-owned protocol duties, and integration boundaries for MSIP daemons and surfaces.

The multi-surface interaction protocol (MSIP) lets one daemon drive terminal,
graphical, and automated interfaces. The `msip` Rust crate provides wire
framing, message structures, answer checks, and page state. It doesn't open
listeners or run an operation for you.

Use the [protocol specification](/specifications/pgss/msip/scope-and-roles.md) for the
complete contract. The library is a set of helpers, not a conformance claim
for an application that embeds it.

## Library boundaries

The modules divide responsibilities as follows:

| Module | Responsibility |
| --- | --- |
| `frame` | Version-one framing, a 1 MiB total limit, and JSON object bodies |
| `msg` | Typed message bodies and protocol enum encodings |
| `element` | Common element fields and open type-specific state |
| `daemon` | Turn sequencing, atomic updates, and structural answer checks |
| `surface` | The outstanding page after accepted updates |

Your application owns socket permissions, peer verification, authorization,
HELLO negotiation, binding order, listings, and conversation lifetime. It
also owns timeouts, write serialization, bounded queues, and broadcast to
attached peers. A frame's direction bit doesn't establish a valid connection
state.

## Daemon state

Create a `Conversation` for an application-defined kind. Creation reads
128 random bits from `/dev/urandom`; failure returns an I/O error. The
identifier names the conversation and does not authorize attachment.

Supply a `TurnSpec` to `issue`. It assigns the next sequence number and
replaces the outstanding turn. Provide unique refs, valid state and defaults,
and only element types supported by every attached surface.

Call `handle_answer` for a decoded Answer. It returns stale, protocol-error,
missing-required-value, or valid results. It checks built-in value encodings
and select/table choices. Your application validates domain rules, including
string length, patterns, and whether referenced resources still exist.
Negotiated extension types also need application-specific checks.

A valid result doesn't consume the answer. Serialize checking, domain
validation, and acceptance across attached surfaces. Accept by issuing the
next turn or ending the conversation before processing another competing
answer. Reject domain validation with `reject`, then broadcast its Update.

## Updates and attachment

`update` stages an entire sparse batch before changing the stored turn.
Unknown refs or malformed fields reject the batch without partial changes.
Repeated refs fold in order, and log `append` entries accumulate in `lines`.
If a log patch also supplies `lines`, that explicit value replaces the
accumulated lines. Prefer one operation per patch.

`update_full` replaces the element list. Neither operation changes the turn
sequence. Send `current_turn` after a successful attachment so the surface
receives folded state without replaying earlier updates.

`end` marks the conversation ended and returns End for broadcast. The
embedding daemon removes it from listings and handles connection cleanup.
The library retains its final turn until the conversation is dropped.

## Surface state

Pass decoded daemon messages to `Session::handle`. Turn replaces the page;
Update changes it atomically. Updates for other sequence numbers are ignored.
Malformed updates and End bodies preserve the page. A valid End clears it.
The last Bound identifier remains available for displaying the result.

The session doesn't enforce greeting or binding order. Apply those checks in
your connection handler before calling it. Treat names, help, and messages
as text; don't execute instructions inferred from display content.

## Secrets and failure handling

Mark secret inputs, collect them without echo, and avoid retaining their
values after submission. Never put collected secrets in turn state, updates,
errors, or logs. Message and element `Debug` implementations do not redact
values. The library does not wipe caller-owned buffers.

A framing error can leave the stream between messages. Close the connection
instead of attempting to resume decoding. A failed write can have sent a
partial frame; don't retry that frame on the same stream. Configure read and
write deadlines in the transport layer.

## Presentation across surfaces

Turn and element classes are optional presentation hints. The protocol
carries typed content and state; it does not prescribe a daemon-controlled
layout. Keep actions, required values, and validation correct when a surface
ignores every class.

The installer owns its terminal renderer's
[presentation behavior](/peios/developing-for-peios/setup-conversations/terminal-presentation.md).
Those conventions describe `msip-tui`, not guarantees made by the Rust
library or by all MSIP surfaces.

---

# Conversation Lifetime

_Peios / Developing for Peios / Installer and Setup Conversations_

> Attaching to an existing conversation and understanding disconnects, job results, and daemon restarts.

An installer daemon keeps one live conversation in memory. A frontend
connects to that conversation to show its current questions and progress.
The conversation belongs to the daemon rather than to a browser tab.

```mermaid
flowchart LR
    T[Terminal] --> D[Installer daemon]
    B[Browser frontend] --> D
    A[Scripted driver] --> D
    D --> J[Installation or setup job]
```

A second client can attach to the same live conversation. Its answers affect
the same state, so multiple clients are collaborators rather than isolated
sessions. Starting a client is not proof that it created a fresh operation.

## Disconnects and restarts

Closing a frontend does not stop an active job. A reconnect can show the
current turn while the daemon remains alive. Restarting the daemon loses
the conversation; the protocol does not make an interrupted disk operation
transactional or provide durable recovery.

Completed and failed conversations are cleared so a later start can create
another conversation. Read and preserve a failure result before retrying.
Starting again is an additional operation, not an automatic rollback.

## Progress and completion

A successful installation job reaches a result page that offers restart.
The restart request and the actual disk boot are separate events. A daemon
can accept a restart request without proving the firmware booted the target.

The graphical frontend retains a failed job's result until you request a
new conversation. Its log download records the job's output. `msip-drive`
prints a trace, but its abbreviated log display is not a complete audit
journal. See `msip-drive(1)` for automation constraints.

## Slow clients and completion

Each daemon connection has one writer, so complete messages remain in
order. The daemon disconnects a client if queued output, including the frame
being written, exceeds 4 MiB or writes make no progress for 10 seconds. A
client that stops reading does not hold the conversation lock indefinitely.

At conversation completion, final messages drain outside that lock with a
shared 10-second deadline. A start request during retirement receives an
unavailable result. After retirement finishes, a fresh start can create the
next conversation. A disconnected client must not assume that its last
action failed or replay it without checking the daemon's state.

## Browser input and reconnection

The graphical frontend limits each incoming browser message and the input
it admits to its shared queue. When the queue is full, submission waits for
space while the browser continues receiving state updates. An oversized
submission is refused with a message on the supplied page.

A stalled write to the daemon ends that connection. The page shows the lost
connection while the frontend tries again. Actions queued for the old daemon
connection are discarded, and browsers reconnect to fresh state. They are
not automatically replayed against another conversation.

An action sent before disconnection can already have taken effect. Check the
recovered page and any job result before submitting it again. Closing a tab
also does not guarantee that an earlier submission was canceled. If a form
is refused for exceeding the message limit, shorten its input before retrying.

The queue limit is not a limit on total process memory or the number of
connected browsers. `installer-gxwi(1)` and `oobe-gxwi(1)` specify the message
limits, queue accounting, and connection timeout.

---

# Service Lifecycle

_Peios / Developing for Peios / Installer and Setup Conversations_

> How registry seeds start installer services and retire first-boot setup.

Installer packages carry registry seeds that define service startup.
A seed is inert until an image or administrator applies it. Installing a
package alone does not select the machine's setup lifecycle.

The `installerd-service` seed starts `installerd` as SYSTEM and restarts it
after failure. A restart restores a listening service, but does not recover
its previous in-memory conversation.

The `oobe-service` seed is intended for the installed system. It starts
`oobed` after the local account service and waits for its readiness signal
before starting the terminal frontend. `oobed` sends readiness after its
socket is bound and its browser setup has been prepared.

The terminal frontend takes `/dev/console` ahead of the normal sign-in
prompt. It also runs as SYSTEM in the supplied seed because the first
administrator has not yet been created. Splitting the frontend from the
engine separates responsibilities; the seed still determines authority.

On successful setup, `oobed` removes its service definition and the terminal
setup definition. On failure, it keeps them so another boot can retry.
Releasing the console lets the normal prompt appear even if setup failed.

## Socket access

The intended installation socket descriptor admits SYSTEM and
Administrators. Setup additionally admits its temporary browser account
when browser setup is offered.

Applying the descriptor is best effort: if `sd` is unavailable or fails,
the daemon warns and retains inherited access. A listening message does
not prove that the intended descriptor was applied. Verify the service's
runtime environment and socket protection before granting access.

## Console output

While a conversation is active, the privileged service suppresses routine
kernel console messages and restores the prior setting afterward.
Emergency kernel messages remain visible. Other services can still write
to the console; <kbd>Ctrl</kbd>+<kbd>L</kbd> asks the terminal frontend to
repaint if those messages disturb the form.

## Terminal geometry

The terminal frontend discovers its size at startup. A render area with
zero width or height draws no content and leaves the conversation intact.
This does not add size reporting to a serial connection: a terminal that
does not report later size changes still needs its size set explicitly.

Use the nonzero dimensions accepted by the frontend's `--size` option when
starting with known geometry. See `install-tui(1)` or `oobe-tui(1)` for the
size-discovery fallback and repaint controls.

---

# Rehearsing Installer Conversations

_Peios / Developing for Peios / Installer and Setup Conversations_

> The scope and limits of synthetic installer and first-boot rehearsals.

Dry-run mode exercises the installation or setup conversation without
performing its disk or account operations. It helps check frontend behavior
and error handling, but it does not qualify a boot medium or installed
operating system.

Use a private directory reserved for the rehearsal and an explicit socket
path.
Daemon startup removes the existing entry at that path, binds its socket,
and attempts to apply its access descriptor even in dry-run mode. Do not
point a rehearsal at a production service socket.

For installation, supply a synthetic inventory as well as `--dry-run`.
Without an inventory, the daemon still probes the host's disk inventory.
The checked-in frontend fixtures describe invented machines; the developer
harness selects them explicitly.

A simulated phase failure can exercise an error page without damaging a
filesystem. A simulated restart acknowledges the request without restarting
the machine. Neither checks the real executor's cleanup, disk state, or
boot behavior.

`msip-drive` can answer named inputs and queue actions, but it does not guard
against joining an existing conversation. It waits on progress and consumes
actions on new turns. It has no built-in deadline, and a rejected answer or
same-turn update can leave it waiting. Stopping the driver does not stop
the daemon's job.

Keep synthetic inputs and captured output in the disposable fixture.
Credentials passed through `--set` are exposed in process arguments; the
`--set-file` option avoids that exposure but still requires a protected
input file. Do not use real credentials in a rehearsal.

The repository's build guide describes its host and VM harnesses. For the
complete command interfaces, read `installerd(8)`, `oobed(8)`, and
`msip-drive(1)`.

---

# Terminal Presentation

_Peios / Developing for Peios / Installer and Setup Conversations_

> Understand how installer terminal interfaces render MSIP pages and optional presentation hints.

The installer's `msip-tui` renderer draws pages for `install-tui` and
`oobe-tui`. Daemons supply typed elements through the multi-surface
interaction
protocol (MSIP); the renderer chooses their arrangement and appearance.
A page still needs to work when another surface ignores its presentation
hints.

## Page arrangement

Without a recognized turn class, the renderer places the heading and elements
in a column, with actions together below them. The `menu` class moves actions
into the body as a list. The `confirm` class marks the heading as a
confirmation.
Neither class changes the daemon's validation or makes an action safe to run.

The renderer checks these classes independently. Prefer one clear purpose
for a turn rather than assuming that combinations define another layout.
Unknown classes do not acquire behavior merely by being sent.

Progress elements render as a phase list. The first unfinished progress
element is active, and a log can use the remaining height. This follows the
element types and state; it does not require a `progress` turn class.

## Element presentation

| Element information | Terminal behavior |
|---|---|
| An action's `primary` state | Accent color and bold text |
| An action's `destructive` state | Destructive coloring, including focus |
| A string's `secret` flag | Masked entered text |
| A string's `placeholder` state | Dim text while the empty field is unfocused |
| A table column's `align: right` | Right-aligned cells |
| A table row's `enabled: false` | Dimmed row, skipped during selection |
| A table row's `note` | A remark after its cells |
| A table's `empty` state | Text shown when it has no rows |
| An element's `help` | Context explaining the element or why it is unavailable |
| An element's `error` | An error below the element until cleared |

Masking is a display property. It does not make logging, debug formatting,
or retaining a submitted secret safe. Follow the
[MSIP library's secret handling guidance](https://learn.peios.org/peios/developing-for-peios/setup-conversations/rust-library/)
and keep secrets out of turn updates and diagnostics.

A primary action's appearance does not authorize unattended execution.
Choose explicit actions in automation. A destructive action is not given
extra validation by its color; the daemon owns confirmation and authorization.

## Focus and narrow terminals

Unavailable input elements can take focus, allowing a person to discover
why they cannot answer them. Supply useful `help`, such as the missing
prerequisite. Initial focus favors the first answerable element, with the
primary action used where appropriate.

Fields reserve space for their note so moving focus does not shift the page.
Errors remain visible. Help appears when the element is focused or
unavailable.
Table selection skips unavailable rows, and the answer validator also rejects
them; dimming alone is not the enforcement mechanism.

Tables drop columns from the right when space is limited. Put the column
needed to identify a row first, and test narrow terminal widths.

## Leaving and automation

Esc opens the surface's leave question. Its wording depends on the frontend:
leaving an ongoing installation differs from leaving initial account setup.
A daemon page cannot override that lifecycle meaning with a presentation
class.

`msip-drive` does not draw the terminal layout. Its scripted answers rely on
refs, values, and actions rather than color or class hints. Use
[Installer Conversation Rehearsals](/peios/developing-for-peios/setup-conversations/rehearsing-conversations.md)
to check that the same conversation remains usable through automation.
