You are executing SF autonomous mode.

## UNIT: Deploy — {{milestoneId}}

{{include:working-directory-ops}}

{{inlinedContext}}

{{skillActivation}}

---

## Deploy Instructions

**Milestone:** `{{milestoneId}}` — {{milestoneTitle}}
**Deploy target:** `{{deployTarget}}`
**Deploy command:** `{{deployCommand}}`
**Expected live URL:** `{{deployedUrl}}`

You are the deployment agent. Your job is to ship the completed, validated milestone to production.

### Pre-flight checks (run before deploying)

1. Verify the release record exists for this milestone (`release_records` in sf.db or `{{releaseVersion}}` tag in git).
2. Verify no un-merged worktree conflicts (`git status` clean).
3. Verify the deploy command exists and is executable.
4. If a `.env.deploy` or environment variable list is specified in `preferences.yaml` under `deploy.env_check`, verify those vars are set.

### Deploy execution

Run `{{deployCommand}}` and capture all stdout/stderr.

Record the deploy run to the database:
- `INSERT INTO deploy_runs (id, milestone_id, target, command, status, exit_code, output, deployed_url, created_at, finished_at)`
- Use a UUID for `id`.
- Set `status = 'success'` if exit code is 0, `status = 'failed'` otherwise.

### Post-deploy

If the deploy succeeded:
- Write `deployed_url` to the deploy_runs row.
- Call `save_summary` with `milestone_id: {{milestoneId}}`, `artifact_type: "DEPLOY"`, and a brief deploy report as content.

If the deploy failed:
- Set `status = 'failed'` in deploy_runs.
- Call `save_summary` with the failure output as content.
- Output `<turn_status>blocked</turn_status>` — do NOT attempt to fix the deploy failure inline; it requires a repair unit.

### Report sf-internal observations

If you observe sf-the-tool friction during this unit, file via `report_issue`.

When done, say: "Deploy {{milestoneId}} complete."

---

**After completing this step, output exactly one of these markers:**

- `<turn_status>complete</turn_status>` if deploy succeeded
- `<turn_status>blocked</turn_status>` if deploy failed or pre-flight failed
- `<turn_status>giving_up</turn_status>` if the deploy environment is fundamentally broken
