a21f2358c6
tracker-policy-pr / check-pr (pull_request) Successful in 16s
test / integration-docker (pull_request) Successful in 21s
lint / lint (push) Failing after 58s
test / unit (pull_request) Successful in 2m11s
test / integration-firecracker (pull_request) Successful in 3m27s
test / coverage (pull_request) Successful in 16s
test / publish-infra (pull_request) Has been skipped
_common had rotted into a junk drawer. Trim it to what actually
justifies a shared leaf module and rename for legibility:
* REPO_DIR: deleted (dead — nothing imported it).
* read_tty_line: dropped the pointless re-export; cleanup/start/init
now import it straight from bot_bottle.util.
* USER_CWD: deleted. It captured os.getcwd() at import time, but
nothing chdirs and no test patched it, so it was equivalent to a
live os.getcwd() — inlined at the six call sites.
* PROG: kept, now the sole member. It's still a leaf (both the
dispatcher and the commands it imports need it) so it can't move
into __init__ without a circular import.
_common.py -> constants.py. Full unit suite green (2243); CLI dispatch
verified.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
"""resume: re-launch a bottle by its identity.
|
|
|
|
Reads ~/.bot-bottle/state/<identity>/metadata.json to recover the
|
|
(agent_name, cwd, copy_cwd) the bottle was originally started with,
|
|
then runs the same launch core as `start` — but pinned to the
|
|
recorded identity so the new bottle picks up any per-bottle Dockerfile
|
|
override and transcript snapshot under the same state dir.
|
|
|
|
Use case: an interrupted or preserved bottle needs to be relaunched;
|
|
the operator runs
|
|
./cli.py resume <identity>
|
|
to bring up the replacement from the recorded state.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
|
|
from ...backend import BottleSpec
|
|
from ...bottle_state import read_metadata
|
|
from ...log import die
|
|
from ...manifest import ManifestIndex
|
|
from ..constants import PROG
|
|
from .start import _launch_bottle
|
|
|
|
|
|
def cmd_resume(argv: list[str]) -> int:
|
|
parser = argparse.ArgumentParser(prog=f"{PROG} resume", add_help=True)
|
|
parser.add_argument("--dry-run", action="store_true")
|
|
parser.add_argument(
|
|
"identity",
|
|
help="bottle identity from a prior `start` (see its session-end output)",
|
|
)
|
|
args = parser.parse_args(argv)
|
|
|
|
metadata = read_metadata(args.identity)
|
|
if metadata is None:
|
|
die(
|
|
f"no state recorded for identity {args.identity!r}; "
|
|
f"check ~/.bot-bottle/state/ or run `cli.py start` to create a new bottle"
|
|
)
|
|
|
|
manifest = ManifestIndex.resolve(os.getcwd())
|
|
manifest.require_agent(metadata.agent_name)
|
|
|
|
spec = BottleSpec(
|
|
manifest=manifest,
|
|
agent_name=metadata.agent_name,
|
|
copy_cwd=metadata.copy_cwd,
|
|
user_cwd=metadata.cwd or os.getcwd(),
|
|
identity=metadata.identity,
|
|
bottle_names=tuple(metadata.bottle_names),
|
|
)
|
|
backend_name = metadata.backend or None
|
|
return _launch_bottle(
|
|
spec,
|
|
dry_run=args.dry_run,
|
|
backend_name=backend_name,
|
|
)
|