|
| 1 | +""" |
| 2 | +Paths command group for PraisonAI CLI. |
| 3 | +
|
| 4 | +Provides path inspection: |
| 5 | +- paths show: Display all resolved storage paths |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +import typer |
| 12 | + |
| 13 | +from ..output.console import get_output_controller |
| 14 | + |
| 15 | +app = typer.Typer(help="Storage path inspection and migration") |
| 16 | + |
| 17 | + |
| 18 | +@app.command("show") |
| 19 | +def paths_show( |
| 20 | + json_output: bool = typer.Option( |
| 21 | + False, |
| 22 | + "--json", |
| 23 | + help="Output in JSON format", |
| 24 | + ), |
| 25 | +): |
| 26 | + """ |
| 27 | + Show all resolved storage paths. |
| 28 | +
|
| 29 | + Displays global, project-local, and environment-overridden paths. |
| 30 | + """ |
| 31 | + output = get_output_controller() |
| 32 | + |
| 33 | + try: |
| 34 | + from praisonaiagents.paths import ( |
| 35 | + ENV_VAR, |
| 36 | + DEFAULT_DIR_NAME, |
| 37 | + LEGACY_DIR_NAME, |
| 38 | + get_data_dir, |
| 39 | + get_all_paths, |
| 40 | + get_project_data_dir, |
| 41 | + ) |
| 42 | + except ImportError: |
| 43 | + output.print_error("praisonaiagents package not installed") |
| 44 | + raise typer.Exit(1) |
| 45 | + |
| 46 | + env_home = os.environ.get(ENV_VAR) |
| 47 | + global_dir = get_data_dir() |
| 48 | + project_dir = get_project_data_dir() |
| 49 | + legacy_dir = Path.home() / LEGACY_DIR_NAME |
| 50 | + all_paths = get_all_paths() |
| 51 | + |
| 52 | + if json_output or (hasattr(output, "is_json_mode") and output.is_json_mode): |
| 53 | + data = { |
| 54 | + "env_var": ENV_VAR, |
| 55 | + "env_value": env_home, |
| 56 | + "global_dir": str(global_dir), |
| 57 | + "project_dir": str(project_dir), |
| 58 | + "legacy_dir_exists": legacy_dir.exists(), |
| 59 | + "paths": {k: str(v) for k, v in all_paths.items()}, |
| 60 | + } |
| 61 | + output.print_json(data) |
| 62 | + return |
| 63 | + |
| 64 | + # Text output using Rich console directly |
| 65 | + from rich.console import Console |
| 66 | + from rich.table import Table |
| 67 | + |
| 68 | + console = Console() |
| 69 | + console.print("\n[bold cyan]PraisonAI Storage Paths[/bold cyan]\n") |
| 70 | + |
| 71 | + # Environment override |
| 72 | + if env_home: |
| 73 | + console.print(f" [green]✓[/green] {ENV_VAR} = {env_home}") |
| 74 | + else: |
| 75 | + console.print(f" [dim]{ENV_VAR} is not set (using defaults)[/dim]") |
| 76 | + |
| 77 | + console.print() |
| 78 | + |
| 79 | + # Table of paths |
| 80 | + table = Table(title="Resolved Paths", show_lines=False) |
| 81 | + table.add_column("Category", style="cyan") |
| 82 | + table.add_column("Path", style="white") |
| 83 | + table.add_column("Exists", justify="center") |
| 84 | + |
| 85 | + table.add_row( |
| 86 | + "Global data dir", |
| 87 | + str(global_dir), |
| 88 | + "✅" if global_dir.exists() else "—", |
| 89 | + ) |
| 90 | + table.add_row( |
| 91 | + "Project data dir", |
| 92 | + str(project_dir), |
| 93 | + "✅" if project_dir.exists() else "—", |
| 94 | + ) |
| 95 | + |
| 96 | + for name, path_val in sorted(all_paths.items()): |
| 97 | + p = Path(str(path_val)) |
| 98 | + table.add_row(name, str(p), "✅" if p.exists() else "—") |
| 99 | + |
| 100 | + console.print(table) |
| 101 | + |
| 102 | + # Legacy warning |
| 103 | + if legacy_dir.exists(): |
| 104 | + console.print( |
| 105 | + f"\n [yellow]⚠ Legacy directory {legacy_dir} exists.[/yellow]" |
| 106 | + ) |
0 commit comments