qq-bot-roost 1.0.13 → 1.0.14

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-903%20passed-brightgreen" alt="测试 903 项">
11
+ <img src="https://img.shields.io/badge/tests-913%20passed-brightgreen" alt="测试 913 项">
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.0.13-blueviolet" alt="版本 1.0.13">
13
+ <img src="https://img.shields.io/badge/version-1.0.14-blueviolet" alt="版本 1.0.14">
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/tdcq9594/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/tdcq9594/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qq-bot-roost",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "type": "module",
5
5
  "description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
6
6
  "license": "AGPL-3.0-only",
@@ -29,9 +29,9 @@
29
29
  "start": "node src/main.js",
30
30
  "mock": "node src/main.js --mock",
31
31
  "check": "node src/main.js --check",
32
- "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.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/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/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs",
32
+ "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.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/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/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs",
33
33
  "test:e2e": "node test/e2e.mjs",
34
- "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.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/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/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs",
34
+ "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.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/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/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs",
35
35
  "check:secrets": "node scripts/check-secrets.mjs",
36
36
  "create": "node scripts/create-plugin.mjs",
37
37
  "test:plugin": "node scripts/test-plugin.mjs",
package/src/instance.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
- import { readFileSync, statSync } from 'node:fs';
2
+ import { readFileSync, readlinkSync, statSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { execFileSync } from 'node:child_process';
5
5
  import { createHash } from 'node:crypto';
@@ -155,6 +155,37 @@ function looksLikeNodeRuntime(name) {
155
155
  return /\bnode\b|electron|.*harness.*/i.test(base);
156
156
  }
157
157
 
158
+ /**
159
+ * 纯函数:`/proc/<pid>` 的三处内容里,有没有证据表明它是 node 运行时。
160
+ *
161
+ * **为什么不能只看 `comm`**:Node 24 起会把主线程名设成 `MainThread`,
162
+ * `/proc/<pid>/comm` 读出来就是这四个字,不再含 `node`。只认 comm 会把一个
163
+ * **活着的**实例判成陈旧记录 → 删锁 → 放行第二次认领 → 同 AppID 双开 →
164
+ * 4902 互踢。CI 的 `ubuntu-latest / Node 24.x` 就是从这条断言红起的。
165
+ *
166
+ * 判定顺序(与文件头「拿不准往活着倒」一致):
167
+ * · `comm` 读不到(空串)→ 活(无法确认就不否定)
168
+ * · comm / cmdline / exe 任一提及 node → 活
169
+ * · **另两项一个都没读到**(传 `null`)→ 活
170
+ * · 至少读到一项、且都没提 node → 死(这才真的是 PID 被别的程序复用)
171
+ *
172
+ * 倒数第二条是**跨用户 / 加固内核**的保命线:`/proc/<pid>/exe` 要 ptrace 权限,
173
+ * 读别人的进程会 EACCES;`cmdline` 在非 dumpable 进程上也可能读不到。
174
+ * 若这时只拿 comm 下结论,一个 `MainThread` 的活实例就会被判死——又绕回互踢。
175
+ * 「读不到」和「读到了但没有 node」必须分开,所以这里用 `null` 表示前者。
176
+ *
177
+ * 拆成纯函数是为了能在**任意平台**单测:真机上只有跑在对应系统上才能观测到
178
+ * `/proc` 的内容,而这段逻辑恰恰是跨平台行为分叉的地方。
179
+ */
180
+ function looksLikeNodeProc({ comm = '', cmdline = null, exe = null } = {}) {
181
+ if (!comm) return true;
182
+ if (/node/i.test(comm)) return true;
183
+ if (cmdline && /node/i.test(cmdline)) return true;
184
+ if (exe && /node/i.test(exe)) return true;
185
+ if (cmdline === null && exe === null) return true;
186
+ return false;
187
+ }
188
+
158
189
  /**
159
190
  * 这个 pid 现在是不是一个 node 进程。
160
191
  *
@@ -193,15 +224,16 @@ function pidLooksLikeNode(pid) {
193
224
  if (process.platform === 'linux') {
194
225
  const comm = readFileSync(`/proc/${pid}/comm`, 'utf8').trim();
195
226
  /**
196
- * 读到空字符串时**按活着算**,不是按死了算。
197
- *
198
- * 判断不出来的方向要选保守的那个:当成死 → 删记录 → 放行第二次认领
199
- * → 同一个 AppID 双开 → 4902 互踢,正是这套机制存在的理由。
200
- * 当成活 → 顶多让用户手动清一条残留记录(有 `--force`)。
201
- *
202
- * 真实的误判代价不对称,所以拿不准就往"活着"倒。
227
+ * Node 24 起主线程被改名成 `MainThread`,`comm` 不再含 `node`,
228
+ * 所以再核对 `cmdline`(完整命令行)与 `exe`(可执行文件链接)。
229
+ * **读不到的项传 `null`**(不是空串):纯函数要区分「这一项没证据」和
230
+ * 「这一项读不到」,后者在跨用户 / 加固内核下很常见,不能单独导致判死。
203
231
  */
204
- return comm ? /node/i.test(comm) : true;
232
+ let cmdline = null;
233
+ let exe = null;
234
+ try { cmdline = readFileSync(`/proc/${pid}/cmdline`, 'utf8').replace(/\0/g, ' '); } catch { /* 读不到就看下一项 */ }
235
+ try { exe = readlinkSync(`/proc/${pid}/exe`); } catch { /* 权限或已退出 */ }
236
+ return looksLikeNodeProc({ comm, cmdline, exe });
205
237
  }
206
238
  const comm = execFileSync('ps', ['-p', String(pid), '-o', 'comm='], {
207
239
  encoding: 'utf8',
@@ -594,6 +626,16 @@ export function _pidExists(pid) {
594
626
  return pidExists(pid);
595
627
  }
596
628
 
629
+ /**
630
+ * 测试用:`/proc/<pid>` 三处证据的合并判据。
631
+ *
632
+ * 这条逻辑跨平台分叉,真机上只有跑在对应系统才观测得到 `/proc` 的内容,
633
+ * 所以在 CI 里用表驱动直接喂 comm / cmdline / exe(见 `test/instance-proc.mjs`)。
634
+ */
635
+ export function _looksLikeNodeProc(parts) {
636
+ return looksLikeNodeProc(parts);
637
+ }
638
+
597
639
  /** 测试用:直接跑剪枝,便于构造「停跳租约 + 不像 node 的进程名」边界 */
598
640
  export function _pruneForTest(data) {
599
641
  return prune(data);
@@ -512,6 +512,14 @@ export class PluginManager {
512
512
 
513
513
  async #loadExternal(id, dir) {
514
514
  const raw = JSON.parse(await fs.readFile(path.join(dir, 'plugin.json'), 'utf8'));
515
+ /**
516
+ * DSH 扩展不归框架加载。它们没有 `index.js`、runtime 是 mcp,旧逻辑会回落成
517
+ * python 去拉一个不存在的子进程。明确跳过并留一句可查的 warn,比静默失败好。
518
+ */
519
+ if (raw?.kind === 'dsh-extension') {
520
+ log.warn(`目录 ${id} 是 DSH 扩展(kind=dsh-extension),不归框架插件加载;请用 dsh-roost 面板安装`);
521
+ return false;
522
+ }
515
523
  if (raw.id && raw.id !== id) {
516
524
  log.warn(`插件目录 ${id} 的 plugin.json 声明 id 为 ${raw.id},与目录名不一致,以目录名为准`);
517
525
  }
@@ -796,6 +804,7 @@ export class PluginManager {
796
804
  // 外部插件:plugin.json 就是元信息
797
805
  try {
798
806
  const raw = JSON.parse(await fs.readFile(path.join(dir, 'plugin.json'), 'utf8'));
807
+ if (raw?.kind === 'dsh-extension') return; // 扩展不进框架插件列表
799
808
  this.#cacheMeta(id, raw, 'external', raw.runtime || 'python');
800
809
  return;
801
810
  } catch {
@@ -485,8 +485,25 @@ async function downloadRepoContents({
485
485
  }
486
486
  }
487
487
 
488
+ /**
489
+ * 索引里的 **DSH 扩展**条目。
490
+ *
491
+ * 扩展与框架插件共用 `index.json` / `plugin.json`,但运行形态完全不同:扩展是
492
+ * 标准 MCP server,由 DSH 按受管块 spawn,没有 `index.js`、没有 version 契约,
493
+ * 装在 `~/.dsh/dsh-roost/extensions/`,由 dsh-roost 自己的安装器管。
494
+ *
495
+ * 框架侧(这里)必须跳过它:装进 `plugins/` 后 loader 会按不认识的 runtime 处理,
496
+ * 旧逻辑还会回落成 `python` 去拉一个不存在的子进程,表现是「装上了但一点反应都没有」。
497
+ */
498
+ export function isExtensionEntry(entry) {
499
+ return entry?.kind === 'dsh-extension';
500
+ }
501
+
488
502
  export async function installPlugin({ entry, pluginsDir, repo, branch = 'main', exists, sha256 = null }) {
489
503
  const id = String(entry?.id ?? '').trim();
504
+ if (isExtensionEntry(entry)) {
505
+ throw new Error(`「${id}」是 DSH 扩展,不归框架插件市场;请在 dsh-roost 面板的「设置 → 扩展」里安装`);
506
+ }
490
507
  if (!/^[a-z0-9][a-z0-9_-]{0,31}$/.test(id)) throw new Error(`插件 id 不合法:${id}`);
491
508
  if (!entry?.path) throw new Error('索引里缺少 path 字段');
492
509
  if (!repo) throw new Error('索引里缺少 repo 字段');
@@ -586,6 +603,7 @@ export { compareVersion } from '../semver.js';
586
603
  export function detectUpdates(indexPlugins, localVersions = {}) {
587
604
  const out = [];
588
605
  for (const entry of indexPlugins ?? []) {
606
+ if (isExtensionEntry(entry)) continue; // 扩展按目录哈希由 dsh-roost 更新
589
607
  const cur = localVersions[entry.id];
590
608
  // 没装、或本地版本号缺失/不合法 → 不提示,让用户自己决定
591
609
  if (!cur) continue;
@@ -684,6 +702,7 @@ export async function updatePlugins({ tmp, index, pluginsDir, ids, localVersions
684
702
  const result = { updated: [], skipped: [], failed: [] };
685
703
 
686
704
  for (const entry of index.plugins ?? []) {
705
+ if (isExtensionEntry(entry)) { result.skipped.push({ id: entry.id, reason: 'DSH 扩展,不归框架市场更新' }); continue; }
687
706
  if (want && !want.has(entry.id)) continue;
688
707
 
689
708
  const dest = path.join(pluginsDir, entry.id);