A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Skip the Bot clock when DSH's own clock is loaded
FeiZhuLulub2de4c23f6b0
diff --git a/ds-bot/src/host/time-context.js b/ds-bot/src/host/time-context.jsindex fc695e6d..4aef4d72 100644--- a/ds-bot/src/host/time-context.js+++ b/ds-bot/src/host/time-context.js@@ -20,7 +20,10 @@ export function install(rt) {if (decision.kind === 'reject' || signal.aborted) return decisionawait rt.load()if (!rt.isBotSession(agent.id) || signal.aborted) return decision- // A preset may already supply DSH's clock for this step.+ // A loaded DSH clock covers every step itself. Its listener may run before or+ // after this one (a reload reorders them), so its presence is read from its+ // projection, not from the messages added so far.+ if (ctx.get?.('sessionProjections')?.stateOf(agent.session, 'timeContext') !== undefined) return decisionif (decision.messages.some(message => isClock(message.source))) return decisionconst now = Date.now()for await (const event of rt.eventsBackwards(agent.id, signal, Infinity)) {diff --git a/ds-bot/test/time-context.test.js b/ds-bot/test/time-context.test.jsindex 3d79601d..c0d5905a 100644--- a/ds-bot/test/time-context.test.js+++ b/ds-bot/test/time-context.test.js@@ -1,5 +1,8 @@import assert from 'node:assert/strict'+import { createRequire } from 'node:module'+import { join } from 'node:path'import { test } from 'node:test'+import { pathToFileURL } from 'node:url'import { install } from '../src/host/time-context.js'import { historyEntry } from '../src/host/parts.js'import { fakeContext } from './fake-ctx.js'@@ -65,6 +68,36 @@ test('native DSH readings, pending or persisted, do not get a second clock', asyassert.equal(await step(empty), empty)})+test('a loaded DSH clock gets no second clock in either listener order', async (t) => {+ t.mock.method(Date, 'now', () => NOW)+ // DSH's opt-in clock ships with the Web bundle, not the base one the plugin resolves from.+ const bundle = join(process.env.DSH_HARNESS, 'packages/bundle/web-app/package.json')+ const { apply: nativeClock } = await import(pathToFileURL(createRequire(bundle).resolve('@deepseek-ai/dsh-time-context')).href)+ const run = async (nativeFirst) => {+ const projections = new Map()+ const ctx = fakeContext({+ services: {+ sessionProjections: {+ register: (definition) => { projections.set(definition.key, definition) },+ stateOf: (_session, key) => projections.get(key)?.init(),+ },+ },+ })+ ctx.sessionProjections = ctx.get('sessionProjections')+ // Prepended listeners run last-registered first.+ ctx.on = (name, listener) => { ctx.listeners.set(name, [listener, ...(ctx.listeners.get(name) ?? [])]) }+ const rt = { ctx, config: { timeZone: 'UTC' }, load: async () => {}, isBotSession: () => true, async* eventsBackwards() {} }+ if (nativeFirst) { nativeClock(ctx, { timeZone: 'UTC' }); install(rt) } else { install(rt); nativeClock(ctx, { timeZone: 'UTC' }) }+ const hooks = ctx.listeners.get('agent/pre-step')+ const payload = { agent: { id: 'bot', session: { seq: 0, eventAt() {} } }, turn: 1, step: 1, signal: new AbortController().signal }+ const user = { role: 'user', content: [{ type: 'text', text: 'Hello' }], source: { kind: 'user' } }+ const invoke = at => at === hooks.length ? { kind: 'enter', messages: [user] } : hooks[at](payload, () => invoke(at + 1))+ return (await invoke(0)).messages.map(message => message.source.kind)+ }+ assert.deepEqual(await run(true), ['user', 'time-context'])+ assert.deepEqual(await run(false), ['user', 'time-context'])+})+test('an expired native DSH clock is refreshed when the preset no longer supplies one', async (t) => {const { step } = setup(t, { events: [reading(NOW - 600_000, 'time-context')] })assert.equal((await step()).messages.length, 2)