From f8d80a664c5417bd92f940f987ccb35250ccdf43 Mon Sep 17 00:00:00 2001 From: laststylebender14 Date: Mon, 9 Mar 2026 13:04:37 +0530 Subject: [PATCH 1/3] fix(shell-plugin): clear BUFFER before action output to prevent display corruption --- crates/forge_main/src/built_in_commands.json | 4 ++++ shell-plugin/forge.plugin.zsh | 1 + shell-plugin/lib/actions/echo.zsh | 13 +++++++++++++ shell-plugin/lib/dispatcher.zsh | 15 +++++++++++---- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 shell-plugin/lib/actions/echo.zsh diff --git a/crates/forge_main/src/built_in_commands.json b/crates/forge_main/src/built_in_commands.json index 1bf786a2d1..3fd7851a72 100644 --- a/crates/forge_main/src/built_in_commands.json +++ b/crates/forge_main/src/built_in_commands.json @@ -99,6 +99,10 @@ "command": "keyboard-shortcuts", "description": "Display ZSH keyboard shortcuts [alias: kb]" }, + { + "command": "echo", + "description": "Echo the input text" + }, { "command": "setup", "description": "Setup zsh integration by updating .zshrc" diff --git a/shell-plugin/forge.plugin.zsh b/shell-plugin/forge.plugin.zsh index e877afdff7..8f92c395f8 100755 --- a/shell-plugin/forge.plugin.zsh +++ b/shell-plugin/forge.plugin.zsh @@ -26,6 +26,7 @@ source "${0:A:h}/lib/actions/editor.zsh" source "${0:A:h}/lib/actions/provider.zsh" source "${0:A:h}/lib/actions/doctor.zsh" source "${0:A:h}/lib/actions/keyboard.zsh" +source "${0:A:h}/lib/actions/echo.zsh" # Main dispatcher and widget registration source "${0:A:h}/lib/dispatcher.zsh" diff --git a/shell-plugin/lib/actions/echo.zsh b/shell-plugin/lib/actions/echo.zsh new file mode 100644 index 0000000000..b9a988778c --- /dev/null +++ b/shell-plugin/lib/actions/echo.zsh @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh + +# Echo action handler + +# Action handler: Echo the input text +function _forge_action_echo() { + local input_text="$1" + + echo + if [[ -n "$input_text" ]]; then + echo "$input_text" + fi +} diff --git a/shell-plugin/lib/dispatcher.zsh b/shell-plugin/lib/dispatcher.zsh index 70703379e6..2d36270d40 100644 --- a/shell-plugin/lib/dispatcher.zsh +++ b/shell-plugin/lib/dispatcher.zsh @@ -112,10 +112,14 @@ function forge-accept-line() { # Add the original command to history before transformation print -s -- "$original_buffer" - # CRITICAL: Move cursor to end so output doesn't overwrite - # Don't clear BUFFER yet - let _forge_reset do that after action completes - # This keeps buffer state consistent if Ctrl+C is pressed - CURSOR=${#BUFFER} + # Shrink ZLE's tracked display height BEFORE actions print output. + # ZLE remembers how many terminal lines its display occupies. If the typed + # command wrapped across N lines, reset-prompt (in _forge_reset) would move + # up N lines and clear them — wiping N lines of action output. Clearing + # BUFFER and calling redisplay forces ZLE to re-render as a 1-line empty + # prompt, so the later reset-prompt only clears 1 line. + BUFFER="" + CURSOR=0 zle redisplay # Handle aliases - convert to their actual agent names @@ -217,6 +221,9 @@ function forge-accept-line() { keyboard-shortcuts|kb) _forge_action_keyboard ;; + echo) + _forge_action_echo "$input_text" + ;; *) _forge_action_default "$user_action" "$input_text" ;; From 758cabbd181979cc1cab4ef55992bf83dc2a1368 Mon Sep 17 00:00:00 2001 From: laststylebender14 Date: Mon, 9 Mar 2026 13:12:52 +0530 Subject: [PATCH 2/3] - revert --- shell-plugin/lib/dispatcher.zsh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/shell-plugin/lib/dispatcher.zsh b/shell-plugin/lib/dispatcher.zsh index 2d36270d40..abaaa90c6c 100644 --- a/shell-plugin/lib/dispatcher.zsh +++ b/shell-plugin/lib/dispatcher.zsh @@ -112,14 +112,10 @@ function forge-accept-line() { # Add the original command to history before transformation print -s -- "$original_buffer" - # Shrink ZLE's tracked display height BEFORE actions print output. - # ZLE remembers how many terminal lines its display occupies. If the typed - # command wrapped across N lines, reset-prompt (in _forge_reset) would move - # up N lines and clear them — wiping N lines of action output. Clearing - # BUFFER and calling redisplay forces ZLE to re-render as a 1-line empty - # prompt, so the later reset-prompt only clears 1 line. - BUFFER="" - CURSOR=0 + # CRITICAL: Move cursor to end so output doesn't overwrite + # Don't clear BUFFER yet - let _forge_reset do that after action completes + # This keeps buffer state consistent if Ctrl+C is pressed + CURSOR=${#BUFFER} zle redisplay # Handle aliases - convert to their actual agent names From 5ac8cbbcb4d67c05e7686319877b77b872d4c09a Mon Sep 17 00:00:00 2001 From: laststylebender14 Date: Wed, 11 Mar 2026 18:06:43 +0530 Subject: [PATCH 3/3] fix(shell-plugin): add zle -I to prevent display corruption --- shell-plugin/lib/actions/echo.zsh | 2 -- shell-plugin/lib/dispatcher.zsh | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/shell-plugin/lib/actions/echo.zsh b/shell-plugin/lib/actions/echo.zsh index b9a988778c..4656c68d1f 100644 --- a/shell-plugin/lib/actions/echo.zsh +++ b/shell-plugin/lib/actions/echo.zsh @@ -5,8 +5,6 @@ # Action handler: Echo the input text function _forge_action_echo() { local input_text="$1" - - echo if [[ -n "$input_text" ]]; then echo "$input_text" fi diff --git a/shell-plugin/lib/dispatcher.zsh b/shell-plugin/lib/dispatcher.zsh index abaaa90c6c..08e0f609c3 100644 --- a/shell-plugin/lib/dispatcher.zsh +++ b/shell-plugin/lib/dispatcher.zsh @@ -65,8 +65,6 @@ function _forge_action_default() { _FORGE_CONVERSATION_ID="$new_id" fi - echo - # Only set the agent if user explicitly specified one if [[ -n "$user_action" ]]; then _FORGE_ACTIVE_AGENT="$user_action" @@ -218,9 +216,11 @@ function forge-accept-line() { _forge_action_keyboard ;; echo) + zle -I _forge_action_echo "$input_text" ;; *) + zle -I _forge_action_default "$user_action" "$input_text" ;; esac