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.
- package/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +30 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +37 -4
- package/lib/qqbot-0.5.3-patches.json +75 -70
- package/lib/qqbot-patch.mjs +12 -7
- package/lib/video.mjs +11 -2
- package/package.json +7 -23
- package/vendor/dsh-agent-md/LICENSE +21 -0
- package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
- package/vendor/dsh-agent-md/lib/index.js +775 -0
- package/vendor/dsh-agent-md/lib/persona.js +634 -0
- package/vendor/dsh-agent-md/lib/qq.js +527 -0
- package/vendor/dsh-agent-md/package.json +50 -0
- package/vendor/dsh-bili-scroll/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
- package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
- package/vendor/dsh-bili-scroll/index.js +3278 -0
- package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
- package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
- package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
- package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
- package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
- package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
- package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
- package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
- package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
- package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
- package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
- package/vendor/dsh-bili-scroll/package.json +84 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
- package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
- package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
- package/vendor/dsh-meme/LICENSE +21 -0
- package/vendor/dsh-meme/anim.js +588 -0
- package/vendor/dsh-meme/cordis.patch.yml +13 -0
- package/vendor/dsh-meme/icon.jpg +0 -0
- package/vendor/dsh-meme/index.js +2616 -0
- package/vendor/dsh-meme/locale/en.json +6 -0
- package/vendor/dsh-meme/locale/zh.json +6 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
- package/vendor/dsh-meme/memes.js +998 -0
- package/vendor/dsh-meme/package.json +67 -0
- package/vendor/dsh-meme/panel.html +210 -0
- package/vendor/dsh-video-storyboard/LICENSE +21 -0
- package/vendor/dsh-video-storyboard/NOTICE +12 -0
- package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
- package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
- package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
- package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
- package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
- package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
- package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
- package/vendor/dsh-video-storyboard/package.json +88 -0
- package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
- package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
- package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
- package/vendor/dsh-video-storyboard/src/index.js +82 -0
- package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
- package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
- package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
- package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
- package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
- package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
- package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
- package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
- package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
- package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
- package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
- package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
- package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
- package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
- package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
- package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
- package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
- package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
- package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
- package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
- package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
- package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
- package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
- package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
- package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
- package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
- package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
- package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
- package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
- package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
- package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
- package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
- package/vendor/dsh-world/LICENSE +21 -0
- package/vendor/dsh-world/assets/qq-card.png +0 -0
- package/vendor/dsh-world/cordis.patch.yml +6 -0
- package/vendor/dsh-world/lib/archive.d.ts +6 -0
- package/vendor/dsh-world/lib/archive.js +49 -0
- package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
- package/vendor/dsh-world/lib/archiveSelection.js +20 -0
- package/vendor/dsh-world/lib/compaction.d.ts +124 -0
- package/vendor/dsh-world/lib/compaction.js +273 -0
- package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
- package/vendor/dsh-world/lib/compactionRegion.js +210 -0
- package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
- package/vendor/dsh-world/lib/console/routes.js +129 -0
- package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
- package/vendor/dsh-world/lib/console/snapshot.js +51 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
- package/vendor/dsh-world/lib/faults.d.ts +10 -0
- package/vendor/dsh-world/lib/faults.js +13 -0
- package/vendor/dsh-world/lib/history.d.ts +16 -0
- package/vendor/dsh-world/lib/history.js +80 -0
- package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
- package/vendor/dsh-world/lib/hostContract.js +1 -0
- package/vendor/dsh-world/lib/http.d.ts +18 -0
- package/vendor/dsh-world/lib/http.js +39 -0
- package/vendor/dsh-world/lib/index.d.ts +108 -0
- package/vendor/dsh-world/lib/index.js +356 -0
- package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
- package/vendor/dsh-world/lib/life/activity.js +58 -0
- package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
- package/vendor/dsh-world/lib/life/alarm.js +132 -0
- package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
- package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
- package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
- package/vendor/dsh-world/lib/life/diary.js +9 -0
- package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
- package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
- package/vendor/dsh-world/lib/life/home.d.ts +34 -0
- package/vendor/dsh-world/lib/life/home.js +91 -0
- package/vendor/dsh-world/lib/life/host.d.ts +22 -0
- package/vendor/dsh-world/lib/life/host.js +24 -0
- package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
- package/vendor/dsh-world/lib/life/journal.js +59 -0
- package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
- package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
- package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
- package/vendor/dsh-world/lib/life/messages.js +53 -0
- package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
- package/vendor/dsh-world/lib/life/notify.js +40 -0
- package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
- package/vendor/dsh-world/lib/life/pricing.js +30 -0
- package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
- package/vendor/dsh-world/lib/life/runtime.js +376 -0
- package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
- package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
- package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
- package/vendor/dsh-world/lib/life/tools.js +47 -0
- package/vendor/dsh-world/lib/life/types.d.ts +67 -0
- package/vendor/dsh-world/lib/life/types.js +1 -0
- package/vendor/dsh-world/lib/persona.d.ts +10 -0
- package/vendor/dsh-world/lib/persona.js +29 -0
- package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
- package/vendor/dsh-world/lib/promptSection.js +81 -0
- package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
- package/vendor/dsh-world/lib/qqScope.js +39 -0
- package/vendor/dsh-world/lib/runtime.d.ts +23 -0
- package/vendor/dsh-world/lib/runtime.js +206 -0
- package/vendor/dsh-world/lib/self.d.ts +10 -0
- package/vendor/dsh-world/lib/self.js +36 -0
- package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
- package/vendor/dsh-world/lib/sourceArchive.js +156 -0
- package/vendor/dsh-world/lib/store.d.ts +30 -0
- package/vendor/dsh-world/lib/store.js +191 -0
- package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
- package/vendor/dsh-world/lib/timeContext.js +13 -0
- package/vendor/dsh-world/lib/types.d.ts +118 -0
- package/vendor/dsh-world/lib/types.js +1 -0
- package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
- package/vendor/dsh-world/lib/worldPrompt.js +49 -0
- package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
- package/vendor/dsh-world/lib/worldSwitch.js +78 -0
- package/vendor/dsh-world/package-lock.json +1088 -0
- package/vendor/dsh-world/package.json +88 -0
- package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
- package/vendor/dsh-world/src/archive.ts +45 -0
- package/vendor/dsh-world/src/archiveSelection.ts +27 -0
- package/vendor/dsh-world/src/compaction.ts +260 -0
- package/vendor/dsh-world/src/compactionRegion.ts +172 -0
- package/vendor/dsh-world/src/console/routes.ts +125 -0
- package/vendor/dsh-world/src/console/snapshot.ts +84 -0
- package/vendor/dsh-world/src/ecosystem/README.md +14 -0
- package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
- package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
- package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
- package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
- package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
- package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
- package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
- package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
- package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
- package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
- package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
- package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
- package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
- package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
- package/vendor/dsh-world/src/faults.ts +12 -0
- package/vendor/dsh-world/src/history.ts +77 -0
- package/vendor/dsh-world/src/hostContract.ts +9 -0
- package/vendor/dsh-world/src/http.ts +34 -0
- package/vendor/dsh-world/src/index.ts +286 -0
- package/vendor/dsh-world/src/life/activity.ts +48 -0
- package/vendor/dsh-world/src/life/alarm.ts +119 -0
- package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
- package/vendor/dsh-world/src/life/diary.ts +10 -0
- package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
- package/vendor/dsh-world/src/life/home.ts +85 -0
- package/vendor/dsh-world/src/life/host.ts +50 -0
- package/vendor/dsh-world/src/life/journal.ts +44 -0
- package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
- package/vendor/dsh-world/src/life/messages.ts +44 -0
- package/vendor/dsh-world/src/life/notify.ts +47 -0
- package/vendor/dsh-world/src/life/pricing.ts +37 -0
- package/vendor/dsh-world/src/life/runtime.ts +318 -0
- package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
- package/vendor/dsh-world/src/life/tools.ts +61 -0
- package/vendor/dsh-world/src/life/types.ts +19 -0
- package/vendor/dsh-world/src/persona.ts +26 -0
- package/vendor/dsh-world/src/promptSection.ts +71 -0
- package/vendor/dsh-world/src/qqScope.ts +51 -0
- package/vendor/dsh-world/src/runtime.ts +172 -0
- package/vendor/dsh-world/src/self.ts +32 -0
- package/vendor/dsh-world/src/sourceArchive.ts +132 -0
- package/vendor/dsh-world/src/store.ts +170 -0
- package/vendor/dsh-world/src/timeContext.ts +13 -0
- package/vendor/dsh-world/src/types.ts +112 -0
- package/vendor/dsh-world/src/worldPrompt.ts +64 -0
- package/vendor/dsh-world/src/worldSwitch.ts +82 -0
- package/vendor/dsh-world/templates/alarm.md +49 -0
- package/vendor/dsh-world/templates/world-prompt.md +7 -0
- package/vendor/dsh-world/tests/archive.test.ts +57 -0
- package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
- package/vendor/dsh-world/tests/bridge.test.ts +211 -0
- package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
- package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
- package/vendor/dsh-world/tests/compaction.test.ts +141 -0
- package/vendor/dsh-world/tests/console.test.ts +202 -0
- package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
- package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
- package/vendor/dsh-world/tests/fixtures.ts +6 -0
- package/vendor/dsh-world/tests/history.test.ts +100 -0
- package/vendor/dsh-world/tests/hostFixture.ts +46 -0
- package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
- package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
- package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
- package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
- package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
- package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
- package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
- package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
- package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
- package/vendor/dsh-world/tests/outlets.test.ts +85 -0
- package/vendor/dsh-world/tests/panel.test.ts +85 -0
- package/vendor/dsh-world/tests/plugin.test.ts +614 -0
- package/vendor/dsh-world/tests/pricing.test.ts +21 -0
- package/vendor/dsh-world/tests/qq.test.ts +121 -0
- package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
- package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
- package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
- package/vendor/dsh-world/tests/store.test.ts +82 -0
- package/vendor/dsh-world/tests/storeWriter.ts +5 -0
- package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
- package/vendor/dsh-world/tests/wechat.test.ts +254 -0
- package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
- package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
- package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
- package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
- package/vendor/dsh-world/tsconfig.build.json +5 -0
- package/vendor/dsh-world/tsconfig.json +8 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/login.mjs —— 扫码登录(直接在 JS 里走 B站 passport 接口)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 为什么不用它自带的 `bili_login`:那个把码存成 PNG 就返回,**字段全是空**(踩过一次,见 lesson)。
|
|
5
|
+
* 我们按实测跑通的那条来:
|
|
6
|
+
* ① GET /x/passport-login/web/qrcode/generate?source=main-fe-header → data.url + data.qrcode_key
|
|
7
|
+
* ② 手机扫 → 轮询 /x/passport-login/web/qrcode/poll?qrcode_key=…
|
|
8
|
+
* data.code:86101 未扫 / 86090 已扫待确认 / 0 成功 / 86038 过期
|
|
9
|
+
* ③ ⭐ **凭证在轮询响应的 `Set-Cookie` 头里**(成功时那条 `data.url` 里没有 SESSDATA,
|
|
10
|
+
* 那是别的域的游戏票 —— 别在 url 里找)
|
|
11
|
+
* ④ 写成 MCP 认识的四个字段:sessdata / bili_jct / buvid3 / dedeuserid
|
|
12
|
+
*
|
|
13
|
+
* 二维码图片:交给 venv 里的 Python `qrcode` 画(ASCII 的 URL,走 `-c` 安全;
|
|
14
|
+
* 没装就退回"只给 URL",前端会提示先跑「建 venv 装依赖」)。
|
|
15
|
+
* ============================================================================
|
|
16
|
+
*/
|
|
17
|
+
import { spawn } from 'node:child_process'
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
19
|
+
import { execFileSync } from 'node:child_process'
|
|
20
|
+
import { join } from 'node:path'
|
|
21
|
+
|
|
22
|
+
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36'
|
|
23
|
+
const GEN = 'https://passport.bilibili.com/x/passport-login/web/qrcode/generate?source=main-fe-header'
|
|
24
|
+
const pollUrl = (key) => 'https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=' + encodeURIComponent(key) + '&source=main-fe-header'
|
|
25
|
+
const SPI = 'https://api.bilibili.com/x/frontend/finger/spi'
|
|
26
|
+
|
|
27
|
+
/** 从 Set-Cookie 数组里抠出我们要的几个 */
|
|
28
|
+
function pickCookies(list) {
|
|
29
|
+
const jar = {}
|
|
30
|
+
const want = { SESSDATA: 'sessdata', bili_jct: 'bili_jct', DedeUserID: 'dedeuserid', buvid3: 'buvid3' }
|
|
31
|
+
for (const raw of list ?? []) {
|
|
32
|
+
const first = String(raw).split(';')[0] || ''
|
|
33
|
+
const i = first.indexOf('=')
|
|
34
|
+
if (i <= 0) continue
|
|
35
|
+
const name = first.slice(0, i).trim()
|
|
36
|
+
const value = first.slice(i + 1).trim()
|
|
37
|
+
if (want[name]) jar[want[name]] = value
|
|
38
|
+
}
|
|
39
|
+
return jar
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 拿不到 buvid3 时补一张"指纹"(非致命,失败就当空) */
|
|
43
|
+
async function ensureBuvid3(jar) {
|
|
44
|
+
if (jar.buvid3) return jar
|
|
45
|
+
try {
|
|
46
|
+
const r = await fetch(SPI, { headers: { 'User-Agent': UA } })
|
|
47
|
+
const j = await r.json()
|
|
48
|
+
const v = j?.data?.b_3
|
|
49
|
+
if (v) jar.buvid3 = v
|
|
50
|
+
} catch { /* 拿不到就算了 */ }
|
|
51
|
+
return jar
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function loginStart() {
|
|
55
|
+
const r = await fetch(GEN, { headers: { 'User-Agent': UA } })
|
|
56
|
+
const j = await r.json()
|
|
57
|
+
const data = j?.data
|
|
58
|
+
if (!data?.qrcode_key || !data?.url) throw new Error(`生成二维码失败:${j?.message || '返回里没有 qrcode_key'}`)
|
|
59
|
+
return { key: data.qrcode_key, url: data.url }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 轮询一次。state: waiting / scanned / ok / expired / unknown */
|
|
63
|
+
export async function loginPoll(key) {
|
|
64
|
+
const res = await fetch(pollUrl(key), { headers: { 'User-Agent': UA }, redirect: 'manual' })
|
|
65
|
+
const setCookies = typeof res.headers.getSetCookie === 'function' ? res.headers.getSetCookie() : []
|
|
66
|
+
let body = {}
|
|
67
|
+
try { body = await res.json() } catch { /* poll 有时返回空体 */ }
|
|
68
|
+
const code = body?.data?.code
|
|
69
|
+
if (code === 0) {
|
|
70
|
+
const jar = await ensureBuvid3(pickCookies(setCookies))
|
|
71
|
+
if (!jar.sessdata) return { state: 'unknown', code, message: '登录成功了,但响应里没有 SESSDATA —— 把这次的结果记下来再排查' }
|
|
72
|
+
return { state: 'ok', code, credential: jar }
|
|
73
|
+
}
|
|
74
|
+
const map = { 86101: 'waiting', 86090: 'scanned', 86038: 'expired' }
|
|
75
|
+
return { state: map[code] ?? 'unknown', code, message: body?.message || '' }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 把凭证写进 MCP 读的那个文件(家目录里的 bili_credential.json) */
|
|
79
|
+
/**
|
|
80
|
+
* ⭐ 2026-10-23 安全加固(审计 + issue #67):凭证文件权限收紧到"只有自己能读" ——
|
|
81
|
+
* Linux/macOS: chmod 0600;Windows: icacls 去掉继承(只留当前用户)。
|
|
82
|
+
* 失败也不报错(有些文件系统不支持),但会返回 false 让调用方可以说明。
|
|
83
|
+
* ⭐ #128:Windows 上**按 SID 授权**,不按名字 —— 机器名和用户名一样时(`KunQi` / `kunqi`),
|
|
84
|
+
* icacls 会把名字解析成**计算机账户**,再加上 /inheritance:r,文件就谁也读不了 ⇒ 扫码成功却一直「未登录」。
|
|
85
|
+
* 收紧之后再读一次自检,读不回来就 /reset 恢复继承 —— 宁可权限宽一点,也不要把凭证锁死。
|
|
86
|
+
*/
|
|
87
|
+
function currentUserSid() {
|
|
88
|
+
try {
|
|
89
|
+
// 写全路径:从 Git Bash 起的 dsh,PATH 里排前面的 whoami 是 GNU 那个,不认 /user
|
|
90
|
+
const whoami = join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'whoami.exe')
|
|
91
|
+
const out = execFileSync(whoami, ['/user', '/fo', 'csv', '/nh'], { encoding: 'utf8', windowsHide: true })
|
|
92
|
+
const m = /"(S-1-[\d-]+)"/.exec(out)
|
|
93
|
+
return m ? m[1] : null
|
|
94
|
+
} catch { return null }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function hardenPerms(file) {
|
|
98
|
+
try {
|
|
99
|
+
if (process.platform === 'win32') {
|
|
100
|
+
const sid = currentUserSid()
|
|
101
|
+
// `*S-1-…` = 让 icacls 直接用 SID、跳过名字解析;拿不到 SID 才退回「域\用户名」(也不会撞上机器账户)
|
|
102
|
+
const who = sid ? '*' + sid : (process.env.USERDOMAIN ? process.env.USERDOMAIN + '\\' : '') + (process.env.USERNAME || '')
|
|
103
|
+
execFileSync('icacls', [file, '/inheritance:r', '/grant:r', who + ':F'], { stdio: 'ignore', windowsHide: true })
|
|
104
|
+
try { readFileSync(file) } catch {
|
|
105
|
+
execFileSync('icacls', [file, '/reset'], { stdio: 'ignore', windowsHide: true })
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
execFileSync('chmod', ['600', file], { stdio: 'ignore' })
|
|
110
|
+
}
|
|
111
|
+
return true
|
|
112
|
+
} catch { return false }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function saveCredential(stateDir, credential) {
|
|
116
|
+
mkdirSync(stateDir, { recursive: true })
|
|
117
|
+
const file = join(stateDir, 'bili_credential.json')
|
|
118
|
+
writeFileSync(file, JSON.stringify({
|
|
119
|
+
sessdata: credential.sessdata ?? '',
|
|
120
|
+
bili_jct: credential.bili_jct ?? '',
|
|
121
|
+
buvid3: credential.buvid3 || '',
|
|
122
|
+
dedeuserid: credential.dedeuserid ?? '',
|
|
123
|
+
}, null, 2), 'utf8')
|
|
124
|
+
try { hardenPerms(file) } catch { /* 收紧失败也不影响登录 */ }
|
|
125
|
+
return file
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 用 Python 的 qrcode 画一张 PNG,返回**文件路径**(拿不到就返回 null) */
|
|
129
|
+
export function renderQrPng(pythonPath, stateDir, url) {
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const png = join(stateDir, 'qrcode_login.png')
|
|
132
|
+
const code = 'import sys, qrcode; qrcode.make(sys.argv[1]).save(sys.argv[2])'
|
|
133
|
+
let child
|
|
134
|
+
try {
|
|
135
|
+
child = spawn(pythonPath || 'python', ['-c', code, url, png], { cwd: stateDir, windowsHide: true })
|
|
136
|
+
} catch { return resolve(null) }
|
|
137
|
+
const done = () => { try { resolve(existsSync(png) ? png : null) } catch { resolve(null) } }
|
|
138
|
+
child.on('exit', (c) => { if (c === 0) done(); else resolve(null) })
|
|
139
|
+
child.on('error', () => resolve(null))
|
|
140
|
+
})
|
|
141
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/mcp.mjs —— 一个极小的 MCP stdio 客户端(只做我们需要的三件事)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 为什么不用 `@deepseek-ai/dsh-mcp-client`:那是个"把 MCP 挂成 dsh 工具"的完整插件,
|
|
5
|
+
* 而我们要的是**插件内部自己起这个 Python MCP**(用户选了 A 方案:装完就能用,
|
|
6
|
+
* Python 路径和登录都在设置页里,不用去改 profile 的 patch)。
|
|
7
|
+
*
|
|
8
|
+
* 协议就三句话:`initialize` → `notifications/initialized` → `tools/call`,
|
|
9
|
+
* stdio 上是**一行一个 JSON-RPC**。
|
|
10
|
+
* ============================================================================
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from 'node:child_process'
|
|
13
|
+
import { readFileSync } from 'node:fs'
|
|
14
|
+
|
|
15
|
+
// 报给对端的身份:版本号**从 package.json 读**,别手写(手写的那份永远追不上发版)
|
|
16
|
+
const PKG = (() => { try { return JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) } catch { return {} } })()
|
|
17
|
+
|
|
18
|
+
export class McpClient {
|
|
19
|
+
constructor({ command, args = [], cwd, env, log = () => {} }) {
|
|
20
|
+
this.cfg = { command, args, cwd, env, log }
|
|
21
|
+
this.proc = null
|
|
22
|
+
this.buf = ''
|
|
23
|
+
this.nextId = 1
|
|
24
|
+
this.pending = new Map()
|
|
25
|
+
this.stderr = ''
|
|
26
|
+
this.starting = null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get running() { return Boolean(this.proc) }
|
|
30
|
+
|
|
31
|
+
async start() {
|
|
32
|
+
if (this.proc) return
|
|
33
|
+
if (this.starting) return this.starting
|
|
34
|
+
this.starting = (async () => {
|
|
35
|
+
const { command, args, cwd, env, log } = this.cfg
|
|
36
|
+
this.proc = spawn(command, args, {
|
|
37
|
+
cwd,
|
|
38
|
+
env: { ...process.env, ...(env || {}) },
|
|
39
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
+
windowsHide: true,
|
|
41
|
+
})
|
|
42
|
+
this.proc.stdout.setEncoding('utf8')
|
|
43
|
+
this.proc.stdout.on('data', (chunk) => this.#onData(chunk))
|
|
44
|
+
this.proc.stderr.setEncoding('utf8')
|
|
45
|
+
this.proc.stderr.on('data', (c) => { this.stderr = (this.stderr + c).slice(-4000) })
|
|
46
|
+
this.proc.on('error', (e) => log(`MCP 子进程启动失败:${e?.message ?? e}`))
|
|
47
|
+
this.proc.on('exit', (code) => {
|
|
48
|
+
log(`MCP 子进程退出(code=${code})`)
|
|
49
|
+
for (const [, p] of this.pending) p.reject(new Error(`MCP 子进程退出(code=${code})${this.stderr ? ':' + this.stderr.slice(-300) : ''}`))
|
|
50
|
+
this.pending.clear()
|
|
51
|
+
this.proc = null
|
|
52
|
+
})
|
|
53
|
+
await this.#request('initialize', {
|
|
54
|
+
protocolVersion: '2024-11-05',
|
|
55
|
+
capabilities: {},
|
|
56
|
+
clientInfo: { name: PKG.name || 'dsh-bili-scroll', version: PKG.version || '0.0.0' },
|
|
57
|
+
})
|
|
58
|
+
this.#notify('notifications/initialized', {})
|
|
59
|
+
log('MCP 已就绪')
|
|
60
|
+
})()
|
|
61
|
+
try { await this.starting } finally { this.starting = null }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
stop() {
|
|
65
|
+
try { this.proc?.kill() } catch { /* 已经没了 */ }
|
|
66
|
+
this.proc = null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 调一个 MCP 工具:能解析成 JSON 就返回对象,否则返回字符串 */
|
|
70
|
+
async call(name, args = {}, opts = {}) {
|
|
71
|
+
return (await this.callRaw(name, args, opts)).json
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 同 call,但保留图片块:返回 { json, images },images 每项是 { data, mimeType } */
|
|
75
|
+
async callRaw(name, args = {}, { timeoutMs = 180000, signal } = {}) {
|
|
76
|
+
await this.start()
|
|
77
|
+
const result = await this.#request('tools/call', { name, arguments: args }, timeoutMs, signal)
|
|
78
|
+
const blocks = result?.content ?? []
|
|
79
|
+
const text = blocks.map((c) => c?.text ?? '').filter(Boolean).join('\n').trim()
|
|
80
|
+
if (result?.isError) throw new Error(text || `MCP 工具 ${name} 报错`)
|
|
81
|
+
const images = blocks
|
|
82
|
+
.filter((c) => c?.type === 'image' && c?.data)
|
|
83
|
+
.map((c) => ({ data: c.data, mimeType: c.mimeType || c.mime_type || 'image/jpeg' }))
|
|
84
|
+
let json = {}
|
|
85
|
+
try { json = text ? JSON.parse(text) : {} } catch { json = text }
|
|
86
|
+
return { json, images }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#onData(chunk) {
|
|
90
|
+
this.buf += chunk
|
|
91
|
+
let idx
|
|
92
|
+
while ((idx = this.buf.indexOf('\n')) >= 0) {
|
|
93
|
+
const line = this.buf.slice(0, idx).trim()
|
|
94
|
+
this.buf = this.buf.slice(idx + 1)
|
|
95
|
+
if (!line) continue
|
|
96
|
+
let msg
|
|
97
|
+
try { msg = JSON.parse(line) } catch { continue } // 非 JSON 行(有些库会往 stdout 打日志)忽略
|
|
98
|
+
if (msg.id !== undefined && this.pending.has(msg.id)) {
|
|
99
|
+
const p = this.pending.get(msg.id)
|
|
100
|
+
this.pending.delete(msg.id)
|
|
101
|
+
if (msg.error) p.reject(new Error(msg.error?.message ? String(msg.error.message) : JSON.stringify(msg.error)))
|
|
102
|
+
else p.resolve(msg.result)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#send(obj) {
|
|
108
|
+
if (!this.proc?.stdin?.writable) throw new Error('MCP 子进程不在运行')
|
|
109
|
+
this.proc.stdin.write(JSON.stringify(obj) + '\n')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#notify(method, params) { this.#send({ jsonrpc: '2.0', method, params }) }
|
|
113
|
+
|
|
114
|
+
#request(method, params, timeoutMs = 60000, signal) {
|
|
115
|
+
const id = this.nextId++
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
if (signal?.aborted) {
|
|
118
|
+
reject(new Error(`MCP ${method} 已取消`))
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
const cleanup = () => {
|
|
122
|
+
clearTimeout(timer)
|
|
123
|
+
this.pending.delete(id)
|
|
124
|
+
signal?.removeEventListener?.('abort', onAbort)
|
|
125
|
+
}
|
|
126
|
+
const onAbort = () => {
|
|
127
|
+
cleanup()
|
|
128
|
+
reject(new Error(`MCP ${method} 已取消`))
|
|
129
|
+
}
|
|
130
|
+
const timer = setTimeout(() => {
|
|
131
|
+
cleanup()
|
|
132
|
+
reject(new Error(`MCP ${method} 超时(${timeoutMs}ms)${this.stderr ? ':' + this.stderr.slice(-200) : ''}`))
|
|
133
|
+
}, timeoutMs)
|
|
134
|
+
this.pending.set(id, {
|
|
135
|
+
resolve: (v) => { cleanup(); resolve(v) },
|
|
136
|
+
reject: (e) => { cleanup(); reject(e) },
|
|
137
|
+
})
|
|
138
|
+
signal?.addEventListener?.('abort', onAbort, { once: true })
|
|
139
|
+
try { this.#send({ jsonrpc: '2.0', id, method, params }) } catch (e) {
|
|
140
|
+
cleanup(); reject(e)
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/state.mjs —— 插件的"家"与配置
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 规矩(抄 whale_craft):**配置、凭证、报告、日志都放插件自己的家** ——
|
|
5
|
+
* `$DSH_HOME/bili-duty/`,**绝不写进插件包目录**(装进 node_modules 后可能只读、升级也会被覆盖)。
|
|
6
|
+
*
|
|
7
|
+
* 还有一件小事但很要紧:vendored 的 `mcp_server.py` 里,凭证路径是
|
|
8
|
+
* `Path(__file__).parent / "bili_credential.json"` —— 所以**运行时要把脚本拷到家目录里再跑**,
|
|
9
|
+
* 这样凭证才会落在家的目录,而不是插件包里。
|
|
10
|
+
* ============================================================================
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from 'node:fs'
|
|
13
|
+
import { createHash as nodeCreateHash } from 'node:crypto'
|
|
14
|
+
import { createHash } from 'node:crypto'
|
|
15
|
+
import { join } from 'node:path'
|
|
16
|
+
import { homedir } from 'node:os'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 谷时窗口(北京时间)—— 想改就改这一处。
|
|
20
|
+
* ⭐ 官方口径(2026-09-10 起的新定价):**高峰 = 工作日 9:00–12:00 与 14:00–18:00,其余全是谷时**
|
|
21
|
+
* ⇒ 12:00–14:00(夹在两个高峰之间)✓、18:00 之后的一整晚 ✓、以及**整个周末** ✓ 都便宜。
|
|
22
|
+
* ⚠️ 我们原来写的 00:30–08:30 是 DeepSeek **早年**的错峰优惠时段,**已经过时** ✗
|
|
23
|
+
* —— 2026-10-14 使用者在"陌生人验收"里问「晚上峰谷真的是12点半才开始的吗」才查出来 ✓。
|
|
24
|
+
*/
|
|
25
|
+
export const WINDOWS = {
|
|
26
|
+
noon: { label: '中午谷时', start: '12:00', end: '14:00' },
|
|
27
|
+
night: { label: '晚上/夜间谷时', start: '18:00', end: '09:00' },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ⭐ 2026-10-14 真机上踩到的坑(dsh 只留一句 `warning: 1 entry did not activate` + 堆栈):
|
|
32
|
+
* `ctx.get('dshHomePath')` 返回的是**函数**,不是字符串!
|
|
33
|
+
* 形状:`dshHomePath(...segments) => join(resolveDshHome(), ...segments)`(whale_craft 就是这么用的)。
|
|
34
|
+
* 我一开始当字符串用(`String(p)`),路径就成了「函数源码 + \bili-duty」⇒ mkdir ENOENT ⇒ apply 抛错 ⇒ 插件不激活。
|
|
35
|
+
*/
|
|
36
|
+
export function stateDirOf(ctx) {
|
|
37
|
+
let dir = ''
|
|
38
|
+
try {
|
|
39
|
+
const p = ctx?.get?.('dshHomePath')
|
|
40
|
+
if (typeof p === 'function') {
|
|
41
|
+
const v = p('bili-duty') // ← 函数形态:把目录名传进去
|
|
42
|
+
if (v) dir = String(v)
|
|
43
|
+
} else if (typeof p === 'string' && p) {
|
|
44
|
+
dir = join(p, 'bili-duty')
|
|
45
|
+
}
|
|
46
|
+
} catch { /* 拿不到就用下面的兜底 */ }
|
|
47
|
+
if (!dir) dir = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'bili-duty')
|
|
48
|
+
mkdirSync(dir, { recursive: true })
|
|
49
|
+
return dir
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function readJson(file, fallback) {
|
|
53
|
+
try { return JSON.parse(readFileSync(file, 'utf8')) } catch { return fallback }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function writeJson(file, value) {
|
|
57
|
+
writeFileSync(file, JSON.stringify(value, null, 2), 'utf8')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 把 vendored 的脚本铺进家里。
|
|
62
|
+
*
|
|
63
|
+
* ⭐ 2026-10-22(用户 @俺爱啃猪蹄子 指出策略不一致):以前是"内容不一样就覆盖" ⇒ **用户改过的直接丢** ✗,
|
|
64
|
+
* 而章程 duty.md 是"改过就保留" —— 同一个插件两套规矩,很怪。
|
|
65
|
+
* 现在改成**记住"上次我们发出去那份的指纹"**(`.shipped-<文件名>.sha`):
|
|
66
|
+
* · 家里那份 == 我们发的 ⇒ 正常升级覆盖 ✓
|
|
67
|
+
* · 家里那份 ≠ 我们发的 ⇒ **说明用户改过** ⇒ 不覆盖,新版写到 `<文件>.new` 并提示 ✓
|
|
68
|
+
* · 没有指纹(老版本升级上来)⇒ 按老行为覆盖一次并记指纹(从这一版起才有"改过"的概念)✓
|
|
69
|
+
*/
|
|
70
|
+
export function ensureHomeFiles(pluginDir, stateDir, log = () => {}) {
|
|
71
|
+
const copies = [
|
|
72
|
+
[join(pluginDir, 'vendor', 'bilibili-mcp', 'mcp_server.py'), join(stateDir, 'mcp_server.py')],
|
|
73
|
+
[join(pluginDir, 'lib', 'asr.py'), join(stateDir, 'asr.py')],
|
|
74
|
+
[join(pluginDir, 'lib', 'favops.py'), join(stateDir, 'favops.py')],
|
|
75
|
+
]
|
|
76
|
+
const sha = (buf) => {
|
|
77
|
+
try { return nodeCreateHash('sha256').update(buf).digest('hex') } catch { return '' }
|
|
78
|
+
}
|
|
79
|
+
for (const [from, to] of copies) {
|
|
80
|
+
try {
|
|
81
|
+
if (!existsSync(from)) { log(`缺文件:${from}`); continue }
|
|
82
|
+
const incoming = readFileSync(from, 'utf8')
|
|
83
|
+
const markFile = join(stateDir, '.shipped-' + to.split(/[\\/]/).pop() + '.sha')
|
|
84
|
+
const shipped = existsSync(markFile) ? readFileSync(markFile, 'utf8').trim() : ''
|
|
85
|
+
const writeMark = (txt) => { try { writeFileSync(markFile, sha(Buffer.from(txt, 'utf8')), 'utf8') } catch { /* 记不上就下次再说 */ } }
|
|
86
|
+
if (!existsSync(to)) {
|
|
87
|
+
copyFileSync(from, to); writeMark(incoming); log(`已铺好:${to}`); continue
|
|
88
|
+
}
|
|
89
|
+
const onDisk = readFileSync(to, 'utf8')
|
|
90
|
+
if (onDisk === incoming) { if (!shipped) writeMark(incoming); continue } // 本来就是同一份
|
|
91
|
+
// ⭐⭐ 2.1.0(2026-10-24 实证):剩下两种情况的处理可以并成一条 ——
|
|
92
|
+
// 这几个文件是**我们发的运行时代码**(mcp_server.py / asr.py / favops.py),
|
|
93
|
+
// 用户改过也不该拦着升级:否则"宿主新、Python 侧旧",新工具根本不出现 ✗
|
|
94
|
+
// (今天就这么栽的:家目录那份停在 11:50,值班轮里说"没有 bili_cover 这个工具")
|
|
95
|
+
// ⇒ **先备份 .bak-<时间戳>,再覆盖**,改了什么都能自己捞回来 ✓
|
|
96
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19)
|
|
97
|
+
const bak = to + ".bak-" + stamp
|
|
98
|
+
try { copyFileSync(to, bak) } catch { /* 备份不了也继续,原件在插件包里 */ }
|
|
99
|
+
copyFileSync(from, to)
|
|
100
|
+
writeMark(incoming)
|
|
101
|
+
log(`已覆盖:${to}(旧的那份备份在 ${bak})`)
|
|
102
|
+
} catch (e) { log(`铺 ${to} 失败:${e?.message ?? e}`) }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 值班章程(prompts/duty.md)放在哪一份 —— 家里那份优先,没有才用插件里那份。
|
|
108
|
+
* (家里那份由下面的 ensureCharter 保证铺好)
|
|
109
|
+
*/
|
|
110
|
+
export function charterPath(pluginDir, stateDir) {
|
|
111
|
+
const home = join(stateDir, 'duty.md')
|
|
112
|
+
try { if (existsSync(home)) return home } catch { /* 兜底:用插件里那份 */ }
|
|
113
|
+
return join(pluginDir, 'prompts', 'duty.md')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* ⭐ 值班章程怎么升级 —— 2026-10-17 审查里的 M6 就是这里。
|
|
118
|
+
* 老规矩(index.js 里比 mtime):家里那份比 shipped 新 ⇒ 听使用者的。听着合理,实际是一把**单向锁**:
|
|
119
|
+
* 使用者只要改过章程一个字,家里那份就永远比 shipped 新 ⇒ 插件后续版本改进的章程
|
|
120
|
+
* (0.1.5 的注入防护、空输出定义恰好就写在章程里)**永远进不来** ✗。
|
|
121
|
+
* 改成记账制 —— 上次铺的是哪一版(sha256)记在 charter.sha256:
|
|
122
|
+
* · 家里那份 === 我们上次铺的 ⇒ 他没动过 ⇒ 直接用 shipped 覆盖(升级 ✓)
|
|
123
|
+
* · 家里那份变过 ⇒ 他改过 ⇒ **一个字都不动**,新版另存 duty.md.new 让他自己合 ✓
|
|
124
|
+
* · 没有账本(带账本的第一个版本刚跑起来)⇒ 分不清「没改只是版本旧」和「改过」,
|
|
125
|
+
* 按「改过」处理 —— 宁可让他手动合一次,也不能偷偷吃掉他的改动 ✓
|
|
126
|
+
*/
|
|
127
|
+
export function ensureCharter(pluginDir, stateDir, log = () => {}) {
|
|
128
|
+
const shipped = join(pluginDir, 'prompts', 'duty.md')
|
|
129
|
+
const home = join(stateDir, 'duty.md')
|
|
130
|
+
const ledger = join(stateDir, 'charter.sha256')
|
|
131
|
+
const fresh = join(stateDir, 'duty.md.new')
|
|
132
|
+
const readIf = (f) => { try { return readFileSync(f, 'utf8') } catch { return '' } }
|
|
133
|
+
try {
|
|
134
|
+
if (!existsSync(shipped)) { log(`缺文件:${shipped}`); return }
|
|
135
|
+
const sha = (s) => createHash('sha256').update(s, 'utf8').digest('hex')
|
|
136
|
+
const newText = readFileSync(shipped, 'utf8')
|
|
137
|
+
const hShip = sha(newText)
|
|
138
|
+
const hLast = readIf(ledger).trim()
|
|
139
|
+
if (!existsSync(home)) {
|
|
140
|
+
writeFileSync(home, newText, 'utf8'); writeFileSync(ledger, hShip, 'utf8')
|
|
141
|
+
log('已铺好值班章程')
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
const hHome = sha(readFileSync(home, 'utf8'))
|
|
145
|
+
if (hHome === hShip) { // 家里那份就是最新版(他可能只是没动过)
|
|
146
|
+
if (hLast !== hShip) writeFileSync(ledger, hShip, 'utf8')
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
if (!hLast || hHome !== hLast) { // 他改过(或没账本、分不清)⇒ 只另存新版
|
|
150
|
+
if (hShip !== hLast && readIf(fresh) !== newText) {
|
|
151
|
+
writeFileSync(fresh, newText, 'utf8')
|
|
152
|
+
log(`值班章程有新版、但家里那份你改过 ⇒ 新版另存为 ${fresh},自己合一下`)
|
|
153
|
+
}
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
writeFileSync(home, newText, 'utf8'); writeFileSync(ledger, hShip, 'utf8') // 他没动过 ⇒ 直接升级
|
|
157
|
+
log('值班章程已更新到插件里这一版')
|
|
158
|
+
} catch (e) { log(`铺值班章程失败:${e?.message ?? e}`) }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 'HH:MM' → 当天的分钟数 */
|
|
162
|
+
function minutesOf(hhmm) {
|
|
163
|
+
const m = /^(\d{1,2}):(\d{2})$/.exec(String(hhmm).trim())
|
|
164
|
+
if (!m) return null
|
|
165
|
+
return Number(m[1]) * 60 + Number(m[2])
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 官方定价口径是**北京时间**(见上面 WINDOWS 的注释),
|
|
170
|
+
* 所以取"现在几点"必须换算到 UTC+8,**不能直接用 `now.getHours()`** ——
|
|
171
|
+
* 那个读的是**运行机器自己的时区**:部署在 UTC 的机器上会整整差 8 小时,
|
|
172
|
+
* 谷时窗口全部错位(issue #71)。
|
|
173
|
+
*
|
|
174
|
+
* 中国不实行夏令时,UTC+8 是固定偏移,所以直接按偏移算即可,
|
|
175
|
+
* 不依赖 `Intl` 时区数据库(某些精简 Node/Electron 构建里可能缺)。
|
|
176
|
+
*/
|
|
177
|
+
const BEIJING_OFFSET_MINUTES = 8 * 60
|
|
178
|
+
|
|
179
|
+
/** 把一个时刻换算成北京时间的 { 分钟数, 星期几(0=周日) } */
|
|
180
|
+
function beijingClock(now) {
|
|
181
|
+
const shifted = new Date(now.getTime() + BEIJING_OFFSET_MINUTES * 60 * 1000)
|
|
182
|
+
return {
|
|
183
|
+
// 用 getUTC* 读那个"平移过的"时刻 ⇒ 得到的就是北京时间的墙上时间
|
|
184
|
+
minutes: shifted.getUTCHours() * 60 + shifted.getUTCMinutes(),
|
|
185
|
+
weekday: shifted.getUTCDay(),
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 现在在不在这个窗口里(支持跨零点,比如 23:00–02:00)。
|
|
191
|
+
*
|
|
192
|
+
* ⚠️ 按**北京时间**判断,不是本机时区(issue #71)。
|
|
193
|
+
* ⚠️ 另外:官方口径里**整个周末都是谷时**,所以周六/周日一律返回 true ——
|
|
194
|
+
* 以前这里没判断周末,导致周末的 9–12 / 14–18 被当成高峰、该跑的时候没跑。
|
|
195
|
+
*/
|
|
196
|
+
export function inWindow(now, win) {
|
|
197
|
+
const start = minutesOf(win.start); const end = minutesOf(win.end)
|
|
198
|
+
if (start === null || end === null) return false
|
|
199
|
+
const { minutes: cur, weekday } = beijingClock(now)
|
|
200
|
+
// 周末全天谷时
|
|
201
|
+
if (weekday === 0 || weekday === 6) return true
|
|
202
|
+
return start <= end ? (cur >= start && cur < end) : (cur >= start || cur < end)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 本地日期 YYYY-MM-DD。
|
|
207
|
+
*
|
|
208
|
+
* 这里刻意保留**本机时区**:它用于「今天跑过没有」这类按使用者日历翻页的判断,
|
|
209
|
+
* 用本机日期比用北京时间更符合直觉(否则跨时区的使用者在晚上 8 点就被翻页)。
|
|
210
|
+
* 与 `inWindow` 的北京时间口径是两个不同用途,别混。
|
|
211
|
+
*/
|
|
212
|
+
export function dayKey(now = new Date()) {
|
|
213
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
214
|
+
return `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())}`
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 判重表里的日期格 → YYYY-MM-DD;认不出来返回 null
|
|
219
|
+
* ⭐ 模型会自己写短日期(`10-23`、`2026/10/23`、带时间的)⇒ 这里宽容地认(#133):
|
|
220
|
+
* 没写年份就按今年补;补出来比今天还晚(比如一月份读到 `12-31`)⇒ 算去年
|
|
221
|
+
*/
|
|
222
|
+
export function seenDay(raw, now = new Date()) {
|
|
223
|
+
const m = /^(?:(\d{4})[-/.])?(\d{1,2})[-/.](\d{1,2})(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?$/.exec(String(raw ?? '').trim())
|
|
224
|
+
if (!m) return null
|
|
225
|
+
const mo = Number(m[2]); const d = Number(m[3])
|
|
226
|
+
let y = m[1] ? Number(m[1]) : now.getFullYear()
|
|
227
|
+
const valid = (yy) => { const t = new Date(yy, mo - 1, d); return t.getFullYear() === yy && t.getMonth() === mo - 1 && t.getDate() === d }
|
|
228
|
+
if (!valid(y)) return null
|
|
229
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
230
|
+
if (!m[1] && `${y}-${p(mo)}-${p(d)}` > dayKey(now)) {
|
|
231
|
+
y -= 1
|
|
232
|
+
if (!valid(y)) return null // 02-29 遇上去年不是闰年
|
|
233
|
+
}
|
|
234
|
+
return `${y}-${p(mo)}-${p(d)}`
|
|
235
|
+
}
|
|
236
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** lib/uid.mjs —— 用昵称查 B站 UID(私信默认化之后,用户只填「@ 谁」就得能发)
|
|
2
|
+
* 为什么要它:默认投递改成「私信」以后,如果只认 dmUid,那么没填 UID 的用户会**一条都收不到** ✗
|
|
3
|
+
* 接口:/x/web-interface/search/type?search_type=bili_user&keyword=<昵称>(要带登录 cookie)
|
|
4
|
+
* 策略:先精确匹配 uname,再退到第一个结果;结果缓存进 <家>/uid-cache.json,避免每轮都打接口
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
|
|
9
|
+
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36'
|
|
10
|
+
|
|
11
|
+
function loadCred(stateDir) {
|
|
12
|
+
const f = join(stateDir, 'bili_credential.json')
|
|
13
|
+
if (!existsSync(f)) return null
|
|
14
|
+
try {
|
|
15
|
+
const c = JSON.parse(readFileSync(f, 'utf8'))
|
|
16
|
+
return c?.sessdata ? c : null
|
|
17
|
+
} catch { return null }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readCache(stateDir) {
|
|
21
|
+
try { return JSON.parse(readFileSync(join(stateDir, 'uid-cache.json'), 'utf8')) || {} } catch { return {} }
|
|
22
|
+
}
|
|
23
|
+
function writeCache(stateDir, obj) {
|
|
24
|
+
try { writeFileSync(join(stateDir, 'uid-cache.json'), JSON.stringify(obj, null, 2), 'utf8') } catch { /* 写不了就算了 */ }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @returns {Promise<number>} 0 = 没查到 */
|
|
28
|
+
export async function resolveUid(stateDir, name, log = () => {}) {
|
|
29
|
+
const q = String(name || '').trim()
|
|
30
|
+
if (!q) return 0
|
|
31
|
+
const cache = readCache(stateDir)
|
|
32
|
+
if (Number(cache[q]) > 0) return Number(cache[q])
|
|
33
|
+
const cred = loadCred(stateDir)
|
|
34
|
+
if (!cred) { log('查 UID 失败:还没扫码登录 B站'); return 0 }
|
|
35
|
+
const url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=bili_user&page=1&keyword='
|
|
36
|
+
+ encodeURIComponent(q)
|
|
37
|
+
try {
|
|
38
|
+
const r = await fetch(url, {
|
|
39
|
+
headers: {
|
|
40
|
+
'User-Agent': UA,
|
|
41
|
+
Referer: 'https://search.bilibili.com/',
|
|
42
|
+
Cookie: `SESSDATA=${cred.sessdata}; bili_jct=${cred.bili_jct}; buvid3=${cred.buvid3}`,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
const j = await r.json().catch(() => null)
|
|
46
|
+
const list = j?.data?.result || []
|
|
47
|
+
if (!list.length) { log(`查 UID:搜「${q}」没有结果`); return 0 }
|
|
48
|
+
const exact = list.find((u) => String(u.uname) === q)
|
|
49
|
+
const pick = exact || list[0]
|
|
50
|
+
const mid = Number(pick.mid) || 0
|
|
51
|
+
if (mid > 0) {
|
|
52
|
+
cache[q] = mid
|
|
53
|
+
writeCache(stateDir, cache)
|
|
54
|
+
log(`查 UID:「${q}」→ ${mid}(${pick.uname}${exact ? ',精确匹配' : ',第一个结果'})`)
|
|
55
|
+
}
|
|
56
|
+
return mid
|
|
57
|
+
} catch (e) {
|
|
58
|
+
log('查 UID 失败:' + String(e?.message ?? e))
|
|
59
|
+
return 0
|
|
60
|
+
}
|
|
61
|
+
}
|