-
Notifications
You must be signed in to change notification settings - Fork 42
232 lines (202 loc) · 8.99 KB
/
checkpoint-fix.yml
File metadata and controls
232 lines (202 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Checkpoint AI Fix
on:
repository_dispatch:
types: [checkpoint-fix]
permissions:
contents: write
pull-requests: write
jobs:
fix:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
token: ${{ secrets.GH_PAT }}
- name: Notify running
run: |
curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \
-d '{
"reportId": "${{ github.event.client_payload.reportId }}",
"status": "running"
}'
- name: Setup branch
id: branch
run: |
SESSION_BRANCH="${{ github.event.client_payload.meta.sessionBranch }}"
if [ -n "$SESSION_BRANCH" ] && git ls-remote --exit-code --heads origin "$SESSION_BRANCH" >/dev/null 2>&1; then
git fetch origin "$SESSION_BRANCH"
git checkout "$SESSION_BRANCH"
echo "name=$SESSION_BRANCH" >> $GITHUB_OUTPUT
echo "is_new=false" >> $GITHUB_OUTPUT
else
BRANCH="checkpoint/${{ github.event.client_payload.reportId }}"
git checkout -b "$BRANCH"
echo "name=$BRANCH" >> $GITHUB_OUTPUT
echo "is_new=true" >> $GITHUB_OUTPUT
fi
- name: Write context
run: |
cat > /tmp/checkpoint-context.json << 'CONTEXT_EOF'
${{ toJSON(github.event.client_payload) }}
CONTEXT_EOF
- name: Download screenshots
run: |
mkdir -p /tmp/checkpoint-screenshots
URLS=$(echo '${{ toJSON(github.event.client_payload.screenshots) }}' | jq -r '.[]? | .screenshotUrl // empty')
if [ -n "$URLS" ]; then
i=1
while IFS= read -r url; do
if [ -n "$url" ]; then
curl -sL "$url" -o "/tmp/checkpoint-screenshots/screenshot-${i}.png" 2>/dev/null || true
echo "Downloaded screenshot $i"
i=$((i+1))
fi
done <<< "$URLS"
ls -la /tmp/checkpoint-screenshots/
else
echo "No screenshots to download"
fi
- name: Cache Amp CLI
id: amp-cache
uses: actions/cache@v4
with:
path: |
~/.amp
~/.local/bin/amp
key: amp-cli-${{ runner.os }}
- name: Install Amp
if: steps.amp-cache.outputs.cache-hit != 'true'
run: curl -fsSL https://ampcode.com/install.sh | bash
- name: Build prompt
id: prompt
run: |
SCREENSHOT_FILES=$(ls /tmp/checkpoint-screenshots/ 2>/dev/null | head -5)
SCREENSHOT_NOTE=""
if [ -n "$SCREENSHOT_FILES" ]; then
SCREENSHOT_NOTE="Screenshots of the element/area are in /tmp/checkpoint-screenshots/. Look at these images first to understand visually what needs to change."
fi
cat > /tmp/checkpoint-prompt.txt << 'PROMPT_EOF'
You are implementing a specific change requested via Checkpoint. Read AGENTS.md first for codebase structure. Then read /tmp/checkpoint-context.json for the full element context (selectors, styles, DOM).
PROMPT_EOF
cat >> /tmp/checkpoint-prompt.txt << PROMPT_VARS_EOF
Request: ${{ github.event.client_payload.title }}
Details: ${{ github.event.client_payload.description }}
Page URL: ${{ github.event.client_payload.url }}
${SCREENSHOT_NOTE}
Instructions:
1. Read AGENTS.md for project structure
2. Read /tmp/checkpoint-context.json for element context
3. Use the CSS selector or React component name from context to grep for the source file
4. Make the minimal change to implement exactly what was requested
5. Do not refactor, do not add comments, do not touch unrelated code
PROMPT_VARS_EOF
- name: Run AI Agent
env:
AMP_API_KEY: ${{ secrets.AMP_API_KEY }}
run: |
cat /tmp/checkpoint-prompt.txt | amp --dangerously-allow-all -x
- name: Commit and push
id: commit
run: |
REPORTER="${{ github.event.client_payload.meta.reporter }}"
if [ -n "$REPORTER" ] && [ "$REPORTER" != "Anonymous" ]; then
git config user.name "$REPORTER (via Checkpoint)"
git config user.email "checkpoint@tempo.xyz"
else
git config user.name "checkpoint-bot"
git config user.email "checkpoint@tempo.xyz"
fi
if git diff --quiet; then
echo "No changes to commit"
curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \
-d '{
"reportId": "${{ github.event.client_payload.reportId }}",
"status": "failed",
"error": "Agent produced no changes"
}'
exit 0
fi
git add -A
git commit -m "checkpoint: ${{ github.event.client_payload.title }}
Checkpoint Report: ${{ github.event.client_payload.reportId }}
Linear: ${{ github.event.client_payload.issue.id }}"
git push origin ${{ steps.branch.outputs.name }}
echo "pushed=true" >> $GITHUB_OUTPUT
- name: Build screenshot markdown
id: screenshots
run: |
SCREENSHOTS=$(echo '${{ toJSON(github.event.client_payload.screenshots) }}' | jq -r '[.[]? | select(.screenshotUrl) | ""] | join("\n\n")')
if [ -n "$SCREENSHOTS" ] && [ "$SCREENSHOTS" != "" ]; then
echo "markdown<<SCREENSHOTS_EOF" >> $GITHUB_OUTPUT
echo "$SCREENSHOTS" >> $GITHUB_OUTPUT
echo "SCREENSHOTS_EOF" >> $GITHUB_OUTPUT
fi
- name: Create PR
id: create_pr
if: steps.commit.outputs.pushed == 'true' && steps.branch.outputs.is_new == 'true'
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
PR_URL=$(gh pr create \
--title "checkpoint: ${{ github.event.client_payload.title }}" \
--body "## Checkpoint AI Change
**Reported by:** ${{ github.event.client_payload.meta.reporter }}
**Linear:** [${{ github.event.client_payload.issue.id }}](${{ github.event.client_payload.issue.url }})
**Report ID:** \`${{ github.event.client_payload.reportId }}\`
**URL:** ${{ github.event.client_payload.url }}
---
This PR was automatically generated by [Checkpoint](https://tempo-qa-xi.vercel.app) in response to a request.
### Request
${{ github.event.client_payload.description }}
### Screenshots
${{ steps.screenshots.outputs.markdown || '_No screenshots_' }}
### Context
See the linked Linear issue for full element context." \
--head "${{ steps.branch.outputs.name }}" \
--base ${{ github.event.repository.default_branch }})
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Notify PR opened
if: steps.create_pr.outputs.pr_url
run: |
curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \
-d '{
"reportId": "${{ github.event.client_payload.reportId }}",
"status": "pr_opened",
"prUrl": "${{ steps.create_pr.outputs.pr_url }}",
"prNumber": ${{ steps.create_pr.outputs.pr_number }},
"branch": "${{ steps.branch.outputs.name }}",
"issueId": "${{ github.event.client_payload.issue.id }}"
}'
- name: Notify commit added
if: steps.commit.outputs.pushed == 'true' && steps.branch.outputs.is_new == 'false'
run: |
curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \
-d '{
"reportId": "${{ github.event.client_payload.reportId }}",
"status": "committed",
"branch": "${{ steps.branch.outputs.name }}"
}'
- name: Notify failure
if: failure()
run: |
curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \
-d '{
"reportId": "${{ github.event.client_payload.reportId }}",
"status": "failed",
"error": "Workflow failed"
}'