Skip to main content

victauri_plugin/mcp/
introspection_params.rs

1use schemars::JsonSchema;
2use serde::Deserialize;
3
4/// Actions available in the `introspect` compound tool.
5#[derive(Debug, Copy, Clone, Deserialize, JsonSchema)]
6#[serde(rename_all = "snake_case")]
7pub enum IntrospectAction {
8    /// Get per-command execution timing statistics (min/max/avg/p95). Returns both
9    /// `commands` (Victauri-driven `invoke_command` calls) and `ipc_traffic` (the app's
10    /// REAL frontend IPC, derived from the live IPC log — the one reflecting actual use).
11    CommandTimings,
12    /// Report which registered commands have been called during this session. Also
13    /// returns `ipc_calls_observed` and `invoked_not_registered` from the live IPC log.
14    Coverage,
15    /// Record the current response shape of a command as a baseline contract.
16    ContractRecord,
17    /// Check all recorded contracts for schema drift.
18    ContractCheck,
19    /// List all recorded contract baselines.
20    ContractList,
21    /// Clear all recorded contract baselines.
22    ContractClear,
23    /// Report Victauri plugin startup phase timing breakdown.
24    StartupTiming,
25    /// Enumerate Tauri v2 capabilities, security config, plugin config, and window definitions.
26    Capabilities,
27    /// `SQLite` database health diagnostics (journal mode, WAL, page stats).
28    DbHealth,
29    /// Snapshot of the Victauri plugin's internal state (event log, registry, recording, faults).
30    PluginState,
31    /// Enumerate the host process and its child processes (sidecars, background workers).
32    Processes,
33    /// Report Victauri's own spawned async tasks (MCP server, event drain) and their status.
34    PluginTasks,
35    /// List captured Tauri event bus events (automatically intercepted).
36    EventBus,
37    /// Clear the event bus capture buffer.
38    EventBusClear,
39}
40
41/// Parameters for the `introspect` compound tool.
42#[derive(Debug, Deserialize, JsonSchema)]
43pub struct IntrospectParams {
44    /// Which introspection action to perform.
45    pub action: IntrospectAction,
46
47    /// For `command_timings`: only show commands slower than this threshold (ms).
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub slow_threshold_ms: Option<f64>,
50
51    /// For `contract_record`: the command to record a baseline for.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub command: Option<String>,
54
55    /// For `contract_record`: optional arguments to pass when invoking the command.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub args: Option<serde_json::Value>,
58
59    /// For `db_health`: path to the `SQLite` database file.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub db_path: Option<String>,
62
63    /// Target webview for actions that need JS eval.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub webview_label: Option<String>,
66    // NB: `event_bus` options (`limit`, `since_ms`) are read from the generic `args` object
67    // rather than dedicated fields — adding public fields to this externally-constructible
68    // struct would be a semver-major break (it must stay additive within ^0.7).
69}
70
71/// Actions available in the `fault` compound tool.
72#[derive(Debug, Copy, Clone, Deserialize, JsonSchema)]
73#[serde(rename_all = "snake_case")]
74pub enum FaultAction {
75    /// Inject a fault rule for a specific command.
76    Inject,
77    /// List all active fault injection rules.
78    List,
79    /// Remove a specific fault rule.
80    Clear,
81    /// Remove all fault rules.
82    ClearAll,
83}
84
85/// The type of fault to inject.
86#[derive(Debug, Copy, Clone, Deserialize, JsonSchema)]
87#[serde(rename_all = "snake_case")]
88pub enum FaultKind {
89    /// Add artificial delay before command execution.
90    Delay,
91    /// Return an error without executing the command.
92    Error,
93    /// Drop the response (return empty result).
94    Drop,
95    /// Execute normally but corrupt the response structure.
96    Corrupt,
97}
98
99/// Parameters for the `fault` compound tool.
100///
101/// SCOPE (important): injected faults apply ONLY to commands executed through
102/// Victauri's own `invoke_command` tool. They do NOT intercept the application's
103/// real frontend-driven IPC (`window.__TAURI_INTERNALS__.invoke` → Tauri's native
104/// transport), which runs below the JS layer Victauri can reach. Use `fault` to
105/// probe a backend handler's behavior under failure when YOU drive the command
106/// (e.g. "does my error path return the right shape on a DB error?"). It does not
107/// reproduce a failure a user clicking the UI would experience — that path is not
108/// interceptable cross-platform without CDP.
109#[derive(Debug, Deserialize, JsonSchema)]
110pub struct FaultParams {
111    /// Which fault action to perform.
112    pub action: FaultAction,
113
114    /// Target command name (required for `inject` and `clear`).
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub command: Option<String>,
117
118    /// Type of fault to inject (required for `inject`).
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub fault_type: Option<FaultKind>,
121
122    /// For `delay` faults: delay in milliseconds.
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub delay_ms: Option<u64>,
125
126    /// For `error` faults: error message to return.
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub error_message: Option<String>,
129
130    /// Maximum number of times to trigger (0 or omit for unlimited).
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub max_triggers: Option<u64>,
133}
134
135/// Actions available in the `explain` compound tool.
136#[derive(Debug, Copy, Clone, Deserialize, JsonSchema)]
137#[serde(rename_all = "snake_case")]
138pub enum ExplainAction {
139    /// Summarize recent activity across all layers (IPC, DOM, console, network, window events).
140    Summary,
141    /// Correlate the most recent burst of activity into a causal timeline.
142    LastAction,
143    /// Report what changed in the last N seconds (events, IPC calls, console entries).
144    Diff,
145}
146
147/// Parameters for the `explain` compound tool.
148#[derive(Debug, Deserialize, JsonSchema)]
149pub struct ExplainParams {
150    /// Which explain action to perform.
151    pub action: ExplainAction,
152
153    /// How many seconds to look back (default: 30 for summary, 5 for `last_action`, 10 for diff).
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub seconds: Option<u64>,
156
157    /// Target webview for JS eval (console/network log retrieval).
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub webview_label: Option<String>,
160}