Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ There are three special template strings that `cfme` recognizes by default:

- `<__GIT_DIFF__>` (required): Replaced with the output of `git diff --cached`
(i.e. the staged changes)
- `<__RESPONSE__REQUIREMENTS__>` (required): Replaced with a list of requirements
- `<__RESPONSE_FORMAT_REQUIREMENTS__>` (required): Replaced with a list of requirements
that dictates how the AI should format its response. This is essential so
that `cfme` can parse the AI's response.
Note that these requirements merely dictate the format of the response, they
Expand Down
6 changes: 5 additions & 1 deletion defaults/prompts/conventional-commits/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ You are an expert at creating git commit messages according to the Conventional

---

<__RESPONSE_REQUIREMENTS__>
<__RESPONSE_FORMAT_REQUIREMENTS__>

**Content Requirements:**

- ONLY and EXCLUSIVELY use the commit types listed in the following YAML file:

```yaml
<__ALLOWED_TYPES__>
```

- Make sure to follow Conventional Commits:
- A header is REQUIRED and must follow the format: `<required type>(<optional scope>): <required description>`
- type MUST match one of the types provided
- scope is OPTIONAL
- breaking changes can be indicated with ! in header or BREAKING CHANGE in footer
Expand Down
4 changes: 2 additions & 2 deletions spec/render_prompt_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Describe 'render_prompt'
It 'renders the prompt correctly with all variables replaced'
local prompt_template="$(cat spec/samples/sample-prompt-complete.md)"
declare -A vars_map
vars_map["<__RESPONSE_REQUIREMENTS__>"]="$(cat spec/samples/sample-response-requirements.md)"
vars_map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="$(cat spec/samples/sample-response-requirements.md)"
vars_map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
vars_map["<__VAR1__>"]="VAL1"
vars_map["<__VAR2__>"]="VAL2"
Expand All @@ -32,7 +32,7 @@ Describe 'render_prompt'
It 'renders the prompt correctly with empty instructions'
local prompt_template="$(cat spec/samples/sample-prompt-complete.md)"
declare -A vars_map
vars_map["<__RESPONSE_REQUIREMENTS__>"]="$(cat spec/samples/sample-response-requirements.md)"
vars_map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="$(cat spec/samples/sample-response-requirements.md)"
vars_map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
vars_map["<__VAR1__>"]="VAL1"
vars_map["<__VAR2__>"]="VAL2"
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/sample-prompt-complete.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<__RESPONSE_REQUIREMENTS__>
<__RESPONSE_FORMAT_REQUIREMENTS__>
<__GIT_DIFF__>
LINE_1
<__VAR1__>
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/sample-prompt-missing-1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<__RESPONSE_REQUIREMENTS__>
<__RESPONSE_FORMAT_REQUIREMENTS__>
<__GIT_DIFF__>
LINE_1
LINE2
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/sample-prompt-missing-diff.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<__RESPONSE_REQUIREMENTS__>
<__RESPONSE_FORMAT_REQUIREMENTS__>
LINE_1
<__VAR1__>
LINE2
Expand Down
4 changes: 2 additions & 2 deletions spec/samples/sample-rendered-prompt-with-instructions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Requirements:**
**Response Format Requirements:**

- Each commit message MUST include a 'header'.
- Optionally include 'body' and 'footer', ONLY if a 'header'
Expand All @@ -8,7 +8,7 @@

```yaml
commitMessages:
- header: "<type>[optional scope]: <description>"
- header: "<required header>"
body: "<optional body>"
footer: "<optional footer>"
score: <integer 0-100 representing confidence that this is the best commit message>
Expand Down
4 changes: 2 additions & 2 deletions spec/samples/sample-rendered-prompt-without-instructions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Requirements:**
**Response Format Requirements:**

- Each commit message MUST include a 'header'.
- Optionally include 'body' and 'footer', ONLY if a 'header'
Expand All @@ -8,7 +8,7 @@

```yaml
commitMessages:
- header: "<type>[optional scope]: <description>"
- header: "<required header>"
body: "<optional body>"
footer: "<optional footer>"
score: <integer 0-100 representing confidence that this is the best commit message>
Expand Down
4 changes: 2 additions & 2 deletions spec/samples/sample-response-requirements.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Requirements:**
**Response Format Requirements:**

- Each commit message MUST include a 'header'.
- Optionally include 'body' and 'footer', ONLY if a 'header'
Expand All @@ -8,7 +8,7 @@

```yaml
commitMessages:
- header: "<type>[optional scope]: <description>"
- header: "<required header>"
body: "<optional body>"
footer: "<optional footer>"
score: <integer 0-100 representing confidence that this is the best commit message>
Expand Down
14 changes: 7 additions & 7 deletions spec/validate_vars_map_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Describe 'validate_vars_map'

It 'validates variables successfully when everything matches'
local -A map
map["<__RESPONSE_REQUIREMENTS__>"]="SAMPLE_REQUIREMENTS"
map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="SAMPLE_FORMAT_REQUIREMENTS"
map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
map["<__VAR1__>"]="VAL1"
map["<__VAR2__>"]="VAL2"
Expand All @@ -31,7 +31,7 @@ Describe 'validate_vars_map'

It 'fails when a prompt is missing a custom variable present in the map'
local -A map
map["<__RESPONSE_REQUIREMENTS__>"]="SAMPLE_REQUIREMENTS"
map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="SAMPLE_FORMAT_REQUIREMENTS"
map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
map["<__VAR1__>"]="VAL1"
map["<__VAR2__>"]="VAL2"
Expand All @@ -44,9 +44,9 @@ Describe 'validate_vars_map'
The status should be failure
End

It 'fails when a prompt is missing mandatory template string RESPONSE_REQUIREMENTS in the prompt'
It 'fails when a prompt is missing mandatory template string RESPONSE_FORMAT_REQUIREMENTS in the prompt'
local -A map
map["<__RESPONSE_REQUIREMENTS__>"]="SAMPLE_REQUIREMENTS"
map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="SAMPLE_FORMAT_REQUIREMENTS"
map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
map["<__VAR1__>"]="VAL1"
map["<__VAR2__>"]="VAL2"
Expand All @@ -55,13 +55,13 @@ Describe 'validate_vars_map'
local variables_file_path="/path/to/variables.yaml"
local prompt="$(cat spec/samples/sample-prompt-missing-requirements.md)"
When call validate_vars_map map "$prompt"
The stderr should eq "Error: key '<__RESPONSE_REQUIREMENTS__>' is essential for cfme to function, but not present in the prompt."
The stderr should eq "Error: key '<__RESPONSE_FORMAT_REQUIREMENTS__>' is essential for cfme to function, but not present in the prompt."
The status should be failure
End

It 'fails when a prompt is missing mandatory template string GIT_DIFF in the prompt'
local -A map
map["<__RESPONSE_REQUIREMENTS__>"]="SAMPLE_REQUIREMENTS"
map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="SAMPLE_FORMAT_REQUIREMENTS"
map["<__GIT_DIFF__>"]="SAMPLE_DIFF"
map["<__VAR1__>"]="VAL1"
map["<__VAR2__>"]="VAL2"
Expand All @@ -76,7 +76,7 @@ Describe 'validate_vars_map'

It 'fails when a map is missing a variable present in the prompt'
local -A map
map["<__RESPONSE_REQUIREMENTS__>"]="SAMPLE_REQUIREMENTS"
map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="SAMPLE_FORMAT_REQUIREMENTS"
map["<__GIT_DIFF__>"]="SAMPLE_DIFF"

map["<__VAR2__>"]="VAL2"
Expand Down
6 changes: 3 additions & 3 deletions src/lib/load_vars_map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ load_vars_map() {
# Add defaults to the map
referenced_map["<__GIT_DIFF__>"]="$(git diff --cached)"

referenced_map["<__RESPONSE_REQUIREMENTS__>"]="$(
referenced_map["<__RESPONSE_FORMAT_REQUIREMENTS__>"]="$(
cat <<'EOF'
**Requirements:**
**Response Format Requirements:**

- Each commit message MUST include a 'header'.
- Optionally include 'body' and 'footer', ONLY if a 'header'
Expand All @@ -48,7 +48,7 @@ load_vars_map() {

```yaml
commitMessages:
- header: "<type>[optional scope]: <description>"
- header: "<required header>"
body: "<optional body>"
footer: "<optional footer>"
score: <integer 0-100 representing confidence that this is the best commit message>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validate_vars_map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function validate_vars_map() {
continue
fi
if ! grep -q "$key" <<<"$prompt"; then
if [[ "$key" == "<__RESPONSE_REQUIREMENTS__>" || "$key" == "<__GIT_DIFF__>" ]]; then
if [[ "$key" == "<__RESPONSE_FORMAT_REQUIREMENTS__>" || "$key" == "<__GIT_DIFF__>" ]]; then
# This key is mandatory
echo "Error: key '$key' is essential for cfme to function, but not present in the prompt." >&2
return 1
Expand Down