Skip to content

Conversation

@zhao-oai
Copy link
Collaborator

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

Summary

  • Introduces the codex-execpolicy2 crate.
  • This PR covers only the prefix-rule subset of the planned execpolicy v2 language; a richer language will follow.

Policy

  • Policy language centers on prefix_rule(pattern=[...], decision?, match?, not_match?), where pattern is an ordered list of tokens; any element may be a list to denote alternatives. decision defaults to allow; valid values are allow, prompt, and forbidden. match / not_match hold example commands that are tokenized and validated at load time (think of these as unit tests).

Policy shapes

  • Prefix rules use Starlark syntax:
prefix_rule(
    pattern = ["cmd", ["alt1", "alt2"]], # ordered tokens; list entries denote alternatives
    decision = "prompt",                # allow | prompt | forbidden; defaults to allow
    match = [["cmd", "alt1"]],          # examples that must match this rule (enforced at compile time)
    not_match = [["cmd", "oops"]],      # examples that must not match this rule (enforced at compile time)
)

Response shapes

  • Match:
{
  "match": {
    "decision": "allow|prompt|forbidden",
    "matchedRules": [
      {
        "prefixRuleMatch": {
          "matchedPrefix": ["<token>", "..."],
          "decision": "allow|prompt|forbidden"
        }
      }
    ]
  }
}
  • No match:
"noMatch"
  • matchedRules lists every rule whose prefix matched the command; matchedPrefix is the exact prefix that matched.
  • The effective decision is the strictest severity across all matches (forbidden > prompt > allow).

@etraut-openai etraut-openai added the oai-pr PRs posted by Codex team members label Nov 10, 2025
@zhao-oai
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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".

@zhao-oai
Copy link
Collaborator Author

@codex review

@zhao-oai zhao-oai changed the title [draft] first pass at prefix rules execpolicy v2 Nov 11, 2025
@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".

@zhao-oai zhao-oai changed the title execpolicy v2 feat: execpolicy v2 Nov 11, 2025
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.

I'm still reviewing, but I have to jump and wanted to share what I saw thus far.

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.

This is a good start, but some things could be tightened up!

@zhao-oai
Copy link
Collaborator Author

@codex review

@zhao-oai zhao-oai requested a review from bolinfest November 12, 2025 23:59
@zhao-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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".

@zhao-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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".

Comment on lines 25 to 45
"match": {
"decision": "allow|prompt|forbidden",
"matched_rules": [
{
"prefixRuleMatch": {
"matched_prefix": ["<token>", "..."],
"decision": "allow|prompt|forbidden"
}
}
]
}
}
```

- No match:
```json
"noMatch"
```

- `matched_rules` lists every rule whose prefix matched the command; `matched_prefix` is the exact prefix that matched.
- The effective `decision` is the strictest severity across all matches (`forbidden` > `prompt` > `allow`).
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Fix README JSON field names

The response shape documented in README.md shows snake_case fields (matched_rules, matched_prefix) even though the actual serializer derives #[serde(rename_all = "camelCase")] for both Evaluation and RuleMatch (see policy.rs:43-50 and rule.rs:59-66). The CLI/library therefore emits matchedRules and matchedPrefix. Anyone implementing a client using the README will look for the wrong keys and fail to parse the CLI output. Please update the README example and accompanying text to use the camelCase names that the code actually produces.

Useful? React with 👍 / 👎.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codex could you please compile the code and double check this feedback is correct? if it is correct, please fix the README.md

Copy link
Contributor

Choose a reason for hiding this comment

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

Summary

Testing

  • cargo test -p codex-execpolicy2
  • cargo run -p codex-execpolicy2 -- check --policy execpolicy2/examples/example.codexpolicy ls -l

View task →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oai-pr PRs posted by Codex team members

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants