Metadata-Version: 2.5
Name: braven-identity
Version: 0.1.0
Summary: The one credential store the Braven CLI, watcher and SDK read
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# braven-identity

The one credential store the Braven **CLI** and the **SDK** read (and the GPUIX
watcher will read), so a person signs in once per machine and every surface
knows who they are.

This package is the reference implementation (Python, `src/braven_identity/`).
The convention below is the contract: any other implementation — the GPUIX
watcher's TypeScript side included — mirrors it rather than inventing a second
store.

## Two files, one owner

**Config — non-secret, one JSON file per machine.** Never holds a secret, so it
can be read, diffed and synced.

| OS | Path |
| --- | --- |
| macOS | `~/Library/Application Support/braven/config.json` |
| Linux | `${XDG_CONFIG_HOME:-~/.config}/braven/config.json` |
| Windows | `%APPDATA%\braven\config.json` |

```jsonc
{
  "version": 1,
  "current": "https://api.bravenlab.com|me@example.com", // key into `accounts`
  "accounts": [
    {
      "origin": "https://api.bravenlab.com",
      "email": "me@example.com",
      "kind": "session", // "session" | "apiKey"
      "label": "laptop" // optional: an API key's name
    }
  ],
  "defaults": { "company": "Gelion", "project": "Hydrogel Plasma Activation" },
  "watcher": { "concurrency": 3, "ignore": [".git", "node_modules"] }
}
```

**Secret — `credentials.json` beside the config file.** One JSON object keyed by
`{origin}|{email}` (the same string as `current`), written atomically with mode
`0600`. It is opencode's model: no OS keychain, so nothing prompts for a
password when a new binary reads it, and no native addon ships to every surface.
A file that cannot be read or written is a `SecretsError`, never a silent
fallback to the config file.

## Credential kinds

- `session` — a better-auth session token, as returned by
  `POST /api/auth/sign-in/email`. Sent as `Authorization: Bearer <token>`.
- `apiKey` — a long-lived `bvn_api_…` key (`Settings → API keys`), for headless
  machines and CI.

Both resolve to a principal the API already accepts.

## Multi-account

Accounts are keyed by `(origin, email)`; `current` points at one. Two companies
on one machine are two accounts, switched without logging out.

## Precedence: env var > flag > store

For CI and headless machines nothing has to be written:
`BRAVEN_SESSION_TOKEN`, `BRAVEN_API_KEY` (with `BRAVEN_API_URL`) win over the
store, and no file is touched.

## Usage

```bash
uv run pytest        # tests, on tmp files only
uv run ty check      # types
uv run ruff check .  # lint (repo-root ruff.toml)
```
