mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
056c8f8279
This PR introduces an extra layer of abstraction to prepare us for the migration to execpolicy2: - introduces a new trait, `EscalationPolicy`, whose `determine_action()` method is responsible for producing the `EscalateAction` - the existing `ExecPolicy` typedef is changed to return an intermediate `ExecPolicyOutcome` instead of `EscalateAction` - the default implementation of `EscalationPolicy`, `McpEscalationPolicy`, composes `ExecPolicy` - the `ExecPolicyOutcome` includes `codex_execpolicy2::Decision`, which has a `Prompt` variant - when `McpEscalationPolicy` gets `Decision::Prompt` back from `ExecPolicy`, it prompts the user via an MCP elicitation and maps the result into an `ElicitationAction` - now that the end user can reply to an elicitation with `Decline` or `Cancel`, we introduce a new variant, `EscalateAction::Deny`, which the client handles by returning exit code `1` without running anything Note the way the elicitation is created is still not quite right, but I will fix that once we have things running end-to-end for real in a follow-up PR.
52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
use std::collections::HashMap;
|
|
use std::os::fd::RawFd;
|
|
use std::path::PathBuf;
|
|
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
/// 'exec-server escalate' reads this to find the inherited FD for the escalate socket.
|
|
pub(super) const ESCALATE_SOCKET_ENV_VAR: &str = "CODEX_ESCALATE_SOCKET";
|
|
|
|
/// The patched bash uses this to wrap exec() calls.
|
|
pub(super) const BASH_EXEC_WRAPPER_ENV_VAR: &str = "BASH_EXEC_WRAPPER";
|
|
|
|
/// The client sends this to the server to request an exec() call.
|
|
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
|
|
pub(super) struct EscalateRequest {
|
|
/// The absolute path to the executable to run, i.e. the first arg to exec.
|
|
pub(super) file: PathBuf,
|
|
/// The argv, including the program name (argv[0]).
|
|
pub(super) argv: Vec<String>,
|
|
pub(super) workdir: PathBuf,
|
|
pub(super) env: HashMap<String, String>,
|
|
}
|
|
|
|
/// The server sends this to the client to respond to an exec() request.
|
|
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
|
|
pub(super) struct EscalateResponse {
|
|
pub(super) action: EscalateAction,
|
|
}
|
|
|
|
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
|
|
pub(super) enum EscalateAction {
|
|
/// The command should be run directly by the client.
|
|
Run,
|
|
/// The command should be escalated to the server for execution.
|
|
Escalate,
|
|
/// The command should not be executed.
|
|
Deny { reason: Option<String> },
|
|
}
|
|
|
|
/// The client sends this to the server to forward its open FDs.
|
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
pub(super) struct SuperExecMessage {
|
|
pub(super) fds: Vec<RawFd>,
|
|
}
|
|
|
|
/// The server responds when the exec()'d command has exited.
|
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
pub(super) struct SuperExecResult {
|
|
pub(super) exit_code: i32,
|
|
}
|