# TS Worker — Bun-based worker container for the Claw architecture.
#
# The Rust gateway launches this container per profile and routes
# Telegram/Mini App traffic to it via the worker protocol.
#
# Build:
#   docker build -f src/worker/Dockerfile -t claw-ts-worker .
#
# Run:
#   docker run --rm \
#     -e CLAW_WORKER_BIND_ADDR=0.0.0.0 \
#     -e CLAW_WORKER_PORT=8780 \
#     -e ANTHROPIC_API_KEY=sk-... \
#     -p 8780:8780 \
#     claw-ts-worker

FROM oven/bun:1.3

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install dependencies
COPY package.json bun.lock* ./
RUN bun install --frozen-lockfile || bun install

# Copy worker source (only what's needed)
COPY src/worker/ src/worker/

# Create state directories
RUN mkdir -p /state/claude-home /state/claw /workspace

# Default env
ENV CLAW_WORKER_BIND_ADDR=0.0.0.0:8080
ENV CLAW_WORKER_STATE_ROOT=/state
ENV CLAW_WORKER_DEFAULT_CWD=/workspace
ENV CLAW_WORKER_MODEL=claude-sonnet-4-6
ENV CLAW_WORKER_PERMISSION_MODE=default
ENV CLAUDE_CONFIG_DIR=/state/claude-home

EXPOSE 8080

HEALTHCHECK --interval=10s --timeout=3s --start-period=5s \
  CMD curl -f http://localhost:8080/healthz || exit 1

CMD ["bun", "run", "src/worker/main.ts"]
