A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
List only a Bot's own scheduled tasks
Fei24112048953050bb
diff --git a/ds-bot/src/host/schedules.js b/ds-bot/src/host/schedules.jsindex b06010fc..1fa3b028 100644--- a/ds-bot/src/host/schedules.js+++ b/ds-bot/src/host/schedules.js@@ -46,6 +46,9 @@ const hostWide = service => typeof service.edit === 'function'const sessionOf = entry => entry.target === undefined ? entry.sessionId : entry.target.kind === 'session' ? entry.target.sessionId : undefinedconst TIMING_KINDS = { at: 'at', every_seconds: 'every', daily: 'daily', weekly: 'weekly' }const OWN_TASK_TOOLS = ['schedule_edit', 'schedule_view']+// DSH 0.2.2's list page: 100 by default, at most 500.+const LIST_PAGE = 100+const LIST_READ_LIMIT = 500const OTHER_TASK_REFUSAL = 'This task belongs to another chat. A Bot reads and changes only the tasks of its own chat.'const sameOwner = (a, b) => a !== undefined && b !== undefined && a.botId === b.botId && a.roomId === b.roomIdconst timingOf = (selector) => {@@ -200,6 +203,31 @@ 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.+ 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) : undefined+ if (own === undefined) return next()+ const asked = exec.arguments ?? {}+ exec.arguments = { ...asked, limit: LIST_READ_LIMIT, offset: 0 }+ let result+ try {+ result = await next()+ } finally {+ 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 } }+ })Object.assign(rt, { scheduleEndpoint: (endpoint, body) => endpoints[endpoint](body ?? {}), moveSchedules })}diff --git a/ds-bot/test/install.test.js b/ds-bot/test/install.test.jsindex a84f9fb9..ab5d6ede 100644--- a/ds-bot/test/install.test.js+++ b/ds-bot/test/install.test.js@@ -91,6 +91,7 @@ test('apply registers listeners and effects in a fixed order', (t) => {'on agent/status','effect ds-bot: learning','on tools/pre-execute',+ 'on tools/execute','effect ds-bot: usage ledger','on llm/stream','effect ds-bot: update check',diff --git a/ds-bot/test/schedules.test.js b/ds-bot/test/schedules.test.jsindex b5695484..f5178a32 100644--- a/ds-bot/test/schedules.test.js+++ b/ds-bot/test/schedules.test.js@@ -219,6 +219,26 @@ test('on DSH 0.2.2 a Bot reads and changes only the tasks of its own chat', asynassert.deepEqual(await check('schedule_edit', 'missing', 'w2'), { kind: 'allow' })assert.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.+ 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 = []+ 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 } }+ }).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'])+ assert.equal((await run('outside', {})).result.value.items.length, 4)})test('a failed task move can resume without losing identical remaining tasks', async (t) => {diff --git a/ds-bot/test/secrets.test.js b/ds-bot/test/secrets.test.jsindex 6755c2f8..af27a9ce 100644--- a/ds-bot/test/secrets.test.js+++ b/ds-bot/test/secrets.test.js@@ -302,8 +302,9 @@ test('tool results and model requests lose the values', async (t) => {t.after(bench.stop)const value = fresh()await bench.call('secret-set', { name: 'DEMO_TOKEN', value })- // The team tools' listener (working_directory) registers first.- const execute = bench.listeners['tools/execute'].at(-1)+ // The team tools' listener (working_directory) registers first; the schedule list's+ // registers after this one.+ const execute = bench.listeners['tools/execute'].filter(listener => listener.name !== 'listOwnSchedules').at(-1)const ok = await execute({}, async () => ({ isError: false, value: { kind: 'foreground', stdout: { text: `${value}\n`, truncated: false } }, content: [{ type: 'text', text: value }], meta: { stdout: value } }))assert.equal(ok.isError, false)assert.deepEqual(ok.value, { kind: 'foreground', stdout: { text: '[secret:DEMO_TOKEN]\n', truncated: false } })