pub struct GoalRuntimeHandle { /* private fields */ }Expand description
Per-session goal lifecycle manager.
Drives auto-continuation, status transitions, and steering prompt injection.
All mutations go through with_goal_state which serializes access via a
dedicated state lock, preventing external set/clear calls from
interfering with continue_if_idle.
Implementations§
Source§impl GoalRuntimeHandle
impl GoalRuntimeHandle
Sourcepub fn new(initial_goal: Option<SessionGoal>) -> Self
pub fn new(initial_goal: Option<SessionGoal>) -> Self
Creates a new runtime handle with an optional initial goal.
Sourcepub fn get_goal(&self) -> Option<SessionGoal>
pub fn get_goal(&self) -> Option<SessionGoal>
Returns the current goal, if any.
Sourcepub fn set_session_id(&self, session_id: impl Into<String>)
pub fn set_session_id(&self, session_id: impl Into<String>)
Binds this runtime to a session id and rewrites any loaded goal to match.
Sourcepub fn set_objective(
&self,
objective: String,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_objective( &self, objective: String, token_budget: Option<i64>, ) -> SessionGoal
Sets or replaces the goal.
Sourcepub fn set_objective_with_short_description(
&self,
objective: String,
short_description: Option<String>,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_objective_with_short_description( &self, objective: String, short_description: Option<String>, token_budget: Option<i64>, ) -> SessionGoal
Sets or replaces the goal with an optional compact UI label.
Sourcepub fn update_goal(&self, goal: SessionGoal)
pub fn update_goal(&self, goal: SessionGoal)
Updates the stored goal (used after status transitions).
Sourcepub fn clear_goal(&self)
pub fn clear_goal(&self)
Clears the current goal.
Sourcepub fn update_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
pub fn update_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
Updates the checklist on the current goal. Returns the updated goal if successful.
Sourcepub fn update_task_status(
&self,
task_id: usize,
status: TaskStatus,
) -> Option<SessionGoal>
pub fn update_task_status( &self, task_id: usize, status: TaskStatus, ) -> Option<SessionGoal>
Updates a single task’s status in the goal checklist.
Sourcepub fn start_turn(&self)
pub fn start_turn(&self)
Starts turn accounting for the active goal.
Sourcepub fn record_tokens(&self, delta: i64) -> bool
pub fn record_tokens(&self, delta: i64) -> bool
Records token usage during a turn.
Sourcepub fn finish_turn(&self)
pub fn finish_turn(&self)
Finishes turn accounting and updates the stored goal.
Sourcepub fn record_blocked_turn(&self, reason: &str) -> bool
pub fn record_blocked_turn(&self, reason: &str) -> bool
Transitions the goal to Blocked after consecutive blocked turns.
Sourcepub fn mark_usage_limited(&self)
pub fn mark_usage_limited(&self)
Transitions the goal to UsageLimited.
Sourcepub fn continue_if_idle(&self) -> Option<String>
pub fn continue_if_idle(&self) -> Option<String>
If the goal is active and should auto-continue, returns a steering continuation prompt to inject into the conversation. Acquires the state lock to prevent race conditions with concurrent set/clear operations.
Sourcepub fn budget_limit_prompt(&self) -> Option<String>
pub fn budget_limit_prompt(&self) -> Option<String>
Returns a budget-limit steering prompt if the budget is exceeded.
Sourcepub fn objective_updated_prompt(&self) -> Option<String>
pub fn objective_updated_prompt(&self) -> Option<String>
Returns an objective-updated steering prompt.
Sourcepub fn set_auto_continue(&self, enabled: bool)
pub fn set_auto_continue(&self, enabled: bool)
Enables or disables auto-continuation.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Returns true if the goal is in a terminal state.