Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Merge browser-task session model into takeover

Fei2411718f6f26a14c
diff --cc docs/plans/2026-10-21-browser-plugins.md
index 62910613,fc074459..d862920f
--- a/docs/plans/2026-10-21-browser-plugins.md
+++ b/docs/plans/2026-10-21-browser-plugins.md
@@@ -47,6 -47,5 +47,6 @@@ Bot 是长期身份。登录应该跟�
## 变更
- 2026-10-21:维护者定下全团队一个后端、每 Bot 一份 profile、cookie 不同步。三个插件和实测在同一分支,默认关闭。
- - 2026-10-22:实测模型是 OpenDesign 上的 `deepseek-v4.1-flash`(`https://amr-link.open-design.ai/v1`),密钥用 `OPENDESIGN_API_KEY`。
+ - 2026-10-22:`browser_task` 使用调用 Bot 在 DSH 中配置的模型;基准测试模型由 `BENCH_BASE_URL`、`BENCH_MODEL` 和 `BENCH_API_KEY` 配置。
- 2026-10-23:维护者定下权限规则:默认放行;发帖、上传、下载、删除按预授权或审批;删除强制多核对一轮;付款一律交给用户;预授权可设时限,在设置的浏览器页管理。
+- 2026-10-24:桌面应用中的 Bot 操作浏览器面板里的页面;用户可接管、停止 Bot 或交还控制权。Bot 交接可由 Bot 恢复;用户接管只能由用户交还。
diff --cc ds-bot/src/host/browser-plugins.js
index 0bc84e05,2927504d..5cda4663
--- a/ds-bot/src/host/browser-plugins.js
+++ b/ds-bot/src/host/browser-plugins.js
@@@ -1,10 -1,9 +1,10 @@@
// The whole team uses one browser plugin. Each Bot still gets its own profile
// directory, including the group Sessions where that Bot speaks.
-import { join } from 'node:path'
+import { isAbsolute, join } from 'node:path'
+import { randomUUID } from 'node:crypto'
import { defineTool } from '@deepseek-ai/dsh-tools'
- import { completeDeepseek } from './browser/deepseek.js'
import { mountBrowserPlugin } from './browser/mount.js'
+ import { sessionComplete } from './browser/session-model.js'
import * as refs from './browser/refs.js'
import * as script from './browser/script.js'
import * as task from './browser/task.js'
@@@ -110,15 -92,8 +114,15 @@@ export function install(rt)
const executablePath = optionalString(rt.config, 'browserExecutablePath')
const headless = typeof rt.config.browserHeadless === 'boolean'
? rt.config.browserHeadless
- : !process.env.DISPLAY
+ : defaultBrowserHeadless(process.platform)
const downloadRoot = join(rt.home, 'browser-downloads')
+ async function downloadRoots(botId) {
+ await rt.load()
+ const team = rt.teamFolder()
+ const requested = rt.workDirOf({ botId })
+ const working = requested !== undefined && await rt.isFolder(requested) ? requested : team
+ return [...new Set([working, team].filter(root => typeof root === 'string' && isAbsolute(root)))]
+ }
mountBrowserPlugin(rt.ctx, {
toolDefs: plugin.tools ?? plugin.toolDefs,
defineTool,
@@@ -132,12 -108,10 +136,14 @@@
headless,
playwrightUrl,
executablePath,
+ connect: process.env.DS_BOT_APP === '1' && typeof process.send === 'function' ? appBrowserEndpoint : undefined,
+ getHold: botId => rt.browserChannel?.holdOf(botId) ?? null,
+ onHold: (botId, hold) => rt.browserChannel?.setHold(botId, hold),
+ subscribeHolds: listener => rt.browserChannel?.subscribeHolds?.(listener),
authorize: (exec, botId, action) => authorizeBrowserAction(rt, exec, botId, action),
- complete: rt.config.browserComplete ?? completeDeepseek,
+ completeFor: rt.config.browserComplete
+ ? () => rt.config.browserComplete
+ : exec => sessionComplete(rt.ctx, exec, rt),
async keyOf(exec) {
await rt.load()
const id = rt.selfOf(exec.agent?.session?.header?.id ?? exec.agent?.id)
diff --cc ds-bot/src/host/browser/mount.js
index 791d8681,dbe5b4cd..6de9ca65
--- a/ds-bot/src/host/browser/mount.js
+++ b/ds-bot/src/host/browser/mount.js
@@@ -30,19 -18,11 +30,19 @@@ export const browserOutput =
/**
* @param {any} ctx
- * @param {{ toolDefs: any[], defineTool: Function, keyOf: (exec: any) => Promise<string|undefined>, profileRoot: string, downloadRoot?: string, downloadRoots?: (botId: string) => Promise<string[]>, uploadRoots?: (botId: string) => Promise<string[]>, headless: boolean, playwrightUrl?: string, executablePath?: string, actionTimeout?: number, authorize?: (exec: any, botId: string, action: any) => Promise<void>, complete?: Function, connect?: (botId: string, downloadRoots?: string[]) => Promise<string>, getHold?: (botId: string) => any, onHold?: (botId: string, hold: any) => void, subscribeHolds?: (listener: (botId: string, hold: any) => void) => (() => void) | undefined, openSession?: typeof openBotBrowser }} options
- * @param {{ toolDefs: any[], defineTool: Function, keyOf: (exec: any) => Promise<string|undefined>, profileRoot: string, downloadRoot?: string, uploadRoots?: (botId: string) => Promise<string[]>, headless: boolean, playwrightUrl?: string, executablePath?: string, actionTimeout?: number, authorize?: (exec: any, botId: string, action: any) => Promise<void>, completeFor?: (exec: any) => Function }} options
++ * @param {{ toolDefs: any[], defineTool: Function, keyOf: (exec: any) => Promise<string|undefined>, profileRoot: string, downloadRoot?: string, downloadRoots?: (botId: string) => Promise<string[]>, uploadRoots?: (botId: string) => Promise<string[]>, headless: boolean, playwrightUrl?: string, executablePath?: string, actionTimeout?: number, authorize?: (exec: any, botId: string, action: any) => Promise<void>, completeFor?: (exec: any) => Function, connect?: (botId: string, downloadRoots?: string[]) => Promise<string>, getHold?: (botId: string) => any, onHold?: (botId: string, hold: any) => void, subscribeHolds?: (listener: (botId: string, hold: any) => void) => (() => void) | undefined, openSession?: typeof openBotBrowser }} options
*/
- export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRoot, downloadRoot, downloadRoots, uploadRoots, headless, playwrightUrl, executablePath, actionTimeout, authorize, complete, connect, getHold, onHold, subscribeHolds, openSession = openBotBrowser }) {
-export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRoot, downloadRoot, uploadRoots, headless, playwrightUrl, executablePath, actionTimeout, authorize, completeFor }) {
++export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRoot, downloadRoot, downloadRoots, uploadRoots, headless, playwrightUrl, executablePath, actionTimeout, authorize, completeFor, connect, getHold, onHold, subscribeHolds, openSession = openBotBrowser }) {
const sessions = new Map()
+ const unsubscribeHolds = subscribeHolds?.((botId, hold) => {
+ if (hold?.by !== 'user') return
+ const session = sessions.get(botId)
+ if (!session) return
+ sessions.delete(botId)
+ void session.close()
+ })
ctx.effect(() => async () => {
+ unsubscribeHolds?.()
const open = [...sessions.values()]
sessions.clear()
await Promise.all(open.map(session => session.close()))
diff --cc ds-bot/test/browser-plugins.test.js
index ef407dd5,8e3042a0..478f05b2
--- a/ds-bot/test/browser-plugins.test.js
+++ b/ds-bot/test/browser-plugins.test.js
@@@ -4,9 -4,8 +4,10 @@@ import { tmpdir } from 'node:os
import { join } from 'node:path'
import { test } from 'node:test'
import { apply, createRuntime } from '../index.js'
+ import { defaultBrowserHeadless } from '../src/host/browser-plugins.js'
import { gateScope } from '../src/host/browser/gate.js'
+import { appBrowserEndpoint } from '../src/host/browser-plugins.js'
+import { mountBrowserPlugin } from '../src/host/browser/mount.js'
import { systemPrompt as refsPrompt, toolDefs as refsTools } from '../src/host/browser/refs.js'
import { fakeApproval, fakeContext } from './fake-ctx.js'
@@@ -159,36 -100,62 +160,92 @@@ test('no browser plugin is mounted unle
assert.equal(ctx.registeredTools.has('browser_task'), false)
})
+test('user browser controls are not exposed as Bot tools', (t) => {
+ const { ctx, stop } = start({ browser: true, browserPlugin: 'refs' })
+ t.after(stop)
+ for (const name of ['browser-takeover', 'browser-give-back', 'browser-stop']) {
+ assert.equal(ctx.registeredTools.has(name), false)
+ }
+})
+
+test('browser-stop cancels the Bot chat, stops its room work, and sets a user hold', async (t) => {
+ const { rt, call, stop } = start({ browser: true })
+ t.after(stop)
+ await rt.load()
+
+ rt.state.rooms.room1 = { id: 'room1', members: ['b2'], sessions: { b2: 'room-session' } }
+ rt.state.rooms.room2 = { id: 'room2', members: ['m1'], sessions: { m1: 'other-session' } }
+ rt.live.set('b2', { turn: {} })
+ rt.live.set('room-session', { turn: {} })
+ const cancelled = []
+ const stoppedRooms = []
+ rt.resolveAgent = async sessionId => ({ cancel: reason => cancelled.push({ sessionId, reason }) })
+ rt.stopMemberWork = async (roomId, botId) => { stoppedRooms.push({ roomId, botId }) }
+
+ assert.equal((await call('browser-stop', { botId: 'b2' })).value, true)
+ assert.deepEqual(cancelled, [{ sessionId: 'b2', reason: { kind: 'user' } }])
+ assert.deepEqual(stoppedRooms, [{ roomId: 'room1', botId: 'b2' }])
+ assert.deepEqual(rt.browserChannel.holdOf('b2'), {
+ by: 'user', reason: 'stopped', note: 'The user is controlling this browser.',
+ })
+})
+
+ test('browser headless defaults only on Linux without a display', () => {
+ assert.equal(defaultBrowserHeadless('linux', { DISPLAY: ':0' }), false)
+ assert.equal(defaultBrowserHeadless('linux', {}), true)
+ assert.equal(defaultBrowserHeadless('darwin', {}), false)
+ })
+
+ test('browser_task uses the Bot session model route when no test completion is injected', async (t) => {
+ const { ctx, stop } = start({
+ browserPlugin: 'task',
+ browserPluginApi: {
+ id: 'task',
+ tools: [{
+ name: 'browser_task',
+ needsBrowser: false,
+ async execute(_args, toolCtx) {
+ const response = await toolCtx.complete({
+ messages: [{ role: 'user', content: 'Read the page.' }],
+ tools: [{
+ type: 'function',
+ function: { name: 'browser_snapshot', description: 'Read page', parameters: { type: 'object' } },
+ }],
+ })
+ return response.choices[0].message.content
+ },
+ }],
+ },
+ })
+ t.after(stop)
+ const requests = []
+ ctx.llm = {
+ async *stream(request) {
+ requests.push(request)
+ yield { type: 'text-delta', index: 0, text: 'Session-routed response.' }
+ yield { type: 'finish', reason: { kind: 'stop' } }
+ },
+ }
+ const session = {
+ id: 'session-b2',
+ header: { id: 'b2' },
+ requestHeader: () => ({
+ config: { provider: 'mock-provider', model: 'bot-session-model' },
+ tools: [{ name: 'session-private-tool', description: '', parameters: {} }],
+ }),
+ }
+
+ const value = await ctx.registeredTools.get('browser_task').execute({}, {
+ agent: { id: 'b2', session },
+ signal: new AbortController().signal,
+ })
+
+ assert.equal(value, 'Session-routed response.')
+ assert.equal(requests[0].model, 'bot-session-model')
+ assert.equal(requests[0].sessionId, 'session-b2')
+ assert.deepEqual(requests[0].tools.map(tool => tool.name), ['browser_snapshot'])
+ })
+
test('the selected plugin is the same for every Bot, and profiles stay apart', async (t) => {
const seen = []
const { ctx, stop } = start({