pub struct TreeNode {
pub id: String,
pub parent: Option<String>,
pub children: Vec<String>,
pub message: ChatMessage,
pub label: Option<String>,
pub created_at_ms: i64,
}Expand description
One addressable turn in the tree (module 21’s “entry”). Carries the full
ChatMessage (this IS the full-fidelity source for a branched session
— see the module doc’s “off by default” note: the plain linear transcript
file remains the record for an UNBRANCHED session; this sidecar only
exists once a tree operation actually ran), its parent/children links,
and an optional human/agent-set label (module 21 “entry labels”).
Lossless persistence (§1.13). Self::message is a plain
ChatMessage in memory, but this type’s Serialize/Deserialize
impls (below) are hand-written rather than derived: they route the
message through NativeTurn — the SAME full-fidelity wire record
crate::session::Session::to_native_jsonl_v2 already uses to persist
live-appended turns — instead of ChatMessage’s own wire Serialize.
ChatMessage’s hand-rolled wire serde (message.rs:57-79) is deliberately
lossy: it OMITS metadata entirely (never meant to reach a provider
request body) and collapses content whenever content_parts is also
set. That lossy shape is correct for an outbound API request; it is
WRONG for this sidecar, which is the ONLY durable record of an off-path
branch’s messages (a rewound-past branch has no other file backing it).
NativeTurn was built for exactly this distinction (see its module doc:
“the sidecar must retain what the wire serde must drop”) — reusing it
here, rather than inventing a second parallel lossless representation,
keeps TreeNode.message byte-for-byte round-trippable: metadata intact,
content AND content_parts both intact (independently — NativeTurn
does not collapse one into the other).
Fields§
§id: StringThis node’s id.
parent: Option<String>The parent node id. None only for the tree’s root.
children: Vec<String>Child node ids, in the order they were created. More than one entry here IS a branch point (multiple turns following the same parent).
message: ChatMessageThe turn itself.
label: Option<String>A human/agent-set label on this node (module 21 “entry labels”),
e.g. a checkpoint name or an annotation. None (the default) —
unlabeled.
created_at_ms: i64Unix-ms wall-clock time this node was created.