‹ 首页

fallback-file-creation

@hkuds · 收录于 5 天前 · 上游提交 1 周前

Fallback pattern for reliable file creation when code execution tools fail

适合你,如果经常遇到代码执行工具无法创建文件的情况

/ 通过 npx 安装 校验哈希
npx oh-my-skill add hkuds/openspace/fallback-file-creation
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- hkuds/openspace/fallback-file-creation
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify hkuds/openspace/fallback-file-creation
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
6920GitHub stars
~911上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 2c5cc40 · 表述以原文为准
它做什么

当代码执行工具反复失败时,Claude 会使用 shell heredoc 创建脚本,手动执行并验证文件(如 PDF、DOCX),替代失败的工具。

什么时候触发

当代码执行工具多次失败,或需要创建特定格式文件(PDF、DOCX 等),或需要显式验证输出时触发。

装好后可以这样说
Claude 会手动创建脚本并执行。
触发 fallback 流程。
Claude 会执行并验证。
技能原文 SKILL.md作者撰写 · MIT · 2c5cc40

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 |

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。