A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Add a Docker image of DS Bot for a NAS or another always-on machine
klarkxy3b318dbdaea0
diff --git a/.dockerignore b/.dockerignorenew file mode 100644index 00000000..d0f907e8--- /dev/null+++ b/.dockerignore@@ -0,0 +1,11 @@+.git+**/node_modules+ds-bot/dev/harness+.dsh-test*+.dsh-home+shots+docs/images+*.tgz+docker/data+docker/workspace+docker/.envdiff --git a/.gitattributes b/.gitattributesnew file mode 100644index 00000000..477c9a46--- /dev/null+++ b/.gitattributes@@ -0,0 +1,2 @@+# Shell scripts are copied into the Docker image as they are; CRLF breaks them.+*.sh text eol=lfdiff --git a/.gitignore b/.gitignoreindex 3dc75482..d07c5286 100644--- a/.gitignore+++ b/.gitignore@@ -12,3 +12,8 @@ node_modules/# Extra patterns for scripts/scan.mjs that must not be named in the repository..scan-extra++# Local Docker deployment data.+/docker/data/+/docker/workspace/+/docker/.envdiff --git a/README.md b/README.mdindex 95f177e4..a121cf85 100644--- a/README.md+++ b/README.md@@ -36,6 +36,10 @@ npx @deepseek-ai/[email protected] plugin --profile web add ds-botnpx @deepseek-ai/[email protected] web```+**Docker (NAS, Linux server)**++The [`docker/`](docker/) directory builds an image with DSH Web and DS Bot, for a NAS or any always-on machine. The container is the Bots' sandbox: they get full access to what you mount into it, and nothing else. See [`docker/README.md`](docker/README.md).+## SetupI strongly recommend that you set up your other bots and group chats by just talking to a bot.diff --git a/README.zh.md b/README.zh.mdindex b005c703..95fc2ac1 100644--- a/README.zh.md+++ b/README.zh.md@@ -36,6 +36,10 @@ npx @deepseek-ai/[email protected] plugin --profile web add ds-botnpx @deepseek-ai/[email protected] web```+**Docker(NAS、Linux 服务器)**++[`docker/`](docker/) 目录构建一个带 dsh Web 和 DS Bot 的镜像,适合 NAS 或其他常开的机器。容器就是 bot 的沙箱:bot 对挂进容器的目录有完全权限,其他的碰不到。见 [`docker/README.md`](docker/README.md)(英文)。+## 配置我强烈建议你直接通过和 bot 对话来配置其他 bot 和群聊。diff --git a/docker/.env.example b/docker/.env.examplenew file mode 100644index 00000000..283a29b4--- /dev/null+++ b/docker/.env.example@@ -0,0 +1,41 @@+# Copy to .env and fill in. docker compose reads .env in this directory.++# Your DeepSeek API key (or the key of the endpoint DEEPSEEK_BASE_URL names).+DEEPSEEK_API_KEY=++# Another Anthropic-Messages-compatible endpoint. Empty = the official one.+# From inside the container, host.docker.internal reaches the Docker host.+#DEEPSEEK_BASE_URL=++# Host names and addresses (no port) the web UI may be opened at, separated by+# commas. dsh web answers 403 on its API for any authority it does not trust,+# so list the NAS IP and every name you open it at. Loopback (localhost,+# 127.0.0.1) is always allowed.+DSH_TRUSTED_HOST=192.168.1.10++# Port on the Docker host the UI is published at (the container always+# listens on 3080 inside).+#DSH_PORT=3080++# Only with network_mode: host: the address and port dsh listens on directly.+# DSH_HOST accepts 0.0.0.0 (all interfaces, the default) or 127.0.0.1.+#DSH_LISTEN_PORT=3080+#DSH_HOST=0.0.0.0++# User and group that own the data and workspace shares on the host.+# `id -u` and `id -g` of the NAS user that owns them.+#PUID=1000+#PGID=1000++# Where dsh keeps its data (team, chats, logins) and where the Bots work.+#DATA_DIR=./data+#WORKSPACE_DIR=./workspace++# dsh telemetry defaults to feedback-only (session logs leave the box only if+# you submit feedback). Set to 1 to turn it off entirely.+#DSH_TELEMETRY_DISABLED=1++# Build arguments (used by `docker compose build`, not at runtime).+# Mainland China: NPM_REGISTRY=https://registry.npmmirror.com/+#NPM_REGISTRY=https://registry.npmjs.org/+#DSH_VERSION=0.2.0-rc.2diff --git a/docker/Dockerfile b/docker/Dockerfilenew file mode 100644index 00000000..3810fbf3--- /dev/null+++ b/docker/Dockerfile@@ -0,0 +1,62 @@+# syntax=docker/dockerfile:1++# Build: installs dsh and packs the plugin, then initializes a template DSH_HOME+# (the web profile with ds-bot installed) that the entrypoint copies into /data+# on first start. Build context is the repository root:+# docker build -f docker/Dockerfile -t ds-bot:local .+FROM node:24-bookworm-slim AS build++ARG NPM_REGISTRY=https://registry.npmjs.org/+ARG DSH_VERSION=0.2.0-rc.2++RUN corepack enable \+ && npm config set registry "$NPM_REGISTRY" --global \+ && COREPACK_NPM_REGISTRY="$NPM_REGISTRY" pnpm config set registry "$NPM_REGISTRY" --global \+ && npm install -g "@deepseek-ai/dsh@${DSH_VERSION}" \+ --allow-scripts=@deepseek-ai/dsh-subprocess-local,node-pty,koffi,@google/genai,protobufjs \+ && pnpm --version > /pnpm-version++COPY ds-bot/ /src/ds-bot/++# ds-bot has no build step at install (client.js is committed), so pack it as-is+# and let `dsh plugin add` set up the web profile from dsh's own template.+# The tgz is kept for reinstalls into existing volumes at container start.+RUN cd /src/ds-bot \+ && npm pack --pack-destination /tmp \+ && mv /tmp/ds-bot-*.tgz /tmp/ds-bot.tgz \+ && DSH_HOME=/opt/dsh-template dsh plugin --profile web add /tmp/ds-bot.tgz++FROM node:24-bookworm-slim++RUN apt-get update \+ && apt-get install -y --no-install-recommends \+ bash git curl ca-certificates \+ python3 python3-pip python3-venv \+ build-essential jq ripgrep unzip zip ffmpeg less procps gosu \+ && rm -rf /var/lib/apt/lists/* \+ && corepack enable++COPY --from=build /usr/local/ /usr/local/+COPY --from=build /opt/dsh-template /opt/dsh-template+COPY --from=build /tmp/ds-bot.tgz /opt/ds-bot/ds-bot.tgz+COPY --from=build /pnpm-version /opt/ds-bot/pnpm-version+COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh+COPY docker/docker.patch.yml /opt/ds-bot/docker.patch.yml++# pnpm as a plain global install (same version the build used) so plugin+# updates work offline for the node user — corepack would re-download it.+# The build stage's npmrc (with NPM_REGISTRY) came over with /usr/local.+RUN rm -f /usr/local/bin/pnpm /usr/local/bin/pnpx \+ && npm install -g "pnpm@$(cat /opt/ds-bot/pnpm-version)"++ENV DSH_HOME=/data \+ DSH_PERMISSION_MODE=danger-full-access++WORKDIR /workspace+EXPOSE 3080+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]++LABEL org.opencontainers.image.title="DS Bot" \+ org.opencontainers.image.description="A team of long-lived Bots on DeepSeek Harness, served by dsh web" \+ org.opencontainers.image.source="https://github.com/Fei2411/DeepSeek-Bot" \+ org.opencontainers.image.licenses="Apache-2.0"diff --git a/docker/README.md b/docker/README.mdnew file mode 100644index 00000000..ac00b0b2--- /dev/null+++ b/docker/README.md@@ -0,0 +1,157 @@+# DS Bot in Docker++This directory deploys DS Bot as a Docker image: a `dsh web` server (DeepSeek+Harness) with the `ds-bot` plugin installed, ready for a NAS or any always-on+box. The container is the sandbox boundary — see [Permissions](#permissions).++## Requirements++- Docker 24+ with Compose v2.24+ (Docker Desktop, or Docker Engine + the+ compose plugin — `env_file.required` needs 2.24).+- Linux containers, x86-64. arm64 builds should work (`node:24-bookworm-slim` is+ multi-arch) but are untested.+- A DeepSeek API key (or another Anthropic-Messages-compatible endpoint through+ `DEEPSEEK_BASE_URL`).++## Quick start++```sh+cd docker+cp .env.example .env+# edit .env: DEEPSEEK_API_KEY, DSH_TRUSTED_HOST (the NAS IP), PUID/PGID+docker compose up -d+docker compose logs ds-bot | grep "dsh web:"+```++The log prints a line like `dsh web: http://127.0.0.1:3080/?token=… (LAN:+http://172.x.x.x:3080/?token=…)`. Take the token from it and open+`http://<NAS IP>:3080/?token=…` once in your browser: the token sets a signed+cookie (valid 30 days, bound to that authority), after which+`http://<NAS IP>:3080/` opens the UI directly. The first time the team opens,+DS Bot creates a Main Bot called Chief.++## Permissions++The container is the only sandbox. DSH's own kernel sandbox (bubblewrap /+Landlock) does not run inside Docker's default seccomp profile or on most NAS+kernels, so the image offers exactly one permission preset, **Full access**:+every Bot command runs without asking. Only mount folders the Bots may change+into `/workspace`, and run the container with `PUID`/`PGID` of the share owner+so file ownership stays right.++## Network++`dsh web` binds only loopback or all interfaces (`0.0.0.0`) — never a concrete+LAN address — and its `--host` flag refuses `0.0.0.0`, so the entrypoint writes+a config overlay that binds all interfaces. Inside a container the publish rule+is the real boundary, and the trust fence below still applies. The UI checks+the `Host` header of every `/api` request: loopback is always trusted, and+every other name or IP you open it at must be listed in `DSH_TRUSTED_HOST`+(no port — a bare entry trusts it on any port), or the API answers 403.+`DSH_HOST=127.0.0.1` narrows the bind to loopback (e.g. a reverse proxy in the+same network namespace); published ports then no longer reach it.++Alternatives:++- **Host network**: set `network_mode: host` in `compose.yml` and drop `ports:`.+ The server then binds the NAS's interfaces directly on `DSH_LISTEN_PORT`+ (default 3080); `DSH_HOST=127.0.0.1` narrows it to loopback again.+- **Reverse proxy / HTTPS**: the proxy must preserve the browser-visible+ `Host` header and forward WebSocket upgrades; add the public host name to+ `DSH_TRUSTED_HOST`. The printed login URL is the container's — replace its+ host with the public one when logging in the first time.++**HTTPS is recommended, not required.** The UI works over plain+`http://<LAN IP>` on this dsh release, but the page is not a secure context+there: API keys and secret values you type cross the LAN in clear text. Put a+reverse proxy in front for regular use.++## Environment variables++See `.env.example` for the full list. The main ones:++| Variable | Purpose |+|---|---|+| `DEEPSEEK_API_KEY` | API key for the model endpoint |+| `DEEPSEEK_BASE_URL` | Override the endpoint (Anthropic-Messages-compatible) |+| `DSH_TRUSTED_HOST` | Comma-separated host names / IPs the UI answers to |+| `DSH_PORT` | Published port on the Docker host (default 3080; the container always listens on 3080) |+| `DSH_HOST` | Bind address: `0.0.0.0` (default) or `127.0.0.1`; only relevant with `network_mode: host` |+| `DSH_LISTEN_PORT` | Listen port inside the container (default 3080); only relevant with `network_mode: host` |+| `PUID` / `PGID` | User/group the server runs as and new files belong to |+| `DSH_TELEMETRY_DISABLED` | `1` turns off dsh's anonymous telemetry |++Extra `dsh` CLI flags can be appended to the container command.++## Custom model endpoint++For an OpenAI-compatible relay (or another provider DSH speaks), create+`DATA_DIR/cordis.patch.yml` before the first start — DSH's home-level patch+layer, applied after the profile's own — with an `llm-pi-ai` provider and an+`agent-default-model` row, and pass the key as an env var:++```yaml+- id: llm-pi-ai+ config:+ providers:+ relay:+ apiKeyEnv: RELAY_API_KEY+ api: openai-completions # or openai-responses / anthropic-messages+ baseURL: http://host.docker.internal:3425/v1+ models:+ - id: my-model+ contextWindow: 131072+ maxTokens: 8192+# New Bots made from the Create Bot form start on DSH's default model;+# point it at the relay too, or they start on deepseek-official without a key.+- id: agent-default-model+ config:+ provider: relay+ model: my-model+```++`RELAY_API_KEY` rides in from `.env` through `env_file`. The alternative is+Settings → Models in the UI, which writes the same config.++## Data++- `/data` (`DATA_DIR`) is `DSH_HOME`: the team and chats (`bot/`, `sessions/`),+ profiles, settings and the login cookie key (`.credentials.yaml`).+- `/workspace` (`WORKSPACE_DIR`) is the team workspace where the Bots work.++**Backup**: stop the container, then copy `DATA_DIR`. Restore by putting the+folder back and starting again.++## Updating++```sh+docker compose build # or: docker build -f docker/Dockerfile -t ds-bot:local .+docker compose up -d+```++DSH itself lives in the image and updates on rebuild. The plugin lives in the+profile inside the data volume, so the entrypoint compares the installed ds-bot+version with the image's on every start and reinstalls it into the web profile+when they differ — a new image updates an existing volume automatically.+Rebuilds with the same ds-bot version skip the reinstall; to force a fresh+profile, stop the container and delete `DATA_DIR/profiles/web` (not the whole+data dir). The image is built and tested with dsh `0.2.0-rc.2`, the version+DS Bot is verified with; a `DSH_VERSION` build arg exists, but other releases+are untested and newer ones change how the server binds.++## Importing an existing team++To move a team from a dsh you already run: stop this container, then copy+`bot/`, `sessions/` and `storages/` from the old `DSH_HOME` (`~/.dsh`) into+`DATA_DIR` — but not `profiles/`, which the image seeds itself. The ds-bot+README's "Move to another computer" caveat applies: workspace paths are stored+as absolute paths, so this is safest between two Linux deployments (the+container's workspace is always `/workspace`).++## Limits++- No Bot browser / `read_browser` tool: those exist in dsh Desktop only.+- Over plain http, API keys and secret values you type cross the network in+ clear text — use HTTPS off-box (see [Network](#network)).+- Full access is the only permission mode: a Bot can change everything the+ container can see.diff --git a/docker/compose.yml b/docker/compose.ymlnew file mode 100644index 00000000..2a4366d2--- /dev/null+++ b/docker/compose.yml@@ -0,0 +1,21 @@+services:+ ds-bot:+ build:+ context: ..+ dockerfile: docker/Dockerfile+ args:+ NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.npmjs.org/}+ DSH_VERSION: ${DSH_VERSION:-0.2.0-rc.2}+ image: ds-bot:local+ ports:+ - "${DSH_PORT:-3080}:3080"+ env_file:+ - path: .env+ required: false+ volumes:+ - ${DATA_DIR:-./data}:/data+ - ${WORKSPACE_DIR:-./workspace}:/workspace+ extra_hosts:+ - "host.docker.internal:host-gateway"+ restart: unless-stopped+ stop_grace_period: 15sdiff --git a/docker/docker.patch.yml b/docker/docker.patch.ymlnew file mode 100644index 00000000..3417c350--- /dev/null+++ b/docker/docker.patch.yml@@ -0,0 +1,15 @@+# Image-owned overlay: the container is the sandbox boundary, so only full+# access is offered, and the Bots' working folder is /workspace. The webserver+# bind host/port come from a second overlay the entrypoint writes per start.+- id: permission+ config:+ presets:+ danger-full-access:+ sandbox: danger-full-access+ approval: never+ name: Full access+ description: The container is the boundary. Bots can change every file it can see.+ defaultPreset: danger-full-access+- id: bot+ config:+ workspace: /workspacediff --git a/docker/entrypoint.sh b/docker/entrypoint.shnew file mode 100644index 00000000..ddb198a6--- /dev/null+++ b/docker/entrypoint.sh@@ -0,0 +1,79 @@+#!/bin/sh+# Runs dsh web as the node user. The container is the sandbox boundary, so the+# image offers only the danger-full-access preset (see docker.patch.yml).+set -eu++PUID=${PUID:-1000}+PGID=${PGID:-1000}+groupmod -o -g "$PGID" node+usermod -o -u "$PUID" node++# First start: seed the data volume with the template home built into the image+# (a web profile that already has ds-bot installed).+if [ ! -d /data/profiles/web ]; then+ mkdir -p /data+ cp -a /opt/dsh-template/. /data/+ chown -R node:node /data+fi+# Every start: /data itself must be writable by node; the files below keep the+# ownership they got on first start or from the host.+chown node:node /data++mkdir -p /workspace+# Only claim an empty /workspace; a populated share keeps its owners.+if [ -z "$(ls -A /workspace)" ]; then+ chown node:node /workspace+fi++# Keep an existing volume's ds-bot in step with the image. A failed reinstall+# is logged but never blocks the start — the old plugin keeps working.+installed_ver=$(jq -r .version /data/profiles/web/node_modules/ds-bot/package.json 2>/dev/null || echo missing)+image_ver=$(jq -r .version /opt/dsh-template/profiles/web/node_modules/ds-bot/package.json)+if [ "$installed_ver" != "$image_ver" ]; then+ echo "entrypoint: ds-bot $installed_ver -> $image_ver, reinstalling into the web profile"+ HOME=/home/node gosu node dsh plugin --profile web add /opt/ds-bot/ds-bot.tgz \+ || echo "entrypoint: ds-bot reinstall failed; continuing with $installed_ver" >&2+fi++# This dsh release accepts only 127.0.0.1 for --host, so an overlay binds all+# interfaces instead; the container's publish rule is the network boundary.+# DSH_LISTEN_PORT only matters with network_mode: host — published ports+# always map to 3080 inside.+HOST=${DSH_HOST:-0.0.0.0}+LISTEN_PORT=${DSH_LISTEN_PORT:-3080}+case "$HOST" in+ 0.0.0.0|127.0.0.1) ;;+ *) echo "entrypoint: DSH_HOST must be 0.0.0.0 or 127.0.0.1 (got '$HOST')" >&2; exit 1 ;;+esac+case "$LISTEN_PORT" in+ ''|*[!0-9]*) echo "entrypoint: DSH_LISTEN_PORT must be a port number (got '$LISTEN_PORT')" >&2; exit 1 ;;+esac++# The webserver row's whole config is replaced by a patch, so its bundle values+# (compression on this dsh release) are restated literally.+cat > /tmp/listen.patch.yml <<EOF+- id: webserver+ config:+ host: $HOST+ port: $LISTEN_PORT+ compression: gzip+ compressionLevel: 1+ compressionThresholdBytes: 1024+EOF++# --patch is a dsh option and must precede the app's own flags.+set -- dsh --profile web \+ --patch /opt/ds-bot/docker.patch.yml --patch /tmp/listen.patch.yml \+ --no-open "$@"++if [ -n "${DSH_TRUSTED_HOST:-}" ]; then+ old_ifs=$IFS+ IFS=','+ for trusted in $DSH_TRUSTED_HOST; do+ [ -n "$trusted" ] && set -- "$@" --trusted-host "$trusted"+ done+ IFS=$old_ifs+fi+export HOME=/home/node+cd /workspace+exec gosu node "$@"