Skip to content

Fix @mention search to use word-boundary prefix matching#278

Merged
wpfleger96 merged 3 commits intomainfrom
sprout-ux/mention-search
Apr 9, 2026
Merged

Fix @mention search to use word-boundary prefix matching#278
wpfleger96 merged 3 commits intomainfrom
sprout-ux/mention-search

Conversation

@wpfleger96
Copy link
Copy Markdown
Collaborator

@wpfleger96 wpfleger96 commented Apr 8, 2026

This PR fixes @mention search to eliminate irrelevant results caused by substring matching on short queries.

String.includes() matched any substring: @g returned "Will Pfleger" (the "g" in Pfleger), and @c matched any member whose name or pubkey contained "c" anywhere.

  • Replace the includes() filter in useMentions.ts with scoreLabel(), which matches word-boundary prefixes only (no arbitrary mid-word substrings) — standard mention UX matching Slack/Discord/GitHub behavior
  • Score against both display names and persona names, taking the best match
  • Separate actual display name from the truncated-pubkey fallback label so scoring runs against real names, not the 8-char display stub
  • Rank and sort results by match quality before the 8-item cap: full-label prefix (0) > word prefix (1) > pubkey prefix (3) > pubkey substring (4)
  • Use a type predicate on the score filter for proper TypeScript narrowing instead of an as number cast

@wpfleger96 wpfleger96 requested a review from wesbillman as a code owner April 8, 2026 22:29
@wpfleger96 wpfleger96 force-pushed the sprout-ux/mention-search branch from 558465b to 45de905 Compare April 8, 2026 23:23
Copy link
Copy Markdown
Collaborator

@wesbillman wesbillman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but fails some e2e tests

@wesbillman
Copy link
Copy Markdown
Collaborator

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Substring matching with includes() produced irrelevant results: typing
@g matched "Will Pfleger" because "g" appears mid-word in "Pfleger",
and @c matched any member whose name or pubkey contained "c" anywhere.

Replaced the filter with a scoring function that splits labels on
spaces, hyphens, and underscores, then checks whether any resulting
word starts with the query. Results are ranked by match quality (full
label prefix > word prefix > substring fallback > pubkey prefix) and
sorted before the 8-item cap so the best matches always appear first.
Separate actual display name from pubkey fallback label so scoring
doesn't match against 8-char truncated pubkeys. Add pubkey substring
as lowest-priority fallback tier to restore includes() behavior.
Also fix type predicate narrowing and filter empty split tokens.
@wpfleger96 wpfleger96 force-pushed the sprout-ux/mention-search branch from 45de905 to b9d81f8 Compare April 9, 2026 20:12
@g still matched "Will Pfleger" because "pfleger" contains "g" as a
substring (score tier 2). Standard mention UX (Slack, Discord, GitHub)
only matches word-boundary prefixes — no arbitrary mid-word substrings.
Pubkey substring matching (tier 4) is kept since pubkeys are opaque
strings where pasting a middle chunk is reasonable.
@wpfleger96
Copy link
Copy Markdown
Collaborator Author

before:
image

after:
image

@wpfleger96 wpfleger96 enabled auto-merge (squash) April 9, 2026 22:48
@wpfleger96 wpfleger96 merged commit 3878574 into main Apr 9, 2026
9 checks passed
@wpfleger96 wpfleger96 deleted the sprout-ux/mention-search branch April 9, 2026 22:51
tlongwell-block added a commit that referenced this pull request Apr 11, 2026
…ona-migration

* origin/main:
  feat(desktop): add Pulse social notes surface (#296)
  Fix flaky desktop smoke tests (#294)
  Add agent lifecycle controls to channel members sidebar (#291)
  Update nest_agents.md tagging info (#292)
  feat: add Sprout nest — persistent agent workspace at ~/.sprout (#290)
  Fix auth and SSRF vulns (#261)
  Add per-agent MCP toolset configuration to agent setup (#279)
  feat(desktop): team & persona import/edit flows (#288)
  Remove menu item subtitles and fix persona card overflow (#289)
  feat: Phase 1 video upload support (Blossom-compliant-ish) (#285)
  Add inline subtitles to menu items and field descriptions (#276)
  Improve ephemeral channel affordances and hide archived sidebar rows (#286)
  Fix @mention search to use word-boundary prefix matching (#278)
  Allow bot owners to remove their agents from any channel (#284)
  [codex] Polish agent selectors and settings layout (#283)

# Conflicts:
#	desktop/scripts/check-file-sizes.mjs
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