TUI hosts sessions: new-session form, named worktrees, resume, faster permissions

- Use the terminal's own colors and background; the key bar and the Needs-you
  panel wrap, fixed-width panels shrink on narrow terminals.
- Sessions run on threads of the TUI (tui/host.rs), capped by the profile's
  `workers`; quitting asks for `yes` and suspends them. New `suspend` command
  keeps the state so a session can be resumed.
- `N` opens a new-session form: machine, name, --after, a named branch or
  worktree (place.rs; never deleted by orch), and a "keep for a PR" option.
- `u` resumes suspended sessions and ones whose process died.
- `A` allows identical permission requests across sessions, `P` saves an allow
  rule to the profile with toml_edit (comments kept).
- Fix clippy lint in report.rs so tests/all.sh passes; add GLOSSARY.md.

Includes the already staged `orch init` work (init.rs, example profile).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-14 18:04:41 +01:00
1 parent 5a80bc9fe1
commit cfb735cdb3
22 files changed
+1623 -115

No files matched your search

+78
View File
@@ -4,6 +4,35 @@ use anyhow::{Context, Result, bail};
use serde::Deserialize;
use std::path::PathBuf;
/// [`Profile::add_allow`] on a file.
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
crate::policy::check_entry(entry)?;
let text = std::fs::read_to_string(path).map_err(|e| {
if e.kind() == std::io::ErrorKind::NotFound {
anyhow::anyhow!(
"{} does not exist: the implicit default profile has no allowlist to extend",
path.display()
)
} else {
anyhow::anyhow!("{}: {e}", path.display())
}
})?;
let mut doc: toml_edit::DocumentMut =
text.parse().with_context(|| path.display().to_string())?;
let Some(list) = doc.get_mut("allow").and_then(|a| a.as_array_mut()) else {
bail!(
"{} has no `allow` list: without one every tool is already allowed",
path.display()
);
};
if list.iter().any(|v| v.as_str() == Some(entry)) {
return Ok(false);
}
list.push(entry);
std::fs::write(path, doc.to_string()).with_context(|| path.display().to_string())?;
Ok(true)
}
#[derive(Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
pub struct Budget {
@@ -117,6 +146,19 @@ impl Profile {
Self::parse(&s).with_context(|| path.display().to_string())
}
/// Appends `entry` to the `allow` list of profile `name`, keeping the rest of the file (comments, order) as it
/// is. Returns false when the entry was there already. Refuses a profile without a file or without `allow`:
/// no list means "everything allowed", and one entry would silently turn that into "almost nothing".
pub fn add_allow(name: &str, entry: &str) -> Result<bool> {
if name.is_empty() || name.contains(['/', '.']) {
bail!("bad profile name {name:?}");
}
let path = crate::config_dir()
.join("profiles")
.join(format!("{name}.toml"));
add_allow_at(&path, entry)
}
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
self.account.as_deref().unwrap_or(profile)
}
@@ -180,4 +222,40 @@ mod tests {
fn rejects_path_like_names() {
assert!(Profile::load("../x").is_err());
}
#[test]
fn add_allow_keeps_the_file_and_refuses_what_would_change_its_meaning() {
let dir = std::env::temp_dir().join(format!("orch-addallow-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let f = dir.join("p.toml");
std::fs::write(
&f,
"# mine\nhx = \"hx\"\nallow = [\"read\", \"edit\"] # tools\n[budget]\nmax_turns = 3\n",
)
.unwrap();
assert!(add_allow_at(&f, "bash:cargo *").unwrap());
assert!(!add_allow_at(&f, "bash:cargo *").unwrap(), "already there");
let text = std::fs::read_to_string(&f).unwrap();
assert!(
text.contains("# mine") && text.contains("# tools") && text.contains("max_turns = 3"),
"{text}"
);
let p = Profile::parse(&text).unwrap();
assert_eq!(p.allow.unwrap(), ["read", "edit", "bash:cargo *"]);
assert!(add_allow_at(&f, "bad entry").is_err());
assert!(
add_allow_at(&f, "edit:x").is_err(),
"only bash takes a pattern"
);
std::fs::write(&f, "hx = \"hx\"\n").unwrap();
assert!(
add_allow_at(&f, "read")
.unwrap_err()
.to_string()
.contains("no `allow` list")
);
assert!(add_allow_at(&dir.join("none.toml"), "read").is_err());
let _ = std::fs::remove_dir_all(&dir);
}
}