Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(task): show member names for id-only comment mentions (#21820)

Rdmclin27473c8c6eb36
diff --git a/src/features/AgentTasks/AgentTaskDetail/commentMarkdown.tsx b/src/features/AgentTasks/AgentTaskDetail/commentMarkdown.tsx
index 86f589e7452..a62cf854ed5 100644
--- a/src/features/AgentTasks/AgentTaskDetail/commentMarkdown.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/commentMarkdown.tsx
@@ -3,8 +3,13 @@ import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { memo } from 'react';
+import { useWorkspaceMemberProfiles } from '@/business/client/hooks/useWorkspaceMemberProfiles';
import { MENTION_TAG } from '@/const/plugin';
import { createRemarkSelfClosingTagPlugin } from '@/features/Conversation/Markdown/plugins/remarkPlugins/createRemarkSelfClosingTagPlugin';
+import { useUserStore } from '@/store/user';
+import { userProfileSelectors } from '@/store/user/selectors';
+
+import { resolveCommentMentionName } from './commentMentionName';
const styles = stylex.create({
mention: {
@@ -24,12 +29,16 @@ interface CommentMentionProps {
*/
const CommentMention = memo<CommentMentionProps>(({ node }) => {
const { id, name } = node?.properties || {};
- if (!name && !id) return null;
+ const memberProfiles = useWorkspaceMemberProfiles();
+ const currentUser = useUserStore(userProfileSelectors.userProfile);
+
+ const displayName = resolveCommentMentionName({ currentUser, id, memberProfiles, name });
+ if (!displayName) return null;
const { className, style } = stylex.props(styles.mention);
return (
<span className={`editor_mention ${className ?? ''}`} style={style}>
- @{name || id}
+ @{displayName}
</span>
);
});
diff --git a/src/features/AgentTasks/AgentTaskDetail/commentMentionName.test.ts b/src/features/AgentTasks/AgentTaskDetail/commentMentionName.test.ts
new file mode 100644
index 00000000000..e2d67d479e7
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskDetail/commentMentionName.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, it } from 'vitest';
+
+import { resolveCommentMentionName } from './commentMentionName';
+
+const memberProfiles = new Map([
+ ['user_member', { fullName: 'Arvin', username: 'arvin' }],
+ ['user_nameless', { fullName: null, username: 'nameless' }],
+]);
+
+describe('resolveCommentMentionName', () => {
+ it('shows a workspace member name for an id-only mention', () => {
+ expect(resolveCommentMentionName({ id: 'user_member', memberProfiles })).toBe('Arvin');
+ });
+
+ it('falls back to the username when the member has no full name', () => {
+ expect(resolveCommentMentionName({ id: 'user_nameless', memberProfiles })).toBe('nameless');
+ });
+
+ it('shows the signed-in user name when they are mentioned outside a workspace', () => {
+ expect(
+ resolveCommentMentionName({
+ currentUser: { fullName: 'Lin', id: 'user_self' },
+ id: 'user_self',
+ memberProfiles: new Map(),
+ }),
+ ).toBe('Lin');
+ });
+
+ it('prefers the current member name over a stale name in the tag', () => {
+ expect(resolveCommentMentionName({ id: 'user_member', memberProfiles, name: 'Old' })).toBe(
+ 'Arvin',
+ );
+ });
+
+ it('keeps the tag name for someone it cannot resolve', () => {
+ expect(resolveCommentMentionName({ id: 'user_former', memberProfiles, name: 'Former' })).toBe(
+ 'Former',
+ );
+ });
+
+ it('shows the raw id only as a last resort', () => {
+ expect(resolveCommentMentionName({ id: 'user_unknown', memberProfiles })).toBe('user_unknown');
+ expect(resolveCommentMentionName({ memberProfiles })).toBeUndefined();
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskDetail/commentMentionName.ts b/src/features/AgentTasks/AgentTaskDetail/commentMentionName.ts
new file mode 100644
index 00000000000..84e7de39781
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskDetail/commentMentionName.ts
@@ -0,0 +1,32 @@
+interface MentionProfile {
+ fullName?: string | null;
+ username?: string | null;
+}
+
+const profileName = (profile?: MentionProfile | null) =>
+ profile?.fullName || profile?.username || undefined;
+
+/**
+ * Display name of a mention tag. Agents and the CLI often write only
+ * `<mention id="user_xxx" />`, so resolve the id against the workspace members
+ * and the signed-in user first (this also picks up renames), then fall back to
+ * the name written in the tag, and to the raw id only as a last resort.
+ */
+export const resolveCommentMentionName = ({
+ currentUser,
+ id,
+ memberProfiles,
+ name,
+}: {
+ currentUser?: (MentionProfile & { id?: string }) | null;
+ id?: string;
+ memberProfiles: ReadonlyMap<string, MentionProfile>;
+ name?: string;
+}): string | undefined => {
+ const resolved =
+ id &&
+ (profileName(memberProfiles.get(id)) ||
+ (currentUser?.id === id ? profileName(currentUser) : undefined));
+
+ return resolved || name || id;
+};