A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Refuse a move out of the working folder while another dsh has the team
Fei241188fda73d761a
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex d5e495d4..1a88163b 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -318,7 +318,7 @@ export function install(rt) {ctx.on('tools/execute', async (exec, next) => {const cd = exec.name === WORKING_DIRECTORY_TOOL && typeof exec.arguments?.cd === 'string' ? exec.arguments.cd.trim() : ''const session = exec.agent?.session- if (cd === '' || session === undefined || rt.readOnly() !== undefined) return next()+ if (cd === '' || session === undefined) return next()await rt.load()const bot = callerBot(exec)if (bot === undefined) return next()@@ -327,6 +327,8 @@ export function install(rt) {const target = await rt.folderAt(rt.sessionFolder(session), cd)if (target === undefined || home === undefined || within(target, await rt.real(home))) return next()if (room?.workDir) throw new Error(`Every member of "${room.name}" works in ${room.workDir} here, so you stay inside it. The user or a Main Bot can change the group's folder.`)+ const readOnly = rt.readOnly()+ if (readOnly !== undefined) throw new Error(`Your working folder cannot change now: ${readOnly}`)const workDir = await rt.cleanWorkDir(target)await rt.approveFolder(exec, { path: workDir, sessions: rt.sessionsOfBot(bot.id), who: { en: bot.name, zh: ` ${bot.name} ` } })const result = await next()diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex 0d8c4f25..0148f87c 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -1,6 +1,6 @@import assert from 'node:assert/strict'import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'-import { homedir, tmpdir } from 'node:os'+import { homedir, hostname, tmpdir } from 'node:os'import { join, resolve } from 'node:path'import { test } from 'node:test'import { apply } from '../index.js'@@ -29,7 +29,8 @@ const TEAM = {// DSH_HOME, the team's data inside it, and a project folder beside it. Every Session// starts in the team workspace unless it is made with a cwd. `services` are what// ctx.get finds, such as the sandbox policy and approvals.-async function start({ services = {}, workspaces = [], llm, team: saved = TEAM } = {}) {+// `locked`: another dsh holds the team, so this one only shows it.+async function start({ services = {}, workspaces = [], llm, team: saved = TEAM, locked = 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-work-dir-')))const dsh = join(root, 'dsh')@@ -38,6 +39,7 @@ async function start({ services = {}, workspaces = [], llm, team: saved = TEAM }const project = join(root, 'project')for (const dir of [team, project]) mkdirSync(dir, { recursive: true })writeFileSync(join(home, 'state.json'), JSON.stringify(saved))+ if (locked) writeFileSync(join(home, 'state.lock'), JSON.stringify({ pid: process.ppid, host: hostname(), token: 'other' }))const previousHome = process.env.DSH_HOMEprocess.env.DSH_HOME = dsh@@ -705,3 +707,16 @@ test('Sessions that are not a Bot\'s keep DSH\'s own working_directory', async (assert.equal(requests.length, 0)assert.deepEqual(Object.values(state().bots).map(bot => bot.workDir), [undefined, undefined])})++test('while another dsh has the team open, a Bot cannot leave its working folder', async (t) => {+ const { service } = folderService()+ const { services } = approvalServices('allowed-once')+ const { ctx, agentOf, team, project, state, stop } = await start({ services: { ...services, workingDirectory: service }, locked: true })+ t.after(stop)+ mkdirSync(join(team, 'site'))+ assert.equal((await changeDirectory(ctx, service, agentOf('b'), 'site')).ran, true)+ const out = await changeDirectory(ctx, service, agentOf('b'), project)+ assert.match(out.error, /^Your working folder cannot change now: The Bot team in .* is open in another dsh/)+ assert.equal(out.ran, false)+ assert.equal(state().bots.b.workDir, undefined)+})