Document the two-window shape and first-run mode in AGENTS.md

This commit is contained in:
raucao committed 2026-11-24 16:30:12 +04:00
1 parent fa744e23f6
commit 70ec0de749
1 file changed
+79 -18
+79 -18
View File
@@ -26,7 +26,7 @@ The full plan lives at `~/.opencode/plan/regent.md`.
src/main.rs arg parsing, resource registration, entry point
src/application.rs AdwApplication, actions, CSS
src/headless.rs headless mode + CLI pairing (no window)
src/window.rs main window: view switcher over the pages
src/window.rs the windows: main, identities, and the registry (M10)
src/config.rs GSettings wrapper (+ REGENT_RELAYS override)
src/runtime.rs tokio runtime + the bridge back to the GTK main loop
src/state.rs shared state: key vault, app registry, activity log, change channel
@@ -42,7 +42,8 @@ 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/dialogs (markup off)
src/ui/keys_view.rs the keys page (identity list + management)
src/ui/preferences.rs the preferences dialog (vault + rate limit)
src/ui/keys_view.rs the identities window's content (list + management)
src/ui/signer_view.rs the signer page (pairing string, QR, state)
src/ui/switcher.rs the header identity switcher
src/ui/qr.rs QR → GdkTexture
@@ -160,6 +161,60 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
`regent` again, and a second window would share the state and show the same
dialog twice.
## Windows and first run (M10)
- **Two windows, one `AppState`.** `window.rs` builds both and holds the
`Windows` registry; the identities window is chrome
(`data/resources/ui/keys.blp`) around the existing `KeysView`. A second
`AppState` would mean a second registry and a second signer on one device key
(see M5), so the registry is created once in `application.rs` and shared.
- **The invariant: the main window is visible exactly when the responder can
serve prompts.** The approval dialogs are parented to the main window, so a
request must never arrive without it. With no keys there is nothing to sign
with and nothing to listen for, so the identities window is the whole app;
closing the main window **quits the app** (`connect_close_request` →
`app.quit()`), because the identities window would otherwise keep the process —
and a signer that can answer nothing — alive behind a window the user believes
they closed.
- **The launch decision** (`Windows::build` + `present_primary`): no keys ⇒
present the identities window only; keys ⇒ the main window, whose first page is
Signer. `follow_keys` (a `state.listen` callback) follows the *transition*: the
first key presents the main window and leaves the identities window open, and
removing the last key hides the main window and presents the identities window
again — first-run mode. Acting on the transition rather than on every `notify()`
is what keeps a profile fetch or a lock from re-presenting a window the user
just closed. The choice is logged (`no identity key yet, opening the identities
window` / `identity keys found, opening the main window`): it is the one part of
the launch that cannot be observed from outside, and acceptance asserts on it.
- **`Windows::primary()` is the single rule** for "the window the app is", and
`app.focus`, `app.lock` and `present_preferences` all go through it. Do not
reintroduce `app.windows().first()` — it is creation order — and note that
`app.focus` used to present *every* window, which would pop the hidden
identities window open on every notification click.
- The identities window is created once and `set_hide_on_close(true)`:
`AppState::listen` cannot unregister and its closures capture widgets, so a
window destroyed and rebuilt would leave listeners pointing at dead widgets.
- **Preferences** (`ui/preferences.rs`) is an `AdwPreferencesDialog` — libadwaita
1.6 deprecated `AdwPreferencesWindow` in favour of it — built **once** and
re-presented (`AdwDialog` re-presents after being closed), with its listeners
registered once, because the lock state changes while it is open. It holds the
vault group and the auto-approval limit. Deliberately **not** relays: the
running signer holds `config.relays` from start, the bunker URI advertises them
and `get_relays` serves them, so a mid-run edit would mean "changed, but not
until restart, and the paired clients were told otherwise". Reachable by
`Ctrl+,` everywhere but by pointer only from the main window — deliberate, since
in first-run mode there is nothing to configure yet.
- **The primary menu** (main window) carries "Manage identities…",
"Preferences…" and "Quit". The identities entry is not redundant with the
switcher's: the switcher hides itself while there are no keys, and the
last-key-removed state is exactly when the menu is the only pointer route back.
- **The vault loads synchronously** — `KeyStore::connect()` is plain file I/O and
the `async` was vestigial from the removed keyring — so the launch decision can
depend on it and `state.store()` is no longer an `Option`. A vault that exists
but cannot be read is **fatal**: `application::run` prints and exits non-zero
*before* `app.run()`, because starting with an empty vault would let the next
save overwrite the real keys (the shape M8 closed).
## Apps, permissions and the activity log (M5)
- `apps.json` is the single source of truth for what an app may do without
@@ -219,9 +274,9 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
- `AppState::refresh_identities` resolves the current identity (setting valid,
else first key) and binds legacy apps (`bind_legacy`) at startup and after any
key change. Pre-M8 this also migrated a keyring item; that is gone.
- Keys page: list, **Add/Import**, per-key **Rename / Copy / Export / Remove**,
and **Use for new pairings**. Removing a key clears it as current, revokes the
apps bound to it (the dialog names them), and deletes the item.
- Identities window: list, **Add/Import**, per-key **Rename / Copy / Export /
Remove**, and **Use for new pairings**. Removing a key clears it as current,
revokes the apps bound to it (the dialog names them), and deletes the item.
- Approval dialogs show **"Signing as: {name} ({npub})"**; in-app pairing uses
the current identity and warns when it would rebind an existing app.
- Headless: `--headless`/`--pair` take **`--key <npub|hex>`** (default: the
@@ -233,9 +288,10 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
- **Header identity switcher** (`ui/switcher.rs`, Fractal's account-switcher
pattern): a `GtkMenuButton` showing the current identity's initials avatar,
opening a popover with one row per key (avatar, `display_name` or key label,
short npub, a check on the current), then "Manage identities…" (jumps to Keys).
Hidden on the **Keys** page and when there are no keys; rebuilds on key and
selection changes.
short npub, a check on the current), then "Manage identities…" (opens the
identities window). Hidden when there are no keys; rebuilds on key and selection
changes. Holds the `Windows` registry **weakly**: the main window owns the
switcher, so a strong reference would be a cycle.
- **Pages are scoped to the selected identity:** Apps lists only that identity's
approvals (the title names it) and its "Forget all" is scoped; Activity filters
to the identity and "Clear this identity's activity" keeps the rest. Pre-M7
@@ -359,11 +415,11 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
request the vault refused is logged as `locked` and never as `silent`/`allowed`
— the log must not claim an answer that was never produced. Never reintroduce
a `keys.get()` that runs after the record.
- UI: a header lock/unlock button (`app.lock`, `<primary>l`) reflecting state; the
Keys page owns the passphrase ("Change…"), the auto-lock `ComboRow` and "Lock
now", and its add/import dialogs carry the passphrase field (with a
confirmation only when that call *sets* the passphrase). Export needs the vault
open first (`with_unlocked`). The Signer page shows the lock state.
- UI: a header lock/unlock button (`app.lock`, `<primary>l`) reflecting state;
Preferences owns the passphrase ("Change…"), the auto-lock `ComboRow` and "Lock
now", and the identities window's add/import dialogs carry the passphrase field
(with a confirmation only when that call *sets* the passphrase). Export needs
the vault open first (`with_unlocked`).
- **Never log, print or put the passphrase in argv/env.** The passphrase is
`Zeroizing` where it crosses the vault and the headless path, and is dropped as
soon as the unlock lands; the GTK dialog fields hand it over as a plain
@@ -470,11 +526,16 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
1. In Blueprint, **property assignments end with `;`, child objects do not**. A
widget inside a slot (e.g. `[top] Adw.HeaderBar header_bar {}`) must *not* have
a trailing semicolon, or you get `error: Unexpected tokens`.
2. `blueprint-compiler batch-compile OUTPUT SOURCEDIR FILES…` preserves paths
relative to `SOURCEDIR`, so the custom_target must use `output: '.'`. A named
output dir silently produces `ui/ui/window.ui` and then
`glib-compile-resources` fails with "Failed to locate … in any source
directory".
2. Meson forbids a **path segment in a `custom_target`'s `output`**, and
`batch-compile OUTPUT SOURCEDIR FILES…` preserves paths relative to
`SOURCEDIR` — so the tempting `output: 'ui/window.ui'` fails outright
("Output … must not contain a path segment"), and the `output: '.'` workaround
makes the *directory* a target output, which then looks stale on every build
and makes ninja fail to clean it (`remove(…): Directory not empty`) whenever
the set of files changes. Compile one file per target instead
(`blueprint-compiler compile --output @OUTPUT@ @INPUT@`), so each `.ui` is a
real file output; the resource paths are then the plain file names
(`/org/kosmos/raucao/Regent/window.ui`).
3. The app aborts at startup with `Settings schema … is not installed` unless dev
runs set `GSETTINGS_SCHEMA_DIR=_build/data` (see the run recipes in
`README.md`).