mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Render multi-environment skills with env context
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use codex_core_skills::AvailableSkills;
|
||||
use codex_core_skills::SkillEnvironmentRender;
|
||||
use codex_core_skills::render_available_skills_body;
|
||||
use codex_protocol::protocol::SKILLS_INSTRUCTIONS_CLOSE_TAG;
|
||||
use codex_protocol::protocol::SKILLS_INSTRUCTIONS_OPEN_TAG;
|
||||
@@ -9,6 +10,7 @@ use super::ContextualUserFragment;
|
||||
pub(crate) struct AvailableSkillsInstructions {
|
||||
skill_root_lines: Vec<String>,
|
||||
skill_lines: Vec<String>,
|
||||
environment_render: SkillEnvironmentRender,
|
||||
}
|
||||
|
||||
impl From<AvailableSkills> for AvailableSkillsInstructions {
|
||||
@@ -16,6 +18,7 @@ impl From<AvailableSkills> for AvailableSkillsInstructions {
|
||||
Self {
|
||||
skill_root_lines: available_skills.skill_root_lines,
|
||||
skill_lines: available_skills.skill_lines,
|
||||
environment_render: available_skills.environment_render,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +37,10 @@ impl ContextualUserFragment for AvailableSkillsInstructions {
|
||||
}
|
||||
|
||||
fn body(&self) -> String {
|
||||
render_available_skills_body(&self.skill_root_lines, &self.skill_lines)
|
||||
render_available_skills_body(
|
||||
&self.skill_root_lines,
|
||||
&self.skill_lines,
|
||||
self.environment_render,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2744,6 +2744,11 @@ impl Session {
|
||||
let available_skills = build_available_skills(
|
||||
&turn_context.turn_skills.outcome,
|
||||
default_skill_metadata_budget(turn_context.model_info.context_window),
|
||||
if turn_context.environments.turn_environments.len() > 1 {
|
||||
crate::skills::render::SkillEnvironmentRender::Include
|
||||
} else {
|
||||
crate::skills::render::SkillEnvironmentRender::Omit
|
||||
},
|
||||
SkillRenderSideEffects::ThreadStart {
|
||||
session_telemetry: &self.services.session_telemetry,
|
||||
},
|
||||
|
||||
@@ -7255,7 +7255,11 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget()
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Admin,
|
||||
plugin_id: None,
|
||||
},
|
||||
@@ -7266,7 +7270,11 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget()
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
},
|
||||
@@ -7302,13 +7310,18 @@ fn emit_thread_start_skill_metrics_records_enabled_kept_and_truncated_values() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
}];
|
||||
let rendered = build_available_skills(
|
||||
&outcome,
|
||||
SkillMetadataBudget::Characters(1),
|
||||
SkillEnvironmentRender::Omit,
|
||||
SkillRenderSideEffects::ThreadStart {
|
||||
session_telemetry: &session_telemetry,
|
||||
},
|
||||
@@ -7347,7 +7360,11 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/alpha-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/alpha-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/alpha-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
};
|
||||
@@ -7358,7 +7375,11 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/beta-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/beta-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/beta-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
};
|
||||
@@ -7375,6 +7396,7 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o
|
||||
let rendered = build_available_skills(
|
||||
&outcome,
|
||||
SkillMetadataBudget::Characters(minimum_budget + 6),
|
||||
SkillEnvironmentRender::Omit,
|
||||
SkillRenderSideEffects::ThreadStart {
|
||||
session_telemetry: &session_telemetry,
|
||||
},
|
||||
@@ -7406,7 +7428,11 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Admin,
|
||||
plugin_id: None,
|
||||
},
|
||||
@@ -7417,7 +7443,11 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
environment_id: "local".to_string(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
},
|
||||
|
||||
@@ -678,14 +678,21 @@ impl Session {
|
||||
&per_turn_config.to_models_manager_config(),
|
||||
)
|
||||
.await;
|
||||
let path_ref = primary_turn_environment.map(|turn_environment| {
|
||||
crate::skills::EnvironmentPathRef::new(
|
||||
turn_environment.environment.get_filesystem(),
|
||||
turn_environment.cwd.clone(),
|
||||
let skill_env_paths = turn_environments
|
||||
.turn_environments
|
||||
.iter()
|
||||
.map(
|
||||
|turn_environment| codex_core_skills::loader::SkillEnvironment {
|
||||
environment_id: turn_environment.environment_id.clone(),
|
||||
path: crate::skills::EnvironmentPathRef::new(
|
||||
turn_environment.environment.get_filesystem(),
|
||||
turn_environment.cwd.clone(),
|
||||
),
|
||||
},
|
||||
)
|
||||
});
|
||||
let skills_outcome = if let Some(path_ref) = path_ref {
|
||||
// Workspace/repo skill roots use the selected turn environment path above, while
|
||||
.collect::<Vec<_>>();
|
||||
let skills_outcome = if !skill_env_paths.is_empty() {
|
||||
// Workspace/repo skill roots use the selected turn environment paths above, while
|
||||
// user/system/plugin skill roots still read from the available local filesystem.
|
||||
let local_file_system = self
|
||||
.services
|
||||
@@ -699,9 +706,9 @@ impl Session {
|
||||
.plugins_for_config(&plugins_input)
|
||||
.await;
|
||||
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
|
||||
let skills_input = skills_load_input_from_config(
|
||||
let skills_input = crate::skills::skills_load_input_from_environments(
|
||||
&per_turn_config,
|
||||
path_ref,
|
||||
skill_env_paths,
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
);
|
||||
|
||||
@@ -43,7 +43,25 @@ pub(crate) fn skills_load_input_from_config(
|
||||
effective_skill_roots: Vec<PluginSkillRoot>,
|
||||
) -> SkillsLoadInput {
|
||||
SkillsLoadInput::new(
|
||||
env_path,
|
||||
vec![codex_core_skills::loader::SkillEnvironment {
|
||||
environment_id: codex_exec_server::LOCAL_ENVIRONMENT_ID.to_string(),
|
||||
path: env_path,
|
||||
}],
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
config.config_layer_stack.clone(),
|
||||
config.bundled_skills_enabled(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn skills_load_input_from_environments(
|
||||
config: &Config,
|
||||
env_paths: Vec<codex_core_skills::loader::SkillEnvironment>,
|
||||
local_file_system: Option<Arc<dyn ExecutorFileSystem>>,
|
||||
effective_skill_roots: Vec<PluginSkillRoot>,
|
||||
) -> SkillsLoadInput {
|
||||
SkillsLoadInput::new(
|
||||
env_paths,
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
config.config_layer_stack.clone(),
|
||||
|
||||
Reference in New Issue
Block a user