brainos_terminal/types.rs
1//! Public, non-PB types for the Terminal Bridge.
2//!
3//! The protobuf-generated `pb::*` types are tied to gRPC encoding and aren't
4//! ergonomic to pass around the rest of the workspace (intents, audit events,
5//! observers). These mirrored types are what flows through Brain.
6
7use chrono::{DateTime, Utc};
8use identity::Principal;
9use serde::{Deserialize, Serialize};
10
11/// Stable string handle for a live PTY session (UUID v4).
12pub type SessionId = String;
13
14/// PTY dimensions. Mirrors `pb::PtySize` but carries `u16` (the native
15/// `portable_pty::PtySize` width) instead of proto's `uint32`.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
17pub struct TermSize {
18 pub rows: u16,
19 pub cols: u16,
20 pub pixel_width: u16,
21 pub pixel_height: u16,
22}
23
24impl Default for TermSize {
25 fn default() -> Self {
26 Self {
27 rows: 24,
28 cols: 80,
29 pixel_width: 0,
30 pixel_height: 0,
31 }
32 }
33}
34
35/// Lightweight snapshot of a session for intent inspection and audit.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct SessionMeta {
38 pub session_id: SessionId,
39 pub program: String,
40 pub args: Vec<String>,
41 pub cwd: Option<String>,
42 pub opened_at: DateTime<Utc>,
43 pub client_id: Option<String>,
44 pub size: TermSize,
45 /// The authenticated caller that opened this session. `None` when the
46 /// bridge has no identity store configured, or when the caller did not
47 /// present a recognized api-key.
48 #[serde(default)]
49 pub principal: Option<Principal>,
50}