Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
theodoracheng committed Aug 15, 2024
1 parent c290029 commit 28f7ec1
Show file tree
Hide file tree
Showing 17 changed files with 1,517 additions and 2 deletions.
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <[email protected]>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
4 changes: 2 additions & 2 deletions LICENSE → LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 copilot-extensions
Copyright (c) 2024 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# GH Debug CLI

This tool allows you to chat with your assistant locally in order to create a faster feedback loop for developers developing an assistant.
Debug mode is enabled by default so that you can see clearer information around what exactly is getting parsed successfully.

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:
1. [errors](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/copilot-errors.md)
2. [references](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/references.md)
3. [confirmations](https://github.com/github-technology-partners/copilot-partners/blob/c0b6be447b95d94fff6297bae820ea8cc6d36b87/docs/confirmations.md)

> 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.
## Install the debug tool
1. Authenticate with GitHub CLI OAuth app
```shell
gh auth login --web -h github.com
```
1. Install / upgrade extension
```shell
gh extension install github-technology-partners/gh-debug-cli
```
1. See more info about the cli tool
```shell
gh debug-cli -h
```

## Using the debug tool
1. Run the following command `gh debug-cli -h` to see the different flags that it takes in.
```
> gh debug-cli -h
This cli tool allows you to debug your agent by chatting with it locally.
Usage:
[flags]
Flags:
-h, --help help for this command
--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")
--token string GitHub token for chat authentication (optional)
--url string url to chat with your agent (default "http://localhost:8080")
--username string username to display in chat (default "sparklyunicorn")
```
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
```
export URL="http://localhost:8080/agent/blackbeard"
```
3. When you run the CLI, you will see any flags that were previously set in your environment variables as the output.
```
> gh debug-cli
Setting url to http://localhost:8080/agents/blackbeard
Start typing to chat with your assistant...
sparklyunicorn:
```
4. Type something to simulate chatting with your assistant.
```
> gh debug-cli
Setting url to http://localhost:8080/agents/blackbeard
Start typing to chat with your assistant...
sparklyunicorn: hello
assistant: Ahoy, @monalisa! A jolly good day to ye, me heartie. How can ol' Blackbeard be of service to ye today?
Huzzah! You successfully received a message!
╔═══════════╤════════════════════════════════════════════════════════════════╗
║ Role │ Content ║
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ assistant │ [condensed] Ahoy, @monalisa! A jolly good day to ye, me hearti ║
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ Parsed message data ║
╚═══════════╧════════════════════════════════════════════════════════════════╝
sparklyunicorn:
```
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
```
> sparklyunicorn: confirmation
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.
Huzzah! You successfully received a message!
╔═══════════╤════════════════════════════════════════════════════════════════╗
║ Role │ Content ║
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ assistant │ [condensed] Arrr, @monalisa! I be ready and waitin' for yer co ║
╟━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ Parsed message data ║
╚═══════════╧════════════════════════════════════════════════════════════════╝
Huzzah! You successfully received a confirmation!
╔══════════════╤═════════════════════════════════════════════════════╗
║ Key │ Value ║
╟━━━━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ type │ action ║
║ title │ Be ye sure ye want a custom limerick 'bout petals ? ║
║ message │ Arrr, this here action be irreversible, matey! ║
║ confirmation │ map[id:123] ║
╟━━━━━━━━━━━━━━┼━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╢
║ Parsed confirmation data ║
╚══════════════╧═════════════════════════════════════════════════════╝
Be ye sure ye want a custom limerick 'bout petals ?
Arrr, this here action be irreversible, matey!
Reply: [y/N]
```
6. If I got a bad confirmation, it would look something like this
```
> sparklyunicorn: bad confirmation
Alas...The following is not a valid confirmation:
["conf"]
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!
```
7. And if debug mode was set to false, then I would only see the confirmation prompt itself.
```
gh debug-cli --log-level none
Setting url to http://localhost:8080/agents/blackbeard
Start typing to chat with your assistant...
sparklyunicorn: confirmation
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!
Be ye sure ye want a custom limerick 'bout petals ?
Arrr, this here action be irreversible, matey!
Reply: [y/N]
```
8. Currently, the supported event types for debug mode are references, errors, and confirmations! Have fun chatting with your assistant!
31 changes: 31 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Thanks for helping make GitHub safe for everyone.

# Security

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).

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.

## Reporting Security Issues

If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure.

**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**

Instead, please send an email to opensource-security[@]github.com.

Please include as much of the information listed below as you can to help us better understand and resolve the issue:

* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

## Policy

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)
13 changes: 13 additions & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Support

## How to file issues and get help

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.

For help or questions about using this project, please open an issue in the repository.

- **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.

## GitHub Support Policy

Support for this project is limited to the resources listed above.
83 changes: 83 additions & 0 deletions cmd/chat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package cmd

import (
"fmt"
"os"
"strings"

"github.com/github-technology-partners/gh-debug-cli/pkg/chat"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

const (
chatCmdURLFlag = "url"
chatCmdUsernameFlag = "username"
chatCmdLogLevelFlag = "log-level"
chatCmdTokenFlag = "token"
chatCmdPrivateKeyFlag = "private-key"
chatCmdPublicKeyFlag = "public-key"
)

var chatCmd = &cobra.Command{
Short: "Interact with your agent.",
Long: `This cli tool allows you to debug your agent by chatting with it locally.`,
Run: agentChat,
TraverseChildren: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error
cmd.Flags().VisitAll(func(f *pflag.Flag) {
optName := strings.ToUpper(f.Name)
optName = strings.ReplaceAll(optName, "-", "_")
if val, ok := os.LookupEnv(optName); !f.Changed && ok {
fmt.Printf("Setting %s to %s\n", f.Name, val)
err2 := f.Value.Set(val)
if err2 != nil {
err = fmt.Errorf("invalid environment variable %s: %w", optName, err2)
}
}
})
return err
}}

func init() {
chatCmd.CompletionOptions.DisableDefaultCmd = true

chatCmd.PersistentFlags().String(chatCmdURLFlag, "http://localhost:8080", "url to chat with your agent")
chatCmd.PersistentFlags().String(chatCmdUsernameFlag, "sparklyunicorn", "username to display in chat")
chatCmd.PersistentFlags().String(chatCmdTokenFlag, "", "GitHub token for chat authentication (optional)")
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.")
chatCmd.PersistentFlags().String(chatCmdPrivateKeyFlag, "", "Private key for payload verification")
chatCmd.PersistentFlags().String(chatCmdPublicKeyFlag, "", "Public key for payload verification")

}

func agentChat(cmd *cobra.Command, args []string) {

url, _ := cmd.Flags().GetString(chatCmdURLFlag)
if url == "" {
fmt.Println("a url is required to chat with your agent")
}

username, _ := cmd.Flags().GetString(chatCmdUsernameFlag)

token, _ := cmd.Flags().GetString(chatCmdTokenFlag)

debug, _ := cmd.Flags().GetString(chatCmdLogLevelFlag)
debug = strings.ToUpper(debug)
if debug != chat.LEVEL_NONE && debug != chat.LEVEL_DEBUG && debug != chat.LEVEL_TRACE {
fmt.Println("debug mode must be either `DEBUG`, `TRACE`, or `NONE`")
}

err := chat.Chat(url, username, token, debug)
if err != nil {
fmt.Println(err)
}
}

func Execute() {
err := chatCmd.Execute()
if err != nil {
os.Exit(1)
}
}
27 changes: 27 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module github.com/github-technology-partners/gh-debug-cli

go 1.21.0

toolchain go1.21

require (
github.com/alexeyco/simpletable v1.0.0
github.com/google/uuid v1.6.0
github.com/jclem/sseparser v0.5.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prataprc/goparsec v0.0.0-20211219142520-daac0e635e7e // indirect
github.com/rivo/uniseg v0.4.7 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 28f7ec1

Please sign in to comment.