clipmem 0.5.6

macOS clipboard memory backed by SQLite and searchable from agent runtimes
Documentation
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
use std::path::PathBuf;

use rusqlite::Connection;
use serde::{Deserialize, Serialize};

use crate::model::{SearchHit, SnapshotKind};

pub struct Database {
    pub(crate) conn: Connection,
    pub(in crate::db) path: PathBuf,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::db) enum ArchiveChangeKind {
    ArchiveContent,
    Settings,
    Ocr,
    Storage,
    Service,
    #[allow(dead_code)]
    AppPreferences,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ArchiveRevision {
    pub(in crate::db) revision: u64,
    pub(in crate::db) archive_content_revision: u64,
    pub(in crate::db) settings_revision: u64,
    pub(in crate::db) ocr_revision: u64,
    pub(in crate::db) storage_revision: u64,
    pub(in crate::db) service_revision: u64,
    pub(in crate::db) app_preferences_revision: u64,
    pub(in crate::db) last_change_kind: String,
    pub(in crate::db) updated_at: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SearchMode {
    Auto,
    Fts,
    Literal,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TimelineSort {
    Asc,
    Desc,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RetrievalKind {
    Text,
    Html,
    Rtf,
    Url,
    File,
    Image,
    Pdf,
    Binary,
    Other,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct RetrievalFilters {
    pub(in crate::db) since: Option<String>,
    pub(in crate::db) until: Option<String>,
    pub(in crate::db) hours: Option<u32>,
    pub(in crate::db) app: Option<String>,
    pub(in crate::db) bundle_id: Option<String>,
    pub(in crate::db) kind: Option<RetrievalKind>,
    pub(in crate::db) has_text: bool,
    pub(in crate::db) has_url: bool,
    pub(in crate::db) has_file_url: bool,
    pub(in crate::db) has_image: bool,
    pub(in crate::db) has_pdf: bool,
    pub(in crate::db) min_bytes: Option<usize>,
    pub(in crate::db) max_bytes: Option<usize>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub(crate) struct CaptureSettings {
    pub(in crate::db) paused: bool,
    pub(in crate::db) retention_seconds: Option<u64>,
    pub(in crate::db) api_key_filter_enabled: bool,
    pub(in crate::db) ocr_enabled: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
pub(crate) struct CapturePolicy {
    pub(in crate::db) settings: CaptureSettings,
    pub(in crate::db) ignored_bundle_ids: Vec<String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum CaptureSkipReason {
    ApiKeyFilter,
    RestoredSnapshot,
}

#[derive(Debug, Clone)]
pub(crate) enum CaptureStoreOutcome {
    Stored(crate::model::CaptureStoreResult),
    Skipped(CaptureSkipReason),
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct SnapshotDeletionReport {
    pub(in crate::db) snapshot_id: i64,
    pub(in crate::db) item_count: usize,
    pub(in crate::db) representation_count: usize,
    pub(in crate::db) capture_event_count: usize,
    pub(in crate::db) total_bytes: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct PurgeReport {
    pub(in crate::db) older_than_seconds: u64,
    pub(in crate::db) dry_run: bool,
    pub(in crate::db) snapshot_count: usize,
    pub(in crate::db) item_count: usize,
    pub(in crate::db) representation_count: usize,
    pub(in crate::db) capture_event_count: usize,
    pub(in crate::db) total_bytes: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct OcrCandidate {
    pub(in crate::db) raw_sha256: String,
    pub(in crate::db) blob_value: Vec<u8>,
    pub(in crate::db) snapshot_count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct OcrStatusReport {
    pub(in crate::db) pending: usize,
    pub(in crate::db) ready: usize,
    pub(in crate::db) failed: usize,
    pub(in crate::db) skipped: usize,
    pub(in crate::db) snapshots_with_ocr_text: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct OcrRunReport {
    pub(in crate::db) processed: usize,
    pub(in crate::db) ready: usize,
    pub(in crate::db) failed: usize,
    pub(in crate::db) skipped: usize,
    pub(in crate::db) remaining_pending: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct OcrCandidateSummary {
    pub(in crate::db) raw_sha256: String,
    pub(in crate::db) byte_len: usize,
    pub(in crate::db) snapshot_count: usize,
    pub(in crate::db) updated_at: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct OcrResultRecord {
    pub(in crate::db) raw_sha256: String,
    pub(in crate::db) status: String,
    pub(in crate::db) engine: Option<String>,
    pub(in crate::db) recognition_level: Option<String>,
    pub(in crate::db) text_value: Option<String>,
    pub(in crate::db) error: Option<String>,
    pub(in crate::db) attempt_count: usize,
    pub(in crate::db) updated_at: String,
    pub(in crate::db) snapshot_count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct StorageFileSizes {
    pub(crate) db: u64,
    pub(crate) wal: u64,
    pub(crate) shm: u64,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct StorageCheckpointReport {
    pub(crate) busy: i64,
    pub(crate) log: i64,
    pub(crate) checkpointed: i64,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct StorageCompactReport {
    pub(crate) db_path: String,
    pub(crate) before: StorageFileSizes,
    pub(crate) after: StorageFileSizes,
    pub(crate) total_before_bytes: u64,
    pub(crate) total_after_bytes: u64,
    pub(crate) reclaimed_bytes: u64,
    pub(crate) estimated_reclaimable_bytes: u64,
    pub(crate) page_count: usize,
    pub(crate) freelist_count: usize,
    pub(crate) checkpoint: StorageCheckpointReport,
    pub(crate) dry_run: bool,
    pub(crate) completed: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct ImageOptimizationReport {
    pub(crate) dry_run: bool,
    pub(crate) format: &'static str,
    pub(crate) scanned_rows: usize,
    pub(crate) compressed_rows: usize,
    pub(crate) skipped_rows: usize,
    pub(crate) conflict_count: usize,
    pub(crate) original_bytes: usize,
    pub(crate) optimized_bytes: usize,
    pub(crate) logical_saved_bytes: usize,
    pub(crate) compact_run: bool,
    pub(crate) compact: Option<StorageCompactReport>,
    pub(crate) compact_error: Option<String>,
    pub(crate) filesystem_saved_bytes: u64,
    pub(crate) filesystem_growth_bytes: u64,
    pub(crate) compact_recommended: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct ImageOptimizationCandidateSummary {
    pub(in crate::db) snapshot_id: i64,
    pub(in crate::db) item_index: i64,
    pub(in crate::db) uti: String,
    pub(in crate::db) byte_len: usize,
    pub(in crate::db) raw_sha256: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub(crate) enum ImageOptimizationProgressEvent {
    Started {
        total_rows: usize,
    },
    Scanning {
        scanned_rows: usize,
        total_rows: usize,
        compressed_rows: usize,
        skipped_rows: usize,
        conflict_count: usize,
    },
    Compacting {
        scanned_rows: usize,
        total_rows: usize,
        compressed_rows: usize,
        skipped_rows: usize,
        conflict_count: usize,
    },
    Complete {
        report: Box<ImageOptimizationReport>,
    },
}

#[derive(Debug, Clone, Serialize)]
pub struct SearchResults {
    pub(in crate::db) mode_used: SearchMode,
    pub(in crate::db) hits: Vec<SearchHit>,
    pub(in crate::db) has_more: bool,
}

#[derive(Debug, Clone, Serialize)]
pub struct RecentResults {
    pub(in crate::db) hits: Vec<SearchHit>,
    pub(in crate::db) has_more: bool,
}

#[derive(Debug, Clone, Serialize)]
pub struct TimelineResults {
    pub(in crate::db) events: Vec<crate::model::TimelineEvent>,
    pub(in crate::db) has_more: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct StatsReport {
    pub(in crate::db) snapshot_count: usize,
    pub(in crate::db) capture_event_count: usize,
    pub(in crate::db) unique_app_count: usize,
    pub(in crate::db) total_bytes: usize,
    pub(in crate::db) average_bytes_per_snapshot: f64,
    pub(in crate::db) average_captures_per_snapshot: f64,
    pub(in crate::db) dedupe_ratio: f64,
    pub(in crate::db) first_observed_at: Option<String>,
    pub(in crate::db) last_observed_at: Option<String>,
    pub(in crate::db) archive_span_seconds: Option<i64>,
    pub(in crate::db) most_recopied_snapshot: Option<StatsSnapshotLeaderboardEntry>,
    pub(in crate::db) kind_breakdown: Vec<StatsKindBreakdownEntry>,
    pub(in crate::db) top_apps: Vec<StatsAppEntry>,
    pub(in crate::db) busiest_hours: Vec<StatsTimeBucketEntry>,
    pub(in crate::db) busiest_weekdays: Vec<StatsTimeBucketEntry>,
    pub(in crate::db) largest_snapshots: Vec<StatsSnapshotLeaderboardEntry>,
    pub(in crate::db) most_captured_snapshots: Vec<StatsSnapshotLeaderboardEntry>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct StatsKindBreakdownEntry {
    pub(in crate::db) kind: SnapshotKind,
    pub(in crate::db) snapshot_count: usize,
    pub(in crate::db) total_bytes: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct StatsAppEntry {
    pub(in crate::db) app: String,
    pub(in crate::db) capture_event_count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct StatsTimeBucketEntry {
    pub(in crate::db) bucket: String,
    pub(in crate::db) capture_event_count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct StatsSnapshotLeaderboardEntry {
    pub(in crate::db) snapshot_id: i64,
    pub(in crate::db) capture_count: usize,
    pub(in crate::db) kind: SnapshotKind,
    pub(in crate::db) preview_text: String,
    pub(in crate::db) app_name: Option<String>,
    pub(in crate::db) last_observed_at: String,
    pub(in crate::db) total_bytes: usize,
}

impl StatsReport {
    #[must_use]
    pub fn snapshot_count(&self) -> usize {
        self.snapshot_count
    }

    #[must_use]
    pub fn capture_event_count(&self) -> usize {
        self.capture_event_count
    }

    #[must_use]
    pub fn unique_app_count(&self) -> usize {
        self.unique_app_count
    }

    #[must_use]
    pub fn total_bytes(&self) -> usize {
        self.total_bytes
    }

    #[must_use]
    pub fn average_bytes_per_snapshot(&self) -> f64 {
        self.average_bytes_per_snapshot
    }

    #[must_use]
    pub fn average_captures_per_snapshot(&self) -> f64 {
        self.average_captures_per_snapshot
    }

    #[must_use]
    pub fn dedupe_ratio(&self) -> f64 {
        self.dedupe_ratio
    }

    #[must_use]
    pub fn first_observed_at(&self) -> Option<&str> {
        self.first_observed_at.as_deref()
    }

    #[must_use]
    pub fn last_observed_at(&self) -> Option<&str> {
        self.last_observed_at.as_deref()
    }

    #[must_use]
    pub fn archive_span_seconds(&self) -> Option<i64> {
        self.archive_span_seconds
    }

    #[must_use]
    pub fn most_recopied_snapshot(&self) -> Option<&StatsSnapshotLeaderboardEntry> {
        self.most_recopied_snapshot.as_ref()
    }

    #[must_use]
    pub fn kind_breakdown(&self) -> &[StatsKindBreakdownEntry] {
        &self.kind_breakdown
    }

    #[must_use]
    pub fn top_apps(&self) -> &[StatsAppEntry] {
        &self.top_apps
    }

    #[must_use]
    pub fn busiest_hours(&self) -> &[StatsTimeBucketEntry] {
        &self.busiest_hours
    }

    #[must_use]
    pub fn busiest_weekdays(&self) -> &[StatsTimeBucketEntry] {
        &self.busiest_weekdays
    }

    #[must_use]
    pub fn largest_snapshots(&self) -> &[StatsSnapshotLeaderboardEntry] {
        &self.largest_snapshots
    }

    #[must_use]
    pub fn most_captured_snapshots(&self) -> &[StatsSnapshotLeaderboardEntry] {
        &self.most_captured_snapshots
    }
}

impl StatsKindBreakdownEntry {
    #[must_use]
    pub fn kind(&self) -> SnapshotKind {
        self.kind
    }

    #[must_use]
    pub fn snapshot_count(&self) -> usize {
        self.snapshot_count
    }

    #[must_use]
    pub fn total_bytes(&self) -> usize {
        self.total_bytes
    }
}

impl StatsAppEntry {
    #[must_use]
    pub fn app(&self) -> &str {
        &self.app
    }

    #[must_use]
    pub fn capture_event_count(&self) -> usize {
        self.capture_event_count
    }
}

impl StatsTimeBucketEntry {
    #[must_use]
    pub fn bucket(&self) -> &str {
        &self.bucket
    }

    #[must_use]
    pub fn capture_event_count(&self) -> usize {
        self.capture_event_count
    }
}

impl StatsSnapshotLeaderboardEntry {
    #[must_use]
    pub fn snapshot_id(&self) -> i64 {
        self.snapshot_id
    }

    #[must_use]
    pub fn capture_count(&self) -> usize {
        self.capture_count
    }

    #[must_use]
    pub fn kind(&self) -> SnapshotKind {
        self.kind
    }

    #[must_use]
    pub fn preview_text(&self) -> &str {
        &self.preview_text
    }

    #[must_use]
    pub fn app_name(&self) -> Option<&str> {
        self.app_name.as_deref()
    }

    #[must_use]
    pub fn last_observed_at(&self) -> &str {
        &self.last_observed_at
    }

    #[must_use]
    pub fn total_bytes(&self) -> usize {
        self.total_bytes
    }
}

#[derive(Debug, Clone)]
pub(crate) struct Page<T> {
    pub(in crate::db) items: Vec<T>,
    pub(in crate::db) has_more: bool,
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct RecentCursorState {
    pub(in crate::db) last_seen_at: String,
    pub(in crate::db) snapshot_id: i64,
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct SearchCursorState {
    pub(in crate::db) mode_used: SearchMode,
    pub(in crate::db) score: Option<f64>,
    pub(in crate::db) last_seen_at: String,
    pub(in crate::db) snapshot_id: i64,
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct TimelineCursorState {
    pub(in crate::db) observed_at: String,
    pub(in crate::db) event_id: i64,
}