Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions codex-rs/app-server-protocol/src/bin/write_schema_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ struct Args {
/// Optional path to the Prettier executable to format generated TypeScript files.
#[arg(short = 'p', long = "prettier", value_name = "PRETTIER_BIN")]
prettier: Option<PathBuf>,

/// Include experimental API methods and fields in generated fixtures.
#[arg(long = "experimental")]
experimental: bool,
}

fn main() -> Result<()> {
Expand All @@ -22,11 +26,17 @@ fn main() -> Result<()> {
.schema_root
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("schema"));

codex_app_server_protocol::write_schema_fixtures(&schema_root, args.prettier.as_deref())
.with_context(|| {
format!(
"failed to regenerate schema fixtures under {}",
schema_root.display()
)
})
codex_app_server_protocol::write_schema_fixtures_with_options(
&schema_root,
args.prettier.as_deref(),
codex_app_server_protocol::SchemaFixtureOptions {
experimental_api: args.experimental,
},
)
.with_context(|| {
format!(
"failed to regenerate schema fixtures under {}",
schema_root.display()
)
})
}
2 changes: 2 additions & 0 deletions codex-rs/app-server-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ pub use protocol::common::*;
pub use protocol::thread_history::*;
pub use protocol::v1::*;
pub use protocol::v2::*;
pub use schema_fixtures::SchemaFixtureOptions;
pub use schema_fixtures::read_schema_fixture_tree;
pub use schema_fixtures::write_schema_fixtures;
pub use schema_fixtures::write_schema_fixtures_with_options;
25 changes: 23 additions & 2 deletions codex-rs/app-server-protocol/src/schema_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use std::collections::BTreeMap;
use std::path::Path;
use std::path::PathBuf;

#[derive(Clone, Copy, Debug, Default)]
pub struct SchemaFixtureOptions {
pub experimental_api: bool,
}

pub fn read_schema_fixture_tree(schema_root: &Path) -> Result<BTreeMap<PathBuf, Vec<u8>>> {
let typescript_root = schema_root.join("typescript");
let json_root = schema_root.join("json");
Expand All @@ -26,14 +31,30 @@ pub fn read_schema_fixture_tree(schema_root: &Path) -> Result<BTreeMap<PathBuf,
/// This is intended to be used by tooling (e.g., `just write-app-server-schema`).
/// It deletes any previously generated files so stale artifacts are removed.
pub fn write_schema_fixtures(schema_root: &Path, prettier: Option<&Path>) -> Result<()> {
write_schema_fixtures_with_options(schema_root, prettier, SchemaFixtureOptions::default())
}

/// Regenerates schema fixtures with configurable options.
pub fn write_schema_fixtures_with_options(
schema_root: &Path,
prettier: Option<&Path>,
options: SchemaFixtureOptions,
) -> Result<()> {
let typescript_out_dir = schema_root.join("typescript");
let json_out_dir = schema_root.join("json");

ensure_empty_dir(&typescript_out_dir)?;
ensure_empty_dir(&json_out_dir)?;

crate::generate_ts(&typescript_out_dir, prettier)?;
crate::generate_json(&json_out_dir)?;
crate::generate_ts_with_options(
&typescript_out_dir,
prettier,
crate::GenerateTsOptions {
experimental_api: options.experimental_api,
..crate::GenerateTsOptions::default()
},
)?;
crate::generate_json_with_experimental(&json_out_dir, options.experimental_api)?;

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/app-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ At runtime, clients must send `initialize` with `capabilities.experimentalApi =

```bash
just write-app-server-schema
# Include experimental API fields/methods in fixtures.
just write-app-server-schema --experimental
```

5. Verify the protocol crate:
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ write-config-schema:
cargo run -p codex-core --bin codex-write-config-schema

# Regenerate vendored app-server protocol schema artifacts.
write-app-server-schema:
cargo run -p codex-app-server-protocol --bin write_schema_fixtures
write-app-server-schema *args:
cargo run -p codex-app-server-protocol --bin write_schema_fixtures -- "$@"

# Tail logs from the state SQLite database
log *args:
Expand Down
Loading