A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Add a Bot permission setting; ask for issues instead of pull requests for now
Fei2411f20dbfa47142
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b903af66..ef3b30e3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change- Voice chat uses the local speech recognition of the official DSH Voice Input plugin (SenseVoice) when the plugin is on, and the browser's speech recognition otherwise. When the plugin has no speech model yet, the voice panel opens its settings.- The update card also offers DSH updates, but only the DSH version that the newest DS Bot release was verified with (`dsBot.verifiedDsh`). A DSH installed with npm updates in one click; DSH Desktop opens its own update panel.- Each Bot can pick a thinking level with its model, in the model menu or when the Bot is created. **Default** uses the model's own level.+- A permission setting in each Bot's details panel: **Read only**, **Workspace** or **Full access**, from the presets DSH offers. The Bot keeps it in its own chat, its group chats and its new conversation parts.### Fixeddiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 3ce1e87f..23cec650 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -2,13 +2,17 @@Thank you for helping. This file explains how to set up the plugin, how to test a change and which rules a change must follow. For what the plugin does and how users install it, see [README.md](README.md).+## Pull requests++Thank you for your interest in improving DS Bot. The project is still changing quickly, so we are not accepting pull requests for now. If you find a problem or have an idea, please open an issue (see [Report a problem](#report-a-problem)). We hope to open pull requests again when the project is stable. Thank you for your understanding.+## The rules that matter most1. **DS Bot is a DSH plugin, and only a plugin.** Do not patch DeepSeek Harness, and do not depend on files inside a DSH install. Use the plugin APIs that DSH documents (Cordis services, the plugin client entry, profile patches). When a feature needs something that DSH does not offer, open an issue here first; the fix can belong in DSH.2. **Every Bot is a DSH Session.** Bot work runs through the normal DSH agent loop, tools and model routes. Do not add a second agent runtime.3. **No real secrets anywhere.** Do not commit API keys, tokens, cookies, `DSH_HOME` folders, logs or screenshots with personal data. The tests and the test bench use a scripted mock model and need no key.-4. **Only original material.** Do not copy code, text, icons, logos or other graphics from other products or websites. Code under a license compatible with Apache 2.0 is the only exception: say where it comes from in the pull request and add its notice to a `NOTICE` file.-5. **Every change is tested.** Run the unit tests and the client check before you open a pull request (see [Test a change](#test-a-change)).+4. **Only original material.** Do not copy code, text, icons, logos or other graphics from other products or websites. Code under a license compatible with Apache 2.0 is the only exception: say where it comes from and add its notice to a `NOTICE` file.+5. **Every change is tested.** Run the unit tests and the client check for every change (see [Test a change](#test-a-change)).## Set up@@ -79,7 +83,7 @@ For a change to the Bot browser, check it in DSH Desktop. On Linux, the scripts## Write a change-- Keep a pull request to one subject. Explain why the change is needed, how you tested it, and what you did not test.+- Keep a change to one subject.- Do not edit `client.js` by hand. Change `src/client/`, run `npm run build` and commit both.- Follow the style of the code around your change. Write a comment only when the reason for the code is not clear from the code itself.- Write commit messages in English. Use a short subject in the imperative mood ("Keep group replies visible") and explain the reason in the body.diff --git a/ds-bot/client.js b/ds-bot/client.jsindex ca3dba6f..b82ea4f2 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -217,6 +217,10 @@ var ZH = {"Click again to delete. Its chats are archived.": "再点一次删除,它的对话会归档。","Removes the Bot from the team.": "把这个 Bot 从团队里移除。","Pick a model and {name} can start.": "选好模型,{name} 就能开始工作。",+ "Permissions": "权限",+ "Read only": "仅可查看",+ "Workspace": "工作区内修改",+ "Full access": "完全权限","The only Main Bot. To hand the role to another Bot, use Main Bot on the Bots page.": "这是唯一的主 Bot。要把主 Bot 交给别的 Bot,请到「Bot」页的主 Bot 里换。",Change: "更换","Can create and change Bots, and runs every group chat.": "可以创建和修改 Bot,并管理所有群聊。",@@ -814,6 +818,7 @@ var HOST_ERRORS = [];var HOST_ZH = {"Request failed": "请求失败",+ "Permissions are not available in this DeepSeek Harness": "这个 DeepSeek Harness 不支持权限设置","Avatar images must be PNG, JPEG, WebP, or GIF": "头像图片必须是 PNG、JPEG、WebP 或 GIF","Avatar image is too large": "头像图片太大了","A Bot needs a name": "Bot 需要一个名字",@@ -2026,6 +2031,8 @@ button.bt-q-opt:active{background:var(--bt-active)}.bt-set-body{gap:20px}.bt-drawer-model{display:flex;flex-direction:column}.bt-drawer-model .bt-note{margin-top:6px}+.bt-drawer-permission{display:flex;flex-direction:column}+.bt-seg button.bt-perm-danger,.bt-seg button.bt-perm-danger[aria-pressed=true]{color:#e02135}/* Settings dialog: a 198px page list beside the page. */.bt-settings-layer{position:fixed;inset:var(--dsh-frame-chrome-top,0px) 0 0;z-index:60;display:flex;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif}@@ -9986,6 +9993,40 @@ var hostOf = (url) => {};var shortUrl = (url) => String(url ?? "").replace(/^https?:\/\//i, "").replace(/^www\./i, "").replace(/\/$/, "");var EMPTY_TABS = { ids: [], active: null };+var PERMISSION_LABELS = { "read-only": "Read only", "workspace-write": "Workspace", "danger-full-access": "Full access" };+var DANGER = /* @__PURE__ */ new Set(["danger-full-access"]);+function PermissionRow({ bot, roster, actions, run }) {+ const [pending, setPending] = (0, import_react27.useState)(null);+ const catalog = roster.permissions;+ const saved = bot.permission ?? catalog?.defaultPreset;+ (0, import_react27.useEffect)(() => {+ if (pending === saved) setPending(null);+ }, [pending, saved]);+ if (!catalog?.options?.length) return null;+ const current = pending ?? saved;+ const pick2 = (value) => {+ if (value === current && bot.permission !== void 0) return;+ setPending(value);+ void run(actions.updateBot(bot.id, { permission: value })).catch(() => setPending(null));+ };+ return (0, import_react27.createElement)(+ "div",+ { className: "bt-drawer-permission" },+ (0, import_react27.createElement)("div", { className: "bt-section-title" }, t("Permissions")),+ (0, import_react27.createElement)(+ Segmented,+ { label: t("Permissions"), value: current },+ catalog.options.map((option) => (0, import_react27.createElement)("button", {+ key: option.value,+ type: "button",+ "aria-pressed": option.value === current,+ title: option.description,+ onClick: () => pick2(option.value),+ className: DANGER.has(option.value) ? "bt-perm-danger" : void 0+ }, PERMISSION_LABELS[option.value] ? t(PERMISSION_LABELS[option.value]) : option.name))+ )+ );+}function BrowserCards({ bot, sessionId, roster, actions, useBrowserTabs, useBrowserPages }) {const state = useBrowserTabs((map) => map[bot.id] ?? EMPTY_TABS);const pages = useBrowserPages((map) => map);@@ -10217,6 +10258,7 @@ function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, roster, a(0, import_react27.createElement)(ModelMenu, { bot, roster, actions, run, wide: true }),modelOf(bot, roster) ? null : (0, import_react27.createElement)("div", { className: "bt-note" }, t("Pick a model and {name} can start.", { name: bot.name }))),+ (0, import_react27.createElement)(PermissionRow, { key: "permission", bot, roster, actions, run }),bot.instructions ? (0, import_react27.createElement)(About, { key: "about", text: bot.instructions }) : (0, import_react27.createElement)("button", { key: "about", type: "button", className: "bt-more", onClick: () => setView("settings") }, t("Add instructions in Bot settings")),roster.memory === false ? null : (0, import_react27.createElement)(MemoryRow, { key: "memory", bot, actions }),usage ? (0, import_react27.createElement)(diff --git a/ds-bot/index.js b/ds-bot/index.jsindex b639f9fc..b88cb0a8 100644--- a/ds-bot/index.js+++ b/ds-bot/index.js@@ -6,6 +6,7 @@ import { join } from 'node:path'import * as diagnostics from './src/host/diagnostics.js'import * as store from './src/host/store.js'import * as models from './src/host/models.js'+import * as permissions from './src/host/permissions.js'import * as turns from './src/host/turns.js'import * as delivery from './src/host/delivery.js'import * as roster from './src/host/roster.js'@@ -35,7 +36,7 @@ export const inject = ['llm', 'tools', 'systemPrompt', 'sessionController', 'ses// the functions other modules call; they call them through `rt` at run time, never during// install. Listeners run and tools are listed in registration order, so this order holds:// usage meters model requests after every listener that rewrites them.-const MODULES = [diagnostics, store, models, turns, delivery, roster, agents, prompt, tools, chatIndex, groups, memory, parts, images, secrets, connectors, schedules, browser, usage, update, dshUpdate, channel]+const MODULES = [diagnostics, store, models, permissions, turns, delivery, roster, agents, prompt, tools, chatIndex, groups, memory, parts, images, secrets, connectors, schedules, browser, usage, update, dshUpdate, channel]export function apply(ctx, config = {}) {const home = config.home ?? join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'bot')diff --git a/ds-bot/src/client/details-drawer.js b/ds-bot/src/client/details-drawer.jsindex f1dbd59d..2011b04c 100644--- a/ds-bot/src/client/details-drawer.js+++ b/ds-bot/src/client/details-drawer.js@@ -10,7 +10,7 @@ import { GroupSettingsForm, ROOM_MODES, roomSubtitle, shownMode } from './group-import { ModelMenu, modelOf } from './model-menu.js'import { MemoryRow } from './memory-panel.js'import { ScheduleSummary } from './schedules.js'-import { useGlide, useMorph } from './motion.js'+import { Segmented, useGlide, useMorph } from './motion.js'import { t } from './i18n.js'function transcriptOf(list, id, name, hiddenTurns = []) {@@ -33,6 +33,33 @@ const EMPTY_TABS = { ids: [], active: null }// The Bot's browser inside the details page: its tabs as small window cards on// Desktop, a pointer there on web.+const PERMISSION_LABELS = { 'read-only': 'Read only', 'workspace-write': 'Workspace', 'danger-full-access': 'Full access' }+const DANGER = new Set(['danger-full-access'])++// The Bot's permission preset, from the presets DeepSeek Harness offers.+function PermissionRow({ bot, roster, actions, run }) {+ const [pending, setPending] = useState(null)+ const catalog = roster.permissions+ const saved = bot.permission ?? catalog?.defaultPreset+ useEffect(() => { if (pending === saved) setPending(null) }, [pending, saved])+ if (!catalog?.options?.length) return null+ const current = pending ?? saved+ const pick = (value) => {+ // A Bot without its own preset may run on another one set in DSH, so its first pick always applies.+ if (value === current && bot.permission !== undefined) return+ setPending(value)+ void run(actions.updateBot(bot.id, { permission: value })).catch(() => setPending(null))+ }+ return h('div', { className: 'bt-drawer-permission' },+ h('div', { className: 'bt-section-title' }, t('Permissions')),+ h(Segmented, { label: t('Permissions'), value: current },+ catalog.options.map(option => h('button', {+ key: option.value, type: 'button', 'aria-pressed': option.value === current,+ title: option.description, onClick: () => pick(option.value),+ className: DANGER.has(option.value) ? 'bt-perm-danger' : undefined,+ }, PERMISSION_LABELS[option.value] ? t(PERMISSION_LABELS[option.value]) : option.name))))+}+function BrowserCards({ bot, sessionId, roster, actions, useBrowserTabs, useBrowserPages }) {const state = useBrowserTabs(map => map[bot.id] ?? EMPTY_TABS)const pages = useBrowserPages(map => map)@@ -198,6 +225,7 @@ export function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, roh('div', { className: 'bt-section-title' }, t('Model')),h(ModelMenu, { bot, roster, actions, run, wide: true }),modelOf(bot, roster) ? null : h('div', { className: 'bt-note' }, t('Pick a model and {name} can start.', { name: bot.name }))),+ h(PermissionRow, { key: 'permission', bot, roster, actions, run }),bot.instructions? h(About, { key: 'about', text: bot.instructions }): h('button', { key: 'about', type: 'button', className: 'bt-more', onClick: () => setView('settings') }, t('Add instructions in Bot settings')),diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 305ff84e..e701d590 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -195,6 +195,10 @@ const ZH = {'Click again to delete. Its chats are archived.': '再点一次删除,它的对话会归档。','Removes the Bot from the team.': '把这个 Bot 从团队里移除。','Pick a model and {name} can start.': '选好模型,{name} 就能开始工作。',+ 'Permissions': '权限',+ 'Read only': '仅可查看',+ 'Workspace': '工作区内修改',+ 'Full access': '完全权限','The only Main Bot. To hand the role to another Bot, use Main Bot on the Bots page.': '这是唯一的主 Bot。要把主 Bot 交给别的 Bot,请到「Bot」页的主 Bot 里换。',Change: '更换','Can create and change Bots, and runs every group chat.': '可以创建和修改 Bot,并管理所有群聊。',@@ -777,6 +781,7 @@ const HOST_ERRORS = []const HOST_ZH = {'Request failed': '请求失败',+ 'Permissions are not available in this DeepSeek Harness': '这个 DeepSeek Harness 不支持权限设置','Avatar images must be PNG, JPEG, WebP, or GIF': '头像图片必须是 PNG、JPEG、WebP 或 GIF','Avatar image is too large': '头像图片太大了','A Bot needs a name': 'Bot 需要一个名字',diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.jsindex db538520..d8d4bbbb 100644--- a/ds-bot/src/client/styles.js+++ b/ds-bot/src/client/styles.js@@ -402,6 +402,8 @@ button.bt-q-opt:active{background:var(--bt-active)}.bt-set-body{gap:20px}.bt-drawer-model{display:flex;flex-direction:column}.bt-drawer-model .bt-note{margin-top:6px}+.bt-drawer-permission{display:flex;flex-direction:column}+.bt-seg button.bt-perm-danger,.bt-seg button.bt-perm-danger[aria-pressed=true]{color:#e02135}/* Settings dialog: a 198px page list beside the page. */.bt-settings-layer{position:fixed;inset:var(--dsh-frame-chrome-top,0px) 0 0;z-index:60;display:flex;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif}diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.jsindex 00723261..d92b4c62 100644--- a/ds-bot/src/host/channel.js+++ b/ds-bot/src/host/channel.js@@ -55,6 +55,7 @@ export function install(rt) {colors: [...COLORS, ...EXTRA_COLORS],models: rt.cachedCatalog(),defaultModel: rt.cachedDefault() ?? null,+ permissions: rt.permissionCatalog?.() ?? null,modelsKey: modelsKey(),prefs: state.prefs,// Whether a Desktop window should serve Bot browser reads (see browser.js).diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex e9311a92..f8d414c5 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -117,6 +117,8 @@ export function install(rt) {await rt.selectSessionModel(id, splitRef(ref)).catch(error => rt.warn('ds-bot: model for %s in %s not applied: %s', member.name, room.name, error))}+ await rt.applyPermission(member, id)+ .catch(error => rt.warn('ds-bot: permission for %s in %s not applied: %s', member.name, room.name, error))await rt.save()return { id, brief: await rt.ownChatBrief(member) }}diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex 5c862ea5..182ced6f 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -710,6 +710,8 @@ export function install(rt) {await rt.selectSessionModel(freshId, model).catch(error => rt.warn('ds-bot: model for the fresh part of %s not applied: %s', bot.name, error))}+ await rt.applyPermission(bot, freshId)+ .catch(error => rt.warn('ds-bot: permission for the fresh part of %s not applied: %s', bot.name, error))const segment = { sessionId: agent.id, endedAt: Date.now(), ...(tokens !== undefined ? { tokens } : {}), ...noted }if (room !== undefined) {room.segments ??= {}diff --git a/ds-bot/src/host/permissions.js b/ds-bot/src/host/permissions.jsnew file mode 100644index 00000000..4572f683--- /dev/null+++ b/ds-bot/src/host/permissions.js@@ -0,0 +1,42 @@+// Permissions. A Bot's permission preset is its own: kept on the Bot and set on every+// Session it speaks from, so a fresh part or a new group Session keeps it.+// DSH offers Auto review for the current Session only, so a Bot never keeps it.+const SESSION_ONLY = 'auto'++export function install(rt) {+ const { ctx } = rt++ const presets = () => ctx.get?.('permissionPresets')++ // The presets DSH offers, or undefined when the profile has none.+ function permissionCatalog() {+ const service = presets()+ if (service === undefined) return undefined+ const { options, defaultPreset } = service.catalog()+ return { options: options.filter(option => option.value !== SESSION_ONLY), defaultPreset }+ }++ // Sets the Bot's preset on one of its Sessions; a Bot without one keeps DSH's default.+ async function applyPermission(bot, sessionId) {+ const service = presets()+ if (service === undefined || !bot.permission) return+ const agent = await rt.resolveAgent(sessionId)+ service.set(agent.session, bot.permission)+ }++ async function setPermission(bot, name) {+ const service = presets()+ if (service === undefined) throw new Error('Permissions are not available in this DeepSeek Harness')+ const wanted = String(name ?? '').trim()+ if (wanted === SESSION_ONLY) throw new Error('Auto review applies to one Session only and cannot be a Bot\'s permission')+ service.resolve(wanted)+ await applyPermission({ ...bot, permission: wanted }, rt.chatOf(bot.id))+ bot.permission = wanted+ for (const sessionId of rt.groupSessionsOf(bot.id)) {+ await applyPermission(bot, sessionId)+ .catch(error => rt.warn('ds-bot: permission for %s in a group not applied: %s', bot.name, error))+ }+ }++ Object.assign(rt, { permissionCatalog, applyPermission, setPermission })+}diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex b52cb586..36500d76 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -171,6 +171,7 @@ export function install(rt) {}modelChanged = true}+ if (patch.permission !== undefined) await rt.setPermission(bot, patch.permission)await rt.save()if (modelChanged) await rt.applyModel(bot, { force: true })if (bot.model && bot.kickoff !== undefined) {diff --git a/ds-bot/test/permissions.test.js b/ds-bot/test/permissions.test.jsnew file mode 100644index 00000000..a8934367--- /dev/null+++ b/ds-bot/test/permissions.test.js@@ -0,0 +1,69 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { install } from '../src/host/permissions.js'++const PRESETS = { 'workspace-write': {}, 'danger-full-access': {} }+const SESSION_ONLY = ['auto']++function runtime({ presets = true, auto = false, fail = false } = {}) {+ const writes = []+ const service = {+ catalog: () => ({ options: [...Object.keys(PRESETS), ...(auto ? SESSION_ONLY : [])].map(value => ({ value, name: value })), defaultOptions: [], defaultPreset: 'workspace-write' }),+ resolve: (name) => { if (!(name in PRESETS) && !(auto && SESSION_ONLY.includes(name))) throw new Error(`permission: unknown preset "${name}"`); return PRESETS[name] },+ set: (session, name) => { if (fail) throw new Error('permission: rejected'); writes.push(`${session}=${name}`) },+ }+ const ctx = { get: name => (presets && name === 'permissionPresets' ? service : undefined) }+ const rt = {+ ctx,+ chatOf: id => `${id}-chat`,+ groupSessionsOf: id => [`${id}-group`],+ resolveAgent: async sessionId => ({ session: sessionId }),+ warn() {},+ }+ install(rt)+ return { rt, writes }+}++test('a Bot\'s preset is set on its chat and its group Sessions', async () => {+ const { rt, writes } = runtime()+ const bot = { id: 'b1', name: 'Ada' }+ await rt.setPermission(bot, 'danger-full-access')+ assert.equal(bot.permission, 'danger-full-access')+ assert.deepEqual(writes, ['b1-chat=danger-full-access', 'b1-group=danger-full-access'])+})++test('a fresh Session gets the Bot\'s preset, and a Bot without one keeps the default', async () => {+ const { rt, writes } = runtime()+ await rt.applyPermission({ id: 'b1' }, 'fresh')+ await rt.applyPermission({ id: 'b1', permission: 'workspace-write' }, 'fresh')+ assert.deepEqual(writes, ['fresh=workspace-write'])+})++test('an unknown preset is refused and the Bot keeps its own', async () => {+ const { rt, writes } = runtime()+ const bot = { id: 'b1', permission: 'workspace-write' }+ await assert.rejects(rt.setPermission(bot, 'everything'), /unknown preset/)+ assert.equal(bot.permission, 'workspace-write')+ assert.deepEqual(writes, [])+})++test('the catalog lists the presets DSH offers, or nothing without the presets service', () => {+ assert.deepEqual(runtime().rt.permissionCatalog(), { options: [{ value: 'workspace-write', name: 'workspace-write' }, { value: 'danger-full-access', name: 'danger-full-access' }], defaultPreset: 'workspace-write' })+ assert.equal(runtime({ presets: false }).rt.permissionCatalog(), undefined)+})++test('Auto review is not offered or kept as a Bot\'s preset', async () => {+ const { rt, writes } = runtime({ auto: true })+ assert.deepEqual(rt.permissionCatalog().options.map(option => option.value), ['workspace-write', 'danger-full-access'])+ const bot = { id: 'b1' }+ await assert.rejects(rt.setPermission(bot, 'auto'), /one Session only/)+ assert.equal(bot.permission, undefined)+ assert.deepEqual(writes, [])+})++test('a preset the Bot\'s own chat refuses is not kept', async () => {+ const { rt } = runtime({ fail: true })+ const bot = { id: 'b1', permission: 'workspace-write' }+ await assert.rejects(rt.setPermission(bot, 'danger-full-access'), /rejected/)+ assert.equal(bot.permission, 'workspace-write')+})