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,49 @@
1
+ export const realTimers = { set: (fn, ms) => setTimeout(fn, ms), clear: handle => clearTimeout(handle) };
2
+ const retryMinutes = [1, 5, 15, 30, 60];
3
+ /** Timers wait at most this long before re-checking the wall clock, so suspend and clock changes cannot strand an alarm. */
4
+ const SEGMENT_MS = 5 * 60_000;
5
+ /**
6
+ * Waits for the pending alarm and calls `fire` once it is due, never before. A failed delivery backs off
7
+ * (1, 5, 15, 30, 60 minutes); a new alarm or a delivery that worked starts the backoff over.
8
+ */
9
+ export function createAlarmTimer(deps) {
10
+ const { clock, timers } = deps;
11
+ let handle;
12
+ let retries = 0;
13
+ let retryAt;
14
+ let stopped = false;
15
+ const dueAt = (at) => Math.max(Date.parse(at), retryAt ?? 0);
16
+ function cancel() {
17
+ if (handle !== undefined) {
18
+ timers.clear(handle);
19
+ handle = undefined;
20
+ }
21
+ }
22
+ function arm() {
23
+ cancel();
24
+ const at = deps.dueAlarm();
25
+ if (stopped || at === undefined)
26
+ return;
27
+ handle = timers.set(() => {
28
+ handle = undefined;
29
+ const current = deps.dueAlarm();
30
+ if (current !== undefined && dueAt(current) > clock().getTime())
31
+ arm();
32
+ else
33
+ deps.fire();
34
+ }, Math.min(Math.max(0, dueAt(at) - clock().getTime()), SEGMENT_MS));
35
+ }
36
+ return {
37
+ arm,
38
+ /** Starts the backoff over (a new alarm, or one that was delivered) and re-arms. */
39
+ reset() { retries = 0; retryAt = undefined; arm(); },
40
+ /** A delivery failed: the next try waits out the backoff. Returns the wait in minutes. */
41
+ failed() {
42
+ const minutes = retryMinutes[Math.min(retries++, retryMinutes.length - 1)];
43
+ retryAt = clock().getTime() + minutes * 60_000;
44
+ arm();
45
+ return minutes;
46
+ },
47
+ stop() { stopped = true; cancel(); },
48
+ };
49
+ }
@@ -0,0 +1,4 @@
1
+ export declare function createDiaryReader(diaryDir: string): {
2
+ dates: () => string[];
3
+ read: (date: string) => string | undefined;
4
+ };
@@ -0,0 +1,9 @@
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ const datePattern = /^\d{4}-\d{2}-\d{2}$/;
4
+ export function createDiaryReader(diaryDir) {
5
+ const dates = () => existsSync(diaryDir) ? readdirSync(diaryDir).filter(name => /^\d{4}-\d{2}-\d{2}\.md$/.test(name)).map(name => name.slice(0, 10)).sort().reverse() : [];
6
+ /** Only YYYY-MM-DD names are accepted, so a date can never escape the diary directory. */
7
+ const read = (date) => { const file = join(diaryDir, `${date}.md`); return datePattern.test(date) && existsSync(file) ? readFileSync(file, 'utf8') : undefined; };
8
+ return { dates, read };
9
+ }
@@ -0,0 +1,19 @@
1
+ import type { Alarm } from './types.ts';
2
+ /** A home turn that stops more than this before her own alarm stopped early. */
3
+ export declare const EARLY_STOP_MS: number;
4
+ /**
5
+ * Decides when a home turn that ends counts as her stopping early: a completed turn, well before her own
6
+ * alarm, not yet asked about for that alarm. A turn in which her partner spoke is a conversation pausing,
7
+ * and a turn the plugin started itself (the question, a new home's greeting) is never asked about, so nothing loops.
8
+ */
9
+ export declare function createEarlyStopWatch(): {
10
+ partnerSpoke(): void;
11
+ /** Ends the turn's marks; true when this ending should be asked about. */
12
+ turnEnded(completed: boolean, alarm: Alarm | undefined, now: Date): alarm is Alarm & {
13
+ source: "plan";
14
+ };
15
+ /** The plugin is starting a turn of its own; that turn is not asked about. */
16
+ startsOwnTurn(): void;
17
+ /** Its message never arrived, so no turn of its own will follow. */
18
+ ownTurnFailed(): void;
19
+ };
@@ -0,0 +1,25 @@
1
+ /** A home turn that stops more than this before her own alarm stopped early. */
2
+ export const EARLY_STOP_MS = 5 * 60_000;
3
+ /**
4
+ * Decides when a home turn that ends counts as her stopping early: a completed turn, well before her own
5
+ * alarm, not yet asked about for that alarm. A turn in which her partner spoke is a conversation pausing,
6
+ * and a turn the plugin started itself (the question, a new home's greeting) is never asked about, so nothing loops.
7
+ */
8
+ export function createEarlyStopWatch() {
9
+ let partnerSpoke = false;
10
+ let ownTurn = false;
11
+ return {
12
+ partnerSpoke() { partnerSpoke = true; },
13
+ /** Ends the turn's marks; true when this ending should be asked about. */
14
+ turnEnded(completed, alarm, now) {
15
+ const quiet = completed && !partnerSpoke && !ownTurn;
16
+ partnerSpoke = false;
17
+ ownTurn = false;
18
+ return quiet && alarm?.source === 'plan' && !alarm.nudged && Date.parse(alarm.at) - now.getTime() > EARLY_STOP_MS;
19
+ },
20
+ /** The plugin is starting a turn of its own; that turn is not asked about. */
21
+ startsOwnTurn() { ownTurn = true; },
22
+ /** Its message never arrived, so no turn of its own will follow. */
23
+ ownTurnFailed() { ownTurn = false; },
24
+ };
25
+ }
@@ -0,0 +1,34 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ import { type Faults } from '../faults.ts';
3
+ import type { LifeHost } from './host.ts';
4
+ export interface HomeDeps {
5
+ host: LifeHost;
6
+ roomDir: string;
7
+ agentPreset: string;
8
+ title: string;
9
+ /** The title of her room as a workspace. */
10
+ roomTitle: string;
11
+ faults: Faults;
12
+ logger: {
13
+ error(...args: unknown[]): void;
14
+ };
15
+ /** The recorded home, if any. */
16
+ current(): string | undefined;
17
+ /** Records a newly built home before anything else can fail, so a retry reuses it instead of building another. */
18
+ moveIn(sessionId: string): void;
19
+ /** Called with the home every time it is opened. */
20
+ opened(agent: Agent): void;
21
+ stopped(): boolean;
22
+ }
23
+ /**
24
+ * Her home session: the recorded one while it exists and is not archived, otherwise a new one. Full access is
25
+ * granted on every open (selecting the preset in effect is a no-op), so no "still needs access" state has to
26
+ * survive a restart. Her room is a workspace of the host, so the home is listed under it rather than as
27
+ * ungrouped, and new sessions can be opened in the room; a host without workspaces just gets the cwd. The title is applied when the home is built and again after its first turn, because the
28
+ * host retitles a session from its first prompt.
29
+ */
30
+ export declare function createHome(deps: HomeDeps): {
31
+ /** The current home, resolving or rebuilding it; one attempt at a time. */
32
+ open(): Promise<Agent>;
33
+ turnEnded(sessionId: string): void;
34
+ };
@@ -0,0 +1,91 @@
1
+ import { mkdirSync } from 'node:fs';
2
+ import { errorText } from "../faults.js";
3
+ /**
4
+ * Her home session: the recorded one while it exists and is not archived, otherwise a new one. Full access is
5
+ * granted on every open (selecting the preset in effect is a no-op), so no "still needs access" state has to
6
+ * survive a restart. Her room is a workspace of the host, so the home is listed under it rather than as
7
+ * ungrouped, and new sessions can be opened in the room; a host without workspaces just gets the cwd. The title is applied when the home is built and again after its first turn, because the
8
+ * host retitles a session from its first prompt.
9
+ */
10
+ export function createHome(deps) {
11
+ const { host, faults } = deps;
12
+ let opening;
13
+ /** A new home whose title is not applied yet; retried on the next open. */
14
+ let untitled;
15
+ /** A new home before its first turn ends. */
16
+ let firstTurn;
17
+ async function rename(sessionId) {
18
+ try {
19
+ await host.rename(sessionId, deps.title);
20
+ faults.clear('rename');
21
+ return true;
22
+ }
23
+ catch (error) {
24
+ faults.set('rename', `家改名失败:${errorText(error)}`);
25
+ deps.logger.error(error);
26
+ return false;
27
+ }
28
+ }
29
+ async function ready(agent) {
30
+ host.setFullAccess(agent.session);
31
+ if (untitled === agent.id && await rename(agent.id) && untitled === agent.id)
32
+ untitled = undefined;
33
+ deps.opened(agent);
34
+ return agent;
35
+ }
36
+ /** Her room as a workspace; a failure is a fault and the home still opens, ungrouped. */
37
+ async function room() {
38
+ mkdirSync(deps.roomDir, { recursive: true });
39
+ try {
40
+ const workspace = await host.workspace(deps.roomDir, deps.roomTitle);
41
+ faults.clear('room');
42
+ return workspace;
43
+ }
44
+ catch (error) {
45
+ faults.set('room', `房间没能成为工作区:${errorText(error)}`);
46
+ deps.logger.error(error);
47
+ return undefined;
48
+ }
49
+ }
50
+ async function build() {
51
+ const workspace = await room();
52
+ const current = deps.current();
53
+ if (current && !host.isArchived(current)) {
54
+ const agent = await host.resolveAgent(current);
55
+ if (agent) {
56
+ // A home built before her room was a workspace moves in.
57
+ if (workspace && !workspace.sessionIds.includes(agent.id)) {
58
+ try {
59
+ await workspace.attachSession(agent.id);
60
+ }
61
+ catch (error) {
62
+ faults.set('room', `家没能挂进房间:${errorText(error)}`);
63
+ deps.logger.error(error);
64
+ }
65
+ }
66
+ return ready(agent);
67
+ }
68
+ }
69
+ const sessionId = await host.createSession(deps.roomDir, deps.agentPreset, workspace?.id);
70
+ if (deps.stopped())
71
+ throw new Error('生活线已停止');
72
+ untitled = sessionId;
73
+ firstTurn = sessionId;
74
+ deps.moveIn(sessionId);
75
+ const agent = await host.resolveAgent(sessionId);
76
+ if (!agent)
77
+ throw new Error(`dsh-world: the new home ${sessionId} cannot be resolved`);
78
+ return ready(agent);
79
+ }
80
+ return {
81
+ /** The current home, resolving or rebuilding it; one attempt at a time. */
82
+ open() { return opening ??= build().finally(() => { opening = undefined; }); },
83
+ turnEnded(sessionId) {
84
+ if (firstTurn !== sessionId || deps.stopped())
85
+ return;
86
+ firstTurn = undefined;
87
+ void rename(sessionId).then(ok => { if (!ok && deps.current() === sessionId)
88
+ untitled = sessionId; });
89
+ },
90
+ };
91
+ }
@@ -0,0 +1,22 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
3
+ import type { Session } from '@deepseek-ai/dsh-session';
4
+ /** A workspace of the host: a directory that groups its sessions in the sidebar and opens new ones there. */
5
+ export interface HostWorkspace {
6
+ id: string;
7
+ sessionIds: readonly string[];
8
+ attachSession(sessionId: string): Promise<void>;
9
+ }
10
+ export interface LifeHost {
11
+ /** In `workspaceId` when given (its directory is the cwd), otherwise in `cwd`. */
12
+ createSession(cwd: string, agentPreset: string, workspaceId?: string): Promise<string>;
13
+ /** The workspace owning `path`, registered under `title` if none does; undefined when the host keeps no workspaces. */
14
+ workspace(path: string, title: string): Promise<HostWorkspace | undefined>;
15
+ /** The live or resumed Agent, or `undefined` when the session no longer exists; other failures throw. */
16
+ resolveAgent(sessionId: string): Promise<Agent | undefined>;
17
+ isArchived(sessionId: string): boolean;
18
+ setFullAccess(session: Session): void;
19
+ rename(sessionId: string, title: string): Promise<void>;
20
+ origin(): string;
21
+ }
22
+ export declare function hostLife(ctx: Context): LifeHost;
@@ -0,0 +1,24 @@
1
+ export function hostLife(ctx) {
2
+ const host = ctx;
3
+ return {
4
+ createSession: async (cwd, agentPreset, workspaceId) => (await host.sessionController.create({ ...(workspaceId ? { workspaceId } : { cwd }), agentPreset })).sessionId,
5
+ // Optional like isArchived; `create` returns the existing workspace of a directory without retitling it.
6
+ workspace: async (path, title) => {
7
+ const registry = ctx.get('workspaceRegistry');
8
+ return registry?.create ? registry.create(path, title) : undefined;
9
+ },
10
+ async resolveAgent(sessionId) {
11
+ const found = await host.sessionController.resolveAgent(sessionId);
12
+ if ('agent' in found)
13
+ return found.agent;
14
+ if (found.error.code === 'session/not-found')
15
+ return undefined;
16
+ throw new Error(`dsh-world: home ${sessionId} cannot be resolved: ${found.error.message}`);
17
+ },
18
+ // Optional, so read without injecting it: Cordis throws on an un-injected property access.
19
+ isArchived: sessionId => Array.from(ctx.get('workspaceRegistry')?.archivedSessionIds ?? []).includes(sessionId),
20
+ setFullAccess: session => host.permissionPresets.set(session, 'danger-full-access'),
21
+ rename: async (sessionId, title) => { await host.sessionController.rename({ sessionId, title }); },
22
+ origin: () => host.webServer.getOrigin(),
23
+ };
24
+ }
@@ -0,0 +1,20 @@
1
+ import type { Session, SessionEvent } from '@deepseek-ai/dsh-session';
2
+ import { type Faults } from '../faults.ts';
3
+ import type { LifeStore } from './lifeStore.ts';
4
+ /**
5
+ * What the console shows of her life: every tool call in her home, logged once its result is known, and every
6
+ * compaction in her world sessions.
7
+ */
8
+ export declare function createJournal(deps: {
9
+ store: LifeStore;
10
+ faults: Faults;
11
+ roomDir: string;
12
+ logger: {
13
+ error(...args: unknown[]): void;
14
+ };
15
+ }): {
16
+ /** Any world session: compactions. */
17
+ world(session: Session, event: SessionEvent): void;
18
+ /** Her home: tool calls, logged at their result; one that never got a result (cancelled, crashed) is logged when the turn ends. */
19
+ home(session: Session, event: SessionEvent): void;
20
+ };
@@ -0,0 +1,59 @@
1
+ import { errorText } from "../faults.js";
2
+ import { summarizeCall } from "./activity.js";
3
+ /**
4
+ * What the console shows of her life: every tool call in her home, logged once its result is known, and every
5
+ * compaction in her world sessions.
6
+ */
7
+ export function createJournal(deps) {
8
+ const { store, faults } = deps;
9
+ const calls = new Map();
10
+ const shadowed = new Map();
11
+ function logCall(callId, call, status) {
12
+ const { summary, outside } = summarizeCall(call.name, call.arguments, deps.roomDir);
13
+ if (store.appendActivity({ time: call.time, sessionId: call.sessionId, callId, tool: call.name, summary, outside, ...(status ? { status } : {}) }))
14
+ faults.clear('activity');
15
+ else {
16
+ faults.set('activity', '活动记录写入失败,下一条会标记缺口');
17
+ deps.logger.error('dsh-world: activity log write failed');
18
+ }
19
+ }
20
+ return {
21
+ /** Any world session: compactions. */
22
+ world(session, event) {
23
+ if (event.type === 'compaction/summary')
24
+ shadowed.set(event.data.compactionId, event.data.shadowedTokenCount);
25
+ if (event.type !== 'compaction/end')
26
+ return;
27
+ const tokens = shadowed.get(event.data.compactionId);
28
+ shadowed.delete(event.data.compactionId);
29
+ const { error } = event.data;
30
+ try {
31
+ store.appendCompaction({ time: new Date(event.time).toISOString(), sessionId: session.id, ok: error === undefined, ...(tokens === undefined ? {} : { shadowedTokens: tokens }), ...(error === undefined ? {} : { error }) });
32
+ faults.clear('compaction');
33
+ }
34
+ catch (cause) {
35
+ faults.set('compaction', `压缩记录写入失败:${errorText(cause)}`);
36
+ deps.logger.error(cause);
37
+ }
38
+ },
39
+ /** Her home: tool calls, logged at their result; one that never got a result (cancelled, crashed) is logged when the turn ends. */
40
+ home(session, event) {
41
+ if (event.type === 'tool/call')
42
+ calls.set(event.data.callId, { sessionId: session.id, name: event.data.name, arguments: event.data.arguments, time: new Date(event.time).toISOString() });
43
+ if (event.type === 'tool/result') {
44
+ const callId = event.data.message.toolCallId;
45
+ const call = calls.get(callId);
46
+ if (call) {
47
+ calls.delete(callId);
48
+ logCall(callId, call, event.data.message.isError ? 'error' : 'ok');
49
+ }
50
+ }
51
+ if (event.type === 'turn/end')
52
+ for (const [callId, call] of calls)
53
+ if (call.sessionId === session.id) {
54
+ calls.delete(callId);
55
+ logCall(callId, call);
56
+ }
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,16 @@
1
+ import type { ActivityRecord, CompactionRecord, LifeState, WakeRecord } from './types.ts';
2
+ /** Exported for tests only (injectable rename). On Windows a reader, indexer or antivirus can briefly lock the target, so a rename that fails with EPERM/EBUSY/EACCES is retried with a short backoff. */
3
+ export declare function durableWrite(file: string, text: string, rename?: (from: string, to: string) => void): void;
4
+ export declare function createLifeStore(worldDir: string, timeZone: string): {
5
+ read: () => LifeState;
6
+ write: (state: LifeState) => void;
7
+ appendWake: (record: WakeRecord) => void;
8
+ appendCompaction: (record: CompactionRecord) => void;
9
+ /** Never throws: a failed write is reported to the caller and marks the next record. The gap flag is in-memory and marks the next successful write, which may land in a later day's file. */
10
+ appendActivity(record: ActivityRecord): boolean;
11
+ wakes: () => WakeRecord[];
12
+ compactions: () => CompactionRecord[];
13
+ activity: (day: string) => ActivityRecord[];
14
+ activityDays: () => string[];
15
+ };
16
+ export type LifeStore = ReturnType<typeof createLifeStore>;
@@ -0,0 +1,105 @@
1
+ import { closeSync, existsSync, fstatSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { formatLocalTime } from "../timeContext.js";
4
+ const dayPattern = /^\d{4}-\d{2}-\d{2}$/;
5
+ const dayFile = /^\d{4}-\d{2}-\d{2}\.jsonl$/;
6
+ const renameAttempts = 10;
7
+ const transientRename = new Set(['EPERM', 'EBUSY', 'EACCES']);
8
+ function sleepSync(ms) { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); }
9
+ /** Exported for tests only (injectable rename). On Windows a reader, indexer or antivirus can briefly lock the target, so a rename that fails with EPERM/EBUSY/EACCES is retried with a short backoff. */
10
+ export function durableWrite(file, text, rename = renameSync) {
11
+ const temporary = `${file}.${process.pid}.tmp`;
12
+ try {
13
+ const fd = openSync(temporary, 'w');
14
+ try {
15
+ writeFileSync(fd, text);
16
+ fsyncSync(fd);
17
+ }
18
+ finally {
19
+ closeSync(fd);
20
+ }
21
+ for (let attempt = 1;; attempt++) {
22
+ try {
23
+ rename(temporary, file);
24
+ break;
25
+ }
26
+ catch (error) {
27
+ if (attempt >= renameAttempts || !transientRename.has(error.code ?? ''))
28
+ throw error;
29
+ sleepSync(Math.min(100, 10 * 2 ** (attempt - 1)));
30
+ }
31
+ }
32
+ }
33
+ catch (error) {
34
+ rmSync(temporary, { force: true });
35
+ throw error;
36
+ }
37
+ }
38
+ function append(file, value) {
39
+ const fd = openSync(file, 'a+');
40
+ try {
41
+ const size = fstatSync(fd).size;
42
+ const last = Buffer.alloc(1);
43
+ const torn = size > 0 && readSync(fd, last, 0, 1, size - 1) === 1 && last[0] !== 10;
44
+ writeFileSync(fd, `${torn ? '\n' : ''}${JSON.stringify(value)}\n`);
45
+ fsyncSync(fd);
46
+ }
47
+ finally {
48
+ closeSync(fd);
49
+ }
50
+ }
51
+ /** Skips unparsable or non-object lines (a half-written tail or a damaged line). */
52
+ function readJsonl(file) {
53
+ if (!existsSync(file))
54
+ return [];
55
+ return readFileSync(file, 'utf8').split('\n').filter(Boolean).flatMap(line => { try {
56
+ const value = JSON.parse(line);
57
+ return value && typeof value === 'object' ? [value] : [];
58
+ }
59
+ catch {
60
+ return [];
61
+ } });
62
+ }
63
+ export function createLifeStore(worldDir, timeZone) {
64
+ const stateFile = join(worldDir, 'life.json');
65
+ const lifeDir = join(worldDir, 'life');
66
+ const activityDir = join(worldDir, 'activity');
67
+ let activityGap = false;
68
+ mkdirSync(lifeDir, { recursive: true });
69
+ mkdirSync(activityDir, { recursive: true });
70
+ /** A life.json that is not JSON stops the life line (the console says why) and is left as it is. */
71
+ function read() {
72
+ if (!existsSync(stateFile))
73
+ return { version: 1 };
74
+ try {
75
+ return JSON.parse(readFileSync(stateFile, 'utf8'));
76
+ }
77
+ catch (error) {
78
+ throw new Error(`dsh-world: ${stateFile} is not valid JSON; it was left untouched`, { cause: error });
79
+ }
80
+ }
81
+ const localDay = (iso) => formatLocalTime(new Date(iso), timeZone).slice(0, 10);
82
+ return {
83
+ read,
84
+ write: (state) => durableWrite(stateFile, JSON.stringify(state, null, 2)),
85
+ appendWake: (record) => append(join(lifeDir, 'wakes.jsonl'), record),
86
+ appendCompaction: (record) => append(join(worldDir, 'compactions.jsonl'), record),
87
+ /** Never throws: a failed write is reported to the caller and marks the next record. The gap flag is in-memory and marks the next successful write, which may land in a later day's file. */
88
+ appendActivity(record) {
89
+ try {
90
+ mkdirSync(activityDir, { recursive: true });
91
+ append(join(activityDir, `${localDay(record.time)}.jsonl`), activityGap ? { ...record, gapBefore: true } : record);
92
+ activityGap = false;
93
+ return true;
94
+ }
95
+ catch {
96
+ activityGap = true;
97
+ return false;
98
+ }
99
+ },
100
+ wakes: () => readJsonl(join(lifeDir, 'wakes.jsonl')),
101
+ compactions: () => readJsonl(join(worldDir, 'compactions.jsonl')),
102
+ activity: (day) => dayPattern.test(day) ? readJsonl(join(activityDir, `${day}.jsonl`)) : [],
103
+ activityDays: () => existsSync(activityDir) ? readdirSync(activityDir).filter(name => dayFile.test(name)).map(name => name.slice(0, 10)).sort().reverse() : [],
104
+ };
105
+ }
@@ -0,0 +1,17 @@
1
+ /** The alarm wording shipped with the plugin; a world's own `alarm.md` replaces it section by section. */
2
+ export declare const DEFAULT_ALARM_FILE: string;
3
+ export declare const MESSAGE_KEYS: readonly ["第一次到家", "重新开始", "早上兜底", "闹钟响了", "晚到说明", "提前停下", "每日回顾", "额度用完", "结尾提醒", "plan_next 说明", "check_alarm 说明", "cancel_alarm 说明"];
4
+ export type MessageKey = typeof MESSAGE_KEYS[number];
5
+ /** Marks her own alarm messages (in her own voice); the compaction instruction relies on it, so a template cannot drop it. Before 0.5 it read 【你的时间】. */
6
+ export declare const ALARM_MARK = "\u3010\u6211\u7684\u65F6\u95F4\u3011";
7
+ /** `## name` sections; anything before the first heading (the explanatory comment) is ignored. */
8
+ export declare function parseSections(text: string): Map<string, string>;
9
+ export interface AlarmMessages {
10
+ sections: Record<MessageKey, string>;
11
+ error?: string;
12
+ }
13
+ /** Never throws: an unreadable world file falls back to the shipped wording and says why. Missing sections use the shipped ones. */
14
+ export declare function readAlarmMessages(file: string | undefined): AlarmMessages;
15
+ export declare function fillMessage(messages: AlarmMessages, key: MessageKey, values: Record<string, string>, flags?: Record<string, boolean>): string;
16
+ /** A fixed example time with the offset of the configured zone, so the description never changes between runs. */
17
+ export declare function exampleTime(timeZone: string): string;
@@ -0,0 +1,53 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { formatLocalTime } from "../timeContext.js";
4
+ import { renderTemplate } from "../worldPrompt.js";
5
+ /** The alarm wording shipped with the plugin; a world's own `alarm.md` replaces it section by section. */
6
+ export const DEFAULT_ALARM_FILE = fileURLToPath(new URL('../../templates/alarm.md', import.meta.url));
7
+ export const MESSAGE_KEYS = ['第一次到家', '重新开始', '早上兜底', '闹钟响了', '晚到说明', '提前停下', '每日回顾', '额度用完', '结尾提醒', 'plan_next 说明', 'check_alarm 说明', 'cancel_alarm 说明'];
8
+ /** Marks her own alarm messages (in her own voice); the compaction instruction relies on it, so a template cannot drop it. Before 0.5 it read 【你的时间】. */
9
+ export const ALARM_MARK = '【我的时间】';
10
+ /** `## name` sections; anything before the first heading (the explanatory comment) is ignored. */
11
+ export function parseSections(text) {
12
+ const sections = new Map();
13
+ let key;
14
+ let lines = [];
15
+ const close = () => { if (key !== undefined)
16
+ sections.set(key, lines.join('\n').trim()); };
17
+ for (const line of text.replace(/\r\n?/g, '\n').split('\n')) {
18
+ const heading = /^## (.+?)\s*$/.exec(line);
19
+ if (heading) {
20
+ close();
21
+ key = heading[1];
22
+ lines = [];
23
+ }
24
+ else if (key !== undefined)
25
+ lines.push(line);
26
+ }
27
+ close();
28
+ return sections;
29
+ }
30
+ /** Never throws: an unreadable world file falls back to the shipped wording and says why. Missing sections use the shipped ones. */
31
+ export function readAlarmMessages(file) {
32
+ const shipped = parseSections(readFileSync(DEFAULT_ALARM_FILE, 'utf8'));
33
+ let own = new Map();
34
+ let error;
35
+ if (file && existsSync(file)) {
36
+ try {
37
+ own = parseSections(readFileSync(file, 'utf8'));
38
+ }
39
+ catch (cause) {
40
+ error = `闹钟模板 ${file} 读不了,先用默认的:${cause instanceof Error ? cause.message : String(cause)}`;
41
+ }
42
+ }
43
+ const sections = Object.fromEntries(MESSAGE_KEYS.map(key => [key, own.get(key) ?? shipped.get(key) ?? '']));
44
+ return error ? { sections, error } : { sections };
45
+ }
46
+ export function fillMessage(messages, key, values, flags = {}) {
47
+ return renderTemplate(messages.sections[key], flags, values);
48
+ }
49
+ /** A fixed example time with the offset of the configured zone, so the description never changes between runs. */
50
+ export function exampleTime(timeZone) {
51
+ const offset = formatLocalTime(new Date('2026-10-23T12:00:00Z'), timeZone).slice(-6);
52
+ return `2026-10-23T21:00:00${offset}`;
53
+ }
@@ -0,0 +1,15 @@
1
+ import { spawn } from 'node:child_process';
2
+ import type { Outlet } from '../ecosystem/shared/outlets.ts';
3
+ /** reach_out's channels: the system notification where there is one, then every outlet that takes `reach`. */
4
+ export interface Notifier {
5
+ toast?(title: string, body: string): Promise<void>;
6
+ outlets: readonly Outlet[];
7
+ }
8
+ /** System notifications exist on Windows only (WinRT through PowerShell); elsewhere the channel is simply absent. */
9
+ export declare const toastSupported: () => boolean;
10
+ /**
11
+ * The host runs as plain Node (no Electron Notification), so toasts go through WinRT from PowerShell.
12
+ * PowerShell treats U+2018/2019/201A/201B as single quotes, so no text is ever interpolated: it travels as base64.
13
+ */
14
+ export declare function toastScript(appId: string, title: string, body: string): string;
15
+ export declare function windowsToast(appId?: string, spawnImpl?: typeof spawn, timeoutMs?: number): (title: string, body: string) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { spawn } from 'node:child_process';
2
+ /** System notifications exist on Windows only (WinRT through PowerShell); elsewhere the channel is simply absent. */
3
+ export const toastSupported = () => process.platform === 'win32';
4
+ const xmlEscapes = { '<': '&lt;', '>': '&gt;', '&': '&amp;', "'": '&apos;', '"': '&quot;' };
5
+ const xml = (text) => text.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, '').replace(/[<>&'"]/g, char => xmlEscapes[char]);
6
+ const cap = (text, max) => { const chars = [...text]; return chars.length > max ? `${chars.slice(0, max).join('')}…` : text; };
7
+ const b64 = (text) => Buffer.from(text, 'utf8').toString('base64');
8
+ /**
9
+ * The host runs as plain Node (no Electron Notification), so toasts go through WinRT from PowerShell.
10
+ * PowerShell treats U+2018/2019/201A/201B as single quotes, so no text is ever interpolated: it travels as base64.
11
+ */
12
+ export function toastScript(appId, title, body) {
13
+ const payload = `<toast><visual><binding template="ToastGeneric"><text>${xml(cap(title, 64))}</text><text>${xml(cap(body, 500))}</text></binding></visual></toast>`;
14
+ const decode = (text) => `[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64(text)}'))`;
15
+ return [
16
+ "$ErrorActionPreference = 'Stop'; [Console]::OutputEncoding = [Text.Encoding]::UTF8",
17
+ 'try {',
18
+ '$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]',
19
+ '$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]',
20
+ `$appId = ${decode(appId)}`,
21
+ '$xml = New-Object Windows.Data.Xml.Dom.XmlDocument',
22
+ `$xml.LoadXml(${decode(payload)})`,
23
+ '[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($appId).Show([Windows.UI.Notifications.ToastNotification]::new($xml))',
24
+ '} catch { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }',
25
+ ].join('\n');
26
+ }
27
+ export function windowsToast(appId = 'electron.app.DeepSeek Harness', spawnImpl = spawn, timeoutMs = 10_000) {
28
+ return (title, body) => new Promise((resolvePromise, reject) => {
29
+ const encoded = Buffer.from(toastScript(appId, title, body), 'utf16le').toString('base64');
30
+ const child = spawnImpl('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], { windowsHide: true, stdio: ['ignore', 'ignore', 'pipe'] });
31
+ let stderr = '';
32
+ let settled = false;
33
+ const settle = (error) => { if (settled)
34
+ return; settled = true; clearTimeout(timer); error ? reject(error) : resolvePromise(); };
35
+ const timer = setTimeout(() => { child.kill(); settle(new Error('系统通知超时(10 秒)')); }, timeoutMs);
36
+ child.stderr.on('data', chunk => { stderr += String(chunk); });
37
+ child.on('error', error => settle(error));
38
+ child.on('close', code => settle(code === 0 ? undefined : new Error(`powershell 退出码 ${code}:${stderr.trim().slice(0, 200)}`)));
39
+ });
40
+ }
@@ -0,0 +1,4 @@
1
+ import type { TokenUsage } from '@deepseek-ai/dsh-llm';
2
+ export declare function isPeak(at: Date): boolean;
3
+ /** What one model step cost in CNY. DeepSeek reports cache hits apart from the other input; reasoning is part of the output. */
4
+ export declare function stepCost(usage: TokenUsage, model: string, at: Date): number;