dsh-chat-comprehension 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +41 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +54 -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 +3293 -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,634 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-agent-md —— 人格文件的读写与合成(纯 node: 内置模块,无任何第三方依赖)。
|
|
3
|
+
*
|
|
4
|
+
* 三层文件模型(优先级从高到低):
|
|
5
|
+
* 1. 项目内 AGENT.md <cwd>/AGENT.md —— 跟着仓库走,可提交进 git(可选启用)
|
|
6
|
+
* 2. 项目人格(本机存储) <base>/projects/<slug>.md —— 设置页里编辑的那份
|
|
7
|
+
* 3. 全局人格(本机存储) <base>/AGENT.md —— 所有会话的基础人设
|
|
8
|
+
*
|
|
9
|
+
* 生效 `project` 时只取 1、2 里优先级最高的那**一份**(避免两份打架);
|
|
10
|
+
* 全局人格默认作为底座一起注入,可在设置里关掉(includeGlobal=false →
|
|
11
|
+
* 纯项目人格)。
|
|
12
|
+
*
|
|
13
|
+
* 本文件刻意只 import node: 内置模块:本地 link: 安装时 Node 以真实路径解析
|
|
14
|
+
* 本插件,沿目录向上找不到 profile 的 node_modules,裸包名会解析失败。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
20
|
+
|
|
21
|
+
/** 人格文件最大可写字节(防手滑写进巨物)。 */
|
|
22
|
+
export const MAX_FILE_BYTES = 512 * 1024
|
|
23
|
+
/** 注入到系统提示里的正文上限(超出即截断,避免撑爆上下文)。 */
|
|
24
|
+
export const MAX_INJECT_CHARS = 40_000
|
|
25
|
+
/** 默认探测的项目内文件名(按顺序取第一个存在的)。 */
|
|
26
|
+
export const DEFAULT_LOCAL_NAMES = ['AGENT.md']
|
|
27
|
+
|
|
28
|
+
/** DSH 家目录(状态、人格文件都放这儿,与 DSH 其他用户数据同域)。 */
|
|
29
|
+
export function dshHome() {
|
|
30
|
+
const fromEnv = typeof process.env.DSH_HOME === 'string' ? process.env.DSH_HOME.trim() : ''
|
|
31
|
+
return fromEnv.length > 0 ? fromEnv : join(homedir(), '.dsh')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 人格文件根目录:<DSH_HOME>/agents。 */
|
|
35
|
+
export function agentsRoot() {
|
|
36
|
+
return join(dshHome(), 'agents')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 本插件自身状态文件:<DSH_HOME>/agent-md.json。 */
|
|
40
|
+
export function statePath() {
|
|
41
|
+
return join(dshHome(), 'agent-md.json')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 全局人格文件:<DSH_HOME>/AGENT.md。 */
|
|
45
|
+
export function globalPath() {
|
|
46
|
+
return join(dshHome(), 'AGENT.md')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 内置项目人格默认路径:<base>/default.md(用户没设项目时注入它)。 */
|
|
50
|
+
export function defaultProjectPath() {
|
|
51
|
+
return join(agentsRoot(), 'default.md')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 项目人格目录:<base>/projects。 */
|
|
55
|
+
export function projectsDir() {
|
|
56
|
+
return join(agentsRoot(), 'projects')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 内置模板目录:<base>/templates。 */
|
|
60
|
+
export function templatesDir() {
|
|
61
|
+
return join(agentsRoot(), 'templates')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 项目登记表:<base>/projects.json(只用于列出/去重,注入不依赖它)。 */
|
|
65
|
+
export function registryPath() {
|
|
66
|
+
return join(agentsRoot(), 'projects.json')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 全局字典:把工作目录规范化成可比较的键。
|
|
71
|
+
*
|
|
72
|
+
* ⚠️ 写文件时**绝不能**用这个键当文件名:Windows 上 `C:\Users\<你>` 里的 `:`
|
|
73
|
+
* 是非法文件名字符。文件名一律用短 slug(见 slugFor)。
|
|
74
|
+
*/
|
|
75
|
+
export function normalizePathKey(cwd) {
|
|
76
|
+
if (typeof cwd !== 'string') return ''
|
|
77
|
+
let p = cwd.trim().replace(/\\/g, '/')
|
|
78
|
+
if (p === '') return ''
|
|
79
|
+
// 统一去掉结尾斜杠(但保留根:C:/ 与 /)
|
|
80
|
+
if (p.length > 1 && p.endsWith('/')) p = p.replace(/\/+$/, '')
|
|
81
|
+
if (p === '') p = '/'
|
|
82
|
+
// Git / Windows 路径大小写不敏感;先比小写,展示时用登记表里的原始值
|
|
83
|
+
return p.toLowerCase()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** FNV-1a 32 位 → 8 位十六进制,用于生成短 slug。 */
|
|
87
|
+
function hash8(text) {
|
|
88
|
+
let h = 0x811c9dc5
|
|
89
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
90
|
+
h ^= text.charCodeAt(i)
|
|
91
|
+
h = Math.imul(h, 0x01000193) >>> 0
|
|
92
|
+
}
|
|
93
|
+
return h.toString(16).padStart(8, '0')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 路径 → 文件名安全的 slug(保留可读目录名 + 8 位哈希防撞)。 */
|
|
97
|
+
export function slugFor(cwd) {
|
|
98
|
+
const key = normalizePathKey(cwd)
|
|
99
|
+
if (key === '') return {
|
|
100
|
+
key: '',
|
|
101
|
+
slug: 'unknown',
|
|
102
|
+
fileName: 'unknown.md',
|
|
103
|
+
path: join(projectsDir(), 'unknown.md'),
|
|
104
|
+
}
|
|
105
|
+
const tail = key.replace(/\/+$/, '').split('/').filter((s) => s !== '').pop() || 'root'
|
|
106
|
+
// 只保留 ASCII 字母数字、汉字、连字符、下划线、点;其余一律 '-'
|
|
107
|
+
const safe = tail.replace(/[^0-9a-zA-Z\u4e00-\u9fa5._-]/g, '-').slice(0, 40) || 'root'
|
|
108
|
+
const slug = `${safe}-${hash8(key)}`
|
|
109
|
+
return { key, slug, fileName: `${slug}.md`, path: join(projectsDir(), `${slug}.md`) }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 人格名(展示用):路径最后一段;根目录回落成盘符/斜杠。 */
|
|
113
|
+
export function displayNameFor(cwd) {
|
|
114
|
+
const key = normalizePathKey(cwd)
|
|
115
|
+
if (key === '') return '(未命名)'
|
|
116
|
+
const parts = key.replace(/\/+$/, '').split('/').filter((s) => s !== '')
|
|
117
|
+
const tail = parts[parts.length - 1]
|
|
118
|
+
if (tail !== undefined && tail.length > 0) return tail
|
|
119
|
+
return key
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 模板变量降级:宿主(@deepseek-ai/dsh-system-prompt)的段渲染器把段正文里的
|
|
124
|
+
* `{{name}}` 当模板变量解析,未注册的名字会抛 unknown prompt variable 并让整轮
|
|
125
|
+
* 注入失败(只有 provider/model/cwd 是注册的)。用户在地道 Markdown 里写
|
|
126
|
+
* `{{xxx}}` 完全合法,所以注入前统一降级成 `{name}`——保留字面意思,不再被宿主解析。
|
|
127
|
+
*
|
|
128
|
+
* 已知风险(沿自 dsh-memory-evolve 的处理手法):理论上降级后的 `{'{'}` 相邻仍可能
|
|
129
|
+
* 被误判,但宿主只认 `{{` 开头,单花括号安全。
|
|
130
|
+
*/
|
|
131
|
+
export function sanitizeForHost(text) {
|
|
132
|
+
// 目标:正文里不再出现**连续两个左花括号**——宿主只把 `{{name}}` 当模板变量,
|
|
133
|
+
// 命中未注册的 name 就抛错并让整轮注入失败。
|
|
134
|
+
// 所以把任意长度的连续左花括号压成一个:`{{x}}` -> `{x}`。
|
|
135
|
+
// ⚠️ 右花括号必须原样保留(`{x}}` 不会被宿主解析);早先"再把 `}}` 也收掉"的写法
|
|
136
|
+
// 实测不可靠(JS 正则里连续右括号的转义在字符串/工具链上多次被吃掉),
|
|
137
|
+
// 而保留它是安全的——这条注释就是那个坑的记录。
|
|
138
|
+
return String(text).replace(/\{+/g, String.fromCharCode(123))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 项目内 AGENT.md 探测(同步 statSync:只有注入路径会用到,必须同步)。 */
|
|
142
|
+
export function localFileFor(cwd, localNames) {
|
|
143
|
+
if (typeof cwd !== 'string' || cwd.trim() === '') return null
|
|
144
|
+
const dir = resolve(cwd)
|
|
145
|
+
const names = Array.isArray(localNames) && localNames.length > 0 ? localNames : DEFAULT_LOCAL_NAMES
|
|
146
|
+
for (const name of names) {
|
|
147
|
+
if (typeof name !== 'string' || name.trim() === '') continue
|
|
148
|
+
const file = join(dir, name.trim())
|
|
149
|
+
try {
|
|
150
|
+
if (statSync(file).isFile()) return file
|
|
151
|
+
} catch {
|
|
152
|
+
// 不存在/无权限 → 试下一个候选名
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 读文件,失败或缺失返回 null(注入路径绝不能让读失败冒泡)。 */
|
|
159
|
+
export function readTextFile(file) {
|
|
160
|
+
try {
|
|
161
|
+
return readFileSync(file, 'utf8')
|
|
162
|
+
} catch {
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 原子写:先写 .tmp 再 rename,避免半截文件被会话读到。 */
|
|
168
|
+
export function writeTextFile(file, text) {
|
|
169
|
+
mkdirSync(dirname(resolve(file)), { recursive: true })
|
|
170
|
+
const tmp = `${file}.tmp-${process.pid}`
|
|
171
|
+
writeFileSync(tmp, text, 'utf8')
|
|
172
|
+
renameSync(tmp, file)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 统一的纯文本判定:去掉 BOM;CRLF/CR 一律归一到 LF。 */
|
|
176
|
+
export function normalizeText(raw) {
|
|
177
|
+
if (typeof raw !== 'string') return ''
|
|
178
|
+
return raw.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 空人格判定:剥掉 HTML 注释后没有正文就算空。
|
|
183
|
+
*
|
|
184
|
+
* ⚠️ 这里**刻意不把 Markdown 标题算空**(早先版本踩过):模板正文本身就是标题
|
|
185
|
+
* 形式(`# 你是谁` + 下面一句话),而用户写「# 这个项目里你是资深维护者」这种
|
|
186
|
+
* 单标题人格完全合法——把标题算空会让用户的真实人格被静默跳过。
|
|
187
|
+
* 注释承担「未填写」的信号:模板里的注释没删就是没写。
|
|
188
|
+
*/
|
|
189
|
+
export function isEffectivelyEmpty(raw) {
|
|
190
|
+
const text = normalizeText(raw)
|
|
191
|
+
if (text.trim() === '') return true
|
|
192
|
+
// 去掉 HTML 注释(`<!` 连写即注释起始,行首标记不参与匹配,避免模板里出现该字样时误判)
|
|
193
|
+
const stripped = text.replace(/<!--[\s\S]*?-->/g, '').trim()
|
|
194
|
+
return stripped === ''
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 剥掉 HTML 注释:注释是写给**用户看的说明**(模板里的填写提示),不该进模型的
|
|
199
|
+
* 上下文——既省 token,也避免「(例:…)」这类示例文字被模型当成真实设定执行。
|
|
200
|
+
*/
|
|
201
|
+
export function stripComments(raw) {
|
|
202
|
+
return normalizeText(raw).replace(/<!--[\s\S]*?-->/g, '').replace(/\n{3,}/g, '\n\n').trim()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** 项目登记表读写(读失败一律回退空表:登记表坏了不能影响注入)。 */
|
|
206
|
+
export function readRegistry() {
|
|
207
|
+
const file = registryPath()
|
|
208
|
+
const raw = readTextFile(file)
|
|
209
|
+
if (raw === null) return { version: 1, projects: [] }
|
|
210
|
+
try {
|
|
211
|
+
const parsed = JSON.parse(raw)
|
|
212
|
+
if (parsed !== null && typeof parsed === 'object' && Array.isArray(parsed.projects)) {
|
|
213
|
+
return { version: 1, projects: parsed.projects.filter((p) => p !== null && typeof p === 'object' && typeof p.slug === 'string') }
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
// 解析失败:当作空表(下次写入即修复)
|
|
217
|
+
}
|
|
218
|
+
return { version: 1, projects: [] }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** 登记一个项目(幂等:同 key 更新 cwd/lastSeen)。 */
|
|
222
|
+
export function registerProject(cwd, patch = {}) {
|
|
223
|
+
const key = normalizePathKey(cwd)
|
|
224
|
+
if (key === '') return readRegistry()
|
|
225
|
+
const registry = readRegistry()
|
|
226
|
+
const { slug, path } = slugFor(cwd)
|
|
227
|
+
const now = new Date().toISOString()
|
|
228
|
+
const existing = registry.projects.find((p) => p !== null && typeof p === 'object' && p.key === key)
|
|
229
|
+
if (existing !== undefined) {
|
|
230
|
+
existing.cwd = cwd
|
|
231
|
+
existing.slug = slug
|
|
232
|
+
existing.path = path
|
|
233
|
+
existing.lastSeen = now
|
|
234
|
+
if (typeof patch.active === 'boolean') existing.active = patch.active
|
|
235
|
+
} else {
|
|
236
|
+
registry.projects.push({ key, cwd, displayName: displayNameFor(cwd), slug, path, lastSeen: now, active: patch.active === true })
|
|
237
|
+
}
|
|
238
|
+
// 只留最近 200 个:登记表是展示用的,不是真相来源
|
|
239
|
+
registry.projects.sort((a, b) => String(b.lastSeen || '').localeCompare(String(a.lastSeen || '')))
|
|
240
|
+
registry.projects = registry.projects.slice(0, 200)
|
|
241
|
+
try {
|
|
242
|
+
writeTextFile(registryPath(), `${JSON.stringify(registry, null, 2)}\n`)
|
|
243
|
+
} catch {
|
|
244
|
+
// 写失败不影响注入
|
|
245
|
+
}
|
|
246
|
+
return registry
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** 单个项目人格正文随 /state 一起回传的上限(超过就只报状态,正文按需再拉)。 */
|
|
250
|
+
export const MAX_INLINE_CONTENT_CHARS = 64_000
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 一份项目人格的最新状态(正文 + 时间 + 字节)。
|
|
254
|
+
*
|
|
255
|
+
* ⚠️ 这里必须带上 `content`:设置页的项目页签靠它填编辑框。早先版本只回 `exists`
|
|
256
|
+
* 不回正文,于是「文件明明有内容、编辑框却是空的」——用户一按保存就把文件写空,
|
|
257
|
+
* 这是「项目人格看起来没生效」的真凶之一。
|
|
258
|
+
*/
|
|
259
|
+
function projectDetail(cwd, file) {
|
|
260
|
+
const raw = readTextFile(file)
|
|
261
|
+
let bytes = 0
|
|
262
|
+
try {
|
|
263
|
+
bytes = statSync(file).size
|
|
264
|
+
} catch {
|
|
265
|
+
bytes = 0
|
|
266
|
+
}
|
|
267
|
+
const text = raw === null ? '' : normalizeText(raw)
|
|
268
|
+
const tooBig = text.length > MAX_INLINE_CONTENT_CHARS
|
|
269
|
+
return {
|
|
270
|
+
path: file,
|
|
271
|
+
exists: raw !== null,
|
|
272
|
+
empty: raw === null ? true : isEffectivelyEmpty(raw),
|
|
273
|
+
updatedAt: raw === null ? null : mtimeIso(file),
|
|
274
|
+
bytes,
|
|
275
|
+
content: tooBig ? '' : text,
|
|
276
|
+
contentTruncated: tooBig,
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** 列出<按登记表 + 磁盘>的项目人格清单(磁盘上存在但没登记的也列出来)。 */
|
|
281
|
+
export function listProjects() {
|
|
282
|
+
const registry = readRegistry()
|
|
283
|
+
const out = []
|
|
284
|
+
for (const p of registry.projects) {
|
|
285
|
+
if (typeof p.key !== 'string' || p.key === '') continue
|
|
286
|
+
const cwd = typeof p.cwd === 'string' ? p.cwd : ''
|
|
287
|
+
const file = typeof p.path === 'string' && p.path !== '' ? p.path : slugFor(cwd).path
|
|
288
|
+
out.push({
|
|
289
|
+
key: p.key,
|
|
290
|
+
slug: typeof p.slug === 'string' ? p.slug : slugFor(cwd).slug,
|
|
291
|
+
cwd,
|
|
292
|
+
displayName: typeof p.displayName === 'string' && p.displayName !== '' ? p.displayName : displayNameFor(cwd),
|
|
293
|
+
lastSeen: typeof p.lastSeen === 'string' ? p.lastSeen : '',
|
|
294
|
+
...projectDetail(cwd, file),
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
// 磁盘上存在但登记表没有的(手写文件/换机器):补进来
|
|
298
|
+
let files = []
|
|
299
|
+
try {
|
|
300
|
+
files = readdirSync(projectsDir()).filter((f) => f.endsWith('.md'))
|
|
301
|
+
} catch {
|
|
302
|
+
files = []
|
|
303
|
+
}
|
|
304
|
+
for (const f of files) {
|
|
305
|
+
if (f.startsWith('_')) continue
|
|
306
|
+
const full = join(projectsDir(), f)
|
|
307
|
+
if (out.some((p) => p.path === full)) continue
|
|
308
|
+
const slug = f.replace(/\.md$/, '')
|
|
309
|
+
out.push({ key: '', slug, cwd: '', displayName: slug, lastSeen: '', ...projectDetail('', full) })
|
|
310
|
+
}
|
|
311
|
+
out.sort((a, b) => String(b.lastSeen || '').localeCompare(String(a.lastSeen || '')))
|
|
312
|
+
return out
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ---- 本机所有工作区(DSH workspace 表 + 会话目录 + 插件登记表)-------------
|
|
316
|
+
|
|
317
|
+
/** DSH 自己维护的工作区表:<DSH_HOME>/storages/workspace.json。 */
|
|
318
|
+
export function workspaceStorePath() {
|
|
319
|
+
return join(dshHome(), 'storages', 'workspace.json')
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** 会话目录根:<DSH_HOME>/sessions(DSH 给每个工作区一个目录)。 */
|
|
323
|
+
export function sessionsRoot() {
|
|
324
|
+
return join(dshHome(), 'sessions')
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* DSH 会话目录名 → 工作目录。
|
|
329
|
+
*
|
|
330
|
+
* DSH 把 cwd 编码成目录名:`D:\肥鱼` → `--D-~80A5~9C7C--`。规则是**盘符冒号与路径
|
|
331
|
+
* 分隔符都写成 `-`**,非 ASCII/不安全字符写成 `~XXXX`(UTF-16 码元)。这是枚举
|
|
332
|
+
* 「本机用过哪些工作区」的兜底来源,所以哪怕带点启发式也留着。
|
|
333
|
+
*/
|
|
334
|
+
export function decodeSessionDirName(name) {
|
|
335
|
+
if (typeof name !== 'string' || name.length < 5) return ''
|
|
336
|
+
if (!name.startsWith('--') || !name.endsWith('--')) return ''
|
|
337
|
+
const body = name.slice(2, -2)
|
|
338
|
+
if (body === '') return ''
|
|
339
|
+
const sep = process.platform === 'win32' ? '\\' : '/'
|
|
340
|
+
let text = ''
|
|
341
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
342
|
+
if (body[i] === '~' && /^[0-9A-Fa-f]{4}$/.test(body.slice(i + 1, i + 5))) {
|
|
343
|
+
text += String.fromCharCode(parseInt(body.slice(i + 1, i + 5), 16))
|
|
344
|
+
i += 4
|
|
345
|
+
continue
|
|
346
|
+
}
|
|
347
|
+
text += body[i] === '-' ? sep : body[i]
|
|
348
|
+
}
|
|
349
|
+
// 盘符的冒号也被写成了 `-`(`D-team` 其实是 `D:\team`),这里补回来
|
|
350
|
+
return text.replace(/^([A-Za-z])[\\/]/, `$1:${sep}`).replace(/[\\/]+$/, '')
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** 读 DSH 的工作区表(坏文件回退空表:列工作区失败不能拖垮设置页)。 */
|
|
354
|
+
export function readWorkspaceStore() {
|
|
355
|
+
const raw = readTextFile(workspaceStorePath())
|
|
356
|
+
if (raw === null) return []
|
|
357
|
+
try {
|
|
358
|
+
const parsed = JSON.parse(raw)
|
|
359
|
+
const table = parsed !== null && typeof parsed === 'object' && parsed.tables !== undefined ? parsed.tables.workspaces : undefined
|
|
360
|
+
if (table === null || table === undefined || typeof table !== 'object') return []
|
|
361
|
+
return Object.values(table).filter((w) => w !== null && typeof w === 'object' && typeof w.path === 'string' && w.path.trim() !== '')
|
|
362
|
+
} catch {
|
|
363
|
+
return []
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* 本机所有已知工作区(设置页「项目」下拉的清单)。
|
|
369
|
+
*
|
|
370
|
+
* 三个来源合并去重,按最近活跃倒序:
|
|
371
|
+
* 1. DSH 的工作区表(最权威,带 title / updatedAt);
|
|
372
|
+
* 2. 插件自己的项目登记表(写过人格的);
|
|
373
|
+
* 3. `~/.dsh/sessions` 目录名(老工作区、没进工作区表的也捞得回来)。
|
|
374
|
+
*/
|
|
375
|
+
export function listWorkspaces() {
|
|
376
|
+
const map = new Map()
|
|
377
|
+
const ensure = (cwd) => {
|
|
378
|
+
if (typeof cwd !== 'string' || cwd.trim() === '') return null
|
|
379
|
+
const key = normalizePathKey(cwd)
|
|
380
|
+
if (key === '') return null
|
|
381
|
+
let entry = map.get(key)
|
|
382
|
+
if (entry === undefined) {
|
|
383
|
+
entry = { key, cwd, title: '', sources: [], lastActive: '', sessionCount: 0, registered: false }
|
|
384
|
+
map.set(key, entry)
|
|
385
|
+
}
|
|
386
|
+
return entry
|
|
387
|
+
}
|
|
388
|
+
const mark = (entry, source) => {
|
|
389
|
+
if (entry !== null && !entry.sources.includes(source)) entry.sources.push(source)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
for (const w of readWorkspaceStore()) {
|
|
393
|
+
const entry = ensure(w.path)
|
|
394
|
+
if (entry === null) continue
|
|
395
|
+
mark(entry, 'workspace')
|
|
396
|
+
if (typeof w.title === 'string' && w.title !== '') entry.title = w.title
|
|
397
|
+
if (typeof w.updatedAt === 'string' && w.updatedAt > entry.lastActive) entry.lastActive = w.updatedAt
|
|
398
|
+
if (Array.isArray(w.sessionIds)) entry.sessionCount = Math.max(entry.sessionCount, w.sessionIds.length)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
for (const p of readRegistry().projects) {
|
|
402
|
+
const entry = ensure(typeof p.cwd === 'string' ? p.cwd : '')
|
|
403
|
+
if (entry === null) continue
|
|
404
|
+
mark(entry, 'persona')
|
|
405
|
+
entry.registered = true
|
|
406
|
+
if (typeof p.lastSeen === 'string' && p.lastSeen > entry.lastActive) entry.lastActive = p.lastSeen
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let dirs = []
|
|
410
|
+
try {
|
|
411
|
+
dirs = readdirSync(sessionsRoot(), { withFileTypes: true })
|
|
412
|
+
} catch {
|
|
413
|
+
dirs = []
|
|
414
|
+
}
|
|
415
|
+
for (const d of dirs) {
|
|
416
|
+
if (d.isDirectory() !== true) continue
|
|
417
|
+
const cwd = decodeSessionDirName(d.name)
|
|
418
|
+
if (!/^[A-Za-z]:[\\/]/.test(cwd) && !cwd.startsWith('/')) continue
|
|
419
|
+
const entry = ensure(cwd)
|
|
420
|
+
if (entry === null) continue
|
|
421
|
+
mark(entry, 'sessions')
|
|
422
|
+
try {
|
|
423
|
+
const iso = statSync(join(sessionsRoot(), d.name)).mtime.toISOString()
|
|
424
|
+
if (iso > entry.lastActive) entry.lastActive = iso
|
|
425
|
+
} catch {
|
|
426
|
+
// 读不到时间就只按目录名收录
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const out = []
|
|
431
|
+
for (const entry of map.values()) {
|
|
432
|
+
const { slug, path: file } = slugFor(entry.cwd)
|
|
433
|
+
out.push({
|
|
434
|
+
key: entry.key,
|
|
435
|
+
slug,
|
|
436
|
+
cwd: entry.cwd,
|
|
437
|
+
displayName: entry.title !== '' ? entry.title : displayNameFor(entry.cwd),
|
|
438
|
+
sources: entry.sources,
|
|
439
|
+
lastActive: entry.lastActive,
|
|
440
|
+
sessionCount: entry.sessionCount,
|
|
441
|
+
registered: entry.registered,
|
|
442
|
+
path: file,
|
|
443
|
+
exists: existsSync(file),
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
out.sort((a, b) => String(b.lastActive || '').localeCompare(String(a.lastActive || '')))
|
|
447
|
+
return out
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** 候选模板清单(<base>/templates/*.md)。 */
|
|
451
|
+
export function listTemplates() {
|
|
452
|
+
try {
|
|
453
|
+
return readdirSync(templatesDir())
|
|
454
|
+
.filter((f) => f.endsWith('.md'))
|
|
455
|
+
.map((f) => ({ id: f.replace(/\.md$/, ''), name: f.replace(/\.md$/, ''), path: join(templatesDir(), f) }))
|
|
456
|
+
} catch {
|
|
457
|
+
return []
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** 解析一个人格文件的「有效来源」:项目内 > 内置项目 > 无。 */
|
|
462
|
+
export function resolveProjectPersona(cwd, localNames) {
|
|
463
|
+
const local = localFileFor(cwd, localNames)
|
|
464
|
+
if (local !== null) {
|
|
465
|
+
const content = readTextFile(local)
|
|
466
|
+
if (content !== null && !isEffectivelyEmpty(content)) return { kind: 'local', path: local, content }
|
|
467
|
+
}
|
|
468
|
+
const stored = slugFor(cwd).path
|
|
469
|
+
const content = readTextFile(stored)
|
|
470
|
+
if (content !== null && !isEffectivelyEmpty(content)) return { kind: 'project', path: stored, content }
|
|
471
|
+
return null
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** 深读一个人格文件的状态(给设置页用)。 */
|
|
475
|
+
export function fileInfo(file, label) {
|
|
476
|
+
const raw = readTextFile(file)
|
|
477
|
+
return {
|
|
478
|
+
label,
|
|
479
|
+
path: file,
|
|
480
|
+
exists: raw !== null,
|
|
481
|
+
empty: raw === null ? true : isEffectivelyEmpty(raw),
|
|
482
|
+
bytes: raw === null ? 0 : Buffer.byteLength(raw, 'utf8'),
|
|
483
|
+
updatedAt: raw === null ? null : mtimeIso(file),
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** 文件修改时间(ISO);失败返回 null。 */
|
|
488
|
+
export function mtimeIso(file) {
|
|
489
|
+
try {
|
|
490
|
+
return statSync(file).mtime.toISOString()
|
|
491
|
+
} catch {
|
|
492
|
+
return null
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* 合成注入正文。
|
|
498
|
+
*
|
|
499
|
+
* @param {object} options
|
|
500
|
+
* @param {string} options.cwd - 当前会话工作目录
|
|
501
|
+
* @param {object} options.config - { enabled, includeGlobal, localNames, projectPersonaEnabled }
|
|
502
|
+
* @returns {{ text: string, sources: Array<{label:string,path:string,chars:number}>, note: string }}
|
|
503
|
+
*/
|
|
504
|
+
export function composePersona(options) {
|
|
505
|
+
const cwd = typeof options.cwd === 'string' ? options.cwd : ''
|
|
506
|
+
const config = options.config !== null && typeof options.config === 'object' ? options.config : {}
|
|
507
|
+
const includeGlobal = config.includeGlobal !== false
|
|
508
|
+
const localNames = Array.isArray(config.localNames) ? config.localNames : DEFAULT_LOCAL_NAMES
|
|
509
|
+
const useProject = config.projectPersonaEnabled !== false
|
|
510
|
+
|
|
511
|
+
const sources = []
|
|
512
|
+
const blocks = []
|
|
513
|
+
|
|
514
|
+
if (includeGlobal) {
|
|
515
|
+
const gp = globalPath()
|
|
516
|
+
const raw = readTextFile(gp)
|
|
517
|
+
if (raw !== null && !isEffectivelyEmpty(raw)) {
|
|
518
|
+
const body = stripComments(raw)
|
|
519
|
+
blocks.push(`### 全局人格(对所有会话生效)\n适用文件:${gp}\n\n${body}`)
|
|
520
|
+
sources.push({ label: '全局', path: gp, chars: body.length })
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (useProject && cwd !== '') {
|
|
525
|
+
const found = resolveProjectPersona(cwd, localNames)
|
|
526
|
+
if (found !== null) {
|
|
527
|
+
const body = stripComments(found.content)
|
|
528
|
+
const named = displayNameFor(cwd)
|
|
529
|
+
blocks.push(`### 当前项目人格(进「${named}」时生效,优先于全局人格)\n适用项目:${cwd}\n适用文件:${found.path}\n\n${body}`)
|
|
530
|
+
sources.push({ label: '项目', path: found.path, chars: body.length, kind: found.kind })
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (blocks.length === 0) return { text: '', sources, note: '' }
|
|
535
|
+
|
|
536
|
+
let body = blocks.join('\n\n')
|
|
537
|
+
let note = ''
|
|
538
|
+
if (body.length > MAX_INJECT_CHARS) {
|
|
539
|
+
body = `${body.slice(0, MAX_INJECT_CHARS)}\n\n(人格正文过长已截断,请精简 AGENT.md。)`
|
|
540
|
+
note = 'truncated'
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const text = [
|
|
544
|
+
'## 人格设定(AGENT.md)',
|
|
545
|
+
'以下是用户为本机写下的角色/性格设定,是「你是谁、怎么说话、怎么做事」的第一依据,请始终照此扮演:',
|
|
546
|
+
'',
|
|
547
|
+
body,
|
|
548
|
+
'',
|
|
549
|
+
'约束:人格设定只决定语气、风格与行事偏好,不改变安全规则、工具用法与任务事实;两者冲突时以安全规则和事实为准。',
|
|
550
|
+
].join('\n')
|
|
551
|
+
|
|
552
|
+
return { text: sanitizeForHost(text), sources, note }
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** 删除一个人格文件(存在才删)。 */
|
|
556
|
+
export function removeFile(file) {
|
|
557
|
+
try {
|
|
558
|
+
unlinkSync(file)
|
|
559
|
+
return true
|
|
560
|
+
} catch {
|
|
561
|
+
return false
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** 给人格文件根目录建好全部子目录。 */
|
|
566
|
+
export function ensureDirs() {
|
|
567
|
+
for (const dir of [agentsRoot(), projectsDir(), templatesDir()]) {
|
|
568
|
+
try {
|
|
569
|
+
mkdirSync(dir, { recursive: true })
|
|
570
|
+
} catch {
|
|
571
|
+
// 建不了目录时读取路径照常降级(读不到就是没人格)
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** 判断某路径是否位于人格根目录内(防越权读写)。 */
|
|
577
|
+
export function isInsideAgentsRoot(file) {
|
|
578
|
+
const root = resolve(agentsRoot())
|
|
579
|
+
const target = resolve(file)
|
|
580
|
+
const sep = process.platform === 'win32' ? '\\' : '/'
|
|
581
|
+
return target === root || target.startsWith(root + sep)
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** 内置人格模板:新建文件时的初始内容。 */
|
|
585
|
+
export function buildTemplate(kind, name) {
|
|
586
|
+
const label = typeof name === 'string' && name !== '' ? name : '未命名'
|
|
587
|
+
if (kind === 'global') {
|
|
588
|
+
return [
|
|
589
|
+
'<!-- AGENT.md · 全局人格:对所有会话生效。写完后保存即生效(下一个回合开始) -->',
|
|
590
|
+
'',
|
|
591
|
+
'# 你是谁',
|
|
592
|
+
'',
|
|
593
|
+
'(例:你是「先生」的专属助手,说话简洁、直接给结论,不说客套话。)',
|
|
594
|
+
'',
|
|
595
|
+
'# 语气与风格',
|
|
596
|
+
'',
|
|
597
|
+
'- 中文回答,句子短,先给结论再给理由',
|
|
598
|
+
'- 不确定就说不确定,不编造',
|
|
599
|
+
'',
|
|
600
|
+
'# 行事偏好',
|
|
601
|
+
'',
|
|
602
|
+
'- 动手前先确认关键歧义;能一次做完的不要来回问',
|
|
603
|
+
'',
|
|
604
|
+
'# 边界',
|
|
605
|
+
'',
|
|
606
|
+
'- 不改变安全规则与事实判断',
|
|
607
|
+
'',
|
|
608
|
+
].join('\n')
|
|
609
|
+
}
|
|
610
|
+
return [
|
|
611
|
+
'<!-- AGENT.md · 项目人格:只在进入这个项目时生效,优先级高于全局人格 -->',
|
|
612
|
+
`<!-- 项目:${label} -->`,
|
|
613
|
+
'',
|
|
614
|
+
'# 在这个项目里你是谁',
|
|
615
|
+
'',
|
|
616
|
+
'(例:你是这个仓库的资深维护者,熟悉它的架构,改动前先读代码。)',
|
|
617
|
+
'',
|
|
618
|
+
'# 本项目特有的规矩',
|
|
619
|
+
'',
|
|
620
|
+
'- (例:改完必须跑一遍测试)',
|
|
621
|
+
'- (例:注释用中文,提交信息用英文)',
|
|
622
|
+
'',
|
|
623
|
+
].join('\n')
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** 项目人格的文件名(暴露给 API 层做「新建」)。 */
|
|
627
|
+
export function projectFileFor(cwd) {
|
|
628
|
+
return slugFor(cwd).path
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** 目录名(给设置页显示)。 */
|
|
632
|
+
export function baseDirName() {
|
|
633
|
+
return basename(agentsRoot())
|
|
634
|
+
}
|