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.json index 8874038ff7..5e38bd3bb2 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 @@ -13093,6 +13093,15 @@ "description": "File modification time in Unix milliseconds when available, otherwise `0`.", "format": "int64", "type": "integer" + }, + "sizeBytes": { + "description": "Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field.", + "format": "uint64", + "minimum": 0.0, + "type": [ + "integer", + "null" + ] } }, "required": [ diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json index 7e5251909a..a0a5e5005c 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json @@ -8847,6 +8847,15 @@ "description": "File modification time in Unix milliseconds when available, otherwise `0`.", "format": "int64", "type": "integer" + }, + "sizeBytes": { + "description": "Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field.", + "format": "uint64", + "minimum": 0.0, + "type": [ + "integer", + "null" + ] } }, "required": [ diff --git a/codex-rs/app-server-protocol/schema/json/v2/FsGetMetadataResponse.json b/codex-rs/app-server-protocol/schema/json/v2/FsGetMetadataResponse.json index 82481f579e..cb93304d04 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/FsGetMetadataResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/FsGetMetadataResponse.json @@ -23,6 +23,15 @@ "description": "File modification time in Unix milliseconds when available, otherwise `0`.", "format": "int64", "type": "integer" + }, + "sizeBytes": { + "description": "Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field.", + "format": "uint64", + "minimum": 0.0, + "type": [ + "integer", + "null" + ] } }, "required": [ diff --git a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst index 513695ad22..d5b2615a05 100644 Binary files a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst and b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-experimental.json.zst differ diff --git a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst index aa51c941b1..4617198971 100644 Binary files a/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst and b/codex-rs/app-server-protocol/schema/precomputed/app-server-exports-stable.json.zst differ diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/FsGetMetadataResponse.ts b/codex-rs/app-server-protocol/schema/typescript/v2/FsGetMetadataResponse.ts index a1a127e192..18f83b8a38 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/FsGetMetadataResponse.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/FsGetMetadataResponse.ts @@ -25,4 +25,8 @@ createdAtMs: number, /** * File modification time in Unix milliseconds when available, otherwise `0`. */ -modifiedAtMs: number, }; +modifiedAtMs: number, +/** + * Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field. + */ +sizeBytes?: number | null, }; diff --git a/codex-rs/app-server-protocol/src/export.rs b/codex-rs/app-server-protocol/src/export.rs index a92644a655..dd0119bbda 100644 --- a/codex-rs/app-server-protocol/src/export.rs +++ b/codex-rs/app-server-protocol/src/export.rs @@ -2414,8 +2414,10 @@ mod tests { // These are only allowed in *Params types, except additive stable fields // that older servers omit and newer servers may return as null. let legacy_optional_nullable_field = (path - == Path::new("v2/GetAccountTokenUsageResponse.ts") - && field_prefix.trim() == "threadUsage?") + == Path::new("v2/FsGetMetadataResponse.ts") + && field_prefix.trim() == "sizeBytes?") + || (path == Path::new("v2/GetAccountTokenUsageResponse.ts") + && field_prefix.trim() == "threadUsage?") || (path == Path::new("v2/ThreadUsage.ts") && field_prefix.trim() == "nativeUsageUsdMicros?") || (path == Path::new("v2/ThreadItem.ts") diff --git a/codex-rs/app-server-protocol/src/protocol/v2/fs.rs b/codex-rs/app-server-protocol/src/protocol/v2/fs.rs index 6f9ea822e5..59e24230ab 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/fs.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/fs.rs @@ -107,6 +107,9 @@ pub struct FsGetMetadataResponse { /// File modification time in Unix milliseconds when available, otherwise `0`. #[ts(type = "number")] pub modified_at_ms: i64, + /// Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field. + #[ts(type = "number | null", optional)] + pub size_bytes: Option, } /// List direct child names for a directory. diff --git a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs index c5ae40cbf1..867372b9dc 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs @@ -1271,6 +1271,7 @@ fn fs_get_metadata_response_round_trips_minimal_fields() { is_symlink: false, created_at_ms: 123, modified_at_ms: 456, + size_bytes: Some(5), }; let value = serde_json::to_value(&response).expect("serialize fs/getMetadata response"); @@ -1282,12 +1283,28 @@ fn fs_get_metadata_response_round_trips_minimal_fields() { "isSymlink": false, "createdAtMs": 123, "modifiedAtMs": 456, + "sizeBytes": 5, }) ); - let decoded = serde_json::from_value::(value) + let decoded = serde_json::from_value::(value.clone()) .expect("deserialize fs/getMetadata response"); assert_eq!(decoded, response); + + let mut legacy_value = value; + legacy_value + .as_object_mut() + .expect("metadata object") + .remove("sizeBytes"); + let legacy = serde_json::from_value::(legacy_value) + .expect("deserialize fs/getMetadata response from an older server"); + assert_eq!( + legacy, + FsGetMetadataResponse { + size_bytes: None, + ..response + } + ); } #[test] diff --git a/codex-rs/app-server/src/request_processors/fs_processor.rs b/codex-rs/app-server/src/request_processors/fs_processor.rs index d48df12aa2..b97c9b6838 100644 --- a/codex-rs/app-server/src/request_processors/fs_processor.rs +++ b/codex-rs/app-server/src/request_processors/fs_processor.rs @@ -126,6 +126,7 @@ impl FsRequestProcessor { is_symlink: metadata.is_symlink, created_at_ms: metadata.created_at_ms, modified_at_ms: metadata.modified_at_ms, + size_bytes: metadata.is_file.then_some(metadata.size), }) } diff --git a/codex-rs/app-server/tests/suite/v2/fs.rs b/codex-rs/app-server/tests/suite/v2/fs.rs index 295b3b2611..6d27430e1e 100644 --- a/codex-rs/app-server/tests/suite/v2/fs.rs +++ b/codex-rs/app-server/tests/suite/v2/fs.rs @@ -70,7 +70,7 @@ fn absolute_path(path: PathBuf) -> AbsolutePathBuf { } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn fs_get_metadata_returns_only_used_fields() -> Result<()> { +async fn fs_get_metadata_returns_file_size() -> Result<()> { let codex_home = TempDir::new()?; let file_path = codex_home.path().join("note.txt"); std::fs::write(&file_path, "hello")?; @@ -87,23 +87,6 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> { ) .await??; - let result = response - .result - .as_object() - .context("fs/getMetadata result should be an object")?; - let mut keys = result.keys().cloned().collect::>(); - keys.sort(); - assert_eq!( - keys, - vec![ - "createdAtMs".to_string(), - "isDirectory".to_string(), - "isFile".to_string(), - "isSymlink".to_string(), - "modifiedAtMs".to_string(), - ] - ); - let stat: FsGetMetadataResponse = to_response(response)?; assert_eq!( stat, @@ -113,6 +96,7 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> { is_symlink: false, created_at_ms: stat.created_at_ms, modified_at_ms: stat.modified_at_ms, + size_bytes: Some(5), } ); assert!( @@ -120,6 +104,18 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> { "modifiedAtMs should be populated for existing files" ); + let request_id = mcp + .send_fs_get_metadata_request(codex_app_server_protocol::FsGetMetadataParams { + path: absolute_path(codex_home.path().to_path_buf()), + }) + .await?; + let response = timeout( + DEFAULT_READ_TIMEOUT, + mcp.read_stream_until_response_message(RequestId::Integer(request_id)), + ) + .await??; + assert_eq!(response.result.get("sizeBytes"), Some(&json!(null))); + Ok(()) } @@ -168,9 +164,16 @@ async fn fs_get_metadata_reports_symlink() -> Result<()> { .await??; let stat: FsGetMetadataResponse = to_response(response)?; - assert_eq!(stat.is_directory, false); - assert_eq!(stat.is_file, true); - assert_eq!(stat.is_symlink, true); + assert_eq!( + stat, + FsGetMetadataResponse { + is_directory: false, + is_file: true, + is_symlink: true, + size_bytes: Some(5), + ..stat + } + ); Ok(()) } diff --git a/sdk/python/src/openai_codex/generated/v2_all.py b/sdk/python/src/openai_codex/generated/v2_all.py index 5c6a39119a..d345343240 100644 --- a/sdk/python/src/openai_codex/generated/v2_all.py +++ b/sdk/python/src/openai_codex/generated/v2_all.py @@ -1671,6 +1671,14 @@ class FsGetMetadataResponse(BaseModel): description="File modification time in Unix milliseconds when available, otherwise `0`.", ), ] + size_bytes: Annotated[ + int | None, + Field( + alias="sizeBytes", + description="Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field.", + ge=0, + ), + ] = None class FsReadDirectoryEntry(BaseModel):