DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
import type { Context } from '@deepseek-ai/cordis'
import type z from 'schemastery'
import type { Config as RemoteConfig } from './config/schema'
import type { RemoteHostContext } from './types/index'
import { REMOTE_PLUGIN_NAME } from '../shared/constants'
import { clearHostRuntime, migrateLegacyState, setCurrentHostInstance, setHostConfig, setMachineDeps, setSyncDeps, setTunnelDeps } from './config/runtime'
import { ConfigSchema } from './config/schema'
import { server } from './server'
import { panel } from './server/panel'
import { access } from './service/access'
import { gateway } from './service/gateway'
import { machine } from './service/machine'
import { transport } from './service/transport'
import { tunnel } from './service/tunnel'
import { resolveCloudflared, spawnCloudflared } from './utils/cloudflared'
import { packSkills, profileAllowlistReader, profileDependenciesReader, skillRootsScanner } from './utils/local'
const REMOTE_START_EFFECT = `${REMOTE_PLUGIN_NAME}: start`
const REMOTE_ROUTES_EFFECT = `${REMOTE_PLUGIN_NAME}: routes`
const REMOTE_PANEL_EFFECT = `${REMOTE_PLUGIN_NAME}: panel routes`
const REMOTE_RUNTIME_EFFECT = `${REMOTE_PLUGIN_NAME}: host runtime`
export const name = REMOTE_PLUGIN_NAME
export const inject = ['webServer', 'connection']
export const Config: z<RemoteConfig> = ConfigSchema
export function apply(ctx: RemoteHostContext, config: RemoteConfig): void {
setCurrentHostInstance(ctx)
setHostConfig(config)
setMachineDeps({
transport,
emitStatus: () => {}, // keep: 进度出口注入点,故意留空——状态另经 status() 与事件环读取
localAllowlist: profileAllowlistReader(),
})
setSyncDeps({
profileDependencies: profileDependenciesReader(),
scanSkills: skillRootsScanner(),
packSkills,
...config.installTimeoutMs === undefined ? {} : { commandTimeoutMs: config.installTimeoutMs },
})
setTunnelDeps({
policy: () => access.policy(),
resolveBinary: resolveCloudflared,
spawn: spawnCloudflared,
})
ctx.effect(() => {
const migrationFailure = migrateLegacyState()
if (migrationFailure !== undefined)
ctx.logger?.warn?.(`${REMOTE_PLUGIN_NAME}: 旧状态目录迁移未完成,已按新目录空状态启动(旧文件未改动): ${migrationFailure}`)
void machine.start().catch(() => undefined)
void access.restore().catch(() => undefined)
void tunnel.restore().catch(() => undefined)
}, REMOTE_START_EFFECT)
ctx.effect(() => server(ctx as unknown as Context), REMOTE_ROUTES_EFFECT)
ctx.effect(() => panel(ctx as unknown as Context), REMOTE_PANEL_EFFECT)
ctx.effect(() => () => {
// keep: 清理要串行等待:先让各服务停监听、回收子进程,最后才清运行时依赖
// (提前清空会让在途 dispose 读不到 deps,清理静默失败)
void shutdown().catch((error: unknown) => {
ctx.logger?.error?.(`${REMOTE_PLUGIN_NAME}: 关闭清理失败: ${error instanceof Error ? error.message : String(error)}`)
})
}, REMOTE_RUNTIME_EFFECT)
}
export default { apply, Config, inject, name }
// --- internal ---
async function shutdown(): Promise<void> {
try {
await machine.dispose()
}
finally {
try {
await tunnel.dispose()
}
finally {
try {
await access.dispose()
}
finally {
await gateway.dispose().catch(() => undefined)
clearHostRuntime()
}
}
}
}