# Parameter Extraction

Defines how the spec-driven-migration skill resolves its input parameters from the conversation context markers set by the `/migrate-refs` command.

---

## Context Markers

The `/migrate-refs` command sets these context markers before invoking the skill (see SKILL.md "Command Integration"):

| Marker | Format | Example |
|--------|--------|---------|
| `$MIGRATION_ID` | Kebab-case session identifier | `source-tree-2026-05-19` |
| `$FROM_PATTERN` | Literal string the migration replaces | `source-tree.md` |
| `$TO_PATTERN` | Replacement string | `source-tree/` |
| `$SCOPE` | Glob list or comma-separated directory list | `.claude/agents/,.claude/skills/,…` |
| `$EXCLUSIONS` | Comma-separated glob patterns | `_archive/,/plans/` |
| `$DRY_RUN` | `true` or `false` | `false` |

---

## Extraction Algorithm

```
1. Scan conversation context for the marker block:

   **Migration ID:**  {value}
   **From Pattern:**  {value}
   **To Pattern:**    {value}
   **Scope:**         {value}
   **Exclusions:**    {value}
   **Dry Run:**       {value}

2. Extract each value (trim whitespace):
   MIGRATION_ID   = text after "**Migration ID:**"
   FROM_PATTERN   = text after "**From Pattern:**"
   TO_PATTERN     = text after "**To Pattern:**"
   SCOPE          = text after "**Scope:**"        (split on "," → array)
   EXCLUSIONS     = text after "**Exclusions:**"   (split on "," → array, "" → [])
   DRY_RUN        = text after "**Dry Run:**" == "true"

3. Validate:
   IF MIGRATION_ID is empty OR not kebab-case:
       HALT: "Invalid migration ID: {MIGRATION_ID}"
   IF FROM_PATTERN is empty:
       HALT: "No from_pattern specified"
   IF TO_PATTERN is empty:
       HALT: "No to_pattern specified"
   IF SCOPE is empty:
       HALT: "No scope directories specified"
   IF DRY_RUN not in {"true", "false"}:
       HALT: "Invalid Dry Run: {DRY_RUN}"
```

---

## Artifact Directory Lookup

All Phase 01–06 artifacts live under `tmp/${MIGRATION_ID}/`:

```
tmp/${MIGRATION_ID}/
├── intent.json                  # Phase 01 — 5-field migration intent
├── classification.md            # Phase 02 — classifier output
├── transform-rules.md           # Phase 03 — per-bucket transformation rules
├── clusters.json                # Phase 03 — cluster partition plan
├── phase-04-cluster-reports.md  # Phase 04 — consolidated cluster reports
└── session.md                   # Cross-phase session memory
```

Plus the checkpoint at the project-root level:

```
{project-root}/tmp/.migration-checkpoint-${SESSION_ID}.yaml
```

where `SESSION_ID = "MIG-" + ${MIGRATION_ID}`.

---

## Resume Detection Priority

When the skill is invoked, resume detection follows this priority (matches `[[project_source_tree_decomposition]]` precedent):

1. **Checkpoint present** → Read `tmp/.migration-checkpoint-${SESSION_ID}.yaml`, extract `current_phase` and `phase_completion`, jump to the first incomplete phase.
2. **Markers present but no checkpoint** → New migration; Phase 00 creates the checkpoint and walks through every phase.
3. **No markers, no checkpoint** → `AskUserQuestion`: "No migration context detected. Provide MIGRATION_ID, FROM_PATTERN, TO_PATTERN, SCOPE, EXCLUSIONS, DRY_RUN." Skill HALTs until the user supplies them.

---

## References

- `SKILL.md` "Command Integration" — the canonical marker list.
- `phase-00-context-loading.md` — Phase 00 reads markers + detects resume.
- `assets/templates/checkpoint-template.yaml` — checkpoint structure.
- `assets/templates/intent-template.json` — `intent.json` structure derived from these markers.
