# Vibe Kanban Scripts

This directory contains all scripts specifically for Vibe Kanban integration.

## Scripts

### `vibe-setup.sh`
**Purpose:** Sets up the database and Docker services for a Vibe Kanban task environment.

**Usage:**
```bash
bash scripts/vibe-kanban/vibe-setup.sh [TASK_ID] [PORT_OFFSET]
```

**What it does:**
- Detects or generates a consistent TASK_ID for the worktree
- Auto-detects available port offset
- Creates Docker Compose file for the task
- Starts PostgreSQL and Redis containers
- Copies database from main repository
- Saves configuration to `.vibe-setup.env`

**Configuration saved:**
- Task ID
- Port offsets
- Database names
- All connection details

**Note:** This script runs in the "setup" section of Vibe Kanban.

---

### `vibe-dev-server.sh`
**Purpose:** Starts the API and Workers processes (assumes database is already set up).

**Usage:**
```bash
bash scripts/vibe-kanban/vibe-dev-server.sh
```

**What it does:**
- Loads configuration from `.vibe-setup.env` (created by vibe-setup.sh)
- Verifies database is ready
- Starts API and Workers using `start-api-and-workers.sh`
- Displays logs with filtered warnings
- Shows API and Workers logs in real-time

**Requirements:**
- Must run `vibe-setup.sh` first to create the database environment
- Configuration file `.vibe-setup.env` must exist

**Note:** This script runs in the "dev server" section of Vibe Kanban.

---

### `cleanup-api-workers.sh`
**Purpose:** Stops API and Workers processes for a specific task.

**Usage:**
```bash
bash scripts/vibe-kanban/cleanup-api-workers.sh <TASK_ID>
```

**What it does:**
- Stops API process (and child processes)
- Stops Workers process (and child processes)
- Kills orphaned processes
- Removes PID files
- Preserves log files for debugging

**Features:**
- Graceful shutdown (SIGTERM) with fallback to force kill (SIGKILL)
- Handles orphaned processes
- Works with Vibe Kanban worktrees
- Supports environment variables for TASK_ID

**Note:** This script is used by Vibe Kanban for cleanup operations.

---

## Workflow

1. **Setup Phase** (Vibe Kanban "setup" section):
   ```bash
   bash scripts/vibe-kanban/vibe-setup.sh
   ```
   - Sets up database and Docker services
   - Creates configuration file

2. **Dev Server Phase** (Vibe Kanban "dev server" section):
   ```bash
   bash scripts/vibe-kanban/vibe-dev-server.sh
   ```
   - Starts API and Workers
   - Shows logs

3. **Cleanup Phase** (Vibe Kanban cleanup):
   ```bash
   bash scripts/vibe-kanban/cleanup-api-workers.sh <TASK_ID>
   ```
   - Stops all processes
   - Cleans up

## Configuration Files

These scripts create/use the following files in the worktree:

- `.vibe-task-id` - Stores the persistent TASK_ID for the worktree
- `.vibe-setup.env` - Stores all setup configuration (ports, database names, etc.)
- `.task-pids/` - Directory containing PID files and logs

## Paths

All paths in these scripts are relative to the main repository:
- Main repo: `/Users/oda/Desktop/Projects/managing-apps`
- Scripts: `scripts/vibe-kanban/`
- Worktree: Detected automatically from current directory

## Environment Variables

These scripts support the following environment variables:

- `VIBE_TASK_ID` - Task ID from Vibe Kanban
- `VIBE_TASK_NAME` - Task name from Vibe Kanban
- `VIBE_WORKTREE_ROOT` - Worktree root path (set automatically)

