DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
chore(ssh): consolidate shared defaults and internal helpers (#819)
Mao Mr7dfe8c51cbcb
diff --git a/docs/audit/pkg-ssh-scheduler-notify-rightclick.md b/docs/audit/pkg-ssh-scheduler-notify-rightclick.mdindex 8a84c785..30f0624a 100644--- a/docs/audit/pkg-ssh-scheduler-notify-rightclick.md+++ b/docs/audit/pkg-ssh-scheduler-notify-rightclick.md@@ -84,3 +84,16 @@ net: -452 lines, -4 deps possible.- `keep:` scheduler DTO 的接口与 readonly 约束、公开 recommendation.form 和 locale 词典;hydrate 注册仍承载生命周期,入口规范禁止把初始化请求移到 client entry。- `keep:` lodash 的深比较、默认值合并、形状校验及其余仍使用的方法与依赖。`Object.is` 不等价于 `isEqual`,对象展开不等价于跳过 undefined 的 `defaults`;原 -4 deps 预估不作为本次结果。- 验证:新增任务更新/恢复与快照顺序回归;三包 22 文件 / 203 用例连续六次乱序通过,深比较变异被测试拒绝。合并内部包装精简后,与 UI/extension 一起运行 52 文件 / 386 用例通过,限定源码别名类型检查通过,Lint 零错误。++## SSH 执行复核(2026-09-30)++以下结论覆盖原 SSH 建议;独立于另外三包提交。++- 已执行:SSH/远端端口默认值收口至共享常量,保留 storage 的既有导出;`SSH_API_PATH` 与 `REMOTE_PLUGIN_PROFILE` 保留名称但改为同值重导出;复用 `REMOTE_ROOT` 和错误文本转换,私有 `retryHintOf` 内联。+- `keep:` 四个 wire 解析器、路由输入/CORS/回环校验。TypeScript 泛型不校验运行时数据,host 校验不能替代客户端容错。+- `keep:` 客户端与宿主 wire 接口并非逐字同形:除 stage 外,machineId 的品牌类型及 skill root 的开放 string/封闭 union 也不同;不收窄宽容读取契约。+- `keep:` 本地 snapshot store 每次浅复制通知的语义,平台的 Immer store 不是直接等价替换;sync/async 原子写保持各自调度、权限和失败清理语义。+- `keep:` `emitStatus` 生命周期注入面、事件 ring 的测试容量、已有 retry 工具和公开 `SshKey` 词典。仓内少消费者不足以删除协议或真实边界测试能力。+- 撤回类名派生:保留现有 literal/readonly 类型需要额外类型级转换器,实际只减少少量注释行;不为审计预估引入第二套转换逻辑。+- 验证:受影响源码 6 文件 / 170 用例五次独立乱序通过,插件同步命令另 3 用例通过;端口 22→23 的变异被新回归拒绝并已恢复。仓库和限定源码类型检查、SSH Lint 均通过。+- 环境限制:完整 SSH unit 仍有与原始基线相同的 16 项失败(Windows/POSIX shell、路径、文件权限与缺少部署树);现有组件套件因本地 primitives 缺少 `simple-icons` 无法收集。未构建插件、未弱化断言、未提交临时测试配置;CI 结果另行记录。diff --git a/packages/dsh-tauri-ssh/src/client/components/machines-section.tsx b/packages/dsh-tauri-ssh/src/client/components/machines-section.tsxindex 62dd515c..ea6241e5 100644--- a/packages/dsh-tauri-ssh/src/client/components/machines-section.tsx+++ b/packages/dsh-tauri-ssh/src/client/components/machines-section.tsx@@ -4,14 +4,12 @@ import type { InstallResult, MachineRow, MachinesNotice, MachinesStore, MachineSimport type { MachineLifecycleState, RemoteBridge } from '../types/index'import { Button, Input, Modal, StateDot } from 'dsh-tauri-ui/client'import { useEffect, useState, useSyncExternalStore } from 'react'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'+import { messageOf } from '../../shared/error'import { cls } from '../styles/index'import { errorTextOf } from '../utils/error'import { retrySecondsOf } from '../utils/retry'-/** New-machine form defaults (ssh-ui 既有默认:SSH 22 / 远端 web 3080)。 */-const DEFAULT_PORT = 22-const DEFAULT_REMOTE_PORT = 3080-/** The StateDot vocabulary the connection states map onto ('idle' is hollow). */type DotState = 'done' | 'ongoing' | 'error' | 'idle'@@ -161,7 +159,7 @@ function EditPanel({ draft, t, secretSet, dirty, saving, onChange, onSecret, onS<Input className={cls.fieldInput} value={row.host} disabled={saving} onChange={event => onChange(draft.key, { host: event.target.value })} /></Field><Field label={t('field.port')} span={3}>- <Input className={cls.fieldInput} type="number" value={row.port} disabled={saving} onChange={event => onChange(draft.key, { port: numberOf(event.target.value, DEFAULT_PORT) })} />+ <Input className={cls.fieldInput} type="number" value={row.port} disabled={saving} onChange={event => onChange(draft.key, { port: numberOf(event.target.value, DEFAULT_SSH_PORT) })} /></Field><Field label={t('field.user')} span={3}><Input className={cls.fieldInput} value={row.user} disabled={saving} onChange={event => onChange(draft.key, { user: event.target.value })} />@@ -524,32 +522,19 @@ function statusTextOf(status: MachineStatus | undefined, t: (key: SshKey) => str? t('status.disconnected'): t(STATUS_KEY_OF[status.state])if (status?.state === 'reconnecting' && status.nextRetryAt !== undefined) {- return base + t('status.nextRetry').replace('{hint}', retryHintOf(status.nextRetryAt, Date.now(), t))+ const seconds = retrySecondsOf(status.nextRetryAt, Date.now())+ const hint = seconds <= 0 ? t('retry.now') : t('retry.inSeconds').replace('{seconds}', String(seconds))+ return base + t('status.nextRetry').replace('{hint}', hint)}return base}-/**- * The relative-time hint for a scheduled retry: "now" once the instant is- * due, else "in Xs". The clock is read per render; the polling loop keeps- * reconnecting machines re-rendering, so the hint stays current.- */-function retryHintOf(nextRetryAt: number, nowMs: number, t: (key: SshKey) => string): string {- const seconds = retrySecondsOf(nextRetryAt, nowMs)- return seconds <= 0 ? t('retry.now') : t('retry.inSeconds').replace('{seconds}', String(seconds))-}-/** Parse a number input; non-numbers fall back to the default. */function numberOf(raw: string, fallback: number): number {const parsed = Number(raw)return raw !== '' && Number.isFinite(parsed) ? parsed : fallback}-/** One operator-facing description of a bridge failure. */-function messageOf(error: unknown): string {- return error instanceof Error ? error.message : String(error)-}-/** Render one notice: host words verbatim, store literals through the locale table. */function noticeTextOf(notice: MachinesNotice, t: (key: SshKey) => string): string {if (notice.kind === 'text')@@ -578,7 +563,7 @@ function AddMachineDialog({ t, saving, takenIds, onSubmit, onClose }: {const [name, setName] = useState('')const [id, setId] = useState('')const [idTouched, setIdTouched] = useState(false)- const [port, setPort] = useState(String(DEFAULT_PORT))+ const [port, setPort] = useState(String(DEFAULT_SSH_PORT))const [user, setUser] = useState('')const [remotePort, setRemotePort] = useState(String(DEFAULT_REMOTE_PORT))const [profileName, setProfileName] = useState('')@@ -602,7 +587,7 @@ function AddMachineDialog({ t, saving, takenIds, onSubmit, onClose }: {id: effectiveId,name: name.trim() === '' ? effectiveId : name.trim(),host: trimmedHost,- port: numberOf(port, DEFAULT_PORT),+ port: numberOf(port, DEFAULT_SSH_PORT),user: user.trim(),hasPassword: false,hasPassphrase: false,diff --git a/packages/dsh-tauri-ssh/src/client/constants/index.ts b/packages/dsh-tauri-ssh/src/client/constants/index.tsindex b8ce085c..309aa0e9 100644--- a/packages/dsh-tauri-ssh/src/client/constants/index.ts+++ b/packages/dsh-tauri-ssh/src/client/constants/index.ts@@ -30,7 +30,7 @@ export const SSH_TABS_ID = 'dsh-tauri-ssh-tabs'export const SETTINGS_OPEN_MESSAGE = 'dsh://settings:open'/** The /api-ssh route the host plugin mounts (same-origin POST envelope). */-export const SSH_API_PATH = '/api-ssh'+export { SSH_API_PREFIX as SSH_API_PATH } from '../../shared/constants'/*** C-BRIDGE (S5-owned): the desktop iframe invoke commands the panel talks todiff --git a/packages/dsh-tauri-ssh/src/client/store/index.ts b/packages/dsh-tauri-ssh/src/client/store/index.tsindex 19185b3e..00e5751d 100644--- a/packages/dsh-tauri-ssh/src/client/store/index.ts+++ b/packages/dsh-tauri-ssh/src/client/store/index.ts@@ -11,6 +11,8 @@import type { SshKey } from '../locales/index'import type { MachineLifecycleState, SshMachineEvent, SyncApplyResult, SyncItemResult, SyncPreview } from '../types/index'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'+import { messageOf } from '../../shared/error'import { SSH_API_PATH } from '../constants/index'import { isLifecycleState } from '../types/index'@@ -155,11 +157,6 @@ export function createSnapshotStore<T>(initial: T): SnapshotStore<T> & { update:}}-/** Operator-facing description of any failure. */-function messageOf(error: unknown): string {- return error instanceof Error ? error.message : String(error)-}-/** Read one wire state through the C-STATE vocabulary; unknowns read as disconnected. */function lifecycleStateOf(raw: unknown): MachineLifecycleState {return isLifecycleState(raw) ? raw : 'disconnected'@@ -344,8 +341,8 @@ export function machineRowOf(value: unknown): MachineRow | undefined {return undefinedif (typeof row.user !== 'string')return undefined- const port = typeof row.port === 'number' ? row.port : 22- const remotePort = typeof row.remotePort === 'number' ? row.remotePort : 3080+ const port = typeof row.port === 'number' ? row.port : DEFAULT_SSH_PORT+ const remotePort = typeof row.remotePort === 'number' ? row.remotePort : DEFAULT_REMOTE_PORTconst startCommand = typeof row.startCommand === 'string' && row.startCommand !== ''? row.startCommand: undefineddiff --git a/packages/dsh-tauri-ssh/src/host/routes/index.ts b/packages/dsh-tauri-ssh/src/host/routes/index.tsindex 9170b762..eca60618 100644--- a/packages/dsh-tauri-ssh/src/host/routes/index.ts+++ b/packages/dsh-tauri-ssh/src/host/routes/index.ts@@ -19,6 +19,7 @@import type { IncomingMessage, ServerResponse } from 'node:http'import type { MachineSaveRow, MachineSecretWrite, MachineView, SshInstallResult, SshMachineEventsPage, SshMachineStatus, SshTestResult, SyncApplyResult, SyncPluginRef, SyncPreview, SyncSkillRef, SyncSkillRoot } from '../types/index'import { Buffer } from 'node:buffer'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'import { MachineId, SshError } from '../types/index'/** One request envelope. */@@ -331,8 +332,8 @@ function saveRowOf(payload: Record<string, unknown>): MachineSaveRow {throw new Error('invalid row: host')if (typeof value.user !== 'string')throw new Error('invalid row: user')- const port = typeof value.port === 'number' ? value.port : 22- const remotePort = typeof value.remotePort === 'number' ? value.remotePort : 3080+ const port = typeof value.port === 'number' ? value.port : DEFAULT_SSH_PORT+ const remotePort = typeof value.remotePort === 'number' ? value.remotePort : DEFAULT_REMOTE_PORTconst startCommand = typeof value.startCommand === 'string' && value.startCommand !== ''? value.startCommand: undefineddiff --git a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.tsindex d5cf10b5..57345830 100644--- a/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts+++ b/packages/dsh-tauri-ssh/src/host/service/plugins-sync.ts@@ -33,8 +33,7 @@ import { tmpdir } from 'node:os'import { dirname, join, resolve } from 'node:path'import { fileURLToPath } from 'node:url'-/** Remote root of the desktop-managed runtime (mirrors bootstrap REMOTE_ROOT). */-const REMOTE_ROOT = '.dsh-desktop'+import { REMOTE_ROOT } from './bootstrap'/** Remote directory the plugin tree is synced into (flat node_modules inside). */const REMOTE_PLUGINS_DIR = `${REMOTE_ROOT}/plugins`/** Remote marker recording the last synced tree hash. */diff --git a/packages/dsh-tauri-ssh/src/host/service/sync.ts b/packages/dsh-tauri-ssh/src/host/service/sync.tsindex a94e4702..9db5ff5e 100644--- a/packages/dsh-tauri-ssh/src/host/service/sync.ts+++ b/packages/dsh-tauri-ssh/src/host/service/sync.ts@@ -20,13 +20,7 @@ import { allowlistReadCommand, allowlistWriteCommand, mergeWorkspaceAllowlist, pimport { dshEntryProbeCommand, firstLineOf, layoutBinDir, layoutNodeBinary } from './bootstrap'import { shQuote } from './transport'-/**- * Fallback remote profile for plugin installs when the caller names none —- * the same default the tunnel bootstrap serves ({@link DEFAULT_REMOTE_PROFILE}).- * Callers that know the machine (the `/api-ssh` service) always pass the- * machine's own profile, so plugins land where the tunnel actually looks.- */-export const REMOTE_PLUGIN_PROFILE = DEFAULT_REMOTE_PROFILE+export { DEFAULT_REMOTE_PROFILE as REMOTE_PLUGIN_PROFILE } from '../storage/index'/** How many output lines an item failure carries (the operator-facing tail). */const FAILURE_TAIL_LINES = 5@@ -116,7 +110,7 @@ export function installSpecOf(name: string, spec: string): string {* @param profileName - the remote profile to install into.* @returns the shell command line.*/-export function pluginAddCommand(dshEntry: string, target: string, profileName: string = REMOTE_PLUGIN_PROFILE): string {+export function pluginAddCommand(dshEntry: string, target: string, profileName: string = DEFAULT_REMOTE_PROFILE): string {// `dsh plugin add` spawns a bare `pnpm`: the layout bin dir carries the// shim the connect pipeline writes (see `ensurePnpmCommand`), so prepend it// to PATH for this command only.@@ -318,13 +312,13 @@ export class SyncEngine {const keys = parseBuildAllowKeys(output)if (keys.length === 0)return []- const remote = await session.exec(allowlistReadCommand(profileName ?? REMOTE_PLUGIN_PROFILE))+ const remote = await session.exec(allowlistReadCommand(profileName ?? DEFAULT_REMOTE_PROFILE))const { yaml, added } = mergeWorkspaceAllowlist(remote.stdout,{ allowBuilds: Object.fromEntries(keys.map(key => [key, true])), onlyBuiltDependencies: [] },)if (added.length > 0)- await session.exec(allowlistWriteCommand(profileName ?? REMOTE_PLUGIN_PROFILE, yaml))+ await session.exec(allowlistWriteCommand(profileName ?? DEFAULT_REMOTE_PROFILE, yaml))return added}diff --git a/packages/dsh-tauri-ssh/src/host/service/transport.ts b/packages/dsh-tauri-ssh/src/host/service/transport.tsindex cc83855b..33943771 100644--- a/packages/dsh-tauri-ssh/src/host/service/transport.ts+++ b/packages/dsh-tauri-ssh/src/host/service/transport.ts@@ -15,6 +15,7 @@ import { get as httpGet } from 'node:http'import { createServer } from 'node:net'import process from 'node:process'import { Client } from 'ssh2'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'import { MachineId } from '../types/index'/** The credential-resolution face the transport needs (SshConfigResolver implements it). */@@ -330,8 +331,8 @@ export class Ssh2Transport implements SshTransport {name: hop.alias,host: hop.alias,user: hop.user ?? '',- port: hop.port ?? 22,- remotePort: 3080,+ port: hop.port ?? DEFAULT_SSH_PORT,+ remotePort: DEFAULT_REMOTE_PORT,}const jumpAuth = await this.resolver.resolve(jumpProfile)if ((jumpAuth.proxyJump ?? []).length > 0)diff --git a/packages/dsh-tauri-ssh/src/host/storage/index.ts b/packages/dsh-tauri-ssh/src/host/storage/index.tsindex d517f244..e3a5d7e1 100644--- a/packages/dsh-tauri-ssh/src/host/storage/index.ts+++ b/packages/dsh-tauri-ssh/src/host/storage/index.ts@@ -12,13 +12,10 @@ import { randomBytes } from 'node:crypto'import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'import { dirname } from 'pathe'import z from 'schemastery'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'import { MachineId as brandMachineId } from '../types/index'-/** Default TCP port of the remote `dsh web` instance (loopback). */-export const DEFAULT_REMOTE_PORT = 3080--/** Default SSH transport port. */-export const DEFAULT_SSH_PORT = 22+export { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT } from '../../shared/constants'/** Default remote dsh profile name (`dsh --profile <name> web`). */export const DEFAULT_REMOTE_PROFILE = 'remote'diff --git a/packages/dsh-tauri-ssh/src/shared/constants.test.ts b/packages/dsh-tauri-ssh/src/shared/constants.test.tsnew file mode 100644index 00000000..a5123934--- /dev/null+++ b/packages/dsh-tauri-ssh/src/shared/constants.test.ts@@ -0,0 +1,30 @@+import { describe, expect, it } from 'vitest'+import { SSH_API_PATH } from '../client/constants/index'+import { machineRowOf } from '../client/store/index'+import { REMOTE_PLUGIN_PROFILE } from '../host/service/sync'+import { DEFAULT_REMOTE_PORT as hostRemotePort, DEFAULT_SSH_PORT as hostSshPort, machineProfileOf } from '../host/storage/index'+import { DEFAULT_REMOTE_PORT, DEFAULT_SSH_PORT, SSH_API_PREFIX } from './constants'++describe('shared SSH defaults', () => {+ it('preserves numeric defaults and legacy host exports', () => {+ expect(DEFAULT_SSH_PORT).toBe(22)+ expect(DEFAULT_REMOTE_PORT).toBe(3080)+ expect(hostSshPort).toBe(22)+ expect(hostRemotePort).toBe(3080)+ expect(REMOTE_PLUGIN_PROFILE).toBe('remote')+ expect(SSH_API_PREFIX).toBe('/api-ssh')+ expect(SSH_API_PATH).toBe('/api-ssh')+ })++ it.each([{}, { port: 'bad', remotePort: null }])('keeps client and stored wire fallback values for %j', (ports) => {+ const wire = { id: 'a', name: 'alpha', host: 'localhost', user: 'ops', ...ports }+ expect(machineRowOf(wire)).toMatchObject({ port: 22, remotePort: 3080 })+ expect(machineProfileOf(wire)).toMatchObject({ port: 22, remotePort: 3080 })+ })++ it('preserves explicitly supplied numeric ports', () => {+ const wire = { id: 'a', name: 'alpha', host: 'localhost', user: 'ops', port: 2222, remotePort: 4000 }+ expect(machineRowOf(wire)).toMatchObject({ port: 2222, remotePort: 4000 })+ expect(machineProfileOf(wire)).toMatchObject({ port: 2222, remotePort: 4000 })+ })+})diff --git a/packages/dsh-tauri-ssh/src/shared/constants.ts b/packages/dsh-tauri-ssh/src/shared/constants.tsindex 962eba94..8a2cc610 100644--- a/packages/dsh-tauri-ssh/src/shared/constants.ts+++ b/packages/dsh-tauri-ssh/src/shared/constants.ts@@ -14,3 +14,6 @@ export const SSH_PLUGIN_NAME = 'dsh-tauri-ssh'* `ctx.webServer` (and the client half POSTs to). Loopback-only by contract.*/export const SSH_API_PREFIX = '/api-ssh'++export const DEFAULT_SSH_PORT = 22+export const DEFAULT_REMOTE_PORT = 3080diff --git a/packages/dsh-tauri-ssh/src/shared/error.test.ts b/packages/dsh-tauri-ssh/src/shared/error.test.tsnew file mode 100644index 00000000..cafa21f6--- /dev/null+++ b/packages/dsh-tauri-ssh/src/shared/error.test.ts@@ -0,0 +1,15 @@+import { describe, expect, it } from 'vitest'+import { messageOf } from './error'++describe('messageOf', () => {+ it.each([+ [new Error('window refused'), 'window refused'],+ ['plain failure', 'plain failure'],+ [null, 'null'],+ [undefined, 'undefined'],+ [42, '42'],+ [{ message: 'not an Error' }, '[object Object]'],+ ])('preserves the operator-facing text for %j', (error, expected) => {+ expect(messageOf(error)).toBe(expected)+ })+})diff --git a/packages/dsh-tauri-ssh/src/shared/error.ts b/packages/dsh-tauri-ssh/src/shared/error.tsnew file mode 100644index 00000000..e59cf0ae--- /dev/null+++ b/packages/dsh-tauri-ssh/src/shared/error.ts@@ -0,0 +1,3 @@+export function messageOf(error: unknown): string {+ return error instanceof Error ? error.message : String(error)+}