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
//! BP-7 (catalog §4a "Goals (persistent objective across turns)", cc's
//! `/goal`, cx's `/goal` + `goals_1.sqlite`): the session's standing
//! objective.
//!
//! **Not the plan.** `update_plan` (the `todos` module's tool) holds a
//! steps/status array for the CURRENT stretch of work and is deliberately
//! ephemeral. A goal is the condition the whole session is working toward:
//! one sentence, set once, restated to the model on every request until it
//! is changed or cleared, and persisted beside the session so it survives a
//! resume. Design §2 module 7 homes goals with `todos` for exactly this
//! reason — same module, different lifetime.
//!
//! **Where it lands.** `<session>.goal.json`, a single typed record in the
//! sidecar family next to `<session>.git.json` (also a single record, not a
//! log) — never inside the provider-visible transcript, so translating a
//! session to another harness never has to invent a message for it.
use serde::{Deserialize, Serialize};
/// The session's persistent objective.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GoalRecord {
/// The objective, as the user stated it.
pub objective: String,
/// Unix-ms wall-clock time the goal was first set.
pub created_at_ms: i64,
/// Unix-ms wall-clock time it was last changed.
pub updated_at_ms: i64,
}
impl GoalRecord {
/// A goal set now.
pub fn new(objective: impl Into<String>, now_ms: i64) -> GoalRecord {
GoalRecord {
objective: objective.into(),
created_at_ms: now_ms,
updated_at_ms: now_ms,
}
}
/// Replace the objective, keeping `created_at_ms` — the goal's identity
/// is the session's, not the sentence's, so a reworded goal is the same
/// goal refined, not a new one.
pub fn revise(&mut self, objective: impl Into<String>, now_ms: i64) {
self.objective = objective.into();
self.updated_at_ms = now_ms;
}
/// The block spliced into the tail of every request while this goal
/// stands. Deliberately at the TAIL, not the system prompt: a standing
/// objective is only useful if it is the last thing the model reads
/// before the current turn, and appending never disturbs the cached
/// prefix.
pub fn reminder(&self) -> String {
format!(
"<goal>\nThe standing objective for this session is:\n{}\n\
Keep working toward it; say so plainly if it is already met or \
if it cannot be.\n</goal>",
self.objective.trim()
)
}
}