A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep approved and shared capabilities when a Bot is deleted
Fei24112df6e879c0d7
diff --git a/ds-bot/src/host/capabilities.js b/ds-bot/src/host/capabilities.jsindex 66e377b5..29b13666 100644--- a/ds-bot/src/host/capabilities.js+++ b/ds-bot/src/host/capabilities.js@@ -152,19 +152,18 @@ export function install(rt) {await rt.save()return true}- // Called with the attachment list of a Bot being deleted, after it left the team:- // the items no remaining Bot uses leave the list with it instead of staying as- // orphans a later approval would start for nobody. Items never attached stay.- const dropOrphanCapabilities = (names) => {+ // Called with the Bot being deleted, after it left the team. The shared list belongs to+ // the user, so only a local MCP this Bot added, nobody approved and no other Bot or pack+ // uses goes: no one is left to ask for it, and approving it would start a server for no one.+ // Anything a pack lists stays.+ const dropOrphanCapabilities = (bot) => {const items = library()- // Children of a held pack count too: a Set visit reaches entries added while it runs.- const held = new Set(names ?? [])- for (const name of held) for (const child of own(items, name)?.items ?? []) held.add(child)- for (const name of held) {+ const packed = name => Object.values(items).some(item => item.kind === 'pack' && (item.items ?? []).includes(name))+ for (const name of bot.capabilities ?? []) {const item = own(items, name)- if (item === undefined || usedByOthers(name)) continue+ if (item === undefined || item.kind !== 'mcp' || item.transport !== 'stdio' || item.approved === true) continue+ if (item.createdBy !== bot.id || usedByOthers(name, bot.id) || packed(name)) continuedelete items[item.name]- for (const pack of Object.values(items)) if (pack.kind === 'pack') pack.items = (pack.items ?? []).filter(child => child !== item.name)}}const changeAttachment = async (endpoint, { name, bot: targetRef }, callerId) => {diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex bd36c1ec..16dae89b 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -648,9 +648,9 @@ export function install(rt) {await rt.releaseBot(id, [...parts, ...rt.groupSessionsOf(id)])if (closedArchive !== undefined) state.privateArchives = [...(state.privateArchives ?? []).filter(entry => entry.id !== id), closedArchive]delete state.bots[id]- // Shared capabilities only this Bot held have no Bot left to serve; they leave- // the shared list with it instead of staying as approvable orphans.- rt.dropOrphanCapabilities?.(bot.capabilities)+ // The shared capability list is the user's and keeps its items; only a+ // still-unapproved local MCP this Bot alone asked for leaves with it.+ rt.dropOrphanCapabilities?.(bot)for (const part of parts) {delete state.questions[part]if (state.views !== undefined) delete state.views[part]diff --git a/ds-bot/test/capabilities.test.js b/ds-bot/test/capabilities.test.jsindex 3e8302ec..3a651f94 100644--- a/ds-bot/test/capabilities.test.js+++ b/ds-bot/test/capabilities.test.js@@ -176,26 +176,54 @@ test('capability tool descriptions and attach results explain approval', async tassert.ok(attached.endsWith(' The user must allow blocked in DS Bot settings before it can work.'))})-test('a deleted Bot leaves no shared capability it alone held behind', async t => {+test('a deleted Bot drops only a pending local MCP it alone asked for', async t => {const env = await setup({beforeLoad: ({ ctx }) => { ctx.workspaceRegistry = { archiveSession: async () => {} } },})t.after(() => env.dispose())const { rt } = env- await rt.capabilitySave(mcp('echo'), { botId: 'chief' })- await rt.capabilitySave(mcp('solo'), { botId: 'chief' })- await rt.capabilitySave({ name: 'guide', kind: 'skill', description: 'Guide', content: 'Do the work.' }, { botId: 'chief' })- await rt.capabilitySave({ name: 'team', kind: 'pack', items: ['echo', 'solo'] }, { botId: 'chief' })- await rt.capabilitySave(mcp('shared'), { botId: 'chief' })- await rt.capabilitySave(mcp('unused'), { ui: true })- rt.state.bots.worker.capabilities = ['echo', 'guide', 'team']- rt.state.bots.helper.capabilities = ['guide', 'shared']+ const { items } = rt.state.capabilities+ // A local MCP the Bot asked for and nobody approved has no requester left.+ await rt.capabilitySave(mcp('pending-mine'), { botId: 'worker' })+ // Everything else stays: an approved one it asked for, a pending one the Main+ // Bot asked for, one the user saved in settings, and a skill.+ await rt.capabilitySave(mcp('approved-mine'), { botId: 'worker' })+ await rt.capabilityEndpoint('capability-approve', { name: 'approved-mine' })+ await rt.capabilitySave(mcp('pending-chief'), { botId: 'chief' })+ await rt.capabilitySave(mcp('shared'), { ui: true })+ await rt.capabilitySave({ name: 'guide', kind: 'skill', description: 'Guide', content: 'Do the work.' }, { botId: 'worker' })+ rt.state.bots.worker.capabilities = ['pending-mine', 'approved-mine', 'pending-chief', 'shared', 'guide']await rt.deleteBot('worker')- // 'echo', 'solo' (only inside 'team') and 'team' had no other holder; the rest stay.- assert.deepEqual(Object.keys(rt.state.capabilities.items).sort(), ['guide', 'shared', 'unused'])- await assert.rejects(rt.capabilityEndpoint('capability-approve', { name: 'echo' }), /No unapproved stdio MCP/)+ assert.equal(items['pending-mine'], undefined)+ assert.deepEqual(+ Object.keys(items).sort(),+ ['approved-mine', 'guide', 'pending-chief', 'shared'],+ )+ // The kept pending request can still be approved.+ await rt.capabilityEndpoint('capability-approve', { name: 'pending-chief' })+ assert.equal(items['pending-chief'].approved, true)const saved = JSON.parse(await (await import('node:fs/promises')).readFile(join(env.home, 'state.json'), 'utf8'))- assert.deepEqual(Object.keys(saved.capabilities.items).sort(), ['guide', 'shared', 'unused'])+ assert.equal(saved.capabilities.items['pending-mine'], undefined)+})++test('a deleted Bot leaves pack members and other packs untouched', async t => {+ const env = await setup({+ beforeLoad: ({ ctx }) => { ctx.workspaceRegistry = { archiveSession: async () => {} } },+ })+ t.after(() => env.dispose())+ const { rt } = env+ const { items } = rt.state.capabilities+ await rt.capabilitySave(mcp('pending-pack'), { botId: 'worker' })+ await rt.capabilitySave({ name: 'guide', kind: 'skill', description: 'Guide', content: 'Do the work.' }, { botId: 'worker' })+ // Two packs share the skill; only one was on the deleted Bot. The pending MCP+ // the Bot asked for also sits in its pack, so it belongs to the pack.+ await rt.capabilitySave({ name: 'pack-p', kind: 'pack', items: ['guide', 'pending-pack'] }, { botId: 'worker' })+ await rt.capabilitySave({ name: 'pack-q', kind: 'pack', items: ['guide'] }, { botId: 'chief' })+ rt.state.bots.worker.capabilities = ['pack-p', 'pending-pack']+ await rt.deleteBot('worker')+ assert.deepEqual(Object.keys(items).sort(), ['guide', 'pack-p', 'pack-q', 'pending-pack'])+ assert.deepEqual(items['pack-q'].items, ['guide'])+ assert.deepEqual(items['pack-p'].items, ['guide', 'pending-pack'])})test('read-only secret reload does not requeue capability reconciliation', async t => {