feat: add Ctrl+E keybinding to open prompt in external editor by monotykamary · Pull Request #218 · evalstate/fast-agent · GitHub
Skip to content

feat: add Ctrl+E keybinding to open prompt in external editor#218

Merged
evalstate merged 2 commits into
evalstate:mainfrom
monotykamary:feat/add-editor-keybinding
Jun 7, 2025
Merged

feat: add Ctrl+E keybinding to open prompt in external editor#218
evalstate merged 2 commits into
evalstate:mainfrom
monotykamary:feat/add-editor-keybinding

Conversation

@monotykamary

@monotykamary monotykamary commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

Description

This pull request introduces a new feature that allows users to edit the current input prompt in an external editor by pressing Ctrl+E.

Screen.Recording.2025-06-06.at.11.56.36.mov

This functionality enhances the user experience for fast-agent's interactive prompt, especially when composing complex or multi-line inputs.

Changes Made

  • Added a new asynchronous keybinding Ctrl+E to src/mcp_agent/core/enhanced_prompt.py.
  • Implemented a helper function get_text_from_editor within the same file that:
    • Determines the user's preferred editor (from $VISUAL, then $EDITOR, with fallbacks to nano or vim).
    • Creates a temporary file with the current prompt buffer's content.
    • Launches the editor using subprocess.run.
    • Reads the modified content from the temporary file after the editor is closed.
    • Updates the prompt buffer with the edited text.
    • Includes error handling for editor not found, editor errors, and temporary file issues.
  • Ensured that the editor invocation is run in a separate thread using asyncio.to_thread to prevent blocking the main asyncio event loop.
  • Updated the help text in handle_special_commands to include the new Ctrl+E shortcut.

How to Test

  1. Run fast-agent in interactive mode (e.g., uv run agent.py).
  2. At the prompt, type some text.
  3. Press Ctrl+E.
  4. Your default system editor (or $VISUAL/$EDITOR) should open with the text from the prompt.
  5. Modify the text in the editor, save, and close the editor.
  6. The prompt in fast-agent should now display the updated text from the editor.
  7. Test with multi-line inputs and various editors if possible.

This change leverages prompt_toolkit's keybinding system and Python's subprocess and tempfile modules.

@evalstate evalstate left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this, great feature!!!

@evalstate evalstate merged commit aa05d4d into evalstate:main Jun 7, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants