{%- set protocol = dialogue_protocol if dialogue_protocol else {} -%}
{%- set on_start = protocol.get('on_start', {}) -%}
{%- set on_end = protocol.get('on_end', {}) -%}
{%- set flow = protocol.get('standard_flow', []) -%}
{%- set read_files = on_start.get('read_files', []) -%}
{%- set update_files = on_end.get('update_files', []) -%}
## 4.2 Standard Dialogue Flow

### 4.2.0 On Dialogue Start (mandatory)

> **At the start of every new dialogue, the AI must first restore the current state**

```
{% for f in read_files -%}
{{ loop.index }}. Read {{ f }}
{% endfor -%}
{% for action in on_start.get('actions', []) -%}
{{ read_files | length + loop.index }}. {{ action }}
{% endfor -%}
```

**Insight Retrieval (recommended)**:
- If the project has a `.vibecollab/insights/` directory, run `vibecollab insight search --tags <current task keywords>` to find relevant experience
- Search results help avoid repeating mistakes and reuse verified solutions
- You can also use `vibecollab insight list` to browse all insights

**Project Initialization Constraint**:
- If this is a new project without a `.git` directory, you must run `git init` to initialize the repository
- After initialization, perform the first commit immediately: `git add -A && git commit -m "init: project initialization"`
- Git is the foundation for collaboration tracking; without Git, effective version tracking is impossible

### 4.2.1 On Dialogue End (mandatory)

> **Before ending each dialogue, the AI must save the current state**

```
{%- set step_num = [0] -%}
{% for f in update_files -%}
{%- set _ = step_num.append(step_num.pop() + 1) -%}
{{ step_num[0] }}. Update {{ f }}
{% endfor -%}
{%- set _ = step_num.append(step_num.pop() + 1) -%}
{{ step_num[0] }}. Insight check -> any experience worth recording? (vibecollab insight add)
{% if on_end.get('git_commit', True) -%}
{%- set _ = step_num.append(step_num.pop() + 1) -%}
{{ step_num[0] }}. Git commit -> record dialogue outcomes
{% endif -%}
```

### 4.2.2 Standard In-Dialogue Flow

```
{% for step in flow -%}
{%- set actor = "[Human]" if step.get('actor') == 'human' else "[AI]" -%}
{{ step.get('step', '') }}. {{ actor }} {{ step.get('action', '') }}{% if step.get('condition') %} <- condition: {{ step.get('condition') }}{% endif %}
{% if not loop.last %}       |
{% endif -%}
{% endfor -%}
```
