Aller au contenu
Skillpedia
Programmation générale7.8k · #13057

large-file-write-heredoc

Ce qu’il fait

Cette compétence donne à l'agent IA une méthode de secours pour écrire un gros fichier lorsque ses outils d'écriture échouent avec des erreurs inconnues. Elle s'adresse aux personnes qui enregistrent des documents longs ou des fichiers de code.

Quand l’utiliser

  • ✓Quand l'outil d'écriture échoue avec une erreur inconnue sur un gros fichier.
  • ✓Quand l'agent shell échoue aussi parce que le contenu en ligne est trop volumineux.
  • ✓Quand vous avez besoin qu'un long fichier soit enregistré exactement tel qu'il a été fourni.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-heredoc/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Enregistre ce long fichier de configuration dans mon projet. L'outil d'écriture échoue à cause de la taille, donc utilise une autre méthode.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'agent essaie d'abord l'outil d'écriture habituel. En cas d'échec, il envoie tout le contenu du fichier par un heredoc Python dans un appel qui écrit le fichier, en contournant les limites de taille des autres outils.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

Large File Write Fallback

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.

Solution

Use run_shell with a Python heredoc pattern. This streams the file content through stdin directly into Python's open(), bypassing the payload constraints of the other tools.

Template

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.

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:

    • Embed the full file content inside a Python triple-quoted string.
    • Specify the target path inside the open() call.
    • Pass the entire block 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:

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 + Python heredoc
shell_agent also fails on large inline content run_shell + Python heredoc

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.
Questions fréquentes

Pourquoi l'écriture habituelle échoue-t-elle ?

La compétence indique que l'outil d'écriture a une taille maximale par appel, que les gros fichiers peuvent dépasser.

Que faut-il échapper ?

Les antislashs et les guillemets du contenu peuvent demander de l'attention pour être enregistrés comme prévu.

L'agent doit-il réessayer avec l'agent shell ?

La compétence indique que non, car le contenu en ligne échouera probablement là aussi pour la même raison.

Détails

Description originale de l’auteur

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.

repo: HKUDS/AgentPilot

Popularité

Étoiles GitHub
7.8k
Position au classement
#13057
Licence
MIT
Mis à jour
01/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires