A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Check the working_directory path exactly as DSH receives it
Fei2411ccb6cd768cf1
diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.jsindex b0e97841..f908acaf 100644--- a/ds-bot/src/host/folders.js+++ b/ds-bot/src/host/folders.js@@ -61,6 +61,11 @@ export function install(rt) {throw new Error(`There is no folder at ${text}`)}if (!(await isFolder(path))) throw new Error(`${text} is a file, not a folder`)+ return workFolder(path)+ }++ // A folder, as a real path, as a working folder: undefined for the team workspace.+ async function workFolder(path) {if (await guarded(path)) throw new Error(`${path} holds DeepSeek Harness data, so Bots cannot work there`)return path === teamFolder() ? undefined : path}@@ -141,5 +146,5 @@ export function install(rt) {}}- Object.assign(rt, { teamFolder, workDirOf, sessionFolder, isFolder, real, folderAt, cleanWorkDir, sessionsOfBot, approveFolder, folderEndpoint })+ Object.assign(rt, { teamFolder, workDirOf, sessionFolder, isFolder, real, folderAt, cleanWorkDir, workFolder, sessionsOfBot, approveFolder, folderEndpoint })}diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex 1a88163b..b9b2c7f1 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -316,7 +316,8 @@ export function install(rt) {// sets its working folder instead, with update_bot's checks, and goes on in a fresh part// there; a folder inside it only moves this Session there.ctx.on('tools/execute', async (exec, next) => {- const cd = exec.name === WORKING_DIRECTORY_TOOL && typeof exec.arguments?.cd === 'string' ? exec.arguments.cd.trim() : ''+ // Resolved as DSH gets it, untrimmed, so that both mean the same folder.+ const cd = exec.name === WORKING_DIRECTORY_TOOL && typeof exec.arguments?.cd === 'string' ? exec.arguments.cd : ''const session = exec.agent?.sessionif (cd === '' || session === undefined) return next()await rt.load()@@ -325,11 +326,13 @@ export function install(rt) {const room = rt.roomOf(rt.groupOwners.get(exec.agent.id)?.roomId)const home = rt.workDirOf({ botId: bot.id, roomId: room?.id }) ?? rt.teamFolder()const target = await rt.folderAt(rt.sessionFolder(session), cd)- if (target === undefined || home === undefined || within(target, await rt.real(home))) return next()+ if (target === undefined || !(await rt.isFolder(target)) || 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)+ // Saved folders are trimmed like typed ones, so such a name would save another folder.+ if (unquote(target) !== target) throw new Error(`${JSON.stringify(target)} cannot be a working folder: its name starts or ends with a space or a quote mark.`)+ const workDir = await rt.workFolder(target)await rt.approveFolder(exec, { path: workDir, sessions: rt.sessionsOfBot(bot.id), who: { en: bot.name, zh: ` ${bot.name} ` } })const result = await next()if (result?.isError !== true) await rt.updateBot(bot.id, { workDir: workDir ?? '' })diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex 0148f87c..04aaf812 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -720,3 +720,15 @@ test('while another dsh has the team open, a Bot cannot leave its working folderassert.equal(out.ran, false)assert.equal(state().bots.b.workDir, undefined)})++// The trimmed path names no folder, so a check of it would let DSH move out unchecked.+test('the folder is checked as DSH gets it, spaces and all', { skip: process.platform === 'win32' && 'Windows drops trailing spaces from names' }, async (t) => {+ const { service } = folderService()+ const { services } = approvalServices('allowed-once')+ const { ctx, agentOf, root, state, stop } = await start({ services: { ...services, workingDirectory: service } })+ t.after(stop)+ const spaced = join(root, 'outside ')+ mkdirSync(spaced)+ assert.deepEqual(await changeDirectory(ctx, service, agentOf('b'), spaced), { error: `${JSON.stringify(spaced)} cannot be a working folder: its name starts or ends with a space or a quote mark.`, ran: false })+ assert.equal(state().bots.b.workDir, undefined)+})