forked from strands-agents/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (172 loc) · 6.11 KB
/
strands-command.yml
File metadata and controls
184 lines (172 loc) · 6.11 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
name: Strands Command Handler
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
issue_id:
description: 'Issue ID to process (can be issue or PR number)'
required: true
type: string
command:
description: 'Strands command to execute'
required: false
type: string
default: ''
session_id:
description: 'Optional session ID to use'
required: false
type: string
default: ''
jobs:
authorization-check:
if: startsWith(github.event.comment.body, '/strands') || github.event_name == 'workflow_dispatch'
permissions: read-all
runs-on: ubuntu-latest
outputs:
approval-env: ${{ steps.collab-check.outputs.result || steps.auto-approve.outputs.result }}
steps:
- name: Collaborator Check
if: github.event_name != 'workflow_dispatch'
uses: actions/github-script@v8
id: collab-check
with:
result-encoding: string
script: |
try {
const permissionResponse = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.comment.user.login,
});
const permission = permissionResponse.data.permission;
const hasWriteAccess = ['write', 'admin'].includes(permission);
if (!hasWriteAccess) {
console.log(`User ${context.payload.comment.user.login} does not have write access to the repository (permission: ${permission})`);
return "manual-approval"
} else {
console.log(`Verified ${context.payload.comment.user.login} has write access. Auto Approving strands command.`)
return "auto-approve"
}
} catch (error) {
console.log(`${context.payload.comment.user.login} does not have write access. Requiring Manual Approval to run strands command.`)
return "manual-approval"
}
- name: Auto-approve for workflow dispatch
if: github.event_name == 'workflow_dispatch'
id: auto-approve
uses: actions/github-script@v8
with:
result-encoding: string
script: |
return "auto-approve"
setup-and-process:
needs: [authorization-check]
environment: ${{ needs.authorization-check.outputs.approval-env }}
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.process.outputs.branch_name }}
session_id: ${{ steps.process.outputs.session_id }}
system_prompt: ${{ steps.process.outputs.system_prompt }}
prompt: ${{ steps.process.outputs.prompt }}
steps:
- name: Add strands-running label
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ inputs.issue_id || github.event.issue.number }},
labels: ['strands-running']
});
- name: Checkout repository
uses: actions/checkout@v6
with:
sparse-checkout: |
.github
# Outputs: branch_name, session_id, system_prompt, prompt
- name: Process input
id: process
uses: actions/github-script@v8
with:
script: |
const processInput = require('./.github/scripts/javascript/process-input.cjs');
await processInput(context, github, core, {
issue_id: '${{ inputs.issue_id }}',
command: '${{ inputs.command }}',
session_id: '${{ inputs.session_id }}'
});
execute-readonly:
needs: [setup-and-process]
permissions:
contents: read
issues: read
pull-requests: read
id-token: write # Required for OIDC
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
sparse-checkout: |
.github
- name: Run Strands Agent
id: agent-runner
uses: ./.github/actions/strands-agent-runner
with:
system_prompt: ${{ needs.setup-and-process.outputs.system_prompt }}
session_id: ${{ needs.setup-and-process.outputs.session_id }}
task_prompt: ${{ needs.setup-and-process.outputs.prompt }}
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
sessions_bucket: ${{ secrets.AGENT_SESSIONS_BUCKET }}
write_permission: 'false'
ref: ${{ needs.setup-and-process.outputs.branch }}
execute-write:
needs: [setup-and-process, execute-readonly]
permissions:
contents: write
issues: write
pull-requests: write
id-token: write # Required for OIDC
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
sparse-checkout: |
.github
- name: Execute write operations
uses: ./.github/actions/strands-write-executor
with:
ref: ${{ needs.setup-and-process.outputs.branch }}
issue_id: ${{ inputs.issue_id || github.event.issue.number }}
cleanup:
needs: [authorization-check, setup-and-process, execute-readonly, execute-write]
if: always()
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Remove strands-running label
uses: actions/github-script@v8
with:
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ inputs.issue_id || github.event.issue.number }},
name: 'strands-running'
});
} catch (error) {
console.log('Label removal failed (may not exist):', error.message);
}