banger/internal/cli
Thales Maciel 4d8dca6b72
image: add banger image cache prune for OCI cache cleanup
OCI layer blobs accumulate forever — every pull writes layers to
~/.cache/banger/oci/blobs/sha256/<hex> via go-containerregistry's
filesystem cache, and nothing ever evicts them. The cache is purely
a re-pull-avoidance (every flattened image is independent of the
blobs that sourced it), so it's a perfect candidate for an opt-in
operator-driven prune.

New surface:
  * api: ImageCachePruneParams{DryRun}, ImageCachePruneResult
    {BytesFreed, BlobsFreed, DryRun, CacheDir}.
  * daemon: ImageService.PruneOCICache walks layout.OCICacheDir for
    a (bytes, blobs) tally, then — outside dry-run — atomically
    renames the cache aside, recreates it empty, and rm -rf's the
    aside dir. The rename-then-rm avoids leaving the cache in a
    half-removed state if a pull starts mid-prune (the in-flight
    pull's open files survive the rename via standard Linux
    semantics; it just sees a fresh empty cache afterwards). Missing
    cache dir is treated as zero — fresh installs that have never
    pulled an OCI image don't error.
  * dispatch: image.cache.prune RPC (paramHandler-wrapped, mirroring
    every other image RPC). Documented-methods test list updated.
  * cli: `banger image cache` group with a `prune` subcommand
    (--dry-run flag). Output is a single line: "freed 1.2 GiB
    across 47 blob(s) in /var/cache/banger/oci" or "would free …".
    formatBytes helper for the size pretty-print.

docs/oci-import.md: replaced the "Tech debt: cache eviction" bullet
with a "Cache lifecycle" section describing the new command and
the in-flight-pull caveat.

Tests: PruneOCICache covers the happy path (real prune empties the
cache, recreates an empty dir, doesn't leak the .pruning- aside),
the dry-run path (returns size, leaves blobs intact), and the
fresh-install path (cache dir absent → zero result, no error).
Smoke at JOBS=4 still green; live exercise against an empty cache
on a system install prints the expected zero summary.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 16:32:57 -03:00
..
style cli: maturity polish — color, error translation, tabwriter consistency 2026-04-26 22:27:07 -03:00
aliases_test.go remove vm session feature 2026-04-20 12:47:58 -03:00
banger.go cli: rewrite help text for AI-driven discovery 2026-04-26 15:02:08 -03:00
bangerd.go daemon: split owner daemon from root helper 2026-04-26 12:43:17 -03:00
cli_test.go cli: maturity polish — color, error translation, tabwriter consistency 2026-04-26 22:27:07 -03:00
commands_daemon.go daemon: split owner daemon from root helper 2026-04-26 12:43:17 -03:00
commands_image.go image: add banger image cache prune for OCI cache cleanup 2026-04-28 16:32:57 -03:00
commands_internal.go cli + daemon: move test seams off package globals onto injected structs 2026-04-19 19:03:55 -03:00
commands_kernel.go cli: rewrite help text for AI-driven discovery 2026-04-26 15:02:08 -03:00
commands_ssh_config.go cli: rewrite help text for AI-driven discovery 2026-04-26 15:02:08 -03:00
commands_system.go firecracker: adopt firecracker-jailer for VM launch (Phase B) 2026-04-28 14:38:07 -03:00
commands_vm.go feat(vm): add vm exec command with workspace dirty detection 2026-04-26 23:53:45 -03:00
completion.go daemon: split owner daemon from root helper 2026-04-26 12:43:17 -03:00
completion_test.go remove vm session feature 2026-04-20 12:47:58 -03:00
daemon_lifecycle.go cli: wait for the daemon socket to answer ping after install/restart 2026-04-26 21:22:31 -03:00
daemon_lifecycle_test.go firecracker: adopt firecracker-jailer for VM launch (Phase B) 2026-04-28 14:38:07 -03:00
deps.go seams: move the last four package globals onto instance fields 2026-04-22 12:07:14 -03:00
errors.go cli: maturity polish — color, error translation, tabwriter consistency 2026-04-26 22:27:07 -03:00
errors_test.go cli: maturity polish — color, error translation, tabwriter consistency 2026-04-26 22:27:07 -03:00
formatters_test.go remove vm session feature 2026-04-20 12:47:58 -03:00
known_hosts.go daemon: split owner daemon from root helper 2026-04-26 12:43:17 -03:00
make_bundle_test.go banger internal make-bundle: build image bundles from flat rootfs tars 2026-04-17 15:17:50 -03:00
printers.go feat(vm): add vm exec command with workspace dirty detection 2026-04-26 23:53:45 -03:00
prune_test.go cli + daemon: move test seams off package globals onto injected structs 2026-04-19 19:03:55 -03:00
ssh.go smoke: five more scenarios + fix exit-code propagation bug the new ones caught 2026-04-22 19:37:07 -03:00
vm_create.go cli: maturity polish — color, error translation, tabwriter consistency 2026-04-26 22:27:07 -03:00
vm_exec.go feat(vm): add vm exec command with workspace dirty detection 2026-04-26 23:53:45 -03:00
vm_run.go daemon: split owner daemon from root helper 2026-04-26 12:43:17 -03:00
vm_spec_test.go vm defaults: host-aware sizing + spec line on spawn + doctor check 2026-04-19 13:06:51 -03:00
workspace_preview.go noteUntrackedSkipped: fix subdir underreport + be best-effort everywhere 2026-04-22 12:42:33 -03:00
workspace_preview_test.go noteUntrackedSkipped: fix subdir underreport + be best-effort everywhere 2026-04-22 12:42:33 -03:00