Project 33: Multi-Repository Refactoring Agent

Project 33: Multi-Repository Refactoring Agent

Build an agent that coordinates refactoring across multiple repositories - renaming interfaces, updating imports, and ensuring consistency across your entire organizationโ€™s codebase with proper dependency ordering and atomic changes.

Quick Reference

Attribute Value
Difficulty Expert (Level 4)
Time Estimate 1 month+
Primary Language TypeScript
Alternative Languages Python, Go
Prerequisites Projects 7, 10, 14, 25 (GitHub MCP, Subagents, Checkpoints, Code Review)
Key Topics Dependency graphs, parallel processing, atomic changes, PR coordination, rollback strategies
Kiro CLI Concepts Subagent orchestration, GitHub MCP, checkpoints, hooks, parallel execution
Main Book Reference โ€œMonorepo Developmentโ€ by Ben Awad; โ€œPro Gitโ€ by Scott Chacon

1. Learning Objectives

By completing this project, you will:

  1. Master cross-repository dependency mapping: Build dependency graphs across multiple repos and understand topological ordering
  2. Implement subagent orchestration patterns: Coordinate parallel agents working on different repositories with proper synchronization
  3. Design atomic multi-repo changes: Create change sets that can be applied or rolled back as a unit across repositories
  4. Build sophisticated PR coordination: Create linked pull requests with proper dependencies and merge ordering
  5. Implement enterprise-grade rollback: Handle failures gracefully with checkpoint-based recovery across distributed systems

2. Deep Theoretical Foundation

2.1 The Multi-Repository Challenge

Large organizations often have polyrepo architectures where code is spread across many repositories. Making consistent changes across these repos is one of software engineeringโ€™s hardest problems.

                    THE POLYREPO CHALLENGE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   ORGANIZATION CODEBASE                                                  โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
    โ”‚   โ”‚ @org/core-types โ”‚   โ”‚ @org/user-api   โ”‚   โ”‚ @org/web-client โ”‚       โ”‚
    โ”‚   โ”‚                 โ”‚   โ”‚                 โ”‚   โ”‚                 โ”‚       โ”‚
    โ”‚   โ”‚ interface       โ”‚   โ”‚ import {        โ”‚   โ”‚ import {        โ”‚       โ”‚
    โ”‚   โ”‚   UserService { โ”‚โ”€โ”€โ–ถโ”‚   UserService   โ”‚โ”€โ”€โ–ถโ”‚   UserService   โ”‚       โ”‚
    โ”‚   โ”‚   ...           โ”‚   โ”‚ } from         โ”‚   โ”‚ } from         โ”‚       โ”‚
    โ”‚   โ”‚ }               โ”‚   โ”‚ '@org/core'     โ”‚   โ”‚ '@org/user-api' โ”‚       โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
    โ”‚          โ”‚                     โ”‚                     โ”‚                   โ”‚
    โ”‚          โ”‚                     โ”‚                     โ”‚                   โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
    โ”‚   โ”‚ 3 files     โ”‚       โ”‚ 7 files     โ”‚       โ”‚ 15 files    โ”‚           โ”‚
    โ”‚   โ”‚ 150 LOC     โ”‚       โ”‚ 2,500 LOC   โ”‚       โ”‚ 8,000 LOC   โ”‚           โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   THE PROBLEM: Rename UserService โ†’ AccountService                      โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Manual approach:                                                       โ”‚
    โ”‚   1. Update @org/core-types (wait for CI)                               โ”‚
    โ”‚   2. Publish new version (wait for npm)                                 โ”‚
    โ”‚   3. Update @org/user-api to use new version (wait for CI)              โ”‚
    โ”‚   4. Publish @org/user-api (wait for npm)                               โ”‚
    โ”‚   5. Update @org/web-client (wait for CI)                               โ”‚
    โ”‚   6. Repeat for ALL dependent repos...                                  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Time: Days to weeks                                                   โ”‚
    โ”‚   Risk: Inconsistent state during migration                             โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.2 Dependency Graph Theory

Understanding dependency graphs is fundamental to multi-repo refactoring. From โ€œAlgorithmsโ€ (Sedgewick, Ch. 4):

                    DEPENDENCY GRAPH FUNDAMENTALS

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   DIRECTED ACYCLIC GRAPH (DAG)                                          โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   @org/core-types (no dependencies - ROOT)                              โ”‚
    โ”‚           โ”‚                                                              โ”‚
    โ”‚           โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                     โ”‚
    โ”‚           โ”‚                       โ”‚                                     โ”‚
    โ”‚           โ–ผ                       โ–ผ                                     โ”‚
    โ”‚   @org/user-api            @org/auth-service                            โ”‚
    โ”‚           โ”‚                       โ”‚                                     โ”‚
    โ”‚           โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                   โ”‚
    โ”‚           โ”‚                       โ”‚                 โ”‚                   โ”‚
    โ”‚           โ–ผ                       โ–ผ                 โ–ผ                   โ”‚
    โ”‚   @org/web-client         @org/mobile-app    @org/admin-dashboard       โ”‚
    โ”‚                                                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   TOPOLOGICAL SORT: Processing order that respects dependencies         โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Level 0: @org/core-types         (process first)                      โ”‚
    โ”‚   Level 1: @org/user-api, @org/auth-service                             โ”‚
    โ”‚   Level 2: @org/web-client, @org/mobile-app, @org/admin-dashboard       โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Key insight: Repos at the same level can be processed in PARALLEL    โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   CRITICAL PATH ANALYSIS                                                โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   The critical path is the longest path through the dependency graph.   โ”‚
    โ”‚   It determines the minimum time to complete the refactoring.           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Critical path: core-types โ†’ user-api โ†’ web-client                     โ”‚
    โ”‚   Length: 3 levels (cannot be parallelized)                             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Non-critical: auth-service โ†’ mobile-app (can parallel with above)     โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.3 The Subagent Orchestration Pattern

For multi-repo work, a single agent is insufficient. We need coordinated subagents:

                    SUBAGENT ORCHESTRATION ARCHITECTURE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚                        ORCHESTRATOR AGENT                               โ”‚
    โ”‚                        โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  Responsibilities:                                               โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Parse user request                                           โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Build dependency graph                                       โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Determine processing order                                   โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Spawn and coordinate subagents                               โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Aggregate results                                            โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Handle failures and rollback                                 โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”‚
    โ”‚           โ”‚                  โ”‚                  โ”‚                       โ”‚
    โ”‚           โ–ผ                  โ–ผ                  โ–ผ                       โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
    โ”‚   โ”‚  SUBAGENT 1   โ”‚  โ”‚  SUBAGENT 2   โ”‚  โ”‚  SUBAGENT 3   โ”‚              โ”‚
    โ”‚   โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚  โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚  โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚              โ”‚
    โ”‚   โ”‚               โ”‚  โ”‚               โ”‚  โ”‚               โ”‚              โ”‚
    โ”‚   โ”‚  Target:      โ”‚  โ”‚  Target:      โ”‚  โ”‚  Target:      โ”‚              โ”‚
    โ”‚   โ”‚  core-types   โ”‚  โ”‚  user-api     โ”‚  โ”‚  auth-service โ”‚              โ”‚
    โ”‚   โ”‚               โ”‚  โ”‚               โ”‚  โ”‚               โ”‚              โ”‚
    โ”‚   โ”‚  Status:      โ”‚  โ”‚  Status:      โ”‚  โ”‚  Status:      โ”‚              โ”‚
    โ”‚   โ”‚  โœ“ Complete   โ”‚  โ”‚  ~ Running    โ”‚  โ”‚  โธ Waiting    โ”‚              โ”‚
    โ”‚   โ”‚               โ”‚  โ”‚               โ”‚  โ”‚               โ”‚              โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
    โ”‚                                                                          โ”‚
    โ”‚                        SYNCHRONIZATION BARRIER                          โ”‚
    โ”‚                        โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Level 0 complete โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ   โ”‚
    โ”‚   Level 1 agents spawned                                                โ”‚
    โ”‚   Level 1 complete โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ   โ”‚
    โ”‚   Level 2 agents spawned                                                โ”‚
    โ”‚   ...                                                                   โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.4 Atomic Change Sets and Two-Phase Commit

To ensure consistency, changes must be applied atomically. This pattern comes from distributed database theory:

                    TWO-PHASE COMMIT FOR MULTI-REPO CHANGES

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 1: PREPARE                                                       โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Orchestrator: "Prepare to rename UserService โ†’ AccountService"       โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚ core-types  โ”‚  โ”‚ user-api    โ”‚  โ”‚ auth-serviceโ”‚  โ”‚ web-client  โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Create      โ”‚  โ”‚ Create      โ”‚  โ”‚ Create      โ”‚  โ”‚ Create      โ”‚   โ”‚
    โ”‚   โ”‚ branch      โ”‚  โ”‚ branch      โ”‚  โ”‚ branch      โ”‚  โ”‚ branch      โ”‚   โ”‚
    โ”‚   โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Apply       โ”‚  โ”‚ Apply       โ”‚  โ”‚ Apply       โ”‚  โ”‚ Apply       โ”‚   โ”‚
    โ”‚   โ”‚ changes     โ”‚  โ”‚ changes     โ”‚  โ”‚ changes     โ”‚  โ”‚ changes     โ”‚   โ”‚
    โ”‚   โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Run tests   โ”‚  โ”‚ Run tests   โ”‚  โ”‚ Run tests   โ”‚  โ”‚ Run tests   โ”‚   โ”‚
    โ”‚   โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ“           โ”‚  โ”‚ โœ— FAIL      โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ VOTE: YES   โ”‚  โ”‚ VOTE: YES   โ”‚  โ”‚ VOTE: YES   โ”‚  โ”‚ VOTE: NO    โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   DECISION: One "NO" vote โ†’ ABORT                                       โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 2A: ABORT (if any failures)                                     โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Orchestrator: "Abort - delete all branches"                           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚ core-types  โ”‚  โ”‚ user-api    โ”‚  โ”‚ auth-serviceโ”‚  โ”‚ web-client  โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Delete      โ”‚  โ”‚ Delete      โ”‚  โ”‚ Delete      โ”‚  โ”‚ Delete      โ”‚   โ”‚
    โ”‚   โ”‚ branch      โ”‚  โ”‚ branch      โ”‚  โ”‚ branch      โ”‚  โ”‚ branch      โ”‚   โ”‚
    โ”‚   โ”‚ โœ“ Rolled    โ”‚  โ”‚ โœ“ Rolled    โ”‚  โ”‚ โœ“ Rolled    โ”‚  โ”‚ โœ“ Rolled    โ”‚   โ”‚
    โ”‚   โ”‚   back      โ”‚  โ”‚   back      โ”‚  โ”‚   back      โ”‚  โ”‚   back      โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 2B: COMMIT (if all success)                                     โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Orchestrator: "Commit - create PRs in dependency order"               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚ core-types  โ”‚  โ”‚ user-api    โ”‚  โ”‚ auth-serviceโ”‚  โ”‚ web-client  โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Create PR   โ”‚  โ”‚ Create PR   โ”‚  โ”‚ Create PR   โ”‚  โ”‚ Create PR   โ”‚   โ”‚
    โ”‚   โ”‚ #101        โ”‚  โ”‚ #234        โ”‚  โ”‚ #567        โ”‚  โ”‚ #890        โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚   โ”‚
    โ”‚   โ”‚ Deps: none  โ”‚  โ”‚ Deps: #101  โ”‚  โ”‚ Deps: #101  โ”‚  โ”‚ Deps: #234  โ”‚   โ”‚
    โ”‚   โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚ Deps: #567  โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.5 Handling the Diamond Dependency Problem

A common challenge in multi-repo refactoring is the diamond dependency:

                    THE DIAMOND DEPENDENCY PROBLEM

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚                        @org/core-types                                   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                โ”‚
    โ”‚                    โ”‚                   โ”‚                                โ”‚
    โ”‚                    โ–ผ                   โ–ผ                                โ”‚
    โ”‚              @org/user-api      @org/auth-service                       โ”‚
    โ”‚                    โ”‚                   โ”‚                                โ”‚
    โ”‚                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚                       @org/web-client                                    โ”‚
    โ”‚                    (depends on BOTH)                                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   PROBLEM: @org/web-client imports from both user-api and auth-service โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   During migration:                                                      โ”‚
    โ”‚   โ€ข core-types renames UserService โ†’ AccountService                     โ”‚
    โ”‚   โ€ข user-api is updated and published                                   โ”‚
    โ”‚   โ€ข auth-service is NOT yet updated                                     โ”‚
    โ”‚   โ€ข web-client now sees CONFLICTING types!                              โ”‚
    โ”‚     - user-api exports AccountService                                   โ”‚
    โ”‚     - auth-service still exports UserService                            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   SOLUTION: Ensure level-1 repos are updated ATOMICALLY                 โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   1. Update core-types (don't publish yet)                              โ”‚
    โ”‚   2. Update user-api AND auth-service in parallel                       โ”‚
    โ”‚   3. Wait for BOTH to pass tests                                        โ”‚
    โ”‚   4. Merge core-types PR first                                          โ”‚
    โ”‚   5. Publish core-types                                                 โ”‚
    โ”‚   6. Merge user-api and auth-service PRs                                โ”‚
    โ”‚   7. Publish both                                                       โ”‚
    โ”‚   8. Now web-client can be updated safely                               โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.6 GitHub MCP for PR Coordination

The GitHub MCP provides the interface for cross-repo PR management:

                    GITHUB MCP OPERATIONS

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   REPOSITORY ANALYSIS                                                    โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   gh repo list @org --json name,description,updatedAt                   โ”‚
    โ”‚   gh api repos/{owner}/{repo}/contents/package.json                     โ”‚
    โ”‚   โ†’ Parse dependencies to build graph                                   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   BRANCH OPERATIONS                                                      โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Create feature branch across repos                                  โ”‚
    โ”‚   gh api repos/{owner}/{repo}/git/refs \                                โ”‚
    โ”‚     --method POST \                                                     โ”‚
    โ”‚     --field ref="refs/heads/refactor/rename-user-service" \             โ”‚
    โ”‚     --field sha="{base_sha}"                                            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Delete branch on rollback                                           โ”‚
    โ”‚   gh api repos/{owner}/{repo}/git/refs/heads/{branch} --method DELETE   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   PULL REQUEST OPERATIONS                                                โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Create PR with dependencies in description                          โ”‚
    โ”‚   gh pr create \                                                        โ”‚
    โ”‚     --repo @org/user-api \                                              โ”‚
    โ”‚     --title "refactor: Rename UserService to AccountService" \          โ”‚
    โ”‚     --body "Depends on: org/core-types#101" \                           โ”‚
    โ”‚     --label "refactoring" \                                             โ”‚
    โ”‚     --draft                                                             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Mark PR as ready when dependencies are merged                       โ”‚
    โ”‚   gh pr ready 234 --repo @org/user-api                                  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Auto-merge when checks pass                                         โ”‚
    โ”‚   gh pr merge 234 --auto --squash --repo @org/user-api                  โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   CI/CD COORDINATION                                                     โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                    โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Watch for CI completion                                             โ”‚
    โ”‚   gh run watch --repo @org/user-api                                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   # Get CI status                                                       โ”‚
    โ”‚   gh pr checks 234 --repo @org/user-api                                 โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

3. Complete Project Specification

3.1 What You Will Build

A Kiro CLI agent that:

  1. Accepts a refactoring request (rename, move, update API)
  2. Analyzes all organization repositories for impact
  3. Builds dependency graph and determines processing order
  4. Spawns subagents to process repositories in parallel
  5. Creates coordinated PRs with proper dependencies
  6. Handles failures with atomic rollback
  7. Reports progress and final status

3.2 Functional Requirements

Requirement Description
Repository Discovery Find all repos containing the target symbol
Dependency Analysis Build cross-repo dependency graph
Parallel Processing Process independent repos simultaneously
Change Application Apply refactoring transformations
Test Validation Run tests in each repo after changes
PR Creation Create linked PRs with dependencies
Rollback Handling Revert all changes on failure
Progress Reporting Show real-time status of all repos

3.3 Non-Functional Requirements

  • Atomicity: All repos updated or none
  • Consistency: No repo left in broken state
  • Isolation: Parallel agents donโ€™t interfere
  • Durability: Checkpoints survive failures

4. Solution Architecture

4.1 System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    MULTI-REPO REFACTORING AGENT                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                         CLI INTERFACE                                    โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚   kiro-cli chat                                                         โ”‚ โ”‚
โ”‚  โ”‚   > "Rename UserService to AccountService across all repos"             โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                       โ”‚                                       โ”‚
โ”‚                                       โ–ผ                                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                      ORCHESTRATOR AGENT                                  โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Repo Analyzer  โ”‚  โ”‚ Graph Builder  โ”‚  โ”‚ Subagent       โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                โ”‚  โ”‚                โ”‚  โ”‚ Coordinator    โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข List repos   โ”‚  โ”‚ โ€ข Parse deps   โ”‚  โ”‚                โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Find usages  โ”‚  โ”‚ โ€ข Topo sort    โ”‚  โ”‚ โ€ข Spawn agents โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Count files  โ”‚  โ”‚ โ€ข Level assign โ”‚  โ”‚ โ€ข Sync barrier โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ€ข Aggregate    โ”‚            โ”‚ โ”‚
โ”‚  โ”‚                                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                       SUBAGENT POOL                                      โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Subagent     โ”‚  โ”‚ Subagent     โ”‚  โ”‚ Subagent     โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ core-types   โ”‚  โ”‚ user-api     โ”‚  โ”‚ auth-service โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚              โ”‚  โ”‚              โ”‚  โ”‚              โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Clone        โ”‚  โ”‚ Clone        โ”‚  โ”‚ Clone        โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Branch       โ”‚  โ”‚ Branch       โ”‚  โ”‚ Branch       โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Transform    โ”‚  โ”‚ Transform    โ”‚  โ”‚ Transform    โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Test         โ”‚  โ”‚ Test         โ”‚  โ”‚ Test         โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ Report       โ”‚  โ”‚ Report       โ”‚  โ”‚ Report       โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                        INTEGRATION LAYER                                 โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ GitHub MCP   โ”‚  โ”‚ Checkpoint   โ”‚  โ”‚ Test Runner  โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚              โ”‚  โ”‚ Manager      โ”‚  โ”‚ Hook         โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ โ€ข PR ops     โ”‚  โ”‚              โ”‚  โ”‚              โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ โ€ข Branch ops โ”‚  โ”‚ โ€ข Save state โ”‚  โ”‚ โ€ข Run tests  โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ โ€ข CI status  โ”‚  โ”‚ โ€ข Restore    โ”‚  โ”‚ โ€ข Report     โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.2 Data Flow

                    REFACTORING DATA FLOW

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   USER REQUEST                                                           โ”‚
    โ”‚   "Rename UserService โ†’ AccountService"                                 โ”‚
    โ”‚                    โ”‚                                                     โ”‚
    โ”‚                    โ–ผ                                                     โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    REPOSITORY SCAN                              โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Output: ImpactAnalysis                                        โ”‚    โ”‚
    โ”‚   โ”‚   {                                                             โ”‚    โ”‚
    โ”‚   โ”‚     targetSymbol: "UserService",                               โ”‚    โ”‚
    โ”‚   โ”‚     affectedRepos: [                                           โ”‚    โ”‚
    โ”‚   โ”‚       { name: "core-types", files: 3, usages: 5 },             โ”‚    โ”‚
    โ”‚   โ”‚       { name: "user-api", files: 7, usages: 23 },              โ”‚    โ”‚
    โ”‚   โ”‚       { name: "auth-service", files: 4, usages: 12 },          โ”‚    โ”‚
    โ”‚   โ”‚       { name: "web-client", files: 12, usages: 45 }            โ”‚    โ”‚
    โ”‚   โ”‚     ]                                                           โ”‚    โ”‚
    โ”‚   โ”‚   }                                                             โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                   โ”‚                                      โ”‚
    โ”‚                                   โ–ผ                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    DEPENDENCY GRAPH                             โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Output: DependencyGraph                                       โ”‚    โ”‚
    โ”‚   โ”‚   {                                                             โ”‚    โ”‚
    โ”‚   โ”‚     levels: [                                                   โ”‚    โ”‚
    โ”‚   โ”‚       ["core-types"],                                          โ”‚    โ”‚
    โ”‚   โ”‚       ["user-api", "auth-service"],                            โ”‚    โ”‚
    โ”‚   โ”‚       ["web-client"]                                           โ”‚    โ”‚
    โ”‚   โ”‚     ],                                                          โ”‚    โ”‚
    โ”‚   โ”‚     edges: [                                                    โ”‚    โ”‚
    โ”‚   โ”‚       { from: "core-types", to: "user-api" },                  โ”‚    โ”‚
    โ”‚   โ”‚       { from: "core-types", to: "auth-service" },              โ”‚    โ”‚
    โ”‚   โ”‚       { from: "user-api", to: "web-client" },                  โ”‚    โ”‚
    โ”‚   โ”‚       { from: "auth-service", to: "web-client" }               โ”‚    โ”‚
    โ”‚   โ”‚     ]                                                           โ”‚    โ”‚
    โ”‚   โ”‚   }                                                             โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                   โ”‚                                      โ”‚
    โ”‚                                   โ–ผ                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    PARALLEL EXECUTION                           โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Level 0:                                                      โ”‚    โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ Subagent: core-types โ†’ Success                           โ”‚    โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ โœ“ Barrier: Level 0 complete                              โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Level 1:                                                      โ”‚    โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ Subagent: user-api โ†’ Success                             โ”‚    โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ Subagent: auth-service โ†’ Success                         โ”‚    โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ โœ“ Barrier: Level 1 complete                              โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Level 2:                                                      โ”‚    โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ Subagent: web-client โ†’ Success                           โ”‚    โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ โœ“ Barrier: Level 2 complete                              โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                   โ”‚                                      โ”‚
    โ”‚                                   โ–ผ                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    PR CREATION                                  โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Output: PRCoordination                                        โ”‚    โ”‚
    โ”‚   โ”‚   {                                                             โ”‚    โ”‚
    โ”‚   โ”‚     prs: [                                                      โ”‚    โ”‚
    โ”‚   โ”‚       { repo: "core-types", number: 101, deps: [] },           โ”‚    โ”‚
    โ”‚   โ”‚       { repo: "user-api", number: 234, deps: [101] },          โ”‚    โ”‚
    โ”‚   โ”‚       { repo: "auth-service", number: 567, deps: [101] },      โ”‚    โ”‚
    โ”‚   โ”‚       { repo: "web-client", number: 890, deps: [234, 567] }    โ”‚    โ”‚
    โ”‚   โ”‚     ],                                                          โ”‚    โ”‚
    โ”‚   โ”‚     mergeOrder: ["core-types", "user-api", "auth-service",     โ”‚    โ”‚
    โ”‚   โ”‚                  "web-client"]                                 โ”‚    โ”‚
    โ”‚   โ”‚   }                                                             โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.3 Key Data Structures

// Core types for multi-repo refactoring

interface RefactoringRequest {
  type: 'rename' | 'move' | 'deprecate' | 'update-api';
  target: {
    symbol: string;
    type: 'interface' | 'class' | 'function' | 'type' | 'constant';
    sourceRepo: string;
  };
  replacement: {
    symbol: string;
    location?: string;  // For move operations
  };
}

interface ImpactAnalysis {
  targetSymbol: string;
  affectedRepos: RepoImpact[];
  totalFiles: number;
  totalUsages: number;
  estimatedTime: string;
}

interface RepoImpact {
  name: string;
  files: string[];
  usages: UsageLocation[];
  dependencies: string[];
  isSource: boolean;  // true if this repo defines the symbol
}

interface UsageLocation {
  file: string;
  line: number;
  column: number;
  context: string;  // Surrounding code
  usageType: 'import' | 'type-reference' | 'value-reference';
}

interface DependencyGraph {
  nodes: string[];  // Repo names
  edges: DependencyEdge[];
  levels: string[][];  // Repos grouped by dependency level
  criticalPath: string[];
}

interface DependencyEdge {
  from: string;  // Repo that provides
  to: string;    // Repo that consumes
  symbols: string[];  // Shared symbols
}

interface SubagentResult {
  repo: string;
  status: 'success' | 'failure' | 'skipped';
  changes: FileChange[];
  testResults: TestResult;
  branchName: string;
  commitSha: string;
  error?: string;
}

interface PRCoordination {
  prs: PRInfo[];
  mergeOrder: string[];
  autoMergeEnabled: boolean;
}

interface PRInfo {
  repo: string;
  number: number;
  title: string;
  branch: string;
  dependencies: number[];  // PR numbers this depends on
  status: 'draft' | 'ready' | 'merged' | 'closed';
  checksStatus: 'pending' | 'passing' | 'failing';
}

interface MultiRepoCheckpoint {
  id: string;
  timestamp: Date;
  request: RefactoringRequest;
  repoStates: Map<string, RepoCheckpoint>;
  phase: 'analyzing' | 'processing' | 'creating-prs' | 'complete';
}

interface RepoCheckpoint {
  repo: string;
  branchName: string;
  baseSha: string;
  headSha: string;
  status: 'pending' | 'processing' | 'success' | 'failure' | 'rolled-back';
}

5. Phased Implementation Guide

Phase 1: Repository Analysis (Days 1-7)

Goals:

  • Scan organization repositories
  • Find symbol usages across repos
  • Build initial impact analysis

Tasks:

  1. Implement GitHub MCP integration for repo listing
  2. Build symbol search using ripgrep or AST parsing
  3. Parse package.json for dependency mapping
  4. Generate impact analysis report
  5. Create visualization of affected repos

Milestone Checkpoint:

$ kiro-cli chat
> "Analyze impact of renaming UserService in @org"

[Analysis] Scanning organization repositories...
โ”œโ”€โ”€ Found 12 repositories with TypeScript
โ”œโ”€โ”€ Searching for "UserService" usages...
โ””โ”€โ”€ Building dependency graph...

[Impact Analysis]
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Repository           โ”‚ Files โ”‚ Usages โ”‚ Dependencies              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ @org/core-types      โ”‚ 3     โ”‚ 5      โ”‚ None (source)             โ”‚
โ”‚ @org/user-api        โ”‚ 7     โ”‚ 23     โ”‚ @org/core-types           โ”‚
โ”‚ @org/auth-service    โ”‚ 4     โ”‚ 12     โ”‚ @org/core-types           โ”‚
โ”‚ @org/web-client      โ”‚ 12    โ”‚ 45     โ”‚ user-api, auth-service    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Total: 4 repos, 26 files, 85 usages
Estimated time: 2-3 hours with AI assistance

Hint 1: Use gh api repos/{owner}/{repo}/contents/package.json to fetch package.json files directly from GitHub.

Phase 2: Dependency Graph (Days 8-14)

Goals:

  • Build complete dependency graph
  • Implement topological sorting
  • Determine processing levels

Tasks:

  1. Parse all package.json dependencies
  2. Build directed graph of repo dependencies
  3. Implement topological sort algorithm
  4. Group repos by dependency level
  5. Identify critical path

Milestone Checkpoint:

> "Show dependency graph for refactoring"

[Dependency Graph]

Level 0 (no dependencies):
  โ””โ”€โ”€ @org/core-types

Level 1 (depends on Level 0):
  โ”œโ”€โ”€ @org/user-api
  โ””โ”€โ”€ @org/auth-service

Level 2 (depends on Level 1):
  โ””โ”€โ”€ @org/web-client

Critical Path: core-types โ†’ user-api โ†’ web-client
Parallel Opportunities: user-api and auth-service can run in parallel

Hint 2: Use Kahnโ€™s algorithm for topological sort - it naturally gives you level assignments.

Phase 3: Subagent Orchestration (Days 15-21)

Goals:

  • Implement subagent spawning
  • Build synchronization barriers
  • Handle parallel execution

Tasks:

  1. Create subagent configuration for repo processing
  2. Implement barrier synchronization between levels
  3. Build result aggregation system
  4. Add progress reporting for parallel agents
  5. Implement timeout handling

Milestone Checkpoint:

> "Start refactoring UserService โ†’ AccountService"

[Orchestrator] Creating checkpoint: multi-repo-refactor-20241222

[Level 0] Processing 1 repository...
โ”œโ”€โ”€ [Subagent: core-types] Cloning... โœ“
โ”œโ”€โ”€ [Subagent: core-types] Creating branch... โœ“
โ”œโ”€โ”€ [Subagent: core-types] Applying changes... 3 files
โ”œโ”€โ”€ [Subagent: core-types] Running tests... โœ“
โ””โ”€โ”€ โœ“ Level 0 complete

[Level 1] Processing 2 repositories in parallel...
โ”œโ”€โ”€ [Subagent: user-api] Applying changes... 7 files
โ”œโ”€โ”€ [Subagent: auth-service] Applying changes... 4 files
โ”œโ”€โ”€ [Subagent: user-api] Running tests... โœ“
โ”œโ”€โ”€ [Subagent: auth-service] Running tests... โœ“
โ””โ”€โ”€ โœ“ Level 1 complete

[Level 2] Processing 1 repository...
...

Hint 3: Use Promise.all() for parallel execution within a level, but await between levels.

Phase 4: PR Coordination (Days 22-28)

Goals:

  • Create linked pull requests
  • Express dependencies between PRs
  • Enable auto-merge in correct order

Tasks:

  1. Create PRs with proper descriptions
  2. Add dependency links in PR descriptions
  3. Implement PR status monitoring
  4. Set up auto-merge with dependency checks
  5. Handle merge conflicts

Milestone Checkpoint:

> "Create pull requests for the changes"

[PR Creation]
โ”œโ”€โ”€ Creating PR in @org/core-types...
โ”‚   โœ“ PR #101: "refactor: Rename UserService to AccountService"
โ”‚
โ”œโ”€โ”€ Creating PR in @org/user-api...
โ”‚   โœ“ PR #234: "refactor: Update to AccountService"
โ”‚   โ””โ”€โ”€ Dependencies: org/core-types#101
โ”‚
โ”œโ”€โ”€ Creating PR in @org/auth-service...
โ”‚   โœ“ PR #567: "refactor: Update to AccountService"
โ”‚   โ””โ”€โ”€ Dependencies: org/core-types#101
โ”‚
โ””โ”€โ”€ Creating PR in @org/web-client...
    โœ“ PR #890: "refactor: Update to AccountService"
    โ””โ”€โ”€ Dependencies: org/user-api#234, org/auth-service#567

[Auto-merge enabled]
Merge order: #101 โ†’ #234, #567 โ†’ #890

Phase 5: Rollback and Recovery (Days 29-35)

Goals:

  • Implement atomic rollback
  • Handle partial failures
  • Provide recovery options

Tasks:

  1. Build checkpoint restoration
  2. Implement branch deletion for rollback
  3. Add PR closure on failure
  4. Create recovery commands
  5. Test failure scenarios

Hint 4: Store the base SHA for each repo before changes - this is your rollback target.


6. Testing Strategy

6.1 Unit Tests

describe('DependencyGraph', () => {
  it('should detect circular dependencies', () => {
    const graph = new DependencyGraph();
    graph.addEdge('A', 'B');
    graph.addEdge('B', 'C');
    graph.addEdge('C', 'A');  // Creates cycle

    expect(() => graph.topologicalSort()).toThrow('Circular dependency detected');
  });

  it('should group repos by dependency level', () => {
    const graph = new DependencyGraph();
    graph.addEdge('core', 'api');
    graph.addEdge('core', 'auth');
    graph.addEdge('api', 'web');
    graph.addEdge('auth', 'web');

    const levels = graph.getLevels();

    expect(levels[0]).toEqual(['core']);
    expect(levels[1]).toContain('api');
    expect(levels[1]).toContain('auth');
    expect(levels[2]).toEqual(['web']);
  });
});

6.2 Integration Tests

describe('MultiRepoRefactoring', () => {
  it('should rollback all repos on single failure', async () => {
    const orchestrator = new RefactoringOrchestrator();

    // Mock one repo to fail tests
    mockTestRunner.mockImplementation((repo) => {
      if (repo === 'auth-service') {
        return { passed: false, errors: ['Test failed'] };
      }
      return { passed: true };
    });

    await orchestrator.execute({
      type: 'rename',
      target: { symbol: 'UserService', sourceRepo: 'core-types' },
      replacement: { symbol: 'AccountService' }
    });

    // Verify all repos rolled back
    expect(mockGitHub.deleteBranch).toHaveBeenCalledWith('core-types', 'refactor/rename-user-service');
    expect(mockGitHub.deleteBranch).toHaveBeenCalledWith('user-api', 'refactor/rename-user-service');
    expect(mockGitHub.deleteBranch).toHaveBeenCalledWith('auth-service', 'refactor/rename-user-service');
  });
});

7. Common Pitfalls and Debugging

7.1 Common Issues

Pitfall Symptom Solution
Race conditions Parallel agents conflict Use level-based synchronization
Stale dependencies Package versions donโ€™t match Verify versions before starting
Merge conflicts PRs canโ€™t auto-merge Process in strict dependency order
Test flakiness Random failures block progress Implement retry with backoff
API rate limits GitHub API errors Add rate limiting and queuing

7.2 Debugging Strategies

1. Enable detailed logging per subagent:

const subagent = createSubagent({
  repo: 'user-api',
  onProgress: (step, detail) => {
    console.log(`[${repo}] ${step}: ${detail}`);
  },
  onError: (error) => {
    console.error(`[${repo}] ERROR: ${error.message}`);
    console.error(`[${repo}] Stack: ${error.stack}`);
  }
});

2. Visualize dependency graph:

> "Show me the dependency graph in Mermaid format"

graph TD
    core-types --> user-api
    core-types --> auth-service
    user-api --> web-client
    auth-service --> web-client

3. Inspect checkpoint state:

> "Show checkpoint details for multi-repo-refactor-20241222"

[Checkpoint: multi-repo-refactor-20241222]
โ”œโ”€โ”€ Phase: creating-prs
โ”œโ”€โ”€ Repos:
โ”‚   โ”œโ”€โ”€ core-types: success (branch: refactor/rename-user-service)
โ”‚   โ”œโ”€โ”€ user-api: success (branch: refactor/rename-user-service)
โ”‚   โ”œโ”€โ”€ auth-service: failure (tests failed)
โ”‚   โ””โ”€โ”€ web-client: skipped (blocked by auth-service)
โ””โ”€โ”€ Action: Rollback recommended

8. Extensions and Challenges

8.1 Beginner Extensions

  • Add dry-run mode that shows planned changes without applying
  • Generate detailed change report with diffs
  • Add notification system (Slack, email) for progress

8.2 Intermediate Extensions

  • Support for monorepo structures (Lerna, Nx)
  • Implement semantic versioning bump automation
  • Add approval workflow before PR creation

8.3 Advanced Extensions

  • Machine learning for effort estimation based on history
  • Integration with code review platforms (Reviewable, Graphite)
  • Support for cross-language refactoring (shared API types)

9. Real-World Connections

9.1 Industry Tools

Tool Pattern Used Company
Sourcegraph Batch Changes Multi-repo refactoring Sourcegraph
Renovate Bot Dependency updates Mend
Dependabot Automated PRs GitHub
Atomist Code transformation Atomist

9.2 Enterprise Use Cases

  • API versioning: Update all consumers when API changes
  • Security patches: Apply fixes across all repositories
  • Framework upgrades: Migrate React/Vue/Angular versions
  • Deprecation: Remove usage of deprecated APIs

10. Self-Assessment Checklist

Understanding Verification

  • I can explain topological sorting and why it matters
  • I understand the two-phase commit pattern for atomic changes
  • I can describe the diamond dependency problem and solutions
  • I know how to coordinate PRs with dependencies
  • I can explain subagent orchestration patterns

Implementation Verification

  • Repository analysis correctly finds all usages
  • Dependency graph is built correctly
  • Subagents process repos in parallel within levels
  • Synchronization barriers work between levels
  • PRs are created with correct dependencies
  • Rollback works when any repo fails

Integration Verification

  • Full refactoring works on test repositories
  • PR auto-merge respects dependency order
  • Recovery works from any checkpoint
  • Progress is reported accurately

11. Completion Criteria

Minimum Viable Completion

  • Analyzes repositories and builds dependency graph
  • Processes repos in correct dependency order
  • Creates PRs with dependency information
  • Handles single-repo failures with rollback

Full Completion

  • Parallel processing within dependency levels
  • Full atomic rollback across all repos
  • Auto-merge with dependency checking
  • Comprehensive progress reporting
  • Checkpoint-based recovery

Excellence (Going Above and Beyond)

  • Monorepo support
  • Cross-organization refactoring
  • Machine learning for effort estimation
  • Integration with code review platforms
  • Visual dependency graph in dashboard

This guide was expanded from LEARN_KIRO_CLI_MASTERY.md. For the complete learning path, see the README.