Skip to content

modlens/opencode CLI 在 Windows 上"用 -f 传图片时 MIME 探测错误",将图片识别成文本 #77

Closed as not planned

Description

@eason-liuyx

分析结果:modlens 无法分析这张图片,根因是已知 bug
图片本身没问题(已验证:存在、8050 字节、PNG magic 头正确 137,80,78,71...),是一张真正的 PNG 图。

但 modlens 读不了,因为上一轮已定位的 bug 再次命中:

modlens 用 opencode run -f <图片路径> 调 opencode CLI(源码 dist/main.js:3212-3221),opencode CLI 收到 -f 的 PNG 文件后,MIME 探测成了 text/plain(opencode 日志铁证 file mime=text/plain),于是模型收到的是文本而非图像,回 "this model does not support image input"。

这不是图片的问题,也不是你配置/模型/key 的问题 —— 这张图你如果直接在 opencode 对话框里 paste(走 UI 路径,不走 -f),qwen3.7-plus 是能读图的(你之前验证过)。问题只出在 modlens 调 opencode CLI 这条路径上。

总结当前状态
modlens 配置:provider: opencode-cli,model: ali_maas/qwen3.7-plus
链路通到模型(鉴权 OK、key 有权限、模型可调),但图片在 opencode CLI 这步被当文本传
这是 modlens/opencode CLI 在 Windows 上"用 -f 传图片时 MIME 探测错误"的已知限制,配置层面无法修复

Activity

  1. liustack commented on Aug 22, 2026

    @liustack
    Owner

    查了 opencode 的源码,先纠正一下定位:这不是 Windows 上的 MIME 探测出错。opencode run -f 对本地文件在所有平台都把 mime 硬编码成 text/plain(packages/opencode/src/cli/cmd/run.ts 的非 --attach 分支),所以日志里的 file mime=text/plain 在 macOS/Linux 上也是这个值,而那些平台上图片照样能读。

    真正决定图片能不能被读的是后面这段:opencode 服务端拿到 file:// 附件后,会用内置 Read 工具重读这个文件,Read 工具按文件头魔数(PNG 的 137 80 78 71...)把它重新识别成 image/png,再作为图片附件送给模型。这条恢复链路要同时满足两个条件:

    1. opencode 版本 >= v1.14.17(2026-04-19,按文件内容重探 MIME 的修复 fix: detect attachment mime from file contents anomalyco/opencode#23291 从这版开始带)。
    2. 模型在 opencode 里声明了图片输入能力。ali_maas 是自定义 provider,模型没有 models.dev 的能力元数据,不声明就按纯文本模型处理,从工具结果里读出的图片会被丢弃或报不支持。你贴的「this model does not support image input」更符合这一条,而不是图片被当成文本。

    UI 里 paste 能读图不矛盾:paste 直接以 image/png 的 data 附件进对话,不经过 Read 工具这条链路,所以两条路径表现不同。

    请按顺序验证两步,每步都直接跑 opencode 命令行,不经 modlens:

    opencode --version   # 老于 1.14.17 先升级
    opencode run "这张图里有什么" -m ali_maas/qwen3.7-plus -f 你的图.png

    如果升级后还不行,在 opencode 配置里给这个模型声明图片能力再试(models.dev 模型字段):

    {
      "provider": {
        "ali_maas": {
          "models": {
            "qwen3.7-plus": { "attachment": true }
          }
        }
      }
    }

    上面这条命令行通了,modlens 就通,因为 modlens 走 opencode-cli 这条路时就是原样拼这条命令。modlens 侧没有可修的点:mime 是 opencode CLI 硬编码的,modlens 无法从外部传入。验证结果麻烦回帖说一声,命令行直跑仍失败的话,把 opencode --version 和完整输出贴上来。

  2. xhm9 commented on Aug 23, 2026

    @xhm9
    环境 modlens 3.23.1 + DSH web,bundle 方式加载
    错误现象 启动时终端刷 1~3 次报错,err.log 为空,不影响功能
    问题定位 dsh/index.js 第 924 行在 apply() 期间直接调用首次 sweep → 第 880 行 ctx.llm.listProviders() 抛 "inactive context" 错误
  3. liustack commented on Aug 23, 2026

    @liustack
    Owner

    原问题按前面的源码核对结果关闭。

    • opencode run -f 将本地 file:// 附件初始标为 text/plain 是所有平台共有的设计,不是 Windows MIME 探测错误。
    • 图片需要由 OpenCode 的 Read 工具按文件内容重新识别。该链路要求 OpenCode 不低于 v1.14.17,对应修复为 fix: detect attachment mime from file contents anomalyco/opencode#23291
    • ali_maas 是自定义 provider,qwen3.7-plus 还需要在 OpenCode 模型配置中声明 "attachment": true。
    • ModLens 只是按既定接口调用 opencode run ... -f <path>,无法从外部改变 OpenCode 内部的 MIME 和模型能力处理。

    如果直跑下面的命令在满足版本和模型配置后仍然失败,可以重新打开 issue,并附上 opencode --version 与完整输出:

    opencode run "这张图里有什么" -m ali_maas/qwen3.7-plus -f 你的图.png

    #77 下关于 DSH Web 启动时报 inactive context 的评论是另一个真实问题,已经拆到 #79 继续跟踪:

    #79

  4. added
    invalidThis doesn't seem right
    and removed
    bugSomething isn't working
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions