dsh-local-ocr
一个独立的本地 OCR library 和 DeepSeek Harness 工具插件,面向 macOS 和 Windows。它不会修改 deepseek-harness,不负责缓存,也不决定什么时候应该调用 OCR。
底层适配器使用开源的 @napi-rs/system-ocr,通过统一的 Node.js API 调用 macOS 系统 OCR 和 Windows Media OCR。其 native 实现参考了 win-ocr-rs 和 mac-system-ocr。
安装
要求:Node.js 20 或更高版本、pnpm,以及已经安装并可执行的 DeepSeek Harness dsh 命令。
直接从 GitHub 将插件安装到 Web profile:
npx -y github:littlewrite/dsh-local-ocr install安装器会把 bundle 加入指定的 Harness profile。安装完成后重启 dsh web。指定其他 profile:
npx -y github:littlewrite/dsh-local-ocr install --profile web卸载:
npx -y github:littlewrite/dsh-local-ocr uninstall --profile web如果要进行本地开发,可以克隆仓库并安装依赖:
git clone https://github.com/littlewrite/dsh-local-ocr.git
cd dsh-local-ocr
pnpm install当前 native 依赖支持 macOS 和 Windows。Linux 暂不属于本 MVP 的支持范围。
DeepSeek Harness 插件
bundle 会加载 dsh-plugin/index.js。它注册一个面向模型的工具 local_ocr_image,但不会在 Harness 启动时加载 native OCR addon;只有模型真正调用工具时才会加载。
然后从 Harness 仓库正常启动:
cd /path/to/deepseek-harness
pnpm dsh web从源码 checkout 加载插件时,默认要求 Harness 仓库是当前工作目录。如果由其他 launcher 或打包后的 Harness 加载,可以设置 DSH_HARNESS_ROOT 指向 Harness 安装目录。
让 agent 使用绝对路径调用 OCR:
请调用 local_ocr_image 工具,不要调用 read_image。
读取:
/absolute/path/to/image.pngLibrary API
import { createOcrService } from './src/ocr.js'
const ocr = createOcrService()
const result = await ocr.recognize({
path: '/tmp/image.png',
languages: ['zh-cn', 'en-US'],
mode: 'accurate',
signal,
})返回值只包含稳定字段:
{
"text": "recognized text",
"confidence": 0.8,
"engine": "darwin-system-ocr",
"durationMs": 12
}图片中没有可识别文字时,返回空的 text 和 confidence: 0。如果需要保留 native 的无文字错误,可以设置 emptyWhenNoText: false。
开发
pnpm test测试使用 fake engine 注入,不要求当前机器具备 OCR runtime。native smoke test 需要分别在支持的操作系统上运行。