Skip to content

desktop/src-tauri/src/commands.rs

Comment 1, line 1

desktop/src-tauri/src/commands.rs:1

//! Tauri IPC commands for queries, sources, collection, settings, and exports.

Comment 2, line 2

desktop/src-tauri/src/commands.rs:2

//! DTO rules in architecture.md transmit large token values as decimal strings

Comment 3, line 3

desktop/src-tauri/src/commands.rs:3

//! to avoid frontend float rounding; return structured code/message errors without internal cursors.

Comment 4, line 19

desktop/src-tauri/src/commands.rs:19

/// Empty source ownership selects no rows rather than every user's records.

Comment 5, line 35

desktop/src-tauri/src/commands.rs:35

/// Write application operation diagnostics without importing conversation bodies.

Comment 6, line 223

desktop/src-tauri/src/commands.rs:223

/// Native save dialog; None means the user canceled.

Comment 7, line 224

desktop/src-tauri/src/commands.rs:224

/// The backend writes the selected file path under the export interface rules.

Comment 8, line 291

desktop/src-tauri/src/commands.rs:291

/// Usage query DTO.

Comment 9, line 296

desktop/src-tauri/src/commands.rs:296

/// Requested grouping interval; parsed by the shared query builder.

Comment 10, line 352

desktop/src-tauri/src/commands.rs:352

/// Convert known tokens to decimal strings; preserve unknown as null.

Comment 11, line 404

desktop/src-tauri/src/commands.rs:404

// Use the read-only connection pool with WAL; unavailable readers fall back to the writer.

Comment 12, line 517

desktop/src-tauri/src/commands.rs:517

/// Sources include registration, latest run, compatibility counts, and missing registered files.

Comment 13, line 518

desktop/src-tauri/src/commands.rs:518

/// Agent cleanup/compaction may remove source files while history remains in application storage.

Comment 14, line 599

desktop/src-tauri/src/commands.rs:599

// Check disk files per instance and report missing counts without changing source state.

Comment 15, line 619

desktop/src-tauri/src/commands.rs:619

/// Enable/disable a source; automatic collection skips disabled instances.

Comment 16, line 643

desktop/src-tauri/src/commands.rs:643

/// Set a per-source schedule; None deletes the custom rule and restores global timing.

Comment 17, line 644

desktop/src-tauri/src/commands.rs:644

/// Intervals 15s-24h or daily/weekly local times keep a separately persisted timezone.

Comment 18, line 688

desktop/src-tauri/src/commands.rs:688

// Read back the saved schedule, including nextDue for the UI.

Comment 19, line 714

desktop/src-tauri/src/commands.rs:714

/// Request a manual refresh; merge it with an already running refresh.

Comment 20, line 715

desktop/src-tauri/src/commands.rs:715

/// Collect on a background thread so long scans do not block the GUI event loop.

Comment 21, line 716

desktop/src-tauri/src/commands.rs:716

/// The top bar polls state.refresh for progress.

Comment 22, line 736

desktop/src-tauri/src/commands.rs:736

// The initial started value is optimistic; run_refresh merges concurrent triggers.

Comment 23, line 775

desktop/src-tauri/src/commands.rs:775

// Telemetry setup owns receiver lifecycle. Saving an older settings form

Comment 24, line 776

desktop/src-tauri/src/commands.rs:776

// must not disable the receiver when changing unrelated preferences.

Comment 25, line 780

desktop/src-tauri/src/commands.rs:780

// Validate retention tiers using the core rules.

Comment 26, line 799

desktop/src-tauri/src/commands.rs:799

// Validate provider defaults after trimming and restrict cache TTL to 5/60 minutes.

Comment 27, line 824

desktop/src-tauri/src/commands.rs:824

// Online price-cache TTL must be within 1-365 days.

Comment 28, line 849

desktop/src-tauri/src/commands.rs:849

// Rebuild retained event days for a changed statistics timezone, skipping sealed days.

Comment 29, line 883

desktop/src-tauri/src/commands.rs:883

/// Latest generic quota_history snapshots; None selects all Agents.

Comment 30, line 884

desktop/src-tauri/src/commands.rs:884

/// Preserve native quota units separately from observed token usage.

Comment 31, line 913

desktop/src-tauri/src/commands.rs:913

/// Daily usage of one Agent/quota ID in its native request or quota unit.

Comment 32, line 939

desktop/src-tauri/src/commands.rs:939

/// Export presentation summary CSV or versioned record exchange JSON.

Comment 33, line 940

desktop/src-tauri/src/commands.rs:940

/// No target_dir uses application exports/; return the full written path.

Comment 34, line 941

desktop/src-tauri/src/commands.rs:941

/// Prefix CSV cells beginning =, +, -, or @ with an apostrophe to prevent formula execution.

Comment 35, line 1030

desktop/src-tauri/src/commands.rs:1030

// Filter exports by user/host, defaulting to the current user and local host.

Comment 36, line 1089

desktop/src-tauri/src/commands.rs:1089

/// Reload settings from application storage for import/backfill tooling and tests.

Comment 37, line 1100

desktop/src-tauri/src/commands.rs:1100

// Multiuser v6 and import/archive commands.

Comment 38, line 1124

desktop/src-tauri/src/commands.rs:1124

/// Create a statistics user and optionally switch to it.

Comment 39, line 1149

desktop/src-tauri/src/commands.rs:1149

/// Persist the current statistics user in settings.current_user.

Comment 40, line 1190

desktop/src-tauri/src/commands.rs:1190

/// Assign a source instance to the selected statistics user.

Comment 41, line 1208

desktop/src-tauri/src/commands.rs:1208

/// Import record/aggregate exchange data using the M1a merge rules.

Comment 42, line 1322

desktop/src-tauri/src/commands.rs:1322

/// Counts per retention tier and database bytes, including WAL.

Comment 43, line 1354

desktop/src-tauri/src/commands.rs:1354

/// Run tiered retention once using the smaller of configured days and days_before.

Comment 44, line 1386

desktop/src-tauri/src/commands.rs:1386

/// Cancellation never waits for the database mutex held by cleanup.

Comment 45, line 1455

desktop/src-tauri/src/commands.rs:1455

/// Native import-file selection dialog.

Comment 46, line 1464

desktop/src-tauri/src/commands.rs:1464

/// Preview event count and registered source files no longer on disk before clearing.

Comment 47, line 1465

desktop/src-tauri/src/commands.rs:1465

/// Cleared history cannot be recollected from absent sources; see the 2026-09-27 ZCode analysis.

Comment 48, line 1496

desktop/src-tauri/src/commands.rs:1496

/// Before clearing, create a space-checked VACUUM INTO backup and retain three copies.

Comment 49, line 1497

desktop/src-tauri/src/commands.rs:1497

/// Source cleanup/compaction can make recollection incomplete, as in the ZCode analysis;

Comment 50, line 1498

desktop/src-tauri/src/commands.rs:1498

/// the backup preserves recovery data. Skip backup only when no retained usage exists.

Comment 51, line 1556

desktop/src-tauri/src/commands.rs:1556

/// Clear usage/archive/diagnostic/cursor data and request a full collection.

Comment 52, line 1557

desktop/src-tauri/src/commands.rs:1557

/// Preserve hosts/users/settings and mark source_files new for fresh detection.

Comment 53, line 1558

desktop/src-tauri/src/commands.rs:1558

/// Create the automatic backup first; see backup_before_clear.

Comment 54, line 1559

desktop/src-tauri/src/commands.rs:1559

///

Comment 55, line 1560

desktop/src-tauri/src/commands.rs:1560

/// Run in the background without blocking the GUI event loop.

Comment 56, line 1561

desktop/src-tauri/src/commands.rs:1561

/// Send stage changes through clear-all-progress:

Comment 57, line 1562

desktop/src-tauri/src/commands.rs:1562

/// waiting for collection, backup, clearing, cleared with table counts,

Comment 58, line 1563

desktop/src-tauri/src/commands.rs:1563

/// rescan, then done. Any failure emits failed with the error and stops the job.

Comment 59, line 1564

desktop/src-tauri/src/commands.rs:1564

/// Repeated triggers return started=false while the singleton job runs.

Comment 60, line 1578

desktop/src-tauri/src/commands.rs:1578

// Reset the running flag and report failure even after a panic so controls do not stay busy.

Comment 61, line 1601

desktop/src-tauri/src/commands.rs:1601

/// Background clear/recollect job; propagate errors so callers can emit failed.

Comment 62, line 1603

desktop/src-tauri/src/commands.rs:1603

// Wait for active collection before deleting data, preventing its writer

Comment 63, line 1604

desktop/src-tauri/src/commands.rs:1604

// from repopulating tables during cleanup.

Comment 64, line 1626

desktop/src-tauri/src/commands.rs:1626

// Reset cursors request a full collection; the top bar polls refresh progress.

Comment 65, line 1636

desktop/src-tauri/src/commands.rs:1636

/// In one transaction, clear tables/reset file state and retention markers, then advance revision.

Comment 66, line 1658

desktop/src-tauri/src/commands.rs:1658

// Retain file generation and identity after deleting cursors;

Comment 67, line 1659

desktop/src-tauri/src/commands.rs:1659

// status=new still requires the next scan to perform detection again.

Comment 68, line 1699

desktop/src-tauri/src/commands.rs:1699

// Use the requested day to bound hourly aggregation.

Comment 69, line 1746

desktop/src-tauri/src/commands.rs:1746

/// Available export users/hosts, including current selections.

Comment 70, line 1789

desktop/src-tauri/src/commands.rs:1789

/// Grouped chart time series from the shared retained usage view.

Comment 71, line 1831

desktop/src-tauri/src/commands.rs:1831

/// Recent diagnostics for the settings log tab.

Comment 72, line 1871

desktop/src-tauri/src/commands.rs:1871

/// Current API reference with optional selected hours; preserve historical daily amounts.

Comment 73, line 1933

desktop/src-tauri/src/commands.rs:1933

/// Recalculate eligible costs on a background thread and record the completed operation.

Comment 74, line 1970

desktop/src-tauri/src/commands.rs:1970

/// Price snapshot source, age, and row count.

Comment 75, line 1981

desktop/src-tauri/src/commands.rs:1981

/// Import local price JSON after schema/interval checks, skipping identical snapshots.

Comment 76, line 2009

desktop/src-tauri/src/commands.rs:2009

/// Manually refresh models.dev prices; force bypasses TTL. Estimation and online

Comment 77, line 2010

desktop/src-tauri/src/commands.rs:2010

/// refresh must both be enabled; poll price_refresh_status for background results.

Comment 78, line 2029

desktop/src-tauri/src/commands.rs:2029

/// Price refresh enablement, TTL, cache age, running state, and latest result.

Comment 79, line 2072

desktop/src-tauri/src/commands.rs:2072

/// Clear-job transaction empties usage tables, marks source_files new,

Comment 80, line 2073

desktop/src-tauri/src/commands.rs:2073

/// advances revision, and adds one operation diagnostic.

Comment 81, line 2134

desktop/src-tauri/src/commands.rs:2134

// Retained daily costs still require a consistent backup after detail events expire.

Comment 82, line 2168

desktop/src-tauri/src/commands.rs:2168

// Add one operation log after old diagnostics were deleted.