@@ -98,7 +98,8 @@ impl Pane { |
| 98 | 98 | if let Some(cmd) = startup_cmd { |
| 99 | 99 | pane.startup_cmd_state = StartupCmdState::WaitingForPrompt { |
| 100 | 100 | cmd: cmd.to_string(), |
| 101 | | - deadline: Instant::now() + Duration::from_millis(500), |
| 101 | + // Deadline is checked only AFTER DA1 response, so this is additional wait time |
| 102 | + deadline: Instant::now() + Duration::from_millis(1000), |
| 102 | 103 | }; |
| 103 | 104 | } |
| 104 | 105 | |
@@ -167,24 +168,37 @@ impl Pane { |
| 167 | 168 | /// Called when terminal receives OSC 133;A prompt marker |
| 168 | 169 | pub fn on_prompt_ready(&mut self) { |
| 169 | 170 | if let StartupCmdState::WaitingForPrompt { ref cmd, .. } = self.startup_cmd_state { |
| 171 | + // Also require DA1 to be responded to (shell has completed basic init) |
| 172 | + if !self.terminal.da1_responded() { |
| 173 | + return; |
| 174 | + } |
| 170 | 175 | let cmd_with_newline = format!("{}\n", cmd); |
| 171 | 176 | if let Err(e) = self.write_pty(cmd_with_newline.as_bytes()) { |
| 172 | 177 | tracing::error!("Failed to send startup command: {}", e); |
| 173 | 178 | } |
| 174 | 179 | self.startup_cmd_state = StartupCmdState::Sent; |
| 180 | + tracing::debug!("Sent startup command on prompt ready"); |
| 175 | 181 | } |
| 176 | 182 | } |
| 177 | 183 | |
| 178 | 184 | /// Check startup deadline and send command if timed out |
| 185 | + /// Only sends after DA1 has been responded to (shell has started initialization) |
| 179 | 186 | pub fn check_startup_deadline(&mut self) { |
| 180 | 187 | if let StartupCmdState::WaitingForPrompt { ref cmd, deadline } = self.startup_cmd_state { |
| 188 | + // Wait for DA1 response before considering the deadline |
| 189 | + // This ensures the shell has at least started initialization |
| 190 | + if !self.terminal.da1_responded() { |
| 191 | + return; |
| 192 | + } |
| 193 | + |
| 181 | 194 | if Instant::now() >= deadline { |
| 182 | | - // Fallback: send anyway after timeout |
| 195 | + // Fallback: send anyway after timeout (DA1 responded + deadline passed) |
| 183 | 196 | let cmd_with_newline = format!("{}\n", cmd); |
| 184 | 197 | if let Err(e) = self.write_pty(cmd_with_newline.as_bytes()) { |
| 185 | 198 | tracing::error!("Failed to send startup command (deadline): {}", e); |
| 186 | 199 | } |
| 187 | 200 | self.startup_cmd_state = StartupCmdState::Sent; |
| 201 | + tracing::debug!("Sent startup command after DA1 + deadline"); |
| 188 | 202 | } |
| 189 | 203 | } |
| 190 | 204 | } |