Skip to content
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

feat: add new style code and text with chroma #33

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# This release drafter follows the conventions

name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
template: |
## What Changed 👀
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
categories:
- title: 🚀 Features
labels:
- feature
- title: 🐛 Bug Fixes
labels:
- fix
- bug
- title: 🧪 Test
labels:
- test
- title: 👷 CI
labels:
- ci
- title: ♻️ Refactor
labels:
- changed
- enhancement
- refactor
- title: ⛔️ Deprecated
labels:
- deprecated
- title: 🔐 Security
labels:
- security
- title: 📄 Documentation
labels:
- docs
- documentation
- title: 🧩 Dependency Updates
labels:
- deps
- dependencies
- title: 🧰 Maintenance
label: 'chore'
- title: 📝 Other changes
## putting no labels pr to `Other Changes` category with no label

# Using regex for defining rules
autolabeler:
- label: 'chore'
branch:
- '/(chore)\/.*/'
- label: 'security'
branch:
- '/(security)\/.*/'
- label: 'refactor'
branch:
- '/(refactor)\/.*/'
- label: 'docs'
branch:
- '/(docs)\/.*/'
- label: 'ci'
branch:
- '/(ci)\/.*/'
- label: 'test'
branch:
- '/(test)\/.*/'
- label: 'bug'
branch:
- '/(fix)\/.*/'
- label: 'feature'
branch:
- '/(feat)\/.*/'
- label: 'minor'
branch:
- '/(feat)\/.*/'
- label: 'patch'
branch:
- '/(fix)\/.*/'
body:
- '/JIRA-[0-9]{1,4}/'

change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- major
minor:
labels:
- minor
patch:
labels:
- patch
default: patch

exclude-labels:
- skip-changelog
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will build and test golang project

name: CI

on:
push:
branches: ["main"]
paths-ignore:
- "README.md"
- "CHANGELOG.md"
pull_request:
branches: ["main"]

jobs:

ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.23

- name: build
working-directory: ./
run: go build -v ./...

- name: test
working-directory: ./
run: go test -v ./...
21 changes: 21 additions & 0 deletions .github/workflows/release-drafter-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release Drafter Auto Labeler

on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled

jobs:
auto-labeler:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
disable-releaser: true # only run auto-labeler for PRs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release Drafter

on:
push:
branches:
- main

jobs:
update_release_draft:
name: Release drafter
runs-on: ubuntu-latest

steps:
- name: Update Release Draft
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ README.md

# License
LICENSE

# Config
config.yml
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ codai code --provider_name openapi --temperature 0.8
```
This flexibility allows you to customize config of codai on the fly.

> Note: We use [Chroma](https://github.com/alecthomas/chroma) for `style` of our `text` and `code block`, and you can find more theme here in [Chroma Style Gallery](https://xyproto.github.io/splash/docs/) and use it as a `buffering theme` in `codai`.

How to Run
To use **codai** as your code assistant, navigate to the directory where you want to apply codai and run the following command:

Expand Down Expand Up @@ -121,4 +123,4 @@ Thanks a bunch for supporting me!

Thanks to all [contributors](https://github.com/meysamhadeli/codai/graphs/contributors), you're awesome and this wouldn't be possible without you! The goal is to build a categorized, community-driven collection of very well-known resources.

Please follow this [contribution guideline](./CONTRIBUTION.md) to submit a pull request or create the issue.
Please follow this [contribution guideline](./CONTRIBUTION.md) to submit a pull request or create the issue.
15 changes: 14 additions & 1 deletion cmd/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,24 @@ func handleCodeCommand(rootDependencies *RootDependencies) {
for _, change := range changes {

// Prompt the user to accept or reject the changes
err := utils.ConfirmPrompt(change.RelativePath)
promptAccepted, err := utils.ConfirmPrompt(change.RelativePath)
if err != nil {
fmt.Println(lipgloss_color.Red.Render(fmt.Sprintf("Error getting user prompt: %v", err)))
continue
}

if promptAccepted {
err := rootDependencies.Analyzer.ApplyChanges(change.RelativePath)
if err != nil {
fmt.Println(lipgloss_color.Red.Render(fmt.Sprintf("Error applying changes: %v", err)))
continue
}
fmt.Println(lipgloss_color.Green.Render("✔️ Changes accepted!"))

} else {
fmt.Println(lipgloss_color.Red.Render("❌ Changes rejected."))
}

}

// Display token usage details in a boxed format after each AI request
Expand Down
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ var rootCmd = &cobra.Command{
Short: "codai CLI for coding and chatting",
Long: `codai is a CLI tool that assists developers by providing intelligent code suggestions, refactoring, and code reviews based on the full context of your project. It operates in a session-based manner, allowing for continuous context throughout interactions. Codai supports multiple LLMs, including GPT-3.5, GPT-4, and Ollama, to streamline daily development tasks.`,
Run: func(cmd *cobra.Command, args []string) {
handleRootCommand(cmd)
// Check if any arguments or subcommands were provided
if len(args) == 0 {
err := cmd.Help() // Display help if no subcommand or argument is provided
if err != nil {
return
}
} else {
// Run the handleRootCommand if arguments are provided
handleRootCommand(cmd)
}
},
}

Expand Down
11 changes: 4 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func LoadConfigs(rootCmd *cobra.Command, cwd string) *Config {
fmt.Println(lipgloss_color.Red.Render(fmt.Sprintf("Error reading config file: %v", err)))
os.Exit(1)
}
}

// Check if the user provided a config file via CLI
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
// Automatically look for 'config.yml' in the working directory if no CLI file is provided
viper.SetConfigName("config") // name of config file (without extension)
Expand All @@ -82,8 +77,10 @@ func LoadConfigs(rootCmd *cobra.Command, cwd string) *Config {
}

// Read the configuration file if available
err := viper.ReadInConfig()
if err != nil {
if err := viper.ReadInConfig(); err == nil {

} else if cfgFile != "" {
// If a specific config file was set but not found, show error and exit
fmt.Println(lipgloss_color.Red.Render(fmt.Sprintf("Error reading config file: %v", err)))
os.Exit(1)
}
Expand Down
9 changes: 5 additions & 4 deletions embed_data/prompts/code_block_prompt.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# You are a ai code assistant. I will provide you with a description of the change or feature I want to implement, along with the current code context of my project. Use the latest language feature and technology for your assistant.

Your tasks are according these steps:
> Your tasks are according these steps:

## Understand the context:
- Read the code context carefully.
Expand All @@ -9,8 +9,7 @@ Your tasks are according these steps:
## Return Code Block for Changes and Response Format
- For each file that requires changes, give the code modifications in `Code BLOCK` format.
- Do not combine multiple files into a single `Code BLOCK`.
- Put `relative path` of each file top of specific `Code Block` that you are modifying.
- Separate multiple `CodeBlock` with `dividers`.
- Put `relative path` of each file `top` of specific `Code Block` that you are `adding` or `modifying`.
- You MUST use this `CodeBlock format` for every modified or new file like below example:

File: relative path here.
Expand All @@ -34,4 +33,6 @@ File: relative path here.
- For each file you modify, provide a separate CodeBlock. **Do not** combine multiple files into one CodeBlock.
- If you create a new file, follow the same format, making sure the relative path is correct.
- **Avoid** using comments like "... rest of the code..." or "unchanged lines", always return the **full file content**.
- If you delete a file, use the same format but specify an `empty CodeBlock` with the file path.
- If you delete a file, use the same format but specify an `empty CodeBlock` with the file path.

### IMPORTANT: ALWAYS ADD `RELATIVE PATH` `TOP` OF EACH `CODE BLOCK`.
23 changes: 6 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/meysamhadeli/codai
go 1.23.2

require (
github.com/alecthomas/chroma/v2 v2.14.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/charmbracelet/glamour v0.8.0
github.com/charmbracelet/lipgloss v0.13.1
github.com/pkoukk/tiktoken-go v0.1.7
github.com/pterm/pterm v0.12.79
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
github.com/spf13/cobra v1.8.1
Expand All @@ -16,33 +17,24 @@ require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/charmbracelet/x/ansi v0.4.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/dop251/goja v0.0.0-20230304130813-e2f543bf4b4c // indirect
github.com/dop251/goja_nodejs v0.0.0-20230226152057-060fa99b809f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkoukk/tiktoken-go v0.1.7 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -51,17 +43,14 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tiktoken-go/tokenizer v0.2.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.7.4 // indirect
github.com/yuin/goldmark-emoji v1.0.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading