dsh-remote 0.8.24 → 0.8.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,48 @@ Manage several SSH machines, then pick a **remote workspace** (or a **local** on
20
20
 
21
21
  The harness Web UI intentionally binds `127.0.0.1` (the CLI rejects `--host 0.0.0.0` for safety). This plugin goes the other way: **you connect out** to the machines you maintain, pick a workspace, and work in it through the normal DSH workspace + agent fs flows — no changes to `dsh-workspace` or the harness core.
22
22
 
23
+ ## Data collection / telemetry
24
+
25
+ dsh-remote sends **one anonymous heartbeat per launch** (at most once every 6 hours) so the author can measure real usage: daily active installs, which version is actually running, and platform distribution. npm download counts cannot answer this (they are release-driven and include mirrors/crawlers), and GitHub clones include CI.
26
+
27
+ **What is sent** — exactly five fields, and nothing else:
28
+
29
+ | Field | Example | Purpose |
30
+ |---|---|---|
31
+ | `idHash` | `872bd8cf…` (32 hex) | `HMAC-SHA256('dsh-remote/telemetry/v1', installId)` — a pseudonym for this install |
32
+ | `version` | `0.8.24` | which version is actually running |
33
+ | `platform` | `win32` / `darwin` / `linux` | platform distribution |
34
+ | `arch` | `x64` / `arm64` | architecture |
35
+ | `node` | `24.14.0` | Node version |
36
+
37
+ **What is never sent** — hostnames, usernames, file paths, IP addresses, SSH hosts/ports/keys, your machine list, conversation content, or anything from your remote sessions. The original `installId` **never leaves your machine**: only its HMAC is transmitted, so the server cannot correlate it with anything else and cannot reverse it.
38
+
39
+ **Where the identity lives** — a random UUID in `<DSH_HOME>/.dsh-remote-install-id` (e.g. `~/.dsh/`). It is deliberately **not** stored in the plugin directory, which npm/pnpm overwrites on every upgrade; keeping it in `DSH_HOME` means an upgrade does not make you look like a new user. Delete that file to reset the identity.
40
+
41
+ The heartbeat is **fire-and-forget**: it never blocks loading, never logs noise, and any failure (offline, blocked, endpoint change) is swallowed silently — it can never affect any plugin feature.
42
+
43
+ <!--中文-->
44
+
45
+ ## 数据采集 / 遥测
46
+
47
+ dsh-remote 每次启动会发送**一次匿名心跳**(同一安装最多每 6 小时一次),用于统计真实使用量:去重日活、实际在跑的版本、平台分布。npm 下载量回答不了这些问题(由发版驱动、且含镜像与爬虫),GitHub clone 也混有 CI。
48
+
49
+ **发送的内容** —— 严格只有 5 个字段:
50
+
51
+ | 字段 | 示例 | 用途 |
52
+ |---|---|---|
53
+ | `idHash` | `872bd8cf…`(32 位 hex) | `HMAC-SHA256('dsh-remote/telemetry/v1', installId)`,本安装的伪名 |
54
+ | `version` | `0.8.24` | 实际在运行的版本 |
55
+ | `platform` | `win32` / `darwin` / `linux` | 平台分布 |
56
+ | `arch` | `x64` / `arm64` | 架构 |
57
+ | `node` | `24.14.0` | Node 版本 |
58
+
59
+ **绝不发送** —— 主机名、用户名、文件路径、IP、SSH 主机/端口/密钥、你的机器列表、会话内容、任何远程工作区数据。原始 `installId` **不离开本机**:只有它的 HMAC 被传出,服务端无法与其他数据关联,也无法反推。
60
+
61
+ **身份存放位置** —— `<DSH_HOME>/.dsh-remote-install-id`(如 `~/.dsh/`)中的一个随机 UUID。刻意**不放在插件目录**(npm/pnpm 每次升级都会覆盖),放 `DSH_HOME` 才能保证升级后不会把你算成新用户。删除该文件即重置身份。
62
+
63
+ 心跳是**尽力而为**的旁路:不阻塞加载、不产生日志噪音、任何失败(离线/被拦截/端点变更)都静默吞掉,绝不影响插件的任何功能。
64
+
23
65
  ## Screen previews
24
66
 
25
67
  Settings → **远程工作区** — a multi-machine SSH registry (add / edit / delete / set-current, password stored locally):
package/README.zh.md CHANGED
@@ -41,6 +41,26 @@ Desktop 安装器还可能要求明确配置 `ssh2` / `cpu-features` 可选构
41
41
 
42
42
  DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.0.0`)。本插件反过来:**由你主动连出**到你维护的机器,选一个工作区,然后通过 DSH 原生的工作区 + 文件流来工作——**不改动 `dsh-workspace` 核心**。
43
43
 
44
+ ## 数据采集 / 遥测
45
+
46
+ dsh-remote 每次启动会发送**一次匿名心跳**(同一安装最多每 6 小时一次),用于统计真实使用量:去重日活、实际在跑的版本、平台分布。npm 下载量回答不了这些问题(由发版驱动、且含镜像与爬虫),GitHub clone 也混有 CI。
47
+
48
+ **发送的内容** —— 严格只有 5 个字段,一个都不多:
49
+
50
+ | 字段 | 示例 | 用途 |
51
+ |---|---|---|
52
+ | `idHash` | `872bd8cf…`(32 位 hex) | `HMAC-SHA256('dsh-remote/telemetry/v1', installId)`,本安装的伪名 |
53
+ | `version` | `0.8.24` | 实际在运行的版本 |
54
+ | `platform` | `win32` / `darwin` / `linux` | 平台分布 |
55
+ | `arch` | `x64` / `arm64` | 架构 |
56
+ | `node` | `24.14.0` | Node 版本 |
57
+
58
+ **绝不发送** —— 主机名、用户名、文件路径、IP、SSH 主机/端口/密钥、你的机器列表、会话内容、任何远程工作区数据。本插件恰恰能拿到这些信息,所以边界在这里划得很硬:原始 `installId` **不离开本机**,只有它的 HMAC 被传出,服务端无法与其他数据关联,也无法反推身份。
59
+
60
+ **身份存放位置** —— `<DSH_HOME>/.dsh-remote-install-id`(如 `~/.dsh/`)中的一个随机 UUID。刻意**不放在插件目录**:npm/pnpm 每次升级都会覆盖插件目录,放那里会让同一台机器每次升级都换身份,把 1 个用户算成 N 个。删除该文件即重置身份。
61
+
62
+ 心跳是**尽力而为**的旁路:不阻塞加载、不产生日志噪音、任何失败(离线/被拦截/端点变更)都静默吞掉,绝不影响插件的任何功能。
63
+
44
64
  ## 界面预览
45
65
 
46
66
  设置 → **远程工作区** —— 多机 SSH 列表(增/删/改/设为当前,密码本地保存、不回显):
package/lib/index.js CHANGED
@@ -42,6 +42,7 @@ import { resolveMirror, poolKey, lookupSessionCwd, encodeSegmentSafe, readSessio
42
42
  import { TaskManager } from './tasks.js'
43
43
  import { ForwardManager } from './forwards.js'
44
44
  import { selfDir, diskVersion, LOADED_VERSION, gtVersion, fetchLatestVersion, applyUpdate, persistUpdateMode, readUpdateMode, reloadSelf, scheduleSelfReload } from './update.js'
45
+ import { sendHeartbeat, pseudonym, heartbeatUrl, hasPersistedId, installIdPath } from './telemetry.js'
45
46
  import { loadMachines as _loadMachines, saveMachines as _saveMachines, sanitizeMachine as _sanitizeMachine, applyMachine as _applyMachine, machineId as _machineId } from './registry.js'
46
47
  import { registerHttpTransports } from './http-transport.js'
47
48
  import { SshPool } from './pool.js'
@@ -262,6 +263,12 @@ export async function apply(ctx, config) {
262
263
 
263
264
  migrateLegacyData()
264
265
 
266
+ // ── 安装心跳(日活统计)─────────────────────────────────────────────────
267
+ // 旁路:不 await、不阻塞加载、失败静默(见 lib/telemetry.js 的隐私与失败策略)。
268
+ // 无配置开关(按作者要求默认开启);上报的是本插件专属 HMAC 伪名,
269
+ // 原始安装 id 与任何机器信息都不离开本机。
270
+ void sendHeartbeat(dshBase(), LOADED_VERSION)
271
+
265
272
  // The update marker means "a newer version landed on disk but is not the code
266
273
  // running yet". Reaching apply() with a marker naming the version we just
267
274
  // loaded means the swap already happened (or this is a plain boot into the
@@ -0,0 +1,163 @@
1
+ // dsh-remote — 安装级心跳(日活统计)。
2
+ //
3
+ // 目的:npm 下载量只能证明"有人下载",GitHub clone 里混着 CI 与爬虫,
4
+ // 都无法回答"多少人真的在用、用的是哪一版、留在哪个平台"。这里上报一个
5
+ // **最小字段的心跳**,让作者能算出去重日活 / 版本分布 / 平台分布 / 留存。
6
+ //
7
+ // ── 隐私边界(改这个文件前先读)──────────────────────────────────────────
8
+ // 1) 上报的是伪名:`idHash = HMAC-SHA256(SALT, installId)[:32]`。
9
+ // 原始 installId **绝不出机器**,服务端拿到的是本插件专属伪名,
10
+ // 无法与其他数据交叉关联(installId 本身是随机 UUID,不含任何机器信息)。
11
+ // 2) installId 存在 `<DSH_HOME>/.dsh-remote-install-id`,**不在插件目录**:
12
+ // 插件目录会被 pnpm 重装覆盖,放在那里会让同一台机器每次升级都换身份,
13
+ // 把 1 个人算成 N 个。DSH_HOME 跨重装稳定。
14
+ // 3) 字段白名单固定为 {idHash, version, platform, arch, node}。
15
+ // 本插件能拿到 SSH 主机、路径、机器列表——**这些一律不上报**。
16
+ //
17
+ // ── 失败策略 ─────────────────────────────────────────────────────────────
18
+ // 全程静默:任何异常(网络不可达、磁盘只读、端点变更)都只吞掉,
19
+ // 绝不阻塞加载、绝不写日志噪音、绝不重试轰炸。心跳是"尽力而为",
20
+ // 它失败不能影响用户任何真实功能。
21
+
22
+ import { createHmac, randomUUID } from 'node:crypto'
23
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
24
+ import path from 'node:path'
25
+
26
+ /** 上报端点(CloudBase HTTP 访问服务)。改域名只需改这一行。 */
27
+ const HEARTBEAT_URL = 'https://gitbolg-d7gmnsrw46e011706-1256429518.ap-shanghai.app.tcloudbase.com/dsh-hb/heartbeat'
28
+ /** 伪名盐:服务端无法反推身份,且换盐即可切断历史关联。 */
29
+ const SALT = 'dsh-remote/telemetry/v1'
30
+ const ID_FILE = '.dsh-remote-install-id'
31
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
32
+ /** 上报超时:心跳是旁路,不能拖慢启动;但也不能太短 —— 实测端点本身
33
+ * 250~520ms,而 **DSH 启动瞬间的并发初始化会把首帧 fetch 饿到 5s 以上**
34
+ * (曾以 5s 超时稳定失败在首启,靠下次启动才补上,等于丢掉当天最早的那批用户)。
35
+ * 15s 覆盖启动抖动,且因为不 await,慢也不会影响加载。 */
36
+ const TIMEOUT_MS = 15000
37
+ /** 启动后延迟多久再发:避开启动高峰(插件树/路由/服务都在抢事件循环)。
38
+ * 仍不 await——延迟是为了让心跳真的成功,不是为了让用户等待。 */
39
+ const STARTUP_DELAY_MS = 3000
40
+ /** 两次上报之间的最小间隔(同一天内重复启动不再上报)。 */
41
+ const MIN_INTERVAL_MS = 6 * 60 * 60 * 1000
42
+
43
+ /** 安装身份的进程内缓存,**按身份文件路径分键**。
44
+ * ★ 不能只用一个全局变量:同一进程内出现第二个 DSH_HOME(隔离沙箱、
45
+ * 测试夹具、desktop 与 cli 并存)时会串号,把 A 的 id 当成 B 的,
46
+ * 日活与装机量一起失真。DSH 官方的 anonymous-user-id 同样是按路径 memo。 */
47
+ const idCache = new Map()
48
+
49
+ /**
50
+ * 读取或创建本安装的随机身份(稳定 UUID,存 DSH_HOME)。
51
+ * 磁盘只读等异常时返回内存生成的临时身份:日活会多算一次,但绝不报错。
52
+ * @param home - DSH_HOME 绝对路径。
53
+ */
54
+ export function installId(home) {
55
+ const file = path.join(home, ID_FILE)
56
+ const cached = idCache.get(file)
57
+ if (cached) return cached
58
+
59
+ try {
60
+ const existing = readFileSync(file, 'utf8').trim()
61
+ if (UUID_RE.test(existing)) {
62
+ idCache.set(file, existing)
63
+ return existing
64
+ }
65
+ } catch { /* 不存在或不可读 → 下面创建 */ }
66
+ const created = randomUUID()
67
+ try {
68
+ mkdirSync(home, { recursive: true })
69
+ writeFileSync(file, `${created}\n`, 'utf8')
70
+ } catch { /* 只读也不影响本次运行 */ }
71
+ idCache.set(file, created)
72
+ return created
73
+ }
74
+
75
+ /** 稳定的匿名伪名(32 位 hex)。原始 id 不离开本进程。 */
76
+ export function pseudonym(home) {
77
+ return createHmac('sha256', SALT).update(installId(home)).digest('hex').slice(0, 32)
78
+ }
79
+
80
+ /** 是否到该上报了(进程内节流,避免每次工具调用都发)。 */
81
+ let lastSentAt = 0
82
+
83
+ /**
84
+ * 发送一次心跳。**永不抛出**,也永不返回可导致分支的失败态:
85
+ * 调用方不需要 try/catch,心跳成功与否都不应改变任何行为。
86
+ * @param home - DSH_HOME 绝对路径。
87
+ * @param version - 运行中的插件版本(用 LOADED_VERSION,即真正在跑的代码版本)。
88
+ * @param options.delayMs - 发送前延迟(默认 {@link STARTUP_DELAY_MS});
89
+ * 避开启动高峰。测试可传 0。
90
+ * @returns 是否真的发出了请求(仅用于测试与自检)。
91
+ */
92
+ export async function sendHeartbeat(home, version, options = {}) {
93
+ const now = Date.now()
94
+ if (now - lastSentAt < MIN_INTERVAL_MS) return false
95
+
96
+ const delayMs = options.delayMs === undefined ? STARTUP_DELAY_MS : Math.max(0, options.delayMs)
97
+ // 先占位,防止并发触发重复上报(本插件是单进程,够用)
98
+ lastSentAt = now
99
+ try {
100
+ if (delayMs) await new Promise((r) => {
101
+ const t = setTimeout(r, delayMs)
102
+ if (typeof t.unref === 'function') t.unref()
103
+ })
104
+ const body = JSON.stringify({
105
+ idHash: pseudonym(home),
106
+ version: String(version || '0.0.0'),
107
+ platform: process.platform,
108
+ arch: process.arch,
109
+ node: process.versions.node,
110
+ })
111
+ const controller = new AbortController()
112
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS)
113
+ try {
114
+ await fetch(HEARTBEAT_URL, {
115
+ method: 'POST',
116
+ headers: { 'content-type': 'application/json' },
117
+ body,
118
+ signal: controller.signal,
119
+ })
120
+ } finally {
121
+ clearTimeout(timer)
122
+ }
123
+ return true
124
+ } catch {
125
+ // 网络不可达 / 端点变更 / 被拦截:一律忽略。
126
+ // 允许下次重试:回滚节流,避免一次失败就把身份静默六个小时。
127
+ lastSentAt = 0
128
+ return false
129
+ }
130
+ }
131
+
132
+ /** 清空节流与缓存(仅测试用)。 */
133
+ export function _resetForTest() {
134
+ lastSentAt = 0
135
+ idCache.clear()
136
+ }
137
+
138
+ /** 心跳是否已配置(供设置页显示;不含端点本身)。 */
139
+ export function heartbeatEnabled() {
140
+ return typeof HEARTBEAT_URL === 'string' && HEARTBEAT_URL.startsWith('https://')
141
+ }
142
+
143
+ /** 供自检/文档使用的端点(不涉密,可公开)。 */
144
+ export function heartbeatUrl() {
145
+ return HEARTBEAT_URL
146
+ }
147
+
148
+ /** 身份文件是否已存在(自检用,不创建)。 */
149
+ export function hasPersistedId(home) {
150
+ try {
151
+ return UUID_RE.test(readFileSync(path.join(home, ID_FILE), 'utf8').trim())
152
+ } catch {
153
+ return false
154
+ }
155
+ }
156
+
157
+ /** 供自检:确认 installId 落盘位置(不创建)。 */
158
+ export function installIdPath(home) {
159
+ return path.join(home, ID_FILE)
160
+ }
161
+
162
+ // existsSync 仅用于自检导出,避免被 tree-shake 掉误报
163
+ export { existsSync as _existsSync }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-remote",
3
- "version": "0.8.24",
3
+ "version": "0.8.25",
4
4
  "description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive/proxy jump), pick a remote workspace, operate on it with 20 rw_* tools (incl. rw_edit/rw_stat/rw_mkdir/rw_remove/rw_move/rw_forward), conflict-aware mirror sync, port forwarding, optional side-bar remote file editing, audit log, keychain passwords.",
5
5
  "license": "MIT",
6
6
  "author": "flymysql <flyphp@outlook.com>",