Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:1-18-bullseye

# Install Bun
RUN curl -fsSL https://bun.sh/install | bash && \
mv /root/.bun /usr/local/bun && \
ln -s /usr/local/bun/bin/bun /usr/local/bin/bun && \
ln -s /usr/local/bun/bin/bunx /usr/local/bin/bunx

# Install Claude Code CLI
RUN npm install -g @anthropic-ai/claude-code@latest

# Install k3s for local Kubernetes
RUN curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --disable traefik --disable metrics-server || true

# Install Docker Compose
RUN curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose

# Install additional tools
RUN apt-get update && apt-get install -y \
redis-tools \
jq \
vim \
htop \
net-tools \
iputils-ping \
dnsutils \
&& rm -rf /var/lib/apt/lists/*

# Create workspace directory
RUN mkdir -p /workspace

# Note: MCP config will be copied during post-create from the mounted workspace

# Create Claude Code configuration directory
RUN mkdir -p /home/node/.claude && chown -R node:node /home/node/.claude

# Note: Shell environment setup will be handled by post-create script

# Install GitHub CLI for PR operations
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
apt update && \
apt install gh -y

# Setup git
RUN git config --global --add safe.directory /workspace

# Switch to vscode user (will be handled by devcontainer features)
# USER vscode

# Note: npm global packages and shell config will be set up by devcontainer features

WORKDIR /workspace

# Set entrypoint to keep container running
ENTRYPOINT ["/bin/bash"]
24 changes: 0 additions & 24 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
// Features to add to the dev container
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"kubectl": "latest",
"helm": "latest",
"minikube": "none"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "18"
},
"ghcr.io/devcontainers/features/git:1": {}
},

Expand Down Expand Up @@ -43,22 +35,6 @@
"3000": {
"label": "Slack App",
"onAutoForward": "notify"
},
"3001": {
"label": "Dispatcher",
"onAutoForward": "notify"
},
"3002": {
"label": "Dispatcher Service",
"onAutoForward": "notify"
},
"8080": {
"label": "Health Check",
"onAutoForward": "silent"
},
"8081": {
"label": "Orchestrator",
"onAutoForward": "notify"
}
},

Expand Down
102 changes: 1 addition & 101 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -1,104 +1,4 @@
#!/bin/bash
set -e

echo "🚀 Setting up Peerbot development environment..."

# Fix permissions for node_modules volume
sudo chown -R node:node /workspace/node_modules || true

# Install dependencies as node user
echo "📦 Installing dependencies with Bun..."
sudo -u node bun install

# Build packages as node user
echo "🔨 Building packages..."
sudo -u node bash -c "cd packages/core && bun run build"
sudo -u node bash -c "cd packages/worker && bun run build"
sudo -u node bash -c "cd packages/gateway && bun run build"
sudo -u node bash -c "cd packages/orchestrator && bun run build"

# Setup shell environment
echo "🔧 Setting up shell environment..."
cat >> /home/node/.bashrc << 'EOF'

# Peerbot Development Environment
export PATH="/usr/local/bun/bin:$PATH"
export BUN_INSTALL="/usr/local/bun"
export PATH="/home/node/.bun/install/global/node_modules/.bin:$PATH"

# Docker aliases
alias d="docker"
alias dc="docker compose"
alias dps="docker ps"
EOF

# Setup bun global directory as node user
sudo -u node mkdir -p /home/node/.bun/install/global

# Setup Claude Code MCP configuration
echo "🤖 Setting up Claude Code MCP server..."
if [ -f "/workspace/packages/worker/mcp-config.json" ]; then
mkdir -p /home/node/.claude
cp /workspace/packages/worker/mcp-config.json /home/node/.claude/settings.mcp.json
echo "✅ MCP server configuration deployed"
fi

# Setup environment files
echo "🔧 Setting up environment files..."
if [ ! -f ".env" ] && [ -f ".env.example" ]; then
cp .env.example .env
echo "✅ Created .env from .env.example"
fi


# Create CLAUDE.md if it doesn't exist
if [ ! -f "CLAUDE.md" ]; then
cat > CLAUDE.md << 'EOF'
# CLAUDE.md - DevContainer Environment

This is a development environment for the Peerbot running in a VS Code DevContainer.

## Available Commands

- `make dev` - Start Docker development mode with hot reload
- `make k3s-setup` - Setup k3s cluster (if needed)
- `make k3s-install` - Install the application to k3s

## Environment

- Bun package manager installed
- Claude Code CLI available globally
- Docker installed
- MCP Process Manager server configured

## MCP Server

The MCP process manager server is available with these tools:
- start_process
- stop_process
- restart_process
- get_process_status
- get_process_logs

EOF
echo "✅ Created CLAUDE.md"
fi

# Display helpful information
echo ""
echo "✨ DevContainer setup complete!"
echo ""
echo "📚 Quick Start Guide:"
echo " 1. Configure your .env file with Slack and GitHub tokens"
echo " 2. Run 'make dev' to start development with Docker"
echo ""
echo "🛠️ Available Tools:"
echo " - Claude Code CLI: $(claude --version 2>/dev/null || echo 'Run: bun install -g @anthropic-ai/claude-code')"
echo " - Bun: $(bun --version)"
echo " - Node: $(node --version)"
echo " - Docker: $(docker --version 2>/dev/null || echo 'Not available')"
echo ""
echo "💡 Tips:"
echo " - The MCP process manager is configured for Claude Code"
echo " - Ports 3000-3002, 8080-8081 are forwarded"
echo ""
echo "🚀 Setting up Peerbot development environment..."
14 changes: 9 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

- If you create ephemeral files, you MUST delete them when you're done with them.
- Use Docker to build and run the Slack bot in development mode, K8S for production.
- NEVER create files unless they're absolutely necessary for achieving your goal. Instead try to run the code on the fly for testing reasons.
- NEVER proactively create documentation files (\*.md) or README files. Only create documentation files if explicitly requested by the User. If you need to remember something, add it to CLAUDE.md as a a single sentence.
- ALWAYS ignore `/dist/` directories when analyzing code - these contain compiled artifacts, not source
- If you're referencing Slack threads or users in your response, add their direct links as well.
Expand Down Expand Up @@ -73,11 +72,13 @@ Gateway automatically detects zombie Socket Mode connections and triggers restar

## Persistent Storage

Worker pods now use persistent volumes for data storage:
Worker deployments use persistent volumes for session continuity across scale-to-zero:

1. **Persistent Volumes**: Each worker pod mounts a persistent volume at `/workspace` to preserve data across pod restarts
2. **Auto-Resume**: The worker automatically resumes conversations using Claude CLI's built-in `--resume` functionality when continuing a thread in the same persistent volume
3. **Data Persistence**: All workspace data is preserved in the persistent volume, eliminating the need for conversation file syncing
1. **Per-Deployment PVC**: Each worker deployment gets its own PersistentVolumeClaim (1 thread = 1 PVC) mounted at `/workspace`
2. **Session Storage**: Claude SDK sessions are stored in `/workspace/.claude/` (via `HOME=/workspace` environment variable)
3. **Auto-Resume**: When a worker scales back up, it automatically detects existing sessions in `/workspace/.claude/` and uses Claude CLI's `--continue` flag to resume
4. **Cleanup**: PVCs are automatically deleted when deployments are cleaned up after thread inactivity
5. **Docker Mode**: Uses host directory mounts at `./workspaces/{threadId}/` for equivalent persistence

## MCP OAuth Authentication

Expand Down Expand Up @@ -184,6 +185,9 @@ Basic usage:
# JSON output for automation
./slack-qa-bot.js --json "Create a function" | jq -r .thread_ts

# Test thread continuity
./slack-qa-bot.js "2+3" --timeout 20 --json | jq -r '.thread_ts' | xargs -I {} ./slack-qa-bot.js "add 1 to that number, only answer the number" --thread-ts {} --timeout 25

# Comprehensive E2E testing
./slack-qa-bot.js
```
9 changes: 7 additions & 2 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ RUN echo 'export PATH="/home/bun/.bun/bin:$PATH"' >> /home/claude/.bashrc && \
echo 'export BUN_INSTALL="/home/bun/.bun"' >> /home/claude/.bashrc && \
echo 'export PATH="/root/.cargo/bin:$PATH"' >> /home/claude/.bashrc

# Copy worker-specific package manifest to minimize workspace footprint
COPY package.worker.json ./package.json
# Create minimal package.json for worker-only workspace
RUN echo '{ "name": "@peerbot/worker-build", "private": true, "workspaces": [ "packages/core", "packages/github", "packages/worker" ] }' > package.json

# Copy dependency manifests
COPY bun.lock ./bun.lock
COPY tsconfig.json ./
COPY packages/worker/package.json ./packages/worker/
Expand Down Expand Up @@ -139,4 +141,7 @@ WORKDIR /app/packages/worker
# Set the NODE_ENV as an environment variable
ENV NODE_ENV=${NODE_ENV}

# Set HOME to /workspace so Claude sessions persist in mounted volume
ENV HOME=/workspace

ENTRYPOINT ["/app/entrypoint.sh"]
Loading
Loading