ui: name the common event kinds from a data table #13

Merged
raucao merged 2 commits from feat/event-kinds into main 2026-12-01 12:43:53 +00:00
8 changed files with 404 additions and 107 deletions

No files matched your search

+16
View File
@@ -13,6 +13,22 @@ the only place release notes are written.
## [Unreleased]
### Added
- Names for many more event kinds. The table moved out of the code into
`data/event-kinds.tsv` — one kind per line, with the standard that defines it —
and grew from around 80 kinds to more than 230, including the NIP-82 software
catalogue, Blossom authorisation, git-repository kinds a Zapstore-style client
asks for, and community NIPs such as Place Photos and Videos (kind 360). Kinds
not in the table keep a generic name.
### Changed
- A request's event kind now reads as a sentence-cased name and number
together: the approval dialog shows `Kind: Reaction (7)`, an Apps permission
row `Sign kind 7 (Reaction)`, and an activity entry
`Reaction (kind 7) — allowed silently`.
## [0.9.2] - 2026-12-01
### Changed
+22 -2
View File
@@ -1,7 +1,27 @@
# Regent — build metadata and UI resources (`data/`)
The `.desktop`, metainfo and GSettings templates, the app icons, and the
Blueprint sources under `data/resources/ui/`.
The `.desktop`, metainfo and GSettings templates, the app icons, the Blueprint
sources under `data/resources/ui/`, and the event-kind table.
## The event-kind table (`event-kinds.tsv`)
`data/event-kinds.tsv` is the single source of truth for the human names the UI
puts on event kinds (`src/ui/kind.rs` embeds it with `include_str!`). Naming a
new kind — or correcting a name — is a **data edit, not a code edit**. One kind
per line, tab-separated: `kind <TAB> name <TAB> spec`. `kind` is a `u16` or an
inclusive `A-B` range; `name` is the sentence-cased display string (rendered
`Repository state (30618)` in the approval dialog, `Sign kind 30618 (Repository
state)` in the Apps row, `Repository state (kind 30618)` in the Activity row);
`spec` names the standard that defines the kind and
is **documentary only** (the UI does not show it — it is there so provenance is
in the repo). Blank lines and `#` comments are ignored.
`kind.rs` parses the table once and panics on a malformed, duplicated or
overlapping row, so the `kind::tests::the_table_is_well_formed` test is the
guard: run `cargo test` after editing. The file is **not** installed — it is
compiled into the binary — but it is listed in the `cargo_build` `input:` list in
the root `meson.build`, so an edit triggers a rebuild (the "every source file
must be an input" rule applies to `include_str!`ed data too).
## Blueprint / Meson traps
+213
View File
@@ -0,0 +1,213 @@
# Regent's event-kind table: one kind per line, tab-separated.
#
# kind <TAB> name <TAB> spec
#
# `kind` a u16, or an inclusive `A-B` range for a documented block.
# `name` the display string, sentence-cased and concise; it is shown as
# `Repository state (30618)`, `Sign kind 30618 (Repository state)` or
# `Repository state (kind 30618)`. Keep names short -- they sit in a
# dialog field and in permission rows.
# `spec` the standard that defines the kind, kept for provenance. It is
# documentary only: the UI does not show it. `NIP-XX` for a NIP,
# otherwise the spec's own name (e.g. `Marmot`). A `(draft)` or
# `(deprecated)` suffix marks a proposal or an unrecommended NIP. A
# community NIP with no assigned number is cited by its title, with its
# nostr address on a `#` comment line above the row.
#
# Blank lines and lines starting with `#` are ignored. Kinds must not overlap; a
# malformed or duplicated line panics at first use and fails `cargo test`, which
# is the guard. Editing this file is all that naming a new kind takes.
#
# Sources: the NIPs repository's event-kind table (github.com/nostr-protocol/nips
# README.md) and the kind registry (github.com/nostr-protocol/registry-of-kinds).
# The NIP-82 software-catalog kinds follow the unmerged "Zapstore spec" proposal
# (nips pull request #2526), which is why they are marked (draft).
0 Profile metadata NIP-01, NIP-24
1 Text note NIP-10
2 Relay recommendation NIP-01 (legacy)
3 Follow list NIP-02
4 Encrypted direct message NIP-04 (deprecated)
5 Deletion request NIP-09
6 Repost NIP-18
7 Reaction NIP-25
8 Badge award NIP-58
9 Chat message NIP-C7
11 Thread NIP-7D
13 Seal NIP-59
14 Direct message NIP-17
15 File message NIP-17
16 Generic repost NIP-18
17 Website reaction NIP-25
20 Picture NIP-68
21 Video NIP-71
22 Short video NIP-71
24 Public message NIP-A4
30 Internal reference NKBIP-03
31 External web reference NKBIP-03
32 Hardcopy reference NKBIP-03
33 Prompt reference NKBIP-03
40 Channel creation NIP-28 (deprecated)
41 Channel metadata NIP-28 (deprecated)
42 Channel message NIP-28 (deprecated)
43 Channel hide message NIP-28 (deprecated)
44 Channel mute user NIP-28 (deprecated)
54 Podcast episode NIP-F4
62 Request to vanish NIP-62
64 Chess game NIP-64
78 Application data NIP-78
# Community NIP by Râu Cao: Place Photos and Videos (draft), defines kind 360.
# https://nostrhub.io/naddr1qvzqqqrcvypzq8meqkx80g3yuklzymy0qfx2ekk56aqc2ht4ak03z3em4r4cdcwtqqthqmrpvdjj6urgda6x7uedv9hxgttkd9jx2mmnl2q70n
360 Place media Place Photos and Videos (draft)
443 Key package Marmot
444 Welcome message Marmot
445 Group event Marmot
818 Merge request NIP-54
1018 Poll response NIP-88
1021 Bid NIP-15
1022 Bid confirmation NIP-15
1040 OpenTimestamps attestation NIP-03
1059 Gift wrap NIP-59
1063 File metadata NIP-94
1068 Poll NIP-88
1111 Comment NIP-22
1222 Voice message NIP-A0
1234 Draft checkpoint NIP-37
1244 Voice message comment NIP-A0
1311 Live chat message NIP-53
1337 Code snippet NIP-C0
1617 Patch NIP-34
1618 Pull request NIP-34
1619 Pull request update NIP-34
1621 Issue NIP-34
1622 Git reply NIP-34 (deprecated)
1630-1633 Status NIP-34
1971 Problem tracker nostrocket
1984 Report NIP-56
1985 Label NIP-32
1987 AI embedding NKBIP-02
2003 Torrent NIP-35
2004 Torrent comment NIP-35
2022 Coinjoin pool joinstr
3063 Software asset NIP-82 (draft)
4550 Community post approval NIP-72
5128 Nsite manifest snapshot NIP-5A
7374 Cashu wallet tokens (reserved) NIP-60
7375 Cashu wallet tokens NIP-60
7376 Cashu wallet history NIP-60
7516 Geocache log NIP-CC
7517 Geocache proof of find NIP-CC
8000 Add user NIP-43
8001 Remove user NIP-43
9000-9030 Group control event NIP-29
9041 Zap goal NIP-75
9321 Nutzap NIP-61
9734 Zap request NIP-57
9735 Zap NIP-57
9802 Highlight NIP-84
10000 Mute list NIP-51
10001 Pin list NIP-51
10002 Relay list NIP-65, NIP-51
10003 Bookmark list NIP-51
10004 Communities list NIP-51
10005 Public chats list NIP-51
10006 Blocked relays list NIP-51
10007 Search relays list NIP-51
10008 Profile badges NIP-51, NIP-58
10009 User groups NIP-51, NIP-29
10011 External identities NIP-39
10012 Favorite relays list NIP-51
10013 Private event relay list NIP-37
10015 Interests list NIP-51
10019 Nutzap mint recommendation NIP-61
10020 Media follows NIP-51
10021 Favorite follow sets NIP-51
10030 Emoji list NIP-51
10040 Trusted service providers NIP-85
10050 Direct message relay list NIP-51, NIP-17
10051 Key package relays list Marmot
10054 Favorite podcasts list NIP-51
10063 User server list NIP-B7
10064 Authored podcasts list NIP-51
10067 App catalog relays NIP-82 (draft)
10096 File storage server list NIP-96 (deprecated)
10133 Payment targets NIP-A3
10154 Podcast metadata NIP-F4
10166 Relay monitor announcement NIP-66
10312 Room presence NIP-53
10992 Installed slash commands NIP-51, NIP-CD
13194 Wallet info NIP-47
13534 Membership lists NIP-43
15128 Root nsite manifest NIP-5A
17375 Cashu wallet event NIP-60
21059 Ephemeral gift wrap NIP-59
22242 Client authentication NIP-42
23194 Wallet request NIP-47
23195 Wallet response NIP-47
24133 NIP-46 message NIP-46
24242 Blob authorization NIP-B7 (Blossom)
27235 HTTP auth NIP-98
28934 Join request NIP-43
28935 Invite request NIP-43
28936 Leave request NIP-43
30000 Follow sets NIP-51
30002 Relay sets NIP-51
30003 Bookmark sets NIP-51
30004 Curation sets NIP-51
30005 Video sets NIP-51
30006 Picture sets NIP-51
30007 Kind mute sets NIP-51
30008 Badge sets NIP-51, NIP-58
30009 Badge definition NIP-58
30015 Interest sets NIP-51
30017 Stall NIP-15
30018 Product NIP-15
30019 Marketplace ui NIP-15
30020 Auction NIP-15
30023 Long-form article NIP-23
30024 Draft article NIP-23
30030 Emoji sets NIP-51
30040 Publication index NKBIP-01
30041 Publication content NKBIP-01
30063 Software release NIP-82 (draft)
30078 Application data NIP-78
30166 Relay discovery NIP-66
30267 App curation sets NIP-51, NIP-82 (draft)
30311 Live event NIP-53
30312 Interactive room NIP-53
30313 Conference event NIP-53
30315 User status NIP-38
30382 User trusted assertion NIP-85
30383 Event trusted assertion NIP-85
30384 Addressable trusted assertion NIP-85
30402 Classified listing NIP-99
30403 Draft classified listing NIP-99
30509 Signing certificate link NIP-82 (draft)
30617 Repository announcement NIP-34
30618 Repository state NIP-34
30818 Wiki article NIP-54
30819 Wiki redirect NIP-54
31234 Draft event NIP-37
31922 Calendar event (date) NIP-52
31923 Calendar event (time) NIP-52
31924 Calendar NIP-52
31925 Calendar RSVP NIP-52
31989 Handler recommendation NIP-89
31990 Handler information NIP-89
31992 Slash command definition NIP-CD
32267 Software application NIP-82 (draft)
33534 Role definition NIP-43
34128 Legacy nsite manifest NIP-5A (deprecated)
34235 Video (addressable) NIP-71
34236 Short video (addressable) NIP-71
34550 Community definition NIP-72
35128 Named nsite manifest NIP-5A
37516 Geocache listing NIP-CC
37517 Geocache curation list NIP-CC
38000 Mint recommendation NIP-87
38172 Cashu mint announcement NIP-87
38173 Fedimint announcement NIP-87
38383 Peer-to-peer order NIP-69
39000-39009 Group metadata NIP-29
39089 Starter packs NIP-51
39092 Media starter packs NIP-51
39701 Web bookmark NIP-B0
Can't render this file because it contains an unexpected character in line 23 and column 57.
+3 -1
View File
@@ -42,12 +42,14 @@ subdir('data')
# Meson has no native cargo integration, so cargo is driven through a sh -c
# wrapper that also copies the binary to the location Meson expects. Every
# source file is listed as an input so edits trigger a rebuild.
# source file is listed as an input so edits trigger a rebuild -- including the
# non-Rust files `include_str!`/`include_bytes!` embeds (the event-kind table).
cargo_build = custom_target(binary_name,
output: binary_name,
input: files(
'Cargo.toml',
'Cargo.lock',
'data/event-kinds.tsv',
'src/main.rs',
'src/application.rs',
'src/config.rs',
+2 -2
View File
@@ -12,7 +12,7 @@ use libadwaita as adw;
use crate::state::AppState;
use crate::store::audit::{self, ActivityLog, Entry};
use crate::ui::plain;
use crate::ui::{kind, plain};
/// How many entries the page shows. The log keeps more.
const RECENT: usize = 100;
@@ -171,7 +171,7 @@ fn method_label(method: &str, kind: Option<u16>) -> String {
match method {
"connect" => "Pairing".to_string(),
"sign_event" => match kind {
Some(kind) => format!("Sign kind {kind}"),
Some(kind) => kind::activity_label(kind),
None => "Sign event".to_string(),
},
"nip04_encrypt" => "Encrypt (NIP-04)".to_string(),
+1 -4
View File
@@ -556,10 +556,7 @@ fn details(
kind, created_at, ..
} = &question.request
{
content.append(&plain::text_field(
"Kind",
&format!("{} ({})", kind, kind::name(*kind)),
));
content.append(&plain::text_field("Kind", &kind::label(*kind)));
content.append(&plain::text_field("Created at", &when(*created_at)));
}
+1 -1
View File
@@ -344,7 +344,7 @@ impl Ui {
));
} else {
for kind_number in &app.policy.kinds {
let title = format!("Sign kind {} ({})", kind_number, kind::name(*kind_number));
let title = kind::permission_label(*kind_number);
row.add_row(&self.permission_row(app, Permission::Kind(*kind_number), &title));
}
for method in &app.policy.methods {
+146 -97
View File
@@ -1,98 +1,97 @@
//! Human names for the common event kinds, shared by the dialogs and the
//! permission table.
//! Human names for the event kinds, shared by the dialogs and the permission
//! table.
//!
//! The table itself lives in `data/event-kinds.tsv` so that naming a kind (or
//! adding a new one) is a data edit, not a code edit. This module embeds that
//! file at compile time, parses it once into a map, and answers the callers. A
//! malformed, duplicated or overlapping line panics on first use and fails
//! `cargo test`, so the file cannot rot unnoticed.
use std::collections::HashMap;
use std::sync::LazyLock;
/// The embedded kind table. Tab-separated, one kind per line (`#` comments and
/// blank lines ignored); the first field is a `u16` or an inclusive `A-B`
/// range. See the file for the column meanings and the sources.
static TABLE: &str = include_str!("../../data/event-kinds.tsv");
struct Kind {
/// The display string, borrowed from `TABLE`.
name: &'static str,
/// The standard that defines the kind. Documentary only: the UI does not
/// show it (the tests read it, so the provenance cannot silently vanish).
#[allow(dead_code)]
spec: &'static str,
}
/// The parsed table, built once on first use.
static KINDS: LazyLock<HashMap<u16, Kind>> = LazyLock::new(|| {
let mut kinds: HashMap<u16, Kind> = HashMap::new();
for (index, raw) in TABLE.lines().enumerate() {
let line_no = index + 1;
let line = raw.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
let mut fields = line.split('\t').map(str::trim);
let range = fields.next().unwrap_or_default();
let name = fields.next().unwrap_or_default();
let spec = fields.next().unwrap_or_default();
let (first, last) = match range.split_once('-') {
Some((first, last)) => (first, last),
None => (range, range),
};
let parse = |value: &str| {
value
.parse::<u16>()
.unwrap_or_else(|_| panic!("{KIND_FILE} line {line_no}: bad kind {value:?}"))
};
let (first, last) = (parse(first), parse(last));
assert!(
first <= last,
"{KIND_FILE} line {line_no}: reversed range {range:?}"
);
assert!(!name.is_empty(), "{KIND_FILE} line {line_no}: missing name");
assert!(!spec.is_empty(), "{KIND_FILE} line {line_no}: missing spec");
for kind in first..=last {
assert!(
kinds.insert(kind, Kind { name, spec }).is_none(),
"{KIND_FILE} line {line_no}: kind {kind} defined twice"
);
}
}
kinds
});
/// The `include_str!` path, for the parser's assertions above.
const KIND_FILE: &str = "data/event-kinds.tsv";
/// A short, human name for the well-known kinds; a generic one otherwise.
///
/// Names stay lowercase and concise to read as a value (`10002 (relay list)`),
/// and cover the kinds a signer is actually asked for. Anything unknown is just
/// "event".
/// Names are sentence-cased and concise (`Reaction`, `Relay list`), and cover
/// the kinds a signer is actually asked for. Anything unknown is just "Event".
/// The three callers want the number in different places, so each has its own
/// formatter below rather than assembling the string at the call site.
pub fn name(kind: u16) -> &'static str {
match kind {
// Notes and social (NIP-01, 10, 18, 25, 68, 71, 7D).
0 => "profile metadata",
1 => "text note",
2 => "relay recommendation",
3 => "follow list",
4 => "encrypted direct message",
5 => "deletion request",
6 => "repost",
7 => "reaction",
8 => "badge award",
9 => "chat message",
11 => "thread",
16 => "generic repost",
17 => "website reaction",
20 => "picture",
21 => "video",
22 => "short video",
// Private messaging and wrapping (NIP-17, 59).
13 => "seal",
14 => "direct message",
15 => "file message",
1059 => "gift wrap",
1222 => "voice message",
// Channels (NIP-28).
40 => "channel creation",
41 => "channel metadata",
42 => "channel message",
43 => "channel hide message",
44 => "channel mute user",
// Replaceable lists (NIP-51).
10000 => "mute list",
10001 => "pin list",
10002 => "relay list",
10003 => "bookmark list",
10004 => "communities list",
10005 => "public chats list",
10006 => "blocked relays list",
10007 => "search relays list",
10008 => "profile badges",
10009 => "user groups",
10011 => "external identities",
10012 => "favorite relays list",
10013 => "private event relay list",
10015 => "interests list",
10030 => "emoji list",
10050 => "direct message relay list",
// Files, labels, reporting, zaps (NIP-32, 56, 57, 84, 94).
1063 => "file metadata",
1984 => "report",
1985 => "label",
9734 => "zap request",
9735 => "zap",
9802 => "highlight",
// Other common kinds.
62 => "request to vanish",
78 | 30078 => "application data",
1068 => "poll",
1111 => "comment",
1311 => "live chat message",
1337 => "code snippet",
1617 => "patch",
1618 => "pull request",
1621 => "issue",
1630..=1633 => "status",
22242 => "client authentication",
23194 => "wallet request",
23195 => "wallet response",
27235 => "HTTP auth",
30000 => "follow sets",
30003 => "bookmark sets",
30023 => "long-form article",
30024 => "draft article",
30311 => "live event",
30315 => "user status",
30402 => "classified listing",
30617 => "repository announcement",
30818 => "wiki article",
31922 => "calendar event (date)",
31923 => "calendar event (time)",
31924 => "calendar",
31925 => "calendar RSVP",
34550 => "community definition",
24133 => "NIP-46 message",
_ => "event",
}
KINDS.get(&kind).map_or("Event", |entry| entry.name)
}
/// The kind for the approval dialog's "Kind" field: `Reaction (7)`.
pub fn label(kind: u16) -> String {
format!("{} ({kind})", name(kind))
}
/// The kind for an Apps permission row: `Sign kind 7 (Reaction)`.
pub fn permission_label(kind: u16) -> String {
format!("Sign kind {kind} ({})", name(kind))
}
/// The kind for an Activity row, before the ` — <outcome>` suffix:
/// `Reaction (kind 7)`.
pub fn activity_label(kind: u16) -> String {
format!("{} (kind {kind})", name(kind))
}
/// A human label for a well-known content field, if we have one.
@@ -176,13 +175,63 @@ mod tests {
assert_eq!(field_group("something_odd"), None);
}
/// Well-known kinds get a name; anything unknown stays "event".
/// Well-known kinds get a name; anything unknown stays "Event". The range
/// arm is exercised through a member of `1630-1633`.
#[test]
fn well_known_kinds_are_named() {
assert_eq!(name(1), "text note");
assert_eq!(name(10002), "relay list");
assert_eq!(name(30023), "long-form article");
assert_eq!(name(1631), "status");
assert_eq!(name(65535), "event");
assert_eq!(name(1), "Text note");
assert_eq!(name(10002), "Relay list");
assert_eq!(name(30023), "Long-form article");
assert_eq!(name(1631), "Status");
assert_eq!(name(65535), "Event");
}
/// The kinds a Zapstore-style client asks for, which used to fall through to
/// the generic name.
#[test]
fn software_and_git_kinds_are_named() {
assert_eq!(name(3063), "Software asset");
assert_eq!(name(24242), "Blob authorization");
assert_eq!(name(30063), "Software release");
assert_eq!(name(30618), "Repository state");
assert_eq!(name(32267), "Software application");
}
/// A community NIP with no assigned number is named like any other; kind
/// 360 (Place Photos and Videos) is the first one in the table.
#[test]
fn community_kinds_are_named() {
assert_eq!(name(360), "Place media");
}
/// Each surface puts the number in its own place: the dialog leads with the
/// name, the permission row leads with "Sign kind", the activity row names
/// the kind in parentheses.
#[test]
fn each_surface_formats_the_kind_its_own_way() {
assert_eq!(label(7), "Reaction (7)");
assert_eq!(permission_label(7), "Sign kind 7 (Reaction)");
assert_eq!(activity_label(7), "Reaction (kind 7)");
// An unknown kind still reads sensibly in all three.
assert_eq!(label(65535), "Event (65535)");
assert_eq!(permission_label(65535), "Sign kind 65535 (Event)");
assert_eq!(activity_label(65535), "Event (kind 65535)");
}
/// Every row of the embedded table carries a name and a spec, so the
/// provenance column cannot quietly become empty.
#[test]
fn the_table_is_well_formed() {
// Touching `KINDS` runs the parser; a bad row panics there.
assert!(!KINDS.is_empty());
for (kind, entry) in KINDS.iter() {
assert!(!entry.name.is_empty(), "kind {kind} has no name");
assert!(!entry.spec.is_empty(), "kind {kind} has no spec");
}
assert!(
KINDS.len() > 150,
"the kind table shrank unexpectedly: {} kinds",
KINDS.len()
);
}
}