@tencent-connect/openclaw-qqbot 1.6.5-alpha.5 → 1.6.5-alpha.6
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.
|
@@ -251,7 +251,7 @@ registerCommand({
|
|
|
251
251
|
return lines.join("\n");
|
|
252
252
|
},
|
|
253
253
|
});
|
|
254
|
-
const DEFAULT_UPGRADE_URL = "https://
|
|
254
|
+
const DEFAULT_UPGRADE_URL = "https://docs.qq.com/doc/DSGxOZk1oVnVKVkpq";
|
|
255
255
|
function saveUpgradeGreetingTarget(accountId, appId, openid) {
|
|
256
256
|
const safeAccountId = accountId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
257
257
|
const safeAppId = appId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
@@ -561,6 +561,38 @@ function findPowerShell() {
|
|
|
561
561
|
}
|
|
562
562
|
return null;
|
|
563
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* 将升级脚本复制到临时位置,避免升级过程中插件目录被清理后脚本丢失。
|
|
566
|
+
* 返回临时脚本路径,失败返回 null。
|
|
567
|
+
*/
|
|
568
|
+
function copyScriptToTemp(scriptPath) {
|
|
569
|
+
try {
|
|
570
|
+
const ext = path.extname(scriptPath);
|
|
571
|
+
const tmpDir = path.join(getHomeDir(), ".openclaw", ".qqbot-upgrade-tmp");
|
|
572
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
573
|
+
const tmpScript = path.join(tmpDir, `upgrade-via-npm${ext}`);
|
|
574
|
+
fs.copyFileSync(scriptPath, tmpScript);
|
|
575
|
+
if (!isWindows()) {
|
|
576
|
+
fs.chmodSync(tmpScript, 0o755);
|
|
577
|
+
}
|
|
578
|
+
return tmpScript;
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* 清理临时升级脚本目录
|
|
586
|
+
*/
|
|
587
|
+
function cleanupTempScript() {
|
|
588
|
+
try {
|
|
589
|
+
const tmpDir = path.join(getHomeDir(), ".openclaw", ".qqbot-upgrade-tmp");
|
|
590
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
// 非关键,静默忽略
|
|
594
|
+
}
|
|
595
|
+
}
|
|
564
596
|
/**
|
|
565
597
|
* 执行热更新:执行脚本(--no-restart) → 立即触发 gateway restart
|
|
566
598
|
*
|
|
@@ -570,11 +602,15 @@ function findPowerShell() {
|
|
|
570
602
|
* - 新进程启动时 getStartupGreeting() 检测到版本变更,自动通知管理员
|
|
571
603
|
*
|
|
572
604
|
* Windows 使用 PowerShell 执行 .ps1 脚本,Mac/Linux 使用 bash 执行 .sh 脚本。
|
|
605
|
+
*
|
|
606
|
+
* 安全机制:脚本会被复制到临时目录再执行,避免升级过程中插件目录被操作导致脚本自身丢失。
|
|
573
607
|
*/
|
|
574
608
|
function fireHotUpgrade(targetVersion) {
|
|
575
|
-
const
|
|
576
|
-
if (!
|
|
609
|
+
const originalScriptPath = getUpgradeScriptPath();
|
|
610
|
+
if (!originalScriptPath)
|
|
577
611
|
return { ok: false, reason: "no-script" };
|
|
612
|
+
// 将脚本复制到临时位置,避免升级过程中脚本被删除
|
|
613
|
+
const scriptPath = copyScriptToTemp(originalScriptPath) || originalScriptPath;
|
|
578
614
|
const cli = findCli();
|
|
579
615
|
if (!cli)
|
|
580
616
|
return { ok: false, reason: "no-cli" };
|
|
@@ -601,7 +637,7 @@ function fireHotUpgrade(targetVersion) {
|
|
|
601
637
|
shell = bash;
|
|
602
638
|
shellArgs = [scriptPath, "--no-restart", ...(targetVersion ? ["--version", targetVersion] : [])];
|
|
603
639
|
}
|
|
604
|
-
console.log(`[qqbot] fireHotUpgrade: shell=${shell}, script=${scriptPath}, cli=${cli}, target=${targetVersion || "latest"}`);
|
|
640
|
+
console.log(`[qqbot] fireHotUpgrade: shell=${shell}, script=${scriptPath} (original: ${originalScriptPath}), cli=${cli}, target=${targetVersion || "latest"}`);
|
|
605
641
|
// 异步执行升级脚本
|
|
606
642
|
execFile(shell, shellArgs, {
|
|
607
643
|
timeout: 120_000,
|
|
@@ -614,6 +650,7 @@ function fireHotUpgrade(targetVersion) {
|
|
|
614
650
|
console.error(`[qqbot] fireHotUpgrade: stdout: ${stdout.slice(0, 2000)}`);
|
|
615
651
|
if (_stderr)
|
|
616
652
|
console.error(`[qqbot] fireHotUpgrade: stderr: ${_stderr.slice(0, 2000)}`);
|
|
653
|
+
cleanupTempScript();
|
|
617
654
|
_upgrading = false;
|
|
618
655
|
return;
|
|
619
656
|
}
|
|
@@ -623,10 +660,13 @@ function fireHotUpgrade(targetVersion) {
|
|
|
623
660
|
const newVersion = versionMatch?.[1];
|
|
624
661
|
if (newVersion === "unknown") {
|
|
625
662
|
console.error(`[qqbot] fireHotUpgrade: script output QQBOT_NEW_VERSION=unknown, aborting restart`);
|
|
663
|
+
cleanupTempScript();
|
|
626
664
|
_upgrading = false;
|
|
627
665
|
return;
|
|
628
666
|
}
|
|
629
667
|
console.log(`[qqbot] fireHotUpgrade: new version=${newVersion || "(not detected)"}, triggering restart...`);
|
|
668
|
+
// 脚本执行成功,清理临时脚本副本
|
|
669
|
+
cleanupTempScript();
|
|
630
670
|
// 文件替换成功,在 restart 之前把 source 从 path 切换为 npm,
|
|
631
671
|
// 确保新进程启动时读到的是 npm source,不会被本地源码覆盖。
|
|
632
672
|
switchPluginSourceToNpm();
|
package/package.json
CHANGED
|
@@ -230,20 +230,40 @@ if [ "$USE_UPDATE" = "true" ]; then
|
|
|
230
230
|
fi
|
|
231
231
|
|
|
232
232
|
if [ "$UPGRADE_OK" != "true" ]; then
|
|
233
|
-
#
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
# 备份旧目录(而非直接删除),install 失败时可回滚
|
|
234
|
+
BACKUP_DIR=""
|
|
235
|
+
if [ -d "$EXTENSIONS_DIR/$PLUGIN_ID" ]; then
|
|
236
|
+
BACKUP_DIR="$EXTENSIONS_DIR/.openclaw-qqbot-backup-$$"
|
|
237
|
+
mv "$EXTENSIONS_DIR/$PLUGIN_ID" "$BACKUP_DIR"
|
|
238
|
+
echo " 已备份旧目录: $BACKUP_DIR"
|
|
239
|
+
fi
|
|
240
|
+
|
|
241
|
+
# 清理历史遗留名称(这些不需要回滚)
|
|
242
|
+
for dir_name in qqbot openclaw-qq; do
|
|
243
|
+
[ -d "$EXTENSIONS_DIR/$dir_name" ] && rm -rf "$EXTENSIONS_DIR/$dir_name" && echo " 已清理历史目录: $EXTENSIONS_DIR/$dir_name"
|
|
236
244
|
done
|
|
237
245
|
|
|
238
246
|
echo " 执行 install: $INSTALL_SRC"
|
|
239
247
|
if $CMD plugins install "$INSTALL_SRC" --pin 2>&1; then
|
|
240
248
|
UPGRADE_OK=true
|
|
241
249
|
echo " ✅ install 成功"
|
|
250
|
+
# install 成功,清理备份
|
|
251
|
+
if [ -n "$BACKUP_DIR" ] && [ -d "$BACKUP_DIR" ]; then
|
|
252
|
+
rm -rf "$BACKUP_DIR"
|
|
253
|
+
echo " 已清理旧版备份"
|
|
254
|
+
fi
|
|
255
|
+
# 清理 openclaw CLI install 可能留下的额外 backup 目录
|
|
256
|
+
find "$EXTENSIONS_DIR" -maxdepth 1 -name ".openclaw-qqbot-backup-*" -exec rm -rf {} + 2>/dev/null || true
|
|
242
257
|
else
|
|
243
|
-
echo "❌ install 失败"
|
|
258
|
+
echo " ❌ install 失败"
|
|
259
|
+
# 回滚:恢复旧目录
|
|
260
|
+
if [ -n "$BACKUP_DIR" ] && [ -d "$BACKUP_DIR" ]; then
|
|
261
|
+
mv "$BACKUP_DIR" "$EXTENSIONS_DIR/$PLUGIN_ID"
|
|
262
|
+
echo " ↩️ 已回滚到旧版本"
|
|
263
|
+
fi
|
|
244
264
|
restore_qqbot_channel
|
|
245
265
|
echo "QQBOT_NEW_VERSION=unknown"
|
|
246
|
-
echo "QQBOT_REPORT=❌ QQBot
|
|
266
|
+
echo "QQBOT_REPORT=❌ QQBot 安装失败(已回滚到旧版本),请检查网络和 npm registry"
|
|
247
267
|
exit 1
|
|
248
268
|
fi
|
|
249
269
|
fi
|
|
@@ -336,6 +356,19 @@ if [ "$PREFLIGHT_OK" != "true" ]; then
|
|
|
336
356
|
fi
|
|
337
357
|
echo " ✅ 验证全部通过"
|
|
338
358
|
|
|
359
|
+
# 确保 openclaw/plugin-sdk 可解析:
|
|
360
|
+
# openclaw plugins install 不会执行 npm lifecycle scripts,
|
|
361
|
+
# 需要手动调用 postinstall-link-sdk.js 创建 node_modules/openclaw → 全局 openclaw 的符号链接
|
|
362
|
+
POSTINSTALL_SCRIPT="$TARGET_DIR/scripts/postinstall-link-sdk.js"
|
|
363
|
+
if [ -f "$POSTINSTALL_SCRIPT" ]; then
|
|
364
|
+
echo " 执行 postinstall-link-sdk..."
|
|
365
|
+
if node "$POSTINSTALL_SCRIPT" 2>&1; then
|
|
366
|
+
echo " ✅ plugin-sdk 链接就绪"
|
|
367
|
+
else
|
|
368
|
+
echo " ⚠️ postinstall-link-sdk 失败,插件可能无法加载"
|
|
369
|
+
fi
|
|
370
|
+
fi
|
|
371
|
+
|
|
339
372
|
# [3/4] 输出结构化信息(供 TS handler 解析)
|
|
340
373
|
echo ""
|
|
341
374
|
echo "[3/4] 升级结果..."
|
|
@@ -444,6 +444,27 @@ else
|
|
|
444
444
|
# gateway 已在安装前 stop,此时不会有自动 restart 的问题
|
|
445
445
|
# 所有配置写入完成后,在 Step 6 统一启动
|
|
446
446
|
|
|
447
|
+
# 确保 openclaw/plugin-sdk 可解析:
|
|
448
|
+
# openclaw plugins install 不会执行 npm lifecycle scripts,
|
|
449
|
+
# 需要手动调用 postinstall-link-sdk.js 创建 node_modules/openclaw → 全局 openclaw 的符号链接。
|
|
450
|
+
# 必须在 peerDeps 清理之后执行,否则 symlink 会被清理逻辑删除。
|
|
451
|
+
for _candidate_name in openclaw-qqbot qqbot openclaw-qq; do
|
|
452
|
+
_postinstall="$HOME/.openclaw/extensions/$_candidate_name/scripts/postinstall-link-sdk.js"
|
|
453
|
+
if [ -f "$_postinstall" ]; then
|
|
454
|
+
echo " 执行 postinstall-link-sdk..."
|
|
455
|
+
if node "$_postinstall" 2>&1; then
|
|
456
|
+
echo " ✅ plugin-sdk 链接就绪"
|
|
457
|
+
else
|
|
458
|
+
echo " ⚠️ postinstall-link-sdk 失败,插件可能无法加载"
|
|
459
|
+
fi
|
|
460
|
+
break
|
|
461
|
+
fi
|
|
462
|
+
done
|
|
463
|
+
|
|
464
|
+
# 清理 openclaw CLI install 留下的 backup 目录,
|
|
465
|
+
# 避免 gateway 发现两个同 id 插件不断刷 duplicate plugin id 警告
|
|
466
|
+
find "$HOME/.openclaw/extensions/" -maxdepth 1 -name ".openclaw-qqbot-backup-*" -exec rm -rf {} + 2>/dev/null || true
|
|
467
|
+
|
|
447
468
|
# 记录更新后的 qqbot 插件版本
|
|
448
469
|
NEW_QQBOT_VERSION=$(node -e '
|
|
449
470
|
try {
|
package/src/slash-commands.ts
CHANGED
|
@@ -337,7 +337,7 @@ registerCommand({
|
|
|
337
337
|
},
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
-
const DEFAULT_UPGRADE_URL = "https://
|
|
340
|
+
const DEFAULT_UPGRADE_URL = "https://docs.qq.com/doc/DSGxOZk1oVnVKVkpq";
|
|
341
341
|
|
|
342
342
|
function saveUpgradeGreetingTarget(accountId: string, appId: string, openid: string): void {
|
|
343
343
|
const safeAccountId = accountId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
@@ -660,6 +660,38 @@ function findPowerShell(): string | null {
|
|
|
660
660
|
return null;
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
+
/**
|
|
664
|
+
* 将升级脚本复制到临时位置,避免升级过程中插件目录被清理后脚本丢失。
|
|
665
|
+
* 返回临时脚本路径,失败返回 null。
|
|
666
|
+
*/
|
|
667
|
+
function copyScriptToTemp(scriptPath: string): string | null {
|
|
668
|
+
try {
|
|
669
|
+
const ext = path.extname(scriptPath);
|
|
670
|
+
const tmpDir = path.join(getHomeDir(), ".openclaw", ".qqbot-upgrade-tmp");
|
|
671
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
672
|
+
const tmpScript = path.join(tmpDir, `upgrade-via-npm${ext}`);
|
|
673
|
+
fs.copyFileSync(scriptPath, tmpScript);
|
|
674
|
+
if (!isWindows()) {
|
|
675
|
+
fs.chmodSync(tmpScript, 0o755);
|
|
676
|
+
}
|
|
677
|
+
return tmpScript;
|
|
678
|
+
} catch {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* 清理临时升级脚本目录
|
|
685
|
+
*/
|
|
686
|
+
function cleanupTempScript(): void {
|
|
687
|
+
try {
|
|
688
|
+
const tmpDir = path.join(getHomeDir(), ".openclaw", ".qqbot-upgrade-tmp");
|
|
689
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
690
|
+
} catch {
|
|
691
|
+
// 非关键,静默忽略
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
663
695
|
/**
|
|
664
696
|
* 执行热更新:执行脚本(--no-restart) → 立即触发 gateway restart
|
|
665
697
|
*
|
|
@@ -669,10 +701,15 @@ function findPowerShell(): string | null {
|
|
|
669
701
|
* - 新进程启动时 getStartupGreeting() 检测到版本变更,自动通知管理员
|
|
670
702
|
*
|
|
671
703
|
* Windows 使用 PowerShell 执行 .ps1 脚本,Mac/Linux 使用 bash 执行 .sh 脚本。
|
|
704
|
+
*
|
|
705
|
+
* 安全机制:脚本会被复制到临时目录再执行,避免升级过程中插件目录被操作导致脚本自身丢失。
|
|
672
706
|
*/
|
|
673
707
|
function fireHotUpgrade(targetVersion?: string): HotUpgradeStartResult {
|
|
674
|
-
const
|
|
675
|
-
if (!
|
|
708
|
+
const originalScriptPath = getUpgradeScriptPath();
|
|
709
|
+
if (!originalScriptPath) return { ok: false, reason: "no-script" };
|
|
710
|
+
|
|
711
|
+
// 将脚本复制到临时位置,避免升级过程中脚本被删除
|
|
712
|
+
const scriptPath = copyScriptToTemp(originalScriptPath) || originalScriptPath;
|
|
676
713
|
|
|
677
714
|
const cli = findCli();
|
|
678
715
|
if (!cli) return { ok: false, reason: "no-cli" };
|
|
@@ -699,7 +736,7 @@ function fireHotUpgrade(targetVersion?: string): HotUpgradeStartResult {
|
|
|
699
736
|
shellArgs = [scriptPath, "--no-restart", ...(targetVersion ? ["--version", targetVersion] : [])];
|
|
700
737
|
}
|
|
701
738
|
|
|
702
|
-
console.log(`[qqbot] fireHotUpgrade: shell=${shell}, script=${scriptPath}, cli=${cli}, target=${targetVersion || "latest"}`);
|
|
739
|
+
console.log(`[qqbot] fireHotUpgrade: shell=${shell}, script=${scriptPath} (original: ${originalScriptPath}), cli=${cli}, target=${targetVersion || "latest"}`);
|
|
703
740
|
|
|
704
741
|
// 异步执行升级脚本
|
|
705
742
|
execFile(shell, shellArgs, {
|
|
@@ -711,6 +748,7 @@ function fireHotUpgrade(targetVersion?: string): HotUpgradeStartResult {
|
|
|
711
748
|
console.error(`[qqbot] fireHotUpgrade: script failed: ${error.message}`);
|
|
712
749
|
if (stdout) console.error(`[qqbot] fireHotUpgrade: stdout: ${stdout.slice(0, 2000)}`);
|
|
713
750
|
if (_stderr) console.error(`[qqbot] fireHotUpgrade: stderr: ${_stderr.slice(0, 2000)}`);
|
|
751
|
+
cleanupTempScript();
|
|
714
752
|
_upgrading = false;
|
|
715
753
|
return;
|
|
716
754
|
}
|
|
@@ -722,12 +760,16 @@ function fireHotUpgrade(targetVersion?: string): HotUpgradeStartResult {
|
|
|
722
760
|
const newVersion = versionMatch?.[1];
|
|
723
761
|
if (newVersion === "unknown") {
|
|
724
762
|
console.error(`[qqbot] fireHotUpgrade: script output QQBOT_NEW_VERSION=unknown, aborting restart`);
|
|
763
|
+
cleanupTempScript();
|
|
725
764
|
_upgrading = false;
|
|
726
765
|
return;
|
|
727
766
|
}
|
|
728
767
|
|
|
729
768
|
console.log(`[qqbot] fireHotUpgrade: new version=${newVersion || "(not detected)"}, triggering restart...`);
|
|
730
769
|
|
|
770
|
+
// 脚本执行成功,清理临时脚本副本
|
|
771
|
+
cleanupTempScript();
|
|
772
|
+
|
|
731
773
|
// 文件替换成功,在 restart 之前把 source 从 path 切换为 npm,
|
|
732
774
|
// 确保新进程启动时读到的是 npm source,不会被本地源码覆盖。
|
|
733
775
|
switchPluginSourceToNpm();
|