Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(hook-control): 渠道说明声明为系统提示,避免被模型当成用户消息 (#888)
cml233874e044d5a0c23c
diff --git a/apps/desktop/src/main/hook-control/__tests__/outbound.test.ts b/apps/desktop/src/main/hook-control/__tests__/outbound.test.tsindex a715dc8e6b..f5436e8a40 100644--- a/apps/desktop/src/main/hook-control/__tests__/outbound.test.ts+++ b/apps/desktop/src/main/hook-control/__tests__/outbound.test.ts@@ -32,6 +32,16 @@ describe('buildHookPromptNote', () => {expect(telegram).not.toContain('静默丢弃');expect(buildHookPromptNote('slack')).not.toContain('[Telegram 回复格式]');});++ it('两个平台都在开头声明「不是用户消息」,防止模型把渠道说明当成用户请求(2026-07 实踩)', () => {+ for (const im of ['telegram', 'slack'] as const) {+ const note = buildHookPromptNote(im);+ // guard 必须在附件正文之前出现,才能在模型读到附件指令前先定性。+ expect(note).toContain('不是用户发来的消息');+ expect(note).toContain('不要把它当作用户的请求');+ expect(note.indexOf('不是用户发来的消息')).toBeLessThan(note.indexOf('要把文件发给用户'));+ }+ });});function deps(diff --git a/apps/desktop/src/main/hook-control/outbound.ts b/apps/desktop/src/main/hook-control/outbound.tsindex 841689ff7e..4cbe30e8e3 100644--- a/apps/desktop/src/main/hook-control/outbound.ts+++ b/apps/desktop/src/main/hook-control/outbound.ts@@ -40,11 +40,20 @@ const MAX_OUT_TOTAL_BYTES = 30 * 1024 * 1024;* 发给我」路由到 cindy_feishu_bot(hook 会话里唯一可见的推送工具)并失败。* 固定文本、逐 turn 追加,保证行为确定(规则 9);修改措辞时同步* collectOutboundAttachments 的实际语义,别让说明和收集器漂移。+ *+ * 关键约束:这段说明由 session-runner 用 `${prompt}\n\n${note}` 拼在用户原话+ * 之后,和用户内容同处一个 user turn —— 模型无法从消息角色上区分二者。实踩+ * (2026-07)里,用户只发了极短内容(群里 @机器人 带一句话)时,模型把这段+ * 附件说明误当成"用户要我检查附件",回了"你的消息里说'请检查这些附件',但我+ * 没收到"。因此开头必须显式声明「这是系统规范、不是用户消息」,禁止当作用户+ * 请求或加以引用/臆测。删改这句 guard 会让该误读复发。*/export function buildHookPromptNote(im: string | undefined): string {const platform = im === 'telegram' ? 'Telegram' : 'Slack';const attachmentNote =- `[渠道说明] 本会话来自 ${platform}。要把文件发给用户:在最终回复文本里写 ` ++ '[渠道说明] 以下为系统每轮自动追加的投递与格式规范,不是用户发来的消息;' ++ '回复时不要把它当作用户的请求,也不要引用、复述或据此臆测用户意图。' ++ `本会话来自 ${platform}。要把文件发给用户:在最终回复文本里写 ` +'`[文件名](xdt-file:///绝对路径)`;图片直接引用其地址 ' +'``,无需复制文件。' +`系统会在回复结束后自动把它们作为 ${platform} 附件发回,无需调用任何工具;` +