@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,17 +1,17 @@
1
- /**
2
- * What a proactive message may say (T-32; plan §5.7, decisions D1, D4, D7).
3
- *
4
- * Real things only, in this order:
5
- * 1. a reminder coming due (one the user set; `lib/reminders.js`);
6
- * 2. an approval or question that has been waiting for a while;
7
- * 3. task news when the user returns to the phone: tasks that finished while nobody was using DSH;
8
- * 4. a morning summary, once a day, in the hours after quiet hours end.
9
- * Each is skipped when it has nothing real in it. Nothing here is triggered by the user being
10
- * away: no "thinking of you", no "it's been a while", no streaks. When the scheduler is in
11
- * "less" mode (3 days without a reaction) only 1 and 2 are left.
12
- *
13
- * Pure functions: every input is passed in, so each rule has a fake-clock test.
14
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
15
 
16
16
  export const DUE_LEAD_MS = 15 * 60_000;
17
17
  export const DUE_STALE_MS = 24 * 60 * 60_000;
@@ -19,7 +19,7 @@ export const STALE_PENDING_MS = 10 * 60_000;
19
19
  export const RETURN_WINDOW_MS = 10 * 60_000;
20
20
  export const MORNING_WINDOW_MS = 3 * 60 * 60_000;
21
21
  export const DEFAULT_IDLE_MS = 30 * 60_000;
22
- /** "Chatting right now": a message typed in a DSH client within this window. */
22
+
23
23
  export const CHATTING_MS = 5 * 60_000;
24
24
 
25
25
  const hm = (ms) => {
@@ -31,19 +31,19 @@ const clip = (text, n = 80) => {
31
31
  return t.length <= n ? t : `${t.slice(0, n - 1)}…`;
32
32
  };
33
33
 
34
- /**
35
- * "The user is idle" for the proactive gate: no typed message or phone action for `idleMs`.
36
- * One exception: right after the user returns to the phone (the app reconnects after being
37
- * idle), the app's own background writes must not count as chatting, or the task news meant for
38
- * that moment could never go out. Inside the return window only a typed message counts.
39
- */
34
+
35
+
36
+
37
+
38
+
39
+
40
40
  export function isUserIdle({ now, lastActivityAt = 0, lastTypedAt = 0, returnedAt = null, idleMs = DEFAULT_IDLE_MS }) {
41
41
  const t = now.getTime();
42
42
  if (returnedAt != null && t - returnedAt >= 0 && t - returnedAt < RETURN_WINDOW_MS) return lastTypedAt < returnedAt;
43
43
  return t - lastActivityAt >= idleMs;
44
44
  }
45
45
 
46
- /** Reminders that are due within the lead time, or overdue by less than a day, and not done. */
46
+
47
47
  export function dueReminders(reminders, now) {
48
48
  const t = now.getTime();
49
49
  return (reminders ?? [])
@@ -51,7 +51,7 @@ export function dueReminders(reminders, now) {
51
51
  .sort((a, b) => a.dueAt - b.dueAt);
52
52
  }
53
53
 
54
- /** The morning window: from the end of quiet hours (local time) for MORNING_WINDOW_MS. */
54
+
55
55
  export function inMorningWindow(now, quietEnd = "08:30") {
56
56
  const m = /^(\d{1,2}):(\d{2})$/.exec(String(quietEnd ?? "").trim());
57
57
  const [h, min] = m ? [Number(m[1]), Number(m[2])] : [8, 30];
@@ -63,23 +63,23 @@ export function inMorningWindow(now, quietEnd = "08:30") {
63
63
  const dayKey = (now) =>
64
64
  `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
65
65
 
66
- /**
67
- * Pick the one thing worth saying now, or null.
68
- *
69
- * @param {object} e
70
- * @param {Date} e.now
71
- * @param {"normal"|"less"} [e.level] silence level from the scheduler
72
- * @param {string[]} [e.sentKeys] keys already sent: skipped, so the next item gets its turn
73
- * @param {Array<{id: string, text: string, dueAt: number, doneAt?: number, sessionId?: string}>} [e.reminders]
74
- * @param {Array<{key: string, id: string, sessionId: string, approval: boolean, toolName?: string, at: number}>} [e.pending]
75
- * @param {Array<{kind: "completed"|"failed", time: number, sessionId: string}>} [e.finished] task results
76
- * @param {{at: number, since: number}|null} [e.returned] when the user came back to the app, and
77
- * the point from which finished tasks are news (see lib/index.js, POST /presence)
78
- * @param {string} [e.quietEnd] end of quiet hours, "HH:MM"
79
- * @param {boolean} [e.dueOnly] only due reminders (the scheduler's lighter gate for them)
80
- * @param {Set<string>|string[]} [e.busySessions] sessions with a running agent: their reminders wait
81
- * @returns {{key: string, kind: string, title: string, text: string, sessionId: string, until?: number}|null}
82
- */
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
83
  export function pickMaterial({ now, level = "normal", sentKeys = [], reminders = [], pending = [], finished = [], returned = null, quietEnd = "08:30", dueOnly = false, busySessions = [] }) {
84
84
  const sent = new Set(sentKeys);
85
85
  const busy = new Set(busySessions);
@@ -87,7 +87,7 @@ export function pickMaterial({ now, level = "normal", sentKeys = [], reminders =
87
87
  const candidates = [];
88
88
 
89
89
  for (const r of dueReminders(reminders, now)) {
90
- // A reminder tied to a session waits while that session's agent is running.
90
+
91
91
  if (r.sessionId && busy.has(r.sessionId)) continue;
92
92
  const overdue = r.dueAt < t;
93
93
  candidates.push({
@@ -127,7 +127,7 @@ export function pickMaterial({ now, level = "normal", sentKeys = [], reminders =
127
127
  title: "任务有了结果",
128
128
  text: `有 ${news.length} 个任务有了结果:${parts.join(",")}。`,
129
129
  sessionId: sessions.length === 1 ? sessions[0] : "",
130
- // Once said, results up to here are not news again (the caller moves `since`).
130
+
131
131
  until: returned.at,
132
132
  });
133
133
  }
package/lib/proactive.js CHANGED
@@ -1,51 +1,51 @@
1
- /**
2
- * 主动消息调度器(P0-5 / P0-6 的剩余部分)。
3
- *
4
- * 解决的问题只有三个,全部来自"用户被吵醒"与"提醒丢了"这两种真实抱怨:
5
- *
6
- * 1. **`nextFireAt` 落盘**。用 `setTimeout(N)` 排一次性提醒,进程重启、笔记本合盖、
7
- * 系统时间跳变之后那个定时器就永远不触发了——用户等不到本该到来的汇报。
8
- * 这里把"下一次该在什么时候发"写进磁盘,每次 tick 重新算"现在该不该发"。
9
- * 定时器只负责把我叫醒,不负责决定发什么。
10
- * 2. **每日上限**。没有上限的主动消息会很快变成骚扰,用户第一件事就是关掉它,
11
- * 于是这个功能永久失效。上限按电脑本地日历日算,跨零点归零。
12
- * 3. **主人在聊时不插嘴**。用户正在跟助手对话时插一条"我想到一件事"是最烦的;
13
- * 这条判据必须能观测到"最近有没有人在说话",所以由调用方在装配时传入一个
14
- * 读当前活动的回调,而不是让调度器自己去猜。
15
- *
16
- * 刻意不做的事:
17
- * - **不生成内容**。调度器只决定"什么时候可以开口",说什么由调用方给的 `pick`
18
- * 决定;`pick` 返回 null 就这次不发,且不消耗每日配额。这样"没有值得说的"与
19
- * "说漏了"是两件不同的事,前者不该记账。
20
- * - **不用长定时器**。tick 间隔固定(默认 60s),每次重算,时钟跳变最多晚一个 tick。
21
- * - **不重发同一条**。候选带 `key`,发过的 key 落盘,进程重启也不会重复。
22
- *
23
- * 状态文件 `<状态目录>/proactive.json`:与口令、记忆库同在状态目录下,只在本机。
24
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
25
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
26
26
  import { dirname, join } from "node:path";
27
27
 
28
- /** 默认 tick 间隔。60s 够用:主动消息的精度本来就是分钟级。 */
28
+
29
29
  export const DEFAULT_TICK_MS = 60_000;
30
30
 
31
- /** 默认每日上限。3 条是"它记得我"与"它在烦我"之间比较稳的一条线。 */
31
+
32
32
  export const DEFAULT_DAILY_LIMIT = 3;
33
33
 
34
- /** 默认最小间隔:两条主动消息之间至少隔这么久,避免一次 tick 连发。 */
34
+
35
35
  export const DEFAULT_MIN_GAP_MS = 90 * 60_000;
36
36
 
37
- /**
38
- * 沉默衰减(T-32,§5.7):从「第一条没得到回应的主动消息」算起,
39
- * 3 天没回应就少说(每天至多 1 条,只说到期提醒与在等你的事),7 天没回应就停。
40
- * 用户任何一次操作都算回应,计时清零。这样它永远不会因为你不在而越说越多。
41
- */
37
+
38
+
39
+
40
+
41
+
42
42
  export const SILENCE_SAY_LESS_MS = 3 * 24 * 60 * 60_000;
43
43
  export const SILENCE_STOP_MS = 7 * 24 * 60 * 60_000;
44
44
 
45
- /**
46
- * 沉默等级:`normal` 照常;`less` 少说;`stopped` 不说。
47
- * @param {{unansweredSince: number|null, now: Date}} e
48
- */
45
+
46
+
47
+
48
+
49
49
  export function silenceLevel({ unansweredSince, now }) {
50
50
  if (unansweredSince == null) return "normal";
51
51
  const silent = now.getTime() - unansweredSince;
@@ -54,12 +54,12 @@ export function silenceLevel({ unansweredSince, now }) {
54
54
  return "normal";
55
55
  }
56
56
 
57
- /**
58
- * 本地日历日的键(`YYYY-MM-DD`)。
59
- *
60
- * 必须用本地时间:用户在 UTC+8 的晚上 11 点与 UTC-8 的早上 7 点是同一天的不同感受,
61
- * 用 UTC 会让"每日"在用户的夜里归零。
62
- */
57
+
58
+
59
+
60
+
61
+
62
+
63
63
  export function localDayKey(at) {
64
64
  const y = at.getFullYear();
65
65
  const m = String(at.getMonth() + 1).padStart(2, "0");
@@ -67,23 +67,23 @@ export function localDayKey(at) {
67
67
  return `${y}-${m}-${d}`;
68
68
  }
69
69
 
70
- /**
71
- * 判断现在能不能发一条主动消息。纯函数,所有输入显式传入——这样每条规则都能单测。
72
- *
73
- * 返回 `{ ok, reason }`:`reason` 只用于日志与诊断,不参与业务。
74
- *
75
- * @param {object} e
76
- * @param {Date} e.now 当前时刻(本地时间)
77
- * @param {number} [e.dailyLimit] 每日上限;0 表示关闭主动消息
78
- * @param {{day: string, count: number}|null} [e.todaySent] 今天已发计数
79
- * @param {number|null} [e.lastSentAt] 上一条主动消息的时间戳(毫秒)
80
- * @param {number} [e.minGapMs] 两条之间最小间隔
81
- * @param {boolean} [e.quiet] 是否处于安静时段(由 shouldSuppressForQuietHours 算出)
82
- * @param {boolean} [e.userActive] 用户最近是否在对话("主人在聊时不插嘴")
83
- * @param {boolean} [e.busy] 有会话正在干活(T-32:不打断正在跑的任务)
84
- * @param {"normal"|"less"|"stopped"} [e.silence] 沉默等级(silenceLevel)
85
- * @param {boolean} [e.paused] 用户手动暂停
86
- */
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
87
  export function canFire({
88
88
  now,
89
89
  dailyLimit = DEFAULT_DAILY_LIMIT,
@@ -106,23 +106,23 @@ export function canFire({
106
106
  if (busy) return { ok: false, reason: "session-busy" };
107
107
  const day = localDayKey(now);
108
108
  const used = todaySent && todaySent.day === day ? todaySent.count : 0;
109
- // 少说:每天至多 1 条。
109
+
110
110
  const limit = silence === "less" ? Math.min(dailyLimit, 1) : dailyLimit;
111
111
  if (used >= limit) return { ok: false, reason: silence === "less" ? "silence-less" : "daily-limit" };
112
112
  if (lastSentAt != null) {
113
113
  const gap = now.getTime() - lastSentAt;
114
- // 时钟往回跳会得到负值——此时不阻塞(否则用户改了系统时间就永久收不到消息了),
115
- // 但把上一条的时间更新掉,见 markSent。
114
+
115
+
116
116
  if (gap >= 0 && gap < minGapMs) return { ok: false, reason: "min-gap" };
117
117
  }
118
118
  return { ok: true, reason: "ok" };
119
119
  }
120
120
 
121
- /**
122
- * 读状态文件。任何损坏都回落到空状态,绝不因为 JSON 坏了而不启动。
123
- *
124
- * @param {string} file
125
- */
121
+
122
+
123
+
124
+
125
+
126
126
  export function readState(file) {
127
127
  try {
128
128
  const raw = readFileSync(file, "utf8");
@@ -151,12 +151,12 @@ export function emptyState() {
151
151
  return { todaySent: null, lastSentAt: null, nextFireAt: null, sentKeys: [], unansweredSince: null, lastReactionAt: null };
152
152
  }
153
153
 
154
- /**
155
- * 原子写状态文件:先写 `.tmp` 再 rename。
156
- *
157
- * 直接覆盖写会在断电/进程被杀时留下半截 JSON,下次启动就丢掉"今天已经发了 3 条"
158
- * 这个事实,于是用户当天被多发几条。rename 在同一文件系统上是原子的。
159
- */
154
+
155
+
156
+
157
+
158
+
159
+
160
160
  export function writeState(file, state) {
161
161
  mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
162
162
  const tmp = `${file}.tmp`;
@@ -164,24 +164,24 @@ export function writeState(file, state) {
164
164
  renameSync(tmp, file);
165
165
  }
166
166
 
167
- /**
168
- * 创建调度器。
169
- *
170
- * @param {object} e
171
- * @param {string} e.dir 状态目录(与口令、memory.db 同层)
172
- * @param {() => Date} [e.now] 时间源(测试注入)
173
- * @param {() => boolean} [e.isQuiet] 当前是否安静时段
174
- * @param {() => boolean} [e.isUserActive] 用户最近是否在对话
175
- * @param {() => boolean} [e.isBusy] 有会话正在干活(T-32)
176
- * @param {() => boolean} [e.isChatting] 用户此刻正在打字对话(T-32 fix:用户自己设的提醒只看这一条与安静时段)
177
- * @param {(ctx: {level: string, now: Date, sentKeys: string[]}) => Promise<{key: string, text: string}|null>} [e.pick]
178
- * 选一条要发的候选;返回 null 表示这次没有值得说的(不记账)。`level` 是沉默等级,
179
- * `sentKeys` 是已经发过的 key,候选来源据此跳过发过的、换下一条。
180
- * @param {(item: {key: string, text: string}) => Promise<void>} [e.deliver]
181
- * 真正发出去的动作(推送/气泡/IM)。
182
- * @param {(e: {reason: string, at: string}) => void} [e.log]
183
- * @param {object} [e.config] `{enabled, dailyLimit, minGapMs, tickMs}`
184
- */
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
185
  export function createProactiveScheduler({
186
186
  dir,
187
187
  now = () => new Date(),
@@ -196,8 +196,8 @@ export function createProactiveScheduler({
196
196
  }) {
197
197
  if (!dir) throw new Error("createProactiveScheduler: dir is required");
198
198
  const file = join(dir, "proactive.json");
199
- // 配置层只保证是数字(项目用的是 schemastery,没有 `.int()`),
200
- // 所以在这里统一取整:`dailyLimit: 2.7` 的含义不该是"发 2.7 条"这种需要猜的东西。
199
+
200
+
201
201
  const dailyLimit = Number.isFinite(config.dailyLimit)
202
202
  ? Math.max(0, Math.floor(config.dailyLimit))
203
203
  : DEFAULT_DAILY_LIMIT;
@@ -212,22 +212,22 @@ export function createProactiveScheduler({
212
212
  let state = readState(file);
213
213
  let timer = null;
214
214
  let stopped = true;
215
- /** 上一次 tick 记下的判据,供诊断读("它现在为什么不说")。 */
215
+
216
216
  let lastReason = "idle";
217
217
 
218
218
  function save() {
219
219
  try {
220
220
  writeState(file, state);
221
221
  } catch (err) {
222
- // 落盘失败不能让调度器停摆:内存里的计数照旧生效,重启后最多多发一条。
222
+
223
223
  log({ reason: `save-failed:${err?.message ?? err}`, at: now().toISOString() });
224
224
  }
225
225
  }
226
226
 
227
- /**
228
- * 记一次已发:更新当日计数、最后发送时间、已发 key。
229
- * 用户自己设的提醒(kind "due")不算主动开口,不进沉默计时。
230
- */
227
+
228
+
229
+
230
+
231
231
  function markSent(item, at) {
232
232
  const day = localDayKey(at);
233
233
  const used = state.todaySent && state.todaySent.day === day
@@ -238,24 +238,24 @@ export function createProactiveScheduler({
238
238
  todaySent: { day, count: used + 1 },
239
239
  lastSentAt: at.getTime(),
240
240
  sentKeys: [...state.sentKeys, item.key].slice(-200),
241
- // 沉默计时从「回应之后的第一条」开始;后面再发不重置起点。
241
+
242
242
  unansweredSince: item.kind === "due" ? state.unansweredSince : (state.unansweredSince ?? at.getTime()),
243
243
  };
244
244
  save();
245
245
  }
246
246
 
247
- /** 用户有任何操作 = 回应了:沉默计时清零(T-32)。 */
247
+
248
248
  function noteReaction(at = now()) {
249
249
  if (state.unansweredSince == null && state.lastReactionAt != null && at.getTime() - state.lastReactionAt < 60_000) return;
250
250
  state = { ...state, unansweredSince: null, lastReactionAt: at.getTime() };
251
251
  save();
252
252
  }
253
253
 
254
- /**
255
- * 一次 tick:重算"现在该不该发",该发就选一条并投递。
256
- *
257
- * 这个函数是**可重入安全**的:并发调用时后到的那个会看到 `inFlight`,直接返回。
258
- */
254
+
255
+
256
+
257
+
258
+
259
259
  let inFlight = false;
260
260
  async function tick() {
261
261
  if (inFlight) return { fired: false, reason: "in-flight" };
@@ -276,20 +276,20 @@ export function createProactiveScheduler({
276
276
  silence: level,
277
277
  paused: Boolean(state.paused),
278
278
  });
279
- // T-32 fix: a reminder the user set is not proactive chatter. When the full gate says no
280
- // only because of idleness, a busy session, the daily allowance, the gap or silence decay,
281
- // it may still go out, as long as the user is not chatting right now (quiet hours, pause
282
- // and "off" always hold). pick() is asked for due reminders only, and anything else it
283
- // returns is ignored.
279
+
280
+
281
+
282
+
283
+
284
284
  let dueOnly = false;
285
285
  if (!gate.ok) {
286
- // A-35: decided from quiet hours, pause and "off" directly, not from the full gate's first
287
- // reason: after 7 silent days that reason is "silence-stopped" (checked before quiet hours),
288
- // and a due reminder went out at 03:00.
286
+
287
+
288
+
289
289
  const lighter = !["paused", "disabled", "quiet-hours"].includes(gate.reason) && !state.paused && !isQuiet() && !isChatting();
290
290
  if (!lighter) {
291
291
  lastReason = gate.reason;
292
- // 闸门没过也要把"下一次该检查的时间"落盘:诊断页据此显示"它什么时候会再想说话"。
292
+
293
293
  state = { ...state, nextFireAt: at.getTime() + tickMs };
294
294
  save();
295
295
  return { fired: false, reason: gate.reason };
@@ -312,7 +312,7 @@ export function createProactiveScheduler({
312
312
  return { fired: false, reason: "nothing-to-say" };
313
313
  }
314
314
  if (state.sentKeys.includes(item.key)) {
315
- // 同一条候选发过:不要重复。"没有新的"不等于"可以重复"。
315
+
316
316
  lastReason = "already-sent";
317
317
  state = { ...state, nextFireAt: at.getTime() + tickMs };
318
318
  save();
@@ -322,7 +322,7 @@ export function createProactiveScheduler({
322
322
  await deliver(item);
323
323
  markSent(item, at);
324
324
  lastReason = "sent";
325
- // 下一条最早也要等到最小间隔之后。
325
+
326
326
  state = { ...state, nextFireAt: at.getTime() + minGapMs };
327
327
  save();
328
328
  log({ reason: `sent:${item.key}`, at: at.toISOString() });
@@ -342,9 +342,9 @@ export function createProactiveScheduler({
342
342
  timer = setInterval(() => {
343
343
  void tick();
344
344
  }, tickMs);
345
- // 不要让调度器把宿主进程的退出拖住。
345
+
346
346
  timer.unref?.();
347
- // 启动时立刻跑一次:合盖一整晚之后不该再等一个完整 tick。
347
+
348
348
  void tick();
349
349
  }
350
350
 
@@ -359,10 +359,10 @@ export function createProactiveScheduler({
359
359
  start,
360
360
  stop,
361
361
  tick,
362
- /** 只读快照:诊断页/测试用。 */
362
+
363
363
  snapshot: () => ({ ...state, lastReason, enabled, silence: silenceLevel({ unansweredSince: state.unansweredSince, now: now() }) }),
364
364
  noteReaction,
365
- /** 手动暂停/继续(App 或设置页可调)。 */
365
+
366
366
  setPaused: (v) => {
367
367
  state = { ...state, paused: Boolean(v) };
368
368
  save();