Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(community): render channel/server-ref pills for Unicode channel names
Gusc270b22193a5
diff --git a/src/web/src/lib/community/chat-syntax-plugin.test.ts b/src/web/src/lib/community/chat-syntax-plugin.test.tsindex 8e51eb978..9e610d4ec 100644--- a/src/web/src/lib/community/chat-syntax-plugin.test.ts+++ b/src/web/src/lib/community/chat-syntax-plugin.test.ts@@ -149,6 +149,52 @@ describe("chatSyntaxPlugin — channelRef", () => {const full = paragraphChildren(parse("join https://alook.ai/community/invite/xY9k2vW7aQ"))expect(full.some((c) => c.type === "channelRef")).toBe(false)})++ it("wraps a ref with a Chinese channel name — slugify preserves CJK, the charset must match it", () => {+ // The bug Shelly reported (#194): names are slugified display names, not+ // nanoid ids; slugify keeps CJK/emoji, so an ASCII-only charset dropped the pill.+ expect(paragraphChildren(parse("see /Gus/架构"))[1]).toMatchObject({ type: "channelRef", value: "/Gus/架构" })+ expect(paragraphChildren(parse("/Gus/架构"))[0]).toMatchObject({ type: "channelRef", value: "/Gus/架构" })+ })++ it("wraps a ref with emoji in the server segment (slugify keeps emoji, e.g. \"总部 🎉\" → \"总部-🎉\")", () => {+ const children = paragraphChildren(parse("go /总部-🎉/general now"))+ expect(children.find((c) => c.type === "channelRef")).toMatchObject({ value: "/总部-🎉/general" })+ })++ it("wraps a ref with accented-Latin name (café)", () => {+ expect(paragraphChildren(parse("see /studio/café done"))[1]).toMatchObject({ type: "channelRef", value: "/studio/café" })+ })++ it("wraps the thread form on a Unicode name — /Gus/架构/#42", () => {+ expect(paragraphChildren(parse("see /Gus/架构/#42"))[1]).toMatchObject({ type: "channelRef", value: "/Gus/架构/#42" })+ })++ it("still terminates a Unicode ref at a trailing ASCII period — the period is not swallowed", () => {+ // Regression guard for the Unicode charset: the segment class must stay+ // disjoint from the terminator punctuation, else a greedy match eats the `.`.+ const children = paragraphChildren(parse("see /Gus/架构."))+ expect(children.map((c) => c.type)).toEqual(["text", "channelRef", "text"])+ expect(children[1]).toMatchObject({ value: "/Gus/架构" })+ expect(children[2]).toMatchObject({ type: "text", value: "." })+ })++ it("terminates a Unicode ref at a trailing FULL-WIDTH period 。 — the most common CJK sentence ender", () => {+ // Blair's QA flag: a Chinese sentence ends in 。, so the ref-in-a-sentence+ // shape `看 /Gus/架构。` is extremely common. The full-width 。 must be a+ // terminator (in BOTH the segment-exclusion and the lookahead — the segment+ // is greedy, so lookahead-only would let it swallow the 。), else the pill+ // target becomes "架构。" and click/highlight mis-targets the real channel.+ const children = paragraphChildren(parse("看 /Gus/架构。"))+ expect(children.map((c) => c.type)).toEqual(["text", "channelRef", "text"])+ expect(children[1]).toMatchObject({ value: "/Gus/架构" })+ expect(children[2]).toMatchObject({ type: "text", value: "。" })+ })++ it("terminates at other full-width CJK terminators (!? etc.)", () => {+ expect(paragraphChildren(parse("用 /Gus/架构!"))[1]).toMatchObject({ value: "/Gus/架构" })+ expect(paragraphChildren(parse("是 /Gus/架构?好"))[1]).toMatchObject({ value: "/Gus/架构" })+ })})describe("chatSyntaxPlugin — serverRef", () => {@@ -185,6 +231,22 @@ describe("chatSyntaxPlugin — serverRef", () => {expect(bare).toHaveLength(1)expect(bare.some((c) => c.type === "serverRef")).toBe(false)})++ it("wraps a bare Unicode /server ref (Chinese, emoji)", () => {+ expect(paragraphChildren(parse("check /架构"))[1]).toMatchObject({ type: "serverRef", value: "/架构" })+ expect(paragraphChildren(parse("check /总部-🎉 here"))[1]).toMatchObject({ type: "serverRef", value: "/总部-🎉" })+ })++ it("terminates a Unicode /server ref at trailing punctuation (ASCII + full-width)", () => {+ const ascii = paragraphChildren(parse("check /架构."))+ expect(ascii.map((c) => c.type)).toEqual(["text", "serverRef", "text"])+ expect(ascii[1]).toMatchObject({ value: "/架构" })++ const cjk = paragraphChildren(parse("去 /架构。"))+ expect(cjk.map((c) => c.type)).toEqual(["text", "serverRef", "text"])+ expect(cjk[1]).toMatchObject({ value: "/架构" })+ expect(cjk[2]).toMatchObject({ type: "text", value: "。" })+ })})describe("chatSyntaxPlugin — message ref", () => {diff --git a/src/web/src/lib/community/chat-syntax-plugin.ts b/src/web/src/lib/community/chat-syntax-plugin.tsindex dad6404ac..f90af5918 100644--- a/src/web/src/lib/community/chat-syntax-plugin.ts+++ b/src/web/src/lib/community/chat-syntax-plugin.ts@@ -23,32 +23,65 @@ import type { SpoilerNode } from "./spoiler-syntax"// `/server/channel/#N` (thread), or `/server/channel/#N#M` (thread reply,// see plans/agent-thread-emoji-react.md) ref — the CLI's path grammar// (`parseRef`/`formatRef` in `community-cli-contract.ts`). Segment charset-// `[A-Za-z0-9_-]+` is the nanoid alphabet every `communityServer.id`/-// `communityChannel.id` is generated with. Trailing-// `(?=\s|$|[.,;:!?)\]])` boundary lookahead: a 2-segment path followed by-// ANOTHER `/segment` (e.g. `/api/user/123` in a docs URL) must NOT match —+// `[^\s/#.,;:!?)\]]+` = "any char slugify can emit, minus the terminator+// punctuation": server/channel names travel on the wire as their SLUGIFIED+// DISPLAY NAME, not an id (see the round-trip contract in+// `channel-ref-extension.ts`'s `renderText` doc + `slugify.ts`), and slugify+// preserves Unicode — it strips only `/` and `#` and collapses whitespace. So+// the base of the class is the inverse of what slugify removes (everything+// except whitespace, `/`, `#`), which is what lets non-ASCII names+// (`/Gus/架构`, `/总部-🎉/general`, `/studio/café`) render as pills like their+// ASCII kin — matching the `\p{L}` + `u` treatment `MENTION_RE` already uses+// for `@names`. We ALSO exclude the trailing-boundary punctuation (`REF_TERM`+// below) from the segment class: the old ASCII class `[A-Za-z0-9_-]` happened+// to be disjoint from the terminator set, and that disjointness is+// load-bearing — the segment class `[^\s/#…]+` is GREEDY, so without excluding+// a terminator char from the segment it gets eaten BEFORE the lookahead can+// fire (a greedy segment swallows the sentence period in `/studio/general.`;+// same for the full-width `。` in `看 /Gus/架构。`). So a terminator must live+// in BOTH places: excluded from the segment (so the match stops there) AND+// present in the lookahead (so stopping there is legal). slugify never emits a+// leading/trailing terminator anyway, and a mid-name terminator is a rare+// corner that degrading to plain text is acceptable for; keeping the boundary+// correct for ALL refs matters more.+//+// `REF_TERM` is the single source of truth for the terminator set — used BOTH+// as the segment-class exclusion (`REF_SEG`) and the trailing lookahead, so+// the two can't drift out of the disjointness the boundary relies on. It+// covers ASCII `.,;:!?)]` AND the common FULL-WIDTH CJK sentence punctuation+// `。!?;:、)】`: a Chinese sentence ends in `。`, so `看 /Gus/架构。` must+// yield pill `/Gus/架构` + literal `。`, not swallow the period — full-width+// terminators matter MORE here since this fix targets CJK names (Blair's QA+// flag). Kept as a string spliced into `new RegExp(...)` so the shared set is+// declared once.+//+// Trailing `(?=\s|$|[REF_TERM])` boundary lookahead: a 2-segment path followed+// by ANOTHER `/segment` (e.g. `/api/user/123` in a docs URL) must NOT match —// otherwise this regex would greedily take `/api/user` and orphan `/123` as// trailing text next to a broken pill. Leading `(?<=^|\s)` lookbehind// (verified empirically — a bare leading `\/` with no lookbehind would let// this match START mid-path, e.g. matching `/user/123` inside// `/api/user/123`): `" /channel-ref"` matches, `"text/channel-ref"` doesn't.// Both boundaries are zero-width lookaround (not capture groups) so-// `findAndReplace` doesn't need to redistribute a leading/trailing text-// node around the match the way the old string-splice regex's `(^|\s)`-// capture group did.-const CHANNEL_REF_RE = /(?<=^|\s)\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+(?:\/#\d+(?:#\d+)?)?(?=\s|$|[.,;:!?)\]])/g+// `findAndReplace` doesn't need to redistribute a leading/trailing text node+// around the match the way the old string-splice regex's `(^|\s)` capture+// group did. `u` flag for correct astral/emoji handling.+const REF_TERM = ".,;:!?)\\]\\u3002\\uFF01\\uFF1F\\uFF1B\\uFF1A\\u3001\\uFF09\\u3011"+const REF_SEG = `[^\\s/#${REF_TERM}]+`+const CHANNEL_REF_RE = new RegExp(`(?<=^|\\s)/${REF_SEG}/${REF_SEG}(?:/#\\d+(?:#\\d+)?)?(?=\\s|$|[${REF_TERM}])`, "gu")// A bare `/server` ref — one segment, no channel. Same boundary lookaround as-// `CHANNEL_REF_RE` (leading `(?<=^|\s)`, trailing `(?=\s|$|[.,;:!?)\]])`), which-// already excludes being followed by another `/segment` — so this never-// double-matches the first segment of a genuine `/server/channel` ref (that-// trailing boundary fails when the next char is `/`, and `[A-Za-z0-9_-]+`-// backtracking can't produce a shorter match that satisfies it either, since-// every character up to the next `/` is in the segment charset). Registered-// after `CHANNEL_REF_RE` in `chatSyntaxPlugin`'s pairs list purely for-// readability (server-only is the "smaller" grammar); the boundary already-// makes the ordering non-load-bearing for correctness.-const SERVER_REF_RE = /(?<=^|\s)\/[A-Za-z0-9_-]+(?=\s|$|[.,;:!?)\]])/g+// `CHANNEL_REF_RE` (leading `(?<=^|\s)`, trailing `REF_TERM`), which already+// excludes being followed by another `/segment` — so this never double-matches+// the first segment of a genuine `/server/channel` ref (that trailing boundary+// fails when the next char is `/`, and the segment class backtracking can't+// produce a shorter match that satisfies it either, since every character up+// to the next `/` is in the segment charset). Same `REF_SEG`/`REF_TERM` ++// `u` flag as `CHANNEL_REF_RE` above (Unicode server names, full-width+// terminators). Registered after `CHANNEL_REF_RE` in `chatSyntaxPlugin`'s+// pairs list purely for readability (server-only is the "smaller" grammar);+// the boundary already makes the ordering non-load-bearing for correctness.+const SERVER_REF_RE = new RegExp(`(?<=^|\\s)/${REF_SEG}(?=\\s|$|[${REF_TERM}])`, "gu")// Message ref: `#NUMBER` where NUMBER is 1-6 digits (seq range 1-999999).// Same boundary pattern as channel/server refs: leading `(?<=^|\s)` so