Skip to main content

strop_trace/
event.rs

1//! Schema vocabulary shared by producers; payloads retain their domain's types.
2use serde::Serialize;
3
4pub const SCHEMA_VERSION: u32 = 1;
5
6#[derive(Debug, Clone, Copy, Serialize)]
7#[serde(rename_all = "snake_case")]
8pub enum EventKind {
9    SessionStart,
10    SessionEnd,
11    Input,
12    Paste,
13    State,
14    Document,
15    Mutation,
16    History,
17    Render,
18    Resize,
19    JobStarted,
20    JobFinished,
21    JobRejected,
22    LspMessage,
23    Error,
24    Panic,
25}
26
27#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
28pub enum ContentPolicy {
29    /// Keys, paths and bounded previews are still sensitive; this is not redaction.
30    #[default]
31    Metadata,
32    /// Include whole document/paste payloads for reproduction, explicitly opted in.
33    Full,
34}
35
36#[derive(Debug, Default, Clone, Copy)]
37pub struct TraceOptions {
38    pub content: ContentPolicy,
39}
40
41/// UTF-8-safe bounded preview. The byte length and full text are separate fields.
42pub fn preview(text: &str) -> String {
43    let mut chars = text.chars();
44    let mut result: String = chars.by_ref().take(120).collect();
45    if chars.next().is_some() {
46        result.push('…');
47    }
48    result
49}