Compare commits

...

2 Commits

Author SHA1 Message Date
Gabriel Peal
df35b1be7a WIP 2025-07-17 20:01:26 -07:00
Gabriel Peal
c0c340a169 --wip-- [skip ci] 2025-07-17 17:22:08 -07:00
6 changed files with 40 additions and 14 deletions

5
codex-rs/AGENTS.md Normal file
View File

@@ -0,0 +1,5 @@
# Suggestions
* Always check your work with:
* `cargo build`
* `cargo test`
* `cargo clippy --all-features --tests -- -D warnings`

1
codex-rs/Cargo.lock generated
View File

@@ -677,6 +677,7 @@ dependencies = [
"pretty_assertions",
"rand 0.9.1",
"reqwest",
"schemars 0.8.22",
"seccompiler",
"serde",
"serde_json",

View File

@@ -26,6 +26,7 @@ mcp-types = { path = "../mcp-types" }
mime_guess = "2.0"
rand = "0.9"
reqwest = { version = "0.12", features = ["json", "stream"] }
schemars = "0.8.22"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha1 = "0.10.6"

View File

@@ -17,6 +17,7 @@ use crate::config_types::ReasoningEffort as ReasoningEffortConfig;
use crate::config_types::ReasoningSummary as ReasoningSummaryConfig;
use crate::message_history::HistoryEntry;
use crate::model_provider_info::ModelProviderInfo;
use schemars::JsonSchema;
/// Submission Queue Entry - requests from user
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -486,7 +487,7 @@ pub struct SessionConfiguredEvent {
}
/// User's decision in response to an ExecApprovalRequest.
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ReviewDecision {
/// User has approved this command and the agent should execute it.

View File

@@ -2,6 +2,7 @@
use codex_core::config_types::SandboxMode;
use codex_core::protocol::AskForApproval;
use codex_core::protocol::ReviewDecision;
use mcp_types::Tool;
use mcp_types::ToolInputSchema;
use schemars::JsonSchema;
@@ -156,6 +157,14 @@ impl CodexToolCallParam {
}
}
/// Client-supplied configuration for a `codex/experimental/approve_patch` tool-call.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
pub(crate) struct CodexApprovePatchToolCallParam {
/// The user's decision in response to the patch approval request.
pub review_decision: ReviewDecision,
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -329,21 +329,26 @@ impl MessageProcessor {
tracing::info!("tools/call -> params: {:?}", params);
let CallToolRequestParams { name, arguments } = params;
// We only support the "codex" tool for now.
if name != "codex" {
// Tool not found return error result so the LLM can react.
let result = CallToolResult {
content: vec![CallToolResultContent::TextContent(TextContent {
r#type: "text".to_string(),
text: format!("Unknown tool '{name}'"),
annotations: None,
})],
is_error: Some(true),
};
self.send_response::<mcp_types::CallToolRequest>(id, result);
return;
match name.as_str() {
"codex" => self.handle_codex_tool_call(id, arguments),
"codex/experimental/approve_patch" => self.handle_approve_patch(id, arguments),
_ => {
// Tool not found return error result so the LLM can react.
let result = CallToolResult {
content: vec![CallToolResultContent::TextContent(TextContent {
r#type: "text".to_string(),
text: format!("Unknown tool '{name}'"),
annotations: None,
})],
is_error: Some(true),
};
self.send_response::<mcp_types::CallToolRequest>(id, result);
}
}
}
fn handle_codex_tool_call(&self, id: RequestId, arguments: Option<serde_json::Value>) {
// If no arguments are provided, we cannot proceed.
let (initial_prompt, config): (String, CodexConfig) = match arguments {
Some(json_val) => match serde_json::from_value::<CodexToolCallParam>(json_val) {
Ok(tool_cfg) => match tool_cfg.into_config(self.codex_linux_sandbox_exe.clone()) {
@@ -404,6 +409,10 @@ impl MessageProcessor {
});
}
/// TODO: Migrate this to MCP elicitations.
fn handle_approve_patch(&self, id: RequestId, arguments: Option<serde_json::Value>) {
}
fn handle_set_level(
&self,
params: <mcp_types::SetLevelRequest as mcp_types::ModelContextProtocolRequest>::Params,