A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Page a group's earlier parts and resolve its rounds by part
Fei2411dfa0a31914eb
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 46ad9e2d..50ff7e98 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -8129,7 +8129,9 @@ function EarlierParts({ sessionId, roster, actions }) {const load = (cursor) => {if (busy.current) return;const mine = generation.current;- const partIndex = partIndexOf(roster.byId[sessionId], sessionId, cursor);+ const room2 = roster.roomsById[sessionId];+ const owner = roster.byId[sessionId] ?? (room2 === void 0 ? void 0 : { parts: room2.ownParts, sessionId: room2.sessionId });+ const partIndex = partIndexOf(owner, sessionId, cursor);busy.current = true;setView((current) => ({ ...current, loading: true, failed: false }));actions.earlier(sessionId, cursor).then((page) => {@@ -8235,6 +8237,20 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDel}case "btw":return (0, import_react16.createElement)(BtwCardView, { key, card: row.card, sessionId, actions, onDeleted: onBtwDelete });+ case "post": {+ const poster = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };+ return (0, import_react16.createElement)(GroupMessage, {+ key,+ bot: poster,+ text: row.file ? stripLongNote(row.text) : row.text,+ room: roster.roomsById[sessionId],+ roster,+ actions,+ msgKey: `${sessionId}:post:${row.seq ?? row.time}`,+ time: row.time,+ whole: row.file ? { length: row.length, load: () => actions.fileText(row.file) } : void 0+ });+ }case "event": {if (row.role === "report") return (0, import_react16.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };@@ -8277,7 +8293,7 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, usreturn unreadOpening ? (0, import_react16.createElement)(import_react16.Fragment, null, (0, import_react16.createElement)("div", { className: "bt-open-new" }, (0, import_react16.createElement)(NewDivider), (0, import_react16.createElement)("div", { className: "bt-time-sep", role: "separator" }, unreadOpening)), body) : body;function triggerBody() {if (source.kind === "bot") {- if (source.handoff === true) return roster.roomsById[sessionId] ? null : (0, import_react16.createElement)(EarlierParts, { sessionId, roster, actions });+ if (source.handoff === true) return (0, import_react16.createElement)(EarlierParts, { sessionId, roster, actions });if (source.role === "kickoff" || source.role === "room") return null;if (source.role === "secret" || deferred) return null;if (source.role === "update") return (0, import_react16.createElement)("div", { className: "bt-event" }, t("Profile updated"));diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 834e30d2..770b2be9 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -428,8 +428,11 @@ function EarlierParts({ sessionId, roster, actions }) {const load = (cursor) => {if (busy.current) returnconst mine = generation.current- // The host numbers a page by the same part index: cursor.part, or the part before this one.- const partIndex = partIndexOf(roster.byId[sessionId], sessionId, cursor)+ // The host numbers a page by the same part index: cursor.part, or the part+ // before this one. A group's own Session chains `room.ownParts` + `sessionId`.+ const room = roster.roomsById[sessionId]+ const owner = roster.byId[sessionId] ?? (room === undefined ? undefined : { parts: room.ownParts, sessionId: room.sessionId })+ const partIndex = partIndexOf(owner, sessionId, cursor)busy.current = truesetView(current => ({ ...current, loading: true, failed: false }))actions.earlier(sessionId, cursor).then((page) => {@@ -535,6 +538,15 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelreturn speaker ? h(Fragment, { key }, h(SpeakerHead, { bot: speaker, time: row.time }), bubbles) : bubbles}case 'btw': return h(BtwCardView, { key, card: row.card, sessionId, actions, onDeleted: onBtwDelete })+ case 'post': {+ // A member's message in a group's earlier part, as the live row shows it.+ const poster = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }+ return h(GroupMessage, {+ key, bot: poster, text: row.file ? stripLongNote(row.text) : row.text, room: roster.roomsById[sessionId], roster, actions,+ msgKey: `${sessionId}:post:${row.seq ?? row.time}`, time: row.time,+ whole: row.file ? { length: row.length, load: () => actions.fileText(row.file) } : undefined,+ })+ }case 'event': {if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }@@ -586,7 +598,7 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClfunction triggerBody() {if (source.kind === 'bot') {// A part opens with its handoff package, so the earlier parts go right above it.- if (source.handoff === true) return roster.roomsById[sessionId] ? null : h(EarlierParts, { sessionId, roster, actions })+ if (source.handoff === true) return h(EarlierParts, { sessionId, roster, actions })// Group turns belong to the group chat; the member's own chat stays one-to-one.if (source.role === 'kickoff' || source.role === 'room') return null// The secret card itself shows what the user did; the note to the Bot stays out.diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.jsindex 584be6bc..6ea4d53e 100644--- a/ds-bot/src/host/channel.js+++ b/ds-bot/src/host/channel.js@@ -227,8 +227,11 @@ export function install(rt) {case 'usage':await rt.load()return ok(await rt.usageView({ timeZone: typeof body.timeZone === 'string' ? body.timeZone.slice(0, 64) : undefined }))- case 'room-progress':- return ok([...rt.roomProgress.entries()].filter(([, entry]) => entry.roomId === body.roomId).map(([callId, entry]) => ({ callId, replies: entry.replies, speaking: entry.slots.filter(slot => slot.status === 'speaking').map(slot => slot.id) })))+ case 'room-progress': {+ // Any part id of the group's own Session means the group itself.+ const room = rt.roomOf(body.roomId) ?? rt.roomOf(rt.pastOwners.get(body.roomId)?.roomId)+ return ok([...rt.roomProgress.entries()].filter(([, entry]) => entry.roomId === (room?.id ?? body.roomId)).map(([callId, entry]) => ({ callId, replies: entry.replies, speaking: entry.slots.filter(slot => slot.status === 'speaking').map(slot => slot.id) })))+ }case 'create-bot': {await rt.bootstrap()const bot = await rt.createBot({ name: body.name, role: body.role, color: body.color, instructions: body.instructions, brief: body.brief, avatar: body.avatar, model: body.model, effort: body.effort, workDir: body.workDir })diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex 273f9118..0a29d87a 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -1327,6 +1327,19 @@ export function install(rt) {if (reply?.questions !== undefined) stamp(event, { kind: 'answer', questions: reply.questions, answers: reply.answers, time: event.time })else if (reply?.handoff !== undefined) stamp(event, { kind: 'answer', text: replyText(text), handoff: reply.handoff, time: event.time })else if (reply?.views !== undefined) stamp(event, { kind: 'answer', text: replyText(text), views: reply.views, answers: reply.answers, time: event.time })+ } else if (source?.kind === SOURCE_KIND && source.role === 'post') {+ // A group's own Session reads as one conversation: member posts are its+ // messages. A post past what a message holds came as a file, with its start.+ const content = Array.isArray(event.data.content) ? event.data.content : []+ const file = source.length === undefined ? undefined : content.find(block => block?.type === 'file')?.attachment+ stamp(event, {+ kind: 'post',+ botId: source.senderSessionId ?? null,+ name: source.senderName ?? null,+ text: textOf(content).replace(/^\[Group post from (?:[^\r\n]*\]\r?\n|[^\]\r\n]*\])/, ''),+ ...(file ? { file, length: source.length } : {}),+ time: event.time,+ })} else if (source?.kind === SOURCE_KIND && source.handoff !== true && source.deferred !== true && ['request', 'reply', 'report', 'stopped'].includes(source.role)) {stamp(event, { kind: 'event', role: source.role, botId: source.senderSessionId ?? null, name: source.senderName ?? null, roomId: source.roomId ?? null, time: event.time })}@@ -1377,14 +1390,17 @@ export function install(rt) {async function earlierPage(sessionId, cursor) {const past = rt.pastOwners.get(sessionId)- const botId = rt.chatOwners.get(sessionId) ?? (past?.roomId === undefined ? past?.botId : undefined)- const parts = botId === undefined ? [] : partsOf(botId)+ // A group's own Session is its own chain of parts like a Bot's own chat: its+ // current Session and every earlier `room.parts` page the same "Load earlier".+ const roomId = rt.roomOwners?.get(sessionId) ?? (past?.botId === undefined ? past?.roomId : undefined)+ const botId = roomId === undefined ? rt.chatOwners.get(sessionId) ?? (past?.roomId === undefined ? past?.botId : undefined) : undefined+ const parts = roomId === undefined ? (botId === undefined ? [] : partsOf(botId)) : partsOf(undefined, roomId)const at = parts.findIndex(part => part.sessionId === sessionId)const index = Number.isInteger(cursor?.part) ? cursor.part : at - 1if (at <= 0 || index < 0 || index >= at) return { items: [], cursor: null, startedAt: parts[at]?.startedAt ?? null }// Aside cards belong to the part that was current when they were asked, so// they ride along with that part's history instead of the team view.- const btw = (await rt.btwPartCards?.(botId, parts[index].sessionId)) ?? []+ const btw = botId === undefined ? [] : (await rt.btwPartCards?.(botId, parts[index].sessionId)) ?? []return { ...(await partPage(parts, index, cursor)), btw, startedAt: parts[at].startedAt }}diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 3d1c19c4..65f5d36f 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -843,6 +843,16 @@ const step = (host, sessionId, said, callId, name = 'pwsh', args = '{}') => {}const progress = async host => (await host.call('room-progress', { roomId: 'r1' })).value[0]+test('room-progress answers for any part of the group\'s own Session', async (t) => {+ // The group's own Session moved on once: 'r1' is the group's id and an earlier+ // part, 's1' its current one; rounds are still keyed by the group's id.+ const host = await start(t, { sessionId: 's1', parts: [{ sessionId: 'r1', endedAt: 1 }] })+ host.round('c1', host.say('@Writer 整理文档'))+ await settle(() => host.agentOf('gb').calls.length === 1)+ assert.equal((await host.call('room-progress', { roomId: 's1' })).value[0]?.callId, 'c1')+ assert.equal((await host.call('room-progress', { roomId: 'r1' })).value[0]?.callId, 'c1')+})+test('what a member writes while it works shows in the round at once, and its @ calls members', async (t) => {const host = await start(t)const result = host.round('c1', host.say('@Writer 整理文档'))diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex e7b78dd2..08a9c04b 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -1039,6 +1039,24 @@ test('a group folder change moves the group\'s own Session to a part in the foldassert.equal(state().rooms.r1.id, 'r1')})+test('a group\'s earlier parts page like a Bot\'s own chat', async (t) => {+ const { ctx, call, project, state, stop } = await start()+ t.after(stop)+ // The earlier part's record carries the group's posts as user/message events.+ ctx.sessionController.page = async ({ address }) => (address?.sessionId === 'r1'+ ? { records: [{ event: { type: 'user/message', seq: 2, time: 2, data: { content: [{ type: 'text', text: '[Group post from Writer]\nDone.' }], source: { kind: 'bot', role: 'post', senderSessionId: 'gb', senderName: 'Writer' } } } }], hasMore: false }+ : { records: [], hasMore: false })+ assert.equal((await call('update-room', { id: 'r1', workDir: project })).ok, true)+ await until(() => state().rooms.r1.sessionId === 's1')+ // The current part's earlier page reads the part it moved on from.+ const page = (await call('earlier', { sessionId: 's1' })).value+ assert.deepEqual(page.items.map(item => [item.kind, item.name, item.text]), [['post', 'Writer', 'Done.']])+ assert.equal(page.cursor, null)+ assert.equal(typeof page.startedAt, 'number')+ // The first part itself has nothing before it.+ assert.deepEqual((await call('earlier', { sessionId: 'r1' })).value.items, [])+})+test('the file panel of a group with a folder lists the Session\'s own folder', async (t) => {// DSH's file panel lists a Session at the folder the Session was made in, so no// lookup override is needed once the group's own Session moved there.