Skip to content

Commit 91f6f3c

Browse files
committed
add llms txt automation
1 parent 6407734 commit 91f6f3c

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

.github/workflows/llms-txt-automation.yml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Update llms.txt and llms-full.txt in subdirectories
33
on:
44
pull_request:
55
types: [opened, synchronize, reopened, ready_for_review]
6+
issue_comment:
7+
types: [created]
68

79
permissions:
810
contents: write
@@ -161,6 +163,15 @@ jobs:
161163
echo "- \`$file\`"
162164
done
163165
echo ""
166+
echo "---"
167+
echo "💬 **Need changes to the LLM summaries?**"
168+
echo "Reply to this comment with your feedback and I'll update the files accordingly!"
169+
echo ""
170+
echo "**Example feedback:**"
171+
echo "- \"The summary is missing information about X feature\""
172+
echo "- \"Please add more code examples for Y\""
173+
echo "- \"The llms-full.txt should include Z section\""
174+
echo ""
164175
echo "_This comment will be updated if you make more changes to the PR._"
165176
echo ""
166177
echo "<!-- auto-update-llms -->"
@@ -175,3 +186,171 @@ jobs:
175186
fi
176187
177188
echo "=== PR comment posted successfully ==="
189+
190+
feedback-handler:
191+
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '🤖 **LLM summary files updated**')
192+
runs-on: ubuntu-latest
193+
steps:
194+
- name: Check if comment is a reply to bot comment
195+
id: check-reply
196+
env:
197+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
198+
PR_NUMBER: ${{ github.event.issue.number }}
199+
COMMENT_ID: ${{ github.event.comment.id }}
200+
run: |
201+
echo "=== Checking if this is feedback on LLM updates ==="
202+
203+
# Get all comments on the PR
204+
comments=$(gh api repos/${{ github.repository }}/issues/$PR_NUMBER/comments --jq '.[].body')
205+
206+
# Check if there's a bot comment with the auto-update-llms marker
207+
if echo "$comments" | grep -q "<!-- auto-update-llms -->"; then
208+
echo "Found bot comment with LLM updates"
209+
210+
# Get the current comment
211+
current_comment=$(gh api repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body')
212+
213+
# Check if the current comment is NOT the bot comment itself
214+
if ! echo "$current_comment" | grep -q "<!-- auto-update-llms -->"; then
215+
echo "This is user feedback, not the bot comment itself"
216+
echo "is_feedback=true" >> $GITHUB_OUTPUT
217+
echo "feedback_text=$current_comment" >> $GITHUB_OUTPUT
218+
else
219+
echo "This is the bot comment itself, not user feedback"
220+
echo "is_feedback=false" >> $GITHUB_OUTPUT
221+
fi
222+
else
223+
echo "No bot comment found with LLM updates"
224+
echo "is_feedback=false" >> $GITHUB_OUTPUT
225+
fi
226+
227+
- name: Checkout repository for feedback processing
228+
if: steps.check-reply.outputs.is_feedback == 'true'
229+
uses: actions/checkout@v4
230+
with:
231+
fetch-depth: 0
232+
ref: ${{ github.head_ref }}
233+
token: ${{ secrets.GITHUB_TOKEN }}
234+
235+
- name: Install Cursor CLI for feedback
236+
if: steps.check-reply.outputs.is_feedback == 'true'
237+
run: |
238+
curl https://cursor.com/install -fsS | bash
239+
echo "$HOME/.cursor/bin" >> $GITHUB_PATH
240+
241+
- name: Configure git for feedback
242+
if: steps.check-reply.outputs.is_feedback == 'true'
243+
run: |
244+
git config user.name "Cursor Agent"
245+
git config user.email "cursoragent@cursor.com"
246+
247+
- name: Process feedback and update files
248+
if: steps.check-reply.outputs.is_feedback == 'true'
249+
env:
250+
MODEL: gpt-5
251+
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
252+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
253+
FEEDBACK_TEXT: ${{ steps.check-reply.outputs.feedback_text }}
254+
PR_NUMBER: ${{ github.event.issue.number }}
255+
run: |
256+
echo "=== Processing user feedback for LLM files ==="
257+
echo "Feedback received: $FEEDBACK_TEXT"
258+
259+
cursor-agent -p "You are processing user feedback about LLM summary files in a GitHub Actions runner.
260+
261+
IMPORTANT: Do NOT create branches, commit, push, or post PR comments. Only modify files in the working directory as needed. A later workflow step is responsible for publishing changes.
262+
263+
# Context:
264+
- Repo: ${{ github.repository }}
265+
- PR Number: $PR_NUMBER
266+
- User Feedback: $FEEDBACK_TEXT
267+
268+
# Your Task:
269+
Based on the user feedback, update the appropriate llms.txt and llms-full.txt files in the docs subdirectories.
270+
271+
# Step-by-Step Process (print each step as you do it):
272+
1. Print 'STEP 1: Analyzing user feedback'
273+
2. Print 'STEP 2: Getting current PR diff to understand context'
274+
3. Get PR changes: \`gh pr diff $PR_NUMBER\`
275+
4. Print 'STEP 3: Identifying which subdirectories need updates based on feedback'
276+
5. For each relevant subdirectory:
277+
a. Print 'STEP 4a: Reading current docs/[subdirectory]/llms.txt'
278+
b. Print 'STEP 4b: Reading current docs/[subdirectory]/llms-full.txt'
279+
c. Print 'STEP 4c: Applying user feedback to [subdirectory] files'
280+
d. Update the files based on the specific feedback provided
281+
6. Print 'STEP 5: Feedback processing complete'
282+
7. Print 'FEEDBACK_PROCESSED' and exit
283+
284+
# File Requirements:
285+
- Only modify docs/[subdirectory]/llms.txt and docs/[subdirectory]/llms-full.txt files
286+
- Apply the specific changes requested in the user feedback
287+
- Maintain existing format and style while incorporating feedback
288+
- Focus on the areas specifically mentioned in the feedback
289+
290+
# Critical Restrictions:
291+
- NO git operations (no commit, push, branch creation)
292+
- NO PR comments or API calls except gh pr diff
293+
- Only file modifications in working directory
294+
- Must print progress steps as you go
295+
- Must end with 'FEEDBACK_PROCESSED'
296+
297+
Begin now and print each step clearly.
298+
" --force --model "$MODEL" --output-format=text
299+
300+
echo "=== Feedback processing completed ==="
301+
302+
- name: Commit feedback changes
303+
if: steps.check-reply.outputs.is_feedback == 'true'
304+
id: commit_feedback
305+
run: |
306+
echo "=== Checking for feedback-based changes to commit ==="
307+
308+
# Stage all changes
309+
git add -A
310+
311+
# Check if there are any changes to commit
312+
if git diff --staged --quiet; then
313+
echo "No changes to commit based on feedback."
314+
echo "changes_committed=false" >> "$GITHUB_OUTPUT"
315+
exit 0
316+
fi
317+
318+
echo "Changes detected based on feedback:"
319+
git diff --staged --name-only
320+
321+
echo "=== Committing feedback changes to PR branch ==="
322+
COMMIT_MSG="docs: update llms summaries based on user feedback"
323+
git commit -m "$COMMIT_MSG"
324+
git push origin ${{ github.head_ref }}
325+
326+
echo "changes_committed=true" >> "$GITHUB_OUTPUT"
327+
echo "=== Feedback changes committed and pushed successfully ==="
328+
329+
- name: Reply to feedback comment
330+
if: steps.commit_feedback.outputs.changes_committed == 'true'
331+
env:
332+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
333+
PR_NUMBER: ${{ github.event.issue.number }}
334+
COMMENT_ID: ${{ github.event.comment.id }}
335+
run: |
336+
echo "=== Replying to feedback comment ==="
337+
338+
# Get list of changed llms files
339+
changed_llms_files=$(git diff HEAD~1 --name-only | grep -E "llms(-full)?\.txt$" | head -10)
340+
341+
REPLY_FILE="${RUNNER_TEMP}/feedback-reply.md"
342+
{
343+
echo "✅ **Feedback processed!**"
344+
echo ""
345+
echo "I've updated the LLM summary files based on your feedback."
346+
echo ""
347+
echo "**Files updated:**"
348+
for file in $changed_llms_files; do
349+
echo "- \`$file\`"
350+
done
351+
echo ""
352+
echo "The changes have been committed to this PR. Please review and let me know if you need any further adjustments!"
353+
} > "$REPLY_FILE"
354+
355+
gh pr comment "$PR_NUMBER" --body-file "$REPLY_FILE"
356+
echo "=== Feedback reply posted successfully ==="

0 commit comments

Comments
 (0)