A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Let the user move the team workspace from DS Bot settings
Fei24112815add4b85b
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 65ca56dc..34692961 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -943,7 +943,12 @@ var ZH = {"Working folder: {folder}": "工作文件夹:{folder}",Folder: "文件夹",Folders: "文件夹",- "Team workspace": "团队工作区",+ "Team workspace": "总工作区",+ "Team workspace: {folder}": "总工作区:{folder}",+ "Where Bots without a folder of their own work.": "没有单独设置文件夹的 Bot 在这里工作。",+ Locations: "位置",+ "Data location": "数据位置",+ "Change…": "更改…","Each Bot's own folder": "各 Bot 自己的文件夹","Choose a folder…": "选择文件夹…","Browse folders…": "浏览文件夹…",@@ -1459,6 +1464,7 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cardsfolders: () => call2("folders"),folderPick: () => call2("folder-pick"),folderList: (path) => call2("folder-list", { path: path ?? "" }),+ setTeamWorkspace: (path) => after(call2("team-workspace", { path })),deleteBot: (id) => after(call2("delete-bot", { id })),duplicateBot: (id) => after(call2("duplicate-bot", { id })),setPrefs: (prefs) => after(call2("set-prefs", prefs)),@@ -7231,7 +7237,7 @@ var import_react15 = require("react");var import_react_dom7 = require("react-dom");var folderName = (path) => String(path).replace(/[\\/]+$/, "").split(/[\\/]/).pop() || String(path);var Tick = ({ on }) => (0, import_react15.createElement)("span", { className: "bt-model-tick", "aria-hidden": true }, on ? (0, import_react15.createElement)(CheckIcon) : null);-function FolderMenu({ value, group = false, actions, run, onPick, wide = false }) {+function FolderMenu({ value, group = false, team = false, actions, run, onPick, wide = false }) {const { isOpen, shownPlace, leaving, button, menu, open, close } = useAnchoredMenu();const [info, setInfo] = (0, import_react15.useState)(null);const [view, setView] = (0, import_react15.useState)("list");@@ -7273,7 +7279,7 @@ function FolderMenu({ value, group = false, actions, run, onPick, wide = false }const listView = (0, import_react15.createElement)("div",{ key: "list", className: "bt-folder-view" },- (0, import_react15.createElement)(+ team ? null : (0, import_react15.createElement)("button",{ type: "button", role: "menuitemradio", "aria-checked": !value, title: group ? void 0 : info?.team ?? void 0, onClick: () => choose("") },(0, import_react15.createElement)("span", { className: "bt-menu-label" }, fallback),@@ -7345,7 +7351,7 @@ function FolderMenu({ value, group = false, actions, run, onPick, wide = false }"data-wide": wide || void 0,"aria-haspopup": "menu","aria-expanded": isOpen,- "aria-label": t("Working folder: {folder}", { folder: value ?? fallback }),+ "aria-label": team ? t("Team workspace: {folder}", { folder: value ?? "" }) : t("Working folder: {folder}", { folder: value ?? fallback }),title: value,onClick: toggle},@@ -7359,7 +7365,7 @@ function FolderMenu({ value, group = false, actions, run, onPick, wide = false }),shownPlace ? (0, import_react_dom7.createPortal)((0, import_react15.createElement)("div",- { ref: menu, className: `bt-menu bt-model-menu bt-folder-menu${shownPlace.bottom !== void 0 ? " bt-menu-up" : ""}`, role: "menu", "aria-label": t("Working folder"), style: shownPlace, "data-leaving": leaving || void 0 },+ { ref: menu, className: `bt-menu bt-model-menu bt-folder-menu${shownPlace.bottom !== void 0 ? " bt-menu-up" : ""}`, role: "menu", "aria-label": team ? t("Team workspace") : t("Working folder"), style: shownPlace, "data-leaving": leaving || void 0 },shownView,problem ? (0, import_react15.createElement)("div", { className: "bt-folder-error", role: "alert" }, problem) : null), document.body) : null@@ -11552,9 +11558,39 @@ function GeneralPage({ roster, actions, run }) {{ label: t("Classic Agent mode") },(0, import_react31.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => actions.setSurface("agent") }, t("Switch")))- ) : null+ ) : null,+ (0, import_react31.createElement)(LocationsSection, { key: "places", actions, run })];}+function LocationsSection({ actions, run }) {+ const app = globalThis.dsBotApp;+ const [team, setTeam] = (0, import_react31.useState)(null);+ const [data, setData] = (0, import_react31.useState)(null);+ (0, import_react31.useEffect)(() => {+ void Promise.resolve(actions.folders()).then((info) => setTeam(info?.team ?? null)).catch(() => {+ });+ if (app !== void 0) void Promise.resolve(app.dataLocation()).then(setData).catch(() => {+ });+ }, []);+ const pickTeam = (path) => run(Promise.resolve(actions.setTeamWorkspace(path)).then((answer) => {+ setTeam(answer.team);+ app?.teamWorkspaceChanged(answer.team);+ }));+ return (0, import_react31.createElement)(+ SetSection,+ { title: t("Locations") },+ (0, import_react31.createElement)(+ SetRow,+ { label: t("Team workspace"), hint: t("Where Bots without a folder of their own work.") },+ team === null ? null : (0, import_react31.createElement)(FolderMenu, { value: team, team: true, actions, run, onPick: pickTeam })+ ),+ data === null ? null : (0, import_react31.createElement)(+ SetRow,+ { label: t("Data location"), hint: data.path },+ data.fixed ? null : (0, import_react31.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => run(app.moveData(team ?? void 0)) }, t("Change…"))+ )+ );+}function MainBotsSection({ roster, actions, run }) {const mains = (roster.mainBotIds ?? []).map((id) => roster.byId[id]).filter(Boolean);const [first, ...others] = mains;diff --git a/ds-bot/src/client/folder-menu.js b/ds-bot/src/client/folder-menu.jsindex d715b750..ca40ad29 100644--- a/ds-bot/src/client/folder-menu.js+++ b/ds-bot/src/client/folder-menu.js@@ -11,8 +11,9 @@ const Tick = ({ on }) => h('span', { className: 'bt-model-tick', 'aria-hidden':// Where a Bot, or every member of a group, works. `value` is the saved folder; without// one a Bot works in the team workspace and a group member in its own folder. `onPick`-// gets the chosen path, or '' for that default.-export function FolderMenu({ value, group = false, actions, run, onPick, wide = false }) {+// gets the chosen path, or '' for that default. `team` is the menu for the team workspace+// itself, which has no default.+export function FolderMenu({ value, group = false, team = false, actions, run, onPick, wide = false }) {const { isOpen, shownPlace, leaving, button, menu, open, close } = useAnchoredMenu()const [info, setInfo] = useState(null)const [view, setView] = useState('list')@@ -48,7 +49,7 @@ export function FolderMenu({ value, group = false, actions, run, onPick, wide =const known = info?.folders ?? []const folders = value && !known.some(folder => folder.path === value) ? [{ path: value, title: folderName(value) }, ...known] : knownconst listView = h('div', { key: 'list', className: 'bt-folder-view' },- h('button', { type: 'button', role: 'menuitemradio', 'aria-checked': !value, title: group ? undefined : info?.team ?? undefined, onClick: () => choose('') },+ team ? null : h('button', { type: 'button', role: 'menuitemradio', 'aria-checked': !value, title: group ? undefined : info?.team ?? undefined, onClick: () => choose('') },h('span', { className: 'bt-menu-label' }, fallback), h(Tick, { on: !value })),folders.length > 0 ? h('div', { className: 'bt-model-group', role: 'presentation' }, t('Folders')) : null,folders.map(folder => h('button', { key: folder.path, type: 'button', role: 'menuitemradio', 'aria-checked': folder.path === value, title: folder.path, onClick: () => choose(folder.path) },@@ -82,14 +83,14 @@ export function FolderMenu({ value, group = false, actions, run, onPick, wide =return h(Fragment, null,h('button', {ref: button, type: 'button', className: 'bt-model-trigger', 'data-wide': wide || undefined,- 'aria-haspopup': 'menu', 'aria-expanded': isOpen, 'aria-label': t('Working folder: {folder}', { folder: value ?? fallback }),+ 'aria-haspopup': 'menu', 'aria-expanded': isOpen, 'aria-label': team ? t('Team workspace: {folder}', { folder: value ?? '' }) : t('Working folder: {folder}', { folder: value ?? fallback }),title: value, onClick: toggle,},h('span', { className: 'bt-model-copy' },h('span', { className: 'bt-model-name' }, value ? folderName(value) : fallback),value ? h('span', { className: 'bt-model-provider' }, value) : null),h(Caret)),- shownPlace ? createPortal(h('div', { ref: menu, className: `bt-menu bt-model-menu bt-folder-menu${shownPlace.bottom !== undefined ? ' bt-menu-up' : ''}`, role: 'menu', 'aria-label': t('Working folder'), style: shownPlace, 'data-leaving': leaving || undefined },+ shownPlace ? createPortal(h('div', { ref: menu, className: `bt-menu bt-model-menu bt-folder-menu${shownPlace.bottom !== undefined ? ' bt-menu-up' : ''}`, role: 'menu', 'aria-label': team ? t('Team workspace') : t('Working folder'), style: shownPlace, 'data-leaving': leaving || undefined },shownView,problem ? h('div', { className: 'bt-folder-error', role: 'alert' }, problem) : null), document.body) : null)}diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 06bb3594..0032ebeb 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -893,7 +893,12 @@ const ZH = {'Working folder: {folder}': '工作文件夹:{folder}',Folder: '文件夹',Folders: '文件夹',- 'Team workspace': '团队工作区',+ 'Team workspace': '总工作区',+ 'Team workspace: {folder}': '总工作区:{folder}',+ 'Where Bots without a folder of their own work.': '没有单独设置文件夹的 Bot 在这里工作。',+ Locations: '位置',+ 'Data location': '数据位置',+ 'Change…': '更改…',"Each Bot's own folder": '各 Bot 自己的文件夹','Choose a folder…': '选择文件夹…','Browse folders…': '浏览文件夹…',diff --git a/ds-bot/src/client/settings.js b/ds-bot/src/client/settings.jsindex 5bca24f0..98f991c3 100644--- a/ds-bot/src/client/settings.js+++ b/ds-bot/src/client/settings.js@@ -17,6 +17,7 @@ import { SchedulesPage } from './schedules.js'import { FeedbackIcon, FeedbackPage } from './feedback.js'import { AboutPage } from './about.js'import { ProvidersPage } from './providers-page.js'+import { FolderMenu } from './folder-menu.js'import { t } from './i18n.js'const capitalize = word => word[0].toUpperCase() + word.slice(1)@@ -65,9 +66,31 @@ function GeneralPage({ roster, actions, run }) {actions.setSurface ? h(SetSection, { key: 'mode', title: t('Mode') },h(SetRow, { label: t('Classic Agent mode') },h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => actions.setSurface('agent') }, t('Switch')))) : null,+ h(LocationsSection, { key: 'places', actions, run }),]}+// The desktop app's preload hands its window `dsBotApp`; only there does the data location+// show, since DSH keeps the plugin's data where it runs.+function LocationsSection({ actions, run }) {+ const app = globalThis.dsBotApp+ const [team, setTeam] = useState(null)+ const [data, setData] = useState(null)+ useEffect(() => {+ void Promise.resolve(actions.folders()).then(info => setTeam(info?.team ?? null)).catch(() => {})+ if (app !== undefined) void Promise.resolve(app.dataLocation()).then(setData).catch(() => {})+ }, [])+ const pickTeam = path => run(Promise.resolve(actions.setTeamWorkspace(path)).then((answer) => {+ setTeam(answer.team)+ app?.teamWorkspaceChanged(answer.team)+ }))+ return h(SetSection, { title: t('Locations') },+ h(SetRow, { label: t('Team workspace'), hint: t('Where Bots without a folder of their own work.') },+ team === null ? null : h(FolderMenu, { value: team, team: true, actions, run, onPick: pickTeam })),+ data === null ? null : h(SetRow, { label: t('Data location'), hint: data.path },+ data.fixed ? null : h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => run(app.moveData(team ?? undefined)) }, t('Change…'))))+}+// The first Main Bot is the sidebar tile. Picking another Bot there hands it the role// in one step; more Main Bots can sit beside it.function MainBotsSection({ roster, actions, run }) {diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.jsindex 2e36c883..90b62220 100644--- a/ds-bot/src/client/team-actions.js+++ b/ds-bot/src/client/team-actions.js@@ -58,6 +58,7 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, turfolders: () => call('folders'),folderPick: () => call('folder-pick'),folderList: path => call('folder-list', { path: path ?? '' }),+ setTeamWorkspace: path => after(call('team-workspace', { path })),deleteBot: id => after(call('delete-bot', { id })),duplicateBot: id => after(call('duplicate-bot', { id })),setPrefs: prefs => after(call('set-prefs', prefs)),diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.jsindex 44375a7f..306e9e13 100644--- a/ds-bot/src/host/channel.js+++ b/ds-bot/src/host/channel.js@@ -225,6 +225,9 @@ export function install(rt) {case 'folder-list':await rt.load()return ok(await rt.folderEndpoint(endpoint, body, signal))+ case 'team-workspace':+ await rt.load()+ return ok({ team: await rt.setTeamWorkspace(String(body.path ?? '')) })case 'add-agent':await rt.load()return ok(await rt.addAgent())diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.jsindex 6b91b8d3..143f4ece 100644--- a/ds-bot/src/host/folders.js+++ b/ds-bot/src/host/folders.js@@ -2,7 +2,7 @@// there, else a Bot works in its own folder, else in the team workspace. A Session's// folder is fixed when it is made, so a change moves the conversation on to a fresh// part (parts.js).-import { realpath, stat } from 'node:fs/promises'+import { mkdir, realpath, stat } from 'node:fs/promises'import { homedir } from 'node:os'import { basename, isAbsolute, join, resolve, sep } from 'node:path'import { unquote } from './text.js'@@ -21,6 +21,8 @@ export function install(rt) {const { ctx, state } = rtconst teamFolder = () => ctx.workspaceRegistry.get?.(state.workspaceId)?.path+ // The desktop app names the folder the user chose for the Bots' files.+ const defaultTeamFolder = () => rt.config.workspace ?? (process.env.DS_BOT_WORKSPACE?.trim() || join(rt.home, 'workspace'))const workDirOf = ({ botId, roomId } = {}) => rt.roomOf(roomId)?.workDir ?? rt.botOf(botId)?.workDirconst isFolder = path => stat(path).then(info => info.isDirectory(), () => false)const real = path => realpath(path).catch(() => resolve(path))@@ -75,6 +77,35 @@ export function install(rt) {return path === await realTeam() ? undefined : path}+ // The user moves the team workspace. Bots and groups without a folder of their own move on+ // to a fresh part there at their next turn, as for any other change of folder; the old+ // folder and its files stay as they are.+ async function setTeamWorkspace(input) {+ const text = unquote(input)+ const expanded = expandHome(text)+ if (text === '' || !isAbsolute(expanded)) throw new Error(`Give the full path of the folder, not ${text}`)+ // The plugin's own default lies in DSH's data, and going back to it stays possible.+ const fallback = resolve(defaultTeamFolder())+ const holdsData = async (path) => {+ if (path === fallback || path === await real(fallback)) return false+ for (const root of [rt.dshHome, rt.home]) {+ const data = await real(root)+ if (within(path, data) || within(data, path)) return true+ }+ return false+ }+ if (await holdsData(resolve(expanded))) throw new Error(`${text} holds DeepSeek Harness data, so it cannot be the team workspace`)+ await mkdir(expanded, { recursive: true })+ const path = await realpath(expanded)+ if (!(await isFolder(path))) throw new Error(`${text} is a file, not a folder`)+ if (await holdsData(path)) throw new Error(`${text} holds DeepSeek Harness data, so it cannot be the team workspace`)+ if (path === await realTeam()) return path+ const workspace = await ctx.workspaceRegistry.resolveByPath(path) ?? await ctx.workspaceRegistry.create(path, 'DS Bot')+ state.workspaceId = workspace.id+ await rt.save()+ return path+ }+// Every Session of a Bot: its own chat and its conversation in each of its groups.const sessionsOfBot = botId => [rt.chatOf(botId), ...Object.values(state.rooms).filter(room => room.members.includes(botId)).map(room => room.sessions?.[botId])].filter(Boolean)@@ -151,5 +182,5 @@ export function install(rt) {}}- Object.assign(rt, { teamFolder, workDirOf, sessionFolder, isFolder, real, folderAt, cleanWorkDir, workFolder, sessionsOfBot, approveFolder, folderEndpoint })+ Object.assign(rt, { teamFolder, defaultTeamFolder, workDirOf, sessionFolder, isFolder, real, folderAt, cleanWorkDir, workFolder, setTeamWorkspace, sessionsOfBot, approveFolder, folderEndpoint })}diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex 65929010..e22cdf49 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -1,13 +1,12 @@// Roster: creating, changing, and deleting Bots and group chats, the Main Bot role, and// the first Main Bot of a new team.import { mkdir } from 'node:fs/promises'-import { join } from 'node:path'import { MAX_AVATAR_IMAGE, ROOM_MAX_MEMBERS, ROOM_MODES, ROOM_NAME_MAX, ROOM_NOTICE_MAX } from './constants.js'import { currentColor, isColor, normalize, unquote } from './text.js'import { nameProblem } from '../shared/mentions.js'export function install(rt) {- const { ctx, config, home, defaults, state } = rt+ const { ctx, defaults, state } = rtlet bootstrapping = null@@ -23,8 +22,7 @@ export function install(rt) {await keepTeamFolder()return state.workspaceId}- // The desktop app names the folder the user chose for the Bots' files.- const path = config.workspace ?? (process.env.DS_BOT_WORKSPACE?.trim() || join(home, 'workspace'))+ const path = rt.defaultTeamFolder()await mkdir(path, { recursive: true })const workspace = await ctx.workspaceRegistry.resolveByPath(path) ?? await ctx.workspaceRegistry.create(path, 'DS Bot')state.workspaceId = workspace.iddiff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex d9461702..a5a98b60 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -574,6 +574,37 @@ test('a team copied from another DSH_HOME moves on to a fresh part in the folderassert.deepEqual(agentOf('s1').calls.map(([kind, message]) => [kind, message.source.role ?? textOf(message)]), [['followup', 'handoff'], ['followup', 'Hello again']])})+test('the user moves the team workspace, and Bots without a folder of their own move on to a fresh part there at their next turn', async (t) => {+ const { root, team, project, agentOf, created, state, preStep, call, stop } = await start()+ t.after(stop)+ await call('update-bot', { id: 'a', workDir: project })+ const moved = join(root, 'moved')+ assert.deepEqual((await call('team-workspace', { path: moved })).value, { team: moved })+ assert.equal(state().workspaceId, 'w-new')+ assert.equal(existsSync(team), true)+ const input = { id: 'm1', role: 'user', content: [{ type: 'text', text: 'Hello again' }], source: { kind: 'user' } }+ assert.deepEqual(await preStep('b', [input]), { kind: 'reject' })+ await until(() => state().bots.b.sessionId !== 'b')+ assert.equal(agentOf(state().bots.b.sessionId).session.header.cwd, moved)+ assert.deepEqual(created.at(-1), { workspaceId: 'w-new' })+ // A Bot with a folder of its own stays where it works.+ assert.equal(state().bots.a.workDir, project)+})++test('the team workspace holds no DeepSeek Harness data, apart from the plugin\'s own default', async (t) => {+ const { root, dsh, home, team, state, call, stop } = await start()+ t.after(stop)+ const error = async path => (await call('team-workspace', { path })).error?.message+ assert.match(await error(join(dsh, 'inside')), /holds DeepSeek Harness data/)+ assert.match(await error(root), /holds DeepSeek Harness data/)+ assert.match(await error('relative'), /full path/)+ assert.equal(existsSync(join(dsh, 'inside')), false)+ assert.equal(state().workspaceId, 'w1')+ await call('team-workspace', { path: join(root, 'moved') })+ assert.deepEqual((await call('team-workspace', { path: join(home, 'workspace') })).value, { team })+ 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 } })