How basefoundry/base-cli works
base-cli is a reusable production lifecycle layer for Click and Typer CLIs, not a parser or application scaffold. A consumer defines commands and calls the runner; the library supplies lifecycle options, a shared context, configuration and runtime policies, then logging, cleanup, history and human or machine-readable output. The README documents optional Typer, Rich and OpenTelemetry support. Relationships below follow the README or SOURCE INDEX references; unsampled subsystems are represented at their known module paths, without assuming their internal call order.
Main entry points: context.py Command context · _app_core.py App and commands · _run.py Invocation runner · _runtime.py Run directories
Components 25
Invocation lifecycle
- App and commands
lib/python/base_cli/_app_core.py - Lifecycle options
lib/python/base_cli/lifecycle_options.py - Invocation runner
lib/python/base_cli/_run.py - Typer adapter
lib/python/base_cli/typer.py - Command attachment
lib/python/base_cli/_attach.py
Context and policy
- Command context
lib/python/base_cli/context.py - Configuration
lib/python/base_cli/config.py - Consumer profile
lib/python/base_cli/profile.py - Extensions
lib/python/base_cli/extensions.py
Runtime state
- Runtime layout
lib/python/base_cli/runtime.py - Run directories
lib/python/base_cli/_runtime.py - Path policies
lib/python/base_cli/paths.py - Private files
lib/python/base_cli/_private_files.py - Cleanup hooks
lib/python/base_cli/_cleanup.py
Output and integrations
- Structured logging
lib/python/base_cli/logging.py - Run history
lib/python/base_cli/history.py - Sensitive redaction
lib/python/base_cli/redaction.py - JSON contracts
lib/python/base_cli/json_contracts.py - Record output
lib/python/base_cli/output.py - Optional integrations
lib/python/base_cli/integrations.py
Other components
- CLI consumer
- Click parser
- Local filesystem
- Rich
- OpenTelemetry
Connections 26
- CLI consumer → App and commands: defines commands
- CLI consumer → Invocation runner: runs app
- App and commands → Lifecycle options: configures
lib/python/base_cli/_app_core.py - App and commands → Command context: creates context
lib/python/base_cli/_app_core.py - Invocation runner → App and commands: invokes
lib/python/base_cli/_run.py - Invocation runner → Click parser: dispatches to
lib/python/base_cli/_run.py - Typer adapter → Click parser: adapts dialect
- CLI consumer → Typer adapter: opts into
- Command attachment → App and commands: attaches lifecycle
lib/python/base_cli/_attach.py - Command context → Configuration: exposes config
lib/python/base_cli/context.py - Consumer profile → Configuration: supplies policy
lib/python/base_cli/profile.py - Consumer profile → Runtime layout: resolves layout
lib/python/base_cli/profile.py - Command context → Run directories: uses runtime
lib/python/base_cli/context.py - Command context → Cleanup hooks: registers hooks
lib/python/base_cli/context.py - Run directories → Path policies: uses paths
lib/python/base_cli/_runtime.py - Run directories → Private files: secures files
lib/python/base_cli/_runtime.py - Run directories → Local filesystem: manages run state
- App and commands → Structured logging: configures logging
lib/python/base_cli/_app_core.py - Command context → Structured logging: provides logger
lib/python/base_cli/context.py - Command context → Run history: provides history
lib/python/base_cli/context.py - Run history → Sensitive redaction: redacts records
lib/python/base_cli/history.py - Invocation runner → JSON contracts: renders JSON errors
lib/python/base_cli/_run.py - Invocation runner → Record output: captures output
lib/python/base_cli/_run.py - Record output → Optional integrations: tries rendering
lib/python/base_cli/output.py - Optional integrations → Rich: renders tables
lib/python/base_cli/integrations.py - Optional integrations → OpenTelemetry: starts spans
lib/python/base_cli/integrations.py