A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Page a Bot's own scheduled tasks across the whole Host
Fei2411e1172118dbef
diff --git a/ds-bot/src/host/schedules.js b/ds-bot/src/host/schedules.jsindex 1fa3b028..ea1dabeb 100644--- a/ds-bot/src/host/schedules.js+++ b/ds-bot/src/host/schedules.js@@ -203,15 +203,30 @@ export function install(rt) {if (target !== undefined && sameOwner(ownerOf(caller), ownerOf(target))) return decisionreturn { kind: 'deny', reason: OTHER_TASK_REFUSAL }})- // The Host-wide list is read in one widest page and narrowed to the caller's own- // tasks; the page the Bot asked for is then cut from those.+ // schedule_list pages over every Host task and cannot filter by Session, and only the+ // tool formats its items. So the tool is asked for the Host range that holds the+ // caller's page (catalog() keeps list()'s order), and the other chats' tasks in that+ // range are dropped. A page whose tasks span more than one Host page comes back+ // short; total still counts all of the caller's tasks, so the next offset goes on.ctx.on('tools/execute', async function listOwnSchedules(exec, next) {if (exec.name !== 'schedule_list' || service === null || !hostWide(service)) return next()await rt.load()const own = rt.isBotSession(exec.agent?.id) ? ownerOf(exec.agent.id) : undefinedif (own === undefined) return next()const asked = exec.arguments ?? {}- exec.arguments = { ...asked, limit: LIST_READ_LIMIT, offset: 0 }+ const limit = asked.limit ?? LIST_PAGE+ const offset = asked.offset ?? 0+ // An invalid page gets DSH's own input error.+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > LIST_READ_LIMIT || !Number.isSafeInteger(offset) || offset < 0) return next()+ const mine = entry => {+ const target = sessionOf(entry)+ return target !== undefined && sameOwner(own, ownerOf(target))+ }+ const pool = (await service.catalog()).filter(entry => asked.active === undefined || (entry.status === 'active') === asked.active)+ const positions = pool.flatMap((entry, at) => (mine(entry) ? [at] : []))+ const page = positions.slice(offset, offset + limit)+ const from = page[0] ?? pool.length+ exec.arguments = { ...asked, offset: from, limit: page.length === 0 ? 1 : Math.min(LIST_READ_LIMIT, page.at(-1) - from + 1) }let resulttry {result = await next()@@ -219,14 +234,8 @@ export function install(rt) {exec.arguments = asked}if (result.isError || !Array.isArray(result.value?.items)) return result- const mine = result.value.items.filter(item => {- const target = sessionOf(item)- return target !== undefined && sameOwner(own, ownerOf(target))- })- const limit = asked.limit ?? LIST_PAGE- const offset = asked.offset ?? 0- const items = mine.slice(offset, offset + limit)- return { ...result, value: { ...result.value, items, shown: items.length, total: mine.length, limit, offset } }+ const items = result.value.items.filter(mine).slice(0, limit)+ return { ...result, value: { ...result.value, items, shown: items.length, total: positions.length, limit, offset } }})Object.assign(rt, { scheduleEndpoint: (endpoint, body) => endpoints[endpoint](body ?? {}), moveSchedules })diff --git a/ds-bot/test/schedules.test.js b/ds-bot/test/schedules.test.jsindex f5178a32..381d6ea2 100644--- a/ds-bot/test/schedules.test.js+++ b/ds-bot/test/schedules.test.js@@ -220,24 +220,31 @@ test('on DSH 0.2.2 a Bot reads and changes only the tasks of its own chat', asynassert.deepEqual(await check('schedule_list', 'chief', 'w2'), { kind: 'allow' })assert.deepEqual(await check('schedule_edit', 'chief', 'outside'), { kind: 'allow' })- // schedule_list reads the widest Host page and keeps the caller's own tasks.- // Other modules wrap tools/execute too.+ // schedule_list asks the tool for the Host range that holds the caller's page and+ // keeps the caller's own tasks. Other modules wrap tools/execute too.+ schedule.tasks.set('own2', { record: { id: 'own2', kind: 'at', title: 'Mine too', prompt: 'x', scheduledAt: '2030-01-01T00:00:00.000Z' }, target: { kind: 'session', sessionId: 'w2' }, status: 'active' })const list = ctx.listeners.get('tools/execute').find(listener => listener.name === 'listOwnSchedules')- const item = (id, target) => ({ id, title: id, target })- const host = [item('a', { kind: 'session', sessionId: 'w1' }), item('b', { kind: 'session', sessionId: 'm1' }), item('c', { kind: 'session', sessionId: 'w2' }), item('d', { kind: 'new_once' })]const asked = []+ // The tool's own page: the catalog order, cut at offset and limit.const run = (sessionId, args) => {const exec = { name: 'schedule_list', arguments: args, agent: { id: sessionId } }return list(exec, async () => {asked.push(exec.arguments)- return { isError: false, value: { items: host, shown: host.length, total: host.length, limit: exec.arguments.limit ?? 100, offset: exec.arguments.offset ?? 0 } }+ const { limit = 100, offset = 0 } = exec.arguments+ const all = (await schedule.catalog()).map(entry => ({ id: entry.id, title: entry.title, target: entry.target }))+ const items = all.slice(offset, offset + limit)+ return { isError: false, value: { items, shown: items.length, total: all.length, limit, offset } }}).then(result => ({ result, args: exec.arguments }))}- const writer = await run('w2', { active: true, limit: 1, offset: 1 })- assert.deepEqual(asked.at(-1), { active: true, limit: 500, offset: 0 })- assert.deepEqual(writer.args, { active: true, limit: 1, offset: 1 })- assert.deepEqual(writer.result.value, { items: [host[2]], shown: 1, total: 2, limit: 1, offset: 1 })- assert.deepEqual((await run('m1', {})).result.value.items.map(task => task.id), ['b'])+ const second = await run('w2', { active: true, limit: 1, offset: 1 })+ assert.deepEqual(asked.at(-1), { active: true, limit: 1, offset: 3 })+ assert.deepEqual(second.args, { active: true, limit: 1, offset: 1 })+ assert.deepEqual(second.result.value, { items: [{ id: 'own2', title: 'Mine too', target: { kind: 'session', sessionId: 'w2' } }], shown: 1, total: 2, limit: 1, offset: 1 })+ const both = await run('w2', {})+ assert.deepEqual(asked.at(-1), { limit: 4, offset: 0 })+ assert.deepEqual(both.result.value.items.map(task => task.id), ['own', 'own2'])+ assert.deepEqual((await run('w2', { offset: 5 })).result.value, { items: [], shown: 0, total: 2, limit: 100, offset: 5 })+ assert.deepEqual((await run('m1', {})).result.value.items.map(task => task.id), ['chief'])assert.equal((await run('outside', {})).result.value.items.length, 4)})