Move instruction preload helper out of core

This commit is contained in:
Adam Perry
2026-06-04 23:18:53 -07:00
parent 5975615ab4
commit ffed2cae1c
6 changed files with 69 additions and 82 deletions
@@ -1,6 +1,7 @@
use codex_core::AgentsMdManager;
use codex_core::ThreadManager;
use codex_core::config::Config;
use codex_core::load_thread_user_instructions as preload_thread_user_instructions;
use codex_protocol::error::CodexErr;
use codex_protocol::error::Result as CodexResult;
use codex_protocol::protocol::TurnEnvironmentSelection;
@@ -11,10 +12,24 @@ pub(super) async fn load_thread_user_instructions(
config: &mut Config,
environments: &[TurnEnvironmentSelection],
) -> CodexResult<()> {
preload_thread_user_instructions(
config,
thread_manager.environment_manager().as_ref(),
environments,
)
.await
let Some(primary_selection) = environments.first() else {
config.user_instructions = None;
return Ok(());
};
let environment = thread_manager
.environment_manager()
.get_environment(&primary_selection.environment_id)
.ok_or_else(|| {
CodexErr::InvalidRequest(format!(
"unknown turn environment id `{}`",
primary_selection.environment_id
))
})?;
let mut warnings = Vec::new();
let user_instructions = AgentsMdManager::new(config)
.load_user_instructions(environment.as_ref(), &mut warnings)
.await;
config.startup_warnings.extend(warnings);
config.user_instructions = user_instructions;
Ok(())
}