Skip to content

Commit 690f1fb

Browse files
authored
Merge pull request #145 from kalibr-ai/fix/kalibr-status-implement
fix: implement kalibr status command (was stub returning "coming soon")
2 parents f476828 + 8d5609a commit 690f1fb

2 files changed

Lines changed: 85 additions & 6 deletions

File tree

kalibr/cli/main.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Import command functions
1212
from kalibr.cli.serve import serve
1313
from kalibr.cli.signup_cmd import signup
14+
from kalibr.cli.status_cmd import status as _status_cmd
1415
from kalibr.cli.verify_cmd import verify
1516
from rich.console import Console
1617

@@ -32,6 +33,7 @@
3233
app.command(name="signup")(signup)
3334
app.command(name="auth")(auth)
3435
app.command(name="prompt")(prompt)
36+
app.command(name="status")(_status_cmd)
3537

3638

3739
@app.command()
@@ -67,11 +69,5 @@ def update_schemas():
6769
console.print("3. Schemas will be auto-regenerated")
6870

6971

70-
@app.command()
71-
def status():
72-
"""Check status of a deployed Kalibr app."""
73-
console.print("[yellow]📊 Status checking coming soon[/yellow]")
74-
75-
7672
if __name__ == "__main__":
7773
app()

kalibr/cli/status_cmd.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""kalibr status - Show Kalibr SDK and service health."""
2+
3+
import os
4+
5+
import httpx
6+
from rich.console import Console
7+
from rich.rule import Rule
8+
9+
console = Console()
10+
11+
12+
def _mask(value: str, visible: int = 10) -> str:
13+
"""Mask a credential, showing only the first `visible` characters."""
14+
if len(value) <= visible:
15+
return value
16+
return value[:visible] + "..."
17+
18+
19+
def _check_service(url: str, headers: dict) -> str:
20+
"""
21+
Hit a /health endpoint and return a status string.
22+
Returns a Rich-formatted string.
23+
"""
24+
try:
25+
r = httpx.get(url, headers=headers, timeout=8)
26+
if r.status_code == 200:
27+
data = r.json()
28+
parts = []
29+
# Collect sub-service statuses from common health response shapes
30+
for key in ("clickhouse", "redis", "database"):
31+
val = data.get(key) or data.get("services", {}).get(key)
32+
if val:
33+
label = "connected" if str(val).lower() in ("ok", "connected", "healthy", "true") else str(val)
34+
parts.append(f"{key}: {label}")
35+
detail = f" ({', '.join(parts)})" if parts else ""
36+
return f"[green]✓ healthy{detail}[/green]"
37+
else:
38+
return f"[red]✗ unhealthy (HTTP {r.status_code})[/red]"
39+
except httpx.TimeoutException:
40+
return "[red]✗ timed out[/red]"
41+
except Exception as e:
42+
return f"[red]✗ unreachable ({e})[/red]"
43+
44+
45+
def status() -> None:
46+
"""Show Kalibr SDK version, credentials, and live service health."""
47+
from kalibr import __version__
48+
49+
api_key = os.environ.get("KALIBR_API_KEY", "")
50+
tenant_id = os.environ.get("KALIBR_TENANT_ID", "")
51+
base_url = os.environ.get("KALIBR_INTELLIGENCE_URL", "https://kalibr-intelligence.fly.dev")
52+
backend_url = "https://kalibr-backend.fly.dev"
53+
54+
headers = {}
55+
if api_key:
56+
headers["X-API-Key"] = api_key
57+
if tenant_id:
58+
headers["X-Tenant-ID"] = tenant_id
59+
60+
console.print()
61+
console.print("[bold]Kalibr Status[/bold]")
62+
console.print(Rule(style="dim"))
63+
64+
# SDK version
65+
console.print(f" [dim]SDK version:[/dim] {__version__}")
66+
67+
# Credentials
68+
if api_key:
69+
console.print(f" [dim]API key:[/dim] {_mask(api_key)} [green]✓ set[/green]")
70+
else:
71+
console.print(" [dim]API key:[/dim] [red]✗ not set[/red] (export KALIBR_API_KEY=...)")
72+
73+
if tenant_id:
74+
console.print(f" [dim]Tenant ID:[/dim] {_mask(tenant_id)} [green]✓ set[/green]")
75+
else:
76+
console.print(" [dim]Tenant ID:[/dim] [red]✗ not set[/red] (export KALIBR_TENANT_ID=...)")
77+
78+
# Service health
79+
console.print(f" [dim]Intelligence:[/dim] {_check_service(f'{base_url}/api/v1/intelligence/health', headers)}")
80+
console.print(f" [dim]Backend:[/dim] {_check_service(f'{backend_url}/api/health', headers)}")
81+
82+
console.print(Rule(style="dim"))
83+
console.print()

0 commit comments

Comments
 (0)