Add serde derives to AST types, enable chrono serde feature

Prep for wiring context_new.rs into the codebase: AstNode, NodeLeaf,
NodeBody, Role all derive Serialize/Deserialize for conversation log
persistence.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 14:17:40 -04:00
parent bb80225942
commit 9fb9c2b2cb
2 changed files with 6 additions and 5 deletions

View file

@ -30,6 +30,7 @@
// the NodeBody variant. Grammar constraints enforced by construction.
use chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};
use super::tokenizer;
// ---------------------------------------------------------------------------
@ -37,7 +38,7 @@ use super::tokenizer;
// ---------------------------------------------------------------------------
/// Branch roles — maps directly to the grammar's message roles.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Role {
System,
User,
@ -45,7 +46,7 @@ pub enum Role {
}
/// Leaf content — each variant knows how to render itself.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NodeBody {
// Children of message branches — rendered without im_start/im_end
Content(String),
@ -62,7 +63,7 @@ pub enum NodeBody {
}
/// A leaf node: typed content with cached token IDs.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeLeaf {
body: NodeBody,
token_ids: Vec<u32>,
@ -70,7 +71,7 @@ pub struct NodeLeaf {
}
/// A node in the context AST.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AstNode {
Leaf(NodeLeaf),
Branch { role: Role, children: Vec<AstNode> },