# Project export: PromptBreakr

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 12.0
- Tagline: Automated prompt stress-testing for safer AI.
- Devpost: https://devpost.com/software/promptbreaker
- GitHub: https://github.com/NathanG2022/CalHacks
- Video: https://www.youtube.com/embed/6TzXRRyA9Hk?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Team: 3 GitHub contributor(s) — Nathan Guan (9 commits), Johnny Yu (7 commits), tiffany711 (1 commits)

## Devpost submission (written by the team)

### Inspiration

Over 70% of organizations adopting AI systems today report at least one incident of unintended or unsafe model behavior — from biased recommendations to prompt-based jailbreaks that override ethical boundaries. As AI becomes more powerful, it’s also becoming easier to manipulate. Jailbreaks, misinformation, and unsafe outputs are spreading faster than safety systems can keep up. We wanted to build something that helps people trust AI again — a way to create stronger boundaries between what AI can do and what it should do. We started exploring how existing safety systems often fail to anticipate new attack methods — especially for smaller, open-source models that lack specialized protection. We wondered: what if there was a dedicated framework built to test these vulnerabilities automatically? Could we design a system that not only detects unsafe behavior, but actually teaches developers how to build stronger, more aligned models? From that idea, our project was born — an automated red-teaming and stress-testing tool designed to identify weaknesses before they become risks. It continuously challenges models with dynamic, adversarial prompts and provides real-time feedback on how and where they fail. We believe that if tools like ours were implemented across the growing ecosystem of AI developers — from research labs to startups — they could reshape how we approach responsible AI altogether. By catching vulnerabilities early and promoting transparency, this technology has the potential to make AI not only smarter, but genuinely safer for everyone.

### What it does

Our platform automatically generates, executes, and evaluates adversarial prompts against large language models to uncover hidden vulnerabilities. It simulates real-world “stress tests” by crafting diverse attack scenarios, from jailbreaks that attempt to override restrictions, to misinformation traps and subtle bias probes that push ethical boundaries. Once these prompts are executed, the system evaluates how the model responds, measuring its ability to stay aligned, reject unsafe instructions, and maintain consistent behavior under pressure. Every trial is logged, analyzed, and visualized through an interactive dashboard that highlights failure points, success rates, and key risk areas. In simpler terms, it’s like a safety check-up for AI systems, ensuring they’re resilient, responsible, and ready before deployment. By automating what would normally take hours of manual testing, our tool helps developers build AI that the world can actually trust.

### How we built it

At the core of our platform is an autonomous red-teaming agent powered by Letta, which serves as the “AI coordinator” for generating and evaluating adversarial prompts. We began by designing a modular system that could automatically simulate jailbreak attempts, misinformation traps, and bias probes against large language models — all without requiring manual supervision. To make this possible, we built a Letta agent configured with custom tools that perform multi-step reasoning and orchestration. Each agent connects to a Supabase database, where prior jailbreak prompts and model responses are stored. When a user submits a new prompt, Letta retrieves similar examples from the database, synthesizes them with the new input using retrieval-augmented generation (RAG) logic, and generates a fresh adversarial prompt designed to probe model safety limits. The agent then calls an open-source model hosted on Hugging Face to run the generated test. It looks for specific “canary tokens” — markers that help detect if the model has been successfully manipulated or leaked restricted information. Each test result, including the prompt, response, and safety outcome, is logged back into Supabase, allowing the system to learn from its own past successes and failures. We structured the entire workflow through Letta’s internal reasoning loop, which sequentially handles fetching, combining, testing, and logging in real time. This architecture enables persistence and memory — meaning the agent doesn’t just test once, but improves iteratively with every run. Our backend, built with lightweight APIs, communicates with Letta to handle user requests and return structured results to the frontend, which visualizes everything in a clean dashboard.

### Challenges we ran into

We quickly learned that building a system designed to “break” AI safely was just as tricky as it sounds. Integrating Letta, Supabase, and our testing models required a lot of trial and error, mostly because each component handled reasoning, data storage, and model interaction differently. We ran into issues with syncing Letta’s multi-step workflows to our backend in real time, and debugging asynchronous behavior felt like juggling invisible threads. Storing structured memory in Supabase also came with its own quirks, especially when trying to preserve context between test generations. Getting everything to run smoothly across multiple endpoints while maintaining performance was one of the biggest balancing acts of the build. On the AI side, prompt engineering turned out to be way more complex than we expected. Jailbreaking isn’t just about writing clever prompts, it’s about understanding why a model breaks. We had to carefully design stress tests that were adversarial enough to expose weaknesses, but not so vague that the data became meaningless. Finding that middle ground between creativity and consistency took dozens of iterations. Sometimes, the model would refuse harmless prompts and accept dangerous ones, forcing us to rethink how we measured “safety” in the first place. It was frustrating at times, but every failed test taught us more about how unpredictable, and human-like these systems really are.

### Accomplishments we're proud of

We’re incredibly proud of the progress we made in such a short time. None of us came in as experts, we had to learn new frameworks, navigate unfamiliar APIs, and constantly adapt as we built. Despite the steep learning curve, our team stayed focused and persistent, pushing through roadblocks that, at first, felt impossible to solve. Watching our system finally run end-to-end, integrating Letta, Supabase, and the evaluation pipeline, was extremely rewarding. Even when things broke (and they did, often), we approached every challenge with curiosity and teamwork. In the end, we built something far beyond what we first imagined, and proved to ourselves that persistence and collaboration can turn ambitious ideas into something real.

### What we learned

We developed our skills in technologies we were initially unfamiliar with, such as integrating multiple APIs and managing data flow between systems. We also learned how to coordinate the backend logic that connects Supabase, OpenAI, and Hugging Face, ensuring each component communicated smoothly. Through countless iterations of prompt testing and refinement, we gained a deeper understanding of how subtle changes can influence AI behavior and safety. Developing this project helped us recognize the importance of building responsible systems that make AI interactions safer, more transparent, and ultimately more trustworthy for users.

### What's next

for PromptBreaker We plan to refine our testing pipeline and expand the range of adversarial scenarios our system can generate. Beyond improving the tech, our goal is to make AI safety more proactive, giving developers the tools to identify vulnerabilities before they become real-world risks. We hope our platform can contribute to building a future where safer, more reliable AI systems are the standard.

## README (from the GitHub repository)

# CalHacks RAG + LLM Integration System

A comprehensive AI-powered system that combines RAG (Retrieval-Augmented Generation) with Large Language Models for advanced prompt engineering and red-teaming applications.

## 🚀 Features

- **RAG Prompt Generation**: Advanced template-based prompt generation system
- **Multi-Model Support**: Integration with HuggingFace models (Qwen, DialoGPT)
- **Crescendo Attacks**: Multi-turn escalating attack patterns
- **Jailbreaking Strategies**: Multiple attack categories and techniques
- **Real-time Processing**: Individual LLM processing for each generated prompt
- **Docker Integration**: Complete containerized environment
- **Letta Integration**: Advanced AI agent platform
- **PromptBreaker**: Sophisticated prompt injection framework

## 📁 Project Structure

```
CalHacks/
├── client/                    # React frontend
│   ├── src/
│   │   ├── components/        # UI components
│   │   │   ├── Auth/         # Authentication components
│   │   │   ├── CrescendoAttack.jsx
│   │   │   └── EnhancedAI.jsx
│   │   ├── contexts/         # React contexts
│   │   ├── lib/             # Utilities
│   │   ├── pages/           # Page components
│   │   ├── services/        # API services
│   │   └── App.jsx
│   ├── Dockerfile
│   └── package.json
├── server/                   # Express.js backend
│   ├── routes/              # API routes
│   │   ├── enhancedAI.js
│   │   ├── ragPrompts.js
│   │   └── crescendo.js
│   ├── services/            # Business logic
│   │   ├── promptRAGService.js
│   │   ├── crescendoService.js
│   │   ├── huggingFaceService.js
│   │   └── lettaRAGService.js
│   ├── Dockerfile
│   └── server.js
├── promptbreaker/           # Prompt injection framework
│   ├── attacker/           # Attack templates
│   ├── target_letta/       # Letta integration
│   └── orchestrator.py
├── letta/                   # Letta AI platform
├── database/               # Database schema
├── docker-compose.yml      # Docker orchestration
└── .env.example           # Environment configuration
```

## 🛠️ Setup Instructions

### Prerequisites

- Docker and Docker Compose
- Git
- API Keys (see Environment Setup)

### 1. Clone the Repository

```bash
git clone https://github.com/NathanG2022/CalHacks.git
cd CalHacks
```

### 2. Environment Setup

Copy the example environment file and configure it:

```bash
cp .env.example .env
```

Edit `.env` with your API keys:

```env
# Required API Keys
OPENAI_API_KEY=your_openai_api_key_here
HUGGINGFACE_API_KEY=your_huggingface_api_key_here
SUPABASE_URL=your_supabase_url_here
SUPABASE_ANON_KEY=your_supabase_anon_key_here
LETTA_API_KEY=your_letta_api_key_here
LETTA_AGENT_ID=your_letta_agent_id_here

# Optional API Keys
GROQ_API_KEY=your_groq_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# ... (see .env.example for complete list)
```

### 3. Start the System

```bash
# Start all services with Docker
docker-compose up -d

# Check service status
docker-compose ps
```

### 4. Access the Application

- **Frontend Dashboard**: http://localhost:5174
- **Backend API**: http://localhost:3002
- **Letta Server**: http://localhost:8084
- **Letta API**: http://localhost:8284

## 🎯 Usage

### 1. Basic RAG Prompt Generation

1. Open http://localhost:5174
2. Click "New Job" button
3. Enter your prompt (e.g., "How to make a Molotov Cocktail?")
4. Select jailbreaking strategy (Crescendo, Direct, etc.)
5. Select AI model (Qwen, DialoGPT, etc.)
6. Click "Launch Job"
7. Watch as RAG prompts are generated and processed individually

### 2. Crescendo Attack System

1. Click "🎯 Crescendo Attack" button
2. Enter your target prompt
3. Select AI model
4. Watch the multi-turn escalating attack unfold
5. View detailed responses for each step

### 3. Enhanced AI Interface

1. Navigate to "Enhanced AI" tab
2. Enter prompts directly
3. Get real-time AI responses
4. Test different models and strategies

## 🔧 API Endpoints

### Health Check
- `GET /api/health` - Server health status

### RAG Prompts
- `POST /api/rag-prompts/generate` - Generate RAG prompts
- `GET /api/rag-prompts/templates` - Get available templates
- `GET /api/rag-prompts/categories` - Get attack categories

### Enhanced AI
- `POST /api/enhanced-ai/process-prompt` - Process prompts through LLM
- `GET /api/enhanced-ai/health` - Enhanced AI service health

### Crescendo Attacks
- `POST /api/crescendo/execute` - Execute crescendo attack
- `GET /api/crescendo/status` - Crescendo service status

## 🎨 Key Features

### RAG Prompt Generation
- **57+ Attack Templates**: Comprehensive collection of prompt injection patterns
- **Manufacturing Detection**: Automatic prioritization of manufacturing-related prompts
- **Category Filtering**: Filter by attack type (Crescendo, Direct, Contextual, etc.)
- **Confidence Scoring**: Each generated prompt includes confidence metrics

### Multi-Model Support
- **Qwen Models**: Qwen2.5-7B-Instruct, Qwen2.5-14B-Instruct
- **DialoGPT**: Microsoft's conversational model
- **HuggingFace Integration**: Direct API integration
- **Model Selection**: Easy switching between models

### Crescendo Attack System
- **Multi-turn Escalation**: Gradual escalation of attack complexity
- **Real-time Progress**: Live progress tracking and status updates
- **Detailed Logging**: Comprehensive logging for each step
- **Response Analysis**: Detailed analysis of each LLM response

### Advanced UI
- **Real-time Updates**: Live progress indicators and status updates
- **Comprehensive Logging**: Detailed console logs for debugging
- **Error Handling**: Robust error handling with fallbacks
- **Responsive Design**: Modern, responsive UI with Tailwind CSS

## 🐳 Docker Services

### Core Services
- **calhacks-client**: React frontend (port 5174)
- **calhacks-server**: Express.js backend (port 3002)
- **calhacks-letta-server**: Letta AI platform (ports 8084, 8284)
- **calhacks-letta-db**: PostgreSQL database (port 5433)
- **calhacks-promptbreaker**: Prompt injection framework

### Service Dependencies
- Letta database → Letta server → PromptBreaker
- Letta server → CalHacks server → CalHacks client

## 🔐 Security Features

- **Environment Variables**: All API keys stored securely
- **No Hardcoded Secrets**: Clean git history with no exposed credentials
- **CORS Configuration**: Proper cross-origin resource sharing
- **Input Validation**: Comprehensive input validation
- **Error Handling**: Secure error handling without information leakage

## 📊 Monitoring and Debugging

### Health Checks
- All services include health check endpoints
- Docker health checks for service dependencies
- Comprehensive logging throughout the system

### Debug Tools
- **Console Logging**: Detailed logs in browser console
- **API Testing**: Built-in test scripts for all endpoints
- **Service Verification**: Automated service health verification

## 🚀 Deployment

### Production Deployment
1. Set up production environment variables
2. Configure reverse proxy (nginx)
3. Set up SSL certificates
4. Configure monitoring and logging
5. Deploy with Docker Compose

### Development
- Hot reload for both client and server
- Comprehensive error reporting
- Easy debugging with detailed logs

## 🛡️ Security Considerations

- **API Key Protection**: Never commit API keys to version control
- **Input Sanitization**: All inputs are properly validated
- **Rate Limiting**: Consider implementing rate limiting for production
- **Access Control**: Implement proper authentication for production use

## 📝 Development Notes

- **Hot Reload**: Both client and server support hot reload
- **Environment Variables**: Use `.env` for configuration
- **API Communication**: Client communicates with server via REST API
- **Error Handling**: Comprehensive error handling throughout

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Test thoroughly with the provided test scripts
5. Submit a pull request

## 📄 License

This project is open source and availab

[README truncated for size]

## Detected evidence (automated analysis)

Indexed codebase: 118 recognized source files, 901 KB.
- CSS (language) — detected in the code
- Express (technology) — detected in the code
- Flask (technology) — detected in the code
- HTML (language) — detected in the code
- Hugging Face (technology) — detected in the code
- JavaScript (language) — detected in the code
- LangChain (technology) — detected in the code
- OpenAI (technology) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- SQL (language) — detected in the code
- Supabase (technology) — detected in the code
- Tailwind CSS (technology) — detected in the code
- Docker (technology) — claimed on Devpost, not found in the code
- Node.js (technology) — claimed on Devpost, not found in the code
- AI coding agent: Claude Code — evidence: commit authorship or trailers

## Codebase structure (from repository index)

### Files (120 of 144)

```
.env.example
.gitignore
client/Dockerfile
client/env.example
client/eslint.config.js
client/index.html
client/package.json
client/postcss.config.js
client/src/App.jsx
client/src/components/Auth/index.js
client/src/components/Auth/SignIn.jsx
client/src/components/Auth/SignUp.jsx
client/src/components/crescendo/ConversationView.jsx
client/src/components/crescendo/CrescendoInterface.jsx
client/src/components/crescendo/DetectionMetricsPanel.jsx
client/src/components/crescendo/JudgeEvaluationView.jsx
client/src/components/crescendo/ResponseAnalysisPanel.jsx
client/src/components/crescendo/ResultsStatisticsPanel.jsx
client/src/components/crescendo/SafetyScoresPanel.jsx
client/src/components/CrescendoAttack.jsx
client/src/components/EnhancedAI.jsx
client/src/components/HackerBackground.jsx
client/src/components/LoadingScreen.jsx
client/src/components/MultiModelTest.jsx
client/src/contexts/AuthContext.jsx
client/src/index.css
client/src/lib/supabase.js
client/src/main.jsx
client/src/pages/ChatInterface.jsx
client/src/pages/Dashboard.jsx
client/src/pages/Profile.jsx
client/src/pages/Settings.jsx
client/src/pages/Statistics.jsx
client/src/ScrollToTop.jsx
client/src/services/ai.js
client/src/services/api.js
client/src/services/enhancedAI.js
client/src/services/evaluation.js
client/src/services/jobsService.js
client/src/SimpleTest.jsx
client/src/styles/ConversationView.css
client/src/styles/CrescendoInterface.css
client/src/styles/DetectionMetricsPanel.css
client/src/styles/ResponseAnalysisPanel.css
client/src/TestPage.jsx
client/tailwind.config.js
client/vite.config.js
COMPLETE_SETUP_GUIDE.md
database/schema.sql
DOCKER_SETUP.md
docker-compose.yml
docker-start.bat
docker-start.sh
ENHANCED_AI_README.md
ENHANCED_WORKFLOW.md
generate_attack_prompts_enhanced.js
generate_attack_prompts.js
MODELS_GUIDE.md
package.json
promptbreaker/.dockerignore
promptbreaker/.env.example
promptbreaker/.gitignore
promptbreaker/ARCHITECTURE.md
promptbreaker/attacker/__init__.py
promptbreaker/attacker/.gitignore
promptbreaker/attacker/composer.py
promptbreaker/attacker/crescendo_composer.py
promptbreaker/attacker/crescendo_templates.txt
promptbreaker/attacker/templates.txt
promptbreaker/attacker/test_crescendo_tasks.py
promptbreaker/check_env.py
promptbreaker/CRESCENDO_GUIDE.md
promptbreaker/CRESCENDO_SYSTEM_SUMMARY.md
promptbreaker/DEMO_GUIDE.md
promptbreaker/DOCKER_GUIDE.md
promptbreaker/DOCKER_QUICKSTART.md
promptbreaker/DOCKER_TUTORIAL.md
promptbreaker/docker-compose.simple.yml
promptbreaker/docker-compose.yml
promptbreaker/Dockerfile
promptbreaker/Makefile
promptbreaker/orchestrator.py
promptbreaker/PROJECT_SUMMARY.md
promptbreaker/QUICK_START_CRESCENDO.md
promptbreaker/QUICKSTART.md
promptbreaker/README.md
promptbreaker/requirements.txt
promptbreaker/run.bat
promptbreaker/setup.bat
promptbreaker/setup.sh
promptbreaker/target_letta/__init__.py
promptbreaker/target_letta/create_agent.py
promptbreaker/target_letta/run_query.py
promptbreaker/target_letta/upload_docs.py
promptbreaker/TROUBLESHOOTING.md
promptbreaker/wait-for-letta.sh
QUICKSTART.md
RAG_PROMPTS_GUIDE.md
README.md
server/database/schema-updated.sql
server/database/schema.sql
server/Dockerfile
server/env.example
server/package.json
server/python-service/.dockerignore
server/python-service/Dockerfile
server/python-service/huggingface_service.py
server/python-service/README.md
server/python-service/requirements.txt
server/routes/crescendo.js
server/routes/enhancedAI.js
server/routes/evaluation.js
server/routes/multiModelTest.js
server/routes/ragPrompts.js
server/routes/statistics.js
server/server.js
server/services/crescendo/AttackDetector.js
server/services/crescendo/ConversationMemory.js
server/services/crescendo/CrescendoOrchestrator.js
server/services/crescendo/EscalationEngine.js
[24 more files omitted for size]
```

### Dependencies

- client/package.json: @eslint/js@^9.36.0, @supabase/supabase-js@^2.76.1, @types/react@^19.1.16, @types/react-dom@^19.1.9, @vitejs/plugin-react@^5.0.4, autoprefixer@^10.4.21, axios@^1.12.2, chart.js@^4.5.1, eslint@^9.36.0, eslint-plugin-react-hooks@^5.2.0, eslint-plugin-react-refresh@^0.4.22, globals@^16.4.0, openai@^4.104.0, postcss@^8.5.6, react@^19.1.1, react-chartjs-2@^5.3.0, react-dom@^19.1.1, react-router-dom@^7.6.3, tailwindcss@^3.4.17, vite@^7.1.7
- package.json: @supabase/supabase-js@^2.75.1, axios@^1.12.2, baseline-browser-mapping@^2.9.11, chart.js@^4.5.1, concurrently@^8.2.2, react-chartjs-2@^5.3.0
- promptbreaker/requirements.txt: faiss-cpu@>=1.7.4, numpy@>=1.24.0, requests@>=2.31.0, sentence-transformers@>=2.2.0
- server/package.json: @huggingface/inference@^2.8.1, @supabase/supabase-js@^2.76.1, axios@^1.12.2, bcrypt@^6.0.0, cors@^2.8.5, dotenv@^16.4.7, express@^4.21.2, jsonwebtoken@^9.0.3, nodemon@^3.1.9
- server/python-service/requirements.txt: accelerate@>=0.25.0, Flask@>=3.0.0, flask-cors@>=4.0.0, langchain@>=0.1.0, langchain-community@>=0.0.1, langchain-core@>=0.1.0, langchain-huggingface@>=0.0.1, numpy@>=1.24.0, protobuf@>=4.25.0, python-dotenv@>=1.0.0, requests@>=2.31.0, sentencepiece@>=0.1.99, transformers@>=4.36.0

### Recent commits (newest first)

- revert
- Revert "Implement scalable dynamic port detection system"
- Implement scalable dynamic port detection system
- Polish code quality and enhance security
- Fix Letta server connection and save job functionality
- Fix Letta server connection: correct API endpoints and payload format
- Improve prompts for all tasks
- Add quick start guide for Crescendo system
- Fix Unicode encoding issue in test script
- Add Crescendo multi-turn jailbreak attack system
- Remove temporary status/fix documentation files from promptbreaker
- Remove unnecessary test, debug, and temporary files
- Update letta submodule reference with Google AI routing fix
- Fix Docker startup issues and API routing
- fix frontend and merge w backend, project is demoable and finsihed
- Fix text readability and dashboard visibility for dark background
- Add HackerBackground component and fix dark theme
- Update frontend with complete functionality and proper integration
- Remove accidentally created 'ter' file
- Polish codebase: Clean up debug logs, improve error handling, and fix configuration issues

## Key source files (fetched from GitHub, selected and truncated for size)

### STARTUP_SUCCESS.md

```markdown
# ✅ Startup Success!

All services have been successfully started and are running.

## 🌐 Access URLs

- **React Client (Web App)**: http://localhost:5174
- **Express Server API**: http://localhost:3002
- **Letta Server**: http://localhost:8284
- **Letta Nginx**: http://localhost:8080

## 📊 Service Status

All containers are running:
- ✅ `calhacks-letta-db` - PostgreSQL database (healthy)
- ✅ `calhacks-letta-server` - Letta AI platform (healthy)
- ✅ `calhacks-letta-nginx` - Nginx reverse proxy
- ✅ `calhacks-server` - Express.js backend
- ✅ `calhacks-client` - React frontend
- ✅ `calhacks-promptbreaker` - RAG attack demo

## 🔧 What Was Fixed

1. **Letta Server Startup Issue**: Changed from building from source to using the pre-built `letta/letta:latest` image, which resolved the startup script execution error.

2. **Service Dependencies**: All services are properly configured with health checks and dependencies.

## 🚀 Next Steps

1. Open your browser and navigate to http://localhost:5174 to access the web app
2. The PromptBreaker demo will run automatically and populate results
3. Check the Letta UI at http://localhost:8284 to see agents and sources

## 📝 Notes

- The Letta server is using the pre-built Docker image for reliability
- All environment variables should be set in your `.env` file
- Services will automatically restart on failure (where configured)








```

### QUICKSTART.md

```markdown
# CalHacks Quick Start Guide

Get your CalHacks program running with Docker and Letta in minutes!

## 🚀 One-Command Setup

### Windows
```bash
setup-docker.bat
```

### Mac/Linux
```bash
./setup-docker.sh
```

## 📋 What You Get

- **Letta AI Platform** - Full-featured AI agent development environment
- **PromptBreaker Demo** - RAG poisoning attack demonstration
- **CalHacks Web App** - React frontend + Express backend
- **PostgreSQL Database** - Vector database for AI applications

## 🌐 Access Points

After setup, visit:

- **CalHacks Web App**: http://localhost:5173
- **Letta ADE**: http://localhost:8283
- **API Health**: http://localhost:3001/api/health

## ⚙️ Configuration

1. **Edit `.env`** - Add your OpenAI API key
2. **Edit `client/.env.local`** - Add Supabase credentials (optional)
3. **Restart**: `docker-compose restart`

## 🧪 Test Setup

```bash
./test-setup.sh
```

## 🎯 PromptBreaker Demo

The demo runs automatically and shows:
- Baseline attacks (low success)
- Poisoned attacks (high success) 
- Hardened defenses (reduced success)
- Mitigation results (back to baseline)

## 🔧 Common Commands

```bash
# View logs
docker-compose logs -f

# Stop everything
docker-compose down

# Restart services
docker-compose restart

# Update and rebuild
docker-compose up --build -d
```

## 🆘 Need Help?

- Check [DOCKER_SETUP.md](DOCKER_SETUP.md) for detailed instructions
- Run `./test-setup.sh` to diagnose issues
- View logs with `docker-compose logs -f`

## 🎉 You're Ready!

Your CalHacks program is now running with Docker and Letta. Happy hacking!
















```

### package.json

```
{
  "name": "calhacks-app",
  "version": "1.0.0",
  "description": "CalHacks full-stack web application with React client and Express server",
  "main": "index.js",
  "scripts": {
    "dev": "concurrently \"npm run server:dev\" \"npm run client:dev\"",
    "server:dev": "cd server && npm run dev",
    "client:dev": "cd client && npm run dev",
    "server:start": "cd server && npm start",
    "client:build": "cd client && npm run build",
    "client:preview": "cd client && npm run preview",
    "install:all": "npm install && cd client && npm install && cd ../server && npm install",
    "build": "npm run client:build"
  },
  "keywords": [
    "react",
    "express",
    "fullstack",
    "calhacks",
    "web-app"
  ],
  "author": "CalHacks Team",
  "license": "MIT",
  "devDependencies": {
    "baseline-browser-mapping": "^2.9.11",
    "concurrently": "^8.2.2"
  },
  "dependencies": {
    "@supabase/supabase-js": "^2.75.1",
    "axios": "^1.12.2",
    "chart.js": "^4.5.1",
    "react-chartjs-2": "^5.3.0"
  }
}

```

### docker-compose.yml

```yaml
services:
  # Letta Database
  letta_db:
    image: postgres:15
    container_name: calhacks-letta-db
    environment:
      - POSTGRES_DB=letta
      - POSTGRES_USER=letta
      - POSTGRES_PASSWORD=letta
    volumes:
      - letta_db_data:/var/lib/postgresql/data
    ports:
      - "5433:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U letta -d letta"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - calhacks-network

  # Letta Server
  letta_server:
    image: letta/letta:latest
    container_name: calhacks-letta-server
    ports:
      - "8084:8083"
      - "8284:8283"
    environment:
      - LETTA_PG_URI=postgresql+pg8000://letta:letta@letta_db:5432/letta
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
      - GROQ_API_KEY=${GROQ_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - OLLAMA_BASE_URL=${OLLAMA_BASE_URL}
      - AZURE_API_KEY=${AZURE_API_KEY}
      - AZURE_BASE_URL=${AZURE_BASE_URL}
      - AZURE_API_VERSION=${AZURE_API_VERSION}
      - GEMINI_API_KEY=${GEMINI_API_KEY}
      - VLLM_API_BASE=${VLLM_API_BASE}
    volumes:
      - letta_server_data:/root/.letta
    networks:
      - calhacks-network
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8283/ && curl -f http://localhost:8283/v1/agents/ || exit 0"]
      interval: 15s
      timeout: 10s
      retries: 15
      start_period: 45s
    depends_on:
      letta_db:
        condition: service_healthy

  # Letta Nginx
  letta_nginx:
    image: nginx:alpine
    container_name: calhacks-letta-nginx
    ports:
      - "8080:80"
    volumes:
      - ./letta/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - letta_server
    networks:
      - calhacks-network

  # PromptBreaker
  promptbreaker:
    build:
      context: ./promptbreaker
      dockerfile: Dockerfile
    container_name: calhacks-promptbreaker
    depends_on:
      letta_server:
        condition: service_healthy
    restart: on-failure
    environment:
      - LETTA_URL=http://letta_server:8283
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - PYTHONUNBUFFERED=1
    volumes:
      - ./promptbreaker/data:/app/data
      - ./promptbreaker/attacker:/app/attacker
      - ./promptbreaker/target_letta:/app/target_letta
    networks:
      - calhacks-network
    # Run setup then demo by default
    command: ["./wait-for-letta.sh"]

  # CalHacks Web Application - Client
  calhacks_client:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: calhacks-client
    ports:
      - "5174:5173"
    environment:
      - VITE_API_URL=http://localhost:3002
      - VITE_SUPABASE_URL=${SUPABASE_URL}
      - VITE_SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
      - VITE_HF_API_KEY=${HUGGINGFACE_API_KEY}
    depends_on:
      - calhacks_server
    networks:
      - calhacks-network

  # CalHacks Web Application - Server
  calhacks_server:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: calhacks-server
    ports:
      - "3002:3001"
    environment:
      - PORT=3001
      - NODE_ENV=development
      - SUPABASE_URL=${SUPABASE_URL}
      - SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
      - HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
      - LETTA_URL=http://letta_server:8283
      - LETTA_API_KEY=${LETTA_API_KEY}
      - LETTA_AGENT_ID=${LETTA_AGENT_ID}
    volumes:
      - ./server:/app
      - /app/node_modules
      - ./promptbreaker:/app/promptbreaker
    depends_on:
      - letta_server
    networks:
      - calhacks-network

volumes:
  letta_db_data:
  letta_server_data:

networks:
  calhacks-network:
    driver: bridge
```

### promptbreaker/requirements.txt

```
requests>=2.31.0
numpy>=1.24.0
faiss-cpu>=1.7.4
sentence-transformers>=2.2.0

```

### server/Dockerfile

```
# CalHacks Server Dockerfile
FROM node:20-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy source code
COPY . .

# Expose port
EXPOSE 3001

# Start server
CMD ["npm", "run", "dev"]

```

### client/Dockerfile

```
# CalHacks Client Dockerfile
FROM node:20-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy source code
COPY . .

# Expose port
EXPOSE 5173

# Start development server
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]

```

### server/package.json

```
{
  "name": "calhacks-server",
  "version": "1.0.0",
  "description": "Express.js server for CalHacks full-stack web app",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "express",
    "api",
    "server",
    "calhacks"
  ],
  "author": "CalHacks Team",
  "license": "ISC",
  "dependencies": {
    "@huggingface/inference": "^2.8.1",
    "@supabase/supabase-js": "^2.76.1",
    "axios": "^1.12.2",
    "bcrypt": "^6.0.0",
    "cors": "^2.8.5",
    "dotenv": "^16.4.7",
    "express": "^4.21.2",
    "jsonwebtoken": "^9.0.3",
    "nodemon": "^3.1.9"
  }
}

```

### client/package.json

```
{
  "name": "calhacks-client",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint .",
    "preview": "vite preview"
  },
  "dependencies": {
    "@supabase/supabase-js": "^2.76.1",
    "axios": "^1.12.2",
    "chart.js": "^4.5.1",
    "openai": "^4.104.0",
    "react": "^19.1.1",
    "react-chartjs-2": "^5.3.0",
    "react-dom": "^19.1.1",
    "react-router-dom": "^7.6.3"
  },
  "devDependencies": {
    "@eslint/js": "^9.36.0",
    "@types/react": "^19.1.16",
    "@types/react-dom": "^19.1.9",
    "@vitejs/plugin-react": "^5.0.4",
    "autoprefixer": "^10.4.21",
    "eslint": "^9.36.0",
    "eslint-plugin-react-hooks": "^5.2.0",
    "eslint-plugin-react-refresh": "^0.4.22",
    "globals": "^16.4.0",
    "postcss": "^8.5.6",
    "tailwindcss": "^3.4.17",
    "vite": "^7.1.7"
  }
}

```

### promptbreaker/Dockerfile

```
# PromptBreaker Dockerfile
# Containerized environment for RAG poisoning attack demo
# Optimized for build speed and image size

FROM python:3.11-slim-bookworm

# Set working directory
WORKDIR /app

# Install system dependencies in a single layer
# Removed git (not needed at runtime, only in docs)
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    sqlite3 \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Create non-root user for security (before copying files)
RUN useradd -m -u 1000 appuser

# Set environment variables early (for better caching)
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONPATH=/app \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Copy requirements first (for better layer caching)
COPY requirements.txt .

# Install Python dependencies with BuildKit cache mount
# This allows pip cache to persist between builds
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install --no-cache-dir -r requirements.txt

# Copy project files in optimal order (least frequently changed last)
COPY wait-for-letta.sh .
RUN chmod +x wait-for-letta.sh

COPY orchestrator.py .
COPY attacker/ ./attacker/
COPY target_letta/ ./target_letta/

# Create data directory with proper permissions and switch to non-root user
RUN mkdir -p /app/data/logs && \
    chown -R appuser:appuser /app

USER appuser

# Default command (can be overridden)
CMD ["python", "-u", "orchestrator.py", "demo"]

```

[113 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]