---
phase: 01.6
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - src/gsd_lite/template/PROTOCOL.md
  - src/gsd_lite/template/workflows/moodboard.md
  - src/gsd_lite/template/workflows/whiteboard.md
autonomous: true
must_haves:
  truths:
    - "Agent checks file existence before writing any artifact"
    - "Agent reads existing files to preserve examples and user data"
    - "Protocol explicitly forbids overwriting existing files with templates"
  artifacts:
    - path: "src/gsd_lite/template/PROTOCOL.md"
      contains: "## 🛡️ Safety Protocol"
    - path: "src/gsd_lite/template/workflows/moodboard.md"
      contains: "Initialization Check"
    - path: "src/gsd_lite/template/workflows/whiteboard.md"
      contains: "Initialization Check"
  key_links:
    - from: "src/gsd_lite/template/workflows/moodboard.md"
      to: "src/gsd_lite/template/STATE.md"
      via: "read-before-write"
---

<objective>
Prevent data loss by ensuring agents read and adopt existing scaffolded files (STATE.md, WORK.md) instead of overwriting them with blank templates during initialization.

Purpose: Fix critical issue where agents wipe user data/examples by "initializing" over existing files.
Output: Updated PROTOCOL.md and workflow files with strict "Read-First" safety rules.
</objective>

<execution_context>
@~/.config/opencode/get-shit-done/workflows/execute-plan.md
@~/.config/opencode/get-shit-done/templates/summary.md
</execution_context>

<context>
@src/gsd_lite/template/PROTOCOL.md
@src/gsd_lite/template/workflows/moodboard.md
@src/gsd_lite/template/workflows/whiteboard.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add Global Safety Protocol</name>
  <files>src/gsd_lite/template/PROTOCOL.md</files>
  <action>
    Read PROTOCOL.md and add a high-visibility "Safety Protocol" section near the top (after header).
    
    Content to insert:
    ## 🛡️ Safety Protocol (CRITICAL)
    **NEVER overwrite existing artifacts with templates.**
    Before writing to `STATE.md`, `WORK.md`, or `INBOX.md`:
    1. **Check existence:** run `ls gsd-lite/` (or check directory listing)
    2. **Read first:** If file exists, `read` it to understand current state.
    3. **Append/Update:** Only add new information or update specific fields.
    4. **Preserve:** Keep all existing history, loops, and decisions.
  </action>
  <verify>grep "Safety Protocol" src/gsd_lite/template/PROTOCOL.md</verify>
  <done>PROTOCOL.md contains explicit rules against overwriting files.</done>
</task>

<task type="auto">
  <name>Task 2: Add Initialization Checks to Workflows</name>
  <files>src/gsd_lite/template/workflows/moodboard.md, src/gsd_lite/template/workflows/whiteboard.md</files>
  <action>
    1. Update `moodboard.md`:
       - Add "Initialization Check" section before "Entry Conditions".
       - Instruction: "Check if `STATE.md` exists. If yes, READ IT and ADOPT current state. Do NOT overwrite with template."
    
    2. Update `whiteboard.md`:
       - Add "Initialization Check" section.
       - Instruction: "Check if `WORK.md` exists. If yes, READ IT. Append new plan to it. Do NOT overwrite."
  </action>
  <verify>grep "Initialization Check" src/gsd_lite/template/workflows/moodboard.md && grep "Initialization Check" src/gsd_lite/template/workflows/whiteboard.md</verify>
  <done>Workflows explicitly instruct agent to check for file existence before initializing.</done>
</task>

</tasks>

<verification>
grep "Safety Protocol" src/gsd_lite/template/PROTOCOL.md
grep "Initialization Check" src/gsd_lite/template/workflows/moodboard.md
</verification>

<success_criteria>
- PROTOCOL.md forbids overwriting artifacts
- moodboard.md mandates reading STATE.md before writing
- whiteboard.md mandates reading WORK.md before writing
</success_criteria>

<output>
After completion, create `.planning/phases/01.6-fix-agent-overriding-examples-in-scaffolded-file/01.6-01-SUMMARY.md`
</output>
