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

Enhance AI-driven development scripts and update documentation #7

Merged
merged 16 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
72ffcbd
docs(prompts): update code review prompt for clarity and formatting
alexsoyes Jul 3, 2024
febd678
chore(aliases): add aiddc-commits-diff-main alias
alexsoyes Jul 3, 2024
8cad47c
chore(main.js): clean up commented code and adjust GEN_AI_TEMPERATURE
alexsoyes Jul 3, 2024
64f34cc
fix(commit-msg): improve error handling and messaging in aidd-commit-…
alexsoyes Jul 3, 2024
64f21c1
feat: add script to get commit diffs between current branch and main
alexsoyes Jul 3, 2024
7a174e2
feat(aiddc-scripts): add function to list untracked files and update …
alexsoyes Jul 3, 2024
3b2873c
fix(aiddc): empty output
alexsoyes Jul 3, 2024
cc06de5
docs(prompts): update code review template to include commits and cha…
alexsoyes Jul 3, 2024
42f5c50
docs(prompts): update code review template to include inline template…
alexsoyes Jul 3, 2024
040a9f2
feat(main.js): add support for Ollama API and refactor API calls
alexsoyes Jul 8, 2024
6db1452
fix(commit-msg): correct logical return for no created files
alexsoyes Jul 8, 2024
6c02470
docs(README): add Ollama support information
alexsoyes Jul 8, 2024
e25d4ce
chore(env): update .env.example for local model and OpenAI settings
alexsoyes Jul 8, 2024
b0917b5
fix(main.js): correct cost formatting and refactor API call logic
alexsoyes Jul 8, 2024
4f16d69
feat(main.js): add logic to choose between local and OpenAI APIs base…
alexsoyes Jul 8, 2024
7e5a408
feat(aidd-pull-request.sh): add argument parsing and validation for t…
alexsoyes Jul 8, 2024
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
17 changes: 13 additions & 4 deletions ai-driven-dev-prompts/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ matches:
If not, list the potential issues in bullet points and suggest possible solutions.
- trigger: ':reviewCreatePullRequest'
form: |
Goal: Create a pull request for my changes.
Goal:
Create a pull request for my changes.

Rules:
- Use the following template file: #file
- "AI instruction" comments are hints for you, follow them carefully, then, delete them.
- Here are the changes:
- Use the changes from main.
- Fill the "template" file to create the PR (the "output").
- "Instructions" comments must be followed no matter what.
- "Instructions" comments must be remove from the output.
- Output should be properly formatted in markdown.

Template: #file

Code changes (surrendered by `---`):
---
[[copy_your_git_changes_from_main_here]]
---
form_fields:
copy_your_git_changes_from_main_here:
multiline: true
Expand Down
17 changes: 13 additions & 4 deletions resources/prompts/code-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,20 @@ Create a pull request from an AI template (eg: using `.github/pull_request_templ
**Prompt**:

```text
Goal: Create a pull request for my changes.
Goal:
Create a pull request for my changes.

Rules:
- Use the following template file: #file
- "AI instruction" comments are hints for you, follow them carefully, then, delete them.
- Here are the changes:
- Use the changes from main.
- Fill the "template" file to create the PR (the "output").
- "Instructions" comments must be followed no matter what.
- "Instructions" comments must be remove from the output.
- Output should be properly formatted in markdown.

Template: #file

Code changes (surrendered by `---`):
---
[[Copy your git changes (from main?) here]]
---
```
1 change: 1 addition & 0 deletions scripts/aiddc/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ alias aiddc-review='~/.aiddc/scripts/aidd-review.sh'
# Commits
alias aiddc-commit-msg='~/.aiddc/scripts/aidd-commit-msg.sh'
alias aiddc-commit-last='~/.aiddc/scripts/aidd-commit-last.sh'
alias aiddc-commits-diff-main='~/.aiddc/scripts/aidd-commits-diff-main.sh'

# Scripts
alias aiddc-changes='~/.aiddc/scripts/aidd-changes.sh'
Expand Down
13 changes: 5 additions & 8 deletions scripts/aiddc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* It reads environment variables, validates the OpenAI API key, and provides functions to call the OpenAI API.
*/

// const fs = require('fs');
// const path = require('path');
// const https = require('https');
// const readline = require('readline');
import path from 'path';
import { fileURLToPath } from 'url';

Expand All @@ -19,7 +15,6 @@ import fs from 'fs';
import https from 'https';
import readline from 'readline';

// Redefine console.error to always print in red
console.error = (function(origError) {
return function(...args) {
origError('\x1b[31m', ...args, '\x1b[0m');
Expand All @@ -32,7 +27,6 @@ console.warn = (function(origWarn) {
};
})(console.warn);


console.info = (function(origInfo) {
return function(...args) {
origInfo('\x1b[32m', ...args, '\x1b[0m');
Expand Down Expand Up @@ -68,11 +62,14 @@ if (!process.env.OPENAI_API_KEY) {
// Gen-AI parameters
const GEN_AI_MODEL = 'gpt-4o';
const GEN_AI_MAX_TOKENS = 600;
const GEN_AI_TEMPERATURE = 0.7;
const GEN_AI_TEMPERATURE = 1;
const GEN_AI_SYSTEM_MESSAGE = `
Act as a Senior Software Engineer that is experienced in software craft.
Assist with high-quality, concise, efficient, and scalable software solutions.
Limit the response to minimum tokens.
Limit the response to minimum tokens when possible.

Remember that code that will be provided to you is the result of a "git diff" command.
"-" means that a line was removed, and "+" means that a line was added, etc.
`;

/**
Expand Down
36 changes: 33 additions & 3 deletions scripts/aiddc/scripts/aidd-commit-msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,44 @@ notice "[aidd-commit-msg]: Preparing commit message"
PREV_COMMIT_MSG=$(git log -10 --pretty=format:%s)

# Current staged git changes.
CHANGES=$(git diff --staged)
CHANGES=$(git diff)
CURRENT_DIR=$(pwd)
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote the variable to prevent word splitting.

The CHANGES variable should be quoted to prevent word splitting and potential issues with filenames containing spaces.

- CHANGES=$(git diff)
+ CHANGES="$(git diff)"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CHANGES=$(git diff)
CURRENT_DIR=$(pwd)
CHANGES="$(git diff)"
CURRENT_DIR=$(pwd)


# If there is no changes, exit.
if [ -z "$CHANGES" ]; then
error "No changes to commit"
echo "Please stage your changes before generating a commit message."
echo "Please UNSTAGE changes before generating a commit message."
exit 1
fi

# FUNCTION
# --------------------
created_files_prompt() {

local UNTRACKED=$(git ls-files --others --exclude-standard)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use local in POSIX sh, declare and assign separately, and quote the variable.

In POSIX sh, local is undefined. Declare and assign separately to avoid masking return values, and quote the variable to prevent word splitting.

- local UNTRACKED=$(git ls-files --others --exclude-standard)
+ UNTRACKED="$(git ls-files --others --exclude-standard)"

Committable suggestion was skipped due to low confidence.

Tools
Shellcheck

[warning] 29-29: In POSIX sh, 'local' is undefined.

(SC3043)


[warning] 29-29: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 29-29: Quote this to prevent word splitting.

(SC2046)


if [ -z "$UNTRACKED" ]; then
return "No created files."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return values in shell functions must be numeric.

The return statement can only return numeric values (0-255). Use echo to output the message instead.

- return "No created files."
+ echo "No created files."
+ return 0
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return "No created files."
echo "No created files."
return 0
Tools
Shellcheck

[error] 32-32: Can only return 0-255. Other data should be written to stdout.

(SC2152)

fi

echo "Created files:"

for file in $UNTRACKED; do
echo "---"
echo "$file"
cat "$file"
echo "---"
echo ""
done
}

# PROMPT
# --------------------
PROMPT=$(cat <<EOF
Goal:
Generate git add + git commit message for every changes in the code.
1. Summarize functionnal changes in comments, with numbered list.
2. Identify hunks (but do not display them).
3. Generate git add + git commit message for every changes in the code, following rules.

Rules:
- Should be formatted in Conventional Commit.
Expand All @@ -34,12 +58,18 @@ Rules:
- Commits should be small and focused on a single change.
- 1 commit message can have multiple files changes.
- Answer with shell script ONLY.
- Use relative git add path based on $CURRENT_DIR.
- Use "git add --patch" with hunks when little changes are made.
- When using path option, be sure to "y" in EOF multiple if needed.
- Do not use "git add --patch" one 1 line changes.

Previous commit messages:
$PREV_COMMIT_MSG

Current git changes:
$CHANGES

$(created_files_prompt)
EOF
)

Expand Down
24 changes: 24 additions & 0 deletions scripts/aiddc/scripts/aidd-commits-diff-main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

. "$(dirname "$0")/_.sh"

# REQUIREMENTS
# --------------------
check_binary "git"

# NOTICE
# --------------------
notice "[aiddc-commits-diff-main]: Get the commits diff between the current branch and main branch."

# PROMPT PARAMS
# --------------------
DIFF=$(git log --oneline --no-merges main..HEAD)

#
# PROMPT
#
PROMPT=$DIFF
#
# COPY OUTPUT
#
copy "$PROMPT"