A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep a private archive closed when its log row fails or its path is not yet known
Fei241131245fecdf50
diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.jsindex 7a84a46a..47f462ea 100644--- a/ds-bot/src/host/memory.js+++ b/ds-bot/src/host/memory.js@@ -870,7 +870,10 @@ export function install(rt) {const name = `${safeId(botId)}-${new Date().toISOString().replace(/[:.]/g, '-')}`await mkdir(join(root, 'archive'), { recursive: true })await rename(dir, join(root, 'archive', name))+ // The memory is in the archive from here: a log row that cannot be written must not+ // hide where it went, which the privacy guard needs to keep a private archive closed.await journalRow({ id: randomUUID(), time: new Date().toISOString(), op: 'archive', scope: scopeKey(ownScope(botId)), actor: 'user', actorName: 'user', botName: bot?.name, to: `archive/${name}` })+ .catch(error => rt.warn('ds-bot: archive of the memory of %s not logged: %s', bot?.name ?? botId, error))return join(root, 'archive', name)}).catch(error => rt.warn('ds-bot: memory of %s not archived: %s', bot?.name ?? botId, error))}diff --git a/ds-bot/src/host/privacy.js b/ds-bot/src/host/privacy.jsindex 1df14c3f..ccdaf1bd 100644--- a/ds-bot/src/host/privacy.js+++ b/ds-bot/src/host/privacy.js@@ -111,7 +111,10 @@ export function install(rt) {const ownBot = rt.botOf(self)const ownIds = ownBot === undefined ? [] : sessionsOf(ownBot).map(fold)const ownRegions = ownBot === undefined ? [] : await regionsOf(ownBot)- const open = [rt.workDirOf({ botId: self }), teamFolder(), teamMemory, memoryArchive, ...ownRegions].filter(Boolean)+ // A walk of the archive stays closed while a private Bot's memory is on its way+ // there: until the path is known, the walk cannot be told which folder to skip.+ const moving = search && bots.some(bot => bot.archiving === true)+ const open = [rt.workDirOf({ botId: self }), teamFolder(), teamMemory, moving ? undefined : memoryArchive, ...ownRegions].filter(Boolean)const folders = (await Promise.all(open.map(spellings))).flat()const roots = (await Promise.all(dataRoots().map(spellings))).flat()for (const key of keys) {diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex 21bbd015..1d35dc76 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -630,11 +630,14 @@ export function install(rt) {const current = rt.chatOf(id)// Questions and exchange turns are kept per Session, so every part of the chat is cleared.const parts = new Set([id, current, ...(bot.segments ?? []).map(segment => segment.sessionId)])+ // `archiving` stands until the archive's path is known: the memory may already be+ // there, and no region of its own closes it yet.const closedArchive = bot.private === true ? {id: bot.id,name: bot.name,...(bot.workDir === undefined ? {} : { workDir: bot.workDir }),sessionIds: [...parts, ...rt.groupSessionsOf(id)],+ archiving: true,} : undefinedawait rt.releaseBot(id, [...parts, ...rt.groupSessionsOf(id)])if (closedArchive !== undefined) state.privateArchives = [...(state.privateArchives ?? []).filter(entry => entry.id !== id), closedArchive]@@ -656,7 +659,11 @@ export function install(rt) {await followMemberNames(touched)await rt.forgetBotSecrets(id)const archivePath = await archived- if (closedArchive !== undefined && archivePath !== undefined) closedArchive.archivePath = archivePath+ if (closedArchive !== undefined) {+ // No path means nothing was moved: a memory that stayed in place is a region already.+ if (archivePath !== undefined) closedArchive.archivePath = archivePath+ delete closedArchive.archiving+ }const failed = await saveForDelete()// Same as deleteRoom: stopActivity removes the Session's armed scheduled tasks.// Past parts are archived too: a part move can leave tasks on the old Session,diff --git a/ds-bot/test/privacy.test.js b/ds-bot/test/privacy.test.jsindex ecef31fa..126ac04e 100644--- a/ds-bot/test/privacy.test.js+++ b/ds-bot/test/privacy.test.js@@ -10,10 +10,11 @@ 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 }) {+function seed({ diary, privateBot, archives = [] }) {return {version: 1,mainBotIds: ['a'],+ privateArchives: archives,workspaceId: 'w1',bots: {a: { id: 'a', name: 'Chief', role: 'Boss', sessionId: 'a', createdAt: 1 },@@ -30,7 +31,7 @@ function seed({ diary, privateBot }) {}}-async function start({ services = {}, privateBot = true } = {}) {+async function start({ services = {}, privateBot = true, archives } = {}) {// 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')@@ -40,7 +41,7 @@ async function start({ services = {}, privateBot = true } = {}) {const diary = join(root, 'diary')for (const dir of [team, project, diary]) mkdirSync(dir, { recursive: true })writeFileSync(join(diary, 'notes.txt'), 'secret')- writeFileSync(join(home, 'state.json'), JSON.stringify(seed({ diary, privateBot })))+ writeFileSync(join(home, 'state.json'), JSON.stringify(seed({ diary, privateBot, archives })))const previousHome = process.env.DSH_HOMEprocess.env.DSH_HOME = dsh@@ -559,6 +560,59 @@ test('the archived memory of a Bot whose protection is lifted opens; another arcassert.deepEqual(await run('glob', { pattern: '**/*', path: archiveRoot }, reader), { ran: true })})+test('an archive whose log row could not be written is still kept closed to a walk', async (t) => {+ const { rt, ctx, run, home, root, state, stop } = await start({ privateBot: false })+ t.after(stop)+ let created = 0+ ctx.sessionController.create = async () => ({ sessionId: `0000000${++created}-1111-4222-8333-444444444444` })+ const ledgerDir = join(root, 'ledger')+ mkdirSync(ledgerDir)+ const ledger = await rt.createBot({ name: 'Ledger', workDir: ledgerDir })+ await rt.updateBot(ledger.id, { private: true })+ const reader = (await rt.createBot({ name: 'Reader' })).id+ mkdirSync(join(home, 'memory', 'bots', ledger.id), { recursive: true })+ writeFileSync(join(home, 'memory', 'bots', ledger.id, 'MEMORY.md'), 'books')+ // A change log that cannot be read stops the archive's row, after the memory has moved.+ mkdirSync(join(home, 'memory', 'journal.jsonl'), { recursive: true })+ await rt.deleteBot(ledger.id)++ const archiveRoot = join(home, 'memory', 'archive')+ const [entry] = state().privateArchives+ assert.ok(entry.archivePath?.startsWith(archiveRoot), 'the path of the archive is kept')+ assert.equal(entry.archiving, undefined)+ assert.equal(readFileSync(join(entry.archivePath, 'MEMORY.md'), 'utf8'), 'books')+ const read = await run('read', { file_path: join(entry.archivePath, 'MEMORY.md') }, reader)+ assert.equal(read.ran, false)+ assert.match(read.error, /Ledger/)+ assert.equal((await run('glob', { pattern: '**/*', path: archiveRoot }, reader)).ran, false)+ assert.equal((await run('grep', { pattern: 'books', path: archiveRoot }, reader)).ran, false)+})++test('a walk of the archive stays closed while a private Bot\'s memory is still on its way there', async (t) => {+ const GHOST = 'e2b60000-1111-4222-8333-444444444444'+ const { call, run, home, stop } = await start({ privateBot: false, archives: [{ id: GHOST, name: 'Ghost', sessionIds: [], archiving: true }] })+ t.after(stop)+ const archiveRoot = join(home, 'memory', 'archive')+ mkdirSync(join(archiveRoot, `${GHOST}-2026-10-28`), { recursive: true })+ writeFileSync(join(archiveRoot, `${GHOST}-2026-10-28`, 'MEMORY.md'), 'ghost')++ const walk = await run('glob', { pattern: '**/*', path: archiveRoot }, 'b')+ assert.equal(walk.ran, false)+ assert.match(walk.error, /Ghost/)+ // Once the user lifts the protection there is nothing left to hide.+ assert.equal((await call('private-release', { id: GHOST })).ok, true)+ assert.deepEqual(await run('glob', { pattern: '**/*', path: archiveRoot }, 'b'), { ran: true })+})++test('a kept Bot whose memory never moved does not close the archive folder', async (t) => {+ const GHOST = 'e2b60000-1111-4222-8333-444444444444'+ const { run, home, stop } = await start({ privateBot: false, archives: [{ id: GHOST, name: 'Ghost', sessionIds: [] }] })+ t.after(stop)+ const archiveRoot = join(home, 'memory', 'archive')+ mkdirSync(archiveRoot, { recursive: true })+ assert.deepEqual(await run('glob', { pattern: '**/*', path: archiveRoot }, 'b'), { ran: true })+})+test('with no private Bot the tools run as they did', async (t) => {const { run, diary, stop } = await start({ privateBot: false })t.after(stop)