File size: 8,290 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# Configuration

Victauri is configured via the `VictauriBuilder` API in Rust code and/or environment variables.

## Quick Reference

| Setting | Builder Method | Environment Variable | Default |
|---------|---------------|---------------------|---------|
| Port | `.port(7373)` | `VICTAURI_PORT` | 7373 |
| Auth token | `.auth_token("...")` | `VICTAURI_AUTH_TOKEN` | Auto-generated UUID (auth **on**) |
| Disable auth | `.auth_disabled()` | — | Auth enabled |
| Eval timeout | `.eval_timeout(Duration)` | `VICTAURI_EVAL_TIMEOUT` | 30s |
| Event capacity | `.event_capacity(10000)` | — | 10,000 |
| Recorder capacity | `.recorder_capacity(50000)` | — | 50,000 |
| Console log cap | `.console_log_capacity(1000)` | — | 1,000 |
| Network log cap | `.network_log_capacity(1000)` | — | 1,000 |
| Navigation log cap | `.navigation_log_capacity(200)` | — | 200 |
| Event bus capture | `.listen_events(&[...])` | — | Window events only |

## VictauriBuilder API

### Basic Setup

```rust
use victauri_plugin::VictauriBuilder;

tauri::Builder::default()
    .plugin(
        VictauriBuilder::new()
            .port(8080)
            .auth_token("my-fixed-token")
            .build().unwrap(),
    )
    .run(tauri::generate_context!())
    .unwrap();
```

### Port Configuration

```rust
VictauriBuilder::new()
    .port(9000)  // Preferred port
    .build().unwrap()
```

If the preferred port is busy, Victauri tries the next 10 ports (9001-9010). The actual port is:
- Printed to the log on startup
- Written to `<temp_dir>/victauri.port`
- Available via the `/info` endpoint
- Stored in `VictauriState.port` (AtomicU16)

### Authentication

Authentication is **enabled by default**. On startup Victauri auto-generates a UUID
Bearer token and writes it to the per-process discovery directory, where first-party
clients (`VictauriClient::discover()`, the CLI, the VS Code extension) read it
automatically — so zero-config local development still "just works", but no unauthenticated
local process can reach the god-mode tools. The server also binds to `127.0.0.1` only and
the plugin is `#[cfg(debug_assertions)]`-gated.

```rust
// 1. Auth on by default (auto-generated UUID token, auto-discovered by clients)
VictauriBuilder::new().build().unwrap()

// 2. Fixed token (e.g. for CI where you want a known value)
VictauriBuilder::new()
    .auth_token("my-secret-token")
    .build().unwrap()

// 3. Opt OUT of auth (local-only, you accept that any local process can connect)
VictauriBuilder::new()
    .auth_disabled()
    .build().unwrap()
```

The `VICTAURI_AUTH_TOKEN` environment variable overrides the auto-generated token with a
fixed value.

### Privacy Controls

#### Privacy Profiles

Three tiers of access control:

```rust
use victauri_plugin::PrivacyProfile;

// Read-only: snapshots, logs, registry only. No mutations.
VictauriBuilder::new()
    .privacy_profile(PrivacyProfile::Observe)
    .build().unwrap()

// Testing: observe + interactions + input + storage + recording
VictauriBuilder::new()
    .privacy_profile(PrivacyProfile::Test)
    .build().unwrap()

// Full control: everything enabled (default)
VictauriBuilder::new()
    .privacy_profile(PrivacyProfile::FullControl)
    .build().unwrap()
```

`Observe` and `Test` profiles automatically enable output redaction.

#### Strict Privacy Mode

Shorthand for `Observe` profile:

```rust
VictauriBuilder::new()
    .strict_privacy_mode()
    .build().unwrap()
```

#### Tool Disabling

Disable specific tools by name:

```rust
VictauriBuilder::new()
    .disable_tools(&["eval_js", "screenshot", "invoke_command"])
    .build().unwrap()
```

Disabled tools return an error when called and are not listed in tool discovery.

#### Command Allowlists and Blocklists

Control which Tauri commands can be invoked via MCP:

```rust
// Only allow these commands (positive allowlist)
VictauriBuilder::new()
    .command_allowlist(&["get_settings", "get_status", "search"])
    .build().unwrap()

// Block specific commands (negative blocklist)
VictauriBuilder::new()
    .command_blocklist(&["delete_user", "reset_database", "admin_override"])
    .build().unwrap()
```

The allowlist takes priority: if set, only listed commands are permitted regardless of the blocklist.

### Output Redaction

Automatically redact sensitive data from tool responses:

```rust
VictauriBuilder::new()
    .enable_redaction()  // Built-in patterns: API keys, emails, tokens
    .add_redaction_pattern(r"SECRET_\w+")  // Custom regex
    .add_redaction_pattern(r"sk-[a-zA-Z0-9]+")  // OpenAI keys
    .build().unwrap()
```

Built-in patterns match:
- API keys (`api_key`, `apikey`, `api-key` in JSON)
- Bearer tokens
- Email addresses
- Common secret patterns

### Capacity Tuning

```rust
VictauriBuilder::new()
    .event_capacity(50_000)       // Ring buffer for event log (max: 1,000,000)
    .recorder_capacity(100_000)   // Time-travel recording buffer (max: 1,000,000)
    .eval_timeout(std::time::Duration::from_secs(60))  // JS eval timeout (max: 300s)
    .console_log_capacity(2000)   // JS bridge console buffer
    .network_log_capacity(2000)   // JS bridge network buffer
    .navigation_log_capacity(500) // JS bridge navigation buffer
    .build().unwrap()
```

### Event Bus Capture

Window lifecycle events (resize, move, focus, close, theme change, drag-drop) are captured automatically. To also capture app-specific events emitted via `app.emit()`:

```rust
VictauriBuilder::new()
    .listen_events(&["notification-added", "settings-changed", "sync-complete"])
    .build().unwrap()
```

All captured events appear in `introspect.event_bus`.

### File Navigation

By default, the `navigate` tool only allows `http://` and `https://` URLs. To allow `file://` URLs:

```rust
VictauriBuilder::new()
    .allow_file_navigation()
    .build().unwrap()
```

### Ready Callback

Get notified when the server is bound and ready:

```rust
VictauriBuilder::new()
    .on_ready(|port| {
        println!("Victauri ready on port {}", port);
    })
    .build().unwrap()
```

### Pre-registering Commands

Register `#[inspectable]` command schemas at build time:

```rust
VictauriBuilder::new()
    .commands(&[greet__schema(), increment__schema()])
    .build().unwrap()
```

## Environment Variables

| Variable | Description |
|----------|-------------|
| `VICTAURI_PORT` | Override the MCP server port |
| `VICTAURI_AUTH_TOKEN` | Enable auth with this token |
| `VICTAURI_EVAL_TIMEOUT` | Eval timeout in seconds |

Environment variables take priority over builder settings.

## Watchdog Configuration

The `victauri-watchdog` binary is configured entirely via environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `VICTAURI_PORT` | 7373 | Port to monitor |
| `VICTAURI_INTERVAL` | 5 | Health check interval in seconds |
| `VICTAURI_MAX_FAILURES` | 3 | Consecutive failures before recovery action |
| `VICTAURI_ON_FAILURE` | (none) | Shell command to execute on failure |

```bash
VICTAURI_PORT=7373 VICTAURI_MAX_FAILURES=5 VICTAURI_ON_FAILURE="notify-send 'App crashed'" victauri-watchdog
```

## Full Example

```rust
use std::time::Duration;
use victauri_plugin::{VictauriBuilder, PrivacyProfile};

tauri::Builder::default()
    .plugin(
        VictauriBuilder::new()
            // Network
            .port(7373)
            .eval_timeout(Duration::from_secs(30))
            // Auth
            .auth_token("dev-token-123")
            // Privacy
            .privacy_profile(PrivacyProfile::Test)
            .command_blocklist(&["dangerous_command"])
            .disable_tools(&["screenshot"])
            // Redaction
            .enable_redaction()
            .add_redaction_pattern(r"password=\w+")
            // Capacity
            .event_capacity(20_000)
            .recorder_capacity(100_000)
            .console_log_capacity(2000)
            // Commands
            .commands(&[greet__schema(), increment__schema()])
            // Event bus
            .listen_events(&["app-event", "sync-complete"])
            // Callback
            .on_ready(|port| println!("MCP server on :{}", port))
            .build().unwrap(),
    )
    .invoke_handler(tauri::generate_handler![greet, increment])
    .run(tauri::generate_context!())
    .unwrap();
```