🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(topic): add Copy Topic Prompt to topic menu (#20011)
Arvin Xude97d00a5863
diff --git a/apps/cli/src/commands/topic.test.ts b/apps/cli/src/commands/topic.test.tsindex be2d34d33cc..b29767a2787 100644--- a/apps/cli/src/commands/topic.test.ts+++ b/apps/cli/src/commands/topic.test.ts@@ -257,6 +257,20 @@ describe('topic command', () => {expect(output()).toContain('Showing 1–2 of 2');});+ it('scopes the read to --workspace', async () => {+ await createProgram().parseAsync([+ 'node',+ 'test',+ 'topic',+ 'view',+ 't1',+ '--workspace',+ 'ws_1',+ ]);++ expect(mockGetTrpcClient).toHaveBeenCalledWith('ws_1');+ });+it('uses the aggregate endpoint without loading messages for --no-messages', async () => {mockTrpcClient.topic.getTopicTranscript.query.mockResolvedValue({items: [],diff --git a/apps/cli/src/commands/topic/view.ts b/apps/cli/src/commands/topic/view.tsindex 6ac37015b9b..824b4927698 100644--- a/apps/cli/src/commands/topic/view.ts+++ b/apps/cli/src/commands/topic/view.ts@@ -17,6 +17,7 @@ interface TopicViewOptions {limit?: string;messages?: boolean;to?: string;+ workspace?: string;}interface PersistedToolPayload {@@ -267,12 +268,16 @@ export function registerTopicViewCommand(topic: Command) {.option('--to <n>', 'Show messages up to this index (inclusive)').option('--no-messages', 'Skip messages, show topic metadata only').option('--json', 'Output JSON')+ .option(+ '--workspace <id>',+ "Read the topic from this workspace (overrides LOBEHUB_WORKSPACE_ID and 'workspace use')",+ ).action(async (id: string, options: TopicViewOptions) => {const includeMessages = options.messages !== false;const pagination = includeMessages? resolvePagination(options): { from: 1, limit: DEFAULT_LIMIT, offset: 0 };- const client = await getTrpcClient();+ const client = await getTrpcClient(options.workspace);const result = await client.topic.getTopicTranscript.query({includeMessages,limit: pagination.limit,diff --git a/locales/en-US/topic.json b/locales/en-US/topic.jsonindex 2534f0cdf44..f532af55390 100644--- a/locales/en-US/topic.json+++ b/locales/en-US/topic.json@@ -24,6 +24,8 @@"actions.copyLinkSuccess": "Link copied","actions.copySessionId": "Copy Topic ID","actions.copySessionIdSuccess": "Topic ID copied",+ "actions.copyTopicPrompt": "Copy Topic Prompt",+ "actions.copyTopicPromptSuccess": "Topic prompt copied","actions.copyWorkingDirectory": "Copy Working Directory","actions.copyWorkingDirectorySuccess": "Working directory copied","actions.diagnose": "Check Message Chain",diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.jsonindex 5bcb32a506f..3b94e319347 100644--- a/locales/zh-CN/topic.json+++ b/locales/zh-CN/topic.json@@ -22,12 +22,14 @@"actions.confirmRemoveUnstarredWorkspaceAcknowledge": "我已知晓此操作将永久删除其他成员创建的未收藏话题","actions.copyLink": "复制链接","actions.copyLinkSuccess": "链接已复制",- "actions.copySessionId": "复制会话 ID",- "actions.copySessionIdSuccess": "会话 ID 已复制",+ "actions.copySessionId": "复制话题 ID",+ "actions.copySessionIdSuccess": "话题 ID 已复制",+ "actions.copyTopicPrompt": "复制话题 Prompt",+ "actions.copyTopicPromptSuccess": "话题 Prompt 已复制","actions.copyWorkingDirectory": "复制工作目录","actions.copyWorkingDirectorySuccess": "工作目录已复制","actions.diagnose": "检查消息链路",- "actions.duplicate": "复制",+ "actions.duplicate": "拷贝","actions.export": "导出话题","actions.favorite": "收藏","actions.forwardToAgent": "转发给其他助手",diff --git a/packages/locales/src/default/topic.ts b/packages/locales/src/default/topic.tsindex 30ba1900a70..807ee920296 100644--- a/packages/locales/src/default/topic.ts+++ b/packages/locales/src/default/topic.ts@@ -33,6 +33,8 @@ export default {'actions.copyLinkSuccess': 'Link copied','actions.copySessionId': 'Copy Topic ID','actions.copySessionIdSuccess': 'Topic ID copied',+ 'actions.copyTopicPrompt': 'Copy Topic Prompt',+ 'actions.copyTopicPromptSuccess': 'Topic prompt copied','actions.copyWorkingDirectory': 'Copy Working Directory','actions.copyWorkingDirectorySuccess': 'Working directory copied','actions.duplicate': 'Duplicate',diff --git a/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.test.ts b/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.test.tsnew file mode 100644index 00000000000..140b53cbe11--- /dev/null+++ b/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from 'vitest';++import { buildTopicPrompt } from './buildTopicPrompt';++describe('buildTopicPrompt', () => {+ it('includes title, id and the CLI read command', () => {+ expect(buildTopicPrompt({ id: 'tpc_1', title: ' Debug CI ' })).toBe(+ [+ 'LobeHub topic: Debug CI (tpc_1)',+ '',+ 'Use the LobeHub CLI to read the full conversation history of this topic:',+ '',+ 'lh topic view tpc_1 -L 500',+ '',+ 'If the topic has more than 500 messages, page through the remainder with --from and --to.',+ ].join('\n'),+ );+ });++ it('falls back to the bare id when the title is blank', () => {+ expect(+ buildTopicPrompt({ id: 'tpc_1', title: ' ' }).startsWith('LobeHub topic: tpc_1\n\n'),+ ).toBe(true);+ });++ it('pins the CLI to the workspace the topic belongs to', () => {+ expect(buildTopicPrompt({ id: 'tpc_1', title: 'Debug CI', workspaceId: 'ws_1' })).toContain(+ '\nlh topic view tpc_1 -L 500 --workspace ws_1\n',+ );+ });+});diff --git a/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.ts b/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.tsnew file mode 100644index 00000000000..170f5976b8f--- /dev/null+++ b/src/features/AgentSidebar/Topic/List/Item/buildTopicPrompt.ts@@ -0,0 +1,24 @@+export interface BuildTopicPromptParams {+ id: string;+ title?: string;+ /**+ * Set for Workspace topics. Passed as `--workspace`, which outranks both the+ * CLI's own scope and the `LOBEHUB_WORKSPACE_ID` the cloud `lh` shim injects.+ */+ workspaceId?: string | null;+}++/**+ * A pasteable hand-off prompt for another agent (e.g. Claude Code) that points+ * it at this topic and tells it how to read the full history via the LobeHub CLI.+ */+export const buildTopicPrompt = ({ id, title, workspaceId }: BuildTopicPromptParams) =>+ [+ `LobeHub topic: ${title?.trim() ? `${title.trim()} (${id})` : id}`,+ '',+ 'Use the LobeHub CLI to read the full conversation history of this topic:',+ '',+ `lh topic view ${id} -L 500${workspaceId ? ` --workspace ${workspaceId}` : ''}`,+ '',+ 'If the topic has more than 500 messages, page through the remainder with --from and --to.',+ ].join('\n');diff --git a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsxindex 7f8aa6de528..078f412e325 100644--- a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx+++ b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx@@ -4,6 +4,7 @@import { renderHook } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { buildTopicPrompt } from './buildTopicPrompt';import { useTopicItemDropdownMenu } from './useDropdownMenu';const permissionMock = vi.hoisted(() => ({@@ -11,6 +12,7 @@ const permissionMock = vi.hoisted(() => ({edit_own_content: true,}));const versionMock = vi.hoisted(() => ({ isDesktop: false }));+const workspaceMock = vi.hoisted(() => ({ id: null as string | null }));vi.mock('antd', async (importOriginal) => ({...(await importOriginal<object>()),@@ -26,6 +28,10 @@ vi.mock('antd', async (importOriginal) => ({},}));+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({+ useActiveWorkspaceId: () => workspaceMock.id,+}));+vi.mock('@/components/RenameModal', () => ({openRenameModal: vi.fn(),}));@@ -99,6 +105,7 @@ describe('useTopicItemDropdownMenu', () => {permissionMock.create_content = true;permissionMock.edit_own_content = true;versionMock.isDesktop = false;+ workspaceMock.id = null;});afterEach(() => {@@ -109,6 +116,7 @@ describe('useTopicItemDropdownMenu', () => {it.each([['copySessionId', 'topic-1'],['copyLink', 'https://example.com/agent/agent-1/topic-1'],+ ['copyTopicPrompt', buildTopicPrompt({ id: 'topic-1', title: 'Topic 1' })],])('copies %s when the Clipboard API is unavailable', async (key, expected) => {vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue(undefined as never);let copiedText: string | undefined;@@ -130,6 +138,24 @@ describe('useTopicItemDropdownMenu', () => {expect(document.querySelector('textarea')).toBeNull();});+ it('scopes the copied topic prompt to the active workspace', async () => {+ workspaceMock.id = 'ws_1';+ const writeText = vi.fn().mockResolvedValue(undefined);+ vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as never);+ const { result } = renderHook(() =>+ useTopicItemDropdownMenu({ id: 'topic-1', title: 'Topic 1' }),+ );+ const item = getMenuItem(result.current.dropdownMenu(), 'copyTopicPrompt');+ if (!item || !('onClick' in item)) throw new Error('Expected copy action');++ await item.onClick?.({} as never);++ expect(writeText).toHaveBeenCalledWith(+ buildTopicPrompt({ id: 'topic-1', title: 'Topic 1', workspaceId: 'ws_1' }),+ );+ expect(writeText.mock.calls[0][0]).toContain('lh topic view topic-1 -L 500 --workspace ws_1');+ });+it('groups desktop topic actions by intent', () => {versionMock.isDesktop = true;@@ -152,6 +178,7 @@ describe('useTopicItemDropdownMenu', () => {'divider','copySessionId','copyLink',+ 'copyTopicPrompt','divider','duplicate','forwardToAgent',@@ -188,5 +215,6 @@ describe('useTopicItemDropdownMenu', () => {expect(getMenuItem(items, 'copySessionId')).not.toMatchObject({ disabled: true });expect(getMenuItem(items, 'copyLink')).not.toMatchObject({ disabled: true });+ expect(getMenuItem(items, 'copyTopicPrompt')).not.toMatchObject({ disabled: true });});});diff --git a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsxindex 6b46b26b88f..72b5fd50021 100644--- a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx+++ b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx@@ -13,6 +13,7 @@ import {Hash,Link2,LucideCopy,+ MessageSquareText,PanelRight,PanelTop,PencilLine,@@ -24,6 +25,7 @@ import {import { useCallback } from 'react';import { useTranslation } from 'react-i18next';+import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';import { openRenameModal } from '@/components/RenameModal';import { isDesktop } from '@/const/version';@@ -42,6 +44,8 @@ import { useElectronStore } from '@/store/electron';import { useGlobalStore } from '@/store/global';import { isForbiddenError } from '@/utils/forbiddenError';+import { buildTopicPrompt } from './buildTopicPrompt';+export interface TopicItemDropdownMenuProps {fav?: boolean;id?: string;@@ -58,6 +62,7 @@ export const useTopicItemDropdownMenu = ({const { t } = useTranslation(['topic', 'common', 'chat']);const navigate = useWorkspaceAwareNavigate();+ const activeWorkspaceId = useActiveWorkspaceId();const activeWorkspaceSlug = useActiveWorkspaceSlug();const { allowed: canCreateTopic } = usePermission('create_content');const { allowed: canEditTopic } = usePermission('edit_own_content');@@ -233,6 +238,15 @@ export const useTopicItemDropdownMenu = ({toast.success(t('actions.copyLinkSuccess'));},},+ {+ icon: <Icon icon={MessageSquareText} />,+ key: 'copyTopicPrompt',+ label: t('actions.copyTopicPrompt'),+ onClick: async () => {+ await copyToClipboard(buildTopicPrompt({ id, title, workspaceId: activeWorkspaceId }));+ toast.success(t('actions.copyTopicPromptSuccess'));+ },+ },{type: 'divider' as const,},@@ -311,6 +325,7 @@ export const useTopicItemDropdownMenu = ({canCreateTopic,canEditTopic,activeAgentId,+ activeWorkspaceId,activeWorkspaceSlug,appOrigin,autoRenameTopicTitle,