Revert "add cli ux"

This reverts commit 1681e29fa8.
This commit is contained in:
Musa 2026-01-13 11:00:41 -08:00
parent 2d0dcce365
commit 67a52fbcd7
5 changed files with 21 additions and 865 deletions

View file

@ -1,4 +1,4 @@
import rich_click as click
import click
import os
import sys
import subprocess
@ -6,74 +6,6 @@ import multiprocessing
import importlib.metadata
import json
from planoai import targets
# Brand color - Plano purple
PLANO_COLOR = "#969FF4"
# Configure rich-click styling
click.rich_click.USE_RICH_MARKUP = True
click.rich_click.USE_MARKDOWN = False
click.rich_click.SHOW_ARGUMENTS = True
click.rich_click.GROUP_ARGUMENTS_OPTIONS = True
click.rich_click.STYLE_ERRORS_SUGGESTION = "dim italic"
click.rich_click.ERRORS_SUGGESTION = (
"Try running the '--help' flag for more information."
)
click.rich_click.ERRORS_EPILOGUE = ""
# Custom colors matching Plano brand
click.rich_click.STYLE_OPTION = f"dim {PLANO_COLOR}"
click.rich_click.STYLE_ARGUMENT = f"dim {PLANO_COLOR}"
click.rich_click.STYLE_COMMAND = f"bold {PLANO_COLOR}"
click.rich_click.STYLE_SWITCH = "bold green"
click.rich_click.STYLE_METAVAR = "bold yellow"
click.rich_click.STYLE_USAGE = "bold"
click.rich_click.STYLE_USAGE_COMMAND = f"bold dim {PLANO_COLOR}"
click.rich_click.STYLE_HELPTEXT_FIRST_LINE = f"white italic"
click.rich_click.STYLE_HELPTEXT = ""
click.rich_click.STYLE_HEADER_TEXT = "bold"
click.rich_click.STYLE_FOOTER_TEXT = "dim"
click.rich_click.STYLE_OPTIONS_PANEL_BORDER = "dim"
click.rich_click.ALIGN_OPTIONS_PANEL = "left"
click.rich_click.MAX_WIDTH = 100
# Option groups for better organization
click.rich_click.OPTION_GROUPS = {
"planoai up": [
{
"name": "Configuration",
"options": ["--path", "file"],
},
{
"name": "Runtime Options",
"options": ["--foreground"],
},
],
"planoai logs": [
{
"name": "Log Options",
"options": ["--debug", "--follow"],
},
],
}
# Command groups for main help
click.rich_click.COMMAND_GROUPS = {
"planoai": [
{
"name": "Gateway Commands",
"commands": ["up", "down", "build", "logs"],
},
{
"name": "Agent Commands",
"commands": ["cli-agent"],
},
{
"name": "Utilities",
"commands": ["validate", "generate-prompt-targets"],
},
],
}
from planoai.docker_cli import (
docker_validate_plano_schema,
stream_gateway_logs,
@ -102,22 +34,19 @@ from planoai.consts import (
log = getLogger(__name__)
# ref https://patorjk.com/software/taag/#p=display&f=Doom&t=Plano&x=none&v=4&h=4&w=80&we=false
LOGO = f"""[bold {PLANO_COLOR}]
______ _
| ___ \\ |
| |_/ / | __ _ _ __ ___
| __/| |/ _` | '_ \\ / _ \\
| | | | (_| | | | | (_) |
\\_| |_|\\__,_|_| |_|\\___/
[/bold {PLANO_COLOR}]"""
logo = r"""
______ _
| ___ \ |
| |_/ / | __ _ _ __ ___
| __/| |/ _` | '_ \ / _ \
| | | | (_| | | | | (_) |
\_| |_|\__,_|_| |_|\___/
"""
# Command to build plano Docker images
ARCHGW_DOCKERFILE = "./Dockerfile"
# PyPI package name for version checking
PYPI_PACKAGE_NAME = "planoai"
PYPI_URL = f"https://pypi.org/pypi/{PYPI_PACKAGE_NAME}/json"
def get_version():
try:
@ -134,110 +63,19 @@ def get_version():
return "version not found"
def get_latest_version(timeout: float = 2.0) -> str | None:
"""Fetch the latest version from PyPI.
Args:
timeout: Request timeout in seconds
Returns:
Latest version string or None if fetch failed
"""
import requests
try:
response = requests.get(PYPI_URL, timeout=timeout)
if response.status_code == 200:
data = response.json()
return data.get("info", {}).get("version")
except (requests.RequestException, ValueError):
# Network error or invalid JSON - fail silently
pass
return None
def parse_version(version_str: str) -> tuple:
"""Parse version string into comparable tuple.
Handles versions like "0.4.1", "1.0.0", "0.4.1a1"
"""
import re
# Remove any pre-release suffixes for comparison
clean_version = re.split(r"[a-zA-Z]", version_str)[0]
parts = clean_version.split(".")
return tuple(int(p) for p in parts if p.isdigit())
def check_version_status(current: str, latest: str | None) -> dict:
"""Compare current version with latest and return status.
Returns:
dict with keys: is_outdated, current, latest, message
"""
if latest is None:
return {
"is_outdated": False,
"current": current,
"latest": None,
"message": None,
}
try:
current_tuple = parse_version(current)
latest_tuple = parse_version(latest)
is_outdated = current_tuple < latest_tuple
return {
"is_outdated": is_outdated,
"current": current,
"latest": latest,
"message": f"Update available: {latest}" if is_outdated else None,
}
except (ValueError, TypeError):
# Version parsing failed
return {
"is_outdated": False,
"current": current,
"latest": latest,
"message": None,
}
@click.group(invoke_without_command=True)
@click.option("--version", is_flag=True, help="Show the Plano CLI version and exit.")
@click.option("--version", is_flag=True, help="Show the plano cli version and exit.")
@click.pass_context
def main(ctx, version):
from rich.console import Console
console = Console()
if version:
current_version = get_version()
console.print(
f"[bold {PLANO_COLOR}]plano[/bold {PLANO_COLOR}] version [cyan]{current_version}[/cyan]"
)
# Check for updates (skip if PLANO_SKIP_VERSION_CHECK is set)
if not os.environ.get("PLANO_SKIP_VERSION_CHECK"):
latest_version = get_latest_version()
status = check_version_status(current_version, latest_version)
if status["is_outdated"]:
console.print(
f"\n[yellow]⚠ Update available:[/yellow] [bold]{status['latest']}[/bold]"
)
console.print(
f"[dim]Run: uv pip install --upgrade {PYPI_PACKAGE_NAME}[/dim]"
)
elif latest_version:
console.print(f"[dim]✓ You're up to date[/dim]")
click.echo(f"plano cli version: {get_version()}")
ctx.exit()
log.info(f"Starting plano cli version: {get_version()}")
if ctx.invoked_subcommand is None:
console.print(LOGO)
console.print("[dim]The Delivery Infrastructure for Agentic Apps[/dim]\n")
click.echo("""Arch (The Intelligent Prompt Gateway) CLI""")
click.echo(logo)
click.echo(ctx.get_help())
@ -283,16 +121,16 @@ def build():
@click.command()
@click.argument("file", required=False) # Optional file argument
@click.option(
"--path", default=".", help="Path to the directory containing config.yaml"
"--path", default=".", help="Path to the directory containing arch_config.yaml"
)
@click.option(
"--foreground",
default=False,
help="Run Plano in the foreground. Default is False",
help="Run Arch in the foreground. Default is False",
is_flag=True,
)
def up(file, path, foreground):
"""Starts Plano."""
"""Starts Arch."""
# Use the utility function to find config file
arch_config_file = find_config_file(path, file)
@ -360,7 +198,7 @@ def up(file, path, foreground):
@click.command()
def down():
"""Stops Plano."""
"""Stops Arch."""
stop_docker_container()
@ -432,7 +270,7 @@ def logs(debug, follow):
help="Additional settings as JSON string for the CLI agent.",
)
def cli_agent(type, file, path, settings):
"""Start a CLI agent connected to Plano. Currently only 'claude' is supported.
"""Start a CLI agent connected to Arch.
CLI_AGENT: The type of CLI agent to start (currently only 'claude' is supported)
"""
@ -460,258 +298,12 @@ def cli_agent(type, file, path, settings):
sys.exit(1)
def validate_config_file(config_path: str) -> dict:
"""Validate a Plano config file and return validation results.
Args:
config_path: Path to the config file
Returns:
dict with keys: valid, errors, warnings, config, summary
"""
import yaml
from jsonschema import validate as json_validate, ValidationError
result = {
"valid": True,
"errors": [],
"warnings": [],
"config": None,
"summary": {
"model_providers": [],
"listeners": [],
"env_vars_required": [],
},
}
# Check file exists
if not os.path.exists(config_path):
result["valid"] = False
result["errors"].append(f"Config file not found: {config_path}")
return result
# Try to load YAML
try:
with open(config_path, "r") as f:
config = yaml.safe_load(f)
result["config"] = config
except yaml.YAMLError as e:
result["valid"] = False
result["errors"].append(f"Invalid YAML syntax: {e}")
return result
# Find schema file
schema_path = find_repo_root()
if schema_path:
schema_file = os.path.join(schema_path, "config", "arch_config_schema.yaml")
else:
# Fallback - try relative paths
schema_file = None
for possible_path in [
"../config/arch_config_schema.yaml",
"config/arch_config_schema.yaml",
]:
if os.path.exists(possible_path):
schema_file = possible_path
break
# Schema validation
if schema_file and os.path.exists(schema_file):
try:
with open(schema_file, "r") as f:
schema = yaml.safe_load(f)
json_validate(config, schema)
except ValidationError as e:
result["valid"] = False
result["errors"].append(f"Schema validation failed: {e.message}")
except Exception as e:
result["warnings"].append(f"Could not validate schema: {e}")
else:
result["warnings"].append("Schema file not found, skipping schema validation")
# Extract model providers
model_providers = config.get("model_providers", config.get("llm_providers", []))
for provider in model_providers:
model = provider.get("model", "unknown")
is_default = provider.get("default", False)
result["summary"]["model_providers"].append(
{
"model": model,
"default": is_default,
"name": provider.get("name", model),
}
)
# Check for env vars
access_key = provider.get("access_key", "")
if access_key.startswith("$"):
env_var = access_key[1:]
result["summary"]["env_vars_required"].append(env_var)
# Extract listeners
listeners = config.get("listeners", {})
if isinstance(listeners, dict):
# Legacy format
if "egress_traffic" in listeners:
result["summary"]["listeners"].append(
{
"name": "egress_traffic (LLM Gateway)",
"port": listeners["egress_traffic"].get("port", 12000),
"type": "model",
}
)
if "ingress_traffic" in listeners:
result["summary"]["listeners"].append(
{
"name": "ingress_traffic (Prompt Gateway)",
"port": listeners["ingress_traffic"].get("port", 10000),
"type": "prompt",
}
)
elif isinstance(listeners, list):
for listener in listeners:
result["summary"]["listeners"].append(
{
"name": listener.get("name", "unnamed"),
"port": listener.get("port", "unknown"),
"type": listener.get("type", "unknown"),
}
)
# Remove duplicates from env vars first
result["summary"]["env_vars_required"] = list(
set(result["summary"]["env_vars_required"])
)
# Check environment variables (after deduplication)
for env_var in result["summary"]["env_vars_required"]:
if not os.environ.get(env_var):
result["warnings"].append(f"Environment variable ${env_var} is not set")
return result
@click.command()
@click.argument("config_file", required=False, type=click.Path())
@click.option(
"--path", "-p", default=".", help="Path to directory containing config.yaml"
)
@click.option("--quiet", "-q", is_flag=True, help="Only show errors, no summary")
def validate(config_file, path, quiet):
"""Validate a Plano configuration file.
If no CONFIG_FILE is provided, looks for config.yaml in the current directory
or the directory specified by --path.
"""
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
console = Console()
# Determine config file path
if config_file:
config_path = os.path.abspath(config_file)
else:
# Look for config.yaml in path
config_path = os.path.join(os.path.abspath(path), "config.yaml")
if not os.path.exists(config_path):
# Try arch_config.yaml as fallback
config_path = os.path.join(os.path.abspath(path), "arch_config.yaml")
# Show what we're validating
console.print(f"\n[bold]Validating:[/bold] [dim]{config_path}[/dim]\n")
# Run validation
result = validate_config_file(config_path)
# Display results
if result["valid"]:
console.print(
f"[bold green]✓[/bold green] [green]Configuration is valid[/green]\n"
)
else:
console.print(f"[bold red]✗[/bold red] [red]Configuration is invalid[/red]\n")
# Show errors
if result["errors"]:
for error in result["errors"]:
console.print(f" [red]✗ {error}[/red]")
console.print()
# Show warnings
if result["warnings"]:
for warning in result["warnings"]:
console.print(f" [yellow]⚠ {warning}[/yellow]")
console.print()
# Show summary (unless quiet mode)
if not quiet and result["config"]:
summary = result["summary"]
# Model Providers table
if summary["model_providers"]:
table = Table(
title=f"[bold {PLANO_COLOR}]Model Providers[/bold {PLANO_COLOR}]",
border_style="dim",
show_header=True,
header_style=f"bold {PLANO_COLOR}",
)
table.add_column("Model", style="cyan")
table.add_column("Default", style="green", justify="center")
for provider in summary["model_providers"]:
default_marker = "" if provider["default"] else ""
table.add_row(provider["model"], default_marker)
console.print(table)
console.print()
# Listeners table
if summary["listeners"]:
table = Table(
title=f"[bold {PLANO_COLOR}]Listeners[/bold {PLANO_COLOR}]",
border_style="dim",
show_header=True,
header_style=f"bold {PLANO_COLOR}",
)
table.add_column("Name", style="cyan")
table.add_column("Type", style="magenta")
table.add_column("Port", style="yellow", justify="right")
for listener in summary["listeners"]:
table.add_row(listener["name"], listener["type"], str(listener["port"]))
console.print(table)
console.print()
# Environment variables
if summary["env_vars_required"]:
env_status = []
for env_var in sorted(summary["env_vars_required"]):
is_set = os.environ.get(env_var) is not None
status = f"[green]✓[/green]" if is_set else f"[yellow]○[/yellow]"
env_status.append(f" {status} [dim]${env_var}[/dim]")
console.print(
f"[bold {PLANO_COLOR}]Environment Variables[/bold {PLANO_COLOR}]"
)
for line in env_status:
console.print(line)
console.print()
# Exit with appropriate code
if not result["valid"]:
sys.exit(1)
main.add_command(up)
main.add_command(down)
main.add_command(build)
main.add_command(logs)
main.add_command(cli_agent)
main.add_command(generate_prompt_targets)
main.add_command(validate)
if __name__ == "__main__":
main()