Metadata-Version: 2.5
Name: henzo
Version: 0.1.0
Summary: Henzo client: local recall, cloud learning
License: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: cryptography>=42
Requires-Dist: httpx>=0.27
Requires-Dist: keyring>=25
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# henzo

Python client for Henzo. Install once, store one API key, and run coding-agent hooks that recall locally and send finished rounds to the cloud for learning.

## Install

```bash
pip install henzo
henzo login
```

## Quick start

```bash
henzo login          # sign in with Google in the browser; this device gets its own key
henzo whoami         # tenant / profile / device (never prints the key)
henzo setup --agent cursor
henzo logout         # revoke this device's key on the server, then delete it here
```

`henzo login` prints a link and a code:

```
To sign in, open https://login.henzo.ai/device and enter BCDF-GHJK
```

Open the link (the CLI tries to open your browser; `--no-browser` skips that), sign in with an
allowlisted Google account, type the code, and approve. The CLI polls until the key arrives and
stores it. The link never carries the code: you always type it yourself. The browser is started from a
separate process that only gets the variables a browser launcher needs (no `HENZO_*`); on a
Linux box without a display it is not started at all. Logging in again replaces the stored
key and then revokes the old one on the server (best effort, only after the new key is safely
stored). `HENZO_LOGIN_URL` must be a plain `https://host` (no user info, path, or port other
than 443).

Operator-minted keys (`henzo-admin mint`) still work: `henzo login --key-stdin < keyfile`.
Headless hosts can set `HENZO_API_KEY` instead of using the store.

## Configuration

| Variable | Meaning | Default |
|---|---|---|
| `HENZO_API_KEY` | API key (overrides the store) | — |
| `HENZO_GATEWAY_URL` | Gateway base URL | `https://autodidact-learning-sync.guy-360.workers.dev` |
| `HENZO_LOGIN_URL` | Device-flow login base URL (`/v1/device/*` only); https only | `https://login.henzo.ai` |
| `HENZO_DATA_ROOT` | Root for per-profile data | `~/.henzo` |
| `HENZO_CONFIG_DIR` | Config and key-file directory | `~/.config/henzo` |
| `HENZO_TOKEN_STORE` | `auto`, `keyring`, or `file` | `auto` |

Per-profile data lives under `~/.henzo/<profile>/` (outbox, synced items). Tenant, profile and device ids must match the server rule `[A-Za-z0-9][A-Za-z0-9._-]{0,63}`; the profile folder must stay directly under `HENZO_DATA_ROOT`. The client never writes to `~/.autodidact`.

## Commands

- `henzo login [--profile P] [--device-name D] [--no-browser]` — RFC 8628 device flow: `POST /v1/device/start`, show the link and code, poll `POST /v1/device/token` (honours `interval`, `slow_down`, `authorization_pending`, `access_denied`, `expired_token`; stops at the code's expiry, at most 15 min). The returned v2 key is checked (shape, and tenant/profile/device/key id agree with the response and the request) and stored in the keyring when available, else a 0600 file in a 0700 directory. Default profile `main`, default device name the hostname
- `henzo login --key-stdin` (alias `--stdin`) or `--paste` — store a key you already have instead (same checks, same store)
- `henzo logout [--local-only]` — calls `POST /v1/keys/revoke-self` with the stored key (best effort), then deletes it locally. Operator-managed keys (409) and v1 keys (400) are only deleted locally, with a note; `--local-only` skips the call
- `henzo whoami` — show tenant, profile and device parsed from the key
- `henzo setup --agent <claude-code|codex|cursor|cursor-agent>` — install agent hooks (`--dry-run`, `--remove`)
- `henzo hook <event>` — agent hook entry point (reads JSON from stdin; always exits 0). On learn/stop it encrypts the round, queues it, and starts a detached background upload; the hook makes no network call itself
- `henzo round-key [--show]` — fetch the tenant round public key and pin it on first use (`round-key.json`, 0600); later fetches must match the pin or the command fails loudly. `setup` does this too when you are logged in
- `henzo rotate-round-key --confirm [--expect-kid KID]` — the only way to re-pin, after an announced rotation
- `henzo flush` — upload queued rounds now (412/409 count as already uploaded)
- `henzo sync pull [--json]` — pull learned-item deltas and apply them locally (replay-safe)

All gateway wire formats live in `src/henzo/wire.py`.

## Development

```bash
uv sync --extra dev
uv run pytest
```

See `TINY_CHECK.md` for the second-PC check plan and blockers.
