A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Run the Linux desktop host in bundled plain Node
Fei2411f1021baba931
diff --git a/app/README.md b/app/README.mdindex af0a497e..1977e89a 100644--- a/app/README.md+++ b/app/README.md@@ -12,7 +12,7 @@ npm start # starts the appWhen 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.-`npm run runtime` downloads the Office payload (Python with the document libraries, a standalone Node, the Office skill assets) into `build/runtime`, so the unpackaged app mounts the Office skills the same way a package does. `beforePack` builds it again for the package; without it the app still runs, only without the Office skills.+`npm run runtime` downloads the runtime payload (Python with the document libraries, a standalone Node, the Office skill assets) into `build/runtime`. On Linux, run it before `npm start`: the Host uses this plain Node to keep sharp's libvips out of Electron's process. On macOS and Windows the payload is optional for source runs; without it only the Office skills are unavailable. `beforePack` prepares the payload for every package.npm installs `ds-bot` from `../ds-bot` as a copy of its package files (`install-links` in `.npmrc`), so the app runs the plugin of this checkout. Run `npm ci` again after you change `ds-bot` or merge a branch that changes it: while the version stays the same, `npm install` keeps the old copy. `overrides` in `package.json` pins the four peer dependencies of `ds-bot` to the DSH version: they are declared as `*`, and npm does not choose a pre-release to satisfy `*`.@@ -151,7 +151,7 @@ The launch URL of the Host is good for one use only. When the first load never c| `src/bot-browser.mjs` | The Bot browsers' webviews: only a leased one attaches, with fixed preferences; each Bot's logins stay on disk until the Bot is deleted; pages cannot reach the Host || `src/cookie-parse.mjs`, `src/cookie-import.mjs`, `src/browser-sources.mjs` | Cookie imports: the cookie-file parser (Cookie-Editor JSON, Netscape, Playwright storageState), the write into a Bot's partition with read-back and flush, and the installed-browser profiles a source is cloned from — the source browser itself decrypts its own store over a CDP pipe; values never leave the main process || `src/window-frame.mjs`, `src/mica.css` | The frameless Windows window: the caption band, when Mica is available (Windows 11 22H2 and later), and the stylesheet that lets Mica through the sidebar |-| `src/host-process.mjs` | Starts the Host in Electron's Node mode and owns its exit |+| `src/host-process.mjs` | Starts the Host in the bundled plain Node on Linux, Electron's Node mode elsewhere, and owns its exit || `src/host.mjs` | The Host: boots the profile with `runProfile()` and reports the launch URL and the page injections; for the first-run check (`DS_BOT_CHECK`), the chats it cannot read || `src/profile.mjs` | The profiles: the app's own and the first-run check's, their bundles, and their creation and update || `src/session-check.mjs` | Which chats the pinned DSH refuses because a newer DSH wrote them |diff --git a/app/electron-builder.yml b/app/electron-builder.ymlindex dbfc8987..b90f80ca 100644--- a/app/electron-builder.yml+++ b/app/electron-builder.yml@@ -51,6 +51,8 @@ mac:icon: assets/icon.pngcategory: public.app-category.productivitylinux:+ # The Linux Host uses the payload's plain Node, which cannot read asar archives.+ asar: false# One AppImage runs on every distribution and updates itself; the deb is for Debian/Ubuntu,# where it avoids Ubuntu 24.04's AppArmor question of an AppImage and adds a menu entry.target:diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjsindex fdb971fc..8c206c9d 100644--- a/app/scripts/check-packed.mjs+++ b/app/scripts/check-packed.mjs@@ -11,6 +11,7 @@ import { tmpdir } from 'node:os'import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'import { setTimeout as sleep } from 'node:timers/promises'import { fileURLToPath } from 'node:url'+import { hostExecutable } from '../src/host-process.mjs'const root = join(dirname(fileURLToPath(import.meta.url)), '..')const [given, shotFile] = process.argv.slice(2)@@ -35,13 +36,14 @@ if (!existsSync(executable)) {{const resources = process.platform === 'darwin' ? join(dirname(executable), '..', 'Resources') : join(dirname(executable), 'resources')const windows = process.platform === 'win32'+ const unpacked = process.platform === 'linux' ? 'app' : 'app.asar.unpacked'const required = ['primary-runtime/runtime.json',join('primary-runtime', 'dependencies', 'python', ...(windows ? ['python.exe'] : ['bin', 'python3'])),join('primary-runtime', 'dependencies', 'node', 'bin', windows ? 'node.exe' : 'node'),join('office-skills', 'office', 'SKILL.md'),- join('app.asar.unpacked', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'lib', 'cli.js'),- join('app.asar.unpacked', 'node_modules', 'ds-bot', 'office.js'),+ join(unpacked, 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'lib', 'cli.js'),+ join(unpacked, 'node_modules', 'ds-bot', 'office.js'),]const missing = required.filter((entry) => !existsSync(join(resources, entry)))if (missing.length > 0) {@@ -88,10 +90,12 @@ function outsideCheckout(file) {function checkSharp(app) {const resources = process.platform === 'darwin' ? resolve(app, '..', '..', 'Resources') : join(dirname(app), 'resources')+ const linux = process.platform === 'linux'const script = `const assert = require('node:assert/strict')const { createRequire } = require('node:module')- const appRequire = createRequire(${JSON.stringify(join(resources, 'app.asar', 'package.json'))})+ ${linux ? "assert.equal(process.versions.electron, undefined, 'Linux image processing must not run in Electron')" : ''}+ const appRequire = createRequire(${JSON.stringify(join(resources, linux ? 'app' : 'app.asar', 'package.json'))})const sharp = appRequire('sharp');(async () => {const image = await sharp({ create: { width: 4, height: 4, channels: 3, background: '#ff0000' } }).png().toBuffer()@@ -102,8 +106,8 @@ function checkSharp(app) {console.log('check-packed: sharp image processing passed (libvips ' + sharp.versions.vips + ')')})().catch(error => { console.error(error); process.exitCode = 1 })`- // Use the shipped Electron and dependencies outside the checkout, just like the Host.- const result = spawnSync(app, ['-e', script], {+ // Use the Host's runtime and dependencies outside the checkout, not the CI runner's Node.+ const result = spawnSync(linux ? hostExecutable(resources) : app, ['-e', script], {cwd: work, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', NODE_PATH: '' },encoding: 'utf8', timeout: 30_000,})diff --git a/app/src/host-process.mjs b/app/src/host-process.mjsindex dba66e5c..3a69f71e 100644--- a/app/src/host-process.mjs+++ b/app/src/host-process.mjs@@ -1,9 +1,17 @@-// Runs the Host in Electron's Node mode and owns its lifetime.+// Runs the Host in plain Node on Linux, Electron's Node mode elsewhere, and owns its lifetime.// Follows DeepSeek Harness apps/desktop/src/host-process.ts (MIT); see NOTICE.import { spawn } from 'node:child_process'+import { join } from 'node:path'const STDERR_TAIL_CHARS = 8 * 1024+// Electron on Linux leaks system glib symbols into sharp's bundled libvips.+export function hostExecutable(runtimeDir, platform = process.platform) {+ return platform === 'linux'+ ? join(runtimeDir, 'primary-runtime', 'dependencies', 'node', 'bin', 'node')+ : process.execPath+}+// The web server prints its launch URL, and the launch token in it opens the Host.const redact = (text) => text.replace(/([?&]token=)[^&\s]+/gu, '$1<hidden>')@@ -14,6 +22,7 @@ const settlesWithin = (promise, ms) => new Promise((resolve) => {export class HostProcess {#options+ #platform#child#ready#exit@@ -26,7 +35,7 @@ export class HostProcess {* @param {{ entry: string, cwd: string, env: NodeJS.ProcessEnv, pnpm: string, onFailure: (error: Error) => void }} options* `onFailure` receives the first unexpected failure, also after the Host was ready.*/- constructor(options) { this.#options = options }+ constructor(options, platform = process.platform) { this.#options = options; this.#platform = platform }/*** @returns {Promise<{ url: string, injections: unknown[] } | { unreadable: string[] }>} the Host's launch URL@@ -35,7 +44,7 @@ export class HostProcess {start() {this.#ready ??= new Promise((resolve, reject) => {const { entry, cwd, env, pnpm } = this.#options- const child = spawn(process.execPath, ['--expose-internals', entry, pnpm], {+ const child = spawn(hostExecutable(env.DS_BOT_RUNTIME_DIR, this.#platform), ['--expose-internals', entry, pnpm], {cwd, env: { ...env, ELECTRON_RUN_AS_NODE: '1' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'],})this.#child = childdiff --git a/app/src/host.mjs b/app/src/host.mjsindex 6b641f94..70a1bb2e 100644--- a/app/src/host.mjs+++ b/app/src/host.mjs@@ -1,4 +1,5 @@-// The Host: the shell runs this file in Electron's Node mode. It boots the app's own `ds-bot` profile+// The Host: the shell runs this file in plain Node on Linux and Electron's Node mode elsewhere.+// It boots the app's own `ds-bot` profile// on a loopback port and reports the launch URL over IPC. With DS_BOT_CHECK, the path of a JSON list// of Session ids, it boots the first-run check's profile instead and reports which of them it cannot read.// Follows DeepSeek Harness apps/desktop-host/src/index.ts (MIT); see NOTICE.diff --git a/app/src/main.mjs b/app/src/main.mjsindex 43d7bbe3..24928d7e 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -178,12 +178,13 @@ async function start() {const port = await hostPort(join(app.getPath('userData'), 'host-port.json'))origin = `http://127.0.0.1:${String(port)}`const pnpm = join(app.getAppPath(), 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')+ const runtimeDir = app.isPackaged ? process.resourcesPath : join(here, '..', 'build', 'runtime')const profileDir = join(where.dataDir, 'profiles', PROFILE)mkdirSync(profileDir, { recursive: true })const newHost = () => new HostProcess({entry: join(here, 'host.mjs'),cwd: profileDir,- env: { ...process.env, DSH_HOME: where.dataDir, DS_BOT_PORT: String(port), DS_BOT_APP: '1', DS_BOT_USER_DSH_HOME: userDshHome(), DS_BOT_RUNTIME_DIR: app.isPackaged ? process.resourcesPath : join(here, '..', 'build', 'runtime'), ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },+ env: { ...process.env, DSH_HOME: where.dataDir, DS_BOT_PORT: String(port), DS_BOT_APP: '1', DS_BOT_USER_DSH_HOME: userDshHome(), DS_BOT_RUNTIME_DIR: runtimeDir, ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },pnpm,onFailure: fail,})@@ -191,7 +192,7 @@ async function start() {const newCheck = (home, list) => {const cwd = join(home, 'profiles', CHECK_PROFILE)mkdirSync(cwd, { recursive: true })- return new HostProcess({ entry: join(here, 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list }, pnpm, onFailure: () => {} })+ return new HostProcess({ entry: join(here, 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list, DS_BOT_RUNTIME_DIR: runtimeDir }, pnpm, onFailure: () => {} })}const ready = (async () => {let copieddiff --git a/app/test/fixtures/image-host.mjs b/app/test/fixtures/image-host.mjsnew file mode 100644index 00000000..46e14318--- /dev/null+++ b/app/test/fixtures/image-host.mjs@@ -0,0 +1,14 @@+import assert from 'node:assert/strict'+import sharp from 'sharp'++assert.equal(process.versions.electron, undefined)+const png = await sharp({ create: { width: 4, height: 4, channels: 3, background: '#ff0000' } }).png().toBuffer()+const { data, info } = await sharp(png).resize(2, 2).removeAlpha().raw().toBuffer({ resolveWithObject: true })+assert.deepEqual([...data], Array.from({ length: 4 }, () => [255, 0, 0]).flat())+process.send({+ type: 'ready', url: 'http://127.0.0.1/',+ injections: [{ executable: process.argv0, electron: process.versions.electron ?? null, width: info.width, height: info.height }],+})+process.on('message', message => {+ if (message?.type === 'shutdown') process.disconnect()+})diff --git a/app/test/host-process.test.mjs b/app/test/host-process.test.mjsnew file mode 100644index 00000000..2115fbf5--- /dev/null+++ b/app/test/host-process.test.mjs@@ -0,0 +1,41 @@+import assert from 'node:assert/strict'+import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs'+import { createRequire } from 'node:module'+import { tmpdir } from 'node:os'+import { dirname, join } from 'node:path'+import { test } from 'node:test'+import { fileURLToPath } from 'node:url'+import * as host from '../src/host-process.mjs'++test('Linux uses the bundled plain Node, not Electron in Node mode', () => {+ const resources = join('application', 'resources')+ assert.equal(host.hostExecutable(resources, 'linux'), join(resources, 'primary-runtime', 'dependencies', 'node', 'bin', 'node'))+ for (const platform of ['darwin', 'win32']) {+ assert.equal(host.hostExecutable(resources, platform), process.execPath)+ }+})++test('the Linux Host loads sharp only in its plain Node child', { skip: process.platform === 'win32' }, async () => {+ const work = mkdtempSync(join(tmpdir(), 'ds-bot-linux-image-'))+ const node = join(work, 'primary-runtime', 'dependencies', 'node', 'bin', 'node')+ mkdirSync(dirname(node), { recursive: true })+ symlinkSync(process.execPath, node)+ const app = dirname(dirname(fileURLToPath(import.meta.url)))+ const failures = []+ const child = new host.HostProcess({+ entry: join(app, 'test', 'fixtures', 'image-host.mjs'),+ cwd: work,+ env: { ...process.env, DS_BOT_RUNTIME_DIR: work },+ pnpm: join(app, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs'),+ onFailure: error => failures.push(error),+ }, 'linux')+ try {+ const { injections } = await child.start()+ assert.deepEqual(injections, [{ executable: node, electron: null, width: 2, height: 2 }])+ assert.equal(Object.keys(createRequire(import.meta.url).cache).some(file => /[/\\]sharp[/\\]/u.test(file)), false)+ assert.deepEqual(failures, [])+ } finally {+ await child.stop()+ rmSync(work, { recursive: true, force: true })+ }+})diff --git a/app/test/package.test.mjs b/app/test/package.test.mjsindex 57bba5a4..abb3a62f 100644--- a/app/test/package.test.mjs+++ b/app/test/package.test.mjs@@ -34,6 +34,13 @@ test('sharp native modules and versioned libvips libraries are unpacked togetherassert.equal(filter(join(root, 'node_modules/yaml/dist/index.js'), stat), false)})+test('Linux leaves the Host and its dependencies readable by plain Node', () => {+ const config = parse(readFileSync(new URL('../electron-builder.yml', import.meta.url), 'utf8'))+ assert.equal(config.linux.asar, false)+ assert.notEqual(config.mac.asar, false)+ assert.notEqual(config.win.asar, false)+})+// A release is tagged with the version of ds-bot, and the installed apps compare their own// version with the one in the release's latest.yml.test('the app has the version of ds-bot', () => {diff --git a/app/test/session-check.test.mjs b/app/test/session-check.test.mjsindex cfca91b9..320c08ed 100644--- a/app/test/session-check.test.mjs+++ b/app/test/session-check.test.mjs@@ -55,7 +55,7 @@ describe('the first-run check', () => {const check = new HostProcess({entry: join(app, 'src', 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list },pnpm: join(app, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs'), onFailure: () => {},- })+ }, 'darwin') // Exercise the Electron/Node-mode launch without a packaged runtime.try {({ unreadable } = await check.start())} finally {