A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Listen once for indicator clicks and let launch_app reach consent
Fei2411f95df287920c
diff --git a/app/src/computer-indicator.mjs b/app/src/computer-indicator.mjsindex c6aa6987..3b961ed6 100644--- a/app/src/computer-indicator.mjs+++ b/app/src/computer-indicator.mjs@@ -17,6 +17,12 @@*/export function createComputerIndicator({ BrowserWindow, screen, html, ipcMain, preload, onAction = () => {}, log = console }) {let win = null+ // One listener for the indicator's whole life: a listener per open() would+ // multiply each click on reopen. The check pins it to the current window.+ ipcMain?.on?.('ds-bot:computer-indicator:act', (event, action, botId) => {+ if (event?.sender !== win?.webContents) return+ onAction(String(action ?? ''), botId === '' || botId === undefined || botId === null ? null : String(botId))+ })let entries = []let labels = {}const open = () => {@@ -45,12 +51,6 @@ export function createComputerIndicator({ BrowserWindow, screen, html, ipcMain,try { win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }) } catch (error) { log.warn(`DS Bot: the indicator could not join every workspace: ${error instanceof Error ? error.message : String(error)}`) }win.once('ready-to-show', () => { win?.showInactive() })win.on('closed', () => { win = null })- // Button clicks reach the main process over a dedicated channel through the- // indicator's own preload; nothing else may send on it.- ipcMain?.on?.('ds-bot:computer-indicator:act', (event, action, botId) => {- if (event?.sender !== win?.webContents) return- onAction(String(action ?? ''), botId === '' || botId === undefined || botId === null ? null : String(botId))- })const page = html(entries, labels)win.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(page)}`).catch((error) => {log.warn(`DS Bot: the indicator did not load: ${error instanceof Error ? error.message : String(error)}`)diff --git a/app/test/computer-indicator.test.mjs b/app/test/computer-indicator.test.mjsindex 31d4d029..92ea3b27 100644--- a/app/test/computer-indicator.test.mjs+++ b/app/test/computer-indicator.test.mjs@@ -107,3 +107,23 @@ test('button actions go over the dedicated channel and only from the indicator',assert.deepEqual(calls, [['stop', 'w1']])indicator.dispose()})++test('a reopen keeps exactly one action listener, so one click acts once', () => {+ const { windows, BrowserWindow, screen } = fakeElectron()+ const listeners = {}+ const ipcMain = { on: (channel, fn) => { (listeners[channel] ??= []).push(fn) } }+ const calls = []+ const indicator = createComputerIndicator({+ BrowserWindow, screen, html: () => '<html></html>', ipcMain,+ onAction: (kind, botId) => calls.push(kind),+ log: { warn: () => {} },+ })+ indicator.update({ rows: [{ label: 'Chief · Notes', botId: 'w1' }], labels: {} })+ windows[0].close()+ indicator.update({ rows: [{ label: 'Chief · Notes', botId: 'w1' }], labels: {} })+ assert.equal(windows.length, 2)+ assert.equal(listeners['ds-bot:computer-indicator:act'].length, 1)+ listeners['ds-bot:computer-indicator:act'][0]({ sender: windows[1].webContents }, 'stop', 'w1')+ assert.deepEqual(calls, ['stop'])+ indicator.dispose()+})diff --git a/ds-bot/src/host/computer/index.js b/ds-bot/src/host/computer/index.jsindex 5906e140..65e82e60 100644--- a/ds-bot/src/host/computer/index.js+++ b/ds-bot/src/host/computer/index.js@@ -53,7 +53,7 @@ export function isProtectedApp(app) {if (PROTECTED_IDS.has(id)) return trueconst name = String(app.name ?? '').trim().toLowerCase()if (PROTECTED_NAMES.has(name)) return true- const base = (String(app.path ?? app.executablePath ?? '').split(/[\\/]/).pop() ?? '').toLowerCase().replace(/\.exe?$/i, '')+ const base = (String(app.path ?? app.executablePath ?? '').split(/[\\/]/).pop() ?? '').toLowerCase().replace(/\.(exe|app)$/i, '')return PROTECTED_EXES.has(base)}@@ -301,6 +301,13 @@ export function install(rt) {return appsOfSession(sessionId).get(`handle:${handle}`) ?? { key: `handle:${handle}`, name: 'the selected app', unknown: true }}const args = exec.arguments ?? {}+ if (call.method === 'launch_app') {+ const id = [args.bundle_id, args.bundleId, args.app_id, args.appId].find(value => typeof value === 'string' && value !== '')+ const path = [args.path, args.app_path, args.executable_path, args.executablePath].find(value => typeof value === 'string' && value !== '')+ const name = [args.name, args.app_name, args.appName, args.app].find(value => typeof value === 'string' && value !== '')+ if (id === undefined && path === undefined && name === undefined) return undefined+ return { key: appKeyOf({ id, path, name }), name: name ?? path ?? id, id, path, tentative: true }+ }const pid = [args.pid, args.appPid, args.windowPid, args.target_pid].find(value => Number.isInteger(value))if (pid !== undefined) {const known = appsOfSession(sessionId).get(`pid:${pid}`)@@ -370,6 +377,11 @@ export function install(rt) {// record both so a later call on either resolves to the window's app.const stateWindow = [result.window_id, result.windowId, result.wid, result.window?.window_id, result.window?.id].find(value => value !== undefined && value !== null)const statePid = [result.pid, result.appPid, result.app_pid, result.window?.pid, result.window?.app_pid].find(value => Number.isInteger(value))+ if (call.method === 'launch_app') {+ const app = recordPid(result)+ const windowId = [result.window_id, result.windowId, result.wid].find(value => value !== undefined && value !== null)+ if (app !== undefined && windowId !== undefined) apps.set(`window:${windowId}`, app)+ }let stateApp = statePid !== undefined ? recordPid(result) ?? apps.get(`pid:${statePid}`) : undefinedif (stateApp === undefined && stateWindow !== undefined) stateApp = apps.get(`window:${stateWindow}`)if (stateApp === undefined && result?.window && typeof result.window === 'object') stateApp = recordPid(result.window)diff --git a/ds-bot/test/computer.test.js b/ds-bot/test/computer.test.jsindex c4ead18c..0e121e6b 100644--- a/ds-bot/test/computer.test.js+++ b/ds-bot/test/computer.test.js@@ -861,3 +861,33 @@ test('browser tools need a resolvable target, and the driver-refused methods denawait rt.computerEndpoint('app-answer', { id: Object.keys(rt.computerLive().asks)[0], answer: 'once' })assert.equal(await pending, 'allowed')})++test('launch_app resolves by its own name or path: consent, protected check, recorded app', async (t) => {+ const { ctx, home, rt } = setup()+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await rt.load()+ await rt.computerEndpoint('set-enabled', { enabled: true })+ await rt.computerEndpoint('set-level', { botId: 'w1', level: 'background' })+ const gate = ctx.listeners.get('tools/pre-execute').find(fn => fn.name === 'computerGate')+ const track = ctx.listeners.get('tools/execute').find(fn => fn.name === 'computerTrack')+ const allow = async () => 'allowed'+ const call = (args = {}) => gate({ name: 'cua_driver_native__launch_app', arguments: args, agent: { id: 'w1' }, callId: 'launch' }, allow)+ // no identifying argument: refused+ const blind = await call({})+ assert.equal(blind.kind, 'deny')+ // a protected path is refused without a card+ const protectedCall = await call({ path: '/Applications/DSH Computer Use.app' })+ assert.equal(protectedCall.kind, 'deny')+ assert.match(protectedCall.reason, /protected/)+ // an unprotected app asks by card, then runs+ const pending = call({ name: 'Notes', path: '/Applications/Notes.app' })+ await new Promise(resolve => setImmediate(resolve))+ const [id, ask] = Object.entries(rt.computerLive().asks)[0]+ assert.equal(ask.appName, 'Notes')+ await rt.computerEndpoint('app-answer', { id, answer: 'once' })+ assert.equal(await pending, 'allowed')+ // the launched app is recorded: a later call on its window resolves without a card+ await track({ name: 'cua_driver_native__launch_app', arguments: { path: '/Applications/Notes.app' }, agent: { id: 'w1' }, callId: 'launch-2' },+ async () => ({ pid: 50, name: 'Notes', path: '/Applications/Notes.app', window_id: 9 }))+ assert.equal(await gate({ name: 'cua_driver_native__click', arguments: { window_id: 9 }, agent: { id: 'w1' }, callId: 'c9' }, allow), 'allowed')+})