mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Scope resume --approve-for-me to the initial conversation (#63589)
## Why An already-loaded conversation can ignore permission overrides sent with a resume request. Applying the preset to the TUI's launch configuration can also carry it into later conversations. ## What changed Resolve the preset using the selected conversation's workspace and managed requirements. Apply it only to the initial resume, so `/new` and later resumes use the regular launch configuration. If an already-loaded conversation needs a settings update, read back its approval and sandbox settings before submitting the initial prompt. Stop the resume when the server cannot confirm the requested settings or when workspace or managed restrictions cannot be verified. ## Testing Regression tests cover CLI flag precedence, updating an already-loaded conversation, rejecting unverifiable restrictions, and keeping the preset out of new and subsequently resumed conversations. GitOrigin-RevId: 6a09097dfc64fdeb890c03cd3e56bb404e5199c8
This commit is contained in:
@@ -279,6 +279,7 @@ impl App {
|
||||
initial_prompt: Option<String>,
|
||||
initial_images: Vec<PathBuf>,
|
||||
session_selection: SessionSelection,
|
||||
initial_resume_config: Option<Box<Config>>,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
is_first_run: bool,
|
||||
should_prompt_windows_sandbox_nux_at_startup: bool,
|
||||
@@ -638,6 +639,7 @@ impl App {
|
||||
let mut read_only_thread = false;
|
||||
let mut provider_error = None;
|
||||
let mut history_notice = None;
|
||||
let confirm_preset = initial_resume_config.is_some();
|
||||
let (mut chat_widget, initial_started_thread) = match session_selection {
|
||||
SessionSelection::StartFresh
|
||||
| SessionSelection::Exit
|
||||
@@ -732,26 +734,42 @@ impl App {
|
||||
&config,
|
||||
&harness_overrides,
|
||||
);
|
||||
let permissions = if confirm_preset {
|
||||
crate::resume_permissions::ResumePermissions::PRESET
|
||||
} else {
|
||||
crate::resume_permissions::ResumePermissions::from_overrides(
|
||||
&config,
|
||||
&harness_overrides,
|
||||
)
|
||||
};
|
||||
// Keep post-bootstrap launch choices (e.g. --search) for the initial resume.
|
||||
let scoped = initial_resume_config.map(|preset| {
|
||||
let mut scoped = Box::new(config.clone());
|
||||
scoped.permissions = preset.permissions;
|
||||
scoped.approvals_reviewer = preset.approvals_reviewer;
|
||||
scoped.workspace_roots = preset.workspace_roots;
|
||||
scoped
|
||||
});
|
||||
let resume_config = scoped.as_deref().unwrap_or(&config);
|
||||
let resumed = match startup_draft
|
||||
.run_until(
|
||||
tui,
|
||||
app_server.resume_thread_with_permission_overrides(
|
||||
&local_settings,
|
||||
config.clone(),
|
||||
resume_config.clone(),
|
||||
target_session.thread_id,
|
||||
model_settings,
|
||||
crate::resume_permissions::ResumePermissions::from_overrides(
|
||||
&config,
|
||||
&harness_overrides,
|
||||
),
|
||||
permissions,
|
||||
),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Ok(resumed)) => Ok(resumed),
|
||||
Ok(Err(err))
|
||||
if crate::app_server_session::is_active_writer_error(&err)
|
||||
|| crate::app_server_session::model_provider_error(&err).is_some() =>
|
||||
if !permissions.confirm_preset
|
||||
&& (crate::app_server_session::is_active_writer_error(&err)
|
||||
|| crate::app_server_session::model_provider_error(&err)
|
||||
.is_some()) =>
|
||||
{
|
||||
provider_error = crate::app_server_session::model_provider_error(&err);
|
||||
read_only_thread = true;
|
||||
@@ -795,17 +813,11 @@ impl App {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let action = SessionStartAction::Resume(
|
||||
model_settings,
|
||||
crate::resume_permissions::ResumePermissions::from_overrides(
|
||||
&config,
|
||||
&harness_overrides,
|
||||
),
|
||||
);
|
||||
let action = SessionStartAction::Resume(model_settings, permissions);
|
||||
let resumed = complete_session_start(
|
||||
&mut app_server,
|
||||
SessionStartConfig {
|
||||
config: &config,
|
||||
config: resume_config,
|
||||
local_settings: &local_settings,
|
||||
},
|
||||
&target_session,
|
||||
@@ -1196,7 +1208,11 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
// Prewarm WSL interop off the UI thread, without accessing clipboard contents.
|
||||
let _ = tui.clipboard.warm_text_reader(tui.frame_requester());
|
||||
}
|
||||
app.remember_launch_permissions();
|
||||
// The confirmed server settings own the first turn. Replaying a different
|
||||
// launch profile here could undo the preset. /new reloads the launch flags.
|
||||
if !confirm_preset {
|
||||
app.remember_launch_permissions();
|
||||
}
|
||||
if !tui.is_terminal_focused() {
|
||||
app.recap.note_focus_lost(Instant::now());
|
||||
}
|
||||
|
||||
@@ -2422,6 +2422,141 @@ async fn make_history_test_app() -> Result<(Box<App>, tempfile::TempDir)> {
|
||||
Ok((app, codex_home))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn approve_for_me_updates_only_the_initially_resumed_thread() -> Result<()> {
|
||||
use crate::resume_permissions::ResumePermissions;
|
||||
|
||||
let (mut app, _home) = make_history_test_app().await?;
|
||||
let home = app.config.codex_home.clone();
|
||||
let cwd = app.config.cwd.clone();
|
||||
let requirements = home.join("requirements.toml");
|
||||
let loader = LoaderOverrides {
|
||||
system_requirements_path: Some(requirements.to_path_buf()),
|
||||
..LoaderOverrides::without_managed_config_for_tests()
|
||||
};
|
||||
let extra = home.join("extra");
|
||||
std::fs::create_dir_all(extra.join(".git"))?;
|
||||
app_test_support::MockResponsesConfig::new("http://127.0.0.1:9")
|
||||
.with_root_config("project_doc_max_bytes = 0")
|
||||
.with_extra_config(&format!(
|
||||
"[windows]\nsandbox = 'elevated'\n[sandbox_workspace_write]\nwritable_roots = ['{}']",
|
||||
extra.display()
|
||||
))
|
||||
.write(&home)?;
|
||||
app.config = app.rebuild_config_for_cwd(cwd.to_path_buf()).await?;
|
||||
let mut server = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
||||
let first = create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "first")?;
|
||||
let local = app.local_settings.clone();
|
||||
let model = app.resume_model_settings();
|
||||
let loaded = server
|
||||
.resume_thread(&local, app.config.clone(), first, model)
|
||||
.await?;
|
||||
let permissions = |s: &ThreadSessionState| {
|
||||
(
|
||||
s.approval_policy,
|
||||
s.approvals_reviewer,
|
||||
s.permission_profile
|
||||
.legacy_sandbox_policy_label(cwd.as_path()),
|
||||
)
|
||||
};
|
||||
let defaults = permissions(&loaded.session);
|
||||
|
||||
let mut preset = codex_utils_cli::CliConfigOverrides::default();
|
||||
codex_utils_cli::SharedCliOptions {
|
||||
auto_review: true,
|
||||
..Default::default()
|
||||
}
|
||||
.take_auto_review_config_overrides(&mut preset);
|
||||
let builder = crate::legacy_core::config::ConfigBuilder::default()
|
||||
.codex_home(home.to_path_buf())
|
||||
.fallback_cwd(Some(cwd.to_path_buf()))
|
||||
.loader_overrides(loader.clone())
|
||||
.cli_overrides(preset.parse_overrides().unwrap());
|
||||
let overrides = ResumePermissions::PRESET;
|
||||
let resume = async |server: &mut AppServerSession, config| {
|
||||
server
|
||||
.resume_thread_with_permission_overrides(&local, config, first, model, overrides)
|
||||
.await
|
||||
};
|
||||
|
||||
// Loaded threads need a settings update, not just resume overrides.
|
||||
let scoped = builder.clone().build().await?;
|
||||
let other_workspace = builder
|
||||
.clone()
|
||||
.harness_overrides(crate::legacy_core::config::ConfigOverrides {
|
||||
default_permissions: Some(":workspace".into()),
|
||||
additional_writable_roots: vec![extra.to_path_buf(), home.to_path_buf()],
|
||||
..Default::default()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
assert!(resume(&mut server, other_workspace).await.is_err());
|
||||
server.thread_settings_update_supported = false;
|
||||
assert!(resume(&mut server, scoped.clone()).await.is_err());
|
||||
server.thread_settings_update_supported = true;
|
||||
let resumed = resume(&mut server, scoped).await?;
|
||||
assert_eq!(
|
||||
permissions(&resumed.session),
|
||||
(
|
||||
AskForApproval::OnRequest,
|
||||
ApprovalsReviewer::AutoReview,
|
||||
"workspace-write"
|
||||
)
|
||||
);
|
||||
app.enqueue_primary_thread_session(resumed.session, resumed.turns)
|
||||
.await?;
|
||||
|
||||
// Neither restriction is visible in the loaded thread's sandbox summary.
|
||||
for rule in [
|
||||
"[permissions.network]\ndenied_domains = ['blocked.test']",
|
||||
"[permissions.filesystem]\ndeny_read = ['private']",
|
||||
] {
|
||||
std::fs::write(&requirements, rule)?;
|
||||
let restricted = builder.clone().build().await?;
|
||||
assert!(resume(&mut server, restricted).await.is_err(), "{rule}");
|
||||
}
|
||||
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.start_fresh_session(
|
||||
&mut tui,
|
||||
&mut server,
|
||||
FreshSessionStart::PreserveCurrentView(None),
|
||||
/*initial_user_message*/ None,
|
||||
/*new_thread_name*/ None,
|
||||
)
|
||||
.await;
|
||||
let fresh = app.primary_session_configured.as_ref().unwrap();
|
||||
assert_eq!(permissions(fresh), defaults);
|
||||
let other = create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "other")?;
|
||||
let other = server
|
||||
.resume_thread(&local, app.config.clone(), other, model)
|
||||
.await?;
|
||||
assert_eq!(permissions(&other.session), defaults);
|
||||
server.shutdown().await?;
|
||||
|
||||
// A cold load applies the read denial. Inspect the live policy, not the wire summary.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let mut server = Box::pin(crate::start_app_server_for_picker(
|
||||
crate::backend_id::BackendId::new(),
|
||||
&app.config,
|
||||
&crate::AppServerTarget::Embedded,
|
||||
Vec::new(),
|
||||
loader,
|
||||
/*state_db*/ None,
|
||||
Arc::new(EnvironmentManager::default_for_tests()),
|
||||
))
|
||||
.await?;
|
||||
resume(&mut server, builder.build().await?).await?;
|
||||
let live = server.model_preview_permissions(first).await?.unwrap();
|
||||
let policy = live.profile.file_system_sandbox_policy();
|
||||
assert!(!policy.can_read_local_path_with_cwd(&home.join("private"), cwd.as_path()));
|
||||
assert!(policy.can_read_local_path_with_cwd(&home.join("public"), cwd.as_path()));
|
||||
server.shutdown().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn first_prompt_counts_once_before_and_after_resume() -> Result<()> {
|
||||
use crate::app::session_lifecycle::ThreadAttachPresentation::Fresh;
|
||||
|
||||
@@ -47,6 +47,7 @@ pub(super) async fn run_startup_for_test(
|
||||
/*initial_prompt*/ None,
|
||||
Vec::new(),
|
||||
selection,
|
||||
/*initial_resume_config*/ None,
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*is_first_run*/ false,
|
||||
/*should_prompt_windows_sandbox_nux_at_startup*/ false,
|
||||
|
||||
@@ -277,6 +277,31 @@ impl AppServerSession {
|
||||
let metadata = Box::pin(self.thread_read(thread_id, /*include_turns*/ false))
|
||||
.await
|
||||
.ok();
|
||||
// A fresh load applies managed rules. A loaded thread's sandbox summary
|
||||
// cannot confirm its proxy rules or filesystem restrictions.
|
||||
if permission_overrides.confirm_preset
|
||||
&& metadata.as_ref().is_none_or(|thread| {
|
||||
thread.status != codex_app_server_protocol::ThreadStatus::NotLoaded
|
||||
})
|
||||
{
|
||||
if config.managed_network_requirements_enabled() {
|
||||
color_eyre::eyre::bail!(
|
||||
"Cannot verify managed network restrictions for --approve-for-me. Unload the conversation and retry."
|
||||
);
|
||||
}
|
||||
let profile = config.permissions.permission_profile();
|
||||
if profile.to_legacy_sandbox_policy_template().is_err() {
|
||||
// Account for metadata protections on fixed writable roots.
|
||||
let policy = profile.to_legacy_sandbox_policy(config.cwd.as_path())?;
|
||||
if profile.file_system_sandbox_policy()
|
||||
!= codex_protocol::permissions::FileSystemSandboxPolicy::from(&policy)
|
||||
{
|
||||
color_eyre::eyre::bail!(
|
||||
"Cannot verify sandbox restrictions for --approve-for-me."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let known_legacy = cached_legacy
|
||||
&& (!self.uses_embedded_app_server()
|
||||
|| (rollout_maintenance_guard.is_some()
|
||||
@@ -287,6 +312,7 @@ impl AppServerSession {
|
||||
rollout_maintenance_guard = None;
|
||||
}
|
||||
let request_id = self.next_request_id();
|
||||
let exclude_turns = params.exclude_turns;
|
||||
let resume_response = self
|
||||
.request_handle
|
||||
.request_typed(ClientRequest::ThreadResume {
|
||||
@@ -295,7 +321,7 @@ impl AppServerSession {
|
||||
})
|
||||
.await;
|
||||
drop(rollout_maintenance_guard);
|
||||
let response: ThreadResumeResponse = match resume_response {
|
||||
let mut response: ThreadResumeResponse = match resume_response {
|
||||
Ok(response) => response,
|
||||
Err(TypedRequestError::Server { source, .. })
|
||||
if params.exclude_turns && is_history_pagination_unsupported(&source) =>
|
||||
@@ -317,6 +343,36 @@ impl AppServerSession {
|
||||
));
|
||||
}
|
||||
};
|
||||
if permission_overrides.confirm_preset
|
||||
&& let Some(settings) =
|
||||
crate::resume_permissions::initial_resume_update(&config, &response)?
|
||||
{
|
||||
// A loaded thread ignores resume overrides. Read back the effective
|
||||
// settings after the update, before releasing the initial prompt.
|
||||
if !self.thread_settings_update(settings).await? {
|
||||
color_eyre::eyre::bail!(
|
||||
"The server cannot apply --approve-for-me to this conversation."
|
||||
);
|
||||
}
|
||||
let request_id = self.next_request_id();
|
||||
response = self
|
||||
.request_handle
|
||||
.request_typed(ClientRequest::ThreadResume {
|
||||
request_id,
|
||||
params: ThreadResumeParams {
|
||||
thread_id: thread_id.to_string(),
|
||||
exclude_turns: exclude_turns
|
||||
&& self.history_support == ThreadHistorySupport::Paginated,
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
if crate::resume_permissions::initial_resume_update(&config, &response)?.is_some() {
|
||||
color_eyre::eyre::bail!(
|
||||
"The server did not confirm the requested permissions for --approve-for-me."
|
||||
);
|
||||
}
|
||||
}
|
||||
self.finish_thread_resume(
|
||||
local_settings,
|
||||
&config,
|
||||
|
||||
@@ -6,6 +6,13 @@ use codex_utils_cli::ApprovalModeCliArg;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use codex_utils_cli::SharedCliOptions;
|
||||
|
||||
/// Permission preset and its precedence on the first resume only.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ResumeApprovalPreset {
|
||||
pub config: CliConfigOverrides,
|
||||
pub overrides_root_permissions: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
#[command(version)]
|
||||
pub struct Cli {
|
||||
@@ -34,6 +41,10 @@ pub struct Cli {
|
||||
#[clap(skip)]
|
||||
pub resume_session_id: Option<String>,
|
||||
|
||||
/// Launch overrides including the approval preset, scoped to the initial resume.
|
||||
#[clap(skip)]
|
||||
pub resume_approval_preset: Option<ResumeApprovalPreset>,
|
||||
|
||||
/// Internal: show all sessions (disables cwd filtering and shows CWD column).
|
||||
#[clap(skip)]
|
||||
pub resume_show_all: bool,
|
||||
|
||||
@@ -300,6 +300,7 @@ use crate::startup_hooks_review::load_startup_hooks_review_entry;
|
||||
use crate::startup_hooks_review::maybe_run_startup_hooks_review;
|
||||
use crate::tui::Tui;
|
||||
pub use cli::Cli;
|
||||
pub use cli::ResumeApprovalPreset;
|
||||
use codex_arg0::Arg0DispatchPaths;
|
||||
pub use markdown_render::render_markdown_text;
|
||||
pub use public_widgets::composer_input::ComposerAction;
|
||||
@@ -2163,6 +2164,56 @@ async fn run_ratatui_app(
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let should_prompt_windows_sandbox_nux_at_startup = false;
|
||||
|
||||
let initial_resume_config = if let Some(preset) = &cli.resume_approval_preset {
|
||||
if !matches!(
|
||||
session_selection,
|
||||
resume_picker::SessionSelection::Resume(_)
|
||||
) {
|
||||
color_eyre::eyre::bail!("No conversation selected to resume with --approve-for-me.");
|
||||
}
|
||||
if app_server.thread_params_mode() != ThreadParamsMode::Embedded {
|
||||
return Err(color_eyre::eyre::eyre!(
|
||||
"Permission overrides are not supported when resuming a remote task."
|
||||
));
|
||||
}
|
||||
// Resolve the preset under the destination's trust and managed requirements.
|
||||
// Keep it out of the launch config used by /new and subsequent /resume commands.
|
||||
let mut scoped_overrides = overrides.clone();
|
||||
if preset.overrides_root_permissions {
|
||||
scoped_overrides.sandbox_mode = None;
|
||||
scoped_overrides.approval_policy = None;
|
||||
}
|
||||
let scoped_config = startup_draft
|
||||
.run_until(
|
||||
&mut tui,
|
||||
load_config_with_worktree_source_policy(
|
||||
preset
|
||||
.config
|
||||
.parse_overrides()
|
||||
.map_err(color_eyre::Report::msg)?,
|
||||
scoped_overrides,
|
||||
loader_overrides.clone(),
|
||||
cloud_config_bundle.clone(),
|
||||
strict_config,
|
||||
Some(config.cwd.to_path_buf()),
|
||||
managed_worktree.as_ref(),
|
||||
),
|
||||
)
|
||||
.await??;
|
||||
if let Some(warning) = add_dir_warning_message(
|
||||
&cli.add_dir,
|
||||
&scoped_config.permissions.effective_permission_profile(),
|
||||
scoped_config.cwd.as_path(),
|
||||
) {
|
||||
return Err(color_eyre::eyre::eyre!(
|
||||
"Error adding directories: {warning}"
|
||||
));
|
||||
}
|
||||
Some(Box::new(scoped_config))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let Cli {
|
||||
prompt,
|
||||
shared,
|
||||
@@ -2341,6 +2392,7 @@ async fn run_ratatui_app(
|
||||
prompt,
|
||||
images,
|
||||
session_selection,
|
||||
initial_resume_config,
|
||||
feedback,
|
||||
is_first_run,
|
||||
should_prompt_windows_sandbox_nux_at_startup,
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::legacy_core::config::ConfigOverrides;
|
||||
use codex_app_server_protocol::SandboxPolicy;
|
||||
use codex_app_server_protocol::ThreadResumeResponse;
|
||||
use codex_app_server_protocol::ThreadSettingsUpdateParams;
|
||||
use codex_config::ConfigLayerSource;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct ResumePermissions {
|
||||
@@ -11,6 +15,8 @@ pub(crate) struct ResumePermissions {
|
||||
pub approvals_reviewer: bool,
|
||||
pub profile: bool,
|
||||
pub workspace_roots: bool,
|
||||
/// Require the server to confirm the initial --approve-for-me preset before accepting input.
|
||||
pub confirm_preset: bool,
|
||||
}
|
||||
|
||||
impl ResumePermissions {
|
||||
@@ -25,6 +31,7 @@ impl ResumePermissions {
|
||||
})
|
||||
};
|
||||
Self {
|
||||
confirm_preset: false,
|
||||
approval_policy: overrides.approval_policy.is_some() || has("approval_policy"),
|
||||
approvals_reviewer: overrides.approvals_reviewer.is_some() || has("approvals_reviewer"),
|
||||
profile: overrides.sandbox_mode.is_some()
|
||||
@@ -43,15 +50,87 @@ impl ResumePermissions {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) const PRESET: Self = Self {
|
||||
confirm_preset: true,
|
||||
..Self::CURRENT_CONFIG
|
||||
};
|
||||
|
||||
pub(crate) const CURRENT_CONFIG: Self = Self {
|
||||
approval_policy: true,
|
||||
approvals_reviewer: true,
|
||||
profile: true,
|
||||
workspace_roots: true,
|
||||
confirm_preset: false,
|
||||
};
|
||||
}
|
||||
|
||||
/// The daemon may have rejoined an already-loaded thread and ignored the resume overrides.
|
||||
pub(crate) fn initial_resume_update(
|
||||
config: &Config,
|
||||
response: &ThreadResumeResponse,
|
||||
) -> color_eyre::Result<Option<ThreadSettingsUpdateParams>> {
|
||||
// Workspace Write implicitly grants cwd. A named profile also preserves
|
||||
// the thread's runtime roots, so it cannot supply missing ones.
|
||||
let profile = config.permissions.active_permission_profile();
|
||||
let requested: HashSet<_> = config
|
||||
.workspace_roots
|
||||
.iter()
|
||||
.map(codex_utils_absolute_path::AbsolutePathBuf::as_path)
|
||||
.collect();
|
||||
let active: HashSet<_> = response
|
||||
.runtime_workspace_roots
|
||||
.iter()
|
||||
.map(codex_utils_path_uri::LegacyAppPathString::as_path)
|
||||
.collect();
|
||||
if response.cwd.as_path() != config.cwd.as_path()
|
||||
|| !active.is_subset(&requested)
|
||||
|| (profile.is_some() && active != requested)
|
||||
{
|
||||
color_eyre::eyre::bail!("Cannot apply --approve-for-me to a different workspace.");
|
||||
}
|
||||
let approval_policy = config.permissions.approval_policy.value().into();
|
||||
let approvals_reviewer = config.approvals_reviewer.into();
|
||||
let mut settings = ThreadSettingsUpdateParams {
|
||||
thread_id: response.thread.id.clone(),
|
||||
approval_policy: Some(approval_policy),
|
||||
approvals_reviewer: Some(approvals_reviewer),
|
||||
..Default::default()
|
||||
};
|
||||
let sandbox: SandboxPolicy = config
|
||||
.permissions
|
||||
.effective_permission_profile()
|
||||
.to_legacy_sandbox_policy(config.cwd.as_path())?
|
||||
.into();
|
||||
let sandbox_changed = sorted_roots(response.sandbox.clone()) != sorted_roots(sandbox.clone());
|
||||
if let Some(profile) = profile {
|
||||
if sandbox_changed
|
||||
|| response
|
||||
.active_permission_profile
|
||||
.as_ref()
|
||||
.is_none_or(|active| active.id != profile.id)
|
||||
{
|
||||
settings.permissions = Some(profile.id);
|
||||
}
|
||||
} else if sandbox_changed {
|
||||
settings.sandbox_policy = Some(sandbox);
|
||||
}
|
||||
if response.approval_policy == approval_policy
|
||||
&& response.approvals_reviewer == approvals_reviewer
|
||||
&& settings.permissions.is_none()
|
||||
&& settings.sandbox_policy.is_none()
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(settings))
|
||||
}
|
||||
|
||||
fn sorted_roots(mut policy: SandboxPolicy) -> SandboxPolicy {
|
||||
if let SandboxPolicy::WorkspaceWrite { writable_roots, .. } = &mut policy {
|
||||
writable_roots.sort_unstable_by(|a, b| a.as_str().cmp(b.as_str()));
|
||||
}
|
||||
policy
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "resume_permissions_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -874,11 +874,14 @@ pub(super) async fn run_main_inner(
|
||||
|
||||
set_default_client_residency_requirement(config.enforce_residency.value());
|
||||
|
||||
if let Some(warning) = add_dir_warning_message(
|
||||
&cli.add_dir,
|
||||
&config.permissions.effective_permission_profile(),
|
||||
config.cwd.as_path(),
|
||||
) {
|
||||
// A resume-only preset is validated against the selected thread's config.
|
||||
if cli.resume_approval_preset.is_none()
|
||||
&& let Some(warning) = add_dir_warning_message(
|
||||
&cli.add_dir,
|
||||
&config.permissions.effective_permission_profile(),
|
||||
config.cwd.as_path(),
|
||||
)
|
||||
{
|
||||
#[allow(clippy::print_stderr)]
|
||||
{
|
||||
restore_terminal_before_fatal_exit();
|
||||
|
||||
Reference in New Issue
Block a user