Repository navigation
511 lines (475 loc) · 21.4 KB
/
Copy pathupdate-mcp-coverage.yml
File metadata and controls
511 lines (475 loc) · 21.4 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
name: Update MCP Coverage
on:
workflow_run:
workflows: [Publish NPM]
types: [completed]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: update-mcp-coverage
cancel-in-progress: false
jobs:
sdk-version:
if: >-
github.repository == 'kernel/kernel-node-sdk' &&
(github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository))
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
sha: ${{ steps.version.outputs.sha }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
persist-credentials: false
- name: Resolve published SDK version
id: version
run: |
version=$(jq -er 'select(.name == "@onkernel/sdk") | .version' package.json)
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Skipping non-stable SDK version: $version"
exit 0
fi
# A just-published version can take a few minutes to become installable.
for attempt in $(seq 1 30); do
if [[ "$(npm view "@onkernel/sdk@$version" version 2>/dev/null)" == "$version" ]]; then
break
fi
if [[ "$attempt" == 30 ]]; then
echo "::error::@onkernel/sdk@$version is not available on npm after 15 minutes."
exit 1
fi
sleep 30
done
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# Every secret a job references stays readable in runner memory for the whole
# job, so the API read token is minted here and generate only gets model keys.
context:
needs: sdk-version
if: needs.sdk-version.outputs.version != ''
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
update: ${{ steps.prepare.outputs.update }}
main_sha: ${{ steps.prepare.outputs.main_sha }}
update_sha: ${{ steps.prepare.outputs.update_sha }}
rebased: ${{ steps.prepare.outputs.rebased }}
agent_base_tree: ${{ steps.prepare.outputs.agent_base_tree }}
context_artifact_id: ${{ steps.upload-context.outputs.artifact-id }}
env:
SDK_VERSION: ${{ needs.sdk-version.outputs.version }}
SDK_SHA: ${{ needs.sdk-version.outputs.sha }}
UPDATE_BRANCH: mcp-coverage-update
steps:
- name: Checkout updater instructions
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
sparse-checkout: .github
persist-credentials: false
- name: Checkout published SDK
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ env.SDK_SHA }}
path: sdk
fetch-depth: 0
persist-credentials: false
- name: Checkout MCP server
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
repository: kernel/kernel-mcp-server
path: mcp
fetch-depth: 0
persist-credentials: false
- name: Prepare update branch and SDK diff
id: prepare
working-directory: mcp
run: |
git config user.name 'kernel-internal[bot]'
git config user.email '260533166+kernel-internal[bot]@users.noreply.github.com'
echo "main_sha=$(git rev-parse origin/main)" >> "$GITHUB_OUTPUT"
if git show-ref --verify --quiet "refs/remotes/origin/$UPDATE_BRANCH"; then
echo "update_sha=$(git rev-parse "origin/$UPDATE_BRANCH")" >> "$GITHUB_OUTPUT"
git switch --track "origin/$UPDATE_BRANCH"
if ! git rebase origin/main; then
git rebase --abort
# The agent covers everything since main's SDK version, so a bot-only
# branch can be regenerated from main. Human commits must be kept.
if git log --no-merges --format=%ae "origin/main..origin/$UPDATE_BRANCH" \
| grep -qvxF '260533166+kernel-internal[bot]@users.noreply.github.com'; then
echo "::error::$UPDATE_BRANCH has human commits that conflict with main. Resolve the conflicts on that branch, then rerun this workflow."
exit 1
fi
echo "::warning::$UPDATE_BRANCH conflicts with main; regenerating it from main."
git switch -C "$UPDATE_BRANCH" origin/main
else
echo "rebased=true" >> "$GITHUB_OUTPUT"
fi
else
git switch -c "$UPDATE_BRANCH" origin/main
fi
# The agent's changes are published on top of this head, so human
# commits on the update branch keep their content and authorship.
echo "agent_base=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "agent_base_tree=$(git rev-parse 'HEAD^{tree}')" >> "$GITHUB_OUTPUT"
old_version=$(jq -er '.dependencies["@onkernel/sdk"]' package.json)
if [[ "$old_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] &&
[[ "$old_version" != "$SDK_VERSION" ]] &&
[[ "$(printf '%s\n' "$old_version" "$SDK_VERSION" | sort -V | tail -1)" == "$old_version" ]]; then
echo "MCP already uses newer SDK $old_version; skipping stale run."
exit 0
fi
# The report replaces the PR description, so audit every release since
# main's SDK version, not only the ones since the last run.
old_version=$(git show origin/main:package.json | jq -er '.dependencies["@onkernel/sdk"]')
if git -C ../sdk rev-parse --verify "refs/tags/v$old_version" >/dev/null 2>&1; then
git -C ../sdk diff "refs/tags/v$old_version" "$SDK_SHA" \
-- api.md src/client.ts src/lib src/resources > "$RUNNER_TEMP/sdk-diff.patch"
echo "old_date=$(TZ=UTC git -C ../sdk log -1 --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd "refs/tags/v$old_version")" >> "$GITHUB_OUTPUT"
else
printf 'Baseline %s unavailable; audit all of api.md, src/client.ts, src/lib, and src/resources.\n' "$old_version" > "$RUNNER_TEMP/sdk-diff.patch"
fi
echo "new_date=$(TZ=UTC git -C ../sdk log -1 --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd "$SDK_SHA")" >> "$GITHUB_OUTPUT"
echo "update=true" >> "$GITHUB_OUTPUT"
- name: Generate API read token
if: steps.prepare.outputs.update == 'true'
id: api-read-token
uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1
with:
app-id: ${{ secrets.ADMIN_APP_ID }}
private-key: ${{ secrets.ADMIN_APP_PRIVATE_KEY }}
owner: kernel
repositories: kernel
permission-contents: read
- name: Fetch API spec
if: steps.prepare.outputs.update == 'true'
env:
GH_TOKEN: ${{ steps.api-read-token.outputs.token }}
OLD_DATE: ${{ steps.prepare.outputs.old_date }}
NEW_DATE: ${{ steps.prepare.outputs.new_date }}
run: |
main_at() {
gh api -X GET repos/kernel/kernel/commits -f sha=main -f until="$1" -f per_page=1 --jq '.[0].sha // empty'
}
file_at() {
gh api -H 'Accept: application/vnd.github.raw' "repos/kernel/kernel/contents/$1?ref=$2"
}
spec="$RUNNER_TEMP/kernel-api/packages/api/openapi.yaml"
head=$(main_at "$NEW_DATE")
test -n "$head"
mkdir -p "$(dirname "$spec")"
file_at packages/api/openapi.yaml "$head" > "$spec"
base=""
if [[ -n "$OLD_DATE" ]]; then
base=$(main_at "$OLD_DATE")
fi
if [[ -n "$base" ]]; then
file_at packages/api/openapi.yaml "$base" > "$RUNNER_TEMP/openapi-base.yaml"
diff -u --label "openapi.yaml@$base" --label "openapi.yaml@$head" \
"$RUNNER_TEMP/openapi-base.yaml" "$spec" \
> "$RUNNER_TEMP/openapi-diff.patch" || [[ $? -eq 1 ]]
rm "$RUNNER_TEMP/openapi-base.yaml"
else
printf 'Spec baseline unavailable; compare all relevant descriptions in openapi.yaml.\n' > "$RUNNER_TEMP/openapi-diff.patch"
fi
gh api --method DELETE /installation/token
# The spec comes from a private repository and this repository's artifacts are
# public, so the context is only uploaded encrypted to the committed certificate.
- name: Encrypt update context
if: steps.prepare.outputs.update == 'true'
run: |
cert="$GITHUB_WORKSPACE/.github/updater-context.pem"
if [[ ! -s "$cert" ]]; then
echo "::error::Missing $cert, the certificate for the UPDATER_CONTEXT_KEY secret."
exit 1
fi
cd "$RUNNER_TEMP"
files=(sdk-diff.patch openapi-diff.patch kernel-api)
tar -czf context.tar.gz "${files[@]}"
openssl cms -encrypt -binary -aes-256-gcm -outform DER \
-in context.tar.gz -out context.tar.gz.cms "$cert"
rm context.tar.gz
- name: Upload update context
id: upload-context
if: steps.prepare.outputs.update == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: mcp-coverage-context
path: ${{ runner.temp }}/context.tar.gz.cms
if-no-files-found: error
retention-days: 1
# "Re-run all jobs" uploads again in the same run, where a failed generate left the context.
overwrite: true
generate:
needs: [sdk-version, context]
if: needs.context.outputs.update == 'true'
runs-on: ubuntu-latest
timeout-minutes: 55
outputs:
changed: ${{ steps.snapshot.outputs.changed }}
main_sha: ${{ needs.context.outputs.main_sha }}
update_sha: ${{ needs.context.outputs.update_sha }}
rebased: ${{ needs.context.outputs.rebased }}
agent_base_tree: ${{ needs.context.outputs.agent_base_tree }}
env:
SDK_VERSION: ${{ needs.sdk-version.outputs.version }}
SDK_SHA: ${{ needs.sdk-version.outputs.sha }}
UPDATE_BRANCH: mcp-coverage-update
MAIN_SHA: ${{ needs.context.outputs.main_sha }}
UPDATE_SHA: ${{ needs.context.outputs.update_sha }}
REBASED: ${{ needs.context.outputs.rebased }}
AGENT_BASE_TREE: ${{ needs.context.outputs.agent_base_tree }}
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 20
steps:
- name: Checkout updater instructions
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- name: Checkout published SDK
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ env.SDK_SHA }}
path: sdk
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '22'
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: '1.3.3'
- name: Checkout MCP server
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
repository: kernel/kernel-mcp-server
path: mcp
fetch-depth: 0
persist-credentials: false
- name: Download update context
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: mcp-coverage-context
path: ${{ runner.temp }}
# The key is stored base64-encoded on one line so log masking covers all of it.
- name: Decrypt update context
env:
CONTEXT_KEY: ${{ secrets.UPDATER_CONTEXT_KEY }}
run: |
set -o pipefail
cd "$RUNNER_TEMP"
openssl cms -decrypt -binary -inform DER -in context.tar.gz.cms \
-inkey <(base64 -d <<< "$CONTEXT_KEY") | tar -xzf -
rm context.tar.gz.cms
- name: Rebuild update branch
id: prepare
working-directory: mcp
run: |
git config user.name 'kernel-internal[bot]'
git config user.email '260533166+kernel-internal[bot]@users.noreply.github.com'
if [[ "$REBASED" == true ]]; then
git switch -c "$UPDATE_BRANCH" "$UPDATE_SHA"
git rebase -q "$MAIN_SHA"
else
git switch -c "$UPDATE_BRANCH" "$MAIN_SHA"
fi
if [[ "$(git rev-parse 'HEAD^{tree}')" != "$AGENT_BASE_TREE" ]]; then
echo "::error::The rebuilt update branch differs from the one the context job prepared."
exit 1
fi
echo "agent_base=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Install Pi
env:
PI_TELEMETRY: '0'
run: |
npm install -g --ignore-scripts @earendil-works/pi-coding-agent
pi --version
- name: Update SDK dependency and MCP coverage
working-directory: mcp
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PI_PREFERRED_MODEL: ${{ vars.PI_PREFERRED_MODEL }}
PI_SKIP_VERSION_CHECK: '1'
PI_TELEMETRY: '0'
run: |
: "${PI_PREFERRED_MODEL:?Set the PI_PREFERRED_MODEL organization variable}"
bun add --exact "@onkernel/sdk@$SDK_VERSION"
pi --print --no-session --approve \
--model "$PI_PREFERRED_MODEL" --thinking max \
@../.github/prompts/update-mcp-coverage.md
- name: Snapshot publishable changes
id: snapshot
working-directory: mcp
env:
AGENT_BASE: ${{ steps.prepare.outputs.agent_base }}
run: |
git reset -q --soft "$AGENT_BASE"
git add -A
git diff --cached --name-only --no-renames -z \
| bash ../.github/scripts/mcp-update-disallowed-paths.sh > "$RUNNER_TEMP/excluded-paths"
if [[ -s "$RUNNER_TEMP/excluded-paths" ]]; then
echo "::warning::Discarding changes outside the MCP updater allowlist:"
tr '\0' '\n' < "$RUNNER_TEMP/excluded-paths"
GIT_LITERAL_PATHSPECS=1 git reset -q --pathspec-from-file="$RUNNER_TEMP/excluded-paths" --pathspec-file-nul
fi
git diff --cached --binary --no-renames --no-ext-diff --no-textconv > "$RUNNER_TEMP/changes.patch"
git reset -q --hard
git clean -fdq
if [[ -s "$RUNNER_TEMP/changes.patch" ]]; then
git apply --index "$RUNNER_TEMP/changes.patch"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Verify MCP changes
working-directory: mcp
run: |
test -s "$RUNNER_TEMP/mcp-coverage-report.md"
jq -e --arg version "$SDK_VERSION" '.dependencies["@onkernel/sdk"] == $version and
([.overrides, .resolutions, .patchedDependencies] | map((. // {}) | has("@onkernel/sdk")) | any | not)' package.json
grep -qF "\"@onkernel/sdk\": [\"@onkernel/sdk@$SDK_VERSION\", \"\"," bun.lock
bun install --frozen-lockfile
bun run check:managed-auth-app
bunx tsc --noEmit --incremental false
bun test
bun scripts/record-oauth-redis-contract.ts
git diff --exit-code -- fixtures/oauth-redis-recordings.json
git diff --cached --check
- name: Upload validated changes
if: steps.snapshot.outputs.changed == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: mcp-coverage-update
path: |
${{ runner.temp }}/changes.patch
${{ runner.temp }}/mcp-coverage-report.md
if-no-files-found: error
retention-days: 7
publish:
needs: [sdk-version, generate]
if: needs.generate.outputs.changed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
env:
SDK_VERSION: ${{ needs.sdk-version.outputs.version }}
MAIN_SHA: ${{ needs.generate.outputs.main_sha }}
UPDATE_SHA: ${{ needs.generate.outputs.update_sha }}
REBASED: ${{ needs.generate.outputs.rebased }}
AGENT_BASE_TREE: ${{ needs.generate.outputs.agent_base_tree }}
UPDATE_BRANCH: mcp-coverage-update
steps:
- name: Checkout updater scripts
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- name: Download validated changes
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: mcp-coverage-update
path: ${{ runner.temp }}/mcp-coverage-update
- name: Checkout MCP server
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
repository: kernel/kernel-mcp-server
path: mcp
fetch-depth: 0
persist-credentials: false
- name: Apply validated changes
working-directory: mcp
run: |
git config user.name 'kernel-internal[bot]'
git config user.email '260533166+kernel-internal[bot]@users.noreply.github.com'
if [[ "$REBASED" == true ]]; then
git switch -c "$UPDATE_BRANCH" "$UPDATE_SHA"
git rebase -q "$MAIN_SHA"
else
git switch -c "$UPDATE_BRANCH" "$MAIN_SHA"
fi
if [[ "$(git rev-parse 'HEAD^{tree}')" != "$AGENT_BASE_TREE" ]]; then
echo "::error::The rebuilt update branch differs from the one the changes were validated on."
exit 1
fi
git apply --index "$RUNNER_TEMP/mcp-coverage-update/changes.patch"
git diff --cached --name-only --no-renames -z \
| bash ../.github/scripts/mcp-update-disallowed-paths.sh > "$RUNNER_TEMP/disallowed-paths"
if [[ -s "$RUNNER_TEMP/disallowed-paths" ]]; then
echo "::error::Validated changes include paths outside the MCP updater allowlist:"
tr '\0' '\n' < "$RUNNER_TEMP/disallowed-paths"
exit 1
fi
if git diff --cached --raw --no-renames | awk '$2 !~ /^(100644|100755|000000)$/ { found = 1 } END { exit !found }'; then
echo "::error::Validated changes may only contain regular files."
exit 1
fi
git commit -q -m "Update Node SDK to $SDK_VERSION and MCP coverage"
- name: Generate MCP repository token
id: app-token
uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1
with:
app-id: ${{ secrets.ADMIN_APP_ID }}
private-key: ${{ secrets.ADMIN_APP_PRIVATE_KEY }}
owner: kernel
repositories: kernel-mcp-server
permission-contents: write
permission-pull-requests: write
- name: Open or update MCP coverage PR
working-directory: mcp
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
if git diff --quiet origin/main HEAD; then
echo "MCP coverage is already up to date."
exit 0
fi
gh auth setup-git
git push --force-with-lease="$UPDATE_BRANCH:$UPDATE_SHA" origin "$UPDATE_BRANCH"
body="$RUNNER_TEMP/mcp-coverage-pr.md"
{
printf '## Summary\n\n- Update `@onkernel/sdk` to `%s`.\n' "$SDK_VERSION"
printf '\n## Coverage\n\n'
head -c 60000 "$RUNNER_TEMP/mcp-coverage-update/mcp-coverage-report.md"
printf '\n## Validation\n\n- Frozen Bun install\n- Managed-auth App bundle check\n- TypeScript type check\n- Bun tests\n- OAuth Redis recording check\n'
} > "$body"
pr=$(gh pr list --repo kernel/kernel-mcp-server --head "$UPDATE_BRANCH" --base main \
--state open --json number --jq '.[0].number // empty')
title="MCP: Update Node SDK to $SDK_VERSION"
if [[ -n "$pr" ]]; then
gh pr edit "$pr" --repo kernel/kernel-mcp-server --title "$title" --body-file "$body"
else
gh pr create --repo kernel/kernel-mcp-server --head "$UPDATE_BRANCH" --base main \
--title "$title" --body-file "$body"
fi
# Deletes the context once generate has used it, whether or not publish runs.
# After a failed or cancelled generate the context is kept until it expires, so
# re-running failed jobs can still download it.
cleanup:
needs: [context, generate, publish]
if: always() && needs.generate.result == 'success' && needs.context.outputs.context_artifact_id != ''
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
actions: write
steps:
- name: Delete update context
env:
GH_TOKEN: ${{ github.token }}
ARTIFACT_ID: ${{ needs.context.outputs.context_artifact_id }}
run: |
# A re-run after a failed publish finds the context already deleted.
if ! error=$(gh api --method DELETE "repos/$GITHUB_REPOSITORY/actions/artifacts/$ARTIFACT_ID" 2>&1); then
if [[ "$error" != *"(HTTP 404)"* ]]; then
echo "$error" >&2
exit 1
fi
echo "The update context was already deleted."
fi