# Drasill — agent mesh control plane
# Usage: just <recipe>

# Default: list recipes
default:
    @just --list

# ─── Setup ───────────────────────────────────────────────────────────

# Install Python deps
setup:
    uv sync

# Install heimdall (hm) from latest release
install-hm:
    @echo "Download from: https://github.com/nazq/heimdall/releases"
    @echo "Or build: cd ~/dev/heimdall && cargo build --release && cp target/release/hm ~/.local/bin/"

# ─── Run ─────────────────────────────────────────────────────────────

# Start drasill server (with hot reload)
serve port="8400":
    uv run uvicorn drasill.app:create_app --factory --reload --port {{ port }}

# Start drasill server (production, no reload)
serve-prod port="8400":
    uv run uvicorn drasill.app:create_app --factory --port {{ port }} --host 0.0.0.0

# Launch a supervised Claude session
session name workdir=".":
    hm run --id {{ name }} --workdir {{ workdir }} -- claude

# List active sessions
sessions:
    hm ls

# Attach to an existing session
attach name:
    hm attach {{ name }}

# Query session status
status name:
    hm status {{ name }}

# Kill a session gracefully
kill name:
    hm kill {{ name }}

# Clean orphaned session logs
clean-logs:
    hm clean --force

# ─── Quality ─────────────────────────────────────────────────────────

# Run all checks (lint + format + types + unit tests)
check:
    uv run nox -s all_checks

# Run everything (unit tests + e2e tests)
check-all: check test-e2e

# Run Python tests
test *args:
    uv run pytest {{ args }}

# Run Python tests (verbose, stop on first failure)
test-fast:
    uv run pytest -x -q --tb=short

# Run Playwright E2E tests (headless)
test-e2e *args:
    uv run pytest e2e_tests/ --no-cov {{ args }}

# Run Playwright E2E tests (headed, for debugging)
test-e2e-headed *args:
    uv run pytest e2e_tests/ --no-cov --headed {{ args }}

# Lint Python code
lint:
    uv run ruff check py_src py_tests

# Format Python code
fmt:
    uv run ruff format py_src py_tests

# Type check Python code
types:
    uv run ty check

# ─── Dev ─────────────────────────────────────────────────────────────

# Reset database (deletes mesh state)
reset:
    uv run drasill reset-state --force

# Check required dependencies are available
doctor:
    uv run drasill check-deps
