picturereader-zcode 1.0.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -73
- package/mcp/server.js +175 -6
- package/package.json +6 -3
- package/skills/image-reading.md +23 -0
- package/skills/vision-analyze.md +256 -0
- package/src/guard.js +101 -0
- package/src/index.js +2 -0
- package/src/vision-analyze.js +260 -0
- package/src/vlm.js +269 -0
package/README.md
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
# picturereader
|
|
1
|
+
# picturereader(ZCode 版)
|
|
2
2
|
|
|
3
|
-
> 给纯文本模型(如 deepseek-v4-flash
|
|
4
|
-
>
|
|
5
|
-
>
|
|
3
|
+
> **v2.0.0** —— 给纯文本模型(如 deepseek-v4-flash)的**全能"读图"能力**。
|
|
4
|
+
> 融合 **独立伪多模态识图** 与 **外部视觉 API 接口**,一个插件搞定全部,**无需另装任何插件**。
|
|
5
|
+
> 本分支为 **ZCode 桌面端插件**(经 MCP 暴露工具);DSH 版见 [main 分支](https://github.com/jing-hy/picturereader)。
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
>
|
|
9
|
-
> **纯本地、零外部模型依赖、零 API key、零 Python(PaddleOCR 为可选增强)**。
|
|
7
|
+
> - **DSH 版**:DeepSeek Harness 插件(`dsh-plugin`,含 DSH EAC 桌面端)—— [main 分支](https://github.com/jing-hy/picturereader)
|
|
8
|
+
> - **ZCode 版**:ZCode 桌面端插件(`zcode-plugin`,经 MCP 暴露工具)—— 本分支
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
## 本轮工作(v2.0.0 新增)
|
|
11
|
+
|
|
12
|
+
在原有的**本地伪多模态识图**(像素扫描 + OCR + 取样,零外部依赖)之上,融合了社区 `dsh-universal-vision` 的优势,形成一套**统一、可交叉验证的完整识图栈**:
|
|
13
|
+
|
|
14
|
+
1. **新增外部视觉 API 接口**(`src/vlm.js`):桥接任意 OpenAI 兼容的视觉端点(本地 llama-server / LM Studio / vLLM / 云端网关),让模型获得真正的**语义理解**能力(场景、角色、界面、风格)。
|
|
15
|
+
2. **新增统一分析工具 `vision_analyze`**:一次调用即可取回「低信息拦截 + 像素扫描 + OCR + VLM」多路证据。
|
|
16
|
+
3. **新增低信息量拦截**(`src/guard.js`):自动识别空白/未渲染/简单图片,避免小 VLM 在空图上幻觉,也节省调用成本。
|
|
17
|
+
4. **证据交叉验证**:VLM 描述与像素/OCR 实测冲突时,以实测为准——伪多模态与真 VLM 互为印证,抑制幻觉。
|
|
18
|
+
5. **多次提问**:可对同一张图用 `vision_analyze` 以不同 `prompt` 反复提问,从多角度复核同一内容。
|
|
19
|
+
|
|
20
|
+
> **核心优势一句话**:**独立伪多模态识图(零依赖、可离线) + 外部 API 语义接口(可选、即插即用)** —— 简单图用像素就够,复杂图一键接 VLM,一个插件全包含,不需要再装 `dsh-universal-vision` 或任何其他读图插件。
|
|
12
21
|
|
|
13
22
|
## 版本总览
|
|
14
23
|
|
|
15
24
|
| 版本 | 平台 | 形态 | 源码 | 安装 |
|
|
16
25
|
|---|---|---|---|---|
|
|
17
|
-
| **DSH 版** | DeepSeek Harness(含 EAC 桌面端) | npm 插件(`dsh.bundle`) |
|
|
18
|
-
| **ZCode 版** | ZCode 桌面端 | 本地 marketplace 插件(MCP server + skill) |
|
|
26
|
+
| **DSH 版** | DeepSeek Harness(含 EAC 桌面端) | npm 插件(`dsh.bundle`) | [main 分支](https://github.com/jing-hy/picturereader) | `dsh plugin --profile web add picturereader` |
|
|
27
|
+
| **ZCode 版** | ZCode 桌面端 | 本地 marketplace 插件(MCP server + skill) | 本分支 | `npm install picturereader-zcode` |
|
|
19
28
|
|
|
20
29
|
两个版本共用同一套业务核心(`src/core.js`)与读图方法论 skill(`image-reading`),
|
|
21
|
-
|
|
30
|
+
四个工具行为完全一致:`image_scan` / `image_ocr` / `image_sample` / `vision_analyze`。
|
|
31
|
+
|
|
32
|
+
> **兼容性**:DSH 版已验证兼容 **DeepSeek Harness EAC 4.2.0** 及 `@deepseek-ai/dsh-client-ui-workspace` **rc.7**(4.2.0 配套的官方工作区插件版本)。
|
|
22
33
|
|
|
23
34
|
> **ZCode 版性能说明**:ZCode 版通过 MCP(stdio 子进程)暴露工具,每次调用都要
|
|
24
35
|
> 经历进程通信与序列化开销,**速度明显慢于 DSH 版**(DSH 版为插件内直接调用)。
|
|
@@ -26,13 +37,14 @@
|
|
|
26
37
|
|
|
27
38
|
## 这是什么
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
纯文本模型没有视觉编码器,无法直接看图。picturereader 把"看图"翻译成**模型能理解的结构化文本证据**,并提供一套经过大量真实图片迭代验证的**读图方法论 skill(image-reading)**,让模型像人一样分步看图:
|
|
30
41
|
|
|
31
42
|
1. **全局定调**:hue families(纯色指纹)→ structure(条纹/对称)→ texture(写实度)→ regions(色块结构)
|
|
32
43
|
2. **主动找主体**:px_per_cell 定向放大(深色/低对比/小色块不会漏)
|
|
33
44
|
3. **文字验证**:PaddleOCR 实读(防多模态幻觉)
|
|
34
45
|
4. **材质判断**:image_sample 像素取样
|
|
35
|
-
5.
|
|
46
|
+
5. **(可选)VLM 语义理解**:外部视觉 API 提供场景/角色/界面/风格的自然语言描述
|
|
47
|
+
6. **综合描述**:带证据等级的连贯画面描述,伪多模态与 VLM 交叉验证
|
|
36
48
|
|
|
37
49
|
## 工具
|
|
38
50
|
|
|
@@ -41,50 +53,59 @@ DeepSeek 等纯文本模型没有视觉编码器,无法直接看图。picturer
|
|
|
41
53
|
| `image_scan` | 全局/区域扫描:亮度/颜色网格 + regions 色块 + shade diversity + texture mix + structure(条纹/对称) + **像素级 colors** + **hue families 纯色指纹**;支持 `focus`/`region` 局部放大、`px_per_cell` 像素密度定向放大 |
|
|
42
54
|
| `image_ocr` | 文字识别双引擎:`windows`(内置,默认)/ `paddle`(选装,发光/弯曲/游戏字更强),失败自动降级不崩溃 |
|
|
43
55
|
| `image_sample` | 8×8 精确像素取样,判断材质/纹理(金属/木纹/织物/皮肤/噪点) |
|
|
56
|
+
| `vision_analyze` | **统一入口(v2.0.0 新增)**:低信息拦截 + 可选像素扫描/OCR/VLM,组合证据返回;VLM 可选配置 |
|
|
44
57
|
|
|
45
58
|
### 读图方法论 skill(image-reading)
|
|
46
59
|
|
|
47
|
-
`skills/image-reading
|
|
60
|
+
`skills/image-reading/SKILL.md`(ZCode 版)是一套**经大量真实图片场景迭代验证**的读图方法论
|
|
48
61
|
(按 experience / skill / principle / insight 分层,教训有据可依、找得到主模型模式),
|
|
49
62
|
安装后模型自动掌握:
|
|
50
63
|
- **hue 场景指纹**:cyan 高=水/雾/湖泊,green 高=森林,orange/red 高=暖色人物/火光,blue 高=夜空科幻,achromatic+rough=废墟,green+yellow=翠绿能量/浮空仙境
|
|
51
64
|
- **多模态模型校验规则**:游戏名/品牌等文字必须 OCR 实读(多模态模型会猜错);发光元素颜色以 hue 实测为准(多模态模型对发光色的描述系统性不可靠);低对比主体(暗色人物/小色块)必须放大确认
|
|
52
65
|
- **主动验证**:低对比主体(暗色人物/小色块)必须放大确认
|
|
66
|
+
- **vision_analyze 使用**(v2.0.0):先 image_scan 自己看,简单图用像素,复杂图再调 VLM;描述与实测冲突时以实测为准
|
|
53
67
|
|
|
54
68
|
## 安装
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
ZCode 版通过 **MCP server**(`mcp/server.js`,stdio)把四个工具暴露给 ZCode,
|
|
71
|
+
读图方法论作为 **skill** 随插件分发,业务逻辑 `src/core.js` 与 DSH 版完全一致。
|
|
57
72
|
|
|
58
73
|
```sh
|
|
59
|
-
|
|
60
|
-
dsh plugin --profile web add picturereader # 或从源码: dsh plugin --profile web add .
|
|
61
|
-
dsh plugin --profile headless add picturereader
|
|
62
|
-
|
|
63
|
-
# 2. 读图方法论 skill(推荐)
|
|
64
|
-
copy skills\image-reading.md %USERPROFILE%\.dsh\skills\ # Windows
|
|
65
|
-
# macOS/Linux: cp skills/image-reading.md ~/.dsh/skills/
|
|
66
|
-
|
|
67
|
-
# 3.(可选)PaddleOCR 增强引擎:node scripts/setup-ocr.mjs
|
|
74
|
+
npm install picturereader-zcode
|
|
68
75
|
```
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
技能目录出现 `image-reading`。
|
|
77
|
+
### (可选)PaddleOCR 增强引擎
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
```sh
|
|
80
|
+
node scripts/setup-ocr.mjs
|
|
81
|
+
```
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
读图方法论作为 **skill**(`skills/image-reading/`)随插件分发,业务逻辑 `src/core.js`
|
|
79
|
-
与本仓库完全一致。安装与使用请见其 README。
|
|
83
|
+
PaddleOCR 缺失时 `image_ocr` 自动降级为 Windows OCR。
|
|
80
84
|
|
|
81
85
|
## 使用
|
|
82
86
|
|
|
83
|
-
|
|
87
|
+
对 ZCode 模型说:
|
|
84
88
|
|
|
85
89
|
> 用 image_scan 看一下 <路径> 这张图,细看感兴趣的部分
|
|
90
|
+
> (复杂场景可接着用 vision_analyze 获取语义描述并交叉验证)
|
|
91
|
+
|
|
92
|
+
### vision_analyze 用法(v2.0.0)
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
vision_analyze(
|
|
96
|
+
file_path="C:/shot.png",
|
|
97
|
+
prompt="描述这个界面,有哪些元素?布局是否正常?",
|
|
98
|
+
include_scan=true, # 像素扫描证据(默认 true)
|
|
99
|
+
include_ocr=true, # OCR 文字证据(默认 false)
|
|
100
|
+
include_vlm=true, # 外部 VLM 语义描述(默认 true,但未配置 SEE_BASE 时自动跳过)
|
|
101
|
+
allow_low_info=false, # 空白/简单图是否强制调 VLM(默认 false)
|
|
102
|
+
stop_after=false # 调用后是否关闭本插件启动的本地服务器
|
|
103
|
+
)
|
|
104
|
+
```
|
|
86
105
|
|
|
87
|
-
|
|
106
|
+
- **先自己看,再决定**:建议先用 `image_scan` 了解图片,简单图用像素就够;复杂/精密场景再开 VLM。
|
|
107
|
+
- **多次提问**:对同一张图换不同 `prompt` 反复调用,从多角度复核。
|
|
108
|
+
- **交叉验证**:VLM 描述与像素/OCR 冲突时,以实测为准。
|
|
88
109
|
|
|
89
110
|
## 输出示例
|
|
90
111
|
|
|
@@ -98,63 +119,50 @@ colors by area: ...(像素级真实占比)
|
|
|
98
119
|
luminance grid / color grid
|
|
99
120
|
```
|
|
100
121
|
|
|
101
|
-
##
|
|
122
|
+
## 环境变量
|
|
123
|
+
|
|
124
|
+
### PaddleOCR(可选)
|
|
102
125
|
|
|
103
126
|
| 变量 | 默认值 | 作用 |
|
|
104
127
|
|---|---|---|
|
|
105
128
|
| `DSH_PADDLE_PYTHON` | `C:\Users\Administrator\paddle_venv\Scripts\python.exe` | PaddleOCR 解释器路径(与原插件同名,便于直接迁移) |
|
|
106
129
|
| `DSH_PADDLE_CACHE` | `<插件目录>\.paddlex-cache` | PaddleX 模型缓存目录 |
|
|
107
130
|
|
|
131
|
+
### 外部视觉 API / VLM(可选,**默认不配置**)
|
|
132
|
+
|
|
133
|
+
| 变量 | 默认值 | 作用 |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| `SEE_BASE` | `(空)` | OpenAI 兼容视觉端点(留空 = VLM 禁用;本地 llama-server / LM Studio / vLLM / 云端网关) |
|
|
136
|
+
| `SEE_MODEL` | `(空)` | 视觉模型名(如 `google/gemma-4-12b-qat`) |
|
|
137
|
+
| `SEE_API_KEY` | `(空)` | API key(本地端点可随便填,云端需要真实 key) |
|
|
138
|
+
| `SEE_SERVER_EXE` / `SEE_SERVER_MODEL` / `SEE_SERVER_MMPROJ` | `(空)` | 本地 llama-server 自启路径(可选,配置后插件可自动拉起本地视觉服务器) |
|
|
139
|
+
| `SEE_SERVER_PORT` / `SEE_SERVER_NGL` / `SEE_SERVER_CTX` | `8080` / `20` / `16384` | 本地服务器参数 |
|
|
140
|
+
|
|
141
|
+
> **VLM 配置说明**:默认不配置 VLM,`vision_analyze` 会跳过 VLM 调用,只返回像素扫描和 OCR 证据(保持零外部依赖)。需要语义理解时,设置 `SEE_BASE` + `SEE_MODEL` 即可,例如指向本地 LM Studio(`http://127.0.0.1:1234/v1`)。
|
|
142
|
+
|
|
108
143
|
## 开发
|
|
109
144
|
|
|
110
145
|
```sh
|
|
111
|
-
# DSH 版(本仓库)
|
|
112
146
|
npm install
|
|
113
|
-
npm test # node:test
|
|
114
|
-
node scripts/setup-ocr.mjs # 可选:装 PaddleOCR
|
|
115
|
-
node scripts/preview.mjs # 生成 fixtures 并预览渲染
|
|
116
|
-
|
|
117
|
-
# ZCode 版(独立仓库 jing-hy/picturereader-zcode)
|
|
118
|
-
git clone https://github.com/jing-hy/picturereader-zcode.git
|
|
119
|
-
cd picturereader-zcode
|
|
120
|
-
npm install
|
|
121
|
-
npm test # node:test
|
|
147
|
+
npm test # node:test(DSH 版 76 个测试全绿)
|
|
122
148
|
node scripts/setup-ocr.mjs # 可选
|
|
123
149
|
```
|
|
124
150
|
|
|
125
|
-
**热插拔(DSH 版)**:DSH 本身不支持代码热重载,但本插件自带执行层热加载——业务逻辑全在
|
|
126
|
-
`src/core.js` 单文件,工具每次执行按 mtime 动态加载(cache-bust),**改 core.js
|
|
127
|
-
下次调用即生效**;工具定义(schema/描述)改动需重启桌面端。
|
|
128
|
-
|
|
129
151
|
**热插拔(ZCode 版)**:MCP server 从所选目录运行,改 `src/core.js` 下次调用即生效
|
|
130
|
-
(详见
|
|
152
|
+
(详见 zcode 分支 README)。
|
|
131
153
|
|
|
132
154
|
## 优势
|
|
133
155
|
|
|
134
|
-
-
|
|
135
|
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
-
|
|
156
|
+
- **一个插件全包含,无需另装**:独立的伪多模态识图 + 可选外部视觉 API,融合在一个包里,不需要再装 `dsh-universal-vision` 或其他任何读图插件
|
|
157
|
+
- **核心链路零外部依赖**:扫描/取样/解码纯本地纯 JS,不调任何视觉 API;语义理解要么交给主模型,要么按需桥接你自己的 VLM
|
|
158
|
+
- **双版本独立分发,互不污染**:DSH 用 `picturereader`(main 分支),ZCode 用 `picturereader-zcode`(本分支);DSH 版带 `dsh.bundle`、ZCode 版带 `mcp` + `.zcode-plugin`,各装各的宿主,**不会把 ZCode 版误装进 DSH,也不会把 DSH 版误装进 ZCode**
|
|
159
|
+
- **外部 API 可选、即插即用**:默认不配置 `SEE_BASE` 保持纯本地;配了即接入语义理解,本地 llama-server / LM Studio / vLLM / 云端 OpenAI 兼容端点通吃
|
|
160
|
+
- **低信息量拦截**(v2.0.0):自动识别空白/未渲染/简单图,避免小 VLM 幻觉、省调用成本
|
|
161
|
+
- **证据交叉验证**(v2.0.0):VLM 描述与像素/OCR 实测冲突时以实测为准——伪多模态与真 VLM 互为印证,抑制幻觉
|
|
162
|
+
- **多次提问**(v2.0.0):同一张图可换不同 `prompt` 反复 `vision_analyze`,从多角度复核
|
|
163
|
+
- **可追溯、可验证**:每个结论都有数据支撑(hue 占比、色块坐标、OCR 文本+置信度)
|
|
139
164
|
- **成本低**:一次扫描 ≈0.6–2.2K tokens;PaddleOCR 本地跑,无 API 费用
|
|
140
|
-
-
|
|
141
|
-
- **方法论沉淀**:附带的 image-reading skill 把读图经验固化(场景指纹/校验规则),
|
|
142
|
-
模型每次看图都带着经过大量图片验证的经验
|
|
143
|
-
|
|
144
|
-
## 局限性(重要)
|
|
145
|
-
|
|
146
|
-
- **不是真正的视觉模型**:文本网格信息量有限,**人脸/表情/花纹等像素级细节读不出**;
|
|
147
|
-
这是文本模态的硬上限,放大(px_per_cell)只能缩小差距,不能消除
|
|
148
|
-
- **语义推断依赖主模型能力**:物体识别("这是树/空间站")是 LLM 基于结构证据的推测,
|
|
149
|
-
不是视觉模型的确证——复杂/罕见物体可能推断错误
|
|
150
|
-
- **OCR 引擎边界**:Windows OCR 对发光/弯曲/艺术字失效;PaddleOCR 强很多但需选装,
|
|
151
|
-
且对极小文字/极端艺术字仍可能失败(可配合放大)
|
|
152
|
-
- **性能**:4K 图解码 ~230ms;PaddleOCR 每次调用需 ~2s 加载模型;大图网格渲染
|
|
153
|
-
token 随 size 增长(64×64 color ≈ 3–5K tokens)
|
|
154
|
-
- **ZCode 版 MCP 开销**:ZCode 版工具经 MCP stdio 子进程通信,单次调用比 DSH 版慢
|
|
155
|
-
(进程启动 + JSON-RPC 序列化);高频/批量看图建议用 DSH 版
|
|
156
|
-
- **WebP 不支持**(提示转 PNG/JPEG);GIF 只读首帧
|
|
157
|
-
- **多模态模型的描述不可全信**(本插件可交叉验证,但最终语义仍需人工判断关键场景)
|
|
165
|
+
- **方法论沉淀**:附带的 image-reading skill 把读图经验固化(场景指纹/校验规则),模型每次看图都带着经过大量图片验证的经验
|
|
158
166
|
|
|
159
167
|
## License
|
|
160
168
|
|
package/mcp/server.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* picturereader MCP server — exposes the image-reading tools to ZCode as a
|
|
3
3
|
* Model Context Protocol stdio server.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* - `image_scan`
|
|
7
|
-
* - `image_ocr`
|
|
8
|
-
* - `image_sample`
|
|
5
|
+
* Four tools, identical in behavior to the original DSH plugin:
|
|
6
|
+
* - `image_scan` coarse pixel grid + hue/color/structure analysis
|
|
7
|
+
* - `image_ocr` text recognition (Windows OCR default, PaddleOCR optional)
|
|
8
|
+
* - `image_sample` exact-pixel texture sampling for material judgment
|
|
9
|
+
* - `vision_analyze` unified pipeline: low-info guard + optional scan/OCR/VLM
|
|
9
10
|
*
|
|
10
11
|
* The entire business logic lives in `src/core.js`, loaded dynamically with a
|
|
11
12
|
* cache-busting query keyed on the file's mtime (see `importCore`), so editing
|
|
@@ -22,6 +23,8 @@ import { extname, isAbsolute, resolve as resolvePath } from 'node:path';
|
|
|
22
23
|
import { stat, readFile } from 'node:fs/promises';
|
|
23
24
|
import { createInterface } from 'node:readline';
|
|
24
25
|
import { pathToFileURL } from 'node:url';
|
|
26
|
+
import { isLowInformationImage } from '../src/guard.js';
|
|
27
|
+
import { ensureServer, stopServer, sendVisionRequest, defaultVlmConfig, isVlmConfigured } from '../src/vlm.js';
|
|
25
28
|
|
|
26
29
|
/** The MCP protocol version this server speaks. */
|
|
27
30
|
export const PROTOCOL_VERSION = '2025-06-18';
|
|
@@ -314,9 +317,120 @@ export async function executeSample(args) {
|
|
|
314
317
|
};
|
|
315
318
|
}
|
|
316
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Parse a boolean argument with fallback.
|
|
322
|
+
* @param {any} value - the argument value.
|
|
323
|
+
* @param {boolean} fallback - default value.
|
|
324
|
+
* @returns {boolean} parsed boolean.
|
|
325
|
+
*/
|
|
326
|
+
function boolArg(value, fallback = false) {
|
|
327
|
+
if (value === undefined || value === null) return fallback;
|
|
328
|
+
if (typeof value === 'boolean') return value;
|
|
329
|
+
return String(value) === 'true' || String(value) === '1';
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* `vision_analyze`: unified image understanding pipeline.
|
|
334
|
+
* Runs low-information guard, optional scan, optional OCR, optional VLM.
|
|
335
|
+
* @param args - tool arguments.
|
|
336
|
+
* @returns the combined analysis result.
|
|
337
|
+
*/
|
|
338
|
+
export async function executeVisionAnalyze(args) {
|
|
339
|
+
const { core, filePath, ext } = await loadImageArgs(args, 'vision_analyze');
|
|
340
|
+
const absolutePath = resolveImagePath(filePath);
|
|
341
|
+
const data = await readImageFile(absolutePath, 'vision_analyze');
|
|
342
|
+
const image = decodeBounded(core, data, ext, 'vision_analyze');
|
|
343
|
+
|
|
344
|
+
const includeScan = args.include_scan === undefined ? true : boolArg(args.include_scan, true);
|
|
345
|
+
const includeOcr = args.include_ocr === undefined ? false : boolArg(args.include_ocr, false);
|
|
346
|
+
const includeVlm = args.include_vlm === undefined ? true : boolArg(args.include_vlm, true);
|
|
347
|
+
const allowLowInfo = boolArg(args.allow_low_info, false);
|
|
348
|
+
const stopAfter = boolArg(args.stop_after, false);
|
|
349
|
+
const prompt = args.prompt ?? 'Describe this image in detail.';
|
|
350
|
+
|
|
351
|
+
// Check if VLM is configured
|
|
352
|
+
const vlmAvailable = isVlmConfigured();
|
|
353
|
+
const shouldCallVlm = includeVlm && vlmAvailable;
|
|
354
|
+
|
|
355
|
+
const lowInfo = isLowInformationImage(image.data, image.width, image.height);
|
|
356
|
+
const blocks = [];
|
|
357
|
+
let ocrText = '';
|
|
358
|
+
let scanText = '';
|
|
359
|
+
let vlmText = '';
|
|
360
|
+
|
|
361
|
+
if (lowInfo && !allowLowInfo) {
|
|
362
|
+
const message =
|
|
363
|
+
'[vision_analyze] 低信息量拦截:图片空白或内容极少,为避免 VLM 幻觉,未调用 VLM。' +
|
|
364
|
+
'请检查截图是否空白/未渲染/窗口在屏幕外;如确需识别请设置 allow_low_info=true。';
|
|
365
|
+
return { path: absolutePath, lowInformation: true, message, combined: message };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (includeScan) {
|
|
369
|
+
const analysis = core.analyzeImage(image.data, image.width, image.height, {
|
|
370
|
+
size: 32,
|
|
371
|
+
mode: 'auto',
|
|
372
|
+
region: undefined,
|
|
373
|
+
palette: 'auto'
|
|
374
|
+
});
|
|
375
|
+
scanText = core.renderImageScan({
|
|
376
|
+
path: absolutePath,
|
|
377
|
+
width: image.width,
|
|
378
|
+
height: image.height,
|
|
379
|
+
...analysis
|
|
380
|
+
});
|
|
381
|
+
blocks.push(`[scan]\n${scanText}`);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (includeOcr) {
|
|
385
|
+
const engine = args.ocr_engine ?? 'windows';
|
|
386
|
+
const ocr = await core.ocrImage(data, ext, { engine });
|
|
387
|
+
ocrText = core.renderOcr({
|
|
388
|
+
path: absolutePath,
|
|
389
|
+
width: ocr.width,
|
|
390
|
+
height: ocr.height,
|
|
391
|
+
region: 'full',
|
|
392
|
+
engine: ocr.engine,
|
|
393
|
+
lines: ocr.lines
|
|
394
|
+
});
|
|
395
|
+
blocks.push(`[ocr]\n${ocrText}`);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (shouldCallVlm) {
|
|
399
|
+
const config = defaultVlmConfig();
|
|
400
|
+
let startedByUs = false;
|
|
401
|
+
try {
|
|
402
|
+
const child = await ensureServer(config);
|
|
403
|
+
startedByUs = child !== null;
|
|
404
|
+
const base64 = data.toString('base64');
|
|
405
|
+
const mime = ext === '.jpg' || ext === '.jpeg' ? 'image/jpeg' : ext === '.png' ? 'image/png' : ext === '.gif' ? 'image/gif' : 'image/bmp';
|
|
406
|
+
const safePrompt =
|
|
407
|
+
prompt +
|
|
408
|
+
'\n\n重要:只描述图中明确可见的内容。如果图中没有明显物体/文字/界面元素,请直接回答:画面空白或内容极少。不要推测、不要脑补不存在的角色/场景/文字。';
|
|
409
|
+
vlmText = await sendVisionRequest(config, [{ mime, base64 }], safePrompt);
|
|
410
|
+
blocks.push(`[vlm]\n${vlmText}`);
|
|
411
|
+
} finally {
|
|
412
|
+
if (stopAfter && startedByUs) {
|
|
413
|
+
await stopServer();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
} else if (includeVlm && !vlmAvailable) {
|
|
417
|
+
blocks.push('[vlm] VLM 未配置(SEE_BASE 环境变量为空)');
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const combined = blocks.join('\n\n---\n\n');
|
|
421
|
+
return {
|
|
422
|
+
path: absolutePath,
|
|
423
|
+
lowInformation: false,
|
|
424
|
+
...(scanText ? { scan: scanText } : {}),
|
|
425
|
+
...(ocrText ? { ocr: ocrText } : {}),
|
|
426
|
+
...(vlmText ? { vlm: vlmText } : {}),
|
|
427
|
+
combined
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
317
431
|
/**
|
|
318
432
|
* Dispatch a tool call to its implementation.
|
|
319
|
-
* @param name - tool name ('image_scan' | 'image_ocr' | 'image_sample').
|
|
433
|
+
* @param name - tool name ('image_scan' | 'image_ocr' | 'image_sample' | 'vision_analyze').
|
|
320
434
|
* @param args - tool arguments object.
|
|
321
435
|
* @returns the structured tool result.
|
|
322
436
|
*/
|
|
@@ -326,6 +440,7 @@ export async function executeTool(name, args) {
|
|
|
326
440
|
case 'image_scan': return executeScan(cleanArgs);
|
|
327
441
|
case 'image_ocr': return executeOcr(cleanArgs);
|
|
328
442
|
case 'image_sample': return executeSample(cleanArgs);
|
|
443
|
+
case 'vision_analyze': return executeVisionAnalyze(cleanArgs);
|
|
329
444
|
default: throw new Error(`unknown tool: ${name}`);
|
|
330
445
|
}
|
|
331
446
|
}
|
|
@@ -453,11 +568,65 @@ export const TOOLS = [
|
|
|
453
568
|
},
|
|
454
569
|
required: ['file_path', 'region']
|
|
455
570
|
}
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
name: 'vision_analyze',
|
|
574
|
+
description: [
|
|
575
|
+
'Unified image understanding: decode an image, run a low-information guard, optionally scan pixels, OCR text, and/or ask the VLM for a semantic description.',
|
|
576
|
+
'Use this when you need one call to both verify what is in the image and get a natural-language interpretation.',
|
|
577
|
+
'Returns evidence blocks: scan (pixel stats), ocr (real text), vlm (model description). If low-information guard triggers and allow_low_info is false, it will not call the VLM.',
|
|
578
|
+
'Supported formats: PNG, JPEG, GIF (first frame), BMP. WebP is not supported yet.',
|
|
579
|
+
'VLM is optional: if SEE_BASE is not configured, VLM calls are skipped automatically.',
|
|
580
|
+
'Smart API calling: simple images (low color diversity, high dominant color coverage) skip VLM automatically.',
|
|
581
|
+
'Multiple questions: call this tool multiple times with different prompts on the same image for comprehensive analysis.',
|
|
582
|
+
'Cross-validation: main model should verify VLM results against pixel scan and OCR evidence.'
|
|
583
|
+
].join(' '),
|
|
584
|
+
inputSchema: {
|
|
585
|
+
type: 'object',
|
|
586
|
+
additionalProperties: true,
|
|
587
|
+
properties: {
|
|
588
|
+
file_path: { type: 'string', description: IMAGE_PATH_DESCRIPTION },
|
|
589
|
+
prompt: {
|
|
590
|
+
type: 'string',
|
|
591
|
+
description: 'Question/instruction for the VLM, e.g. "Describe this UI" or "What is wrong with this map rendering?"'
|
|
592
|
+
},
|
|
593
|
+
include_scan: {
|
|
594
|
+
type: 'boolean',
|
|
595
|
+
description: 'Include pixel scan evidence (default true).'
|
|
596
|
+
},
|
|
597
|
+
include_ocr: {
|
|
598
|
+
type: 'boolean',
|
|
599
|
+
description: 'Include OCR text evidence (default false; set true when text matters).'
|
|
600
|
+
},
|
|
601
|
+
ocr_engine: {
|
|
602
|
+
type: 'string',
|
|
603
|
+
enum: ['windows', 'paddle'],
|
|
604
|
+
description: 'OCR engine: windows (default) or paddle (better for glowing/curved/game text).'
|
|
605
|
+
},
|
|
606
|
+
include_vlm: {
|
|
607
|
+
type: 'boolean',
|
|
608
|
+
description: 'Include VLM description (default true, but skipped if SEE_BASE not configured).'
|
|
609
|
+
},
|
|
610
|
+
allow_low_info: {
|
|
611
|
+
type: 'boolean',
|
|
612
|
+
description: 'Skip the low-information guard and force VLM even on blank/simple images (default false).'
|
|
613
|
+
},
|
|
614
|
+
stop_after: {
|
|
615
|
+
type: 'boolean',
|
|
616
|
+
description: 'Stop the local llama-server after this call if this plugin started it (default false).'
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
required: ['file_path']
|
|
620
|
+
}
|
|
456
621
|
}
|
|
457
622
|
];
|
|
458
623
|
|
|
459
624
|
/** Render a structured tool result as the text block fed back to the model. */
|
|
460
625
|
async function renderResult(name, value) {
|
|
626
|
+
// vision_analyze has its own combined field
|
|
627
|
+
if (name === 'vision_analyze') {
|
|
628
|
+
return value.combined ?? value.message ?? JSON.stringify(value);
|
|
629
|
+
}
|
|
461
630
|
const core = await importCore();
|
|
462
631
|
const renderer =
|
|
463
632
|
name === 'image_scan' ? core.renderImageScan
|
|
@@ -571,7 +740,7 @@ export function runServer(input = process.stdin, output = process.stdout, log =
|
|
|
571
740
|
};
|
|
572
741
|
rl.on('line', onLine);
|
|
573
742
|
rl.on('error', onError);
|
|
574
|
-
log.write('picturereader MCP server ready (image_scan / image_ocr / image_sample)\n');
|
|
743
|
+
log.write('picturereader MCP server ready (image_scan / image_ocr / image_sample / vision_analyze)\n');
|
|
575
744
|
return () => {
|
|
576
745
|
rl.off('line', onLine);
|
|
577
746
|
rl.off('error', onError);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picturereader-zcode",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "ZCode plugin:
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "ZCode plugin: unified image understanding for text-only models. Fuses frame-free pseudo-multimodal reading (pixel scan + OCR + sample) with an optional external vision API bridge (LM Studio / llama-server / any OpenAI-compatible endpoint) for full semantic understanding. No extra plugin needed.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/core.js",
|
|
7
7
|
"exports": {
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
"paddleocr",
|
|
34
34
|
"hue",
|
|
35
35
|
"multimodal",
|
|
36
|
-
"mcp"
|
|
36
|
+
"mcp",
|
|
37
|
+
"vlm",
|
|
38
|
+
"vision-analyze",
|
|
39
|
+
"llm-vision"
|
|
37
40
|
],
|
|
38
41
|
"license": "MIT",
|
|
39
42
|
"author": "picturereader",
|
package/skills/image-reading.md
CHANGED
|
@@ -94,3 +94,26 @@ Gogomoe 知识框架分类,教训均来自对真实图片的实测复盘)。
|
|
|
94
94
|
→ 教训沉淀为 insight 4。
|
|
95
95
|
|
|
96
96
|
(新增经验会持续按以上分类沉淀进本 skill。)
|
|
97
|
+
|
|
98
|
+
## vision_analyze 统一工具
|
|
99
|
+
|
|
100
|
+
当需要一次性获取多种证据时,使用 `vision_analyze`:
|
|
101
|
+
- 自动检测空白/简单图片(低信息量拦截)
|
|
102
|
+
- 可选像素扫描(include_scan)
|
|
103
|
+
- 可选 OCR 文字识别(include_ocr)
|
|
104
|
+
- 可选 VLM 语义描述(include_vlm,需配置 SEE_BASE)
|
|
105
|
+
- 所有证据以文本形式返回,供主模型推理
|
|
106
|
+
|
|
107
|
+
### 推荐的工作流程
|
|
108
|
+
|
|
109
|
+
建议先用 `image_scan` 自己看,了解图片内容后再决定是否需要调用 VLM。简单图片用像素扫描就够了,复杂场景可以调用 VLM。
|
|
110
|
+
|
|
111
|
+
### 多次提问
|
|
112
|
+
|
|
113
|
+
对同一张图可以进行多次不同角度的提问,获取更全面的理解。
|
|
114
|
+
|
|
115
|
+
### 交叉验证
|
|
116
|
+
|
|
117
|
+
VLM 描述与像素/OCR 证据冲突时,以实测为准。
|
|
118
|
+
|
|
119
|
+
详细用法见 `skills/vision-analyze.md`。
|