diff options
| author | Igor Soarez <igor@soarez.org> | 2026-10-23 18:45:06 +0300 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-10-23 18:45:06 +0300 |
| commit | b4f45632debe6b8dc2f44ca6cc1b003d9093ad33 (patch) | |
| tree | 550add91d02656156330f497d60fe0e6bdf2fc35 /crates | |
| parent | 12ce9f3f8edc84064458b649e8615247641dad36 (diff) | |
session groups: list each pane once, save each group once
a pane in several sessions (a session group, `new-session -t`, or a
linked window) was listed once per session: every agent of a group showed
twice in the menu, panel, search, `dingger status`, and the counts. and
snapshots saved each session of a group with its own copy of the windows,
so restore would have rebuilt them twice and resumed each agent twice on
one session file.
- a pane keeps its first listing (tmux lists sessions by name) and is
attended if the user looks at it through any session of the group.
- snapshots keep the first session of each group; the others are not
restored.
e2e step 19 covers both; the previous binaries fail it. two checks (step
11's and this one) waited for idle after a turn that started from idle,
which passed before the turn was even processed: they now wait for
working first, and the negative control for group attendance fails as it
should. step 18 now waits for the snapshot it later restores from.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/dinggerd/src/snapshot.rs | 11 | ||||
| -rw-r--r-- | crates/dinggerd/src/tmux.rs | 28 | ||||
| -rw-r--r-- | crates/dinggerd/src/watcher.rs | 4 |
3 files changed, 26 insertions, 17 deletions
diff --git a/crates/dinggerd/src/snapshot.rs b/crates/dinggerd/src/snapshot.rs index d4ee321..715bf37 100644 --- a/crates/dinggerd/src/snapshot.rs +++ b/crates/dinggerd/src/snapshot.rs @@ -197,13 +197,22 @@ pub fn capture(now_ms: u64) -> Option<Snapshot> { "#{@agent_session}", "#{@dingger_cmd}", "#{pane_dead}", + "#{?session_grouped,#{session_group},}", ] .join("\t"); let out = tmux::run(&["list-panes", "-a", "-F", &format]).ok()?; let lines: Vec<Vec<&str>> = out .lines() .map(|line| line.split('\t').collect::<Vec<_>>()) - .filter(|f| f.len() >= 21) + .filter(|f| f.len() >= 22) + .collect(); + // One session per group: the others show the same windows, and saving + // them would restore every window, and resume every agent, twice. The + // first listed (tmux lists sessions by name) stands for its group. + let mut group_of_kept: std::collections::HashMap<&str, &str> = std::collections::HashMap::new(); + let lines: Vec<Vec<&str>> = lines + .into_iter() + .filter(|f| f[21].is_empty() || *group_of_kept.entry(f[21]).or_insert(f[0]) == f[0]) .collect(); // What runs in the foreground of each pane's terminal. let pane_pids: Vec<u32> = lines diff --git a/crates/dinggerd/src/tmux.rs b/crates/dinggerd/src/tmux.rs index 182d62f..6610161 100644 --- a/crates/dinggerd/src/tmux.rs +++ b/crates/dinggerd/src/tmux.rs @@ -15,10 +15,10 @@ pub struct Pane { /// Working directory of the pane's foreground process. pub cwd: String, pub dead: bool, - /// The pane's window is the current window of its session. - pub window_active: bool, - /// The pane's session has at least one attached client. - pub session_attached: bool, + /// The user is looking at this pane's window: it is the current window + /// of a session with an attached client. herdr marks every pane of the + /// active tab seen (`mark_active_tab_seen`); a tmux window is a tab. + pub attended: bool, pub agent: Option<Agent>, /// Pane options written by dingger (see the watcher module docs). pub written_state: String, @@ -30,13 +30,6 @@ pub struct Pane { pub written_session: String, } -impl Pane { - /// The user is looking at this pane's window. herdr marks every pane of - /// the active tab seen (`mark_active_tab_seen`); a tmux window is a tab. - pub fn attended(&self) -> bool { - self.window_active && self.session_attached - } -} /// The tmux binary. launchd starts dingger, and the menu bar app that runs /// `dingger focus`, with PATH=/usr/bin:/bin:/usr/sbin:/sbin, where Homebrew's @@ -92,6 +85,9 @@ fn run_tmux(args: &[&str]) -> Result<String, String> { Ok(String::from_utf8_lossy(&output.stdout).into_owned()) } +/// Every pane, once. A pane in several sessions (a session group, or a +/// linked window) keeps its first listing (tmux lists sessions by name), +/// and is attended if the user looks at it in any of them. pub fn list_panes() -> Result<Vec<Pane>, String> { let format = concat!( "#{pane_id}\t", @@ -115,13 +111,18 @@ pub fn list_panes() -> Result<Vec<Pane>, String> { "#{@agent_session}", ); let out = run_tmux(&["list-panes", "-a", "-F", format])?; - let mut panes = Vec::new(); + let mut panes: Vec<Pane> = Vec::new(); let mut process_tree = None; for line in out.lines() { let fields: Vec<&str> = line.split('\t').collect(); if fields.len() < 19 { continue; } + let attended = fields[4] == "1" && fields[5] != "0"; + if let Some(listed) = panes.iter_mut().find(|pane| pane.pane_id == fields[0]) { + listed.attended |= attended; + continue; + } let current_command = fields[1]; let start_command = fields[6]; let pane_pid: Option<u32> = fields[7].trim().parse().ok(); @@ -147,8 +148,7 @@ pub fn list_panes() -> Result<Vec<Pane>, String> { pane_title: fields[2].to_string(), cwd: fields[16].to_string(), dead: fields[3] == "1", - window_active: fields[4] == "1", - session_attached: fields[5] != "0", + attended, agent, written_state: fields[8].to_string(), written_agent: fields[9].to_string(), diff --git a/crates/dinggerd/src/watcher.rs b/crates/dinggerd/src/watcher.rs index 8951623..9198f60 100644 --- a/crates/dinggerd/src/watcher.rs +++ b/crates/dinggerd/src/watcher.rs @@ -267,7 +267,7 @@ impl Watcher { // finished between two ticks is still a completion. let mut alerts = Vec::new(); for observed in observations { - let next = advance(track, observed, pane.attended(), acked, now); + let next = advance(track, observed, pane.attended, acked, now); if next.state != track.state { info!( target = %pane.display_target, @@ -338,7 +338,7 @@ impl Watcher { fn notify(&self, pane: &tmux::Pane, kind: NotificationKind) { // herdr: a blocked pane plays the alert even when the user is looking // at it; a finished pane stays silent when they already are. - let watching = pane.attended(); + let watching = pane.attended; if matches!(kind, NotificationKind::Finished) && watching { return; } |
