# EM Planner Windowed Execution Bootstrap Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Initialize the single cross-window EM Planner progress file with verified protocol state and a complete Stage 1 startup prompt.

**Architecture:** Keep all durable cross-window state in one committed Markdown file. The file points to the approved design and implementation plans, records that no implementation stage has started, preserves the known dirty-worktree baseline, and gives the next Codex window enough exact instructions to execute only Foundation Tasks 1–3.

**Tech Stack:** Markdown, Git, PowerShell validation, existing EM Planner design and implementation plans.

## Global Constraints

- Follow `docs/superpowers/specs/2026-08-03-em-planner-windowed-execution-design.md` exactly.
- Create only `docs/superpowers/progress/em-planner-progress.md` during this bootstrap.
- Stage 1 begins in `NotStarted`; no EM production or test code is implemented in this bootstrap.
- The branch is `trajplanner` and the protocol design baseline is commit `554c84f`.
- The five EM implementation plans are anchored by commit `8dd8ff0`.
- Existing unrelated worktree changes remain untouched and unstaged.
- Never use `git add .`, `git add -A`, destructive reset, checkout restoration, or untracked-file cleanup.
- The initial next-window prompt must prohibit subagents and restrict execution to Foundation Tasks 1–3.
- The progress checkpoint is committed separately from every later functionality commit.

---

## Locked File Structure

```text
docs/superpowers/progress/
└── em-planner-progress.md
```

### Task 1: Initialize the Cross-Window Progress Checkpoint

**Files:**
- Create: `docs/superpowers/progress/em-planner-progress.md`

**Interfaces:**
- Consumes: design commit `554c84f`, plan commit `8dd8ff0`, the ten-stage mapping, and the existing dirty-worktree baseline.
- Produces: the durable Stage 1 entry state and a complete prompt for a fresh Codex window.

- [ ] **Step 1: Run the failing precondition check**

Run:

```powershell
$progress = 'docs/superpowers/progress/em-planner-progress.md'
if (Test-Path -LiteralPath $progress) {
    throw "Progress file already exists; inspect it instead of overwriting it."
}
throw "Expected bootstrap failure: progress file does not exist."
```

Expected: nonzero exit with `Expected bootstrap failure: progress file does not exist.` If the file already exists, stop and reconcile it with the design rather than replacing user state.

- [ ] **Step 2: Verify protocol and plan baselines before creating state**

Run:

```powershell
git cat-file -e '554c84f^{commit}'
if ($LASTEXITCODE -ne 0) { throw 'Windowed-execution design commit is missing.' }
git cat-file -e '8dd8ff0^{commit}'
if ($LASTEXITCODE -ne 0) { throw 'EM implementation-plan commit is missing.' }
if ((git branch --show-current) -ne 'trajplanner') { throw 'Expected trajplanner branch.' }
$staged = @(git diff --cached --name-only)
if ($staged.Count -ne 0) { throw "Unexpected staged files: $($staged -join ', ')" }
Write-Output 'PASS windowed-execution bootstrap prerequisites'
```

Expected: `PASS windowed-execution bootstrap prerequisites` and exit code `0`.

- [ ] **Step 3: Create the exact initial progress document**

Create the file with this complete content:

````markdown
# EM Planner Execution Progress

## Current State

- Current stage: 1 — Foundation contracts and boundaries
- Stage status: NotStarted
- Current branch: `trajplanner`
- Last checkpoint commit: None; Stage 1 has not started
- Protocol design baseline: `554c84f`
- Implementation-plan baseline: `8dd8ff0`

## Completed Tasks

| Stage | Plan | Tasks | Commits | Verification |
|---:|---|---|---|---|
| — | — | — | — | No implementation task has started |

## Current Verification

- Commands:
  - `git cat-file -e 554c84f^{commit}`
  - `git cat-file -e 8dd8ff0^{commit}`
  - `git branch --show-current`
  - `git diff --cached --name-only`
- Result: Bootstrap prerequisites passed; Stage 1 entry is ready
- Verified commit: `554c84f` for protocol design and `8dd8ff0` for implementation plans

## Preserved Workspace State

- The workspace already contains many unrelated Map, CoarsePath, PathSmoothing, project-file, report, and documentation changes. They belong to the user and must remain untouched and unstaged.
- Use explicit file paths for every `git add`; never stage the whole workspace.
- Inspect the existing diff before modifying `ClumsyPilot/ClumsyPilot.csproj`, then append only the Stage 1 rules required by the Foundation plan.
- The normal `ClumsyPilot.csproj` build can be blocked by legacy `auto_avoidance/MultiWheelAutoAvoidance.cs` references to `NetTopologySuite` and `OpenCvSharp`.
- Stage 1 must use the isolated `EMPlannerVerificationHost` rule from the Foundation plan. Do not delete or rewrite legacy functionality to hide the baseline build failure.

## Decisions Needed

- None. The Stage 1 scope and contracts are approved.

## Next Stage

- Stage: 1 — Foundation contracts and boundaries
- Plan: `docs/superpowers/plans/2026-08-03-em-planner-foundation-implementation.md`
- Tasks:
  - Task 1 — Verification Host and Immutable Contracts
  - Task 2 — Configuration, Diagnostics, and Request Validation
  - Task 3 — Direction Segmentation and Exact Boundary Anchors
- Entry checks:
  - Confirm branch `trajplanner`.
  - Confirm commits `554c84f` and `8dd8ff0` exist.
  - Confirm the staging area is empty.
  - Capture `git status --short` before editing.
  - Confirm no prior Stage 1 functionality commit is recorded; if EM files already exist, inspect and reconcile them before continuing.
- Exit gate:
  - Each of Foundation Tasks 1–3 has its own passing verification and independent commit.
  - The Foundation verification host passes `foundation` and `segmentation` groups required through Task 3.
  - Exact gear-switch approach/departure identities and exact horizon anchors are verified.
  - `git diff --check` reports no new whitespace errors.
  - The staging area is empty after all task commits.
  - This progress file is updated to mark Stage 1 completed and Stage 2 ready, then committed alone.

## Next-Window Prompt

```text
请继续 ParkingRobot 仓库的 EM Planner 多窗口实施。

工作目录：D:\Users\Desktop\项目\prakrobot\ParkingRobot

本窗口是阶段 1：Foundation 契约与边界，只执行 Foundation 实施计划的 Task 1–3，不得提前执行 Task 4 或后续阶段。

开始工作前必须完整读取：
1. docs/superpowers/specs/2026-08-03-em-planner-ls-st-design.md
2. docs/superpowers/specs/2026-08-03-em-planner-windowed-execution-design.md
3. docs/superpowers/progress/em-planner-progress.md
4. docs/superpowers/plans/2026-08-03-em-planner-foundation-implementation.md

执行时使用 executing-plans、test-driven-development 和 verification-before-completion 技能，并完整读取对应 SKILL.md。不要使用子代理。

开始前：
- 确认工作目录和分支 trajplanner；
- 确认提交 554c84f 与 8dd8ff0 存在；
- 检查 git status --short 和暂存区；
- 保存开始时的工作区状态用于结束时对照；
- 当前工作区存在大量用户修改，全部保留，不得清理、覆盖或顺带提交；
- 如果进度文件、Git 或实际文件不一致，先诊断并报告，不要直接覆盖。

阶段范围：
- Task 1：Verification Host and Immutable Contracts；
- Task 2：Configuration, Diagnostics, and Request Validation；
- Task 3：Direction Segmentation and Exact Boundary Anchors。

执行要求：
- 严格按 Foundation 计划逐任务进行 TDD；
- 每个任务先运行计划指定的失败验证，再实现最小内容，再运行通过验证；
- 每个任务形成独立提交，只用显式路径 git add；
- 修改 ClumsyPilot/ClumsyPilot.csproj 前先查看现有差异，只追加本阶段要求；
- 不修改无关 Map、CoarsePath、PathSmoothing 和旧 auto_avoidance 文件；
- 不实现 Frenet、静态走廊、OSQP、LS、ST、滚动执行或动态障碍功能；
- 主项目既有 auto_avoidance 依赖失败不能通过删除旧功能规避；使用计划中的隔离验证宿主；
- 任何完成声明前运行计划指定验证和 git diff --check。

阶段结束时：
- 确认 Task 1–3 各有独立提交和测试证据；
- 运行截至 Task 3 的 Foundation 阶段出口验证；
- 核对每个提交只包含计划文件，暂存区为空；
- 更新 docs/superpowers/progress/em-planner-progress.md：记录提交、验证命令和结果，将阶段 1 标为 Completed，将阶段 2 标为 ready；
- 只暂存进度文件并单独提交阶段检查点；
- 返回本阶段完成内容、提交列表、测试证据、遗留问题；
- 给出阶段 2 可直接复制的新窗口提示词。
```
````

- [ ] **Step 4: Validate structure, task scope, and prompt completeness**

Run:

```powershell
$progress = 'docs/superpowers/progress/em-planner-progress.md'
$content = Get-Content -LiteralPath $progress -Raw -Encoding UTF8
$required = @(
    'Stage status: NotStarted',
    'Protocol design baseline: `554c84f`',
    'Implementation-plan baseline: `8dd8ff0`',
    'Task 1 — Verification Host and Immutable Contracts',
    'Task 2 — Configuration, Diagnostics, and Request Validation',
    'Task 3 — Direction Segmentation and Exact Boundary Anchors',
    '不要使用子代理',
    '不得提前执行 Task 4',
    '只暂存进度文件并单独提交阶段检查点'
)
foreach ($term in $required) {
    if (-not $content.Contains($term)) { throw "Missing progress item: $term" }
}
if ($content.Contains('Task 4 — Reverse-Safe')) { throw 'Stage 1 prompt includes Stage 2 implementation.' }
$fences = ([regex]::Matches($content, '```')).Count
if (($fences % 2) -ne 0) { throw "Unbalanced code fences: $fences" }
git diff --check -- $progress
if ($LASTEXITCODE -ne 0) { throw 'Progress-file diff check failed.' }
Write-Output 'PASS initial EM Planner progress checkpoint'
```

Expected: `PASS initial EM Planner progress checkpoint` and exit code `0`.

- [ ] **Step 5: Commit only the initialized progress checkpoint**

Run:

```powershell
$progress = 'docs/superpowers/progress/em-planner-progress.md'
$before = @(git diff --cached --name-only)
if ($before.Count -ne 0) { throw "Unexpected staged files: $($before -join ', ')" }
git add -- $progress
$staged = @(git diff --cached --name-only)
if ($staged.Count -ne 1 -or $staged[0] -ne $progress) {
    throw "Staged scope is not progress-only: $($staged -join ', ')"
}
git diff --cached --check
if ($LASTEXITCODE -ne 0) { throw 'Staged diff check failed.' }
git commit -m "docs: initialize EM planner execution progress"
```

Expected: one commit containing only `docs/superpowers/progress/em-planner-progress.md`; the staging area is empty afterward.

## Completion Gate

- The progress file exists and names Stage 1 as `NotStarted`.
- It references the approved design and implementation-plan commits.
- It contains Foundation Tasks 1–3 exactly and excludes Stage 2 implementation.
- It records dirty-worktree and legacy-build protections.
- Its Stage 1 prompt is directly copyable into a fresh Codex window.
- The bootstrap commit contains only the progress file.
