From 8460a896b6e38a36a705a7066891fd6ed8b2f46f Mon Sep 17 00:00:00 2001 From: QQ Date: Tue, 17 Nov 2026 09:20:10 +0800 Subject: [PATCH] Import patches/0002-fork-fast-mode-lite-projection-force-relay-and-clien.patch --- ...ite-projection-force-relay-and-clien.patch | 326 ++++++++++++------ 1 file changed, 229 insertions(+), 97 deletions(-) diff --git a/patches/0002-fork-fast-mode-lite-projection-force-relay-and-clien.patch b/patches/0002-fork-fast-mode-lite-projection-force-relay-and-clien.patch index 212a036..332ee71 100644 --- a/patches/0002-fork-fast-mode-lite-projection-force-relay-and-clien.patch +++ b/patches/0002-fork-fast-mode-lite-projection-force-relay-and-clien.patch @@ -1,4 +1,4 @@ -From 85e704ac874f5f9d664f8e932f16ac9903b3c07d Mon Sep 17 00:00:00 2001 +From 53a3789330f8ab99cf0295b5b5aafa7d6f44be21 Mon Sep 17 00:00:00 2001 From: rainow Date: Fri, 13 Nov 2026 11:45:58 +0800 Subject: [PATCH 2/3] fork: fast mode (lite projection + force relay) and @@ -6,11 +6,14 @@ Subject: [PATCH 2/3] fork: fast mode (lite projection + force relay) and --- packages/plugin/src/client-connection.ts | 13 +- - packages/plugin/src/client-locale.ts | 8 + + packages/plugin/src/client-locale.ts | 16 ++ packages/plugin/src/client-runtime.ts | 3 +- packages/plugin/src/client.ts | 8 +- + .../plugin/src/client/fast-mode-switches.ts | 92 +++++++++ + packages/plugin/src/client/shell.ts | 3 + packages/plugin/src/client/types.ts | 1 + - packages/plugin/src/client/workspaces.ts | 70 ++++++- + packages/plugin/src/client/workspaces.ts | 5 +- + packages/plugin/src/compact-history.ts | 21 ++- packages/plugin/src/config.ts | 10 + packages/plugin/src/control-runtime.ts | 94 ++++++++-- packages/plugin/src/harness-remote-bridge.ts | 46 ++++- @@ -22,18 +25,20 @@ Subject: [PATCH 2/3] fork: fast mode (lite projection + force relay) and packages/plugin/src/service.ts | 4 + packages/plugin/tests/client-runtime.test.ts | 1 + packages/plugin/tests/control-runtime.test.ts | 29 +++ + .../tests/host-websocket-origin.test.ts | 1 + packages/plugin/tests/lite-mode.test.ts | 91 +++++++++ .../plugin/tests/multi-client-runtime.test.ts | 1 + .../plugin/tests/relay-preference.test.ts | 40 ++++ .../plugin/tests/server-connection.test.ts | 1 + - 21 files changed, 666 insertions(+), 37 deletions(-) + 25 files changed, 722 insertions(+), 41 deletions(-) + create mode 100644 packages/plugin/src/client/fast-mode-switches.ts create mode 100644 packages/plugin/src/lite-mode.ts create mode 100644 packages/plugin/src/relay-preference.ts create mode 100644 packages/plugin/tests/lite-mode.test.ts create mode 100644 packages/plugin/tests/relay-preference.test.ts diff --git a/packages/plugin/src/client-connection.ts b/packages/plugin/src/client-connection.ts -index c592d3a..1f77831 100644 +index c592d3ac..1f778314 100644 --- a/packages/plugin/src/client-connection.ts +++ b/packages/plugin/src/client-connection.ts @@ -21,6 +21,7 @@ import { @@ -87,10 +92,10 @@ index c592d3a..1f77831 100644 for (const attempt of attempts) { webRtcFallback = false diff --git a/packages/plugin/src/client-locale.ts b/packages/plugin/src/client-locale.ts -index dcdd557..b3b075a 100644 +index 4c65bb8e..a08080df 100644 --- a/packages/plugin/src/client-locale.ts +++ b/packages/plugin/src/client-locale.ts -@@ -303,6 +303,10 @@ export const en = { +@@ -330,6 +330,10 @@ export const en = { startSignIn: 'Start sign-in', allowControlCurrentDevice: 'Allow control of this device', allowControlDevice: 'Allow control of this device', @@ -101,7 +106,7 @@ index dcdd557..b3b075a 100644 connectedClientCount: '{count} connected', checkAcp: 'Check backend', checkingAcp: 'Checking ACP…', -@@ -660,6 +664,10 @@ export const zh: Record = { +@@ -714,6 +718,10 @@ export const zh: Record = { startSignIn: '开始登录', allowControlCurrentDevice: '允许控制本机', allowControlDevice: '允许控制本机', @@ -112,11 +117,33 @@ index dcdd557..b3b075a 100644 connectedClientCount: '{count} 台已连接', checkAcp: '检测后端', checkingAcp: '正在检测 ACP…', +@@ -770,6 +778,10 @@ export const zh: Record = { + } + + export const ru: Record = { ++ liteMode: 'Быстрый режим', ++ forceRelay: 'Только через ретранслятор', ++ forceRelayHint: 'Пропускать проверку LAN, прямого соединения и TURN и подключаться сразу через шифрованный ретранслятор. Первое подключение и переподключение быстрее, но весь трафик идёт через сервер.', ++ liteModeHint: 'Отправлять удалённым клиентам только необходимое: в первой странице истории остаются последние 10 сообщений, подробности инструментов сжимаются, крупные проекции плагинов (например, панель контекста) отбрасываются — удалённо этих данных не будет. Включено по умолчанию; отключите для полной истории. Применяется сразу.', + serverSavedLive: 'Адрес сервера сохранён и применён.', + saveServerBeforeLogin: 'Сохраните адрес сервера, прежде чем продолжить вход или сопряжение.', + pairingLoginTab: 'DSH Go', +@@ -1154,6 +1166,10 @@ export const ru: Record = { + } + + export const uk: Record = { ++ liteMode: 'Швидкий режим', ++ forceRelay: 'Лише через ретранслятор', ++ forceRelayHint: 'Пропускати перевірку LAN, прямого зʼєднання й TURN і підключатися одразу через зашифрований ретранслятор. Перше підключення та перепідключення швидші, але весь трафік іде через сервер.', ++ liteModeHint: 'Надсилати віддаленим клієнтам лише необхідне: у першій сторінці історії лишаються останні 10 повідомлень, подробиці інструментів стискаються, великі проєкції плагінів (наприклад, панель контексту) відкидаються — віддалено цих даних не буде. Увімкнено за замовчуванням; вимкніть для повної історії. Застосовується одразу.', + serverSavedLive: 'Адресу сервера збережено й застосовано.', + saveServerBeforeLogin: 'Збережіть адресу сервера, перш ніж продовжити вхід або спарювання.', + pairingLoginTab: 'DSH Go', diff --git a/packages/plugin/src/client-runtime.ts b/packages/plugin/src/client-runtime.ts -index a78ec6c..df07ea9 100644 +index 833deb01..2b401a96 100644 --- a/packages/plugin/src/client-runtime.ts +++ b/packages/plugin/src/client-runtime.ts -@@ -8,6 +8,7 @@ import type { HarnessMode } from './harness-target.js' +@@ -9,6 +9,7 @@ import type { HarnessMode } from './harness-target.js' import { probeRemoteHostFeatures, remoteHostFeatures } from './client-capabilities.js' import { ClientCodexStreams } from './client-codex-streams.js' import { ClientConnection } from './client-connection.js' @@ -124,7 +151,7 @@ index a78ec6c..df07ea9 100644 import { ClientReconnect } from './client-reconnect.js' import { ClientControl } from './client-control.js' import type { -@@ -270,7 +271,7 @@ export class ClientModeRuntime { +@@ -271,7 +272,7 @@ export class ClientModeRuntime { ...(this.clientAuthRequired && !this.connected && targetStatus.mode === 'remote' ? { clientAuthRequired: true } : {}), transport: this.connected?.client.getStats().mode ?? 'Disconnected', connectedTargetDeviceId: this.connected?.target.deviceId, @@ -134,10 +161,10 @@ index a78ec6c..df07ea9 100644 connectionProgress: { targetDeviceId: this.connectionProgress.targetDeviceId, diff --git a/packages/plugin/src/client.ts b/packages/plugin/src/client.ts -index 8bf1885..785c4a2 100644 +index 05a27cd6..17447db0 100644 --- a/packages/plugin/src/client.ts +++ b/packages/plugin/src/client.ts -@@ -50,7 +50,7 @@ declare const DSH_REMOTE_CLIENT_MODULE_ID: string | undefined +@@ -51,7 +51,7 @@ declare const DSH_REMOTE_CLIENT_MODULE_ID: string | undefined const clientModuleId = typeof DSH_REMOTE_CLIENT_MODULE_ID === 'string' ? DSH_REMOTE_CLIENT_MODULE_ID @@ -146,7 +173,7 @@ index 8bf1885..785c4a2 100644 const controlRouteBackoffStepsMs = [1_000, 2_000, 5_000, 10_000, 30_000] as const class ControlRouteUnavailableError extends Error { -@@ -104,7 +104,7 @@ window.__ModuleLoader__.load({ +@@ -113,7 +113,7 @@ window.__ModuleLoader__.load({ // section, so this jumps straight to the Remote card instead of requiring a // scroll through the whole document. function RemotePluginSettingsAction(props: { t: Translate; subject?: unknown }): unknown { @@ -155,7 +182,7 @@ index 8bf1885..785c4a2 100644 const label = props.t('openPluginSettings') return React.createElement('button', { type: 'button', -@@ -634,7 +634,7 @@ window.__ModuleLoader__.load({ +@@ -659,7 +659,7 @@ window.__ModuleLoader__.load({ // (`cordis.patch.yml` row `ds-harness-remote`). ctx.slots.inject('plugins.row.config', () => ctx.slots.register({ name: 'plugins.row.config', @@ -164,7 +191,7 @@ index 8bf1885..785c4a2 100644 locale: localeNamespace, inject: () => ({ control, -@@ -648,7 +648,7 @@ window.__ModuleLoader__.load({ +@@ -673,7 +673,7 @@ window.__ModuleLoader__.load({ // package name. ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({ name: 'plugins.bundle.config', @@ -173,35 +200,34 @@ index 8bf1885..785c4a2 100644 locale: localeNamespace, inject: () => ({ control, -diff --git a/packages/plugin/src/client/types.ts b/packages/plugin/src/client/types.ts -index 178296c..9871389 100644 ---- a/packages/plugin/src/client/types.ts -+++ b/packages/plugin/src/client/types.ts -@@ -205,6 +205,7 @@ interface PluginSettings { - remoteTools?: { enabled?: boolean } - forceRelay?: boolean - logLevel?: 'debug' | 'info' | 'warn' | 'error' -+ liteMode?: boolean - reconnect?: boolean | { - enabled?: boolean - initialDelayMs?: number -diff --git a/packages/plugin/src/client/workspaces.ts b/packages/plugin/src/client/workspaces.ts -index 0cc6ba0..4b838b9 100644 ---- a/packages/plugin/src/client/workspaces.ts -+++ b/packages/plugin/src/client/workspaces.ts -@@ -30,9 +30,75 @@ import type { - SidebarEntryStyle, - } from './types.js' - -+type ToggleConfigKey = 'liteMode' | 'forceRelay' +diff --git a/packages/plugin/src/client/fast-mode-switches.ts b/packages/plugin/src/client/fast-mode-switches.ts +new file mode 100644 +index 00000000..ab0b6b34 +--- /dev/null ++++ b/packages/plugin/src/client/fast-mode-switches.ts +@@ -0,0 +1,92 @@ ++import type { Translate } from '../client-locale.js' ++import type { ClientReact, PluginSettingsView } from './types.js' ++ ++/** ++ * The fork's two fast-mode switches, kept out of `workspaces.ts` on purpose. ++ * ++ * Upstream rewrites the host section heading in that file every few weeks, and ++ * every one of those edits used to collide with this component. Here the whole ++ * widget is one import plus one element, and it renders on its own row instead ++ * of inside `.dshRemoteSectionTitle`, so the heading can keep changing. ++ */ ++export type ToggleConfigKey = 'liteMode' | 'forceRelay' + +const TOGGLES: Record = { + liteMode: { label: 'liteMode', hint: 'liteModeHint', endpoint: 'settings.lite.set' }, + forceRelay: { label: 'forceRelay', hint: 'forceRelayHint', endpoint: 'settings.forceRelay.set' }, +} + -+function createRemoteToggleSwitch(React: ClientReact) { -+ return function RemoteToggleSwitch(props: { ++const TOGGLE_ORDER: ToggleConfigKey[] = ['liteMode', 'forceRelay'] ++ ++export function createFastModeSwitches(React: ClientReact) { ++ function RemoteToggleSwitch(props: { + control: (endpoint: string, payload?: unknown) => Promise + t: Translate + configKey: ToggleConfigKey @@ -231,7 +257,7 @@ index 0cc6ba0..4b838b9 100644 + const hint = props.t(meta.hint) + return React.createElement('div', { + className: 'dshRemoteHostControlToggle', -+ style: { marginLeft: '14px', position: 'relative' }, ++ style: { position: 'relative' }, + }, + React.createElement('span', { title: hint, style: { cursor: 'help' } }, label), + React.createElement('button', { @@ -256,35 +282,129 @@ index 0cc6ba0..4b838b9 100644 + : null, + ) + } -+} + ++ return function FastModeSwitches(props: { ++ control: (endpoint: string, payload?: unknown) => Promise ++ t: Translate ++ className?: string ++ }) { ++ return React.createElement('div', { ++ className: props.className ?? 'dshRemoteFastModeSwitches', ++ }, TOGGLE_ORDER.map(key => React.createElement(RemoteToggleSwitch, { ++ key, ++ control: props.control, ++ t: props.t, ++ configKey: key, ++ }))) ++ } ++} +diff --git a/packages/plugin/src/client/shell.ts b/packages/plugin/src/client/shell.ts +index 4436301c..e855c955 100644 +--- a/packages/plugin/src/client/shell.ts ++++ b/packages/plugin/src/client/shell.ts +@@ -67,6 +67,9 @@ export function installStyle(clientModuleId: string): () => void { + '.dshRemoteSidebarEntry.isWide.hasUpdate .dshRemoteModeButton{border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary-new-colorprimary-new-color,var(--dsw-alias-brand-primary)) 20%,transparent);background:color-mix(in srgb,var(--dsw-alias-brand-primary-new-colorprimary-new-color,var(--dsw-alias-brand-primary)) 8%,transparent);color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,var(--dsw-alias-brand-primary));font-weight:500}.dshRemoteSidebarEntry .dshRemoteModeButton,.dshRemoteAccountEntry .dshRemoteAccountEntryButton{position:relative}.dshRemoteUpdateSuffix{flex:0 0 auto;margin-left:auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;line-height:18px;font-weight:500}.dshRemoteUpdateDot{position:absolute;inset-inline-end:2px;top:2px;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,var(--dsw-alias-brand-primary))}', + '.dshRemoteSectionHeading{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:10px}.dshRemoteSectionTitle{min-width:0;display:flex;align-items:center;gap:10px}.dshRemoteSectionTitle>strong{font-size:14px}.dshRemoteManageHosts{color:var(--dsw-alias-label-secondary);font-size:12px;text-decoration:none;white-space:nowrap}.dshRemoteManageHosts:hover{color:var(--dsw-alias-label-primary);text-decoration:underline}.dshRemoteSectionActions{display:flex;align-items:center;gap:14px}.dshRemoteSectionActions>button{border:0;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;padding:5px 0;font-size:12px}.dshRemoteSectionActions>button:hover:not(:disabled){color:var(--dsw-alias-label-primary);text-decoration:underline}', + '.dshRemoteSectionTitle{flex:1}.dshRemoteSectionTitle>.dshRemoteConnectedMenu{margin-left:auto}', ++ // The fork's fast-mode row: its own line under the host section heading so ++ // upstream edits to `.dshRemoteSectionTitle` never move it. ++ '.dshRemoteFastModeSwitches{display:flex;flex-wrap:wrap;align-items:center;gap:16px;margin:0 0 12px}', + '.dshRemoteAcpSetting{display:block!important;width:100%;padding:0}.dshRemoteAcpSetting>summary{display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;cursor:pointer;list-style:none}.dshRemoteAcpSetting>summary::-webkit-details-marker{display:none}.dshRemoteAcpSetting>summary::after{content:"⌄";color:var(--dsw-alias-label-secondary);transition:transform .18s ease-out}.dshRemoteAcpSetting[open]>summary::after{transform:rotate(180deg)}.dshRemoteAcpSummaryText{min-width:0}.dshRemoteAcpSummaryText strong{display:block}.dshRemoteAcpSummaryText p{margin:4px 0 0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.4}.dshRemoteAcpCheckLink{grid-column:2;grid-row:1;color:var(--dsw-alias-brand-primary);font-size:12px;text-decoration:underline;text-underline-offset:3px}.dshRemoteAcpCheckLink:hover{color:var(--dsw-alias-label-primary)}.dshRemoteAcpCheckResult{grid-column:3;grid-row:1;font-size:11px;line-height:1.4;white-space:nowrap}.dshRemoteAcpCheckResult.isPassed{color:var(--dsw-alias-state-success-primary)}.dshRemoteAcpCheckResult.isFailed{color:var(--dsw-alias-state-danger-primary)}.dshRemoteAcpList{display:flex;flex-direction:column;gap:0;margin-top:12px;padding-top:0;border-top:0}.dshRemoteAcpList>.dshRemoteAuthorizationSetting{display:grid;width:100%;grid-template-columns:minmax(0,1fr) auto auto auto auto;align-items:center;column-gap:18px;line-height:1.4}.dshRemoteAcpList>.dshRemoteAuthorizationSetting>span:first-child{min-width:0;line-height:1.4}.dshRemoteAcpList>.dshRemoteAuthorizationSetting>input{grid-column:4;grid-row:1}', + '.dshRemoteAcpAddLink{align-self:flex-start;margin-top:12px;color:var(--dsw-alias-brand-primary);font-size:12px;text-decoration:underline;text-underline-offset:3px}.dshRemoteAcpAddForm{display:grid;grid-template-columns:minmax(100px,.8fr) minmax(140px,1fr) minmax(100px,1fr) auto;gap:8px;margin-top:12px}.dshRemoteAcpAddForm input{min-width:0;height:34px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:inherit;padding:0 10px}.dshRemoteAcpAddForm button{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary);padding:0 12px;cursor:pointer;font:inherit;font-size:12px}.dshRemoteAcpAddForm button:hover{background:var(--dsw-alias-interactive-bg-hover)}.dshRemoteAcpRemoveLink{grid-column:3;grid-row:1;color:var(--dsw-alias-label-secondary);font-size:12px;text-decoration:underline;text-underline-offset:3px}.dshRemoteAcpRemoveLink:hover{color:var(--dsw-alias-state-danger-primary)}', + '.dshRemoteAcpCheckResult.isPassed,.dshRemoteAcpCheckResult.isFailed{color:var(--dsw-alias-label-secondary)}', +diff --git a/packages/plugin/src/client/types.ts b/packages/plugin/src/client/types.ts +index 11b3ffee..432ed406 100644 +--- a/packages/plugin/src/client/types.ts ++++ b/packages/plugin/src/client/types.ts +@@ -207,6 +207,7 @@ interface PluginSettings { + remoteTools?: { enabled?: boolean } + forceRelay?: boolean + logLevel?: 'debug' | 'info' | 'warn' | 'error' ++ liteMode?: boolean + reconnect?: boolean | { + enabled?: boolean + initialDelayMs?: number +diff --git a/packages/plugin/src/client/workspaces.ts b/packages/plugin/src/client/workspaces.ts +index ec17b423..6506cb2b 100644 +--- a/packages/plugin/src/client/workspaces.ts ++++ b/packages/plugin/src/client/workspaces.ts +@@ -1,6 +1,7 @@ + import { mountAccountEntry } from './account-entry.js' + import { createHostPairingPanel } from './pairing.js' + import { createServerNotice } from './server-notice.js' ++import { createFastModeSwitches } from './fast-mode-switches.js' + import { renderBodyPortal } from './portal.js' + import QRCode from 'qrcode' + import type { Translate } from '../client-locale.js' +@@ -34,6 +35,7 @@ import type { export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalRenderer) { const ServerNotice = createServerNotice(React) const HostPairingPanel = createHostPairingPanel(React) -+ const RemoteToggleSwitch = createRemoteToggleSwitch(React) ++ const FastModeSwitches = createFastModeSwitches(React) const RemoteProgressView = createRemoteProgressView(React) /** -@@ -1412,6 +1478,8 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR - checked: status.host?.authorized === true, +@@ -1080,7 +1082,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR + const updateNotice = updateInfo !== undefined && localUpdateAvailable + ? t('updateAvailable', { latest: updateInfo.latestVersion, current: updateInfo.currentVersion }) + : undefined +- const releasesUrl = 'https://github.com/liguobao/ds-harness-remote/releases' ++ const releasesUrl = 'https://github.com/rainow/ds-harness-remote-fast/releases' + const canUpgradeInPlace = updateInfo?.upgrade === 'ready' + const startLocalUpgrade = async (): Promise => { + if (!canUpgradeInPlace || updateInfo === undefined) return +@@ -1457,6 +1459,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR onChange: (event: Event) => void setCurrentDeviceControl((event.target as HTMLInputElement).checked), })) : null, -+ React.createElement(RemoteToggleSwitch, { control: props.control, t, configKey: 'liteMode' }), -+ React.createElement(RemoteToggleSwitch, { control: props.control, t, configKey: 'forceRelay' }), connectedMenu)), ++ React.createElement(FastModeSwitches, { control: props.control, t }), React.createElement('div', { className: `dshRemoteHostList${connectingHost === undefined ? '' : ' isCollapsed'}`, -@@ -1447,7 +1515,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR - })), - updateNotice === undefined ? null : React.createElement('a', { - className: 'dshRemoteAccountUpdate', -- href: 'https://github.com/liguobao/ds-harness-remote/releases', -+ href: 'https://github.com/rainow/ds-harness-remote-fast/releases', - target: '_blank', - rel: 'noreferrer', - title: updateNotice, + 'aria-busy': connectingHost === undefined ? undefined : true, +diff --git a/packages/plugin/src/compact-history.ts b/packages/plugin/src/compact-history.ts +index 8bc8fc26..56592cfc 100644 +--- a/packages/plugin/src/compact-history.ts ++++ b/packages/plugin/src/compact-history.ts +@@ -9,6 +9,9 @@ const MARKER = '\n[Compact history: output omitted]' + * follow stream has no transfer fallback, so growth has to stay far below it. + */ + const ROUND_BUDGET = 128 * 1024 ++/** Tools whose result the client renders as an in-chat card: the component tree lives in ++ * `arguments`, and `meta` decides whether the card is rendered at all. */ ++const UI_TOOL_NAMES = new Set(['ui_render', 'ui_patch', 'ui_render_widget', 'ui_compose']) + const object = (value: unknown): value is Record => value !== null && typeof value === 'object' && !Array.isArray(value) + + type Budget = { remaining: number } +@@ -28,13 +31,23 @@ function summary(value: unknown, budget: Budget): string { + return preservedRound(text, budget) ?? text.slice(0, LIMIT) + MARKER + } + +-function toolValue(value: unknown, budget: Budget): unknown { +- if (Array.isArray(value)) return value.map(item => toolValue(item, budget)) ++function toolValue(value: unknown, budget: Budget, keepUiPayload = false): unknown { ++ if (Array.isArray(value)) return value.map(item => toolValue(item, budget, keepUiPayload)) + if (!object(value)) return value + const result: Record = { ...value } ++ const toolName = typeof value.name === 'string' ? value.name ++ : typeof value.toolName === 'string' ? value.toolName : undefined ++ const keepUi = keepUiPayload || (toolName !== undefined && UI_TOOL_NAMES.has(toolName)) + for (const [key, child] of Object.entries(value)) { +- if (['input', 'arguments', 'output', 'result', 'rawInput', 'rawOutput', 'uiResultMeta', 'meta', 'argumentsDelta'].includes(key)) { +- result[key] = typeof child === 'string' ? summary(child, budget) : { summary: summary(child, budget) } ++ if (key === 'meta' || key === 'uiResultMeta') { ++ // The client renders an in-chat card only when `meta.ok` / `meta.ui` survive intact; ++ // wrapping this object in `{ summary }` silently drops the whole card. ++ result[key] = child ++ } else if (['input', 'arguments', 'output', 'result', 'rawInput', 'rawOutput', 'argumentsDelta'].includes(key)) { ++ // A UI tool's component tree is its arguments: truncating or wrapping them makes the ++ // client's JSON.parse fail, so keep them byte-exact for those tools only. ++ if (keepUi && (key === 'arguments' || key === 'argumentsDelta' || key === 'input')) result[key] = child ++ else result[key] = typeof child === 'string' ? summary(child, budget) : { summary: summary(child, budget) } + } else if (key === 'content' && Array.isArray(child)) { + let previews = 0 + const blocks = child.flatMap(block => { diff --git a/packages/plugin/src/config.ts b/packages/plugin/src/config.ts -index 56e459f..20c1d2f 100644 +index 56e459f1..20c1d2f1 100644 --- a/packages/plugin/src/config.ts +++ b/packages/plugin/src/config.ts @@ -27,6 +27,12 @@ export interface Config { @@ -333,7 +453,7 @@ index 56e459f..20c1d2f 100644 enabled: parsed.reconnect !== false, initialDelayMs, diff --git a/packages/plugin/src/control-runtime.ts b/packages/plugin/src/control-runtime.ts -index ffea905..04a4111 100644 +index 09f19ac6..ff84703f 100644 --- a/packages/plugin/src/control-runtime.ts +++ b/packages/plugin/src/control-runtime.ts @@ -1,7 +1,10 @@ @@ -348,16 +468,16 @@ index ffea905..04a4111 100644 import { resolveConfig, type Config, type ConfigInput, type ResolvedConfig } from './config.js' import { ClientModeError, -@@ -26,6 +29,8 @@ import { codexBinaryCandidates } from './codex/domain.js' - import { cursorBinaryCandidates } from './acp/gateway.js' +@@ -28,6 +31,8 @@ import { cursorBinaryCandidates } from './acp/gateway.js' import { defaultCheckExecutable, installOrConfigureBackend, isBuiltinAcpBackend } from './acp/backend-installer.js' + import type { HostLogSnapshot, HostLogStore, PluginLogFilter } from './host-log-store.js' +const execFileAsync = promisify(execFile) + export interface PluginSettingsView { config: Config deviceName: string -@@ -148,6 +153,8 @@ export class PluginControlRuntime { +@@ -161,6 +166,8 @@ export class PluginControlRuntime { } if (endpoint === 'settings.development.set') return ok(await this.setDevelopment(payload)) if (endpoint === 'settings.appearance.set') return ok(await this.setAppearance(payload)) @@ -366,7 +486,7 @@ index ffea905..04a4111 100644 if (endpoint === 'settings.get') return ok(await this.settingsView()) if (endpoint === 'settings.configure') return ok(await this.configure(payload)) if (endpoint === 'settings.server.set') return ok(await this.setServer(payload)) -@@ -398,6 +405,40 @@ export class PluginControlRuntime { +@@ -414,6 +421,40 @@ export class PluginControlRuntime { return { ...await this.settingsView(), applies: 'live' } } @@ -407,7 +527,7 @@ index ffea905..04a4111 100644 private async setRole(payload: unknown): Promise { if (this.settings === undefined) { throw new ClientModeError('SETTINGS_UNAVAILABLE', 'DSH user settings are unavailable in this profile.') -@@ -656,7 +697,7 @@ export class PluginControlRuntime { +@@ -711,7 +752,7 @@ export class PluginControlRuntime { writable: this.settings !== undefined, applies: 'restart', associations, @@ -416,7 +536,7 @@ index ffea905..04a4111 100644 ...(association === undefined ? {} : { association }), ...(this.startupFailure === undefined ? {} : { startupError: safeStartupError(this.startupFailure), -@@ -664,6 +705,12 @@ export class PluginControlRuntime { +@@ -719,6 +760,12 @@ export class PluginControlRuntime { } } @@ -429,7 +549,7 @@ index ffea905..04a4111 100644 private async associations(config: Config): Promise { if (config.serverUrl === undefined || !this.storageAvailable) return {} const [host, client] = await Promise.all([ -@@ -710,28 +757,52 @@ export class PluginControlRuntime { +@@ -784,28 +831,52 @@ export class PluginControlRuntime { } } @@ -491,7 +611,7 @@ index ffea905..04a4111 100644 return { enabled: config.enabled, role: config.role, -@@ -744,6 +815,7 @@ function editableConfig(config: ResolvedConfig): Config { +@@ -818,6 +889,7 @@ function editableConfig(config: ResolvedConfig): Config { loopback: config.loopback, forceRelay: config.forceRelay, logLevel: config.logLevel, @@ -500,7 +620,7 @@ index ffea905..04a4111 100644 ? { initialDelayMs: config.reconnect.initialDelayMs, diff --git a/packages/plugin/src/harness-remote-bridge.ts b/packages/plugin/src/harness-remote-bridge.ts -index 66747db..d24d03f 100644 +index 489f68d5..238ff7c8 100644 --- a/packages/plugin/src/harness-remote-bridge.ts +++ b/packages/plugin/src/harness-remote-bridge.ts @@ -1,4 +1,5 @@ @@ -509,7 +629,7 @@ index 66747db..d24d03f 100644 import { randomUUID } from 'node:crypto' import { homedir } from 'node:os' import { lstat, realpath, stat } from 'node:fs/promises' -@@ -314,7 +315,7 @@ export class HarnessRemoteBridge { +@@ -320,7 +321,7 @@ export class HarnessRemoteBridge { if (TERMINAL_STREAMS.has(params.endpoint)) throw new RpcError('METHOD_NOT_ALLOWED', 'Use a stream for this terminal endpoint.') if (['settings/update', 'settings/replace', 'settings/mutate'].includes(params.endpoint)) { const args = requestArgs(params.payload) @@ -518,7 +638,7 @@ index 66747db..d24d03f 100644 throw new RpcError('PERMISSION_DENIED', 'Remote access settings can only be changed locally on the Host.') } } -@@ -712,12 +713,41 @@ export class HarnessRemoteBridge { +@@ -718,12 +719,41 @@ export class HarnessRemoteBridge { try { for await (const value of source) { if (signal.aborted) break @@ -563,7 +683,7 @@ index 66747db..d24d03f 100644 if (!transferFrames) throw new Error('Oversized Harness Remote frame') await this.transferStreamFrame(frame, signal) } else { -@@ -1307,6 +1337,10 @@ function needsDirectoryFallback(result: TypertRpcResult): boolean { +@@ -1323,6 +1353,10 @@ function needsDirectoryFallback(result: TypertRpcResult): boolean { || message.includes('directory-picker-unavailable') } @@ -574,7 +694,7 @@ index 66747db..d24d03f 100644 const SESSION_PROJECTION_WHITELIST = new Set([ 'permissions', 'remoteStatusKnown', -@@ -1457,7 +1491,7 @@ export function filterSessionListProjections( +@@ -1473,7 +1507,7 @@ export function filterSessionListProjections( function filterRemotePluginInventory(endpoint: string, result: TypertRpcResult): TypertRpcResult { if (!result.ok) return result const isRemote = (value: unknown): boolean => typeof value === 'string' @@ -583,7 +703,7 @@ index 66747db..d24d03f 100644 const filterEntries = (entries: unknown[]): unknown[] => entries.filter(entry => !isRecord(entry) || !isRemote(entry.moduleName)) if (endpoint === 'pluginManager/listPlugins' && Array.isArray(result.value)) { -@@ -1496,7 +1530,7 @@ function isCompactSnapshot(value: unknown): boolean { +@@ -1512,7 +1546,7 @@ function isCompactSnapshot(value: unknown): boolean { /** Whether one official plugin-manager row belongs to this Remote plugin or its bundle. */ function remoteOwnedBundleRow(row: Record, plugin: boolean): boolean { const remoteModule = (value: unknown): boolean => typeof value === 'string' @@ -593,10 +713,10 @@ index 66747db..d24d03f 100644 return !plugin && (!Array.isArray(row.rows) || row.rows.some(value => !isRecord(value) || remoteModule(value.moduleName)) diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts -index 759122b..0629349 100644 +index 679e254b..fb4e52ab 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts -@@ -32,6 +32,8 @@ import { TypertGatewaySwitch } from './typert-gateway-switch.js' +@@ -34,6 +34,8 @@ import { TypertGatewaySwitch } from './typert-gateway-switch.js' import type { FileViewerHostServiceLike } from './file-viewer-bridge.js' import { createPluginRouteDispatcher, type PluginRouteConnectionLike } from './plugin-route-dispatcher.js' import { installRemoteDiscoveryTools } from './remote-tools.js' @@ -604,8 +724,8 @@ index 759122b..0629349 100644 +import { setLiteModeEnabled } from './lite-mode.js' import { runHmrSafe, type HmrContextLike } from './hmr-safe-settings.js' import { PluginUpdateChecker } from './update-check.js' - import { assertRemoteEventSource } from './tui-event-source.js' -@@ -50,7 +52,7 @@ declare module '@deepseek-ai/cordis' { + import { LocalPluginUpgrade, type PluginManagerUpdate } from './plugin-self-update.js' +@@ -53,7 +55,7 @@ declare module '@deepseek-ai/cordis' { } } @@ -614,8 +734,8 @@ index 759122b..0629349 100644 export { Config } // The unscoped dsh-remote package belongs to another publisher. A bare name -@@ -463,7 +465,17 @@ async function activate( - await runtime?.close() +@@ -504,7 +506,17 @@ async function activate( + await logStore.flush() } }, 'ds-harness-remote lifecycle') - if (config.remoteTools?.enabled) installRemoteDiscoveryTools(ctx, () => closed || !clientActive ? undefined : clientRuntime) @@ -635,7 +755,7 @@ index 759122b..0629349 100644 /** diff --git a/packages/plugin/src/lite-mode.ts b/packages/plugin/src/lite-mode.ts new file mode 100644 -index 0000000..3b05639 +index 00000000..3b05639c --- /dev/null +++ b/packages/plugin/src/lite-mode.ts @@ -0,0 +1,174 @@ @@ -815,7 +935,7 @@ index 0000000..3b05639 +} diff --git a/packages/plugin/src/relay-preference.ts b/packages/plugin/src/relay-preference.ts new file mode 100644 -index 0000000..4be7a89 +index 00000000..4be7a892 --- /dev/null +++ b/packages/plugin/src/relay-preference.ts @@ -0,0 +1,33 @@ @@ -853,7 +973,7 @@ index 0000000..4be7a89 + return forceRelay || !rtcAvailable ? ['relay'] : ['direct', 'turn', 'relay'] +} diff --git a/packages/plugin/src/remote-tools.ts b/packages/plugin/src/remote-tools.ts -index c68746c..4d5b2b2 100644 +index c68746ce..4d5b2b2b 100644 --- a/packages/plugin/src/remote-tools.ts +++ b/packages/plugin/src/remote-tools.ts @@ -151,10 +151,42 @@ export function remoteSessionTools(resolve: () => Pick void -@@ -245,9 +258,12 @@ export class HostServerConnection { +@@ -251,9 +264,12 @@ export class HostServerConnection { private async connectOnce(): Promise { const credentials = await this.api.authenticate(this.identity) if (this.stopped) return @@ -948,7 +1068,7 @@ index 00ce537..08c9a9e 100644 const recoveryTickets = [...this.tunnels.values()].flatMap(tunnel => tunnel.lease?.recoveryTicket() ?? []).slice(0, 64) const socket = this.createWebSocket(websocketUrl(this.api.baseUrl)) this.socket = socket -@@ -879,7 +895,7 @@ export class HostServerConnection { +@@ -946,7 +962,7 @@ export class HostServerConnection { this.logger.warn('duplicate webrtc offer ignored', { connectionId: shortId(tunnel.connectionId) }) return } @@ -958,19 +1078,19 @@ index 00ce537..08c9a9e 100644 this.logger.warn('webrtc offer ignored: forceRelay is enabled', { connectionId: shortId(tunnel.connectionId) }) return diff --git a/packages/plugin/src/service.ts b/packages/plugin/src/service.ts -index 2c2a5b5..353b36d 100644 +index cd92f50e..2e1016cc 100644 --- a/packages/plugin/src/service.ts +++ b/packages/plugin/src/service.ts -@@ -5,6 +5,8 @@ import { workspaceUploadRootResolver } from './workspace-upload-authority.js' +@@ -6,6 +6,8 @@ import { workspaceUploadRootResolver } from './workspace-upload-authority.js' import { LoopbackHost } from './loopback-host.js' import { TerminalPolicy } from './terminal-policy.js' - import { createEvent, type RemoteWorkspaceTypeDescription } from '@dsh-remote/protocol' + import { createEvent, REMOTE_SESSION_EVENTS_CAPABILITY, type RemoteWorkspaceTypeDescription } from '@dsh-remote/protocol' +import { setLiteModeEnabled } from './lite-mode.js' +import { setForceRelayEnabled } from './relay-preference.js' import { ConnectionController } from './connection-controller.js' import type { ResolvedConfig } from './config.js' import type { HostIdentity, IdentityStore } from './identity-store.js' -@@ -98,6 +100,8 @@ export class HostPluginRuntime { +@@ -106,6 +108,8 @@ export class HostPluginRuntime { private readonly schedule?: ScheduleCreateService, ) { this.terminalEnabled = config.terminal.enabled @@ -980,7 +1100,7 @@ index 2c2a5b5..353b36d 100644 this.codex = new CodexRemoteDomain(config.codex, logger) this.acp = new AcpRemoteGateway(config.acp ?? { enabled: false, backends: [] }, logger, undefined, undefined, () => this.terminalEnabled, this.terminalSpawner) diff --git a/packages/plugin/tests/client-runtime.test.ts b/packages/plugin/tests/client-runtime.test.ts -index cc1edaf..cf361eb 100644 +index cc1edaf6..cf361eb5 100644 --- a/packages/plugin/tests/client-runtime.test.ts +++ b/packages/plugin/tests/client-runtime.test.ts @@ -1585,6 +1585,7 @@ function config(): ResolvedConfig { @@ -992,10 +1112,10 @@ index cc1edaf..cf361eb 100644 codex: { enabled: false, binary: 'codex' }, cursor: { enabled: false, binary: 'agent' }, diff --git a/packages/plugin/tests/control-runtime.test.ts b/packages/plugin/tests/control-runtime.test.ts -index f0499a4..858b222 100644 +index b53566f2..15219611 100644 --- a/packages/plugin/tests/control-runtime.test.ts +++ b/packages/plugin/tests/control-runtime.test.ts -@@ -134,6 +134,35 @@ describe('PluginControlRuntime settings setup', () => { +@@ -135,6 +135,35 @@ describe('PluginControlRuntime settings setup', () => { expect(apply.mock.calls[0]?.[0].codex.enabled).toBe(true) }) @@ -1031,9 +1151,21 @@ index f0499a4..858b222 100644 it('coexists with a Remote Web UI that already owns /remote', async () => { const channels = new Set(['/remote']) const connection = { +diff --git a/packages/plugin/tests/host-websocket-origin.test.ts b/packages/plugin/tests/host-websocket-origin.test.ts +index 587b8f93..22aed907 100644 +--- a/packages/plugin/tests/host-websocket-origin.test.ts ++++ b/packages/plugin/tests/host-websocket-origin.test.ts +@@ -383,6 +383,7 @@ function hostConnection( + serverUrl: baseUrl, + deviceName: 'Host', + forceRelay: true, ++ liteMode: true, + rotatePinnedPeerKey: false, + logLevel: 'error', + reconnect: reconnect ?? { enabled: false, initialDelayMs: 10, maxDelayMs: 20, jitter: 0 }, diff --git a/packages/plugin/tests/lite-mode.test.ts b/packages/plugin/tests/lite-mode.test.ts new file mode 100644 -index 0000000..2dae6a0 +index 00000000..2dae6a08 --- /dev/null +++ b/packages/plugin/tests/lite-mode.test.ts @@ -0,0 +1,91 @@ @@ -1129,10 +1261,10 @@ index 0000000..2dae6a0 + }) +}) diff --git a/packages/plugin/tests/multi-client-runtime.test.ts b/packages/plugin/tests/multi-client-runtime.test.ts -index 1729c7b..238632e 100644 +index e7ed851e..ac2de9ab 100644 --- a/packages/plugin/tests/multi-client-runtime.test.ts +++ b/packages/plugin/tests/multi-client-runtime.test.ts -@@ -596,6 +596,7 @@ function config(): ResolvedConfig { +@@ -742,6 +742,7 @@ function config(): ResolvedConfig { forceRelay: true, rotatePinnedPeerKey: false, logLevel: 'error', @@ -1142,7 +1274,7 @@ index 1729c7b..238632e 100644 cursor: { enabled: false, binary: 'agent' }, diff --git a/packages/plugin/tests/relay-preference.test.ts b/packages/plugin/tests/relay-preference.test.ts new file mode 100644 -index 0000000..e4f5658 +index 00000000..e4f56589 --- /dev/null +++ b/packages/plugin/tests/relay-preference.test.ts @@ -0,0 +1,40 @@ @@ -1187,7 +1319,7 @@ index 0000000..e4f5658 + }) +}) diff --git a/packages/plugin/tests/server-connection.test.ts b/packages/plugin/tests/server-connection.test.ts -index 10f5a80..0c60c70 100644 +index 10f5a807..0c60c707 100644 --- a/packages/plugin/tests/server-connection.test.ts +++ b/packages/plugin/tests/server-connection.test.ts @@ -1349,6 +1349,7 @@ function config(): ResolvedConfig {