A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Show DSH's Web front end in the desktop app's window
Fei2411cd4b65586eaf
diff --git a/app/README.md b/app/README.mdindex 7ef515a5..90b85a6c 100644--- a/app/README.md+++ b/app/README.md@@ -1,13 +1,13 @@# DeepSeek Bot desktop app-The Electron app for Windows and macOS. It installs a pinned DeepSeek Harness (DSH 0.2.0-rc.2) and the `ds-bot` plugin of this repository, boots its own DSH profile `ds-bot` through `@deepseek-ai/dsh/profile-boot`, and keeps its data in its own `DSH_HOME`. It never writes to `~/.dsh`. Its window is its own page (`ui/`), which talks only to ds-bot's channel in the engine. The design is in [docs/plans/2026-10-16-desktop-app.md](../docs/plans/2026-10-16-desktop-app.md).+The Electron app for Windows and macOS. It installs a pinned DeepSeek Harness (DSH 0.2.0-rc.2) and the `ds-bot` plugin of this repository, boots its own DSH profile `ds-bot` through `@deepseek-ai/dsh/profile-boot`, and keeps its data in its own `DSH_HOME`. It never writes to `~/.dsh`. Its window shows DSH's Web front end with the plugin, as DSH Desktop does. The design is in [docs/plans/2026-10-16-desktop-app.md](../docs/plans/2026-10-16-desktop-app.md).## Run```shnpm cinode node_modules/electron/install.js # when npm did not download Electron (no node_modules/electron/dist)-npm start # builds the window (npm run build), then starts the app+npm start # starts the app```When GitHub downloads are slow, set `ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` before the Electron download. Unset `ELECTRON_RUN_AS_NODE` before `npm start` if your terminal has it (terminals inside some Electron-based editors do): with it, Electron runs as plain Node and the app does not start.@@ -19,7 +19,7 @@ npm installs `ds-bot` from `../ds-bot` as a copy of its package files (`install-| `DS_BOT_HOME` | The data location: the `DSH_HOME` of the app | `~/.ds-bot` || `DS_BOT_SHELL_DATA` | The app's own data (window, Chromium storage) | Electron's `userData` (Windows: `%APPDATA%\DeepSeek Bot`) |-The Host reads model settings and keys the way DSH does: environment variables such as `DEEPSEEK_API_KEY`, and `.env` and `.credentials.yaml` in the data location. In the window, Settings > Models sets up model providers and their keys; DSH keeps the providers in the profile's `cordis.patch.yml` and the keys in `.credentials.yaml`. When no model has its API key, the first Main Bot asks for one in its chat.+The Host reads model settings and keys the way DSH does: environment variables such as `DEEPSEEK_API_KEY`, and `.env` and `.credentials.yaml` in the data location. DSH's settings in the window set up model providers and their keys; DSH keeps the providers in the profile's `cordis.patch.yml` and the keys in `.credentials.yaml`.## The profile@@ -28,19 +28,18 @@ The Host's profile `ds-bot` is in `profiles/ds-bot` in the data location. It sta| Bundle | What it adds ||---|---|| `@deepseek-ai/dsh-base` | DSH's shared core: models, Sessions, tools, settings, plugin management |-| `deepseek-bot-engine` (`engine/`) | The loopback transport for ds-bot's channel, the host services that ds-bot uses, and the `standard` agent preset that Bot Sessions run on, without the goal command and tool. It has no row of DSH's Web front end |+| `@deepseek-ai/dsh-web-app` | DSH's Web front end, which the window shows, and the host services that it and ds-bot use || `ds-bot` | The Bot team |-At every start the Host puts these three bundles at the head of the profile's bundle list. Settings for one machine go into the profile's `cordis.patch.yml`, as in DSH. The `@deepseek-ai/dsh` package still installs DSH's Web front end, but the profile does not load it. When the app moves to another DSH version, compare `engine/` with the `dsh-web-app` bundle patch and the standard preset of that version.+At every start the Host puts these three bundles at the head of the profile's bundle list. Settings for one machine go into the profile's `cordis.patch.yml`, as in DSH. A profile from an earlier build that lists `deepseek-bot-engine` gets `@deepseek-ai/dsh-web-app` in its place.## Check a change`npm test` checks the composition of the profile, and that every package the app runs on is a dependency (see [Package](#package)).-`scripts/shot.mjs` starts the app on throwaway folders, saves a screenshot of its window, prints the page text, closes the window the way a user does and waits until the app exits. Build the window first (`npm run build`). Use the mock model of the plugin, `../ds-bot/dev/mock-llm.mjs` (`MOCK_PORT=<port> node ../ds-bot/dev/mock-llm.mjs`).+`scripts/shot.mjs` starts the app on throwaway folders, saves a screenshot of its window, prints the page text, closes the window the way a user does and waits until the app exits. Use the mock model of the plugin, `../ds-bot/dev/mock-llm.mjs` (`MOCK_PORT=<port> node ../ds-bot/dev/mock-llm.mjs`).```sh-npm run buildDS_BOT_HOME=<tmp>/home DS_BOT_SHELL_DATA=<tmp>/shell \DEEPSEEK_BASE_URL=http://127.0.0.1:<port>/v1 DEEPSEEK_API_KEY=mock-key \node scripts/shot.mjs <tmp>/shot.png 20@@ -68,14 +67,15 @@ The Windows installer installs for the current user only, without administrator| File | What it does ||---|---|-| `src/main.mjs` | Main process: one instance, the `dsh-app://app` scheme (the window's build, and `/api/` forwarded to the Host), the window. The window has no title bar: a band along the top of the page moves it, and the system's window buttons sit in that band |+| `src/main.mjs` | Main process: one instance, the `dsh-app://app` scheme (DSH's Web front end, and everything else forwarded to the Host), the window and its boot data |+| `src/preload.cjs` | Hands the window the boot data that DSH's Web front end needs || `src/host-process.mjs` | Starts the Host in Electron's Node mode and owns its exit |-| `src/host.mjs` | The Host: boots the profile with `runProfile()` and reports the launch URL |+| `src/host.mjs` | The Host: boots the profile with `runProfile()` and reports the launch URL and the page injections || `src/profile.mjs` | The profile: its name, its bundles, and its creation and update |-| `engine/` | The bundle `deepseek-bot-engine`: `cordis.patch.yml`, `preset-standard.patch.yml`, and `index.js`, which trades the launch token for the Host cookie |+| `engine/` | On hold, not installed: the bundle `deepseek-bot-engine` for the app's own window in `ui/` || `test/` | `npm test`: the composition of the profile, and the dependencies that the package needs |-| `src/web.mjs` | The window's files, the launch-token cookie exchange and the request forwarding |-| `ui/` | The window: React, built with Vite (`vite.config.js`) into `ui/dist`. It draws the plugin's own Bot views from `../ds-bot/src/client/` (sidebar, chat rows, docks, dialogs and their stylesheets) and puts its own Markdown in place of DSH's. It uses ds-bot's `api/bot` channel and its live feed `api/bot/feed` |+| `src/web.mjs` | DSH's Web front end document, the launch-token cookie exchange and the request forwarding |+| `ui/` | On hold, not built or packaged: the app's own window. React, built with Vite (`vite.config.js`) into `ui/dist`. It draws the plugin's own Bot views from `../ds-bot/src/client/` (sidebar, chat rows, docks, dialogs and their stylesheets) and puts its own Markdown in place of DSH's. It uses ds-bot's `api/bot` channel and its live feed `api/bot/feed` || `assets/` | The app icon: `icon.svg`, `icon.png` (1024 px) and `icon.ico` (Windows, 16 to 256 px). `npm run icon` (`scripts/icon.mjs`) draws them again from the Main Bot's whale in `../ds-bot` || `electron-builder.yml`, `build/` | The package and the installer: app identity, files, icons, the Windows installer and the macOS disk image || `scripts/check-packed.mjs` | `npm run check-packed`: the check of a packaged app |diff --git a/app/electron-builder.yml b/app/electron-builder.ymlindex c483176f..0c7dccd6 100644--- a/app/electron-builder.yml+++ b/app/electron-builder.yml@@ -7,8 +7,6 @@ directories:files:- package.json- src/**- - engine/**- - ui/dist/**- assets/**# The Host runs pnpm as a separate Node process to install plugins, so it must be a plain file.asarUnpack:diff --git a/app/package-lock.json b/app/package-lock.jsonindex 8ecb5b48..8a28eae5 100644--- a/app/package-lock.json+++ b/app/package-lock.json@@ -39,7 +39,6 @@"@deepseek-ai/dsh-util-time": "0.2.0-rc.2","@deepseek-ai/dsh-util-workspace-path": "0.2.0-rc.2","@deepseek-ai/dsh-workflow": "0.2.0-rc.2",- "deepseek-bot-engine": "file:./engine","ds-bot": "file:../ds-bot","pnpm": "11.7.0"},@@ -56,6 +55,7 @@"engine": {"name": "deepseek-bot-engine","version": "0.1.7",+ "extraneous": true,"license": "Apache-2.0","dependencies": {"@deepseek-ai/dsh-agent-instructions": "0.2.0-rc.2",@@ -9295,10 +9295,6 @@"url": "https://github.com/sponsors/sindresorhus"}},- "node_modules/deepseek-bot-engine": {- "resolved": "engine",- "link": true- },"node_modules/default-browser": {"version": "5.5.1","resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.5.1.tgz",diff --git a/app/package.json b/app/package.jsonindex 39c7e2ff..82c34e5a 100644--- a/app/package.json+++ b/app/package.json@@ -10,9 +10,9 @@"main": "src/main.mjs","scripts": {"build": "vite build",- "start": "vite build && electron .",- "pack": "vite build && electron-builder --dir",- "dist": "vite build && electron-builder",+ "start": "electron .",+ "pack": "electron-builder --dir",+ "dist": "electron-builder","check-packed": "node scripts/check-packed.mjs","shot": "node scripts/shot.mjs","icon": "node scripts/icon.mjs",@@ -49,7 +49,6 @@"@deepseek-ai/dsh-util-time": "0.2.0-rc.2","@deepseek-ai/dsh-util-workspace-path": "0.2.0-rc.2","@deepseek-ai/dsh-workflow": "0.2.0-rc.2",- "deepseek-bot-engine": "file:./engine","ds-bot": "file:../ds-bot","pnpm": "11.7.0"},diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjsindex 122611a0..a2dc9d2a 100644--- a/app/scripts/check-packed.mjs+++ b/app/scripts/check-packed.mjs@@ -131,20 +131,27 @@ async function chat(cdp) {}throw new Error(`timed out waiting for ${label}`)}- const bubbles = "document.querySelectorAll('.dsb-flow .bt-bubble')"+ // DSH shows a preview notice once per profile; it would keep the focus away from the composer.+ const dismissNotice = () => evaluate("[...document.querySelectorAll('[role=dialog] button')].find(node => /^(Continue|继续)$/u.test(node.textContent.trim()))?.click()")+ const text = needle => `document.body.innerText.includes(${JSON.stringify(needle)})`await cdp.call('Runtime.enable')await cdp.call('Log.enable')- await until("document.querySelector('.bt-model-chip')", 'the model choice')+ await until("document.querySelector('.bt-tile, .bt-row')", 'the team')+ await dismissNotice()+ const main = await evaluate("fetch('api/bot', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ endpoint: 'state', payload: {} }) }).then(r => r.json()).then(r => r.value.mainBotId)")+ await evaluate(`document.querySelector(${JSON.stringify(`[data-bot-id="${main}"]`)}).click()`)+ await until("document.querySelector('.bt-model-chip:not(.bt-model-chip-quiet)')", 'the model choice')await evaluate("document.querySelector('.bt-model-chip:not(.bt-model-chip-quiet)').click()")- await until(`${bubbles}.length > 1 && !document.querySelector('.dsb-pending')`, 'the greeting')- const before = await evaluate(`${bubbles}.length`)- await evaluate("document.querySelector('[data-composer-input]').focus()")+ // The mock model's greeting for a new team.+ await until(text('先让团队帮你做哪块'), 'the greeting')+ await dismissNotice()+ await evaluate("[...document.querySelectorAll('[role=textbox][contenteditable=true], textarea')].at(-1).focus()")await cdp.call('Input.insertText', { text: 'packaged app check' })for (const type of ['keyDown', 'keyUp']) await cdp.call('Input.dispatchKeyEvent', { type, key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13 })// The mock model starts its reply with 收到: and the message.- await until(`${bubbles}.length > ${String(before)} && [...${bubbles}].some(node => node.textContent.includes('收到:packaged app check'))`, 'the reply')+ await until(text('收到:packaged app check'), 'the reply')await sleep(1000)- console.log(`check-packed: chat ${JSON.stringify(await evaluate("document.querySelector('.dsb-flow').innerText.slice(-200)"))}`)+ console.log(`check-packed: chat ${JSON.stringify(await evaluate('document.body.innerText.slice(-200)'))}`)}let failed = falsediff --git a/app/src/host-process.mjs b/app/src/host-process.mjsindex f36afb76..819462bd 100644--- a/app/src/host-process.mjs+++ b/app/src/host-process.mjs@@ -27,7 +27,7 @@ export class HostProcess {*/constructor(options) { this.#options = options }- /** @returns {Promise<{ url: string }>} the Host's launch URL */+ /** @returns {Promise<{ url: string, injections: unknown[] }>} the Host's launch URL and index injections */start() {this.#ready ??= new Promise((resolve, reject) => {const { entry, cwd, env, pnpm } = this.#options@@ -43,7 +43,7 @@ export class HostProcess {this.#stderr = (this.#stderr + chunk).slice(-STDERR_TAIL_CHARS)})child.on('message', (message) => {- if (message?.type === 'ready') resolve({ url: message.url })+ if (message?.type === 'ready') resolve({ url: message.url, injections: message.injections })else if (message?.type === 'fatal') this.#fail(new Error(message.message), reject)})child.once('error', (error) => { this.#fail(error, reject) })diff --git a/app/src/host.mjs b/app/src/host.mjsindex 3a0f27f9..9d3e93da 100644--- a/app/src/host.mjs+++ b/app/src/host.mjs@@ -22,7 +22,7 @@ async function main() {profile: PROFILE,resolvedProfile: { profile, installAnchor: INSTALL_ANCHOR },patchFiles: [],- args: [],+ args: ['--no-open', '--port', '0'],...(pnpm === undefined ? {} : {packageManager: { command: process.execPath, args: ['--expose-internals', pnpm], env: { ELECTRON_RUN_AS_NODE: '1' } },}),@@ -42,7 +42,7 @@ async function main() {// A profile patch can turn these rows off; then the window has nothing to talk to.if (webServer === undefined || connection === undefined) throw new Error(`The profile in ${profile.dir} does not start the engine's web server and connection.`)const url = connection.authenticatedUrl(`http://127.0.0.1:${String(webServer.port)}`)- await send({ type: 'ready', url })+ await send({ type: 'ready', url, injections: webServer.collectIndexInjections() })}main().catch(async (error) => {diff --git a/app/src/main.mjs b/app/src/main.mjsindex bb5390dd..67c13064 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -1,23 +1,22 @@// Electron main process: one window for the Bot team, served by the app's own DSH Host.-// The dsh-app scheme and the request forwarding follow DeepSeek Harness-// apps/desktop/src/main.ts (MIT); see NOTICE.-import { app, BrowserWindow, dialog, Menu, nativeTheme, protocol, screen, shell } from 'electron'-import { existsSync, mkdirSync } from 'node:fs'+// The dsh-app scheme, the request forwarding and the WebSocket header rewrite follow+// DeepSeek Harness apps/desktop/src/main.ts (MIT); see NOTICE.+import { app, BrowserWindow, dialog, ipcMain, Menu, nativeTheme, protocol, session, shell } from 'electron'+import { mkdirSync } from 'node:fs'+import { createRequire } from 'node:module'import { homedir } from 'node:os'import { dirname, join } from 'node:path'import { fileURLToPath } from 'node:url'import { HostProcess } from './host-process.mjs'-import { APP_ORIGIN, authenticateWebHost, forwardWebRequest, serveFile } from './web.mjs'+import { APP_ORIGIN, authenticateWebHost, forwardWebRequest, serveWebDocument } from './web.mjs'// DSH writes dsh-app://app/ into workspace file URLs and Markdown file links, so the window keeps that scheme.const SCHEME = 'dsh-app'-// The window has no title bar: its page draws a band this high along the top (--dsb-band-// in ui/src/app.css), and the system's window buttons sit in it.-const BAND = 48+const IPC = { boot: 'ds-bot:boot', bootFailed: 'ds-bot:boot-failed' }+const STATIC_PATHS = new Set(['/', '/index.html', '/manifest.webmanifest'])const here = dirname(fileURLToPath(import.meta.url))-// The window is the app's own build (ui/, `npm run build`); everything under /api/ goes to the Host.-const uiDist = join(here, '..', 'ui', 'dist')+const webDist = join(dirname(createRequire(import.meta.url).resolve('@deepseek-ai/dsh-web-frontend/package.json')), 'dist')// Drawn by scripts/icon.mjs. Windows takes the .ico for its several sizes.const iconFile = join(here, '..', 'assets', process.platform === 'win32' ? 'icon.ico' : 'icon.png')const dataDir = process.env.DS_BOT_HOME || join(homedir(), '.ds-bot')@@ -51,7 +50,6 @@ if (!app.requestSingleInstanceLock()) {}function start() {- if (!existsSync(join(uiDist, 'index.html'))) throw new Error('The window is not built. Run npm run build in app/.')const profileDir = join(dataDir, 'profiles', 'ds-bot')mkdirSync(profileDir, { recursive: true })host = new HostProcess({@@ -67,43 +65,46 @@ function start() {})ready.catch(fail)- // The window opens while the Host boots; its first requests wait for the Host.- protocol.handle(SCHEME, async (request) => {+ protocol.handle(SCHEME, (request) => {const url = new URL(request.url)if (url.hostname !== 'app') return new Response(null, { status: 404 })- if (!url.pathname.startsWith('/api/')) return serveFile(request, uiDist)- const target = hostState ?? await ready.catch(() => undefined)- if (target === undefined) return new Response(null, { status: 503 })- return forwardWebRequest(request, target.url, target.cookie)+ if (STATIC_PATHS.has(url.pathname) || url.pathname.startsWith('/assets/')) return serveWebDocument(request, webDist)+ if (hostState === undefined) return new Response(null, { status: 503 })+ return forwardWebRequest(request, hostState.url, hostState.cookie)+ })++ ipcMain.handle(IPC.boot, async (event) => {+ assertWindow(event)+ const { url, injections } = await ready+ return { injections, streamBaseUrl: new URL(url).origin }+ })+ ipcMain.handle(IPC.bootFailed, (event, message) => {+ assertWindow(event)+ fail(new Error(String(message)))+ })++ // The stream connects to the Host directly; the Host accepts only its own origin and cookie.+ session.defaultSession.webRequest.onBeforeSendHeaders({ urls: ['ws://127.0.0.1/*'] }, (details, callback) => {+ if (hostState === undefined || details.webContentsId !== mainWindow?.webContents.id) { callback({}); return }+ const target = new URL(hostState.url)+ if (new URL(details.url).host !== target.host) { callback({}); return }+ const headers = Object.fromEntries(Object.entries(details.requestHeaders).map(([name, value]) => [name.toLowerCase(), value]))+ if (headers.origin !== APP_ORIGIN) { callback({ cancel: true }); return }+ callback({ requestHeaders: { ...headers, origin: target.origin, cookie: hostState.cookie, 'sec-fetch-site': 'same-origin' } })})setMenu()// A packaged app has the icon in its bundle; Electron's own run shows Electron's.if (process.platform === 'darwin' && !app.isPackaged) app.dock?.setIcon(iconFile)createWindow()- nativeTheme.on('updated', () => {- if (mainWindow === undefined) return- mainWindow.setBackgroundColor(windowFill())- if (process.platform !== 'darwin') mainWindow.setTitleBarOverlay(windowButtons())- })}-const windowFill = () => (nativeTheme.shouldUseDarkColors ? '#141414' : '#fcfcfc')-// Clear, so the buttons sit on the page's own colors; the symbols take its text color.-const windowButtons = () => ({ color: '#00000000', symbolColor: nativeTheme.shouldUseDarkColors ? '#f2f2f2' : '#141414', height: BAND })-function createWindow() {- const area = screen.getPrimaryDisplay().workAreaSizemainWindow = new BrowserWindow({- width: Math.min(1320, Math.round(area.width * 0.9)), height: Math.min(860, Math.round(area.height * 0.9)),- minWidth: 720, minHeight: 480,+ width: 1320, height: 860, minWidth: 720, minHeight: 480,title: 'DeepSeek Bot', show: false, icon: iconFile,- titleBarStyle: 'hidden',- // macOS keeps its traffic lights, centered in the band; Windows and Linux draw their- // buttons over the band's right end.- ...(process.platform === 'darwin' ? { trafficLightPosition: { x: 18, y: (BAND - 12) / 2 } } : { titleBarOverlay: windowButtons() }),- backgroundColor: windowFill(),- webPreferences: { contextIsolation: true, sandbox: true },+ backgroundColor: nativeTheme.shouldUseDarkColors ? '#1b1b1c' : '#ffffff',+ webPreferences: { preload: join(here, 'preload.cjs'), contextIsolation: true, sandbox: true },})mainWindow.once('ready-to-show', () => { mainWindow?.show() })mainWindow.on('page-title-updated', (event) => { event.preventDefault() })@@ -135,6 +136,12 @@ function focusWindow() {mainWindow.focus()}+function assertWindow(event) {+ const contents = mainWindow?.webContents+ if (contents === undefined || event.sender !== contents || event.senderFrame !== contents.mainFrame+ || !event.senderFrame.url.startsWith(`${APP_ORIGIN}/`)) throw new Error('DeepSeek Bot: rejected IPC from an unknown page')+}+function openOutside(url) {if (/^https?:\/\//iu.test(url)) void shell.openExternal(url)}diff --git a/app/src/preload.cjs b/app/src/preload.cjsnew file mode 100644index 00000000..acc18b39--- /dev/null+++ b/app/src/preload.cjs@@ -0,0 +1,9 @@+// Gives the DSH Web entry the boot handshake it uses inside an app window.+const { contextBridge, ipcRenderer } = require('electron')++if (location.protocol === 'dsh-app:' && location.hostname === 'app') {+ contextBridge.exposeInMainWorld('dshDesktopBoot', {+ ready: () => ipcRenderer.invoke('ds-bot:boot'),+ failed: (message) => ipcRenderer.invoke('ds-bot:boot-failed', String(message)),+ })+}diff --git a/app/src/profile.mjs b/app/src/profile.mjsindex 10b829f0..d7f04110 100644--- a/app/src/profile.mjs+++ b/app/src/profile.mjs@@ -3,10 +3,10 @@ import { fileURLToPath } from 'node:url'import { initProfile, loadProfileDirectory, readProfileManifest, resolveProfileDir, writeProfileBundles } from '@deepseek-ai/dsh-app-boot'export const PROFILE = 'ds-bot'-// DSH's shared core, the app's engine layer (../engine), then the Bot team. Bundles the user installs follow.-export const BUNDLES = ['@deepseek-ai/dsh-base', 'deepseek-bot-engine', 'ds-bot']-// Bundles that earlier builds of the app put in its profile.-const RETIRED_BUNDLES = ['@deepseek-ai/dsh-web-app']+// DSH's shared core, DSH's web front end (the window), then the Bot team. Bundles the user installs follow.+export const BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', 'ds-bot']+// Bundles that earlier builds of the app put in its profile: the engine layer of its own window (../engine).+const RETIRED_BUNDLES = ['deepseek-bot-engine']// The app's own manifest is the installation: DSH imports plugins only from the installation's dependency// graph, resolves bundles there first, and keeps the bundles it names as direct dependencies from removal.export const INSTALL_ANCHOR = fileURLToPath(new URL('../package.json', import.meta.url))diff --git a/app/src/web.mjs b/app/src/web.mjsindex b2c0a375..24b77b4c 100644--- a/app/src/web.mjs+++ b/app/src/web.mjs@@ -1,6 +1,5 @@-// The window's files and the authenticated request forwarding to the Host.-// The launch-token exchange and the forwarding adapt DeepSeek Harness-// apps/desktop/src/web-document.ts (MIT); see NOTICE.+// The local Web document and the authenticated request forwarding for the app window.+// Adapted from DeepSeek Harness apps/desktop/src/web-document.ts (MIT); see NOTICE.import { readFile } from 'node:fs/promises'import { extname, resolve, sep } from 'node:path'@@ -11,14 +10,16 @@ const MIME = {'.css': 'text/css; charset=utf-8', '.svg': 'image/svg+xml', '.json': 'application/json','.woff2': 'font/woff2', '.png': 'image/png', '.ico': 'image/x-icon',}+// The Web entry waits on this gate until the shell hands over the Host's index injections.+const BOOT = '<script>globalThis.__DSH_BOOT_READY__ = Promise.withResolvers()</script>'/**- * Serve a file of the window's build.+ * Serve a file of the DSH Web build; the index gets the boot gate.* @param {Request} request - request from the app origin- * @param {string} root - the build's directory+ * @param {string} root - the Web build's `dist` directory* @returns {Promise<Response>}*/-export async function serveFile(request, root) {+export async function serveWebDocument(request, root) {if (!['GET', 'HEAD'].includes(request.method)) return new Response(null, { status: 405 })const url = new URL(request.url)let pathname@@ -27,10 +28,12 @@ export async function serveFile(request, root) {if (!target.startsWith(resolve(root) + sep)) return new Response(null, { status: 403 })let bodytry { body = await readFile(target) } catch (error) {- if (error.code === 'ENOENT' || error.code === 'EISDIR') return new Response(null, { status: 404 })+ if (error.code === 'ENOENT') return new Response(null, { status: 404 })throw error}- return new Response(request.method === 'HEAD' ? null : new Uint8Array(body), {+ const content = pathname === '/' || pathname === '/index.html'+ ? body.toString().replace('<head>', '<head>' + BOOT) : new Uint8Array(body)+ return new Response(request.method === 'HEAD' ? null : content, {headers: { 'content-type': MIME[extname(target)] ?? 'application/octet-stream' },})}@@ -56,10 +59,11 @@ const WITHHELD_RESPONSE_HEADERS = ['content-encoding', 'content-length','transfer-encoding', 'connection', 'keep-alive', 'te', 'trailer', 'upgrade', 'proxy-authenticate', 'proxy-authorization',]+// The Host marks plugin bundles immutable under a revision that changes every launch.+const PLUGIN_BUNDLE_PATH = /^\/plugins\//u/*** Forward a request from the app origin to the Host as a same-origin request with the Host cookie.- * The response streams through, so the live feed arrives as it is written.* @param {Request} request - request from the app origin* @param {string} host - Host URL* @param {string} cookie - Host cookie pair@@ -80,5 +84,6 @@ export async function forwardWebRequest(request, host, cookie) {})const outgoing = new Headers(response.headers)for (const name of WITHHELD_RESPONSE_HEADERS) outgoing.delete(name)+ if (PLUGIN_BUNDLE_PATH.test(source.pathname)) outgoing.set('cache-control', 'no-store')return new Response(response.body, { status: response.status, headers: outgoing })}diff --git a/app/test/profile.test.mjs b/app/test/profile.test.mjsindex 095e935f..6c977423 100644--- a/app/test/profile.test.mjs+++ b/app/test/profile.test.mjs@@ -6,7 +6,7 @@ import { after, before, describe, test } from 'node:test'import { composeEntries } from '@deepseek-ai/dsh-app-boot'import { BUNDLES, claimBundles, loadAppProfile } from '../src/profile.mjs'-// Packages of DSH's own Web front end and its browser runtime; the window is the app's own page.+// Packages of DSH's own Web front end and its browser runtime, which the window shows.const DSH_WEB_FRONT_END = /^@deepseek-ai\/dsh-(client-ui-|web-app|web-frontend|client-modules|host-frontend-static|cordis-client-runner|client-hmr)/u// Every row of an entry list, with the rows inside groups and agent presets.@@ -31,31 +31,10 @@ describe('the app profile', () => {})after(() => { rmSync(home, { recursive: true, force: true }) })- test('mounts no part of the DSH Web front end', () => {- assert.deepEqual(rows(entries).map((entry) => entry.name).filter((name) => DSH_WEB_FRONT_END.test(name)), [])- })-- test('mounts the transport, the services ds-bot uses and the Bot team', () => {+ test('mounts DSH Web, which the window shows, and the Bot team', () => {const on = new Set(entries.filter((entry) => entry.disabled !== true).map((entry) => entry.id))- for (const id of ['webserver', 'connection', 'engine-index', 'file-upload', 'workspace', 'session-controller', 'session-stats', 'directory-picker', 'agent-preset-registry', 'preset-standard', 'bot']) {- assert.ok(on.has(id), `${id} is mounted`)- }- })-- test('gives Bot Sessions the standard preset without goals', () => {- assert.equal(entries.find((entry) => entry.id === 'agent-preset-registry').config.default, 'standard')- const preset = entries.find((entry) => entry.id === 'preset-standard')- assert.equal(preset.config.id, 'standard')- const names = rows(preset.config.plugins).map((row) => row.name)- assert.ok(names.includes('@deepseek-ai/dsh-tool-fs'))- assert.deepEqual(names.filter((name) => /goal/u.test(name)), [])- })-- test('keeps every preset row off the host plane', () => {- const top = new Map(entries.map((entry) => [entry.id, entry]))- const preset = entries.find((entry) => entry.id === 'preset-standard')- const mounted = rows(preset.config.plugins).filter((row) => top.has(row.id) && top.get(row.id).disabled !== true)- assert.deepEqual(mounted.map((row) => row.id), [])+ for (const id of ['webserver', 'connection', 'bot']) assert.ok(on.has(id), `${id} is mounted`)+ assert.ok(rows(entries).some((entry) => DSH_WEB_FRONT_END.test(entry.name ?? '')), 'the DSH Web front end is mounted')})})@@ -71,7 +50,7 @@ describe('claimBundles', () => {const read = () => JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))test('puts the app bundles first, keeps the user bundles and drops the retired ones', () => {- write(['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', 'ds-bot', 'a-plugin'])+ write(['@deepseek-ai/dsh-base', 'deepseek-bot-engine', 'ds-bot', 'a-plugin'])claimBundles(dir)assert.deepEqual(read().dsh.profile.bundles, [...BUNDLES, 'a-plugin'])assert.deepEqual(read().dependencies, { 'a-plugin': '1.0.0' })diff --git a/docs/plans/2026-10-16-desktop-app.md b/docs/plans/2026-10-16-desktop-app.mdindex 754dac5b..9c818810 100644--- a/docs/plans/2026-10-16-desktop-app.md+++ b/docs/plans/2026-10-16-desktop-app.md@@ -10,7 +10,7 @@取舍:- **引擎用 DSH,不另写 Agent 运行时。** Bot 的回合、工具、模型、会话、MCP、技能照旧走 DSH,和插件版一样。-- **界面自己写,不建在 DSH 的网页前端上。** DSH 网页前端启动时要激活全部界面插件,一个插件出错整页停住;它的模块格式和页面结构由 DSH 决定,还在变。Bot 界面要能按页面加载,一个插件出错只影响它自己。代价是 DSH 插件里管界面的那部分不能原样装进来,要小改。+- **界面先用 DSH 的网页前端。** 自己写界面要把 DSH 网页前端已有的东西(工具卡片、审批、设置、Markdown、发文件、群聊历史)一样样重做,拖慢了其他工作,所以先停下。窗口用 DSH 的网页前端,`ds-bot` 以插件的形式在里面,和 DSH Desktop 里一样。自己的界面以后再接着做,原因不变:DSH 网页前端启动时要激活全部界面插件,一个插件出错整页停住;它的模块格式和页面结构由 DSH 决定,还在变。## 已定的行为@@ -18,24 +18,17 @@| 部分 | 做什么 ||---|---|-| 壳 | Electron 主进程。只开一个实例;窗口用 `dsh-app://app` 加载页面,把请求转发给引擎;管引擎进程的启动和退出。窗口无边框:没有系统标题栏;页面最上面一行可以拖动窗口,最小化、最大化、关闭三个按钮在这一行的最右边(macOS 的红绿灯在最左边) |+| 壳 | Electron 主进程。只开一个实例;窗口用 `dsh-app://app` 加载 DSH 的网页前端,把请求转发给引擎;管引擎进程的启动和退出。窗口用系统标题栏 || 引擎 | 子进程,用 Electron 自带的 Node 运行。通过 `@deepseek-ai/dsh/profile-boot` 的 `runProfile()` 启动 profile `ds-bot`,只监听 `127.0.0.1` 上系统分配的端口。环境变量 `DS_BOT_APP=1` 告诉 ds-bot 它跑在桌面应用里 |-| 界面 | DS Bot 自己写的网页(React + Vite)。只认 DS Bot 自己的接口:引擎里的 ds-bot 用 HTTP 和事件流提供团队、对话和设置的数据,界面不直接调 DSH 的接口,也不引用 `@deepseek-ai/*` 的包。DSH 只出现在引擎这一层。Bot 界面(侧栏、对话、详情、弹窗和它们的样式)和插件版是同一套代码,两边长得一样;插件版里由 DSH 画的部分(Markdown 排版、会话框架),窗口自己画 |+| 界面 | DSH 的网页前端加上 `ds-bot` 插件,和插件版一样 |- 插件版和桌面应用用同一份 `ds-bot`,插件版不变。- 安装包和 `ds-bot` 用同一个版本号。-- 引擎的 profile 由三个 bundle 叠成:DSH 的 `dsh-base`、桌面应用的引擎层 `deepseek-bot-engine`、`ds-bot`,用户装的插件排在后面。引擎层只放引擎用的东西:给 ds-bot 接口用的本机传输、ds-bot 用到的宿主服务、Bot 会话用的 `standard` 预设(不带目标)。DSH 网页前端的部分一个都不加载。每次启动时,引擎把这三个 bundle 排回最前面。--### 界面--- Bot 详情里显示这个 Bot 当前对话的轮数、输出速度(tok/s)、缓存命中和上下文用量。插件版里这一行在 DSH 输入框下面的状态栏,窗口里没有这个状态栏。+- 引擎的 profile 由三个 bundle 叠成:DSH 的 `dsh-base`、DSH 的网页前端 `dsh-web-app`、`ds-bot`,用户装的插件排在后面。每次启动时,引擎把这三个 bundle 排回最前面。### 模型-- 窗口里没有 DSH 的设置,所以设置里多一页「模型」:列出模型服务商、它们的模型和 key 的状态;可以填、换、删 key,可以添加、删除服务商。插件版没有这一页,照旧用 DSH 的设置。-- 能添加的服务商就是 DSH 自带的那些,模型列表也用 DSH 带的。DSH 没有的接口,按 ID、地址、协议和 key 手动加,模型从接口获取或手填。-- 服务商写进 DSH 的设置,key 存进 DSH 的密钥库,key 的名字和 DSH 自己的模型页一样,所以插件版和 DSH 网页版都认。key 只从界面送进引擎,不读回来。-- 没有一个模型有 API key 时,第一个主 Bot 在对话里请用户填 DeepSeek 的 key;这张卡片上也能去「模型」页用别的服务商。+- 模型服务商和 key 在 DSH 自己的设置里配,存在桌面应用的数据位置里,和插件版一样。### DSH 版本@@ -75,23 +68,19 @@## 不做什么- 不 fork DSH,不给 DSH 打补丁。-- 不把 DSH 的网页前端当作 Bot 界面的底层,也不原样加载 DSH 的界面插件。- 不做 npm 安装的桌面应用,也不做在 DSH Desktop 里一键安装。- 第一版不带 Office 技能。## 暂时不做-以后再看要不要加。插件版里照旧都有。--- DSH 的右侧栏(文件、终端)。-- 设置里的「经典 Agent 模式」(切到 DSH 自己的界面)。+- DS Bot 自己的界面:先停下,窗口用 DSH 的网页前端。代码留在仓库里(`app/ui/` 和它的引擎层 `app/engine/`),不安装、不打包。上面「插件」一节里界面插件的写法,等自己的界面接着做时再落实。## 已知限制-- 窗口里还没有:群聊的历史消息、工具卡片和审批、首次启动和导入、DeepSeek 账号登录、每个 Bot 的浏览器、更新。侧栏每一行的最新一句只显示打开窗口以后的新消息。插件版里打开 DSH 自己界面的入口(连接插件、Harness 设置,「+」里的添加文件和引用对话)窗口里也没有。+- 还没有:首次启动和导入、更新。- 不签名:Windows 第一次运行会弹出 SmartScreen 警告,macOS 要在系统设置里手动放行。- 会话里记着工作文件夹的完整路径,不能改。所以导入和搬工作文件夹都要换段。-- 安装的 `@deepseek-ai/dsh` 包带着 DSH 的网页前端、Office 套件和语音包,所以安装包里仍有这些文件,只是不加载。+- 安装的 `@deepseek-ai/dsh` 包带着 Office 套件和语音包,所以安装包里仍有这些文件,只是不加载。## 变更@@ -102,3 +91,4 @@- 2026-10-17:引擎的 profile 换成桌面应用自己的组合,不再加载 DSH 的网页前端,PR #291。- 2026-10-18:应用标识定为 `io.github.fei2411.deepseekbot`;Windows 只给当前用户安装,更新下载完提示重启;安装包不按 profile 删减 DSH 的文件,PR #303。- 2026-10-18:设置里加「模型」页,服务商和 key 存在 DSH 里,PR #319。+- 2026-10-18:自己的界面先停下,窗口换回 DSH 的网页前端和系统标题栏;引擎的 profile 换回 `dsh-base`、`dsh-web-app`、`ds-bot`。diff --git a/docs/plans/README.md b/docs/plans/README.mdindex 4e1e4494..37a00aef 100644--- a/docs/plans/README.md+++ b/docs/plans/README.md@@ -43,5 +43,5 @@| [上下文与记忆](2026-10-09-context-and-memory.md) | 对话分段、上下文管家(压缩还是换段)、交接包、`read_own_chat`;记忆的存放、格式、权限、整理和冻结 || [Bot 运行配置](2026-10-10-bot-runtime.md) | Agent 预设、每个 Bot 的模型和思考强度、工作文件夹、能力(MCP、技能、能力包) || [长消息](2026-10-16-long-messages.md) | state.json 只存开头;超过 2 万字的 Bot 消息转成 DSH 文件;成员和界面怎么读全文 |-| [桌面应用](2026-10-16-desktop-app.md) | 壳、引擎和自己的界面怎么分;锁定的 DSH 版本、独立的数据位置、首次启动和导入、插件怎么兼容 DSH、安装和更新 |+| [桌面应用](2026-10-16-desktop-app.md) | 壳、引擎和界面怎么分;锁定的 DSH 版本、独立的数据位置、首次启动和导入、插件怎么兼容 DSH、安装和更新 || [Bot 之间派活](2026-10-16-bot-handoffs.md) | Bot 看得到对方的状态;没读的消息合成一条;派活树:下面的活交回后才往上交,不许发给在等结果的 Bot;不设总量和链长上限 |