Skip to content

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

Bridge approvals for Bots moved onto a local agent and keep activity on its own line

Fei24112064637def5d
diff --git a/ds-bot/src/host/local-agents/acp.js b/ds-bot/src/host/local-agents/acp.js
index f7567e16..93cc864c 100644
--- a/ds-bot/src/host/local-agents/acp.js
+++ b/ds-bot/src/host/local-agents/acp.js
@@ -103,6 +103,8 @@ export class AcpEngine {
const session = [...this.sessions.values()].find(entry => entry.acpSessionId === params?.sessionId)
if (session === undefined) return Promise.reject({ code: -32603, message: 'unknown session' })
const options = (params?.options ?? []).map(option => ({ optionId: option.optionId, name: option.name, kind: option.kind }))
+ const call = callOf(session, params?.toolCall)
+ const action = describeCall(call)
return new Promise((resolve) => {
const id = `perm-${Math.random().toString(36).slice(2)}`
const reply = (optionId) => {
@@ -111,8 +113,8 @@ export class AcpEngine {
}
session.push({
type: 'permission', id, reply,
- action: describeCall(callOf(session, params?.toolCall)),
- detail: detailText(callOf(session, params?.toolCall)),
+ action,
+ detail: detailText(call, action),
options,
})
})
@@ -209,12 +211,17 @@ export const describeCall = (call) => {
if (verb !== undefined && target !== '') return `${verb} ${target}`
return [title ?? verb ?? 'Use a tool', target].filter(Boolean).join(': ')
}
-const detailText = (toolCall) => {
- if (toolCall === undefined) return ''
- const parts = []
- if (toolCall.rawInput !== undefined) parts.push(JSON.stringify(toolCall.rawInput))
- if (Array.isArray(toolCall.locations) && toolCall.locations.length > 0) parts.push(toolCall.locations.map(location => location.path).join(', '))
- return parts.join('\n').slice(0, 4_000)
+// What the card adds under its one-line action: the call's other inputs, one
+// per line; what the action line already says is not repeated.
+const detailText = (call, action = '') => {
+ const lines = Object.entries(inputOf(call))
+ .filter(([, value]) => value !== undefined && value !== null && value !== '')
+ .map(([key, value]) => [key, typeof value === 'string' ? value : JSON.stringify(value)])
+ .filter(([, value]) => !action.includes(value))
+ .map(([key, value]) => `${key}: ${value}`)
+ const paths = (call.locations ?? []).map(location => location?.path).filter(path => path && !action.includes(path))
+ if (paths.length > 0) lines.push(paths.join(', '))
+ return lines.join('\n').slice(0, 4_000)
}
const usageOf = update => {
const used = update.used ?? update
diff --git a/ds-bot/src/host/local-agents/adapter.js b/ds-bot/src/host/local-agents/adapter.js
index 8943dc03..30e8b3cb 100644
--- a/ds-bot/src/host/local-agents/adapter.js
+++ b/ds-bot/src/host/local-agents/adapter.js
@@ -411,7 +411,9 @@ export class LocalAgentAdapter extends LlmAdapter {
}
case 'thought':
case 'activity': {
- const text = event.type === 'activity' ? `${event.text}\n` : event.text
+ // An activity line stands on its own line of the reasoning, which is
+ // how the chat tells it from the thought around it.
+ const text = event.type === 'activity' ? `${thinkBuf === '' || thinkBuf.endsWith('\n') ? '' : '\n'}${event.text}\n` : event.text
if (thinkIndex === -1) {
if (textIndex !== -1) { yield { type: 'block-end', index: textIndex, block: { type: 'text', text: textBuf } }; textIndex = -1; textBuf = '' }
yield { type: 'block-start', index: index++, blockType: 'reasoning' }
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index 2af3a172..9cce9daf 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -797,9 +797,15 @@ export function install(rt) {
const relayOnly = !owns && rt.roomOf(id) !== undefined
const wanted = owns || relayOnly
let held = scoped.get(id)
- // A Session that left the team, a scope of the wrong kind, or a fresh Agent
- // for one Session all start over; a wanted scope is registered again below.
- if (held !== undefined && (!wanted || held.agent !== agent || held.relay !== relayOnly)) {
+ // The local-agent tools (the CLI permission bridge) join the scope only of
+ // a Bot whose route is a local agent; they are not in rt.teamTools. A Bot
+ // can move onto or off a local route after its Agent exists.
+ const self = owns ? rt.botOf(rt.selfOf(id)) : undefined
+ const localBot = rt.isLocalAgentRef?.(self?.appliedModel ?? self?.model) === true
+ // A Session that left the team, a scope of the wrong kind, a fresh Agent
+ // for one Session, or a Bot that changed between a local route and a model
+ // all start over; a wanted scope is registered again below.
+ if (held !== undefined && (!wanted || held.agent !== agent || held.relay !== relayOnly || (held.tools === true && held.local !== localBot))) {
unscope(id)
held = undefined
}
@@ -814,9 +820,6 @@ export function install(rt) {
const disposers = []
const failed = []
const registered = []
- // The local-agent tools (the CLI permission bridge) join the scope only of
- // a Bot whose route is a local agent; they are not in rt.teamTools.
- const localBot = rt.isLocalAgentRef?.(rt.botOf(rt.selfOf(id))?.appliedModel ?? rt.botOf(rt.selfOf(id))?.model) === true
for (const def of [...rt.teamTools, ...(localBot ? (rt.localAgentTools ?? []) : [])]) {
if (relayOnly && def.name !== 'group_relay') continue
try {
@@ -837,6 +840,7 @@ export function install(rt) {
held.agent = agent
held.relay = relayOnly
held.tools = true
+ held.local = localBot
held.disposers.push(...disposers)
scoped.set(id, held)
// A scope made outside creation never reached a collected tool list; the
diff --git a/ds-bot/test/fixtures/fake-acp.mjs b/ds-bot/test/fixtures/fake-acp.mjs
index a24db134..bae0b1e2 100644
--- a/ds-bot/test/fixtures/fake-acp.mjs
+++ b/ds-bot/test/fixtures/fake-acp.mjs
@@ -36,7 +36,7 @@ async function runPrompt(session, prompt, requestId) {
update(sessionId, { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text: textOut } })
reply(requestId, { stopReason: 'end_turn' })
}
- if (text.includes('hang')) return // session/cancel releases it below
+ if (/\bhang\b/.test(text)) return // session/cancel releases it below
if (text.includes('ask-permission')) {
// Like Devin: the call's kind and input arrive with its tool_call update;
// the permission request names it only by id.
@@ -66,7 +66,9 @@ async function runPrompt(session, prompt, requestId) {
return
}
update(sessionId, { sessionUpdate: 'agent_thought_chunk', content: { type: 'text', text: `thought about: ${text.slice(0, 40)}` } })
- update(sessionId, { sessionUpdate: 'tool_call', toolCallId: 't0', title: 'edit src/a.js', kind: 'edit', status: 'in_progress' })
+ update(sessionId, { sessionUpdate: 'tool_call', toolCallId: 't0', kind: 'read', status: 'in_progress', locations: [{ path: 'src/a.js' }] })
+ update(sessionId, { sessionUpdate: 'tool_call', toolCallId: 't1', kind: 'execute', status: 'in_progress', rawInput: { command: 'npm test' } })
+ update(sessionId, { sessionUpdate: 'tool_call_update', toolCallId: 't1', status: 'completed' })
finish(`ok: ${text.slice(0, 60)}`)
}
diff --git a/ds-bot/test/local-agents.test.js b/ds-bot/test/local-agents.test.js
index 0c98b015..563be85b 100644
--- a/ds-bot/test/local-agents.test.js
+++ b/ds-bot/test/local-agents.test.js
@@ -130,7 +130,9 @@ test('a permission prompt bridges to approve_agent_action and fails closed', asy
assert.equal(ask.finish.kind, 'tool-calls')
assert.equal(ask.calls[0].name, 'approve_agent_action')
// The request named the call only by id; the card still says what it runs.
- assert.equal(JSON.parse(ask.calls[0].arguments ?? JSON.stringify(ask.calls[0].args)).action, 'Run `rm -rf /tmp/x`')
+ const asked = JSON.parse(ask.calls[0].arguments ?? JSON.stringify(ask.calls[0].args))
+ assert.equal(asked.action, 'Run `rm -rf /tmp/x`')
+ assert.equal(asked.detail ?? '', '')
// An allowed answer picks the agent's allow option: the tool returns its
// structured decision, and only {"decision":"allow"} counts.
const allowed = await collect(adapter.stream(options('s1', [user('m1', 'ask-permission'), toolResult('m2', ask.calls[0].id, JSON.stringify({ decision: 'allow' }))])))
diff --git a/ds-bot/test/scoped-tools-creation.test.js b/ds-bot/test/scoped-tools-creation.test.js
index 9711bf27..5a685191 100644
--- a/ds-bot/test/scoped-tools-creation.test.js
+++ b/ds-bot/test/scoped-tools-creation.test.js
@@ -187,6 +187,24 @@ test('a Bot Session gets every team tool in its own scope', async (t) => {
assert.deepEqual(scopedNames(host, 'a').sort(), [...TEAM_TOOLS].filter(name => name !== 'read_browser').sort())
})
+test('a Bot moved onto a local agent route gets the approval bridge, and loses it moving off', async (t) => {
+ const host = start()
+ t.after(host.stop)
+ await host.call('state', {})
+ await host.agentCreated('b')
+ assert.equal(scopedNames(host, 'b').includes('approve_agent_action'), false)
+ rt.isLocalAgentRef = ref => typeof ref === 'string' && ref.startsWith('acp-')
+ const bot = rt.botOf('b')
+ bot.model = 'acp-fake/default'
+ rt.hideBotUnusedTools(host.agentOf('b'))
+ assert.equal(scopedNames(host, 'b').includes('approve_agent_action'), true)
+ assert.equal(scopedNames(host, 'b').filter(name => name === 'message_bot').length, 1)
+ bot.model = 'deepseek-official/deepseek-flash'
+ rt.hideBotUnusedTools(host.agentOf('b'))
+ assert.equal(scopedNames(host, 'b').includes('approve_agent_action'), false)
+ assert.equal(scopedNames(host, 'b').includes('message_bot'), true)
+})
+
test('a Session ds-bot does not own sees none of the team tools', async (t) => {
const host = start()
t.after(host.stop)