A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Ask for computer access DS Bot never decided and clear decisions on revoke
Fei241150420c721226
diff --git a/ds-bot/dev/mock-llm.mjs b/ds-bot/dev/mock-llm.mjsindex 833be49f..c044f65d 100644--- a/ds-bot/dev/mock-llm.mjs+++ b/ds-bot/dev/mock-llm.mjs@@ -248,6 +248,7 @@ function decide(body) {return [text(picked ? `好,就从「${picked}」开始。` : '好的。'), text('我先把要点理一下,稍后给你一个方案。')]}case 'list_bots': return [text(`现在的班底:\n${resultText}`)]+ case 'cua': return [text(`cua 结果:${resultText.slice(0, 400)}`)]case 'create_group':case 'update_group':case 'delete_group':@@ -428,6 +429,13 @@ function decide(body) {if ((order = /^插话\s*(\S+?)\s*[::]\s*(.+)$/.exec(userText))) return [tool('message_bot', { to: order[1], message: order[2], when: 'now' })]if ((order = /^排队\s*(\S+?)\s*[::]\s*(.+)$/.exec(userText))) return [tool('message_bot', { to: order[1], message: order[2], when: 'queue' })]if ((order = /^叫停\s*(\S+?)\s*[::]\s*(.+)$/.exec(userText))) return [tool('stop_bot', { bot: order[1], reason: order[2] })]+ // 调用 <tool> <json>: emit the named tool call verbatim — the generic way to+ // drive a tool the mock has no dedicated trigger for (e.g. the cua methods).+ if ((order = /^调用\s*(\S+)(?:\s+([\s\S]+))?$/.exec(userText))) {+ if (!tools.has(order[1])) return [text(`The tool ${order[1]} is not in my tool list.`)]+ try { return [tool(order[1], order[2] ? JSON.parse(order[2]) : {})] }+ catch { return [text(`Bad JSON for ${order[1]}.`)] }+ }if ((order = /^看群\s*(.+)$/.exec(userText))) return [tool('read_group_chat', { group: order[1].trim() })]// Memory: 记住[@话题] 事实 · 团队记住 事实 · 忘掉 事实 · 回忆 [词]if ((order = /^(团队)?记住(?:@(\S+))?\s*[::]?\s*(.+)$/.exec(userText)) && tools.has('remember')) {diff --git a/ds-bot/src/host/computer/index.js b/ds-bot/src/host/computer/index.jsindex e6dc4451..7b2eed67 100644--- a/ds-bot/src/host/computer/index.js+++ b/ds-bot/src/host/computer/index.js@@ -287,7 +287,7 @@ export function install(rt) {}const handle = typeof params.appHandle === 'string' ? params.appHandle : undefinedif (handle === undefined) return undefined- return appsOfSession(sessionId).get(`handle:${handle}`) ?? { key: `handle:${handle}`, name: 'the selected app' }+ return appsOfSession(sessionId).get(`handle:${handle}`) ?? { key: `handle:${handle}`, name: 'the selected app', unknown: true }}const args = exec.arguments ?? {}const pid = [args.pid, args.appPid, args.windowPid, args.target_pid].find(value => Number.isInteger(value))@@ -429,6 +429,7 @@ export function install(rt) {return 'allow'}decisions.set(app.key, answer === 'once' ? 'once' : 'deny')+ if (normName(app.name) !== app.key) decisions.set(normName(app.name), answer === 'once' ? 'once' : 'deny')return answer === 'once' ? 'allow' : `The user did not allow ${bot.name} to use ${app.name}.`}@@ -462,14 +463,20 @@ export function install(rt) {}// Every refusal is decided before a lease is taken.if (call.provider === 'cua' && app !== undefined && app.tentative !== true) {- // macOS: DSH's per-Session decision is not enough; DS Bot requires its own- // Always grant or a "This time" for this Session, so a revoke bites at once.- const decision = decisionsOf(bot.id, sessionId).get(app.key) ?? decisionsOf(bot.id, sessionId).get(normName(app.name))+ if (app.unknown === true) {+ return { kind: 'deny', reason: `Access to ${app.name} was revoked. Select it again with getApp.` }+ }+ // macOS: DS Bot requires its own Always grant or a "This time" for this+ // Session, so a revoke bites at once. A saved DSH decision can let getApp+ // through without asking here; then the first real call asks by card.+ const decisions = decisionsOf(bot.id, sessionId)+ const decision = decisions.get(app.key) ?? decisions.get(normName(app.name))if (decision === 'deny') {return { kind: 'deny', reason: `The user did not allow ${bot.name} to use ${app.name}.` }}if (decision !== 'once' && grantFor(bot, app) === undefined) {- return { kind: 'deny', reason: `Access to ${app.name} was revoked. Select it again with getApp.` }+ const verdict = await driverConsent(exec, bot, sessionId, app)+ if (verdict !== 'allow') return { kind: 'deny', reason: verdict }}}if (call.provider === 'cua-driver' && app !== undefined) {@@ -729,9 +736,17 @@ export function install(rt) {// the provider's decision too or the Bot keeps using the app. Other Bots'// grants are unaffected: their next getApp is answered by DS Bot again.const access = ctx.get?.('cuaAccess')- const wanted = normName(grant?.name ?? appKey)- const knownId = grant?.id ?? [...sessionApps.values()].flatMap(map => [...map.values()])- .find(app => app.id !== undefined && (normName(app.name) === wanted || app.key === appKey))?.id+ const recorded = [...sessionApps.values()].flatMap(map => [...map.values()])+ .find(app => app.key === appKey || app.id === appKey || normName(app.name) === normName(grant?.name ?? appKey))+ const wanted = normName(grant?.name ?? recorded?.name ?? appKey)+ // A "This time" must not outlive the revoke, in any of this Bot's Sessions.+ for (const [key, decisions] of sessionDecisions) {+ if (!key.startsWith(`${botId}:`)) continue+ for (const entry of [...decisions.keys()]) {+ if (entry === appKey || normName(entry) === wanted) decisions.delete(entry)+ }+ }+ const knownId = grant?.id ?? recorded?.idif (access !== undefined && knownId !== undefined && typeof access.revoke === 'function') {await access.revoke(knownId).catch(error => rt.warn('ds-bot: revoking %s in the provider failed: %s', knownId, error))}diff --git a/ds-bot/test/computer.test.js b/ds-bot/test/computer.test.jsindex f9d52d26..9494721b 100644--- a/ds-bot/test/computer.test.js+++ b/ds-bot/test/computer.test.js@@ -382,14 +382,17 @@ test('a revoke removes the grant, aborts the call, revokes in the provider and tconst allow = async () => 'allowed'const call = args => gate({ name: 'cua', arguments: args, agent: { id: 'w1' }, callId: 'c1' }, allow)assert.equal(await call({ method: 'click', params: { appHandle: 'h1' } }), 'allowed')- // revoke: grant gone, provider revoked, guard refuses the old handle+ // revoke: grant gone, provider revoked, the old handle asks again instead of runningassert.equal(await rt.computerEndpoint('revoke-app', { botId: 'w1', appKey: 'notes' }), true)assert.equal(rt.botOf('w1').computer.apps, undefined)assert.deepEqual(revoked, ['com.apple.Notes'])- const after = await call({ method: 'click', params: { appHandle: 'h1' } })- assert.equal(after.kind, 'deny')- assert.match(after.reason, /revoked|Select it again/)- // and a fresh getApp asks through the card again+ const pending = call({ method: 'click', params: { appHandle: 'h1' } })+ await new Promise(resolve => setImmediate(resolve))+ assert.equal(Object.keys(rt.computerLive().asks).length, 1)+ const [id] = Object.entries(rt.computerLive().asks)[0]+ await rt.computerEndpoint('app-answer', { id, answer: 'deny' })+ assert.match((await pending).reason, /did not allow/)+ // a fresh getApp asks through the card againconst answerer = ctx.listeners.get('user-questions/request').find(fn => fn.name === 'computerConsent')void answerer({ agent: { id: 'w1' }, questions: [{ id: 'cua-app-access', intent: { subject: { name: 'Notes' } }, options: [] }] }, async () => 'next')await new Promise(resolve => setImmediate(resolve))@@ -573,3 +576,72 @@ test('computer_handoff: the hold answers done, skip and takeover', async (t) =>assert.equal(reply.outcome, 'done')assert.match(reply.message, /gave the computer back|handed/)})++test('a cua call DS Bot never decided asks by card instead of saying revoked', 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'+ // DSH's saved decision let getApp through; DS Bot never saw a consent question.+ await track({ name: 'cua', arguments: { method: 'getApp', params: { selector: 'Notes' } }, agent: { id: 'w1' }, callId: 'g1' },+ async () => ({ appHandle: 'h1', pid: 9, authorization: { id: 'com.apple.Notes', name: 'Notes' } }))+ const pending = gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: 'h1' } }, agent: { id: 'w1' }, callId: 'c1' }, allow)+ 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 Session decision now covers later calls without a new card+ assert.equal(await gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: 'h1' } }, agent: { id: 'w1' }, callId: 'c2' }, allow), 'allowed')+ // an explicit Deny is still a refusal, not a card+ const denied = gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: 'h1' } }, agent: { id: 'w1' }, callId: 'c3' }, allow)+ assert.equal(await denied, 'allowed')+ // but a deny recorded for another app refuses outright+ await track({ name: 'cua', arguments: { method: 'getApp', params: { selector: 'Mail' } }, agent: { id: 'w1' }, callId: 'g2' },+ async () => ({ appHandle: 'h2', pid: 10, authorization: { id: 'com.apple.Mail', name: 'Mail' } }))+ const ask2 = gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: 'h2' } }, agent: { id: 'w1' }, callId: 'c4' }, allow)+ await new Promise(resolve => setImmediate(resolve))+ const [id2] = Object.entries(rt.computerLive().asks)[0]+ await rt.computerEndpoint('app-answer', { id: id2, answer: 'deny' })+ assert.match((await ask2).reason, /did not allow/)+ const again = await gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: 'h2' } }, agent: { id: 'w1' }, callId: 'c5' }, allow)+ assert.match(again.reason, /did not allow/)+})++test('a revoke clears the Bot’s session decisions for the app in every Session', 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 other = 'w1-part2'+ rt.isBotSession = id => id === 'w1' || id === other+ const selfOf = rt.selfOf+ rt.selfOf = id => (id === other ? 'w1' : selfOf(id))+ for (const sessionId of ['w1', other]) {+ await track({ name: 'cua', arguments: { method: 'getApp', params: { selector: 'Notes' } }, agent: { id: sessionId }, callId: `g-${sessionId}` },+ async () => ({ appHandle: `h-${sessionId}`, pid: 9, authorization: { id: 'com.apple.Notes', name: 'Notes' } }))+ const pending = gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: `h-${sessionId}` } }, agent: { id: sessionId }, callId: `c-${sessionId}` }, allow)+ await new Promise(resolve => setImmediate(resolve))+ const [id] = Object.entries(rt.computerLive().asks)[0]+ await rt.computerEndpoint('app-answer', { id, answer: 'once' })+ assert.equal(await pending, 'allowed')+ }+ // revoke: the next call in each Session asks again rather than reusing the decision+ await rt.computerEndpoint('revoke-app', { botId: 'w1', appKey: 'com.apple.Notes' })+ for (const sessionId of ['w1', other]) {+ const pending = gate({ name: 'cua', arguments: { method: 'click', params: { appHandle: `h-${sessionId}` } }, agent: { id: sessionId }, callId: `d-${sessionId}` }, allow)+ await new Promise(resolve => setImmediate(resolve))+ assert.equal(Object.keys(rt.computerLive().asks).length, 1, sessionId)+ const [id] = Object.entries(rt.computerLive().asks)[0]+ await rt.computerEndpoint('app-answer', { id, answer: 'deny' })+ await pending+ }+})