---
title: Stage 1 - Data & Models (Foundation)
status: IN_PROGRESS
priority: HIGH
---

## Core Objectives
Establish the underlying database structure and filesystem mirroring required for the Co-Worker agent's state management.

## Task Breakdown
- [x] **DB Model Update**: Modify the backend `AgentInstance` model (PostgreSQL/MongoDB as applicable) to include:
    - [x] `co_worker_enabled`: (Boolean) Default: `False`.
    - [x] `rework_threshold`: (Integer) Range 0-100. Default: `80`.
    - [x] `max_rework_count`: (Integer) Default: `3`.
- [x] **Workspace Mirroring**:
    - [x] Create `.cortex/` directory in the agent's unique jail during initialization.
    - [x] Implement `history.log` append logic (JSON format).

## Claude Code Inspiration: Memory Context
*Reference: `src/memdir/memdir.ts`*
- Ensure the `.cortex/` directory exists immediately on agent startup (idempotent initialization).
- Use a single line append-only JSON format for `history.log` to prevent partial write corruption.
