par_term_config/scripting.rs
1//! Configuration types for external observer scripts.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6use crate::automation::RestartPolicy;
7
8/// Configuration for an external observer script that receives terminal events via JSON protocol.
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10pub struct ScriptConfig {
11 /// Human-readable name for this script
12 pub name: String,
13
14 /// Whether this script is enabled (default: true)
15 #[serde(default = "crate::defaults::bool_true")]
16 pub enabled: bool,
17
18 /// Path to the script executable
19 pub script_path: String,
20
21 /// Arguments to pass to the script
22 #[serde(default)]
23 pub args: Vec<String>,
24
25 /// Whether to start this script automatically when a tab opens
26 #[serde(default)]
27 pub auto_start: bool,
28
29 /// Policy for restarting the script when it exits
30 #[serde(default)]
31 pub restart_policy: RestartPolicy,
32
33 /// Delay in milliseconds before restarting (when restart_policy is not Never)
34 #[serde(default)]
35 pub restart_delay_ms: u64,
36
37 /// Event types to subscribe to (empty = all events)
38 #[serde(default)]
39 pub subscriptions: Vec<String>,
40
41 /// Additional environment variables to set for the script process
42 #[serde(default)]
43 pub env_vars: HashMap<String, String>,
44
45 /// Allow this script to inject text into the active PTY via `WriteText`.
46 ///
47 /// Defaults to `false`. Must be explicitly set to `true` to enable.
48 /// When enabled, VT/ANSI escape sequences are stripped before writing
49 /// and a rate limit is applied (see `write_text_rate_limit`).
50 #[serde(default)]
51 pub allow_write_text: bool,
52
53 /// Allow this script to spawn external processes via `RunCommand`.
54 ///
55 /// Defaults to `false`. Must be explicitly set to `true` to enable.
56 /// When enabled, the command is checked against the denylist and a
57 /// rate limit is applied (see `run_command_rate_limit`).
58 #[serde(default)]
59 pub allow_run_command: bool,
60
61 /// Allow this script to modify runtime configuration via `ChangeConfig`.
62 ///
63 /// Defaults to `false`. Must be explicitly set to `true` to enable.
64 /// Only keys in the runtime allowlist may be changed.
65 #[serde(default)]
66 pub allow_change_config: bool,
67
68 /// Maximum `WriteText` writes per second (0 = use default of 10/s).
69 #[serde(default)]
70 pub write_text_rate_limit: u32,
71
72 /// Maximum `RunCommand` executions per second (0 = use default of 1/s).
73 #[serde(default)]
74 pub run_command_rate_limit: u32,
75}