@dsh-mobile/mobile-remote 3.2.6 → 3.3.0
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/FAQ.md +19 -12
- package/README.md +39 -40
- package/cordis.patch.yml +8 -4
- package/docs/PRIVACY-POLICY.en.md +88 -61
- package/docs/PRIVACY-POLICY.md +88 -61
- package/docs/SUPPORT.md +5 -5
- package/docs/TERMS-OF-SERVICE.en.md +1 -1
- package/docs/TERMS-OF-SERVICE.md +1 -1
- package/docs/USER-GUIDE.zh-CN.md +562 -0
- package/lib/account-usage-query.js +117 -4
- package/lib/assistant-prefs.js +147 -0
- package/lib/auto-config.js +55 -3
- package/lib/backup.js +405 -0
- package/lib/break-reminder.js +133 -0
- package/lib/client.js +57 -11
- package/lib/config.js +94 -5
- package/lib/git-read-bundled-provider.js +12 -3
- package/lib/git-read-service.js +4 -0
- package/lib/host-compat.js +25 -0
- package/lib/http-util.js +6 -2
- package/lib/index.js +987 -74
- package/lib/memory/context.js +76 -0
- package/lib/memory/decay.js +144 -0
- package/lib/memory/extract.js +146 -0
- package/lib/memory/routes.js +198 -0
- package/lib/memory/store.js +667 -0
- package/lib/notify-copy.js +245 -0
- package/lib/permission-guide.js +184 -0
- package/lib/persona-cards.js +362 -0
- package/lib/proactive-material.js +162 -0
- package/lib/proactive.js +369 -0
- package/lib/protected-paths.js +130 -0
- package/lib/protocol.js +35 -0
- package/lib/rate-limit.js +1 -1
- package/lib/relay/connector.js +97 -12
- package/lib/relay/devices.js +14 -0
- package/lib/relay/fingerprint.js +55 -0
- package/lib/relay/identity.js +69 -0
- package/lib/relay/on-demand.js +84 -0
- package/lib/relay/phone.js +87 -12
- package/lib/reminders.js +140 -0
- package/lib/rpc-adapter.js +21 -2
- package/lib/session-rotation.js +198 -0
- package/lib/timeline.js +1 -1
- package/package.json +31 -14
- package/CHANGELOG.md +0 -1336
- package/CONTRIBUTING.md +0 -61
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +0 -432
- package/docs/01-PRD.md +0 -148
- package/docs/02-architecture.md +0 -249
- package/docs/03-api.md +0 -882
- package/docs/04-security.md +0 -110
- package/docs/05-test-cases.md +0 -376
- package/docs/06-install-run.md +0 -349
- package/docs/07-user-manual.md +0 -92
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +0 -86
- package/docs/09-compatibility.md +0 -201
- package/docs/11-remote-relay-guide.md +0 -85
- package/docs/APP-ENCRYPTION-DESCRIPTION.md +0 -50
- package/docs/APP-ENCRYPTION-DESCRIPTION.pdf +0 -0
- package/docs/APP-REVIEW-NOTES.md +0 -135
- package/docs/BRAND-ASSETS.md +0 -142
- package/docs/STORE-LAUNCH.md +0 -305
- package/docs/STORE-LISTING.md +0 -150
package/lib/client.js
CHANGED
|
@@ -151,7 +151,22 @@ window.__ModuleLoader__.load({
|
|
|
151
151
|
// 导出供测试直接调用。
|
|
152
152
|
|
|
153
153
|
var RELAY_API = "/m/api/relay";
|
|
154
|
-
var LINK_LABELS = { online: "已连接", connecting: "连接中…", offline: "离线,自动重试中", idle: "
|
|
154
|
+
var LINK_LABELS = { online: "已连接", connecting: "连接中…", offline: "离线,自动重试中", idle: "待命(配对手机后才连接)" };
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 把 16 位十六进制指纹拆成 4 组 4 位,方便用户逐段和手机屏幕比对。
|
|
158
|
+
*
|
|
159
|
+
* 这里是一份内联实现——`lib/client.js` 被宿主当独立模块打包,不能 import
|
|
160
|
+
* 仓库里的其它文件。权威定义在 `lib/relay/fingerprint.js`,手机端对应
|
|
161
|
+
* `dsh-mobile-app/lib/relay/fingerprint.dart`;三处的分组方式必须逐字一致,
|
|
162
|
+
* 否则用户会看到两个不同的字符串而不敢连接。
|
|
163
|
+
* `test/pairing-fingerprint.test.mjs` 会对着共用模块校验这里的输出。
|
|
164
|
+
*/
|
|
165
|
+
function formatPairingFingerprint(hex) {
|
|
166
|
+
var clean = String(hex || "").toLowerCase().replace(/[^0-9a-f]/g, "");
|
|
167
|
+
if (clean.length !== 16) return String(hex || "");
|
|
168
|
+
return [clean.slice(0, 4), clean.slice(4, 8), clean.slice(8, 12), clean.slice(12, 16)].join(" ");
|
|
169
|
+
}
|
|
155
170
|
|
|
156
171
|
/** 中继连接状态的中文说明。 */
|
|
157
172
|
function relayLinkLabel(link) {
|
|
@@ -186,7 +201,8 @@ window.__ModuleLoader__.load({
|
|
|
186
201
|
" - wss://<你部署的中继域名>",
|
|
187
202
|
].join("\n");
|
|
188
203
|
/**
|
|
189
|
-
* 中继 3.2.6
|
|
204
|
+
* 中继 3.2.6 起默认允许使用(随包补丁与 schema 默认值都指向 wss://dsh.claud.ing),面板正常出现;
|
|
205
|
+
* 电脑只在配对过手机之后才真的去连(没配对时连接状态显示「待命」)。
|
|
190
206
|
* 如果用户显式关闭中继(relay.enabled: false),默认不展示(advertiseWhenOff=false);
|
|
191
207
|
* 要恢复「未启用 → 怎么启用」的引导,把它改成 true。做成对象是为了测试可以切换;生产代码只读。
|
|
192
208
|
*/
|
|
@@ -194,6 +210,7 @@ window.__ModuleLoader__.load({
|
|
|
194
210
|
exports.relayLinkLabel = relayLinkLabel;
|
|
195
211
|
exports.formatCountdown = formatCountdown;
|
|
196
212
|
exports.relativeTime = relativeTime;
|
|
213
|
+
exports.formatPairingFingerprint = formatPairingFingerprint;
|
|
197
214
|
exports.RELAY_SNIPPET = RELAY_SNIPPET;
|
|
198
215
|
exports.relayUi = relayUi;
|
|
199
216
|
|
|
@@ -227,7 +244,8 @@ window.__ModuleLoader__.load({
|
|
|
227
244
|
* 「远程访问」面板:手机不在同一 Wi-Fi 时的连接方式。
|
|
228
245
|
* 未启用 → 说明怎么启用;已启用 → 中继连接状态、生成一次性配对二维码、已配对手机列表(可撤销)。
|
|
229
246
|
*/
|
|
230
|
-
function RelayPanel() {
|
|
247
|
+
function RelayPanel(props) {
|
|
248
|
+
var onCredentialsChanged = props && typeof props.onCredentialsChanged === "function" ? props.onCredentialsChanged : function () {};
|
|
231
249
|
var stateHook = useState({ status: "loading" });
|
|
232
250
|
var st = stateHook[0];
|
|
233
251
|
var setSt = stateHook[1];
|
|
@@ -308,7 +326,7 @@ window.__ModuleLoader__.load({
|
|
|
308
326
|
function (res) {
|
|
309
327
|
setBusy(false);
|
|
310
328
|
setNow(Date.now());
|
|
311
|
-
setPairing({ uri: res.uri, qr: res.qr, expiresAt: res.expiresAt, knownIds: known });
|
|
329
|
+
setPairing({ uri: res.uri, qr: res.qr, fingerprint: res.fingerprint, expiresAt: res.expiresAt, knownIds: known });
|
|
312
330
|
},
|
|
313
331
|
function (err) {
|
|
314
332
|
setBusy(false);
|
|
@@ -317,12 +335,25 @@ window.__ModuleLoader__.load({
|
|
|
317
335
|
);
|
|
318
336
|
}
|
|
319
337
|
function revoke(device) {
|
|
320
|
-
|
|
338
|
+
// T-62:撤销会同时更换中继密钥和(自动生成的)访问口令,确认前把后果说清楚。
|
|
339
|
+
var devices = (st.data && Array.isArray(st.data.devices)) ? st.data.devices : [];
|
|
340
|
+
var others = Math.max(0, devices.length - 1);
|
|
341
|
+
var ok = window.confirm(
|
|
342
|
+
"撤销「" + device.name + "」?\n\n为了让这台手机彻底连不上这台电脑,会同时:\n" +
|
|
343
|
+
"• 更换这台电脑的中继密钥:" + (others > 0 ? "其余 " + others + " 台已配对的手机也会断开,需要重新扫码配对;" : "以后配对要用新的二维码;") + "\n" +
|
|
344
|
+
"• 更换访问口令(自动生成的口令):局域网里连着的手机会断开,需要用新二维码重新连接。如果口令是你在配置里写的,插件不能替你换,请自己更换。"
|
|
345
|
+
);
|
|
321
346
|
if (!ok) return;
|
|
322
347
|
relayCall("/revoke", "POST", { id: device.id }).then(
|
|
323
|
-
function () {
|
|
324
|
-
|
|
348
|
+
function (res) {
|
|
349
|
+
var parts = ["已撤销「" + device.name + "」"];
|
|
350
|
+
if (res && res.repairRequired > 0) parts.push("另有 " + res.repairRequired + " 台手机需要重新扫码配对");
|
|
351
|
+
if (res && res.tokenRotated) parts.push("访问口令已更换,请用下面的新二维码重新连接");
|
|
352
|
+
else if (res && res.tokenRotationSkipped === "configured") parts.push("访问口令是你在配置里写的,请尽快自己更换");
|
|
353
|
+
if (res && res.relayKeyRotated === false) parts.push("中继密钥更换失败,请查看日志");
|
|
354
|
+
toast(parts.join(";"));
|
|
325
355
|
load();
|
|
356
|
+
onCredentialsChanged(); // 口令与二维码已变:重新读取,免得继续显示扫了会 401 的旧码
|
|
326
357
|
},
|
|
327
358
|
function (err) {
|
|
328
359
|
toast("撤销失败:" + String((err && err.message) || err));
|
|
@@ -391,7 +422,13 @@ window.__ModuleLoader__.load({
|
|
|
391
422
|
pairing && countdown
|
|
392
423
|
? [
|
|
393
424
|
jsxRuntime.jsx("img", { src: pairing.qr, alt: "配对二维码", style: { width: 216, height: 216, borderRadius: "12px", background: "#fff", padding: 8 } }, "img"),
|
|
394
|
-
jsxRuntime.jsx("div", { style: mutedStyle, children: "手机 App →
|
|
425
|
+
jsxRuntime.jsx("div", { style: mutedStyle, children: "手机 App → 连接页「粘贴配对链接」粘贴,或直接扫这个码。一次性," + countdown + " 后失效。" }, "t"),
|
|
426
|
+
// 本机公钥指纹:手机配对时会显示同一串数字,用户在这里逐段核对。
|
|
427
|
+
// 没有这一行,手机上那个「去电脑上核对」的提示就无处可核。
|
|
428
|
+
jsxRuntime.jsx("div", { style: { ...mutedStyle, textAlign: "center" }, children: [
|
|
429
|
+
jsxRuntime.jsx("div", { children: "本机指纹(手机上会显示同一串)" }, "l"),
|
|
430
|
+
jsxRuntime.jsx("div", { style: { fontFamily: "monospace", fontSize: "14px", letterSpacing: "1px", color: "#111", userSelect: "all" }, children: formatPairingFingerprint(pairing.fingerprint) }, "f"),
|
|
431
|
+
] }, "fp"),
|
|
395
432
|
jsxRuntime.jsx("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
396
433
|
jsxRuntime.jsx("button", { style: btnStyle, onClick: function () { copyText(pairing.uri); }, children: "复制配对链接" }, "cp"),
|
|
397
434
|
jsxRuntime.jsx("button", { style: btnStyle, onClick: function () { setPairing(null); }, children: "关闭" }, "x"),
|
|
@@ -408,6 +445,11 @@ window.__ModuleLoader__.load({
|
|
|
408
445
|
rows.push(jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "4px 0 2px" }, children: "已配对的手机(" + (data.devices || []).length + ")" }, "dh"));
|
|
409
446
|
if ((data.devices || []).length === 0) rows.push(jsxRuntime.jsx("div", { style: mutedStyle, children: "还没有。点上面的按钮,用手机扫码即可。" }, "none"));
|
|
410
447
|
(data.devices || []).forEach(function (d) {
|
|
448
|
+
// 注意:这里刻意不显示「设备指纹」。
|
|
449
|
+
// 手机配对时核对的是**电脑**的公钥(配对链接里的 pk),
|
|
450
|
+
// 而 d.id 是**手机**公钥的指纹——两者不是同一个东西,
|
|
451
|
+
// 摆在一起会让人以为能互相对照,比不显示更糟。
|
|
452
|
+
// 电脑侧要展示的是自己的公钥指纹,见下面「本机指纹」那一行。
|
|
411
453
|
rows.push(
|
|
412
454
|
jsxRuntime.jsx(
|
|
413
455
|
"div",
|
|
@@ -436,6 +478,10 @@ window.__ModuleLoader__.load({
|
|
|
436
478
|
var state = useState({ status: "loading", urls: [], token: "" });
|
|
437
479
|
var data = state[0];
|
|
438
480
|
var setData = state[1];
|
|
481
|
+
// T-62:撤销设备会更换口令;递增它就重新读取 qr-config(新口令、新二维码)。
|
|
482
|
+
var reloadHook = useState(0);
|
|
483
|
+
var reloadKey = reloadHook[0];
|
|
484
|
+
var setReloadKey = reloadHook[1];
|
|
439
485
|
|
|
440
486
|
useEffect(function () {
|
|
441
487
|
var alive = true;
|
|
@@ -462,7 +508,7 @@ window.__ModuleLoader__.load({
|
|
|
462
508
|
return function () {
|
|
463
509
|
alive = false;
|
|
464
510
|
};
|
|
465
|
-
}, []);
|
|
511
|
+
}, [reloadKey]);
|
|
466
512
|
|
|
467
513
|
if (data.status === "loading") {
|
|
468
514
|
return jsxRuntime.jsx("div", { style: { padding: "20px 0", color: "var(--dsw-alias-label-secondary, #888)" }, children: "加载中…" });
|
|
@@ -500,7 +546,7 @@ window.__ModuleLoader__.load({
|
|
|
500
546
|
lineHeight: "1.6",
|
|
501
547
|
},
|
|
502
548
|
children:
|
|
503
|
-
"⚠️
|
|
549
|
+
"⚠️ 访问口令为空:现在只有这台电脑能连接,手机连不上。要让手机连接,请删掉 cordis.patch.yml 里空的 authToken(默认的 \"@auto\" 会自动生成口令),或打开 lanBridge / 中继,然后重启。",
|
|
504
550
|
}),
|
|
505
551
|
jsxRuntime.jsx("div", {
|
|
506
552
|
style: { display: "flex", flexDirection: "column", alignItems: "center", gap: "10px", padding: "14px 0" },
|
|
@@ -559,7 +605,7 @@ window.__ModuleLoader__.load({
|
|
|
559
605
|
style: { fontSize: "12px", color: "var(--dsw-alias-label-tertiary, #aaa)", marginTop: "6px" },
|
|
560
606
|
children: "二维码包含访问口令,仅在本机显示;请勿截屏转发。App 与手机浏览器(/m 网页)共用同一连接。",
|
|
561
607
|
}),
|
|
562
|
-
jsxRuntime.jsx(RelayPanel, {}),
|
|
608
|
+
jsxRuntime.jsx(RelayPanel, { onCredentialsChanged: function () { setReloadKey(function (k) { return k + 1; }); } }),
|
|
563
609
|
],
|
|
564
610
|
});
|
|
565
611
|
}
|
package/lib/config.js
CHANGED
|
@@ -32,7 +32,9 @@ export const Config = z.object({
|
|
|
32
32
|
/** 移动页挂载路径:单段、以 / 开头。禁止 "/"(会劫持桌面 SPA fallback)。 */
|
|
33
33
|
path: z.string().pattern(/^\/[a-zA-Z0-9_-]+$/).default("/m"),
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* 访问口令。建议 ≥16 字符随机串。
|
|
36
|
+
* 空 = 关闭认证,但**只在服务只有本机可达时**生效(webserver 只听回环,且没有 LAN 桥、trustedHosts、中继);
|
|
37
|
+
* 否则空口令按 `"@auto"` 处理(T-03 / E6:空口令不再把带 shell 权限的 agent 暴露给整个局域网)。
|
|
36
38
|
* 写 `"@auto"`(v3.2.4,随插件自带的 cordis.patch.yml 使用)= 首次启动自动生成强口令并保存到
|
|
37
39
|
* `~/.dsh/mobile-remote/auth-token`,之后复用;启动日志与 DSH 设置页「连接移动端设备」都会显示它。
|
|
38
40
|
*/
|
|
@@ -143,7 +145,7 @@ export const Config = z.object({
|
|
|
143
145
|
/**
|
|
144
146
|
* LAN 桥(v2.9.0):桌面版(dsh-plugin-desktop)强制 webserver 只听回环,手机无法直连;
|
|
145
147
|
* 插件在 DSH 进程内自建第二个 HTTP 监听,把 `${path}` 前缀请求流式转发到回环 webserver。
|
|
146
|
-
* 仅暴露移动端面(不转发 /api 网关、qr-config/qr.png
|
|
148
|
+
* 仅暴露移动端面(不转发 /api 网关、qr-config/qr.png);口令短于 16 字符时拒绝启动(口令为空时按 `@auto` 自动生成,见 authToken)。
|
|
147
149
|
* 默认关闭;启用后手机访问 `http://<电脑局域网IP>:<port>/m`(App 扫码/手动填均可)。
|
|
148
150
|
*
|
|
149
151
|
* `enabled` 除了 true/false,还可写 `"auto"`(v3.2.4,随插件自带的 cordis.patch.yml 使用):
|
|
@@ -160,10 +162,13 @@ export const Config = z.object({
|
|
|
160
162
|
/**
|
|
161
163
|
* 端到端加密中继(v3.3):让手机在**任何网络**下连到这台电脑,手机与电脑都不用装 VPN 软件。
|
|
162
164
|
* 电脑只**出站**连接 `urls` 里的中继(不开任何入站端口);中继只转发密文,看不到内容。
|
|
163
|
-
*
|
|
165
|
+
* `enabled` 默认 true,指向项目公共中继:意思是**允许使用**中继,不是「一启动就连」。
|
|
166
|
+
* **按需连接**:只有配对过手机之后电脑才去连中继(或者刚在桌面「远程访问」里生成了配对码、正等手机来);
|
|
167
|
+
* 全新安装、没配对过手机的电脑不产生任何中继连接。撤销最后一台手机后连接随之断开。
|
|
168
|
+
* 完全不想用中继时设 relay.enabled: false。
|
|
164
169
|
* **开启不改变局域网地址与口令**:电脑仍以原来的地址与 authToken 提供 LAN 直连;中继只是额外的出站连接。
|
|
165
170
|
* 设备用桌面设置页里的一次性二维码配对,可单独撤销。
|
|
166
|
-
* 设计与威胁模型见 docs/
|
|
171
|
+
* 设计与威胁模型见 docs/CONSOLIDATED-DOCUMENTATION.en.md Part 00 §4,中继服务见 relay/。
|
|
167
172
|
*/
|
|
168
173
|
relay: z
|
|
169
174
|
.object({
|
|
@@ -181,7 +186,7 @@ export const Config = z.object({
|
|
|
181
186
|
* 即 approval/request 瀑布 + $events 远程事件通道);旧宿主自动降级 mobile。
|
|
182
187
|
* mobile —— 手机在线时由手机独占应答(v3.1.2 行为),离线交桌面 GUI。外出远程用。
|
|
183
188
|
* desktop —— 一律交给桌面 GUI(手机不弹审批/问询卡)。常驻电脑前、不远程审批用。
|
|
184
|
-
* 桌面端/手机端均无应答时保持超时 fail-close(FAQ「问询/审批弹窗类」+ docs/09 §2.1)。
|
|
189
|
+
* 桌面端/手机端均无应答时保持超时 fail-close(FAQ「问询/审批弹窗类」+ docs/CONSOLIDATED-DOCUMENTATION.en.md Part 09 §2.1)。
|
|
185
190
|
*/
|
|
186
191
|
approvalMode: z
|
|
187
192
|
.union([z.const("both"), z.const("mobile"), z.const("desktop")])
|
|
@@ -210,4 +215,88 @@ export const Config = z.object({
|
|
|
210
215
|
* 会响一次 —— 纯噪音。与 zen-remote 的同名策略一致(它的默认值也是 5 秒)。
|
|
211
216
|
*/
|
|
212
217
|
pushApprovalGraceMs: z.number().min(0).max(60_000).default(5_000),
|
|
218
|
+
/**
|
|
219
|
+
* 长期记忆库(v3.3.0,T7)。默认关闭:它会往磁盘写用户的原话片段,
|
|
220
|
+
* 必须由用户显式打开,不能在升级时悄悄开始记录。
|
|
221
|
+
*
|
|
222
|
+
* 打开后数据放在 `<状态目录>/memory.db`(SQLite),**只在本机**,不上传任何服务器;
|
|
223
|
+
* 入库前自动脱敏(手机号 / 证件号 / 密钥 / 长数字串)。生活模式按 scope 硬过滤,
|
|
224
|
+
* 看不到工作记忆——那是隐私边界,靠 SQL 条件实现,不靠提示词。
|
|
225
|
+
*/
|
|
226
|
+
memory: z
|
|
227
|
+
.object({
|
|
228
|
+
enabled: z.boolean().default(false),
|
|
229
|
+
})
|
|
230
|
+
.default({ enabled: false }),
|
|
231
|
+
/**
|
|
232
|
+
* 主动汇报与通知的角色口吻(v3.3.0,T9/T10)。
|
|
233
|
+
*
|
|
234
|
+
* `colleague` —— 克制的同事:说事实、说下一步,不寒暄(默认)
|
|
235
|
+
* `character` —— 有性格的角色:可以带一点情绪与口癖,但事实部分与前者完全一致
|
|
236
|
+
*
|
|
237
|
+
* 人格只换说法,不改变事实与判断——两套人格回答同一个问题时结论必须一样。
|
|
238
|
+
*/
|
|
239
|
+
persona: z.union([z.const("colleague"), z.const("character")]).default("colleague"),
|
|
240
|
+
/**
|
|
241
|
+
* 安静时段(v3.3.0,T12)。默认 23:30–08:30,按**电脑本地时间**判断。
|
|
242
|
+
*
|
|
243
|
+
* 只拦「任务完成」与「余额提醒」这两类;「等你回答」与「失败」不受影响——
|
|
244
|
+
* 它们卡在那里等人,憋到早上才是真的坏了。
|
|
245
|
+
* 写非法时间(如 `25:00`)时不静默:宁可多吵一次,也不要因为配置写错把通知全吞掉。
|
|
246
|
+
*/
|
|
247
|
+
quietHours: z
|
|
248
|
+
.object({
|
|
249
|
+
start: z.string().default("23:30"),
|
|
250
|
+
end: z.string().default("08:30"),
|
|
251
|
+
})
|
|
252
|
+
.default({ start: "23:30", end: "08:30" }),
|
|
253
|
+
/**
|
|
254
|
+
* 工作 / 生活模式(v3.3.0,T9)。`work` 同时加载工作记忆与长期记忆;
|
|
255
|
+
* `life` **只**加载长期记忆(工作记忆在检索层就被过滤掉)。
|
|
256
|
+
*/
|
|
257
|
+
mode: z.union([z.const("work"), z.const("life")]).default("work"),
|
|
258
|
+
/**
|
|
259
|
+
* 主动消息调度器(v3.4.0,P0-5/P0-6)。
|
|
260
|
+
*
|
|
261
|
+
* 与推送的区别:推送是"任务状态变了,告诉你一声";主动消息是"它自己想起来要说话"。
|
|
262
|
+
* 后者必须有上限与闸门,否则很快变成骚扰,用户第一件事就是永久关掉它。
|
|
263
|
+
*
|
|
264
|
+
* `enabled` 默认 **false**:功能存在但默认不自己开口。用户没答应过"你可以主动找我",
|
|
265
|
+
* 就不该在升级后突然开始收到消息——与记忆库默认关闭同理。
|
|
266
|
+
*/
|
|
267
|
+
proactive: z
|
|
268
|
+
.object({
|
|
269
|
+
enabled: z.boolean().default(false),
|
|
270
|
+
/** 每日上限,按**电脑本地日历日**算;0 等于关闭。取值时按整数截断。 */
|
|
271
|
+
dailyLimit: z.number().min(0).max(20).default(3),
|
|
272
|
+
/** 两条之间至少隔多久(毫秒),默认 90 分钟。 */
|
|
273
|
+
minGapMs: z.number().min(0).default(90 * 60_000),
|
|
274
|
+
/** tick 间隔(毫秒),默认 60 秒;每次 tick 重算,不依赖长定时器。 */
|
|
275
|
+
tickMs: z.number().min(1_000).default(60_000),
|
|
276
|
+
/**
|
|
277
|
+
* 用户这么久没有任何操作才算「空闲」,才可能收到主动消息(毫秒,默认 30 分钟,§5.7)。
|
|
278
|
+
* T-32 起材料只来自真实的事:到期的提醒(/api/reminders)、在等你的审批或问题、
|
|
279
|
+
* 回到手机时的任务结果、每天一次的早间概览;3 天没回应就少说,7 天没回应就停。
|
|
280
|
+
*/
|
|
281
|
+
activeWindowMs: z.number().min(0).default(30 * 60_000),
|
|
282
|
+
})
|
|
283
|
+
.default({
|
|
284
|
+
enabled: false,
|
|
285
|
+
dailyLimit: 3,
|
|
286
|
+
minGapMs: 90 * 60_000,
|
|
287
|
+
tickMs: 60_000,
|
|
288
|
+
activeWindowMs: 30 * 60_000,
|
|
289
|
+
}),
|
|
290
|
+
/**
|
|
291
|
+
* Break reminder (T-15, plan §5.7, D10). After 2 hours of continuous activity from any client
|
|
292
|
+
* (a gap of 10 minutes or more starts the count again) the PC sends one reminder: an SSE
|
|
293
|
+
* `break/reminder` event for the app, plus a push when no app is connected. At most once per
|
|
294
|
+
* 2 hours, never in quiet hours. On by default; `enabled: false` turns it off for this PC,
|
|
295
|
+
* and the app's own setting (`breakReminder` in `/api/assistant`) turns it off for the user.
|
|
296
|
+
*/
|
|
297
|
+
breakReminder: z
|
|
298
|
+
.object({
|
|
299
|
+
enabled: z.boolean().default(true),
|
|
300
|
+
})
|
|
301
|
+
.default({ enabled: true }),
|
|
213
302
|
});
|
|
@@ -2,6 +2,7 @@ import { constants as fsConstants } from "node:fs";
|
|
|
2
2
|
import { realpath, open, lstat } from "node:fs/promises";
|
|
3
3
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
|
+
import { isProtectedFile, isProtectedPath } from "./protected-paths.js";
|
|
5
6
|
|
|
6
7
|
const UNTRACKED_PREVIEW_MAX = 512 * 1024;
|
|
7
8
|
const SIGNATURE_SAMPLE_BYTES = 4096;
|
|
@@ -10,9 +11,13 @@ function sameRegularFile(expected, opened) {
|
|
|
10
11
|
return expected.isFile() && opened.isFile() && expected.dev === opened.dev && expected.ino === opened.ino;
|
|
11
12
|
}
|
|
12
13
|
async function readPrefix(path, maximum, expected) {
|
|
14
|
+
// T-62 fix: never read the DSH home's keys or the plugin's state, by any name or link.
|
|
15
|
+
if (isProtectedPath(path)) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
|
|
13
16
|
const handle = await open(path, readOnlyNoFollow);
|
|
14
17
|
try {
|
|
15
|
-
|
|
18
|
+
const opened = await handle.stat();
|
|
19
|
+
if (isProtectedFile(opened)) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
|
|
20
|
+
if (!sameRegularFile(expected, opened)) throw new Error("file changed while opening preview");
|
|
16
21
|
const buffer = Buffer.alloc(maximum + 1);
|
|
17
22
|
const { bytesRead } = await handle.read(buffer, 0, maximum + 1, 0);
|
|
18
23
|
return { bytes: buffer.subarray(0, bytesRead), truncated: bytesRead > maximum };
|
|
@@ -46,7 +51,8 @@ export function createBundledGitReadProvider(ctx) {
|
|
|
46
51
|
const get = (name) => {
|
|
47
52
|
try { return ctx.get?.(name); } catch { return undefined; }
|
|
48
53
|
};
|
|
49
|
-
|
|
54
|
+
// 真实 cordis 的 ctx 读没声明的属性会抛错,所以兜底读取也要 try。
|
|
55
|
+
const subprocess = () => get("subprocess") ?? (() => { try { return ctx.subprocess; } catch { return undefined; } })();
|
|
50
56
|
const workspaces = () => (get("workspaceRegistry")?.list?.() ?? [])
|
|
51
57
|
.map((entry) => entry?.path).filter((path) => typeof path === "string" && path !== "");
|
|
52
58
|
const inside = (child, parent) => {
|
|
@@ -221,7 +227,10 @@ export function createBundledGitReadProvider(ctx) {
|
|
|
221
227
|
const { bytes, truncated } = await readPrefix(target, UNTRACKED_PREVIEW_MAX, info);
|
|
222
228
|
const binary = bytes.includes(0);
|
|
223
229
|
return { diff: binary ? "" : bytes.toString("utf8"), binary, truncated, additions: null, deletions: null, ...(binary ? { notice: "binary preview omitted" } : {}) };
|
|
224
|
-
} catch
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error?.code === "path-protected") throw error;
|
|
232
|
+
return { diff: "", binary: false, additions: 0, deletions: 0, notice: "unavailable" };
|
|
233
|
+
}
|
|
225
234
|
}
|
|
226
235
|
return { diff: await run(root, args, true), binary: false, additions: null, deletions: null };
|
|
227
236
|
},
|
package/lib/git-read-service.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { basename, isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { realpath } from "node:fs/promises";
|
|
4
4
|
import { createBundledGitReadProvider } from "./git-read-bundled-provider.js";
|
|
5
|
+
import { isProtectedPath } from "./protected-paths.js";
|
|
5
6
|
|
|
6
7
|
const MAX_GRAPH_TIPS = 5;
|
|
7
8
|
|
|
@@ -130,6 +131,9 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
130
131
|
async preview(sessionId, repositoryId, { kind, snapshotId, path, oid } = {}) {
|
|
131
132
|
const authorized = await binding(sessionId, repositoryId);
|
|
132
133
|
if (!safeFilePath(path) || !["staged", "unstaged", "untracked", "commit"].includes(kind)) throw failure("preview-invalid", 400);
|
|
134
|
+
// T-62 fix: a repository can contain the DSH home (a dotfiles repo). Its keys and the
|
|
135
|
+
// plugin's state are never previewed, whatever the kind (worktree, staged, untracked, commit).
|
|
136
|
+
if (isProtectedPath(resolve(authorized.root, path))) throw failure("path-protected", 403, "this file holds DSH's or the plugin's keys and data");
|
|
133
137
|
const reader = createBundledGitReadProvider(ctx);
|
|
134
138
|
let raw;
|
|
135
139
|
if (kind === "commit") {
|
package/lib/host-compat.js
CHANGED
|
@@ -115,6 +115,31 @@ export const jobsCallerFor = (jobs, agent, sessionId) => {
|
|
|
115
115
|
return typeof id === "string" && id !== "" ? id.replace(/^session:/, "") : undefined;
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Live top-level agents (not subagents), in registration order.
|
|
120
|
+
*
|
|
121
|
+
* A host that still has `AgentRegistry.roots()` (DSH ≤ 0.2.2-rc.1) knows its own runtime
|
|
122
|
+
* tree, so its answer is used as is: filtering `list()` there would count a subagent whose
|
|
123
|
+
* session header lacks `origin` as a root. DSH 0.2.2-rc.2 removed `roots()` (upgrade guide
|
|
124
|
+
* `v0.2.1-rc.3/subagent-runtime-ownership`); there only `get()` and `list()` remain, and the
|
|
125
|
+
* migration is to filter `list()` by `session.header.origin !== "subagent"`. User forks keep
|
|
126
|
+
* `parentSession`, so they count as top-level, as they did under `roots()`. Anything else yields [].
|
|
127
|
+
*/
|
|
128
|
+
export const liveRootAgents = (agents) => {
|
|
129
|
+
if (typeof agents?.roots === "function") {
|
|
130
|
+
const roots = agents.roots();
|
|
131
|
+
return Array.isArray(roots) ? [...roots] : [];
|
|
132
|
+
}
|
|
133
|
+
if (typeof agents?.list === "function") {
|
|
134
|
+
const all = agents.list();
|
|
135
|
+
return Array.isArray(all) ? all.filter((agent) => agent?.session?.header?.origin !== "subagent") : [];
|
|
136
|
+
}
|
|
137
|
+
return [];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** The first live top-level agent, or undefined. */
|
|
141
|
+
export const firstRootAgent = (agents) => liveRootAgents(agents)[0];
|
|
142
|
+
|
|
118
143
|
/**
|
|
119
144
|
* 单项宿主能力的状态(ADR 0017 要求的三态报告)。仅报"服务在不在"不够:
|
|
120
145
|
* 本次四处不兼容**全部**是"服务在、调用不报错、语义已变",两分法看不见它们。
|
package/lib/http-util.js
CHANGED
|
@@ -34,18 +34,22 @@ export const readBody = (req, limit = 64 * 1024) =>
|
|
|
34
34
|
new Promise((resolve, reject) => {
|
|
35
35
|
let size = 0;
|
|
36
36
|
const chunks = [];
|
|
37
|
-
|
|
37
|
+
const onData = (chunk) => {
|
|
38
38
|
size += chunk.length;
|
|
39
39
|
if (size > limit) {
|
|
40
40
|
reject(Object.assign(new Error("body too large"), { status: 413 }));
|
|
41
41
|
// v3.0.0 修复:超限先停读并让 handler 回 413——此前先 req.destroy()
|
|
42
42
|
// 会把连接直接掐断,客户端看到的是"连接意外关闭/连接重置"而非 413
|
|
43
43
|
// (592KB 图片上传即此症状:上游看到连接被切断 → 桥回 502 bridge-unavailable)
|
|
44
|
+
// T-55: stop listening too, so the server can discard the rest after an early 413
|
|
45
|
+
// without this handler pausing the request again on every chunk.
|
|
46
|
+
req.off("data", onData);
|
|
44
47
|
req.pause();
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
chunks.push(chunk);
|
|
48
|
-
}
|
|
51
|
+
};
|
|
52
|
+
req.on("data", onData);
|
|
49
53
|
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
50
54
|
req.on("error", reject);
|
|
51
55
|
// review:客户端断开且不触发 error 时也要 settle,避免 handler 悬挂
|