Repository navigation
Releases: Whatsmore-nf/dsh-pdf-edit
Release list
v0.4.5
v0.4.5 (2026-08-25)
-
背景色采样替代白补丁(P0,视觉保真):native 直绘新增内容流背景采样——扫描页面填充矩形(含 pdf.js 分解的
re路径与 CMYK/灰度填充),按画家算法取补丁位置最上层背景色作为遮盖底色。彩色背景合同、带底纹证书上不再出现"白块";图片等无法采样的区域自动回退patchColor。新配置项autoPatchColor(默认开启)。纯 JS 实现,零浏览器依赖 -
tid 合并阈值自适应(P0,准确性):
mergeRuns不再硬编码 0.45/0.18 系数——按同页相邻文本项间隙中位数动态计算(合并上限 clamp [0.3, 0.8]、空格下限 clamp [0.1, 0.4]),学术双栏紧凑排版不再跨栏误合并,宽字距标题不再被拆散;显式传入maxGapFactor/spaceGapFactor时仍优先显式值(向后兼容) -
提取缓存 LRU 淘汰(P0):
extractCache加 20 页容量上限(LRU),500+ 页大文档编辑不再全量驻留内存导致 OOM 风险;新增通用LRUCache工具类 -
CID 字体乱码检测降级(P1):提取阶段检测私用区/U+FFFD 占比超 50% 的页面(Type0/CID 字体缺 ToUnicode CMap 的典型症状),记入
warnings提示该页 AI 编辑结果可能不可靠,不中断其余页面 -
字体解析结果 LRU 缓存(P1):
FontResolver.resolveA结果按「族 | 字重变体 | CJK/标准」缓存(128 条),批量applyPatches高频调用免重复解析 -
Background color sampling replaces white patches (P0, visual fidelity): Native rendering now samples the real background from the page content stream — it scans filled rectangles (including pdf.js-decomposed
repaths plus CMYK/gray fills) and picks the topmost fill covering each patch area (painter's algorithm). No more white blocks on colored-background contracts or textured certificates; areas that cannot be sampled (images, gradients) gracefully fall back topatchColor. New optionautoPatchColor(enabled by default). Pure JS, zero browser dependencies -
Adaptive tid merge thresholds (P0, accuracy):
mergeRunsno longer uses hardcoded 0.45/0.18 factors — thresholds are derived from the median gap between adjacent text items on the page (merge cap clamped to [0.3, 0.8], space threshold to [0.1, 0.4]). Compact two-column academic layouts no longer merge across columns, and wide-tracked headlines are no longer split apart. Explicitly configuredmaxGapFactor/spaceGapFactorstill take precedence (backward compatible) -
LRU eviction for the extract cache (P0):
extractCacheis now capped at 20 pages (LRU), eliminating the OOM risk when editing 500+ page documents where everyPageExtractused to stay resident; adds a reusableLRUCacheutility -
Garbled CID text detection (P1): Extraction now flags pages where Private Use Area / U+FFFD characters exceed 50% (typical symptom of Type0/CID fonts missing a ToUnicode CMap) via
warnings, instead of silently producing unreliable AI edits; other pages keep working -
LRU cache for font resolution (P1):
FontResolver.resolveAresults are cached by "family | weight variant | CJK/std" (128 entries), removing repeated resolution in high-frequencyapplyPatchescalls during batch edits
验证 / Verification
- 测试 +14(背景采样单测、彩色背景端到端补丁色断言、自适应阈值行为、LRU、乱码检测),全套 164 例通过
- +14 tests (bg sampling units, end-to-end patch-color assertions on colored backgrounds, adaptive thresholds, LRU, garbled detection); full suite 164 passed
v0.4.3
v0.4.3 (2026-08-25)
修复
parsePatchObject解析再加固:新增「按 JSON 解析错误位置截断」(tryParseJsonLenient)——模型在 JSON 值后附带任意说明文字(包括含{}/[]的尾注)都能正确解析出items,彻底解决pdf-edit-page/document线上偶发报Unexpected non-whitespace character after JSON
验证
- 新增 2 条回归测试(尾注含花括号/方括号、任意垃圾尾随),全套 150 例通过
v0.4.2
v0.4.2 (2026-08-25)
修复
- AI 精修(
pdf-edit-page/pdf-edit-document)在 LLM 返回「顶层 JSON 数组 + 尾部说明文字」时的解析失败(Unexpected non-whitespace character after JSON):parsePatchObject改为候选式容错解析——原样 / 花括号截取 / 方括号截取依次尝试,且只接受带items的候选(避免误吞数组内单对象)
验证
- 新增 2 条回归测试(数组+尾注、对象+尾注含花括号),全套 148 例通过
v0.4.1
v0.4.1 (2026-08-25)
修复(std 生态下 insert 与预览的体验问题)
- 标准字体 WinAnsi 崩溃:
inserter.drawLine对标准字体(WinAnsi)run 绘制前先过toWinAnsiSafe——−/—/ 弯引号等字符不再抛WinAnsi cannot encode(v0.3.0 潜在 bug,std 默认字体路径触发) pdf-edit-insert自动派生字体族:从fonts.customs取第 1 项为正文family、第 2 项为titleFamily;配置独立加粗字体时自动fakeBold:false,消除标题双绘导致的文本提取重复- preview 免 LLM:只读预览不再强制要求 LLM Key
新增
- std 宿主环境变量:
DSH_PDF_EDIT_FAKE_BOLD;DSH_PDF_EDIT_FONTS_CJK / _CUSTOMS / _FALLBACKS(化学式上下标回退在 std 宿主可用)
验证
- 全套 146 例测试通过;std 入口 end-to-end 输出与 cordis 直连一致(页数/几何/文本提取)
Fixes (std ecosystem – insert & preview UX)
-
Standard font WinAnsi crash fix:
inserter.drawLinenow appliestoWinAnsiSafebefore rendering runs with standard fonts (WinAnsi). Characters like−,—, and curly quotes no longer throwWinAnsi cannot encode(a potential v0.3.0 regression triggered by the std default font path). -
pdf-edit-insertauto‑derives font families: takes the 1st item fromfonts.customsas the bodyfamily, and the 2nd astitleFamily. When a dedicated bold font is configured,fakeBoldis automatically set tofalse, eliminating duplicate text extraction caused by double‑rendering of titles. -
Preview no longer requires LLM: read‑only preview no longer mandates an LLM Key.
New
- Std host environment variables added:
DSH_PDF_EDIT_FAKE_BOLD;
DSH_PDF_EDIT_FONTS_CJK/_CUSTOMS/_FALLBACKS(chemical formula sub‑/superscript fallback now available in std hosts).
Validation
- Full suite of 146 tests passed; std entry end‑to‑end output matches Cordis direct‑connect (page count / geometry / text extraction).
v0.4.0
适配 dsh-std Community v0.15 生态:本插件同时是标准生态插件与 cordis 直连插件。经 @dsh-std/adapter-dsh 等标准宿主装载时不再依赖任何 @deepseek-ai/* 官方包——未来 dsh 上游破坏性变更由 adapter 层单点吸收,插件免维护。
新增
- 静态清单
dsh-plugin.json(包根,manifestVersion: 0.15,组件 IDio.github.whatsmore-nf.dsh-pdf-edit):5 个工具以contributes["x-tools"]声明为tools.dsh/v1alpha1 Tool扩展;不声明任何 required 契约与权限 → 与任意 std 宿主协商即兼容 - 标准 FacetModule 入口
src/std/host.ts(编译为dist/std/host.js):activation 时发布 5 个本地ToolHandler(惰性 JSON Schema 参数/输出,execute返回{data, content});生命周期与清理走标准 activation scope - std 宿主环境变量配置:
DSH_PDF_EDIT_ALLOWED_ROOTS/_RENDER_MODE/_PROVIDER/_MODEL等 +DEEPSEEK_API_KEY,README 附完整对照表
变更
@deepseek-ai/dsh-toolspeerDependency 改为 optional:标准宿主下插件零官方包依赖;cordis 直连入口原样保留,缺包时报错带修复指引- 工具参数 schema 升级为标准 JSON Schema(顶层
required数组);工具实现函数(pdfEditPreview等)公开导出供两种入口复用
Adapted for the dsh-std Community v0.15 ecosystem:
This plugin now serves both as a standard ecosystem plugin and a Cordis direct‑connect plugin. When loaded via standard hosts such as @dsh-std/adapter-dsh, it no longer depends on any @deepseek-ai/* official packages – future breaking changes from the dsh upstream will be absorbed at the adapter layer, making the plugin maintenance‑free.
New
-
Static manifest
dsh-plugin.json(at package root,manifestVersion: 0.15, component IDio.github.whatsmore-nf.dsh-pdf-edit)
– 5 tools declared undercontributes["x-tools"]astools.dsh/v1alpha1 Toolextensions.
– No required contracts or permissions are declared → compatible with any std host through negotiation. -
Standard FacetModule entry
src/std/host.ts(compiled todist/std/host.js)
– On activation, it publishes 5 localToolHandlerinstances (with lazy JSON Schema parameters/outputs,executereturns{data, content}).
– Lifecycle and cleanup follow the standard activation scope. -
Std host environment variables configuration
–DSH_PDF_EDIT_ALLOWED_ROOTS/_RENDER_MODE/_PROVIDER/_MODELetc. plusDEEPSEEK_API_KEY– a full mapping table is provided in the README.
Changed
-
@deepseek-ai/dsh-toolspeer dependency changed to optional
– Under standard hosts, the plugin has zero dependency on official packages.
– The Cordis direct‑connect entry remains unchanged; when the package is missing, an error with fix instructions is shown. -
Tool parameter schemas upgraded to standard JSON Schema (with top‑level
requiredarray)
– Tool implementation functions (e.g.,pdfEditPreview) are now publicly exported for reuse by both entry points.
v0.3.1
v0.3.1 (2026-08-23)
工具层路径白名单体验修复
- 越界报错现在带出「当前允许的根目录」(
rootsText),用户一眼知道该对配置什么 - 5 个工具(page / document / relayout / preview / insert)支持按调用传
allowedRoots,与插件配置合并去重(withExtraRoots)——GUI 工作目录与 dsh 服务 cwd 不一致时无需改服务配置即可放行
pdf-edit-insert 支持 markdown 文本
insertions[].markdown直接传 md(# 标题 / - 要点 / 缩进子要点 / eq: 公式 / --- 分隔),内部经 parseMarkdownBlocks 解析,与 blocks 合并;blocks / markdown 至少提供一个
其他
- 测试 +4(path-guard 合并 / 报错信息 / 按调用放行),全套 137 例通过
v0.3.0
v0.3.0 (2026-08-23)
新增:往 PDF 里「补内容」能力(无需 LLM)
- 工具
pdf-edit-insert:把结构化内容(标题 + 文本块)作为新页插入指定页之后,自动排版(灰底横幅标题 / 正文 / 公式灰底框 / 跨页断页 / 页脚),原页零改动 - 编程接口
insertPages()/parseMarkdownBlocks()(src/inserter.ts)
字体
FontResolver新增字形覆盖与回退链:resolveRuns()/hasGlyph()/fonts.fallbacks—— 化学式上下标(₂₃⁺⁻ 等 Noto CJK cmap 缺失的字形)自动混排回退- 修复:回退字体不做 pdf-lib 子集化(FreeSans 等 CFF 字体子集化后字形整段空白)
- 系统 CJK 字体自动探测补充 wqy-zenhei / noto-cjk 路径
其他
- 测试新增 8 例,全套 133 例通过
v0.2.2
v0.2.2 — AI Agent 操作手册与编程接口开放
主要变更
- README 重构:人类可读内容(这是什么 / 安装 / 版本号)前置,AI Agent 操作手册后置,工作原理移至末尾。
- AI Agent 操作手册新增:直接暴露三个隐藏规则——
allowedRoots路径白名单、sanitizeText拒收空字符串、ctx.llm/DEEPSEEK_API_KEY依赖——并给出绕过方式。 - 新增
removeSubheadings():完整实现删除匹配小标题的包装函数(支持精确匹配 / 包含匹配,多页累积渲染),无需再手动操作applyPatches或drawPatchedPages。 - 关键方法公开:
StyleLockedEditor的getExtract、openNativeDoc、drawPatchedPages、mergeChanged由private改为public,AI Agent 可直接调用。
v0.2.1
v0.2.1
动态读取 DSH 默认模型,替换硬编码 agnes —— 零配置模型跟随。
- 通过
ctx.agentDefaultModel.currentSelection()获取用户当前配置的 provider/model - 优先级:用户配置 (
config.provider/config.model) > DSH 默认模型 > agnes 兜底 - 无论用户在 DSH 里用的是 deepseek、kimi、glm、minimax、openpangu、mino、claude、grok、gpt 等,插件都会自动跟随
Dynamically read DSH default model, replacing hardcoded agnes — zero-config model following.
- Use
ctx.agentDefaultModel.currentSelection()to get the user's current provider/model - Priority: user config (
config.provider/config.model) > DSH default model > agnes fallback - Whether the user is on deepseek, kimi, glm, minimax, openpangu, mino, claude, grok, gpt, etc., the plugin follows automatically