Skip to content

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

fix(turnrewind): declare the remote service instead of reading it un-injected

yingtianlan08055a24d263
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/index.ts b/packages/dsh-tauri-turnrewind-ts/src/client/index.ts
index 0b8ff23d..08791962 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/index.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/index.ts
@@ -31,8 +31,15 @@ export { parseUndoOutput, resolveOwnerSessionId, resolvePlanStatus }
/** 插件显示名(诊断元数据)。 */
export const name = 'dsh-tauri-turnrewind'
-/** 需要的客户端服务:slots(卡片点位)、sessions(状态轮询/弹窗)、locale(双语)。 */
-export const inject = ['slots', 'sessions', 'locale']
+/**
+ * 需要的客户端服务:slots(卡片点位)、sessions(状态轮询/弹窗)、locale(双语)、
+ * remote(在 turn 尾部按钮里执行 `/undo` 命令)。
+ *
+ * `remote` 必须在这里声明:cordis 的 context 代理对未 inject 的服务属性**直接抛**
+ * (`cannot get property "remote" without inject`),而 apply 里会读它——漏声明会
+ * 让整个客户端插件 apply 失败(界面报 "Failed to load plugins")。
+ */
+export const inject = ['slots', 'sessions', 'locale', 'remote']
/**
* 插件体:安装 locale 与卡片/弹窗注册。
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/utils/turn-action.ts b/packages/dsh-tauri-turnrewind-ts/src/client/utils/turn-action.ts
index c4b0a3b9..8cbd2a53 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/utils/turn-action.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/utils/turn-action.ts
@@ -35,8 +35,16 @@ export type CommandRunner = (line: string, sessionId: string | null) => Promise<
* 宿主未暴露该能力时返回 null,调用方据此不注册槽位(老版本宿主优雅降级)。
*/
export function resolveCommandRunner(ctx: unknown, translate: Translate): CommandRunner | null {
- const remote = (ctx as { remote?: { commands?: { execute?: unknown } } } | undefined)?.remote
- const commands = remote?.commands
+ let commands: { execute?: unknown } | undefined
+ try {
+ commands = (ctx as { remote?: { commands?: { execute?: unknown } } } | undefined)?.remote?.commands
+ }
+ catch {
+ // 未在 inject 里声明 `remote`、或该服务尚未就绪时,cordis 的 context 代理对属性
+ // 访问会直接抛。这里吞掉并降级为「不注册槽位」——按钮不出现,好过整个客户端插件
+ // apply 失败(界面会报 Failed to load plugins)。
+ return null
+ }
const execute = commands?.execute
if (typeof execute !== 'function' || commands === undefined)
return null
diff --git a/packages/dsh-tauri-turnrewind-ts/test/client-view.test.js b/packages/dsh-tauri-turnrewind-ts/test/client-view.test.js
index e0468181..e6756c88 100644
--- a/packages/dsh-tauri-turnrewind-ts/test/client-view.test.js
+++ b/packages/dsh-tauri-turnrewind-ts/test/client-view.test.js
@@ -5,7 +5,9 @@ import * as client from '../src/client/index'
it('exposes the cordis plugin face and pure helpers', () => {
assert.equal(typeof client.apply, 'function')
- assert.deepEqual(client.inject, ['slots', 'sessions', 'locale'])
+ // `remote` 必须在列:turn 尾部按钮读 ctx.remote 执行 /undo,未声明 inject 时
+ // cordis 代理会抛,整个插件 apply 失败(线上复现过 Failed to load plugins)。
+ assert.deepEqual(client.inject, ['slots', 'sessions', 'locale', 'remote'])
assert.equal(typeof client.parseUndoOutput, 'function')
assert.equal(typeof client.resolvePlanStatus, 'function')
assert.equal(typeof client.resolveOwnerSessionId, 'function')
diff --git a/packages/dsh-tauri-turnrewind-ts/test/turn-action.test.js b/packages/dsh-tauri-turnrewind-ts/test/turn-action.test.js
index 68ffac02..887ef132 100644
--- a/packages/dsh-tauri-turnrewind-ts/test/turn-action.test.js
+++ b/packages/dsh-tauri-turnrewind-ts/test/turn-action.test.js
@@ -32,6 +32,17 @@ it('resolves the command runner only when the host exposes remote.commands.execu
assert.equal(typeof resolveCommandRunner({ remote: { commands: { execute: async () => {} } } }, translate), 'function')
})
+it('degrades to null when the cordis proxy rejects the property access', () => {
+ // 未在 inject 里声明 remote 时,cordis 的 context 代理读该属性会直接抛。
+ // 这个抛绝不能冒泡到 apply(线上表现为整个客户端插件 "Failed to load plugins")。
+ const throwing = new Proxy({}, {
+ get(_target, key) {
+ throw new Error(`cannot get property "${String(key)}" without inject`)
+ },
+ })
+ assert.equal(resolveCommandRunner(throwing, translate), null)
+})
+
it('runs the command against the given session and surfaces host failures', async () => {
const calls = []
const ctx = {