DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): merge dialog into the manifest-imported client module
yingtianlan3c3a57cc6d26
diff --git a/plugins/dsh-tauri-turnrewind/lib/client.js b/plugins/dsh-tauri-turnrewind/lib/client.jsindex 418a7669..9a948040 100644--- a/plugins/dsh-tauri-turnrewind/lib/client.js+++ b/plugins/dsh-tauri-turnrewind/lib/client.js@@ -1,13 +1,22 @@// dsh-tauri-turnrewind — client bundle (browser).-// Registers a keyed renderer for the `conversation.chat.commandview` slot at-// key "undo", replacing the generic plain-text command card with a diff-aware-// view that renders deletions red and additions green.+//+// One module, two jobs:+// 1. Renders the `/undo` command card in the `conversation.chat.commandview`+// slot with a diff-aware view (deletions red, additions green).+// 2. Raises the in-app "undo unavailable" dialog when the current session+// carries the unsupported-workspace heads-up injected by the host.//// Hand-written against the DSH client module contract:// window.__ModuleLoader__.load({ id, factory }) where factory receives a// CommonJS-style `require` and must export `apply` (cordis plugin) + `inject`-// (list of cordis services the apply() context needs).-window.__ModuleLoader__.load({+// (services the apply() context needs).+//+// The module id MUST normalize to the bare package name: the client module+// system strips a trailing `/client` and the boot manifest imports the plugin+// under its package name, so this factory is what the manifest materializes.+// Registering a second module under another suffix would never be imported+// by anything and its apply() would silently never run.+globalThis.__ModuleLoader__.load({id: 'dsh-tauri-turnrewind/client',factory: (require) => {const module = { exports: {} }@@ -17,10 +26,10 @@ window.__ModuleLoader__.load({const jsx = jsxRuntime.jsxconst jsxs = jsxRuntime.jsxs- const inject = ['slots']+ const inject = ['slots', 'sessions', 'locale']// ------------------------------------------------------------------- // Unified-diff line classification.+ // /undo command card: unified-diff line classification.// ------------------------------------------------------------------function classifyLine(raw) {const line = raw@@ -51,7 +60,7 @@ window.__ModuleLoader__.load({}// ------------------------------------------------------------------- // Rendering.+ // /undo command card: rendering.// ------------------------------------------------------------------const COLORS = {delBg: 'rgba(248,81,73,0.16)',@@ -156,224 +165,207 @@ window.__ModuleLoader__.load({})}- function apply(ctx) {- ctx.slots.inject('conversation.chat.commandview', () => {- return ctx.slots.register({- name: 'conversation.chat.commandview',- key: 'undo',- }, UndoCommandView)- })+ // ------------------------------------------------------------------+ // Unsupported-workspace dialog: storage, DOM, and runner.+ // ------------------------------------------------------------------+ const NS = 'dsh-tauri-turnrewind'+ const SEEN_KEY = 'turnrewind.seenUnsupportedNotices'+ const MAX_SEEN = 100++ const dictionaries = {+ zh: {+ title: '撤销功能在此工作区不可用',+ intro: '当前会话的工作区不支持文件撤销。对话照常运行,但本工作区内的文件改动无法用 /undo 撤销。',+ reason: '原因',+ ok: '知道了',+ },+ en: {+ title: 'Undo is unavailable in this workspace',+ intro: 'File undo is disabled for this session\'s workspace. Turns still run normally, but changes in this workspace cannot be reverted with /undo.',+ reason: 'Reason',+ ok: 'Got it',+ },}- exports.apply = apply- exports.inject = inject- return module.exports- },-})-// Client half of dsh-tauri-turnrewind: raises an in-app dialog when the-// current session carries an unsupported-workspace heads-up from the host.-// Hand-wrapped in the dsh client ModuleLoader format (no build step): the web-// app evaluates this file and registers the module under the plugin name.-if (globalThis.__ModuleLoader__) {-// The bare package name is pre-registered by the client module system, so the-// dialog module needs its own suffix — reusing the package id throws-// "duplicate factory registration" and the dialog silently never applies.- try {- globalThis.__ModuleLoader__.load({ id: 'dsh-tauri-turnrewind/dialog', factory: () => {- const module = { exports: {} }- const exports = module.exports-- const inject = ['sessions', 'locale']-- const NS = 'dsh-tauri-turnrewind'- const SEEN_KEY = 'turnrewind.seenUnsupportedNotices'- const MAX_SEEN = 100-- const dictionaries = {- zh: {- title: '撤销功能在此工作区不可用',- intro: '当前会话的工作区不支持文件撤销。对话照常运行,但本工作区内的文件改动无法用 /undo 撤销。',- reason: '原因',- ok: '知道了',- },- en: {- title: 'Undo is unavailable in this workspace',- intro: 'File undo is disabled for this session\'s workspace. Turns still run normally, but changes in this workspace cannot be reverted with /undo.',- reason: 'Reason',- ok: 'Got it',- },+ function readSeen() {+ try {+ const raw = globalThis.localStorage.getItem(SEEN_KEY)+ const list = raw ? JSON.parse(raw) : []+ return Array.isArray(list) ? list : []}-- function readSeen() {- try {- const raw = globalThis.localStorage.getItem(SEEN_KEY)- const list = raw ? JSON.parse(raw) : []- return Array.isArray(list) ? list : []- }- catch {- return []- }+ catch {+ return []}+ }- function markSeen(id) {- try {- const seen = readSeen().filter(entry => entry !== id)- seen.push(id)- globalThis.localStorage.setItem(SEEN_KEY, JSON.stringify(seen.slice(-MAX_SEEN)))- }- catch {+ function markSeen(id) {+ try {+ const seen = readSeen().filter(entry => entry !== id)+ seen.push(id)+ globalThis.localStorage.setItem(SEEN_KEY, JSON.stringify(seen.slice(-MAX_SEEN)))+ }+ catch {// Storage may be unavailable; the dialog just re-shows next reload.- }}+ }- let dialog-- function palette() {- const dark = globalThis.matchMedia?.('(prefers-color-scheme: dark)')?.matches ?? false- return dark- ? { card: '#1f2937', text: '#f9fafb', muted: '#9ca3af', box: '#111827', boxBorder: '#374151', backdrop: 'rgba(2, 6, 23, 0.6)', button: '#6366f1', buttonText: '#ffffff' }- : { card: '#ffffff', text: '#111827', muted: '#6b7280', box: '#f3f4f6', boxBorder: '#e5e7eb', backdrop: 'rgba(15, 23, 42, 0.45)', button: '#4f46e5', buttonText: '#ffffff' }- }+ let dialog- function ensureDialog() {- if (dialog)- return dialog- const colors = palette()- const backdrop = document.createElement('div')- backdrop.setAttribute('role', 'presentation')- Object.assign(backdrop.style, {- display: 'none',- position: 'fixed',- inset: '0',- zIndex: '2147483000',- alignItems: 'center',- justifyContent: 'center',- background: colors.backdrop,- })+ function dialogPalette() {+ const dark = globalThis.matchMedia?.('(prefers-color-scheme: dark)')?.matches ?? false+ return dark+ ? { card: '#1f2937', text: '#f9fafb', muted: '#9ca3af', box: '#111827', boxBorder: '#374151', backdrop: 'rgba(2, 6, 23, 0.6)', button: '#6366f1', buttonText: '#ffffff' }+ : { card: '#ffffff', text: '#111827', muted: '#6b7280', box: '#f3f4f6', boxBorder: '#e5e7eb', backdrop: 'rgba(15, 23, 42, 0.45)', button: '#4f46e5', buttonText: '#ffffff' }+ }- const card = document.createElement('div')- card.setAttribute('role', 'dialog')- card.setAttribute('aria-modal', 'true')- Object.assign(card.style, {- maxWidth: '440px',- width: 'calc(100vw - 48px)',- boxSizing: 'border-box',- background: colors.card,- color: colors.text,- borderRadius: '12px',- padding: '20px 22px',- fontFamily: 'inherit',- fontSize: '13px',- lineHeight: '1.6',- boxShadow: '0 20px 50px rgba(0, 0, 0, 0.3)',- })+ function ensureDialog() {+ if (dialog)+ return dialog+ const colors = dialogPalette()+ const backdrop = document.createElement('div')+ backdrop.setAttribute('role', 'presentation')+ Object.assign(backdrop.style, {+ display: 'none',+ position: 'fixed',+ inset: '0',+ zIndex: '2147483000',+ alignItems: 'center',+ justifyContent: 'center',+ background: colors.backdrop,+ })- const title = document.createElement('div')- Object.assign(title.style, { fontSize: '15px', fontWeight: '600', marginBottom: '10px' })-- const intro = document.createElement('div')-- const reasonLabel = document.createElement('div')- Object.assign(reasonLabel.style, { marginTop: '12px', color: colors.muted, fontSize: '12px' })-- const reasonBox = document.createElement('div')- Object.assign(reasonBox.style, {- marginTop: '6px',- padding: '8px 10px',- borderRadius: '8px',- background: colors.box,- border: `1px solid ${colors.boxBorder}`,- wordBreak: 'break-all',- whiteSpace: 'pre-wrap',- maxHeight: '160px',- overflowY: 'auto',- })+ const card = document.createElement('div')+ card.setAttribute('role', 'dialog')+ card.setAttribute('aria-modal', 'true')+ Object.assign(card.style, {+ maxWidth: '440px',+ width: 'calc(100vw - 48px)',+ boxSizing: 'border-box',+ background: colors.card,+ color: colors.text,+ borderRadius: '12px',+ padding: '20px 22px',+ fontFamily: 'inherit',+ fontSize: '13px',+ lineHeight: '1.6',+ boxShadow: '0 20px 50px rgba(0, 0, 0, 0.3)',+ })- const actions = document.createElement('div')- Object.assign(actions.style, { marginTop: '16px', textAlign: 'right' })- const button = document.createElement('button')- button.type = 'button'- Object.assign(button.style, {- background: colors.button,- color: colors.buttonText,- border: 'none',- borderRadius: '8px',- padding: '6px 18px',- fontSize: '13px',- cursor: 'pointer',- })- actions.appendChild(button)+ const title = document.createElement('div')+ Object.assign(title.style, { fontSize: '15px', fontWeight: '600', marginBottom: '10px' })++ const intro = document.createElement('div')++ const reasonLabel = document.createElement('div')+ Object.assign(reasonLabel.style, { marginTop: '12px', color: colors.muted, fontSize: '12px' })++ const reasonBox = document.createElement('div')+ Object.assign(reasonBox.style, {+ marginTop: '6px',+ padding: '8px 10px',+ borderRadius: '8px',+ background: colors.box,+ border: `1px solid ${colors.boxBorder}`,+ wordBreak: 'break-all',+ whiteSpace: 'pre-wrap',+ maxHeight: '160px',+ overflowY: 'auto',+ })- card.append(title, intro, reasonLabel, reasonBox, actions)- backdrop.appendChild(card)- document.body.appendChild(backdrop)+ const actions = document.createElement('div')+ Object.assign(actions.style, { marginTop: '16px', textAlign: 'right' })+ const button = document.createElement('button')+ button.type = 'button'+ Object.assign(button.style, {+ background: colors.button,+ color: colors.buttonText,+ border: 'none',+ borderRadius: '8px',+ padding: '6px 18px',+ fontSize: '13px',+ cursor: 'pointer',+ })+ actions.appendChild(button)- function hide() {- backdrop.style.display = 'none'- }- button.addEventListener('click', hide)- backdrop.addEventListener('click', (event) => {- if (event.target === backdrop)- hide()- })+ card.append(title, intro, reasonLabel, reasonBox, actions)+ backdrop.appendChild(card)+ document.body.appendChild(backdrop)- dialog = { backdrop, title, intro, reasonLabel, reasonBox, button }- return dialog+ function hide() {+ backdrop.style.display = 'none'}+ button.addEventListener('click', hide)+ backdrop.addEventListener('click', (event) => {+ if (event.target === backdrop)+ hide()+ })- function showDialog(t, notices) {- const el = ensureDialog()- el.title.textContent = t('title')- el.intro.textContent = t('intro')- el.reasonLabel.textContent = t('reason')- el.reasonBox.textContent = notices.map(notice => notice.reason || notice.id).join('\n')- el.button.textContent = t('ok')- el.backdrop.style.display = 'flex'- }+ dialog = { backdrop, title, intro, reasonLabel, reasonBox, button }+ return dialog+ }- function apply(ctx) {- console.warn('[turnrewind] client apply: unsupported-workspace dialog runner starting')- ctx.effect(() => ctx.locale.register(NS, dictionaries), 'turnrewind locale')- const t = ctx.locale.bind(NS)- // Read through the service store, not the ctx.sessions property proxy:- // the host session service merges a different member under the same name.- const sessions = ctx.get('sessions')-- function checkOnce() {- const state = sessions.list.getSnapshot()- const summary = state.current !== undefined ? state.byId[state.current] : undefined- const value = summary?.projectionValues?.turnrewind- const notices = Array.isArray(value?.notices) ? value.notices : []- const fresh = notices.filter(notice => notice && typeof notice.id === 'string' && !readSeen().includes(notice.id))- if (fresh.length === 0)- return- console.warn(`[turnrewind] unsupported heads-up visible: ${fresh.map(notice => notice.id).join(', ')}`)- for (const notice of fresh) markSeen(notice.id)- showDialog(t, fresh)- }+ function showDialog(t, notices) {+ const el = ensureDialog()+ el.title.textContent = t('title')+ el.intro.textContent = t('intro')+ el.reasonLabel.textContent = t('reason')+ el.reasonBox.textContent = notices.map(notice => notice.reason || notice.id).join('\n')+ el.button.textContent = t('ok')+ el.backdrop.style.display = 'flex'+ }- ctx.effect(() => {- const unsubscribe = sessions.list.subscribe(checkOnce)- // Projection frames can land while the page is loading, before the list- // store has any subscribers; poll briefly so that ordering can never- // silently swallow the heads-up.- const poll = setInterval(checkOnce, 2000)- const stopPolling = setTimeout(clearInterval, 120000, poll)- return () => {- unsubscribe()- clearInterval(poll)- clearTimeout(stopPolling)- }- }, 'turnrewind dialog runner')+ // ------------------------------------------------------------------+ // Plugin apply: both features share the one cordis plugin this bundle+ // materializes into (the boot manifest imports the package name).+ // ------------------------------------------------------------------+ function apply(ctx) {+ console.warn('[turnrewind] client apply: command view + dialog runner starting')++ ctx.effect(() => {+ ctx.slots.inject('conversation.chat.commandview', () => {+ return ctx.slots.register({+ name: 'conversation.chat.commandview',+ key: 'undo',+ }, UndoCommandView)+ })+ }, 'turnrewind command view')++ // Unsupported-workspace heads-up runner.+ ctx.effect(() => ctx.locale.register(NS, dictionaries), 'turnrewind locale')+ const t = ctx.locale.bind(NS)+ // Read through the service store, not the ctx.sessions property proxy:+ // the host session service merges a different member under the same name.+ const sessions = ctx.get('sessions')++ function checkOnce() {+ const state = sessions.list.getSnapshot()+ const summary = state.current !== undefined ? state.byId[state.current] : undefined+ const value = summary?.projectionValues?.turnrewind+ const notices = Array.isArray(value?.notices) ? value.notices : []+ const fresh = notices.filter(notice => notice && typeof notice.id === 'string' && !readSeen().includes(notice.id))+ if (fresh.length === 0)+ return+ console.warn(`[turnrewind] unsupported heads-up visible: ${fresh.map(notice => notice.id).join(', ')}`)+ for (const notice of fresh) markSeen(notice.id)+ showDialog(t, fresh)}- Object.assign(exports, { apply, inject })- return module.exports- } })- }- catch (error) {- // A duplicate registration means the bundle executed twice (HMR without- // invalidate); the first registration is still alive, so just surface it.- console.error('[turnrewind] dialog module registration failed:', error)- }-}+ ctx.effect(() => {+ const unsubscribe = sessions.list.subscribe(checkOnce)+ // Projection frames can land while the page is loading, before the list+ // store has any subscribers; poll briefly so that ordering can never+ // silently swallow the heads-up.+ const poll = setInterval(checkOnce, 2000)+ const stopPolling = setTimeout(clearInterval, 120000, poll)+ return () => {+ unsubscribe()+ clearInterval(poll)+ clearTimeout(stopPolling)+ }+ }, 'turnrewind dialog runner')+ }++ Object.assign(exports, { apply, inject })+ return module.exports+ },+})