Initial Tessera backup vault (M0–M2)

Scaffold Rust workspace, React canvas, vault engine, hub API,
providers, agent wormhole path, and Docker compose per SPEC.
This commit is contained in:
Tessera Agent
2026-11-09 09:59:42 +00:00
commit a5ffb2c1b4
54 changed files with 8379 additions and 0 deletions

166
docs/SPEC.md Normal file
View File

@@ -0,0 +1,166 @@
# Tessera — behavioral specification (v1)
Tessera is a self-hosted backup vault. This document is the contract for metaphors, state machines, error copy, and security baseline.
## Metaphor glossary
| Internal concept | User-facing term | Notes |
|------------------|------------------|-------|
| Repository | **Vault** | One encrypted store per host |
| Scheduled / manual job | **Orbit** | “Your data circles the vault on a schedule” |
| Point-in-time backup | **Snapshot** | A **tile** on the vault ring |
| Remote machine | **Outpost** | Runs `tessera-agent` |
| Encrypted link to hub | **Wormhole** | Pair once; beam snapshots upstream |
| Retention | **Decay** | Old snapshots fade per policy |
| Restore | **Reconstitute** | Destructive-capable; always confirm |
| Deduped deltas | “Only stardust that changed” | Tooltip only—not headline copy |
### Status dots (Lune-style)
| Color | Meaning |
|-------|---------|
| Green | All orbits current; last snapshot succeeded |
| Amber | Orbit running, pairing waiting, or reconstitute countdown |
| Grey | Outpost offline or never paired |
| Red | Last snapshot or reconstitute failed |
---
## State machine: orbit run
```
┌─────────────┐
schedule/ │ idle │
manual snap └──────┬──────┘
│ start
▼
┌─────────────┐
┌────│ preparing │──── timeout ──► failed
│ └──────┬──────┘
│ │ provider ready
│ ▼
│ ┌─────────────┐
│ │ capturing │◄── dry-run: skip vault write, end at rehearsed
│ └──────┬──────┘
│ │ packs sealed
│ ▼
│ ┌─────────────┐
│ │ sealing │
│ └──────┬──────┘
│ │ index updated
│ ▼
│ ┌─────────────┐
└───►│ applying │ decay after success only
│ decay │
└──────┬──────┘
│
┌───────────┴───────────┐
▼ ▼
┌─────────────┐ ┌─────────────┐
│ completed │ │ failed │
└─────────────┘ └─────────────┘
```
**Invariants**
- Only one active capture per orbit per vault at a time (hub enforces lock).
- Decay runs only after a **successful** non-dry-run seal.
- Dry-run (“rehearse”) never writes snapshot metadata to the vault store.
---
## State machine: reconstitute
```
user picks snapshot + target
│
▼
┌─────────────┐
│ confirming │ show evidence: size, age, paths/DB name
└──────┬──────┘
│ user confirms
▼
┌─────────────┐
│ countdown │ 12s grace; abort returns to idle
└──────┬──────┘
│ timer elapsed
▼
┌─────────────┐
│ restoring │
└──────┬──────┘
│
┌────────┴────────┐
▼ ▼
completed failed
```
**Copy during countdown:** “Reconstituting in {n}s — abort restores nothing.”
---
## State machine: wormhole pairing
```
Hub Outpost (agent)
│ │
│ display 6-char pairing code │
│◄───────────────────────────────│ user runs: tessera wormhole pair
│ │
│ POST /wormhole/claim │
│◄───────────────────────────────│
│ │
│ issue device token + id │
│───────────────────────────────►│
│ │
│ mTLS or Bearer on upload API │
│◄───────────────────────────────│
```
States: `unpaired` → `code_shown` → `claimed` → `active` → `offline` (heartbeat miss).
---
## Error UX copy (English v1)
| Situation | User message | Telemetry (expandable) |
|-----------|--------------|------------------------|
| Vault locked | “Another orbit is still circling the vault. Try again when it finishes.” | `orbit_lock:{id}` |
| Wrong passphrase | “That key doesn’t unlock this vault.” | No stack traces |
| Provider missing | “We couldn’t reach the source at this outpost.” | Provider error string |
| Postgres dump failed | “The database wouldn’t yield a snapshot.” | `pg_dump` exit code |
| Disk full | “The vault is out of space—free room or widen the hold.” | Bytes needed |
| Wormhole expired code | “That pairing code has burned up. Generate a fresh one on the vault.” | TTL 10m |
| Reconstitute aborted | “Reconstitute cancelled. Nothing was changed.” | — |
| Decay pruned | “{n} old snapshots decayed per your policy.” | Snapshot IDs |
Tone: short sentences, metaphor in headings, facts in telemetry panels.
---
## Security baseline
1. **Vault key:** Argon2id-derived key from passphrase; key file `keys/tessera.key` (mode 0600). Never logged.
2. **Hub auth (v1):** Local admin password → HTTP-only session cookie; hook point for OIDC later.
3. **Agents:** No vault master key. Hub issues **scoped upload tokens** per outpost/orbit after pairing.
4. **Wormhole:** v1 token-based HTTPS upload; mTLS optional when `TESSERA_WORMHOLE_MTLS=1` and certs present.
5. **Control plane:** SQLite (`data/tessera.db`) holds metadata only—no backup payloads.
6. **Audit:** Pairing, reconstitute start/complete, decay prune logged to `audit_log` table.
---
## Decay presets (friendly → policy)
| Preset | Rule |
|--------|------|
| `week-of-dailies` | Keep 7 daily snapshots |
| `month-of-weeklies` | Keep 4 weekly |
| `year-of-monthlies` | Keep 12 monthly |
| `custom` | Hub-stored JSON policy (see `tessera-core::decay`) |
---
## API conventions
- REST JSON under `/api/v1/`
- OpenAPI 3.1 via hub `utoipa`
- Webhooks (struct only v1): `orbit.completed`, `orbit.failed`, `decay.pruned`, `outpost.offline`