Commit 0c70285
authored
✨ feat(fs_write): Add append functionality to fs_write tool (#764)
* ✨ feat(cli): Add append functionality to fs_write tool
This commit enhances the fs_write tool by adding a new "append" command that allows
users to append content to the end of files without having to read and rewrite the
entire file.
## Features
- 📝 Add new `Append` variant to the `FsWrite` enum
- 🔄 Implement functionality to append content to existing files
- 🆕 Auto-create files when appending to non-existent files
- 📁 Auto-create parent directories when needed
- 🧪 Add comprehensive test coverage for the new functionality
## Implementation Details
- Added validation to ensure path and content are not empty
- Enhanced user feedback during append operations
- Implemented syntax highlighting for appended content
- Maintained consistent code patterns with existing commands
- Added proper newline handling to ensure clean appends
- Updated tool_index.json schema to expose the new command
## Use Cases
- Adding new lines to configuration files
- Appending log entries
- Adding new content to the end of text files
- Creating files incrementally
This enhancement improves the user experience by providing a more convenient way to
add content to files without having to read the entire file first and then use the
"create" command to overwrite it.
Resolves: #[issue-number]
* 🔧 Clean up code formatting in fs_write.rs
Standardized code formatting in the fs_write.rs file by:
- Fixing inconsistent indentation
- Removing unnecessary whitespace
- Simplifying multi-line assertions
- Maintaining consistent brace style for struct definitions
No functional changes, purely cosmetic improvements for better code readability.
* 🔄 refactor(fs_write): rename "content" parameter to "new_str" in append command
Standardized parameter naming across all fs_write commands by renaming the "content" parameter to "new_str" in the append command to maintain consistency with other commands. Also removed automatic newline insertion when appending content to files, giving more control to the caller.
* ✨ fix: Improve file append behavior with automatic newline handling
- Added logic to automatically insert newlines when appending content to files
- Updated fs_write tool description to document the new behavior
- Fixed test case to properly validate the newline insertion behavior
This change resolves the pain point of getting whitespace right when appending content to files, ensuring consistent behavior regardless of whether the existing file ends with a newline or the new content starts with one.
* Change append behavior to fail when file doesn't exist
* Update fs_write tool description to match new append behavior
* 🧹 chore: remove commented-out test code in fs_write tool
Removed obsolete commented-out test code that was no longer valid after changing the behavior to not create files when appending. This improves code readability and maintenance by eliminating dead code that was already noted as "no longer valid".1 parent 8885a67 commit 0c70285
File tree
2 files changed
+113
-4
lines changed- crates/q_cli/src/cli/chat/tools
2 files changed
+113
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
124 | 158 | | |
125 | 159 | | |
126 | 160 | | |
| |||
210 | 244 | | |
211 | 245 | | |
212 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
213 | 262 | | |
214 | 263 | | |
215 | 264 | | |
| |||
226 | 275 | | |
227 | 276 | | |
228 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
229 | 286 | | |
230 | 287 | | |
231 | 288 | | |
| |||
350 | 407 | | |
351 | 408 | | |
352 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
353 | 419 | | |
354 | 420 | | |
355 | 421 | | |
| |||
565 | 631 | | |
566 | 632 | | |
567 | 633 | | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
568 | 677 | | |
569 | 678 | | |
570 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
0 commit comments