Study-Mate
Miaotofu01
你的AI学习搭档:定路线、讲知识、做项目,边学边做,学透一门科目
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:beiwei91/dsh-paper-reader
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
在 DeepSeek Harness(DSH)右侧栏新增一个「论文」标签页,把 PDF 论文当作可读、可标注、可对话的对象:连续滚动阅读、目录跳转、全文搜索、记忆阅读位置、Ctrl/Cmd + 滚轮缩放;八色高亮、下划线、页面文本框与边注徽标;一键生成结构化摘要提示词;把当前论文的批注导出为新的 PDF 副本;选中原文可引用到对话、让 agent 解释或翻译。也支持 arXiv 链接/ID 与关键词搜索直接打开论文;agent 通过四个只读工具(paper_info、paper_outline、paper_read、paper_search)读取当前会话里打开的那篇论文。扫描版 PDF 会在阅读器空闲时做文本级 OCR,识别文本进入逐页文本缓存,因此页内搜索、翻译和 paper_* 工具同样可用。
engines.dsh,也没有 npm 发布。dsh-paper-reader(来自 package.json.name,也是 bundle patch 的 name 字段);cordis 插件行 id = paper-reader(cordis.patch.yml 的 id);GitHub 仓库 = https://github.com/beiwei91/dsh-paper-reader。v0.2.0(本仓库树包含八色标注、下划线、文本框、页边距徽标、摘要提示词、批注 PDF 导出、最近打开、Ctrl/Cmd + 滚轮缩放等);更早的 v0.1.0 是已发布的预发布版本,其 tag/Release 保留、不再移动。npm 发布为未来可选项(unscoped 名 dsh-paper-reader 已被无关项目占用)。tesseract.js、tesseract.js-core、语言数据等)与批注导出用的 pdf-lib 栈(MIT)的第三方许可见 THIRD-PARTY-LICENSES.md。https://arxiv.org/abs/…、https://arxiv.org/pdf/…、裸 ID(如 1706.03762)与版本后缀(v2),也支持旧式 ID(如 cond-mat.mes-hall/0601001)。选中文字后出现工具条:八色调色板(4×2 排列)、引用、解释、翻译、复制。
调色板(Client 与 Host 共用同一份颜色白名单,旧的四色保持原有渲染):
| 颜色 | 色板 | 高亮填充 | 下划线 / 笔记徽标 |
|---|---|---|---|
yellow 黄 |
#ffd400 |
rgba(255,214,0,.35) |
#c9a100 |
green 绿 |
#3cc878 |
rgba(56,200,120,.35) |
#27995a |
blue 蓝 |
#5b9dff |
rgba(80,150,255,.32) |
#3b7bd8 |
pink 粉 |
#ff7ab4 |
rgba(255,120,180,.35) |
#d4568c |
orange 橙 |
#ff9f2e |
rgba(255,160,40,.35) |
#d97a12 |
purple 紫 |
#a07aff |
rgba(168,120,255,.35) |
#7c53d6 |
cyan 青 |
#2fc8dc |
rgba(60,200,220,.35) |
#1596a8 |
red 红 |
#f04646 |
rgba(240,80,80,.32) |
#c92b2b |
下划线工具(工具栏「下划线 / Underline」):开启后选中文字即直接加下划线(不弹工具条);画成 2 px 底线、无填充,和同一页+同一段引文锚定,点击可打开边注编辑器;工具栏下方有独立的八色选择条;Esc 退出该工具。
文本框工具(工具栏「文本框 / Text box」):开启后点击页面空白处即放置文本框并直接进入编辑;位置按页面宽高的比例(xPct / yPct)锚定,所以任何缩放级别下都停在同一位置、且不依赖文本层。Escape 或失焦即提交,内容为空则删除该文本框;靠近页面边缘时向页面内部生长。
文本框不可拖动(有意设计):页面上的拖拽是选文字手势,拖动会与选择冲突;要换位置请删除后重新放置。
边注徽标:有边注的高亮/下划线会在页面右侧页边距显示一个小圆点(颜色随标注),位置固定在该标注最后一行之外,不压住字形;点击圆点直接打开该边注。徽标随标注一起重画/移除。
高亮/下划线按「页 + 选中文本」锚定,绘制是字符级的:只覆盖真正选中的字符,而不是整行文本 run;高亮矩形在垂直方向做了内缩,相邻行的色块不会糊成一片(点击命中仍按实际绘制框)。下划线的点击热区是整行未裁剪的文本框(2 px 线本身太细)。
点击已画出的高亮/下划线可打开边注编辑器,写、改、删边注;文本框点击则编辑其内容。
笔记面板:每行按类型标注(高亮 · p.N · 摘要文字 — 边注、下划线 · …、文本框 · …)。点击一行会滚到该标注本身附近并打开编辑器(不是只跳到页顶),高倍缩放下同样成立;若缓存已失效、引文暂时定位不到,会等文本层重建,超时后才退化为跳到该页顶部。
标注按论文保存在本地,关掉再打开仍在。
存储模型:文件仍是 { key, highlights: [...] }(字段名与 /paper-reader/api/annotations 路由为兼容旧数据而保留),每个条目的 kind 为 'highlight' | 'underline' | 'text'。缺少 kind 或值未知的旧数据按 highlight 读取,旧标注因此自动沿用,不需要迁移步骤;未知颜色回退为黄色。高亮/下划线必须有 quote,文本框必须有 xPct/yPct 与非空 text。
工具栏的「摘要 / Digest」按钮会从阅读器已经知道的信息拼出一条结构化摘要提示词:
paper_info、paper_outline、paper_read、paper_search 读取论文,先看摘要/结论/目录,再按需精读。提示词一次性写入对话输入框(单次编辑器写入,不自动发送),由用户确认后自行发送。输入框不可用时回退到剪贴板,并用工具栏提示说明结果。
工具栏的「导出 / Export」把当前论文的全部标注画到原 PDF 的副本上并触发浏览器下载:
<论文名>.annotated.pdf(论文名为空时为 annotated.pdf;非法路径字符会被替换)。.annotated.pdf 只含高亮/下划线/文本框的可见图形,边注仍只保存在插件的标注数据里。src/client/pdf/exportPdf.ts)在按下按钮时才 import(),pdf-lib 及其依赖只在真正导出时执行;它们是 devDependencies,构建期被打进懒加载的 client.pdf.js,不新增任何 tarball 文件(pnpm pack 仍是 21 个文件),第三方许可证已相应更新。选中原文后的工具条提供:
请解释这段:)作为同一条消息写入输入框并立即发送。请把这段翻译成中文:)作为同一条消息写入输入框并立即发送(翻译目标固定为中文)。解释 / 翻译的引用块与指令是在同一次输入框写入里完成的,所以发送出去的消息始终同时包含「引用 + 出处 + 明确指令」,不会再出现只发引用、让 agent 自行猜测要解释还是翻译的情况。
扫描页没有文本层,原本页内搜索、翻译和 paper_* 工具都读不到内容。现在:
eng+chi_sim)识别,完全离线,运行时不需要任何 npm 依赖、也不访问网络。papers/<sha1>.text.json,记录 ocrPages),所以页内搜索、翻译和四个 paper_* 工具都能读到;paper_info 会报告 OCR 页数,paper_read 会在页头标注 [第 N 页 · OCR]。OCR n/m 进度;识别过的页按页缓存,重开论文不会重复识别。实测约 1.4–2.4 秒/页(本机、eng+chi_sim;取决于页面分辨率与机器)。注 意 力 → 注意力),否则多字词搜不到。四个工具只作用于当前会话里「论文」标签页打开的那篇论文,模型不需要路径:
| 工具 | 作用 |
|---|---|
paper_info |
标题、页数、有文本层的页数、OCR 页数(及已识别页码)、目录项数、已存标注数(含高亮/下划线/文本框;输出标签沿用「已存高亮」) |
paper_outline |
按层级缩进列出目录与页码,便于决定读哪几页 |
paper_read |
读取指定页范围的逐页文本;pages 支持 "3"、"3-7"、"all",默认前 3 页;maxChars 默认 12000、上限 30000;OCR 页标注为 [第 N 页 · OCR] |
paper_search |
在全文里搜关键词/短语,返回每页命中次数与上下文片段;maxResults 默认 20、上限 50 |
示例提问:
先用 paper_outline 看这篇论文的目录,再用 paper_read 读 1–3 页,用中文总结它要解决什么问题。
用 paper_search 找一下 "attention",告诉我在哪一页、上下文是什么。
读第 5–7 页,提炼实验设置(数据集、baseline、指标)。
用 paper_info 看一下这篇论文有多少页、文本层是否完整、扫描页识别了多少页。
注意:
本仓库是一个标准 DSH bundle(package.json 里声明 dsh.bundle.patch)。只通过 GitHub 分发(仓库 https://github.com/beiwei91/dsh-paper-reader,当前发布版本是 v0.2.0);npm 发布为未来可选项,见下方「npm(计划中)」。
版本说明:当前公开发布版本是
v0.2.0(package.json.version同为0.2.0);本文档描述的八色标注、下划线、文本框、页边距徽标、摘要提示词、批注导出、最近打开、Ctrl/Cmd + 滚轮缩放等功能都包含在该版本中,按下面的 commit / tag 方式安装即可。
包名 / loader 名与 GitHub 仓库同名(dsh-paper-reader,来自 package.json.name)。
需要本机 git 与 GitHub 网络。固定完整 40 位 commit 的 git 安装才可能被 plugin_manager 视为可更新安装:
# <40-hex> 来自:git rev-list -n1 v0.2.0
dsh plugin --profile <profile> add 'git+https://github.com/beiwei91/dsh-paper-reader.git#<40-hex>'
dsh plugin --profile <profile> add 'github:beiwei91/dsh-paper-reader#v0.2.0'
# 当注释。plugin_manager 的 install_bundle,target 填上面同一个 spec(例如 git+https://github.com/beiwei91/dsh-paper-reader.git#<40-hex>)。desktop profile 由桌面端管理,请用 Desktop 的 Plugins 设置或 agent 的 plugin_manager。dsh plugin --profile <profile> add 'https://github.com/beiwei91/dsh-paper-reader/releases/download/v0.2.0/dsh-paper-reader-0.2.0.tgz'
注意:pnpm 11.0–11.8 配合 DSH profile 的 hoisted 布局安装裸 Release 资产 URL 时可能报
ERR_PNPM_MISSING_TARBALL_INTEGRITY(11.9+ 正常)。优先用上面的 commit / tag 安装。
plugin_manager 的 install_bundle,target 填本仓库绝对路径。本地目录是链接安装:修改源码后需要重新构建并重新加载插件条目(关掉再打开该插件)。
dsh-paper-reader 这个 unscoped 名在 npm 上已被无关项目占用(rantz 1.5.0),所以现在没有可以直接 add 的 npm 包。未来若发布 npm,会改用 scope 名(如 @beiwei91/dsh-paper-reader)或另选未占用名字;在此之前请用上面的 GitHub 方式安装。
打开右侧栏 → 在引导页点「论文阅读器」卡片 → 打开「论文」标签页。
所有持久数据都在 DSH home($DSH_HOME,通常是 ~/.dsh)下,不写入用户工作区:
paper-reader/papers/<sha1>.pdf 论文字节(供 paper_* 工具、OCR 与重新打开使用)
paper-reader/papers/<sha1>.text.json 逐页文本缓存(OCR 文本也合并在这里,并记 ocrPages 标记)
paper-reader/annotations/<sha1>.json 标注({ key, highlights }:高亮、下划线、文本框与边注)
目录名沿用实现命名空间
paper-reader(历史原因),与包名 / loader 名dsh-paper-reader无关。
<sha1> 是论文 key 的 SHA-1:
drop:<文件名>:<大小>:<修改时间>;arxiv:<arXiv ID>。浏览器本地(localStorage)只保存三样小数据:dsh.paper-reader.tab.<tabId>(当前标签页打开的是哪篇)、dsh.paper-reader.pos.<key>(页码与缩放)与 dsh.paper-reader.recent(空状态里的最近打开列表,最多 12 条,只含 key/名称/可选路径/来源/打开时间)。目前没有界面内的数据清理入口,需要时手动删除 $DSH_HOME/paper-reader/ 或对应 localStorage 键。
https://export.arxiv.org/api/query(元数据 / 检索)与 https://arxiv.org/pdf/<id>(PDF 下载);请求带固定 User-Agent,PDF 抓取超时 45 秒,PDF 上限 32 MiB。eng/chi_sim 语言数据随 bundle 分发,识别时不联网、不加载 CDN。/paper-reader/api/*,不加载 CDN、字体、统计脚本或任何第三方资源。/paper-reader/api/* 只接受回环地址(127.0.0.1 / localhost / [::1]);写操作要求 Origin 是回环来源,Renderer 不带 Origin(或 Origin: null)时按回环 Host 放行,跨站 Origin 返回 403。OCR_QUEUE_LIMIT),滚动 / 跳页会按新的当前页继续排队,不会主动扫全篇;识别质量取决于扫描质量,双栏、倾斜、低分辨率可能漏字或错字;OCR 页不参与标注锚定,扫描页上不能选中、高亮、加下划线或放文本框;首次识别某页时 Host 可能要先整篇抽取一次文本,大文档会多等几秒。.annotated.pdf,但不能把批注从 PDF 导回插件;PDF 里只画高亮/下划线/文本框,边注正文不写入;加密 PDF 拒绝导出;引文在页文本层里定位不到时该条会被跳过(控制台警告,标注仍保留);没有标注时按钮禁用,无法导出一份「空批注」副本。$DSH_HOME/paper-reader/annotations/ 中的文件即等于删除对应论文的标注。docs/PUBLISHING.md、docs/README.draft.md、docs/OCR-VERIFICATION.md 是维护者文档:只留在 GitHub 仓库(源码归档可见),不随安装包 / Release tarball 分发,普通使用不需要它们。要求:Node.js(DSH 自身要求 ≥ 24.9)与 pnpm。
pnpm install
node build.mjs # -> client.js + client.pdf.js + lib/host.js + lib/pdf.worker.mjs + lib/ocr/*
pnpm typecheck # tsc -p tsconfig.json
产物:
| 文件 | 作用 |
|---|---|
client.js |
常驻客户端半:标签页注册、空状态(含最近打开)、arXiv 入口、标注存储接线、摘要提示词接线、对话动作 |
client.pdf.js |
懒加载 chunk:PDF.js 渲染、目录、全文搜索、高亮/下划线绘制、文本框层、笔记徽标、Ctrl/Cmd + 滚轮缩放、扫描页 OCR 队列,以及按需 import() 的批注导出(pdf-lib 在按下「导出」时才执行) |
lib/host.js |
Host 半:/paper-reader/api/* 路由、arXiv 抓取、OCR 路由、四个只读工具(内置 PDF.js 做文本抽取) |
lib/pdf.worker.mjs |
Host 侧 PDF.js 伪 worker,必须与 lib/host.js 同目录 |
lib/ocr/engine.cjs |
OCR 引擎入口(tesseract.js worker 工厂,bundle) |
lib/ocr/worker.cjs |
OCR worker 线程脚本(bundle,含 core 加载器) |
lib/ocr/engine-impl.cjs |
运行时引擎:串行化、超时、空闲回收、中文空格归一化 |
lib/ocr/tesseract-core-simd-lstm.wasm、lib/ocr/tesseract-core-lstm.wasm |
LSTM-only WASM core(SIMD / 无 SIMD 回退) |
lib/ocr/lang/eng.traineddata.gz、lib/ocr/lang/chi_sim.traineddata.gz |
best_int 英文 / 简体中文语言数据 |
说明:
构建产物是提交进仓库的(包内没有 prepack / prepare,从 git 安装与 Release tarball 都需要现成的 JS,安装方不需要本地构建)。
OCR 资源在构建期从 devDependencies(tesseract.js、tesseract.js-core、@tesseract.js-data/eng、@tesseract.js-data/chi_sim)复制 / 打包进 lib/ocr/,所以 pnpm install 后 node build.mjs 会一并产出;运行时零 npm 依赖、不联网。
批注导出模块是 src/client/pdf/exportPdf.ts;pdf-lib 是 devDependencies,build.mjs 在构建懒加载 chunk 时把它及其传递依赖打进 client.pdf.js,运行时同样零 npm 依赖、不联网。它不新增 tarball 文件:pnpm pack --dry-run 仍是 21 个文件;第三方许可证见 THIRD-PARTY-LICENSES.md。
客户端与宿主类型来自真实 DSH 包(devDependencies 固定到 0.2.2-rc.3),DSH 契约变化会直接变成类型错误。
DSH 的文件沙箱不允许生命周期脚本所需的管道式 spawn,所以 pnpm-workspace.yaml 把 esbuild 的构建脚本设为 false,并显式固定 @esbuild/win32-x64(Windows devDependency);当前构建在 Windows 上验证,其它平台构建前请先确认 devDependencies。
不开浏览器也能自查 OCR:
python scripts/ocr-fixture.py .build/ocr-fixture
node scripts/ocr-check.mjs .build/ocr-fixture/scan.png .build/ocr-fixture/scan.pdf
设计、实测耗时与资源体积见 docs/OCR-VERIFICATION.md。
src/client/index.tsx tab 类型、body、标题、引导页入口注册
src/client/PapersBody.tsx 空状态(路径/拖拽/arXiv 搜索/最近打开)、按标签页恢复论文、摘要提示词接线、标注与对话动作接线
src/client/annotations.ts 按论文的标注 store(单飞队列写、失败可见可重试、离开时 keepalive flush)
src/client/annotationQueue.ts 标注保存队列:单飞、合并、有界重试、teardown keepalive(可无浏览器测试)
src/client/pdf/chunk.tsx 阅读层:渲染窗口、目录、全文搜索、选区工具条、下划线/文本框工具、笔记、徽标、缩放、导出入口、OCR 队列接线
src/client/pdf/marks.ts 按「页 + 文本片段」把高亮/下划线画回重建后的文本层(字符级、行间内缩)
src/client/pdf/exportPdf.ts 批注导出:测量页面、把标注画进 PDF 副本、栅格化文本框、触发浏览器下载(pdf-lib 懒加载)
src/client/ocr/queue.ts 扫描页 OCR 队列(空闲时逐页、当前页优先、有界、可取消)
src/client/ocr/raster.ts 扫描页栅格化与「页是否有文本层」的探测
src/host/index.ts Host 入口:/paper-reader/api/*(含 OCR)、工具注册
src/host/{arxiv,store,text,tools}.ts arXiv 抓取、落盘、文本抽取与 OCR 合并、四个只读工具
src/host/ocr/* OCR 引擎(串行 worker、超时、空闲回收)与构建期 worker 入口
src/shared/annotationModel.ts 标注 `kind` / 八色白名单与两侧共用的规范化(旧数据迁移点)
scripts/ocr-{fixture.py,check.mjs} 无浏览器的 OCR 复现自查
scripts/annotation-save-test.cjs 无浏览器的标注保存队列自查
SECURITY.md 的渠道私密报告。LICENSE);随包分发的 PDF.js 为 Apache-2.0,批注导出所用的 pdf-lib 栈为 MIT,第三方许可证与修改声明见 THIRD-PARTY-LICENSES.md。Paper Reader adds a Papers tab to the DSH right sidebar. Open local PDFs by drag-and-drop or absolute path, an arXiv link/ID, or arXiv keyword search; a recently-opened list in the empty state reopens up to 12 papers from the Host's stored bytes (falling back to the original path). Read with continuous scrolling, outline jumps, whole-paper search, a remembered position, Ctrl/Cmd + wheel zoom anchored at the cursor (0.25–4×, plain wheel still scrolls) and horizontal scrolling for zoomed-in wide pages. Annotate with eight highlight colours, an underline tool (2 px bottom stroke, no fill) and text boxes (fraction-of-page anchoring, stay put at any zoom); margin badge dots mark annotations with notes, the notes list labels each row by kind, and jumping to an annotation scrolls to the mark itself. The toolbar's Digest button builds a structured digest prompt (paper facts + instructions to use paper_info/paper_outline/paper_read/paper_search, with problem/method/contributions/experiments/limitations/reproducibility sections) and writes it into the composer as one draft — never auto-sent, with a clipboard fallback. The Export button writes every annotation into a new annotated PDF copy (<name>.annotated.pdf) and downloads it: highlights as translucent rectangles, underlines as 2 pt lines, text boxes rasterised CJK-safely and embedded, rotated pages handled. The original PDF is never modified, and margin-note bodies are deliberately not written into the PDF. Quote a selection into the conversation or ask the agent to explain/translate it. Four read-only agent tools (paper_info, paper_outline, paper_read, paper_search) read the paper currently open in the session — no path needed.
Scanned PDFs get text-level OCR: pages without a text layer are rasterised in the reader when it is idle, recognised on the Host with a bundled, fully offline tesseract.js (eng+chi_sim), and merged into the same per-page text cache, so in-document search, translation and the agent tools work. OCR pages get no text layer, so they cannot be selected or annotated. A rolling queue of about 30 pages is filled around the current page per session, results are cached per page, and measurement showed roughly 1.4–2.4 s per page.
Data lives under $DSH_HOME/paper-reader/ (paper bytes, extracted-text cache including OCR text, annotations as { key, highlights } with per-entry kind), plus small localStorage pointers for the open paper, reading position and the recent-papers list. The only outbound network traffic is the Host fetching from arXiv (export.arxiv.org, arxiv.org); OCR and the annotated-PDF export are fully local. The browser talks only to the loopback-only, same-origin /paper-reader/api/* routes. No telemetry.
Known limitations: page 1's size is used as a placeholder before a page renders; highlights/underlines are anchored by page + text and cross-page selections are rejected; duplicated text on a page is marked at its first occurrence only; moving/renaming a local PDF detaches its annotations; text boxes cannot be dragged (by design), existing marks cannot be recoloured or moved, and there is no freehand pen; switching right-sidebar tabs releases the PDF after about 1.5 s and reloads it from the Host's stored bytes; a 32 MiB file cap; the first selection drag on a page builds its text layer and takes a moment; scanned pages cannot be selected or annotated, OCR quality depends on the scan, and the rolling queue never scans a whole document automatically; export is one-way (no importing annotations back), margin notes are not embedded in the PDF, encrypted PDFs are refused, and unlocatable marks are skipped.
Install from GitHub: dsh plugin --profile <profile> add 'git+https://github.com/beiwei91/dsh-paper-reader.git#<40-hex>' (pin the commit for updatable installs; github:beiwei91/dsh-paper-reader#v0.2.0 also installs, and a local directory can be linked for development). v0.2.0 is the current release. The package/loader name and the GitHub repository are both dsh-paper-reader. An npm release is not possible under this unscoped name (already taken); a scoped package may follow. Development: pnpm install && node build.mjs && pnpm typecheck. License: MIT; bundled PDF.js is Apache-2.0 and the export's pdf-lib stack is MIT (see THIRD-PARTY-LICENSES.md). Repository: https://github.com/beiwei91/dsh-paper-reader.
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: 论文。