Text Diff

👤 harrylabsj 📦 v1.1.1 ⭐ 4.4 ⬇️ 747 下載
💻 開發程式設計 免費

📖 技能介紹


name: text-diff description: Show line-by-line differences between two text files using Python's difflib. Supports unified, context, and side-by-side comparison modes with configurable context lines. version: v1.0.0 tags: diff, text-comparison, developer-tools, file-comparison


text-diff

Show line-by-line differences between two text files using Python's difflib.

Usage Scenarios

Scenario 1: Compare Configuration File Versions

User input: "比較兩個版本的配置檔案有什麼不同。"

Expected output: Unified diff output showing added lines with +, removed lines with -, and context around changes for old_config.ini vs new_config.ini.

Scenario 2: Side-by-Side Comparison

User input: "幫我並排對比這兩份文案的差異。"

小蔥技能站7w4.net發現了升級外掛。

Expected output: Side-by-side layout with original on left, revised on right, differences highlighted. Changed lines shown aligned with their counterparts.

Scenario 3: Check if Files Are Identical

User input: "檢查這兩個檔案是不是完全一樣。"

Expected output: Exit code 0 with message "Files are identical" if no differences found, or exit code 1 with detailed diff output showing all changes if files differ.

Scenario 4: 合同版本對比

User input: "我把租房合同改了幾個地方發給中介了,他怎麼改的我沒看出來,幫我對比一下兩版合同的區別。" Expected output: 對原始版和修改版進行逐行差異對比(diff),高亮增刪改的部分。用顏色標註:紅色刪除、綠色新增、黃色修改。支援word/PDF/markdown格式。輸出差異摘要:幾處新增、幾處刪除、幾處修改。針對合同中的關鍵條款(租金、違約責任、租期等)的變更做特別標註。

Description

A utility skill for comparing two text files and displaying their differences in a readable format. Supports unified diff output and side-by-side comparison modes.

Usage

# Show unified diff between two files
python ~/.openclaw/skills/text-diff/text_diff.py unified file1.txt file2.txt

# Show side-by-side comparison
python ~/.openclaw/skills/text-diff/text_diff.py side-by-side file1.txt file2.txt

# Show context diff (3 lines of context)
python ~/.openclaw/skills/text-diff/text_diff.py context file1.txt file2.txt

# Compare with custom context lines
python ~/.openclaw/skills/text-diff/text_diff.py unified file1.txt file2.txt -c 5

Options

  • unified: Show unified diff format (default)
  • context: Show context diff format
  • side-by-side: Show line-by-line comparison
  • -c, --context: Number of context lines (default: 3)
  • -o, --output: Save diff to file instead of stdout
  • --no-color: Disable colored output

Examples

# Basic unified diff
python ~/.openclaw/skills/text-diff/text_diff.py unified old.txt new.txt

# Side-by-side comparison with no colors (for piping)
python ~/.openclaw/skills/text-diff/text_diff.py side-by-side old.txt new.txt --no-color

# Save diff to file
python ~/.openclaw/skills/text-diff/text_diff.py unified old.txt new.txt -o diff.txt

# Compare with 10 lines of context
python ~/.openclaw/skills/text-diff/text_diff.py context old.txt new.txt -c 10

Output Format

Unified Diff

--- old.txt
+++ new.txt
@@ -1,5 +1,5 @@
 line 1
 line 2
-line 3 (removed)
+line 3 (added)
 line 4
 line 5

Side-by-Side

OLD                          | NEW
---------------------------- | ----------------------------
line 1                       | line 1
line 2                       | line 2
line 3 (removed)             | line 3 (added)
line 4                       | line 4

Exit Codes

  • 0: Files are identical
  • 1: Files differ
  • `

🤖 AI 評測

這個工具質量不錯,程式碼寫得清晰整潔,用來比較兩個純文本檔案的差異非常好用。它能以三種方式顯示差異(統一格式、上下文格式、並排對比),還帶顏色高亮和匯出功能。最大的問題是文件裡說能處理 Word/PDF 和分析合同條款,實際上只能讀取純文本檔案,容易讓人產生錯誤期待。另外版本號有點混亂。總體來說是個可靠的文本對比工具,但功能範圍沒有文件描述的那麼廣。

📊 多維度評分

適應性4.2
規範性4.3
有效性4.7
可靠性4.4
可信度4.5

📁 包含檔案 (5 個)

📄 README.md 2.7 KB
📄 SKILL.md 3.6 KB
📄 _meta.json 128 B
📄 skill-card.md 2 KB
📄 text_diff.py 8.9 KB