Lightweight coding agent that runs in your terminal
Rust
Add message phase to agent message thread item (#12072)
Jack Mousseau486e60bb5515
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.jsonindex b6d87cd442..71256baa09 100644--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json@@ -4415,6 +4415,13 @@"type": "string"},"MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },+ "MessagePhase2": {"description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.","oneOf": [{@@ -5344,7 +5351,7 @@"phase": {"anyOf": [{- "$ref": "#/definitions/MessagePhase"+ "$ref": "#/definitions/MessagePhase2"},{"type": "null"@@ -6594,6 +6601,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},@@ -7383,7 +7401,7 @@"phase": {"anyOf": [{- "$ref": "#/definitions/MessagePhase"+ "$ref": "#/definitions/MessagePhase2"},{"type": "null"diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.jsonindex b6002dabd3..e540fc68b0 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json@@ -15351,6 +15351,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/v2/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.jsonindex 7fc1dab9b6..1a0ef630a1 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json@@ -236,6 +236,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -360,6 +367,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.jsonindex 5ed713e580..50e7e1e664 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json@@ -236,6 +236,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -360,6 +367,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.jsonindex 6194557811..e71ebbdc7f 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json@@ -350,6 +350,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -474,6 +481,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.jsonindex de1823e9de..214d54ae3a 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json@@ -386,6 +386,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"NetworkAccess": {"enum": ["restricted",@@ -850,6 +857,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.jsonindex 96e3761978..ddda3ca353 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json@@ -373,6 +373,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -656,6 +663,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.jsonindex e0d4cc4f7a..0a478b9f81 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json@@ -373,6 +373,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -656,6 +663,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.jsonindex 4385565f96..d73833f106 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json@@ -386,6 +386,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"NetworkAccess": {"enum": ["restricted",@@ -850,6 +857,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.jsonindex 9f81c5ea7b..63c9f794d5 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json@@ -373,6 +373,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -656,6 +663,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.jsonindex fd75b56a28..4f98fd138c 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json@@ -386,6 +386,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"NetworkAccess": {"enum": ["restricted",@@ -850,6 +857,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.jsonindex 3ad16408ee..5d30115009 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json@@ -373,6 +373,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -656,6 +663,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.jsonindex 3f8bd66861..64487a4127 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json@@ -373,6 +373,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -656,6 +663,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.jsonindex 9fe3517e95..e20e71be29 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json@@ -350,6 +350,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -474,6 +481,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.jsonindex 116ded84cb..4fb088a13e 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json@@ -350,6 +350,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -474,6 +481,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.jsonindex 276ab3b46b..4e7f82f4e5 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json@@ -350,6 +350,13 @@],"type": "string"},+ "MessagePhase": {+ "enum": [+ "commentary",+ "finalAnswer"+ ],+ "type": "string"+ },"PatchApplyStatus": {"enum": ["inProgress",@@ -474,6 +481,17 @@"id": {"type": "string"},+ "phase": {+ "anyOf": [+ {+ "$ref": "#/definitions/MessagePhase"+ },+ {+ "type": "null"+ }+ ],+ "default": null+ },"text": {"type": "string"},diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/MessagePhase.ts b/codex-rs/app-server-protocol/schema/typescript/v2/MessagePhase.tsnew file mode 100644index 0000000000..80d7236e74--- /dev/null+++ b/codex-rs/app-server-protocol/schema/typescript/v2/MessagePhase.ts@@ -0,0 +1,5 @@+// GENERATED CODE! DO NOT MODIFY BY HAND!++// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.++export type MessagePhase = "commentary" | "finalAnswer";diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.tsindex fa098ed3ea..cbdad0bf2b 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts@@ -11,11 +11,12 @@ import type { FileUpdateChange } from "./FileUpdateChange";import type { McpToolCallError } from "./McpToolCallError";import type { McpToolCallResult } from "./McpToolCallResult";import type { McpToolCallStatus } from "./McpToolCallStatus";+import type { MessagePhase } from "./MessagePhase";import type { PatchApplyStatus } from "./PatchApplyStatus";import type { UserInput } from "./UserInput";import type { WebSearchAction } from "./WebSearchAction";-export type ThreadItem = { "type": "userMessage", id: string, content: Array<UserInput>, } | { "type": "agentMessage", id: string, text: string, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array<string>, content: Array<string>, } | { "type": "commandExecution", id: string,+export type ThreadItem = { "type": "userMessage", id: string, content: Array<UserInput>, } | { "type": "agentMessage", id: string, text: string, phase: MessagePhase | null, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array<string>, content: Array<string>, } | { "type": "commandExecution", id: string,/*** The command to be executed.*/diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts b/codex-rs/app-server-protocol/schema/typescript/v2/index.tsindex 8b9453c170..d10b7f7d53 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts@@ -93,6 +93,7 @@ export type { McpToolCallProgressNotification } from "./McpToolCallProgressNotifexport type { McpToolCallResult } from "./McpToolCallResult";export type { McpToolCallStatus } from "./McpToolCallStatus";export type { MergeStrategy } from "./MergeStrategy";+export type { MessagePhase } from "./MessagePhase";export type { Model } from "./Model";export type { ModelListParams } from "./ModelListParams";export type { ModelListResponse } from "./ModelListResponse";diff --git a/codex-rs/app-server-protocol/src/protocol/thread_history.rs b/codex-rs/app-server-protocol/src/protocol/thread_history.rsindex a54b550fd9..bb80010321 100644--- a/codex-rs/app-server-protocol/src/protocol/thread_history.rs+++ b/codex-rs/app-server-protocol/src/protocol/thread_history.rs@@ -149,9 +149,11 @@ impl ThreadHistoryBuilder {}let id = self.next_item_id();- self.ensure_turn()- .items- .push(ThreadItem::AgentMessage { id, text });+ self.ensure_turn().items.push(ThreadItem::AgentMessage {+ id,+ text,+ phase: None,+ });}fn handle_agent_reasoning(&mut self, payload: &AgentReasoningEvent) {@@ -839,6 +841,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-2".into(),text: "Hi there".into(),+ phase: None,});assert_eq!(@@ -869,6 +872,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-5".into(),text: "Reply two".into(),+ phase: None,});}@@ -975,6 +979,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-2".into(),text: "Working...".into(),+ phase: None,});@@ -996,6 +1001,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-4".into(),text: "Second attempt complete.".into(),+ phase: None,});}@@ -1057,6 +1063,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-2".into(),text: "A1".into(),+ phase: None,},]);@@ -1073,6 +1080,7 @@ mod tests {ThreadItem::AgentMessage {id: "item-4".into(),text: "A3".into(),+ phase: None,},]);diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rsindex 52eeaf883a..030d82ce77 100644--- a/codex-rs/app-server-protocol/src/protocol/v2.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2.rs@@ -18,6 +18,7 @@ use codex_protocol::items::TurnItem as CoreTurnItem;use codex_protocol::mcp::Resource as McpResource;use codex_protocol::mcp::ResourceTemplate as McpResourceTemplate;use codex_protocol::mcp::Tool as McpTool;+use codex_protocol::models::MessagePhase as CoreMessagePhase;use codex_protocol::models::ResponseItem;use codex_protocol::openai_models::InputModality;use codex_protocol::openai_models::ReasoningEffort;@@ -2549,6 +2550,24 @@ impl From<CoreUserInput> for UserInput {}}+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]+#[serde(rename_all = "camelCase")]+#[ts(rename_all = "camelCase")]+#[ts(export_to = "v2/")]+pub enum MessagePhase {+ Commentary,+ FinalAnswer,+}++impl From<CoreMessagePhase> for MessagePhase {+ fn from(value: CoreMessagePhase) -> Self {+ match value {+ CoreMessagePhase::Commentary => Self::Commentary,+ CoreMessagePhase::FinalAnswer => Self::FinalAnswer,+ }+ }+}+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]#[serde(tag = "type", rename_all = "camelCase")]#[ts(tag = "type")]@@ -2559,7 +2578,12 @@ pub enum ThreadItem {UserMessage { id: String, content: Vec<UserInput> },#[serde(rename_all = "camelCase")]#[ts(rename_all = "camelCase")]- AgentMessage { id: String, text: String },+ AgentMessage {+ id: String,+ text: String,+ #[serde(default)]+ phase: Option<MessagePhase>,+ },#[serde(rename_all = "camelCase")]#[ts(rename_all = "camelCase")]/// EXPERIMENTAL - proposed plan item content. The completed plan item is@@ -2710,7 +2734,11 @@ impl From<CoreTurnItem> for ThreadItem {CoreAgentMessageContent::Text { text } => text,}).collect::<String>();- ThreadItem::AgentMessage { id: agent.id, text }+ ThreadItem::AgentMessage {+ id: agent.id,+ text,+ phase: agent.phase.map(Into::into),+ }}CoreTurnItem::Plan(plan) => ThreadItem::Plan {id: plan.id,@@ -3485,6 +3513,7 @@ mod tests {use codex_protocol::items::TurnItem;use codex_protocol::items::UserMessageItem;use codex_protocol::items::WebSearchItem;+ use codex_protocol::models::MessagePhase as CoreMessagePhase;use codex_protocol::models::WebSearchAction as CoreWebSearchAction;use codex_protocol::protocol::NetworkAccess as CoreNetworkAccess;use codex_protocol::protocol::ReadOnlyAccess as CoreReadOnlyAccess;@@ -3685,6 +3714,24 @@ mod tests {ThreadItem::AgentMessage {id: "agent-1".to_string(),text: "Hello world".to_string(),+ phase: None,+ }+ );++ let agent_item_with_phase = TurnItem::AgentMessage(AgentMessageItem {+ id: "agent-2".to_string(),+ content: vec![AgentMessageContent::Text {+ text: "final".to_string(),+ }],+ phase: Some(CoreMessagePhase::FinalAnswer),+ });++ assert_eq!(+ ThreadItem::from(agent_item_with_phase),+ ThreadItem::AgentMessage {+ id: "agent-2".to_string(),+ text: "final".to_string(),+ phase: Some(MessagePhase::FinalAnswer),});