50a67c04bd
test / integration-docker (pull_request) Successful in 18s
tracker-policy-pr / check-pr (pull_request) Successful in 17s
test / unit (pull_request) Failing after 41s
lint / lint (push) Failing after 57s
test / integration-firecracker (pull_request) Successful in 3m26s
test / coverage (pull_request) Has been skipped
test / publish-infra (pull_request) Has been skipped
Move the eleven per-command modules (backend, cleanup, commit, edit, info, init, list, login, resume, start, supervise) into a new bot_bottle/cli/commands/ package, leaving the dispatcher (__init__), entrypoint (__main__), and shared helpers (_common, tui) at the cli root. Makes the command surface obvious at a glance and separates handlers from the plumbing that registers them. Updated the dispatcher's COMMANDS imports to .commands.*, bumped the moved files' relative-import depths (.._common, .. import tui, sibling .start unchanged), and repointed test references to bot_bottle.cli.commands.*. Full unit suite green (2243); CLI dispatch verified via `python -m bot_bottle.cli --help`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""list: list available agents or active bottles."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
from ...backend import enumerate_active_agents
|
|
from ...manifest import ManifestIndex
|
|
from .._common import PROG, USER_CWD
|
|
|
|
_ANSI_COLOR_CODES: dict[str, str] = {
|
|
"red": "\033[91m",
|
|
"green": "\033[92m",
|
|
"yellow": "\033[93m",
|
|
"blue": "\033[94m",
|
|
"magenta": "\033[95m",
|
|
}
|
|
_ANSI_RESET = "\033[0m"
|
|
|
|
|
|
def _ansi_label(text: str, color: str) -> str:
|
|
if not color:
|
|
return text
|
|
if not sys.stdout.isatty():
|
|
return text
|
|
term = os.environ.get("TERM", "")
|
|
if term in ("dumb", ""):
|
|
return text
|
|
code = _ANSI_COLOR_CODES.get(color)
|
|
if not code:
|
|
return text
|
|
return f"{code}{text}{_ANSI_RESET}"
|
|
|
|
|
|
def cmd_list(argv: list[str]) -> int:
|
|
parser = argparse.ArgumentParser(prog=f"{PROG} list", add_help=True)
|
|
parser.add_argument("scope", choices=["available", "active"])
|
|
args = parser.parse_args(argv)
|
|
|
|
if args.scope == "available":
|
|
manifest = ManifestIndex.resolve(USER_CWD)
|
|
for name in manifest.all_agent_names:
|
|
print(name)
|
|
return 0
|
|
|
|
# `active` enumerates every backend (docker, firecracker,
|
|
# macos-container) so non-docker bottles aren't hidden behind
|
|
# the env var.
|
|
active = enumerate_active_agents()
|
|
if not active:
|
|
print("no active bot-bottle bottles", file=sys.stderr)
|
|
return 0
|
|
# One line per bottle: `<backend>\t<slug>\t<label>\t<services>`.
|
|
# Tab-separated keeps the format stable for shell pipelines.
|
|
for b in active:
|
|
services = ",".join(b.services) if b.services else "-"
|
|
display_name = f"{b.label} ({b.agent_name})" if b.label else b.agent_name
|
|
colored_name = _ansi_label(display_name, b.color)
|
|
print(f"{b.backend_name}\t{b.slug}\t{colored_name}\t{services}")
|
|
return 0
|