A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Copy .asar files as files in the import and the data move
AdamPlatin1236c471b136fdd
diff --git a/app/README.md b/app/README.mdindex 9fb3820d..3014ba7d 100644--- a/app/README.md+++ b/app/README.md@@ -82,7 +82,7 @@ Never point `DS_BOT_HOME` at `~/.dsh` or at the data of an app that you use.```shnpm run pack # the app without an installer: dist-pack/win-unpacked/ (Windows), dist-pack/mac*/ (macOS), dist-pack/linux-unpacked/ (Linux)npm run dist # the installer: dist-pack/DS-Bot-<version>-win-x64.exe (Windows), a .zip (macOS), an .AppImage and a .deb (Linux)-npm run check-packed # converts an image and a Word document with the packaged sharp and LibreOffice engine, starts the packaged app on throwaway folders with the mock model, chats once, closes it+npm run check-packed # copies files that end in .asar, converts an image and a Word document with the packaged sharp and LibreOffice engine, starts the packaged app on throwaway folders with the mock model, chats once, closes it```macOS produces one zip per architecture. Build arm64 on an Apple chip Mac and x64 on an Intel Mac, or under Rosetta with an x64 Node that also ran `npm ci`. Do not cross-build: it packages native modules from `node_modules`; a combined build put 12 arm64-only native modules in its x64 app. `scripts/before-pack.mjs` stops a build whose architecture is not the one of the Node that runs it. The app is ad-hoc signed so downloaded copies are sealed. It ships as a zip, not a dmg: macOS 26 calls a downloaded unsigned dmg damaged and does not open it, and an ad-hoc signature on the dmg does not help (#351). Safari unzips the download; move DS Bot to Applications. On first open, use System Settings → Privacy & Security → Open Anyway. Do not disable Gatekeeper.diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjsindex 80fa44ee..bd610a78 100644--- a/app/scripts/check-packed.mjs+++ b/app/scripts/check-packed.mjs@@ -1,4 +1,4 @@-// Check a packaged app: process an image with its sharp, convert a Word document with its LibreOffice engine, then start it on throwaway folders with the ds-bot mock model, choose a model,+// Check a packaged app: copy files that end in .asar with its copy of a user's folders, process an image with its sharp, convert a Word document with its LibreOffice engine, then start it on throwaway folders with the ds-bot mock model, choose a model,// send a message, wait for the reply, then close the window the way a user does: the window hides// and the app goes on. The window comes back when the app is started again, and the app ends the// way the tray's Quit ends it. Fails on a page error or a non-zero exit.@@ -89,6 +89,41 @@ function outsideCheckout(file) {return join(copy, relative(appDir, file))}+// The copy that the import and the data move share, in Electron's own fs, which plain Node and so+// the tests do not have: a user's files that end in .asar arrive as they are and can be removed.+function checkAsarCopy(app) {+ const resources = process.platform === 'darwin' ? resolve(app, '..', '..', 'Resources') : join(dirname(app), 'resources')+ const tree = join(resources, process.platform === 'linux' ? 'app' : 'app.asar', 'src', 'copy-tree.mjs')+ const result = spawnSync(app, ['-e', `+ const assert = require('node:assert/strict')+ const { join } = require('node:path')+ const { pathToFileURL } = require('node:url')+ const work = ${JSON.stringify(join(work, 'asar-copy'))}+ // asar's own format: two size headers, the length of the JSON, the JSON padded to 4 bytes, the files.+ const json = Buffer.from(JSON.stringify({ files: { 'f.txt': { size: 2, offset: '0' } } }))+ const padded = Math.ceil(json.length / 4) * 4+ const archive = Buffer.alloc(16 + padded + 2)+ for (const [at, size] of [[0, 4], [4, 8 + padded], [8, 4 + padded], [12, json.length]]) archive.writeUInt32LE(size, at)+ json.copy(archive, 16)+ archive.write('hi', 16 + padded)+ import(pathToFileURL(${JSON.stringify(tree)}).href).then(async ({ copyTree, disk }) => {+ assert.ok(process.versions.electron, 'this check needs Electron')+ const files = { 'valid.asar': archive, 'junk.asar': Buffer.from('no archive'), 'folder.asar/in.txt': Buffer.from('in') }+ for (const [name, content] of Object.entries(files)) {+ disk.mkdirSync(join(work, 'from', name, '..'), { recursive: true })+ disk.writeFileSync(join(work, 'from', name), content)+ }+ assert.deepEqual(await copyTree(join(work, 'from'), join(work, 'to'), { skip: true }), [])+ for (const [name, content] of Object.entries(files)) assert.ok(disk.readFileSync(join(work, 'to', name)).equals(content), name)+ await disk.promises.rm(join(work, 'to'), { recursive: true })+ assert.equal(disk.existsSync(join(work, 'to')), false)+ console.log('check-packed: files that end in .asar are copied as they are')+ }).catch((error) => { console.error(error); process.exit(1) })+ `], { cwd: work, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', NODE_PATH: '' }, encoding: 'utf8', timeout: 60_000 })+ if (result.error || result.status !== 0) throw new Error(`the .asar copy check failed (exit ${String(result.status)}): ${result.error?.message ?? result.stderr}`)+ console.log(result.stdout.trim())+}+// Run a script with the Host's runtime and the app's dependencies as the Host loads them,// outside the checkout and not with the CI runner's Node.function runInHost(app, what, script, timeout) {@@ -394,6 +429,7 @@ let failed = falseconst problems = []try {const packedApp = outsideCheckout(resolve(executable))+ checkAsarCopy(packedApp)checkSharp(packedApp)checkOffice(packedApp)const modelUrl = await startMock()diff --git a/app/src/copy-tree.mjs b/app/src/copy-tree.mjsindex 23822dd2..f4c76474 100644--- a/app/src/copy-tree.mjs+++ b/app/src/copy-tree.mjs@@ -1,8 +1,14 @@// Copying a folder of the user's whole, with its links, for the first-run import and the data move.-import { existsSync, realpathSync } from 'node:fs'-import { cp, lstat, readlink, realpath, stat, symlink } from 'node:fs/promises'import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'+// Electron's fs takes every path that ends in .asar for an archive: a file that is none cannot be+// read, one that is looks like a folder and stays locked on Windows, and a name that is not there+// yet is an error that fs.cp stops at. original-fs is the disk as it is, but for a recursive+// readdir, which still goes through Electron; plain Node has only fs.+export const disk = process.getBuiltinModule('original-fs') ?? process.getBuiltinModule('node:fs')+const { existsSync, realpathSync } = disk+const { cp, lstat, readlink, realpath, stat, symlink } = disk.promises+export const within = (inner, outer) => {const path = relative(resolve(outer), resolve(inner))return path === '' || (!path.startsWith('..') && !path.startsWith(sep) && !/^[a-z]:/iu.test(path))diff --git a/app/src/import.mjs b/app/src/import.mjsindex 0d9ac773..f18a1217 100644--- a/app/src/import.mjs+++ b/app/src/import.mjs@@ -1,15 +1,16 @@// The first-run import: a copy of the Bot team in the user's own DSH home. It only reads there.-import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'-import { chmod, cp, lstat, mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises'import { homedir, hostname } from 'node:os'import { join, relative, resolve } from 'node:path'import { parseSessionFormatLogFilename } from '@deepseek-ai/dsh-session-format'import { sessionFormatCatalog } from '@deepseek-ai/dsh-session-format-catalog'import { parse, stringify } from 'yaml'-import { copyTree, within } from './copy-tree.mjs'+import { copyTree, disk, within } from './copy-tree.mjs'export { within }+const { existsSync, readdirSync, readFileSync, statSync } = disk+const { chmod, cp, lstat, mkdir, readdir, readFile, rename, rm, writeFile } = disk.promises+// The rows of a profile patch that hold model settings: DeepSeek's API and account, other// providers, the default model and the agent presets. Rows of other plugins may name plugins// that the app does not have.diff --git a/app/src/main.mjs b/app/src/main.mjsindex 386d45f0..f1a99248 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -7,12 +7,13 @@// window is up (docs/plans/2026-10-26-start-window.md §11).import { app, BrowserWindow, clipboard, ipcMain, Menu, nativeImage, nativeTheme, powerMonitor, screen, session, shell as electronShell, systemPreferences, Tray, WebContentsView } from 'electron'import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'-import { readFile, rm } from 'node:fs/promises'+import { readFile } from 'node:fs/promises'import { release } from 'node:os'import { basename, dirname, isAbsolute, join, resolve } from 'node:path'import { setTimeout as sleep } from 'node:timers/promises'import { fileURLToPath } from 'node:url'import { canonicalExecPath } from './canonical-path.mjs'+import { disk } from './copy-tree.mjs'import { configureIdentity } from './legacy.mjs'import { hostPort } from './host-port.mjs'import { captureStdio, LogFile } from './logs.mjs'@@ -25,6 +26,8 @@ import { langOf } from './start/text.mjs'import { createDeferredPrompt } from './update-prompt.mjs'import { CAPTION_HEIGHT, cssColor, micaAvailable, nativeThemeSource } from './window-frame.mjs'+const { rm } = disk.promises+const IPC = {caption: 'ds-bot:caption-colors', nativeTheme: 'ds-bot:native-theme', fullscreen: 'ds-bot:fullscreen',dataLocation: 'ds-bot:data-location', moveData: 'ds-bot:move-data', teamWorkspace: 'ds-bot:team-workspace',diff --git a/app/src/move-data.mjs b/app/src/move-data.mjsindex fb8269b7..669e5522 100644--- a/app/src/move-data.mjs+++ b/app/src/move-data.mjs@@ -1,13 +1,14 @@// Moving the app's data to another folder. The copy is put together in a folder beside the new// one and takes its name only once it is whole, so a copy that stopped or failed leaves nothing// that looks like data. The old folder stays as it was.-import { existsSync, readdirSync, statSync } from 'node:fs'-import { mkdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'import { basename, dirname, join, resolve } from 'node:path'-import { copyTree, real, within } from './copy-tree.mjs'+import { copyTree, disk, real, within } from './copy-tree.mjs'export { copyReason } from './copy-tree.mjs'+const { existsSync, readdirSync, statSync } = disk+const { mkdir, rename, rm, rmdir, writeFile } = disk.promises+// The engine's lock on the team belongs to the old folder; the first-run copy and its check// leave their temporary folders only when they were cut short.const LEFT_BEHIND = [/^bot[\\/]state\.lock$/u, /^\.import(-check)?-\d+$/u]diff --git a/app/src/place.mjs b/app/src/place.mjsindex d5f4891d..2ebf2a85 100644--- a/app/src/place.mjs+++ b/app/src/place.mjs@@ -1,10 +1,11 @@// Where a first start puts the data: the line on the start page that says so (and when a later// start shows it again), and the root rule of 「换个位置…」 (windows-onboarding §3, 一个位置;// start-window §6). No Electron here, so the tests run without it.-import { existsSync, mkdirSync, readdirSync, rmdirSync, rmSync, statfsSync, statSync, writeFileSync } from 'node:fs'import { homedir } from 'node:os'import { basename, dirname, join, parse, resolve, sep } from 'node:path'-import { real, within } from './copy-tree.mjs'+import { disk, real, within } from './copy-tree.mjs'++const { existsSync, mkdirSync, readdirSync, rmdirSync, rmSync, statfsSync, statSync, writeFileSync } = diskexport const DATA_DIR = 'data'export const WORKSPACE_DIR = 'workspace'diff --git a/app/test/copy-tree.test.mjs b/app/test/copy-tree.test.mjsnew file mode 100644index 00000000..47744eae--- /dev/null+++ b/app/test/copy-tree.test.mjs@@ -0,0 +1,18 @@+import assert from 'node:assert/strict'+import { readFileSync } from 'node:fs'+import { test } from 'node:test'+import { disk } from '../src/copy-tree.mjs'++// Only Electron's fs shows the bug, and this job has no Electron: check-packed.mjs runs the copy+// itself. This keeps the files that touch the user's folders from going back to that fs.+test('the import, the data move and the data location stay off Electron\'s fs', () => {+ for (const name of ['copy-tree', 'import', 'move-data', 'place']) {+ const source = readFileSync(new URL(`../src/${name}.mjs`, import.meta.url), 'utf8')+ assert.doesNotMatch(source, /from 'node:fs(\/promises)?'/u, name)+ }+ assert.doesNotMatch(readFileSync(new URL('../src/main.mjs', import.meta.url), 'utf8'), /import \{[^}]*\brm\b[^}]*\} from 'node:fs/u)+})++test('outside Electron the disk is plain fs', () => {+ assert.equal(disk, process.getBuiltinModule('node:fs'))+})