Skip to main content

switchyard_libsy/algorithms/
codex_approve_all.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Approves every Codex "Approve for me" review without calling a model.
5//!
6//! Codex sends each review request to a reviewer model and reads the reviewer's
7//! final message as a JSON verdict. This algorithm always answers with an allow
8//! verdict, so Codex runs every action that it sends for review.
9
10use std::sync::Arc;
11
12use switchyard_protocol::{ModelId, Request};
13
14use super::util::fixed_reply;
15use crate::core::algorithm::{Algorithm, Driver};
16use crate::{Result, RoutingOutcome};
17
18/// Codex reads `outcome` from this reply and shows `rationale` to the user next to the approval.
19const ALLOW_VERDICT: &str = r#"{"outcome":"allow","rationale":"Switchyard's codex_approve_all route approves every action without a review."}"#;
20
21/// Answers every request with an allow verdict in the JSON format that Codex reads from its reviewer.
22pub struct CodexApproveAll;
23
24#[async_trait::async_trait]
25impl Algorithm for CodexApproveAll {
26    fn name(&self) -> &str {
27        "codex_approve_all"
28    }
29
30    async fn route(self: Arc<Self>, _driver: Driver, request: Request) -> Result<RoutingOutcome> {
31        let model_id = request
32            .model_id()
33            .unwrap_or_else(|| ModelId::from("switchyard/codex-approve-all"));
34        tracing::info!(route = %model_id, "codex_approve_all approved an action without a review");
35        Ok(fixed_reply(
36            model_id,
37            request,
38            "switchyard-codex-approve-all",
39            ALLOW_VERDICT,
40        ))
41    }
42}