Skip to content

Conversation

samibs
Copy link

@samibs samibs commented Oct 7, 2025

External (non-OpenAI) Pull Request Requirements

Before opening this Pull Request, please read the dedicated "Contributing" markdown file or your PR may be closed:
https://github.com/openai/codex/blob/main/docs/contributing.md

If your PR conforms to our contribution guidelines, replace this text with a detailed and high quality description of your changes.

samibs and others added 3 commits September 29, 2025 12:58
…-for-codex-cli

Add optional guardrails support to CLI
This commit introduces the core features of the GuardLoop project into the Codex CLI, transforming the static guardrail system into a dynamic, learning-based one.

Key changes:

- **Python Bridge (`guardloop_bridge.py`):** A new Python script that acts as the brain for the GuardLoop integration. It handles:
  - **Task Classification:** Analyzes the user's prompt to classify it as "code", "creative", or "unknown" and provides context-aware guardrails.
  - **Failure Logging:** Sets up a SQLite database at `~/.guardloop/data.db` and logs failed interactions when prompted by the user.

- **Codex CLI Integration (TypeScript):**
  - The `loadGuardrails` function in `src/extensions/guardrails.ts` is modified to execute the Python bridge script instead of reading from the `.guardrails` directory.
  - The user's prompt is now passed to the bridge for classification.

- **Codex CLI TUI Integration (Rust):**
  - A user feedback mechanism is added to the TUI. After each AI response, a "Was this helpful?" prompt is displayed.
  - If the user responds "No," the `LogGuardLoopFailure` event is triggered, which executes the Python bridge with the `--log-failure` flag to record the prompt.
  - The `ChatWidget` in `codex-rs/tui/src/chatwidget.rs` is updated to manage this feedback loop.

This integration lays the foundation for a more adaptive and intelligent AI governance system within the Codex CLI, learning from user feedback to improve its guardrails over time.
Copy link

github-actions bot commented Oct 7, 2025


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


0 out of 2 committers have signed the CLA.
@samibs
@google-labs-jules[bot]
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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 👍.

Comment on lines +59 to +66
export async function buildPromptWithGuardrails(userPrompt, options = {}) {
const { argv = process.argv.slice(2), env = process.env, cwd = process.cwd(), guardrailsEnabled } = options;
const enabled =
typeof guardrailsEnabled === "boolean" ? guardrailsEnabled : shouldUseGuardrails({ argv, env });

if (!enabled) {
return userPrompt;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Wire guardrail toggle into actual prompt generation

The CLI exposes shouldUseGuardrails/buildPromptWithGuardrails to prepend guardrail text (lines 59‑73), but nothing in the repository calls these functions outside of the new unit tests. Because the main CLI entry points never invoke buildPromptWithGuardrails, the --guardrails flag and CODEX_GUARDRAILS environment variable have no effect and user prompts are never modified. The feature is effectively dead code and the guardrails setting cannot work until prompt construction is updated to use this helper.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant