Răsfoiți Sursa

【初始】

设计并实现 DeepSeek Harness Web 容器化项目:单容器(dsh + Caddy basic auth,supervisord 管理)、./data bind mount 持久化、.env 注入密钥与密码、CI 自动推送 GHCR(ghcr.io/Xidong-AI/deepseek-harness-web-docker)。
PJ568 3 luni în urmă
comite
1dfb1a5e47

+ 10 - 0
.dockerignore

@@ -0,0 +1,10 @@
+# 构建上下文精简(Dockerfile 仅 COPY 所需文件)
+# Trim the build context (Dockerfile only COPYs the files it needs)
+.git
+.gitignore
+.env
+data
+DESIGN.md
+README.md
+LICENSE
+.github

+ 23 - 0
.env.example

@@ -0,0 +1,23 @@
+# ===== DeepSeek Harness Web Docker 配置 | DeepSeek Harness Web Docker configuration =====
+# 复制为 .env 后编辑(.env 不入库,含敏感信息)
+# Copy to .env and edit (.env is not committed; it contains sensitive info)
+
+# basic auth 用户名(必填)| Basic auth username (required)
+DSH_AUTH_USER=admin
+# basic auth 明文密码(必填,容器启动时自动生成 bcrypt 哈希)
+# Basic auth plaintext password (required; a bcrypt hash is auto-generated at container startup)
+DSH_AUTH_PASSWORD=change-me
+# DeepSeek API Key(必填,settings.yaml 经 apiKeyEnv 引用)
+# DeepSeek API Key (required; referenced by settings.yaml via apiKeyEnv)
+DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxx
+# 宿主机对外端口(可选,默认 3080;本机已有服务占用时请修改)
+# Host-facing port (optional, default 3080; change it if the local port is already in use)
+DSH_WEB_PORT=3080
+# 额外受信 Host(可选,逗号分隔;公网域名/自定义域名访问时填写,
+# Additional trusted hosts (optional, comma-separated; fill in for public/custom domain access,
+# 注入 profile 的 cordis.patch.yml。默认靠 Caddy 改写 loopback 已覆盖常规访问)
+# injected into the profile's cordis.patch.yml. The Caddy loopback rewrite covers regular access by default)
+#DSH_TRUSTED_HOSTS=dsh.example.com,example.org
+# dsh 版本(构建期,可选;默认 0.1.0-rc.6,改后需 --build 重建镜像)
+# dsh version (build-time, optional; default 0.1.0-rc.6; rebuild with --build after changing)
+#DSH_VERSION=0.1.0-rc.6

+ 50 - 0
.github/workflows/docker-build.yml

@@ -0,0 +1,50 @@
+# 自动构建并推送 GHCR:push master 触发
+# 镜像 tag:latest + 日期时间 - 提交哈希(如 20260815T0054-a1b2c3d)
+#
+# Auto-build and push to GHCR: triggered on push to master
+# Image tags: latest + datetime-commit-hash (e.g. 20260815T0054-a1b2c3d)
+name: build-push-ghcr
+
+on:
+  push:
+    branches: [master]
+
+env:
+  IMAGE: ghcr.io/xidong-ai/deepseek-harness-web-docker
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      packages: write
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v3
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+
+      - name: Log in to GHCR
+        uses: docker/login-action@v3
+        with:
+          registry: ghcr.io
+          username: ${{ github.actor }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+
+      - name: 生成日期时间 - 哈希 tag
+        id: meta
+        run: |
+          echo "tag=$(date +%Y%m%dT%H%M)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
+
+      - name: Build and push
+        uses: docker/build-push-action@v6
+        with:
+          context: .
+          push: true
+          platforms: linux/amd64,linux/arm64
+          tags: |
+            ${{ env.IMAGE }}:latest
+            ${{ env.IMAGE }}:${{ steps.meta.outputs.tag }}

+ 117 - 0
.github/workflows/upstream-check.yml

@@ -0,0 +1,117 @@
+# 定时检查 dsh 上游版本:有新版本 → 提升版本号 → 构建冒烟测试 → 通过则推送 master,失败则创建 Issue
+# 推送 master 会触发 docker-build.yml 自动构建 GHCR 镜像,形成「升级 → 发布」闭环
+#
+# Scheduled dsh upstream check: bump version on update → build & smoke test → push master on success, open an Issue on failure
+# Pushing to master triggers docker-build.yml, which builds GHCR images — an "upgrade → release" loop
+name: check-dsh-upstream
+
+on:
+  schedule:
+    # 每日 UTC 03:00(北京时间 11:00)
+    #
+    # Daily 03:00 UTC (11:00 Beijing time)
+    - cron: "0 3 * * *"
+  workflow_dispatch:
+
+permissions:
+  contents: read
+
+concurrency:
+  group: check-dsh-upstream
+  cancel-in-progress: false
+
+jobs:
+  check:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      issues: read
+    outputs:
+      current: ${{ steps.check.outputs.current }}
+      latest: ${{ steps.check.outputs.latest }}
+      should_upgrade: ${{ steps.check.outputs.should_upgrade }}
+      blocked: ${{ steps.gate.outputs.blocked }}
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: 查询上游版本并比较
+        id: check
+        run: |
+          scripts/check-upstream.sh | tee -a "$GITHUB_OUTPUT"
+
+      # 门闩:同版本已有未关闭的失败 Issue 时跳过自动升级(npm 包版本不可变,重试必失败)
+      # 仅定时触发生效;手动触发(workflow_dispatch)绕过,用于人工重试环境性失败
+      #
+      # Gate: skip auto-upgrade when an open failure Issue exists for this version (npm versions are immutable, retry is doomed)
+      # Only applies to schedule runs; manual dispatch bypasses it for human-driven retries
+      - name: 门闩检查:同版本失败 Issue
+        id: gate
+        if: steps.check.outputs.should_upgrade == 'true' && github.event_name == 'schedule'
+        run: |
+          BLOCKED="$(scripts/check-issue-gate.sh "$LATEST")"
+          echo "blocked=$BLOCKED" >> "$GITHUB_OUTPUT"
+          if [ "$BLOCKED" = "1" ]; then
+            echo "存在 $LATEST 的未关闭失败 Issue,跳过本次自动升级(可手动触发强制重试)"
+          fi
+        env:
+          LATEST: ${{ steps.check.outputs.latest }}
+
+      - name: 打印检查结果
+        run: |
+          echo "当前版本 (current): ${{ steps.check.outputs.current }}"
+          echo "上游最新 (latest):  ${{ steps.check.outputs.latest }}"
+          echo "需要升级 (upgrade): ${{ steps.check.outputs.should_upgrade }}"
+          echo "被门闩拦截 (blocked): ${{ steps.gate.outputs.blocked }}"
+
+  upgrade:
+    needs: check
+    if: needs.check.outputs.should_upgrade == 'true' && needs.check.outputs.blocked != 'true'
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+      issues: write
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: 提升版本号(Dockerfile / compose / README 双语)
+        run: |
+          scripts/upgrade-dsh.sh "$LATEST"
+        env:
+          LATEST: ${{ needs.check.outputs.latest }}
+
+      - name: 构建镜像并冒烟测试
+        id: smoke
+        run: |
+          scripts/smoke-test.sh "$LATEST"
+        env:
+          LATEST: ${{ needs.check.outputs.latest }}
+
+      - name: 推送升级至 master
+        run: |
+          git config user.name "github-actions[bot]"
+          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+          git add Dockerfile docker-compose.yml README.md README.zh.md
+          git commit -m "【维护,构建】升级 dsh 版本至 $LATEST"
+          git push origin master
+        env:
+          LATEST: ${{ needs.check.outputs.latest }}
+
+      # 升级已成功:旧版本的失败 Issue 均已过时,关闭以免陈旧累积
+      # continue-on-error:清理失败不影响升级结果(不触发下方 failure() 步骤)
+      #
+      # The upgrade succeeded: failure Issues for older versions are stale; close them to avoid accumulation
+      # continue-on-error: cleanup failure must not fail the upgrade (must not trigger the failure() step below)
+      - name: 关闭过时的失败 Issue
+        continue-on-error: true
+        run: |
+          scripts/close-stale-issues.sh
+        env:
+          LATEST: ${{ needs.check.outputs.latest }}
+
+      - name: 失败时创建 Issue(同版本去重)
+        if: failure()
+        run: |
+          scripts/open-issue.sh "$LATEST" "$CURRENT"
+        env:
+          LATEST: ${{ needs.check.outputs.latest }}
+          CURRENT: ${{ needs.check.outputs.current }}

+ 7 - 0
.gitignore

@@ -0,0 +1,7 @@
+# 敏感文件与本地数据 | Sensitive files and local data
+.env
+data/
+
+# 本地构建工具目录(沙箱/测试用)
+# Local build tool directory (for sandbox/testing)
+.docker-local/

+ 33 - 0
Caddyfile

@@ -0,0 +1,33 @@
+# 反向代理配置
+#
+# Reverse proxy configuration
+#
+# DSH 反向代理:basic auth + 转发到容器内 dsh 127.0.0.1:3080
+#
+# DSH reverse proxy: basic auth + forwarding to the in-container dsh at 127.0.0.1:3080
+#
+# 注意:
+# - 容器内必须监听 0.0.0.0(Docker 端口映射 DNAT 到容器 eth0,bind loopback 会拒接映射流量)
+# - DSH 特权 API(settings.*/credentials.*)只接受 loopback 来源(防 DNS rebinding),
+#   必须把 Host/Origin 改写为 127.0.0.1:3080 使 dsh 视为本机来源;
+#   Origin 必须与改写后 Host 同源,否则 fence 的 Origin 检查仍 403
+# - bcrypt 哈希含 $ 字符,必须经环境变量注入({$DSH_AUTH_HASH}),不能直写本文件
+# - http:// 前缀显式声明纯 HTTP 站点,禁用 auto-HTTPS/本地 CA
+#
+# Notes:
+# - Must listen on 0.0.0.0 inside the container (Docker port mapping DNATs to container eth0; binding loopback rejects mapped traffic)
+# - DSH privileged APIs (settings.*/credentials.*) accept only loopback origins (anti-DNS-rebinding),
+#   Host/Origin must be rewritten to 127.0.0.1:3080 so dsh treats it as a local origin;
+#   Origin must match the rewritten Host, otherwise the fence's Origin check still returns 403
+# - bcrypt hashes contain $, so they must be injected via environment variable ({$DSH_AUTH_HASH}), never written inline
+# - The http:// prefix explicitly declares a plain-HTTP site, disabling auto-HTTPS/local CA
+http://:3081 {
+	basic_auth {
+		{$DSH_AUTH_USER} {$DSH_AUTH_HASH}
+	}
+
+	reverse_proxy 127.0.0.1:3080 {
+		header_up Host 127.0.0.1:3080
+		header_up Origin http://127.0.0.1:3080
+	}
+}

+ 219 - 0
DESIGN.md

@@ -0,0 +1,219 @@
+# DeepSeek Harness Web Docker 设计文档
+
+> 状态:设计稿(v1,已与需求方对齐,未进入实现)
+
+## 1. 项目概述
+
+把 DeepSeek Harness(DSH)Web 客户端 + 基础认证反代容器化,交付一个**可复现、面向最终用户**的单容器镜像:
+
+- 容器内托管 dsh Web 客户端(监听容器内 loopback,不对外)
+- 内置 Caddy basic auth 用户名密码保护
+- 配置与项目/会话数据经 bind mount 持久化到宿主机
+- CI 自动构建并推送 GHCR(`ghcr.io/xidong-ai/deepseek-harness-web-docker`)
+
+参考现有宿主机实现(`~/.local/bin/dsh`、`~/.local/bin/caddy-dsh`),但项目独立、不含个人私有配置,适合推送给其他用户。
+
+## 2. 架构
+
+```
+浏览器 ──HTTP──> 宿主机:${DSH_WEB_PORT:-3080}
+                    │  docker compose ports 映射
+                    ▼
+        ┌─────────── Docker 容器 ────────────────────────────┐
+        │  supervisord (PID 1)                                │
+        │  ├─ caddy  0.0.0.0:3081                             │
+        │  │   ├─ basic_auth(用户 ${DSH_AUTH_USER},bcrypt)│
+        │  │   └─ reverse_proxy 127.0.0.1:3080                │
+        │  │       header_up Host/Origin → loopback           │
+        │  └─ dsh --profile web --port 3080                   │
+        │       (仅 bind 127.0.0.1:3080,不对外)             │
+        │                                                     │
+        │  /home/dsh/.dsh ◄── bind mount ──> ./data           │
+        └─────────────────────────────────────────────────────┘
+```
+
+### 2.1 为什么 dsh 与 Caddy 必须同容器共享 loopback
+
+DSH v0.1 无内置认证,且特权 API(`settings.*`/`credentials.*`,`PRIVILEGED_METHODS` 硬编码空信任列表)**只接受 loopback 来源**(防 DNS rebinding)。因此:
+
+- 反代必须与 dsh 处于同一 network namespace,经 `127.0.0.1:3080` 转发
+- Caddy 必须把上游请求的 `Host`/`Origin` 改写为 `127.0.0.1:3080`,使 dsh 视为本机来源(Origin 必须与改写后 Host 同源,否则 fence 的 Origin 检查仍 403)
+- 若拆成 compose 多服务,跨容器请求的来源不是 loopback,特权 API 必然 403——故**单容器是硬约束,不是偏好**
+
+### 2.2 与现有实现的差异(容器化的关键修正)
+
+| 项目 | 宿主机现有(参考) | 容器内 |
+| --- | --- | --- |
+| dsh 监听 | `127.0.0.1:3080` | `127.0.0.1:3080`(不变) |
+| Caddy 监听 | `bind 127.0.0.1 ::1` 的 `:3081` | `0.0.0.0:3081`(Docker 端口映射 DNAT 到容器 eth0,bind loopback 会拒接映射流量) |
+| 对外端口 | 公网经 cloudflared → 3081 | `${DSH_WEB_PORT:-3080}:3081`,默认 3080 |
+| 进程管理 | pm2(宿主机开机自启) | supervisord(容器 PID 1) |
+| 配置目录 | `~/.dsh/`(HOME 本机) | `/home/dsh/.dsh/`,bind mount `./data` |
+| basic auth 密码 | `ecosystem.config.js` 里 bcrypt 哈希 | `.env` 明文,entrypoint 启动时自动哈希 |
+| profile web | 软链到 dot-files 仓库 | 镜像内置默认模板,entrypoint 首启复制进数据卷 |
+| trustedHosts | 硬编码 `dsh.pj568.eu.org` | `.env` 可选变量注入,默认靠 Caddy 改写 |
+
+## 3. 关键决策记录(对齐结论)
+
+| # | 决策点 | 结论 |
+| --- | --- | --- |
+| 1 | 容器编排形态 | 单容器:dsh + Caddy 共存(supervisord 管理) |
+| 2 | 镜像基础 | `node:22-slim`(Debian glibc)+ `npm i -g` 装 dsh;Caddy 官方静态二进制 |
+| 3 | 进程管理 | supervisord(PID 1 正确处理信号,日志转发 stdout/stderr) |
+| 4 | 运行用户 | 专用非 root 用户 `dsh`(uid 1000),HOME=`/home/dsh` |
+| 5 | 持久化 | bind mount `./data` → `/home/dsh/.dsh/`(整个目录:settings/credentials/profiles/sessions/storages) |
+| 6 | 认证密码 | `.env` 放明文 `DSH_AUTH_PASSWORD`,entrypoint 用 `caddy hash-password` 生成 bcrypt 注入 |
+| 7 | dsh 版本 | Dockerfile `ARG DSH_VERSION=0.1.0-rc.6`,可构建时覆盖 |
+| 8 | 对外端口 | `${DSH_WEB_PORT:-3080}:3081`,环境变量可改(本机测试时换端口避开现有 3080/3081) |
+| 9 | 首启初始化 | 镜像内置最小 web profile + settings.yaml 模板,entrypoint 检测数据卷为空时复制,之后持久化 |
+| 10 | trustedHosts | `DSH_TRUSTED_HOSTS`(可选,逗号分隔)注入 `cordis.patch.yml`;默认靠 Caddy 改写 loopback |
+| 11 | API Key | 仅 `.env` 注入:`DEEPSEEK_API_KEY`,settings.yaml 用 `apiKeyEnv` 引用 |
+| 12 | settings 模板 | 最小通用:`deepseek-official`(apiKeyEnv)+ `agent-default-model`;不含个人私有 provider |
+| 13 | 与现有部署关系 | 独立通用项目,推送给用户;本机测试用另一端口,不影响现有 pm2 部署 |
+| 14 | 分发 | 源码(Dockerfile + compose)+ CI 自动构建推 GHCR |
+| 15 | GHCR 路径 | `ghcr.io/xidong-ai/deepseek-harness-web-docker` |
+| 16 | CI 触发/tag | push master 触发;镜像 tag = 日期时间 + 提交哈希(另推 `latest` 便于 compose 默认引用) |
+
+## 4. 文件清单
+
+```
+deepseek-harness-web-docker/
+├── Dockerfile                  # node:22-slim + dsh(npm, ARG 版本) + caddy + supervisord + entrypoint
+├── docker-compose.yml          # 单服务;ports: ${DSH_WEB_PORT:-3080}:3081;./data bind mount
+├── .env.example                # 全部可配变量的模板(提交入库,.env 不入库)
+├── .gitignore                  # .env、data/(含 .credentials.yaml 等敏感文件)
+├── .dockerignore
+├── README.md                   # 面向用户:快速开始、变量说明、升级、排错
+├── LICENSE
+├── Caddyfile                   # basic_auth + reverse_proxy(容器内 /etc/caddy/Caddyfile)
+├── supervisord.conf            # 两个 program:dsh、caddy(容器内 /etc/supervisor/conf.d/dsh.conf)
+├── entrypoint.sh               # 首启初始化 + 哈希注入 + 降权启动 supervisord
+├── defaults/                   # 镜像内置默认配置(COPY 进镜像 /opt/dsh/defaults)
+│   ├── settings.yaml           # deepseek-official(apiKeyEnv: DEEPSEEK_API_KEY) + agent-default-model
+│   └── profiles/web/
+│       ├── package.json        # dsh.profile.bundles: [@deepseek-ai/dsh-base, @deepseek-ai/dsh-web-app]
+│       ├── cordis.yml          # [](空入口,patch 机制组合)
+│       ├── cordis.patch.yml    # connection.trustedHosts 占位(entrypoint 按 DSH_TRUSTED_HOSTS 注入)
+│       └── pnpm-workspace.yaml # packages: [.],nodeLinker: hoisted
+├── .github/workflows/
+│   └── docker-build.yml        # push master → buildx → tag(日期时间-哈希, latest) → push GHCR
+└── data/                       # 持久化卷(git 忽略,运行期生成)
+```
+
+### 4.1 各文件要点
+
+- **Dockerfile**:`ARG DSH_VERSION=0.1.0-rc.6` → `npm install -g @deepseek-ai/dsh@${DSH_VERSION}`;下载 Caddy 官方二进制(glibc);`apt-get install supervisor`;创建 `dsh` 用户(uid 1000);COPY defaults、Caddyfile、entrypoint、supervisord.conf;`ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]`
+- **docker-compose.yml**:单服务 `dsh-web`;`ports: ["${DSH_WEB_PORT:-3080}:3081"]`;`volumes: ["./data:/home/dsh/.dsh"]`;`env_file: .env`(必填 `DSH_AUTH_PASSWORD`、`DEEPSEEK_API_KEY`);`restart: unless-stopped`
+- **Caddyfile**:
+  ```
+  http://:3081 {
+      basic_auth {
+          {$DSH_AUTH_USER} {$DSH_AUTH_HASH}
+      }
+      reverse_proxy 127.0.0.1:3080 {
+          header_up Host 127.0.0.1:3080
+          header_up Origin http://127.0.0.1:3080
+      }
+  }
+  ```
+  (bcrypt 含 `$` 必须经环境变量注入,不能直写 Caddyfile;`{$VAR}` 引用安全)
+
+- **entrypoint.sh**(bash,按序执行):
+  1. 若 `/home/dsh/.dsh` 为空:从 `/opt/dsh/defaults` 复制 `settings.yaml` 与 `profiles/web/`,并创建 `profiles/web/node_modules` 软链指向 `/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules`(bundle 解析需要,参考现有 `profiles/node_modules` 软链做法)
+  2. 若 `DSH_TRUSTED_HOSTS` 非空:以逗号分隔项替换 `cordis.patch.yml` 的 `trustedHosts` 占位
+  3. `DSH_AUTH_HASH=$(caddy hash-password --plaintext "$DSH_AUTH_PASSWORD")`,导出给 supervisord 子进程
+  4. `chown -R dsh:dsh /home/dsh/.dsh`(bind mount 首启属主可能是 root)
+  5. supervisord 以 root 启动、program 指定 `user=dsh`(避免 su 嵌套)
+- **supervisord.conf**:`[program:dsh]` 执行 `dsh --profile web --port 3080`(不传 `--trusted-host`,该链路不可靠;trustedHosts 走 cordis.patch.yml);`[program:caddy]` 执行 `caddy run --config /etc/caddy/Caddyfile --adapter caddyfile`;均 `stdout_logfile=/dev/stdout`、`autorestart=true`
+- **defaults/settings.yaml**:
+  ```yaml
+  deepseek-official:
+    providers:
+      deepseek:
+        apiKeyEnv: DEEPSEEK_API_KEY
+  agent-default-model:
+    provider: deepseek
+    model: deepseek-v4-pro
+    reasoningEffort: high
+  ```
+  (字段名以实际 dsh schema 为准,实现时用本机 rc.6 实例核对后定稿)
+- **defaults/profiles/web/cordis.patch.yml** 占位:
+  ```yaml
+  - id: connection
+    config:
+      trustedHosts: []
+  ```
+- **.github/workflows/docker-build.yml**:`on: push: branches: [master]`;buildx(`linux/amd64`,可选 `linux/arm64` 多架构)→ tag `latest` + `${日期时间}-${sha7}`(如 `20260815T0054-a1b2c3d`)→ push `ghcr.io/xidong-ai/deepseek-harness-web-docker`(用 `GITHUB_TOKEN`,组织级包权限需在仓库设置开启)
+
+## 5. 环境变量参考(.env.example)
+
+| 变量 | 必填 | 默认 | 说明 |
+| --- | --- | --- | --- |
+| `DSH_AUTH_USER` | 是 | `admin` | basic auth 用户名 |
+| `DSH_AUTH_PASSWORD` | 是 | 无 | basic auth 明文密码(entrypoint 自动生成 bcrypt) |
+| `DEEPSEEK_API_KEY` | 是 | 无 | DeepSeek API Key(settings.yaml 经 apiKeyEnv 引用) |
+| `DSH_WEB_PORT` | 否 | `3080` | 宿主机对外端口(测试时可改,如 3082) |
+| `DSH_TRUSTED_HOSTS` | 否 | 空 | 逗号分隔的额外受信 Host(公网域名/自定义域名),注入 cordis.patch.yml;默认靠 Caddy 改写 loopback 已覆盖常规访问 |
+| `DSH_VERSION` | 否(构建期) | `0.1.0-rc.6` | Dockerfile ARG,构建镜像时固定 |
+
+> `.env` 不入库;`.env.example` 入库。API Key 与密码均为敏感信息,bind mount 的 `data/.credentials.yaml` 同样敏感,`.gitignore` 必须覆盖。
+
+## 6. 用户运行说明(README 草案要点)
+
+```bash
+git clone <repo>
+cd deepseek-harness-web-docker
+cp .env.example .env          # 编辑 DSH_AUTH_USER/PASSWORD、DEEPSEEK_API_KEY
+docker compose up -d --build  # 或 docker compose up -d(用 GHCR 镜像时)
+# 浏览器访问 http://<host>:3080,输入 basic auth 用户名密码
+```
+
+- 配置与项目/会话数据持久化在 `./data`,删容器不丢
+- 升级:`docker compose pull` + `docker compose up -d`(数据卷不动)
+- 改密码:改 `.env` 后 `docker compose up -d`(entrypoint 重新哈希)
+- 公网暴露(可选):配合 Cloudflare Tunnel/反代,把公网域名填入 `DSH_TRUSTED_HOSTS` 并建议加 HTTPS
+
+## 7. 安全注意事项
+
+- basic auth 是**基础**认证:HTTP 明文传输时密码可被嗅探,公网使用必须套 HTTPS(Caddy 容器内仅 HTTP,HTTPS 由外层隧道/反代终结)
+- dsh 不直接对外暴露:容器内仅 bind `127.0.0.1:3080`,compose 不映射该端口
+- 特权 API 依赖 Caddy 改写 Host/Origin 为 loopback 才可通过;Caddyfile 不可去掉 `header_up` 两行
+- 容器非 root 运行(uid 1000),数据卷属主由 entrypoint 修正
+- `data/`、`.env` 含密钥,禁止入库
+
+## 8. 验证计划(实现阶段的 TDD 冒烟测试)
+
+1. **构建**:`docker build --build-arg DSH_VERSION=0.1.0-rc.6 -t dsh-web:test .` 成功
+2. **首启初始化**:清空 `./data` 后起容器,验证 `data/settings.yaml`、`data/profiles/web/*` 生成、属主为 1000
+3. **basic auth**:无凭据 `curl -o /dev/null -w "%{http_code}" http://127.0.0.1:${DSH_WEB_PORT}/` 应 401;带 `-u` 应 200
+4. **dsh 响应**:带凭据访问 `/` 返回 dsh Web 页面;`/api` 健康接口 200(Host/Origin 改写生效,无 fence 403)
+5. **持久化**:重启容器后 `data/` 内容不变;`docker compose down && up` 后 settings 仍在
+6. **密码轮换**:改 `.env` 密码重建容器,旧密码 401、新密码 200
+7. **trustedHosts**:设 `DSH_TRUSTED_HOSTS=example.com` 后检查 `data/profiles/web/cordis.patch.yml` 注入正确
+8. **CI**:本地 `act` 或推 master 后确认 GHCR 出现 `latest` 与日期时间 - 哈希 tag
+
+本机测试必须改 `DSH_WEB_PORT`(如 3082)避开现有 pm2 的 3080/3081。
+
+## 9. 后续实现任务(按序)
+
+1. 建 Dockerfile + defaults(settings.yaml 字段以本机 rc.6 实际 schema 核对)
+2. entrypoint.sh + supervisord.conf + Caddyfile
+3. docker-compose.yml + .env.example + .gitignore/.dockerignore
+4. 本机冒烟测试(§8,另一端口)
+5. README + LICENSE
+6. GitHub Actions workflow → push master 验证 GHCR
+7. 合入 master(单目标提交,遵循提交规范)
+## 10. 实现差异记录(实现阶段实测修正)
+
+| 设计稿 | 实现实测 | 原因 |
+| --- | --- | --- |
+| 镜像内置默认 web profile,entrypoint 首启复制 | defaults 仅含 settings.yaml;profile 由 dsh 首启自动初始化(dsh-app-boot 的 PROFILE_TEMPLATES.web + initProfile),entrypoint 仅在设置 DSH_TRUSTED_HOSTS 时预写 cordis.patch.yml | 代码调研发现 dsh 内置 web profile 模板且自动维护 profiles/node_modules 软链(healProfilesModuleFallback),无需内置复制 |
+| 专用非 root 用户 dsh(uid 1000),数据目录 /home/dsh/.dsh | 复用官方镜像自带 node 用户(uid 1000),数据目录 /home/node/.dsh | node:22-slim 已自带 uid 1000 的 node 用户,避免删除/重建用户 |
+| npm i -g 纯 JS 安装 | 需先装 build-essential + python3(node-pty 等 native 依赖编译),装完清理 build-essential | dsh 依赖 node-pty(node-gyp 编译),slim 镜像无工具链 |
+| GHCR 路径 ghcr.io/Xidong-AI/... | 全小写 ghcr.io/xidong-ai/... | Docker registry 仓库名必须小写 |
+| 容器内 Caddyfile 可读 | 需显式 chmod 644 /etc/caddy/Caddyfile | COPY 保留源 600 权限,node 用户读不了 |
+| 容器内工具集 | 镜像补充 git/openssh-client/curl/jq/unzip + corepack pnpm;并集成 x-cmd 环境自举 | agent 的 bash 工具环境是白名单(PATH 固定 /usr/local/bin 等、无 HOME),镜像预装保证基础可用,x-cmd 让 agent 免 root 自装工具(持久化于卷);x wrapper 注入 HOME,use 包 shim 软链至 /usr/local/bin |
+| 数据卷布局 | bind mount 从 /home/node/.dsh 扩为整个 /home/node | x-cmd 安装于 $HOME/.x-cmd.root(硬编码 HOME 路径),需要 HOME 整体持久化;.dsh 数据兼容保留 |
+| defaults 内容 | 增加 AGENTS.md(容器环境指引,dsh 会话自动加载) | agent 需要知道容器环境限制与 x-cmd 用法 |
+| 上游版本手动升级(改 ARG 后 --build) | 新增 `upstream-check.yml` 定时任务(每日 UTC 03:00 + workflow_dispatch)与 `scripts/`(check-upstream / should-upgrade / upgrade-dsh / smoke-test / open-issue / check-issue-gate / close-stale-issues):检测 `@deepseek-ai/dsh` dist-tags.latest 更新后自动提升 Dockerfile/compose/README 双语中的版本号,构建冒烟测试(镜像构建、dsh --version 校验、basic auth 401/200、双进程 RUNNING)通过则推送 master(触发 GHCR 自动构建),失败则创建 Issue(同版本去重);存在同版本未关闭失败 Issue 时定时任务跳过自动升级(npm 包版本不可变,重试必失败;仅 schedule 生效,手动触发绕过供人工重试环境性失败),升级成功后自动关闭过时失败 Issue | 需求:dsh 上游自动跟进;失败不推送、master 保持已验收状态;冒烟跳过 x-cmd 首启下载(预置假 x);DESIGN.md 历史内容不做自动替换 |
+

+ 115 - 0
Dockerfile

@@ -0,0 +1,115 @@
+# syntax=docker/dockerfile:1
+# DeepSeek Harness Web Docker 镜像
+#
+# DeepSeek Harness Web Docker image
+#
+# 单容器:dsh(127.0.0.1:3080) + Caddy basic auth(0.0.0.0:3081),supervisord 管理
+#
+# Single container: dsh (127.0.0.1:3080) + Caddy basic auth (0.0.0.0:3081), managed by supervisord
+#
+# 构建:docker build --build-arg DSH_VERSION=0.1.0-rc.6 -t dsh-web:latest .
+#
+# Build: docker build --build-arg DSH_VERSION=0.1.0-rc.6 -t dsh-web:latest .
+
+ARG DSH_VERSION=0.1.0-rc.6
+
+# Caddy 官方镜像
+# 静态二进制,与平台无关
+#
+# Caddy Official Image
+# Static binary, platform-independent
+FROM caddy:2-alpine AS caddy
+
+FROM node:22-slim
+
+ARG DSH_VERSION
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+# Caddy 静态二进制
+# 来自官方镜像,可在 glibc Debian 上直接运行
+#
+# Caddy Static Binary
+# From the official image, runs directly on glibc Debian
+COPY --from=caddy /usr/bin/caddy /usr/bin/caddy
+
+# 运行依赖与 agent 工具集
+# 全部可在白名单 bash 环境直接调用
+#
+# Runtime Dependencies and Agent Toolset
+# All directly callable in the whitelisted bash environment
+#
+# - supervisor(PID 1 进程管理,Python 包,python3 保留)
+# - git/openssh-client:git 工作流(GIT_PAGER=cat 表明 dsh 预期 git 存在)
+# - curl/wget:网络下载;jq:JSON;unzip/zip:解压/压缩;tar(coreutils)
+# - procps(ps/kill/pgrep):进程排查;ripgrep:代码搜索;rsync:同步
+# - yq:YAML 处理;file:类型识别;dnsutils(dig):DNS 排查;sqlite3:数据
+# - python3-pip:python 包管理(pip install --user);vim-tiny:vi 编辑器兜底
+# - build-essential/python3:npm 编译 native 依赖(node-pty 等),装完即清理
+#
+# - supervisor (PID 1 process management, Python package, python3 kept)
+# - git/openssh-client: git workflows (GIT_PAGER=cat shows dsh expects git)
+# - curl/wget: downloads; jq: JSON; unzip/zip: archive; tar (coreutils)
+# - procps (ps/kill/pgrep): process inspection; ripgrep: code search; rsync: sync
+# - yq: YAML; file: type detection; dnsutils (dig): DNS; sqlite3: data
+# - python3-pip: Python packages (pip install --user); vim-tiny: fallback vi editor
+# - build-essential/python3: compile native npm deps (node-pty etc.), purged after install
+#
+# 有意不 pin apt 版本:依赖 Debian 源自动更新;npm 版本已由 ARG DSH_VERSION pin
+#
+# Apt versions are deliberately unpinned: Debian sources auto-update; npm is pinned by ARG DSH_VERSION
+# hadolint ignore=DL3008
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends supervisor ca-certificates git openssh-client curl wget jq unzip zip procps ripgrep rsync yq file dnsutils sqlite3 python3-pip vim-tiny build-essential python3 \
+ && rm -rf /var/lib/apt/lists/*
+
+# pnpm
+# dsh plugin 命令在 profile 目录内转发给 pnpm(corepack 官方方式,pin 大版本)
+#
+# pnpm
+# dsh plugin commands forward to pnpm inside the profile dir (official corepack way, major version pinned)
+RUN corepack enable \
+ && corepack prepare pnpm@10 --activate
+
+# dsh 全局安装
+# 版本由 DSH_VERSION 构建参数固定
+# simp: 不硬编码 npm 镜像,用户可在构建时经 npm_config_registry 指定
+#
+# Global dsh Install
+# Version pinned by the DSH_VERSION build argument
+# simp: no hardcoded npm mirror; users can set npm_config_registry at build time
+RUN npm install -g @deepseek-ai/dsh@${DSH_VERSION} \
+ && npm cache clean --force \
+ && apt-get purge -y --auto-remove build-essential \
+ && rm -rf /var/lib/apt/lists/* /root/.npm
+
+# 运行用户与数据目录
+# 非 root 运行用户:复用官方镜像自带的 node 用户(uid 1000,home /home/node)
+# 数据目录 /home/node/.dsh 挂载卷;uid 1000 便于宿主机 bind mount 属主对齐
+#
+# Runtime User and Data Directory
+# Non-root runtime user: reuse the node user from the official image (uid 1000, home /home/node)
+# Data dir /home/node/.dsh is a mounted volume; uid 1000 aligns ownership for host bind mounts
+
+# 配置与入口
+#
+# Configuration and Entrypoint
+COPY defaults/ /opt/dsh/defaults/
+COPY Caddyfile /etc/caddy/Caddyfile
+COPY supervisord.conf /etc/supervisor/conf.d/dsh.conf
+COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+# 构建收尾说明
+# Caddyfile 需 node 用户可读(COPY 保留源 600 权限)
+# vim-tiny 默认不注册 vim 命令名,补 alternatives 注册(vi 已自动可用)
+#
+# Build Finalization Notes
+# Caddyfile must be readable by the node user (COPY keeps the source 600 permission)
+# vim-tiny does not register the vim command by default; alternatives registration added (vi already available)
+RUN chmod 644 /etc/caddy/Caddyfile \
+ && chmod +x /usr/local/bin/entrypoint.sh \
+ && update-alternatives --install /usr/bin/vim vim /usr/bin/vim.tiny 10
+
+ENV HOME=/home/node
+EXPOSE 3081
+
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Xidong-AI
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 112 - 0
README.md

@@ -0,0 +1,112 @@
+# DeepSeek Harness Web Docker
+
+> [English](README.md) | [中文](README.zh.md)
+
+Containerized deployment of the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh) web client: a single container bundles dsh + Caddy Basic Auth, with configuration and project/session data persisted, and CI automatically pushes GHCR images.
+
+## Features
+
+- Self-contained single container: dsh (loopback only, inside the container) + Caddy username/password Basic Auth
+- Configuration and project/session data persisted: bind mount `./data` → `/home/node/.dsh` (settings.yaml, API Key, profiles, sessions, storages)
+- Runs as non-root (uid 1000); dsh is not exposed directly
+- Pinnable image version: build argument `DSH_VERSION`
+- CI automatically builds and pushes `ghcr.io/xidong-ai/deepseek-harness-web-docker` (latest + date-time-hash tags)
+- A scheduled CI job checks the dsh upstream daily: on a new version it bumps `DSH_VERSION`, builds and smoke-tests the image, pushes to master on success, or opens an Issue on failure (a failed version is not retried automatically while its Issue is open; manual dispatch bypasses the gate)
+
+## Quick Start
+
+### Option 1: Use the GHCR image
+
+```bash
+git clone https://github.com/Xidong-AI/deepseek-harness-web-docker
+cd deepseek-harness-web-docker
+cp .env.example .env    # edit DSH_AUTH_USER / DSH_AUTH_PASSWORD / DEEPSEEK_API_KEY
+docker compose up -d    # pull the latest image and start
+```
+
+### Option 2: Build locally
+
+```bash
+docker compose up -d --build
+# or pin a dsh version:
+docker build --build-arg DSH_VERSION=0.1.0-rc.6 -t dsh-web:latest .
+```
+
+After startup, open `http://<host>:3080` in a browser (the port is controlled by `DSH_WEB_PORT` in `.env`) and enter the Basic Auth username and password.
+
+## Environment Variables (.env)
+
+| Variable | Required | Default | Description |
+| --- | --- | --- | --- |
+| `DSH_AUTH_USER` | Yes | `admin` | Basic Auth username |
+| `DSH_AUTH_PASSWORD` | Yes | None | Basic Auth plaintext password (bcrypt hash generated automatically at container startup) |
+| `DEEPSEEK_API_KEY` | Yes | None | DeepSeek API Key (referenced by the provider via apiKeyEnv) |
+| `DSH_WEB_PORT` | No | `3080` | Host port exposed to the outside (change it when it conflicts with an existing service) |
+| `DSH_TRUSTED_HOSTS` | No | Empty | Comma-separated extra trusted hosts, injected into the profile's `cordis.patch.yml`; by default Caddy rewrites Host/Origin to loopback, which covers normal access |
+| `DSH_VERSION` | No (build-time) | `0.1.0-rc.6` | dsh version; rebuild with `--build` after changing it |
+
+> `.env` contains passwords and the API Key — never commit it to the repository.
+
+## Data Persistence
+
+All configuration and data is stored in `./data/` under the project directory (git-ignored):
+
+- `settings.yaml`: dsh configuration (auto-generated from the default template on first startup)
+- `.credentials.yaml`: credentials (e.g. API Keys configured via the web UI)
+- `profiles/web/`: web profile (auto-initialized by dsh on first startup)
+- `sessions/`, `storages/`: session and project data
+
+Deleting the container does not affect the data; configuration is preserved after upgrades.
+
+## Upgrading
+
+```bash
+docker compose pull && docker compose up -d   # when using the GHCR image
+# or rebuild locally:
+docker compose build && docker compose up -d
+```
+
+## In-Container Tools & Environment
+
+dsh agents run commands inside the container through the bash tool; the available toolset = what's preinstalled in the image + **tools the agent installs itself (x-cmd)**.
+
+### Preinstalled in the image
+
+- Runtime: node 22, npm, pnpm (corepack, required by `dsh plugin`), python3, Caddy, dsh
+- Agent tools: git, openssh-client, curl/wget (network), jq/yq (JSON/YAML), ripgrep (search), rsync (sync), procps (processes), zip/unzip/tar, file, dig, sqlite3, python3-pip, vim-tiny, ca-certificates
+
+### Agent self-installation (x-cmd, no root required)
+
+The image ships [x-cmd](https://x-cmd.com) (auto-installed to the data volume on first startup; idempotent; Alibaba Cloud OSS source). Inside a dsh session you can run:
+
+```bash
+x env use git python jq       # install/enable tools (no root)
+x env ls                      # list enabled tools
+x env which jq                # show tool path
+x jq . data.json              # call with x prefix (always available)
+jq . data.json                # bare command: enabled packages are symlinked to /usr/local/bin, directly usable
+```
+
+- Install location: `~/.x-cmd.root` (inside the data volume `./data`), **preserved across container restart/rebuild**
+- The `x` command and enabled tools are automatically symlinked to `/usr/local/bin` (the agent's bash PATH is fixed; the symlink is the only entry point)
+- Newly installed tools are invoked with the `x <pkg>` prefix in the current session; bare commands become available after the container restarts
+- Tools come from the x-cmd package source (Alibaba Cloud OSS, reachable from mainland China) and support version management (`x env use node=v20`)
+
+For the in-container agent environment guide, see `AGENTS.md` in the data volume (auto-loaded by dsh sessions).
+
+
+System packages that require root (build toolchain like gcc/make, editors, etc.): modify the `apt-get install` line in the `Dockerfile` and rebuild, or add a layer on top of this image:
+
+```dockerfile
+FROM ghcr.io/xidong-ai/deepseek-harness-web-docker:latest
+RUN apt-get update && apt-get install -y --no-install-recommends build-essential \
+ && rm -rf /var/lib/apt/lists/*
+```
+
+## Changing the Password
+
+Edit `DSH_AUTH_PASSWORD` in `.env`, then run `docker compose up -d` (the entrypoint regenerates the hash automatically).
+
+## Acknowledgements
+
+Thanks to the [Linux.do](https://linux.do) community for support.

+ 112 - 0
README.zh.md

@@ -0,0 +1,112 @@
+# DeepSeek Harness Web Docker
+
+> [English](README.md) | [中文](README.zh.md)
+
+容器化部署 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(dsh)Web 客户端:单容器内含 dsh + Caddy basic auth,配置与项目/会话数据持久化,CI 自动推送 GHCR 镜像。
+
+## 特性
+
+- 单容器自包含:dsh(仅容器内 loopback)+ Caddy 基础用户名密码认证(basic auth)
+- 配置与项目/会话数据持久化:bind mount `./data` → `/home/node/.dsh`(settings.yaml、API Key、profiles、sessions、storages)
+- 非 root 运行(uid 1000),dsh 不直接对外暴露
+- 镜像版本可 pin:构建参数 `DSH_VERSION`
+- CI 自动构建并推送 `ghcr.io/xidong-ai/deepseek-harness-web-docker`(latest + 日期时间 - 哈希 tag)
+- 定时任务每日检查 dsh 上游:有新版本自动提升 `DSH_VERSION`、构建并冒烟测试,通过则推送 master,失败则创建 Issue(存在同版本未关闭 Issue 时不再自动重试,可手动触发强制重试)
+
+## 快速开始
+
+### 方式一:使用 GHCR 镜像
+
+```bash
+git clone https://github.com/Xidong-AI/deepseek-harness-web-docker
+cd deepseek-harness-web-docker
+cp .env.example .env    # 编辑 DSH_AUTH_USER / DSH_AUTH_PASSWORD / DEEPSEEK_API_KEY
+docker compose up -d    # 拉取 latest 镜像并启动
+```
+
+### 方式二:本地构建
+
+```bash
+docker compose up -d --build
+# 或指定 dsh 版本:
+docker build --build-arg DSH_VERSION=0.1.0-rc.6 -t dsh-web:latest .
+```
+
+启动后浏览器访问 `http://<主机>:3080`(端口由 `.env` 的 `DSH_WEB_PORT` 控制),输入 basic auth 用户名密码。
+
+## 环境变量(.env)
+
+| 变量 | 必填 | 默认 | 说明 |
+| --- | --- | --- | --- |
+| `DSH_AUTH_USER` | 是 | `admin` | basic auth 用户名 |
+| `DSH_AUTH_PASSWORD` | 是 | 无 | basic auth 明文密码(容器启动时自动生成 bcrypt 哈希) |
+| `DEEPSEEK_API_KEY` | 是 | 无 | DeepSeek API Key(provider 经 apiKeyEnv 引用) |
+| `DSH_WEB_PORT` | 否 | `3080` | 宿主机对外端口(与已有服务冲突时修改) |
+| `DSH_TRUSTED_HOSTS` | 否 | 空 | 逗号分隔的额外受信 Host,注入 profile 的 `cordis.patch.yml`;默认靠 Caddy 改写 Host/Origin 为 loopback 已覆盖常规访问 |
+| `DSH_VERSION` | 否(构建期) | `0.1.0-rc.6` | dsh 版本,修改后需 `--build` 重建 |
+
+> `.env` 含密码与 API Key,禁止提交入库。
+
+## 数据持久化
+
+所有配置与数据保存在项目目录 `./data/`(git 已忽略):
+
+- `settings.yaml`:dsh 配置(首启自动从默认模板生成)
+- `.credentials.yaml`:凭据(如经 Web UI 配置的 API Key)
+- `profiles/web/`:web profile(首启由 dsh 自动初始化)
+- `sessions/`、`storages/`:会话与项目数据
+
+删除容器不影响数据;升级后配置保留。
+
+## 升级
+
+```bash
+docker compose pull && docker compose up -d   # 使用 GHCR 镜像时
+# 或本地重建:
+docker compose build && docker compose up -d
+```
+
+## 容器内工具与环境
+
+dsh 的 agent 通过 bash 工具在容器内执行命令,可用工具集 = 镜像预装 + **agent 自行安装(x-cmd)**。
+
+### 镜像预装
+
+- 运行时:node 22、npm、pnpm(corepack,`dsh plugin` 依赖)、python3、Caddy、dsh
+- agent 工具:git、openssh-client、curl/wget(网络)、jq/yq(JSON/YAML)、ripgrep(搜索)、rsync(同步)、procps(进程)、zip/unzip/tar、file、dig、sqlite3、python3-pip、vim-tiny、ca-certificates
+
+### agent 自行安装(x-cmd,免 root)
+
+镜像内置 [x-cmd](https://x-cmd.com)(首启自动安装到数据卷,幂等;阿里云 OSS 源)。dsh 会话中可直接执行:
+
+```bash
+x env use git python jq       # 安装/启用工具(免 root)
+x env ls                      # 查看已启用工具
+x env which jq                # 查看工具路径
+x jq . data.json              # x 前缀调用(任何情况都可用)
+jq . data.json                # 裸命令:已启用包已软链至 /usr/local/bin,直接可用
+```
+
+- 安装位置:`~/.x-cmd.root`(数据卷 `./data` 内),**容器重启/重建后保留**
+- `x` 命令与已启用工具自动软链至 `/usr/local/bin`(agent 的 bash 环境 PATH 固定,软链是唯一接入点)
+- 新安装的工具本会话用 `x <pkg>` 前缀调用,容器重启后裸命令可用
+- 工具源为 x-cmd 包源(阿里云 OSS,国内可达),支持版本管理(`x env use node=v20`)
+
+容器内 agent 的环境指引见数据卷 `AGENTS.md`(dsh 会话自动加载)。
+
+
+编译工具链(gcc/make)、编辑器等需 root 的系统包,修改 `Dockerfile` 的 `apt-get install` 行重建,或基于本镜像追加一层:
+
+```dockerfile
+FROM ghcr.io/xidong-ai/deepseek-harness-web-docker:latest
+RUN apt-get update && apt-get install -y --no-install-recommends build-essential \
+ && rm -rf /var/lib/apt/lists/*
+```
+
+## 修改密码
+
+编辑 `.env` 的 `DSH_AUTH_PASSWORD`,然后 `docker compose up -d`(entrypoint 自动重新生成哈希)。
+
+## 鸣谢
+
+感谢 [Linux.do](https://linux.do) 社区的支持。

+ 32 - 0
defaults/AGENTS.md

@@ -0,0 +1,32 @@
+# 容器内运行环境说明(dsh agent 必读)
+
+本会话运行在 Docker 容器内(用户 node,uid 1000),以下规则适用于所有 bash 工具调用。
+
+## 预装工具
+
+- 运行时:node 22、npm、pnpm(corepack)、python3、Caddy
+- 常用工具:git、openssh-client、curl、wget、jq、yq、ripgrep、rsync、ps/pgrep、zip/unzip/tar、file、dig、sqlite3、pip、vim-tiny
+
+## 自行安装工具(x-cmd,免 root)
+
+镜像内置 x-cmd。安装并启用工具:
+
+```bash
+x env use jq python git   # 一次启用多个;可指定版本:x env use node=v20
+x env ls                  # 查看已启用
+x env which <pkg>         # 查看路径
+```
+
+调用已启用工具:
+
+- **优先 `x <pkg>` 前缀调用**(`x jq . file.json`)——任何情况下都可用;
+- 本次启动前已启用的包也已软链进 /usr/local/bin,**裸命令直接可用**(`jq . file.json`);
+- 刚安装的新包裸命令需容器重启后才进入 /usr/local/bin,当前会话请用 `x <pkg>` 前缀。
+
+工具安装持久化在数据卷(~/.x-cmd.root),容器重启/重建后保留。
+
+## 限制
+
+- 无 root/apt 权限,不能安装系统级包(gcc/make 等需自定义镜像,见项目 README);
+- 不读 shell rc 文件:每次 bash -c 为全新环境,PATH 固定(/usr/local/sbin:/usr/local/bin:/usr/bin);
+- 文件沙箱:工作区之外的文件操作可能被拒绝(见工具描述)。

+ 19 - 0
defaults/settings.yaml

@@ -0,0 +1,19 @@
+# dsh 默认配置模板
+# entrypoint 首启复制到数据卷,之后由用户持久化维护
+#
+# dsh default configuration template
+# Copied by entrypoint to the data volume on first run; maintained by the user afterwards
+#
+# 说明:
+# - deepseek-official provider 无需显式配置:默认 apiKeyEnv=DEEPSEEK_API_KEY
+#   (.env 注入)、默认 baseURL=https://api.deepseek.com
+# - 仅设置默认模型;更多模型/自定义 provider 请在数据卷 settings.yaml 追加
+#
+# Notes:
+# - The deepseek-official provider needs no explicit config: default apiKeyEnv=DEEPSEEK_API_KEY
+#   (injected via .env), default baseURL=https://api.deepseek.com
+# - Only the default model is set; add more models/custom providers to the data-volume settings.yaml
+agent-default-model:
+  provider: deepseek-official
+  model: deepseek-v4-pro
+  reasoningEffort: high

+ 25 - 0
docker-compose.yml

@@ -0,0 +1,25 @@
+# 编排配置
+# DeepSeek Harness Web Docker
+# 用法:cp .env.example .env(编辑 DSH_AUTH_USER/PASSWORD、DEEPSEEK_API_KEY)→ docker compose up -d --build
+# 配置、项目/会话数据与 agent 自装工具(x-cmd)持久化于 ./data(bind mount → /home/node 整个 HOME)
+#
+# Orchestration configuration
+# DeepSeek Harness Web Docker
+# Usage: cp .env.example .env (edit DSH_AUTH_USER/PASSWORD, DEEPSEEK_API_KEY) → docker compose up -d --build
+# Config, project/session data and agent-installed tools (x-cmd) persist in ./data (bind mount → the entire /home/node HOME)
+services:
+  dsh-web:
+    image: ghcr.io/xidong-ai/deepseek-harness-web-docker:latest
+    build:
+      context: .
+      args:
+        DSH_VERSION: ${DSH_VERSION:-0.1.0-rc.6}
+    container_name: dsh-web
+    restart: unless-stopped
+    ports:
+      - "${DSH_WEB_PORT:-3080}:3081"
+    volumes:
+      - ./data:/home/node
+    env_file: .env
+    environment:
+      - HOME=/home/node

+ 127 - 0
entrypoint.sh

@@ -0,0 +1,127 @@
+#!/usr/bin/env bash
+# 容器入口脚本
+# dsh-web 容器入口:校验必需变量 → 生成 bcrypt → 首启初始化数据卷 → 启动 supervisord
+#
+# Container Entrypoint Script
+# dsh-web container entrypoint: validate required env vars → generate bcrypt → initialize the data volume on first run → start supervisord
+set -euo pipefail
+
+log() { echo "[entrypoint] $*"; }
+
+# ---- 必需变量校验 ----
+#
+# ---- Required variable validation ----
+: "${DSH_AUTH_USER:?必须设置 DSH_AUTH_USER(.env)}"
+: "${DSH_AUTH_PASSWORD:?必须设置 DSH_AUTH_PASSWORD(.env)}"
+: "${DEEPSEEK_API_KEY:?必须设置 DEEPSEEK_API_KEY(.env)}"
+
+# ---- basic auth:明文密码 → bcrypt 哈希(注入 Caddyfile 环境变量)----
+#
+# ---- Basic auth: plaintext password → bcrypt hash (injected into Caddyfile env vars) ----
+DSH_AUTH_HASH="$(caddy hash-password --plaintext "$DSH_AUTH_PASSWORD" | tail -n 1)"
+export DSH_AUTH_HASH
+
+# ---- 数据卷首启初始化(/home/node/.dsh,node 用户为 uid 1000)----
+#
+# ---- Data volume first-run initialization (/home/node/.dsh, node user with uid 1000) ----
+DHS_HOME=/home/node/.dsh
+mkdir -p "$DHS_HOME"
+
+# 1. settings.yaml:不存在时复制默认模板(之后由用户持久化维护)
+#
+# 1. settings.yaml: copy the default template when absent (later maintained by the user)
+if [ ! -f "$DHS_HOME/settings.yaml" ]; then
+  cp /opt/dsh/defaults/settings.yaml "$DHS_HOME/settings.yaml"
+  log "已初始化默认 settings.yaml"
+fi
+
+# 1b. AGENTS.md:容器环境指引(dsh 会话自动加载,agent 必读)
+#
+# 1b. AGENTS.md: container environment guide (auto-loaded by dsh sessions, mandatory for agents)
+if [ ! -f "$DHS_HOME/AGENTS.md" ]; then
+  cp /opt/dsh/defaults/AGENTS.md "$DHS_HOME/AGENTS.md"
+  log "已初始化 AGENTS.md(容器环境指引)"
+fi
+
+# 2. trustedHosts 注入 cordis.patch.yml(仅当文件不存在;已存在则视为用户维护)
+#    profile 其余文件(package.json/pnpm-workspace.yaml)由 dsh 首启自动补全
+#
+# 2. Inject trustedHosts into cordis.patch.yml (only when absent; existing files are treated as user-maintained)
+#    The rest of the profile (package.json/pnpm-workspace.yaml) is auto-completed by dsh on first run
+if [ -n "${DSH_TRUSTED_HOSTS:-}" ]; then
+  PROFILE_DIR="$DHS_HOME/profiles/web"
+  PATCH="$PROFILE_DIR/cordis.patch.yml"
+  if [ ! -f "$PATCH" ]; then
+    mkdir -p "$PROFILE_DIR"
+    {
+      echo "- id: connection"
+      echo "  config:"
+      echo "    trustedHosts:"
+      # shellcheck disable=SC2086 # 有意按空白分词(逗号分隔列表)
+      for host in ${DSH_TRUSTED_HOSTS//,/ }; do
+        echo "      - $host"
+      done
+    } > "$PATCH"
+    log "已注入 trustedHosts: $DSH_TRUSTED_HOSTS"
+  else
+    log "cordis.patch.yml 已存在,跳过 trustedHosts 注入(用户维护)"
+  fi
+fi
+
+# 3. 修正数据卷属主(bind mount 挂整个 /home/node,首启属主可能是 root)
+#
+# 3. Fix data volume ownership (the whole /home/node is bind-mounted; owner may be root on first run)
+chown -R node:node /home/node
+# ---- x-cmd:agent 自行配置运行环境的工具(幂等安装 + 系统 PATH 接入)----
+# agent 的 bash 工具环境是白名单(PATH 固定为 /usr/local/sbin:/usr/local/bin:/usr/bin,无 HOME),
+# 因此:1) 生成 HOME 注入的 x wrapper;2) 把已 use 包的 shim 软链进 /usr/local/bin。
+# agent 用法见数据卷 AGENTS.md:`x env use <pkg>` 安装,`x <pkg>` 前缀调用(始终可用),
+# 裸命令对本次启动前已 use 的包可用(重启容器后对新装包生效)。
+#
+# ---- x-cmd: tools agents install to configure their runtime (idempotent install + system PATH integration) ----
+# The agent's bash tool environment is a whitelist (PATH fixed to /usr/local/sbin:/usr/local/bin:/usr/bin, no HOME),
+# hence: 1) generate an x wrapper that injects HOME; 2) symlink shims of already-used packages into /usr/local/bin.
+# Agent usage is documented in the data-volume AGENTS.md: install with `x env use <pkg>`, invoke with the `x <pkg>` prefix (always available),
+# Bare commands work for packages used before this startup (newly installed packages take effect after a container restart).
+XCMD_HOME=/home/node/.x-cmd.root
+if [ ! -x "$XCMD_HOME/bin/x" ]; then
+  log "首次启动:安装 x-cmd(agent 环境自举,约 80MB,写入数据卷;阿里云 OSS 源)"
+  if timeout 300 su -s /bin/bash node -c 'HOME=/home/node curl -fsSL https://get.x-cmd.com | sh' >/dev/null 2>&1; then
+    log "x-cmd 安装完成"
+  else
+    log "警告:x-cmd 安装失败(网络或 su 受限?),dsh 照常启动;"
+    log "       可稍后手动安装:docker exec -it dsh-web su -s /bin/bash node -c 'curl -fsSL https://get.x-cmd.com | sh'"
+  fi
+fi
+if [ -x "$XCMD_HOME/bin/x" ]; then
+  # 1) x wrapper:agent bash 无 HOME,x 需要 HOME 定位安装根
+  #
+  # 1) x wrapper: the agent bash has no HOME; x needs HOME to locate its install root
+  cat > /usr/local/bin/x <<EOF
+#!/bin/bash
+export HOME=/home/node
+exec /home/node/.x-cmd.root/bin/x "$@"
+EOF
+  chmod 755 /usr/local/bin/x
+  # 2) 已 use 包 shim 快照软链 → /usr/local/bin(裸命令直接可用)
+  #    exec/<pkg> 文件内容为 shim_bin 路径;shim_bin/<pkg> 是 `#! /bin/sh + exec 真实 bin` 包装
+  #
+  # 2) Symlink the shim snapshot of used packages → /usr/local/bin (bare commands become directly usable)
+  #    exec/<pkg> contains the shim_bin path; shim_bin/<pkg> is a `#! /bin/sh + exec real bin` wrapper
+  for shim in "$XCMD_HOME/local/data/pkg/exec"/*; do
+    [ -f "$shim" ] || continue
+    pkg="$(basename "$shim")"
+    target="$(head -n 1 "$shim" 2>/dev/null)" || continue
+    if [ -n "$target" ] && [ -e "$target" ]; then
+      ln -sf "$target" "/usr/local/bin/$pkg"
+    fi
+  done
+  pkg_list="$("$XCMD_HOME/bin/x" env ls 2>/dev/null | awk '{print $1}' | tr '\n' ' ')"
+  log "x-cmd 就绪(已启用包:$pkg_list)"
+fi
+
+# ---- 启动 supervisord(dsh + caddy)----
+#
+# ---- Start supervisord (dsh + caddy) ----
+log "启动 supervisord(DSH_AUTH_USER=$DSH_AUTH_USER,对外端口由 compose 映射)"
+exec supervisord -c /etc/supervisor/conf.d/dsh.conf

+ 26 - 0
scripts/check-issue-gate.sh

@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# 门闩检查:是否存在针对指定版本的未关闭「自动升级」失败 Issue
+# 输出:1(存在,应跳过自动升级)/ 0(无,可继续)
+#
+# Gate check: whether an open auto-upgrade failure Issue exists for the given version
+# Output: 1 (exists, skip the auto-upgrade) / 0 (none, proceed)
+# Usage: check-issue-gate.sh <version>
+#
+# 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
+#
+# Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
+set -euo pipefail
+
+VERSION="$1"
+GH_BIN="${GH:-gh}"
+
+# 列出未关闭的自动升级失败 Issue,标题含目标版本即命中
+# simp: gh 仅输出 JSON,匹配交给 jq(mock 易仿真);查询上限 50 条,按版本去重后远不会触及
+#
+# List open auto-upgrade failure Issues; a title containing the target version is a hit
+# simp: gh only outputs JSON, matching is delegated to jq (easy to mock); cap of 50 is far above the deduped per-version count
+JSON="$("$GH_BIN" issue list --state open --search 'in:title "[自动升级]"' --json title,number --limit 50 2>/dev/null || true)"
+[ -n "$JSON" ] || { echo 0; exit 0; }
+
+MATCH="$(jq -r '.[] | select(.title | contains("'"$VERSION"'")) | .number' <<<"$JSON" | head -n1)"
+[ -n "$MATCH" ] && echo 1 || echo 0

+ 27 - 0
scripts/check-upstream.sh

@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# 检查 dsh 上游版本,输出 current / latest / should_upgrade(GITHUB_OUTPUT 兼容格式)
+#
+# Check the dsh upstream version; outputs current / latest / should_upgrade (GITHUB_OUTPUT-compatible)
+# Usage: check-upstream.sh [repo-dir](默认当前目录)
+set -euo pipefail
+
+DIR="${1:-.}"
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+
+# 从 Dockerfile 提取当前版本(仅带值的 ARG 声明行)
+#
+# Extract the current version from the Dockerfile (only the ARG line with a value)
+CURRENT="$(grep -E '^ARG DSH_VERSION=' "$DIR/Dockerfile" | head -n1 | cut -d= -f2)"
+[ -n "$CURRENT" ] || { echo "错误:未能在 Dockerfile 找到 ARG DSH_VERSION" >&2; exit 1; }
+
+# npm view 返回 dist-tags.latest;registry 由 npm 配置决定(CI 默认 npmjs)
+#
+# npm view returns dist-tags.latest; the registry follows npm config (npmjs by default on CI)
+LATEST="$(npm view @deepseek-ai/dsh version)"
+[ -n "$LATEST" ] || { echo "错误:npm view 未返回版本" >&2; exit 1; }
+
+SHOULD="$("$SCRIPT_DIR/should-upgrade.sh" "$CURRENT" "$LATEST")"
+
+echo "current=$CURRENT"
+echo "latest=$LATEST"
+echo "should_upgrade=$SHOULD"

+ 25 - 0
scripts/close-stale-issues.sh

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+# 关闭过时的自动升级失败 Issue(升级成功后,旧版本的失败记录均已过时)
+#
+# Close stale auto-upgrade failure Issues (after a successful upgrade, older failure records are all stale)
+# Usage: close-stale-issues.sh
+#
+# 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
+#
+# Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
+set -euo pipefail
+
+GH_BIN="${GH:-gh}"
+
+JSON="$("$GH_BIN" issue list --state open --search 'in:title "[自动升级]"' --json title,number --limit 50 2>/dev/null || true)"
+[ -n "$JSON" ] || { echo "无过时的失败 Issue"; exit 0; }
+
+# 本次升级已成功:所有自动升级失败 Issue 均视为过时,全部关闭
+#
+# This upgrade succeeded: every auto-upgrade failure Issue is now stale; close them all
+STALE="$(jq -r '.[] | .number' <<<"$JSON")"
+for n in $STALE; do
+  echo "关闭过时 Issue #$n"
+  "$GH_BIN" issue close "$n"
+done
+[ -n "$STALE" ] || echo "无过时的失败 Issue"

+ 38 - 0
scripts/open-issue.sh

@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+# 创建自动升级失败 Issue(同版本去重:已存在相同标题的 open Issue 则跳过)
+#
+# Create an Issue for a failed auto-upgrade (dedup: skip when an open Issue with the same title exists)
+# Usage: open-issue.sh <latest> <current>
+#
+# 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
+#
+# Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
+set -euo pipefail
+
+LATEST="$1"
+CURRENT="$2"
+GH_BIN="${GH:-gh}"
+TITLE="[自动升级] dsh 上游 $LATEST 构建冒烟测试失败"
+
+EXISTING="$("$GH_BIN" issue list --state open --search "in:title \"$TITLE\"" --json number -q '.[0].number' 2>/dev/null || true)"
+if [ -n "$EXISTING" ]; then
+  echo "已存在同版本 Issue #$EXISTING,跳过创建"
+  exit 0
+fi
+
+"$GH_BIN" issue create --title "$TITLE" --body "$(cat <<EOF
+## 自动升级失败 | Auto-upgrade failed
+
+- 上游版本 (upstream): \`$LATEST\`
+- 仓库当前版本 (repo current): \`$CURRENT\`
+- 检测时间 (detected at): \`$(date -u +%FT%TZ)\`
+- 运行日志 (run log): ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
+
+升级脚本已将 \`DSH_VERSION\` 提升至 \`$LATEST\` 并执行构建与冒烟测试,但未通过,代码**未推送**至 master。
+The upgrade script bumped \`DSH_VERSION\` to \`$LATEST\` and ran build & smoke tests, but they failed; the change was **not** pushed to master.
+
+请人工排查:上游版本是否可安装、容器是否可正常启动,修复后手动升级或等待下次定时检查。
+Please investigate: whether the upstream version installs and the container starts; fix it, then upgrade manually or wait for the next scheduled check.
+EOF
+)"
+echo "已创建 Issue"

+ 21 - 0
scripts/should-upgrade.sh

@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+# 版本比较:判断 latest 是否严格高于 current(semver 语义)
+# 输出:1(应升级)/ 0(无需升级)
+#
+# Version comparison: whether latest is strictly newer than current (semver semantics)
+# Output: 1 (should upgrade) / 0 (no upgrade needed)
+# Usage: should-upgrade.sh <current> <latest>
+set -euo pipefail
+
+CURRENT="$1"
+LATEST="$2"
+
+[ "$CURRENT" = "$LATEST" ] && { echo 0; exit 0; }
+
+# npx semver:latest 满足 >current 时输出自身,否则输出空
+# simp: 借 npm 生态 semver 实现,避免自写版本比较(prerelease 如 0.1.0-rc.6 的排序规则易错)
+#
+# npx semver: echoes latest when it satisfies >current, otherwise empty
+# simp: reuse the npm semver CLI instead of hand-rolling comparison (prerelease ordering like 0.1.0-rc.6 is error-prone)
+UPDATED="$(npx --yes semver@7 -r ">$CURRENT" "$LATEST" 2>/dev/null || true)"
+[ -n "$UPDATED" ] && echo 1 || echo 0

+ 68 - 0
scripts/smoke-test.sh

@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# 冒烟测试:构建镜像 → 校验 dsh 版本 → 起容器 → basic auth 与进程检查
+#
+# Smoke test: build image → verify dsh version → run container → basic auth & process checks
+# Usage: smoke-test.sh <version>
+set -euo pipefail
+
+VERSION="$1"
+IMAGE="dsh-web:smoke"
+CID="dsh-smoke"
+
+cleanup() {
+  docker rm -f "$CID" >/dev/null 2>&1 || true
+  [ -n "${SMOKE_HOME:-}" ] && rm -rf "$SMOKE_HOME" || true
+}
+trap cleanup EXIT
+cleanup
+
+echo "==> 构建镜像(DSH_VERSION=$VERSION)"
+docker build --build-arg DSH_VERSION="$VERSION" -t "$IMAGE" .
+
+echo "==> 校验 dsh --version"
+OUT="$(docker run --rm --entrypoint dsh "$IMAGE" --version)"
+echo "    dsh --version => $OUT"
+grep -q "$VERSION" <<<"$OUT" || { echo "错误:版本不符(期望包含 $VERSION)" >&2; exit 1; }
+
+echo "==> 启动容器冒烟"
+# 预置假 x-cmd(x 可执行即跳过 entrypoint 首启 300s 下载)
+#
+# Pre-seed a fake x-cmd (an executable x skips the entrypoint's 300s first-run download)
+SMOKE_HOME="$(mktemp -d)"
+mkdir -p "$SMOKE_HOME/.x-cmd.root/bin"
+printf '#!/bin/sh\nexit 0\n' > "$SMOKE_HOME/.x-cmd.root/bin/x"
+docker run -d --name "$CID" \
+  -v "$SMOKE_HOME:/home/node" \
+  -e DSH_AUTH_USER=admin -e DSH_AUTH_PASSWORD=smoketest \
+  -e DEEPSEEK_API_KEY=sk-dummy \
+  -p 127.0.0.1::3081 "$IMAGE" >/dev/null
+PORT="$(docker port "$CID" 3081 | head -n1 | sed 's/.*://')"
+echo "    容器 $CID 已启动,映射端口 $PORT"
+
+echo "==> 等待服务就绪(最多 120s)"
+READY=0
+for _ in $(seq 1 60); do
+  CODE="$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/" || true)"
+  if [ "$CODE" != "000" ]; then READY=1; break; fi
+  sleep 2
+done
+if [ "$READY" != 1 ]; then
+  echo "错误:服务 120s 内未就绪" >&2
+  docker logs "$CID" 2>&1 | tail -30 >&2
+  exit 1
+fi
+
+echo "==> basic auth:无凭据应 401"
+CODE="$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/")"
+[ "$CODE" = "401" ] || { echo "错误:期望 401 实际 $CODE" >&2; exit 1; }
+
+echo "==> basic auth:带凭据应 200"
+CODE="$(curl -s -u admin:smoketest -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/")"
+[ "$CODE" = "200" ] || { echo "错误:期望 200 实际 $CODE" >&2; exit 1; }
+
+echo "==> 进程检查:dsh 与 caddy 均 RUNNING"
+STATUS="$(docker exec "$CID" supervisorctl status)"
+grep -qE '^dsh[[:space:]]+RUNNING' <<<"$STATUS" || { printf '错误:dsh 未运行\n%s\n' "$STATUS" >&2; exit 1; }
+grep -qE '^caddy[[:space:]]+RUNNING' <<<"$STATUS" || { printf '错误:caddy 未运行\n%s\n' "$STATUS" >&2; exit 1; }
+
+echo "==> 冒烟测试全部通过 ✓"

+ 38 - 0
scripts/upgrade-dsh.sh

@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+# 升级脚本:将仓库中 dsh 上游版本号提升到指定版本
+# 更新范围:Dockerfile(ARG + 注释示例)、docker-compose.yml(默认值)、README.md / README.zh.md(示例与变量表)
+# DESIGN.md 为历史设计稿,不在自动升级范围(差异由 §10 实现差异记录人工维护)
+#
+# Upgrade script: bump the dsh upstream version in the repo to the given version
+# Updated files: Dockerfile (ARG + comment example), docker-compose.yml (default), README.md / README.zh.md (examples and variable tables)
+# DESIGN.md is a historical design doc, out of scope for auto-upgrade (differences are maintained manually in §10)
+# Usage: upgrade-dsh.sh <new-version> [repo-dir](默认当前目录)
+set -euo pipefail
+
+NEW="$1"
+DIR="${2:-.}"
+
+# 从 Dockerfile 提取当前版本(仅带值的 ARG 声明行)
+#
+# Extract the current version from the Dockerfile (only the ARG line with a value)
+OLD="$(grep -E '^ARG DSH_VERSION=' "$DIR/Dockerfile" | head -n1 | cut -d= -f2)"
+[ -n "$OLD" ] || { echo "错误:未能在 Dockerfile 找到 ARG DSH_VERSION" >&2; exit 1; }
+[ "$NEW" != "$OLD" ] || { echo "新版本与当前版本相同($NEW),无需升级" >&2; exit 0; }
+
+FILES=(Dockerfile docker-compose.yml README.md README.zh.md)
+for f in "${FILES[@]}"; do
+  [ -f "$DIR/$f" ] || { echo "错误:缺少 $f" >&2; exit 1; }
+  # npm 版本号仅含 [0-9a-zA-Z.-],无 sed 特殊字符,可安全作替换串
+  #
+  # npm versions only contain [0-9a-zA-Z.-], no sed metacharacters, safe as a replacement string
+  sed -i "s/${OLD}/${NEW}/g" "$DIR/$f"
+done
+
+# 原子验证:旧版本号必须全部消失,新版本号已写入
+#
+# Atomic verification: the old version must be fully gone and the new version written
+LEFT="$(grep -l "$OLD" "$DIR"/Dockerfile "$DIR"/docker-compose.yml "$DIR"/README.md "$DIR"/README.zh.md 2>/dev/null || true)"
+[ -z "$LEFT" ] || { echo "错误:旧版本仍残留于 $LEFT" >&2; exit 1; }
+grep -q "$NEW" "$DIR/Dockerfile" || { echo "错误:新版本未写入" >&2; exit 1; }
+
+echo "已升级:$OLD → $NEW(Dockerfile / docker-compose.yml / README.md / README.zh.md)"

+ 57 - 0
supervisord.conf

@@ -0,0 +1,57 @@
+[supervisord]
+nodaemon=true
+logfile=/dev/null
+logfile_maxbytes=0
+pidfile=/tmp/supervisord.pid
+
+# socket 服务:固定 /var/run/supervisor.sock,与 Debian supervisorctl 默认路径一致
+# 修复:此前缺失该段,supervisord 实际 socket 与 supervisorctl 默认路径不符,docker exec supervisorctl status 报 no such file
+#
+# Socket server: fixed at /var/run/supervisor.sock, matching the Debian supervisorctl default
+# Fix: previously missing, the actual socket did not match supervisorctl's default, so docker exec supervisorctl status failed
+[unix_http_server]
+file=/var/run/supervisor.sock
+chmod=0700
+
+[supervisorctl]
+serverurl=unix:///var/run/supervisor.sock
+
+# dsh Web 客户端
+# 仅绑定容器内 loopback,不对外暴露
+# 注意:不传 --trusted-host(该 CLI 链路在 rc.6 不可靠),trustedHosts 走 cordis.patch.yml
+#
+# dsh Web client
+# Binds only to the in-container loopback, never exposed externally
+# Note: --trusted-host is not passed (unreliable in rc.6); trustedHosts goes through cordis.patch.yml
+[program:dsh]
+command=/usr/local/bin/dsh --profile web --port 3080
+# PATH 继承 entrypoint 注入(含 x-cmd 工具目录)
+#
+# PATH inherits the entrypoint injection (including the x-cmd tool directory)
+user=node
+environment=HOME="/home/node"
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+autorestart=true
+startsecs=3
+stopwaitsecs=30
+
+# Caddy basic auth 反代
+#
+# Caddy basic auth reverse proxy
+[program:caddy]
+command=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
+# PATH 继承 entrypoint 注入(含 x-cmd 工具目录)
+#
+# PATH inherits the entrypoint injection (including the x-cmd tool directory)
+user=node
+environment=HOME="/home/node",XDG_DATA_HOME="/home/node/.local/share"
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+autorestart=true
+startsecs=2
+stopwaitsecs=10

+ 140 - 0
tests/test-scripts.sh

@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+# 单测:should-upgrade.sh(版本比较)与 upgrade-dsh.sh(文件更新)
+#
+# Unit tests: should-upgrade.sh (version comparison) and upgrade-dsh.sh (file updates)
+# Usage: tests/test-scripts.sh
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+TMP="$(mktemp -d)"
+trap 'rm -rf "$TMP"' EXIT
+
+PASS=0
+FAIL=0
+
+# 断言辅助
+#
+# assertion helpers
+assert_eq() { # <desc> <expected> <actual>
+  if [ "$2" = "$3" ]; then PASS=$((PASS+1)); echo "  ✓ $1"; else
+    FAIL=$((FAIL+1)); echo "  ✗ $1:期望 [$2] 实际 [$3]"
+  fi
+}
+assert_grep() { # <desc> <pattern> <file>(期望存在匹配)
+  if grep -q "$2" "$3"; then PASS=$((PASS+1)); echo "  ✓ $1"; else
+    FAIL=$((FAIL+1)); echo "  ✗ $1:$3 未匹配 $2"
+  fi
+}
+assert_no_grep() { # <desc> <pattern> <file>(期望无匹配)
+  if grep -q "$2" "$3"; then FAIL=$((FAIL+1)); echo "  ✗ $1:$3 意外匹配 $2"; else
+    PASS=$((PASS+1)); echo "  ✓ $1"
+  fi
+}
+
+echo "== should-upgrade.sh(版本比较)=="
+SU="$ROOT/scripts/should-upgrade.sh"
+assert_eq "相等版本不升级"           0 "$("$SU" 0.1.0-rc.6 0.1.0-rc.6)"
+assert_eq "rc → 正式版应升级"         1 "$("$SU" 0.1.0-rc.6 0.1.0)"
+assert_eq "patch 升级应升级"          1 "$("$SU" 0.1.0 0.1.1)"
+assert_eq "minor 升级应升级"          1 "$("$SU" 0.1.0 0.2.0)"
+assert_eq "上游回退(降级)不升级"    0 "$("$SU" 0.1.0-rc.6 0.1.0-rc.5)"
+assert_eq "正式版后的 rc 不升级"      0 "$("$SU" 0.1.0 0.1.0-rc.9)"
+
+echo "== upgrade-dsh.sh(文件更新)=="
+# fixture:直接从仓库复制当前文件(模拟"升级前"状态)
+#
+# fixtures: copy the current repo files directly (simulating the "pre-upgrade" state)
+for f in Dockerfile docker-compose.yml README.md README.zh.md DESIGN.md; do
+  cp "$ROOT/$f" "$TMP/"
+done
+"$ROOT/scripts/upgrade-dsh.sh" 0.2.0 "$TMP" >/dev/null
+assert_no_grep "Dockerfile 旧版本已清除"      "0\.1\.0-rc\.6" "$TMP/Dockerfile"
+assert_grep     "Dockerfile 新版本已写入"      "0\.2\.0"       "$TMP/Dockerfile"
+assert_no_grep "docker-compose.yml 旧版本清除" "0\.1\.0-rc\.6" "$TMP/docker-compose.yml"
+assert_grep     "docker-compose.yml 新版本写入" "0\.2\.0"       "$TMP/docker-compose.yml"
+assert_no_grep "README.md 旧版本已清除"        "0\.1\.0-rc\.6" "$TMP/README.md"
+assert_no_grep "README.zh.md 旧版本已清除"     "0\.1\.0-rc\.6" "$TMP/README.zh.md"
+assert_grep     "DESIGN.md 不受影响"           "0\.1\.0-rc\.6" "$TMP/DESIGN.md"
+
+echo "== upgrade-dsh.sh(同版本幂等)=="
+TMP2="$TMP/idempotent"
+mkdir -p "$TMP2"
+for f in Dockerfile docker-compose.yml README.md README.zh.md; do
+  cp "$ROOT/$f" "$TMP2/"
+done
+"$ROOT/scripts/upgrade-dsh.sh" 0.1.0-rc.6 "$TMP2" > "$TMP2/idempotent.out" 2>&1 || true
+assert_eq "同版本返回提示且不报错" 0 "$?"
+assert_grep "同版本提示输出" "无需升级" "$TMP2/idempotent.out"
+
+echo "== open-issue.sh (mock gh)=="
+MOCK_GH="$TMP/mock-gh"
+cat > "$MOCK_GH" <<'MOCK'
+#!/usr/bin/env bash
+echo "$*" >> "${MOCK_LOG:?}"
+case "$1 $2" in
+  "issue list")
+    if [[ "$*" == *"-q"* ]]; then
+      # 仿真 gh 的 -q jq 查询:[] → 空输出;[{"number":7}] → 7
+      python3 -c "import json,sys; d=json.load(sys.stdin); print(d[0]['number'] if d else '')" <<< "${MOCK_LIST_OUT-}"
+    else
+      # 原始 JSON 输出(gate/close 脚本自行 jq 解析);未设置时输出空 = 仿真 gh 失败
+      echo "${MOCK_LIST_OUT-}"
+    fi
+    ;;
+  "issue create") echo "created" ;;
+  "issue close") echo "closed $3" ;;
+esac
+MOCK
+chmod +x "$MOCK_GH"
+OPEN_ISSUE="$ROOT/scripts/open-issue.sh"
+
+MOCK_LOG="$TMP/mock1.log" MOCK_LIST_OUT='[]' GH="$MOCK_GH" \
+  "$OPEN_ISSUE" 0.2.0 0.1.0-rc.6 > "$TMP/issue1.out" 2>&1
+assert_grep "无已有 Issue 时创建"            "已创建 Issue" "$TMP/issue1.out"
+assert_grep "create 调用含新版本标题"         "issue create --title \[自动升级\] dsh 上游 0.2.0" "$TMP/mock1.log"
+assert_grep "create 调用含上游版本正文"        "0.2.0" "$TMP/mock1.log"
+
+MOCK_LOG="$TMP/mock2.log" MOCK_LIST_OUT='[{"number":7}]' GH="$MOCK_GH" \
+  "$OPEN_ISSUE" 0.2.0 0.1.0-rc.6 > "$TMP/issue2.out" 2>&1
+assert_grep "已有同版本 Issue 时跳过"         "已存在同版本 Issue #7" "$TMP/issue2.out"
+assert_no_grep "去重时不调用 create"          "issue create" "$TMP/mock2.log"
+
+echo "== check-issue-gate.sh (mock gh)=="
+GATE="$ROOT/scripts/check-issue-gate.sh"
+GATE_LIST='[{"title":"[自动升级] dsh 上游 0.2.0 构建冒烟测试失败","number":5}]'
+
+MOCK_LOG="$TMP/mock3.log" MOCK_LIST_OUT="$GATE_LIST" GH="$MOCK_GH" \
+  "$GATE" 0.2.0 > "$TMP/gate1.out" 2>&1
+assert_eq "同版本失败 Issue 存在时拦截" 1 "$(cat "$TMP/gate1.out")"
+
+MOCK_LOG="$TMP/mock4.log" MOCK_LIST_OUT="$GATE_LIST" GH="$MOCK_GH" \
+  "$GATE" 0.2.1 > "$TMP/gate2.out" 2>&1
+assert_eq "不同版本失败 Issue 不拦截" 0 "$(cat "$TMP/gate2.out")"
+
+MOCK_LOG="$TMP/mock5.log" MOCK_LIST_OUT='[]' GH="$MOCK_GH" \
+  "$GATE" 0.2.0 > "$TMP/gate3.out" 2>&1
+assert_eq "无失败 Issue 不拦截" 0 "$(cat "$TMP/gate3.out")"
+
+MOCK_LOG="$TMP/mock6.log" MOCK_LIST_OUT='' GH="$MOCK_GH" \
+  "$GATE" 0.2.0 > "$TMP/gate4.out" 2>&1
+assert_eq "gh 查询失败(空输出)不拦截" 0 "$(cat "$TMP/gate4.out")"
+
+echo "== close-stale-issues.sh (mock gh)=="
+CLOSE="$ROOT/scripts/close-stale-issues.sh"
+CLOSE_LIST='[{"title":"[自动升级] dsh 上游 0.1.9 构建冒烟测试失败","number":9},{"title":"[自动升级] dsh 上游 0.2.0 构建冒烟测试失败","number":7}]'
+
+MOCK_LOG="$TMP/mock7.log" MOCK_LIST_OUT="$CLOSE_LIST" GH="$MOCK_GH" \
+  "$CLOSE" > "$TMP/close1.out" 2>&1
+assert_grep "关闭第一条过时 Issue" "关闭过时 Issue #9" "$TMP/close1.out"
+assert_grep "关闭第二条过时 Issue" "关闭过时 Issue #7" "$TMP/close1.out"
+assert_eq "close 调用两次" 2 "$(grep -c 'issue close' "$TMP/mock7.log")"
+assert_grep "close 参数为 Issue 编号" "issue close 9" "$TMP/mock7.log"
+
+MOCK_LOG="$TMP/mock8.log" MOCK_LIST_OUT='[]' GH="$MOCK_GH" \
+  "$CLOSE" > "$TMP/close2.out" 2>&1
+assert_grep "无 Issue 时提示" "无过时的失败 Issue" "$TMP/close2.out"
+assert_no_grep "无 Issue 时不调用 close" "issue close" "$TMP/mock8.log"
+
+echo
+echo "结果:$PASS 通过,$FAIL 失败"
+[ "$FAIL" -eq 0 ] || exit 1