Skip to main content

session_core/
continuation.rs

1//! `/continue` (`Op::ContinueFrom`): a new session that continues an old one by searching its log instead of carrying
2//! a summary of it. Its first message says which session it continues and how to read it (`sessions.search` /
3//! `sessions.read` scoped to it); nothing of the old conversation is copied.
4
5use serde_json::{Value, json};
6use session_journal::repo::Metadata;
7
8/// The custom message type of the note.
9pub const CONTINUATION: &str = "continuation";
10
11/// The note that opens a session continuing `old` (named `name`).
12pub fn message(old: &Metadata, name: Option<&str>, timestamp: i64) -> Value {
13    let id = &old.id;
14    let named = name.map_or(String::new(), |name| format!(" (\"{name}\")"));
15    let content = format!(
16        "[continuation] This session continues session {id}{named}, last active {}. Its conversation is not in your \
17         context and was not summarized: when the user refers to earlier work, or you need a decision, path or result \
18         from it, look it up instead of guessing: `await sessions.search(\"regex\", sessions=[\"{id}\"])` (or \
19         `terms=[...]`) finds its turns, each hit with a `span`; `await sessions.read(span, around=5)` reads one; \
20         `await sessions.read(session=\"{id}\", limit=50)` reads it from the start.",
21        jsrt::date::iso_string(old.modified_at as i64)
22    );
23    json!({
24        "role": "custom",
25        "customType": CONTINUATION,
26        "content": content,
27        "display": true,
28        "details": {"session": id},
29        "timestamp": timestamp,
30    })
31}