From c231568d1f243acf1d39450ba71dee09bbd08308 Mon Sep 17 00:00:00 2001 From: James Ward Date: Wed, 26 Aug 2026 12:43:29 -0600 Subject: [PATCH] Fix agent-toolkit prompt defaults Treat an empty response as acceptance of the displayed default for the Agent Toolkit installation and MCP configuration prompts. --- .../customizations/agenttoolkit/configure.py | 5 ++-- awscli/customizations/prompts.py | 5 +++- tests/unit/customizations/test_prompts.py | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/unit/customizations/test_prompts.py diff --git a/awscli/customizations/agenttoolkit/configure.py b/awscli/customizations/agenttoolkit/configure.py index 834752183f07..d8aedeae9cff 100644 --- a/awscli/customizations/agenttoolkit/configure.py +++ b/awscli/customizations/agenttoolkit/configure.py @@ -146,7 +146,8 @@ def _install_default_skills(self, selected_agents, client, yes=False): uni_print(f' Found: {names}\n', self._stream) if not yes and not yes_no_choice( - f'\nInstall {len(default_skills)} default AWS skills? [Y/n]: ' + f'\nInstall {len(default_skills)} default AWS skills? [Y/n]: ', + default=True, ): return @@ -196,7 +197,7 @@ def _install_default_skills(self, selected_agents, client, yes=False): def _configure_mcp(self, agents, yes=False): if not yes and not yes_no_choice( - '\nConfigure AWS MCP server connection? [Y/n]: ' + '\nConfigure AWS MCP server connection? [Y/n]: ', default=True ): return diff --git a/awscli/customizations/prompts.py b/awscli/customizations/prompts.py index a1a9921d1b24..e2e74311a42b 100644 --- a/awscli/customizations/prompts.py +++ b/awscli/customizations/prompts.py @@ -16,17 +16,20 @@ from awscli.utils import is_stdin_a_tty -def yes_no_choice(prompt): +def yes_no_choice(prompt, default=None): """ Prompts the user to answer a yes/no question. Continually re-prompts for invalid selections. :param prompt: Prompt text. + :param default: Optional boolean returned when the response is empty. :returns: True for yes, False for no. """ while True: response = compat_input(prompt) + if response == '' and default is not None: + return default if response.lower() in ('y', 'yes'): return True elif response.lower() in ('n', 'no'): diff --git a/tests/unit/customizations/test_prompts.py b/tests/unit/customizations/test_prompts.py new file mode 100644 index 000000000000..f65bffa4c705 --- /dev/null +++ b/tests/unit/customizations/test_prompts.py @@ -0,0 +1,24 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +from unittest.mock import patch + +from awscli.customizations.prompts import yes_no_choice + + +def test_enter_accepts_yes_default(): + with patch( + 'awscli.customizations.prompts.compat_input', return_value='' + ) as input_mock: + assert yes_no_choice('Continue? [Y/n]: ', default=True) + + input_mock.assert_called_once_with('Continue? [Y/n]: ')