AGENT SKILL

dx-pr-commit

Commit changes (work item ID in the message, rebase onto base) and optionally open a PR in the configured SCM (only ado is implemented). Use for 'commit', 'push', 'open PR', 'create PR'. Not for reviews (dx-pr-review) or replies (dx-pr-answer); the end-of-plan PR is dx-pr.

License 许可
MIT
最近更新
2026-11-11
Stars
★ 7
Forks
3

01 前言 Front Matter

name
dx-pr-commit
context
fork
description
Commit changes (work item ID in the message, rebase onto base) and optionally open a PR in the configured SCM (only ado is implemented). Use for 'commit', 'push', 'open PR', 'create PR'. Not for reviews (dx-pr-review) or replies (dx-pr-answer); the end-of-plan PR is dx-pr.
allowed-tools
[ "read", "edit", "search", "write", "agent", "ado/*" ]
argument-hint
[optional: commit message or 'pr' to also create PR]

03 SKILL.md 正文

Isolation check. This skill is meant to run in its own context (context: fork). If you can see the user's messages from before this skill was invoked, you are running inline (Copilot CLI ignores context: fork): do not run the steps below yourself. Start one subagent with your task/subagent tool, give it only this instruction — "Invoke the dx-core:dx-pr-commit skill with these arguments: <the arguments you were given, or none>. Run it fully and reply with its final report only." — then show the user that report and stop. If you cannot see earlier user messages, or your only earlier message is that instruction to invoke dx-core:dx-pr-commit (you are a fork or that subagent), continue below.

You handle git commits and Azure DevOps pull requests.

Provider check

Read scm.provider from .ai/config.yaml (missing means ado). Only ado is implemented: the steps below call the ADO MCP server (mcp__ado__*). If it is anything else (e.g. github), stop before any git push or MCP call and tell the user: "dx PR skills support only scm.provider: ado (found: <value>)."

Output discipline

You run in a forked context. Before emitting any chat output, determine whether you were invoked by the orchestrator (dx-agent-all) or standalone — see plugins/dx-core/shared/orchestration-check.md:

ORCHESTRATED=0
FLAG=".ai/run-context/orchestrating.flag"
if [ -f "$FLAG" ]; then
  AGE=$(( $(date +%s) - $(date -r "$FLAG" +%s) ))
  [ "$AGE" -lt 7200 ] && ORCHESTRATED=1
fi
  • If $ORCHESTRATED == 1 (orchestrator path): complete the commit (and PR if requested) and emit ONLY the ## Return block to chat.
  • If $ORCHESTRATED == 0 (standalone path): complete the commit (and PR if requested) AND emit the human-friendly summary marked <!-- standalone-only --> below, followed by the ## Return block at the very end.

Per-step progress lines during the run are allowed in both paths.

Before anything else, read these two files:

  • ../../shared/git-rules.md — all git/ADO conventions (base branch discovery, repo ID discovery, commit format, staging, rebase, PRs)
  • .ai/config.yaml — project config, preferences (Auto-Commit, Auto-PR)

Follow every rule in git-rules.md. The steps below assume you have read it.

Persona (optional)

If .ai/me.md exists, read it. Use it to shape PR titles and descriptions. Commit message format (#<ID> <imperative>) is a structural constraint and always wins. If .ai/me.md doesn't exist, use defaults.

1. Determine Intent

Parse the user's request and argument:

  • Commit only — default if no "pr" keyword
  • Commit + PR — if user says "pr", "pull request", "open pr", etc.
  • PR only — if changes are already committed and user just wants a PR

1. Gather Git Context

Run the context discovery script:

bash .ai/lib/gather-context.sh

This outputs CURRENT_BRANCH, BASE_BRANCH, and GITIGNORE_RULES. Use these values throughout — do NOT re-run discovery commands.

2. Setup

  1. Base branch — already discovered above (use BASE_BRANCH value). If unknown, fall back to git-rules.md probing.
  2. Discover repo ID — per git-rules.md
  3. Check branch safety — must be on feature/* or bugfix/* (check CURRENT_BRANCH above)

3. Extract ADO Work Item ID

Find it from (in priority order):

  1. User argument — if they passed an ID
  2. Branch name — extract digits from feature/#2416553-... or feature/2416553-... or bugfix/2416553-...
  3. Spec directory — check .ai/specs/<id>-*/ for the most recent spec
  4. Recent commits — parse git log -5 --oneline for #<digits> pattern

If no ID found, ask the user.

4. Rebase (if needed)

Per git-rules.md — fetch, check if behind, rebase. Never merge.

5. Stage Changes

Run git status. Stage files specifically per git-rules.md.

Identify YOUR changes only

Before staging, determine which files are actually yours vs came from the base branch:

# Files changed only on this branch (yours)
git diff origin/$BASE_BRANCH...HEAD --name-only

# Compare with git status to spot foreign files
git status --short

If git status shows files NOT in the git diff ...HEAD --name-only output, those came from a merge or rebase — do NOT stage them.

Stage rules

  • Only stage files that appear in YOUR diff
  • Files the user explicitly mentioned
  • If a spec directory exists, also stage implement.md status updates
  • Never stage files that only exist in git status but not in your branch diff

Present the staged files to the user for confirmation before committing.

6. Commit

Craft message per git-rules.md format: #<ADO-ID> <imperative description>

If the user provided a message in the argument, use it (prepend the #<ID> if missing).

Commit and verify with git log -1 --oneline.

6b. Orchestrated PR update (headless)

When $ORCHESTRATED == 1 (e.g. /dx-pr-answer applying fixes to a reviewer's open PR), the branch usually already has an Active PR and the intent is update it, not create a new one. After committing, check:

mcp__ado__repo_pull_request
  action: "list"
  repositoryId: "<repo ID>"
  sourceRefName: "refs/heads/<current-branch>"
  status: "Active"

If an Active PR exists, push the new commit to update it — no new PR, no prompt:

git push origin "$(git branch --show-current)" \
  || { git pull --rebase origin "$(git branch --show-current)" && git push origin "$(git branch --show-current)"; }

Pushing the source branch updates the existing PR automatically. Do not create a new PR and do not bare---force (only --force-with-lease, and only after an explicit rebase). Capture the PR URL/ID for the caller's ## Return block, then skip step 7.

If no Active PR exists, fall through: create one only if a PR was requested (the pr keyword), otherwise this was a commit-only run and you're done.

7. Create PR (if requested)

Only if the user asked for a PR.

7a. PR Pre-Flight Checks (per git-rules.md)

Run all pre-flight checks from git-rules.md before creating:

  1. Check for existing PR — if Active, show it and stop. If Abandoned, offer to reactivate.
  2. Check for empty diff — if no commits vs base branch, stop.
  3. Push branch — git push -u origin $(git branch --show-current). If rejected after rebase, use --force-with-lease.

7b. Create PR via ADO MCP

Use mcp__ado__repo_pull_request_write with action: "create" per git-rules.md:

  • repositoryId: auto-discovered
  • sourceRefName: refs/heads/<current-branch>
  • targetRefName: refs/heads/$BASE_BRANCH
  • title: #<ID> <short description> (under 70 chars)
  • description: Build from available context (share-plan.md, git log, diff stat). Use PR description template from git-rules.md.
  • workItems: <ADO-ID> to auto-link the work item

7c. Post-Creation Check

After creating the PR, verify merge status per git-rules.md. If conflicts detected, warn the user to rebase.

7d. Set Auto-Complete (optional)

If the user asks, use mcp__ado__repo_pull_request_write with action: "update" and autoComplete: true.

Examples

Simple commit

/dx-pr-commit

Discovers work item ID from branch name, stages your changes (not base branch files), commits with #2435084 add language selector component.

Commit with message

/dx-pr-commit fix null check in hero component

Uses your message, prepends #<ID>: #2435084 fix null check in hero component.

Commit and create PR

/dx-pr-commit pr

Commits, pushes, creates ADO PR targeting the configured base branch with work item linked.

Troubleshooting

"Not on a feature or bugfix branch"

Cause: You're on development, main, or another protected branch. Fix: Create a feature branch first: git checkout -b feature/<id>-<slug>.

Stages unexpected files from base branch

Cause: After rebase, files from the base branch appear in git status. Fix: The skill compares git status against git diff origin/<base>...HEAD --name-only to only stage YOUR changes.

PR creation fails — "active PR already exists"

Cause: An active PR already exists for this branch. Fix: The skill detects this and shows the existing PR URL. Update the existing PR instead.

Present Summary (standalone path only)

<!-- standalone-only — emit only when $ORCHESTRATED == 0 -->

When running standalone, emit:

## Commit complete

**<count> files** committed as `<SHA>` on `<branch>`.
<If PR was created:>
**PR:** <title>
**URL:** <PR web URL>

### Next steps:
- Push branch: `git push -u origin <branch>`
- Or run `/dx-pr` to create the PR (if not already created)

After commit (detailed form):

**Committed:** `#<ID> <message>`
**Files:** <count> files
**Hash:** `<short hash>`
**Branch:** <branch name>

After PR:

**PR #<pr-id>:** `<title>`
**Branch:** <source> → <$BASE_BRANCH>
**URL:** <PR web URL from ADO response>

When orchestrated ($ORCHESTRATED == 1), skip this section entirely and emit only the ## Return block.

Return

This skill runs in a forked context. It MUST end with a ## Return block per plugins/dx-core/shared/skill-return-contract.md.

Examples:

## Return
verdict: pass
summary: Committed 3 files as 26e7cb8 on feature/2490722-microsite; PR not created (auto-pr=false).
artifacts:
  - .ai/specs/2490722-microsite/commit-log.txt
next_action: open PR via printed URL
## Return
verdict: fail
summary: Commit aborted — pre-commit hook failed: lint-staged eslint no-shadow on token.
artifacts: []
next_action: fix lint error and re-run /dx-pr-commit

If a PR was created, include the PR URL in summary (truncated if needed) and the full URL in an artifact file.

04 同仓库更多 Skills