Install
openclaw skills install cross-branch-auditPerforms pre-migration audit for cross-branch module or feature migration by analyzing commits, dependencies, conflict risks, and generating detailed interac...
openclaw skills install cross-branch-auditThis skill performs comprehensive pre-migration audits before cross-branch code migration. It analyzes git history, diff content, and code semantics to automatically identify external dependencies, evaluate migration risks, and generate structured audit reports.
Applicable to any language, any framework, any project type.
Important: Generate all output (reports, suggestions, checklists) in the user's preferred language. If the user communicates in Chinese, output in Chinese. If in English, output in English.
git merged — need to precisely identify migration scopeUse when: Migrating a complete directory/module with clear boundaries.
Input:
Characteristics:
Use when: Migrating a feature whose code is scattered across multiple directories, composed of multiple commits.
Input (any combination):
Characteristics:
Use when: Primarily module-path based, but need to also capture module-external related changes.
Input:
Before starting the audit, automatically detect the project type to use correct dependency analysis strategies:
# Detect project type
ls -la # Check root directory structure
# Identify by characteristic files:
# - build.gradle / settings.gradle → Android/Java/Kotlin (Gradle)
# - pom.xml → Java/Kotlin (Maven)
# - package.json → JavaScript/TypeScript (Node.js)
# - go.mod → Go
# - Cargo.toml → Rust
# - requirements.txt / setup.py / pyproject.toml → Python
# - Podfile / *.xcodeproj → iOS (Swift/ObjC)
# - CMakeLists.txt → C/C++
# - *.sln / *.csproj → C# (.NET)
# - mix.exs → Elixir
# - Gemfile → Ruby
Also detect multi-channel/multi-flavor structure:
# Check for flavor/variant structure (Android)
grep -r "productFlavors" --include="*.gradle" . | head -5
# Check for multi-environment config (Node.js)
ls .env* 2>/dev/null
# Check for multiple targets (iOS)
grep -c "target" *.xcodeproj/project.pbxproj 2>/dev/null
Record project type and multi-channel structure for subsequent steps.
Confirm the following with the user:
Required parameters:
Mode-specific parameters:
| Mode | Parameters to confirm |
|---|---|
| A (Module Path) | Module path(s), e.g., src/audio/, lib/player/ |
| B (Feature) | Commit list / keywords / time range + author / Issue ID |
| C (Hybrid) | Module path + feature keywords |
Optional parameters:
test/, docs/)# Get merge-base of two branches
git merge-base origin/<source-branch> origin/<target-branch>
# Get all commits on source branch for the target module (exclude merges)
git log <start-commit>..origin/<source-branch> --oneline --no-merges -- <module-path-1> <module-path-2> ...
Execute the following strategies in order, merge and deduplicate:
Strategy 1: Exact commit list (if user provided)
git log --oneline <sha1> <sha2> <sha3> ...
Strategy 2: Keyword search (AI auto-expands keyword variants)
# User's original keyword
git log <start>..<source> --oneline --no-merges --grep="<keyword>"
# AI auto-expanded variants (translations, abbreviations, related concepts)
git log <start>..<source> --oneline --no-merges --grep="<variant1>"
git log <start>..<source> --oneline --no-merges --grep="<variant2>"
# ... merge and deduplicate
Keyword expansion rules:
Strategy 3: Time range + author
git log <start>..<source> --oneline --no-merges --author="<author>" --since="<start-date>" --until="<end-date>"
Strategy 4: Issue/TAPD ID search
git log <start>..<source> --oneline --no-merges --grep="<issue-id>"
Strategy 5: File path reverse tracking
# Extract files from known commits
git diff-tree --no-commit-id -r --name-only <known-sha>
# Reverse-find other commits that modified these files
git log <start>..<source> --oneline --no-merges -- <file1> <file2> ...
Strategy 6: Code reference chain analysis
# From known core classes/functions, find all files that reference them
grep -rn "<CoreClassName>" --include="*.<ext>" . | grep -v build | grep -v node_modules
# Find commits that modified these referencing files
git log <start>..<source> --oneline --no-merges -- <referencing-files>
After merging and deduplication, present to user for confirmation:
I found N related commits through the following strategies:
- Keyword search ("payment", "order", "checkout"): found X
- File reverse tracking: additionally found Y
- Code reference chain: additionally found Z
Complete list:
1. abc1234 - feat: add payment processing
2. def5678 - fix: fix order validation
...
Please confirm if anything is missing. Provide additional info if needed.
Execute Mode A path scan first, then Mode B keyword search, merge and deduplicate.
For each commit in the determined range, check if it involves files outside the migration scope:
for sha in <commit-list>; do
all_files=$(git diff-tree --no-commit-id -r --name-only "$sha")
external_files=$(echo "$all_files" | grep -v "^<module-path-pattern>")
if [ -n "$external_files" ]; then
echo "=== $sha ==="
echo "$external_files"
fi
done
For Feature Mode, the definition of "external files" needs dynamic determination:
For each commit involving external files, run git show <sha> to examine diff content. Apply these universal criteria:
| Criterion | Classification | Explanation |
|---|---|---|
| External file adds symbols referenced by migrated code (class/function/variable/type) | Strong dependency | Migrated code compilation/runtime depends on this change |
| External file modifies function signature called by migrated code | Strong dependency | Signature mismatch causes compilation failure |
| External file references symbols within migration scope | Strong dependency | External code integrates migrated functionality |
| External file changes have no reference relationship with migrated code | Weak dependency | Unrelated changes in the same commit |
| External file is a build configuration file | Infrastructure | Module registration/dependency declaration |
| External file is a test file | Test dependency | Optional migration |
| External file is a resource file (strings/drawable/layout etc.) | Resource dependency | Check for duplicate definitions |
Based on project type detected in Step 0, use corresponding reference identification methods:
| Project Type | Reference Identification Method |
|---|---|
| Java/Kotlin | import statements, class inheritance, interface implementation, method calls, constructor parameters |
| JavaScript/TypeScript | import/require statements, export declarations |
| Python | import/from...import statements |
| Go | import statements, package references |
| C/C++ | #include directives, function declarations/definitions |
| Rust | use/mod statements, extern crate |
| Swift/ObjC | import/#import statements |
| Ruby | require/require_relative statements |
| C# | using statements, namespace references |
| Generic | Filename/path string references in code |
For each strongly-dependent external file, evaluate conflict risk:
# Get diff statistics between two branches
git diff origin/<target-branch> origin/<source-branch> --stat -- <file>
# Get file total lines (evaluate complexity)
wc -l <file>
# Check if target branch also modified this file (bidirectional = high conflict probability)
git log <start>..origin/<target-branch> --oneline --no-merges -- <file>
# Check line ending format (CR/LF/CRLF)
file <file>
Risk level determination:
During the audit, additionally check these universal common pitfalls:
file <path> — check for "CR line terminators" (Windows/Mac mixed)
After migrating a module, must check if all third-party libraries imported by the module are declared in the target branch's build configuration:
# Example: Java/Kotlin project
grep -rh "^import " <module-path> --include="*.java" --include="*.kt" | \
grep -v "<project-package>" | grep -v "android\|java\|kotlin" | sort -u
# Compare with build.gradle / pom.xml dependency declarations
⚠️ Transitive dependency chains may differ between branches. Libraries obtained through transitive dependencies in the source branch may not be available in the target branch. Must explicitly declare all directly-used dependencies.
| Project Type | Check Items |
|---|---|
| Gradle (Java/Android/Kotlin) | build.gradle dependencies, settings.gradle module registration, flavor config, local aar/jar dependencies, AGP library module restrictions (fileTree cannot include .aar) |
| Maven (Java) | pom.xml dependencies, module structure, parent pom version |
| npm/yarn (JS/TS) | package.json dependency versions, lock file differences, workspace config |
| Go | go.mod dependency versions, replace directives |
| Cargo (Rust) | Cargo.toml dependency versions, workspace members |
| pip (Python) | requirements.txt versions, setup.py/pyproject.toml config |
| CocoaPods (iOS) | Podfile dependencies, .xcodeproj config |
| CMake (C/C++) | CMakeLists.txt targets and link libraries |
| .NET (C#) | .csproj references, NuGet package versions |
Generate an interactive HTML report, saved to the project's docs/ directory (create if not exists).
Report contents:
Overview Statistics
Commit Discovery Process (Feature Mode only)
⚠️ Critical Risk Alert Panel (pinned to top)
Strong Dependency Commit List
External File Risk Matrix
Special Situation Warnings
Suggested Migration Strategy
Post-Cherry-pick Checklist (printable)
Report interactive features:
Based on audit results, provide phased migration plan:
Phase 0: Infrastructure
- Build config files (build.gradle / package.json / go.mod etc.)
- Module registration/declaration
- New dependency modules (e.g., model layer)
✅ Compile verification immediately after completion
Phase 1: Core Code Migration
- Approach A (whole-module overwrite): Directly overwrite target branch with source branch's module directory
- Confirm target branch module directory has no unique code before overwriting
- Check transitive dependencies after overwriting
- Approach B (per-commit cherry-pick): Cherry-pick in chronological order
✅ Compile verification immediately after completion
Phase 2: Low-Risk External Dependencies
- New files (direct copy)
- Append-only changes (cherry-pick without conflict)
- Files unmodified in target branch
✅ Compile verification immediately after completion
Phase 3: Medium-Risk External Dependencies
- Per-commit cherry-pick, manually resolve minor conflicts
- Or manually merge differences
- Execute checklist after each cherry-pick
✅ Compile verification immediately after completion
Phase 4: High-Risk External Dependencies
- Manual handling
- Keep target branch version + manually add necessary changes
- Do NOT cherry-pick large files as a whole
- CR line ending files need format conversion before editing
✅ Compile verification immediately after completion
Phase 5: Verification
- Compilation verification
- Unit tests
- Functional tests
- Regression tests
docs/migration-audit-<timestamp>.html| File Type | Recommended Strategy |
|---|---|
| Internal file conflicts (within migration scope) | Directly overwrite with source branch's final version |
| External file conflicts | Manually resolve, preserve target branch's unique logic |
| Large files (>5000 lines) | Do NOT cherry-pick as whole, keep target branch version + manually add |
| Build config files | Manually merge, do NOT overwrite target branch's config |
| Binary files | Directly overwrite with source branch version (cannot merge) |
| Test files | Optional migration, lowest priority |
| Resource files (strings.xml etc.) | Check for duplicate definitions after cherry-pick |
| CR line ending files | tr '\r' '\n' convert → edit → tr '\n' '\r' convert back |
After each cherry-pick, AI must remind user to perform these checks:
grep -rn "<<<<<<" --include="*.<ext>" .
Proactively flag these risks in the report:
api(name:'xxx', ext:'aar') in moduleWhen using Feature Mode, AI must:
When user encounters compilation errors or runtime issues during migration, AI should:
User: I need to migrate the payment module from feature/payment branch to main branch, help me do an audit
AI: OK, I'll perform a cross-branch module migration audit. Please confirm:
feature/paymentmainsrc/modules/payment/)User: I need to migrate the "user authentication refactoring" feature from develop branch to release/v2.0
AI: OK, I'll perform a feature-level migration audit. This feature may span multiple directories and commits. I need to first locate all related commits.
Please provide (the more the better):
I'll use multi-strategy cross-validation to find all related commits, then ask you to confirm.
User: Migrate src/audio/ module, but it also depends on some shared component changes
AI: OK, I'll use Hybrid Mode:
src/audio/ pathPlease confirm source and target branch names?
User: After cherry-pick, compilation error: "actual and formal argument lists differ in length"
AI: This is a typical interface signature difference issue. Let me check the signature differences between the two branches... (Compare interface definitions between branches, provide specific fix plan)
Report structure:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cross-Branch Migration Audit Report</title>
<!-- Inline CSS: Modern clean design, dark/light mode support -->
<!-- Inline JS: Filter, search, expand/collapse, export CSV -->
</head>
<body>
<!-- 0. Critical Risk Alert Panel (pinned top, red/orange background) -->
<!-- 1. Report header: project name, source branch, target branch, generation time -->
<!-- 2. Overview statistics cards (commit count, dependency count, risk distribution, estimated workload) -->
<!-- 3. Commit discovery process (Feature Mode) -->
<!-- 4. Risk matrix table (filterable, sortable) -->
<!-- 5. Commit detail list (expandable diff) -->
<!-- 6. Special situation warning panel -->
<!-- 7. Migration strategy suggestions (phased) -->
<!-- 8. Post-cherry-pick checklist (printable) -->
<!-- 9. Action buttons (export CSV, export Markdown, print) -->
</body>
</html>
Report style requirements: