Files
bot-bottle/bot_bottle/backend/smolmachines/freezer.py
T
didericis-claude 8ab24726fe
lint / lint (push) Failing after 1m38s
test / unit (pull_request) Successful in 31s
test / integration (pull_request) Successful in 15s
refactor(commit): introduce Freezer class hierarchy across backends
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.
2026-06-23 07:41:48 +00:00

26 lines
922 B
Python

"""SmolmachinesFreezer — snapshot a smolmachines bottle via smolvm pack."""
from __future__ import annotations
from .. import ActiveAgent, Bottle
from ..freeze import Freezer
from .smolvm import pack_create_from_vm
from ...bottle_state import bottle_state_dir
from ...log import info
class SmolmachinesFreezer(Freezer):
"""Freezes a smolmachines bottle via `smolvm pack create --from-vm`."""
backend_name = "smolmachines"
def _freeze(self, agent: ActiveAgent, bottle: Bottle) -> str:
output = bottle_state_dir(agent.slug) / "committed-smolmachine"
output.parent.mkdir(parents=True, exist_ok=True)
pack_create_from_vm(bottle.name, output)
artifact = output.with_name(f"{output.name}.smolmachine")
return str(artifact)
def _export_hint(self, slug: str, image_ref: str) -> None:
info(f"to export for migration: cp {image_ref} {slug}.smolmachine")