Expand description
Layout files — the agentmux.layout v1 format and its writer
(docs/specs/SPEC_LAYOUT_FILES_2026_09_25.md, Phase 1).
A layout file describes a window’s tabs, their split trees (as ratios)
and each pane’s typed views, so it can be read, diffed, shared and — in
Phase 2 — reopened. It is not a dump of the store: every view is
written through a per-type allowlist ([view_from_block]), never by
copying block meta. The session-restore snapshot
(server/service/session_restore.rs) copies meta verbatim, which is fine
for an internal blob and wrong for a file a user hands to someone else:
session ids, instance ids, absolute paths and env would all leak.
Every struct carries an extra map, so a reader keeps fields it doesn’t
know and writes them back unchanged (spec §3.1).
A workspace export (SPEC_WORKSPACES_2026_10_23.md §4.2) is the same
document with scope: "workspace", the workspace’s name, and every window
it holds, each with its name and its state (open or closed). Those
fields are optional, so it stays version 1: an older reader keeps them as
unknown fields, and a file without them reads as open, unnamed windows.
Structs§
- Apply
Plan - A layout file turned into panes, plus everything the user should see before it opens.
- Export
Context - Everything the exporter reads from outside the store, injected so tests are deterministic.
- Exported
- The result of exporting: the document, plus anything the user should be told before it is written (spec §3.4).
- Layout
Doc - Layout
Pane - Layout
Tab - Layout
View - Layout
Window - Plan
Options - How to turn a file into panes.
- PlanTab
- One tab ready for
session_restore::replay_tabs: block metas, and a tree whose leaves name them byplaceholder(i). - SavedBy
- Tree
Child - Window
Plan - One window of a
WorkspacePlan: its tabs, asApplyPlanhas them. - Workspace
Plan - A whole file turned into panes, every window of it: what Import… opens
as a new workspace (
SPEC_WORKSPACES_2026_10_23.md§3.2). A layout file saved from one window is a workspace of that window. - Workspace
Window - One window of a workspace export: its contents (the srv object), the name the user gave it, and whether it is closed.
Enums§
- Tree
Node - A split (
{split, children}) or a leaf ({pane}).
Constants§
- LAYOUT_
EXTENSION - Every layout file ends with this (spec §3.1): filterable in dialogs, highlighted as JSON in any editor.
- LAYOUT_
FORMAT - The
formatdiscriminator. A reader refuses any other value. - LAYOUT_
VERSION - The format version this build writes and the newest it reads.
- MAX_
LAYOUT_ FILE_ BYTES - A layout file larger than this is refused unread — real ones are a few KB.
- META_
LAYOUT_ AGENT - Block meta key naming the agent definition a layout’s agent pane should
launch. Set on the empty
{view:"agent"}placeholder the plan creates;agent_open::open_agent_into_blocklaunches into it and clears the key. - SCOPE_
WORKSPACE - The
scopeof a workspace export. - WINDOW_
CLOSED - WINDOW_
OPEN - A window’s
statein a workspace export: shown, or closed (kept to reopen). - WORKSPACE_
EXTENSION - An exported workspace ends with this.
Functions§
- export_
window - Export one window — every tab of its workspace — as a layout document.
- export_
workspace - Export a workspace (
SPEC_WORKSPACES_2026_10_23.md§4.2): every window inwindows, each with its name and state, under the workspace’sname. A window with nothing to write is left out; none at all is an error. - is_
layout_ path - Whether
pathis somewhere a layout may be written: absolute, and named*.agentmux-layout.json. - is_
trusted - Whether a file counts as trusted (spec §3.5): saved by this install and sitting in its default layouts folder. Only trusted files start terminal commands without the user’s say-so.
- is_
workspace_ path - Whether
pathis somewhere a workspace export may be written: absolute, and named*.agentmux-workspace.json. - parse_
layout - Parse a layout document, refusing another format or a newer version
(spec §3.1). Unknown fields are kept in
extra. - placeholder
- The stand-in for the block at position
idxin a saved snapshot (server/service/session_restore.rs). - placeholder_
idx - plan_
from_ doc - Build the plan. Never touches the store beyond reading agent definitions.
- plan_
workspace - Build the plan for every window of
doc. Never touches the store beyond reading agent definitions. - read_
layout_ file - Read and parse a layout file, refusing anything too large to be one.
- write_
layout_ file - Write
doctopathatomically: a temp file beside it, then a rename, so a crash or a full disk never leaves half a layout behind.