Highdra CLI Structure and Web UI Integration¶
This document explains how highdra-cli is organized, how it uses the database, and how it connects to the Flask-based web UI for remote command execution and software checkout workflows.
High-Level Structure¶
Core package layout in src/highdra/:
highdra/
__init__.py # package version export
cli/
__init__.py # Typer app setup + command lifecycle + DB run logging
__main__.py # python -m highdra.cli
runner.py # starts websocket runner service
software.py # starts runner and opens software checkout web UI
arm.py, battery.py, ... # hardware command groups
models/
__init__.py # SQLAlchemy engine factory + model exports
base_entity.py # schema-aware declarative base
command_run.py # command run metadata
command_log_event.py # per-line/structured logs
available_runner.py # runner registration + heartbeat state
software_manifest*.py # software checkout metadata
root_certificate.py # CA certificate persistence
websocket_runner/
__init__.py # runner API exports
runner_service.py # websocket server + auth + heartbeat lifecycle
command_executor.py # command router (ping/status/cli/software_checkout_step)
command_messages.py # typed websocket payload/event models
serial_in_out.py # terminal stream cleanup and input-request framing
ws_input.py # websocket-backed interactive input protocol helpers
certificate/ # runner TLS certificate creation and bootstrap helpers
cert_gen.py # generates leaf certificates for runner TLS
common.py # shared certificate/key path and utility helpers
root_fetch.py # fetches persisted CA material for TLS setup
command_handler/
general_cli.py # allowlisted generic CLI execution
software_checkout_step.py# step-wise download/automated/manual execution
steps/
software_download.py # fetches scripts/assets
software_execute.py # runs downloaded scripts
Module Initialization¶
highdra uses explicit module init files to define package boundaries and side effects.
-
src/highdra/__init__.py- Keeps the top-level package lightweight.
- Exposes only
__version__.
-
src/highdra/cli/__init__.py- Creates the Typer app and registers all subcommands (
arm,battery,body,esc,images,config,software,runner). - Creates a runtime
Sessionobject (ctx.obj) used across commands. - Initializes command-run DB tracking when
--db-loggingis enabled. - Finalizes command status (
success/failure, exit code, timestamps) in_finalize_command_run().
- Creates the Typer app and registers all subcommands (
-
src/highdra/websocket_runner/__init__.py- Re-exports runner service and websocket message types (
RunnerService,RunnerConfig,RunnerCmdResult, etc.) for stable imports.
- Re-exports runner service and websocket message types (
Database Usage¶
Database access is shared between CLI runner processes and the web UI.
Connection and Schema¶
-
src/highdra/models/__init__.pyget_engine()readsPG_ALEMBIC_CONNECTION_STRINGand requiresPG_SCHEMA_NAME.- Returns a cached SQLAlchemy engine.
-
src/highdra/models/base_entity.py- Declares
metadata = MetaData(schema=os.getenv("PG_SCHEMA_NAME")). - All mapped tables default to the configured schema (for example
v0).
- Declares
What Is Persisted¶
-
CommandRun+CommandLogEvent- Command lifecycle and output logs.
- Written by CLI entrypoint (
cli/__init__.py) and consumed by web history pages.
-
AvailableRunner- Runner endpoint, auth token, online/enabled flags, heartbeat and claim window.
- Updated continuously by
websocket_runner/runner_service.py.
-
SoftwareManifestand step records- Used by web routes to build checkout step payloads.
-
RootCertificate- Stores generated CA cert/key material for TLS websocket usage.
Connection to Flask Web UI¶
The web UI (software_management_web) uses the same DB models and opens browser websocket connections directly to runners.
Browser to Handler Flow¶
sequenceDiagram
participant B as Browser
participant RS as RunnerService
participant CE as CommandExecutor
participant H as Handler
B->>RS: WebSocket connect + auth response
B->>RS: {command: "cli" | "software_checkout_step"}
RS->>CE: execute(payload)
CE->>H: dispatch to specific handler
H-->>CE: output/result events
CE-->>RS: command_result
RS-->>B: streamed output + final result
A. Generic Command-Line Execution via Web¶
-
Flask renders runner command page:
software_management_web/src/software_management_web/controllers/runners/routes.pysoftware_management_web/src/software_management_web/templates/runners/runner_detail.html
-
Browser JS opens websocket and sends command payload:
software_management_web/src/software_management_web/static/js/runners/runner_detail.js- Sends payloads like:
{ "command": "ping" }{ "command": "cli", "cli": "highdra esc checkout" }
-
highdra-clirunner handles it:src/highdra/websocket_runner/runner_service.pyauthenticates with HMAC challenge-response.src/highdra/websocket_runner/command_executor.pydispatches toCliCommandHandler.src/highdra/websocket_runner/command_handler/general_cli.pyvalidates allowlisted top-level commands, then executes:python -m highdra.cli ...
-
Output and prompts are streamed back:
- Command output events (
command_output). - Interactive prompts (
input_request/input_response). - Final result (
command_result).
- Command output events (
B. Software Checkout Steps via Web¶
-
Flask prepares manifest and sorted step payload:
software_management_web/src/software_management_web/controllers/commands/routes.py
-
Page + JS orchestrate step execution:
- Template:
software_management_web/src/software_management_web/templates/commands/software_checkout_run.html - JS modules:
software_checkout_run.js,software_checkout_run_websocket.js,software_checkout_run_ui.js,software_checkout_run_utils.js
- Template:
-
Browser sends per-substep websocket command:
{ "command": "software_checkout_step", ... }- Substeps:
download,automated,manual
-
Runner executes substeps:
src/highdra/websocket_runner/command_handler/software_checkout_step.py- Downloads scripts/assets, executes
automated.py, and streams manual markdown + reference files back to UI.
-
UI confirms each substep interactively:
- Confirmation exchanged via
input_requestandinput_responsemessages.
TLS/WSS Notes¶
- Runner TLS cert setup is performed in:
src/highdra/cli/runner.pysrc/highdra/websocket_runner/runner_service.py
- Web UI can switch websocket preference (
ws://vswss://) and provides CA certificate download/install guidance in:software_management_web/src/software_management_web/templates/ca_cert.html
Related Docs¶
- User-facing software checkout command docs:
docs/commands/software/checkout.md
- History/logging UI based on
CommandRunandCommandLogEvent:software_management_web/src/software_management_web/controllers/history/routes.py