Synced from the project README at build time. ·View on GitHub ↗

Ansina is my hands-on lab for building an autonomous AI agent end to end: a small always-on Heart that decides when to idle, act or escalate, a remote Brain for the real reasoning, and a single authenticated REST API in between. I write up each milestone as a blog post; the project README below is pulled straight from the repository on every build of this site.

🫀 Ansina

CI

A self-owned AI agent: an always-on in-process Heart plus a remote Brain, exposed over a single internal REST API. No chat channels.

flowchart LR
    Client["Client\n(ansina-tui · curl · browser)"] -->|Bearer token| Auth["Auth + RBAC\n(roles, sudo step-up)"]
    Auth --> Routes["REST API\n(health · heart · auth)"]
    Routes --> DB[("SQLite\nWAL")]
    Routes --> Tick["TickLoop\n(idle / act / escalate)"]
    Tick -.optional.-> Brain[("Brain\n(remote, OpenAI-compatible)")]
Request flow: a client (the TUI, curl or a browser) authenticates with a bearer token and role checks, then calls the REST API. The API reads and writes SQLite and drives the Heart’s tick loop, which can optionally escalate a decision to the remote Brain.

⚡ Quick Start

make sync          # bootstraps uv if missing, installs dependencies
uv run ansina       # serves on http://127.0.0.1:8000
curl localhost:8000/healthz

First run prints a bootstrap Admin API token once — copy it now, it’s never shown or stored in plaintext again:

uv run ansina        # look for the banner, then Ctrl-C
export TOKEN=<the token from the banner>
curl -H "Authorization: Bearer $TOKEN" localhost:8000/version

🔐 Auth

Every route except /healthz//readyz/the login routes requires a bearer token (Authorization: Bearer ...) identifying a user with a role granting that route. Four fixed roles, increasing in scope: Read → Write → Maintain/Admin.

A handful of sensitive actions (user/role management) additionally require a short-lived sudo grant, mirroring Linux sudo:

curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"password": "..."}' localhost:8000/auth/sudo
# -> {"token": "...", "expires_at": "..."}
# then present it on the sensitive call:
curl -H "Authorization: Bearer $TOKEN" -H "X-Sudo-Token: <that token>" ...

Password login (POST /auth/login), OIDC federated login, TOTP second-factor step-up, and CORS for browser-hosted clients are all supported, each off or gated behind its own config flag — see docs/architecture/blueprint.md for how and why. The full route-by-route contract is GET /openapi.json (point any OpenAPI UI at a fetched copy — no /docs//redoc HTML viewer is served) or tui/README.md for the CLI’s own per-command breakdown.

🖥️ Control surface (ansina-tui)

One binary, two surfaces, over the same REST API: bare ansina-tui opens a Textual TUI; any argument — a subcommand, --help — makes it a CLI instead.

uv tool install ./tui              # global `ansina-tui`
ansina-tui status                  # health → readiness → version, no token needed
ansina-tui auth login --with-token < token.txt
ansina-tui api /auth/me | jq .roles

See tui/README.md for every command, flag, exit code, and the config file layout.

⚙️ Configuration

Precedence: built-in defaults → ansina.toml → ANSINA_* env vars. Secrets are env-only — setting ANSINA_SECURITY__API_TOKEN in ansina.toml is a hard startup error. See ansina.example.toml for the full shape.

🫀 Heart runtime

The in-process Heart ([heart] enabled, off by default) currently runs on MLX only — Apple Silicon:

uv sync --extra mlx
ANSINA_HEART__ENABLED=true uv run ansina

On any other host, enabling it fails loudly at boot rather than silently degrading. For the Mac Mini M4 deployment target specifically, docs/heart/mac-mini-m4.toml is a complete, copy-to-ansina.toml profile with every validated [heart]/[heart.tick]/ [heart.journal] value, annotated with the measurement behind it.

Once loaded, the Heart runs an autonomic tick loop ([heart.tick]): every interval_seconds it decides idle/act/escalate. GET /heart/tick reports its state; POST /heart/tick/pause//resume is the kill switch; GET /heart/journal is a durable, readable trace of every past decision. [heart.tick] escalate_to_brain (default false) additionally wires an escalate decision to a real BrainProvider call ([brain], below) — false is a verified no-op either way.

The remote Brain ([brain] enabled, off by default) is a 35B+ model reached through any OpenAI-compatible endpoint — configure [brain] base_url/api_key/ model. It owns all real reasoning; the Heart never answers for it.

🧪 Dev tooling

make check         # everything CI runs: lint, format-check, mypy --strict, full test suite
make check-all      # the above, plus tui/'s own check suite

Run make help for the full target list.

📚 Docs

Ansina on the blog