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
//! `SessionRegistry`'s #2350 operator-facing goal-slot plumbing:
//! `session.set_goal`/`session.clear_goal`/`session.get_goals`. Split out of
//! `registry.rs` for the same 500-SLOC-cap reason as `registry_events.rs`/
//! `registry_memory_sink.rs` — this is a child module of `registry`
//! (declared via `#[path = ...] mod goal_ops;`), so it shares full access to
//! `SessionRegistry`'s private `lock` helper and `SessionEntry`'s fields
//! exactly as if these methods were still defined in that file.
//!
//! Why: `agent_loop::goals::GoalSlots` already lets the PM's own model write
//! goals via the `set_goal`/`clear_goal` tools (#2347), each tagged
//! `GoalSource::Model`. An operator (human, or a future TUI/CLI) needs the
//! SAME shared slots reachable over `session.*` JSON-RPC, tagged
//! `GoalSource::Operator` — last-write-wins between the two sources is
//! implicit in `GoalSlots::set` simply overwriting whichever slot is named,
//! regardless of who wrote it last.
//! **Design decision (documented per the ticket):** the goal slots live on
//! `Transcript` (`SessionEntry.pm_transcript`), which is only seeded on a
//! session's FIRST `task.run` (`SessionRegistry::begin_pm_transcript`). A
//! session that has never run a task has no `Transcript` and therefore no
//! goal-slot storage to write into yet. Rather than adding a second,
//! parallel "pending goals" slot on `SessionEntry` that would need to be
//! applied at the first `begin_pm_transcript` call (a real design, but more
//! moving parts than this ticket's scope needs), `set_goal`/`clear_goal`
//! return a clear `invalid_argument` error naming the limitation. `get_goals`
//! takes the simpler read-side convention already established by
//! `get_transcript`: a session with no transcript yet is a valid EMPTY
//! result, not an error. Upgrading `set_goal` to a pending-goals path that
//! applies on the first run is documented future work, not needed here.
//! What: `set_goal`/`clear_goal` resolve `id`'s `pm_transcript`'s
//! `goals_handle()`, erroring `session_not_found` if the session itself is
//! unknown or `invalid_argument` if it has no transcript yet or the slot
//! index is out of range; `get_goals` returns `[]` for a never-run session
//! rather than erroring. [`goal_records`] is the shared snapshot helper
//! `registry.rs`'s `get_transcript` also calls, so `TranscriptRecord.goals`
//! and `session.get_goals` can never independently drift on shape.
//! Test: `registry_tests::set_goal_*`, `registry_tests::clear_goal_*`,
//! `registry_tests::get_goals_*`,
//! `registry_tests::get_transcript_round_trips_goal_state`.
use *;
use crate;
use crateGoalSlotRecord;
/// Snapshot a `SessionEntry`'s current goal slots as wire-shaped
/// [`GoalSlotRecord`]s, or `[]` if it has no `pm_transcript` yet.
///
/// Why: shared by [`SessionRegistry::get_goals`] and `registry.rs`'s
/// `SessionRegistry::get_transcript` (`TranscriptRecord.goals`) so the two
/// read paths can never disagree on shape or on the never-run-session
/// convention.
/// What: `None` `pm_transcript` -> `vec![]`; otherwise locks the transcript's
/// `goals_handle()` (recovering a poisoned lock) and maps every
/// `GoalSlots::occupied` pair through `GoalSlotRecord::from_slot`.
pub