dsh-qqbot-muu 0.1.12 → 0.1.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/CHANGELOG.md +18 -6
- package/dist/gateway/data-root.js +33 -2
- package/dist/session/session-manager.js +28 -0
- package/dist/transport/outbound.js +46 -0
- package/docs/README.md +2 -2
- package/docs/RELEASE_CHECKLIST.md +1 -1
- package/dshqqbot/.qqbot-extensions/interview/keepalive.bat +13 -3
- package/package.json +3 -3
- package/scripts/release-all.mjs +79 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
-
## 0.1.11
|
|
3
|
+
## 0.1.14 — 2026-11-20
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
5
|
+
这一版只修问题,不加花活:把「长上下文开不了新会话」「工具卡住整会话焊死」「装在只读目录就报路径错误」「发布流程会并发/乱发版本」四件事处理掉。
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
- **上下文过长后开不了新会话**:以前一个会话的上下文越堆越多,最后模型直接报超长、新消息进不来,只能手动删档。现在两处兜底(`dist/transport/outbound.js` + `dist/session/session-manager.js`):
|
|
9
|
+
- 回合结束时如果报「上下文超长 / token 超限」,立刻换一份新会话档(旧档文件保留,可在侧边栏回看),下一条消息从干净上下文开始;
|
|
10
|
+
- 回合数超过阈值(默认 60 回合,`QQBOT_SESSION_MAX_TURNS` 可调)也会主动换档,避免无限堆积。
|
|
11
|
+
- 人设和长期记忆不在会话档里(每轮由 persona / recall 重新注入),换档不丢性格、不丢印象卡与记忆。
|
|
12
|
+
- **工具调用卡住把会话焊死**:加了回合看门狗(`QQBOT_TURN_TIMEOUT_MS`,默认 15 分钟)。卡住的回合会被取消并写一条明确的 warn(带会话 key 和已卡时长),下一条消息能正常进来,不再出现「消息来了但永远不回应、日志里还查不到原因」。
|
|
13
|
+
- **数据根不可写就整套报路径错误**:`dist/gateway/data-root.js` 新增落点兜底 —— `{cwd}/dshqqbot` 建不出来(只读目录/系统目录)时自动退到用户主目录下的 `.dsh-qqbot`,并只 warn 一次;用户也可以继续用 `dataRoot` 指定位置。
|
|
14
|
+
- **面试陪练的 keepalive 脚本写死 `F:\nodejs\node.exe`**:改成先找 PATH 里的 `node`,再找常见安装目录,找不到就写日志跳过 —— 别人机器上不会再因为这一行直接失败。
|
|
15
|
+
|
|
16
|
+
### 发版流程(用户要求:禁止并发、一次只发一个、每次都要有内容)
|
|
17
|
+
- `scripts/release-all.mjs` 增加发布闸门,任一不满足就停,绝不推:
|
|
18
|
+
- 同一时间只允许一个发布进程(`tmp/release.lock` + pid 存活判断,30 分钟视为陈旧锁);
|
|
19
|
+
- 版本号必须比 npm 上的 `latest` 新,且 npm / git tag 里都不能已经存在;
|
|
20
|
+
- `CHANGELOG.md` 必须有这一版的一节,避免「空版本」。
|
|
21
|
+
- 仍然是一条命令:`npm run ci`(只体检)、`npm run release`(CI → 隐私扫描 → 提交 → GitHub → npm → 市场条目)。
|
|
10
22
|
|
|
11
23
|
## 0.1.9
|
|
12
24
|
|
|
@@ -9,13 +9,44 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 迁移: 首次启动时, 若 cwd 下存在旧数据目录而数据根下还没有, 自动整目录搬移(rename, 同盘瞬时完成), 不覆盖已有目标。
|
|
11
11
|
*/
|
|
12
|
-
import { existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
12
|
+
import { accessSync, constants, existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
13
|
+
import { homedir } from 'node:os';
|
|
13
14
|
import { join, resolve } from 'node:path';
|
|
14
15
|
import { absCwdOf } from '../util/abs-path.js';
|
|
15
16
|
/** 旧版数据直接落在 agent cwd 的清单(与数据根对应的相对布局; 目录+散文件) */
|
|
16
17
|
export const DATA_SUBDIRS = ['表情包', '.qqbot', '.qqbot-extensions', 'schedule-state.json', 'botplay-events.json'];
|
|
17
18
|
/** 未配置 dataRoot 时的默认数据子目录名(通用设计: 让工作目录保持干净) */
|
|
18
19
|
export const DEFAULT_DATA_SUBDIR = 'dshqqbot';
|
|
20
|
+
const _writableCache = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* 0.1.14:数据根落点兜底。
|
|
23
|
+
* 用户反馈「装上就报路径错误」的根因之一:插件从只读目录/系统目录启动时,
|
|
24
|
+
* {cwd}/dshqqbot 建不出来(EPERM/EACCES),之后所有读写全炸。
|
|
25
|
+
* 先试首选目录;建不出来就退到用户主目录下的 .dsh-qqbot,并只 warn 一次。
|
|
26
|
+
*/
|
|
27
|
+
function pickWritableRoot(preferred) {
|
|
28
|
+
const hit = _writableCache.get(preferred);
|
|
29
|
+
if (hit)
|
|
30
|
+
return hit;
|
|
31
|
+
let chosen = preferred;
|
|
32
|
+
try {
|
|
33
|
+
mkdirSync(preferred, { recursive: true });
|
|
34
|
+
accessSync(preferred, constants.W_OK);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
const fallback = join(homedir(), '.dsh-qqbot');
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(fallback, { recursive: true });
|
|
40
|
+
chosen = fallback;
|
|
41
|
+
console.warn(`[data-root] ${preferred} 不可写,数据改存 ${fallback}(可用 dataRoot 指定位置)`);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
chosen = preferred;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
_writableCache.set(preferred, chosen);
|
|
48
|
+
return chosen;
|
|
49
|
+
}
|
|
19
50
|
/**
|
|
20
51
|
* 插件数据根: config.dataRoot(绝对化) > `{cwd}/dshqqbot` > 进程 cwd。
|
|
21
52
|
*
|
|
@@ -30,7 +61,7 @@ export function dataRootOf(config) {
|
|
|
30
61
|
return r;
|
|
31
62
|
// ⚠️ cwd 必须绝对化:安卓/设置页可能给出 "storage\emulated\0\大肥鱼" 这种相对路径,
|
|
32
63
|
// 直接 join 会被解析到 process.cwd() 下,凭空多出一套幽灵数据根(issue #18)。
|
|
33
|
-
return join(absCwdOf(config.cwd) || process.cwd(), DEFAULT_DATA_SUBDIR);
|
|
64
|
+
return pickWritableRoot(join(absCwdOf(config.cwd) || process.cwd(), DEFAULT_DATA_SUBDIR));
|
|
34
65
|
}
|
|
35
66
|
/** 图库/台账/活性计数等通用数据目录: config.sticker.dataDir 覆盖 > {dataRoot}/表情包 */
|
|
36
67
|
export function stickerDirOf(config) {
|
|
@@ -1519,6 +1519,34 @@ export class SessionManager {
|
|
|
1519
1519
|
return false;
|
|
1520
1520
|
}
|
|
1521
1521
|
}
|
|
1522
|
+
/**
|
|
1523
|
+
* 0.1.14:主动换一份新会话档(旧档文件保留在 sessions 目录,可在侧边栏回看)。
|
|
1524
|
+
* 人设/记忆由插件每轮重新注入,换档不影响性格与长期记忆,只是把上下文清零。
|
|
1525
|
+
*/
|
|
1526
|
+
async forceRotate(scope, peerId, reason = 'context') {
|
|
1527
|
+
const key = this.sessionKey(scope, peerId);
|
|
1528
|
+
const record = this.sessions.get(key);
|
|
1529
|
+
const fresh = SessionId(randomUUID());
|
|
1530
|
+
try {
|
|
1531
|
+
this.modelResolver.setSessionId(key, fresh);
|
|
1532
|
+
}
|
|
1533
|
+
catch { /* 记不下就算了,下面照样清内存 */ }
|
|
1534
|
+
if (!record) {
|
|
1535
|
+
this.logger.warn(`forceRotate(no-record): key=${key} new=${fresh} reason=${reason}`);
|
|
1536
|
+
return { rotated: true, sessionId: fresh };
|
|
1537
|
+
}
|
|
1538
|
+
this.sessions.delete(key);
|
|
1539
|
+
try {
|
|
1540
|
+
record.agent.cancel({ kind: 'user' });
|
|
1541
|
+
}
|
|
1542
|
+
catch { /* ignore */ }
|
|
1543
|
+
try {
|
|
1544
|
+
await record.handle.dispose();
|
|
1545
|
+
}
|
|
1546
|
+
catch { /* ignore */ }
|
|
1547
|
+
this.logger.warn(`forceRotate: key=${key} old=${record.sessionId} new=${fresh} reason=${reason}`);
|
|
1548
|
+
return { rotated: true, sessionId: fresh };
|
|
1549
|
+
}
|
|
1522
1550
|
async remove(scope, peerId) {
|
|
1523
1551
|
const key = this.sessionKey(scope, peerId);
|
|
1524
1552
|
const record = this.sessions.get(key);
|
|
@@ -119,6 +119,36 @@ class OutboundRouter {
|
|
|
119
119
|
*/
|
|
120
120
|
turnAcc = new Map();
|
|
121
121
|
constructor(manager, bot, config, logger, toolsRegistry) {
|
|
122
|
+
this.manager = manager;
|
|
123
|
+
// 0.1.14:回合看门狗 —— 用户反馈「会话超时后工具调用卡住、日志看不到原因」。
|
|
124
|
+
// 回合超过 N 分钟没有结束(默认 15 分钟,QQBOT_TURN_TIMEOUT_MS 可调)就:
|
|
125
|
+
// 写一条明确的 warn(带 sessionKey / 已过时长 / 是否有工具在跑)→ cancel 本回合,
|
|
126
|
+
// 让会话回到空闲,下一条消息能正常进来;不再出现"消息进来但永远不回应"。
|
|
127
|
+
const _stuckMs = Number(process.env.QQBOT_TURN_TIMEOUT_MS || 15 * 60_000) || 15 * 60_000;
|
|
128
|
+
this.stuckWatchdog = setInterval(() => {
|
|
129
|
+
try {
|
|
130
|
+
const recs = this.manager?.sessions;
|
|
131
|
+
if (!recs || typeof recs.values !== 'function')
|
|
132
|
+
return;
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
for (const rec of recs.values()) {
|
|
135
|
+
if (!rec?.turnActive || !rec.turnStartedAt)
|
|
136
|
+
continue;
|
|
137
|
+
const idle = now - rec.turnStartedAt;
|
|
138
|
+
if (idle < _stuckMs)
|
|
139
|
+
continue;
|
|
140
|
+
this.logger.warn?.(`im-qqbot: 回合卡住 ${Math.round(idle / 60000)} 分钟,已取消 key=${rec.sessionKey}(可用 QQBOT_TURN_TIMEOUT_MS 调整阈值)`);
|
|
141
|
+
try {
|
|
142
|
+
rec.agent?.cancel?.({ kind: 'user' });
|
|
143
|
+
}
|
|
144
|
+
catch { /* ignore */ }
|
|
145
|
+
rec.turnActive = false;
|
|
146
|
+
rec.turnStartedAt = undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch { /* 看门狗自身异常不影响出站 */ }
|
|
150
|
+
}, 60_000);
|
|
151
|
+
this.stuckWatchdog.unref?.();
|
|
122
152
|
this.manager = manager;
|
|
123
153
|
this.bot = bot;
|
|
124
154
|
this.config = config;
|
|
@@ -329,6 +359,7 @@ class OutboundRouter {
|
|
|
329
359
|
// turn/end 复位 false → 攒的消息才批量入站。assistant/tool 事件=回合活跃。
|
|
330
360
|
if (event.type === 'turn/end') {
|
|
331
361
|
record.turnActive = false;
|
|
362
|
+
record.turnStartedAt = undefined;
|
|
332
363
|
// 插话计数随回合结束清零(2026-10-09)→ 下一回合的第一次插话又用完整提示
|
|
333
364
|
record.interjectSeq = 0;
|
|
334
365
|
// 好感度结算:整个回合算**一次**(放在 silent/nothink 早退之前 —— "照常思考"也包括潜水)
|
|
@@ -353,6 +384,7 @@ class OutboundRouter {
|
|
|
353
384
|
else if (event.type === 'assistant/chunk' || event.type === 'assistant/message'
|
|
354
385
|
|| event.type === 'tool/call' || event.type === 'tool/result') {
|
|
355
386
|
record.turnActive = true;
|
|
387
|
+
record.turnStartedAt = record.turnStartedAt ?? Date.now();
|
|
356
388
|
}
|
|
357
389
|
// 完全不出站(silent)= 照常思考但所有回复不向 QQ 发(静默潜水; dock/web 仍可见思考流);
|
|
358
390
|
// 完全不思考(nothink)= QQ 入站根本不唤醒 LLM(见 inbound), 这里防御性兜底同样吞。
|
|
@@ -533,6 +565,20 @@ class OutboundRouter {
|
|
|
533
565
|
finish();
|
|
534
566
|
}
|
|
535
567
|
const failure = extractTurnError(event.reason);
|
|
568
|
+
// 0.1.14(用户反馈:上下文过长后开不了新会话):
|
|
569
|
+
// ① 本回合报"上下文超长/token 超限" → 立刻换新档(旧档保留),下一轮从干净上下文开始;
|
|
570
|
+
// ② 回合数超过阈值(默认 60,可用 QQBOT_SESSION_MAX_TURNS 调)→ 同样换新档,避免无限堆积。
|
|
571
|
+
// 人设与记忆不在会话档里(每轮由 persona / recall 重新注入),换档不丢性格和长期记忆。
|
|
572
|
+
record.turns = (record.turns ?? 0) + 1;
|
|
573
|
+
const _errText = failure === undefined ? '' : (String(failure.code ?? '') + ' ' + String(failure.message ?? '')).toLowerCase();
|
|
574
|
+
const _overflow = _errText !== '' && /context|too long|maximum|token limit|413|超长|超出/.test(_errText);
|
|
575
|
+
const _maxTurns = Number(process.env.QQBOT_SESSION_MAX_TURNS || 60) || 60;
|
|
576
|
+
const _turnLimit = this.config.sessionRotateByTurns !== false && record.turns >= _maxTurns;
|
|
577
|
+
if ((_overflow || _turnLimit) && typeof this.manager?.forceRotate === 'function') {
|
|
578
|
+
const _why = _overflow ? 'context-overflow' : 'turn-limit';
|
|
579
|
+
this.logger.warn?.(`im-qqbot: 换新档 key=${record.sessionKey} turns=${record.turns} reason=${_why}`);
|
|
580
|
+
void Promise.resolve(this.manager.forceRotate(record.scope, record.peerId ?? record.targetId, _why)).catch((e) => this.logger.warn?.(`im-qqbot: 换档失败: ${e instanceof Error ? e.message : String(e)}`));
|
|
581
|
+
}
|
|
536
582
|
// 闸门静默导致的"取消"不是故障 —— 这个回合本来就不该出声(2026-09-14 主人要求)
|
|
537
583
|
if (failure !== undefined && !SILENT_TURN_ERROR_CODES.has(failure.code) && !silenced) {
|
|
538
584
|
void this.send(_record, `⚠️ 本轮异常结束\n\`${failure.code}\`: ${failure.message}`, 'sendTurnEndError');
|
package/docs/README.md
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
- [releases/2026-11-07-运维收口.md](releases/2026-11-07-运维收口.md) — 本批次快照(替代 tag;回滚按文件清单)
|
|
15
15
|
- 发布流程见 `publish-flow.md`(存档);视频链路见 `视频链路.md`;其余为专题笔记。
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
含隐私的材料已移到仓库根的 `secrets/docs/`(不进 git、不进发布包):
|
|
18
18
|
|
|
19
19
|
- `两段会话消息.md`(含真实 QQ 号/openid 与聊天节选)
|
|
20
20
|
- `密钥与Token.md`(部署与轮换说明)
|
|
21
21
|
|
|
22
|
-
`
|
|
22
|
+
`secrets/` 整个目录都在 `.gitignore` 里,不会进仓库,也不会随插件包发布。
|
|
23
23
|
|
|
24
24
|
浮窗截图(`assets/shot-*.png`)和 `screenshots.json` 同样含真实群名/昵称,已单独忽略;市场用的截图需要重新做脱敏版。
|
|
@@ -94,5 +94,5 @@ pnpm 会把它当相对路径拼成 `<profile>\F:\qqbot`,scandir 失败 →
|
|
|
94
94
|
|
|
95
95
|
## 6. 已知未清的技术债
|
|
96
96
|
|
|
97
|
-
-
|
|
97
|
+
- 绝对路径已在 0.1.8 清完(运行期一律按「环境变量 → 模块位置 → cwd」推导);还剩少量注释/示例里提到旧路径,不影响运行。
|
|
98
98
|
- 微信 4.0 本地库是 SQLCipher 加密,正文导出仍缺密钥;媒体文件(`msg/attach`)可直接归档。
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@echo off
|
|
2
2
|
rem interview standalone keepalive (ASCII only: cmd parses bat as ANSI, UTF-8 Chinese breaks it)
|
|
3
3
|
rem 2026-11-09: keep 4321 alive so shared interview links never die.
|
|
4
|
-
rem same idea as wechat-bridge/start-bridge.bat: skip when already listening
|
|
5
|
-
rem
|
|
4
|
+
rem same idea as wechat-bridge/start-bridge.bat: skip when already listening.
|
|
5
|
+
rem 0.1.14: node 位置不再写死(原来写死某台机器的 F:\nodejs\node.exe,别人机器上必坏)。
|
|
6
6
|
cd /d "%~dp0"
|
|
7
7
|
|
|
8
8
|
netstat -ano | findstr /C:":4321" | findstr /C:"LISTENING" >nul 2>&1
|
|
@@ -13,4 +13,14 @@ if not exist "%LOGDIR%" mkdir "%LOGDIR%"
|
|
|
13
13
|
if not exist %TEMP%\interview-key.txt echo xiaolan> %TEMP%\interview-key.txt
|
|
14
14
|
set /p IKEY=<%TEMP%\interview-key.txt
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
set "NODE_BIN="
|
|
17
|
+
for /f "delims=" %%i in ('where node 2^>nul') do if not defined NODE_BIN set "NODE_BIN=%%i"
|
|
18
|
+
if not defined NODE_BIN if exist "%ProgramFiles%\nodejs\node.exe" set "NODE_BIN=%ProgramFiles%\nodejs\node.exe"
|
|
19
|
+
if not defined NODE_BIN if exist "%ProgramFiles(x86)%\nodejs\node.exe" set "NODE_BIN=%ProgramFiles(x86)%\nodejs\node.exe"
|
|
20
|
+
if not defined NODE_BIN if exist "%LOCALAPPDATA%\Programs\nodejs\node.exe" set "NODE_BIN=%LOCALAPPDATA%\Programs\nodejs\node.exe"
|
|
21
|
+
if not defined NODE_BIN (
|
|
22
|
+
echo [keepalive] node not found, skip > "%LOGDIR%\standalone.log"
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
"%NODE_BIN%" standalone.mjs --port 4321 --key %IKEY% >> "%LOGDIR%\standalone.log" 2>&1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-qqbot-muu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "独立的 DSH QQ 桌宠助手插件:统一记忆库/印象卡、人格注入、表情包视觉打标、三形态桌宠+公网受限链接、逐帧视频流水线、B站运营(自持底盘,零 @zaofan 依赖)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./entry.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./client": "./client/qqbot-settings.js"
|
|
25
25
|
},
|
|
26
26
|
"bin": {
|
|
27
|
-
"dsh-qqbot-muu-install": "
|
|
27
|
+
"dsh-qqbot-muu-install": "install.mjs"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"index.js",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"author": "wuwo1979",
|
|
101
101
|
"repository": {
|
|
102
102
|
"type": "git",
|
|
103
|
-
"url": "https://github.com/wuwo1979/dsh-qqbot-muu"
|
|
103
|
+
"url": "git+https://github.com/wuwo1979/dsh-qqbot-muu.git"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
106
106
|
"release:check": "node scripts/release-check.mjs",
|
package/scripts/release-all.mjs
CHANGED
|
@@ -20,6 +20,7 @@ const REPO = 'wuwo1979/dsh-qqbot-muu'
|
|
|
20
20
|
const FORK = 'wuwo1979/awesome-dsh-plugin'
|
|
21
21
|
const UPSTREAM = 'awesome-dsh-plugin/awesome-dsh-plugin'
|
|
22
22
|
const MARKET_BRANCH = 'release/dsh-qqbot-muu-v0.1.7'
|
|
23
|
+
let NPM_PENDING = ''
|
|
23
24
|
const MARKET_PR = 17081 // 0 = 每次新开 PR;>0 表示复用该 PR 号
|
|
24
25
|
const MARKET_FILE = 'data/plugins/wuwo1979__dsh-qqbot-muu.yml'
|
|
25
26
|
const LOCAL_MARKET = 'submission/data/plugins/wuwo1979__dsh-qqbot-muu.yml'
|
|
@@ -71,6 +72,58 @@ const TAG = `v${VERSION}`
|
|
|
71
72
|
const TGZ = `dsh-qqbot-muu-${VERSION}.tgz`
|
|
72
73
|
console.log(` ${c.dim}版本 ${VERSION}${c.end}`)
|
|
73
74
|
|
|
75
|
+
// ── 发布闸门:并发/版本(用户 2026-11-20 要求)─────────────────────────────
|
|
76
|
+
// ① 同一时间只允许一个发布进程(锁文件 + pid 存活判断,30 分钟视为陈旧锁);
|
|
77
|
+
// ② 版本必须严格大于 npm 上的 latest,且不能是已存在过的版本(npm / git tag 任一已存在就停);
|
|
78
|
+
// ③ 版本必须有实际内容(CHANGELOG 里要有这一版的一节)。
|
|
79
|
+
{
|
|
80
|
+
const LOCK = 'tmp/release.lock'
|
|
81
|
+
const { mkdirSync, rmSync, readFileSync: rf, writeFileSync: wf } = await import('node:fs')
|
|
82
|
+
if (!CHECK_ONLY) {
|
|
83
|
+
mkdirSync('tmp', { recursive: true })
|
|
84
|
+
if (existsSync(LOCK)) {
|
|
85
|
+
let info = null
|
|
86
|
+
try { info = JSON.parse(rf(LOCK, 'utf8')) } catch { /* 坏锁当陈旧锁 */ }
|
|
87
|
+
const age = info?.at ? Date.now() - info.at : Infinity
|
|
88
|
+
let alive = false
|
|
89
|
+
if (info?.pid) {
|
|
90
|
+
try { process.kill(info.pid, 0); alive = true } catch { alive = false }
|
|
91
|
+
}
|
|
92
|
+
if (alive && age < 30 * 60_000) die(`另一个发布流程正在跑(pid=${info.pid}),等它结束再来`)
|
|
93
|
+
rmSync(LOCK, { force: true })
|
|
94
|
+
}
|
|
95
|
+
wf(LOCK, JSON.stringify({ pid: process.pid, at: Date.now(), version: VERSION }))
|
|
96
|
+
process.on('exit', () => { try { rmSync(LOCK, { force: true }) } catch { /* ignore */ } })
|
|
97
|
+
for (const sig of ['SIGINT', 'SIGTERM']) process.on(sig, () => { try { rmSync(LOCK, { force: true }) } catch { /* ignore */ } ; process.exit(130) })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 版本必须比 npm latest 新
|
|
101
|
+
const view = tryRun('npm', ['view', 'dsh-qqbot-muu', 'version', '--silent'])
|
|
102
|
+
const latest = String(view.out || '').trim()
|
|
103
|
+
if (view.ok && latest) {
|
|
104
|
+
const cmp = (a, b) => {
|
|
105
|
+
const pa = a.split('.').map(Number), pb = b.split('.').map(Number)
|
|
106
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
107
|
+
const d = (pa[i] || 0) - (pb[i] || 0)
|
|
108
|
+
if (d) return d
|
|
109
|
+
}
|
|
110
|
+
return 0
|
|
111
|
+
}
|
|
112
|
+
if (cmp(VERSION, latest) <= 0) die(`版本 ${VERSION} 不比 npm 上的 ${latest} 新 —— 每次发布只能是新版本号`)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 同版本已发过(npm 或 tag)→ 停
|
|
116
|
+
if (tryRun('npm', ['view', `dsh-qqbot-muu@${VERSION}`, 'version', '--silent']).ok) die(`npm 上已经有 ${VERSION} 这个版本了,换个版本号`)
|
|
117
|
+
if (tryRun('git', ['rev-parse', '-q', '--verify', `refs/tags/${TAG}`]).ok) die(`本地已经打过 tag ${TAG},换个版本号`)
|
|
118
|
+
|
|
119
|
+
// 必须有内容:CHANGELOG 里要有这一版
|
|
120
|
+
const cl = existsSync('CHANGELOG.md') ? readFileSync('CHANGELOG.md', 'utf8') : ''
|
|
121
|
+
if (!new RegExp(`^##\\s*` + VERSION.replace(/\./g, '\\.') + `\\b`, 'm').test(cl)) {
|
|
122
|
+
die(`CHANGELOG.md 里没有 ${VERSION} 这一节 —— 每次发布都要写清这次改了什么`)
|
|
123
|
+
}
|
|
124
|
+
if (!CHECK_ONLY) ok('发布闸门:无并发、版本号是新的、CHANGELOG 有内容')
|
|
125
|
+
}
|
|
126
|
+
|
|
74
127
|
if (CHECK_ONLY) {
|
|
75
128
|
console.log('\n✅ 本地检查全绿(--check 模式,未推送)')
|
|
76
129
|
process.exit(0)
|
|
@@ -214,8 +267,25 @@ else {
|
|
|
214
267
|
const AUTH_FLAG = '--//registry.npmjs.org/:' + '_auth' + 'Token=' + nt
|
|
215
268
|
if (!nt) die('没有 npm 令牌', '设置 NPM_TOKEN,或把令牌写进 secrets/npm.txt')
|
|
216
269
|
const r = spawnSync('npm', ['publish', '--access', 'public', '--provenance=false', AUTH_FLAG], { encoding: 'utf8', shell: IS_WIN, stdio: 'pipe' })
|
|
217
|
-
|
|
218
|
-
|
|
270
|
+
// npm 11 起是 staged publishing:PUT 202 只代表进了暂存区,必须 2FA 批准才上线;
|
|
271
|
+
// 以前只看 exit code → 202 也报成功、其实注册表里没有。这里必须回查注册表。
|
|
272
|
+
const live = (() => {
|
|
273
|
+
const v = spawnSync('npm', ['view', `dsh-qqbot-muu@${VERSION}`, 'version'], { encoding: 'utf8', shell: IS_WIN })
|
|
274
|
+
return String(v.stdout || '').trim().includes(VERSION)
|
|
275
|
+
})()
|
|
276
|
+
if (!live) {
|
|
277
|
+
const outTxt = `${r.stdout}\n${r.stderr}`
|
|
278
|
+
const staged = /202|staged|E409|previously staged/i.test(outTxt)
|
|
279
|
+
NPM_PENDING = staged
|
|
280
|
+
? `npm 把 ${VERSION} 收进了暂存区(HTTP 202 / E409),没有 2FA 批准不会上线。去 npm 网站上该包的 Staged/Pending 批准,或换一个允许 2FA bypass 的 granular token。`
|
|
281
|
+
: `npm publish 没成功(exit ${r.status}),注册表里查不到 ${VERSION}。`
|
|
282
|
+
console.log(' ! ' + NPM_PENDING)
|
|
283
|
+
} else {
|
|
284
|
+
ok(`已发布 dsh-qqbot-muu@${VERSION}(注册表已核到)`)
|
|
285
|
+
}
|
|
286
|
+
// 202/staged 路径不会自动挪 latest:显式把 latest 指到本版本,否则用户 npm i 还拿旧版
|
|
287
|
+
const tag = spawnSync('npm', ['dist-tag', 'add', `dsh-qqbot-muu@${VERSION}`, 'latest', AUTH_FLAG], { encoding: 'utf8', shell: IS_WIN })
|
|
288
|
+
if (tag.status === 0) ok(`latest → ${VERSION}`)
|
|
219
289
|
}
|
|
220
290
|
|
|
221
291
|
// ── 7) 市场条目同步(fork 分支 + PR)───────────────────────────────────
|
|
@@ -268,5 +338,11 @@ else {
|
|
|
268
338
|
}
|
|
269
339
|
}
|
|
270
340
|
|
|
271
|
-
|
|
341
|
+
if (NPM_PENDING) {
|
|
342
|
+
console.log(`\n${TAG} 已推 GitHub / Release 已出 / 市场条目已同步。`)
|
|
343
|
+
console.log(`⚠️ npm 还差一步:${NPM_PENDING}`)
|
|
344
|
+
process.exitCode = 2
|
|
345
|
+
} else {
|
|
346
|
+
console.log(`\n✅ ${TAG} 全流程完成:本地 CI 全绿 → 已推送 → Release 已出 → npm 已就绪 → 市场条目已同步`)
|
|
347
|
+
}
|
|
272
348
|
console.log('下一步:到 GitHub Actions 确认这次 push 的 ci 也是绿的(本地跑的是同一套步骤)。')
|