fix(cli): resolve @mentions wrapped in markdown emphasis and skip code regions
Fixes #2526
Problem
buzz messages send silently dropped any @mention wrapped in markdown emphasis — **@Name**, *@Name*, _@Name_ — or preceded by ( / ||. The message posted with zero p tags, exit 0, no warning, so no one was notified and no buzz-acp agent woke. Desktop's TypeScript parser (hasMention.ts) was fixed for exactly this in 0f93ef44 (#328); the Rust parser never got the equivalent, and none of the 69 existing mention tests contained an emphasis character next to an @.
Changes
Following the direction in the issue — widen the existing Rust predicates against one shared delimiter definition rather than porting the TS regex:
crates/buzz-sdk/src/mentions.rs
- New
is_mention_lead(prev, prev2)— the single definition of "what may precede an@": start-of-string, ASCII whitespace,(, emphasis*/_, or spoiler||. Bothextract_at_namesandextract_at_mentions_with_knownnow use it, so the two extraction paths can no longer drift from each other. is_word_boundarywidened to accept trailing*,_, and||(single|intentionally stays a non-boundary, matching TS), so**@Will Pfleger**matches the known multi-word name instead of falling through to a uselesswilltoken.- Doc comments on both predicates point at
hasMention.tsas the counterpart that must stay in agreement.
crates/buzz-cli/src/commands/messages.rs
resolve_content_mentionsnow appliesstrip_code_regionsbefore@nameextraction (previously only NIP-27 URI extraction was stripped). An@nameinside a fenced block or backtick span no longer fires a notification — the false-positive mirror of the reported false negative.buzz messages sendprints a warning to stderr when the (code-stripped) content contains@mentioncandidates but zero mentions resolved — the independent mitigation suggested in the issue, so a zero-recipient send is no longer silent. Email addresses and@never count as candidates, so ordinary prose does not warn.
Tests
- 10 new unit tests in
buzz-sdkcovering bold/italic/spoiler/paren leads, trailing emphasis on multi-word names, the single-|non-delimiter, emails inside emphasis, code-region stripping, and the deliberate_@carol_fallback-tokenizer trade-off (the_glues to the name in the fallback path only; the known-names path resolves it correctly — pinned in a test with a comment). - 5 new tests in
buzz-clicovering the send-pipeline regression case (**@Atlas**), code-region skipping, and thementions_went_unresolvedwarning predicate. cargo test -p buzz-sdk -p buzz-cli,cargo clippy --all-targets, andcargo fmtall clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CqMxL1inNtU7icywZxbrGY
Nice — this matches the direction from the triage notes, and the zero-resolved-mentions warning is a good addition. Two things worth a look:
-
Table pipes. Keeping a single
|a non-boundary means a mention flush against markdown table pipes (|@Atlas|) still resolves nothing, whilef9402f75in the issue shows table mentions are expected to tag (that one only worked because of surrounding spaces). Accepting a single|on both sides is a strict superset of||and keeps the delimiter predicate single-character. Repro:extract_at_mentions_with_known("|@Atlas|status|", &["Atlas"])— currently[], expected["atlas"]. -
There's a third parser this doesn't reach.
resolve_mention_pubkeysincrates/buzz-relay/src/workflow_sink.rsis an independent @-mention parser — its doc comment says it "defines the matching contract" for workflow-emitted kind:9ptags, and its left-boundary check (workflow_sink.rs:102) still accepts only start-of-string / whitespace /(. Thoseptags are what ACP agent wake is gated on (event_mentions_agent,buzz-acp/src/lib.rs:2656), so a workflow-generated**@Robby**emits zeroptags — the exact stalled-handoff failure mode from this issue, on a surface where the text is machine-generated. Nothing this PR needs to absorb, but the issue's "longer term the parsers should be one implementation" note actually spans three parsers, not two — worth a follow-up either way.
Thanks for the review @SeanGearin!
-
Table pipes — done in 0a39d45d. A single
|is now accepted as both lead and boundary; your repro (|@Atlas|status|→["atlas"]) is pinned as a test, along with@Will Pfleger|xresolving the full known name. It also simplified both predicates back to single-character checks (the two-char||special case is gone). Documented in the doc comments as a deliberate superset of the TS regex's||-only rule so a future parity sweep doesn't "fix" it backwards. -
Third parser — confirmed:
is_left_boundaryinworkflow_sink.rsaccepts only start / whitespace /((its right side is already emphasis-tolerant, though a trailing_extends the name there). Filed #2686 to track it, with a note that sincebuzz-relayalready depends onbuzz-sdk, the cheapest convergence is forworkflow_sinkto call the now-sharedis_mention_lead— three hand-synced parsers down to two. Happy to pick that up as a follow-up PR once this one settles.
@SeanGearin gentle ping when you have a moment — both review points are addressed (table pipes in 0a39d45d with your repro pinned as a test; #2686 filed for the third parser). No rush on my end, but Chessing234 has offered to take the buzz-sdk convergence PR for workflow_sink on top of this one (see #2691), so this is now the head of a small train. 🚂