qq-bot-roost 1.1.13 → 1.1.15

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/README.md CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  <img src="https://img.shields.io/badge/Node.js-22.13%2B-339933?logo=node.js&logoColor=white" alt="Node.js 22.13+">
10
10
  <img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="零依赖">
11
- <img src="https://img.shields.io/badge/tests-1445%20passed-brightgreen" alt="测试 1445 项">
11
+ <img src="https://img.shields.io/badge/tests-1481%20passed-brightgreen" alt="测试 1481 项">
12
12
  <img src="https://img.shields.io/badge/plugins-JS%20%7C%20Python%20%7C%20Go%20%7C%20any-blue" alt="多语言插件">
13
- <img src="https://img.shields.io/badge/version-1.1.13-blueviolet" alt="版本 1.1.13">
13
+ <img src="https://img.shields.io/badge/version-1.1.15-blueviolet" alt="版本 1.1.15">
14
14
  <img src="https://img.shields.io/badge/license-AGPL--3.0--only-blue" alt="AGPL-3.0-only">
15
15
  <a href="https://github.com/roost-qq/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/roost-qq/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
16
16
 
@@ -508,7 +508,7 @@ bot/
508
508
  │ └── plugin/ 插件加载、配置、依赖、子进程宿主、面板页面注册
509
509
  ├── test/
510
510
  │ ├── selftest.mjs 框架自检(712 项)
511
- │ ├── e2e.mjs 端到端测试(253 项,起真实服务打接口)
511
+ │ ├── e2e.mjs 端到端测试(244 项,起真实服务打接口)
512
512
  │ ├── qrlogin.mjs 扫码建机器人(8 项)
513
513
  │ └── deps.mjs 插件依赖安装(11 项)
514
514
  ├── web/ 面板前端(原生 JS/CSS,无构建)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qq-bot-roost",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "type": "module",
5
5
  "description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
6
6
  "license": "AGPL-3.0-only",
@@ -30,9 +30,9 @@
30
30
  "mock": "node src/main.js --mock",
31
31
  "check": "node src/main.js --check",
32
32
  "release:prepare": "node scripts/release-prepare.mjs",
33
- "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
33
+ "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/market-hash-dual.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/mention-routing.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/media-time.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
34
34
  "test:e2e": "node test/e2e.mjs",
35
- "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
35
+ "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/market-hash-dual.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/mention-routing.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/healthz-identity.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/deps-mirror.mjs && node --test test/faces.mjs && node --test test/md-image.mjs && node --test test/market-source.mjs && node --test test/hashdir-sums.mjs",
36
36
  "check:secrets": "node scripts/check-secrets.mjs",
37
37
  "create": "node scripts/create-plugin.mjs",
38
38
  "test:plugin": "node scripts/test-plugin.mjs",
package/src/bot.js CHANGED
@@ -1178,7 +1178,17 @@ export class BotRuntime {
1178
1178
  * 传的是**完整 msg**(含 uin / msgIdx / attachments),不走 message-bus——
1179
1179
  * 那条通道的 payload 是对外契约,故意脱敏过,拿不到 ID 映射要的东西。
1180
1180
  */
1181
- if (hasMessageContent(msg)) {
1181
+ /**
1182
+ * 「静默消息是否交给协议层」开关(plugins.forwardSilentToProtocol,默认 true):
1183
+ * silent 消息(@ 别的机器人 / 只回@模式的闲聊 / 命令必须@模式的裸命令)
1184
+ * 在框架内部一律不响应,但要不要让 DSH 宿主 / OneBot 客户端也看到它,
1185
+ * 交给用户决定——默认照旧全交(`!== false` 让没写过这个字段的老配置保持原样)。
1186
+ * 关掉后这些消息不进协议层:DSH 的 ai 模式就不会再「补一句」(issue #38 的另一半)。
1187
+ * 注意转发在下面的静默闸之前,所以必须在这一层拦;观测通道(message-bus /
1188
+ * 日志)仍看得到,面板能查「确实收到过这条」。
1189
+ */
1190
+ const forwardSilent = cfg?.plugins?.forwardSilentToProtocol !== false;
1191
+ if (hasMessageContent(msg) && (!msg.silent || forwardSilent)) {
1182
1192
  this.onebot?.onMessage(msg);
1183
1193
  /** 宿主协议:传完整 msg(原生结构),它自己挑字段 */
1184
1194
  this.host?.onMessage(msg);
@@ -1208,7 +1218,8 @@ export class BotRuntime {
1208
1218
 
1209
1219
  this.logIncoming(msg);
1210
1220
 
1211
- if (msg.mentioned || msg.isCommand) session.markAddressed(msg.chatId);
1221
+ // @ 别的机器人 / 只回@模式下的裸命令:不写免@窗口,免得后续闲聊被当 addressed(issue #38)
1222
+ if (!msg.silent && (msg.mentioned || msg.isCommand)) session.markAddressed(msg.chatId);
1212
1223
 
1213
1224
  /**
1214
1225
  * 兼容模式「独占」:**插件**不再回话,内核命令也只留绑定那四条。
@@ -1251,6 +1262,14 @@ export class BotRuntime {
1251
1262
 
1252
1263
  this.#rememberPerson(msg);
1253
1264
 
1265
+ /**
1266
+ * 静默消息(issue #38):明确 @ 了别的机器人,或「只回@ / 命令必须@」模式下的裸命令。
1267
+ * 放在 pipeline 之后:去重 / 白名单 / 限流 / 暂停闸照跑(别的地方也别想绕过),
1268
+ * 但到这里整条掐断——不执行命令、不 session.deliver、不进插件与 AI 模型。
1269
+ * 观测(metrics / stats / 记人)在上面已经做完,面板仍看得到「收到过这条」。
1270
+ */
1271
+ if (msg.silent) return;
1272
+
1254
1273
  if (msg.isCommand && commandEntry) {
1255
1274
  /**
1256
1275
  * 独占模式只放行「绑定四件套」,其余内核命令一律静默。
package/src/config.js CHANGED
@@ -177,10 +177,43 @@ const GLOBAL_DEFAULTS = {
177
177
  intervalHours: 6,
178
178
  },
179
179
 
180
- plugins: {
181
- autoInstallDeps: true,
182
- /** Go 插件用的 go 可执行文件路径,留空则用 PATH 里的 go 或 GO_BIN 环境变量 */
183
- goBin: '',
180
+ plugins: {
181
+ autoInstallDeps: true,
182
+ /**
183
+ * 插件市场安装 / 更新时校验目录内容哈希,默认开。
184
+ * 关掉等于放弃供应链完整性校验(只靠 https 和索引本身),市场页会明确提示风险;
185
+ * 只在索引与框架算法版本错位的过渡期临时用,修好后请打开。
186
+ */
187
+ verifyHash: true,
188
+ /**
189
+ * 只回 @ 消息(全局,默认关;只作用于群聊)。
190
+ * 开后群聊里只有明确 @ 本机器人的消息才算 addressed——裸 `/命令`、
191
+ * 普通闲聊、免@窗口一律静默。单聊天生一对一,不受影响。
192
+ * 与 commandRequiresMention 可叠加:前者管所有消息,后者只管命令。
193
+ */
194
+ groupOnlyMentioned: false,
195
+ /**
196
+ * @ 了别的机器人就静默(默认开;issue #38)。
197
+ * 群里同时有好几个机器人时,@ 别的机器人不该把本机器人吵起来。
198
+ * 默认开、行为与修复前一致地「只理 @ 我的」;关掉则恢复旧行为
199
+ * (官方 mentions 里 bot=true 也算 @ 我,容易误触发)。同时 @ 我仍照常回复。
200
+ */
201
+ ignoreOtherBotMention: true,
202
+ /**
203
+ * 命令必须 @ 才回复(全局,默认关;只作用于群聊,issue #38)。
204
+ * 开后群聊里裸 `/命令` 静默(不解析、不回「没有这个命令」),
205
+ * 但普通闲聊照旧进插件 / 模型。只要明确了 @ 别的机器人,无论本开关如何都静默。
206
+ */
207
+ commandRequiresMention: false,
208
+ /**
209
+ * 静默消息是否交给协议层(默认 true;issue #38)。
210
+ * silent 消息(@ 别的机器人 / 上面两个开关静默掉的消息)在框架内部一律不响应;
211
+ * 这个开关只决定要不要把它们推给 DSH 宿主与 OneBot 客户端。默认全交、行为不变;
212
+ * 关掉后协议层看不到这些消息,DSH 的 ai 模式也就不会「补一句」。
213
+ */
214
+ forwardSilentToProtocol: true,
215
+ /** Go 插件用的 go 可执行文件路径,留空则用 PATH 里的 go 或 GO_BIN 环境变量 */
216
+ goBin: '',
184
217
  /**
185
218
  * 插件市场索引地址,换成你自己的插件仓库即可。
186
219
  *
package/src/hashdir.js CHANGED
@@ -16,6 +16,12 @@
16
16
  * **换行符要归一**:Windows 上 `core.autocrlf=true` 的仓库,检出是 CRLF,
17
17
  * 而 GitHub 打的 tarball 里是 LF。按原始字节哈希,两边永远对不上,
18
18
  * 结果是「每个插件都校验失败」——比不校验更糟。所以文本文件统一按 LF 算。
19
+ *
20
+ * 两套算法(与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 同步):
21
+ * · algo1 = 老算法,纯文档 / LICENSE 计入指纹;旧索引的 `sha256` 是它算的;
22
+ * · algo2 = 现行算法(HASH_ALGO),排除文档与运行时状态;`sha256_v2` 是它算的。
23
+ * 安装 / 更新时两个都认(见 plugin/market.js 的 entryHashes);框架自更新的
24
+ * `hashFileList()` 仍只走下面的 `isHashedFile()`,行为不变——别把两套规则混起来。
19
25
  */
20
26
  import fs from 'node:fs/promises';
21
27
  import path from 'node:path';
@@ -23,19 +29,39 @@ import crypto from 'node:crypto';
23
29
  import { HASH_SKIP } from './skipdirs.js';
24
30
 
25
31
  /**
26
- * 不参与哈希的东西见 ./skipdirs.js(HASH_SKIP)。
27
- * **改它会改变已发布插件的 sha256,必须同步重建 index.json。**
32
+ * algo1 的老跳过表:1.4.0 及以前就是这几项,只用来校验旧索引的 `sha256`。
33
+ * 来自 ./skipdirs.js 的 HASH_SKIP——改它会改变已发布插件的 sha256,必须同步重建索引。
34
+ */
35
+ const LEGACY_SKIP_DIRS = HASH_SKIP;
36
+ const LEGACY_SKIP_FILES = new Set(['.deps.json', '.DS_Store', 'Thumbs.db']);
37
+
38
+ /**
39
+ * algo2 额外排除:旧依赖位置、抽帧目录与运行时状态文件。
40
+ * 这些文件不入库,但用户机器上会生成——带进去会让同一份插件算出不同指纹。
28
41
  */
29
- const SKIP_DIRS = HASH_SKIP;
30
- const SKIP_FILES = new Set(['.deps.json', '.DS_Store', 'Thumbs.db']);
42
+ const SKIP_DIRS_ALGO2 = new Set([...HASH_SKIP, 'deps', 'shots']);
43
+ const SKIP_FILES_ALGO2 = new Set([
44
+ ...LEGACY_SKIP_FILES,
45
+ 'ui-data.json', 'qr.png', 'cookie.txt',
46
+ 'replies.json', 'replied.json', 'pending.json', 'history.json', 'seen.json',
47
+ ]);
48
+
49
+ /** 纯文档不进 algo2 指纹:改 README / LICENSE 不该逼维护者重算索引。 */
50
+ function isDocFile(name) {
51
+ const lower = name.toLowerCase();
52
+ return lower.endsWith('.md') || /^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower);
53
+ }
54
+
55
+ /** 算法版本。与插件仓 scripts/hashdir.mjs、dsh-roost src/ext-bundle.js 保持一致。 */
56
+ export const HASH_ALGO = 2;
31
57
 
32
58
  /**
33
- * 一个相对路径(`/` 分隔,含文件名)是否参与内容指纹。
59
+ * 一个相对路径(`/` 分隔,含文件名)是否参与**框架自更新**的内容指纹。
34
60
  *
35
- * **这是唯一的排除规则**,目录遍历(collect)和发版脚本(build-sums.mjs)
36
- * 都必须调它,不能各自复制一份判断——2026-11 就因为发版脚本漏了这里的
37
- * 文档排除规则,导致 SHA256SUMS 记录的指纹含 17 个 md/LICENSE、而更新器
38
- * 解包后算出的不含,v1.1.11 及之后所有版本的自更新全部校验失败。
61
+ * **只服务 hashFileList()(框架自更新 / SHA256SUMS)**,不是插件目录哈希的排除规则:
62
+ * 插件目录哈希走下面 collect() 的 algo1 / algo2 两套表。两处别混——2026-11 就
63
+ * 因为发版脚本漏了这里的文档排除规则,导致 SHA256SUMS 记录的指纹含 17 个
64
+ * md/LICENSE、而更新器解包后算出的不含,v1.1.11 及之后所有版本的自更新全部失败。
39
65
  *
40
66
  * @param {string} rel 相对路径,如 `src/main.js` / `docs/架构说明.md`
41
67
  * @returns {boolean}
@@ -45,8 +71,8 @@ export function isHashedFile(rel) {
45
71
  const name = parts.pop();
46
72
  if (!name) return false;
47
73
  // 任一级目录在跳过表里就排除(与 collect 逐层剪枝等价)
48
- if (parts.some((seg) => SKIP_DIRS.has(seg))) return false;
49
- if (SKIP_FILES.has(name)) return false;
74
+ if (parts.some((seg) => LEGACY_SKIP_DIRS.has(seg))) return false;
75
+ if (LEGACY_SKIP_FILES.has(name)) return false;
50
76
  const lower = name.toLowerCase();
51
77
  if (lower.endsWith('.md')) return false;
52
78
  if (/^(license|licence|copying)(\.[a-z0-9]+)?$/.test(lower)) return false;
@@ -74,7 +100,9 @@ function normalize(buf) {
74
100
  * @param {string} root
75
101
  * @returns {Promise<string[]>} 已排序的相对路径
76
102
  */
77
- async function collect(root) {
103
+ async function collect(root, algo) {
104
+ const dirs = algo >= 2 ? SKIP_DIRS_ALGO2 : LEGACY_SKIP_DIRS;
105
+ const files = algo >= 2 ? SKIP_FILES_ALGO2 : LEGACY_SKIP_FILES;
78
106
  const out = [];
79
107
 
80
108
  const walk = async (dir, prefix) => {
@@ -86,11 +114,12 @@ async function collect(root) {
86
114
  }
87
115
  for (const it of items) {
88
116
  if (it.isDirectory()) {
89
- if (SKIP_DIRS.has(it.name)) continue;
117
+ if (dirs.has(it.name)) continue;
90
118
  await walk(path.join(dir, it.name), prefix ? `${prefix}/${it.name}` : it.name);
91
119
  } else if (it.isFile()) {
120
+ if (files.has(it.name)) continue;
121
+ if (algo >= 2 && isDocFile(it.name)) continue;
92
122
  const rel = prefix ? `${prefix}/${it.name}` : it.name;
93
- if (!isHashedFile(rel)) continue;
94
123
  out.push(rel);
95
124
  }
96
125
  // 符号链接一律跳过:它可能指向仓库外,内容不稳定
@@ -134,7 +163,9 @@ export async function hashFileList(root, rels) {
134
163
  * 算目录的内容指纹。
135
164
  *
136
165
  * @param {string} dir 插件目录
137
- * @param {{exclude?: string[], only?: string[]}} [opts]
166
+ * @param {{algo?: number, exclude?: string[], only?: string[]}} [opts]
167
+ * - `algo`:1 = 老算法(含文档),2 = 现行算法(排除文档与运行时状态);默认 HASH_ALGO。
168
+ * 校验市场条目时两个都算,见 plugin/market.js 的 entryHashes。
138
169
  * - `exclude`:精确匹配要跳过的相对路径(如 `SHA256SUMS` 这种会自引用的文件)
139
170
  * - `only`:只算这些路径(`src` 这类目录前缀,或 `package.json` 这类文件名)。
140
171
  * 用途:GitHub 的 tarball 是**全量**(含 .github、scripts、sdk),
@@ -143,6 +174,7 @@ export async function hashFileList(root, rels) {
143
174
  * @returns {Promise<string>} 64 位十六进制
144
175
  */
145
176
  export async function hashDir(dir, opts = {}) {
177
+ const algo = Number.isFinite(opts.algo) ? Number(opts.algo) : HASH_ALGO;
146
178
  /**
147
179
  * 根目录不存在时必须报错,**不能静默返回空哈希**。
148
180
  *
@@ -156,7 +188,7 @@ export async function hashDir(dir, opts = {}) {
156
188
 
157
189
  const skip = new Set(opts.exclude ?? []);
158
190
  const only = (opts.only ?? []).map((p) => String(p));
159
- let files = (await collect(dir)).filter((rel) => !skip.has(rel));
191
+ let files = (await collect(dir, algo)).filter((rel) => !skip.has(rel));
160
192
  if (only.length) {
161
193
  files = files.filter((rel) =>
162
194
  only.some((p) => rel === p || rel.startsWith(p.endsWith('/') ? p : `${p}/`)),
package/src/host/ops.js CHANGED
@@ -373,6 +373,8 @@ export function registerOps(def, { R, err, log = () => {} }) {
373
373
  branch: idx.branch || 'main',
374
374
  sha256: idx?.archive?.sha256 ?? idx?.sha256 ?? null,
375
375
  exists: (pid) => plugins().loaded.has(pid),
376
+ // 与面板共用同一个全局开关,老配置默认开
377
+ verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
376
378
  });
377
379
  await ensurePluginInList(R, r.id, true, err);
378
380
  const scanned = await plugins().rescan();
@@ -428,6 +430,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
428
430
  const r = await updatePlugins({
429
431
  tmp: repo.tmp, index: repo.index, pluginsDir: DIRS.plugins,
430
432
  ids: [id], localVersions: localVers,
433
+ verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
431
434
  });
432
435
  if (r.failed.length) throw err.bad(r.failed[0].error);
433
436
  if (!r.updated.length) throw err.bad(`${id} 没有可用的更新`);
@@ -448,6 +451,7 @@ export function registerOps(def, { R, err, log = () => {} }) {
448
451
  const r = await updatePlugins({
449
452
  tmp: repo.tmp, index: repo.index,
450
453
  pluginsDir: DIRS.plugins, localVersions: localVers,
454
+ verifyHash: R.globalCfg?.plugins?.verifyHash !== false,
451
455
  });
452
456
  for (const u of r.updated) {
453
457
  await plugins().reload(u.id).catch((e) => log(`插件 ${u.id} 重载失败:${e.message}`));
package/src/message.js CHANGED
@@ -152,6 +152,33 @@ function detectMention(d) {
152
152
  return MENTION_TEST.test(String(d?.content ?? ''));
153
153
  }
154
154
 
155
+ /**
156
+ * 这条消息是否**明确只 @ 了别的机器人**(issue #38)。
157
+ *
158
+ * 官方 `GroupMentionsUser` 里 `is_you` 才是「@ 的是当前这个 bot」,`bot`
159
+ * 只表示「被 @ 的是个机器人」。`detectMention()` 历史用 `is_you || bot`
160
+ * 做「有没有 @ 我」的宽松判断,于是多机器人群里 @B 也被算成 @ 我。
161
+ *
162
+ * 这里不推翻那个宽松口径(正文正则 fallback 还要靠它),而是单独识别
163
+ * 「官方字段明确说 @ 了机器人、但明确不是我」的情况:
164
+ * · `m.bot === true && m.is_you === false` —— 明确是别的机器人
165
+ * · 只要有一个 `m.is_you === true` 就不算(同时 @ 了我,该响应)
166
+ * · `scope === 'all'` 是 @全体,不是 @机器人,不算
167
+ * · 没有官方 mentions 字段(如 GROUP_AT_MESSAGE_CREATE)时返回 false——
168
+ * 那种事件 content 已去掉 @ 前缀,无从判断,不能瞎静默
169
+ *
170
+ * 保守取向:宁可漏静默(多回一句),不可误静默(该回的没回)。
171
+ */
172
+ function detectOtherBotMention(d) {
173
+ const list = Array.isArray(d?.mentions) ? d.mentions : [];
174
+ if (!list.length) return false;
175
+ // 同时 @ 了我 → 按「@ 我」处理,不静默
176
+ if (list.some((m) => m && m.is_you === true)) return false;
177
+ return list.some(
178
+ (m) => m && m.bot === true && m.is_you === false && m.scope !== 'all',
179
+ );
180
+ }
181
+
155
182
  /**
156
183
  * 附件归一化。
157
184
  *
@@ -355,6 +382,16 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
355
382
  const prefix = cfg.commandPrefix || '/';
356
383
  const isCommand = content.startsWith(prefix);
357
384
  const mentioned = detectMention(d);
385
+ /**
386
+ * @ 了别的机器人(issue #38)。只在官方字段**明确**时生效——正文正则
387
+ * fallback 那条不动,避免误静默。是否因此静默由开关决定(默认静默):
388
+ * `ignoreOtherBotMention=false` 时恢复旧行为(@ 任意机器人都算 @ 我)。
389
+ * `mentionedOtherBot` 始终报告「检测到」这个事实,与开关无关。
390
+ */
391
+ const mentionedOtherBot = detectOtherBotMention(d);
392
+ const ignoreOtherBot =
393
+ mentionedOtherBot && cfg?.plugins?.ignoreOtherBotMention !== false;
394
+ const effectiveMentioned = ignoreOtherBot ? false : mentioned;
358
395
  const chatId = groupId || userId;
359
396
  const receivedAt = Date.now();
360
397
 
@@ -381,7 +418,24 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
381
418
 
382
419
  // 没 @ 也不算命令,但可能处在免@窗口内 —— 此时同样算「在跟机器人说话」
383
420
  const sticky = Boolean(session?.isSticky(chatId));
384
- const addressed = mentioned || isCommand || sticky;
421
+ /**
422
+ * 「只回复 @ 我」开关(plugins.groupOnlyMentioned,默认关):
423
+ * 开后群聊里只有明确 @ 本机器人的消息才算 addressed,裸 `/命令` 与
424
+ * 免@窗口都不算。单聊天生是一对一,不受影响。
425
+ *
426
+ * 与 issue #38 的 @ 别的机器人静默叠加:后者默认开,可用
427
+ * `ignoreOtherBotMention=false` 关掉,关掉后 @ 别的机器人恢复旧行为。
428
+ */
429
+ const onlyMentioned = cfg?.plugins?.groupOnlyMentioned === true && kind === 'group';
430
+ /** 「命令必须 @ 我」开关(plugins.commandRequiresMention,默认关):只管命令,闲聊不受影响 */
431
+ const cmdRequiresMention =
432
+ cfg?.plugins?.commandRequiresMention === true &&
433
+ kind === 'group' &&
434
+ isCommand &&
435
+ !effectiveMentioned;
436
+ const addressed =
437
+ !ignoreOtherBot &&
438
+ (effectiveMentioned || (onlyMentioned || cmdRequiresMention ? false : isCommand || sticky));
385
439
 
386
440
  /**
387
441
  * 官方事件里以前被整个丢掉的载荷。
@@ -462,7 +516,10 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
462
516
 
463
517
  content,
464
518
  raw: d,
465
- mentioned,
519
+ /** 修正后的「@ 我」:@ 了别的机器人时这里是 false(issue #38) */
520
+ mentioned: effectiveMentioned,
521
+ /** 明确 @ 了别的机器人(客观检测结果,与 ignoreOtherBotMention 开关无关) */
522
+ mentionedOtherBot,
466
523
  /**
467
524
  * 本条消息 @ 了谁(不含机器人自己)。
468
525
  *
@@ -547,7 +604,10 @@ export function buildMessage(eventName, d, { api, cfg, outbound, session, traceI
547
604
  quoted: elements.find((e) => e.type === 'quote')?.content ?? '',
548
605
 
549
606
  sticky,
607
+ /** 是否「在跟我说话」:@ 别的机器人 / 只回@模式下的裸命令都为 false */
550
608
  addressed,
609
+ /** 是否该整条静默(命令闸与会话投递统一读它) */
610
+ silent: ignoreOtherBot || (onlyMentioned && !effectiveMentioned) || cmdRequiresMention,
551
611
  isCommand,
552
612
  receivedAt, // 被动回复窗口从这里开始算,出站调度器要用
553
613
  replied: false, // 任何发送动作都会置为 true,供内核判断「有没有插件回应」
package/src/pipeline.js CHANGED
@@ -182,7 +182,8 @@ export function ratelimitMiddleware(cfg, { isSticky = () => false, metrics = nul
182
182
  return async (ctx, next) => {
183
183
  const rl = cfg.rateLimit ?? {};
184
184
  const msg = ctx.msg;
185
- const addressed = msg.mentioned || msg.isCommand || isSticky(msg.chatId);
185
+ // 静默消息(@ 别的机器人 / 只回@模式下的裸命令)不占额度,也不该被限流回复打岔
186
+ const addressed = !msg.silent && (msg.mentioned || msg.isCommand || isSticky(msg.chatId));
186
187
  if (!rl.enabled || !msg.chatId || !addressed) return next();
187
188
 
188
189
  const limit = Math.max(1, rl.perChatPerMinute ?? 30);
@@ -291,6 +291,23 @@ async function fetchIndexOnce(url) {
291
291
  * @param {string|null} [p.sha256] 索引里给的仓库包校验值,有就验
292
292
  * @returns {Promise<{id:string, dir:string}>}
293
293
  */
294
+ /**
295
+ * 索引条目声明的两种目录哈希(schema 4 起双写)。
296
+ *
297
+ * 2026-11-23 的坑:插件仓把 `sha256` 退回 algo1(给老安装器用),新增
298
+ * `sha256_v2` 存 algo2。框架此前只算 algo2 却拿它去比 `sha256`,于是所有
299
+ * 带 README / LICENSE 的插件 100% 装不上。现在两个都认,任一匹配即通过。
300
+ * 旧索引只有 `sha256` 的也兼容:可能是 algo1,也可能是早期的 algo2 值。
301
+ */
302
+ export function entryHashes(entry) {
303
+ const legacy = String(entry?.sha256 ?? '').toLowerCase();
304
+ const current = String(entry?.sha256_v2 ?? '').toLowerCase();
305
+ return {
306
+ legacy: /^[0-9a-f]{64}$/.test(legacy) ? legacy : '',
307
+ current: /^[0-9a-f]{64}$/.test(current) ? current : '',
308
+ };
309
+ }
310
+
294
311
  /**
295
312
  * 校验失败时说清楚:到底是「索引过期」还是「内容真被改了」。
296
313
  *
@@ -311,10 +328,13 @@ async function shaMismatchError(entry, dir, got) {
311
328
  ' 已中止,原有插件未动。',
312
329
  );
313
330
  }
331
+ const { legacy, current } = entryHashes(entry);
332
+ const expected = [...new Set([current, legacy].filter(Boolean))];
314
333
  return new Error(
315
334
  '插件内容校验失败(sha256 不匹配)\n' +
316
- ` 索引 ${entry.sha256}\n 实际 ${got}\n` +
317
- ' 索引和实际内容对不上,可能是仓库被改动。已中止,原有插件未动。',
335
+ ` 索引 ${expected.join(' / ') || '(没有哈希)'}\n 实际 ${got}\n` +
336
+ ' 索引和实际内容对不上:可能是仓库被改动,也可能是索引与框架的哈希算法版本不一致。\n' +
337
+ ' 先刷新市场 / 升级框架再试;仍失败就别装。已中止,原有插件未动。',
318
338
  );
319
339
  }
320
340
 
@@ -340,13 +360,40 @@ async function readVersionLoose(dir) {
340
360
  }
341
361
  }
342
362
 
343
- /** 插件安装时用,逻辑同 installPlugin 里的校验 */
344
- export async function verifyPluginDir(entry, dir) {
345
- if (!entry?.sha256) return;
346
- const got = await hashDir(dir);
347
- if (got !== String(entry.sha256).toLowerCase()) {
348
- throw await shaMismatchError(entry, dir, got);
363
+ /**
364
+ * 校验插件目录内容。安装 / 更新共用一套规则,避免两边各自漂移。
365
+ *
366
+ * 双算法任一匹配即通过:现行索引 `sha256` 是 algo1、`sha256_v2` 是 algo2;
367
+ * 老索引只有 `sha256`,值可能是任一算法算出来的,两种都试一遍。
368
+ *
369
+ * @param {object} entry 索引条目
370
+ * @param {string} dir 待校验的插件目录
371
+ * @param {{verifyHash?: boolean}} [opts] verifyHash=false 时跳过校验(面板开关,默认开)
372
+ */
373
+ export async function verifyPluginDir(entry, dir, opts = {}) {
374
+ const { legacy, current } = entryHashes(entry);
375
+ if (!legacy && !current) {
376
+ log.warn(`索引里没有 ${entry?.id} 的 sha256,本次未做内容校验`);
377
+ return;
378
+ }
379
+ if (opts.verifyHash === false) {
380
+ log.warn(`插件 ${entry?.id} 的内容哈希校验已被关闭(market.verifyHash=false)`);
381
+ return;
349
382
  }
383
+
384
+ const gotCurrent = await hashDir(dir);
385
+ if ((current && gotCurrent === current) || (legacy && gotCurrent === legacy)) {
386
+ log.info(`插件 ${entry?.id} 内容 sha256 校验通过`);
387
+ return;
388
+ }
389
+ if (legacy) {
390
+ const gotLegacy = await hashDir(dir, { algo: 1 });
391
+ if (gotLegacy === legacy) {
392
+ log.info(`插件 ${entry?.id} 内容 sha256 校验通过(algo1)`);
393
+ return;
394
+ }
395
+ }
396
+ throw await shaMismatchError(entry, dir, gotCurrent);
350
397
  }
351
398
 
352
399
  /**
@@ -517,7 +564,9 @@ export function isExtensionEntry(entry) {
517
564
  return entry?.kind === 'dsh-extension';
518
565
  }
519
566
 
520
- export async function installPlugin({ entry, pluginsDir, repo, branch = 'main', exists, sha256 = null }) {
567
+ export async function installPlugin({
568
+ entry, pluginsDir, repo, branch = 'main', exists, sha256 = null, verifyHash = true,
569
+ }) {
521
570
  const id = String(entry?.id ?? '').trim();
522
571
  if (isExtensionEntry(entry)) {
523
572
  throw new Error(`「${id}」是 DSH 扩展,不归框架插件市场;请在 dsh-roost 面板的「设置 → 扩展」里安装`);
@@ -566,15 +615,7 @@ export async function installPlugin({ entry, pluginsDir, repo, branch = 'main',
566
615
  * 没有稳定的压缩包哈希可对。校验放在**拷贝进 plugins/ 之前**,
567
616
  * 对不上就什么都不留。
568
617
  */
569
- if (entry.sha256) {
570
- const got = await hashDir(resolved);
571
- if (got !== String(entry.sha256).toLowerCase()) {
572
- throw await shaMismatchError(entry, resolved, got);
573
- }
574
- log.info(`插件 ${id} 内容 sha256 校验通过`);
575
- } else {
576
- log.warn(`索引里没有 ${id} 的 sha256,本次安装未做内容校验`);
577
- }
618
+ await verifyPluginDir(entry, resolved, { verifyHash });
578
619
 
579
620
  const dest = path.join(pluginsDir, id);
580
621
  await fs.rm(dest, { recursive: true, force: true });
@@ -589,14 +630,22 @@ export async function installPlugin({ entry, pluginsDir, repo, branch = 'main',
589
630
 
590
631
  /**
591
632
  * 把市场索引和本地已装插件对上,给面板用。
633
+ *
634
+ * DSH 扩展(`kind: dsh-extension`)与框架插件共用同一份 index.json,但装的位置、
635
+ * 安装器、运行形态都不同——框架面板列出来只会让用户点了安装再报错。这里就把
636
+ * 扩展从面板列表里滤掉(执行层 `installPlugin` 的守卫仍在,两道都要有)。
637
+ * `detectUpdates` 也跳过扩展,所以分类计数、更新提示、卡片列表口径一致。
638
+ *
592
639
  * @param {object[]} indexPlugins
593
640
  * @param {Set<string>} installedIds
594
641
  */
595
642
  export function mergeWithInstalled(indexPlugins, installedIds) {
596
- return indexPlugins.map((p) => ({
597
- ...p,
598
- installed: installedIds.has(p.id),
599
- }));
643
+ return indexPlugins
644
+ .filter((p) => !isExtensionEntry(p))
645
+ .map((p) => ({
646
+ ...p,
647
+ installed: installedIds.has(p.id),
648
+ }));
600
649
  }
601
650
 
602
651
  /* ------------------------------------------------------------------ */
@@ -799,9 +848,12 @@ export async function syncCodeTree(src, dest, keepTop) {
799
848
  * @param {string} p.pluginsDir 目标插件目录
800
849
  * @param {string[]} [p.ids] 只更新这些;不传则更新全部「有新版」的
801
850
  * @param {Object<string,string>} [p.localVersions] 本地版本,用于判断谁有新版
851
+ * @param {boolean} [p.verifyHash] 是否校验目录内容,默认 true(面板可关)
802
852
  * @returns {Promise<{updated:Array, skipped:Array, failed:Array}>}
803
853
  */
804
- export async function updatePlugins({ tmp, index, pluginsDir, ids, localVersions = {} }) {
854
+ export async function updatePlugins({
855
+ tmp, index, pluginsDir, ids, localVersions = {}, verifyHash = true,
856
+ }) {
805
857
  const want = ids?.length ? new Set(ids) : null;
806
858
  const result = { updated: [], skipped: [], failed: [] };
807
859
 
@@ -839,12 +891,7 @@ export async function updatePlugins({ tmp, index, pluginsDir, ids, localVersions
839
891
  * 「第一次装的时候小心,以后随便覆盖」,供应链校验的意义就没了。
840
892
  * 校验放在**动旧目录之前**:对不上就什么都不碰,用户手上的插件还是好的。
841
893
  */
842
- if (entry.sha256) {
843
- const got = await hashDir(src);
844
- if (got !== String(entry.sha256).toLowerCase()) {
845
- throw await shaMismatchError(entry, src, got);
846
- }
847
- }
894
+ await verifyPluginDir(entry, src, { verifyHash });
848
895
 
849
896
  const hadOld = await fs.stat(dest).catch(() => null);
850
897
 
@@ -55,6 +55,9 @@ export function serializeMessage(msg, extra = {}) {
55
55
  command: msg.command || '',
56
56
  args: msg.args ?? [],
57
57
  mentioned: Boolean(msg.mentioned),
58
+ addressed: Boolean(msg.addressed),
59
+ /** 静默消息(@ 别的机器人 / 只回@模式下裸命令):插件应直接跳过,不要搭话 */
60
+ silent: Boolean(msg.silent),
58
61
  isCommand: Boolean(msg.isCommand),
59
62
  at: msg.at ?? Date.now(),
60
63
  /**
@@ -237,6 +237,7 @@ export function makeMsg({
237
237
  sticky = false,
238
238
  mentions = null,
239
239
  raw = null,
240
+ silent,
240
241
  } = {}) {
241
242
  const replies = [];
242
243
  /** markdown 消息单独记一份,好断言「走的是富文本还是纯文本」 */
@@ -261,8 +262,10 @@ export function makeMsg({
261
262
  args: isCommand ? parts.slice(1) : parts,
262
263
  isCommand,
263
264
  mentioned,
264
- // 和 message.js 保持一致:@ 了、是命令、或还在免 @ 窗口里,都算「在跟我说话」
265
- addressed: mentioned || isCommand || sticky,
265
+ // 和 message.js 保持一致:@ 了、是命令、或还在免 @ 窗口里,都算「在跟我说话」;
266
+ // silent 由调用方显式给(@ 别的机器人 / 只回@模式),默认按没有静默处理
267
+ silent: Boolean(silent),
268
+ addressed: silent ? false : mentioned || isCommand || sticky,
266
269
  sticky,
267
270
  mentions: mentions ?? [],
268
271
  raw: raw ?? (kind === 'group' ? { author: { member_role: 'member' } } : {}),
@@ -374,6 +377,7 @@ export async function runCommand(plugin, command, opts = {}) {
374
377
  mentioned: opts.mentioned,
375
378
  mentions: opts.mentions,
376
379
  raw: opts.raw,
380
+ silent: opts.silent,
377
381
  });
378
382
 
379
383
  await handler(msg, { args: msg.args, raw: msg.content });
package/src/web/server.js CHANGED
@@ -2079,6 +2079,20 @@ async function startWebServerInstance({
2079
2079
  if (body.dedupWindowSec !== undefined) {
2080
2080
  cfg.dedupWindowSec = Math.max(0, Number(body.dedupWindowSec) || 0);
2081
2081
  }
2082
+ /**
2083
+ * @ 回复策略(bot 级;message.js 每条消息现读 cfg.plugins,立即生效)。
2084
+ * 严格只认布尔,漏给的不动——面板和旧脚本可能只提交其中一个。
2085
+ * 用 merge 而不是替换,避免冲掉 autoInstallDeps / verifyHash 等其它 plugins 字段。
2086
+ */
2087
+ if (body.plugins && typeof body.plugins === 'object') {
2088
+ const patch = {};
2089
+ for (const key of ['groupOnlyMentioned', 'ignoreOtherBotMention', 'commandRequiresMention', 'forwardSilentToProtocol']) {
2090
+ if (typeof body.plugins[key] === 'boolean') patch[key] = body.plugins[key];
2091
+ }
2092
+ if (Object.keys(patch).length) {
2093
+ cfg.plugins = { ...(cfg.plugins ?? {}), ...patch };
2094
+ }
2095
+ }
2082
2096
  /**
2083
2097
  * 连接方式:面板一直在提交这个字段,但服务端从来没读过——
2084
2098
  * 用户选「Webhook」保存后毫无变化、也没有任何提示,以为已经切了。
@@ -2763,6 +2777,8 @@ async function startWebServerInstance({
2763
2777
  repo: idx.repo,
2764
2778
  updated: idx.updated,
2765
2779
  source: url2 || 'default',
2780
+ // 面板「插件市场」的内容哈希校验开关;老配置没这个字段时默认开
2781
+ verifyHash: globalCfg?.plugins?.verifyHash !== false,
2766
2782
  plugins: mergeWithInstalled(idx.plugins, installedIds),
2767
2783
  // 本地有新版可用的插件
2768
2784
  updates: updates.map((u) => ({
@@ -2780,6 +2796,26 @@ async function startWebServerInstance({
2780
2796
  }
2781
2797
  }
2782
2798
 
2799
+ /**
2800
+ * 市场内容哈希校验开关(全局,默认开;面板「插件市场」直接切换)。
2801
+ *
2802
+ * 严格只认布尔:字符串 "false" 若按真值判断会被读成「开」,
2803
+ * 安全开关上这种错代价最大。立即生效——安装 / 更新每次都现读 globalCfg。
2804
+ */
2805
+ if (pathname === '/api/market/settings' && req.method === 'PUT') {
2806
+ const body = await readBody(req);
2807
+ if (typeof body?.verifyHash !== 'boolean') {
2808
+ return json(res, 400, { error: 'verifyHash 必须是 true / false' });
2809
+ }
2810
+ globalCfg.plugins = {
2811
+ ...(globalCfg.plugins ?? {}),
2812
+ verifyHash: body.verifyHash,
2813
+ };
2814
+ await saveGlobalConfig?.(globalCfg).catch(() => {});
2815
+ log.info(`插件市场内容哈希校验已${body.verifyHash ? '开启' : '关闭'}`);
2816
+ return json(res, 200, { ok: true, verifyHash: body.verifyHash });
2817
+ }
2818
+
2783
2819
  // 一键安装
2784
2820
  if (pathname === '/api/market/install' && req.method === 'POST') {
2785
2821
  const body = await readBody(req);
@@ -2816,6 +2852,8 @@ async function startWebServerInstance({
2816
2852
  // 索引给了仓库包校验值就带上,tarball 那边会比对
2817
2853
  sha256: idx?.archive?.sha256 ?? idx?.sha256 ?? null,
2818
2854
  exists: (pid) => plugins.loaded.has(pid),
2855
+ // 面板开关:只有显式 false 才关,老配置没这个字段时默认校验
2856
+ verifyHash: globalCfg?.plugins?.verifyHash !== false,
2819
2857
  });
2820
2858
 
2821
2859
  /**
@@ -4661,6 +4699,7 @@ async function startWebServerInstance({
4661
4699
  pluginsDir: DIRS.plugins,
4662
4700
  ids: [id],
4663
4701
  localVersions: localVers,
4702
+ verifyHash: globalCfg?.plugins?.verifyHash !== false,
4664
4703
  });
4665
4704
  if (r.failed.length) return json(res, 400, { error: r.failed[0].error });
4666
4705
  if (!r.updated.length) return json(res, 400, { error: `${id} 没有可用的更新` });
@@ -4692,6 +4731,7 @@ async function startWebServerInstance({
4692
4731
  index: repo.index,
4693
4732
  pluginsDir: DIRS.plugins,
4694
4733
  localVersions: localVers,
4734
+ verifyHash: globalCfg?.plugins?.verifyHash !== false,
4695
4735
  });
4696
4736
 
4697
4737
  // 更新成功的逐个重载,失败的不碰
package/web/app.js CHANGED
@@ -1961,6 +1961,13 @@ function fillForm(c) {
1961
1961
  f.rateLimitEnabled.checked = c.rateLimit?.enabled !== false;
1962
1962
  f.perChatPerMinute.value = c.rateLimit?.perChatPerMinute ?? 30;
1963
1963
  f.dedupWindowSec.value = c.dedupWindowSec ?? 120;
1964
+ // @ 回复策略(bot 级;与 message.js 的 plugins.* 对应)
1965
+ // @ 别的机器人静默:默认开,所以用 !== false(老配置没这个字段也算开)
1966
+ f.ignoreOtherBotMention.checked = c.plugins?.ignoreOtherBotMention !== false;
1967
+ f.groupOnlyMentioned.checked = c.plugins?.groupOnlyMentioned === true;
1968
+ f.commandRequiresMention.checked = c.plugins?.commandRequiresMention === true;
1969
+ // 静默消息交给协议层:默认开,所以用 !== false(老配置没这个字段也算开)
1970
+ f.forwardSilentToProtocol.checked = c.plugins?.forwardSilentToProtocol !== false;
1964
1971
 
1965
1972
  const ml = c.messageLog ?? {};
1966
1973
  f.messageLogEnabled.checked = ml.enabled !== false;
@@ -1996,7 +2003,7 @@ function fillForm(c) {
1996
2003
  ? '当前框架没有内置信任公钥,这个开关即使打开也不起作用(框架自更新照常放行)。'
1997
2004
  : !trust.pubkeyValid
1998
2005
  ? '信任公钥配错了,解析不了——这个开关打开也不会生效。检查配置里的 security.trust.pubkey。'
1999
- : '开启后,框架自更新会校验 SHA256SUMS 签名,不符或缺失时拒绝更新;插件市场不做签名校验。';
2006
+ : '开启后,框架自更新会校验 SHA256SUMS 签名,不符或缺失时拒绝更新;插件市场不做签名校验(内容哈希在「插件市场」页单独开关,默认开)。';
2000
2007
  }
2001
2008
  }
2002
2009
 
@@ -2430,6 +2437,12 @@ function collectAutoPayload(f) {
2430
2437
  perChatPerMinute: Number(f.perChatPerMinute.value) || 30,
2431
2438
  },
2432
2439
  dedupWindowSec: Number(f.dedupWindowSec.value) || 0,
2440
+ plugins: {
2441
+ ignoreOtherBotMention: f.ignoreOtherBotMention.checked,
2442
+ groupOnlyMentioned: f.groupOnlyMentioned.checked,
2443
+ commandRequiresMention: f.commandRequiresMention.checked,
2444
+ forwardSilentToProtocol: f.forwardSilentToProtocol.checked,
2445
+ },
2433
2446
  messageLog: {
2434
2447
  enabled: f.messageLogEnabled.checked,
2435
2448
  muteKinds: [
@@ -2525,6 +2538,12 @@ async function saveCfgForm({ fromQr = false } = {}) {
2525
2538
  perChatPerMinute: Number(f.perChatPerMinute.value) || 30,
2526
2539
  },
2527
2540
  dedupWindowSec: Number(f.dedupWindowSec.value) || 0,
2541
+ plugins: {
2542
+ ignoreOtherBotMention: f.ignoreOtherBotMention.checked,
2543
+ groupOnlyMentioned: f.groupOnlyMentioned.checked,
2544
+ commandRequiresMention: f.commandRequiresMention.checked,
2545
+ forwardSilentToProtocol: f.forwardSilentToProtocol.checked,
2546
+ },
2528
2547
  messageLog: {
2529
2548
  enabled: f.messageLogEnabled.checked,
2530
2549
  muteKinds: [
@@ -4451,6 +4470,15 @@ async function testMirrors() {
4451
4470
  }
4452
4471
  }
4453
4472
 
4473
+ /** 市场内容哈希开关的说明:关掉时必须把风险说清楚,别让用户以为照旧受保护 */
4474
+ function setMarketHashHint(on) {
4475
+ const el = $('#marketHashHint');
4476
+ if (!el) return;
4477
+ el.textContent = on
4478
+ ? '安装 / 更新会比对索引 sha256,内容不符就拒绝。'
4479
+ : '已关闭:不再校验下载内容完整性,仅建议兼容旧索引时临时使用。';
4480
+ }
4481
+
4454
4482
  /**
4455
4483
  * 拉市场数据并渲染。reveal=false 用于进插件页时的后台预拉:只填数据,不切页签。
4456
4484
  * 在途请求复用(loading),成功过的用缓存(loaded),只有 force 才真重拉。
@@ -4479,6 +4507,12 @@ async function loadMarket({ reveal = true, force = false } = {}) {
4479
4507
  }
4480
4508
 
4481
4509
  meta.textContent = `${d.repo} · 更新于 ${d.updated || '未知'}`;
4510
+ // 内容哈希开关:后端只回「开 / 关」,老配置没字段时按默认开处理
4511
+ const hashBox = $('#marketVerifyHash');
4512
+ if (hashBox) {
4513
+ hashBox.checked = d.verifyHash !== false;
4514
+ setMarketHashHint(hashBox.checked);
4515
+ }
4482
4516
  // 网络不通时后端会退回本地缓存,得让用户知道这是旧数据
4483
4517
  if (d.stale) {
4484
4518
  meta.innerHTML =
@@ -4892,6 +4926,29 @@ $('#proxySelect')?.addEventListener('change', (e) => {
4892
4926
  saveMirror();
4893
4927
  });
4894
4928
  $('#proxyCustom')?.addEventListener('change', saveMirror);
4929
+
4930
+ /**
4931
+ * 市场内容哈希校验:改完立即落盘生效,不重启。
4932
+ * 失败时把勾选弹回去——安全开关最怕「面板显示开着、后端其实没保存」的假状态。
4933
+ */
4934
+ $('#marketVerifyHash')?.addEventListener('change', async (e) => {
4935
+ const on = e.target.checked;
4936
+ try {
4937
+ const r = await api('/api/market/settings', {
4938
+ method: 'PUT',
4939
+ body: JSON.stringify({ verifyHash: on }),
4940
+ });
4941
+ const actual = r?.verifyHash !== false;
4942
+ if (actual !== on) e.target.checked = actual;
4943
+ setMarketHashHint(actual);
4944
+ toast(`内容哈希校验已${actual ? '开启' : '关闭'}`, actual ? 'ok' : 'info');
4945
+ } catch (err) {
4946
+ e.target.checked = !on;
4947
+ setMarketHashHint(!on);
4948
+ toast(`保存失败:${errText(err)}`, 'error');
4949
+ }
4950
+ });
4951
+
4895
4952
  /* 子页签:切到市场时确保数据拉过;切回已安装只切显隐,不产生请求 */
4896
4953
  $$('[data-plugin-subtab]').forEach((btn) => {
4897
4954
  btn.addEventListener('click', () => {
package/web/index.html CHANGED
@@ -961,6 +961,32 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
961
961
  <label>去重窗口(秒)<input name="dedupWindowSec" type="number" min="0"></label>
962
962
  </div>
963
963
  <div class="divider"></div>
964
+ <div class="intent-group-title">@ 回复策略</div>
965
+ <div class="hint" style="margin-bottom:6px">
966
+ 默认只有第一项开、后两项关:群里 @ 别的机器人不理会,裸 <code>/命令</code> 与免@窗口照旧算「在跟我说话」。
967
+ 后两项只作用于群聊,私聊一对一不受影响。
968
+ </div>
969
+ <label class="switch">
970
+ <input type="checkbox" name="ignoreOtherBotMention" checked>
971
+ @ 别的机器人时静默(默认开;同时 @ 我仍照常回复)
972
+ </label>
973
+ <label class="switch">
974
+ <input type="checkbox" name="groupOnlyMentioned">
975
+ 只回复 @ 我的消息(群聊里裸 <code>/命令</code> 和普通闲聊都不回应)
976
+ </label>
977
+ <label class="switch">
978
+ <input type="checkbox" name="commandRequiresMention">
979
+ /命令 必须 @ 我才回复(普通闲聊照旧进插件 / 模型)
980
+ </label>
981
+ <label class="switch">
982
+ <input type="checkbox" name="forwardSilentToProtocol" checked>
983
+ 静默消息仍交给协议层(默认开;关掉后 DSH 宿主 / OneBot 客户端也看不到这些消息)
984
+ </label>
985
+ <div class="hint" style="margin-top:4px">
986
+ 上面几种静默消息在框架内部一律不回复。本开关只管<b>要不要把它们推给外部协议层</b>:
987
+ 默认全交(和以前一样);关掉后连 DSH 的 AI 模式也看不到,就不会「补一句」。不影响本框架收到消息的记录。
988
+ </div>
989
+ <div class="divider"></div>
964
990
  <div class="intent-group-title">消息日志</div>
965
991
  <label class="switch">
966
992
  <input type="checkbox" name="messageLogEnabled">
@@ -1041,7 +1067,7 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
1041
1067
  </label>
1042
1068
  <div class="hint" id="trustHint">
1043
1069
  开启后,面板里「更新框架」会检查 Release 里的 SHA256SUMS 签名,签名不符或缺失时拒绝更新。
1044
- 只影响框架自身升级;<b>插件市场不再做签名校验</b>,插件照常安装(下载内容仍校验 sha256)。
1070
+ 只影响框架自身升级;<b>插件市场不再做签名校验</b>,下载内容的 sha256 校验在「插件市场」页单独开关(默认开)。
1045
1071
  需要框架内置信任公钥——没内置时这个开关不起作用。
1046
1072
  </div>
1047
1073
  <div class="hint">
@@ -1183,8 +1209,17 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
1183
1209
  </div>
1184
1210
  </div>
1185
1211
 
1186
- <!-- 下载源:国内直连 GitHub 经常超时,这里可以换镜像 -->
1187
1212
  <div class="mirror-bar">
1213
+ <!--
1214
+ 内容哈希校验:默认开。关掉后安装 / 更新不再比对索引 sha256,
1215
+ 只建议在索引与框架算法版本错位的过渡期临时用。
1216
+ -->
1217
+ <label class="switch small" title="安装 / 更新时比对索引里的 sha256,防止下载内容被替换">
1218
+ <input type="checkbox" id="marketVerifyHash" checked> 校验内容哈希
1219
+ </label>
1220
+ <span class="hint" id="marketHashHint"></span>
1221
+
1222
+ <!-- 下载源:国内直连 GitHub 经常超时,这里可以换镜像 -->
1188
1223
  <span class="hint">下载源</span>
1189
1224
  <select id="mirrorSelect" class="mini-select" aria-label="下载源"></select>
1190
1225
  <input