large-file-write-via-temp-script
하는 일
이 스킬은 백틱, 템플릿 리터럴, 이모지 같은 까다로운 문자가 들어간 큰 파일을 AI 에이전트가 저장하는 방법을 보여 줍니다. 인라인으로 넘기면 실패하는 TypeScript, TSX 파일을 다루는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓파일 내용에 백틱, 달러 중괄호 템플릿 리터럴, 이모지가 있어 인라인 명령이 깨질 때.
- ✓인라인 쓰기 시도가 알 수 없는 오류를 내거나 파일을 조용히 비워 버릴 때.
- ✓큰 TypeScript나 TSX 파일을 쓰여 있는 그대로 저장해야 할 때.
스킬 링크
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에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이 TSX 컴포넌트를 제 프로젝트에 저장해 주세요. 백틱과 템플릿 리터럴이 있어서 인라인 쓰기가 계속 깨집니다.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 작은 Python 도우미 스크립트를 임시 파일에 씁니다. 대상 파일의 내용은 그 스크립트 안의 raw 문자열에 들어가 특수 문자가 보존되며, 그 뒤 에이전트가 도우미를 실행해 대상 파일을 씁니다.
기술 내용 (원본 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_filereturns[ERROR] unknown erroron large payloadsnode -e '...'with backtick template literals silently empties the target filepython3 -c '...'breaks on unescaped quotes or special charactersshell_agentmay 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 usenode -eor inline Python. Instead write a Python script to/tmp/write_panel.pyusing 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 문자열이란 무엇인가요?
백슬래시와 특수 문자를 입력한 그대로 유지하는 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
- 업데이트
- 2026. 11. 1.
댓글
- …
이 저장소의 다른 스킬
agentpilot
7.8k작업을 준비하고 AgentPilot 루프를 실행해 변경을 제안, 테스트, 점수화하면서 프로젝트를 단계적으로 개선하도록 돕습니다.
openspace
7.8k에이전트 스킬을 저장하고 가져오는 도구인 OpenSpace를 설정하고, MCP를 통해 AI 앱에 연결하도록 돕습니다.
rsi-arena
7.8kAIME나 Terminal-Bench 같은 표준 AI 벤치마크 테스트를 설정하고 실행해 서로 다른 개선 방법을 비교하도록 돕습니다.
experiment-guide
7.8k프로그램을 개선하는 방법을 조사하면서 작은 실험을 계획하고, 결과를 읽고, 발견 사항을 기록하도록 돕습니다.