Skip to main content

kaizen/prompt/
types.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! Pure data types for prompt snapshot tracking.
3
4use serde::{Deserialize, Serialize};
5
6/// One file that contributes to the prompt fingerprint.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct PromptFile {
9    pub path: String,
10    pub sha256: String,
11    pub bytes: u64,
12}
13
14/// Immutable snapshot of all prompt/rule/skill files at a point in time.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct PromptSnapshot {
17    /// Blake3 hash over sorted file contents — primary key in the store.
18    pub fingerprint: String,
19    pub captured_at_ms: u64,
20    /// JSON-serialised `Vec<PromptFile>`.
21    pub files_json: String,
22    pub total_bytes: u64,
23}
24
25impl PromptSnapshot {
26    pub fn files(&self) -> Vec<PromptFile> {
27        serde_json::from_str(&self.files_json).unwrap_or_default()
28    }
29}
30
31/// Difference between two snapshots.
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
33pub struct PromptDiff {
34    pub added: Vec<String>,
35    pub removed: Vec<String>,
36    pub changed: Vec<String>,
37}
38
39impl PromptDiff {
40    pub fn is_empty(&self) -> bool {
41        self.added.is_empty() && self.removed.is_empty() && self.changed.is_empty()
42    }
43}