module

Noir::CLI::CacheCommand

noir cache <info|clear|purge>

Managed resource: the on-disk LLM response cache.

Constants

ACTION_ARITY = {"info" => 0, "clear" => 0, "purge" => 1}

Positionals each action accepts after the action word. purge takes <days>; the rest take none. Used to reject surplus argv rather than dropping it, which matters most for clear: an unrecognized flag used to sail straight through to a real, irreversible wipe.

ACTIONS = Noir::CLI::Catalog::CACHE_ACTIONS
MAX_PURGE_DAYS = 36500

Upper bound on noir cache purge <days>. 100 years is well past any realistic cache retention horizon; the actual reason for the cap is Crystal's Time.utc - <days>.days arithmetic, which raises ArgumentError: Invalid time: seconds out of range for values that push the resulting Time past the supported range. 100 years stays comfortably inside the Time bounds.

Class methods

clear(io : IO = STDOUT)
Source
flag?(arg : String) : Bool

A leading - marks an option — except on a bare negative number, which is a plausible (if invalid) purge <days> value. Routing -5 to the positional slot lets parse_days explain the real problem ("must be a positive integer") instead of "Unknown option: -5".

Source
format_age(t : Time) : String

Public for the same reason as format_bytes. Clamps to 0 for a future-dated t (clock skew, an NTP jump, a manually touch'd file) so the display never shows a negative "-3599s ago" that reads like a parsing bug.

Source
format_bytes(bytes : Int64) : String

Public so the unit ladder (B/KB/MB/GB) can be exercised directly, matching the testability philosophy the rest of this module follows.

The unit decision compares against the rounded value, not the raw one: just below a 1024 boundary the raw value stays under 1024 while rounding to one decimal lands on 1024.0, which printed as e.g. "1024.0 KB" instead of rolling over to "1.0 MB".

Source
orphan_note(outcome : LLM::Cache::DeleteOutcome) : String

Reclaimed temp files are reported apart from the entry count so "Removed N cache entries" keeps meaning N usable cached responses.

Source
parse_argv(argv : Array(String)) : Parsed
Source
parse_days(arg : String | Nil) : Int32 | Nil

Returns days when arg is a positive integer within the representable Time range, nil otherwise. Pulled out of purge so the validation rule can be exercised without going through the die exit path.

Source
purge(rest : Array(String), io : IO = STDOUT)
Source
run(argv : Array(String))
Source
usage_for(action : String) : String

Single-line usage for one action, used in surplus-argument errors.

Source

Nested types