-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Feature/guardloop integration #4886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…-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.
I have read the CLA Document and I hereby sign the CLA 0 out of 2 committers have signed the CLA. |
There was a problem hiding this 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 👍.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
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.