Skip to main content

hatchery_session_events/
event.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
4#[serde(rename_all = "snake_case")]
5pub enum Confidence {
6    /// Typed source (ACP, stream-json): the fields are what the agent said.
7    Structured,
8    /// Recovered from rendered terminal text: may be wrong after a provider UI change.
9    Heuristic,
10}
11
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
13#[serde(rename_all = "snake_case")]
14pub enum SessionState {
15    Starting,
16    Working,
17    Idle,
18    NeedsInput,
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
22#[serde(rename_all = "snake_case")]
23pub enum PromptKind {
24    Login,
25    Trust,
26    Permission,
27    ApiKey,
28    Menu,
29    Confirm,
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
33#[serde(rename_all = "snake_case")]
34pub enum ActionStatus {
35    Running,
36    Done,
37    Failed,
38}
39
40#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
41#[serde(tag = "kind", rename_all = "snake_case")]
42pub enum EventKind {
43    Banner { text: String },
44    UserMessage { text: String },
45    Answer { text: String },
46    Thought { text: String },
47    Action { name: String, args: String, result: Option<String>, status: ActionStatus },
48    Diff { files: Vec<String>, patch: String },
49    PromptNeeded { prompt: PromptKind, text: String, options: Vec<String> },
50    State { state: SessionState, detail: String },
51}
52
53/// One typed event. `id` is stable for an item; `rev` grows when the same item changes
54/// (a tool call getting its result, an answer growing). Consumers upsert by `id`.
55#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
56pub struct SessionEvent {
57    pub id: u64,
58    pub rev: u32,
59    pub provider: String,
60    /// `pty:<provider>` or `acp`.
61    pub source: String,
62    pub confidence: Confidence,
63    pub ts_ms: u64,
64    #[serde(flatten)]
65    pub event: EventKind,
66}