8ab24726fe
Adds a Freezer ABC (backend/freeze.py) that encapsulates the
stop-commit-mark-preserved flow for all backends, following the same
pattern as BottleBackend. Each backend gets its own Freezer subclass:
DockerFreezer — docker commit
MacosContainerFreezer — container export + image rebuild; prompts
to stop if the container is running
SmolmachinesFreezer — smolvm pack create --from-vm
The base class owns write_committed_image, mark_preserved, and the
resume hint. Subclasses implement _freeze() and optionally override
_export_hint() for migration instructions.
Freezer.commit(agent, bottle) is the primary entry point for use
within a live launch context. Freezer.commit_slug(slug) is a
convenience wrapper for cmd_commit, which no longer branches on
backend names itself.
get_freezer(backend_name) is the factory, analogous to
get_bottle_backend(). CommitCancelled is raised by MacosContainerFreezer
when the user declines the stop prompt; cmd_commit catches it and
returns 0.
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""commit: freeze a running bottle's state to a resumable artifact.
|
|
|
|
Docker bottles are committed to a local Docker image. Macos-container
|
|
bottles are exported and rebuilt as a local Apple Container image.
|
|
Smolmachines bottles are packed from the running VM into a
|
|
`.smolmachine` artifact. The resulting reference is stored in
|
|
per-bottle state so the next `./cli.py resume <slug>` boots from the
|
|
snapshot instead of rebuilding from the Dockerfile.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from ..backend import enumerate_active_agents
|
|
from ..backend.freeze import CommitCancelled, get_freezer
|
|
from ..bottle_state import read_metadata
|
|
from ..log import die
|
|
from ._common import PROG
|
|
from . import tui
|
|
|
|
|
|
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 ""
|
|
|
|
try:
|
|
get_freezer(backend).commit_slug(slug)
|
|
except CommitCancelled:
|
|
return 0
|
|
return 0
|