Skip to content

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

Keep a Bot's schedule tools to its own chat's tasks

Fei241130b039fa39c2
diff --git a/ds-bot/src/host/schedules.js b/ds-bot/src/host/schedules.js
index 533b1924..b06010fc 100644
--- a/ds-bot/src/host/schedules.js
+++ b/ds-bot/src/host/schedules.js
@@ -45,6 +45,9 @@ const hostWide = service => typeof service.edit === 'function'
// The existing Session a task delivers to; a task that opens new Sessions has none.
const sessionOf = entry => entry.target === undefined ? entry.sessionId : entry.target.kind === 'session' ? entry.target.sessionId : undefined
const TIMING_KINDS = { at: 'at', every_seconds: 'every', daily: 'daily', weekly: 'weekly' }
+const OWN_TASK_TOOLS = ['schedule_edit', 'schedule_view']
+const 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.roomId
const timingOf = (selector) => {
const [key] = Object.keys(selector)
return { kind: TIMING_KINDS[key], [key]: selector[key] }
@@ -182,5 +185,21 @@ export function install(rt) {
}
}
+ // DSH 0.2.2's task ids are Host-wide, so a Bot's schedule tools reach only the tasks
+ // that deliver to its own chat, or to the same group place, in any of its parts.
+ ctx.on('tools/pre-execute', async (exec, next) => {
+ const decision = await next()
+ if (decision.kind !== 'allow' || !OWN_TASK_TOOLS.includes(exec.name) || service === null || !hostWide(service)) return decision
+ await rt.load()
+ const caller = exec.agent?.id
+ if (!rt.isBotSession(caller)) return decision
+ const entry = (await service.catalog()).find(task => task.id === exec.arguments?.id)
+ // An unknown id gets DSH's own not-found result.
+ if (entry === undefined) return decision
+ const target = sessionOf(entry)
+ if (target !== undefined && sameOwner(ownerOf(caller), ownerOf(target))) return decision
+ return { kind: 'deny', reason: OTHER_TASK_REFUSAL }
+ })
+
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.js
index fbdbba29..a84f9fb9 100644
--- a/ds-bot/test/install.test.js
+++ b/ds-bot/test/install.test.js
@@ -90,6 +90,7 @@ test('apply registers listeners and effects in a fixed order', (t) => {
'effect ds-bot: capabilities',
'on agent/status',
'effect ds-bot: learning',
+ 'on tools/pre-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.js
index 23d46405..b5695484 100644
--- a/ds-bot/test/schedules.test.js
+++ b/ds-bot/test/schedules.test.js
@@ -199,6 +199,28 @@ test('on DSH 0.2.2 tasks target the Bot’s current part, list by target, delete
assert.deepEqual(schedule.edits.at(-1), { id: 'schedule-2', action: 'delete' })
})
+// DSH 0.2.2's task ids are Host-wide, so schedule_edit could reach another Bot's task.
+test('on DSH 0.2.2 a Bot reads and changes only the tasks of its own chat', async (t) => {
+ const schedule = hostSchedule()
+ const { ctx, home, rt } = setup({ schedule })
+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })
+ await rt.load()
+ schedule.tasks.set('own', { record: { id: 'own', kind: 'at', title: 'Mine', prompt: 'x', scheduledAt: '2030-01-01T00:00:00.000Z' }, target: { kind: 'session', sessionId: 'w1' }, status: 'active' })
+ schedule.tasks.set('chief', { record: { id: 'chief', kind: 'at', title: 'Chief', prompt: 'x', scheduledAt: '2030-01-01T00:00:00.000Z' }, target: { kind: 'session', sessionId: 'm1' }, status: 'active' })
+ schedule.tasks.set('elsewhere', { record: { id: 'elsewhere', kind: 'at', title: 'New', prompt: 'x', scheduledAt: '2030-01-01T00:00:00.000Z' }, target: { kind: 'new_once' }, status: 'active' })
+ const [gate] = ctx.listeners.get('tools/pre-execute')
+ const check = (name, id, sessionId) => gate({ name, arguments: { id, action: 'delete' }, agent: { id: sessionId } }, async () => ({ kind: 'allow' }))
+ assert.deepEqual(await check('schedule_edit', 'own', 'w2'), { kind: 'allow' })
+ assert.deepEqual(await check('schedule_view', 'own', 'w2'), { kind: 'allow' })
+ for (const id of ['chief', 'elsewhere']) {
+ for (const name of ['schedule_edit', 'schedule_view']) assert.equal((await check(name, id, 'w2')).kind, 'deny')
+ }
+ assert.deepEqual(await check('schedule_edit', 'chief', 'm1'), { kind: 'allow' })
+ assert.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' })
+})
+
test('a failed task move can resume without losing identical remaining tasks', async (t) => {
const schedule = scheduleService()
const { ctx, home, rt } = setup({ schedule })