DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(pet): 工作状态动画/气泡接线对齐 dsh-dafeiyu,修复成功动画被提前掐断
hairyf7d99aceab9c2
diff --git a/src/pet/app.tsx b/src/pet/app.tsxindex be95a204..459afce9 100644--- a/src/pet/app.tsx+++ b/src/pet/app.tsx@@ -8,6 +8,7 @@ import { useBubble } from './hooks/use-bubble'import { useDrag } from './hooks/use-drag'import { useOmitIgnoreCursorEvents } from './hooks/use-omit-ignore-cursor-events'import { usePet } from './hooks/use-pet'+import { isLoopingAnimation } from './pet-config'/** 拖拽方向 → 动画状态:桌面宠物在原生拖拽期间播放对应的移动动画。 */const DRAW_STATUS: Record<DragDirection, PetStatus> = {@@ -30,8 +31,10 @@ export function App() {() => {if (bubble.status === undefined)return pet.clear()+ // 细分档位(thinking/working/result/waiting)与 running 均为循环档;+ // 终态档(success/error)与 review/failed 播一次后回落(handleEnded)。pet.change({- loop: bubble.status === 'running',+ loop: isLoopingAnimation(bubble.status),status: bubble.status,})},diff --git a/src/pet/components/pet.tsx b/src/pet/components/pet.tsxindex 0e1dc756..d2614c38 100644--- a/src/pet/components/pet.tsx+++ b/src/pet/components/pet.tsx@@ -8,11 +8,13 @@ import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'reactimport { If } from 'react-if-lite'import { PET_STATUSES } from '../hooks/use-pet'import {+ isLoopingAnimation,pick,pickCategoryAction,poolEntryToStatus,resolvePresetName,rollKind,+ spriteStatusFallback,} from '../pet-config'const PET_BASE_WIDTH = 220@@ -621,13 +623,6 @@ function isSupportedAsset(value: Asset): boolean {&& value.spritesheet.length > 0}-function isLoopingAnimation(activity: Animation | string): boolean {- // moving-* 与 dragging 仅存在于原生拖拽期间(手势状态),持续播放直到拖拽结束。- return activity === 'idle' || activity === 'running'- || activity === 'moving-left' || activity === 'moving-right'- || activity === 'dragging'-}-function spriteSequence(activity: Animation | string, reducedMotion: boolean, loop: boolean): { frames: Frame[], loopStart: number | null } {const idleFrames = IDLE_DURATIONS.map((duration, column) => ({ column, duration: duration * 6, row: 0 }))const action = spriteAction(activity)@@ -643,7 +638,10 @@ function spriteSequence(activity: Animation | string, reducedMotion: boolean, lofunction spriteAction(activity: Animation | string): Frame[] {if (activity === 'idle')return IDLE_DURATIONS.map((duration, column) => ({ column, duration, row: 0 }))- const mapped = activity === 'turn' ? 'moving-right' : activity === 'bubble' ? 'waving' : activity === 'dragging' ? 'moving-right' : activity+ // 自定义图集无细分档行:先近似映射到既有行(thinking→waiting 等),+ // 此类档位对预设宠物(WebM)不影响——它们走 resolvePresetName 直接命中资产。+ const base = spriteStatusFallback(activity)+ const mapped = base === 'turn' ? 'moving-right' : base === 'bubble' ? 'waving' : base === 'dragging' ? 'moving-right' : baseconst config = ACTIONS[mapped as keyof typeof ACTIONS] ?? ACTIONS.wavingreturn Array.from({ length: config.frames }, (_, column) => ({column,diff --git a/src/pet/hooks/bubble-copy.test.ts b/src/pet/hooks/bubble-copy.test.tsnew file mode 100644index 00000000..5c977bfd--- /dev/null+++ b/src/pet/hooks/bubble-copy.test.ts@@ -0,0 +1,104 @@+/**+ * bubble-copy.test.ts — 桌宠气泡文案纯函数(对齐 dsh-dafeiyu src/status-copy.js)单测。+ *+ * 覆盖:seed 稳定选句(同 seed 恒定、不同 seed 可换句)、分组回落、工具活动分类+ * 文案、taskCopy 句式(对齐 dsh-dafeiyu:正在/继续、动作动词、默认处理「…」)。+ */+import { describe, expect, it } from 'vitest'+import { activityCopy, seedNumber, statusCopy, taskCopy, toolActivityGroup } from './bubble-copy'++describe('seedNumber', () => {+ it('numeric strings resolve to the absolute truncated integer', () => {+ expect(seedNumber('12.9')).toBe(12)+ expect(seedNumber('-7')).toBe(7)+ expect(seedNumber(5)).toBe(5)+ })++ it('non-numeric strings sum char code points (stable per string)', () => {+ expect(seedNumber('abc')).toBe(97 + 98 + 99)+ expect(seedNumber('abc')).toBe(seedNumber('abc'))+ expect(seedNumber(undefined)).toBe(0)+ expect(seedNumber('')).toBe(0)+ })+})++describe('statusCopy', () => {+ it('returns a stable sentence for the same seed within a group', () => {+ const first = statusCopy('thinking', 'session-1')+ expect(statusCopy('thinking', 'session-1')).toBe(first)+ })++ it('picks from known groups only', () => {+ const variants = new Set(['正在分析', '思考中', '整理结果中'])+ expect(variants.has(statusCopy('thinking', 0))).toBe(true)+ expect(variants.has(statusCopy('thinking', 1))).toBe(true)+ })++ it('falls back to the working group for unknown groups', () => {+ expect(['正在处理任务', '步骤正在进行中', '系统运行中']).toContain(statusCopy('unknown-group', 0))+ })+})++describe('activityCopy', () => {+ it('maps activity categories to their copy groups', () => {+ expect(['正在检索', '正在项目中进行全面搜索', '正在调阅相关文件']).toContain(activityCopy('searching', 0))+ expect(['正在修改', '正在写入变更内容', '正在调整代码实现']).toContain(activityCopy('editing', 1))+ expect(['正在检验', '正在运行测试集进行确认', '正在验证变更有效性']).toContain(activityCopy('testing', 2))+ expect(['正在执行', '正在启动项目服务', '正在监控指令执行状态']).toContain(activityCopy('commanding', 3))+ })++ it('falls back to the working group for missing activity categories', () => {+ expect(['正在处理任务', '步骤正在进行中', '系统运行中']).toContain(activityCopy('weird', 0))+ })+})++describe('toolActivityGroup', () => {+ it('classifies search/read/fetch tools as searching', () => {+ expect(toolActivityGroup('grep')).toBe('searching')+ expect(toolActivityGroup('read')).toBe('searching')+ expect(toolActivityGroup('web_fetch')).toBe('searching')+ })++ it('classifies write/edit tools as editing', () => {+ expect(toolActivityGroup('write')).toBe('editing')+ expect(toolActivityGroup('str_replace_editor')).toBe('editing')+ })++ it('classifies test/lint/build tools as testing', () => {+ expect(toolActivityGroup('run_test')).toBe('testing')+ expect(toolActivityGroup('lint')).toBe('testing')+ })++ it('classifies shell/terminal tools as commanding', () => {+ expect(toolActivityGroup('pwsh')).toBe('commanding')+ expect(toolActivityGroup('bash')).toBe('commanding')+ })++ it('returns working for unmatched tools', () => {+ expect(toolActivityGroup('think')).toBe('working')+ expect(toolActivityGroup(undefined)).toBe('working')+ })+})++describe('taskCopy', () => {+ it('strips trailing punctuation and keeps 正在/继续-prefixed tasks as-is plus 呢', () => {+ expect(taskCopy('正在写测试。')).toBe('正在写测试呢')+ expect(taskCopy('继续修改文档')).toBe('继续修改文档呢')+ })++ it('prefixes action-verb tasks with 正在 (dsh-dafeiyu 句式:正在 + 原文 + 呢)', () => {+ expect(taskCopy('修改 bug')).toBe('正在修改 bug呢')+ expect(taskCopy('搜索相关代码')).toBe('正在搜索相关代码呢')+ expect(taskCopy('整理文档')).toBe('正在整理文档呢')+ })++ it('wraps other tasks in 正在处理「…」呢', () => {+ expect(taskCopy('把动画接到气泡')).toBe('正在处理「把动画接到气泡」呢')+ })++ it('returns undefined for empty/whitespace tasks', () => {+ expect(taskCopy(undefined)).toBeUndefined()+ expect(taskCopy(' ')).toBeUndefined()+ expect(taskCopy('')).toBeUndefined()+ })+})diff --git a/src/pet/hooks/bubble-copy.ts b/src/pet/hooks/bubble-copy.tsnew file mode 100644index 00000000..c1c29009--- /dev/null+++ b/src/pet/hooks/bubble-copy.ts@@ -0,0 +1,119 @@+/**+ * bubble-copy.ts — 桌宠会话气泡文案的纯逻辑层(对齐 dsh-dafeiyu src/status-copy.js)。+ *+ * 分组文案(thinking/working/result/waiting/approval/success/error/…)+ seed 稳定选句、+ * 工具活动分类文案(activityCopy)、todo 任务文案(taskCopy)都是纯函数,无 React/DOM+ * 依赖,可独立单测。use-bubble.ts 只负责把会话状态喂进来取一句展示。+ * 桌宠窗口无 i18n 基础设施:按窗口语言(IS_ZH)就地取中/英文案。+ */++/** 桌宠窗口无 i18n 基础设施,就地按窗口语言取单语文案(与 pet.tsx 保留文案一致)。 */+const IS_ZH = (typeof document !== 'undefined' ? document.documentElement.lang || navigator.language : 'zh-CN')+ .toLowerCase()+ .startsWith('zh')++/**+ * 气泡文案库(对齐 dsh-dafeiyu src/status-copy.js 分组 + seed 稳定选句)。+ * 各组多备选句:statusCopy 按会话稳定 seed 选一句,避免同一会话反复切换文案。+ */+const STATUS_COPY: Record<string, readonly string[]> = {+ thinking: IS_ZH+ ? ['正在分析', '思考中', '整理结果中']+ : ['Analyzing information', 'Thinking', 'Organizing results'],+ working: IS_ZH+ ? ['正在处理任务', '步骤正在进行中', '系统运行中']+ : ['Processing task', 'Step in progress', 'System is working'],+ result: IS_ZH+ ? ['正在整理结果', '步骤已完成,准备下一步', '正在确认后续操作']+ : ['Organizing results', 'Step completed, preparing for next step', 'Confirming next action'],+ waiting: IS_ZH+ ? ['等待确认', '需提供后续指令', '请决策下一步操作']+ : ['Awaiting your confirmation', 'Requires your input', 'Please decide on the next step'],+ approval: IS_ZH+ ? ['等待审批', '需授权确认', '敏感操作确认授权']+ : ['Awaiting your approval', 'Authorization required', 'Please confirm and authorize this action'],+ success: IS_ZH+ ? ['任务已完成', '本阶段任务已完成', '流程执行成功']+ : ['Task completed successfully', 'Current phase completed', 'Execution succeeded'],+ running: IS_ZH+ ? ['任务运行中', '当前步骤正在处理']+ : ['Task is running', 'Current step is processing'],+ review: IS_ZH+ ? ['正在汇总变更', '变更已就绪,等待审阅']+ : ['Consolidating', 'Ready for your review'],+ failed: IS_ZH+ ? ['步骤执行失败', '操作执行过程中发生异常']+ : ['Step execution failed', 'An error occurred during operation'],+ error: IS_ZH+ ? ['任务发生错误', '出现异常,请进行排查', '流程未能成功']+ : ['Task encountered an error', 'Exception detected, please check', 'Process failed to complete'],+ stopped: IS_ZH+ ? ['任务已终止', '任务已在此处暂停']+ : ['Task terminated', 'Task paused at this stage'],+} as const++/** 工具活动分类 → 文案(对齐 dsh-dafeiyu activityCopy:按工具分类选句)。 */+const ACTIVITY_COPY: Record<string, readonly string[]> = {+ searching: IS_ZH+ ? ['正在检索', '正在项目中进行全面搜索', '正在调阅相关文件']+ : ['Searching', 'Searching across the project', 'Checking related files'],+ editing: IS_ZH+ ? ['正在修改', '正在写入变更内容', '正在调整代码实现']+ : ['Editing', 'Applying changes', 'Adjusting implementation'],+ testing: IS_ZH+ ? ['正在检验', '正在运行测试集进行确认', '正在验证变更有效性']+ : ['Verifying', 'Running test suites', 'Verifying changes'],+ commanding: IS_ZH+ ? ['正在执行', '正在启动项目服务', '正在监控指令执行状态']+ : ['Executing', 'Starting project services', 'Monitoring command execution'],+} as const++/** seed → 稳定非负整数(数值取整数部分,否则按字符码点求和;对齐 dsh-dafeiyu seedNumber)。 */+export function seedNumber(seed: string | number | undefined): number {+ const value = String(seed ?? '')+ const numeric = Number(value)+ if (Number.isFinite(numeric))+ return Math.abs(Math.trunc(numeric))+ return [...value].reduce((total, character) => total + (character.codePointAt(0) ?? 0), 0)+}++/** 按组取一句稳定文案(选句随 seed 变化但同一 seed 恒定)。 */+export function statusCopy(group: string, seed?: string | number): string {+ const variants = STATUS_COPY[group] ?? STATUS_COPY.working+ return variants[seedNumber(seed) % variants.length] ?? variants[0]+}++/** 工具活动分类文案(dsh-dafeiyu activityCopy 的对齐实现);无分类回落 working 通用文案。 */+export function activityCopy(activity: string, seed?: string | number): string {+ const variants = ACTIVITY_COPY[activity] ?? STATUS_COPY.working+ return variants[seedNumber(seed) % variants.length] ?? variants[0]+}++/**+ * 任务文本 → 气泡文案(对齐 dsh-dafeiyu taskCopy 的句式:+ * 「正在/继续」开头 → 原文+呢;动作动词开头 → 正在+原文+呢;否则 正在处理「原文」呢)。+ */+export function taskCopy(task: string | undefined): string | undefined {+ const value = String(task ?? '').trim().replace(/[。!?.!?]+$/u, '')+ if (!value)+ return undefined+ if (/^(?:正在|继续)/u.test(value))+ return `${value}呢`+ if (/^(?:准备|检查|验证|修改|修复|测试|构建|整理|分析|梳理|查找|搜索|读取|实现)/u.test(value))+ return `正在${value}呢`+ return `正在处理「${value}」呢`+}++/** 工具名 → 活动分类(对齐 dsh-dafeiyu toolActivity 正则 + DSH 实际工具名 pwsh;供 working 档无 liveActivity 时选文案)。 */+export function toolActivityGroup(tool: string | undefined): string {+ const value = String(tool || '').toLowerCase()+ if (/search|grep|find|glob|web|read|fetch|open/.test(value))+ return 'searching'+ if (/write|edit|patch|replace|create|move|delete/.test(value))+ return 'editing'+ if (/test|check|lint|build|verify/.test(value))+ return 'testing'+ if (/shell|bash|exec|command|terminal|powershell|pwsh/.test(value))+ return 'commanding'+ return 'working'+}diff --git a/src/pet/hooks/use-bubble.ts b/src/pet/hooks/use-bubble.tsindex a68f0fcd..a072ad86 100644--- a/src/pet/hooks/use-bubble.ts+++ b/src/pet/hooks/use-bubble.ts@@ -3,6 +3,7 @@ import type { PetStatus } from './use-pet'import { listen } from '@tauri-apps/api/event'import { useEffect, useState } from 'react'import { toast } from '@/utils/toast'+import { statusCopy, taskCopy, toolActivityGroup } from './bubble-copy'export interface BubbleSession {[key: string]: unknown@@ -19,6 +20,15 @@ const FAILED_BUBBLE_TIMEOUT = 4000const REVIEW_BUBBLE_TIMEOUT = 2500const SUCCESS_TOAST_TIMEOUT = 3000const FAILED_PULSE_TTL = 1800+/**+ * 终态档(success/error)聚合保持时长:对齐 dsh-pet 的 BUBBLE_DURATION_MS=10000+ * (终态动画播一次 + 10s 收气泡)语义。不得复用 SUCCESS_TOAST_TIMEOUT(3s)——成功+ * WebM(如 雀跃庆祝)实际播放时长超过 3s 时,聚合状态提前回落会让 app.tsx 的+ * useWatch 调 pet.clear() 掐断未播完的动画(用户报告:成功动画没播完就换回待机)。+ * 动画播完由视频 ended(handleEnded → 清 override)自然回落,toast 收起仍走+ * scheduleHide 的独立 3s(SUCCESS_TOAST_TIMEOUT),二者互不影响。+ */+const TERMINAL_PULSE_TTL = 10000/** 会话完成/变空闲后保留的时长:超过即从会话表沉淀,防止 durable subagent 等永不发 remove 的会话无界积累。 */const IDLE_SESSION_RETENTION = 5000@@ -68,12 +78,17 @@ const TOOL_ARG_KEYS: Record<string, readonly string[]> = {skill: ['name'],} as const-/** 状态优先级映射,数值越大优先级越高 */+/** 状态优先级映射,数值越大优先级越高(对齐 dsh-dafeiyu statePriority:等待>错误>工作>思考>空闲)。 */const STATUS_PRIORITY: Record<string, number> = {- 'waiting': 4,- 'review': 3,- 'failed': 2,- 'running': 1,+ 'waiting': 60,+ 'error': 50,+ 'failed': 45,+ 'review': 40,+ 'working': 30,+ 'result': 25,+ 'thinking': 20,+ 'running': 12,+ 'success': 10,'idle': 0,'turn': 0,'moving-left': 0,@@ -145,7 +160,15 @@ export function useBubble(): BubbleHandle {if (disposed)returnconst session = sessions.get(id)- if (!session || sessionStatus(session) !== undefined)+ if (!session)+ return+ // 活跃档(think/work/result/waiting/running/review)不沉淀;+ // 终态档(workStatus success/error)翻开底层:底层空闲(回合完成且无错误残留)才可沉淀。+ const status = sessionStatus(session)+ const bottom = sessionStatus(session, true)+ if (bottom !== undefined)+ return+ if (status !== undefined && status !== 'success' && status !== 'error')returnremoveSessionData(id)@@ -154,15 +177,22 @@ export function useBubble(): BubbleHandle {const armPrune = (id: string) => {clearTimer(pruneTimers, id)- pruneTimers.set(id, window.setTimeout(() => {+ const timer = window.setTimeout(() => {pruneTimers.delete(id)pruneSession(id)- }, IDLE_SESSION_RETENTION))+ }, IDLE_SESSION_RETENTION)+ pruneTimers.set(id, timer)}const scheduleHide = (id: string, current: PetStatus) => {clearTimer(hideTimers, id)- const timeout = current === 'failed' ? FAILED_BUBBLE_TIMEOUT : current === 'review' ? REVIEW_BUBBLE_TIMEOUT : undefined+ const timeout = current === 'failed' || current === 'error'+ ? FAILED_BUBBLE_TIMEOUT+ : current === 'review'+ ? REVIEW_BUBBLE_TIMEOUT+ : current === 'success'+ ? SUCCESS_TOAST_TIMEOUT+ : undefinedconst key = toastKeys.get(id)if (timeout === undefined || key === undefined)return@@ -180,11 +210,14 @@ export function useBubble(): BubbleHandle {const current = sessionStatus(session)const previous = previousStatus.get(session.id)- if (current === 'failed') {- if (previous === 'failed' || consumedFailed.has(session.id))+ if (current === 'failed' || current === 'error' || current === 'success') {+ if (previous === current || consumedFailed.has(session.id))return- const deadline = Date.now() + FAILED_PULSE_TTL+ // 终态档脉冲窗口:failed 短 TTL 恢复底层状态;success/error 为终态档,+ // 保持 TERMINAL_PULSE_TTL(对齐 dsh-pet 10s 收气泡),等动画完整播完再回落空闲。+ const ttl = current === 'success' || current === 'error' ? TERMINAL_PULSE_TTL : FAILED_PULSE_TTL+ const deadline = Date.now() + ttlfailedUntil.set(session.id, deadline)clearTimer(pulseTimers, session.id)@@ -195,7 +228,7 @@ export function useBubble(): BubbleHandle {clearTimer(pulseTimers, session.id)consumedFailed.add(session.id)updateAgg()- }, FAILED_PULSE_TTL)+ }, ttl)pulseTimers.set(session.id, timer)}@@ -231,7 +264,8 @@ export function useBubble(): BubbleHandle {}clearTimer(pruneTimers, session.id)- const isTerminal = current === 'failed' || current === 'review'+ // 终态档(播完即收):failed/error 失败、review 待审阅、success 完成。+ const isTerminal = current === 'failed' || current === 'review' || current === 'error' || current === 'success'if (!isTerminal) {dismissed.delete(session.id)}@@ -246,7 +280,7 @@ export function useBubble(): BubbleHandle {isLoading: content.isLoading,description: content.description,placement: 'top end',- variant: content.variant as 'warning' | 'danger' | 'default',+ variant: content.variant as 'warning' | 'danger' | 'default' | 'success',timeout: 0,onClose: () => {if (toastKeys.get(session.id) === createdKey) {@@ -340,15 +374,32 @@ function sessionTitle(session: BubbleSession): string {if (session.phase === 'user-question' || session.phase === 'blocked')return `${LABELS.waitChoice} · ${base}`if (session.origin === 'subagent')- return `${LABELS.subagent}:${base}`+ return `${LABELS.subagent} · ${base}`return base}-/** 提取单个会话的状态(忽略底层恢复逻辑) */+/** 细分工作状态档位(host reducer workStatus 输出;动画名映射见 pet-config)。 */+const WORK_STATUSES = ['thinking', 'working', 'result', 'waiting', 'success', 'error'] as const++type WorkStatus = (typeof WORK_STATUSES)[number]++/** 提取单个会话的状态(细分档优先,忽略底层恢复逻辑)。 */function sessionStatus(session: BubbleSession, ignoreError = false): PetStatus | undefined {+ // 细分工作档位(host reducer 权威):thinking/working/result/waiting/success/error+ const work = session.workStatus as unknown+ if (WORK_STATUSES.includes(work as WorkStatus)) {+ // error/success 是终态档;pulse 过期(ignoreError)后回落底层推导,不残留失败/成功视觉。+ if (ignoreError && (work === 'error' || work === 'success'))+ return undefined+ return work as PetStatus+ }+const value = session.status ?? session.activity ?? session.phase- if (!ignoreError && (value === 'failed' || value === 'error' || Boolean(session.lastAgentError))) {+ // 终态错误判定只在回合已结束(running !== true)时生效:工具级失败/旧快照的+ // lastAgentError 若与 running=true 并存,说明回合仍在跑(agent 捕获错误继续),+ // 此时绝不判 failed 收起气泡(用户报告:会话还在跑 toast 却消失了)。+ if (!ignoreError && session.running !== true && (value === 'failed' || value === 'error' || Boolean(session.lastAgentError))) {return 'failed'}if (value === 'review' || value === 'reviewing' || value === 'plan-review') {@@ -380,7 +431,7 @@ function statusOf(for (const session of sessions.values()) {let status = sessionStatus(session)- if (status === 'failed') {+ if (status === 'failed' || status === 'error' || status === 'success') {const deadline = failedUntil.get(session.id)if (deadline === undefined || now >= deadline) {status = sessionStatus(session, true) // 底层恢复状态@@ -392,7 +443,7 @@ function statusOf(if (priority > maxPriority) {maxPriority = priorityhighestStatus = status- if (maxPriority === 4)+ if (maxPriority === STATUS_PRIORITY.waiting)break // 'waiting' 为最高优先级,提前终止遍历}}@@ -436,7 +487,7 @@ function toolArgDetail(tool: string, args: unknown): string | undefined {return undefined}-/** 生成 Toast 渲染数据 */+/** 生成 Toast 渲染数据(对齐 dsh-dafeiyu:优先失败详情 → 任务文案 → 工具/思考活动 → 档位状态文案)。 */function toastContent(session: BubbleSession, status: PetStatus) {const getFirstString = (...items: unknown[]): string | undefined => {for (const item of items) {@@ -448,21 +499,24 @@ function toastContent(session: BubbleSession, status: PetStatus) {}const getLiveActivity = (): string | undefined => {- if (status !== 'running' || !session.liveActivity || typeof session.liveActivity !== 'object') {+ if (status !== 'running' && status !== 'thinking' && status !== 'working' && status !== 'result') {+ return undefined+ }+ if (!session.liveActivity || typeof session.liveActivity !== 'object') {return undefined}const { kind, text, name, args } = session.liveActivity as Record<string, unknown>if (kind === 'reasoning' && typeof text === 'string' && text.trim()) {- return `思考 · ${sanitizeText(text)}`+ return IS_ZH ? `思考 · ${sanitizeText(text)}` : `Thought · ${sanitizeText(text)}`}if (kind === 'tool' && typeof name === 'string' && name) {const tool = name.toLowerCase()const label = TOOL_LABELS[tool]if (!label)- return `工具调用 · ${name}`+ return IS_ZH ? `工具调用 · ${name}` : `Tool · ${name}`const detail = toolArgDetail(tool, args)return detail ? `${label} · ${detail}` : label@@ -473,37 +527,56 @@ function toastContent(session: BubbleSession, status: PetStatus) {const isSub = session.origin === 'subagent'const title = sessionTitle(session)- const statusTextMap: Record<PetStatus, string> = {- 'failed': '失败',- 'review': '待审阅',- 'waiting': '等待中',- 'running': isSub ? '运行中' : '思考中',- 'idle': '空闲',- 'turn': '空闲',- 'moving-left': '空闲',- 'moving-right': '空闲',- 'waving': '空闲',+ // 会话稳定 seed(同会话同档位文案恒定,跨档位切换自然换句;对齐 dsh-dafeiyu statusCopy(seed))。+ const seed = session.id+ const statusTextMap: Record<string, string> = {+ 'think': IS_ZH ? '思考中' : 'Thinking',+ 'thinking': IS_ZH ? '思考中' : 'Thinking',+ 'working': IS_ZH ? '处理中' : 'Working',+ 'result': IS_ZH ? '整理中' : 'Organizing',+ 'waiting': IS_ZH ? '等待中' : 'Waiting',+ 'running': isSub ? (IS_ZH ? '运行中' : 'Running') : (IS_ZH ? '思考中' : 'Thinking'),+ 'review': IS_ZH ? '待审阅' : 'Review',+ 'failed': IS_ZH ? '失败' : 'Failed',+ 'error': IS_ZH ? '出错' : 'Error',+ 'success': IS_ZH ? '已完成' : 'Done',+ 'idle': IS_ZH ? '空闲' : 'Idle',+ 'turn': IS_ZH ? '空闲' : 'Idle',+ 'moving-left': IS_ZH ? '空闲' : 'Idle',+ 'moving-right': IS_ZH ? '空闲' : 'Idle',+ 'waving': IS_ZH ? '空闲' : 'Idle',}- const statusText = statusTextMap[status] ?? '空闲'+ const statusText = statusTextMap[status] ?? (IS_ZH ? '空闲' : 'Idle')+ // 档位状态文案:waiting 分 approval/user-question 两档,working 按工具活动分类选句。+ const fallbackCopy = status === 'waiting'+ ? (session.phase === 'approval' ? statusCopy('approval', seed) : statusCopy('waiting', seed))+ : status === 'working'+ ? statusCopy(toolActivityGroup(String((session.liveActivity as Record<string, unknown> | undefined)?.name ?? '')), seed)+ : statusCopy(status, seed)const description = getFirstString(+ session.lastAgentError ? (IS_ZH ? `失败:${String(session.lastAgentError)}` : `Failed: ${String(session.lastAgentError)}`) : undefined,+ taskCopy(session.task as string | undefined), // todo 任务文案:正在处理「xxx」呢+ getLiveActivity(), // 工具/思考活动详情(保留既有实用信息)+ fallbackCopy, // 档位状态文案(dsh-dafeiyu statusCopy)session.description,session.message,- session.lastAgentError ? `失败:${String(session.lastAgentError)}` : undefined,- getLiveActivity(),statusText,- ) ?? '会话'+ ) ?? (IS_ZH ? '会话' : 'Session')- const variant = (status === 'waiting' || status === 'review')+ const variant = status === 'waiting' || status === 'review'? 'warning'- : status === 'failed'+ : status === 'failed' || status === 'error'? 'danger'- : 'default'+ : status === 'success'+ ? 'success'+ : 'default'return {title,description,- isLoading: status === 'running',+ // 工作中平凡态显示 spinner(running/细分工作档位);等待/终态档不显示 loading。+ isLoading: status === 'running' || status === 'thinking' || status === 'working' || status === 'result',variant,}}diff --git a/src/pet/hooks/use-pet.ts b/src/pet/hooks/use-pet.tsindex da0d46fa..9ef52f0f 100644--- a/src/pet/hooks/use-pet.ts+++ b/src/pet/hooks/use-pet.ts@@ -7,10 +7,16 @@ export const PET_STATUSES = ['moving-left','moving-right','waving',+ // 细分工作状态档位(host reducer workStatus;动画名映射见 pet-config PRESET_SESSION_ANIMATIONS)+ 'thinking',+ 'working',+ 'result','waiting','running','review','failed',+ 'success',+ 'error',] as constexport type PetStatus = (typeof PET_STATUSES)[number]diff --git a/src/pet/pet-config.test.ts b/src/pet/pet-config.test.tsindex 933ca3de..35ed2272 100644--- a/src/pet/pet-config.test.ts+++ b/src/pet/pet-config.test.ts@@ -1,12 +1,14 @@import type { PetCategory, PetWeights } from './pet-config'import { describe, expect, it, vi } from 'vitest'import {+ isLoopingAnimation,pick,pickCategoryAction,pickWeightedCategory,poolEntryToStatus,resolvePresetName,rollKind,+ spriteStatusFallback,} from './pet-config'const WEIGHTS: PetWeights = { idle: 10, turn: 5, move: 5 }@@ -112,8 +114,14 @@ describe('resolvePresetName', () => {'东张西望': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E4%B8%9C.webm','被鼠标拖拽悬空反馈': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E8%A2%AB.webm','点击回应-开心跃动': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E5%BC%80.webm',- // DSH 会话状态叠加映射名(与旧内置 maid-*.webm 一一对应)- '深度思考碎碎念': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E6%B7%B1.webm',+ // DSH 细分工作状态档位叠加映射名(e1ff8c1 起的 6 个新 webm)+ '工作状态-思考冒泡': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E6%80%9D.webm',+ '工作状态-忙碌点按': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E5%BF%99.webm',+ '工作状态-清点归档': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E6%B8%85.webm',+ '工作状态-原地踱步张望': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E8%B8%B1.webm',+ '工作状态-雀跃庆祝': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E9%9B%80.webm',+ '工作状态-垂头叹气冒汗': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E5%9E%82.webm',+ // 旧粗态兼容映射名'写代码': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E5%86%99.webm','轻快记录': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E8%BD%BB.webm','玩游戏气急败坏': 'dsh-pet://localhost/maid-deepseek-whale/webm/%E6%B0%94.webm',@@ -134,12 +142,43 @@ describe('resolvePresetName', () => {})it('maps session statuses to the DSH overlay animation names', () => {- expect(resolvePresetName('waiting', pools, assets)).toBe('深度思考碎碎念')+ // 细分工作状态档位(e1ff8c1 起的 6 个新 webm)+ expect(resolvePresetName('thinking', pools, assets)).toBe('工作状态-思考冒泡')+ expect(resolvePresetName('working', pools, assets)).toBe('工作状态-忙碌点按')+ expect(resolvePresetName('result', pools, assets)).toBe('工作状态-清点归档')+ expect(resolvePresetName('waiting', pools, assets)).toBe('工作状态-原地踱步张望')+ expect(resolvePresetName('success', pools, assets)).toBe('工作状态-雀跃庆祝')+ expect(resolvePresetName('error', pools, assets)).toBe('工作状态-垂头叹气冒汗')+ // 旧粗态兼容映射expect(resolvePresetName('running', pools, assets)).toBe('写代码')expect(resolvePresetName('review', pools, assets)).toBe('轻快记录')expect(resolvePresetName('failed', pools, assets)).toBe('玩游戏气急败坏')})+ it('isLoopingAnimation:细分非终态档与 idle/running 循环,终态档与 review/failed 播一次', () => {+ expect(isLoopingAnimation('idle')).toBe(true)+ expect(isLoopingAnimation('thinking')).toBe(true)+ expect(isLoopingAnimation('working')).toBe(true)+ expect(isLoopingAnimation('result')).toBe(true)+ expect(isLoopingAnimation('waiting')).toBe(true)+ expect(isLoopingAnimation('running')).toBe(true)+ expect(isLoopingAnimation('success')).toBe(false)+ expect(isLoopingAnimation('error')).toBe(false)+ expect(isLoopingAnimation('review')).toBe(false)+ expect(isLoopingAnimation('failed')).toBe(false)+ expect(isLoopingAnimation('waving')).toBe(false)+ })++ it('spriteStatusFallback:自定义图集无细分档行,近似映射到既有行', () => {+ expect(spriteStatusFallback('thinking')).toBe('waiting')+ expect(spriteStatusFallback('working')).toBe('running')+ expect(spriteStatusFallback('result')).toBe('review')+ expect(spriteStatusFallback('success')).toBe('waving')+ expect(spriteStatusFallback('error')).toBe('failed')+ expect(spriteStatusFallback('idle')).toBe('idle')+ expect(spriteStatusFallback('running')).toBe('running')+ })+it('returns null for session statuses whose overlay asset is missing', () => {const partial: Record<string, string> = { 待机呼吸休闲: 'x.webm' }expect(resolvePresetName('running', pools, partial)).toBeNull()diff --git a/src/pet/pet-config.ts b/src/pet/pet-config.tsindex 6e0c34ca..cdcfa91c 100644--- a/src/pet/pet-config.ts+++ b/src/pet/pet-config.ts@@ -55,6 +55,38 @@ export interface PetConfig {eventsRefreshSec?: Record<string, number>}+/**+ * 播放状态是否循环。+ * - idle/running/moving-*\/dragging:常驻循环(手势期间持续直到结束);+ * - 细分工作状态档位 thinking/working/result/waiting:非终态档,常驻循环播动画+ * (对齐 dsh-pet workStatusTick 语义:等用户/干活期间动画不自动结束);+ * - 终态档 success/error 与 review/failed:播一次后回落(气泡收尾由 use-bubble 管理)。+ */+export function isLoopingAnimation(activity: string): boolean {+ return activity === 'idle' || activity === 'running'+ || activity === 'thinking' || activity === 'working' || activity === 'result' || activity === 'waiting'+ || activity === 'moving-left' || activity === 'moving-right'+ || activity === 'dragging'+}++/**+ * 自定义 Codex v2 图集没有细分档位行(固定 8×11,无思考/工作/整理/庆祝行):+ * 细分档播放时近似映射到既有行,避免播到错误 sprite(保留会话状态近似观感)。+ */+export function spriteStatusFallback(activity: string): string {+ return activity === 'thinking'+ ? 'waiting'+ : activity === 'working'+ ? 'running'+ : activity === 'result'+ ? 'review'+ : activity === 'success'+ ? 'waving'+ : activity === 'error'+ ? 'failed'+ : activity+}+/** 从字符串池等概率抽一个;exclude 排除某个名字(避免连续重复)。 */export function pick<T>(pool: readonly T[], exclude?: T): T {const entries = exclude === undefined ? pool : pool.filter(item => item !== exclude)@@ -125,15 +157,26 @@ export function poolEntryToStatus(entry: string): string {/*** DSH 会话状态 → dsh-pet 动画名(webm 文件名主名)的叠加映射。*- * dsh-pet 协议(config.jsonc)只有 idle/turn/drag/clicks/moves/categories/events 池,- * 没有 waiting/running/review/failed/bubble 这些 DSH 会话状态的对应池。这些动画文件- * 在预设资产里真实存在(与旧内置 maid-*.webm 按字节一一对应,见 pet.todo.md 4.0),- * 由本表把会话状态映射到具体文件名:running 循环写代码、waiting 深度思考碎碎念、- * review 轻快记录、failed 玩游戏气急败坏、bubble 鲸鱼吐泡泡特效。+ * 两族状态:+ * 1. 细分工作状态档位(workStatus,host reducer 输出):thinking/working/result/+ * waiting/success/error,对齐 dsh-pet config.jsonc animations.events.workStatus+ * 数组(索引即档位)——turn/start→thinking、tool/call→working、tool/result→result、+ * approval/asked 等→waiting、turn/end completed→success、error/max-tokens→error。+ * 这些档位优先映射到工作状态系列动画(思考冒泡/忙碌点按/清点归档/踱步张望/+ * 雀跃庆祝/垂头叹气冒汗,e1ff8c1 起的新预设资产)。+ * 2. 旧粗态兼容(无细分档的会话展示路径):running 写代码、review 轻快记录、+ * failed 玩游戏气急败坏、bubble 鲸鱼吐泡泡特效。* 资产缺失时 resolvePresetName 仍返回 null(调用方保持当前动画,不做静默兜底)。*/export const PRESET_SESSION_ANIMATIONS: Record<string, string> = {- waiting: '深度思考碎碎念',+ // 细分工作状态档位(workStatus)+ thinking: '工作状态-思考冒泡',+ working: '工作状态-忙碌点按',+ result: '工作状态-清点归档',+ waiting: '工作状态-原地踱步张望',+ success: '工作状态-雀跃庆祝',+ error: '工作状态-垂头叹气冒汗',+ // 旧粗态兼容running: '写代码',review: '轻快记录',failed: '玩游戏气急败坏',