mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Clarify folder trust prompts and add restricted widget support (#44732)
## What changed - Explain that folder settings can run code automatically and that the trust decision is saved. Label the actions “Trust and continue” and “Quit”, and show the Escape shortcut. - Add a restricted state to `TrustDirectoryWidget` with an “Open restricted” action and a disclosure of which project features remain disabled. Skip trust persistence for this state. Onboarding still initializes the widget with `restricted: false`. ## Testing Add a restricted-folder rendering snapshot and a test that accepting or cancelling the restricted widget does not persist trust. Update existing trust snapshots and the interactive startup safety test for the revised prompt. GitOrigin-RevId: d913f5624ac7c24ff1a16c19b5889573ab2752e6
This commit is contained in:
1 parent
da20788df9
commit
40b0409aa1
7 files changed
+118
-34
No files matched your search
@@ -177,6 +177,7 @@ impl OnboardingScreen {
|
||||
}
|
||||
};
|
||||
steps.push(Step::TrustDirectory(TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd,
|
||||
trust_target,
|
||||
show_windows_create_sandbox_hint,
|
||||
@@ -650,6 +651,7 @@ async fn persist_selected_trust(
|
||||
.find_map(|(index, step)| {
|
||||
if let Step::TrustDirectory(widget) = step
|
||||
&& widget.selection == Some(TrustDirectorySelection::Trust)
|
||||
&& !widget.restricted
|
||||
{
|
||||
return Some((index, widget.trust_target.clone()));
|
||||
}
|
||||
@@ -783,6 +785,7 @@ mod tests {
|
||||
let mut onboarding_screen = OnboardingScreen {
|
||||
request_frame: FrameRequester::test_dummy(),
|
||||
steps: vec![Step::TrustDirectory(TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
trust_target: PathBuf::from("/workspace/project"),
|
||||
show_windows_create_sandbox_hint: false,
|
||||
@@ -841,11 +844,42 @@ mod tests {
|
||||
assert!(onboarding_screen.should_exit());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn restricted_acceptance_and_cancellation_do_not_persist_trust() {
|
||||
for key in [KeyCode::Enter, KeyCode::Esc] {
|
||||
let mut screen = OnboardingScreen {
|
||||
request_frame: FrameRequester::test_dummy(),
|
||||
steps: vec![Step::TrustDirectory(TrustDirectoryWidget {
|
||||
restricted: true,
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
trust_target: PathBuf::from("/workspace/project"),
|
||||
show_windows_create_sandbox_hint: false,
|
||||
should_quit: false,
|
||||
selection: None,
|
||||
highlighted: TrustDirectorySelection::Trust,
|
||||
error: None,
|
||||
})],
|
||||
remote_trust_key: Some("/workspace/project".to_string()),
|
||||
is_done: false,
|
||||
should_exit: false,
|
||||
};
|
||||
screen.handle_key_event(key.into());
|
||||
assert!(!persist_selected_trust(&mut screen, /*request_handle*/ None).await);
|
||||
assert!(screen.is_done());
|
||||
assert_eq!(screen.should_exit(), key == KeyCode::Esc);
|
||||
let Step::TrustDirectory(widget) = &screen.steps[0] else {
|
||||
panic!("trust step")
|
||||
};
|
||||
assert_eq!(widget.error, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn trust_persistence_failure_keeps_trust_step_in_progress() {
|
||||
let mut onboarding_screen = OnboardingScreen {
|
||||
request_frame: FrameRequester::test_dummy(),
|
||||
steps: vec![Step::TrustDirectory(TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
trust_target: PathBuf::from("/workspace/project"),
|
||||
show_windows_create_sandbox_hint: false,
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/onboarding/trust_directory.rs
|
||||
assertion_line: 335
|
||||
expression: terminal.backend()
|
||||
---
|
||||
> You are in /workspace/project
|
||||
|
||||
This folder is marked untrusted. Project-local config, hooks, and
|
||||
exec policies stay disabled. Skills still load, and tool execution
|
||||
follows your permission settings. Opening it will not change its
|
||||
trust setting.
|
||||
|
||||
› 1. Open restricted
|
||||
2. Quit
|
||||
|
||||
Press enter to continue; esc to quit
|
||||
+8
-7
@@ -1,15 +1,16 @@
|
||||
---
|
||||
source: tui/src/onboarding/trust_directory.rs
|
||||
assertion_line: 295
|
||||
expression: terminal.backend()
|
||||
---
|
||||
> You are in /workspace/project
|
||||
|
||||
Do you trust the contents of this directory? Working with untrusted
|
||||
contents comes with higher risk of prompt injection. Trusting the
|
||||
directory allows project-local config, hooks, and exec policies to
|
||||
load.
|
||||
Trust this folder? Codex can read, edit, and run files here, subject
|
||||
to your permission settings. Folder settings can run code
|
||||
automatically, even without a model request. Continue only if you
|
||||
trust these files. Your trust decision will be saved.
|
||||
|
||||
› 1. Yes, continue
|
||||
2. No, quit
|
||||
› 1. Trust and continue
|
||||
2. Quit
|
||||
|
||||
Press enter to continue
|
||||
Press enter to continue; esc to quit
|
||||
+8
-7
@@ -1,5 +1,6 @@
|
||||
---
|
||||
source: tui/src/onboarding/trust_directory.rs
|
||||
assertion_line: 314
|
||||
expression: "terminal.backend().to_string().lines().map(str::trim_end).collect::<Vec<_>>().join(\"\\n\")"
|
||||
---
|
||||
> You are in /srv/remote/project/nested
|
||||
@@ -7,12 +8,12 @@ expression: "terminal.backend().to_string().lines().map(str::trim_end).collect::
|
||||
Note: You’re in a subdirectory of a Git project. Trusting will apply
|
||||
to the repository root: /srv/remote/project
|
||||
|
||||
Do you trust the contents of this directory? Working with untrusted
|
||||
contents comes with higher risk of prompt injection. Trusting the
|
||||
directory allows project-local config, hooks, and exec policies to
|
||||
load.
|
||||
Trust this folder? Codex can read, edit, and run files here, subject
|
||||
to your permission settings. Folder settings can run code
|
||||
automatically, even without a model request. Continue only if you
|
||||
trust these files. Your trust decision will be saved.
|
||||
|
||||
› 1. Yes, continue
|
||||
2. No, quit
|
||||
› 1. Trust and continue
|
||||
2. Quit
|
||||
|
||||
Press enter to continue
|
||||
Press enter to continue; esc to quit
|
||||
+8
-7
@@ -1,19 +1,20 @@
|
||||
---
|
||||
source: tui/src/onboarding/trust_directory.rs
|
||||
assertion_line: 364
|
||||
expression: terminal.backend()
|
||||
---
|
||||
> You are in /workspace/project
|
||||
|
||||
Do you trust the contents of this directory? Working with untrusted
|
||||
contents comes with higher risk of prompt injection. Trusting the
|
||||
directory allows project-local config, hooks, and exec policies to
|
||||
load.
|
||||
Trust this folder? Codex can read, edit, and run files here, subject
|
||||
to your permission settings. Folder settings can run code
|
||||
automatically, even without a model request. Continue only if you
|
||||
trust these files. Your trust decision will be saved.
|
||||
|
||||
› 1. Yes, continue
|
||||
2. No, quit
|
||||
› 1. Trust and continue
|
||||
2. Quit
|
||||
|
||||
Failed to set trust for /workspace/project: config/batchWrite failed
|
||||
in TUI: Invalid configuration: features.fast_mode=true is not
|
||||
supported; allowed set [fast_mode=false]
|
||||
|
||||
Press enter to continue
|
||||
Press enter to continue; esc to quit
|
||||
@@ -1,3 +1,5 @@
|
||||
//! Folder trust disclosure and protected keyboard selection.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crossterm::event::KeyEvent;
|
||||
@@ -22,6 +24,7 @@ use crate::selection_list::selection_option_row;
|
||||
|
||||
use super::onboarding_screen::StepState;
|
||||
pub(crate) struct TrustDirectoryWidget {
|
||||
pub restricted: bool,
|
||||
pub cwd: PathBuf,
|
||||
pub trust_target: PathBuf,
|
||||
pub show_windows_create_sandbox_hint: bool,
|
||||
@@ -48,7 +51,7 @@ impl WidgetRef for &TrustDirectoryWidget {
|
||||
]));
|
||||
column.push("");
|
||||
|
||||
if self.cwd != self.trust_target {
|
||||
if !self.restricted && self.cwd != self.trust_target {
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
let git_root_warning = Paragraph::new(format!(
|
||||
"Note: You’re in a subdirectory of a Git project. Trusting will apply to the repository root: {}",
|
||||
@@ -66,12 +69,16 @@ impl WidgetRef for &TrustDirectoryWidget {
|
||||
}
|
||||
|
||||
column.push(
|
||||
Paragraph::new(
|
||||
"Do you trust the contents of this directory? Working with untrusted \
|
||||
contents comes with higher risk of prompt injection. Trusting the \
|
||||
directory allows project-local config, hooks, and exec policies to load."
|
||||
.to_string(),
|
||||
)
|
||||
Paragraph::new(if self.restricted {
|
||||
"This folder is marked untrusted. Project-local config, hooks, and exec \
|
||||
policies stay disabled. Skills still load, and tool execution follows \
|
||||
your permission settings. Opening it will not change its trust setting."
|
||||
} else {
|
||||
"Trust this folder? Codex can read, edit, and run files here, subject to \
|
||||
your permission settings. Folder settings can run code automatically, \
|
||||
even without a model request. Continue only if you trust these files. \
|
||||
Your trust decision will be saved."
|
||||
})
|
||||
.wrap(Wrap { trim: true })
|
||||
.inset(Insets::tlbr(
|
||||
/*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0,
|
||||
@@ -80,8 +87,15 @@ impl WidgetRef for &TrustDirectoryWidget {
|
||||
column.push("");
|
||||
|
||||
let options: Vec<(&str, TrustDirectorySelection)> = vec![
|
||||
("Yes, continue", TrustDirectorySelection::Trust),
|
||||
("No, quit", TrustDirectorySelection::Quit),
|
||||
(
|
||||
if self.restricted {
|
||||
"Open restricted"
|
||||
} else {
|
||||
"Trust and continue"
|
||||
},
|
||||
TrustDirectorySelection::Trust,
|
||||
),
|
||||
("Quit", TrustDirectorySelection::Quit),
|
||||
];
|
||||
|
||||
for (idx, (text, selection)) in options.iter().enumerate() {
|
||||
@@ -110,10 +124,10 @@ impl WidgetRef for &TrustDirectoryWidget {
|
||||
Line::from(vec![
|
||||
"Press ".dim(),
|
||||
keys::CONFIRM[0].into(),
|
||||
if self.show_windows_create_sandbox_hint {
|
||||
if self.show_windows_create_sandbox_hint && !self.restricted {
|
||||
" to continue and create a sandbox...".dim()
|
||||
} else {
|
||||
" to continue".dim()
|
||||
" to continue; esc to quit".dim()
|
||||
},
|
||||
])
|
||||
.inset(Insets::tlbr(
|
||||
@@ -195,6 +209,7 @@ mod tests {
|
||||
|
||||
fn widget(error: Option<String>) -> TrustDirectoryWidget {
|
||||
TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
trust_target: PathBuf::from("/workspace/project"),
|
||||
show_windows_create_sandbox_hint: false,
|
||||
@@ -208,6 +223,7 @@ mod tests {
|
||||
#[test]
|
||||
fn release_event_does_not_change_selection() {
|
||||
let mut widget = TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd: PathBuf::from("."),
|
||||
trust_target: PathBuf::from("."),
|
||||
show_windows_create_sandbox_hint: false,
|
||||
@@ -268,6 +284,7 @@ mod tests {
|
||||
#[test]
|
||||
fn renders_snapshot_for_remote_git_subdirectory() {
|
||||
let widget = TrustDirectoryWidget {
|
||||
restricted: false,
|
||||
cwd: PathBuf::from("/srv/remote/project/nested"),
|
||||
trust_target: PathBuf::from("/srv/remote/project"),
|
||||
..widget(/*error*/ None)
|
||||
@@ -290,6 +307,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renders_restricted_folder() {
|
||||
let widget = TrustDirectoryWidget {
|
||||
restricted: true,
|
||||
..widget(/*error*/ None)
|
||||
};
|
||||
let mut terminal =
|
||||
Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 18)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| (&widget).render_ref(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renders_snapshot_for_trust_error() {
|
||||
let widget = widget(Some(
|
||||
@@ -298,7 +329,7 @@ mod tests {
|
||||
));
|
||||
|
||||
let mut terminal =
|
||||
Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 18)).expect("terminal");
|
||||
Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 22)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| (&widget).render_ref(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
|
||||
Reference in new issue
Block a user