Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Close private subagent paths

Fei2411d04d8805da8b
diff --git a/docs/plans/2026-10-27-private-bots.md b/docs/plans/2026-10-27-private-bots.md
index 880d32ed..cede5a56 100644
--- a/docs/plans/2026-10-27-private-bots.md
+++ b/docs/plans/2026-10-27-private-bots.md
@@ -29,8 +29,9 @@
- `list_bots` 只向其他 Bot 显示隐私 Bot 的名字、角色和隐私状态,不显示它的指令、当前工作、模型或文件夹。
- 其他 Bot 不能向它发 `message_bot`,不能用 `stop_bot` 或 `update_bot` 操作它,不能用 `attach_capability` 或 `detach_capability` 改它的能力,也不能通过 `recall`、`remember`、`forget` 读取或修改它的记忆。
-- 文件工具、图片读取、`glob`、`grep`、`working_directory` 和会话查询会检查目标;命中隐私 Bot 的文件夹、记忆或会话就拒绝。其他 Bot 做跨会话搜索时必须给出经过检查的安全会话或父会话 id,不能做未过滤的全局搜索。
-- 团队状态文件、共享聊天索引、记忆变更日志和暂存文件也对其他 Bot 关闭。存在隐私 Bot 或其保留的归档时,其他 Bot 不能在数据位置做目录遍历搜索,也不能直接读取其中的共享数据文件;自己的文件夹和总工作区仍可正常使用。
+- 文件工具、图片读取、`glob`、`grep`、`working_directory`、`subagent` / `subagent_fork` 的 `cwd` 和会话查询会检查目标;命中隐私 Bot 的文件夹、记忆或会话就拒绝。其他 Bot 做跨会话搜索时必须给出经过检查的安全会话或父会话 id,不能做未过滤的全局搜索。
+- 会话目标会沿 `parentSession` 追踪;隐私 Bot 的子 agent Session 也同样关闭。
+- 团队状态文件、共享聊天索引、记忆变更日志和暂存文件也对其他 Bot 关闭。存在隐私 Bot 或其保留的归档时,其他 Bot 不能在数据位置做目录遍历搜索,也不能直接读取其中的共享数据文件;自己的文件夹、总工作区和团队共享记忆仍可正常使用。
- 隐私 Bot 的记忆变更日志保存在它自己的受保护目录,条目的前后正文不写进团队共享日志。
- 子 agent 继承最上层 Bot 的身份,多层嵌套不会改变这道边界。
diff --git a/ds-bot/src/host/privacy.js b/ds-bot/src/host/privacy.js
index 4607de01..e11c80d4 100644
--- a/ds-bot/src/host/privacy.js
+++ b/ds-bot/src/host/privacy.js
@@ -83,6 +83,7 @@ export function install(rt) {
].filter(Boolean).map(spellings))).flat()
const teamFolder = () => rt.teamFolder() ?? resolve(rt.defaultTeamFolder())
+ const teamMemory = join(rt.home, 'memory', 'team')
// The private Bot that `path` belongs to, other than `self`; undefined when it is open.
// `search` is for tools that walk a folder: a folder that holds a closed one is closed
@@ -106,7 +107,7 @@ 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(), ...ownRegions].filter(Boolean)
+ const open = [rt.workDirOf({ botId: self }), teamFolder(), teamMemory, ...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) {
@@ -208,6 +209,26 @@ export function install(rt) {
}
}
+ // A Session started under a private Bot is closed too, even when its own id is not in
+ // the Bot's chat history. Walk the same parent chain as the caller check.
+ async function ownerOfSession(id, self) {
+ const bots = protectedBots()
+ const owns = (sessionId, bot) => bot.id !== self && sessionsOf(bot).includes(sessionId)
+ const direct = bots.find(bot => owns(id, bot))
+ if (direct) return direct
+ const seen = new Set([id])
+ let current = id
+ for (;;) {
+ const agent = await rt.resolveAgent(current).catch(() => undefined)
+ const parent = agent?.session?.header?.parentSession
+ if (parent === undefined || seen.has(parent)) return undefined
+ const owner = bots.find(bot => owns(parent, bot))
+ if (owner) return owner
+ seen.add(parent)
+ current = parent
+ }
+ }
+
// The file tools, the shell and the session search: where the path or text names a
// closed place, the call fails before it runs.
async function guardFiles(exec, self) {
@@ -223,7 +244,8 @@ export function install(rt) {
// A private Bot's file changes stay in its own folder unless the user allows them.
if (isPrivate(self) && WRITE_TOOLS.includes(name)) {
const own = await spellings(rt.botOf(self).workDir)
- const target = await spellings(resolve(folder(), path))
+ const base = folder()
+ const target = await spellings(base === undefined ? path : resolve(base, path))
if (!target.every(key => own.some(root => within(key, root)))) await approve(exec, { en: `Let ${rt.botOf(self).name} change ${path}? It is outside its own folder.`, zh: `允许 ${rt.botOf(self).name} 修改 ${path} 吗?它在自己的文件夹之外。` })
}
return
@@ -240,6 +262,11 @@ export function install(rt) {
if (bot) refuse(bot)
return
}
+ if ((name === 'subagent' || name === 'subagent_fork') && typeof args.cwd === 'string') {
+ const bot = await ownerOfPath(args.cwd, { self, search: true, base: folder() })
+ if (bot) refuse(bot)
+ return
+ }
if (name === 'working_directory' && typeof args.cd === 'string') {
const bot = await ownerOfPath(args.cd, { self, search: true, base: folder() })
if (bot) refuse(bot)
@@ -247,8 +274,10 @@ export function install(rt) {
}
if (SESSION_TOOLS.includes(name)) {
const asked = strings([args.session_id, args.session_ids, args.parent_session_ids])
- const bot = protectedBots().find(found => found.id !== self && sessionsOf(found).some(id => asked.includes(id)))
- if (bot) refuse(bot)
+ for (const id of asked) {
+ const bot = await ownerOfSession(id, self)
+ if (bot) refuse(bot)
+ }
// DSH scopes Session search to the caller's cwd. A subagent can have another cwd,
// so an unfiltered search is closed too; explicit safe ids still narrow it.
if (name === 'session_search' && args.session_ids === undefined && args.parent_session_ids === undefined) {
diff --git a/ds-bot/test/privacy.test.js b/ds-bot/test/privacy.test.js
index c7e85413..265f75cc 100644
--- a/ds-bot/test/privacy.test.js
+++ b/ds-bot/test/privacy.test.js
@@ -258,6 +258,8 @@ test('other Bots cannot read, write or search what a private Bot keeps', async (
await refused('bash', { command: `cat ${posix(join(home, 'chat-index.sqlite'))}` })
await refused('working_directory', { cd: diary })
await refused('working_directory', { cd: root })
+ await refused('subagent', { cwd: diary, prompt: 'read notes.txt' })
+ await refused('subagent_fork', { cwd: relative(team, diary), prompt: 'read notes.txt' })
await refused('session_search', { query: 'x' })
await refused('session_search', { query: 'x', session_id: P })
await refused('session_trace', { session_ids: ['b', P] })
@@ -268,10 +270,13 @@ test('other Bots cannot read, write or search what a private Bot keeps', async (
['read', { file_path: 'a.txt' }],
['write', { file_path: join(team, 'a.txt'), content: 'x' }],
['read', { file_path: join(dsh, 'sessions', 'b.jsonl') }],
+ ['read', { file_path: join(home, 'memory', 'team', 'MEMORY.md') }],
+ ['glob', { pattern: '**/*', path: join(home, 'memory', 'team') }],
['glob', { pattern: '**/*', path: project }],
['glob', { pattern: '**/*', path: team }],
['grep', { pattern: 'x' }],
['bash', { command: 'ls', workdir: project }],
+ ['subagent', { cwd: project, prompt: 'work in the open folder' }],
['working_directory', { cd: join(team, 'sub') }],
['session_search', { query: 'x', session_ids: ['b'] }],
]) {
@@ -306,6 +311,9 @@ test('the private Bot reads its own and the team\'s files; a Session it starts s
assert.deepEqual(await run('glob', { pattern: '**/*', path: home }, P), { ran: true })
assert.deepEqual(await run('read', { file_path: join(project, 'a.txt') }, P), { ran: true })
assert.deepEqual(await run('glob', { pattern: '**/*', path: team }, P), { ran: true })
+ assert.deepEqual(await run('read', { file_path: join(home, 'memory', 'team', 'MEMORY.md') }, P), { ran: true })
+ assert.deepEqual(await run('glob', { pattern: '**/*', path: join(home, 'memory', 'team') }, P), { ran: true })
+ assert.deepEqual(await run('subagent', { cwd: diary, prompt: 'work in my folder' }, P), { ran: true })
const sub = parent => ({ id: 'sub1', session: { id: 'sub1', header: { cwd: team, parentSession: parent } } })
const fromWriter = await run('read', { file_path: join(diary, 'notes.txt') }, 'b', sub('b'))
assert.equal(fromWriter.ran, false)
@@ -354,7 +362,7 @@ test('a message of a private Bot that the user does not allow is not sent', asyn
test('a private Bot changes files outside its folder only with the user\'s approval', async (t) => {
const approval = fakeApproval('allowed-once')
- const { run, diary, project, stop } = await start({ services: { approval } })
+ const { run, ctx, diary, project, stop } = await start({ services: { approval } })
t.after(stop)
assert.deepEqual(await run('write', { file_path: join(diary, 'today.txt'), content: 'x' }, P), { ran: true })
assert.deepEqual(await run('write', { file_path: 'today.txt', content: 'x' }, P), { ran: true })
@@ -368,6 +376,15 @@ test('a private Bot changes files outside its folder only with the user\'s appro
// Reading is free.
assert.deepEqual(await run('read', { file_path: join(project, 'a.txt') }, P), { ran: true })
assert.equal(approval.requests.length, 2)
+ // A subagent can have no cwd of its own; an absolute path still needs no TypeError.
+ const getWorkspace = ctx.workspaceRegistry.get
+ try {
+ ctx.workspaceRegistry.get = () => undefined
+ const noCwd = { id: 'sub-no-cwd', session: { id: 'sub-no-cwd', header: { parentSession: P } } }
+ assert.deepEqual(await run('write', { file_path: join(diary, 'no-cwd.txt'), content: 'x' }, P, noCwd), { ran: true })
+ } finally {
+ ctx.workspaceRegistry.get = getWorkspace
+ }
})
test('a write of a private Bot outside its folder that the user does not allow is not made', async (t) => {
@@ -421,11 +438,18 @@ test('a nested subagent speaks for the private Bot at its root', async (t) => {
const { run, diary, agentOf, stop } = await start({ services: { approval } })
t.after(stop)
agentOf('sub1').session.header.parentSession = P
- const nested = { id: 'sub2', session: { id: 'sub2', header: { cwd: diary, parentSession: 'sub1' } } }
+ const nested = agentOf('sub2')
+ nested.session.header.cwd = diary
+ nested.session.header.parentSession = 'sub1'
assert.deepEqual(await run('read', { file_path: join(diary, 'notes.txt') }, P, nested), { ran: true })
assert.deepEqual(await run('message_bot', { to: 'Writer', message: 'from a nested subagent' }, P, nested), { ran: true })
assert.equal(approval.requests.length, 1)
assert.match(approval.requests[0].reason, /from a nested subagent/)
+ for (const id of ['sub1', 'sub2']) {
+ const result = await run('session_trace', { session_id: id }, 'b')
+ assert.equal(result.ran, false, id)
+ assert.match(result.error, CLOSED)
+ }
})
test('deleting a private Bot keeps its folder and archived memory closed', async (t) => {