The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | name: Agent Context Budget |
| 2 | |
| 3 | # Fails when a PR raises a value in agentContextBudget.json above main's. AgentContextBudget.test.ts |
| 4 | # keeps that file equal to the measured context, so the context cannot grow by editing the file. |
| 5 | # To accept growth on purpose, a maintainer adds the agent-context-increase label. |
| 6 | on: |
| 7 | pull_request: |
| 8 | types: [opened, synchronize, reopened, labeled, unlabeled] |
| 9 | |
| 10 | permissions: |
| 11 | contents: read |
| 12 | |
| 13 | # No concurrency group: label events arrive in bursts, and a cancelled run reports as a failed check. |
| 14 | jobs: |
| 15 | budget: |
| 16 | name: Agent context budget |
| 17 | runs-on: ubuntu-24.04 |
| 18 | timeout-minutes: 5 |
| 19 | env: |
| 20 | BUDGET: apps/server/src/provider/agentContextBudget.json |
| 21 | ALLOW_INCREASE: ${{ contains(github.event.pull_request.labels.*.name, 'agent-context-increase') }} |
| 22 | steps: |
| 23 | - name: Checkout |
| 24 | uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 |
| 25 | with: |
| 26 | sparse-checkout: apps/server/src/provider/agentContextBudget.json |
| 27 | sparse-checkout-cone-mode: false |
| 28 | fetch-depth: 2 |
| 29 | |
| 30 | # The checkout is the PR merged onto main; compare with that merge's main parent. A fresh |
| 31 | # fetch of main can be newer and lower, which reports the PR as growing what main just cut. |
| 32 | - name: Compare with main |
| 33 | run: | |
| 34 | if ! git cat-file -e "HEAD^1:$BUDGET" 2>/dev/null; then |
| 35 | echo "main has no agent context budget yet." |
| 36 | exit 0 |
| 37 | fi |
| 38 | git show "HEAD^1:$BUDGET" > "$RUNNER_TEMP/main.json" |
| 39 | grown=$(jq -r --slurpfile main "$RUNNER_TEMP/main.json" ' |
| 40 | to_entries[] |
| 41 | | select($main[0][.key] != null and .value > $main[0][.key]) |
| 42 | | "\(.key): \($main[0][.key]) -> \(.value) (+\(.value - $main[0][.key]))" |
| 43 | ' "$BUDGET") |
| 44 | if [ -z "$grown" ]; then |
| 45 | echo "Agent context is not larger than main." |
| 46 | exit 0 |
| 47 | fi |
| 48 | printf 'Agent context grew compared to main:\n%s\n' "$grown" |
| 49 | if [ "$ALLOW_INCREASE" = "true" ]; then |
| 50 | echo "Accepted by the agent-context-increase label." |
| 51 | exit 0 |
| 52 | fi |
| 53 | echo "::error file=$BUDGET::Agent context grew compared to main. Cut the added text and rerun the evals that cover it (evals/README.md), or ask a maintainer to add the agent-context-increase label." |
| 54 | exit 1 |