mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
tui: keep trust onboarding on config write failure
This commit is contained in:
@@ -16,15 +16,13 @@ use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::SkillsConfigWriteParams;
|
||||
use codex_app_server_protocol::SkillsConfigWriteResponse;
|
||||
use codex_config::loader::project_trust_key;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::FEATURES;
|
||||
use codex_git_utils::resolve_root_git_project_for_trust;
|
||||
use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::WrapErr;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) fn replace_config_value(key_path: impl Into<String>, value: JsonValue) -> ConfigEdit {
|
||||
@@ -170,15 +168,11 @@ pub(crate) async fn write_oss_provider(
|
||||
|
||||
pub(crate) async fn write_trusted_project(
|
||||
request_handle: AppServerRequestHandle,
|
||||
cwd: &AbsolutePathBuf,
|
||||
) -> Result<PathBuf> {
|
||||
let trust_target = resolve_root_git_project_for_trust(LOCAL_FS.as_ref(), cwd)
|
||||
.await
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|| cwd.to_path_buf());
|
||||
trust_target: &Path,
|
||||
) -> Result<()> {
|
||||
let mut project_update = serde_json::Map::new();
|
||||
project_update.insert(
|
||||
project_trust_key(trust_target.as_path()),
|
||||
project_trust_key(trust_target),
|
||||
serde_json::json!({ "trust_level": "trusted" }),
|
||||
);
|
||||
write_upsert_config_value(
|
||||
@@ -193,7 +187,7 @@ pub(crate) async fn write_trusted_project(
|
||||
trust_target.display()
|
||||
)
|
||||
})?;
|
||||
Ok(trust_target)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn write_config_value(
|
||||
|
||||
+2
-21
@@ -1421,26 +1421,7 @@ async fn run_ratatui_app(
|
||||
exit_reason: ExitReason::UserRequested,
|
||||
});
|
||||
}
|
||||
if matches!(
|
||||
onboarding_result.directory_trust_decision,
|
||||
Some(crate::onboarding::TrustDirectorySelection::Trust)
|
||||
) {
|
||||
let Some(app_server) = app_server.as_ref() else {
|
||||
unreachable!("app server should exist while onboarding is active");
|
||||
};
|
||||
if let Err(err) = crate::config_update::write_trusted_project(
|
||||
app_server.request_handle(),
|
||||
&initial_config.cwd,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
"failed to persist trusted project state through app server"
|
||||
);
|
||||
}
|
||||
}
|
||||
trust_decision_was_made = onboarding_result.directory_trust_decision.is_some();
|
||||
trust_decision_was_made = onboarding_result.trusted_directory.is_some();
|
||||
// If this onboarding run included the login step, always refresh cloud requirements and
|
||||
// rebuild config. This avoids missing newly available cloud requirements due to login
|
||||
// status detection edge cases.
|
||||
@@ -1456,7 +1437,7 @@ async fn run_ratatui_app(
|
||||
|
||||
// If the user made an explicit trust decision, or we showed the login flow, reload config
|
||||
// so current process state reflects persisted trust/auth changes.
|
||||
if onboarding_result.directory_trust_decision.is_some()
|
||||
if onboarding_result.trusted_directory.is_some()
|
||||
|| (show_login_screen && !uses_remote_workspace)
|
||||
{
|
||||
load_config_or_exit(
|
||||
|
||||
@@ -4,5 +4,4 @@ pub(crate) mod onboarding_screen;
|
||||
mod trust_directory;
|
||||
pub(crate) use auth::mark_underlined_hyperlink;
|
||||
pub(crate) use auth::mark_url_hyperlink;
|
||||
pub(crate) use trust_directory::TrustDirectorySelection;
|
||||
mod welcome;
|
||||
|
||||
@@ -47,6 +47,7 @@ use crate::tui::FrameRequester;
|
||||
use crate::tui::Tui;
|
||||
use crate::tui::TuiEvent;
|
||||
use color_eyre::eyre::Result;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
|
||||
@@ -89,7 +90,7 @@ pub(crate) struct OnboardingScreenArgs {
|
||||
}
|
||||
|
||||
pub(crate) struct OnboardingResult {
|
||||
pub directory_trust_decision: Option<TrustDirectorySelection>,
|
||||
pub trusted_directory: Option<PathBuf>,
|
||||
pub should_exit: bool,
|
||||
}
|
||||
|
||||
@@ -221,17 +222,30 @@ impl OnboardingScreen {
|
||||
.any(|step| matches!(step.get_step_state(), StepState::InProgress))
|
||||
}
|
||||
|
||||
pub fn directory_trust_decision(&self) -> Option<TrustDirectorySelection> {
|
||||
self.steps
|
||||
.iter()
|
||||
.find_map(|step| {
|
||||
if let Step::TrustDirectory(TrustDirectoryWidget { selection, .. }) = step {
|
||||
Some(*selection)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
fn trusted_directory_target(&self) -> Option<PathBuf> {
|
||||
self.steps.iter().find_map(|step| {
|
||||
if let Step::TrustDirectory(TrustDirectoryWidget {
|
||||
selection: Some(TrustDirectorySelection::Trust),
|
||||
trust_target,
|
||||
..
|
||||
}) = step
|
||||
{
|
||||
Some(trust_target.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn set_trust_directory_error(&mut self, message: String) {
|
||||
if let Some(Step::TrustDirectory(widget)) = self
|
||||
.steps
|
||||
.iter_mut()
|
||||
.find(|step| matches!(step, Step::TrustDirectory(_)))
|
||||
{
|
||||
widget.selection = None;
|
||||
widget.error = Some(message);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn should_exit(&self) -> bool {
|
||||
@@ -491,7 +505,9 @@ pub(crate) async fn run_onboarding_app(
|
||||
) -> Result<OnboardingResult> {
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
let trust_request_handle = args.app_server_request_handle.clone();
|
||||
let mut onboarding_screen = OnboardingScreen::new(tui, args).await;
|
||||
let mut trusted_directory = None;
|
||||
// One-time guard to fully clear the screen after ChatGPT login success message is shown
|
||||
let mut did_full_clear_after_success = false;
|
||||
|
||||
@@ -571,9 +587,46 @@ pub(crate) async fn run_onboarding_app(
|
||||
}
|
||||
}
|
||||
}
|
||||
if trusted_directory.is_none()
|
||||
&& let Some(trust_target) = onboarding_screen.trusted_directory_target()
|
||||
{
|
||||
match trust_request_handle.clone() {
|
||||
Some(request_handle) => {
|
||||
if let Err(err) = crate::config_update::write_trusted_project(
|
||||
request_handle,
|
||||
trust_target.as_path(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
project = %trust_target.display(),
|
||||
"failed to persist trusted project state through app server"
|
||||
);
|
||||
onboarding_screen.set_trust_directory_error(format!(
|
||||
"Failed to set trust for {}: {err}",
|
||||
trust_target.display()
|
||||
));
|
||||
let _ = tui.draw(u16::MAX, |frame| {
|
||||
frame.render_widget_ref(&onboarding_screen, frame.area());
|
||||
});
|
||||
} else {
|
||||
trusted_directory = Some(trust_target);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
onboarding_screen.set_trust_directory_error(
|
||||
"Failed to set trust: app server is unavailable".to_string(),
|
||||
);
|
||||
let _ = tui.draw(u16::MAX, |frame| {
|
||||
frame.render_widget_ref(&onboarding_screen, frame.area());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(OnboardingResult {
|
||||
directory_trust_decision: onboarding_screen.directory_trust_decision(),
|
||||
trusted_directory,
|
||||
should_exit: onboarding_screen.should_exit(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ impl StepStateProvider for TrustDirectoryWidget {
|
||||
|
||||
impl TrustDirectoryWidget {
|
||||
fn handle_trust(&mut self) {
|
||||
self.error = None;
|
||||
self.selection = Some(TrustDirectorySelection::Trust);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user