Repository navigation
Code Monkey ⏰: revise rust-workflows#80 python-workflows#208 generic-workflows#170 (Fusion high) #2120
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # SPDX-FileCopyrightText: 2026 The Linux Foundation | |
| # On-demand entry point for the reusable workflow. | |
| # | |
| # Nothing runs unattended: there is no schedule, and a run works only | |
| # what an operator names in a dispatch. A dispatch names issues to | |
| # work or open bot pull requests to revise, or sets revise_only to | |
| # revise the bot's open pull requests with work outstanding and work | |
| # no new issue. No run scans the organisation for new issues: the | |
| # reusable workflow's input check refuses a dispatch that names | |
| # nothing. A dispatch is live unless its form asks for a dry run. The | |
| # continue job re-dispatches this workflow for the next round of each | |
| # pull request a round left with work (docs/DESIGN.md section 20.6). | |
| # Disabling this workflow in the Actions UI is the kill switch. | |
| name: 'Code Monkey ⏰' | |
| # Name each run by what it works, keeping the workflow name as prefix: | |
| # its pull requests, else its issues, else a revise-only scan. A | |
| # dispatch naming none of them fails the input check. The lists are | |
| # the operator's raw input; GitHub truncates a long name. A Copilot | |
| # Fusion run says so and names its tier. | |
| run-name: >- | |
| ${{ format('Code Monkey ⏰: {0}{1}{2}', | |
| inputs.pull_requests != '' | |
| && format('revise {0}', inputs.pull_requests) | |
| || inputs.issues != '' && format('work {0}', inputs.issues) | |
| || inputs.revise_only && 'revise-only scan' | |
| || 'nothing named', | |
| inputs.fusion_auto_model_select | |
| && format(' (Fusion {0})', inputs.fusion_tier) || '', | |
| inputs.dry_run && ' (dry run)' || '') }} | |
| # yamllint disable-line rule:truthy | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: 'Run the agent but publish nothing' | |
| type: boolean | |
| default: false | |
| model: | |
| description: 'Model' | |
| type: choice | |
| options: | |
| - 'Claude Opus 5.5' | |
| - 'Claude Fable 5.2' | |
| - 'Claude Sonnet 5.5' | |
| - 'GPT-6 Astra' | |
| default: 'Claude Opus 5.5' | |
| fusion_auto_model_select: | |
| description: >- | |
| Let Copilot Fusion pick the model per task; overrides Model | |
| type: boolean | |
| default: false | |
| fusion_tier: | |
| description: 'Copilot Fusion tier; used only when Fusion is on' | |
| type: choice | |
| options: | |
| - 'standard' | |
| - 'high' | |
| - 'max' | |
| default: 'standard' | |
| mode: | |
| description: 'How far to take each issue' | |
| type: choice | |
| options: | |
| - 'select' | |
| - 'branches' | |
| - 'pull-requests' | |
| default: 'pull-requests' | |
| max_pull_requests: | |
| description: 'Pull requests to raise at most (0 = no cap)' | |
| type: string | |
| default: '10' | |
| max_runtime_minutes: | |
| description: 'Minutes each agent may run' | |
| type: string | |
| default: '180' | |
| max_rounds: | |
| description: 'Revision rounds a pull request may receive (1-50)' | |
| type: string | |
| default: '10' | |
| stale_status_minutes: | |
| description: 'Minutes before pending pre-commit.ci is stale (0: off)' | |
| type: string | |
| default: '8' | |
| max_concurrent_agents: | |
| description: 'Agents at once (1-30)' | |
| type: string | |
| default: '10' | |
| allow_subagents: | |
| description: 'Allow the agent to spawn sub-agents' | |
| type: boolean | |
| default: true | |
| include_dotgithub: | |
| description: 'Include issues from the .github repository' | |
| type: boolean | |
| default: false | |
| load_repo_skills: | |
| description: 'Trust skills found in the target checkout' | |
| type: boolean | |
| default: false | |
| allow_workflow_edits: | |
| description: 'Let new pull requests change .github/workflows/ files' | |
| type: boolean | |
| default: false | |
| allow_precommit_config_edits: | |
| description: 'Let new pull requests change .pre-commit-config.yaml' | |
| type: boolean | |
| default: false | |
| request_review: | |
| description: 'Request and await a Copilot review of each pull request' | |
| type: boolean | |
| default: true | |
| request_antagonistic_review: | |
| description: >- | |
| Ask the review bot for an antagonistic review once Copilot's | |
| review is clean | |
| type: boolean | |
| default: true | |
| issues: | |
| description: >- | |
| Issues to work: repo#N, owner/repo#N, repo/issues/N or URLs | |
| (commas and/or spaces) | |
| type: string | |
| default: '' | |
| pull_requests: | |
| description: >- | |
| Open bot pull requests to revise: repo#N, owner/repo#N, | |
| repo/pull/N or URLs (commas and/or spaces) | |
| type: string | |
| default: '' | |
| revise: | |
| description: 'Revise open bot pull requests with work outstanding' | |
| type: boolean | |
| default: true | |
| revise_only: | |
| description: >- | |
| Revise open bot pull requests alone, working no new issue; | |
| leave issues empty | |
| type: boolean | |
| default: false | |
| outstanding_only: | |
| description: >- | |
| Revise each named pull request only if it has work | |
| outstanding; needs pull_requests alone | |
| type: boolean | |
| default: false | |
| continues_run: | |
| description: >- | |
| Set by the continue job: the run that dispatched this one, | |
| which must have published a round on each pull request | |
| type: string | |
| default: '' | |
| # The 24th input: GitHub caps a workflow_dispatch form at 25. | |
| inherit_run_parameters: | |
| description: >- | |
| Set by a hand-back: take the model, budgets and switches from | |
| the named pull request's last round; one pull request only | |
| type: boolean | |
| default: false | |
| permissions: {} | |
| # Serialise the revise-only dispatches of this caller. Pending runs | |
| # wait in a FIFO queue (`queue: max`, up to 100) instead of the default | |
| # single slot a newcomer would take, so no run is cancelled unseen; | |
| # `queue` needs `cancel-in-progress: false`. A dry dispatch writes | |
| # nothing and takes a group of its own: it never waits behind a live | |
| # run. A live dispatch that names `issues` or `pull_requests` locks on | |
| # its own run, a fixed-length key: a group name built from the target | |
| # lists would grow with them past GitHub's 400-character limit. Two | |
| # dispatches naming the same or overlapping targets run apart; the | |
| # reusable workflow's publish locks serialise their writes to any one | |
| # pull request or issue, and the per-issue pull request check, the | |
| # branch-exists refusal and the revision's compare-and-swap stop a | |
| # duplicate. A revise-only run scans the bot's own pull requests and | |
| # shares `code-monkey`: two never run side by side, and one with | |
| # nothing to do ends after selection. | |
| concurrency: | |
| group: >- | |
| ${{ inputs.dry_run | |
| && format('code-monkey-dry-run-{0}', github.run_id) | |
| || (inputs.issues != '' || inputs.pull_requests != '') | |
| && format('code-monkey-named-{0}', github.run_id) | |
| || 'code-monkey' }} | |
| cancel-in-progress: false | |
| queue: max | |
| jobs: | |
| options: | |
| name: 'Resolve options' | |
| runs-on: 'ubuntu-latest' | |
| timeout-minutes: 2 | |
| permissions: {} | |
| outputs: | |
| model: "${{ steps.map.outputs.id }}" | |
| fusion_tier: "${{ steps.map.outputs.fusion_tier }}" | |
| steps: | |
| # Block mode needs the allow-list in this job too: the | |
| # environment variable does not cross job boundaries. | |
| - name: 'Load egress allow-list' | |
| # yamllint disable-line rule:line-length | |
| uses: lfreleng-actions/harden-runner-block-action@65ff87957e1cac2de3203a85dbb07c31810321cb # v0.16.4 | |
| with: | |
| # yamllint disable-line rule:line-length | |
| config: '@6e6cab073a93c0d58e4e8846d44e1cbddbac975b' # v0.21.0 | |
| allow_list_summary: 'false' | |
| - name: 'Harden runner' | |
| # yamllint disable-line rule:line-length | |
| uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 | |
| with: | |
| egress-policy: 'block' | |
| allowed-endpoints: "${{ env.CONNECTION_ALLOW_LIST }}" | |
| # Display names in the dispatch form map to the identifiers | |
| # docs/DESIGN.md section 10.3 checked against the CLI. The | |
| # Fusion switch replaces the model with the router and passes | |
| # its tier; off, the tier output is empty, the reusable | |
| # workflow's default. | |
| - name: 'Map display name to identifier' | |
| id: map | |
| env: | |
| MODEL: "${{ inputs.model }}" | |
| FUSION: "${{ inputs.fusion_auto_model_select }}" | |
| FUSION_TIER: "${{ inputs.fusion_tier }}" | |
| run: | | |
| case "$MODEL" in | |
| 'Claude Opus 5.5') id='claude-opus-5.5' ;; | |
| 'Claude Fable 5.2') id='claude-fable-5.2' ;; | |
| 'Claude Sonnet 5.5') id='claude-sonnet-5.5' ;; | |
| 'GPT-6 Astra') id='gpt-6-astra' ;; | |
| *) echo "::error::Unknown model $MODEL"; exit 1 ;; | |
| esac | |
| tier='' | |
| if [ "$FUSION" = true ]; then | |
| case "$FUSION_TIER" in | |
| standard|high|max) ;; | |
| *) echo "::error::Unknown Fusion tier $FUSION_TIER"; exit 1 ;; | |
| esac | |
| id='fusion' | |
| tier="$FUSION_TIER" | |
| fi | |
| echo "id=$id" >> "$GITHUB_OUTPUT" | |
| echo "fusion_tier=$tier" >> "$GITHUB_OUTPUT" | |
| code-monkey: | |
| name: 'Code Monkey' | |
| needs: 'options' | |
| permissions: | |
| issues: read # Named issue reads when running without the App | |
| contents: read # Asset checkout and public repository reads | |
| actions: read # Publish and report jobs locate artifacts | |
| checks: read # Select reads other runs' evidence vouches | |
| uses: $/.github/workflows/code-monkey.yaml | |
| with: | |
| org: "${{ github.repository_owner }}" | |
| mode: "${{ inputs.mode }}" | |
| dry_run: ${{ inputs.dry_run }} | |
| model: "${{ needs.options.outputs.model }}" | |
| # Empty unless the Fusion switch is on: the input's default. | |
| fusion_tier: "${{ needs.options.outputs.fusion_tier }}" | |
| # A form field left blank takes its default. | |
| max_pull_requests: "${{ inputs.max_pull_requests || '10' }}" | |
| max_runtime_minutes: "${{ inputs.max_runtime_minutes || '180' }}" | |
| max_rounds: "${{ inputs.max_rounds || '10' }}" | |
| stale_status_minutes: "${{ inputs.stale_status_minutes || '8' }}" | |
| max_concurrent_agents: "${{ inputs.max_concurrent_agents || '10' }}" | |
| allow_subagents: ${{ inputs.allow_subagents }} | |
| include_dotgithub: ${{ inputs.include_dotgithub }} | |
| load_repo_skills: ${{ inputs.load_repo_skills }} | |
| allow_workflow_edits: ${{ inputs.allow_workflow_edits }} | |
| allow_precommit_config_edits: ${{ inputs.allow_precommit_config_edits }} | |
| request_review: ${{ inputs.request_review }} | |
| request_antagonistic_review: ${{ inputs.request_antagonistic_review }} | |
| issues: "${{ inputs.issues }}" | |
| pull_requests: "${{ inputs.pull_requests }}" | |
| revise: ${{ inputs.revise }} | |
| revise_only: ${{ inputs.revise_only }} | |
| outstanding_only: ${{ inputs.outstanding_only }} | |
| continues_run: "${{ inputs.continues_run }}" | |
| inherit_run_parameters: ${{ inputs.inherit_run_parameters }} | |
| # The repository variable alone sets the list: no dispatch form | |
| # field can widen it. Unset, the run fails at pre-flight. | |
| issue_authors: "${{ vars.CODE_MONKEY_ISSUE_AUTHORS || '' }}" | |
| # Likewise the variable alone can turn the rule off. | |
| only_known_authors: "${{ vars.ONLY_KNOWN_AUTHORS || '' }}" | |
| # The fork pool token's lifetime limit and recorded expiry come | |
| # from the repository variables alone, like the author list: no | |
| # dispatch form field can widen the limit. | |
| fork_pool_token_max_days: "${{ vars.FORK_POOL_TOKEN_MAX_DAYS || '' }}" | |
| fork_pool_token_expires: "${{ vars.FORK_POOL_TOKEN_EXPIRES || '' }}" | |
| # Trusted jobs hold App tokens and run in block mode with the | |
| # organisation allow-list; the author job is always audit. | |
| harden_runner_egress: 'block' | |
| # yamllint disable-line rule:line-length | |
| harden_runner_allowlist: '@6e6cab073a93c0d58e4e8846d44e1cbddbac975b' # v0.21.0 | |
| github_app_client_id: "${{ vars.BOT_APP_CLIENT_ID || '' }}" | |
| assets_repository: "${{ github.repository }}" | |
| assets_ref: "${{ github.sha }}" | |
| secrets: | |
| copilot_token: "${{ secrets.COPILOT_CLI_TOKEN }}" | |
| github_app_private_key: "${{ secrets.BOT_APP_PRIVATE_KEY }}" | |
| copilot_review_token: "${{ secrets.COPILOT_REVIEW_TOKEN }}" | |
| antagonistic_dispatch_token: "${{ secrets.CODE_REVIEW_DISPATCH_TOKEN }}" | |
| fork_pool_token: "${{ secrets.FORK_POOL_TOKEN }}" | |
| # Dispatch the next round of each pull request whose round left work | |
| # outstanding (docs/DESIGN.md section 20.6). The job holds one | |
| # credential, its own token with Actions write on this repository, | |
| # in one step; it reads no artifact and checks out nothing. A | |
| # dispatch with the workflow token starts a run: GitHub's rule | |
| # against recursive runs exempts workflow_dispatch. Each dispatch | |
| # is a named run that re-reads everything with outstanding_only and | |
| # applies the revision scan's repository policy, author rule and | |
| # work test, so a forged or stale entry costs one select job, or | |
| # brings forward a round a revise-only run would start. Each names | |
| # this run as continues_run, and its select job skips a pull request | |
| # on which this run published no counted round. Only a pull-requests | |
| # run continues: no other mode moves a live pull request's head, so | |
| # a forged output of a branches run must start no round. Setting the | |
| # repository variable CODE_MONKEY_CONTINUE to 'false' stops the loop. | |
| continue: | |
| name: 'Continue rounds' | |
| needs: [code-monkey] | |
| # Gated on the output, not the call's result: another entry's | |
| # failed publish must not stop this one's round. | |
| if: >- | |
| ${{ !cancelled() | |
| && needs.code-monkey.outputs.continue_pull_requests != '' | |
| && needs.code-monkey.outputs.continue_pull_requests != '[]' | |
| && !inputs.dry_run | |
| && inputs.mode == 'pull-requests' | |
| && vars.CODE_MONKEY_CONTINUE != 'false' }} | |
| runs-on: 'ubuntu-latest' | |
| timeout-minutes: 10 | |
| permissions: | |
| actions: write # Dispatch this workflow for the next round | |
| steps: | |
| - name: 'Load egress allow-list' | |
| # yamllint disable-line rule:line-length | |
| uses: lfreleng-actions/harden-runner-block-action@65ff87957e1cac2de3203a85dbb07c31810321cb # v0.16.4 | |
| with: | |
| # yamllint disable-line rule:line-length | |
| config: '@6e6cab073a93c0d58e4e8846d44e1cbddbac975b' # v0.21.0 | |
| allow_list_summary: 'false' | |
| - name: 'Harden runner' | |
| # yamllint disable-line rule:line-length | |
| uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 | |
| with: | |
| egress-policy: 'block' | |
| allowed-endpoints: "${{ env.CONNECTION_ALLOW_LIST }}" | |
| # Every entry is checked as a JSON string literal, so one holding | |
| # a newline cannot pass as two, and one bad entry refuses the | |
| # whole list before any dispatch. One pull request per dispatch | |
| # keeps a failure to that pull request, and each loop at its own | |
| # pace. A failed dispatch is a warning: an operator's revise_only | |
| # dispatch still finds the pull request. The run parameters it | |
| # used go with it (docs/DESIGN.md section 20.1): those the | |
| # reusable workflow reports, which a hand-back may have inherited, | |
| # else the form's. So a dispatch that turned a review off keeps | |
| # it off for the loop, one that trusted checkout skills or | |
| # .github keeps them on, and a Copilot Fusion run stays on Fusion | |
| # at its tier. A run that inherited asks its next round to | |
| # inherit too, so a model the form no longer lists carries on. | |
| - name: 'Dispatch next rounds' | |
| id: dispatch | |
| env: | |
| GH_TOKEN: "${{ github.token }}" | |
| ORG: "${{ github.repository_owner }}" | |
| PULLS: "${{ needs.code-monkey.outputs.continue_pull_requests }}" | |
| PARENT_RUN: "${{ github.run_id }}" | |
| MODEL: "${{ inputs.model }}" | |
| FUSION: "${{ inputs.fusion_auto_model_select }}" | |
| # A form field left blank forwards its default. | |
| FUSION_TIER: "${{ inputs.fusion_tier || 'standard' }}" | |
| RUNTIME: "${{ inputs.max_runtime_minutes || '180' }}" | |
| ROUNDS: "${{ inputs.max_rounds || '10' }}" | |
| STALE: "${{ inputs.stale_status_minutes || '8' }}" | |
| SUBAGENTS: "${{ inputs.allow_subagents }}" | |
| REVIEW: "${{ inputs.request_review }}" | |
| ANTAGONISTIC: "${{ inputs.request_antagonistic_review }}" | |
| SKILLS: "${{ inputs.load_repo_skills }}" | |
| DOTGITHUB: "${{ inputs.include_dotgithub }}" | |
| INHERIT: "${{ inputs.inherit_run_parameters }}" | |
| EFFECTIVE: "${{ needs.code-monkey.outputs.run_parameters }}" | |
| run: | | |
| set -euo pipefail | |
| export LC_ALL=C | |
| # The effective values, by form input name, in place of the | |
| # form's; every one is checked below as a form value is. | |
| if [ -n "$EFFECTIVE" ]; then | |
| if ! fields=$(jq -r 'if type == "object" then | |
| [.model, .fusion_tier, .max_runtime_minutes, .max_rounds, | |
| .stale_status_minutes, .allow_subagents, .request_review, | |
| .request_antagonistic_review, .load_repo_skills, | |
| .include_dotgithub] | map(tostring) | join("|") | |
| else error("not an object") end' <<< "$EFFECTIVE"); then | |
| echo '::error::The run parameters are not a JSON object' | |
| exit 1 | |
| fi | |
| IFS='|' read -r id tier RUNTIME ROUNDS STALE SUBAGENTS REVIEW \ | |
| ANTAGONISTIC SKILLS DOTGITHUB <<< "$fields" | |
| FUSION=false | |
| case "$id" in | |
| claude-opus-5.5) MODEL='Claude Opus 5.5' ;; | |
| claude-fable-5.2) MODEL='Claude Fable 5.2' ;; | |
| claude-sonnet-5.5) MODEL='Claude Sonnet 5.5' ;; | |
| gpt-6-astra) MODEL='GPT-6 Astra' ;; | |
| fusion) FUSION=true; FUSION_TIER="$tier" ;; | |
| *) | |
| # Not on the form: only a round that inherits can carry | |
| # it, and the form's model holds its place. | |
| if [ "$INHERIT" != true ]; then | |
| echo "::error::Unknown model identifier $id" | |
| exit 1 | |
| fi ;; | |
| esac | |
| fi | |
| case "$MODEL" in | |
| 'Claude Opus 5.5'|'Claude Fable 5.2'|'Claude Sonnet 5.5') ;; | |
| 'GPT-6 Astra') ;; | |
| *) echo "::error::Unknown model $MODEL"; exit 1 ;; | |
| esac | |
| case "$FUSION_TIER" in | |
| standard|high|max) ;; | |
| *) echo "::error::Unknown Fusion tier $FUSION_TIER"; exit 1 ;; | |
| esac | |
| if ! [[ "$RUNTIME" =~ ^[1-9][0-9]*$ && "$ROUNDS" =~ ^[1-9][0-9]*$ && | |
| "$STALE" =~ ^[0-9]+$ && "$PARENT_RUN" =~ ^[1-9][0-9]*$ ]] | |
| then | |
| echo '::error::max_runtime_minutes, max_rounds,' \ | |
| 'stale_status_minutes and the run ID must be numbers' | |
| exit 1 | |
| fi | |
| for switch in "$SUBAGENTS" "$REVIEW" "$ANTAGONISTIC" "$SKILLS" \ | |
| "$DOTGITHUB" "$FUSION" "$INHERIT"; do | |
| case "$switch" in | |
| true|false) ;; | |
| *) echo '::error::The forwarded switches must be true or false' | |
| exit 1 ;; | |
| esac | |
| done | |
| if ! items=$(jq -r 'if type == "array" then .[] | @json | |
| else error("not an array") end' <<< "$PULLS"); then | |
| echo '::error::The continuing pull requests are not a JSON array' | |
| exit 1 | |
| fi | |
| pattern='^"([A-Za-z0-9-]+)/[A-Za-z0-9_.-]+#[1-9][0-9]*"$' | |
| pulls=() | |
| while IFS= read -r item; do | |
| [ -n "$item" ] || continue | |
| if ! [[ "$item" =~ $pattern ]] || | |
| [ "${BASH_REMATCH[1],,}" != "${ORG,,}" ]; then | |
| echo "::error::Refused an entry outside $ORG or not owner/repo#N" | |
| exit 1 | |
| fi | |
| pulls+=("${item:1:${#item}-2}") | |
| done <<< "$items" | |
| inherit=() | |
| if [ "$INHERIT" = true ]; then | |
| inherit=(-f inherit_run_parameters=true) | |
| fi | |
| dispatched=() | |
| failed=() | |
| for pull in "${pulls[@]}"; do | |
| if gh workflow run code-monkey-cron.yaml \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| -f dry_run=false -f mode=pull-requests -f max_pull_requests=0 \ | |
| -f pull_requests="$pull" -f outstanding_only=true \ | |
| -f continues_run="$PARENT_RUN" \ | |
| -f model="$MODEL" -f fusion_auto_model_select="$FUSION" \ | |
| -f fusion_tier="$FUSION_TIER" -f max_runtime_minutes="$RUNTIME" \ | |
| -f max_rounds="$ROUNDS" -f stale_status_minutes="$STALE" \ | |
| -f allow_subagents="$SUBAGENTS" \ | |
| -f request_review="$REVIEW" \ | |
| -f request_antagonistic_review="$ANTAGONISTIC" \ | |
| -f load_repo_skills="$SKILLS" -f include_dotgithub="$DOTGITHUB" \ | |
| "${inherit[@]}" | |
| then | |
| dispatched+=("$pull") | |
| else | |
| echo "::warning::Next round dispatch failed: $pull" | |
| failed+=("$pull") | |
| fi | |
| done | |
| { | |
| echo '## Next rounds' | |
| echo | |
| for pull in "${dispatched[@]}"; do echo "- dispatched: $pull"; done | |
| for pull in "${failed[@]}"; do echo "- failed: $pull"; done | |
| } >> "$GITHUB_STEP_SUMMARY" |