simplify-code
ما الذي تفعله
تساعد هذه المهارة ذكاءك على إيجاد التعقيد غير الضروري في الكود وإزالته. وهي لمطورين صار كودهم صعبًا على القراءة أو الصيانة.
متى تستخدمها
- ✓عندما تحتوي قاعدة الكود على أغلفة أو تجريدات تفعل القليل جدًا.
- ✓عندما تجد كودًا ميتًا أو استيرادات غير مستخدمة أو منطقًا متداخلًا يصعب تتبعه.
- ✓عندما تريد كودًا أسهل في القراءة مع الحفاظ على السلوك نفسه.
رابط المهارة
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/simplify-code/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“بسّط هذه الوحدة. أزل كل ما هو غير مستخدم، وسطّح المنطق المتداخل، لكن حافظ على السلوك نفسه.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تفحص المهارة الكود بحسب قائمة من مشكلات التعقيد الشائعة. ثم تزيل ما لا حاجة إليه أو تسطّحه، مع الحفاظ على السلوك نفسه.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Simplify Code — Reduce Unnecessary Complexity
The best code is the code you don't have to write. The second best is the code anyone can read.
Core Principle
Complexity is a cost. Every abstraction, every indirection, every clever pattern
adds cognitive load. Simplify ruthlessly unless complexity serves a clear purpose.
Simplification Checklist
1. Unnecessary Abstractions
| Smell | Simplification |
|---|---|
| Wrapper class that just delegates | Remove wrapper, use the inner class directly |
| Factory that creates only one type | Replace with direct constructor |
| Strategy pattern with one strategy | Replace with simple function |
| Interface with one implementation | Remove interface, use the class |
| Abstract class with one child | Merge into the child class |
| Config object for 2 values | Use function parameters |
2. Dead Code
| Smell | Action |
|---|---|
| Unused imports | Remove |
| Unreachable branches | Remove (check tests first) |
| Commented-out code | Remove (it's in git history) |
| Unused variables/functions | Remove |
| TODO comments older than 6 months | Remove or create issue |
| Feature flags for launched features | Remove flag, keep the code |
3. Deep Nesting
// ❌ Before: 4 levels deep
function process(data) {
if (data) {
if (data.items) {
for (const item of data.items) {
if (item.active) {
doSomething(item)
}
}
}
}
}
// ✅ After: Early returns + filter
function process(data) {
if (!data?.items) return
data.items
.filter(item => item.active)
.forEach(doSomething)
}
4. Over-Parameterized Functions
// ❌ Before: 8 parameters
function createUser(name, email, age, role, dept, active, verified, avatar) { }
// ✅ After: Object parameter
function createUser(opts: CreateUserOpts) { }
5. Premature Optimization
| Smell | Simplification |
|---|---|
| Custom cache for <100 items | Remove cache, measure first |
| Memoization on cheap functions | Remove memo |
| Lazy loading for small modules | Use direct import |
| Complex state machine for 3 states | Use simple if/else or switch |
Simplification Protocol
Step 1: Identify Complexity
- Count nesting levels (target: ≤3)
- Count function parameters (target: ≤4)
- Count lines per function (target: ≤30)
- Count abstractions per feature (target: ≤2)
- Check for dead code (target: 0)
Step 2: Verify Understanding
Before simplifying, ensure you understand:
- What the code does (not what it looks like it does)
- Why it was written this way (maybe there's a reason)
- What tests cover it (simplification must not break tests)
Step 3: Simplify Incrementally
1. Remove dead code first (safest)
2. Flatten nesting with early returns
3. Inline trivial abstractions
4. Merge related functions
5. Simplify data structures
Step 4: Verify Behavior Preserved
npm run test # All existing tests still pass
npm run build # Still compiles
When NOT to Simplify
| Situation | Why Keep Complexity |
|---|---|
| Performance-critical hot path | Optimization may look complex but is necessary |
| Required by framework/library | External constraints |
| Explicitly requested pattern | User chose this architecture |
| Will need extension soon | Abstraction prepares for known growth |
Ask first: "This pattern seems over-engineered. Should I simplify it, or is there a reason for the abstraction?"
الأسئلة الشائعة
هل يغيّر التبسيط طريقة عمل الكود؟
صُممت المهارة للحفاظ على السلوك، وتتحقق من الاختبارات قبل إزالة فروع المنطق.
ما الذي يُعدّ كودًا ميتًا؟
الاستيرادات غير المستخدمة، والمتغيرات والدوال غير المستعملة، والفروع التي لا يمكن الوصول إليها، والكود القديم المعلَّق.
هل تزيل مفاتيح الميزات (feature flags)؟
تقترح إزالة المفاتيح للميزات التي أُطلقت فعلًا، مع الإبقاء على الكود نفسه.
التفاصيل
الوصف الأصلي من المؤلف
Reduce complexity of over-engineered code. Identify unnecessary abstractions, remove dead code, flatten deep nesting, and simplify logic while preserving behavior.
repo: vudovn/ag-kit
الشعبية
- نجوم GitHub
- 8.2k
- الترتيب
- #12539
- الترخيص
- MIT
- آخر تحديث
- 18/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
batch-operations
8.2kيساعد وكيلك على إجراء التغيير نفسه على ملفات كثيرة دفعة واحدة، مثل إعادة تسمية دالة أو استبدال استيراد قديم في كل مكان.
brainstorming
8.2kيعلّم وكيلك أن يطرح أسئلة توضيحية قبل بناء أي شيء جديد أو معقد، حتى يفهم هدفك أولًا.
code-review-checklist
8.2kيعطي وكيلك قائمة تحقق لمراجعة الكود من ناحية الصحة والأمان والأداء والاختبارات والتوثيق، بما في ذلك مخاطر الذكاء الاصطناعي.
code-review-graph
8.2kيساعد وكيلك على مراجعة الكود في المشاريع الكبيرة باستخدام خريطة بنيوية، فيقرأ الملفات المتأثرة بالتغيير فقط.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.