synheart-sensor-agent 0.4.0

Privacy-first PC background sensor for behavioral research
Documentation
//! # 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. It is a **pure collector** — raw
//! events are emitted via a channel for downstream processing by
//! `synheart-session-runtime` via `synheart-core-rust`.
//!
//! # Privacy Guarantees
//!
//! - **No key content** — only timing and category (typing vs. navigation)
//! - **No coordinates** — only mouse movement magnitude/speed
//! - **No raw storage** — events are emitted and discarded immediately
//! - **Transparency** — all collection is logged and auditable via [`TransparencyLog`]
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │                    Synheart Sensor Agent                     │
//! ├─────────────────────────────────────────────────────────────┤
//! │  ┌─────────────┐                     ┌─────────────┐       │
//! │  │  Collector  │────────────────────▶│ Raw Events  │       │
//! │  │ (platform)  │                     │  (channel)  │       │
//! │  └─────────────┘                     └─────────────┘       │
//! │         │                                                  │
//! │         ▼                                                  │
//! │  ┌─────────────┐                                           │
//! │  │Transparency │                                           │
//! │  │    Log      │                                           │
//! │  └─────────────┘                                           │
//! └─────────────────────────────────────────────────────────────┘
//!    Pure sensor — windowing, features, and sessions handled by
//!    synheart-session-runtime via synheart-core-rust orchestration
//! ```
//!
//! # Quick Start
//!
//! ```no_run
//! use synheart_sensor_agent::{collector, 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()
//! ```
//!
//! # 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)

#![cfg_attr(docsrs, feature(doc_cfg))]

/// Platform-specific event collection (keyboard, mouse, shortcuts).
pub mod collector;

/// Agent configuration and persistence.
pub mod config;

/// Transparency logging for auditable data collection.
pub mod transparency;

/// HTTP server for receiving behavioral data from the Chrome extension.
#[cfg(feature = "server")]
pub mod server;

// Re-export key types at crate root for convenience
pub use collector::{Collector, CollectorConfig, CollectorError, SensorEvent};
pub use config::{Config, SourceConfig};
pub use transparency::{SharedTransparencyLog, TransparencyLog, TransparencyStats};

// Server re-exports (when enabled)
#[cfg(feature = "server")]
pub use server::{run as run_server, ServerConfig};

/// Library version string sourced from `Cargo.toml`.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// 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                                          ║
║                                                                  ║
║  Raw events are emitted to the orchestration layer and           ║
║  discarded immediately. No raw data is stored locally.           ║
║                                                                  ║
║  You can view collection statistics anytime with:                ║
║    synheart-sensor status                                        ║
║                                                                  ║
╚══════════════════════════════════════════════════════════════════╝
"#;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_privacy_declaration_contents() {
        assert!(PRIVACY_DECLARATION.contains("PRIVACY"));
        assert!(PRIVACY_DECLARATION.contains("NEVER CAPTURE"));
        assert!(PRIVACY_DECLARATION.contains("keys you press"));
    }
}