<!-- docs/decisiones/0055-vault-and-sentinel-architecture.md at 034e81b52d1b693c65ff95181cd555c6734bc8e8 · https://github.com/OmarAlex24/klav/blob/034e81b52d1b693c65ff95181cd555c6734bc8e8/docs/decisiones/0055-vault-and-sentinel-architecture.md · status: fresh -->

# 0055 · Vault and Sentinel: the product's two layers, Klav Cloud as Sync and Sentinel, and a calmer Mac app

- Status: accepted (2026-12-03). Omar decided the model, the names and the Mac app's direction in this thread (recorded under "Omar's decisions" below). Amended on 2026-12-04 after Omar tested `v0.15.0` ("Amendment of 2026-12-04", at the end): Sentinel has five tabs, a credential is allowed from its item, and repositories link from every developer tab.
- Date: 2026-12-03
- Read on: `fix/mac-totp-activity-notifications` at `995c2ab3` (PR #118, 2026-12-03). Paths below are from that commit.
- Amends:
  - [ADR 0033](0033-agentes-desde-la-app-de-mac.md) E1: the Mac sidebar's "Development" section becomes two groups that show when relevant (§3.1), and Clients becomes a tab of Agents (§3.2).
  - [ADR 0051](0051-hosted-nitro-enclave-proxy.md), in the interface only: the hosted proxy the apps called "Klav Cloud" or "Klav Cloud's proxy" is "Klav Cloud Sentinel" (§1.3). No identifier, format or wire value changes.
- Builds on and does not replace:
  - the Mac app ([ADR 0027](0027-app-de-mac.md)) and its tokens ([`docs/diseno-visual/README.md`](../diseno-visual/README.md)),
  - the "Development" switch in the vault ([ADR 0032](0032-entornos-por-repositorio.md) §7, not built), which §3.1 leaves as it is,
  - sandboxes and the credential proxy ([ADR 0036](0036-sandboxes-de-agentes.md)), the MCP gateway ([ADR 0049](0049-mcp-gateway.md)), tunnels and the Postgres SQL guard ([ADR 0052](0052-websocket-tunnels-and-postgres-sql-guard.md)) and sandbox MCP ([ADR 0053](0053-sandbox-mcp.md)),
  - deleting the account ([ADR 0037](0037-borrar-la-cuenta.md) D-C): what the window keeps after it does not change.

## Context

### What the person sees today
The Mac app's sidebar (`apps/ios/Mac/MainWindow.swift`, `Sidebar`) stacks, in 220 pt: All items, up to ten item kinds, Vaults, Repositories, Requests, six Development rows (Map, Clients, Agents, Sandboxes, MCP servers, Activity), a "Passwords" group with Vault health alone in it, This Mac and the account. A vault with developer items and agents reaches about 25 rows, and on the default 780 pt window the last ones fall below the fold. Someone who only keeps passwords sees six developer rows they will never use, and Vault health, which is where Klav started, at the very bottom.

Development › Sandboxes (`SandboxesPane.swift`) stacks up to seven blocks before the first sandbox: a security problem, the pause, the credential proxy's header, Klav Cloud's row, the shared credentials, this Mac's proxy and the warnings.

### What the words say today
"Klav Cloud" names two different things. On the map it is "Klav Cloud Sync", the server at `api.klav.dev` that stores only ciphertext. In Sandboxes, MCP servers, an agent's row ("Klav Cloud · attested") and the iPhone's Settings it is the hosted credential proxy of ADR 0051, which does decrypt the credentials shared with it, inside an attested enclave. Someone who reads "Klav Cloud" in one place can't tell whether their passwords are in the other.

### What the Mac app can't do yet
The CLI imports from other password managers, empties and restores the trash, creates vaults and projects, attaches files and sets up a credential proxy. The Mac app does none of these yet.

## Decision

### 1. Two layers: the Vault and Sentinel

#### 1.1 The Vault
The person's end-to-end encrypted, zero-knowledge vault, on their own devices: `klavd`, the Mac app, the iPhone app and the browser extension. It keeps personal logins, one-time codes, passkeys, cards, secure notes, addresses and files, and a developer's secrets: API keys, databases, environments and SSH keys. Agents get actions on it, not values, as before (ADR 0002, ADR 0033).

#### 1.2 Sentinel
The only layer outside the person's devices that decrypts a shared credential, in flight, to use it for them. It comes in two forms:

- **Klav Cloud Sentinel:** `klav-proxy` inside a hardware-attested AWS Nitro Enclave that Klav runs (ADR 0051), which every device verifies before it wraps anything for it.
- **A self-hosted `klav-proxy`** (ADR 0036): on the person's server, or on their Mac as a LaunchAgent.

Sentinel serves what has to run while the person's devices may be asleep or elsewhere: sandboxes (ADR 0036, ADR 0042), remote MCP servers (ADR 0049), the Postgres SQL guard and WebSocket tunnels (ADR 0052), and sandbox MCP (ADR 0053).

**There are no two vaults.** Cryptographically there is one vault. A credential reaches Sentinel only when the person shares that item with it, one by one, wrapped with HPKE to the proxy's key (ADR 0036 §2, ADR 0051 §4). Sentinel never holds the master password, the Secret Key, a vault or project key, or an item that wasn't shared with it. Stopping it changes the keys of what it held, as today.

#### 1.3 Klav Cloud is Sync and Sentinel
Klav Cloud, the hosted service, has two parts, and every surface names the one it means:

- **Klav Cloud Sync:** `klav-server` at `api.klav.dev`. Zero-knowledge: it stores and relays ciphertext only.
- **Klav Cloud Sentinel:** the hosted proxy in a hardware-attested Nitro Enclave (ADR 0051).

"Klav Cloud" alone names the hosted service as a whole (the plan, the account), never one of its two parts.

**Only names change.** No identifier, format, wire value, CLI command or Rust and FFI type is renamed: `proxy.mode = "klav"`, `HostedProxyInfo`, `klav proxy cloud`, the `klav-cloud-proxy` agent and `proxy.klav.dev` stay. Prose follows the interface; identifiers are quoted as they are ([`docs/glossary.md`](../glossary.md)).

### 2. Why, in three sentences for the person
Where Klav explains the two layers (the docs, the site, and later onboarding), it says:

> Your passwords, codes, passkeys and keys live in your vault, encrypted end to end on your own devices, and Klav's servers only ever sync ciphertext they can't read. An agent in a remote sandbox or a remote MCP server keeps working while your devices sleep, so something has to use a credential for it without handing it over: that is Sentinel, either Klav Cloud's hardware-attested enclave or your own `klav-proxy`. Sentinel only ever gets the credentials you share with it, one at a time, and never your vault.

The Mac app says it in one sentence above the proxies, in Sentinel › Proxy & issuers (`SentinelWords.note`).

### 3. The Mac app: a personal vault first, the rest when it is relevant (layer 1)

#### 3.1 The sidebar
```
All items                 ⌘1
Logins                          logins and their passkeys
One-time codes
› More                          cards, secure notes, addresses, files: only when one has items
Vault health              ⌘4
Vaults                          only with more than one
───────
Requests                  ⌘2    never hidden
Development                     only when relevant
  Keys & environments           API keys, databases, environments, SSH keys, in tabs
    github.com/acme/backend     one row per linked repository
Agents                          only when relevant
  Agents                  ⌘3    tabs: Agents · Connect apps (⌘6)
  Sentinel                ⌘7    tabs: Sandboxes · MCP servers (⌘8) · Proxy & issuers · Map (⌘9)
  Activity                ⌘5
───────
This Mac                  ⌘,
account · Lock
```

- **The personal vault comes first:** All items, Logins, One-time codes, and "More", which folds the kinds a person keeps less often and shows only when one of them has items. It opens by hand (remembered on this Mac) or while one of its kinds is chosen. Vault health moves up under the personal rows, and the old "Passwords" group goes. The vaults follow when there is more than one, as today.
- **Development** shows when the vault holds an API key, a database, an environment or an SSH key, when a project has a linked repository, when the switch below is on, or while one of its rows is chosen. "Keys & environments" is one row for the four developer kinds: its list has tabs ("All · API keys · Databases · Environments · SSH keys", only the kinds with items plus the chosen one), so nothing is lost and three sidebar rows go. "New item" there makes an API key; on its Environments tab, an environment, as today. The repositories follow it, indented.
- **Agents** shows when the account has an agent in any state (a credential proxy is one) or every agent is paused, when a credential proxy is known (the account's setting, Klav Cloud Sentinel in use, the list's proxy, one registered on this Mac, an MCP server), when the switch is on, or while one of its rows is chosen. Six rows become three: Agents, Sentinel and Activity.
- **Requests stays on its own and is never hidden** (ADR 0033 E1). The menu bar's warnings, theft signals and pause don't depend on either group.
- **A shortcut or a link always lands.** Each group also shows while one of its rows is chosen, so ⌘3, a notification or "Open the issuer's page" on an empty vault opens the pane and shows its group.
- **"Show developer & agent sections"** in Settings › This Mac, off by default. On, both groups show from the start, even on an empty vault. It only adds rows to this Mac's window: it changes no data, grant or permission, it never hides anything that exists, and it lives in this Mac's preferences (`KlavDeveloperMode`), not in the vault, so no agent can turn it.
- **ADR 0032 §7's switch stays as it was decided and unbuilt.** That one is synced in the vault, on by default, and hides kinds. If it is built, which of the two the Mac reads goes back to Omar.
- **After the account's deletion** (ADR 0037 D-C), the window keeps only the vault: the personal rows and "Keys & environments" with the repositories; no Requests, Vault health or Agents group, as today.
- The sidebar is 228 pt wide, with a little more room between groups.

#### 3.2 Panes with tabs
Agents and Sentinel are panes with tabs in their header: grey text, the chosen tab in ink with a 2 pt rule, a hairline closing the row, no boxes and no color ([`docs/diseno-visual`](../diseno-visual/README.md) §7, «Pestañas»). A tab with something wrong in it (a theft signal, a failed check, Klav Cloud Sentinel unverified, a heartbeat that went back, a client's entry changed outside Klav) carries a small red square.

- **Agents:** "Agents" (the account's agents, as before, with each agent's page) and "Connect apps" (what Development › Clients was).
- **Sentinel:**
  - **Sandboxes:** the security problems, the pause and the theft signals as before, then the account's proxy in one line (its name and heartbeat, in red when the heartbeat went back), with "Share a credential…" and "Proxy & issuers", then the sandboxes. Nothing else is stacked above them.
  - **MCP servers:** as before, except that Klav Cloud Sentinel's row moves to Proxy & issuers. This Mac's proxy stays, since local clients reach the servers through it (ADR 0049 §3.1).
  - **Proxy & issuers:** the one-sentence note of §2, the account's proxy with its heartbeat (or what is lost without one and how to set one up), Klav Cloud Sentinel's row, the shared credentials with "Share a credential…", this Mac's proxy, and the sandbox issuers with their profiles and limits, each opening its page, where "Manage sandbox profiles…" is.
  - **Map:** as before; a proxy's node opens Proxy & issuers.
- Every tab is a section of the window (`Section.clients`, `.mcpServers`, `.proxies`, `.map`), so the shortcuts, the menu bar, notifications, the links between panes and `-KlavSection` for screenshots land on the right tab, and the sidebar marks the pane's row.
- A pane's content is at most 740 pt wide.

#### 3.3 Shortcuts
The numbers don't move: ⌘1 All items, ⌘2 Requests, ⌘3 Agents, ⌘4 Vault health, ⌘5 Activity, ⌘6 Agents › Connect apps, ⌘7 Sentinel (on Sandboxes), ⌘8 Sentinel › MCP servers, ⌘9 Sentinel › Map. The Go menu adds "Keys & environments", without a shortcut.

#### 3.4 Words
- Where the interface said "Klav Cloud" or "Klav Cloud's proxy" for the enclave, it says "Klav Cloud Sentinel": its row, "Use Klav Cloud Sentinel", the red row, the map's node, an agent's row ("Klav Cloud Sentinel · attested") and the notices that name it. "Klav Cloud Sync" stays. The words shared with the iPhone (`CloudProxyWords`) change its Settings › Credential proxy too.
- Paths in the interface follow the new places: "Agents › Connect apps", "Sentinel › Proxy & issuers".
- "Sentinel" is a name and isn't translated; Spanish says «Llaves y entornos», «Conectar apps» and «Proxy y emisores».

### 4. The Mac app catching up with the CLI (layers 2 and later)
Each of these is a layer of its own, after this one, and none of them is designed here:

- **Import** from another password manager (ADR 0024), in the vault.
- **Trash and restore.**
- **Create a vault or a project.**
- **Attachments**, for files.
- **Setting up Sentinel** from the app: a self-hosted `klav-proxy`, this Mac's, or Klav Cloud Sentinel, with the pairing words where they apply. It touches keys and who the account trusts, so it gets its own ADR or amendment before code.

## Rejected alternatives
- **Two vaults, personal and developer or local and cloud.** It would split one account's keys and sharing in two, and it isn't needed: sharing one item with Sentinel already keeps the rest out of it.
- **Hiding Development and Agents behind the switch alone.** Someone with agents and the switch off would lose sight of them. The groups show on their own once there is something in them, and the switch only adds.
- **A sidebar row per Sentinel pane, as today.** It is what crowds the sidebar.
- **Renaming code identifiers** (`proxy.mode = "klav"` to something with "sentinel"). It would need a migration across the server and every client, for no change the person sees.
- **Calling the hosted proxy only "Sentinel".** A self-hosted `klav-proxy` is Sentinel too; "Klav Cloud" says who runs it.

## Consequences
- An empty vault's sidebar has five rows above This Mac (All items, Logins, One-time codes, Vault health and Requests); the sample vault, with developer items and agents, about thirteen instead of about twenty-five.
- The Development and Agents groups appear on their own the first time a developer item, an agent or a proxy shows up. That is when they become relevant.
- Sandboxes no longer shows the proxies' details; they are one tab away, and the proxy's line says when something is wrong with it.
- The public docs (`apps/docs`, the Mac app's page and the pages that name its panes), `docs/macos.md`, `docs/features.md` and both glossaries change in the same PR.
- Screenshots: `-KlavSection` also takes `proxies`, `sentinel` and `keys`, and `-KlavDeveloperMode YES` turns the switch on (`Snapshot.swift`).

## Plan in layers
1. **This ADR, the sidebar, the panes with tabs and the words** (§1–§3): Mac app only, no Rust change. Tests in `KlavMacTests` (`SidebarTests` and the existing ones updated).
2. Import in the Mac app.
3. Trash and restore.
4. Create a vault or a project.
5. Attachments.
6. Setting up Sentinel from the app, after its own ADR or amendment.

The iPhone app and the extension follow §1's names as their screens change; that is not a layer of this ADR.

## Stop rules
- If layer 1 turns out to need a change in `crates/` or in the FFI, stop: it is names and layout only.
- If a group's rule would hide something that asks the person for a decision, stop and come back to Omar.

## Omar's decisions (2026-12-03)
- **The model:** the Vault (end to end, on the person's devices) and Sentinel (the only layer outside them that decrypts a shared credential in flight: Klav Cloud Sentinel in a hardware-attested Nitro Enclave, or a self-hosted `klav-proxy`).
- **The names:** Klav Cloud is Sync (ciphertext only) and Sentinel (the attested enclave).
- **No two physical vaults:** one vault, shared item by item with HPKE when granted to Sentinel.
- **The Mac app:** a clean personal vault by default; Development and Agents shown when relevant or with a "developer mode" switch in Settings; the six infrastructure rows become three calm panes, Agents, Sentinel and Activity, with tabs.
- **The CLI's features in the Mac app** (import, trash and restore, creating vaults and projects, attachments, proxy setup) come as layers 2 and later, so this PR stays on layer 1.

## Amendment of 2026-12-04: Sentinel in five tabs, allowing a credential from its item, and linking repositories

Omar tested `v0.15.0` on his Mac. Sandboxes and Proxy & issuers looked the same (both showed the account's proxy with its heartbeat, "Share a credential…" and the way to the other tab), "Share a credential…" didn't say what it does or why it is needed when the vault is already encrypted end to end, an item had no way to reach Sentinel, and the Repositories bar with "Link repo…" disappeared on the Environments and SSH keys tabs. This amends §3.2 and §3.4 for the Mac app only: no change in `crates/`, in the FFI or in what is signed.

### Sentinel's tabs (amends §3.1 and §3.2)
`Sentinel ⌘7 tabs: Sandboxes · Credentials · MCP servers (⌘8) · Setup · Map (⌘9)`. They separate what runs, what Sentinel may use, what it serves, and what is set up once:

- **Sandboxes:** what runs, as before (the security problems, the pause, theft signals, "Active sandboxes" with "Revoke" and "Revoke all…", "Ended in the last 24 h" and the log's footer), without the account's proxy line. A red line with "Open setup" shows only when Setup needs the person: a heartbeat the server held back, or Klav Cloud Sentinel failing its check.
- **Credentials** (new, `Section.sentinelCredentials`, `-KlavSection credentials`): one sentence on why a credential is allowed here, which Sentinel it is, what it holds (each credential with its profile, its host, its WebSocket tunnel hosts, the issuers whose grant names its profile, and "Open", which opens the item), and "Allow credential…".
- **MCP servers:** as before.
- **Setup** (`Section.proxies`, still `-KlavSection proxies`, and now also `setup`): what was Proxy & issuers, without the shared credentials: the note of §2, the account's proxy with its heartbeat or what is lost without one, Klav Cloud Sentinel's row, this Mac's proxy and the sandbox issuers. The tab keeps the red square of §3.2.
- **Map:** as before; a proxy's node opens Setup, and its "+", "Allow credential…".

### Allowing a credential (amends §3.4)
- "Share a credential…" is "Allow credential…" (ES «Permitir credencial…»). Its sheet is "Allow a credential in Sentinel", says in one line that Sentinel gets only that credential, encrypted to its attested enclave (or to the person's `klav-proxy`'s key), and injects it for the host and rules shown, and its button is "Allow in Sentinel". What is signed doesn't change: it is the per-item share of ADR 0036 §2 (`klav proxy grant`). Code names (`ShareCredentialSheet`, `proxy_grant`) stay.
- The sheet is the window's, opened by `MacModel.allowInSentinel(itemId:)` from Credentials, the map, a pending proxy's row in Agents and an item's page, so it never shows twice.
- **An item's "Sentinel" row:** an API key or a database (and any item Sentinel holds) says "Allowed in Sentinel" with its profile and host and "View in Sentinel", or "Use in Sentinel…", which opens the sheet with that item chosen, or "Set up Sentinel" when the account has none. The page reads the account's proxy once, not per item (`loadCredentialProxy`), so opening items never asks Klav Cloud Sentinel's enclave for another attestation.

### Setting Sentinel up with an agent (not layer 6)
While the account has no Sentinel, Sandboxes, Credentials and Setup show "Set up Sentinel with your agent": a prompt, in English or Spanish, to paste into a coding agent, which follows `https://klav.dev/setup.md` one step at a time, never asks for a password or a key in the chat and gives the person each `klav proxy` command to run in their own terminal. "Copy prompt" puts it on the clipboard as plain text: it holds no secret. The app sets nothing up and changes no key or trust, so layer 6 (setting up Sentinel from the app) still needs its own ADR or amendment.

### Repositories (ADR 0032 §2)
- The Repositories bar with "Link repo…" shows on every tab of "Keys & environments", Environments and SSH keys included, with the chips on each (`VaultFilter.showsRepositories`, `keysAndEnvironments`).
- An environment's page and a developer item's page show their project's repository under the title, with "Repos…" or "Link repo…". The three open one sheet over the window (`MacModel.linkRepo`).
- "Link a repository" adds "Choose local repo…", which reads a chosen folder's `origin` from its Git config in Swift, without running `git` (a worktree through `commondir`, a submodule through its `gitdir:`), and leaves out a password or token in an `https://` remote; and "New project…" in the project's menu (`ProjectMenu`, as in the editor and the import).
