🤯 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
🐛 fix(goal): generate acceptance criteria with AI (#18265)
Arvin Xu0dddd8b8563f
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex fca7efa8f1f..7ffcb991f92 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -243,8 +243,8 @@"createGoal.criteriaTitle": "Acceptance criteria","createGoal.criterionPlaceholder": "Describe a result that can be clearly checked","createGoal.describeHint": "Describe the outcome first, then complete its execution plan.",- "createGoal.describeTitle": "What outcome do you want?",- "createGoal.generateFailed": "Could not draft acceptance criteria. Try again.",+ "createGoal.describeTitle": "What goal do you expect to achieve?",+ "createGoal.generateFailed": "Could not draft acceptance criteria, so your goal was used as the criterion.","createGoal.instructionPlaceholder": "Add any context the agent needs — scope, constraints, where to look…","createGoal.next": "Next","createGoal.preparing": "Preparing plan…",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex b24d814d80c..edb7d8973d0 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -243,8 +243,8 @@"createGoal.criteriaTitle": "验收标准","createGoal.criterionPlaceholder": "描述一个能够明确检查的结果","createGoal.describeHint": "先描述想要的结果,下一步再完善完整执行计划。",- "createGoal.describeTitle": "你想要的效果",- "createGoal.generateFailed": "没能起草验收标准,请重试。",+ "createGoal.describeTitle": "你期望达到的目标",+ "createGoal.generateFailed": "没能自动起草,已将目标内容作为验收标准。","createGoal.instructionPlaceholder": "补充 Agent 需要的背景 —— 范围、约束、从哪里入手……","createGoal.next": "下一步","createGoal.preparing": "正在准备计划…",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex e09e1dc01d8..3b50c0eaf5a 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -1540,9 +1540,10 @@ export default {'createGoal.criterionPlaceholder': 'Describe a result that can be clearly checked','createGoal.criteriaHint': 'Review and edit these before the goal starts','createGoal.criteriaTitle': 'Acceptance criteria',- 'createGoal.describeTitle': 'What outcome do you want?',+ 'createGoal.describeTitle': 'What goal do you expect to achieve?','createGoal.describeHint': 'Describe the outcome first, then complete its execution plan.',- 'createGoal.generateFailed': 'Could not draft acceptance criteria. Try again.',+ 'createGoal.generateFailed':+ 'Could not draft acceptance criteria, so your goal was used as the criterion.','createGoal.instructionPlaceholder':'Add any context the agent needs — scope, constraints, where to look…','createGoal.next': 'Next',diff --git a/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx b/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsxindex 02b05fa9b7e..68ee2cacf76 100644--- a/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx+++ b/src/features/AgentGoals/CreateGoalModal/CreateGoalContent.tsx@@ -4,10 +4,10 @@ import type { CreateGoalParams, GoalCriterionDraft } from '@lobechat/builtin-tooimport { openCriterionEditModal } from '@lobechat/builtin-tool-task/client';import { DEFAULT_GOAL_MAX_ROUNDS } from '@lobechat/const/verify';import { useEditor } from '@lobehub/editor/react';-import { ActionIcon, Flexbox, Icon, Text } from '@lobehub/ui';+import { ActionIcon, Flexbox, Icon, Tag, Text } from '@lobehub/ui';import { Button, toast, useModalContext } from '@lobehub/ui/base-ui';import { InputNumber } from 'antd';-import { createStaticStyles, cssVar } from 'antd-style';+import { createGlobalStyle, createStaticStyles, cssVar } from 'antd-style';import {ArrowLeft,CircleDashed,@@ -32,9 +32,12 @@ import { EditorCanvas } from '@/features/EditorCanvas';import { pickAndInsertAttachments } from '@/features/EditorCanvas/editorAttachments';import { usePermission } from '@/hooks/usePermission';import { verifyService } from '@/services/verify';+import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors, agentSelectors } from '@/store/agent/selectors';import { useTaskStore } from '@/store/task';-import { buildGoalTaskConfig, deriveInitialGoalCriterionTitle } from './goalConfig';+import { buildGoalTaskConfig } from './goalConfig';+import { createFallbackGoalCriterion, generateGoalCriteria } from './goalCriteria';import { deriveGoalTitle } from './goalTitle';const styles = createStaticStyles(({ css }) => ({@@ -123,37 +126,34 @@ const styles = createStaticStyles(({ css }) => ({padding: 2px;border-radius: inherit;- background: linear-gradient(- 90deg,- ${cssVar.colorBorderSecondary} 0%,- ${cssVar.colorBorderSecondary} 16%,- #ff3d8d 30%,- #8b5cf6 40%,- #00c8ff 50%,- #22e6a8 60%,- #ffd43b 70%,- #ff6b35 80%,- ${cssVar.colorBorderSecondary} 92%,- ${cssVar.colorBorderSecondary} 100%+ background: conic-gradient(+ from var(--goal-border-angle),+ ${cssVar.colorBorderSecondary} 0deg 210deg,+ #ff3d8d 238deg,+ #8b5cf6 258deg,+ #00c8ff 278deg,+ #22e6a8 298deg,+ #ffd43b 318deg,+ #ff6b35 338deg,+ ${cssVar.colorBorderSecondary} 360deg);- background-size: 300% 100%;mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);- animation: goal-input-flow 1.2s linear infinite;+ animation: goal-input-flow 1.8s linear infinite;mask-composite: exclude;}@keyframes goal-input-flow {from {- background-position: 0% 50%;+ --goal-border-angle: 0deg;}to {- background-position: 150% 50%;+ --goal-border-angle: 360deg;}}@@ -175,16 +175,6 @@ const styles = createStaticStyles(({ css }) => ({padding-block-end: 0 !important;}`,- optional: css`- flex: none;- color: ${cssVar.colorTextSecondary};- background: ${cssVar.colorFillSecondary};- `,- required: css`- flex: none;- color: ${cssVar.colorInfo};- background: ${cssVar.colorInfoBg};- `,reviewSection: css`padding-block: 16px;@@ -222,6 +212,14 @@ const styles = createStaticStyles(({ css }) => ({`,}));+const GoalBorderFlowStyle = createGlobalStyle`+ @property --goal-border-angle {+ inherits: false;+ initial-value: 0deg;+ syntax: '<angle>';+ }+`;+const criterionRequirement = (drafts: GoalCriterionDraft[]) =>drafts.map((draft) => draft.title.trim())@@ -257,6 +255,16 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {const createTask = useTaskStore((s) => s.createTask);const isCreating = useTaskStore((s) => s.isCreatingTask);const activeWorkspaceId = useActiveWorkspaceId();+ const model = useAgentStore((s) =>+ agentId+ ? agentByIdSelectors.getAgentModelById(agentId)(s)+ : agentSelectors.currentAgentModel(s),+ );+ const provider = useAgentStore((s) =>+ agentId+ ? agentByIdSelectors.getAgentModelProviderById(agentId)(s)+ : agentSelectors.currentAgentModelProvider(s),+ );const [step, setStep] = useState<'describe' | 'preparing' | 'review'>('describe');const [plan, setPlan] = useState<CreateGoalParams>({@@ -277,13 +285,6 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {}, [isPrivateAgent, visibility]);const editor = useEditor();- const prepareTimerRef = useRef<ReturnType<typeof setTimeout>>(null);- useEffect(- () => () => {- if (prepareTimerRef.current) clearTimeout(prepareTimerRef.current);- },- [],- );const instructionRef = useRef(plan.instruction);const assigneeMeta = useAgentDisplayMeta(agentId);const requirement = useMemo(() => criterionRequirement(plan.criteria), [plan.criteria]);@@ -298,30 +299,41 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {pickAndInsertAttachments(editor);}, [editor]);- const handleNext = useCallback(() => {+ const handleNext = useCallback(async () => {const instruction = instructionRef.current.trim() || plan.instruction.trim();- if (!canCreate || !instruction) return;- const criterionTitle = deriveInitialGoalCriterionTitle(instruction, initialRequirement);+ if (!canCreate || !instruction || !model || !provider) return;+ const name = plan.name.trim() || deriveGoalTitle(instruction);setPlan((current) => ({...current,- criteria:- current.criteria.length > 0- ? current.criteria- : [- {- onFail: 'auto_repair',- required: true,- title: criterionTitle,- verifierType: 'agent',- },- ],instruction,- name: current.name.trim() || deriveGoalTitle(instruction),+ name,}));instructionRef.current = instruction;setStep('preparing');- prepareTimerRef.current = setTimeout(() => setStep('review'), 1200);- }, [canCreate, initialRequirement, plan.instruction]);+ try {+ const generated = await generateGoalCriteria({+ context: name ? `Goal: ${name}` : undefined,+ goal: initialRequirement?.trim() || instruction,+ model,+ provider,+ });+ setPlan((current) => ({+ ...current,+ criteria: generated,+ }));+ setStep('review');+ } catch (error) {+ console.error('[CreateGoalContent] generate failed:', error);+ setPlan((current) => ({+ ...current,+ criteria: [createFallbackGoalCriterion(instruction)],+ instruction,+ name: instruction,+ }));+ setStep('review');+ toast.warning(t('createGoal.generateFailed'));+ }+ }, [canCreate, initialRequirement, model, plan.instruction, plan.name, provider, t]);const handleCreateBlank = useCallback(() => {if (!canCreate) return;@@ -448,6 +460,7 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {return (<Flexbox onKeyDown={handleKeyDown}>+ <GoalBorderFlowStyle /><Flexbox horizontal className={styles.head}><Flexbox flex={1} gap={6}>{step === 'review' && (@@ -544,10 +557,10 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {<Text ellipsis style={{ flex: 1, minWidth: 0 }}>{criterion.title || t('createGoal.criterionPlaceholder')}</Text>- <Button- className={(criterion.required ?? true) ? styles.required : styles.optional}+ <Tag+ color={(criterion.required ?? true) ? 'info' : undefined}size={'small'}- type={'text'}+ variant={'filled'}onClick={(event) => {event.stopPropagation();updateCriterion(index, {@@ -559,7 +572,7 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {{(criterion.required ?? true)? t('verifyConfig.required'): t('verifyConfig.optional')}- </Button>+ </Tag><ActionIconicon={Pencil}size={'small'}@@ -596,9 +609,13 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {min={2}size={'small'}style={{ width: '100%' }}- suffix={t('createGoal.roundsUnit')}value={plan.maxIterations ?? undefined}variant={'filled'}+ suffix={+ <Text fontSize={12} type={'secondary'}>+ {t('createGoal.roundsUnit')}+ </Text>+ }onChange={(value) => setPlan((current) => ({ ...current, maxIterations: value }))}/><Text className={styles.sectionHint} fontSize={12}>@@ -615,11 +632,15 @@ const CreateGoalContent = memo<CreateGoalContentProps>((props) => {disabled={!canCreate}min={0}placeholder={t('createGoal.costBudgetPlaceholder')}- prefix={'$'}size={'small'}style={{ width: '100%' }}value={plan.maxTotalCost}variant={'filled'}+ prefix={+ <Text fontSize={12} type={'secondary'}>+ $+ </Text>+ }onChange={(value) => setPlan((current) => ({ ...current, maxTotalCost: value }))}/><Text className={styles.sectionHint} fontSize={12}>diff --git a/src/features/AgentGoals/CreateGoalModal/goalCriteria.test.ts b/src/features/AgentGoals/CreateGoalModal/goalCriteria.test.tsnew file mode 100644index 00000000000..6d8ba0845c1--- /dev/null+++ b/src/features/AgentGoals/CreateGoalModal/goalCriteria.test.ts@@ -0,0 +1,69 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { verifyService } from '@/services/verify';++import { createFallbackGoalCriterion, generateGoalCriteria } from './goalCriteria';++describe('generateGoalCriteria', () => {+ beforeEach(() => {+ vi.restoreAllMocks();+ });++ it('generates and normalizes acceptance criteria for the goal review step', async () => {+ const generateCriteria = vi+ .spyOn(verifyService, 'generateCriteria')+ .mockResolvedValue([+ { title: 'Paper draft is complete' },+ { required: false, title: 'Results are reproducible', verifierType: 'llm' },+ ]);++ const result = await generateGoalCriteria({+ context: 'Goal: Publish an ICLR paper',+ goal: 'Complete an RSI benchmark paper in three months',+ model: 'test-model',+ provider: 'test-provider',+ });++ expect(generateCriteria).toHaveBeenCalledWith({+ context: 'Goal: Publish an ICLR paper',+ goal: 'Complete an RSI benchmark paper in three months',+ maxCriteria: 8,+ modelConfig: { model: 'test-model', provider: 'test-provider' },+ });+ expect(result).toEqual([+ {+ onFail: 'auto_repair',+ required: true,+ title: 'Paper draft is complete',+ verifierType: 'agent',+ },+ {+ onFail: 'auto_repair',+ required: false,+ title: 'Results are reproducible',+ verifierType: 'llm',+ },+ ]);+ });++ it('rejects an empty AI response instead of advancing with no criteria', async () => {+ vi.spyOn(verifyService, 'generateCriteria').mockResolvedValue([]);++ await expect(+ generateGoalCriteria({+ goal: 'Ship the project',+ model: 'test-model',+ provider: 'test-provider',+ }),+ ).rejects.toThrow('No acceptance criteria were generated.');+ });++ it('uses the original goal as a reviewable criterion when AI generation fails', () => {+ expect(createFallbackGoalCriterion('Ship the project')).toEqual({+ onFail: 'auto_repair',+ required: true,+ title: 'Ship the project',+ verifierType: 'agent',+ });+ });+});diff --git a/src/features/AgentGoals/CreateGoalModal/goalCriteria.ts b/src/features/AgentGoals/CreateGoalModal/goalCriteria.tsnew file mode 100644index 00000000000..e0a2cbd8442--- /dev/null+++ b/src/features/AgentGoals/CreateGoalModal/goalCriteria.ts@@ -0,0 +1,43 @@+import type { GoalCriterionDraft } from '@lobechat/builtin-tool-task';++import type { VerifyCriterionDraft } from '@/services/verify';+import { verifyService } from '@/services/verify';++interface GenerateGoalCriteriaParams {+ context?: string;+ goal: string;+ model: string;+ provider: string;+}++export const withGoalCriterionDefaults = (draft: VerifyCriterionDraft): GoalCriterionDraft => ({+ ...draft,+ onFail: draft.onFail ?? 'auto_repair',+ required: draft.required ?? true,+ verifierType: draft.verifierType ?? 'agent',+});++export const createFallbackGoalCriterion = (goal: string): GoalCriterionDraft => ({+ onFail: 'auto_repair',+ required: true,+ title: goal,+ verifierType: 'agent',+});++export const generateGoalCriteria = async ({+ context,+ goal,+ model,+ provider,+}: GenerateGoalCriteriaParams): Promise<GoalCriterionDraft[]> => {+ const generated = await verifyService.generateCriteria({+ context,+ goal,+ maxCriteria: 8,+ modelConfig: { model, provider },+ });++ if (generated.length === 0) throw new Error('No acceptance criteria were generated.');++ return generated.map(withGoalCriterionDefaults);+};