<purpose>

Migrate `.planning/` from parallel to sequential organizational mode via a single atomic commit. Validates preconditions (clean working tree + parallel source + EXACTLY 1 milestone In Progress per SPEC D6 asymmetric safety HARD CONTRACT), relocates shipped milestone folders to `.planning/milestones/_archive/<slug>/` per SPEC §7 O3, commits as ONE atomic migration commit.

Phase 68-02 (v1.5.9 Parallel Milestone Organization, MIGR-02 + MIGR-03 partial) ships this command end-to-end:
- Library `bin/lib/migrate-to-sequential.js` (migrateToSequential + buildOpsList + executeMigration + readShippedMilestones; sibling tests 26/26 PASS including 2 mutation-RED probes + 1 round-trip test G1)
- CONSUMES `bin/lib/migrate-dry-run.js` (formatPlannedOperationsReport + EXIT_DRYRUN=10; FOUND-04 2nd-use-site — LOCKED signatures from Plan 68-01 honored verbatim)
- CLI dispatch arm in `bin/gmd-tools.cjs` parses --dry-run/--yes flags
- Slash-command shim at `C:/Users/Christopher/.claude/commands/gmd/migrate-to-sequential.md`

Fail-loud discipline (per 68-CONTEXT.md Area 3 + SPEC D6 + TD-07 + Phase 66 R3 precedent):
- Dirty-working-tree refuse (Gate 3 R1)
- Already-sequential refuse
- ASYMMETRIC SAFETY HARD CONTRACT: refuses unless EXACTLY 1 milestone In Progress. NO `--force` / `--allow-multi` override flag. Refusal message LOCKED byte-for-byte per SPEC D6 + CONTEXT.md Area 3.
- Zero In Progress refuse (anomalous parallel state — parallel mode with no active work has no sequential representation)

Asymmetric safety rationale (SPEC D6): Parallel mode can represent multiple concurrent In-Progress milestones. Sequential mode CANNOT — there is exactly one current milestone. So the migration refuses unless the source state is reducible (≤1 In Progress). The user must complete or archive one milestone before this command can proceed. No override flag exists because the asymmetry is structural, not stylistic.

`_archive/` relocation (SPEC §7 O3, resolved at Phase 68): shipped milestone folders move from `milestones/<slug>/` to `milestones/_archive/<slug>/` as PART OF this single migration commit. This is distinct from `/gmd:complete-milestone` (Phase 66-04 CMD-05), which leaves shipped milestones at top-level for `/gmd:list-milestones` consumption. Relocation belongs with the directional flip, not with normal completion.

NO D7 interactive prompt for this direction: research files all flatten to `.planning/research/` — sequential mode has one flat research dir; there is no ambiguity case (per CONTEXT.md Area 3 documented absence).

</purpose>

<required_reading>

Read all files referenced by the invoking prompt's execution_context before starting.

</required_reading>

<process>

## 0. Load Mode

Run the state-load init to retrieve organizational mode:

```bash
MODE=$(node bin/gmd-tools.cjs state load --raw 2>/dev/null | grep -i organizational_mode | cut -d= -f2 || echo "sequential")
```

If `MODE === 'sequential'`, the library refuses with the LOCKED message; surface the refusal and exit. The library is the single source of truth for refusal — the workflow does not re-implement validation.

Capture flag arguments: `--dry-run`, `--yes`.

## 1. Validate Source State (Asymmetric Safety)

Always run `--dry-run` internally as Step 1 to surface refuse messages BEFORE any prompts. The asymmetric-safety check fires here — the library refuses unless EXACTLY 1 milestone In Progress.

```bash
node bin/gmd-tools.cjs migrate-to-sequential --dry-run
DRYRUN_EXIT=$?
```

Outcomes:
- `exit 10` (EXIT_DRYRUN sentinel) → dry-run succeeded; report printed to stdout
- `exit 1` with stderr matching `refusing migration: <N> milestones In Progress` → asymmetric safety violation; workflow surfaces refuse message + exits 1
- `exit 1` with stderr matching `refusing migration: 0 milestones In Progress` → anomalous parallel state; workflow surfaces refuse message + exits 1
- `exit 1` with stderr matching `refusing migration: working tree not clean` → dirty-tree precondition violation
- `exit 1` with stderr matching `refusing migration: organizational_mode already 'sequential'` → directional mismatch
- Any other exit → unexpected; workflow exits non-zero with the captured message

The library NEVER accepts override flags (no `--force`, no `--allow-multi`). This is the SPEC D6 hard contract.

## 2. Display Planned Operations

The stdout from Step 1 is the planned-operations report (formatted by `formatPlannedOperationsReport` from `bin/lib/migrate-dry-run.js` — Plan 68-01 LOCKED signatures honored). Surface it verbatim so the user can review:

```
=== Planned Migration to sequential ===

## Planned File Moves
- mv .planning/milestones/<slug>/REQUIREMENTS.md → .planning/REQUIREMENTS.md
- mv .planning/milestones/<slug>/ROADMAP.md → .planning/ROADMAP.md
- mv .planning/milestones/<slug>/STATE.md → .planning/STATE.md
- mv .planning/milestones/<slug>/phases → .planning/phases
- mv .planning/milestones/<slug>/research/<file> → .planning/research/<file>
- archive shipped <shipped-slug> to milestones/_archive/ (if any shipped milestones)

## Planned Rewrites
- rewrite .planning/PROJECT.md: restore sequential "## Current Milestone" section
- rewrite .planning/MILESTONES.md: rewrite to retrospective log shape

## Planned Config Flip
- config.json organizational_mode: parallel → sequential

## Planned STATE.md Init
(none — current_milestone pointer is CLEARED, not initialized; see catch-all section below)

## Planned Rollback Command
- git reset --hard HEAD && git clean -fd <touched-paths-joined>
```

If `--dry-run` was passed by the user (NOT an internal step-1 dry-run), exit 0 here without proceeding — the report is the deliverable.

## 3. Confirm

If `--yes` was NOT passed, ask one final confirmation:

```
Proceed with migration to sequential mode? This is a one-direction change for current parallel state. [y/N]
```

Default is `N` (safer). On `n` / empty / non-y input, print `Migration cancelled.` and exit 0.

There is NO D7 interactive prompt for this direction — research files all flatten to `.planning/research/` (no ambiguity case per CONTEXT.md Area 3 documented absence).

## 4. Execute Migration

Re-invoke the CLI without `--dry-run`:

```bash
EXEC_FLAGS=""
if [[ "$YES" == "true" ]]; then EXEC_FLAGS="$EXEC_FLAGS --yes"; fi

node bin/gmd-tools.cjs migrate-to-sequential $EXEC_FLAGS
EXEC_EXIT=$?
```

The library re-validates all preconditions (defense-in-depth — Step 1's dry-run state may have drifted between Step 2 and Step 4) and executes the single-commit atomic migration:

1. Move `.planning/milestones/<in-progress-slug>/{REQUIREMENTS.md, ROADMAP.md, STATE.md, phases/}` to `.planning/` root
2. Flatten research files: `.planning/milestones/<in-progress-slug>/research/*` to `.planning/research/`
3. Preserve `MILESTONE.md` content as audit trail at `.planning/milestones/_archive/<in-progress-slug>-MILESTONE-source.md` then remove the original
4. Relocate shipped milestone folders to `.planning/milestones/_archive/<shipped-slug>/`
5. Rewrite `.planning/PROJECT.md` to restore the sequential-mode `## Current Milestone` section
6. Rewrite `.planning/MILESTONES.md` to retrospective log shape
7. Flip `.planning/config.json::organizational_mode` from `parallel` to `sequential`
8. Clear root `.planning/STATE.md` `current_milestone:` field (via `setCurrentMilestone(cwd, null)`)
9. `git add -A` then `git commit -m "migrate(sequential): v1.5.9 .planning/ organization → sequential"` (LOCKED subject; single commit)

On any mid-step failure, the library performs scoped rollback (`git reset --hard HEAD && git clean -fd <touched-paths>`) and throws; this workflow surfaces the error and exits non-zero.

## 5. Report Result

On success (exit 0), the CLI prints:

```
Migrated to sequential. .planning/ now flat. Commit: <short-sha>
```

Surface the message and recommend the next action:

```
Migrated to sequential. .planning/ now flat.
Run /gmd:progress for current-milestone status.
/gmd:migrate-to-parallel <slug> can re-enter parallel mode if needed.
```

</process>

<failure_handling>

ALL refusals are emitted by the library to stderr with EXIT 1. The workflow surfaces them verbatim — never paraphrases. LOCKED refusal messages (asserted byte-for-byte in `bin/lib/migrate-to-sequential.test.cjs`):

- Dirty tree: `refusing migration: working tree not clean. Commit or stash changes before running /gmd:migrate-to-sequential.`
- Already sequential: `refusing migration: organizational_mode already 'sequential'. /gmd:migrate-to-sequential is parallel→sequential only.`
- Asymmetric safety violation (LOAD-BEARING per SPEC D6 + CONTEXT.md Area 3): `refusing migration: <N> milestones In Progress (<slug-A>, <slug-B>, ...); complete or archive one before migrating to sequential. Sequential mode cannot represent multiple concurrent milestones.` — NO `--force` / `--allow-multi` override flag accepted.
- Zero In Progress: `refusing migration: 0 milestones In Progress; parallel mode with no active work has no sequential representation. Initialize a milestone first via /gmd:new-milestone.`

Mid-step failure rollback: scoped via `git reset --hard HEAD && git clean -fd <touched-paths>` (NOT global `git clean -fd .`). Touched-paths list is incrementally built during `buildOpsList` and always includes `.planning/milestones/_archive/` so the audit-trail-preservation dir is cleaned on rollback. The library catches the original error, performs rollback, re-throws — the workflow exits non-zero with the original message.

</failure_handling>

<carryforward>

DEFER-65-01 (per Phase 65 VERIFICATION carry-forward #3): this workflow does NOT add new templates. The slash-command shim at `C:/Users/Christopher/.claude/commands/gmd/migrate-to-sequential.md` is the only new authoring surface beyond this file. Per-plan `cp + diff -q + git add -f` discipline holds for `workflows/migrate-to-sequential.md` mirror; no SCOPES extension needed (Phase 69 DOC-01 work).

P1 sequential-mode byte-identical regression: this migration command is ADDITIVE. Existing sequential-mode commands (e.g., `/gmd:progress`, `/gmd:plan-phase`, `/gmd:execute-phase` against sequential-mode projects) are unchanged in this plan. Final P1 verification via Task 2's automated probes against ship anchor a9e6cd4.

Phase 66-04 CMD-05 surface UNCHANGED: `workflows/complete-milestone.md` Step 7 `parallel_milestone_finalize` retains leave-at-top-level semantics for `/gmd:list-milestones` consumption (Test C4 grep proof in sibling test battery). `_archive/` relocation lives in `/gmd:migrate-to-sequential` per CONTEXT.md Area 3 + SPEC §7 O3 resolution, NOT in `/gmd:complete-milestone`.

Plan 68-03 inherits the round-trip test G1 substrate (sequential → parallel → sequential identity modulo D9 allowed-differ) as the foundation for the tradesrv3 D9 set-equal acceptance test.

</carryforward>
