Repository navigation
Commit 114d40d
authored
feat(relay): gate kind 30178 team-catalog reads behind the shared tag (#3358)
Team catalog projections (`kind:30178`) embed every member's system
prompt, so they need the same read gate personas already have: only the
author sees an unshared event. The gate was hardcoded to `kind:30175` at
six read surfaces plus the SQL pushdown, so rather than adding a second
special case it becomes kind-generic over `SHARED_GATED_KINDS = {30175,
30178}`.
## Kind 30178
New parameterized-replaceable kind, addressed by `(pubkey_o, 30178,
team_id)`. It embeds sanitized member projections instead of referencing
`kind:30175` heads — a foreign reader of a shared team could not
otherwise hydrate members whose own persona events are unshared or, for
built-ins, absent entirely. `kind:30176`'s wire body is untouched, so
device sync keeps its contract.
## Kind-generic shared gate
`buzz_core::kind` replaces `is_persona_shared_kind` /
`is_unshared_persona_event` / `persona_event_is_shared` with
`SHARED_GATED_KINDS` and the kind-agnostic `is_shared_gated_kind` /
`is_unshared_gated_event` / `event_is_shared`. Every read surface
consults the set:
| Surface | File |
|---|---|
| REQ historical delivery + `ids` lookup |
`crates/buzz-relay/src/handlers/req.rs` |
| Live fan-out | `crates/buzz-relay/src/handlers/event.rs` |
| COUNT fallback | `crates/buzz-relay/src/handlers/count.rs` |
| NIP-98 HTTP `/query`, `/count`, `/search` |
`crates/buzz-relay/src/api/bridge.rs` |
| Pre-`LIMIT` SQL pushdown | `crates/buzz-db/src/event.rs` |
The SQL clause generalizes from `kind != 30175` to `kind NOT IN (...)`
bound from `SHARED_GATED_KINDS`, still applied before `ORDER BY … LIMIT`
so a page of newer private events cannot starve an older shared one off
the candidate set. `EventQuery::persona_reader` is renamed
`shared_gated_reader` and `needs_persona_filtering` to
`needs_shared_gate_filtering` to match.
Because the `buzz-core` rename has consumers outside the relay, the four
desktop call sites of `persona_event_is_shared` travel with it:
`desktop/src-tauri/src/commands/personas/pending.rs`,
`desktop/src-tauri/src/event_sync.rs`, and two in
`desktop/src-tauri/src/managed_agents/persona_events.rs`. Each call is
unchanged apart from the name — the persona `shared` projection behaves
exactly as before.
## Ingest validation
`validate_persona_envelope` splits into two reusable pieces —
`validate_shared_tag` (exactly-two-element `["shared","true"]`, at most
one occurrence) and `single_bounded_d_tag` (exactly one `d` tag,
non-empty, `<=64` chars, no ASCII control characters or whitespace).
`validate_team_catalog_envelope` composes both; personas additionally
keep the slug grammar `^[a-z0-9][a-z0-9_-]{0,63}$`.
`kind:30178` deliberately does **not** get the slug grammar. Team ids
are UUIDs or built-in identifiers such as `builtin-team:welcome`, and
the colon is not slug-legal; rewriting ids to fit would break NIP-33
addressing against the team's own `kind:30176` head. The non-empty and
exactly-one checks are load-bearing regardless — without them generic
NIP-33 storage maps a missing `d` onto `(pubkey_o, 30178, "")` and every
team overwrites its predecessor.
The exact two-element `shared` shape is enforced because the SQL
visibility clause is JSONB containment (`tags @>
'[["shared","true"]]'`), which would match a three-element superset such
as `["shared","true","extra"]`.
`kind:30178` is also added to the `Scope::UsersWrite` allowlist and to
`is_global_only_kind`, so a stray `h` tag cannot channel-scope an
owner-authored definition.
## Deferred
`kind:30176` is deliberately not a gate member. Its writers never emit
`shared`, so catalog opt-in semantics do not describe it — it needs
owner-private reads driven by an authenticated principal set, tracked as
a separate follow-up.
## Tests
- 19 new `ingest.rs` unit tests covering the 30178 envelope (UUID and
colon `d` tags, 64-char boundary, non-ASCII bound,
empty/valueless/duplicate/missing `d`, embedded newline, `shared`
false/three-element/duplicate, scope and global-only membership).
- Persona regressions for the valueless `["d"]` shapes, since the
`d`-tag helper is shared by both validators.
- Existing `kind.rs` gate tests generalized and extended to assert the
gate applies to 30178 as it does to 30175.
- New `crates/buzz-test-client/tests/e2e_team_catalog.rs`: 9 WS-level
tests over a live relay covering author reads of unshared heads, foreign
omission from REQ, `ids`-lookup denial, COUNT existence-leak, share and
unshare transitions, and the mixed-kind filter case.
- `.github/workflows/ci.yml` adds `--test e2e_team_catalog` to the Relay
E2E job so the new suite runs.
## Docs
`docs/nips/NIP-AP.md` gains a "Team catalog projection: kind:30178"
section and an "Ingest validation: kind:30178" subsection, records the
gate as kind-generic, documents 30178 deletion vs. unshare semantics,
and adds a security note that sharing a team exposes every member's
instructions even when that member's own `kind:30175` head is unshared.
Signed-off-by: Will Pfleger <[email protected]>1 parent b9e4ed6 commit 114d40d
14 files changed
Lines changed: 1033 additions & 179 deletions
File tree
- .github/workflows
- crates
- buzz-core/src
- buzz-db/src
- buzz-relay/src
- api
- handlers
- buzz-test-client/tests
- desktop/src-tauri/src
- commands/personas
- managed_agents
- docs/nips
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
739 | 739 | | |
740 | 740 | | |
741 | 741 | | |
742 | | - | |
| 742 | + | |
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
194 | 208 | | |
195 | 209 | | |
196 | | - | |
197 | | - | |
198 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
199 | 213 | | |
200 | 214 | | |
201 | 215 | | |
202 | | - | |
| 216 | + | |
203 | 217 | | |
204 | 218 | | |
205 | | - | |
| 219 | + | |
206 | 220 | | |
207 | | - | |
| 221 | + | |
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
211 | 225 | | |
212 | 226 | | |
213 | 227 | | |
214 | 228 | | |
215 | | - | |
| 229 | + | |
216 | 230 | | |
217 | 231 | | |
218 | 232 | | |
219 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
220 | 239 | | |
221 | 240 | | |
222 | 241 | | |
223 | 242 | | |
224 | 243 | | |
225 | 244 | | |
226 | | - | |
| 245 | + | |
227 | 246 | | |
228 | 247 | | |
229 | 248 | | |
| |||
258 | 277 | | |
259 | 278 | | |
260 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
261 | 308 | | |
262 | 309 | | |
263 | 310 | | |
| |||
586 | 633 | | |
587 | 634 | | |
588 | 635 | | |
| 636 | + | |
589 | 637 | | |
590 | 638 | | |
591 | 639 | | |
| |||
784 | 832 | | |
785 | 833 | | |
786 | 834 | | |
| 835 | + | |
787 | 836 | | |
788 | 837 | | |
789 | 838 | | |
| |||
858 | 907 | | |
859 | 908 | | |
860 | 909 | | |
861 | | - | |
| 910 | + | |
862 | 911 | | |
863 | | - | |
| 912 | + | |
864 | 913 | | |
865 | 914 | | |
866 | 915 | | |
867 | 916 | | |
868 | 917 | | |
869 | 918 | | |
870 | | - | |
| 919 | + | |
871 | 920 | | |
872 | 921 | | |
873 | 922 | | |
874 | 923 | | |
875 | 924 | | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
876 | 929 | | |
877 | | - | |
| 930 | + | |
878 | 931 | | |
879 | | - | |
| 932 | + | |
880 | 933 | | |
881 | 934 | | |
882 | 935 | | |
883 | | - | |
| 936 | + | |
884 | 937 | | |
885 | | - | |
| 938 | + | |
886 | 939 | | |
887 | 940 | | |
888 | 941 | | |
889 | | - | |
| 942 | + | |
890 | 943 | | |
891 | | - | |
| 944 | + | |
892 | 945 | | |
893 | 946 | | |
894 | 947 | | |
895 | | - | |
| 948 | + | |
896 | 949 | | |
897 | 950 | | |
898 | 951 | | |
899 | | - | |
| 952 | + | |
900 | 953 | | |
901 | 954 | | |
902 | 955 | | |
903 | | - | |
| 956 | + | |
904 | 957 | | |
905 | 958 | | |
906 | 959 | | |
907 | | - | |
| 960 | + | |
908 | 961 | | |
909 | 962 | | |
910 | 963 | | |
911 | | - | |
| 964 | + | |
912 | 965 | | |
913 | 966 | | |
914 | | - | |
| 967 | + | |
915 | 968 | | |
916 | 969 | | |
917 | 970 | | |
918 | | - | |
| 971 | + | |
919 | 972 | | |
920 | 973 | | |
921 | 974 | | |
| |||
924 | 977 | | |
925 | 978 | | |
926 | 979 | | |
927 | | - | |
| 980 | + | |
928 | 981 | | |
929 | 982 | | |
930 | 983 | | |
931 | | - | |
| 984 | + | |
932 | 985 | | |
933 | 986 | | |
934 | | - | |
| 987 | + | |
935 | 988 | | |
936 | 989 | | |
937 | 990 | | |
938 | | - | |
| 991 | + | |
939 | 992 | | |
940 | 993 | | |
941 | | - | |
| 994 | + | |
942 | 995 | | |
943 | 996 | | |
944 | 997 | | |
945 | | - | |
| 998 | + | |
946 | 999 | | |
947 | 1000 | | |
948 | 1001 | | |
949 | 1002 | | |
950 | 1003 | | |
951 | 1004 | | |
952 | | - | |
953 | | - | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
954 | 1058 | | |
955 | 1059 | | |
0 commit comments