Expand description
CLI bootstrap: argv → resolved mode + runtime handle, or short-circuit exit.
Ports the ordered pipeline of .references/pi/packages/coding-agent/src/ main.ts into a testable orchestrator. Everything that touches the process
(env vars, TTY status, stdin, stdout/stderr) flows through an injected
BootstrapIo trait; everything that builds the agent-session runtime
flows through an injected RuntimeFactory trait. Pure helpers
(resolve_app_mode, validators) are public so the integrator and tests
can drive them directly.
§Pipeline order (matches main.ts:472-858)
- Reset timings (no-op here; the timings module is a sibling concern).
- Offline mode:
args.contains("--offline") || PI_OFFLINE→ setPI_OFFLINE=1,PI_SKIP_VERSION_CHECK=1. - Package/config short-circuit (
pi install …,pi config …). parse_args+ report diagnostics (errors exit 1, warnings continue).--version→ print version, exit 0.--export→ export session file, exit 0/1.resolve_app_mode+take_over_stdout(unless interactive or plain runtime metadata command).- RPC +
@fileguard. - Fork / session-id flag validation.
run_migrations(recordsmigrated_providers+deprecation_warnings).- Startup settings + first-time setup (interactive only — gated, the UI surface itself is a sibling slice).
- Session-dir resolution +
create_session_manager. --nameappend + validation.- Trust store + resource paths.
- Build runtime via factory.
--help(with extension flags) → exit 0.--list-models→ exit 0.- Read piped stdin (skip RPC); demote interactive→print when stdin present.
- Prepare initial message.
- Report runtime diagnostics (errors exit 1, with extension hint when relevant).
- Non-interactive requires
session.model, else no-models message + exit 1. PI_STARTUP_BENCHMARKguard.- Return
BootstrapOutcome::Dispatchwith the resolved mode + handle.
Structs§
- Bootstrap
Inputs - Inputs to
run_bootstrap. - Dispatched
- A bootstrap that reached the dispatch stage.
- Flag
Validation Error - Error returned by
validate_fork_flags/validate_session_id_flags. - Runtime
Factory Options - Inputs to
RuntimeFactory::create. - Runtime
Handle - Result of a successful runtime construction.
Enums§
- AppMode
- Resolved application mode.
- Bootstrap
Outcome - Result of running the bootstrap pipeline.
Traits§
- Bootstrap
Io - Process-level I/O surface the bootstrap needs.
- Runtime
Factory - Injected factory that turns a session manager + CLI args into a live
AgentSessionRuntime.
Functions§
- is_
plain_ runtime_ metadata_ command - Whether
--help/--list-modelsshould run without taking over stdout. - is_
truthy_ env_ flag - Truthy env-flag test matching
isTruthyEnvFlag(main.ts:94-97). - resolve_
app_ mode - Resolve the application mode from parsed args and TTY status.
- run_
bootstrap - Run the bootstrap pipeline.
- validate_
fork_ flags --forkcannot combine with--session/--continue/--resume/--no-session.- validate_
name - Validate
--name/-npost-parse. - validate_
session_ id_ flags --session-idcannot combine with--session/--continue/--resume.