🤯 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
⚡️ perf(task): page the task activity feed instead of mounting every entry (#22155)
Rdmclin2ea569e74e963
diff --git a/locales/ar/chat.json b/locales/ar/chat.jsonindex b96a47e7a39..168f782af8c 100644--- a/locales/ar/chat.json+++ b/locales/ar/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> غيّر الأولوية من <from/> إلى <to/>","taskDetail.activities.status.changed": "<actor/> غيّر الحالة من <from/> إلى <to/>","taskDetail.activitiesEmpty": "لا توجد أي نشاطات بعد",+ "taskDetail.activitiesLoadMore": "عرض النشاط الأقدم ({{count}})","taskDetail.addSubtask": "إضافة مهمة فرعية","taskDetail.artifactInaccessible": "المستند غير متاح — لا يوجد وصول","taskDetail.artifactMenu.delete": "إزالة من المهمة",diff --git a/locales/bg-BG/chat.json b/locales/bg-BG/chat.jsonindex 51423aa3456..61e67a00ca6 100644--- a/locales/bg-BG/chat.json+++ b/locales/bg-BG/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> промени приоритета от <from/> на <to/>","taskDetail.activities.status.changed": "<actor/> промени статуса от <from/> на <to/>","taskDetail.activitiesEmpty": "Все още няма дейности",+ "taskDetail.activitiesLoadMore": "Покажи по-ранна активност ({{count}})","taskDetail.addSubtask": "Добавяне на подзадача","taskDetail.artifactInaccessible": "Недостъпен документ — няма достъп","taskDetail.artifactMenu.delete": "Премахни от задачата",diff --git a/locales/de-DE/chat.json b/locales/de-DE/chat.jsonindex acb486260ba..24f63f69e51 100644--- a/locales/de-DE/chat.json+++ b/locales/de-DE/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> hat die Priorität von <from/> zu <to/> geändert","taskDetail.activities.status.changed": "<actor/> hat den Status von <from/> zu <to/> geändert","taskDetail.activitiesEmpty": "Noch keine Aktivitäten",+ "taskDetail.activitiesLoadMore": "Frühere Aktivitäten anzeigen ({{count}})","taskDetail.addSubtask": "Teilaufgabe hinzufügen","taskDetail.artifactInaccessible": "Nicht verfügbares Dokument — kein Zugriff","taskDetail.artifactMenu.delete": "Aus Aufgabe entfernen",diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 31f220609b3..5a8ce8de38b 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -2421,6 +2421,7 @@"taskDetail.activities.priority.changed": "<actor/> changed the priority from <from/> to <to/>","taskDetail.activities.status.changed": "<actor/> changed the status from <from/> to <to/>","taskDetail.activitiesEmpty": "No activity yet",+ "taskDetail.activitiesLoadMore": "Show earlier activity ({{count}})","taskDetail.addSubtask": "Add sub-task","taskDetail.artifactInaccessible": "Unavailable document — no access","taskDetail.artifactMenu.delete": "Remove from task",diff --git a/locales/es-ES/chat.json b/locales/es-ES/chat.jsonindex 6ce6986a690..e4fccdbb18a 100644--- a/locales/es-ES/chat.json+++ b/locales/es-ES/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> cambió la prioridad de <from/> a <to/>","taskDetail.activities.status.changed": "<actor/> cambió el estado de <from/> a <to/>","taskDetail.activitiesEmpty": "Aún no hay actividad",+ "taskDetail.activitiesLoadMore": "Mostrar actividad anterior ({{count}})","taskDetail.addSubtask": "Añadir subtarea","taskDetail.artifactInaccessible": "Documento no disponible — sin acceso","taskDetail.artifactMenu.delete": "Quitar de la tarea",diff --git a/locales/fa-IR/chat.json b/locales/fa-IR/chat.jsonindex db4d7eb9cc3..c5501a1f3e9 100644--- a/locales/fa-IR/chat.json+++ b/locales/fa-IR/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> اولویت را از <from/> به <to/> تغییر داد","taskDetail.activities.status.changed": "<actor/> وضعیت را از <from/> به <to/> تغییر داد","taskDetail.activitiesEmpty": "هنوز فعالیتی وجود ندارد",+ "taskDetail.activitiesLoadMore": "نمایش فعالیتهای قبلی ({{count}})","taskDetail.addSubtask": "افزودن زیروظیفه","taskDetail.artifactInaccessible": "سند در دسترس نیست — دسترسی وجود ندارد","taskDetail.artifactMenu.delete": "حذف از وظیفه",diff --git a/locales/fr-FR/chat.json b/locales/fr-FR/chat.jsonindex bbff43f6c29..3913ea46960 100644--- a/locales/fr-FR/chat.json+++ b/locales/fr-FR/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> a changé la priorité de <from/> à <to/>","taskDetail.activities.status.changed": "<actor/> a changé le statut de <from/> à <to/>","taskDetail.activitiesEmpty": "Aucune activité pour le moment",+ "taskDetail.activitiesLoadMore": "Afficher l’activité antérieure ({{count}})","taskDetail.addSubtask": "Ajouter une sous-tâche","taskDetail.artifactInaccessible": "Document indisponible — accès refusé","taskDetail.artifactMenu.delete": "Retirer de la tâche",diff --git a/locales/it-IT/chat.json b/locales/it-IT/chat.jsonindex e26ee5af68d..cd5323e4e90 100644--- a/locales/it-IT/chat.json+++ b/locales/it-IT/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> ha modificato la priorità da <from/> a <to/>","taskDetail.activities.status.changed": "<actor/> ha modificato lo stato da <from/> a <to/>","taskDetail.activitiesEmpty": "Nessuna attività",+ "taskDetail.activitiesLoadMore": "Mostra attività precedenti ({{count}})","taskDetail.addSubtask": "Aggiungi sotto-attività","taskDetail.artifactInaccessible": "Documento non disponibile — nessun accesso","taskDetail.artifactMenu.delete": "Rimuovi dal task",diff --git a/locales/ja-JP/chat.json b/locales/ja-JP/chat.jsonindex b45280c51e4..302f464abfc 100644--- a/locales/ja-JP/chat.json+++ b/locales/ja-JP/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> が優先度を <from/> から <to/> に変更しました","taskDetail.activities.status.changed": "<actor/> がステータスを <from/> から <to/> に変更しました","taskDetail.activitiesEmpty": "まだアクティビティはありません",+ "taskDetail.activitiesLoadMore": "以前のアクティビティを表示({{count}})","taskDetail.addSubtask": "サブタスクを追加","taskDetail.artifactInaccessible": "利用できないドキュメント — アクセス不可","taskDetail.artifactMenu.delete": "タスクから削除",diff --git a/locales/ko-KR/chat.json b/locales/ko-KR/chat.jsonindex 8f87f20eb07..472cd9d0c46 100644--- a/locales/ko-KR/chat.json+++ b/locales/ko-KR/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/>이(가) 우선순위를 <from/>에서 <to/>로 변경했습니다","taskDetail.activities.status.changed": "<actor/>이(가) 상태를 <from/>에서 <to/>로 변경했습니다","taskDetail.activitiesEmpty": "아직 활동이 없습니다",+ "taskDetail.activitiesLoadMore": "이전 활동 보기 ({{count}})","taskDetail.addSubtask": "하위 작업 추가","taskDetail.artifactInaccessible": "이용 불가 문서 — 접근 불가","taskDetail.artifactMenu.delete": "작업에서 제거",diff --git a/locales/nl-NL/chat.json b/locales/nl-NL/chat.jsonindex 5fef35896c4..5d492bb586f 100644--- a/locales/nl-NL/chat.json+++ b/locales/nl-NL/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> heeft de prioriteit gewijzigd van <from/> naar <to/>","taskDetail.activities.status.changed": "<actor/> heeft de status gewijzigd van <from/> naar <to/>","taskDetail.activitiesEmpty": "Nog geen activiteit",+ "taskDetail.activitiesLoadMore": "Eerdere activiteit tonen ({{count}})","taskDetail.addSubtask": "Subtaak toevoegen","taskDetail.artifactInaccessible": "Niet beschikbaar document — geen toegang","taskDetail.artifactMenu.delete": "Uit taak verwijderen",diff --git a/locales/pl-PL/chat.json b/locales/pl-PL/chat.jsonindex 693e6a4a51e..60cceefdec8 100644--- a/locales/pl-PL/chat.json+++ b/locales/pl-PL/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> zmienił priorytet z <from/> na <to/>","taskDetail.activities.status.changed": "<actor/> zmienił status z <from/> na <to/>","taskDetail.activitiesEmpty": "Brak aktywności",+ "taskDetail.activitiesLoadMore": "Pokaż wcześniejszą aktywność ({{count}})","taskDetail.addSubtask": "Dodaj podzadanie","taskDetail.artifactInaccessible": "Dokument niedostępny — brak dostępu","taskDetail.artifactMenu.delete": "Usuń z zadania",diff --git a/locales/pt-BR/chat.json b/locales/pt-BR/chat.jsonindex 15a02e299cf..056712e6ae4 100644--- a/locales/pt-BR/chat.json+++ b/locales/pt-BR/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> alterou a prioridade de <from/> para <to/>","taskDetail.activities.status.changed": "<actor/> alterou o status de <from/> para <to/>","taskDetail.activitiesEmpty": "Nenhuma atividade ainda",+ "taskDetail.activitiesLoadMore": "Mostrar atividade anterior ({{count}})","taskDetail.addSubtask": "Adicionar subtarefa","taskDetail.artifactInaccessible": "Documento indisponível — sem acesso","taskDetail.artifactMenu.delete": "Remover da tarefa",diff --git a/locales/ru-RU/chat.json b/locales/ru-RU/chat.jsonindex ab38d0a3f8f..d0c25872252 100644--- a/locales/ru-RU/chat.json+++ b/locales/ru-RU/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> изменил приоритет с <from/> на <to/>","taskDetail.activities.status.changed": "<actor/> изменил статус с <from/> на <to/>","taskDetail.activitiesEmpty": "Активности пока нет",+ "taskDetail.activitiesLoadMore": "Показать более раннюю активность ({{count}})","taskDetail.addSubtask": "Добавить подзадачу","taskDetail.artifactInaccessible": "Недоступный документ — нет доступа","taskDetail.artifactMenu.delete": "Удалить из задачи",diff --git a/locales/tr-TR/chat.json b/locales/tr-TR/chat.jsonindex e480fc6c3fd..1b946e857c6 100644--- a/locales/tr-TR/chat.json+++ b/locales/tr-TR/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> önceliği <from/> değerinden <to/> değerine değiştirdi","taskDetail.activities.status.changed": "<actor/> durumu <from/> değerinden <to/> değerine değiştirdi","taskDetail.activitiesEmpty": "Henüz aktivite yok",+ "taskDetail.activitiesLoadMore": "Önceki etkinliği göster ({{count}})","taskDetail.addSubtask": "Alt görev ekle","taskDetail.artifactInaccessible": "Kullanılamayan belge — erişim yok","taskDetail.artifactMenu.delete": "Görevden kaldır",diff --git a/locales/vi-VN/chat.json b/locales/vi-VN/chat.jsonindex 8bb6e2cee08..39935c65e19 100644--- a/locales/vi-VN/chat.json+++ b/locales/vi-VN/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> đã thay đổi mức độ ưu tiên từ <from/> thành <to/>","taskDetail.activities.status.changed": "<actor/> đã thay đổi trạng thái từ <from/> thành <to/>","taskDetail.activitiesEmpty": "Chưa có hoạt động nào",+ "taskDetail.activitiesLoadMore": "Hiển thị hoạt động trước đó ({{count}})","taskDetail.addSubtask": "Thêm nhiệm vụ con","taskDetail.artifactInaccessible": "Tài liệu không khả dụng — không có quyền truy cập","taskDetail.artifactMenu.delete": "Gỡ khỏi tác vụ",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex 1f0b330774c..9ca4a1f3b60 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -2421,6 +2421,7 @@"taskDetail.activities.priority.changed": "<actor/> 将优先级从 <from/> 改为 <to/>","taskDetail.activities.status.changed": "<actor/> 将状态从 <from/> 改为 <to/>","taskDetail.activitiesEmpty": "暂无活动记录",+ "taskDetail.activitiesLoadMore": "查看更早的动态({{count}})","taskDetail.addSubtask": "添加子任务","taskDetail.artifactInaccessible": "无权访问的文稿","taskDetail.artifactMenu.delete": "从任务中移除",diff --git a/locales/zh-TW/chat.json b/locales/zh-TW/chat.jsonindex 9f9d4d090a2..05c63beecc2 100644--- a/locales/zh-TW/chat.json+++ b/locales/zh-TW/chat.json@@ -2386,6 +2386,7 @@"taskDetail.activities.priority.changed": "<actor/> 將優先級從 <from/> 更改為 <to/>","taskDetail.activities.status.changed": "<actor/> 將狀態從 <from/> 更改為 <to/>","taskDetail.activitiesEmpty": "尚無活動",+ "taskDetail.activitiesLoadMore": "查看更早的動態({{count}})","taskDetail.addSubtask": "新增子任務","taskDetail.artifactInaccessible": "不可用的文件 — 無法訪問","taskDetail.artifactMenu.delete": "從任務中移除",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 3b84d8a8f9a..4e44c47f503 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -2079,6 +2079,7 @@ export default {'taskDetail.goalTimeline.title': 'Round progress','taskDetail.activities': 'Activities','taskDetail.activitiesEmpty': 'No activity yet',+ 'taskDetail.activitiesLoadMore': 'Show earlier activity ({{count}})','taskDetail.artifacts': 'Artifacts','taskDetail.untitled': 'Untitled','taskDetail.artifactMenu.delete': 'Remove from task',diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskActivities.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskActivities.test.tsxnew file mode 100644index 00000000000..fd5e4105134--- /dev/null+++ b/src/features/AgentTasks/AgentTaskDetail/TaskActivities.test.tsx@@ -0,0 +1,202 @@+/**+ * @vitest-environment happy-dom+ */+import type { TaskDetailActivity } from '@lobechat/types';+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import TaskActivities from './TaskActivities';+import { ACTIVITY_PAGE_SIZE, sliceActivityPage } from './useActivityPaging';++const mocks = vi.hoisted(() => ({+ listeners: new Set<() => void>(),+ taskState: {} as any,+}));++vi.mock('@/store/task', async () => {+ const { useSyncExternalStore } = await import('react');+ const refresh = vi.fn();+ const subscribe = (listener: () => void) => {+ mocks.listeners.add(listener);+ return () => mocks.listeners.delete(listener);+ };+ return {+ useTaskStore: (selector: any) =>+ selector({+ ...useSyncExternalStore(subscribe, () => mocks.taskState),+ internal_refreshTaskDetail: refresh,+ }),+ };+});++vi.mock('react-i18next', () => ({+ Trans: () => null,+ useTranslation: () => ({+ t: (key: string, opts?: { count?: number }) =>+ opts?.count === undefined ? key : `${key}:${opts.count}`,+ }),+}));++vi.mock('./CommentCard', () => ({+ default: ({ activity }: { activity: TaskDetailActivity }) => (+ <div data-testid={'comment'}>{activity.content}</div>+ ),+}));+vi.mock('./TopicCard', () => ({+ default: ({ activity }: { activity: TaskDetailActivity }) => (+ <div data-testid={'topic'}>{activity.title}</div>+ ),+}));+vi.mock('./TaskRunReport', () => ({+ default: ({ activity }: { activity: TaskDetailActivity }) => (+ <div data-testid={'report'}>{activity.title}</div>+ ),+}));+vi.mock('./CommentInput', () => ({ default: () => null }));+vi.mock('./TaskBriefCard', () => ({ default: () => null }));++const comment = (i: number): TaskDetailActivity => ({+ content: `comment-${i}`,+ id: `c-${i}`,+ time: new Date(Date.UTC(2026, 0, 1, 0, 0, i)).toISOString(),+ type: 'comment',+});++const setActivities = (taskId: string, activities: TaskDetailActivity[]) => {+ mocks.taskState = {+ activeTaskId: taskId,+ taskDetailMap: { [taskId]: { activities, id: taskId, identifier: taskId } },+ };+ mocks.listeners.forEach((listener) => listener());+};++describe('sliceActivityPage', () => {+ it('returns everything when the list fits', () => {+ expect(sliceActivityPage([1, 2, 3], 20)).toEqual({ remaining: 0, visible: [1, 2, 3] });+ });++ it('keeps the head of the list and counts the rest', () => {+ const { remaining, visible } = sliceActivityPage(+ Array.from({ length: 50 }, (_, i) => i),+ 20,+ );+ expect(visible).toHaveLength(20);+ expect(visible[0]).toBe(0);+ expect(remaining).toBe(30);+ });+});++describe('TaskActivities paging', () => {+ beforeEach(() => {+ setActivities(+ 'T-1',+ Array.from({ length: 500 }, (_, i) => comment(i)),+ );+ });++ afterEach(() => {+ cleanup();+ });++ it('mounts only the newest page of a long feed', () => {+ render(<TaskActivities />);++ const rows = screen.getAllByTestId('comment');+ expect(rows).toHaveLength(ACTIVITY_PAGE_SIZE);+ // Newest first: the latest comment leads the feed.+ expect(rows[0].textContent).toBe('comment-499');+ expect(rows.at(-1)!.textContent).toBe(`comment-${500 - ACTIVITY_PAGE_SIZE}`);+ expect(screen.getByText('taskDetail.activitiesLoadMore:480')).toBeTruthy();+ });++ it('appends the next page on demand', () => {+ render(<TaskActivities />);++ fireEvent.click(screen.getByText('taskDetail.activitiesLoadMore:480'));++ expect(screen.getAllByTestId('comment')).toHaveLength(ACTIVITY_PAGE_SIZE * 2);+ expect(screen.getByText('taskDetail.activitiesLoadMore:460')).toBeTruthy();+ });++ it('hides the load-more control when the feed fits one page', () => {+ setActivities('T-1', [comment(1), comment(2)]);+ render(<TaskActivities />);++ expect(screen.getAllByTestId('comment')).toHaveLength(2);+ expect(screen.queryByText(/taskDetail\.activitiesLoadMore/)).toBeNull();+ });++ it('starts from the first page again when another task opens', () => {+ render(<TaskActivities />);+ fireEvent.click(screen.getByText('taskDetail.activitiesLoadMore:480'));+ expect(screen.getAllByTestId('comment')).toHaveLength(ACTIVITY_PAGE_SIZE * 2);++ act(() =>+ setActivities(+ 'T-2',+ Array.from({ length: 100 }, (_, i) => comment(i)),+ ),+ );++ expect(screen.getAllByTestId('comment')).toHaveLength(ACTIVITY_PAGE_SIZE);+ });++ it('pages the result panel over the cards it shows, not lifecycle rows', () => {+ const lifecycle: TaskDetailActivity[] = Array.from({ length: 30 }, (_, i) => ({+ propertyChange: { field: 'status', from: 'running', to: 'paused' },+ time: new Date(Date.UTC(2026, 0, 2, 0, 0, i)).toISOString(),+ type: 'property',+ })) as TaskDetailActivity[];+ setActivities('T-1', [...Array.from({ length: 25 }, (_, i) => comment(i)), ...lifecycle]);++ render(<TaskActivities variant={'result'} />);++ expect(screen.getAllByTestId('comment')).toHaveLength(ACTIVITY_PAGE_SIZE);+ expect(screen.getByText('taskDetail.activitiesLoadMore:5')).toBeTruthy();+ });++ it('keeps the newest run report on the result panel first page under newer comments', () => {+ const run: TaskDetailActivity = {+ id: 'tpc-latest',+ time: new Date(Date.UTC(2026, 0, 1, 0, 0, 0)).toISOString(),+ title: 'latest-run',+ type: 'topic',+ };+ const olderRun: TaskDetailActivity = {+ id: 'tpc-older',+ time: new Date(Date.UTC(2025, 11, 31)).toISOString(),+ title: 'older-run',+ type: 'topic',+ };+ // 30 comments, all newer than the latest run.+ setActivities('T-1', [olderRun, run, ...Array.from({ length: 30 }, (_, i) => comment(i + 1))]);++ render(<TaskActivities variant={'result'} />);++ expect(screen.getByTestId('report').textContent).toBe('latest-run');+ expect(screen.getAllByTestId('comment')).toHaveLength(ACTIVITY_PAGE_SIZE);+ // 10 older comments + the older run remain; the pinned report is not counted.+ expect(screen.getByText('taskDetail.activitiesLoadMore:11')).toBeTruthy();++ fireEvent.click(screen.getByText('taskDetail.activitiesLoadMore:11'));++ // Once older entries are loaded the report sits in timeline order: after+ // every comment (all newer), before the older run.+ const order = screen.getAllByTestId(/^(comment|report|topic)$/).map((node) => node.textContent);+ expect(order.at(-2)).toBe('latest-run');+ expect(order.at(-1)).toBe('older-run');+ expect(screen.getAllByTestId('report')).toHaveLength(1);+ });++ it('auto-loads on scroll in the detail feed but not in the result panel', () => {+ const { unmount } = render(<TaskActivities />);+ expect(screen.getByTestId('activity-sentinel')).toBeTruthy();+ unmount();++ // Sections follow the feed in the result panel; a sentinel there would keep+ // loading pages above them as the reader scrolls toward them.+ render(<TaskActivities variant={'result'} />);+ expect(screen.queryByTestId('activity-sentinel')).toBeNull();+ expect(screen.getByText('taskDetail.activitiesLoadMore:480')).toBeTruthy();+ });+});diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskActivities.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskActivities.tsxindex 0b7cec719d5..4e280d86a1d 100644--- a/src/features/AgentTasks/AgentTaskDetail/TaskActivities.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TaskActivities.tsx@@ -4,7 +4,17 @@ import type {TaskDetailActivity,TaskDetailActivityAuthor,} from '@lobechat/types';-import { Avatar, Block, Collapsible, cssVar, Empty, Flexbox, Icon, Text } from '@lobehub/ui';+import {+ Avatar,+ Block,+ Button,+ Collapsible,+ cssVar,+ Empty,+ Flexbox,+ Icon,+ Text,+} from '@lobehub/ui';import type { TFunction } from 'i18next';import type { LucideIcon } from 'lucide-react';import {@@ -35,6 +45,7 @@ import CommentInput from './CommentInput';import TaskBriefCard from './TaskBriefCard';import TaskRunReport from './TaskRunReport';import TopicCard from './TopicCard';+import { useActivityPaging } from './useActivityPaging';const PRIORITY_NAME: Record<number, 'high' | 'low' | 'none' | 'normal' | 'urgent'> = {0: 'none',@@ -240,6 +251,9 @@ const AssignmentRow = memo<{ activity: TaskDetailActivity }>(({ activity }) => {);});+/** Activity types the result panel renders; everything else is lifecycle bookkeeping. */+const RESULT_ACTIVITY_TYPES = new Set<TaskDetailActivity['type']>(['brief', 'comment', 'topic']);+interface TaskActivitiesProps {/** Result review leads with run output and leaves the reply composer after the evidence. */variant?: 'activity' | 'result';@@ -402,11 +416,47 @@ const TaskActivities = memo<TaskActivitiesProps>(({ variant = 'activity' }) => {[activities],);- const commentInput = activeTaskId ? <CommentInput taskId={activeTaskId} /> : null;-// A goal loop can produce many rounds; only the newest run opens by default so// the latest result is not buried under older ones.- const firstTopicKey = items.find(({ activity }) => activity.type === 'topic')?.key;+ const firstTopicIndex = items.findIndex(({ activity }) => activity.type === 'topic');+ const firstTopicKey = firstTopicIndex === -1 ? undefined : items[firstTopicIndex].key;++ // The result panel drops lifecycle bookkeeping, so page over what it shows —+ // otherwise a page of status flips would render as an empty page. Its newest+ // run is the report the panel exists for, so it is pinned outside the pager+ // rather than paged away behind a burst of newer comments.+ const resultReport =+ variant === 'result' && firstTopicIndex !== -1 ? items[firstTopicIndex] : null;+ const pageableItems = useMemo(+ () =>+ variant === 'result'+ ? items.filter(+ ({ activity, key }) =>+ RESULT_ACTIVITY_TYPES.has(activity.type) && key !== firstTopicKey,+ )+ : items,+ [items, variant, firstTopicKey],+ );+ // The result panel's verdict and artifacts sit below the feed, so it pages+ // on demand only — auto-loading would push them away as the reader scrolls+ // toward them. The detail page's feed is its last section.+ const {+ autoLoad,+ loadMore,+ remaining,+ sentinelRef,+ visible: page,+ } = useActivityPaging(pageableItems, activeTaskId, { autoLoad: variant !== 'result' });+ // Put the pinned report back in timeline order among what is loaded: after+ // the newer entries on screen, before older ones once they are loaded.+ const visible = useMemo(() => {+ if (!resultReport) return page;+ const order = new Map(items.map(({ key }, i) => [key, i]));+ return [...page, resultReport].sort((a, b) => order.get(a.key)! - order.get(b.key)!);+ }, [page, resultReport, items]);++ const commentInput = activeTaskId ? <CommentInput taskId={activeTaskId} /> : null;+// Compact lines that sit next to each other share one rail, so the marks// read as a timeline; a card (comment, run, brief) breaks the rail.const withRail = (nodes: ReactNode[]): ReactNode[] => {@@ -440,7 +490,7 @@ const TaskActivities = memo<TaskActivitiesProps>(({ variant = 'activity' }) => {const rows =items.length > 0 ? (withRail(- items.map(({ activity, brief, key }) => {+ visible.map(({ activity, brief, key }) => {if (brief) {return (<TaskBriefCard@@ -485,6 +535,23 @@ const TaskActivities = memo<TaskActivitiesProps>(({ variant = 'activity' }) => {/>);+ const loadMoreFooter =+ remaining > 0 ? (+ <>+ {autoLoad && (+ <div+ aria-hidden+ data-testid={'activity-sentinel'}+ ref={sentinelRef}+ style={{ height: 1 }}+ />+ )}+ <Button size={'small'} style={{ alignSelf: 'center' }} type={'text'} onClick={loadMore}>+ {t('taskDetail.activitiesLoadMore', { count: remaining })}+ </Button>+ </>+ ) : null;+// The Portal header already names the task and the report is the only thing// in this section, so a collapsible "运行结果" band above it labels a section// of one and eats the top of the reading surface.@@ -492,7 +559,13 @@ const TaskActivities = memo<TaskActivitiesProps>(({ variant = 'activity' }) => {// Leaving a note for the next run is one of the report's own actions, which// opens the editor on demand instead of parking an empty box under every// report.- if (variant === 'result') return <Flexbox gap={12}>{rows}</Flexbox>;+ if (variant === 'result')+ return (+ <Flexbox gap={12}>+ {rows}+ {loadMoreFooter}+ </Flexbox>+ );return (<Flexbox gap={8}>@@ -517,6 +590,7 @@ const TaskActivities = memo<TaskActivitiesProps>(({ variant = 'activity' }) => {<Flexbox gap={12} paddingBlock={4} paddingInline={12}>{commentInput}{rows}+ {loadMoreFooter}</Flexbox></Collapsible></Flexbox>diff --git a/src/features/AgentTasks/AgentTaskDetail/useActivityPaging.ts b/src/features/AgentTasks/AgentTaskDetail/useActivityPaging.tsnew file mode 100644index 00000000000..eee1e7460cf--- /dev/null+++ b/src/features/AgentTasks/AgentTaskDetail/useActivityPaging.ts@@ -0,0 +1,70 @@+import { useCallback, useEffect, useRef, useState } from 'react';++/**+ * Activity entries mounted per page. A scheduled task can accumulate hundreds+ * of runs and comments, each a heavy card (markdown, run summary); mounting+ * them all at once is what makes a long-lived task's page freeze. The feed is+ * newest-first, so the first page is the part a reader actually came for.+ */+export const ACTIVITY_PAGE_SIZE = 20;++export const sliceActivityPage = <T>(items: T[], visibleCount: number) => {+ const visible = items.length > visibleCount ? items.slice(0, visibleCount) : items;+ return { remaining: items.length - visible.length, visible };+};++interface ActivityPagingOptions {+ /**+ * Append a page when the sentinel below the list scrolls into view. Only+ * safe when nothing follows the feed: with sections below it, scrolling+ * toward them would keep loading pages above them until the whole history+ * is mounted.+ */+ autoLoad?: boolean;+}++/**+ * Newest-first paging for the activity feed: shows `ACTIVITY_PAGE_SIZE`+ * entries, then appends another page when the sentinel below the list scrolls+ * into view (`autoLoad`) or the fallback button is pressed. Resets when the+ * task changes.+ */+export const useActivityPaging = <T>(+ items: T[],+ resetKey: string | undefined,+ { autoLoad = true }: ActivityPagingOptions = {},+) => {+ const [visibleCount, setVisibleCount] = useState(ACTIVITY_PAGE_SIZE);++ // Reset during render (not in an effect) so a newly opened task never+ // mounts the previous task's expanded page for a frame.+ const [lastResetKey, setLastResetKey] = useState(resetKey);+ if (lastResetKey !== resetKey) {+ setLastResetKey(resetKey);+ setVisibleCount(ACTIVITY_PAGE_SIZE);+ }++ const { remaining, visible } = sliceActivityPage(items, visibleCount);++ const loadMore = useCallback(() => setVisibleCount((n) => n + ACTIVITY_PAGE_SIZE), []);++ const sentinelRef = useRef<HTMLDivElement>(null);+ const hasMore = remaining > 0;+ const observe = autoLoad && hasMore;+ useEffect(() => {+ const element = sentinelRef.current;+ if (!element || !observe || typeof IntersectionObserver === 'undefined') return;+ const observer = new IntersectionObserver(+ (entries) => {+ if (entries[0]?.isIntersecting) loadMore();+ },+ { rootMargin: '240px' },+ );+ observer.observe(element);+ return () => observer.disconnect();+ // `visibleCount` re-arms the observer after each page: if the sentinel is+ // still in view (short cards), the fresh observer fires again.+ }, [observe, loadMore, visibleCount]);++ return { autoLoad, loadMore, remaining, sentinelRef, visible };+};