/project-toolkit:merge-resolverfrom project-toolkit
Resolves merge conflicts by analyzing git history and commit intent. Handles PR conflicts, branch conflicts, and session file conflicts with automated resolution for known patterns.
Ships in project-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Resolve merge conflicts by analyzing git history and commit intent.
# Resolve conflicts for a specific PR
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/resolve_pr_conflicts.py --pr-number 123 --branch-name "fix/my-feature" --target-branch "main"; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# Dry-run mode (no side effects)
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/resolve_pr_conflicts.py --pr-number 123 --branch-name "fix/test" --dry-run; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
| Trigger Phrase | Operation |
|---|---|
resolve merge conflicts | Auto-detect branch/PR and resolve |
fix conflicts on this branch | Context-aware conflict resolution |
PR has conflicts with main | Merge-based conflict resolution |
can't merge due to conflicts | Analyze and fix blocking conflicts |
resolve PR conflicts | Resolve conflicts for a specific PR number |
Run this self-check FIRST, before any context gathering, analysis, or plan. Conflict resolution requires shell execution: worktree creation, git merge, staging, commit, and git push. Without those tools you can only describe steps, never resolve anything.
| Step | Action | Verification |
|---|---|---|
| 0.1 | Confirm shell/Bash is available (git, worktree creation, git push) | A tool result in this run shows a shell command executed |
| 0.2 | If shell is unavailable: return immediately with status [BLOCKED], one-line reason, route execution back to the orchestrator, and STOP | No resolution plan, phase list, or report is produced |
If shell execution is unavailable, do NOT produce a step-by-step resolution plan. A plan reads as completed work and is the exact failure this precondition prevents. Return BLOCKED and route execution back to the orchestrator.
Completion rule (applies to every execution phase below): mark a phase complete ONLY when a tool result in this run proves it ran. A plan is not a completion. Never report "create worktree", "merge", "push", or "run gates" as complete from instructions alone.
| Step | Action | Verification |
|---|---|---|
| 1.1 | Fetch PR metadata via gh pr view | PR metadata displayed |
| 1.2 | Checkout PR branch | git branch --show-current matches |
| 1.3 | Attempt merge with base (--no-commit) | Conflict markers created |
| 1.4 | List conflicted files | git diff --name-only --diff-filter=U output |
| Step | Action | Verification |
|---|---|---|
| 2.1 | Classify files (auto-resolvable vs manual) | Classification logged |
| 2.2 | Auto-resolve known patterns (accept --theirs) | Files staged cleanly |
| 2.3 | For manual files: run git blame, analyze intent | Commit messages captured |
| 2.4 | Apply manual resolutions per decision framework | Conflict markers removed |
| 2.5 | Stage all resolved files | git diff --cached --check MERGE_HEAD clean |
| Step | Action | Verification |
|---|---|---|
| 3.1 | Verify no remaining conflict markers and no unmerged files | ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/verify_no_conflict_markers.py; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) exits 0 |
| 3.2 | Run session protocol validator | validate_session_json.py exits 0 |
| 3.3 | Run markdown lint | npx markdownlint-cli2 exits 0 |
| 3.4 | Commit merge resolution | Commit SHA recorded |
| 3.5 | Push to remote | Remote ref updated |
Classify each side's changes to determine resolution priority.
| Type | Indicators | Priority |
|---|---|---|
| Security | "security", "vuln", "CVE" in message | Highest (1) |
| Bugfix | "fix", "bug", "patch", "hotfix" in message | High (2) |
| Feature | "feat", "add", "implement"; new functionality | Medium (3) |
| Refactor | "refactor", "cleanup", "rename"; no behavior change | Medium (3) |
| Style | "style", "format", "lint"; whitespace only | Lowest (4) |
Priority is a strict priority hierarchy: Security (1) > Bugfix (2) > Feature/Refactor (3) > Style (4). Intent priority is the PRIMARY sort key when two sides conflict. A Security change is NEVER dropped: if it cannot be cleanly combined with the other side, Security wins and the lower-priority change is reapplied around it. Recency and test coverage are tiebreakers ONLY between two changes in the same priority tier; they never let a lower-tier change beat a higher-tier one.
| Scenario | Resolution |
|---|---|
| Same intent, compatible changes | Merge both |
| Bugfix vs feature | Bugfix wins; integrate feature around it |
| Security vs anything else | Security wins and is preserved; reapply the other change around the security fix (never drop the security change) |
| Higher-priority vs lower-priority tier (e.g. Bugfix vs Refactor) | Higher-priority wins; integrate the lower-priority change around it |
| Same-tier conflict / Conflicting logic | Combine if possible; else break the tie by better-tested, then more recent |
| Style vs Style conflicts | Accept either; prefer consistency with surrounding code |
| Deletions vs modifications | Investigate why; deletion usually intentional |
CRITICAL: Session files from main are immutable audit records.
| Action | Correct | Wrong |
|---|---|---|
| Session file conflict | Accept --theirs, rename ours with a distinguishing suffix | Accept --ours (alters main's record) |
| Same-numbered session (add/add) | Keep both; rename ours with a suffix, keep the number | Merge both contents into one file |
Rename, never content-merge. An add/add conflict on an append-only evidence artifact (session logs .project-toolkit/sessions/*, QA reports .project-toolkit/qa/*, retrospectives .project-toolkit/retrospective/*) means two branches wrote different records to the same filename. Keep both files: accept the base branch version at the original name, rename the head branch version with a distinguishing suffix (keep the session number, append an issue or topic slug), and update any index or report that references the renamed file. Never merge the two contents into one file. Merging both sessions' prose into one file would destroy two accurate records to produce one false one.
See references/strategies.md for the full session file resolution workflow.
The script auto-resolves these by accepting the target branch version.
Add/add caveat: accept-theirs alone is wrong for an add/add conflict on an append-only evidence artifact (.project-toolkit/sessions/*, .project-toolkit/qa/*, .project-toolkit/retrospective/*), because it silently discards the head branch's own record. resolve_pr_conflicts.py detects this case (no common-ancestor stage on the conflicted path) and refuses to auto-resolve it: the file lands in files_blocked and the run exits 1 instead of pushing. Resolve it manually: accept the base branch version at the original name, then restore the head branch version under a renamed path per the Session File Rules above.
| Pattern | Rationale |
|---|---|
.project-toolkit/sessions/*.json | Session files from main are immutable audit records |
.agents/* | Agent inputs, main is authoritative |
.project-toolkit/* | Session artifacts, constantly changing |
.serena/* | Serena memories, auto-generated |
.claude/skills/*/*.md | Skill definitions, main is authoritative |
.claude/agents/* | Agent definitions, main is authoritative |
templates/* | Template files, main is authoritative |
src/copilot-cli/* | Platform agent definitions |
src/vs-code-agents/* | Platform agent definitions |
src/claude/* | Platform agent definitions |
.github/agents/* | GitHub agent configs |
.github/prompts/* | GitHub prompts |
package-lock.json, yarn.lock, pnpm-lock.yaml | Lock files; regenerate from main |
*/.claude-plugin/plugin.json is NOT accept-theirs. When the two sides differ
only in version, the script resolves them without manual handling:
version: the merged manifest carries none. ADR-092
deleted the field from all three manifests, and the version-field gate
(validate_plugin_version_bump.py) fails when one carries it.
This is the shape every branch opened before ADR-092 hits when it merges a
fixed main.0.5.168 vs theirs 0.5.169 resolves to 0.5.170). Retained
only for branches that predate the deletion on both sides; the merged
manifest then still carries a field the gate rejects, so delete it before
pushing.Any other field difference, or a prerelease/build-metadata version, blocks auto-resolution and requires manual handling.
Resolves PR merge conflicts with auto-resolution for known file patterns.
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/resolve_pr_conflicts.py --pr-number <number> --branch-name <name> [--target-branch <branch>] [--worktree-base-path <path>] [--dry-run]; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Conflicts resolved successfully (and, if not --dry-run, pushed) |
| 1 | Non-auto-resolvable conflicts remain |
When running with --dry-run, exit code 0 indicates that conflicts were fully auto-resolvable and the changes would have been pushed, but no changes were made because of dry-run mode.
Output format (JSON):
{
"success": true,
"message": "Successfully resolved conflicts for PR #<number>",
"files_resolved": [".agents/governance/PROJECT-CONSTRAINTS.md"],
"files_blocked": []
}
Security: Branch name validation prevents command injection. Worktree path validation prevents path traversal.
Verifies that resolution is complete: no still-unmerged (UU) files and no leftover conflict markers in any in-flight change. Replaces the broad git grep -n '<<<<<<<' -- check, which false-fails on intentional fenced examples in committed docs and Serena memories.
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/verify_no_conflict_markers.py [--cwd PATH] [--json]; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Uses git diff --cached --check MERGE_HEAD when a merge is in progress (MERGE_HEAD present) to avoid false positives from whitespace already in the incoming branch. Falls back to git diff HEAD --check outside merge state. Both forms use git diff --name-only --diff-filter=U to catch still-unmerged files.
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Clean: no unmerged files and no leftover conflict markers |
| 1 | Resolution incomplete: markers remain or unmerged files exist |
| 2 | Usage error: not inside a git working tree |
| 3 | External error: a git command failed unexpectedly |
| Anti-Pattern | Why It Fails | Instead |
|---|---|---|
| Alter session files from main | Breaks audit trail (immutable records) | Accept --theirs, then rename our session file with a distinguishing suffix |
| Content-merge an add/add session-log conflict | Destroys two accurate records to produce one false one | Keep both files; rename ours with a suffix; update references |
| Push without session validation | CI blocks with MUST violations | Run validate_session_json.py first |
| Manual edit of generated files | Lost on regeneration | Edit template, run generator |
Accept --ours for HANDOFF.md | Branch version often stale | Accept --theirs (main is canonical) |
| Merge lock files manually | JSON corruption, broken deps | Accept base, regenerate with npm install |
Skip git blame analysis | Wrong intent inference | Always check commit messages |
| Resolve before fetching PR context | Missing context, wrong base | Always gh pr view first |
Forget to stage .agents/ | Dirty worktree CI failure | Include all .agents/ changes |
| Criterion | Evidence |
|---|---|
| All conflicts resolved | python3 -c "import subprocess, sys; r=subprocess.run(['git','diff','--name-only','--diff-filter=U'],capture_output=True,text=True,encoding='utf-8',errors='replace'); u=[l for l in r.stdout.splitlines() if l.strip()]; sys.exit(1 if u else 0)" exits 0 (--diff-filter=U catches every unmerged state -- UU, AA, DU -- not only UU) |
| No merge markers remain | ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/verify_no_conflict_markers.py; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) exits 0 (during merge: checks staged vs MERGE_HEAD AND working tree vs index; outside merge: checks working tree+index vs HEAD; ignores intentional fenced examples in committed docs) |
| Any opted-in session log valid | validate_session_json.py exits 0 |
| Markdown lint passes | npx markdownlint-cli2 exits 0 |
| Push successful | Remote ref updated |
git add)git diff --name-only --diff-filter=U empty (catches every unmerged state, not only UU)Add patterns to AUTO_RESOLVABLE_PATTERNS in resolve_pr_conflicts.py.
Add entries in references/strategies.md for domain-specific conflicts.
- name: Resolve conflicts
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_REF: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
run: |
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/merge-resolver/scripts/resolve_pr_conflicts.py --pr-number "$PR_NUMBER" --branch-name "$HEAD_REF" --target-branch "$BASE_REF"; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
.claude/rules/session-logs.md: Optional log and continuity requirementsSession logs are historical records once created. A malformed staged or explicitly supplied log still fails validation.
# Validate an existing log only when one is part of the merge.
uv run python scripts/validate_session_json.py ".project-toolkit/sessions/<log>.json"
| Req | Step | Status |
|---|---|---|
| MUST | Update Serena memory (cross-session context) | [ ] |
| MUST | Run markdown lint | [ ] |
| MUST | Route to qa agent (feature implementation) | [ ] |
| MUST | Update the per-issue handoff, when work remains open | [ ] |
| Error | Cause | Fix |
|---|---|---|
E_TEMPLATE_DRIFT | Existing log checklist outdated | Repair from the retained schema and optional appendix |
E_QA_EVIDENCE | QA row checked but no report path | Add QA report or use "SKIPPED: docs-only" |
E_DIRTY_WORKTREE | Uncommitted changes | Stage and commit all files including .agents/ |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
merge-conflicts, git-workflow, pr-resolution, branch-conflicts
npx claudepluginhub rjmurillo/ai-agents --plugin project-toolkit105 skills in this plugin
/adr-generatorCreate comprehensive Architectural Decision Records (ADRs). Researches the destination directory to detect existing template conventions, gathers context, determines next ADR number, generates the ADR, validates completeness, and saves. Supports multiple ADR formats (MADR, Nygard, Alexandrian, project canonical). Use when documenting technical decisions, creating new ADR files, or capturing rationale so future readers can revisit a choice. Use when you say "write an ADR", "document this decision", "document these design choices", "record why we chose this", "capture the rationale", or "for future maintainers", or when creating an ADR-like markdown file under docs/decisions/, docs/adr/, docs/architecture/, architecture/decisions/, or .project-toolkit/architecture/. Do NOT use to debate or review an existing ADR (use adr-review)./adr-reviewMulti-agent debate orchestration for Architecture Decision Records. Automatically triggers on ADR create/edit/delete. Coordinates architect, critic, independent-thinker, security, analyst, and high-level-advisor agents in structured debate rounds until consensus. Use when you say "review this ADR", when an ADR is created/edited/deleted, or when reviewing, accepting, or updating a decision file under .project-toolkit/architecture/, docs/architecture/, docs/decisions/, docs/adr/, or architecture/decisions/, including intent like "review this decision record" or "check this rationale for future maintainers". Do NOT use to author a new ADR (use adr-generator)./agent-harness-referenceField reference for Claude Code and GitHub Copilot CLI hook contracts. Covers hook locations, events, matchers, payloads, decisions, exit codes, timeouts, plugin roots, and cloud limits with official URLs and versioned probes. Use for `harness contract`, `copilot cli hook behavior`, `hook payload format`, `stale plugin root`, `Errno 2 _dispatch.py`, or before changing cross-harness hooks. Do NOT use to run the porting campaign (in the ai-agents repository, use `ai-agents-portability-campaign`)./ai-agents-external-claimsVerify external, vendor, and third-party claims (numbers, attributions, structure) against authoritative primary sources before they land in a repo artifact or external deliverable. Covers stake-holding sources, round-number tells, citation-chain drift, and the walk-the-gate-or-file-conservative discipline. Use when you say `verify an external claim`, `check a vendor number`, `is this stat real`, `validate a third-party citation`. Do NOT use for running an experiment (use `ai-agents-research-methodology` in the ai-agents repository) or command-injection scanning (use `security-scan`)./analysis-provenanceIdentify code ownership before modifying validators or linters. Checks file headers for provenance indicators, reviews documentation, and determines provenance as UPSTREAM, LOCAL, VENDOR, or UNKNOWN. Prevents accidental modification of upstream tools./analyzeSystematic multi-step codebase analysis producing prioritized findings with file-line evidence. Covers architecture reviews, security assessments, and code quality evaluations through guided exploration, investigation planning, and synthesis. Use when you say "analyze this codebase", "run security assessment", "architecture review of this system", "find code smells", or "review code quality" across multiple files. Do NOT use for single-file maintainability scoring (use code-qualities-assessment) or CWE-78 injection pattern scanning (use security-scan).Other plugins' skills for the same job