1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//! Goal slots: 5 fixed, privileged standing-goal slots pinned near the top
//! of the prompt (#2347, epic #2343 pillar 3).
//!
//! Why: Infinite Sessions (#2343) must keep a long-running PM anchored on
//! its objective even after many rounds of compaction/summarisation have
//! discarded the turns that originally stated it. A free-form "remember
//! your goal" instruction buried in the transcript is exactly the kind of
//! content non-destructive compaction (#2070) is entitled to fold into a
//! summary once it ages out of the kept window — so goals cannot live as an
//! ordinary transcript entry. Fixed, numbered slots (rather than an
//! unbounded list) keep the injected block small and bounded — the vision
//! spec's ~2K-token goals budget out of the 200K-window overhead accounting
//! (#2343) assumes a small constant number of slots, not an
//! attacker/model-controlled list length.
//! What: [`GoalSlots`] holds exactly [`GOAL_SLOT_COUNT`] `Option<GoalSlot>`
//! entries. [`GoalSlots::set`]/[`GoalSlots::clear`] mutate a 1-based slot
//! number (matching the `set_goal`/`clear_goal` tool schemas in
//! `tools::goals`), returning [`GoalSlotError::OutOfRange`] rather than
//! panicking on an out-of-range index. [`GoalSlots::render`] produces the
//! synthetic prompt block `agent_loop::transcript::Transcript::to_messages`
//! injects at position `[1]` — `None` when every slot is empty, so an
//! all-empty `GoalSlots` never adds a message at all.
//! Test: `goals_tests::*` — set/clear round-trips, out-of-range rejection,
//! render formatting (numbering skips empty slots, `None` when all empty),
//! and that `set` overwrites in place (updating `updated_at`) rather than
//! appending.
use ;
use ;
use Error;
/// The number of fixed goal slots (#2343 design decision: exactly 5).
///
/// Why: A fixed, small constant — rather than a caller-supplied capacity —
/// is what makes the rendered block's size bounded and predictable for the
/// epic's overhead-budget accounting; growing it is a deliberate design
/// change, not a runtime configuration knob.
pub const GOAL_SLOT_COUNT: usize = 5;
/// Who last wrote a given [`GoalSlot`].
///
/// Why: `set_goal` (the `tools::goals::SetGoalTool` the PM's own model
/// calls) and the future operator-facing `session.set_goal` RPC (#2350)
/// both mutate the same [`GoalSlots`]; recording the source lets a future
/// UI/audit view distinguish "the model decided this" from "an operator
/// pinned this" without a second parallel data structure.
/// Test: `goals_tests::set_records_model_source`,
/// `goals_tests::goal_source_serialises_snake_case`.
/// One occupied goal slot: its text, who wrote it, and when.
///
/// Why: A bare `String` would lose the provenance/recency information a
/// future operator-facing view (#2350) needs; bundling all three in one
/// struct keeps `GoalSlots`'s storage a simple fixed-size array of
/// `Option<GoalSlot>` rather than three parallel arrays.
/// What: `text` is the free-form goal description; `source` is
/// [`GoalSource`]; `updated_at` is the UTC timestamp of the last `set` call
/// that wrote this slot (matching the `chrono::Utc` convention already used
/// by `session::registry`/`session::model` for session timestamps).
/// Test: `goals_tests::set_then_get_round_trips_all_fields`.
/// Slot-index validation failure.
///
/// Why: `set`/`clear` accept a caller- (ultimately model-) supplied 1-based
/// slot number; an out-of-range value (0, or greater than
/// [`GOAL_SLOT_COUNT`]) must be a recoverable error the LLM tool layer can
/// report back to the model, never a panic/index-out-of-bounds.
/// What: The single variant names the offending `slot` value so the
/// rendered error message is actionable.
/// Test: `goals_tests::set_out_of_range_slot_errors`,
/// `goals_tests::clear_out_of_range_slot_errors`.
/// The fixed preamble prefixed to every non-empty [`GoalSlots::render`]
/// output.
///
/// Why: Without an explicit framing line the model has no way to tell this
/// injected block apart from an ordinary system note, and might treat it as
/// a todo list to be checked off and discarded rather than a standing
/// objective to keep re-reading. Fixed rather than configurable per #2347's
/// scope: the schema descriptions on the `set_goal`/`clear_goal` tools (not
/// this preamble) carry the "not todos" usage guidance per the issue's
/// explicit "do NOT modify prompt/assembler.rs or preamble.rs" constraint.
const GOALS_PREAMBLE: &str = "## Active Goals\n\
These are your privileged, standing goals — fixed slots that persist across \
turns and survive context compaction. They are not a todo list; use \
set_goal/clear_goal only when the underlying objective itself changes.";
/// 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::*`.