DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(ui): hide continuation request notices (#962)
Mao Mr6d13b903a668
diff --git a/packages/dsh-tauri-ui/src/client/index.test.ts b/packages/dsh-tauri-ui/src/client/index.test.tsindex 913fcbea..79da95f1 100644--- a/packages/dsh-tauri-ui/src/client/index.test.ts+++ b/packages/dsh-tauri-ui/src/client/index.test.ts@@ -1,5 +1,6 @@import { afterEach, describe, expect, it, vi } from 'vitest'import { apply } from './index'+import { registerContinueNotice } from './register/continue-notice'import { registerSettings } from './register/settings'vi.mock('./components', () => ({}))@@ -8,6 +9,7 @@ vi.mock('./components/segmented-control', () => ({}))vi.mock('./hooks/use-mount-style', () => ({}))vi.mock('./locales', () => ({ locale: { registerLocale: vi.fn() } }))vi.mock('./register/composer-resume', () => ({ composerResumeFeature: vi.fn() }))+vi.mock('./register/continue-notice', () => ({ registerContinueNotice: vi.fn() }))vi.mock('./register/hero-workspace', () => ({ heroWorkspaceFeature: vi.fn() }))vi.mock('./register/im-panel', () => ({ registerImPanel: vi.fn() }))vi.mock('./register/new-session', () => ({ sidebarNewSessionFeature: vi.fn(), ungroupedNewSessionFeature: vi.fn() }))@@ -32,7 +34,8 @@ describe('ui client settings effect registration', () => {apply({ effect } as unknown as Parameters<typeof apply>[0])expect(effect).toHaveBeenCalledWith(registerSettings, 'dsh-tauri-ui: settings panel')- expect(effect).toHaveBeenCalledTimes(11)+ expect(effect).toHaveBeenCalledTimes(12)+ expect(effect).toHaveBeenCalledWith(registerContinueNotice, 'dsh-tauri-ui: continue notice')expect(effect).toHaveBeenCalledWith(expect.any(Function), 'dsh-tauri-ui: styles')expect(effect.mock.calls.some(([, name]) => name.includes('mobile'))).toBe(false)})diff --git a/packages/dsh-tauri-ui/src/client/index.ts b/packages/dsh-tauri-ui/src/client/index.tsindex 8f3cd1fd..26ff55bc 100644--- a/packages/dsh-tauri-ui/src/client/index.ts+++ b/packages/dsh-tauri-ui/src/client/index.ts@@ -4,6 +4,7 @@ import { PLUGIN_ID } from '../shared/constants'import { HERO_WORKSPACE_EFFECT, IM_PANEL_EFFECT, LOCALE_EFFECT, NEW_SESSION_EFFECT, OBSTRUCTIONS_EFFECT, SECTIONS_EFFECT, SETTINGS_EFFECT, SETTINGS_OPEN_EFFECT, STYLES_EFFECT, UNGROUPED_NEW_SESSION_EFFECT } from './constants'import { locale } from './locales'import { composerResumeFeature } from './register/composer-resume'+import { registerContinueNotice } from './register/continue-notice'import { heroWorkspaceFeature } from './register/hero-workspace'import { registerImPanel } from './register/im-panel'import { sidebarNewSessionFeature, ungroupedNewSessionFeature } from './register/new-session'@@ -30,6 +31,7 @@ export const name = PLUGIN_IDexport const inject = ['slots', 'layout', 'locale', 'sessions']const COMPOSER_RESUME_EFFECT = `${PLUGIN_ID}: composer resume`+const CONTINUE_NOTICE_EFFECT = `${PLUGIN_ID}: continue notice`export function apply(ctx: ClientContext): void {ctx.effect(locale.registerLocale, LOCALE_EFFECT)@@ -42,5 +44,6 @@ export function apply(ctx: ClientContext): void {ctx.effect(registerSettingsOpen, SETTINGS_OPEN_EFFECT)ctx.effect(ungroupedNewSessionFeature, UNGROUPED_NEW_SESSION_EFFECT)ctx.effect(composerResumeFeature, COMPOSER_RESUME_EFFECT)+ ctx.effect(registerContinueNotice, CONTINUE_NOTICE_EFFECT)ctx.effect(registerImPanel, IM_PANEL_EFFECT)}diff --git a/packages/dsh-tauri-ui/src/client/register/continue-notice.test.ts b/packages/dsh-tauri-ui/src/client/register/continue-notice.test.tsnew file mode 100644index 00000000..4aead007--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/register/continue-notice.test.ts@@ -0,0 +1,171 @@+import type { ComponentType } from 'react'+import { SlotCore } from '@deepseek-ai/dsh-client-ui-slots'+import { createElement, memo } from 'react'+import { renderToStaticMarkup } from 'react-dom/server'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { registerContinueNotice } from './continue-notice'++vi.mock('dsh-tauri/client', async () => ({+ ...await import('../../../../dsh-tauri/src/client/register'),+ ...await import('../../../../dsh-tauri/src/client/modules/lodash-es'),+}))++const SLOT = 'conversation.chat.node'+const cleanups: Array<() => void> = []++function setup(declared = true) {+ const core = new SlotCore()+ const declare = () => core.register({+ name: 'root',+ children: { [SLOT]: { kind: 'keyed', scope: 'session' } },+ } as never, (() => null) as never)+ const slots = {+ spec: core.spec.bind(core),+ entries: core.entries.bind(core),+ entriesOfSlot: core.entriesOfSlot.bind(core),+ subscribe: core.subscribe.bind(core),+ register: vi.fn(core.register.bind(core)),+ inject(key: string, callback: () => Iterable<() => void>) {+ let disposers: Array<() => void> = []+ const clear = () => {+ for (const dispose of disposers.splice(0).reverse())+ dispose()+ }+ const sync = () => {+ clear()+ if (core.specDynamic(key) !== undefined)+ disposers = [...callback()]+ }+ const unsubscribe = core.subscribeDeclaration(key, sync)+ sync()+ return () => {+ unsubscribe()+ clear()+ }+ },+ }+ const undeclare = declared ? declare() : undefined+ const ctx = { get: (name: string) => name === 'slots' ? slots : undefined }+ const dispose = registerContinueNotice.call(ctx)+ cleanups.push(dispose)+ const add = (key: string, priority = 0, extra = {}) => core.register({+ name: SLOT,+ key,+ priority,+ locale: 'chat',+ registrant: 'official-chat',+ ...extra,+ } as never, memo((props: Record<string, unknown>) => createElement('button', {}, String(props.label))) as never)+ const render = (key: string, source: unknown, label = 'Original request') => {+ const entry = core.entriesOfSlot(SLOT).find(entry => entry.options.key === key)+ expect(entry, `Missing ${key} renderer`).not.toBeUndefined()+ return renderToStaticMarkup(createElement(entry!.component as ComponentType<Record<string, unknown>>, {+ node: Object.freeze({ data: Object.freeze({ source }) }),+ label,+ }))+ }+ return { core, slots, add, render, dispose, declare, undeclare, ctx }+}++afterEach(() => {+ for (const dispose of cleanups.splice(0))+ dispose()+ vi.restoreAllMocks()+})++describe('continue notice rendering', () => {+ it.each(['turn-trigger', 'context'])('hides only the continue source in %s', async (key) => {+ const h = setup()+ h.add(key)+ await Promise.resolve()+ expect(h.render(key, Object.freeze({ kind: 'continue' }))).toBe('<span data-dsh-tauri-ui-continue-notice="" hidden=""></span>')+ expect(h.render(key, { kind: 'continue', recovery: 'content-risk' })).not.toContain('Original request')+ expect(h.render(key, { kind: 'schedule' })).toBe('<button>Original request</button>')+ expect(h.render(key, { kind: 'content-risk-recovery' }, 'Safe recovery boundary')).toBe('<button>Safe recovery boundary</button>')+ expect(h.render(key, { kind: 'user' }, '继续')).toBe('<button>继续</button>')+ expect(h.render(key, undefined)).toBe('<button>Original request</button>')+ })++ it('waits for the declaration and preserves the original registration shares', async () => {+ const h = setup(false)+ expect(h.slots.register).not.toHaveBeenCalled()+ h.declare()+ const inject = () => ({ extra: 'injected' })+ h.add('turn-trigger', -4, { inject })+ await Promise.resolve()+ expect(h.slots.register.mock.calls[0]?.[0]).toMatchObject({+ name: SLOT,+ key: 'turn-trigger',+ priority: -5,+ locale: 'chat',+ inject,+ })+ expect(h.render('turn-trigger', { kind: 'continue' })).not.toContain('Original request')+ })++ it('rebinds after replacement without repeatedly registering itself', async () => {+ const h = setup()+ const remove = h.add('turn-trigger')+ await Promise.resolve()+ const first = h.core.entriesOfSlot(SLOT)[0]+ await Promise.resolve()+ expect(h.slots.register).toHaveBeenCalledTimes(1)+ remove()+ h.add('turn-trigger', -2)+ await Promise.resolve()+ expect(h.core.entriesOfSlot(SLOT)[0]).not.toBe(first)+ expect(h.slots.register).toHaveBeenCalledTimes(2)+ await Promise.resolve()+ expect(h.slots.register).toHaveBeenCalledTimes(2)+ })++ it('unloads the wrapper when the original disappears or the plugin disposes', async () => {+ const h = setup()+ const remove = h.add('turn-trigger')+ await Promise.resolve()+ remove()+ await Promise.resolve()+ expect(h.core.entries(SLOT)).toEqual([])+ h.add('turn-trigger')+ await Promise.resolve()+ h.dispose()+ await Promise.resolve()+ expect(h.core.entries(SLOT)).toHaveLength(1)+ expect(h.render('turn-trigger', { kind: 'continue' })).toBe('<button>Original request</button>')+ })++ it.each(['install', 'replacement'])('preserves the live fallback when the raw head retired before %s', async (phase) => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ const h = setup()+ if (phase === 'install') {+ h.dispose()+ }+ else {+ const remove = h.add('turn-trigger')+ await Promise.resolve()+ remove()+ h.slots.register.mockClear()+ }+ h.add('turn-trigger', -2)+ h.core.register({ name: SLOT, key: 'turn-trigger', priority: 1 } as never, (() => createElement('button', {}, 'Survivor')) as never)+ const retired = h.core.entries(SLOT).find(entry => entry.options.priority === -2)!+ h.core.reportEntryError(SLOT, retired, new Error('Retired renderer'), { abdicate: true })+ if (phase === 'install')+ cleanups.push(registerContinueNotice.call(h.ctx))+ await Promise.resolve()+ expect(h.render('turn-trigger', { kind: 'schedule' })).toBe('<button>Survivor</button>')+ expect(h.render('turn-trigger', { kind: 'continue' })).toBe('<button>Survivor</button>')+ expect(h.slots.register).not.toHaveBeenCalled()+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('continue'))+ })++ it('does not shadow a renderer that owns child slots', async () => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ const h = setup()+ h.add('turn-trigger', 0, { children: { 'notice.child': { kind: 'single', scope: 'session' } } })+ await Promise.resolve()+ expect(h.slots.register).not.toHaveBeenCalled()+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('continue'))+ expect(h.render('turn-trigger', { kind: 'schedule' })).toBe('<button>Original request</button>')+ })+})diff --git a/packages/dsh-tauri-ui/src/client/register/continue-notice.ts b/packages/dsh-tauri-ui/src/client/register/continue-notice.tsnew file mode 100644index 00000000..eb586de0--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/register/continue-notice.ts@@ -0,0 +1,66 @@+import type { ClientContext, SlotRegistry, StoredEntry } from 'dsh-tauri/client'+import type { ComponentType } from 'react'+import { defineRegister, get } from 'dsh-tauri/client'+import { createElement } from 'react'+import { PLUGIN_ID } from '../../shared/constants'++const CONTINUE_NOTICE_SLOT = 'conversation.chat.node' as Parameters<SlotRegistry['inject']>[0]++export const registerContinueNotice = defineRegister<ClientContext>((controller, _ctx, adapter) => {+ const slots = adapter.service<SlotRegistry>('slots')+ if (!slots || typeof slots.inject !== 'function' || typeof slots.entries !== 'function'+ || typeof slots.entriesOfSlot !== 'function' || typeof slots.subscribe !== 'function'+ || typeof slots.spec !== 'function' || typeof slots.register !== 'function') {+ console.warn(`[${PLUGIN_ID}] continue 提示隐藏不可用:缺少会话节点槽能力`)+ return+ }++ controller.add(slots.inject(CONTINUE_NOTICE_SLOT, function* () {+ const spec: NonNullable<StoredEntry['children']>[string] | undefined = slots.spec(CONTINUE_NOTICE_SLOT)+ if (spec?.kind !== 'keyed' || spec.scope !== 'session') {+ console.warn(`[${PLUGIN_ID}] continue 提示隐藏不可用:会话节点槽契约不匹配`)+ return+ }+ for (const key of ['context', 'turn-trigger']) {+ let original: StoredEntry | undefined+ let wrapper: unknown+ let unregister: (() => void) | undefined+ const sync = () => {+ const next = slots.entries(CONTINUE_NOTICE_SLOT)+ .find(entry => entry.options.key === key && entry.component !== wrapper)+ if (next === original)+ return+ unregister?.()+ unregister = undefined+ original = next+ if (!next)+ return+ const priority = (next.options.priority ?? 0) - 1+ // ponytail: retired heads keep official fallback; track retirement if survivors need wrapping.+ if (slots.entriesOfSlot(CONTINUE_NOTICE_SLOT).find(entry => entry.options.key === key) !== next+ || Object.keys(next.children ?? {}).length > 0 || !Number.isFinite(priority)+ || priority >= (next.options.priority ?? 0) || next.component == null) {+ console.warn(`[${PLUGIN_ID}] continue 提示隐藏不可用:${key} 渲染器不支持安全包装`)+ return+ }+ const Original = next.component as ComponentType<Record<string, unknown>>+ const ContinueNotice = (props: Record<string, unknown>) => get(props, 'node.data.source.kind') === 'continue'+ ? createElement('span', { 'data-dsh-tauri-ui-continue-notice': '', 'hidden': true })+ : createElement(Original, props)+ wrapper = ContinueNotice+ unregister = slots.register({+ name: CONTINUE_NOTICE_SLOT,+ key,+ priority,+ registrant: PLUGIN_ID,+ locale: next.locale,+ inject: next.inject,+ store: next.store,+ } as never, ContinueNotice as never)+ }+ yield () => unregister?.()+ yield slots.subscribe(CONTINUE_NOTICE_SLOT, sync)+ sync()+ }+ }))+})diff --git a/packages/dsh-tauri-ui/src/client/styles/global.cssr.test.ts b/packages/dsh-tauri-ui/src/client/styles/global.cssr.test.tsindex 516db6a3..87f03b2c 100644--- a/packages/dsh-tauri-ui/src/client/styles/global.cssr.test.ts+++ b/packages/dsh-tauri-ui/src/client/styles/global.cssr.test.ts@@ -122,6 +122,10 @@ describe('chat flow off-screen rendering', () => {})})+ it('只移除带 continue 标记的外层聊天节点,不留下间距', () => {+ expect(rules['[data-chat-flow-key]:has(> [data-slot="conversation.chat.node"] > [data-dsh-tauri-ui-continue-notice])']).toEqual({ display: 'none' })+ })+it('不把内容整块藏起来(保浏览器查找与无障碍树)', () => {expect(globalStyle.render()).not.toMatch(/content-visibility:\s*hidden/)})diff --git a/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts b/packages/dsh-tauri-ui/src/client/styles/global.cssr.tsindex f9d2419b..5231c939 100644--- a/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts+++ b/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts@@ -159,6 +159,9 @@ export default c([contentVisibility: 'auto',containIntrinsicSize: 'auto 320px',}),+ c('[data-chat-flow-key]:has(> [data-slot="conversation.chat.node"] > [data-dsh-tauri-ui-continue-notice])', {+ display: 'none !important',+ }),c('[class$="sidebarCol"]', {borderRight: 'none !important',