Some notes and references while exploring the GitHub CLI extension for the GitHub Copilot CLI.
The GitHub CLI allows extensions to be installed into it:
- https://cli.github.com/
-
GitHub CLI, or
gh
, is a command-line interface to GitHub for use in your terminal or your scripts.
-
- https://cli.github.com/manual/gh_extension
-> GitHub CLI extensions are repositories that provide additional
gh
commands.
The GitHub Copilot CLI is one of these extensions, which is a compiled Golang binary, and at the time of writing, not open-source:
- https://github.com/github/gh-copilot
-
GitHub Copilot in the CLI GitHub Copilot in the CLI is an extension for GitHub CLI which provides a chat-like interface in the terminal that allows you to ask questions about the command line. You can ask Copilot in the CLI to suggest a command for your use case with
gh copilot suggest
, or to explain a command you're curious about withgh copilot explain
.
-
The GitHub CLI can be configured with various environment variables, one of which is GH_DEBUG
, which when set to api
, will log details of HTTP traffic:
- https://cli.github.com/manual/gh_help_environment
-
GH_DEBUG
: set to a truthy value to enable verbose output on standard error. Set to "api" to additionally log details of HTTP traffic.
-
We can use that to see the API calls being made by the gh-copilot
extension.
The gh-copilot
CLI extension has 2 main features: suggest
, and explain
⇒ gh copilot -h
Your AI command line copilot.
Usage:
copilot [command]
Examples:
$ gh copilot suggest "Install git"
$ gh copilot explain "traceroute github.com"
Available Commands:
config Configure options
explain Explain a command
suggest Suggest a command
Flags:
-h, --help help for copilot
-v, --version version for copilot
Use "copilot [command] --help" for more information about a command.
The help docs for suggest
are as follows:
⇒ gh copilot suggest -h
Suggest a command based on a natural language description of the desired output effect.
There is no task too small or too large to need help when working in the terminal, the only limit is your imagination:
- installing and upgrading software
- troubleshooting and debugging problems with your system
- processing and manipulating files
- working with git and GitHub in the terminal
Usage:
copilot suggest [flags]
Examples:
- Guided experience
$ gh copilot suggest
- Git use cases
$ gh copilot suggest -t git "Undo the most recent local commits"
$ gh copilot suggest -t git "Clean up local branches"
$ gh copilot suggest -t git "Setup LFS for images"
- Working with the GitHub CLI in the terminal
$ gh copilot suggest -t gh "Create pull request"
$ gh copilot suggest -t gh "List pull requests waiting for my review"
$ gh copilot suggest -t gh "Summarize work I have done in issues and pull requests for promotion"
- General use cases
$ gh copilot suggest -t shell "Kill processes holding onto deleted files"
$ gh copilot suggest -t shell "Test whether there are SSL/TLS issues with github.com"
$ gh copilot suggest -t shell "Convert SVG to PNG and resize"
$ gh copilot suggest -t shell "Convert MOV to animated PNG"
Flags:
-h, --help help for suggest
-t, --target target Target for suggestion; must be shell, gh, git
The help docs for explain
are as follows:
⇒ gh copilot explain -h
Explain a given input command in natural language.
Did you ever wonder what a command does? Or why it was suggested to you? Now you can find out!
Usage:
copilot explain [flags]
Examples:
# View disk usage, sorted by size
$ gh copilot explain 'du -sh | sort -h'
# View git repository history as text graphical representation
$ gh copilot explain 'git log --oneline --graph --decorate --all'
# Remove binary objects larger than 50 megabytes from git history
$ gh copilot explain 'bfg --strip-blobs-bigger-than 50M'
Flags:
-h, --help help for explain
Since explain
is simpler, let's start with that.
Running with GH_DEBUG=api
, we can see the API calls being made when we run gh copilot explain
.
First we will try an example where we don't find an explanation:
⇒ GH_DEBUG=api gh copilot explain 'this will not be found'
We see that a new chat thread is created by making a POST
request to https://api.githubcopilot.com/github/chat/threads
:
* Request at 2023-11-27 18:13:37.116072 +1100 AEDT m=+0.116938413
* Request to https://api.githubcopilot.com/github/chat/threads
> POST /github/chat/threads HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 2
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{}
< HTTP/2.0 201 Created
< Content-Length: 235
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:13:38 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F740:1CD3:3F518B:D165F8:656441A1
{
"thread_id": "e3b04df8-5d32-4d72-baa8-a40cc459cbd7",
"thread": {
"id": "e3b04df8-5d32-4d72-baa8-a40cc459cbd7",
"name": "",
"repoID": 0,
"repoOwnerID": 0,
"createdAt": "2023-11-27T07:13:38.194799803Z",
"updatedAt": "2023-11-27T07:13:38.194799803Z"
}
}
* Request took 1.082443704s
And then a message is added to that chat by making a POST request to https://api.githubcopilot.com/github/chat/threads/:threadUuid/messages
, which gets the response as the reply:
* Request at 2023-11-27 18:13:38.201104 +1100 AEDT m=+1.201943992
* Request to https://api.githubcopilot.com/github/chat/threads/e3b04df8-5d32-4d72-baa8-a40cc459cbd7/messages
> POST /github/chat/threads/e3b04df8-5d32-4d72-baa8-a40cc459cbd7/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 110
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "this will not be found",
"intent": "cli-explain",
"references": [
{
"type": "cli-command",
"program": ""
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 358
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:13:39 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F740:1CD3:3F51AB:D16647:656441A2
{
"message": {
"id": "a9991548-30cc-4506-ba1e-fb26f9f08c24",
"threadID": "e3b04df8-5d32-4d72-baa8-a40cc459cbd7",
"turnID": "0680e661-466b-4e58-9611-4e8d5b533743",
"role": "assistant",
"content": "* The command you provided, \"this will not be found:\", is not a valid shell command.",
"createdAt": "2023-11-27T07:13:39.635853891Z",
"intent": "cli-explain",
"references": []
}
}
* Request took 1.544495822s
Ignoring the HTTP debug logs, the rest of the output basically looks like this:
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.
⡿ Hold on, asking GitHub Copilot...
Explanation:
• The command you provided, "this will not be found:", is not a valid shell command.
Next, we try an example where we do find an explanation:
⇒ GH_DEBUG=api gh copilot explain 'sort'
Which similarly creates a chat thread:
* Request at 2023-11-27 18:18:40.735178 +1100 AEDT m=+0.121896140
* Request to https://api.githubcopilot.com/github/chat/threads
> POST /github/chat/threads HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 2
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{}
< HTTP/2.0 201 Created
< Content-Length: 235
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:18:41 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F7F3:0D49:422A48:D4C6A3:656442D1
{
"thread_id": "5f4926ed-5c0c-4a39-8a68-554b7f08f033",
"thread": {
"id": "5f4926ed-5c0c-4a39-8a68-554b7f08f033",
"name": "",
"repoID": 0,
"repoOwnerID": 0,
"createdAt": "2023-11-27T07:18:41.778028851Z",
"updatedAt": "2023-11-27T07:18:41.778028851Z"
}
}
* Request took 1.063955767s
And then adds a message to that thread, which it gets a response to:
* Request at 2023-11-27 18:18:41.801388 +1100 AEDT m=+1.188080668
* Request to https://api.githubcopilot.com/github/chat/threads/5f4926ed-5c0c-4a39-8a68-554b7f08f033/messages
> POST /github/chat/threads/5f4926ed-5c0c-4a39-8a68-554b7f08f033/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 92
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "sort",
"intent": "cli-explain",
"references": [
{
"type": "cli-command",
"program": ""
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 501
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:18:43 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F7F3:0D49:422A6C:D4C6EE:656442D1
{
"message": {
"id": "d7210faf-194e-49f0-8f4d-fce34d461286",
"threadID": "5f4926ed-5c0c-4a39-8a68-554b7f08f033",
"turnID": "55d9ade6-25c2-4642-8bb8-af0adf06ce8b",
"role": "assistant",
"content": "* 'sort' is used to sort lines of text.\n * It reads input from either standard input or a file specified as an argument.\n * By default, it sorts the text in ascending order.\n * It outputs the sorted text to standard output.",
"createdAt": "2023-11-27T07:18:43.135860298Z",
"intent": "cli-explain",
"references": []
}
}
* Request took 1.421621445s
Ignoring the HTTP debug logs, the rest of the output basically looks like this:
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.
⢿ Hold on, asking GitHub Copilot...
Explanation:
• sort is used to sort lines of text.
• It reads input from either standard input or a file specified as an argument.
• By default, it sorts the text in ascending order.
• It outputs the sorted text to standard output.
Since suggest
can have 3 different 'types' of suggestion (git
, gh
, shell
), let's handle them separately.
Running with GH_DEBUG=api
, we can see the API calls being made when we run gh copilot suggest -t git
.
GH_DEBUG=api gh copilot suggest -t git 'create a new branch with a name'
First, the new chat thread is created:
* Request at 2023-11-27 18:30:39.728445 +1100 AEDT m=+0.124495906
* Request to https://api.githubcopilot.com/github/chat/threads
> POST /github/chat/threads HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 2
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{}
< HTTP/2.0 201 Created
< Content-Length: 235
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:30:40 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F9D7:8EE8:146BB7A:3631008:656445A0
{
"thread_id": "e1855984-0fc6-46d6-ae22-a1a89f028bdf",
"thread": {
"id": "e1855984-0fc6-46d6-ae22-a1a89f028bdf",
"name": "",
"repoID": 0,
"repoOwnerID": 0,
"createdAt": "2023-11-27T07:30:40.820942415Z",
"updatedAt": "2023-11-27T07:30:40.820942415Z"
}
}
* Request took 1.058698782s
Then the main chat message for our request is added:
* Request at 2023-11-27 18:30:40.789028 +1100 AEDT m=+1.185054198
* Request to https://api.githubcopilot.com/github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages
> POST /github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 122
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "create a new branch with a name",
"intent": "cli-suggest",
"references": [
{
"type": "cli-command",
"program": "git"
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 305
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:30:41 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: F9D7:8EE8:146BBB3:3631079:656445A0
{
"message": {
"id": "021052d7-d30f-4925-bd4d-c88815be5613",
"threadID": "e1855984-0fc6-46d6-ae22-a1a89f028bdf",
"turnID": "d700692a-0ab3-4c3c-95a6-c8483c4a89fb",
"role": "assistant",
"content": "git branch <branchname>",
"createdAt": "2023-11-27T07:30:41.701965827Z",
"intent": "cli-suggest",
"references": []
}
}
* Request took 1.00446051s
Which gives us output (with HTTP debug logs removed) that looks something like this:
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.
⣾ Hold on, asking GitHub Copilot...
Suggestion:
git branch <branchname>
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
We can see now that we have 3 more options that are likely to create additional API calls:
- Explain command
- Revise command
- Rate response
First we try explain command:
? Select an option
> Explain command
⣾ Hold on, asking GitHub Copilot...
Explanation:
• git branch is used to manage branches in Git.
• <branchname> is the name of the branch to be created.
Which generated the following HTTP debug logs:
* Request at 2023-11-27 18:34:36.633862 +1100 AEDT m=+237.024248987
* Request to https://api.githubcopilot.com/github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages
> POST /github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 121
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "git branch <branchname>",
"intent": "cli-explain",
"references": [
{
"type": "cli-command",
"program": ""
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 392
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:34:38 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FA67:0643:42FB07:D6BE00:6564468D
{
"message": {
"id": "d034feca-a119-4645-ac50-2bf5f8edd31f",
"threadID": "e1855984-0fc6-46d6-ae22-a1a89f028bdf",
"turnID": "a2a6e957-f852-4028-9c18-0e21d0aecd4c",
"role": "assistant",
"content": "* 'git branch' is used to manage branches in Git.\n * '<branchname>' is the name of the branch to be created.",
"createdAt": "2023-11-27T07:34:38.411428909Z",
"intent": "cli-explain",
"references": []
}
}
* Request took 1.888562667s
Then we try revise command:
? Select an option
> Revise command
? How should this be revised?
> Specify a different branch name
⣾ Hold on, asking GitHub Copilot...
Suggestion:
git branch <newbranchname>
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
Which generated the following HTTP debug logs:
* Request at 2023-11-27 18:38:08.553872 +1100 AEDT m=+448.939191773
* Request to https://api.githubcopilot.com/github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages
> POST /github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 122
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "Specify a different branch name",
"intent": "cli-suggest",
"references": [
{
"type": "cli-command",
"program": "git"
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 308
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:38:10 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FB00:01C2:13BE6D7:3582067:65644761
{
"message": {
"id": "7c622f71-fc3d-414f-b3d8-3d40f304d81f",
"threadID": "e1855984-0fc6-46d6-ae22-a1a89f028bdf",
"turnID": "f5d958fd-078f-4601-bc13-d131284fdaaf",
"role": "assistant",
"content": "git branch <newbranchname>",
"createdAt": "2023-11-27T07:38:10.116998875Z",
"intent": "cli-suggest",
"references": []
}
}
* Request took 1.71950429s
Next, we try rate response and choose a positive response:
? Select an option
> Rate response
? Was this helpful?
> Yes
Thanks for your feedback!
Which generated the following HTTP debug logs:
* Request at 2023-11-27 18:39:59.502995 +1100 AEDT m=+559.885661450
* Request to https://api.githubcopilot.com/github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages/7c622f71-fc3d-414f-b3d8-3d40f304d81f/feedback
> POST /github/chat/threads/e1855984-0fc6-46d6-ae22-a1a89f028bdf/messages/7c622f71-fc3d-414f-b3d8-3d40f304d81f/feedback HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 94
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"feedback": "POSITIVE",
"text_response": "",
"feedback_choice": null,
"is_contacted_checked": false
}
< HTTP/2.0 204 No Content
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:40:00 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FB3A:1019:12C9887:349C2EE:656447D0
* Request took 952.349999ms
And finally, we try rate response and choose a negative response (note that this was done on a new run of the command, so the thread ID's/etc will be different from the above because of this):
? Was this helpful?
> No
? This response is:
> Unhelpful, Incorrect, Not true, Poorly formatted, Offensive or discriminatory, Other
? How could we improve this response?
> SOME IMPROVEMENT TEXT HERE
? Do you wish to be contacted via your GitHub email address?
> No
Thanks for your feedback!
Which generated the following HTTP debug logs:
* Request at 2023-11-27 18:41:18.244372 +1100 AEDT m=+38.052650891
* Request to https://api.githubcopilot.com/github/chat/threads/619d2353-d38b-40fb-8f97-c825fed1bbe2/messages/ed906fac-76ea-4387-983c-8c92e17e6c9b/feedback
> POST /github/chat/threads/619d2353-d38b-40fb-8f97-c825fed1bbe2/messages/ed906fac-76ea-4387-983c-8c92e17e6c9b/feedback HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 209
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"feedback": "NEGATIVE",
"text_response": "SOME IMPROVEMENT TEXT HERE",
"feedback_choice": [
"unhelpful",
"incorrect",
"not_true",
"poorly_formatted",
"offensive_or_discriminatory",
"other"
],
"is_contacted_checked": false
}
< HTTP/2.0 204 No Content
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:41:18 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FB57:496C:1338C98:350C5A0:656447FA
* Request took 550.753104ms
Running with GH_DEBUG=api
, we can see the API calls being made when we run gh copilot suggest -t gh
.
⇒ GH_DEBUG=api gh copilot suggest -t gh 'list extensions'
Since the API calls will likely be the same for all of the suggest
flows, we'll only include the basic initial requests here (not the extra followup commands).
First, the new chat thread is created:
* Request at 2023-11-27 18:45:14.133759 +1100 AEDT m=+0.116387627
* Request to https://api.githubcopilot.com/github/chat/threads
> POST /github/chat/threads HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 2
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{}
< HTTP/2.0 201 Created
< Content-Length: 235
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:45:15 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FC1C:16AF:191640:3EA7AA:6564490A
{
"thread_id": "d04f1192-51ae-450e-910e-ca13b55e22e0",
"thread": {
"id": "d04f1192-51ae-450e-910e-ca13b55e22e0",
"name": "",
"repoID": 0,
"repoOwnerID": 0,
"createdAt": "2023-11-27T07:45:15.342462675Z",
"updatedAt": "2023-11-27T07:45:15.342462675Z"
}
}
* Request took 1.237816207s
Then the main message request is made:
* Request to https://api.githubcopilot.com/github/chat/threads/d04f1192-51ae-450e-910e-ca13b55e22e0/messages
> POST /github/chat/threads/d04f1192-51ae-450e-910e-ca13b55e22e0/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 105
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "list extensions",
"intent": "cli-suggest",
"references": [
{
"type": "cli-command",
"program": "gh"
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 289
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:45:16 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FC1C:16AF:191677:3EA81B:6564490B
{
"message": {
"id": "e40d0f43-9e17-4aa9-803c-d26dc794a41a",
"threadID": "d04f1192-51ae-450e-910e-ca13b55e22e0",
"turnID": "ed6ef162-a35d-4b24-9b37-025a15a7fc42",
"role": "assistant",
"content": "gh extension list",
"createdAt": "2023-11-27T07:45:16.259152292Z",
"intent": "cli-suggest",
"references": []
}
}
* Request took 1.028340758s
Which gives us output (with HTTP debug logs removed) that looks something like this:
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.
* Request at 2023-11-27 18:45:15.373407 +1100 AEDT m=+1.355997912
⣾ Hold on, asking GitHub Copilot...
Suggestion:
gh extension list
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
Running with GH_DEBUG=api
, we can see the API calls being made when we run gh copilot suggest -t shell
.
GH_DEBUG=api gh copilot suggest -t shell 'echo to a file'
Since the API calls will likely be the same for all of the suggest
flows, we'll only include the basic initial requests here (not the extra followup commands).
First, the new chat thread is created:
⇒ GH_DEBUG=api gh copilot suggest -t shell 'echo to a file'
* Request at 2023-11-27 18:48:50.840719 +1100 AEDT m=+0.118348846
* Request to https://api.githubcopilot.com/github/chat/threads
> POST /github/chat/threads HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 2
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{}
< HTTP/2.0 201 Created
< Content-Length: 235
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:48:52 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FC9B:0F72:13487D7:3518A02:656449E3
{
"thread_id": "8baa9f15-c7b4-4f98-ab75-d2cc755dd835",
"thread": {
"id": "8baa9f15-c7b4-4f98-ab75-d2cc755dd835",
"name": "",
"repoID": 0,
"repoOwnerID": 0,
"createdAt": "2023-11-27T07:48:51.865699594Z",
"updatedAt": "2023-11-27T07:48:51.865699594Z"
}
}
* Request took 1.139865034s
Then the main message request is made:
* Request at 2023-11-27 18:48:51.982605 +1100 AEDT m=+1.260200795
* Request to https://api.githubcopilot.com/github/chat/threads/8baa9f15-c7b4-4f98-ab75-d2cc755dd835/messages
> POST /github/chat/threads/8baa9f15-c7b4-4f98-ab75-d2cc755dd835/messages HTTP/1.1
> Host: api.githubcopilot.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 107
> Content-Type: application/json
> Time-Zone: Australia/Sydney
> User-Agent: go-gh
{
"content": "echo to a file",
"intent": "cli-suggest",
"references": [
{
"type": "cli-command",
"program": "shell"
}
]
}
< HTTP/2.0 200 OK
< Content-Length: 310
< Content-Type: application/json
< Date: Mon, 27 Nov 2023 07:48:53 GMT
< X-Github-Backend: Kubernetes
< X-Github-Request-Id: FC9B:0F72:13487FE:3518A67:656449E4
{
"message": {
"id": "33d0a1c1-e358-40cf-9e06-16f77763e3f2",
"threadID": "8baa9f15-c7b4-4f98-ab75-d2cc755dd835",
"turnID": "a2c84dca-f768-4847-a628-57d8a741b181",
"role": "assistant",
"content": "echo \"Hello, World!\" > file.txt",
"createdAt": "2023-11-27T07:48:52.958558477Z",
"intent": "cli-suggest",
"references": []
}
}
* Request took 1.085444884s
Which gives us output (with HTTP debug logs removed) that looks something like this:
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.
⣾ Hold on, asking GitHub Copilot...
Suggestion:
echo "Hello, World!" > file.txt
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
This reference document categorizes the API calls used in the GitHub Copilot CLI by their endpoints. Each endpoint is detailed with its methods, inputs, and outputs.
This endpoint initializes a new chat thread for both explain
and suggest
functionalities.
- Endpoint:
https://api.githubcopilot.com/github/chat/threads
- Method: POST
- Input:
{}
- Output:
{ "thread_id": "string", "thread": { "id": "string", "name": "string", "repoID": 0, "repoOwnerID": 0, "createdAt": "datetime", "updatedAt": "datetime" } }
This endpoint is used to send messages to an existing chat thread, applicable for both explaining and suggesting commands.
- Endpoint:
https://api.githubcopilot.com/github/chat/threads/:threadUuid/messages
- Method: POST
- Input:
{ "content": "string", "intent": "cli-explain" | "cli-suggest", "references": [ { "type": "cli-command", "program": "string" } ] }
- Output:
{ "message": { "id": "string", "threadID": "string", "turnID": "string", "role": "assistant", "content": "string", "createdAt": "datetime", "intent": "cli-explain" | "cli-suggest", "references": [] } }
This endpoint handles feedback submissions for the responses generated by the Copilot.
- Endpoint:
https://api.githubcopilot.com/github/chat/threads/:threadUuid/messages/:messageId/feedback
- Method: POST
- Input:
{ "feedback": "POSITIVE" | "NEGATIVE", "text_response": "string", "feedback_choice": ["string"], "is_contacted_checked": boolean }
- Output: Typically a status code (like 204 No Content), indicating the successful submission of feedback.
- Input:
feedback
: Indicates the type of feedback (e.g., "POSITIVE", "NEGATIVE").text_response
: Optional text elaborating on the feedback.feedback_choice
: An array of specific feedback categories (e.g., "unhelpful", "incorrect").is_contacted_checked
: Boolean indicating whether the user opts for contact via email.
- Output: Typically a status code (like 204 No Content), indicating the successful submission of feedback.