diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pane.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/pane.rs b/src/pane.rs index 9f2416ab..bd3f7ffd 100644 --- a/src/pane.rs +++ b/src/pane.rs @@ -374,6 +374,15 @@ fn foreground_shell_agent_action( ForegroundShellAgentAction::ObserveProbe } +/// Drops retained OSC evidence when changing away from an identified agent. +/// First acquisition keeps bytes that the newly identified process may have +/// emitted before the process probe recognized it. +fn clear_osc_evidence_for_agent_transition(terminal: &PaneTerminal, previous_agent: Option<Agent>) { + if previous_agent.is_some() { + terminal.clear_agent_osc_state(); + } +} + fn apply_foreground_shell_agent_action( agent_presence: &mut AgentDetectionPresence, action: ForegroundShellAgentAction, @@ -831,9 +840,10 @@ fn spawn_basic_detection_task( if agent_changed { pending_idle.clear(); last_screen_scan_detection_content_seq = None; - // A new foreground agent must not inherit OSC - // title/progress evidence from the previous process. - terminal.clear_agent_osc_state(); + // A replacement agent must not inherit OSC evidence + // from the previous process; a first acquisition keeps + // the evidence its own process already emitted. + clear_osc_evidence_for_agent_transition(&terminal, previous_agent); if let Some(agent) = agent { agent_startup_grace_until = Some(now + AGENT_STARTUP_GRACE_WINDOW); state = AgentState::Unknown; @@ -2363,9 +2373,14 @@ impl PaneRuntime { { pending_idle.clear(); last_screen_scan_detection_content_seq = None; - // A new foreground agent must not inherit OSC - // title/progress evidence from the previous process. - terminal.clear_agent_osc_state(); + // A replacement agent must not inherit OSC + // evidence from the previous process; a first + // acquisition keeps the evidence its own + // process already emitted. + clear_osc_evidence_for_agent_transition( + &terminal, + previous_agent, + ); if let Some(agent) = agent { agent_startup_grace_until = Some(now + AGENT_STARTUP_GRACE_WINDOW); @@ -3732,6 +3747,20 @@ mod tests { ); } + #[tokio::test] + async fn first_agent_acquisition_keeps_osc_evidence_replacement_clears_it() { + let runtime = PaneRuntime::test_with_screen_bytes(80, 24, b""); + runtime.test_process_pty_bytes(b"\x1b]2;startup title\x1b\\\x1b]9;4;1;\x1b\\"); + + clear_osc_evidence_for_agent_transition(&runtime.terminal, None); + assert_eq!(runtime.agent_osc_title(), "startup title"); + assert_eq!(runtime.agent_osc_progress(), "4;1;"); + + clear_osc_evidence_for_agent_transition(&runtime.terminal, Some(Agent::Claude)); + assert_eq!(runtime.agent_osc_title(), ""); + assert_eq!(runtime.agent_osc_progress(), ""); + } + #[test] fn reported_process_exit_clears_before_unknown_foreground_probe() { assert_eq!( |
