360 Secure SkillHub
360 安全技能中心

File Diff

核心功能是对比两个文件差异,通过执行带-u参数的diff命令解析输出,整理为清晰的Markdown格式,标注增删内容及对应行号。典型场景为查看文件版本差异、比较文档异同,触发词含“比较文件”“diff”等。输入为指定文件路径的diff命令,输出含文件路径、差异位置及带颜色标识的增删内容。

super9du
super9du
热度 42.39
最近更新 2026-05-11 17:41:45
分类:效率依赖:代码执行 / 读写文件应用场景:摘要总结 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add file-diff
Metadata
name
file-diff
description
Compare two files and display their differences in a human-readable markdown format. Use when asked to "compare files", "show diff", "compare differences", "diff two files", or any request to analyze file differences. Triggers on phrases like "比较文件"、"比较异同"、"diff"、"show me the differences".

File Diff

Compare two files and display differences in a clean, readable markdown format.

Usage

Quick Compare (Two file paths)

diff <source_file> <target_file>

Unified Diff Format (Recommended)

diff -u <source_file> <target_file>

Output Format

The diff output is formatted as:

**File A**: `/path/to/file1`
**File B**: `/path/to/file2`

## Differences

### 1. [Section/Line description]
```diff
- removed line
+ added line

## Workflow

1. Identify the two files to compare
2. Run `diff -u` command
3. Parse the unified diff output
4. Format into readable markdown with:
   - File paths as headers
   - Line numbers from diff output
   - `-` prefix for removals (red)
   - `+` prefix for additions (green)
   - Context lines for clarity

## Example

Input:
```bash
diff -u /tmp/original.txt /tmp/modified.txt

Output format:

**File A**: `/tmp/original.txt`
**File B**: `/tmp/modified.txt`

## Differences

### Line 5
```diff
- old content
+ new content

## Notes

- Always use `-u` flag for unified format (more readable)
- Include both file paths in the output
- Preserve all changes including additions, deletions, and modifications