-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add initial Q Developer customization #9470
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
Merged
+468
−2
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a0d8d0
Add initial Q Developer customization
ashovlin 1ba81f1
Exclude from autocomplete model indexing
ashovlin 5941846
Move entrypoint to --agent-mode
ashovlin 457423a
Consider AWS_DATA_PATH when looking for extensions
ashovlin c136e57
Fix tests for Windows
ashovlin 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,62 @@ | ||
# 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. | ||
|
||
import argparse | ||
|
||
from awscli.argparser import CLIArgParser | ||
from awscli.customizations.q.chat import ChatCommand | ||
|
||
|
||
class AgentModeDriver(CLIArgParser): | ||
""" | ||
Driver for the CLI to enable the Q plugin when the --agent-mode argument | ||
is passed. This behaves more like a custom command, but is implemented | ||
as a driver similar to autoprompt so we don't need to expose it as an | ||
actual command via the command table. | ||
""" | ||
|
||
_AGENT_MODE_ARG = '--agent-mode' | ||
|
||
def __init__(self, driver): | ||
super().__init__() | ||
self._driver = driver | ||
self._session = driver.session | ||
self._parser = self._create_parser() | ||
|
||
def _create_parser(self): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'--region', | ||
help='AWS region to use for agent inference.', | ||
default=None, | ||
) | ||
parser.add_argument( | ||
'--profile', | ||
help='Use a specific profile from your credential file.', | ||
default=None, | ||
) | ||
parser.add_argument( | ||
self._AGENT_MODE_ARG, | ||
action='store_true', | ||
help='Enable agentic mode.', | ||
) | ||
return parser | ||
|
||
def should_enter_agent_mode(self, args): | ||
return self._AGENT_MODE_ARG in args | ||
|
||
def enter_agent_mode(self, args): | ||
parsed_args = self._parser.parse_args(args) | ||
|
||
# TODO - handle the agent-mode-specific region and profile | ||
return ChatCommand(self._session)('', parsed_args) |
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,42 @@ | ||
# 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 awscli.customizations.commands import BasicCommand | ||
from awscli.customizations.q.chat import ChatCommand | ||
from awscli.customizations.q.uninstall import UninstallCommand | ||
from awscli.customizations.q.update import UpdateCommand | ||
|
||
|
||
def register_q_commands(event_handlers): | ||
event_handlers.register('building-command-table.main', inject_commands) | ||
|
||
|
||
def inject_commands(command_table, session, **kwargs): | ||
command_table['q'] = QCommand(session) | ||
|
||
|
||
class QCommand(BasicCommand): | ||
# 'TODO help prints "System Message: WARNING/2 (<string>:, line 7)" | ||
# but not figuring out yet since naming may still change | ||
NAME = 'q' | ||
SYNOPSIS = 'q <command> [<args>]' | ||
DESCRIPTION = ( | ||
'You can use Amazon Q Developer to translate natural language to ' | ||
'AWS CLI commands. Run ``aws q chat`` to launch the Q CLI. You can ' | ||
'update to the latest version of the Q plugin with ``aws q update``.' | ||
) | ||
SUBCOMMANDS = [ | ||
{'name': 'chat', 'command_class': ChatCommand}, | ||
{'name': 'update', 'command_class': UpdateCommand}, | ||
{'name': 'uninstall', 'command_class': UninstallCommand}, | ||
] |
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,39 @@ | ||
# 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. | ||
|
||
import subprocess | ||
|
||
from botocore.utils import original_ld_library_path | ||
|
||
from awscli.customizations.commands import BasicCommand | ||
from awscli.customizations.q.utils import _get_executable_path_or_download | ||
|
||
|
||
class ChatCommand(BasicCommand): | ||
NAME = 'chat' | ||
DESCRIPTION = ( | ||
'Launch Amazon Q Developer, which can translate natural language ' | ||
'to AWS CLI commands.' | ||
) | ||
|
||
def __init__(self, session): | ||
super().__init__(session) | ||
|
||
def _run_main(self, parsed_args, parsed_globals): | ||
path = _get_executable_path_or_download() | ||
if not path: | ||
raise RuntimeError('Amazon Q extension is not found.') | ||
|
||
# TODO pass through credentials and region | ||
with original_ld_library_path(): | ||
subprocess.check_call(path) |
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,39 @@ | ||
# 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. | ||
|
||
import shutil | ||
import sys | ||
from pathlib import Path | ||
|
||
from awscli.customizations.commands import BasicCommand | ||
from awscli.customizations.q.utils import _find_extension_paths | ||
|
||
|
||
class UninstallCommand(BasicCommand): | ||
NAME = 'uninstall' | ||
DESCRIPTION = 'Uninstall the Q CLI extension.' | ||
|
||
def __init__(self, session): | ||
super().__init__(session) | ||
|
||
def _run_main(self, parsed_args, parsed_globals): | ||
extension_paths = _find_extension_paths() | ||
|
||
if not extension_paths: | ||
sys.stdout.write('The Q CLI extension is not installed.\n') | ||
return | ||
|
||
for path in extension_paths: | ||
extension_path = Path(path).parent.absolute() | ||
shutil.rmtree(extension_path, ignore_errors=True) | ||
sys.stdout.write(f'Uninstalled {path}\n') |
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,28 @@ | ||
# 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. | ||
|
||
import sys | ||
|
||
from awscli.customizations.commands import BasicCommand | ||
|
||
|
||
class UpdateCommand(BasicCommand): | ||
NAME = 'update' | ||
DESCRIPTION = 'Update the Q CLI extension.' | ||
|
||
def __init__(self, session): | ||
super().__init__(session) | ||
|
||
def _run_main(self, parsed_args, parsed_globals): | ||
# TODO - implement this | ||
pass |
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,49 @@ | ||
# 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. | ||
import os | ||
from pathlib import Path | ||
|
||
EXTENSIONS_DIR = Path.home() / '.aws' / 'cli' / 'extensions' | ||
Q_DIRECTORY_NAME = 'q' | ||
Q_EXECUTABLE_NAME = 'q' | ||
DEFAULT_EXTENSION_PATH = EXTENSIONS_DIR / Q_DIRECTORY_NAME / Q_EXECUTABLE_NAME | ||
|
||
|
||
def _find_extension_paths(): | ||
"""Finds all possible paths of the Q extension. For the case where multiple | ||
are found via AWS_DATA_PATH, callers should prefer the first.""" | ||
|
||
# Prioritize any paths specified by AWS_DATA_PATH ahead of our default path | ||
possible_extension_paths = os.environ.get('AWS_DATA_PATH', '').split( | ||
os.pathsep | ||
) | ||
possible_extension_paths.append(str(EXTENSIONS_DIR)) | ||
|
||
q_extension_paths = [] | ||
for extension_path in possible_extension_paths: | ||
possible_path = ( | ||
Path(extension_path) / Q_DIRECTORY_NAME / Q_EXECUTABLE_NAME | ||
) | ||
if Path.is_file(possible_path): | ||
q_extension_paths.append(possible_path) | ||
return q_extension_paths | ||
|
||
|
||
def _get_executable_path_or_download(): | ||
extension_paths = _find_extension_paths() | ||
|
||
if extension_paths: | ||
return extension_paths[0] | ||
|
||
# TODO - implement download | ||
return None |
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
[--no-cli-pager] | ||
[--cli-auto-prompt] | ||
[--no-cli-auto-prompt] | ||
[--agent-mode] |
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,12 @@ | ||
# 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. |
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.