Adds a new `item.started` event to `codex exec` and implements it for
command_execution item type.
```jsonl
{"type":"session.created","session_id":"019982d1-75f0-7920-b051-e0d3731a5ed8"}
{"type":"item.completed","item":{"id":"item_0","item_type":"reasoning","text":"**Executing commands securely**\n\nI'm thinking about how the default harness typically uses \"bash -lc,\" while historically \"bash\" is what we've been using. The command should be executed as a string in our CLI, so using \"bash -lc 'echo hello'\" is optimal but calling \"echo hello\" directly feels safer. The sandbox makes sure environment variables like CODEX_SANDBOX_NETWORK_DISABLED=1 are set, so I won't ask for approval. I just need to run \"echo hello\" and correctly present the output."}}
{"type":"item.completed","item":{"id":"item_1","item_type":"reasoning","text":"**Preparing for tool calls**\n\nI realize that I need to include a preamble before making any tool calls. So, I'll first state the preamble in the commentary channel, then proceed with the tool call. After that, I need to present the final message along with the output. It's possible that the CLI will show the output inline, but I must ensure that I present the result clearly regardless. Let's move forward and get this organized!"}}
{"type":"item.completed","item":{"id":"item_2","item_type":"assistant_message","text":"Running `echo` to confirm shell access and print output."}}
{"type":"item.started","item":{"id":"item_3","item_type":"command_execution","command":"bash -lc echo hello","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_3","item_type":"command_execution","command":"bash -lc echo hello","aggregated_output":"hello\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_4","item_type":"assistant_message","text":"hello"}}
```
156 lines
4.3 KiB
Rust
156 lines
4.3 KiB
Rust
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use ts_rs::TS;
|
|
|
|
/// Top-level events emitted on the Codex Exec conversation stream.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
#[serde(tag = "type")]
|
|
pub enum ConversationEvent {
|
|
#[serde(rename = "session.created")]
|
|
SessionCreated(SessionCreatedEvent),
|
|
#[serde(rename = "item.started")]
|
|
ItemStarted(ItemStartedEvent),
|
|
#[serde(rename = "item.completed")]
|
|
ItemCompleted(ItemCompletedEvent),
|
|
#[serde(rename = "error")]
|
|
Error(ConversationErrorEvent),
|
|
}
|
|
|
|
/// Payload describing a newly created conversation item.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct SessionCreatedEvent {
|
|
pub session_id: String,
|
|
}
|
|
|
|
/// Payload describing the start of an existing conversation item.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ItemStartedEvent {
|
|
pub item: ConversationItem,
|
|
}
|
|
|
|
/// Payload describing the completion of an existing conversation item.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ItemCompletedEvent {
|
|
pub item: ConversationItem,
|
|
}
|
|
|
|
/// Fatal error emitted by the stream.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ConversationErrorEvent {
|
|
pub message: String,
|
|
}
|
|
|
|
/// Canonical representation of a conversation item and its domain-specific payload.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ConversationItem {
|
|
pub id: String,
|
|
#[serde(flatten)]
|
|
pub details: ConversationItemDetails,
|
|
}
|
|
|
|
/// Typed payloads for each supported conversation item type.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
#[serde(tag = "item_type", rename_all = "snake_case")]
|
|
pub enum ConversationItemDetails {
|
|
AssistantMessage(AssistantMessageItem),
|
|
Reasoning(ReasoningItem),
|
|
CommandExecution(CommandExecutionItem),
|
|
FileChange(FileChangeItem),
|
|
McpToolCall(McpToolCallItem),
|
|
WebSearch(WebSearchItem),
|
|
Error(ErrorItem),
|
|
}
|
|
|
|
/// Session conversation metadata.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct SessionItem {
|
|
pub session_id: String,
|
|
}
|
|
|
|
/// Assistant message payload.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct AssistantMessageItem {
|
|
pub text: String,
|
|
}
|
|
|
|
/// Model reasoning summary payload.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ReasoningItem {
|
|
pub text: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TS)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum CommandExecutionStatus {
|
|
#[default]
|
|
InProgress,
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
/// Local shell command execution payload.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct CommandExecutionItem {
|
|
pub command: String,
|
|
pub aggregated_output: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub exit_code: Option<i32>,
|
|
pub status: CommandExecutionStatus,
|
|
}
|
|
|
|
/// Single file change summary for a patch.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct FileUpdateChange {
|
|
pub path: String,
|
|
pub kind: PatchChangeKind,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum PatchApplyStatus {
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
/// Patch application payload.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct FileChangeItem {
|
|
pub changes: Vec<FileUpdateChange>,
|
|
pub status: PatchApplyStatus,
|
|
}
|
|
|
|
/// Known change kinds for a patch.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum PatchChangeKind {
|
|
Add,
|
|
Delete,
|
|
Update,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TS)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum McpToolCallStatus {
|
|
#[default]
|
|
InProgress,
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct McpToolCallItem {
|
|
pub server: String,
|
|
pub tool: String,
|
|
pub status: McpToolCallStatus,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct WebSearchItem {
|
|
pub query: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
|
|
pub struct ErrorItem {
|
|
pub message: String,
|
|
}
|