-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (153 loc) · 6.81 KB
/
dragon-ai.yml
File metadata and controls
183 lines (153 loc) · 6.81 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
name: Dragon AI Agent GitHub Mentions
env:
ROBOT_VERSION: v1.9.7
TOOLS_DIR: ${{ github.workspace }}/tools
on:
issues:
types: [opened, edited]
issue_comment:
types: [created, edited]
pull_request:
types: [opened, edited]
pull_request_review_comment:
types: [created, edited]
jobs:
check-mention:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.check.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check for qualifying mention
id: check
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_FOR_PR }} # Use PAT instead of default token
script: |
// Load allowed users from config
const fs = require('fs');
let allowedUsers = [];
try {
const configContent = fs.readFileSync('.github/ai-controllers.json', 'utf8');
allowedUsers = JSON.parse(configContent);
} catch (error) {
console.log('Error loading allowed users:', error);
allowedUsers = ['cmungall']; // Fallback
}
// Get content and user from event payload directly to avoid API calls when possible
let content = '';
let userLogin = '';
let itemType = '';
let itemNumber = 0;
if (context.eventName === 'issues') {
content = context.payload.issue.body || '';
userLogin = context.payload.issue.user.login;
itemType = 'issue';
itemNumber = context.payload.issue.number;
} else if (context.eventName === 'pull_request') {
content = context.payload.pull_request.body || '';
userLogin = context.payload.pull_request.user.login;
itemType = 'pull_request';
itemNumber = context.payload.pull_request.number;
} else if (context.eventName === 'issue_comment') {
content = context.payload.comment.body || '';
userLogin = context.payload.comment.user.login;
itemType = 'issue';
itemNumber = context.payload.issue.number;
} else if (context.eventName === 'pull_request_review_comment') {
content = context.payload.comment.body || '';
userLogin = context.payload.comment.user.login;
itemType = 'pull_request';
itemNumber = context.payload.pull_request.number;
}
// Check if user is allowed and mention exists
const isAllowed = allowedUsers.includes(userLogin);
const mentionRegex = /@dragon-ai-agent\s+please\s+(.*)/i;
const mentionMatch = content.match(mentionRegex);
const qualifiedMention = isAllowed && mentionMatch !== null;
const prompt = qualifiedMention ? mentionMatch[1].trim() : '';
console.log(`User: ${userLogin}, Allowed: ${isAllowed}, Has mention: ${mentionMatch !== null}`);
return {
qualifiedMention,
itemType,
itemNumber,
prompt,
user: userLogin,
controllers: allowedUsers.map(u => '@' + u).join(', ')
};
respond-to-mention:
needs: check-mention
if: fromJSON(needs.check-mention.outputs.result).qualifiedMention == true
permissions:
contents: write
pull-requests: write
issues: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.PAT_FOR_PR }} # Use PAT for checkout to allow committing later
- name: Configure Git
run: |
git config --global user.name "Dragon-AI Agent"
git config --global user.email "dragon-ai-agent[bot]@users.noreply.github.com"
- name: Create tools directory
run: mkdir -p ${{ env.TOOLS_DIR }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: install claude
run: |
npm install -g @anthropic-ai/claude-code
- name: Set up environment
run: |
echo "BRANCH_NAME=dragon_ai_agent_${{ fromJSON(needs.check-mention.outputs.result).itemNumber }}" >> $GITHUB_ENV
# Safely write prompt to file
mkdir -p /tmp/claude-input
echo "${{ fromJSON(needs.check-mention.outputs.result).prompt }}" > /tmp/claude-input/prompt.txt
- name: Set up Anthropic API key and GitHub token
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GH_TOKEN: ${{ secrets.PAT_FOR_PR }} # Kept PAT as requested
run: |
echo "ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY" >> $GITHUB_ENV
echo "GH_TOKEN=$GH_TOKEN" >> $GITHUB_ENV
echo "LOGFIRE_SEND_TO_LOGFIRE=false" >> $GITHUB_ENV
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install python tools
run: |
uv venv
source .venv/bin/activate
- name: Create structured Claude prompt
run: |
cat > /tmp/claude-input/claude_prompt.txt << EOL
You are @dragon-ai-agent.
You're responding to a request from or relayed by @${{ fromJSON(needs.check-mention.outputs.result).user }} on GitHub ${{ fromJSON(needs.check-mention.outputs.result).itemType }} #${{ fromJSON(needs.check-mention.outputs.result).itemNumber }}.
You only respond to requests from the following authorized controllers: ${{ fromJSON(needs.check-mention.outputs.result).controllers }}.
You should use \`gh\` to communicate with the user via the GitHub issue/ticket.
If instructed to modify files, you should make changes on a branch and submit a PR, communicating clearly and in
detail on the PR.
Always end by informing the user what you did (or were not able to do) with a message, either on an issue or a PR,
as appropriate.
The request is below, enclosed in triple backticks:
\`\`\`
$(cat /tmp/claude-input/prompt.txt)
\`\`\`
However, you should use `gh` to read the complete context of the request, and look at any linked issues or PRs
that provide additional context.
EOL
- name: Run Claude Code in headless mode
id: claude-response
run: |
# Python env
source .venv/bin/activate
# Run Claude with proper permissions
claude -p "$(cat /tmp/claude-input/claude_prompt.txt)" \
--output-format stream-json \
--allowedTools "Bash(git:*)" "Bash(gh:*)" "FileSystem(*)" \
--verbose