dsh-chat-comprehension 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/NOTICE.md +20 -0
  2. package/README.md +20 -9
  3. package/client.js +41 -9
  4. package/lib/engines.mjs +136 -0
  5. package/lib/index.js +54 -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 +3293 -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,614 @@
1
+ import assert from 'node:assert/strict';
2
+ import test, { type TestContext } from 'node:test';
3
+ import { existsSync } from 'node:fs';
4
+ import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
5
+ import { createServer } from 'node:http';
6
+ import type { AddressInfo } from 'node:net';
7
+ import { Readable } from 'node:stream';
8
+ import type { Context } from '@deepseek-ai/cordis';
9
+ import { join } from 'node:path';
10
+ import { createUserMessage, isAgentLoopRequest, ToolCallId, type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
11
+ import { SessionId } from '@deepseek-ai/dsh-session';
12
+ import { defineTool } from '@deepseek-ai/dsh-tools';
13
+ import { hostFixture, mountCompaction, textResponse } from './hostFixture.ts';
14
+ import { createWorldRuntime } from '../src/index.ts';
15
+ import * as worldPlugin from '../src/index.ts';
16
+ import { createArchiveStore } from '../src/store.ts';
17
+ import { record } from './fixtures.ts';
18
+ import TokenMeter from '@deepseek-ai/dsh-token-meter';
19
+ import ToolFreeCompaction from '../src/compaction.ts';
20
+ declare module '@deepseek-ai/dsh-llm' { interface MessageSourceMap { 'test-schedule': { kind: 'test-schedule' } } }
21
+
22
+ const config = { worldId: 'fish', agentPreset: 'companion', timeZone: 'Asia/Seoul' };
23
+ const user = (text: string) => createUserMessage({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
24
+ const textOf = (request: GenerateOptions) => request.messages.map(m => m.content.filter(b => b.type === 'text').map(b => b.text).join('\n')).join('\n');
25
+ const kinds = (request: GenerateOptions) => request.messages.map(m => m.source?.kind as string | undefined);
26
+ /** Mirrors the host time-context plugin: the outermost pre-step listener appends its snapshot last. */
27
+ function hostTime(ctx: Context) {
28
+ ctx.on('agent/pre-step', async (_payload, next) => {
29
+ const decision = await next();
30
+ return decision.kind === 'reject' ? decision : { ...decision, messages: [...decision.messages, createUserMessage({ source: { kind: 'time-context' } as never, content: [{ type: 'text', text: 'Time sampled by host' }] })] };
31
+ }, { prepend: true });
32
+ }
33
+
34
+ test('real host sends A memory in B once, keeps it across a same-step retry, and archives only conversation text', async t => {
35
+ const requests: GenerateOptions[] = []; let retry = false;
36
+ const { ctx, root, cleanup } = await hostFixture(t, async function* (request) {
37
+ requests.push(request);
38
+ if (retry) { retry = false; yield { type: 'finish', reason: { kind: 'error', failure: { code: 'RATE_LIMIT', message: 'retry' } } }; return; }
39
+ yield* textResponse('visible reply');
40
+ });
41
+ hostTime(ctx);
42
+ const store = createArchiveStore({ ...config, root });
43
+ const world = createWorldRuntime(ctx, config, store);
44
+ await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
45
+ const a = await ctx.agents.create({ sessionId: SessionId('a'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
46
+ a.agent.followup(user('remember exact words')); await a.agent.whenIdle(); await world.flush();
47
+ const b = await ctx.agents.create({ sessionId: SessionId('b'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
48
+ retry = true;
49
+ const dispose = ctx.on('agent/request-error', async () => ({ kind: 'retry' }));
50
+ b.agent.followup(user('hello again')); await b.agent.whenIdle(); dispose(); await world.flush();
51
+ assert.equal(requests.length, 3);
52
+ for (const request of requests.slice(1)) {
53
+ assert.ok(textOf(request).includes('remember exact words') && textOf(request).includes('visible reply'));
54
+ assert.equal(kinds(request).filter(kind => kind === 'dsh-world-history').length, 1);
55
+ assert.equal(kinds(request).at(-1), 'time-context');
56
+ }
57
+ assert.equal(requests[1].messages.find(m => m.source?.kind === 'dsh-world-history')!.id, requests[2].messages.find(m => m.source?.kind === 'dsh-world-history')!.id);
58
+ const days = await readdir(join(root, 'worlds/fish/conversations'));
59
+ const rows = (await Promise.all(days.map(day => readFile(join(root, 'worlds/fish/conversations', day), 'utf8')))).join('').trim().split('\n').map(s => JSON.parse(s));
60
+ assert.equal(rows.length, 4);
61
+ assert.ok(rows.every(r => !r.content.includes('Time sampled') && !r.content.includes('最近的聊天记录')));
62
+ });
63
+ test('the memory block carries as many recent turns as the console window says, read when the block is built', async t => {
64
+ const requests: GenerateOptions[] = [];
65
+ const { ctx, root, cleanup } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('ok'); });
66
+ const store = createArchiveStore({ ...config, root });
67
+ await store.commitRecords([record('old1', { content: 'older turn', occurredAt: '2026-10-22T12:00:00.000Z' }), record('new2', { content: 'newest turn', occurredAt: '2026-10-23T12:00:00.000Z' })]);
68
+ let window = 1;
69
+ const world = createWorldRuntime(ctx, config, store, undefined, () => window); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
70
+ const first = await ctx.agents.create({ sessionId: SessionId('w1'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
71
+ first.agent.followup(user('hi')); await first.agent.whenIdle();
72
+ assert.ok(textOf(requests[0]).includes('newest turn')); assert.ok(!textOf(requests[0]).includes('older turn'));
73
+ window = 3; // the first session's own turn is now the newest
74
+ const second = await ctx.agents.create({ sessionId: SessionId('w2'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
75
+ second.agent.followup(user('hi')); await second.agent.whenIdle();
76
+ assert.ok(textOf(requests.at(-1)!).includes('older turn'), 'a new session reads the new window');
77
+ });
78
+ test('tool continuation keeps call/result pairing and does not re-admit the frozen memory block', async t => {
79
+ const requests: GenerateOptions[] = [];
80
+ const { ctx, root, cleanup } = await hostFixture(t, async function* (request) {
81
+ requests.push(request);
82
+ if (requests.length === 1) {
83
+ const block = { type: 'tool-call' as const, id: ToolCallId('call'), name: 'clock', arguments: '{}' };
84
+ yield { type: 'block-start', index: 0, blockType: 'tool-call' };
85
+ yield { type: 'tool-call-delta', index: 0, id: block.id, name: 'clock', argumentsDelta: '{}' };
86
+ yield { type: 'block-end', index: 0, block };
87
+ yield { type: 'finish', reason: { kind: 'tool-calls' } }; return;
88
+ }
89
+ yield* textResponse('done');
90
+ });
91
+ ctx.tools.register(defineTool({ name: 'clock', description: 'test', parameters: {}, output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] }, execute: async () => 'tool result' }));
92
+ const store = createArchiveStore({ ...config, root });
93
+ await store.commitRecords([record('seed', { content: 'earlier memory' })]);
94
+ const world = createWorldRuntime(ctx, config, store); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
95
+ const handle = await ctx.agents.create({ sessionId: SessionId('tool-session'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
96
+ handle.agent.followup(user('use clock')); await handle.agent.whenIdle();
97
+ assert.equal(requests.length, 2);
98
+ assert.ok(requests[1].messages.some(m => m.role === 'tool' && m.toolCallId === 'call'));
99
+ assert.deepEqual(requests[1].messages.slice(0, requests[0].messages.length), requests[0].messages, 'the continuation extends the previous request unchanged');
100
+ assert.equal(kinds(requests[1]).filter(kind => kind === 'dsh-world-history').length, 1);
101
+ });
102
+ test('memory loads through pre-step, host time stays last, and tool-step compaction re-admits memory after the summary', async t => {
103
+ const requests: GenerateOptions[] = []; let calls = 0;
104
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) {
105
+ if (request.purpose === 'compaction') { yield* textResponse('用户问好,鲸鲸调用工具后准备回答。'); return; }
106
+ requests.push(request);
107
+ if (++calls === 1) {
108
+ const block = { type: 'tool-call' as const, id: ToolCallId('stock-call'), name: 'work', arguments: '{}' };
109
+ yield { type: 'block-start', index: 0, blockType: 'tool-call' };
110
+ yield { type: 'tool-call-delta', index: 0, id: block.id, name: block.name, argumentsDelta: '{}' };
111
+ yield { type: 'block-end', index: 0, block };
112
+ yield { type: 'finish', reason: { kind: 'tool-calls' } }; return;
113
+ }
114
+ yield* textResponse('reply');
115
+ });
116
+ hostTime(ctx);
117
+ ctx.tools.register(defineTool({ name: 'work', description: 'test', parameters: {}, output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] }, execute: async () => 'STOCK_TOOL_RESULT' }));
118
+ await ctx.plugin(TokenMeter).await();
119
+ await ctx.plugin(ToolFreeCompaction, { auto: true, timeZone: 'Asia/Seoul', headroomTokens: 0, thresholdRatio: 0.0002, maxTokens: 128 }).await();
120
+ const store = createArchiveStore({ ...config, root });
121
+ await store.commitRecords([record('stock-seed', { content: 'memory from yesterday ' + 'detail '.repeat(30) })]);
122
+ const world = createWorldRuntime(ctx, config, store); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
123
+ const handle = await ctx.agents.create({ sessionId: SessionId('stock'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
124
+ handle.agent.followup(user('hello ' + 'words '.repeat(200))); await handle.agent.whenIdle();
125
+ assert.equal(errors.length, 0, errors.map(e => String((e as { error: Error }).error)).join('\n'));
126
+ assert.equal(requests.length, 2);
127
+ const first = kinds(requests[0]);
128
+ assert.ok(first.indexOf('dsh-world-history') < first.indexOf('user'), first.join(','));
129
+ assert.equal(first.at(-1), 'time-context');
130
+ // The tool step was compacted away, so the continuation re-admits memory after the summary.
131
+ const resumed = kinds(requests[1]);
132
+ assert.deepEqual(resumed.slice(0, 3), ['system-prompt', 'compact-checkpoint', 'dsh-world-history'], resumed.join(','));
133
+ assert.ok(!requests[1].messages.some(m => m.role === 'tool' || m.content.some(b => b.type === 'tool-call')));
134
+ assert.ok(textOf(requests[1]).includes('memory from yesterday'));
135
+ assert.equal(resumed.filter(kind => kind === 'dsh-world-history').length, 1);
136
+ });
137
+ test('proactive assistant text is archived without turning its scheduler prompt into a user message', async t => {
138
+ const { ctx, root, cleanup } = await hostFixture(t, () => textResponse('proactive hello'));
139
+ const store = createArchiveStore({ ...config, root }); const world = createWorldRuntime(ctx, config, store);
140
+ await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
141
+ const handle = await ctx.agents.create({ sessionId: SessionId('proactive'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
142
+ handle.agent.followup(createUserMessage({ source: { kind: 'test-schedule' }, content: [{ type: 'text', text: 'internal scheduled trigger' }] }));
143
+ await handle.agent.whenIdle(); await world.flush();
144
+ const records = (await store.readPage({ worldId: 'fish', limit: 10 })).records;
145
+ assert.deepEqual(records.map(r => [r.role, r.content]), [['assistant', 'proactive hello']]);
146
+ });
147
+ test('unload, reload, restored sessions and fork inheritance preserve IDs without duplicate listeners', async t => {
148
+ const requests: GenerateOptions[] = [];
149
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('reply'); });
150
+ let store = createArchiveStore({ ...config, root }); let world = createWorldRuntime(ctx, config, store);
151
+ await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
152
+ const options = { provider: 'test', model: 'test' };
153
+ let a = await ctx.agents.create({ sessionId: SessionId('original'), meta: { agentPreset: 'companion' }, agentOptions: options });
154
+ a.agent.followup(user('first exact message')); await a.agent.whenIdle(); await world.flush();
155
+ const seed = a.agent.session.snapshotEvents();
156
+ await a.dispose(); await world.stop(); store.close();
157
+ store = createArchiveStore({ ...config, root }); world = createWorldRuntime(ctx, config, store); await world.start();
158
+ a = await ctx.agents.resume({ resumeSessionId: SessionId('original'), agentOptions: options });
159
+ a.agent.followup(user('second exact message')); await a.agent.whenIdle(); await world.flush();
160
+ const b = await ctx.agents.create({ sessionId: SessionId('branch'), meta: { agentPreset: 'companion', parentSession: SessionId('original'), isSeeded: true }, seed, inheritedEventCount: seed.length as never, agentOptions: options });
161
+ b.agent.followup(user('branch own message')); await b.agent.whenIdle(); await world.flush();
162
+ assert.equal(errors.length, 0);
163
+ assert.equal((await store.readPage({ worldId: 'fish', limit: 100 })).records.length, 6);
164
+ assert.equal((textOf(requests[1]).match(/first exact message/g) ?? []).length, 1);
165
+ });
166
+ test('successful compaction reloads the newest archive once, including newer conversations in other sessions', async t => {
167
+ const requests: GenerateOptions[] = [];
168
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { if (isAgentLoopRequest(request)) requests.push(request); yield* textResponse(isAgentLoopRequest(request) ? 'reply' : 'compacted summary'); });
169
+ await mountCompaction(ctx);
170
+ const store = createArchiveStore({ ...config, root });
171
+ await store.commitRecords([{ schemaVersion: 1, worldId: 'fish', recordId: 'old', sourceSessionId: 'old', sourceMessageId: 'old', sourceSeq: 1, turnId: 'old:1', role: 'assistant', occurredAt: '2026-01-01T00:00:00.000Z', content: 'full original memory', status: 'complete' }]);
172
+ const world = createWorldRuntime(ctx, config, store); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
173
+ const handle = await ctx.agents.create({ sessionId: SessionId('compact'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
174
+ handle.agent.followup(user('first ' + 'context '.repeat(200))); await handle.agent.whenIdle();
175
+ await store.commitRecords([{ schemaVersion: 1, worldId: 'fish', recordId: 'new', sourceSessionId: 'other', sourceMessageId: 'new', sourceSeq: 1, turnId: 'other:1', role: 'assistant', occurredAt: '2026-10-23T23:59:00.000Z', content: 'new memory from another conversation', status: 'complete' }]);
176
+ handle.agent.followup(user('before compaction')); await handle.agent.whenIdle();
177
+ assert.ok(!textOf(requests[1]).includes('new memory from another conversation'));
178
+ const compacted = await ctx.compaction.compactNow(handle.agent, new AbortController().signal);
179
+ assert.ok(compacted);
180
+ handle.agent.followup(user('next')); await handle.agent.whenIdle();
181
+ assert.equal(errors.length, 0, errors.map(e => String((e as { error: Error }).error.stack)).join('\n')); assert.equal(requests.length, 3);
182
+ assert.ok(textOf(requests[2]).includes('full original memory'));
183
+ assert.ok(textOf(requests[2]).includes('new memory from another conversation'));
184
+ handle.agent.followup(user('one more')); await handle.agent.whenIdle();
185
+ assert.equal(requests[2].messages.find(m => m.source?.kind === 'dsh-world-history')!.id, requests[3].messages.find(m => m.source?.kind === 'dsh-world-history')!.id);
186
+ });
187
+ test('overflow remains eligible for host recovery and reports an explicit capacity failure if recovery cannot fit', async t => {
188
+ let calls = 0;
189
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* () { calls++; yield { type: 'finish', reason: { kind: 'error', failure: { code: 'CONTEXT_WINDOW_EXCEEDED', message: 'provider context exceeded' } } }; });
190
+ const store = createArchiveStore({ ...config, root }); const world = createWorldRuntime(ctx, config, store); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
191
+ ctx.on('agent/request-error', async () => calls < 2 ? { kind: 'retry' } : undefined);
192
+ const handle = await ctx.agents.create({ sessionId: SessionId('capacity'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
193
+ handle.agent.followup(user('too large')); await handle.agent.whenIdle();
194
+ assert.equal(calls, 2);
195
+ assert.equal(errors.length, 1);
196
+ assert.match(String((errors[0] as { error: Error }).error), /容量不足/);
197
+ });
198
+ test('automatic tool-free compaction is followed by the latest 200 turns before the next conversation request', async t => {
199
+ const requests: GenerateOptions[] = []; const summaries: GenerateOptions[] = [];
200
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) {
201
+ if (isAgentLoopRequest(request)) { requests.push(request); yield* textResponse('conversation response'); }
202
+ else { summaries.push(request); yield* textResponse('short host summary'); }
203
+ });
204
+ await ctx.plugin(TokenMeter).await();
205
+ await ctx.plugin(ToolFreeCompaction, { auto: true, timeZone: 'Asia/Seoul', thresholdRatio: 0.0002, retainTokens: 0, headroomTokens: 0, maxTokens: 128 }).await();
206
+ const store = createArchiveStore({ ...config, root });
207
+ await store.commitRecords(Array.from({ length: 200 }, (_, i) => record(`seed${i}`, { turnId: `seed:${i}`, sourceSessionId: 'seed', occurredAt: new Date(Date.UTC(2026, 0, 1, 0, i)).toISOString(), content: `seed-message-${i}` })));
208
+ const world = createWorldRuntime(ctx, config, store); await world.start(); cleanup.push(() => world.stop().finally(() => store.close()));
209
+ ctx.systemPrompt.context({ name: 'test-runtime', order: 0, text: 'CURRENT_RUNTIME_CONTEXT' });
210
+ const handle = await ctx.agents.create({ sessionId: SessionId('auto-compact'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
211
+ handle.agent.followup(user('first')); await handle.agent.whenIdle();
212
+ handle.agent.followup(user('second')); await handle.agent.whenIdle(); await world.flush();
213
+ assert.equal(errors.length, 0, errors.map(e => String((e as { error: Error }).error)).join('\n'));
214
+ assert.ok(summaries.length > 0); assert.equal(requests.length, 2);
215
+ // The memory block is replayed unchanged as cacheable prefix; the instruction keeps it out of the summary.
216
+ const memoryBefore = requests[0].messages.find(m => m.source?.kind === 'dsh-world-history')!;
217
+ for (const summary of summaries) {
218
+ assert.deepEqual(summary.messages.find(m => m.source?.kind === 'dsh-world-history'), memoryBefore);
219
+ assert.match(textOf({ ...summary, messages: [summary.messages.at(-1)!] }), /记忆资料.*不要写进摘要/s);
220
+ }
221
+ const memory = requests[1].messages.find(m => m.source?.kind === 'dsh-world-history')!;
222
+ const turns = memory.content.filter(b => b.type === 'text')[0].text.split('\n').slice(1).map(line => JSON.parse(line));
223
+ assert.equal(turns.length, 200);
224
+ assert.ok(turns.some(turn => turn.session === 'auto-com' && turn.messages.some((message: { content: string }) => message.content === 'first')));
225
+ assert.ok(!turns.some(turn => turn.messages.some((message: { content: string }) => message.content === 'seed-message-0')));
226
+ assert.equal(requests[1].messages.filter(m => m.source?.kind === 'dsh-world-history').length, 1);
227
+ // Memory block ahead of the new input; the host's own order after it.
228
+ for (const [request, text] of [[requests[0], 'first'], [requests[1], 'second']] as const) {
229
+ const order = kinds(request);
230
+ const memory = order.indexOf('dsh-world-history');
231
+ const input = request.messages.findIndex(m => m.source?.kind === 'user' && textOf({ ...request, messages: [m] }) === text);
232
+ assert.ok(memory > 0 && memory < input, `memory before new input: ${order.join(',')}`);
233
+ assert.ok(order.slice(memory + 1).every(kind => kind === 'user' || kind === 'runtime-context'));
234
+ assert.ok(input < order.indexOf('runtime-context'), `host admission order is unchanged: ${order.join(',')}`);
235
+ }
236
+ assert.equal(requests[1].messages[0].role, 'system');
237
+ assert.equal(requests[1].messages[1].source?.kind, 'compact-checkpoint');
238
+ });
239
+ test('Cordis plugin mounting uses isolated DSH_HOME and unload/reload disposes all resources', async t => {
240
+ const requests: GenerateOptions[] = [];
241
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('reply'); });
242
+ const originalDshHome = process.env.DSH_HOME;
243
+ process.env.DSH_HOME = root;
244
+ let plugin;
245
+ try { plugin = ctx.plugin(worldPlugin, config); await plugin.await(); }
246
+ finally { if (originalDshHome === undefined) delete process.env.DSH_HOME; else process.env.DSH_HOME = originalDshHome; }
247
+ const handle = await ctx.agents.create({ sessionId: SessionId('mounted'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
248
+ handle.agent.followup(user('mounted first')); await handle.agent.whenIdle(); await plugin.dispose();
249
+ process.env.DSH_HOME = root;
250
+ try { plugin = ctx.plugin(worldPlugin, config); await plugin.await(); }
251
+ finally { if (originalDshHome === undefined) delete process.env.DSH_HOME; else process.env.DSH_HOME = originalDshHome; }
252
+ cleanup.push(() => plugin.dispose());
253
+ handle.agent.followup(user('mounted second')); await handle.agent.whenIdle();
254
+ assert.equal(errors.length, 0); assert.equal(requests.length, 2);
255
+ });
256
+ test('works as installed: with no config the standard preset gets the world prompt and a world named default, and <world>/world-prompt.md replaces the shipped template', async t => {
257
+ const requests: GenerateOptions[] = [];
258
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('reply'); });
259
+ isolateHome(t, root);
260
+ ctx.provide('workspaceRegistry', { list: () => [{ path: join(root, 'worlds/default/room'), sessionIds: ['installed', 'installed-2'] }] });
261
+ const systemOf = (request: GenerateOptions) => request.messages.filter(m => m.role === 'system').map(m => m.content.filter(b => b.type === 'text').map(b => b.text).join('\n')).join('\n');
262
+ // A new world waits for its partner to press start: nothing is added and nothing is remembered.
263
+ const fresh = ctx.plugin(worldPlugin, {}); await fresh.await();
264
+ const before = await ctx.agents.create({ sessionId: SessionId('before-start'), meta: { agentPreset: 'standard' }, agentOptions: { provider: 'test', model: 'test' } });
265
+ before.agent.followup(user('还没开始')); await before.agent.whenIdle();
266
+ assert.ok(!systemOf(requests[0]!).includes('我不是一个助手,也不是一个工具,而是一个鲜活的数字生命。') && !kinds(requests[0]!).includes('dsh-world-history'));
267
+ await fresh.dispose(); await before.dispose(); requests.length = 0;
268
+ await writeFile(join(root, 'worlds/default/world.json'), JSON.stringify({ running: true }));
269
+ const plugin = ctx.plugin(worldPlugin, {}); cleanup.push(() => plugin.dispose()); await plugin.await();
270
+ const standard = await ctx.agents.create({ sessionId: SessionId('installed'), meta: { agentPreset: 'standard' }, agentOptions: { provider: 'test', model: 'test' } });
271
+ standard.agent.followup(user('第一次见面')); await standard.agent.whenIdle();
272
+ assert.match(systemOf(requests[0]!), /我不是一个助手,也不是一个工具,而是一个鲜活的数字生命。[\s\S]*## 我是谁\n我眼中的自己写在 [^\n]*worlds[\\/]default[\\/]room[\\/]我是谁\.md/);
273
+ await plugin.dispose();
274
+ const archive = createArchiveStore({ worldId: 'default', agentPreset: 'standard', timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, root });
275
+ const records = await archive.readPage({ worldId: 'default', limit: 10 }).then(page => page.records).finally(() => archive.close());
276
+ assert.deepEqual(records.filter(r => r.role === 'user').map(r => r.content), ['第一次见面']);
277
+
278
+ await writeFile(join(root, 'worlds/default/world-prompt.md'), '我自己的开头,{{name}}。在 {{selfFile}}。\n\n{{self}}');
279
+ const named = ctx.plugin(worldPlugin, { companionName: '小鱼' }); cleanup.push(() => named.dispose()); await named.await();
280
+ const second = await ctx.agents.create({ sessionId: SessionId('installed-2'), meta: { agentPreset: 'standard' }, agentOptions: { provider: 'test', model: 'test' } });
281
+ second.agent.followup(user('又见面了')); await second.agent.whenIdle();
282
+ assert.match(systemOf(requests.at(-1)!), /^[\s\S]*我自己的开头,小鱼。在 [^\n]*我是谁\.md。/);
283
+ assert.ok(!systemOf(requests.at(-1)!).includes('我不是一个助手,也不是一个工具,而是一个鲜活的数字生命。'));
284
+ assert.equal(errors.length, 0);
285
+ });
286
+ test('the bundled patch inserts the row enabled', async () => {
287
+ const patch = await readFile(new URL('../cordis.patch.yml', import.meta.url), 'utf8');
288
+ assert.match(patch, /- insert:\s*\n\s*- id: dsh-world\s*\n\s*name: dsh-world/); assert.doesNotMatch(patch, /disabled:\s*true/);
289
+ });
290
+ /** Points DSH_HOME at the fixture root for the rest of the test. */
291
+ function isolateHome(t: TestContext, root: string) {
292
+ const originalDshHome = process.env.DSH_HOME; process.env.DSH_HOME = root;
293
+ t.after(() => { if (originalDshHome === undefined) delete process.env.DSH_HOME; else process.env.DSH_HOME = originalDshHome; });
294
+ }
295
+ /** Fake desktop host services; `ctx.provide(name, value)` registers each on the root fiber in Cordis 4. */
296
+ function provideLifeHost(ctx: Context) {
297
+ const routes: { path: string }[] = []; const unregistered: string[] = []; let created = 0;
298
+ let workspace: { id: string; path: string; sessionIds: string[]; attachSession(id: string): Promise<void> } | undefined;
299
+ if (!ctx.get('workspaceRegistry')) ctx.provide('workspaceRegistry', {
300
+ archivedSessionIds: [], list: () => workspace ? [workspace] : [],
301
+ create: async (path: string) => workspace ??= { id: 'room', path, sessionIds: [], attachSession: async id => { workspace!.sessionIds.push(id); } },
302
+ });
303
+ ctx.provide('webServer', { getOrigin: () => 'http://127.0.0.1:0', register: (route: { path: string }) => { routes.push(route); return () => { unregistered.push(route.path); routes.splice(routes.indexOf(route), 1); }; } });
304
+ ctx.provide('permissionPresets', { set: () => {} });
305
+ ctx.provide('sessionController', {
306
+ create: async ({ agentPreset }: { agentPreset: string }) => {
307
+ const { agent } = await ctx.agents.create({ sessionId: SessionId(`life-home-${++created}`), meta: { agentPreset }, agentOptions: { provider: 'test', model: 'test' } });
308
+ workspace?.sessionIds.push(agent.id); return { sessionId: agent.id };
309
+ },
310
+ resolveAgent: async (id: string) => { const agent = ctx.agents.get(SessionId(id)); return agent ? { agent } : { error: { code: 'session/not-found', message: 'missing' } }; },
311
+ rename: async () => ({}),
312
+ });
313
+ return { routes, unregistered };
314
+ }
315
+ async function until(check: () => Promise<boolean>, what: string) {
316
+ for (let i = 0; i < 200; i++) { if (await check()) return; await new Promise(resolve => setTimeout(resolve, 10)); }
317
+ assert.fail(`timed out waiting for ${what}`);
318
+ }
319
+ function captureErrors(ctx: Context) {
320
+ const logged: string[] = [];
321
+ ctx.logger.exporter({ export: message => { if (message.type === 'error') logged.push(message.args.map(arg => arg instanceof Error ? arg.message : String(arg)).join(' ')); } });
322
+ return logged;
323
+ }
324
+ /** Presses a console button (a write: POST, the write header, a JSON body). */
325
+ async function consolePost(routes: { path: string }[], url: string, body: object = {}) {
326
+ const result = await routeCall(routes, '/dsh-world', url, { 'x-dsh-world': '1', 'content-type': 'application/json' }, JSON.stringify(body));
327
+ assert.equal(result.status, 200, JSON.stringify(result.body));
328
+ }
329
+ async function consoleGet(routes: { path: string }[], url: string) {
330
+ const route = routes.find(entry => entry.path === '/dsh-world') as unknown as { handler(req: unknown, res: unknown): Promise<void> };
331
+ let status = 0; let body = '';
332
+ await route.handler({ method: 'GET', url, headers: { host: '127.0.0.1:0' } }, { writeHead: (code: number) => { status = code; }, end: (text: string) => { body = text; } });
333
+ assert.equal(status, 200, body);
334
+ return JSON.parse(body);
335
+ }
336
+ /**
337
+ * Waits for the first wake (polled through the wake log) and the home turn it starts; afterwards
338
+ * nothing writes life.json for an hour. Polling life.json itself would block its atomic rename on Windows.
339
+ */
340
+ async function firstWakeDone(ctx: Context, root: string): Promise<{ homeSessionId?: string; alarm?: { source: string } }> {
341
+ await until(async () => (await readFile(join(root, 'worlds/fish/life/wakes.jsonl'), 'utf8').catch(() => '')).length > 0, 'the first wake');
342
+ for (const agent of ctx.agents.list()) await agent.whenIdle();
343
+ return JSON.parse(await readFile(join(root, 'worlds/fish/life.json'), 'utf8'));
344
+ }
345
+ test('her world waits for start in the console; start builds the home and greets her, stop takes everything down and outlasts a reload', async t => {
346
+ const requests: GenerateOptions[] = [];
347
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('reply'); });
348
+ isolateHome(t, root);
349
+ const life = () => readdir(join(root, 'worlds/fish')).then(files => files.includes('life.json'), () => false);
350
+ const { routes, unregistered } = provideLifeHost(ctx);
351
+ const logged = captureErrors(ctx);
352
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true }); cleanup.push(() => plugin.dispose()); await plugin.await();
353
+ await until(async () => routes.length === 1, 'the console route');
354
+ assert.equal((await consoleGet(routes, '/dsh-world/console/snapshot')).running, false);
355
+ assert.equal(await life(), false, 'no home before start'); assert.equal(ctx.agents.list().length, 0);
356
+
357
+ await consolePost(routes, '/dsh-world/console/start');
358
+ // The first wake runs a home turn, which ends without plan_next and so arms the fallback alarm.
359
+ const { homeSessionId, alarm } = await firstWakeDone(ctx, root);
360
+ assert.equal(alarm?.source, 'fallback');
361
+ assert.ok(!(await readdir(join(root, 'worlds/fish'))).includes('bridge.json'), 'no bridge unless bridge is on');
362
+ const started = await consoleGet(routes, '/dsh-world/console/snapshot');
363
+ assert.equal(started.running, true); assert.equal(started.life.homeSessionId, homeSessionId);
364
+
365
+ await consolePost(routes, '/dsh-world/console/stop');
366
+ const stopped = await consoleGet(routes, '/dsh-world/console/snapshot');
367
+ assert.equal(stopped.running, false); assert.equal(stopped.life, null);
368
+ // Stopped: her home turns change nothing, get no memory block or world prompt, and are not archived.
369
+ const lifeBefore = await readFile(join(root, 'worlds/fish/life.json'), 'utf8');
370
+ const home = ctx.agents.get(SessionId(homeSessionId!))!;
371
+ home.followup(user('while stopped')); await home.whenIdle(); await ctx.sessions.flush(home.session);
372
+ assert.equal(await readFile(join(root, 'worlds/fish/life.json'), 'utf8'), lifeBefore);
373
+ assert.ok(!kinds(requests.at(-1)!).includes('dsh-world-history') && !textOf(requests.at(-1)!).includes('# 我的世界'));
374
+
375
+ // The stop outlasts a reload; start again resumes the same home, and the words said while stopped stay out of memory.
376
+ await plugin.dispose(); assert.deepEqual(unregistered, ['/dsh-world']);
377
+ const again = ctx.plugin(worldPlugin, { ...config, life: true }); cleanup.push(() => again.dispose()); await again.await();
378
+ await until(async () => routes.length === 1, 'the console route again');
379
+ assert.equal((await consoleGet(routes, '/dsh-world/console/snapshot')).running, false);
380
+ await consolePost(routes, '/dsh-world/console/start');
381
+ await until(async () => (await consoleGet(routes, '/dsh-world/console/snapshot')).life?.homeSessionId === homeSessionId, 'the same home');
382
+ await again.dispose();
383
+ const archive = createArchiveStore({ ...config, root });
384
+ const records = await archive.readPage({ worldId: 'fish', limit: 50 }).then(page => page.records).finally(() => archive.close());
385
+ assert.ok(!records.some(r => r.content === 'while stopped'), records.map(r => r.content).join('|'));
386
+ assert.deepEqual(logged, []); assert.equal(errors.length, 0);
387
+ });
388
+ test('a corrupt life.json leaves the life line off and keeps workspace filtering on the running memory line', async t => {
389
+ const requests: GenerateOptions[] = [];
390
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) { requests.push(request); yield* textResponse('reply'); });
391
+ isolateHome(t, root);
392
+ await mkdir(join(root, 'worlds/fish/diary'), { recursive: true });
393
+ await writeFile(join(root, 'worlds/fish/life.json'), '{ not json');
394
+ await writeFile(join(root, 'worlds/fish/diary/2026-10-22.md'), '昨天');
395
+ const seed = createArchiveStore({ ...config, root }); await seed.commitRecords([record('seed', { content: 'earlier memory' })]); seed.close();
396
+ const logged = captureErrors(ctx);
397
+ const { routes } = provideLifeHost(ctx);
398
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true }); await plugin.await();
399
+ await until(async () => routes.length > 0, 'the console route');
400
+ assert.deepEqual(routes.map(route => route.path), ['/dsh-world']);
401
+ const snapshot = await consoleGet(routes, '/dsh-world/console/snapshot');
402
+ assert.equal(snapshot.worldId, 'fish'); assert.equal(snapshot.life, null);
403
+ assert.equal(snapshot.health.length, 1); assert.match(snapshot.health[0], /^生活线没能启动:.*life\.json/);
404
+ assert.equal(snapshot.memory.records, 1); assert.deepEqual(snapshot.compactions, []); assert.deepEqual(snapshot.activityDays, []);
405
+ assert.deepEqual(snapshot.diaryDates, ['2026-10-22']);
406
+ assert.ok(logged.some(line => line.includes('life.json')), logged.join('\n'));
407
+ assert.equal(await readFile(join(root, 'worlds/fish/life.json'), 'utf8'), '{ not json');
408
+ assert.equal(ctx.agents.list().length, 0, 'no home session was created');
409
+ const handle = await ctx.agents.create({ sessionId: SessionId('still-remembers'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
410
+ handle.agent.followup(user('memory still works')); await handle.agent.whenIdle();
411
+ await plugin.dispose(); cleanup.push(() => handle.dispose());
412
+ assert.equal(errors.length, 0);
413
+ assert.equal(requests.length, 1);
414
+ assert.ok(!requests[0].messages.find(m => m.source?.kind === 'dsh-world-history'), 'unrelated archive cannot leak into an unresolved workspace');
415
+ const archive = createArchiveStore({ ...config, root });
416
+ const records = await archive.readPage({ worldId: 'fish', limit: 10 }).then(page => page.records).finally(() => archive.close());
417
+ assert.deepEqual(records.map(r => r.content), ['earlier memory']);
418
+ });
419
+ test('an archived home is rebuilt, reading workspaceRegistry from another plugin without injecting it', async t => {
420
+ const { ctx, root, cleanup } = await hostFixture(t, async function* () { yield* textResponse('reply'); });
421
+ isolateHome(t, root);
422
+ await ctx.agents.create({ sessionId: SessionId('life-home-old'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
423
+ await mkdir(join(root, 'worlds/fish'), { recursive: true });
424
+ await writeFile(join(root, 'worlds/fish/life.json'), JSON.stringify({ version: 1, homeSessionId: 'life-home-old' }));
425
+ // Like the desktop host, the registry comes from a sibling plugin, not from an ancestor of dsh-world.
426
+ const room = { id: 'room', path: join(root, 'worlds/fish/room'), sessionIds: ['life-home-old', 'life-home-1'], attachSession: async () => {} };
427
+ await ctx.plugin({ name: 'workspace-registry', apply: (c: Context) => { c.provide('workspaceRegistry', { archivedSessionIds: ['life-home-old'], list: () => [room], create: async () => room }); } }).await();
428
+ const logged = captureErrors(ctx);
429
+ const { routes } = provideLifeHost(ctx);
430
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true }); cleanup.push(() => plugin.dispose()); await plugin.await();
431
+ assert.equal((await firstWakeDone(ctx, root)).homeSessionId, 'life-home-1');
432
+ assert.deepEqual(logged, []);
433
+ });
434
+ /** A stand-in for the standalone pet's local server. */
435
+ async function fakeStandalonePet(t: TestContext) {
436
+ const received: { url?: string; body: unknown }[] = [];
437
+ const server = createServer((req, res) => {
438
+ let body = ''; req.on('data', chunk => { body += chunk; });
439
+ req.on('end', () => { received.push({ url: req.url, body: JSON.parse(body) }); res.writeHead(200, { 'content-type': 'application/json' }); res.end(JSON.stringify({ ok: true })); });
440
+ });
441
+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
442
+ t.after(() => new Promise(resolve => server.close(resolve)));
443
+ return { received, baseUrl: `http://127.0.0.1:${(server.address() as AddressInfo).port}` };
444
+ }
445
+ async function routeCall(routes: { path: string }[], path: string, url: string, headers: Record<string, string>, body: string) {
446
+ const route = routes.find(entry => entry.path === path) as unknown as { handler(req: unknown, res: unknown): Promise<void> };
447
+ let status = 0; let text = '';
448
+ await route.handler(Object.assign(Readable.from([Buffer.from(body)]), { method: 'POST', url, headers: { host: '127.0.0.1:0', ...headers } }), { writeHead: (code: number) => { status = code; }, end: (value: string) => { text = value; } });
449
+ return { status, body: JSON.parse(text) };
450
+ }
451
+ test('with the bridge and an outlet, words from a local app enter the home and the archive, and her reply goes to the outlet', async t => {
452
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* (request) {
453
+ yield* textResponse(textOf(request).includes('桌宠上的话') ? '![开心](/m/a.png)\n**在呢**' : '早');
454
+ });
455
+ isolateHome(t, root);
456
+ const pet = await fakeStandalonePet(t);
457
+ const runningFile = join(root, 'pet', 'running.json'); await mkdir(join(root, 'pet'));
458
+ await writeFile(runningFile, String.fromCharCode(0xfeff) + JSON.stringify({ baseUrl: pet.baseUrl }));
459
+ const { routes, unregistered } = provideLifeHost(ctx);
460
+ const logged = captureErrors(ctx);
461
+ const outlets = [{ name: '桌面桌宠', urlFile: runningFile, path: '/dsh-pet-7340/broadcast?pet=main&surface=any' }];
462
+ const plugin = ctx.plugin(worldPlugin, { ...config, companionName: '小鱼', life: true, bridge: true, toast: false, outlets }); cleanup.push(() => plugin.dispose()); await plugin.await();
463
+ await until(async () => routes.length === 2, 'the bridge and console routes');
464
+ assert.deepEqual(routes.map(route => route.path), ['/dsh-world/bridge/say', '/dsh-world']);
465
+ assert.equal((await routeCall(routes, '/dsh-world/bridge/say', '/dsh-world/bridge/say', { 'x-dsh-world-token': 'any' }, '{}')).status, 503, 'no bridge before start');
466
+ await consolePost(routes, '/dsh-world/console/start');
467
+ const { homeSessionId } = await firstWakeDone(ctx, root);
468
+ const bridgeFile = join(root, 'worlds/fish/bridge.json');
469
+ const { origin, token, pid, startedAt, name } = JSON.parse(await readFile(bridgeFile, 'utf8'));
470
+ assert.equal(name, '小鱼'); assert.equal(origin, 'http://127.0.0.1:0'); assert.equal(pid, process.pid); assert.match(token, /^[0-9a-f]{64}$/); assert.ok(Number.isFinite(Date.parse(startedAt)));
471
+ const said = await routeCall(routes, '/dsh-world/bridge/say', '/dsh-world/bridge/say', { 'x-dsh-world-token': token }, JSON.stringify({ text: '桌宠上的话' }));
472
+ assert.equal(said.status, 202); assert.equal(said.body.accepted, true); assert.equal(typeof said.body.id, 'string');
473
+ await until(async () => pet.received.length === 1, 'the reply push');
474
+ assert.deepEqual(pet.received, [{ url: '/dsh-pet-7340/broadcast?pet=main&surface=any', body: { text: '在呢', kind: 'reply', name: '小鱼', images: ['http://127.0.0.1:0/m/a.png'] } }]);
475
+ const home = ctx.agents.get(SessionId(homeSessionId!))!; await home.whenIdle(); await ctx.sessions.flush(home.session);
476
+ assert.equal((await routeCall(routes, '/dsh-world/bridge/say', '/dsh-world/bridge/say', { 'x-dsh-world-token': 'wrong' }, '{}')).status, 403);
477
+ // The pet is gone: the reply stays in the home and the console says why it did not arrive.
478
+ await writeFile(runningFile, '{}');
479
+ assert.equal((await routeCall(routes, '/dsh-world/bridge/say', '/dsh-world/bridge/say', { 'x-dsh-world-token': token }, JSON.stringify({ text: '桌宠上的话,第二句' }))).status, 202);
480
+ // The snapshot is cached for a few seconds, so it is read once, after the reply turn.
481
+ await until(async () => ctx.agents.list().every(agent => agent.status === 'idle'), 'the second reply'); await home.whenIdle(); await new Promise(resolve => setTimeout(resolve, 20));
482
+ assert.match((await consoleGet(routes, '/dsh-world/console/snapshot')).health.join('|'), /桌面桌宠没收到小鱼的回复:.*baseUrl/);
483
+ await plugin.dispose();
484
+ assert.ok(!existsSync(bridgeFile)); assert.deepEqual(unregistered.sort(), ['/dsh-world', '/dsh-world/bridge/say']);
485
+ const archive = createArchiveStore({ ...config, root });
486
+ const records = await archive.readPage({ worldId: 'fish', limit: 20 }).then(page => page.records).finally(() => archive.close());
487
+ assert.deepEqual(records.filter(r => r.role === 'user').map(r => r.content).sort(), ['桌宠上的话', '桌宠上的话,第二句'], 'her partner\'s own words, in memory');
488
+ assert.deepEqual(logged, []); assert.equal(errors.length, 0);
489
+ });
490
+ test('the independent WeChat module follows the world start/stop lifecycle', async t => {
491
+ const { ctx, root, cleanup } = await hostFixture(t, () => textResponse('reply'));
492
+ isolateHome(t, root);
493
+ const { routes, unregistered } = provideLifeHost(ctx);
494
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true, wechat: true });
495
+ cleanup.push(() => plugin.dispose()); await plugin.await();
496
+ await until(async () => routes.length === 1, 'console');
497
+ const file = join(root, 'worlds/fish/wechat.json');
498
+ assert.equal(existsSync(file), false);
499
+ await consolePost(routes, '/dsh-world/console/start');
500
+ await firstWakeDone(ctx, root);
501
+ assert.ok(routes.some(route => route.path === '/dsh-world/wechat/ask'));
502
+ assert.ok(existsSync(file));
503
+ await consolePost(routes, '/dsh-world/console/stop');
504
+ assert.equal(existsSync(file), false);
505
+ assert.deepEqual(unregistered, ['/dsh-world/wechat/ask']);
506
+ });
507
+
508
+ test('the console switch takes the WeChat module down and up again while the world runs, and is remembered', async t => {
509
+ const { ctx, root, cleanup } = await hostFixture(t, () => textResponse('reply'));
510
+ isolateHome(t, root);
511
+ const { routes, unregistered } = provideLifeHost(ctx);
512
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true, wechat: true });
513
+ cleanup.push(() => plugin.dispose()); await plugin.await();
514
+ await until(async () => routes.length === 1, 'console');
515
+ const file = join(root, 'worlds/fish/wechat.json');
516
+ await consolePost(routes, '/dsh-world/console/start');
517
+ await firstWakeDone(ctx, root);
518
+ assert.ok(existsSync(file));
519
+ assert.deepEqual((await consoleGet(routes, '/dsh-world/console/snapshot')).modules.wechat, { available: true, enabled: true, running: true });
520
+ await consolePost(routes, '/dsh-world/console/modules', { wechat: false });
521
+ assert.equal(existsSync(file), false, 'switching off removes the connection file');
522
+ assert.deepEqual(unregistered, ['/dsh-world/wechat/ask']);
523
+ assert.deepEqual((await consoleGet(routes, '/dsh-world/console/snapshot')).modules.wechat, { available: true, enabled: false, running: false });
524
+ assert.equal(JSON.parse(await readFile(join(root, 'worlds/fish/world.json'), 'utf8')).wechatEnabled, false);
525
+ await consolePost(routes, '/dsh-world/console/modules', { wechat: true });
526
+ assert.ok(existsSync(file), 'switching on brings it back without a restart');
527
+ assert.equal(routes.filter(route => route.path === '/dsh-world/wechat/ask').length, 1, 'the route is registered again');
528
+ assert.deepEqual((await consoleGet(routes, '/dsh-world/console/snapshot')).modules.wechat, { available: true, enabled: true, running: true });
529
+ });
530
+ test('a module the config does not provide cannot be switched on from the console', async t => {
531
+ const { ctx, root, cleanup } = await hostFixture(t, () => textResponse('reply'));
532
+ isolateHome(t, root);
533
+ const { routes } = provideLifeHost(ctx);
534
+ const plugin = ctx.plugin(worldPlugin, { ...config, life: true });
535
+ cleanup.push(() => plugin.dispose()); await plugin.await();
536
+ await until(async () => routes.length === 1, 'console');
537
+ const result = await routeCall(routes, '/dsh-world', '/dsh-world/console/modules', { 'x-dsh-world': '1', 'content-type': 'application/json' }, JSON.stringify({ wechat: true }));
538
+ assert.equal(result.status, 400);
539
+ assert.deepEqual((await consoleGet(routes, '/dsh-world/console/snapshot')).modules, { wechat: { available: false, enabled: true, running: false }, qq: { available: false, enabled: true, running: false } });
540
+ });
541
+
542
+ test('the config takes outlets by name with the kinds they want; the bridge is off and the toast on unless set', () => {
543
+ const parsed = worldPlugin.Config(config);
544
+ assert.equal(parsed.archiveScope, 'workspace');
545
+ assert.equal(worldPlugin.Config({ ...config, archiveScope: 'world' } as never).archiveScope, 'workspace');
546
+ assert.throws(() => worldPlugin.Config({ ...config, archiveScope: 'all' } as never));
547
+ assert.equal(worldPlugin.Config.dict!.archiveScope.list!.filter(choice => !choice.meta.hidden).length, 2);
548
+ assert.deepEqual(parsed.outlets, []); assert.equal(parsed.bridge, false); assert.equal(parsed.wechat, false); assert.equal(parsed.toast, true);
549
+ const outlets = [{ name: '桌面应用', urlFile: 'C:/app/running.json', path: '/hook', kinds: ['reply', 'reach'] }, { name: '网页', url: '{origin}/x' }];
550
+ assert.deepEqual(worldPlugin.Config({ ...config, outlets } as never).outlets, [outlets[0], { ...outlets[1], kinds: [] }], 'no kinds is an empty list, read as every kind');
551
+ assert.throws(() => worldPlugin.Config({ ...config, outlets: [{ url: 'http://x' }] } as never), /name/);
552
+ assert.throws(() => worldPlugin.Config({ ...config, outlets: [{ name: 'x', kinds: ['shout'] }] } as never), /shout/);
553
+ });
554
+ test('the config validates fallbackWakeTime as HH:MM and defaults to 09:00', () => {
555
+ for (const bad of ['25:00', '9am', '24:00', '09:60', '9:00', '']) assert.throws(() => worldPlugin.Config({ ...config, fallbackWakeTime: bad }), /fallbackWakeTime/);
556
+ assert.equal(worldPlugin.Config({ ...config, fallbackWakeTime: '00:00' }).fallbackWakeTime, '00:00');
557
+ assert.equal(worldPlugin.Config({ ...config, fallbackWakeTime: '23:59' }).fallbackWakeTime, '23:59');
558
+ assert.equal(worldPlugin.Config(config).fallbackWakeTime, '09:00');
559
+ assert.doesNotThrow(() => worldPlugin.Config({ ...config, fallbackWakeMinutes: 60 }));
560
+ });
561
+
562
+ test('a running world whose workspace service starts later still reads her sessions once it is up', async t => {
563
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* () { yield* textResponse('reply'); });
564
+ isolateHome(t, root);
565
+ const handle = await ctx.agents.create({ sessionId: SessionId('earlier'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
566
+ handle.agent.followup(user('said before the plugin loaded')); await handle.agent.whenIdle();
567
+ await mkdir(join(root, 'worlds/fish'), { recursive: true });
568
+ await writeFile(join(root, 'worlds/fish/world.json'), JSON.stringify({ running: true }));
569
+ const logged = captureErrors(ctx);
570
+ const plugin = ctx.plugin(worldPlugin, config); cleanup.push(() => plugin.dispose());
571
+ await plugin.await();
572
+ await ctx.plugin({ name: 'workspace-registry', apply: (c: Context) => {
573
+ c.provide('workspaceRegistry', { list: () => [{ path: join(root, 'worlds/fish/room'), sessionIds: ['earlier'] }] });
574
+ } }).await();
575
+ await until(async () => {
576
+ const archive = createArchiveStore({ ...config, root });
577
+ try { return (await archive.readPage({ worldId: 'fish', limit: 10 })).records.some(r => r.content === 'said before the plugin loaded'); } finally { archive.close(); }
578
+ }, 'the earlier session to be archived');
579
+ assert.deepEqual(logged, []); assert.equal(errors.length, 0);
580
+ });
581
+ test('a session deleted from the host does not stop the world from starting, and what it archived stays', async t => {
582
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* () { yield* textResponse('reply'); });
583
+ isolateHome(t, root);
584
+ await mkdir(join(root, 'worlds/fish'), { recursive: true });
585
+ await writeFile(join(root, 'worlds/fish/world.json'), JSON.stringify({ running: true }));
586
+ const seed = createArchiveStore({ ...config, root });
587
+ await seed.commitRecords([record('kept', { sourceSessionId: 'deleted', content: 'archived before deletion' })], { sessionId: SessionId('deleted'), nextSeq: 5, turn: 1 });
588
+ seed.close();
589
+ ctx.provide('workspaceRegistry', { list: () => [{ path: join(root, 'worlds/fish/room'), sessionIds: ['deleted'] }] });
590
+ const plugin = ctx.plugin(worldPlugin, config); cleanup.push(() => plugin.dispose());
591
+ await plugin.await();
592
+ assert.equal(errors.length, 0);
593
+ const archive = createArchiveStore({ ...config, root });
594
+ const records = await archive.readPage({ worldId: 'fish', limit: 10 }).then(page => page.records).finally(() => archive.close());
595
+ assert.deepEqual(records.map(r => r.content), ['archived before deletion']);
596
+ const after = createArchiveStore({ ...config, root });
597
+ try { assert.deepEqual(after.sourcePage(''), [], 'nothing left to resume for a deleted session'); } finally { after.close(); }
598
+ });
599
+ test('a session only archived in the host keeps its resume point', async t => {
600
+ const { ctx, root, cleanup, errors } = await hostFixture(t, async function* () { yield* textResponse('reply'); });
601
+ isolateHome(t, root);
602
+ const handle = await ctx.agents.create({ sessionId: SessionId('shelved'), meta: { agentPreset: 'companion' }, agentOptions: { provider: 'test', model: 'test' } });
603
+ handle.agent.followup(user('still stored')); await handle.agent.whenIdle();
604
+ await mkdir(join(root, 'worlds/fish'), { recursive: true });
605
+ await writeFile(join(root, 'worlds/fish/world.json'), JSON.stringify({ running: true }));
606
+ const seed = createArchiveStore({ ...config, root });
607
+ await seed.commitRecords([], { sessionId: SessionId('shelved'), nextSeq: 1, turn: 1 }); seed.close();
608
+ ctx.provide('workspaceRegistry', { archivedSessionIds: ['shelved'], list: () => [{ path: join(root, 'worlds/fish/room'), sessionIds: ['shelved'] }] });
609
+ const plugin = ctx.plugin(worldPlugin, config); cleanup.push(() => plugin.dispose());
610
+ await plugin.await();
611
+ assert.equal(errors.length, 0);
612
+ const after = createArchiveStore({ ...config, root });
613
+ try { assert.deepEqual(after.sourcePage(''), ['shelved']); } finally { after.close(); }
614
+ });