diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 1b1bc0e59a..cb758898c7 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -1904,6 +1904,7 @@ dependencies = [ "codex-file-search", "codex-file-watcher", "codex-git-utils", + "codex-goal-extension", "codex-guardian", "codex-hooks", "codex-login", diff --git a/codex-rs/app-server/Cargo.toml b/codex-rs/app-server/Cargo.toml index 09e3197b77..62bac97859 100644 --- a/codex-rs/app-server/Cargo.toml +++ b/codex-rs/app-server/Cargo.toml @@ -41,6 +41,7 @@ codex-extension-api = { workspace = true } codex-external-agent-migration = { workspace = true } codex-external-agent-sessions = { workspace = true } codex-features = { workspace = true } +codex-goal-extension = { workspace = true } codex-guardian = { workspace = true } codex-git-utils = { workspace = true } codex-file-watcher = { workspace = true } diff --git a/codex-rs/app-server/src/extensions.rs b/codex-rs/app-server/src/extensions.rs index 1246da7b37..6519e245f9 100644 --- a/codex-rs/app-server/src/extensions.rs +++ b/codex-rs/app-server/src/extensions.rs @@ -12,11 +12,13 @@ use codex_extension_api::AgentSpawner; use codex_extension_api::ExtensionEventSink; use codex_extension_api::ExtensionRegistry; use codex_extension_api::ExtensionRegistryBuilder; +use codex_features::Feature; use codex_login::AuthManager; use codex_protocol::ThreadId; use codex_protocol::error::CodexErr; use codex_protocol::protocol::Event; use codex_protocol::protocol::EventMsg; +use codex_rollout::state_db::StateDbHandle; use crate::outgoing_message::OutgoingMessageSender; @@ -24,12 +26,23 @@ pub(crate) fn thread_extensions( guardian_agent_spawner: S, event_sink: Arc, auth_manager: Arc, + state_db: Option, + thread_manager: Weak, ) -> Arc> where S: AgentSpawner + 'static, { let mut builder = ExtensionRegistryBuilder::::with_event_sink(event_sink); codex_guardian::install(&mut builder, guardian_agent_spawner); + if let Some(state_db) = state_db { + codex_goal_extension::install_with_backend( + &mut builder, + state_db, + codex_otel::global(), + thread_manager, + |config: &Config| config.features.enabled(Feature::Goals), + ); + } codex_memories_extension::install(&mut builder, codex_otel::global()); codex_web_search_extension::install(&mut builder, auth_manager); Arc::new(builder.build()) diff --git a/codex-rs/app-server/src/mcp_refresh.rs b/codex-rs/app-server/src/mcp_refresh.rs index 4ddfa34735..f6146ab197 100644 --- a/codex-rs/app-server/src/mcp_refresh.rs +++ b/codex-rs/app-server/src/mcp_refresh.rs @@ -191,6 +191,8 @@ mod tests { guardian_agent_spawner(thread_manager.clone()), Arc::new(NoopExtensionEventSink), auth_manager.clone(), + Some(state_db.clone()), + thread_manager.clone(), ), /*analytics_events_client*/ None, Arc::clone(&thread_store), diff --git a/codex-rs/app-server/src/message_processor.rs b/codex-rs/app-server/src/message_processor.rs index 33b9c56d4a..bd2beaa5c3 100644 --- a/codex-rs/app-server/src/message_processor.rs +++ b/codex-rs/app-server/src/message_processor.rs @@ -315,6 +315,8 @@ impl MessageProcessor { guardian_agent_spawner(thread_manager.clone()), app_server_extension_event_sink(outgoing.clone()), auth_manager.clone(), + state_db.clone(), + thread_manager.clone(), ), Some(analytics_events_client.clone()), Arc::clone(&thread_store), diff --git a/codex-rs/app-server/src/request_processors.rs b/codex-rs/app-server/src/request_processors.rs index 66ab8e3a1d..58e2a95847 100644 --- a/codex-rs/app-server/src/request_processors.rs +++ b/codex-rs/app-server/src/request_processors.rs @@ -271,8 +271,6 @@ use codex_config::loader::project_trust_key; use codex_config::types::McpServerTransportConfig; use codex_core::CodexThread; use codex_core::CodexThreadSettingsOverrides; -use codex_core::ExternalGoalPreviousStatus; -use codex_core::ExternalGoalSet; use codex_core::ForkSnapshot; use codex_core::NewThread; #[cfg(test)] @@ -335,6 +333,8 @@ use codex_feedback::FeedbackAttachmentPath; use codex_feedback::FeedbackUploadOptions; use codex_git_utils::git_diff_to_remote; use codex_git_utils::resolve_root_git_project_for_trust; +use codex_goal_extension::GoalRuntimeHandle; +use codex_goal_extension::PreviousGoalSnapshot; use codex_login::AuthManager; use codex_login::CLIENT_ID; use codex_login::CodexAuth; diff --git a/codex-rs/app-server/src/request_processors/thread_goal_processor.rs b/codex-rs/app-server/src/request_processors/thread_goal_processor.rs index c18806ea03..0d66f26937 100644 --- a/codex-rs/app-server/src/request_processors/thread_goal_processor.rs +++ b/codex-rs/app-server/src/request_processors/thread_goal_processor.rs @@ -66,10 +66,8 @@ impl ThreadGoalRequestProcessor { } self.emit_thread_goal_snapshot(thread_id).await; // App-server owns resume response and snapshot ordering, so wait until - // those are sent before letting core start goal continuation. - if let Err(err) = thread.continue_active_goal_if_idle().await { - tracing::warn!("failed to continue active goal after resume: {err}"); - } + // those are sent before letting extensions start idle work. + thread.continue_idle_extension_work().await; } pub(crate) async fn pending_resume_goal_state( @@ -144,19 +142,17 @@ impl ThreadGoalRequestProcessor { validate_goal_budget(params.token_budget.flatten()).map_err(invalid_request)?; } - if let Some(thread) = running_thread.as_ref() { - thread.prepare_external_goal_mutation().await; - } + prepare_external_goal_mutation(running_thread.as_deref()).await; let should_set_thread_preview = objective.is_some(); - let (goal, previous_status) = (if let Some(objective) = objective { + let (goal, previous_goal) = (if let Some(objective) = objective { let existing_goal = state_db .thread_goals() .get_thread_goal(thread_id) .await .map_err(|err| invalid_request(err.to_string()))?; if let Some(goal) = existing_goal.as_ref() { - let previous_status = ExternalGoalPreviousStatus::from(goal); + let previous_goal = PreviousGoalSnapshot::from(goal); state_db .thread_goals() .update_thread_goal( @@ -176,9 +172,8 @@ impl ThreadGoalRequestProcessor { ) }) }) - .map(|goal| (goal, previous_status)) + .map(|goal| (goal, Some(previous_goal))) } else { - let previous_status = ExternalGoalPreviousStatus::NewGoal; state_db .thread_goals() .replace_thread_goal( @@ -188,7 +183,7 @@ impl ThreadGoalRequestProcessor { params.token_budget.flatten(), ) .await - .map(|goal| (goal, previous_status)) + .map(|goal| (goal, None)) } } else { let existing_goal = state_db @@ -201,7 +196,7 @@ impl ThreadGoalRequestProcessor { "cannot update goal for thread {thread_id}: no goal exists" ))); }; - let previous_status = ExternalGoalPreviousStatus::from(&existing_goal); + let previous_goal = PreviousGoalSnapshot::from(&existing_goal); state_db .thread_goals() .update_thread_goal( @@ -219,7 +214,7 @@ impl ThreadGoalRequestProcessor { anyhow::anyhow!("cannot update goal for thread {thread_id}: no goal exists") }) }) - .map(|goal| (goal, previous_status)) + .map(|goal| (goal, Some(previous_goal))) }) .map_err(|err| invalid_request(err.to_string()))?; if should_set_thread_preview @@ -229,10 +224,7 @@ impl ThreadGoalRequestProcessor { { warn!("failed to set empty thread preview from goal objective for {thread_id}: {err}"); } - let external_goal_set = ExternalGoalSet { - goal: goal.clone(), - previous_status, - }; + let goal_state = goal.clone(); let goal = api_thread_goal_from_state(goal); self.outgoing .send_response( @@ -242,9 +234,7 @@ impl ThreadGoalRequestProcessor { .await; self.emit_thread_goal_updated_ordered(thread_id, goal, listener_command_tx) .await; - if let Some(thread) = running_thread.as_ref() { - thread.apply_external_goal_set(external_goal_set).await; - } + apply_external_goal_set(running_thread.as_deref(), goal_state, previous_goal).await; Ok(()) } @@ -307,9 +297,7 @@ impl ThreadGoalRequestProcessor { ) .await; - if let Some(thread) = running_thread.as_ref() { - thread.prepare_external_goal_mutation().await; - } + prepare_external_goal_mutation(running_thread.as_deref()).await; let listener_command_tx = { let thread_state = self.thread_state_manager.thread_state(thread_id).await; @@ -322,8 +310,8 @@ impl ThreadGoalRequestProcessor { .await .map_err(|err| internal_error(format!("failed to clear thread goal: {err}")))?; - if cleared && let Some(thread) = running_thread.as_ref() { - thread.apply_external_goal_clear().await; + if cleared { + apply_external_goal_clear(running_thread.as_deref()).await; } self.outgoing @@ -449,6 +437,45 @@ impl ThreadGoalRequestProcessor { } } +fn goal_runtime_handle(thread: &CodexThread) -> Option> { + thread.thread_extension_data().get::() +} + +async fn prepare_external_goal_mutation(thread: Option<&CodexThread>) { + let Some(runtime) = thread.and_then(goal_runtime_handle) else { + return; + }; + if let Err(err) = runtime.prepare_external_goal_mutation().await { + tracing::warn!("failed to prepare external goal mutation: {err}"); + } +} + +async fn apply_external_goal_set( + thread: Option<&CodexThread>, + goal: codex_state::ThreadGoal, + previous_goal: Option, +) { + let Some(thread) = thread else { + return; + }; + let Some(runtime) = goal_runtime_handle(thread) else { + return; + }; + if let Err(err) = runtime.apply_external_goal_set(goal, previous_goal).await { + tracing::warn!("failed to apply external goal status runtime effects: {err}"); + } + thread.continue_idle_extension_work().await; +} + +async fn apply_external_goal_clear(thread: Option<&CodexThread>) { + let Some(runtime) = thread.and_then(goal_runtime_handle) else { + return; + }; + if let Err(err) = runtime.apply_external_goal_clear().await { + tracing::warn!("failed to apply external goal clear runtime effects: {err}"); + } +} + fn validate_goal_budget(value: Option) -> Result<(), String> { if let Some(value) = value && value <= 0 diff --git a/codex-rs/app-server/src/request_processors/thread_lifecycle.rs b/codex-rs/app-server/src/request_processors/thread_lifecycle.rs index 985baac91a..dddddeb514 100644 --- a/codex-rs/app-server/src/request_processors/thread_lifecycle.rs +++ b/codex-rs/app-server/src/request_processors/thread_lifecycle.rs @@ -596,10 +596,8 @@ pub(super) async fn handle_pending_thread_resume_request( } } - if pending.emit_thread_goal_update - && let Err(err) = conversation.apply_goal_resume_runtime_effects().await - { - tracing::warn!("failed to apply goal resume runtime effects: {err}"); + if pending.emit_thread_goal_update { + conversation.emit_thread_resume_lifecycle().await; } let ThreadConfigSnapshot { @@ -670,11 +668,9 @@ pub(super) async fn handle_pending_thread_resume_request( .replay_requests_to_connection_for_thread(connection_id, conversation_id) .await; // App-server owns resume response and snapshot ordering, so wait until - // replay completes before letting core start goal continuation. - if pending.emit_thread_goal_update - && let Err(err) = conversation.continue_active_goal_if_idle().await - { - tracing::warn!("failed to continue active goal after running-thread resume: {err}"); + // replay completes before letting extensions start idle work. + if pending.emit_thread_goal_update { + conversation.continue_idle_extension_work().await; } } diff --git a/codex-rs/core/src/codex_thread.rs b/codex-rs/core/src/codex_thread.rs index 1113a12c8a..d00c5fafe2 100644 --- a/codex-rs/core/src/codex_thread.rs +++ b/codex-rs/core/src/codex_thread.rs @@ -1,7 +1,5 @@ use crate::agent::AgentStatus; use crate::config::ConstraintResult; -use crate::goals::ExternalGoalSet; -use crate::goals::GoalRuntimeEvent; use crate::session::Codex; use crate::session::SessionSettingsUpdate; use crate::session::SteerInputError; @@ -148,7 +146,7 @@ impl CodexThread { self.codex.session_loop_termination.clone().await; } - pub(crate) async fn emit_thread_resume_lifecycle(&self) { + pub async fn emit_thread_resume_lifecycle(&self) { for contributor in self .codex .session @@ -165,51 +163,12 @@ impl CodexThread { } } - pub async fn apply_goal_resume_runtime_effects(&self) -> anyhow::Result<()> { - self.codex - .session - .goal_runtime_apply(GoalRuntimeEvent::ThreadResumed) - .await + pub async fn continue_idle_extension_work(&self) { + self.codex.session.maybe_start_idle_extension_turn().await; } - pub async fn continue_active_goal_if_idle(&self) -> anyhow::Result<()> { - self.codex - .session - .goal_runtime_apply(GoalRuntimeEvent::MaybeContinueIfIdle) - .await - } - - pub async fn prepare_external_goal_mutation(&self) { - if let Err(err) = self - .codex - .session - .goal_runtime_apply(GoalRuntimeEvent::ExternalMutationStarting) - .await - { - tracing::warn!("failed to prepare external goal mutation: {err}"); - } - } - - pub async fn apply_external_goal_set(&self, external_set: ExternalGoalSet) { - if let Err(err) = self - .codex - .session - .goal_runtime_apply(GoalRuntimeEvent::ExternalSet { external_set }) - .await - { - tracing::warn!("failed to apply external goal status runtime effects: {err}"); - } - } - - pub async fn apply_external_goal_clear(&self) { - if let Err(err) = self - .codex - .session - .goal_runtime_apply(GoalRuntimeEvent::ExternalClear) - .await - { - tracing::warn!("failed to apply external goal clear runtime effects: {err}"); - } + pub fn thread_extension_data(&self) -> &codex_extension_api::ExtensionData { + &self.codex.session.services.thread_extension_data } #[doc(hidden)] diff --git a/codex-rs/core/src/context/contextual_user_message.rs b/codex-rs/core/src/context/contextual_user_message.rs index 940a938fce..afc1de9b09 100644 --- a/codex-rs/core/src/context/contextual_user_message.rs +++ b/codex-rs/core/src/context/contextual_user_message.rs @@ -4,9 +4,9 @@ use codex_protocol::models::ContentItem; use super::AdditionalContextUserFragment; use super::EnvironmentContext; +use super::ExtensionContext; use super::FragmentRegistration; use super::FragmentRegistrationProxy; -use super::GoalContext; use super::LegacyApplyPatchExecCommandWarning; use super::LegacyModelMismatchWarning; use super::LegacyUnifiedExecProcessLimitWarning; @@ -22,6 +22,8 @@ static ENVIRONMENT_CONTEXT_REGISTRATION: FragmentRegistrationProxy = FragmentRegistrationProxy::new(); +static EXTENSION_CONTEXT_REGISTRATION: FragmentRegistrationProxy = + FragmentRegistrationProxy::new(); static SKILL_INSTRUCTIONS_REGISTRATION: FragmentRegistrationProxy = FragmentRegistrationProxy::new(); static USER_SHELL_COMMAND_REGISTRATION: FragmentRegistrationProxy = @@ -30,8 +32,6 @@ static TURN_ABORTED_REGISTRATION: FragmentRegistrationProxy = FragmentRegistrationProxy::new(); static SUBAGENT_NOTIFICATION_REGISTRATION: FragmentRegistrationProxy = FragmentRegistrationProxy::new(); -static GOAL_CONTEXT_REGISTRATION: FragmentRegistrationProxy = - FragmentRegistrationProxy::new(); static LEGACY_UNIFIED_EXEC_PROCESS_LIMIT_WARNING_REGISTRATION: FragmentRegistrationProxy< LegacyUnifiedExecProcessLimitWarning, > = FragmentRegistrationProxy::new(); @@ -46,11 +46,11 @@ static CONTEXTUAL_USER_FRAGMENTS: &[&dyn FragmentRegistration] = &[ &USER_INSTRUCTIONS_REGISTRATION, &ENVIRONMENT_CONTEXT_REGISTRATION, &ADDITIONAL_CONTEXT_REGISTRATION, + &EXTENSION_CONTEXT_REGISTRATION, &SKILL_INSTRUCTIONS_REGISTRATION, &USER_SHELL_COMMAND_REGISTRATION, &TURN_ABORTED_REGISTRATION, &SUBAGENT_NOTIFICATION_REGISTRATION, - &GOAL_CONTEXT_REGISTRATION, &LEGACY_UNIFIED_EXEC_PROCESS_LIMIT_WARNING_REGISTRATION, &LEGACY_APPLY_PATCH_EXEC_COMMAND_WARNING_REGISTRATION, &LEGACY_MODEL_MISMATCH_WARNING_REGISTRATION, diff --git a/codex-rs/core/src/context/contextual_user_message_tests.rs b/codex-rs/core/src/context/contextual_user_message_tests.rs index 195b189929..a4ccbbd738 100644 --- a/codex-rs/core/src/context/contextual_user_message_tests.rs +++ b/codex-rs/core/src/context/contextual_user_message_tests.rs @@ -1,6 +1,5 @@ use super::*; use crate::context::ContextualUserFragment; -use crate::context::GoalContext; use crate::context::SubagentNotification; use codex_protocol::items::HookPromptFragment; use codex_protocol::items::build_hook_prompt_message; @@ -14,6 +13,13 @@ fn detects_environment_context_fragment() { })); } +#[test] +fn detects_extension_context_fragment() { + assert!(is_contextual_user_fragment(&ContentItem::InputText { + text: "\ndata\n".to_string(), + })); +} + #[test] fn detects_agents_instructions_fragment() { assert!(is_contextual_user_fragment(&ContentItem::InputText { @@ -29,27 +35,6 @@ fn detects_subagent_notification_fragment_case_insensitively() { )); } -#[test] -fn detects_goal_context_fragment() { - let text = GoalContext::new("Continue working toward the active thread goal.").render(); - - assert!(is_contextual_user_fragment(&ContentItem::InputText { - text - })); -} - -#[test] -fn contextual_user_fragment_is_dyn_compatible() { - let fragment: Box = Box::new(GoalContext::new( - "Continue working toward the active thread goal.", - )); - - assert_eq!( - fragment.render(), - "\nContinue working toward the active thread goal.\n" - ); -} - #[test] fn ignores_regular_user_text() { assert!(!is_contextual_user_fragment(&ContentItem::InputText { diff --git a/codex-rs/core/src/context/extension_context.rs b/codex-rs/core/src/context/extension_context.rs new file mode 100644 index 0000000000..4b9a6d0ad4 --- /dev/null +++ b/codex-rs/core/src/context/extension_context.rs @@ -0,0 +1,30 @@ +use super::ContextualUserFragment; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ExtensionContext { + body: String, +} + +impl ExtensionContext { + pub fn new(body: impl Into) -> Self { + Self { body: body.into() } + } +} + +impl ContextualUserFragment for ExtensionContext { + fn role() -> &'static str { + "user" + } + + fn markers(&self) -> (&'static str, &'static str) { + Self::type_markers() + } + + fn type_markers() -> (&'static str, &'static str) { + ("", "") + } + + fn body(&self) -> String { + format!("\n{}\n", self.body) + } +} diff --git a/codex-rs/core/src/context/goal_context.rs b/codex-rs/core/src/context/goal_context.rs deleted file mode 100644 index ad4c47ef06..0000000000 --- a/codex-rs/core/src/context/goal_context.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! Hidden user-context fragment for runtime-owned goal steering prompts. - -use super::ContextualUserFragment; - -/// Hidden runtime-owned goal steering context injected into model input. -#[derive(Debug, Clone, PartialEq)] -pub struct GoalContext { - prompt: String, -} - -impl GoalContext { - /// Creates goal context around an already-rendered steering prompt. - pub fn new(prompt: impl Into) -> Self { - Self { - prompt: prompt.into(), - } - } -} - -impl ContextualUserFragment for GoalContext { - fn role() -> &'static str { - "user" - } - - fn markers(&self) -> (&'static str, &'static str) { - Self::type_markers() - } - - fn type_markers() -> (&'static str, &'static str) { - ("", "") - } - - fn body(&self) -> String { - format!("\n{}\n", self.prompt) - } -} diff --git a/codex-rs/core/src/context/mod.rs b/codex-rs/core/src/context/mod.rs index 6d88df87e2..5ad1a8711e 100644 --- a/codex-rs/core/src/context/mod.rs +++ b/codex-rs/core/src/context/mod.rs @@ -7,9 +7,9 @@ mod available_skills_instructions; mod collaboration_mode_instructions; mod contextual_user_message; mod environment_context; +mod extension_context; mod fragment; mod fragments; -mod goal_context; mod guardian_followup_review_reminder; mod hook_additional_context; mod image_generation_instructions; @@ -38,12 +38,12 @@ pub(crate) use collaboration_mode_instructions::CollaborationModeInstructions; pub(crate) use contextual_user_message::is_contextual_user_fragment; pub(crate) use contextual_user_message::parse_visible_hook_prompt_message; pub(crate) use environment_context::EnvironmentContext; +pub use extension_context::ExtensionContext; pub use fragment::ContextualUserFragment; pub(crate) use fragment::FragmentRegistration; pub(crate) use fragment::FragmentRegistrationProxy; pub(crate) use fragments::AdditionalContextDeveloperFragment; pub(crate) use fragments::AdditionalContextUserFragment; -pub use goal_context::GoalContext; pub(crate) use guardian_followup_review_reminder::GuardianFollowupReviewReminder; pub(crate) use hook_additional_context::HookAdditionalContext; pub(crate) use image_generation_instructions::ImageGenerationInstructions; diff --git a/codex-rs/core/src/event_mapping_tests.rs b/codex-rs/core/src/event_mapping_tests.rs index 57d6362f55..02ce42f312 100644 --- a/codex-rs/core/src/event_mapping_tests.rs +++ b/codex-rs/core/src/event_mapping_tests.rs @@ -1,6 +1,4 @@ use super::parse_turn_item; -use crate::context::ContextualUserFragment; -use crate::context::GoalContext; use codex_protocol::items::AgentMessageContent; use codex_protocol::items::HookPromptFragment; use codex_protocol::items::TurnItem; @@ -316,20 +314,6 @@ fn parses_hook_prompt_and_hides_other_contextual_fragments() { } } -#[test] -fn goal_context_does_not_parse_as_visible_turn_item() { - let item = ResponseItem::Message { - id: Some("msg-1".to_string()), - role: "user".to_string(), - content: vec![ContentItem::InputText { - text: GoalContext::new("Continue working toward the active thread goal.").render(), - }], - phase: None, - }; - - assert!(parse_turn_item(&item).is_none()); -} - #[test] fn parses_agent_message() { let item = ResponseItem::Message { diff --git a/codex-rs/core/src/goals.rs b/codex-rs/core/src/goals.rs deleted file mode 100644 index c8e76f7d41..0000000000 --- a/codex-rs/core/src/goals.rs +++ /dev/null @@ -1,1861 +0,0 @@ -//! Core support for persisted thread goals. -//! -//! This module bridges core sessions and the state-db goal table. It validates -//! goal mutations, converts between state and protocol shapes, emits goal-update -//! events, and owns helper hooks used by goal lifecycle behavior. - -use crate::StateDbHandle; -use crate::context::ContextualUserFragment; -use crate::context::GoalContext; -use crate::session::TurnInput; -use crate::session::session::Session; -use crate::session::turn_context::TurnContext; -use crate::state::ActiveTurn; -use crate::state::TurnState; -use crate::tasks::RegularTask; -use crate::tools::handlers::goal_spec::UPDATE_GOAL_TOOL_NAME; -use anyhow::Context; -use codex_features::Feature; -use codex_otel::GOAL_BLOCKED_METRIC; -use codex_otel::GOAL_BUDGET_LIMITED_METRIC; -use codex_otel::GOAL_COMPLETED_METRIC; -use codex_otel::GOAL_CREATED_METRIC; -use codex_otel::GOAL_DURATION_SECONDS_METRIC; -use codex_otel::GOAL_RESUMED_METRIC; -use codex_otel::GOAL_TOKEN_COUNT_METRIC; -use codex_otel::GOAL_USAGE_LIMITED_METRIC; -use codex_protocol::ThreadId; -use codex_protocol::config_types::ModeKind; -use codex_protocol::models::ResponseInputItem; -use codex_protocol::protocol::EventMsg; -use codex_protocol::protocol::ThreadGoal; -use codex_protocol::protocol::ThreadGoalStatus; -use codex_protocol::protocol::ThreadGoalUpdatedEvent; -use codex_protocol::protocol::TokenUsage; -use codex_protocol::protocol::validate_thread_goal_objective; -use codex_rollout::state_db::reconcile_rollout; -use codex_thread_store::LocalThreadStore; -use codex_utils_template::Template; -use futures::future::BoxFuture; -use std::sync::Arc; -use std::sync::LazyLock; -use std::time::Duration; -use std::time::Instant; -use tokio::sync::Mutex; -use tokio::sync::Semaphore; -use tokio::sync::SemaphorePermit; - -pub(crate) struct SetGoalRequest { - pub(crate) objective: Option, - pub(crate) status: Option, - pub(crate) token_budget: Option>, -} - -pub(crate) struct CreateGoalRequest { - pub(crate) objective: String, - pub(crate) token_budget: Option, -} - -static CONTINUATION_PROMPT_TEMPLATE: LazyLock