Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,29 @@ jobs:
retention-days: 14

- name: Select the same installed Chrome for UI and worker
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
id: handoff_chrome
run: bash scripts/workbench/ci-select-chromium.sh

- name: Verify workbench UI controlling a second sandboxed browser
id: manual_handoff_ui
if: ${{ !cancelled() && steps.handoff_chrome.outcome == 'success' }}
timeout-minutes: 5
env:
DEVA_QA_HANDOFF_CAPTURE: '1'
run: node scripts/workbench/e2e-manual-browser.mjs

- name: Publish cropped evidence of the verified synthetic same-tab handoff
if: ${{ !cancelled() && steps.manual_handoff_ui.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: workbench-synthetic-browser-handoff
path: |
test-results/manual-browser/handoff-ready.png
test-results/manual-browser/handoff-returned.png
if-no-files-found: error
retention-days: 14

packaged-session-workspaces:
name: Packaged session workspace on native amd64 Docker
if: ${{ github.event_name == 'pull_request' && github.head_ref == 'feat/web-workbench-session-workspaces' }}
Expand Down Expand Up @@ -344,6 +361,32 @@ jobs:
timeout-minutes: 3
run: node scripts/workbench/container-skill-library.mjs

packaged-browser-handoff:
name: Human handoff with packaged Workbench, Chromium and broker
if: ${{ github.event_name == 'pull_request' && github.head_ref == 'feat/web-workbench-sandbox-handoff' }}
runs-on: ubuntu-latest
timeout-minutes: 22
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
package-manager-cache: false
- name: Build the actual non-root Linux amd64 images
timeout-minutes: 15
run: |
set -eu
test "$(uname -m)" = x86_64
docker build --platform linux/amd64 --target runtime -t deva-workbench:browser-verify .
docker build --platform linux/amd64 --file apps/browser-worker/Dockerfile --target broker -t deva-browser-broker:verify .
docker build --platform linux/amd64 --file apps/browser-worker/Dockerfile --target browser -t deva-browser-worker:verify .
for image in deva-workbench:browser-verify deva-browser-broker:verify deva-browser-worker:verify; do
docker image inspect -f '{{.Os}}/{{.Architecture}} {{.Id}} {{.Size}} bytes' "$image"
done
- name: Verify real Compose sandbox, approved form, owner controls and cleanup
timeout-minutes: 6
run: node scripts/workbench/container-browser-handoff.mjs

sandbox:
name: Private human browser worker
runs-on: ubuntu-latest
Expand All @@ -359,5 +402,7 @@ jobs:
run: node --test --test-concurrency=1 apps/browser-worker/test/*.test.mjs test/browser-handoff.test.mjs
- name: Select the installed browser for pipe-based verification
run: bash scripts/workbench/ci-select-chromium.sh
- name: Observe blank-only targets with and without default background apps
run: node apps/browser-worker/test-real/blank-targets.mjs --compare "$CHROMIUM_PATH"
- name: Exercise a real sandboxed worker, handoff and shutdown
run: node apps/browser-worker/test-real/engine-handoff.mjs
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ COPY --from=build /src/apps/headless/src ./apps/headless/src
COPY --from=build /src/apps/headless/dist ./apps/headless/dist
# Narrow Unix client only. Neither Chromium nor its egress broker runs in the workbench.
COPY apps/browser-worker/src/client.mjs apps/browser-worker/src/worker-control.mjs ./apps/browser-worker/src/
COPY apps/browser-worker/src/engine/policy.mjs ./apps/browser-worker/src/engine/
COPY apps/browser-worker/src/engine/policy.mjs apps/browser-worker/src/engine/entry-diagnostics.mjs ./apps/browser-worker/src/engine/
# Only the private Unix PTY client runs here; the native addon and fixed child program stay in the separate worker image.
COPY apps/terminal-worker/src/client.mjs apps/terminal-worker/src/protocol.mjs apps/terminal-worker/src/socket-path.mjs apps/terminal-worker/src/socket-channel.mjs ./apps/terminal-worker/src/
# ws has JS fallbacks for its optional native helpers; no desktop dependency tree is shipped.
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ The [amd64 Docker Compose workbench](apps/headless/README.md) runs independently
- **Attachments and deliveries:** explicitly send supported text, static images or PDFs on compatible adapters. Export confirmed replies or use the desktop delivery card to download and reveal an authorized project file.
- **Inspection:** view branches, first-parent history and staged or working-tree differences in separately approved repositories. Inspect recorded desktop tasks, preview a schedule in an explicit time zone, and pause an active record after confirmation. The server does not run a task scheduler.

The [optional server-side human-operated browser](apps/browser-worker/README.md) remains experimental: full handoff has not passed acceptance. The base workbench does not depend on it. See the [desktop parity inventory](docs/development/web-workbench/README.md) for pending work.
The [optional server-side human-operated browser](apps/browser-worker/README.md) passed same-tab handoff, return and reclaim with two actual browsers on a sandbox-capable Linux runner. The tested default Docker environment still denied kernel sandbox startup; the base workbench runs independently. See the [desktop parity inventory](docs/development/web-workbench/README.md) for pending work.

## Build from Source

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ IM 机器人支持 `/new [角色名]`、`/list`、`/stop`、`/status`、`/help`
- **附件与交付**:显式发送文本、静态图片或兼容协议的 PDF;导出已完成的回复,或在桌面同源交付卡下载、定位授权文件。
- **检查**:获准仓库可看分支、首父历史,以及暂存区和工作树的差异;任务页可查阅桌面记录、预览时区日程和确认暂停。它不会启动任务调度器。

[可选的服务器端人工浏览器](apps/browser-worker/README.md)仍属实验功能,完整接管与交还尚未通过。普通工作台不依赖它。逐项实现状态与回归门禁见[桌面对等清单](docs/development/web-workbench/README.md)。
[可选的服务器端人工浏览器](apps/browser-worker/README.md)已在支持沙箱的 Linux 上通过两个真实浏览器的同标签页接管、交还和重新接管验证。受测的默认 Docker 环境仍在内核沙箱初始化时受阻;普通工作台独立运行。逐项实现状态与回归门禁见[桌面对等清单](docs/development/web-workbench/README.md)。

## 从源码构建

Expand Down
28 changes: 28 additions & 0 deletions apps/browser-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

工作台网页本身可以在任何受支持的客户端浏览器中打开。这里的 Chromium 是**服务器里另一份浏览器**:所有者手动打开管理员登记的站点,通过工作台查看实时画面、点击、滚动、输入,完成或跳过后回到同一个页面。模型不能启动或操纵它,网页里的凭据、帧及输入不进入会话记录。这与 Electron 自动化和普通浏览器客户端是三件不同的事。

## 已验证到哪一步

| 环境 | 实际结果 |
|---|---|
| [原生 Linux 工作器](https://github.com/Facetomyself/deva/actions/runs/45866511888/job/140070596393) | 沙箱 Chromium 在真实表单中接收中文输入,提交后校验 PNG、同标签页会话状态、前进/后退和进程回收。 |
| [真实工作台页面控制第二个沙箱浏览器](https://github.com/Facetomyself/deva/actions/runs/45866511888/job/140070596078) | 所有者登录后选择已登记站点、接管、输入、确认、交还并重新接管。第二次接管验证的是第一次提交后的同一文档,而非重开的页面。60 秒租约到期、切换对话、退出登录和回收也已验证。 |
| [默认 Docker Compose 三组件](https://github.com/Facetomyself/deva/actions/runs/45866511888/job/140070596510) | 三份 linux/amd64 镜像均已构建,工作台和出口可用,但该运行机内的 Chromium 在握手前报告 `sandbox-denied`。已登录的打开操作返回 503,普通工作台就绪检查仍为 200;站点收到零次 GET/POST,所有本次测试资源正常清理。此环境尚未通过容器内接管验收。 |

以上回执对应提交 `40c6d20`。前两项证明人工工作流有效;镜像构建成功、宿主能运行 Chrome 或空白页探针通过,都不能代替当前容器的同页接管验证。

## 部署边界

- 默认 Compose 只有聊天工作台。可选配置另起两个普通用户进程:`browser-worker` 运行沙箱 Chromium,无网络接口(除其自身回环);`browser-egress` 有出站网络,只接收私有 Unix socket 上的请求,并匹配管理员登记的精确 origin。工作台只挂控制 socket,不挂工作器临时配置、数据或 Chromium profile;两个旁路容器都无工作台数据卷、模型密钥、宿主 Docker socket 和发布端口。
Expand All @@ -22,6 +32,16 @@

`ready` 指真实沙箱探针通过,`unconfigured`、`egress-unavailable`、`binary-missing`、`sandbox-startup-failure` 分别表示未配置、受限出口不可达、未找到浏览器、实际启动/沙箱验证失败。Compose 要支持相应目标架构、本地命名卷和 bind 配置;这个覆盖文件不把宿主浏览器、工作台 Cookie 或历史目录挂入工作器。部署前应确认操作系统、容器引擎和 seccomp 配置本来就能运行非特权 Chromium。若不具备,保留默认工作台,不改变宿主安全策略来冒充通过。

### 单独核对工作器容器里的 Chromium 沙箱

```sh
docker compose -f compose.yaml -f compose.browser.yaml exec -T browser-worker node /opt/browser-worker/src/cli.mjs diagnose-sandbox
```

这是本地运维命令,不是网页接口或后台健康检查。它只在新的私有 profile 中启动一次 Chromium,配置不可达的回环代理,渲染空白页并验证实际渲染器的内核沙箱,随后关闭进程。退出码 0 及 `BROWSER_BLANK_VERIFIED` 表示这条链成功;非零时,JSON 只显示固定的阶段和故障类别,不输出浏览器原始日志。它不连接已注册站点,因此不能代替表单提交、同标签页交还或工作台登录测试。

工作器保留禁用浏览器崩溃报告的常规设置,但不传 Chromium 的测试专用 Crashpad 开关:实测该开关会令部分版本的网络子进程在首次请求前反复重启,即便空白页的沙箱验证已经通过。Compose 仅为此工作器设置 core 文件软、硬上限为 0,继续使用只读根、独立临时文件系统、无出站网络和最小权限。

## 验证

```sh
Expand All @@ -30,3 +50,11 @@ CHROMIUM_PATH=/absolute/path/to/chromium node apps/browser-worker/test-real/engi
```

第二条是单独的真实浏览器门禁,必须有可工作的沙箱。从私有管道打开自建回环表单,核对像素、中文输入、同页会话状态与最终进程清理;失败退出是失败,协议夹具并不能替代它。不以能够对外发 HTTP 请求作为沙箱可用的证据。

本地还可用页面清单诊断,验证空白启动只有一个页面、零 worker:

```sh
node apps/browser-worker/test-real/blank-targets.mjs --compare /absolute/path/to/chromium
```

诊断使用新建的空白私有 profile 和固定的空代理,输出仅含目标类型、URL scheme 和计数。`--compare` 可省略;基线观察只用于对照。诊断与真实 Chromium 门禁及工作台所有者租约验证分开,后两项仍需各自通过。
65 changes: 65 additions & 0 deletions apps/browser-worker/src/blank-diagnostic.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { EngineError } from './engine/policy.mjs'

const success = 'BROWSER_BLANK_VERIFIED'
const generic = 'BROWSER_DIAGNOSTIC_FAILED'
const failures = new Set([
generic, 'BROWSER_ABORTED', 'BROWSER_CLEANUP_FAILED', 'BROWSER_CONFIGURATION_INVALID',
'BROWSER_EXECUTABLE_REQUIRED', 'BROWSER_FRAME_INVALID', 'BROWSER_NAVIGATION_BLOCKED',
'BROWSER_PROTOCOL_INVALID', 'BROWSER_PROTOCOL_LIMIT', 'BROWSER_PROXY_REQUIRED',
'BROWSER_SANDBOX_REQUIRED', 'BROWSER_START_FAILED', 'BROWSER_TARGET_LOST', 'BROWSER_TIMEOUT',
])
const stages = new Set([
'version', 'discover-bootstrap', 'watch-targets', 'download-guard', 'attach-bootstrap',
'page-controls', 'bootstrap-png', 'sandbox-attest',
])
const commands = new Set([
'Browser.getVersion', 'Browser.setDownloadBehavior', 'Browser.close', 'Target.getTargets',
'Target.setDiscoverTargets', 'Target.attachToTarget', 'Page.enable', 'Page.setLifecycleEventsEnabled',
'Page.setInterceptFileChooserDialog', 'Network.setCacheDisabled', 'Network.setBypassServiceWorker',
'Emulation.setDeviceMetricsOverride', 'Page.getFrameTree', 'Fetch.enable', 'Fetch.continueRequest',
'Fetch.failRequest', 'Fetch.continueWithAuth', 'Page.handleJavaScriptDialog', 'Page.captureScreenshot',
'SystemInfo.getProcessInfo',
])
const hints = new Set([
'silent', 'unclassified', 'missing-library', 'sandbox-denied', 'debug-pipe',
'profile-lock', 'snap-wrapper', 'startup-fatal',
])
const member = (values, value) => values.has(value) ? value : null

function report(available, code, details) {
return { available, code, stage: member(stages, details?.stage),
command: member(commands, details?.command), launchHint: member(hints, details?.launchHint) }
}

// A single local probe, independent of the worker, broker and their configured sites.
export async function runBlankDiagnostic(executablePath, { extraArgs = false, signals = process, probe } = {}) {
if (extraArgs) return report(false, 'BROWSER_CONFIGURATION_INVALID')
const controller = new AbortController()
const stop = () => controller.abort()
signals.on('SIGINT', stop); signals.on('SIGTERM', stop)
try {
probe ??= (await import('./engine/chromium.mjs')).probeChromium
const result = await probe({ executablePath, proxyUrl: 'http://127.0.0.1:9', signal: controller.signal })
if (controller.signal.aborted) return report(false, 'BROWSER_ABORTED')
// The native result only resolves after PNG capture, kernel attestation and cleanup.
return result?.available === true ? report(true, success) : report(false, generic)
} catch (error) {
if (error instanceof EngineError && failures.has(error.code) && error.code !== generic) {
return report(false, error.code, error.diagnostic)
}
return report(false, generic)
} finally {
signals.removeListener('SIGINT', stop); signals.removeListener('SIGTERM', stop)
}
}

// Hosted exec accepts exactly the CLI frame and correlated exit status, with no stderr.
export function parseBlankDiagnostic(stdout, stderr, exitCode) {
if (typeof stdout !== 'string' || stdout.length > 512 || stderr !== '' || (exitCode !== 0 && exitCode !== 1)) return null
try {
const value = JSON.parse(stdout)
if (value?.available !== (exitCode === 0) || (value.available ? value.code !== success : !failures.has(value.code))) return null
const safe = report(value.available, value.code, value.available || value.code === generic ? undefined : value)
return stdout === `${JSON.stringify(safe)}\n` ? safe : null
} catch { return null }
}
11 changes: 9 additions & 2 deletions apps/browser-worker/src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { pathToFileURL } from 'node:url'
import { parseSites, probeEgress, startEgress } from './egress/index.mjs'
import { openWorkerClient } from './client.mjs'
import { startWorker } from './worker.mjs'
import { runBlankDiagnostic } from './blank-diagnostic.mjs'

const chromiumPath = env => env.DEVA_CHROMIUM_PATH || '/usr/bin/chromium'

function absolute(value, label) {
if (typeof value !== 'string' || !isAbsolute(value) || value.includes('\0')) throw Error(label)
Expand All @@ -31,14 +34,18 @@ export async function launch(mode, env) {
if (!sites.length) throw Error('configuration')
if (mode === 'worker') {
return startWorker({ runDir: control, egressSocket: join(egress, 'egress.sock'), sites,
executablePath: absolute(env.DEVA_CHROMIUM_PATH || '/usr/bin/chromium', 'chromium') })
executablePath: absolute(chromiumPath(env), 'chromium') })
}
const privateOrigins = (env.DEVA_BROWSER_PRIVATE_ORIGINS ?? '').split(',').map(s => s.trim()).filter(Boolean)
return startEgress({ runDir: egress, sites, privateOrigins })
}

if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
if (process.argv.includes('--help')) console.log('Usage: node cli.mjs egress|worker|check-egress|check-worker')
if (process.argv[2] === 'diagnose-sandbox') {
const report = await runBlankDiagnostic(chromiumPath(process.env), { extraArgs: process.argv.length !== 3 })
console.log(JSON.stringify(report))
process.exitCode = report.available ? 0 : 1
} else if (process.argv.includes('--help')) console.log('Usage: node cli.mjs egress|worker|check-egress|check-worker|diagnose-sandbox')
else {
let resource, signalled = false, closing
function stop() {
Expand Down
Loading