feat: orch up starts issue sessions in existing worktrees
orch up MANIFEST reads an issue manifest (a path, or NAME in manifest_dir, default <config>/manifests, set in <config>/config.toml) and starts one detached session per listed worktree, across repos. Each worktree brings its own machine, profile and .hx/task.md; the task text now reaches the agent. Sessions live in <state>/issues.db; orch issues shows them grouped by issue. Also: liveness checks use kill(pid, 0) instead of /proc (broken on macOS), the same branch name in two repos no longer counts as the same place, and the merge queue column ticket is renamed to issue (migrated on open). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
440b19180e
commit
20f88d88df
16 files changed
+791
-65
No files matched your search
+46
-12
@@ -18,11 +18,17 @@ use std::io::IsTerminal;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
/// The TUI on the current directory's `.hx/orch.db`, or with `issues` on the database of `orch up`.
|
||||
pub fn run(issues: bool) -> Result<()> {
|
||||
if !std::io::stdout().is_terminal() {
|
||||
bail!("orch needs a terminal; use a subcommand (orch --help) in scripts");
|
||||
}
|
||||
let mut app = App::new(std::env::current_dir()?);
|
||||
if issues {
|
||||
app.db_path = crate::issue::db_path();
|
||||
app.issues = true;
|
||||
app.rev = "all repos".into();
|
||||
}
|
||||
let mut term = ratatui::init();
|
||||
let res = event_loop(&mut term, &mut app);
|
||||
ratatui::restore();
|
||||
@@ -155,6 +161,10 @@ struct Pager {
|
||||
|
||||
struct App {
|
||||
repo: PathBuf,
|
||||
/// `<repo>/.hx/orch.db`, or the issues database.
|
||||
db_path: PathBuf,
|
||||
/// Showing the sessions of `orch up` (many repos): no new-session form and no checks on main.
|
||||
issues: bool,
|
||||
/// Opened lazily: launching `orch` in a directory without a goal must not create `.hx/orch.db`.
|
||||
db: Option<Db>,
|
||||
events: Vec<Event>,
|
||||
@@ -185,7 +195,11 @@ impl App {
|
||||
fn ensure_host(&mut self) -> Result<&mut host::Host> {
|
||||
if self.host.is_none() {
|
||||
let profile = crate::profile::Profile::load(PROFILE)?;
|
||||
self.host = Some(host::Host::new(self.repo.clone(), profile));
|
||||
self.host = Some(host::Host::new(
|
||||
self.db_path.clone(),
|
||||
self.repo.clone(),
|
||||
profile,
|
||||
));
|
||||
}
|
||||
Ok(self.host.as_mut().expect("just created"))
|
||||
}
|
||||
@@ -194,6 +208,14 @@ impl App {
|
||||
fn resume_all(&mut self) -> Result<usize> {
|
||||
let Some(db) = &self.db else { return Ok(0) };
|
||||
let ids = host::resumable(db);
|
||||
if self.issues {
|
||||
// issue sessions run detached, like `orch up` starts them: they outlive this TUI
|
||||
for id in &ids {
|
||||
crate::issue::spawn(db, id)?;
|
||||
}
|
||||
self.refresh();
|
||||
return Ok(ids.len());
|
||||
}
|
||||
let host = self.ensure_host()?;
|
||||
let ids: Vec<String> = ids.into_iter().filter(|id| !host.hosts(id)).collect();
|
||||
for id in &ids {
|
||||
@@ -209,7 +231,11 @@ impl App {
|
||||
bail!("no database")
|
||||
};
|
||||
db.reopen(id)?;
|
||||
self.ensure_host()?.submit(id);
|
||||
if self.issues {
|
||||
crate::issue::spawn(db, id)?;
|
||||
} else {
|
||||
self.ensure_host()?.submit(id);
|
||||
}
|
||||
self.refresh();
|
||||
Ok(())
|
||||
}
|
||||
@@ -247,7 +273,7 @@ impl App {
|
||||
let db = self.db.as_ref().expect("db_or_create opened it");
|
||||
let base = self.repo.file_name().unwrap_or_default();
|
||||
let wts = crate::state_dir().join("worktrees").join(base);
|
||||
let s = crate::runner::create_in(db, &wts, name, machine, &after, &place, f.no_merge)?;
|
||||
let s = crate::runner::create_in(db, &wts, name, "", machine, &after, &place, f.no_merge)?;
|
||||
if let Some(h) = &mut self.host {
|
||||
h.submit(&s.id);
|
||||
}
|
||||
@@ -272,7 +298,7 @@ impl App {
|
||||
/// Runs every check on main in the background; the goal view shows `running…` meanwhile.
|
||||
fn run_all_checks(&mut self) {
|
||||
use std::sync::atomic::Ordering;
|
||||
if self.checks_running.swap(true, Ordering::SeqCst) {
|
||||
if self.issues || self.checks_running.swap(true, Ordering::SeqCst) {
|
||||
return; // already running
|
||||
}
|
||||
let (repo, flag) = (self.repo.clone(), self.checks_running.clone());
|
||||
@@ -287,7 +313,7 @@ impl App {
|
||||
/// The goal database, created on first use by actions that only make sense with one (edit goal, add check).
|
||||
fn db_or_create(&mut self) -> Option<&Db> {
|
||||
if self.db.is_none() {
|
||||
self.db = Db::open(&self.repo.join(".hx/orch.db")).ok();
|
||||
self.db = Db::open(&self.db_path).ok();
|
||||
}
|
||||
self.db.as_ref()
|
||||
}
|
||||
@@ -429,6 +455,8 @@ impl App {
|
||||
fn new(repo: PathBuf) -> Self {
|
||||
let rev = git_rev(&repo);
|
||||
Self {
|
||||
db_path: repo.join(".hx/orch.db"),
|
||||
issues: false,
|
||||
repo,
|
||||
db: None,
|
||||
events: vec![],
|
||||
@@ -451,9 +479,8 @@ impl App {
|
||||
}
|
||||
|
||||
fn refresh(&mut self) {
|
||||
let path = self.repo.join(".hx/orch.db");
|
||||
if self.db.is_none() && path.exists() {
|
||||
self.db = Db::open(&path).ok();
|
||||
if self.db.is_none() && self.db_path.exists() {
|
||||
self.db = Db::open(&self.db_path).ok();
|
||||
}
|
||||
if let (Some(h), Some(db)) = (&mut self.host, &self.db) {
|
||||
h.tick(db);
|
||||
@@ -496,7 +523,11 @@ impl App {
|
||||
|
||||
fn header(&self) -> Header {
|
||||
let home = std::env::var("HOME").unwrap_or_default();
|
||||
let repo = self.repo.to_string_lossy().into_owned();
|
||||
let repo = if self.issues {
|
||||
"issues".to_string()
|
||||
} else {
|
||||
self.repo.to_string_lossy().into_owned()
|
||||
};
|
||||
let repo = match repo.strip_prefix(&home) {
|
||||
Some(rest) if !home.is_empty() => format!("~{rest}"),
|
||||
_ => repo,
|
||||
@@ -907,7 +938,9 @@ fn on_key(
|
||||
app.screen = Screen::Goal;
|
||||
app.refresh();
|
||||
}
|
||||
KeyCode::Char('N') => app.form = Some(newform::Form::new(&app.repo)),
|
||||
KeyCode::Char('N') if !app.issues => {
|
||||
app.form = Some(newform::Form::new(&app.repo));
|
||||
}
|
||||
KeyCode::Char('u') if app.overview.resumable > 0 => {
|
||||
if let Err(e) = app.resume_all() {
|
||||
app.pager = Some(Pager {
|
||||
@@ -1147,6 +1180,7 @@ mod tests {
|
||||
ok,
|
||||
last: &str| Row {
|
||||
id: id.into(),
|
||||
group: String::new(),
|
||||
status,
|
||||
task: task.into(),
|
||||
sub: sub.into(),
|
||||
@@ -1921,7 +1955,7 @@ end = "merged"
|
||||
}
|
||||
let err = app.start_session(&form).unwrap_err().to_string();
|
||||
assert!(err.contains("name"), "{err}");
|
||||
form.name = "ticket work".into();
|
||||
form.name = "issue work".into();
|
||||
form.after = "s1, s9".into();
|
||||
let err = app.start_session(&form).unwrap_err().to_string();
|
||||
assert!(err.contains("no session s9"), "{err}");
|
||||
|
||||
Reference in new issue
Block a user