# xa.config

TOML config loader for `xa`.

Resolves a host registry and settings from `~/.config/xa/config.toml`
(respecting `$XDG_CONFIG_HOME`). Override the path via `$XA_CONFIG`.

### Example

```toml
[settings]
cache_dir = "~/.cache/xa/remotes"
stale_threshold_sec = 3600

[nav]                            # optional links to your other pages: label = address
Tasks = "/tasks/"
Docs = "https://docs.example.com/"

[hosts.local]
kind = "local"

[hosts.devbox]
kind = "ssh"
host = "devbox"

[hosts.phone_mirror]
kind = "http"
base_url = "https://apps.example.com/api/xa"
auth = "basic"
username = "me"
password_env = "XA_PHONE_PASSWORD"   # value read from env, not stored in TOML
```

The registry exposed by [`load_hosts()`](#xa.config.load_hosts) is `{name: Host}` and can be
passed directly to [`xa.sessions.list_sessions()`](xa.sessions.html.md#xa.sessions.list_sessions).

### Functions

| `default_config_path`()                                               |                                                                                       |
|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------|
| [`load`](#xa.config.load)([path])         | Return `(settings, hosts_registry)` from a config file.                               |
| [`load_hosts`](#xa.config.load_hosts)([path])   | Shortcut: just the host registry.                                                     |
| [`load_nav`](#xa.config.load_nav)([path])     | The `[nav]` links of the config file; empty when there is no file or no table.        |
| [`nav_entries`](#xa.config.nav_entries)(raw_nav) | `(label, address)` pairs of a `[nav]` table, in file order, unsafe addresses dropped. |

### Classes

| [`Settings`](#xa.config.Settings)(cache_dir[, stale_threshold_sec, ...])   |    |
|----------------------------------------------------------------------------------------------------|----|

### *class* xa.config.Settings(cache_dir, stale_threshold_sec=3600, claude_bin='claude', tmux_bin='tmux')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

### xa.config.load(path=None)

Return `(settings, hosts_registry)` from a config file.

Missing file → `(defaults, {"local": LocalHost()})`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Settings`](#xa.config.Settings), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### xa.config.load_hosts(path=None)

Shortcut: just the host registry.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

### xa.config.load_nav(path=None)

The `[nav]` links of the config file; empty when there is no file or no table.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]

### xa.config.nav_entries(raw_nav)

`(label, address)` pairs of a `[nav]` table, in file order, unsafe addresses dropped.

An address is kept only when it is an `http(s)` URL or a path on the same host
(`/tasks/`, not `//elsewhere`): a `javascript:` or `data:` link in a config
must not become a link on the page.

```pycon
>>> nav_entries({'A': '/a/', 'B': 'https://b.example/', 'C': 'javascript:x', 'D': '//d'})
[('A', '/a/'), ('B', 'https://b.example/')]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]
