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
//! # Synheart Sensor Agent
//!
//! **Privacy-first PC background sensor for behavioral research.**
//!
//! This library captures keyboard and mouse interaction timing for behavioral
//! research with strong privacy guarantees. Raw events are never stored — only
//! derived statistical features are produced as HSI 1.0 JSON snapshots.
//!
//! # Privacy Guarantees
//!
//! - **No key content** — only timing and category (typing vs. navigation)
//! - **No coordinates** — only mouse movement magnitude/speed
//! - **No raw storage** — events are discarded after feature extraction (every 10 s)
//! - **Transparency** — all collection is logged and auditable via [`TransparencyLog`]
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ Synheart Sensor Agent │
//! ├─────────────────────────────────────────────────────────────┤
//! │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
//! │ │ Collector │──▶│ Windowing │──▶│ Features │ │
//! │ │ (platform) │ │ (10s bins) │ │ (compute) │ │
//! │ └─────────────┘ └─────────────┘ └─────────────┘ │
//! │ │ │ │
//! │ ▼ ▼ │
//! │ ┌─────────────┐ ┌─────────────┐ │
//! │ │Transparency │ │ HSI │ │
//! │ │ Log │ │ Snapshot │ │
//! │ └─────────────┘ └─────────────┘ │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Quick Start
//!
//! ```no_run
//! use synheart_sensor_agent::{collector, core, transparency};
//!
//! // Create a collector (requires Input Monitoring permission on macOS)
//! let config = collector::CollectorConfig::default();
//! let mut collector = collector::Collector::new(config);
//!
//! // Start collection
//! collector.start().expect("Failed to start collector");
//!
//! // Events can be received from collector.receiver()
//! ```
//!
//! # Modules
//!
//! | Module | Purpose |
//! |--------|---------|
//! | [`collector`] | Platform-specific event capture ([`SensorEvent`], [`Collector`]) |
//! | [`config`] | Agent configuration and persistence ([`Config`], [`SourceConfig`]) |
//! | [`core`] | Windowing, feature extraction, and HSI encoding ([`WindowManager`], [`compute_features`], [`HsiBuilder`]) |
//! | [`transparency`] | Auditable collection logging ([`TransparencyLog`], [`TransparencyStats`]) |
//! | [`flux`] | Synheart Flux integration for baseline tracking *(requires `flux` feature)* |
//! | [`gateway`] | Gateway client for real-time HSI sync *(requires `gateway` feature)* |
//! | [`server`] | HTTP server for Chrome extension ingest *(requires `server` feature)* |
//!
//! # Feature Flags
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `flux` | Enables [`SensorFluxProcessor`] for rolling baseline tracking via synheart-flux |
//! | `gateway` | Enables [`GatewayClient`] / [`BlockingGatewayClient`] for syncing HSI to the local gateway |
//! | `server` | Enables the HTTP ingest server for Chrome extension data (implies `flux` + `gateway`) |
//!
//! # Platform Support
//!
//! The [`collector`] module adapts to the build target:
//!
//! - **macOS** — CoreGraphics event tap + NSWorkspace for foreground app detection
//! - **Windows** — Windows Hooks API for keyboard/mouse + foreground window detection
//! - **Other** — No-op collector (compiles but does not capture events)
/// Platform-specific event collection (keyboard, mouse, shortcuts).
///
/// See [`SensorEvent`](collector::types::SensorEvent) for the event types and
/// [`Collector`](collector::Collector) for the platform-agnostic entry point.
/// Agent configuration and persistence.
/// Core functionality — windowing, feature extraction, and HSI snapshot building.
/// Transparency logging for auditable data collection.
/// Synheart Flux integration for baseline tracking and HSI enrichment.
///
/// See [`SensorFluxProcessor`](flux::SensorFluxProcessor) for the main entry point.
/// Gateway client for syncing HSI snapshots to the local synheart-core-gateway.
///
/// See [`GatewayClient`](gateway::GatewayClient) for async usage and
/// [`BlockingGatewayClient`](gateway::BlockingGatewayClient) for synchronous usage.
/// HTTP server for receiving behavioral data from the Chrome extension.
///
/// See `server::run` to start the server and `server::ServerConfig`
/// for configuration.
// Re-export key types at crate root for convenience
pub use ;
pub use ;
pub use ;
pub use ;
// Flux re-exports (when enabled)
pub use ;
// Gateway re-exports (when enabled)
pub use ;
// Server re-exports (when enabled)
pub use ;
/// Library version string sourced from `Cargo.toml`.
pub const VERSION: &str = env!;
/// Privacy declaration that can be displayed to users.
pub const PRIVACY_DECLARATION: &str = r#"
╔══════════════════════════════════════════════════════════════════╗
║ SYNHEART SENSOR AGENT - PRIVACY DECLARATION ║
╠══════════════════════════════════════════════════════════════════╣
║ ║
║ This agent captures behavioral timing data for research. ║
║ ║
║ ✓ WHAT WE CAPTURE: ║
║ • When keys are pressed (timing only) ║
║ • Key categories (backspace, enter, etc. - NOT which letter) ║
║ • Common shortcut patterns (copy, paste, etc. - timing only) ║
║ • How fast the mouse moves (speed only) ║
║ • When clicks and scrolls occur (timing only) ║
║ • Which app is in the foreground (identifier only, no titles) ║
║ ║
║ ✗ WHAT WE NEVER CAPTURE: ║
║ • Which keys you press (no passwords, messages, etc.) ║
║ • Where your cursor is (no screen position tracking) ║
║ • Window titles, file names, or document content ║
║ • Any screen content ║
║ ║
║ All data is processed locally. Raw events are discarded ║
║ after feature extraction (every 10 seconds). ║
║ ║
║ You can view collection statistics anytime with: ║
║ synheart-sensor status ║
║ ║
╚══════════════════════════════════════════════════════════════════╝
"#;