fix: TUI should use cwd from Config (#808)
https://github.com/openai/codex/pull/800 made `cwd` a property of `Config`, so the TUI should use this instead of running `std::env::current_dir()`.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::SendError;
|
use std::sync::mpsc::SendError;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -34,7 +35,6 @@ pub(crate) struct ChatWidget<'a> {
|
|||||||
bottom_pane: BottomPane<'a>,
|
bottom_pane: BottomPane<'a>,
|
||||||
input_focus: InputFocus,
|
input_focus: InputFocus,
|
||||||
config: Config,
|
config: Config,
|
||||||
cwd: std::path::PathBuf,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
@@ -48,15 +48,10 @@ impl ChatWidget<'_> {
|
|||||||
config: Config,
|
config: Config,
|
||||||
app_event_tx: Sender<AppEvent>,
|
app_event_tx: Sender<AppEvent>,
|
||||||
initial_prompt: Option<String>,
|
initial_prompt: Option<String>,
|
||||||
initial_images: Vec<std::path::PathBuf>,
|
initial_images: Vec<PathBuf>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (codex_op_tx, mut codex_op_rx) = unbounded_channel::<Op>();
|
let (codex_op_tx, mut codex_op_rx) = unbounded_channel::<Op>();
|
||||||
|
|
||||||
// Determine the current working directory up‑front so we can display
|
|
||||||
// it alongside the Session information when the session is
|
|
||||||
// initialised.
|
|
||||||
let cwd = std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
|
|
||||||
|
|
||||||
let app_event_tx_clone = app_event_tx.clone();
|
let app_event_tx_clone = app_event_tx.clone();
|
||||||
// Create the Codex asynchronously so the UI loads as quickly as possible.
|
// Create the Codex asynchronously so the UI loads as quickly as possible.
|
||||||
let config_for_agent_loop = config.clone();
|
let config_for_agent_loop = config.clone();
|
||||||
@@ -105,7 +100,6 @@ impl ChatWidget<'_> {
|
|||||||
}),
|
}),
|
||||||
input_focus: InputFocus::BottomPane,
|
input_focus: InputFocus::BottomPane,
|
||||||
config,
|
config,
|
||||||
cwd: cwd.clone(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = chat_widget.submit_welcome_message();
|
let _ = chat_widget.submit_welcome_message();
|
||||||
@@ -193,7 +187,7 @@ impl ChatWidget<'_> {
|
|||||||
fn submit_user_message_with_images(
|
fn submit_user_message_with_images(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: String,
|
text: String,
|
||||||
image_paths: Vec<std::path::PathBuf>,
|
image_paths: Vec<PathBuf>,
|
||||||
) -> std::result::Result<(), SendError<AppEvent>> {
|
) -> std::result::Result<(), SendError<AppEvent>> {
|
||||||
let mut items: Vec<InputItem> = Vec::new();
|
let mut items: Vec<InputItem> = Vec::new();
|
||||||
|
|
||||||
@@ -233,7 +227,7 @@ impl ChatWidget<'_> {
|
|||||||
EventMsg::SessionConfigured { model } => {
|
EventMsg::SessionConfigured { model } => {
|
||||||
// Record session information at the top of the conversation.
|
// Record session information at the top of the conversation.
|
||||||
self.conversation_history
|
self.conversation_history
|
||||||
.add_session_info(&self.config, model, self.cwd.clone());
|
.add_session_info(&self.config, model);
|
||||||
self.request_redraw()?;
|
self.request_redraw()?;
|
||||||
}
|
}
|
||||||
EventMsg::AgentMessage { message } => {
|
EventMsg::AgentMessage { message } => {
|
||||||
|
|||||||
@@ -184,8 +184,8 @@ impl ConversationHistoryWidget {
|
|||||||
|
|
||||||
/// Note `model` could differ from `config.model` if the agent decided to
|
/// Note `model` could differ from `config.model` if the agent decided to
|
||||||
/// use a different model than the one requested by the user.
|
/// use a different model than the one requested by the user.
|
||||||
pub fn add_session_info(&mut self, config: &Config, model: String, cwd: PathBuf) {
|
pub fn add_session_info(&mut self, config: &Config, model: String) {
|
||||||
self.add_to_history(HistoryCell::new_session_info(config, model, cwd));
|
self.add_to_history(HistoryCell::new_session_info(config, model));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_active_exec_command(&mut self, call_id: String, command: Vec<String>) {
|
pub fn add_active_exec_command(&mut self, call_id: String, command: Vec<String>) {
|
||||||
|
|||||||
@@ -144,18 +144,14 @@ impl HistoryCell {
|
|||||||
HistoryCell::BackgroundEvent { lines }
|
HistoryCell::BackgroundEvent { lines }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_session_info(
|
pub(crate) fn new_session_info(config: &Config, model: String) -> Self {
|
||||||
config: &Config,
|
|
||||||
model: String,
|
|
||||||
cwd: std::path::PathBuf,
|
|
||||||
) -> Self {
|
|
||||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||||
|
|
||||||
lines.push(Line::from("codex session:".magenta().bold()));
|
lines.push(Line::from("codex session:".magenta().bold()));
|
||||||
lines.push(Line::from(vec!["↳ model: ".bold(), model.into()]));
|
lines.push(Line::from(vec!["↳ model: ".bold(), model.into()]));
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
"↳ cwd: ".bold(),
|
"↳ cwd: ".bold(),
|
||||||
cwd.display().to_string().into(),
|
config.cwd.display().to_string().into(),
|
||||||
]));
|
]));
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
"↳ approval: ".bold(),
|
"↳ approval: ".bold(),
|
||||||
|
|||||||
Reference in New Issue
Block a user