diff --git a/Makefile b/Makefile index f9030c2cca..7290907133 100644 --- a/Makefile +++ b/Makefile @@ -217,4 +217,5 @@ clean-web: .PHONY: clean-db clean-db: @echo "Removing local SQLite database..." - @rm -f kandev.db $(BACKEND_DIR)/kandev.db + @rm -f kandev.db kandev.db-wal kandev.db-shm \ + $(BACKEND_DIR)/kandev.db $(BACKEND_DIR)/kandev.db-wal $(BACKEND_DIR)/kandev.db-shm diff --git a/apps/backend/Makefile b/apps/backend/Makefile index 966ef0fd5d..3c8e24f1f8 100644 --- a/apps/backend/Makefile +++ b/apps/backend/Makefile @@ -14,7 +14,7 @@ BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') LDFLAGS += -X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.BuildTime=$(BUILD_TIME) -.PHONY: all build build-all build-agentctl clean run dev dev-db dev-db-reset test lint fmt vet help +.PHONY: all build build-all build-agentctl clean run dev test lint fmt vet help ## Default target all: build @@ -47,24 +47,10 @@ run: build @echo "Running $(BINARY_NAME)..." ./$(BUILD_DIR)/$(BINARY_NAME) -## Run in development mode with pre-seeded database -dev: build dev-db +## Run in development mode +dev: build @echo "Running $(BINARY_NAME) in development mode..." - KANDEV_DB_PATH=./dev/kandev-dev.db ./$(BUILD_DIR)/$(BINARY_NAME) - -## Initialize/reset the development database -dev-db: - @if [ ! -f ./dev/kandev-dev.db ]; then \ - echo "Initializing development database..."; \ - ./dev/init-db.sh; \ - else \ - echo "Development database already exists. Use 'make dev-db-reset' to recreate."; \ - fi - -## Reset the development database (recreate with fresh seed data) -dev-db-reset: - @echo "Resetting development database..." - ./dev/init-db.sh --reset + ./$(BUILD_DIR)/$(BINARY_NAME) ## Run tests test: @@ -124,9 +110,7 @@ help: @echo " build-agentctl Build the agentctl sidecar binary" @echo " clean Remove build artifacts" @echo " run Build and run the application" - @echo " dev Run in development mode with pre-seeded database" - @echo " dev-db Initialize development database (if not exists)" - @echo " dev-db-reset Reset development database with fresh seed data" + @echo " dev Run in development mode with a local database" @echo " test Run tests" @echo " test-coverage Run tests with coverage report" @echo " lint Run golangci-lint" @@ -136,4 +120,3 @@ help: @echo " deps Download dependencies" @echo " build-cross Build for Linux, macOS, and Windows" @echo " help Show this help message" - diff --git a/apps/backend/dev/init-db.sh b/apps/backend/dev/init-db.sh deleted file mode 100755 index 6531582754..0000000000 --- a/apps/backend/dev/init-db.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -# Initialize the development database with seed data -# Usage: ./dev/init-db.sh [--reset] - -set -e - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -DEV_DIR="$SCRIPT_DIR" -DB_PATH="$DEV_DIR/kandev-dev.db" -SEED_SQL="$DEV_DIR/seed.sql" -SEED_SQL_PROCESSED="$DEV_DIR/.seed-processed.sql" - -# Get the repository root path (three levels up from apps/backend/dev/) -REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -echo -e "${GREEN}=== Kandev Development Database Initialization ===${NC}" -echo -e "Repository path: ${YELLOW}$REPO_ROOT${NC}" - -# Check if reset flag is passed -if [[ "$1" == "--reset" ]]; then - echo -e "${YELLOW}Resetting database...${NC}" - rm -f "$DB_PATH" "$DB_PATH-wal" "$DB_PATH-shm" -fi - -# Check if database already exists -if [[ -f "$DB_PATH" ]]; then - echo -e "${YELLOW}Database already exists at: $DB_PATH${NC}" - echo "Use --reset flag to recreate: ./dev/init-db.sh --reset" - exit 0 -fi - -# Build the backend to ensure schema is created -echo -e "${GREEN}Building backend...${NC}" -cd "$SCRIPT_DIR/.." -go build -o /tmp/kandev-init ./cmd/kandev - -# Create the database by running the backend briefly (to create schema) -echo -e "${GREEN}Creating database schema...${NC}" -KANDEV_DB_PATH="$DB_PATH" timeout 2 /tmp/kandev-init 2>/dev/null || true - -# Wait for the database file to be created -sleep 1 - -if [[ ! -f "$DB_PATH" ]]; then - echo -e "${RED}Failed to create database${NC}" - exit 1 -fi - -# Process seed.sql - replace $KANDEV_REPO_PATH with actual path -echo -e "${GREEN}Processing seed data...${NC}" -sed "s|\\\$KANDEV_REPO_PATH|$REPO_ROOT|g" "$SEED_SQL" > "$SEED_SQL_PROCESSED" - -# Apply seed data -echo -e "${GREEN}Applying seed data...${NC}" -sqlite3 "$DB_PATH" < "$SEED_SQL_PROCESSED" - -# Clean up processed file -rm -f "$SEED_SQL_PROCESSED" - -echo -e "${GREEN}=== Database initialized successfully ===${NC}" -echo -e "Database path: ${YELLOW}$DB_PATH${NC}" -echo "" -echo "To run the backend with this database:" -echo -e " ${YELLOW}KANDEV_DB_PATH=$DB_PATH ./bin/kandev${NC}" -echo "" -echo "Or use the Makefile target:" -echo -e " ${YELLOW}make dev${NC}" - diff --git a/apps/backend/dev/seed.sql b/apps/backend/dev/seed.sql deleted file mode 100644 index 1fc4edb244..0000000000 --- a/apps/backend/dev/seed.sql +++ /dev/null @@ -1,83 +0,0 @@ --- Seed data for development database --- This file is used to populate the dev database with sample data - --- Default workspace (created by initSchema, just update if needed) -INSERT OR REPLACE INTO workspaces (id, name, description, owner_id, created_at, updated_at) -VALUES ('default', 'Default Workspace', 'Your default workspace', '', datetime('now'), datetime('now')); - --- Default user and settings -INSERT OR REPLACE INTO users (id, email, settings, created_at, updated_at) -VALUES ('default-user', 'default@kandev.local', '{"workspace_id":"default","board_id":"dev-board-1","repository_ids":[]}', datetime('now'), datetime('now')); - --- Default repository (for task creation) -INSERT OR REPLACE INTO repositories (id, workspace_id, name, source_type, local_path, provider, provider_repo_id, provider_owner, provider_name, default_branch, setup_script, cleanup_script, created_at, updated_at) -VALUES ('default-repo', 'default', 'kandev', 'local', '$KANDEV_REPO_PATH', '', '', '', '', 'main', '', '', datetime('now'), datetime('now')); - --- Sample board -INSERT OR REPLACE INTO boards (id, workspace_id, name, description, created_at, updated_at) -VALUES - ('dev-board-1', 'default', 'Kandev Development', 'Main development board for kandev', datetime('now'), datetime('now')), - ('dev-board-2', 'default', 'Feature Backlog', 'Upcoming features and ideas', datetime('now'), datetime('now')); - --- Columns for dev-board-1 -INSERT OR REPLACE INTO columns (id, board_id, name, position, state, created_at, updated_at) -VALUES - ('col-backlog', 'dev-board-1', 'Backlog', 0, 'TODO', datetime('now'), datetime('now')), - ('col-todo', 'dev-board-1', 'To Do', 1, 'TODO', datetime('now'), datetime('now')), - ('col-inprogress', 'dev-board-1', 'In Progress', 2, 'IN_PROGRESS', datetime('now'), datetime('now')), - ('col-review', 'dev-board-1', 'Review', 3, 'REVIEW', datetime('now'), datetime('now')), - ('col-done', 'dev-board-1', 'Done', 4, 'COMPLETED', datetime('now'), datetime('now')); - --- Columns for dev-board-2 -INSERT OR REPLACE INTO columns (id, board_id, name, position, state, created_at, updated_at) -VALUES - ('col-ideas', 'dev-board-2', 'Ideas', 0, 'TODO', datetime('now'), datetime('now')), - ('col-planned', 'dev-board-2', 'Planned', 1, 'TODO', datetime('now'), datetime('now')), - ('col-scheduled', 'dev-board-2', 'Scheduled', 2, 'IN_PROGRESS', datetime('now'), datetime('now')); - --- Sample tasks for dev-board-1 --- NOTE: repository_url should be an absolute path to a local git repository --- The placeholder $KANDEV_REPO_PATH will be replaced by init-db.sh with the actual path -INSERT OR REPLACE INTO tasks (id, board_id, column_id, title, description, state, priority, position, agent_type, repository_url, branch, metadata, created_at, updated_at) -VALUES - -- Backlog tasks (no agent assigned) - ('task-001', 'dev-board-1', 'col-backlog', 'Add dark mode support', 'Implement a dark theme toggle for the UI', 'TODO', 3, 0, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')), - ('task-002', 'dev-board-1', 'col-backlog', 'Implement search functionality', 'Add full-text search for tasks across all boards', 'TODO', 2, 1, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')), - - -- To Do tasks (agent assigned with repository) - ('task-003', 'dev-board-1', 'col-todo', 'Fix WebSocket reconnection', 'Handle WebSocket disconnects gracefully and auto-reconnect', 'TODO', 5, 0, 'augment-agent', '$KANDEV_REPO_PATH', 'main', '{}', datetime('now'), datetime('now')), - ('task-004', 'dev-board-1', 'col-todo', 'Add task labels/tags', 'Allow users to add colored labels to tasks for categorization', 'TODO', 2, 1, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')), - - -- In Progress tasks (agent with repository) - ('task-005', 'dev-board-1', 'col-inprogress', 'Agent session persistence', 'Persist agent sessions in database instead of memory', 'IN_PROGRESS', 8, 0, 'augment-agent', '$KANDEV_REPO_PATH', 'main', '{}', datetime('now'), datetime('now')), - - -- Review tasks - ('task-006', 'dev-board-1', 'col-review', 'Comment system improvements', 'Enhanced comment display with markdown and tool calls', 'REVIEW', 6, 0, 'augment-agent', '$KANDEV_REPO_PATH', 'main', '{}', datetime('now'), datetime('now')), - - -- Done tasks - ('task-007', 'dev-board-1', 'col-done', 'Basic kanban board UI', 'Create the initial kanban board with drag-and-drop', 'COMPLETED', 10, 0, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now', '-3 days'), datetime('now', '-1 day')), - ('task-008', 'dev-board-1', 'col-done', 'WebSocket API implementation', 'Implement real-time WebSocket communication', 'COMPLETED', 9, 1, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now', '-5 days'), datetime('now', '-2 days')); - --- Sample tasks for dev-board-2 (Feature Backlog) -INSERT OR REPLACE INTO tasks (id, board_id, column_id, title, description, state, priority, position, agent_type, repository_url, branch, metadata, created_at, updated_at) -VALUES - ('task-101', 'dev-board-2', 'col-ideas', 'Multi-user collaboration', 'Allow multiple users to work on the same board', 'TODO', 5, 0, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')), - ('task-102', 'dev-board-2', 'col-ideas', 'Task dependencies', 'Add ability to link tasks as dependencies', 'TODO', 4, 1, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')), - ('task-103', 'dev-board-2', 'col-planned', 'Agent type marketplace', 'Browse and install different agent types', 'TODO', 6, 0, '', '$KANDEV_REPO_PATH', '', '{}', datetime('now'), datetime('now')); - --- Sample comments on tasks -INSERT OR REPLACE INTO task_comments (id, task_id, author_type, author_id, content, type, metadata, requests_input, task_session_id, created_at) -VALUES - -- Comments on task-005 (Agent session persistence) - ('comment-001', 'task-005', 'user', 'dev-user', 'Starting work on database schema for agent sessions', 'message', '{}', 0, '', datetime('now', '-2 hours')), - ('comment-002', 'task-005', 'agent', 'augment-agent', 'I''ll help you implement the agent session persistence. Let me start by analyzing the current codebase structure.', 'message', '{}', 0, '', datetime('now', '-1 hour')), - ('comment-003', 'task-005', 'agent', 'augment-agent', 'codebase-retrieval', 'tool_call', '{"tool_call_id": "tc-001", "title": "codebase-retrieval: Looking for agent execution tracking", "status": "completed"}', 0, '', datetime('now', '-55 minutes')), - - -- Comments on task-006 (Comment system) - ('comment-004', 'task-006', 'user', 'dev-user', 'Need to add support for tool call rendering in the chat panel', 'message', '{}', 0, '', datetime('now', '-1 day')), - ('comment-005', 'task-006', 'agent', 'augment-agent', 'I''ve implemented the tool call comment type with proper rendering. The changes include:\n\n1. Added `type` field to comments\n2. Added `metadata` for tool call details\n3. Updated the frontend to render tool calls differently', 'message', '{}', 0, '', datetime('now', '-20 hours')); - --- Sample task session -INSERT OR REPLACE INTO task_sessions (id, task_id, agent_instance_id, agent_type, state, progress, error_message, metadata, started_at, completed_at, updated_at) -VALUES - ('session-001', 'task-005', 'agent-instance-123', 'augment-agent', 'RUNNING', 0.0, '', '{}', datetime('now', '-1 hour'), NULL, datetime('now'));