Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(im): 卡片渠道也自动发出回复里的本机图片
Dashfba9d3744e14
diff --git a/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts b/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.tsindex cb45dbad4e..9379741cdb 100644--- a/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/localMarkdownImages.test.ts@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';import os from 'node:os';import path from 'node:path';import { afterEach, describe, expect, it, vi } from 'vitest';-import { materializeLocalMarkdownImages } from '../localMarkdownImages';+import { materializeLocalMarkdownImageRefs, materializeLocalMarkdownImages } from '../localMarkdownImages';const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);const tempRoots: string[] = [];@@ -132,3 +132,17 @@ describe('materializeLocalMarkdownImages', () => {expect(deps.stat).not.toHaveBeenCalled();});});++describe('materializeLocalMarkdownImageRefs', () => {+ it('keeps imported images in place for card channels and captions the rest', async () => {+ // Feishu / Telegram / Discord cards previously dropped local image paths entirely.+ const materialize = vi.fn(async () => '前文\n\n\n后文');+ expect(+ await materializeLocalMarkdownImageRefs(+ { text: '前文\n\n\n后文', sessionId: 's' },+ { materialize },+ ),+ ).toBe('前文\n\n失败\n后文\n\n有 1 张图片未能作为附件发送。');+ expect(materialize).toHaveBeenCalledWith('s', '前文\n\n\n后文');+ });+});diff --git a/apps/desktop/src/main/im/shared/localMarkdownImages.ts b/apps/desktop/src/main/im/shared/localMarkdownImages.tsindex e66a5b9395..e6d1675eda 100644--- a/apps/desktop/src/main/im/shared/localMarkdownImages.ts+++ b/apps/desktop/src/main/im/shared/localMarkdownImages.ts@@ -132,3 +132,22 @@ export async function materializeLocalMarkdownImages(const notice = failedUrls.size > 0 ? `有 ${failedUrls.size} 张图片未能作为附件发送。` : '';return { absPaths, text: notice ? `${body.trimEnd()}\n\n${notice}` : body };}++/**+ * Card channels (Feishu, Telegram, Discord) upload managed image references in+ * place. Rewrite local image paths to managed references through the same Host+ * importer; an unavailable image keeps only its caption plus a delivery notice.+ */+export async function materializeLocalMarkdownImageRefs(+ params: { text: string; sessionId: string },+ deps: Pick<LocalMarkdownImageDeps, 'materialize'> = defaultDeps,+): Promise<string> {+ const sourceText = await deps.materialize(params.sessionId, params.text);+ const failed = new Map<string, string>();+ for (const ref of taskImageReferences(sourceText)) {+ if (localTaskImagePath(ref.url)) failed.set(ref.url, ref.url);+ }+ if (failed.size === 0) return sourceText;+ const body = rewriteTaskImageReferences(sourceText, failed, 'alt');+ return `${body.trimEnd()}\n\n有 ${failed.size} 张图片未能作为附件发送。`;+}diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.tsindex f878cc1801..6e4412e537 100644--- a/apps/desktop/src/main/im/shared/turnRunner.ts+++ b/apps/desktop/src/main/im/shared/turnRunner.ts@@ -161,7 +161,7 @@ import {generateImSessionTitleText,persistGeneratedSessionTitle,} from './fbotTitle';-import { materializeLocalMarkdownImages } from './localMarkdownImages';+import { materializeLocalMarkdownImageRefs, materializeLocalMarkdownImages } from './localMarkdownImages';import {applyStatusTokenRate,clearRunningIndicators,@@ -3215,6 +3215,9 @@ export function createTurnRunner(for (const absPath of materialized.absPaths) {if (!t.mediaAbsPaths.includes(absPath)) t.mediaAbsPaths.push(absPath);}+ } else if (output.kind === 'rich-card' && !state.makerSession.remoteHostId && projectedBody.includes('![')) {+ t.buffer = await materializeLocalMarkdownImageRefs({ text: projectedBody, sessionId: state.makerSession.id })+ .catch(() => projectedBody);}if (sessionStates.get(state.makerSession.id) !== state) return;const base = composeTranspondView(state, t, true);@@ -3913,15 +3916,17 @@ export function createTurnRunner(}async function materializeTurnLocalImages(state: SessionState, turn: TurnState): Promise<void> {- if (- output.kind !== 'chunked-text' ||- turn.allowedFileRoots.length === 0- ) {- return;- }+ if (turn.allowedFileRoots.length === 0) return;const projectedBody = composeOutboundBody(turn.presenter.wholeText(), true);if (!projectedBody.includes('![')) return;try {+ if (output.kind === 'rich-card') {+ // Card channels upload managed references in place, keeping images beside their text.+ turn.presenter.replaceBody(+ await materializeLocalMarkdownImageRefs({ text: projectedBody, sessionId: state.makerSession.id }),+ );+ return;+ }const materialized = await materializeLocalMarkdownImages({text: projectedBody,workingDir: state.workingDir,diff --git a/docs/dev-rules/media-storage-and-protocols.md b/docs/dev-rules/media-storage-and-protocols.mdindex dfe5303081..b57368433a 100644--- a/docs/dev-rules/media-storage-and-protocols.md+++ b/docs/dev-rules/media-storage-and-protocols.md@@ -314,6 +314,8 @@未送达提示按界面语言点名未发出的附件。渠道出站与桌面聊天展示一致,接受本机任意路径的普通图片,不限于工作目录与 scratchpad(2026-10-27 裁决:渠道发图与导入后再发本质相同,不为此多走一步);网络/设备路径、非普通文件、超限与非图片仍拒绝,SVG 需 Agent 先转 PNG。+ 当前会话所在渠道一律用回复里的图片引用发图:文本渠道收集为附件,飞书、Telegram、Discord+ 卡片先改写为受管引用再原位上传;渠道发送工具只用于跨会话推送,不引导 Agent 在当前会话用它发图。SSH 官方渠道不导入或读取控制端文件,仍复用出站引用清理:本地图片地址(含远端Windows 路径)只保留说明,并提示附件发送不完整,不将不可用的媒体地址发到 IM。与图片共用目标的普通链接也指向保存后的同一图片;外发时这些本地链接降为显示文字,diff --git a/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts b/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.tsindex 4c2b4fc400..70a2be3e4c 100644--- a/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts+++ b/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts@@ -89,7 +89,7 @@ describe('cindy_feishu_bot channel routing note', () => {'正文可以使用标题、列表、表格、普通段落或代码块组织内容,发布时会转换为纯文本;附件引用不受此限制',);expect(X_HOOK_SESSION_CHANNEL_NOTE).toContain('xdt-file:///绝对路径');- expect(X_HOOK_SESSION_CHANNEL_NOTE).toContain('cindy-media://… 或 xdt-image://…');+ expect(X_HOOK_SESSION_CHANNEL_NOTE).toContain('本机图片绝对路径或 cindy-media://…');expect(X_HOOK_SESSION_CHANNEL_NOTE).toContain('不要解释或复述这些格式要求');expect(X_HOOK_SESSION_CHANNEL_NOTE).not.toContain('X (Twitter)');expect(X_HOOK_SESSION_CHANNEL_NOTE).not.toContain('公开回帖');diff --git a/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts b/packages/lizi-mcps/src/cindy_feishuBotMcpServer.tsindex 419c32bba8..ea07435ed0 100644--- a/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts+++ b/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts@@ -49,16 +49,16 @@ type FeishuBotToolDescriptions = { [K in keyof typeof D]: string };* (organic SlackIM 渠道及其 lizi_slack_bot 已于 2026-07-17 随老 relay 退役。)*/export const SLACK_HOOK_SESSION_CHANNEL_NOTE =- '\n\n⚠️ 当前是 Slack 会话:文字回复直接输出即可(会自动回贴到当前 Slack thread,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为 Slack 附件发回,不要用本工具;仅当用户明确说「发飞书或 Lark / 通过飞书或 Lark 通知我」时才走该 IM 通道。';+ '\n\n⚠️ 当前是 Slack 会话:文字回复直接输出即可(会自动回贴到当前 Slack thread,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为 Slack 附件发回,不要用本工具;仅当用户明确说「发飞书或 Lark / 通过飞书或 Lark 通知我」时才走该 IM 通道。';export const TELEGRAM_HOOK_SESSION_CHANNEL_NOTE =- '\n\n⚠️ 当前是 Telegram 会话:文字回复直接输出即可(会自动回贴到当前 Telegram 对话或回复链,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为 Telegram 附件发回,不要用本工具;仅当用户明确说「发飞书或 Lark / 通过飞书或 Lark 通知我」时才走该 IM 通道。';+ '\n\n⚠️ 当前是 Telegram 会话:文字回复直接输出即可(会自动回贴到当前 Telegram 对话或回复链,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为 Telegram 附件发回,不要用本工具;仅当用户明确说「发飞书或 Lark / 通过飞书或 Lark 通知我」时才走该 IM 通道。';export const X_HOOK_SESSION_CHANNEL_NOTE =- '\n\n⚠️ 当前是 X 会话:当前账号为付费账号,不受 280 个字符限制,无需针对当前渠道调整回答篇幅;文字回复直接输出即可(系统会自动发回当前 X 会话,无需工具);正文可以使用标题、列表、表格、普通段落或代码块组织内容,发布时会转换为纯文本;附件引用不受此限制。在 X 中除附件引用外,尽量避免输出其他 URL 链接,也不要解释或复述这些格式要求;把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``;仅当用户明确说「发飞书 / 飞书通知我」时才走飞书通道。';+ '\n\n⚠️ 当前是 X 会话:当前账号为付费账号,不受 280 个字符限制,无需针对当前渠道调整回答篇幅;文字回复直接输出即可(系统会自动发回当前 X 会话,无需工具);正文可以使用标题、列表、表格、普通段落或代码块组织内容,发布时会转换为纯文本;附件引用不受此限制。在 X 中除附件引用外,尽量避免输出其他 URL 链接,也不要解释或复述这些格式要求;把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``;仅当用户明确说「发飞书 / 飞书通知我」时才走飞书通道。';export const WECOM_SESSION_CHANNEL_NOTE =- '\n\n⚠️ 当前是企业微信会话:文字回复直接输出即可(会自动回复到当前企业微信会话,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为企业微信附件发回,不要用本工具;仅当用户明确说「发飞书 / 飞书通知我」时才走飞书通道。';+ '\n\n⚠️ 当前是企业微信会话:文字回复直接输出即可(会自动回复到当前企业微信会话,无需工具);把文件发给用户是在最终回复文本里写 `[文件名](xdt-file:///绝对路径)`(文件须位于当前工作目录内),图片直接引用其地址 ``,系统自动作为企业微信附件发回,不要用本工具;仅当用户明确说「发飞书 / 飞书通知我」时才走飞书通道。';const NOTE_BY_SOURCE: Record<string, string> = {'slack-hook': SLACK_HOOK_SESSION_CHANNEL_NOTE,diff --git a/packages/lizi-mcps/src/prompts/cindy_feishu_bot/tools/send_file_to_user.md b/packages/lizi-mcps/src/prompts/cindy_feishu_bot/tools/send_file_to_user.mdindex e29051527d..c778266dbc 100644--- a/packages/lizi-mcps/src/prompts/cindy_feishu_bot/tools/send_file_to_user.md+++ b/packages/lizi-mcps/src/prompts/cindy_feishu_bot/tools/send_file_to_user.md@@ -5,7 +5,7 @@用途:- **跨 session 文件推送**:用户在桌面端说"把这份文档 / 这张图发飞书或 Lark 给我" —— 用这个,文件立刻出现在对应 IM 的 DM。-- **IM session 内直接发送**:用户让你"出张图发我看看"、"把日志文件传过来" —— 任何需要把磁盘上的文件本体送到用户手机/PC 客户端的场景。+- **当前就是飞书 / Lark 会话时不要用这个工具发图**:图片直接写在回复里 ``,回复结束后自动随卡片发出,Cindy 聊天里也能看到。需要把其它文件本体送到用户客户端时仍可用这个工具。- **不要**用这个工具发卡片正文里的内联说明,正文用流式输出就好;这个工具是发独立的 file/image 消息(用户会看到"📎 文件名"或图片预览,可以直接下载/转发)。- 用户没明确说"发飞书 / Lark 给我"或类似意图时,不要自作主张主动推送文件。