Skip to content

About

Human-in-control pair programming for AI coding with shadow implementation, design approval, guided reconstruction, and pitfall-aware handoff.

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Pair Programming Skill

English | 简体中文

Pair Programming Skill Banner

Let AI prove the feature in an isolated workspace first, then guide you through rebuilding it step by step until the code is something you understand, can maintain, and are confident changing.

Modern coding agents no longer struggle mainly with writing code. The new problem is:

AI coding speed is starting to exceed human comprehension speed.

If an agent changes dozens of files and generates thousands of lines in one pass, the result may compile and all tests may pass, yet you can still lose ownership of the code very quickly.

Pair Programming Skill does not try to make AI weaker. It changes the division of labor:

  • AI first explores, implements, builds, tests, and debugs the complete feature in a Shadow Workspace.
  • If the request is not already an implementation-ready design, AI first writes a design and waits for user approval.
  • Once the Shadow solution is verified, AI reverse-decomposes it into human-sized implementation steps.
  • The real Human Workspace remains under user control.
  • The user can ask for hints, explanations, reference code, review, or selective AI takeover at any time.
  • Pitfalls discovered during Shadow implementation are preserved and proactively taught during the guided reconstruction.

Core principle:

AI coding throughput <= Human comprehension throughput


Why this exists

A typical autonomous coding-agent workflow looks like this:

Requirement
    ↓
Agent
    ↓
Large code change
    ↓
Tests pass
    ↓
"Looks fine"
    ↓
A few weeks later:
"I no longer feel safe changing this code."

Pair Programming Skill changes the workflow to:

Requirement / Design
        ↓
Design Gate
        ↓
Shadow Implementation
        ↓
Build / Test / Debug
        ↓
Record Pitfalls & Hidden Constraints
        ↓
Reverse Decomposition
        ↓
Guided Reconstruction
        ↓
AI Review / Hint / Explain
        ↓
Selective AI Takeover when useful
        ↓
Code you can actually maintain

The Shadow Workspace is the route AI has already flown once.

The Human Workspace is the code that ultimately matters.


Core architecture

The workflow has four major layers:

┌────────────────────────────────┐
│ 1. Design Gate                 │
│ Turn a goal into a concrete    │
│ implementation-ready design    │
└───────────────┬────────────────┘
                ↓
┌────────────────────────────────┐
│ 2. Shadow Workspace            │
│ AI fully implements, validates │
│ and discovers pitfalls         │
└───────────────┬────────────────┘
                ↓
┌────────────────────────────────┐
│ 3. Guide Branch                │
│ Rebuild the verified solution  │
│ as teachable commits           │
└───────────────┬────────────────┘
                ↓
┌────────────────────────────────┐
│ 4. Human Workspace             │
│ The code the user actually     │
│ implements and owns            │
└────────────────────────────────┘

1. Design Gate — design before implementation

/pair plan does not always mean "start coding immediately."

If the user only provides a feature goal:

/pair plan add automatic reconnect for remote MCP

that is a Feature Goal, not an implementation-ready design.

The agent first:

  1. inspects the relevant existing code;
  2. understands current interfaces, data flow, lifecycle, and constraints;
  3. produces a concrete implementation design;
  4. saves it to:
.pair/design.md
  1. records:
design:
  source: ai_generated
  status: awaiting_approval
  revision: 1
  approved_revision: 0

Then it stops.

At this point it must not:

  • create the Shadow worktree;
  • create an implementation branch;
  • edit production/source code;
  • generate the full implementation.

Implementation starts only after explicit approval, for example:

Approved. Implement this design.

Approval is revision-scoped

Design approval is not permanent.

revision 3
   ↓
user approves
   ↓
approved_revision = 3
   ↓
design changes materially
   ↓
revision 4
status = awaiting_approval
approved_revision = 0

A changed design must be approved again.

Implementation is allowed only when:

design.status == approved
AND
design.approved_revision == design.revision

If /pair plan already includes a sufficiently concrete design, ADR, PRD, or design document, the Skill reads it, verifies that it is implementation-ready, normalizes/saves it as .pair/design.md, and may proceed directly to Shadow implementation unless the user explicitly asks for design review only.


2. Shadow Workspace — let AI walk the whole path first

After design approval, AI creates an isolated Git worktree for the Shadow solution:

pair-shadow/<feature>/solution

Inside the Shadow Workspace, AI may:

  • implement the complete feature;
  • try alternative approaches;
  • compile/build;
  • run tests;
  • debug;
  • validate edge cases;
  • add temporary instrumentation;
  • discard failed approaches.

The Shadow Workspace does not replace the user's real working tree.

Default worktree layout

workspace/
├── my-project/
│   ├── .git/
│   │   └── worktrees/...          # Git-managed metadata
│   ├── .pair/                     # Pair Programming state
│   └── src/
│
└── .pair-worktrees/
    └── my-project/
        └── feature-name/
            └── shadow/            # Actual Shadow checkout

The Skill resolves Git paths using:

git rev-parse --show-toplevel
git rev-parse --git-common-dir

It does not assume .git is always a directory.

The actual checked-out source tree does not live inside .git.
.git/worktrees/* is managed only by Git itself.

By default, each feature uses one physical Shadow checkout.

The verified complete implementation is preserved in:

pair-shadow/<feature>/solution

The pedagogical commit chain is preserved in:

pair-shadow/<feature>/guide

3. Pitfall Journal — Shadow failures become teaching material

The value of Shadow implementation is not only that AI reaches a working answer first.

It also discovers problems before the user does:

  • incorrect assumptions;
  • lifecycle bugs;
  • concurrency traps;
  • hidden API constraints;
  • build and dependency surprises;
  • platform-specific behavior;
  • edge cases exposed only by tests;
  • approaches that look reasonable but fail in practice.

That knowledge must not disappear after the final implementation passes.

Meaningful pitfalls are recorded in:

.pair/pitfalls.yaml

Example:

- id: P003
  title: Registry teardown order causes dangling provider references
  status: resolved
  severity: high
  category: lifetime

  symptom: Integration test crashes during Plugin destruction.

  wrong_assumption:
    Registry entries could outlive Plugin instances.

  root_cause:
    Registry does not own Provider lifetime.

  resolution:
    Remove capability registrations before Plugin destruction.

  related_steps:
    - plugin-lifecycle

  lesson_for_human:
    Registry entries must never outlive their Provider.

  avoidance:
    Always unregister before destroying Plugin.

Pitfalls are surfaced proactively

When the user runs:

/pair next

and the current step has a mapped Shadow pitfall, the agent must proactively explain it.

Example:

Shadow pitfall P003

The first Shadow implementation called unregister after Plugin destruction,
which produced a dangling reference in integration tests.

Root cause:
CapabilityRegistry does not own Provider lifetime.

Invariant for this step:
unregister first, destroy Plugin second.

The user should not have to ask:

"Did AI run into any problems here?"

/pair review also checks whether the Human implementation falls into a known Shadow pitfall.

Shadow therefore serves two purposes:

Reference Implementation
        +
Pre-mortem / Pitfall Discovery

4. Reverse Decomposition — derive the learning path from a verified solution

After Shadow implementation is complete and verified, the Skill does not split the final diff mechanically by file.

This is a poor decomposition:

Step 1 modify foo.h
Step 2 modify foo.cpp
Step 3 modify test.cpp

Instead, it decomposes by:

  • dependency;
  • concept;
  • architecture;
  • verification point.

Example:

Step 1  Define Capability identity
        ↓
Step 2  Implement CapabilityRegistry
        ↓
Step 3  Integrate with PluginManager
        ↓
Step 4  Define lifecycle / concurrency rules
        ↓
Step 5  Add integration tests
        ↓
Step 6  Final verification

Default guidance for one step:

  • one primary concept;
  • roughly 1–3 files;
  • around 150 effective diff lines;
  • one explicit validation point.

Complex steps may exceed these limits when the change is logically cohesive.


5. Guide Branch — stable reference code for every step

After the full solution is verified, the Skill reconstructs the feature from the original baseline as a pedagogical commit chain:

pair-shadow/<feature>/guide

Example:

baseline
   │
   ├── Step 1 commit
   ├── Step 2 commit
   ├── Step 3 commit
   ├── Step 4 commit
   └── Step 5 commit

This makes:

/pair show step 3

able to show the exact reference delta for Step 3.

And:

/pair take step 3

can selectively transfer that logical unit rather than trying to infer it from one huge final diff.

The Guide Branch does not need to preserve Shadow's exploratory commit history.

Its goal is:

correct + verifiable + teachable


6. Guided Reconstruction — the user stays in the driver's seat

The Human Workspace now rebuilds the feature deliberately.

Running:

/pair next

shows only what is needed for the current step:

  • Goal;
  • Why;
  • current code path;
  • constraints and invariants;
  • target files/symbols;
  • validation command;
  • relevant Shadow pitfalls;
  • suggested first move.

The full reference implementation is not shown by default.


Commands

These are conversation protocol commands. They do not require the host coding agent to register actual shell slash commands.

/pair plan <goal-or-design>

Start a Pair Programming feature.

If the input is underspecified:

Design
→ save .pair/design.md
→ wait for explicit approval

If an implementation-ready design is already provided:

Normalize design
→ Shadow Implementation
→ Guide

/pair next

Enter the next available Guide step.

Before the user writes code, AI explains:

  • why this step exists;
  • what should change;
  • which invariants matter;
  • what Shadow already discovered here;
  • how to validate the result.

Then it stops at the human coding checkpoint.


/pair review [scope]

Review the Human implementation semantically.

Priority:

correctness
→ behavioral gap
→ regression
→ ownership / lifetime
→ error handling
→ concurrency
→ API compatibility
→ maintainability
→ style

Shadow is a secondary reference, not a mandatory answer.

If the Human implementation is simpler, fits the repository better, and satisfies the requirements, the Skill should keep the Human design and adapt later steps.


/pair hint [scope] [level]

Progressive assistance:

Level 1  Conceptual hint
Level 2  API / data structure / control-flow hint
Level 3  Pseudocode / skeleton
Level 4  Minimal reference excerpt / diff
Level 5  AI takeover

Repeated hints for the same blocker escalate by default.


/pair explain <scope>

Explain without modifying code.

Typical scopes:

  • current step;
  • file;
  • symbol;
  • architecture decision;
  • lifetime;
  • data flow;
  • pitfall;
  • reference diff.

/pair show <scope>

Show reference code without applying it.

Examples:

/pair show step 3
/pair show file src/plugin_manager.cpp
/pair show symbol PluginManager::registerCapability
/pair show tests
/pair show build

/pair take <scope>

Delegate a selected scope to AI.

Examples:

/pair take step 3
/pair take tests
/pair take build
/pair take file src/foo.cpp
/pair take symbol Foo::bar
/pair take remaining
/pair take all

Preferred application strategy:

Semantic Port
      ↓
Cherry-pick Guide Commit
      ↓
3-way Patch
      ↓
Manual Adaptation

If Human code has diverged from Shadow, AI should adapt the reference intent to the current Human design instead of overwriting it wholesale.

Each takeover creates recovery evidence first.


/pair challenge [scope]

AI asks 1–3 high-value questions about the design instead of writing code.

For example:

Why should Registry not own Provider?

What breaks if Plugin is destroyed before unregister?

What invariant protects this lookup across unregister?

The goal is not syntax trivia. It is to exercise maintainability-critical understanding.


/pair status

Show workflow state:

Feature: Plugin Capability Management
Design: approved revision 3
Shadow: verified
Guide: 6 steps

[✓] 1 Capability model          human
[✓] 2 CapabilityRegistry        human
[✓] 3 Plugin integration        mixed
[→] 4 Concurrency protection    current
[ ] 5 Integration tests
[ ] 6 Final verification

Shadow pitfalls:
✓ P001 surfaced
✓ P002 discussed
! P004 unresolved

Next:
Step 4 — locking boundary

/pair rebase-plan

This is not Git rebase.

Use it when the Human implementation diverges materially or reveals a better architecture.

Human implementation
        +
remaining goal
        ↓
new Shadow generation
        ↓
new remaining Guide

The Skill:

  • treats the Human Workspace as authoritative;
  • preserves completed work;
  • re-runs only the remaining Shadow work;
  • regenerates the remaining Guide;
  • marks obsolete steps as superseded.

It never resets Human code back to the original Shadow solution.


State files

Pair Programming Skill keeps feature state under .pair/:

.pair/
├── config.yaml
├── design.md
├── manifest.yaml
├── progress.yaml
├── pitfalls.yaml
├── notes.md
├── checkpoints/
├── patches/
└── sessions/

design.md

The canonical design for the current feature.

Implementation is blocked until the required design revision is approved.

manifest.yaml

Describes the feature and the reference implementation:

  • feature goal;
  • design revision / approval;
  • baseline;
  • Shadow branch;
  • Guide branch;
  • validation;
  • steps;
  • risks;
  • Pitfall mappings.

progress.yaml

Tracks actual Human Workspace progress:

  • current phase;
  • current step;
  • human / ai / mixed ownership;
  • hint level;
  • divergences;
  • knowledge coverage;
  • whether each pitfall has been surfaced/discussed.

pitfalls.yaml

Stores engineering knowledge discovered during Shadow:

  • symptom;
  • failed approach;
  • root cause;
  • resolution;
  • validation;
  • related steps;
  • lesson for human;
  • avoidance.

notes.md

Stores design decisions, important discoveries, and deferred work.

checkpoints/

Stores recovery evidence before operations such as /pair take, so user work is not silently overwritten.

sessions/

Stores cross-session summaries:

  • current step;
  • important decisions;
  • validation results;
  • discussed pitfalls;
  • next concrete action.

End-to-end example

Start with:

/pair plan add a Capability Registry to the Plugin system

Because this is only a feature goal, AI first creates:

.pair/design.md

and reports:

Design revision 1
Status: awaiting_approval

The user approves:

The design looks good. Start implementation.

AI implements and validates the feature in Shadow, discovering:

P001 Duplicate provider semantics were ambiguous
P002 Registry ownership caused a lifetime issue
P003 Existing test fixture destroys Plugin too early

It then reverse-decomposes the verified implementation into:

Step 1 Capability identity
Step 2 CapabilityRegistry
Step 3 Duplicate provider semantics
Step 4 Plugin lifecycle integration
Step 5 Tests
Step 6 Final verification

The user runs:

/pair next

and begins Step 1.

When Step 4 is reached, AI proactively warns:

Shadow pitfall P002

Shadow originally hit a lifetime bug here.
Registry does not own Provider.
Unregister must happen before Provider destruction.

If the user does not want to write test boilerplate:

/pair take tests

AI writes only the delegated scope, validates it, explains what was handled, and returns control.

For a full session that demonstrates every command, see:

examples/example-session.md


Human Workspace is always authoritative

This is the most important rule in the Skill:

Shadow implementation != mandatory answer

Shadow is:

  • a verified reference implementation;
  • an exploration result;
  • a Pitfall Discovery environment.

If the Human implementation is:

  • simpler;
  • a better fit for the existing architecture;
  • less abstract;
  • behaviorally correct;

the Skill should keep the Human design and update the remaining Guide.


Safety boundaries

By default, the Skill does not:

  • run git reset --hard;
  • run git clean -fd;
  • force-checkout over user changes;
  • automatically merge Shadow branches;
  • automatically push Shadow branches;
  • force-push;
  • begin full implementation before required design approval;
  • force Human code to match Shadow merely because it differs;
  • opportunistically refactor unrelated code.

Any takeover operation that may affect Human work should create a checkpoint first.


Recommended configuration

Default template:

templates/config.yaml

Recommended settings:

interaction:
  human_controls_main_workspace: true
  auto_advance_after_review: false
  explain_before_human_step: true
  show_reference_by_default: false

limits:
  preferred_files_per_step: 3
  preferred_effective_diff_lines: 150
  hard_effective_diff_lines: 300

takeover:
  prefer_semantic_port: true
  create_checkpoint: true
  preserve_human_changes: true
  return_control_after_apply: true

The purpose is simple:

Keep AI's effective coding throughput below the user's comprehension throughput.


Installation

Copy the whole directory into the Skill directory used by your coding agent:

pair-programming/
├── SKILL.md
├── README.md
├── README.zh-CN.md
├── assets/
│   ├── banner.svg
│   └── icon.png
├── reference/
├── templates/
└── examples/

If the host only supports a single-file Skill, SKILL.md is the minimum installation.

Keeping the whole directory is recommended because:

  • Design Gate uses templates/design.md;
  • Pitfall Journal uses templates/pitfalls.yaml;
  • Manifest / Progress have standard templates;
  • complex operations have dedicated reference documents.

The exact Skill installation path depends on the host agent.


Repository structure

pair-programming-skill/
├── LICENSE
├── README.md
├── README.zh-CN.md
├── assets/
│   └── icon.png
├── SKILL.md
│
├── examples/
│   └── example-session.md
│
├── reference/
│   ├── command-protocol.md
│   ├── decomposition.md
│   ├── design-gate.md
│   ├── pitfall-journal.md
│   ├── review-rubric.md
│   ├── state-model.md
│   └── takeover.md
│
└── templates/
    ├── config.yaml
    ├── design.md
    ├── manifest.yaml
    ├── notes.md
    ├── pitfalls.yaml
    ├── progress.yaml
    └── session-summary.md

When to use it

Especially useful for:

  • medium or large features;
  • system-level or architecture-heavy code;
  • concurrency and lifecycle-sensitive changes;
  • changes where a coding agent would touch many files;
  • projects where you want strong AI assistance without losing code ownership.

For obvious one-line fixes, spelling corrections, or trivial configuration changes, the full Shadow → Guide workflow may be unnecessary.


The goal

This Skill does not insist that:

"Every line must be typed by a human."

And it does not aim to:

"Hand the whole project to an autonomous agent."

The goal is:

I understand the important code, I participate in the key design decisions, I can delegate low-value work to AI, and I can take control back at any time.

Months later, when you return to maintain the feature, you should still know:

  • why it was designed this way;
  • which invariants matter;
  • where it is most likely to fail;
  • which pitfalls AI discovered while implementing it;
  • what must remain true when you change it.

That is the problem Pair Programming Skill is designed to solve.

About

Human-in-control pair programming for AI coding with shadow implementation, design approval, guided reconstruction, and pitfall-aware handoff.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages