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,32 @@
1
+ /**
2
+ * storyboard/register.js — 视频识别那四个工具的注册入口(storyboard / zoom / probe / locate)。
3
+ *
4
+ * 四件套都在这一个目录里:schema 在 `./tool-spec.js`,handler 在 `../tools/`,注册在这里。
5
+ * 陪看(`watch_together`)曾经和这里对称,现在是另一个包 `dsh-watch-together`。
6
+ *
7
+ * 为什么 handler 没跟着搬进 `storyboard/`:那四个 handler 加起来 154 行,且都被
8
+ * `test/schema-audit.test.mjs` 按 `src/tools/*.js` 扫;搬家的收益只是好看,
9
+ * 而陪看的 handler 必须搬是因为它要跟插件一起走。**该拆的拆,不该拆的不动。**
10
+ */
11
+
12
+ import {
13
+ locateToolSpec, probeToolSpec, storyboardToolSpec, zoomToolSpec,
14
+ } from './tool-spec.js';
15
+ import * as locate from '../tools/locate.js';
16
+ import * as probe from '../tools/probe.js';
17
+ import * as storyboard from '../tools/storyboard.js';
18
+ import * as zoom from '../tools/zoom.js';
19
+
20
+ /**
21
+ * @param {(spec: object) => object} defineTool 宿主的 defineTool
22
+ * @param {object} ctx 宿主上下文(存图用)
23
+ * @returns {object[]} 已经 `defineTool()` 好的工具
24
+ */
25
+ export function storyboardTools(defineTool, ctx) {
26
+ return [
27
+ defineTool({ ...storyboardToolSpec(), execute: (args) => storyboard.execute(ctx, args) }),
28
+ defineTool({ ...zoomToolSpec(), execute: (args) => zoom.execute(ctx, args) }),
29
+ defineTool({ ...probeToolSpec(), execute: (args) => probe.execute(ctx, args) }),
30
+ defineTool({ ...locateToolSpec(), execute: (args) => locate.execute(ctx, args) }),
31
+ ];
32
+ }
@@ -0,0 +1,486 @@
1
+ /**
2
+ * scan.js — HSV 加权镜头切分(PySceneDetect ContentDetector 思路的独立实现)。
3
+ *
4
+ * 为什么不用 `ffmpeg scdet`:它算的是 MAFD(亮度类),对"同亮度换色"失明。
5
+ * 实测同一段测试片:scdet 默认阈值召回 4/9,本实现 9/9,零误检。
6
+ *
7
+ * 做法:ffmpeg 把画面缩到 64×36 rawvideo 喂进来(2304 像素/帧,解码量极小),
8
+ * 逐像素转 HSV,与上一帧求三通道绝对差均值,得到 0–255 的分数。
9
+ */
10
+
11
+ import { spawn } from 'node:child_process';
12
+
13
+ import { DEFAULT_FFMPEG } from './probe.js';
14
+ import { describeMediaSearch } from './binaries.js';
15
+
16
+ export const SCAN_W = 64;
17
+ export const SCAN_H = 36;
18
+ /** 指纹尺寸(供 flash.js 判闪光):16×9 = 144 字节/帧,60 分钟片子约 13 MB */
19
+ export const FP_W = 16;
20
+ export const FP_H = 9;
21
+ export const DEFAULT_THRESHOLD = 15;
22
+ export const HUE_WEIGHT = 1;
23
+ export const SAT_WEIGHT = 1;
24
+ export const VAL_WEIGHT = 1;
25
+
26
+ /** RGB(0-255) → HSV,各通道归一到 0-255(H 由角度缩放到 0-255) */
27
+ export function rgbToHsv(r, g, b) {
28
+ const rn = r / 255;
29
+ const gn = g / 255;
30
+ const bn = b / 255;
31
+ const max = Math.max(rn, gn, bn);
32
+ const min = Math.min(rn, gn, bn);
33
+ const d = max - min;
34
+ let h = 0;
35
+ if (d !== 0) {
36
+ if (max === rn) h = ((gn - bn) / d) % 6;
37
+ else if (max === gn) h = (bn - rn) / d + 2;
38
+ else h = (rn - gn) / d + 4;
39
+ h *= 60;
40
+ if (h < 0) h += 360;
41
+ }
42
+ return [(h / 360) * 255, (max === 0 ? 0 : d / max) * 255, max * 255];
43
+ }
44
+
45
+ /**
46
+ * 把整帧 RGB 缓冲转成 HSV 缓冲。out 可复用,避免每帧分配。
47
+ * @param {Uint8Array|Buffer} rgb 长度 = pixels*3
48
+ * @param {Float32Array} [out] 长度 = pixels*3
49
+ */
50
+ export function frameToHsv(rgb, out = new Float32Array((rgb.length / 3) * 3)) {
51
+ for (let i = 0, j = 0; i < rgb.length; i += 3, j += 3) {
52
+ const rn = rgb[i] / 255;
53
+ const gn = rgb[i + 1] / 255;
54
+ const bn = rgb[i + 2] / 255;
55
+ const max = rn > gn ? (rn > bn ? rn : bn) : gn > bn ? gn : bn;
56
+ const min = rn < gn ? (rn < bn ? rn : bn) : gn < bn ? gn : bn;
57
+ const d = max - min;
58
+ let h = 0;
59
+ if (d !== 0) {
60
+ if (max === rn) h = ((gn - bn) / d) % 6;
61
+ else if (max === gn) h = (bn - rn) / d + 2;
62
+ else h = (rn - gn) / d + 4;
63
+ h *= 60;
64
+ if (h < 0) h += 360;
65
+ }
66
+ out[j] = (h / 360) * 255;
67
+ out[j + 1] = max === 0 ? 0 : (d / max) * 255;
68
+ out[j + 2] = max * 255;
69
+ }
70
+ return out;
71
+ }
72
+
73
+ /** 两帧 HSV 的加权绝对差均值,0–255。全权重大于 1 时按权重和归一。 */
74
+ export function scorePair(prev, cur) {
75
+ if (prev.length !== cur.length) throw new RangeError('frames must have the same length');
76
+ let sum = 0;
77
+ for (let i = 0; i < cur.length; i += 3) {
78
+ // 色相是**环形**的:0° 和 359° 只差 1°,但直接相减会算成 359。
79
+ // 不做这一步,红色渐变到品红(跨越 0°)会被判成一次巨大的"画面变化",
80
+ // 于是夜景霓虹、日落、色轮转场这些地方会凭空多出切点。
81
+ const dh = Math.abs(cur[i] - prev[i]);
82
+ const hueDiff = Math.min(dh, 255 - dh);
83
+ // 低饱和像素的色相没有意义:近灰的色相会被编码噪声甩到色环另一端。
84
+ // 实测 rgb(128,128,127) → rgb(128,127,128)(肉眼完全一样)色相差 85、整帧分数 28,
85
+ // 而常用阈值只有 12–58 —— 于是"画面没变"被记成一次切镜。
86
+ // 用两帧中较低的那个饱和度给色相项降权:灰的地方色相说了不算,亮色地方照常。
87
+ const hueWeight = Math.min(cur[i + 1], prev[i + 1]) / 255;
88
+ sum += hueDiff * hueWeight * HUE_WEIGHT
89
+ + Math.abs(cur[i + 1] - prev[i + 1]) * SAT_WEIGHT
90
+ + Math.abs(cur[i + 2] - prev[i + 2]) * VAL_WEIGHT;
91
+ }
92
+ const totalWeight = HUE_WEIGHT + SAT_WEIGHT + VAL_WEIGHT;
93
+ return sum / ((cur.length / 3) * totalWeight);
94
+ }
95
+
96
+ /**
97
+ * 按"相对本地基线"找切点:分数(= 相邻两帧的画面变化百分比)突然**比它附近的常态高很多**才算一刀。
98
+ *
99
+ * 为什么需要它:固定阈值对两种内容无解 ——
100
+ * - PPT/网课:平时变化 0.6,换页瞬间 40。固定阈值 15 能抓到换页,但"只多出一个要点"这种
101
+ * 小改动只有 5,被阈值挡掉;而 5 其实是基线(0.6)的 8 倍。
102
+ * - 匀速运镜/长镜头:每帧都在变,基线本身就有 20,固定阈值要么全放过要么全挡掉;
103
+ * 真要在这段里找剪辑,只能看"比这段自己的常态高多少"。
104
+ *
105
+ * 所以判据从"分数 > 15"改成"分数 > max(绝对下限, k × 本地中位数)"。
106
+ * 返回的每一刀都带 ratio(相对基线的倍数),可以用来说明"这一刀有多确信"。
107
+ *
108
+ * @param {Array<{t:number, score:number}>} stats 逐帧分数
109
+ * @param {{k?:number, minAbs?:number, halfWindow?:number}} opts
110
+ * @returns {Array<{t:number, score:number, ratio:number}>}
111
+ */
112
+ export function spikeCuts(stats, { k = 3, minAbs = 6, halfWindow = 15 } = {}) {
113
+ if (!Array.isArray(stats) || stats.length < 3) return [];
114
+ const scores = stats.map((s) => s.score);
115
+ const sorted = [...scores].sort((a, b) => a - b);
116
+ const q = (p) => sorted[Math.min(sorted.length - 1, Math.max(0, Math.floor(sorted.length * p)))];
117
+ // 基线取"本地中位数"和"全片中位数"里更小的那个:本地安静就用本地,
118
+ // 本地本来就很吵(运镜)就退回全片,避免把运镜的常态当成基线而漏掉真正的剪切。
119
+ const global = q(0.5);
120
+ const out = [];
121
+ for (let i = 0; i < stats.length; i++) {
122
+ const lo = Math.max(0, i - halfWindow);
123
+ const hi = Math.min(stats.length, i + halfWindow + 1);
124
+ // 旧写法 `slice(lo,hi).slice(0,i-lo).concat(slice(i-lo+1, hi-lo))` 在 lo > 0 时
125
+ // 会取到**全数组**的 16..30 号元素(而不是 63..hi 的邻居),于是 i 这一刀被漏掉。
126
+ const around = scores.slice(lo, i).concat(scores.slice(i + 1, hi));
127
+ const local = around.length ? around.sort((a, b) => a - b)[Math.floor(around.length / 2)] : global;
128
+ const base = Math.max(0.2, Math.min(local, global));
129
+ const need = Math.max(minAbs, base * k);
130
+ if (scores[i] > need) {
131
+ out.push({ ...stats[i], ratio: +(scores[i] / base).toFixed(1) });
132
+ }
133
+ }
134
+ return out;
135
+ }
136
+
137
+ /** 抑制过密切点:同窗口内只保留分数最高的那个 */
138
+ export function suppressClose(cuts, minGap = 0.35) {
139
+ const sorted = [...cuts].sort((a, b) => a.t - b.t);
140
+ const kept = [];
141
+ for (const cut of sorted) {
142
+ const last = kept[kept.length - 1];
143
+ if (last && cut.t - last.t < minGap) {
144
+ if (cut.score > last.score) kept[kept.length - 1] = cut;
145
+ } else {
146
+ kept.push(cut);
147
+ }
148
+ }
149
+ return kept;
150
+ }
151
+
152
+ /**
153
+ * 自适应阈值:按"每秒大约多少个切点"反推,而不是按分数倍数。
154
+ *
155
+ * 为什么换掉"3×p95"(用 6 条真实视频打脸过):
156
+ * - B-roll 类(p95=12.8)→ 3×=38 → 88 切点,OK
157
+ * - 快剪动画 PV(p90=26、p95=43)→ 3×=130 → **0 个切点**
158
+ * - 另一支 92s 的 PV(p95=32)→ 3×=96 → 14 个切点
159
+ * 分数倍数在"切点极密"的素材上会把阈值推到切点带里面去。而这类素材恰恰是
160
+ * 每个画面都不一样,倍数法必崩。
161
+ *
162
+ * 换成速率法后:目标约 1 个切点 / minGap 秒,再用 floor 兜住"整片不动"的素材
163
+ * (一支 251s 的静态单镜头素材,p95=2.5,速率法会给出分数 3 的阈值 → floor 12 把它拉回来,切点 0)。
164
+ *
165
+ * @param {number[]} scores 逐帧分数
166
+ * @param {{duration?:number, minGap?:number, floor?:number}} opts
167
+ */
168
+ export function autoThreshold(scores, { duration, minGap, floor = 12 } = {}) {
169
+ if (!Array.isArray(scores) || scores.length === 0) return floor;
170
+ const sorted = [...scores].sort((a, b) => a - b);
171
+ const n = sorted.length;
172
+ const total = duration > 0 ? duration : n / 25;
173
+ // 短片要有更细的粒度:5s 的片子按 1.5s 一个切点只剩 3 个名额,会砍掉真实的快切
174
+ const gap = typeof minGap === 'number' ? minGap : Math.min(1.5, Math.max(0.5, total / 60));
175
+ const target = Math.max(1, Math.min(n * 0.25, total / gap)); // 上限 25% 的帧
176
+ const idx = Math.max(0, Math.min(n - 1, Math.floor(n - target)));
177
+ // 取整朝下:宁可多报一个切点(后续会合并),也不要因为四舍五入丢掉真切镜
178
+ return Math.max(floor, Math.floor(sorted[idx]));
179
+ }
180
+
181
+ /** 分数分布的摘要,供 suggest() 判断"内容有多密" */
182
+ /**
183
+ * 从逐帧分数里"判定切点"。纯函数:同一份 stats 可以反复用不同参数重判,不需要再读一次视频。
184
+ *
185
+ * 这就是"细扫"真正需要的东西 —— 粗扫已经把每一帧的分数算完了(stats 全量保留),
186
+ * 重新判定只是换一组阈值/间隔,零 IO。
187
+ *
188
+ * @param {Array<{t:number, score:number}>} stats 逐帧分数
189
+ * @param {{threshold?:number|'auto'|'auto-low', minGap?:number, duration?:number}} opts
190
+ */
191
+ export function decideCuts(stats, { threshold = 'auto', minGap = 0.35, duration } = {}) {
192
+ const scores = stats.map((s) => s.score);
193
+ const used = threshold === 'auto'
194
+ ? autoThreshold(scores, { duration })
195
+ : threshold === 'auto-low'
196
+ ? Math.max(4, quantile(scores, 0.10))
197
+ : threshold;
198
+ const eps = 1e-6;
199
+ const above = stats.filter((s) => s.score > used + eps);
200
+ // 上限只对 auto 生效:显式阈值是调用方的明确意图
201
+ const cap = threshold === 'auto' ? autoThreshold(scores, { duration }).target : Infinity;
202
+ const picked = Number.isFinite(cap) && cap > 0 && above.length > cap
203
+ ? [...above].sort((a, b) => b.score - a.score).slice(0, cap).sort((a, b) => a.t - b.t)
204
+ : above;
205
+ const cuts = suppressClose(picked.map((s) => ({ ...s })), minGap);
206
+ const hotRatio = stats.length > 0 ? above.length / stats.length : 0;
207
+ // 分数序列的变异系数:区分"每帧一剪"和"匀速运镜"
208
+ const mean = scores.length ? scores.reduce((a, b) => a + b, 0) / scores.length : 0;
209
+ const scoreCv = mean > 0
210
+ ? Math.sqrt(scores.reduce((a, b) => a + (b - mean) ** 2, 0) / scores.length) / mean
211
+ : 0;
212
+ return {
213
+ cuts,
214
+ threshold: used,
215
+ degraded: assessDegraded({ span: duration, cuts: cuts.length, hotRatio, scoreCv, scoreMean: mean }),
216
+ };
217
+ }
218
+
219
+ /**
220
+ * 切点计数是不是不可信?连续运镜会被逐帧切成"切点",于是 cuts=N 变成一个没有节奏含义的数字。
221
+ *
222
+ * 判据:中位镜头 < 0.5 秒,且超过 30% 的帧都在阈值之上 —— 真正的剪辑不会这样,
223
+ * 只有匀速运镜/甩镜/手持抖动会。
224
+ *
225
+ * @returns {'motion'|null}
226
+ */
227
+ export function assessDegraded({ span, cuts, hotRatio, scoreCv, scoreMean }) {
228
+ if (!(span > 0) || !(cuts > 0)) return null;
229
+ const medianShot = span / cuts;
230
+ if (medianShot >= 0.5 || hotRatio <= 0.3) return null;
231
+ // **关键补充**:每帧一剪的素材也会"刀数极密 + 高分帧极多",和运镜长得一模一样。
232
+ // 区别在分数序列的平滑度:运镜每帧只变一点点(变异系数很低),
233
+ // 而每帧一剪是"这一刀变 80、下一刀变 20"(变异系数高)。
234
+ // 只有"整窗分数都很高"(每帧都在大改)才可能是每帧一剪;
235
+ // 低均值 + 高变异系数只是"偶尔来一下",那是真正的运镜素材,仍然判 motion。
236
+ if (typeof scoreCv === 'number' && scoreCv >= 0.4 && (scoreMean ?? 0) >= 30) return null;
237
+ return 'motion';
238
+ }
239
+
240
+ /** 取分位(0..1)。用于"这片就是很快"时的低阈值:按片中自己的分数分布定,而不是全局倍数。 */
241
+ export function quantile(scores, q) {
242
+ if (!Array.isArray(scores) || scores.length === 0) return 0;
243
+ const s = [...scores].sort((a, b) => a - b);
244
+ const i = Math.min(s.length - 1, Math.max(0, Math.floor(s.length * q)));
245
+ return s[i];
246
+ }
247
+
248
+ export function scanSummary(scores) {
249
+ if (!Array.isArray(scores) || scores.length === 0) {
250
+ return { p50: 0, p90: 0, p95: 0, p99: 0, max: 0, frames: 0 };
251
+ }
252
+ const s = [...scores].sort((a, b) => a - b);
253
+ const q = (p) => s[Math.min(s.length - 1, Math.floor(s.length * p))];
254
+ return {
255
+ p50: +q(0.5).toFixed(2), p90: +q(0.9).toFixed(2), p95: +q(0.95).toFixed(2),
256
+ p99: +q(0.99).toFixed(2), max: +s[s.length - 1].toFixed(2), frames: s.length,
257
+ };
258
+ }
259
+
260
+ /**
261
+ * 扫描整条视频,返回切点与逐帧分数。
262
+ * @param {{input:string, fps:number, ffmpegPath?:string, width?:number, height?:number,
263
+ * threshold?:number|'auto', minGap?:number, signal?:AbortSignal, onProgress?:Function}} opts
264
+ * threshold='auto' 时按 p95×3 自适应(推荐,真实素材与合成素材都能用)
265
+ * @returns {Promise<{cuts:Array<{t:number,score:number}>, stats:Array<{t:number,score:number}>,
266
+ * frames:number, threshold:number}>}
267
+ */
268
+ export function scanShots(opts) {
269
+ const {
270
+ input,
271
+ fps,
272
+ ffmpegPath = DEFAULT_FFMPEG,
273
+ width = SCAN_W,
274
+ height = SCAN_H,
275
+ threshold = 'auto',
276
+ minGap = 0.35,
277
+ start = 0,
278
+ end,
279
+ signal,
280
+ onProgress,
281
+ } = opts;
282
+
283
+ if (!(fps > 0)) throw new RangeError(`fps must be > 0, got ${fps}`);
284
+ const n = width * height;
285
+ const frameBytes = n * 3;
286
+
287
+ return new Promise((resolve, reject) => {
288
+ const child = spawn(
289
+ ffmpegPath,
290
+ ['-hide_banner', '-v', 'error', '-nostdin',
291
+ ...(start > 0 ? ['-ss', String(start)] : []),
292
+ ...(end !== undefined ? ['-t', String(Math.max(0.1, end - start))] : []),
293
+ '-i', input, '-an', '-sn',
294
+ '-vf', `scale=${width}:${height},format=rgb24`, '-f', 'rawvideo', '-'],
295
+ { stdio: ['ignore', 'pipe', 'pipe'], signal },
296
+ );
297
+
298
+ let pending = Buffer.alloc(0);
299
+ let prev = new Float32Array(n * 3);
300
+ let cur = new Float32Array(n * 3);
301
+ let hasPrev = false;
302
+ let frame = 0;
303
+ const stats = [];
304
+ // 顺便采集两个几乎免费的量,供 flash.js 判断「亮度闪一下又回来」:
305
+ // means[i] 整帧 V 均值(平移/摇镜不改变它)
306
+ // prints[i] 16×9 的 V 指纹(比 means 多一点点空间信息,用来确认"结构没变")
307
+ // 实测代价:解码占 95–98%,这两样只占 1–2%。
308
+ const means = [];
309
+ const prints = [];
310
+ let stderr = '';
311
+
312
+ child.stdout.on('data', (chunk) => {
313
+ pending = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
314
+ while (pending.length >= frameBytes) {
315
+ const slice = pending.subarray(0, frameBytes);
316
+ pending = pending.subarray(frameBytes);
317
+ frameToHsv(slice, cur);
318
+ if (hasPrev) {
319
+ stats.push({ t: start + frame / fps, score: scorePair(prev, cur) });
320
+ }
321
+ {
322
+ let sum = 0;
323
+ const acc = new Float64Array(FP_W * FP_H);
324
+ const cnt = new Uint16Array(FP_W * FP_H);
325
+ for (let y = 0; y < height; y++) {
326
+ const by = Math.min(FP_H - 1, Math.floor((y * FP_H) / height));
327
+ for (let x = 0; x < width; x++) {
328
+ const i = (y * width + x) * 3;
329
+ const v = Math.max(slice[i], slice[i + 1], slice[i + 2]);
330
+ sum += v;
331
+ const bi = by * FP_W + Math.min(FP_W - 1, Math.floor((x * FP_W) / width));
332
+ acc[bi] += v;
333
+ cnt[bi] += 1;
334
+ }
335
+ }
336
+ const fp = new Uint8Array(FP_W * FP_H);
337
+ for (let i = 0; i < FP_W * FP_H; i++) fp[i] = Math.round(acc[i] / (cnt[i] || 1));
338
+ means.push(sum / n);
339
+ prints.push(fp);
340
+ }
341
+ // 交换缓冲,避免每帧分配
342
+ const tmp = prev;
343
+ prev = cur;
344
+ cur = tmp;
345
+ hasPrev = true;
346
+ frame += 1;
347
+ }
348
+ onProgress?.({ frames: frame, lastScore: stats.length ? stats[stats.length - 1].score : 0 });
349
+ });
350
+
351
+ child.stderr.on('data', (d) => { stderr += d.toString(); });
352
+ child.on('error', (err) => reject(new Error(
353
+ `ffmpeg spawn failed: ${err.message} (${describeMediaSearch('ffmpeg')})`,
354
+ )));
355
+ child.on('close', (code) => {
356
+ if (code !== 0) {
357
+ reject(new Error(`ffmpeg exited ${code}: ${stderr.trim().split('\n').slice(-3).join(' | ')}`));
358
+ return;
359
+ }
360
+ const span = end !== undefined ? end - start : frame / fps;
361
+ const decided = decideCuts(stats, { threshold, minGap, duration: span });
362
+ const cuts = decided.cuts;
363
+
364
+ resolve({
365
+ cuts, stats, frames: frame, threshold: decided.threshold, degraded: decided.degraded,
366
+ summary: scanSummary(stats.map((s) => s.score)),
367
+ // 逐帧的亮度均值与 16×9 指纹(供 flash.js / 转场分类用)。
368
+ // 老调用方不读它们也不会受影响。
369
+ means, prints,
370
+ });
371
+ });
372
+ });
373
+ }
374
+
375
+ const MIN_REFINE_SCORE = 25;
376
+ // 整窗平均分高于这个值 → 认为"几乎每帧都在大改"(每帧一剪)。
377
+ // 实测:真每帧一剪 44.5,概念 PV 的快剪窗口 12–18,所以 30 能把两者分开。
378
+ const PER_FRAME_MEAN = 30;
379
+ /**
380
+ * 逐窗口重判:**先算画面差异,再按窗口决定用多细的间隔去数刀。**
381
+ *
382
+ * 早先的版本靠 `findBursts` 找爆点再细判,那有个死穴:整片都快时,"到处一样快"就没有爆点,
383
+ * 于是全片都被 0.35s 的间隔压扁(实测 3 秒 18 镜的素材只数出 4 刀)。
384
+ *
385
+ * 改成逐个 2 秒窗口判断,问的问题变成"**这个窗口的刀,粗间隔看得见吗**",是局部且绝对的,
386
+ * 跟全片平均无关。采纳条件三条:
387
+ * 1) 细判(一帧间隔)确实数出更多刀
388
+ * 2) 没被判成 motion(连续运镜每帧都在变,但幅度小)
389
+ * 3) 这些刀的分数均值 ≥ 25(真剪辑一次性换画面,运镜每帧只挪一点)
390
+ *
391
+ * 细判不需要重新读盘:两套判定都跑在同一份逐帧分数上。
392
+ *
393
+ * @returns {{cuts:Array, refined:Array<{from:number,to:number,coarse:number,fine:number}>}}
394
+ */
395
+ export function refineCutsByWindow({
396
+ stats, fps, coarseCuts, winStart = 0, winDur, winSec = 2, minScore = MIN_REFINE_SCORE,
397
+ }) {
398
+ // 间隔要按内容选:
399
+ // - 普通快闪:间隔略大于一帧(1.02/fps),避免同一个镜头的相邻帧被判成两刀;
400
+ // - **每帧一剪**:整窗平均分很高(实测 44,普通快闪只有 12–18),这时才把间隔压到一帧以下,
401
+ // 否则 23 刀只会数出 9 刀。
402
+ // 用固定的小间隔会把普通动画的快镜放成 19 刀/秒(实测概念 PV 48 → 164),所以必须按窗口内容分流。
403
+ const out = [];
404
+ const refined = [];
405
+ let open = null;
406
+ let finalGap = Math.max(1.02 / Math.max(1, fps), 0.04); // 收尾合并用的间隔(遇到每帧一剪会调小) // 正在进行的采纳区间
407
+
408
+ // 按下标切窗口:stats 是等间隔的,用 slice 比每窗 filter 全量快几个量级
409
+ // (60 分钟片子 90k 帧、1800 个窗口,原来每窗都扫全量 = 1.6 亿次比较)
410
+ const perWin = Math.max(4, Math.round(winSec * Math.max(1, fps)));
411
+ for (let i0 = 0; i0 < stats.length; i0 += perWin) {
412
+ const windowStats = stats.slice(i0, i0 + perWin);
413
+ const from = windowStats[0].t;
414
+ const to = windowStats[windowStats.length - 1].t + 1 / Math.max(1, fps);
415
+ const coarse = coarseCuts.filter((c) => c.t >= from && c.t < to);
416
+ if (windowStats.length < 4) { out.push(...coarse); continue; }
417
+
418
+ const meanScoreAll = windowStats.reduce((a, s) => a + s.score, 0) / windowStats.length;
419
+ const perFrame = meanScoreAll >= PER_FRAME_MEAN; // 整窗几乎每帧都在大改
420
+ const gap = perFrame
421
+ ? Math.max(0.9 / Math.max(1, fps), 0.03) // 一帧以下:每帧一剪也数得出
422
+ : Math.max(1.02 / Math.max(1, fps), 0.04); // 略大于一帧:不把同镜头的相邻帧算两刀
423
+ if (perFrame) finalGap = Math.min(finalGap, gap);
424
+ const fine = decideCuts(windowStats, { threshold: 'auto-low', minGap: gap, duration: to - from });
425
+ const mean = fine.cuts.reduce((a, c) => a + (c.score ?? 0), 0) / Math.max(1, fine.cuts.length);
426
+ const adopt = fine.cuts.length > coarse.length
427
+ && fine.degraded !== 'motion'
428
+ && mean >= minScore;
429
+
430
+ if (adopt) {
431
+ out.push(...fine.cuts);
432
+ const n = out.length;
433
+ if (open && Math.abs(open.to - from) < 1e-6) { open.to = to; open.fine = n; }
434
+ else {
435
+ if (open) refined.push({ from: open.from, to: open.to, coarse: open.coarse, fine: open.count });
436
+ open = { from, to, coarse: coarse.length, count: 0, fine: 0 };
437
+ }
438
+ open.count += fine.cuts.length;
439
+ } else {
440
+ out.push(...coarse);
441
+ if (open) { refined.push({ from: open.from, to: open.to, coarse: open.coarse, fine: open.count }); open = null; }
442
+ }
443
+ }
444
+ if (open) refined.push({ from: open.from, to: open.to, coarse: open.coarse, fine: open.count });
445
+
446
+ return {
447
+ // 收尾再并一次:跨窗口边界可能留下贴得很近的两刀。
448
+ // 间隔取"所有窗口用过的最小值",否则每帧一剪的结果会在这一步被并回去(实测 21 → 9)。
449
+ cuts: suppressClose(out.sort((a, b) => a.t - b.t), finalGap),
450
+ refined: refined.map((r) => ({
451
+ from: +r.from.toFixed(2), to: +r.to.toFixed(2), coarse: r.coarse, fine: r.fine,
452
+ })),
453
+ };
454
+ }
455
+
456
+
457
+ /**
458
+ * 找出**黑场区间**(片头黑屏、转场黑场、片尾字幕前的黑)。
459
+ *
460
+ * 为什么需要:黑场在分数上几乎为 0(前后都是黑的,没有"变化"),所以永远不会被当成切点。
461
+ * 结果它就和后面的 logo / 正片挤在同一格里,那一段的代表帧取中点 —— 正好落在黑里,
462
+ * 整格变成一张纯黑图,片头的内容全丢。
463
+ *
464
+ * 实测概念 PV:前 5 秒亮度只有 1(全黑),第一个切点在 5.71 秒(logo 出现),
465
+ * 而 0–37.6 秒那一格的中点 18.8 秒亮度是 0 —— 整格黑。
466
+ *
467
+ * @param {number[]} means 逐帧亮度均值(0–255)
468
+ * @param {{threshold?:number, minFrames?:number, fps?:number}} opts
469
+ * threshold: 低于它算黑(默认 12)
470
+ * minFrames: 至少持续这么多帧才算一段黑场(默认 0.4 秒),避免把暗场镜头误判
471
+ * @returns {Array<{from:number, to:number}>} 黑场区间(秒)
472
+ */
473
+ export function detectDarkRuns(means, { threshold = 12, minFrames = 10, fps = 25 } = {}) {
474
+ if (!Array.isArray(means) || means.length === 0) return [];
475
+ const runs = [];
476
+ let start = -1;
477
+ for (let i = 0; i <= means.length; i++) {
478
+ const dark = i < means.length && means[i] < threshold;
479
+ if (dark && start < 0) start = i;
480
+ if (!dark && start >= 0) {
481
+ if (i - start >= minFrames) runs.push({ from: start / fps, to: i / fps });
482
+ start = -1;
483
+ }
484
+ }
485
+ return runs;
486
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * segments.js — 从切点推导内容段,并把它调到目标格数。纯函数。
3
+ *
4
+ * 三条规则(顺序不能反):
5
+ * 1. 切点 → 区间,丢掉过短段(闪光/抖动误检)
6
+ * 2. 段数 > 目标:合并最短的一对相邻段(保护长镜头与关键段)
7
+ * 3. 段数 < 目标:对半拆最长的段(单镜头长视频的唯一出路)
8
+ */
9
+
10
+ /** 切点 → 有序、首尾相接的区间(from 用于"只看全片某一段"的场景) */
11
+ export function segmentsFromCuts(duration, cuts, minLen = 0.4, from = 0) {
12
+ if (!(duration > 0)) throw new RangeError(`duration must be > 0, got ${duration}`);
13
+ const lo = from + minLen;
14
+ const hi = from + duration - minLen;
15
+ const inner = cuts
16
+ .filter((c) => c > lo && c < hi)
17
+ .sort((a, b) => a - b);
18
+ const bounds = [from, ...inner, from + duration];
19
+ const segs = [];
20
+ for (let i = 0; i < bounds.length - 1; i++) {
21
+ if (bounds[i + 1] - bounds[i] >= minLen) segs.push([bounds[i], bounds[i + 1]]);
22
+ }
23
+ // 窗口本身就比 minLen 还短(例如模型要 zoom 看 0.2 秒):
24
+ // 所有段都过不了长度门槛 → 这里会返回空数组,下游 fitSegments 解构 undefined 直接崩。
25
+ // 短窗口本来就只能是一段,原样给它一整段。
26
+ if (segs.length === 0 && duration > 0) return [[from, from + duration]];
27
+ return mergeTail(segs);
28
+ }
29
+
30
+ /** 兜底:过滤后若出现空隙(被丢掉的切点),把尾段并回前一段,保证首尾相接 */
31
+ function mergeTail(segs) {
32
+ if (segs.length === 0) return [];
33
+ const out = [segs[0].slice()];
34
+ for (let i = 1; i < segs.length; i++) {
35
+ const prev = out[out.length - 1];
36
+ if (Math.abs(segs[i][0] - prev[1]) < 1e-6) out.push(segs[i].slice());
37
+ else prev[1] = segs[i][1];
38
+ }
39
+ return out;
40
+ }
41
+
42
+ export const segDur = (seg) => seg[1] - seg[0];
43
+ export const totalDur = (segs) => segs.reduce((s, seg) => s + segDur(seg), 0);
44
+
45
+ /**
46
+ * 把短于 minGap 的段并进更短的那一侧邻居。
47
+ *
48
+ * 为什么需要:快剪处的 0.3s 镜头占一整格毫无意义(它的代表帧和相邻格几乎一样),
49
+ * 而每格的机会成本是固定的。并掉之后,相邻采样点的间隔不会小于 minGap,
50
+ * 等价于给"取帧"加了一个最小间隔。
51
+ */
52
+ function mergeShorterThan(out, minGap) {
53
+ if (!(minGap > 0)) return out;
54
+ let guard = 0;
55
+ while (out.length > 1 && guard++ < 10000) {
56
+ const idx = out.findIndex((s) => segDur(s) < minGap);
57
+ if (idx === -1) break;
58
+ const left = idx > 0 ? segDur(out[idx - 1]) : Infinity;
59
+ const right = idx < out.length - 1 ? segDur(out[idx + 1]) : Infinity;
60
+ if (left <= right && idx > 0) {
61
+ out.splice(idx - 1, 2, [out[idx - 1][0], out[idx][1]]);
62
+ } else if (right < left && idx < out.length - 1) {
63
+ out.splice(idx, 2, [out[idx][0], out[idx + 1][1]]);
64
+ } else {
65
+ break;
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+
71
+ /** 段长中位数:用来判断"这条片子能给到的最细粒度是多少" */
72
+ function medianDuration(segs) {
73
+ const d = segs.map(segDur).sort((a, b) => a - b);
74
+ if (d.length === 0) return 0;
75
+ const mid = Math.floor(d.length / 2);
76
+ return d.length % 2 ? d[mid] : (d[mid - 1] + d[mid]) / 2;
77
+ }
78
+
79
+ /**
80
+ * 把段数调到 k,并保证每段不短于 minGap。
81
+ * 顺序很重要:先并短段(保证采样间隔),再按 k 合并/拆分。
82
+ * - 多于 k:反复合并"合并后最短"的那对相邻段
83
+ * - 少于 k:反复对半拆最长的段(拆到 < minGap 就停)
84
+ */
85
+ export function fitSegments(segs, k, { minGap = 0 } = {}) {
86
+ if (!Number.isInteger(k) || k < 1) throw new RangeError(`k must be a positive integer, got ${k}`);
87
+ let out = segs.map((s) => [Number(s[0]), Number(s[1])]);
88
+ // minGap 是"偏好",不能超过素材本身能提供的粒度:
89
+ // 一条全是 1s 短镜头的片子,硬按 1.2s 合并会把 6 段并成 3 段,反而凑不够格数。
90
+ const gap = minGap > 0 ? Math.min(minGap, Math.max(0.2, medianDuration(out) * 0.9)) : 0;
91
+
92
+ out = mergeShorterThan(out, gap);
93
+
94
+ while (out.length > k) {
95
+ let bestIdx = 0;
96
+ let bestSum = Infinity;
97
+ for (let i = 0; i < out.length - 1; i++) {
98
+ const sum = segDur(out[i]) + segDur(out[i + 1]);
99
+ if (sum < bestSum) { bestSum = sum; bestIdx = i; }
100
+ }
101
+ const merged = [out[bestIdx][0], out[bestIdx + 1][1]];
102
+ out.splice(bestIdx, 2, merged);
103
+ }
104
+
105
+ let guard = 0;
106
+ while (out.length < k) {
107
+ if (guard++ > 1000) break;
108
+ let idx = 0;
109
+ for (let i = 1; i < out.length; i++) if (segDur(out[i]) > segDur(out[idx])) idx = i;
110
+ const [a, b] = out[idx];
111
+ const floor = Math.max(0.2, gap); // 拆完两半都不能比最小间隔还短
112
+ if (b - a < floor * 2) break;
113
+ const mid = (a + b) / 2;
114
+ out.splice(idx, 1, [a, mid], [mid, b]);
115
+ }
116
+ return out;
117
+ }