1use std::collections::HashMap;
23
24use taimux_core::{conv, state, tmux};
25
26pub fn transcript_is_settled(text: &str, now: i64) -> Result<(), String> {
40 let Some(last) = text.lines().rfind(|l| !l.trim().is_empty()) else {
41 return Ok(()); };
43 if taimux_core::json::field(last, "type") == "assistant"
44 && (last.contains("\"type\":\"tool_use\"") || last.contains("\"type\": \"tool_use\""))
45 {
46 return Err("a tool call is still running".into());
47 }
48 let ts = taimux_core::json::field(last, "timestamp");
49 if ts.is_empty() {
50 return Ok(());
51 }
52 let Some(then) = parse_iso8601(&ts) else {
53 return Ok(()); };
55 if now - then < 45 {
56 return Err("active in the last 45s".into());
57 }
58 Ok(())
59}
60
61fn parse_iso8601(s: &str) -> Option<i64> {
65 taimux_core::turn::epoch_ms(s).map(|ms| ms.div_euclid(1000))
66}
67
68pub fn screen_has_no_dialog(screen: &str) -> Result<(), String> {
73 if state::awaits_input(screen) {
74 return Err("a dialog is waiting for an answer".into());
75 }
76 let tail: Vec<&str> = screen
77 .lines()
78 .filter(|l| !l.trim().is_empty())
79 .rev()
80 .take(4)
81 .collect();
82 if tail
83 .iter()
84 .any(|l| l.contains("Press Ctrl-C again to exit"))
85 {
86 return Err("a Ctrl-C is already half-pressed".into());
87 }
88 Ok(())
89}
90
91pub fn screen_has_no_draft(screen: &str) -> Result<(), String> {
97 let txt: Vec<&str> = screen.lines().filter(|l| !l.trim().is_empty()).collect();
98 if txt.is_empty() {
99 return Ok(());
100 }
101 let Some(box_line) = txt.iter().rev().find(|l| l.contains('❯')) else {
102 return Err("no prompt box on screen".into());
103 };
104 let after = box_line.split_once('❯').map(|(_, r)| r).unwrap_or("");
105 let rest: String = after
106 .chars()
107 .filter(|c| !c.is_whitespace() && *c != '\u{a0}')
108 .collect();
109 if rest.is_empty() {
110 Ok(())
111 } else {
112 Err("unsent text in the prompt box".into())
113 }
114}
115
116const BOX_ROWS: usize = 6;
131
132type Cmd = Vec<String>;
134
135type ZoomSteps = (Vec<Cmd>, Vec<Cmd>);
137
138fn zoom_steps(
154 pane: &str,
155 zoomed: bool,
156 pane_rows: usize,
157 window_rows: usize,
158 active: &str,
159 last: &str,
160) -> Option<ZoomSteps> {
161 if pane_rows >= BOX_ROWS || window_rows < BOX_ROWS || window_rows <= pane_rows {
162 return None;
163 }
164 let cmd = |a: &[&str]| a.iter().map(|s| s.to_string()).collect::<Cmd>();
165
166 let mut go = Vec::new();
167 if zoomed {
172 go.push(cmd(&["resize-pane", "-Z", "-t", pane]));
173 }
174 go.push(cmd(&["resize-pane", "-Z", "-t", pane]));
175
176 let mut back = vec![cmd(&["resize-pane", "-Z", "-t", pane])];
177 if active != pane {
183 if !last.is_empty() && last != pane {
184 back.push(cmd(&["select-pane", "-t", last]));
185 }
186 if !active.is_empty() {
187 back.push(cmd(&["select-pane", "-t", active]));
188 }
189 }
190 if zoomed && !active.is_empty() {
194 back.push(cmd(&["resize-pane", "-Z", "-t", active]));
195 }
196 Some((go, back))
197}
198
199struct Restoring(Vec<Cmd>);
205
206impl Drop for Restoring {
207 fn drop(&mut self) {
208 for c in &self.0 {
209 tmux::run(&c.iter().map(String::as_str).collect::<Vec<_>>());
210 }
211 }
212}
213
214pub fn capture_zoomed(pane: &str) -> Option<String> {
227 if !taimux_core::env::on("TAIMUX_ZOOM_TO_READ") {
228 return None;
229 }
230 let geom = tmux::ask(&[
231 "display-message",
232 "-p",
233 "-t",
234 pane,
235 "-F",
236 "#{window_zoomed_flag}\t#{pane_height}\t#{window_height}\t#{window_id}",
237 ])?;
238 let g: Vec<&str> = geom.trim_end().split('\t').collect();
239 if g.len() < 4 {
240 return None;
241 }
242 let (zoomed, win) = (g[0] == "1", g[3]);
243 let pane_rows: usize = g[1].parse().ok()?;
244 let window_rows: usize = g[2].parse().ok()?;
245
246 let mut active = String::new();
247 let mut last = String::new();
248 for l in tmux::ask(&[
249 "list-panes",
250 "-t",
251 win,
252 "-F",
253 "#{pane_id}\t#{pane_active}\t#{pane_last}",
254 ])?
255 .lines()
256 {
257 let c: Vec<&str> = l.split('\t').collect();
258 if c.len() < 3 {
259 continue;
260 }
261 if c[1] == "1" {
262 active = c[0].to_string();
263 }
264 if c[2] == "1" {
265 last = c[0].to_string();
266 }
267 }
268
269 let (go, back) = zoom_steps(pane, zoomed, pane_rows, window_rows, &active, &last)?;
270 for c in &go {
271 tmux::run(&c.iter().map(String::as_str).collect::<Vec<_>>());
272 }
273 let _restore = Restoring(back);
274
275 let deadline = std::time::Instant::now() + std::time::Duration::from_millis(500);
276 loop {
277 let screen = tmux::capture(pane).unwrap_or_default();
278 if screen.contains('❯') || std::time::Instant::now() >= deadline {
279 return Some(screen);
280 }
281 std::thread::sleep(std::time::Duration::from_millis(10));
282 }
283}
284
285pub fn version_of_pid(pid: i32, versions_dir: &str) -> Option<String> {
289 let exe = std::fs::read_link(format!("/proc/{}/exe", pid)).ok()?;
290 let exe = exe.to_string_lossy();
291 let exe = exe.trim_end_matches(" (deleted)"); let prefix = format!("{}/", versions_dir);
293 exe.strip_prefix(&prefix)
294 .filter(|rest| !rest.is_empty())
295 .map(|rest| rest.split('/').next().unwrap_or(rest).to_string())
296}
297
298pub struct Planned {
300 pub pane: String,
301 pub target: String,
302 pub pid: i32,
303 pub cmd: String,
304 pub title: String,
305 pub via: String,
306}
307
308pub struct Plan {
309 pub newver: String,
310 pub launcher: String,
311 pub go: Vec<Planned>,
312 pub skipped: Vec<String>,
313 pub unresolved: bool,
316}
317
318pub struct Opts {
319 pub include_busy: bool,
320 pub only_panes: Vec<String>,
321 pub force_transcript: Option<String>,
322 pub self_pane: String,
323}
324
325pub trait Env {
328 fn capture(&self, pane: &str) -> String;
329 fn capture_zoomed(&self, _pane: &str) -> Option<String> {
336 None
337 }
338 fn hook_state(&self, pane: &str, pid: i32) -> Option<String>;
339 fn hook_mode(&self, _pane: &str, _pid: i32) -> Option<String> {
342 None
343 }
344 fn own_state(&self, _pid: i32, _screen: &str) -> Option<state::State> {
348 None
349 }
350 fn elsewhere(&self, _pane: &str, _pid: i32) -> Option<Elsewhere> {
353 None
354 }
355 fn version_of_pid(&self, pid: i32) -> Option<String>;
356 fn cwd_of(&self, pid: i32) -> Option<String>;
357 fn argv_of(&self, pid: i32) -> Vec<String>;
358 fn resolve(&self, pane: &str, cwd: &str, title: &str, pid: i32) -> Result<String, String>;
359 fn read_transcript(&self, path: &str) -> Option<String>;
360 fn now(&self) -> i64;
361}
362
363pub struct Elsewhere {
366 pub id: String,
368 pub pid: i32,
370 pub version: Option<String>,
372 pub moved: bool,
374}
375
376pub fn plan(
382 rows: &str,
383 newver: &str,
384 launcher: &str,
385 o: &Opts,
386 e: &dyn Env,
387 versions_dir: &str,
388 agents: &dyn Fn() -> String,
389) -> Plan {
390 let mut p = Plan {
391 newver: newver.to_string(),
392 launcher: launcher.to_string(),
393 go: Vec::new(),
394 skipped: Vec::new(),
395 unresolved: false,
396 };
397 let mut claimed: HashMap<String, String> = HashMap::new();
398 let mut matched: Vec<i32> = Vec::new();
401
402 for line in rows.lines() {
403 let f: Vec<&str> = line.split('\t').collect();
404 if f.len() < 7 || f[3] != "claude" {
405 continue;
406 }
407 let (id, tgt, cwd, title) = (f[0], f[1], f[2], f[6]);
408 let pid: i32 = f[4].parse().unwrap_or(0);
409
410 let Some(ver) = (pid != 0).then(|| e.version_of_pid(pid)).flatten() else {
411 p.skipped.push(format!(
412 "{} {} looks like claude but no session process was found under the pane",
413 id, tgt
414 ));
415 continue;
416 };
417 matched.push(pid);
418 if !o.only_panes.is_empty() && !o.only_panes.iter().any(|w| w == id) {
419 continue;
420 }
421
422 if let Some(away) = e.elsewhere(id, pid) {
429 matched.push(away.pid);
430 let aver = away.version.as_deref().unwrap_or("?");
431 if aver == newver {
432 continue;
433 }
434 p.skipped.push(if away.moved {
435 format!(
436 "{} {} {}, its conversation moved to background session {}: claude attach {}",
437 id, tgt, aver, away.id, away.id
438 )
439 } else {
440 format!(
441 "{} {} {}, attached to background session {}, which agent view only restarts with nothing attached",
442 id, tgt, aver, away.id
443 )
444 });
445 continue;
446 }
447
448 if ver == newver {
449 continue; }
451 if id == o.self_pane {
452 p.skipped.push(format!(
453 "{} {} {}, this pane: restart it by hand (killing it would kill taimux)",
454 id, tgt, ver
455 ));
456 continue;
457 }
458
459 let mut screen = e.capture(id);
460 if !screen.contains('❯') {
469 if let Some(bigger) = e.capture_zoomed(id) {
470 screen = bigger;
471 }
472 }
473 let hook = e.hook_state(id, pid);
474 let st = state::reading(&screen, e.own_state(pid, &screen), hook.as_deref());
475 if st.as_str() != "idle" && !o.include_busy {
476 p.skipped.push(format!(
477 "{} {} {}, {}: rerun when idle, or --include-busy",
478 id,
479 tgt,
480 ver,
481 st.as_str()
482 ));
483 continue;
484 }
485 if state::background(&screen, hook.as_deref()) && !o.include_busy {
491 p.skipped.push(format!(
492 "{} {} {}, work still in flight: rerun once it reports back, or --include-busy",
493 id, tgt, ver
494 ));
495 continue;
496 }
497
498 let ccwd = e.cwd_of(pid).unwrap_or_else(|| cwd.to_string());
499 let (transcript, via) = match &o.force_transcript {
500 Some(t) => (t.clone(), "--transcript, given".to_string()),
501 None => match e.resolve(id, &ccwd, title, pid) {
502 Ok(t) => {
503 let (path, why) = t.split_once('\t').unwrap_or((t.as_str(), ""));
505 (path.to_string(), why.to_string())
506 }
507 Err(why) => {
508 p.skipped
509 .push(format!("{} {} {}, unresolved: {}", id, tgt, ver, why));
510 p.unresolved = true;
511 continue;
512 }
513 },
514 };
515
516 if let Err(why) = screen_has_no_dialog(&screen) {
517 p.skipped
518 .push(format!("{} {} {}, not settled: {}", id, tgt, ver, why));
519 continue;
520 }
521 if !o.include_busy {
522 let settled =
523 screen_has_no_draft(&screen).and_then(|()| match e.read_transcript(&transcript) {
524 Some(text) => transcript_is_settled(&text, e.now()),
525 None => Ok(()),
526 });
527 if let Err(why) = settled {
528 p.skipped
529 .push(format!("{} {} {}, not settled: {}", id, tgt, ver, why));
530 continue;
531 }
532 }
533
534 if let Some(first) = claimed.get(&transcript) {
535 p.skipped.push(format!(
536 "{} {} {}, resolves to the same transcript as {}",
537 id, tgt, ver, first
538 ));
539 continue;
540 }
541 claimed.insert(transcript.clone(), id.to_string());
542
543 let mode = conv::current_mode(&screen, e.hook_mode(id, pid).as_deref());
546 let Some(cmd) = conv::build_cmd(&e.argv_of(pid), &transcript, &ccwd, cwd, mode.as_deref())
547 else {
548 p.skipped
549 .push(format!("{} {} {}, could not read its argv", id, tgt, ver));
550 continue;
551 };
552 p.go.push(Planned {
553 pane: id.to_string(),
554 target: tgt.to_string(),
555 pid,
556 cmd,
557 title: title.to_string(),
558 via: format!("{} -> {}, {}, {}", ver, newver, via, st.as_str()),
559 });
560 }
561
562 let mut agents_json: Option<String> = None;
567 for np in nonpane_pids(&matched, versions_dir) {
568 let Some(ver) = e.version_of_pid(np) else {
569 continue;
570 };
571 if ver == newver {
572 continue;
573 }
574 let j = agents_json.get_or_insert_with(agents);
575 p.skipped.push(format!(
576 "pid {} {}, not a tmux pane: {}",
577 np,
578 ver,
579 describe_nonpane(&e.argv_of(np), j)
580 ));
581 }
582 p
583}
584
585pub fn render(p: &Plan) -> String {
588 let mut s = format!("claude: {} installed at {}\n\n", p.newver, p.launcher);
589 if p.go.is_empty() {
590 s.push_str("nothing to restart.\n");
591 } else {
592 s.push_str(&format!("to restart ({}):\n", p.go.len()));
593 for g in &p.go {
594 s.push_str(&format!(" {:<5} {:<14} {}\n", g.pane, g.target, g.title));
595 s.push_str(&format!(" {}\n", g.via));
596 s.push_str(&format!(" {}\n", g.cmd));
597 }
598 }
599 if !p.skipped.is_empty() {
600 s.push_str(&format!("\nskipped ({}):\n", p.skipped.len()));
601 for k in &p.skipped {
602 s.push_str(&format!(" {}\n", k));
603 }
604 }
605 if p.unresolved {
606 s.push_str(
607 "\nAn unresolved pane means guessing, so it was left alone: restart it by hand\n\
608 with `claude -c` in that pane, or from its /resume picker. Each session records\n\
609 its pane at the next SessionStart, so a pane resolves cleanly once restarted.\n",
610 );
611 }
612 s
613}
614
615pub fn restart_pane(pane: &str, pid: i32, cmd: &str) -> bool {
622 use std::thread::sleep;
623 use std::time::Duration;
624
625 tmux::run(&["send-keys", "-t", pane, "C-c"]);
626 sleep(Duration::from_millis(300));
627 tmux::run(&["send-keys", "-t", pane, "C-c"]);
628
629 let mut waited = 0;
630 let mut sent_exit = false;
631 while alive(pid) {
632 sleep(Duration::from_millis(400));
633 waited += 1;
634 if waited >= 6 && !sent_exit {
635 tmux::run(&["send-keys", "-t", pane, "/exit", "Enter"]);
636 sent_exit = true;
637 }
638 if waited >= 30 {
639 return false;
640 }
641 }
642 sleep(Duration::from_millis(500));
643 tmux::run(&["send-keys", "-t", pane, "C-c"]);
644 sleep(Duration::from_millis(200));
645 tmux::run(&["send-keys", "-t", pane, cmd, "Enter"])
646}
647
648fn alive(pid: i32) -> bool {
651 std::path::Path::new(&format!("/proc/{}", pid)).exists()
652}
653
654pub fn confirm_yes(answer: &str) -> bool {
657 matches!(answer.trim(), "" | "y" | "Y" | "yes" | "YES" | "Yes")
658}
659
660pub struct Live {
662 pub versions_dir: String,
663}
664
665impl Env for Live {
666 fn capture(&self, pane: &str) -> String {
667 tmux::ask_raw(&["capture-pane", "-p", "-t", pane]).unwrap_or_default()
668 }
669 fn capture_zoomed(&self, pane: &str) -> Option<String> {
670 capture_zoomed(pane)
671 }
672 fn hook_state(&self, pane: &str, pid: i32) -> Option<String> {
673 taimux_core::hook::hook_state_of(pane, pid)
674 }
675 fn hook_mode(&self, pane: &str, pid: i32) -> Option<String> {
676 taimux_core::hook::hook_entry(pane, pid).map(|e| e.mode)
677 }
678 fn own_state(&self, pid: i32, screen: &str) -> Option<state::State> {
679 taimux_core::status::of(pid, &|| screen.to_string()).and_then(|o| o.state())
680 }
681 fn elsewhere(&self, pane: &str, pid: i32) -> Option<Elsewhere> {
682 let o =
684 taimux_core::status::of(pid, &|| self.capture(pane)).filter(|o| o.via.elsewhere())?;
685 let id = if o.job.is_empty() {
686 o.session_id.get(..8).unwrap_or(&o.session_id)
687 } else {
688 &o.job
689 };
690 Some(Elsewhere {
691 id: id.to_string(),
692 pid: o.pid,
693 version: version_of_pid(o.pid, &self.versions_dir),
694 moved: o.via == taimux_core::status::Via::MovedTo,
695 })
696 }
697 fn version_of_pid(&self, pid: i32) -> Option<String> {
698 version_of_pid(pid, &self.versions_dir)
699 }
700 fn cwd_of(&self, pid: i32) -> Option<String> {
701 std::fs::read_link(format!("/proc/{}/cwd", pid))
702 .ok()
703 .map(|p| p.to_string_lossy().into_owned())
704 .filter(|s| !s.is_empty())
705 }
706 fn argv_of(&self, pid: i32) -> Vec<String> {
707 conv::argv_of(pid)
708 }
709 fn resolve(&self, pane: &str, cwd: &str, title: &str, pid: i32) -> Result<String, String> {
710 conv::resolve(pane, cwd, title, pid)
711 .map(|r| format!("{}\t{}", r.transcript.display(), r.why))
712 }
713 fn read_transcript(&self, path: &str) -> Option<String> {
714 std::fs::read_to_string(path).ok()
715 }
716 fn now(&self) -> i64 {
717 std::time::SystemTime::now()
718 .duration_since(std::time::UNIX_EPOCH)
719 .map(|d| d.as_secs() as i64)
720 .unwrap_or(0)
721 }
722}
723
724pub fn installed(launcher: &str, versions_dir: &str) -> Result<String, String> {
727 let target = std::fs::canonicalize(launcher)
728 .map(|p| p.to_string_lossy().into_owned())
729 .unwrap_or_default();
730 let prefix = format!("{}/", versions_dir);
731 match target.strip_prefix(&prefix) {
732 Some(rest) if !rest.is_empty() => Ok(rest.split('/').next().unwrap_or(rest).to_string()),
733 _ => Err(format!(
734 "restart: {} does not point into {} (got '{}')",
735 launcher,
736 versions_dir,
737 if target.is_empty() {
738 "nothing"
739 } else {
740 &target
741 }
742 )),
743 }
744}
745
746pub fn versions_dir() -> String {
747 format!(
748 "{}/.local/share/claude/versions",
749 std::env::var("HOME").unwrap_or_default()
750 )
751}
752
753pub fn launcher() -> String {
754 format!(
755 "{}/.local/bin/claude",
756 std::env::var("HOME").unwrap_or_default()
757 )
758}
759
760#[cfg(test)]
761mod tests {
762 use super::*;
763
764 #[test]
765 fn a_timestamp_becomes_epoch_seconds() {
766 assert_eq!(parse_iso8601("2026-09-02T01:23:45.678Z"), Some(1788312225));
768 assert_eq!(parse_iso8601("1970-01-01T00:00:00Z"), Some(0));
769 assert_eq!(parse_iso8601("2024-02-29T00:00:00Z"), Some(1709164800));
771 }
772
773 #[test]
777 fn an_unparseable_timestamp_is_no_answer() {
778 assert_eq!(parse_iso8601(""), None);
779 assert_eq!(parse_iso8601("yesterday"), None);
780 assert_eq!(parse_iso8601("2026-09-02 01:23:45"), None);
781 assert_eq!(parse_iso8601("2026-13-02T01:23:45Z"), None);
782 }
783
784 #[test]
785 fn a_tool_call_still_running_is_not_settled() {
786 let t = r#"{"type":"assistant","message":{"content":[{"type":"tool_use"}]},"timestamp":"2020-01-01T00:00:00Z"}"#;
787 assert_eq!(
788 transcript_is_settled(t, 1788312225),
789 Err("a tool call is still running".into())
790 );
791 }
792
793 #[test]
795 fn recent_activity_is_not_settled_whatever_the_screen_said() {
796 let t = r#"{"type":"user","timestamp":"2026-09-02T01:23:45Z"}"#;
797 assert!(transcript_is_settled(t, 1788312225 + 10).is_err());
798 assert!(transcript_is_settled(t, 1788312225 + 100).is_ok());
799 }
800
801 #[test]
802 fn an_empty_or_odd_transcript_does_not_block() {
803 assert!(transcript_is_settled("", 0).is_ok());
804 assert!(transcript_is_settled("not json at all\n", 0).is_ok());
805 assert!(transcript_is_settled(r#"{"type":"user"}"#, 0).is_ok());
807 }
808
809 #[test]
813 fn a_dialog_on_screen_blocks_a_restart() {
814 let footer = "some output\n\nDo you want to proceed?\n";
815 assert_eq!(
816 screen_has_no_dialog(footer),
817 Err("a dialog is waiting for an answer".into())
818 );
819 let choice = "some output\n1. Yes\n2. No\n❯ 1. Yes\n";
820 assert_eq!(
821 screen_has_no_dialog(choice),
822 Err("a dialog is waiting for an answer".into())
823 );
824 assert!(screen_has_no_dialog("some output\n❯ \n").is_ok());
826 }
827
828 #[test]
831 fn a_half_pressed_ctrl_c_blocks_a_restart() {
832 let screen = "work\n\nPress Ctrl-C again to exit\n";
833 assert_eq!(
834 screen_has_no_dialog(screen),
835 Err("a Ctrl-C is already half-pressed".into())
836 );
837 }
838
839 #[test]
840 fn an_empty_prompt_box_is_no_draft() {
841 assert!(screen_has_no_draft("stuff\n❯ \n").is_ok());
842 assert!(screen_has_no_draft("stuff\n❯ \u{a0}\u{a0}\n").is_ok());
844 assert_eq!(
845 screen_has_no_draft("stuff\n❯ half a thought\n"),
846 Err("unsent text in the prompt box".into())
847 );
848 }
849
850 #[test]
853 fn a_pane_tall_enough_to_read_is_left_alone() {
854 assert!(zoom_steps("%1", false, 6, 40, "%2", "%3").is_none());
856 assert!(zoom_steps("%1", false, 40, 40, "%2", "%3").is_none());
857 assert!(zoom_steps("%1", false, 3, 3, "%2", "%3").is_none());
859 assert!(zoom_steps("%1", false, 3, 5, "%2", "%3").is_none());
860 }
861
862 #[test]
866 fn a_short_pane_is_zoomed_and_the_selection_put_back() {
867 let (go, back) = zoom_steps("%1", false, 3, 17, "%2", "%3").unwrap();
868 assert_eq!(go, vec![vec!["resize-pane", "-Z", "-t", "%1"]]);
869 assert_eq!(
870 back,
871 vec![
872 vec!["resize-pane", "-Z", "-t", "%1"],
873 vec!["select-pane", "-t", "%3"],
874 vec!["select-pane", "-t", "%2"],
875 ]
876 );
877 }
878
879 #[test]
883 fn a_window_zoomed_elsewhere_is_handed_back_zoomed() {
884 let (go, back) = zoom_steps("%1", true, 3, 17, "%2", "%3").unwrap();
885 assert_eq!(
886 go,
887 vec![
888 vec!["resize-pane", "-Z", "-t", "%1"],
889 vec!["resize-pane", "-Z", "-t", "%1"],
890 ]
891 );
892 assert_eq!(
893 back,
894 vec![
895 vec!["resize-pane", "-Z", "-t", "%1"],
896 vec!["select-pane", "-t", "%3"],
897 vec!["select-pane", "-t", "%2"],
898 vec!["resize-pane", "-Z", "-t", "%2"],
899 ]
900 );
901 }
902
903 #[test]
906 fn an_active_short_pane_has_no_selection_to_restore() {
907 let (go, back) = zoom_steps("%1", false, 3, 17, "%1", "%3").unwrap();
908 assert_eq!(go.len(), 1);
909 assert_eq!(back, vec![vec!["resize-pane", "-Z", "-t", "%1"]]);
910 }
911
912 #[test]
915 fn no_prompt_box_is_a_refusal() {
916 assert_eq!(
917 screen_has_no_draft("just some text\n"),
918 Err("no prompt box on screen".into())
919 );
920 assert!(screen_has_no_draft("").is_ok());
922 assert!(screen_has_no_draft(" \n\n").is_ok());
923 }
924
925 #[test]
926 fn a_bare_enter_confirms() {
927 assert!(confirm_yes(""));
928 assert!(confirm_yes("y"));
929 assert!(confirm_yes("YES"));
930 assert!(!confirm_yes("n"));
931 assert!(!confirm_yes("no"));
932 assert!(!confirm_yes("maybe"));
933 }
934
935 #[test]
936 fn the_launcher_must_point_into_the_versions_dir() {
937 let root = std::env::temp_dir().join(format!("jmrs{}", std::process::id()));
938 let vers = root.join("versions");
939 std::fs::create_dir_all(&vers).unwrap();
940 std::fs::write(vers.join("2.1.258"), "x").unwrap();
941 let link = root.join("claude");
942 std::os::unix::fs::symlink(vers.join("2.1.258"), &link).unwrap();
943 assert_eq!(
944 installed(&link.to_string_lossy(), &vers.to_string_lossy()),
945 Ok("2.1.258".into())
946 );
947 std::fs::write(root.join("elsewhere"), "x").unwrap();
949 std::fs::remove_file(&link).unwrap();
950 std::os::unix::fs::symlink(root.join("elsewhere"), &link).unwrap();
951 let e = installed(&link.to_string_lossy(), &vers.to_string_lossy()).expect_err("refused");
952 assert!(e.contains("elsewhere"));
953 let _ = std::fs::remove_dir_all(&root);
954 }
955}
956
957pub fn nonpane_pids(matched: &[i32], versions_dir: &str) -> Vec<i32> {
963 let mut out = Vec::new();
964 for e in std::fs::read_dir("/proc").into_iter().flatten().flatten() {
965 let Some(pid) = e.file_name().to_str().and_then(|s| s.parse::<i32>().ok()) else {
966 continue;
967 };
968 if matched.contains(&pid) {
969 continue;
970 }
971 let comm = std::fs::read_to_string(format!("/proc/{}/comm", pid)).unwrap_or_default();
974 let argv = conv::argv_of(pid);
975 let is_claude = comm.trim() == "claude"
976 || argv
977 .first()
978 .map(|a| a.starts_with(&format!("{}/", versions_dir)))
979 .unwrap_or(false);
980 if is_claude {
981 out.push(pid);
982 }
983 }
984 out.sort_unstable();
985 out
986}
987
988fn json_object_with_prefix(text: &str, key: &str, prefix: &str) -> Option<String> {
996 let needle = format!("\"{}\":\"{}", key, prefix);
997 let at = text.find(&needle).or_else(|| {
998 let spaced = format!("\"{}\": \"{}", key, prefix);
999 text.find(&spaced)
1000 })?;
1001 let mut depth = 0i32;
1003 let bytes = text.as_bytes();
1004 let mut start = None;
1005 for i in (0..at).rev() {
1006 match bytes[i] {
1007 b'}' => depth += 1,
1008 b'{' => {
1009 if depth == 0 {
1010 start = Some(i);
1011 break;
1012 }
1013 depth -= 1;
1014 }
1015 _ => {}
1016 }
1017 }
1018 let start = start?;
1019 let mut depth = 0i32;
1021 for i in start..bytes.len() {
1022 match bytes[i] {
1023 b'{' => depth += 1,
1024 b'}' => {
1025 depth -= 1;
1026 if depth == 0 {
1027 return Some(text[start..=i].to_string());
1028 }
1029 }
1030 _ => {}
1031 }
1032 }
1033 None
1034}
1035
1036pub fn describe_nonpane(argv: &[String], agents_json: &str) -> String {
1043 if argv.is_empty() {
1044 return "gone".into();
1045 }
1046 let (mut sid, mut res, mut forked) = (String::new(), String::new(), false);
1047 for i in 1..argv.len() {
1048 match argv[i].as_str() {
1049 "--fork-session" => forked = true,
1050 "--session-id" => sid = argv.get(i + 1).cloned().unwrap_or_default(),
1051 "-r" | "--resume" => res = argv.get(i + 1).cloned().unwrap_or_default(),
1052 _ => {}
1053 }
1054 }
1055 let own = base_id(if sid.is_empty() { &res } else { &sid });
1056 let parent = if forked && !res.is_empty() {
1057 base_id(&res)
1058 } else {
1059 String::new()
1060 };
1061
1062 let (mut kind, mut st, mut name) = ("?".to_string(), "?".to_string(), String::new());
1063 if !own.is_empty() {
1064 if let Some(obj) = json_object_with_prefix(agents_json, "sessionId", &own) {
1065 let f = |k: &str| taimux_core::json::field(&obj, k);
1066 let k = f("kind");
1067 if !k.is_empty() {
1068 kind = k;
1069 }
1070 let s = {
1071 let a = f("state");
1072 if a.is_empty() {
1073 f("status")
1074 } else {
1075 a
1076 }
1077 };
1078 if !s.is_empty() {
1079 st = s;
1080 }
1081 name = f("name");
1082 }
1083 }
1084 let mut out = format!("{} {}", kind, st);
1085 if forked {
1086 out.push_str(" fork");
1087 }
1088 if !name.is_empty() {
1089 out.push_str(&format!(" \"{}\"", name));
1090 }
1091 if !own.is_empty() {
1092 out.push_str(&format!(" [{}]", own.chars().take(8).collect::<String>()));
1093 }
1094 if !parent.is_empty() {
1095 out.push_str(&format!(
1096 " of [{}]",
1097 parent.chars().take(8).collect::<String>()
1098 ));
1099 }
1100 out
1101}
1102
1103fn base_id(s: &str) -> String {
1105 if s.is_empty() {
1106 return String::new();
1107 }
1108 let b = s.rsplit('/').next().unwrap_or(s);
1109 b.strip_suffix(".jsonl").unwrap_or(b).to_string()
1110}
1111
1112#[cfg(test)]
1113mod nonpane_tests {
1114 use super::*;
1115
1116 fn v(a: &[&str]) -> Vec<String> {
1117 a.iter().map(|s| s.to_string()).collect()
1118 }
1119
1120 #[test]
1121 fn a_session_id_is_read_out_of_a_path_or_taken_as_it_stands() {
1122 assert_eq!(base_id("/a/b/263946b5-9bd7.jsonl"), "263946b5-9bd7");
1123 assert_eq!(base_id("263946b5"), "263946b5");
1124 assert_eq!(base_id(""), "");
1125 }
1126
1127 #[test]
1131 fn the_right_object_comes_back_whole() {
1132 let j = r#"[{"sessionId":"aaa111","kind":"task","meta":{"a":1},"name":"first"},
1133 {"sessionId":"bbb222","kind":"agent","name":"second"}]"#;
1134 let o = json_object_with_prefix(j, "sessionId", "bbb222").expect("found");
1135 assert!(o.contains("second"));
1136 assert!(!o.contains("first"));
1137 let o = json_object_with_prefix(j, "sessionId", "aaa").expect("found by prefix");
1138 assert!(o.contains("first"));
1139 assert!(
1140 o.contains("\"meta\":{\"a\":1}"),
1141 "nested field truncated: {}",
1142 o
1143 );
1144 assert!(json_object_with_prefix(j, "sessionId", "zzz").is_none());
1145 }
1146
1147 #[test]
1148 fn a_process_with_no_argv_is_simply_gone() {
1149 assert_eq!(describe_nonpane(&[], "[]"), "gone");
1150 }
1151
1152 #[test]
1153 fn an_unnamed_session_still_says_what_it_can() {
1154 let d = describe_nonpane(&v(&["claude", "--session-id", "263946b5-9bd7"]), "[]");
1155 assert_eq!(d, "? ? [263946b5]");
1156 }
1157
1158 #[test]
1159 fn a_named_one_says_kind_state_and_name() {
1160 let j =
1161 r#"[{"sessionId":"263946b5-9bd7","kind":"task","state":"running","name":"the thing"}]"#;
1162 let d = describe_nonpane(&v(&["claude", "--session-id", "263946b5-9bd7"]), j);
1163 assert_eq!(d, "task running \"the thing\" [263946b5]");
1164 }
1165
1166 #[test]
1169 fn status_stands_in_for_state() {
1170 let j = r#"[{"sessionId":"aaa11111","kind":"agent","status":"idle"}]"#;
1171 let d = describe_nonpane(&v(&["claude", "--session-id", "aaa11111"]), j);
1172 assert_eq!(d, "agent idle [aaa11111]");
1173 }
1174
1175 #[test]
1178 fn a_fork_names_its_parent_too() {
1179 let d = describe_nonpane(
1180 &v(&[
1181 "claude",
1182 "--session-id",
1183 "child111",
1184 "--fork-session",
1185 "--resume",
1186 "/p/parent22.jsonl",
1187 ]),
1188 "[]",
1189 );
1190 assert_eq!(d, "? ? fork [child111] of [parent22]");
1191 }
1192}
1193
1194#[cfg(test)]
1195mod plan_tests {
1196 use super::*;
1197
1198 struct Fake {
1203 vers: HashMap<i32, String>,
1205 screens: HashMap<String, String>,
1207 resolved: HashMap<String, Result<String, String>>,
1209 zoomed: HashMap<String, String>,
1212 zooms: std::cell::Cell<usize>,
1215 hooks: HashMap<String, String>,
1217 modes: HashMap<String, String>,
1219 own: HashMap<i32, state::State>,
1221 away: HashMap<i32, (String, String, bool)>,
1224 transcript: String,
1225 now: i64,
1226 }
1227
1228 impl Env for Fake {
1229 fn capture(&self, pane: &str) -> String {
1230 self.screens.get(pane).cloned().unwrap_or_default()
1231 }
1232 fn capture_zoomed(&self, pane: &str) -> Option<String> {
1233 let bigger = self.zoomed.get(pane).cloned();
1234 if bigger.is_some() {
1235 self.zooms.set(self.zooms.get() + 1);
1236 }
1237 bigger
1238 }
1239 fn hook_state(&self, pane: &str, _pid: i32) -> Option<String> {
1240 self.hooks.get(pane).cloned()
1241 }
1242 fn hook_mode(&self, pane: &str, _pid: i32) -> Option<String> {
1243 self.modes.get(pane).cloned()
1244 }
1245 fn own_state(&self, pid: i32, _screen: &str) -> Option<state::State> {
1246 self.own.get(&pid).copied()
1247 }
1248 fn elsewhere(&self, _pane: &str, pid: i32) -> Option<Elsewhere> {
1249 self.away.get(&pid).map(|(id, ver, moved)| Elsewhere {
1250 id: id.clone(),
1251 pid: 1000 + pid,
1252 version: Some(ver.clone()),
1253 moved: *moved,
1254 })
1255 }
1256 fn version_of_pid(&self, pid: i32) -> Option<String> {
1257 self.vers.get(&pid).cloned()
1258 }
1259 fn cwd_of(&self, _pid: i32) -> Option<String> {
1260 Some("/w".into())
1261 }
1262 fn argv_of(&self, _pid: i32) -> Vec<String> {
1263 vec!["claude".into()]
1264 }
1265 fn resolve(&self, pane: &str, _c: &str, _t: &str, _p: i32) -> Result<String, String> {
1266 self.resolved
1267 .get(pane)
1268 .cloned()
1269 .unwrap_or_else(|| Err("no candidate".into()))
1270 }
1271 fn read_transcript(&self, _path: &str) -> Option<String> {
1272 Some(self.transcript.clone())
1273 }
1274 fn now(&self) -> i64 {
1275 self.now
1276 }
1277 }
1278
1279 fn fake() -> Fake {
1280 let mut vers = HashMap::new();
1281 vers.insert(11, "2.1.100".to_string()); vers.insert(22, "2.1.258".to_string()); let mut screens = HashMap::new();
1284 screens.insert("%1".to_string(), "some output\n❯ \n".to_string());
1286 screens.insert("%2".to_string(), "some output\n❯ \n".to_string());
1287 let mut resolved = HashMap::new();
1288 resolved.insert("%1".to_string(), Ok("/t/a.jsonl\tpane map".to_string()));
1289 Fake {
1290 vers,
1291 screens,
1292 resolved,
1293 zoomed: HashMap::new(),
1294 zooms: std::cell::Cell::new(0),
1295 hooks: HashMap::new(),
1296 modes: HashMap::new(),
1297 own: HashMap::new(),
1298 away: HashMap::new(),
1299 transcript: r#"{"type":"user","timestamp":"2020-01-01T00:00:00Z"}"#.to_string(),
1300 now: 1788312225,
1301 }
1302 }
1303
1304 fn opts() -> Opts {
1305 Opts {
1306 include_busy: false,
1307 only_panes: Vec::new(),
1308 force_transcript: None,
1309 self_pane: String::new(),
1310 }
1311 }
1312
1313 const ROWS: &str = "%1\tw:1.1\t/w\tclaude\t11\tclaude\tproj: the stale one\n\
1314 %2\tw:2.1\t/w\tclaude\t22\tclaude\tproj: the current one";
1315
1316 fn plan_of(e: &Fake, o: &Opts) -> Plan {
1317 plan(ROWS, "2.1.258", "/l/claude", o, e, "/nowhere", &|| {
1318 "[]".into()
1319 })
1320 }
1321
1322 #[test]
1323 fn a_stale_pane_is_planned_and_a_current_one_is_not() {
1324 let p = plan_of(&fake(), &opts());
1325 assert_eq!(p.go.len(), 1);
1326 assert_eq!(p.go[0].pane, "%1");
1327 assert_eq!(p.go[0].cmd, "command claude --resume /t/a.jsonl");
1328 assert_eq!(p.go[0].via, "2.1.100 -> 2.1.258, pane map, idle");
1329 assert!(p.skipped.is_empty());
1330 }
1331
1332 #[test]
1337 fn a_session_comes_back_in_the_mode_it_is_in() {
1338 let rule = "────────────────────────────────";
1339 let mut e = fake();
1340 e.screens.insert(
1341 "%1".into(),
1342 format!("some output\n{rule}\n❯ \n{rule}\n ⏵⏵ accept edits on (shift+tab to cycle)\n"),
1343 );
1344 e.modes.insert("%1".into(), "auto".into()); let p = plan_of(&e, &opts());
1346 assert_eq!(p.go.len(), 1, "{:?}", p.skipped);
1347 assert_eq!(
1348 p.go[0].cmd,
1349 "command claude --permission-mode acceptEdits --resume /t/a.jsonl"
1350 );
1351
1352 let mut e = fake();
1354 e.modes.insert("%1".into(), "plan".into());
1355 let p = plan_of(&e, &opts());
1356 assert_eq!(
1357 p.go[0].cmd,
1358 "command claude --permission-mode plan --resume /t/a.jsonl"
1359 );
1360
1361 let mut e = fake();
1363 e.modes.insert("%1".into(), "-".into());
1364 assert_eq!(
1365 plan_of(&e, &opts()).go[0].cmd,
1366 "command claude --resume /t/a.jsonl"
1367 );
1368 }
1369
1370 #[test]
1373 fn the_rendered_plan_reads_the_way_it_always_did() {
1374 let out = render(&plan_of(&fake(), &opts()));
1375 assert_eq!(
1376 out,
1377 "claude: 2.1.258 installed at /l/claude\n\n\
1378 to restart (1):\n\
1379 \x20 %1 w:1.1 proj: the stale one\n\
1380 \x20 2.1.100 -> 2.1.258, pane map, idle\n\
1381 \x20 command claude --resume /t/a.jsonl\n"
1382 );
1383 }
1384
1385 #[test]
1387 fn this_pane_is_never_restarted() {
1388 let mut o = opts();
1389 o.self_pane = "%1".into();
1390 let p = plan_of(&fake(), &o);
1391 assert!(p.go.is_empty());
1392 assert!(p.skipped[0].contains("this pane"));
1393 assert!(p.skipped[0].contains("killing it would kill taimux"));
1394 }
1395
1396 #[test]
1397 fn a_pane_that_is_not_idle_waits_for_include_busy() {
1398 let mut e = fake();
1399 e.screens
1401 .insert("%1".into(), "Twisting… (35s · ↓ 1.6k tokens)\n❯ \n".into());
1402 let p = plan_of(&e, &opts());
1403 assert!(p.go.is_empty());
1404 assert!(p.skipped[0].contains("rerun when idle, or --include-busy"));
1405
1406 let mut o = opts();
1407 o.include_busy = true;
1408 assert_eq!(plan_of(&e, &o).go.len(), 1);
1409 }
1410
1411 #[test]
1415 fn a_session_that_says_it_is_busy_is_busy() {
1416 let mut e = fake();
1417 e.hooks.insert("%1".into(), "input".into());
1418 e.own.insert(11, state::State::Run);
1419 let p = plan_of(&e, &opts());
1420 assert!(p.go.is_empty());
1421 assert!(
1422 p.skipped[0].contains("run: rerun when idle"),
1423 "{:?}",
1424 p.skipped
1425 );
1426 e.hooks.insert("%1".into(), "run".into());
1428 e.own.insert(11, state::State::Idle);
1429 assert_eq!(plan_of(&e, &opts()).go.len(), 1);
1430 }
1431
1432 #[test]
1436 fn a_pane_whose_conversation_moved_to_the_background_is_left_alone() {
1437 let mut e = fake();
1438 e.own.insert(11, state::State::Idle);
1439 e.away
1440 .insert(11, ("2447b564".into(), "2.1.100".into(), true));
1441 let mut o = opts();
1442 o.include_busy = true; let p = plan_of(&e, &o);
1444 assert!(p.go.is_empty());
1445 assert!(
1446 p.skipped[0].contains("moved to background session 2447b564: claude attach 2447b564"),
1447 "{:?}",
1448 p.skipped
1449 );
1450 }
1451
1452 #[test]
1456 fn an_attached_pane_is_judged_by_its_workers_version() {
1457 let mut e = fake();
1458 e.away
1459 .insert(22, ("880ae832".into(), "2.1.250".into(), false));
1460 let p = plan_of(&e, &opts());
1461 assert_eq!(p.go.len(), 1, "{:?}", p.skipped);
1462 assert_eq!(p.go[0].pane, "%1");
1463 assert!(
1464 p.skipped.iter().any(
1465 |s| s.starts_with("%2 w:2.1 2.1.250, attached to background session 880ae832")
1466 ),
1467 "{:?}",
1468 p.skipped
1469 );
1470
1471 let mut e = fake();
1472 e.away
1473 .insert(11, ("880ae832".into(), "2.1.258".into(), false));
1474 let p = plan_of(&e, &opts());
1475 assert!(p.go.is_empty());
1476 assert!(
1477 p.skipped.iter().all(|s| !s.starts_with("%1")),
1478 "{:?}",
1479 p.skipped
1480 );
1481 }
1482
1483 #[test]
1486 fn a_pane_with_work_in_flight_waits_for_include_busy() {
1487 let mut e = fake();
1488 e.screens.insert(
1489 "%1".into(),
1490 "✻ Cogitated for 1m 3s · done 4:55 PM · 2 shells still running\n❯ \n".into(),
1491 );
1492 let p = plan_of(&e, &opts());
1493 assert!(p.go.is_empty());
1494 assert!(
1495 p.skipped[0].contains("work still in flight"),
1496 "{:?}",
1497 p.skipped
1498 );
1499
1500 let mut e = fake();
1502 e.hooks.insert("%1".into(), "bg".into());
1503 let p = plan_of(&e, &opts());
1504 assert!(p.go.is_empty());
1505 assert!(
1506 p.skipped[0].contains("work still in flight"),
1507 "{:?}",
1508 p.skipped
1509 );
1510
1511 let mut o = opts();
1512 o.include_busy = true;
1513 assert_eq!(plan_of(&e, &o).go.len(), 1);
1514 }
1515
1516 #[test]
1519 fn a_dialog_blocks_a_restart_even_with_include_busy() {
1520 let mut e = fake();
1521 e.screens
1522 .insert("%1".into(), "output\n\nDo you want to proceed?\n".into());
1523 let mut o = opts();
1524 o.include_busy = true;
1525 let p = plan_of(&e, &o);
1526 assert!(p.go.is_empty());
1527 assert!(p.skipped[0].contains("a dialog is waiting for an answer"));
1528 }
1529
1530 #[test]
1531 fn an_unsent_draft_is_left_alone() {
1532 let mut e = fake();
1533 e.screens
1534 .insert("%1".into(), "output\n❯ half a thought\n".into());
1535 let p = plan_of(&e, &opts());
1536 assert!(p.skipped[0].contains("unsent text in the prompt box"));
1537 }
1538
1539 #[test]
1543 fn a_pane_too_short_for_its_box_is_read_zoomed() {
1544 let mut e = fake();
1545 e.screens.insert(
1546 "%1".into(),
1547 " current: 2.1.100 · latest…\n────────\n".into(),
1548 );
1549 e.zoomed.insert("%1".into(), "some output\n❯ \n".into());
1550 let p = plan_of(&e, &opts());
1551 assert_eq!(e.zooms.get(), 1);
1552 assert_eq!(p.go.len(), 1);
1553 assert_eq!(p.go[0].pane, "%1");
1554 assert!(p.skipped.is_empty());
1555 }
1556
1557 #[test]
1562 fn a_draft_hidden_by_a_short_pane_still_refuses() {
1563 let mut e = fake();
1564 e.screens
1565 .insert("%1".into(), " current: 2.1.100…\n".into());
1566 e.zoomed
1567 .insert("%1".into(), "output\n❯ half a thought\n".into());
1568 let p = plan_of(&e, &opts());
1569 assert_eq!(e.zooms.get(), 1);
1570 assert!(p.go.is_empty());
1571 assert!(p.skipped[0].contains("unsent text in the prompt box"));
1572 }
1573
1574 #[test]
1578 fn a_dialog_hidden_by_a_short_pane_is_found_by_the_zoom() {
1579 let mut e = fake();
1580 e.screens.insert("%1".into(), " Bash command\n".into());
1581 e.zoomed.insert(
1582 "%1".into(),
1583 "Do you want to proceed?\n❯ 1. Yes\n 2. No\n".into(),
1584 );
1585 let mut o = opts();
1586 o.include_busy = true;
1587 let p = plan_of(&e, &o);
1588 assert!(p.go.is_empty());
1589 assert!(p.skipped[0].contains("a dialog is waiting for an answer"));
1590 }
1591
1592 #[test]
1595 fn a_pane_that_shows_its_box_is_not_zoomed() {
1596 let e = fake();
1597 let p = plan_of(&e, &opts());
1598 assert_eq!(e.zooms.get(), 0);
1599 assert_eq!(p.go.len(), 1);
1600 }
1601
1602 #[test]
1605 fn a_recently_active_transcript_is_left_alone() {
1606 let mut e = fake();
1607 e.transcript = r#"{"type":"user","timestamp":"2026-09-02T01:23:45Z"}"#.into();
1608 e.now = 1788312225 + 10;
1609 let p = plan_of(&e, &opts());
1610 assert!(p.skipped[0].contains("active in the last 45s"));
1611 }
1612
1613 #[test]
1614 fn an_unresolved_pane_says_so_and_earns_the_paragraph() {
1615 let mut e = fake();
1616 e.resolved
1617 .insert("%1".into(), Err("3 transcripts share this title".into()));
1618 let p = plan_of(&e, &opts());
1619 assert!(p.go.is_empty());
1620 assert!(p.unresolved);
1621 assert!(p.skipped[0].contains("unresolved: 3 transcripts share this title"));
1622 assert!(render(&p).contains("restart it by hand"));
1623 }
1624
1625 #[test]
1628 fn one_transcript_is_never_resumed_into_two_panes() {
1629 let mut e = fake();
1630 e.vers.insert(22, "2.1.100".into()); e.resolved
1632 .insert("%2".into(), Ok("/t/a.jsonl\tpane map".into()));
1633 let p = plan_of(&e, &opts());
1634 assert_eq!(p.go.len(), 1);
1635 assert_eq!(p.go[0].pane, "%1");
1636 assert!(p.skipped[0].contains("resolves to the same transcript as %1"));
1637 }
1638
1639 #[test]
1640 fn only_panes_narrows_the_plan_without_changing_the_verdicts() {
1641 let mut o = opts();
1642 o.only_panes = vec!["%2".into()];
1643 let p = plan_of(&fake(), &o);
1644 assert!(p.go.is_empty());
1645 assert!(p.skipped.is_empty()); }
1647
1648 #[test]
1649 fn a_pane_with_no_session_process_is_reported_not_dropped() {
1650 let rows = "%9\tw:9.9\t/w\tclaude\t0\tclaude\tno pid here";
1651 let p = plan(rows, "2.1.258", "/l", &opts(), &fake(), "/nowhere", &|| {
1652 "[]".into()
1653 });
1654 assert!(p.go.is_empty());
1655 assert_eq!(p.skipped.len(), 1);
1656 assert!(p.skipped[0].contains("no session process was found"));
1657 }
1658
1659 #[test]
1660 fn nothing_to_restart_says_so() {
1661 let mut e = fake();
1662 e.vers.insert(11, "2.1.258".into());
1663 let out = render(&plan_of(&e, &opts()));
1664 assert!(out.contains("nothing to restart."));
1665 assert!(!out.contains("to restart ("));
1666 }
1667
1668 #[test]
1671 fn a_given_transcript_overrides_the_ladder() {
1672 let mut e = fake();
1673 e.resolved.insert("%1".into(), Err("no candidate".into()));
1674 let mut o = opts();
1675 o.force_transcript = Some("/given.jsonl".into());
1676 let p = plan_of(&e, &o);
1677 assert_eq!(p.go.len(), 1);
1678 assert!(p.go[0].via.contains("--transcript, given"));
1679 assert!(p.go[0].cmd.contains("--resume /given.jsonl"));
1680 }
1681}