dsh-mobile-plugin 0.5.33 → 0.5.35
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 +17 -2
- package/dsh-mobile-credentials/lib/credentials.js +49 -2
- package/extensions/README.md +25 -21
- package/host.js +16 -1
- package/lib/git/pr.js +375 -0
- package/lib/git/read.js +1 -0
- package/lib/host-capabilities.cjs +67 -0
- package/lib/http/routing.js +25 -0
- package/lib/impl.js +34 -26
- package/lib/mirror/history-blob.cjs +184 -0
- package/lib/mirror/pusher.cjs +276 -1
- package/lib/mobile/approval-facts.js +439 -0
- package/lib/mobile/approval-memory.js +199 -0
- package/lib/mobile/approvals.js +596 -30
- package/lib/mobile/auto-review-log.js +160 -0
- package/lib/mobile/auto-review.js +172 -0
- package/lib/mobile/credential-upgrade.js +14 -0
- package/lib/mobile/device-permissions.js +86 -0
- package/lib/mobile/directory-browse.js +23 -8
- package/lib/mobile/events.js +9 -1
- package/lib/mobile/extension-catalog.js +106 -44
- package/lib/mobile/extension-data.js +6 -0
- package/lib/mobile/file-ops.js +89 -76
- package/lib/mobile/git.js +108 -2
- package/lib/mobile/live-steps.js +107 -4
- package/lib/mobile/mail.js +621 -0
- package/lib/mobile/monitor.js +6 -0
- package/lib/mobile/notification-prefs.js +205 -0
- package/lib/mobile/pairing.js +15 -2
- package/lib/mobile/permissions.js +433 -0
- package/lib/mobile/project-write-queue.js +115 -0
- package/lib/mobile/project-writes.js +61 -0
- package/lib/mobile/push-notify.js +293 -13
- package/lib/mobile/questions.js +20 -3
- package/lib/mobile/recent-failures.js +48 -0
- package/lib/mobile/relay-control.js +5 -0
- package/lib/mobile/session-cache.js +50 -0
- package/lib/mobile/session-last-turn.js +24 -22
- package/lib/mobile/session-new.js +205 -0
- package/lib/mobile/session-send.js +0 -1
- package/lib/mobile/sessions.js +12 -84
- package/lib/mobile/skill-write.js +549 -0
- package/lib/mobile/stats-collect.cjs +33 -3
- package/lib/mobile/stats-ledger.cjs +39 -2
- package/lib/mobile/stream.js +24 -3
- package/lib/mobile/supervisor-broadcast.js +58 -11
- package/lib/mobile/supervisor-tools.js +1 -1
- package/lib/mobile/third-party-extensions.js +158 -0
- package/lib/mobile/uploads.js +30 -14
- package/lib/mobile/worktree-isolation.js +479 -0
- package/lib/mobile/worktree-lifecycle.js +79 -0
- package/lib/p2p/wiring.cjs +41 -16
- package/lib/panel/index.html +15 -15
- package/lib/read-receipt.cjs +89 -5
- package/lib/relay/core.js +25 -1
- package/lib/relay/lan-proxy.js +6 -1
- package/lib/relay/preview.js +21 -1
- package/lib/relay/protocol.js +1 -0
- package/lib/relay/status.js +6 -0
- package/lib/relay/tunnel-forwarder.cjs +178 -0
- package/lib/routes/control-plane.js +35 -1
- package/lib/routes/mobile-api.js +105 -52
- package/lib/shared/via-header.js +15 -2
- package/lib/sidecar-facade-worker.cjs +15 -2
- package/lib/sidecar-facade.cjs +5 -0
- package/lib/tailcat/host-process.cjs +1 -1
- package/lib/tailcat/ingress.cjs +2 -2
- package/lib/tailcat/wiring.cjs +34 -13
- package/package.json +11 -3
- package/assets/pets/README.md +0 -9
- package/assets/pets/deepy-whale/attention.gif +0 -0
- package/assets/pets/deepy-whale/done.gif +0 -0
- package/assets/pets/deepy-whale/error.gif +0 -0
- package/assets/pets/deepy-whale/idle.gif +0 -0
- package/assets/pets/deepy-whale/pack.json +0 -54
- package/assets/pets/deepy-whale/sleeping.gif +0 -0
- package/assets/pets/deepy-whale/working-3.gif +0 -0
- package/assets/pets/deepy-whale/working.gif +0 -0
- package/knowledge/apps/alipay.md +0 -30
- package/knowledge/apps/android-settings.md +0 -30
- package/knowledge/apps/baijiahao.md +0 -30
- package/knowledge/apps/bilibili.md +0 -31
- package/knowledge/apps/boss-zhipin.md +0 -32
- package/knowledge/apps/dedao.md +0 -33
- package/knowledge/apps/douyin.md +0 -32
- package/knowledge/apps/feishu.md +0 -35
- package/knowledge/apps/gmail.md +0 -33
- package/knowledge/apps/jike.md +0 -31
- package/knowledge/apps/kuaishou.md +0 -34
- package/knowledge/apps/linkedin.md +0 -33
- package/knowledge/apps/qqmail.md +0 -30
- package/knowledge/apps/taobao.md +0 -33
- package/knowledge/apps/telegram.md +0 -27
- package/knowledge/apps/toutiao.md +0 -32
- package/knowledge/apps/uber-eats.md +0 -26
- package/knowledge/apps/uber.md +0 -27
- package/knowledge/apps/wechat.md +0 -33
- package/knowledge/apps/weibo.md +0 -31
- package/knowledge/apps/whatsapp.md +0 -27
- package/knowledge/apps/x.md +0 -32
- package/knowledge/apps/xiaohongshu.md +0 -30
- package/knowledge/apps/zhihu.md +0 -31
- package/knowledge/sites/bilibili.com/SITE.md +0 -50
- package/knowledge/sites/bilibili.com/references/view-fields.md +0 -17
- package/knowledge/sites/github.com/SITE.md +0 -51
- package/knowledge/sites/github.com/references/repo-fields.md +0 -13
- package/knowledge/sites/x.com/SITE.md +0 -47
- package/knowledge/sites/xiaohongshu.com/SITE.md +0 -48
- package/knowledge/sites/xiaohongshu.com/references/note-fields.md +0 -18
- package/knowledge/sites/youtube.com/SITE.md +0 -49
- package/knowledge/sites/youtube.com/references/innertube-fields.md +0 -14
- package/knowledge/sites/zhihu.com/SITE.md +0 -47
- package/knowledge/sites/zhihu.com/references/api-fields.md +0 -21
- package/lib/mobile/pet-tools.js +0 -261
- package/lib/mobile/pets.js +0 -755
- package/lib/mobile/phone/access.js +0 -85
- package/lib/mobile/phone/binding.js +0 -247
- package/lib/mobile/phone/confirm.js +0 -189
- package/lib/mobile/phone/evidence.js +0 -228
- package/lib/mobile/phone/gate.js +0 -290
- package/lib/mobile/phone/grounding.js +0 -314
- package/lib/mobile/phone/guard.js +0 -465
- package/lib/mobile/phone/index.js +0 -83
- package/lib/mobile/phone/irreversible.js +0 -226
- package/lib/mobile/phone/knowledge-tools.js +0 -665
- package/lib/mobile/phone/learn.js +0 -329
- package/lib/mobile/phone/pacing.js +0 -173
- package/lib/mobile/phone/redact.js +0 -237
- package/lib/mobile/phone/risk.js +0 -95
- package/lib/mobile/phone/route-hint.js +0 -164
- package/lib/mobile/phone/routes-memory.js +0 -133
- package/lib/mobile/phone/routes.js +0 -279
- package/lib/mobile/phone/service.js +0 -500
- package/lib/mobile/phone/site-commands.js +0 -271
- package/lib/mobile/phone/step-summary.js +0 -201
- package/lib/mobile/phone/stop-summary.js +0 -235
- package/lib/mobile/phone/tool-groups.js +0 -125
- package/lib/mobile/phone/tools.js +0 -2282
- package/lib/mobile/phone/untrusted.js +0 -65
- package/lib/mobile/phone-knowledge.js +0 -317
- package/lib/mobile/wechat-tools.js +0 -257
- package/lib/mobile/wechat.js +0 -514
package/lib/mirror/pusher.cjs
CHANGED
|
@@ -19,14 +19,42 @@ const { stableRevision } = require('../shared/list-revision.js');
|
|
|
19
19
|
const { dshHome } = require('../shared/paths.js');
|
|
20
20
|
const { listSignal: sharedListSignal } = require('../shared/list-signal.js');
|
|
21
21
|
const { sessionSignal: sharedSessionSignal } = require('../shared/session-signal.js');
|
|
22
|
-
const { dropSessionListCache } = require('../mobile/session-cache.js');
|
|
22
|
+
const { dropSessionListCache, deletedSessionIdsOf } = require('../mobile/session-cache.js');
|
|
23
23
|
const { observeCompletionEvent } = require('../mobile/completion.js');
|
|
24
24
|
const { observeAutoContinue } = require('../mobile/auto-continue.js');
|
|
25
25
|
const { lastTurnOf } = require('../mobile/session-last-turn.js');
|
|
26
|
+
const {
|
|
27
|
+
FILE_MAX_PLAIN_BYTES,
|
|
28
|
+
isBlobEligible,
|
|
29
|
+
digestListOf,
|
|
30
|
+
sessionUpdatedAt,
|
|
31
|
+
messagesBlobFingerprint,
|
|
32
|
+
buildMessagesBlobPut,
|
|
33
|
+
collectFileBlobSources,
|
|
34
|
+
statFileSource,
|
|
35
|
+
fileBlobFingerprint,
|
|
36
|
+
readFileSource,
|
|
37
|
+
buildFileBlobPut,
|
|
38
|
+
} = require('./history-blob.cjs');
|
|
26
39
|
|
|
27
40
|
/** 后台循环每个 tick 补推一个冷会话,保证没人动的会话镜像也不长期不更新。 */
|
|
28
41
|
const HIGH_PRIORITY_WINDOW_MS = 5 * 60 * 1000;
|
|
29
42
|
const BG_TICK_INTERVAL_MS = 500;
|
|
43
|
+
/**
|
|
44
|
+
* 每轮最多推几条历史 blob:正文 6 条、文件 2 条,合计 8。
|
|
45
|
+
*
|
|
46
|
+
* 一轮镜像 tick 里塞几百条 `blobPut` 会把隧道写满、把镜像自己的推送挤在后面,而 blob 是
|
|
47
|
+
* 「离线兜底」,慢一轮没人看得出来。超出的留给下一轮:没记指纹的那几条一定还会重试。
|
|
48
|
+
* 两档分开配额(见 pushHistoryBlobs):共用一条计数器时,每轮都在变的那几个会话能把
|
|
49
|
+
* 配额吃光,文件永远轮不到。
|
|
50
|
+
*/
|
|
51
|
+
const MAX_BLOB_MESSAGE_FRAMES_PER_ROUND = 6;
|
|
52
|
+
const MAX_BLOB_FILE_FRAMES_PER_ROUND = 2;
|
|
53
|
+
/** creds-only 更新的每批条数(`cipher` 空串,只改中转那份鉴权名单)。 */
|
|
54
|
+
const MAX_CREDS_ONLY_BATCH = 32;
|
|
55
|
+
/** 一条 `blobDelete` 帧最多带几个 key(中转对单帧体积也有上限)。 */
|
|
56
|
+
const MAX_DELETE_KEYS_PER_FRAME = 64;
|
|
57
|
+
|
|
30
58
|
/**
|
|
31
59
|
* 没人看的时候,后台 tick 降到这个节拍。
|
|
32
60
|
*
|
|
@@ -80,6 +108,14 @@ function createMirrorPusher(deps) {
|
|
|
80
108
|
* 比对。不传就按「一份都没有」处理:镜像照推,只是中转认不出任何缓存读者。
|
|
81
109
|
*/
|
|
82
110
|
const credentialDigests = typeof deps.credentialDigests === 'function' ? deps.credentialDigests : () => [];
|
|
111
|
+
/**
|
|
112
|
+
* 实例历史密钥(HK)的取值器(`relay/core.js` 的 `ensureHistoryKey` 形态)。
|
|
113
|
+
*
|
|
114
|
+
* 不传就当作「没有 HK」:这时一条 blob 都不推,转发行为与加这个功能之前一字不差。
|
|
115
|
+
* **绝不在这里生成密钥** —— 生成/落盘是 `relay.json` 单一真源的事(core.ensureHistoryKey),
|
|
116
|
+
* 推送路径只读不写,免得一次镜像 tick 顺手改了配置。
|
|
117
|
+
*/
|
|
118
|
+
const getHistoryKey = typeof deps.getHistoryKey === 'function' ? deps.getHistoryKey : () => '';
|
|
83
119
|
const hasAudience = () => {
|
|
84
120
|
if (listSignal.watching()) return true;
|
|
85
121
|
if (!lastMobileAt) return true;
|
|
@@ -222,6 +258,237 @@ function createMirrorPusher(deps) {
|
|
|
222
258
|
}
|
|
223
259
|
};
|
|
224
260
|
|
|
261
|
+
/**
|
|
262
|
+
* 历史 blob 的本地账:**只记真的推成功的那一份**。
|
|
263
|
+
*
|
|
264
|
+
* 失败的那条不记指纹,下一轮还会重试;记了就等于把它永久判成「内容没变」。HK 换过
|
|
265
|
+
* (吊销全部时会轮换)也整份清空,下一轮按新钥重封重推。
|
|
266
|
+
*/
|
|
267
|
+
const pushedMessageBlobs = new Map(); // sessionId -> { fingerprint }
|
|
268
|
+
const pushedFileBlobs = new Map(); // fileKey -> { fingerprint, sessionId, skipped? }
|
|
269
|
+
let blobHistoryKey = null;
|
|
270
|
+
let blobCredsKey = null;
|
|
271
|
+
// 同一条失败只记一次日志:每轮刷同一行会把真故障淹掉。成功之后清掉,下次真再坏还能报一次。
|
|
272
|
+
const blobLogOnce = new Set();
|
|
273
|
+
const errorText = (error) => (error instanceof Error ? error.message : String(error));
|
|
274
|
+
const blobLog = (tag, message) => {
|
|
275
|
+
if (blobLogOnce.has(tag)) return;
|
|
276
|
+
blobLogOnce.add(tag);
|
|
277
|
+
process.stderr.write(`[dsh-mobile-plugin] history blob ${tag}: ${message}\n`);
|
|
278
|
+
};
|
|
279
|
+
const blobLogClear = (tag) => { blobLogOnce.delete(tag); };
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* blob 引擎的几段能力是不是都在。
|
|
283
|
+
*
|
|
284
|
+
* `history-blob.cjs` 今天只导出了信封与候选那几样,正文 / 文件两条路的辅助函数(`digestListOf`、
|
|
285
|
+
* `messagesBlobFingerprint`、`buildMessagesBlobPut`、`collectFileBlobSources` 等)在那边还没有
|
|
286
|
+
* 实现(文件 scope 的生产者按 decisions 里 d2838e82 那条是「今天没有」)。照写的样子调用会拿到
|
|
287
|
+
* `undefined`,第一发就抛 TypeError,被外层的单行诊断吞掉 —— 每一轮每个 tick 都白跑一趟。
|
|
288
|
+
* 所以这里先问一句能力在不在:缺哪段就跳过哪段,一轮只留一行诊断,别刷屏。
|
|
289
|
+
*
|
|
290
|
+
* 这批解构是提交 8722b77f 引进的:那一版把这里从「只取 buildBlobPuts」改成解构十几个符号,
|
|
291
|
+
* 而 history-blob.cjs 一个都没跟着加。从那一次落地起,blob 推送就一直是全哑的。
|
|
292
|
+
*/
|
|
293
|
+
const hasFns = (...fns) => fns.every((fn) => typeof fn === 'function');
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 缺能力时统一给一句人能照做的话。
|
|
297
|
+
*
|
|
298
|
+
* 只打变量名(`digestListOf is not a function`)读的人既不知道哪条路坏了、也不知道是不是
|
|
299
|
+
* 自己该去修 —— 但这条路的实情是「镜像侧那半边还没实现」,不是设备 / 网络 / 凭据的问题。
|
|
300
|
+
* 所以这句要直接说清 skip 了哪两段、以及它意味着什么,一轮只记一次(`blobLog` 自带去重)。
|
|
301
|
+
*/
|
|
302
|
+
const noteBlobGaps = (canMessages, canFiles) => {
|
|
303
|
+
const skipped = [!canMessages ? '正文' : '', !canFiles ? '文件' : ''].filter(Boolean);
|
|
304
|
+
if (skipped.length === 0) return;
|
|
305
|
+
blobLog(
|
|
306
|
+
'impl-missing',
|
|
307
|
+
`镜像侧的历史 blob 实现尚未就绪(mirror/history-blob.cjs 未提供 digestListOf 等导出,见 8722b77f),${skipped.join(' / ')} blob 整段跳过:离线时这部分内容拿不到,在线路径不受影响`,
|
|
308
|
+
);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 会话真的被删掉之后,把中转上它的 blob 一起删掉。
|
|
313
|
+
*
|
|
314
|
+
* 判据用本进程那本「已删会话」账(`deletedSessionIdsOf`):移动端唯一的删除语义是
|
|
315
|
+
* 「清理所有已归档」,那条路在排进待删队列的同时就把 id 记进了这本账(见
|
|
316
|
+
* archive-clean.js),宿主下次启动删日志时也会记。**不用「清单里没有」当判据**:
|
|
317
|
+
* 归档中的会话本来就不在默认清单里,而它日志还在、取消归档后手机还要能离线读;
|
|
318
|
+
* 宿主降级读偶尔漏几行也不该把离线正文删掉。工作区快照也不再下发归档集合
|
|
319
|
+
* (见 workspaces.js 的说明),拿不到的东西不能当门。
|
|
320
|
+
*
|
|
321
|
+
* `scope=file` 的 key 按当初记账的归属会话一起删。
|
|
322
|
+
*/
|
|
323
|
+
const deleteRemovedSessionBlobs = async (sidecar) => {
|
|
324
|
+
if (typeof sidecar.deleteBlobs !== 'function') return;
|
|
325
|
+
const deleted = deletedSessionIdsOf(ctx);
|
|
326
|
+
if (!deleted || deleted.size === 0) return;
|
|
327
|
+
const goneMessages = [...pushedMessageBlobs.keys()].filter((key) => deleted.has(key));
|
|
328
|
+
if (goneMessages.length === 0) return;
|
|
329
|
+
const goneSet = new Set(goneMessages);
|
|
330
|
+
const goneFiles = [...pushedFileBlobs.entries()]
|
|
331
|
+
.filter(([, rec]) => rec && goneSet.has(rec.sessionId))
|
|
332
|
+
.map(([key]) => key);
|
|
333
|
+
for (let i = 0; i < goneMessages.length; i += MAX_DELETE_KEYS_PER_FRAME) {
|
|
334
|
+
const keys = goneMessages.slice(i, i + MAX_DELETE_KEYS_PER_FRAME);
|
|
335
|
+
try {
|
|
336
|
+
await sidecar.deleteBlobs({ scope: 'messages', keys });
|
|
337
|
+
for (const key of keys) pushedMessageBlobs.delete(key);
|
|
338
|
+
blobLogClear(`delete:messages:${keys[0]}`);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
blobLog(`delete:messages:${keys[0]}`, errorText(error));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (let i = 0; i < goneFiles.length; i += MAX_DELETE_KEYS_PER_FRAME) {
|
|
344
|
+
const keys = goneFiles.slice(i, i + MAX_DELETE_KEYS_PER_FRAME);
|
|
345
|
+
try {
|
|
346
|
+
await sidecar.deleteBlobs({ scope: 'file', keys });
|
|
347
|
+
for (const key of keys) pushedFileBlobs.delete(key);
|
|
348
|
+
blobLogClear(`delete:file:${keys[0]}`);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
blobLog(`delete:file:${keys[0]}`, errorText(error));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 把本次镜像里该进 blob 的内容封好,经同一条隧道发 `blobPut`;真的被删掉的会话发
|
|
357
|
+
* `blobDelete`。
|
|
358
|
+
*
|
|
359
|
+
* 与镜像推送绑定但**互不拖累**:没有 HK、没有 `pushBlob` 通道、或某一条发送失败,都只留
|
|
360
|
+
* 一行诊断,绝不影响已经成功的镜像推送。
|
|
361
|
+
*
|
|
362
|
+
* 每轮的顺序与限流:删除 → creds-only → 正文 → 文件,逐条串行;正文最多
|
|
363
|
+
* `MAX_BLOB_MESSAGE_FRAMES_PER_ROUND` 条、文件最多 `MAX_BLOB_FILE_FRAMES_PER_ROUND` 条,
|
|
364
|
+
* 超出的下一轮再推。
|
|
365
|
+
*/
|
|
366
|
+
const pushHistoryBlobs = async (payload, creds) => {
|
|
367
|
+
// blob 是加法:它自己炸了不许把一次已经成功的镜像推送翻成失败(调用方会把异常记成
|
|
368
|
+
// 推送失败)。所以整趟兜一层,失败只留一行诊断。
|
|
369
|
+
try {
|
|
370
|
+
await pushHistoryBlobsUnlocked(payload, creds);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
blobLog('round', errorText(error));
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const pushHistoryBlobsUnlocked = async (payload, creds) => {
|
|
377
|
+
let hk = '';
|
|
378
|
+
try { hk = getHistoryKey() || ''; } catch { hk = ''; }
|
|
379
|
+
if (!hk) return;
|
|
380
|
+
const sidecar = getSidecar();
|
|
381
|
+
if (!sidecar || typeof sidecar.pushBlob !== 'function') return;
|
|
382
|
+
// 凭据摘要是三条路(creds-only / 正文 / 文件)都要用的那一份,它不在这段就整轮没得做。
|
|
383
|
+
const canDigests = hasFns(digestListOf);
|
|
384
|
+
// 两条路各自判能力:缺一段只跳一段,另一段照推(见上面 hasFns 的说明)。
|
|
385
|
+
const canMessages = canDigests && hasFns(sessionUpdatedAt, messagesBlobFingerprint, buildMessagesBlobPut);
|
|
386
|
+
const canFiles = canDigests && typeof FILE_MAX_PLAIN_BYTES === 'number'
|
|
387
|
+
&& hasFns(collectFileBlobSources, statFileSource, fileBlobFingerprint, readFileSource, buildFileBlobPut);
|
|
388
|
+
noteBlobGaps(canMessages, canFiles);
|
|
389
|
+
// 凭据摘要都拿不到时,creds-only 与后面两段全都没法跑 —— 一个字节都不发,直接收工。
|
|
390
|
+
if (!canDigests) return;
|
|
391
|
+
const digestList = digestListOf(creds);
|
|
392
|
+
|
|
393
|
+
// HK 换了:中转上的旧密文当场作废,本地「已推」账一起清掉,下一轮按新钥重封重推。
|
|
394
|
+
// 不清的话这些会话会被指纹判成「内容没变」,新钥永远推不上去。
|
|
395
|
+
if (blobHistoryKey !== null && hk !== blobHistoryKey) {
|
|
396
|
+
pushedMessageBlobs.clear();
|
|
397
|
+
pushedFileBlobs.clear();
|
|
398
|
+
blobCredsKey = null;
|
|
399
|
+
blobLogOnce.clear();
|
|
400
|
+
}
|
|
401
|
+
blobHistoryKey = hk;
|
|
402
|
+
|
|
403
|
+
await deleteRemovedSessionBlobs(sidecar);
|
|
404
|
+
|
|
405
|
+
// 一台设备凭据都没有(还没配对过 / 刚吊销完):推上去也没人能拉,中转那边还要求 creds
|
|
406
|
+
// 非空。删除已经在上面做过了,剩下的不发,省得每轮撞一条注定被拒的帧。
|
|
407
|
+
if (digestList.length === 0) return;
|
|
408
|
+
|
|
409
|
+
// 设备集合变了(新配对 / 吊销):对本实例已有 blob 发一轮 creds-only(`cipher` 空串),
|
|
410
|
+
// 让中转那份鉴权名单立刻跟上,不必等各会话下次重推正文。
|
|
411
|
+
const credsKey = digestList.join(',');
|
|
412
|
+
if (credsKey !== blobCredsKey) {
|
|
413
|
+
const targets = [
|
|
414
|
+
...[...pushedMessageBlobs.keys()].map((key) => ({ scope: 'messages', key })),
|
|
415
|
+
// 超限跳过的文件从没推上去过,中转那边没有它,别拿 creds 去撞一个不存在的 key。
|
|
416
|
+
...[...pushedFileBlobs.entries()].filter(([, rec]) => rec && !rec.skipped).map(([key]) => ({ scope: 'file', key })),
|
|
417
|
+
];
|
|
418
|
+
let allOk = true;
|
|
419
|
+
for (let i = 0; i < targets.length; i += MAX_CREDS_ONLY_BATCH) {
|
|
420
|
+
const batch = targets.slice(i, i + MAX_CREDS_ONLY_BATCH);
|
|
421
|
+
for (const target of batch) {
|
|
422
|
+
try { await sidecar.pushBlob({ ...target, creds: digestList, cipher: '' }); }
|
|
423
|
+
catch (error) { allOk = false; blobLog(`creds:${target.scope}:${target.key}`, errorText(error)); }
|
|
424
|
+
}
|
|
425
|
+
if (!allOk) break; // 下一轮再来,别在这一轮把 stderr 刷满
|
|
426
|
+
}
|
|
427
|
+
// 只有整批都成功了才前移基准:失败那次下一轮必须重来(否则被撤设备一直留在中转名单里)。
|
|
428
|
+
if (allOk) blobCredsKey = credsKey;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// 正文与文件各自一份配额。不共用一条计数器:共用的话,一个每轮都在变的会话就能把
|
|
432
|
+
// 整条配额吃光,文件永远轮不到(饥饿)。
|
|
433
|
+
let messageBudget = MAX_BLOB_MESSAGE_FRAMES_PER_ROUND;
|
|
434
|
+
let fileBudget = MAX_BLOB_FILE_FRAMES_PER_ROUND;
|
|
435
|
+
const messages = payload && payload.messages && typeof payload.messages === 'object' ? payload.messages : {};
|
|
436
|
+
for (const [sessionId, body] of Object.entries(messages)) {
|
|
437
|
+
if (messageBudget <= 0) break;
|
|
438
|
+
if (!canMessages) break;
|
|
439
|
+
if (!isBlobEligible(body)) continue;
|
|
440
|
+
const updatedAt = sessionUpdatedAt(payload, sessionId);
|
|
441
|
+
const fingerprint = messagesBlobFingerprint(sessionId, body, updatedAt);
|
|
442
|
+
const previous = pushedMessageBlobs.get(sessionId);
|
|
443
|
+
if (previous && previous.fingerprint === fingerprint) continue;
|
|
444
|
+
let frame;
|
|
445
|
+
try { frame = buildMessagesBlobPut(hk, sessionId, body, updatedAt, digestList); }
|
|
446
|
+
catch (error) { blobLog(`build:messages:${sessionId}`, errorText(error)); continue; }
|
|
447
|
+
try {
|
|
448
|
+
await sidecar.pushBlob(frame);
|
|
449
|
+
pushedMessageBlobs.set(sessionId, { fingerprint });
|
|
450
|
+
blobLogClear(`put:messages:${sessionId}`);
|
|
451
|
+
messageBudget -= 1;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
blobLog(`put:messages:${sessionId}`, errorText(error));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 文件 blob:消息里引用到的附件 / 交付文件,读原始字节,≤2MB 才推。超过的不推、
|
|
458
|
+
// 只记一行(离线时该文件照旧不可用,App 侧另有可见区分)。
|
|
459
|
+
//
|
|
460
|
+
// 这一段今天在 `history-blob.cjs` 里没有生产者(见 decisions 里 d2838e82 那条:文件 scope
|
|
461
|
+
// 「今天没有」),所以 `canFiles` 为假时整段不跑 —— 不跑不等于没写,真接上了这里自己就通。
|
|
462
|
+
for (const source of (canFiles ? collectFileBlobSources(payload) : [])) {
|
|
463
|
+
if (fileBudget <= 0) break;
|
|
464
|
+
const stat = statFileSource(source);
|
|
465
|
+
if (!stat) continue;
|
|
466
|
+
const fingerprint = fileBlobFingerprint(source.key, stat);
|
|
467
|
+
const previous = pushedFileBlobs.get(source.key);
|
|
468
|
+
if (previous && previous.fingerprint === fingerprint) continue;
|
|
469
|
+
if (stat.size > FILE_MAX_PLAIN_BYTES) {
|
|
470
|
+
// 记下这一版:免得每轮重新 stat 一遍、也免得日志刷屏。文件变了指纹就变,会自动重试。
|
|
471
|
+
pushedFileBlobs.set(source.key, { fingerprint, sessionId: source.sessionId, skipped: true });
|
|
472
|
+
blobLog(`file-too-large:${source.key}`, `${stat.size} bytes`);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const bytes = readFileSource(source);
|
|
476
|
+
if (!bytes) { blobLog(`file-unreadable:${source.key}`, 'bytes unavailable'); continue; }
|
|
477
|
+
let frame;
|
|
478
|
+
try { frame = buildFileBlobPut(hk, source, bytes, digestList); }
|
|
479
|
+
catch (error) { blobLog(`build:file:${source.key}`, errorText(error)); continue; }
|
|
480
|
+
try {
|
|
481
|
+
await sidecar.pushBlob(frame);
|
|
482
|
+
pushedFileBlobs.set(source.key, { fingerprint, sessionId: source.sessionId });
|
|
483
|
+
blobLogClear(`put:file:${source.key}`);
|
|
484
|
+
blobLogClear(`file-too-large:${source.key}`);
|
|
485
|
+
fileBudget -= 1;
|
|
486
|
+
} catch (error) {
|
|
487
|
+
blobLog(`put:file:${source.key}`, errorText(error));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
225
492
|
// 镜像推送的唯一出口:所有 pushSync 都必须经此,保证状态与真实推送一致。
|
|
226
493
|
const pushMirrorPayload = async (payload) => {
|
|
227
494
|
// 每一次推上去的清单都顺手记一下规模(含短路那两条路径:手机侧栏看的就是这份清单)。
|
|
@@ -250,6 +517,10 @@ function createMirrorPusher(deps) {
|
|
|
250
517
|
lastPushedWorkspacesRevision = workspacesRevision;
|
|
251
518
|
lastPushedCreds = credsKey;
|
|
252
519
|
announceSessionActivity(payload.messages);
|
|
520
|
+
// 镜像判重跳过时**仍然过一遍 blob**:blob 自己有指纹判重(推成功才记账),所以这里
|
|
521
|
+
// 通常一条都不发;但上一轮 blob 推送失败、或设备集合刚变过,就得靠这一趟补上 ——
|
|
522
|
+
// 否则镜像内容不变的那些轮次里,失败的 blob 永远等不到重试。
|
|
523
|
+
await pushHistoryBlobs(payload, payload.creds);
|
|
253
524
|
return false;
|
|
254
525
|
}
|
|
255
526
|
try {
|
|
@@ -261,6 +532,8 @@ function createMirrorPusher(deps) {
|
|
|
261
532
|
lastPushedFingerprint = fingerprint;
|
|
262
533
|
lastPushedCreds = credsKey;
|
|
263
534
|
recordMirrorPush(true, null)
|
|
535
|
+
// 镜像已落地之后再推历史 blob:同一份载荷、同一批凭据摘要。失败不影响上面这次成功。
|
|
536
|
+
await pushHistoryBlobs(payload, payload.creds);
|
|
264
537
|
// 基准只在真的推进去(或被判重跳过)之后才前移:推送失败必须能在下一轮重试,
|
|
265
538
|
// 否则「清单变了」会被一次失败吃掉,中转镜像永远停在旧版(见 processBgQueue 的门)。
|
|
266
539
|
lastPushedListRevision = listRevision;
|
|
@@ -799,6 +1072,8 @@ function createMirrorPusher(deps) {
|
|
|
799
1072
|
start,
|
|
800
1073
|
pushMirror,
|
|
801
1074
|
pushSessionImmediately,
|
|
1075
|
+
/** 会话名(取不到就空串):装配层拿它当系统通知的标题。 */
|
|
1076
|
+
sessionTitleOf,
|
|
802
1077
|
getMirrorPush: () => ({
|
|
803
1078
|
pushedAt: mirrorPushAt, ok: mirrorPushOk, error: mirrorPushError,
|
|
804
1079
|
// 正文缺失而清单照推的次数与最近原因:与 ok/pushedAt 分开,避免再把
|