Skip to content

Commit 91b6ad5

Browse files
authored
Restrict llms.txt updates and enhance logging
1 parent 9d5f95c commit 91b6ad5

File tree

1 file changed

+74
-48
lines changed

1 file changed

+74
-48
lines changed

.github/workflows/main.yml

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,120 +32,146 @@ jobs:
3232
- name: Detect changed subdirectories
3333
id: detect-changes
3434
run: |
35+
echo "=== Detecting changed subdirectories ==="
36+
3537
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- docs/)
38+
echo "Changed files in docs/:"
39+
echo "$changed_files"
3640
3741
changed_subdirs=""
3842
for file in $changed_files; do
3943
subdir=$(echo "$file" | sed -n 's|^docs/\([^/]*\)/.*|\1|p')
4044
if [ -n "$subdir" ] && [ -f "docs/$subdir/llms.txt" ] && [ -f "docs/$subdir/llms-full.txt" ]; then
4145
if [[ ! "$changed_subdirs" =~ (^|[[:space:]])"$subdir"($|[[:space:]]) ]]; then
4246
changed_subdirs="$changed_subdirs $subdir"
47+
echo "Found subdirectory with llms files: $subdir"
4348
fi
4449
fi
4550
done
4651
4752
changed_subdirs=$(echo "$changed_subdirs" | xargs)
4853
4954
echo "changed_subdirs=$changed_subdirs" >> $GITHUB_OUTPUT
50-
echo "Found changed subdirectories: $changed_subdirs"
55+
echo "=== Final changed subdirectories: $changed_subdirs ==="
5156
52-
- name: Generate llms.txt updates with forced completion
57+
- name: Generate llms.txt updates (restricted)
5358
if: steps.detect-changes.outputs.changed_subdirs != ''
5459
env:
5560
MODEL: gpt-5
5661
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
5762
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5863
CHANGED_SUBDIRS: ${{ steps.detect-changes.outputs.changed_subdirs }}
5964
run: |
60-
# Create a script that will force completion
61-
cat > force_complete.sh << 'EOF'
62-
#!/bin/bash
63-
set -euo pipefail
64-
65-
echo "=== Starting forced completion approach ==="
65+
echo "=== Starting restricted file modification process ==="
66+
echo "Processing subdirectories: $CHANGED_SUBDIRS"
6667
67-
# Run cursor-agent in background
68-
cursor-agent -p "You are updating documentation summary files.
68+
cursor-agent -p "You are updating documentation summary files in a GitHub Actions runner.
6969
70-
TASK: Check if docs/$CHANGED_SUBDIRS/llms.txt and docs/$CHANGED_SUBDIRS/llms-full.txt need updates based on PR ${{ github.event.pull_request.number }}.
70+
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 and commenting on the PR.
7171
72-
PROCESS:
73-
1. Get diff: gh pr diff ${{ github.event.pull_request.number }}
74-
2. Read docs/$CHANGED_SUBDIRS/llms.txt
75-
3. Read docs/$CHANGED_SUBDIRS/llms-full.txt
76-
4. If changes warrant updates: modify the files
77-
5. If no updates needed: do nothing
78-
6. Print 'ANALYSIS_COMPLETE' and stop
72+
# Context:
73+
- Repo: ${{ github.repository }}
74+
- PR Number: ${{ github.event.pull_request.number }}
75+
- Base Ref: ${{ github.base_ref }}
76+
- Head Ref: ${{ github.head_ref }}
77+
- Changed Subdirectories: $CHANGED_SUBDIRS
7978
80-
CRITICAL: You have 5 minutes to complete this. Print 'ANALYSIS_COMPLETE' when done and exit immediately. Do not commit or push." \
81-
--force --model "$MODEL" --output-format=text &
82-
83-
AGENT_PID=$!
84-
echo "Started cursor-agent with PID: $AGENT_PID"
85-
86-
# Force kill after 5 minutes
87-
(sleep 300; echo "=== Forcing completion after 5 minutes ==="; kill -9 $AGENT_PID 2>/dev/null) &
88-
KILLER_PID=$!
89-
90-
# Wait for completion
91-
if wait $AGENT_PID 2>/dev/null; then
92-
echo "=== Agent completed normally ==="
93-
kill $KILLER_PID 2>/dev/null || true
94-
else
95-
echo "=== Agent was terminated ==="
96-
fi
97-
98-
echo "=== Process finished ==="
99-
EOF
100-
101-
chmod +x force_complete.sh
102-
./force_complete.sh
79+
# Your Task:
80+
Update llms.txt and llms-full.txt files in the changed subdirectories based on documentation changes in this PR.
10381
104-
- name: Commit changes directly to PR branch
82+
# Step-by-Step Process (print each step as you do it):
83+
1. Print 'STEP 1: Getting PR diff'
84+
2. Get PR changes: \`gh pr diff ${{ github.event.pull_request.number }}\`
85+
3. Print 'STEP 2: Processing subdirectories: $CHANGED_SUBDIRS'
86+
4. For each subdirectory in CHANGED_SUBDIRS:
87+
a. Print 'STEP 3a: Reading docs/[subdirectory]/llms.txt'
88+
b. Print 'STEP 3b: Reading docs/[subdirectory]/llms-full.txt'
89+
c. Print 'STEP 3c: Analyzing if updates are needed for [subdirectory]'
90+
d. If updates needed: Print 'STEP 3d: Updating files for [subdirectory]' and modify the files
91+
e. If no updates needed: Print 'STEP 3e: No updates needed for [subdirectory]'
92+
5. Print 'STEP 4: File modifications complete'
93+
6. Print 'TASK_FINISHED' and exit
94+
95+
# File Requirements:
96+
- Only modify docs/[subdirectory]/llms.txt and docs/[subdirectory]/llms-full.txt files
97+
- Do NOT modify root-level llms.txt or llms-full.txt files
98+
- llms.txt should be a concise summary/index of the documentation in that subdirectory
99+
- llms-full.txt should be a comprehensive guide with code examples and detailed explanations
100+
- Maintain existing format and style
101+
- Only update files that actually need changes based on PR content
102+
103+
# Critical Restrictions:
104+
- NO git operations (no commit, push, branch creation)
105+
- NO PR comments or API calls except gh pr diff
106+
- Only file modifications in working directory
107+
- Must print progress steps as you go
108+
- Must end with 'TASK_FINISHED'
109+
110+
Begin now and print each step clearly.
111+
" --force --model "$MODEL" --output-format=text
112+
113+
echo "=== Cursor agent file modification completed ==="
114+
115+
- name: Commit changes to PR branch (deterministic)
105116
if: steps.detect-changes.outputs.changed_subdirs != ''
106117
id: commit_changes
107118
run: |
108-
echo "changes_committed=false" >> "$GITHUB_OUTPUT"
119+
echo "=== Checking for file changes to commit ==="
109120
121+
# Stage all changes
110122
git add -A
111123
124+
# Check if there are any changes to commit
112125
if git diff --staged --quiet; then
113126
echo "No llms.txt changes to commit."
127+
echo "changes_committed=false" >> "$GITHUB_OUTPUT"
114128
exit 0
115129
fi
116130
117-
echo "Changes detected:"
131+
echo "Changes detected in the following files:"
118132
git diff --staged --name-only
119133
120-
COMMIT_MSG="docs: update llms summaries for PR #${{ github.event.pull_request.number }}"
134+
echo "=== Committing changes to PR branch ==="
135+
COMMIT_MSG="docs: update llms summaries for subdirectories (${{ steps.detect-changes.outputs.changed_subdirs }})"
121136
git commit -m "$COMMIT_MSG"
122137
git push origin ${{ github.head_ref }}
123138
124139
echo "changes_committed=true" >> "$GITHUB_OUTPUT"
140+
echo "=== Changes committed and pushed successfully ==="
125141
126-
- name: Comment on PR about updates
142+
- name: Post PR comment (deterministic)
127143
if: steps.commit_changes.outputs.changes_committed == 'true'
128144
env:
129145
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130146
PR_NUMBER: ${{ github.event.pull_request.number }}
131147
run: |
148+
echo "=== Posting PR comment about updates ==="
149+
150+
# Get list of changed llms files
132151
changed_llms_files=$(git diff HEAD~1 --name-only | grep -E "llms(-full)?\.txt$" | head -10)
133152
134153
COMMENT_FILE="${RUNNER_TEMP}/llms-update-comment.md"
135154
{
136-
echo "🤖 **LLMs summaries updated**"
155+
echo "🤖 **LLM summary files updated**"
156+
echo ""
157+
echo "Updated the following documentation summary files based on changes in subdirectories: \`${{ steps.detect-changes.outputs.changed_subdirs }}\`"
137158
echo ""
138-
echo "Updated documentation summary files:"
159+
echo "**Files updated:**"
139160
for file in $changed_llms_files; do
140161
echo "- \`$file\`"
141162
done
142163
echo ""
164+
echo "_This comment will be updated if you make more changes to the PR._"
165+
echo ""
143166
echo "<!-- auto-update-llms -->"
144167
} > "$COMMENT_FILE"
145168
169+
# Try to update existing comment, fall back to new comment
146170
if gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE" --edit-last; then
147171
echo "Updated existing PR comment."
148172
else
149173
gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE"
150174
echo "Posted new PR comment."
151175
fi
176+
177+
echo "=== PR comment posted successfully ==="

0 commit comments

Comments
 (0)