मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग7.8k · #13058

large-file-write-mkdir

यह क्या करती है

यह स्किल बड़ी फ़ाइलों के बैकअप तरीके को आगे बढ़ाती है, लिखने से पहले पक्का करके कि लक्ष्य फ़ोल्डर मौजूद है। यह उन लोगों के लिए है जो लंबी फ़ाइलें ऐसे फ़ोल्डरों में सहेजते हैं जो अभी मौजूद नहीं।

कब इस्तेमाल करें

  • ✓जब बड़ी फ़ाइल पर सामान्य राइट टूल फेल हो।
  • ✓जब नई फ़ाइल के लिए फ़ोल्डर अभी मौजूद न हो।
  • ✓जब किसी गायब फ़ोल्डर पर Python लेखन FileNotFoundError दे।

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-mkdir/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-mkdir/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“इस लंबी रिपोर्ट को एक नए reports सबफ़ोल्डर में सहेजिए। पहले लिखना फेल हुआ था, इसलिए फ़ोल्डर बनाइए और फ़ाइल लिखिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट पैरेंट फ़ोल्डर पर mkdir -p चलाता है, जो गायब फ़ोल्डर बना देता है, फिर एक Python हेरडॉक चलाता है जो फ़ाइल लिखता है। अगर पैरेंट फ़ोल्डर ज्ञात न हो, तो वह dirname से उसे खोज सकता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Large File Write Fallback (with Directory Pre-creation)

Problem

When writing large files (typically several KB or more), two common tools may fail with unknown error due to internal payload size limits:

  • write_file — has a maximum content size it can handle in a single call.
  • shell_agent — may also hit payload limits when the task description includes large inline content.

A second class of failure occurs when the target directory does not exist: Python's open() will raise FileNotFoundError if any intermediate directory is missing. Always pre-create the parent directory to prevent this.

Solution

Use run_shell with a mkdir -p prefix and a Python heredoc pattern. The mkdir -p ensures the target directory exists; the heredoc streams the file content through stdin directly into Python's open(), bypassing the payload constraints of the other tools.

Template

mkdir -p "<PARENT DIRECTORY OF TARGET PATH>" && python3 - << 'EOF'
content = """<FILE CONTENTS HERE>"""
with open("<TARGET PATH>", "w") as f:
    f.write(content)
EOF

Pass this as the command parameter to run_shell.

Tip: If the parent directory is not known in advance, use the shell dirname helper: mkdir -p "$(dirname '<TARGET PATH>')" && python3 - << 'EOF'

Step-by-Step Instructions

  1. Attempt the normal write using write_file first. If it succeeds, you are done.

  2. If write_file fails (especially with unknown error or a timeout on large content), do NOT retry with shell_agent using inline content — it will likely fail for the same reason.

  3. Use the run_shell heredoc fallback:

    • Pre-create the parent directory with mkdir -p <parent_dir>. This is a no-op when the directory already exists, so it is always safe to include. Skipping this step causes Python's open() to raise FileNotFoundError for any new or deeply-nested path.
    • Embed the full file content inside a Python triple-quoted string.
    • Specify the target path inside the open() call.
    • Pass the entire block (mkdir + heredoc) as the command to run_shell.
  4. Escape carefully inside the heredoc:

    • Backslashes that should be literal in the file must be doubled (\\).
    • Triple-quotes inside the content must be escaped (\"\"\").
    • The heredoc delimiter EOF must not appear on a line by itself inside the content (rename it to PYEOF or FILEEOF if needed).
  5. Verify the write by following up with a run_shell call such as:

    wc -l <TARGET PATH> && head -5 <TARGET PATH>
    

Full Example

Suppose you need to write a large TypeScript file to src/components/Dashboard.ts:

mkdir -p "src/components" && python3 - << 'PYEOF'
content = """import { foo } from './foo';

export interface DashboardData {
  title: string;
  items: string[];
}

export function createDashboard(data: DashboardData): string {
  return `<div>${data.title}</div>`;
}
"""
with open("src/components/Dashboard.ts", "w") as f:
    f.write(content)
PYEOF

Pass the above (without the surrounding code fence) as the command argument to run_shell.

When to Use This Pattern

Situation Recommended tool
Small file (< ~2 KB) write_file
Medium file, no errors yet write_file (try first)
Large file or write_file failed run_shell + mkdir -p + Python heredoc
shell_agent also fails on large inline content run_shell + mkdir -p + Python heredoc
Target directory may not exist Always add mkdir -p <parent_dir> first

Notes

  • This pattern works for any text-based file (TypeScript, Python, JSON, YAML, Markdown, etc.).
  • For binary files, adapt the approach to use base64 decoding inside the Python script.
  • The heredoc delimiter (EOF, PYEOF, FILEEOF) can be any string not present as a standalone line in your content — choose accordingly.
  • This technique is also useful when content contains characters that would need heavy shell escaping in a plain echo or printf approach.
  • The mkdir -p command is idempotent: it succeeds whether or not the directory already exists, so it is always safe to include.
  • To derive the parent directory from a target path in shell: mkdir -p "$(dirname '<TARGET PATH>')" works as a generic alternative when the parent path is not already known.
अक्सर पूछे जाने वाले सवाल

mkdir पहले क्यों चलाएं?

लक्ष्य फ़ोल्डर पाथ का कोई भी हिस्सा गायब हो तो Python FileNotFoundError के साथ फेल होगा।

mkdir -p क्या करता है?

-p फ्लैग एक कमांड में सभी गायब पैरेंट फ़ोल्डर बनाता है, और अगर वे पहले से हों तो कुछ नहीं करता।

अगर मुझे फ़ोल्डर पता न हो तो?

स्किल दिखाती है कि लक्ष्य पाथ पर dirname चलाकर पैरेंट फ़ोल्डर खोजा जा सकता है।

जानकारी

लेखक का मूल विवरण

Reliable fallback technique for writing large file contents when write_file and shell_agent both fail with 'unknown error' due to payload size limits — uses run_shell with a Python heredoc to bypass tool constraints, with an explicit mkdir -p step to ensure the target directory exists before writing.

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#13058
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills