A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Drop shared capabilities left holderless by a deleted Bot
Fei2411c11dcbf5b5a6
diff --git a/ds-bot/src/host/capabilities.js b/ds-bot/src/host/capabilities.jsindex 8807be25..66e377b5 100644--- a/ds-bot/src/host/capabilities.js+++ b/ds-bot/src/host/capabilities.js@@ -152,6 +152,21 @@ 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) => {+ 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 item = own(items, name)+ if (item === undefined || usedByOthers(name)) continue+ delete 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) => {await rt.load()writeCheck()@@ -515,6 +530,7 @@ export function install(rt) {Object.assign(rt, {capabilitySave,capabilityDelete,+ dropOrphanCapabilities,capabilityEndpoint,capabilityLibraryView: libraryView,capabilityStatusesView,diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex 7f6b59bd..bd36c1ec 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -648,6 +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)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 39a96156..3e8302ec 100644--- a/ds-bot/test/capabilities.test.js+++ b/ds-bot/test/capabilities.test.js@@ -176,6 +176,28 @@ 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 => {+ 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']+ 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/)+ 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'])+})+test('read-only secret reload does not requeue capability reconciliation', async t => {const env = await setup()t.after(() => env.dispose())