Add orch session --resume to continue an unfinished session
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f2486a599
commit
d4c6e9133b
1 file changed
+38
-9
+38
-9
@@ -115,10 +115,13 @@ enum Cmd {
|
||||
#[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,
|
||||
#[arg(long, required_unless_present = "resume")]
|
||||
machine: Option<String>,
|
||||
#[arg(long, required_unless_present = "resume")]
|
||||
name: Option<String>,
|
||||
/// Continue this unfinished session (e.g. s1) from its saved state instead of creating one.
|
||||
#[arg(long, conflicts_with_all = ["machine", "name", "after"])]
|
||||
resume: Option<String>,
|
||||
/// Value for {{scope}} in machine commands.
|
||||
#[arg(long, default_value = "")]
|
||||
scope: String,
|
||||
@@ -233,17 +236,43 @@ fn main() -> Result<std::process::ExitCode> {
|
||||
repo,
|
||||
machine,
|
||||
name,
|
||||
resume,
|
||||
scope,
|
||||
profile,
|
||||
} => {
|
||||
let profile = profile::Profile::load(&profile)?;
|
||||
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_after(&db, &wts, &name, "", &machine, &after)?;
|
||||
let s = if let Some(id) = resume {
|
||||
let s = db
|
||||
.session(&id)?
|
||||
.with_context(|| format!("no session {id}"))?;
|
||||
anyhow::ensure!(
|
||||
!db.events(Some(&id), 0)?.iter().any(|e| e.kind == "end"),
|
||||
"session {id} already ended; start a new one"
|
||||
);
|
||||
anyhow::ensure!(
|
||||
s.pid
|
||||
.is_none_or(|p| !Path::new(&format!("/proc/{p}")).exists()
|
||||
|| p == std::process::id()),
|
||||
"session {id} is still running (pid {})",
|
||||
s.pid.unwrap_or(0)
|
||||
);
|
||||
s
|
||||
} else {
|
||||
// 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 (machine, name) = (machine.unwrap_or_default(), name.unwrap_or_default());
|
||||
machine::Machine::find(&machine, &repo)?;
|
||||
runner::create_after(&db, &wts, &name, "", &machine, &after)?
|
||||
};
|
||||
let task = db
|
||||
.tasks()?
|
||||
.into_iter()
|
||||
.find(|t| t.id == s.task_id)
|
||||
.with_context(|| format!("no task {}", s.task_id))?;
|
||||
let m = machine::Machine::find(&task.machine, &repo)?;
|
||||
let status = runner::run_session(&db, &m, &s.id, &repo, &scope, &profile)?;
|
||||
println!("{} {} -> {status}", s.id, s.branch);
|
||||
Ok(code(status == "merged"))
|
||||
|
||||
Reference in new issue
Block a user