dsh-qqbot-plus 0.0.0-stage → 0.1.2

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 (301) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/CHANGELOG_EN.md +188 -0
  3. package/LICENSE +21 -0
  4. package/README.md +281 -2
  5. package/README_EN.md +248 -0
  6. package/cordis.patch.yml +163 -0
  7. package/cordis.yml +112 -0
  8. package/install.sh +108 -0
  9. package/lib/alarms.js +371 -0
  10. package/lib/client.js +2411 -0
  11. package/lib/commands/auth.d.ts +18 -0
  12. package/lib/commands/auth.d.ts.map +1 -0
  13. package/lib/commands/auth.js +15 -0
  14. package/lib/commands/auth.js.map +1 -0
  15. package/lib/commands/help.d.ts +10 -0
  16. package/lib/commands/help.d.ts.map +1 -0
  17. package/lib/commands/help.js +39 -0
  18. package/lib/commands/help.js.map +1 -0
  19. package/lib/commands/index.d.ts +15 -0
  20. package/lib/commands/index.d.ts.map +1 -0
  21. package/lib/commands/index.js +30 -0
  22. package/lib/commands/index.js.map +1 -0
  23. package/lib/commands/misc.d.ts +21 -0
  24. package/lib/commands/misc.d.ts.map +1 -0
  25. package/lib/commands/misc.js +93 -0
  26. package/lib/commands/misc.js.map +1 -0
  27. package/lib/commands/model.d.ts +6 -0
  28. package/lib/commands/model.d.ts.map +1 -0
  29. package/lib/commands/model.js +63 -0
  30. package/lib/commands/model.js.map +1 -0
  31. package/lib/commands/new.js +17 -0
  32. package/lib/commands/preset.d.ts +8 -0
  33. package/lib/commands/preset.d.ts.map +1 -0
  34. package/lib/commands/preset.js +56 -0
  35. package/lib/commands/preset.js.map +1 -0
  36. package/lib/commands/session.d.ts +14 -0
  37. package/lib/commands/session.d.ts.map +1 -0
  38. package/lib/commands/session.js +34 -0
  39. package/lib/commands/session.js.map +1 -0
  40. package/lib/commands/status.d.ts +7 -0
  41. package/lib/commands/status.d.ts.map +1 -0
  42. package/lib/commands/status.js +26 -0
  43. package/lib/commands/status.js.map +1 -0
  44. package/lib/commands/types.d.ts +21 -0
  45. package/lib/commands/types.d.ts.map +1 -0
  46. package/lib/commands/types.js +2 -0
  47. package/lib/commands/types.js.map +1 -0
  48. package/lib/config.d.ts +95 -0
  49. package/lib/config.js +88 -0
  50. package/lib/features/answer-parser.d.ts +9 -0
  51. package/lib/features/answer-parser.d.ts.map +1 -0
  52. package/lib/features/answer-parser.js +23 -0
  53. package/lib/features/answer-parser.js.map +1 -0
  54. package/lib/features/approval-channel.d.ts +94 -0
  55. package/lib/features/approval-channel.d.ts.map +1 -0
  56. package/lib/features/approval-channel.js +158 -0
  57. package/lib/features/approval-channel.js.map +1 -0
  58. package/lib/features/approval-renderer.d.ts +18 -0
  59. package/lib/features/approval-renderer.d.ts.map +1 -0
  60. package/lib/features/approval-renderer.js +52 -0
  61. package/lib/features/approval-renderer.js.map +1 -0
  62. package/lib/features/button-utils.d.ts +34 -0
  63. package/lib/features/button-utils.d.ts.map +1 -0
  64. package/lib/features/button-utils.js +27 -0
  65. package/lib/features/button-utils.js.map +1 -0
  66. package/lib/features/history-store.d.ts +8 -0
  67. package/lib/features/history-store.d.ts.map +1 -0
  68. package/lib/features/history-store.js +23 -0
  69. package/lib/features/history-store.js.map +1 -0
  70. package/lib/features/question-channel.d.ts +96 -0
  71. package/lib/features/question-channel.d.ts.map +1 -0
  72. package/lib/features/question-channel.js +234 -0
  73. package/lib/features/question-channel.js.map +1 -0
  74. package/lib/features/question-renderer.d.ts +20 -0
  75. package/lib/features/question-renderer.d.ts.map +1 -0
  76. package/lib/features/question-renderer.js +70 -0
  77. package/lib/features/question-renderer.js.map +1 -0
  78. package/lib/fishcheck/measure.js +230 -0
  79. package/lib/fishcheck/rules.js +99 -0
  80. package/lib/fishmeme/plugin.js +605 -0
  81. package/lib/fishmeme/routes.js +141 -0
  82. package/lib/fishmemory/plugin.js +1052 -0
  83. package/lib/gateway/bootstrap.d.ts +12 -0
  84. package/lib/gateway/bootstrap.d.ts.map +1 -0
  85. package/lib/gateway/bootstrap.js +200 -0
  86. package/lib/gateway/bootstrap.js.map +1 -0
  87. package/lib/gateway/index.d.ts +3 -0
  88. package/lib/gateway/index.d.ts.map +1 -0
  89. package/lib/gateway/index.js +3 -0
  90. package/lib/gateway/index.js.map +1 -0
  91. package/lib/gateway/middleware-setup.d.ts +12 -0
  92. package/lib/gateway/middleware-setup.d.ts.map +1 -0
  93. package/lib/gateway/middleware-setup.js +82 -0
  94. package/lib/gateway/middleware-setup.js.map +1 -0
  95. package/lib/host/adapter.d.ts +48 -0
  96. package/lib/host/adapter.d.ts.map +1 -0
  97. package/lib/host/adapter.js +127 -0
  98. package/lib/host/adapter.js.map +1 -0
  99. package/lib/humanlike/ENV_PROMPT.md +28 -0
  100. package/lib/humanlike/affinity.js +316 -0
  101. package/lib/humanlike/learn.js +343 -0
  102. package/lib/humanlike/life.js +899 -0
  103. package/lib/humanlike/mind.js +323 -0
  104. package/lib/humanlike/plugin.js +587 -0
  105. package/lib/humanlike/reach.js +119 -0
  106. package/lib/humanlike/real.js +276 -0
  107. package/lib/humanlike/rules.js +67 -0
  108. package/lib/humanlike/settings-api.js +159 -0
  109. package/lib/humanlike/settings.js +370 -0
  110. package/lib/humanlike/together.js +251 -0
  111. package/lib/identity/paths.js +27 -0
  112. package/lib/identity/persona.js +75 -0
  113. package/lib/identity/portrait.js +25 -0
  114. package/lib/identity/runtime.js +78 -0
  115. package/lib/index.d.ts +15 -0
  116. package/lib/index.js +117 -0
  117. package/lib/media/draft-tool.js +442 -0
  118. package/lib/media/draft-tool.js.bak-to-182027 +389 -0
  119. package/lib/media/media-cleaner.d.ts +19 -0
  120. package/lib/media/media-cleaner.d.ts.map +1 -0
  121. package/lib/media/media-cleaner.js +81 -0
  122. package/lib/media/media-cleaner.js.map +1 -0
  123. package/lib/media/say-tool.js +72 -0
  124. package/lib/media/send-file-tool.d.ts +12 -0
  125. package/lib/media/send-file-tool.d.ts.map +1 -0
  126. package/lib/media/send-file-tool.js +122 -0
  127. package/lib/media/send-file-tool.js.map +1 -0
  128. package/lib/media/send-media.d.ts +61 -0
  129. package/lib/media/send-media.d.ts.map +1 -0
  130. package/lib/media/send-media.js +104 -0
  131. package/lib/media/send-media.js.map +1 -0
  132. package/lib/media/vision-tool.d.ts +22 -0
  133. package/lib/media/vision-tool.d.ts.map +1 -0
  134. package/lib/media/vision-tool.js +288 -0
  135. package/lib/media/vision-tool.js.map +1 -0
  136. package/lib/middleware/attachment.d.ts +11 -0
  137. package/lib/middleware/attachment.d.ts.map +1 -0
  138. package/lib/middleware/attachment.js +30 -0
  139. package/lib/middleware/attachment.js.map +1 -0
  140. package/lib/middleware/question-answer.d.ts +10 -0
  141. package/lib/middleware/question-answer.d.ts.map +1 -0
  142. package/lib/middleware/question-answer.js +19 -0
  143. package/lib/middleware/question-answer.js.map +1 -0
  144. package/lib/model/index.d.ts +10 -0
  145. package/lib/model/index.d.ts.map +1 -0
  146. package/lib/model/index.js +9 -0
  147. package/lib/model/index.js.map +1 -0
  148. package/lib/model/model-resolver.d.ts +102 -0
  149. package/lib/model/model-resolver.d.ts.map +1 -0
  150. package/lib/model/model-resolver.js +206 -0
  151. package/lib/model/model-resolver.js.map +1 -0
  152. package/lib/model/prefs-store.d.ts +50 -0
  153. package/lib/model/prefs-store.d.ts.map +1 -0
  154. package/lib/model/prefs-store.js +215 -0
  155. package/lib/model/prefs-store.js.map +1 -0
  156. package/lib/model/settings-reader.d.ts +19 -0
  157. package/lib/model/settings-reader.d.ts.map +1 -0
  158. package/lib/model/settings-reader.js +76 -0
  159. package/lib/model/settings-reader.js.map +1 -0
  160. package/lib/model/types.d.ts +15 -0
  161. package/lib/model/types.d.ts.map +1 -0
  162. package/lib/model/types.js +5 -0
  163. package/lib/model/types.js.map +1 -0
  164. package/lib/resume-check.js +122 -0
  165. package/lib/resume-tool.js +29 -0
  166. package/lib/rules.js +57 -0
  167. package/lib/session/idle-evictor.d.ts +18 -0
  168. package/lib/session/idle-evictor.d.ts.map +1 -0
  169. package/lib/session/idle-evictor.js +31 -0
  170. package/lib/session/idle-evictor.js.map +1 -0
  171. package/lib/session/index.d.ts +9 -0
  172. package/lib/session/index.d.ts.map +1 -0
  173. package/lib/session/index.js +8 -0
  174. package/lib/session/index.js.map +1 -0
  175. package/lib/session/pick-agent.js +116 -0
  176. package/lib/session/session-id.d.ts +5 -0
  177. package/lib/session/session-id.d.ts.map +1 -0
  178. package/lib/session/session-id.js +15 -0
  179. package/lib/session/session-id.js.map +1 -0
  180. package/lib/session/session-manager.d.ts +138 -0
  181. package/lib/session/session-manager.d.ts.map +1 -0
  182. package/lib/session/session-manager.js +1157 -0
  183. package/lib/session/session-manager.js.bak-target +1081 -0
  184. package/lib/session/session-manager.js.bak-title-20261118 +1119 -0
  185. package/lib/session/session-manager.js.map +1 -0
  186. package/lib/session/types.d.ts +162 -0
  187. package/lib/session/types.d.ts.map +1 -0
  188. package/lib/session/types.js +2 -0
  189. package/lib/session/types.js.map +1 -0
  190. package/lib/setup/bind-routes.d.ts +78 -0
  191. package/lib/setup/bind-routes.d.ts.map +1 -0
  192. package/lib/setup/bind-routes.js +588 -0
  193. package/lib/setup/bind-routes.js.bak-join-163944 +761 -0
  194. package/lib/setup/bind-routes.js.map +1 -0
  195. package/lib/setup/binding-service.d.ts +86 -0
  196. package/lib/setup/binding-service.d.ts.map +1 -0
  197. package/lib/setup/binding-service.js +175 -0
  198. package/lib/setup/binding-service.js.map +1 -0
  199. package/lib/setup/index.d.ts +50 -0
  200. package/lib/setup/index.d.ts.map +1 -0
  201. package/lib/setup/index.js +163 -0
  202. package/lib/setup/index.js.map +1 -0
  203. package/lib/setup/persist.d.ts +42 -0
  204. package/lib/setup/persist.d.ts.map +1 -0
  205. package/lib/setup/persist.js +344 -0
  206. package/lib/setup/persist.js.map +1 -0
  207. package/lib/setup/presenters.d.ts +40 -0
  208. package/lib/setup/presenters.d.ts.map +1 -0
  209. package/lib/setup/presenters.js +84 -0
  210. package/lib/setup/presenters.js.map +1 -0
  211. package/lib/setup/qr-svg.d.ts +9 -0
  212. package/lib/setup/qr-svg.d.ts.map +1 -0
  213. package/lib/setup/qr-svg.js +33 -0
  214. package/lib/setup/qr-svg.js.map +1 -0
  215. package/lib/shared/bind-protocol.d.ts +42 -0
  216. package/lib/shared/bind-protocol.d.ts.map +1 -0
  217. package/lib/shared/bind-protocol.js +33 -0
  218. package/lib/shared/bind-protocol.js.map +1 -0
  219. package/lib/shared/dirs.d.ts +10 -0
  220. package/lib/shared/dirs.d.ts.map +1 -0
  221. package/lib/shared/dirs.js +20 -0
  222. package/lib/shared/dirs.js.map +1 -0
  223. package/lib/shared/http-body.js +43 -0
  224. package/lib/shared/index.d.ts +8 -0
  225. package/lib/shared/index.d.ts.map +1 -0
  226. package/lib/shared/index.js +8 -0
  227. package/lib/shared/index.js.map +1 -0
  228. package/lib/shared/json-file.js +34 -0
  229. package/lib/shared/orders.js +26 -0
  230. package/lib/shared/scope.d.ts +14 -0
  231. package/lib/shared/scope.d.ts.map +1 -0
  232. package/lib/shared/scope.js +12 -0
  233. package/lib/shared/scope.js.map +1 -0
  234. package/lib/shared/send-helper.d.ts +11 -0
  235. package/lib/shared/send-helper.d.ts.map +1 -0
  236. package/lib/shared/send-helper.js +13 -0
  237. package/lib/shared/send-helper.js.map +1 -0
  238. package/lib/shared/utils.d.ts +31 -0
  239. package/lib/shared/utils.d.ts.map +1 -0
  240. package/lib/shared/utils.js +228 -0
  241. package/lib/shared/utils.js.map +1 -0
  242. package/lib/tool-guard.js +74 -0
  243. package/lib/transport/attachment.d.ts +41 -0
  244. package/lib/transport/attachment.d.ts.map +1 -0
  245. package/lib/transport/attachment.js +191 -0
  246. package/lib/transport/attachment.js.map +1 -0
  247. package/lib/transport/chunker.d.ts +14 -0
  248. package/lib/transport/chunker.d.ts.map +1 -0
  249. package/lib/transport/chunker.js +78 -0
  250. package/lib/transport/chunker.js.map +1 -0
  251. package/lib/transport/deliverables.d.ts +20 -0
  252. package/lib/transport/deliverables.d.ts.map +1 -0
  253. package/lib/transport/deliverables.js +72 -0
  254. package/lib/transport/deliverables.js.map +1 -0
  255. package/lib/transport/events.d.ts +117 -0
  256. package/lib/transport/events.d.ts.map +1 -0
  257. package/lib/transport/events.js +112 -0
  258. package/lib/transport/events.js.map +1 -0
  259. package/lib/transport/inbound.d.ts +11 -0
  260. package/lib/transport/inbound.d.ts.map +1 -0
  261. package/lib/transport/inbound.js +511 -0
  262. package/lib/transport/inbound.js.map +1 -0
  263. package/lib/transport/index.d.ts +10 -0
  264. package/lib/transport/index.d.ts.map +1 -0
  265. package/lib/transport/index.js +10 -0
  266. package/lib/transport/index.js.map +1 -0
  267. package/lib/transport/msgid-cache.d.ts +23 -0
  268. package/lib/transport/msgid-cache.d.ts.map +1 -0
  269. package/lib/transport/msgid-cache.js +57 -0
  270. package/lib/transport/msgid-cache.js.map +1 -0
  271. package/lib/transport/notify.js +147 -0
  272. package/lib/transport/outbound-buffer.d.ts +42 -0
  273. package/lib/transport/outbound-buffer.d.ts.map +1 -0
  274. package/lib/transport/outbound-buffer.js +68 -0
  275. package/lib/transport/outbound-buffer.js.map +1 -0
  276. package/lib/transport/outbound.d.ts +42 -0
  277. package/lib/transport/outbound.d.ts.map +1 -0
  278. package/lib/transport/outbound.js +183 -0
  279. package/lib/transport/outbound.js.map +1 -0
  280. package/lib/transport/reply-limiter.d.ts +31 -0
  281. package/lib/transport/reply-limiter.d.ts.map +1 -0
  282. package/lib/transport/reply-limiter.js +50 -0
  283. package/lib/transport/reply-limiter.js.map +1 -0
  284. package/lib/transport/reply-target.d.ts +32 -0
  285. package/lib/transport/reply-target.d.ts.map +1 -0
  286. package/lib/transport/reply-target.js +64 -0
  287. package/lib/transport/reply-target.js.map +1 -0
  288. package/lib/transport/streaming-writer.d.ts +55 -0
  289. package/lib/transport/streaming-writer.d.ts.map +1 -0
  290. package/lib/transport/streaming-writer.js +122 -0
  291. package/lib/transport/streaming-writer.js.map +1 -0
  292. package/lib/transport/tool-presenter.d.ts +37 -0
  293. package/lib/transport/tool-presenter.d.ts.map +1 -0
  294. package/lib/transport/tool-presenter.js +116 -0
  295. package/lib/transport/tool-presenter.js.map +1 -0
  296. package/lib/turn-check.js +85 -0
  297. package/lib/types.d.ts +39 -0
  298. package/lib/types.js +5 -0
  299. package/locale/en.json +6 -0
  300. package/locale/zh.json +6 -0
  301. package/package.json +127 -4
@@ -0,0 +1,323 @@
1
+ // 「惦记」家族工具:humanlike_mind { want | list | done | drop }
2
+ //
3
+ // 从 cortico-world-humanlike-alont1/src/modules/mind/world.ts 搬过来。
4
+ // 存的是她自己写的一句话、为什么、什么时候提醒;到点只提醒一次,做不做由她决定。
5
+ // dsh 这边没有宿主事件总线,所以推送那一路(mind.due / digest / freetime)不搬,
6
+ // 只留四条工具动作、前缀计数,以及调度侧要用的几个纯判定/清理钩子。
7
+ // 回执、上限、编号、方括号容忍都照原样。
8
+
9
+ import fs from 'node:fs'
10
+ import path from 'node:path'
11
+ import { DEFAULT_VALUES } from './settings.js'
12
+ import { PLUGIN_HOME } from '../shared/dirs.js'
13
+
14
+ const DEFAULT_DATA_DIR = path.join(PLUGIN_HOME, 'humanlike')
15
+ const TZ_OFFSET_MINUTES = 480
16
+ const TIME_ZONE = 'Asia/Shanghai'
17
+
18
+ const RECENT_CAP = 30
19
+ const TEXT_MAX = 200
20
+ const WHY_MAX = 200
21
+ const ABOUT_MAX = 40
22
+ const AFTER_MINUTES_MAX = 20160
23
+ const RECENT_SHOWN = 8
24
+ // 刚起来的 30 秒内不提醒:那是重启,不是「想起来了」
25
+ const STARTUP_SILENCE_MS = 30_000
26
+
27
+ // 默认值由 lib/settings.js 统一提供。
28
+ const DEFAULTS = { ...DEFAULT_VALUES.mind }
29
+
30
+ // 原版按配置时区格式化;dsh 这边没有配置面板,固定 +08:00。
31
+ function nowIso (date = new Date()) {
32
+ const d = new Date(date.getTime() + TZ_OFFSET_MINUTES * 60_000)
33
+ return d.toISOString().replace('Z', '+08:00')
34
+ }
35
+
36
+ // 「11/18 18:23」——月/日不带前导零,小时两位
37
+ function clock (at = new Date()) {
38
+ return new Intl.DateTimeFormat('zh-CN', {
39
+ timeZone: TIME_ZONE,
40
+ month: 'numeric',
41
+ day: 'numeric',
42
+ hour: '2-digit',
43
+ minute: '2-digit',
44
+ hour12: false,
45
+ }).format(at)
46
+ }
47
+
48
+ function freshData () {
49
+ return {
50
+ version: 1,
51
+ items: [],
52
+ recent: [],
53
+ day: '',
54
+ pushesToday: 0,
55
+ lastPushAt: 0,
56
+ freeToday: 0,
57
+ lastFreeAt: 0,
58
+ lastDigestDay: '',
59
+ }
60
+ }
61
+
62
+ export function createMind (opts = {}) {
63
+ const { dataDir = DEFAULT_DATA_DIR, config = {}, logger } = opts
64
+ const cfg = { ...DEFAULTS, ...config }
65
+ const file = path.join(dataDir, 'mind.json')
66
+ const startedAt = Date.now()
67
+
68
+ let data = freshData()
69
+ let nextId = 1
70
+
71
+ // 编号接着最大的往下发,重启后不会撞号
72
+ function computeNextId () {
73
+ const maxId = [...data.items, ...data.recent]
74
+ .map((i) => Number(String(i.id).replace(/^m/, '')))
75
+ .filter((n) => Number.isFinite(n))
76
+ .reduce((a, b) => Math.max(a, b), 0)
77
+ nextId = maxId + 1
78
+ }
79
+
80
+ // 读:先摆一份空账,再逐字段做类型兜底;坏了只 warn,从空账开始。
81
+ function load () {
82
+ data = freshData()
83
+ try {
84
+ if (!fs.existsSync(file)) {
85
+ computeNextId()
86
+ return
87
+ }
88
+ const raw = JSON.parse(fs.readFileSync(file, 'utf8'))
89
+ const items = Array.isArray(raw.items) ? raw.items.filter((i) => i && typeof i.text === 'string') : []
90
+ data = {
91
+ version: 1,
92
+ items: items.map((i) => ({ ...i, pushedCount: Number.isFinite(i.pushedCount) ? i.pushedCount : 0 })),
93
+ recent: Array.isArray(raw.recent) ? raw.recent.slice(0, RECENT_CAP) : [],
94
+ day: typeof raw.day === 'string' ? raw.day : '',
95
+ pushesToday: Number.isFinite(raw.pushesToday) ? Number(raw.pushesToday) : 0,
96
+ lastPushAt: Number.isFinite(raw.lastPushAt) ? Number(raw.lastPushAt) : 0,
97
+ freeToday: Number.isFinite(raw.freeToday) ? Number(raw.freeToday) : 0,
98
+ lastFreeAt: Number.isFinite(raw.lastFreeAt) ? Number(raw.lastFreeAt) : 0,
99
+ lastDigestDay: typeof raw.lastDigestDay === 'string' ? raw.lastDigestDay : '',
100
+ }
101
+ } catch (error) {
102
+ logger?.warn?.(`humanlike: 惦记账本读取失败,从空账开始 ${String(error)}`)
103
+ data = freshData()
104
+ }
105
+ computeNextId()
106
+ }
107
+ load()
108
+
109
+ // 写:先进 tmp 再 rename,原子替换(原版如此)。
110
+ function save () {
111
+ try {
112
+ fs.mkdirSync(path.dirname(file), { recursive: true })
113
+ const tmp = `${file}.tmp`
114
+ fs.writeFileSync(tmp, JSON.stringify(data, null, 1), 'utf8')
115
+ fs.renameSync(tmp, file)
116
+ } catch (error) {
117
+ logger?.warn?.(`humanlike: 惦记账本落盘失败 ${String(error)}`)
118
+ }
119
+ }
120
+
121
+ // 了结一件:打上标记、从 items 挪进 recent。
122
+ function retire (item, patch) {
123
+ Object.assign(item, patch)
124
+ data.items = data.items.filter((i) => i.id !== item.id)
125
+ data.recent = [item, ...data.recent].slice(0, RECENT_CAP)
126
+ }
127
+
128
+ // 编号容忍外面套一对方括号([m1]),只剥首尾各一个
129
+ function find (id) {
130
+ const key = id.trim().replace(/^\[|\]$/g, '')
131
+ return data.items.find((i) => i.id === key)
132
+ }
133
+
134
+ // ── want ──────────────────────────────────────────────────────────────────
135
+ function want (args) {
136
+ const text = String(args?.text ?? '').trim()
137
+ const why = String(args?.why ?? '').trim()
138
+ if (!text) return 'text 不能为空——要记的是你想做的那件事。'
139
+ if (!why) return 'why 不能为空——没有理由的事不值得占一个位置。'
140
+ const pending = data.items
141
+ // 上限按 max(1, maxPending) 判,但文案打印原始 maxPending
142
+ if (pending.length >= Math.max(1, cfg.maxPending)) {
143
+ return `已经惦记着 ${pending.length} 件了(上限 ${cfg.maxPending})。`
144
+ + '先 humanlike_mind_done 或 humanlike_mind_drop 掉一件,或者干脆别记——手上这些做完了再说。\n'
145
+ + pending.map((i) => `- [${i.id}] ${i.text}`).join('\n')
146
+ }
147
+ const id = `m${nextId++}`
148
+ let dueAt
149
+ const afterMinutes = Number(args?.afterMinutes)
150
+ const atTime = String(args?.atTime ?? '').trim()
151
+ // afterMinutes 优先,两者都给时 atTime 被忽略
152
+ if (Number.isFinite(afterMinutes) && afterMinutes > 0) {
153
+ // 只 Math.min 封顶,不取整
154
+ dueAt = nowIso(new Date(Date.now() + Math.min(afterMinutes, AFTER_MINUTES_MAX) * 60_000))
155
+ } else if (/^\d{1,2}:\d{2}$/.test(atTime)) {
156
+ const [hh, mm] = atTime.split(':').map(Number)
157
+ if (hh <= 23 && mm <= 59) {
158
+ // 这一步照原版用进程本地时区的 setHours;本机时区与 +08:00 一致,
159
+ // 所以「已经过了就明天」和回执上的钟点不会错位。
160
+ const target = new Date()
161
+ target.setHours(hh, mm, 0, 0)
162
+ if (target.getTime() <= Date.now()) target.setDate(target.getDate() + 1)
163
+ dueAt = nowIso(target)
164
+ }
165
+ }
166
+ const about = String(args?.about ?? '').trim()
167
+ const item = {
168
+ id,
169
+ text: text.slice(0, TEXT_MAX),
170
+ why: why.slice(0, WHY_MAX),
171
+ ...(about ? { about: String(args.about).trim().slice(0, ABOUT_MAX) } : {}),
172
+ ...(dueAt ? { dueAt } : {}),
173
+ createdAt: nowIso(),
174
+ pushedCount: 0,
175
+ }
176
+ data.items.push(item)
177
+ save()
178
+ return dueAt
179
+ ? `记下了 [${id}]:${item.text}\n到点(${clock(new Date(Date.parse(dueAt)))})我会把你这句话还给你一次,做不做那时候再说。`
180
+ : `记下了 [${id}]:${item.text}\n没定时间——它只挂在 humanlike_mind_list 里,你想起来的时候自己看。`
181
+ }
182
+
183
+ // ── list ──────────────────────────────────────────────────────────────────
184
+ function list () {
185
+ const now = Date.now()
186
+ const pending = data.items
187
+ const head = pending.length
188
+ ? pending.map((i) => {
189
+ // 正好等于也算到点(<=)
190
+ const when = i.dueAt
191
+ ? Date.parse(i.dueAt) <= now ? '**已到点**' : `到点 ${clock(new Date(Date.parse(i.dueAt)))}`
192
+ : '没定时间'
193
+ return `- [${i.id}] ${i.text}${i.about ? `(关于 ${i.about})` : ''} ${when} (因为:${i.why})`
194
+ }).join('\n')
195
+ : '(手上没有惦记的事——这很正常。)'
196
+ const recent = data.recent.slice(0, RECENT_SHOWN).map((i) => {
197
+ // 判定顺序:doneAt → droppedAt → 过期
198
+ const how = i.doneAt
199
+ ? `做完了${i.outcome ? `:${i.outcome}` : ''}`
200
+ : i.droppedAt ? '放下了' : '过期了'
201
+ return `- [${i.id}] ${i.text} → ${how}`
202
+ }).join('\n')
203
+ return `还惦记着的(${pending.length}/${cfg.maxPending}):\n${head}`
204
+ + (recent ? `\n\n最近了结的:\n${recent}` : '')
205
+ }
206
+
207
+ // ── done ──────────────────────────────────────────────────────────────────
208
+ function done (args) {
209
+ const item = find(String(args?.id ?? ''))
210
+ if (!item) return `没有编号 ${String(args?.id ?? '')} 这一条(用 humanlike_mind_list 看编号)。`
211
+ const outcome = String(args?.outcome ?? '').trim()
212
+ // 回执用未截断的原始 trim 值,账本存 slice(0, 200)
213
+ retire(item, { doneAt: nowIso(), ...(outcome ? { outcome: outcome.slice(0, TEXT_MAX) } : {}) })
214
+ save()
215
+ return `了了 [${item.id}]:${item.text}${outcome ? `\n(记了一句:${outcome})` : ''}`
216
+ }
217
+
218
+ // ── drop ──────────────────────────────────────────────────────────────────
219
+ function drop (args) {
220
+ const item = find(String(args?.id ?? ''))
221
+ if (!item) return `没有编号 ${String(args?.id ?? '')} 这一条(用 humanlike_mind_list 看编号)。`
222
+ retire(item, { droppedAt: nowIso() })
223
+ save()
224
+ return `放下了 [${item.id}]:${item.text}`
225
+ }
226
+
227
+ // 写进系统前缀的一段:只报件数与到点数,不放原文
228
+ function promptBlock () {
229
+ const pending = data.items
230
+ if (!pending.length) return ''
231
+ const due = pending.filter((i) => i.dueAt && Date.parse(i.dueAt) <= Date.now()).length
232
+ return `记着 ${pending.length} 件,其中 ${due} 件已到点。用 humanlike_mind_list 查看条目内容。`
233
+ }
234
+
235
+ // ── 调度侧(不是工具动作,宿主每次 tick 自己挑着调)──────────────────────
236
+ // 静默判定:两值相等 = 不静默;起始点含、结束点不含。
237
+ function inQuietHours (d = new Date()) {
238
+ if (cfg.quietFrom === cfg.quietTo) return false
239
+ const h = Number(new Intl.DateTimeFormat('en-US', { timeZone: TIME_ZONE, hour: 'numeric', hour12: false }).format(d)) % 24
240
+ return cfg.quietFrom > cfg.quietTo
241
+ ? (h >= cfg.quietFrom || h < cfg.quietTo)
242
+ : (h >= cfg.quietFrom && h < cfg.quietTo)
243
+ }
244
+
245
+ // 跨天归零 + 过期清理。过期在静默/暂停判定之前跑,静默期里也清;
246
+ // 正好到时限(now - lastPushedAt === expireMs)会被清,判的是 <。
247
+ function sweep (now = Date.now()) {
248
+ const day = nowIso(new Date(now)).slice(0, 10)
249
+ let changed = false
250
+ if (data.day !== day) {
251
+ data.day = day
252
+ data.pushesToday = 0
253
+ data.freeToday = 0
254
+ changed = true
255
+ }
256
+ const expireMs = Math.max(1, cfg.expireAfterH) * 3600_000
257
+ for (const item of [...data.items]) {
258
+ if (!item.pushedCount || !item.lastPushedAt) continue
259
+ if (now - Date.parse(item.lastPushedAt) < expireMs) continue
260
+ retire(item, { droppedAt: nowIso() })
261
+ logger?.info?.(`humanlike: 惦记的事过期清掉 ${item.id}`)
262
+ changed = true
263
+ }
264
+ if (changed) save()
265
+ return changed
266
+ }
267
+
268
+ // 该不该推:启动静默 → 静默时段 → 每日配额 → 全局间隔(判 <,正好等间隔也压住)
269
+ function canPush (now = Date.now()) {
270
+ if (now - startedAt < STARTUP_SILENCE_MS) return false
271
+ if (inQuietHours(new Date(now))) return false
272
+ if (cfg.dailyPushes > 0 && data.pushesToday >= cfg.dailyPushes) return false
273
+ if (cfg.pushGapSec > 0 && now - data.lastPushAt < cfg.pushGapSec * 1000) return false
274
+ return true
275
+ }
276
+
277
+ // 推过一次就记这本账(全局间隔 + 当天次数共用)
278
+ function notePush (now = Date.now()) {
279
+ data.lastPushAt = now
280
+ data.pushesToday += 1
281
+ save()
282
+ }
283
+
284
+ return {
285
+ want, list, done, drop, promptBlock,
286
+ inQuietHours, sweep, canPush, notePush,
287
+ stats: () => ({
288
+ pending: data.items.length,
289
+ due: data.items.filter((i) => i.dueAt && Date.parse(i.dueAt) <= Date.now()).length,
290
+ recent: data.recent.length,
291
+ }),
292
+ reload: () => { load() },
293
+ }
294
+ }
295
+
296
+ export const MIND_TOOL = {
297
+ name: 'humanlike_mind',
298
+ description:
299
+ '惦记的账:给自己记一件想做、为什么、什么时候提醒;列出来;做完了;放掉。\n'
300
+ + 'want:**给你自己记一件事**:你想做什么、为什么、大概什么时候做。到点我会把你写下的原话还给你一次,'
301
+ + '做不做那一刻由你决定。要说的话、要发的消息都还是走你当前渠道已提供的发送工具,'
302
+ + '这里只管"记住我想做这件事"。\n'
303
+ + '**别拿它排满日程**——攒上好几件就变成待办清单了,那不是我。真的心里挂着才记。\n'
304
+ + 'list:看你手上还惦记着什么(含到点时间),以及最近了结掉的几件(做完的、放掉的、过期的)。\n'
305
+ + 'done:把惦记的一件标记成做完了,可以顺手写一句结果(那句话会留在你自己的账里)。\n'
306
+ + 'drop:把惦记的一件放掉(不想做了、或者那件事已经不成立了)。放下也是回答,别让它在账上反复出现。\n'
307
+ + '操作及必填参数:want(text, why,可带 about/afterMinutes 或 atTime);list();done(id,可带 outcome);drop(id)。',
308
+ parameters: {
309
+ type: 'object',
310
+ additionalProperties: false,
311
+ properties: {
312
+ action: { type: 'string', enum: ['want', 'list', 'done', 'drop'], description: '选择一次操作;只传此操作使用的参数。' },
313
+ text: { type: 'string', maxLength: TEXT_MAX, description: 'want:一句话:你想做什么(上限 200 字)。' },
314
+ why: { type: 'string', maxLength: WHY_MAX, description: 'want:为什么想做——没有理由的事不值得记(上限 200 字)。' },
315
+ about: { type: 'string', maxLength: ABOUT_MAX, description: 'want:可选:这事关于谁,或者要发给谁(如「主人」)。到点会原样提醒你。' },
316
+ afterMinutes: { type: 'integer', minimum: 1, maximum: AFTER_MINUTES_MAX, description: 'want:多少分钟之后提醒我(1 分钟 ~ 14 天)。' },
317
+ atTime: { type: 'string', description: 'want:或者直接给钟点,形如 "21:30";已经过了就是明天这个点。' },
318
+ id: { type: 'string', description: 'done:条目编号,如 m1(humanlike_mind_list 里的那个)。/drop:条目编号。' },
319
+ outcome: { type: 'string', maxLength: TEXT_MAX, description: 'done:可选:后来怎么了。' },
320
+ },
321
+ required: ['action'],
322
+ },
323
+ }