feat(calendar): NIP-52 compliance — effective end, reference facets, educational attributes, Typesense routing #25

Merged
laoc merged 12 commits from feat/calendar-nip52-end-and-attributes into main 2026-11-03 22:13:16 +00:00
Owner

NIP-52 compliance for the calendar content type, found while aligning the relay with the updated edufeed calendar wiki ("Calendar events in edufeed", 2026-11-03) and edufeed-app v0.14. Reviewed in seven passes incl. four independent adversarial reviews; every finding has a test.

End semantics: docs and the Bolt index store the NIP-52 effective end (end-less 31923 = instantaneous, end-less or legacy inclusive-end 31922 = one day). Before, #end_after silently dropped every one-day and instantaneous event (10 of 123 upcoming all-day events on prod). end_after is strict because end is exclusive.

Reference tags: #a, #p, #e, #r, #l, #L were mapped to fields the calendar schema never declared — verified on prod: "RSVPs for event X", "calendars listing X", "events with participant Y" all returned 0. All are facets on every calendar kind now; #status, #fb, #currency too.

Educational attributes (NIP-52-Edufeed): registrationRequired, price+currency, eventAttendanceMode, named participants (searchable), D days as facets, read with exactly the rules of edufeed-app's calendar-attributes.js. All location tags searchable.

Routing: pure time ranges and calendar searches go to Typesense (BoltDB's planner silently dropped tag clauses beyond two; the chunk-rerank detour stripped the window before the lexical fetch and re-matched attributes raw — it is gone, calendar is chunked: false). Bolt serves geohash-prefix only; geohash + search post-filters a full page. NIP-45 COUNT follows every split so it agrees with REQ.

Validation: deprecated name accepted, unparseable/signed-plus start/end and end < start rejected, RSVP a must reference a 31922/31923 coordinate, first occurrence judged like every reader.

Deploy: Init adds the schema fields; run a NIP-86 reindex afterwards so existing docs get end and the new facets and the Bolt index drops its end = 0 entries. go.mod pins nostrlib PR #34's head; re-pin to the merge commit after it lands. calendar_typesense_test.go covers every documented query shape against a live Typesense (TS_TEST_HOST/TS_TEST_APIKEY).

🤖 Generated with Claude Code

NIP-52 compliance for the calendar content type, found while aligning the relay with the updated edufeed calendar wiki ("Calendar events in edufeed", 2026-11-03) and edufeed-app v0.14. Reviewed in seven passes incl. four independent adversarial reviews; every finding has a test. **End semantics**: docs and the Bolt index store the NIP-52 *effective* end (end-less 31923 = instantaneous, end-less or legacy inclusive-end 31922 = one day). Before, `#end_after` silently dropped every one-day and instantaneous event (10 of 123 upcoming all-day events on prod). `end_after` is strict because `end` is exclusive. **Reference tags**: `#a`, `#p`, `#e`, `#r`, `#l`, `#L` were mapped to fields the calendar schema never declared — verified on prod: "RSVPs for event X", "calendars listing X", "events with participant Y" all returned 0. All are facets on every calendar kind now; `#status`, `#fb`, `#currency` too. **Educational attributes** (NIP-52-Edufeed): `registrationRequired`, `price`+`currency`, `eventAttendanceMode`, named `participant`s (searchable), `D` days as facets, read with exactly the rules of edufeed-app's `calendar-attributes.js`. All `location` tags searchable. **Routing**: pure time ranges and calendar searches go to Typesense (BoltDB's planner silently dropped tag clauses beyond two; the chunk-rerank detour stripped the window before the lexical fetch and re-matched attributes raw — it is gone, calendar is `chunked: false`). Bolt serves geohash-prefix only; geohash + search post-filters a full page. NIP-45 COUNT follows every split so it agrees with REQ. **Validation**: deprecated `name` accepted, unparseable/signed-plus `start`/`end` and `end < start` rejected, RSVP `a` must reference a 31922/31923 coordinate, first occurrence judged like every reader. **Deploy**: Init adds the schema fields; run a NIP-86 `reindex` afterwards so existing docs get `end` and the new facets and the Bolt index drops its `end = 0` entries. `go.mod` pins nostrlib PR #34's head; re-pin to the merge commit after it lands. `calendar_typesense_test.go` covers every documented query shape against a live Typesense (`TS_TEST_HOST`/`TS_TEST_APIKEY`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
laoc added 11 commits 2026-11-03 22:06:16 +00:00
End rules: the Typesense doc stored `end` only when the event carried the
tag, so an end-less 31923 (ends instantaneously per NIP-52) and an end-less
31922 (a one-day event; `end` is exclusive and omitted) never matched an
`#end_after` bound — "ongoing or upcoming" silently dropped every one-day
event (10 of 123 upcoming all-day events on prod, 2026-11-03). Legacy
writers (edufeed-app up to v0.13.0) put the inclusive last day in `end`, so
`end == start` was cut off at 00:00 UTC of the day itself. nostrToCalendar
now stores nip52.EffectiveEnd (nostrlib fix/nip52-effective-end), the same
rule the Bolt range index applies, so both query paths agree.

Educational attributes (NIP-52-Edufeed, wiki "Calendar events in edufeed",
tag names fixed 2026-07-06) become facets with the wiki's read rules —
first tag wins, absent = no statement: registrationRequired (literal
true/false), price (normalised amount, string facet) + currency
(upper-cased), eventAttendanceMode (http:// and bare terms normalised to
the https://schema.org URI). Named `participant` tags are a searchable
`participants` facet; `D` tags are a `days` facet. calendarTagFields maps
#registrationRequired/#price/#eventAttendanceMode/#participant/#D, which
previously hit the query builder's fail-closed default and returned
nothing. The schema invariant in facet_filters_test now also accepts
scalar string facets, since `field:=[a,b]` is valid on both.

Deploy note: Init adds the new schema fields; run a NIP-86 reindex so
existing docs get values and the Bolt index drops its end=0 entries.
Requires the nostrlib bump (follow-up commit once the nostrlib PR lands).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Verified on prod 2026-11-03: `#a`, `#p` and `#e` over the calendar kinds
returned 0 for values that exist, because the calendar schema declared no
field for them — the shared query builder maps them to nostr_a/nostr_p (and
`#e` had no mapping), which the collection never carried. NIP-52 leans on
exactly these tags: RSVPs answer an event by `a` (+ optional `e` revision,
`p` author), calendars list their events by `a`, events ask for calendar
inclusion by `a` and name participants by `p`. All three are now string[]
facets filled on every calendar kind, so "who RSVP'd to X", "which
calendars list X" and "events with participant Y" work.

Also per spec: RSVP `fb` (free/busy) is a facet, dropped when the status is
declined; every `location` tag (the tag is repeated) is searchable via
`locations`, `location` keeps the first; the deprecated `name` tag is
accepted as the title (nostrlib nip52 falls back to it). Validation rejects
an unparseable `start`/`end` with a kind-specific message instead of
storing an unindexable event (YYYY-MM-DD without rollover dates for 31922,
unix seconds for 31923); an `end` at or before `start` stays tolerated
(legacy inclusive end). An RSVP's `a` must reference a 31922/31923
coordinate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Same class as the nostr_a/nostr_p finding: the shared query builder maps
#r → references and #l/#L → nostr_l/nostr_L by default, but the calendar
collection declared none of them, so those filters answered 0 for every
value. `r` is a NIP-52 common tag (links); NIP-32 labels are written on
calendar events by importers such as RPI. All three are now string[]
facets filled on every calendar kind, mirroring the AMB collection.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Pure time-range queries (no geohash) now go to Typesense instead of the
Bolt index. BoltDB's planner narrows on at most two tags and silently
drops further tag clauses, so a range plus #price plus #eventAttendanceMode
came back wider than asked (nostrlib's CalendarStore now re-checks the
filter, but the Bolt path still matches RAW tag values); Typesense applies
every clause and matches attribute values in their normalised form
(`#price:0` finds a "0,00" tag), with start/end as int64 facets using the
effective end. The Bolt index serves geohash-prefix queries only.
`end_after` is strict there and in Typesense (NIP-52 `end` is exclusive).

calendarTagFields maps #status, #fb and #currency (declared facets that
previously hit the query builder's fail-closed default). parsePriceTag
rejects NaN/Inf. validateCalendar rejects `end` before `start` for both
kinds (NIP-52: start must be less than end); `end == start` stays
tolerated (legacy inclusive end, instantaneous event).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The calendar content type counted with tsDB4.CountEvents for every
filter, but `#g` is unmapped on Typesense and fails closed, so COUNT
answered 0 for a geohash query while REQ (served by the Bolt prefix
index) returned events. calendarCount mirrors calendarFetch: a geohash
query counts the Bolt fetch, everything else is counted by Typesense with
the identical filter_by; an unsatisfiable bound counts 0 like the empty
REQ.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The chunk-rerank route that serves a free-text search plus a time window
(calendarRerankQuery → inCalendarWindow) still read the RAW `end`, failed
every end bound for an end-less event and used an inclusive end_after, so
"mathematik, ongoing or upcoming" dropped every one-day and instantaneous
event that the same REQ without a search term returned. The window now
uses nip52.EffectiveEnd and the same bounds as the Typesense and Bolt
paths (strict end_after).

A geohash query with a search term went to Bolt, which ignores `search`
— the relay answered a wider question than asked. It now runs the
Typesense search without `#g` and post-filters the page by geohash
prefix; calendarCount follows, so COUNT and REQ agree on that shape too.

Validation: an RSVP's required `a` may be any `a` tag referencing a
31922/31923 coordinate, not only the first; `title` (or deprecated
`name`) must be non-empty for events and calendars. The stale
content_registry comment ("calendar events are not chunked") is
corrected; CLAUDE.md describes the three routes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Skips without TS_TEST_HOST/TS_TEST_APIKEY. Covers the effective end and
strict end_after on real docs, normalised attribute facets, D/participant/
p/a/e/status/fb/currency filters on all four kinds, NIP-50 field syntax,
full text over the second location and a speaker name, and COUNT vs REQ.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The chunk-rerank detour for calendar searches (calendarRerankQuery +
windowCalendar/inCalendarWindow) stripped the time window before the
lexical Typesense fetch — recall capped by the text top-200 page, so
"Fortbildung next week" could miss events Typesense's filter_by finds —
re-matched attribute tags against raw values (`#price:0` missed a "0,00"
tag whenever a search term was present) and let 31924/31925 through a
windowed query. Calendar events are not chunked by amb-indexer, so the
detour bought nothing: calendar is now registered chunked:false and a
calendar-only search goes straight to Typesense, which applies the term,
the window and the normalised facets in one query. A mixed filter that
names calendar kinds is restricted to the event kinds and served plainly
when it carries a window or geohash. windowCalendar/inCalendarWindow are
gone.

Geohash + search post-filters a FULL Typesense page (250) and then caps
to the client's limit — the top-`limit` text hits may all lie outside the
geohash; calendarCount counts that page (a maxLimit of 0 asked Typesense
for per_page 0 and always counted 0). `#g:[""]` fails closed.

Attribute read rules now match edufeed-app's calendar-attributes.js
exactly: the first VALID tag wins (an invalid one does not shadow), the
price grammar is a plain decimal (no exponents/hex/leading dot), the
attendance mode is trimmed and read by its last path segment with unknown
terms as no statement, an empty educationalLevel:id is skipped, and RSVP
status/fb are first-wins like the validator and the app.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A 31923 start/end is digits with an optional minus; strconv.ParseInt also
took a leading '+', which the MCP and the app do not parse, so such an
event indexed here showed no usable time downstream. Concept ids are
trimmed like the app does. CLAUDE.md now gives the real NIP-50 form for
the concept facets (`educationalLevelId:<uri>`; `educationalLevel🆔…`
parses as field `educationalLevel` and is dropped as unknown).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chore(deps): pin nostrlib to the NIP-52 branch (ad6b78e) for the standalone build
All checks were successful
Build and Push Docker Image / build (pull_request) Successful in 1m5s
31c446ebfe
GOWORK=off go build . and go test pass against the pinned pseudo-version.
Re-pin to the merge commit once nostrlib PR #34 lands.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chore(deps): pin nostrlib to the merge of PR #34 (v0.0.0-20261103221136-e3ceb20b46cf)
All checks were successful
Build and Push Docker Image / build (pull_request) Successful in 51s
69d173b5d4
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
laoc merged commit bccbb78cf2 into main 2026-11-03 22:13:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
edufeed/amb-relay!25
No description provided.