Skip to main content

bijux_cli/contracts/
diagnostics.rs

1use std::collections::BTreeMap;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7use super::command::CommandPath;
8use super::execution::ExecutionPolicy;
9
10/// Stable diagnostic record contract.
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
12pub struct DiagnosticRecord {
13    /// Stable diagnostic identifier.
14    pub id: String,
15    /// Severity (`info`, `warning`, `error`).
16    pub severity: String,
17    /// Human-readable message.
18    pub message: String,
19    /// Machine-readable context.
20    pub fields: BTreeMap<String, Value>,
21}
22
23/// Stable invocation event used by trace logs.
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
25pub struct InvocationEvent {
26    /// Event timestamp as unix milliseconds encoded as string.
27    pub timestamp: String,
28    /// Event name.
29    pub name: String,
30    /// Event payload.
31    pub payload: BTreeMap<String, Value>,
32}
33
34/// Stable invocation trace contract.
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
36pub struct InvocationTrace {
37    /// Unique invocation identifier.
38    pub invocation_id: String,
39    /// Original command path.
40    pub command: CommandPath,
41    /// Effective execution policy.
42    pub policy: ExecutionPolicy,
43    /// Ordered execution events.
44    pub events: Vec<InvocationEvent>,
45}
46
47/// Stable memory summary payload contract.
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
49pub struct MemorySummary {
50    /// Command execution status.
51    pub status: String,
52    /// Number of keys stored in memory state.
53    pub count: usize,
54    /// Human-readable summary message.
55    pub message: String,
56}
57
58/// Stable memory key listing payload contract.
59#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
60pub struct MemoryKeyList {
61    /// Command execution status.
62    pub status: String,
63    /// Sorted memory keys.
64    pub keys: Vec<String>,
65    /// Number of keys returned.
66    pub count: usize,
67}
68
69/// Stable route metadata used by inspect and dev diagnostics surfaces.
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
71pub struct RouteSourceMetadata {
72    /// Route command segments.
73    pub segments: Vec<String>,
74    /// Route owner (`bijux-cli` or `plugin`).
75    pub owner: String,
76    /// Resolution source (`built-in`, `compatibility-alias`, `plugin`).
77    pub source: String,
78}
79
80/// Stable alias rewrite metadata for routing diagnostics.
81#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
82pub struct AliasRewrite {
83    /// Alias path segments.
84    pub alias: Vec<String>,
85    /// Canonical normalized path segments.
86    pub canonical: Vec<String>,
87    /// Rewrite source marker.
88    pub source: String,
89}
90
91/// Stable inspect payload contract for machine-readable diagnostics output.
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
93pub struct InspectReport {
94    /// Command execution status.
95    pub status: String,
96    /// Route source metadata rows.
97    pub route_sources: Vec<RouteSourceMetadata>,
98    /// Alias rewrite metadata rows.
99    pub alias_rewrites: Vec<AliasRewrite>,
100}