
أداة سطر أوامر بلغة Rust تكتشف مستودعات Git بشكل متكرر، وتلتقط تغييرات الحالة، وتُولد الفروقات، وتستخرج عناصر الكود مع مقتطفات كاملة، وتُنتج تقارير تركز على الأمان لسير عمل مراجعة الكود والتدقيق.
إذا كان هذا المشروع يساعدك في عملك، فادعم الصيانة المستمرة والميزات الجديدة.
محفظة التبرع (ETH)
0x11282eE5726B3370c8B480e321b3B2aA13686582
امسح رمز QR أو انسخ عنوان المحفظة أعلاه.
أداة سطر أوامر بلغة Rust تكتشف مستودعات Git بشكل متكرر، وتلتقط تغييرات الحالة، وتنشئ الفروق، وتستخرج عناصر الكود مع مقتطفات كاملة، وتنتج تقارير موجهة للأمان لسير عمل مراجعة الكود والتدقيق.
لماذا لا تستخدم bash فقط؟
سطر واحد مثل
ls | while read line; do git -C "$line" diff HEAD~1 HEAD || true; doneيُظهر الفروق الخام فقط. يضيف DiffCatcher اكتشافًا متكررًا، واستخراج عناصر الكود، واكتشاف الأنماط الأمنية، ومخرجات SARIF للتكامل المستمر/النشر المستمر، ومعالجة متوازية، وتجميع أمني عبر المستودعات. انظر المقارنة الكاملة أدناه.
git clone https://github.com/Teycir/DiffCatcher.git
cd DiffCatcher
cargo build --release
./target/release/diffcatcher --help
# Scan all repos in a directory (fetch-only, no modifications)
diffcatcher ~/projects
# Pull updates and generate security report
diffcatcher ~/projects --pull -o ./report
# Diff two branches in a single repo (PR review mode)
diffcatcher ./my-repo --diff main..feature/auth -o ./pr-report
# Generate SARIF output for GitHub Code Scanning
diffcatcher ~/projects --summary-format sarif,json -o ./report
# Dry run to see what would be scanned
diffcatcher ~/projects --dry-run
# Fast scan with 8 parallel workers
diffcatcher ~/projects -j 8 --quiet
# Scan with default settings (fetch-only)
diffcatcher <ROOT_DIR>
# Custom output directory
diffcatcher ~/projects -o ./my-report
# Include nested repos and follow symlinks
diffcatcher ~/projects --nested --follow-symlinks
# Skip hidden directories
diffcatcher ~/projects --skip-hidden
# Fetch only (default - no working tree changes)
diffcatcher ~/projects
# Actually pull changes
diffcatcher ~/projects --pull
# Force pull with stash/pop for dirty repos
diffcatcher ~/projects --pull --force-pull
# Use rebase strategy
diffcatcher ~/projects --pull --pull-strategy rebase
# Skip fetch/pull entirely (historical diffs only)
diffcatcher ~/projects --no-pull
# Skip element extraction (raw diffs only)
diffcatcher ~/projects --no-summary-extraction
# Extract elements but skip code snippets
diffcatcher ~/projects --no-snippets
# Adjust snippet context and limits
diffcatcher ~/projects --snippet-context 10 --max-snippet-lines 300
# Limit elements per diff
diffcatcher ~/projects --max-elements 1000
# Skip security tagging
diffcatcher ~/projects --no-security-tags
# Include test files in security analysis
diffcatcher ~/projects --include-test-security
# Use custom security patterns
diffcatcher ~/projects --security-tags-file ./custom-patterns.json
يمكن لـ DiffCatcher تحميل التكوين المحلي للمشروع تلقائيًا من:
<ROOT_DIR>/.diffcatcher.toml (افتراضي)--config <FILE>--no-configمثال:
output = "reports-local"
no_pull = true
history_depth = 2
summary_formats = ["json", "txt"]
no_security_tags = false
[plugins]
security_pattern_files = ["plugins/security-extra.json"]
extractor_files = ["plugins/extractors.json"]
لا تزال أعلام سطر الأوامر تتجاوز قيم التكوين عند ضبطها صراحةً.
يدعم DiffCatcher نوعين من الإضافات:
--security-plugin-file <FILE> (قابل للتكرار)--extractor-plugin-file <FILE> (قابل للتكرار)تنسيق إضافة الأمان يطابق JSON الخاص بـ --security-tags-file (version، mode، tags).
تنسيق إضافة الاستخراج:
{
"version": 1,
"extractors": [
{
"name": "policy-rule",
"kind": "Config",
"regex": "^policy\\s+([A-Za-z_][A-Za-z0-9_]*)"
}
]
}
# Diff two branches in a single repo
diffcatcher ./my-repo --diff main..feature/auth
# Diff specific commits
diffcatcher ./my-repo --diff abc123..def456
# Diff with SARIF output for CI integration
diffcatcher ./my-repo --diff origin/main..HEAD --summary-format sarif -o ./pr-report
العلم --diff BASE..HEAD يتجاوز اكتشاف المستودع وسحب البيانات — فهو يقارن مباشرة بين مرجعين (فروع، علامات، أو تجزئات التزامات) ويشغل مسار الاستخراج الكامل + وضع العلامات الأمنية على النتيجة.
# Generate SARIF alongside other formats
diffcatcher ~/projects --summary-format sarif,json,md
# SARIF-only for CI/CD upload
diffcatcher ~/projects --summary-format sarif -o ./report
عند تضمين sarif في --summary-format، يتم كتابة ملف results.sarif في جذر التقرير. يتبع هذا الملف معيار SARIF 2.1.0 ويتكامل مع فحص كود GitHub، وعارض SARIF لـ VS Code، وAzure DevOps، وأدوات أخرى متوافقة مع SARIF.
# Incremental mode (skip unchanged repos)
diffcatcher ~/projects --incremental -o ./report
# Filter by branch pattern
diffcatcher ~/projects --branch-filter "main"
# Adjust history depth
diffcatcher ~/projects --history-depth 5
# JSON output for CI/CD
diffcatcher ~/projects --quiet --json > result.json
# Verbose output with discovered paths
diffcatcher ~/projects --verbose
<report_dir>/
├── summary.json # ملخص عام
├── summary.md # ملخص Markdown
├── results.sarif # مخرجات SARIF 2.1.0 (عند --summary-format sarif)
├── security_overview.json # تجميع أمني عبر المستودعات
├── security_overview.md
├── <repo-name>/
│ ├── status.json # حالة المستودع
│ ├── pull_log.txt
│ └── diffs/
│ ├── diff_N_vs_N-1.patch # فرق موحد خام
│ ├── changes_N_vs_N-1.txt # قائمة الملفات
│ ├── summary_N_vs_N-1.json # استخراج العناصر
│ ├── summary_N_vs_N-1.md
│ └── snippets/
│ ├── 001_validate_token_ADDED.rs
│ ├── 002_check_permissions_BEFORE.rs
│ ├── 002_check_permissions_AFTER.rs
│ └── 002_check_permissions.diff
└── ...
انظر diffcatcher --help لجميع الخيارات.
أنشئ ملف JSON بأنماط مخصصة:
{
"version": 1,
"mode": "extend",
"tags": [
{
"tag": "pii-handling",
"description": "معالجة بيانات PII",
"severity": "High",
"patterns": ["ssn", "social_security", "passport"]
}
]
}
استخدم مع --security-tags-file ./patterns.json
src/
├── cli.rs # تحليل الوسائط
├── scanner.rs # اكتشاف المستودعات
├── git/ # عمليات Git
│ ├── commands.rs # أغلفة Git
│ ├── state.rs # التقاط الحالة
│ ├── diff.rs # إنشاء الفروق
│ └── file_retrieval.rs
├── extraction/ # استخراج العناصر
│ ├── parser.rs # محلل الفروق الموحدة
│ ├── elements.rs # اكتشاف العناصر
│ ├── snippets.rs # استخراج مقتطفات الكود
│ ├── boundary.rs # تتبع الأقواس/المسافات البادئة
│ └── languages/ # أنماط خاصة باللغة
├── security/ # وضع العلامات الأمنية
│ ├── tagger.rs # مطابقة الأنماط
│ ├── patterns.rs # الأنماط المدمجة
│ └── overview.rs # التجميع عبر المستودعات
└── report/ # إنشاء التقارير
├── writer.rs # هيكل الدليل
├── json.rs # تسلسل JSON
├── sarif.rs # مخرجات SARIF 2.1.0
├── markdown.rs # تنسيق Markdown
└── snippet_writer.rs
سطر bash بسيط يمكنه سرد الفروق:
ls | while read line; do git -C "$line" diff HEAD~1 HEAD || true; done
هذا يعمل للفحوصات السريعة، لكن DiffCatcher يضيف قدرات كبيرة:
سطر bash الواحد هو حوالي 100 بايت. DiffCatcher هي أداة تدقيق موجهة للأمان مع استخراج كامل لعناصر الكود.
# Run all tests
cargo test
# Run specific test suite
cargo test security_tagger
# Run with output
cargo test -- --nocapture
تغطية الاختبار تشمل:
# Compile benchmark binaries
cargo bench --no-run
# Run benchmark harness
cargo bench --bench core_bench
مصدر المقاييس موجود في benches/core_bench.rs ويتتبع إنتاجية المحلل/الاستخراج.
تتضمن سير عمل GitHub Actions:
.github/workflows/ci.yml: فحص التنسيق، clippy، الاختبارات، بناء المقاييس.github/workflows/release.yml: تغليف الإصدار بناءً على العلامات ونشر الإصدار على GitHubsrc/security/patterns.rs)تحتوي جميع الوحدات على توثيق شامل مضمّن. الوحدات الرئيسية:
src/extraction/parser.rs - محلل الفروق الموحدة مع استخراج الكتلsrc/extraction/elements.rs - اكتشاف عناصر الكود حسب اللغةsrc/extraction/snippets.rs - استخراج مقتطفات كود كاملة مع اكتشاف الحدودsrc/security/tagger.rs - محرك مطابقة الأنماط الأمنيةsrc/git/commands.rs - أغلفة عمليات Gitإنشاء توثيق API الكامل:
cargo doc --open
#rust #git #security #code-review #diff-analysis #static-analysis #devops #cli-tool #audit #vulnerability-detection #code-quality #snippet-extraction #parallel-processing #security-scanning
المساهمات مرحب بها! من فضلك:
cargo testرخصة MIT - انظر ملف LICENSE للتفاصيل
| العلم | القيمة الافتراضية | الوصف |
|---|
-o, --output | ./reports/<timestamp> | دليل إخراج التقرير |
-j, --parallel | 4 | المعالجة المتزامنة للمستودعات |
-t, --timeout | 120 | مهلة عمليات Git (بالثواني) |
-d, --history-depth | 2 | الالتزامات التاريخية للمقارنة |
--snippet-context | 5 | أسطر السياق حول التغييرات |
--max-snippet-lines | 200 | أقصى عدد أسطر لكل مقتطف |
--max-elements | 500 | أقصى عدد عناصر لكل فرق |
--diff | — | مقارنة مرجعين في مستودع واحد (BASE..HEAD) |
--summary-format | json,md | تنسيقات الإخراج: json، md، txt، sarif |
| القدرة | سطر Bash واحد | DiffCatcher |
|---|
| الاكتشاف المتكرر | عناصر المستوى الأعلى فقط | مستودعات متداخلة، روابط رمزية، عوامل تصفية |
| تتبع الحالة | لا شيء | تجزئات الالتزام، كشف التعديلات، سجلات السحب |
| فهم الكود | فرق خام فقط | استخراج الدوال/الهياكل/الكلاسات عبر أكثر من 10 لغات |
| مقتطفات الكود | لا شيء | نصوص كاملة قبل/بعد مع نوافذ سياق |
| التحليل الأمني | لا شيء | 18 نمطًا مدمجًا (المصادقة، التشفير، الأسرار، حقن SQL، XSS) |
| تنسيقات الإخراج | طرفية فقط | JSON، Markdown، SARIF (فحص كود GitHub) |
| عرض عبر المستودعات | لكل مستودع فقط | تقرير أمني مجمع عبر جميع المستودعات |
| الأداء | تسلسلي | عمال متوازيون، تخزين مؤقت LRU، وضع تدريجي |
| التكامل مع CI/CD | لا شيء | رفع SARIF إلى GitHub/Azure DevOps |
| معالجة الأخطاء | كبت || true | معالجة أخطاء مناسبة مع تسجيل مفصل |
| معالجة المسارات | يفشل مع المسافات | يعالج جميع أسماء المسارات بشكل صحيح |
| السياق التاريخي | HEAD~1 ثابت | عمق قابل للتعديل، تتبع الحالة |