Compare commits

...

2 Commits

Author SHA1 Message Date
Dylan Hurd
540aee3d5c store _codex_meta field 2025-08-22 18:10:01 -07:00
Dylan Hurd
7e0056fbdf [mcp] Add InputItem type 2025-08-22 14:15:05 -07:00
5 changed files with 96 additions and 1 deletions

View File

@@ -183,6 +183,9 @@ impl From<Vec<InputItem>> for ResponseInputItem {
None
}
},
InputItem::FileReference { name, path } => Some(ContentItem::InputText {
text: format!("[{name}]({})", path.to_string_lossy()),
}),
_ => None,
})
.collect::<Vec<ContentItem>>(),

View File

@@ -22,6 +22,7 @@ use uuid::Uuid;
use crate::config::Config;
use crate::git_info::GitInfo;
use crate::git_info::collect_git_info;
use crate::models::ContentItem;
use crate::models::ResponseItem;
const SESSIONS_SUBDIR: &str = "sessions";
@@ -318,7 +319,12 @@ async fn rollout_writer(
| ResponseItem::FunctionCall { .. }
| ResponseItem::FunctionCallOutput { .. }
| ResponseItem::Reasoning { .. } => {
writer.write_line(&item).await?;
// Inject rollout-only _codex_meta for easier resume/debug.
let mut v = serde_json::to_value(&item)?;
if let Some(obj) = v.as_object_mut() {
obj.insert("_codex_meta".to_string(), build_codex_meta(&item));
}
writer.write_line(&v).await?;
}
ResponseItem::Other => {}
}
@@ -346,6 +352,70 @@ async fn rollout_writer(
Ok(())
}
/// Construct rollout-only metadata for a ResponseItem to aid resume/debugging.
/// This is not sent to providers; it is only stored in rollout JSONL.
fn build_codex_meta(item: &ResponseItem) -> serde_json::Value {
match item {
ResponseItem::Message { id, role, content } => {
let kinds: Vec<&'static str> = content
.iter()
.map(|c| match c {
ContentItem::InputText { .. } => "input_text",
ContentItem::InputImage { .. } => "input_image",
ContentItem::OutputText { .. } => "output_text",
})
.collect();
serde_json::json!({
"variant": "message",
"role": role,
"message_id": id,
"content_kinds": kinds,
})
}
ResponseItem::Reasoning { id, .. } => {
serde_json::json!({
"variant": "reasoning",
"id": id,
})
}
ResponseItem::LocalShellCall {
id,
call_id,
status,
action,
} => {
// Capture identifiers that are important to correlate with outputs.
// Avoid duplicating the full action payload; keep meta concise.
let action_type = match action {
crate::models::LocalShellAction::Exec(_) => "exec",
};
serde_json::json!({
"variant": "local_shell_call",
"id": id,
"call_id": call_id,
"action_type": action_type,
"status": status,
})
}
ResponseItem::FunctionCall {
id, name, call_id, ..
} => serde_json::json!({
"variant": "function_call",
"id": id,
"call_id": call_id,
"name": name,
}),
ResponseItem::FunctionCallOutput { call_id, output } => serde_json::json!({
"variant": "function_call_output",
"call_id": call_id,
// success is advisory in our internal payload; include if set.
"success": output.success,
}),
ResponseItem::Other => serde_json::json!({
"variant": "other",
}),
}
}
struct JsonlWriter {
file: tokio::fs::File,

View File

@@ -417,6 +417,9 @@ impl CodexMessageProcessor {
WireInputItem::Text { text } => CoreInputItem::Text { text },
WireInputItem::Image { image_url } => CoreInputItem::Image { image_url },
WireInputItem::LocalImage { path } => CoreInputItem::LocalImage { path },
WireInputItem::FileReference { name, path } => {
CoreInputItem::FileReference { name, path }
}
})
.collect();
@@ -465,6 +468,9 @@ impl CodexMessageProcessor {
WireInputItem::Text { text } => CoreInputItem::Text { text },
WireInputItem::Image { image_url } => CoreInputItem::Image { image_url },
WireInputItem::LocalImage { path } => CoreInputItem::LocalImage { path },
WireInputItem::FileReference { name, path } => {
CoreInputItem::FileReference { name, path }
}
})
.collect();

View File

@@ -292,6 +292,14 @@ pub enum InputItem {
LocalImage {
path: PathBuf,
},
/// A reference to a file in the user's workspace.
FileReference {
/// The name of the file
name: String,
/// The relative path to the file in the user's workspace.
path: PathBuf,
},
}
// TODO(mbolin): Need test to ensure these constants match the enum variants.

View File

@@ -376,6 +376,14 @@ pub enum InputItem {
LocalImage {
path: std::path::PathBuf,
},
/// A reference to a file in the user's workspace.
FileReference {
/// The name of the file
name: String,
/// The relative path to the file in the user's workspace.
path: PathBuf,
},
}
/// Event Queue Entry - events from agent