Add state-machine sessions, event table and TUI overview

- machine.rs: TOML machine parser/validator, four example machines
- db.rs: per-goal SQLite (.hx/orch.db) with append-only events
- runner.rs: session runner for computer steps (catches, retries, resume)
- view.rs + tui/: sessions overview built from events; bare `orch` opens it
- orch session: create and run a session from the CLI
- devenv with git and sqlite

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-14 11:58:23 +01:00
1 parent 374cf28aed
commit d66a014bc5
19 files changed
+4525 -8

No files matched your search

+45 -3
View File
@@ -1,10 +1,15 @@
mod adapter;
mod db;
mod lock;
mod machine;
mod policy;
mod profile;
mod report;
mod run;
mod runner;
mod state;
mod tui;
mod view;
use anyhow::{Context, Result, bail};
use clap::{Parser, Subcommand};
@@ -14,10 +19,13 @@ use std::sync::Mutex;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
#[derive(Parser)]
#[command(version, about = "Run hx coding agents on tasks")]
#[command(
version,
about = "Run hx coding agents on tasks; without a subcommand, opens the TUI"
)]
struct Cli {
#[command(subcommand)]
cmd: Cmd,
cmd: Option<Cmd>,
}
#[derive(Subcommand)]
@@ -62,6 +70,19 @@ enum Cmd {
#[arg(long)]
check: bool,
},
/// Create a state-machine session in REPO and run it to the end (computer steps only for now).
Session {
#[arg(long)]
repo: PathBuf,
/// Machine file name, without .toml (looked up in REPO/.hx/machines, then ~/.hx/machines).
#[arg(long)]
machine: String,
#[arg(long)]
name: String,
/// Value for {{scope}} in machine commands.
#[arg(long, default_value = "")]
scope: String,
},
/// hx extension that enforces a run's tool allowlist (started by hx, not by hand).
#[command(hide = true)]
Guard { policy: PathBuf },
@@ -98,7 +119,28 @@ fn code(ok: bool) -> std::process::ExitCode {
}
fn main() -> Result<std::process::ExitCode> {
match Cli::parse().cmd {
let Some(cmd) = Cli::parse().cmd else {
tui::run()?;
return Ok(code(true));
};
match cmd {
Cmd::Session {
repo,
machine,
name,
scope,
} => {
let repo = repo.canonicalize()?;
let m = machine::Machine::find(&machine, &repo)?;
let db = db::Db::open(&repo.join(".hx/orch.db"))?;
// shortcut: worktrees are grouped by repo directory name; two repos with one name would share ids
let base = repo.file_name().unwrap_or_default();
let wts = state_dir().join("worktrees").join(base);
let s = runner::create(&db, &wts, &name, "", &machine)?;
let status = runner::run_session(&db, &m, &s.id, &repo, &scope)?;
println!("{} {} -> {status}", s.id, s.branch);
Ok(code(status == "merged"))
}
Cmd::Run {
task,
repo,