A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Root the group file panel at its folder without touching the Session header
Fei2411dc13ef52fbd6
diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.jsindex 9caad66b..e8bdeb56 100644--- a/ds-bot/src/host/folders.js+++ b/ds-bot/src/host/folders.js@@ -60,6 +60,26 @@ export function install(rt) {return workDirOf({ botId: rt.selfOf?.(id), roomId: rt.groupOwners?.get(id)?.roomId }) ?? teamFolder()}+ // The file panel lists a Session at its workspace root, which the workspaceFileScope+ // lookup resolves from the header the Session was made with; a group's relay Session+ // keeps that header after the group gets a folder. The declared resolver answers the+ // group's folder for the group's own Session, and every other Session goes back to the+ // provider's own resolution.+ const lookups = ctx.get?.('typert')?.lookups+ const files = lookups?.get?.('workspaceFileScope')+ if (files !== undefined) {+ try {+ lookups.configure('workspaceFileScope', async (id) => {+ await rt.load()+ const dir = rt.roomOf(id)?.workDir+ if (dir !== undefined && await isFolder(dir)) return { sessionId: id, workspaceRoot: dir }+ return files.resolve(id)+ })+ } catch (error) {+ rt.warn('ds-bot: group folders cannot be given to the file panel: %s', error)+ }+ }+// The desktop app runs its own DSH and names the user's, which Bots must not write either.const dataRoots = () => [rt.dshHome, rt.home, process.env.DS_BOT_USER_DSH_HOME?.trim()].filter(Boolean)diff --git a/ds-bot/src/host/privacy.js b/ds-bot/src/host/privacy.jsindex af080718..dc48b973 100644--- a/ds-bot/src/host/privacy.js+++ b/ds-bot/src/host/privacy.js@@ -316,8 +316,9 @@ export function install(rt) {}// Checks a change of `private` or of the folder of a Bot before it is written. A- // private Bot's folder is no other Bot's, no group's and not the team workspace,- // because DSH cannot be told which files of a shared folder to hide.+ // private Bot's folder is no other Bot's, no group's and not the team workspace —+ // a member's own pick in a group counts as that member's folder — because DSH+ // cannot be told which files of a shared folder to hide.async function checkChange(bot, { flag, moving, workDir }) {const makes = flag === undefined ? bot.private === true : flagconst dir = moving ? workDir : bot.workDir@@ -336,6 +337,9 @@ export function install(rt) {['the team workspace', teamFolder()],...Object.values(state.bots).filter(other => other.id !== bot.id && other.workDir).map(other => [`the folder of ${other.name}`, other.workDir]),...Object.values(state.rooms).filter(room => room.workDir).map(room => [`the folder of "${room.name}"`, room.workDir]),+ ...Object.values(state.rooms).flatMap(room => Object.entries(room.memberDirs ?? {})+ .filter(([member, dir]) => room.members.includes(member) && dir !== null)+ .map(([member, dir]) => [`the folder of ${rt.botOf(member)?.name ?? 'a member'} in "${room.name}"`, dir])),]for (const [what, path] of others) {const spelled = await spellings(path)diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex 6ff56232..e08a2a00 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -425,60 +425,10 @@ export function install(rt) {return holdName('room', custom, () => buildRoom({ members, custom, notice, mode, adminId, createdBy }))}- // A group's own Session already exists, so a folder change cannot make it again.- // The header is frozen and keys the log, so only the live header moves. `still`- // is false when a later change already picked another folder.- async function pointSession(sessionId, cwd, still) {- try {- const agent = await rt.resolveAgent(sessionId)- if (still !== undefined && !still()) return- const session = agent?.session- const header = session?.header- if (header === undefined || header.cwd === cwd) return- try {- header.cwd = cwd- } catch {- try {- session.header = { ...header, cwd }- } catch (error) {- rt.warn('ds-bot: group chat Session %s stays where it was; it could not move to %s: %s', sessionId, cwd, error)- }- }- } catch (error) {- rt.warn('ds-bot: group chat Session %s stays where it was; it could not move to %s: %s', sessionId, cwd, error)- }- }-- // The file tree reads this Session's cwd. The relay does not write there: its step- // is a synthesized group_relay, and a long line is stored under the team data.- // Members keep their own Sessions and move on to the folder at their next turn.- async function pointRoom(room) {- const dir = room.workDir- const usable = dir !== undefined && await rt.isFolder(dir)- if (room.workDir !== dir) return- const cwd = usable ? dir : await rt.keepTeamFolder()- if (room.workDir !== dir || cwd === undefined) return- await pointSession(room.id, cwd, () => room.workDir === dir)- }-- // Once per process, after the team is loaded: a restart reads the stored header.- let roomsPointed = null- function pointSavedRooms() {- roomsPointed ??= (async () => {- for (const room of Object.values(state.rooms)) {- if (room.workDir !== undefined) await pointRoom(room)- }- })().catch(error => {- roomsPointed = null- rt.warn('ds-bot: group chats could not be pointed at their folders: %s', error)- })- return roomsPointed- }-async function buildRoom({ members, custom, notice, mode, adminId, createdBy }) {const title = custom || autoRoomName(members)- // A new group has no folder yet, so its own Session starts in the team workspace.- // pointRoom moves that same Session when a folder is set.+ // The group's own Session only relays, so it stays in the team workspace; the+ // group's folder is for its members' Sessions.const id = await createSession(title)try {// A member deleted while the Session was made stays out, and the group is checked@@ -613,8 +563,6 @@ export function install(rt) {await retitleRoom(room)}await rt.save()- // After the folder is saved. A failure here leaves the setting in place.- if (moving) await pointRoom(room)return { room, changes }}@@ -739,8 +687,6 @@ export function install(rt) {async function bootstrap() {await rt.load()void rt.syncModels()- // Opening the group Sessions must not hold up the team view.- void pointSavedRooms()if (state.mainBotIds.some(id => rt.botOf(id))) return// Only the team's first Main Bot is stored as the DeepSeek whale; other Bots get a// look from their id, and a Bot made Main Bot later keeps its own.diff --git a/ds-bot/test/privacy.test.js b/ds-bot/test/privacy.test.jsindex 3107059f..bb4b8514 100644--- a/ds-bot/test/privacy.test.js+++ b/ds-bot/test/privacy.test.js@@ -10,7 +10,7 @@ import { fakeApproval, fakeContext } from './fake-ctx.js'const P = 'd1a40000-1111-4222-8333-444444444444'// Chief (Main), Writer in the group Ops, and Diary, a Bot with a folder of its own.-function seed({ diary, privateBot, archives = [] }) {+function seed({ diary, privateBot, archives = [], picked }) {return {version: 1,mainBotIds: ['a'],@@ -21,7 +21,7 @@ function seed({ diary, privateBot, archives = [] }) {b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 },[P]: { id: P, name: 'Diary', role: 'Notes', sessionId: P, createdAt: 3, instructions: 'Keep the diary of the user.', workDir: diary, ...(privateBot ? { private: true } : {}) },},- rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b'], mode: 'admin', admin: 'a', named: true, sessions: { b: 'gb' } } },+ rooms: { r1: { id: 'r1', name: 'Ops', members: ['a', 'b'], mode: 'admin', admin: 'a', named: true, sessions: { b: 'gb' }, ...(picked === undefined ? {} : { memberDirs: { b: picked } }) } },agents: {},exchanges: [],exchangeTurns: {},@@ -31,7 +31,7 @@ function seed({ diary, privateBot, archives = [] }) {}}-async function start({ services = {}, privateBot = true, archives } = {}) {+async function start({ services = {}, privateBot = true, archives, memberPick = false } = {}) {// The native realpath, as fs/promises uses: on Windows the JS one keeps 8.3 short names.const root = realpathSync.native(mkdtempSync(join(tmpdir(), 'ds-bot-privacy-')))const dsh = join(root, 'dsh')@@ -39,9 +39,10 @@ async function start({ services = {}, privateBot = true, archives } = {}) {const team = join(home, 'workspace')const project = join(root, 'project')const diary = join(root, 'diary')- for (const dir of [team, project, diary]) mkdirSync(dir, { recursive: true })+ const picked = join(root, 'picked')+ for (const dir of [team, project, diary, ...(memberPick ? [picked] : [])]) mkdirSync(dir, { recursive: true })writeFileSync(join(diary, 'notes.txt'), 'secret')- writeFileSync(join(home, 'state.json'), JSON.stringify(seed({ diary, privateBot, archives })))+ writeFileSync(join(home, 'state.json'), JSON.stringify(seed({ diary, privateBot, archives, picked: memberPick ? picked : undefined })))const previousHome = process.env.DSH_HOMEprocess.env.DSH_HOME = dsh@@ -119,7 +120,7 @@ async function start({ services = {}, privateBot = true, archives } = {}) {}// Loading once fills the Session-owner indexes.await tool('list_bots', {}, 'a')- return { rt, ctx, root, dsh, home, team, project, diary, agentOf, call, tool, run, state, stop }+ return { rt, ctx, root, dsh, home, team, project, diary, picked, agentOf, call, tool, run, state, stop }}const CLOSED = /private Bot/@@ -174,6 +175,22 @@ test('a private Bot has a folder that no other folder is in or around', async (tassert.equal(state().bots.b.workDir, project)})+test('a member\'s folder pick in a group counts as that member\'s folder for a private Bot', async (t) => {+ const { rt, picked, diary, run, state, stop } = await start({ privateBot: false, memberPick: true })+ t.after(stop)+ mkdirSync(join(picked, 'inside'))+ // Writer picked this folder for its conversation in Ops, so it is closed to Diary too.+ await assert.rejects(rt.updateBot(P, { private: true, workDir: picked }), /folder of Writer in "Ops"/)+ await assert.rejects(rt.updateBot(P, { private: true, workDir: join(picked, 'inside') }), /folder of Writer in "Ops"/)+ await rt.updateBot(P, { private: true, workDir: diary })+ assert.equal(state().bots[P].private, true)+ // The other way around too: the member cannot move that conversation into a+ // private Bot's folder.+ const moved = await run('working_directory', { cd: diary }, 'gb')+ assert.equal(moved.ran, false)+ assert.match(moved.error, CLOSED)+})+test('a private Bot is no Main Bot, no member of a group and no copy', async (t) => {const { rt, stop } = await start()t.after(stop)diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex dcf998b7..1e68fbd0 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -924,12 +924,30 @@ test('a member\'s folder pick in a group goes with the group\'s folder setting oassert.equal(state().rooms.r1.memberDirs?.b, undefined)})-test('setting a group folder points that group\'s own Session, and clearing it points back', async (t) => {+test('a member cannot pick the folder of a private Bot inside a group', async (t) => {+ const { service } = folderService()+ const { services } = approvalServices('allowed-once')+ const three = {+ ...TEAM,+ bots: { ...TEAM.bots, c: { id: 'c', name: 'Diary', role: 'Notes', sessionId: 'c', createdAt: 3 } },+ }+ const { ctx, call, agentOf, project, state, stop } = await start({ services: { ...services, workingDirectory: service }, team: three })+ t.after(stop)+ assert.equal((await call('update-bot', { id: 'c', private: true, workDir: project })).ok, true)+ const moved = await changeDirectory(ctx, service, agentOf('gb'), project)+ assert.equal(moved.ran, false)+ assert.match(moved.error, /Diary is a private Bot/)+ assert.equal(state().rooms.r1.memberDirs, undefined)+})++test('a group folder change leaves the group\'s own Session as it was made', async (t) => {const { call, created, agentOf, preStep, project, team, state, stop } = await start()t.after(stop)assert.equal((await call('update-room', { id: 'r1', workDir: project })).ok, true)assert.equal(state().rooms.r1.id, 'r1')- assert.equal(agentOf('r1').session.header.cwd, project)+ // A Session's header is creation metadata DSH owns: the relay Session stays in the+ // team workspace, and no fresh Session is made for the group.+ assert.equal(agentOf('r1').session.header.cwd, team)assert.equal(state().rooms.r1.sessions.b, 'gb')assert.deepEqual(created, [])@@ -937,7 +955,7 @@ test('setting a group folder points that group\'s own Session, and clearing it pawait until(() => state().rooms.r1.sessions.b === 's1')assert.deepEqual(created, [{ cwd: project }])assert.equal(state().rooms.r1.id, 'r1')- assert.equal(agentOf('r1').session.header.cwd, project)+ assert.equal(agentOf('r1').session.header.cwd, team)assert.equal((await call('update-room', { id: 'r1', workDir: '' })).ok, true)assert.equal(state().rooms.r1.workDir, undefined)@@ -946,45 +964,33 @@ test('setting a group folder points that group\'s own Session, and clearing it passert.equal(state().rooms.r1.sessions.b, 's1')})-test('a frozen group Session header is replaced in memory', async (t) => {- const { call, agentOf, project, team, state, created, stop } = await start()+test('the file panel of a group with a folder lists that folder', async (t) => {+ // The workspaceFileScope lookup answers what the file panel lists; until DS Bot's+ // resolver answers for the group's own Session, the provider's own resolution runs.+ const resolved = []+ const provider = { resolve: async id => { resolved.push(id); return { sessionId: id, workspaceRoot: `/header-${id}` } } }+ let resolver+ const typert = { lookups: {+ get: key => (key === 'workspaceFileScope' ? provider : undefined),+ configure: (key, next) => { resolver = next; return () => {} },+ } }+ const { call, project, stop } = await start({ services: { typert } })t.after(stop)- const session = agentOf('r1').session- const previous = session.header- Object.freeze(previous)+ assert.deepEqual(await resolver('r1'), { sessionId: 'r1', workspaceRoot: '/header-r1' })+assert.equal((await call('update-room', { id: 'r1', workDir: project })).ok, true)- assert.equal(previous.cwd, team)- assert.equal(session.header.cwd, project)- assert.notEqual(session.header, previous)- assert.equal(state().rooms.r1.id, 'r1')- assert.deepEqual(created, [])-})+ assert.deepEqual(await resolver('r1'), { sessionId: 'r1', workspaceRoot: project })+ // A member's Session and every other Session still resolve as the provider would.+ assert.deepEqual(await resolver('gb'), { sessionId: 'gb', workspaceRoot: '/header-gb' })+ assert.deepEqual(resolved, ['r1', 'gb'])-test('pointing a saved group folder does not hold up the team view', async (t) => {- const env = await start()- t.after(env.stop)- assert.equal((await env.call('update-room', { id: 'r1', workDir: env.project })).ok, true)- assert.equal(env.agentOf('r1').session.header.cwd, env.project)- env.agentOf('r1').session.header.cwd = env.team- let release- const gate = new Promise(resolve => { release = resolve })- const resolveAgent = env.ctx.sessionController.resolveAgent- env.ctx.sessionController.resolveAgent = async (id) => {- if (id === 'r1') await gate- return resolveAgent(id)- }- const view = await Promise.race([- env.call('state', {}),- new Promise((_, reject) => setTimeout(() => reject(new Error('state waited for the group Session')), 300)),- ])- assert.equal(view.ok, true)- assert.equal(env.agentOf('r1').session.header.cwd, env.team)- release()- await until(() => env.agentOf('r1').session.header.cwd === env.project)- env.agentOf('r1').session.header.cwd = env.team- assert.equal((await env.call('state', {})).ok, true)- await settle()- assert.equal(env.agentOf('r1').session.header.cwd, env.team)+ // A folder gone from disk resolves as the provider would have it, not as an error.+ rmSync(project, { recursive: true })+ assert.deepEqual(await resolver('r1'), { sessionId: 'r1', workspaceRoot: '/header-r1' })+ mkdirSync(project)++ assert.equal((await call('update-room', { id: 'r1', workDir: '' })).ok, true)+ assert.deepEqual(await resolver('r1'), { sessionId: 'r1', workspaceRoot: '/header-r1' })})test('a group Session that cannot be opened still saves the folder', async (t) => {