Skip to main content

Module layout_file

Module layout_file 

Source
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§

ApplyPlan
A layout file turned into panes, plus everything the user should see before it opens.
ExportContext
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).
LayoutDoc
LayoutPane
LayoutTab
LayoutView
LayoutWindow
PlanOptions
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 by placeholder(i).
SavedBy
TreeChild
WindowPlan
One window of a WorkspacePlan: its tabs, as ApplyPlan has them.
WorkspacePlan
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.
WorkspaceWindow
One window of a workspace export: its contents (the srv object), the name the user gave it, and whether it is closed.

Enums§

TreeNode
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 format discriminator. 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_block launches into it and clears the key.
SCOPE_WORKSPACE
The scope of a workspace export.
WINDOW_CLOSED
WINDOW_OPEN
A window’s state in 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 in windows, each with its name and state, under the workspace’s name. A window with nothing to write is left out; none at all is an error.
is_layout_path
Whether path is 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 path is 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 idx in 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 doc to path atomically: a temp file beside it, then a rename, so a crash or a full disk never leaves half a layout behind.