-
Notifications
You must be signed in to change notification settings - Fork 129
127 lines (115 loc) · 4.62 KB
/
claudebox.yml
File metadata and controls
127 lines (115 loc) · 4.62 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
name: ClaudeBox
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
prompt:
description: 'Prompt / instructions for Claude'
required: true
type: string
link:
description: 'Context link (e.g., PR URL, issue URL, external reference)'
required: false
type: string
jobs:
claudebox:
if: >-
github.event_name == 'workflow_dispatch' ||
startsWith(github.event.comment.body, '/claudebox')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check write access
if: github.event_name == 'issue_comment'
run: |
ASSOCIATION="${{ github.event.comment.author_association }}"
echo "Author association: $ASSOCIATION"
if [[ "$ASSOCIATION" != "OWNER" && "$ASSOCIATION" != "MEMBER" && "$ASSOCIATION" != "COLLABORATOR" ]]; then
echo "ERROR: User does not have write access (association: $ASSOCIATION)"
exit 1
fi
echo "Access granted."
- name: Add reaction
if: github.event_name == 'issue_comment'
env:
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
run: |
gh api \
repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
-f content='eyes' || true
- name: Parse command
id: parse
env:
COMMENT_BODY: ${{ github.event.comment.body || '' }}
INPUT_PROMPT: ${{ inputs.prompt || '' }}
INPUT_LINK: ${{ inputs.link || '' }}
run: |
if [ -n "$INPUT_PROMPT" ]; then
PROMPT="$INPUT_PROMPT"
LINK="$INPUT_LINK"
else
PROMPT=$(printf '%s' "$COMMENT_BODY" | sed 's|^/claudebox[[:space:]]*||')
LINK=""
fi
echo "link=$LINK" >> "$GITHUB_OUTPUT"
{
echo "prompt<<PROMPT_EOF"
echo "$PROMPT"
echo "PROMPT_EOF"
} >> "$GITHUB_OUTPUT"
echo "Parsed: prompt=${PROMPT:0:120}"
- name: Post status comment
id: status_comment
if: github.event_name == 'issue_comment'
env:
GH_TOKEN: ${{ secrets.AZTEC_BOT_GITHUB_TOKEN }}
PROMPT_TEXT: ${{ steps.parse.outputs.prompt }}
run: |
ISSUE_NUM="${{ github.event.issue.number }}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
SHORT_PROMPT=$(printf '%.120s' "$PROMPT_TEXT")
BODY="**ClaudeBox**: _${SHORT_PROMPT}_ ... [workflow run]($RUN_URL)"
COMMENT_ID=$(gh api \
repos/${{ github.repository }}/issues/$ISSUE_NUM/comments \
-f body="$BODY" \
--jq '.id')
echo "run_comment_id=$COMMENT_ID" >> "$GITHUB_OUTPUT"
echo "Posted status comment: $COMMENT_ID"
- name: Run ClaudeBox
timeout-minutes: 5
env:
CLAUDEBOX_URL: ${{ vars.CLAUDEBOX_URL }}
CLAUDEBOX_API_SECRET: ${{ secrets.CLAUDEBOX_API_SECRET }}
CLAUDEBOX_PROMPT: ${{ steps.parse.outputs.prompt }}
CLAUDEBOX_LINK: ${{ steps.parse.outputs.link }}
COMMENT_ID: ${{ github.event.comment.id || '' }}
RUN_COMMENT_ID: ${{ steps.status_comment.outputs.run_comment_id || '' }}
REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
AUTHOR: ${{ github.event.comment.user.login || github.actor }}
run: |
PAYLOAD=$(jq -n \
--arg prompt "$CLAUDEBOX_PROMPT" \
--arg user "$AUTHOR" \
--arg comment_id "$COMMENT_ID" \
--arg run_comment_id "$RUN_COMMENT_ID" \
--arg repo "$REPO" \
--arg run_url "$RUN_URL" \
--arg link "$CLAUDEBOX_LINK" \
'{prompt: $prompt, user: $user, comment_id: $comment_id, run_comment_id: $run_comment_id, repo: $repo, run_url: $run_url, link: $link}')
# POST to ClaudeBox — returns 202 immediately with log URL
RESPONSE=$(curl -sS -w "\n%{http_code}" \
-H "Authorization: Bearer ${CLAUDEBOX_API_SECRET}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"${CLAUDEBOX_URL}/run")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | head -n -1)
if [ "$HTTP_CODE" -ge 400 ] 2>/dev/null; then
echo "ClaudeBox returned HTTP $HTTP_CODE: $BODY"
exit 1
fi
LOG_URL=$(echo "$BODY" | jq -r '.log_url // empty')
echo "ClaudeBox session started: $LOG_URL"