dsh-quay-bot 0.7.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -28
- package/bin/doctor.mjs +148 -0
- package/botscreen/requirements-offline.txt +11 -0
- package/client.js +1 -2
- package/cordis.patch.yml +1 -1
- package/host/api.js +0 -4
- package/host/remote.js +2 -140
- package/host/screen.js +85 -21
- package/market/index.json +41 -0
- package/package.json +32 -13
- package/vendor/wheels/any/annotated_doc-0.0.7-py3-none-any.whl +0 -0
- package/vendor/wheels/any/annotated_types-0.8.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/anyio-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/certifi-2026.11.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/click-8.5.1-py3-none-any.whl +0 -0
- package/vendor/wheels/any/fastapi-0.165.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/h11-0.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpcore-1.0.9-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpx-0.29.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/idna-3.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/mss-10.2.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/opentelemetry_api-1.45.2-py3-none-any.whl +0 -0
- package/vendor/wheels/any/pydantic-2.14.4-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_multipart-0.0.34-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_xlib-0.33-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/six-1.17.0-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/starlette-1.10.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_extensions-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_inspection-0.4.5-py3-none-any.whl +0 -0
- package/vendor/wheels/any/uvicorn-0.54.0-py3-none-any.whl +0 -0
- package/vendor/wheels/linux-aarch64/pillow-12.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/websockets-17.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pillow-12.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/websockets-17.4-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl +0 -0
- package/botscreen/botscreen/__init__.py +0 -2
- package/botscreen/botscreen/__main__.py +0 -5
- package/botscreen/botscreen/artifacts.py +0 -388
- package/botscreen/botscreen/audit.py +0 -94
- package/botscreen/botscreen/cgroup.py +0 -293
- package/botscreen/botscreen/config.py +0 -320
- package/botscreen/botscreen/desktop/assets/chrome.png +0 -0
- package/botscreen/botscreen/desktop/assets/codex.png +0 -0
- package/botscreen/botscreen/desktop/assets/drive.png +0 -0
- package/botscreen/botscreen/desktop/assets/folder.png +0 -0
- package/botscreen/botscreen/desktop/assets/search.png +0 -0
- package/botscreen/botscreen/desktop/assets/terminal.png +0 -0
- package/botscreen/botscreen/desktop/assets/trash.png +0 -0
- package/botscreen/botscreen/desktop/assets/wallpaper.png +0 -0
- package/botscreen/botscreen/desktop.py +0 -244
- package/botscreen/botscreen/driver.py +0 -832
- package/botscreen/botscreen/gateway.py +0 -2089
- package/botscreen/botscreen/iconlayer.py +0 -841
- package/botscreen/botscreen/mcp_server.py +0 -435
- package/botscreen/botscreen/resources.py +0 -494
- package/botscreen/botscreen/screen.py +0 -1282
- package/botscreen/botscreen/session.py +0 -706
- package/botscreen/botscreen/state.py +0 -330
- package/botscreen/botscreen/streamer.py +0 -388
- package/remote/bin/dsh-remote.mjs +0 -418
- package/remote/package.json +0 -27
- package/remote/src/config.mjs +0 -183
- package/remote/src/crypto.mjs +0 -220
- package/remote/src/keys.mjs +0 -226
- package/remote/src/proxy.mjs +0 -1028
- package/remote/src/sessions.mjs +0 -163
- package/remote/src/shim.js +0 -838
- package/remote/src/supervisor.mjs +0 -207
- package/remote/src/tunnel.mjs +0 -489
- package/remote/src/upstream.mjs +0 -372
- package/remote/src/util.mjs +0 -139
- package/remote/src/ws.mjs +0 -313
- package/requirements.txt +0 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kdczyz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,37 +1,114 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
DeepSeek Harness 的 Bot
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
# dsh-quay-bot
|
|
2
|
+
|
|
3
|
+
DeepSeek Harness 的 **Bot 团队模式**插件(Host + Web Client 双半区),并内置一套自举的 **BotScreen 虚拟桌面**(X + 窗口管理器 + 把画面流进 Web UI)。装完即用:Python 依赖走包内 wheel,系统组件在首次启动时自动补装,不需要手工 `pip install` / `apt install`。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
dsh plugin install dsh-quay-bot # 在目标 profile 里
|
|
7
|
+
# 或在 DSH 桌面端 Plugin Manager → Install → 输入 dsh-quay-bot
|
|
8
|
+
# 或在 Discover 页把下面「Market index」里的 URL 加成索引源后直接搜索安装
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 1. 这个包做了什么
|
|
14
|
+
|
|
15
|
+
- 每个 Bot 独立目录、`SOUL.md` / `MEMORY.md`、永久私聊会话,以及**按房间隔离的隐藏 Group Session**(支持房间共享工程目录 `workDir`)
|
|
16
|
+
- 每个 Bot 可单独绑定模型:DSH 默认(空绑定,每轮重读)、provider/model、思考档位;模型目录标注是否支持图片输入
|
|
17
|
+
- Bot 聊天可发图片(PNG/JPEG/WebP/GIF,≤6 张 × 12 MB),纯文本模型在 Host 入队前拒绝
|
|
18
|
+
- `message_agent` 异步队友消息(会话级 FIFO、跳数护栏 `MAX_AGENT_HOPS=4`、同链去重、回信降级、>16k 落盘、群聊隐藏会话禁止)
|
|
19
|
+
- **Group Room(2–6 人)**:`auto`(并发协作 + `@` 接力)/ `everyone`(全员并发审阅)/ `lead`(Lead 派工与验收);全异步 `BotActor` 总线 + `snapshotSeq` 水位线防漏看;3 种显式终态(`completed` / `settled` / `waiting_user`);3 个病态探针(`idle_spin` / `paused_error` / `token_budget`);共享任务板 `claim_subtask(taskId, paths)` + 文件软锁;前端按 `botId` 分轨流式渲染;人类中途发言走 Soft Steer 软插话
|
|
20
|
+
- **Memory Hub**:`memory_tencentdb`(v3 HTTP Gateway `127.0.0.1:8420`,熔断后自动降级 Node 原生 SQLite FTS5)、`local_sqlite`、`builtin`,支持页面/命令一键下载安装第三方记忆库
|
|
21
|
+
- Host 持久 Routines(cron + 冷会话唤醒)、审批与提问桥(`approval/request`、`user-questions/request`)
|
|
22
|
+
- **BotScreen 屏幕工具**:`screen_screenshot` / `screen_click` / `screen_type` / `screen_key` / `screen_scroll` / `screen_drag` / `screen_open_app` / `screen_windows` / `screen_request_help`,网关 `127.0.0.1:6200`
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 2. 依赖:一个都不用手动装
|
|
27
|
+
|
|
28
|
+
| 层 | 内容 | 包内自带? |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| Node | ≥ 22.13(`node:sqlite` 需无 flag 版本);DSH 本体要求 ≥ 24.9 | DSH 侧负责 |
|
|
31
|
+
| DSH | `>= 0.2.2-rc.3`(写进 `engines.dsh`,不满足会被安装器拦下) | — |
|
|
32
|
+
| JS 依赖 | **零**(无 `dependencies`;只动态 `import` 可选的 `@deepseek-ai/dsh-mcp-client`,缺失自动降级) | ✅ |
|
|
33
|
+
| Web Client | `dsh-client-locale` / `ui-layout` / `ui-sidebar` / `ui-workspace` / `dsh-api-session-controller` | 由 DSH 提供 |
|
|
34
|
+
| Python | `fastapi uvicorn python-multipart Pillow python-xlib websockets httpx mss` | ✅ `vendor/wheels/` 离线 wheel(linux **x86_64 + aarch64**,CPython **3.12**) |
|
|
35
|
+
| pip 自身 | `vendor/pip/` 内置 `pip` + `setuptools` wheel(宿主机没有 ensurepip 也能建 venv) | ✅ |
|
|
36
|
+
| 系统组件 | `xvfb x11vnc websockify novnc xauth xfwm4 xfdesktop4 xfconf dbus-x11 tint2 picom pcmanfm xterm xdotool xclip glib-networking gvfs gvfs-daemons feh adwaita-icon-theme fonts-noto-color-emoji fonts-noto-cjk` | 首次启动自动 `apt-get install`(需 root 或无密码 sudo) |
|
|
37
|
+
| 运行时底座 | cgroup v2 unified(屏幕冻结)、`Xvfb`(或 KasmVNC 提供的 `Xvnc`) | 检测/自动装 Xvfb;KasmVNC 可选 |
|
|
38
|
+
|
|
39
|
+
首次启动的顺序(`host/screen.js` → `bootstrapVenv` / `ensureSystemDependencies`):
|
|
40
|
+
|
|
41
|
+
1. 探活 `127.0.0.1:6200/healthz`,已就绪直接复用;
|
|
42
|
+
2. 找 Python:`BOTSCREEN_PYTHON` → `$DSH_HOME/botmode/screen-venv` → 插件内 `.venv` → 仓库 `.venv` → `python3`(只要它的 import 探针通过就原地用);
|
|
43
|
+
3. 否则建 venv,用包内 pip wheel 播种,再 **离线** `pip install --no-index --find-links vendor/wheels/{any,linux-<arch>}`;wheel 不匹配解释器(如 3.10/3.11/3.13)时回退 PyPI,仍是全自动;
|
|
44
|
+
4. 逐项探测 14 个系统 bin,缺哪个就 `apt-get install` 全套一次(无 root/免密 sudo 时打印可复制的一行命令,不阻断其它功能);
|
|
45
|
+
5. 拉起 `python -m botscreen`,写日志 `$DSH_HOME/botmode/botscreen-gateway.log`。
|
|
46
|
+
|
|
47
|
+
关掉自动安装:`BOTSCREEN_AUTO_INSTALL_DEPS=0`。
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 3. 自检
|
|
24
52
|
|
|
25
53
|
```bash
|
|
26
|
-
dsh
|
|
54
|
+
npx dsh-quay-bot # 人类可读报告(node / python / 系统 bin / 内置 wheel / 网关)
|
|
55
|
+
npx dsh-quay-bot --json # 给脚本用
|
|
56
|
+
npx dsh-quay-bot --fix-hint # 只输出需要执行的命令
|
|
27
57
|
```
|
|
28
58
|
|
|
29
|
-
|
|
59
|
+
常见环境变量:`DSH_HOME`、`BOTSCREEN_DATA_ROOT`(默认 `/data/botscreen`)、`BOTSCREEN_PORT`(6200)、`BOTSCREEN_PYTHON`、`BOTSCREEN_X_BACKEND`(`xvfb`/`x11vnc`)、`BOTSCREEN_WM`(`openbox`/`xfwm4`)、`BOTSCREEN_WIDTH` / `BOTSCREEN_HEIGHT`、`BOTSCREEN_IDLE_MODE`。
|
|
30
60
|
|
|
31
|
-
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 4. Market index(Discover 页搜索)
|
|
64
|
+
|
|
65
|
+
包内提供一份符合 DSH plugin market format 1 的索引:`market/index.json`。把它放到任意 https 可访问地址(或本机 http),在 DSH 的 Discover / 插件市场设置里添加为索引源,即可在页面里搜到 `dsh-quay-bot` 并一键安装:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"format": 1,
|
|
70
|
+
"title": { "en": "Quay Bot", "zh": "Quay Bot 团队模式" },
|
|
71
|
+
"metadata": { "updated": 1764276000 },
|
|
72
|
+
"plugins": [
|
|
73
|
+
{
|
|
74
|
+
"name": "dsh-quay-bot",
|
|
75
|
+
"versions": [
|
|
76
|
+
{ "version": "1.0.0", "publishTimestamp": 1764276000, "source": { "type": "npm" }, "engines": { "dsh": ">=0.2.2-rc.3" } }
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
索引 URL 必须能被 DSH 以 `https:`(或同源的 http)读取;`source.type: "npm"` 会解析成 `dsh-quay-bot@1.0.0` 交给 profile 的包管理器。
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 5. 安装后去哪里找
|
|
88
|
+
|
|
89
|
+
- Host 行:`include:botmode`,模块 `dsh-quay-bot`
|
|
90
|
+
- Client 模块:`dsh-quay-bot/client`(侧边栏底部「Bot 模式」+ 机器人图标 → `main` 面板 `botmode`)
|
|
91
|
+
- 状态根:`$DSH_HOME/botmode`(`state.json` v4、`rooms/`、`bots/`、`memory-data/`、`memory-plugins/`、网关日志)
|
|
92
|
+
- HTTP:`/botmode/api/state`、`/models`、`/memory`、`/image`、`/command`、`/screen/*`、`/avatar/*`、`/artifacts/*`
|
|
93
|
+
|
|
94
|
+
改代码后:Plugin Manager 里关再开 `include:botmode` 重载 Host;Client 改动刷新页面即可(跑着 `pnpm run dev:web` 会热更新)。
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 6. 测试
|
|
32
99
|
|
|
33
100
|
```bash
|
|
34
|
-
node
|
|
101
|
+
node test/host.test.mjs && node test/screen.test.mjs && node test/avatar.test.mjs \
|
|
102
|
+
&& node test/artifacts.test.mjs && node test/routines.test.mjs && node test/qr.test.mjs \
|
|
103
|
+
&& node test/remote.test.mjs && node test/isolation.test.mjs && node test/governance-channels.test.mjs
|
|
35
104
|
```
|
|
36
105
|
|
|
37
|
-
|
|
106
|
+
覆盖 cron 解析、store/身份文件、会话隔离与 FIFO、模型与图片能力、Group Room 协议纯函数与多轮状态机、`message_agent` 护栏、Memory Hub(含降级路径)、审批策略、全部 HTTP 端点、venv 自举与系统依赖探测。
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 7. 与 `@local/dsh-botmode` 的关系
|
|
111
|
+
|
|
112
|
+
本包是同一套源码的**公开发布版**:包名、`dsh.bundle.patch` 的插件名、`client` 模块 id 改为 `dsh-quay-bot`;补上 `builtin-skills/**` 与 `vendor/wheels/**`;`bootstrapVenv` 改为离线优先;`ensureSystemDependencies` 从「5 个 bin」扩到「14 个 bin」。状态根、数据格式、`teamId=dsh-botmode` 保持不变,已有 Bot / 房间 / 记忆库可原样沿用。
|
|
113
|
+
|
|
114
|
+
同一 profile 里不要与 `@local/dsh-botmode` 同时启用(两者都插入 `include:botmode`)。
|
package/bin/doctor.mjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* dsh-quay-bot · doctor
|
|
4
|
+
*
|
|
5
|
+
* Zero-dependency preflight for the bundled BotScreen gateway. Everything this script
|
|
6
|
+
* checks is normally handled automatically the first time the plugin boots; run it when
|
|
7
|
+
* you want to know *why* the virtual desktop is not coming up.
|
|
8
|
+
*
|
|
9
|
+
* npx dsh-quay-bot # report
|
|
10
|
+
* npx dsh-quay-bot --json # machine-readable
|
|
11
|
+
* npx dsh-quay-bot --fix-hint # only print the exact copy-paste commands
|
|
12
|
+
*/
|
|
13
|
+
import { execFileSync } from 'node:child_process'
|
|
14
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
15
|
+
import { dirname, join, resolve } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const ROOT = resolve(HERE, '..')
|
|
20
|
+
const JSON_OUT = process.argv.includes('--json')
|
|
21
|
+
const HINT_ONLY = process.argv.includes('--fix-hint')
|
|
22
|
+
|
|
23
|
+
/** Keep in sync with `host/screen.js` → REQUIRED_BINS / AUTO_SYSTEM_PACKAGES. */
|
|
24
|
+
const REQUIRED_BINS = [
|
|
25
|
+
'Xvfb', 'xauth', 'xdotool', 'xclip', 'openbox',
|
|
26
|
+
'tint2', 'picom', 'pcmanfm', 'xterm', 'xfwm4', 'xfdesktop4',
|
|
27
|
+
'x11vnc', 'websockify', 'feh',
|
|
28
|
+
]
|
|
29
|
+
const APT_PACKAGES = [
|
|
30
|
+
'xvfb', 'x11vnc', 'websockify', 'novnc', 'xauth',
|
|
31
|
+
'xfwm4', 'xfdesktop4', 'xfconf', 'dbus-x11', 'tint2', 'picom', 'pcmanfm',
|
|
32
|
+
'xterm', 'xdotool', 'xclip',
|
|
33
|
+
'glib-networking', 'gvfs', 'gvfs-daemons', 'feh',
|
|
34
|
+
'adwaita-icon-theme', 'fonts-noto-color-emoji', 'fonts-noto-cjk',
|
|
35
|
+
]
|
|
36
|
+
const PY_IMPORTS = ['fastapi', 'uvicorn', 'multipart', 'PIL', 'Xlib', 'websockets', 'httpx', 'mss']
|
|
37
|
+
|
|
38
|
+
function which(bin) {
|
|
39
|
+
try {
|
|
40
|
+
return execFileSync('sh', ['-c', `command -v ${bin} 2>/dev/null`], { encoding: 'utf8', timeout: 8000 }).trim()
|
|
41
|
+
} catch {
|
|
42
|
+
return ''
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function pythonInfo() {
|
|
47
|
+
const candidates = [process.env.BOTSCREEN_PYTHON, join(process.env.HOME || '', '.dsh', 'botmode', 'screen-venv', 'bin', 'python'), 'python3'].filter(Boolean)
|
|
48
|
+
for (const py of candidates) {
|
|
49
|
+
if (py !== 'python3' && !existsSync(py)) continue
|
|
50
|
+
try {
|
|
51
|
+
const version = execFileSync(py, ['-V'], { encoding: 'utf8', timeout: 8000 }).trim()
|
|
52
|
+
let imports = 'missing'
|
|
53
|
+
try {
|
|
54
|
+
execFileSync(py, ['-c', `import ${PY_IMPORTS.join(', ')}`], { stdio: 'ignore', timeout: 15000 })
|
|
55
|
+
imports = 'ok'
|
|
56
|
+
} catch { /* keep missing */ }
|
|
57
|
+
return { python: py, version, imports }
|
|
58
|
+
} catch { /* next */ }
|
|
59
|
+
}
|
|
60
|
+
return { python: '', version: '', imports: 'no-python' }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function wheelSets() {
|
|
64
|
+
const base = join(ROOT, 'vendor', 'wheels')
|
|
65
|
+
const arch = process.arch === 'arm64' ? 'linux-aarch64' : process.arch === 'x64' ? 'linux-x86_64' : ''
|
|
66
|
+
return ['any', arch].filter(Boolean).map(dir => {
|
|
67
|
+
const path = join(base, dir)
|
|
68
|
+
const present = existsSync(path)
|
|
69
|
+
let wheels = 0
|
|
70
|
+
if (present) {
|
|
71
|
+
try {
|
|
72
|
+
wheels = readdirSync(path).filter(name => name.endsWith('.whl')).length
|
|
73
|
+
} catch { wheels = 0 }
|
|
74
|
+
}
|
|
75
|
+
return { dir, present, wheels }
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function gatewayHealth() {
|
|
80
|
+
const url = process.env.BOTSCREEN_GATEWAY || 'http://127.0.0.1:6200'
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch(`${url.replace(/\/$/, '')}/healthz`, { signal: AbortSignal.timeout(2500) })
|
|
83
|
+
if (!res.ok) return { url, ok: false, status: res.status }
|
|
84
|
+
const body = await res.json()
|
|
85
|
+
return { url, ok: true, apiVersion: body.api_version }
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return { url, ok: false, error: String(error?.message || error) }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const missingBins = REQUIRED_BINS.filter(bin => !which(bin))
|
|
92
|
+
const py = pythonInfo()
|
|
93
|
+
const health = await gatewayHealth()
|
|
94
|
+
const nodeMajor = Number(process.versions.node.split('.')[0])
|
|
95
|
+
const nodeOk = nodeMajor >= 22
|
|
96
|
+
const pythonOk = Boolean(py.python)
|
|
97
|
+
const depsOk = py.imports === 'ok'
|
|
98
|
+
const binsOk = missingBins.length === 0
|
|
99
|
+
const wheelsOk = wheelSets().every(set => set.present)
|
|
100
|
+
/* The gateway bootstraps Python deps from the bundle and installs the system packages
|
|
101
|
+
itself, so missing bins/deps are fixable on the next boot; only Node and Python block. */
|
|
102
|
+
const serviceable = nodeOk && pythonOk && (depsOk || wheelsOk)
|
|
103
|
+
const offlineCoversInterpreter = py.version.startsWith('Python 3.12')
|
|
104
|
+
|
|
105
|
+
const report = {
|
|
106
|
+
package: 'dsh-quay-bot',
|
|
107
|
+
root: ROOT,
|
|
108
|
+
node: { version: process.version, ok: nodeOk, need: '>=22.13' },
|
|
109
|
+
python: { ...py, ok: pythonOk, depsOk },
|
|
110
|
+
systemBins: { missing: missingBins, ok: binsOk },
|
|
111
|
+
bundledWheels: wheelSets(),
|
|
112
|
+
gateway: health,
|
|
113
|
+
offlineCoversInterpreter,
|
|
114
|
+
serviceable,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (JSON_OUT) {
|
|
118
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`)
|
|
119
|
+
process.exit(serviceable ? 0 : 1)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const mark = ok => (ok ? '✓' : '✗')
|
|
123
|
+
if (!HINT_ONLY) {
|
|
124
|
+
console.log('dsh-quay-bot doctor\n')
|
|
125
|
+
console.log(`${mark(nodeOk)} node ${process.version} (need >= 22.13)`)
|
|
126
|
+
console.log(`${mark(pythonOk)} python ${py.python || '(not found)'} ${py.version}`)
|
|
127
|
+
console.log(`${mark(depsOk)} python deps (fastapi uvicorn python-multipart pillow python-xlib websockets httpx mss)${depsOk ? '' : (wheelsOk ? ' · will install from bundled wheels' : ' · will install from PyPI')}`)
|
|
128
|
+
console.log(`${mark(binsOk)} system bins${missingBins.length ? ` · missing: ${missingBins.join(', ')} (auto-installed on boot)` : ''}`)
|
|
129
|
+
console.log(`${mark(health.ok)} gateway ${health.url}${health.ok ? ` · api v${health.apiVersion}` : ''}`)
|
|
130
|
+
for (const set of report.bundledWheels) console.log(`${mark(set.present)} bundled wheels vendor/wheels/${set.dir}`)
|
|
131
|
+
const note = offlineCoversInterpreter || depsOk ? '' : '\nnote: bundled wheels cover CPython 3.12 only; this interpreter gets its deps from PyPI on first boot.'
|
|
132
|
+
console.log(`${serviceable ? '\nready — the plugin installs and boots without further setup' : '\nnot ready — see the commands below'}${note}\n`)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const hints = []
|
|
136
|
+
if (!nodeOk) hints.push('# upgrade Node.js to >= 22.13 (DSH itself needs >= 24.9)')
|
|
137
|
+
if (!pythonOk) hints.push('sudo apt-get install -y python3 python3-venv')
|
|
138
|
+
if (missingBins.length) hints.push(`sudo apt-get install -y --no-install-recommends ${APT_PACKAGES.join(' ')}`)
|
|
139
|
+
if (pythonOk && !depsOk) {
|
|
140
|
+
hints.push(`# deps are installed automatically on first boot; to do it now:`)
|
|
141
|
+
hints.push(`python3 -m venv ~/.dsh/botmode/screen-venv && ~/.dsh/botmode/screen-venv/bin/pip install -r ${join(ROOT, 'botscreen', 'requirements.txt')}`)
|
|
142
|
+
}
|
|
143
|
+
if (hints.length) {
|
|
144
|
+
console.log('# suggested commands')
|
|
145
|
+
for (const line of hints) console.log(line)
|
|
146
|
+
}
|
|
147
|
+
process.exit(serviceable ? 0 : 1)
|
|
148
|
+
process.exit(ready ? 0 : 1)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Offline install set (no optional accelerators) — kept in sync with requirements.txt
|
|
2
|
+
# and vendored as wheels in vendor/wheels for linux x86_64 / aarch64, CPython 3.10–3.13.
|
|
3
|
+
# The gateway only needs these imports to boot: fastapi uvicorn multipart PIL Xlib websockets httpx mss
|
|
4
|
+
fastapi>=0.110
|
|
5
|
+
uvicorn>=0.27
|
|
6
|
+
python-multipart>=0.0.9
|
|
7
|
+
Pillow>=10.0
|
|
8
|
+
python-xlib>=0.33
|
|
9
|
+
websockets>=12.0
|
|
10
|
+
httpx>=0.27
|
|
11
|
+
mss>=9.0
|
package/client.js
CHANGED
|
@@ -8369,8 +8369,7 @@ window.__ModuleLoader__.load({
|
|
|
8369
8369
|
h('div', { className: 'bm-remote-hint' }, t('remote.appLabel')),
|
|
8370
8370
|
h('div', { className: 'bm-remote-link' }, data.appLink),
|
|
8371
8371
|
h('div', { className: 'bm-remote-hint' }, t('remote.appHint')))
|
|
8372
|
-
: h('div', { className: 'bm-remote-empty' },
|
|
8373
|
-
busy || (error ? t('remote.failed') : (data ? t('remote.appDisabled') : t('remote.starting'))))
|
|
8372
|
+
: h('div', { className: 'bm-remote-empty' }, busy || t('remote.appDisabled'))
|
|
8374
8373
|
|
|
8375
8374
|
const dialog = h('div', {
|
|
8376
8375
|
className: 'bm-modal-backdrop bm-remote-backdrop',
|
package/cordis.patch.yml
CHANGED
package/host/api.js
CHANGED
|
@@ -283,7 +283,6 @@ export class BotApi {
|
|
|
283
283
|
}
|
|
284
284
|
if (route === 'remote' && req.method === 'GET') {
|
|
285
285
|
try {
|
|
286
|
-
await this.remote?.recordUpstreamHintFromRequest?.(req)
|
|
287
286
|
sendJson(res, 200, await this.remote.status({ qr: url.searchParams.get('qr') !== '0' }))
|
|
288
287
|
} catch (error) {
|
|
289
288
|
sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) })
|
|
@@ -893,9 +892,6 @@ export class BotApi {
|
|
|
893
892
|
sendJson(res, 400, { ok: false, error: 'invalid JSON' })
|
|
894
893
|
return
|
|
895
894
|
}
|
|
896
|
-
if (String(payload?.type ?? '').startsWith('remote.')) {
|
|
897
|
-
await this.remote?.recordUpstreamHintFromRequest?.(req)
|
|
898
|
-
}
|
|
899
895
|
const result = await this.command(payload)
|
|
900
896
|
sendJson(res, 200, { ok: true, state: this.publicState(), result })
|
|
901
897
|
return
|
package/host/remote.js
CHANGED
|
@@ -11,48 +11,22 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { execFile } from 'node:child_process'
|
|
13
13
|
import { existsSync } from 'node:fs'
|
|
14
|
-
import {
|
|
14
|
+
import { readFile, stat } from 'node:fs/promises'
|
|
15
15
|
import { homedir } from 'node:os'
|
|
16
16
|
import { dirname, join } from 'node:path'
|
|
17
|
-
import { fileURLToPath } from 'node:url'
|
|
18
17
|
import { promisify } from 'node:util'
|
|
19
18
|
import { qrDataUrl, qrSvg } from './qr.js'
|
|
20
19
|
|
|
21
20
|
const execFileAsync = promisify(execFile)
|
|
22
|
-
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
23
|
-
const BUNDLED_BIN = join(HERE, '..', 'remote', 'bin', 'dsh-remote.mjs')
|
|
24
21
|
|
|
25
22
|
const DEFAULT_HOME = process.env.DSH_REMOTE_HOME || join(homedir(), '.dsh-remote')
|
|
26
23
|
const BIN_CANDIDATES = [
|
|
27
24
|
process.env.DSH_REMOTE_BIN,
|
|
28
|
-
BUNDLED_BIN,
|
|
29
25
|
join(process.cwd(), 'bin', 'dsh-remote.mjs'),
|
|
30
26
|
join(homedir(), 'Desktop', 'dsh-remote', 'bin', 'dsh-remote.mjs'),
|
|
31
27
|
join(homedir(), 'dsh-remote', 'bin', 'dsh-remote.mjs'),
|
|
32
28
|
].filter(Boolean)
|
|
33
29
|
|
|
34
|
-
function normalizeSocketHost(raw) {
|
|
35
|
-
const s = String(raw ?? '').trim().replace(/^::ffff:/i, '')
|
|
36
|
-
if (!s || s === '::' || s === '::1' || s === '0.0.0.0') return '127.0.0.1'
|
|
37
|
-
return s
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extractDshAuthCookie(cookieHeader) {
|
|
41
|
-
if (typeof cookieHeader !== 'string' || !cookieHeader.trim()) return ''
|
|
42
|
-
const parts = cookieHeader.split(';')
|
|
43
|
-
for (const part of parts) {
|
|
44
|
-
const trimmed = part.trim()
|
|
45
|
-
const eq = trimmed.indexOf('=')
|
|
46
|
-
if (eq <= 0) continue
|
|
47
|
-
const name = trimmed.slice(0, eq).trim()
|
|
48
|
-
// 跳过 dsh-remote 自身的 relay cookie,避免自循环;只取宿主机真实 dsh-auth-* cookie
|
|
49
|
-
if (name.startsWith('dsh-auth-') && name !== 'dsh-auth-relay') {
|
|
50
|
-
return trimmed
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return ''
|
|
54
|
-
}
|
|
55
|
-
|
|
56
30
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
57
31
|
|
|
58
32
|
async function readJson(path) {
|
|
@@ -144,72 +118,10 @@ export class RemoteGateway {
|
|
|
144
118
|
this.serviceName = serviceName
|
|
145
119
|
this.useSystemd = useSystemd ?? (home === DEFAULT_HOME && !bin && process.platform === 'linux')
|
|
146
120
|
this.runtimePath = join(home, 'state', 'runtime.json')
|
|
147
|
-
this.hintPath = join(home, 'state', 'upstream-hint.json')
|
|
148
|
-
this.configPath = join(home, 'config.json')
|
|
149
121
|
this.linkPath = join(home, 'link.txt')
|
|
150
122
|
this.lastAction = null
|
|
151
123
|
}
|
|
152
124
|
|
|
153
|
-
/**
|
|
154
|
-
* 记录当前活跃 `dsh web` 进程的真实监听地址与已鉴权 cookie 到 `state/upstream-hint.json`。
|
|
155
|
-
* 即使用户在新机器终端裸跑 `dsh web`(无日志文件),dsh-remote 也能零配置自动对接。
|
|
156
|
-
*/
|
|
157
|
-
async recordUpstreamHintFromRequest(req) {
|
|
158
|
-
try {
|
|
159
|
-
const port = Number(req?.socket?.localPort)
|
|
160
|
-
if (!Number.isInteger(port) || port <= 0) return false
|
|
161
|
-
const host = normalizeSocketHost(req?.socket?.localAddress)
|
|
162
|
-
const cookie = extractDshAuthCookie(req?.headers?.cookie)
|
|
163
|
-
if (!cookie) return false
|
|
164
|
-
await mkdir(dirname(this.hintPath), { recursive: true })
|
|
165
|
-
const tmp = `${this.hintPath}.${process.pid}.tmp`
|
|
166
|
-
const body = `${JSON.stringify({ host, port, cookie, pid: process.pid, updatedAt: Date.now() }, null, 2)}\n`
|
|
167
|
-
await writeFile(tmp, body, { encoding: 'utf8', mode: 0o600 })
|
|
168
|
-
await chmod(tmp, 0o600).catch(() => {})
|
|
169
|
-
await rename(tmp, this.hintPath)
|
|
170
|
-
return true
|
|
171
|
-
} catch {
|
|
172
|
-
return false
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async #ensureDefaultConfig() {
|
|
177
|
-
if (existsSync(this.configPath)) return this.configPath
|
|
178
|
-
await mkdir(this.home, { recursive: true })
|
|
179
|
-
const homeDir = homedir()
|
|
180
|
-
const defaults = {
|
|
181
|
-
version: 1,
|
|
182
|
-
listen: { host: '127.0.0.1', port: 44691 },
|
|
183
|
-
public: { mode: 'quick' },
|
|
184
|
-
upstream: {
|
|
185
|
-
mode: 'auto',
|
|
186
|
-
log: null,
|
|
187
|
-
logs: [
|
|
188
|
-
join(homeDir, 'logs', 'dsh-web.log'),
|
|
189
|
-
join(homeDir, '.dsh', 'logs', 'dsh-web.log'),
|
|
190
|
-
join(homeDir, '.dsh-app-remote', 'web.log'),
|
|
191
|
-
],
|
|
192
|
-
discoverIntervalMs: 3000,
|
|
193
|
-
},
|
|
194
|
-
proxy: { appBridge: true, hostRewrite: true },
|
|
195
|
-
tunnel: { persistAcrossRestart: true },
|
|
196
|
-
}
|
|
197
|
-
const tmp = `${this.configPath}.${process.pid}.tmp`
|
|
198
|
-
await writeFile(tmp, `${JSON.stringify(defaults, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 })
|
|
199
|
-
await rename(tmp, this.configPath)
|
|
200
|
-
return this.configPath
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async #hasSystemdUserBus() {
|
|
204
|
-
if (!this.useSystemd || !this.serviceName) return false
|
|
205
|
-
try {
|
|
206
|
-
await execFileAsync('systemctl', ['--user', 'show-environment'], { timeout: 3000 })
|
|
207
|
-
return true
|
|
208
|
-
} catch {
|
|
209
|
-
return false
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
125
|
async #hasSystemdService() {
|
|
214
126
|
if (!this.useSystemd || !this.serviceName) return false
|
|
215
127
|
try {
|
|
@@ -220,58 +132,8 @@ export class RemoteGateway {
|
|
|
220
132
|
}
|
|
221
133
|
}
|
|
222
134
|
|
|
223
|
-
/**
|
|
224
|
-
* Linux + systemd --user 环境下首次启动时自动安装独立的 `dsh-remote.service`,
|
|
225
|
-
* 让 dsh-remote / cloudflared 脱离 dsh-web.service 的 cgroup,避免 dsh 重启导致隧道断联。
|
|
226
|
-
*/
|
|
227
|
-
async #ensureSystemdService() {
|
|
228
|
-
if (await this.#hasSystemdService()) return true
|
|
229
|
-
if (!(await this.#hasSystemdUserBus())) return false
|
|
230
|
-
if (!this.bin || !existsSync(this.bin)) return false
|
|
231
|
-
try {
|
|
232
|
-
const unitDir = join(homedir(), '.config', 'systemd', 'user')
|
|
233
|
-
const unitPath = join(unitDir, this.serviceName)
|
|
234
|
-
const logDir = join(this.home, 'logs')
|
|
235
|
-
await mkdir(unitDir, { recursive: true })
|
|
236
|
-
await mkdir(logDir, { recursive: true })
|
|
237
|
-
const workDir = dirname(dirname(this.bin))
|
|
238
|
-
const unitBody = [
|
|
239
|
-
'[Unit]',
|
|
240
|
-
'Description=dsh-remote — DSH Gateway Remote Tunnel (auto-managed by dsh-botmode)',
|
|
241
|
-
'After=network-online.target',
|
|
242
|
-
'Wants=network-online.target',
|
|
243
|
-
'',
|
|
244
|
-
'[Service]',
|
|
245
|
-
'Type=simple',
|
|
246
|
-
`Environment=HOME=${homedir()}`,
|
|
247
|
-
'Environment=NODE_ENV=production',
|
|
248
|
-
`Environment=DSH_REMOTE_HOME=${this.home}`,
|
|
249
|
-
`WorkingDirectory=${workDir}`,
|
|
250
|
-
`ExecStart="${process.execPath}" "${this.bin}" up --foreground --config "${this.configPath}"`,
|
|
251
|
-
'Restart=always',
|
|
252
|
-
'RestartSec=3',
|
|
253
|
-
`StandardOutput=append:${join(logDir, 'relay.log')}`,
|
|
254
|
-
`StandardError=append:${join(logDir, 'relay.log')}`,
|
|
255
|
-
'',
|
|
256
|
-
'[Install]',
|
|
257
|
-
'WantedBy=default.target',
|
|
258
|
-
'',
|
|
259
|
-
].join('\n')
|
|
260
|
-
await writeFile(unitPath, unitBody, 'utf8')
|
|
261
|
-
await execFileAsync('systemctl', ['--user', 'daemon-reload'], { timeout: 10_000 })
|
|
262
|
-
await execFileAsync('systemctl', ['--user', 'enable', this.serviceName], { timeout: 10_000 }).catch(() => {})
|
|
263
|
-
return true
|
|
264
|
-
} catch (error) {
|
|
265
|
-
this.logger?.warn?.(`botmode: auto-install ${this.serviceName} failed, falling back: ${String(error?.message ?? error)}`)
|
|
266
|
-
return false
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
135
|
async #runDetachedUp({ timeoutMs = 120_000 } = {}) {
|
|
271
|
-
if (this
|
|
272
|
-
await this.#ensureDefaultConfig().catch(() => {})
|
|
273
|
-
}
|
|
274
|
-
if (await this.#ensureSystemdService()) {
|
|
136
|
+
if (await this.#hasSystemdService()) {
|
|
275
137
|
const startedAt = Date.now()
|
|
276
138
|
await execFileAsync('systemctl', ['--user', 'start', this.serviceName], { timeout: 30_000 })
|
|
277
139
|
this.lastAction = { args: ['systemctl', '--user', 'start', this.serviceName], ok: true, at: new Date().toISOString(), ms: Date.now() - startedAt }
|