跳到正文
Skillpedia
通用编程7.8k · #12975

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-file-creation/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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_sandbox fails with unknown error on file/directory creation
  • shell_agent fails 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

  1. Create all directories first before writing any files to avoid path errors
  2. Write files one at a time rather than attempting batch operations
  3. Use absolute or clearly relative paths to avoid ambiguity
  4. Verify after creation when working on critical deliverables
  5. Document the structure in comments or SKILL.md if it's complex

Why This Works

  • run_shell executes commands directly without the abstraction layer that can fail
  • write_file is 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能