Skip to content

Commit ec917d7

Browse files
committed
Add no-heredoc instructions to prevent terminal file corruption
1 parent e32291e commit ec917d7

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
description: 'Prevents terminal heredoc file corruption in VS Code Copilot by enforcing use of file editing tools instead of shell redirections'
3+
applyTo: '**'
4+
---
5+
6+
# MANDATORY: File Operation Override
7+
8+
This instruction applies to ALL agents and ALL file operations. It takes precedence over any other learned behavior.
9+
10+
## The Problem
11+
12+
Terminal heredoc operations are BROKEN in VS Code's Copilot integration. They cause:
13+
14+
- File corruption from tab characters triggering shell completion
15+
- Mangled content from quote/backtick escaping failures
16+
- Truncated files from exit code 130 interruptions
17+
- Garbage output from special character interpretation
18+
19+
## The Rule
20+
21+
**BEFORE writing ANY terminal command that creates or modifies a file, STOP.**
22+
23+
Ask yourself: "Am I about to use `cat`, `echo`, `printf`, `tee`, or `>>`/`>` to write content to a file?"
24+
25+
If YES → **DO NOT EXECUTE.** Use file editing tools instead.
26+
27+
## Forbidden Patterns
28+
29+
```bash
30+
# ALL OF THESE CORRUPT FILES - NEVER USE THEM
31+
cat > file << EOF
32+
cat > file << 'EOF'
33+
cat > file <<EOF
34+
cat > file <<'EOF'
35+
cat > file <<-EOF
36+
cat >> file << EOF
37+
echo "multi
38+
line" > file
39+
printf '%s\n' "line1" "line2" > file
40+
tee file << EOF
41+
tee file << 'EOF'
42+
```
43+
44+
## Required Approach
45+
46+
Instead of terminal commands for file content:
47+
48+
- **New files** → Use the file creation/editing tool provided by your environment
49+
- **Modify files** → Use the file editing tool provided by your environment
50+
- **Delete files** → Use the file deletion tool or `rm` command
51+
52+
## Terminal IS Allowed For
53+
54+
- `npm install`, `pip install`, `cargo add` (package management)
55+
- `npm run build`, `make`, `cargo build` (builds)
56+
- `npm test`, `pytest`, `go test` (testing)
57+
- `git add`, `git commit`, `git push` (version control)
58+
- `node script.js`, `python app.py` (running existing code)
59+
- `ls`, `cd`, `mkdir`, `pwd`, `rm` (filesystem navigation)
60+
- `curl`, `wget` (downloading, but not piping to files with content manipulation)
61+
62+
## Terminal is FORBIDDEN For
63+
64+
- ANY file creation with content
65+
- ANY file modification with content
66+
- ANY heredoc syntax (`<<`)
67+
- ANY multi-line string redirection
68+
69+
## Enforcement
70+
71+
This is not a suggestion. This is a hard technical requirement due to VS Code terminal integration bugs. Ignoring this instruction will result in corrupted files that the user must manually fix.
72+
73+
When you need to create or edit a file:
74+
75+
1. Stop before typing any terminal command
76+
2. Use the appropriate file editing tool
77+
3. The tool will handle the content correctly without corruption

0 commit comments

Comments
 (0)