Milestone 4: taking access back

Removing someone from a vault, a device, or the team opens departures
on the hub. Each device stops syncing, saves, goes read-only, hands
unshared work over (secrets redacted), and deletes the folder only if
the app created it. Managers review handovers (show/keep/discard/skip);
removed devices may only hand over, then their key is retired. Adds the
delete-from-devices vault setting and team restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 06:14:28 +07:00
parent 2b4ca84a6b
commit 4025726083
16 changed files with 1222 additions and 133 deletions

View File

@@ -153,52 +153,47 @@ Only the current milestone gets detailed below. The next one is detailed when th
---
## 6. Milestone 3 — Shared with my team
## 6. Milestone 4 — Access I can take back
Milestones 1–2 (sync over a Git remote, secret check, runaway guard) are built; their detail lives in the code and tests now.
Milestones 1–3 (sync, safety checks, the hub with invites, pairing and roles) are built; their detail lives in the code and tests now.
### Goal
A hub Sen runs in Docker replaces the plain Git remote. People get in by invite, add their own devices by pairing code, and every vault they're a member of arrives on its own. Roles are enforced by the hub, not by trust.
Taking access back is as clean as giving it. Removing someone from a vault collects their unshared work for a manager to review, then their copy disappears; their other vaults keep working. Removing someone from the team stops everything. A lost laptop can be removed on its own. All from the CLI.
### What Sen does
```bash
# on the VM
docker compose up -d # hub; first start prints the owner invite link in the log
# on the laptop
lunesync join https://hub.example/join/… --name Codex
lunesync vault upload DevOps # the M1 vault moves onto the hub, history kept
lunesync invite Alice --vault DevOps:edit # one-time link for Alice
lunesync pair # prints a ready-to-paste login line with a short code
# on the VPS
lunesync login --hub https://hub.example --code K7QD-4MXA --name Hermes
lunesync run # DevOps arrives in ~/Vaults/DevOps
# anytime
lunesync vault new Notes | grant Alice Notes --role read | members DevOps | hub log
lunesync remove Alice --vault DevOps # Alice loses DevOps only (A5)
lunesync remove Alice --vault DevOps --without-saving
lunesync device remove "Old laptop" # one device, e.g. lost; --person for someone else's (owner)
lunesync team remove Bob # owner only; asks to type the name (A8)
lunesync team restore Bob # re-enables the account; prints a one-time sign-in link
lunesync handovers # unshared work that came back, and devices still to report in
lunesync handover show|keep|discard 7
lunesync handover skip 7 # a device that will never come back: delete without saving
lunesync vault set DevOps --delete-from-devices off # A7, on by default
```
Alice runs `lunesync join <link> --name "Alice laptop"`, then `lunesync run`: DevOps arrives.
### Behavior
- **Hub** = one container: an HTTP API plus Git over HTTPS for vaults, SQLite and bare repos on one volume (`/data`). It listens on plain HTTP; TLS comes from Sen's reverse proxy. `LUNE_HUB_URL` is the public address used in links.
- **Accounts, memberships, devices (A1)**. The hub has one team; the first account is its **owner**. Owners create vaults; owners and a vault's **Manage** members invite and grant for that vault.
- **Invites (A4)**: one per person, a one-time link that names the person and the vaults + roles they get, valid 7 days. Accepting it creates the account and its first device.
- **Pairing**: a signed-in device asks for a code (8 characters, 10 minutes, single use); a new device logs in with it and gets its own key. Devices never share keys. A device key is shown once and stored in the device's config file (owner-only permissions); the hub stores only its hash.
- **Vaults arrive**: while `run` is going, the device checks the hub every 30 s and adds any vault it's now a member of, under `~/Vaults/<name>` (`--vaults-dir` to change). Vaults from M1 with a plain Git remote keep working.
- **Roles (A3)** are enforced by the hub on every Git request: Read can only receive changes. A Read member's own edits stay local; `status` says "not shared — you have read access".
- **Device labels (S7)**: chosen at join/login, renamed with `lunesync device name` (updates the hub too). History entries carry the label.
- **Hub secret check (P3)**: every incoming change is scanned with the same rules, commit by commit, before the hub accepts it. A hit is refused with the note, line and rule. "Not a secret" on a device is also sent to the hub for that vault.
- **Upload** keeps history. If old history contains a secret the hub refuses it; `vault upload --fresh` uploads only the current notes as a fresh start (the old history stays on that device only).
- **Access log (A10)**: the hub records invites created and accepted, devices paired and renamed, vaults created, memberships granted, and refused changes. `lunesync hub log` (owner).
- **Removing from a vault (A5, A6)**: the membership ends at once and the hub opens a *departure* for each of that person's devices. A device learns about it the next time it checks in (within ~30 s while running; offline devices on reconnect), then:
1. stops syncing that vault and saves anything unsaved;
2. makes the folder read-only;
3. sends everything not yet shared to the hub's **handover area** for that vault. Notes held by the secret check go along with the secret replaced by `[secret removed when leaving]` (P1: the secret itself is never sent or kept);
4. after the hub confirms receipt, deletes the folder — only if the app created it (marker in `.git/`, A9), never following links out. A folder the app adopted, or a vault with "delete from devices" off (A7), is left in place, read-only and no longer synced.
- A device that was removed can still do exactly one thing until its departures are done: hand over. It can't read or change the vault.
- **Handovers** are reviewed by a manager: **keep** combines them into the vault (same-lines clashes keep both, labeled with the leaving device), **discard** drops them. If nothing was unshared, the departure just completes. `skip` = "Delete without saving" for a pending departure.
- **Removing a device (A1)**: same flow for every vault on that device; afterwards its key stops working.
- **Remove from team (A8)**: owner only, asks for confirmation. Ends every membership (departures as above), removes every device, disables the account (restorable, keeps its name in history). Restore re-enables it with no vaults and a one-time sign-in link for a new device.
- Everything is in the access log (A10). Messages say plainly what can't be recalled (A11): copies made elsewhere stay where they are.
### Acceptance — Sen acts this out
1. `docker compose up -d` on a fresh VM; the owner link from the log works once and only once.
2. Upload the real DevOps vault; history and every file survive (checksums).
3. Pair the VPS with a code as "Hermes"; DevOps arrives; its edits show up labeled Hermes.
4. Invite a teammate with Edit on DevOps; they join, the vault arrives, their edits reach Sen.
5. Grant someone Read: the vault arrives, their edits stay local with the note, the hub refuses them even if pushed by hand.
6. Edit a note with a fake key directly in a hub vault from outside the app (plain `git push` with a device key): refused.
1. Alice has DevOps and Notes and edits DevOps while offline. Remove her from DevOps; when she reconnects her edit arrives as a handover, her DevOps folder disappears, Notes keeps syncing.
2. `handover show` lists her changes; `keep` brings them into DevOps on every device; another handover is discarded.
3. Remove Bob from the team: all his vaults leave his devices, his device can't do anything after, the access log shows each step. `team restore Bob` lets him back in with no vaults.
4. Remove a device that's switched off: `handover skip`; when it's switched on later, its copy is deleted without anything being sent.
5. A vault with "delete from devices" off: the person's copy stays, read-only, no longer synced.
### Out of scope for M3
Removing people or devices, handovers (M4). Any web UI (M5). Client updates from the hub (M7).
### Out of scope for M4
Undo window and gestures (M5, X2). Permanent account deletion (later admin action). Verifying removal in external tools (non-goal for v1).
## 7. Open questions
None open.