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
5 changes: 5 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions codex-rs/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ version.workspace = true
edition.workspace = true
license.workspace = true

[[example]]
name = "generate-proto"
path = "examples/generate-proto.rs"

[lints]
workspace = true

Expand All @@ -21,6 +25,7 @@ codex-utils-path = { workspace = true }
futures = { workspace = true, features = ["alloc", "std"] }
gethostname = { workspace = true }
multimap = { workspace = true }
prost = "0.14.3"
schemars = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand All @@ -30,6 +35,8 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
toml = { workspace = true }
toml_edit = { workspace = true }
tonic = { workspace = true }
tonic-prost = { workspace = true }
tracing = { workspace = true }
wildmatch = { workspace = true }

Expand All @@ -44,3 +51,6 @@ winapi-util = { workspace = true }
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-stream = { workspace = true, features = ["net"] }
tonic = { workspace = true, features = ["router", "transport"] }
tonic-prost-build = { version = "=0.14.3", default-features = false, features = ["transport"] }
19 changes: 19 additions & 0 deletions codex-rs/config/examples/generate-proto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would love a better place to put the proto generation than examples but I couldn't figure out a better way to do it with the repo build rules

let Some(proto_dir_arg) = std::env::args().nth(1) else {
eprintln!("Usage: generate-proto <proto-dir>");
std::process::exit(1);
};

let proto_dir = PathBuf::from(proto_dir_arg);
let proto_file = proto_dir.join("codex.thread_config.v1.proto");

tonic_prost_build::configure()
.build_client(true)
.build_server(true)
.out_dir(&proto_dir)
.compile_protos(&[proto_file], &[proto_dir])?;

Ok(())
}
38 changes: 38 additions & 0 deletions codex-rs/config/scripts/generate-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "$script_dir/../../.." && pwd)"
proto_dir="$repo_root/codex-rs/config/src/thread_config/proto"
generated="$proto_dir/codex.thread_config.v1.rs"
tmpdir="$(mktemp -d)"

cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT

(
cd "$repo_root/codex-rs"
CARGO_TARGET_DIR="$tmpdir/target" cargo run \
-p codex-config \
--example generate-proto \
-- "$proto_dir"
)

if ! sed -n '2p' "$generated" | grep -q 'clippy::trivially_copy_pass_by_ref'; then
{
sed -n '1p' "$generated"
printf '#![allow(clippy::trivially_copy_pass_by_ref)]\n'
sed '1d' "$generated"
} > "$tmpdir/generated.rs"
mv "$tmpdir/generated.rs" "$generated"
fi

rustfmt --edition 2024 "$generated"

awk '
NR == 3 && previous ~ /clippy::trivially_copy_pass_by_ref/ && $0 != "" { print "" }
{ print; previous = $0 }
' "$generated" > "$tmpdir/formatted.rs"
mv "$tmpdir/formatted.rs" "$generated"
1 change: 1 addition & 0 deletions codex-rs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub use state::ConfigLayerStack;
pub use state::ConfigLayerStackOrdering;
pub use state::LoaderOverrides;
pub use thread_config::NoopThreadConfigLoader;
pub use thread_config::RemoteThreadConfigLoader;
pub use thread_config::SessionThreadConfig;
pub use thread_config::StaticThreadConfigLoader;
pub use thread_config::ThreadConfigContext;
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/config/src/thread_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use toml::Value as TomlValue;

use crate::ConfigLayerEntry;

mod remote;

pub use remote::RemoteThreadConfigLoader;

/// Context available to implementations when loading thread-scoped config.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct ThreadConfigContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
syntax = "proto3";

package codex.thread_config.v1;

service ThreadConfigLoader {
rpc Load(LoadThreadConfigRequest) returns (LoadThreadConfigResponse);
}

message LoadThreadConfigRequest {
optional string thread_id = 1;
optional string cwd = 2;
}

message LoadThreadConfigResponse {
repeated ThreadConfigSource sources = 1;
}

message ThreadConfigSource {
oneof source {
SessionThreadConfig session = 1;
UserThreadConfig user = 2;
}
}

message SessionThreadConfig {
optional string model_provider = 1;
repeated ModelProvider model_providers = 2;
map<string, bool> features = 3;
}

message UserThreadConfig {}

message ModelProvider {
string id = 1;
string name = 2;
optional string base_url = 3;
optional string env_key = 4;
optional string env_key_instructions = 5;
optional string experimental_bearer_token = 6;
optional ModelProviderAuthInfo auth = 7;
WireApi wire_api = 8;
optional StringMap query_params = 9;
optional StringMap http_headers = 10;
optional StringMap env_http_headers = 11;
optional uint64 request_max_retries = 12;
optional uint64 stream_max_retries = 13;
optional uint64 stream_idle_timeout_ms = 14;
optional uint64 websocket_connect_timeout_ms = 15;
bool requires_openai_auth = 16;
bool supports_websockets = 17;
}

message StringMap {
map<string, string> values = 1;
}

message ModelProviderAuthInfo {
string command = 1;
repeated string args = 2;
uint64 timeout_ms = 3;
uint64 refresh_interval_ms = 4;
string cwd = 5;
}

enum WireApi {
WIRE_API_UNSPECIFIED = 0;
WIRE_API_RESPONSES = 1;
}
Loading
Loading