Skip to main content

Module bootstrap

Module bootstrap 

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

  1. Reset timings (no-op here; the timings module is a sibling concern).
  2. Offline mode: args.contains("--offline") || PI_OFFLINE → set PI_OFFLINE=1, PI_SKIP_VERSION_CHECK=1.
  3. Package/config short-circuit (pi install …, pi config …).
  4. parse_args + report diagnostics (errors exit 1, warnings continue).
  5. --version → print version, exit 0.
  6. --export → export session file, exit 0/1.
  7. resolve_app_mode + take_over_stdout (unless interactive or plain runtime metadata command).
  8. RPC + @file guard.
  9. Fork / session-id flag validation.
  10. run_migrations (records migrated_providers + deprecation_warnings).
  11. Startup settings + first-time setup (interactive only — gated, the UI surface itself is a sibling slice).
  12. Session-dir resolution + create_session_manager.
  13. --name append + validation.
  14. Trust store + resource paths.
  15. Build runtime via factory.
  16. --help (with extension flags) → exit 0.
  17. --list-models → exit 0.
  18. Read piped stdin (skip RPC); demote interactive→print when stdin present.
  19. Prepare initial message.
  20. Report runtime diagnostics (errors exit 1, with extension hint when relevant).
  21. Non-interactive requires session.model, else no-models message + exit 1.
  22. PI_STARTUP_BENCHMARK guard.
  23. Return BootstrapOutcome::Dispatch with the resolved mode + handle.

Structs§

BootstrapInputs
Inputs to run_bootstrap.
Dispatched
A bootstrap that reached the dispatch stage.
FlagValidationError
Error returned by validate_fork_flags / validate_session_id_flags.
RuntimeFactoryOptions
Inputs to RuntimeFactory::create.
RuntimeHandle
Result of a successful runtime construction.

Enums§

AppMode
Resolved application mode.
BootstrapOutcome
Result of running the bootstrap pipeline.

Traits§

BootstrapIo
Process-level I/O surface the bootstrap needs.
RuntimeFactory
Injected factory that turns a session manager + CLI args into a live AgentSessionRuntime.

Functions§

is_plain_runtime_metadata_command
Whether --help/--list-models should 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
--fork cannot combine with --session/--continue/--resume/--no-session.
validate_name
Validate --name/-n post-parse.
validate_session_id_flags
--session-id cannot combine with --session/--continue/--resume.