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.

💄 style(goal): show the user by face and drop the system actor in the activity timeline (#20150)

Arvin Xu74e0c80f796d
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 2f2ba5fee77..dcb218203a1 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -586,6 +586,7 @@
"goalProcess.activity.finding": "Recorded finding: {{title}}",
"goalProcess.activity.title": "Activity",
"goalProcess.actor.agent": "Agent",
+ "goalProcess.actor.member": "Member",
"goalProcess.actor.system": "System",
"goalProcess.actor.user": "You",
"goalProcess.addTask.descriptionLabel": "Instruction (optional)",
@@ -668,19 +669,30 @@
"goalProcess.lifecycle.action.created.finding": "drew a finding",
"goalProcess.lifecycle.action.created.problem": "raised a question",
"goalProcess.lifecycle.action.linked": "linked",
+ "goalProcess.lifecycle.action.paused": "paused the goal",
"goalProcess.lifecycle.action.rejected": "rejected {{kind}}",
"goalProcess.lifecycle.action.resolved": "completed {{kind}}",
"goalProcess.lifecycle.action.resolved.decision": "made a decision",
"goalProcess.lifecycle.action.resolved.problem": "answered a question",
+ "goalProcess.lifecycle.action.resumed": "resumed the goal",
"goalProcess.lifecycle.action.retired": "retired {{kind}}",
+ "goalProcess.lifecycle.action.taskCanceled": "task canceled",
"goalProcess.lifecycle.action.unlinked": "unlinked",
"goalProcess.lifecycle.action.updated": "updated {{kind}}",
+ "goalProcess.lifecycle.action.work.contradicts": "added counter-evidence",
+ "goalProcess.lifecycle.action.work.input": "used as input",
+ "goalProcess.lifecycle.action.work.produced": "produced",
+ "goalProcess.lifecycle.action.work.supports": "added evidence",
"goalProcess.lifecycle.kind.decision": "decision",
"goalProcess.lifecycle.kind.experiment": "experiment",
"goalProcess.lifecycle.kind.finding": "finding",
"goalProcess.lifecycle.kind.goal": "goal",
"goalProcess.lifecycle.kind.problem": "question",
"goalProcess.lifecycle.kind.task": "task",
+ "goalProcess.lifecycle.note.budgetExhausted": "The goal or the main Agent ran out of turns",
+ "goalProcess.lifecycle.note.mainAgent": "Main Agent: {{text}}",
+ "goalProcess.lifecycle.note.recoveredAbandoned": "The previous run stopped responding; a new attempt started automatically",
+ "goalProcess.lifecycle.note.retryAfterVerification": "Verification did not pass; the next attempt started automatically",
"goalProcess.linked.open": "Open goal progress",
"goalProcess.manager.pending": "Waiting for the first run",
"goalProcess.manager.title": "Main agent",
@@ -703,7 +715,7 @@
"goalProcess.metricDetail.duration.total": "Total runtime",
"goalProcess.metricDetail.findings.title": "All findings",
"goalProcess.metricDetail.lifecycle.empty": "No events recorded yet",
- "goalProcess.metricDetail.lifecycle.title": "Lifecycle",
+ "goalProcess.metricDetail.lifecycle.title": "Activity timeline",
"goalProcess.metricDetail.liveness.driver": "The goal advances on its own: each finished task triggers the next move, and a recovery sweep rescues anything that stalls or loses its device. Nothing here waits for you unless a decision gate is open.",
"goalProcess.metricDetail.liveness.latest": "Last activity",
"goalProcess.metricDetail.liveness.running": "Running now",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index f3eeb0e0127..04b384836aa 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -586,6 +586,7 @@
"goalProcess.activity.finding": "沉淀结论:{{title}}",
"goalProcess.activity.title": "活动",
"goalProcess.actor.agent": "Agent",
+ "goalProcess.actor.member": "成员",
"goalProcess.actor.system": "系统",
"goalProcess.actor.user": "你",
"goalProcess.addTask.descriptionLabel": "任务说明(选填)",
@@ -668,19 +669,30 @@
"goalProcess.lifecycle.action.created.finding": "得出结论",
"goalProcess.lifecycle.action.created.problem": "提出问题",
"goalProcess.lifecycle.action.linked": "关联",
+ "goalProcess.lifecycle.action.paused": "暂停目标",
"goalProcess.lifecycle.action.rejected": "否决{{kind}}",
"goalProcess.lifecycle.action.resolved": "完成{{kind}}",
"goalProcess.lifecycle.action.resolved.decision": "做出决策",
"goalProcess.lifecycle.action.resolved.problem": "解决问题",
+ "goalProcess.lifecycle.action.resumed": "恢复目标",
"goalProcess.lifecycle.action.retired": "归档{{kind}}",
+ "goalProcess.lifecycle.action.taskCanceled": "任务已取消",
"goalProcess.lifecycle.action.unlinked": "解除关联",
"goalProcess.lifecycle.action.updated": "更新{{kind}}",
+ "goalProcess.lifecycle.action.work.contradicts": "提出反证",
+ "goalProcess.lifecycle.action.work.input": "引用输入",
+ "goalProcess.lifecycle.action.work.produced": "产出交付物",
+ "goalProcess.lifecycle.action.work.supports": "补充证据",
"goalProcess.lifecycle.kind.decision": "决策",
"goalProcess.lifecycle.kind.experiment": "实验",
"goalProcess.lifecycle.kind.finding": "结论",
"goalProcess.lifecycle.kind.goal": "目标",
"goalProcess.lifecycle.kind.problem": "问题",
"goalProcess.lifecycle.kind.task": "任务",
+ "goalProcess.lifecycle.note.budgetExhausted": "目标或主 Agent 的轮次预算已用完",
+ "goalProcess.lifecycle.note.mainAgent": "主 Agent:{{text}}",
+ "goalProcess.lifecycle.note.recoveredAbandoned": "上一次运行已失去响应,已自动重新开始",
+ "goalProcess.lifecycle.note.retryAfterVerification": "验收未通过,已自动开始下一次尝试",
"goalProcess.linked.open": "查看目标进度",
"goalProcess.manager.pending": "等待首次执行",
"goalProcess.manager.title": "主 Agent",
@@ -703,7 +715,7 @@
"goalProcess.metricDetail.duration.total": "总运行时长",
"goalProcess.metricDetail.findings.title": "全部结论",
"goalProcess.metricDetail.lifecycle.empty": "还没有记录任何事件",
- "goalProcess.metricDetail.lifecycle.title": "生命周期",
+ "goalProcess.metricDetail.lifecycle.title": "活动时间线",
"goalProcess.metricDetail.liveness.driver": "目标会自主推进:每个任务完成即触发下一步,失联或停滞的任务由兜底扫描捞回。除非有决策门等你,这里没有任何事情需要你干预。",
"goalProcess.metricDetail.liveness.latest": "最近活动",
"goalProcess.metricDetail.liveness.running": "正在执行",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 2d79f68efca..3d0a1af2af5 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -2152,6 +2152,7 @@ export default {
'goalProcess.node.unanswered': 'Unanswered',
'goalProcess.metrics.status': 'Status',
'goalProcess.actor.agent': 'Agent',
+ 'goalProcess.actor.member': 'Member',
'goalProcess.actor.system': 'System',
'goalProcess.actor.user': 'You',
'goalProcess.lifecycle.action.activated': 'started {{kind}}',
@@ -2160,19 +2161,32 @@ export default {
'goalProcess.lifecycle.action.created.finding': 'drew a finding',
'goalProcess.lifecycle.action.created.problem': 'raised a question',
'goalProcess.lifecycle.action.linked': 'linked',
+ 'goalProcess.lifecycle.action.paused': 'paused the goal',
'goalProcess.lifecycle.action.rejected': 'rejected {{kind}}',
'goalProcess.lifecycle.action.resolved': 'completed {{kind}}',
'goalProcess.lifecycle.action.resolved.decision': 'made a decision',
'goalProcess.lifecycle.action.resolved.problem': 'answered a question',
+ 'goalProcess.lifecycle.action.resumed': 'resumed the goal',
'goalProcess.lifecycle.action.retired': 'retired {{kind}}',
+ 'goalProcess.lifecycle.action.taskCanceled': 'task canceled',
'goalProcess.lifecycle.action.unlinked': 'unlinked',
'goalProcess.lifecycle.action.updated': 'updated {{kind}}',
+ 'goalProcess.lifecycle.action.work.contradicts': 'added counter-evidence',
+ 'goalProcess.lifecycle.action.work.input': 'used as input',
+ 'goalProcess.lifecycle.action.work.produced': 'produced',
+ 'goalProcess.lifecycle.action.work.supports': 'added evidence',
'goalProcess.lifecycle.kind.decision': 'decision',
'goalProcess.lifecycle.kind.experiment': 'experiment',
'goalProcess.lifecycle.kind.finding': 'finding',
'goalProcess.lifecycle.kind.goal': 'goal',
'goalProcess.lifecycle.kind.problem': 'question',
'goalProcess.lifecycle.kind.task': 'task',
+ 'goalProcess.lifecycle.note.budgetExhausted': 'The goal or the main Agent ran out of turns',
+ 'goalProcess.lifecycle.note.mainAgent': 'Main Agent: {{text}}',
+ 'goalProcess.lifecycle.note.recoveredAbandoned':
+ 'The previous run stopped responding; a new attempt started automatically',
+ 'goalProcess.lifecycle.note.retryAfterVerification':
+ 'Verification did not pass; the next attempt started automatically',
'goalProcess.metricDetail.budget.controlTitle': 'Budget control',
'goalProcess.metricDetail.budget.perTaskEmpty': 'No run has been billed yet.',
'goalProcess.metricDetail.budget.perTaskTitle': 'Where it went',
@@ -2191,7 +2205,7 @@ export default {
'goalProcess.metricDetail.duration.total': 'Total runtime',
'goalProcess.metricDetail.findings.title': 'All findings',
'goalProcess.metricDetail.lifecycle.empty': 'No events recorded yet',
- 'goalProcess.metricDetail.lifecycle.title': 'Lifecycle',
+ 'goalProcess.metricDetail.lifecycle.title': 'Activity timeline',
'goalProcess.metricDetail.liveness.driver':
'The goal advances on its own: each finished task triggers the next move, and a recovery sweep rescues anything that stalls or loses its device. Nothing here waits for you unless a decision gate is open.',
'goalProcess.metricDetail.liveness.latest': 'Last activity',
diff --git a/src/features/AgentGoals/ProcessControl/Deliverables.tsx b/src/features/AgentGoals/ProcessControl/Deliverables.tsx
index 7b6c30e3082..6f2ae7f0531 100644
--- a/src/features/AgentGoals/ProcessControl/Deliverables.tsx
+++ b/src/features/AgentGoals/ProcessControl/Deliverables.tsx
@@ -90,6 +90,32 @@ export const openTargetOf = (artifact: GoalArtifactView) => {
return undefined;
};
+/**
+ * Opens a deliverable where it lives: a document inside the app, a generated
+ * file or external resource at its canonical target.
+ */
+export const useOpenGoalArtifact = () => {
+ const openDocument = useChatStore((s) => s.openDocument);
+
+ return (artifact: GoalArtifactView) => {
+ const target = openTargetOf(artifact);
+ if (!target) return;
+ // `openDocument` takes the DOCUMENT id, not the agent-document binding id:
+ // `agentDocumentId` only establishes that a binding exists.
+ if (target.kind === 'document') {
+ openDocument(artifact.resourceId!, artifact.agentDocumentId);
+ return;
+ }
+ // A generated file and an external resource both leave for their canonical
+ // target. The file-preview Portal is not a substitute: it resolves a
+ // knowledge-base item, so an ordinary exported file loads forever in it.
+ window.open(target.url, '_blank', 'noopener,noreferrer');
+ };
+};
+
+export const artifactIconOf = (type: GoalArtifactView['type']) =>
+ type === 'document' ? FileText : type === 'file' ? FileDown : ExternalLink;
+
const DeliverableRow = memo<{
artifact: GoalArtifactView;
onOpen: (artifact: GoalArtifactView) => void;
@@ -99,8 +125,7 @@ const DeliverableRow = memo<{
const { text, title } = useActivityTime(artifact.createdAt);
// A document opens inside the app; a generated file downloads; an external
// resource leaves for its own site.
- const icon =
- artifact.type === 'document' ? FileText : artifact.type === 'file' ? FileDown : ExternalLink;
+ const icon = artifactIconOf(artifact.type);
const openable = !!openTargetOf(artifact);
@@ -142,22 +167,7 @@ DeliverableRow.displayName = 'GoalDeliverableRow';
const Deliverables = memo<{ graph: GoalGraphView }>(({ graph }) => {
const { t } = useTranslation('chat');
- const openDocument = useChatStore((s) => s.openDocument);
-
- const open = (artifact: GoalArtifactView) => {
- const target = openTargetOf(artifact);
- if (!target) return;
- // `openDocument` takes the DOCUMENT id, not the agent-document binding id:
- // `agentDocumentId` only establishes that a binding exists.
- if (target.kind === 'document') {
- openDocument(artifact.resourceId!, artifact.agentDocumentId);
- return;
- }
- // A generated file and an external resource both leave for their canonical
- // target. The file-preview Portal is not a substitute: it resolves a
- // knowledge-base item, so an ordinary exported file loads forever in it.
- window.open(target.url, '_blank', 'noopener,noreferrer');
- };
+ const open = useOpenGoalArtifact();
if (graph.artifacts.length === 0)
return (
diff --git a/src/features/Portal/GoalMetric/Lifecycle.tsx b/src/features/Portal/GoalMetric/Lifecycle.tsx
index 4975e127a7a..bf3ba2fefa9 100644
--- a/src/features/Portal/GoalMetric/Lifecycle.tsx
+++ b/src/features/Portal/GoalMetric/Lifecycle.tsx
@@ -1,18 +1,23 @@
import type { GoalEventType, GoalGraphEvent, GoalNodeKind } from '@lobechat/types';
import { Empty, Flexbox, Icon } from '@lobehub/ui';
import { Text } from '@lobehub/ui/base-ui';
-import { createStaticStyles, cssVar } from 'antd-style';
+import { GithubIcon } from '@lobehub/ui/icons';
+import { createStaticStyles, cssVar, cx } from 'antd-style';
import dayjs from 'dayjs';
import {
Archive,
+ ArrowUpRight,
+ Ban,
Check,
+ GitPullRequest,
History,
Link2,
type LucideIcon,
+ PackageCheck,
+ Pause,
Pencil,
Play,
Plus,
- Settings2,
Unlink,
X,
} from 'lucide-react';
@@ -20,14 +25,30 @@ import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import AssigneeProfileAvatar from '@/features/AgentGoals/ProcessControl/AssigneeProfileAvatar';
+import {
+ artifactIconOf,
+ openTargetOf,
+ useOpenGoalArtifact,
+} from '@/features/AgentGoals/ProcessControl/Deliverables';
import type {
+ GoalArtifactView,
GoalGraphView,
GoalNodeView,
} from '@/features/AgentGoals/ProcessControl/goalGraphViewModel';
import { KIND_ICON } from '@/features/AgentGoals/ProcessControl/shared';
import { useGoalNodeSelect } from '@/features/AgentGoals/ProcessControl/useGoalProcessActions';
import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';
+import UserAvatar from '@/features/User/UserAvatar';
import { goalSelectors, useGoalStore } from '@/store/goal';
+import { useUserStore } from '@/store/user';
+import { userProfileSelectors } from '@/store/user/selectors';
+
+import {
+ type LifecycleNote,
+ type LifecyclePresentation,
+ nodeTwinKey,
+ presentLifecycleEvent,
+} from './lifecycleEvent';
/**
* The goal's history as a timeline, newest first and grouped by day. Each event
@@ -39,8 +60,49 @@ import { goalSelectors, useGoalStore } from '@/store/goal';
*/
const BADGE = 20;
+/** The metric panel body's padding (`Body`), which is also the scroller's. */
+const PANEL_PADDING = 16;
+/** How much closer to the panel title a stuck day label sits than at rest. */
+const STUCK_LIFT = 12;
const styles = createStaticStyles(({ css }) => ({
+ artifact: css`
+ margin: 0;
+ padding-block: 8px;
+ padding-inline: 10px;
+ border: none;
+ border-radius: ${cssVar.borderRadius};
+
+ font: inherit;
+ color: ${cssVar.colorText};
+ text-align: start;
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ artifactIcon: css`
+ display: flex;
+ flex: none;
+ align-items: center;
+ justify-content: center;
+
+ width: 32px;
+ height: 32px;
+ border-radius: ${cssVar.borderRadiusSM};
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ artifactOpenable: css`
+ cursor: pointer;
+
+ &:hover {
+ background: ${cssVar.colorFillSecondary};
+ }
+
+ &:focus-visible {
+ outline: 2px solid ${cssVar.colorPrimaryBorder};
+ outline-offset: 1px;
+ }
+ `,
badge: css`
display: flex;
flex: none;
@@ -51,12 +113,18 @@ const styles = createStaticStyles(({ css }) => ({
height: ${BADGE}px;
border-radius: 50%;
`,
+ // Sticks past the panel's top edge instead of at the scroller's padding edge,
+ // so rows scrolling by never show through a gap above it, and a stuck label
+ // sits close under the panel title rather than a full padding below it. The
+ // negative margin cancels the extra padding, leaving the resting layout as is.
+ // Each day's header is bounded by its own group, so the next day pushes it out.
day: css`
position: sticky;
z-index: 1;
- inset-block-start: 0;
+ inset-block-start: -${PANEL_PADDING + STUCK_LIFT}px;
- padding-block: 6px;
+ margin-block-start: -${PANEL_PADDING}px;
+ padding-block: ${PANEL_PADDING + 6}px 6px;
font-size: 12px;
font-weight: 600;
@@ -68,6 +136,12 @@ const styles = createStaticStyles(({ css }) => ({
position: relative;
padding-block-end: 14px;
+ /* The next day's header reaches ${PANEL_PADDING}px up above it; the last
+ row leaves that much room so a card's bottom edge is never covered. */
+ &:last-child {
+ padding-block-end: ${PANEL_PADDING}px;
+ }
+
/* The rail: runs from under this badge to the next one. */
&:not(:last-child)::before {
content: '';
@@ -98,6 +172,7 @@ const styles = createStaticStyles(({ css }) => ({
font-size: 12px;
line-height: 1.6;
color: ${cssVar.colorTextSecondary};
+ white-space: pre-line;
overflow-wrap: anywhere;
background: ${cssVar.colorFillQuaternary};
@@ -160,6 +235,13 @@ const EVENT_VISUAL: Record<GoalEventType, { icon: LucideIcon; tone: Tone }> = {
updated: { icon: Pencil, tone: NEUTRAL },
};
+const ACTION_ICON: Record<string, LucideIcon> = {
+ paused: Pause,
+ resumed: Play,
+ taskCanceled: Ban,
+ work: PackageCheck,
+};
+
/**
* The node an event is about. Events carry the id of whatever row they touched,
* so a decision or task event is walked back to the graph node that owns it.
@@ -229,6 +311,71 @@ const Subject = memo<{ onSelect: (nodeId: string) => void; view: GoalNodeView }>
Subject.displayName = 'GoalMetricLifecycleSubject';
+const parseUrl = (url: string | null) => {
+ if (!url) return null;
+ try {
+ return new URL(url);
+ } catch {
+ return null;
+ }
+};
+
+/**
+ * The glyph and caption a deliverable card leads with. A GitHub link is named
+ * by its own glyph — a pull request as a PR — so its host would only repeat
+ * what the icon already says; any other external link keeps its host.
+ */
+const artifactLook = (artifact: GoalArtifactView) => {
+ const url = artifact.type === 'document' ? null : parseUrl(artifact.url);
+ if (url?.hostname === 'github.com')
+ return {
+ host: null,
+ icon: /\/pull\/\d+/.test(url.pathname) ? GitPullRequest : GithubIcon,
+ };
+ return { host: url?.host ?? null, icon: artifactIconOf(artifact.type) };
+};
+
+/**
+ * A deliverable the event attached, as a card on its own line: the row names
+ * the task that produced it, the card is the thing itself, opened where it
+ * lives.
+ */
+const ArtifactCard = memo<{ artifact: GoalArtifactView }>(({ artifact }) => {
+ const { t } = useTranslation('chat');
+ const open = useOpenGoalArtifact();
+ const openable = !!openTargetOf(artifact);
+ const label = artifact.title || artifact.identifier || t('goalProcess.deliverables.untitled');
+ const { host, icon } = artifactLook(artifact);
+
+ return (
+ <Flexbox
+ horizontal
+ align={'center'}
+ as={openable ? 'button' : 'div'}
+ className={cx(styles.artifact, openable && styles.artifactOpenable)}
+ gap={10}
+ {...(openable ? { onClick: () => open(artifact), type: 'button' as const } : {})}
+ >
+ <span className={styles.artifactIcon}>
+ <Icon color={cssVar.colorTextSecondary} icon={icon} size={16} />
+ </span>
+ <Flexbox flex={1} gap={2} style={{ minWidth: 0 }}>
+ <Text ellipsis fontSize={13} weight={500}>
+ {label}
+ </Text>
+ {host && (
+ <Text ellipsis fontSize={12} type={'secondary'}>
+ {host}
+ </Text>
+ )}
+ </Flexbox>
+ {openable && <Icon color={cssVar.colorTextQuaternary} icon={ArrowUpRight} size={14} />}
+ </Flexbox>
+ );
+});
+
+ArtifactCard.displayName = 'GoalMetricLifecycleArtifact';
+
const AgentActor = memo<{ agentId: string }>(({ agentId }) => {
const { t } = useTranslation('chat');
const meta = useAgentDisplayMeta(agentId);
@@ -247,42 +394,84 @@ const AgentActor = memo<{ agentId: string }>(({ agentId }) => {
AgentActor.displayName = 'GoalMetricLifecycleAgentActor';
-const Actor = memo<{ event: GoalGraphEvent }>(({ event }) => {
+const UserActor = memo<{ userId?: string | null }>(({ userId }) => {
const { t } = useTranslation('chat');
- if (event.actorType === 'agent' && event.actorId) return <AgentActor agentId={event.actorId} />;
+ const [currentUserId, nickName] = useUserStore((s) => [
+ userProfileSelectors.userId(s),
+ userProfileSelectors.nickName(s),
+ ]);
+
+ // Only the signed-in user can be shown by face; another member's event reads
+ // as "Member" rather than borrowing this user's identity or calling it "You".
+ if (userId && userId !== currentUserId)
+ return (
+ <Text fontSize={13} style={{ flex: 'none' }} weight={500}>
+ {t('goalProcess.actor.member')}
+ </Text>
+ );
return (
<Flexbox horizontal align={'center'} flex={'none'} gap={6}>
- {event.actorType === 'system' && (
- <Icon color={cssVar.colorTextTertiary} icon={Settings2} size={14} />
- )}
- <Text fontSize={13} weight={500}>
- {t(`goalProcess.actor.${event.actorType}` as const)}
+ <UserAvatar size={16} />
+ <Text ellipsis fontSize={13} style={{ maxWidth: 120 }} weight={500}>
+ {nickName || t('goalProcess.actor.user')}
</Text>
</Flexbox>
);
});
+UserActor.displayName = 'GoalMetricLifecycleUserActor';
+
+const Actor = memo<{ event: GoalGraphEvent }>(({ event }) => {
+ const { t } = useTranslation('chat');
+ if (event.actorType === 'agent' && event.actorId) return <AgentActor agentId={event.actorId} />;
+ if (event.actorType === 'user') return <UserActor userId={event.actorId} />;
+
+ // Automatic steps name no actor: the event reads as the action alone, so
+ // the rows a person or agent drove stand out.
+ if (event.actorType === 'system') return null;
+
+ return (
+ <Text fontSize={13} style={{ flex: 'none' }} weight={500}>
+ {t('goalProcess.actor.agent')}
+ </Text>
+ );
+});
+
Actor.displayName = 'GoalMetricLifecycleActor';
+const noteText = (note: LifecycleNote, t: (key: any, options?: any) => string) => {
+ if (!('key' in note)) return note.text;
+ if (note.key === 'mainAgent') return t('goalProcess.lifecycle.note.mainAgent', { text: note.text });
+ return t(`goalProcess.lifecycle.note.${note.key}` as const);
+};
+
const EventItem = memo<{
event: GoalGraphEvent;
graph: GoalGraphView;
onSelect: (nodeId: string) => void;
-}>(({ event, graph, onSelect }) => {
+ presentation: Exclude<LifecyclePresentation, { hidden: true }>;
+}>(({ event, graph, onSelect, presentation }) => {
const { t } = useTranslation('chat');
- const { icon, tone } = EVENT_VISUAL[event.eventType] ?? {
- icon: History,
- tone: NEUTRAL,
- };
+ const visual = EVENT_VISUAL[event.eventType] ?? { icon: History, tone: NEUTRAL };
+ const tone = visual.tone;
+ // A recognised event names what happened more precisely than its raw type:
+ // a canceled task or a delivered Work is not an "edit".
+ const icon = (presentation.action && ACTION_ICON[presentation.action.split('.')[0]]) || visual.icon;
const subjects = subjectNodes(event, graph);
const kind = eventKind(event, subjects);
const phrase = `${event.eventType}.${kind}`;
- const action = ACTION_PHRASES.has(phrase)
- ? t(`goalProcess.lifecycle.action.${phrase}` as any)
- : t(`goalProcess.lifecycle.action.${event.eventType}` as const, {
- kind: kind ? t(`goalProcess.lifecycle.kind.${kind}` as const) : '',
- }).trim();
+ const action = presentation.action
+ ? t(`goalProcess.lifecycle.action.${presentation.action}` as const)
+ : ACTION_PHRASES.has(phrase)
+ ? t(`goalProcess.lifecycle.action.${phrase}` as any)
+ : t(`goalProcess.lifecycle.action.${event.eventType}` as const, {
+ kind: kind ? t(`goalProcess.lifecycle.kind.${kind}` as const) : '',
+ }).trim();
+ const artifact = presentation.workVersion
+ ? graph.artifacts.find((item) => item.workVersionId === presentation.workVersion!.id)
+ : undefined;
+ const note = presentation.note ? noteText(presentation.note, t) : undefined;
return (
<Flexbox horizontal className={styles.item} gap={10}>
@@ -321,9 +510,10 @@ const EventItem = memo<{
{dayjs(event.createdAt).format('HH:mm')}
</Text>
</Flexbox>
- {event.reason && (
- <div className={styles.reason} title={event.reason}>
- {event.reason}
+ {artifact && <ArtifactCard artifact={artifact} />}
+ {note && (
+ <div className={styles.reason} title={note}>
+ {note}
</div>
)}
</Flexbox>
@@ -354,15 +544,29 @@ const Lifecycle = memo<{ goalId: string; graph: GoalGraphView }>(({ goalId, grap
const onSelect = useGoalNodeSelect(goalId, graph);
const days = useMemo(() => {
- const sorted = [...(snapshot?.events ?? [])].sort(
- (a, b) => b.createdAt.getTime() - a.createdAt.getTime(),
+ const events = snapshot?.events ?? [];
+ const workTypes = new Map(
+ (snapshot?.workVersions ?? []).map((link) => [link.workVersionId, link.work?.type]),
+ );
+ const nodeTwins = new Set(
+ events.filter((event) => event.entityType === 'node' && event.reason).map(nodeTwinKey),
);
- const groups: { day: dayjs.Dayjs; events: GoalGraphEvent[] }[] = [];
+ const sorted = [...events].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
+ type Row = { event: GoalGraphEvent; presentation: Exclude<LifecyclePresentation, { hidden: true }> };
+ const groups: { day: dayjs.Dayjs; rows: Row[] }[] = [];
for (const event of sorted) {
+ const presentation = presentLifecycleEvent(event, {
+ hasNodeTwin: event.entityType === 'goal' && nodeTwins.has(nodeTwinKey(event)),
+ workTypeOf: (id) => workTypes.get(id),
+ });
+ // Bookkeeping rows are dropped before grouping so a day holding nothing
+ // else does not leave an empty header behind.
+ if (presentation.hidden) continue;
+ const row = { event, presentation };
const day = dayjs(event.createdAt).startOf('day');
const last = groups.at(-1);
- if (last?.day.isSame(day)) last.events.push(event);
- else groups.push({ day, events: [event] });
+ if (last?.day.isSame(day)) last.rows.push(row);
+ else groups.push({ day, rows: [row] });
}
return groups;
}, [snapshot]);
@@ -371,13 +575,19 @@ const Lifecycle = memo<{ goalId: string; graph: GoalGraphView }>(({ goalId, grap
return <Empty description={t('goalProcess.metricDetail.lifecycle.empty')} icon={History} />;
return (
- <Flexbox gap={8}>
- {days.map(({ day, events }) => (
- <Flexbox gap={4} key={day.valueOf()}>
+ <Flexbox gap={0}>
+ {days.map(({ day, rows }) => (
+ <Flexbox gap={2} key={day.valueOf()}>
<div className={styles.day}>{dayLabel(day)}</div>
<Flexbox gap={0}>
- {events.map((event) => (
- <EventItem event={event} graph={graph} key={event.id} onSelect={onSelect} />
+ {rows.map(({ event, presentation }) => (
+ <EventItem
+ event={event}
+ graph={graph}
+ key={event.id}
+ presentation={presentation}
+ onSelect={onSelect}
+ />
))}
</Flexbox>
</Flexbox>
diff --git a/src/features/Portal/GoalMetric/lifecycleEvent.test.ts b/src/features/Portal/GoalMetric/lifecycleEvent.test.ts
new file mode 100644
index 00000000000..e79da7eb745
--- /dev/null
+++ b/src/features/Portal/GoalMetric/lifecycleEvent.test.ts
@@ -0,0 +1,107 @@
+import type { GoalEventType } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { nodeTwinKey, presentLifecycleEvent } from './lifecycleEvent';
+
+const ctx = (types: Record<string, string> = {}, hasNodeTwin = false) => ({
+ hasNodeTwin,
+ workTypeOf: (id: string) => types[id],
+});
+
+const node = (reason: string | null, eventType: GoalEventType = 'updated') => ({
+ entityType: 'node' as const,
+ eventType,
+ reason,
+});
+
+describe('presentLifecycleEvent', () => {
+ it('hides the task registering its own task Work', () => {
+ expect(
+ presentLifecycleEvent(node('Attached Work version v1 as produced'), ctx({ v1: 'task' })),
+ ).toEqual({ hidden: true });
+ });
+
+ it('shows a delivered Work as the object of a "produced" row', () => {
+ expect(
+ presentLifecycleEvent(node('Attached Work version v2 as produced'), ctx({ v2: 'document' })),
+ ).toEqual({ action: 'work.produced', workVersion: { id: 'v2', relation: 'produced' } });
+ });
+
+ it('keeps an attached Work whose row is gone rather than hiding it', () => {
+ expect(presentLifecycleEvent(node('Attached Work version v3 as supports'), ctx())).toEqual({
+ action: 'work.supports',
+ workVersion: { id: 'v3', relation: 'supports' },
+ });
+ });
+
+ it('drops reasons that only restate the verb', () => {
+ expect(presentLifecycleEvent(node('Responsible task completed', 'resolved'), ctx())).toEqual(
+ {},
+ );
+ });
+
+ it('reads a canceled task as such and keeps only the main Agent diagnosis', () => {
+ expect(
+ presentLifecycleEvent(node('Task canceled — main Agent: stuck on a duplicate node'), ctx()),
+ ).toEqual({
+ action: 'taskCanceled',
+ note: { key: 'mainAgent', text: 'stuck on a duplicate node' },
+ });
+ expect(presentLifecycleEvent(node('Task canceled'), ctx())).toEqual({
+ action: 'taskCanceled',
+ });
+ });
+
+ it('hides the goal row a failure gate writes alongside its task row', () => {
+ expect(
+ presentLifecycleEvent(
+ { entityType: 'goal', eventType: 'updated', reason: 'Task canceled' },
+ ctx({}, true),
+ ),
+ ).toEqual({ hidden: true });
+ });
+
+ it('names pausing and resuming the goal', () => {
+ expect(
+ presentLifecycleEvent(
+ { entityType: 'goal', eventType: 'updated', reason: 'paused by user' },
+ ctx(),
+ ),
+ ).toEqual({ action: 'paused' });
+ expect(
+ presentLifecycleEvent(
+ { entityType: 'goal', eventType: 'updated', reason: 'Goal or main Agent turn budget exhausted' },
+ ctx(),
+ ),
+ ).toEqual({ action: 'paused', note: { key: 'budgetExhausted' } });
+ expect(
+ presentLifecycleEvent(
+ { entityType: 'goal', eventType: 'activated', reason: 'resumed by user' },
+ ctx(),
+ ),
+ ).toEqual({ action: 'resumed' });
+ });
+
+ it('translates fixed recovery reasons', () => {
+ expect(
+ presentLifecycleEvent(
+ node('Recovered an abandoned Task operation and started the next attempt', 'activated'),
+ ctx(),
+ ),
+ ).toEqual({ note: { key: 'recoveredAbandoned' } });
+ });
+
+ it('keeps an unrecognised reason as written', () => {
+ expect(presentLifecycleEvent(node('Planner refined the description'), ctx())).toEqual({
+ note: { text: 'Planner refined the description' },
+ });
+ });
+});
+
+describe('nodeTwinKey', () => {
+ it('matches events written in the same second with the same reason', () => {
+ const a = nodeTwinKey({ createdAt: new Date('2026-09-28T01:51:00.100Z'), reason: 'x' });
+ const b = nodeTwinKey({ createdAt: new Date('2026-09-28T01:51:00.900Z'), reason: 'x' });
+ expect(a).toBe(b);
+ });
+});
diff --git a/src/features/Portal/GoalMetric/lifecycleEvent.ts b/src/features/Portal/GoalMetric/lifecycleEvent.ts
new file mode 100644
index 00000000000..b2206dfc790
--- /dev/null
+++ b/src/features/Portal/GoalMetric/lifecycleEvent.ts
@@ -0,0 +1,122 @@
+import type { GoalGraphEvent, GoalNodeWorkVersionRelation } from '@lobechat/types';
+
+/**
+ * How one goal event reads in the timeline.
+ *
+ * Events only carry a free-text `reason`, and much of it is coordinator
+ * bookkeeping written for logs ("Attached Work version <uuid> as produced",
+ * "Responsible task completed"). This turns the reasons the coordinator writes
+ * verbatim into something a person can read: a verb that already says what
+ * happened, the note worth keeping, or nothing at all when the row adds no
+ * information. A reason it does not recognise is kept as written.
+ */
+export type LifecyclePresentation =
+ | { hidden: true }
+ | {
+ /** Overrides the generic "<verb> <kind>" action. */
+ action?: LifecycleAction;
+ hidden?: false;
+ /** The note under the row; `undefined` drops the raw reason. */
+ note?: LifecycleNote;
+ /** A Work version the event attached, to show as the row's object. */
+ workVersion?: { id: string; relation: GoalNodeWorkVersionRelation };
+ };
+
+export type LifecycleAction =
+ | 'paused'
+ | 'resumed'
+ | 'taskCanceled'
+ | `work.${GoalNodeWorkVersionRelation}`;
+
+export type LifecycleNote =
+ | { key: 'budgetExhausted' | 'recoveredAbandoned' | 'retryAfterVerification' }
+ | { key: 'mainAgent'; text: string }
+ | { text: string };
+
+const ATTACHED_WORK = /^Attached Work version (\S+) as (input|produced|supports|contradicts)$/;
+/** `GoalService.gateOrTakeOver` appends the main Agent's diagnosis this way. */
+const MAIN_AGENT = ' — main Agent: ';
+const TASK_CANCELED = 'Task canceled';
+const BUDGET_EXHAUSTED = 'Goal or main Agent turn budget exhausted';
+
+/** Fixed coordinator reasons that carry meaning, shown in the reader's language. */
+const KNOWN_NOTES: Record<string, 'recoveredAbandoned' | 'retryAfterVerification'> = {
+ 'Automatically started the next Task attempt after verification feedback':
+ 'retryAfterVerification',
+ 'Recovered an abandoned Task operation and started the next attempt': 'recoveredAbandoned',
+};
+
+/** Reasons that only restate what the row's verb already says. */
+const REDUNDANT_REASONS = new Set([
+ 'Goal achieved',
+ 'Goal-level acceptance passed',
+ 'Responsible task completed',
+ 'paused by user',
+ 'resumed by user',
+]);
+
+/** The failure itself, and the main Agent's diagnosis when one was attached. */
+const splitDiagnosis = (reason: string) => {
+ const at = reason.indexOf(MAIN_AGENT);
+ if (at < 0) return { failure: reason };
+ return { diagnosis: reason.slice(at + MAIN_AGENT.length).trim(), failure: reason.slice(0, at) };
+};
+
+export interface LifecycleContext {
+ /**
+ * Whether a node event at the same moment carries the same reason. A failure
+ * gate moves the task node and the goal in one step with one reason, so the
+ * goal row would only repeat the task row.
+ */
+ hasNodeTwin: boolean;
+ /** Type of the Work behind a Work version id, when the graph joined it. */
+ workTypeOf: (workVersionId: string) => string | undefined;
+}
+
+export const presentLifecycleEvent = (
+ event: Pick<GoalGraphEvent, 'entityType' | 'eventType' | 'reason'>,
+ { hasNodeTwin, workTypeOf }: LifecycleContext,
+): LifecyclePresentation => {
+ const reason = event.reason?.trim();
+ if (!reason) return {};
+
+ const attached = ATTACHED_WORK.exec(reason);
+ if (attached) {
+ const [, id, relation] = attached;
+ // A task's own `task` Work is how the run registers itself, not something
+ // it delivered — the task row already says the task exists.
+ if (workTypeOf(id) === 'task') return { hidden: true };
+ return {
+ action: `work.${relation as GoalNodeWorkVersionRelation}`,
+ workVersion: { id, relation: relation as GoalNodeWorkVersionRelation },
+ };
+ }
+
+ if (event.entityType === 'goal' && event.eventType === 'updated') {
+ if (hasNodeTwin) return { hidden: true };
+ if (reason === 'paused by user') return { action: 'paused' };
+ if (reason === BUDGET_EXHAUSTED) return { action: 'paused', note: { key: 'budgetExhausted' } };
+ }
+ if (event.entityType === 'goal' && event.eventType === 'activated' && reason === 'resumed by user')
+ return { action: 'resumed' };
+
+ if (REDUNDANT_REASONS.has(reason)) return {};
+ if (KNOWN_NOTES[reason]) return { note: { key: KNOWN_NOTES[reason] } };
+
+ const { diagnosis, failure } = splitDiagnosis(reason);
+ if (event.entityType === 'node' && failure === TASK_CANCELED)
+ return {
+ action: 'taskCanceled',
+ ...(diagnosis ? { note: { key: 'mainAgent', text: diagnosis } } : {}),
+ };
+ if (diagnosis) return { note: { text: `${failure}\n${diagnosis}` } };
+
+ return { note: { text: reason } };
+};
+
+/**
+ * Keys node events by moment + reason so a goal event can tell it only
+ * repeats one. Second precision: both rows are written in the same step.
+ */
+export const nodeTwinKey = (event: Pick<GoalGraphEvent, 'createdAt' | 'reason'>) =>
+ `${Math.floor(event.createdAt.getTime() / 1000)}|${event.reason ?? ''}`;