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:
Eric Traut authored and copyberry committed 2026-09-11 05:38:18 +00:00
1 parent da20788df9
commit 40b0409aa1
7 files changed
+118 -34

No files matched your search

+1 -1
View File
@@ -256,7 +256,7 @@ async fn interactive_tmux_startup_does_not_execute_workspace_helpers() -> Result
.chars() .chars()
.filter(|character| !character.is_whitespace()) .filter(|character| !character.is_whitespace())
.collect(); .collect();
if text.contains("Doyoutrustthecontentsofthisdirectory?") { if text.contains("Trustthisfolder?") {
return Ok::<_, anyhow::Error>(()); return Ok::<_, anyhow::Error>(());
} }
} }
@@ -177,6 +177,7 @@ impl OnboardingScreen {
} }
}; };
steps.push(Step::TrustDirectory(TrustDirectoryWidget { steps.push(Step::TrustDirectory(TrustDirectoryWidget {
restricted: false,
cwd, cwd,
trust_target, trust_target,
show_windows_create_sandbox_hint, show_windows_create_sandbox_hint,
@@ -650,6 +651,7 @@ async fn persist_selected_trust(
.find_map(|(index, step)| { .find_map(|(index, step)| {
if let Step::TrustDirectory(widget) = step if let Step::TrustDirectory(widget) = step
&& widget.selection == Some(TrustDirectorySelection::Trust) && widget.selection == Some(TrustDirectorySelection::Trust)
&& !widget.restricted
{ {
return Some((index, widget.trust_target.clone())); return Some((index, widget.trust_target.clone()));
} }
@@ -783,6 +785,7 @@ mod tests {
let mut onboarding_screen = OnboardingScreen { let mut onboarding_screen = OnboardingScreen {
request_frame: FrameRequester::test_dummy(), request_frame: FrameRequester::test_dummy(),
steps: vec![Step::TrustDirectory(TrustDirectoryWidget { steps: vec![Step::TrustDirectory(TrustDirectoryWidget {
restricted: false,
cwd: PathBuf::from("/workspace/project"), cwd: PathBuf::from("/workspace/project"),
trust_target: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"),
show_windows_create_sandbox_hint: false, show_windows_create_sandbox_hint: false,
@@ -841,11 +844,42 @@ mod tests {
assert!(onboarding_screen.should_exit()); 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] #[tokio::test]
async fn trust_persistence_failure_keeps_trust_step_in_progress() { async fn trust_persistence_failure_keeps_trust_step_in_progress() {
let mut onboarding_screen = OnboardingScreen { let mut onboarding_screen = OnboardingScreen {
request_frame: FrameRequester::test_dummy(), request_frame: FrameRequester::test_dummy(),
steps: vec![Step::TrustDirectory(TrustDirectoryWidget { steps: vec![Step::TrustDirectory(TrustDirectoryWidget {
restricted: false,
cwd: PathBuf::from("/workspace/project"), cwd: PathBuf::from("/workspace/project"),
trust_target: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"),
show_windows_create_sandbox_hint: false, show_windows_create_sandbox_hint: false,
@@ -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
@@ -1,15 +1,16 @@
--- ---
source: tui/src/onboarding/trust_directory.rs source: tui/src/onboarding/trust_directory.rs
assertion_line: 295
expression: terminal.backend() expression: terminal.backend()
--- ---
> You are in /workspace/project > You are in /workspace/project
Do you trust the contents of this directory? Working with untrusted Trust this folder? Codex can read, edit, and run files here, subject
contents comes with higher risk of prompt injection. Trusting the to your permission settings. Folder settings can run code
directory allows project-local config, hooks, and exec policies to automatically, even without a model request. Continue only if you
load. trust these files. Your trust decision will be saved.
› 1. Yes, continue › 1. Trust and continue
2. No, quit 2. Quit
Press enter to continue Press enter to continue; esc to quit
@@ -1,5 +1,6 @@
--- ---
source: tui/src/onboarding/trust_directory.rs source: tui/src/onboarding/trust_directory.rs
assertion_line: 314
expression: "terminal.backend().to_string().lines().map(str::trim_end).collect::<Vec<_>>().join(\"\\n\")" expression: "terminal.backend().to_string().lines().map(str::trim_end).collect::<Vec<_>>().join(\"\\n\")"
--- ---
> You are in /srv/remote/project/nested > 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 Note: You’re in a subdirectory of a Git project. Trusting will apply
to the repository root: /srv/remote/project to the repository root: /srv/remote/project
Do you trust the contents of this directory? Working with untrusted Trust this folder? Codex can read, edit, and run files here, subject
contents comes with higher risk of prompt injection. Trusting the to your permission settings. Folder settings can run code
directory allows project-local config, hooks, and exec policies to automatically, even without a model request. Continue only if you
load. trust these files. Your trust decision will be saved.
› 1. Yes, continue › 1. Trust and continue
2. No, quit 2. Quit
Press enter to continue Press enter to continue; esc to quit
@@ -1,19 +1,20 @@
--- ---
source: tui/src/onboarding/trust_directory.rs source: tui/src/onboarding/trust_directory.rs
assertion_line: 364
expression: terminal.backend() expression: terminal.backend()
--- ---
> You are in /workspace/project > You are in /workspace/project
Do you trust the contents of this directory? Working with untrusted Trust this folder? Codex can read, edit, and run files here, subject
contents comes with higher risk of prompt injection. Trusting the to your permission settings. Folder settings can run code
directory allows project-local config, hooks, and exec policies to automatically, even without a model request. Continue only if you
load. trust these files. Your trust decision will be saved.
› 1. Yes, continue › 1. Trust and continue
2. No, quit 2. Quit
Failed to set trust for /workspace/project: config/batchWrite failed Failed to set trust for /workspace/project: config/batchWrite failed
in TUI: Invalid configuration: features.fast_mode=true is not in TUI: Invalid configuration: features.fast_mode=true is not
supported; allowed set [fast_mode=false] supported; allowed set [fast_mode=false]
Press enter to continue Press enter to continue; esc to quit
+43 -12
View File
@@ -1,3 +1,5 @@
//! Folder trust disclosure and protected keyboard selection.
use std::path::PathBuf; use std::path::PathBuf;
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
@@ -22,6 +24,7 @@ use crate::selection_list::selection_option_row;
use super::onboarding_screen::StepState; use super::onboarding_screen::StepState;
pub(crate) struct TrustDirectoryWidget { pub(crate) struct TrustDirectoryWidget {
pub restricted: bool,
pub cwd: PathBuf, pub cwd: PathBuf,
pub trust_target: PathBuf, pub trust_target: PathBuf,
pub show_windows_create_sandbox_hint: bool, pub show_windows_create_sandbox_hint: bool,
@@ -48,7 +51,7 @@ impl WidgetRef for &TrustDirectoryWidget {
])); ]));
column.push(""); column.push("");
if self.cwd != self.trust_target { if !self.restricted && self.cwd != self.trust_target {
#[allow(clippy::disallowed_methods)] #[allow(clippy::disallowed_methods)]
let git_root_warning = Paragraph::new(format!( let git_root_warning = Paragraph::new(format!(
"Note: You’re in a subdirectory of a Git project. Trusting will apply to the repository root: {}", "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( column.push(
Paragraph::new( Paragraph::new(if self.restricted {
"Do you trust the contents of this directory? Working with untrusted \ "This folder is marked untrusted. Project-local config, hooks, and exec \
contents comes with higher risk of prompt injection. Trusting the \ policies stay disabled. Skills still load, and tool execution follows \
directory allows project-local config, hooks, and exec policies to load." your permission settings. Opening it will not change its trust setting."
.to_string(), } 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 }) .wrap(Wrap { trim: true })
.inset(Insets::tlbr( .inset(Insets::tlbr(
/*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0, /*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0,
@@ -80,8 +87,15 @@ impl WidgetRef for &TrustDirectoryWidget {
column.push(""); column.push("");
let options: Vec<(&str, TrustDirectorySelection)> = vec![ 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() { for (idx, (text, selection)) in options.iter().enumerate() {
@@ -110,10 +124,10 @@ impl WidgetRef for &TrustDirectoryWidget {
Line::from(vec![ Line::from(vec![
"Press ".dim(), "Press ".dim(),
keys::CONFIRM[0].into(), 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() " to continue and create a sandbox...".dim()
} else { } else {
" to continue".dim() " to continue; esc to quit".dim()
}, },
]) ])
.inset(Insets::tlbr( .inset(Insets::tlbr(
@@ -195,6 +209,7 @@ mod tests {
fn widget(error: Option<String>) -> TrustDirectoryWidget { fn widget(error: Option<String>) -> TrustDirectoryWidget {
TrustDirectoryWidget { TrustDirectoryWidget {
restricted: false,
cwd: PathBuf::from("/workspace/project"), cwd: PathBuf::from("/workspace/project"),
trust_target: PathBuf::from("/workspace/project"), trust_target: PathBuf::from("/workspace/project"),
show_windows_create_sandbox_hint: false, show_windows_create_sandbox_hint: false,
@@ -208,6 +223,7 @@ mod tests {
#[test] #[test]
fn release_event_does_not_change_selection() { fn release_event_does_not_change_selection() {
let mut widget = TrustDirectoryWidget { let mut widget = TrustDirectoryWidget {
restricted: false,
cwd: PathBuf::from("."), cwd: PathBuf::from("."),
trust_target: PathBuf::from("."), trust_target: PathBuf::from("."),
show_windows_create_sandbox_hint: false, show_windows_create_sandbox_hint: false,
@@ -268,6 +284,7 @@ mod tests {
#[test] #[test]
fn renders_snapshot_for_remote_git_subdirectory() { fn renders_snapshot_for_remote_git_subdirectory() {
let widget = TrustDirectoryWidget { let widget = TrustDirectoryWidget {
restricted: false,
cwd: PathBuf::from("/srv/remote/project/nested"), cwd: PathBuf::from("/srv/remote/project/nested"),
trust_target: PathBuf::from("/srv/remote/project"), trust_target: PathBuf::from("/srv/remote/project"),
..widget(/*error*/ None) ..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] #[test]
fn renders_snapshot_for_trust_error() { fn renders_snapshot_for_trust_error() {
let widget = widget(Some( let widget = widget(Some(
@@ -298,7 +329,7 @@ mod tests {
)); ));
let mut terminal = let mut terminal =
Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 18)).expect("terminal"); Terminal::new(VT100Backend::new(/*width*/ 70, /*height*/ 22)).expect("terminal");
terminal terminal
.draw(|f| (&widget).render_ref(f.area(), f.buffer_mut())) .draw(|f| (&widget).render_ref(f.area(), f.buffer_mut()))
.expect("draw"); .expect("draw");