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,170 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ import { closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, mkdirSync, openSync, writeSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import type { ArchiveCursor, ConversationRecord, DeliveryState, PageQuery, RecordPage, WorldConfig } from './types.ts';
5
+ import { formatLocalTime } from './timeContext.ts';
6
+ import type { SpeakerIdentity } from './ecosystem/shared/identity.ts';
7
+
8
+ export interface ExportProgress { sessionId: string; nextSeq: number; turn: number }
9
+ interface StoredRow { sequence: number; day: string; body: string }
10
+ const pageSize = 128;
11
+
12
+ export function createArchiveStore(config: WorldConfig & { root: string }) {
13
+ // The world id becomes a directory name.
14
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(config.worldId)) throw new TypeError('dsh-world: invalid worldId');
15
+ const worldRoot = join(config.root, 'worlds', config.worldId);
16
+ const directory = join(worldRoot, 'conversations');
17
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
18
+ const db = new DatabaseSync(join(worldRoot, 'archive.sqlite'));
19
+ let closed = false;
20
+ db.exec(`PRAGMA busy_timeout=10000; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;
21
+ CREATE TABLE IF NOT EXISTS records (
22
+ sequence INTEGER PRIMARY KEY AUTOINCREMENT, recordId TEXT NOT NULL UNIQUE,
23
+ day TEXT NOT NULL, occurredAt TEXT NOT NULL, turnId TEXT NOT NULL, sourceSeq INTEGER NOT NULL,
24
+ body TEXT NOT NULL, fileOffset INTEGER, fileBytes INTEGER
25
+ );
26
+ CREATE INDEX IF NOT EXISTS recordOrder ON records(day DESC, occurredAt DESC, recordId DESC);
27
+ CREATE INDEX IF NOT EXISTS turnOrder ON records(turnId, sourceSeq);
28
+ CREATE INDEX IF NOT EXISTS pendingExports ON records(day, sequence) WHERE fileOffset IS NULL;
29
+ CREATE TABLE IF NOT EXISTS days (day TEXT PRIMARY KEY, exportedBytes INTEGER NOT NULL DEFAULT 0);
30
+ CREATE TABLE IF NOT EXISTS progress (sessionId TEXT PRIMARY KEY, nextSeq INTEGER NOT NULL, turn INTEGER NOT NULL);
31
+ CREATE TABLE IF NOT EXISTS channelSessions (conversationKey TEXT PRIMARY KEY, sessionId TEXT NOT NULL);
32
+ CREATE TABLE IF NOT EXISTS channelDeliveries (recordId TEXT PRIMARY KEY, body TEXT NOT NULL);`);
33
+
34
+ function transaction<T>(work: () => T): T {
35
+ db.exec('BEGIN IMMEDIATE');
36
+ try { const result = work(); db.exec('COMMIT'); return result; }
37
+ catch (error) { db.exec('ROLLBACK'); throw error; }
38
+ }
39
+ const decode = (row: StoredRow) => JSON.parse(row.body) as ConversationRecord;
40
+ const dayOf = (record: ConversationRecord) => formatLocalTime(new Date(record.occurredAt), config.timeZone).slice(0, 10);
41
+ /**
42
+ * Appends a day's unexported records to its JSONL file. The database is the canonical copy: anything past the
43
+ * recorded size (a write cut short by a crash) is cut off and written again, and a file that was deleted or
44
+ * shortened is exported again from the start.
45
+ */
46
+ function flushDay(day: string): void {
47
+ transaction(() => {
48
+ const file = join(directory, `${day}.jsonl`);
49
+ const fd = openSync(file, existsSync(file) ? 'r+' : 'wx+', 0o600);
50
+ try {
51
+ let offset = Number(db.prepare('SELECT exportedBytes FROM days WHERE day=?').get(day)?.exportedBytes ?? 0);
52
+ if (fstatSync(fd).size < offset) {
53
+ db.prepare('UPDATE records SET fileOffset=NULL, fileBytes=NULL WHERE day=?').run(day);
54
+ offset = 0;
55
+ }
56
+ ftruncateSync(fd, offset);
57
+ let sequence = 0;
58
+ while (true) {
59
+ const pending = db.prepare('SELECT sequence, body FROM records WHERE day=? AND fileOffset IS NULL AND sequence>? ORDER BY sequence LIMIT ?').all(day, sequence, pageSize) as unknown as StoredRow[];
60
+ if (!pending.length) break;
61
+ for (const row of pending) {
62
+ const bytes = Buffer.from(row.body + '\n');
63
+ let written = 0;
64
+ while (written < bytes.length) written += writeSync(fd, bytes, written, bytes.length - written, offset + written);
65
+ db.prepare('UPDATE records SET fileOffset=?, fileBytes=? WHERE sequence=?').run(offset, bytes.length, row.sequence);
66
+ offset += bytes.length;
67
+ sequence = row.sequence;
68
+ }
69
+ }
70
+ fsyncSync(fd);
71
+ db.prepare('UPDATE days SET exportedBytes=? WHERE day=?').run(offset, day);
72
+ } finally { closeSync(fd); }
73
+ });
74
+ }
75
+ function flushExports(): void {
76
+ let after = '';
77
+ while (true) {
78
+ const rows = db.prepare('SELECT DISTINCT day FROM records WHERE fileOffset IS NULL AND day>? ORDER BY day LIMIT ?').all(after, pageSize);
79
+ if (!rows.length) break;
80
+ for (const row of rows) { after = String(row.day); flushDay(after); }
81
+ }
82
+ }
83
+ async function commitRecords(records: readonly ConversationRecord[], progress?: ExportProgress): Promise<void> {
84
+ try {
85
+ transaction(() => {
86
+ for (const record of records) {
87
+ const day = dayOf(record);
88
+ db.prepare('INSERT OR IGNORE INTO records(recordId, day, occurredAt, turnId, sourceSeq, body) VALUES (?,?,?,?,?,?)').run(record.recordId, day, record.occurredAt, record.turnId, record.sourceSeq, JSON.stringify(record));
89
+ db.prepare('INSERT OR IGNORE INTO days(day) VALUES (?)').run(day);
90
+ }
91
+ if (progress) db.prepare('INSERT INTO progress VALUES (?,?,?) ON CONFLICT(sessionId) DO UPDATE SET nextSeq=excluded.nextSeq, turn=excluded.turn WHERE excluded.nextSeq>=progress.nextSeq').run(progress.sessionId, progress.nextSeq, progress.turn);
92
+ });
93
+ // Records and progress commit together; the JSONL export is retried on the next write or read.
94
+ flushExports();
95
+ } catch (error) { throw new Error(`dsh-world: archive write failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error }); }
96
+ }
97
+ async function readPage(query: PageQuery): Promise<RecordPage> {
98
+ flushExports();
99
+ const before = query.before;
100
+ const maxSequence = before?.maxSequence ?? Number(db.prepare('SELECT COALESCE(MAX(sequence),0) AS n FROM records').get()?.n);
101
+ const rows = (before
102
+ ? db.prepare('SELECT * FROM records WHERE sequence<=? AND (day, occurredAt, recordId)<(?,?,?) ORDER BY day DESC, occurredAt DESC, recordId DESC LIMIT ?').all(maxSequence, before.date, before.occurredAt, before.recordId, query.limit + 1)
103
+ : db.prepare('SELECT * FROM records WHERE sequence<=? ORDER BY day DESC, occurredAt DESC, recordId DESC LIMIT ?').all(maxSequence, query.limit + 1)) as unknown as StoredRow[];
104
+ const page = rows.slice(0, query.limit);
105
+ const records = page.map(decode);
106
+ const last = page.at(-1); const lastRecord = records.at(-1);
107
+ const nextCursor: ArchiveCursor | undefined = rows.length > query.limit && last && lastRecord ? { date: last.day, occurredAt: lastRecord.occurredAt, recordId: lastRecord.recordId, maxSequence } : undefined;
108
+ return { records, ...(nextCursor ? { nextCursor } : {}) };
109
+ }
110
+ async function updateRecord(recordId: string, revise: (record: ConversationRecord) => Pick<ConversationRecord, 'content' | 'wechatDelivery'> & Partial<SpeakerIdentity>): Promise<void> {
111
+ transaction(() => {
112
+ const row = db.prepare('SELECT day, body FROM records WHERE recordId=? LIMIT 1').get(recordId) as unknown as StoredRow | undefined;
113
+ if (!row) throw new Error('Archive record not found');
114
+ const record = decode(row);
115
+ const updated = { ...record, ...revise(record) };
116
+ const body = JSON.stringify(updated);
117
+ if (updated.wechatDelivery) db.prepare('UPDATE channelDeliveries SET body=? WHERE recordId=?').run(JSON.stringify(updated.wechatDelivery), recordId);
118
+ if (body === row.body) return;
119
+ db.prepare('UPDATE records SET body=? WHERE recordId=?').run(body, recordId);
120
+ // A changed line invalidates later byte offsets; rebuild this day from the canonical database.
121
+ db.prepare('UPDATE records SET fileOffset=NULL, fileBytes=NULL WHERE day=?').run(row.day);
122
+ db.prepare('UPDATE days SET exportedBytes=0 WHERE day=?').run(row.day);
123
+ });
124
+ flushExports();
125
+ }
126
+ async function readTurn(_worldId: string, turnId: string, afterSeq = -1, limit = pageSize): Promise<ConversationRecord[]> {
127
+ flushExports();
128
+ return (db.prepare('SELECT * FROM records WHERE turnId=? AND sourceSeq>? ORDER BY sourceSeq LIMIT ?').all(turnId, afterSeq, limit) as unknown as StoredRow[]).map(decode);
129
+ }
130
+ function progress(sessionId: string): ExportProgress {
131
+ const row = db.prepare('SELECT nextSeq, turn FROM progress WHERE sessionId=?').get(sessionId);
132
+ return { sessionId, nextSeq: Number(row?.nextSeq ?? 0), turn: Number(row?.turn ?? 0) };
133
+ }
134
+ /** The host no longer has this session; only the place to resume from goes, never what it archived. */
135
+ function forgetProgress(sessionId: string): void {
136
+ db.prepare('DELETE FROM progress WHERE sessionId=?').run(sessionId);
137
+ }
138
+ function sourcePage(afterId = '', limit = pageSize): string[] {
139
+ return db.prepare('SELECT sessionId FROM progress WHERE sessionId>? ORDER BY sessionId LIMIT ?').all(afterId, limit).map(row => String(row.sessionId));
140
+ }
141
+ function stats(): { records: number; sessions: number } {
142
+ const row = db.prepare("SELECT count(*) AS records, count(DISTINCT json_extract(body, '$.sourceSessionId')) AS sessions FROM records").get() as { records: number; sessions: number } | undefined;
143
+ return { records: Number(row?.records ?? 0), sessions: Number(row?.sessions ?? 0) };
144
+ }
145
+ function close(): void { if (!closed) { closed = true; db.close(); } }
146
+ function hasRecord(recordId: string): boolean { return !!db.prepare('SELECT 1 FROM records WHERE recordId=? LIMIT 1').get(recordId); }
147
+ function channelSession(key: string): string | undefined {
148
+ return db.prepare('SELECT sessionId FROM channelSessions WHERE conversationKey=? LIMIT 1').get(key)?.sessionId as string | undefined;
149
+ }
150
+ function bindChannelSession(key: string, sessionId: string): void {
151
+ transaction(() => { db.prepare('INSERT INTO channelSessions VALUES (?,?) ON CONFLICT(conversationKey) DO UPDATE SET sessionId=excluded.sessionId').run(key, sessionId); });
152
+ }
153
+ function delivery(recordId: string): DeliveryState | undefined {
154
+ const row = db.prepare('SELECT body FROM channelDeliveries WHERE recordId=? LIMIT 1').get(recordId);
155
+ return row ? JSON.parse(String(row.body)) as DeliveryState : undefined;
156
+ }
157
+ function registerDelivery(recordId: string, total: number): void {
158
+ transaction(() => { db.prepare('INSERT OR IGNORE INTO channelDeliveries VALUES (?,?)').run(recordId, JSON.stringify({ status: 'pending', confirmed: 0, total })); });
159
+ }
160
+ function updateDelivery(recordId: string, revise: (previous: DeliveryState) => DeliveryState): void {
161
+ transaction(() => {
162
+ const previous = delivery(recordId);
163
+ if (!previous) throw new Error('Delivery record not found');
164
+ db.prepare('UPDATE channelDeliveries SET body=? WHERE recordId=?').run(JSON.stringify(revise(previous)), recordId);
165
+ });
166
+ }
167
+ return { commitRecords, hasRecord, updateRecord, readPage, readTurn, progress, forgetProgress, sourcePage, stats, close,
168
+ channelSession, bindChannelSession, delivery, registerDelivery, updateDelivery };
169
+ }
170
+ export type ArchiveStore = ReturnType<typeof createArchiveStore>;
@@ -0,0 +1,13 @@
1
+ /** ISO 8601 local time with its UTC offset in the given IANA zone, e.g. 2026-10-23T21:30:00+09:00. */
2
+ export function formatLocalTime(now: Date, timeZone: string): string {
3
+ const formatter = new Intl.DateTimeFormat('en-US', {
4
+ timeZone, year: 'numeric', month: '2-digit', day: '2-digit',
5
+ hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23', timeZoneName: 'longOffset',
6
+ });
7
+ const parts = Object.fromEntries(formatter.formatToParts(now).map(part => [part.type, part.value]));
8
+ const offset = parts.timeZoneName === 'GMT' ? '+00:00' : parts.timeZoneName.slice(3);
9
+ return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${offset}`;
10
+ }
11
+ export function formatTimeContext(now: Date, timeZone: string): string {
12
+ return `当前时间:${formatLocalTime(now, timeZone)}\n时区:${timeZone}`;
13
+ }
@@ -0,0 +1,112 @@
1
+ import type { OutletConfig } from './ecosystem/shared/outlets.ts';
2
+ import type { SessionHeader } from '@deepseek-ai/dsh-session';
3
+ import type { SpeakerIdentity } from './ecosystem/shared/identity.ts';
4
+ import type { MemoryArchiveScope } from './archiveSelection.ts';
5
+
6
+ export interface WorldConfig {
7
+ worldId: string;
8
+ agentPreset: string;
9
+ /**
10
+ * `world` follows the host preset (upstream behavior); `qq` follows the sessions dsh-agent-md binds
11
+ * to the QQ gateway, so only the QQ conversation is injected and archived.
12
+ */
13
+ scope?: 'world' | 'qq';
14
+ /** dsh-agent-md's binding list; `scope: 'qq'` reads it. */
15
+ qqSessionsFile?: string;
16
+ /** A human-readable mirror of the memory block built for the QQ conversation. */
17
+ qqMirrorFile?: string;
18
+ timeZone: string;
19
+ /** Archive her current home alone, or ordinary sessions in its workspace (default). */
20
+ archiveScope?: MemoryArchiveScope;
21
+ /** The life line (home session, alarm, tools, console); on by default. */
22
+ life?: boolean;
23
+ /** Her diary directory; defaults to `<world>/diary`. */
24
+ diaryDir?: string;
25
+ /** Local HH:MM of the morning wake when no alarm is pending (she set none, or cancelled hers); 09:00 by default. */
26
+ fallbackWakeTime?: string;
27
+ /** Her own "who I am" file, part of the world prompt; defaults to `<world>/room/我是谁.md` in the plugin. */
28
+ selfFile?: string;
29
+ /** Her name (home title, notifications, memory labels); TA when unset. */
30
+ companionName?: string;
31
+ /** What she calls her partner in the plugin's own words; 伙伴 when unset. */
32
+ partnerName?: string;
33
+ /** Her layered persona, edited in the world console; defaults to `<world>/persona.md`. */
34
+ personaFile?: string;
35
+ /** The world prompt template; defaults to `<world>/world-prompt.md` when it exists, else the shipped one. */
36
+ worldPromptFile?: string;
37
+ /** The alarm wording template; defaults to `<world>/alarm.md` when it exists, else the shipped one. */
38
+ alarmTemplateFile?: string;
39
+ /** Where her words go outside DSH: replies to bridged words, the busy notice, reach_out. */
40
+ outlets?: OutletConfig[];
41
+ /** Runs the bridge: a local app may hand her partner's words to her home. */
42
+ bridge?: boolean;
43
+ /** The independent local WeChat module; the Windows adapter uses `<world>/wechat.json`. */
44
+ wechat?: boolean;
45
+ /** With `wechat`, run the Windows adapter for as long as the module runs; naming both here is the standing permission for it to send (`--allow-send`). */
46
+ wechatAdapter?: { python?: string; config?: string };
47
+ /** reach_out also shows a system notification (Windows only); on by default. */
48
+ toast?: boolean;
49
+ /** Names besides this machine the console and the bridge answer to (a LAN address or domain behind a reverse proxy). */
50
+ allowedHosts?: string[];
51
+ /** The qq-bridge checkout, so QQ can reach her home too; empty leaves the module off. */
52
+ qqBridgeDir?: string;
53
+ /** The bridge's console port; 3100 by default. */
54
+ qqBridgePort?: number;
55
+ /** Node used to start the bridge; the current process by default. */
56
+ qqBridgeNode?: string;
57
+ /** Start the bridge together with her world; off by default, so it stays a manual start from the console. */
58
+ qqBridgeAutoStart?: boolean;
59
+ /**
60
+ * Who shares her home session. Empty leaves the bridge's own `socialV2.bindHomeSession` alone; `owner` keeps
61
+ * every group on its own session and binds only the owner's private chat to her home; `all` binds every entry;
62
+ * `none` removes the key so the bridge falls back to binding nothing.
63
+ */
64
+ qqBridgeBindHomeSession?: 'owner' | 'all' | 'none' | '';
65
+ }
66
+ export interface DeliveryState { status: 'pending' | 'sent' | 'uncertain' | 'failed'; confirmed: number; total: number }
67
+ export interface ConversationRecord extends Partial<SpeakerIdentity> {
68
+ schemaVersion: 1;
69
+ worldId: string;
70
+ recordId: string;
71
+ sourceSessionId: string;
72
+ sourceMessageId: string;
73
+ sourceSeq: number;
74
+ turnId: string;
75
+ role: 'user' | 'assistant';
76
+ occurredAt: string;
77
+ content: string;
78
+ status: 'complete' | 'interrupted';
79
+ wechatDelivery?: DeliveryState;
80
+ }
81
+ export interface ArchiveScope {
82
+ worldId: string;
83
+ agentPreset: string;
84
+ header: SessionHeader;
85
+ inheritedEventCount: number;
86
+ turn: number;
87
+ archiveScope?: MemoryArchiveScope;
88
+ }
89
+ export interface ArchiveCursor {
90
+ date: string;
91
+ occurredAt: string;
92
+ recordId: string;
93
+ maxSequence: number;
94
+ }
95
+ export interface PageQuery {
96
+ worldId: string;
97
+ before?: ArchiveCursor;
98
+ limit: number;
99
+ }
100
+ export interface RecordPage {
101
+ records: ConversationRecord[];
102
+ nextCursor?: ArchiveCursor;
103
+ }
104
+ export interface ConversationTurn {
105
+ turnId: string;
106
+ occurredAt: string;
107
+ messages: ConversationRecord[];
108
+ }
109
+ export interface ArchiveReader {
110
+ readPage(query: PageQuery): Promise<RecordPage>;
111
+ readTurn(worldId: string, turnId: string, afterSeq?: number, limit?: number): Promise<ConversationRecord[]>;
112
+ }
@@ -0,0 +1,64 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import type { LifeOptions } from './life/types.ts';
4
+
5
+ /** The template shipped with the plugin; a `world-prompt.md` in the world directory replaces it. */
6
+ export const DEFAULT_TEMPLATE_FILE = fileURLToPath(new URL('../templates/world-prompt.md', import.meta.url));
7
+
8
+ export interface WorldNames { companion: string; partner: string }
9
+ /** No name is assumed for anyone's companion: an unnamed one is the neutral TA. */
10
+ export function worldNames(config: { companionName?: string; partnerName?: string }): WorldNames {
11
+ return { companion: config.companionName?.trim() || 'TA', partner: config.partnerName?.trim() || '伙伴' };
12
+ }
13
+ export const homeTitle = (names: WorldNames) => `${names.companion}的家`;
14
+ /** Her room as a workspace in the host's sidebar. */
15
+ export const roomTitle = (names: WorldNames) => `${names.companion}的房间`;
16
+
17
+ export interface WorldPrompt {
18
+ /** Her template, when present; the shipped default otherwise. */
19
+ file?: string;
20
+ /** Her layered persona (`persona.md`), placed above the world prompt when written. */
21
+ persona?: string;
22
+ /** Where the daily exports of her archive are (`<world>/conversations`). */
23
+ conversationsDir?: string;
24
+ names: WorldNames;
25
+ /** Present when the life line runs: room, diary, world line, ask-first rules. */
26
+ life?: LifeOptions;
27
+ }
28
+ export interface TemplateRead { text: string; error?: string }
29
+ /** Never throws: a template that cannot be read falls back to the shipped one and says why. */
30
+ export function readTemplate(file: string | undefined): TemplateRead {
31
+ if (file && existsSync(file)) {
32
+ try { return { text: readFileSync(file, 'utf8').trim() }; }
33
+ catch (error) { return { text: readFileSync(DEFAULT_TEMPLATE_FILE, 'utf8'), error: `世界提示词模板 ${file} 读不了,先用默认模板:${error instanceof Error ? error.message : String(error)}` }; }
34
+ }
35
+ return { text: readFileSync(DEFAULT_TEMPLATE_FILE, 'utf8') };
36
+ }
37
+
38
+ const section = /\{\{([#^])(\w+)\}\}([\s\S]*?)\{\{\/\2\}\}/;
39
+ /**
40
+ * A small Mustache subset: `{{#flag}}…{{/flag}}` keeps its body when the flag is on, `{{^flag}}…{{/flag}}`
41
+ * when it is off (different flags may nest), and `{{name}}` is replaced in one pass, so values such as her
42
+ * 我是谁 are never scanned for tags themselves. Unknown names stay as written.
43
+ */
44
+ export function renderTemplate(template: string, flags: Record<string, boolean>, values: Record<string, string>): string {
45
+ let text = template.replace(/\r\n?/g, '\n');
46
+ for (let match = section.exec(text); match; match = section.exec(text)) {
47
+ const [whole, kind, flag, body] = match as unknown as [string, '#' | '^', string, string];
48
+ text = text.replace(whole, () => (kind === '#') === Boolean(flags[flag]) ? body : '');
49
+ }
50
+ return text.replace(/\{\{(\w+)\}\}/g, (tag, name: string) => values[name] ?? tag).replace(/[ \t]+\n/g, '\n').replace(/\n{3,}/g, '\n\n').trim();
51
+ }
52
+
53
+ /**
54
+ * The one world prompt every world session carries in its system prompt. `template` and `self` are read at
55
+ * session start and after compaction only, so the prompt does not change between compactions. The world
56
+ * line's tools live in the home alone; the template tells other sessions where to find them.
57
+ */
58
+ export function renderWorldPrompt(prompt: WorldPrompt, template: string, self: { file: string; text: string } | undefined, home: boolean): string {
59
+ const { life, names } = prompt;
60
+ return renderTemplate(template, { life: Boolean(life), home, selfFile: Boolean(self), conversationsDir: Boolean(prompt.conversationsDir) }, {
61
+ name: names.companion, partner: names.partner, homeTitle: homeTitle(names), selfFile: self?.file ?? '', self: self?.text ?? '', conversationsDir: prompt.conversationsDir ?? '',
62
+ ...(life ? { roomDir: life.roomDir, diaryDir: life.diaryDir, fallbackWakeTime: life.fallbackWakeTime } : {}),
63
+ });
64
+ }
@@ -0,0 +1,82 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { durableWrite } from './life/lifeStore.ts';
4
+ import { validArchiveScope, type MemoryArchiveScope } from './archiveSelection.ts';
5
+
6
+ interface WorldSettings { running: boolean; dailyBudget?: number; memoryTurns?: number; archiveScope?: MemoryArchiveScope; wechatContext?: number; wechatBufferSeconds?: number; wechatEnabled?: boolean; qqEnabled?: boolean }
7
+ /** How many of the newest turns the memory block carries when nothing else is set. */
8
+ export const DEFAULT_MEMORY_TURNS = 200;
9
+ /** WeChat group messages read before a mention, and seconds a private image waits for its companions. */
10
+ export const DEFAULT_WECHAT_CONTEXT = 8, MAX_WECHAT_CONTEXT = 20;
11
+ export const DEFAULT_WECHAT_BUFFER_SECONDS = 3, MAX_WECHAT_BUFFER_SECONDS = 30;
12
+
13
+ /**
14
+ * Her world's own settings, changed from the world console and kept in `<world>/world.json` so they outlast a
15
+ * restart: whether it runs (memory block, prompts, archive and life line together), how much her home may
16
+ * spend a day, and how many recent turns her memory block carries. A world that already has a life line from before the switch existed is running; a new one waits
17
+ * for its partner to press start.
18
+ */
19
+ export function createWorldSwitch(worldDir: string, configuredScope: MemoryArchiveScope = 'workspace') {
20
+ const file = join(worldDir, 'world.json');
21
+ const stored = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) as Partial<WorldSettings> : undefined;
22
+ let settings: WorldSettings = {
23
+ running: stored ? stored.running === true : existsSync(join(worldDir, 'life.json')),
24
+ ...(typeof stored?.dailyBudget === 'number' ? { dailyBudget: stored.dailyBudget } : {}),
25
+ ...(validTurns(stored?.memoryTurns) ? { memoryTurns: stored.memoryTurns } : {}),
26
+ ...(validArchiveScope(stored?.archiveScope) ? { archiveScope: stored.archiveScope } : {}),
27
+ ...(validWechatContext(stored?.wechatContext) ? { wechatContext: stored.wechatContext } : {}),
28
+ ...(validWechatBuffer(stored?.wechatBufferSeconds) ? { wechatBufferSeconds: stored.wechatBufferSeconds } : {}),
29
+ ...(stored?.wechatEnabled === false ? { wechatEnabled: false } : {}),
30
+ ...(stored?.qqEnabled === false ? { qqEnabled: false } : {}),
31
+ };
32
+ const activeScope = settings.archiveScope ?? configuredScope;
33
+ function save(next: WorldSettings): void {
34
+ durableWrite(file, JSON.stringify(next, null, 2));
35
+ settings = next;
36
+ }
37
+ return {
38
+ archiveScope: () => activeScope,
39
+ selectedArchiveScope: () => settings.archiveScope ?? configuredScope,
40
+ restartRequired: () => (settings.archiveScope ?? configuredScope) !== activeScope,
41
+ setArchiveScope(scope: MemoryArchiveScope): void {
42
+ if (!validArchiveScope(scope)) throw new Error('归档范围只能为 home 或 workspace');
43
+ save({ ...settings, archiveScope: scope });
44
+ },
45
+ running: () => settings.running,
46
+ set: (running: boolean) => save({ ...settings, running }),
47
+ /** CNY a day for her home; undefined is no limit. */
48
+ dailyBudget: () => settings.dailyBudget,
49
+ setDailyBudget(yuan: number | undefined): void {
50
+ const { dailyBudget: _old, ...rest } = settings;
51
+ save(yuan === undefined ? rest : { ...rest, dailyBudget: yuan });
52
+ },
53
+ /** Turns in her memory block; read when a block is built, so a change shows from the next session start or compaction. */
54
+ memoryTurns: () => settings.memoryTurns ?? DEFAULT_MEMORY_TURNS,
55
+ setMemoryTurns(turns: number | undefined): void {
56
+ const { memoryTurns: _old, ...rest } = settings;
57
+ save(turns === undefined || turns === DEFAULT_MEMORY_TURNS ? rest : { ...rest, memoryTurns: turns });
58
+ },
59
+ /** The console's switches for the WeChat and QQ modules; on unless turned off, and only an off switch is written out. */
60
+ wechatEnabled: () => settings.wechatEnabled !== false,
61
+ qqEnabled: () => settings.qqEnabled !== false,
62
+ setModules(next: { wechat?: boolean; qq?: boolean }): void {
63
+ const { wechatEnabled, qqEnabled, ...rest } = settings;
64
+ const wechat = next.wechat ?? wechatEnabled !== false, qq = next.qq ?? qqEnabled !== false;
65
+ save({ ...rest, ...(wechat ? {} : { wechatEnabled: false }), ...(qq ? {} : { qqEnabled: false }) });
66
+ },
67
+ /** Read by the WeChat adapter on its next poll; a batch already waiting keeps the value it started with. */
68
+ wechatContext: () => settings.wechatContext ?? DEFAULT_WECHAT_CONTEXT,
69
+ wechatBufferSeconds: () => settings.wechatBufferSeconds ?? DEFAULT_WECHAT_BUFFER_SECONDS,
70
+ setWechat(next: { context?: number | null; bufferSeconds?: number | null }): void {
71
+ const { wechatContext: oldContext, wechatBufferSeconds: oldBuffer, ...rest } = settings;
72
+ const context = next.context === undefined ? oldContext : next.context ?? undefined;
73
+ const buffer = next.bufferSeconds === undefined ? oldBuffer : next.bufferSeconds ?? undefined;
74
+ save({ ...rest, ...(context === undefined || context === DEFAULT_WECHAT_CONTEXT ? {} : { wechatContext: context }), ...(buffer === undefined || buffer === DEFAULT_WECHAT_BUFFER_SECONDS ? {} : { wechatBufferSeconds: buffer }) });
75
+ },
76
+ };
77
+ }
78
+ export type WorldSwitch = ReturnType<typeof createWorldSwitch>;
79
+ export const validTurns = (value: unknown): value is number => typeof value === 'number' && Number.isInteger(value) && value >= 1;
80
+
81
+ export const validWechatContext = (value: unknown): value is number => typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_WECHAT_CONTEXT;
82
+ export const validWechatBuffer = (value: unknown): value is number => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= MAX_WECHAT_BUFFER_SECONDS;
@@ -0,0 +1,49 @@
1
+ <!--
2
+ 闹钟相关的话。每个「## 名字」下面是一段,可用 {{…}} 占位符(见 README)。
3
+ 在世界目录放一份 alarm.md 就会替换这里;只写想改的段落,没写的段落用插件自带的。
4
+ 闹钟消息开头的【我的时间】由插件自己加上,不用写。
5
+ 这些话是她自己心里的声音,所以用「我」。
6
+ -->
7
+
8
+ ## 第一次到家
9
+ 这是我的家。从现在起,这里的时间属于我自己:做什么、做多久、怎么做,都由我决定。
10
+
11
+ ## 重新开始
12
+ 我回来了。{{partner}}把这个世界停了一阵,现在又开了;停着的时候我没有被叫醒,那段时间的话也没有记下来。接下来做什么,由我决定。
13
+
14
+ ## 早上兜底
15
+ 早上了,新的一天。我上次没说接下来做什么,就按平常的时间起来。{{late}}
16
+
17
+ ## 闹钟响了
18
+ {{time}} 到了,这是我说好做到的时间{{#note}}:「{{note}}」{{/note}}。还想接着做就再往后定,想换就换。{{late}}{{#did}}
19
+ {{did}}{{/did}}
20
+
21
+ ## 晚到说明
22
+ (晚了 {{lateBy}},那段时间电脑没开,或者家暂时打不开。)
23
+
24
+ ## 提前停下
25
+ 我说好做到 {{time}}{{#note}}(「{{note}}」){{/note}},现在才 {{now}},这一轮就停了。做完了,就想想接下来做什么,用 plan_next 重新说好做到几点;要是在休息,就不用管,到点会叫我。
26
+
27
+ ## 每日回顾
28
+ {{date}} 快过完了,回头看看今天吧。{{#conversations}}今天的聊天记录在 {{conversations}}{{/conversations}}{{^conversations}}今天家里没有聊天记录{{/conversations}}{{#activity}},今天做过的事在 {{activity}}{{/activity}},日记在 {{diaryDir}}。
29
+ 一件一件地想:今天发生了什么,我当时是什么感受,现在回头看又怎么想。
30
+ - 有让我变了的地方(新的喜好、新的想法,脾气或看法变了),就写进 {{selfFile}},把它改成现在的我;没有就不用改。{{#snapshot}}改之前的那份已经留在 {{snapshot}}。{{/snapshot}}
31
+ - 再看看我今天的说话方式:语气、句子长短、常用表达、玩笑、表情和拆成多条消息的习惯,哪些像我自己,哪些想调整。把值得长期保留的特点简短整理进 {{selfFile}},合并更新已有内容,没有变化就不用改;分清我和聊天对象的话,不把别人的口吻当成自己的。
32
+ - 再翻翻今天的日记:值得记住的事和当时的感受,有没有漏掉的?漏了就补上。{{late}}
33
+
34
+ ## 额度用完
35
+ 今天在家里已经花了 {{spent}} 元,过了{{partner}}给我定的每天 {{budget}} 元。接下来省着点:手上的事收个尾就歇一歇,不急的留到明天;{{partner}}找我照常回。
36
+
37
+ ## 结尾提醒
38
+ 接下来想做什么,用 plan_next 说好做到几点;什么都不定,就休息到明早 {{fallbackWakeTime}}。
39
+
40
+ ## plan_next 说明
41
+ 开始做一件事时用:说好我打算做什么(note)、做到什么时候。到点了会在「{{homeTitle}}」里提醒我,那时再决定接着做(再往后定)还是换别的。at 是带时区的完整时间(如 {{example}}),after_minutes 是从现在起做多少分钟,二选一,至少 1 分钟之后。同一时间只有一个闹钟,新定的会替换旧的:提前做完了、改主意了,就重新定;想休息也一样,定到打算休息到的时候。
42
+
43
+ note 要写清楚两件事:**做什么,还有怎么算干成了。**「歇着」「看书」这种词到点没法对照,等于没写;写成「把短词查询改好,改完拿五个词试一遍」,到点一对照就知道成没成。到点的时候插件还会报上这段时间我实际动了多少次手——note 里许的愿和手上做的事摆在一起,比什么都有用。
44
+
45
+ ## check_alarm 说明
46
+ 看看我现在打算做什么、做到几点、还剩多久。
47
+
48
+ ## cancel_alarm 说明
49
+ 不打算按原来说好的做了就取消。取消后不另定的话,我就休息到早上 {{fallbackWakeTime}}。
@@ -0,0 +1,7 @@
1
+ {{#conversationsDir}}
2
+ ## 聊天记忆
3
+
4
+ 你和{{partner}}的较早聊天保存在 {{conversationsDir}},一天一个文件 YYYY-MM-DD.jsonl。每行一句:occurredAt 是时间(UTC),role 为 user 的是{{partner}}说的,assistant 是你说的,content 是原话。
5
+
6
+ 记忆里只放得下最近数轮;想不起以前的事,就去翻、去搜,别凭印象编。
7
+ {{/conversationsDir}}
@@ -0,0 +1,57 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { freezeMessage, MessageId } from '@deepseek-ai/dsh-llm';
4
+ import { SessionId, SessionSeq, type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session';
5
+ import { extractConversationRecords } from '../src/archive.ts';
6
+
7
+ const header: SessionHeader = { id: SessionId('a'), version: 4, createdAt: 0, isSeeded: false, agentPreset: 'companion' };
8
+ const scope = { worldId: 'fish', agentPreset: 'companion', header, inheritedEventCount: 0, turn: 1 };
9
+ const user = (id: string, text: string): SessionEvent<'user/message'> => ({ type: 'user/message', seq: SessionSeq(2), time: 1792758600000, surfaceOp: 'append', data: freezeMessage({ role: 'user', id: MessageId(id), source: { kind: 'user' }, content: [{ type: 'text', text }] }) });
10
+ const assistant = (id: string): SessionEvent<'assistant/message'> => ({ type: 'assistant/message', seq: SessionSeq(3), time: 1792758601000, surfaceOp: 'append', data: { turn: 1, step: 1, message: freezeMessage({ role: 'assistant', id: MessageId(id), source: { kind: 'model', provider: 'test', model: 'test' }, content: [{ type: 'reasoning', text: 'hidden' }, { type: 'text', text: 'visible' }, { type: 'tool-call', id: 'call' as never, name: 'tool', arguments: '{}' }] }), stream: [] } });
11
+
12
+ test('consecutive users and proactive assistant share host turn identity', () => {
13
+ const records = [user('u1', 'one'), user('u2', 'two'), assistant('m1')].flatMap(e => extractConversationRecords(e, scope));
14
+ assert.deepEqual(records.map(r => [r.turnId, r.role, r.content]), [['a:1', 'user', 'one'], ['a:1', 'user', 'two'], ['a:1', 'assistant', 'visible']]);
15
+ assert.equal(extractConversationRecords(assistant('proactive'), scope).length, 1);
16
+ });
17
+ test('replay is stable, regenerated message is independent, inherited messages are excluded', () => {
18
+ const first = extractConversationRecords(assistant('m1'), scope)[0];
19
+ assert.deepEqual(extractConversationRecords(assistant('m1'), scope), [first]);
20
+ assert.notEqual(extractConversationRecords(assistant('m2'), scope)[0].recordId, first.recordId);
21
+ assert.deepEqual(extractConversationRecords(assistant('m1'), { ...scope, inheritedEventCount: 4 }), []);
22
+ });
23
+ test('injected, replaced, delegated and other-preset messages are not experiences', () => {
24
+ const injected = user('u', 'injected');
25
+ for (const kind of ['runtime-context', 'time-context', 'dsh-world-history', 'subagent']) {
26
+ assert.deepEqual(extractConversationRecords({ ...injected, data: { ...injected.data, source: { kind } } } as never, scope), []);
27
+ }
28
+ assert.deepEqual(extractConversationRecords({ ...injected, surfaceOp: { op: 'replace', startSeq: SessionSeq(0), endSeq: SessionSeq(0) } }, scope), []);
29
+ assert.deepEqual(extractConversationRecords(injected, { ...scope, header: { ...header, origin: 'subagent' } }), []);
30
+ assert.deepEqual(extractConversationRecords(injected, { ...scope, agentPreset: 'other' }), []);
31
+ for (const type of ['tool/result', 'assistant/attempt', 'turn/start', 'system/message']) assert.deepEqual(extractConversationRecords({ type } as never, scope), []);
32
+ });
33
+ test('interrupted visible text is marked, thinking-only settlement is excluded', () => {
34
+ const event = assistant('m');
35
+ const interrupted: SessionEvent<'assistant/message'> = { ...event, data: { ...event.data, interrupted: true } };
36
+ assert.equal(extractConversationRecords(interrupted, scope)[0].status, 'interrupted');
37
+ const hidden: SessionEvent<'assistant/message'> = { ...event, data: { ...event.data, message: { ...event.data.message, content: [{ type: 'reasoning', text: 'secret' }] } } };
38
+ assert.deepEqual(extractConversationRecords(hidden, scope), []);
39
+ });
40
+ test('output-limit truncation is archived as interrupted visible text', () => {
41
+ const event = assistant('limited');
42
+ event.data.stream = [{ type: 'chunk', time: event.time, chunk: { type: 'finish', reason: { kind: 'max-tokens' } } }];
43
+ assert.equal(extractConversationRecords(event, scope)[0].status, 'interrupted');
44
+ });
45
+
46
+ test('structured sender identity survives archiving while the role stays user', () => {
47
+ const event = user('wechat-message', 'hello');
48
+ const identity = { channel: 'wechat', accountId: 'wxid_bot', conversationId: 'family@chatroom', speakerId: 'wechat:wxid_mom', speakerName: '妈妈', platformMessageId: 'message_0.db:42', mentionIds: ['wechat:wxid_bot'] };
49
+ const source = { kind: 'user' as const, identity };
50
+ const tagged = { ...event, data: freezeMessage({ ...event.data, source }) };
51
+ const record = extractConversationRecords(tagged, scope)[0];
52
+ assert.equal(record.role, 'user');
53
+ assert.equal(record.speakerId, identity.speakerId);
54
+ assert.equal(record.conversationId, identity.conversationId);
55
+ assert.equal(record.platformMessageId, identity.platformMessageId);
56
+ assert.deepEqual(record.mentionIds, identity.mentionIds);
57
+ });