520e6f545d
Add bot_bottle/api.py with four public functions the orchestrator uses: start_headless, resume_headless, freeze, and destroy. These let a ProgrammaticBottleRunner call directly into bot_bottle instead of shelling out to the CLI; call sites in lifecycle.py stay unchanged. Key changes: - BottleSpec gains forge_env field for forge sidecar credentials - _launch_bottle returns (slug, exit_code) instead of int so start_headless can return the slug to callers - All four API functions convert Die and non-zero exits to BottleError - 27 new unit tests; existing tests updated for the new return type Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
85 lines
2.7 KiB
Python
85 lines
2.7 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
|
|
|
|
from ..backend import BottleSpec
|
|
from ..bottle_state import read_metadata
|
|
from ..log import die
|
|
from ..manifest import ManifestIndex
|
|
from ._common import PROG, USER_CWD
|
|
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(
|
|
"--headless",
|
|
action="store_true",
|
|
help=(
|
|
"non-interactive rehydrate: deliver --prompt to the agent and "
|
|
"skip the y/N preflight. For orchestrators / the freeze-rehydrate "
|
|
"loop."
|
|
),
|
|
)
|
|
parser.add_argument(
|
|
"--prompt",
|
|
default=None,
|
|
help="follow-up prompt delivered to the agent (required with --headless)",
|
|
)
|
|
parser.add_argument(
|
|
"identity",
|
|
help="bottle identity from a prior `start` (see its session-end output)",
|
|
)
|
|
args = parser.parse_args(argv)
|
|
|
|
if args.prompt and not args.headless:
|
|
die("--prompt is only valid with --headless")
|
|
if args.headless and not args.prompt:
|
|
die(
|
|
"--headless requires --prompt: "
|
|
"./cli.py resume <identity> --headless --prompt 'Address the review'"
|
|
)
|
|
|
|
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(USER_CWD)
|
|
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 USER_CWD,
|
|
identity=metadata.identity,
|
|
bottle_names=tuple(metadata.bottle_names),
|
|
)
|
|
backend_name = metadata.backend or None
|
|
_, rc = _launch_bottle(
|
|
spec,
|
|
dry_run=args.dry_run,
|
|
backend_name=backend_name,
|
|
assume_yes=args.headless,
|
|
headless_prompt_text=args.prompt or "",
|
|
)
|
|
return rc
|