Skip to content

feat(relay): let plugins keep NIP-AR community-scoped artifacts - #3827

Closed
LordMelkor wants to merge 9 commits into
block:mainfrom
LordMelkor:clod/community-artifacts
Closed

LordMelkor wants to merge 9 commits into
block:mainfrom
LordMelkor:clod/community-artifacts

Conversation

@LordMelkor

@LordMelkor LordMelkor commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This lets a plugin keep community-wide artifacts under NIP-AR community scope (spec; relay: draft block/buzz#9646). A relay that advertises NIP-11 artifacts.community_scope version 1 keeps kind-45010 revisions that carry a community tag and no h. It also keeps a per-type write policy, set with kind 9034. Today a plugin can't do either:

  • session.artifacts.sync throws on a filter without #h.
  • Nothing a plugin can reach carries the community id.
  • No route signs kind 9034, which the spec keeps off the artifact writer.

The app gains three things:

  1. A community sync. session.artifacts.sync({ artifact: "current", scope: "community", "#type": [type] }) takes exactly one #type and no #h. It has the same statuses as a channel sync.
  2. session.artifacts.communityId. It is present only when the relay advertises community scope, so a plugin can check it synchronously before it shows anything that needs community artifacts.
  3. session.artifacts.typePolicy. It is { read, set } for this community:
    • read(type, signal) returns { policy, revision }.
    • set({ type, policy, prev }, signal) signs one kind-9034 command as the viewer and publishes it once. It resolves { id, ok, message }, with the relay's answer when the host keeps it.

Kind-45010 community records need no new writer. configArtifactWriter already signs an h-less 45010, and snapshotRead already reads a head.

A plugin owns every feature built on this. A shared mention-groups plugin, in a separate repository, is the first consumer.

Why each change is in core, and why it is this small

The rule for each row: a change belongs in the app only if no plugin can do it with today's API, and then only in the smallest general form, one that names NIP-AR concepts and no feature.

Change Necessity: why a plugin can't do it today Minimality
artifact-community.ts (new): wire helpers for community id, type name grammar, 9034 template and validation, policy filter and parser Both hosts and the broker need the same NIP-AR checks. Without a shared module each one would carry a copy. NIP-AR names only, with no dependencies, so the broker imports it the way it already imports artifact-sync-filter.ts.
artifact-sync-filter.ts: accept scope: "community" with one #type The filter refuses any sync without #h on both hosts (artifact-sync.ts, relay-broker.mjs). One branch on a NIP-AR key. The existing limits apply to both forms.
native.ts, transport.ts, relay-broker.mjs: read artifacts.community_scope at connect The session carries no NIP-11 data. transport.scope is the relay origin, not the community UUID. One string, parsed the way the read-state community already is.
artifact-type-policy.ts (new) plus one route each in native.ts, transport.ts and relay-broker.mjs: a typed 9034 sign, publish and policy read configArtifacts refuses any kind but 45010, and relay_sign refuses 9034. The broker's /sign doesn't handle it. The policy answer is a JSON object, which parseEvents refuses. One NIP-AR operation through the existing typed-route mechanism that the community-wide 9035/9036 archive already uses. The sign, publish and outcome mapping live once, shared by both hosts.
channel_writes.rs, relay.rs: the native shape check for the 9034 route, and 9034 added to the /events refusal list The desktop host signs only shapes it validates itself. One match arm and one kind in an existing list. relay_sign keeps refusing 9034.
socket-requests.ts: treat a 9034 conflict: like the existing 40100 and 45010 compare-and-set refusals Without it, a stale prev is reported as an unconfirmed publish instead of the relay's refusal. One kind added to an existing list.
session.ts: communityId and typePolicy on session.artifacts A plugin's synchronous match(observation, context) gets only context.session, so the community gate has to live there. Two optional fields on an existing object, present only together and passed through from the transport.
docs/artifact-sync.md: one section Documents the contract and its boundary. One section in the existing artifact-sync doc.

Boundary. typePolicy acts with the viewer's authority, like the session's other administrative writers (memberAdministration, channelLifecycle): any plugin in an admin's session can change any type's write policy. The relay accepts the command only from a direct owner or admin. A per-plugin gated service would add a new service, a registration and a naming rule. That rule would block any plugin that governs several types, for no protection beyond what the relay already enforces.

Size

Measured against main (46a09dbfd) with git diff --numstat:

Added Removed
Production (TypeScript, broker, Rust without its inline tests) 394 21
Tests 818 4
Docs 10 0

The two largest pieces are artifact-community.ts (+145, the shared NIP-AR wire helpers) and the broker routes (+61).

FOUNDATION files touched: src/features/relay/session.ts, +11/-1: the two pass-through fields and one comment line. No other edited file carries the marker.

Testing

All runs were on a separate Linux machine at b2f6be14f:

Check Result
bin/node scripts/check-push.mjs (types and related tests) pass: 427 files, 12,912 tests
check-push.mjs --design pass
check-push.mjs --clippy pass
cargo test relay:: (at fce1bf43a; no Rust file changed after it) pass: 240 tests

New tests cover:

  • Every byte class of the type-name grammar, in TypeScript and Rust.
  • The 9034 template and validation, including community mismatch, nil UUID, prev and created_at bounds.
  • The community sync filter.
  • The broker's sign, publish and read routes, with their refusal mapping.
  • The native and browser set outcomes (accepted, rejected with the relay's reason, not sent, unconfirmed).
  • read refusing a malformed relay answer.

Not yet run: end to end against a relay that advertises community scope. The relay side is draft block/buzz#9646. This PR stays a draft until that test passes with the consuming plugin.

Merge order

This PR shares no files with #3726 or #2878. It is meant to land after them, with the plugin PR after it.

🤖 Generated with Claude Code

LordMelkor and others added 9 commits November 18, 2026 06:32
Add the dependency-free NIP-AR community-scope helpers that the desktop
host, the browser broker and the session share: NIP-11
`artifacts.community_scope` discovery, the exact kind-9034 type policy
command and its validator, the policy read filter and response parser,
and the relay's artifact type grammar.

Artifact sync now accepts a community filter (`"scope": "community"`
with exactly one `#type` and no `#h`); channel filters are unchanged.
A socket `conflict:` refusal of a 9034 command counts as proven
non-delivery, like other compare-and-set refusals.

The browser transport exposes `artifactCommunity` and
`artifactTypePolicy` when the broker reports a canonical community id:
the read posts `{type}` to `artifact-type-policy`, and the writer uses
the `artifact-type-policy-sign` and `-publish` routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The desktop transport reads NIP-11 `artifacts.community_scope` (only
when the relay lists `nip-ar`) and, for such a relay, offers
`artifactCommunity` with `artifactTypePolicy`: a signed `/query` read of
the community's per-type write policy, and a writer for the kind-9034
command bound to this community.

Kind 9034 goes only through the purpose-bound `relay_channel_sign` and
`relay_channel_publish` route `artifact-type-policy`, which accepts
exactly the four tags in order (a canonical non-nil community, the
relay's namespaced type grammar, `everyone` or `admins`, and `prev` of
"0" or a lowercase event id) with empty content. The generic `relay_sign`
keeps refusing 9034, so the artifact signer cannot set a policy, and raw
`/events` posts now refuse it like the other typed-route kinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The browser host's relay broker now reads NIP-11
`artifacts.community_scope` (only with `nip-ar` listed) and reports the
community as `artifactCommunity` in the session, so the browser
transport can offer community-scoped artifacts.

Kind-9034 type policy commands get their own `artifact-type-policy-sign`
and `-publish` routes, like identity archive requests: each accepts only
the exact command for the relay's advertised community, and the generic
sign and publish routes still refuse it. The `artifact-type-policy` read
accepts exactly `{type}` and sends the relay its own policy filter.

A socket publication refused with `restricted:`, `blocked:` or
`auth-required:` is now answered 403 with the relay's text, as the
relay's HTTP API does, instead of 503 unsent, so writers show it as a
refusal. Community artifact sync passes through the broker unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
…ession

`session.artifacts.communityId` is the community id the relay advertises
in NIP-11 `artifacts.community_scope`, and `session.artifacts.typePolicy`
reads and sets a type's write policy (NIP-AR kind 9034). Both are present
only when the transport provides the community and its policy route, so a
plugin can detect community artifacts synchronously.

`typePolicy.set` builds the exact 9034 command for the session's own
community, signs it once as the viewer and publishes it once. It resolves
with the command id and the relay's answer: the relay's refusal text when
the host keeps it, or an empty message after a transport failure. It
rejects only on a malformed change, a signing failure or an aborted signal.

The artifact sync guide describes the community sync filter, both fields
and their boundary: the policy capability acts with the viewer's
authority, like the session's other administrative writers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
A community sync filter with one `#type` outside the NIP-AR type
grammar passed `artifactSyncFilter` and reached the relay, which
closes the REQ as `invalid:`. The view then ended in status `error`
instead of the call throwing, while the policy helpers refused the
same type at the call site.

The community branch now checks the value with `artifactTypeName`,
the grammar the policy helpers already share, so every host refuses
it before the REQ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The desktop type policy route was tested with types made only of
lowercase letters, and its refusals all failed on a segment's first
character. Dropping the digit, `_` or `-` arm of the per-byte check,
or widening it to accept uppercase inside a segment, still passed.

The test now accepts types with digits, `_` and `-` (including a
hyphenated middle segment) and refuses uppercase or punctuation
inside a segment and a leading or trailing dot, matching the shared
TypeScript grammar's table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The broker answers a proven socket refusal starting with
`restricted:`, `blocked:` or `auth-required:` with 403, so the writer
sees the relay's refusal instead of an unconfirmed publication. Only
the first two prefixes were tested, so dropping `auth-required` from
the mapping still passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
Make the transport's artifactTypePolicy the plugin-facing read/set access
and build it in one helper shared by the native and broker transports, so
the session only passes it through. Move the set behavior tests to the
helper's own test file. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The Rust shape test named a feature in its sample type; it now uses
com.example.settings.item, as the other tests do.

Two refusal cases repeated checks that have one owner elsewhere:
- The broker route test sent three malformed policy commands. Wrong tag
  order and an extra tag are covered by artifact-community.test.ts and
  the Rust shape test, so it keeps only the other-community command,
  which proves the route binds to its relay's community.
- The access test rejected three malformed relay reads. The parser's
  own table covers them, so one row is kept to prove read uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Moved to #3838, so that the branch is in this repository.

@LordMelkor LordMelkor closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant