Skip to content

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

Keep Bots out of the user's own DSH data in the desktop app

Fei24117190ac7a2445
diff --git a/app/README.md b/app/README.md
index 399264c0..7dded765 100644
--- a/app/README.md
+++ b/app/README.md
@@ -17,7 +17,7 @@ npm installs `ds-bot` from `../ds-bot` as a copy of its package files (`install-
| Variable | What it sets | Default |
|---|---|---|
| `DS_BOT_HOME` | The data location: the `DSH_HOME` of the app. When it is set, the app asks nothing at its first start and imports nothing | The folder chosen at the first start |
-| `DS_BOT_WORKSPACE` | With `DS_BOT_HOME`: the folder for the files that Bots make | `bot/workspace` in the data location |
+| `DS_BOT_WORKSPACE` | With `DS_BOT_HOME`: the team workspace | `bot/workspace` in the data location |
| `DS_BOT_SHELL_DATA` | The app's own data (window, Chromium storage, `locations.json`) | Electron's `userData` (Windows: `%APPDATA%\DeepSeek Bot`; macOS: `~/Library/Application Support/DeepSeek Bot`) |
| `DS_BOT_UPDATE_URL` | Windows: a folder URL with `latest.yml` and its installer. macOS: a URL returning a JSON list like GitHub's `releases` API; a release counts only when this Mac's zip is attached. Prereleases count only for prerelease installs (see [Updates](#updates)). With `DS_BOT_HOME`, the app checks only when this is set | The newest GitHub release |
@@ -27,7 +27,7 @@ On macOS, Electron's default `userData` directory for `productName` "DeepSeek Bo
At its first start the app asks, in system dialogs, for the data location (`~/.ds-bot` by default) and the team workspace (`~/DeepSeek Bot`), and keeps the answer in `locations.json` in its own data. Neither folder may be inside the other or inside the user's DSH data.
-Both change later in DS Bot's Settings > General > Locations. The plugin moves the team workspace and tells the app, which writes it into `locations.json`. The data location moves through the app (`src/move-data.mjs`): the new folder must be empty or new and apart from the old data, the team workspace, the user's DSH data and the program folder. The app stops the Host, copies the data (without the team's lock) into a staging folder beside the new one, renames it to the new folder once it is whole, writes `locations.json` and starts again. A failed or interrupted copy leaves the old location in use and removes the staging folder; the old folder always stays. A run on throwaway folders (`DS_BOT_HOME`) keeps its data location.
+Both change later in DS Bot's Settings > General > Locations. The plugin moves the team workspace and tells the app, which writes it into `locations.json`. The app names the user's DSH data to the plugin (`DS_BOT_USER_DSH_HOME`), so that neither the team workspace nor a Bot's folder can be set there. The data location moves through the app (`src/move-data.mjs`): the new folder must be empty or new and apart from the old data, the team workspace, the user's DSH data and the program folder. The app stops the Host, copies the data (without the team's lock) into a staging folder beside the new one, renames it to the new folder once it is whole, writes `locations.json` and starts again. A failed or interrupted copy leaves the old location in use and removes the staging folder; the old folder always stays. A run on throwaway folders (`DS_BOT_HOME`) keeps its data location.
When the user's DSH (`DSH_HOME`, else `~/.dsh`) has a Bot team, the app offers to copy it (`src/import.mjs`). It only reads there. Before the copy it checks that no running DSH holds the team and that no chat is in a newer session format than the pinned DSH reads. Then the pinned DSH reads each chat once: a newer DSH can write records that the pinned one refuses in the same format. It reads a throwaway copy in the data location, with a profile of its own (`import-check`: `dsh-base` and `dsh-web-app`, without `ds-bot`), and removes the copy afterwards. A chat that a newer DSH wrote stops the copy as a newer format does; a damaged one does not, since the user's DSH cannot read it either. Then the app starts the Host once on the new data location, so that DSH does not register the copied Sessions' folders as projects. The copy takes `bot/` (without its lock, turns in flight and workspace), every Session the team names, the attachments, `.credentials.yaml`, `.env`, the model rows of one profile's `cordis.patch.yml`, and the old team workspace's files, which go into the new folder without replacing a file there. `bot/imported.json` records it. At its next turn, each Bot and group moves on to a fresh part in the new folder.
diff --git a/app/src/main.mjs b/app/src/main.mjs
index f5364720..ecd74255 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -104,7 +104,7 @@ async function start() {
const newHost = () => new HostProcess({
entry: join(here, 'host.mjs'),
cwd: profileDir,
- env: { ...process.env, DSH_HOME: where.dataDir, DS_BOT_APP: '1', ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },
+ env: { ...process.env, DSH_HOME: where.dataDir, DS_BOT_APP: '1', DS_BOT_USER_DSH_HOME: userDshHome(), ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },
pnpm,
onFailure: fail,
})
diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.js
index 5f761546..495f6081 100644
--- a/ds-bot/src/host/folders.js
+++ b/ds-bot/src/host/folders.js
@@ -52,11 +52,14 @@ export function install(rt) {
return workDirOf({ botId: rt.selfOf?.(id), roomId: rt.groupOwners?.get(id)?.roomId }) ?? teamFolder()
}
+ // The desktop app runs its own DSH and names the user's, which Bots must not write either.
+ const dataRoots = () => [rt.dshHome, rt.home, process.env.DS_BOT_USER_DSH_HOME?.trim()].filter(Boolean)
+
// A Bot that could write where DSH or the team keeps its data could change its own
// permissions or the team, so neither those folders nor one that holds them is allowed.
async function guarded(path) {
const team = await realTeam()
- for (const root of [rt.dshHome, rt.home]) {
+ for (const root of dataRoots()) {
const data = await real(root)
if (within(data, path)) return true
if (within(path, data) && !(team !== undefined && within(path, team))) return true
@@ -99,7 +102,7 @@ export function install(rt) {
const fallback = resolve(defaultTeamFolder())
const own = join(await realBeyond(dirname(fallback)), basename(fallback))
const holdsData = async (path) => {
- const roots = await Promise.all([rt.dshHome, rt.home].map(real))
+ const roots = await Promise.all(dataRoots().map(real))
if (roots.some(data => within(data, path))) return true
if (path === own && await realBeyond(fallback) === own) return false
return roots.some(data => within(path, data))
diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.js
index 09a5414e..ef92184f 100644
--- a/ds-bot/test/work-dir.test.js
+++ b/ds-bot/test/work-dir.test.js
@@ -619,6 +619,19 @@ test('the team workspace holds no DeepSeek Harness data, apart from the plugin\'
assert.equal(state().workspaceId, 'w-new')
})
+test('in the desktop app the user\'s own DSH data is no team workspace and no Bot\'s folder either', async (t) => {
+ const { root, state, call, stop } = await start()
+ t.after(stop)
+ const user = join(root, 'user-dsh')
+ mkdirSync(join(user, 'profiles'), { recursive: true })
+ process.env.DS_BOT_USER_DSH_HOME = user
+ t.after(() => { delete process.env.DS_BOT_USER_DSH_HOME })
+ assert.match((await call('team-workspace', { path: join(user, 'new') })).error?.message, /holds DeepSeek Harness data/)
+ assert.equal(existsSync(join(user, 'new')), false)
+ assert.equal((await call('update-bot', { id: 'b', workDir: join(user, 'profiles') })).error?.message, `${join(user, 'profiles')} holds DeepSeek Harness data, so Bots cannot work there`)
+ assert.equal(state().workspaceId, 'w1')
+})
+
test('a team folder that was deleted is made again before DSH checks it', async (t) => {
const { sets, service } = folderService()
const { ctx, agentOf, team, stop } = await start({ services: { workingDirectory: service } })