!n12pi9PdvbrK-XNEQgV4nsImj0DWQylQSemc5NNrtVU(临时房间,可保留查阅)# 容器任务:修 strip_media + 每个文件独立发附件(2026-11-13 晚)
> 目标:`agent-node-lj-test`
> 用户裁决:**方案 A**(容器侧修,每个文件独立发)
---
## 背景:你自己查出的根因
23:14:39,612 INFO plugin_deliverable_inject.media_strip: strip_media: 已剥离 MEDIA 标记(878 -> 829 字符) 878 - 829 = 49 个字符 = `` 这一行的长度
`plugin-deliverable-inject` 的 `strip_media` 把 `` 行整行删掉,
导致 **HTML 文件没有作为附件发出**,用户只看到纯文字和两条 s3 链接。
日志显示这个行为已持续一段(15:26、15:56、18:24、20:02 都有同类记录)。
---
## 要做的两件事
### 任务 1:修 `strip_media`,放行本地文件路径
**现状**:只要回复里出现 `` 标记就删掉整行。
**要改成**:
- 只剥离**重复的 https 链接**(因为正文里已经有「已上云」段落了)
- **放行本地文件路径**(`` 这种要保留,它是发附件的唯一途径)
参考判据:
如果 MEDIA: 后面是 http(s):// → 可以剥离(正文已有链接) 如果 MEDIA: 后面是本地路径(/opt/data/...)→ 必须保留
### 任务 2:每个交付文件发**独立的 `m.file` 附件**
**现状**:用户发了 2 个文件(`data.json` + `nanchang-weather.html`),
但 App 只显示 1 张卡片 —— 因为只有第一个走了附件,第二个只留了链接。
**要改成**:每个文件都发一条独立的 `m.file` 事件。
**硬性要求**:
- 附件 `content.url` 用 `https://s3.fmode.cn/deliverables/...`(已验证可行)
- `body` = 文件名,`info.mimetype` / `info.size` 齐全
- **保留正文里的「已上云(可直接下载)」段落** —— 供不支持的客户端降级
---
## 验证(必须真实回读)
改完重启 gateway,然后:
1. 让容器产出一个任务,**至少 2 个文件**
2. 从 Matrix API 回读该回合的所有 `m.file` / `m.image` 事件
3. **逐条贴出**:
event_id | msgtype | body | url(完整,不许省略)
**判据**:
- 2 个文件 → **2 条独立的 `m.file` 事件**
- 每条 `url` 都是 `https://s3.fmode.cn/deliverables/...`
- 正文里仍有「已上云」段落
---
## 说明
App 侧我已经修好接收端:
- 每个 `m.file` 都会进文件宫格(有多条就显示多张卡片)
- 附件优先用 `cloudUrl`
**所以只要你把附件发出来,用户就能看到并下载。**
---
## 纪律
- 改插件后**必须重启 gateway**,重启会打断当前回合
- 用**真实回读**验证,不要靠打印自证
- 做不到就说做不到 —— 前面已经出现过多次伪证据
我先查看插件当前的实际实现,再动代码。
terminal · ls -la /opt/data/plugins/plugin-deliverable-inject/ 2>/dev/n…
ls /opt/data/plugins/ 2>/dev/null; ec...
📖 Reading __init__.py
已经找到根因。接下来先确认两件事:Matrix 适配器如何解析 `MEDIA:`,以及是否已有把文件发成 `m.file` 的插件。
* ```
ls /opt/data/plugins/ 2>/dev/null; ec...
📖 Reading init.py 📖 Reading media_strip.py 💻 terminal
grep -rn "MEDIA:" /opt/hermes/gateway...
### 6【prose】
text 很好,已有插件把 Matrix 出站的上传改走 s3。现在我要确认适配器如何确定 MEDIA 后面的路径,以及它会发哪些内容。
### 7【prose】
text
ls /opt/data/plugins/plugin-matrix-ou...
grep -rn "MEDIA" /opt/hermes/gateway/...
### 8【prose】
text 我要查一下 Matrix 适配器里拆分并发送媒体的位置。
### 9【prose】
text
grep -rln "media" /opt/hermes/gateway...
grep -rn "MEDIA_\|media_paths\|extrac...
### 10【prose】
text
extract_media 已支持多个 MEDIA 标签。现在我要确认媒体发送循环的范围,并查看每个文件会如何处理。
### 11【prose】
text
grep -rn "MEDIA:" /opt/hermes/gateway...
grep -rn "extract_media\|for path in ...
### 12【prose】
text
ls /opt/hermes/gateway/platforms/ | g...
📖 Reading run_turn.py L2385-2504
### 13【prose】
text
matrix.py 不在 platform 目录里,因为 matrix 适配器是插件,我接下来要定位它,并检查 extract_media 对 .html、.json 的处理方式。
### 14【prose】
text
ls /opt/hermes/gateway/platforms/ | g...
📖 Reading run_turn.py L2385-2504 💻 terminal
ls /opt/hermes/gateway/platforms/*.py...
python3 -c " ...
### 15【prose】
text
Matrix 适配器位于 /opt/hermes/plugins/platforms/matrix。我要确认 .html、.json 是否在可发送的扩展名白名单中,并检查 send_document 是如何发出 m.file 的。
### 16【prose】
text
ls /opt/hermes/plugins/platforms/matr...
sed -n '1185,1200p' /opt/hermes/gatew...
### 17【prose】
text
.html 和 .json 都在可发送扩展名白名单中。现在我检查 s3 出站插件是如何替换上传逻辑的,因为 _upload_and_send 在这里仍会生成 mxc 地址。
### 18【prose】
text
ls /opt/hermes/plugins/platforms/matr...
sed -n '1185,1200p' /opt/hermes/gatew...
📖 Reading adapter.py L1762-1836 📖 Reading init.py
### 19【prose】
text
接下来我要确认主回合(非后台任务)的发送路径:它是否会遍历 media_files,以及是由哪个组件真正去发送。
### 20【prose】
text ...
### 21【prose】
text
grep -n "extract_media\|send_document...
grep -rn "media_files\|extract_media"...
### 22【prose】
text
grep -rn "media_files" /opt/hermes/ga...
grep -rn "extract_media\|send_documen...
### 23【prose】
text
grep -rn "media_files" /opt/hermes/ga...
grep -rn "extract_media\|send_documen...
grep -n "extract_media\|send_document...
### 24【prose】
text
grep -rn "media_files" /opt/hermes/ga...
grep -rn "extract_media\|send_documen...
grep -n "extract_media\|send_document...
📖 Reading run_turn_runner.py L1835-1914
### 25【prose】
text
网络调用行为是好的。现在看我的插件实际把内容剥离到了什么程度:我要复现那个 878→829 的剥离。
### 26【prose】
text
grep -rn "media_files" /opt/hermes/ga...
grep -rn "extract_media\|send_documen...
grep -n "extract_media\|send_document...
📖 Reading run_turn_runner.py L1835-1914 🐍 Running code import subprocess code = r''' import ...
### 27【prose】
text
execute_code · import subprocess code = r''' import sys, os sys.path.insert…
### 28【prose】
text
已确认:strip_media 会无条件删除 MEDIA 行。接下来我会修复它,让本地路径对应的行保留下来。
### 29【prose】
text write_file · /opt/data/plugins/plugin-deliverable-inject/media_strip.py
### 30【prose】
text 现在测试这个修复,包括历史故障场景——出现两行 MEDIA 标记时正是 878→829 的字符数差异。
### 31【prose】
text 任务 1 已验证通过:本地路径的 MEDIA 行现在会保留,远程 URL 的 MEDIA 行仍会被剥离。
现在检查任务 2:每个文件分别发送附件时,实际是哪条代码路径来分发 media_files。
### 32【prose】
text
我需要找到前台回合中真正循环处理 media_files 的位置。
### 33【prose】
text
grep -rn "send_document\|send_image_f...
grep -rn "extract_media(" /opt/hermes...
### 34【prose】
text
框架已经会为每个文件循环发送。我要确认真正的交接口:filter_media_delivery_paths 是否会静默丢弃文件。
### 35【prose】
text terminal · grep -n "def filter_media_delivery_paths" -A 40 /opt/hermes/…
### 36【prose】
text 我要测试媒体分发链路的端到端行为,确认当文件存在时,两个 MEDIA 行都会保留下来。
### 37【prose】
text
框架的媒体分发链路把两个文件都正确提取出来了;罪魁祸首正是我的 strip_media。不过,我怀疑我的 __init__ 插件里还有第二个问题:它会把不在白名单里的 URL 删掉。我要验证这一点。
### 38【prose】
text
发现第二个问题:注入插件会把 s3 链接从正文里删掉,只留下空白的 - 项目符号。我要查看一个真实的状态文件,看看应该依据哪些信息建立白名单。
### 39【prose】
text 现在我要让注入插件同时按路径做匹配,这样上云块的链接与 MEDIA 标签对应的路径相同时,就不会被当作非白名单 URL 删掉。
### 40【prose】
text patch · /opt/data/plugins/plugin-deliverable-inject/init.py
### 41【prose】
text 现在把它接进主转换流程:按文件名把链接对到本轮已推送的记录,并在加载状态之前先做 MEDIA 剥离。
### 42【prose】
text
还要保护 MEDIA 本地路径行,不让后面的 _LOCAL_HINTS 清理删掉它们。
### 43【prose】
text 现在我要用一个模拟状态做整个插件的端到端测试。
### 44【prose】
text 端到端表现正常——两个 MEDIA 行都保留,伪造的 s3 链接也被改写成真实链接。现在重启 gateway,让改动生效。
### 45【prose】
text
ls /etc/s6-overlay/s6-rc.d/ 2>/dev/nu...
### 46【prose】
text
使用 --replace 在后台重启,让它重新启动,而不是杀掉服务管理器。
### 47【prose】
text
ls /etc/s6-overlay/s6-rc.d/ 2>/dev/nu...
cd /opt/data && nohup /opt/hermes/.ve...
### 48【prose】
text
/opt/hermes/.venv/bin/hermes gateway ...
### 49【prose】
text
/opt/hermes/.venv/bin/hermes gateway ...
sleep 25; ps -eo pid,etime,cmd | grep...
### 50【prose】
text
⚠️ 我要下线一会儿——手上这个任务会中断。等我回来,你随便说句话,我就接着往下做。
### 51【prose】
text 会话已恢复正常,网关重新上线。
刚才的进度:
strip_media):已完成,并做了本地测试。现在只剥离 `这类远程行;本地路径对应行(MEDIA:/opt/data/...`)会原样保留。实测结果:两行 MEDIA 标记都保留,上云段完整。-。已改为按文件名认领、替换成真实 URL 后保留。实测:两条假链接都被改写成 state 里的真实地址。run_notifications._deliver_media_from_response 本来就是 for media_path in non_image_media 逐个 send_document,extract_media() 也确实会返回两个路径。所以只要 MEDIA 行不被剥掉,两个附件就会各自发一条 m.file —— 之前只显示一张卡片,根因就是任务 1 那个剥离动作。还差的一步(重启打断了):真实回读验证 —— 发一个含 2 个文件的任务,从 Matrix API 拉该回合的 m.file 事件逐条贴 event_id | msgtype | body | url。
要我现在就跑这一步验证吗?还是你先有别的安排? ```
💻 terminalls -la /opt/data/plugins/plugin-deliv...``📖 Reading base.py L3079-3143* 📖 Reading base.py L3079-3143 💻 terminalgrep -rn "MEDIA_DELIVERY_EXTS" /opt/h...``💻 terminalgrep -n "send_document\|send_image_fi...``* 💻 terminalgrep -n "send_document\|send_image_fi...sed -n '1600,1660p' /opt/hermes/plugi...grep -n "media_files\|extract_media\|...``✍️ Writing /opt/data/plugins/plugin-deliverable-...🐍 Running code import subprocess code = r''' import ...💻 terminalsed -n '2690,2760p' /opt/hermes/gatew...``📖 Reading run_notifications.py L285-364* 📖 Reading run_notifications.py L285-364 💻 terminalgrep -n "def filter_media_delivery_pa...``🐍 Running code import subprocess code = r''' import ...🐍 Running code import subprocess code = r''' import ...💻 terminalpython3 -c " ...``🔧 Editing /opt/data/plugins/plugin-deliverable-...🔧 Editing /opt/data/plugins/plugin-deliverable-...📖 Reading __init__.py L126-195🔧 Editing /opt/data/plugins/plugin-deliverable-...* 🔧 Editing /opt/data/plugins/plugin-deliverable-... 🐍 Running code import subprocess, json, os, time, te...💻 terminalps -eo pid,user,etime,cmd | grep -i "...``