Chuyển đến nội dung
Skillpedia
Lập trình chung7.8k · #12880

fallback-file-creation

Skill này làm gì

Skill này cho AI một cách thủ công, dựa trên shell, để tạo và kiểm tra tệp khi công cụ thực thi code liên tục thất bại. Dành cho người cần các định dạng tệp cụ thể được tạo đáng tin cậy.

Khi nào nên dùng

  • ✓Khi công cụ thực thi code hoặc trợ lý shell đã thất bại nhiều lần với một tác vụ tệp.
  • ✓Khi tôi cần tệp PDF hoặc Word được tạo và các công cụ thông thường không hoạt động.
  • ✓Khi tôi muốn mỗi tệp được kiểm tra sau khi ghi.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-file-creation/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Các công cụ code liên tục thất bại với tệp của tôi. Hãy kiểm tra thư mục, viết script trong shell và xác nhận tệp thật sự có ở đó.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI xác nhận thư mục làm việc, viết script bằng heredoc shell, chạy chúng với đường dẫn rõ ràng, và kiểm tra từng tệp đầu ra có tồn tại.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Vì sao dùng heredoc?

Nó cho phép AI ghi cả một script vào tệp chỉ trong một lệnh shell.

Vì sao kiểm tra thư mục làm việc trước?

Điều này đảm bảo các tệp được tạo đúng trong không gian làm việc.

Biến có được mở rộng trong script không?

Khi dấu đánh dấu EOF được đặt trong dấu nháy thì không, nhờ vậy văn bản script được giữ đúng như đã viết.

Chi tiết

Mô tả gốc của tác giả

Fallback pattern for reliable file creation when code execution tools fail

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12880
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự