src/cli/cache.ts — vx cache prune
Purpose
Section titled “Purpose”Implements vx cache prune plus the shared duration / size parsers
exported for tests. Drives Cache.prune({...}) from
src/cache/cache.ts with a workspace-resolved cache directory.
Public surface
Section titled “Public surface”export async function cacheCmd(args: readonly string[]): Promise<number>
interface PruneArgs { olderThanMs?: number maxBytes?: number error?: string}
export function parsePruneArgs(args: readonly string[]): PruneArgsexport function parseDuration(input: string): number | nullexport function parseSize(input: string): number | nullSubcommand surface
Section titled “Subcommand surface”vx cache prune --older-than <duration>vx cache prune --max-size <size>vx cache prune --older-than 7d --max-size 500M # bothAt least one of --older-than / --max-size is required. Both may
be combined: age-based eviction first, then LRU eviction if the total
is still over the size cap.
Parsers
Section titled “Parsers”parseDuration(input): number | null
Section titled “parseDuration(input): number | null”/^(\d+)([smhd])$/Returns ms. s (× 1000), m (× 60_000), h (× 3_600_000), d
(× 86_400_000). null on parse fail (caller surfaces
invalid duration).
parseSize(input): number | null
Section titled “parseSize(input): number | null”/^(\d+)([KMGT])?B?$/iReturns bytes. Multipliers are powers of 1024 (K, M, G, T).
Optional trailing B is allowed. null on parse fail.
What this does NOT do
Section titled “What this does NOT do”- Doesn’t honor
vx.workspace.tscacheDir. Hard-codes<workspaceRoot>/.vx/cache. A follow-up should route throughworkspace/workspace.ts:resolveCacheDirto matchvx run. - Doesn’t list candidates.
--dry-runsemantics aren’t wired up;Cache.prunedoes the eviction directly.
tests/cli.test.ts covers:
parseDurationunits + parse failures.parseSizeunits + parse failures.parsePruneArgsrequires at least one policy.vx cache prune --older-than 0sno-ops cleanly.
Real eviction logic is tested in tests/cache.test.ts against
Cache.prune.