Add Needs-you queue and goal view with acceptance checks

- needs table: human steps, permission requests and agent questions wait
  for an answer written to the database; a/c/d, y/Y/n, r keys in the TUI
- goal view (g): task graph, critical path, decisions, acceptance checks;
  e edit goal, + add check, R run all checks on main
- checks.rs: acceptance checks on a branch or on main in a clean worktree
- runner: wait for --after dependencies, one session in merge at a time,
  all checks again on main after each merge
- orch goal / check / checks commands, ORCH_DB and {{repo}} for machine steps
- example machines merge with git merge --ff-only

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-14 12:38:46 +01:00
1 parent 5b659fa8ba
commit 7bf0986640
16 files changed
+2551 -105

No files matched your search

+100 -2
View File
@@ -1,7 +1,9 @@
mod acp;
mod adapter;
mod checks;
mod db;
mod detail;
mod goal;
mod junit;
mod lock;
mod machine;
@@ -73,8 +75,42 @@ enum Cmd {
#[arg(long)]
check: bool,
},
/// Create a state-machine session in REPO and run it to the end (human steps are not supported yet).
/// Show or set the goal sentence; `--export` also prints the acceptance checks (for machine steps).
Goal {
/// New goal text.
text: Option<String>,
#[arg(long)]
export: bool,
/// Repo with the goal (default: ORCH_DB of a machine step, else the current directory).
#[arg(long)]
repo: Option<PathBuf>,
},
/// Add an acceptance check: a shell command, pass = exit 0.
Check {
name: String,
cmd: String,
/// Session that is responsible for it (its `run-acceptance` step runs it before merging).
#[arg(long)]
owner: Option<String>,
#[arg(long)]
repo: Option<PathBuf>,
},
/// Run acceptance checks in the current directory (a worktree), or with --main in a clean copy of main.
Checks {
/// Only the checks this session owns.
#[arg(long)]
owner: Option<String>,
/// All checks on main; the results are recorded for the goal view.
#[arg(long)]
main: bool,
#[arg(long)]
repo: Option<PathBuf>,
},
/// Create a state-machine session in REPO and run it to the end. Waits for `--after` sessions to merge.
Session {
/// Sessions that must be merged before this one starts, comma separated.
#[arg(long, value_delimiter = ',')]
after: Vec<String>,
#[arg(long)]
repo: PathBuf,
/// Machine file name, without .toml (looked up in REPO/.hx/machines, then ~/.hx/machines).
@@ -120,6 +156,20 @@ pub fn state_dir() -> PathBuf {
env_dir("ORCH_STATE_DIR", "XDG_STATE_HOME", ".local/state")
}
/// The goal database: `--repo`, else `ORCH_DB` (set by the runner for machine steps), else `./.hx/orch.db`.
fn open_db(repo: Option<&Path>) -> Result<db::Db> {
if repo.is_none()
&& let Some(p) = std::env::var_os("ORCH_DB")
{
return db::Db::open(Path::new(&p));
}
let dir = match repo {
Some(r) => r.to_path_buf(),
None => std::env::current_dir()?,
};
db::Db::open(&dir.join(".hx/orch.db"))
}
fn code(ok: bool) -> std::process::ExitCode {
u8::from(!ok).into()
}
@@ -130,7 +180,55 @@ fn main() -> Result<std::process::ExitCode> {
return Ok(code(true));
};
match cmd {
Cmd::Goal { text, export, repo } => {
let db = open_db(repo.as_deref())?;
if let Some(t) = text {
db.set_goal(&t)?;
}
println!("{}", db.goal()?.unwrap_or_else(|| "no goal set".into()));
if export {
println!("\nAcceptance checks (all must pass on main):");
for c in db.checks()? {
let owner = c.owner.map_or(String::new(), |o| format!(" [{o}]"));
println!("- {}{owner}: {}", c.name, c.cmd);
}
}
Ok(code(true))
}
Cmd::Check {
name,
cmd,
owner,
repo,
} => {
let id = open_db(repo.as_deref())?.add_check(&name, &cmd, owner.as_deref())?;
println!("check {id}: {name}");
Ok(code(true))
}
Cmd::Checks { owner, main, repo } => {
let db = open_db(repo.as_deref())?;
let results = if main {
let repo = match (repo, std::env::var_os("ORCH_REPO")) {
(Some(r), _) => r,
(None, Some(r)) => r.into(),
(None, None) => std::env::current_dir()?,
};
checks::run_on_main(&db, &repo)?
} else {
checks::run(&db, &std::env::current_dir()?, owner.as_deref(), false)?
};
for r in &results {
if r.pass {
println!("✓ {}", r.check.name);
} else {
println!("✗ {} (exit {})", r.check.name, r.exit.unwrap_or(-1));
print!("{}", r.output);
}
}
Ok(code(results.iter().all(|r| r.pass)))
}
Cmd::Session {
after,
repo,
machine,
name,
@@ -144,7 +242,7 @@ fn main() -> Result<std::process::ExitCode> {
// 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 s = runner::create_after(&db, &wts, &name, "", &machine, &after)?;
let status = runner::run_session(&db, &m, &s.id, &repo, &scope, &profile)?;
println!("{} {} -> {status}", s.id, s.branch);
Ok(code(status == "merged"))