pub struct GoalSlots { /* private fields */ }Expand description
Exactly GOAL_SLOT_COUNT fixed, privileged goal slots (#2347).
Why: See module docs — this is the in-memory state
agent_loop::transcript::Transcript renders fresh on every
to_messages() call and tools::goals::{SetGoalTool, ClearGoalTool}
mutate on the model’s behalf.
What: A fixed-size array of Option<GoalSlot>; Default is all-empty.
Test: goals_tests::*.
Implementations§
Source§impl GoalSlots
impl GoalSlots
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an all-empty GoalSlots.
Why: Explicit constructor mirrors this crate’s Tool::new()
convention even though Default would do the same.
Test: goals_tests::new_is_all_empty.
Sourcepub fn set(
&mut self,
slot: usize,
text: impl Into<String>,
source: GoalSource,
) -> Result<(), GoalSlotError>
pub fn set( &mut self, slot: usize, text: impl Into<String>, source: GoalSource, ) -> Result<(), GoalSlotError>
Write (or overwrite) a 1-based slot with text from source.
Why: The model-facing set_goal tool and the future operator RPC
(#2350) both need one shared, validated write path rather than
reaching into the array directly.
What: Validates slot via Self::validate, then replaces (does
NOT append to) that slot with a fresh GoalSlot { text, source, updated_at: Utc::now() }. Overwriting an occupied slot discards its
previous content — slots hold the CURRENT goal only, not a history.
Test: goals_tests::set_then_get_round_trips_all_fields,
goals_tests::set_overwrites_existing_slot,
goals_tests::set_out_of_range_slot_errors.
Sourcepub fn clear(&mut self, slot: usize) -> Result<(), GoalSlotError>
pub fn clear(&mut self, slot: usize) -> Result<(), GoalSlotError>
Clear a 1-based slot, leaving it empty.
Why: The model-facing clear_goal tool needs a validated way to
retire a completed/obsolete goal without disturbing the other four
slots.
What: Validates slot via Self::validate, then sets it to
None. Clearing an already-empty slot is a no-op success, not an
error — idempotent clearing is simpler for the model to reason about
than a “nothing to clear” failure.
Test: goals_tests::clear_empties_slot,
goals_tests::clear_already_empty_slot_is_ok,
goals_tests::clear_out_of_range_slot_errors.
Sourcepub fn get(&self, slot: usize) -> Option<&GoalSlot>
pub fn get(&self, slot: usize) -> Option<&GoalSlot>
Read the current content of a 1-based slot, if occupied.
Why: Test/observability accessor; also lets a future operator view
(#2350) inspect one slot without re-deriving the whole rendered
block.
What: Returns None for an out-of-range slot OR an empty one — the
two cases are intentionally not distinguished here (callers that
need to distinguish “invalid” from “empty” use set/clear’s
Result instead).
Test: goals_tests::set_then_get_round_trips_all_fields.
Sourcepub fn occupied(&self) -> Vec<(usize, GoalSlot)>
pub fn occupied(&self) -> Vec<(usize, GoalSlot)>
Snapshot every currently-occupied slot as (1-based slot, GoalSlot)
pairs, in slot order (#2350).
Why: session.get_goals and TranscriptRecord.goals
(session::transcript) both need a serialisable view of every
occupied slot together with its 1-based index — cloning here (rather
than returning references) lets the caller build its own DTO without
holding this GoalSlots’s lock any longer than the snapshot itself.
What: Filters out empty slots, cloning each occupied GoalSlot paired
with its 1-based slot number.
Test: goals_tests::occupied_skips_empty_slots_and_preserves_index,
goals_tests::occupied_empty_when_all_slots_empty.
Sourcepub fn render(&self) -> Option<String>
pub fn render(&self) -> Option<String>
Render the privileged-goals prompt block, or None if every slot is
empty.
Why: This is what Transcript::to_messages injects at position
[1] on every call — computed fresh from live state rather than
stored, so it can never drift from what set/clear last wrote.
Returning None when nothing is set means an all-empty GoalSlots
injects NOTHING, matching the acceptance criterion that the goals
message is absent (not an empty stub) when no goal has ever been set.
What: Numbers each occupied slot by its 1-based position, skipping
empty slots entirely (so slot 3 alone renders as "3. <text>", not
"1. <text>"), joined under [GOALS_PREAMBLE].
Test: goals_tests::render_none_when_all_empty,
goals_tests::render_numbers_by_slot_skipping_empty,
goals_tests::render_includes_preamble.
Trait Implementations§
impl StructuralPartialEq for GoalSlots
Auto Trait Implementations§
impl Freeze for GoalSlots
impl RefUnwindSafe for GoalSlots
impl Send for GoalSlots
impl Sync for GoalSlots
impl Unpin for GoalSlots
impl UnsafeUnpin for GoalSlots
impl UnwindSafe for GoalSlots
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more