Skip to main content

dsh-tool-diff/packages/dsh-tool-diff

24Stars1Forks1Issues0Watchers

Implements diff generation and comparison for text or data structures, aiding change analysis.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki

ⓘ This plugin is a sub-package of the omdsh-dev/dsh-toolkit monorepo — stars and activity count the whole repository.

Language
TypeScript
License
MIT
Branch
main
collectiondshdsh-plugintoolkitzero-dependency

Install

cmdweb profile
$ dsh plugin --profile web add github:omdsh-dev/dsh-toolkit#path:packages/dsh-tool-diff

Run the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial

Install via your agent

Install the DeepSeek Harness plugin omdsh-dev/dsh-toolkit/packages/dsh-tool-diff for me: review the repository at https://github.com/omdsh-dev/dsh-toolkit first, then run the install command and verify the plugin loads successfully.

Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.

一句话定位

给 DSH Agent 提供一个零依赖的结构化差异比较工具,让 Agent 不用每次都起 bash 进程调用系统 diff,也能对 JSON/CSV/Markdown 做路径级、列级、块级的变更分析。

核心能力

  • text action:行级 Myers diff,输出标准 unified diff(---/+++/@@)与行号化操作列表
  • json action:递归比较两个 JSON 值,输出 $.path 形式的 add/remove/replace(支持 $.user.name、$.items[0]、$['a.b'])
  • csv action:RFC 4180 解析后按主键或行号位置比较,报告 addedRows / removedRows / changedRows(列级)/ duplicateKeys
  • markdown action:识别标题重命名、块路径(如 h2[1]/p[0]),代码块的语言/行数/内容变更单独进 codeBlockChanges
  • patch action:在内存中生成 unified patch 并按 hunk 坐标验证能否应用到 before,校验 valid/targetMatchesAfter,绝不落盘

技术实现

  • 语言: TypeScript(零运行时依赖,编译产物 lib/index.js)
  • 关键依赖: @deepseek-ai/cordis(Cordis 服务注册)、@deepseek-ai/dsh-tools(defineTool 工厂)、@deepseek-ai/dsh-invariants(invariants 服务的 companion 占位)
  • 架构模式: cordis 插件,通过 cordis.patch.yml 在 profile layer stack 插入 row(id tool-diff);apply(ctx) 中调用 ctx.tools.register(defineTool(...)) 注册工具;同时导出 diff-invariant companion 插件登记 invariant 所有权
  • 入口文件: src/index.ts(导出 name/inject/apply),各算法分文件 text-diff.ts / json-diff.ts / csv-diff.ts / markdown-diff.ts / patch.ts / limits.ts

适用场景

Agent 拿到"对比这两段内容"任务时(配置文件片段 diff、API 响应前后变化、表格行变更、Markdown 文档修订、生成可应用的 patch 又不希望落盘),调用 diff 工具一次返回结构化 JSON 报告,省去每次起 bash 进程,也避免手写对引号内逗号/嵌套数组/标题重命名这些边界条件容易出错的比较代码。

前置依赖与兼容性

依赖最低版本说明
DSH>= 0.1.0-rc.8已在 npm @deepseek-ai/[email protected] 隔离 consumer 完成全链路验证
Node^22.19.0 或 >=24.0.0package.json engines.node
Peer 依赖cordis ^4.0.1 / dsh-tools / dsh-invariants由 profile 层自动治愈安装
原生模块无纯 JS,零运行时依赖
平台跨平台不读文件、不联网、不调 git;Windows/macOS/Linux 表现一致

安装方式

dsh plugin --profile web add github:omdsh-dev/dsh-toolkit/packages/dsh-tool-diff

配置项

本插件没有全局配置文件,所有行为都通过工具调用参数控制:

配置类型说明默认值
action必填字符串选择比较模式:text / json / csv / markdown / patch无
before必填字符串原内容文本(任何 action 的输入侧)无
after必填字符串新内容文本无
format字符串输出格式:unified(text/patch 默认)/ structured(json/csv/markdown 默认)/ both按 action 而定
context0..20 整数unified diff 每段上下文行数3
key字符串CSV 主键列名或 1-based 列下标;不传则按行号位置比较不传 → 位置模式
delimiter字符串CSV 字段分隔符,单字符或 tab,
ignoreWhitespace布尔比较时忽略空白差异(patch action 主动拒绝)false
ignoreCase布尔比较时忽略大小写(patch action 主动拒绝)false
sortKeys布尔JSON 键排序后再比较和输出,变更列表稳定可复现true
maxChanges1..10000 整数单次最多报告多少变更;超出按字节二分截断1000

常见问题

Q: 安装后注册了什么工具,能在哪些命令里看到?

A: 在 profile layer stack 里加一条 row id 为 tool-diff 的工具(tool 名为 diff),并附带 diff-invariant companion。dsh --profile web --dump-config | grep tool-diff 应该能输出这一行;headless profile 需要单独再装一次。

Q: 为什么不直接调 bash 或系统 diff?

A: 系统 diff 每次调用都会 fork 一个 bash 子进程(Windows 上尤其贵),且它只懂行级文本:JSON 只能给整段对比,看不到 $.user.name 这种路径级变更;CSV 不知道列对应关系。本插件是纯函数 + 零依赖,一次函数调用返回结构化 JSON。

Q: patch action 会不会真的去改文件?

A: 不会。patch 只在内存里把 hunks 应用到 before 行数组并与 after 逐行比对,输出 valid / targetMatchesAfter / errors。绝不调 git apply、不写文件、不联网。

Q: 输入文件特别大,是不是得先用 shell 切一下?

A: 单侧输入有 256 KiB 硬顶,行数 ≤ 50K,JSON 嵌套 ≤ 64 层,CSV ≤ 50K 行 / 512 列。超限工具层直接报错。输出整体不超过 64 KiB,超出会按 maxChanges 与字节预算二分截断并把 truncated 设为 true。

Q: CSV 里有中文表头、字段内含逗号或换行,能正确比对吗?

A: 能。解析按 RFC 4180:"" 转义、CRLF/BOM、引号内换行都已处理。分隔符可传 tab;不传 key 时按行号位置比,传列名后按主键匹配(keyed 模式下行顺序无关)。

Q: 重复 key 的 JSON 会被静默吞掉吗?

A: 不会。解析时遇到重复 key 由状态机扫描并在结果里以 duplicateKeys.before / duplicateKeys.after 分侧报告,同时把 equal 设为 false,不丢信息。

Q: web profile 装了,为什么 dsh run 调不到?

A: web 和 headless 是两个独立 profile,web 不会自动覆盖 headless。dsh run 默认走 headless profile,所以 headless 那侧也需要 dsh plugin --profile headless add ... 装一次。

Q: 怎么确认这个工具真的能跑?

A: 装完后跑 dsh run "用 diff 工具对比两段文本,让 AI 触发一次调用"。或者直接看 dsh --profile web --dump-config 里有没有 tool-diff 这一行。

上手难度

入门 — 不需要任何额外配置文件或环境变量,只要按 action/before/after 三个必填参数调用即可;所有可选参数都有合理默认值。

已知问题与限制

  • 单侧输入 ≤ 256 KiB、最终 JSON 输出 ≤ 64 KiB,超出会按 maxChanges 与字节二分截断或在入口直接报错
  • 行数 ≤ 50K、JSON 嵌套 ≤ 64 层、CSV ≤ 50K 行 / 512 列;超出直接拒绝
  • 单次执行硬超时 2000 ms(timeoutMs: 2000),Myers diagonal 预算 2000、蛇步总预算 2000 万
  • patch action 主动拒绝 ignoreWhitespace 和 ignoreCase(精确文本协议),归一化比较请用 text action
  • CSV 若 before 或 after 任一侧存在重复主键,结果 equal 一定为 false,且重复行不参与匹配(行为确定性,避免错配)
  • 孤立 Unicode surrogate 会在入口被拒绝(invalid Unicode),避免序列化阶段产生不一致
  • 工具参数会写入会话日志,调用方不要传入密码、token 等敏感凭据

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](https://deepseek-plugin.org/plugins/omdsh-dev/dsh-toolkit/packages/dsh-tool-diff)

Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.

← Back to plugin directory