Zum Hauptinhalt springen
R

dsh-cloud-sync

robinliang0829-lgtm/dsh-cloud-sync

Ship OpenTelemetry GenAI observability and multi-device cloud state sync from one DSH bundle. It reuses and replaces the standalone @loongsuite/dsh-plugin (traces + metrics for sessions, agent loop, LLM and tool lifecycle; do not install both — disable or remove the upstream plugin first), and adds a WebSocket client that pushes full session event logs (header + snapshotEvents) to a relay you run so different local DSH instances share state. On connect it pulls and rebuilds the other devices' sessions automatically (cross-device resume). The sync client itself has zero third-party runtime dependencies; a small Node.js relay is included in the repo. The local /cloud-sync/* HTTP routes (status, sessions, config, resync, delete) have no origin or loopback check, and the bundled relay accepts unauthenticated connections unless AUTH_TOKEN is set — keep the DSH web port off untrusted networks and run the relay with a token.

Installation

dsh plugin --profile web add github:robinliang0829-lgtm/dsh-cloud-sync

README

dsh-cloud-sync

一个 DeepSeek Harness (DSH) 插件 bundle,把两件事装进一个包:

  1. OpenTelemetry GenAI 可观测性 —— 复用 @loongsuite/dsh-plugin,把会话 / Agent 循环 / LLM / 工具生命周期事件导出为 OTel GenAI trace 与 metric。
  2. 云端状态同步 —— 新增的 Host 插件,作为 WebSocket 客户端主动外连云端中继,把完整会话事件日志(session header + snapshotEvents())增量推送到云端,从而把不同本地端登录的 DSH 状态集中同步;并在连接时自动拉回并重建其他设备的会话(跨设备续接)。

结构

dsh-cloud-sync/
├─ package.json         bundle 清单(含 dsh.bundle.patch 与依赖)
├─ cordis.patch.yml     插入两行:observability + sync
├─ index.js             云端同步插件(WebSocket 客户端)
├─ locale/en.json  locale/zh.json   显示元数据
└─ icon.svg

工作原理

  • 启动时用 Node 内置 WebSocket(undici,无需额外依赖)连接 config.server。
  • 连接后发送 hello(携带 deviceId / instanceId / token),随后对 sessions.list() 里的每个 session 推送一次完整快照(header + 全部事件),重连后同样重新全量同步一次。
  • 监听 session/created(推快照)、session/event(推增量事件)、session/disposed(从云端删除该会话)。
  • 启用 resume 时,连接后向云端 sync.list 拉取其他设备的会话摘要,再 sync.pull 逐个拉全量日志并用 sessions.create(id, { seed }) 本地重建。
  • 断线后指数退避重连,并用 ping 心跳保活。

事件中的 Buffer/ArrayBuffer/BigInt/Error 会被 JSON 安全序列化(__bytes/__bigint/__error),函数与 symbol 被丢弃;续接重建前用逆向 revive() 还原。

配置

键默认说明
enabledtrue是否启用云端同步
serverws://127.0.0.1:8080/ws云端 WebSocket 地址
token空云端鉴权令牌,须与云端 AUTH_TOKEN/AUTH_TOKENS 之一一致
deviceId自动(<profile>@<hostname>)本机设备标识
resumetrue连接后自动拉取并重建其他设备的会话(跨设备续接)
resumeOnlyFrom[]只拉取这些 deviceId 的会话(空 = 全部)
resumeMaxSessions20每次连接最多重建的会话数
reconnectMinMs / reconnectMaxMs500 / 30000重连退避区间
heartbeatMs30000心跳间隔
debugfalse打印收发消息类型

环境变量可覆盖:DSH_CLOUD_SYNC_SERVER、DSH_CLOUD_SYNC_TOKEN、DSH_CLOUD_SYNC_DEVICE。

手动操作(斜杠命令)

插件注册了 /cloud-sync 命令:

  • /cloud-sync 或 /cloud-sync status —— 显示同步状态(设备、云端、连接、本地会话数、续接开关)。
  • /cloud-sync delete <sessionId> —— 从云端删除指定会话。
  • /cloud-sync resync —— 立即触发一次全量重同步。

Web UI(设置页)

插件带一个客户端面板,出现在 设置 → 云端同步(settings.section 槽位,order 35):

  • 状态卡:连接点(已连接/未连接)、中继地址、本机设备名、本地会话数、凭据是否已设置、最近一次连接时间与错误。
  • 连接设置:中继地址、设备名、Token(留空表示不修改)、是否启用跨设备续接;「保存并重连」立即生效(写入 ~/.dsh/cloud-sync/settings.json,无需重启 DSH)。
  • 本地会话:列出本机会话,「删除云端副本」从云端移除该会话。
  • 其他设备会话:列出云端其他设备的会话,可「从云端拉取」(立即重建到本地)或删除。

面板通过宿主注册的同源 HTTP 路由工作:GET /cloud-sync/status、GET /cloud-sync/sessions、GET /cloud-sync/remote、POST /cloud-sync/config、POST /cloud-sync/resync、POST /cloud-sync/delete。这些路由仅在 Web UI 宿主存在时注册。

安装

本 bundle 用于替换独立的 @loongsuite/dsh-plugin:

  1. 从 profile 的 bundle 列表中禁用(或移除)@loongsuite/dsh-plugin。
  2. 用 Plugin Manager 安装本 bundle(它会把 @loongsuite/dsh-plugin 作为普通依赖拉进来,并重新插入 observability 行,同时新增 sync 行)。

index.js 零第三方运行时依赖——只用 Node 22 内置模块(node:os、node:crypto 与全局 WebSocket);@loongsuite/dsh-plugin 作为 bundle 依赖由 DSH loader 从 profile 解析,index.js 不直接 import。

详见根目录 PROTOCOL.md(wire 协议)与 cloud-server/(参考云端服务)。

Ähnliche Plugins