From 5dc7bc055e86afaa1d0f55eed7e25b4192072b9a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 13:42:36 -0300 Subject: [PATCH 1/8] Whitelist more /cmds for no dirty commit --- HISTORY.md | 4 ++++ aider/coders/base_coder.py | 4 ++-- tests/test_coder.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 94b5fefa5..c48c726a9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # Release history +### GitHub main branch + +- + ### v0.9.0 - Support for the OpenAI models in [Azure](https://aider.chat/docs/faq.html#azure) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index f4b000acf..5ceea559f 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -407,8 +407,8 @@ class Coder: if cmds: matching_commands, _, _ = cmds if len(matching_commands) == 1: - cmd = matching_commands[0] - if cmd in ("/exit", "/commit"): + cmd = matching_commands[0][1:] + if cmd in "add clear commit diff drop exit help ls tokens".split(): return if not self.dirty_commits: diff --git a/tests/test_coder.py b/tests/test_coder.py index 80a92f902..41ae7e644 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -24,6 +24,26 @@ class TestCoder(unittest.TestCase): def tearDown(self): self.patcher.stop() + def test_should_dirty_commit(self): + # Mock the IO object + mock_io = MagicMock() + + with GitTemporaryDirectory(): + repo = git.Repo(Path.cwd()) + fname = Path("new.txt") + fname.touch() + repo.git.add(str(fname)) + repo.git.commit("-m", "new") + + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder.create(models.GPT4, None, mock_io) + + fname.write_text("hi") + self.assertTrue(coder.should_dirty_commit("hi")) + + self.assertFalse(coder.should_dirty_commit("/exit")) + self.assertFalse(coder.should_dirty_commit("/help")) + def test_check_for_file_mentions(self): # Mock the IO object mock_io = MagicMock() From 7df07c7ae7c88396459851643b467a7b2f5961de Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 13:55:10 -0300 Subject: [PATCH 2/8] aider: Add a table of contents to the `docs/install.md` file. # Aider chat conversation: USER: add a table of contents ASSISTANT: To add a table of contents to the `docs/install.md` file, we need to add a list of links to the headers in the document. Here is how to do it: markdown docs/install.md <<<<<<< ORIGINAL # Installing aider ## pip install aider-chat ======= # Installing aider - [Installing aider](#installing-aider) - [pip install aider-chat](#pip-install-aider-chat) - [Provide your OpenAI API key](#provide-your-openai-api-key) - [Install git](#install-git) - [Install universal ctags (optional)](#install-universal-ctags-optional) - [Add aider to your editor (optional)](#add-aider-to-your-editor-optional) ## pip install aider-chat >>>>>>> UPDATED This change adds a table of contents at the beginning of the document, with links to each of the main sections. The links use the header text, converted to lowercase and with spaces replaced by hyphens, as the target of the link. This is the standard way that markdown generates ids for headers, so these links will jump to the correct section when clicked. --- docs/install.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/install.md b/docs/install.md index 18f41196a..4c2c8e274 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,6 +1,13 @@ # Installing aider +- [Installing aider](#installing-aider) + - [pip install aider-chat](#pip-install-aider-chat) + - [Provide your OpenAI API key](#provide-your-openai-api-key) + - [Install git](#install-git) + - [Install universal ctags (optional)](#install-universal-ctags-optional) + - [Add aider to your editor (optional)](#add-aider-to-your-editor-optional) + ## pip install aider-chat Install the “aider-chat” package with pip from one of these sources: From 668b8841e2694b7599dfe300b61f0738a7165ba8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 13:56:46 -0300 Subject: [PATCH 3/8] outdent toc --- docs/install.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/install.md b/docs/install.md index 4c2c8e274..c607d7da6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,12 +1,11 @@ # Installing aider -- [Installing aider](#installing-aider) - - [pip install aider-chat](#pip-install-aider-chat) - - [Provide your OpenAI API key](#provide-your-openai-api-key) - - [Install git](#install-git) - - [Install universal ctags (optional)](#install-universal-ctags-optional) - - [Add aider to your editor (optional)](#add-aider-to-your-editor-optional) +- [pip install aider-chat](#pip-install-aider-chat) +- [Provide your OpenAI API key](#provide-your-openai-api-key) +- [Install git](#install-git) +- [Install universal ctags (optional)](#install-universal-ctags-optional) +- [Add aider to your editor (optional)](#add-aider-to-your-editor-optional) ## pip install aider-chat From 6244df835257f448c9fda37c02ba090ad651b40b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 14:12:01 -0300 Subject: [PATCH 4/8] aider: `get_input` now treats control+enter as a newline with prompt toolkit KeyBindings. # Aider chat conversation: USER: can we have `get_input` treat control+enter as a newline with prompt toolkit KeyBindings ASSISTANT: To implement this feature, we need to modify the `get_input` method in the `InputOutput` class in the `aider/io.py` file. We will use the `KeyBindings` class from `prompt_toolkit.keys` to bind the `Control+Enter` key combination to insert a newline. Here are the changes: ```python aider/io.py <<<<<<< ORIGINAL from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt ======= from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt from prompt_toolkit.keys import Keys from prompt_toolkit.key_binding import KeyBindings >>>>>>> UPDATED ```python aider/io.py <<<<<<< ORIGINAL session = PromptSession(**session_kwargs) ======= kb = KeyBindings() @kb.add(Keys.ControlJ, eager=True) def _(event): event.current_buffer.insert_text('\n') session = PromptSession(key_bindings=kb, **session_kwargs) >>>>>>> UPDATED ``` This code creates a new `KeyBindings` instance and adds a binding for `Control+Enter` (represented by `Keys.ControlJ`) to insert a newline. Then, it passes this key bindings instance to the `PromptSession` constructor. --- aider/io.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aider/io.py b/aider/io.py index c96f65d9a..43c4eb931 100644 --- a/aider/io.py +++ b/aider/io.py @@ -7,6 +7,8 @@ from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.history import FileHistory from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt +from prompt_toolkit.keys import Keys +from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.styles import Style from pygments.lexers import MarkdownLexer, guess_lexer_for_filename from pygments.token import Token @@ -203,7 +205,13 @@ class InputOutput: if self.input_history_file is not None: session_kwargs["history"] = FileHistory(self.input_history_file) - session = PromptSession(**session_kwargs) + kb = KeyBindings() + + @kb.add(Keys.ControlJ, eager=True) + def _(event): + event.current_buffer.insert_text('\n') + + session = PromptSession(key_bindings=kb, **session_kwargs) line = session.prompt() if line and line[0] == "{" and not multiline_input: From 36af2a51af5d707178fb17c44a7b8f6912478d12 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 14:15:18 -0300 Subject: [PATCH 5/8] Change keybinding from ControlJ to ControlM for inserting a new line. # Aider chat conversation: --- aider/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/io.py b/aider/io.py index 43c4eb931..c27b0069f 100644 --- a/aider/io.py +++ b/aider/io.py @@ -207,7 +207,7 @@ class InputOutput: kb = KeyBindings() - @kb.add(Keys.ControlJ, eager=True) + @kb.add(Keys.ControlM, eager=True) def _(event): event.current_buffer.insert_text('\n') From dbf3b09c064f3e53fcf103677587d885c1b0332d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 14:18:57 -0300 Subject: [PATCH 6/8] copy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 729996741..da5c69547 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Aider has some ability to help GPT figure out which files to edit all by itself, * Large changes are best performed as a sequence of thoughtful bite sized steps, where you plan out the approach and overall design. Walk GPT through changes like you might with a junior dev. Ask for a refactor to prepare, then ask for the actual change. Spend the time to ask for code quality/structure improvements. * Use Control-C to safely interrupt GPT if it isn't providing a useful response. The partial response remains in the conversation, so you can refer to it when you reply to GPT with more information or direction. * Use the `/run` command to run tests, linters, etc and show the output to GPT so it can fix any issues. -* Enter a multiline chat message by entering `{` alone on the first line. End the multiline message with `}` alone on the last line. +* Use Control+ENTER to enter a multiline chat message. Or enter `{` alone on the first line and end the multiline message with `}` alone on the last line. * If your code is throwing an error, share the error output with GPT using `/run` or by pasting it into the chat. Let GPT figure out and fix the bug. * GPT knows about a lot of standard tools and libraries, but may get some of the fine details wrong about APIs and function arguments. You can paste doc snippets into the chat to resolve these issues. * [Aider will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding](https://aider.chat/docs/faq.html#how-does-aider-use-git). From e7f35e2cf70444a1c0eb7581fff348be17ef8b4d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 14:26:49 -0300 Subject: [PATCH 7/8] Apparently prompt toolkit can not express control-enter? --- README.md | 2 +- aider/io.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da5c69547..12d22bb8d 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Aider has some ability to help GPT figure out which files to edit all by itself, * Large changes are best performed as a sequence of thoughtful bite sized steps, where you plan out the approach and overall design. Walk GPT through changes like you might with a junior dev. Ask for a refactor to prepare, then ask for the actual change. Spend the time to ask for code quality/structure improvements. * Use Control-C to safely interrupt GPT if it isn't providing a useful response. The partial response remains in the conversation, so you can refer to it when you reply to GPT with more information or direction. * Use the `/run` command to run tests, linters, etc and show the output to GPT so it can fix any issues. -* Use Control+ENTER to enter a multiline chat message. Or enter `{` alone on the first line and end the multiline message with `}` alone on the last line. +* Use ESC-ENTER to enter a multiline chat message. Or enter `{` alone on the first line and end the multiline message with `}` alone on the last line. * If your code is throwing an error, share the error output with GPT using `/run` or by pasting it into the chat. Let GPT figure out and fix the bug. * GPT knows about a lot of standard tools and libraries, but may get some of the fine details wrong about APIs and function arguments. You can paste doc snippets into the chat to resolve these issues. * [Aider will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding](https://aider.chat/docs/faq.html#how-does-aider-use-git). diff --git a/aider/io.py b/aider/io.py index c27b0069f..086813b61 100644 --- a/aider/io.py +++ b/aider/io.py @@ -5,10 +5,9 @@ from pathlib import Path from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.history import FileHistory +from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt -from prompt_toolkit.keys import Keys -from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.styles import Style from pygments.lexers import MarkdownLexer, guess_lexer_for_filename from pygments.token import Token @@ -207,9 +206,9 @@ class InputOutput: kb = KeyBindings() - @kb.add(Keys.ControlM, eager=True) + @kb.add("escape", "c-m", eager=True) def _(event): - event.current_buffer.insert_text('\n') + event.current_buffer.insert_text("\n") session = PromptSession(key_bindings=kb, **session_kwargs) line = session.prompt() From d349693205147ecccf8c19971889b04b4d809c13 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 17:36:19 -0300 Subject: [PATCH 8/8] copy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12d22bb8d..b54cb69a9 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Aider has some ability to help GPT figure out which files to edit all by itself, * Large changes are best performed as a sequence of thoughtful bite sized steps, where you plan out the approach and overall design. Walk GPT through changes like you might with a junior dev. Ask for a refactor to prepare, then ask for the actual change. Spend the time to ask for code quality/structure improvements. * Use Control-C to safely interrupt GPT if it isn't providing a useful response. The partial response remains in the conversation, so you can refer to it when you reply to GPT with more information or direction. * Use the `/run` command to run tests, linters, etc and show the output to GPT so it can fix any issues. -* Use ESC-ENTER to enter a multiline chat message. Or enter `{` alone on the first line and end the multiline message with `}` alone on the last line. +* Use Meta-ENTER (Esc+ENTER in some environments) to enter multiline chat messages. Or enter `{` alone on the first line to start a multiline message and `}` alone on the last line to end it. * If your code is throwing an error, share the error output with GPT using `/run` or by pasting it into the chat. Let GPT figure out and fix the bug. * GPT knows about a lot of standard tools and libraries, but may get some of the fine details wrong about APIs and function arguments. You can paste doc snippets into the chat to resolve these issues. * [Aider will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding](https://aider.chat/docs/faq.html#how-does-aider-use-git).