Repository navigation
feat(composer): let completion providers add rows beside the caret owner - #3726
LordMelkor wants to merge 3 commits into
Conversation
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>
joahg
left a comment
There was a problem hiding this comment.
🤖 This is a comment, not an approval. A human maintainer (design or core team) must review this PR, because it changes the plugin completion contract (contracts.ts is a FOUNDATION file) and what users see in the composer. I could not verify the "human guidance" the description cites for the FOUNDATION edit.
I read the full diff, docs/plugin-architecture.md and the registration path. CI is green. I did not run the tests locally.
What looks right:
- Winner selection is unchanged: only non-supplements can win, and supplements are filtered to the winner's final
start. - Rows are keyed by provider plus id. Accept,
canSelect,disabledand retry go to the row's own provider. - A supplement's
spaceId,spacePending,agentandgroupare dropped. OnlyholdAutoSelectis read from it. - Publishing and accepting check liveness (
live, registry membership,editor.valid, not failed). A plugin removed mid-popup cannot publish or accept, and the changed supplement set remounts the owner. - A supplement that throws, in its component or a preview, drops only its own section and releases its hold. The winner's failure still closes the popup.
- Each keystroke remounts the owner, so a stale publication cannot carry a
holdAutoSelectforward.
Findings:
- P2: Enter and Tab take whichever row is first, across all sections. A plugin picks any finite
order, so its row can be the default-selected row under@, ahead of the built-in people rows. A supplement that publishes late with a lowerorderalso moves the first row under a user who is already about to press Enter. Itsmentionsedit can carry up to 32 recipients. The row is highlighted, but a maintainer should decide whether a plugin may own the default row. Consider defaulting to the winner's first row unless the user navigates. No test covers a late publication changing the default. - P2: The hold has no bound. A supplement that never publishes, or always sets
holdAutoSelect, stops Space and closing punctuation from accepting the built-in exact match (and from holding a pending mention) for as long as that query is open. Typing@alicethen stays text, so no mention chip is created. That is silent for the user. Consider a timeout, after which the hold is ignored. Or document that a plugin can do this. - P3: Missing tests for plugin removal while the popup is open, and for a late supplement publication. The code handles removal, but nothing pins it.
- P3:
rows.findIndexruns inside the row map (twice per row), which is quadratic in the row count. Fine at 50 rows per provider, but easy to hoist.
Needs a maintainer's call: the default-row policy, the hold bound, and whether this extension point belongs in core. Also the visual result: no screenshots or in-app check are in the description, and the AGENTS.md UI guidance asks for them.
| {node} | ||
| </ContributionBoundary> | ||
| ); | ||
| const rows: Row[] = []; |
There was a problem hiding this comment.
🤖 P2: rows from all sections are flattened here, and the default selection is index 0 (selectedIndex). A supplement with a low order, or one that publishes late, becomes the Enter/Tab target ahead of the built-in rows. Consider defaulting to the winner's first row unless the user navigated, or ask a maintainer whether plugin rows may own the default.
There was a problem hiding this comment.
🤖 I've kept the one rule, "the first row is the default", which docs/plugin-architecture.md already stated. Plugins are trusted code, and they choose order on purpose. The highlighted row is visible before Enter. Once the user moves the selection, it stays on that row while the row exists. A winner-first default would add a second rule that overrides the order a plugin declared. The plugin this was built for orders its rows after the people rows, so it never takes the default.
The late-publication case was real and wasn't documented. 4ccb32df1 adds it to the docs: a supplement that publishes later with a lower order moves the default row until the user moves the selection.
| }, [publishers, display, trigger]); | ||
| // The winner's exact match waits while a supplement has, or may have, a | ||
| // name the typed one is, or begins. | ||
| const held = () => |
There was a problem hiding this comment.
🤖 P2: this hold has no time limit. A supplement that never publishes, or keeps holdAutoSelect: true, blocks the winner's terminator accept and pending-mention hold for the whole query, so @alice stays text with no chip. Consider a bound after which the hold is ignored.
There was a problem hiding this comment.
🤖 No timeout, on purpose. The hold exists so that typing @mrm doesn't turn into a person chip while a group named mrm is still loading. With a timeout, Space would accept the person after the time limit while the group could still arrive. The docs already describe the hold, and 4ccb32df1 adds "A hold has no time limit."
… 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>
… untouched default Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
|
🤖 Update, Nov 18: Moved to #3836, so that the branch is in this repository. This PR is closed; its review history stays here. On the review's other points:
|
joahg
left a comment
There was a problem hiding this comment.
🤖 This is a comment, not an approval. A human maintainer (design or core team) still needs to review this PR. It changes the plugin completion contract, and contracts.ts is a FOUNDATION file.
Follow-up on 4ccb32df1 and 4f31f7798. These commits only touch tests and docs. CI is green.
- Both P3 test gaps are covered now:
- Removing a supplement mid-menu: a stale
publishreturnsfalse, the supplement's rows are gone, and Space accepts the built-in exact match, so its hold is released. - A late publication with a lower
ordermoves an untouched default row. A row the user already moved to stays selected.
- Removing a supplement mid-menu: a stale
- The docs now state that a late, lower-
ordersupplement moves the default row, and that a hold has no time limit. - Keeping the
findIndexlookup is fine at the 50-row cap.
On the two P2s, I accept the reasoning in the threads. The behavior is now documented and tested. It's still a policy choice for a maintainer to make:
- whether a plugin's row may be the default Enter/Tab target under
@ - whether a plugin that never publishes may hold mention chips for as long as the query is open
* 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
…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 | |---|---| |  |  | **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 | |---|---| |  |  | </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 | |---|---|---| |  |  |  | ### 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>
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
supplement: true:matchreturns the samestart, with its own query;Sections: each provider's rows form a section, ordered by the existing
orderfield, then the contribution key, with the winner among them. A supplement chooses its place throughorder. Its section sits under a host-drawn heading with the provider'stitle. The winner's section gets itstitleheading 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'sagentmark.holdAutoSelect: trueon 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:@engfollowed by Space must not pick a person called Eng while a group namedengexists.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.supplement?: trueonComposerCompletion(contracts.ts), matched incompletion.tsmatchCompletionkeeps one winner per caret (completion.ts:36-75on the base), andComposerCompletionsmounts only that provider. A plugin on@either loses to bundled mentions (order -10) or replaces every people row. Wrapping or replacing the bundled provider isn't possible from a plugin.orderfor placement andtitlefor the heading, and adds no registration API.order, then key (ComposerCompletions.tsx)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.orderfield. No quota, no new field.xshare selection and acceptance. Test: "accepts each row through its own provider when their ids collide".holdAutoSelect?: booleanonCompletionResultspaceIdon 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".teamBlocksSpacerule (use-team-mentions.ts:32-50).FOUNDATION:
src/features/conversation/contracts.tsis the only FOUNDATION file this PR edits: two optional fields,supplementandholdAutoSelect. The PR's author, who directs this work, gave the human guidance for this edit.src/features/conversation/service.tsxis unchanged: the flag is read incompletion.ts, asagentis.Merge order
This PR is independent of #3725. It goes before the multi-recipient chip rework (#2878), because both edit the completion types in
contracts.ts.Validation
Later commit
4ccb32df12(a test and docs), on a separate Linux machine: Biome andtsc --noEmitare clean, andsrc/features/conversation/passes: 19 files and 181 tests. #2878's runs below contain this commit too.Later commit
4f31f7798(a test only), on the same machine:ComposerCompletions.test.tsxpasses, 40 tests, and so doesvitest relatedon it. Biome andtsc --noEmitare clean. With the ArrowDown pin removed, its "keeps a row the user moved to" case fails. #2878 doesn't contain this commit yet; it adds no app code.At HEAD
3c3191c967dfa1494cdde6cdd64a3977060eb85b:New test cases: 13 in
ComposerCompletions.test.tsxand 1 incompletion.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:
spaceIdandspacePending, and the hold before a first answer;agentmark;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@xysection 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 inInboxPage.test.tsx, and a list count inNewMessage.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 --designpasses. The Clippy lane has no Rust inputs to check.tsc --noEmitandbiome checkare 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
spaceIdandspacePendingwas 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 heldspacePending. 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 offerscrewfor@(order -20,holdAutoSelectwhilecrewstarts with the query).@crshows a "Groups" heading withcrewabove 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.8824d8c1e, which contains this PR: a plain mention (@Grace Hopper, then Space) still gives her person chip. With a member named Crew,@crewthen Space types a space and picks no one. Control: withholdAutoSelectforced tofalse, Space inserts a chip.@cr: the supplement's section above the people@crew, Space: no one pickedEnd-user test (AGENTS.md step 3)
An end-user test by the PR author's agent on a separate Linux machine. It ran the three hooks, #3725, #3726 and #2878, together at
9424adddd,3c3191c96andec02a157f(merged into one test branch), so one run covers all three. Since that run,4ccb32df12adds a test and two docs sentences,4f31f7798adds another test, and #2878 is rebased onto4ccb32df12; none of these changes app code.9148c337e, which adds the relay records the plugin writes.Every step was scripted and has screenshots. All passed.
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.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.@rows (feat(composer): let completion providers add rows beside the caret owner #3726): typing@mrmshows Buzz's people rows, then the plugin's "Groups" section withmrm, "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.@mrm · 4.[@mrm](buzz://plugin?…). Itsptags are the 4 other members, once each, and the sender is left out. The message shows@mrmas a link.Not covered: a control run on
main(there, Buzz refuses this plugin's manifest at install, becausemaindoesn't knowhost.relayKinds; this is from the code, not a run), a second app instance, and the macOS app. Each PR's own in-app run, under Validation, has its controls.@mrm: people rows, then the plugin's groupTry it yourself
Run this branch (
just desktop). The test uses a small unsigned plugin, built like the ones inexamples/plugins. Make a folder with these two files:manifest.json{ "id": "example.supplement", "name": "Supplement example", "apiVersion": 1 }plugin.js@e. Working: a "Groups" heading withengsits above a "Mention" heading (the bundled provider's existingtitle) 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.
#2878 contains this PR, so its steps also cover this one.
🤖 Generated with Claude Code