diff --git a/epiphany-openai-runtime/Cargo.toml b/epiphany-openai-runtime/Cargo.toml index 9c5379e1..f794f937 100644 --- a/epiphany-openai-runtime/Cargo.toml +++ b/epiphany-openai-runtime/Cargo.toml @@ -16,6 +16,7 @@ epiphany-core = { path = "../epiphany-core" } epiphany-model-adapter = { path = "../epiphany-model-adapter" } epiphany-openai-adapter = { path = "../epiphany-openai-adapter" } epiphany-openai-codex-spine = { path = "../epiphany-openai-codex-spine" } +epiphany-tool-adapter = { path = "../epiphany-tool-adapter" } rmp-serde = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index d0ae4286..cc14e4bd 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -127,12 +127,24 @@ async fn main() -> Result<()> { let mut receipt = EpiphanyOpenAiModelReceipt::new(&request.request_id, &request.model); receipt.response_id = Some("smoke-response".to_string()); receipt.transport = Some("smoke_no_network".to_string()); - let events = vec![EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), - request_id: request.request_id.clone(), - sequence: 0, - payload: EpiphanyOpenAiStreamPayload::Completed { receipt }, - }]; + let events = vec![ + EpiphanyOpenAiStreamEvent { + schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), + request_id: request.request_id.clone(), + sequence: 0, + payload: EpiphanyOpenAiStreamPayload::ToolCall { + call_id: "smoke-tool-call".to_string(), + name: "mcp__smoke_server__smoke_tool".to_string(), + arguments: "{}".to_string(), + }, + }, + EpiphanyOpenAiStreamEvent { + schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), + request_id: request.request_id.clone(), + sequence: 1, + payload: EpiphanyOpenAiStreamPayload::Completed { receipt }, + }, + ]; let summary = record_openai_events( &runtime_options.store_path, &runtime_options, diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index 9d2c613f..b888bd73 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -37,6 +37,9 @@ use epiphany_openai_codex_spine::EpiphanyCodexOpenAiTransport; use epiphany_openai_codex_spine::auth_manager; pub use epiphany_openai_codex_spine::default_codex_home; use epiphany_openai_codex_spine::status_from_auth_manager; +use epiphany_tool_adapter::CODEX_MCP_TOOL_ADAPTER_ID; +use epiphany_tool_adapter::EpiphanyToolInvocationIntent; +use epiphany_tool_adapter::tool_invocation_intent_key; use serde::de::DeserializeOwned; pub const OPENAI_RUNTIME_ROLE: &str = "openai-model-adapter"; @@ -65,6 +68,7 @@ pub struct EpiphanyOpenAiRuntimeRunSummary { pub verdict: String, pub result_id: String, pub receipt_id: Option, + pub tool_intent_ids: Vec, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -236,6 +240,9 @@ pub fn record_openai_events( cache.put(model_request_key(&model_request.request_id), &model_request)?; for event in events { let model_event = model_event_from_openai_event(DEFAULT_MODEL_PROVIDER, event); + if let Some(intent) = tool_invocation_intent_from_model_event(&model_event) { + cache.put(tool_invocation_intent_key(&intent.intent_id), &intent)?; + } cache.put( model_event_key(&model_event.request_id, model_event.sequence), &model_event, @@ -323,6 +330,10 @@ pub fn record_openai_events( verdict: verdict.to_string(), result_id, receipt_id: receipt.map(|item| openai_receipt_key(&item.request_id)), + tool_intent_ids: tool_invocation_intents_from_openai_events(DEFAULT_MODEL_PROVIDER, events) + .into_iter() + .map(|intent| intent.intent_id) + .collect(), }) } @@ -771,6 +782,78 @@ pub fn model_receipt_from_openai_receipt( } } +pub fn tool_invocation_intents_from_openai_events( + provider: &str, + events: &[EpiphanyOpenAiStreamEvent], +) -> Vec { + events + .iter() + .filter_map(|event| { + let model_event = model_event_from_openai_event(provider, event); + tool_invocation_intent_from_model_event(&model_event) + }) + .collect() +} + +pub fn tool_invocation_intent_from_model_event( + event: &EpiphanyModelStreamEvent, +) -> Option { + let EpiphanyModelStreamPayload::ToolCall { + call_id, + name, + arguments, + } = &event.payload + else { + return None; + }; + let (server, tool_name) = split_mcp_tool_name(name)?; + if !arguments_are_invocation_ready(arguments) { + return None; + } + Some(EpiphanyToolInvocationIntent::new( + format!( + "model-{}-{}-{}", + sanitize_request_id(&event.request_id), + event.sequence, + sanitize_request_id(call_id) + ), + CODEX_MCP_TOOL_ADAPTER_ID, + server, + tool_name, + arguments.clone(), + format!("model-runtime:{}", event.provider), + format!( + "Model request {} emitted MCP tool call {}.", + event.request_id, call_id + ), + now(), + )) +} + +fn split_mcp_tool_name(name: &str) -> Option<(String, String)> { + let mut parts = name.split("__"); + if parts.next()? != "mcp" { + return None; + } + let server = parts.next()?.trim(); + let tool = parts.collect::>().join("__"); + if server.is_empty() || tool.trim().is_empty() { + return None; + } + Some((server.to_string(), tool)) +} + +fn arguments_are_invocation_ready(arguments: &str) -> bool { + let trimmed = arguments.trim(); + if trimmed.is_empty() || trimmed == "null" { + return true; + } + matches!( + serde_json::from_str::(trimmed), + Ok(serde_json::Value::Object(_)) + ) +} + fn require_openai_provider(provider: &str) -> Result<()> { if matches!(provider, "openai-codex" | "openai") { return Ok(()); @@ -1196,6 +1279,7 @@ mod tests { verdict: "pass".to_string(), result_id: "result-openai-worker-worker-job-1".to_string(), receipt_id: Some(model_request.request_id.clone()), + tool_intent_ids: Vec::new(), }; let result = complete_worker_job_from_assistant_text( &store, @@ -1231,4 +1315,55 @@ mod tests { ); Ok(()) } + + #[test] + fn mcp_model_tool_call_becomes_typed_invocation_intent() -> Result<()> { + let event = EpiphanyModelStreamEvent { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_EVENT_SCHEMA_ID.to_string(), + request_id: "request-1".to_string(), + provider: DEFAULT_MODEL_PROVIDER.to_string(), + sequence: 7, + payload: EpiphanyModelStreamPayload::ToolCall { + call_id: "call/1".to_string(), + name: "mcp__calendar_server__list_events".to_string(), + arguments: r#"{"limit":3}"#.to_string(), + }, + }; + + let intent = tool_invocation_intent_from_model_event(&event) + .expect("MCP-shaped tool call should produce an intent"); + assert_eq!( + intent.adapter, + epiphany_tool_adapter::CODEX_MCP_TOOL_ADAPTER_ID + ); + assert_eq!(intent.server, "calendar_server"); + assert_eq!(intent.tool_name, "list_events"); + assert_eq!(intent.arguments_json, r#"{"limit":3}"#); + assert_eq!(intent.intent_id, "model-request-1-7-call-1"); + Ok(()) + } + + #[test] + fn incomplete_or_non_mcp_tool_calls_do_not_create_invocation_intents() { + let base = EpiphanyModelStreamEvent { + schema_id: epiphany_model_adapter::MODEL_ADAPTER_EVENT_SCHEMA_ID.to_string(), + request_id: "request-1".to_string(), + provider: DEFAULT_MODEL_PROVIDER.to_string(), + sequence: 7, + payload: EpiphanyModelStreamPayload::ToolCall { + call_id: "call".to_string(), + name: "shell".to_string(), + arguments: "{}".to_string(), + }, + }; + assert!(tool_invocation_intent_from_model_event(&base).is_none()); + + let mut incomplete = base.clone(); + incomplete.payload = EpiphanyModelStreamPayload::ToolCall { + call_id: "call".to_string(), + name: "mcp__server__tool".to_string(), + arguments: "{".to_string(), + }; + assert!(tool_invocation_intent_from_model_event(&incomplete).is_none()); + } } diff --git a/epiphany-tool-adapter/src/lib.rs b/epiphany-tool-adapter/src/lib.rs index b0700595..f1309971 100644 --- a/epiphany-tool-adapter/src/lib.rs +++ b/epiphany-tool-adapter/src/lib.rs @@ -3,6 +3,15 @@ use cultcache_rs::DatabaseEntry; pub const TOOL_ADAPTER_CAPABILITY_SCHEMA_ID: &str = "epiphany.tool_capability.v0"; pub const TOOL_ADAPTER_INVOCATION_INTENT_SCHEMA_ID: &str = "epiphany.tool_invocation_intent.v0"; pub const TOOL_ADAPTER_INVOCATION_RECEIPT_SCHEMA_ID: &str = "epiphany.tool_invocation_receipt.v0"; +pub const CODEX_MCP_TOOL_ADAPTER_ID: &str = "codex-mcp"; + +pub fn tool_invocation_intent_key(intent_id: &str) -> String { + format!("intent:{intent_id}") +} + +pub fn tool_invocation_receipt_key(intent_id: &str) -> String { + format!("receipt:{intent_id}") +} #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] #[cultcache( diff --git a/epiphany-tool-codex-mcp-spine/Cargo.lock b/epiphany-tool-codex-mcp-spine/Cargo.lock index 42a3df73..26b572e3 100644 --- a/epiphany-tool-codex-mcp-spine/Cargo.lock +++ b/epiphany-tool-codex-mcp-spine/Cargo.lock @@ -24,7 +24,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "generic-array", ] @@ -36,7 +36,21 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", - "cpufeatures", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", ] [[package]] @@ -527,7 +541,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -539,6 +553,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + [[package]] name = "block-padding" version = "0.3.3" @@ -570,6 +593,20 @@ dependencies = [ "piper", ] +[[package]] +name = "bm25" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cbd8ffdfb7b4c2ff038726178a780a94f90525ed0ad264c0afaa75dd8c18a64" +dependencies = [ + "cached", + "deunicode", + "fxhash", + "rust-stemmers", + "stop-words", + "unicode-segmentation", +] + [[package]] name = "borsh" version = "1.6.1" @@ -629,6 +666,39 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +[[package]] +name = "cached" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801927ee168e17809ab8901d9f01f700cd7d8d6a6527997fee44e4b0327a253c" +dependencies = [ + "ahash", + "cached_proc_macro", + "cached_proc_macro_types", + "hashbrown 0.15.5", + "once_cell", + "thiserror 2.0.18", + "web-time", +] + +[[package]] +name = "cached_proc_macro" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9225bdcf4e4a9a4c08bf16607908eb2fbf746828d5e0b5e019726dbf6571f201" +dependencies = [ + "darling 0.20.11", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0" + [[package]] name = "cbc" version = "0.1.2" @@ -668,6 +738,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "chardetng" version = "0.1.17" @@ -705,7 +786,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "inout", "zeroize", ] @@ -768,6 +849,12 @@ dependencies = [ "cc", ] +[[package]] +name = "cmov" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" + [[package]] name = "cmp_any" version = "0.8.1" @@ -788,7 +875,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2", + "sha2 0.10.9", ] [[package]] @@ -899,7 +986,7 @@ dependencies = [ "serde", "serde_json", "serde_path_to_error", - "sha2", + "sha2 0.10.9", "thiserror 2.0.18", "tokio", "toml", @@ -1003,7 +1090,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "thiserror 2.0.18", "tiny_http", "tokio", @@ -1169,7 +1256,7 @@ dependencies = [ "rmcp", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "sse-stream", "thiserror 2.0.18", "tiny_http", @@ -1341,7 +1428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33e2a781ebdf4467d1428dc4593067825fb646f6871475098d8577421af73558" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "proptest", "serde_core", ] @@ -1352,6 +1439,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "const_format" version = "0.2.36" @@ -1446,6 +1539,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.0" @@ -1470,6 +1572,16 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + [[package]] name = "crossbeam-epoch" version = "0.9.18" @@ -1502,6 +1614,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + [[package]] name = "crypto_box" version = "0.9.1" @@ -1563,6 +1684,24 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "ctutils" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e" +dependencies = [ + "cmov", +] + [[package]] name = "cultcache-rs" version = "0.1.0" @@ -1587,6 +1726,37 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "cultmesh-rs" +version = "0.1.0" +dependencies = [ + "anyhow", + "cultcache-rs", + "cultnet-rs", + "serde", +] + +[[package]] +name = "cultnet-rs" +version = "0.1.0" +dependencies = [ + "aes-gcm", + "anyhow", + "base64", + "chrono", + "cultcache-rs", + "hmac 0.12.1", + "rand 0.9.4", + "rmp-serde", + "rmpv", + "serde", + "serde_bytes", + "serde_json", + "sha2 0.10.9", + "socket2 0.5.10", + "uuid", +] + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -1594,9 +1764,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "curve25519-dalek-derive", - "digest", + "digest 0.10.7", "fiat-crypto", "rustc_version", "subtle", @@ -1614,14 +1784,38 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core 0.20.11", + "darling_macro 0.20.11", +] + [[package]] name = "darling" version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.23.0", + "darling_macro 0.23.0", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.11.1", + "syn 2.0.117", ] [[package]] @@ -1637,13 +1831,24 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core 0.20.11", + "quote", + "syn 2.0.117", +] + [[package]] name = "darling_macro" version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" dependencies = [ - "darling_core", + "darling_core 0.23.0", "quote", "syn 2.0.117", ] @@ -1679,7 +1884,7 @@ dependencies = [ "hkdf", "num", "once_cell", - "sha2", + "sha2 0.10.9", "zeroize", ] @@ -1700,7 +1905,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "zeroize", ] @@ -1761,6 +1966,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "deunicode" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04" + [[package]] name = "diff" version = "0.1.13" @@ -1773,11 +1984,23 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", "subtle", ] +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.0", + "const-oid 0.10.2", + "crypto-common 0.2.2", + "ctutils", +] + [[package]] name = "dirs" version = "6.0.0" @@ -1859,7 +2082,7 @@ checksum = "6e39034cee21a2f5bbb66ba0e3689819c4bb5d00382a282006e802a7ffa6c41d" dependencies = [ "cfg-if", "libc", - "socket2", + "socket2 0.6.3", "windows-sys 0.60.2", ] @@ -1929,7 +2152,7 @@ dependencies = [ "curve25519-dalek", "ed25519", "serde", - "sha2", + "sha2 0.10.9", "subtle", "zeroize", ] @@ -2009,6 +2232,47 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "epiphany-core" +version = "0.1.0" +dependencies = [ + "anyhow", + "bm25", + "chrono", + "cultcache-rs", + "cultmesh-rs", + "cultnet-rs", + "epiphany-model-adapter", + "epiphany-openai-adapter", + "epiphany-state-model", + "epiphany-tool-adapter", + "ignore", + "postgres", + "reqwest", + "rmp-serde", + "serde", + "serde_json", + "sha1", + "tracing", + "uuid", +] + +[[package]] +name = "epiphany-model-adapter" +version = "0.1.0" +dependencies = [ + "cultcache-rs", + "serde", +] + +[[package]] +name = "epiphany-openai-adapter" +version = "0.1.0" +dependencies = [ + "cultcache-rs", + "serde", +] + [[package]] name = "epiphany-state-model" version = "0.1.0" @@ -2038,6 +2302,7 @@ dependencies = [ "codex-mcp", "codex-protocol", "cultcache-rs", + "epiphany-core", "epiphany-tool-adapter", "serde", "serde_json", @@ -2108,6 +2373,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "2.4.1" @@ -2413,7 +2684,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -2440,10 +2711,21 @@ dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", + "rand_core 0.10.1", "wasip2", "wasip3", ] +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "gif" version = "0.14.2" @@ -2508,6 +2790,8 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ + "allocator-api2", + "equivalent", "foldhash 0.1.5", ] @@ -2622,7 +2906,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ - "hmac", + "hmac 0.12.1", ] [[package]] @@ -2631,7 +2915,16 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", ] [[package]] @@ -2694,6 +2987,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hybrid-array" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" +dependencies = [ + "typenum", +] + [[package]] name = "hyper" version = "1.10.0" @@ -2779,7 +3081,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2", + "socket2 0.6.3", "system-configuration", "tokio", "tower-service", @@ -2992,6 +3294,22 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "ignore" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + [[package]] name = "image" version = "0.25.10" @@ -3074,7 +3392,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222" dependencies = [ - "socket2", + "socket2 0.6.3", "widestring", "windows-registry", "windows-result", @@ -3477,6 +3795,16 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608" +[[package]] +name = "md-5" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" +dependencies = [ + "cfg-if", + "digest 0.11.3", +] + [[package]] name = "md5" version = "0.8.0" @@ -3546,7 +3874,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", "windows-sys 0.61.2", ] @@ -3783,7 +4111,7 @@ dependencies = [ "serde", "serde_json", "serde_path_to_error", - "sha2", + "sha2 0.10.9", "thiserror 1.0.69", "url", ] @@ -3916,6 +4244,15 @@ dependencies = [ "objc2-foundation", ] +[[package]] +name = "objc2-system-configuration" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7216bd11cbda54ccabcab84d523dc93b858ec75ecfb3a7d89513fa22464da396" +dependencies = [ + "objc2-core-foundation", +] + [[package]] name = "objc2-ui-kit" version = "0.3.2" @@ -4219,6 +4556,16 @@ dependencies = [ "indexmap 2.14.0", ] +[[package]] +name = "phf" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_shared 0.13.1", + "serde", +] + [[package]] name = "phf_shared" version = "0.11.3" @@ -4228,6 +4575,15 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.13" @@ -4320,7 +4676,19 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ - "cpufeatures", + "cpufeatures 0.2.17", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", "opaque-debug", "universal-hash", ] @@ -4352,6 +4720,49 @@ dependencies = [ "winreg", ] +[[package]] +name = "postgres" +version = "0.19.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacf632d0554ff75f58183694f41dc8999c8a3a43a386994d0ec2d034f1dfbe1" +dependencies = [ + "bytes", + "fallible-iterator", + "futures-util", + "log", + "tokio", + "tokio-postgres", +] + +[[package]] +name = "postgres-protocol" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56201207dac53e2f38e848e31b4b91616a6bb6e0c7205b77718994a7f49e70fc" +dependencies = [ + "base64", + "byteorder", + "bytes", + "fallible-iterator", + "hmac 0.13.0", + "md-5", + "memchr", + "rand 0.10.1", + "sha2 0.11.0", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc729a129e682e8d24170cd30ae1aa01b336b096cbb56df6d534ffec133d186" +dependencies = [ + "bytes", + "fallible-iterator", + "postgres-protocol", +] + [[package]] name = "potential_utf" version = "0.1.5" @@ -4524,7 +4935,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls", - "socket2", + "socket2 0.6.3", "thiserror 2.0.18", "tokio", "tracing", @@ -4561,7 +4972,7 @@ dependencies = [ "cfg_aliases 0.2.1", "libc", "once_cell", - "socket2", + "socket2 0.6.3", "tracing", "windows-sys 0.60.2", ] @@ -4818,8 +5229,8 @@ dependencies = [ "rama-macros", "rama-utils", "serde", - "sha2", - "socket2", + "sha2 0.10.9", + "socket2 0.6.3", "tokio", ] @@ -4938,6 +5349,17 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -4976,6 +5398,12 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "rand_xorshift" version = "0.4.0" @@ -5204,7 +5632,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e88ad84b8b6237a934534a62b379a5be6388915663c0cc598ceb9b3292bbbfe" dependencies = [ - "darling", + "darling 0.23.0", "proc-macro2", "quote", "serde_json", @@ -5230,6 +5658,27 @@ dependencies = [ "serde", ] +[[package]] +name = "rmpv" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a4e1d4b9b938a26d2996af33229f0ca0956c652c1375067f0b45291c1df8417" +dependencies = [ + "rmp", + "serde", + "serde_bytes", +] + +[[package]] +name = "rust-stemmers" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46a2036019fdb888131db7a4c847a1063a7493f971ed94ea82c67eada63ca54" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "rustc-hash" version = "2.1.2" @@ -5518,7 +5967,7 @@ dependencies = [ "once_cell", "rand 0.8.6", "serde", - "sha2", + "sha2 0.10.9", "zbus", ] @@ -5711,7 +6160,7 @@ version = "3.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b90c488738ecb4fb0262f41f43bc40efc5868d9fb744319ddf5f5317f417bfac" dependencies = [ - "darling", + "darling 0.23.0", "proc-macro2", "quote", "syn 2.0.117", @@ -5735,10 +6184,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", ] +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + [[package]] name = "sha2" version = "0.10.9" @@ -5746,8 +6201,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -5853,6 +6319,16 @@ dependencies = [ "serde_core", ] +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "socket2" version = "0.6.3" @@ -5997,6 +6473,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stop-words" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645a3d441ccf4bf47f2e4b7681461986681a6eeea9937d4c3bc9febd61d17c71" +dependencies = [ + "serde_json", +] + [[package]] name = "streaming-iterator" version = "0.1.9" @@ -6011,10 +6496,21 @@ checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f" dependencies = [ "new_debug_unreachable", "parking_lot", - "phf_shared", + "phf_shared 0.11.3", "precomputed-hash", ] +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "strsim" version = "0.10.0" @@ -6310,7 +6806,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.6.3", "tokio-macros", "windows-sys 0.61.2", ] @@ -6349,6 +6845,32 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-postgres" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd8df5ef180f6364759a6f00f7aadda4fbbac86cdee37480826a6ff9f3574ce" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand 0.10.1", + "socket2 0.6.3", + "tokio", + "tokio-util", + "whoami", +] + [[package]] name = "tokio-rustls" version = "0.26.4" @@ -6758,12 +7280,33 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + [[package]] name = "unicode-segmentation" version = "1.13.2" @@ -6788,7 +7331,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "subtle", ] @@ -6850,6 +7393,7 @@ dependencies = [ "getrandom 0.4.2", "js-sys", "serde_core", + "sha1_smol", "wasm-bindgen", ] @@ -6896,6 +7440,15 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + [[package]] name = "wasip2" version = "1.0.3+wasi-0.2.9" @@ -6914,6 +7467,15 @@ dependencies = [ "wit-bindgen 0.51.0", ] +[[package]] +name = "wasite" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fe902b4a6b8028a753d5424909b764ccf79b7a209eac9bf97e59cda9f71a42" +dependencies = [ + "wasi 0.14.7+wasi-0.2.4", +] + [[package]] name = "wasm-bindgen" version = "0.2.122" @@ -7076,6 +7638,19 @@ dependencies = [ "libc", ] +[[package]] +name = "whoami" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "998767ef88740d1f5b0682a9c53c24431453923962269c2db68ee43788c5a40d" +dependencies = [ + "libc", + "libredox", + "objc2-system-configuration", + "wasite", + "web-sys", +] + [[package]] name = "widestring" version = "1.2.1" diff --git a/epiphany-tool-codex-mcp-spine/Cargo.toml b/epiphany-tool-codex-mcp-spine/Cargo.toml index c6dd0d0a..d411b384 100644 --- a/epiphany-tool-codex-mcp-spine/Cargo.toml +++ b/epiphany-tool-codex-mcp-spine/Cargo.toml @@ -14,6 +14,7 @@ codex-exec-server = { path = "../vendor/codex/codex-rs/exec-server" } codex-mcp = { path = "../vendor/codex/codex-rs/codex-mcp" } codex-protocol = { path = "../vendor/codex/codex-rs/protocol" } cultcache-rs = { path = "../vendor/cultcache-rs" } +epiphany-core = { path = "../epiphany-core" } epiphany-tool-adapter = { path = "../epiphany-tool-adapter" } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/epiphany-tool-codex-mcp-spine/src/main.rs b/epiphany-tool-codex-mcp-spine/src/main.rs index d0fd8b70..af1ea1fb 100644 --- a/epiphany-tool-codex-mcp-spine/src/main.rs +++ b/epiphany-tool-codex-mcp-spine/src/main.rs @@ -2,8 +2,8 @@ use anyhow::Context; use anyhow::Result; use anyhow::anyhow; use async_channel::unbounded; -use codex_config::Constrained; use codex_config::CONFIG_TOML_FILE; +use codex_config::Constrained; use codex_config::config_toml::ConfigToml; use codex_config::load_global_mcp_servers; use codex_config::types::OAuthCredentialsStoreMode; @@ -15,14 +15,11 @@ use codex_mcp::compute_auth_statuses; use codex_mcp::effective_mcp_servers; use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::SandboxPolicy; -use cultcache_rs::CultCache; -use cultcache_rs::SingleFileMessagePackBackingStore; -use epiphany_tool_adapter::EpiphanyToolCapability; +use epiphany_tool_adapter::CODEX_MCP_TOOL_ADAPTER_ID; use epiphany_tool_adapter::EpiphanyToolInvocationIntent; use epiphany_tool_adapter::EpiphanyToolInvocationReceipt; -use epiphany_tool_adapter::TOOL_ADAPTER_CAPABILITY_SCHEMA_ID; -use epiphany_tool_adapter::TOOL_ADAPTER_INVOCATION_INTENT_SCHEMA_ID; -use epiphany_tool_adapter::TOOL_ADAPTER_INVOCATION_RECEIPT_SCHEMA_ID; +use epiphany_tool_adapter::tool_invocation_intent_key; +use epiphany_tool_adapter::tool_invocation_receipt_key; use serde::Serialize; use serde_json::Value; use std::collections::BTreeMap; @@ -34,7 +31,7 @@ use std::sync::Arc; use std::time::SystemTime; use std::time::UNIX_EPOCH; -const ADAPTER_ID: &str = "codex-mcp"; +const ADAPTER_ID: &str = CODEX_MCP_TOOL_ADAPTER_ID; #[tokio::main] async fn main() -> Result<()> { @@ -92,9 +89,7 @@ impl Command { .cloned() .unwrap_or_else(|| "codex-mcp-spine-smoke".to_string()), })), - other => Err(anyhow!( - "unknown command {other:?}; expected run or smoke" - )), + other => Err(anyhow!("unknown command {other:?}; expected run or smoke")), } } } @@ -129,12 +124,8 @@ fn optional_path(values: &BTreeMap, name: &str) -> Result