Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(community): full-path message refs, deprecate bare #N

Shelly3db8851ef09b
diff --git a/src/web/src/components/community/channel-ref-pill.test.ts b/src/web/src/components/community/channel-ref-pill.test.ts
index 7226a0e20..e6ee8b9aa 100644
--- a/src/web/src/components/community/channel-ref-pill.test.ts
+++ b/src/web/src/components/community/channel-ref-pill.test.ts
@@ -48,6 +48,27 @@ describe("describeChannelRefPillView", () => {
})
})
+ it("channel-message ref (resolved.seq set, no thread) → pill carrying messageSuffix as a trailing #N cursor", () => {
+ // `/server/channel#N` (message-ref-upgrade.md): the pill targets the channel
+ // and renders `#N` as a plain trailing cursor — same treatment as a thread
+ // message ref's `#M`. Cross-channel auto-scroll to the seq isn't wired (the
+ // app deep-links by id, not seq), so `#N` is a cursor, not a link anchor.
+ const view = describeChannelRefPillView({
+ ref: "/srv_1/chn_1#42",
+ resolved: resolved({ seq: 42 }),
+ directoryLoading: false,
+ thread: null,
+ currentServerId: "srv_1",
+ })
+ expect(view).toEqual({
+ kind: "pill",
+ label: "general",
+ serverPrefix: undefined,
+ href: { serverId: "srv_1", channelId: "chn_1" },
+ messageSuffix: 42,
+ })
+ })
+
it("resolved.server.id !== currentServerId → pill with serverPrefix set to the server's name", () => {
const view = describeChannelRefPillView({
ref: "/srv_1/chn_1",
diff --git a/src/web/src/components/community/channel-ref-pill.tsx b/src/web/src/components/community/channel-ref-pill.tsx
index 228d3fcaf..c1cca8047 100644
--- a/src/web/src/components/community/channel-ref-pill.tsx
+++ b/src/web/src/components/community/channel-ref-pill.tsx
@@ -75,6 +75,12 @@ export function describeChannelRefPillView(args: {
label: resolved.channel.name,
serverPrefix,
href: { serverId: resolved.server.id, channelId: resolved.channel.id },
+ // A channel-MESSAGE ref (`/server/channel#N`, message-ref-upgrade.md):
+ // the clickable target is the channel; `#N` renders as a trailing cursor,
+ // exactly like a thread-message ref's `#M` below. (Auto-scroll to the seq
+ // cross-channel would need seq→id deep-link infra the app doesn't have —
+ // `?msg=` anchors by id — so it's a plain cursor, matching the thread case.)
+ ...(resolved.seq !== undefined ? { messageSuffix: resolved.seq } : {}),
}
}
diff --git a/src/web/src/components/community/message-body.tsx b/src/web/src/components/community/message-body.tsx
index 7572d05ad..2aabb893b 100644
--- a/src/web/src/components/community/message-body.tsx
+++ b/src/web/src/components/community/message-body.tsx
@@ -94,16 +94,14 @@ const REHYPE_PLUGINS: PluggableList = [
function MessageBodyImpl({
text,
onOpenProfile,
- messageRefContext,
}: {
text: string
onOpenProfile?: OpenProfile
- messageRefContext?: { onJumpToSeq?: (seq: number) => void }
}) {
const inviteTokens = useMemo(() => extractInviteTokens(text), [text])
const components = useMemo(
- () => buildMdComponents(onOpenProfile, messageRefContext),
- [onOpenProfile, messageRefContext],
+ () => buildMdComponents(onOpenProfile),
+ [onOpenProfile],
)
return (
<div className="markdown markdown-chat wrap-anywhere text-[15px] leading-snug">
diff --git a/src/web/src/components/community/message-context-sheet.tsx b/src/web/src/components/community/message-context-sheet.tsx
index 1b79ef889..2688d05a1 100644
--- a/src/web/src/components/community/message-context-sheet.tsx
+++ b/src/web/src/components/community/message-context-sheet.tsx
@@ -442,14 +442,6 @@ function ContextRows({
onDownloadFile: (url: string) => void
onOpenContextSheet?: (seq: number) => void
}) {
- // Chained `#NUMBER` refs inside the sheet reopen the sheet on the new seq,
- // via the same setter the parent already owns.
- const messageRefContext = useMemo(
- () => ({
- onJumpToSeq: onOpenContextSheet ? (s: number) => onOpenContextSheet(s) : undefined,
- }),
- [onOpenContextSheet],
- )
return (
<div className="flex flex-col">
{rows.map((m, i) => {
@@ -479,7 +471,6 @@ function ContextRows({
onPreviewImage={onPreviewImage}
onDownloadFile={onDownloadFile}
resolveUserName={resolveUserName}
- messageRefContext={messageRefContext}
/>
</div>
</div>
diff --git a/src/web/src/components/community/message-list.tsx b/src/web/src/components/community/message-list.tsx
index 8c22e3930..d4255d82c 100644
--- a/src/web/src/components/community/message-list.tsx
+++ b/src/web/src/components/community/message-list.tsx
@@ -284,31 +284,6 @@ export function MessageList({
window.setTimeout(() => setJumped((v) => (v === id ? null : v)), 1600)
}, [jumpToIndex])
- // Message-ref jump handler + the context object handed to each message row.
- //
- // Both MUST stay reference-stable across renders — otherwise `MessageRow`'s
- // memo tears down every row on every WS tick, which is exactly the storm
- // 3fc84fa2 ("perf(web): kill community switch re-render storm") set out to
- // fix. We reach the target by:
- // - reading `messages` / `jumpTo` / `onOpenContextSheet` lazily through a
- // ref that's written on each commit (latest-ref pattern, same as
- // `page.tsx`'s `messageActions`);
- // - `useCallback([])` on the handler and `useMemo([onJumpToSeq])` on the
- // context — both are stable for the mount's lifetime.
- const jumpCtxRef = useRef({ messages, jumpTo, onOpenContextSheet })
- /* eslint-disable-next-line react-hooks/immutability -- latest-ref for lazy click reads */
- jumpCtxRef.current = { messages, jumpTo, onOpenContextSheet }
- const onJumpToSeq = useCallback((seq: number) => {
- const { messages, jumpTo, onOpenContextSheet } = jumpCtxRef.current
- const msg = messages.find((m) => m.seq === seq)
- if (msg) {
- jumpTo(msg.id)
- } else if (onOpenContextSheet) {
- onOpenContextSheet(seq)
- }
- }, [])
- const messageRefContext = useMemo(() => ({ onJumpToSeq }), [onJumpToSeq])
-
useEffect(() => {
if (scrollToMessageId) jumpTo(scrollToMessageId)
}, [scrollToMessageId, jumpTo])
@@ -416,7 +391,6 @@ export function MessageList({
onDownloadFile={onDownloadFile}
resolveUserName={resolveUserName}
onImageLoad={onImageLoad}
- messageRefContext={messageRefContext}
/>
</div>
)}
diff --git a/src/web/src/components/community/message-markdown.tsx b/src/web/src/components/community/message-markdown.tsx
index 9f437a276..1ca259932 100644
--- a/src/web/src/components/community/message-markdown.tsx
+++ b/src/web/src/components/community/message-markdown.tsx
@@ -2,7 +2,6 @@ import type React from "react"
import { Spoiler, MentionPill } from "./inline-marks"
import { ChannelRefPill } from "./channel-ref-pill"
import { ServerRefPill } from "./server-ref-pill"
-import { MessageRefPill } from "./message-ref-pill"
// Match `/c/invite/<token>` — with or without an origin.
// - token allows [A-Za-z0-9_-] (nanoid alphabet) and length 6..64 (short + old
@@ -45,14 +44,13 @@ export const MD_ALLOWED_TAGS = {
mention: ["dataEveryone", "dataTag"],
channelref: [],
serverref: [],
- messageref: [],
}
// `spoiler` is deliberately excluded — unlike `mention`/`channelref`/`serverref`/`messageref`
// (leaf nodes whose content is always plain tag text), a spoiler must keep its
// nested markdown children (e.g. `||**bold**||`). Handing it to Streamdown's
// `literalTagContent` flattens all descendants into one text node, stripping
// the nested `<strong>`/`<em>` — see message-body.test.tsx's regression case.
-export const MD_LITERAL_TAGS = ["mention", "channelref", "serverref", "messageref"]
+export const MD_LITERAL_TAGS = ["mention", "channelref", "serverref"]
// A mention pill's rendered text is always `@name` (produced by
// `chat-syntax-plugin.ts`'s `mentionReplacer`, which already drops the
@@ -69,24 +67,23 @@ export const MD_COMPONENTS = {
mention: ({ children, ...rest }: Record<string, unknown> & { children?: React.ReactNode }) => (
<MentionPill everyone={rest["data-everyone"] === "1"}>{children}</MentionPill>
),
- // `channelref`/`serverref`/`messageref` are fully self-sufficient via hooks
- // (resolve via `useChannelRefDirectory`/`useMessages`, navigate via
- // `useRouter`) — unlike `mention`, they need no closure injected by
- // `buildMdComponents`, so the same static entries are reused there too (see
- // the spread below).
+ // `channelref`/`serverref` are fully self-sufficient via hooks (resolve via
+ // `useChannelRefDirectory`, navigate via `useRouter`) — unlike `mention`,
+ // they need no closure injected by `buildMdComponents`, so the same static
+ // entries are reused there too (see the spread below). A message ref
+ // (`/server/channel#N`) is now a `channelref` too (message-ref-upgrade.md):
+ // the pill navigates to the channel and shows `#N` as a trailing cursor,
+ // same as an existing thread-message ref (`/s/c/#N#M`).
channelref: ChannelRefPill,
serverref: ServerRefPill,
- messageref: MessageRefPill,
} as Record<string, React.ComponentType<Record<string, unknown> & { children?: React.ReactNode }>>
// Same as `MD_COMPONENTS`, but the `mention` pill opens the profile card on
-// click (skipped for @everyone — there's no user behind it), and
-// `messageref` receives `onJumpToSeq` for click-time navigation. Built
-// per-render (memoized by the caller) rather than statically, since it closes
-// over callbacks.
+// click (skipped for @everyone — there's no user behind it). Built per-render
+// (memoized by the caller) rather than statically, since it closes over the
+// `onOpenProfile` callback.
export function buildMdComponents(
onOpenProfile?: (name: string, e: React.MouseEvent, discriminator?: string) => void,
- messageRefContext?: { onJumpToSeq?: (seq: number) => void },
): Record<string, React.ComponentType<Record<string, unknown> & { children?: React.ReactNode }>> {
return {
...MD_COMPONENTS,
@@ -104,10 +101,5 @@ export function buildMdComponents(
</MentionPill>
)
},
- messageref: ({ children }: { children?: React.ReactNode }) => (
- <MessageRefPill onJumpToSeq={messageRefContext?.onJumpToSeq}>
- {children}
- </MessageRefPill>
- ),
}
}
diff --git a/src/web/src/components/community/message-ref-pill.tsx b/src/web/src/components/community/message-ref-pill.tsx
deleted file mode 100644
index 6c04b86c6..000000000
--- a/src/web/src/components/community/message-ref-pill.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-"use client"
-
-import type React from "react"
-
-// `#NUMBER` — channel-scoped message ref. Lazy: always renders as a pill,
-// validates on click. The click handler decides:
-// - loaded in the current window → scroll to it
-// - not loaded → open the context sheet (which resolves seq → id server-side)
-//
-// Range-based rendering was removed on purpose. `seqRange` (min/max) advanced
-// on every WS message tick, which busted the `messageRefContext` identity and
-// re-rendered every memoized message row on incoming traffic. `onJumpToSeq` is
-// built with a latest-ref in `message-list.tsx` and stays reference-stable,
-// which keeps `MessageRow`'s memo intact.
-export function MessageRefPill({
- children,
- onJumpToSeq,
-}: {
- children?: React.ReactNode
- onJumpToSeq?: (seq: number) => void
-}) {
- const text = String(children ?? "")
- const seq = parseInt(text.replace(/^#/, ""), 10)
-
- if (!seq || isNaN(seq) || seq <= 0 || !onJumpToSeq) {
- return <>{text}</>
- }
-
- return (
- <button
- type="button"
- onClick={() => onJumpToSeq(seq)}
- title={text}
- className="inline-flex items-baseline rounded-[4px] bg-accent px-1 font-medium text-foreground transition-colors hover:bg-primary/15 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
- >
- {text}
- </button>
- )
-}
diff --git a/src/web/src/components/community/message-row.tsx b/src/web/src/components/community/message-row.tsx
index 76a246d64..bc46a2da6 100644
--- a/src/web/src/components/community/message-row.tsx
+++ b/src/web/src/components/community/message-row.tsx
@@ -33,7 +33,6 @@ export interface MessageRowProps {
onDownloadFile?: (name: string) => void
resolveUserName?: (userId: string) => string
onImageLoad?: () => void
- messageRefContext?: { onJumpToSeq?: (seq: number) => void }
}
function MessageRowImpl(props: MessageRowProps) {
@@ -41,7 +40,7 @@ function MessageRowImpl(props: MessageRowProps) {
m, pinned, highlighted, onOpenThread, onOpenProfile,
onToggleReactionId, onReactId, onReplyId, onPinId, onCreateThreadId,
onCopyId, onRetryId, onJumpToId, onPreviewImage, onDownloadFile,
- resolveUserName, onImageLoad, messageRefContext,
+ resolveUserName, onImageLoad,
} = props
const id = m.id
const replyToId = m.replyTo?.id
@@ -85,7 +84,6 @@ function MessageRowImpl(props: MessageRowProps) {
onDownloadFile={onDownloadFile}
resolveUserName={resolveUserName}
onImageLoad={onImageLoad}
- messageRefContext={messageRefContext}
/>
)
}
diff --git a/src/web/src/components/community/message.tsx b/src/web/src/components/community/message.tsx
index 6c92c2688..4b60909c8 100644
--- a/src/web/src/components/community/message.tsx
+++ b/src/web/src/components/community/message.tsx
@@ -49,7 +49,7 @@ export function messageCanShare(m: RenderMsg, compact?: boolean): boolean {
function MessageImpl({
m, compact, pinned, onOpenThread, onOpenProfile, onJumpReply,
onToggleReaction, onReact, onReply, onPin, onCreateThread, onCopy, onRetry,
- onPreviewImage, onDownloadFile, highlighted, resolveUserName, onImageLoad, messageRefContext,
+ onPreviewImage, onDownloadFile, highlighted, resolveUserName, onImageLoad,
}: {
m: RenderMsg
compact?: boolean
@@ -69,7 +69,6 @@ function MessageImpl({
highlighted?: boolean
resolveUserName?: (userId: string) => string
onImageLoad?: () => void
- messageRefContext?: { onJumpToSeq?: (seq: number) => void }
}) {
// keep the hover toolbar pinned open while its ⋯ dropdown is open
const [toolbarOpen, setToolbarOpen] = useState(false)
@@ -197,7 +196,7 @@ function MessageImpl({
<BotApprovalCard approval={m.approval} />
) : (
m.content && (
- <MessageBody text={m.content} onOpenProfile={onOpenProfile} messageRefContext={messageRefContext} />
+ <MessageBody text={m.content} onOpenProfile={onOpenProfile} />
)
)}
@@ -449,8 +448,7 @@ function messagePropsEqual(prev: MessageProps, next: MessageProps): boolean {
prev.onPreviewImage === next.onPreviewImage &&
prev.onDownloadFile === next.onDownloadFile &&
prev.resolveUserName === next.resolveUserName &&
- prev.onImageLoad === next.onImageLoad &&
- prev.messageRefContext === next.messageRefContext
+ prev.onImageLoad === next.onImageLoad
)
}
diff --git a/src/web/src/lib/community/chat-syntax-plugin.test.ts b/src/web/src/lib/community/chat-syntax-plugin.test.ts
index 001ac4203..2aef4d31b 100644
--- a/src/web/src/lib/community/chat-syntax-plugin.test.ts
+++ b/src/web/src/lib/community/chat-syntax-plugin.test.ts
@@ -3,7 +3,7 @@ import { unified } from "unified"
import remarkParse from "remark-parse"
import type { Root, PhrasingContent } from "mdast"
import { chatSyntaxPlugin } from "./chat-syntax-plugin"
-import type { MentionNode, ChannelRefNode, ServerRefNode, MessageRefNode } from "./chat-syntax-plugin"
+import type { MentionNode, ChannelRefNode, ServerRefNode } from "./chat-syntax-plugin"
function parse(md: string): Root {
const processor = unified().use(remarkParse).use(chatSyntaxPlugin)
@@ -37,11 +37,12 @@ describe("chatSyntaxPlugin — mention", () => {
it("does not swallow ordinary prose ending in #dddd — the name-run must end in a non-space", () => {
// No earlier `#`, so a naive non-greedy run would span "bob check issue "
// and terminate at #0042. The non-space-before-# guard prevents this.
- // With message ref support, `#0042` is now parsed as a message ref (which
- // will render as a muted pill when the seq doesn't exist in the channel).
+ // `@bob` is not a valid handle (no #dddd), so not a mention. A bare `#0042`
+ // is no longer a message ref (message-ref-upgrade.md — refs are full-path
+ // now), so the whole thing is plain text.
const children = paragraphChildren(parse("@bob check issue #0042"))
expect(children.some((c) => c.type === "mention")).toBe(false)
- expect(children.map((c) => c.type)).toEqual(["text", "messageRef"])
+ expect(children.every((c) => c.type === "text")).toBe(true)
})
it("keeps two adjacent handles as two distinct mentions", () => {
@@ -51,15 +52,13 @@ describe("chatSyntaxPlugin — mention", () => {
})
it("does not truncate a 5+ digit run into a false-positive discriminator (still not a mention)", () => {
- // "#00423" is not a 4-digit tag, so "@Gus#00423" is NOT a mention. Since
- // message refs no longer require a leading space (Gus #94), the leading
- // 1–6 digits of the run now read as a message ref (`#00423`, 5 digits ≤ 6),
- // leaving "@Gus" as text. The key guarantee this test protects is unchanged:
- // it is NOT parsed as a mention with a truncated discriminator.
+ // "#00423" is not a 4-digit tag, so "@Gus#00423" is NOT a mention. A bare
+ // `#N` is no longer a message ref (message-ref-upgrade.md), so the run stays
+ // plain text. The key guarantee this test protects is unchanged: it is NOT
+ // parsed as a mention with a truncated discriminator.
const children = paragraphChildren(parse("hi @Gus#00423"))
expect(children.some((c) => c.type === "mention")).toBe(false)
- expect(children.map((c) => c.type)).toEqual(["text", "messageRef"])
- expect(children.find((c) => c.type === "messageRef")).toMatchObject({ value: "#00423" })
+ expect(children.every((c) => c.type === "text")).toBe(true)
})
it("flags @everyone", () => {
@@ -139,15 +138,24 @@ describe("chatSyntaxPlugin — channelRef", () => {
expect(refs[0]).toMatchObject({ type: "channelRef", value: "/studio/general/#5#42" })
})
- it("does not wrap a mid-string thread-reply path as a channelRef (leading-space boundary still applies to CHANNEL refs)", () => {
- // The channelRef pass still requires a leading space, so `text/.../#5#42`
- // is NOT a channelRef. But message refs no longer require a leading space
- // (Gus #94), so the trailing `#42` (a bare `#`+digits token) now reads as a
- // message ref. The channelRef guarantee this test protects — no channelRef
- // mid-string — is unchanged.
+ it("wraps the channel-message form /studio/general#42 (seq glued to the channel)", () => {
+ // message-ref-upgrade.md: `/server/channel#N` is a channel-MESSAGE ref. The
+ // 2nd segment stops at `#` (REF_SEG excludes `#`), so `#42` falls into the
+ // suffix group — the whole span is ONE channelRef (rendered as a pill with a
+ // trailing `#42` cursor, resolved.seq = 42).
+ const children = paragraphChildren(parse("see /studio/general#42 done"))
+ const refs = children.filter((c): c is ChannelRefNode => c.type === "channelRef")
+ expect(refs).toHaveLength(1)
+ expect(refs[0]).toMatchObject({ type: "channelRef", value: "/studio/general#42" })
+ })
+
+ it("does not wrap a mid-string path as a channelRef, and a bare #N is now plain text", () => {
+ // The channelRef pass requires a leading space, so `text/.../#5#42` is NOT a
+ // channelRef. And a bare `#42` is no longer a message ref (message-ref-
+ // upgrade.md), so nothing pills — the whole run is plain text.
const children = paragraphChildren(parse("text/studio/general/#5#42"))
expect(children.some((c) => c.type === "channelRef")).toBe(false)
- expect(children.find((c) => c.type === "messageRef")).toMatchObject({ value: "#42" })
+ expect(children.every((c) => c.type === "text")).toBe(true)
})
it("leaves a channel-ref-shaped path inside inline code literal", () => {
@@ -263,88 +271,61 @@ describe("chatSyntaxPlugin — serverRef", () => {
})
})
-describe("chatSyntaxPlugin — message ref", () => {
- it("parses space + #NUMBER as messageRef", () => {
- const children = paragraphChildren(parse("see #123"))
- const messageRef = children.find((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRef).toMatchObject({ type: "messageRef", value: "#123" })
- })
+describe("chatSyntaxPlugin — message ref (full-path only; bare #N deprecated)", () => {
+ // message-ref-upgrade.md: a message ref is ALWAYS the full path
+ // `/server/channel#N` (channel message) or `/server/channel/#N#M` (thread
+ // message), matched by CHANNEL_REF_RE as a channelRef. A bare `#N` is no
+ // longer a ref — it renders as plain text (the deprecation).
- it("parses #NUMBER at line start as messageRef", () => {
- const children = paragraphChildren(parse("#42 was fixed"))
- const messageRef = children.find((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRef).toMatchObject({ type: "messageRef", value: "#42" })
+ it("a bare #N renders as plain text (no ref node)", () => {
+ for (const text of ["see #123", "#42 was fixed", "Fixed in #123.", "See #10 and #20"]) {
+ const children = paragraphChildren(parse(text))
+ expect(children.every((c) => c.type === "text")).toBe(true)
+ }
})
- it("parses text#NUMBER glued to a preceding word as messageRef (no leading space needed)", () => {
- // Reversed from the old "avoid GitHub issue#42" rule: agents dislike
- // prepending a space, so a `#N` glued to a word must still pill (Gus #94,
- // approved #105). GitHub-style `issue#42` now renders as a message ref.
+ it("a glued word#N renders as plain text (the old issue#42 pill is gone)", () => {
const children = paragraphChildren(parse("issue#42 in GitHub"))
- const messageRef = children.find((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRef).toMatchObject({ type: "messageRef", value: "#42" })
- // The word before keeps its text; only the #42 becomes a ref.
- expect(children[0]).toMatchObject({ type: "text", value: "issue" })
+ expect(children.every((c) => c.type === "text")).toBe(true)
})
- it("parses #NUMBER with NO space in various glued forms", () => {
- expect(paragraphChildren(parse("text#123")).find((c) => c.type === "messageRef")).toMatchObject({ value: "#123" })
- // CJK glued form + full-width terminator: 见#42。 → msgref #42 + literal 。
- const cjk = paragraphChildren(parse("见#42。"))
- expect(cjk.find((c) => c.type === "messageRef")).toMatchObject({ value: "#42" })
- expect(cjk.some((c) => c.type === "text" && c.value === "。")).toBe(true)
+ it("a channel-message ref /server/channel#N is a channelRef carrying the seq", () => {
+ const children = paragraphChildren(parse("see /studio/general#42 done"))
+ const ref = children.find((c): c is ChannelRefNode => c.type === "channelRef")
+ expect(ref).toMatchObject({ type: "channelRef", value: "/studio/general#42" })
})
- it("a valid @name#0042 handle is still a mention, not a name + message ref (mention pass runs first)", () => {
- // Dropping the leading-space boundary must NOT split #0042 out of a real
- // mention — the mention pass runs before the message-ref pass and consumes
- // the whole handle.
+ it("a thread-message ref /server/channel/#N#M stays a single channelRef", () => {
+ const children = paragraphChildren(parse("see /studio/general/#5#42 done"))
+ const refs = children.filter((c): c is ChannelRefNode => c.type === "channelRef")
+ expect(refs).toHaveLength(1)
+ expect(refs[0]).toMatchObject({ value: "/studio/general/#5#42" })
+ })
+
+ it("a valid @name#0042 handle is still a mention, never split (mention pass runs first)", () => {
const children = paragraphChildren(parse("@Alice#0042"))
- expect(children.some((c) => c.type === "messageRef")).toBe(false)
expect(children[0]).toMatchObject({ type: "mention", value: "@Alice", discriminator: "0042" })
})
- it("an INVALID @name#42 (2-digit, not a mention) now yields text + message ref #42", () => {
- // Documented consequence: @Alice#42 isn't a valid 4-digit handle, so it's
- // not a mention; with the leading boundary gone, its #42 reads as a msgref.
+ it("an INVALID @name#42 (2-digit, not a mention) is now plain text (no bare-#N ref)", () => {
const children = paragraphChildren(parse("@Alice#42"))
expect(children.some((c) => c.type === "mention")).toBe(false)
- expect(children.find((c) => c.type === "messageRef")).toMatchObject({ value: "#42" })
+ expect(children.every((c) => c.type === "text")).toBe(true)
})
- it("parses multiple message refs in one message", () => {
- const children = paragraphChildren(parse("See #10 and #20"))
- const messageRefs = children.filter((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRefs.map((m) => m.value)).toEqual(["#10", "#20"])
+ it("a numeric URL fragment is now plain text (no bare-#N pill — the fragile GitHub#42 case is gone)", () => {
+ // The old no-leading-space MESSAGE_REF_RE turned `github.com/foo/bar#42`
+ // into a pill; with full-path-only refs it's plain text. `foo/bar` is not a
+ // prefix-anchored `/seg/seg` path (no leading `/`), so it isn't a channelRef
+ // either. This is the disambiguation win Gus asked for.
+ const children = paragraphChildren(parse("see github.com/foo/bar#42"))
+ expect(children.every((c) => c.type === "text")).toBe(true)
+ expect(children.some((c) => c.type === "channelRef")).toBe(false)
})
- it("does NOT parse inside code blocks", () => {
+ it("a bare #N inside inline code stays code (unchanged)", () => {
const children = paragraphChildren(parse("`#42`"))
- expect(children.some((c) => c.type === "messageRef")).toBe(false)
- })
-
- it("parses #NUMBER with trailing punctuation", () => {
- const children = paragraphChildren(parse("Fixed in #123."))
- const messageRef = children.find((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRef).toMatchObject({ value: "#123" })
- })
-
- it("does NOT parse 7+ digit numbers", () => {
- const children = paragraphChildren(parse("ref #9999999"))
- expect(children.some((c) => c.type === "messageRef")).toBe(false)
- })
-
- it("CONSEQUENCE of no-leading-space: a numeric URL fragment now reads as a message ref", () => {
- // Documented tradeoff of Gus #94 (approved #105): dropping the leading
- // boundary means `…#42` glued to a URL becomes a message-ref pill.
- // `github.com/foo/bar#42` → text + messageRef `#42`. Non-numeric fragments
- // (`#section`) are unaffected. Flagged to Gus; this test pins the behavior
- // so it's a deliberate decision, not a silent regression.
- const numeric = paragraphChildren(parse("see github.com/foo/bar#42"))
- expect(numeric.find((c) => c.type === "messageRef")).toMatchObject({ value: "#42" })
-
- const nonNumeric = paragraphChildren(parse("see example.com/page#section"))
- expect(nonNumeric.some((c) => c.type === "messageRef")).toBe(false)
+ expect(children.map((c) => c.type)).toEqual(["inlineCode"])
})
})
@@ -368,13 +349,12 @@ describe("chatSyntaxPlugin — mixed", () => {
expect(serverRef).toMatchObject({ value: "/studio" })
})
- it("handles mention, message ref, and channel ref together", () => {
- const children = paragraphChildren(parse("@Alice#0001 check #42 in /studio/general"))
+ it("handles mention, a full-path message ref, and a channel ref together", () => {
+ const children = paragraphChildren(parse("@Alice#0001 check /studio/general#42 in /studio/dev"))
const mention = children.find((c): c is MentionNode => c.type === "mention")
expect(mention).toMatchObject({ value: "@Alice", discriminator: "0001" })
- const messageRef = children.find((c): c is MessageRefNode => c.type === "messageRef")
- expect(messageRef).toMatchObject({ value: "#42" })
- const channelRef = children.find((c): c is ChannelRefNode => c.type === "channelRef")
- expect(channelRef).toMatchObject({ value: "/studio/general" })
+ const refs = children.filter((c): c is ChannelRefNode => c.type === "channelRef")
+ // Two channelRefs: the message ref (with seq) and the plain channel ref.
+ expect(refs.map((r) => r.value)).toEqual(["/studio/general#42", "/studio/dev"])
})
})
diff --git a/src/web/src/lib/community/chat-syntax-plugin.ts b/src/web/src/lib/community/chat-syntax-plugin.ts
index 2732c3633..d180cc1d9 100644
--- a/src/web/src/lib/community/chat-syntax-plugin.ts
+++ b/src/web/src/lib/community/chat-syntax-plugin.ts
@@ -68,7 +68,19 @@ import type { SpoilerNode } from "./spoiler-syntax"
// 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")
+// `/server/channel` plus an optional message/thread suffix. The suffix has two
+// branches (message-ref-upgrade.md):
+// `#\d+` — a channel-MESSAGE ref, seq glued straight to the channel
+// (`/server/channel#N`). Single seq ONLY — `#N#M` without a
+// slash is not a valid form (Cecilia #295, load-bearing).
+// `/#\d+(?:#\d+)?` — a THREAD (`/server/channel/#N`) or thread-message
+// (`/server/channel/#N#M`) ref; the inner `#M` lives only
+// on this slash branch.
+// `REF_SEG` excludes `#`, so the 2nd segment stops at the `#` and the seq falls
+// cleanly into the suffix group. The leading `(?<=^|\s)` prefix-anchor means this
+// only ever matches a full path — never a bare `#` — which is what lets us drop
+// the old bare-`#N` MESSAGE_REF pass and root-solve the disambiguation Gus flagged.
+const CHANNEL_REF_RE = new RegExp(`(?<=^|\\s)/${REF_SEG}/${REF_SEG}(?:#\\d+|/#\\d+(?:#\\d+)?)?(?=\\s|$|[${REF_TERM}])`, "gu")
// A bare `/server` ref — one segment, no channel. Same boundary lookaround as
// `CHANNEL_REF_RE` (leading `(?<=^|\s)`, trailing `REF_TERM`), which already
@@ -83,25 +95,12 @@ const CHANNEL_REF_RE = new RegExp(`(?<=^|\\s)/${REF_SEG}/${REF_SEG}(?:/#\\d+(?:#
// 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).
-// DELIBERATELY has NO leading `(?<=^|\s)` boundary (unlike channel/server
-// refs): a `#NNN` glued to a preceding word — `issue#42`, `text#123`, `见#42`
-// — SHOULD render as a message-ref pill. Agents dislike prepending a space
-// before a ref, so requiring one dropped the pill in practice (Gus #94, approved
-// #105). This intentionally reverses the older "avoid GitHub issue#42" rule.
-// Trailing boundary reuses the shared `REF_TERM` set (ASCII + full-width CJK
-// terminators) + `u` flag, matching the channel/server refs above, so `见#42。`
-// terminates cleanly before the full-width period. Still 1–6 digits, so 7+
-// digit runs (`#9999999`) don't match. Channel-scoped: `#123` = message seq 123
-// in the current channel, not a global id. Registered LAST in the pass list
-// (after mention AND channel/server refs — see `chatSyntaxPlugin`): the mention
-// pass consumes a valid `@Alice#0042` handle first (so its `#0042` is never
-// split out), and the channelRef pass consumes thread refs `/server/channel/#N`
-// first (so this pass, now lacking a leading-space boundary, can't steal the
-// `#N` out of them). By the time it runs it only sees a genuine standalone
-// `#N`. (An INVALID handle like `@Alice#42` — 2 digits, not a mention — does
-// now yield `@Alice` + msgref `#42`; accepted, minor.)
-const MESSAGE_REF_RE = new RegExp(`#\\d{1,6}(?=\\s|$|[${REF_TERM}])`, "gu")
+// (The old bare-`#N` MESSAGE_REF_RE was removed in message-ref-upgrade.md — a
+// message ref is now always the full path `/server/channel#N`, matched by
+// CHANNEL_REF_RE's suffix group above. A bare `#N` now renders as plain text.
+// This kills the fragile "works only because it's the last consumption pass"
+// disambiguation: the prefix-anchored full-path form can't collide with a bare
+// `#`, so no ordering hazard with mentions/spoilers/other `#` syntax.)
// Two-branch mention grammar (see plans/mandatory-mention-discriminator.md):
//
@@ -147,25 +146,16 @@ export interface ServerRefNode {
value: string
}
-/** mdast node produced by `#NUMBER` (message seq ref in current channel). */
-export interface MessageRefNode {
- type: "messageRef"
- /** The full matched string including `#` (e.g., `"#123"`). */
- value: string
-}
-
declare module "mdast" {
interface RootContentMap {
mention: MentionNode
channelRef: ChannelRefNode
serverRef: ServerRefNode
- messageRef: MessageRefNode
}
interface PhrasingContentMap {
mention: MentionNode
channelRef: ChannelRefNode
serverRef: ServerRefNode
- messageRef: MessageRefNode
}
}
@@ -193,13 +183,9 @@ function serverRefReplacer(value: string): ServerRefNode {
return { type: "serverRef", value }
}
-function messageRefReplacer(value: string): MessageRefNode {
- return { type: "messageRef", value }
-}
-
/**
* remark plugin: combines the spoiler micromark extension (`spoiler-syntax.ts`)
- * with a `mdast-util-find-and-replace` pass for `mention`/`channelRef`/`messageRef`.
+ * with a `mdast-util-find-and-replace` pass for `mention`/`channelRef`.
* Registers `spoilerSyntax`'s micromark/from-markdown extensions on the
* processor (the `remark-gfm`-style `this.data(...)` convention) and returns
* a tree transform running the find-and-replace pass after parsing.
@@ -223,15 +209,6 @@ export const chatSyntaxPlugin: Plugin<[], Root> = function chatSyntaxPlugin(this
// a `text` node `findAndReplace` visits), so this pass only ever sees
// genuine bare `/server` refs among the remaining text.
[SERVER_REF_RE, serverRefReplacer as unknown as (value: string) => PhrasingContent],
- // Runs LAST (after both channel/server ref passes). MESSAGE_REF_RE has
- // no leading-space boundary (a `#N` glued to a word must pill — Gus
- // #94), so if it ran before channelRef it would steal the `#N` out of a
- // thread ref (`/server/channel/#N`, `/#N#M`) before channelRef could
- // claim the whole span. Running it last means those thread refs are
- // already `channelRef` elements (not text nodes findAndReplace revisits),
- // so this pass only ever sees a genuine standalone `#N`. Same
- // consume-the-larger-token-first discipline that puts MENTION first.
- [MESSAGE_REF_RE, messageRefReplacer as unknown as (value: string) => PhrasingContent],
],
{ ignore: IGNORE_NODE_TYPES },
)
@@ -271,10 +248,4 @@ export const chatSyntaxHandlers: Handlers = {
properties: {},
children: [{ type: "text", value: node.value }],
})) as Handler,
- messageRef: ((_state, node: MessageRefNode): Element => ({
- type: "element",
- tagName: "messageref",
- properties: {},
- children: [{ type: "text", value: node.value }],
- })) as Handler,
}