Expose typed tool invocation status
This commit is contained in:
parent
c0218dba32
commit
15b079db93
7 changed files with 220 additions and 2 deletions
|
|
@ -48,6 +48,7 @@ use std::time::{Duration, Instant};
|
|||
const DEFAULT_APP_SERVER: &str = r"C:\Users\Meta\.cargo-target-codex\debug\codex-app-server.exe";
|
||||
const DEFAULT_CARGO_TARGET_DIR: &str = r"C:\Users\Meta\.cargo-target-codex";
|
||||
const DEFAULT_THREAD_STATE_STORE: &str = "state/thread-state.msgpack";
|
||||
const DEFAULT_RUNTIME_STORE: &str = "state/runtime-spine.msgpack";
|
||||
const REORIENT_BINDING_ID: &str = "reorient-worker";
|
||||
const IMAGINATION_BINDING_ID: &str = "imagination-synthesis-worker";
|
||||
const MODELING_BINDING_ID: &str = "modeling-checkpoint-worker";
|
||||
|
|
@ -107,6 +108,7 @@ struct Args {
|
|||
thread_id: Option<String>,
|
||||
cwd: PathBuf,
|
||||
thread_state_store: PathBuf,
|
||||
runtime_store: PathBuf,
|
||||
ephemeral: bool,
|
||||
json: bool,
|
||||
result: Option<PathBuf>,
|
||||
|
|
@ -127,6 +129,7 @@ impl Args {
|
|||
thread_id: None,
|
||||
cwd: root.clone(),
|
||||
thread_state_store: PathBuf::from(DEFAULT_THREAD_STATE_STORE),
|
||||
runtime_store: PathBuf::from(DEFAULT_RUNTIME_STORE),
|
||||
ephemeral: true,
|
||||
json: false,
|
||||
result: None,
|
||||
|
|
@ -149,6 +152,9 @@ impl Args {
|
|||
"--thread-state-store" => {
|
||||
parsed.thread_state_store = take_path(&mut args, "--thread-state-store")?
|
||||
}
|
||||
"--runtime-store" => {
|
||||
parsed.runtime_store = take_path(&mut args, "--runtime-store")?
|
||||
}
|
||||
"--ephemeral" => parsed.ephemeral = true,
|
||||
"--no-ephemeral" => parsed.ephemeral = false,
|
||||
"--json" => parsed.json = true,
|
||||
|
|
@ -172,6 +178,7 @@ fn run_status(args: &Args) -> Result<Value> {
|
|||
fn run_native_status(args: &Args) -> Result<Value> {
|
||||
let cwd = absolute_path(&args.cwd)?;
|
||||
let store_path = absolute_path(&args.thread_state_store)?;
|
||||
let runtime_store_path = absolute_path(&args.runtime_store)?;
|
||||
let state_entry = if store_path.exists() {
|
||||
load_thread_state_entry(&store_path)
|
||||
.with_context(|| format!("failed to load {}", store_path.display()))?
|
||||
|
|
@ -325,6 +332,7 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
reorient_finding_accepted: finding_signals.reorient_finding_accepted,
|
||||
});
|
||||
let coordinator_json = coordinator_status_json(&coordinator)?;
|
||||
let tool_invocations = native_tool_invocation_surface(&runtime_store_path)?;
|
||||
|
||||
let root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let native_aux = native_auxiliary_status(&root)?;
|
||||
|
|
@ -359,6 +367,7 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
"recommendation": recommendation,
|
||||
},
|
||||
"coordinator": coordinator_json,
|
||||
"tools": tool_invocations.clone(),
|
||||
},
|
||||
"scene": {
|
||||
"threadId": thread_id,
|
||||
|
|
@ -404,6 +413,7 @@ fn run_native_status(args: &Args) -> Result<Value> {
|
|||
"recommendation": recommendation,
|
||||
},
|
||||
"coordinator": coordinator_json,
|
||||
"tools": tool_invocations,
|
||||
"heartbeat": native_aux.heartbeat,
|
||||
"face": native_aux.face,
|
||||
"voidMemory": native_aux.void_memory,
|
||||
|
|
@ -500,6 +510,8 @@ fn run_codex_status(args: &Args) -> Result<Value> {
|
|||
.get("coordinator")
|
||||
.cloned()
|
||||
.unwrap_or_else(|| json!(null));
|
||||
let runtime_store_path = absolute_path(&args.runtime_store)?;
|
||||
let tool_invocations = native_tool_invocation_surface(&runtime_store_path)?;
|
||||
let root = env::current_dir().context("failed to resolve current directory")?;
|
||||
let native_aux = native_auxiliary_status(&root)?;
|
||||
let status = json!({
|
||||
|
|
@ -516,6 +528,7 @@ fn run_codex_status(args: &Args) -> Result<Value> {
|
|||
"reorientResult": reorient_result,
|
||||
"crrc": crrc,
|
||||
"coordinator": coordinator,
|
||||
"tools": tool_invocations,
|
||||
"heartbeat": native_aux.heartbeat,
|
||||
"face": native_aux.face,
|
||||
"voidMemory": native_aux.void_memory,
|
||||
|
|
@ -585,6 +598,22 @@ fn native_role_result(binding_id: &str) -> Value {
|
|||
})
|
||||
}
|
||||
|
||||
fn native_tool_invocation_surface(runtime_store: &Path) -> Result<Value> {
|
||||
let spine_status = epiphany_core::runtime_spine_status(runtime_store)?;
|
||||
let invocations = epiphany_core::runtime_tool_invocation_statuses(runtime_store)?;
|
||||
Ok(json!({
|
||||
"source": "native",
|
||||
"runtimeStore": runtime_store.display().to_string(),
|
||||
"summary": {
|
||||
"present": spine_status.present,
|
||||
"intentCount": spine_status.tool_invocation_intents,
|
||||
"pendingCount": spine_status.pending_tool_invocations,
|
||||
"receiptCount": spine_status.tool_invocation_receipts,
|
||||
},
|
||||
"invocations": invocations,
|
||||
}))
|
||||
}
|
||||
|
||||
fn coordinator_status_json(status: &epiphany_core::EpiphanyCoordinatorStatus) -> Result<Value> {
|
||||
let mut value = serde_json::to_value(status).context("failed to encode coordinator status")?;
|
||||
let decision = value
|
||||
|
|
@ -1043,6 +1072,35 @@ pub fn render_status(status: &Value) -> String {
|
|||
}
|
||||
}
|
||||
}
|
||||
let tools = &status["tools"];
|
||||
let tool_summary = &tools["summary"];
|
||||
lines.extend([
|
||||
String::new(),
|
||||
"Tools".to_string(),
|
||||
format!(
|
||||
"- intents: {} pending: {} receipts: {}",
|
||||
maybe(&tool_summary["intentCount"], "0"),
|
||||
maybe(&tool_summary["pendingCount"], "0"),
|
||||
maybe(&tool_summary["receiptCount"], "0")
|
||||
),
|
||||
format!("- runtime store: {}", maybe(&tools["runtimeStore"], "none")),
|
||||
]);
|
||||
if let Some(invocations) = tools["invocations"].as_array() {
|
||||
if invocations.is_empty() {
|
||||
lines.push("- latest: none".to_string());
|
||||
} else {
|
||||
for invocation in invocations.iter().rev().take(5) {
|
||||
lines.push(format!(
|
||||
"- {}: {} {}/{} ({})",
|
||||
maybe(&invocation["intentId"], "unknown"),
|
||||
maybe(&invocation["status"], "unknown"),
|
||||
maybe(&invocation["server"], "unknown"),
|
||||
maybe(&invocation["toolName"], "unknown"),
|
||||
maybe(&invocation["adapter"], "unknown")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
lines.extend([
|
||||
String::new(),
|
||||
"Available Actions".to_string(),
|
||||
|
|
|
|||
|
|
@ -64,6 +64,12 @@ fn main() -> Result<()> {
|
|||
println!("jobs: {} open: {}", status.jobs, status.open_jobs);
|
||||
println!("job results: {}", status.job_results);
|
||||
println!("events: {}", status.events);
|
||||
println!(
|
||||
"tool invocations: {} pending: {} receipts: {}",
|
||||
status.tool_invocation_intents,
|
||||
status.pending_tool_invocations,
|
||||
status.tool_invocation_receipts
|
||||
);
|
||||
if !status.supported_document_types.is_empty() {
|
||||
println!("documents: {}", status.supported_document_types.join(", "));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,6 +353,7 @@ pub use runtime_spine::EpiphanyRuntimeSession;
|
|||
pub use runtime_spine::EpiphanyRuntimeSessionStatus;
|
||||
pub use runtime_spine::EpiphanyRuntimeSpineStatus;
|
||||
pub use runtime_spine::EpiphanyRuntimeWorkerLaunchRequest;
|
||||
pub use runtime_spine::EpiphanyToolInvocationStatus;
|
||||
pub use runtime_spine::RUNTIME_EVENT_TYPE;
|
||||
pub use runtime_spine::RUNTIME_IDENTITY_KEY;
|
||||
pub use runtime_spine::RUNTIME_IDENTITY_TYPE;
|
||||
|
|
@ -394,6 +395,7 @@ pub use runtime_spine::runtime_role_worker_result;
|
|||
pub use runtime_spine::runtime_schema_catalog_response;
|
||||
pub use runtime_spine::runtime_spine_cache;
|
||||
pub use runtime_spine::runtime_spine_status;
|
||||
pub use runtime_spine::runtime_tool_invocation_statuses;
|
||||
pub use runtime_spine::runtime_worker_launch_request;
|
||||
pub use runtime_spine::write_runtime_hello_frame;
|
||||
pub use runtime_spine::write_runtime_schema_catalog_json;
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ use epiphany_tool_adapter::EpiphanyToolInvocationReceipt;
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -535,9 +536,28 @@ pub struct EpiphanyRuntimeSpineStatus {
|
|||
pub open_jobs: usize,
|
||||
pub job_results: usize,
|
||||
pub events: usize,
|
||||
pub tool_invocation_intents: usize,
|
||||
pub tool_invocation_receipts: usize,
|
||||
pub pending_tool_invocations: usize,
|
||||
pub supported_document_types: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyToolInvocationStatus {
|
||||
pub intent_id: String,
|
||||
pub adapter: String,
|
||||
pub server: String,
|
||||
pub tool_name: String,
|
||||
pub caller: String,
|
||||
pub reason: String,
|
||||
pub created_at: String,
|
||||
pub status: String,
|
||||
pub receipt_id: Option<String>,
|
||||
pub completed_at: Option<String>,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RuntimeSpineInitOptions {
|
||||
pub runtime_id: String,
|
||||
|
|
@ -1240,6 +1260,9 @@ pub fn runtime_spine_status(store_path: impl AsRef<Path>) -> Result<EpiphanyRunt
|
|||
open_jobs: 0,
|
||||
job_results: 0,
|
||||
events: 0,
|
||||
tool_invocation_intents: 0,
|
||||
tool_invocation_receipts: 0,
|
||||
pending_tool_invocations: 0,
|
||||
supported_document_types: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
|
@ -1252,6 +1275,12 @@ pub fn runtime_spine_status(store_path: impl AsRef<Path>) -> Result<EpiphanyRunt
|
|||
let jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
|
||||
let job_results = cache.get_all::<EpiphanyRuntimeJobResult>()?;
|
||||
let events = cache.get_all::<EpiphanyRuntimeEvent>()?;
|
||||
let tool_intents = cache.get_all::<EpiphanyToolInvocationIntent>()?;
|
||||
let tool_receipts = cache.get_all::<EpiphanyToolInvocationReceipt>()?;
|
||||
let receipt_intent_ids = tool_receipts
|
||||
.iter()
|
||||
.map(|receipt| receipt.intent_id.as_str())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let active_sessions = sessions
|
||||
.iter()
|
||||
.filter(|session| {
|
||||
|
|
@ -1284,12 +1313,65 @@ pub fn runtime_spine_status(store_path: impl AsRef<Path>) -> Result<EpiphanyRunt
|
|||
open_jobs,
|
||||
job_results: job_results.len(),
|
||||
events: events.len(),
|
||||
tool_invocation_intents: tool_intents.len(),
|
||||
tool_invocation_receipts: tool_receipts.len(),
|
||||
pending_tool_invocations: tool_intents
|
||||
.iter()
|
||||
.filter(|intent| !receipt_intent_ids.contains(intent.intent_id.as_str()))
|
||||
.count(),
|
||||
supported_document_types: identity
|
||||
.map(|item| item.supported_document_types)
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn runtime_tool_invocation_statuses(
|
||||
store_path: impl AsRef<Path>,
|
||||
) -> Result<Vec<EpiphanyToolInvocationStatus>> {
|
||||
let store_path = store_path.as_ref();
|
||||
if !store_path.exists() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache
|
||||
.pull_all_backing_stores()
|
||||
.with_context(|| format!("failed to read runtime spine {}", store_path.display()))?;
|
||||
let mut receipts = cache
|
||||
.get_all::<EpiphanyToolInvocationReceipt>()?
|
||||
.into_iter()
|
||||
.map(|receipt| (receipt.intent_id.clone(), receipt))
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
let mut statuses = cache
|
||||
.get_all::<EpiphanyToolInvocationIntent>()?
|
||||
.into_iter()
|
||||
.map(|intent| {
|
||||
let receipt = receipts.remove(&intent.intent_id);
|
||||
EpiphanyToolInvocationStatus {
|
||||
intent_id: intent.intent_id,
|
||||
adapter: intent.adapter,
|
||||
server: intent.server,
|
||||
tool_name: intent.tool_name,
|
||||
caller: intent.caller,
|
||||
reason: intent.reason,
|
||||
created_at: intent.created_at,
|
||||
status: receipt
|
||||
.as_ref()
|
||||
.map(|receipt| receipt.status.clone())
|
||||
.unwrap_or_else(|| "pending".to_string()),
|
||||
receipt_id: receipt.as_ref().map(|receipt| receipt.receipt_id.clone()),
|
||||
completed_at: receipt.as_ref().map(|receipt| receipt.completed_at.clone()),
|
||||
error: receipt.and_then(|receipt| receipt.error),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
statuses.sort_by(|left, right| {
|
||||
left.created_at
|
||||
.cmp(&right.created_at)
|
||||
.then_with(|| left.intent_id.cmp(&right.intent_id))
|
||||
});
|
||||
Ok(statuses)
|
||||
}
|
||||
|
||||
pub fn runtime_hello_frame(store_path: impl AsRef<Path>) -> Result<Vec<u8>> {
|
||||
let mut cache = runtime_spine_cache(store_path.as_ref())?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
|
|
@ -2806,6 +2888,73 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_spine_derives_tool_invocation_statuses() -> Result<()> {
|
||||
let temp = tempdir()?;
|
||||
let store = temp.path().join("runtime.msgpack");
|
||||
initialize_runtime_spine(
|
||||
&store,
|
||||
RuntimeSpineInitOptions {
|
||||
runtime_id: "epiphany-test".to_string(),
|
||||
display_name: "Epiphany Test".to_string(),
|
||||
created_at: "2026-05-06T00:00:00Z".to_string(),
|
||||
},
|
||||
)?;
|
||||
let mut cache = runtime_spine_cache(&store)?;
|
||||
cache.put(
|
||||
"intent:done",
|
||||
&EpiphanyToolInvocationIntent::new(
|
||||
"done",
|
||||
"codex-mcp",
|
||||
"smoke-server",
|
||||
"smoke_tool",
|
||||
"{}",
|
||||
"model-request-1",
|
||||
"Test completed tool call.",
|
||||
"2026-05-06T00:01:00Z",
|
||||
),
|
||||
)?;
|
||||
cache.put(
|
||||
"intent:pending",
|
||||
&EpiphanyToolInvocationIntent::new(
|
||||
"pending",
|
||||
"codex-mcp",
|
||||
"smoke-server",
|
||||
"waiting_tool",
|
||||
"{}",
|
||||
"model-request-2",
|
||||
"Test pending tool call.",
|
||||
"2026-05-06T00:02:00Z",
|
||||
),
|
||||
)?;
|
||||
let mut failed_receipt = EpiphanyToolInvocationReceipt::new(
|
||||
"receipt-done",
|
||||
"done",
|
||||
"codex-mcp",
|
||||
"smoke-server",
|
||||
"smoke_tool",
|
||||
"failed",
|
||||
"2026-05-06T00:03:00Z",
|
||||
);
|
||||
failed_receipt.error = Some("smoke server absent".to_string());
|
||||
cache.put("receipt:done", &failed_receipt)?;
|
||||
|
||||
let status = runtime_spine_status(&store)?;
|
||||
assert_eq!(status.tool_invocation_intents, 2);
|
||||
assert_eq!(status.tool_invocation_receipts, 1);
|
||||
assert_eq!(status.pending_tool_invocations, 1);
|
||||
|
||||
let invocations = runtime_tool_invocation_statuses(&store)?;
|
||||
assert_eq!(invocations.len(), 2);
|
||||
assert_eq!(invocations[0].intent_id, "done");
|
||||
assert_eq!(invocations[0].status, "failed");
|
||||
assert_eq!(invocations[0].error.as_deref(), Some("smoke server absent"));
|
||||
assert_eq!(invocations[1].intent_id, "pending");
|
||||
assert_eq!(invocations[1].status, "pending");
|
||||
assert!(invocations[1].receipt_id.is_none());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_spine_opens_and_completes_native_jobs() -> Result<()> {
|
||||
let temp = tempdir()?;
|
||||
|
|
|
|||
Reference in a new issue