From 871188219b89caf1f6c8ee5a8b458deaadf4c23a Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 16 Dec 2025 15:15:37 +0100 Subject: [PATCH] Fix editor text clearing during compaction, fixes #179 --- packages/coding-agent/CHANGELOG.md | 1 + .../src/modes/interactive/interactive-mode.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index de739226..bdacf67b 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -14,6 +14,7 @@ ### Fixed +- Fixed editor text being cleared during compaction. Text typed while compaction is running is now preserved. ([#179](https://github.com/badlogic/pi-mono/issues/179)) - Improved RGB to 256-color mapping for terminals without truecolor support. Now correctly uses grayscale ramp for neutral colors and preserves semantic tints (green for success, red for error, blue for pending) instead of mapping everything to wrong cube colors. - `/think off` now actually disables thinking for all providers. Previously, providers like Gemini with "dynamic thinking" enabled by default would still use thinking even when turned off. ([#180](https://github.com/badlogic/pi-mono/pull/180) by [@markusylisiurunen](https://github.com/markusylisiurunen)) diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts index 8e291ef3..0c2cad11 100644 --- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts +++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts @@ -577,14 +577,19 @@ export class InteractiveMode { return; } if (text === "/clear") { - await this.handleClearCommand(); this.editor.setText(""); + await this.handleClearCommand(); return; } if (text === "/compact" || text.startsWith("/compact ")) { const customInstructions = text.startsWith("/compact ") ? text.slice(9).trim() : undefined; - await this.handleCompactCommand(customInstructions); this.editor.setText(""); + this.editor.disableSubmit = true; + try { + await this.handleCompactCommand(customInstructions); + } finally { + this.editor.disableSubmit = false; + } return; } if (text === "/autocompact") { @@ -625,7 +630,7 @@ export class InteractiveMode { } } - // Block input during compaction (will retry automatically) + // Block input during compaction if (this.session.isCompacting) { return; } @@ -789,6 +794,8 @@ export class InteractiveMode { break; case "auto_compaction_start": { + // Disable submit to preserve editor text during compaction + this.editor.disableSubmit = true; // Set up escape to abort auto-compaction this.autoCompactionEscapeHandler = this.editor.onEscape; this.editor.onEscape = () => { @@ -809,6 +816,8 @@ export class InteractiveMode { } case "auto_compaction_end": { + // Re-enable submit + this.editor.disableSubmit = false; // Restore escape handler if (this.autoCompactionEscapeHandler) { this.editor.onEscape = this.autoCompactionEscapeHandler;