haloforge_plugin_api/
permissions.rs1#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
4#[serde(tag = "type", content = "value", rename_all = "snake_case")]
5pub enum Permission {
6 DatabaseReadAll,
8 DatabaseRead(String),
10 DatabaseWrite(String),
12 DatabaseCreateTables,
14
15 FilesystemRead,
17 FilesystemReadAppData,
19 FilesystemWrite,
21 FilesystemWriteAppData,
23
24 NetworkHttp,
26 NetworkHttpDomain(String),
28
29 IpcRegister,
31
32 EventsEmit,
34 EventsListen,
36
37 UiInject,
39
40 ProcessSpawn,
42 ProcessSpawnWhitelist(Vec<String>),
44
45 Notifications,
47
48 ClipboardRead,
50 ClipboardWrite,
52
53 HostNavigation,
55 HostAppStateRead,
57 HostFileIntents,
59 HostFileDialogs,
61 HostAIChatAccess,
63 HostThemeRead,
65 HostEventSubscribe,
67
68 AppConfigRead,
70}
71
72impl Permission {
73 pub fn tier(&self) -> PermissionTier {
75 match self {
76 Self::UiInject
77 | Self::EventsListen
78 | Self::DatabaseCreateTables
79 | Self::AppConfigRead
80 | Self::Notifications
81 | Self::HostAppStateRead
82 | Self::HostThemeRead => PermissionTier::Transparent,
83
84 Self::DatabaseReadAll
85 | Self::DatabaseRead(_)
86 | Self::IpcRegister
87 | Self::EventsEmit
88 | Self::NetworkHttpDomain(_)
89 | Self::HostNavigation
90 | Self::HostFileIntents
91 | Self::HostFileDialogs
92 | Self::HostAIChatAccess
93 | Self::HostEventSubscribe => PermissionTier::Standard,
94
95 Self::FilesystemRead
96 | Self::FilesystemWrite
97 | Self::FilesystemReadAppData
98 | Self::FilesystemWriteAppData
99 | Self::NetworkHttp
100 | Self::ProcessSpawnWhitelist(_)
101 | Self::ClipboardRead
102 | Self::ClipboardWrite => PermissionTier::Sensitive,
103
104 Self::DatabaseWrite(_)
105 | Self::ProcessSpawn => PermissionTier::Restricted,
106 }
107 }
108
109 pub fn description(&self) -> String {
111 match self {
112 Self::DatabaseReadAll => "Read all app data".into(),
113 Self::DatabaseRead(t) => format!("Read table: {t}"),
114 Self::DatabaseWrite(t) => format!("Write to table: {t}"),
115 Self::DatabaseCreateTables => "Create plugin-owned database tables".into(),
116 Self::FilesystemRead => "Read files from your filesystem".into(),
117 Self::FilesystemReadAppData => "Read files in the app data directory".into(),
118 Self::FilesystemWrite => "Write files to your filesystem".into(),
119 Self::FilesystemWriteAppData => "Write files in the app data directory".into(),
120 Self::NetworkHttp => "Make outbound HTTP requests".into(),
121 Self::NetworkHttpDomain(d) => format!("Make HTTP requests to: {d}"),
122 Self::IpcRegister => "Register new app commands".into(),
123 Self::EventsEmit => "Emit app events".into(),
124 Self::EventsListen => "Listen to app lifecycle events".into(),
125 Self::UiInject => "Inject UI components".into(),
126 Self::ProcessSpawn => "Spawn arbitrary child processes".into(),
127 Self::ProcessSpawnWhitelist(v) => format!("Spawn processes: {}", v.join(", ")),
128 Self::Notifications => "Show desktop notifications".into(),
129 Self::ClipboardRead => "Read the clipboard".into(),
130 Self::ClipboardWrite => "Write to the clipboard".into(),
131 Self::HostNavigation => "Navigate within HaloForge".into(),
132 Self::HostAppStateRead => "Read HaloForge UI state".into(),
133 Self::HostFileIntents => "Receive file-open intents from HaloForge".into(),
134 Self::HostFileDialogs => "Open HaloForge file and directory dialogs".into(),
135 Self::HostAIChatAccess => "Use HaloForge AI models and chat transport".into(),
136 Self::HostThemeRead => "Read HaloForge theme tokens".into(),
137 Self::HostEventSubscribe => "Subscribe to HaloForge host events".into(),
138 Self::AppConfigRead => "Read app configuration".into(),
139 }
140 }
141}
142
143#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
144pub enum PermissionTier {
145 Transparent = 0,
147 Standard = 1,
149 Sensitive = 2,
151 Restricted = 3,
153}
154
155#[cfg(test)]
156mod tests {
157 use super::{Permission, PermissionTier};
158
159 #[test]
160 fn host_permissions_have_expected_tiers() {
161 assert_eq!(Permission::HostAppStateRead.tier(), PermissionTier::Transparent);
162 assert_eq!(Permission::HostThemeRead.tier(), PermissionTier::Transparent);
163 assert_eq!(Permission::HostNavigation.tier(), PermissionTier::Standard);
164 assert_eq!(Permission::HostFileDialogs.tier(), PermissionTier::Standard);
165 assert_eq!(Permission::HostAIChatAccess.tier(), PermissionTier::Standard);
166 }
167}