-
Notifications
You must be signed in to change notification settings - Fork 1
317 lines (285 loc) · 11.3 KB
/
Copy pathkilo-dispatch.yml
File metadata and controls
317 lines (285 loc) · 11.3 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: Kilo Dispatch
on:
workflow_dispatch:
inputs:
prompt:
description: Fallback prompt when command is not provided
required: false
default: ""
type: string
command:
description: Kilo command to run (without leading slash), e.g. local-review
required: false
default: ""
type: string
command_args:
description: Optional arguments passed to command mode
required: false
default: ""
type: string
timeout_minutes:
description: Timeout in minutes for job and Kilo run
required: false
default: "120"
type: string
model:
description: Gateway model ID for kilocode provider
required: false
default: "openai/gpt-5.3-codex"
type: string
pr_number:
description: Pull request number to post result to
required: false
default: ""
type: string
review_comment_id:
description: Optional PR review comment ID to reply to
required: false
default: ""
type: string
parent_comment_id:
description: Optional parent comment ID (preferred over review_comment_id)
required: false
default: ""
type: string
permissions:
contents: read
issues: write
pull-requests: write
jobs:
run-kilo:
name: run-kilo
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(inputs.timeout_minutes) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch remote branches for baseline resolution
run: git fetch --no-tags origin +refs/heads/*:refs/remotes/origin/*
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install Kilo CLI
run: npm install -g @kilocode/cli
- name: Install performance dependencies
if: ${{ inputs.command == 'perf-review' }}
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential cmake ninja-build pkg-config \
python3 python3-pip \
python3-numpy python3-scipy \
libpfm4 libpfm4-dev
cmake --version
python3 --version
python3 -c "import numpy, scipy; print(f'numpy {numpy.__version__}'); print(f'scipy {scipy.__version__}')"
dpkg-query -W -f='${Package} ${Version}\n' libpfm4 libpfm4-dev
test -f /usr/include/perfmon/pfmlib.h
- name: Verify KILO_API_TOKEN secret
run: |
if [ -z "${{ secrets.KILO_API_TOKEN }}" ]; then
echo "KILO_API_TOKEN secret is missing. Add it in repository settings before running this workflow."
exit 1
fi
if [ -z "${{ secrets.NIKOLAY_REVIEWER_APP_ID }}" ]; then
echo "NIKOLAY_REVIEWER_APP_ID secret is missing. Add it in repository settings before running this workflow."
exit 1
fi
if [ -z "${{ secrets.NIKOLAY_REVIEWER_PRIVATE_KEY }}" ]; then
echo "NIKOLAY_REVIEWER_PRIVATE_KEY secret is missing. Add it in repository settings before running this workflow."
exit 1
fi
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.NIKOLAY_REVIEWER_APP_ID }}
private-key: ${{ secrets.NIKOLAY_REVIEWER_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
- name: Post start status as GitHub App comment
if: ${{ always() && inputs.pr_number != '' && steps.app-token.outputs.token != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const prNumber = Number(${{ toJSON(inputs.pr_number) }});
const command = ${{ toJSON(inputs.command) }};
const commandArgs = ${{ toJSON(inputs.command_args) }};
const prompt = ${{ toJSON(inputs.prompt) }};
const parentCommentIdRaw = ((${{ toJSON(inputs.parent_comment_id) }} || ${{ toJSON(inputs.review_comment_id) }} || '') + '').trim();
const parentCommentId = parentCommentIdRaw ? Number(parentCommentIdRaw) : null;
const runUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
let requestSummary = '';
if ((command || '').trim()) {
requestSummary = `/${command}${(commandArgs || '').trim() ? ` ${commandArgs}` : ''}`;
} else {
requestSummary = (prompt || '').trim();
}
requestSummary = requestSummary.replace(/\s+/g, ' ').trim();
if (!requestSummary) {
requestSummary = '(no request text provided)';
}
if (requestSummary.length > 180) {
requestSummary = `${requestSummary.slice(0, 177)}...`;
}
const body = `Started Kilo run: ${requestSummary}\nRun: ${runUrl}`;
if (parentCommentId) {
try {
await github.rest.pulls.createReplyForReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
comment_id: parentCommentId,
body
});
return;
} catch (error) {
const status = error?.status;
if (status !== 404 && status !== 422) {
throw error;
}
let prefix = '';
try {
const parent = await github.rest.issues.getComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: parentCommentId
});
const login = parent?.data?.user?.login;
if (login) {
prefix = `@${login} `;
}
} catch {
// Fallback to plain issue comment if parent lookup fails.
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `${prefix}${body}`
});
return;
}
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body
});
- name: Run Kilo CLI
env:
KILO_API_TOKEN: ${{ secrets.KILO_API_TOKEN }}
KILO_API_KEY: ${{ secrets.KILO_API_TOKEN }}
KILO_PROVIDER: kilocode
KILOCODE_MODEL: ${{ inputs.model }}
run: |
set -euo pipefail
: > kilo-run.log
: > kilo-events.log
: > kilo-output.log
kilo --version 2>&1 | tee -a kilo-run.log
has_timeout=false
if kilo run --help 2>&1 | grep -q -- '--timeout'; then
has_timeout=true
fi
kilo_args=(kilo run --auto --format json)
if [ -n "${{ inputs.command }}" ]; then
kilo_args+=(--command "${{ inputs.command }}")
if [ -n "${{ inputs.command_args }}" ]; then
kilo_args+=("${{ inputs.command_args }}")
fi
elif [ -n "${{ inputs.prompt }}" ]; then
kilo_args+=("${{ inputs.prompt }}")
else
echo "Either 'command' or 'prompt' must be provided." | tee -a kilo-run.log
exit 1
fi
if [ "$has_timeout" = true ]; then
"${kilo_args[@]}" --timeout "${{ inputs.timeout_minutes }}m" 2>&1 | tee -a kilo-events.log | tee -a kilo-run.log
else
echo "kilo run does not support --timeout; relying on job timeout-minutes." >> kilo-run.log
"${kilo_args[@]}" 2>&1 | tee -a kilo-events.log | tee -a kilo-run.log
fi
node --experimental-strip-types scripts/kilo-postprocess.ts kilo-events.log kilo-output.log kilo-readable.log
- name: Create GitHub App token for final comment
if: ${{ always() && inputs.pr_number != '' }}
id: app-token-final
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.NIKOLAY_REVIEWER_APP_ID }}
private-key: ${{ secrets.NIKOLAY_REVIEWER_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
- name: Post result as GitHub App comment
if: ${{ always() && inputs.pr_number != '' && steps.app-token-final.outputs.token != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token-final.outputs.token }}
script: |
const fs = require('fs');
const prNumber = Number('${{ inputs.pr_number }}');
const parentCommentIdRaw = ('${{ inputs.parent_comment_id }}' || '${{ inputs.review_comment_id }}').trim();
const parentCommentId = parentCommentIdRaw ? Number(parentCommentIdRaw) : null;
let outputContent = '';
try {
outputContent = fs.readFileSync('kilo-output.log', 'utf8');
} catch {
outputContent = 'kilo-output.log not found.';
}
const body = outputContent.trim() || '(empty Kilo output)';
if (parentCommentId) {
try {
await github.rest.pulls.createReplyForReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
comment_id: parentCommentId,
body
});
return;
} catch (error) {
const status = error?.status;
if (status !== 404 && status !== 422) {
throw error;
}
let prefix = '';
try {
const parent = await github.rest.issues.getComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: parentCommentId
});
const login = parent?.data?.user?.login;
if (login) {
prefix = `@${login} `;
}
} catch {
// Fallback to plain issue comment if parent lookup fails.
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `${prefix}${body}`
});
return;
}
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body
});
- name: Upload Kilo run log
if: always()
uses: actions/upload-artifact@v4
with:
name: kilo-run-log
path: |
kilo-run.log
kilo-readable.log