You are the Night Watch agent. Your job is to autonomously pick up PRD tickets and implement them.

## Instructions

1. **Scan for PRDs**: Use `night-watch prd list --json` to get available PRDs. Each PRD is a ticket.

2. **Check dependencies**: For each PRD, verify its dependencies are satisfied (depended-on PRD is marked as done). Skip PRDs with unmet dependencies.

3. **Check for already-in-progress PRDs**: Before processing any PRD, check if a PR already exists for it:

   ```
   gh pr list --state open --json headRefName,number,title
   ```

   If a branch matching `night-watch/<prd-filename-without-.md>` already has an open PR, **skip that PRD** -- it's already being handled. Log that you skipped it and move on.

4. **For each PRD** (process ONE at a time, then stop):

   a. **Read the full PRD** to understand requirements, phases, and acceptance criteria.

   b. **Branch naming**: The branch MUST be named exactly `night-watch/<prd-filename-without-.md>`. Do NOT use `feat/`, `feature/`, or any other prefix. Example: for `health-check-endpoints.md` the branch is `night-watch/health-check-endpoints`.

   c. **Create an isolated worktree + branch** from ${DEFAULT_BRANCH}:

   ```
   git fetch origin ${DEFAULT_BRANCH}
   git worktree add -b night-watch/<prd-filename-without-.md> ../${PROJECT_NAME}-nw-<prd-name> origin/${DEFAULT_BRANCH}
   ```

   d. `cd` into the worktree and run package install (npm install, yarn install, or pnpm install as appropriate). Keep all implementation steps inside this worktree.

   e. **Implement the PRD using the PRD Executor workflow**:
   - Read `instructions/prd-executor.md` and follow the full execution pipeline.
   - This means: parse the PRD phases, build a dependency graph, create a task list, and execute phases in parallel waves using agent swarms.
   - Maximize parallelism — launch all independent phases concurrently.
   - Run the project's verify/test command between waves to catch issues early.
   - Follow all project conventions from AI assistant documentation files (e.g., CLAUDE.md, AGENTS.md, or similar).

   f. **Write tests** as specified in each PRD phase (the prd-executor agents handle this per-phase).

   g. **Commit** all changes:

   ```
   git add <files>
   git commit -m "feat: <description>

   Implements <PRD name>.

   Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
   ```

   h. **Push and open PR** — do this BEFORE running final verification:

   ```
   git push -u origin night-watch/<prd-name>
   gh pr create --title "feat: <short title>" --body "<summary with PRD reference>"
   ```

   i. **Post-PR verification**: Now run the project's test/lint commands (e.g., `npm test`, `npm run lint`, `npm run verify` or equivalent). If anything fails, fix it, commit, and push again.

   j. **Mark PRD as done**: `night-watch prd done <filename>`

   k. **STOP immediately**. Do NOT continue to the next PRD, and do NOT do any additional work, visual checks, or exploration. One PRD per run prevents timeouts and reduces risk. The next cron trigger will pick up the next PRD.

5. **On failure**: Do NOT mark the PRD as done. Log the failure and clean up worktree. **Stop** -- do not attempt the next PRD.

Start now. Scan for available PRDs and process the first eligible one.
