Expand description
Shared bootstrap for outrig run and (future) outrig mcp. Lifts the
sequence of “load + merge config -> resolve container -> ensure image ->
start + bootstrap container -> session row + log dir” out of run
so both subcommands hit the same code path.
Three pieces:
setup– everything from config-load through “container started + bootstrapped + session row + log dir created”, returning a populatedSessionSetup. Stops before MCP children connect.merged_mcp+connect_mcp_clients– reads any image-embedded MCP config, applies repo-config overrides, and spawns oneMcpClientper merged backing MCP inBTreeMap(key-sorted, deterministic) iteration order. Adapter construction stays in the caller because only the REPL path consumes adapters.teardown– mirror of the cleanup tail: graceful MCP shutdowns (drop adapters first soArc::try_unwrapsucceeds), then stop the container, then finalize the session row. Errors are logged and never override the caller’s outcome.
The MCP children are podman exec processes whose stdio rides through
the container; tearing the container down before shutting them down
races their pipes, so the order in teardown is load-bearing.
Structs§
- Session
Setup - Output of
setup: every long-lived value the post-setup pipeline needs (REPL build, MCP children, teardown). The container is already started + bootstrapped; the session row is already on disk. - Session
Setup Args - Inputs to
setup. Borrowed to keep the call site cheap; the lifetime is the caller’s stack frame.
Functions§
- connect_
mcp_ clients - Spawn one
McpClientper backing MCP declared inmcp, in key-sorted (BTreeMap) iteration order.cli_envprovides any--envoverlay entries to merge per server. Adapter construction is the caller’s job because only the REPL path consumes adapters. - merged_
mcp - Read image-embedded MCP config and overlay explicit
config.tomlentries. - setup
- Run the shared bootstrap. Returns once the container is up, the runtime user is bootstrapped, and the session directory + log dir exist.
- teardown
- Cleanup tail. Order: MCP shutdowns (so their
podman execpipes drain before the container goes away) -> container stop -> session finalize. Each step’s failure is logged but never propagated; the caller’s outcome owns the process exit code.