|
23 | 23 | - **Testing**: Group related tests, use descriptive test names, mock external dependencies |
24 | 24 | - **File Editing**: Use eed (Enhanced Ed) for all file modifications - NEVER use Edit/MultiEdit tools |
25 | 25 |
|
26 | | -## Tool Usage Policy - Critical Understanding |
27 | | - |
28 | | -### Why Edit/MultiEdit are BANNED |
29 | | -Edit and MultiEdit waste massive amounts of tokens and time due to fundamental design flaws for AI workflows: |
30 | | - |
31 | | -**Problem 1: Forced Read Tax** |
32 | | -- Edit requires you to Read entire files before modification, even when Grep already told you the exact line |
33 | | -- Example: Change one line in a 500-line file = Read 500 lines + Edit = thousands of wasted tokens |
34 | | -- eed: Direct modification without reading = minimal tokens |
35 | | - |
36 | | -**Problem 2: The Try-Fail-Retry Loop** |
37 | | -- Edit fails on multiple matches → you retry with MultiEdit → wasted round trip |
38 | | -- This happens on almost every file with common patterns |
39 | | -- eed: Express intent clearly with patterns (s/old/new/ or s/old/new/g) - works first try |
40 | | - |
41 | | -**Real Cost Comparison** (modifying 5 files): |
42 | | -- Edit path: 5 Reads (10k tokens) + 2-3 failures + 7-10 tool calls = ~12 interactions |
43 | | -- eed path: 5 eed commands (500 tokens) + 0 failures = 5 interactions |
44 | | -- **20x efficiency gain with eed** |
45 | | - |
46 | | -### REQUIRED TOOL: eed (Enhanced Ed) |
47 | | -Use eed for ALL file modifications. Fallback to sed/awk only if eed unavailable. |
48 | | - |
49 | | -## Enhanced Ed (eed) Usage Guidelines |
50 | | - |
51 | | -### Why eed Exists - The Real Story |
52 | | -eed is not "just another editor" - it's a safety wrapper around ed that fixes the sharp edges: |
53 | | - |
54 | | -**What eed Does for You Automatically**: |
55 | | -1. **Smart operation ordering**: Converts `1a ... 5a ... 6a` to `6a→5a→1a` to prevent line number drift |
56 | | -2. **Auto-completion**: Adds missing `w` and `q` commands so you never lose changes |
57 | | -3. **Atomic commits**: Every edit is committed immediately with clear history |
58 | | -4. **Safe rollback**: `eed --undo` when things go wrong |
59 | | - |
60 | | -**Raw ed problems eed solves**: |
61 | | -- Line numbers shift after insertions/deletions → eed reorders operations |
62 | | -- Forgot to save → eed auto-saves |
63 | | -- Made a mistake → eed provides undo |
64 | | -- Need to track changes → eed commits everything |
65 | | - |
66 | | - |
67 | | -### Why Use eed |
68 | | -- **Atomic commits**: Every edit is automatically committed, making it safe to experiment |
69 | | -- **Easy rollback**: `eed --undo` instantly reverts the last change |
70 | | -- **Precision editing**: When you know line numbers, no need to re-read entire files |
71 | | -- **Consistent workflow**: Every edit follows the same pattern with clear commit messages |
72 | | - |
73 | | -### Learning Experience & First Steps |
74 | | -**Start with `eed --help`** - Don't be like me and jump in directly. Understanding the tool first saves debugging time later. |
75 | | - |
76 | | -**AI vs Human editing**: As AI, we need non-interactive, atomic edits. We can't use mouse, big screens, or make multiple changes before saving like humans. Each eed command must be complete and correct in one shot. |
77 | | - |
78 | | -**From beginner to proficient**: My eed journey this session: started bold but clumsy → got comfortable with basic patterns → became overconfident with complex edits → made silly mistakes when tired → learned that consistency beats cleverness. |
79 | | - |
80 | | - |
81 | | -### Quick Start - Your First eed Commands |
82 | | - |
83 | | -**Basic syntax (commit every change)**: |
84 | | -```bash |
85 | | -eed -m 'what you are doing' /path/to/file <<'EOF' |
86 | | -# ed commands here |
87 | | -w |
88 | | -q |
89 | | -EOF |
90 | | -``` |
91 | | - |
92 | | -**Most common operations**: |
93 | | -```bash |
94 | | -# 1. Simple substitution (first occurrence) |
95 | | -/pattern/s/old/new/ |
96 | | - |
97 | | -# 2. Global substitution (all occurrences) |
98 | | -s/old/new/g |
99 | | - |
100 | | -# 3. Substitute in specific pattern context |
101 | | -/function_name/s/old/new/ |
102 | | - |
103 | | -# 4. Delete lines matching pattern |
104 | | -/pattern_to_delete/d |
105 | | - |
106 | | -# 5. Append after matching line |
107 | | -/pattern/a |
108 | | -new line content here |
109 | | -. |
110 | | - |
111 | | -# 6. Change (replace) matching line |
112 | | -/pattern/c |
113 | | -replacement line |
114 | | -. |
115 | | -``` |
116 | | - |
117 | | -**When grep finds what you need**: |
118 | | -```bash |
119 | | -# grep tells you: "lib/foo.dart:42: some old code" |
120 | | -# Don't Read the file! Just: |
121 | | -eed -m 'fix the thing' lib/foo.dart <<'EOF' |
122 | | -/old code/s/old/new/ |
123 | | -w |
124 | | -q |
125 | | -EOF |
126 | | -``` |
127 | | - |
128 | | -### Practical eed Tips |
129 | | - |
130 | | -**Pattern-based editing** (avoid line number dependency): |
131 | | -- `/function_name/,/^}/d` - Delete entire function |
132 | | -- `/import.*flutter/a` - Add after import section |
133 | | -- `s/old_pattern/new_pattern/g` - Global replace |
134 | | - |
135 | | -**Common scenarios**: |
136 | | -- Single-line fix: Use `/pattern/s/old/new/` |
137 | | -- Multiple files: Run parallel eed commands (no Read needed!) |
138 | | -- Uncertain change: Make the edit, test, `eed --undo` if wrong |
139 | | - |
140 | | -**Error recovery**: |
141 | | -- Wrong edit → `eed --undo` immediately |
142 | | -- Complex edit → Break into multiple simple eed commands |
143 | | -- Preview first → Read the file ONLY if you need to understand context |
144 | | - |
145 | 26 | **Key insight**: With eed, you express *intent* (what to change and where), not *exact text* (like Edit requires). This makes it robust and efficient |
0 commit comments