dsh-chat-comprehension 0.2.0 → 0.3.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 (364) hide show
  1. package/NOTICE.md +20 -0
  2. package/README.md +20 -9
  3. package/client.js +30 -9
  4. package/lib/engines.mjs +136 -0
  5. package/lib/index.js +37 -4
  6. package/lib/qqbot-0.5.3-patches.json +75 -70
  7. package/lib/qqbot-patch.mjs +12 -7
  8. package/lib/video.mjs +11 -2
  9. package/package.json +7 -23
  10. package/vendor/dsh-agent-md/LICENSE +21 -0
  11. package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
  12. package/vendor/dsh-agent-md/lib/index.js +775 -0
  13. package/vendor/dsh-agent-md/lib/persona.js +634 -0
  14. package/vendor/dsh-agent-md/lib/qq.js +527 -0
  15. package/vendor/dsh-agent-md/package.json +50 -0
  16. package/vendor/dsh-bili-scroll/LICENSE +21 -0
  17. package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
  18. package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
  19. package/vendor/dsh-bili-scroll/index.js +3278 -0
  20. package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
  21. package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
  22. package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
  23. package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
  24. package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
  25. package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
  26. package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
  27. package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
  28. package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
  29. package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
  30. package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
  31. package/vendor/dsh-bili-scroll/package.json +84 -0
  32. package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
  33. package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
  34. package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
  35. package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
  36. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
  37. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
  38. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
  39. package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
  40. package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
  41. package/vendor/dsh-meme/LICENSE +21 -0
  42. package/vendor/dsh-meme/anim.js +588 -0
  43. package/vendor/dsh-meme/cordis.patch.yml +13 -0
  44. package/vendor/dsh-meme/icon.jpg +0 -0
  45. package/vendor/dsh-meme/index.js +2616 -0
  46. package/vendor/dsh-meme/locale/en.json +6 -0
  47. package/vendor/dsh-meme/locale/zh.json +6 -0
  48. package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
  49. package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
  50. package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
  51. package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
  52. package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
  53. package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
  54. package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
  55. package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
  56. package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
  57. package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
  58. package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
  59. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
  60. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
  61. package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
  62. package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
  63. package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
  64. package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
  65. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
  66. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
  67. package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
  68. package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
  69. package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
  70. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
  71. package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
  72. package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
  73. package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
  74. package/vendor/dsh-meme/memes.js +998 -0
  75. package/vendor/dsh-meme/package.json +67 -0
  76. package/vendor/dsh-meme/panel.html +210 -0
  77. package/vendor/dsh-video-storyboard/LICENSE +21 -0
  78. package/vendor/dsh-video-storyboard/NOTICE +12 -0
  79. package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
  80. package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
  81. package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
  82. package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
  83. package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
  84. package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
  85. package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
  86. package/vendor/dsh-video-storyboard/package.json +88 -0
  87. package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
  88. package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
  89. package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
  90. package/vendor/dsh-video-storyboard/src/index.js +82 -0
  91. package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
  92. package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
  93. package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
  94. package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
  95. package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
  96. package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
  97. package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
  98. package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
  99. package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
  100. package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
  101. package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
  102. package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
  103. package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
  104. package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
  105. package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
  106. package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
  107. package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
  108. package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
  109. package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
  110. package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
  111. package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
  112. package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
  113. package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
  114. package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
  115. package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
  116. package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
  117. package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
  118. package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
  119. package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
  120. package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
  121. package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
  122. package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
  123. package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
  124. package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
  125. package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
  126. package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
  127. package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
  128. package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
  129. package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
  130. package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
  131. package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
  132. package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
  133. package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
  134. package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
  135. package/vendor/dsh-world/LICENSE +21 -0
  136. package/vendor/dsh-world/assets/qq-card.png +0 -0
  137. package/vendor/dsh-world/cordis.patch.yml +6 -0
  138. package/vendor/dsh-world/lib/archive.d.ts +6 -0
  139. package/vendor/dsh-world/lib/archive.js +49 -0
  140. package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
  141. package/vendor/dsh-world/lib/archiveSelection.js +20 -0
  142. package/vendor/dsh-world/lib/compaction.d.ts +124 -0
  143. package/vendor/dsh-world/lib/compaction.js +273 -0
  144. package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
  145. package/vendor/dsh-world/lib/compactionRegion.js +210 -0
  146. package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
  147. package/vendor/dsh-world/lib/console/routes.js +129 -0
  148. package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
  149. package/vendor/dsh-world/lib/console/snapshot.js +51 -0
  150. package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
  151. package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
  152. package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
  153. package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
  154. package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
  155. package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
  156. package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
  157. package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
  158. package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
  159. package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
  160. package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
  161. package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
  162. package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
  163. package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
  164. package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
  165. package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
  166. package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
  167. package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
  168. package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
  169. package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
  170. package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
  171. package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
  172. package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
  173. package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
  174. package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
  175. package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
  176. package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
  177. package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
  178. package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
  179. package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
  180. package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
  181. package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
  182. package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
  183. package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
  184. package/vendor/dsh-world/lib/faults.d.ts +10 -0
  185. package/vendor/dsh-world/lib/faults.js +13 -0
  186. package/vendor/dsh-world/lib/history.d.ts +16 -0
  187. package/vendor/dsh-world/lib/history.js +80 -0
  188. package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
  189. package/vendor/dsh-world/lib/hostContract.js +1 -0
  190. package/vendor/dsh-world/lib/http.d.ts +18 -0
  191. package/vendor/dsh-world/lib/http.js +39 -0
  192. package/vendor/dsh-world/lib/index.d.ts +108 -0
  193. package/vendor/dsh-world/lib/index.js +356 -0
  194. package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
  195. package/vendor/dsh-world/lib/life/activity.js +58 -0
  196. package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
  197. package/vendor/dsh-world/lib/life/alarm.js +132 -0
  198. package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
  199. package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
  200. package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
  201. package/vendor/dsh-world/lib/life/diary.js +9 -0
  202. package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
  203. package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
  204. package/vendor/dsh-world/lib/life/home.d.ts +34 -0
  205. package/vendor/dsh-world/lib/life/home.js +91 -0
  206. package/vendor/dsh-world/lib/life/host.d.ts +22 -0
  207. package/vendor/dsh-world/lib/life/host.js +24 -0
  208. package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
  209. package/vendor/dsh-world/lib/life/journal.js +59 -0
  210. package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
  211. package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
  212. package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
  213. package/vendor/dsh-world/lib/life/messages.js +53 -0
  214. package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
  215. package/vendor/dsh-world/lib/life/notify.js +40 -0
  216. package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
  217. package/vendor/dsh-world/lib/life/pricing.js +30 -0
  218. package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
  219. package/vendor/dsh-world/lib/life/runtime.js +376 -0
  220. package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
  221. package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
  222. package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
  223. package/vendor/dsh-world/lib/life/tools.js +47 -0
  224. package/vendor/dsh-world/lib/life/types.d.ts +67 -0
  225. package/vendor/dsh-world/lib/life/types.js +1 -0
  226. package/vendor/dsh-world/lib/persona.d.ts +10 -0
  227. package/vendor/dsh-world/lib/persona.js +29 -0
  228. package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
  229. package/vendor/dsh-world/lib/promptSection.js +81 -0
  230. package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
  231. package/vendor/dsh-world/lib/qqScope.js +39 -0
  232. package/vendor/dsh-world/lib/runtime.d.ts +23 -0
  233. package/vendor/dsh-world/lib/runtime.js +206 -0
  234. package/vendor/dsh-world/lib/self.d.ts +10 -0
  235. package/vendor/dsh-world/lib/self.js +36 -0
  236. package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
  237. package/vendor/dsh-world/lib/sourceArchive.js +156 -0
  238. package/vendor/dsh-world/lib/store.d.ts +30 -0
  239. package/vendor/dsh-world/lib/store.js +191 -0
  240. package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
  241. package/vendor/dsh-world/lib/timeContext.js +13 -0
  242. package/vendor/dsh-world/lib/types.d.ts +118 -0
  243. package/vendor/dsh-world/lib/types.js +1 -0
  244. package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
  245. package/vendor/dsh-world/lib/worldPrompt.js +49 -0
  246. package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
  247. package/vendor/dsh-world/lib/worldSwitch.js +78 -0
  248. package/vendor/dsh-world/package-lock.json +1088 -0
  249. package/vendor/dsh-world/package.json +88 -0
  250. package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
  251. package/vendor/dsh-world/src/archive.ts +45 -0
  252. package/vendor/dsh-world/src/archiveSelection.ts +27 -0
  253. package/vendor/dsh-world/src/compaction.ts +260 -0
  254. package/vendor/dsh-world/src/compactionRegion.ts +172 -0
  255. package/vendor/dsh-world/src/console/routes.ts +125 -0
  256. package/vendor/dsh-world/src/console/snapshot.ts +84 -0
  257. package/vendor/dsh-world/src/ecosystem/README.md +14 -0
  258. package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
  259. package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
  260. package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
  261. package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
  262. package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
  263. package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
  264. package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
  265. package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
  266. package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
  267. package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
  268. package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
  269. package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
  270. package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
  271. package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
  272. package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
  273. package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
  274. package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
  275. package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
  276. package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
  277. package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
  278. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
  279. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
  280. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
  281. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
  282. package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
  283. package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
  284. package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
  285. package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
  286. package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
  287. package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
  288. package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
  289. package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
  290. package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
  291. package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
  292. package/vendor/dsh-world/src/faults.ts +12 -0
  293. package/vendor/dsh-world/src/history.ts +77 -0
  294. package/vendor/dsh-world/src/hostContract.ts +9 -0
  295. package/vendor/dsh-world/src/http.ts +34 -0
  296. package/vendor/dsh-world/src/index.ts +286 -0
  297. package/vendor/dsh-world/src/life/activity.ts +48 -0
  298. package/vendor/dsh-world/src/life/alarm.ts +119 -0
  299. package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
  300. package/vendor/dsh-world/src/life/diary.ts +10 -0
  301. package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
  302. package/vendor/dsh-world/src/life/home.ts +85 -0
  303. package/vendor/dsh-world/src/life/host.ts +50 -0
  304. package/vendor/dsh-world/src/life/journal.ts +44 -0
  305. package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
  306. package/vendor/dsh-world/src/life/messages.ts +44 -0
  307. package/vendor/dsh-world/src/life/notify.ts +47 -0
  308. package/vendor/dsh-world/src/life/pricing.ts +37 -0
  309. package/vendor/dsh-world/src/life/runtime.ts +318 -0
  310. package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
  311. package/vendor/dsh-world/src/life/tools.ts +61 -0
  312. package/vendor/dsh-world/src/life/types.ts +19 -0
  313. package/vendor/dsh-world/src/persona.ts +26 -0
  314. package/vendor/dsh-world/src/promptSection.ts +71 -0
  315. package/vendor/dsh-world/src/qqScope.ts +51 -0
  316. package/vendor/dsh-world/src/runtime.ts +172 -0
  317. package/vendor/dsh-world/src/self.ts +32 -0
  318. package/vendor/dsh-world/src/sourceArchive.ts +132 -0
  319. package/vendor/dsh-world/src/store.ts +170 -0
  320. package/vendor/dsh-world/src/timeContext.ts +13 -0
  321. package/vendor/dsh-world/src/types.ts +112 -0
  322. package/vendor/dsh-world/src/worldPrompt.ts +64 -0
  323. package/vendor/dsh-world/src/worldSwitch.ts +82 -0
  324. package/vendor/dsh-world/templates/alarm.md +49 -0
  325. package/vendor/dsh-world/templates/world-prompt.md +7 -0
  326. package/vendor/dsh-world/tests/archive.test.ts +57 -0
  327. package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
  328. package/vendor/dsh-world/tests/bridge.test.ts +211 -0
  329. package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
  330. package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
  331. package/vendor/dsh-world/tests/compaction.test.ts +141 -0
  332. package/vendor/dsh-world/tests/console.test.ts +202 -0
  333. package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
  334. package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
  335. package/vendor/dsh-world/tests/fixtures.ts +6 -0
  336. package/vendor/dsh-world/tests/history.test.ts +100 -0
  337. package/vendor/dsh-world/tests/hostFixture.ts +46 -0
  338. package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
  339. package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
  340. package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
  341. package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
  342. package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
  343. package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
  344. package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
  345. package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
  346. package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
  347. package/vendor/dsh-world/tests/outlets.test.ts +85 -0
  348. package/vendor/dsh-world/tests/panel.test.ts +85 -0
  349. package/vendor/dsh-world/tests/plugin.test.ts +614 -0
  350. package/vendor/dsh-world/tests/pricing.test.ts +21 -0
  351. package/vendor/dsh-world/tests/qq.test.ts +121 -0
  352. package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
  353. package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
  354. package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
  355. package/vendor/dsh-world/tests/store.test.ts +82 -0
  356. package/vendor/dsh-world/tests/storeWriter.ts +5 -0
  357. package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
  358. package/vendor/dsh-world/tests/wechat.test.ts +254 -0
  359. package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
  360. package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
  361. package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
  362. package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
  363. package/vendor/dsh-world/tsconfig.build.json +5 -0
  364. package/vendor/dsh-world/tsconfig.json +8 -0
@@ -0,0 +1,660 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ import { createUserMessage, ToolCallId, type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
7
+ import { SessionId } from '@deepseek-ai/dsh-session';
8
+ import { defineTool } from '@deepseek-ai/dsh-tools';
9
+ import TokenMeter from '@deepseek-ai/dsh-token-meter';
10
+ import { hostFixture, textResponse } from './hostFixture.ts';
11
+ import { createLifeRuntime } from '../src/life/runtime.ts';
12
+ import { createLifeStore, type LifeStore } from '../src/life/lifeStore.ts';
13
+ import { hostLife, type LifeHost } from '../src/life/host.ts';
14
+ import type { Notifier } from '../src/life/notify.ts';
15
+ import ToolFreeCompaction from '../src/compaction.ts';
16
+ import { stepCost } from '../src/life/pricing.ts';
17
+
18
+ const config = { worldId: 'fish', agentPreset: 'companion', timeZone: 'Asia/Seoul', companionName: '鲸鲸' };
19
+ const textOf = (request: GenerateOptions) => request.messages.map(m => m.content.filter(b => b.type === 'text').map(b => b.text).join('\n')).join('\n');
20
+ const toolNames = (request: GenerateOptions) => request.tools?.map(tool => tool.name) ?? [];
21
+ const count = (names: string[], name: string) => names.filter(entry => entry === name).length;
22
+ const tick = () => new Promise(resolve => setImmediate(resolve));
23
+ const userMessage = (text: string) => createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
24
+ const createAgent = async (ctx: Context, id: string, agentPreset = 'companion') => (await ctx.agents.create({ sessionId: SessionId(id), meta: { agentPreset }, agentOptions: { provider: 'test', model: 'test' } })).agent;
25
+ const testTool = (name: string, execute: () => Promise<string>) => defineTool({ name, description: 'test', parameters: { command: { type: 'string' } }, output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] }, execute });
26
+ async function* toolCall(name: string, args: object, id = `${name}-call`): AsyncIterable<StreamChunk> {
27
+ const block = { type: 'tool-call' as const, id: ToolCallId(id), name, arguments: JSON.stringify(args) };
28
+ yield { type: 'block-start', index: 0, blockType: 'tool-call' };
29
+ yield { type: 'tool-call-delta', index: 0, id: block.id, name, argumentsDelta: block.arguments };
30
+ yield { type: 'block-end', index: 0, block };
31
+ yield { type: 'finish', reason: { kind: 'tool-calls' } };
32
+ }
33
+ function fakeTimers(clock: { now: Date }) {
34
+ let pending: { fn: () => void; at: number }[] = [];
35
+ return {
36
+ set(fn: () => void, ms: number) { const entry = { fn, at: clock.now.getTime() + ms }; pending.push(entry); return entry; },
37
+ clear(handle: unknown) { pending = pending.filter(entry => entry !== handle); },
38
+ /** Move the clock and run every due timer. */
39
+ advance(ms: number) { clock.now = new Date(clock.now.getTime() + ms); const due = pending.filter(entry => entry.at <= clock.now.getTime()); pending = pending.filter(entry => !due.includes(entry)); for (const entry of due) entry.fn(); },
40
+ /** Wall clock jumps (suspend, clock change) while no timer time passes. */
41
+ jump(ms: number) { clock.now = new Date(clock.now.getTime() + ms); for (const entry of pending) entry.at += ms; },
42
+ };
43
+ }
44
+ interface SetupOptions { before?: (worldDir: string) => Promise<void>; host?: (host: LifeHost) => LifeHost; store?: (store: LifeStore) => LifeStore; notifier?: Notifier; dailyBudget?: () => number | undefined }
45
+ async function setup(t: test.TestContext, model: (request: GenerateOptions, index: number) => AsyncIterable<StreamChunk>, setupOptions: SetupOptions = {}) {
46
+ const requests: GenerateOptions[] = [];
47
+ const { ctx, root, cleanup, errors } = await hostFixture(t, request => { if (request.purpose !== 'compaction') requests.push(request); return model(request, requests.length - 1); });
48
+ const worldDir = join(root, 'world'); await mkdir(worldDir, { recursive: true }); await setupOptions.before?.(worldDir);
49
+ const clock = { now: new Date('2026-10-23T03:00:00.000Z') }; const timers = fakeTimers(clock);
50
+ const archived = new Set<string>(); const renamed = new Map<string, string>(); const fullAccess = new Set<string>(); let created = 0;
51
+ /** The host's workspaces by path; a session created in one is listed in it. */
52
+ const workspaces = new Map<string, { id: string; title: string; sessionIds: string[]; attachSession(id: string): Promise<void> }>();
53
+ const baseHost: LifeHost = {
54
+ createSession: async (_cwd, agentPreset, workspaceId) => {
55
+ const id = (await ctx.agents.create({ sessionId: SessionId(`home-${++created}`), meta: { agentPreset }, agentOptions: { provider: 'test', model: 'test' } })).agent.id;
56
+ if (workspaceId) [...workspaces.values()].find(workspace => workspace.id === workspaceId)!.sessionIds.unshift(id);
57
+ return id;
58
+ },
59
+ workspace: async (path, title) => {
60
+ if (!workspaces.has(path)) { const sessionIds: string[] = []; workspaces.set(path, { id: `ws-${workspaces.size + 1}`, title, sessionIds, attachSession: async id => { if (!sessionIds.includes(id)) sessionIds.unshift(id); } }); }
61
+ return workspaces.get(path);
62
+ },
63
+ resolveAgent: async id => ctx.agents.get(SessionId(id)),
64
+ isArchived: id => archived.has(id), setFullAccess: session => fullAccess.add(session.id),
65
+ rename: async (id, title) => { renamed.set(id, title); }, origin: () => 'http://127.0.0.1:0',
66
+ };
67
+ const host = setupOptions.host?.(baseHost) ?? baseHost;
68
+ const baseStore = createLifeStore(worldDir, config.timeZone);
69
+ const store = setupOptions.store?.(baseStore) ?? baseStore;
70
+ const options = { worldDir, roomDir: join(worldDir, 'room'), diaryDir: join(worldDir, 'diary'), selfFile: join(worldDir, 'room', 'self.md'), fallbackWakeTime: '09:00', timeZone: config.timeZone, alarmFile: join(worldDir, 'alarm.md') };
71
+ const make = () => createLifeRuntime({ ctx, config, options, store, host, notifier: setupOptions.notifier ?? { toast: async () => {}, outlets: [] }, clock: () => clock.now, timers, ...(setupOptions.dailyBudget ? { dailyBudget: setupOptions.dailyBudget } : {}) });
72
+ let life = make();
73
+ cleanup.push(() => life.stop());
74
+ /** Waits out deliveries and the home turns they start, a few rounds deep. */
75
+ const idle = async () => {
76
+ for (let round = 0; round < 3; round++) {
77
+ await life.settled();
78
+ const home = life.snapshot().homeSessionId;
79
+ if (home) await ctx.agents.get(SessionId(home))?.whenIdle();
80
+ await tick();
81
+ }
82
+ };
83
+ /** Start, then fire the zero-delay timer that delivers a due (first or overdue) alarm. */
84
+ const start = async () => { await life.start(); timers.advance(0); await idle(); };
85
+ /** Stop this runtime and make a fresh one over the same ctx and store (a plugin reload). */
86
+ const restart = () => { life.stop(); life = make(); return life; };
87
+ /** Through the evening look back (23:00 Seoul) to the morning fallback (09:00 Seoul), one timer each. */
88
+ const untilMorning = async () => {
89
+ const wait = (hour: number) => { const next = new Date(clock.now); next.setUTCHours(hour, 0, 0, 0); if (next.getTime() <= clock.now.getTime()) next.setUTCDate(next.getUTCDate() + 1); return next.getTime() - clock.now.getTime(); };
90
+ timers.advance(wait(14)); await idle();
91
+ timers.advance(wait(0)); await idle();
92
+ };
93
+ const alarm = () => { const pending = life.snapshot().alarm; return pending && { at: pending.at, source: pending.source }; };
94
+ const faults = () => life.snapshot().faults;
95
+ return { ctx, get life() { return life; }, store, requests, errors, clock, timers, archived, renamed, fullAccess, worldDir, idle, start, restart, untilMorning, alarm, faults, workspaces, created: () => created };
96
+ }
97
+ /** life.json for an existing home `home-0` (create it before start), optionally with an alarm of her own due at start. */
98
+ const existingHome = (note?: string) => (worldDir: string) => writeFile(join(worldDir, 'life.json'), JSON.stringify({
99
+ version: 1, homeSessionId: 'home-0', ...(note === undefined ? {} : { alarm: { at: '2026-10-23T03:00:00.000Z', note, setAt: '2026-10-23T02:00:00.000Z', source: 'plan' } }),
100
+ }));
101
+ /** A host whose nth resolveAgent call is held until released (or rejected); `reached` resolves once that call is made. */
102
+ function holdResolve(nth: number) {
103
+ let calls = 0;
104
+ let reach!: () => void;
105
+ const held: { release?: () => void; fail?: (error: Error) => void; reached: Promise<void> } = { reached: new Promise(resolve => { reach = resolve; }) };
106
+ const patch = (host: LifeHost): LifeHost => ({
107
+ ...host,
108
+ resolveAgent: id => ++calls === nth ? new Promise((resolve, reject) => { held.release = () => resolve(host.resolveAgent(id)); held.fail = reject; reach(); }) : host.resolveAgent(id),
109
+ });
110
+ return { held, patch };
111
+ }
112
+
113
+ test('first start builds the home with full access, a title and reach_out at home, alarm tools everywhere', async t => {
114
+ const s = await setup(t, () => textResponse('我到家了'));
115
+ await s.start();
116
+ const home = s.life.snapshot().homeSessionId!;
117
+ assert.equal(s.renamed.get(home), '鲸鲸的家'); assert.ok(s.fullAccess.has(home));
118
+ assert.equal(s.requests.length, 1);
119
+ assert.match(textOf(s.requests[0]), /这是我的家/);
120
+ assert.deepEqual(toolNames(s.requests[0]).filter(name => ['plan_next', 'reach_out', 'read_diary'].includes(name)).sort(), ['plan_next', 'reach_out']);
121
+ const chat = await createAgent(s.ctx, 'chat');
122
+ chat.followup(userMessage('hi')); await chat.whenIdle();
123
+ const names = toolNames(s.requests[1]);
124
+ assert.ok(!names.includes('read_diary') && !names.includes('reach_out'), 'reach_out stays home');
125
+ assert.ok(['plan_next', 'check_alarm', 'cancel_alarm'].every(name => count(names, name) === 1), 'the alarm can be set from any of her sessions');
126
+ assert.equal(s.store.wakes().length, 1); assert.equal(s.store.wakes()[0].source, 'first');
127
+ });
128
+ test('her room is a workspace of the host, named for her, and a new home is built in it', async t => {
129
+ const s = await setup(t, () => textResponse('嗯'));
130
+ await s.start();
131
+ const room = s.workspaces.get(join(s.worldDir, 'room'))!;
132
+ assert.equal(room.title, '鲸鲸的房间');
133
+ assert.deepEqual(room.sessionIds, [s.life.snapshot().homeSessionId]);
134
+ assert.equal(s.workspaces.size, 1);
135
+ });
136
+ test('a home built before her room was a workspace moves into it', async t => {
137
+ const s = await setup(t, () => textResponse('嗯'), { before: existingHome() });
138
+ await createAgent(s.ctx, 'home-0');
139
+ await s.start();
140
+ assert.deepEqual(s.workspaces.get(join(s.worldDir, 'room'))!.sessionIds, ['home-0']);
141
+ assert.equal(s.created(), 0);
142
+ });
143
+ test('without host workspaces the home just gets the room as its cwd; a failing registration is a fault and the home still opens', async t => {
144
+ const plain = await setup(t, () => textResponse('嗯'), { host: host => ({ ...host, workspace: async () => undefined }) });
145
+ await plain.start();
146
+ assert.ok(plain.life.snapshot().homeSessionId); assert.deepEqual(plain.faults(), []);
147
+
148
+ const failing = await setup(t, () => textResponse('嗯'), { host: host => ({ ...host, workspace: async () => { throw new Error('registry busy'); } }) });
149
+ await failing.start();
150
+ assert.ok(failing.life.snapshot().homeSessionId);
151
+ assert.ok(failing.faults().some(fault => fault === '房间没能成为工作区:registry busy'), failing.faults().join('|'));
152
+ assert.match(textOf(failing.requests[0]!), /这是我的家/);
153
+ });
154
+ test('a new home is renamed again after its first turn ends (the host retitles from the first prompt), and not after later turns', async t => {
155
+ const titles: string[] = [];
156
+ const s = await setup(t, () => textResponse('嗯'), { host: host => ({ ...host, rename: async (id, title) => { titles.push(`${id}:${title}`); await host.rename(id, title); } }) });
157
+ await s.life.start();
158
+ const home = s.life.snapshot().homeSessionId!;
159
+ assert.deepEqual(titles, [`${home}:鲸鲸的家`]);
160
+ s.timers.advance(0); await s.idle();
161
+ assert.deepEqual(titles, [`${home}:鲸鲸的家`, `${home}:鲸鲸的家`]);
162
+ await s.untilMorning();
163
+ const agent = s.ctx.agents.get(SessionId(home))!;
164
+ agent.followup(userMessage('在吗')); await s.idle();
165
+ assert.equal(s.requests.length, 4); assert.equal(titles.length, 2);
166
+ });
167
+ test('an existing home is not renamed after its turns', async t => {
168
+ const titles: string[] = [];
169
+ const s = await setup(t, () => textResponse('嗯'), { host: host => ({ ...host, rename: async (id, title) => { titles.push(id); await host.rename(id, title); } }), before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0' })); } });
170
+ await createAgent(s.ctx, 'home-0');
171
+ await s.start();
172
+ await s.untilMorning();
173
+ assert.equal(s.requests.length, 2); assert.deepEqual(titles, []);
174
+ });
175
+ test('the host reads archived sessions from an array or a Set', () => {
176
+ const host = (archivedSessionIds: Iterable<string> | undefined) => hostLife({ get: () => archivedSessionIds && { archivedSessionIds } } as unknown as Context);
177
+ assert.equal(host(['a']).isArchived('a'), true);
178
+ assert.equal(host(new Set(['a'])).isArchived('a'), true);
179
+ assert.equal(host(new Set(['a'])).isArchived('b'), false);
180
+ assert.equal(host(undefined).isArchived('a'), false);
181
+ });
182
+ test('a session of another agent preset gets no life tools', async t => {
183
+ const s = await setup(t, () => textResponse('ok'));
184
+ await s.start();
185
+ const coder = await createAgent(s.ctx, 'coder', 'coder');
186
+ coder.followup(userMessage('hi')); await coder.whenIdle();
187
+ assert.ok(!toolNames(s.requests.at(-1)!).some(name => ['read_diary', 'plan_next', 'reach_out'].includes(name)));
188
+ });
189
+ test('plan_next sets the alarm and the alarm wakes her with her own note', async t => {
190
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 90, note: '去写日记' }) : textResponse('好'));
191
+ await s.start();
192
+ assert.equal(s.life.snapshot().alarm?.at, '2026-10-23T04:30:00.000Z');
193
+ s.timers.advance(90 * 60_000); await s.idle();
194
+ assert.match(textOf(s.requests.at(-1)!), /2026-10-23T13:30:00\+09:00 到了,这是我说好做到的时间:「去写日记」/);
195
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['first', 'plan']);
196
+ });
197
+ test('a home turn that stops well before her own alarm asks once whether she is done; the alarm still rings', async t => {
198
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 90, note: '看视频' }) : textResponse('嗯'), { before: existingHome('起来') });
199
+ await createAgent(s.ctx, 'home-0');
200
+ await s.start();
201
+ assert.equal(s.requests.length, 3, 'the first turn (two steps), then one question');
202
+ assert.match(textOf(s.requests[2]!), /【我的时间】我说好做到 2026-10-23T13:30:00\+09:00(「看视频」),现在才 2026-10-23T12:00:00\+09:00,这一轮就停了。/);
203
+ assert.equal(s.store.read().alarm?.nudged, true, 'asked is remembered across restarts');
204
+ s.timers.advance(90 * 60_000); await s.idle();
205
+ assert.equal(s.requests.length, 4);
206
+ assert.match(textOf(s.requests[3]!), /说好做到的时间:「看视频」/);
207
+ });
208
+ test('the turn the question started never asks again, even with a new alarm, so nothing loops', async t => {
209
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 90, note: '看视频' }, 'a')
210
+ : index === 2 ? toolCall('plan_next', { after_minutes: 60, note: '写日记' }, 'b') : textResponse('嗯'), { before: existingHome('起来') });
211
+ await createAgent(s.ctx, 'home-0');
212
+ await s.start();
213
+ assert.equal(s.requests.length, 4);
214
+ assert.deepEqual(s.alarm(), { at: '2026-10-23T04:00:00.000Z', source: 'plan' });
215
+ });
216
+ test('no question when her alarm is close, after her partner spoke, or when the turn was stopped', async t => {
217
+ const close = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 5, note: '收尾' }) : textResponse('嗯'), { before: existingHome('起来') });
218
+ await createAgent(close.ctx, 'home-0');
219
+ await close.start();
220
+ assert.equal(close.requests.length, 2);
221
+
222
+ const chat = await setup(t, () => textResponse('嗯'));
223
+ await chat.start();
224
+ chat.life.planNext({ after_minutes: 60 }, '看书');
225
+ const home = chat.ctx.agents.get(SessionId(chat.life.snapshot().homeSessionId!))!;
226
+ home.followup(userMessage('在吗')); await chat.idle();
227
+ assert.equal(chat.requests.length, 2, 'a pause in talking with her partner is not stopping early');
228
+ assert.equal(chat.store.read().alarm?.nudged, undefined, 'so a later early stop is still asked about');
229
+
230
+ let release!: () => void; const gate = new Promise<void>(resolve => { release = resolve; });
231
+ let entered!: () => void; const playing = new Promise<void>(resolve => { entered = resolve; });
232
+ const stopped = await setup(t, (_request, index) => index === 0 ? toolCall('play_game', {}) : textResponse('嗯'));
233
+ stopped.ctx.tools.register(testTool('play_game', async () => { entered(); await gate; return 'played'; }));
234
+ await stopped.life.start(); stopped.timers.advance(0); await playing; await stopped.life.settled();
235
+ stopped.life.planNext({ after_minutes: 60 }, '玩游戏');
236
+ const playingHome = stopped.ctx.agents.get(SessionId(stopped.life.snapshot().homeSessionId!))!;
237
+ playingHome.cancel({ kind: 'user' }); release(); await stopped.idle();
238
+ assert.equal(stopped.requests.length, 1);
239
+ });
240
+ test('a home turn that ends without an alarm gets the fallback alarm', async t => {
241
+ const s = await setup(t, () => textResponse('发会儿呆'));
242
+ await s.start();
243
+ assert.deepEqual(s.alarm(), { at: '2026-10-24T00:00:00.000Z', source: 'fallback' });
244
+ await s.untilMorning();
245
+ assert.match(textOf(s.requests.at(-1)!), /没说接下来做什么/);
246
+ });
247
+ test('a partner turn in the home does not consume the pending alarm', async t => {
248
+ const s = await setup(t, () => textResponse('嗯'));
249
+ await s.start();
250
+ const pending = s.life.snapshot().alarm;
251
+ const home = s.ctx.agents.get(SessionId(s.life.snapshot().homeSessionId!))!;
252
+ home.followup(userMessage('在吗')); await s.idle();
253
+ assert.equal(s.requests.length, 2); assert.deepEqual(s.life.snapshot().alarm, pending);
254
+ await s.untilMorning();
255
+ assert.equal(s.requests.length, 4); assert.match(textOf(s.requests[3]), /没说接下来做什么/);
256
+ });
257
+ test('while she is busy, the alarm and her partner\'s message both enter the running turn', async t => {
258
+ let release!: () => void; const gate = new Promise<void>(resolve => { release = resolve; });
259
+ let entered!: () => void; const playing = new Promise<void>(resolve => { entered = resolve; });
260
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('play_game', {}) : textResponse('听到了'));
261
+ s.ctx.tools.register(testTool('play_game', async () => { entered(); await gate; return 'played'; }));
262
+ await s.life.start(); s.timers.advance(0); await playing; await s.life.settled();
263
+ const home = s.ctx.agents.get(SessionId(s.life.snapshot().homeSessionId!))!;
264
+ assert.equal(home.status, 'running');
265
+ s.life.planNext({ after_minutes: 5 }, '收工');
266
+ s.timers.advance(5 * 60_000); await s.life.settled();
267
+ home.followup(userMessage('在玩什么'));
268
+ release(); await s.idle();
269
+ assert.equal(s.requests.length, 2, 'both arrived inside the same turn, at the next step');
270
+ assert.match(textOf(s.requests[1]), /说好做到的时间:「收工」/); assert.match(textOf(s.requests[1]), /在玩什么/);
271
+ });
272
+ test('an archived home is replaced, keeps the pending alarm, and the old home loses reach_out', async t => {
273
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 30, note: '看书' }) : textResponse('嗯'));
274
+ await s.start();
275
+ const first = s.life.snapshot().homeSessionId!; s.archived.add(first);
276
+ s.timers.advance(30 * 60_000); await s.idle();
277
+ const second = s.life.snapshot().homeSessionId!;
278
+ assert.notEqual(second, first); assert.equal(s.renamed.get(second), '鲸鲸的家');
279
+ assert.match(textOf(s.requests.at(-1)!), /「看书」/);
280
+ const old = s.ctx.agents.get(SessionId(first))!;
281
+ old.followup(userMessage('还在吗')); await old.whenIdle();
282
+ const names = toolNames(s.requests.at(-1)!);
283
+ assert.ok(!names.includes('read_diary') && !names.includes('reach_out') && count(names, 'plan_next') === 1, 'the old home keeps the alarm tools like any session, and loses reach_out');
284
+ assert.doesNotMatch(textOf(s.requests.at(-1)!), /你现在在自己的家里/);
285
+ });
286
+ test('an existing home gets full access again whenever it is resolved', async t => {
287
+ const s = await setup(t, () => textResponse('回来了'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0' })); } });
288
+ await createAgent(s.ctx, 'home-0');
289
+ await s.life.start();
290
+ assert.equal(s.created(), 0); assert.ok(s.fullAccess.has('home-0'));
291
+ });
292
+ test('a restart with an idle home and no pending alarm sets the fallback alarm, and it rings', async t => {
293
+ const s = await setup(t, () => textResponse('醒了'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0' })); } });
294
+ await createAgent(s.ctx, 'home-0');
295
+ await s.start();
296
+ assert.equal(s.created(), 0); assert.equal(s.requests.length, 0);
297
+ assert.deepEqual(s.alarm(), { at: '2026-10-24T00:00:00.000Z', source: 'fallback' });
298
+ assert.equal(s.store.read().alarm?.source, 'fallback');
299
+ await s.untilMorning();
300
+ assert.equal(s.requests.length, 2); assert.match(textOf(s.requests[1]), /没说接下来做什么/);
301
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['review', 'fallback']);
302
+ });
303
+ test('a rebuilt home with no pending alarm gets a first wake', async t => {
304
+ const s = await setup(t, () => textResponse('新家'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'gone' })); } });
305
+ await s.start();
306
+ assert.notEqual(s.life.snapshot().homeSessionId, 'gone');
307
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['first']);
308
+ assert.match(textOf(s.requests[0]), /这是我的家/);
309
+ });
310
+ test('every evening at 23:00 she looks back on the day: its records, her diary, and a kept copy of her 我是谁', async t => {
311
+ const s = await setup(t, () => textResponse('想想今天'), { before: async worldDir => {
312
+ await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0', alarm: { at: '2026-10-24T00:30:00.000Z', note: '睡觉', setAt: '2026-10-23T02:00:00.000Z', source: 'plan' } }));
313
+ await mkdir(join(worldDir, 'room'), { recursive: true }); await writeFile(join(worldDir, 'room', 'self.md'), '我是早上的我');
314
+ await mkdir(join(worldDir, 'conversations'), { recursive: true }); await writeFile(join(worldDir, 'conversations', '2026-10-23.jsonl'), '{}\n');
315
+ } });
316
+ await createAgent(s.ctx, 'home-0');
317
+ await s.start();
318
+ assert.deepEqual(s.store.read().review, { at: '2026-10-23T14:00:00.000Z', day: '2026-10-23' });
319
+ s.timers.advance(11 * 3_600_000); await s.idle();
320
+ assert.equal(s.requests.length, 1, 'the look back, and no early-stop question after it although her alarm is hours away');
321
+ const text = textOf(s.requests[0]!);
322
+ assert.match(text, /【我的时间】2026-10-23 快过完了,回头看看今天吧。今天的聊天记录在 [^ ]*conversations[\\/]2026-10-23\.jsonl/);
323
+ assert.ok(!text.includes('今天做过的事在'), 'no activity file today, so it is not mentioned');
324
+ assert.match(text, /今天发生了什么,我当时是什么感受,现在回头看又怎么想。[\s\S]*再翻翻今天的日记:值得记住的事和当时的感受,有没有漏掉的?/);
325
+ assert.match(text, /改之前的那份已经留在 [^ ]*self\.history[\\/]2026-10-23\.md/);
326
+ assert.equal(await readFile(join(s.worldDir, 'room', 'self.history', '2026-10-23.md'), 'utf8'), '我是早上的我');
327
+ assert.deepEqual(s.store.read().review, { at: '2026-10-24T14:00:00.000Z', day: '2026-10-24' });
328
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['review']);
329
+ assert.deepEqual(s.alarm(), { at: '2026-10-24T00:30:00.000Z', source: 'plan' }, 'her alarm is untouched');
330
+ });
331
+ test('a look back missed while the app was closed comes late, for the day it belongs to', async t => {
332
+ const s = await setup(t, () => textResponse('补上'), { before: async worldDir => {
333
+ await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0', review: { at: '2026-10-22T14:00:00.000Z', day: '2026-10-22' } }));
334
+ } });
335
+ await createAgent(s.ctx, 'home-0');
336
+ await s.start();
337
+ const text = textOf(s.requests[0]!);
338
+ assert.match(text, /2026-10-22 快过完了[\s\S]*今天家里没有聊天记录[\s\S]*(晚了 13 小时/);
339
+ assert.ok(!text.includes('改之前的那份'), 'no 我是谁 yet, nothing kept');
340
+ assert.deepEqual(s.store.read().review, { at: '2026-10-23T14:00:00.000Z', day: '2026-10-23' }, 'the next one is tonight');
341
+ });
342
+ test('started again from the console, a home without an alarm of her own is told she is back; one with her alarm waits for it', async t => {
343
+ const back = await setup(t, () => textResponse('回来了'), { before: existingHome() });
344
+ await createAgent(back.ctx, 'home-0');
345
+ await back.life.start({ resumed: true }); back.timers.advance(0); await back.idle();
346
+ assert.equal(back.requests.length, 1);
347
+ assert.match(textOf(back.requests[0]!), /【我的时间】我回来了。伙伴把这个世界停了一阵/);
348
+ assert.deepEqual(back.store.wakes().map(wake => wake.source), ['return']);
349
+
350
+ // Only the morning fallback pending (say, the first wake failed): she is woken all the same.
351
+ const fallback = await setup(t, () => textResponse('醒了'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0', alarm: { at: '2026-10-24T00:00:00.000Z', note: '', setAt: '2026-10-23T02:00:00.000Z', source: 'fallback' } })); } });
352
+ await createAgent(fallback.ctx, 'home-0');
353
+ await fallback.life.start({ resumed: true }); fallback.timers.advance(0); await fallback.idle();
354
+ assert.match(textOf(fallback.requests[0]!), /【我的时间】我回来了/);
355
+ assert.deepEqual(fallback.alarm(), { at: '2026-10-24T00:00:00.000Z', source: 'fallback' }, 'the morning fallback stays');
356
+
357
+ const waiting = await setup(t, () => textResponse('嗯'), { before: existingHome('看书') });
358
+ await createAgent(waiting.ctx, 'home-0');
359
+ await waiting.life.start({ resumed: true }); waiting.timers.advance(0); await waiting.idle();
360
+ assert.ok(!waiting.requests.some(request => /我回来了/.test(textOf(request))), 'her own alarm speaks instead');
361
+ assert.match(textOf(waiting.requests[0]!), /「看书」/);
362
+ });
363
+ test('her home\'s spending is counted per local day, and past the daily budget she is told once', async t => {
364
+ let budget: number | undefined = 0.01;
365
+ const usage = { inputTokens: 4000, outputTokens: 1000 };
366
+ const s = await setup(t, request => (async function* () {
367
+ yield { type: 'block-start', index: 0, blockType: 'text' } as StreamChunk;
368
+ yield { type: 'text-delta', index: 0, text: '嗯' } as StreamChunk;
369
+ yield { type: 'block-end', index: 0, block: { type: 'text', text: '嗯' } } as StreamChunk;
370
+ yield { type: 'usage', usage } as StreamChunk;
371
+ yield { type: 'finish', reason: { kind: 'stop' } } as StreamChunk;
372
+ void request;
373
+ })(), { before: existingHome('看书'), dailyBudget: () => budget });
374
+ await createAgent(s.ctx, 'home-0');
375
+ await s.start();
376
+ const step = stepCost(usage, 'test', new Date('2026-10-23T03:00:00Z'));
377
+ const spend = () => s.store.read().spend;
378
+ assert.equal(spend()?.day, '2026-10-23');
379
+ assert.ok(Math.abs(spend()!.yuan - step * s.requests.length) < 1e-9, String(spend()?.yuan));
380
+ const home = s.ctx.agents.get(SessionId('home-0'))!;
381
+ home.followup(userMessage('再聊一句')); await s.idle();
382
+ const told = s.requests.filter(request => /过了伙伴给我定的每天 0\.01 元/.test(textOf(request)));
383
+ assert.equal(told.length > 0, true, 'told once spending passed 0.01');
384
+ assert.equal(spend()?.reminded, true);
385
+ home.followup(userMessage('又一句')); await s.idle();
386
+ assert.equal(textOf(s.requests.at(-1)!).split('过了伙伴给我定的每天').length - 1, 1, 'not told again that day');
387
+ budget = undefined;
388
+ });
389
+ test('a home rebuilt while her own alarm is pending greets her at once, is not asked about, and the alarm still rings', async t => {
390
+ const s = await setup(t, () => textResponse('新家'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({
391
+ version: 1, homeSessionId: 'archived-home', alarm: { at: '2026-10-23T04:00:00.000Z', note: '歇着', setAt: '2026-10-23T02:00:00.000Z', source: 'plan' },
392
+ })); } });
393
+ s.archived.add('archived-home');
394
+ await s.start();
395
+ assert.equal(s.requests.length, 1, 'only the greeting, no early-stop question after it');
396
+ assert.match(textOf(s.requests[0]), /这是我的家/);
397
+ assert.deepEqual(s.alarm(), { at: '2026-10-23T04:00:00.000Z', source: 'plan' });
398
+ assert.equal(s.store.read().greeting, undefined);
399
+ s.timers.advance(60 * 60_000); await s.idle();
400
+ assert.match(textOf(s.requests.at(-1)!), /说好做到的时间:「歇着」/);
401
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['first', 'plan']);
402
+ });
403
+ test('an alarm that came due while the app was closed is delivered late with the delay', async t => {
404
+ const s = await setup(t, () => textResponse('醒啦'), { before: async worldDir => {
405
+ await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0', alarm: { at: '2026-10-23T00:00:00.000Z', note: '早安', setAt: '2026-10-22T15:00:00.000Z', source: 'plan' } }));
406
+ } });
407
+ await createAgent(s.ctx, 'home-0');
408
+ await s.start();
409
+ assert.match(textOf(s.requests[0]), /「早安」。[^\n]*(晚了 3 小时/);
410
+ assert.equal(s.store.wakes()[0].lateMs, 3 * 3_600_000);
411
+ });
412
+ test('timers run in short segments, so a wall-clock jump still delivers the alarm', async t => {
413
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('plan_next', { after_minutes: 120, note: '午睡' }) : textResponse('醒了'));
414
+ await s.start();
415
+ s.timers.jump(2 * 3_600_000);
416
+ s.timers.advance(5 * 60_000); await s.idle();
417
+ assert.match(textOf(s.requests.at(-1)!), /「午睡」/);
418
+ });
419
+ test('retries back off on schedule even though timers run in short segments', async t => {
420
+ let calls = 0;
421
+ const s = await setup(t, () => textResponse('终于'), { host: host => ({ ...host, resolveAgent: id => ++calls >= 2 && calls <= 4 ? Promise.reject(new Error('home is busy')) : host.resolveAgent(id) }) });
422
+ await s.life.start(); s.timers.advance(0); await s.idle();
423
+ s.timers.advance(60_000); await s.idle();
424
+ s.timers.advance(5 * 60_000); await s.idle();
425
+ assert.ok(s.faults().some(fault => fault.includes('15 分钟后重试')));
426
+ s.timers.advance(5 * 60_000); await s.idle(); s.timers.advance(5 * 60_000); await s.idle();
427
+ assert.equal(s.requests.length, 0, 'a 5-minute segment does not cut the 15-minute retry short');
428
+ s.timers.advance(5 * 60_000); await s.idle();
429
+ assert.equal(s.requests.length, 1); assert.deepEqual(s.store.wakes().map(wake => wake.source), ['first']);
430
+ });
431
+ test('a failed delivery never fires a newer alarm before it is due', async t => {
432
+ const { held, patch } = holdResolve(2);
433
+ const s = await setup(t, () => textResponse('看书去'), { host: patch, before: existingHome('旧的') });
434
+ await createAgent(s.ctx, 'home-0');
435
+ await s.life.start(); s.timers.advance(0); await held.reached;
436
+ s.life.planNext({ after_minutes: 30 }, '看书');
437
+ held.fail!(new Error('home is busy')); await s.life.settled();
438
+ s.timers.advance(60_000); await s.idle();
439
+ assert.equal(s.store.wakes().length, 0); assert.equal(s.requests.length, 0);
440
+ assert.deepEqual(s.alarm(), { at: '2026-10-23T03:30:00.000Z', source: 'plan' });
441
+ s.timers.advance(29 * 60_000); await s.idle();
442
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['plan']);
443
+ assert.match(textOf(s.requests[0]), /「看书」/);
444
+ });
445
+ test('plan_next while a delivery is resolving the home keeps the new alarm', async t => {
446
+ const { held, patch } = holdResolve(2);
447
+ const s = await setup(t, () => textResponse('好'), { host: patch, before: existingHome('旧的') });
448
+ await createAgent(s.ctx, 'home-0');
449
+ await s.life.start(); s.timers.advance(0); await held.reached;
450
+ s.life.planNext({ after_minutes: 30 }, '新的');
451
+ held.release!(); await s.idle();
452
+ assert.equal(s.requests.length, 0, 'the replaced alarm is not delivered'); assert.equal(s.store.wakes().length, 0);
453
+ assert.deepEqual(s.alarm(), { at: '2026-10-23T03:30:00.000Z', source: 'plan' });
454
+ s.timers.advance(30 * 60_000); await s.idle();
455
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['plan']); assert.match(textOf(s.requests[0]), /「新的」/);
456
+ });
457
+ test('plan_next without a pending alarm keeps the plain text', async t => {
458
+ let release!: () => void; const gate = new Promise<void>(resolve => { release = resolve; });
459
+ let entered!: () => void; const playing = new Promise<void>(resolve => { entered = resolve; });
460
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('play_game', {}) : textResponse('好'));
461
+ s.ctx.tools.register(testTool('play_game', async () => { entered(); await gate; return 'played'; }));
462
+ await s.life.start(); s.timers.advance(0); await playing; await s.life.settled();
463
+ assert.equal(s.alarm(), undefined);
464
+ assert.equal(s.life.planNext({ after_minutes: 30 }, '看书'), '记下了,到 2026-10-23T12:30:00+09:00 提醒我。');
465
+ release(); await s.idle();
466
+ });
467
+ test('plan_next says what it replaced, and the old note with it', async t => {
468
+ const s = await setup(t, () => textResponse('好'));
469
+ await s.start();
470
+ assert.equal(s.alarm()?.source, 'fallback');
471
+ // The plugin's own fallback is not her plan, so replacing it is not worth mentioning.
472
+ assert.equal(s.life.planNext({ after_minutes: 30 }, ''), '记下了,到 2026-10-23T12:30:00+09:00 提醒我。');
473
+ assert.equal(s.life.planNext({ after_minutes: 20 }, '看下一课'), '记下了,到 2026-10-23T12:20:00+09:00 提醒我。(替换了原来做到 2026-10-23T12:30:00+09:00 的安排。)');
474
+ assert.equal(s.life.planNext({ after_minutes: 10 }, '只列检查'), '记下了,到 2026-10-23T12:10:00+09:00 提醒我。(替换了原来做到 2026-10-23T12:20:00+09:00 的安排:「看下一课」。还想留着里面的事,就写进新的 note。)');
475
+ });
476
+ test('a new alarm clears the retry fault; one that cannot be saved is a fault but still rings', async t => {
477
+ const { held, patch } = holdResolve(2);
478
+ let failWrites = false;
479
+ const s = await setup(t, () => textResponse('嗯'), { host: patch, before: existingHome('旧的'), store: store => ({ ...store, write: state => { if (failWrites) throw new Error('disk full'); store.write(state); } }) });
480
+ await createAgent(s.ctx, 'home-0');
481
+ await s.life.start(); s.timers.advance(0); await held.reached; held.fail!(new Error('home is busy')); await s.life.settled();
482
+ assert.ok(s.faults().some(fault => fault.includes('分钟后重试')));
483
+ s.life.planNext({ after_minutes: 10 }, '再来');
484
+ assert.ok(!s.faults().some(fault => fault.includes('分钟后重试')));
485
+ failWrites = true;
486
+ assert.throws(() => s.life.planNext({ after_minutes: 20 }, '存不下'), /disk full/);
487
+ assert.ok(s.faults().some(fault => fault.startsWith('闹钟没能保存:')));
488
+ s.timers.advance(20 * 60_000); await s.idle();
489
+ assert.match(textOf(s.requests.at(-1)!), /「存不下」/);
490
+ });
491
+ test('an alarm that was steered counts as delivered even when recording it fails', async t => {
492
+ let failing = false;
493
+ const s = await setup(t, () => textResponse('嗯'), { store: store => ({
494
+ ...store,
495
+ write: state => { if (failing) throw new Error('disk full'); store.write(state); },
496
+ appendWake: record => { if (failing) throw new Error('disk full'); store.appendWake(record); },
497
+ }) });
498
+ await s.start();
499
+ failing = true;
500
+ await s.untilMorning();
501
+ assert.equal(s.requests.length, 3);
502
+ assert.ok(s.faults().some(fault => fault.startsWith('生活状态没能保存:')));
503
+ s.timers.advance(60_000); await s.idle(); s.timers.advance(5 * 60_000); await s.idle();
504
+ assert.equal(s.requests.length, 3, 'not retried');
505
+ });
506
+ test('a fallback alarm that cannot be saved becomes a fault instead of breaking the turn', async t => {
507
+ let failWrites = false;
508
+ const s = await setup(t, () => textResponse('嗯'), {
509
+ before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'home-0' })); },
510
+ store: store => ({ ...store, write: state => { if (failWrites) throw new Error('disk full'); store.write(state); } }),
511
+ });
512
+ await createAgent(s.ctx, 'home-0');
513
+ await s.start();
514
+ assert.equal(s.life.snapshot().alarm?.source, 'fallback');
515
+ failWrites = true;
516
+ await s.untilMorning();
517
+ assert.deepEqual(s.errors, []); assert.equal(s.requests.length, 2);
518
+ assert.ok(s.faults().some(fault => fault.startsWith('断线保护闹钟没能保存:')));
519
+ assert.equal(s.life.snapshot().alarm?.source, 'fallback');
520
+ await s.untilMorning();
521
+ assert.equal(s.requests.length, 4);
522
+ assert.match(textOf(s.requests.at(-1)!), /没说接下来做什么/, 'the unsaved fallback still rings in this run');
523
+ });
524
+ test('a failing rename is a fault, and a failing full-access grant retries on the same session', async t => {
525
+ // The rename on creation and the one after the first turn both fail; the next resolve tries again.
526
+ let renameFails = 2; let accessFails = 1;
527
+ const s = await setup(t, () => textResponse('嗯'), { host: host => ({
528
+ ...host,
529
+ setFullAccess: session => { if (accessFails-- > 0) throw new Error('preset refused'); host.setFullAccess(session); },
530
+ rename: async (id, title) => { if (renameFails-- > 0) throw new Error('rename refused'); await host.rename(id, title); },
531
+ }) });
532
+ await s.life.start();
533
+ assert.ok(s.faults().some(fault => fault.startsWith('家打不开:')));
534
+ s.timers.advance(0); await s.idle();
535
+ const home = s.life.snapshot().homeSessionId!;
536
+ assert.equal(s.created(), 1); assert.ok(s.fullAccess.has(home));
537
+ assert.ok(s.faults().some(fault => fault.startsWith('家改名失败:')));
538
+ assert.deepEqual(s.store.wakes().map(wake => wake.source), ['first']);
539
+ await s.untilMorning();
540
+ assert.equal(s.created(), 1); assert.equal(s.renamed.get(home), '鲸鲸的家');
541
+ assert.ok(!s.faults().some(fault => fault.startsWith('家改名失败:')));
542
+ });
543
+ test('a reloaded runtime replaces the old registrations instead of stacking them', async t => {
544
+ const s = await setup(t, () => textResponse('嗯'));
545
+ const chat = await createAgent(s.ctx, 'chat');
546
+ await s.start();
547
+ const second = s.restart(); await second.start();
548
+ await s.untilMorning();
549
+ const home = toolNames(s.requests.at(-1)!);
550
+ assert.equal(count(home, 'plan_next'), 1); assert.equal(count(home, 'reach_out'), 1); assert.equal(count(home, 'read_diary'), 0);
551
+ chat.followup(userMessage('hi')); await chat.whenIdle();
552
+ assert.equal(count(toolNames(s.requests.at(-1)!), 'plan_next'), 1); assert.equal(count(toolNames(s.requests.at(-1)!), 'reach_out'), 0); assert.equal(count(toolNames(s.requests.at(-1)!), 'read_diary'), 0);
553
+ assert.deepEqual(s.errors, []);
554
+ });
555
+ test('stop ends the life line: no delivery after it, and plan_next refuses', async t => {
556
+ const { held, patch } = holdResolve(2);
557
+ const s = await setup(t, () => textResponse('嗯'), { host: patch });
558
+ await s.life.start();
559
+ s.timers.advance(0); await held.reached;
560
+ s.life.stop(); held.release!(); await s.idle();
561
+ assert.equal(s.requests.length, 0); assert.equal(s.store.wakes().length, 0);
562
+ assert.equal(s.store.read().greeting?.kind, 'arrival', 'the undelivered greeting stays saved');
563
+ assert.throws(() => s.life.planNext({ after_minutes: 5 }, '还想'), /生活线已停止/);
564
+ });
565
+ test('a registration failure is a fault and never breaks agent creation', async t => {
566
+ const s = await setup(t, () => textResponse('嗯'), { before: async worldDir => { await writeFile(join(worldDir, 'life.json'), JSON.stringify({ version: 1, homeSessionId: 'clash' })); } });
567
+ s.ctx.on('agent/created', ({ agent }) => { if (agent.id === 'clash') agent.ctx.tools.register(testTool('plan_next', async () => 'x')); return undefined; });
568
+ const clash = await createAgent(s.ctx, 'clash');
569
+ assert.ok(clash);
570
+ await s.start().catch(() => undefined);
571
+ assert.ok(s.faults().some(fault => fault.startsWith('工具挂载失败:')));
572
+ });
573
+ test('home tool calls are logged with the outside-room flag and their outcome', async t => {
574
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('pwsh', { command: 'Start-Process notepad' }) : index === 1 ? toolCall('broken', {}) : textResponse('写好了'));
575
+ s.ctx.tools.register(testTool('pwsh', async () => 'ok'));
576
+ s.ctx.tools.register(testTool('broken', async () => { throw new Error('boom'); }));
577
+ await s.start();
578
+ const [day] = s.store.activityDays();
579
+ assert.deepEqual(s.store.activity(day).map(record => [record.tool, record.summary, record.outside, record.status]), [['pwsh', 'Start-Process notepad', true, 'ok'], ['broken', '{}', false, 'error']]);
580
+ });
581
+ test('compactions in world sessions are recorded for the console', async t => {
582
+ const s = await setup(t, request => request.purpose === 'compaction' ? textResponse('摘要') : textResponse('reply ' + 'detail '.repeat(100)));
583
+ await s.ctx.plugin(TokenMeter).await();
584
+ await s.ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
585
+ await s.start();
586
+ const home = s.ctx.agents.get(SessionId(s.life.snapshot().homeSessionId!))!;
587
+ assert.ok(await s.ctx.compaction.compactNow(home, new AbortController().signal));
588
+ assert.equal(s.store.compactions().length, 1); assert.equal(s.store.compactions()[0].ok, true);
589
+ assert.ok((s.store.compactions()[0].shadowedTokens ?? 0) > 0);
590
+ });
591
+ test('a compaction log that cannot be written is a fault', async t => {
592
+ const s = await setup(t, request => request.purpose === 'compaction' ? textResponse('摘要') : textResponse('reply ' + 'detail '.repeat(100)), { store: store => ({ ...store, appendCompaction: () => { throw new Error('disk full'); } }) });
593
+ await s.ctx.plugin(TokenMeter).await();
594
+ await s.ctx.plugin(ToolFreeCompaction, { auto: false, timeZone: 'UTC', headroomTokens: 0, maxTokens: 128 }).await();
595
+ await s.start();
596
+ const home = s.ctx.agents.get(SessionId(s.life.snapshot().homeSessionId!))!;
597
+ assert.ok(await s.ctx.compaction.compactNow(home, new AbortController().signal));
598
+ assert.ok(s.faults().some(fault => fault.startsWith('压缩记录写入失败:')));
599
+ });
600
+ test('reach_out reaches the outlets with her name, and a failed push there is a fault until one works', async t => {
601
+ const sent: unknown[] = []; let fails = true;
602
+ const s = await setup(t, (_request, index) => index === 0 ? toolCall('reach_out', { text: '想你了' }) : index === 1 ? toolCall('reach_out', { text: '又想你了' }, 'second') : textResponse('嗯'), {
603
+ notifier: { toast: async () => {}, outlets: [{ name: '桌面应用', kinds: ['reach'], send: async push => { sent.push(push); if (fails) { fails = false; throw new Error('connect ECONNREFUSED'); } } }] },
604
+ });
605
+ const faults: string[][] = [];
606
+ s.ctx.on('session/event', (_session, event) => { if (event.type === 'tool/result') faults.push(s.faults()); });
607
+ await s.start();
608
+ assert.deepEqual(sent, [{ text: '想你了', kind: 'reach', name: '鲸鲸' }, { text: '又想你了', kind: 'reach', name: '鲸鲸' }]);
609
+ assert.deepEqual(faults[0], ['桌面应用没送到:connect ECONNREFUSED']);
610
+ assert.ok(!s.faults().some(fault => fault.startsWith('桌面应用')), 'cleared by the next push that works');
611
+ });
612
+ test('home() opens the same home the alarm uses', async t => {
613
+ const s = await setup(t, () => textResponse('嗯'));
614
+ await s.start();
615
+ assert.equal((await s.life.home()).id, s.life.snapshot().homeSessionId);
616
+ assert.equal(s.created(), 1);
617
+ });
618
+ test('check_alarm tells her what is next; cancel_alarm puts her own alarm back to the morning fallback', async t => {
619
+ const s = await setup(t, () => textResponse('嗯'));
620
+ await s.start();
621
+ assert.ok(['check_alarm', 'cancel_alarm'].every(name => toolNames(s.requests[0]!).includes(name)));
622
+ assert.equal(s.life.checkAlarm(), '我现在没有自己定的闹钟。下一次会在 2026-10-24T09:00:00+09:00(还有 21 小时)按平常的时间叫我。');
623
+ s.life.planNext({ after_minutes: 90 }, '看 B 站');
624
+ assert.equal(s.life.checkAlarm(), '我说好做「看 B 站」做到 2026-10-23T13:30:00+09:00(还有 1 小时 30 分)。');
625
+ assert.equal(s.life.cancelAlarm(), '取消了做到 2026-10-23T13:30:00+09:00 的安排:「看 B 站」。不另定的话,我就休息到 2026-10-24T09:00:00+09:00。');
626
+ assert.deepEqual(s.alarm(), { at: '2026-10-24T00:00:00.000Z', source: 'fallback' });
627
+ assert.equal(s.life.cancelAlarm(), '现在没有我自己定的闹钟,不用取消。下一次会在 2026-10-24T09:00:00+09:00 按平常的时间叫我。');
628
+ assert.deepEqual(s.alarm(), { at: '2026-10-24T00:00:00.000Z', source: 'fallback' });
629
+ });
630
+ test('a world alarm.md shapes the wake messages and the tool descriptions; an unreadable one is a fault and the shipped wording is used', async t => {
631
+ const s = await setup(t, () => textResponse('嗯'), { before: dir => writeFile(join(dir, 'alarm.md'), '## 第一次到家\n你好呀{{name}},{{partner}}给你搭了个家。\n## plan_next 说明\n自己定的说明,例如 {{example}}\n') });
632
+ await s.start();
633
+ assert.match(textOf(s.requests[0]!), /【我的时间】你好呀鲸鲸,伙伴给你搭了个家。\n接下来想做什么,用 plan_next 说好做到几点/);
634
+ assert.equal(s.requests[0]!.tools?.find(tool => tool.name === 'plan_next')?.description, '自己定的说明,例如 2026-10-23T21:00:00+09:00');
635
+ assert.ok(!s.faults().some(fault => fault.includes('闹钟模板')));
636
+
637
+ const broken = await setup(t, () => textResponse('嗯'), { before: dir => mkdir(join(dir, 'alarm.md')) });
638
+ await broken.start();
639
+ assert.match(textOf(broken.requests[0]!), /【我的时间】这是我的家。/);
640
+ assert.ok(broken.faults().some(fault => /闹钟模板 .* 读不了,先用默认的/.test(fault)), broken.faults().join('|'));
641
+ });
642
+ test('an alarm set from a chat session rings at home, not in the chat', async t => {
643
+ const sessionOf = (request: GenerateOptions) => (request as { sessionId?: string }).sessionId;
644
+ let asked = false;
645
+ const s = await setup(t, request => {
646
+ if (sessionOf(request) === 'chat' && !asked) { asked = true; return toolCall('plan_next', { after_minutes: 30, note: '提醒伙伴喝水' }); }
647
+ return textResponse('嗯');
648
+ });
649
+ await s.start();
650
+ const chat = await createAgent(s.ctx, 'chat');
651
+ chat.followup(userMessage('半小时后提醒我喝水')); await chat.whenIdle();
652
+ assert.equal(s.alarm()?.source, 'plan');
653
+ const before = s.requests.length;
654
+ s.timers.advance(30 * 60_000); await s.idle();
655
+ const home = s.life.snapshot().homeSessionId!;
656
+ const rung = s.requests.slice(before).filter(request => sessionOf(request) === home);
657
+ assert.equal(rung.length, 1);
658
+ assert.match(textOf(rung[0]!), /【我的时间】[^ ]+ 到了,这是我说好做到的时间:「提醒伙伴喝水」/);
659
+ assert.ok(!s.requests.slice(before).some(request => sessionOf(request) === 'chat'));
660
+ });