M AI 员工技能商店
AI 员工平台 返回商城
返回技能商店

小紫 文本对比插件

v1.0.0 · 数据处理 · 官方

文本对比 diff patch 相似度 数据处理 小紫

简介

小紫 文本对比插件 v1.0,AI 帮你对比文本差异:

  • compare 两段文本对比,返回相似度与差异摘要
  • files 两个文件对比,支持 unified / ndiff 格式
  • patch 生成 unified diff patch 文件
  • 无需 pip,Python 标准库 difflib
  • Win / macOS / Linux 通用

适用:文档版本对比、配置变更检查、代码/日志 diff、生成 patch。

典型流程:files 看差异摘要 → format unified 看详细 diff → patch 导出变更文件

操作说明

action功能
compare对比 text_a 与 text_b
files对比 filepath_a 与 filepath_b
patch生成 unified diff,可写 output 文件

format 参数:

  • summary(默认):相似度 + changes 变更块列表
  • unified:标准 unified diff 输出
  • ndiff:逐行 +/-/? 标记

其他参数:

  • context unified 上下文行数,默认 3
  • ignore_whitespace 忽略行尾空白
  • encoding 文件编码 utf-8/gbk
  • max_lines 限制 diff 返回行数(防超长)
  • output patch 保存路径

安装

  1. 解压到 D:\xiaozi-plugins\数据处理\文本对比插件\
  2. 复制 python/ 到本目录
  3. 测试:run.bat --action compare --text_a "hello" --text_b "hello world"
文件说明
diff_plugin.py主程序
run.bat / run.sh启动脚本
文本对比插件.md用户文档
config/diff_config.example.json配置示例
无需 pip,标准库即可。

命令行

run.bat --action compare --text_a "版本A内容" --text_b "版本B内容"
run.bat --action files --filepath_a D:\docs\old.txt --filepath_b D:\docs\new.txt
run.bat --action files --filepath_a D:\a.txt --filepath_b D:\b.txt --format unified
run.bat --action patch --filepath_a D:\old.txt --filepath_b D:\new.txt --output D:\changes.patch

注册技能 diff_tool

名称: diff_tool

描述: 文本对比 v1.0。compare/files/patch对比文本或文件、返回相似度和diff、生成patch。用户对比文档版本、看改了什么时使用。compare需text_a和text_b;files/patch需filepath_a和filepath_b。

脚本: D:\xiaozi-plugins\数据处理\文本对比插件\run.bat

参数 JSON:

{
  "type": "object",
  "properties": {
    "action": {"type": "string", "enum": ["compare", "files", "patch"], "description": "操作类型"},
    "text_a": {"type": "string", "description": "compare文本A"},
    "text_b": {"type": "string", "description": "compare文本B"},
    "filepath_a": {"type": "string", "description": "文件A路径"},
    "filepath_b": {"type": "string", "description": "文件B路径"},
    "format": {"type": "string", "description": "summary/unified/ndiff"},
    "context": {"type": "string", "description": "上下文行数"},
    "ignore_whitespace": {"type": "string", "description": "忽略空白"},
    "encoding": {"type": "string", "description": "文件编码"},
    "max_lines": {"type": "string", "description": "diff最大行数"},
    "output": {"type": "string", "description": "patch输出路径"}
  },
  "required": ["action"]
}

对话示例

场景说法
比文本对比这两段文字有什么不同
比文件比较 v1.txt 和 v2.txt 的差异
相似度这两个文件相似度多少?
生成 patch生成 old 到 new 的 diff patch
看详细用 unified 格式对比 a.txt 和 b.txt

常见错误

现象处理
缺参数compare 需 text_a/b;files 需 filepath_a/b
文件不存在检查路径
乱码试 encoding gbk
diff 太长max_lines 限制
python folder missing复制 python

能力边界

支持不支持
文本/纯文本文件二进制/Word/PDF 内部 diff
unified/ndiff/patch三方 merge
相似度统计目录级对比

与其他插件配合

  • json_tool:格式化后对比 JSON
  • csv_tool:导出 CSV 后 diff
  • log_analyzer:配合日志变更分析

详见包内 文本对比插件.md。