-
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
Open
ashovlin
wants to merge
3
commits into
aws:feature/cliq
Choose a base branch
from
ashovlin:shovlia/cliq-initial
base: feature/cliq
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
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,44 @@ | ||
# 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 | ||
from awscli.customizations.q.version import VersionCommand | ||
|
||
|
||
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': 'version', 'command_class': VersionCommand}, | ||
{'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,34 @@ | ||
# 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 Q_EXTENSION_DIR, Q_EXTENSION_PATH | ||
|
||
|
||
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): | ||
if not Path.is_file(Q_EXTENSION_PATH): | ||
sys.stdout.write('The Q CLI extension is not installed.\n') | ||
else: | ||
shutil.rmtree(Q_EXTENSION_DIR, ignore_errors=True) | ||
sys.stdout.write(f'Uninstalled {Q_EXTENSION_DIR}\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,26 @@ | ||
# 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 pathlib import Path | ||
|
||
EXTENSIONS_DIR = Path.home() / '.aws' / 'cli' / 'extensions' | ||
Q_EXTENSION_DIR = EXTENSIONS_DIR / 'q' | ||
Q_EXTENSION_PATH = Q_EXTENSION_DIR / 'q' | ||
|
||
|
||
def _get_executable_path_or_download(): | ||
if Path.is_file(Q_EXTENSION_PATH): | ||
return Q_EXTENSION_PATH | ||
|
||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 pathlib import Path | ||
|
||
from botocore.utils import original_ld_library_path | ||
|
||
from awscli.customizations.commands import BasicCommand | ||
from awscli.customizations.q.utils import Q_EXTENSION_PATH | ||
|
||
|
||
class VersionCommand(BasicCommand): | ||
NAME = 'version' | ||
DESCRIPTION = 'Displays the version of the Q CLI extension.' | ||
|
||
def __init__(self, session): | ||
super().__init__(session) | ||
|
||
def _run_main(self, parsed_args, parsed_globals): | ||
# version doesn't install the Q extension if needed like | ||
# chat does, so check Q_EXTENSION_PATH directly | ||
if not Path.is_file(Q_EXTENSION_PATH): | ||
raise RuntimeError( | ||
'The Q CLI extension is not installed. ' | ||
'Run aws q chat or aws q upgrade to install it.' | ||
) | ||
|
||
with original_ld_library_path(): | ||
subprocess.check_call(f'{Q_EXTENSION_PATH} --version'.split(' ')) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to consider the
AWS_DATA_PATH
here as well if they've configured something other than~/.aws/cli/...
?