|
1 | 1 | //! GPUI 终端对 Runtime API 暴露的读取、输入与任务状态边界。 |
2 | 2 |
|
| 3 | +mod codex_checkpoint; |
| 4 | + |
3 | 5 | use gpui::{Context, EventEmitter as _, SharedString, Window, px}; |
4 | 6 | use nebula_terminal::grid::Dimensions as _; |
5 | 7 | use nebula_terminal::index::{Column, Line, Point as TermPoint}; |
@@ -898,101 +900,6 @@ impl TerminalView { |
898 | 900 | crate::ai_agents::AgentKind::parse(&identity.source)?.fork_command(&identity.session_id) |
899 | 901 | } |
900 | 902 |
|
901 | | - pub(crate) fn prepare_ai_session_save(&mut self, cx: &mut Context<Self>) { |
902 | | - // A refresh may fail or time out. Keep the last confirmed native ID. |
903 | | - self.last_ai_session_probe = None; |
904 | | - self.probe_missing_codex_session(cx); |
905 | | - } |
906 | | - |
907 | | - pub(crate) fn ai_session_save_pending(&self) -> bool { |
908 | | - // A failed refresh cannot erase an already durable identity. Pi/Codex |
909 | | - // without any native target must finish identifying before safe exit. |
910 | | - self.ai_session_probe_pending |
911 | | - || self.session_agent().is_some_and(|agent| { |
912 | | - matches!(agent.source.as_str(), "pi" | "codex") |
913 | | - && agent.session_id.as_deref().is_none_or(str::is_empty) |
914 | | - }) |
915 | | - } |
916 | | - |
917 | | - /// Read the active conversation metadata when its hook has not reported an ID. |
918 | | - /// File and process operations run on the background executor. Only results |
919 | | - /// for the same foreground command and unchanged identity are applied. |
920 | | - pub(super) fn probe_missing_codex_session(&mut self, cx: &mut Context<Self>) { |
921 | | - if self.exited.is_some() |
922 | | - || self.ai_session_probe_pending |
923 | | - || self.ssh_destination.is_some() |
924 | | - || !self |
925 | | - .running_program |
926 | | - .as_deref() |
927 | | - .and_then(crate::ai_agents::AgentKind::parse) |
928 | | - .is_some_and(|agent| agent == crate::ai_agents::AgentKind::Codex) |
929 | | - { |
930 | | - return; |
931 | | - } |
932 | | - if self.last_ai_session_probe.is_some_and(|at| { |
933 | | - at.elapsed() |
934 | | - < std::time::Duration::from_secs(if self.ai_session.is_some() { 10 } else { 2 }) |
935 | | - }) { |
936 | | - return; |
937 | | - } |
938 | | - let Some(exec_context) = self.exec_context.clone() else { return }; |
939 | | - let epoch = self.ai_session_probe_epoch; |
940 | | - let pane_id = self.pane_id; |
941 | | - let shell_pid = self.session.as_ref().map(|session| session.shell_pid); |
942 | | - let previous_target = self.session_agent(); |
943 | | - self.ai_session_probe_pending = true; |
944 | | - self.last_ai_session_probe = Some(std::time::Instant::now()); |
945 | | - let work = cx.background_executor().spawn(async move { |
946 | | - crate::platform::ai_session_identity::probe_codex_session( |
947 | | - pane_id, |
948 | | - Some(&exec_context), |
949 | | - shell_pid, |
950 | | - ) |
951 | | - }); |
952 | | - cx.spawn(async move |this, cx| { |
953 | | - let session_id = work.await; |
954 | | - let _ = this.update(cx, |view, cx| { |
955 | | - if view.ai_session_probe_epoch == epoch { |
956 | | - view.ai_session_probe_pending = false; |
957 | | - } |
958 | | - if !probe_result_is_current( |
959 | | - view.ai_session_probe_epoch, |
960 | | - epoch, |
961 | | - view.session_agent() != previous_target, |
962 | | - view.running_program.as_deref(), |
963 | | - ) { |
964 | | - return; |
965 | | - } |
966 | | - if let Some(session) = session_id { |
967 | | - log::debug!("agent session identity from active rollout: pane={pane_id}"); |
968 | | - let target = crate::session::AgentSession { |
969 | | - source: "codex".to_owned(), |
970 | | - session_id: Some(session.session_id.clone()), |
971 | | - session_file: Some(session.session_file), |
972 | | - }; |
973 | | - let previous = view.recovery.target.clone(); |
974 | | - if !view.recovery.confirm(target) { |
975 | | - return; |
976 | | - } |
977 | | - if previous != view.recovery.target { |
978 | | - cx.emit(TerminalViewEvent::SessionIdentityChanged); |
979 | | - } |
980 | | - view.ai_session = Some(crate::display::AiSessionIdentity { |
981 | | - source: "codex".to_owned(), |
982 | | - session_id: session.session_id, |
983 | | - }); |
984 | | - if let Some(cwd) = session.cwd { |
985 | | - view.process_event(nebula_terminal::event::Event::CwdReport(cwd), cx); |
986 | | - } |
987 | | - view.ai_session_from_probe = true; |
988 | | - cx.emit(TerminalViewEvent::TitleChanged); |
989 | | - cx.notify(); |
990 | | - } |
991 | | - }); |
992 | | - }) |
993 | | - .detach(); |
994 | | - } |
995 | | - |
996 | 903 | pub(super) fn sync_native_prompt(&mut self) { |
997 | 904 | if !self.suggest.suggest_env.is_this_machine() { |
998 | 905 | return; |
|
0 commit comments