Skip to content

Runtime lifecycle

This chapter follows the bundle from process start to cleanup. It is the right entry point for questions about package loading, root command routing, TUI/prompt/server modes, terminal integration, voice/runtime workers, protocol servers, rendering support, update behavior, and shutdown.

The runtime lifecycle is the outer harness around the model loop: it decides which mode runs, prepares shared services, connects to sessions/tools, and guarantees cleanup when execution ends.

Source-anchor policy

This page is a chapter guide. The linked implementation pages carry concrete app.js anchors.

Semantic aliasMinified anchorScope
Runtime lifecycle chapterN/A — navigation pageGroups startup, command routing, mode dispatch, terminal/protocol support, voice workers, rendering, and cleanup.
Runtime implementation pagesSee linked source-anchor tablesConcrete bundle anchors live in the destination pages.

Runtime flow

flowchart TD
Loader[Loader/bootstrap] --> Root[Root command and pre-action setup]
Root --> Dispatch{Runtime mode}
Dispatch --> TUI[Interactive TUI]
Dispatch --> Prompt[Prompt/stdin/non-TTY]
Dispatch --> Server[JSON-RPC/headless server]
Dispatch --> ACP[ACP server]
Dispatch --> Commands[Subcommands]
TUI --> Sessions[Session runtime]
Prompt --> Sessions
Server --> Sessions
ACP --> Sessions
Sessions --> Shutdown[Shutdown/update/logging cleanup]
click Loader "./loader-bootstrap/" "Open loader and bootstrap"
click Root "./mode-dispatch-and-runtime-startup/" "Open Mode dispatch and runtime startup"
click TUI "./tui-and-slash-commands/" "Open TUI and slash commands"
click Server "./embedded-server-acp-protocol/" "Open embedded server and ACP"
click Shutdown "../05-hosted-agent-ops/telemetry-update-and-shutdown/" "Open observability and shutdown"

Primary reading order

OrderPageRuntime question answered
1Loader and bootstrap workflowsHow does the SEA/npm package select and load the actual runtime bundle?
2Mode dispatch and runtime startupHow do argv, stdin, TTY, settings, auth, and sessions choose the execution mode?
3Interactive TUI and slash-command workflowsHow does the terminal UI handle input, rendering, slash commands, dialogs, and permissions?
4Embedded server, ACP, and JSON-RPC protocolHow does the CLI expose runtime/session capabilities to external hosts?
5Telemetry, update, and shutdownHow are logs, telemetry, update/version behavior, signals, disposables, and graceful exit coordinated?

Runtime support topics

TopicPageWhy it belongs here
Terminal ergonomicsTerminal setup and shell environmentDefines shell detection, Shift+Enter setup, history state, and command-environment context.
Syntax and diff renderingTree-sitter WASM usageExplains packaged grammars, highlight queries, and rendering fallbacks.
Voice entry pointVoice mode and Foundry LocalCovers voice mode activation, Foundry Local checks, settings, and native modules.
Voice backendVoice runtime workers and transcription pipelineTraces microphone, installer, worker state machines, PCM flow, transcription, and cleanup.

Handoffs

Created and maintained by Yingting Huang.