Skip to main content

Module key_activity

Module key_activity 

Source
Expand description

Per-host SSH connection activity log.

Records (alias, timestamp) events each time purple opens an SSH session, exec command or tunnel for a host. Persisted to ~/.purple/key_activity.json. The Keys tab reads this log to render per-key sparklines, last-touch hints and “hosts touched in last 30d” metrics by pivoting events through SshKeyInfo::linked_hosts at render time. We log per alias rather than per key fingerprint so we never have to attribute connects to a specific key file; the alias mapping already encodes the link.

Structs§

ConnectEvent
KeyActivityLog

Constants§

DEMO_NOW_SECS
Fixed reference timestamp used by demo data seeding and by render-time helpers that need a deterministic “now”. Picked at the cutover date so visual goldens render deterministically; the date itself only matters in concert with the timestamps demo.rs seeds.

Functions§

format_created
Format a file mtime as YYYY-MM-DD (<age> ago) for the Created label. Uses humanize_last_use for the age tail so the rhythm matches the Last touch tile.
humanize_last_use
Format the gap between now and ts as a compact Nu ago label (N count, u unit). Mirrors the rhythm Linear / GitHub use: just now, 14m ago, 3h ago, 2d ago, 3w ago, 2mo ago, 1y ago.
now_for_render
Demo-aware “now” for render-time callers. Returns the frozen DEMO_NOW_SECS when the process is in demo mode (so visual goldens land byte-stable), otherwise the wall clock. Record-time callers must use now_secs() directly and pass the result through; mixing the two would let a render-time freeze leak into persisted events.
now_secs
Current wall-clock epoch seconds. Demo-aware rendering uses now_for_render() instead, which substitutes DEMO_NOW_SECS so sparkline rendering stays byte-stable across golden runs.
record_and_flush
Field-disjoint helper: record + flush the activity log without holding &mut App. Lets the event loop record a connect while another sub-state (FileBrowser, TunnelState) still holds a mutable borrow on App, where the App::record_key_use method would be rejected by the borrow checker. Caller passes now; production call sites pass now_secs().