skills/migrate/SKILL.md

Migrate a project through a factory version

/factory:migrate <version> prepares the ordered preview and asks whether to apply it. check [version] reports only; apply [version] still requires approval of the exact preview before writing. With no version, use the installed version from plugin.json; if unavailable, stop. Reject unknown arguments, task IDs, all, unknown targets and versions newer than the installed plugin. Installation and invoking this command are not migration approval. Never update/install the plugin, start tasks, run task verification commands, commit, push or rewrite product history.

Resolve and plan without writes

  1. Read the storage contract, resolving the absolute shared Git directory and catalog without creating them. Resolve plugin documents relative to this skill, not the product checkout. Inventory legacy records/reservations, existing catalog and available refs/checkouts read-only. Do not fetch, initialize directories, take locks, append logs or modify records during preview. Report unavailable coverage and any separately needed remote refresh.
  2. Read the release migration index and only the descriptors needed through the requested target. Descriptors use schema_version: 1, unique migration_id, target_version and target_layout; reject malformed metadata or unsupported schema versions. Check index/descriptor consistency. Do not invent source-version/layout selectors. An unindexed descriptor, missing release instructions, duplicate ID or ambiguous ordering blocks application.
  3. Establish the project's last verified target and completed migration IDs from catalog migration.md or the pre-catalog external backup/checkpoint. The installed plugin version is an upper bound, not project progress. Verify checkpoint evidence against actual target invariants and partial-step inventories. If missing/inconsistent, propose read-only reconstruction from project/backup evidence and ask the developer to confirm it; do not guess a starting version or treat an empty legacy directory as success. A fresh project with no legacy records/reservations or catalog needs no historical migration: report that without creating storage or checkpoints.
  4. Visit every release after the verified checkpoint through the target in ascending semantic-version order, not lexical filename order. Follow index order within a shared target version; if absent, stop. Include explicit no-migration decisions. Resume an incomplete step before later ones; never skip it because the installed plugin is newer. A requested target below verified progress is a downgrade, not a migration: stop and refer to recovery. At an already verified target, validate completion read-only without duplicate writes. Earlier target layouts need not still exist after a later verified relocation; use the recorded verification/relocation evidence, not stale branch copies.
  5. Preview each step's ID/target, source inventory and hashes, proposed differences, external backup, locks/writer pauses, verification and recovery. Separate storage moves, schema/status changes and product cleanup. Unknown classifications, conflicting variants or missing approvals remain blockers. In check, stop after the report. Otherwise rehearse before asking for approval.

Rehearse in a sandbox first

Every migration that would write runs on a copy before it touches the live project. The sandbox helper (node <plugin>/scripts/migration-sandbox.mjs) copies the inputs and checks them; it never writes to the project.

  1. Ask the developer to pause every record writer (other sessions, automations such as scheduled feedback, linked worktrees). Choose a new sandbox directory outside the product checkout and its Git directory, for example under the system temp directory.
  2. Run snapshot <product checkout> <sandbox>. It copies the shared catalog, legacy reservations and legacy .factory/ folders of every linked worktree into a new Git repository at <sandbox>/project (no remote), with a SHA-256 manifest. A copy is not isolation if it shares the live catalog, so never rehearse in a linked worktree or ordinary clone instead. Symlinks, changes during the copy and the inputs it reports as not covered (committed .factory/ on other refs, other clones) are blockers to resolve or explicitly accept with the developer, not to guess around. Linked worktrees' .factory/ folders are copied to <sandbox>/project/.worktrees/<n>/.factory (the manifest names each original path); a step that inventories worktrees reads them there. A step that depends on Git-tracked history (such as the 0.4.0 cleanup of committed .factory/) cannot be rehearsed from these copies: treat it as a blocker for the rehearsal unless the developer accepts rehearsing only its record copy.
  3. Apply every pending step from the verified checkpoint through the target to <sandbox>/project, exactly as the live run would: same descriptors and order, external backups inside the sandbox directory, checkpoints in the sandbox catalog. Do not run delivery, push, call external services that write (such as creating issues), or touch live paths. A step that needs such an action records it as an unsupported or live-only action for the preview. Verify each step's postconditions in the sandbox; on failure, stop, keep the diagnostics and report. Never repair the live project as a side effect; recreate the sandbox to retry.
  4. Run changes <sandbox> after each step and keep each output, so the live run can be checked step by step. The last one lists the exact files the whole migration adds, removes and changes. Run verify <sandbox> to prove live inputs were untouched. Present the rehearsal result, exact proposed live changes, exclusions, backups and recovery procedure, and ask for approval. Rehearsal success is evidence, not approval. Wait if approval is unavailable.

Apply, verify and checkpoint

  1. After approval, pause all record writers/allocators across linked worktrees and designate one coordinator for independent clones. Acquire an exclusive mkdir lock at <absolute git-common-dir>/factory-migration.lock, recording its owner/session/checkout. If occupied, report the owner and stop; never remove a possibly live lock. This coordinates migration sessions, not normal writers: confirm those are paused too. Before the first live write, run verify <sandbox>: any drift since the snapshot invalidates the rehearsal and approval, so re-snapshot and rehearse again. Before each later step, compare the live inputs with the rehearsal's recorded state after the previous step instead; a difference needs a fresh rehearsal and approval for the remaining steps. Refresh any authorized remote coverage, re-inventory and renew approval if inputs changed. Make and verify the descriptor's external backups before changing records. Do not initialize the catalog before a descriptor authorizes it.
  2. Apply only the approved current step, re-reading sources before writes. For writes to an existing catalog, also acquire the task/named locks required by the storage contract; occupied locks require an owner decision, not removal. Before catalog initialization, the migration lock and confirmed writer pause protect legacy writes without creating catalog locks early. Follow the descriptor's target-specific instructions, not the newest task template or historical /factory:migrate-tasks invocations. Make the same changes that were rehearsed and approved, re-doing them on live paths; never copy sandbox files or its .git over the real repository. Preserve IDs (unless the descriptor defines an identity mapping and the developer approved it), reservation metadata, custom content, history and exact human-approved revisions; never infer approval or overwrite unexpected destinations. Product cleanup needs separate authorization and normal project review rules. A target version in an approved log entry means the descriptor's version, not the installed plugin version.
  3. Verify the current target's postconditions before advancing, and compare the live result with the rehearsed changes; an unexplained difference is a failure. Keep execution evidence with the agreed external backup until the catalog exists; then consolidate it into catalog migration.md as the storage descriptor permits. Record migration ID, descriptor revision/hash, target version/layout, approved inventory, backup location, actual checks and completed/remaining steps. Mark partial/failure explicitly; advance the last verified release checkpoint only when every step for that release is verified. Never put this state in tracked product files or duplicate checkpoints for compliant records.
  4. On interruption or changed inputs, stop later steps, preserve originals/backups/partial outputs and report recovery actions. Resume only verified identical copies; changed sources or destinations need reconciliation and a fresh preview/approval. Before rollback, export current/new work and restore the checkpoint only to the last verified restored target. Follow descriptor recovery instructions, never a destructive reset. Release the migration lock on completion, failure or handoff; reacquire/recheck after waiting for human input.
  5. Report requested/last verified target, applied/skipped/pending IDs, changed files, backup/checkpoint locations, checks, conflicts and separately pending cleanup. Migration never makes a task ready or approved by itself. If any step remains incomplete, do not claim the project reached the requested version.
Original Markdown, including metadata
---
name: migrate
description: Preview and apply developer-approved factory migrations through a selected target version, in release order. Use after plugin updates or to resume an interrupted migration; not to update the plugin, define tasks or start delivery.
argument-hint: "[check | apply] [target version]"
---

# Migrate a project through a factory version

`/factory:migrate <version>` prepares the ordered preview and asks whether to apply it. `check [version]` reports only; `apply [version]` still requires approval of the exact preview before writing. With no version, use the installed version from [plugin.json](../../.claude-plugin/plugin.json); if unavailable, stop. Reject unknown arguments, task IDs, `all`, unknown targets and versions newer than the installed plugin. Installation and invoking this command are not migration approval. Never update/install the plugin, start tasks, run task verification commands, commit, push or rewrite product history.

## Resolve and plan without writes

1. Read the [storage contract](../storage.md), resolving the absolute shared Git directory and catalog without creating them. Resolve plugin documents relative to this skill, not the product checkout. Inventory legacy records/reservations, existing catalog and available refs/checkouts read-only. Do not fetch, initialize directories, take locks, append logs or modify records during preview. Report unavailable coverage and any separately needed remote refresh.
2. Read [the release migration index](../../docs/updating.md#select-version-scoped-migration-instructions) and only the descriptors needed through the requested target. Descriptors use `schema_version: 1`, unique `migration_id`, `target_version` and `target_layout`; reject malformed metadata or unsupported schema versions. Check index/descriptor consistency. Do not invent source-version/layout selectors. An unindexed descriptor, missing release instructions, duplicate ID or ambiguous ordering blocks application.
3. Establish the project's last verified target and completed migration IDs from catalog `migration.md` or the pre-catalog external backup/checkpoint. The installed plugin version is an upper bound, not project progress. Verify checkpoint evidence against actual target invariants and partial-step inventories. If missing/inconsistent, propose read-only reconstruction from project/backup evidence and ask the developer to confirm it; do not guess a starting version or treat an empty legacy directory as success. A fresh project with no legacy records/reservations or catalog needs no historical migration: report that without creating storage or checkpoints.
4. Visit every release after the verified checkpoint through the target in ascending **semantic-version** order, not lexical filename order. Follow index order within a shared target version; if absent, stop. Include explicit no-migration decisions. Resume an incomplete step before later ones; never skip it because the installed plugin is newer. A requested target below verified progress is a downgrade, not a migration: stop and refer to recovery. At an already verified target, validate completion read-only without duplicate writes. Earlier target layouts need not still exist after a later verified relocation; use the recorded verification/relocation evidence, not stale branch copies.
5. Preview each step's ID/target, source inventory and hashes, proposed differences, external backup, locks/writer pauses, verification and recovery. Separate storage moves, schema/status changes and product cleanup. Unknown classifications, conflicting variants or missing approvals remain blockers. In `check`, stop after the report. Otherwise rehearse before asking for approval.

## Rehearse in a sandbox first

Every migration that would write runs on a copy before it touches the live project. The [sandbox helper](../../scripts/migration-sandbox.mjs) (`node <plugin>/scripts/migration-sandbox.mjs`) copies the inputs and checks them; it never writes to the project.

1. Ask the developer to pause every record writer (other sessions, automations such as scheduled `feedback`, linked worktrees). Choose a new sandbox directory outside the product checkout and its Git directory, for example under the system temp directory.
2. Run `snapshot <product checkout> <sandbox>`. It copies the shared catalog, legacy reservations and legacy `.factory/` folders of every linked worktree into a new Git repository at `<sandbox>/project` (no remote), with a SHA-256 manifest. A copy is not isolation if it shares the live catalog, so never rehearse in a linked worktree or ordinary clone instead. Symlinks, changes during the copy and the inputs it reports as not covered (committed `.factory/` on other refs, other clones) are blockers to resolve or explicitly accept with the developer, not to guess around. Linked worktrees' `.factory/` folders are copied to `<sandbox>/project/.worktrees/<n>/.factory` (the manifest names each original path); a step that inventories worktrees reads them there. A step that depends on Git-tracked history (such as the `0.4.0` cleanup of committed `.factory/`) cannot be rehearsed from these copies: treat it as a blocker for the rehearsal unless the developer accepts rehearsing only its record copy.
3. Apply every pending step from the verified checkpoint through the target to `<sandbox>/project`, exactly as the live run would: same descriptors and order, external backups inside the sandbox directory, checkpoints in the sandbox catalog. Do not run delivery, push, call external services that write (such as creating issues), or touch live paths. A step that needs such an action records it as an unsupported or live-only action for the preview. Verify each step's postconditions in the sandbox; on failure, stop, keep the diagnostics and report. Never repair the live project as a side effect; recreate the sandbox to retry.
4. Run `changes <sandbox>` after each step and keep each output, so the live run can be checked step by step. The last one lists the exact files the whole migration adds, removes and changes. Run `verify <sandbox>` to prove live inputs were untouched. Present the rehearsal result, exact proposed live changes, exclusions, backups and recovery procedure, and ask for approval. Rehearsal success is evidence, not approval. Wait if approval is unavailable.


## Apply, verify and checkpoint

1. After approval, pause all record writers/allocators across linked worktrees and designate one coordinator for independent clones. Acquire an exclusive `mkdir` lock at `<absolute git-common-dir>/factory-migration.lock`, recording its owner/session/checkout. If occupied, report the owner and stop; never remove a possibly live lock. This coordinates migration sessions, not normal writers: confirm those are paused too. Before the first live write, run `verify <sandbox>`: any drift since the snapshot invalidates the rehearsal and approval, so re-snapshot and rehearse again. Before each later step, compare the live inputs with the rehearsal's recorded state after the previous step instead; a difference needs a fresh rehearsal and approval for the remaining steps. Refresh any authorized remote coverage, re-inventory and renew approval if inputs changed. Make and verify the descriptor's external backups before changing records. Do not initialize the catalog before a descriptor authorizes it.
2. Apply only the approved current step, re-reading sources before writes. For writes to an existing catalog, also acquire the task/named locks required by the storage contract; occupied locks require an owner decision, not removal. Before catalog initialization, the migration lock and confirmed writer pause protect legacy writes without creating catalog locks early. Follow the descriptor's target-specific instructions, not the newest task template or historical `/factory:migrate-tasks` invocations. Make the same changes that were rehearsed and approved, re-doing them on live paths; never copy sandbox files or its `.git` over the real repository. Preserve IDs (unless the descriptor defines an identity mapping and the developer approved it), reservation metadata, custom content, history and exact human-approved revisions; never infer approval or overwrite unexpected destinations. Product cleanup needs separate authorization and normal project review rules. A target version in an approved log entry means the descriptor's version, not the installed plugin version.
3. Verify the current target's postconditions before advancing, and compare the live result with the rehearsed `changes`; an unexplained difference is a failure. Keep execution evidence with the agreed external backup until the catalog exists; then consolidate it into catalog `migration.md` as the storage descriptor permits. Record migration ID, descriptor revision/hash, target version/layout, approved inventory, backup location, actual checks and completed/remaining steps. Mark partial/failure explicitly; advance the last verified release checkpoint only when every step for that release is verified. Never put this state in tracked product files or duplicate checkpoints for compliant records.
4. On interruption or changed inputs, stop later steps, preserve originals/backups/partial outputs and report recovery actions. Resume only verified identical copies; changed sources or destinations need reconciliation and a fresh preview/approval. Before rollback, export current/new work and restore the checkpoint only to the last verified restored target. Follow descriptor recovery instructions, never a destructive reset. Release the migration lock on completion, failure or handoff; reacquire/recheck after waiting for human input.
5. Report requested/last verified target, applied/skipped/pending IDs, changed files, backup/checkpoint locations, checks, conflicts and separately pending cleanup. Migration never makes a task ready or approved by itself. If any step remains incomplete, do not claim the project reached the requested version.