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).
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
Builder 🔒 - 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 bysession_restore::placeholder(i). - SavedBy
- TabBuilder 🔒
- Pane ids are minted per tab in tree order; node ids are the tree’s own, used only to map focus/magnify onto them.
- Tree
Child
Enums§
- Tree
Node - A split (
{split, children}) or a leaf ({pane}). - Truncated 🔒
- A per-tab limit the file hit. Each is noted once per tab, however many panes or branches it cuts off.
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.
- MAX_
PANES_ 🔒PER_ TAB - MAX_
TABS 🔒 - MAX_
TREE_ 🔒DEPTH - 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. - PLAIN_
VIEWS 🔒 - Views that need no config to open, beyond their type.
Functions§
- armory_
target 🔒 - Where a saved Armory pane goes, by its section (and, for the old Memory
section, its Global/Personal subsection): its pane,
connectorsormemory, and that pane’s section. The same mapping m0037_retire_old_pane_names.rs applied to stored blocks; layout files live outside AgentMux, so their import still needs it. - cfg_str 🔒
- expand_
home 🔒 ~/~/xresolved underhome; anything else unchanged.- export_
tab 🔒 - export_
window - Export one window — every tab of its workspace — as a layout document.
- home_
relative 🔒 - A path under
homeas~/…(forward slashes); anything else unchanged. - 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.
- meta_
str 🔒 - parse_
layout - Parse a layout document, refusing another format or a newer version
(spec §3.1). Unknown fields are kept in
extra. - plan_
from_ doc - Build the plan. Never touches the store beyond reading agent definitions.
- ratios 🔒
- Flex sizes → ratios summing to exactly 1, rounded to 4 places for a readable file (the last sibling absorbs the rounding). Non-positive sizes share equally.
- read_
layout_ file - Read and parse a layout file, refusing anything too large to be one.
- resolve_
agent 🔒 - A user agent (not a template) matching the file’s slug, else its display name — only if exactly one matches, so a name shared by two agents never launches the wrong one.
- strip_
query 🔒 - A URL with its query string and fragment removed (spec §3.3/§3.4) — they are where tokens, session ids and tracking live.
- view_
from_ 🔒block - One pane tab, written from the per-type allowlist (spec §3.3). Anything
not named here — session ids, instance ids, env, runtime state, CLI
paths, failure records — is never written. An unknown view type is
written as
{type}alone. - 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.