Commit 34df6b6
committed
🤖 Add educational note when bash commands use cd
Instead of blocking redundant cd commands with 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.
**Solution:** Inform rather than restrict.
1. Detect if command starts with `cd` (simple regex)
2. Add `note` field to BashToolResult with educational message
3. Agent sees note in tool result JSON, but UI doesn't display it
4. Agent learns the execution model through explicit feedback
## Example
```typescript
// Agent calls:
bash({ script: "cd ~/workspace/project && ls" })
// Result includes:
{
success: true,
output: "file1.txt\nfile2.txt",
exitCode: 0,
wall_duration_ms: 45,
note: "Note: Each bash command starts in ~/workspace/project. Directory changes (cd) do not persist between commands."
}
```
## Advantages over blocking approach
- ✅ Zero false positives (no complex heuristics)
- ✅ Educational (explains the behavior)
- ✅ Works for all cd cases (not just redundant ones)
- ✅ Simpler implementation (~15 LoC vs ~40 LoC)
- ✅ Cleaner UX (note hidden from user)
## Changes
- `src/types/tools.ts`: Added `note?: string` to BashToolResult
- `src/services/tools/bash.ts`: Detect cd and add note to success results
- `src/services/tools/bash.test.ts`: Removed blocking tests, added note verification tests
## Testing
- Removed all redundant cd blocking tests (no longer relevant)
- Added tests to verify note appears when cd is used
- Added test to verify note absent when cd not used
- Type checking and linting pass
_Generated with `cmux`_1 parent c564e72 commit 34df6b6
File tree
4 files changed
+23
-193
lines changed- src
- runtime
- services/tools
- types
4 files changed
+23
-193
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 | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
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 | 700 | | |
790 | 701 | | |
791 | 702 | | |
| |||
1261 | 1172 | | |
1262 | 1173 | | |
1263 | 1174 | | |
1264 | | - | |
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 | 1175 | | |
1319 | | - | |
1320 | | - | |
| 1176 | + | |
| 1177 | + | |
1321 | 1178 | | |
1322 | 1179 | | |
1323 | 1180 | | |
1324 | 1181 | | |
1325 | | - | |
| 1182 | + | |
1326 | 1183 | | |
1327 | 1184 | | |
1328 | 1185 | | |
1329 | 1186 | | |
1330 | 1187 | | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1334 | 1193 | | |
1335 | 1194 | | |
1336 | 1195 | | |
1337 | | - | |
1338 | | - | |
| 1196 | + | |
| 1197 | + | |
1339 | 1198 | | |
1340 | 1199 | | |
1341 | 1200 | | |
1342 | 1201 | | |
1343 | | - | |
| 1202 | + | |
1344 | 1203 | | |
1345 | 1204 | | |
1346 | 1205 | | |
1347 | 1206 | | |
1348 | 1207 | | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
| 1208 | + | |
| 1209 | + | |
1353 | 1210 | | |
1354 | 1211 | | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | 1212 | | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | 1213 | | |
| 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 | + | |
| 84 | + | |
99 | 85 | | |
100 | 86 | | |
101 | 87 | | |
| |||
392 | 378 | | |
393 | 379 | | |
394 | 380 | | |
| 381 | + | |
395 | 382 | | |
396 | 383 | | |
397 | 384 | | |
| |||
476 | 463 | | |
477 | 464 | | |
478 | 465 | | |
| 466 | + | |
479 | 467 | | |
480 | 468 | | |
481 | 469 | | |
| |||
| 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