Skip to content

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

Complete private Bot settings and archived-data protection

Fei24111ba00be1acfa
diff --git a/docs/plans/2026-10-27-private-bots.md b/docs/plans/2026-10-27-private-bots.md
new file mode 100644
index 00000000..e3292fab
--- /dev/null
+++ b/docs/plans/2026-10-27-private-bots.md
@@ -0,0 +1,67 @@
+# 隐私 Bot
+
+- 日期:2026-10-27
+- 相关:Issue #597
+
+## 为什么
+
+团队里的 Bot 默认互相协作:能看到彼此的状态、记忆和工作内容。但有些任务只适合用户和一个 Bot 看。隐私 Bot 提供一道单向边界:它仍可以读取团队,其他 Bot 不能读取它;它向其他 Bot 分享内容时,由用户决定。
+
+这道边界只用于 Bot 之间,不是操作系统沙箱,也不对模型服务商隐藏内容。
+
+## 已定的行为
+
+### 开关
+
+- 每个 Bot 的设置页有「隐私」开关,只有用户能开关;Bot 不能通过工具改变自己或其他 Bot 的隐私状态。
+- 隐私 Bot 不能是 Main Bot,也不能加入群聊。已经是 Main Bot 或群成员的 Bot,要先取消对应身份或退出群聊。
+- 隐私 Bot 不能被复制,避免把它的指令和文件夹带进一个公开的新 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 不能在数据位置做目录遍历搜索;自己的文件夹和总工作区仍可正常使用。
+- 子 agent 继承最上层 Bot 的身份,多层嵌套不会改变这道边界。
+
+### 隐私 Bot 能做什么
+
+- 它读取公开 Bot 和团队共享内容的方式不变,包括读取其他公开 Bot 的记忆。
+- 它可以读自己的文件夹、记忆和会话,也可以读团队其他允许读取的内容。
+- 它向其他 Bot 发 `message_bot`、保存所有 Bot 都能读取的共享能力,或写自己文件夹之外的文件时,要先得到用户批准。
+- 批准卡显示接收方和要分享的内容;拒绝、取消或无法回答时,操作不执行。
+- 它在自己的文件夹里读写不需要额外批准。
+
+### 删除以后
+
+- 删除隐私 Bot 不会把它留下的内容自动公开。
+- 它原来的工作文件夹、归档记忆和会话仍受同样的 Bot 间边界保护;这些位置不能被其他 Bot、群或总工作区接管。
+- 团队保留完成这项保护所需的最少归档记录,不在 Bot 列表中显示已经删除的 Bot。
+
+## 不做什么
+
+- 不拦截 `web_fetch`、`web_search`、浏览器、MCP 或 shell 里的网络访问。只拦部分联网工具会给出虚假的安全感。
+- 不改变模型请求:隐私 Bot 使用的服务商仍会收到发给模型的内容。
+- 不修改 DSH,不宣称实现操作系统级或内核级隔离。
+- 不提供隐私群聊或隐私 Main Bot。
+
+## 已知限制
+
+- DSH 的文件沙箱不限制读取。文件工具和目录搜索的路径检查是在 DS Bot 的工具钩子里做的,不是系统安全边界。
+- shell 命令只能按其中出现的路径和会话标识做保守检查。动态拼接路径、通过相对路径向上走、遍历未直接写出隐私路径的父目录等方式仍可能绕过检查。能够执行 shell 的模型,最终仍可能读取当前系统账号有权限读取的文件。
+- 网络工具保持可用,所以隐私 Bot 仍可能把内容发到外部服务;是否允许这类任务,仍由用户按 Bot 的权限和工具配置判断。
+- 路径检查偏保守:包含隐私会话标识的路径,以及与受保护位置同前缀的个别路径,可能被一并拒绝。
+- 对尚不存在的路径,链接解析依赖当前文件系统能提供的信息;之后新建的链接不能把既有授权变成系统级隔离。
+
+## 变更
+
+- 2026-10-27:初版,Issue #597。
diff --git a/docs/plans/README.md b/docs/plans/README.md
index 283d53e4..04943d5d 100644
--- a/docs/plans/README.md
+++ b/docs/plans/README.md
@@ -38,6 +38,7 @@
|---|---|
| [DSH 让步总账](2026-10-13-dsh-concessions.md) | 因 DSH 本身的限制而做的妥协,以及桌面应用之后怎么处理。判断「是 DS Bot 的 bug 还是 DSH 的限制」先看这里 |
| [角色与权限](2026-10-07-roles-and-permissions.md) | 用户、Main Bot、群管理员、普通 Bot 各能做什么;Bot 的权限预设和群的统一权限 |
+| [隐私 Bot](2026-10-27-private-bots.md) | 只有用户能开关;其他 Bot 读不到它的文件夹、记忆和会话,外发由用户批准;独立文件夹、删除后的保护和隔离边界 |
| [群聊](2026-10-07-group-chat.md) | 谁来回答、按顺序发言、@ 提及、轮数上限、干活中的进度和迟到的回复、审批 |
| [浏览器、搜索、密钥和连接器](2026-10-08-browser-and-secrets.md) | 每个 Bot 的浏览器和 `read_browser`、`auto` 联网搜索、密钥卡和替换规则、GitHub 连接器 |
| [浏览器插件](2026-10-21-browser-plugins.md) | 全团队一个浏览器后端,每个 Bot 一份 profile;`refs` / `script` / `task` |
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 14f2ed76..b319bedd 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1050,6 +1050,11 @@ var ZH = {
"Working folder: {folder}": "工作文件夹:{folder}",
Folder: "文件夹",
Folders: "文件夹",
+ Privacy: "隐私",
+ 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。",
+ "A private Bot cannot be a Main Bot.": "隐私 Bot 不能设为主 Bot。",
"Team workspace": "总工作区",
"Team workspace: {folder}": "总工作区:{folder}",
"Where Bots without a folder of their own work.": "没有单独设置文件夹的 Bot 在这里工作。",
@@ -1096,6 +1101,17 @@ var HOST_ERRORS = [
[/^There is no folder at (.+)$/, "找不到文件夹 $1"],
[/^(.+) is a file, not a folder$/, "$1 是文件,不是文件夹"],
[/^(.+) holds DeepSeek Harness data, so Bots cannot work there$/, "$1 里有 DeepSeek Harness 的数据,Bot 不能在这里工作"],
+ [/^(.+) needs a folder of its own to be private$/, "$1 需要有自己的工作文件夹,才能设为隐私 Bot"],
+ [/^(.+) is a Main Bot, so it cannot be private$/, "$1 是主 Bot,不能设为隐私 Bot"],
+ [/^(.+) is in a group chat, where every member reads what is said\. Remove it from its groups first$/, "$1 还在群聊里,群成员都能看到群里的内容。请先把它移出群聊"],
+ [/^(.+) is private, so it cannot be a Main Bot$/, "$1 是隐私 Bot,不能设为主 Bot"],
+ [/^(.+) is private, so it cannot be copied$/, "$1 是隐私 Bot,不能复制"],
+ [/^(.+) is a private Bot and cannot be in a group chat: what is said in a group is read by every member$/, "$1 是隐私 Bot,不能加入群聊:群成员都能看到群里的内容"],
+ [/^(.+) is in or around the team workspace, so (.+) cannot be private there\. Give it a folder of its own$/, "$1 与总工作区重叠,$2 不能在这里设为隐私 Bot。请给它一个独立文件夹"],
+ [/^(.+) is in or around the folder of (.+), so (.+) cannot be private there\. Give it a folder of its own$/, "$1 与「$2」的文件夹重叠,$3 不能在这里设为隐私 Bot。请给它一个独立文件夹"],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so (.+) cannot work there$/, "$1 在隐私 Bot「$2」的文件夹内或外层,$3 不能在这里工作"],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so a group cannot work there$/, "$1 在隐私 Bot「$2」的文件夹内或外层,群聊不能在这里工作"],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so it cannot be the team workspace$/, "$1 在隐私 Bot「$2」的文件夹内或外层,不能作为总工作区"],
// Memory changes the memory panel asked for; the whole message is matched.
[/^This looks like a key, token, or password[\s\S]*$/, "看起来像密钥、令牌或密码,记忆不会保存这类内容"],
[/^An entry holds at most (\d+) characters; this one has (\d+)\.[\s\S]*$/, "一条记忆最多 $1 个字符,这条有 $2 个"],
@@ -12161,6 +12177,17 @@ function BotSettingsForm({ bot, roster, actions, run: run2 }) {
(0, import_react25.createElement)(FolderMenu, { value: bot.workDir, actions, run: run2, onPick: (workDir) => save({ workDir }) })
)
),
+ (0, import_react25.createElement)(
+ Card,
+ { 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."),
+ on: bot.private === true,
+ disabled: isMainBot,
+ onChange: (value) => save({ private: value })
+ })
+ ),
(0, import_react25.createElement)(
Card,
{ title: t("Instructions") },
@@ -12186,7 +12213,13 @@ function BotSettingsForm({ bot, roster, actions, run: run2 }) {
(0, import_react25.createElement)("span", { className: "bt-set-hint" }, t("The only Main Bot. To hand the role to another Bot, use Main Bot on the Bots page."))
),
(0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => actions.openSettings("bots") }, t("Change"))
- ) : (0, import_react25.createElement)(SwitchRow, { label: t("Main Bot"), hint: t("Can create and change Bots, and runs every group chat."), on: isMainBot, onChange: (on) => run2(actions.setMain(bot.id, on)) })
+ ) : (0, import_react25.createElement)(SwitchRow, {
+ label: t("Main Bot"),
+ hint: bot.private === true ? t("A private Bot cannot be a Main Bot.") : t("Can create and change Bots, and runs every group chat."),
+ on: isMainBot,
+ disabled: bot.private === true,
+ onChange: (on) => run2(actions.setMain(bot.id, on))
+ })
),
// The Main Bot tile is always first and always shown, like in the context menu.
isTile ? null : (0, import_react25.createElement)(
@@ -12198,7 +12231,7 @@ function BotSettingsForm({ bot, roster, actions, run: run2 }) {
(0, import_react25.createElement)(
Card,
{ title: t("Manage") },
- (0, import_react25.createElement)(
+ bot.private === true ? null : (0, import_react25.createElement)(
"button",
{ type: "button", className: "bt-set-row bt-bs-row", onClick: duplicate },
(0, import_react25.createElement)("span", { className: "bt-set-copy" }, (0, import_react25.createElement)("span", { className: "bt-bs-label" }, t("Duplicate")), (0, import_react25.createElement)("span", { className: "bt-set-hint" }, t("A copy with the same job and model, and fresh memory."))),
diff --git a/ds-bot/src/client/bot-settings.js b/ds-bot/src/client/bot-settings.js
index 21d287c5..34bebc24 100644
--- a/ds-bot/src/client/bot-settings.js
+++ b/ds-bot/src/client/bot-settings.js
@@ -228,6 +228,14 @@ export function BotSettingsForm({ bot, roster, actions, run }) {
h('div', { className: 'bt-set-row bt-bs-row' },
h('span', { className: 'bt-set-copy' }, h('span', { className: 'bt-bs-label' }, t('Folder'))),
h(FolderMenu, { value: bot.workDir, actions, run, onPick: workDir => save({ workDir }) }))),
+ 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.'),
+ on: bot.private === true,
+ disabled: isMainBot,
+ onChange: value => save({ private: value }),
+ })),
h(Card, { title: t('Instructions') },
h(Row, { label: t('What this Bot does'), hint: t('Its job on the team. Part of the Bot\'s system prompt.'), stack: true },
h(InlineText, { label: t('Instructions'), value: bot.instructions, multiline: true, placeholder: t('What this Bot is responsible for…'), onSave: instructions => save({ instructions }) }))),
@@ -241,13 +249,19 @@ export function BotSettingsForm({ bot, roster, actions, run }) {
h('span', { className: 'bt-bs-label' }, t('Main Bot')),
h('span', { className: 'bt-set-hint' }, t('The only Main Bot. To hand the role to another Bot, use Main Bot on the Bots page.'))),
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => actions.openSettings('bots') }, t('Change')))
- : h(SwitchRow, { label: t('Main Bot'), hint: t('Can create and change Bots, and runs every group chat.'), on: isMainBot, onChange: on => run(actions.setMain(bot.id, on)) })),
+ : h(SwitchRow, {
+ label: t('Main Bot'),
+ hint: bot.private === true ? t('A private Bot cannot be a Main Bot.') : t('Can create and change Bots, and runs every group chat.'),
+ on: isMainBot,
+ disabled: bot.private === true,
+ onChange: on => run(actions.setMain(bot.id, on)),
+ })),
// The Main Bot tile is always first and always shown, like in the context menu.
isTile ? null : h(Card, { title: t('Sidebar') },
h(SwitchRow, { label: t('Pin'), hint: t('Kept above the other chats.'), on: bot.pinned === true, onChange: pinned => run(actions.setFlags(bot.id, { pinned })) }),
isMainBot ? null : h(SwitchRow, { label: t('Hide from sidebar'), hint: t('Search still finds it.'), on: bot.hidden === true, onChange: hidden => run(actions.setFlags(bot.id, { hidden })) })),
h(Card, { title: t('Manage') },
- h('button', { type: 'button', className: 'bt-set-row bt-bs-row', onClick: duplicate },
+ bot.private === true ? null : h('button', { type: 'button', className: 'bt-set-row bt-bs-row', onClick: duplicate },
h('span', { className: 'bt-set-copy' }, h('span', { className: 'bt-bs-label' }, t('Duplicate')), h('span', { className: 'bt-set-hint' }, t('A copy with the same job and model, and fresh memory.'))),
h('span', { className: 'bt-chevron' }, h(ChevronRightIcon))),
isMainBot ? null : h('button', { type: 'button', className: 'bt-set-row bt-bs-row bt-bs-danger', 'data-confirm': confirming || undefined, onClick: remove },
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 3eb93caa..e1e2f26b 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -1002,6 +1002,11 @@ const ZH = {
'Working folder: {folder}': '工作文件夹:{folder}',
Folder: '文件夹',
Folders: '文件夹',
+ Privacy: '隐私',
+ 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。',
+ 'A private Bot cannot be a Main Bot.': '隐私 Bot 不能设为主 Bot。',
'Team workspace': '总工作区',
'Team workspace: {folder}': '总工作区:{folder}',
'Where Bots without a folder of their own work.': '没有单独设置文件夹的 Bot 在这里工作。',
@@ -1051,6 +1056,17 @@ const HOST_ERRORS = [
[/^There is no folder at (.+)$/, '找不到文件夹 $1'],
[/^(.+) is a file, not a folder$/, '$1 是文件,不是文件夹'],
[/^(.+) holds DeepSeek Harness data, so Bots cannot work there$/, '$1 里有 DeepSeek Harness 的数据,Bot 不能在这里工作'],
+ [/^(.+) needs a folder of its own to be private$/, '$1 需要有自己的工作文件夹,才能设为隐私 Bot'],
+ [/^(.+) is a Main Bot, so it cannot be private$/, '$1 是主 Bot,不能设为隐私 Bot'],
+ [/^(.+) is in a group chat, where every member reads what is said\. Remove it from its groups first$/, '$1 还在群聊里,群成员都能看到群里的内容。请先把它移出群聊'],
+ [/^(.+) is private, so it cannot be a Main Bot$/, '$1 是隐私 Bot,不能设为主 Bot'],
+ [/^(.+) is private, so it cannot be copied$/, '$1 是隐私 Bot,不能复制'],
+ [/^(.+) is a private Bot and cannot be in a group chat: what is said in a group is read by every member$/, '$1 是隐私 Bot,不能加入群聊:群成员都能看到群里的内容'],
+ [/^(.+) is in or around the team workspace, so (.+) cannot be private there\. Give it a folder of its own$/, '$1 与总工作区重叠,$2 不能在这里设为隐私 Bot。请给它一个独立文件夹'],
+ [/^(.+) is in or around the folder of (.+), so (.+) cannot be private there\. Give it a folder of its own$/, '$1 与「$2」的文件夹重叠,$3 不能在这里设为隐私 Bot。请给它一个独立文件夹'],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so (.+) cannot work there$/, '$1 在隐私 Bot「$2」的文件夹内或外层,$3 不能在这里工作'],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so a group cannot work there$/, '$1 在隐私 Bot「$2」的文件夹内或外层,群聊不能在这里工作'],
+ [/^(.+) is in or around the folder of (.+), a private Bot, so it cannot be the team workspace$/, '$1 在隐私 Bot「$2」的文件夹内或外层,不能作为总工作区'],
// Memory changes the memory panel asked for; the whole message is matched.
[/^This looks like a key, token, or password[\s\S]*$/, '看起来像密钥、令牌或密码,记忆不会保存这类内容'],
[/^An entry holds at most (\d+) characters; this one has (\d+)\.[\s\S]*$/, '一条记忆最多 $1 个字符,这条有 $2 个'],
diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.js
index de583e91..e0a60d3e 100644
--- a/ds-bot/src/host/memory.js
+++ b/ds-bot/src/host/memory.js
@@ -859,6 +859,7 @@ export function install(rt) {
await mkdir(join(root, 'archive'), { recursive: true })
await rename(dir, join(root, 'archive', name))
await journalRow({ id: randomUUID(), time: new Date().toISOString(), op: 'archive', scope: scopeKey(ownScope(botId)), actor: 'user', actorName: 'user', botName: bot?.name, to: `archive/${name}` })
+ 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.js
index e9dd059a..e5dce639 100644
--- a/ds-bot/src/host/privacy.js
+++ b/ds-bot/src/host/privacy.js
@@ -28,23 +28,34 @@ export function install(rt) {
const isPrivate = id => rt.botOf(id)?.private === true
const privateBots = () => Object.values(state.bots).filter(bot => bot.private === true)
- const sessionsOf = bot => [...new Set([bot.id, rt.chatOf(bot.id), ...(bot.segments ?? []).map(segment => segment.sessionId), ...rt.groupSessionsOf(bot.id)])]
+ // Deleting a private Bot does not make the files and memory it leaves behind public.
+ const protectedBots = () => [...new Map([...(state.privateArchives ?? []), ...privateBots()].map(bot => [bot.id, bot])).values()]
+ 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))])]
- // The Bot a call speaks for. A subagent speaks for the Bot that started it.
- const callerOf = (exec) => {
- const own = rt.selfOf(exec.agent?.id)
+ // 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.
+ const callerOf = async (exec) => {
+ const own = rt.selfOf(exec.agent?.id) ?? rt.selfOf(exec.agent?.session?.id)
if (own !== undefined) return own
- const parent = exec.agent?.session?.header?.parentSession
- return parent === undefined ? undefined : rt.selfOf(parent)
+ let parent = exec.agent?.session?.header?.parentSession
+ const seen = new Set()
+ while (parent !== undefined && !seen.has(parent)) {
+ seen.add(parent)
+ const owner = rt.selfOf(parent)
+ if (owner !== undefined) return owner
+ const agent = await rt.resolveAgent(parent).catch(() => undefined)
+ parent = agent?.session?.header?.parentSession
+ }
+ return undefined
}
// 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)].filter(Boolean).map(spellings))).flat()
+ 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 teamFolder = () => rt.teamFolder() ?? resolve(rt.defaultTeamFolder())
@@ -53,7 +64,7 @@ export function install(rt) {
// `search` is for tools that walk a folder: a folder that holds a closed one is closed
// too, and so are the data folders, where the walk cannot be told which files to skip.
async function ownerOfPath(path, { self, search = false, base } = {}) {
- const bots = privateBots()
+ const bots = protectedBots()
if (bots.length === 0) return undefined
const keys = await spellings(base === undefined ? path : resolve(base, path))
for (const bot of bots) {
@@ -65,8 +76,8 @@ export function install(rt) {
if (needles.some(needle => key.includes(needle))) return bot
}
}
- for (const file of await sharedFiles()) if (keys.some(key => key.startsWith(file))) return bots[0]
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)
const folders = (await Promise.all(open.map(spellings))).flat()
@@ -81,12 +92,14 @@ export function install(rt) {
// command builds, or reaches by walking up from a folder, is not seen.
async function ownerInText(text, self) {
const flat = fold(text.replace(/\\/g, '/'))
- for (const bot of privateBots()) {
+ const bots = protectedBots()
+ for (const bot of bots) {
if (bot.id === self) continue
const spelled = (await regionsOf(bot)).flatMap(asShell)
if (spelled.some(region => flat.includes(region)) || sessionsOf(bot).some(id => flat.includes(fold(id)))) return bot
}
- for (const file of await sharedFiles()) if (asShell(file).some(spelled => flat.includes(spelled))) return privateBots()[0]
+ const other = bots.find(bot => bot.id !== self)
+ for (const file of await sharedFiles()) if (other !== undefined && asShell(file).some(spelled => flat.includes(spelled))) return other
return undefined
}
@@ -197,15 +210,15 @@ export function install(rt) {
}
if (SESSION_TOOLS.includes(name)) {
const asked = strings([args.session_id, args.session_ids, args.parent_session_ids])
- const bot = privateBots().find(found => found.id !== self && sessionsOf(found).some(id => asked.includes(id)))
+ const bot = protectedBots().find(found => found.id !== self && sessionsOf(found).some(id => asked.includes(id)))
if (bot) refuse(bot)
}
}
// Before the tools' own hooks, so that a closed call never reaches a card they show.
ctx.on('tools/execute', async (exec, next) => {
- if (privateBots().length === 0) return next()
- const self = callerOf(exec)
+ if (protectedBots().length === 0) return next()
+ const self = await callerOf(exec)
await guardTeam(exec, self)
await guardFiles(exec, self)
return next()
@@ -214,7 +227,7 @@ export function install(rt) {
// A folder that a private Bot's folder would overlap, or that overlaps one.
async function privateClash(path, { except } = {}) {
const keys = await spellings(path)
- for (const bot of privateBots()) {
+ for (const bot of protectedBots()) {
if (bot.id === except || bot.workDir === undefined) continue
const dirs = await spellings(bot.workDir)
if (keys.some(key => dirs.some(dir => overlap(key, dir)))) return bot
diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.js
index 4c418978..e4048a98 100644
--- a/ds-bot/src/host/roster.js
+++ b/ds-bot/src/host/roster.js
@@ -605,7 +605,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)])
+ const closedArchive = bot.private === true ? {
+ id: bot.id,
+ name: bot.name,
+ ...(bot.workDir === undefined ? {} : { workDir: bot.workDir }),
+ sessionIds: [...parts, ...rt.groupSessionsOf(id)],
+ } : undefined
await rt.releaseBot(id, [...parts, ...rt.groupSessionsOf(id)])
+ if (closedArchive !== undefined) state.privateArchives = [...(state.privateArchives ?? []).filter(entry => entry.id !== id), closedArchive]
delete state.bots[id]
for (const part of parts) {
delete state.questions[part]
@@ -623,7 +630,8 @@ export function install(rt) {
}
await followMemberNames(touched)
await rt.forgetBotSecrets(id)
- await archived
+ const archivePath = await archived
+ if (closedArchive !== undefined && archivePath !== undefined) closedArchive.archivePath = archivePath
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/src/host/store.js b/ds-bot/src/host/store.js
index e3c260f9..a20a0b3e 100644
--- a/ds-bot/src/host/store.js
+++ b/ds-bot/src/host/store.js
@@ -18,8 +18,8 @@ export const own = (table, key) => (table != null && Object.hasOwn(table, key) ?
export function install(rt) {
const { ctx, home, statePath } = rt
- /** @type {{version:1, workspaceId?:string, mainBotIds:string[], bots:Record<string,any>, rooms:Record<string,any>, agents:Record<string,any>, capabilities:{items:Record<string,any>}, exchanges:any[], exchangeTurns:Record<string,number[]>, revision:number}} */
- const state = { version: 1, mainBotIds: [], bots: {}, rooms: {}, agents: {}, capabilities: { items: {} }, exchanges: [], exchangeTurns: {}, works: {}, requests: {}, questions: {}, views: {}, prefs: {}, switching: {}, revision: 0 }
+ /** @type {{version:1, workspaceId?:string, mainBotIds:string[], bots:Record<string,any>, privateArchives:any[], rooms:Record<string,any>, agents:Record<string,any>, capabilities:{items:Record<string,any>}, exchanges:any[], exchangeTurns:Record<string,number[]>, revision:number}} */
+ const state = { version: 1, mainBotIds: [], bots: {}, privateArchives: [], rooms: {}, agents: {}, capabilities: { items: {} }, exchanges: [], exchangeTurns: {}, works: {}, requests: {}, questions: {}, views: {}, prefs: {}, switching: {}, revision: 0 }
let loaded = null
let writing = Promise.resolve()
const { warn } = rt
@@ -143,6 +143,7 @@ export function install(rt) {
migrated = true
}
state.mainBotIds = state.mainBotIds.filter(id => state.bots[id])
+ if (!Array.isArray(state.privateArchives)) state.privateArchives = []
// Teams from before the whale was stored at setup: their first Bot, while still a
// Main Bot, gets it once wherever it has no look of its own. After that the whale is
// an ordinary look the user can change, and it never passes to another Bot.
diff --git a/ds-bot/test/privacy.test.js b/ds-bot/test/privacy.test.js
index f87f33ab..3a54d83e 100644
--- a/ds-bot/test/privacy.test.js
+++ b/ds-bot/test/privacy.test.js
@@ -359,6 +359,43 @@ test('a write of a private Bot outside its folder that the user does not allow i
assert.match(result.error, /not done/)
})
+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 } })
+ t.after(stop)
+ agentOf('sub1').session.header.parentSession = P
+ const nested = { id: 'sub2', session: { id: 'sub2', header: { cwd: diary, 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/)
+})
+
+test('deleting a private Bot keeps its folder and archived memory closed', async (t) => {
+ const { rt, run, home, diary, state, stop } = await start()
+ t.after(stop)
+ const memory = join(home, 'memory', 'bots', P)
+ mkdirSync(memory, { recursive: true })
+ writeFileSync(join(memory, 'MEMORY.md'), 'private memory')
+ await rt.deleteBot(P)
+ assert.equal(state().bots[P], undefined)
+ const archived = state().privateArchives
+ assert.equal(archived.length, 1)
+ assert.equal(archived[0].id, P)
+ assert.equal(typeof archived[0].archivePath, 'string')
+ for (const [name, args] of [
+ ['read', { file_path: join(diary, 'notes.txt') }],
+ ['read', { file_path: join(archived[0].archivePath, 'MEMORY.md') }],
+ ['glob', { pattern: '**/*', path: home }],
+ ['session_trace', { session_id: P }],
+ ]) {
+ const result = await run(name, args, 'b')
+ assert.equal(result.ran, false, name)
+ assert.match(result.error, CLOSED)
+ }
+ await assert.rejects(rt.createBot({ name: 'Third', workDir: diary }), CLOSED)
+})
+
test('with no private Bot the tools run as they did', async (t) => {
const { run, diary, stop } = await start({ privateBot: false })
t.after(stop)