Skip to main content

orbok_core/
privacy.rs

1//! Privacy settings and local data visibility (RFC-039 §6, §17, as amended
2//! 2026-09-25).
3//!
4//! This is the shared vocabulary for privacy settings. It lives in
5//! `orbok-core` so that `orbok`, `orbok-ui`, and any future
6//! diagnostics layer can all refer to the same types without a
7//! circular dependency.
8
9use serde::{Deserialize, Serialize};
10
11// ── Privacy settings ──────────────────────────────────────────────────
12
13/// Privacy preferences (RFC-039 §17, as amended 2026-09-25, Task 115).
14///
15/// Privacy is orbok's fixed safe defaults -- everything is processed on this
16/// computer, and text-bearing caches are cleared from Storage -- plus **one**
17/// control, *Remember recent searches*. There is no privacy *mode*: the mode
18/// that used to sit here could not be set from any screen, and its only
19/// effect was reachable by hand-editing `settings.json`.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct PrivacySettings {
22    /// Whether to persist recent search queries. The whole truth about
23    /// whether a search is recorded.
24    pub remember_recent_searches: bool,
25    /// Whether diagnostics may include raw filesystem paths (RFC-040).
26    pub diagnostics_include_paths: bool,
27    /// Whether diagnostics may include recent search queries (RFC-040).
28    pub diagnostics_include_recent_searches: bool,
29}
30
31impl Default for PrivacySettings {
32    fn default() -> Self {
33        Self {
34            remember_recent_searches: true,
35            diagnostics_include_paths: false,
36            diagnostics_include_recent_searches: false,
37        }
38    }
39}
40
41impl PrivacySettings {
42    /// Whether recent searches are recorded: just the toggle.
43    pub fn effective_recent_searches(&self) -> bool {
44        self.remember_recent_searches
45    }
46}
47
48// ── Local data category ───────────────────────────────────────────────
49
50/// Classified local data categories for the storage dashboard
51/// and cleanup controls (RFC-039 §6, §15, §16).
52///
53/// User-facing labels must avoid technical terms — see RFC-039 §15
54/// for the mapping (`KeywordIndex` → "Search data", etc.).
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum LocalDataCategory {
57    SourcePaths,
58    FileMetadata,
59    ExtractedText,
60    KeywordIndex,
61    Embeddings,
62    Snippets,
63    TemporaryPreviews,
64    RecentSearches,
65    Logs,
66    Diagnostics,
67    ModelFiles,
68    Settings,
69}
70
71impl LocalDataCategory {
72    /// Plain-language user label (RFC-039 §15 — no "cache/catalog/vector").
73    pub fn user_label(self) -> &'static str {
74        match self {
75            LocalDataCategory::SourcePaths => "Folder list",
76            LocalDataCategory::FileMetadata => "File information",
77            LocalDataCategory::ExtractedText => "Prepared text",
78            LocalDataCategory::KeywordIndex => "Search data",
79            LocalDataCategory::Embeddings => "Better search data",
80            LocalDataCategory::Snippets => "Temporary previews",
81            LocalDataCategory::TemporaryPreviews => "Temporary previews",
82            LocalDataCategory::RecentSearches => "Recent searches",
83            LocalDataCategory::Logs => "Logs",
84            LocalDataCategory::Diagnostics => "Support files",
85            LocalDataCategory::ModelFiles => "Search helper",
86            LocalDataCategory::Settings => "App settings",
87        }
88    }
89}
90
91// ── Diagnostics policy ────────────────────────────────────────────────
92
93/// Policy governing what a diagnostics export may include (RFC-040 §12).
94///
95/// All sensitive fields default to `false`. RFC-040 is accepted and unbuilt;
96/// this policy is what it will read. It has no privacy-mode input: the mode
97/// was removed (RFC-039 amendment, Task 115), and it behaves as the Standard
98/// mode always did -- sensitive opt-ins may be offered, none is on.
99#[derive(Debug, Clone, Default)]
100pub struct DiagnosticsPolicy {
101    pub include_raw_paths: bool,
102    pub include_folder_names: bool,
103    pub include_recent_searches: bool,
104    pub include_detailed_logs: bool,
105}
106
107impl DiagnosticsPolicy {
108    /// Build from privacy settings.
109    pub fn from_privacy(settings: &PrivacySettings) -> Self {
110        Self {
111            include_raw_paths: false,    // never enabled by default
112            include_folder_names: false, // opt-in only
113            include_recent_searches: settings.diagnostics_include_recent_searches,
114            include_detailed_logs: false,
115        }
116    }
117
118    /// Whether this policy permits showing sensitive opt-in checkboxes.
119    /// Fixed at the Standard default until RFC-040 decides otherwise.
120    pub fn allows_sensitive_optins(&self) -> bool {
121        true
122    }
123}