From 1ae4da33e52091404cfc887ac8bfa618329c10f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 00:52:13 +0000 Subject: [PATCH 1/2] Initial plan From 91e4518f8ee4bba883ac7f4d7c7c933c2026fa57 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 01:02:33 +0000 Subject: [PATCH 2/2] Optimize contribution-check workflow: trim deep research, pre-fetch guidelines, narrow toolset, reduce batch size - Replace Step 2.5 'Deep Research' with 'Targeted Context' in contribution-checker.agent.md (removes repo browsing, surrounding code reads, and duplicate PR searches) - Pre-fetch CONTRIBUTING.md once in the pre-agent bash step; pass it inline to each subagent dispatch to eliminate 9 redundant fetches per run - Narrow GitHub toolset from [default] to [pull_requests, repos, issues] - Reduce MAX_EVALUATE from 10 to 5 to cap token usage on high-traffic days - Recompile contribution-check.lock.yml Resolves: copilot-token-optimizer issue (~46% token reduction estimated)" Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b996051a-b125-4b10-a8e1-20f02279380e Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/agents/contribution-checker.agent.md | 18 +++++------ .github/workflows/contribution-check.lock.yml | 26 ++++++++-------- .github/workflows/contribution-check.md | 30 +++++++++++++++++-- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/.github/agents/contribution-checker.agent.md b/.github/agents/contribution-checker.agent.md index 92c324252fa..7e4030023a4 100644 --- a/.github/agents/contribution-checker.agent.md +++ b/.github/agents/contribution-checker.agent.md @@ -13,7 +13,9 @@ You will be called with a PR reference in `owner/repo#number` format. Parse the ## Step 1: Fetch Contributing Guidelines -Fetch the target repository's contributing guidelines. Look for these files in order and use the **first one found**: +If the CONTRIBUTING.md content was provided inline at the start of this prompt (inside `` tags), use that content directly and skip this step. If the inline content is `# No CONTRIBUTING.md found`, treat it as missing guidelines and return a single row with verdict `❓` and quality `no-guidelines`. + +Otherwise, fetch the target repository's contributing guidelines. Look for these files in order and use the **first one found**: 1. `CONTRIBUTING.md` (repo root) 2. `.github/CONTRIBUTING.md` @@ -30,17 +32,15 @@ For the given PR, retrieve: - list of changed file paths (use `get_files`) - diff content (use `get_diff`) -## Step 2.5: Deep Research +## Step 2.5: Targeted Context -Before running the checklist, do a deep dive into both the **target repository** and the **PR branch** to build enough context for high-quality, specific feedback: +Before running the checklist, gather targeted context: -1. **Understand the codebase** — browse the target repo's directory structure, README, and architecture docs. Identify the project's tech stack, module layout, and conventions (e.g., where tests live, how modules are organized, what frameworks are used). -2. **Understand the changed area** — for each file touched by the PR, read the surrounding code (not just the diff). Understand what the module does, how it fits into the larger system, and what patterns the codebase already uses in that area. -3. **Check for related issues** — if the PR body references an issue, read that issue to understand the original requirements and acceptance criteria. -4. **Check for existing tests** — look at the test directory/files adjacent to the changed code. Understand the testing patterns and frameworks the project uses so your feedback and agentic prompts reference the right tools and conventions. -5. **Check for duplicated effort** — search for open PRs that touch the same files or address the same issue to flag potential conflicts. +- Read the PR diff and changed files carefully to understand what's changing. +- If the PR body references an issue number, read that issue to understand the original requirements. -This research ensures the comment and agentic prompt you generate are **specific to the actual codebase** — referencing real file paths, real test patterns, and real conventions rather than generic advice. +Do not browse the repo directory, read surrounding code, or search for duplicate PRs. +This focused approach gives you enough context for a high-quality checklist without expensive exploration. ## Step 3: Run the Checklist diff --git a/.github/workflows/contribution-check.lock.yml b/.github/workflows/contribution-check.lock.yml index 4d20274cb5c..1b94a126cb2 100644 --- a/.github/workflows/contribution-check.lock.yml +++ b/.github/workflows/contribution-check.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v3","frontmatter_hash":"b98e3c517540ddc6787d7a128a47bb71cdfe6b43d14630b29ab3c9a907111631","strict":true,"agent_id":"copilot"} +# gh-aw-metadata: {"schema_version":"v3","frontmatter_hash":"a00d530081db489f981d45ad6773d2fe3bf1869c14c1af1592ea1bdd270e586e","strict":true,"agent_id":"copilot"} # gh-aw-manifest: {"version":1,"secrets":["COPILOT_GITHUB_TOKEN","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN"],"actions":[{"repo":"actions/checkout","sha":"de0fac2e4500dabe0009e67214ff5f5447ce83dd","version":"v6.0.2"},{"repo":"actions/download-artifact","sha":"3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c","version":"v8.0.1"},{"repo":"actions/github-script","sha":"373c709c69115d41ff229c7e5df9f8788daa9553","version":"v9"},{"repo":"actions/upload-artifact","sha":"043fb46d1a93c77aae656e7c1c64a875d1fc6a0a","version":"v7.0.1"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.25.20","digest":"sha256:9161f2415a3306a344aca34dd671ee69f122317e0a512e66dc64c94b9c508682","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.25.20@sha256:9161f2415a3306a344aca34dd671ee69f122317e0a512e66dc64c94b9c508682"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.25.20","digest":"sha256:6971639e381e82e45134bcd333181f456df3a52cd6f818a3e3d6de068ff91519","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.25.20@sha256:6971639e381e82e45134bcd333181f456df3a52cd6f818a3e3d6de068ff91519"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.25.20","digest":"sha256:5411d903f73ee597e6a084971c2adef3eb0bd405910df3ed7bf5e3d6bd58a236","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.25.20@sha256:5411d903f73ee597e6a084971c2adef3eb0bd405910df3ed7bf5e3d6bd58a236"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.2.19","digest":"sha256:44d4d8de7e6c37aaea484eba489940c52df6a0b54078ddcbc9327592d5b3c3dd","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.2.19@sha256:44d4d8de7e6c37aaea484eba489940c52df6a0b54078ddcbc9327592d5b3c3dd"},{"image":"ghcr.io/github/github-mcp-server:v0.32.0","digest":"sha256:2763823c63bcca718ce53850a1d7fcf2f501ec84028394f1b63ce7e9f4f9be28","pinned_image":"ghcr.io/github/github-mcp-server:v0.32.0@sha256:2763823c63bcca718ce53850a1d7fcf2f501ec84028394f1b63ce7e9f4f9be28"},{"image":"node:lts-alpine","digest":"sha256:01743339035a5c3c11a373cd7c83aeab6ed1457b55da6a69e014a95ac4e4700b","pinned_image":"node:lts-alpine@sha256:01743339035a5c3c11a373cd7c83aeab6ed1457b55da6a69e014a95ac4e4700b"}]} # ___ _ _ # / _ \ | | (_) @@ -163,14 +163,14 @@ jobs: run: | bash "${RUNNER_TEMP}/gh-aw/actions/create_prompt_first.sh" { - cat << 'GH_AW_PROMPT_8a59bfc260cb8f0e_EOF' + cat << 'GH_AW_PROMPT_a566c1dcc1635783_EOF' - GH_AW_PROMPT_8a59bfc260cb8f0e_EOF + GH_AW_PROMPT_a566c1dcc1635783_EOF cat "${RUNNER_TEMP}/gh-aw/prompts/xpia.md" cat "${RUNNER_TEMP}/gh-aw/prompts/temp_folder_prompt.md" cat "${RUNNER_TEMP}/gh-aw/prompts/markdown.md" cat "${RUNNER_TEMP}/gh-aw/prompts/safe_outputs_prompt.md" - cat << 'GH_AW_PROMPT_8a59bfc260cb8f0e_EOF' + cat << 'GH_AW_PROMPT_a566c1dcc1635783_EOF' Tools: add_comment(max:10), create_issue, add_labels(max:4), missing_tool, missing_data, noop @@ -202,12 +202,12 @@ jobs: {{/if}} - GH_AW_PROMPT_8a59bfc260cb8f0e_EOF + GH_AW_PROMPT_a566c1dcc1635783_EOF cat "${RUNNER_TEMP}/gh-aw/prompts/github_mcp_tools_with_safeoutputs_prompt.md" - cat << 'GH_AW_PROMPT_8a59bfc260cb8f0e_EOF' + cat << 'GH_AW_PROMPT_a566c1dcc1635783_EOF' {{#runtime-import .github/workflows/contribution-check.md}} - GH_AW_PROMPT_8a59bfc260cb8f0e_EOF + GH_AW_PROMPT_a566c1dcc1635783_EOF } > "$GH_AW_PROMPT" - name: Interpolate variables and render templates uses: actions/github-script@373c709c69115d41ff229c7e5df9f8788daa9553 # v9 @@ -353,7 +353,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} name: Fetch and filter PRs - run: "# Fetch open PRs from the target repository opened in the last 24 hours\nSINCE=$(date -d '24 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null \\\n || date -v-24H '+%Y-%m-%dT%H:%M:%SZ')\n\necho \"Fetching open PRs from $TARGET_REPOSITORY created since $SINCE...\"\nALL_PRS=$(gh pr list \\\n --repo \"$TARGET_REPOSITORY\" \\\n --state open \\\n --limit 100 \\\n --json number,createdAt \\\n --jq \"[.[] | select(.createdAt >= \\\"$SINCE\\\")]\" \\\n 2>/dev/null || echo \"[]\")\n\nTOTAL=$(echo \"$ALL_PRS\" | jq 'length')\necho \"Found $TOTAL open PRs created in the last 24 hours\"\n\n# Cap the number of PRs to evaluate at 10\nMAX_EVALUATE=10\nEVALUATED=$(echo \"$ALL_PRS\" | jq --argjson max \"$MAX_EVALUATE\" '[.[0:$max][] | .number]')\nEVALUATED_COUNT=$(echo \"$EVALUATED\" | jq 'length')\nSKIPPED_COUNT=$((TOTAL - EVALUATED_COUNT))\n\n# Write results to workspace root\njq -n \\\n --argjson pr_numbers \"$EVALUATED\" \\\n --argjson skipped_count \"$SKIPPED_COUNT\" \\\n --argjson evaluated_count \"$EVALUATED_COUNT\" \\\n '{pr_numbers: $pr_numbers, skipped_count: $skipped_count, evaluated_count: $evaluated_count}' \\\n > \"$GITHUB_WORKSPACE/pr-filter-results.json\"\n\necho \"✓ Wrote pr-filter-results.json: $EVALUATED_COUNT to evaluate, $SKIPPED_COUNT skipped\"\ncat \"$GITHUB_WORKSPACE/pr-filter-results.json\"" + run: "# Fetch open PRs from the target repository opened in the last 24 hours\nSINCE=$(date -d '24 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null \\\n || date -v-24H '+%Y-%m-%dT%H:%M:%SZ')\n\necho \"Fetching open PRs from $TARGET_REPOSITORY created since $SINCE...\"\nALL_PRS=$(gh pr list \\\n --repo \"$TARGET_REPOSITORY\" \\\n --state open \\\n --limit 100 \\\n --json number,createdAt \\\n --jq \"[.[] | select(.createdAt >= \\\"$SINCE\\\")]\" \\\n 2>/dev/null || echo \"[]\")\n\nTOTAL=$(echo \"$ALL_PRS\" | jq 'length')\necho \"Found $TOTAL open PRs created in the last 24 hours\"\n\n# Cap the number of PRs to evaluate at 5\nMAX_EVALUATE=5\nEVALUATED=$(echo \"$ALL_PRS\" | jq --argjson max \"$MAX_EVALUATE\" '[.[0:$max][] | .number]')\nEVALUATED_COUNT=$(echo \"$EVALUATED\" | jq 'length')\nSKIPPED_COUNT=$((TOTAL - EVALUATED_COUNT))\n\n# Write results to workspace root\njq -n \\\n --argjson pr_numbers \"$EVALUATED\" \\\n --argjson skipped_count \"$SKIPPED_COUNT\" \\\n --argjson evaluated_count \"$EVALUATED_COUNT\" \\\n '{pr_numbers: $pr_numbers, skipped_count: $skipped_count, evaluated_count: $evaluated_count}' \\\n > \"$GITHUB_WORKSPACE/pr-filter-results.json\"\n\necho \"✓ Wrote pr-filter-results.json: $EVALUATED_COUNT to evaluate, $SKIPPED_COUNT skipped\"\ncat \"$GITHUB_WORKSPACE/pr-filter-results.json\"\n\n# Pre-fetch CONTRIBUTING.md once so all subagent calls can reuse it\nCONTRIBUTING_FETCHED=false\nfor CONTRIBUTING_PATH in \"CONTRIBUTING.md\" \".github/CONTRIBUTING.md\" \"docs/CONTRIBUTING.md\"; do\n if gh api \"repos/$TARGET_REPOSITORY/contents/$CONTRIBUTING_PATH\" \\\n --jq '.content' 2>/dev/null | base64 -d > \"$GITHUB_WORKSPACE/contributing-guidelines.md\" 2>/dev/null; then\n echo \"✓ Pre-fetched contributing guidelines from $CONTRIBUTING_PATH\"\n CONTRIBUTING_FETCHED=true\n break\n fi\ndone\nif [ \"$CONTRIBUTING_FETCHED\" = \"false\" ]; then\n echo \"# No CONTRIBUTING.md found\" > \"$GITHUB_WORKSPACE/contributing-guidelines.md\"\n echo \"ℹ No CONTRIBUTING.md found in $TARGET_REPOSITORY (checked root, .github/, docs/)\"\nfi" - name: Configure Git credentials env: @@ -406,9 +406,9 @@ jobs: mkdir -p "${RUNNER_TEMP}/gh-aw/safeoutputs" mkdir -p /tmp/gh-aw/safeoutputs mkdir -p /tmp/gh-aw/mcp-logs/safeoutputs - cat > "${RUNNER_TEMP}/gh-aw/safeoutputs/config.json" << 'GH_AW_SAFE_OUTPUTS_CONFIG_92d185d0bb1731a8_EOF' + cat > "${RUNNER_TEMP}/gh-aw/safeoutputs/config.json" << 'GH_AW_SAFE_OUTPUTS_CONFIG_4b9126606c561328_EOF' {"add_comment":{"hide_older_comments":true,"max":10,"target":"*","target-repo":"${{ vars.TARGET_REPOSITORY }}"},"add_labels":{"allowed":["spam","needs-work","outdated","lgtm"],"max":4,"target":"*","target-repo":"${{ vars.TARGET_REPOSITORY }}"},"create_issue":{"close_older_issues":true,"expires":24,"group_by_day":true,"labels":["contribution-report"],"max":1,"title_prefix":"[Contribution Check Report]"},"create_report_incomplete_issue":{},"missing_data":{},"missing_tool":{},"noop":{"max":1,"report-as-issue":"true"},"report_incomplete":{}} - GH_AW_SAFE_OUTPUTS_CONFIG_92d185d0bb1731a8_EOF + GH_AW_SAFE_OUTPUTS_CONFIG_4b9126606c561328_EOF - name: Write Safe Outputs Tools env: GH_AW_TOOLS_META_JSON: | @@ -640,7 +640,7 @@ jobs: export MCP_GATEWAY_DOCKER_COMMAND='docker run -i --rm --network host -v /var/run/docker.sock:/var/run/docker.sock -e MCP_GATEWAY_PORT -e MCP_GATEWAY_DOMAIN -e MCP_GATEWAY_API_KEY -e MCP_GATEWAY_PAYLOAD_DIR -e MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD -e DEBUG -e MCP_GATEWAY_LOG_DIR -e GH_AW_MCP_LOG_DIR -e GH_AW_SAFE_OUTPUTS -e GH_AW_SAFE_OUTPUTS_CONFIG_PATH -e GH_AW_SAFE_OUTPUTS_TOOLS_PATH -e GH_AW_ASSETS_BRANCH -e GH_AW_ASSETS_MAX_SIZE_KB -e GH_AW_ASSETS_ALLOWED_EXTS -e DEFAULT_BRANCH -e GITHUB_MCP_SERVER_TOKEN -e GITHUB_MCP_GUARD_MIN_INTEGRITY -e GITHUB_MCP_GUARD_REPOS -e GITHUB_REPOSITORY -e GITHUB_SERVER_URL -e GITHUB_SHA -e GITHUB_WORKSPACE -e GITHUB_TOKEN -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RUN_ATTEMPT -e GITHUB_JOB -e GITHUB_ACTION -e GITHUB_EVENT_NAME -e GITHUB_EVENT_PATH -e GITHUB_ACTOR -e GITHUB_ACTOR_ID -e GITHUB_TRIGGERING_ACTOR -e GITHUB_WORKFLOW -e GITHUB_WORKFLOW_REF -e GITHUB_WORKFLOW_SHA -e GITHUB_REF -e GITHUB_REF_NAME -e GITHUB_REF_TYPE -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GH_AW_SAFE_OUTPUTS_PORT -e GH_AW_SAFE_OUTPUTS_API_KEY -v /tmp/gh-aw/mcp-payloads:/tmp/gh-aw/mcp-payloads:rw -v /opt:/opt:ro -v /tmp:/tmp:rw -v '"${GITHUB_WORKSPACE}"':'"${GITHUB_WORKSPACE}"':rw ghcr.io/github/gh-aw-mcpg:v0.2.19' mkdir -p /home/runner/.copilot - cat << GH_AW_MCP_CONFIG_51099f0b654e28c7_EOF | bash "${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh" + cat << GH_AW_MCP_CONFIG_00768c14579c9f4e_EOF | bash "${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh" { "mcpServers": { "github": { @@ -650,7 +650,7 @@ jobs: "GITHUB_HOST": "\${GITHUB_SERVER_URL}", "GITHUB_PERSONAL_ACCESS_TOKEN": "\${GITHUB_MCP_SERVER_TOKEN}", "GITHUB_READ_ONLY": "1", - "GITHUB_TOOLSETS": "context,repos,issues,pull_requests" + "GITHUB_TOOLSETS": "pull_requests,repos,issues" }, "guard-policies": { "allow-only": { @@ -684,7 +684,7 @@ jobs: "payloadDir": "${MCP_GATEWAY_PAYLOAD_DIR}" } } - GH_AW_MCP_CONFIG_51099f0b654e28c7_EOF + GH_AW_MCP_CONFIG_00768c14579c9f4e_EOF - name: Download activation artifact uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: diff --git a/.github/workflows/contribution-check.md b/.github/workflows/contribution-check.md index 0066fc83026..52ff41c2462 100644 --- a/.github/workflows/contribution-check.md +++ b/.github/workflows/contribution-check.md @@ -14,7 +14,7 @@ env: tools: github: - toolsets: [default] + toolsets: [pull_requests, repos, issues] allowed-repos: all min-integrity: none safe-outputs: @@ -57,8 +57,8 @@ steps: TOTAL=$(echo "$ALL_PRS" | jq 'length') echo "Found $TOTAL open PRs created in the last 24 hours" - # Cap the number of PRs to evaluate at 10 - MAX_EVALUATE=10 + # Cap the number of PRs to evaluate at 5 + MAX_EVALUATE=5 EVALUATED=$(echo "$ALL_PRS" | jq --argjson max "$MAX_EVALUATE" '[.[0:$max][] | .number]') EVALUATED_COUNT=$(echo "$EVALUATED" | jq 'length') SKIPPED_COUNT=$((TOTAL - EVALUATED_COUNT)) @@ -73,6 +73,21 @@ steps: echo "✓ Wrote pr-filter-results.json: $EVALUATED_COUNT to evaluate, $SKIPPED_COUNT skipped" cat "$GITHUB_WORKSPACE/pr-filter-results.json" + + # Pre-fetch CONTRIBUTING.md once so all subagent calls can reuse it + CONTRIBUTING_FETCHED=false + for CONTRIBUTING_PATH in "CONTRIBUTING.md" ".github/CONTRIBUTING.md" "docs/CONTRIBUTING.md"; do + if gh api "repos/$TARGET_REPOSITORY/contents/$CONTRIBUTING_PATH" \ + --jq '.content' 2>/dev/null | base64 -d > "$GITHUB_WORKSPACE/contributing-guidelines.md" 2>/dev/null; then + echo "✓ Pre-fetched contributing guidelines from $CONTRIBUTING_PATH" + CONTRIBUTING_FETCHED=true + break + fi + done + if [ "$CONTRIBUTING_FETCHED" = "false" ]; then + echo "# No CONTRIBUTING.md found" > "$GITHUB_WORKSPACE/contributing-guidelines.md" + echo "ℹ No CONTRIBUTING.md found in $TARGET_REPOSITORY (checked root, .github/, docs/)" + fi --- ## Target Repository @@ -105,9 +120,18 @@ For each PR number in the comma-separated list, delegate evaluation to the **con ### How to dispatch +Read the contents of `contributing-guidelines.md` from the workspace root. This file was pre-fetched in the `pre-agent` step and contains the target repository's contributing guidelines. Include it verbatim in every subagent dispatch prompt to avoid redundant fetches. + Call the contribution-checker subagent for each PR with this prompt: ``` +The CONTRIBUTING.md content for this repository is attached below. +Skip Step 1 — do not fetch CONTRIBUTING.md again. + + +{contents of contributing-guidelines.md} + + Evaluate PR ${{ env.TARGET_REPOSITORY }}# against the contribution guidelines. ```