AGENT SKILL

XMC Create PR

Automates creating and updating GitHub Pull Requests, running pre-commit hooks, formatting PR body templates, managing CI wait buffers, and enforcing strict confirmation gates for Draft PR conversion.

License 许可
Apache-2.0
所属仓库
google/xmc
最近更新
2026-11-14
Stars
★ 8
Forks
0

01 前言 Front Matter

name
XMC Create PR
description
Automates creating and updating GitHub Pull Requests, running pre-commit hooks, formatting PR body templates, managing CI wait buffers, and enforcing strict confirmation gates for Draft PR conversion.

03 SKILL.md 正文

GitHub Pull Request Creation & Update Playbook

This skill provides step-by-step procedures for creating, updating, and managing GitHub Pull Requests in the XMC repository.

[!IMPORTANT] All execution steps in this skill MUST strictly adhere to the policy rules defined in GitHub Authoring & PR Creation Standards, Skills & Automation Guidelines, and Core Engineering Standards.


Guidelines for Using CLI Tools

When invoking helper tools under tools/ (e.g., update_pr_description.py):

  1. Do not read tool source code: Do not open or read the Python source code of helper tools. Refer to Skills & Automation Guidelines.
  2. Use --help: Run tools with --help to inspect parameters and usage.
  3. Parse Structured Output & Handle Errors: All tools output structured JSON; check the exit code per Helper Tool Exit Codes.
  4. Shell & Payload Safety: Execute standalone .py script files or pass arguments via script parameters. Avoid double-quoted inline commands (python3 -c "...").

1. Branch Check & Formatting Verification

Before making commits or opening a PR:

  1. Check current branch:
    git branch --show-current
    
  2. Validate branch format: Ensure the branch name strictly conforms to <prefix>/<kebab-case-description> (e.g., feat/enforce-pr-comment-integrity, fix/gke-rollout-timeout).
  3. Rename branch if non-compliant: If the branch name uses raw worktree directory names, underscores, or lacks a prefix:
    git branch -m <prefix>/<kebab-case-description>
    
  4. Detached HEAD State: If git branch --show-current is empty, create and switch to a compliant branch:
    git checkout -b <prefix>/<kebab-case-description>
    

2. Pre-Commit Hooks & Commit Creation

Before creating any commit:

  1. Stage, Then Run Pre-Commit Formatting & Affected Tests Protocol:
    git add <changed_paths>
    ./.githooks/pre-commit
    
    Stage first: the hook auto-restages formatter fixes only for fully staged files (opt out with XMC_PRECOMMIT_NO_AUTOSTAGE=1). It exits 1 on unfixed lint errors or on fixes to partially staged or unstaged files; review those (git diff), stage them, and re-run. Once linters pass it executes python3 ./tools/run_affected_tests.py --skip-emulator-check, skipped when every staged path is Markdown or under docs/.
  2. Format Conventional Commit Message: Format the commit message header using <type>(<scope>): <summary> (e.g., feat(auth): add OAuth2 token refresh support).
  3. Include Mandatory Context & Tags: Append technical rationale, bug references (e.g., Fixes bug 12345), and mandatory description tags at the bottom of the commit body:
    TAG=agy
    CONV=<conversation_id>
    
  4. Execute Git Commit via Message File: To avoid shell double-quoting syntax errors when dealing with multiline commit bodies, write the commit message to a temporary file and commit using -F:
    cat << 'EOF' > commit_msg.txt
    <type>(<scope>): <summary>
    
    <Detailed commit body>
    
    TAG=agy
    CONV=<conversation_id>
    EOF
    git commit -F commit_msg.txt && rm commit_msg.txt
    

3. Pull Request Creation & PR Body Population

When creating a new PR or populating its description:

  1. Diff Sizing Pre-Flight Check: Run the deterministic diff sizing tool before preparing the PR:

    ./tools/analyze_diff_size.py --base-ref origin/main...
    

    If should_trigger_split_verifier is true (Prod $\ge 400$, Total Code $\ge 1,000$, or Docs $\ge 1,000$ lines), STOP and execute the XMC PR Split Verification Skill to audit SRP and construct a gh-stack plan before opening a PR.

  2. Pre-Commit Verification: Verify ./.githooks/pre-commit (formatters, linters, and run_affected_tests.py) passes cleanly.

  3. Conventional PR Title: Match the PR title to Conventional Commits syntax (<type>(<scope>): <summary>).

  4. Check for Trajectory Benchmark Artifact: Check if /tmp/benchmark_report_<branch_name>.md exists (generated by XMC Trajectory Comparison). If present, embed its content into the ## Verification & Testing section.

  5. Compile the Assumptions List & Verify Blueprint/Downstream Claims: Sweep the session trajectory for decisions made in place of an explicit instruction or verified fact, resolve any that are still cheaply checkable, and disclose the remainder per Mandatory Assumptions Disclosure:

    • Verify Blueprint & Downstream Component Settings Before Repeating Task Claims: For changes under deploy/ or test/helm/, inspect the target blueprint/chart files (e.g., whether deploy/ctk_v2/xmanager-cloud.yaml provisions GKE Standard vs. Autopilot, which components consume a global.* Helm setting, and which downstream modules actually opt into a dependency via set_values) before repeating symptom or impact statements from an issue/task prompt in inline comments or ## Motivation & Context.
    • Operational & Upgrade Assumptions on Deployment PRs: Infrastructure, Helm chart, and blueprint changes carry operational and upgrade assumptions (target cluster policies/versions, upstream chart behavior, in-place helm upgrade rollout and orphaned resource semantics) that must be listed as <assumption> — <why it was assumed> — <impact if wrong> rather than writing None — requirements were fully specified..
    • Stacked / Non-main Base Branch Disclosure: When a PR targets a base branch other than main, state the stacked base branch and rationale explicitly in ## Motivation & Context.
  6. Format PR Body Template: Write the PR body to a temporary markdown file (e.g., pr_body.md):

    ## Summary
    <Concise 2-3 sentence overview of what this PR introduces or fixes.>
    
    ## Motivation & Context
    <Explanation of the underlying problem, business/technical rationale, and design choices.>
    
    ## Key Changes
    - <Bulleted highlight of structural code adjustments>
    - <Targeted package, binary, or deployment modifications>
    
    ## Assumptions
    - <Assumption made during development> — <why it was assumed> — <impact if wrong>
    - <Deferred scope or unresolved open question, if any>
    <Replace the bullets above with `None — requirements were fully specified.` when no assumptions were made.>
    
    ## Verification & Testing
    - **Commands Executed**: `<bazel test / go test / ./tools/run_affected_tests.py>`
    - **Coverage & Test Status**: <Summary of unit/integration test results and pass state.>
    
    <!-- Embed Trajectory Benchmark if available -->
    <details open>
    <summary><b>🧪 Trajectory & Outcome Benchmark Results</b></summary>
    
    [Benchmark Telemetry & Scorecard]
    </details>
    
    ## Related Issues / Bugs
    Fixes bug <bug_id> (or N/A)
    
    TAG=agy
    CONV=<conversation_id>
    
  7. Mandatory User Confirmation Gate Before PR Creation: NEVER execute gh pr create (draft or non-draft) without explicit, affirmative user confirmation in the current conversation turn. Phrases like "proceed with next phase" authorize local work and verification, but DO NOT authorize opening a remote Pull Request. The agent MUST present pr_body.md, the planned PR title, body preview, and list of changes to the user for review and explicitly ask:

    "I have prepared the Pull Request." Title: <type>(<scope>): <summary> List of Changes:

    • [List of changes] Description Preview (from pr_body.md):

    [Markdown Preview]

    Shall I proceed with creating the Draft Pull Request on GitHub? (Y/n)"

  8. Create Draft PR via GitHub CLI: All new PRs must be created in Draft state:

    gh pr create --draft --title "<type>(<scope>): <summary>" --body-file pr_body.md
    

4. PR Description Updates via Helper Tool

When updating an existing Pull Request description:

  1. Format Updated Body: Prepare the updated body markdown in a temporary file (e.g., updated_pr_body.md).
  2. User Edit Gate: Present the updated PR description preview to the user and pause for confirmation/edits.
  3. Execute Update Tool:
    ./tools/pr_review/update_pr_description.py <pr_number> --body-file updated_pr_body.md
    

    [!IMPORTANT] Do NOT use gh pr edit directly to update descriptions, as classic project deprecations break description fields.


5. CI Wait Buffer Period

  1. After creating or updating a Pull Request, pause execution for approximately 2 minutes (120 seconds).
  2. Allow GitHub CI status checks and automated PR review passes to run and produce initial status checks before proceeding to subsequent workflow steps.
  3. Wait for CI Completion via Helper Tool: After the buffer, block on CI with:
    ./tools/pr_review/wait_for_ci.py <pr_number> [--repo owner/name] [--timeout 1800] [--interval 30]
    
    The tool polls with backoff until every check completes, exits 0 when all pass, 1 on failure or timeout, and 2 on an unexpected internal error. It judges only the newest run of each check, so runs cancelled because a later push superseded them are not failures. On failure its error JSON lists failed_checks, each with its workflow run_id, job_id, and a bounded log_tail (up to 80 lines of the job log ending at its last ##[error] line; tune with --log-lines).

    [!IMPORTANT] Do NOT poll with bare gh pr checks (it exits 8 while checks are pending, breaking && chains), do NOT pass check/job IDs to gh run list --workflow or use gh pr checks --json (unsupported by older gh releases), and do NOT rely on gh run view --log-failed (prints nothing on some gh releases). Use wait_for_ci.py output instead of dumping full CI logs.


6. Draft PR to Open Conversion Policy (Strict Confirmation Gate)

Pull Requests in XMC MUST always be created as Draft PRs by default.

[!CAUTION] Strict Prohibition Against Automatic Draft-to-Open PR Conversion: Agents MUST NEVER execute gh pr ready <pr_number> or convert a Draft Pull Request to Open (ready for review) without explicit, separate user confirmation in the current conversation turn.

Rules & Guardrails:

  1. Draft State Default: All newly created PRs remain in Draft state throughout development, testing, and automated review iterations.
  2. Generic Authorizations Insufficient: General instructions like "proceed", "continue", "finish", "all done", "looks good", or "resolve comments" authorize local fixes or test verification, but DO NOT authorize converting a Draft PR to Open.
  3. Mandatory Confirmation Prompt: Even after all CI checks pass (./tools/pr_review/wait_for_ci.py <pr_number> exits 0) and 100% of review comments are resolved, the agent MUST NOT run gh pr ready. Instead, the agent reports completion and explicitly asks:

    "All CI checks have passed and all review comments have been resolved for Draft PR #<pr_number>."

    "Would you like me to convert Pull Request #<pr_number> from Draft to Open (ready for review)? (Y/n)"

  4. Execution on Explicit Affirmation Only:
    • Run gh pr ready <pr_number> ONLY IF the user explicitly confirms (e.g., "yes", "Y", "convert to open", "mark ready for review").
    • If the user declines ("no"), does not respond to the question, or provides any other instruction, the PR MUST REMAIN in Draft state.

7. Standard 5-Step End-to-End PR Lifecycle

When creating and managing Pull Requests, follow this mandatory 5-step lifecycle:

  1. Diff Sizing Check & Create Draft PR (Requires Confirmation Gate): Run ./tools/analyze_diff_size.py --base-ref origin/main.... If thresholds are exceeded, invoke XMC PR Split Verification. Otherwise, obtain explicit user confirmation per Section 3, Step 7 (presenting Title, List of Changes, and Description Preview). Once confirmed, execute: gh pr create --draft --title "<type>(<scope>): <summary>" --body-file pr_body.md
  2. Wait for Automated Review Bot: Pause for 2–3 minutes to allow GitHub CI status checks and the automated Gemini review bot to inspect code diffs and post review comments.
  3. Pull Review Comments: Fetch unresolved review comments and generate the review checklist artifact:
    ./tools/pr_review/generate_review_checklist.py <owner> <repo> <pr_number> -o pr_review_checklist.md
    
  4. Address Review Comments: Triage each comment's technical validity, rule alignment, and PR scope impact per Comment Validity & Pushback Triage (adopting valid fixes vs. posting technical pushback replies when a suggestion conflicts with repository rules or scope boundaries), commit and push adopted updates, post inline thread replies (./tools/pr_review/reply_pr_comment.py), and verify 1-to-1 resolution (./tools/pr_review/verify_pr_comment_resolution.py).
  5. Verify CI Checks & Draft Status Report (Requires Explicit Confirmation Gate to Convert): Verify CI status with ./tools/pr_review/wait_for_ci.py <pr_number> (see Section 5). When checks pass and all comments are resolved, report the final state to the user. Do NOT automatically convert the PR to open. Explicitly ask for user confirmation per Section 6 ('Would you like me to convert Pull Request #<pr_number> from Draft to Open (ready for review)? (Y/n)'). Only if explicitly confirmed by the user, execute: gh pr ready <pr_number>

04 同仓库更多 Skills

google
google/xmc

XMC Upgrade Environment

Upgrades an existing XManager on Cloud (XMC) environment on GKE to the latest current branch state using the deployment configuration YAML.

★ 8
google
google/xmc

XMC Trajectory Comparison

Validates proposed skill or rule changes by executing concurrent A/B benchmark subagents on clean baseline vs candidate worktrees, comparing trajectories, and tearing down test resources.

★ 8
google
google/xmc

XMC Review PR

Interactive multi-agent PR review workflow enforcing code rules, open direction discussions, explicit confirmation gates, inline comment deduplication, and follow-up re-review verification.

★ 8
google
google/xmc

XMC Release

Orchestrates an end-to-end XMC release workflow — deploying the latest main to nightly, running and verifying e2e tests, capturing visual snapshot galleries, generating and iterating on structured release notes with the user, and publishing the release. Use when preparing, orchestrating, or publishing a formal XMC release from main.

★ 8
google
google/xmc

XMC PR Split Verification

Analyzes pull request diffs exceeding size thresholds (400 prod / 1000 total / 1000 docs) to enforce Single Responsibility Principle (SRP), evaluate vertical slice splitting feasibility, eliminate dead code, and plan gh-stack PR stacks.

★ 8
google
google/xmc

XMC Iterative Reflection

Audits active session trajectory, thought history, and PR review comments to identify friction points, rule gaps, missing helper tools, and token inefficiencies. Use when requested by the user, after major implementations, or following PR review comment resolutions.

★ 8