Skip to main content

Module wrap

Module wrap 

Source
Expand description

Daily wrap generator (Addendum A §9.1).

When a session ends after more than 2 hours of live use, the CLI renders a wrap: a short, honest summary of what the operator did this session. The wrap is saved under ~/.zero/state/wraps/<session_ulid>.json and printed as a single advisory line on stderr. The next session does not see the wrap — it is a closing statement, not a reminder.

§Honesty contract

  • The wrap is computed, never curated. Every number traces back to rows in the session store; no rankings, no gamification, no “streak” counters (§15’s “no cute” locks those out).
  • The wrap never editorialises. It reports: duration, command counts grouped by risk direction, a few top-N tallies, and — if present — the number of warn / alert lines the dispatcher emitted. That is it.
  • /wrap-off suppresses the current session’s wrap only. The operator cannot permanently disable it (§15).

§Separation of concerns

generate is pure: it takes a SessionRow + its stored events and returns a WrapReport. No disk I/O, no clock. This lets tests run fast and deterministically.

write_wrap is the I/O half: it takes a report + a target dir and writes <ulid>.json, returning the final path. Tests use tempfile::TempDir or a throwaway path under std::env::temp_dir() so production ~/.zero is never touched.

Structs§

CommandCount
A single entry in WrapReport::top_commands.
EventCounts
Per-kind event counts. Named fields rather than a HashMap so the JSON shape is self-documenting and readers do not have to probe for keys.
WrapReport
The wrap artifact as persisted to disk and printed as a line in the log.

Constants§

MIN_WRAP_DURATION
Minimum session length before a wrap is generated. The spec (Addendum A §9.1) says “session exit >2h”; re-declaring the threshold here lets callers avoid importing a magic number.

Functions§

generate
Pure wrap computation. No clock, no disk.
should_wrap
Determine whether this session qualifies for a wrap.
write_wrap
Persist a wrap report as <dir>/<session_ulid>.json, creating dir if needed. Returns the final path.