feat(cli): add commit command to snapshot running bottle state
Adds `./cli.py commit [<slug>]` which runs `docker commit` on the active agent container and stores the resulting image tag in per-bottle state. The next `./cli.py resume <slug>` automatically boots from the committed snapshot instead of rebuilding from the Dockerfile, preserving all in-container state across restarts and migrations. - bottle_state: add write_committed_image / read_committed_image helpers - docker/util: add commit_container wrapper around `docker commit` - docker/launch: check for a committed image before the Dockerfile build step; fall back to normal build if the image is absent from the daemon - cli/commit: new command with interactive slug picker; errors clearly on non-Docker backends - 50 new unit tests covering all paths Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Main CLI dispatcher.
|
||||
|
||||
Commands: cleanup, edit, info, init, list, resume, start, supervise
|
||||
Commands: cleanup, commit, edit, info, init, list, resume, start, supervise
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,6 +12,7 @@ from ..manifest import ManifestError
|
||||
from ._common import PROG
|
||||
from . import list as _list_mod
|
||||
from .cleanup import cmd_cleanup
|
||||
from .commit import cmd_commit
|
||||
from .edit import cmd_edit
|
||||
from .info import cmd_info
|
||||
from .init import cmd_init
|
||||
@@ -23,6 +24,7 @@ cmd_list = _list_mod.cmd_list
|
||||
|
||||
COMMANDS = {
|
||||
"cleanup": cmd_cleanup,
|
||||
"commit": cmd_commit,
|
||||
"edit": cmd_edit,
|
||||
"info": cmd_info,
|
||||
"init": cmd_init,
|
||||
@@ -37,6 +39,7 @@ def usage() -> None:
|
||||
sys.stderr.write(f"usage: {PROG} <command> [args...]\n\n")
|
||||
sys.stderr.write("Commands:\n")
|
||||
sys.stderr.write(" cleanup stop and remove all active bot-bottle containers\n")
|
||||
sys.stderr.write(" commit snapshot a running bottle's container state to a Docker image\n")
|
||||
sys.stderr.write(" edit open an agent in vim for editing\n")
|
||||
sys.stderr.write(" info print env, skills, and prompt details for a named agent\n")
|
||||
sys.stderr.write(" init interactively create a new agent and add it to bot-bottle.json\n")
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
"""commit: freeze a running Docker bottle's container state to a local image.
|
||||
|
||||
Runs `docker commit <container> <image-tag>` on the active agent
|
||||
container and stores the image tag in per-bottle state so the next
|
||||
`./cli.py resume <slug>` boots from that snapshot instead of
|
||||
rebuilding from the Dockerfile.
|
||||
|
||||
Only the Docker backend is supported. Smolmachines VMs have no
|
||||
container-level commit API in the current smolvm CLI surface.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
from ..backend import enumerate_active_agents
|
||||
from ..backend.docker.util import commit_container
|
||||
from ..bottle_state import mark_preserved, read_metadata, write_committed_image
|
||||
from ..log import die, info
|
||||
from ._common import PROG
|
||||
from . import tui
|
||||
|
||||
|
||||
_COMMITTED_IMAGE_PREFIX = "bot-bottle-committed-"
|
||||
_DOCKER_BACKENDS = {"docker", ""}
|
||||
|
||||
|
||||
def _committed_image_tag(slug: str) -> str:
|
||||
return f"{_COMMITTED_IMAGE_PREFIX}{slug}:latest"
|
||||
|
||||
|
||||
def _agent_container_name(slug: str) -> str:
|
||||
return f"bot-bottle-{slug}"
|
||||
|
||||
|
||||
def cmd_commit(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(prog=f"{PROG} commit", add_help=True)
|
||||
parser.add_argument(
|
||||
"slug",
|
||||
nargs="?",
|
||||
default=None,
|
||||
help=(
|
||||
"bottle slug from `cli.py list active` "
|
||||
"(omit to pick interactively)"
|
||||
),
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
slug = args.slug
|
||||
if slug is None:
|
||||
active = enumerate_active_agents()
|
||||
if not active:
|
||||
die("no active bottles; start one with `./cli.py start`")
|
||||
choices = [a.slug for a in active]
|
||||
slug = tui.filter_select(choices, title="Select bottle to commit")
|
||||
if slug is None:
|
||||
return 0
|
||||
|
||||
metadata = read_metadata(slug)
|
||||
backend = metadata.backend if metadata else ""
|
||||
if backend not in _DOCKER_BACKENDS:
|
||||
die(
|
||||
f"commit is only supported for the docker backend; "
|
||||
f"bottle {slug!r} uses {backend!r}"
|
||||
)
|
||||
|
||||
container = _agent_container_name(slug)
|
||||
image_tag = _committed_image_tag(slug)
|
||||
|
||||
commit_container(container, image_tag)
|
||||
write_committed_image(slug, image_tag)
|
||||
mark_preserved(slug)
|
||||
info(f"to resume from this snapshot: ./cli.py resume {slug}")
|
||||
info(f"to export for migration: docker save {image_tag} -o {slug}.tar")
|
||||
return 0
|
||||
Reference in New Issue
Block a user