dsh-mobile-plugin 0.5.143 → 0.5.145

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.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +4 -2
  3. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/harmonyos.md +27 -0
  4. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network-guide.md +1 -1
  5. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +1 -1
  6. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay-server.md +1 -1
  7. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +8 -9
  8. package/docs/extension-authoring.md +28 -0
  9. package/dsh-mobile-credentials/lib/credentials.js +74 -6
  10. package/lib/cloudflared/wiring.cjs +14 -1
  11. package/lib/frpc/runner.cjs +14 -5
  12. package/lib/impl.js +21 -6
  13. package/lib/mobile/activity.cjs +107 -11
  14. package/lib/mobile/feedback.js +19 -0
  15. package/lib/mobile/mux.js +2 -1
  16. package/lib/mobile/pairing.js +19 -24
  17. package/lib/mobile/permissions.js +13 -10
  18. package/lib/mobile/relay-control.js +7 -0
  19. package/lib/mobile/schedule-edit.js +9 -8
  20. package/lib/mobile/send-continuation.js +2 -2
  21. package/lib/mobile/session-send.js +3 -4
  22. package/lib/p2p/session.cjs +21 -38
  23. package/lib/panel/index.html +18 -19
  24. package/lib/relay/config-store.js +5 -0
  25. package/lib/relay/core.js +6 -43
  26. package/lib/relay/ipv6-lifetime.cjs +89 -0
  27. package/lib/relay/lan-discovery.cjs +4 -7
  28. package/lib/relay/lan-network.cjs +16 -6
  29. package/lib/relay/lan-port-policy.cjs +6 -14
  30. package/lib/relay/lan-proxy.js +16 -30
  31. package/lib/relay/pairing-payload.cjs +76 -2
  32. package/lib/remote/host-control.cjs +14 -8
  33. package/lib/routes/control-plane.js +11 -1
  34. package/lib/routes/mobile-api.js +4 -1
  35. package/lib/shared/device-headers.js +1 -3
  36. package/lib/sidecar-facade-worker.cjs +15 -4
  37. package/lib/tailcat/host-process.cjs +17 -25
  38. package/lib/zeronews/account.cjs +8 -4
  39. package/lib/zeronews/probe.cjs +22 -14
  40. package/lib/zeronews/runner.cjs +26 -5
  41. package/package.json +14 -13
@@ -1,28 +1,124 @@
1
+ // 2026-11-30:五类真实操作的按设备时间,经 snapshot 的 interactions 交给外部工具。
1
2
  'use strict'
2
3
 
3
4
  /**
4
- * 「手机上最近来过没有」—— 一个时间戳,别的什么都没有。
5
+ * 「手机上最近来过没有」+「哪台手机真的做过事」。
5
6
  *
6
- * 移动端守卫每放行一个带有效 token 的请求就叫一次 `note()`(见 `../http/routing.js`
7
- * 的 `createGuarded`,**401 那条不算**),控制面把 `snapshot()` 补进本机状态给面板读:
8
- * 引导最后一页靠它把「等手机扫码」变成真结论,而不是一个永远转下去的圈。
7
+ * `note()` 还是那一个全局时间戳:移动端守卫每放行一个带有效 token 的请求就叫一次
8
+ * (401 不算),引导最后一页靠它把「等手机扫码」变成真结论。
9
9
  *
10
- * 为什么单独一个文件:装配层 `lib/impl.js` 有行数上限(`test/assembly-layer.test.cjs`
11
- * 钉着),而这份状态既不属于装配、也不属于路由表。放在模块作用域就够 —— 一个进程就是
12
- * 一个宿主,插件的代被换掉时这个数跟着重置,换代之后的第一部手机再来一次就会重新记上,
13
- * 正是我们要的语义。
10
+ * `noteInteraction()` 是另一回事:只有发消息、回答问题、审批、建会话、打开文件这五类动作
11
+ * **成功回包后**才叫,心跳、流续订、扩展取数与状态轮询都不算。时间落在凭据记录上,按
12
+ * deviceId 读回映射,经 `snapshot()` 和控制面现有的 `mobileActivity` 状态出口给外部工具。
13
+ * 记账坏了只影响这份展示数据,绝不影响请求结果。
14
+ *
15
+ * 放在模块作用域就够 —— 一个进程就是一个宿主,插件的代被换掉时这些账跟着重置。
14
16
  */
15
17
 
16
18
  let lastMobileAt = 0
19
+ let provider = null
20
+ /** 发消息的去重按 clientMessageId,与会话侧那张幂等表同一口径:只活在本进程。 */
21
+ const messageIds = new Map()
22
+ const MAX_MESSAGE_IDS = 1024
23
+
24
+ /** 路由 → 动作。只有这张表里的路径会被包装层盯住。 */
25
+ const INTERACTION_ACTIONS = new Map([
26
+ ['/api/mobile/v1/session/send', 'message'],
27
+ ['/api/mobile/v1/question/respond', 'question'],
28
+ ['/api/mobile/v1/approval/respond', 'approval'],
29
+ ['/api/mobile/v1/session/new', 'session'],
30
+ ['/api/mobile/v1/file/read', 'file'],
31
+ ])
32
+
33
+ /** 装配期注入凭据库与实例号取值器;反复调用只用最后一份。 */
34
+ function configure(deps) {
35
+ provider = deps && typeof deps === 'object' ? deps : null
36
+ }
17
37
 
18
38
  /** 记一次「手机来过」。守卫里调用;异常一律吞掉——记账坏了也只是面板少一个确认。 */
19
39
  function note() {
20
40
  lastMobileAt = Date.now()
21
41
  }
22
42
 
23
- /** 面板读的快照。`0` = 从来没来过。 */
43
+ /**
44
+ * 记一次真实操作。成功与否由调用方(路由包装层)判,这里只管去重与落账。
45
+ * 发消息沿用 clientMessageId 去重:离线重投拿到同一条回执时不刷新。
46
+ */
47
+ function noteInteraction(record, action, options = {}) {
48
+ if (![...INTERACTION_ACTIONS.values()].includes(action)) return false
49
+ const credentials = provider && provider.credentials
50
+ if (!credentials || typeof credentials.noteInteraction !== 'function') return false
51
+ const deviceId = String(record && record.deviceId || '').trim()
52
+ if (!deviceId) return false
53
+ const clientMessageId = action === 'message' && typeof options.clientMessageId === 'string'
54
+ ? options.clientMessageId.trim() : ''
55
+ // 与会话侧那张幂等表同一把键:按会话 + clientMessageId,再加 deviceId 隔离。
56
+ const sessionKey = `${deviceId}\u0000${typeof options.sessionId === 'string' ? options.sessionId.trim() : ''}`
57
+ if (clientMessageId && messageIds.get(sessionKey) === clientMessageId) return false
58
+ let ok = false
59
+ try {
60
+ ok = credentials.noteInteraction(record) === true
61
+ } catch { /* 记账不影响这次请求 */ }
62
+ if (ok && clientMessageId) {
63
+ if (messageIds.size >= MAX_MESSAGE_IDS) messageIds.delete(messageIds.keys().next().value)
64
+ messageIds.set(sessionKey, clientMessageId)
65
+ }
66
+ return ok
67
+ }
68
+
69
+ /**
70
+ * 把一条移动路由包上「成功才记账」。劫 `res.end` 看写出去的状态码与信封体:
71
+ * 这里在守卫内层,见到的是明文响应,不用管协议 v2 的封包。
72
+ */
73
+ function withInteractionNote(path, handler) {
74
+ const action = INTERACTION_ACTIONS.get(path)
75
+ if (!action || typeof handler !== 'function') return handler
76
+ return async (ctx, req, res) => {
77
+ const originalEnd = res && typeof res.end === 'function' ? res.end.bind(res) : null
78
+ let wrappedEnd = null
79
+ if (originalEnd) {
80
+ const wrapped = (chunk, ...rest) => {
81
+ if (res.end === wrappedEnd) res.end = originalEnd
82
+ try {
83
+ const status = Number(res.statusCode) || 200
84
+ let ok = status >= 200 && status < 300
85
+ if (ok && (typeof chunk === 'string' || Buffer.isBuffer(chunk))) {
86
+ const text = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : chunk
87
+ try {
88
+ const payload = JSON.parse(text)
89
+ if (payload && typeof payload === 'object' && payload.ok === false) ok = false
90
+ } catch { /* 文件字节不是 JSON,按状态码算成功 */ }
91
+ }
92
+ if (ok) noteInteraction(req && req.__dshRecord, action, {
93
+ clientMessageId: req && req.body && req.body.clientMessageId,
94
+ sessionId: req && req.body && req.body.sessionId,
95
+ })
96
+ } catch { /* 记账不影响请求 */ }
97
+ return originalEnd(chunk, ...rest)
98
+ }
99
+ wrappedEnd = wrapped
100
+ res.end = wrapped
101
+ }
102
+ try {
103
+ return await handler(ctx, req, res)
104
+ } finally {
105
+ // 流没结束时把钩子摘干净;守卫自己换过 res.end 就不覆盖它的那一层。
106
+ if (res && wrappedEnd && res.end === wrappedEnd) res.end = originalEnd
107
+ }
108
+ }
109
+ }
110
+
111
+ /** 面板读的快照。`0` = 从来没来过;interactions 按 deviceId,0 = 没做过真实操作。 */
24
112
  function snapshot() {
25
- return { lastMobileAt }
113
+ const credentials = provider && provider.credentials
114
+ let interactions = {}
115
+ if (credentials && typeof credentials.interactionsOf === 'function') {
116
+ try {
117
+ const instanceId = typeof provider.instanceId === 'function' ? provider.instanceId() : provider.instanceId
118
+ interactions = credentials.interactionsOf(instanceId) || {}
119
+ } catch { /* 读不到就当未知 */ }
120
+ }
121
+ return { lastMobileAt, interactions }
26
122
  }
27
123
 
28
- module.exports = { note, snapshot }
124
+ module.exports = { note, noteInteraction, withInteractionNote, configure, snapshot, INTERACTION_ACTIONS }
@@ -1,5 +1,6 @@
1
1
  // 用途:插件反馈统一提交、读取与轮询等回复口;工具和本机面板按线程查看官方回复、继续跟进。
2
2
  // 自检 / 探针文案不进真人反馈队列:submit 只收真实问题的现象描述。
3
+ // 2026-11-29:面板纯状态自报不再上报;只有标题+详情、没有真人现场内容的一律拦掉。
3
4
  // 2026-11-26:工具注册改为显式取 tools 服务,没声明注入的宿主也挂得上;真缺服务才跳过。
4
5
  // 注册走调用方的注入作用域(`ctx.tools`),记在那一代 fiber 名下,热重载换代时随旧代卸掉。
5
6
  'use strict';
@@ -55,6 +56,20 @@ function isSelfTestContent(content) {
55
56
  return SELF_TEST_MARKERS.some((pattern) => pattern.test(content));
56
57
  }
57
58
 
59
+ /**
60
+ * 面板把一行状态读数当成反馈提交时,正文里只有产品的标题和详情,没有任何真人写下的现象。
61
+ * 这类自报排查侧拿不到信息,只会白跑一趟;与 `isSelfTestContent` 一样在本地就挡住。
62
+ *
63
+ * 判据:带 `title`/`detail` 的自报形态,且 summary 正是「标题\n详情」原样拼出来的——
64
+ * 没有别的补充。真人通过 IssueMark 写下的额外文字会让 summary 多出内容,照常放行。
65
+ */
66
+ function isPanelStatusOnly({ summary, context }) {
67
+ const ctx = context && typeof context === 'object' ? context : {};
68
+ if (typeof ctx.title !== 'string' || typeof ctx.detail !== 'string') return false;
69
+ const expected = `${ctx.title}\n${ctx.detail}`;
70
+ return String(summary || '').trim() === expected.trim();
71
+ }
72
+
58
73
  /** 明确指定设备、但包名读不到时的兜底;没有设备时这一格留空。 */
59
74
  const DEFAULT_PACKAGE_ID = 'com.dsh.mobile';
60
75
 
@@ -417,6 +432,9 @@ function renderSummary(value) {
417
432
  * submit_kind,保持「插件自报」的归类),所以这里复用同一套 buildFeedbackForm。
418
433
  */
419
434
  async function submitPanelFeedback({ summary, detail, context, version, deviceId, submissionId }) {
435
+ if (isPanelStatusOnly({ summary, context })) {
436
+ throw Object.assign(new Error('面板状态提示没有真人补充,不提交到反馈队列'), { status: 400 });
437
+ }
420
438
  const form = buildFeedbackForm(null, String(summary || ''), '', {
421
439
  localDeviceId: String(deviceId || ''),
422
440
  submissionId,
@@ -470,6 +488,7 @@ module.exports = {
470
488
  handlePanelFeedback,
471
489
  feedbackChannels,
472
490
  installFeedback,
491
+ isPanelStatusOnly,
473
492
  localDeviceId,
474
493
  pickDevice,
475
494
  readFeedback,
package/lib/mobile/mux.js CHANGED
@@ -1,3 +1,4 @@
1
+ // 2026-11-29:转发头白名单去掉局域网发现能力位。
1
2
  // mux 握手遵守查看权限,连接归属随身份迁移并保留有界吊销回执。
2
3
  'use strict';
3
4
 
@@ -34,7 +35,7 @@ const MOBILE_PATH = /^\/api\/mobile\/v1\/[a-zA-Z0-9/_-]+(?:\?[^\r\n#]*)?$/;
34
35
  const CONNECTION_HEADERS = new Set([
35
36
  'authorization', 'cookie', 'x-dsh-device-credential', 'x-dsh-device', 'x-dsh-instance',
36
37
  'x-dsh-device-name', 'x-dsh-device-model', 'x-dsh-platform', 'x-dsh-os-version',
37
- 'x-dsh-app-version', 'x-dsh-package-id', 'x-dsh-build-number', 'x-dsh-channel', 'x-dsh-lan-discovery',
38
+ 'x-dsh-app-version', 'x-dsh-package-id', 'x-dsh-build-number', 'x-dsh-channel',
38
39
  ]);
39
40
 
40
41
  /** 单帧上限:与中转 `MAX_WS_MESSAGE_BYTES` / 宿主预览管道对齐(8 MiB)。 */
@@ -1,8 +1,9 @@
1
+ // 2026-11-30:需求变为不接老配对——无 proto 的六位码入口直接拒掉,带票据的二维码照常配。
1
2
  // 签发成功后记录绑定时间,供二维码自动收起,并发布独立的 IPv6 直连候选。
2
3
  'use strict';
3
4
 
4
5
  /**
5
- * 移动端配对:手机在中转上用自己的配对码换到 token 与设备凭据。
6
+ * 移动端配对:手机在中转上用自己的二维码票据换到 token 与设备凭据。
6
7
  *
7
8
  * 这条路由归宿主、不归中转:「谁可以进这台机器」是宿主自己的判断,配对码存在宿主的 state
8
9
  * 里,中转只按实例标识把请求转过来。
@@ -10,18 +11,18 @@
10
11
  * 与局域网那条(`lib/relay/lan-proxy.js` 的 `/__lan_pair`)是同一件事的两个入口,签发的
11
12
  * 是同一种 HMAC(都用宿主 lanSecret 签名),所以经中转配对拿到的 token 也能用于局域网请求。
12
13
  *
13
- * 请求体两种形状都认:老 App 的 `{ instanceId?, code, device }` 明文照旧;协议 v2 的
14
- * `{ instanceId, sealed }` 没有配对码,票据本身就是资格证明,回包同样是密文 —— 里面是
15
- * token / cookie / 设备凭据,明文回包等于让中转拿到这台设备的长期通行证。
14
+ * 请求体只认协议 v2 的 `{ instanceId, sealed }`:没有配对码,票据本身就是资格证明,回包同样是
15
+ * 密文 —— 里面是 token / cookie / 设备凭据,明文回包等于让中转拿到这台设备的长期通行证。
16
+ * 无 proto 的六位码明文形状不再受理(需求变为不接老配对),带 proto 却没 sealed 的按过期二维码
17
+ * 拒掉;升级桥 / 老会话验签 / 换身份认上一代号走各自的接口,不在这里借壳。
16
18
  *
17
19
  * 协议 v2 的请求体还多了个可选 `ticketId`(批量同步导入用,见 docs/device-batch-sync.md):
18
20
  * 有它就从一次性券表(`mobile/transfer-tickets.js`)取那张券当票据,配成功后 `consume` 作废;
19
21
  * 没有就沿用 `state.pairingTicket`(电脑面板二维码那条路,行为不变)。券由导出方手机向目标
20
- * 电脑申领、塞进二维码,所以票据不再只能是面板上那一张 —— 这是本文件相对旧签名的唯一变化。
22
+ * 电脑申领、塞进二维码,所以票据不再只能是面板上那一张。
21
23
  */
22
24
 
23
25
  const { sendJson } = require('../shared/http-util');
24
- const { safeEqual } = require('../shared/dshtoken');
25
26
  const { createPairThrottle, PAIR_RATE_NORMAL } = require('../shared/pair-throttle');
26
27
  const { openSealedPairRequest, sealPairResponse } = require('../shared/e2ee-pair');
27
28
  // 档位 → 权限位(唯一真源)。配对时电脑侧选定的档位落在 state.pairingTier,这里展开成数组
@@ -153,8 +154,8 @@ function createPairHandler(deps) {
153
154
 
154
155
  // ── 形状判定 ──────────────────────────────────────────────────
155
156
  //
156
- // 有 `sealed` 就是协议 v2;有 `code` 就是旧 App 的老形状,**一字不改地照旧走**;
157
- // 两样都没有就是畸形请求。两条路只在「怎么拿到设备信息」上不同,签发凭据之后完全汇合。
157
+ // 有 `sealed` 就是协议 v2;没有就是不再受理的老形状(含无 proto 的六位码)。
158
+ // 官方二维码都带票据,配对只会走 sealed 这一条。
158
159
  const sealed = typeof body.sealed === 'string' ? body.sealed.trim() : '';
159
160
  const isSealedShape = sealed !== '';
160
161
 
@@ -164,9 +165,8 @@ function createPairHandler(deps) {
164
165
  // 却还带着六位码」只可能是一张过期的旧二维码(截图、面板重开之前的那份)。这个形状
165
166
  // 的码是逐位可试的,没有必要继续为它开门 —— 直接让它重扫当前那张。
166
167
  //
167
- // **判据是请求里带没带 `proto`,不是版本号**:老 App 没有协议概念、不带这个字段,
168
- // 照旧能配;而版本号在 OTA 里并不一定变(热更换的是 JS,App 版本还是那个),拿它
169
- // 当判据会把「就是不给更新的人」和「已经更新的人」一起判错。
168
+ // **判据是请求里带没带 `proto`,不是版本号**:版本号在 OTA 里并不一定变(热更换的是 JS,
169
+ // App 版本还是那个),拿它当判据会把人判错。不带 proto 的六位码形状在下面一并不再受理。
170
170
  if (!isSealedShape && body.proto !== undefined) {
171
171
  sendJson(res, 400, {
172
172
  ok: false,
@@ -225,19 +225,14 @@ function createPairHandler(deps) {
225
225
  issuedExtra = { deviceKey: opened.deviceKey, keyId: opened.keyId };
226
226
  pairKey = opened.pairKey;
227
227
  } else {
228
- const code = typeof body.code === 'string' ? body.code.trim() : '';
229
- if (!/^\d{6}$/.test(code)) {
230
- sendJson(res, 400, { ok: false, error: '配对码需为 6 位数字' });
231
- return;
232
- }
233
- const expected = String(state.pairingCode || '');
234
- if (!expected || !safeEqual(code, expected)) {
235
- log('pair: pairing code mismatch')
236
- throttle.noteFail();
237
- pairDenied(res);
238
- return;
239
- }
240
- supplied = body.device && typeof body.device === 'object' ? body.device : {};
228
+ // 需求变为不接老配对:无 proto 的六位码入口会新产生明文会话,官方二维码都带票据,
229
+ // 这个入口直接拒掉,提示用当前二维码重新扫。码的真假不再校验,不给逐位试码的余地。
230
+ sendJson(res, 400, {
231
+ ok: false,
232
+ code: 'pairing-code-retired',
233
+ error: '六位配对码已停用,请用电脑面板上当前的二维码重新扫',
234
+ });
235
+ return;
241
236
  }
242
237
 
243
238
  // 还要宿主自己的策略点头:'deny' 就是明确不收新设备。
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:需求变为不接老权限缺省——库里有记录的凭据启动时补成显式权限,缺位不再当全权。
1
2
  // 2026-11-29:/voice/lexicon/learn 归 input(会把用户内容写进电脑侧词库)。
2
3
  // 2026-11-28:语音输入三条路由登记权限档——能力表归 view,整段 / 流式归 input。
3
4
  // 2026-11-26:画像 / 学习开关五条路由登记权限档,读归 view,写与归纳归 config。
@@ -12,8 +13,9 @@
12
13
  * 设备管理页按这里显示与降档。任何一处要「这条路由归哪一位」,都改这里,别散到别处。
13
14
  *
14
15
  * 边界口径(只收紧不放开):
15
- * - 凭据记录里**没有 `permissions` 字段 = 全权**。现网老凭据、升级前的老会话都缺这一格,
16
- * 一律按全权放行,行为与今天单 token 全给一字不差。
16
+ * - 凭据记录里**没有 `permissions` 字段**:启动时已批量补成显式全权(隐式全权变显式,
17
+ * 权限不变),运行时不再把缺位当全权 —— 有记录却没写权限位按「没给」处理。没有记录
18
+ * (升级前 HMAC 那种无状态通行证)仍按全权放行,那是独立的验签兜底,不在这里收。
17
19
  * - `permissions: []`(空数组)≠ 缺失:它是「明确什么都不给」,除下方 BASE 那几条保命接口
18
20
  * (能连上、能自愈、能自己解绑、能升级)外全部 403。
19
21
  * - 授权只能收窄:手机端只能在自己的当前权限里往下减(见 setDevicePermissions 的调用方),
@@ -25,7 +27,7 @@
25
27
  *
26
28
  * 两条限制,摆明在头里:
27
29
  * - 无记录的老凭据(升级前的 HMAC)按全权放行,且**无法被按设备降档** —— 它没有记录可写,
28
- * 要断只能吊销全部。
30
+ * 要断只能吊销全部。有记录但缺权限位的老凭据已在启动时补齐,不在此列。
29
31
  * - 可答审批档(approve)不等于无副作用:批一次能让模型在该会话里落地写动作,也能立一条
30
32
  * 长期自动放行规则。
31
33
  */
@@ -104,16 +106,17 @@ function normalizePermissionsInput(input) {
104
106
  }
105
107
 
106
108
  /**
107
- * 「这条请求能不能做」。`record` 缺 `permissions`(老凭据)或没有记录(升级前 HMAC)都放行。
108
- * `permission` 为 null/空串(BASE 路由)也放行。
109
+ * 「这条请求能不能做」。`permission` 为 null/空串(BASE 路由)也放行;没有记录(升级前
110
+ * HMAC 那种无状态通行证)仍按全权放行。有记录却缺 `permissions` 不再当全权 —— 这类老凭据
111
+ * 启动时已补成显式权限,运行时按「没给」处理。
109
112
  */
110
113
  function hasPermission(record, permission) {
111
114
  if (!permission) return true;
112
115
  // 没有记录 = 升级前 HMAC 那种无状态通行证,它本来就等于全权,不能一刀切拦住。
113
116
  if (!record || typeof record !== 'object') return true;
114
117
  const granted = record.permissions;
115
- // 字段缺失 / null = 全权(向后兼容的命门,别用 || 把空数组合成缺失)。
116
- if (!Array.isArray(granted)) return true;
118
+ // 需求变为不接老权限缺省:缺位不再隐式全权(老记录启动时已补成显式)。
119
+ if (!Array.isArray(granted)) return false;
117
120
  return granted.includes(permission);
118
121
  }
119
122
 
@@ -124,8 +127,8 @@ function hasPermission(record, permission) {
124
127
  * 据此决定要不要建卡、推卡:一台能答的设备都没有时不推。`store` 是设备凭据库
125
128
  * (`credentialsEntry()`),由调用方传进来 —— 本文件不反向依赖凭据包。
126
129
  *
127
- * 口径与 `hasPermission` 一致:记录里缺 `permissions` = 全权(算能答);活动设备一台都没有时
128
- * 也返回 true —— 老凭据 / 测试环境按全权处理,不能因为读不到清单就把提醒静默掐掉。
130
+ * 口径与 `hasPermission` 一致:记录里缺 `permissions` 不算能答(启动时已补齐);活动设备
131
+ * 一台都没有时也返回 true —— 读不到清单的环境按全权处理,不能因为读不到就把提醒静默掐掉。
129
132
  */
130
133
  function anyApprover(store) {
131
134
  try {
@@ -135,7 +138,7 @@ function anyApprover(store) {
135
138
  if (instanceIds.size === 0) return true;
136
139
  for (const instanceId of instanceIds) {
137
140
  for (const device of store.listDevices(instanceId)) {
138
- if (!device || !Array.isArray(device.permissions) || device.permissions.includes(PERMISSIONS.APPROVE)) return true;
141
+ if (device && Array.isArray(device.permissions) && device.permissions.includes(PERMISSIONS.APPROVE)) return true;
139
142
  }
140
143
  }
141
144
  return false;
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:手机配置口放出 Bonjour 广播单独开关,老配置缺项按开。
1
2
  // 2026-11-27:「立即同步」的上报半段只认「自动上报网络地址」开关,中转 / 远程控制关着也能催报一次(与 control.js 解耦口径一致)。
2
3
  // 手机主动重连在回执发出后调用独立隧道动作,普通配置同步保持幂等。
3
4
  // 既有中转配置复用有界健康判据与出网诊断,保留本实例吊销回执收尾。
@@ -127,6 +128,8 @@ function configView(state) {
127
128
  relayUrls: relay.relayUrls,
128
129
  name: typeof state.name === 'string' ? state.name : '',
129
130
  lanEnabled: state.lanEnabled === true,
131
+ // Bonjour 广播开关:只有显式 false 才算关,老配置与坏值都按开。
132
+ lanDiscoveryEnabled: state.lanDiscoveryEnabled !== false,
130
133
  lanPort: Number.isInteger(state.lanPort) ? state.lanPort : 51887,
131
134
  lanPortFixed: state.lanPortFixed === true,
132
135
  pairingPolicy: pairingApproval.normalize(state.pairingPolicy),
@@ -169,6 +172,10 @@ function configPatch(body) {
169
172
  if (typeof body.lanEnabled !== 'boolean') return { ok: false, message: 'lanEnabled 必须是布尔值' };
170
173
  patch.lanEnabled = body.lanEnabled;
171
174
  }
175
+ if (body.lanDiscoveryEnabled !== undefined) {
176
+ if (typeof body.lanDiscoveryEnabled !== 'boolean') return { ok: false, message: 'lanDiscoveryEnabled 必须是布尔值' };
177
+ patch.lanDiscoveryEnabled = body.lanDiscoveryEnabled;
178
+ }
172
179
  if (body.lanPortFixed !== undefined) {
173
180
  if (typeof body.lanPortFixed !== 'boolean') return { ok: false, message: 'lanPortFixed 必须是布尔值' };
174
181
  patch.lanPortFixed = body.lanPortFixed;
@@ -1,3 +1,4 @@
1
+ // 本次改动:写入侧 timing 只收 snake_case,删掉 camelCase 时间字段兼容;读侧归一化不动。
1
2
  // Schedule v2 写入沿用宿主 timing/target/CAS,读回统一完整目录字段与冲突结果。
2
3
  'use strict';
3
4
 
@@ -93,8 +94,8 @@ function optionalWeekdays(value) {
93
94
  /**
94
95
  * 把一个 timing 输入收成宿主认的 wire 形状;不合法回 null。
95
96
  *
96
- * 兼容 App 可能传的 snake_case(宿主原字段)与 camelCase(少数客户端习惯):两种写法都认,
97
- * 出去一律按宿主那套(after_seconds / every_seconds / daily.time_zone …)。
97
+ * App 写入只发 snake_case(宿主原字段),出去就是宿主那套(after_seconds / every_seconds /
98
+ * daily.time_zone …);camelCase 不再接。
98
99
  *
99
100
  * @returns 宿主 `ScheduleTiming` 或 null
100
101
  */
@@ -104,11 +105,11 @@ function normalizeTiming(value) {
104
105
  if (typeof kind !== 'string' || !SCHEDULE_KINDS.has(kind)) return null;
105
106
 
106
107
  if (kind === 'after') {
107
- const seconds = optionalPositive(value.after_seconds ?? value.afterSeconds);
108
+ const seconds = optionalPositive(value.after_seconds);
108
109
  return seconds === undefined ? null : { kind: 'after', after_seconds: seconds };
109
110
  }
110
111
  if (kind === 'every') {
111
- const seconds = optionalPositive(value.every_seconds ?? value.everySeconds);
112
+ const seconds = optionalPositive(value.every_seconds);
112
113
  return seconds === undefined ? null : { kind: 'every', every_seconds: seconds };
113
114
  }
114
115
  if (kind === 'at') {
@@ -120,7 +121,7 @@ function normalizeTiming(value) {
120
121
  if (at && typeof at === 'object' && !Array.isArray(at)) {
121
122
  const date = requiredText(at.date, SCHEDULE_TIME_MAX);
122
123
  const time = requiredText(at.time, SCHEDULE_TIME_MAX);
123
- const zone = requiredText(at.time_zone ?? at.timeZone, SCHEDULE_TIMEZONE_MAX);
124
+ const zone = requiredText(at.time_zone, SCHEDULE_TIMEZONE_MAX);
124
125
  if (!date || !time || !zone) return null;
125
126
  return { kind: 'at', at: { date, time, time_zone: zone } };
126
127
  }
@@ -137,20 +138,20 @@ function normalizeTiming(value) {
137
138
  const body = nested && typeof nested === 'object' && !Array.isArray(nested) ? nested : value;
138
139
  if (kind === 'daily') {
139
140
  const time = requiredText(body.time, SCHEDULE_TIME_MAX);
140
- const zone = requiredText(body.time_zone ?? body.timeZone, SCHEDULE_TIMEZONE_MAX);
141
+ const zone = requiredText(body.time_zone, SCHEDULE_TIMEZONE_MAX);
141
142
  if (!time || !zone) return null;
142
143
  return { kind: 'daily', daily: { time, time_zone: zone } };
143
144
  }
144
145
  if (kind === 'weekly') {
145
146
  const time = requiredText(body.time, SCHEDULE_TIME_MAX);
146
- const zone = requiredText(body.time_zone ?? body.timeZone, SCHEDULE_TIMEZONE_MAX);
147
+ const zone = requiredText(body.time_zone, SCHEDULE_TIMEZONE_MAX);
147
148
  const weekdays = optionalWeekdays(body.weekdays);
148
149
  if (!time || !zone || weekdays === undefined) return null;
149
150
  return { kind: 'weekly', weekly: { time, time_zone: zone, weekdays } };
150
151
  }
151
152
  // cron
152
153
  const expression = optionalText(body.expression, SCHEDULE_EXPRESSION_MAX);
153
- const zone = requiredText(body.time_zone ?? body.timeZone, SCHEDULE_TIMEZONE_MAX);
154
+ const zone = requiredText(body.time_zone, SCHEDULE_TIMEZONE_MAX);
154
155
  if (expression === undefined || !zone) return null;
155
156
  return { kind: 'cron', cron: { expression, time_zone: zone } };
156
157
  }
@@ -1,3 +1,4 @@
1
+ // 本次改动:删掉旧 {sessionId, text} 发送形状,发送内容只认 App 现在传的 content 数组。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -24,9 +25,8 @@ function continuationOf(body) {
24
25
  */
25
26
  function resolveSendContent(body, continuation) {
26
27
  if (Array.isArray(body.content)) return { content: body.content };
27
- if (typeof body.text === 'string' && body.text.trim()) return { content: [{ type: 'text', text: body.text }] };
28
28
  if (continuation) return { content: [] };
29
- return { error: { code: 'bad-request', message: '需要 content 数组或 text' } };
29
+ return { error: { code: 'bad-request', message: '需要 content 数组' } };
30
30
  }
31
31
 
32
32
  /**
@@ -1,3 +1,4 @@
1
+ // 本次改动:删掉旧 {sessionId, text} 发送形状兼容,只认 content 数组;图片内联 data 兼容保留。
1
2
  /** 发送前核对显式同意的模型接收方;旧宿主无切换能力时仍验证真实当前路由。 */
2
3
  'use strict';
3
4
 
@@ -91,9 +92,7 @@ async function executeCommand(ctx, sessionId, line) {
91
92
 
92
93
  /**
93
94
  * POST /api/mobile/v1/session/send(token)
94
- * 兼容两种格式:
95
- * 旧:{sessionId, text}
96
- * 新:{sessionId, content:[{type:'text',text} | {type:'image',mediaType,data(base64),name?}], mode?:'queue'|'steer',
95
+ * 请求体:{sessionId, content:[{type:'text',text} | {type:'image',mediaType,data(base64),name?}], mode?:'queue'|'steer',
97
96
  * modelSelection?:{provider,model,reasoningEffort?}}
98
97
  * `modelSelection` 是本次发送要用的模型(App 侧选模型不再单独发切换请求);提交 prompt 之前先
99
98
  * 落到会话上。恰为单个文本块且以 / 开头时派发为 slash 命令(commands.execute,不发给模型,也不应用模型);
@@ -115,7 +114,7 @@ function promptOnce(ctx, clientMessageId, payload) {
115
114
  async function handleSend(ctx, req, res) {
116
115
  const body = await readJsonBody(req, SEND_MAX_BODY);
117
116
  if (!body || typeof body.sessionId !== 'string' || !body.sessionId) {
118
- return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要 { sessionId, content | text }' } });
117
+ return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要 { sessionId, content }' } });
119
118
  }
120
119
  const mode = body.mode;
121
120
  if (mode !== undefined && mode !== 'queue' && mode !== 'steer') {
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:需求变为不接外部组件老形状,助手事件缺 peerKey 直接丢,不猜最近会合那台也不落匿名槽。
1
2
  // P2P 启动按 peer 串行,候选由各自 ready 确认,查询与停止回执独立。
2
3
  'use strict';
3
4
 
@@ -117,10 +118,7 @@ function createP2PSession(options) {
117
118
  *
118
119
  * `dialing`:当前 peer 的启动命令已发出、尚未收到 ready;后续候选在 opens 表里排队。
119
120
  *
120
- * `stamp`:最近一次被动到的顺序。`status()` 那几格老字段取「最近活跃的那条」,靠它排。
121
- *
122
- * 空串那把是**匿名槽**:老助手的事件里没有 `peerKey`、而这次会话又还没收到过任何手机
123
- * 公钥时,事件落在它上面。它不进 `status().peers` 的详单。
121
+ * `stamp`:最近一次被动到的顺序。面板那几格老字段取「最近活跃的那条」,靠它排。
124
122
  */
125
123
  const peers = new Map();
126
124
  // 每个 peer 同时只向助手发送一条启动;失败后的 stop 回执是下一条启动的边界。
@@ -147,21 +145,12 @@ function createP2PSession(options) {
147
145
  }
148
146
 
149
147
  /**
150
- * 助手发来的事件属于哪一台手机。
151
- *
152
- * 新助手会带 `peerKey`(手机公钥),按它路由。**老助手不带**:退回「最近会合的那一台」;
153
- * 连那一台都还没有、而表里恰好只有一把公钥时就用它;什么都没有就落进匿名槽。任何一条
154
- * 退路都不抛错 —— 老助手配新插件必须照常能用。
148
+ * 助手发来的事件属于哪一台手机。需求变为不接外部组件老形状:事件必须带非空 `peerKey`,
149
+ * 缺了就返回 null 让调用方丢掉,不再退回「最近会合那台 / 只有一把就用它 / 匿名槽」。
155
150
  */
156
151
  function routeKey(event) {
157
152
  const announced = typeof event.peerKey === 'string' ? event.peerKey.trim() : '';
158
- if (announced) {
159
- lastPeer = announced;
160
- return announced;
161
- }
162
- if (lastPeer) return lastPeer;
163
- const named = [...peers.keys()].filter(key => key);
164
- return named.length === 1 ? named[0] : '';
153
+ return announced || null;
165
154
  }
166
155
 
167
156
  /**
@@ -173,7 +162,7 @@ function createP2PSession(options) {
173
162
  * 而电脑那头一切正常。轮询与会合本来就会同时等着,两个都得能收到同一条事件。
174
163
  */
175
164
  const waiters = new Set();
176
- /** 最近一次配对 / 会合换进来的手机公钥(老助手事件没有 peerKey 时靠它兜底路由)。 */
165
+ /** 最近一次配对 / 会合换进来的手机公钥(手机侧复用用,不参与助手事件路由)。 */
177
166
  let lastPeer = '';
178
167
  /** 状态轮询定时器与开关(见 `watch`)。 */
179
168
  let timer = null;
@@ -212,7 +201,6 @@ function createP2PSession(options) {
212
201
 
213
202
  /**
214
203
  * 等待者同时按操作和 peer 认领;查询不能提前确认启动或停止。
215
- * 老助手缺 peerKey 时仅在同类操作内广播,错误与总收尾才结束所有操作。
216
204
  */
217
205
  function settle(value, key = '', type) {
218
206
  for (const done of [...waiters]) {
@@ -244,6 +232,7 @@ function createP2PSession(options) {
244
232
  case 'p2pReady': {
245
233
  lastError = '';
246
234
  const key = routeKey(event);
235
+ if (!key) break; // 缺新标识的事件直接丢,不再猜是哪台手机。
247
236
  const owner = opens.get(key);
248
237
  if (owner && (!owner.active || owner.draining)) break;
249
238
  const entry = ensurePeer(key);
@@ -263,21 +252,20 @@ function createP2PSession(options) {
263
252
  break;
264
253
  }
265
254
  case 'p2pStatus': {
266
- if (event.running === false && !event.peerKey) {
267
- // 这可能是较早发出的查询回执;只清已确认旧事实,保留后来登记的启动及其候选。
268
- for (const [key, entry] of peers) {
255
+ const key = routeKey(event);
256
+ if (!key) break; // 需求变为不接外部组件老形状:缺 peerKey 的空状态不再当「全停了」。
257
+ if (event.running === false) {
258
+ // 空状态也按 peer 落:只清这一台确认的旧事实,保留别人的在飞启动与候选。
259
+ const entry = peers.get(key);
260
+ if (entry) {
269
261
  if (entry.dialing) Object.assign(entry, emptyTunnel());
270
262
  else peers.delete(key);
271
263
  }
272
- if (!peers.has(lastPeer)) lastPeer = '';
273
- // 助手已恢复到可答查询的空状态;重发未确认的停止建立新边界,不能直接放行旧 ready。
274
- for (const [key, owner] of opens) {
275
- if (owner.draining && !owner.stopPromise) drainPeer(key, owner);
276
- }
277
- settle({ ok: true, ...emptyTunnel() }, '', 'status');
264
+ const owner = opens.get(key);
265
+ if (owner && owner.draining && !owner.stopPromise) drainPeer(key, owner);
266
+ settle({ ok: true, ...emptyTunnel() }, key, 'status');
278
267
  break;
279
268
  }
280
- const key = routeKey(event);
281
269
  const entry = ensurePeer(key);
282
270
  // 启动中的同 peer 也可能先收到旧查询;查询不能确认新启动或覆盖它的候选。
283
271
  if (!entry.dialing && !opens.get(key)?.draining) {
@@ -298,15 +286,11 @@ function createP2PSession(options) {
298
286
  }
299
287
  break;
300
288
  case 'p2pStopped': {
301
- const announced = typeof event.peerKey === 'string' ? event.peerKey.trim() : '';
302
- if (announced) {
303
- // 新助手:只收掉这一台那条,别人的照跑。
304
- peers.delete(announced);
305
- } else {
306
- // 老助手:它一条进程只有一条隧道,回的就是「全停了」。
307
- peers.clear();
308
- }
309
- settle({ ok: true, running: false }, announced, 'stop');
289
+ const key = routeKey(event);
290
+ if (!key) break; // 需求变为不接外部组件老形状:缺 peerKey 的收尾不再按「全停了」清掉所有台。
291
+ // 只收掉报上来的这一台,别人的照跑。
292
+ peers.delete(key);
293
+ settle({ ok: true, running: false }, key, 'stop');
310
294
  break;
311
295
  }
312
296
  case 'error': {
@@ -463,7 +447,6 @@ function createP2PSession(options) {
463
447
  }
464
448
  const entry = recentPeer();
465
449
  const current = entry ? pick(entry) : emptyTunnel();
466
- // 详单:最近活跃的排前面。匿名槽(空串)不进这份 —— 它只是老助手事件的落点。
467
450
  const roster = [...peers.entries()]
468
451
  .filter(([key]) => key)
469
452
  .sort((left, right) => right[1].stamp - left[1].stamp)