-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Agent Toolkit installation after setup moments #10505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndrewAsseily
wants to merge
7
commits into
v2
Choose a base branch
from
nyandrew/agent-toolkit-configure-hint
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
221ca2c
Suggest Agent Toolkit setup after configure/update and in install scr…
AndrewAsseily dd97515
Add Agent Toolkit hint to aws login and configure sso
AndrewAsseily 60f043e
Address review feedback
AndrewAsseily 6a1aa5a
strip interactive hint from update command
AndrewAsseily 05f3aa3
Address review feedback
AndrewAsseily 5965e72
Show hint instead of prompt outside us-east-1
AndrewAsseily 51e7a13
Dropped the interactive prompt entirely, so everyone gets the same st…
AndrewAsseily File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "type": "enhancement", | ||
| "category": "configure", | ||
| "description": "Suggest installing the Agent Toolkit for AWS when a supported AI coding agent is detected. A one-line tip pointing at ``aws configure agent-toolkit`` is printed after ``aws configure``, ``aws configure sso``, and a first-time ``aws login`` that creates a new profile; it appears only on a terminal when no AWS skills are installed yet, and can be suppressed by setting the ``AWS_CLI_AGENT_TOOLKIT_HINT_DISABLED`` environment variable to ``true``. The same tip is also printed by the install scripts and after ``aws update``." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # 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. | ||
| """End-of-command hint pointing at the Agent Toolkit wizard. | ||
|
|
||
| After a successful ``aws configure``, ``aws configure sso``, or first-time | ||
| ``aws login``, print a one-line tip suggesting ``aws configure agent-toolkit`` | ||
| when a supported AI coding agent is present and no AWS skills are installed | ||
| yet. The tip only shows on a TTY and can be suppressed with an environment | ||
| variable. | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| from botocore.utils import ensure_boolean | ||
|
|
||
| from awscli.customizations.agenttoolkit.agents import ( | ||
| get_detected_real_agents, | ||
| ) | ||
| from awscli.customizations.utils import uni_print | ||
| from awscli.utils import is_a_tty | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
| HINT_DISABLED_ENV_VAR = 'AWS_CLI_AGENT_TOOLKIT_HINT_DISABLED' | ||
|
|
||
| # The Agent Toolkit skill APIs are only available in us-east-1 today, so the | ||
| # tip pins the region explicitly rather than routing the caller's configured | ||
| # region through a hidden cross-region call. | ||
| HINT_TEXT = ( | ||
| "\nTip: run 'aws configure agent-toolkit --region us-east-1' to set up " | ||
| 'AWS skills and the AWS MCP server for your AI coding agent(s).\n' | ||
| ) | ||
|
|
||
|
|
||
| def hint_disabled(): | ||
| return ensure_boolean(os.environ.get(HINT_DISABLED_ENV_VAR, '')) | ||
|
|
||
|
|
||
| def _has_installed_skills(detected_agents): | ||
| return any(agent.get_installed_skills() for agent in detected_agents) | ||
|
|
||
|
|
||
| def _is_eligible(): | ||
| if not is_a_tty(): | ||
| return False | ||
| if hint_disabled(): | ||
| return False | ||
| detected_agents = get_detected_real_agents() | ||
| if not detected_agents: | ||
| return False | ||
| if _has_installed_skills(detected_agents): | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def maybe_print_agent_toolkit_hint(): | ||
| try: | ||
| if _is_eligible(): | ||
| uni_print(HINT_TEXT) | ||
| except Exception as e: | ||
| LOG.debug('Agent toolkit hint failed: %s', e, exc_info=True) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # 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 MagicMock, patch | ||
|
|
||
| from awscli.customizations.agenttoolkit import hint | ||
|
|
||
|
|
||
| def _agent(installed_skills=None): | ||
| agent = MagicMock() | ||
| agent.get_installed_skills.return_value = installed_skills or [] | ||
| return agent | ||
|
|
||
|
|
||
| def _run(agents=None, tty=True): | ||
| if agents is None: | ||
| agents = [_agent()] | ||
| with ( | ||
| patch.object(hint, 'is_a_tty', return_value=tty), | ||
| patch.object(hint, 'get_detected_real_agents', return_value=agents), | ||
| ): | ||
| hint.maybe_print_agent_toolkit_hint() | ||
|
|
||
|
|
||
| def test_prints_tip_when_eligible(capsys): | ||
| _run() | ||
| assert '--region us-east-1' in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_no_tip_when_not_a_tty(capsys): | ||
| _run(tty=False) | ||
| assert capsys.readouterr().out == '' | ||
|
|
||
|
|
||
| def test_no_tip_when_env_var_true(capsys, monkeypatch): | ||
| monkeypatch.setenv(hint.HINT_DISABLED_ENV_VAR, 'true') | ||
| _run() | ||
| assert capsys.readouterr().out == '' | ||
|
|
||
|
|
||
| def test_tip_shown_when_env_var_false(capsys, monkeypatch): | ||
| monkeypatch.setenv(hint.HINT_DISABLED_ENV_VAR, 'false') | ||
| _run() | ||
| assert '--region us-east-1' in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_no_tip_when_no_agents(capsys): | ||
| _run(agents=[]) | ||
| assert capsys.readouterr().out == '' | ||
|
|
||
|
|
||
| def test_no_tip_when_skills_already_installed(capsys): | ||
| _run(agents=[_agent(installed_skills=['s'])]) | ||
| assert capsys.readouterr().out == '' | ||
|
|
||
|
|
||
| def test_detection_failure_does_not_raise(capsys): | ||
| with ( | ||
| patch.object(hint, 'is_a_tty', return_value=True), | ||
| patch.object( | ||
| hint, 'get_detected_real_agents', side_effect=OSError('boom') | ||
| ), | ||
| ): | ||
| hint.maybe_print_agent_toolkit_hint() | ||
| assert capsys.readouterr().out == '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.