From 2fb519a373e6f0abb8739bcda97b743a0bc129db Mon Sep 17 00:00:00 2001 From: Wxw-Gu <84499436+Wxw-Gu@users.noreply.github.com> Date: Thu, 19 Nov 2026 10:07:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E6=B5=8B=E8=AF=95=E6=96=87=E6=9C=AC=E9=94=99=E8=AF=AF?= =?UTF-8?q?,=20=E6=8F=90=E5=8D=87=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/extensions/group-chat-bot/ui/app.js | 35 +++++++++++-- examples/extensions/template-lock.json | 4 +- package.json | 2 +- scripts/build-macos-edition.cjs | 1 + scripts/prepare-electron-runtime.cjs | 52 +++++++++++++++++++- 5 files changed, 86 insertions(+), 8 deletions(-) diff --git a/examples/extensions/group-chat-bot/ui/app.js b/examples/extensions/group-chat-bot/ui/app.js index 0bfc23d..735e0cd 100644 --- a/examples/extensions/group-chat-bot/ui/app.js +++ b/examples/extensions/group-chat-bot/ui/app.js @@ -1195,6 +1195,7 @@ document.getElementById('memory-clear-btn').addEventListener('click', async () = /* ---------- 预览与测试发送 ---------- */ const testOutput = document.getElementById('test-output') +let previewSnapshot = null function showTestOutput(text) { testOutput.hidden = false @@ -1204,15 +1205,26 @@ function showTestOutput(text) { document.getElementById('preview-reply-btn').addEventListener('click', async () => { collectConfigFromForm() await callHost('storage.set', { key: CONFIG_KEY, value: config }) + const testGroupId = document.getElementById('test-group-select').value + const testMessageText = document.getElementById('test-message-input').value.trim() + const testPersonaId = editingPersonaId + previewSnapshot = { + groupId: testGroupId, + personaId: testPersonaId, + messageText: testMessageText, + replyText: '', + blocked: false + } showTestOutput('正在执行安全检查与 AI 思考预览…') try { const result = await callBackground('previewReply', { - groupId: document.getElementById('test-group-select').value, - personaId: editingPersonaId, + groupId: testGroupId, + personaId: testPersonaId, senderName: document.getElementById('test-sender-name').value.trim() || '测试群友', - messageText: document.getElementById('test-message-input').value.trim() + messageText: testMessageText }) if (result.blocked) { + previewSnapshot.blocked = true showTestOutput( [ `【安全防护拦截】已触发敏感探测/提示词保护(${result.securityLabel || result.securityCategory})`, @@ -1233,6 +1245,7 @@ document.getElementById('preview-reply-btn').addEventListener('click', async () `【本轮随机抽样方式】${modeLabel}(原因:${result.deliveryReason})` ].join('\n') ) + previewSnapshot.replyText = result.replyText || '' setBanner('AI 预览生成完成。', 'ok') } catch (error) { showTestOutput(`预览失败:${error.message}`) @@ -1250,10 +1263,24 @@ async function triggerTestSend(mode) { await callHost('storage.set', { key: CONFIG_KEY, value: config }) showTestOutput(`正在向 ${groupDisplayName(to)} 执行测试发送(模式:${mode})…`) try { + const messageText = document.getElementById('test-message-input').value.trim() + const preview = previewSnapshot + const samePreview = + preview && + !preview.blocked && + preview.groupId === to && + preview.personaId === editingPersonaId && + preview.messageText === messageText + if (preview && preview.blocked && preview.groupId === to) { + throw new Error('当前预览已被安全拦截,未发送') + } const result = await callBackground('testSend', { to, mode, - text: document.getElementById('test-message-input').value.trim() + messageText, + replyText: samePreview ? preview.replyText : '', + personaId: editingPersonaId, + senderName: document.getElementById('test-sender-name').value.trim() || '群友' }) const desc = result.channel === 'voice' diff --git a/examples/extensions/template-lock.json b/examples/extensions/template-lock.json index 0cb513c..e3c3747 100644 --- a/examples/extensions/template-lock.json +++ b/examples/extensions/template-lock.json @@ -14,8 +14,8 @@ "bytes": 33471 }, "group-chat-bot@1.0.0": { - "sha256": "5c2d7409011184b85980a37955347537cd9530860f81b644ec995971d5af6f66", - "bytes": 24751 + "sha256": "122a4da7710cf882975f09440819e9dc1b619e4bd6f94153085a7d6fe8a33885", + "bytes": 24981 }, "keyword-bot@1.0.0": { "sha256": "3d8e5453e7ae6de7e29c16eb3c9e718a98bae27e9ed2edfd10399fb158e1c87d", diff --git a/package.json b/package.json index 4fcdf59..357075e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tracememo", - "version": "2.6.0", + "version": "2.7.0", "packageManager": "pnpm@7.33.7", "description": "TraceMemo(迹忆)是一款本地优先、可追溯的 AI 微信知识与分析工作台。 原名 WechatExplorer,支持聊天记录搜索、知识库、微信群聊总结和 Agent 助手。", "keywords": [ diff --git a/scripts/build-macos-edition.cjs b/scripts/build-macos-edition.cjs index 3a26bfe..62d5af8 100644 --- a/scripts/build-macos-edition.cjs +++ b/scripts/build-macos-edition.cjs @@ -60,6 +60,7 @@ function createBuilderConfig({ edition, stageRoot, buildOutput, outputRoot, appV ], extraResources: [ { from: path.join(stageRoot, 'resources'), to: 'resources', filter: ['**/*'] }, + { from: path.join(ROOT, 'build/extension-templates'), to: 'extension-templates', filter: ['**/*'] }, { from: path.join(ROOT, 'build/app-update.yml'), to: 'app-update.yml' }, { from: path.join(ROOT, 'docs/skill/tracememo-reader'), diff --git a/scripts/prepare-electron-runtime.cjs b/scripts/prepare-electron-runtime.cjs index 5670adf..d2faf15 100644 --- a/scripts/prepare-electron-runtime.cjs +++ b/scripts/prepare-electron-runtime.cjs @@ -83,7 +83,57 @@ function prepareFfmpegRuntime(targetPlatform = process.platform, targetArch = pr fs.chmodSync(ffmpegPath, 0o755) if (process.platform === 'darwin') { - execFileSync('/usr/bin/codesign', ['--force', '--sign', '-', ffmpegPath], { stdio: 'ignore' }) + assertMachOIntact(ffmpegPath) + try { + execFileSync('/usr/bin/codesign', ['--force', '--sign', '-', ffmpegPath], { + stdio: ['ignore', 'pipe', 'pipe'] + }) + } catch (error) { + const detail = error?.stderr?.toString?.().trim() || error.message + throw new Error( + 'codesign 失败:' + + detail + + '\n最常见原因:ffmpeg-static 下载被截断,文件不完整。' + + '\n处理:删除 ' + + ffmpegPath + + ' 后重跑本命令;网络不稳时先用 curl -C - 把 .gz 补齐再解压。' + ) + } + } +} + +/** + * 截断的 Mach-O 能被 file 认出来,却签不了名,也跑不起来。 + * otool 解析 load command,截断会直接失败——比事后读 codesign 的天书便宜。 + */ +function assertMachOIntact(ffmpegPath) { + let listing = '' + try { + listing = execFileSync('/usr/bin/otool', ['-l', ffmpegPath], { + encoding: 'utf8', + maxBuffer: 16 * 1024 * 1024 + }) + } catch { + throw new Error( + 'ffmpeg 二进制无法解析(下载不完整):' + ffmpegPath + '\n处理:删除该文件后重跑本命令。' + ) + } + // otool 对超出文件末尾的段会标 "(past end of file)":下载被截断的确凿信号。 + if (listing.includes('past end of file')) { + throw new Error( + 'ffmpeg 二进制被截断(下载不完整):' + + ffmpegPath + + '\n处理:删除该文件后重跑本命令;网络不稳时先用 curl -C - 把 .gz 补齐再解压。' + ) + } + let kind = '' + try { + kind = execFileSync('/usr/bin/file', ['-b', ffmpegPath], { encoding: 'utf8' }) + } catch { + kind = '' + } + if (!kind.includes('Mach-O')) { + throw new Error('ffmpeg 不是 Mach-O 可执行文件:' + ffmpegPath) } }