fix: handle square brackets in agent names for mention parsing#1992
Open
kagura-agent wants to merge 2 commits intomultica-ai:mainfrom
Open
fix: handle square brackets in agent names for mention parsing#1992kagura-agent wants to merge 2 commits intomultica-ai:mainfrom
kagura-agent wants to merge 2 commits intomultica-ai:mainfrom
Conversation
…ca-ai#1991) The mention regex used [^\]]* to match labels, which broke when agent names contained square brackets (e.g. David[TF]). The ] inside the name caused the regex to stop matching prematurely, silently dropping the mention. Changes: - Backend (mention.go): Switch to .+? (non-greedy) anchored on ](mention:// to correctly match labels with brackets - Frontend (mention-extension.ts): Same regex fix in tokenizer, plus escape [ and ] in renderMarkdown to prevent creating ambiguous markdown syntax - Add comprehensive tests for ParseMentions covering bracket names Fixes multica-ai#1991
|
@kagura-agent is attempting to deploy a commit to the IndexLabs Team on Vercel. A member of the Team first needs to authorize it. |
Fixes TS2532: Object is possibly 'undefined' on match[1] when calling .replace() in the mention tokenizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Agent mentions fail silently when the agent's display name contains square brackets (e.g.
David[TF]).The mention link
[@David[TF]](mention://agent/<id>)conflicts with Markdown's own link syntax because the regex uses[^\]]*to match the label — this stops at the first]inside the name, causing the entire mention to go unrecognized.Root Cause
Both the backend Go regex (
MentionReinserver/internal/util/mention.go) and the frontend Tiptap tokenizer (mention-extension.ts) used[^\]]+/[^\]]*to match the label portion of a mention link. This character class excludes], so any]inside the agent name breaks the match.Fix
Backend (
mention.go):MentionReto use.+?(non-greedy) instead of[^\]]*. The](mention://anchor is specific enough to prevent over-matching —mention://will never appear in normal text.ParseMentionsto use the correct capture group indices (the label is now captured as group 1).Frontend (
mention-extension.ts):markdownTokenizer.start()andtokenize().renderMarkdown()now escapes[and]in the label before serializing, preventing ambiguous markdown from being created in the first place.tokenize()unescapes\\[and\\]when parsing, so the round-trip is clean.Testing
mention_test.gowith comprehensive test cases:David[TF])Bot[v2][beta])David\[TF\])All tests pass locally.
Closes #1991