Skip to content

Conversation

@zhao-oai
Copy link
Collaborator

@zhao-oai zhao-oai commented Nov 20, 2025

this PR enables TUI to approve commands and add their prefixes to an allowlist:
Screenshot 2025-11-21 at 4 18 07 PM

note: we only show the option to whitelist the command when

  1. command is not multi-part (e.g git add -A && git commit -m 'hello world')
  2. command is not already matched by an existing rule

@zhao-oai zhao-oai changed the base branch from main to pr7032 November 20, 2025 21:48
@zhao-oai zhao-oai force-pushed the pr7032 branch 3 times, most recently from 683bc5f to 1273f94 Compare November 20, 2025 22:16
@zhao-oai zhao-oai force-pushed the pr7033 branch 4 times, most recently from 9cb7ed0 to 80c63d3 Compare November 21, 2025 17:15
@zhao-oai
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

commands: &[Vec<String>],
features: &Features,
) -> Option<Vec<String>> {
if features.enabled(Feature::ExecPolicy) && commands.len() == 1 {
Copy link
Collaborator Author

@zhao-oai zhao-oai Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the solution I came up with here w.r.t only persisting allow prefix if ExecPolicy is enabled. I think a better solution would be to change the way we store Policy in session state. We should store either an enum indicating whether ExecPolicy is enabled or store Policy as an optional. However, I think this is fit for a followup PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this relates to my long comment above on NeedsApproval.

@zhao-oai zhao-oai changed the title Add approval allow-prefix flow in core and tui allow-prefix integration in core and tui Nov 21, 2025
@zhao-oai zhao-oai changed the title allow-prefix integration in core and tui whitelist command prefix integration in core and tui Nov 21, 2025
@zhao-oai zhao-oai requested a review from bolinfest November 21, 2025 22:18
@zhao-oai
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

features: Features,
/// Execpolicy policy, applied only when enabled by feature flag.
exec_policy: Arc<ExecPolicy>,
exec_policy: Arc<RwLock<ExecPolicy>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this feels slightly undesirable since SessionConfiguration is already generally wrapped in a mutex, but maybe this is OK, I'm not sure yet...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #7540

}

#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
pub struct ExecApprovalRequestEvent {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to update the v2 app server protocol as well, I expect. /cc @owenlin0

Copy link
Contributor

@owenlin0 owenlin0 Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhao-oai yes that'd be great if we can keep app-server at feature-parity (but can be done as a followup PR). We'd probably want to add a field here: https://github.com/openai/codex/blob/main/codex-rs/app-server-protocol/src/protocol/v2.rs#L1428 and wire it up

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. let's do this as a followup

Base automatically changed from pr7032 to main December 2, 2025 20:05
let approval_requirement = {
let exec_policy = context.session.current_exec_policy().await;
create_approval_requirement_for_command(
&exec_policy,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if instead of adding current_exec_policy(), we just pass &context.exec_policy to create_approval_requirement_for_command()?

Is the issue that context.session.state is held by a tokio::sync::mutex and so we need to clone the values while holding the lock so we can pass them into create_approval_requirement_for_command() because it is not async?

If so, should we make create_approval_requirement_for_command() async?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhao-oai How's this: #7501

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, merged. Rebase and rejoice!

bolinfest added a commit that referenced this pull request Dec 2, 2025
I think this might help with #7033
because `create_approval_requirement_for_command()` will soon need
access to `Session.state`, which is a `tokio::sync::Mutex` that needs to
be accessed via `async`.
@zhao-oai zhao-oai force-pushed the pr7033 branch 3 times, most recently from d23f506 to 312ceb4 Compare December 3, 2025 02:58
features: Features,
/// Execpolicy policy, applied only when enabled by feature flag.
exec_policy: Arc<ExecPolicy>,
exec_policy: Arc<RwLock<ExecPolicy>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #7540

commands: &[Vec<String>],
features: &Features,
) -> Option<Vec<String>> {
if features.enabled(Feature::ExecPolicy) && commands.len() == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this relates to my long comment above on NeedsApproval.

@zhao-oai zhao-oai force-pushed the pr7033 branch 5 times, most recently from 86b1d98 to 31c5e11 Compare December 3, 2025 23:14
Copy link
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to rebase on #7540 when cleaning up merge conflicts!

Add explicit prefix-approval decision and wire it through execpolicy/UI snapshots

update doc

mutating in memory policy instead of reloading

using RW locks

clippy

refactor: adding allow_prefix into ApprovedAllowPrefix

fmt

do not send allow_prefix if execpolicy is disabled

moving args around

cleanup exec_policy getters

undo diff

fixing rw lock bug causing tui to hang

updating phrasing

integration test

.

fix compile

fix flaky test

fix compile error

running test with single thread

fixup allow_prefix_if_applicable

fix formatting

fix approvals test

only cloning when needed

docs

add docstring

fix rebase bug

fixing rebase issues

Revert "fixing rebase issues"

This reverts commit 79ce7e1.

fix rebase errors
@zhao-oai zhao-oai merged commit e925a38 into main Dec 4, 2025
71 of 73 checks passed
@zhao-oai zhao-oai deleted the pr7033 branch December 4, 2025 07:17
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants