Skip to content

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

Ship DSH's Office runtime in the desktop app

Fei2411e39bdf131d46
diff --git a/.gitignore b/.gitignore
index 30ee868f..4942f23f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,13 @@
node_modules/
*.tgz
# The desktop app's window build (npm run build in app/), its packages (npm run pack, npm run dist)
-# and the next version that checks its update (see app/README.md).
+# and the next version that checks its update (see app/README.md). The Office runtime payload
+# (npm run runtime in app/) is downloaded per machine.
/app/ui/dist/
/app/dist-pack/
/app/dist-next/
+/app/build/runtime/
+/app/build/runtime-cache/
# A DeepSeek Harness checkout for the tests and the test bench.
/deepseek-harness/
diff --git a/NOTICE b/NOTICE
index 9a3151c2..00515a79 100644
--- a/NOTICE
+++ b/NOTICE
@@ -16,7 +16,13 @@ MIT License, Copyright (c) 2026 DeepSeek
developer script for screenshots on Linux and is not in the npm package.
- app/src/host.mjs and app/src/profile.mjs follow
apps/desktop-host/src/index.ts: the profile boot and the ready, fatal and
- shutdown messages.
+ shutdown messages. app/src/office-patch.mjs follows
+ apps/desktop-host/src/office.ts: the workspace-dependencies and skill-office
+ plugin rows with the payload's Node and the unpacked LibreOffice Kit CLI.
+ - app/scripts/prepare-runtime.mjs and app/scripts/primary-runtime.lock.json are a
+ JavaScript port of scripts/primary-runtime/ (prepare.ts, prune-python-tests.ts
+ and lock.json): the pinned Python, Node and wheel downloads with checksum
+ verification, the wheel test pruning and the Office skill asset copy.
- app/src/host-process.mjs follows apps/desktop/src/host-process.ts: the
Host in Electron's Node mode and the shutdown escalation.
- app/src/main.mjs follows apps/desktop/src/main.ts for the Windows window
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index ad93bf1e..3b144b98 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -8,9 +8,18 @@ files:
- package.json
- src/**
- assets/**
-# The Host runs pnpm as a separate Node process to install plugins, so it must be a plain file.
+# The Host runs pnpm as a separate Node process to install plugins, and the Office payload's
+# plain Node runs the LibreOffice Kit CLI: both must be plain files outside the asar.
asarUnpack:
- node_modules/pnpm/**
+ - node_modules/@deepseek-ai/libreoffice-kit/**
+# The Office payload that scripts/prepare-runtime.mjs writes in beforePack (see package.json's
+# `runtime` script). build/ is not in `files`, so nothing of it lands inside the asar.
+extraResources:
+ - from: build/runtime/primary-runtime
+ to: primary-runtime
+ - from: build/runtime/office-skills
+ to: office-skills
# 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/package-lock.json b/app/package-lock.json
index 2cb00180..b271e6db 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -37,10 +37,13 @@
"@deepseek-ai/dsh-session-telemetry": "0.2.1-rc.2",
"@deepseek-ai/dsh-session-title-llm": "0.2.1-rc.2",
"@deepseek-ai/dsh-shell": "0.2.1-rc.2",
+ "@deepseek-ai/dsh-skill-office": "0.2.1-rc.2",
"@deepseek-ai/dsh-spill": "0.2.1-rc.2",
+ "@deepseek-ai/dsh-tool-workspace-dependencies": "0.2.1-rc.2",
"@deepseek-ai/dsh-util-time": "0.2.1-rc.2",
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-rc.2",
"@deepseek-ai/dsh-workflow": "0.2.1-rc.2",
+ "@deepseek-ai/libreoffice-kit": "0.1.5",
"ds-bot": "file:../ds-bot",
"electron-updater": "6.8.10",
"pnpm": "11.7.0",
@@ -50,10 +53,13 @@
"devDependencies": {
"electron": "44.7.0",
"electron-builder": "26.17.0",
+ "extract-zip": "2.0.1",
+ "papaparse": "5.5.3",
"react": "19.3.0",
"react-dom": "19.3.0",
"react-markdown": "10.1.0",
"remark-gfm": "4.0.1",
+ "tar": "7.5.22",
"vite": "8.3.4"
}
},
@@ -8600,6 +8606,17 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/yauzl": {
+ "version": "2.10.3",
+ "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz",
+ "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@ungap/structured-clone": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz",
@@ -9422,6 +9439,16 @@
"base64-js": "^1.1.2"
}
},
+ "node_modules/buffer-crc32": {
+ "version": "0.2.13",
+ "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
+ "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
@@ -10753,6 +10780,68 @@
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==",
"license": "MIT"
},
+ "node_modules/extract-zip": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz",
+ "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==",
+ "dev": true,
+ "license": "BSD-2-Clause",
+ "dependencies": {
+ "debug": "^4.1.1",
+ "get-stream": "^5.1.0",
+ "yauzl": "^2.10.0"
+ },
+ "bin": {
+ "extract-zip": "cli.js"
+ },
+ "engines": {
+ "node": ">= 10.17.0"
+ },
+ "optionalDependencies": {
+ "@types/yauzl": "^2.9.1"
+ }
+ },
+ "node_modules/extract-zip/node_modules/debug": {
+ "version": "4.4.3",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
+ "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "ms": "^2.1.3"
+ },
+ "engines": {
+ "node": ">=6.0"
+ },
+ "peerDependenciesMeta": {
+ "supports-color": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/extract-zip/node_modules/get-stream": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
+ "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "pump": "^3.0.0"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "node_modules/extract-zip/node_modules/ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -10781,6 +10870,16 @@
],
"license": "BSD-3-Clause"
},
+ "node_modules/fd-slicer": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
+ "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "pend": "~1.2.0"
+ }
+ },
"node_modules/fdir": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
@@ -13986,6 +14085,13 @@
"integrity": "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==",
"license": "MIT"
},
+ "node_modules/papaparse": {
+ "version": "5.5.3",
+ "resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.5.3.tgz",
+ "integrity": "sha512-5QvjGxYVjxO59MGU2lHVYpRWBBtKHnlIAcSe1uNFCkkptUh63NFRj0FJQm7nR67puEruUci/ZkjmEFrjCAyP4A==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/parse-entities": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-4.0.2.tgz",
@@ -14074,6 +14180,13 @@
"url": "https://github.com/sponsors/jet2jet"
}
},
+ "node_modules/pend": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
+ "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@@ -16075,6 +16188,17 @@
"node": ">=12"
}
},
+ "node_modules/yauzl": {
+ "version": "2.10.0",
+ "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
+ "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "buffer-crc32": "~0.2.3",
+ "fd-slicer": "~1.1.0"
+ }
+ },
"node_modules/yocto-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
diff --git a/app/package.json b/app/package.json
index f8fa480f..18a41af4 100644
--- a/app/package.json
+++ b/app/package.json
@@ -16,6 +16,7 @@
"pack": "electron-builder --dir --publish never",
"dist": "electron-builder --publish never",
"check-packed": "node scripts/check-packed.mjs",
+ "runtime": "node scripts/prepare-runtime.mjs",
"shot": "node scripts/shot.mjs",
"icon": "node scripts/icon.mjs",
"test": "node --test \"test/*.test.mjs\""
@@ -49,10 +50,13 @@
"@deepseek-ai/dsh-session-telemetry": "0.2.1-rc.2",
"@deepseek-ai/dsh-session-title-llm": "0.2.1-rc.2",
"@deepseek-ai/dsh-shell": "0.2.1-rc.2",
+ "@deepseek-ai/dsh-skill-office": "0.2.1-rc.2",
"@deepseek-ai/dsh-spill": "0.2.1-rc.2",
+ "@deepseek-ai/dsh-tool-workspace-dependencies": "0.2.1-rc.2",
"@deepseek-ai/dsh-util-time": "0.2.1-rc.2",
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-rc.2",
"@deepseek-ai/dsh-workflow": "0.2.1-rc.2",
+ "@deepseek-ai/libreoffice-kit": "0.1.5",
"ds-bot": "file:../ds-bot",
"electron-updater": "6.8.10",
"pnpm": "11.7.0",
@@ -62,10 +66,13 @@
"devDependencies": {
"electron": "44.7.0",
"electron-builder": "26.17.0",
+ "extract-zip": "2.0.1",
+ "papaparse": "5.5.3",
"react": "19.3.0",
"react-dom": "19.3.0",
"react-markdown": "10.1.0",
"remark-gfm": "4.0.1",
+ "tar": "7.5.22",
"vite": "8.3.4"
},
"overrides": {
diff --git a/app/scripts/before-pack.mjs b/app/scripts/before-pack.mjs
index 05c6014f..bc11600d 100644
--- a/app/scripts/before-pack.mjs
+++ b/app/scripts/before-pack.mjs
@@ -2,6 +2,9 @@
// (npmRebuild: false), so they fit only the architecture of the Node that ran npm. An app built for
// another architecture would carry them and not start, so such a build stops here.
import { Arch } from 'electron-builder'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { preparePrimaryRuntime, runtimeTarget } from './prepare-runtime.mjs'
const WHERE = {
darwin: { x64: 'on an Intel Mac, or under Rosetta with an x64 Node', arm64: 'on a Mac with Apple silicon' },
@@ -17,10 +20,32 @@ export function archProblem({ target, platform, host = process.arch, targets = [
return `This Node runs on ${host}, so npm installed ${host} native modules, and an ${target} app with them would not start. Install the dependencies and build ${where}.`
}
-export async function beforePack(context) {
+/**
+ * The Office payload the package ships next to the asar through extraResources; it must
+ * match the package's own platform and architecture, which the arch check guarantees.
+ * @param {*} context - electron-builder's beforePack context.
+ * @returns {{ target: string, output: string, cache: string, version: string }}
+ */
+export function officeRuntimeRequest(context) {
+ const target = runtimeTarget(context.electronPlatformName, Arch[context.arch])
+ if (target === undefined) throw new Error(`No Office runtime payload for ${context.electronPlatformName} ${Arch[context.arch]}.`)
+ // The context's packager is the PlatformPackager; the app directory lives on its Packager
+ // (.info), exposed directly as projectDir. For this one-package app they are the same.
+ const appDir = context.packager.appDir ?? context.packager.projectDir
+ return {
+ target,
+ output: join(appDir, 'build', 'runtime'),
+ cache: process.env.DS_BOT_RUNTIME_CACHE ?? join(appDir, 'build', 'runtime-cache'),
+ version: context.packager?.appInfo?.version
+ ?? JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version,
+ }
+}
+
+export async function beforePack(context, prepare = preparePrimaryRuntime) {
const targets = []
for (const archToNames of context.packager?.packagerOptions?.targets?.values() ?? [])
for (const arch of archToNames.keys()) targets.push(Arch[arch])
const problem = archProblem({ target: Arch[context.arch], platform: context.electronPlatformName, targets })
if (problem !== undefined) throw new Error(problem)
+ await prepare(officeRuntimeRequest(context))
}
diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjs
index 9e22f315..a58fa1ea 100644
--- a/app/scripts/check-packed.mjs
+++ b/app/scripts/check-packed.mjs
@@ -28,6 +28,25 @@ if (!existsSync(executable)) {
process.exit(2)
}
+// The Office payload sits next to the asar as extraResources, and the LibreOffice Kit CLI is a
+// plain file in the unpacked tree; without them the app's Office skills and tools cannot run.
+{
+ const resources = process.platform === 'darwin' ? join(dirname(executable), '..', 'Resources') : join(dirname(executable), 'resources')
+ const windows = process.platform === 'win32'
+ 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'),
+ ]
+ const missing = required.filter((entry) => !existsSync(join(resources, entry)))
+ if (missing.length > 0) {
+ console.error(`check-packed: FAILED: missing from ${resources}:\n ${missing.join('\n ')}`)
+ process.exit(1)
+ }
+}
+
const work = realpathSync.native(mkdtempSync(join(realpathSync.native(tmpdir()), 'ds-bot-packed-')))
mkdirSync(join(work, 'home'))
const children = []
diff --git a/app/scripts/prepare-runtime.mjs b/app/scripts/prepare-runtime.mjs
new file mode 100644
index 00000000..c36412eb
--- /dev/null
+++ b/app/scripts/prepare-runtime.mjs
@@ -0,0 +1,288 @@
+// Prepare the app's Office payload: a pinned, relocatable CPython with the document
+// libraries, a standalone Node for the LibreOffice Kit CLI, and the Office skill
+// assets, all downloaded against the lock in primary-runtime.lock.json without
+// installing into the build host. electron-builder's beforePack calls it for the
+// platform being packed; `npm run runtime` builds the same tree for development.
+// Follows DeepSeek Harness scripts/primary-runtime/prepare.ts and
+// prune-python-tests.ts (MIT); see NOTICE. Unlike DSH's, this payload ships no pnpm.
+import { execFileSync } from 'node:child_process'
+import { createHash, randomUUID } from 'node:crypto'
+import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs'
+import { cp } from 'node:fs/promises'
+import { tmpdir } from 'node:os'
+import { dirname, join, resolve } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { parseArgs } from 'node:util'
+import { copyPrimaryRuntime, parsePrimaryRuntime, workspaceDependencyPaths } from '@deepseek-ai/dsh-tool-workspace-dependencies'
+import extractZip from 'extract-zip'
+import Papa from 'papaparse'
+import { x as extractTar } from 'tar'
+
+const lock = JSON.parse(readFileSync(new URL('./primary-runtime.lock.json', import.meta.url), 'utf8'))
+
+// The targets the lock pins, named by the platform and architecture electron-builder packs for.
+const RUNTIME_TARGET = {
+ win32: { x64: 'win-x64' },
+ darwin: { x64: 'mac-x64', arm64: 'mac-arm64' },
+ linux: { x64: 'linux-x64', arm64: 'linux-arm64' },
+}
+
+/**
+ * The lock's target for a platform and architecture, or undefined when the lock pins none.
+ * @param {string} platform - process.platform of the payload's system.
+ * @param {string} arch - process.arch of the payload's system.
+ * @returns {keyof typeof lock.targets | undefined}
+ */
+export function runtimeTarget(platform, arch) {
+ return RUNTIME_TARGET[platform]?.[arch]
+}
+
+/**
+ * Download or reuse an archive only when its bytes match the release lock.
+ * @param {string} url - Locked archive URL.
+ * @param {string} sha256 - Expected hexadecimal sha256 digest.
+ * @param {string} cache - Download cache directory.
+ * @returns {Promise<string>} verified local archive path
+ */
+async function downloadPrimaryRuntimeAsset(url, sha256, cache) {
+ mkdirSync(cache, { recursive: true })
+ const destination = join(cache, sha256)
+ let bytes
+ let cached = true
+ try { bytes = readFileSync(destination) } catch (error) {
+ if (error.code !== 'ENOENT') throw error
+ cached = false
+ const timeout = Number(process.env.DS_BOT_RUNTIME_DOWNLOAD_TIMEOUT_MS ?? '300000')
+ if (!Number.isSafeInteger(timeout) || timeout < 1 || timeout > 2_147_483_647) throw new Error('DS_BOT_RUNTIME_DOWNLOAD_TIMEOUT_MS must be an integer from 1 to 2147483647')
+ const response = await fetch(url, { signal: AbortSignal.timeout(timeout) })
+ if (!response.ok) throw new Error(`primary runtime download: ${String(response.status)} ${url}`)
+ bytes = Buffer.from(await response.arrayBuffer())
+ }
+ if (createHash('sha256').update(bytes).digest('hex') !== sha256) {
+ rmSync(destination, { force: true })
+ throw new Error(`primary runtime download: checksum mismatch for ${url}`)
+ }
+ if (cached) return destination
+ const temporary = join(cache, `.${randomUUID()}`)
+ try {
+ writeFileSync(temporary, bytes)
+ renameSync(temporary, destination)
+ } finally {
+ rmSync(temporary, { force: true })
+ }
+ return destination
+}
+
+/**
+ * Prepare the locked standalone Node for the target.
+ * @param {keyof typeof lock.targets} target - Target interpreter platform.
+ * @param {string} destination - Directory receiving bin/node and LICENSE.
+ * @param {string} cache - Verified archive cache.
+ */
+async function downloadNodeRuntime(target, destination, cache) {
+ const artifact = lock.targets[target]
+ const filename = `node-v${lock.nodeVersion}-${artifact.nodeArchive}`
+ const archive = await downloadPrimaryRuntimeAsset(`https://nodejs.org/dist/v${lock.nodeVersion}/${filename}`, artifact.nodeSha256, cache)
+ const staging = mkdtempSync(join(tmpdir(), 'ds-bot-node-'))
+ try {
+ if (target === 'win-x64') await extractZip(archive, { dir: staging })
+ else await extractTar({ file: archive, cwd: staging })
+ const source = join(staging, filename.replace(/\.(?:zip|tar\.gz)$/u, ''))
+ mkdirSync(join(destination, 'bin'), { recursive: true })
+ cpSync(join(source, ...(target === 'win-x64' ? ['node.exe'] : ['bin', 'node'])),
+ join(destination, 'bin', target === 'win-x64' ? 'node.exe' : 'node'))
+ cpSync(join(source, 'LICENSE'), join(destination, 'LICENSE'))
+ } finally {
+ rmSync(staging, { recursive: true, force: true })
+ }
+}
+
+async function pythonArchive(target, cache) {
+ const artifact = lock.targets[target]
+ const filename = `cpython-${lock.pythonVersion}+${lock.pythonRelease}-${artifact.pythonTarget}-install_only_stripped.tar.gz`
+ return downloadPrimaryRuntimeAsset(`https://github.com/astral-sh/python-build-standalone/releases/download/${lock.pythonRelease}/${encodeURIComponent(filename)}`, artifact.pythonSha256, cache)
+}
+
+/**
+ * Identify the inputs that assemble one target's payload, excluding unrelated target locks.
+ * @param {keyof typeof lock.targets} target - Runtime target whose archives are installed.
+ * @returns {string} sha256 payload identity for installation reuse
+ */
+function primaryRuntimePayloadDigest(target) {
+ const { pythonVersion, pythonRelease, nodeVersion, wheels, pythonPackages } = lock
+ return createHash('sha256').update(JSON.stringify({
+ format: 7, target, pythonVersion, pythonRelease, nodeVersion,
+ artifact: lock.targets[target], wheels, pythonPackages,
+ })).digest('hex')
+}
+
+/**
+ * The runtime.json written into a target's payload.
+ * @param {keyof typeof lock.targets} target - Runtime target the manifest describes.
+ * @param {string} version - The app's version, recorded in the legacy desktopVersion field.
+ * @returns {object} validated manifest
+ */
+export function primaryRuntimeManifest(target, version) {
+ return {
+ desktopVersion: version,
+ platform: target === 'win-x64' ? 'win32' : target.startsWith('linux-') ? 'linux' : 'darwin',
+ arch: target.endsWith('-arm64') ? 'arm64' : 'x64',
+ payloadDigest: primaryRuntimePayloadDigest(target),
+ python: lock.pythonVersion,
+ node: lock.nodeVersion,
+ pythonPackages: lock.pythonPackages,
+ }
+}
+
+/**
+ * Whether an output directory already holds a complete payload for the manifest.
+ * @param {string} output - Directory receiving primary-runtime/.
+ * @param {object} manifest - The manifest the payload must match.
+ * @returns {boolean}
+ */
+export function runtimeReusable(output, manifest) {
+ const root = join(output, 'primary-runtime')
+ let existing
+ try { existing = parsePrimaryRuntime(JSON.parse(readFileSync(join(root, 'runtime.json'), 'utf8'))) } catch { return false }
+ if (existing.payloadDigest !== manifest.payloadDigest) return false
+ const entries = workspaceDependencyPaths(root, manifest)
+ return [entries.python, entries.node].every(path => existsSync(path)) && existsSync(entries.pythonPackages)
+}
+
+/**
+ * Unpack a locked library wheel, retaining auxiliary scripts in its distribution data directory.
+ * @param {string} archive - Hash-verified wheel archive.
+ * @param {string} destination - Absolute site-packages directory.
+ */
+async function unpackPrimaryRuntimeWheel(archive, destination) {
+ await extractZip(archive, {
+ dir: destination,
+ onEntry: (entry) => {
+ const [directory, scheme] = entry.fileName.split('/')
+ if (directory?.endsWith('.data') && scheme !== '' && scheme !== 'scripts') {
+ throw new Error(`primary runtime: wheel requires unsupported installation paths: ${entry.fileName}`)
+ }
+ },
+ })
+}
+
+function removeTestDirectories(root, directory) {
+ const removed = []
+ for (const entry of readdirSync(join(root, directory), { withFileTypes: true })) {
+ if (!entry.isDirectory()) continue
+ const path = `${directory}/${entry.name}`
+ if (entry.name === 'tests') {
+ rmSync(join(root, path), { recursive: true })
+ removed.push(path)
+ } else {
+ removed.push(...removeTestDirectories(root, path))
+ }
+ }
+ return removed
+}
+
+/**
+ * Prune NumPy/pandas tests and their RECORD rows, preserving testing helpers and native extensions.
+ * @param {string} sitePackages - Staged site-packages directory containing the locked wheels.
+ * @throws If a locked distribution's RECORD is missing or malformed.
+ */
+export function prunePrimaryRuntimePythonTests(sitePackages) {
+ for (const name of ['numpy', 'pandas']) {
+ const record = join(sitePackages, `${name}-${lock.pythonPackages[name]}.dist-info`, 'RECORD')
+ const { data, errors } = Papa.parse(readFileSync(record, 'utf8'), { delimiter: ',', skipEmptyLines: true })
+ if (errors.length > 0 || data.length === 0
+ || !data.every((row) => row.length === 3 && Boolean(row[0]))) {
+ throw new Error(`primary runtime: invalid wheel RECORD: ${record}`)
+ }
+ const removed = removeTestDirectories(sitePackages, name)
+ if (removed.length === 0) continue
+ const retained = data.filter(([path]) => !removed.some(directory => path.startsWith(`${directory}/`)))
+ writeFileSync(record, `${Papa.unparse(retained, { newline: '\n' })}\n`)
+ }
+}
+
+/**
+ * Copy the skill package's complete asset tree to ordinary filesystem resources.
+ * @param {string} source - The package's assets directory.
+ * @param {string} destination - External Office skill resource directory.
+ */
+async function prepareOfficeSkillAssets(source, destination) {
+ rmSync(destination, { recursive: true, force: true })
+ await cp(source, destination, { recursive: true, dereference: true })
+}
+
+/**
+ * Materialize locked interpreters, libraries and Office resources without executing target code.
+ * @param {{ target: keyof typeof lock.targets, output: string, cache: string, version: string, skillSource?: string }} options
+ * target: payload platform. output: directory receiving primary-runtime/ and office-skills/.
+ * cache: sha256-addressed archive cache. version: the app's version for the manifest.
+ */
+export async function preparePrimaryRuntime(options) {
+ const { target } = options
+ const artifact = lock.targets[target]
+ if (artifact === undefined) throw new Error(`primary runtime: unknown target ${String(target)}`)
+ const paths = { runtime: resolve(options.output), downloads: resolve(options.cache) }
+ const manifest = primaryRuntimeManifest(target, options.version)
+ mkdirSync(paths.runtime, { recursive: true })
+ mkdirSync(paths.downloads, { recursive: true })
+ if (runtimeReusable(paths.runtime, manifest)) {
+ console.log(`primary-runtime: payload in ${paths.runtime} is current (digest ${manifest.payloadDigest.slice(0, 12)}…)`)
+ } else {
+ const staging = mkdtempSync(join(tmpdir(), 'ds-bot-primary-'))
+ try {
+ const output = join(staging, 'payload')
+ const dependencies = join(output, 'dependencies')
+ mkdirSync(dependencies, { recursive: true })
+ const node = join(dependencies, 'node')
+ await downloadNodeRuntime(target, node, paths.downloads)
+ mkdirSync(join(node, 'node_modules'))
+ writeFileSync(join(node, 'node_modules', 'README.txt'), 'Reserved for bundled Node packages.\n')
+ await extractTar({ file: await pythonArchive(target, paths.downloads), cwd: dependencies })
+ const entries = workspaceDependencyPaths(output, manifest)
+ for (const wheel of [...artifact.wheels, ...lock.wheels]) {
+ await unpackPrimaryRuntimeWheel(await downloadPrimaryRuntimeAsset(wheel.url, wheel.sha256, paths.downloads), entries.pythonPackages)
+ }
+ prunePrimaryRuntimePythonTests(entries.pythonPackages)
+ writeFileSync(join(output, 'runtime.json'), `${JSON.stringify(manifest, undefined, 2)}\n`)
+ const destination = join(paths.runtime, 'primary-runtime')
+ rmSync(destination, { recursive: true, force: true })
+ await copyPrimaryRuntime(output, destination, manifest)
+ } finally {
+ rmSync(staging, { recursive: true, force: true })
+ }
+ }
+ const assets = options.skillSource ?? join(dirname(fileURLToPath(import.meta.resolve('@deepseek-ai/dsh-skill-office/package.json'))), 'assets')
+ await prepareOfficeSkillAssets(assets, join(paths.runtime, 'office-skills'))
+}
+
+/**
+ * Run the freshly prepared payload's interpreter and libraries; skipped when the
+ * target is not the build host's own platform and architecture.
+ * @param {string} root - Final payload directory.
+ */
+function smokePrimaryRuntime(root) {
+ const manifest = parsePrimaryRuntime(JSON.parse(readFileSync(join(root, 'runtime.json'), 'utf8')))
+ if (manifest.platform !== process.platform || manifest.arch !== process.arch) return
+ const entries = workspaceDependencyPaths(root, manifest)
+ execFileSync(entries.python, ['-I', '-B', '-c', 'import docx, pptx, openpyxl, pandas, lxml, PIL'], { stdio: 'inherit', timeout: 120_000 })
+ execFileSync(entries.node, ['--version'], { stdio: 'inherit', timeout: 30_000 })
+}
+
+if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ const { values } = parseArgs({ options: {
+ target: { type: 'string' }, output: { type: 'string' }, cache: { type: 'string' },
+ } })
+ const here = dirname(fileURLToPath(import.meta.url))
+ const target = values.target ?? runtimeTarget(process.platform, process.arch)
+ if (target === undefined || !Object.hasOwn(lock.targets, target)) {
+ throw new Error(`Usage: node scripts/prepare-runtime.mjs [--target <${Object.keys(lock.targets).join('|')}>] [--output <directory>] [--cache <directory>]`)
+ }
+ const output = resolve(values.output ?? join(here, '..', 'build', 'runtime'))
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
+ await preparePrimaryRuntime({
+ target, output,
+ cache: values.cache ?? process.env.DS_BOT_RUNTIME_CACHE ?? join(here, '..', 'build', 'runtime-cache'),
+ version,
+ })
+ smokePrimaryRuntime(join(output, 'primary-runtime'))
+}
diff --git a/app/scripts/primary-runtime.lock.json b/app/scripts/primary-runtime.lock.json
new file mode 100644
index 00000000..f5b0ada4
--- /dev/null
+++ b/app/scripts/primary-runtime.lock.json
@@ -0,0 +1,180 @@
+{
+ "nodeVersion": "24.21.0",
+ "pythonVersion": "3.12.14",
+ "pythonRelease": "20260901",
+ "targets": {
+ "win-x64": {
+ "nodeArchive": "win-x64.zip",
+ "nodeSha256": "158f7685b44de51f6c0df1d153526cbcd3e1bc739a8dfc607721cef75de9e541",
+ "pythonTarget": "x86_64-pc-windows-msvc",
+ "pythonSha256": "7c45c9622400d578709a9b2cddbe8124cc21d382409d9f13406d706d28e31b14",
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/2d/57/8aeaf160312f7f489dea47ab61e430b5cb051f59a98ae68b7133ce8fa06a/numpy-2.3.5-cp312-cp312-win_amd64.whl",
+ "sha256": "86945f2ee6d10cdfd67bcb4069c1662dd711f7e2a4343db5cecec06b87cf31aa"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/75/08/67cc404b3a966b6df27b38370ddd96b3b023030b572283d035181854aac5/pandas-3.0.1-cp312-cp312-win_amd64.whl",
+ "sha256": "536232a5fe26dd989bd633e7a0c450705fdc86a207fec7254a55e9a22950fe43"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/45/89/da2f7971a317f83d807fdd4065c0af40208e59e692cc43d315a71a0e96d1/pillow-12.3.0-cp312-cp312-win_amd64.whl",
+ "sha256": "a2b55dd6b2a4c4b7d87ffa56bdb33fdc5fdb9a462173861a7bc097f17d91cb09"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/3a/5b/6ed903e4e6278a020c8a6f0dbbe78030d041840a6b4a64ea441a1e414077/lxml-6.1.3-cp312-cp312-win_amd64.whl",
+ "sha256": "3e9a00d1c2c30936f7add097c41afc5da6556c580909104aafd382cac92a855c"
+ }
+ ]
+ },
+ "mac-arm64": {
+ "nodeArchive": "darwin-arm64.tar.gz",
+ "nodeSha256": "bed7eea5325e1108f32ce5228ddd6a5f0f08a499ee42aa7442aea583702f6057",
+ "pythonTarget": "aarch64-apple-darwin",
+ "pythonSha256": "81a359f1cfadd4da11766534c5913791cea55f26e1bb902cacd2a531bb1e4b2b",
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/c5/65/df0db6c097892c9380851ab9e44b52d4f7ba576b833996e0080181c0c439/numpy-2.3.5-cp312-cp312-macosx_11_0_arm64.whl",
+ "sha256": "ee3888d9ff7c14604052b2ca5535a30216aa0a58e948cdd3eeb8d3415f638769"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/7c/f1/e2567ffc8951ab371db2e40b2fe068e36b81d8cf3260f06ae508700e5504/pandas-3.0.1-cp312-cp312-macosx_11_0_arm64.whl",
+ "sha256": "0ab749dfba921edf641d4036c4c21c0b3ea70fea478165cb98a998fb2a261955"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/d8/66/9a386a92561f402389a4fc70c18838bf6d35eb5eb5c6850b4b2dc64f5048/pillow-12.3.0-cp312-cp312-macosx_11_0_arm64.whl",
+ "sha256": "ffd0c5368496f41b0944be820fcb7a838aa6e623d250b01acf2643939c3f99d7"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/dd/1f/a180b57d9eeabaab77f9d5aa30356898ea749c4795596a8f66d1eb6bef2e/lxml-6.1.3-cp312-cp312-macosx_10_13_universal2.whl",
+ "sha256": "0c0710ac085a157b593c38fbcacd950f15c4afa8e2057527185875ab302752bc"
+ }
+ ]
+ },
+ "mac-x64": {
+ "nodeArchive": "darwin-x64.tar.gz",
+ "nodeSha256": "1462cb3b3046b815cf8ea436d3da450ec1a9f11dac7e5a46b0ada5305d7e8097",
+ "pythonTarget": "x86_64-apple-darwin",
+ "pythonSha256": "65b195c9cedc1fef6767f044f9822069adbd1bd9204d424ece4628776fdc04bb",
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/44/37/e669fe6cbb2b96c62f6bbedc6a81c0f3b7362f6a59230b23caa673a85721/numpy-2.3.5-cp312-cp312-macosx_10_13_x86_64.whl",
+ "sha256": "74ae7b798248fe62021dbf3c914245ad45d1a6b0cb4a29ecb4b31d0bfbc4cc3e"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/37/51/b467209c08dae2c624873d7491ea47d2b47336e5403309d433ea79c38571/pandas-3.0.1-cp312-cp312-macosx_10_13_x86_64.whl",
+ "sha256": "476f84f8c20c9f5bc47252b66b4bb25e1a9fc2fa98cead96744d8116cb85771d"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/37/bf/fb3ebff8ddcb76aac5a01389251bbbb9519922a9b520d8247c1ca864a25d/pillow-12.3.0-cp312-cp312-macosx_10_13_x86_64.whl",
+ "sha256": "ba09209fbe443b4acccebe845d8a138b89a8f4fbaeedd44953490b5315d5e965"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/a8/25/070c92013a1c029a602b03560d68772313d918268667fa993da7961759c9/lxml-6.1.3-cp312-cp312-macosx_10_13_x86_64.whl",
+ "sha256": "623c8799c17128753c65699f1c3aa32402657393a9ad6db09ed8b98ddf76611d"
+ }
+ ]
+ },
+ "linux-x64": {
+ "nodeArchive": "linux-x64.tar.gz",
+ "nodeSha256": "6e1db87ef58b8819e5d5402eff1536491b18edd8eb7bee5ef7897876e88dc5ff",
+ "pythonTarget": "x86_64-unknown-linux-gnu",
+ "pythonSha256": "72748da13197c1fb161e3afeef20a6a385ff24f2165e6e2758e47008e7faba4c",
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/b6/23/2a1b231b8ff672b4c450dac27164a8b2ca7d9b7144f9c02d2396518352eb/numpy-2.3.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
+ "sha256": "0d8163f43acde9a73c2a33605353a4f1bc4798745a8b1d73183b28e5b435ae28"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/3d/fe/89d77e424365280b79d99b3e1e7d606f5165af2f2ecfaf0c6d24c799d607/pandas-3.0.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl",
+ "sha256": "532527a701281b9dd371e2f582ed9094f4c12dd9ffb82c0c54ee28d8ac9520c4"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/84/21/a35af28dcc61f37ed850a2d64c65c701321dfbf25085e469d5559360cbbf/pillow-12.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
+ "sha256": "78cb2c6865a35ab8ff8b75fd122f6033b92a62c82801110e48ddd6c936a45d91"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/db/36/aa413bc214dc4f785ad2b2ddd8cc99aae7062d49ab155e91e6011af00daf/lxml-6.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
+ "sha256": "379f8a75cf6eb7eef0af074b55f49ab73b868388a98de14646abcdfa4564bb11"
+ }
+ ]
+ },
+ "linux-arm64": {
+ "nodeArchive": "linux-arm64.tar.gz",
+ "nodeSha256": "724282c3b43aec998aa9527380465b45d229e021b58035f5f4f63095eabfe5d5",
+ "pythonTarget": "aarch64-unknown-linux-gnu",
+ "pythonSha256": "577b4bec0793ad1ff0cbff9adbd0df078eddde38a4c41bf5d83ad381a85ee39d",
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/74/78/fcd41e5a0ce4f3f7b003da85825acddae6d7ecb60cf25194741b036ca7d6/numpy-2.3.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl",
+ "sha256": "8b973c57ff8e184109db042c842423ff4f60446239bd585a5131cc47f06f789d"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/d7/39/327802e0b6d693182403c144edacbc27eb82907b57062f23ef5a4c4a5ea7/pandas-3.0.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl",
+ "sha256": "b8e36891080b87823aff3640c78649b91b8ff6eea3c0d70aeabd72ea43ab069b"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/25/27/ac8f99618ffd3dde21db0f4d4b1d2ab00c0880595bfd17df103f7f39fd0c/pillow-12.3.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl",
+ "sha256": "d9c7f76c0673154f044e9d78c8655fb4213f6ca31a836df48b40fe5d187717b9"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/1e/1c/722e88883173097a1a375153e3c2447eba3060d0231522cf6596e99f4195/lxml-6.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl",
+ "sha256": "f683dc6300317700025e41d89a43e0276692ded16113a3c43eab704d605c58e5"
+ }
+ ]
+ }
+ },
+ "wheels": [
+ {
+ "url": "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
+ "sha256": "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl",
+ "sha256": "4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl",
+ "sha256": "1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/d0/00/1e03a4989fa5795da308cd774f05b704ace555a70f9bf9d3be057b680bcf/python_docx-1.2.0-py3-none-any.whl",
+ "sha256": "3fd478f3250fbbbfd3b94fe1e985955737c145627498896a8a6bf81f4baf66c7"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/d9/4f/00be2196329ebbff56ce564aa94efb0fbc828d00de250b1980de1a34ab49/python_pptx-1.0.2-py3-none-any.whl",
+ "sha256": "160838e0b8565a8b1f67947675886e9fea18aa5e795db7ae531606d68e785cba"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl",
+ "sha256": "5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/3a/0c/3662f4a66880196a590b202f0db82d919dd2f89e99a27fadef91c4a33d41/xlsxwriter-3.2.9-py3-none-any.whl",
+ "sha256": "9a5db42bc5dff014806c58a20b9eae7322a134abb6fce3c92c181bfb275ec5b3"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl",
+ "sha256": "481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"
+ },
+ {
+ "url": "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl",
+ "sha256": "7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa"
+ }
+ ],
+ "pythonPackages": {
+ "numpy": "2.3.5",
+ "pandas": "3.0.1",
+ "python-dateutil": "2.9.0.post0",
+ "six": "1.17.0",
+ "tzdata": "2025.2",
+ "python-docx": "1.2.0",
+ "python-pptx": "1.0.2",
+ "openpyxl": "3.1.5",
+ "Pillow": "12.3.0",
+ "lxml": "6.1.3",
+ "XlsxWriter": "3.2.9",
+ "typing_extensions": "4.16.0",
+ "et_xmlfile": "2.0.0"
+ }
+}
diff --git a/app/src/host.mjs b/app/src/host.mjs
index d8608060..6b641f94 100644
--- a/app/src/host.mjs
+++ b/app/src/host.mjs
@@ -7,6 +7,7 @@ import { inspect } from 'node:util'
import { loadLayeredEnv, reportSkippedBundles } from '@deepseek-ai/dsh-app-boot'
import { runProfile } from '@deepseek-ai/dsh/profile-boot'
import { CHECK_PROFILE, INSTALL_ANCHOR, loadAppProfile, loadCheckProfile, PROFILE } from './profile.mjs'
+import { reconcileOfficeRuntime } from './office-patch.mjs'
import { reconcileSearchSelector } from './search-patch.mjs'
import { unreadableSessions } from './session-check.mjs'
@@ -22,11 +23,16 @@ async function main() {
const check = process.env.DS_BOT_CHECK || undefined
const profile = check === undefined ? loadAppProfile() : loadCheckProfile()
reportSkippedBundles('dsh', profile)
+ // The Office payload is the app's own, for the team profile; the first-run check reads
+ // chats without it.
+ const office = check === undefined ? reconcileOfficeRuntime(profile) : { patchFiles: [] }
+ // ds-bot reads the payload's Node for the Office commands it runs itself.
+ if (office.node !== undefined) process.env.DS_BOT_OFFICE_NODE = office.node
const application = runProfile({
environment: loadLayeredEnv('dsh'),
profile: check === undefined ? PROFILE : CHECK_PROFILE,
resolvedProfile: { profile, installAnchor: INSTALL_ANCHOR },
- patchFiles: check === undefined ? reconcileSearchSelector(profile) : [],
+ patchFiles: check === undefined ? [...reconcileSearchSelector(profile), ...office.patchFiles] : [],
args: ['--no-open', '--port', process.env.DS_BOT_PORT || '0'],
...(pnpm === undefined ? {} : {
packageManager: { command: process.execPath, args: ['--expose-internals', pnpm], env: { ELECTRON_RUN_AS_NODE: '1' } },
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 4b7a6088..c968e3b6 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -132,7 +132,7 @@ async function start() {
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(), ...(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: app.isPackaged ? process.resourcesPath : join(here, '..', 'build', 'runtime'), ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },
pnpm,
onFailure: fail,
})
diff --git a/app/src/office-patch.mjs b/app/src/office-patch.mjs
new file mode 100644
index 00000000..da443d39
--- /dev/null
+++ b/app/src/office-patch.mjs
@@ -0,0 +1,53 @@
+// Reconcile #613: the app carries DSH's Office runtime — the workspace-dependencies tool and
+// the seven Office skills — in build/runtime (development) or beside the asar (packaged).
+// DSH's own profile does not mount them, so when the payload is complete the Host adds them
+// through a `--patch` overlay it writes into its own data area next to the profiles
+// (`<DSH_HOME>/profiles/office.patch.yml`), which DSH reads only through `patchFiles`.
+// Follows DeepSeek Harness apps/desktop-host/src/office.ts (MIT); see NOTICE.
+import { existsSync, rmSync, writeFileSync } from 'node:fs'
+import { dirname, join, sep } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { stringify } from 'yaml'
+
+export const OFFICE_PATCH_NAME = 'office.patch.yml'
+
+/**
+ * The payload's runtime directory and standalone Node, when the runtime is complete.
+ * @param {string} runtimeDir - The directory holding primary-runtime/ and office-skills/.
+ * @returns {{ source: string, node: string } | undefined}
+ */
+export function officeRuntime(runtimeDir) {
+ const source = join(runtimeDir, 'primary-runtime')
+ const node = join(source, 'dependencies', 'node', 'bin', process.platform === 'win32' ? 'node.exe' : 'node')
+ if (!existsSync(join(source, 'runtime.json')) || !existsSync(node)) return undefined
+ return { source, node }
+}
+
+// The payload's Node is a plain interpreter: it cannot read through the asar archive, so the
+// CLI must come from the unpacked tree electron-builder writes beside it.
+export function officeCli(manifest = fileURLToPath(import.meta.resolve('@deepseek-ai/libreoffice-kit/package.json'))) {
+ return join(dirname(manifest).replace(`${sep}app.asar${sep}`, `${sep}app.asar.unpacked${sep}`), 'lib', 'cli.js')
+}
+
+/**
+ * Write the Office overlay next to the profiles and report it for `patchFiles`; without a
+ * complete payload, drop a stale one from an earlier launch.
+ * @param {import('@deepseek-ai/dsh-app-boot').Profile} profile
+ * @param {string} [runtimeDir] - The directory holding primary-runtime/ and office-skills/;
+ * the packaged app's resources, or build/runtime in development.
+ * @returns {{ patchFiles: string[], node?: string }} the `patchFiles` addition for this
+ * launch and the payload's Node, which the Host exports for the plugin's own use
+ */
+export function reconcileOfficeRuntime(profile, runtimeDir = process.env.DS_BOT_RUNTIME_DIR) {
+ const file = join(dirname(profile.dir), OFFICE_PATCH_NAME)
+ const runtime = runtimeDir === undefined ? undefined : officeRuntime(runtimeDir)
+ if (runtime === undefined) {
+ rmSync(file, { force: true })
+ return { patchFiles: [] }
+ }
+ writeFileSync(file, stringify([{ insert: [
+ { id: 'workspace-dependencies', name: '@deepseek-ai/dsh-tool-workspace-dependencies', config: { source: runtime.source } },
+ { id: 'skill-office', name: '@deepseek-ai/dsh-skill-office', config: { assetRoot: join(runtimeDir, 'office-skills'), node: runtime.node, cli: officeCli() } },
+ ] }]), 'utf8')
+ return { patchFiles: [file], node: runtime.node }
+}
diff --git a/app/test/before-pack.test.mjs b/app/test/before-pack.test.mjs
index d1a70e15..2095c13d 100644
--- a/app/test/before-pack.test.mjs
+++ b/app/test/before-pack.test.mjs
@@ -1,13 +1,20 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
import { test } from 'node:test'
import { Arch } from 'electron-builder'
-import { archProblem, beforePack } from '../scripts/before-pack.mjs'
+import { archProblem, beforePack, officeRuntimeRequest } from '../scripts/before-pack.mjs'
+import { runtimeTarget } from '../scripts/prepare-runtime.mjs'
test('a build for the architecture of this Node goes on', async () => {
assert.equal(archProblem({ target: 'arm64', platform: 'darwin', host: 'arm64' }), undefined)
assert.equal(archProblem({ target: 'x64', platform: 'win32', host: 'x64' }), undefined)
- await beforePack({ arch: Arch[process.arch], electronPlatformName: process.platform })
+ const asked = []
+ const packager = { projectDir: 'app-dir', appInfo: { version: '0.0.0' } }
+ await beforePack({ arch: Arch[process.arch], electronPlatformName: process.platform, packager }, async (request) => { asked.push(request) })
+ assert.equal(asked.length, 1)
+ assert.equal(asked[0].target, runtimeTarget(process.platform, process.arch))
+ assert.equal(asked[0].output, join('app-dir', 'build', 'runtime'))
})
test('a build for another architecture stops and says where to build it', async () => {
@@ -31,3 +38,12 @@ test('a requested universal build stops before packing either architecture', asy
test('electron-builder runs the check before it packs', () => {
assert.match(readFileSync(new URL('../electron-builder.yml', import.meta.url), 'utf8'), /^beforePack: \.\/scripts\/before-pack\.mjs$/m)
})
+
+test('the Office payload goes next to the asar for a platform the lock pins', () => {
+ const request = officeRuntimeRequest({ arch: Arch.x64, electronPlatformName: 'win32', packager: { projectDir: 'app-dir', appInfo: { version: '9.9.9' } } })
+ assert.equal(request.target, 'win-x64')
+ assert.equal(request.version, '9.9.9')
+ assert.equal(request.output, join('app-dir', 'build', 'runtime'))
+ assert.throws(() => officeRuntimeRequest({ arch: Arch.arm64, electronPlatformName: 'win32', packager: { projectDir: 'app-dir' } }), /No Office runtime payload for win32 arm64/)
+ assert.match(readFileSync(new URL('../electron-builder.yml', import.meta.url), 'utf8'), /from: build\/runtime\/primary-runtime\r?\n\s+to: primary-runtime/u)
+})
diff --git a/app/test/office-patch.test.mjs b/app/test/office-patch.test.mjs
new file mode 100644
index 00000000..1afc4f11
--- /dev/null
+++ b/app/test/office-patch.test.mjs
@@ -0,0 +1,95 @@
+import assert from 'node:assert/strict'
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { dirname, join } from 'node:path'
+import { after, before, describe, test } from 'node:test'
+import { parse } from 'yaml'
+import { OFFICE_PATCH_NAME, officeCli, officeRuntime, reconcileOfficeRuntime } from '../src/office-patch.mjs'
+
+let home
+let runtimeDir
+// A stand-in payload: the manifest and the standalone Node are what the Host checks.
+function makePayload() {
+ const source = join(runtimeDir, 'primary-runtime')
+ const node = join(source, 'dependencies', 'node', 'bin', process.platform === 'win32' ? 'node.exe' : 'node')
+ mkdirSync(dirname(node), { recursive: true })
+ writeFileSync(node, '')
+ writeFileSync(join(source, 'runtime.json'), '{}')
+}
+// A stand-in profile under a throwaway DSH_HOME.
+function profile() {
+ const dir = join(home, 'profiles', 'ds-bot')
+ mkdirSync(dir, { recursive: true })
+ return { name: 'ds-bot', dir, patchPath: join(dir, 'cordis.patch.yml'), skippedBundles: [], layers: [], patches: [] }
+}
+
+before(() => {
+ home = mkdtempSync(join(tmpdir(), 'ds-bot-office-patch-'))
+ runtimeDir = join(home, 'runtime')
+})
+after(() => { rmSync(home, { recursive: true, force: true }) })
+
+describe('officeRuntime', () => {
+ test('sees a complete payload and nothing else', () => {
+ assert.equal(officeRuntime(runtimeDir), undefined)
+ makePayload()
+ const runtime = officeRuntime(runtimeDir)
+ assert.equal(runtime.source, join(runtimeDir, 'primary-runtime'))
+ assert.ok(existsSync(runtime.node))
+ rmSync(join(runtime.source, 'runtime.json'))
+ assert.equal(officeRuntime(runtimeDir), undefined)
+ })
+})
+
+describe('officeCli', () => {
+ test('runs the CLI from the unpacked tree, not through the asar', () => {
+ const packed = join('program', 'resources', 'app.asar', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'package.json')
+ assert.equal(officeCli(packed), join('program', 'resources', 'app.asar.unpacked', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'lib', 'cli.js'))
+ })
+
+ test('leaves an unpacked checkout alone', () => {
+ const unpacked = join('checkout', 'app', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'package.json')
+ assert.equal(officeCli(unpacked), join('checkout', 'app', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'lib', 'cli.js'))
+ })
+})
+
+describe('reconcileOfficeRuntime', () => {
+ test('inserts the workspace tool and the Office skills against the payload', () => {
+ makePayload()
+ const { patchFiles, node } = reconcileOfficeRuntime(profile(), runtimeDir)
+ assert.equal(node, join(runtimeDir, 'primary-runtime', 'dependencies', 'node', 'bin', process.platform === 'win32' ? 'node.exe' : 'node'))
+ assert.deepEqual(patchFiles, [join(home, 'profiles', OFFICE_PATCH_NAME)])
+ const [row] = parse(readFileSync(patchFiles[0], 'utf8'))
+ assert.equal(row.insert.length, 2)
+ const [tool, skills] = row.insert
+ assert.equal(tool.id, 'workspace-dependencies')
+ assert.equal(tool.name, '@deepseek-ai/dsh-tool-workspace-dependencies')
+ assert.equal(tool.config.source, join(runtimeDir, 'primary-runtime'))
+ assert.equal(skills.id, 'skill-office')
+ assert.equal(skills.name, '@deepseek-ai/dsh-skill-office')
+ assert.equal(skills.config.assetRoot, join(runtimeDir, 'office-skills'))
+ assert.equal(skills.config.node, node)
+ assert.ok(skills.config.cli.endsWith(join('libreoffice-kit', 'lib', 'cli.js')))
+ })
+
+ test('writes no overlay and drops a stale one when the payload is gone', () => {
+ makePayload()
+ const p = profile()
+ const [file] = reconcileOfficeRuntime(p, runtimeDir).patchFiles
+ assert.ok(existsSync(file))
+ rmSync(join(runtimeDir, 'primary-runtime', 'runtime.json'))
+ assert.deepEqual(reconcileOfficeRuntime(p, runtimeDir), { patchFiles: [] })
+ assert.equal(existsSync(file), false)
+ })
+
+ test('writes no overlay without a runtime directory', () => {
+ assert.deepEqual(reconcileOfficeRuntime(profile(), undefined), { patchFiles: [] })
+ })
+})
+
+// The first-run check reads chats without the team or the Office payload: the Host asks for
+// the overlay only for the main profile.
+test('the check profile boots without the Office overlay', () => {
+ const source = readFileSync(new URL('../src/host.mjs', import.meta.url), 'utf8')
+ assert.match(source, /check === undefined \? reconcileOfficeRuntime\(profile\) : \{ patchFiles: \[\] \}/u)
+})
diff --git a/app/test/prepare-runtime.test.mjs b/app/test/prepare-runtime.test.mjs
new file mode 100644
index 00000000..5596c457
--- /dev/null
+++ b/app/test/prepare-runtime.test.mjs
@@ -0,0 +1,70 @@
+import assert from 'node:assert/strict'
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { dirname, join } from 'node:path'
+import { after, before, describe, test } from 'node:test'
+import { parsePrimaryRuntime, workspaceDependencyPaths } from '@deepseek-ai/dsh-tool-workspace-dependencies'
+import { primaryRuntimeManifest, runtimeReusable, runtimeTarget } from '../scripts/prepare-runtime.mjs'
+
+describe('runtimeTarget', () => {
+ test('maps the platforms electron-builder packs for to the lock\'s targets', () => {
+ assert.equal(runtimeTarget('win32', 'x64'), 'win-x64')
+ assert.equal(runtimeTarget('darwin', 'x64'), 'mac-x64')
+ assert.equal(runtimeTarget('darwin', 'arm64'), 'mac-arm64')
+ assert.equal(runtimeTarget('linux', 'x64'), 'linux-x64')
+ assert.equal(runtimeTarget('linux', 'arm64'), 'linux-arm64')
+ assert.equal(runtimeTarget('win32', 'arm64'), undefined)
+ assert.equal(runtimeTarget('freebsd', 'x64'), undefined)
+ })
+})
+
+describe('primaryRuntimeManifest', () => {
+ test('carries the platform, both interpreters and the locked wheels, but no pnpm', () => {
+ const manifest = primaryRuntimeManifest('win-x64', '0.2.2')
+ assert.equal(manifest.platform, 'win32')
+ assert.equal(manifest.arch, 'x64')
+ assert.equal(manifest.desktopVersion, '0.2.2')
+ assert.match(manifest.payloadDigest, /^[a-f0-9]{64}$/u)
+ assert.match(manifest.node, /^\d+\.\d+\.\d+$/u)
+ assert.equal('pnpm' in manifest, false)
+ assert.match(manifest.python, /^\d+\.\d+\.\d+$/u)
+ assert.equal(manifest.pythonPackages['python-docx'], '1.2.0')
+ // The tool validates the manifest the same way it reads one from a prepared payload.
+ assert.deepEqual(parsePrimaryRuntime(manifest).payloadDigest, manifest.payloadDigest)
+ })
+
+ test('maps mac and linux targets to the manifest platform names', () => {
+ assert.deepEqual([primaryRuntimeManifest('mac-arm64', '1').platform, primaryRuntimeManifest('mac-arm64', '1').arch], ['darwin', 'arm64'])
+ assert.deepEqual([primaryRuntimeManifest('linux-x64', '1').platform, primaryRuntimeManifest('linux-x64', '1').arch], ['linux', 'x64'])
+ })
+
+ test('changes the digest with the target', () => {
+ assert.notEqual(primaryRuntimeManifest('mac-x64', '1').payloadDigest, primaryRuntimeManifest('mac-arm64', '1').payloadDigest)
+ })
+})
+
+describe('runtimeReusable', () => {
+ const target = runtimeTarget(process.platform, process.arch)
+ const manifest = primaryRuntimeManifest(target ?? 'win-x64', '1.0.0')
+ let output
+ let root
+ before(() => {
+ output = mkdtempSync(join(tmpdir(), 'ds-bot-runtime-'))
+ root = join(output, 'primary-runtime')
+ })
+ after(() => { rmSync(output, { recursive: true, force: true }) })
+
+ test('is false without a payload, true with a complete one, false on a digest change', () => {
+ assert.equal(runtimeReusable(output, manifest), false)
+ const entries = workspaceDependencyPaths(root, manifest)
+ for (const path of [entries.python, entries.node]) {
+ mkdirSync(dirname(path), { recursive: true })
+ writeFileSync(path, '')
+ }
+ mkdirSync(entries.pythonPackages, { recursive: true })
+ writeFileSync(join(root, 'runtime.json'), JSON.stringify(manifest))
+ assert.equal(runtimeReusable(output, manifest), true)
+ writeFileSync(join(root, 'runtime.json'), JSON.stringify({ ...manifest, payloadDigest: '0'.repeat(64) }))
+ assert.equal(runtimeReusable(output, manifest), false)
+ })
+})