mirror of
https://github.com/openai/codex.git
synced 2026-10-26 18:38:47 +00:00
## Why `codex-rs/app-server-protocol/src/protocol/v2.rs` had grown into a single ~12k-line definition file for the entire app-server v2 API. This is purely a mechanical refactor to break up the monolithic `v2.rs` file that contains all app-server API v2 types into more modular files, grouped by resource (e.g. account, thread, turn, etc.). `just write-app-server-schema` shows no real changes, so we can be sure that this is purely an internal organizational change. ## What changed - Replaced the monolithic `protocol/v2.rs` with a `protocol/v2/` module tree and a small `mod.rs` that only declares and reexports modules. - Grouped v2 API definitions by conceptual owner, including `account`, `apps`, `collaboration_mode`, `command_exec`, `config`, `device_key`, `experimental_feature`, `feedback`, `fs`, `hook`, `item`, `mcp`, `model`, `notification`, `permissions`, `plugin`, `process`, `realtime`, `review`, `thread`, `thread_data`, `turn`, and `windows_sandbox`. - Moved v2 tests into `protocol/v2/tests.rs` so `mod.rs` stays small. - Kept shared protocol helpers in `protocol/v2/shared.rs`, including the enum mirroring macro and common cross-resource types. - Co-located resource-specific notifications and server-request payloads with the modules that own those resources. - Regenerated app-server protocol schema fixtures. The schema diffs are non-semantic newline-only changes after the refactor. ## Verification - `cargo check -p codex-app-server-protocol` - `cargo test -p codex-app-server-protocol` - `just write-app-server-schema`
205 lines
7.1 KiB
Rust
205 lines
7.1 KiB
Rust
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use ts_rs::TS;
|
|
|
|
/// Read a file from the host filesystem.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsReadFileParams {
|
|
/// Absolute path to read.
|
|
pub path: AbsolutePathBuf,
|
|
}
|
|
|
|
/// Base64-encoded file contents returned by `fs/readFile`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsReadFileResponse {
|
|
/// File contents encoded as base64.
|
|
pub data_base64: String,
|
|
}
|
|
|
|
/// Write a file on the host filesystem.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsWriteFileParams {
|
|
/// Absolute path to write.
|
|
pub path: AbsolutePathBuf,
|
|
/// File contents encoded as base64.
|
|
pub data_base64: String,
|
|
}
|
|
|
|
/// Successful response for `fs/writeFile`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsWriteFileResponse {}
|
|
|
|
/// Create a directory on the host filesystem.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsCreateDirectoryParams {
|
|
/// Absolute directory path to create.
|
|
pub path: AbsolutePathBuf,
|
|
/// Whether parent directories should also be created. Defaults to `true`.
|
|
#[ts(optional = nullable)]
|
|
pub recursive: Option<bool>,
|
|
}
|
|
|
|
/// Successful response for `fs/createDirectory`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsCreateDirectoryResponse {}
|
|
|
|
/// Request metadata for an absolute path.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsGetMetadataParams {
|
|
/// Absolute path to inspect.
|
|
pub path: AbsolutePathBuf,
|
|
}
|
|
|
|
/// Metadata returned by `fs/getMetadata`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsGetMetadataResponse {
|
|
/// Whether the path resolves to a directory.
|
|
pub is_directory: bool,
|
|
/// Whether the path resolves to a regular file.
|
|
pub is_file: bool,
|
|
/// Whether the path itself is a symbolic link.
|
|
pub is_symlink: bool,
|
|
/// File creation time in Unix milliseconds when available, otherwise `0`.
|
|
#[ts(type = "number")]
|
|
pub created_at_ms: i64,
|
|
/// File modification time in Unix milliseconds when available, otherwise `0`.
|
|
#[ts(type = "number")]
|
|
pub modified_at_ms: i64,
|
|
}
|
|
|
|
/// List direct child names for a directory.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsReadDirectoryParams {
|
|
/// Absolute directory path to read.
|
|
pub path: AbsolutePathBuf,
|
|
}
|
|
|
|
/// A directory entry returned by `fs/readDirectory`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsReadDirectoryEntry {
|
|
/// Direct child entry name only, not an absolute or relative path.
|
|
pub file_name: String,
|
|
/// Whether this entry resolves to a directory.
|
|
pub is_directory: bool,
|
|
/// Whether this entry resolves to a regular file.
|
|
pub is_file: bool,
|
|
}
|
|
|
|
/// Directory entries returned by `fs/readDirectory`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsReadDirectoryResponse {
|
|
/// Direct child entries in the requested directory.
|
|
pub entries: Vec<FsReadDirectoryEntry>,
|
|
}
|
|
|
|
/// Remove a file or directory tree from the host filesystem.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsRemoveParams {
|
|
/// Absolute path to remove.
|
|
pub path: AbsolutePathBuf,
|
|
/// Whether directory removal should recurse. Defaults to `true`.
|
|
#[ts(optional = nullable)]
|
|
pub recursive: Option<bool>,
|
|
/// Whether missing paths should be ignored. Defaults to `true`.
|
|
#[ts(optional = nullable)]
|
|
pub force: Option<bool>,
|
|
}
|
|
|
|
/// Successful response for `fs/remove`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsRemoveResponse {}
|
|
|
|
/// Copy a file or directory tree on the host filesystem.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsCopyParams {
|
|
/// Absolute source path.
|
|
pub source_path: AbsolutePathBuf,
|
|
/// Absolute destination path.
|
|
pub destination_path: AbsolutePathBuf,
|
|
/// Required for directory copies; ignored for file copies.
|
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
pub recursive: bool,
|
|
}
|
|
|
|
/// Successful response for `fs/copy`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsCopyResponse {}
|
|
|
|
/// Start filesystem watch notifications for an absolute path.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsWatchParams {
|
|
/// Connection-scoped watch identifier used for `fs/unwatch` and `fs/changed`.
|
|
pub watch_id: String,
|
|
/// Absolute file or directory path to watch.
|
|
pub path: AbsolutePathBuf,
|
|
}
|
|
|
|
/// Successful response for `fs/watch`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsWatchResponse {
|
|
/// Canonicalized path associated with the watch.
|
|
pub path: AbsolutePathBuf,
|
|
}
|
|
|
|
/// Stop filesystem watch notifications for a prior `fs/watch`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsUnwatchParams {
|
|
/// Watch identifier previously provided to `fs/watch`.
|
|
pub watch_id: String,
|
|
}
|
|
|
|
/// Successful response for `fs/unwatch`.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsUnwatchResponse {}
|
|
|
|
/// Filesystem watch notification emitted for `fs/watch` subscribers.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export_to = "v2/")]
|
|
pub struct FsChangedNotification {
|
|
/// Watch identifier previously provided to `fs/watch`.
|
|
pub watch_id: String,
|
|
/// File or directory paths associated with this event.
|
|
pub changed_paths: Vec<AbsolutePathBuf>,
|
|
}
|