mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Investigate Gemini CLI ACP tests
This commit is contained in:
Generated
+28
@@ -1371,6 +1371,33 @@ version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9b18233253483ce2f65329a24072ec414db782531bdbb7d0bbc4bd2ce6b7e21"
|
||||
|
||||
[[package]]
|
||||
name = "codex-acp-server"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"codex-app-server-client",
|
||||
"codex-app-server-protocol",
|
||||
"codex-arg0",
|
||||
"codex-cloud-requirements",
|
||||
"codex-core",
|
||||
"codex-feedback",
|
||||
"codex-protocol",
|
||||
"codex-rmcp-client",
|
||||
"codex-utils-cargo-bin",
|
||||
"codex-utils-cli",
|
||||
"futures",
|
||||
"pretty_assertions",
|
||||
"rmcp",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codex-ansi-escape"
|
||||
version = "0.0.0"
|
||||
@@ -1637,6 +1664,7 @@ dependencies = [
|
||||
"assert_matches",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"codex-acp-server",
|
||||
"codex-app-server",
|
||||
"codex-app-server-protocol",
|
||||
"codex-app-server-test-client",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
members = [
|
||||
"backend-client",
|
||||
"ansi-escape",
|
||||
"acp-server",
|
||||
"async-utils",
|
||||
"app-server",
|
||||
"app-server-client",
|
||||
@@ -84,6 +85,7 @@ license = "Apache-2.0"
|
||||
app_test_support = { path = "app-server/tests/common" }
|
||||
codex-ansi-escape = { path = "ansi-escape" }
|
||||
codex-api = { path = "codex-api" }
|
||||
codex-acp-server = { path = "acp-server" }
|
||||
codex-artifacts = { path = "artifacts" }
|
||||
codex-package-manager = { path = "package-manager" }
|
||||
codex-app-server = { path = "app-server" }
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
[package]
|
||||
name = "codex-acp-server"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "codex-acp-server"
|
||||
path = "src/main.rs"
|
||||
|
||||
[lib]
|
||||
name = "codex_acp_server"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
codex-app-server-client = { workspace = true }
|
||||
codex-app-server-protocol = { workspace = true }
|
||||
codex-arg0 = { workspace = true }
|
||||
codex-cloud-requirements = { workspace = true }
|
||||
codex-core = { workspace = true }
|
||||
codex-feedback = { workspace = true }
|
||||
codex-protocol = { workspace = true }
|
||||
codex-rmcp-client = { workspace = true }
|
||||
codex-utils-cli = { workspace = true }
|
||||
futures = { workspace = true, default-features = false, features = ["std"] }
|
||||
rmcp = { workspace = true, default-features = false, features = ["client", "server"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
tokio = { workspace = true, features = [
|
||||
"io-std",
|
||||
"macros",
|
||||
"rt-multi-thread",
|
||||
"signal",
|
||||
"sync",
|
||||
] }
|
||||
tracing = { workspace = true, features = ["log"] }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
codex-utils-cargo-bin = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
use codex_acp_server::run_main;
|
||||
use codex_arg0::Arg0DispatchPaths;
|
||||
use codex_arg0::arg0_dispatch_or_else;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
arg0_dispatch_or_else(|arg0_paths: Arg0DispatchPaths| async move {
|
||||
run_main(arg0_paths, CliConfigOverrides::default()).await?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
pub const JSONRPC_VERSION: &str = "2.0";
|
||||
pub const PROTOCOL_VERSION: i64 = 1;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum JsonRpcMessage {
|
||||
Request(JsonRpcRequest),
|
||||
Notification(JsonRpcNotification),
|
||||
Response(JsonRpcResponse),
|
||||
Error(JsonRpcError),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct JsonRpcRequest {
|
||||
pub jsonrpc: String,
|
||||
pub id: RequestId,
|
||||
pub method: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub params: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct JsonRpcNotification {
|
||||
pub jsonrpc: String,
|
||||
pub method: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub params: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct JsonRpcResponse {
|
||||
pub jsonrpc: String,
|
||||
pub id: RequestId,
|
||||
pub result: JsonValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct JsonRpcError {
|
||||
pub jsonrpc: String,
|
||||
pub id: RequestId,
|
||||
pub error: JsonRpcErrorBody,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct JsonRpcErrorBody {
|
||||
pub code: i64,
|
||||
pub message: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub data: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InitializeParams {
|
||||
pub protocol_version: i64,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub client_capabilities: Option<ClientCapabilities>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub client_info: Option<ClientInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ClientCapabilities {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub elicitation: Option<ElicitationCapabilities>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ElicitationCapabilities {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub form: Option<JsonValue>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ClientInfo {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InitializeResult {
|
||||
pub protocol_version: i64,
|
||||
pub agent_capabilities: AgentCapabilities,
|
||||
pub agent_info: AgentInfo,
|
||||
pub auth_methods: Vec<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AgentCapabilities {
|
||||
pub load_session: bool,
|
||||
pub session_capabilities: SessionCapabilities,
|
||||
pub prompt_capabilities: PromptCapabilities,
|
||||
pub mcp_capabilities: McpCapabilities,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionCapabilities {
|
||||
pub list: EmptyCapability,
|
||||
pub fork: EmptyCapability,
|
||||
pub resume: EmptyCapability,
|
||||
pub close: EmptyCapability,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Deserialize, Serialize)]
|
||||
pub struct EmptyCapability {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpCapabilities {
|
||||
pub http: bool,
|
||||
pub sse: bool,
|
||||
pub acp: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PromptCapabilities {
|
||||
pub image: bool,
|
||||
pub audio: bool,
|
||||
pub embedded_context: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Mode {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Modes {
|
||||
pub current_mode_id: String,
|
||||
pub available_modes: Vec<Mode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AgentInfo {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionNewParams {
|
||||
pub cwd: String,
|
||||
#[serde(default)]
|
||||
pub mcp_servers: Vec<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionNewResult {
|
||||
pub session_id: String,
|
||||
pub modes: Modes,
|
||||
pub config_options: Vec<ConfigOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionLoadParams {
|
||||
pub session_id: String,
|
||||
pub cwd: String,
|
||||
#[serde(default)]
|
||||
pub mcp_servers: Vec<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionLoadResult {
|
||||
pub modes: Modes,
|
||||
pub config_options: Vec<ConfigOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionResumeParams {
|
||||
pub session_id: String,
|
||||
pub cwd: String,
|
||||
#[serde(default)]
|
||||
pub mcp_servers: Vec<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionResumeResult {
|
||||
pub modes: Modes,
|
||||
pub config_options: Vec<ConfigOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionForkParams {
|
||||
pub session_id: String,
|
||||
pub cwd: String,
|
||||
#[serde(default)]
|
||||
pub mcp_servers: Vec<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionForkResult {
|
||||
pub session_id: String,
|
||||
pub modes: Modes,
|
||||
pub config_options: Vec<ConfigOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionListParams {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub cwd: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionListResult {
|
||||
pub sessions: Vec<SessionInfo>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionInfo {
|
||||
pub session_id: String,
|
||||
pub cwd: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub updated_at: Option<String>,
|
||||
#[serde(default, rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionCloseParams {
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct SessionCloseResult {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionSetModeParams {
|
||||
pub session_id: String,
|
||||
pub mode_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct SessionSetModeResult {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionPromptParams {
|
||||
pub session_id: String,
|
||||
pub prompt: Vec<PromptContent>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum PromptContent {
|
||||
Text { text: String },
|
||||
Resource { resource: ResourceContent },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ResourceContent {
|
||||
pub uri: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mime_type: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionPromptResult {
|
||||
pub stop_reason: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionCancelParams {
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionUpdateParams {
|
||||
pub session_id: String,
|
||||
pub update: SessionUpdate,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "sessionUpdate", rename_all = "snake_case")]
|
||||
pub enum SessionUpdate {
|
||||
UserMessageChunk {
|
||||
content: TextContent,
|
||||
},
|
||||
AgentMessageChunk {
|
||||
content: TextContent,
|
||||
},
|
||||
Plan {
|
||||
entries: Vec<PlanEntry>,
|
||||
},
|
||||
CurrentModeUpdate {
|
||||
current_mode_id: String,
|
||||
},
|
||||
ConfigOptionsUpdate {
|
||||
config_options: Vec<ConfigOption>,
|
||||
},
|
||||
SessionInfoUpdate {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
title: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
updated_at: Option<String>,
|
||||
#[serde(default, rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
meta: Option<JsonValue>,
|
||||
},
|
||||
ToolCall {
|
||||
tool_call_id: String,
|
||||
title: String,
|
||||
kind: String,
|
||||
status: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
locations: Option<Vec<Location>>,
|
||||
},
|
||||
ToolCallUpdate {
|
||||
tool_call_id: String,
|
||||
status: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
content: Option<Vec<ToolCallContent>>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct TextContent {
|
||||
#[serde(rename = "type")]
|
||||
pub content_type: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PlanEntry {
|
||||
pub content: String,
|
||||
pub priority: String,
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConfigOption {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub category: Option<String>,
|
||||
#[serde(rename = "type")]
|
||||
pub option_type: String,
|
||||
pub current_value: String,
|
||||
pub options: Vec<ConfigOptionValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConfigOptionValue {
|
||||
pub value: String,
|
||||
pub name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Location {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum ToolCallContent {
|
||||
Content { content: TextContent },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionRequestPermissionParams {
|
||||
pub session_id: String,
|
||||
pub tool_call: PermissionToolCall,
|
||||
pub options: Vec<PermissionOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionElicitationParams {
|
||||
pub session_id: String,
|
||||
pub elicitation: SessionElicitationRequest,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "mode", rename_all = "camelCase")]
|
||||
pub enum SessionElicitationRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Form {
|
||||
message: String,
|
||||
requested_schema: JsonValue,
|
||||
#[serde(default, rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
meta: Option<JsonValue>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Url {
|
||||
message: String,
|
||||
url: String,
|
||||
elicitation_id: String,
|
||||
#[serde(default, rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
meta: Option<JsonValue>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionElicitationResponse {
|
||||
pub action: ElicitationAction,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub content: Option<JsonValue>,
|
||||
#[serde(default, rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ElicitationAction {
|
||||
Accept,
|
||||
Decline,
|
||||
Cancel,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpConnectParams {
|
||||
pub acp_id: String,
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpConnectResult {
|
||||
pub connection_id: String,
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpDisconnectParams {
|
||||
pub connection_id: String,
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpDisconnectResult {
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpMessageParams {
|
||||
pub connection_id: String,
|
||||
pub method: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub params: Option<JsonValue>,
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct McpMessageResult {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub result: Option<JsonValue>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<JsonValue>,
|
||||
#[serde(default, alias = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<JsonValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PermissionToolCall {
|
||||
pub tool_call_id: String,
|
||||
pub title: String,
|
||||
pub kind: String,
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PermissionOption {
|
||||
pub option_id: String,
|
||||
pub name: String,
|
||||
pub kind: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct PermissionResponse {
|
||||
pub outcome: PermissionOutcome,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "outcome", rename_all = "snake_case")]
|
||||
pub enum PermissionOutcome {
|
||||
Selected { option_id: String },
|
||||
Cancelled,
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value as JsonValue;
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn write_json_line(stdin: &mut std::process::ChildStdin, value: JsonValue) -> Result<()> {
|
||||
writeln!(stdin, "{}", serde_json::to_string(&value)?)?;
|
||||
stdin.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_json_line(stdout: &mut BufReader<std::process::ChildStdout>) -> Result<JsonValue> {
|
||||
let mut line = String::new();
|
||||
stdout.read_line(&mut line)?;
|
||||
serde_json::from_str(&line).context("parse ACP JSON-RPC response")
|
||||
}
|
||||
|
||||
fn read_response(stdout: &mut BufReader<std::process::ChildStdout>, id: i64) -> Result<JsonValue> {
|
||||
loop {
|
||||
let message = read_json_line(stdout)?;
|
||||
if message["id"] == id {
|
||||
return Ok(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_session_update_kinds(
|
||||
stdout: &mut BufReader<std::process::ChildStdout>,
|
||||
count: usize,
|
||||
) -> Result<Vec<String>> {
|
||||
let mut kinds = Vec::new();
|
||||
while kinds.len() < count {
|
||||
let message = read_json_line(stdout)?;
|
||||
if message["method"] == "session/update" {
|
||||
kinds.push(
|
||||
message["params"]["update"]["sessionUpdate"]
|
||||
.as_str()
|
||||
.context("session update kind missing")?
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(kinds)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acp_server_supports_session_setup_and_mode_switching() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let workspace = TempDir::new()?;
|
||||
let mut child = Command::new(codex_utils_cargo_bin::cargo_bin("codex-acp-server")?)
|
||||
.env("CODEX_HOME", codex_home.path())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::inherit())
|
||||
.spawn()
|
||||
.context("spawn codex-acp-server")?;
|
||||
|
||||
let mut stdin = child.stdin.take().context("take stdin")?;
|
||||
let stdout = child.stdout.take().context("take stdout")?;
|
||||
let mut stdout = BufReader::new(stdout);
|
||||
|
||||
write_json_line(
|
||||
&mut stdin,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": 1,
|
||||
"clientInfo": {
|
||||
"name": "acp-test",
|
||||
"version": "0.0.0"
|
||||
}
|
||||
}
|
||||
}),
|
||||
)?;
|
||||
|
||||
let initialize = read_response(&mut stdout, 1)?;
|
||||
assert_eq!(initialize["id"], 1);
|
||||
assert_eq!(initialize["result"]["protocolVersion"], 1);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["promptCapabilities"]["embeddedContext"],
|
||||
JsonValue::Bool(true)
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["promptCapabilities"]["image"],
|
||||
JsonValue::Bool(true)
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["mcpCapabilities"]["acp"],
|
||||
JsonValue::Bool(true)
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["sessionCapabilities"]["list"],
|
||||
serde_json::json!({})
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["sessionCapabilities"]["fork"],
|
||||
serde_json::json!({})
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["sessionCapabilities"]["resume"],
|
||||
serde_json::json!({})
|
||||
);
|
||||
assert_eq!(
|
||||
initialize["result"]["agentCapabilities"]["sessionCapabilities"]["close"],
|
||||
serde_json::json!({})
|
||||
);
|
||||
|
||||
write_json_line(
|
||||
&mut stdin,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 2,
|
||||
"method": "session/new",
|
||||
"params": {
|
||||
"cwd": workspace.path(),
|
||||
"mcpServers": []
|
||||
}
|
||||
}),
|
||||
)?;
|
||||
|
||||
let session_new = read_response(&mut stdout, 2)?;
|
||||
assert_eq!(session_new["id"], 2);
|
||||
let session_id = session_new["result"]["sessionId"]
|
||||
.as_str()
|
||||
.context("sessionId missing")?
|
||||
.to_string();
|
||||
let modes = session_new["result"]["modes"]["availableModes"]
|
||||
.as_array()
|
||||
.context("availableModes missing")?;
|
||||
assert!(!modes.is_empty(), "expected at least one ACP mode");
|
||||
let first_mode_id = modes[0]["id"]
|
||||
.as_str()
|
||||
.context("mode id missing")?
|
||||
.to_string();
|
||||
assert_eq!(
|
||||
session_new["result"]["configOptions"][0]["id"],
|
||||
JsonValue::String("mode".to_string())
|
||||
);
|
||||
|
||||
write_json_line(
|
||||
&mut stdin,
|
||||
serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 3,
|
||||
"method": "session/set_mode",
|
||||
"params": {
|
||||
"sessionId": session_id,
|
||||
"modeId": first_mode_id
|
||||
}
|
||||
}),
|
||||
)?;
|
||||
|
||||
let set_mode = read_response(&mut stdout, 3)?;
|
||||
assert_eq!(set_mode["id"], 3);
|
||||
assert_eq!(set_mode["result"], serde_json::json!({}));
|
||||
|
||||
let updates = read_session_update_kinds(&mut stdout, 2)?;
|
||||
assert!(updates.contains(&"current_mode_update".to_string()));
|
||||
assert!(updates.contains(&"config_options_update".to_string()));
|
||||
|
||||
drop(stdin);
|
||||
child.kill()?;
|
||||
let _ = child.wait()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1701,6 +1701,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -14336,6 +14336,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -12134,6 +12134,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -760,6 +760,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -760,6 +760,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -760,6 +760,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -518,6 +518,7 @@
|
||||
"cli",
|
||||
"vscode",
|
||||
"exec",
|
||||
"acp",
|
||||
"appServer",
|
||||
"unknown"
|
||||
],
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { SubAgentSource } from "./SubAgentSource";
|
||||
|
||||
export type SessionSource = "cli" | "vscode" | "exec" | "mcp" | { "subagent": SubAgentSource } | "unknown";
|
||||
export type SessionSource = "cli" | "vscode" | "exec" | "acp" | "mcp" | { "subagent": SubAgentSource } | "unknown";
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { SubAgentSource } from "../SubAgentSource";
|
||||
|
||||
export type SessionSource = "cli" | "vscode" | "exec" | "appServer" | { "subAgent": SubAgentSource } | "unknown";
|
||||
export type SessionSource = "cli" | "vscode" | "exec" | "acp" | "appServer" | { "subAgent": SubAgentSource } | "unknown";
|
||||
|
||||
@@ -1382,6 +1382,7 @@ pub enum SessionSource {
|
||||
#[default]
|
||||
VsCode,
|
||||
Exec,
|
||||
Acp,
|
||||
AppServer,
|
||||
SubAgent(CoreSubAgentSource),
|
||||
#[serde(other)]
|
||||
@@ -1394,6 +1395,7 @@ impl From<CoreSessionSource> for SessionSource {
|
||||
CoreSessionSource::Cli => SessionSource::Cli,
|
||||
CoreSessionSource::VSCode => SessionSource::VsCode,
|
||||
CoreSessionSource::Exec => SessionSource::Exec,
|
||||
CoreSessionSource::Acp => SessionSource::Acp,
|
||||
CoreSessionSource::Mcp => SessionSource::AppServer,
|
||||
CoreSessionSource::SubAgent(sub) => SessionSource::SubAgent(sub),
|
||||
CoreSessionSource::Unknown => SessionSource::Unknown,
|
||||
@@ -1407,6 +1409,7 @@ impl From<SessionSource> for CoreSessionSource {
|
||||
SessionSource::Cli => CoreSessionSource::Cli,
|
||||
SessionSource::VsCode => CoreSessionSource::VSCode,
|
||||
SessionSource::Exec => CoreSessionSource::Exec,
|
||||
SessionSource::Acp => CoreSessionSource::Acp,
|
||||
SessionSource::AppServer => CoreSessionSource::Mcp,
|
||||
SessionSource::SubAgent(sub) => CoreSessionSource::SubAgent(sub),
|
||||
SessionSource::Unknown => CoreSessionSource::Unknown,
|
||||
|
||||
@@ -22,6 +22,7 @@ clap_complete = { workspace = true }
|
||||
codex-app-server = { workspace = true }
|
||||
codex-app-server-protocol = { workspace = true }
|
||||
codex-app-server-test-client = { workspace = true }
|
||||
codex-acp-server = { workspace = true }
|
||||
codex-arg0 = { workspace = true }
|
||||
codex-chatgpt = { workspace = true }
|
||||
codex-cloud-tasks = { path = "../cloud-tasks" }
|
||||
|
||||
@@ -102,6 +102,9 @@ enum Subcommand {
|
||||
/// Start Codex as an MCP server (stdio).
|
||||
McpServer,
|
||||
|
||||
/// Start Codex as an ACP server (stdio).
|
||||
AcpServer,
|
||||
|
||||
/// [experimental] Run the app server or related tooling.
|
||||
AppServer(AppServerCommand),
|
||||
|
||||
@@ -597,6 +600,9 @@ async fn cli_main(arg0_paths: Arg0DispatchPaths) -> anyhow::Result<()> {
|
||||
Some(Subcommand::McpServer) => {
|
||||
codex_mcp_server::run_main(arg0_paths.clone(), root_config_overrides).await?;
|
||||
}
|
||||
Some(Subcommand::AcpServer) => {
|
||||
codex_acp_server::run_main(arg0_paths.clone(), root_config_overrides).await?;
|
||||
}
|
||||
Some(Subcommand::Mcp(mut mcp_cli)) => {
|
||||
// Propagate any root-level config overrides (e.g. `-c key=value`).
|
||||
prepend_config_flags(&mut mcp_cli.config_overrides, root_config_overrides.clone());
|
||||
@@ -1207,6 +1213,14 @@ mod tests {
|
||||
app_server
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_acp_server_subcommand() {
|
||||
let cli = MultitoolCli::try_parse_from(["codex", "acp-server"]).expect("parse");
|
||||
let Some(Subcommand::AcpServer) = cli.subcommand else {
|
||||
panic!("expected acp-server subcommand");
|
||||
};
|
||||
}
|
||||
|
||||
fn sample_exit_info(conversation_id: Option<&str>, thread_name: Option<&str>) -> AppExitInfo {
|
||||
let token_usage = TokenUsage {
|
||||
output_tokens: 2,
|
||||
|
||||
@@ -426,6 +426,10 @@ async fn run_list(config_overrides: &CliConfigOverrides, list_args: ListArgs) ->
|
||||
.map(|entry| entry.auth_status)
|
||||
.unwrap_or(McpAuthStatus::Unsupported);
|
||||
let transport = match &cfg.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => serde_json::json!({
|
||||
"type": "acp",
|
||||
"id": id,
|
||||
}),
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
@@ -482,10 +486,20 @@ async fn run_list(config_overrides: &CliConfigOverrides, list_args: ListArgs) ->
|
||||
}
|
||||
|
||||
let mut stdio_rows: Vec<[String; 7]> = Vec::new();
|
||||
let mut acp_rows: Vec<[String; 4]> = Vec::new();
|
||||
let mut http_rows: Vec<[String; 5]> = Vec::new();
|
||||
|
||||
for (name, cfg) in entries {
|
||||
match &cfg.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => {
|
||||
let status = format_mcp_status(cfg);
|
||||
let auth_status = auth_statuses
|
||||
.get(name.as_str())
|
||||
.map(|entry| entry.auth_status)
|
||||
.unwrap_or(McpAuthStatus::Unsupported)
|
||||
.to_string();
|
||||
acp_rows.push([name.clone(), id.clone(), status, auth_status]);
|
||||
}
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
@@ -603,6 +617,45 @@ async fn run_list(config_overrides: &CliConfigOverrides, list_args: ListArgs) ->
|
||||
println!();
|
||||
}
|
||||
|
||||
if !acp_rows.is_empty() {
|
||||
let mut widths = ["Name".len(), "ACP Id".len(), "Status".len(), "Auth".len()];
|
||||
for row in &acp_rows {
|
||||
for (i, cell) in row.iter().enumerate() {
|
||||
widths[i] = widths[i].max(cell.len());
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"{name:<name_w$} {id:<id_w$} {status:<status_w$} {auth:<auth_w$}",
|
||||
name = "Name",
|
||||
id = "ACP Id",
|
||||
status = "Status",
|
||||
auth = "Auth",
|
||||
name_w = widths[0],
|
||||
id_w = widths[1],
|
||||
status_w = widths[2],
|
||||
auth_w = widths[3],
|
||||
);
|
||||
|
||||
for row in &acp_rows {
|
||||
println!(
|
||||
"{name:<name_w$} {id:<id_w$} {status:<status_w$} {auth:<auth_w$}",
|
||||
name = row[0].as_str(),
|
||||
id = row[1].as_str(),
|
||||
status = row[2].as_str(),
|
||||
auth = row[3].as_str(),
|
||||
name_w = widths[0],
|
||||
id_w = widths[1],
|
||||
status_w = widths[2],
|
||||
auth_w = widths[3],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!stdio_rows.is_empty() || !acp_rows.is_empty()) && !http_rows.is_empty() {
|
||||
println!();
|
||||
}
|
||||
|
||||
if !http_rows.is_empty() {
|
||||
let mut widths = [
|
||||
"Name".len(),
|
||||
@@ -667,6 +720,10 @@ async fn run_get(config_overrides: &CliConfigOverrides, get_args: GetArgs) -> Re
|
||||
|
||||
if get_args.json {
|
||||
let transport = match &server.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => serde_json::json!({
|
||||
"type": "acp",
|
||||
"id": id,
|
||||
}),
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
@@ -739,6 +796,10 @@ async fn run_get(config_overrides: &CliConfigOverrides, get_args: GetArgs) -> Re
|
||||
println!(" disabled_tools: {disabled_tools_display}");
|
||||
}
|
||||
match &server.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => {
|
||||
println!(" transport: acp");
|
||||
println!(" id: {id}");
|
||||
}
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
|
||||
@@ -1245,6 +1245,10 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"id": {
|
||||
"default": null,
|
||||
"type": "string"
|
||||
},
|
||||
"oauth_resource": {
|
||||
"default": null,
|
||||
"type": "string"
|
||||
@@ -1276,6 +1280,10 @@
|
||||
"format": "double",
|
||||
"type": "number"
|
||||
},
|
||||
"transport": {
|
||||
"default": null,
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
@@ -147,6 +147,10 @@ mod document_helpers {
|
||||
entry.set_implicit(false);
|
||||
|
||||
match &config.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => {
|
||||
entry["transport"] = value("acp");
|
||||
entry["id"] = value(id.clone());
|
||||
}
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
|
||||
@@ -111,6 +111,11 @@ pub struct McpServerConfig {
|
||||
#[derive(Deserialize, Clone, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub(crate) struct RawMcpServerConfig {
|
||||
#[serde(default)]
|
||||
pub transport: Option<String>,
|
||||
#[serde(default)]
|
||||
pub id: Option<String>,
|
||||
|
||||
// stdio
|
||||
pub command: Option<String>,
|
||||
#[serde(default)]
|
||||
@@ -187,7 +192,31 @@ impl<'de> Deserialize<'de> for McpServerConfig {
|
||||
)))
|
||||
}
|
||||
|
||||
let transport = if let Some(command) = raw.command.clone() {
|
||||
let transport = if raw.transport.as_deref() == Some("acp") || raw.id.is_some() {
|
||||
throw_if_set("acp", "command", raw.command.as_ref())?;
|
||||
throw_if_set("acp", "args", raw.args.as_ref())?;
|
||||
throw_if_set("acp", "env", raw.env.as_ref())?;
|
||||
throw_if_set("acp", "env_vars", raw.env_vars.as_ref())?;
|
||||
throw_if_set("acp", "cwd", raw.cwd.as_ref())?;
|
||||
throw_if_set("acp", "url", raw.url.as_ref())?;
|
||||
throw_if_set(
|
||||
"acp",
|
||||
"bearer_token_env_var",
|
||||
raw.bearer_token_env_var.as_ref(),
|
||||
)?;
|
||||
throw_if_set("acp", "bearer_token", raw.bearer_token.as_ref())?;
|
||||
throw_if_set("acp", "http_headers", raw.http_headers.as_ref())?;
|
||||
throw_if_set("acp", "env_http_headers", raw.env_http_headers.as_ref())?;
|
||||
let acp_id = raw
|
||||
.id
|
||||
.clone()
|
||||
.filter(|id| !id.is_empty())
|
||||
.ok_or_else(|| SerdeError::custom("acp transport requires non-empty id"))?;
|
||||
McpServerTransportConfig::Acp {
|
||||
transport: "acp".to_string(),
|
||||
id: acp_id,
|
||||
}
|
||||
} else if let Some(command) = raw.command.clone() {
|
||||
throw_if_set("stdio", "url", raw.url.as_ref())?;
|
||||
throw_if_set(
|
||||
"stdio",
|
||||
@@ -243,6 +272,8 @@ const fn default_enabled() -> bool {
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
|
||||
#[serde(untagged, deny_unknown_fields, rename_all = "snake_case")]
|
||||
pub enum McpServerTransportConfig {
|
||||
/// ACP draft MCP-over-ACP transport.
|
||||
Acp { transport: String, id: String },
|
||||
/// https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#stdio
|
||||
Stdio {
|
||||
command: String,
|
||||
|
||||
@@ -92,6 +92,7 @@ async fn compute_auth_status(
|
||||
store_mode: OAuthCredentialsStoreMode,
|
||||
) -> Result<McpAuthStatus> {
|
||||
match &config.transport {
|
||||
McpServerTransportConfig::Acp { .. } => Ok(McpAuthStatus::Unsupported),
|
||||
McpServerTransportConfig::Stdio { .. } => Ok(McpAuthStatus::Unsupported),
|
||||
McpServerTransportConfig::StreamableHttp {
|
||||
url,
|
||||
|
||||
@@ -284,6 +284,7 @@ fn canonical_mcp_key(transport: &str, identifier: &str, fallback: &str) -> Strin
|
||||
|
||||
fn canonical_mcp_server_key(name: &str, config: &McpServerConfig) -> String {
|
||||
match &config.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => canonical_mcp_key("acp", id, name),
|
||||
McpServerTransportConfig::Stdio { command, .. } => {
|
||||
canonical_mcp_key("stdio", command, name)
|
||||
}
|
||||
|
||||
@@ -1439,6 +1439,9 @@ async fn make_rmcp_client(
|
||||
.await
|
||||
.map_err(StartupOutcomeError::from)
|
||||
}
|
||||
McpServerTransportConfig::Acp { id, .. } => RmcpClient::new_acp_client(id)
|
||||
.await
|
||||
.map_err(StartupOutcomeError::from),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1549,6 +1552,7 @@ fn transport_origin(transport: &McpServerTransportConfig) -> Option<String> {
|
||||
let parsed = Url::parse(url).ok()?;
|
||||
Some(parsed.origin().ascii_serialization())
|
||||
}
|
||||
McpServerTransportConfig::Acp { id, .. } => Some(format!("acp:{id}")),
|
||||
McpServerTransportConfig::Stdio { .. } => Some("stdio".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2191,6 +2191,7 @@ pub enum SessionSource {
|
||||
#[default]
|
||||
VSCode,
|
||||
Exec,
|
||||
Acp,
|
||||
Mcp,
|
||||
SubAgent(SubAgentSource),
|
||||
#[serde(other)]
|
||||
@@ -2221,6 +2222,7 @@ impl fmt::Display for SessionSource {
|
||||
SessionSource::Cli => f.write_str("cli"),
|
||||
SessionSource::VSCode => f.write_str("vscode"),
|
||||
SessionSource::Exec => f.write_str("exec"),
|
||||
SessionSource::Acp => f.write_str("acp"),
|
||||
SessionSource::Mcp => f.write_str("mcp"),
|
||||
SessionSource::SubAgent(sub_source) => write!(f, "subagent_{sub_source}"),
|
||||
SessionSource::Unknown => f.write_str("unknown"),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::RwLock;
|
||||
|
||||
use anyhow::Result;
|
||||
use futures::future::BoxFuture;
|
||||
use rmcp::model::ClientJsonRpcMessage;
|
||||
use rmcp::model::ServerJsonRpcMessage;
|
||||
|
||||
pub trait AcpConnection: Send + Sync + 'static {
|
||||
fn send(&self, message: ClientJsonRpcMessage) -> BoxFuture<'static, Result<()>>;
|
||||
fn recv(&self) -> BoxFuture<'static, Result<Option<ServerJsonRpcMessage>>>;
|
||||
fn close(&self) -> BoxFuture<'static, Result<()>>;
|
||||
}
|
||||
|
||||
pub trait AcpBridge: Send + Sync + 'static {
|
||||
fn connect(&self, acp_id: String) -> BoxFuture<'static, Result<Arc<dyn AcpConnection>>>;
|
||||
}
|
||||
|
||||
static ACP_BRIDGE: LazyLock<RwLock<Option<Arc<dyn AcpBridge>>>> =
|
||||
LazyLock::new(|| RwLock::new(None));
|
||||
|
||||
pub fn set_acp_bridge(bridge: Option<Arc<dyn AcpBridge>>) {
|
||||
let mut slot = ACP_BRIDGE
|
||||
.write()
|
||||
.unwrap_or_else(|_| panic!("ACP bridge registry poisoned"));
|
||||
*slot = bridge;
|
||||
}
|
||||
|
||||
pub(crate) fn get_acp_bridge() -> Result<Arc<dyn AcpBridge>> {
|
||||
ACP_BRIDGE
|
||||
.read()
|
||||
.unwrap_or_else(|_| panic!("ACP bridge registry poisoned"))
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::anyhow!("ACP MCP bridge is not installed"))
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod acp_bridge;
|
||||
mod auth_status;
|
||||
mod logging_client_handler;
|
||||
mod oauth;
|
||||
@@ -6,6 +7,9 @@ mod program_resolver;
|
||||
mod rmcp_client;
|
||||
mod utils;
|
||||
|
||||
pub use acp_bridge::AcpBridge;
|
||||
pub use acp_bridge::AcpConnection;
|
||||
pub use acp_bridge::set_acp_bridge;
|
||||
pub use auth_status::determine_streamable_http_auth_status;
|
||||
pub use auth_status::supports_oauth_login;
|
||||
pub use codex_protocol::protocol::McpAuthStatus;
|
||||
|
||||
@@ -53,6 +53,11 @@ use rmcp::transport::streamable_http_client::StreamableHttpClient;
|
||||
use rmcp::transport::streamable_http_client::StreamableHttpClientTransportConfig;
|
||||
use rmcp::transport::streamable_http_client::StreamableHttpError;
|
||||
use rmcp::transport::streamable_http_client::StreamableHttpPostResponse;
|
||||
use rmcp::transport::worker::Worker;
|
||||
use rmcp::transport::worker::WorkerConfig;
|
||||
use rmcp::transport::worker::WorkerContext;
|
||||
use rmcp::transport::worker::WorkerQuitReason;
|
||||
use rmcp::transport::worker::WorkerTransport;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
@@ -66,6 +71,8 @@ use tokio::time;
|
||||
use tracing::info;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::acp_bridge::AcpConnection;
|
||||
use crate::acp_bridge::get_acp_bridge;
|
||||
use crate::load_oauth_tokens;
|
||||
use crate::logging_client_handler::LoggingClientHandler;
|
||||
use crate::oauth::OAuthCredentialsStoreMode;
|
||||
@@ -295,6 +302,84 @@ impl StreamableHttpClient for StreamableHttpResponseClient {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum AcpTransportError {
|
||||
#[error("ACP transport bridge is closed")]
|
||||
Closed,
|
||||
#[error("ACP transport join failed: {0}")]
|
||||
Join(#[source] tokio::task::JoinError),
|
||||
#[error(transparent)]
|
||||
Bridge(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
struct AcpTransportWorker {
|
||||
connection: Arc<dyn AcpConnection>,
|
||||
}
|
||||
|
||||
impl Worker for AcpTransportWorker {
|
||||
type Error = AcpTransportError;
|
||||
type Role = RoleClient;
|
||||
|
||||
fn err_closed() -> Self::Error {
|
||||
AcpTransportError::Closed
|
||||
}
|
||||
|
||||
fn err_join(error: tokio::task::JoinError) -> Self::Error {
|
||||
AcpTransportError::Join(error)
|
||||
}
|
||||
|
||||
fn config(&self) -> WorkerConfig {
|
||||
WorkerConfig {
|
||||
name: Some("mcp_acp_transport".to_string()),
|
||||
channel_buffer_capacity: 32,
|
||||
}
|
||||
}
|
||||
|
||||
async fn run(
|
||||
self,
|
||||
mut context: WorkerContext<Self>,
|
||||
) -> Result<(), WorkerQuitReason<Self::Error>> {
|
||||
let cancellation_token = context.cancellation_token.clone();
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = cancellation_token.cancelled() => {
|
||||
self.connection
|
||||
.close()
|
||||
.await
|
||||
.map_err(AcpTransportError::from)
|
||||
.map_err(WorkerQuitReason::fatal_context("closing ACP transport"))?;
|
||||
return Err(WorkerQuitReason::Cancelled);
|
||||
}
|
||||
incoming = self.connection.recv() => {
|
||||
match incoming
|
||||
.map_err(AcpTransportError::from)
|
||||
.map_err(WorkerQuitReason::fatal_context("receiving ACP MCP message"))?
|
||||
{
|
||||
Some(message) => context.send_to_handler(message).await?,
|
||||
None => return Err(WorkerQuitReason::TransportClosed),
|
||||
}
|
||||
}
|
||||
outbound = context.recv_from_handler() => {
|
||||
let outbound = outbound?;
|
||||
let send_result = self.connection
|
||||
.send(outbound.message)
|
||||
.await
|
||||
.map_err(AcpTransportError::from);
|
||||
match send_result {
|
||||
Ok(()) => {
|
||||
let _ = outbound.responder.send(Ok(()));
|
||||
}
|
||||
Err(error) => {
|
||||
let _ = outbound.responder.send(Err(AcpTransportError::Closed));
|
||||
return Err(WorkerQuitReason::fatal(error, "sending ACP MCP message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PendingTransport {
|
||||
ChildProcess {
|
||||
transport: TokioChildProcess,
|
||||
@@ -307,6 +392,9 @@ enum PendingTransport {
|
||||
transport: StreamableHttpClientTransport<AuthClient<StreamableHttpResponseClient>>,
|
||||
oauth_persistor: OAuthPersistor,
|
||||
},
|
||||
Acp {
|
||||
transport: WorkerTransport<AcpTransportWorker>,
|
||||
},
|
||||
}
|
||||
|
||||
enum ClientState {
|
||||
@@ -396,6 +484,9 @@ enum TransportRecipe {
|
||||
env_http_headers: Option<HashMap<String, String>>,
|
||||
store_mode: OAuthCredentialsStoreMode,
|
||||
},
|
||||
Acp {
|
||||
acp_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -524,6 +615,19 @@ impl RmcpClient {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn new_acp_client(acp_id: String) -> Result<Self> {
|
||||
let transport_recipe = TransportRecipe::Acp { acp_id };
|
||||
let transport = Self::create_pending_transport(&transport_recipe).await?;
|
||||
Ok(Self {
|
||||
state: Mutex::new(ClientState::Connecting {
|
||||
transport: Some(transport),
|
||||
}),
|
||||
transport_recipe,
|
||||
initialize_context: Mutex::new(None),
|
||||
session_recovery_lock: Mutex::new(()),
|
||||
})
|
||||
}
|
||||
|
||||
/// Perform the initialization handshake with the MCP server.
|
||||
/// https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#initialization
|
||||
pub async fn initialize(
|
||||
@@ -947,6 +1051,13 @@ impl RmcpClient {
|
||||
Ok(PendingTransport::StreamableHttp { transport })
|
||||
}
|
||||
}
|
||||
TransportRecipe::Acp { acp_id } => {
|
||||
let bridge = get_acp_bridge()?;
|
||||
let connection = bridge.connect(acp_id.clone()).await?;
|
||||
Ok(PendingTransport::Acp {
|
||||
transport: WorkerTransport::spawn(AcpTransportWorker { connection }),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,6 +1092,11 @@ impl RmcpClient {
|
||||
Some(oauth_persistor),
|
||||
None,
|
||||
),
|
||||
PendingTransport::Acp { transport } => (
|
||||
service::serve_client(client_handler, transport).boxed(),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
};
|
||||
|
||||
let service = match timeout {
|
||||
@@ -1163,3 +1279,145 @@ async fn create_oauth_transport_and_runtime(
|
||||
|
||||
Ok((transport, runtime))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rmcp::model::ClientCapabilities;
|
||||
use rmcp::model::ClientJsonRpcMessage;
|
||||
use rmcp::model::ClientRequest;
|
||||
use rmcp::model::Implementation;
|
||||
use rmcp::model::InitializeRequestParams;
|
||||
use rmcp::model::InitializeResult;
|
||||
use rmcp::model::JsonRpcRequest;
|
||||
use rmcp::model::JsonRpcResponse;
|
||||
use rmcp::model::ListToolsResult;
|
||||
use rmcp::model::ProtocolVersion;
|
||||
use rmcp::model::ServerCapabilities;
|
||||
use rmcp::model::ServerJsonRpcMessage;
|
||||
use rmcp::model::ServerResult;
|
||||
use serial_test::serial;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
struct FakeAcpBridge {
|
||||
connection: Arc<FakeAcpConnection>,
|
||||
}
|
||||
|
||||
impl crate::AcpBridge for FakeAcpBridge {
|
||||
fn connect(
|
||||
&self,
|
||||
_acp_id: String,
|
||||
) -> BoxFuture<'static, Result<Arc<dyn crate::AcpConnection>>> {
|
||||
let connection = Arc::clone(&self.connection);
|
||||
Box::pin(async move { Ok(connection as Arc<dyn crate::AcpConnection>) })
|
||||
}
|
||||
}
|
||||
|
||||
struct FakeAcpConnection {
|
||||
inbound_tx: mpsc::UnboundedSender<ServerJsonRpcMessage>,
|
||||
inbound_rx: Arc<tokio::sync::Mutex<mpsc::UnboundedReceiver<ServerJsonRpcMessage>>>,
|
||||
}
|
||||
|
||||
impl crate::AcpConnection for FakeAcpConnection {
|
||||
fn send(&self, message: ClientJsonRpcMessage) -> BoxFuture<'static, Result<()>> {
|
||||
let inbound_tx = self.inbound_tx.clone();
|
||||
Box::pin(async move {
|
||||
if let ClientJsonRpcMessage::Request(JsonRpcRequest { id, request, .. }) = message {
|
||||
match request {
|
||||
ClientRequest::InitializeRequest(_) => inbound_tx
|
||||
.send(ServerJsonRpcMessage::Response(JsonRpcResponse {
|
||||
jsonrpc: rmcp::model::JsonRpcVersion2_0,
|
||||
id,
|
||||
result: ServerResult::InitializeResult(InitializeResult {
|
||||
protocol_version: ProtocolVersion::default(),
|
||||
capabilities: ServerCapabilities::builder()
|
||||
.enable_tools()
|
||||
.build(),
|
||||
server_info: Implementation {
|
||||
name: "fake-acp".to_string(),
|
||||
version: "0.0.0".to_string(),
|
||||
title: None,
|
||||
description: None,
|
||||
icons: None,
|
||||
website_url: None,
|
||||
},
|
||||
instructions: None,
|
||||
}),
|
||||
}))
|
||||
.map_err(|_| anyhow!("failed to enqueue initialize response"))?,
|
||||
ClientRequest::ListToolsRequest(_) => inbound_tx
|
||||
.send(ServerJsonRpcMessage::Response(JsonRpcResponse {
|
||||
jsonrpc: rmcp::model::JsonRpcVersion2_0,
|
||||
id,
|
||||
result: ServerResult::ListToolsResult(ListToolsResult {
|
||||
tools: Vec::new(),
|
||||
next_cursor: None,
|
||||
meta: None,
|
||||
}),
|
||||
}))
|
||||
.map_err(|_| anyhow!("failed to enqueue tools response"))?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn recv(&self) -> BoxFuture<'static, Result<Option<ServerJsonRpcMessage>>> {
|
||||
let inbound_rx = Arc::clone(&self.inbound_rx);
|
||||
Box::pin(async move { Ok(inbound_rx.lock().await.recv().await) })
|
||||
}
|
||||
|
||||
fn close(&self) -> BoxFuture<'static, Result<()>> {
|
||||
Box::pin(async { Ok(()) })
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn acp_transport_initializes_and_lists_tools() {
|
||||
let (inbound_tx, inbound_rx) = mpsc::unbounded_channel();
|
||||
crate::set_acp_bridge(Some(Arc::new(FakeAcpBridge {
|
||||
connection: Arc::new(FakeAcpConnection {
|
||||
inbound_tx,
|
||||
inbound_rx: Arc::new(tokio::sync::Mutex::new(inbound_rx)),
|
||||
}),
|
||||
})));
|
||||
|
||||
let client = RmcpClient::new_acp_client("srv-123".to_string())
|
||||
.await
|
||||
.expect("ACP client should initialize");
|
||||
let send_elicitation: SendElicitation =
|
||||
Box::new(|_, _| async { anyhow::bail!("elicitation should be unused") }.boxed());
|
||||
|
||||
let initialize_result = client
|
||||
.initialize(
|
||||
InitializeRequestParams {
|
||||
meta: None,
|
||||
protocol_version: ProtocolVersion::default(),
|
||||
capabilities: ClientCapabilities::default(),
|
||||
client_info: Implementation {
|
||||
name: "test-client".to_string(),
|
||||
version: "0.0.0".to_string(),
|
||||
title: None,
|
||||
description: None,
|
||||
icons: None,
|
||||
website_url: None,
|
||||
},
|
||||
},
|
||||
None,
|
||||
send_elicitation,
|
||||
)
|
||||
.await
|
||||
.expect("initialize should succeed");
|
||||
let tools = client
|
||||
.list_tools(None, None)
|
||||
.await
|
||||
.expect("tools/list should succeed");
|
||||
|
||||
assert_eq!(initialize_result.server_info.name, "fake-acp");
|
||||
assert_eq!(tools.tools, Vec::new());
|
||||
crate::set_acp_bridge(None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1767,6 +1767,9 @@ pub(crate) fn new_mcp_tools_output(
|
||||
lines.push(vec![" • Auth: ".into(), auth_status.to_string().into()].into());
|
||||
|
||||
match &cfg.transport {
|
||||
McpServerTransportConfig::Acp { id, .. } => {
|
||||
lines.push(vec![" • ACP Id: ".into(), id.clone().into()].into());
|
||||
}
|
||||
McpServerTransportConfig::Stdio {
|
||||
command,
|
||||
args,
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
# Add Native ACP Support to Codex
|
||||
|
||||
This ExecPlan is a living document. Keep the sections Progress, Surprises & Discoveries, Decision Log, and Outcomes & Retrospective up to date as work proceeds.
|
||||
|
||||
No repo-specific `docs/PLANS.md` policy exists as of 2026-03-10, so this plan follows the shared ExecPlan template.
|
||||
|
||||
## Purpose / Big Picture
|
||||
|
||||
Add native Agent Client Protocol (ACP) support to Codex so ACP-aware editors and clients can drive Codex without a bespoke integration. The intended end state is a thin ACP adapter over the existing app-server v2/runtime stack, preserving current thread/turn/item semantics, approvals, and streaming behavior instead of creating a second direct integration into `codex-core`.
|
||||
|
||||
Someone can see this working when an ACP client can:
|
||||
|
||||
- `initialize` successfully and negotiate capabilities.
|
||||
- create or load a session backed by a Codex thread.
|
||||
- send `session/prompt` and receive streamed `session/update` notifications.
|
||||
- handle permission/interactivity flows without losing parity with current app-server behavior.
|
||||
- cancel or resume sessions without hanging or duplicating state.
|
||||
|
||||
## Progress
|
||||
|
||||
- [x] (2026-03-10 14:23Z) Completed initial discovery across ACP docs, app-server/app-server-protocol/mcp-server, and likely stakeholder surfaces.
|
||||
- [x] (2026-03-10 20:31Z) Prototyped a native ACP adapter crate and CLI entrypoint as `codex acp-server`.
|
||||
- [x] (2026-03-10 23:18Z) Added ACP session modes/config options, `session/set_mode`, stdio+HTTP `mcpServers` passthrough via request config overrides, text/image resource prompt support, and a distinct `SessionSource::Acp`.
|
||||
- [x] (2026-03-10 23:18Z) Added local ACP transcript coverage for `initialize`, `session/new`, and `session/set_mode`.
|
||||
- [ ] Flesh out the ACP-to-app-server v2 mapping table in the plan doc with the concrete implementation decisions now in code.
|
||||
- [x] Add focused ACP integration tests that exercise stdio JSON-RPC flows against the in-process runtime.
|
||||
- [x] Implement `session/set_mode` support instead of returning not implemented.
|
||||
- [ ] Replace the current `mcpServers` stdio+HTTP passthrough with MCP-over-ACP session wiring for ACP-transport servers or make the unsupported capability boundary explicit in initialize.
|
||||
- [x] Consider adding a distinct `SessionSource::Acp` once we are ready to pay the shared-protocol validation cost.
|
||||
- [ ] Draft the ACP-to-app-server v2 mapping table and record protocol gaps, including `session/load`, `session/request_permission`, `session/set_mode`, and MCP-over-ACP.
|
||||
- [ ] Decide whether to adopt the official ACP Rust SDK or a smaller transport-only adapter.
|
||||
- [ ] Implement and validate stable-core ACP compliance.
|
||||
- [ ] Implement and validate extended ACP support for session replay, modes, and MCP-over-ACP.
|
||||
- [ ] Build interop coverage and documentation against official ACP SDKs/examples.
|
||||
|
||||
## Surprises & Discoveries
|
||||
|
||||
- Observation: `codex-app-server` already exposes nearly all of the interaction primitives ACP needs: lifecycle, streaming notifications, server-initiated approval requests, tool user-input requests, and MCP elicitation requests. Evidence: `codex-rs/app-server/README.md`, `codex-rs/app-server/src/bespoke_event_handling.rs`, `codex-rs/app-server-protocol/src/protocol/common.rs`.
|
||||
- Observation: local embedders already reuse app-server semantics through the in-process runtime and `codex-app-server-client` instead of reaching into `core` directly. Evidence: `codex-rs/app-server/src/in_process.rs`, `codex-rs/app-server-client/src/lib.rs`.
|
||||
- Observation: `codex-mcp-server` is prior art for an adapter layer, but it constructs its own `ThreadManager`, which is probably the wrong long-term pattern for a new native rich-client protocol. Evidence: `codex-rs/mcp-server/src/message_processor.rs`.
|
||||
- Observation: ACP's stable core is JSON-RPC 2.0 with `initialize`, `session/new`, `session/prompt`, `session/cancel`, and `session/update`; `session/load` and `session/set_mode` are optional capabilities. Evidence: ACP docs in `initialization`, `session-setup`, and `session-modes` from `/agentclientprotocol/agent-client-protocol` via Context7.
|
||||
- Observation: ACP includes client-advertised filesystem and terminal capabilities plus agent-driven `session/request_permission`, which overlap strongly with Codex approvals and `tool/requestUserInput`, but not one-to-one. Evidence: ACP docs in `initialization` and `tool-calls` from `/agentclientprotocol/agent-client-protocol` via Context7.
|
||||
- Observation: ACP session loading is stronger than a simple resume. If Codex advertises `loadSession`, ACP expects replay via `session/update` before returning. Evidence: ACP `session-setup` docs from `/agentclientprotocol/agent-client-protocol` via Context7.
|
||||
- Observation: I did not find an official ACP-wide conformance suite in the official docs I queried. The closest official validation assets are the Rust and TypeScript SDKs, their examples, and SDK test helpers. This is an inference from the available docs, not a guarantee that no such suite exists elsewhere. Evidence: ACP docs in `libraries/rust`, `libraries/typescript`, and `rust-sdk-v1` from `/agentclientprotocol/agent-client-protocol` via Context7.
|
||||
- Observation: the current app-server API collapses `CoreSessionSource::Mcp` into API `SessionSource::AppServer`, so ACP likely needs its own session source if we want clean analytics/compliance attribution. Evidence: `codex-rs/app-server-protocol/src/protocol/v2.rs`.
|
||||
- Observation: ACP richer elicitation and several session-management capabilities are still evolving via RFDs, so the implementation should separate stable compliance from draft/extended support. Evidence: ACP `elicitation`, `session-stop`, `session-info-update`, and `mcp-over-acp` RFDs from `/agentclientprotocol/agent-client-protocol` and subagent research.
|
||||
|
||||
## Decision Log
|
||||
|
||||
- Decision: plan around an ACP adapter layered on top of app-server v2 rather than a new direct `core` integration. Rationale: app-server already owns the stable rich-client contract, state management, approvals, and backpressure. Date/Author: 2026-03-10 / Codex.
|
||||
- Decision: treat `codex-app-server-client` as the preferred internal seam for a native ACP implementation. Rationale: it preserves app-server semantics while avoiding a second process boundary and already supports typed requests plus server-request resolution. Date/Author: 2026-03-10 / Codex.
|
||||
- Decision: engage app-server owners first, especially Owen Lin, with Michael Bolin and Celia Chen as key follow-ups for runtime-contract stability and interactivity. Rationale: git history and doc ownership point there more strongly than any formal `CODEOWNERS` file. Date/Author: 2026-03-10 / Codex.
|
||||
- Decision: explicitly split delivery into stable-core ACP compliance and extended ACP support for evolving features. Rationale: this lets Codex make a credible compliance claim for the stable protocol while still planning for draft features like richer elicitation and broader session management. Date/Author: 2026-03-10 / Codex.
|
||||
|
||||
## Outcomes & Retrospective
|
||||
|
||||
The first implementation slice is now in place:
|
||||
|
||||
- a new `codex-rs/acp-server` crate starts the in-process app-server runtime through `codex-app-server-client`.
|
||||
- `codex acp-server` is wired as a new CLI entrypoint.
|
||||
- the adapter handles ACP `initialize`, `session/new`, `session/load`, `session/prompt`, `session/cancel`, and `session/set_mode`.
|
||||
- app-server notifications are translated into ACP `session/update` events for agent text, plans, command/file tool calls, and tool call completion updates.
|
||||
- app-server approval requests for command execution and file changes are translated into ACP `session/request_permission`.
|
||||
- ACP session setup now returns modes plus config options for mode/model/thought level derived from app-server collaboration mode and model APIs.
|
||||
- ACP `mcpServers` declarations are now translated into Codex config overrides for stdio and streamable HTTP MCP servers.
|
||||
- ACP text resources and image resources can now be converted into Codex input items, so the adapter advertises embedded-context and image prompt support.
|
||||
- ACP sessions are now recorded with a distinct `SessionSource::Acp`, and app-server schema fixtures were regenerated accordingly.
|
||||
- local transcript coverage now exercises `initialize`, `session/new`, and `session/set_mode` against the real stdio server binary.
|
||||
|
||||
Current known gaps after the first slice:
|
||||
|
||||
- ACP transport MCP servers from the MCP-over-ACP RFD are still rejected; only stdio and HTTP declarations are currently translated.
|
||||
- richer elicitation remains unsupported because ACP `session/request_permission` cannot carry MCP form/URL elicitation content; unsupported server requests are still rejected back to app-server.
|
||||
- compliance is still demonstrated only with local crate/unit/protocol/CLI tests, not official ACP SDK counterpart interop.
|
||||
|
||||
The main remaining unknowns are whether the official ACP Rust SDK fits cleanly into Codex's runtime architecture, how far to go on MCP-over-ACP in the first user-facing milestone, and whether a distinct ACP session source should be introduced in the shared protocol soon or deferred until the adapter semantics settle.
|
||||
|
||||
## Context and Orientation
|
||||
|
||||
The most relevant local layers are:
|
||||
|
||||
- `codex-rs/app-server-protocol/src/protocol/common.rs`
|
||||
Defines the JSON-RPC request, server request, and notification surface for app-server v2, including approval, tool-input, and elicitation requests.
|
||||
- `codex-rs/app-server-protocol/src/protocol/v2.rs`
|
||||
Defines the typed v2 payloads and session/thread metadata exposed over app-server.
|
||||
- `codex-rs/app-server/src/message_processor.rs`
|
||||
Owns initialization, capability gating, and dispatch for app-server requests.
|
||||
- `codex-rs/app-server/src/bespoke_event_handling.rs`
|
||||
Translates core runtime events into app-server notifications and server requests. This is where user-input, approval, and MCP elicitation flows are already bridged.
|
||||
- `codex-rs/app-server/src/in_process.rs`
|
||||
Hosts the app-server runtime in-process with bounded queues and server-request reply plumbing.
|
||||
- `codex-rs/app-server-client/src/lib.rs`
|
||||
Provides the reusable in-process client facade that TUI and exec already use.
|
||||
- `codex-rs/mcp-server/src/message_processor.rs`
|
||||
Shows how a protocol adapter can sit above the shared runtime, but also shows the maintenance cost of duplicating lifecycle handling.
|
||||
- `codex-rs/app-server/tests/suite/v2/`
|
||||
Provides the best existing model for request/notification regression coverage.
|
||||
- `codex-rs/app-server-test-client/src/lib.rs`
|
||||
Provides a practical harness for app-server transport tests and scripted interaction flows.
|
||||
- `codex-rs/cli/src/main.rs`
|
||||
Defines top-level CLI entrypoints; ACP support will likely need a new subcommand or server mode here.
|
||||
|
||||
Relevant ACP concepts:
|
||||
|
||||
- `initialize` negotiates protocol version plus client and agent capabilities.
|
||||
- `session/new` and optional `session/load` establish or resume a conversation.
|
||||
- `session/prompt` and `session/cancel` drive one user turn and interrupt it.
|
||||
- `session/update` streams agent message chunks, plan updates, tool activity, diffs, and mode changes.
|
||||
- `session/request_permission` asks the client to surface approval options and return a user choice.
|
||||
- `session/set_mode` is optional and adjacent to Codex collaboration modes.
|
||||
- MCP-over-ACP allows clients to declare ACP-managed MCP servers and expects the agent to connect to them directly.
|
||||
- draft session-management and elicitation extensions should remain behind explicit seams until the protocol settles.
|
||||
|
||||
## Plan of Work
|
||||
|
||||
Requirements driving scope:
|
||||
|
||||
- Reuse the existing app-server/runtime contract instead of duplicating stateful logic in a parallel ACP-specific core integration.
|
||||
- Preserve interaction parity for approvals, request-user-input, cancellation, and streaming updates.
|
||||
- Keep analytics/compliance attribution explicit so ACP traffic is distinguishable from MCP/app-server traffic.
|
||||
- Ship with an interop harness because the official ACP docs do not currently point to a dedicated conformance suite.
|
||||
- Support the stable ACP core well enough to make a concrete compliance claim, then layer in extended support for `session/load`, `session/set_mode`, and MCP-over-ACP.
|
||||
|
||||
Sequence of work:
|
||||
|
||||
First, produce a protocol mapping document that aligns ACP requests and notifications with app-server v2 methods, notifications, and server requests. This must explicitly cover `initialize`, `session/new`, `session/load`, `session/prompt`, `session/cancel`, `session/update`, `session/request_permission`, `session/set_mode`, and MCP-over-ACP, and it must call out mismatches such as ACP client capabilities (`fs`, `terminal`) and ACP-managed MCP servers from `session/new`.
|
||||
|
||||
Next, decide whether to build on the official ACP Rust SDK or implement only the ACP wire protocol/transport glue manually. The default should be to use the official SDK if it cleanly supports Codex's bounded async runtime, server-initiated interactions, and a stable test harness. If the SDK makes the embedding awkward, keep a very thin ACP adapter crate with minimal protocol code and put all business logic behind `codex-app-server-client`.
|
||||
|
||||
Then, create a new crate, tentatively `codex-rs/acp-server`, and expose it through the CLI, likely as `codex acp-server`. This crate should start the in-process app-server runtime through `codex-app-server-client`, stamp a distinct `SessionSource::Acp` if approved, and translate ACP messages into typed app-server calls and events. The adapter should own only translation, capability negotiation, and session bookkeeping required by ACP; it should not own core conversation logic.
|
||||
|
||||
After the transport skeleton works, implement the stable ACP core:
|
||||
|
||||
- `initialize` mapped to ACP protocol negotiation plus a derived Codex capability view.
|
||||
- `session/new` mapped to `thread/start`.
|
||||
- `session/prompt` mapped to `turn/start`.
|
||||
- `session/cancel` mapped to `turn/interrupt`.
|
||||
- `session/update` synthesized from app-server `ServerNotification` events and, where needed, `ServerRequestResolved`.
|
||||
- `session/request_permission` mapped from app-server approval and elicitation flows with ACP-native option/outcome semantics.
|
||||
|
||||
Then implement the extended ACP slice needed for a stronger compliance story:
|
||||
|
||||
- `session/load` mapped to persisted Codex sessions with full ACP-style replay through `session/update` before the response completes.
|
||||
- `session/set_mode` mapped to collaboration modes or an ACP-specific mode layer only if the mapping remains explicit and user-visible.
|
||||
- MCP-over-ACP support for ACP-declared MCP servers passed in `session/new`, reusing existing Codex MCP connection machinery where possible.
|
||||
- Draft-rich interactivity support behind explicit feature gates so ACP elicitation can evolve without destabilizing the stable core.
|
||||
|
||||
Finally, add test coverage and docs. Mirror the style of `codex-rs/app-server/tests/suite/v2/`, add ACP interop tests that run against a real adapter instance, and update user-facing docs under `codex-rs/docs/` plus CLI help text in `codex-rs/cli/src/main.rs`. If shared app-server v2 payloads change, update the app-server README and regenerate schema fixtures.
|
||||
|
||||
## Concrete Steps
|
||||
|
||||
Discovery and design:
|
||||
|
||||
1. From repo root, inspect the current rich-client boundary:
|
||||
`rg -n "initialize|ServerRequest|ServerNotification|requestUserInput|ElicitationRequest|RequestPermissions" codex-rs/app-server codex-rs/app-server-protocol codex-rs/app-server-client`
|
||||
2. Review the lifecycle docs:
|
||||
`sed -n '1,260p' codex-rs/app-server/README.md`
|
||||
3. Review the protocol surfaces:
|
||||
`sed -n '430,770p' codex-rs/app-server-protocol/src/protocol/common.rs`
|
||||
`rg -n "SessionSource" codex-rs/app-server-protocol/src/protocol/v2.rs`
|
||||
4. Review ACP docs through Context7 before implementation begins:
|
||||
resolve `/agentclientprotocol/agent-client-protocol`
|
||||
query for `initialization`, `session-setup`, `prompt-turn`, `session-modes`, and `request_permission`
|
||||
5. Produce an explicit compliance matrix with rows for stable-core ACP, optional ACP features, and draft/RFD features.
|
||||
|
||||
Implementation:
|
||||
|
||||
1. Create the adapter crate:
|
||||
`cargo new -w codex-rs/acp-server --bin`
|
||||
2. Add workspace wiring in `codex-rs/Cargo.toml` and CLI wiring in `codex-rs/cli/src/main.rs`.
|
||||
3. Implement ACP connection/session translation on top of `codex-app-server-client`.
|
||||
4. Add focused tests for the new crate:
|
||||
`cargo test -p codex-acp-server`
|
||||
5. If app-server protocol or docs change, regenerate or refresh the relevant artifacts:
|
||||
`just write-app-server-schema`
|
||||
6. Run ACP SDK/example interop checks for at least one official ACP client or harness implementation.
|
||||
|
||||
Expected implementation proof points:
|
||||
|
||||
- ACP `initialize` returns negotiated capabilities and agent metadata.
|
||||
- ACP `session/new` yields a persistent Codex-backed session id.
|
||||
- ACP `session/prompt` streams incremental `session/update` events and completes cleanly.
|
||||
- ACP permission prompts round-trip with ACP-native option and outcome shapes and without orphaned pending requests.
|
||||
- ACP `session/load` replays prior conversation history as `session/update` events before returning when `loadSession` is advertised.
|
||||
- ACP mode changes behave deterministically and visibly when `session/set_mode` is advertised.
|
||||
- ACP-declared MCP servers can be connected and used through the ACP session lifecycle when MCP-over-ACP is enabled.
|
||||
|
||||
## Validation and Acceptance
|
||||
|
||||
Acceptance criteria:
|
||||
|
||||
- An ACP client can complete `initialize`, `session/new`, and `session/prompt` against Codex without using MCP as a wrapper transport.
|
||||
- Streaming updates include enough fidelity to render agent text, plans, tool calls, tool-call updates, and diffs in an ACP client.
|
||||
- At least one sensitive operation path exercises ACP permission prompting and maps cleanly to existing Codex approval semantics.
|
||||
- Cancellation ends the active prompt turn and results in a stable terminal state instead of a stuck pending turn.
|
||||
- A previously created session can be loaded and its prior history replayed in ACP shape when `loadSession` is advertised.
|
||||
- If `session/set_mode` is advertised, the mode list and mode transitions conform to ACP expectations and remain aligned with Codex policy behavior.
|
||||
- If MCP-over-ACP is advertised, ACP-provided MCP server declarations connect successfully and do not require a parallel runtime path.
|
||||
- The implementation ships with a written compliance matrix that marks which stable, optional, and draft ACP features are supported.
|
||||
|
||||
Proof artifacts to capture:
|
||||
|
||||
- A saved ACP transcript showing `initialize`, `session/new`, `session/prompt`, and streamed `session/update`.
|
||||
- A saved ACP transcript covering one permission prompt round-trip.
|
||||
- A saved ACP transcript for `session/load` showing replay before completion.
|
||||
- A saved ACP transcript for `session/set_mode`, if supported.
|
||||
- A saved ACP transcript for one MCP-over-ACP session, if supported.
|
||||
- Test output from `cargo test -p codex-acp-server`.
|
||||
- Interop logs or transcripts from at least one official ACP SDK/example counterpart.
|
||||
- If shared app-server types change, a diff to the regenerated schema fixtures and README docs.
|
||||
|
||||
Suggested test strategy:
|
||||
|
||||
- Unit tests for ACP-to-app-server mapping functions.
|
||||
- Integration tests that run the ACP adapter against the in-process app-server runtime.
|
||||
- Replay-focused tests for `session/load` so ordering and completion semantics are pinned down.
|
||||
- Permission-shape tests to verify ACP option IDs, kinds, and selected/cancelled outcomes.
|
||||
- Mode tests to verify `availableModes`, `currentModeId`, and `session/set_mode` behavior if advertised.
|
||||
- MCP-over-ACP tests that verify agent-side connection setup from ACP session declarations.
|
||||
- Interop smoke tests using the official ACP Rust or TypeScript examples/SDKs as counterpart clients where practical.
|
||||
|
||||
## Idempotence and Recovery
|
||||
|
||||
The implementation should be additive:
|
||||
|
||||
- the new ACP adapter must live behind a dedicated crate and CLI entrypoint.
|
||||
- no existing `app-server`, `mcp-server`, TUI, or exec flows should change behavior unless they share a deliberate supporting abstraction.
|
||||
- if the ACP prototype proves unstable, disable the CLI entrypoint and keep the internal mapping code out of existing startup paths.
|
||||
|
||||
Recovery path:
|
||||
|
||||
- revert the ACP crate and CLI entrypoint if the adapter destabilizes startup or transport logic.
|
||||
- if a shared app-server abstraction becomes too ACP-specific, move that logic back to the adapter boundary and restore the previous app-server surface.
|
||||
|
||||
## Artifacts and Notes
|
||||
|
||||
Local references:
|
||||
|
||||
- `codex-rs/app-server/README.md`
|
||||
- `codex-rs/app-server-protocol/src/protocol/common.rs`
|
||||
- `codex-rs/app-server-protocol/src/protocol/v2.rs`
|
||||
- `codex-rs/app-server/src/bespoke_event_handling.rs`
|
||||
- `codex-rs/app-server/src/in_process.rs`
|
||||
- `codex-rs/app-server-client/src/lib.rs`
|
||||
- `codex-rs/mcp-server/src/message_processor.rs`
|
||||
- `codex-rs/core/src/connectors.rs`
|
||||
- `codex-rs/app-server/tests/suite/v2/`
|
||||
- `codex-rs/app-server-test-client/src/lib.rs`
|
||||
|
||||
External ACP references consulted through Context7:
|
||||
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/protocol/initialization.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/protocol/session-setup.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/protocol/prompt-turn.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/protocol/session-modes.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/protocol/tool-calls.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/rfds/mcp-over-acp.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/rfds/elicitation.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/rfds/session-stop.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/rfds/session-info-update.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/libraries/rust.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/libraries/typescript.mdx`
|
||||
- `/agentclientprotocol/agent-client-protocol` `docs/rfds/rust-sdk-v1.mdx`
|
||||
|
||||
Stakeholder starting point:
|
||||
|
||||
- Primary discussion: Owen Lin
|
||||
- Secondary discussion: Michael Bolin, Celia Chen
|
||||
- Focus area for initial review: app-server v2 lifecycle, approval semantics, and analytics/compliance identity for ACP sessions
|
||||
|
||||
## Interfaces and Dependencies
|
||||
|
||||
Expected local modules and crates:
|
||||
|
||||
- `codex-app-server-client` as the primary internal runtime seam.
|
||||
- `codex-app-server` and `codex-app-server-protocol` for any shared lifecycle or schema extensions.
|
||||
- `codex-cli` for surfacing a user-facing ACP server command.
|
||||
- `codex-protocol::protocol::SessionSource` if ACP needs a distinct session identity.
|
||||
- `codex-core` MCP connector plumbing if MCP-over-ACP needs to reuse the existing connector stack.
|
||||
- `codex-app-server/tests` and `codex-app-server-test-client` for reusable harness patterns.
|
||||
|
||||
Expected external dependencies:
|
||||
|
||||
- ACP official Rust SDK if it fits Codex's embedding model.
|
||||
- Otherwise, no large ACP-specific runtime dependency beyond JSON-RPC/transport helpers already compatible with the workspace.
|
||||
Reference in New Issue
Block a user