Document M5 in AGENTS.md

This commit is contained in:
raucao committed 2026-11-13 22:33:33 +04:00
1 parent 556201849d
commit c3bede517d
1 file changed
+51 -5
+51 -5
View File
@@ -26,13 +26,17 @@ src/application.rs AdwApplication, actions, CSS
src/window.rs main window: view switcher over the pages
src/config.rs GSettings wrapper (+ REGENT_RELAYS override)
src/runtime.rs tokio runtime + the bridge back to the GTK main loop
src/state.rs the key store, once connected, and change notifications
src/state.rs shared state: key store, app registry, activity log, change channel
src/signer/mod.rs the NIP-46 responder
src/signer/approval.rs asking the user (timeout ⇒ deny)
src/signer/policy.rs the auto-approval rate limit
src/store/apps.rs the registry of approved applications + their permissions
src/store/audit.rs the activity log (metadata only, mode 0600)
src/store/keys.rs key storage (Secret Service, one item per key)
src/ui/approval.rs approval dialogs
src/ui/apps_view.rs the apps page (permission table + revoke)
src/ui/activity_view.rs the activity page
src/ui/kind.rs human names for the common event kinds
src/ui/plain.rs plain-text rows/banners/dialogs (markup off)
src/ui/keys_view.rs the keys page
src/ui/signer_view.rs the signer page (pairing string, QR, state)
@@ -93,6 +97,39 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
- On start the app logs `regent: signer listening on N relay(s) as npub1…` — the
public key only, never the secret. That line is what headless checks assert on.
## Apps, permissions and the activity log (M5)
- `apps.json` is the single source of truth for what an app may do without
asking, and it is **shared**: `AppState` owns one `Arc<Mutex<AppRegistry>>`,
and the responder and the Apps page read the same one. "The policy table
drives behaviour" means revoking on the Apps page changes the responder
immediately.
- **Create `AppState` once per process** (in `application.rs`, captured by the
activate closure), not per window. A second `AppState` would mean a second
registry and a second signer on the same device key.
- The Apps page shows one `AdwExpanderRow` per app: per-app *Revoke* as a
suffix (visible while collapsed), one *Remove* row per stored permission
(kind for `sign_event`, method for encryption), and *Forget all*.
- The activity log (`store/audit.rs`) records **metadata only**: app, method,
event kind, outcome, time. `Entry` has a typed `kind: Option<u16>` and
deliberately **no free-form detail field**, so event content, plaintext and
ciphertext cannot reach it. Unapproved requests are **not** logged, so a
stranger who knows the device pubkey cannot flush the history. Both
`activity.jsonl` and `apps.json` are mode **0600** — including the log's trim
rewrite, which would otherwise recreate it world-readable.
- One **bounded(1), coalescing change channel** (`AppState::changes`) wakes both
pages after a registry or log change; the responder pings it from `record()`
and registry mutations, and `try_send` never blocks a signature. Never send
while holding the registry lock. Because it is shared, the Apps page compares
a `(pubkey, name, policy)` snapshot and skips the rebuild when only the log
changed — otherwise every answered request would collapse the expanders.
- `apps.json` is written **atomically** (temp file + rename), and a corrupt one
is moved to `apps.json.corrupt` rather than silently overwritten. `logout`
(NIP-46 "forget the client") revokes the app and its permissions — the only
meaningful "drop session" in a stateless responder. `get_permissions` is a
**Regent extension**, not NIP-46; the requested `perms` from a `connect`
(`params[2]`) are shown in the pairing dialog but never auto-granted.
## Keys
- The **identity key** is the user's `nsec`. It lives in the system keyring and
@@ -161,8 +198,13 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
markup-rendered widgets dynamic text breaks rendering on the first `&` (a
`bunker://…&secret=…` connection string shows nothing) and lets a client
inject formatting. Build them through `crate::ui::plain`
(`plain::row`, `plain::banner`, `plain::dialog`), which turns markup off;
put untrusted text in an `extra-child` of plain, selectable labels.
(`plain::row`, `plain::expander`, `plain::banner`, `plain::dialog`), which
turns markup off; put untrusted text in an `extra-child` of plain, selectable
labels. **Order matters:** a builder that sets `title`/`subtitle` before
`use_markup(false)` parses them as markup while it is still on, so an `&`
warns even though `use_markup(false)` follows — set markup off first, then the
text (`plain` does this). Symptom: a row renders empty and GTK logs "Failed to
set text … from markup".
## Blueprint / Meson traps
@@ -209,8 +251,12 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
port — sharing one port makes the parallel run hang.
- The policy logic itself is also covered by fast, relay-free tests that drive
`handle_request` with a client key they control (denial, allow-always per kind,
encryption remembered vs. decryption always asking, the rate limit, and a
dropped question denying). They run on a plain `cargo test`.
encryption remembered vs. decryption always asking, the rate limit, a dropped
question denying, revoking a permission bringing the prompt back, `logout`
forgetting the app, `get_permissions`, and registry changes being announced).
The audit has its own tests: a content canary never reaches the log,
unapproved requests are not logged, names are bounded, and `record` trims an
oversized file while keeping it 0600. All run on a plain `cargo test`.
- End to end (keyring → responder → app), in a throwaway HOME:
```sh
dbus-run-session -- build-aux/acceptance.sh