dsh-qqbot-muu 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +168 -154
  2. package/client/qqbot-settings.js +13401 -13380
  3. package/dist/config.js +573 -581
  4. package/dist/features/contextless-store.js +247 -247
  5. package/dist/features/four-source.js +338 -336
  6. package/dist/features/group-join-request.js +289 -287
  7. package/dist/features/local-models.js +1494 -1467
  8. package/dist/features/style-layer.js +501 -498
  9. package/dist/features/thinking-log.js +71 -69
  10. package/dist/gateway/bootstrap.js +1704 -1652
  11. package/dist/model/settings-reader.js +193 -102
  12. package/dist/shared/paths.js +128 -0
  13. package/dist/shared/settings-io.js +79 -83
  14. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  15. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -794
  16. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  17. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  18. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -444
  19. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  20. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  21. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  22. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  23. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  24. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  25. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  26. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  27. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  28. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  29. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  30. package/package.json +119 -118
  31. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  32. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  33. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  34. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  35. package/scripts/ai-toolkit.py +607 -478
  36. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  37. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  38. package/scripts/chat-archive/build-sft-v4.py +566 -0
  39. package/scripts/chat-archive/build-sft.py +390 -0
  40. package/scripts/chat-archive/eval-sft.py +155 -0
  41. package/scripts/chat-archive/extract-memory.py +143 -0
  42. package/scripts/chat-archive/inventory.py +182 -0
  43. package/scripts/chat-archive/merge-sft.py +114 -0
  44. package/scripts/chat-archive/qce-pull.py +217 -0
  45. package/scripts/chat-archive/qqheader.py +110 -0
  46. package/scripts/chat-archive/qqkey2.py +113 -0
  47. package/scripts/chat-archive/qqprobe.py +153 -0
  48. package/scripts/chat-archive/screen-collect.py +163 -0
  49. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  50. package/scripts/episode.py +529 -0
  51. package/scripts/fan-curve.py +218 -0
  52. package/scripts/fan-guard.cmd +8 -0
  53. package/scripts/fan-mode.py +380 -263
  54. package/scripts/gen-image.py +420 -413
  55. package/scripts/gen-video.py +186 -178
  56. package/scripts/hw-profile.py +175 -0
  57. package/scripts/media-enhance.py +402 -0
  58. package/scripts/memory-audit.py +581 -0
  59. package/scripts/migrate-scope.mjs +140 -139
  60. package/scripts/qq-connect-login.py +133 -0
  61. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  62. package/scripts/qq-ip-sync.py +300 -0
  63. package/scripts/qq-whitelist.py +71 -0
  64. package/scripts/release-all.mjs +636 -509
  65. package/scripts/release-check.mjs +244 -226
  66. package/scripts/secure-room/index.html +334 -0
  67. package/scripts/secure-room/server.py +582 -0
  68. package/scripts/stickers/auto-tag.mjs +161 -0
  69. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  70. package/scripts/train/gguf-quantize.py +92 -0
  71. package/scripts/train/gguf-to-hf.py +112 -0
  72. package/scripts/train/merge-lora.py +51 -0
  73. package/scripts/train/probe-mirrors.sh +12 -0
  74. package/scripts/train/probe-mirrors2.sh +20 -0
  75. package/scripts/train/setup-wsl.sh +23 -0
  76. package/scripts/train/setup-wsl2.sh +25 -0
  77. package/scripts/train/setup-wsl3.sh +22 -0
  78. package/scripts/train/setup-wsl4.sh +22 -0
  79. package/scripts/train/train-lora.py +319 -0
  80. package/dist/_backup_ctx_20261125_183653/dist/config.d.ts +0 -473
  81. package/dist/_backup_ctx_20261125_183653/dist/config.js +0 -450
  82. package/dist/_backup_ctx_20261125_183653/dist/features/contextless-trim.js +0 -304
  83. package/dist/_backup_ctx_20261125_183653/dist/session/session-manager.js +0 -1588
  84. package/dist/_backup_ctx_20261125_183653/dist/transport/inbound.js +0 -1567
  85. package/dist/_backup_ctx_20261125_183653/dist/transport/outbound.js +0 -647
  86. package/scripts/__pycache__/ai-mode.cpython-311.pyc +0 -0
  87. package/scripts/__pycache__/ai-toolkit.cpython-311.pyc +0 -0
  88. package/scripts/__pycache__/comfy_gen.cpython-311.pyc +0 -0
  89. package/scripts/__pycache__/gen-image.cpython-311.pyc +0 -0
  90. package/scripts/__pycache__/gen-video.cpython-311.pyc +0 -0
  91. package/scripts/__pycache__/model-registry.cpython-311.pyc +0 -0
  92. package/scripts/__pycache__/purge-standby.cpython-311.pyc +0 -0
@@ -1,226 +1,244 @@
1
- #!/usr/bin/env node
2
- /**
3
- * release-check.mjs —— 发版前的守门(2026-11-18,v0.1.7 起每次发布必跑)
4
- *
5
- * node scripts/release-check.mjs # 普通检查:有硬伤就 exit 1
6
- * node scripts/release-check.mjs --strict # 发布用:再加「本机隐私名单 / profile 依赖」硬校验
7
- *
8
- * 检查四类东西:
9
- * 1) 打包内容——不能带 data/、.state/、*.bak、*.lnk、cookie、私聊库、本地密钥脚本、tmp/;
10
- * 2) 包里内容——不能出现 token / 私钥 / 真实账号(名单从本机 private-people.json 读,脚本本身不存 id);
11
- * 3) 兼容性——入口文件语法、必需文件齐全、不能写死本机绝对路径(只警告,列出清单);
12
- * 4) 新用户可用性——人设必须有内置默认值(没有 character.json 也要有情绪和世界观)。
13
- *
14
- * 退出码:0 通过(可能有警告);1 有硬伤,禁止发布。
15
- */
16
- import { execFileSync } from 'node:child_process'
17
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
18
- import { dirname, join, relative, sep } from 'node:path'
19
- import { fileURLToPath } from 'node:url'
20
-
21
- const REPO = dirname(dirname(fileURLToPath(import.meta.url)))
22
- const STRICT = process.argv.includes('--strict')
23
- const fails = []
24
- const warns = []
25
-
26
- function fail(msg) { fails.push(msg) }
27
- function warn(msg) { warns.push(msg) }
28
- function ok(msg) { console.log(`✓ ${msg}`) }
29
-
30
- // ── 0. 基本文件 ─────────────────────────────────────────────────────────────
31
- const REQUIRED = [
32
- 'package.json', 'index.js', 'entry.js', 'cordis.patch.yml', 'install.mjs',
33
- 'README.md', 'CHANGELOG.md', 'settings-host.js',
34
- 'dist/gateway/bootstrap.js',
35
- 'dshqqbot/.qqbot-extensions/lib/private-guard.mjs',
36
- 'dshqqbot/.qqbot-extensions/live/persona.mjs',
37
- 'scripts/dsh-profile-links.mjs',
38
- 'scripts/dsh-profile-preflight.mjs',
39
- ]
40
- for (const f of REQUIRED) if (!existsSync(join(REPO, f))) fail(`缺少必需文件:${f}`)
41
- if (!fails.length) ok(`必需文件齐全(${REQUIRED.length} 项)`)
42
-
43
- const pkg = JSON.parse(readFileSync(join(REPO, 'package.json'), 'utf8'))
44
- const version = String(pkg.version || '0.0.0')
45
- if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(version)) fail(`package.json version 不是合法 semver:${version}`)
46
- ok(`版本 ${pkg.name}@${version}`)
47
-
48
- // ── 1. 打包内容清单(npm pack --dry-run,离线可用)────────────────────────────
49
- let packed = []
50
- try {
51
- const raw = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], {
52
- cwd: REPO, encoding: 'utf8', shell: process.platform === 'win32', stdio: ['ignore', 'pipe', 'pipe'],
53
- })
54
-
55
- const j = JSON.parse(raw.slice(raw.indexOf('[')))
56
- packed = (j[0]?.files || []).map((f) => String(f.path).replace(/\\/g, '/'))
57
- } catch (e) {
58
- warn(`npm pack --dry-run 失败,改用 files 字段估算:${e?.message ?? e}`)
59
- packed = ['package.json']
60
- }
61
-
62
- const FORBIDDEN_PATH = [
63
- /(^|\/)data\//, /\.state\//, /\.bak($|[-.0-9])/, /\.lnk$/, /\.db($|-)/, /\.ndjson$/,
64
- /(^|\/)tmp\//, /(^|\/)logs\//, /private-people/i, /douyin-cookie/i,
65
- /wcx-token|bridge-token|env\.json|credentials/i, /wx4-[^/]*\.(ps1|cmd)$/,
66
- /(^|\/)secrets\//, /memory\.db$/, /\.sqlite3?$/,
67
- ]
68
- const badPaths = packed.filter((p) => FORBIDDEN_PATH.some((re) => re.test(p)))
69
- if (badPaths.length) fail(`发布包里混进了隐私/运行时文件(${badPaths.length} 个):${badPaths.slice(0, 8).join(', ')}`)
70
- else ok(`打包清单干净(${packed.length} 个文件,无 data/.state/cookie/密钥/私聊库)`)
71
-
72
- // ── 2. 包里内容扫描 ─────────────────────────────────────────────────────────
73
- const TEXT_EXT = /\.(mjs|js|cjs|ts|json|ya?ml|md|txt|html|css|ps1|cmd|bat)$/i
74
- const SECRET_PATTERNS = [
75
- [/sk-[A-Za-z0-9_-]{16,}/, '疑似 API Key(sk-)'],
76
- [/gh[pousr]_[A-Za-z0-9]{20,}/, '疑似 GitHub Token'],
77
- [/AKIA[0-9A-Z]{16}/, '疑似 AWS Key'],
78
- [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, '疑似私钥'],
79
- [/(_authToken|NODE_AUTH_TOKEN)\s*[=:]\s*\S+/, '疑似 npm token 写法'],
80
- [/Bearer\s+[A-Za-z0-9._-]{24,}/, '疑似 Bearer token'],
81
- [/\bsk-[A-Za-z0-9]{32,}\b/, '疑似长 key'],
82
- ]
83
-
84
- // 本机真实账号名单:只从本机数据读,脚本本身不带任何 id
85
- const localIds = new Set()
86
- const peopleFile = join(REPO, 'dshqqbot', '.qqbot', 'private-people.json')
87
- if (existsSync(peopleFile)) {
88
- try {
89
- for (const p of JSON.parse(readFileSync(peopleFile, 'utf8'))) {
90
- for (const k of ['qq', 'wx', 'douyin']) if (p?.[k]) localIds.add(String(p[k]))
91
- if (p?.name && String(p.name).length >= 2) localIds.add(String(p.name))
92
- }
93
- } catch (e) { warn(`读取 ${peopleFile} 失败:${e?.message ?? e}`) }
94
- } else if (STRICT) {
95
- warn(`没有 ${peopleFile},跳过「真实账号」扫描(strict 下建议先建这份名单)`)
96
- }
97
-
98
- // 另外从本机的会话台账/通讯录里再收一批 id(防止名单文件没列的账号漏网)
99
- for (const extra of [
100
- join(REPO, 'dshqqbot', '.qqbot', 'xtc-peers.json'),
101
- join(REPO, 'xtc-bridge', 'people.json'),
102
- ]) {
103
- if (!existsSync(extra)) continue
104
- try {
105
- const j = JSON.parse(readFileSync(extra, 'utf8'))
106
- const walk = (v) => {
107
- if (typeof v === 'string' && /^[0-9A-Za-z_-]{6,64}$/.test(v) && /\d/.test(v)) localIds.add(v)
108
- else if (Array.isArray(v)) v.forEach(walk)
109
- else if (v && typeof v === 'object') { for (const [k, vv] of Object.entries(v)) { walk(k); walk(vv) } }
110
- }
111
- walk(j)
112
- } catch { /* 忽略 */ }
113
- }
114
- // 8 位以上纯数字句柄(openid 尾号、xtcId 之类)也算隐私,别写进包里
115
- const NUMERIC_ID_RE = /\d{8,12}/
116
-
117
- const hits = []
118
- let scanned = 0
119
- for (const rel of packed) {
120
- if (!TEXT_EXT.test(rel)) continue
121
- const abs = join(REPO, rel.split('/').join(sep))
122
- if (!existsSync(abs)) continue
123
- let txt = ''
124
- try {
125
- if (statSync(abs).size > 4 * 1024 * 1024) continue
126
- txt = readFileSync(abs, 'utf8')
127
- } catch { continue }
128
- scanned += 1
129
- for (const [re, label] of SECRET_PATTERNS) {
130
- if (re.test(txt)) hits.push(`${rel}: ${label}`)
131
- }
132
- for (const id of localIds) {
133
- if (id.length >= 6 && txt.includes(id)) hits.push(`${rel}: 含本机真实账号/姓名「${id.slice(0, 4)}…」`)
134
- }
135
- if (rel.endsWith('.md')) {
136
- const m = txt.match(NUMERIC_ID_RE)
137
- if (m) hits.push(`${rel}: 出现疑似账号数字「${m[0]}」`)
138
- }
139
- }
140
- if (hits.length) {
141
- for (const h of hits.slice(0, 12)) fail(`内容泄露:${h}`)
142
- } else {
143
- ok(`内容扫描通过(${scanned} 个文本文件,无 token/私钥/本机账号)`)
144
- }
145
-
146
- // ── 3. 兼容性 ───────────────────────────────────────────────────────────────
147
- const ENTRY_FILES = ['index.js', 'entry.js', 'settings-host.js', 'install.mjs', 'dist/gateway/bootstrap.js',
148
- 'dshqqbot/.qqbot-extensions/lib/private-guard.mjs', 'dshqqbot/.qqbot-extensions/live/persona.mjs']
149
- for (const f of ENTRY_FILES) {
150
- const abs = join(REPO, f)
151
- if (!existsSync(abs)) continue
152
- try {
153
- execFileSync(process.execPath, ['--check', abs], { stdio: 'pipe' })
154
- } catch (e) {
155
- fail(`语法错误:${f}\n${String(e?.stderr || e?.message || e).slice(0, 400)}`)
156
- }
157
- }
158
- ok(`入口语法检查通过(${ENTRY_FILES.length} 个文件)`)
159
-
160
- // 本机 profile 依赖写法(npm 绝对盘符 file: → pnpm 拼路径 → 安全模式)
161
- const appData = process.env.APPDATA || ''
162
- if (appData) {
163
- const prof = join(appData, 'dsh-desktop', 'harness', 'profiles', 'web', 'package.json')
164
- if (existsSync(prof)) {
165
- try {
166
- const man = JSON.parse(readFileSync(prof, 'utf8'))
167
- const deps = { ...(man.dependencies || {}), ...(man.devDependencies || {}) }
168
- const bad = Object.entries(deps).filter(([, v]) => typeof v === 'string' && /^file:[A-Za-z]:[\\/]/.test(v))
169
- if (bad.length) {
170
- const msg = `本机 profile 有绝对盘符 file: 依赖(会让 DSH 进安全模式):${bad.map(([k]) => k).join(', ')} → 跑 node scripts/dsh-profile-links.mjs`
171
- if (STRICT) fail(msg)
172
- else warn(msg)
173
- } else ok('profile 依赖写法正常(无绝对盘符 file:)')
174
- } catch { warn('读取本机 profile 的 package.json 失败(跳过)') }
175
- }
176
- }
177
-
178
- // 写死的本机绝对路径(只警告,列出来慢慢清)
179
- const ABS_PATH_RE = /["'`]([A-Za-z]:[\\/][^"'`\n]{3,})["'`]/
180
- const absOffenders = []
181
- for (const rel of packed) {
182
- if (!TEXT_EXT.test(rel) || rel.endsWith('.md')) continue
183
- const abs = join(REPO, rel.split('/').join(sep))
184
- if (!existsSync(abs)) continue
185
- let txt = ''
186
- try { txt = readFileSync(abs, 'utf8') } catch { continue }
187
- let n = 0
188
- for (const line of txt.split('\n')) {
189
- if (/^\s*(\*|\/\/|#)/.test(line)) continue
190
- // 系统目录(Windows 字体 / Program Files)不算「作者本机路径」,允许作为兜底
191
- const sysLine = line.indexOf('Windows') >= 0 || line.indexOf('Program Files') >= 0
192
- if (!sysLine && ABS_PATH_RE.test(line)) n += 1
193
- }
194
- if (n) absOffenders.push(`${relative(REPO, abs).split(sep).join('/')}(${n} 处)`)
195
- }
196
- if (absOffenders.length) {
197
- warn(`代码里还有 ${absOffenders.length} 个文件写着本机绝对路径(别人机器上会失效,建议逐步改成从 import.meta.url 推):${absOffenders.slice(0, 6).join('、')}${absOffenders.length > 6 ? ' …' : ''}`)
198
- } else {
199
- ok('没有写死的本机绝对路径')
200
- }
201
-
202
- // ── 4. 新用户可用性:默认人设/世界观 ─────────────────────────────────────────
203
- const personaFile = join(REPO, 'dshqqbot', '.qqbot-extensions', 'live', 'persona.mjs')
204
- if (existsSync(personaFile)) {
205
- const t = readFileSync(personaFile, 'utf8')
206
- const hasDefaultName = /j\?\.name\s*\|\|\s*'[^']+'/.test(t)
207
- const hasDefaultSpecies = /j\?\.species\s*\|\|\s*'[^']+'/.test(t)
208
- const hasCore = /j\?\.core[^\n]*(\|\||:)\s*'[^']+'/.test(t)
209
- if (!(hasDefaultName && hasDefaultSpecies && hasCore)) fail('persona.mjs 缺少内置默认人设(新用户会没有性格/世界观)')
210
- else ok('默认人设齐全(名字 / 种族 / 性格 都有内置兜底)')
211
- } else {
212
- fail('缺少 live/persona.mjs')
213
- }
214
-
215
- // ── 汇总 ────────────────────────────────────────────────────────────────────
216
- console.log('')
217
- if (warns.length) {
218
- console.log(`⚠ 警告 ${warns.length} 条:`)
219
- for (const w of warns) console.log(` - ${w}`)
220
- }
221
- if (fails.length) {
222
- console.error(`\n✗ 发版检查未通过(${fails.length} 条硬伤):`)
223
- for (const f of fails) console.error(` - ${f}`)
224
- process.exit(1)
225
- }
226
- console.log(`\n✅ 发版检查通过${STRICT ? '(strict)' : ''}:可以 npm publish / 提 market PR`)
1
+ #!/usr/bin/env node
2
+ /**
3
+ * release-check.mjs —— 发版前的守门(2026-11-18,v0.1.7 起每次发布必跑)
4
+ *
5
+ * node scripts/release-check.mjs # 普通检查:有硬伤就 exit 1
6
+ * node scripts/release-check.mjs --strict # 发布用:再加「本机隐私名单 / profile 依赖」硬校验
7
+ *
8
+ * 检查四类东西:
9
+ * 1) 打包内容——不能带 data/、.state/、*.bak、*.lnk、cookie、私聊库、本地密钥脚本、tmp/;
10
+ * 2) 包里内容——不能出现 token / 私钥 / 真实账号(名单从本机 private-people.json 读,脚本本身不存 id);
11
+ * 3) 兼容性——入口文件语法、必需文件齐全、不能写死本机绝对路径(只警告,列出清单);
12
+ * 4) 新用户可用性——人设必须有内置默认值(没有 character.json 也要有情绪和世界观)。
13
+ *
14
+ * 退出码:0 通过(可能有警告);1 有硬伤,禁止发布。
15
+ */
16
+ import { execFileSync } from 'node:child_process'
17
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
18
+ import { dirname, join, relative, sep } from 'node:path'
19
+ import { fileURLToPath } from 'node:url'
20
+
21
+ const REPO = dirname(dirname(fileURLToPath(import.meta.url)))
22
+ const STRICT = process.argv.includes('--strict')
23
+ const fails = []
24
+ const warns = []
25
+
26
+ function fail(msg) { fails.push(msg) }
27
+ function warn(msg) { warns.push(msg) }
28
+ function ok(msg) { console.log(`✓ ${msg}`) }
29
+
30
+ // ── 0. 基本文件 ─────────────────────────────────────────────────────────────
31
+ const REQUIRED = [
32
+ 'package.json', 'index.js', 'entry.js', 'cordis.patch.yml', 'install.mjs',
33
+ 'README.md', 'CHANGELOG.md', 'settings-host.js',
34
+ 'dist/gateway/bootstrap.js',
35
+ 'dshqqbot/.qqbot-extensions/lib/private-guard.mjs',
36
+ 'dshqqbot/.qqbot-extensions/live/persona.mjs',
37
+ 'scripts/dsh-profile-links.mjs',
38
+ 'scripts/dsh-profile-preflight.mjs',
39
+ ]
40
+ for (const f of REQUIRED) if (!existsSync(join(REPO, f))) fail(`缺少必需文件:${f}`)
41
+ if (!fails.length) ok(`必需文件齐全(${REQUIRED.length} 项)`)
42
+
43
+ // ── 0.1 兼容性回归守卫(2026-12-04)────────────────────────────────────────
44
+ // dsh-next 内核每次启动会把 settings.yaml 改名成 .imported,插件只认原名时
45
+ // groupAdmin / owner 权限会整体失效。上次是手工给用户机器打补丁,插件一更新
46
+ // 就被冲掉 —— 这里把它变成发布硬门槛:兜底不在就不许发版。
47
+ {
48
+ const f = join(REPO, 'dist/model/settings-reader.js')
49
+ try {
50
+ const src = readFileSync(f, 'utf8')
51
+ const need = ['settings.yaml.imported', 'settings.imported', 'DSH_HOME']
52
+ const miss = need.filter((n) => !src.includes(n))
53
+ if (miss.length) fail(`settings-reader.js 缺少 dsh-next 兼容兜底:${miss.join(' / ')}(少了会导致群管/owner 失效)`)
54
+ else ok('settings.yaml 兼容兜底在位(.imported 链 + DSH_HOME)')
55
+ }
56
+ catch (e) {
57
+ fail(`读不到 dist/model/settings-reader.js:${e instanceof Error ? e.message : String(e)}`)
58
+ }
59
+ }
60
+
61
+ const pkg = JSON.parse(readFileSync(join(REPO, 'package.json'), 'utf8'))
62
+ const version = String(pkg.version || '0.0.0')
63
+ if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(version)) fail(`package.json version 不是合法 semver:${version}`)
64
+ ok(`版本 ${pkg.name}@${version}`)
65
+
66
+ // ── 1. 打包内容清单(npm pack --dry-run,离线可用)────────────────────────────
67
+ let packed = []
68
+ try {
69
+ const raw = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], {
70
+ cwd: REPO, encoding: 'utf8', shell: process.platform === 'win32', stdio: ['ignore', 'pipe', 'pipe'],
71
+ })
72
+
73
+ const j = JSON.parse(raw.slice(raw.indexOf('[')))
74
+ packed = (j[0]?.files || []).map((f) => String(f.path).replace(/\\/g, '/'))
75
+ } catch (e) {
76
+ warn(`npm pack --dry-run 失败,改用 files 字段估算:${e?.message ?? e}`)
77
+ packed = ['package.json']
78
+ }
79
+
80
+ const FORBIDDEN_PATH = [
81
+ /(^|\/)data\//, /\.state\//, /\.bak($|[-.0-9])/, /\.lnk$/, /\.db($|-)/, /\.ndjson$/,
82
+ /(^|\/)tmp\//, /(^|\/)logs\//, /private-people/i, /douyin-cookie/i,
83
+ /wcx-token|bridge-token|env\.json|credentials/i, /wx4-[^/]*\.(ps1|cmd)$/,
84
+ /(^|\/)secrets\//, /memory\.db$/, /\.sqlite3?$/,
85
+ ]
86
+ const badPaths = packed.filter((p) => FORBIDDEN_PATH.some((re) => re.test(p)))
87
+ if (badPaths.length) fail(`发布包里混进了隐私/运行时文件(${badPaths.length} 个):${badPaths.slice(0, 8).join(', ')}`)
88
+ else ok(`打包清单干净(${packed.length} 个文件,无 data/.state/cookie/密钥/私聊库)`)
89
+
90
+ // ── 2. 包里内容扫描 ─────────────────────────────────────────────────────────
91
+ const TEXT_EXT = /\.(mjs|js|cjs|ts|json|ya?ml|md|txt|html|css|ps1|cmd|bat)$/i
92
+ const SECRET_PATTERNS = [
93
+ [/sk-[A-Za-z0-9_-]{16,}/, '疑似 API Key(sk-)'],
94
+ [/gh[pousr]_[A-Za-z0-9]{20,}/, '疑似 GitHub Token'],
95
+ [/AKIA[0-9A-Z]{16}/, '疑似 AWS Key'],
96
+ [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, '疑似私钥'],
97
+ [/(_authToken|NODE_AUTH_TOKEN)\s*[=:]\s*\S+/, '疑似 npm token 写法'],
98
+ [/Bearer\s+[A-Za-z0-9._-]{24,}/, '疑似 Bearer token'],
99
+ [/\bsk-[A-Za-z0-9]{32,}\b/, '疑似长 key'],
100
+ ]
101
+
102
+ // 本机真实账号名单:只从本机数据读,脚本本身不带任何 id
103
+ const localIds = new Set()
104
+ const peopleFile = join(REPO, 'dshqqbot', '.qqbot', 'private-people.json')
105
+ if (existsSync(peopleFile)) {
106
+ try {
107
+ for (const p of JSON.parse(readFileSync(peopleFile, 'utf8'))) {
108
+ for (const k of ['qq', 'wx', 'douyin']) if (p?.[k]) localIds.add(String(p[k]))
109
+ if (p?.name && String(p.name).length >= 2) localIds.add(String(p.name))
110
+ }
111
+ } catch (e) { warn(`读取 ${peopleFile} 失败:${e?.message ?? e}`) }
112
+ } else if (STRICT) {
113
+ warn(`没有 ${peopleFile},跳过「真实账号」扫描(strict 下建议先建这份名单)`)
114
+ }
115
+
116
+ // 另外从本机的会话台账/通讯录里再收一批 id(防止名单文件没列的账号漏网)
117
+ for (const extra of [
118
+ join(REPO, 'dshqqbot', '.qqbot', 'xtc-peers.json'),
119
+ join(REPO, 'xtc-bridge', 'people.json'),
120
+ ]) {
121
+ if (!existsSync(extra)) continue
122
+ try {
123
+ const j = JSON.parse(readFileSync(extra, 'utf8'))
124
+ const walk = (v) => {
125
+ if (typeof v === 'string' && /^[0-9A-Za-z_-]{6,64}$/.test(v) && /\d/.test(v)) localIds.add(v)
126
+ else if (Array.isArray(v)) v.forEach(walk)
127
+ else if (v && typeof v === 'object') { for (const [k, vv] of Object.entries(v)) { walk(k); walk(vv) } }
128
+ }
129
+ walk(j)
130
+ } catch { /* 忽略 */ }
131
+ }
132
+ // 8 位以上纯数字句柄(openid 尾号、xtcId 之类)也算隐私,别写进包里
133
+ const NUMERIC_ID_RE = /\d{8,12}/
134
+
135
+ const hits = []
136
+ let scanned = 0
137
+ for (const rel of packed) {
138
+ if (!TEXT_EXT.test(rel)) continue
139
+ const abs = join(REPO, rel.split('/').join(sep))
140
+ if (!existsSync(abs)) continue
141
+ let txt = ''
142
+ try {
143
+ if (statSync(abs).size > 4 * 1024 * 1024) continue
144
+ txt = readFileSync(abs, 'utf8')
145
+ } catch { continue }
146
+ scanned += 1
147
+ for (const [re, label] of SECRET_PATTERNS) {
148
+ if (re.test(txt)) hits.push(`${rel}: ${label}`)
149
+ }
150
+ for (const id of localIds) {
151
+ if (id.length >= 6 && txt.includes(id)) hits.push(`${rel}: 含本机真实账号/姓名「${id.slice(0, 4)}…」`)
152
+ }
153
+ if (rel.endsWith('.md')) {
154
+ const m = txt.match(NUMERIC_ID_RE)
155
+ if (m) hits.push(`${rel}: 出现疑似账号数字「${m[0]}」`)
156
+ }
157
+ }
158
+ if (hits.length) {
159
+ for (const h of hits.slice(0, 12)) fail(`内容泄露:${h}`)
160
+ } else {
161
+ ok(`内容扫描通过(${scanned} 个文本文件,无 token/私钥/本机账号)`)
162
+ }
163
+
164
+ // ── 3. 兼容性 ───────────────────────────────────────────────────────────────
165
+ const ENTRY_FILES = ['index.js', 'entry.js', 'settings-host.js', 'install.mjs', 'dist/gateway/bootstrap.js',
166
+ 'dshqqbot/.qqbot-extensions/lib/private-guard.mjs', 'dshqqbot/.qqbot-extensions/live/persona.mjs']
167
+ for (const f of ENTRY_FILES) {
168
+ const abs = join(REPO, f)
169
+ if (!existsSync(abs)) continue
170
+ try {
171
+ execFileSync(process.execPath, ['--check', abs], { stdio: 'pipe' })
172
+ } catch (e) {
173
+ fail(`语法错误:${f}\n${String(e?.stderr || e?.message || e).slice(0, 400)}`)
174
+ }
175
+ }
176
+ ok(`入口语法检查通过(${ENTRY_FILES.length} 个文件)`)
177
+
178
+ // 本机 profile 依赖写法(npm 绝对盘符 file: → pnpm 拼路径 → 安全模式)
179
+ const appData = process.env.APPDATA || ''
180
+ if (appData) {
181
+ const prof = join(appData, 'dsh-desktop', 'harness', 'profiles', 'web', 'package.json')
182
+ if (existsSync(prof)) {
183
+ try {
184
+ const man = JSON.parse(readFileSync(prof, 'utf8'))
185
+ const deps = { ...(man.dependencies || {}), ...(man.devDependencies || {}) }
186
+ const bad = Object.entries(deps).filter(([, v]) => typeof v === 'string' && /^file:[A-Za-z]:[\\/]/.test(v))
187
+ if (bad.length) {
188
+ const msg = `本机 profile 有绝对盘符 file: 依赖(会让 DSH 进安全模式):${bad.map(([k]) => k).join(', ')} → 跑 node scripts/dsh-profile-links.mjs`
189
+ if (STRICT) fail(msg)
190
+ else warn(msg)
191
+ } else ok('profile 依赖写法正常(无绝对盘符 file:)')
192
+ } catch { warn('读取本机 profile 的 package.json 失败(跳过)') }
193
+ }
194
+ }
195
+
196
+ // 写死的本机绝对路径(只警告,列出来慢慢清)
197
+ const ABS_PATH_RE = /["'`]([A-Za-z]:[\\/][^"'`\n]{3,})["'`]/
198
+ const absOffenders = []
199
+ for (const rel of packed) {
200
+ if (!TEXT_EXT.test(rel) || rel.endsWith('.md')) continue
201
+ const abs = join(REPO, rel.split('/').join(sep))
202
+ if (!existsSync(abs)) continue
203
+ let txt = ''
204
+ try { txt = readFileSync(abs, 'utf8') } catch { continue }
205
+ let n = 0
206
+ for (const line of txt.split('\n')) {
207
+ if (/^\s*(\*|\/\/|#)/.test(line)) continue
208
+ // 系统目录(Windows 字体 / Program Files)不算「作者本机路径」,允许作为兜底
209
+ const sysLine = line.indexOf('Windows') >= 0 || line.indexOf('Program Files') >= 0
210
+ if (!sysLine && ABS_PATH_RE.test(line)) n += 1
211
+ }
212
+ if (n) absOffenders.push(`${relative(REPO, abs).split(sep).join('/')}(${n} 处)`)
213
+ }
214
+ if (absOffenders.length) {
215
+ warn(`代码里还有 ${absOffenders.length} 个文件写着本机绝对路径(别人机器上会失效,建议逐步改成从 import.meta.url 推):${absOffenders.slice(0, 6).join('、')}${absOffenders.length > 6 ? ' …' : ''}`)
216
+ } else {
217
+ ok('没有写死的本机绝对路径')
218
+ }
219
+
220
+ // ── 4. 新用户可用性:默认人设/世界观 ─────────────────────────────────────────
221
+ const personaFile = join(REPO, 'dshqqbot', '.qqbot-extensions', 'live', 'persona.mjs')
222
+ if (existsSync(personaFile)) {
223
+ const t = readFileSync(personaFile, 'utf8')
224
+ const hasDefaultName = /j\?\.name\s*\|\|\s*'[^']+'/.test(t)
225
+ const hasDefaultSpecies = /j\?\.species\s*\|\|\s*'[^']+'/.test(t)
226
+ const hasCore = /j\?\.core[^\n]*(\|\||:)\s*'[^']+'/.test(t)
227
+ if (!(hasDefaultName && hasDefaultSpecies && hasCore)) fail('persona.mjs 缺少内置默认人设(新用户会没有性格/世界观)')
228
+ else ok('默认人设齐全(名字 / 种族 / 性格 都有内置兜底)')
229
+ } else {
230
+ fail('缺少 live/persona.mjs')
231
+ }
232
+
233
+ // ── 汇总 ────────────────────────────────────────────────────────────────────
234
+ console.log('')
235
+ if (warns.length) {
236
+ console.log(`⚠ 警告 ${warns.length} 条:`)
237
+ for (const w of warns) console.log(` - ${w}`)
238
+ }
239
+ if (fails.length) {
240
+ console.error(`\n✗ 发版检查未通过(${fails.length} 条硬伤):`)
241
+ for (const f of fails) console.error(` - ${f}`)
242
+ process.exit(1)
243
+ }
244
+ console.log(`\n✅ 发版检查通过${STRICT ? '(strict)' : ''}:可以 npm publish / 提 market PR`)