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): show assignee, duration and start date in the All tasks drill-down (#20023)

Arvin Xub4518f3ccee3
diff --git a/src/features/Portal/GoalMetric/Body.tsx b/src/features/Portal/GoalMetric/Body.tsx
index 9643f5cdcf6..6332fc280f5 100644
--- a/src/features/Portal/GoalMetric/Body.tsx
+++ b/src/features/Portal/GoalMetric/Body.tsx
@@ -1,23 +1,32 @@
import type { GoalSpend } from '@lobechat/types';
-import { Flexbox } from '@lobehub/ui';
-import { Tag, Text, toast } from '@lobehub/ui/base-ui';
+import { Flexbox, Icon, Tooltip } from '@lobehub/ui';
+import { Text, toast } from '@lobehub/ui/base-ui';
import { InputNumber } from 'antd';
import { createStaticStyles, cssVar } from 'antd-style';
import dayjs from 'dayjs';
import { memo, type ReactNode, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { TASK_STATUS_VISUALS } from '@/components/ExecutionStatus';
import { formatSpan, formatUsd } from '@/features/AgentGoals/goalPresentation';
+import AssigneeProfileAvatar from '@/features/AgentGoals/ProcessControl/AssigneeProfileAvatar';
import {
buildGoalGraphView,
type GoalGraphView,
+ type GoalNodeView,
} from '@/features/AgentGoals/ProcessControl/goalGraphViewModel';
import { KindDot } from '@/features/AgentGoals/ProcessControl/shared';
+import { formatElapsed, useElapsed } from '@/features/AgentGoals/ProcessControl/useElapsed';
+import AssigneeAvatar from '@/features/AgentTasks/features/AssigneeAvatar';
+import { formatTaskItemDate } from '@/features/AgentTasks/features/formatTaskItemDate';
+import RunningGlyph from '@/features/Home/components/RunningGlyph';
import { usePermission } from '@/hooks/usePermission';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
import { goalSelectors, useGoalStore } from '@/store/goal';
+import { taskRowSpan, type TaskRowState, taskRowState, taskRowStateLabelKey } from './taskRowState';
+
/**
* Drill-down behind each header metric of the goal detail page. Every view is
* an honest projection of the `goal.graph` snapshot β€” where the product does
@@ -51,11 +60,18 @@ const styles = createStaticStyles(({ css }) => ({
}));
const NodeRow = memo<{
+ /** Sits right after the title rather than at the row's far end. */
+ afterTitle?: ReactNode;
extra?: ReactNode;
goalId: string;
nodeId: string;
graph: GoalGraphView;
-}>(({ extra, goalId, graph, nodeId }) => {
+ /**
+ * Replaces the kind dot β€” the status glyph, when every row is the same kind,
+ * as on the Task list.
+ */
+ leading?: ReactNode;
+}>(({ afterTitle, extra, goalId, graph, leading, nodeId }) => {
const openGoalNode = useChatStore((s) => s.openGoalNode);
const view = graph.byId[nodeId];
if (!view) return null;
@@ -73,10 +89,12 @@ const NodeRow = memo<{
#{view.seq}
</Text>
)}
- <KindDot kind={view.node.kind} />
- <Text ellipsis style={{ flex: 1, minWidth: 0 }} weight={500}>
+ {leading ?? <KindDot kind={view.node.kind} />}
+ <Text ellipsis style={{ flex: afterTitle ? '0 1 auto' : 1, minWidth: 0 }} weight={500}>
{view.node.title}
</Text>
+ {afterTitle}
+ {afterTitle && <Flexbox flex={1} />}
{extra}
</Flexbox>
);
@@ -134,20 +152,118 @@ const Lifecycle = memo<{ goalId: string; graph: GoalGraphView }>(({ graph }) =>
Lifecycle.displayName = 'GoalMetricLifecycle';
-const Tasks = memo<{ goalId: string; graph: GoalGraphView }>(({ goalId, graph }) => {
+/**
+ * How long the Task has taken across every attempt β€” a live clock only while
+ * it is genuinely running, a frozen span otherwise. A Task that was never
+ * dispatched has nothing to show.
+ */
+const TaskDuration = memo<{ view: GoalNodeView }>(({ view }) => {
+ const span = taskRowSpan(view);
+ const elapsed = useElapsed(span && !span.endedAt ? span.startedAt : undefined);
+ if (!span) return null;
+
+ return (
+ <Text className={styles.mono} fontSize={12} style={{ flex: 'none' }} type={'secondary'}>
+ {span.endedAt ? formatElapsed(span.endedAt.getTime() - span.startedAt.getTime()) : elapsed}
+ </Text>
+ );
+});
+
+TaskDuration.displayName = 'GoalMetricTaskDuration';
+
+/**
+ * When the Task started, in the Task list's own date column β€” same format and
+ * width, with the exact start β†’ end one hover away. An undispatched Task still
+ * holds the column so the avatars stay aligned.
+ */
+const TaskStartDate = memo<{ view: GoalNodeView }>(({ view }) => {
+ const { t, i18n } = useTranslation('common');
+ const span = taskRowSpan(view);
+ const date = span
+ ? formatTaskItemDate(span.startedAt, {
+ formatOtherYear: t('time.formatOtherYear'),
+ formatThisYear: t('time.formatThisYear'),
+ locale: i18n.language,
+ })
+ : '';
+
+ return (
+ <Text
+ align={'right'}
+ fontSize={12}
+ style={{ flex: 'none', whiteSpace: 'nowrap', width: 48 }}
+ type={'secondary'}
+ title={
+ span
+ ? `${dayjs(span.startedAt).format('YYYY-MM-DD HH:mm:ss')} β†’ ${
+ span.endedAt ? dayjs(span.endedAt).format('YYYY-MM-DD HH:mm:ss') : '…'
+ }`
+ : undefined
+ }
+ >
+ {date}
+ </Text>
+ );
+});
+
+TaskStartDate.displayName = 'GoalMetricTaskStartDate';
+
+/** The Task-list visual for each row state; `running` draws the animated ring instead. */
+const STATE_VISUAL = {
+ decision: TASK_STATUS_VISUALS.paused,
+ done: TASK_STATUS_VISUALS.completed,
+ lost: TASK_STATUS_VISUALS.failed,
+ queued: TASK_STATUS_VISUALS.backlog,
+ retired: TASK_STATUS_VISUALS.canceled,
+} as const satisfies Record<Exclude<TaskRowState, 'running'>, unknown>;
+
+/**
+ * A Task node's state as the leading glyph the Task list uses β€” the same marks
+ * the goal page's own frontier draws, so a row reads the same in both places.
+ * The status name stays one hover away, worded from the same state as the icon.
+ */
+const TaskStatusGlyph = memo<{ view: GoalNodeView }>(({ view }) => {
const { t } = useTranslation('chat');
+ const state = taskRowState(view);
+
+ return (
+ <Tooltip title={t(taskRowStateLabelKey(view, state))}>
+ <span style={{ display: 'inline-flex', flex: 'none' }}>
+ {state === 'running' ? (
+ <RunningGlyph size={16} />
+ ) : (
+ <Icon color={STATE_VISUAL[state].color} icon={STATE_VISUAL[state].icon} size={16} />
+ )}
+ </span>
+ </Tooltip>
+ );
+});
+
+TaskStatusGlyph.displayName = 'GoalMetricTaskStatusGlyph';
+
+/** Laid out like a Task list row: number and state, the title, then who is on it and when. */
+const Tasks = memo<{ goalId: string; graph: GoalGraphView }>(({ goalId, graph }) => {
const works = graph.nodes.filter((view) => view.node.kind === 'task');
return (
<Flexbox gap={0}>
{works.map((view) => (
<NodeRow
+ afterTitle={<TaskDuration view={view} />}
goalId={goalId}
graph={graph}
key={view.node.id}
+ leading={<TaskStatusGlyph view={view} />}
nodeId={view.node.id}
extra={
- <Tag size={'small'}>{t(`goalProcess.nodeStatus.${view.node.status}` as const)}</Tag>
+ <Flexbox horizontal align={'center'} flex={'none'} gap={8}>
+ {view.assigneeAgentId ? (
+ <AssigneeProfileAvatar agentId={view.assigneeAgentId} />
+ ) : (
+ <AssigneeAvatar />
+ )}
+ <TaskStartDate view={view} />
+ </Flexbox>
}
/>
))}
diff --git a/src/features/Portal/GoalMetric/taskRowState.test.ts b/src/features/Portal/GoalMetric/taskRowState.test.ts
new file mode 100644
index 00000000000..f1c126c918f
--- /dev/null
+++ b/src/features/Portal/GoalMetric/taskRowState.test.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from 'vitest';
+
+import type { GoalNodeView } from '@/features/AgentGoals/ProcessControl/goalGraphViewModel';
+
+import { taskRowSpan, taskRowState, taskRowStateLabelKey } from './taskRowState';
+
+const STARTED = new Date('2026-09-26T10:00:00Z');
+const HEARTBEAT = new Date('2026-09-26T10:20:00Z');
+const ENDED = new Date('2026-09-26T10:40:00Z');
+
+const view = (overrides: Partial<GoalNodeView> & { status?: string } = {}): GoalNodeView => {
+ const { status = 'active', ...rest } = overrides;
+ return {
+ attempts: [{ index: 1, outcome: 'running', startedAt: STARTED }],
+ heartbeatAt: HEARTBEAT,
+ isStale: false,
+ node: { kind: 'task', status },
+ ...rest,
+ } as unknown as GoalNodeView;
+};
+
+describe('taskRowState', () => {
+ it('ticks the clock only for a task that is genuinely running', () => {
+ const running = view();
+
+ expect(taskRowState(running)).toBe('running');
+ expect(taskRowStateLabelKey(running, 'running')).toBe('goalProcess.nodeStatus.active');
+ expect(taskRowSpan(running)).toEqual({ endedAt: undefined, startedAt: STARTED });
+ });
+
+ it('reads a stale active task as lost and freezes its clock at the last heartbeat', () => {
+ const stale = view({ isStale: true });
+ const state = taskRowState(stale);
+
+ expect(state).toBe('lost');
+ // The node row still says `active`; the label must follow the lost glyph, not "Running".
+ expect(taskRowStateLabelKey(stale, state)).toBe('goalProcess.tag.lost');
+ expect(taskRowSpan(stale)).toEqual({ endedAt: HEARTBEAT, startedAt: STARTED });
+ });
+
+ it('freezes the clock of a task parked on a decision', () => {
+ const parked = view({ decision: { id: 'd1' } as GoalNodeView['decision'] });
+ const state = taskRowState(parked);
+
+ expect(state).toBe('decision');
+ expect(taskRowStateLabelKey(parked, state)).toBe('goalProcess.tag.needsDecision');
+ expect(taskRowSpan(parked)?.endedAt).toEqual(HEARTBEAT);
+ });
+
+ it('spans a settled task from its first attempt start to its last attempt end', () => {
+ const done = view({
+ attempts: [
+ { endedAt: HEARTBEAT, index: 1, outcome: 'failed', startedAt: STARTED },
+ { endedAt: ENDED, index: 2, outcome: 'passed', startedAt: HEARTBEAT },
+ ],
+ status: 'resolved',
+ });
+
+ expect(taskRowState(done)).toBe('done');
+ expect(taskRowSpan(done)).toEqual({ endedAt: ENDED, startedAt: STARTED });
+ });
+
+ it('has no span for a task that was never dispatched', () => {
+ const queued = view({ attempts: [], status: 'proposed' });
+
+ expect(taskRowState(queued)).toBe('queued');
+ expect(taskRowSpan(queued)).toBeUndefined();
+ });
+});
diff --git a/src/features/Portal/GoalMetric/taskRowState.ts b/src/features/Portal/GoalMetric/taskRowState.ts
new file mode 100644
index 00000000000..bb78e2dfc58
--- /dev/null
+++ b/src/features/Portal/GoalMetric/taskRowState.ts
@@ -0,0 +1,50 @@
+import {
+ type GoalNodeView,
+ isRunningNode,
+} from '@/features/AgentGoals/ProcessControl/goalGraphViewModel';
+
+/**
+ * What one All-tasks row says about its Task. The glyph, its hover label and
+ * whether the duration clock ticks all read this one value, so the icon, the
+ * word and the clock can never disagree β€” an `active` node that lost its lease
+ * is `lost`, not "Running".
+ */
+export type TaskRowState = 'decision' | 'done' | 'lost' | 'queued' | 'retired' | 'running';
+
+export const taskRowState = (view: GoalNodeView): TaskRowState => {
+ if (view.isStale) return 'lost';
+ if (view.decision) return 'decision';
+ if (isRunningNode(view)) return 'running';
+ if (view.node.status === 'resolved') return 'done';
+ if (view.node.status === 'rejected' || view.node.status === 'retired') return 'retired';
+ return 'queued';
+};
+
+export const taskRowStateLabelKey = (view: GoalNodeView, state: TaskRowState) => {
+ if (state === 'lost') return 'goalProcess.tag.lost' as const;
+ if (state === 'decision') return 'goalProcess.tag.needsDecision' as const;
+ return `goalProcess.nodeStatus.${view.node.status}` as const;
+};
+
+export interface TaskRowSpan {
+ /** Absent only while the Task is genuinely running β€” the clock is live. */
+ endedAt?: Date;
+ startedAt: Date;
+}
+
+/**
+ * First attempt start β†’ last attempt end. An attempt left open without a
+ * running Task (lease lost, parked on a decision) has no audit boundary yet, so
+ * it is closed at the last sign of life instead of ticking forever.
+ */
+export const taskRowSpan = (
+ view: GoalNodeView,
+ state: TaskRowState = taskRowState(view),
+): TaskRowSpan | undefined => {
+ const first = view.attempts[0];
+ const last = view.attempts.at(-1);
+ if (!first || !last) return undefined;
+
+ const endedAt = last.endedAt ?? (state === 'running' ? undefined : view.heartbeatAt);
+ return { endedAt, startedAt: first.startedAt };
+};