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.

✨ feat(goal): default the goal list to All and split the filters (#20314)

Arvin Xu82514cd50809
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index ef1418a1511..4efb08d5926 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -563,11 +563,12 @@
"goalPage.allGoals": "All goals",
"goalPage.create": "Create goal",
"goalPage.description": "Track what this agent is pursuing and how close each goal is to acceptance.",
- "goalPage.filter.active": "In progress",
+ "goalPage.filter.achieved": "Completed",
"goalPage.filter.all": "All",
- "goalPage.filter.open": "Open goals",
- "goalPage.filteredEmptyDescription": "Switch to All to review completed or canceled goals.",
- "goalPage.filteredEmptyTitle": "No open goals",
+ "goalPage.filter.review": "Needs review",
+ "goalPage.filter.running": "In progress",
+ "goalPage.filteredEmptyDescription": "Switch to All to see every goal.",
+ "goalPage.filteredEmptyTitle": "No goals in this view",
"goalPage.listTitle": "Goal list",
"goalPage.loadMore": "Load more",
"goalPage.loadingProgress": "Loading acceptance progress…",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index bc435b1b8fe..9b64b3d1f7e 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -563,11 +563,12 @@
"goalPage.allGoals": "全部目标",
"goalPage.create": "创建目标",
"goalPage.description": "掌握 Agent 正在追逐什么,以及每个目标距离验收还有多远。",
- "goalPage.filter.active": "进行中",
+ "goalPage.filter.achieved": "已完成",
"goalPage.filter.all": "全部",
- "goalPage.filter.open": "待处理目标",
- "goalPage.filteredEmptyDescription": "切换到“全部”可查看已完成或已取消的目标。",
- "goalPage.filteredEmptyTitle": "没有待处理目标",
+ "goalPage.filter.review": "待审阅",
+ "goalPage.filter.running": "进行中",
+ "goalPage.filteredEmptyDescription": "切换到“全部”可查看所有目标。",
+ "goalPage.filteredEmptyTitle": "该筛选下暂无目标",
"goalPage.listTitle": "目标列表",
"goalPage.loadMore": "加载更多",
"goalPage.loadingProgress": "正在加载验收进度…",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 1554db15919..75ce8f3b513 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -2429,11 +2429,12 @@ export default {
'goalPage.description':
'Track what this agent is pursuing and how close each goal is to acceptance.',
'goalPage.create': 'Create goal',
- 'goalPage.filteredEmptyDescription': 'Switch to All to review completed or canceled goals.',
- 'goalPage.filteredEmptyTitle': 'No open goals',
- 'goalPage.filter.active': 'In progress',
+ 'goalPage.filteredEmptyDescription': 'Switch to All to see every goal.',
+ 'goalPage.filteredEmptyTitle': 'No goals in this view',
+ 'goalPage.filter.achieved': 'Completed',
'goalPage.filter.all': 'All',
- 'goalPage.filter.open': 'Open goals',
+ 'goalPage.filter.review': 'Needs review',
+ 'goalPage.filter.running': 'In progress',
'goalPage.loadingProgress': 'Loading acceptance progress…',
'goalPage.listTitle': 'Goal list',
'goalPage.loadMore': 'Load more',
diff --git a/src/components/Skeleton/Goal.tsx b/src/components/Skeleton/Goal.tsx
index 744909b034b..b618bc9a4a4 100644
--- a/src/components/Skeleton/Goal.tsx
+++ b/src/components/Skeleton/Goal.tsx
@@ -17,6 +17,26 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
+/**
+ * The three row shapes a goal list settles into. Exported so a list that is
+ * re-reading one of its tabs can hold the same shape instead of collapsing to
+ * blank while the server answers.
+ */
+export const GoalListRowsSkeleton = () => (
+ <Flexbox aria-busy className={styles.listRows}>
+ {Array.from({ length: 3 }).map((_, index) => (
+ <Flexbox horizontal align={'center'} gap={12} key={index} paddingBlock={14}>
+ <SkeletonBar height={20} radius={'50%'} width={20} />
+ <Flexbox flex={1} gap={7}>
+ <SkeletonBar height={16} width={`${36 + index * 8}%`} />
+ <SkeletonBar height={12} width={`${54 + index * 6}%`} />
+ </Flexbox>
+ <SkeletonBar height={24} width={72} />
+ </Flexbox>
+ ))}
+ </Flexbox>
+);
+
const GoalSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
<Flexbox aria-busy flex={1} height={'100%'}>
{chrome !== 'body' && <NavHeader />}
@@ -48,18 +68,7 @@ const GoalSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
<SkeletonBar height={28} width={64} />
</Flexbox>
</Flexbox>
- <Flexbox className={styles.listRows}>
- {Array.from({ length: 3 }).map((_, index) => (
- <Flexbox horizontal align={'center'} gap={12} key={index} paddingBlock={14}>
- <SkeletonBar height={20} radius={'50%'} width={20} />
- <Flexbox flex={1} gap={7}>
- <SkeletonBar height={16} width={`${36 + index * 8}%`} />
- <SkeletonBar height={12} width={`${54 + index * 6}%`} />
- </Flexbox>
- <SkeletonBar height={24} width={72} />
- </Flexbox>
- ))}
- </Flexbox>
+ <GoalListRowsSkeleton />
</Flexbox>
</WideScreenContainer>
</Flexbox>
diff --git a/src/features/AgentGoals/AgentGoalsPage.tsx b/src/features/AgentGoals/AgentGoalsPage.tsx
index 13e174c7f7c..40456d29275 100644
--- a/src/features/AgentGoals/AgentGoalsPage.tsx
+++ b/src/features/AgentGoals/AgentGoalsPage.tsx
@@ -1,6 +1,5 @@
'use client';
-import type { GoalStatus } from '@lobechat/const/goal';
import { Block, Empty, Flexbox } from '@lobehub/ui';
import { ActionIcon, Button, Segmented, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar } from 'antd-style';
@@ -8,11 +7,12 @@ import { LayoutGridIcon, ListIcon, PlusIcon, RefreshCwIcon } from 'lucide-react'
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import GoalSkeleton from '@/components/Skeleton/Goal';
+import GoalSkeleton, { GoalListRowsSkeleton } from '@/components/Skeleton/Goal';
import AgentBreadcrumb from '@/features/AgentBreadcrumb';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import type { GoalListFilter } from '@/store/goal';
import { useGoalStore } from '@/store/goal';
import { createGoalModal } from './CreateGoalModal';
@@ -63,8 +63,27 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-/** Goals whose loop has stopped for good — hidden by the default "open" filter. */
-const TERMINAL_GOAL_STATUSES = new Set<GoalStatus>(['achieved', 'failed', 'canceled']);
+/**
+ * The list failed to load — the page's own read, or the selected tab's. Both
+ * carry the same retry, which revalidates every tab's entry at once.
+ */
+const GoalLoadError = ({ onRetry }: { onRetry: () => void }) => {
+ const { t } = useTranslation('chat');
+
+ return (
+ <Block padding={32} variant={'outlined'}>
+ <Flexbox align={'center'} gap={12}>
+ <Text weight={600}>{t('goalList.loadError')}</Text>
+ <Text fontSize={13} type={'secondary'}>
+ {t('goalList.loadErrorDescription')}
+ </Text>
+ <Button icon={RefreshCwIcon} onClick={onRetry}>
+ {t('goalList.retry')}
+ </Button>
+ </Flexbox>
+ </Block>
+ );
+};
interface AgentGoalsPageProps {
agentId?: string;
@@ -89,17 +108,45 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
// between. `data?.goals` keeps the settled-empty and hydrated shapes aligned.
const { data, error, isLoading } = useFetchGoals(agentId, projectId);
const goals = useMemo(() => data?.goals ?? [], [data]);
+ // The active tab reads its own statuses from the server. `all` shares the
+ // window read's cache entry, so the page only pays for an extra request once
+ // the user opens a narrow tab.
+ const tabSWR = useFetchGoals(agentId, projectId, filter);
+ // `delivered` is a whole-set count, not a count of the page the list happens
+ // to hold: read the review set's own total so the header can never disagree
+ // with what the Needs-review tab shows once a goal sits past the list's page.
+ const reviewSWR = useFetchGoals(agentId, projectId, 'review');
const summary = useMemo(() => {
- const delivered = goals.filter(({ goal }) => goal.status === 'review').length;
+ const total = data?.total ?? goals.length;
+ // An aggregate that has not answered is unknown, not zero. Falling back to
+ // the review goals visible in the list's page would understate it for
+ // exactly the accounts this page reads past one page, and present that
+ // partial count as the delivered total.
+ const delivered = reviewSWR.data?.total;
- return { delivered, pursuing: goals.length - delivered, total: goals.length };
- }, [goals]);
- const filteredGoals = useMemo(() => {
- if (filter === 'all') return goals;
-
- return goals.filter(({ goal }) => !TERMINAL_GOAL_STATUSES.has(goal.status));
- }, [filter, goals]);
- const visibleGoalCount = filteredGoals.length;
+ return {
+ delivered,
+ pursuing: delivered === undefined ? undefined : total - delivered,
+ total,
+ };
+ }, [data, goals.length, reviewSWR.data]);
+ // A page of the newest goals cannot prove a tab empty, and neither can a read
+ // that failed: hold the list's shape while the tab's own read is in flight,
+ // and surface its failure rather than spinning on it.
+ const isTabUnresolved = filter !== 'all' && tabSWR.data === undefined;
+ const isTabPending = isTabUnresolved && !tabSWR.error;
+ const isTabError = isTabUnresolved && Boolean(tabSWR.error);
+ // The rows are the tab's own read, with no client-side fallback: a page of the
+ // newest goals cannot stand in for the tab's answer, and presenting it as if
+ // it could is what let a tab claim an outcome it had no way to know.
+ const filteredGoals = useMemo(
+ () => (filter === 'all' ? goals : (tabSWR.data?.goals ?? [])),
+ [filter, goals, tabSWR.data],
+ );
+ const isFilterEmpty = !isTabUnresolved && filteredGoals.length === 0;
+ // The tab's count is the server's answer for that tab. Until it arrives — or
+ // when it failed — the list's page cannot stand in for it either.
+ const visibleGoalCount = isTabUnresolved ? '—' : filteredGoals.length;
const GoalItem = viewMode === 'list' ? GoalListItem : GoalCardItem;
const openCreateGoal = (seed?: GoalExampleSeed) => {
createGoalModal({
@@ -144,17 +191,7 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
{isLoading && data === undefined ? (
<GoalSkeleton chrome={'body'} />
) : error ? (
- <Block padding={32} variant={'outlined'}>
- <Flexbox align={'center'} gap={12}>
- <Text weight={600}>{t('goalList.loadError')}</Text>
- <Text fontSize={13} type={'secondary'}>
- {t('goalList.loadErrorDescription')}
- </Text>
- <Button icon={RefreshCwIcon} onClick={() => void refreshGoals(scopeId)}>
- {t('goalList.retry')}
- </Button>
- </Flexbox>
- </Block>
+ <GoalLoadError onRetry={() => void refreshGoals(scopeId)} />
) : goals.length === 0 ? (
<GoalEmptyState onCreate={openCreateGoal} />
) : (
@@ -178,7 +215,7 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
</Flexbox>
<Flexbox className={styles.metric} gap={2}>
<Text fontSize={20} weight={600}>
- {summary.pursuing}
+ {summary.pursuing ?? '—'}
</Text>
<Text fontSize={12} type={'secondary'}>
{t('goalPage.metrics.pursuing')}
@@ -186,7 +223,7 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
</Flexbox>
<Flexbox className={styles.metric} gap={2}>
<Text fontSize={20} weight={600}>
- {summary.delivered}
+ {summary.delivered ?? '—'}
</Text>
<Text fontSize={12} type={'secondary'}>
{t('goalPage.metrics.delivered')}
@@ -208,16 +245,24 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
size={'small'}
value={filter}
options={[
- {
- label: t('goalPage.filter.open'),
- value: 'active',
- },
{
label: t('goalPage.filter.all'),
value: 'all',
},
+ {
+ label: t('goalPage.filter.review'),
+ value: 'review',
+ },
+ {
+ label: t('goalPage.filter.running'),
+ value: 'running',
+ },
+ {
+ label: t('goalPage.filter.achieved'),
+ value: 'achieved',
+ },
]}
- onChange={(value) => setFilter(value as 'active' | 'all')}
+ onChange={(value) => setFilter(value as GoalListFilter)}
/>
<ActionIcon
icon={ListIcon}
@@ -238,7 +283,11 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
</Flexbox>
</Flexbox>
<div className={viewMode === 'card' ? styles.list : styles.listRows}>
- {filteredGoals.length === 0 ? (
+ {isTabError ? (
+ <GoalLoadError onRetry={() => void refreshGoals(scopeId)} />
+ ) : isTabPending ? (
+ <GoalListRowsSkeleton />
+ ) : isFilterEmpty ? (
<Block padding={32} variant={'outlined'}>
<Empty
description={t('goalPage.filteredEmptyDescription')}
diff --git a/src/store/goal/action.test.ts b/src/store/goal/action.test.ts
index 8d8d050c705..2077fb4ef5c 100644
--- a/src/store/goal/action.test.ts
+++ b/src/store/goal/action.test.ts
@@ -18,7 +18,7 @@ beforeEach(() => {
vi.clearAllMocks();
useGoalStore.setState({
goalListByAgentId: {},
- goalListFilter: 'active',
+ goalListFilter: 'all',
goalListInitializedAgentIds: [],
goalListVisibleLimit: 10,
goalViewMode: 'list',
diff --git a/src/store/goal/action.ts b/src/store/goal/action.ts
index b1faf631ca1..423cb9b165c 100644
--- a/src/store/goal/action.ts
+++ b/src/store/goal/action.ts
@@ -1,4 +1,4 @@
-import { type GoalStatus, goalStatuses } from '@lobechat/const/goal';
+import type { GoalStatus } from '@lobechat/const/goal';
import type { GoalMetricCriterion, GoalTickResult } from '@lobechat/types';
import { mutate, useClientDataSWR, useClientDataSWRWithSync } from '@/libs/swr';
@@ -7,9 +7,19 @@ import { goalService } from '@/services/goal';
import { metricService } from '@/services/metric';
import type { StoreSetter } from '@/store/types';
+import { goalStatusesForFilter } from './goalListFilter';
import type { GoalListFilter, GoalState, GoalViewMode } from './initialState';
-const GOAL_STATUSES: GoalStatus[] = [...goalStatuses];
+/** The list page's tabs, in render order. `refreshGoals` revalidates every one. */
+const GOAL_LIST_FILTERS: GoalListFilter[] = ['all', 'review', 'running', 'achieved'];
+
+/**
+ * Cache scope of one tab's list. `all` keeps the scope's own entry — it is the
+ * page-level window the project dashboard and the overview metrics read — while
+ * a narrow tab gets its own entry, so each tab caches its own server answer.
+ */
+const goalListCacheScope = (scopeId: string, filter: GoalListFilter): string =>
+ filter === 'all' ? `${scopeId}:goals-page` : `${scopeId}:goals-page:${filter}`;
/**
* The home roll-up only ever renders goals that are still open, so it asks for
@@ -298,7 +308,11 @@ export class GoalActionImpl {
};
refreshGoals = async (scopeId: string): Promise<void> => {
- await mutate(taskKeys.sidebarGroups(`${scopeId}:goals-page`));
+ await Promise.all(
+ GOAL_LIST_FILTERS.map((filter) =>
+ mutate(taskKeys.sidebarGroups(goalListCacheScope(scopeId, filter))),
+ ),
+ );
};
refreshHomeGoals = async (scope: string): Promise<void> => {
@@ -314,25 +328,37 @@ export class GoalActionImpl {
};
/**
- * The goal list page's read. The sync wrapper matters here: this list is
- * persisted in the `task:` IndexedDB tier, and a cache hit never fires
- * `onSuccess` — without `onData` the store would stay uninitialized on a
- * revisit and the page would flash its empty state over hydrated data.
+ * The goal list page's read, one entry per tab.
+ *
+ * A narrow tab asks the server for its own statuses rather than filtering the
+ * `all` page on the client: the read only loads the newest `limit` goals, so a
+ * client-side filter would let a busy agent's older matching goal fall past
+ * the page and the tab would report itself empty while the goal exists.
+ *
+ * The sync wrapper matters here: this list is persisted in the `task:`
+ * IndexedDB tier, and a cache hit never fires `onSuccess` — without `onData`
+ * the store would stay uninitialized on a revisit and the page would flash its
+ * empty state over hydrated data.
*/
- useFetchGoals = (agentId?: string, projectId?: string) => {
+ useFetchGoals = (agentId?: string, projectId?: string, filter: GoalListFilter = 'all') => {
const scopeId = projectId ? `project:${projectId}` : agentId;
return useClientDataSWRWithSync(
- scopeId ? taskKeys.sidebarGroups(`${scopeId}:goals-page`) : null,
+ scopeId ? taskKeys.sidebarGroups(goalListCacheScope(scopeId, filter)) : null,
() =>
goalService.list({
agentId,
limit: 100,
projectId,
- statuses: GOAL_STATUSES,
+ statuses: goalStatusesForFilter(filter),
}),
{
onData: ({ goals }) => {
+ // Only `all` feeds the shared slice: it is the page-level window the
+ // project dashboard reads, and a filtered list stored under the plain
+ // scope would make that reader render a subset as if it were the list.
+ if (filter !== 'all') return;
+
this.#set(
({ goalListByAgentId, goalListInitializedAgentIds }) => ({
goalListByAgentId: {
diff --git a/src/store/goal/goalListFilter.test.ts b/src/store/goal/goalListFilter.test.ts
new file mode 100644
index 00000000000..98592f2204c
--- /dev/null
+++ b/src/store/goal/goalListFilter.test.ts
@@ -0,0 +1,36 @@
+import { goalStatuses } from '@lobechat/const/goal';
+import { describe, expect, it } from 'vitest';
+
+import { goalStatusesForFilter } from './goalListFilter';
+
+describe('goalStatusesForFilter', () => {
+ it('asks the server for every status under All', () => {
+ expect(goalStatusesForFilter('all')).toEqual([...goalStatuses]);
+ });
+
+ it('names exactly the tab state for a narrow tab, so the server decides emptiness', () => {
+ expect(goalStatusesForFilter('review')).toEqual(['review']);
+ expect(goalStatusesForFilter('running')).toEqual(['running']);
+ expect(goalStatusesForFilter('achieved')).toEqual(['achieved']);
+ });
+
+ it('never widens a narrow tab into the states it must not show', () => {
+ for (const filter of ['review', 'running'] as const) {
+ expect(goalStatusesForFilter(filter)).not.toContain('achieved');
+ expect(goalStatusesForFilter(filter)).not.toContain('canceled');
+ }
+
+ // `achieved` is a terminal tab, but "completed" does not name a failure or
+ // a cancellation: those stay reachable through `all` only.
+ expect(goalStatusesForFilter('achieved')).not.toContain('canceled');
+ expect(goalStatusesForFilter('achieved')).not.toContain('failed');
+ expect(goalStatusesForFilter('achieved')).not.toContain('running');
+ });
+
+ it('returns a fresh array for All, so a caller cannot mutate the shared status list', () => {
+ const first = goalStatusesForFilter('all');
+ first.push('achieved');
+
+ expect(goalStatusesForFilter('all')).toEqual([...goalStatuses]);
+ });
+});
diff --git a/src/store/goal/goalListFilter.ts b/src/store/goal/goalListFilter.ts
new file mode 100644
index 00000000000..159385105af
--- /dev/null
+++ b/src/store/goal/goalListFilter.ts
@@ -0,0 +1,32 @@
+import { type GoalStatus, goalStatuses } from '@lobechat/const/goal';
+
+import type { GoalListFilter } from './initialState';
+
+/**
+ * Lifecycle states each list tab keeps, as an explicit partition rather than a
+ * predicate per tab: the tab's rows and the server query behind them can then
+ * never disagree, and a status a later lifecycle adds has one place to land.
+ *
+ * `null` means "every status" — `all` is the default, so a goal is never hidden
+ * by default.
+ */
+const goalListFilterStatuses: Record<GoalListFilter, GoalStatus[] | null> = {
+ achieved: ['achieved'],
+ all: null,
+ review: ['review'],
+ running: ['running'],
+};
+
+/** Every status, as a fresh array so a caller cannot mutate a shared list. */
+const allGoalStatuses = (): GoalStatus[] => [...goalStatuses];
+
+/**
+ * The tab's statuses, as the server query argument.
+ *
+ * The list read loads one page of the newest goals, so a tab asks the server for
+ * exactly its own states instead of filtering that page: otherwise a busy
+ * agent's older matching goal falls past the page, and the tab reports itself
+ * empty while the goal exists.
+ */
+export const goalStatusesForFilter = (filter: GoalListFilter): GoalStatus[] =>
+ goalListFilterStatuses[filter] ?? allGoalStatuses();
diff --git a/src/store/goal/index.ts b/src/store/goal/index.ts
index 59171211251..d67f580e9f0 100644
--- a/src/store/goal/index.ts
+++ b/src/store/goal/index.ts
@@ -21,4 +21,6 @@ export const useGoalStore = createWithEqualityFn<GoalStore>()(
export const getGoalStoreState = () => useGoalStore.getState();
+export { goalStatusesForFilter } from './goalListFilter';
+export type { GoalListFilter, GoalViewMode } from './initialState';
export { goalSelectors } from './selectors';
diff --git a/src/store/goal/initialState.ts b/src/store/goal/initialState.ts
index 8f5f20a3c48..3b407f934ad 100644
--- a/src/store/goal/initialState.ts
+++ b/src/store/goal/initialState.ts
@@ -4,7 +4,15 @@ import type { GoalListItem } from '@/services/goal';
import type { MetricSeriesWithPoints } from '@/services/metric';
export type { GoalListItem };
-export type GoalListFilter = 'active' | 'all';
+/**
+ * List tab. Each option names the lifecycle states it keeps: `all` is the
+ * default (nothing hidden), `review` the goals at the human acceptance gate,
+ * `running` the goal whose loop is executing right now, `achieved` the goals
+ * that reached their terminal outcome. The other terminal states (`failed`,
+ * `canceled`) stay reachable through `all` only — "completed" would misname
+ * them.
+ */
+export type GoalListFilter = 'all' | 'review' | 'running' | 'achieved';
export type GoalViewMode = 'card' | 'list';
export interface GoalState {
@@ -35,7 +43,7 @@ export const initialState: GoalState = {
goalMetricSeriesById: {},
goalGraphById: {},
goalListByAgentId: {},
- goalListFilter: 'active',
+ goalListFilter: 'all',
goalListInitializedAgentIds: [],
goalListVisibleLimit: 10,
goalViewMode: 'list',