Mneme HQ governs AI-assisted software migrations by separating legacy, transitional, and target architecture into decisions that supported coding agents’ writes are checked against before they land, and again in CI. During a migration a repository contains more examples of the architecture you are leaving than the one you are moving toward, so an agent that infers patterns from the codebase infers the wrong one. Path applicability decides which decision governs which tree. Retrieval tells an agent what exists. Governance tells it what should survive.
Reference Architecture · Simulated Scenario

Keeping AI Coding Agents Inside the Target Architecture During Migrations

A migration leaves legacy and target patterns in the same repository. Mneme HQ scopes each architectural decision to the paths it governs, so agents build toward the architecture you are migrating to.

MIGRATION GOVERNANCE PIPELINE mixed repository Legacy + Target both patterns in one tree migration ADRs Decision Corpus legacy · transitional · target include / exclude_paths Scope Resolution which rule governs this path pre-write and CI Enforcement target architecture holds
The Problem

During a migration, the codebase teaches the wrong architecture.

Suppose the system you are leaving is Controller → Service → Repository → Database and the system you are moving toward is API → Domain → Port → Adapter. While the migration runs, both structures legitimately exist in the repository. That is not a defect. It is what a migration is.

Now ask a coding agent to add a feature. It inspects the codebase, finds two hundred examples of the old structure and twenty of the new one, and concludes that the old structure is how this system is built. Statistically it is correct. Architecturally it has just reproduced the thing you are paying to remove.

The dominant pattern in a repository may be precisely the pattern you are trying to eliminate. What exists in the codebase is not what should be created next, and frequency is not intent.

Without Mneme HQ — agent follows the majority:
Prompt: "Add customer lookup to the migrated orders service"
I'll follow the existing pattern in this codebase and query the database directly from the service layer...

db.query(Customer).filter_by(id=customer_id)
With Mneme HQ — applicable decision resolved:
mneme check --mode strict
FAIL [ADR-042] direct database access is superseded
Path: modern/orders/customer_lookup.py
Applies: migrated modules only. The legacy tree is excluded.
Use: CustomerRepository via RepositoryPort.

→ The pattern the agent copied is the one being removed.
Why Existing Tools Fall Short

Nothing in the toolchain knows which architecture is the target.

Approach Limitation With Mneme HQ
Codebase context and retrieval Reports what the repository contains, and during a migration legacy is most of it Decisions state which pattern survives, independent of how often it appears
Migration plan in the prompt Advisory, and silently dropped when context is compacted mid-session Typed rules sit outside the prompt, in pre-write hooks and a CI gate, so compaction cannot drop them
Linters and static analysis Apply uniformly; cannot permit a pattern in legacy code and forbid it in migrated code Path applicability scopes each rule to the tree it actually governs
Code review Sees the diff after the wrong pattern was already copied, at AI output volume Pre-write hooks stop supported agent writes before review, and a strict CI gate checks the pull request
Deleting the legacy code Unavailable until the migration finishes, which is the entire problem Both architectures coexist under explicit, separately scoped decisions
How Mneme HQ Solves It

Give every migration role its own decision.

A migration has more than two states. Treating it as "old code" and "new code" is what makes agents guess. Four roles cover most migrations: legacy, target, transitional and forbidden reintroduction. Mneme has no field for these roles. You express each one as its own decision, scoped to the paths it governs.

1

Record each migration role as a scoped decision

Legacy was valid historically and is no longer the model for new work. Target is what new and migrated code follows. Transitional covers the adapters, dual writes, and compatibility layers that exist only during the cutover. Forbidden reintroduction covers the pattern that must not return to a component once it has migrated.

These roles are not lifecycle states. In the Decision Index each decision has one lifecycle status: active, superseded, deprecated or inactive. An Architecture Decision Record (ADR) with status: accepted becomes an active decision, and only active decisions are enforced. To retire a decision, write a new ADR that lists the old one under supersedes and re-import with --update-existing; the old decision becomes superseded and stops being enforced. Changing an imported ADR’s status alone does not remove its decision. Give each role decision its own scope: when two accepted ADRs share a scope, Mneme keeps the higher-priority one and marks the other inactive.

2

Scope each rule to the paths it governs

include_paths and exclude_paths decide where a rule applies. A target rule governs modern/** and leaves legacy/** alone, which is what lets both trees coexist without the agent inferring which one is canonical.

3

Compile with mneme adr import

The Constraints block of each ADR compiles into typed rules the enforcement layer evaluates. Applicability is resolved against the real target path at check time, and every check reports which rules applied, which were excluded, and why.

4

Gate agent writes and CI on the applicable decision

Install the pre-write hook for your agent. It checks native write tools before the file changes: Claude Code Edit, Write and MultiEdit, Codex CLI apply_patch, and native write tools in Kiro CLI 3.0, the command-line version of the Kiro coding agent. Shell writes reach disk first; Claude Code and Codex CLI check them at end of turn. Kiro CLI does not check shell writes; CI catches them. Then add mneme check --mode strict to CI. With that gate in place, a pull request that reaches for the superseded pattern in a migrated module fails against the decision that governs its path, whichever agent wrote it. Only strict mode blocks. Warn mode reports each violation and exits zero, which suits a team still shaping its decisions.

Technical Implementation

What a scoped migration decision looks like.

The decision below supersedes direct database access, but only inside the migrated tree. The legacy tree keeps its existing calls until its components are migrated, so the rule does not fire on code that has not moved yet.

docs/adr/ADR-042-repository-port.md
---
id: ADR-042
title: Direct database access is superseded by RepositoryPort
status: accepted
priority: foundational
date: "2026-08-28"
scope: data-access
---

Direct database access was the standard in the pre-migration architecture.
Migrated modules reach persistence through RepositoryPort. The legacy tree
keeps its existing calls until its components are migrated.

## Constraints

- FORBID_LITERAL:
    value: db.query(
    include_paths:
      - "modern/**"
    exclude_paths:
      - "legacy/**"
Terminal — enforcement with applicability resolved
$ mneme adr import docs/adr --memory .mneme/project_memory.json --apply
Wrote 3 decisions to .mneme/project_memory.json

$ mneme check \
  --memory .mneme/project_memory.json \
  --input orders-service.diff \
  --target-path modern/orders/customer_lookup.py \
  --query "migrated module data access" --mode strict

FAIL  [ADR-042] FORBID_LITERAL "db.query(" -- trigger: db.query(
      Direct database access is superseded by RepositoryPort
      path: modern/orders/customer_lookup.py via modern/**

PATH  APPLIED  [ADR-042] modern/orders/customer_lookup.py via modern/** -- an include selector matched
# ...one PATH line for each other path-scoped rule

Result: FAIL

The PATH line is the part that matters during a migration. A path-scoped rule reports its applicability outcome against the target path. Run the same check with --target-path legacy/orders/service.py and ADR-042 reports PATH EXCLUDED via legacy/** with Result: PASS, so the same decision that fails inside the migrated tree is visibly and explainably inert outside it. An agent working across a half-migrated repository gets a different answer per path instead of one blanket rule it has to reason around.

The enforcement path itself is shown end to end in the repository pattern demo, where a direct SQL call from a service layer is matched to its decision and denied by a strict check.

Simulated Outcome

What changes once migration roles are enforced.

4
migration roles per boundary, each its own scoped decision: legacy, target, transitional, forbidden reintroduction
10:1
legacy-to-target example ratio the agent sees in the reference repository
0
superseded-pattern violations reaching review from migrated modules
⚠ These figures describe a simulated reference scenario, not live customer data.
Research Direction

Before the migration: deciding what must survive.

A rewrite can match every tested output and still carry forward things nobody meant to keep: a rounding bug, a workaround for an interface retired years ago, a direct database call someone wrote as a shortcut rather than a design. Before the rewrite starts, sort what you recover from the old system into three classes. Observed behavior is what the system does today. An inferred decision is a reading, by a person or a tool, of why it does that. An approved decision is one a named owner has reviewed and agreed must hold in the target system.

Only approved decisions should constrain the migration. Observed behavior feeds parity tests. Inferred decisions are candidates for review. Neither should bind the new system until someone with authority approves it.

For Mneme HQ this is research direction, not a shipped feature. Mneme does not extract business logic from legacy code. Recovering candidate decisions from a legacy system is conceptual work with no validated results.

What ships today starts after approval. A team records the approved decision as an ADR with status: accepted and a typed rule. Accepted is the nearest thing Mneme has to approved: the Decision Index records each version and its source, not who approved it. A typed rule is active when its decision is: imported from an accepted ADR, not superseded by a later ADR, and not outranked by another accepted ADR in the same scope. Mneme enforces only active rules, through the pre-write hooks and CI gate described above, and blocks only in strict mode.

The full argument is in AI Legacy Modernization: What Must Survive the Rewrite? and what OpenAI's legacy migration benchmark does not measure.

FAQ

Common questions.

How is this different from putting the migration plan in the prompt?
A prompt is advisory and is dropped when context is compacted. Typed rules live outside the prompt. Pre-write hooks check supported agents’ native writes, and a strict CI gate checks each pull request whichever agent produced it, so the constraint survives a migration that runs across many sessions, agents and months.
The legacy pattern is still valid in unmigrated modules. Does Mneme forbid it everywhere?
No. Applicability is scoped by path. A rule can carry include_paths for the migrated tree and exclude_paths for the legacy tree, which is what lets both architectures coexist without the agent guessing which one governs the file it is editing.
What happens to a decision when a component finishes migrating?
Write a new ADR that lists the transitional one under supersedes and re-import it with --update-existing; the old decision becomes superseded and stops being enforced. Changing the status in the old ADR file alone does not remove its decision. The superseded record stays in the Decision Index as the reason the exception existed.
Do we have to model the whole migration before this is useful?
No. Start with the boundary agents cross most often, usually persistence or service-to-service calls. A few scoped decisions on that boundary are a reasonable start, and you add further boundaries as the migration proceeds.