wechat-clawbot 1.2.0 → 1.3.1

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 (73) hide show
  1. package/README.md +26 -13
  2. package/README.zh.md +26 -13
  3. package/assets/icon.svg +7 -0
  4. package/cordis.patch.yml +4 -0
  5. package/lib/backlog.d.ts +14 -0
  6. package/lib/backlog.d.ts.map +1 -1
  7. package/lib/backlog.js +65 -4
  8. package/lib/backlog.js.map +1 -1
  9. package/lib/bridge.d.ts +6 -3
  10. package/lib/bridge.d.ts.map +1 -1
  11. package/lib/bridge.js +44 -11
  12. package/lib/bridge.js.map +1 -1
  13. package/lib/claude-peer.js +11 -11
  14. package/lib/claude-peer.js.map +1 -1
  15. package/lib/client.js +461 -85
  16. package/lib/codex-rpc.js +1 -1
  17. package/lib/config.d.ts +30 -7
  18. package/lib/config.d.ts.map +1 -1
  19. package/lib/config.js +17 -3
  20. package/lib/config.js.map +1 -1
  21. package/lib/idle-compact.d.ts +5 -0
  22. package/lib/idle-compact.d.ts.map +1 -1
  23. package/lib/idle-compact.js +10 -8
  24. package/lib/idle-compact.js.map +1 -1
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js +78 -28
  27. package/lib/index.js.map +1 -1
  28. package/lib/localtime.d.ts +4 -3
  29. package/lib/localtime.d.ts.map +1 -1
  30. package/lib/localtime.js +7 -6
  31. package/lib/localtime.js.map +1 -1
  32. package/lib/mac-alarms.d.ts +168 -0
  33. package/lib/mac-alarms.d.ts.map +1 -0
  34. package/lib/mac-alarms.js +612 -0
  35. package/lib/mac-alarms.js.map +1 -0
  36. package/lib/mac-calendar.d.ts +126 -11
  37. package/lib/mac-calendar.d.ts.map +1 -1
  38. package/lib/mac-calendar.js +418 -99
  39. package/lib/mac-calendar.js.map +1 -1
  40. package/lib/mcp-route.d.ts.map +1 -1
  41. package/lib/mcp-route.js +8 -2
  42. package/lib/mcp-route.js.map +1 -1
  43. package/lib/mcp-server.js +1 -1
  44. package/lib/memory-auto.js +4 -4
  45. package/lib/memory-auto.js.map +1 -1
  46. package/lib/models-route.d.ts +1 -1
  47. package/lib/pending.d.ts +9 -1
  48. package/lib/pending.d.ts.map +1 -1
  49. package/lib/pending.js +18 -1
  50. package/lib/pending.js.map +1 -1
  51. package/lib/permissions.d.ts +164 -0
  52. package/lib/permissions.d.ts.map +1 -0
  53. package/lib/permissions.js +549 -0
  54. package/lib/permissions.js.map +1 -0
  55. package/lib/prompt.d.ts.map +1 -1
  56. package/lib/prompt.js +12 -11
  57. package/lib/prompt.js.map +1 -1
  58. package/lib/secretary.d.ts +42 -9
  59. package/lib/secretary.d.ts.map +1 -1
  60. package/lib/secretary.js +142 -36
  61. package/lib/secretary.js.map +1 -1
  62. package/lib/time-context.d.ts +57 -0
  63. package/lib/time-context.d.ts.map +1 -0
  64. package/lib/time-context.js +90 -0
  65. package/lib/time-context.js.map +1 -0
  66. package/lib/tool.js +1 -1
  67. package/lib/typing.d.ts +0 -1
  68. package/lib/typing.d.ts.map +1 -1
  69. package/lib/typing.js +7 -1
  70. package/lib/typing.js.map +1 -1
  71. package/native/macos-calendar/main.swift +476 -13
  72. package/package.json +7 -6
  73. package/wechat-clawbot-INSTALL.md +64 -40
package/lib/client.js CHANGED
@@ -64,7 +64,7 @@ window.__ModuleLoader__.load({
64
64
  })();
65
65
  const react = require("react");
66
66
  const h = react.createElement;
67
- const { useState, useEffect } = react;
67
+ const { useState, useEffect, useRef } = react;
68
68
 
69
69
  /** Loader entry id; since DSH 0.1.7 also the settings form id. */
70
70
  const NAMESPACE = "clawbot";
@@ -75,6 +75,11 @@ window.__ModuleLoader__.load({
75
75
  const BRIDGE_URL = "/plugins/clawbot/mcp/status";
76
76
  const CALENDAR_URL = "/plugins/clawbot/calendar/status";
77
77
  const MEMORY_OPEN_URL = "/plugins/clawbot/memory/open";
78
+ const AUTHORIZE_URL = "/plugins/clawbot/secretary/authorize";
79
+ const TEST_ALARM_URL = "/plugins/clawbot/secretary/test-alarm";
80
+ const PERMISSIONS_URL = "/plugins/clawbot/permissions";
81
+ const PERMISSIONS_SETTINGS_URL = "/plugins/clawbot/permissions/open-settings";
82
+ const PERMISSIONS_REVEAL_URL = "/plugins/clawbot/permissions/reveal";
78
83
 
79
84
  const cls = (n) => `clawbot-${n}`;
80
85
  const S = {
@@ -85,7 +90,7 @@ window.__ModuleLoader__.load({
85
90
  reset: cls("reset"), input: cls("input"), area: cls("area"), hint: cls("hint"),
86
91
  switch: cls("switch"), switchOn: cls("switch-on"), knob: cls("knob"),
87
92
  footer: cls("footer"), note: cls("note"), button: cls("button"),
88
- failed: cls("failed"),
93
+ failed: cls("failed"), actions: cls("actions"), attention: cls("attention"),
89
94
  };
90
95
 
91
96
  let stylesInjected = false;
@@ -171,6 +176,9 @@ window.__ModuleLoader__.load({
171
176
  border-color: var(--dsw-alias-label-dimmed); }
172
177
  .${S.button}:disabled { opacity: .4; cursor: default; }
173
178
  .${S.failed} { color: var(--dsw-alias-state-error-primary); font-size: 12px; line-height: 1.5; }
179
+ .${S.actions} { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
180
+ .${S.attention} { color: var(--dsw-alias-state-warn-label, var(--dsw-alias-state-warn-primary));
181
+ font-size: 12px; line-height: 1.5; }
174
182
  `;
175
183
  document.head.appendChild(el);
176
184
  }
@@ -215,6 +223,43 @@ window.__ModuleLoader__.load({
215
223
  return `${Math.round(secs / 86400)} 天前`;
216
224
  }
217
225
 
226
+ /**
227
+ * GET one of the card's status routes. With no answer to show it rejects
228
+ * with { status, message, platform }; status is missing when DSH was not
229
+ * reached at all, platform unless the route said which system DSH runs on.
230
+ */
231
+ function getStatus(url) {
232
+ return fetch(url, { headers: { accept: "application/json" } }).then(async (r) => {
233
+ const d = await r.json().catch(() => null);
234
+ if (r.ok && d && d.ok) return d;
235
+ throw {
236
+ status: r.status,
237
+ message: d && typeof d.message === "string" ? d.message : undefined,
238
+ platform: d && typeof d.platform === "string" ? d.platform : undefined,
239
+ };
240
+ });
241
+ }
242
+
243
+ /**
244
+ * What a status row keeps when getStatus has no answer (not `failed`: the card has a state by that name).
245
+ * `hostPlatform`: the system DSH runs on, when a refusal said so — kept apart from `platform`, which is an answer's.
246
+ */
247
+ function noAnswer(e) {
248
+ if (!e || typeof e.status !== "number") return { unreachable: true };
249
+ return { unreachable: true, status: e.status, message: e.message, ...(e.platform ? { hostPlatform: e.platform } : {}) };
250
+ }
251
+
252
+ /**
253
+ * A status row's words when there is no answer. 403 is not a missing route:
254
+ * these routes name programs and paths, so they answer only a page opened on
255
+ * DSH's own computer, and a restart changes nothing.
256
+ */
257
+ function unreachableText(s) {
258
+ if (s.status === 403) return "这一项只在运行 DSH 的那台电脑上能看(在那台电脑上用 127.0.0.1 打开这个页面)";
259
+ if (s.status >= 500 && s.message) return `状态读不到:${s.message}`;
260
+ return "状态读不到(路由没注册?DSH 可能需要重启)";
261
+ }
262
+
218
263
  /**
219
264
  * What the bridge row says under its switch.
220
265
  *
@@ -225,7 +270,7 @@ window.__ModuleLoader__.load({
225
270
  */
226
271
  function bridgeHint(bridge) {
227
272
  if (bridge === null) return "读取状态…";
228
- if (bridge.unreachable === true) return "状态读不到(路由没注册?DSH 可能需要重启)";
273
+ if (bridge.unreachable === true) return unreachableText(bridge);
229
274
  if (bridge.enabled !== true) return "已关闭:MCP 路由都返回 403。开关立刻生效,不用重启";
230
275
  if (bridge.tokenReady !== true) return `token 还没生成(${bridge.tokenPath})`;
231
276
  const rejected = bridge.rejected > 0 ? `;另有 ${bridge.rejected} 次 token 不对被拒` : "";
@@ -235,54 +280,197 @@ window.__ModuleLoader__.load({
235
280
  return `MCP 客户端已调用 ${bridge.calls} 次,最近一次 ${ago(bridge.lastCallAt)}(${bridge.lastRoute})${rejected}`;
236
281
  }
237
282
 
283
+ /** One Mac permission as a short phrase. */
284
+ function grant(state, what, app) {
285
+ switch (state) {
286
+ case "fullAccess": return `${what}已授权`;
287
+ case "notDetermined": return `${what}还没授权`;
288
+ // 隐私与安全: macOS 27's name, and the start of 隐私与安全性 (macOS 13–26).
289
+ case "denied": return `${what}被拒绝了(系统设置 → 隐私与安全 → ${what} 里打开「${app}」)`;
290
+ case "writeOnly": return `${what}只有「仅添加」(系统设置 → 隐私与安全 → ${what} 里改成完全访问)`;
291
+ case "restricted": return `${what}被这台 Mac 的管理策略限制了`;
292
+ case "outdated": return `${what}:要先更新小程序`;
293
+ default: return `${what}:${state || "读取中"}`;
294
+ }
295
+ }
296
+
238
297
  /**
239
- * What the calendar row says under its switch. The interesting states are the
240
- * ones that need the owner at the Mac: the permission prompt, or a refusal
241
- * that only System Settings can undo.
298
+ * What the 全天候秘书 row says. The states that need the owner at the Mac
299
+ * come first (a prompt on screen, an outdated helper, a refusal): that is
300
+ * what has to be done before walking away from it.
242
301
  */
243
- function calendarHint(status, name, on) {
244
- const base = "打开后 bot 能读取 Mac「日历」里所有账户的日程(含备注),在这个专用日历里自主加、改、删;"
245
- + "动别的日历会先在微信里问你。关着时不占 token。改开关会重启微信监听";
302
+ function assistantHint(status, name, on) {
303
+ const base = "打开后,bot 能读 Mac「日历」里所有账户的日程(含备注),在专用日历里自己安排,还能设闹钟(紧急提醒,到点像闹钟一样响,不靠微信)。"
304
+ + "闹钟要 macOS 26.2 和 iOS 26.2 或更新。排日程、定闹钟的规则写在 memory.md 的「## 全天候秘书」一节,可以直接改。"
305
+ + "仅 macOS,关着时不占 token。打开时(或之后点「一键授权」)Mac 上会弹出「日历」和「提醒事项」两个授权"
306
+ + "(macOS 早于 26.2 时只有「日历」),要在 Mac 前点「允许」";
246
307
  if (status === null) return base;
247
- if (status.unreachable === true) return "状态读不到(路由没注册?DSH 可能需要重启)";
308
+ if (status.unreachable === true) return unreachableText(status);
248
309
  if (status.mac === false) return "只支持 macOS";
249
310
  if (!on) return name ? base : `先填专用日历的名字,再打开开关。${base}`;
250
- if (status.others > 0) return "白名单里还有别人:大家共用这一个对话,日历内容会被看到,所以日历工具不开放";
251
- if (status.error && status.authorization !== "fullAccess") return `还没就绪:${status.error}`;
311
+ if (!name) return "先在上面填专用日历的名字(闹钟清单第一次也按它起名),bot 才能排日程、定闹钟";
312
+ if (status.others > 0) return "白名单里还有别人:大家共用这一个对话,日历和闹钟会被看到,所以这些工具不开放";
252
313
  const app = status.helper || "Clawbot-Calendar";
253
- if (status.prompting) return `等你在 Mac 上点「允许」:屏幕上有「${app}」想要访问日历的窗口`;
254
- switch (status.authorization) {
255
- case "fullAccess": {
256
- const own = status.dedicated && status.dedicated.name === name
257
- ? `专用日历「${name}」在「${status.dedicated.account || "本机"}」`
258
- : `专用日历「${name}」第一次添加时创建(优先建在 iCloud;和已有日历重名会先在微信里问你)`;
259
- return `已授权,能看到 ${status.calendars ?? "?"} 个日历(${status.accounts ?? "?"} 个账户)。${own};`
260
- + "改名字会另用一个日历,旧的不会删";
261
- }
262
- case "notDetermined":
263
- return `等你在 Mac 上点「允许」:屏幕上应该有「${app}」想要访问日历的窗口。`
264
- + "没看到就去 系统设置 → 隐私与安全性 → 日历";
265
- case "denied":
266
- return `授权被拒绝了:在 系统设置 → 隐私与安全性 → 日历 里打开「${app}」`;
267
- case "writeOnly":
268
- return `「${app}」只有「仅添加」权限,读不到日程:在 系统设置 → 隐私与安全性 → 日历 里改成完全访问`;
269
- case "restricted":
270
- return "这台 Mac 的日历访问被管理策略限制了";
271
- default:
272
- return status.built === false ? `正在准备「${app}」(第一次要编译,约一分钟)…` : "读取状态…";
314
+ if (status.preparing && status.built === false && !status.stale) {
315
+ return `正在准备「${app}」(第一次要编译,约一分钟),之后 Mac 上会弹出授权窗口`;
316
+ }
317
+ if (status.prompting) {
318
+ const names = { calendar: "「日历」", reminders: "「提醒事项」" };
319
+ const which = (status.waitingFor || []).map((k) => names[k]).join("、");
320
+ return `等你在 Mac 上点「允许」:屏幕上有「${app}」的${which || ""}授权窗口(可能被别的窗口挡住)`;
273
321
  }
322
+ if (status.preparing) return `正在准备「${app}」…`;
323
+ if (status.error && status.authorization !== "fullAccess") return `还没就绪:${status.error}`;
324
+ if (status.built === false && !status.stale) return `「${app}」还没编译:点「一键授权」`;
325
+ const unsupported = status.alarms === "unsupported";
326
+ const lines = [];
327
+ if (status.updateError) lines.push(`小程序更新没成功(旧版照常能用):${status.updateError}`);
328
+ else if (status.outdated) {
329
+ // Protocol 1 has no alarms at all; protocol 2 has them, and only misses the newer pieces.
330
+ lines.push(`${(status.protocol ?? 1) < 2 ? "小程序要更新才能用闹钟" : "小程序有更新"}:到 Mac 前点「一键授权」`
331
+ + "(更新后「日历」「提醒事项」都要在 Mac 上再点一次「允许」,不在 Mac 前就先别点,日历会停到点了「允许」为止)");
332
+ }
333
+ lines.push(unsupported
334
+ ? `${grant(status.authorization, "日历", app)};这台 Mac 的系统没有紧急提醒(要 macOS 26.2 或更新),闹钟用不了`
335
+ : `${grant(status.authorization, "日历", app)};${grant(status.reminders, "提醒事项", app)}`);
336
+ if (status.authorization === "fullAccess") {
337
+ lines.push(status.dedicated && status.dedicated.name === name
338
+ ? `专用日历「${name}」在「${status.dedicated.account || "本机"}」,能看到 ${status.calendars ?? "?"} 个日历`
339
+ : `专用日历「${name}」第一次用到时创建(优先建在 iCloud)`);
340
+ }
341
+ if (status.reminders === "fullAccess" && !unsupported) {
342
+ lines.push(status.alarmList
343
+ ? `闹钟清单「${status.alarmList.name}」在「${status.alarmList.account || "iCloud"}」(改了名字也继续用它)`
344
+ : `闹钟清单「${name} 闹钟」第一次设闹钟时创建`);
345
+ }
346
+ if (status.secretaryOn === false) {
347
+ lines.push("排日程的规则没开(配置里 secretary 是关的):日历和闹钟照常能用;要那套规则,就把开关关掉再打开一次"
348
+ + (status.outdated ? "(在 Mac 前做:重新打开会顺便更新小程序、弹出授权)" : ""));
349
+ } else if (status.secretary === false) {
350
+ lines.push("memory.md 里没找到「## 全天候秘书」一节:关掉再打开一次就会放回去");
351
+ }
352
+ const undecided = status.authorization === "notDetermined" || (!unsupported && status.reminders === "notDetermined");
353
+ const ready = status.authorization === "fullAccess" && !status.outdated
354
+ && (unsupported || status.reminders === "fullAccess");
355
+ if (ready && !unsupported) {
356
+ lines.push("闹钟只在「查找」里作为“我的位置”的那台设备上像闹钟一样响(一般是 iPhone);iPhone 上还要先在「提醒事项」里"
357
+ + "手动把一条提醒设成「紧急」一次、允许弹出的授权,闹钟才会响(之后在「设置 → App → 提醒事项」的「闹钟」里能看到它)。点「测试闹钟」试响一次");
358
+ } else if (undecided) {
359
+ lines.push("缺的授权到 Mac 前点「一键授权」补上;都允许之后点「测试闹钟」试响一次");
360
+ }
361
+ return lines.join("。");
362
+ }
363
+
364
+ /** What 一键授权 answered it is doing (the route's plan). */
365
+ function authorizeText(d) {
366
+ const p = (d && d.plan) || {};
367
+ const names = { calendar: "「日历」", reminders: "「提醒事项」" };
368
+ const list = (keys) => (keys || []).map((k) => names[k] || k).join("、");
369
+ const parts = [];
370
+ if (p.build === "first") parts.push("先编译小程序(第一次要一两分钟)");
371
+ if (p.build === "update") parts.push("先更新小程序(更新后两个授权都要重新点)");
372
+ if ((p.ask || []).length > 0) {
373
+ parts.push(`Mac 屏幕上会弹出${list(p.ask)}的授权窗口(可能被别的窗口挡住),都点「允许」`);
374
+ } else if (p.error) {
375
+ parts.push(`小程序这次没有回应(${p.error}):过一会儿再点一次「一键授权」`);
376
+ }
377
+ if ((p.denied || []).length > 0) {
378
+ parts.push(`${list(p.denied)}之前被拒绝了,只能在 系统设置 → 隐私与安全 里打开「Clawbot-Calendar」`);
379
+ }
380
+ if (p.alarmsUnsupported) parts.push("这台 Mac 的系统没有紧急提醒,闹钟用不了(日历不受影响)");
381
+ return parts.length > 0 ? parts.join(";") : "都已经授权了,不用再点";
274
382
  }
275
383
 
276
- /** What the secretary row says: what the switch does, and whether the rules are in memory now. */
277
- function secretaryHint(status, on, calendarOn) {
278
- const what = "把一套排日程的规则写进长期记忆(memory.md 里的「## 日程秘书」一节):你说待办、截止时间,"
279
- + "bot 先查日历再排进专用日历,回复只说几点做什么、挪走了什么。规则可以直接在 memory.md 里改;"
280
- + "关掉时移出记忆并留一份副本,再打开原样放回";
281
- if (!calendarOn) return on ? "Mac 日历关着,秘书暂停(规则已移出记忆);打开日历后自动恢复" : `要先打开 Mac 日历。${what}`;
282
- if (!on) return what;
283
- if (status && status.secretary === true) return "已开:规则在 memory.md 的「## 日程秘书」一节,可以直接改,下一条消息生效";
284
- if (status && status.secretary === false) return "已开,但 memory.md 里没找到「## 日程秘书」一节:关掉再打开一次就会放回去";
285
- return what;
384
+ /** Whether this page is open on the computer DSH runs on: the 电脑权限 buttons act on that computer. */
385
+ function onThisComputer() {
386
+ if (typeof location === "undefined" || location.protocol === "dsh-app:") return true;
387
+ const host = location.hostname;
388
+ return host === "localhost" || host === "[::1]" || host === "::1" || /^127(?:\.\d{1,3}){3}$/.test(host);
389
+ }
390
+
391
+ /**
392
+ * How the card names what DSH's access is held against: 「终端」(Terminal),
393
+ * 「DSH小鲸鱼」(DSHWhale.app) — Finder lists a bundle by its file name, which
394
+ * can differ from the app's own name — 「node」…, or null when it is not known.
395
+ */
396
+ function starterName(l) {
397
+ if (!l || l.kind === "unknown") return null;
398
+ if (l.kind !== "app") return `「${l.name}」`;
399
+ const file = (l.file || "").replace(/\.app$/, "");
400
+ const also = [];
401
+ if (l.localName) also.push(l.name);
402
+ if (file !== "" && file !== l.name && file !== l.localName) also.push(l.file);
403
+ return `「${l.localName || l.name}」${also.length > 0 ? `(${also.join(",")})` : ""}`;
404
+ }
405
+
406
+ /** The name Finder shows for it, for the 在访达中显示 button. */
407
+ function finderName(l) {
408
+ if (l.kind !== "app") return l.name;
409
+ return l.localName || (l.file ? l.file.replace(/\.app$/, "") : l.name);
410
+ }
411
+
412
+ /**
413
+ * The 电脑权限 row. On a Mac the bot's file access belongs to whatever started
414
+ * DSH (or to DSH's own program), so the text names it; without Full Disk
415
+ * Access every protected folder puts a dialog on the Mac's screen, and the bot
416
+ * waits for someone to click. System Settings' words are quoted as they read
417
+ * in Chinese (「完全磁盘访问权限」, 「以后」).
418
+ */
419
+ function permissionHint(p, here) {
420
+ if (p === null) return "读取中…";
421
+ if (p.unreachable === true) return unreachableText(p);
422
+ const away = here ? "" : "。下面的按钮在运行 DSH 的那台电脑上打开";
423
+ if (p.platform === "win32") {
424
+ const base = "Windows 不用单独授权:bot 能读你能读的所有文件,不会弹窗问";
425
+ if (p.folderGuard !== "on") return base;
426
+ // Windows Security has used both names over the years; English too, in case it renames them again.
427
+ return `${base}。不过这台电脑开着「文件夹限制访问」(勒索软件防护,也叫「受控文件夹访问」,英文 Controlled folder access):`
428
+ + "bot 在文档、图片、视频、音乐这些受保护的文件夹(桌面通常也在内)里新建、修改文件会被拦(读不受影响),"
429
+ + "Windows 安全中心会弹出「未经授权的更改被阻止」。"
430
+ + `被拦的主要是两个程序:DSH 自己的读写工具算 ${p.program},bot 跑的命令算 PowerShell(装了 PowerShell 7 是 pwsh.exe,否则是 powershell.exe);`
431
+ + "命令里再运行的其他程序也可能按它自己的名字被拦。"
432
+ + "要放行,点「打开 Windows 安全中心」→「通过文件夹限制访问允许某个应用」→「添加允许的应用」→「最近阻止的应用」,把列出的这些加进去"
433
+ + "(会弹出用户帐户控制,要管理员确认);加好以后重启一次 DSH(桌面版退出再打开),DSH 自己的工具才放行。"
434
+ // DSH's own program is node.exe under `dsh web`, the app itself under DSH Desktop.
435
+ + `注意:放行 PowerShell 或 ${String(p.program || "node.exe").split(/[\\/]/).pop()},等于让用它们运行的所有脚本都能改这些文件夹;`
436
+ + `不想放行,就让 bot 把文件存到别处(「下载」默认不受保护)${away}`;
437
+ }
438
+ if (p.platform !== "darwin") return "这台电脑不用单独授权";
439
+ const l = p.launcher || { kind: "unknown" };
440
+ const who = starterName(l);
441
+ const holder = l.kind === "program" && l.own ? ` DSH 自己的程序${who}` : `启动 DSH 的程序${who || ""}`;
442
+ const unsigned = l.signing === "adhoc" || l.signing === "unsigned";
443
+ const unstable = who !== null && unsigned ? `${who}没有正式签名:它每更新一次,macOS 就当它是新程序,要回这里再开一次` : null;
444
+ if (p.fullDisk === "granted") {
445
+ const lines = [`完全磁盘访问权限已开${who ? `(开给了${who})` : ""}:bot 读下载、桌面、文稿、照片图库都不会再弹窗`];
446
+ if (p.fullDiskHere === "denied") lines.push("DSH 是在开之前启动的,它自己的读文件工具要重启一次 DSH 才用得上(bot 跑的命令已经可以了)");
447
+ if (unstable) lines.push(unstable);
448
+ return lines.join("。");
449
+ }
450
+ const lines = [p.fullDisk === "denied"
451
+ ? `还没开「完全磁盘访问权限」:macOS 把 bot 读文件的授权算在${holder}头上。没开时 bot 每进一个受保护的文件夹`
452
+ + "(下载、桌面、文稿、照片图库……),Mac 上都会弹窗,没人点「允许」它就一直卡着"
453
+ : `查不出「完全磁盘访问权限」开没开(探测没有得到回答)${who ? `;要开就开给${holder}` : ""}`];
454
+ const admin = "(要管理员确认一次:触控 ID 或登录密码)";
455
+ if (l.kind === "app") {
456
+ // "Quit & Reopen" on Terminal or DSH Desktop would take DSH down with it; the bot's
457
+ // commands are new processes and have the access at once, so 以后 (Later) is enough.
458
+ lines.push(`点「打开设置」,在列表里把它打开;列表里没有就点「+」添加,或者把访达里选中的它拖进去${admin}。`
459
+ + "提示「…将无法完全访问磁盘,直至退出」时点「以后」(英文系统是 Later),不要点「退出并重新打开」。开好后这里会自动变成「已开」");
460
+ if (!l.dsh) lines.push("注意:开了以后,在它里面运行的其他程序也都能读你的全部文件");
461
+ if (unstable) lines.push(unstable);
462
+ } else if (l.kind === "program") {
463
+ // The card's own probe leaves it in the list, switched off — next to any other node of the same name.
464
+ lines.push(`它是 ${l.path}${l.own ? "(macOS 没把它算在哪个 App 头上:DSH 由 launchd 直接运行,或者启动它的程序把授权交给了 DSH 自己,都是这样)" : ""}。`
465
+ + `点「打开设置」:列表里多半已经有一个关着的「${l.name}」(同名的可能不止一个,要的是这个路径),把它打开;`
466
+ + `没有就点「+」,按 ⌘⇧G 粘贴这个路径${admin}。`
467
+ + (unsigned ? "它没有正式签名,每更新一次都要回来重新开" : "换了版本、路径变了要重新开"));
468
+ lines.push(`注意:开了以后,不经过 App、直接用这个「${l.name}」运行的其他程序也都能读你的全部文件`);
469
+ } else {
470
+ lines.push(`没认出启动 DSH 的程序(${l.reason || "原因不明"}):在终端里运行就给「终端」,用 DSH 桌面版就给「DeepSeek Harness」,`
471
+ + `用小鲸鱼就给「DSH小鲸鱼」(DSHWhale.app)${p.own ? `,由 launchd 直接运行就给 DSH 自己的程序 ${p.own}` : ""}。点「打开设置」去开`);
472
+ }
473
+ return lines.join("。") + away;
286
474
  }
287
475
 
288
476
  function Switch(props) {
@@ -313,6 +501,20 @@ window.__ModuleLoader__.load({
313
501
  const [calName, setCalName] = useState(null);
314
502
  // The "打开 memory.md" button: null, "opening", "opened", or what went wrong.
315
503
  const [memoryOpen, setMemoryOpen] = useState(null);
504
+ // 一键授权 / 测试闹钟: { busy, text, kind, at } while one runs and after it answered; cleared once stale.
505
+ const [action, setAction] = useState(null);
506
+ // Bumped to look at the calendar status again at once (after 一键授权).
507
+ const [poke, setPoke] = useState(0);
508
+ // The 电脑权限 row: what started DSH and whether it has Full Disk Access (macOS),
509
+ // or Controlled folder access (Windows). null until the first answer.
510
+ const [perm, setPerm] = useState(null);
511
+ // 打开设置 / 在访达中显示: { busy, text, at } while one runs and for a while after.
512
+ const [permAction, setPermAction] = useState(null);
513
+ // Set at the click itself: two clicks before React re-renders would both still see permAction idle.
514
+ const permPressing = useRef(false);
515
+ // The switch, before the early return below: flipping it looks again at once
516
+ // (the off state counts as settled, so the next look would be a minute away).
517
+ const calendarOn = Boolean(state && state.value && state.value.macCalendar === true);
316
518
 
317
519
  // The model catalogue is a server fact, fetched the first time the card is
318
520
  // opened rather than on mount: it costs one resolveModelInfo per model, and
@@ -334,10 +536,9 @@ window.__ModuleLoader__.load({
334
536
  if (!open) return;
335
537
  let alive = true;
336
538
  const load = () => {
337
- fetch(BRIDGE_URL, { headers: { accept: "application/json" } })
338
- .then((r) => (r.ok ? r.json() : Promise.reject(new Error(`HTTP ${r.status}`))))
339
- .then((d) => { if (alive && d && d.ok) setBridge(d); })
340
- .catch(() => { if (alive) setBridge({ unreachable: true }); });
539
+ getStatus(BRIDGE_URL)
540
+ .then((d) => { if (alive) setBridge(d); })
541
+ .catch((e) => { if (alive) setBridge(noAnswer(e)); });
341
542
  };
342
543
  load();
343
544
  const timer = setInterval(load, 5000);
@@ -352,17 +553,80 @@ window.__ModuleLoader__.load({
352
553
  let timer = null;
353
554
  // Fast while the permission is still being decided, slow once it has
354
555
  // settled (or the switch is off): every look launches the helper app.
556
+ const final = ["fullAccess", "denied", "restricted", "writeOnly"];
355
557
  const settled = (d) => d && (d.enabled !== true
356
- || ["fullAccess", "denied", "restricted", "writeOnly"].includes(d.authorization));
558
+ || (final.includes(d.authorization)
559
+ && (final.includes(d.reminders) || d.reminders === "outdated" || d.alarms === "unsupported")
560
+ && d.preparing !== true && d.prompting !== true));
357
561
  const next = (d) => { if (alive) timer = setTimeout(tick, settled(d) ? 60000 : 10000); };
358
562
  const tick = () => {
359
- fetch(CALENDAR_URL, { headers: { accept: "application/json" } })
360
- .then((r) => (r.ok ? r.json() : Promise.reject(new Error(`HTTP ${r.status}`))))
361
- .then((d) => { if (!alive) return; if (d && d.ok) setCalendar(d); next(d && d.ok ? d : null); })
362
- .catch(() => { if (alive) { setCalendar({ unreachable: true }); next(null); } });
563
+ getStatus(CALENDAR_URL)
564
+ .then((d) => {
565
+ if (!alive) return;
566
+ setCalendar(d);
567
+ // 一键授权's answer describes a round: once that round is over, the live hint says the rest.
568
+ if (d.preparing !== true && d.prompting !== true) {
569
+ setAction((a) => (a && !a.busy && a.kind === "authorize" && Date.now() - a.at > 3000 ? null : a));
570
+ }
571
+ next(d);
572
+ })
573
+ .catch((e) => { if (alive) { setCalendar(noAnswer(e)); next(null); } });
363
574
  };
364
575
  tick();
365
576
  return () => { alive = false; if (timer) clearTimeout(timer); };
577
+ }, [open, poke, calendarOn]);
578
+
579
+ // Full Disk Access is given in System Settings, outside this page. One look even
580
+ // while the card is folded (the header says when it is missing); while open, a
581
+ // look every few seconds until it is there, and whenever the window gets focus
582
+ // back — so the row turns 已开 by itself once the owner has switched it on.
583
+ useEffect(() => {
584
+ let alive = true;
585
+ let timer = null;
586
+ // The pace an answer calls for: every few seconds while Full Disk Access is missing, else a minute.
587
+ // A look that got nothing back (DSH restarting, a dropped connection) is tried again in a few
588
+ // seconds, so the row does not say 状态读不到 for a minute after DSH is back; a refusal (403:
589
+ // this page is not on DSH's computer) is an answer of its own and keeps the pace.
590
+ let waiting = false;
591
+ // Looks overlap (the timer and a focus); only an answer newer than the one shown counts.
592
+ let asked = 0;
593
+ let shown = 0;
594
+ const next = (d, retry) => {
595
+ if (!alive || !open) return;
596
+ if (timer !== null) clearTimeout(timer);
597
+ if (d !== null) waiting = d.platform === "darwin" && d.fullDisk !== "granted";
598
+ timer = setTimeout(tick, retry ? 5000 : waiting ? 4000 : 60000);
599
+ };
600
+ const tick = () => {
601
+ const n = ++asked;
602
+ const fresh = () => {
603
+ if (!alive || n <= shown) return false;
604
+ shown = n;
605
+ return true;
606
+ };
607
+ getStatus(PERMISSIONS_URL)
608
+ .then((d) => {
609
+ if (!fresh()) return;
610
+ setPerm(d);
611
+ // Done once it is there: what a button said is about the way there.
612
+ if (d.platform === "darwin" && d.fullDisk === "granted") setPermAction((a) => (a && !a.busy ? null : a));
613
+ next(d);
614
+ })
615
+ .catch((e) => {
616
+ if (!fresh()) return;
617
+ const lost = noAnswer(e);
618
+ setPerm(lost);
619
+ next(null, lost.status !== 403);
620
+ });
621
+ };
622
+ tick();
623
+ const onFocus = () => tick();
624
+ if (typeof window !== "undefined") window.addEventListener("focus", onFocus);
625
+ return () => {
626
+ alive = false;
627
+ if (timer !== null) clearTimeout(timer);
628
+ if (typeof window !== "undefined") window.removeEventListener("focus", onFocus);
629
+ };
366
630
  }, [open]);
367
631
 
368
632
  // Follow the saved name again once it changes (a save landed, or 重置).
@@ -409,6 +673,75 @@ window.__ModuleLoader__.load({
409
673
  }
410
674
  };
411
675
 
676
+ /** POST one of the 全天候秘书 buttons; the answer is shown under the row. */
677
+ const press = async (url, running, done, kind) => {
678
+ if (action !== null && action.busy) return;
679
+ const at = Date.now();
680
+ setAction({ busy: true, text: running, kind, at });
681
+ try {
682
+ const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" });
683
+ const d = await res.json().catch(() => null);
684
+ setAction({ busy: false, text: res.ok && d && d.ok ? done(d) : ((d && d.message) || `没成功(HTTP ${res.status})`), kind, at });
685
+ } catch {
686
+ setAction({ busy: false, text: "没成功:路由读不到,DSH 可能需要重启", kind, at });
687
+ }
688
+ // The test alarm's line is about the next few minutes only.
689
+ if (kind === "test") setTimeout(() => setAction((a) => (a && a.at === at ? null : a)), 240000);
690
+ setPoke((n) => n + 1);
691
+ };
692
+ const authorize = () => press(AUTHORIZE_URL, "正在看要做什么…", authorizeText, "authorize");
693
+ const testAlarm = () => press(TEST_ALARM_URL, "正在设测试闹钟…",
694
+ (d) => d.urgent === false
695
+ ? `设上了(${d.at}),但没能设成紧急提醒,到点只会弹通知`
696
+ : `已设:${d.at} 在「${d.list}」里响,看 iPhone 是不是像闹钟一样响(没响就看这条提醒的备注)`, "test");
697
+
698
+ /** 打开设置 / 在访达中显示: the card's own JSON POST; the answer shows under the row for a while. */
699
+ const pressPermission = async (url, done) => {
700
+ if (permPressing.current) return;
701
+ permPressing.current = true;
702
+ const at = Date.now();
703
+ setPermAction({ busy: true, text: "正在打开…", at });
704
+ let text;
705
+ try {
706
+ const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" });
707
+ const d = await res.json().catch(() => null);
708
+ text = res.ok && d && d.ok ? done : ((d && d.message) || `没打开(HTTP ${res.status})`);
709
+ } catch {
710
+ text = "没打开:路由读不到,DSH 可能需要重启";
711
+ } finally {
712
+ permPressing.current = false;
713
+ }
714
+ setPermAction({ busy: false, text, at });
715
+ setTimeout(() => setPermAction((a) => (a && a.at === at ? null : a)), 20000);
716
+ };
717
+ const permBusy = permAction !== null && permAction.busy;
718
+ const starter = perm !== null && perm.platform === "darwin" ? starterName(perm.launcher) : null;
719
+ const permButtons = [];
720
+ if (perm !== null && perm.platform === "darwin" && perm.fullDisk !== "granted") {
721
+ permButtons.push(h("button", {
722
+ key: "settings", type: "button", className: S.button, disabled: permBusy,
723
+ onClick: () => pressPermission(PERMISSIONS_SETTINGS_URL, "已打开「完全磁盘访问权限」那一页"),
724
+ }, "打开设置"));
725
+ if (starter !== null) {
726
+ const short = finderName(perm.launcher);
727
+ permButtons.push(h("button", {
728
+ key: "reveal", type: "button", className: S.button, disabled: permBusy,
729
+ onClick: () => pressPermission(PERMISSIONS_REVEAL_URL, `已在访达中选中「${short}」,把它拖进列表就行`),
730
+ }, `在访达中显示「${short}」`));
731
+ }
732
+ }
733
+ if (perm !== null && perm.platform === "win32" && perm.folderGuard === "on") {
734
+ permButtons.push(h("button", {
735
+ key: "settings", type: "button", className: S.button, disabled: permBusy,
736
+ onClick: () => pressPermission(PERMISSIONS_SETTINGS_URL, "已打开 Windows 安全中心的「勒索软件防护」"),
737
+ }, "打开 Windows 安全中心"));
738
+ }
739
+ // Nothing to do on other computers (Windows without Controlled folder access, Linux): no row. Nor on a
740
+ // page opened elsewhere when DSH's computer is not a Mac: a refusal cannot say whether Windows has
741
+ // Controlled folder access on (it is off unless turned on), and the other rows already say where to look.
742
+ const permRow = perm === null || perm.platform === "darwin" || (perm.platform === "win32" && perm.folderGuard === "on")
743
+ || (perm.unreachable === true && (perm.hostPlatform === undefined || perm.hostPlatform === "darwin"));
744
+
412
745
  const restartNow = async () => {
413
746
  if (restarting) return;
414
747
  setRestarting(true);
@@ -439,7 +772,19 @@ window.__ModuleLoader__.load({
439
772
  );
440
773
 
441
774
  const fields = [
442
- // Model first: it is the setting whose default surprises people, because
775
+ // First, because it is what a new install trips over: on a Mac the bot's file
776
+ // access is held against whatever started DSH, and until that has Full Disk
777
+ // Access every protected folder brings up a dialog on the Mac's screen.
778
+ // The words first, then the buttons: they are steps to read before pressing.
779
+ // What a button answered shows only while there are buttons (nothing left to do, nothing to say).
780
+ permRow ? Field({
781
+ label: "电脑权限",
782
+ control: h("div", null,
783
+ h("p", { className: S.hint }, permissionHint(perm, onThisComputer())
784
+ + (permButtons.length > 0 && permAction !== null && permAction.text ? `(${permAction.text})` : "")),
785
+ permButtons.length > 0 ? h("div", { className: S.actions }, permButtons) : null),
786
+ }) : null,
787
+ // Model next: it is the setting whose default surprises people, because
443
788
  // leaving it empty means the bot follows the deployment default — and the
444
789
  // web UI's model picker writes through to exactly that.
445
790
  Field({
@@ -517,6 +862,18 @@ window.__ModuleLoader__.load({
517
862
  onChange: (next) => set("idleCompaction", next),
518
863
  }),
519
864
  }),
865
+ Field({
866
+ label: "空闲整理阈值",
867
+ hint: "万 token。上一次请求超过这个数,空闲时就整理。留空 = 宿主压缩阈值的 85%。只管 bot,网页会话不受影响",
868
+ overridden: isSet("idleCompactionTokens"), disabled,
869
+ onReset: () => clear("idleCompactionTokens"),
870
+ control: h("input", {
871
+ type: "number", className: S.input, min: 1, step: 1, disabled,
872
+ value: v.idleCompactionTokens === undefined ? "" : v.idleCompactionTokens / 10000,
873
+ placeholder: "自动",
874
+ onChange: (e) => num("idleCompactionTokens", e.target.value, 10000),
875
+ }),
876
+ }),
520
877
  Field({
521
878
  label: "把工作目录的说明文件交给 bot",
522
879
  hint: "AGENTS.md / CLAUDE.md。关掉则微信会话里不再自动塞这些文件(DSH 每次改动都会重发整份),需要时让 bot 自己去读",
@@ -657,35 +1014,56 @@ window.__ModuleLoader__.load({
657
1014
  }),
658
1015
  }),
659
1016
  Field({
660
- label: "Mac 日历",
661
- hint: calendarHint(calendar, (calName ?? v.macCalendarName ?? "").trim(), v.macCalendar === true),
662
- overridden: isSet("macCalendar") || isSet("macCalendarName"), disabled,
663
- onReset: () => { clear("macCalendar"); clear("macCalendarName"); setCalName(null); },
1017
+ label: "全天候秘书",
1018
+ hint: assistantHint(calendar, (calName ?? v.macCalendarName ?? "").trim(), v.macCalendar === true)
1019
+ + (action !== null && action.text ? `(${action.text})` : "")
1020
+ + (memoryOpen !== null && memoryOpen !== "opening" && memoryOpen !== "opened" ? `(${memoryOpen})` : ""),
1021
+ overridden: isSet("macCalendar") || isSet("macCalendarName") || isSet("secretary"), disabled,
1022
+ onReset: () => { clear("macCalendar"); clear("macCalendarName"); clear("secretary"); setCalName(null); },
664
1023
  inline: h(Switch, {
665
- label: "Mac 日历",
1024
+ label: "全天候秘书",
666
1025
  on: v.macCalendar === true,
667
- // Turning it on needs a calendar name first (the one being typed
668
- // counts); turning it off never does.
1026
+ // Turning it on needs a name first (the one being typed counts);
1027
+ // turning it off never does. Calendar, alarms and rules are one
1028
+ // feature: the switch sets both fields.
669
1029
  disabled: disabled || (v.macCalendar !== true
670
1030
  && (!(calName ?? v.macCalendarName ?? "").trim() || (calendar !== null && calendar.mac === false))),
671
1031
  onChange: (next) => {
672
1032
  const typed = (calName ?? v.macCalendarName ?? "").trim();
673
1033
  if (next && typed !== (v.macCalendarName || "").trim()) set("macCalendarName", typed);
674
1034
  set("macCalendar", next);
1035
+ set("secretary", next);
675
1036
  },
676
1037
  }),
677
- control: h("input", {
678
- type: "text", className: S.input, disabled,
679
- value: calName ?? (v.macCalendarName || ""),
680
- placeholder: "专用日历的名字,例如 规划",
681
- maxLength: 60,
682
- onChange: (e) => setCalName(String(e.target.value)),
683
- onBlur: (e) => {
684
- const name = String(e.target.value).trim();
685
- if (name === (v.macCalendarName || "").trim()) return;
686
- if (name === "") clear("macCalendarName"); else set("macCalendarName", name);
687
- },
688
- }),
1038
+ control: h("div", null,
1039
+ h("input", {
1040
+ type: "text", className: S.input, disabled,
1041
+ value: calName ?? (v.macCalendarName || ""),
1042
+ placeholder: "专用日历的名字(闹钟清单第一次也用它),例如 规划",
1043
+ maxLength: 60,
1044
+ onChange: (e) => setCalName(String(e.target.value)),
1045
+ onBlur: (e) => {
1046
+ const name = String(e.target.value).trim();
1047
+ if (name === (v.macCalendarName || "").trim()) return;
1048
+ if (name === "") clear("macCalendarName"); else set("macCalendarName", name);
1049
+ },
1050
+ }),
1051
+ h("div", { className: S.actions },
1052
+ h("button", {
1053
+ type: "button", className: S.button,
1054
+ disabled: disabled || v.macCalendar !== true || (action !== null && action.busy),
1055
+ onClick: authorize,
1056
+ }, "一键授权"),
1057
+ h("button", {
1058
+ type: "button", className: S.button,
1059
+ disabled: disabled || v.macCalendar !== true || (action !== null && action.busy)
1060
+ || !(calendar && calendar.reminders === "fullAccess" && !calendar.outdated && calendar.alarms !== "unsupported"),
1061
+ onClick: testAlarm,
1062
+ }, "测试闹钟"),
1063
+ h("button", {
1064
+ type: "button", className: S.button, disabled: disabled || memoryOpen === "opening", onClick: openMemory,
1065
+ }, memoryOpen === "opened" ? "已在 Mac 上打开" : "打开 memory.md"),
1066
+ )),
689
1067
  }),
690
1068
  Field({
691
1069
  label: "日历提醒",
@@ -705,20 +1083,14 @@ window.__ModuleLoader__.load({
705
1083
  }),
706
1084
  }),
707
1085
  Field({
708
- label: "日程秘书",
709
- hint: secretaryHint(calendar, v.secretary === true, v.macCalendar === true)
710
- + (memoryOpen !== null && memoryOpen !== "opening" && memoryOpen !== "opened" ? `(${memoryOpen})` : ""),
711
- control: h("div", null, h("button", {
712
- type: "button", className: S.button, disabled: disabled || memoryOpen === "opening", onClick: openMemory,
713
- }, memoryOpen === "opened" ? "已在 Mac 上打开" : "打开 memory.md")),
714
- overridden: isSet("secretary"), disabled,
715
- onReset: () => clear("secretary"),
1086
+ label: "改别的日历前先问我",
1087
+ hint: "bot 往专用日历以外的日历里加、改、删日程前,先在微信里问你、回「好」才动。"
1088
+ + "关掉就直接改(只读和订阅的日历本来就改不了);会通知其他参与者的改动仍会先问",
1089
+ overridden: isSet("macCalendarAsk"), disabled,
1090
+ onReset: () => clear("macCalendarAsk"),
716
1091
  inline: h(Switch, {
717
- label: "日程秘书",
718
- // It leans on the calendar: off (and not switchable) while the calendar is off.
719
- on: v.secretary === true && v.macCalendar === true,
720
- disabled: disabled || v.macCalendar !== true || (calendar !== null && calendar.mac === false),
721
- onChange: (next) => set("secretary", next),
1092
+ label: "改别的日历前先问我", on: v.macCalendarAsk !== false, disabled,
1093
+ onChange: (next) => set("macCalendarAsk", next),
722
1094
  }),
723
1095
  }),
724
1096
  Field({
@@ -747,7 +1119,11 @@ window.__ModuleLoader__.load({
747
1119
  { className: S.headText },
748
1120
  h("span", { className: S.name }, "微信 Bot"),
749
1121
  h("span", { className: S.description },
750
- "模型、图片、白名单、Mac 日历与日程秘书。大多改完立刻生效,微信连接不中断"),
1122
+ "模型、图片、白名单、全天候秘书(日历和闹钟)。大多改完立刻生效,微信连接不中断"),
1123
+ // Shown folded: the one thing a new install has to do on the Mac itself (open, the row says it).
1124
+ !open && perm !== null && perm.platform === "darwin" && perm.fullDisk === "denied"
1125
+ ? h("span", { className: S.attention }, "还差一项电脑权限:完全磁盘访问权限(展开看怎么开)")
1126
+ : null,
751
1127
  ),
752
1128
  h(
753
1129
  "svg",