mirror of
https://github.com/openai/codex.git
synced 2026-10-19 16:17:49 +00:00
Organize bundled Rust resources under asset directories (#41477)
## Why The `core` and `tui` Bazel targets treated nearly their entire crate trees as compile-time data, mixing embedded runtime resources with source files and test fixtures. ## What changed - Move embedded resources for `core` and `tui` into dedicated `assets/` directories and update their `include_str!` paths. - Restrict Bazel compile data to explicit asset and frame directories. - Move test-only prompts into `tests/fixtures`, resolve the core prompt through `find_resource!`, and reuse the integration-test file glob when assembling Bazel test data. GitOrigin-RevId: eee9b0e41df77ea2604215a7f7333a6fe8317bfa
This commit is contained in:
committed by
copyberry
parent
9a0d7a7cd0
commit
6478a751fd
@@ -2,15 +2,7 @@ load("//:defs.bzl", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "core",
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
"BUILD.bazel",
|
||||
"Cargo.toml",
|
||||
],
|
||||
),
|
||||
compile_data = glob(["assets/**"]),
|
||||
crate_name = "codex_core",
|
||||
extra_binaries = [
|
||||
"//codex-rs/bwrap:bwrap",
|
||||
@@ -22,7 +14,7 @@ codex_rust_crate(
|
||||
"//codex-rs/windows-sandbox-rs:codex-command-runner",
|
||||
"//codex-rs/windows-sandbox-rs:codex-windows-sandbox-setup",
|
||||
],
|
||||
integration_compile_data_extra = ["src/guardian/node_repl_policy.md"],
|
||||
integration_compile_data_extra = glob(["assets/**"]),
|
||||
integration_test_timeout = "long",
|
||||
run_tests_with_wine_exec = True,
|
||||
rustc_env = {
|
||||
@@ -34,6 +26,7 @@ codex_rust_crate(
|
||||
"config.schema.json",
|
||||
] + glob([
|
||||
"src/**/snapshots/**",
|
||||
"tests/fixtures/**",
|
||||
]) + [
|
||||
# This is a bit of a hack, but empirically, some of our integration tests
|
||||
# are relying on the presence of this file as a repo root marker. When
|
||||
|
||||
@@ -19,7 +19,7 @@ use codex_protocol::intersect_effective_permission_profiles;
|
||||
use codex_protocol::protocol::EnvironmentConfigState;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
const AGENT_NAMES: &str = include_str!("../agent_names.txt");
|
||||
const AGENT_NAMES: &str = include_str!("../../../assets/agent/agent_names.txt");
|
||||
|
||||
struct SpawnAgentThreadInheritance {
|
||||
environments: Option<TurnEnvironmentSnapshot>,
|
||||
|
||||
@@ -405,8 +405,8 @@ Rules:
|
||||
|
||||
/// Resolves a built-in role `config_file` path to embedded content.
|
||||
pub(super) fn config_file_contents(path: &Path) -> Option<&'static str> {
|
||||
const EXPLORER: &str = include_str!("builtins/explorer.toml");
|
||||
const AWAITER: &str = include_str!("builtins/awaiter.toml");
|
||||
const EXPLORER: &str = include_str!("../../assets/agent/builtins/explorer.toml");
|
||||
const AWAITER: &str = include_str!("../../assets/agent/builtins/awaiter.toml");
|
||||
match path.to_str()? {
|
||||
"explorer.toml" => Some(EXPLORER),
|
||||
"awaiter.toml" => Some(AWAITER),
|
||||
|
||||
@@ -22,6 +22,6 @@ impl ContextualUserFragment for GuardianNodeReplPolicy {
|
||||
}
|
||||
|
||||
fn body(&self) -> String {
|
||||
include_str!("../guardian/node_repl_policy.md").to_string()
|
||||
include_str!("../../assets/guardian/node_repl_policy.md").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use codex_protocol::openai_models::ReasoningEffort;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
const DEFAULT_INSTRUCTIONS: &str = include_str!("../../../templates/persistent_mode.md");
|
||||
const DEFAULT_INSTRUCTIONS: &str = include_str!("../../../assets/persistent_mode.md");
|
||||
const REPLACEMENT_NOTICE: &str = "These persistent-mode instructions replace all previously provided persistent-mode instructions.";
|
||||
const REMOVAL_NOTICE: &str =
|
||||
"The previously provided persistent-mode instructions no longer apply.";
|
||||
|
||||
@@ -819,8 +819,9 @@ For anything else, use this JSON schema:
|
||||
}"#
|
||||
}
|
||||
|
||||
pub(crate) const BUNDLED_GUARDIAN_POLICY: &str = include_str!("policy.md");
|
||||
pub(crate) const BUNDLED_GUARDIAN_POLICY_TEMPLATE: &str = include_str!("policy_template.md");
|
||||
pub(crate) const BUNDLED_GUARDIAN_POLICY: &str = include_str!("../../assets/guardian/policy.md");
|
||||
pub(crate) const BUNDLED_GUARDIAN_POLICY_TEMPLATE: &str =
|
||||
include_str!("../../assets/guardian/policy_template.md");
|
||||
const TENANT_POLICY_CONFIG_PLACEHOLDER: &str = "{{ tenant_policy_config }}";
|
||||
|
||||
/// Guardian policy prompt.
|
||||
|
||||
@@ -70,7 +70,7 @@ pub(crate) fn render_mcp_tool_approval_template(
|
||||
|
||||
fn load_consequential_tool_message_templates() -> Option<Vec<ConsequentialToolMessageTemplate>> {
|
||||
let templates = match serde_json::from_str::<ConsequentialToolMessageTemplatesFile>(
|
||||
include_str!("consequential_tool_message_templates.json"),
|
||||
include_str!("../assets/consequential_tool_message_templates.json"),
|
||||
) {
|
||||
Ok(templates) => templates,
|
||||
Err(err) => {
|
||||
|
||||
@@ -1613,8 +1613,12 @@ async fn user_shell_commands_remain_login_shells_when_model_login_shells_are_dis
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_base_instructions_no_user_content() {
|
||||
let prompt_path = codex_utils_cargo_bin::find_resource!(
|
||||
"tests/fixtures/prompt_with_apply_patch_instructions.md"
|
||||
)
|
||||
.expect("resolve prompt fixture path");
|
||||
let prompt_with_apply_patch_instructions =
|
||||
include_str!("../../prompt_with_apply_patch_instructions.md");
|
||||
std::fs::read_to_string(prompt_path).expect("read prompt fixture");
|
||||
let models_response = bundled_models_response()
|
||||
.unwrap_or_else(|err| panic!("bundled models.json should parse: {err}"));
|
||||
let model_info_for_slug = |slug: &str, config: &Config| {
|
||||
|
||||
@@ -2,7 +2,7 @@ use codex_tools::FreeformTool;
|
||||
use codex_tools::FreeformToolFormat;
|
||||
use codex_tools::ToolSpec;
|
||||
|
||||
const APPLY_PATCH_LARK_GRAMMAR: &str = include_str!("apply_patch.lark");
|
||||
const APPLY_PATCH_LARK_GRAMMAR: &str = include_str!("../../../assets/tools/apply_patch.lark");
|
||||
|
||||
/// Returns a custom tool that can be used to edit files. Well-suited for GPT-5 models
|
||||
/// https://platform.openai.com/docs/guides/function-calling#custom-tools
|
||||
|
||||
@@ -753,7 +753,7 @@ async fn guardian_node_repl_policy_follows_production_approval_path(
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(guardian_requests.len(), actions.len());
|
||||
|
||||
let policy = include_str!("../../src/guardian/node_repl_policy.md");
|
||||
let policy = include_str!("../../assets/guardian/node_repl_policy.md");
|
||||
let first_guardian_thread = guardian_requests[0].body_json()["client_metadata"]["thread_id"]
|
||||
.as_str()
|
||||
.expect("Guardian reviewer thread id")
|
||||
|
||||
@@ -2,18 +2,10 @@ load("//:defs.bzl", "MACOS_WEBRTC_RUSTC_LINK_FLAGS", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "tui",
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
"BUILD.bazel",
|
||||
"Cargo.toml",
|
||||
],
|
||||
) + [
|
||||
"//codex-rs/collaboration-mode-templates:templates/default.md",
|
||||
"//codex-rs/collaboration-mode-templates:templates/plan.md",
|
||||
],
|
||||
compile_data = glob([
|
||||
"assets/**",
|
||||
"frames/**",
|
||||
]),
|
||||
crate_name = "codex_tui",
|
||||
extra_binaries = [
|
||||
"//codex-rs/cli:codex",
|
||||
@@ -23,6 +15,7 @@ codex_rust_crate(
|
||||
test_data_extra = glob([
|
||||
"src/**/*.rs",
|
||||
"src/**/snapshots/**",
|
||||
"tests/fixtures/**",
|
||||
]),
|
||||
test_shard_counts = {
|
||||
"tui-unit-tests": 8,
|
||||
|
||||
@@ -258,7 +258,7 @@ impl ChatWidget {
|
||||
.send(AppEvent::OpenDesktopThread { thread_id });
|
||||
}
|
||||
SlashCommand::Init => {
|
||||
const INIT_PROMPT: &str = include_str!("../../prompt_for_init_command.md");
|
||||
const INIT_PROMPT: &str = include_str!("../../assets/prompt_for_init_command.md");
|
||||
self.submit_user_message(INIT_PROMPT.to_string().into());
|
||||
}
|
||||
SlashCommand::Compact => {
|
||||
|
||||
@@ -10,8 +10,8 @@ const FRAGMENT_PLACEHOLDER: &str = "<!--__INLINE_VISUALIZATION_FRAGMENT__-->";
|
||||
const VIEWER_DIRECTORY_NAME: &str = ".codex-viewers";
|
||||
|
||||
// Keep these assets in sync with the bundled visualize skill's browser renderer.
|
||||
const VIEWER_STYLESHEET: &str = include_str!("assets/visualize.css");
|
||||
const VIEWER_RUNTIME: &str = include_str!("assets/visualize.html");
|
||||
const VIEWER_STYLESHEET: &str = include_str!("../../assets/inline_visualization/visualize.css");
|
||||
const VIEWER_RUNTIME: &str = include_str!("../../assets/inline_visualization/visualize.html");
|
||||
|
||||
const FRAME_CSP: &str = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob: data: https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://esm.sh https://fonts.bunny.net https://fonts.googleapis.com https://fonts.gstatic.com https://unpkg.com; style-src 'unsafe-inline' blob: data: https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://esm.sh https://fonts.bunny.net https://fonts.googleapis.com https://fonts.gstatic.com https://unpkg.com; img-src blob: data: https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://esm.sh https://fonts.bunny.net https://fonts.googleapis.com https://fonts.gstatic.com https://unpkg.com; font-src blob: data: https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://esm.sh https://fonts.bunny.net https://fonts.googleapis.com https://fonts.gstatic.com https://unpkg.com; media-src blob: data:; worker-src blob:; connect-src blob: data:; frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'";
|
||||
const SHELL_STYLE: &str = ":root{color-scheme:light dark;background:light-dark(rgb(255 255 255), rgb(24 24 24))}html,body{margin:0}body{box-sizing:border-box;padding:1rem;background:inherit}iframe{display:block;width:100%;max-width:736px;height:calc(100vh - 2rem);margin:0 auto;border:0}";
|
||||
|
||||
@@ -20,7 +20,7 @@ const OTHER_TOOLTIP_NON_MAC: &str = "*New* Build faster with Codex.";
|
||||
const FREE_GO_TOOLTIP: &str =
|
||||
"*New* For a limited time, Codex is included in your plan for free – let’s build together.";
|
||||
|
||||
const RAW_TOOLTIPS: &str = include_str!("../tooltips.txt");
|
||||
const RAW_TOOLTIPS: &str = include_str!("../assets/tooltips.txt");
|
||||
|
||||
lazy_static! {
|
||||
static ref TOOLTIPS: Vec<&'static str> = RAW_TOOLTIPS
|
||||
|
||||
@@ -458,10 +458,11 @@ def codex_rust_crate(
|
||||
integration_test_binaries = sanitized_binaries
|
||||
integration_test_cargo_env = cargo_env
|
||||
integration_test_cargo_env_runfiles = cargo_env_runfiles
|
||||
integration_test_files = native.glob(["tests/**"], allow_empty = True)
|
||||
integration_test_data_extra = [
|
||||
data
|
||||
for data in test_data_extra
|
||||
if data not in cargo_env_runfiles
|
||||
if data not in cargo_env_runfiles and data not in integration_test_files
|
||||
]
|
||||
non_windows_sanitized_binaries = []
|
||||
non_windows_cargo_env = {}
|
||||
@@ -545,8 +546,8 @@ def codex_rust_crate(
|
||||
crate_name = test_crate_name,
|
||||
crate_root = test,
|
||||
srcs = [test],
|
||||
data = native.glob(["tests/**"], allow_empty = True) + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = native.glob(["tests/**"], allow_empty = True) + integration_compile_data_extra,
|
||||
data = integration_test_files + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = integration_test_files + integration_compile_data_extra,
|
||||
deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra,
|
||||
# Bazel has emitted both `codex-rs/<crate>/...` and
|
||||
# `../codex-rs/<crate>/...` paths for `file!()`. Strip either
|
||||
@@ -585,8 +586,8 @@ def codex_rust_crate(
|
||||
crate_name = test_crate_name,
|
||||
crate_root = test,
|
||||
srcs = [test],
|
||||
data = native.glob(["tests/**"], allow_empty = True) + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = native.glob(["tests/**"], allow_empty = True) + integration_compile_data_extra,
|
||||
data = integration_test_files + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = integration_test_files + integration_compile_data_extra,
|
||||
deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra,
|
||||
# Bazel has emitted both `codex-rs/<crate>/...` and
|
||||
# `../codex-rs/<crate>/...` paths for `file!()`. Strip either
|
||||
@@ -660,8 +661,8 @@ def codex_rust_crate(
|
||||
crate_name = test_crate_name,
|
||||
crate_root = test,
|
||||
srcs = [test],
|
||||
data = native.glob(["tests/**"], allow_empty = True) + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = native.glob(["tests/**"], allow_empty = True) + integration_compile_data_extra,
|
||||
data = integration_test_files + integration_test_binaries + integration_test_data_extra,
|
||||
compile_data = integration_test_files + integration_compile_data_extra,
|
||||
deps = all_crate_deps(normal = True, normal_dev = True) + maybe_deps + deps_extra,
|
||||
rustc_flags = rustc_flags_extra + WINDOWS_RUSTC_LINK_FLAGS + [
|
||||
"--remap-path-prefix=../codex-rs=",
|
||||
|
||||
Reference in New Issue
Block a user