Layouts¶
The layout APIs turn Python intent into terminal structure. They define tabs, serialize layouts, build tab commands from callables, and split oversized layouts before handing them to zellij, tmux, or Windows Terminal backends.
Layout schema¶
The schema lives in stackops.utils.schemas.layouts.layout_types.
Core types¶
| Type | Fields |
|---|---|
TabConfig |
tabName, startDir, command, optional tabWeight |
LayoutConfig |
layoutName, layoutTabs |
LayoutsFile |
version, layouts |
Helper behavior¶
serialize_layouts_to_file(layouts, version, path)writes a new layout file with"$schema": "https://bit.ly/cfglayout".- If the target file already exists,
serialize_layouts_to_file()replaces layouts that share the samelayoutNameand appends new ones. substitute_home(tabs)expands~and$HOMEand rewrites shorthand command prefixes:f ...->~/.config/stackops/scripts/wrap_stackops fire ...t ...->~/.config/stackops/scripts/wrap_stackops terminal ...s ...->~/.config/stackops/scripts/wrap_stackops seek ...
The current schema key is layoutTabs. There is no alternate tabs field in the typed definitions.
Building layouts from Python functions¶
stackops.cluster.sessions_managers.utils.maker converts Python callables into TabConfig entries.
Main helpers¶
| Helper | Purpose |
|---|---|
get_fire_tab_using_uv() |
Generates Python source from a callable, writes a temporary script, and returns the tab config plus the generated file path |
get_fire_tab_using_fire() |
Builds a wrap_stackops fire ... command for an importable callable |
make_layout_from_functions() |
Builds a LayoutConfig from functions plus any extra tabs you want to append |
make_layout_from_functions() accepts both launch styles through method:
"script"to execute generated Python throughuv"fire"to use thewrap_stackops fireentrypoint
Its flags parameter is passed through to the selected launch mode as either uv_run_flags or fire_flags.
Example¶
from stackops.cluster.sessions_managers.tmux.tmux_local import run_tmux_layout
from stackops.cluster.sessions_managers.utils.maker import make_layout_from_functions
def ingest() -> None:
print("ingest")
def train() -> None:
print("train")
layout = make_layout_from_functions(
functions=[ingest, train],
functions_weights=[1, 2],
import_module=True,
tab_configs=[],
layout_name="ml-workflow",
method="script",
uv_with=["stackops"],
uv_project_dir=None,
flags="",
start_dir="~/code/my-project",
)
run_tmux_layout(layout_config=layout, on_conflict="rename")
If functions_weights is None, each function is treated as weight 1.
Controlling layout size¶
stackops.cluster.sessions_managers.utils.load_balancer provides two controls.
limit_tab_num()¶
limit_tab_num(
layout_configs=layouts,
max_thresh=8,
threshold_type="number",
breaking_method="moreLayouts",
)
Supported threshold_type values:
"number"for raw tab count"weight"for summedtabWeight
Supported breaking_method values:
"moreLayouts""combineTabs"
limit_tab_weight()¶
limit_tab_weight(layout_configs, max_weight, command_splitter) rewrites overweight tabs by calling your command_splitter(command, to=max_weight) function and replacing the original tab with ..._part1, ..._part2, and so on.
Convenience launcher¶
load_balancer.run(layouts, on_conflict) is a thin helper that:
- creates a
ZellijLocalManager - starts all sessions
- runs the monitoring routine
- kills all managed sessions when monitoring finishes
Backend-specific layout generators¶
The same LayoutConfig can be handed to multiple backends:
run_zellij_layout(layout_config, on_conflict)run_tmux_layout(layout_config, on_conflict)run_wt_layout(layout_config, exit_mode)
Their generator classes are:
ZellijLayoutGeneratorTmuxLayoutGeneratorWTLayoutGenerator
Those classes are responsible for rendering backend-specific layout artifacts:
- zellij KDL files
- tmux shell scripts
- Windows Terminal PowerShell scripts
API reference¶
Layout schema¶
layout_types
¶
Type definitions for the standardized layout configuration schema. This module defines the data structures that match the layout.json schema.
TabConfig
¶
Bases: TypedDict
Configuration for a single tab in a layout.
LayoutConfig
¶
Bases: TypedDict
Configuration for a complete layout with its tabs.
LayoutsFile
¶
Bases: TypedDict
Complete layout file structure.
serialize_layouts_to_file
¶
serialize_layouts_to_file(
layouts: list[LayoutConfig],
version: Literal["0.1"],
path: str,
)
Serialize a LayoutConfig to a JSON string.
Layout builders¶
maker
¶
Layout load balancer¶
load_balancer
¶
Zellij layout helpers¶
zellij_local
¶
ZellijLayoutGenerator
¶
ZellijLayoutGenerator(
layout_config: LayoutConfig, session_name: str
)
restart_tab
¶
Restart the process running in a specific tab without changing the layout.
This method will: 1. Navigate to the specified tab 2. Send Ctrl+C to stop the running process 3. Clear the screen 4. Re-execute the original command
The tab layout and configuration remain unchanged - only the process is restarted.
create_zellij_layout
¶
create_zellij_layout(
layout_config: LayoutConfig, layout_template: str
) -> str
Standalone function to create Zellij layout content from config.
tmux layout helpers¶
tmux_local
¶
Windows Terminal layout helpers¶
wt_local
¶
Windows Terminal local layout generator and session manager. Equivalent to zellij_local.py but for Windows Terminal.
https://github.com/ruby9455/app_management/tree/main/app_management
WTLayoutGenerator
¶
WTLayoutGenerator(
layout_config: LayoutConfig,
session_name: str,
exit_mode: SessionExitMode,
)
create_layout_file
¶
Create Windows Terminal layout file and return success status.
get_wt_layout_preview
¶
get_wt_layout_preview(layout_config: LayoutConfig) -> str
Generate preview of the Windows Terminal command that would be created.
get_status_report
¶
Get status report for this layout including Windows Terminal and commands.
print_status_report
¶
Print a comprehensive status report for this Windows Terminal layout.
run_wt_layout
¶
run_wt_layout(
layout_config: LayoutConfig, exit_mode: SessionExitMode
) -> None
Create and run a Windows Terminal layout.
run_command_in_wt_tab
¶
Create a command to run in a new Windows Terminal tab.