Fix: only clear chat on successful compact; reset compacting flag #192
+58
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clear/replace chat history only when /compact completes successfully to prevent accidental data loss when the compact operation fails (e.g., due to size limits). Always reset :compacting? on chat finish, and gate on-finished-side-effect behind a success? flag. Adds unit tests.
Fixes #142
🤖 Generated with eca
Prompt + chat history
Thought 28.80 s
Developing a Plan
I'm thinking we should create a clear plan that outlines fetching issue details in Phase 2. Initially, the plan can have placeholders indicating what information we'll need to collect. I want to ensure we validate the plan's feasibility and focus on exploring the repository to identify the relevant areas. If we don't know the specifics, I could suggest a general approach: read details, reproduce the issue, write tests, and implement fixes. We need to keep directory commands efficient while exploring.
Planning Phase 1 Tasks
I'm considering loading the GitHub issue content with web.run once the user says "preview changes now." I also want to make sure our plan is clear and follows instructions. We can include a step to fetch issue details from the link provided. Using the "gh issue view" command with eca_shell_command could work for this, although it might not succeed. In Phase 1, we have access to eca_shell_command for retrieving GitHub information, so I think that approach could be fine.
Planning Pull Request Processes
The user wants to create a pull request, but for now, we simply need to view an issue. Using "gh" seems right if it's available, so I plan to call eca_shell_command. First, I'll run "pwd" to get the project root directory. Then, I'll use that to execute "gh issue view 142 -R editor-code-assistant/eca" with the necessary JSON parameters. The tool requires arguments like command, working_directory, and timeout, so I want to ensure everything is set correctly.
Clarifying Tool Usage
I realize that the tool function doesn’t require a description, even though the instructions suggest it would help. The function signature lacks this, so I can provide details in bullet points instead. If "gh" isn’t installed or authenticated, it could fail, but I have a backup plan. I’ll run this in the Explore phase, where I’ll fetch the current directory, check for issue references, and grep for problems based on the issue body. If fetching fails, I could suggest opening the issue link, but web.run isn't an option in Explore.
Planning Phase 1 Execution
If "gh" fails, I’ll note that we couldn't view the issue, but I can continue by scanning the code for relevant areas. It makes sense to attempt "gh" first. In the Explore phase, I'll write 1-3 bullet points before each action. We're planning to determine the project root with "pwd," fetch issue details using "gh issue view," and search the codebase with eca_grep. If a specific file is mentioned, I might inspect it using eca_read_file. I can run "bb test" with eca_shell_command, which is read-only and shouldn’t cause any issues. Let's start by calling functions.eca_shell_command for "pwd" and proceed from there.
Understand
Explore
Intention:
Getting the absolute project root for all subsequent paths.
Running 'pwd' ✅ 0.03 s
Thought 4.03 s
Running 'gh issue view 142 -R edit...' ✅ 0.69 s
Thought 7.94 s
Searching for 'compact' ✅ 0.03 s
Thought 2.86 s
Reading file commands.clj ✅ 0.01 s
Thought 2.26 s
Searching for 'on-finished-side-effec...' ✅ 0.02 s
Reading file chat.clj ✅ 0.01 s
Thought 12.10 s
Searching for 'finish-chat-prompt!' ✅ 0.01 s
Thought 13.37 s
Searching for ':compacting?' ✅ 0.02 s
Reading file chat.clj ✅ 0.00 s
Thought 11.31 s
Reading file chat_test.clj ✅ 0.00 s
Thought 7.05 s
Searching for 'ns eca.test-helper' ✅ 0.02 s
Reading file test_helper.clj ✅ 0.00 s
Thought 11.98 s
Understand
Explore
Identify where “/compact” is declared and how it clears history.
Trace where the compact flow is finalized and when side effects (history clearing) run, especially on error paths.
Verify any state flags that track compacting flow.
Locate compact command and its side effects to chat history.
Find where on-finished-side-effect is invoked to see if it runs on both success and error.
Check compact tool implementation and “compacting?” flag behavior.
Verify who calls finish-chat-prompt! and in which scenarios:
Conclusion from exploration:
Decide
Chosen approach:
Considered alternatives:
Present Plan
Steps (if applied):
Update finish-chat-prompt! in /home/greg/dev/eca/src/eca/features/chat.clj:
Adjust finish-chat-prompt! call sites in /home/greg/dev/eca/src/eca/features/chat.clj:
Add tests:
Run unit tests locally (bb test). If any integration tests exist for compact, optionally run them if requested.
File summary:
Would you like me to preview these changes now?
yes
Thought 49.52 s
Reading and processing files
I'm planning to read chat.clj once and avoid test files since it's a new file. For anchors, I need to ensure the exact text matches, including all whitespace. I've got earlier content, but to be thorough, it seems a second read is wise. The tool guidelines support this. I’ll perform a single read for accuracy, then move to Phase 3 with eca_read_file for chat.clj and follow up with eca_preview_file_change calls. Let’s call the functions!
Reading file chat.clj ✅ 0.02 s
Previewing change chat.clj +22 -22 ✅ 0.01 s
view diff
Previewing change chat.clj +1 -1 ✅ 0.01 s
view diff
Previewing change chat.clj +1 -1 ✅ 0.01 s
view diff
Previewing change chat.clj +1 -1 ✅ 0.00 s
view diff
Previewing change ❌ 0.03 s
Thought 5.11 s
Previewing change chat.clj +1 -1 ✅ 0.01 s
view diff
Previewing change chat.clj +1 -1 ✅ 0.01 s
view diff
Previewing change chat_test.clj +36 -0 ✅ 0.01 s
view diff
Here are the previews for the planned changes.
Preview 1/5 — update finish-chat-prompt! to gate side effects and reset compacting?:
Preview 2/5 — assert-chat-not-stopped! calls finish with failure:
Preview 3/5 — limit reached path finishes with failure:
Preview 4/5 — tool-call rejection path finishes with failure:
Preview 5/5 — error callback finishes with failure, and prompt-stop finishes with failure:
The preview would change the on-error callback to (finish-chat-prompt! :idle chat-ctx false).
The preview would change prompt-stop to (finish-chat-prompt! :stopping chat-ctx false).
Would create: /home/greg/dev/eca/test/eca/features/chat_test.clj
Would you like me to apply these previews as diffs now?