Command line interface: acptui, acptui run, acptui connect, acptui agents.
main
main(argv: Sequence[str] | None = None) -> None
Entry point.
Source code in src/acptui/cli.py
| def main(argv: Sequence[str] | None = None) -> None:
"""Entry point."""
options = _parser().parse_args(argv)
try:
settings = load_settings(options.config)
except ConfigError as exc:
raise SystemExit(str(exc)) from exc
cwd: Path = (options.cwd or Path.cwd()).resolve()
if not cwd.is_dir():
raise SystemExit(f"not a directory: {cwd}")
spec: AgentSpec | None = None
resume: str | None = None
match options.command:
case "agents":
_list_agents(settings)
return
case "config":
print(options.config or config_path())
return
case "options":
spec = _resolve_run(settings, options.agent, options.args)
raise SystemExit(print_options(spec, cwd))
case "run":
args = list(options.args)
resume = options.resume
if settings.find_agent(options.agent) is not None and args[:1] == ["--resume"]:
if len(args) != 2: # noqa: PLR2004
raise SystemExit("usage: acptui run AGENT --resume SESSION_ID")
resume, args = args[1], []
if args and settings.find_agent(options.agent) is not None:
msg = (
f"{options.agent!r} is a registry agent; "
"run a program with: acptui run -- PROGRAM ARGS"
)
raise SystemExit(msg)
spec = _resolve_run(settings, options.agent, args)
case "connect":
spec = url_spec(options.url, _headers(options.header))
resume = options.resume
case _:
if settings.default_agent is not None:
spec = settings.find_agent(settings.default_agent)
if spec is None:
print(f"unknown default_agent {settings.default_agent!r}", file=sys.stderr)
from acptui.setup import build_setup, parse_option
from acptui.ui.app import AcpTui
setup = None
if spec is not None:
try:
overrides = dict(parse_option(item) for item in options.option)
except ValueError as exc:
raise SystemExit(str(exc)) from exc
setup = build_setup(
settings,
spec,
options=overrides,
additional_directories=options.add_dir,
system_prompt=options.system_prompt,
system_prompt_mode=options.system_prompt_mode,
)
AcpTui(settings, cwd, spec, resume_id=resume, setup=setup).run()
|
print_options
print_options(spec: AgentSpec, cwd: Path) -> int
Print the config options and commands a new session of the agent would have.
Source code in src/acptui/cli.py
| def print_options(spec: AgentSpec, cwd: Path) -> int:
"""Print the config options and commands a new session of the agent would have."""
import anyio
from acptui.headless import describe_options
try:
print(anyio.run(describe_options, spec, cwd))
except Exception as exc: # noqa: BLE001 - shown to the user as an error message
print(f"error: {exc}", file=sys.stderr)
return 1
return 0
|