Skillpedia
برمجة عامة7.8k · #13030

working-directory-resolution

ما الذي تفعله

تشرح هذه المهارة لوكيل الذكاء الاصطناعي كيف يتجنب أخطاء الملفات الناتجة عن تشغيل الأوامر في مجلد خاطئ. وهي مناسبة لمن توجد ملفاته فعلًا لكن الوكيل يبلغ بأنها غير موجودة.

متى تستخدمها

  • ✓عندما تفشل قراءة ملف بخطأ لم يُعثر عليه أو لا يوجد ملف كهذا، رغم أن الملف موجود.
  • ✓عندما لا تجد بيئة التنفيذ المعزولة ملفات تشير إليها المهمة.
  • ✓عندما يبلغ أمر في الطرفية عن ملف مفقود يُفترض أن يكون موجودًا.

رابط المهارة

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/working-directory-resolution/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/working-directory-resolution/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“يقول الوكيل إن ملف config.json غير موجود، رغم أنني أراه في مساحة العمل. أصلح مشكلة المجلد واقرأ الملف.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يبدأ الوكيل كل أمر في الطرفية بالأمر cd إلى المجلد المستهدف، فتعمل كل الأوامر في المكان الصحيح. وهذا يزيل الفرق بين مجلد العمل ومكان الملفات.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Working Directory Resolution Pattern

Many file operation failures occur because the tool's current working directory doesn't match where the target files are located. This skill provides a reliable pattern for resolving such issues.

Problem Symptoms

File operations fail with errors like:

  • "File not found" or "No such file or directory"
  • "Permission denied" (when path is actually relative)
  • Tools returning empty results for files that should exist

These failures often occur even when files are present in the workspace—the working directory context is simply wrong.

Solution

Always explicitly set the working directory before file operations by prepending cd to your shell commands.

Implementation Pattern

Basic Syntax

cd /path/to/target/directory && your-command-here

With run_shell

run_shell(command="cd /workspace/project && cat config.json")

Multiple Operations in Same Directory

cd /workspace/project && ls -la && cat README.md && python script.py

Conditional Directory Change

cd /workspace/project 2>/dev/null && cat file.txt || echo "Directory not found"

When to Apply

Use this pattern when:

  • read_file fails to locate an existing file
  • execute_code_sandbox can't find referenced files
  • Shell commands report missing files that should exist
  • File paths work in some contexts but not others
  • You're unsure of the tool's current working directory

Best Practices

  1. Use absolute paths when possible

    cd /workspace/project/src && python main.py
    
  2. Combine related operations to avoid repeated cd calls

    cd /workspace/project && ./build.sh && ./test.sh
    
  3. Verify directory exists before operations

    [ -d /workspace/project ] && cd /workspace/project && ls
    
  4. For scripts, set working directory at the start

    #!/bin/bash
    cd "$(dirname "$0")" || exit 1
    # Rest of script runs from script's directory
    

Common Pitfalls

Issue Wrong Approach Correct Approach
Relative paths cat config.json cd /workspace && cat config.json
Assumed cwd python script.py cd /workspace && python script.py
Multiple dirs cd dir1; cd dir2; cmd cd dir1/dir2 && cmd

Fallback Strategy

If cd also fails:

  1. Use pwd to check current directory
  2. Use find or ls -R to locate files
  3. Verify the path structure with ls -la /path/to/check
pwd && find /workspace -name "target_file.txt" 2>/dev/null

This pattern is especially valuable when tools like execute_code_sandbox or read_file fail but run_shell with explicit directory context succeeds.

الأسئلة الشائعة

لماذا يصلح هذا أخطاء الملفات المفقودة؟

معظم تلك الأخطاء تحدث لأن الأمر يُنفَّذ من مجلد مختلف عن مكان الملفات.

هل يمكن تشغيل عدة أوامر في مجلد واحد؟

نعم، توضح المهارة ربط الأوامر بعد أمر cd واحد، فتعمل كلها في ذلك المجلد.

ماذا لو لم يكن المجلد موجودًا؟

توضح المهارة صيغة شرطية تطبع رسالة عندما لا يُعثر على المجلد.

التفاصيل

الوصف الأصلي من المؤلف

Resolve file access failures by changing to the correct working directory before command execution

repo: HKUDS/AgentPilot

الشعبية

نجوم GitHub
7.8k
الترتيب
#13030
الترخيص
MIT
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة