A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
End a part-switch step as completed before its first step
Fei241159f7caca9cec
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex fa6d15f3..ed56e687 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -1040,6 +1040,14 @@ export function install(rt) {carried.recent.length, carried.earlier.length, folder === undefined ? '' : `; now works in ${folder}`)}+ // Ends a step DS Bot takes over. Before a turn's first step an empty batch ends the+ // turn as completed, where a reject ends it as blocked, which other listeners read as+ // a failure. Later in a turn an empty batch would run another model step, and a turn+ // carried through a steer cut keeps its reject, since a completed turn reads as answered.+ const takeOverStep = (agent, payload) => (payload.step === 1 && rt.live.get(agent.id)?.carried !== true+ ? { kind: 'enter', messages: [] }+ : { kind: 'reject' })+// Runs first: an earlier part hands its input on, a part past the hard line makes// room before the step (condensed in place, or it stops and goes on in a fresh// part), and the backend's own pre-step listener sees the wrapper.@@ -1049,14 +1057,14 @@ export function install(rt) {const past = rt.pastOwners.get(agent.id)if (past !== undefined && !rt.isBotSession(agent.id)) {await forward(past, payload.messages).catch(error => rt.warn('ds-bot: input for %s was not handed on: %s', agent.id, error))- return { kind: 'reject' }+ return takeOverStep(agent, payload)}if (!rt.isBotSession(agent.id)) return next()adoptCompaction(agent)const job = switches.get(agent.id)if (job !== undefined) {job.carry.push(...payload.messages)- return { kind: 'reject' }+ return takeOverStep(agent, payload)}const fresh = freshParts.get(agent.id)if (fresh !== undefined) {@@ -1078,7 +1086,7 @@ export function install(rt) {const running = switches.get(agent.id)if (running !== undefined) {running.carry.push(...payload.messages)- return { kind: 'reject' }+ return takeOverStep(agent, payload)}const entry = rt.liveOf(agent.id)// A turn carried through a steer cut keeps its trigger and joined work, so@@ -1086,7 +1094,7 @@ export function install(rt) {const midTurn = payload.step > 1 || entry.carried === trueentry.switched = truestartSwitch(agent, { resume: midTurn, carry: payload.messages, info: midTurn ? entry.info : undefined, joined: midTurn ? [...(entry.joined ?? [])] : undefined, ...options })- return { kind: 'reject' }+ return takeOverStep(agent, payload)}// The folder a part should move to, when it is not the one the part was made in. Adiff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.jsindex 5bacc2d7..57e56b6e 100644--- a/ds-bot/test/bot-messages.test.js+++ b/ds-bot/test/bot-messages.test.js@@ -1121,7 +1121,7 @@ for (const id of ['b', 'gb']) {if (pending) {const decision = await ctx.listeners.get('agent/pre-step').at(-1)({ agent, messages: [input], step: 1, signal: AbortSignal.timeout(60_000) }, async () => 'next')- assert.deepEqual(decision, { kind: 'reject' })+ assert.deepEqual(decision, { kind: 'enter', messages: [] })} else {record('user/message', input)await fire('agent/request-error', { agent, failure: { code: 'CONTEXT_WINDOW_EXCEEDED' }, signal: AbortSignal.timeout(60_000) })diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex d0f32db7..e25e3609 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -240,7 +240,7 @@ test('a running Bot moves at its next step and carries that step\'s input along'assert.deepEqual(created, [])const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Now build it' }], source: { kind: 'user' } }- assert.deepEqual(await preStep('b', [input]), { kind: 'reject' })+ assert.deepEqual(await preStep('b', [input]), { kind: 'enter', messages: [] })await until(() => state().bots.b.sessionId === 's1')assert.deepEqual(created, [{ cwd: project }])await until(() => agentOf('s1').calls.length >= 2)@@ -293,7 +293,7 @@ test('a group\'s folder holds for every member there; only the user or a Main Boassert.equal(await preStep('b'), 'next')assert.equal(await preStep('gb', [], 2), 'next')assert.deepEqual(created, [])- assert.deepEqual(await preStep('gb'), { kind: 'reject' })+ assert.deepEqual(await preStep('gb'), { kind: 'enter', messages: [] })await until(() => state().rooms.r1.sessions.b === 's1')assert.deepEqual(created, [{ cwd: project }])assert.equal(state().bots.b.sessionId, 'b')@@ -342,7 +342,7 @@ test('a group\'s permissions hold for every member there in place of its own, un// A fresh part of the group conversation starts on the group's preset.await call('update-room', { id: 'r1', workDir: project })- assert.deepEqual(await preStep('gb'), { kind: 'reject' })+ assert.deepEqual(await preStep('gb'), { kind: 'enter', messages: [] })await until(() => state().rooms.r1.sessions.b === 's1')assert.equal(presetOf.get('s1'), 'read-only')@@ -558,7 +558,7 @@ test('a Bot whose folder is gone changes to the team folder before DSH checks it// of the change is about the old part, so it stays behind.const notice = { id: 'm0', role: 'user', content: [{ type: 'text', text: 'The working directory is now the team folder.' }], source: { kind: 'working-directory' } }const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Still there?' }], source: { kind: 'user' } }- assert.deepEqual(await preStep('s1', [notice, input]), { kind: 'reject' })+ assert.deepEqual(await preStep('s1', [notice, input]), { kind: 'enter', messages: [] })await until(() => state().bots.b.sessionId === 's2')assert.deepEqual(created.at(-1), { workspaceId: 'w1' })await until(() => agentOf('s2').calls.length >= 2)@@ -582,7 +582,7 @@ test('a team copied from another DSH_HOME moves on to a fresh part in the folderrmSync(root, { recursive: true, force: true })})const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Hello again' }], source: { kind: 'user' } }- assert.deepEqual(await preStep('b', [input]), { kind: 'reject' })+ assert.deepEqual(await preStep('b', [input]), { kind: 'enter', messages: [] })await until(() => state().bots.b.sessionId === 's1')assert.equal(state().workspaceId, 'w-new')assert.deepEqual(created, [{ workspaceId: 'w-new' }])@@ -600,7 +600,7 @@ test('the user moves the team workspace, and Bots without a folder of their ownassert.equal(state().workspaceId, 'w-new')assert.equal(existsSync(team), true)const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Hello again' }], source: { kind: 'user' } }- assert.deepEqual(await preStep('b', [input]), { kind: 'reject' })+ assert.deepEqual(await preStep('b', [input]), { kind: 'enter', messages: [] })await until(() => state().bots.b.sessionId !== 'b')assert.equal(agentOf(state().bots.b.sessionId).session.header.cwd, moved)assert.deepEqual(created.at(-1), { workspaceId: 'w-new' })@@ -608,6 +608,54 @@ test('the user moves the team workspace, and Bots without a folder of their ownassert.equal(state().bots.a.workDir, project)})+// The handoff note takes a while; the move waits in `runMaintenance` until the test releases it.+const holdMove = (agent) => {+ const run = agent.runMaintenance+ let release+ const held = new Promise(resolve => { release = resolve })+ agent.runMaintenance = async (job) => { await held; return run.call(agent, job) }+ return release+}++test('a folder move that a first message starts is flagged in the work view until the part moves on', async (t) => {+ const { root, agentOf, call, state, preStep, stop } = await start()+ t.after(stop)+ const moved = join(root, 'moved')+ await call('team-workspace', { path: moved })+ const release = holdMove(agentOf('b'))+ const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Hello again' }], source: { kind: 'user' } }+ assert.deepEqual(await preStep('b', [input]), { kind: 'enter', messages: [] })+ const work = (await call('state', {})).value.work.bots.b+ assert.deepEqual([work.switching, work.folder], [true, true])+ release()+ await until(() => state().bots.b.sessionId === 's1')+ await until(() => agentOf('s1').calls.length >= 2)+ assert.deepEqual(agentOf('s1').calls.map(([kind, message]) => [kind, message.source.role ?? textOf(message)]), [['followup', 'handoff'], ['followup', 'Hello again']])+})++test('input that arrives while a switch runs ends its turn as completed and goes on to the new part', async (t) => {+ const { root, agentOf, call, state, preStep, stop } = await start()+ t.after(stop)+ await call('team-workspace', { path: join(root, 'moved') })+ const release = holdMove(agentOf('b'))+ const said = text => ({ role: 'user', content: [{ type: 'text', text }], source: { kind: 'user' } })+ assert.deepEqual(await preStep('b', [said('Hello again')]), { kind: 'enter', messages: [] })+ assert.deepEqual(await preStep('b', [said('and one more')]), { kind: 'enter', messages: [] })+ release()+ await until(() => state().bots.b.sessionId === 's1')+ await until(() => agentOf('s1').calls.length >= 3)+ assert.deepEqual(agentOf('s1').calls.map(([kind, message]) => [kind, message.source.role ?? textOf(message)]), [['followup', 'handoff'], ['followup', 'Hello again'], ['followup', 'and one more']])+})++test('a switch that starts mid-turn still rejects its step, the only way DSH ends a step there', async (t) => {+ const { root, state, call, preStep, stop } = await start()+ t.after(stop)+ await call('team-workspace', { path: join(root, 'moved') })+ const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Hello again' }], source: { kind: 'user' } }+ assert.deepEqual(await preStep('b', [input], 2), { kind: 'reject' })+ await until(() => state().bots.b.sessionId === 's1')+})+test('the team workspace holds no DeepSeek Harness data, apart from the plugin\'s own default', async (t) => {const { root, dsh, home, team, state, call, stop } = await start()t.after(stop)@@ -808,7 +856,7 @@ test('a Bot that changes to a folder outside its working folder makes it its worassert.equal(state().bots.b.workDir, project)const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Now build it' }], source: { kind: 'user' } }- assert.deepEqual(await preStep('b', [input]), { kind: 'reject' })+ assert.deepEqual(await preStep('b', [input]), { kind: 'enter', messages: [] })await until(() => state().bots.b.sessionId === 's1')assert.deepEqual(created, [{ cwd: project }])await until(() => handoffOf(agentOf('s1')) !== undefined)