feat(maestro): nest sessions by live working directory, drop labels
Replace the freeform `metadata.label` session grouping with nesting derived
from each session's working directory. The daemon's activity watcher already
polls each tmux pane every tick, so it now also captures
`#{pane_current_path}` and surfaces it as a new `Session.current_cwd`
(serde-default, back-compat); `cwd` stays the spawn dir for worktree
inference, spawn-similar, and recents.
Web catalog builds the tree from `current_cwd ?? cwd`, collapses the home
dir to `~`, and folds single-child folder chains so `~/git/maestro` reads as
one node. CLI swaps its LABEL column for an abbreviated DIR; the spawn forms
(web + TUI) and `--label` flag are removed.
The pane format stays space-delimited (parser splits the first three tokens
and keeps the remainder as the path) so a cwd containing spaces survives.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -65,9 +65,6 @@ pub struct SpawnArgs {
|
||||
/// Command to launch (e.g. `bash`, `claude`).
|
||||
#[arg(long)]
|
||||
pub command: String,
|
||||
/// Human-readable label, persisted in session metadata (`label`).
|
||||
#[arg(long)]
|
||||
pub label: Option<String>,
|
||||
/// Set an env var on the session (`KEY=VALUE`). Repeatable.
|
||||
#[arg(long = "env", short = 'e', value_parser = parse_kv, value_name = "KEY=VALUE")]
|
||||
pub env: Vec<(String, String)>,
|
||||
|
||||
@@ -45,10 +45,7 @@ pub async fn run_spawn(client: &RegistryClient, args: SpawnArgs) -> Result<Sessi
|
||||
env.insert(k.clone(), v.clone());
|
||||
}
|
||||
|
||||
let mut metadata: HashMap<String, Value> = HashMap::new();
|
||||
if let Some(label) = args.label.as_deref() {
|
||||
metadata.insert("label".into(), Value::String(label.into()));
|
||||
}
|
||||
let metadata: HashMap<String, Value> = HashMap::new();
|
||||
|
||||
let worktree = match (args.worktree_from.as_ref(), args.branch.as_ref()) {
|
||||
(Some(repo), Some(branch)) => Some(WorktreeSpec {
|
||||
@@ -119,24 +116,19 @@ fn print_session_table(out: &mut impl Write, sessions: &[Session], daemons: &[Da
|
||||
}
|
||||
|
||||
for (daemon_id, group) in &by_daemon {
|
||||
let hostname = daemons
|
||||
.iter()
|
||||
.find(|d| &d.daemon_id == daemon_id)
|
||||
.map(|d| d.hostname.as_str())
|
||||
.unwrap_or("?");
|
||||
let daemon = daemons.iter().find(|d| &d.daemon_id == daemon_id);
|
||||
let hostname = daemon.map(|d| d.hostname.as_str()).unwrap_or("?");
|
||||
let home = daemon.map(|d| d.home_dir.as_str()).unwrap_or("");
|
||||
writeln!(out, "\n{daemon_id} ({hostname})").ok();
|
||||
writeln!(
|
||||
out,
|
||||
" {:<36} {:<8} {:<9} {:<20} {}",
|
||||
"ID", "STATUS", "ACTIVITY", "LABEL", "COMMAND"
|
||||
" {:<36} {:<8} {:<9} {:<28} {}",
|
||||
"ID", "STATUS", "ACTIVITY", "DIR", "COMMAND"
|
||||
)
|
||||
.ok();
|
||||
for s in group {
|
||||
let label = s
|
||||
.metadata
|
||||
.get("label")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("-");
|
||||
// The pane's live cwd if observed, else the spawn dir, home-abbreviated.
|
||||
let dir = abbreviate_dir(s.current_cwd.as_deref().unwrap_or(&s.cwd), home);
|
||||
let status = match s.status {
|
||||
SessionStatus::Running => "running",
|
||||
SessionStatus::Dead => "dead",
|
||||
@@ -154,14 +146,29 @@ fn print_session_table(out: &mut impl Write, sessions: &[Session], daemons: &[Da
|
||||
};
|
||||
writeln!(
|
||||
out,
|
||||
" {:<36} {:<8} {:<9} {:<20} {command}",
|
||||
s.id, status, activity, label
|
||||
" {:<36} {:<8} {:<9} {:<28} {command}",
|
||||
s.id, status, activity, dir
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Render a path with the daemon's home dir collapsed to `~`. Mirrors the web
|
||||
/// UI's abbreviation so CLI and browser show the same directory shorthand.
|
||||
fn abbreviate_dir(path: &std::path::Path, home: &str) -> String {
|
||||
let p = path.to_string_lossy();
|
||||
if !home.is_empty() {
|
||||
if p == home {
|
||||
return "~".into();
|
||||
}
|
||||
if let Some(rest) = p.strip_prefix(&format!("{home}/")) {
|
||||
return format!("~/{rest}");
|
||||
}
|
||||
}
|
||||
p.into_owned()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
@@ -169,33 +176,31 @@ mod tests {
|
||||
|
||||
use chrono::{TimeZone, Utc};
|
||||
use maestro_protocol::{ActivityState, DaemonInfo, Session, SessionStatus};
|
||||
use serde_json::Value;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn session(daemon: &str, label: &str, command: &str, id: u128) -> Session {
|
||||
let mut meta = HashMap::new();
|
||||
meta.insert("label".into(), Value::String(label.into()));
|
||||
fn session(daemon: &str, cwd: &str, command: &str, id: u128) -> Session {
|
||||
Session {
|
||||
id: Uuid::from_u128(id),
|
||||
daemon_id: daemon.into(),
|
||||
cwd: PathBuf::from("/tmp"),
|
||||
cwd: PathBuf::from(cwd),
|
||||
command: command.into(),
|
||||
env: HashMap::new(),
|
||||
metadata: meta,
|
||||
metadata: HashMap::new(),
|
||||
status: SessionStatus::Running,
|
||||
created_at: Utc.with_ymd_and_hms(2026, 5, 25, 12, 0, 0).unwrap(),
|
||||
foreground: None,
|
||||
activity: Default::default(),
|
||||
last_activity_at: chrono::Utc::now(),
|
||||
current_cwd: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_grouped_table() {
|
||||
let sessions = vec![
|
||||
session("laptop", "personal/maestro", "claude", 1),
|
||||
session("vm1", "work/api", "bash", 2),
|
||||
session("laptop", "scratch", "nvim", 3),
|
||||
session("laptop", "/home/naps/maestro", "claude", 1),
|
||||
session("vm1", "/srv/work/api", "bash", 2),
|
||||
session("laptop", "/home/naps/scratch", "nvim", 3),
|
||||
];
|
||||
let daemons = vec![
|
||||
DaemonInfo {
|
||||
@@ -203,7 +208,7 @@ mod tests {
|
||||
hostname: "naps-laptop".into(),
|
||||
version: "0.1.0".into(),
|
||||
daemon_url: "ws://10.0.0.1:7070".into(),
|
||||
home_dir: String::new(),
|
||||
home_dir: "/home/naps".into(),
|
||||
},
|
||||
DaemonInfo {
|
||||
daemon_id: "vm1".into(),
|
||||
@@ -218,15 +223,36 @@ mod tests {
|
||||
let s = String::from_utf8(buf).unwrap();
|
||||
assert!(s.contains("laptop (naps-laptop)"), "{s}");
|
||||
assert!(s.contains("vm1 (vm1.lan)"), "{s}");
|
||||
assert!(s.contains("personal/maestro"), "{s}");
|
||||
// Home dir collapses to ~ in the DIR column.
|
||||
assert!(s.contains("~/maestro"), "{s}");
|
||||
// No home dir → path shown verbatim.
|
||||
assert!(s.contains("/srv/work/api"), "{s}");
|
||||
assert!(s.contains("running"), "{s}");
|
||||
assert!(s.contains("ACTIVITY"), "{s}");
|
||||
assert!(s.contains("DIR"), "{s}");
|
||||
assert!(s.contains("idle"), "{s}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_cwd_overrides_spawn_dir_in_table() {
|
||||
let mut s = session("laptop", "/home/naps/maestro", "bash", 1);
|
||||
s.current_cwd = Some(PathBuf::from("/home/naps/maestro/crates/maestro-cli"));
|
||||
let daemons = vec![DaemonInfo {
|
||||
daemon_id: "laptop".into(),
|
||||
hostname: "h".into(),
|
||||
version: "0.1.0".into(),
|
||||
daemon_url: "ws://x".into(),
|
||||
home_dir: "/home/naps".into(),
|
||||
}];
|
||||
let mut buf = Vec::new();
|
||||
super::print_session_table(&mut buf, &[s], &daemons);
|
||||
let out = String::from_utf8(buf).unwrap();
|
||||
assert!(out.contains("~/maestro/crates/maestro-cli"), "{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_activity_and_foreground() {
|
||||
let mut s1 = session("laptop", "work", "bash", 1);
|
||||
let mut s1 = session("laptop", "/tmp", "bash", 1);
|
||||
s1.activity = ActivityState::AwaitingInput;
|
||||
s1.foreground = Some("claude".into()); // differs from spawn command
|
||||
let daemons = vec![DaemonInfo {
|
||||
|
||||
Reference in New Issue
Block a user