Skip to main content

sqry_core/uses/
mod.rs

1//! Local uses and insights module
2//!
3//! This module provides privacy-respecting behavioral capture for sqry,
4//! enabling users to understand their own usage patterns and share
5//! anonymous insights if they choose to.
6//!
7//! # Architecture
8//!
9//! ```text
10//! sqry operations ──▶ UsesCollector ──▶ Daily JSONL files
11//!                       (fire-and-forget)     │
12//!                                             ▼
13//!                     DiagnosticsAggregator ◀─┘
14//!                              │
15//!                              ▼
16//!                     Weekly summaries + Insights reports
17//! ```
18//!
19//! # Privacy Guarantees
20//!
21//! All data is local-first:
22//! - Events capture behavioral patterns, never code content
23//! - All fields are strongly-typed enums (no arbitrary strings)
24//! - Sharing is always explicit and requires confirmation
25//! - Users can disable entirely via config or environment
26//!
27//! # Feature Gating
28//!
29//! This module is gated behind the `uses` feature flag. The hierarchy is:
30//! - `uses`: Local uses recording
31//! - `insights`: Local summaries and reports (requires `uses`)
32//! - `troubleshoot`: Support bundle generation (requires `insights`)
33//!
34//! Build with `--no-default-features` to produce a binary with no collection code.
35//!
36//! # Usage
37//!
38//! ```rust,ignore
39//! use sqry_core::uses::{UseEvent, UseEventType, QueryKind, DiagnosticsAggregator};
40//!
41//! // Record an event (fire-and-forget)
42//! let event = UseEvent::new(UseEventType::QueryExecuted {
43//!     kind: QueryKind::CallChain,
44//!     result_count: 42,
45//! });
46//! collector.record(event);
47//!
48//! // Get weekly insights
49//! let aggregator = DiagnosticsAggregator::new(&uses_dir);
50//! let summary = aggregator.summarize_week("2025-W50")?;
51//! ```
52
53mod types;
54
55// Core uses modules
56mod collector;
57mod config;
58mod storage;
59
60// Insights module (aggregator)
61#[cfg(feature = "insights")]
62mod aggregator;
63
64// Feature-gated submodules
65#[cfg(feature = "troubleshoot")]
66mod troubleshoot;
67
68#[cfg(feature = "share")]
69mod share;
70
71// Re-export all types from the types module
72pub use types::*;
73
74// Re-export collector, config, and storage
75pub use collector::{CollectorTimedUse, UsesCollector};
76pub use config::{
77    AutoSummarizeConfig, ConfigLoadError, ConfigSaveError, ContextualFeedbackConfig,
78    PromptFrequency, UsesConfig,
79};
80pub use storage::{UsesStorage, UsesWriter};
81
82// Feature-gated re-exports
83#[cfg(feature = "insights")]
84pub use aggregator::{AggregatorError, DiagnosticsAggregator};
85
86#[cfg(feature = "troubleshoot")]
87pub use troubleshoot::generate_bundle;
88
89#[cfg(feature = "share")]
90pub use share::{
91    format_share_preview, generate_current_share_snapshot, generate_share_snapshot, merge_snapshots,
92};