Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(pet): refine pet window toasts

hairyf382362c4d887
diff --git a/docs/plugins/pet.todo.md b/docs/plugins/pet.todo.md
index 3f7bffdd..bd6fc265 100644
--- a/docs/plugins/pet.todo.md
+++ b/docs/plugins/pet.todo.md
@@ -335,6 +335,29 @@ BongoCat 是窗口行为基准,不是完整交互基准。它在 mousedown 立
- 验证:`tsc --noEmit` ✅、`eslint src/pet --max-warnings=0` 零 warning ✅、
`vitest run` 239/239 ✅(含 pet-config 14 条)。无 Rust 改动。
+### 4.0g 最近完成(feat/pet-reapply,会话完成成功 toast + 气泡图标 + toast 微调)
+
+用户三项小优化:
+
+- **会话完成成功 toast**(`src/pet/hooks/use-bubble.ts`):真实运行时 SessionSnapshot
+ 只有 `running: boolean` 与 `lastAgentError`(无 status/phase 字段),完成信号 =
+ `running: true → false` 边沿(失败先经 lastAgentError 落在 'failed',不会误触发)。
+ `syncToast` 在 `current === undefined && previous === 'running'` 时先 closeToast 常驻
+ 气泡,再弹 3s `variant: 'success'` toast(`SUCCESS_TOAST_TIMEOUT = 3000`,
+ title=会话名,description='已完成',placement 'top end');250ms 心跳重发同状态
+ 不重复触发。会话从列表删除(remove)不算完成,不弹。
+- **气泡图标恢复**(`src/components/toast-provider.tsx` hideCloseButton 分支,桌宠窗口
+ 专用):自定义渲染缺 `Toast.Indicator`,图标消失。对齐 HeroUI `getDefaultChildren`
+ 源码补回:`indicator === null` 隐藏;`isLoading` 显示 `Spinner`(import
+ `Spinner` from '@heroui/react');否则显示 content.indicator 或按 variant 默认图标
+ (default/accent→Info、success→Success、warning→Warning、danger→Danger)。
+- **toast 位置/宽度微调**(`src/pet/main.css`,仅 pet webview 生效):`.toast-region--top-end`
+ `top: 2.5rem`(原 top-4=1rem,下移一点);`.toast-region` `width: calc(90vw - 2rem)`
+ (原 `w-[calc(100vw-2rem)]`,收窄约 10%)。规则放 @layer base 之外(unlayered 后置
+ 覆盖 @heroui/styles 的 toast.css 规则)。
+- 验证:`tsc --noEmit` ✅、`eslint src/pet src/components/toast-provider.tsx
+ --max-warnings=0` 零 warning ✅、`vitest run` 239/239 ✅、`git diff --check` ✅。
+
### 4.1 已完成并应保留
- 三个参考仓库已加入 `source/*` 子模块。
diff --git a/src/components/toast-provider.tsx b/src/components/toast-provider.tsx
index d8a3f8c5..9f478282 100644
--- a/src/components/toast-provider.tsx
+++ b/src/components/toast-provider.tsx
@@ -1,7 +1,7 @@
import type { ReactNode } from 'react'
import type { ToastUpdateEvent } from '@/utils/toast'
import { useEventBus } from '@hairy/react-lib'
-import { Toast } from '@heroui/react'
+import { Spinner, Toast } from '@heroui/react'
import { useState } from 'react'
import { If } from 'react-if-lite'
import { activeQueues, placements } from '@/utils/toast'
@@ -39,8 +39,18 @@ export function ToastProvider(props: ToastProviderProps) {
{props.hideCloseButton
? ({ toast: item }) => {
const content = { ...item.content, ...updates.get(item.key) }
+
+ // 对齐 HeroUI 默认渲染(getDefaultChildren):indicator === null
+ // 隐藏图标;isLoading 时显示 Spinner;否则显示内容或按 variant 的
+ // 默认图标(default/accent→Info、success→Success、warning→Warning、
+ // danger→Danger)。
return (
<Toast toast={item} variant={content?.variant}>
+ <If cond={content?.isLoading} else={<Toast.Indicator variant={content?.variant} />}>
+ <Toast.Indicator variant={content?.variant}>
+ <Spinner color="current" size="sm" />
+ </Toast.Indicator>
+ </If>
<Toast.Content>
<If cond={content?.title !== undefined}>
<Toast.Title>{content?.title}</Toast.Title>
diff --git a/src/pet/hooks/use-bubble.ts b/src/pet/hooks/use-bubble.ts
index 90adaf02..1a86be49 100644
--- a/src/pet/hooks/use-bubble.ts
+++ b/src/pet/hooks/use-bubble.ts
@@ -20,6 +20,8 @@ const DESCRIPTION_MAX_LENGTH = 120
/** 终态气泡自动隐藏时长(毫秒):失败展示 4s、待审阅 2.5s(对齐参考实现的完成脉冲)。实时状态(running / waiting)常驻,由后续会话事件更新内容。 */
const FAILED_BUBBLE_TIMEOUT = 4000
const REVIEW_BUBBLE_TIMEOUT = 2500
+/** 会话任务完成后的成功 toast 展示时长(毫秒)。 */
+const SUCCESS_TOAST_TIMEOUT = 3000
/**
* 失败动画脉冲时长(毫秒):对齐参考实现 companion-reducer 的工具失败脉冲 ttlMs=1800。
* 失败只作为瞬态脉冲展示一次,到期自动恢复到底层会话状态,避免 DSH 快照上粘性的
@@ -121,8 +123,15 @@ export function useBubble(): BubbleHandle {
previousStatus.set(session.id, current)
const key = toastKeys.get(session.id)
if (current === undefined) {
+ // 任务完成的边沿:running → 无状态(真实运行时的 SessionSnapshot 只有
+ // running: boolean 与 lastAgentError,没有 status/phase 字段;失败会先
+ // 经 lastAgentError 落在 'failed',不会走到这里)。关闭常驻气泡后弹出
+ // 一次 3s 的成功 toast,随后 250ms 心跳重发同状态不会重复触发。
+ const completed = previous === 'running'
if (key !== undefined)
closeToast(session.id)
+ if (completed)
+ showSuccessToast(session)
return
}
@@ -137,6 +146,7 @@ export function useBubble(): BubbleHandle {
return
let createdKey = ''
createdKey = toast(content.title, {
+ isLoading: content.isLoading,
description: content.description,
placement: 'top end',
variant: content.variant,
@@ -244,6 +254,7 @@ function rawSession(payload: unknown): BubbleSession | undefined {
function toastContent(session: BubbleSession): {
title: string
description: string
+ isLoading: boolean
variant: 'accent' | 'danger' | 'default'
} {
const status = sessionStatus(session)
@@ -257,10 +268,22 @@ function toastContent(session: BubbleSession): {
return {
title,
description,
+ isLoading: status === 'running',
variant: status === 'failed' ? 'danger' : 'default',
}
}
+/** 任务完成的一次性成功提示:标题取会话名,正文固定「已完成」,3s 后自动关闭。 */
+function showSuccessToast(session: BubbleSession): void {
+ const title = truncate(firstText(session.title, session.displayTitle, session.name, session.id), TITLE_MAX_LENGTH)
+ toast(title, {
+ description: '已完成',
+ placement: 'top end',
+ variant: 'success',
+ timeout: SUCCESS_TOAST_TIMEOUT,
+ })
+}
+
function truncate(text: string, maxLength: number): string {
if (text.length <= maxLength)
return text
diff --git a/src/pet/main.css b/src/pet/main.css
index f13cac92..5924548a 100644
--- a/src/pet/main.css
+++ b/src/pet/main.css
@@ -3,6 +3,17 @@
@config "../../tailwind.config.js";
@import "@heroui/styles";
+/* 桌宠窗口 toast 微调(仅本 webview 生效):
+ - 整体下移一点,避免贴顶挤占宠物视野;
+ - 宽度收窄约 10%(toast.css 默认 w-[calc(100vw-2rem)])。 */
+.toast-region--top-end {
+ top: 2.5rem;
+}
+
+.toast-region {
+ width: calc(90vw - 2rem);
+}
+
@layer base {
html,
body,