---
description: "Prepare phase: register sites and create batches"
agent: build
---

# LLM Prepare Command Instructions

## Goal
Register sites into REGISTRY and create batches (with locking) before design/implement. Prepare phase is independent and can run concurrently with design/implement for other batches.

## Inputs
- `sites.csv` at repo root (domain, theme columns)
- `.wdmaker/config.toml` for temp_dir configuration

---

## General Rules (Main Agent AND Subagents)

### G1. Script Execution
**Run shell scripts directly (all Python scripts have .sh wrappers):**
- All shell scripts have shebangs (`#!/bin/bash`).
- Execute them directly: `tools/script.sh`
- **Do NOT** add `sh` or `bash` prefix (e.g., `bash tools/script.sh` is WRONG).

**NEVER run Python directly or create Python scripts.**

### G2. No Invented Commands
- **DO NOT create new bash commands or scripts**
- **DO NOT use ad-hoc shell commands** (cat/ls/find/grep/wc/for-loops)
- Use ONLY the provided assist scripts listed below

### G3. No HEREDOC Pattern
- **NEVER use HEREDOC** (`<<EOF`, `<<'EOF'`, etc.) for ad-hoc file writing
- Use **Write tool** or **Filesystem MCP server** when writing new files

### G4. Temp Directory
- Use `${TMP}` from `.wdmaker/config.toml` for temporary files
- **NEVER use `/tmp`** — always use the configured temp directory

### G5. Directory Creation
- **Use provided scripts** for creating/preparing directories
- **NEVER use `mkdir`** directly
- **DO NOT create `.gitkeep`**, `.keep`, or similar placeholder files

### G6. Preserve Reports
- **DO NOT delete** generated reports (batch reports, registry backups, logs)

---

## Steps for LLM (non-interactive)

> **Note:** General Rules (G1-G6) apply to ALL steps below.

### Step 1: Check Environment
Execute:
```bash
tools/prepare/info.sh --root .
```
Use this instead of `ls`/`cat` to preview config and sites.csv.
Never use other commands to check environment.

If `sites.csv` doesn't exist, report user its absence and stop here.

### Step 2: Validate and Register

**Note:** The Read tool is explicitly allowed here for checking REGISTRY existence (exception to G2).

Check existence of `.smbatcher/REGISTRY.md` using the Read tool.

If file does not exist (Read returns error), run validation then registration:
```bash
tools/check/site-list.sh sites.csv
```
```bash
tools/prepare/register.sh --input-file sites.csv
```

If file exists, proceed to Step 3.

### Step 3: Create Batch
```bash
tools/prepare/batch.sh --version v1 --batch-size 20 --input-file sites.csv
```
Modify version (v1) and batch-size (20) based on user request.

### Step 4: Verify Registration
```bash
tools/check/status-report.sh
```

---

## Outputs
- New `Batch_<ID>.md` in `.smbatcher/batches/` listing domains/themes/status.
- Updated sites in new batch as B at `.smbatcher/REGISTRY.md`
- Site directories under `sites/<domain-vX>/`.

## Status Code Flow
```
- (none) -> B (batched) -> d (designing) -> D (designed) -> O (open) -> i (implementing) -> I (implemented) -> Q (complete)
```
