Skip to content

Operator CLI

The autoswe CLI is a Click-based operator interface designed to manage the lifecycle, state, and monitoring of the autonomous Go-rewrite loop. It provides a dual-mode interaction model: a menu-driven interactive TUI for quick status checks and manual interventions, and a suite of subcommands for programmatic or scriptable control of the systemd-managed service. The CLI acts as a thin wrapper around core logic, delegating service control to systemctl, file-system-based state management (sentinels), and direct execution of helper scripts for live monitoring.

The CLI is not distributed via pip. Instead, the executable ~/.local/bin/autoswe is a symlink to scripts/autoswe.py 1. This script inserts scripts/ onto sys.path to make the autoswe_cli package importable, then delegates to the Click group defined in cli.py. Any standalone script importing from this package must perform the same sys.path insertion.

The main entry point is the cli Click group, which supports invoke_without_command=True 2. If no subcommand is provided, it defaults to launching the interactive TUI. Commands are registered dynamically by importing them from sibling modules and adding them to the group.

Key command groups include:

  • Lifecycle (ops.py): start, stop, restart, pause, resume, status, logs, attach, serve, watch-agent, verdicts, journey, rules-review.
  • State Management (state.py): state_read, state_merge, select_module, write_status, plan_status, judge_status, verify_cells.
  • Sandbox & Runs (sandbox.py, runs.py): sandbox, runs_group, preflight_cmd, parity_flip_cmd.
  • Journey & Gating (journey.py, gating.py): journey_synth, baseline_capture_cmd, enable_autonomous_cmd, lock_check_cmd.
  • Utilities (units.py, lease.py, images.py): install-units, lease_ready_cmd, images.
diagram

The ops.py module provides commands to control the autoswe systemd service. These commands are protected by a check for the AUTOSWE_RUN_CONFIG environment variable; if set, they refuse to execute to prevent accidental interference with config-run shells 3.

  • start: Starts the autoswe service, the autoswe-watchdog.timer, and the autoswe-meta-judge.timer via systemctl --user.
  • stop: Stops the watchdog timer, meta-judge timer, and the autoswe service.
  • restart: Restarts the autoswe service.
  • status: Renders a rich table showing the current state from state.json, parity progress (GREEN/RED cell counts), last heartbeat age, GPU status, and proxy health 4.
  • logs: Tails the user journal for the autoswe unit, showing the last 50 lines and following 3.
  • serve: Launches the journey_server.py HTTP server in the foreground, defaulting to port 8765.

Pause and resume operations are implemented via file-system sentinels rather than direct process signals, allowing the Go loop to check for pause states at specific hook points.

  • pause: Creates a PAUSE sentinel file in the runtime directory. An optional --hard flag also creates a PAUSE_HARD sentinel.
    • Soft Pause: The loop finishes the current vertex, then blocks on the next one 4.
    • Hard Pause: Denies every tool call immediately at the next hook fire 3.
  • resume: Removes both PAUSE and PAUSE_HARD sentinel files. The loop wakes up within 60 seconds from its next ScheduleWakeup tick 4.

The status command distinguishes between these states:

  • PAUSE_HARD exists: “[bold red]HARD PAUSED[/]”.
  • PAUSE exists and state is WEDGE_PAUSED: “[bold red]WEDGE-PAUSED[/] - {reason}”.
  • PAUSE exists: “[bold yellow]SOFT PAUSED[/] - {sentinel_text}”.
  • Neither exists: “[bold green]running[/]”.

The CLI provides several ways to monitor the agent’s activity.

  • attach: Creates a tmux session named autoswe if it doesn’t exist, then attaches the user to it 3. The session has a 4-pane layout:
    1. Live agent transcript via watch_active.py 4.
    2. State and parity progress, updated every 5 seconds.
    3. GPU status and proxy health, updated every 5 seconds.
    4. Live tail of the VERDICTS file.
  • watch-agent: Live-tails the currently active Workflow agent transcript by executing scripts/watch_active.py 3.
  • verdicts: Displays the last 10 verdicts from the VERDICTS file, color-coded by outcome (ACCEPT: green, REVISE: yellow, REVERT: red) 4.
  • journey: Displays the latest journey entry from docs/journey/iter-*.md.
  • rules-review: Shows pending rule-refinement proposals from RULES_QUEUE, indicating which are auto-applicable (additive) and which require operator approval (relaxation/removal).

Running autoswe without arguments, or explicitly calling autoswe tui, launches an interactive menu-driven interface 2. The TUI provides a quick-access menu for common operations:

  • s: Refresh status 5.
  • p: Soft pause.
  • P: Hard pause.
  • r: Resume.
  • a: Attach to tmux session.
  • v: View verdicts.
  • j: View journey.
  • R: Rules review.
  • q: Quit.

The TUI calls core.render_status() to display the current state, parity, and health metrics in a rich panel.

The install-units command renders systemd unit templates from the deploy/ directory and installs them into ~/.config/systemd/user/ 6. It substitutes the @AUTOSWE_REPO_ROOT@ placeholder with the actual repository root path. The units are installed but not enabled or started; the operator must run autoswe start to begin the loop.