Skip to content

feat(composer): one chip for several recipients, sent as @label - #2878

Closed
LordMelkor wants to merge 5 commits into
block:mainfrom
LordMelkor:clod/team-mentions-people
Closed

LordMelkor wants to merge 5 commits into
block:mainfrom
LordMelkor:clod/team-mentions-people

Conversation

@LordMelkor

@LordMelkor LordMelkor commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A completion row can insert one chip for several people. A mentions edit that adds a label inserts one @label chip. Each listed person becomes a recipient of the message, and the message carries the chip as the plain text @label, with one p tag per person. Nothing else goes on the wire: no link, no new tag, no new event field. A blank or non-string label drops the row before it is shown.

  • In Markdown code only the text @label goes in, and no one is notified, as with mentions.
  • While editing a sent message only the text @label goes in, because an edit adds no recipients.
  • Removing recipients (removeRecipient, replaceRecipients) keeps the chip with the people left. With no one left it is plain text.
  • Typing onto the label (a letter right after @label) turns the chip into text, as it does for a person's chip. A link added around the chip keeps it and its recipients, as it does for a person's chip.
  • The chip is the shared chip (InlineChip), shown as @crew · 2. Its accessible name names the recipients: "Person crew, 2 recipients: Ann, Bo".
  • Drafts keep the chip's recipients when restored, from the saved document or from text plus recipients. A restored recipient must sit on exactly the text @label, followed by a mention boundary.
  • The 32-recipient cap counts distinct people, and a send names each person once, so a person in two chips counts once.
  • Namesakes: a mention that shares a name with one of a chip's recipients is sent qualified (@Name (<hex>)), as namesake mentions already are, so readers can tell which person it names.
  • Solo chat titles drop a leading @label whole, as they drop a leading person tag, even when the label starts with a member's name.

Readers need no change: the sent message is ordinary text plus the existing recipient tags. Readers show @label as plain text, so the label has no click target in the timeline.

This replaces two earlier versions of this PR. The first had saved teams insert one @team chip, which put a feature in core. The second sent the chip as a Markdown link to a plugin page, which made the wire form depend on a link format. This version is only the general hook a plugin needs to own such a feature (see the rule below), and it sends the chip the same way a person's chip is sent.

Why this is in core (Necessity and Minimality)

Features belong in plugins, and core gets only the smallest general capability a plugin needs. This is the rule in this repository's AGENTS.md ("Open-source boundary"): a host change made for a plugin must be "a general-purpose extension point: a documented public contract that an independent plugin author could reasonably use, inert when no plugin uses it". The table measures each change two ways. Necessity: a plugin can't do it with today's API. Minimality: it is the smallest general hook any plugin could use.

Change Necessity: a plugin can't do this today Minimality: the smallest general hook
label on the mentions edit (contracts.ts, completion.ts) A completion edit inserts text, one mention, or mentions, which become one @name chip per person (insertMentions in MessageComposer.tsx on the base). No edit gives one chip for several people. One optional field on the existing edit. No new edit kind and no new registration API.
One token, several recipients (composer-document.ts, mention-draft.ts) A token holds at most one recipient (the recipient attribute in composer-document.ts on the base). One group attribute on the existing token. Its source is the text @label, as a person chip's source is @name, so composer-markdown.ts sends it unchanged. A draft recipient gains an optional label, so a restored draft keeps recipients only on the exact text @label.
Insert at the completion range (EditableInput.tsx, composer-dom.ts, MessageComposer.tsx) insertText, the insert that person chips use, takes one person or a list of people, and each person becomes their own chip. The existing method's recipient argument also accepts { label, members }. It reuses that method's range, code, cap and length rules, and the editor keeps a group token on the same terms as a person token. The edit and availability rules are the existing mention rules.
Chip view (RichComposerInput.tsx) A token with recipients is drawn as one person's chip. The shared chip (InlineChip) with the label and a · N qualifier whose accessible label names the recipients. No new chip component.
Distinct people (mention-draft.ts, MessageComposer.tsx, NewMessage.tsx, composer-markdown.ts) Once several chips can name the same person, counting spans would refuse drafts with fewer than 32 people, a send would name a person twice, and a namesake among a chip's recipients would leave a typed @Name that readers can't bind. Count and send distinct people, and count a chip's recipients in the existing namesake check.
Solo chat title (src/features/solo/chat-title.ts) Core names a new Solo chat from its first message and drops the leading tags by matching each recipient's @name. A chip's recipients share one @label span, so the title kept the label, or cut it after a member's name. A plugin can't change how core names a chat. Match a recipient on @label when it has one, and count a shared span once. Two lines; no new API.

FOUNDATION: src/features/conversation/contracts.ts is the only FOUNDATION file this PR edits: one new arm of the existing completion edit type, with a label. The PR's author, who directs this work, gave the human guidance for this edit.

Merge order

This PR is stacked on #3726 (plugin @ rows). The base stays main so the earlier review history stays here, so until #3726 merges this diff also shows #3726's commits. This PR's own changes are the last two commits, 4e108350d and fe32d1096. Merge it after #3726.

Validation

Follow-up at fe32d1096: a group chip's label is now protected like a person's name when the message is turned into Markdown. Before, in a paragraph with formatting, an italic group chip was sent as _@eng\_ios_ and a * in a label was escaped (@eng\*ops), so a reader of the raw text could not match the label. Now both are sent the way a person chip is (*@eng\_ios*, @eng*ops). The new test in composer-document.test.ts fails on 4e108350d and passes here. On a separate Linux machine at fe32d1096: the push lanes pass (types and related tests: 315 files, 10,939 passed, 6 skipped; design; Clippy). The end-user run below is from 4e108350d.

At HEAD 4e108350d87e655eb3712d3d1216abe2fb83f6e4, on a separate Linux machine:

  • Types and lint: tsc --noEmit and tsc -p tsconfig.design.json are clean. pnpm lint and biome format pass.
  • Push lanes: check-push.mjs (types and related unit tests): 316 related files (315 passed, 1 skipped), 10,938 tests passed and 6 skipped, none failed. check-push.mjs --design passes. The Clippy lane has no Rust inputs to check.
  • Changed areas: src/features/solo/, src/features/conversation/, src/features/messages/ and src/features/direct-messages/: 151 files and 3,865 tests pass.
  • Fail-before for the title test: with chat-title.ts from the previous head (bc958b60c), the new title test fails (the title is 's team @Scout do X, not do X; 1 failed, 7 passed). At this head all 8 tests in chat-title.test.ts pass.
  • Tests for this change: 8 cases in EditableInput.test.tsx (one chip whose span names every member; text only in a code block; members kept through edits and through both restores, and plain text without them; removing members; replacing recipients; members kept inside a new link; a letter typed onto the label notifies no one; the distinct-people cap), 6 in MessageComposer.test.tsx (the sent text is @Crew @Honey (<hex>) with each member tagged once; text only in Markdown code; text only in a message edit; an unavailable member adds nothing; one reference per person outside a DM; Solo tag order), 2 in mention-draft.test.ts (recipients only on the exact @label with a boundary; the distinct-people cap), 1 in completion.test.ts (a blank or non-string label drops the row) and 1 in chat-title.test.ts (a leading @label is dropped whole, then the next person tag, even when the label starts with a member's name). Five existing tests changed, because the cap and the send now count distinct people: "rejects adding a recipient when retained duplicate mentions fill the limit" becomes "counts a person mentioned many times once against the recipient limit" (EditableInput.test.tsx); in MessageComposer.test.tsx, "qualifies both namesakes retroactively…" and "prefills only exact selected agents after an accepted send" now expect each person tagged once, and "rejects overlong and over-limit tool edits…" and the 32-recipient refusal case fill the cap with 32 different people instead of one person 32 times.
  • Agent review: an independent review of the previous head found no blockers. Its optional points: picking the row inside a link or literal text inserts only the text (a known limit below); a label is checked only for being non-blank, as a person's name is; a Solo chat title stripped a leading person tag but not a leading @label; and more negative restore cases could be tested. The Solo title point is fixed at this head (chat-title.ts). A second independent review of that fix found no defects. It checked a group after a person tag, a one-member group, a namesake qualifier and a label with Markdown characters. Its optional points were more test cases and a stricter guard if spans could ever overlap in part. Nothing else changed.
  • Not re-run at this head: the other fail-before checks with production files reverted, the mutation checks, and the in-app browser run. They ran on the earlier link form. The code paths for removing and replacing recipients, the cap and the send are the same; the insert, the token's validity and the chip's view changed.

Known limits

  • Readers show @label as plain text, so it has no click target. If the label matches the name of one of its members (mobile readers ignore case), readers that bind a bare @Name to the one tagged key with that name show it as that member's mention.
  • A chip inside a code block is only text: the recipient mark that keeps a person in code holds one person, so a chip's members are not kept there.
  • Picking the row inside a formatted link, or inside literal text, inserts only the text @label, as it does in code. A chip already in the draft keeps its members when a link is added around it.
  • Picking the row when @cr is a whole inline code span (`@cr`) inserts plain @crew without code formatting, because the shared insert (EditableInput.tsx) takes formatting from the start of the text it replaces. A code block keeps its formatting.

End-user test (AGENTS.md step 3)

An end-user test by the PR author's agent on a separate Linux machine, in two runs. Each run merged the three hooks, #3725, #3726 and #2878, into one test branch, so one run covers all three.

Both runs used:

  • Relay: a real local relay, which adds the relay records the plugin writes.
  • App: the Linux desktop app (debug build) under Xvfb, driven by WebDriver (tauri-driver). 63 throwaway identities were seeded as community members.
  • Plugin: an external mention-groups plugin that uses all three hooks, installed from a folder through Settings → Manage plugins → Add.

Every step was scripted and has screenshots. All passed.

  1. Install (feat(plugins): sign manifest-declared relay kinds and read relay info #3725): the review lists "Publish events of kind 47000 as you", and the same for 47001 and 47002. (In the second run, at feat(plugins): sign manifest-declared relay kinds and read relay info #3725's newer head, it lists the plugin's own purpose for each kind, such as "Sign and send as you: Create or edit a mention group".)
  2. relayInfo (feat(plugins): sign manifest-declared relay kinds and read relay info #3725): the plugin found the relay's support in its NIP-11 document, so its settings card loaded the community's groups.
  3. publish (feat(plugins): sign manifest-declared relay kinds and read relay info #3725): creating a group with 4 people and 1 agent signed and sent a kind 47000 event. The relay's state for the group shows version 1 with 5 members. A rename (47000 again) and a delete (47001) were also accepted.
  4. @ rows (feat(composer): let completion providers add rows beside the caret owner #3726): typing @mrm shows Buzz's people rows, then the plugin's "Groups" section with mrm, "4 people, 1 agent". ArrowDown moves from the people rows into the group row. Enter alone takes the first row, a person, in Buzz's order. Space leaves plain text and picks no one.
  5. Chip (feat(composer): one chip for several recipients, sent as @label #2878): the group mrm has 5 members, the sender among them. A WebDriver click on its row inserted one chip, @mrm · 4. It is drawn as a mention chip (the shared InlineChip, as a person's chip), not a link, and its accessible name is "Person mrm, 4 recipients: Mara Ruiz, Mrm Ortega, Mrm Review Bot, Miles". After the draft was cleared, typing @mrm, pressing ArrowDown four times to reach the group row, and pressing Enter inserted the same single chip.
  6. Send (feat(composer): one chip for several recipients, sent as @label #2878): typing please review the deck and pressing Enter sent a kind 9 event, read back from the relay. Its content is @mrm please review the deck, with no link and no buzz:// URL. Its p tags are the 4 other members, once each (Mara Ruiz, Mrm Ortega, Mrm Review Bot, Miles), and the sender is not tagged. Its only other tags are h, client-id and ms. The timeline shows @mrm please review the deck as plain text, with no link in the message. After the send, the next draft starts with @Mrm Review Bot, the group's agent member. That is the existing follow-up rule (rememberedMentions in remembered-mentions.ts), which keeps the agents a sent message notified.

Not covered: a control run on main (there, Buzz refuses this plugin's manifest at install, because main doesn't know host.relayKinds; this is from the code, not a run), a Solo chat title in the app (the unit test and its fail-before above cover it), a second app instance, and the macOS app.

The screenshots are from the second run, at this head. The first run's install review is here.

@mrm: people rows, then the plugin's group One chip, picked by a click
Buzz's people rows, then a Groups heading with mrm, 4 people, 1 agent The composer holds one mention chip, @mrm · 4
ArrowDown reaches the group row One chip, picked by Enter
The group row mrm is selected below the people rows The composer holds one mention chip, @mrm · 4
Before sending The sent message
The chip @mrm · 4 followed by please review the deck The timeline shows @mrm please review the deck as plain text

Try it yourself

Run this branch (just desktop). The test uses a small unsigned plugin, built like the ones in examples/plugins. Make a folder with these two files:

manifest.json

{ "id": "example.group-chip", "name": "Group chip example", "apiVersion": 1 }

plugin.js

export const inject = ["react", "conversation"];

export function apply(ctx) {
  const React = ctx.react;
  ctx.conversation.registerCompletion({
    id: "crew",
    title: "Groups",
    order: -20,
    supplement: true,
    match: ({ text, start }) => {
      const at = text.lastIndexOf("@", start - 1);
      const query = text.slice(at + 1, start);
      return at >= 0 && !/\s/.test(query) ? { start: at, end: start, query } : null;
    },
    component: function Crew({ query, publish, session, channelId }) {
      // The group is up to three other members of this channel.
      const read = () => session.channels.get?.(channelId ?? "")?.members;
      const roster = React.useSyncExternalStore(session.channels.subscribeList, read, read);
      const members = (roster ?? []).filter((key) => key !== session.viewer).slice(0, 3);
      const key = members.join();
      React.useEffect(() => {
        const matches = "crew".startsWith(query.query.toLowerCase());
        const edit = {
          mentions: members.map((pubkey) => ({ pubkey, name: pubkey.slice(0, 8) })),
          label: "crew",
        };
        const rows = matches && members.length ? [{ id: "crew", label: "crew", edit }] : [];
        return publish({ items: rows, holdAutoSelect: matches }) || undefined;
      }, [query.query, key]);
      return null;
    },
  });
}
  1. Open Settings → Manage plugins → Add → Browse, choose the folder, and install Group chip example with Enable plugin on.
  2. In a channel with at least one other member, type @cr, press Enter, type hello and send. Working: a "Groups" heading with crew sits above the "Mention" heading, Enter replaces @cr with one @crew · N chip, and the sent message shows @crew hello as plain text, with each member notified.

This branch contains #3726, so these steps also cover #3726's.

🤖 Generated with Claude Code

@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from 1dfbe27 to 0e914ad Compare November 7, 2026 00:17
@LordMelkor
LordMelkor marked this pull request as ready for review November 7, 2026 00:17
@LordMelkor
LordMelkor requested a review from a team as a code owner November 7, 2026 00:17
@LordMelkor LordMelkor changed the title feat(mentions): let saved teams mention people outside the channel feat(mentions): saved teams can mention people and insert one @team chip Nov 7, 2026
@morgmart

morgmart commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🤖 Design review: this isn't critical path for the Nov 10 launch. Please hold it until after launch, or build it as an external plugin that isn't bundled into the app. Questions: #buzz-design-review.

@LordMelkor

LordMelkor commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Thanks. We'll hold this until after the Nov 10 launch.

The feature is already an external plugin: Mention Groups, in a separate repository, isn't bundled, and this PR doesn't bundle it. What's left here is the host side it needs: a group completion edit, so a team inserts one @team chip, plus letting saved teams include people. A plugin can't add those. We'll revisit after the launch.

@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from 454a627 to 21f1a60 Compare November 10, 2026 15:15
@LordMelkor

LordMelkor commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Update, Nov 18: Moved to #3837, so that the branch is in this repository. This PR is closed; its review history stays here.


Update, Nov 17: this PR is reworked to keep features out of core, following the maintainer's rule that anything a plugin can build stays in a plugin. The saved-team changes are gone. What's left is one general hook: a plugin's mentions completion edit may add label and href, which inserts one chip that notifies each person and is sent as a link. The Mention Groups plugin, in a separate repository, will use it, and nothing is bundled.

It's stacked on #3726 and back in draft until the human test in the PR body. Details and evidence are in the body.

@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch 3 times, most recently from a6ed632 to 94118b4 Compare November 14, 2026 03:00
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from 94118b4 to 4b0afb8 Compare November 16, 2026 22:29
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Rebase-only review at 4b0afb8371c6a4a1d14ac679b6137012c8ef8eaf: no new blocker found. The Solo conflict resolution preserves main's boundary: team eligibility uses current members and the viewer's available agents, while directory-only outsiders remain individual references. Acceptance rechecks the same eligibility. The combined agents docs and new help sentence match that behavior.

All 778 tests in the full Mentions and Buzz MCP selections passed at this head. Independent source review found no integration blocker. No app source changes or repeated visual acceptance were part of this review; this is not a full-feature or readiness approval.

A provider registered with `supplement: true` mounts beside the provider
that owns the caret when its own match has the same start, with its own
query. It never owns the caret, so it never opens a popup alone.

Each provider's rows form a section, in `order` then contribution key,
with the winner among them. A supplement's section sits under a heading
with its `title`, and so does the winner's when another section comes
first. Rows are keyed by provider and id, so ids may repeat across
providers; acceptance, retry, status and failure stay per provider.

Terminator evidence still comes only from the winner. A supplement's
`holdAutoSelect: true`, or a supplement that has not published yet,
withholds the winner's `spaceId` and `spacePending`, so a typed
terminator stays text. A supplement that throws drops only its section
and releases its hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from 4b0afb8 to 21958f8 Compare November 17, 2026 18:47
@LordMelkor
LordMelkor marked this pull request as draft November 17, 2026 18:47
@LordMelkor LordMelkor changed the title feat(mentions): saved teams can mention people and insert one @team chip feat(composer): one chip for several recipients, sent as a link Nov 17, 2026
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from 21958f8 to ec02a15 Compare November 17, 2026 19:29
LordMelkor added a commit to LordMelkor/buzz-app that referenced this pull request Nov 17, 2026
@LordMelkor
LordMelkor marked this pull request as ready for review November 17, 2026 20:48
… hold

A supplement whose plugin is removed while the menu is open loses its
rows and its hold, and a publish from its old owner is refused. Nothing
covered that before.

The docs now say that a supplement publishing later with a lower order
moves the default row until the user moves the selection, and that a
hold has no time limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from ec02a15 to bc797a5 Compare November 17, 2026 21:47
… untouched default

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
LordMelkor added a commit to LordMelkor/buzz-app that referenced this pull request Nov 18, 2026
* commit '4f31f7798c600528c8ea335b262e673e56a676f2':
  test(completions): a late supplement with a lower order moves only an untouched default

* commit 'f26a1060f9f54297586c19742416f8947727c22a':
  Plugin relay kinds: say what each kind is for at install
  fix(plugins): no relay-kind grant may include a private-message or signer kind
  docs(plugins): say where host.publish checks the scope
  fix(relay): leave old-event acceptance to the relay; 429 is a refusal
  feat(host): host.publish and host.relayInfo for plugins
  feat(relay): sign and publish a declared kind for a plugin
  feat(plugins): declare relay event kinds in the manifest
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from bc797a5 to bc958b6 Compare November 18, 2026 02:35
A `mentions` completion edit may carry a `label`. The composer inserts one
`@label` chip over the query. It notifies each person in `mentions` once
and is sent as the plain text `@label`, with one `p` tag per person. A
blank or non-string label drops the row before it is shown.

- In code, and in a message edit, only the text `@label` goes in, since
  edits add no recipients.
- Removing or replacing recipients keeps the members still wanted; with
  none left the chip is plain text. A letter typed onto the label turns it
  into text, as for a person's chip, and marks such as a link keep it.
- Saved drafts keep each member on the label's span, checked against the
  exact text `@label` and a mention boundary when restored.
- The chip shows the recipient count beside the label and their names in
  its accessible name.
- The 32-recipient cap counts distinct people, and a send names each person
  once. A chip's members count as namesakes, so a mention that shares a
  name with one of them is sent qualified.
- A Solo chat's title drops a leading chip whole, as it drops a leading
  person tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor force-pushed the clod/team-mentions-people branch from bc958b6 to 4e10835 Compare November 18, 2026 02:53
@LordMelkor LordMelkor changed the title feat(composer): one chip for several recipients, sent as a link feat(composer): one chip for several recipients, sent as @label Nov 18, 2026
@LordMelkor
LordMelkor marked this pull request as draft November 18, 2026 04:01
In a paragraph with formatting, a group chip's @Label was not masked as a
recipient span: italic wrapped it in _..._ and a * in the label was
backslash-escaped on send. Treat a group chip like a recipient chip when
serializing, and exclude it from semantic tokens when reading a snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor LordMelkor closed this Nov 18, 2026
LordMelkor added a commit that referenced this pull request Nov 21, 2026
…ner (#3836)

**What a person gets:** someone types `@design` to reach a team. Today a
plugin can't put its rows in the `@` popup without taking the popup over
and hiding the people. With this hook, the plugin's rows show in the
same popup under their own heading, and the people rows stay as they
are. With no supplement registered, nothing changes.

| `@b` with a plugin that adds groups | `@b` today |
|---|---|
| ![The popup shows Bob Member, then a Groups heading with Bobsled Team,
1
person](https://raw.githubusercontent.com/LordMelkor/buzz-app/af8a5a0cc66a4bd23fa9df976f55c871583e40f8/e2e-v7/105at-p105m-head-atb.png)
| ![The popup shows one row, Bob
Member](https://raw.githubusercontent.com/LordMelkor/buzz-app/af8a5a0cc66a4bd23fa9df976f55c871583e40f8/e2e-v7/105at-p2x6-noplugin-atb.png)
|

**Size:** production +327/−158, tests +611/−3, docs +25, at `e4cdd8ff1`.

**Status:** an automated review approved the code at `275173f99` and
left the two product rules below to a person. The author has decided
both. Two commits since then: `cd95a6906` (production +1/−1) applies the
decision on the second rule and adds the real-composer Enter and Tab
cases that review suggested, and `e4cdd8ff1` brings the contract's
comment and the docs in line with it (no code change).

**Two product rules, both decided by the author.**

1. **A plugin's row can be the default Enter or Tab pick under `@`.**
Decided: yes, as written. This happens when the plugin orders its
section above the people rows: the first row is the default, as it is
today. On `main`, a plugin can already take Enter under `@` by
registering a provider that owns the caret, and then the people rows are
hidden. A typed Space still accepts only the people provider's exact
match.
2. **A supplement that has published nothing holds nothing.** Decided:
no silent hold and no timer. Only a published `holdAutoSelect: true`
keeps Space from picking the people provider's exact match, so a
supplement that is still loading publishes the hold itself. One that
never publishes changes nothing: `@Bob` and Space picks Bob, as on
`main`. Up to `275173f99`, a supplement that hadn't published yet for
the query held Space for as long as the query was open.

Moved from #3726, so that the branch is in this repository. The earlier
review history is on #3726.

## Summary

More than one completion provider can contribute rows to the same
composer trigger. Today one provider wins the caret at a given start and
only that provider mounts, so a plugin that offers rows for `@` either
loses to the bundled people provider or replaces it.

A provider registered with
`ctx.conversation.registerCompletionSupplement(provider)`:
- mounts beside the winning provider when its own `match` returns the
same `start`, with its own query;
- never wins the caret, so it never opens a popup alone.

**Registration:** older hosts have no `registerCompletionSupplement`, so
a plugin calls it as `registerCompletionSupplement?.(provider)` and adds
nothing there. `registerCompletion` refuses a provider with `supplement`
set, so the method is the only way to register one. A flag on
`registerCompletion` would not degrade safely: a host that doesn't know
it treats the provider as an ordinary one, and with an `order` below the
bundled mentions' that provider owns the `@` caret and hides the people
rows. An end-user test on Buzz 1.0.5 showed this with the earlier
flag-only form of this PR.

**Sections:** each provider's rows form a section, ordered by the
existing `order` field, then the contribution key, with the winner among
them. A supplement chooses its place through `order`. Its section sits
under a host-drawn heading with the provider's `title`. The winner's
section gets its `title` heading too when another section comes first
and the winner draws no heading of its own, so its rows never read as
part of the section above. Alone or first, the winner looks as it does
today. Each provider keeps its own 50-row cap. There is no shared quota.

**Rows keep their provider:** a row is identified by its provider plus
its item id, so two providers may use the same id. Accept, `canSelect`,
`disabled`, retry and status each go to the provider that published the
row.

**Exact match:** a supplement decides no exact match. The host reads
terminator evidence (`spaceId`, `spacePending`) only from the winner,
and drops a supplement row's `agent` mark.
- `holdAutoSelect: true` on a supplement's result says that its whole
source, not only its shown rows, has or extends the typed name, or is
still loading. While any supplement holds, a typed terminator never
accepts the winner's exact match and types as text. This is the general
form of the rule the bundled teams use: `@eng` followed by Space must
not pick a person called Eng while a group named `eng` exists.
- Only a published hold holds. A supplement that has published nothing
for this query holds nothing, so one that is still loading publishes
`holdAutoSelect: true` itself.
- A supplement that throws, in its component or in one of its row
previews, drops only its own section and releases its hold. From then
on, for this query, the host refuses its publications and its rows.
- Escape still dismisses the popup while a supplement's published hold
is on, even when no row is shown. With nothing shown and no hold, Escape
goes on to the composer, as it does with no supplement.
- The first row is selected by default, so Enter and Tab take a
supplement row ordered above the winner's. A typed terminator still
accepts only the winner's exact match.

With no supplement registered, behaviour is unchanged.

## Why this is in core (Necessity and Minimality)

Features belong in plugins, and core gets only the smallest general
capability a plugin needs. This is the rule in this repository's
`AGENTS.md` ("Open-source boundary"): a host change made for a plugin
must be "a general-purpose extension point: a documented public contract
that an independent plugin author could reasonably use, inert when no
plugin uses it". The table measures each change two ways. **Necessity:**
a plugin can't do it with today's API. **Minimality:** it is the
smallest general hook any plugin could use.

| Change | Necessity: a plugin can't do this today | Minimality: the
smallest general hook |
|---|---|---|
| `registerCompletionSupplement` on `Conversation` (`service.tsx`), kept
as `supplement: true` on the existing completion contribution
(`contracts.ts`) and matched in `completion.ts` | **Supplements:**
`matchCompletion` keeps one winner per caret (`completion.ts:36-75` on
the base), and `ComposerCompletions` mounts only that provider. A plugin
on `@` either loses to bundled mentions (order -10,
`src/bundled/mentions/index.tsx:13`) or replaces every people row.
Wrapping or replacing the bundled provider isn't possible from a plugin.
**A method, not only the flag:** a host that doesn't know the flag
treats a supplement as an ordinary provider. It sorts providers by
`order`, then key, and a later one replaces the winner only at a later
start (`completion.ts:42-48` and `:60` at `v1.0.5`). With `order` below
-10, the plugin's provider owns `@` and hides the people rows, which the
end-user test found on Buzz 1.0.5. With `order` above -10, it still owns
`@` wherever the bundled matcher declines, such as right after a
completed identity link (`src/bundled/mentions/mention-query.ts:13-16`),
and on a host with supplements its rows sit below the people's 50 (next
row). Nothing in that host's API tells a plugin whether supplements
exist, so a plugin can't guard the flag itself. | One method beside
`registerCompletion`, writing to the same contributions, so no new
reader or component changes. It names no feature, and reuses `order` for
placement and `title` for the heading. Its absence on older hosts is the
capability check, as with `registerLinkPreview` and
`registerIdentityMark`. |
| Sections in `order`, then key (`ComposerCompletions.tsx`) | The popup
is `max-height: 17.5rem` (`Completions.module.css:16`), about 6 to 7
rows, and bundled people fill up to 50 rows
(`MentionCompletion.tsx:314-320`). Rows placed after the winner sit
below row 50 for short queries such as `@e`, reachable only by a
wrap-around ArrowUp. | Reuses the existing `order` field. No quota, no
new field. |
| Rows keyed by provider plus id | Provider ids are local. Without the
provider in the key, two providers that both publish `x` share selection
and acceptance. Test: "accepts each row through its own provider when
their ids collide". | A key change only. Each provider's results stay
separate. |
| `holdAutoSelect?: boolean` on `CompletionResult` | The host accepts
the winner's `spaceId` on a terminator. Only the supplement knows
whether its whole source, rather than its shown rows, has a longer or
equal name. Test: "keeps Space from picking the winner's exact match
while a supplement holds it". | One boolean, read only from supplements.
It's the general form of the bundled `teamBlocksSpace` rule
(`use-team-mentions.ts:32-50`). |

**FOUNDATION:** this PR edits two FOUNDATION files.
`src/features/conversation/contracts.ts` gets two optional fields,
`supplement` and `holdAutoSelect`.
`src/features/conversation/service.tsx` gets
`registerCompletionSupplement` and the refusal in `registerCompletion`
(+17/−1). The PR's author, who directs this work, gave the human
guidance for the `contracts.ts` fields. For the `service.tsx` method,
the author had a second agent review the design, and that review
approved this shape. The author, who holds the Maintain role on this
repository, has since approved the whole change for merge, including
both FOUNDATION edits and the published-hold rule above.

## Merge order

This PR goes before the multi-recipient chip rework (#3837), which is
stacked on it, because both edit the completion types in `contracts.ts`.
No other order is needed.

## Size

Measured against `main` (`cf2355f1e`) at `e4cdd8ff1`, with `git diff`.

| | Added | Removed |
|---|---|---|
| Production | 327 | 158 |
| Tests | 611 | 3 |
| Docs | 25 | 0 |

Most of it is `ComposerCompletions.tsx` (+269/−148): mounting
supplements beside the winner, their sections, and per-provider results,
failures and holds. `completion.ts` is +29/−9, `service.tsx` +17/−1 and
`contracts.ts` +12, of which 2 lines are the two fields and 10 are their
comments.

## Validation

**Published holds only, at `cd95a6906`:** one commit on `275173f99`.
Production is one line: `held()` in `ComposerCompletions.tsx` counts a
supplement only when it has published `holdAutoSelect: true`. The docs
say the same in `docs/plugin-architecture.md`.
- Unit tests: "leaves Space to the winner when a supplement %s" gets the
row "has not answered", which replaces the test of the old rule. The
Escape test now says that a published hold beside an empty winner keeps
Escape, and a silent supplement doesn't.
- Real composer, in `tests/browser/completion-work.spec.mjs`, Chromium
and WebKit. The fixture's supplement publishes in an effect, as a plugin
does.
- With a published hold: `@Mary Jane` and Space typed with no pause
gives no chip, and the Space stays as text.
- With a supplement that publishes nothing: Space picks Mary Jane, as on
`main`.
- Enter, and Tab, on a supplement row ordered first: each puts in that
row's two member chips.
  - The two Space cases, run 20 times each in each engine: 80 of 80.
- Controls. With the old rule put back, the new unit row, the Escape
test and the silent browser case fail. With no hold at all, the browser
hold case fails with one chip where none is expected.
- On a separate Linux machine at `cd95a6906`: `pnpm check` passes.
`src/features/conversation` and `src/features/messages` pass, 142 files
and 3,860 tests. The nine browser specs for mentions, completions and
the composer pass in Chromium and WebKit, 122 of 122.
- In the app, built from `cd95a6906` without #3837, with the plugin
these hooks were built for: `@Ops Shared` shows one group row, a pick
gives one chip per member, and the sent message has a `p` tag for each.
5 of 5 cases pass. That plugin publishes its own hold while its groups
load, so it doesn't depend on the old rule.

**`e4cdd8ff1`:** a comment, the docs and one test name, after an
independent review of `cd95a6906` found no code defect and one stale
sentence. The comment on `supplement` in `contracts.ts` and
`docs/plugin-architecture.md` now say that a supplement which is still
loading publishes `holdAutoSelect: true` in its mount effect, for every
query. No type changes. `pnpm check` passes and
`src/features/conversation` passes, 19 files and 190 tests.

Some text below, written at earlier heads, describes the old rule ("the
hold before a first answer"). `cd95a6906` replaces it.

**Updated from `main` at `275173f99`:** a merge of `main` at `cf2355f1e`
(#4133) and one test commit. #4133 changed `accept` in
`ComposerCompletions.tsx`, which this PR also changes, so the merge had
three conflicts, all in that file:
- `accept` takes #4133's browser event and keeps this PR's lookup of the
row's own provider.
- #4133's `withHumanMentionSelection` wraps the `replace` call for every
row, a supplement's too. A supplement row that a person picks marks its
recipients as the owner's mention, and a scripted pick marks none. That
is what `main` already does for every provider's row, a plugin's
ordinary `registerCompletion` row included: `accept` wraps each pick and
checks no provider. A supplement gets nothing more.
- #4133's edit to the single Retry row goes with that row. This PR draws
one Retry row per provider through the same option element as every
other row, and its click passes the event.

All three callers of `accept` run inside their key or click event. A
supplement ordered above the people rows holds the first row, so Enter
or Tab there gives that evidence for the supplement's recipients, as a
plugin provider that owns the caret already does on `main`. The merge
leaves this PR's diff against `main` as it was: production is +326/−158
before and after.

The test commit adds one browser case to
`tests/browser/completion-work.spec.mjs`, run for a people row and for a
supplement row. A scripted click puts the chips in and the send is
confirmed, but there is no owner mention evidence. A real click gives
the evidence, with exactly the send's `p`-tag recipients. With the wrap
taken out of `accept`, the case fails for both rows in Chromium and
WebKit and nothing else fails: #4133's own journeys pick from the member
picker, not from the completion list.

On a separate Linux machine at `275173f99`:
- `pnpm check` (Biome, types and design checks) passes.
- The mention and completion browser journeys pass in Chromium and
WebKit: 114 of 114. The new case, run five times in each engine, passes
20 of 20.
- The full unit suite passes: 1,188 files, 25,309 tests. It ran before
two comment lines were removed from the browser spec; nothing else
changed after it.
- In the app, built from this head without #3837, with the plugin these
hooks were built for: `@Ops Shared` shows one group row with its two
members. A real click gives one chip per member, and the sent message
has a `p` tag for each. 5 of 5 cases pass.
- An independent review of the merge and the test commit found nothing
that blocks it. It noted that the new case picks by click only: Enter
and Tab pass their key event to the same `accept`, but no browser case
picks a supplement row with a key.

CI passed at `275173f99`. The rest of this section describes earlier
heads.

<details>
<summary>Checks at earlier heads</summary>

**Selection fix at `644624b50`:** one commit. A row the user moved to
with the arrow keys stays selected when a supplement is added or removed
while the popup is open. Before, that change remounted the popup's rows,
and the selection went back to the first row. The selection now lives
above that remount, and it is dropped when the winner's query changes.
Its test, "drops a supplement removed while the menu is open, with its
hold", moves to the second person, removes the supplement and checks
that Enter takes that person. The collision test now also accepts the
winner's row. The commit removes "never opens for a supplement alone"
from `ComposerCompletions.test.tsx`, because `completion.test.ts`
already checks that a supplement alone gives no match. One of `main`'s
comments moves with the state it describes.

On a separate Linux machine at `644624b50`:
- `pnpm check` (Biome, types and design checks) passes.
- `bin/node scripts/check-push.mjs` (types and related tests): 72 files,
2,385 tests pass. `check-push.mjs --design` passes. No Rust changed.
- The three test files this PR changes pass: 67 tests.
- In the app, built from this head without #3837, with the plugin these
hooks were built for: `@Ops Shared` shows one group row with its two
members. Picking it gives one chip per member, and the sent message has
a `p` tag for each. 5 of 5 cases pass.
- An independent review of the commit found no defects.

CI passed at that head. The rest of this section describes earlier
heads.

**Registration at `ba160730f`:** one commit adds
`registerCompletionSupplement` and makes `registerCompletion` refuse
`supplement`. Its test, "makes a supplement only through
registerCompletionSupplement" (`service.test.tsx`), registers an owner
and a supplement, checks that the refused call throws, and reads back
which contribution is a supplement.

On a separate Linux machine at `ba160730f`:
- `pnpm check` (Biome, types and design checks) passes.
- `src/features/conversation/` and `src/bundled/mentions/` pass: 28
files, 529 tests.
- `bin/node scripts/check-push.mjs` (types and related tests): 72 files,
2,386 tests pass. `check-push.mjs --design` passes. No Rust changed.
- The landmines lint finds nothing on this commit's lines.
- An independent review of the commit found no defects.

The rest of this section describes earlier heads.

**Lint cleanup at `702432464`:** two commits from a pass with the
landmines lint rules, with no behavior change. They remove the prose
comments this PR added (production +296/−152 became +278/−151), and they
replace the two test helpers' return types with `satisfies Source`,
which keeps `supplement: true` a literal. One comment on an added line
stays: `main`'s "Only the name ellipsizes" note, which moved with its
row. The test doubles stay, because they copy what `main`'s tests
already do in the same file for what jsdom lacks or what a test
observes: the `replace` spy, the `ResizeObserver` stub and the
`console.error` spy. The lint found no sleeps, polling, retries or
raised timeouts on this PR's lines.

On a separate Linux machine at `702432464`:
- `bin/node scripts/check-push.mjs` (types and related tests): `tsc`
passed. 12 of the 72 related test files failed while two other branches'
test runs shared the machine. All 12 then passed when rerun as a set
with nothing else running (1,105 tests). This PR changes none of them.
- `check-push.mjs --design`: pass.

An independent review of the two commits found no behavior or type
change. The rest of this section describes earlier heads.

**Size cut at `36a7ec245`:** one commit makes the change smaller with no
behavior change. Production went from +390/−216 to +296/−152, and no
test changed.
- `matchCompletion` returns the winner and its supplements in provider
precedence, so the second sort goes.
- Per-provider state is keyed by the contribution key.
- The option row is back at `main`'s indentation.
- Group checks that only the winner's rows could reach are dropped,
because supplements never carry a group.

On a separate Linux machine at that SHA:
- the types and related-tests lane passes (72 files, 2,385 tests);
- the design lane passes;
- the Clippy lane has no Rust inputs;
- `src/features/conversation/` passes (19 files, 183 tests).

An independent review of the commit found no behavior change. The rest
of this section describes earlier heads.

**Updated from `main` at `5d5400bd22`:** a merge of `main`
(`46a09dbfd`), with no change to this PR's diff. CI passes at this head.
The end-user test below ran on that same `main` with this PR's commits.

Later commit `4ccb32df12` (a test and docs), on a separate Linux
machine: Biome and `tsc --noEmit` are clean, and
`src/features/conversation/` passes: 19 files and 181 tests. #3837's
runs below contain this commit too.

Later commit `4f31f7798` (a test only), on the same machine:
`ComposerCompletions.test.tsx` passes, 40 tests, and so does `vitest
related` on it. Biome and `tsc --noEmit` are clean. With the ArrowDown
pin removed, its "keeps a row the user moved to" case fails. #3837
doesn't contain this commit yet; it adds no app code.

At HEAD `3c3191c967dfa1494cdde6cdd64a3977060eb85b`:
- New test cases: 13 in `ComposerCompletions.test.tsx` and 1 in
`completion.test.ts`. 13 of the 14 fail with this PR's three source
files reverted to the base. The fourteenth, Escape while a supplement
has not answered, passes on the base, which has no supplements; it
covers a path this PR adds.
- Mutation checks: with each guard removed in turn, its test fails. The
guards are:
- the holds on `spaceId` and `spacePending`, and the hold before a first
answer;
  - release on failure;
- after a failure, clearing the failed section and refusing its later
publications;
  - error isolation for a supplement's previews;
  - Escape wiring while a supplement holds;
  - dropping a supplement row's `agent` mark;
  - rows keyed by provider;
  - the winner's heading after another section;
  - the matcher's same-start filter.
- A carried result is also cleared for a provider that is no longer
beside the query, such as a supplement that stopped matching mid-word.
Without this, typing `@xy`, then `@xyz`, then Backspace would paint the
stale `@xy` section for one render before its provider publishes again.
No test isolates this, because the test harness keeps one observation
per mount.
- The three pre-push lanes ran on a separate 64-core Linux machine at
this SHA:
- `check-push.mjs` (types and related unit tests): 68 files and 2,323
tests passed, with the existing suites unchanged. Two tests failed while
three lanes ran at once: a 5-second timeout in `InboxPage.test.tsx`, and
a list count in `NewMessage.test.tsx`. The same two failed in a
concurrent run of another branch. This PR touches neither file. Rerun
alone, both files pass at this SHA and at the base: 234 tests each.
- `check-push.mjs --design` passes. The Clippy lane has no Rust inputs
to check.
- `tsc --noEmit` and `biome check` are clean.
- Agent reviews: the first found two defects, both fixed. The winner's
rows had no heading when a supplement section came first, and the
stripping of a supplement's `spaceId` and `spacePending` was dead code,
since the host reads that evidence only from the winner. It also named
two missing tests, now added: a winner with no rows beside a supplement
with rows, and a held `spacePending`. A later review found that a failed
supplement kept its rows, and that its previews could close the popup;
both are fixed, with tests. A fresh review of that fix found no defects.
- In the app: an agent ran the flow in the app's browser build
(`tests/browser`, headless Chromium, on the same machine), with a
fixture plugin whose supplement offers `crew` for `@` (order -20,
`holdAutoSelect` while `crew` starts with the query).
- At this HEAD: `@cr` shows a "Groups" heading with `crew` above the
"Mention" heading and the matching people. `@` alone shows the same
Groups section above all the people. ArrowDown and ArrowUp move across
both sections in order.
- At #2878's commit `8824d8c1e`, which contains this PR: a plain mention
(`@Grace Hopper`, then Space) still gives her person chip. With a member
named Crew, `@crew` then Space types a space and picks no one. Control:
with `holdAutoSelect` forced to `false`, Space inserts a chip.

| `@cr`: the supplement's section above the people | `@crew`, Space: no
one picked |
  |---|---|
| ![Groups heading with crew above the Mention heading with Crew and
Crystal
Ng](https://raw.githubusercontent.com/LordMelkor/buzz-app/b4dc4fa8a82b0ab9754e5e208ff191ef61887a41/3726/sections.png)
| ![The composer holds the text @crew and no
chip](https://raw.githubusercontent.com/LordMelkor/buzz-app/b4dc4fa8a82b0ab9754e5e208ff191ef61887a41/3726/space-holds.png)
|

</details>

## End-user test (AGENTS.md step 3)

The PR author's agent ran the end-user test again on a separate Linux
machine, with this PR at `ba160730f`, #3837 at `01260a91c`, relay `main`
and the plugin these hooks were built for, which registers its `@` rows
through `registerCompletionSupplement?.()`:

- **Buzz built from `main` with both PRs:** with a group Bobsled Team
saved, `@b` shows Bob Member and, under a **Groups** heading, Bobsled
Team in one popup. `@` shows the 29 people and the group row. Alice
typed `@des` and the popup showed the group Design Team (Alice, Bob and
Carol; no person matches `des`). Enter made one chip. The sent message,
`@Design Team`, has one `p` tag each for Bob and Carol; Alice, who sent
it, isn't tagged.
- **Buzz 1.0.5, which has no supplements:** `@` lists the same 29 people
as the same Buzz with no plugin. `@b` lists only Bob, and no group rows
show.

The first run of this test used the flag-only form of this PR and found
the problem that `registerCompletionSupplement` fixes: on Buzz 1.0.5,
the plugin's `@` rows emptied the people picker.

| `@b` on `main` with both PRs: Bob Member, then the Groups section |
`@b` on Buzz 1.0.5 with the same plugin: Bob Member only | `@b` on Buzz
1.0.5 with no plugin |
|---|---|---|
| ![The popup shows Bob Member, then a Groups heading with Bobsled Team,
1
person](https://raw.githubusercontent.com/LordMelkor/buzz-app/af8a5a0cc66a4bd23fa9df976f55c871583e40f8/e2e-v7/105at-p105m-head-atb.png)
| ![The popup shows one row, Bob
Member](https://raw.githubusercontent.com/LordMelkor/buzz-app/af8a5a0cc66a4bd23fa9df976f55c871583e40f8/e2e-v7/105at-p105at2-head-atb.png)
| ![The popup shows one row, Bob
Member](https://raw.githubusercontent.com/LordMelkor/buzz-app/af8a5a0cc66a4bd23fa9df976f55c871583e40f8/e2e-v7/105at-p2x6-noplugin-atb.png)
|

### Try it yourself

Run this branch (`just desktop`). The test uses a small unsigned plugin,
built like the ones in `examples/plugins`. Make a folder with these two
files:

`manifest.json`

```json
{ "id": "example.supplement", "name": "Supplement example", "apiVersion": 1 }
```

`plugin.js`

```js
export const inject = ["react", "conversation"];

export function apply(ctx) {
  const React = ctx.react;
  ctx.conversation.registerCompletionSupplement?.({
    id: "groups",
    title: "Groups",
    order: -20,
    match: ({ text, start }) => {
      const at = text.lastIndexOf("@", start - 1);
      const query = text.slice(at + 1, start);
      return at >= 0 && !/\s/.test(query) ? { start: at, end: start, query } : null;
    },
    component: function Groups({ query, publish }) {
      React.useEffect(() => {
        const hold = "eng".startsWith(query.query.toLowerCase());
        const rows = hold ? [{ id: "eng", label: "eng", edit: { text: "@eng " } }] : [];
        return publish({ items: rows, holdAutoSelect: hold }) || undefined;
      }, [query.query]);
      return null;
    },
  });
}
```

1. Open Settings → Plugins → **Load from folder**, choose the folder,
install **Supplement example** and enable it.
2. In a channel, type `@e`. **Working:** a "Groups" heading with `eng`
sits above a "Mention" heading (the bundled provider's existing `title`)
and the people rows.

An agent ran the rest of the flow in the app (arrow keys across
sections, Space with a namesake, a plain mention); see Validation. With
no supplement registered, the existing completion tests pass unchanged.

#3837 contains this PR, so its steps also cover this one.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: LordMelkor <kray@squareup.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Clod <c7b21872e9ddb79ca62967d0e21e6a4518a669eb04648e963cdfb2426e62fafb@buzz.block.builderlab.xyz>
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.

2 participants