Task 0.5 of clean-analyst-bootstrap. Greenfield rewrite — no fallback, no aliases. Existing dev environments lose their cached PAT and must re-authenticate. Env var renames (hard cutover): - DA_CONFIG_DIR -> AGNES_CONFIG_DIR - DA_SERVER -> AGNES_SERVER - DA_SERVER_URL -> AGNES_SERVER_URL (test-only stale ref, not in spec) - DA_NO_UPDATE_CHECK -> AGNES_NO_UPDATE_CHECK - DA_LOCAL_DIR -> AGNES_LOCAL_DIR - DA_TOKEN -> AGNES_TOKEN - DA_STREAM_RETRIES -> AGNES_STREAM_RETRIES Config dir rename: ~/.config/da/ -> ~/.config/agnes/ (across code, comments, docstrings, error messages, install templates, dev scripts). Stale `da X` references in CLI source (and adjacent app/, tests/): swept docstrings, comments, help text, and error messages where the verb survives the rewrite (init, pull, push, catalog, status, diagnose, auth, admin, skills, query, schema, describe, explore, disk-info, snapshot, login, logout, whoami, server, setup) and replaced `da X` with `agnes X`. Intentionally kept `da sync`, `da fetch`, `da analyst`, `da metrics` — those verbs are removed in later tasks; the legacy strings will be detected by `_LEGACY_STRINGS` (added in Task 2). Test fixes: - TestCLIVersion now asserts output starts with `agnes ` (was `da `). Test results: 2675 passed, 25 skipped (full pytest run, excluding 9 pre-existing test_db.py / test_user_management.py / test_e2e_extract.py / test_cli_binary_rename.py failures unrelated to this rename).
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""Status commands — agnes status."""
|
|
|
|
import json
|
|
|
|
import typer
|
|
|
|
from cli.client import api_get
|
|
from cli.config import get_sync_state
|
|
|
|
status_app = typer.Typer(help="System status")
|
|
|
|
|
|
@status_app.callback(invoke_without_command=True)
|
|
def status(
|
|
local: bool = typer.Option(False, "--local", help="Show local-only status (no server)"),
|
|
as_json: bool = typer.Option(False, "--json", help="Output as JSON"),
|
|
):
|
|
"""Show system health and sync status."""
|
|
if local:
|
|
state = get_sync_state()
|
|
info = {
|
|
"mode": "local",
|
|
"tables_synced": len(state.get("tables", {})),
|
|
"last_sync": state.get("last_sync", "never"),
|
|
"tables": state.get("tables", {}),
|
|
}
|
|
if as_json:
|
|
typer.echo(json.dumps(info, indent=2))
|
|
else:
|
|
typer.echo(f"Mode: offline (local data)")
|
|
typer.echo(f"Tables synced: {info['tables_synced']}")
|
|
typer.echo(f"Last sync: {info['last_sync']}")
|
|
return
|
|
|
|
try:
|
|
# Minimal health ping first
|
|
resp = api_get("/api/health")
|
|
minimal = resp.json()
|
|
if minimal.get("status") != "ok":
|
|
if as_json:
|
|
typer.echo(json.dumps(minimal, indent=2))
|
|
else:
|
|
typer.echo(f"Status: {minimal.get('status', 'unknown')}")
|
|
return
|
|
|
|
# Detailed health (auth required) for service-level info
|
|
try:
|
|
resp = api_get("/api/health/detailed")
|
|
data = resp.json()
|
|
except Exception:
|
|
data = minimal
|
|
|
|
if as_json:
|
|
typer.echo(json.dumps(data, indent=2))
|
|
else:
|
|
typer.echo(f"Status: {data.get('status', 'unknown')}")
|
|
for name, check in data.get("services", {}).items():
|
|
s = check.get("status", "?")
|
|
detail = ""
|
|
if "tables" in check:
|
|
detail = f" ({check['tables']} tables, {check.get('total_rows', 0)} rows)"
|
|
if "count" in check:
|
|
detail = f" ({check['count']})"
|
|
if check.get("stale_tables"):
|
|
detail += f" [stale: {', '.join(check['stale_tables'])}]"
|
|
typer.echo(f" {name}: {s}{detail}")
|
|
except Exception as e:
|
|
typer.echo(f"Cannot reach server: {e}", err=True)
|
|
typer.echo("Use --local for offline status.")
|
|
raise typer.Exit(1)
|