Skip to content

Commit 28f7ec1

Browse files
committed
initial commit
1 parent c290029 commit 28f7ec1

17 files changed

+1517
-2
lines changed

CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at <[email protected]>. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE LICENSE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 copilot-extensions
3+
Copyright (c) 2024 GitHub
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# GH Debug CLI
2+
3+
This tool allows you to chat with your assistant locally in order to create a faster feedback loop for developers developing an assistant.
4+
Debug mode is enabled by default so that you can see clearer information around what exactly is getting parsed successfully.
5+
6+
The different SSE events in the [agent protocol](https://github.com/github-technology-partners/copilot-partners/blob/main/docs/sse-events.md) that the CLI gives debug output for are:
7+
1. [errors](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/copilot-errors.md)
8+
2. [references](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/references.md)
9+
3. [confirmations](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/confirmations.md)
10+
11+
> Note: This tool does not handle the payload verification process. To use this tool to validate your events, please temporarily disable payload verification for local testing and re-enable when completed.
12+
13+
## Install the debug tool
14+
1. Authenticate with GitHub CLI OAuth app
15+
```shell
16+
gh auth login --web -h github.com
17+
```
18+
1. Install / upgrade extension
19+
```shell
20+
gh extension install github-technology-partners/gh-debug-cli
21+
```
22+
1. See more info about the cli tool
23+
```shell
24+
gh debug-cli -h
25+
```
26+
27+
## Using the debug tool
28+
1. Run the following command `gh debug-cli -h` to see the different flags that it takes in.
29+
```
30+
> gh debug-cli -h
31+
This cli tool allows you to debug your agent by chatting with it locally.
32+
33+
Usage:
34+
[flags]
35+
36+
Flags:
37+
-h, --help help for this command
38+
--log-level DEBUG Log level to help debug events. Supported types are DEBUG, `TRACE`, `NONE`. `DEBUG` returns general logs. `TRACE` prints the raw http response. (default "DEBUG")
39+
--token string GitHub token for chat authentication (optional)
40+
--url string url to chat with your agent (default "http://localhost:8080")
41+
--username string username to display in chat (default "sparklyunicorn")
42+
```
43+
2. You can alternatively set these flags as environment variables (in all caps) so you don't need to pass them in every time. The only "required" one to get this up and running is the url for your agent
44+
```
45+
export URL="http://localhost:8080/agent/blackbeard"
46+
```
47+
3. When you run the CLI, you will see any flags that were previously set in your environment variables as the output.
48+
```
49+
> gh debug-cli
50+
Setting url to http://localhost:8080/agents/blackbeard
51+
52+
Start typing to chat with your assistant...
53+
sparklyunicorn:
54+
```
55+
4. Type something to simulate chatting with your assistant.
56+
```
57+
> gh debug-cli
58+
Setting url to http://localhost:8080/agents/blackbeard
59+
60+
Start typing to chat with your assistant...
61+
sparklyunicorn: hello
62+
assistant: Ahoy, @monalisa! A jolly good day to ye, me heartie. How can ol' Blackbeard be of service to ye today?
63+
64+
Huzzah! You successfully received a message!
65+
╔═══════════╤════════════════════════════════════════════════════════════════╗
66+
║ Role │ Content ║
67+
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
68+
║ assistant │ [condensed] Ahoy, @monalisa! A jolly good day to ye, me hearti ║
69+
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
70+
║ Parsed message data ║
71+
╚═══════════╧════════════════════════════════════════════════════════════════╝
72+
sparklyunicorn:
73+
74+
```
75+
5. To debug your SSE events, you can set up a key word that your assistant uses to send you a specific type of event. My blackbeard agent allows me to send a keyword "confirmation", and here I can see the debug output on what is parsed from the SSE event
76+
```
77+
> sparklyunicorn: confirmation
78+
assistant: Arrr, @monalisa! I be ready and waitin' for yer confirmation. Be ye ready to set sail on this treacherous journey and receive a custom limerick 'bout petals? Aye or nay, let me know yer decision, and I'll be at yer service.
79+
80+
Huzzah! You successfully received a message!
81+
╔═══════════╤════════════════════════════════════════════════════════════════╗
82+
║ Role │ Content ║
83+
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
84+
║ assistant │ [condensed] Arrr, @monalisa! I be ready and waitin' for yer co ║
85+
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
86+
║ Parsed message data ║
87+
╚═══════════╧════════════════════════════════════════════════════════════════╝
88+
89+
Huzzah! You successfully received a confirmation!
90+
╔══════════════╤═════════════════════════════════════════════════════╗
91+
║ Key │ Value ║
92+
╟━━━━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
93+
║ type │ action ║
94+
║ title │ Be ye sure ye want a custom limerick 'bout petals ? ║
95+
║ message │ Arrr, this here action be irreversible, matey! ║
96+
║ confirmation │ map[id:123] ║
97+
╟━━━━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
98+
║ Parsed confirmation data ║
99+
╚══════════════╧═════════════════════════════════════════════════════╝
100+
101+
Be ye sure ye want a custom limerick 'bout petals ?
102+
Arrr, this here action be irreversible, matey!
103+
Reply: [y/N]
104+
```
105+
6. If I got a bad confirmation, it would look something like this
106+
```
107+
> sparklyunicorn: bad confirmation
108+
109+
Alas...The following is not a valid confirmation:
110+
["conf"]
111+
112+
assistant: Avast, @monalisa! Me apologies if I didn't quite understand yer request. Pray tell, could ye please clarify what be wrong with the confirmation? I be here to assist ye, me matey!
113+
```
114+
7. And if debug mode was set to false, then I would only see the confirmation prompt itself.
115+
```
116+
gh debug-cli --log-level none
117+
Setting url to http://localhost:8080/agents/blackbeard
118+
119+
Start typing to chat with your assistant...
120+
sparklyunicorn: confirmation
121+
assistant: Ahoy, @monalisa! Ye be seekin' confirmation, me hearty. Are ye sure ye want a custom limerick 'bout petals? This here action be irreversible, matey!
122+
123+
Be ye sure ye want a custom limerick 'bout petals ?
124+
Arrr, this here action be irreversible, matey!
125+
Reply: [y/N]
126+
```
127+
8. Currently, the supported event types for debug mode are references, errors, and confirmations! Have fun chatting with your assistant!

SECURITY.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Thanks for helping make GitHub safe for everyone.
2+
3+
# Security
4+
5+
GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
6+
7+
Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation.
8+
9+
## Reporting Security Issues
10+
11+
If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure.
12+
13+
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
14+
15+
Instead, please send an email to opensource-security[@]github.com.
16+
17+
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
18+
19+
* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
20+
* Full paths of source file(s) related to the manifestation of the issue
21+
* The location of the affected source code (tag/branch/commit or direct URL)
22+
* Any special configuration required to reproduce the issue
23+
* Step-by-step instructions to reproduce the issue
24+
* Proof-of-concept or exploit code (if possible)
25+
* Impact of the issue, including how an attacker might exploit the issue
26+
27+
This information will help us triage your report more quickly.
28+
29+
## Policy
30+
31+
See [GitHub's Safe Harbor Policy](https://docs.github.com/en/site-policy/security-policies/github-bug-bounty-program-legal-safe-harbor#1-safe-harbor-terms)

SUPPORT.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Support
2+
3+
## How to file issues and get help
4+
5+
This project uses GitHub issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.
6+
7+
For help or questions about using this project, please open an issue in the repository.
8+
9+
- **GH Debug CLI** is under active development and maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support, feature requests, and community questions in a timely manner.
10+
11+
## GitHub Support Policy
12+
13+
Support for this project is limited to the resources listed above.

cmd/chat.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/github-technology-partners/gh-debug-cli/pkg/chat"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
11+
)
12+
13+
const (
14+
chatCmdURLFlag = "url"
15+
chatCmdUsernameFlag = "username"
16+
chatCmdLogLevelFlag = "log-level"
17+
chatCmdTokenFlag = "token"
18+
chatCmdPrivateKeyFlag = "private-key"
19+
chatCmdPublicKeyFlag = "public-key"
20+
)
21+
22+
var chatCmd = &cobra.Command{
23+
Short: "Interact with your agent.",
24+
Long: `This cli tool allows you to debug your agent by chatting with it locally.`,
25+
Run: agentChat,
26+
TraverseChildren: true,
27+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
28+
var err error
29+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
30+
optName := strings.ToUpper(f.Name)
31+
optName = strings.ReplaceAll(optName, "-", "_")
32+
if val, ok := os.LookupEnv(optName); !f.Changed && ok {
33+
fmt.Printf("Setting %s to %s\n", f.Name, val)
34+
err2 := f.Value.Set(val)
35+
if err2 != nil {
36+
err = fmt.Errorf("invalid environment variable %s: %w", optName, err2)
37+
}
38+
}
39+
})
40+
return err
41+
}}
42+
43+
func init() {
44+
chatCmd.CompletionOptions.DisableDefaultCmd = true
45+
46+
chatCmd.PersistentFlags().String(chatCmdURLFlag, "http://localhost:8080", "url to chat with your agent")
47+
chatCmd.PersistentFlags().String(chatCmdUsernameFlag, "sparklyunicorn", "username to display in chat")
48+
chatCmd.PersistentFlags().String(chatCmdTokenFlag, "", "GitHub token for chat authentication (optional)")
49+
chatCmd.PersistentFlags().String(chatCmdLogLevelFlag, "DEBUG", "Log level to help debug events. Supported types are `DEBUG`, `TRACE`, `NONE`. `DEBUG` returns general logs. `TRACE` prints the raw http response.")
50+
chatCmd.PersistentFlags().String(chatCmdPrivateKeyFlag, "", "Private key for payload verification")
51+
chatCmd.PersistentFlags().String(chatCmdPublicKeyFlag, "", "Public key for payload verification")
52+
53+
}
54+
55+
func agentChat(cmd *cobra.Command, args []string) {
56+
57+
url, _ := cmd.Flags().GetString(chatCmdURLFlag)
58+
if url == "" {
59+
fmt.Println("a url is required to chat with your agent")
60+
}
61+
62+
username, _ := cmd.Flags().GetString(chatCmdUsernameFlag)
63+
64+
token, _ := cmd.Flags().GetString(chatCmdTokenFlag)
65+
66+
debug, _ := cmd.Flags().GetString(chatCmdLogLevelFlag)
67+
debug = strings.ToUpper(debug)
68+
if debug != chat.LEVEL_NONE && debug != chat.LEVEL_DEBUG && debug != chat.LEVEL_TRACE {
69+
fmt.Println("debug mode must be either `DEBUG`, `TRACE`, or `NONE`")
70+
}
71+
72+
err := chat.Chat(url, username, token, debug)
73+
if err != nil {
74+
fmt.Println(err)
75+
}
76+
}
77+
78+
func Execute() {
79+
err := chatCmd.Execute()
80+
if err != nil {
81+
os.Exit(1)
82+
}
83+
}

go.mod

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module github.com/github-technology-partners/gh-debug-cli
2+
3+
go 1.21.0
4+
5+
toolchain go1.21
6+
7+
require (
8+
github.com/alexeyco/simpletable v1.0.0
9+
github.com/google/uuid v1.6.0
10+
github.com/jclem/sseparser v0.5.0
11+
github.com/spf13/cobra v1.8.1
12+
github.com/spf13/pflag v1.0.5
13+
github.com/stretchr/testify v1.8.4
14+
)
15+
16+
require (
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
19+
github.com/kr/pretty v0.1.0 // indirect
20+
github.com/kr/text v0.2.0 // indirect
21+
github.com/mattn/go-runewidth v0.0.15 // indirect
22+
github.com/pmezard/go-difflib v1.0.0 // indirect
23+
github.com/prataprc/goparsec v0.0.0-20211219142520-daac0e635e7e // indirect
24+
github.com/rivo/uniseg v0.4.7 // indirect
25+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
26+
gopkg.in/yaml.v3 v3.0.1 // indirect
27+
)

0 commit comments

Comments
 (0)