Files
bot-bottle/claude_bottle/cli/cleanup.py
T
didericis 18d29fc23f
test / run tests/run_tests.py (pull_request) Successful in 13s
refactor(bottles): two-phase cleanup parallel to prepare/launch
cmd_cleanup used to only sweep running containers via `docker ps`,
missing stopped pipelock sidecars and orphaned networks entirely. On
my host the new version surfaced ~10 stranded networks left behind by
SIGKILLed sessions — the kind of thing the old command implied it was
handling.

New shape, symmetric with start:
- BottleCleanupPlan (abstract, in bottles/__init__.py) with `print` +
  `empty` abstract members.
- DockerBottleCleanupPlan (concrete, in bottles/docker.py) carrying
  the resolved tuples of containers and networks.
- BottlePlatform gains abstract prepare_cleanup() + cleanup(plan).
  DockerBottlePlatform implements both:
    - prepare_cleanup: docker ps -a + docker network ls, both
      filtered to ^claude-bottle-, sorted for stable output.
    - cleanup: docker rm -f containers first (they hold the network
      attachment), then docker network rm.
- cmd_cleanup is now ~25 lines: prepare → print → y/N → cleanup.
2026-05-10 23:14:54 -04:00

32 lines
770 B
Python

"""cleanup: stop and remove all orphaned claude-bottle resources
(containers + networks) left behind by previous bottles."""
from __future__ import annotations
import sys
from ..bottles import get_bottle_platform
from ..log import info
from ._common import read_tty_line
def cmd_cleanup(_argv: list[str]) -> int:
platform = get_bottle_platform()
plan = platform.prepare_cleanup()
if plan.empty:
info("no claude-bottle resources to clean up")
return 0
plan.print()
sys.stderr.write("claude-bottle: remove all of the above? [y/N] ")
sys.stderr.flush()
reply = read_tty_line()
if reply not in ("y", "Y", "yes", "YES"):
info("aborted")
return 0
platform.cleanup(plan)
info("done")
return 0