working-directory-resolution
Resolve file access failures by changing to the correct working directory before command execution
- License 许可
- MIT
- 所属仓库
- HKUDS/AgentPilot
- 最近更新
- 2026-11-12
- Stars
- ★ 8.0k
- Forks
- 944
01 前言 Front Matter
- name
- working-directory-resolution
- description
- Resolve file access failures by changing to the correct working directory before command execution
02 资源文件 1
- 其他.skill_id42 B
03 SKILL.md 正文
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_filefails to locate an existing fileexecute_code_sandboxcan'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
-
Use absolute paths when possible
cd /workspace/project/src && python main.py -
Combine related operations to avoid repeated
cdcallscd /workspace/project && ./build.sh && ./test.sh -
Verify directory exists before operations
[ -d /workspace/project ] && cd /workspace/project && ls -
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:
- Use
pwdto check current directory - Use
findorls -Rto locate files - 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.
04 同仓库更多 Skills
agentpilot
Set up AgentPilot and use its single entry to prepare missing inputs and run configured RSI experiments. Use when the user requests AgentPilot installation or work with AgentPilot.
remember
Review auto-memory entries and propose promotions to OPENSPACE.md, OPENSPACE.local.md, or retained auto-memory topics; detect duplicates, stale facts, conflicts, and ambiguous entries before making changes.
skill-discovery
Search reusable OpenSpace skills locally, and browse cloud packages step by step when a cloud skill may help. Reusing proven skills saves tokens, improves reliability, and extends your capabilities beyond built-in tools.
delegate-task
Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
write-special-chars-ts-check
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.
write-special-chars-readback
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of /tmp helper scripts.