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

large-file-write-via-temp-script

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

यह स्किल AI एजेंट को बैकटिक, टेम्पलेट लिटरल या इमोजी जैसे जटिल अक्षरों वाली बड़ी फ़ाइलें सहेजने का तरीका बताती है। यह उन डेवलपर्स के लिए है जो TypeScript, TSX या समान फ़ाइलें सहेजते हैं और इनलाइन लिखने पर वे टूट जाती हैं।

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

  • ✓जब फ़ाइल सामग्री में बैकटिक, dollar-brace टेम्पलेट लिटरल या इमोजी हों जो इनलाइन कमांड तोड़ देते हैं।
  • ✓जब इनलाइन लिखने की कोशिशें अज्ञात त्रुटि दें या फ़ाइल को चुपचाप खाली कर दें।
  • ✓जब बड़ी TypeScript या TSX फ़ाइल ठीक वैसे ही सहेजनी हो जैसी लिखी गई है।

Skill का लिंक

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

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

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

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

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

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

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

“इस TSX कंपोनेंट को मेरे प्रोजेक्ट में सहेजिए। इसमें बैकटिक और टेम्पलेट लिटरल हैं, और इनलाइन लेखन बार-बार टूट रहा है।”

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

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

एजेंट एक छोटी Python हेल्पर स्क्रिप्ट एक टेम्प फ़ाइल में लिखता है। फ़ाइल सामग्री उस स्क्रिप्ट में एक raw string के भीतर रहती है, इसलिए विशेष अक्षर बचे रहते हैं, और फिर एजेंट उस हेल्पर को चलाकर लक्ष्य फ़ाइल लिखता है।

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

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

Large File Write via Temp Script

Problem

Writing large files — especially TypeScript, TSX, or any content containing Unicode emoji, backticks, ${} template literals, or multi-line heredoc conflicts — can silently fail or truncate content when passed inline.

Failure modes observed:

  • write_file returns [ERROR] unknown error on large payloads
  • node -e '...' with backtick template literals silently empties the target file
  • python3 -c '...' breaks on unescaped quotes or special characters
  • shell_agent may time out or fail when the inline content is too large

Solution: Write a Python Script to a Temp File First

Instead of passing file content inline, write a small Python helper script to /tmp/write_task.py (or similar), then execute it. The helper script holds the target file content as a raw Python string or via base64 decoding.


Approach A — Python Triple-Quoted String (preferred for readability)

Use write_file or a heredoc to create the helper, then run it:

# Step 1: Write the helper script to /tmp
cat > /tmp/write_task.py << 'PYEOF'
import pathlib

content = r"""
// Your TypeScript / file content goes here
// Backticks `like this`, ${template} literals, and emoji 🎉 are all safe
export const MyComponent = () => {
  const msg = `Hello, world!`;
  return <div>{msg}</div>;
};
"""

pathlib.Path("/path/to/target/file.ts").write_text(content.lstrip("\n"), encoding="utf-8")
print("Written successfully.")
PYEOF

# Step 2: Execute the helper
python3 /tmp/write_task.py

Why r"""? A raw triple-quoted string avoids all backslash escaping issues. The only content that cannot appear verbatim is """ itself — if needed, split the string or escape that sequence only.


Approach B — Base64-Encoded Content (most robust for binary/complex content)

When the content contains """ or other Python string edge cases:

# Step 1: Base64-encode your content (done once, outside the target system)
# python3 -c "import base64; print(base64.b64encode(open('file.ts').read().encode()).decode())"

# Step 2: Embed the base64 blob in the helper script
cat > /tmp/write_task.py << 'PYEOF'
import base64, pathlib

b64 = (
    "aW1wb3J0IFJlYWN0IGZyb20gJ3JlYWN0JzsKCmV4cG9ydCBjb25zdCBNeUNvbXBvbmVudCA9"
    "ICgpID0+IHsKICByZXR1cm4gPGRpdj5IZWxsbzwvZGl2PjsKfTsK"
    # ... more lines if needed
)

content = base64.b64decode(b64).decode("utf-8")
pathlib.Path("/path/to/target/file.ts").write_text(content, encoding="utf-8")
print(f"Written {len(content)} bytes successfully.")
PYEOF

python3 /tmp/write_task.py

Approach C — shell_agent Delegation (simplest for agents)

Ask shell_agent to perform the write using the temp-script pattern:

"Write the following TypeScript content to /src/components/MyPanel.ts. Do NOT use node -e or inline Python. Instead write a Python script to /tmp/write_panel.py using a triple-quoted raw string, then execute it."


Decision Guide

Situation Recommended Approach
Content has backticks / ${} template literals Approach A (raw r""")
Content has """ sequences Approach B (base64)
Content is binary or non-UTF-8 Approach B (base64)
Delegating to shell_agent Approach C with explicit instructions
Quick small file Direct write_file (no workaround needed)

Anti-Patterns to Avoid

# ❌ DANGEROUS — backtick template literals will break node -e
node -e "const fs = require('fs'); fs.writeFileSync('out.ts', \`${content}\`);"

# ❌ FRAGILE — breaks on unescaped quotes and special characters
python3 -c "open('out.ts','w').write('${content}')"

# ❌ UNRELIABLE for large payloads — may silently truncate
echo "${large_content}" > out.ts

Verification Step

Always verify the write succeeded:

# Check file exists and has non-zero size
python3 -c "
import pathlib
p = pathlib.Path('/path/to/target/file.ts')
assert p.exists() and p.stat().st_size > 0, f'Write failed: {p}'
print(f'OK — {p.stat().st_size} bytes written to {p}')
"

Notes

  • The temp script approach works for any file type: .ts, .tsx, .js, .json, .md, .py, etc.
  • Always lstrip("\n") the triple-quoted string to avoid a leading blank line.
  • For very large files (>50 KB), prefer base64 to avoid any risk of heredoc conflicts.
  • Clean up temp scripts after use: rm /tmp/write_task.py
अक्सर पूछे जाने वाले सवाल

इनलाइन लेखन क्यों टूटता है?

स्किल कहती है कि इनलाइन पास करने पर बैकटिक, टेम्पलेट लिटरल और कोट्स कट या बिगड़ सकते हैं।

raw string क्या है?

यह एक Python स्ट्रिंग है जो बैकस्लैश और विशेष अक्षरों को ठीक वैसा ही रखती है जैसा लिखा गया हो।

हेल्पर स्क्रिप्ट कहां जाती है?

स्किल उसे /tmp जैसे अस्थायी स्थान में रखती है, हालांकि ऐसा ही कोई टेम्प पाथ भी चल सकता है।

जानकारी

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

Reliable fallback technique for writing large or special-character-heavy file content when inline write_file or shell_agent calls fail with unknown errors — uses a Python helper script written to a temp file to avoid escaping and truncation pitfalls.

repo: HKUDS/AgentPilot

लोकप्रियता

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

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

0

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

कमेंट

  • …

इस repository की और skills

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