@dsh-mobile/mobile-remote 3.3.1 → 3.4.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.
Files changed (58) hide show
  1. package/README.md +9 -5
  2. package/docs/PRIVACY-POLICY.en.md +10 -3
  3. package/docs/PRIVACY-POLICY.md +10 -3
  4. package/docs/USER-GUIDE.zh-CN.md +1 -0
  5. package/lib/account-usage-query.js +60 -60
  6. package/lib/account-usage.js +10 -10
  7. package/lib/api-helpers.js +109 -109
  8. package/lib/assistant-prefs.js +82 -59
  9. package/lib/auto-config.js +65 -65
  10. package/lib/backup.js +117 -117
  11. package/lib/break-reminder.js +45 -45
  12. package/lib/client.js +93 -93
  13. package/lib/config.js +232 -218
  14. package/lib/git-read-bundled-provider.js +12 -12
  15. package/lib/git-read-service.js +5 -5
  16. package/lib/host-compat.js +84 -84
  17. package/lib/http-util.js +17 -17
  18. package/lib/index.js +1534 -1534
  19. package/lib/memory/context.js +44 -44
  20. package/lib/memory/decay.js +93 -93
  21. package/lib/memory/extract.js +77 -77
  22. package/lib/memory/routes.js +33 -33
  23. package/lib/memory/store.js +196 -196
  24. package/lib/notify-copy.js +93 -93
  25. package/lib/permission-guide.js +86 -86
  26. package/lib/persona-cards.js +73 -65
  27. package/lib/phone-action-args.js +175 -0
  28. package/lib/phone-actions.js +227 -0
  29. package/lib/phone-announce.js +58 -0
  30. package/lib/proactive-material.js +42 -42
  31. package/lib/proactive.js +121 -121
  32. package/lib/protected-paths.js +79 -79
  33. package/lib/protocol.js +61 -26
  34. package/lib/push.js +29 -29
  35. package/lib/rate-limit.js +16 -16
  36. package/lib/relay/connector.js +246 -102
  37. package/lib/relay/crypto.js +15 -15
  38. package/lib/relay/devices.js +36 -36
  39. package/lib/relay/fingerprint.js +34 -34
  40. package/lib/relay/identity.js +26 -26
  41. package/lib/relay/mux.js +60 -46
  42. package/lib/relay/noise.js +40 -40
  43. package/lib/relay/on-demand.js +33 -33
  44. package/lib/relay/p2p.js +239 -0
  45. package/lib/relay/pairing.js +24 -24
  46. package/lib/relay/phone.js +62 -40
  47. package/lib/relay/serve.js +21 -21
  48. package/lib/relay/signal.js +69 -0
  49. package/lib/relay/ws-server.js +32 -32
  50. package/lib/reminders.js +15 -15
  51. package/lib/rpc-adapter.js +43 -43
  52. package/lib/session-list.js +31 -31
  53. package/lib/session-rotation.js +95 -95
  54. package/lib/session-title-cache.js +35 -35
  55. package/lib/session-title-refresh.js +51 -51
  56. package/lib/timeline.js +140 -140
  57. package/lib/turn-outline.js +104 -104
  58. package/package.json +6 -13
@@ -1,82 +1,82 @@
1
- /**
2
- * 宿主 API 代际探测(ADR 0017):按结构特征判别任务服务 / 网关 / 设置服务属于哪一代,以及能力状态归类。
3
- * 从 lib/index.js 原样拆出(行为不变)。
4
- */
5
-
6
- /**
7
- * 任务服务的代际:0.2.0 同时带来两处差异——`list`/`kill` 改收 SessionId **字符串**
8
- * (0.1.x 收 **Agent 对象**,实现内部取其 `.id`),以及事件回调
9
- * `onJobsChanged`/`onJobDone` 被统一的 `events.subscribe(filter, listener)` 取代。
10
- * 两处同版发生,故共用同一个结构探测(事件流是否存在),避免"用一个特征的版本
11
- * 去推断另一个特征"。传错 caller 形状不报错,只是恒返回空。
12
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
13
  export const jobsNeedsSessionId = (jobs) => typeof jobs?.events?.subscribe === "function";
14
14
 
15
- /**
16
- * 事件流打开:0.2.0 在途中插入了 uplink/peer,取消信号从**第 3 位移到第 5 位**。
17
- * 传错位不会报参数错误——信号落进 uplink、真正的 signal 为 undefined,
18
- * 宿主在 `AbortSignal.any` 处抛错并被重试循环吞掉,表现为"该通道不可用"。
19
- * 按形参个数判别(0.1.x 为 3,0.2.0 为 6)。
20
- */
15
+
16
+
17
+
18
+
19
+
20
+
21
21
  export const wireStreamTakesControl = (gateway) =>
22
22
  typeof gateway?.openWireStream === "function" && gateway.openWireStream.length >= 5;
23
23
 
24
- /**
25
- * 进程内网关调用的 Peer 来源(issue #34,DSH 0.2.1-rc.2)。
26
- *
27
- * 宿主 0.2.1 删除了 `typertGateway.operatorPeer()` / `connection.operator` 兜底,改为
28
- * **每一个**网关入口(`invokeRpc` / `stream` / `openWireStream` / `dispatchRpc`)都先
29
- * `assertPeerLive(peer)`——进程内调用者必须显式传一个活着的 Peer(`InvokeRemoteRequest.peer`
30
- * 已是必填)。0.2.1 给进程内调用者的入口是 `connection.createPeer({ principal, interactions })`。
31
- *
32
- * 返回值即"插件该走哪条 peer 路径":
33
- * - `createPeer` 0.2.1+:由 `ctx.connection.createPeer` 现造 owner Peer;
34
- * - `operatorPeer` 0.2.0:网关自带 operator Peer 兜底,插件继续传 undefined 即可;
35
- * - `none` 网关入口在、但两条 peer 来源都没有 —— 调用必失败(能力语义漂移)。
36
- *
37
- * 按结构特征判别,不按版本号(ADR 0017)。
38
- */
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
39
  export const hostPeerSource = (gateway, connection) => {
40
40
  if (typeof connection?.createPeer === "function") return "createPeer";
41
41
  if (typeof gateway?.operatorPeer === "function") return "operatorPeer";
42
42
  return "none";
43
43
  };
44
44
 
45
- /**
46
- * 0.2.1+:创建一个进程内 owner Peer(与浏览器 GUI 同主体,`interactions: "answer"` 才能开
47
- * `$events` 转发流)。旧代没有 `createPeer` 时返回 undefined,让网关自己兜底。
48
- */
45
+
46
+
47
+
48
+
49
49
  export const createInProcessPeer = (connection) => {
50
50
  if (typeof connection?.createPeer !== "function") return undefined;
51
51
  return connection.createPeer({ principal: { kind: "owner" }, interactions: "answer" });
52
52
  };
53
53
 
54
- /**
55
- * 跨代读取一个设置节:0.2.0 走 `describe()` 找同名描述符取其 `value`;
56
- * 0.1.x 走 `get(ns)`。两代都取不到时返回 undefined(调用方按"无此配置"处理)。
57
- */
54
+
55
+
56
+
57
+
58
58
  export const readSettingsSection = (settings, ns) => {
59
59
  const result = readSettingsSectionStrict(settings, ns);
60
60
  return result.ok ? result.value : undefined;
61
61
  };
62
62
 
63
- /**
64
- * **严格**读取一个设置节(issue #21 评审 WARNING 3)。
65
- *
66
- * `readSettingsSection` 会把"读取抛错""describe 返回形状不合法""方法缺失"全部折叠成
67
- * undefined,调用方再用 `?? {}` 兜底 —— 于是**读取失败被伪装成"命名空间不存在"**。
68
- * 对 Codex 代理配置而言这是致命的:插件会据此判定"用户没开代理"、静默改走直连。
69
- *
70
- * 本函数把三件事分开:
71
- * - `{ ok: true, value }` —— 读到了(`value` 可能是 undefined,表示命名空间确实不存在);
72
- * - `{ ok: false, reason }` —— **读不到**(方法缺失 / 抛错 / 描述符形状漂移)。
73
- *
74
- * @returns {{ok: true, value: unknown} | {ok: false, reason: string}}
75
- */
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
76
  export const readSettingsSectionStrict = (settings, ns) => {
77
77
  if (!settings) return { ok: false, reason: "settings-service-missing" };
78
78
  if (typeof ns !== "string" || ns === "") return { ok: false, reason: "namespace-invalid" };
79
- // 0.1.x:get(ns)
79
+
80
80
  if (typeof settings.get === "function") {
81
81
  try {
82
82
  return { ok: true, value: settings.get(ns) };
@@ -84,7 +84,7 @@ export const readSettingsSectionStrict = (settings, ns) => {
84
84
  return { ok: false, reason: "settings-get-threw" };
85
85
  }
86
86
  }
87
- // 0.2.x:describe() → 描述符数组
87
+
88
88
  if (typeof settings.describe === "function") {
89
89
  let rows;
90
90
  try {
@@ -92,22 +92,22 @@ export const readSettingsSectionStrict = (settings, ns) => {
92
92
  } catch {
93
93
  return { ok: false, reason: "settings-describe-threw" };
94
94
  }
95
- // 形状漂移(返回对象而非数组、或行结构不认识)属于**读不到**,不是"不存在"
95
+
96
96
  if (!Array.isArray(rows)) return { ok: false, reason: "settings-describe-shape-invalid" };
97
97
  const row = rows.find((candidate) => candidate?.ns === ns);
98
- if (row === undefined) return { ok: true, value: undefined }; // 命名空间确实不存在
98
+ if (row === undefined) return { ok: true, value: undefined };
99
99
  if (!Object.prototype.hasOwnProperty.call(row, "value")) return { ok: false, reason: "settings-descriptor-without-value" };
100
100
  return { ok: true, value: row.value };
101
101
  }
102
102
  return { ok: false, reason: "settings-has-no-read-method" };
103
103
  };
104
104
 
105
- /**
106
- * 任务查询 / 终止的 caller 实参:0.2.0 要 SessionId **字符串**,0.1.x 要 **Agent 对象**。
107
- * 传错形状不会报参数错误:列表恒返回空(看起来像"这个会话确实没有任务"),
108
- * 终止则报"任务属于另一个会话"。因此必须按代际给出正确形状。
109
- * caller 缺失时两代都接受 undefined,原样传 undefined。
110
- */
105
+
106
+
107
+
108
+
109
+
110
+
111
111
  export const jobsCallerFor = (jobs, agent, sessionId) => {
112
112
  if (!jobsNeedsSessionId(jobs)) return agent;
113
113
  if (typeof sessionId === "string" && sessionId !== "") return sessionId;
@@ -115,16 +115,16 @@ 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
- */
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
128
  export const liveRootAgents = (agents) => {
129
129
  if (typeof agents?.roots === "function") {
130
130
  const roots = agents.roots();
@@ -137,22 +137,22 @@ export const liveRootAgents = (agents) => {
137
137
  return [];
138
138
  };
139
139
 
140
- /** The first live top-level agent, or undefined. */
140
+
141
141
  export const firstRootAgent = (agents) => liveRootAgents(agents)[0];
142
142
 
143
- /**
144
- * 单项宿主能力的状态(ADR 0017 要求的三态报告)。仅报"服务在不在"不够:
145
- * 本次四处不兼容**全部**是"服务在、调用不报错、语义已变",两分法看不见它们。
146
- * · `ok` 服务与插件真正调用的成员都在;
147
- * · `drift` 服务在,但成员形状不是插件认识的样子(能力语义漂移);
148
- * · `missing` 服务本身不存在。
149
- * 判定谓词由调用方给出——每项能力"什么算可用"的定义不同(例如 tasks 有两代合法形状)。
150
- */
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
151
  export const capabilityState = (service, predicate) => {
152
152
  if (!service) return "missing";
153
153
  try {
154
154
  return predicate(service) ? "ok" : "drift";
155
155
  } catch {
156
- return "drift"; // 探测自身抛错,同样说明形状不符预期
156
+ return "drift";
157
157
  }
158
158
  };
package/lib/http-util.js CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * JSON 响应 / 请求体读取 / 方法检查 / 响应防崩守卫。从 lib/index.js 原样拆出(行为不变;`error` 在模块内更名为 `sendError`)。
3
- */
4
1
 
5
- /** 响应防崩守卫(写已销毁响应时 error 事件有监听)。 */
2
+
3
+
4
+
5
+
6
6
  export const guardRes = (res) => {
7
7
  if (!res.__dshErrGuarded) {
8
8
  res.__dshErrGuarded = true;
@@ -11,17 +11,17 @@ export const guardRes = (res) => {
11
11
  };
12
12
 
13
13
  export const sendJson = (res, status, body, headers = {}) => {
14
- // v2.7.2 review(S2):客户端中途断开后对已销毁响应 writeHead/end 会 emit 'error',
15
- // 无监听时 Node 抛未捕获异常 → 崩进程;挂一次性 noop 监听兜底
14
+
15
+
16
16
  guardRes(res);
17
17
  const text = JSON.stringify(body);
18
18
  res.writeHead(status, {
19
19
  "content-type": "application/json; charset=utf-8",
20
20
  "cache-control": "no-store",
21
- // v3.0.0(热修 04):响应即断(connection: close)——关闭 keep-alive 复用窗口:
22
- // 手机 dart:io 连接池 idle 15s 与服务端 keep-alive 5s 存在半关竞态,
23
- // 复用半关 socket 表现为「Connection reset by peer」:消息已送达却报失败。
24
- // 移动端 API 均为一问一答短请求,无 keep-alive 收益。
21
+
22
+
23
+
24
+
25
25
  "connection": "close",
26
26
  "content-length": Buffer.byteLength(text),
27
27
  ...headers,
@@ -38,11 +38,11 @@ export const readBody = (req, limit = 64 * 1024) =>
38
38
  size += chunk.length;
39
39
  if (size > limit) {
40
40
  reject(Object.assign(new Error("body too large"), { status: 413 }));
41
- // v3.0.0 修复:超限先停读并让 handler 回 413——此前先 req.destroy()
42
- // 会把连接直接掐断,客户端看到的是"连接意外关闭/连接重置"而非 413
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.
41
+
42
+
43
+
44
+
45
+
46
46
  req.off("data", onData);
47
47
  req.pause();
48
48
  return;
@@ -52,11 +52,11 @@ export const readBody = (req, limit = 64 * 1024) =>
52
52
  req.on("data", onData);
53
53
  req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
54
54
  req.on("error", reject);
55
- // review:客户端断开且不触发 error 时也要 settle,避免 handler 悬挂
55
+
56
56
  req.on("close", () => reject(Object.assign(new Error("request closed"), { status: 400 })));
57
57
  });
58
58
 
59
- // Phase 1(S6):方法检查收敛——不匹配时已响应 405 并返回 true,调用点 `if (requireGet(method, res)) return;`
59
+
60
60
  export const requireGet = (method, res) => {
61
61
  if (method !== "GET" && method !== "HEAD") {
62
62
  sendError(res, 405, "method-not-allowed");