dsh-quay-bot 1.0.2 → 1.0.6
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/README.md +28 -105
- package/botscreen/requirements.txt +1 -1
- package/client.js +123 -53
- package/cordis.patch.yml +1 -1
- package/host/api.js +4 -0
- package/host/remote.js +285 -8
- package/host/screen.js +22 -86
- package/package.json +34 -32
- package/remote/bin/dsh-remote.mjs +435 -0
- package/remote/package.json +27 -0
- package/remote/src/config.mjs +183 -0
- package/remote/src/crypto.mjs +220 -0
- package/remote/src/keys.mjs +226 -0
- package/remote/src/proxy.mjs +1028 -0
- package/remote/src/sessions.mjs +163 -0
- package/remote/src/shim.js +838 -0
- package/remote/src/supervisor.mjs +207 -0
- package/remote/src/tunnel.mjs +533 -0
- package/remote/src/upstream.mjs +403 -0
- package/remote/src/util.mjs +149 -0
- package/remote/src/ws.mjs +313 -0
- package/LICENSE +0 -21
- package/avatar/build.mjs +0 -81
- package/avatar/gallery/droid.json +0 -14
- package/avatar/gallery/ghost.json +0 -14
- package/avatar/gallery/grok-pod.json +0 -14
- package/avatar/gallery/guardian.json +0 -14
- package/avatar/gallery/mecha.json +0 -14
- package/avatar/gallery/mochi.json +0 -14
- package/avatar/gallery/neko.json +0 -14
- package/avatar/gallery/orbiter.json +0 -14
- package/avatar/gallery/relay.json +0 -14
- package/avatar/gallery/spark.json +0 -14
- package/avatar/src/bot/clay.ts +0 -135
- package/avatar/src/bot/effects.ts +0 -100
- package/avatar/src/bot/grok-bot.ts +0 -626
- package/avatar/src/bot/index.ts +0 -15
- package/avatar/src/bot/palettes.ts +0 -62
- package/avatar/src/bot/ring.ts +0 -219
- package/avatar/src/bot/scheduler.ts +0 -239
- package/avatar/src/bot/shapes.ts +0 -277
- package/avatar/src/bot/spring.ts +0 -196
- package/avatar/src/core/color.ts +0 -92
- package/avatar/src/core/eyes.ts +0 -297
- package/avatar/src/core/field.ts +0 -482
- package/avatar/src/core/frame.ts +0 -655
- package/avatar/src/core/fx.ts +0 -375
- package/avatar/src/core/index.ts +0 -49
- package/avatar/src/core/paint.ts +0 -331
- package/avatar/src/core/path.ts +0 -495
- package/avatar/src/core/pose.ts +0 -581
- package/avatar/src/core/svg.ts +0 -98
- package/avatar/src/core/types.ts +0 -153
- package/avatar/src/core/validate.ts +0 -296
- package/avatar/src/core/volume.ts +0 -681
- package/avatar/src/entry.ts +0 -260
- package/bin/doctor.mjs +0 -148
- package/botscreen/requirements-offline.txt +0 -11
- package/market/index.json +0 -41
- package/vendor/pip/pip-25.1.1-py3-none-any.whl +0 -0
- package/vendor/pip/setuptools-78.1.1-py3-none-any.whl +0 -0
package/host/remote.js
CHANGED
|
@@ -11,22 +11,157 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { execFile } from 'node:child_process'
|
|
13
13
|
import { existsSync } from 'node:fs'
|
|
14
|
-
import { readFile, stat } from 'node:fs/promises'
|
|
14
|
+
import { chmod, mkdir, readFile, rename, rm, stat, writeFile } 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'
|
|
17
18
|
import { promisify } from 'node:util'
|
|
18
19
|
import { qrDataUrl, qrSvg } from './qr.js'
|
|
19
20
|
|
|
20
21
|
const execFileAsync = promisify(execFile)
|
|
22
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
23
|
+
const BUNDLED_BIN = join(HERE, '..', 'remote', 'bin', 'dsh-remote.mjs')
|
|
21
24
|
|
|
22
25
|
const DEFAULT_HOME = process.env.DSH_REMOTE_HOME || join(homedir(), '.dsh-remote')
|
|
23
26
|
const BIN_CANDIDATES = [
|
|
24
27
|
process.env.DSH_REMOTE_BIN,
|
|
28
|
+
BUNDLED_BIN,
|
|
25
29
|
join(process.cwd(), 'bin', 'dsh-remote.mjs'),
|
|
26
30
|
join(homedir(), 'Desktop', 'dsh-remote', 'bin', 'dsh-remote.mjs'),
|
|
27
31
|
join(homedir(), 'dsh-remote', 'bin', 'dsh-remote.mjs'),
|
|
28
32
|
].filter(Boolean)
|
|
29
33
|
|
|
34
|
+
function systemNodeCandidates(platform = process.platform, env = process.env) {
|
|
35
|
+
const list = []
|
|
36
|
+
if (env.DSH_NODE_BIN) list.push(env.DSH_NODE_BIN)
|
|
37
|
+
if (platform === 'win32') {
|
|
38
|
+
list.push('node.exe', 'node')
|
|
39
|
+
const pf = env.ProgramFiles || 'C:\\Program Files'
|
|
40
|
+
const pf86 = env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)'
|
|
41
|
+
const localAppData = env.LOCALAPPDATA
|
|
42
|
+
list.push(join(pf, 'nodejs', 'node.exe'))
|
|
43
|
+
list.push(join(pf86, 'nodejs', 'node.exe'))
|
|
44
|
+
if (localAppData) list.push(join(localAppData, 'Programs', 'nodejs', 'node.exe'))
|
|
45
|
+
if (env.NVM_SYMLINK) list.push(join(env.NVM_SYMLINK, 'node.exe'))
|
|
46
|
+
if (env.VOLTA_HOME) list.push(join(env.VOLTA_HOME, 'bin', 'node.exe'))
|
|
47
|
+
} else if (platform === 'darwin') {
|
|
48
|
+
list.push(
|
|
49
|
+
'node',
|
|
50
|
+
'/opt/homebrew/bin/node',
|
|
51
|
+
'/usr/local/bin/node',
|
|
52
|
+
'/opt/local/bin/node',
|
|
53
|
+
join(homedir(), '.volta', 'bin', 'node'),
|
|
54
|
+
join(homedir(), '.asdf', 'shims', 'node'),
|
|
55
|
+
)
|
|
56
|
+
} else {
|
|
57
|
+
list.push(
|
|
58
|
+
'node',
|
|
59
|
+
'/usr/local/bin/node',
|
|
60
|
+
'/usr/bin/node',
|
|
61
|
+
join(homedir(), '.volta', 'bin', 'node'),
|
|
62
|
+
join(homedir(), '.asdf', 'shims', 'node'),
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
return [...new Set(list.filter(Boolean))]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function probeNodeMajor(command, extraEnv = {}) {
|
|
69
|
+
try {
|
|
70
|
+
const { stdout } = await execFileAsync(command, ['-p', 'process.versions.node'], {
|
|
71
|
+
timeout: 5_000,
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
env: { ...process.env, ...extraEnv },
|
|
74
|
+
})
|
|
75
|
+
const match = /^(\d+)\./.exec(String(stdout ?? '').trim())
|
|
76
|
+
return match ? Number(match[1]) : 0
|
|
77
|
+
} catch {
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let cachedNodeRuntime = null
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 解析可执行 dsh-remote.mjs 的 Node 运行时(兼容 Linux / macOS / Windows 及 Electron 桌面端):
|
|
86
|
+
* - 非 Electron 环境:直接使用当前 `process.execPath`;
|
|
87
|
+
* - Electron 环境(macOS `.app` / Windows `.exe` / Linux 桌面端):
|
|
88
|
+
* 1) 优先选用宿主机已安装的独立 `node` (>= 20),避免 Electron 关闭 `RunAsNode` fuse 或拉起新 GUI 窗口;
|
|
89
|
+
* 2) 宿主机未安装 `node` 时,回退到 `process.execPath` 并注入 `ELECTRON_RUN_AS_NODE=1`。
|
|
90
|
+
*/
|
|
91
|
+
export async function resolveNodeRuntime({
|
|
92
|
+
execPath = process.execPath,
|
|
93
|
+
isElectron = Boolean(process.versions?.electron),
|
|
94
|
+
platform = process.platform,
|
|
95
|
+
env = process.env,
|
|
96
|
+
probe = probeNodeMajor,
|
|
97
|
+
useCache = true,
|
|
98
|
+
} = {}) {
|
|
99
|
+
if (!isElectron) {
|
|
100
|
+
return { command: execPath, extraEnv: {} }
|
|
101
|
+
}
|
|
102
|
+
if (useCache && cachedNodeRuntime) return cachedNodeRuntime
|
|
103
|
+
for (const candidate of systemNodeCandidates(platform, env)) {
|
|
104
|
+
const major = await probe(candidate, {})
|
|
105
|
+
if (major >= 20) {
|
|
106
|
+
const resolved = { command: candidate, extraEnv: {} }
|
|
107
|
+
if (useCache) cachedNodeRuntime = resolved
|
|
108
|
+
return resolved
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const electronFallback = { command: execPath, extraEnv: { ELECTRON_RUN_AS_NODE: '1' } }
|
|
112
|
+
if (useCache) cachedNodeRuntime = electronFallback
|
|
113
|
+
return electronFallback
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function atomicWriteFile(filePath, content, { mode = 0o600 } = {}) {
|
|
117
|
+
await mkdir(dirname(filePath), { recursive: true })
|
|
118
|
+
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`
|
|
119
|
+
await writeFile(tmp, content, { encoding: 'utf8', mode })
|
|
120
|
+
if (process.platform !== 'win32') {
|
|
121
|
+
await chmod(tmp, mode).catch(() => {})
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
await rename(tmp, filePath)
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (process.platform === 'win32' && (error?.code === 'EPERM' || error?.code === 'EEXIST')) {
|
|
127
|
+
await rm(filePath, { force: true }).catch(() => {})
|
|
128
|
+
await rename(tmp, filePath)
|
|
129
|
+
} else {
|
|
130
|
+
await rm(tmp, { force: true }).catch(() => {})
|
|
131
|
+
throw error
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function hasRelayCookie(cookieHeader) {
|
|
137
|
+
if (typeof cookieHeader !== 'string' || !cookieHeader.trim()) return false
|
|
138
|
+
return cookieHeader
|
|
139
|
+
.split(';')
|
|
140
|
+
.some((part) => part.trim().startsWith('dsh-auth-relay='))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function normalizeSocketHost(raw) {
|
|
144
|
+
const s = String(raw ?? '').trim().replace(/^::ffff:/i, '')
|
|
145
|
+
if (!s || s === '::' || s === '::1' || s === '0.0.0.0') return '127.0.0.1'
|
|
146
|
+
return s
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function extractDshAuthCookie(cookieHeader) {
|
|
150
|
+
if (typeof cookieHeader !== 'string' || !cookieHeader.trim()) return ''
|
|
151
|
+
const parts = cookieHeader.split(';')
|
|
152
|
+
for (const part of parts) {
|
|
153
|
+
const trimmed = part.trim()
|
|
154
|
+
const eq = trimmed.indexOf('=')
|
|
155
|
+
if (eq <= 0) continue
|
|
156
|
+
const name = trimmed.slice(0, eq).trim()
|
|
157
|
+
// 跳过 dsh-remote 自身的 relay cookie,避免自循环;只取宿主机真实 dsh-auth-* cookie
|
|
158
|
+
if (name.startsWith('dsh-auth-') && name !== 'dsh-auth-relay') {
|
|
159
|
+
return trimmed
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return ''
|
|
163
|
+
}
|
|
164
|
+
|
|
30
165
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
31
166
|
|
|
32
167
|
async function readJson(path) {
|
|
@@ -118,10 +253,80 @@ export class RemoteGateway {
|
|
|
118
253
|
this.serviceName = serviceName
|
|
119
254
|
this.useSystemd = useSystemd ?? (home === DEFAULT_HOME && !bin && process.platform === 'linux')
|
|
120
255
|
this.runtimePath = join(home, 'state', 'runtime.json')
|
|
256
|
+
this.hintPath = join(home, 'state', 'upstream-hint.json')
|
|
257
|
+
this.configPath = join(home, 'config.json')
|
|
121
258
|
this.linkPath = join(home, 'link.txt')
|
|
122
259
|
this.lastAction = null
|
|
123
260
|
}
|
|
124
261
|
|
|
262
|
+
/**
|
|
263
|
+
* 记录当前活跃 `dsh web` / Electron 内嵌网关的真实监听地址与鉴权信息到 `state/upstream-hint.json`。
|
|
264
|
+
* 即使用户在 Linux / macOS / Windows 裸跑 `dsh web` 或桌面端(无日志文件),dsh-remote 也能零配置自动对接。
|
|
265
|
+
*/
|
|
266
|
+
async recordUpstreamHintFromRequest(req) {
|
|
267
|
+
try {
|
|
268
|
+
const port = Number(req?.socket?.localPort)
|
|
269
|
+
if (!Number.isInteger(port) || port <= 0) return false
|
|
270
|
+
const host = normalizeSocketHost(req?.socket?.localAddress)
|
|
271
|
+
const cookieHeader = req?.headers?.cookie
|
|
272
|
+
const cookie = extractDshAuthCookie(cookieHeader)
|
|
273
|
+
// 跳过仅来自 dsh-remote 自身的 relay 请求,避免自循环或覆盖真实 cookie
|
|
274
|
+
if (!cookie && hasRelayCookie(cookieHeader)) return false
|
|
275
|
+
if (!cookie) {
|
|
276
|
+
const existing = await readJson(this.hintPath)
|
|
277
|
+
if (existing && existing.port === port && existing.host === host && existing.cookie) {
|
|
278
|
+
return false
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const payload = {
|
|
282
|
+
host,
|
|
283
|
+
port,
|
|
284
|
+
cookie: cookie || null,
|
|
285
|
+
authMode: cookie ? 'cookie' : 'none',
|
|
286
|
+
pid: process.pid,
|
|
287
|
+
updatedAt: Date.now(),
|
|
288
|
+
}
|
|
289
|
+
await atomicWriteFile(this.hintPath, `${JSON.stringify(payload, null, 2)}\n`, { mode: 0o600 })
|
|
290
|
+
return true
|
|
291
|
+
} catch {
|
|
292
|
+
return false
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async #ensureDefaultConfig() {
|
|
297
|
+
if (existsSync(this.configPath)) return this.configPath
|
|
298
|
+
const homeDir = homedir()
|
|
299
|
+
const defaults = {
|
|
300
|
+
version: 1,
|
|
301
|
+
listen: { host: '127.0.0.1', port: 44691 },
|
|
302
|
+
public: { mode: 'quick' },
|
|
303
|
+
upstream: {
|
|
304
|
+
mode: 'auto',
|
|
305
|
+
log: null,
|
|
306
|
+
logs: [
|
|
307
|
+
join(homeDir, 'logs', 'dsh-web.log'),
|
|
308
|
+
join(homeDir, '.dsh', 'logs', 'dsh-web.log'),
|
|
309
|
+
join(homeDir, '.dsh-app-remote', 'web.log'),
|
|
310
|
+
],
|
|
311
|
+
discoverIntervalMs: 3000,
|
|
312
|
+
},
|
|
313
|
+
proxy: { appBridge: true, hostRewrite: true },
|
|
314
|
+
tunnel: { persistAcrossRestart: true },
|
|
315
|
+
}
|
|
316
|
+
await atomicWriteFile(this.configPath, `${JSON.stringify(defaults, null, 2)}\n`, { mode: 0o600 })
|
|
317
|
+
return this.configPath
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async #hasSystemdUserBus() {
|
|
321
|
+
if (!this.useSystemd || !this.serviceName) return false
|
|
322
|
+
try {
|
|
323
|
+
await execFileAsync('systemctl', ['--user', 'show-environment'], { timeout: 3000 })
|
|
324
|
+
return true
|
|
325
|
+
} catch {
|
|
326
|
+
return false
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
125
330
|
async #hasSystemdService() {
|
|
126
331
|
if (!this.useSystemd || !this.serviceName) return false
|
|
127
332
|
try {
|
|
@@ -132,8 +337,70 @@ export class RemoteGateway {
|
|
|
132
337
|
}
|
|
133
338
|
}
|
|
134
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Linux + systemd --user 环境下首次启动时自动安装独立的 `dsh-remote.service`,
|
|
342
|
+
* 让 dsh-remote / cloudflared 脱离 dsh-web.service 的 cgroup,避免 dsh 重启导致隧道断联。
|
|
343
|
+
*/
|
|
344
|
+
async #ensureSystemdService() {
|
|
345
|
+
if (await this.#hasSystemdService()) return true
|
|
346
|
+
if (!(await this.#hasSystemdUserBus())) return false
|
|
347
|
+
if (!this.bin || !existsSync(this.bin)) return false
|
|
348
|
+
try {
|
|
349
|
+
const runtime = await resolveNodeRuntime()
|
|
350
|
+
const unitDir = join(homedir(), '.config', 'systemd', 'user')
|
|
351
|
+
const unitPath = join(unitDir, this.serviceName)
|
|
352
|
+
const logDir = join(this.home, 'logs')
|
|
353
|
+
await mkdir(unitDir, { recursive: true })
|
|
354
|
+
await mkdir(logDir, { recursive: true })
|
|
355
|
+
const workDir = dirname(dirname(this.bin))
|
|
356
|
+
const envLines = [
|
|
357
|
+
`Environment=HOME=${homedir()}`,
|
|
358
|
+
'Environment=NODE_ENV=production',
|
|
359
|
+
`Environment=DSH_REMOTE_HOME=${this.home}`,
|
|
360
|
+
]
|
|
361
|
+
if (runtime.extraEnv.ELECTRON_RUN_AS_NODE) {
|
|
362
|
+
envLines.push(`Environment=ELECTRON_RUN_AS_NODE=${runtime.extraEnv.ELECTRON_RUN_AS_NODE}`)
|
|
363
|
+
}
|
|
364
|
+
const unitBody = [
|
|
365
|
+
'[Unit]',
|
|
366
|
+
'Description=dsh-remote — DSH Gateway Remote Tunnel (auto-managed by dsh-botmode)',
|
|
367
|
+
'After=network-online.target',
|
|
368
|
+
'Wants=network-online.target',
|
|
369
|
+
'',
|
|
370
|
+
'[Service]',
|
|
371
|
+
'Type=simple',
|
|
372
|
+
...envLines,
|
|
373
|
+
`WorkingDirectory=${workDir}`,
|
|
374
|
+
`ExecStart="${runtime.command}" "${this.bin}" up --foreground --config "${this.configPath}"`,
|
|
375
|
+
'Restart=always',
|
|
376
|
+
'RestartSec=3',
|
|
377
|
+
`StandardOutput=append:${join(logDir, 'relay.log')}`,
|
|
378
|
+
`StandardError=append:${join(logDir, 'relay.log')}`,
|
|
379
|
+
'',
|
|
380
|
+
'[Install]',
|
|
381
|
+
'WantedBy=default.target',
|
|
382
|
+
'',
|
|
383
|
+
].join('\n')
|
|
384
|
+
await writeFile(unitPath, unitBody, 'utf8')
|
|
385
|
+
await execFileAsync('systemctl', ['--user', 'daemon-reload'], { timeout: 10_000 })
|
|
386
|
+
await execFileAsync('systemctl', ['--user', 'enable', this.serviceName], { timeout: 10_000 }).catch(() => {})
|
|
387
|
+
return true
|
|
388
|
+
} catch (error) {
|
|
389
|
+
this.logger?.warn?.(`botmode: auto-install ${this.serviceName} failed, falling back: ${String(error?.message ?? error)}`)
|
|
390
|
+
return false
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async #resolveWorkDir() {
|
|
395
|
+
const candidate = this.bin ? dirname(dirname(this.bin)) : null
|
|
396
|
+
if (candidate && existsSync(candidate)) return candidate
|
|
397
|
+
await mkdir(this.home, { recursive: true }).catch(() => {})
|
|
398
|
+
return existsSync(this.home) ? this.home : homedir()
|
|
399
|
+
}
|
|
400
|
+
|
|
135
401
|
async #runDetachedUp({ timeoutMs = 120_000 } = {}) {
|
|
136
|
-
|
|
402
|
+
await this.#ensureDefaultConfig().catch(() => {})
|
|
403
|
+
if (await this.#ensureSystemdService()) {
|
|
137
404
|
const startedAt = Date.now()
|
|
138
405
|
await execFileAsync('systemctl', ['--user', 'start', this.serviceName], { timeout: 30_000 })
|
|
139
406
|
this.lastAction = { args: ['systemctl', '--user', 'start', this.serviceName], ok: true, at: new Date().toISOString(), ms: Date.now() - startedAt }
|
|
@@ -141,13 +408,15 @@ export class RemoteGateway {
|
|
|
141
408
|
}
|
|
142
409
|
if (this.useSystemd) {
|
|
143
410
|
try {
|
|
411
|
+
const runtime = await resolveNodeRuntime()
|
|
144
412
|
const unit = `dsh-remote-detached-${Date.now()}`
|
|
145
|
-
const env = { ...process.env, DSH_REMOTE_HOME: this.home }
|
|
413
|
+
const env = { ...process.env, ...runtime.extraEnv, DSH_REMOTE_HOME: this.home }
|
|
414
|
+
const cwd = await this.#resolveWorkDir()
|
|
146
415
|
const startedAt = Date.now()
|
|
147
416
|
await execFileAsync(
|
|
148
417
|
'systemd-run',
|
|
149
|
-
['--user', '--scope', `--unit=${unit}`, '--',
|
|
150
|
-
{ timeout: timeoutMs, env, cwd:
|
|
418
|
+
['--user', '--scope', `--unit=${unit}`, '--', runtime.command, this.bin, 'up'],
|
|
419
|
+
{ timeout: timeoutMs, env, cwd, windowsHide: true, maxBuffer: 4 * 1024 * 1024 },
|
|
151
420
|
)
|
|
152
421
|
this.lastAction = { args: ['systemd-run', 'up'], ok: true, at: new Date().toISOString(), ms: Date.now() - startedAt }
|
|
153
422
|
return
|
|
@@ -159,13 +428,21 @@ export class RemoteGateway {
|
|
|
159
428
|
}
|
|
160
429
|
|
|
161
430
|
async #run(args, { timeoutMs = 90_000 } = {}) {
|
|
162
|
-
const env = { ...process.env, DSH_REMOTE_HOME: this.home }
|
|
163
431
|
const startedAt = Date.now()
|
|
432
|
+
if (!this.bin || !existsSync(this.bin)) {
|
|
433
|
+
const message = `未找到内置 dsh-remote 脚本(${this.bin ?? '未配置'})`
|
|
434
|
+
this.lastAction = { args, ok: false, at: new Date().toISOString(), ms: 0, error: message }
|
|
435
|
+
throw new Error(`dsh-remote ${args.join(' ')} 失败:${message}`)
|
|
436
|
+
}
|
|
437
|
+
const runtime = await resolveNodeRuntime()
|
|
438
|
+
const env = { ...process.env, ...runtime.extraEnv, DSH_REMOTE_HOME: this.home }
|
|
439
|
+
const cwd = await this.#resolveWorkDir()
|
|
164
440
|
try {
|
|
165
|
-
const { stdout, stderr } = await execFileAsync(
|
|
441
|
+
const { stdout, stderr } = await execFileAsync(runtime.command, [this.bin, ...args], {
|
|
166
442
|
timeout: timeoutMs,
|
|
167
443
|
env,
|
|
168
|
-
cwd
|
|
444
|
+
cwd,
|
|
445
|
+
windowsHide: true,
|
|
169
446
|
maxBuffer: 4 * 1024 * 1024,
|
|
170
447
|
})
|
|
171
448
|
this.lastAction = { args, ok: true, at: new Date().toISOString(), ms: Date.now() - startedAt }
|
package/host/screen.js
CHANGED
|
@@ -26,7 +26,7 @@ const LOCAL_HOSTS = new Set(['127.0.0.1', 'localhost', '::1', '[::1]'])
|
|
|
26
26
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
27
27
|
// Keep in sync with botscreen/requirements.txt. Checking every runtime import avoids
|
|
28
28
|
// half-bootstrapped environments where the gateway process starts but immediately exits.
|
|
29
|
-
const PY_DEPS_CHECK = 'import fastapi, uvicorn, multipart, PIL, Xlib, websockets, httpx
|
|
29
|
+
const PY_DEPS_CHECK = 'import fastapi, uvicorn, multipart, pydantic, PIL, Xlib, websockets, httpx'
|
|
30
30
|
const _pyChecked = new Map()
|
|
31
31
|
|
|
32
32
|
let _lastLocalCpuSample = null
|
|
@@ -248,17 +248,6 @@ const AUTO_SYSTEM_PACKAGES = [
|
|
|
248
248
|
'adwaita-icon-theme', 'fonts-noto-color-emoji', 'fonts-noto-cjk',
|
|
249
249
|
]
|
|
250
250
|
|
|
251
|
-
/**
|
|
252
|
-
* Binaries the bundled desktop actually launches. Probing every one of them (not just
|
|
253
|
-
* the X core) is what makes `npm i` alone sufficient: a host that already had `Xvfb`
|
|
254
|
-
* but no `tint2`/`picom`/`pcmanfm` would otherwise be skipped and boot a crippled shell.
|
|
255
|
-
*/
|
|
256
|
-
const REQUIRED_BINS = [
|
|
257
|
-
'Xvfb', 'xauth', 'xdotool', 'xclip', 'openbox',
|
|
258
|
-
'tint2', 'picom', 'pcmanfm', 'xterm', 'xfwm4', 'xfdesktop4',
|
|
259
|
-
'x11vnc', 'websockify', 'feh',
|
|
260
|
-
]
|
|
261
|
-
|
|
262
251
|
function hasPythonDepsSync(py) {
|
|
263
252
|
if (_pyChecked.has(py)) return _pyChecked.get(py)
|
|
264
253
|
try {
|
|
@@ -333,7 +322,10 @@ function ensureSystemDependencies(logger) {
|
|
|
333
322
|
logger?.warn?.('botmode: system dependency auto-install disabled by BOTSCREEN_AUTO_INSTALL_DEPS=0')
|
|
334
323
|
return
|
|
335
324
|
}
|
|
336
|
-
const
|
|
325
|
+
const requiredBins = [
|
|
326
|
+
'Xvfb', 'xauth', 'xdotool', 'xclip', 'openbox',
|
|
327
|
+
]
|
|
328
|
+
const missingBins = requiredBins.filter(name =>
|
|
337
329
|
!runQuiet('sh', ['-c', `command -v ${name} >/dev/null 2>&1`], { timeout: 10_000 }),
|
|
338
330
|
)
|
|
339
331
|
if (!missingBins.length) return
|
|
@@ -341,38 +333,20 @@ function ensureSystemDependencies(logger) {
|
|
|
341
333
|
logger?.warn?.(`botmode: missing BotScreen system components (${missingBins.join(', ')}); install them manually`)
|
|
342
334
|
return
|
|
343
335
|
}
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
: (runQuiet('sh', ['-c', 'command -v sudo >/dev/null 2>&1 && sudo -n true'], { timeout: 10_000 }) ? ['sudo', '-n'] : null)
|
|
348
|
-
if (sudo === null) {
|
|
349
|
-
logger?.warn?.(
|
|
350
|
-
`botmode: missing BotScreen system components (${missingBins.join(', ')}); `
|
|
351
|
-
+ `no passwordless sudo. Run once: sudo apt-get install -y --no-install-recommends ${AUTO_SYSTEM_PACKAGES.join(' ')}`,
|
|
352
|
-
)
|
|
353
|
-
return
|
|
354
|
-
}
|
|
336
|
+
const sudo = runQuiet('sh', ['-c', 'command -v sudo >/dev/null 2>&1 && sudo -n true'], { timeout: 10_000 })
|
|
337
|
+
? ['sudo', '-n']
|
|
338
|
+
: []
|
|
355
339
|
logger?.info?.(`botmode: installing BotScreen system components: ${missingBins.join(', ')}`)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const apt = (args, timeout) => (sudo.length
|
|
359
|
-
? run([...sudo, 'apt-get', ...args], timeout)
|
|
360
|
-
: run(['apt-get', ...args], timeout))
|
|
361
|
-
if (!apt(['update', '-qq'], 300_000)) {
|
|
362
|
-
logger?.warn?.('botmode: apt-get update failed; BotScreen system components stay missing')
|
|
363
|
-
return
|
|
340
|
+
if (!runQuiet('apt-get', ['update', '-qq'], { timeout: 300_000 })) {
|
|
341
|
+
throw new Error('apt-get update 失败,无法自动安装 BotScreen 系统依赖')
|
|
364
342
|
}
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
+ `run: sudo apt-get install -y --no-install-recommends ${AUTO_SYSTEM_PACKAGES.join(' ')}`,
|
|
373
|
-
)
|
|
374
|
-
} else {
|
|
375
|
-
logger?.info?.('botmode: BotScreen system components installed')
|
|
343
|
+
const env = { ...process.env, DEBIAN_FRONTEND: 'noninteractive' }
|
|
344
|
+
const installCmd = sudo.length ? sudo[0] : 'apt-get'
|
|
345
|
+
const installArgs = sudo.length
|
|
346
|
+
? [...sudo.slice(1), 'apt-get', 'install', '-y', '--no-install-recommends', ...AUTO_SYSTEM_PACKAGES]
|
|
347
|
+
: ['install', '-y', '--no-install-recommends', ...AUTO_SYSTEM_PACKAGES]
|
|
348
|
+
if (!runQuiet(installCmd, installArgs, { env, timeout: 900_000 })) {
|
|
349
|
+
throw new Error('apt-get install 失败,无法自动安装 BotScreen 系统依赖')
|
|
376
350
|
}
|
|
377
351
|
}
|
|
378
352
|
|
|
@@ -382,7 +356,7 @@ function findBotscreenRuntime({ botscreenRoot, pythonBin, logDir } = {}) {
|
|
|
382
356
|
const candidates = [
|
|
383
357
|
botscreenRoot,
|
|
384
358
|
process.env.BOTSCREEN_ROOT,
|
|
385
|
-
pluginRoot, // bundled inside dsh-
|
|
359
|
+
pluginRoot, // bundled inside @local/dsh-botmode
|
|
386
360
|
repoRoot,
|
|
387
361
|
'/opt/botscreen',
|
|
388
362
|
join(homedir(), 'Desktop', 'dsh- bot'),
|
|
@@ -432,48 +406,10 @@ function findBotscreenRuntime({ botscreenRoot, pythonBin, logDir } = {}) {
|
|
|
432
406
|
return null
|
|
433
407
|
}
|
|
434
408
|
|
|
435
|
-
|
|
436
|
-
function offlineWheelDirs(pluginRoot) {
|
|
437
|
-
const base = join(pluginRoot, 'vendor', 'wheels')
|
|
438
|
-
const archDir = process.arch === 'arm64'
|
|
439
|
-
? 'linux-aarch64'
|
|
440
|
-
: (process.arch === 'x64' ? 'linux-x86_64' : '')
|
|
441
|
-
const dirs = [join(base, 'any'), archDir ? join(base, archDir) : ''].filter(d => d && existsSync(d))
|
|
442
|
-
return dirs
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Install the gateway's Python deps with zero user interaction:
|
|
447
|
-
* 1. offline from the bundle's vendored wheels (matches CPython 3.12 x86_64/arm64), else
|
|
448
|
-
* 2. online from PyPI as a fallback for other interpreters.
|
|
449
|
-
* The offline set omits optional accelerators (uvloop/httptools/watchfiles); uvicorn falls
|
|
450
|
-
* back to pure-Python h11 automatically, and the live `import` probe stays satisfied.
|
|
451
|
-
*/
|
|
452
|
-
async function installPythonDeps(python, root, pluginRoot, logger) {
|
|
453
|
-
const env = { ...process.env, PIP_DISABLE_PIP_VERSION_CHECK: '1' }
|
|
454
|
-
const offlineReq = join(root, 'botscreen', 'requirements-offline.txt')
|
|
455
|
-
const wheelDirs = offlineWheelDirs(pluginRoot)
|
|
456
|
-
if (wheelDirs.length && existsSync(offlineReq)) {
|
|
457
|
-
const args = ['-m', 'pip', 'install', '-q', '--no-index', '--disable-pip-version-check']
|
|
458
|
-
for (const dir of wheelDirs) args.push('--find-links', dir)
|
|
459
|
-
args.push('-r', offlineReq)
|
|
460
|
-
try {
|
|
461
|
-
await execFileAsync(python, args, { env, timeout: 600_000 })
|
|
462
|
-
logger?.info?.('botmode: BotScreen Python deps installed from bundled wheels (offline)')
|
|
463
|
-
return 'bundled'
|
|
464
|
-
} catch (error) {
|
|
465
|
-
logger?.warn?.(`botmode: bundled wheel set did not satisfy ${python} (${String(error?.message || error).slice(0, 200)}); falling back to PyPI`)
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const reqFile = join(root, 'botscreen', 'requirements.txt')
|
|
469
|
-
await execFileAsync(python, ['-m', 'pip', 'install', '-q', '--disable-pip-version-check', '-r', reqFile], { env, timeout: 600_000 })
|
|
470
|
-
logger?.info?.('botmode: BotScreen Python deps installed from PyPI')
|
|
471
|
-
return 'pypi'
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
async function bootstrapVenv(runtime, logDir, logPath, logger) {
|
|
409
|
+
async function bootstrapVenv(runtime, logDir, logPath) {
|
|
475
410
|
const venvDir = resolve(dirname(runtime.python), '..')
|
|
476
411
|
const pluginRoot = resolve(__dirname, '..')
|
|
412
|
+
const reqFile = join(runtime.root, 'botscreen', 'requirements.txt')
|
|
477
413
|
const invalidVenv = !isUsableVenv(runtime.python)
|
|
478
414
|
if (!invalidVenv) {
|
|
479
415
|
// Nothing to do: keep the existing interpreter and its pip as-is.
|
|
@@ -484,7 +420,7 @@ async function bootstrapVenv(runtime, logDir, logPath, logger) {
|
|
|
484
420
|
await execFileAsync('python3', ['-m', 'venv', '--without-pip', venvDir], { timeout: 60_000 })
|
|
485
421
|
}
|
|
486
422
|
await ensurePipInVenv(runtime.python, pluginRoot)
|
|
487
|
-
await
|
|
423
|
+
await execFileAsync(runtime.python, ['-m', 'pip', 'install', '-q', '-r', reqFile], { timeout: 300_000 })
|
|
488
424
|
_pyChecked.delete(runtime.python)
|
|
489
425
|
return runtime.python
|
|
490
426
|
}
|
|
@@ -764,7 +700,7 @@ export class ScreenBridge {
|
|
|
764
700
|
if (runtime.needsBootstrap) {
|
|
765
701
|
try {
|
|
766
702
|
this.logger?.info?.(`botmode: bootstrapping embedded BotScreen Python venv at ${logBase}`)
|
|
767
|
-
await bootstrapVenv(runtime, logBase, logPath
|
|
703
|
+
await bootstrapVenv(runtime, logBase, logPath)
|
|
768
704
|
} catch (err) {
|
|
769
705
|
if (logFd !== null) {
|
|
770
706
|
try { closeSync(logFd) } catch (_e) { /* ignore */ }
|
package/package.json
CHANGED
|
@@ -1,36 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-quay-bot",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Bot mode for DeepSeek Harness: isolated Bot personas, loop-guarded teammate messaging, Hermes-style Group Rooms, persistent Routines, a pluggable Team Memory Hub, and a bundled BotScreen virtual desktop — installs and runs with no separate dependency setup.",
|
|
5
|
-
"author": "kdczyz",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"dsh",
|
|
8
|
-
"dsh-plugin",
|
|
9
|
-
"dsh-bundle",
|
|
10
|
-
"deepseek-harness",
|
|
11
|
-
"dsh-botmode",
|
|
12
|
-
"botmode",
|
|
13
|
-
"botscreen",
|
|
14
|
-
"bot",
|
|
15
|
-
"multi-agent",
|
|
16
|
-
"group-room",
|
|
17
|
-
"agent-team",
|
|
18
|
-
"virtual-desktop",
|
|
19
|
-
"vnc"
|
|
20
|
-
],
|
|
3
|
+
"version": "1.0.6",
|
|
21
4
|
"type": "module",
|
|
22
|
-
"license": "MIT",
|
|
23
5
|
"engines": {
|
|
24
|
-
"node": ">=22.
|
|
25
|
-
"dsh": ">=0.2.2-rc.3"
|
|
6
|
+
"node": ">=22.5.0"
|
|
26
7
|
},
|
|
27
8
|
"scripts": {
|
|
28
|
-
"test": "node test/host.test.mjs && node test/screen.test.mjs && node test/avatar.test.mjs && node test/artifacts.test.mjs && node test/routines.test.mjs && node test/qr.test.mjs && node test/remote.test.mjs"
|
|
29
|
-
"doctor": "node bin/doctor.mjs"
|
|
30
|
-
},
|
|
31
|
-
"bin": {
|
|
32
|
-
"dsh-quay-bot": "bin/doctor.mjs"
|
|
9
|
+
"test": "node test/host.test.mjs && node test/screen.test.mjs && node test/avatar.test.mjs && node test/artifacts.test.mjs && node test/routines.test.mjs && node test/isolation.test.mjs && node test/governance-channels.test.mjs && node test/qr.test.mjs && node test/remote.test.mjs && node --test remote/test/*.test.mjs"
|
|
33
10
|
},
|
|
11
|
+
"description": "Bot mode for DeepSeek Harness: isolated Bot personas, loop-guarded teammate messaging, Hermes-style Group Rooms, persistent Routines and a pluggable Team Memory Hub (built-in memory_tencentdb).",
|
|
34
12
|
"exports": {
|
|
35
13
|
".": "./index.js",
|
|
36
14
|
"./client": "./client.js",
|
|
@@ -41,19 +19,24 @@
|
|
|
41
19
|
"files": [
|
|
42
20
|
"index.js",
|
|
43
21
|
"client.js",
|
|
44
|
-
"avatar
|
|
45
|
-
"
|
|
22
|
+
"avatar/catalog.json",
|
|
23
|
+
"avatar/dist/avatar-engine.js",
|
|
24
|
+
"avatar/LICENSE",
|
|
46
25
|
"botscreen/**/*",
|
|
26
|
+
"!botscreen/**/__pycache__/**",
|
|
27
|
+
"!botscreen/**/*.pyc",
|
|
47
28
|
"builtin-skills/**/*",
|
|
29
|
+
"remote/bin/**/*",
|
|
30
|
+
"remote/src/**/*",
|
|
31
|
+
"remote/package.json",
|
|
48
32
|
"host/**/*.js",
|
|
33
|
+
"host/**/*.mjs",
|
|
49
34
|
"host/**/*.json",
|
|
50
35
|
"cordis.patch.yml",
|
|
51
36
|
"locale/*.json",
|
|
52
|
-
"market/index.json",
|
|
53
37
|
"docs",
|
|
54
38
|
"icon.svg",
|
|
55
|
-
"README.md"
|
|
56
|
-
"vendor/pip/*.whl"
|
|
39
|
+
"README.md"
|
|
57
40
|
],
|
|
58
41
|
"dsh": {
|
|
59
42
|
"bundle": {
|
|
@@ -70,5 +53,24 @@
|
|
|
70
53
|
"@deepseek-ai/dsh-api-session-controller"
|
|
71
54
|
]
|
|
72
55
|
}
|
|
73
|
-
}
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"author": "kdczyz",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "git+https://github.com/kdczyz/dsh-bot.git",
|
|
62
|
+
"directory": "packages/dsh-botmode"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/kdczyz/dsh-bot#readme",
|
|
65
|
+
"keywords": [
|
|
66
|
+
"dsh",
|
|
67
|
+
"dsh-plugin",
|
|
68
|
+
"dsh-bundle",
|
|
69
|
+
"deepseek-harness",
|
|
70
|
+
"dsh-botmode",
|
|
71
|
+
"botmode",
|
|
72
|
+
"botscreen",
|
|
73
|
+
"dsh-remote",
|
|
74
|
+
"multi-agent"
|
|
75
|
+
]
|
|
74
76
|
}
|