こんにちは、CX 事業本部 Delivery 部の若槻です。
先週開催された GitHub Universe 2023 では、GitHub の AI に関連した多くの機能が発表されました。
- GitHub Copilot Chat が 2023 年 12 月より一般提供開始
- GitHub Copilot Chat が GitHub.com およびモバイルアプリで利用可能に
- GitHub Copilot Enterprise が 2024 年 2 月より一般提供開始
- GitHub Copilot Partner Program の発表
- GitHub Advanced Security サポートのプレビュー提供開始
- GitHub Copilot Workspace の発表
しかし Universe のキーノート内では取り上げられず Change log でひっそりと(?)発表されるのみだった Copilot 関連の機能もいくつかあり、そのうちの一つが GitHub Copilot in the CLI の Public beta 提供開始の発表です。
ドキュメントもすでに公開されています。
今回は、この GitHub Copilot in the CLI を試してみました。
GitHub Copilot in the CLI とは
GitHub Copilot in the CLI は、コマンドラインで実行したい処理をターミナル上で自然言語を使ってチャットのように指示すると、コマンドの説明や提案を行ってくれる機能です。例えば、make get request with curl
のように指示すれば、Curl で GET リクエストを実行するコマンドを提案してくれるので「あれをするコマンドはどう書くんだっけ?」をキーボードと IDE から離れることなく解決できるようになります。
ちなみに、GitHub Copilot in the CLI は以前は GitHub Next で Copilot for CLI というプロジェクト名で開発されていました。
今回の Public beta 提供開始を受けて、現在のステータスは COMPLETED
に移行されたようです。(一般提供開始されたプロジェクトは PRODUCT
ステータスとなります。)
前提
GitHub Copilot in the CLI の利用には以下の前提条件を満たしている必要があります。
- GitHub Copilot サブスクリプションが有効になっていること
- GitHub CLI がインストールされていること
試してみた
環境
- Visual Studio Code
1.84.2
- GitHub CLI
2.39.1
- GitHub Copilot Extention
1.137.0
- GitHub Copilot Business
機能の有効化
まずは、GitHub Copilot in the CLI 機能を、GitHub の組織設定メニューから有効化します。
自身のユーザーアカウントに GitHub Copilot へのアクセス権を付与している組織の設定メニューを開きます。(なお、この有効化手順は操作者が組織の適切な権限を持っていることが前提となります。権限が無い場合は管理者に有効化を依頼する必要があります。)
GitHub Copilot policies and features メニューで、GitHub Copilot in the CLI を Enabled
にして有効化します。
GitHub Copilot in the CLI 機能は、Copilot Business ライセンスでは既定では無効となるため利用する場合は有効化の操作が必要です。一方で Copilot Individual ライセンスでは自動的に有効となります。
GitHub Copilot 拡張機能のインストール
まだの場合は VS Code で GitHub Copilot を利用可能にします。
gh auth login
コマンドで GitHub CLI にログインします。
gh auth login
VS Code に GitHub Copilot をインストールします。
gh extension install github/gh-copilot
バージョンが古い場合はアップデートを行います。
gh extension upgrade gh-copilot
コマンドの説明
gh copilot explain
コマンドを利用すると、Copilot にコマンドを説明してもらうことができます。
引数なしで実行すると、プロンプトが表示されるので、説明を取得したいコマンドを入力します。
$ gh copilot explain
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
? Which command would you like to explain?
>
説明を取得できました。コマンドとオプションを解釈して分けて説明してくれています。
$ gh copilot explain
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
? Which command would you like to explain?
> cdk init --region us-east-1
Explanation:
• cdk init initializes a new AWS Cloud Development Kit (CDK) project.
• --region us-east-1 specifies the AWS region to set as the default for the project.
gh copilot explain "<コマンド>"
のように説明を取得したいコマンドを引数として直接指定もできます。
$ gh copilot explain "aws s3 ls"
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
Explanation:
• aws s3 is the AWS command-line interface (CLI) command for interacting with Amazon S3.
• ls is the command to list objects in an S3 bucket.
コマンドの提案
gh copilot suggest
コマンドを利用すると、Copilot にコマンドを提案してもらうことができます。
引数なしで実行すると、プロンプトでコマンドの種類の選択を求められます。
$ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
? What kind of command can I help you with? [Use arrows to move, type to filter]
> generic shell command
gh command
git command
選択肢は上から次のようになります。
オプション | 説明 |
---|---|
generic shell command | 一般のシェルコマンド |
gh command | GitHub CLI コマンド |
git command | Git コマンド |
generic shell command
generic shell command
を選択すると、次はどのような操作を実行したいのか入力による指定を求められます。
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
>
操作内容を指定するとコマンドがサジェストされます。日本語の指示でも問題無さそうですね。そして、そのコマンドをどうするかの選択を求められます。
? What would you like the shell command to do?
> src/ 配下のデータをすべてapp/src 配下に移動させる
Suggestion:
mv src/* app/src/
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
選択肢は上から次のようになります。
オプション | 説明 |
---|---|
Copy command to clipboard | コマンドをクリップボードにコピー |
Explain command | コマンドの説明を表示 |
Revise command | コマンドを修正 |
Rate response | レスポンスの評価をフィードバック |
Exit | 終了 |
これらの選択肢は Exit を選択するまでプロンプトで表示されるため、質問を変えて何度でも提案してもらうことができます。
$
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
> src/ 配下のデータをすべてapp/src 配下に移動させる
Suggestion:
mv src/* app/src/
? Select an option
> Copy command to clipboard
Command copied to clipboard!
? Select an option
> Explain command
Explanation:
• mv is used to move files and directories.
• src/* selects all files in the src directory.
• app/src/ specifies the destination directory.
• : means that we want to move the selected files to that directory.
? Select an option
> Revise command
? How should this be revised?
> src/ 配下のデータをすべて web/src 配下に移動させる
Suggestion:
mv src/* web/src/
? Select an option
> Exit
gh command と git command
最初の選択肢で gh command または git command を選択した場合でも基本的な操作の流れは同じです。
$ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.3-beta (2023-11-09)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.
? What kind of command can I help you with?
> git command
? What would you like the git command to do?
> 最新のコミットに含まれる変更をステージに戻す
Suggestion:
git restore --staged .
? Select an option
> Revise command
? How should this be revised?
> 最新のコミットを打ち消して、それに含まれる変更をステージに戻す
Suggestion:
git reset --hard HEAD~1
? Select an option
> Exit
その他
機能が有効化されていない場合
GitHub Copilot in the CLI の機能が有効化されていないユーザーがコマンドを実行すると次のようなエラーとなります。
$ gh copilot suggest
✗ Error: User is not authorized to use this Copilot feature
To start using GitHub Copilot in the CLI, request access from your organization admin.
機能が有効化されているか確認しましょう。
GitHub Copilot 拡張機能を Pre-release 版に切り替える必要はない
GitHub Copilot 拡張機能では Pre-release 版の機能を利用可能とするスイッチがあります。
現在 Public beta となっている GitHub Copilot in the CLI の利用に際しては Pre-release 版に切り替える必要があると考えていましが、実際には必要ありませんでした。
GitHub の公式 X でもリリースがちゃんと祝われていました
This started as something @mattrothenberg made during a lunch break at a Next onsite 💪🤯 https://t.co/5yMgGDl3RU
— GitHub Next (@GitHubNext) November 17, 2023
おわりに
CLI 上の操作だけでコマンドの説明や提案をしてもらえる「GitHub Copilot in the CLI」の Public Beta が提供開始されたのでご紹介しました。
GitHub Copilot in the CLI で出来ることはだいたいは Copilot Chat でもできはするのですが、ターミナルから最短の操作で Copilot を呼び出せるというのは便利ですしなんだかロマンもありますね。
以上