小紫 文本对比插件
v1.0.0 · 数据处理 · 官方
简介
小紫 文本对比插件 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:逐行 +/-/? 标记
其他参数:
contextunified 上下文行数,默认 3ignore_whitespace忽略行尾空白encoding文件编码 utf-8/gbkmax_lines限制 diff 返回行数(防超长)outputpatch 保存路径
安装
- 解压到
D:\xiaozi-plugins\数据处理\文本对比插件\ - 复制
python/到本目录 - 测试:
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。