Commit 7ed9493
authored
🤖 Add educational note when bash commands use cd (#444)
## Better UX: Teach instead of block
Instead of blocking redundant cd commands with complex heuristics (which
had false positives), we now add an agent-only `note` field to results
when commands start with cd. This educates the agent about the execution
model without blocking legitimate commands.
## Approach
**Problem:** Agents don't understand that cd doesn't persist between
bash tool calls, leading to redundant cd commands.
**Solution:** Inform rather than restrict.
1. **Detect cd usage**: Simple regex checks if command starts with `cd`
2. **Add note field**: Include educational message in tool result
3. **Agent sees, user doesn't**: Note appears in tool result JSON for
agent, but UI doesn't display it
4. **Agent learns**: Explicit feedback about how the execution model
works
## Example
**Agent executes:**
```bash
cd ~/workspace/project/branch && ls
```
**Tool result:**
```json
{
"success": true,
"output": "file1.txt\nfile2.txt",
"exitCode": 0,
"wall_duration_ms": 45,
"note": "Note: Each bash command starts in ~/workspace/project/branch. Directory changes (cd) do not persist between commands."
}
```
**User sees in UI:**
```
file1.txt
file2.txt
```
**Agent learns:** "Oh, I don't need to cd every time, I'm already in the
right directory."
## Advantages
| Aspect | This approach | Previous (blocking) |
|--------|--------------|---------------------|
| **False positives** | Zero (no heuristics) | Had false positives with
short paths |
| **Agent learning** | ✅ Explicit education | ❌ Just blocked without
explanation |
| **Works for all cds** | ✅ Yes (even legitimate ones) | ❌ Only
redundant cds |
| **Complexity** | ~15 LoC | ~40 LoC with heuristics |
| **User experience** | ✅ Clean (note hidden) | ✅ Clean |
| **Maintenance** | ✅ Simple regex | 1 parent 52d8403 commit 7ed9493
File tree
4 files changed
+22
-196
lines changed- src
- runtime
- services/tools
- types
4 files changed
+22
-196
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | 320 | | |
322 | 321 | | |
323 | 322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 701 | | |
791 | 702 | | |
792 | 703 | | |
| |||
1262 | 1173 | | |
1263 | 1174 | | |
1264 | 1175 | | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
1317 | | - | |
1318 | | - | |
1319 | | - | |
1320 | | - | |
1321 | | - | |
| 1176 | + | |
| 1177 | + | |
1322 | 1178 | | |
1323 | 1179 | | |
1324 | 1180 | | |
1325 | 1181 | | |
1326 | | - | |
| 1182 | + | |
1327 | 1183 | | |
1328 | 1184 | | |
1329 | 1185 | | |
1330 | 1186 | | |
1331 | 1187 | | |
1332 | | - | |
1333 | | - | |
1334 | | - | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1335 | 1193 | | |
1336 | 1194 | | |
1337 | 1195 | | |
1338 | | - | |
1339 | | - | |
| 1196 | + | |
| 1197 | + | |
1340 | 1198 | | |
1341 | 1199 | | |
1342 | 1200 | | |
1343 | 1201 | | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
| 1202 | + | |
1363 | 1203 | | |
1364 | 1204 | | |
1365 | 1205 | | |
1366 | 1206 | | |
1367 | 1207 | | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
| 1208 | + | |
| 1209 | + | |
1372 | 1210 | | |
1373 | 1211 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
99 | 84 | | |
100 | 85 | | |
101 | 86 | | |
| |||
392 | 377 | | |
393 | 378 | | |
394 | 379 | | |
| 380 | + | |
395 | 381 | | |
396 | 382 | | |
397 | 383 | | |
| |||
479 | 465 | | |
480 | 466 | | |
481 | 467 | | |
| 468 | + | |
482 | 469 | | |
483 | 470 | | |
484 | 471 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
0 commit comments