Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Ship the desktop app as plain files so Office previews work

AdamPlatin123908a1b7ba4be
diff --git a/app/README.md b/app/README.md
index 40a6718f..61000e17 100644
--- a/app/README.md
+++ b/app/README.md
@@ -75,12 +75,12 @@ Never point `DS_BOT_HOME` at `~/.dsh` or at the data of an app that you use.
## Package
-[electron-builder](https://www.electron.build/) packages the app with the settings in `electron-builder.yml`. Build on the platform that you package for: the native modules (`node-pty`, `sharp`, `koffi`) are taken from `node_modules` as npm installed them, not rebuilt.
+[electron-builder](https://www.electron.build/) packages the app with the settings in `electron-builder.yml`. Build on the platform that you package for: the native modules (`node-pty`, `sharp`, `koffi`) are taken from `node_modules` as npm installed them, not rebuilt. The app stays plain files in `resources/app`, not an asar archive: packages start programs that they ship, such as pnpm and the LibreOffice engine of file previews, by paths next to their own files, and Electron cannot start a program from inside an archive (#679).
```sh
npm 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/DeepSeek-Bot-<version>-win-x64.exe (Windows), a .zip (macOS), an .AppImage and a .deb (Linux)
-npm run check-packed # starts the packaged app on throwaway folders with the mock model, chats once, closes it
+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
```
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 DeepSeek Bot to Applications. On first open, use System Settings → Privacy & Security → Open Anyway. Do not disable Gatekeeper.
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index ad185c2a..481f269e 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -8,11 +8,11 @@ files:
- package.json
- src/**
- assets/**
-# The Host runs pnpm as a separate Node process to install plugins, so it must be a plain file.
-asarUnpack:
- - node_modules/pnpm/**
- # Automatic unpacking misses versioned Linux libraries such as libvips-cpp.so.8.18.7.
- - node_modules/@img/sharp*/**
+# No asar archive: the app stays plain files. Packages start programs that they ship by paths
+# next to their own files: the Host runs pnpm to install plugins, and file previews run the
+# LibreOffice engine. Electron cannot start a program by a path inside an archive, even when
+# the program itself is unpacked (#679).
+asar: false
# node-pty, sharp and koffi ship prebuilt binaries for each platform. A rebuild would compile
# node-pty from source and needs a C++ toolchain.
npmRebuild: false
diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjs
index 328c5df3..34fc3f52 100644
--- a/app/scripts/check-packed.mjs
+++ b/app/scripts/check-packed.mjs
@@ -1,4 +1,5 @@
-// Check a packaged app: process an image with its sharp, then start it on throwaway folders with the ds-bot mock model, choose a model,
+// 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,
// 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.
@@ -11,6 +12,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 { crc32 } from 'node:zlib'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const [given, shotFile] = process.argv.slice(2)
@@ -66,12 +68,27 @@ function outsideCheckout(file) {
return join(copy, relative(appDir, file))
}
-function checkSharp(app) {
+// The packaged app as Electron loads it: from an asar archive when there is one.
+function appFolder(app) {
const resources = process.platform === 'darwin' ? resolve(app, '..', '..', 'Resources') : join(dirname(app), 'resources')
+ return [join(resources, 'app.asar'), join(resources, 'app')].find(existsSync) ?? join(resources, 'app')
+}
+
+// Use the shipped Electron and dependencies outside the checkout, just like the Host.
+function runInApp(app, what, script, timeout) {
+ const result = spawnSync(app, ['-e', script], {
+ cwd: work, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', NODE_PATH: '' },
+ encoding: 'utf8', timeout,
+ })
+ if (result.error || result.status !== 0) throw new Error(`packaged ${what} failed (exit ${String(result.status)}, signal ${String(result.signal)}): ${result.error?.message ?? ''}\n${result.stderr ?? ''}`)
+ console.log(result.stdout.trim())
+}
+
+function checkSharp(app) {
const script = `
const assert = require('node:assert/strict')
const { createRequire } = require('node:module')
- const appRequire = createRequire(${JSON.stringify(join(resources, 'app.asar', 'package.json'))})
+ const appRequire = createRequire(${JSON.stringify(join(appFolder(app), 'package.json'))})
const sharp = appRequire('sharp')
;(async () => {
const image = await sharp({ create: { width: 4, height: 4, channels: 3, background: '#ff0000' } }).png().toBuffer()
@@ -82,13 +99,82 @@ 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], {
- cwd: work, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', NODE_PATH: '' },
- encoding: 'utf8', timeout: 30_000,
+ runInApp(app, 'sharp', script, 30_000)
+}
+
+// A zip archive of stored (uncompressed) files.
+function zip(files) {
+ const records = []
+ const directory = []
+ let offset = 0
+ for (const [path, text] of Object.entries(files)) {
+ const name = Buffer.from(path)
+ const data = Buffer.from(text)
+ // The fields that the local header and the directory entry share: zip 2.0, stored, dated 1980-01-01.
+ const shared = Buffer.alloc(26)
+ shared.writeUInt16LE(20, 0)
+ shared.writeUInt16LE(0x21, 8)
+ shared.writeUInt32LE(crc32(data), 10)
+ shared.writeUInt32LE(data.length, 14)
+ shared.writeUInt32LE(data.length, 18)
+ shared.writeUInt16LE(name.length, 22)
+ const local = Buffer.alloc(4)
+ local.writeUInt32LE(0x04034b50)
+ const entry = Buffer.alloc(6)
+ entry.writeUInt32LE(0x02014b50)
+ entry.writeUInt16LE(20, 4)
+ const entryEnd = Buffer.alloc(14)
+ entryEnd.writeUInt32LE(offset, 10)
+ records.push(local, shared, name, data)
+ directory.push(entry, shared, entryEnd, name)
+ offset += local.length + shared.length + name.length + data.length
+ }
+ const listing = Buffer.concat(directory)
+ const end = Buffer.alloc(22)
+ end.writeUInt32LE(0x06054b50)
+ end.writeUInt16LE(Object.keys(files).length, 8)
+ end.writeUInt16LE(Object.keys(files).length, 10)
+ end.writeUInt32LE(listing.length, 12)
+ end.writeUInt32LE(offset, 16)
+ return Buffer.concat([...records, listing, end])
+}
+
+function wordDocument(text) {
+ return zip({
+ '[Content_Types].xml': '<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/></Types>',
+ '_rels/.rels': '<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>',
+ 'word/document.xml': `<?xml version="1.0" encoding="UTF-8"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>${text}</w:t></w:r></w:p></w:body></w:document>`,
})
- if (result.error || result.status !== 0) throw new Error(`packaged sharp failed (exit ${String(result.status)}, signal ${String(result.signal)}): ${result.error?.message ?? ''}\n${result.stderr ?? ''}`)
- console.log(result.stdout.trim())
+}
+
+// File previews convert Office files with this engine. It is a program of its own, which the
+// kit finds next to its own files, so it runs only when the app's packages are real files (#679).
+function checkOffice(app) {
+ const folder = join(work, 'office')
+ mkdirSync(folder)
+ const input = join(folder, 'check.docx')
+ const output = join(folder, 'check.pdf')
+ writeFileSync(input, wordDocument('packaged app check'))
+ const script = `
+ const assert = require('node:assert/strict')
+ const { readFileSync } = require('node:fs')
+ const { createRequire } = require('node:module')
+ const { pathToFileURL } = require('node:url')
+ const appRequire = createRequire(${JSON.stringify(join(appFolder(app), 'package.json'))})
+ ;(async () => {
+ const kit = await import(pathToFileURL(appRequire.resolve('@deepseek-ai/libreoffice-kit')).href)
+ const { backend } = await kit.discoverRuntime()
+ const converter = await kit.createConverter({ fontMetadataCacheDirectory: ${JSON.stringify(join(folder, 'fonts'))} })
+ try {
+ await converter.render({ inputPath: ${JSON.stringify(input)}, outputPath: ${JSON.stringify(output)} })
+ } finally {
+ await converter.dispose()
+ }
+ assert.equal(readFileSync(${JSON.stringify(output)}).subarray(0, 5).toString('latin1'), '%PDF-')
+ console.log('check-packed: Office conversion passed (' + backend + ' engine)')
+ })().catch(error => { console.error(error); process.exitCode = 1 })
+ `
+ runInApp(app, 'Office conversion', script, 180_000)
}
function startMock() {
@@ -293,6 +379,7 @@ const problems = []
try {
const packedApp = outsideCheckout(resolve(executable))
checkSharp(packedApp)
+ checkOffice(packedApp)
const modelUrl = await startMock()
const port = await freePort()
const mainPort = await freePort()
diff --git a/app/test/package.test.mjs b/app/test/package.test.mjs
index 57bba5a4..681b8125 100644
--- a/app/test/package.test.mjs
+++ b/app/test/package.test.mjs
@@ -1,8 +1,6 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'
-import { join, resolve } from 'node:path'
-import { FileMatcher } from 'app-builder-lib/out/fileMatcher.js'
import { parse } from 'yaml'
// npm installs the peers that the DSH packages ask for, but electron-builder packs only the
@@ -16,22 +14,12 @@ test('every package that the app runs on is a dependency, not only a peer', () =
assert.deepEqual(peerOnly, [], `add these to "dependencies" in app/package.json: ${peerOnly.join(' ')}`)
})
-test('sharp native modules and versioned libvips libraries are unpacked together', () => {
+// The LibreOffice kit finds its engine next to its own files and starts it. From an asar archive
+// that path lies inside the archive, which Electron cannot start a program from, and every file
+// preview fails (#679).
+test('the app is packed as plain files, not into an asar archive', () => {
const config = parse(readFileSync(new URL('../electron-builder.yml', import.meta.url), 'utf8'))
- const root = resolve('app-fixture')
- const filter = new FileMatcher(root, root, value => value, config.asarUnpack).createFilter()
- const stat = { isDirectory: () => false }
- for (const file of [
- '@img/sharp-linux-x64/lib/sharp-linux-x64-0.35.5.node',
- '@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.8.18.7',
- '@img/sharp-linux-arm64/lib/sharp-linux-arm64.node',
- '@img/sharp-libvips-linux-arm64/lib/libvips-cpp.so.8.18.7',
- '@img/sharp-libvips-linuxmusl-x64/lib/libvips-cpp.so.8.18.7',
- '@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.18.7.dylib',
- '@img/sharp-win32-x64/lib/libvips-42.dll',
- 'pnpm/bin/pnpm.cjs',
- ]) assert.equal(filter(join(root, 'node_modules', file), stat), true, file)
- assert.equal(filter(join(root, 'node_modules/yaml/dist/index.js'), stat), false)
+ assert.equal(config.asar, false)
})
// A release is tagged with the version of ds-bot, and the installed apps compare their own