heredoc-file-write
यह क्या करती है
यह स्किल AI को कोड फ़ाइलें सहेजने का बैकअप तरीका देती है, जब सामान्य फ़ाइल राइटर कोट्स, एस्केप या विशेष अक्षरों पर बार-बार विफल हो। यह उन लोगों के लिए है जिनके AI टास्क React, TypeScript या JSON फ़ाइलें बनाते हैं।
कब इस्तेमाल करें
- ✓जब फ़ाइल राइटर एक ही कोड फ़ाइल पर अज्ञात एरर के साथ बार-बार विफल हो।
- ✓जब कोड फ़ाइल में नेस्टेड कोट्स, एस्केप वर्ण या दूसरी जटिल सिंटैक्स हों।
- ✓जब मुझे शेल से कोड फ़ाइल बनाने का भरोसेमंद तरीका चाहिए।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/heredoc-file-write/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“कोट्स की वजह से फ़ाइल राइटर मेरी React कंपोनेंट फ़ाइल नहीं लिख पा रहा। कृपया इसे किसी और तरीके से सहेजिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI quoted heredoc मार्कर के साथ cat कमांड चलाता है, जो कोड को जैसा दिया गया है वैसा ही लिखता है, बिना शेल के उसके अंदर के किसी वर्ण को बदले।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Heredoc File Write Workaround
When to Use This Skill
Use this pattern when:
write_filerepeatedly fails with "unknown error" or similar messages- The target file contains complex code (TypeScript, JSX, JSON with special characters, etc.)
- Standard file writing approaches encounter encoding or escaping issues
- You need a reliable fallback method to create files
Core Technique
Switch from write_file to run_shell using heredoc syntax with cat. The heredoc approach handles special characters, quotes, and complex content more reliably.
Step-by-Step Instructions
Step 1: Identify Write Failures
When write_file fails repeatedly on the same file:
- Note the error message (e.g., "unknown error", encoding issues)
- Review the file content for special characters, nested quotes, or complex syntax
- Attempt the heredoc workaround below
Step 2: Use Heredoc Syntax
Execute shell command with heredoc:
cat > /path/to/file.tsx << 'EOF'
// Your file content here
import React from 'react';
const Component = () => {
return <div>Hello</div>;
};
export default Component;
EOF
Step 3: Key Heredoc Rules
Use quoted delimiter (
'EOF'notEOF) to prevent variable expansion:'EOF'= literal content (recommended for code files)EOF= allows variable expansion (use only if needed)
Match delimiters exactly: Opening and closing
EOFmust be on their own lines with no leading/trailing whitespaceNo escaping needed: Content between delimiters is taken literally when using quoted delimiter
Step 4: Verify File Creation
After executing the heredoc command:
- Check if file exists:
ls -la /path/to/file.tsx - Verify content:
cat /path/to/file.tsxorhead -20 /path/to/file.tsx - Proceed with subsequent tasks once confirmed
Example Scenarios
TypeScript/JSX Component
cat > src/components/Button.tsx << 'EOF'
import React from 'react';
interface ButtonProps {
label: string;
onClick: () => void;
}
export const Button: React.FC<ButtonProps> = ({ label, onClick }) => {
return (
<button onClick={onClick} className="btn-primary">
{label}
</button>
);
};
EOF
JSON Configuration
cat > tsconfig.json << 'EOF'
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*"]
}
EOF
Complex Shell Script
cat > deploy.sh << 'EOF'
#!/bin/bash
set -e
echo "Deploying..."
if [ "$ENV" = "production" ]; then
echo "Production deployment"
fi
EOF
Advantages Over write_file
- No escaping complexity: Quotes, backslashes, and special characters work naturally
- Preserves formatting: Indentation and line breaks remain exact
- Handles multi-line content: No need to concatenate strings or use base64
- More reliable: Shell handles file I/O directly with fewer abstraction layers
Limitations
- Creates files in shell execution context (ensure correct working directory)
- Less programmatic than
write_filefor dynamic content generation - Requires shell access (may not work in restricted environments)
Troubleshooting
Problem: File not created at expected path
- Solution: Use absolute paths or verify current working directory with
pwd
Problem: Content appears corrupted
- Solution: Ensure delimiter is quoted (
'EOF') and closing delimiter has no trailing whitespace
Problem: Permission denied
- Solution: Ensure target directory exists and you have write permissions
अक्सर पूछे जाने वाले सवाल
quoted मार्कर क्यों मायने रखता है?
quoted मार्कर शेल को कोड के भीतर डॉलर चिह्न या दूसरे प्रतीक बदलने से रोकता है।
किन कोड प्रकारों का ज़िक्र है?
गाइड विशेष अक्षरों वाली TypeScript, JSX और JSON फ़ाइलों का ज़िक्र करती है।
बंद होने वाला मार्कर कैसा होना चाहिए?
बंद करने वाला मार्कर शुरुआती मार्कर से बिल्कुल मेल खाना चाहिए और अपनी अलग पंक्ति में होना चाहिए।
जानकारी
लेखक का मूल विवरण
Use shell heredoc syntax as a workaround when write_file fails on complex TypeScript/JSX/code files with encoding or escaping issues
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #12891
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।