robust-file-creation
它能做什么
这项技能在 AI 智能体的自动化工具出现故障时,为它提供一种手动创建项目文件夹和文件的方法。它适合需要可靠地建立一组文件夹和文件的人。
适用场景
- ✓当代码沙箱或辅助智能体在创建文件夹或文件时失败的时候。
- ✓当你需要一个包含多个文件的嵌套文件夹结构的时候。
- ✓当项目进度因文件工具错误而受阻的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-file-creation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的网站创建项目文件夹和初始文件。自动工具在这方面一直失败。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用 mkdir -p 创建每个文件夹,这也会创建所有上级文件夹。然后它逐个写入文件,并可以列出结果,以确认结构正确。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Robust File Creation Strategy
When creating complex project structures, automated tools like execute_code_sandbox and shell_agent may fail with 'unknown error' on filesystem operations. This skill provides a reliable fallback strategy using explicit shell commands.
When to Use
Apply this pattern when:
execute_code_sandboxfails with unknown error on file/directory creationshell_agentfails to complete filesystem operations after retries- You need to create nested directory structures with multiple files
- Task progress is blocked by filesystem tool failures
Fallback Procedure
Step 1: Detect the Failure
When either execute_code_sandbox or shell_agent fails on filesystem operations (especially after automatic retries), immediately switch to the manual hybrid approach.
Step 2: Create Directories Explicitly
Use run_shell with mkdir -p for each required directory:
run_shell command="mkdir -p /path/to/nested/directory"
The -p flag ensures parent directories are created automatically.
Step 3: Write Files Individually
Use write_file tool for each file with explicit path and content:
write_file path="/path/to/file.py" content="..."
Do not attempt to batch multiple file creations in a single operation.
Step 4: Verify Creation (Optional)
Confirm the structure was created correctly:
run_shell command="ls -la /path/to/directory"
# or
run_shell command="tree /path/to/directory"
Complete Example Flow
[execute_code_sandbox fails on project setup]
↓
[run_shell mkdir -p src/components]
[run_shell mkdir -p src/utils]
[run_shell mkdir -p tests]
↓
[write_file path="src/main.py" content="..."]
[write_file path="src/components/widget.py" content="..."]
[write_file path="tests/test_main.py" content="..."]
↓
[run_shell ls -la src/ # verify]
Best Practices
- Create all directories first before writing any files to avoid path errors
- Write files one at a time rather than attempting batch operations
- Use absolute or clearly relative paths to avoid ambiguity
- Verify after creation when working on critical deliverables
- Document the structure in comments or SKILL.md if it's complex
Why This Works
run_shellexecutes commands directly without the abstraction layer that can failwrite_fileis a primitive operation with fewer failure modes- Separating directory creation from file writing isolates potential failure points
- Explicit commands are easier to debug when issues occur
Anti-Patterns to Avoid
❌ Don't keep retrying the same failing execute_code_sandbox command
❌ Don't attempt to create complex nested structures in a single Python script via sandbox
❌ Don't assume directories exist before writing files to them
❌ Don't skip verification on critical project scaffolding
常见问题
为什么使用 mkdir 的 -p 参数?
-p 参数会同时创建上级文件夹,因此整条路径可以通过一条命令完成。
为什么要逐个写入文件?
这项技能要求不要批量创建文件,这样每一步都便于检查。
之后能检查结果吗?
可以。这项技能建议使用列出命令来确认文件夹和文件确实存在。
详情
作者的原始描述
Fallback to run_shell and write_file when execute_code_sandbox or shell_agent fail on filesystem operations
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12975
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。