Skip to content

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

Harden private Bot review boundaries

Fei241195b4efb19308
diff --git a/docs/plans/2026-10-27-private-bots.md b/docs/plans/2026-10-27-private-bots.md
index e3292fab..880d32ed 100644
--- a/docs/plans/2026-10-27-private-bots.md
+++ b/docs/plans/2026-10-27-private-bots.md
@@ -21,16 +21,17 @@
### 独立文件夹
- 隐私 Bot 必须有单独的工作文件夹。
-- 这个文件夹不能与总工作区、其他 Bot 的工作文件夹或群文件夹互相包含。比较路径时会解析已经存在的链接。
+- 这个文件夹不能与总工作区、其他 Bot 的工作文件夹或群文件夹互相包含。比较路径时会解析链接;目标文件尚不存在时,也会解析最深的现有父目录。
- 其他 Bot、群或总工作区不能改到与隐私 Bot 重叠的文件夹。
- 文件夹不能重叠是强制条件:DSH 的搜索工具会遍历目录,插件不能从搜索结果里可靠地剔除其中一部分文件。
### 其他 Bot 看不到什么
- `list_bots` 只向其他 Bot 显示隐私 Bot 的名字、角色和隐私状态,不显示它的指令、当前工作、模型或文件夹。
-- 其他 Bot 不能向它发 `message_bot`,不能用 `stop_bot` 或 `update_bot` 操作它,也不能通过 `recall`、`remember`、`forget` 读取或修改它的记忆。
-- 文件工具、图片读取、`glob`、`grep`、`working_directory` 和会话查询会检查目标;命中隐私 Bot 的文件夹、记忆或会话就拒绝。
-- 团队状态文件和记忆变更日志也对其他 Bot 关闭。存在隐私 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 不能在数据位置做目录遍历搜索,也不能直接读取其中的共享数据文件;自己的文件夹和总工作区仍可正常使用。
+- 隐私 Bot 的记忆变更日志保存在它自己的受保护目录,条目的前后正文不写进团队共享日志。
- 子 agent 继承最上层 Bot 的身份,多层嵌套不会改变这道边界。
### 隐私 Bot 能做什么
@@ -38,7 +39,7 @@
- 它读取公开 Bot 和团队共享内容的方式不变,包括读取其他公开 Bot 的记忆。
- 它可以读自己的文件夹、记忆和会话,也可以读团队其他允许读取的内容。
- 它向其他 Bot 发 `message_bot`、保存所有 Bot 都能读取的共享能力,或写自己文件夹之外的文件时,要先得到用户批准。
-- 批准卡显示接收方和要分享的内容;拒绝、取消或无法回答时,操作不执行。
+- 批准卡显示接收方和完整的待分享内容;拒绝、取消或无法回答时,操作不执行。
- 它在自己的文件夹里读写不需要额外批准。
### 删除以后
@@ -57,10 +58,10 @@
## 已知限制
- DSH 的文件沙箱不限制读取。文件工具和目录搜索的路径检查是在 DS Bot 的工具钩子里做的,不是系统安全边界。
-- shell 命令只能按其中出现的路径和会话标识做保守检查。动态拼接路径、通过相对路径向上走、遍历未直接写出隐私路径的父目录等方式仍可能绕过检查。能够执行 shell 的模型,最终仍可能读取当前系统账号有权限读取的文件。
+- shell 命令只能按其中出现的路径和会话标识做保守检查。动态拼接路径、通过相对路径向上走、遍历未直接写出隐私路径的父目录等方式仍可能绕过检查。能够执行 shell 的模型,最终仍可能读取当前系统账号有权限读取的文件,也能直接写共享文件夹而不经过文件夹外写入批准。
- 网络工具保持可用,所以隐私 Bot 仍可能把内容发到外部服务;是否允许这类任务,仍由用户按 Bot 的权限和工具配置判断。
- 路径检查偏保守:包含隐私会话标识的路径,以及与受保护位置同前缀的个别路径,可能被一并拒绝。
-- 对尚不存在的路径,链接解析依赖当前文件系统能提供的信息;之后新建的链接不能把既有授权变成系统级隔离。
+- 如果外部文件系统改动后来造成目录重叠,遍历搜索会按失败关闭处理,直到用户把目录分开;这是可用性损失,不能为了继续搜索而暴露受保护内容。
## 变更
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 4fc34e5e..1d6a6077 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1055,6 +1055,8 @@ var ZH = {
Private: "隐私",
"Other Bots cannot read its folder, memory or chats, and you approve what it shares with them.": "其他 Bot 不能读取它的文件夹、记忆或对话;它分享给其他 Bot 的内容需要你批准。",
"A Main Bot cannot be private.": "主 Bot 不能设为隐私 Bot。",
+ "Leave its group chats before making it private.": "先退出所有群聊,才能设为隐私 Bot。",
+ "Choose a working folder of its own first.": "先选择一个独立的工作文件夹。",
"A private Bot cannot be a Main Bot.": "隐私 Bot 不能设为主 Bot。",
"Team workspace": "总工作区",
"Team workspace: {folder}": "总工作区:{folder}",
@@ -12127,6 +12129,9 @@ function BotSettingsForm({ bot, roster, actions, run: run2 }) {
const isMainBot = isMainOf(roster, bot.id);
const onlyMain = isMainBot && (roster.mainBotIds ?? []).length === 1;
const isTile = roster.mainBotId === bot.id;
+ const inGroup = (roster.rooms ?? []).some((room2) => room2.members?.includes(bot.id));
+ const privateHint = t("Other Bots cannot read its folder, memory or chats, and you approve what it shares with them.");
+ const privacyHint = bot.private === true ? privateHint : isMainBot ? t("A Main Bot cannot be private.") : inGroup ? t("Leave its group chats before making it private.") : !bot.workDir ? t("Choose a working folder of its own first.") : privateHint;
const save = (patch) => run2(actions.updateBot(bot.id, patch));
const duplicate = () => run2(actions.duplicateBot(bot.id).then((copy2) => actions.openSession(copy2.id)));
const remove = () => {
@@ -12191,9 +12196,9 @@ function BotSettingsForm({ bot, roster, actions, run: run2 }) {
{ title: t("Privacy") },
(0, import_react25.createElement)(SwitchRow, {
label: t("Private"),
- hint: isMainBot ? t("A Main Bot cannot be private.") : t("Other Bots cannot read its folder, memory or chats, and you approve what it shares with them."),
+ hint: privacyHint,
on: bot.private === true,
- disabled: isMainBot,
+ disabled: bot.private !== true && (isMainBot || inGroup || !bot.workDir),
onChange: (value) => save({ private: value })
})
),
diff --git a/ds-bot/src/client/bot-settings.js b/ds-bot/src/client/bot-settings.js
index 34bebc24..77de0b46 100644
--- a/ds-bot/src/client/bot-settings.js
+++ b/ds-bot/src/client/bot-settings.js
@@ -202,6 +202,9 @@ export function BotSettingsForm({ bot, roster, actions, run }) {
const isMainBot = isMainOf(roster, bot.id)
const onlyMain = isMainBot && (roster.mainBotIds ?? []).length === 1
const isTile = roster.mainBotId === bot.id
+ const inGroup = (roster.rooms ?? []).some(room => room.members?.includes(bot.id))
+ const privateHint = t('Other Bots cannot read its folder, memory or chats, and you approve what it shares with them.')
+ const privacyHint = bot.private === true ? privateHint : isMainBot ? t('A Main Bot cannot be private.') : inGroup ? t('Leave its group chats before making it private.') : !bot.workDir ? t('Choose a working folder of its own first.') : privateHint
const save = patch => run(actions.updateBot(bot.id, patch))
const duplicate = () => run(actions.duplicateBot(bot.id).then(copy => actions.openSession(copy.id)))
const remove = () => { if (confirming) void run(actions.deleteBot(bot.id)); else setConfirming(true) }
@@ -231,9 +234,9 @@ export function BotSettingsForm({ bot, roster, actions, run }) {
h(Card, { title: t('Privacy') },
h(SwitchRow, {
label: t('Private'),
- hint: isMainBot ? t('A Main Bot cannot be private.') : t('Other Bots cannot read its folder, memory or chats, and you approve what it shares with them.'),
+ hint: privacyHint,
on: bot.private === true,
- disabled: isMainBot,
+ disabled: bot.private !== true && (isMainBot || inGroup || !bot.workDir),
onChange: value => save({ private: value }),
})),
h(Card, { title: t('Instructions') },
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 11e4c45c..79f26781 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -1007,6 +1007,8 @@ const ZH = {
Private: '隐私',
'Other Bots cannot read its folder, memory or chats, and you approve what it shares with them.': '其他 Bot 不能读取它的文件夹、记忆或对话;它分享给其他 Bot 的内容需要你批准。',
'A Main Bot cannot be private.': '主 Bot 不能设为隐私 Bot。',
+ 'Leave its group chats before making it private.': '先退出所有群聊,才能设为隐私 Bot。',
+ 'Choose a working folder of its own first.': '先选择一个独立的工作文件夹。',
'A private Bot cannot be a Main Bot.': '隐私 Bot 不能设为主 Bot。',
'Team workspace': '总工作区',
'Team workspace: {folder}': '总工作区:{folder}',
diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.js
index 2cee3bb3..f6130805 100644
--- a/ds-bot/src/host/folders.js
+++ b/ds-bot/src/host/folders.js
@@ -208,5 +208,5 @@ export function install(rt) {
}
}
- Object.assign(rt, { teamFolder, defaultTeamFolder, workDirOf, sessionFolder, isFolder, real, folderAt, cleanWorkDir, workFolder, inData, setTeamWorkspace, sessionsOfBot, approveFolder, folderEndpoint })
+ Object.assign(rt, { teamFolder, defaultTeamFolder, workDirOf, sessionFolder, isFolder, real, realBeyond, folderAt, cleanWorkDir, workFolder, inData, setTeamWorkspace, sessionsOfBot, approveFolder, folderEndpoint })
}
diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.js
index e0a60d3e..7a84a46a 100644
--- a/ds-bot/src/host/memory.js
+++ b/ds-bot/src/host/memory.js
@@ -6,7 +6,8 @@
// <home>/memory/bots/<botId>/ a Bot's own MEMORY.md and topics
// <home>/memory/groups/<roomId>/ what the members of one group chat share there
// <home>/memory/team/ what every Bot reads
-// <home>/memory/journal.jsonl every change, with the line before and after
+// <home>/memory/journal.jsonl non-private changes, with the line before and after
+// <home>/memory/bots/<botId>/journal.jsonl a private Bot's own change log
// <home>/memory/snapshots/ the memory section each Session froze
// <home>/memory/summaries/ the memory panel's summary per Bot or group chat
// <home>/memory/archive/ the memory of deleted Bots and group chats
@@ -318,11 +319,13 @@ const memoryRules = review => [
'- Each entry ends with [source: …]. A part anchor such as part 2 #1234 opens with read_own_chat around: in your own chat, or, when the entry has by: and a Bot\'s name, in that Bot\'s chat, which you can ask about with message_bot.',
].join('\n')
-const teamRule = (main, writer) => (main
+const teamRule = (main, writer, privateBot) => (main
? '- The team memory is shared by every Bot. As a Main Bot you write it with remember scope "team", for what the whole team needs; with scope set to a Bot\'s name you read or change that Bot\'s memory, when the user asks.'
- : writer
- ? '- The team memory is shared by every Bot. As a group admin you write it with remember scope "team", for what the whole team needs.'
- : '- The team memory is shared by every Bot. Main Bots and group admins write it; when the whole team should know something, tell a Main Bot with message_bot.')
+ : privateBot
+ ? '- The team memory is shared by every Bot. Main Bots and group admins write it; with scope set to a public Bot\'s name you read that Bot\'s memory.'
+ : writer
+ ? '- The team memory is shared by every Bot. As a group admin you write it with remember scope "team", for what the whole team needs.'
+ : '- The team memory is shared by every Bot. Main Bots and group admins write it; when the whole team should know something, tell a Main Bot with message_bot.')
// A group Session shows its group's memory after the rest of the section, so the text
// before it is the same as in the Bot's own chat.
@@ -474,6 +477,14 @@ export function install(rt) {
const groupScope = roomId => ({ kind: 'group', roomId })
const dirOf = scope => (scope.kind === 'team' ? join(root, 'team') : scope.kind === 'group' ? join(root, 'groups', safeId(scope.roomId)) : join(root, 'bots', safeId(scope.botId)))
const scopeKey = scope => (scope.kind === 'team' ? 'team' : scope.kind === 'group' ? `group:${scope.roomId}` : `bot:${scope.botId}`)
+ // A private Bot's before/after text never goes into the team-wide change log.
+ const journalFor = (scope, op) => {
+ const botId = scope?.startsWith('bot:') ? scope.slice(4) : undefined
+ const archived = (state.privateArchives ?? []).find(entry => entry.id === botId)
+ if (op === 'archive' || (botId === undefined || (!rt.isPrivate(botId) && archived === undefined))) return { path: journalPath, torn: tornPath }
+ const dir = archived?.archivePath ?? dirOf(ownScope(botId))
+ return { path: join(dir, 'journal.jsonl'), torn: join(dir, 'journal.torn') }
+ }
// The group a Session speaks in, an earlier part of it included: none for a Bot's
// own chat. Writes check membership again, so a member that has left writes nothing.
const roomIdOf = sessionId => rt.groupOwners.get(sessionId)?.roomId ?? rt.pastOwners.get(sessionId)?.roomId
@@ -556,12 +567,12 @@ export function install(rt) {
// The change log as it is. A log that cannot be read stops the memory: it is what
// says what was done.
- function readJournal() {
+ function readJournal(path) {
try {
- return readFileSync(journalPath, 'utf8')
+ return readFileSync(path, 'utf8')
} catch (error) {
if (error?.code === 'ENOENT') return ''
- unreadable(journalPath, error)
+ unreadable(path, error)
}
}
@@ -593,25 +604,26 @@ export function install(rt) {
// kept beside the log as the evidence it is, the log is cut back to the rows that
// are whole, and the row after it starts on a line of its own.
async function journalRow(row) {
- const text = readJournal()
+ const { path, torn } = journalFor(row.scope, row.op)
+ const text = readJournal(path)
if (journalled(text, row.id)) return false
const cut = text.lastIndexOf('\n') + 1
const half = text.slice(cut)
const line = JSON.stringify(row)
- mkdirSync(root, { recursive: true })
+ mkdirSync(dirname(path), { recursive: true })
if (half === '') {
- await appendFile(journalPath, `${line}\n`, 'utf8')
+ await appendFile(path, `${line}\n`, 'utf8')
return true
}
if (whole(half)) {
// A whole row that lost its newline: it is ended, and the row after it starts
// on a line of its own.
- await appendFile(journalPath, `\n${line}\n`, 'utf8')
+ await appendFile(path, `\n${line}\n`, 'utf8')
return true
}
- await appendFile(tornPath, `${half}\n`, 'utf8')
- truncateSync(journalPath, Buffer.byteLength(text.slice(0, cut), 'utf8'))
- await appendFile(journalPath, `${line}\n`, 'utf8')
+ await appendFile(torn, `${half}\n`, 'utf8')
+ truncateSync(path, Buffer.byteLength(text.slice(0, cut), 'utf8'))
+ await appendFile(path, `${line}\n`, 'utf8')
return true
}
@@ -923,7 +935,7 @@ export function install(rt) {
const lines = [
'# Your memory',
memoryRules(reviewOn),
- teamRule(rt.isMain(bot.id), writesTeam(bot.id)),
+ teamRule(rt.isMain(bot.id), writesTeam(bot.id), rt.isPrivate(bot.id)),
'',
'## Your memory (MEMORY.md)',
...sectionEntries(main),
@@ -976,7 +988,7 @@ export function install(rt) {
// longer one) is frozen again, so the rule it states matches what the tools allow;
// so is a group Session's section frozen before groups kept a memory.
const roomId = roomIdOf(sessionId)
- const marks = [teamRule(rt.isMain(bot.id), writesTeam(bot.id)), ...(roomId === undefined ? [] : [GROUP_HEADING])]
+ const marks = [teamRule(rt.isMain(bot.id), writesTeam(bot.id), rt.isPrivate(bot.id)), ...(roomId === undefined ? [] : [GROUP_HEADING])]
const holds = text => marks.every(mark => text.includes(mark))
const kept = frozen.get(sessionId)
if (kept !== undefined && holds(kept)) return kept
@@ -1159,7 +1171,10 @@ export function install(rt) {
const { scope, error } = namedScope(raw, botId, roomId)
if (error) return { error }
if (scope === undefined) return { scopes: roomId === undefined ? [ownScope(botId), TEAM] : [ownScope(botId), groupScope(roomId), TEAM] }
- if (scope.kind === 'bot' && scope.botId !== botId && !rt.isMain(botId)) return { error: 'Only a Main Bot can read another Bot\'s memory. Ask that Bot with message_bot instead.' }
+ if (scope.kind === 'bot' && scope.botId !== botId) {
+ const allowed = rt.isMain(botId) || (rt.isPrivate(botId) && rt.botOf(scope.botId)?.private !== true)
+ if (!allowed) return { error: 'Only a Main Bot can read another Bot\'s memory. Ask that Bot with message_bot instead.' }
+ }
return { scopes: [scope] }
}
const tagOf = (scope, botId) => (scope.kind === 'team' ? 'team' : scope.kind === 'group' ? 'group' : scope.botId === botId ? 'yours' : rt.botOf(scope.botId)?.name ?? '?')
@@ -1170,7 +1185,7 @@ export function install(rt) {
parameters: {
query: { type: 'string', description: 'Words to look for, separated by spaces. An entry must have all of them; when none has, those with the most are shown' },
topic: { type: 'string', description: 'A topic to read whole, as listed with [[topic]]' },
- scope: { type: 'string', description: 'Omit for yours, the team\'s, and in a group chat the group\'s; "own", "group", "team", or a Bot\'s name (Main Bots only)' },
+ scope: { type: 'string', description: 'Omit for yours, the team\'s, and in a group chat the group\'s; "own", "group", "team", or a Bot\'s name (Main Bots; private Bots may read public Bots)' },
},
output,
async execute(args, exec) {
diff --git a/ds-bot/src/host/privacy.js b/ds-bot/src/host/privacy.js
index e5dce639..4607de01 100644
--- a/ds-bot/src/host/privacy.js
+++ b/ds-bot/src/host/privacy.js
@@ -33,8 +33,9 @@ export function install(rt) {
const sessionsOf = bot => [...new Set([bot.id, ...(bot.sessionIds ?? [rt.chatOf(bot.id), ...(bot.segments ?? []).map(segment => segment.sessionId), ...rt.groupSessionsOf(bot.id)])])]
const dataRoots = () => [rt.dshHome, rt.home, process.env.DS_BOT_USER_DSH_HOME?.trim()].filter(Boolean)
- // A path as it is and as the file system resolves it, folded for comparing.
- const spellings = async (path) => [...new Set([fold(resolve(path)), fold(await rt.real(path))])]
+ // A path as it is and as the file system resolves it, folded for comparing. realBeyond
+ // also resolves a link above a file that does not exist yet.
+ const spellings = async (path) => [...new Set([fold(resolve(path)), fold(await rt.realBeyond(resolve(path)))])]
// The Bot a call speaks for. A subagent speaks for the Bot at the root of its
// parent chain, however many subagents sit between them.
@@ -55,8 +56,31 @@ export function install(rt) {
// Where a private Bot keeps what must stay closed: its folder and its memory. Its
// Sessions and its id are in file names under DSH's and the team's data.
- const regionsOf = async bot => (await Promise.all([bot.workDir, join(rt.home, 'memory', 'bots', bot.id), bot.archivePath].filter(Boolean).map(spellings))).flat()
- const sharedFiles = async () => (await Promise.all([rt.statePath, join(rt.home, 'memory', 'journal.jsonl')].filter(Boolean).map(spellings))).flat()
+ const regionsOf = async bot => (await Promise.all([
+ bot.workDir,
+ join(rt.home, 'memory', 'bots', bot.id),
+ join(rt.home, 'browser-profiles', bot.id),
+ join(rt.home, 'browser-downloads', bot.id),
+ join(rt.home, 'side', `${bot.id}.json`),
+ join(rt.home, 'btw', bot.id),
+ bot.archivePath,
+ ].filter(Boolean).map(spellings))).flat()
+ const sharedFiles = async () => (await Promise.all([
+ rt.statePath,
+ join(rt.home, 'chat-index.sqlite'),
+ join(rt.home, 'chat-index.sqlite-wal'),
+ join(rt.home, 'chat-index.sqlite-shm'),
+ join(rt.home, 'usage.sqlite'),
+ join(rt.home, 'usage.sqlite-wal'),
+ join(rt.home, 'usage.sqlite-shm'),
+ join(rt.home, 'inflight.json'),
+ join(rt.home, 'ocr.json'),
+ join(rt.home, 'secrets.json'),
+ join(rt.home, 'memory', 'journal.jsonl'),
+ join(rt.home, 'memory', 'journal.torn'),
+ join(rt.home, 'memory', 'pending.json'),
+ join(rt.home, 'logs', 'diagnostics.jsonl'),
+ ].filter(Boolean).map(spellings))).flat()
const teamFolder = () => rt.teamFolder() ?? resolve(rt.defaultTeamFolder())
@@ -78,11 +102,18 @@ export function install(rt) {
}
const other = bots.find(bot => bot.id !== self)
for (const file of await sharedFiles()) if (other !== undefined && keys.some(key => key.startsWith(file))) return other
- if (search && other !== undefined) {
- const open = [rt.workDirOf({ botId: self }), teamFolder()].filter(Boolean)
+ if (other !== undefined) {
+ 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 folders = (await Promise.all(open.map(spellings))).flat()
- for (const root of (await Promise.all(dataRoots().map(spellings))).flat()) {
- if (keys.some(key => within(root, key) || (within(key, root) && !folders.some(folder => within(key, folder))))) return other
+ const roots = (await Promise.all(dataRoots().map(spellings))).flat()
+ for (const key of keys) {
+ if ((!search && ownIds.some(id => key.includes(id))) || folders.some(folder => within(key, folder))) continue
+ // Direct reads are closed too, not only walks: an index, pending record or log
+ // can hold the same private text without naming the Session in its file name.
+ if (roots.some(root => within(key, root) || (search && within(root, key)))) return other
}
}
return undefined
@@ -146,7 +177,7 @@ export function install(rt) {
// Every Bot reads the shared capabilities, so saving one shares what is in it.
case 'save_capability': {
if (!isPrivate(self)) return
- const shown = [args.name, args.description, typeof args.content === 'string' ? args.content.slice(0, 500) : ''].filter(Boolean).join('\n\n')
+ const shown = JSON.stringify(args, null, 2)
await approve(exec, { en: `Let ${rt.botOf(self).name} share this with the team?\n\n${shown}`, zh: `允许 ${rt.botOf(self).name} 把下面的内容共享给团队吗?\n\n${shown}` })
return
}
@@ -155,6 +186,12 @@ export function install(rt) {
if (bot) throw closed(bot, 'turns')
return
}
+ case 'attach_capability':
+ case 'detach_capability': {
+ const bot = target(args.bot)
+ if (bot) throw closed(bot, 'capabilities')
+ return
+ }
case 'update_bot': {
const bot = target(args.bot)
if (bot) throw closed(bot, 'settings')
@@ -212,6 +249,12 @@ export function install(rt) {
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)
+ // 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) {
+ const closedBot = protectedBots().find(found => found.id !== self)
+ if (closedBot) throw closed(closedBot, 'Sessions')
+ }
}
}
@@ -249,6 +292,8 @@ export function install(rt) {
if (rt.isMain(bot.id)) throw new Error(`${bot.name} is a Main Bot, so it cannot be private`)
if (dir === undefined) throw new Error(`${bot.name} needs a folder of its own to be private`)
if (Object.values(state.rooms).some(room => room.members.includes(bot.id))) throw new Error(`${bot.name} is in a group chat, where every member reads what is said. Remove it from its groups first`)
+ const clash = await privateClash(dir, { except: bot.id })
+ if (clash) throw new Error(`${dir} is in or around the folder of ${clash.name}, a private Bot, so ${bot.name} cannot work there`)
const keys = await spellings(dir)
const others = [
['the team workspace', teamFolder()],
diff --git a/ds-bot/test/bot-settings.test.js b/ds-bot/test/bot-settings.test.js
new file mode 100644
index 00000000..cae6f688
--- /dev/null
+++ b/ds-bot/test/bot-settings.test.js
@@ -0,0 +1,63 @@
+import assert from 'node:assert/strict'
+import { fileURLToPath } from 'node:url'
+import { runInNewContext } from 'node:vm'
+import { test } from 'node:test'
+import { build } from 'esbuild'
+
+const { outputFiles } = await build({
+ entryPoints: [fileURLToPath(new URL('../src/client/bot-settings.js', import.meta.url))],
+ bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+const react = {
+ createElement: (type, props, ...children) => ({ type, props: { ...props, children: children.flat(Infinity) } }),
+ useState: initial => [typeof initial === 'function' ? initial() : initial, () => {}],
+ useEffect() {}, useLayoutEffect() {}, useMemo: make => make(), useCallback: fn => fn,
+ useRef: current => ({ current }), useId: () => 'id', Fragment: Symbol('Fragment'),
+}
+const module = { exports: {} }
+runInNewContext(outputFiles[0].text, {
+ module, exports: module.exports,
+ require: name => (name === 'react' ? react : name === 'react-dom' ? { createPortal: node => node } : {}),
+})
+const { BotSettingsForm } = module.exports
+
+function walk(node, found = []) {
+ if (Array.isArray(node)) { for (const child of node) walk(child, found); return found }
+ if (node === null || node === undefined || typeof node !== 'object') return found
+ found.push(node)
+ walk(node.props?.children, found)
+ return found
+}
+function settings(bot, { main = false, rooms = [] } = {}) {
+ const roster = { mainBotIds: main ? [bot.id] : [], mainBotId: main ? bot.id : null, rooms, models: [], memory: false }
+ return walk(BotSettingsForm({ bot, roster, actions: {}, run: fn => fn }))
+}
+const bot = { id: 'b', name: 'Writer', role: 'Writer', instructions: '', capabilities: [] }
+
+test('the Private switch is enabled only for a state the host accepts', () => {
+ const noFolder = settings(bot).find(node => node.props?.label === 'Private')
+ assert.equal(noFolder.props.disabled, true)
+ assert.equal(noFolder.props.hint, 'Choose a working folder of its own first.')
+
+ const grouped = settings({ ...bot, workDir: '/work' }, { rooms: [{ id: 'r', members: ['b'] }] }).find(node => node.props?.label === 'Private')
+ assert.equal(grouped.props.disabled, true)
+ assert.equal(grouped.props.hint, 'Leave its group chats before making it private.')
+
+ const main = settings({ ...bot, workDir: '/work' }, { main: true }).find(node => node.props?.label === 'Private')
+ assert.equal(main.props.disabled, true)
+ assert.equal(main.props.hint, 'A Main Bot cannot be private.')
+
+ const allowed = settings({ ...bot, workDir: '/work' }).find(node => node.props?.label === 'Private')
+ assert.equal(allowed.props.disabled, false)
+ assert.equal(allowed.props.on, false)
+})
+
+test('a private Bot can always turn privacy off, and cannot become Main or be duplicated', () => {
+ const tree = settings({ ...bot, workDir: '/work', private: true })
+ const privacy = tree.find(node => node.props?.label === 'Private')
+ assert.equal(privacy.props.on, true)
+ assert.equal(privacy.props.disabled, false)
+ assert.equal(tree.find(node => node.props?.label === 'Main Bot').props.disabled, true)
+ assert.equal(tree.some(node => node.props?.onClick && node.props.className === 'bt-set-row bt-bs-row' && JSON.stringify(node).includes('Duplicate')), false)
+})
diff --git a/ds-bot/test/privacy.test.js b/ds-bot/test/privacy.test.js
index 3a54d83e..c7e85413 100644
--- a/ds-bot/test/privacy.test.js
+++ b/ds-bot/test/privacy.test.js
@@ -201,6 +201,8 @@ test('other Bots cannot reach a private Bot through the tools between Bots', asy
['message_bot', { to: '@diary', message: 'hi' }, 'b'],
['message_bot', { to: P, message: 'hi' }, 'b'],
['stop_bot', { bot: 'Diary' }, 'a'],
+ ['attach_capability', { bot: 'Diary', name: 'x' }, 'a'],
+ ['detach_capability', { bot: 'Diary', name: 'x' }, 'a'],
['update_bot', { bot: 'Diary', instructions: 'x' }, 'a'],
['recall', { scope: 'Diary', query: 'x' }, 'a'],
['recall', { scope: '"Diary"' }, 'b'],
@@ -219,7 +221,7 @@ test('other Bots cannot reach a private Bot through the tools between Bots', asy
})
test('other Bots cannot read, write or search what a private Bot keeps', async (t) => {
- const { run, root, home, diary, team, project, stop } = await start()
+ const { run, root, dsh, home, diary, team, project, stop } = await start()
t.after(stop)
const notes = join(diary, 'notes.txt')
const posix = path => path.replace(/\\/g, '/')
@@ -239,6 +241,10 @@ test('other Bots cannot read, write or search what a private Bot keeps', async (
await refused('read', { file_path: join(home, 'memory', 'bots', P, 'MEMORY.md') })
await refused('read', { file_path: join(home, 'memory', 'journal.jsonl') })
await refused('read', { file_path: join(home, 'state.json') })
+ await refused('read', { file_path: join(home, 'chat-index.sqlite') })
+ await refused('read', { file_path: join(home, 'usage.sqlite') })
+ await refused('read', { file_path: join(home, 'secrets.json') })
+ await refused('read', { file_path: join(home, 'memory', 'pending.json') })
await refused('glob', { pattern: '**/*', path: diary })
await refused('glob', { pattern: '**/*.txt', path: root })
await refused('grep', { pattern: 'secret', path: root })
@@ -249,8 +255,10 @@ test('other Bots cannot read, write or search what a private Bot keeps', async (
await refused('pwsh', { command: `Get-Content '${notes}'`, workdir: project })
await refused('bash', { command: 'ls', workdir: diary })
await refused('bash', { command: `cat ${posix(join(home, 'state.json'))}` })
+ 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('session_search', { query: 'x' })
await refused('session_search', { query: 'x', session_id: P })
await refused('session_trace', { session_ids: ['b', P] })
await refused('session_event_read', { parent_session_ids: [P] })
@@ -259,12 +267,13 @@ test('other Bots cannot read, write or search what a private Bot keeps', async (
['read', { file_path: join(project, 'a.txt') }],
['read', { file_path: 'a.txt' }],
['write', { file_path: join(team, 'a.txt'), content: 'x' }],
+ ['read', { file_path: join(dsh, 'sessions', 'b.jsonl') }],
['glob', { pattern: '**/*', path: project }],
['glob', { pattern: '**/*', path: team }],
['grep', { pattern: 'x' }],
['bash', { command: 'ls', workdir: project }],
['working_directory', { cd: join(team, 'sub') }],
- ['session_search', { query: 'x', session_id: 'b' }],
+ ['session_search', { query: 'x', session_ids: ['b'] }],
]) {
assert.deepEqual(await run(name, args, 'b'), { ran: true }, `${name} ${JSON.stringify(args)}`)
}
@@ -282,6 +291,10 @@ test('a link into the folder of a private Bot is closed too', async (t) => {
const result = await run('read', { file_path: join(project, 'link', 'notes.txt') }, 'b')
assert.equal(result.ran, false)
assert.match(result.error, CLOSED)
+ // The file does not exist yet: the link above it still has to be resolved.
+ const created = await run('write', { file_path: join(project, 'link', 'new.txt'), content: 'x' }, 'b')
+ assert.equal(created.ran, false)
+ assert.match(created.error, CLOSED)
})
test('the private Bot reads its own and the team\'s files; a Session it starts speaks for it', async (t) => {
@@ -312,9 +325,15 @@ test('what a private Bot sends to the others waits for the user', async (t) => {
// The Bots that are not private send as before.
await run('message_bot', { to: 'Chief', message: 'hi' }, 'b')
assert.equal(approval.requests.length, 1)
- assert.deepEqual(await run('save_capability', { name: 'plan', kind: 'skill', content: 'steps' }, P), { ran: true })
+ const content = 'secret step '.repeat(80)
+ assert.deepEqual(await run('save_capability', { name: 'plan', kind: 'skill', content }, P), { ran: true })
assert.equal(approval.requests.length, 2)
- assert.match(approval.requests[1].reason, /share this with the team[\s\S]*steps/)
+ assert.match(approval.requests[1].reason, /share this with the team/)
+ assert.ok(approval.requests[1].reason.includes(content), 'the approval shows the whole skill, not a prefix')
+ assert.deepEqual(await run('save_capability', { name: 'search', kind: 'mcp', command: 'secret-command', args: ['--private'] }, P), { ran: true })
+ assert.equal(approval.requests.length, 3)
+ assert.match(approval.requests[2].reason, /secret-command/)
+ assert.match(approval.requests[2].reason, /--private/)
})
test('a message of a private Bot that the user does not allow is not sent', async (t) => {
@@ -359,6 +378,44 @@ test('a write of a private Bot outside its folder that the user does not allow i
assert.match(result.error, /not done/)
})
+test('one private Bot reads its own data but not another private Bot\'s', async (t) => {
+ const { rt, run, dsh, home, diary, project, stop } = await start()
+ t.after(stop)
+ const other = await rt.createBot({ name: 'Other', workDir: project })
+ await rt.updateBot(other.id, { private: true })
+ assert.deepEqual(await run('read', { file_path: join(diary, 'notes.txt') }, P), { ran: true })
+ assert.deepEqual(await run('read', { file_path: join(home, 'memory', 'bots', P, 'MEMORY.md') }, P), { ran: true })
+ assert.deepEqual(await run('read', { file_path: join(dsh, 'sessions', `${P}.jsonl`) }, P), { ran: true })
+ assert.deepEqual(await run('session_search', { query: 'x', session_ids: [P] }, P), { ran: true })
+ assert.deepEqual(await run('session_search', { query: 'x', session_ids: ['b'] }, P), { ran: true })
+ const search = await run('session_search', { query: 'x' }, P)
+ assert.equal(search.ran, false)
+ assert.match(search.error, CLOSED)
+ const otherSearch = await run('session_search', { query: 'x', session_ids: [other.id] }, P)
+ assert.equal(otherSearch.ran, false)
+ assert.match(otherSearch.error, CLOSED)
+ const result = await run('read', { file_path: join(home, 'memory', 'bots', other.id, 'MEMORY.md') }, P)
+ assert.equal(result.ran, false)
+ assert.match(result.error, CLOSED)
+ const folder = await run('read', { file_path: join(project, 'notes.txt') }, P)
+ assert.equal(folder.ran, false)
+ assert.match(folder.error, CLOSED)
+})
+
+test('a private Bot reads public memory and keeps its own journal out of the shared log', async (t) => {
+ const { tool, home, stop } = await start()
+ t.after(stop)
+ await tool('remember', { text: 'a public fact', scope: 'own' }, 'b')
+ await tool('remember', { text: 'a private fact', scope: 'own' }, P)
+ const recalled = await tool('recall', { scope: 'Writer', query: 'public fact' }, P)
+ assert.match(recalled, /a public fact/)
+ const shared = readFileSync(join(home, 'memory', 'journal.jsonl'), 'utf8')
+ assert.match(shared, /a public fact/)
+ assert.doesNotMatch(shared, /a private fact/)
+ const own = readFileSync(join(home, 'memory', 'bots', P, 'journal.jsonl'), 'utf8')
+ assert.match(own, /a private fact/)
+})
+
test('a nested subagent speaks for the private Bot at its root', async (t) => {
const approval = fakeApproval('allowed-once')
const { run, diary, agentOf, stop } = await start({ services: { approval } })
@@ -372,7 +429,7 @@ test('a nested subagent speaks for the private Bot at its root', async (t) => {
})
test('deleting a private Bot keeps its folder and archived memory closed', async (t) => {
- const { rt, run, home, diary, state, stop } = await start()
+ const { rt, run, home, diary, project, state, stop } = await start()
t.after(stop)
const memory = join(home, 'memory', 'bots', P)
mkdirSync(memory, { recursive: true })
@@ -394,6 +451,8 @@ test('deleting a private Bot keeps its folder and archived memory closed', async
assert.match(result.error, CLOSED)
}
await assert.rejects(rt.createBot({ name: 'Third', workDir: diary }), CLOSED)
+ const third = await rt.createBot({ name: 'Third', workDir: project })
+ await assert.rejects(rt.updateBot(third.id, { workDir: diary, private: true }), CLOSED)
})
test('with no private Bot the tools run as they did', async (t) => {