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

fallback-file-creation

它能做什么

这项技能为 AI 提供一种手动的、基于 shell 的方法,用于在代码执行工具持续失败时创建并检查文件。它适合需要可靠地制作特定文件格式的人。

适用场景

  • ✓当代码执行或 shell 辅助工具在某个文件任务上多次失败的时候。
  • ✓当我需要创建 PDF 或 Word 文件,而常用工具无法使用的时候。
  • ✓当我希望每个文件在写入后都得到检查的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-file-creation/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 AI

“代码工具一直在处理我的文件时失败。请检查文件夹,在 shell 中编写脚本,并确认文件确实存在。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会确认工作文件夹,用 shell heredoc 编写脚本,使用明确的路径运行它们,并检查每个输出文件是否存在。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Fallback File Creation Workflow

Use this skill when execute_code_sandbox or shell_agent fails repeatedly for file creation tasks. This pattern provides a manual but reliable approach to create and verify files.

When to Use

  • Code execution tools fail after multiple retries
  • You need to create specific file formats (PDF, DOCX, etc.)
  • Direct shell commands are more reliable than generated scripts
  • You need explicit verification of file outputs

Step-by-Step Instructions

Step 1: Verify Working Directory

Before any file operations, confirm your current location:

pwd
ls -la

This ensures you're creating files in the correct workspace directory.

Step 2: Create Scripts via Heredoc

Use shell heredocs to create scripts with properly escaped syntax:

cat > /path/to/script.sh << 'EOF'
#!/bin/bash
# Your script content here
# Variables are NOT expanded inside 'EOF' (quoted)
echo "Creating file..."
# Commands to generate output
EOF

Key escaping rules:

  • Use 'EOF' (quoted) to prevent variable expansion inside the heredoc
  • Use EOF (unquoted) if you want shell variables to expand
  • Escape any $, backticks, or special characters if using unquoted EOF

Step 3: Execute with Explicit Path

Always run scripts with their full or explicit relative path:

chmod +x /path/to/script.sh
/path/to/script.sh
# or
bash /path/to/script.sh

Avoid relying on . or implicit paths.

Step 4: Verify Output

After execution, verify files were created correctly:

# Check file exists and size
ls -lh /path/to/output.file

# For PDFs: inspect metadata
pdfinfo /path/to/output.pdf

# For DOCX: check structure
unzip -l /path/to/output.docx | head -20

# For any file: check content preview
file /path/to/output.file
head -c 500 /path/to/output.file

Step 5: Iterative Debugging

If verification fails:

  1. Check error messages from script execution
  2. Verify all dependencies are available (which command)
  3. Test individual commands from the script manually
  4. Re-run with verbose output (bash -x script.sh)

Example: Creating a PDF Document

# Step 1: Verify directory
pwd
ls -la

# Step 2: Create conversion script
cat > /workspace/create_pdf.sh << 'EOF'
#!/bin/bash
cd /workspace
libreoffice --headless --convert-to pdf checklist.odt --outdir .
EOF

# Step 3: Execute
chmod +x /workspace/create_pdf.sh
/workspace/create_pdf.sh

# Step 4: Verify
ls -lh /workspace/checklist.pdf
pdfinfo /workspace/checklist.pdf

Example: Creating a DOCX Document

# Step 1: Verify directory
pwd
ls -la

# Step 2: Create document script
cat > /workspace/create_docx.sh << 'EOF'
#!/bin/bash
cd /workspace
pandoc -f markdown -t docx action_tracker.md -o action_tracker.docx
EOF

# Step 3: Execute
chmod +x /workspace/create_docx.sh
/workspace/create_docx.sh

# Step 4: Verify
ls -lh /workspace/action_tracker.docx
unzip -l /workspace/action_tracker.docx | head -20

Best Practices

  1. Always verify before and after - Check directory state before starting and after completion
  2. Use absolute or explicit paths - Avoid ambiguity in file locations
  3. Quote heredoc delimiters - Use 'EOF' to prevent unwanted variable expansion
  4. Make scripts executable - Always chmod +x before running
  5. Inspect file metadata - Use format-specific tools (pdfinfo, unzip -l, file) to verify content
  6. Keep scripts simple - Each script should do one thing well
  7. Clean up temporary files - Remove intermediate files after successful completion

Troubleshooting

Issue Solution
Script not found Use full path: /workspace/script.sh
Permission denied Run chmod +x script.sh
File not created Check script output, verify working directory in script
Wrong file format Verify conversion tool supports target format
Corrupted output Re-run with verbose mode, check intermediate files
常见问题

为什么要用 heredoc?

它让 AI 可以用一条 shell 命令把整个脚本写入文件。

为什么要先检查工作文件夹?

这样可以确保文件被创建在正确的工作区中。

脚本中的变量会被展开吗?

使用带引号的 EOF 标记时不会展开,从而保证脚本文本与所写的完全一致。

详情

作者的原始描述

Fallback pattern for reliable file creation when code execution tools fail

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12880
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能