Skip to content

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

Merge dev into fix/679-office-preview-asar

AdamPlatin1235d8779d1f247
diff --cc app/electron-builder.yml
index 481f269e,dbfc8987..c0c6417d
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@@ -8,11 -8,22 +8,19 @@@ files
- package.json
- src/**
- assets/**
-# 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 payload Node cannot read office.js through the asar.
- - node_modules/ds-bot/office.js
- # 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).
++# the program itself is unpacked (#679). The Office payload's plain Node also reads the
++# LibreOffice Kit CLI and ds-bot's office.js from here, which it could not do through an archive.
+asar: false
+ # 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.
++# `runtime` script). build/ is not in `files`, so none of it lands in the app's own folder.
+ 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 --cc app/scripts/before-pack.mjs
index 05c6014f,bc11600d..7745435b
--- a/app/scripts/before-pack.mjs
+++ b/app/scripts/before-pack.mjs
@@@ -17,7 -20,28 +20,28 @@@ export function archProblem({ target, p
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
++ * The Office payload the package ships next to the app's folder 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])
diff --cc app/scripts/check-packed.mjs
index 34fc3f52,fdb971fc..92e35ee8
--- a/app/scripts/check-packed.mjs
+++ b/app/scripts/check-packed.mjs
@@@ -32,6 -30,26 +32,26 @@@ 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.
++// The Office payload sits next to the app's folder as extraResources, and the LibreOffice Kit CLI
++// is a plain file in that folder; 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'),
- join('app.asar.unpacked', 'node_modules', 'ds-bot', 'office.js'),
++ join('app', 'node_modules', '@deepseek-ai', 'libreoffice-kit', 'lib', 'cli.js'),
++ join('app', 'node_modules', 'ds-bot', 'office.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'))
mkdirSync(join(work, 'shell'))
diff --cc app/src/office-patch.mjs
index 00000000,149cb8cc..685b22de
mode 000000,100644..100644
--- a/app/src/office-patch.mjs
+++ b/app/src/office-patch.mjs
@@@ -1,0 -1,56 +1,57 @@@
+ // 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).
++// the seven Office skills — in build/runtime (development) or beside the app's folder (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')
+ // The skill plugin reads its SKILL.md files at boot: an incomplete payload must fall back
+ // to no overlay rather than stop the Host from starting.
+ if (!existsSync(join(source, 'runtime.json')) || !existsSync(node)
+ || !existsSync(join(runtimeDir, 'office-skills', 'office', 'SKILL.md'))) 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.
++// The payload's Node is a plain interpreter: it cannot read through an asar archive, so a CLI
++// inside one must come from the unpacked tree beside it. The app itself ships without an archive
++// (#679), where the path stays as it is.
+ 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 --cc app/test/before-pack.test.mjs
index d1a70e15,2095c13d..d9723748
--- a/app/test/before-pack.test.mjs
+++ b/app/test/before-pack.test.mjs
@@@ -31,3 -38,12 +38,12 @@@ test('a requested universal build stop
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', () => {
++test('the Office payload goes next to the app 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 --cc docs/plans/2026-10-27-office-documents.md
index 00000000,6da728c1..3dab8496
mode 000000,100644..100644
--- a/docs/plans/2026-10-27-office-documents.md
+++ b/docs/plans/2026-10-27-office-documents.md
@@@ -1,0 -1,60 +1,60 @@@
+ # Office 文档
+
+ - 日期:2026-10-27
+ - 相关:Issue #613;[桌面应用](2026-10-16-desktop-app.md)、[Bot 运行配置](2026-10-10-bot-runtime.md)
+
+ ## 为什么
+
+ Bot 要能直接处理 .docx/.pptx/.xlsx:打开看结构、检查包健康、定点改内容,用户不装任何东西。DSH 自带一套 Office 技能(python-docx 写文档、LibreOffice Kit 渲染/重算/PDF),缺的是「包级」的那把刀:稳定 id 的结构读取、关系和内容类型检查、跨 run 的定点编辑、修订接受/拒绝、页面对象的盒模型和拼图巡检。
+
+ ## 桌面应用打包了什么
+
+ 按 DSH Desktop 的做法,桌面应用随包带一份 payload(`npm run runtime` 从锁定清单下载、SHA-256 校验):
+
+ - CPython + 文档库(python-docx、python-pptx、openpyxl、lxml、Pillow、pandas 等)
+ - 独立的 Node
+ - LibreOffice Kit 的 CLI 和原生引擎
+ - DSH 的七个 Office 技能素材
+
+ 安装体积多约 245 MB(841 → 1086 MB),下载约 91 MB。无 payload 时 app 照常启动,只是技能缺席——同一份 `office.patch.yml` 在两个插件可用时才生成。
+
+ ## ds-bot 自己的命令行(`office.js`)
+
+ 打进 npm 包的单文件 CLI,依赖 Node 内建加打包进去的 XML 解析库,所有运行面通用(桌面应用、DSH Desktop、DSH Web)。退出码:0 成功、1 仍有 finding、2 用法或失败;`--json` 时输出 `{"ok":true,"data":…}` / `{"ok":false,"error":{…}}`(finding 在 `data.findings` 里,ok 仍为 true)。编辑默认另存(`-o`),`--in-place` 才原地写。
+
+ - `unpack`/`pack`:把包解成可读 XML(`pack` 还原排版空白并跑 `check --against`)
+ - `check [--against] [--fix]`:只查会让 Office 拒开或弹修复的问题——XML 良构、内容类型完整、内部关系可达、r:id 引用存在、pptx 形状/幻灯片 id、docx docPr/paraId、`xml:space`、批注 id 一致。`--against` 只看新引入的问题;`--fix` 修安全的几类
+ - `docx read [--changes]`:正文块按 `p1…`/`t1…` 编号,页眉页脚、脚注尾注、批注及其锚点;修订默认按接受显示,`--changes` 用 `{+插入 (作者)+}` 这类内联标记
+ - `docx fields`:简单/复杂域的指令与当前结果
+ - `docx edit --ops`:原子批量 ops——跨 run `replace`(保留起始 run 格式、不进删除文本、正则带 `$1`)、`set_cell`、`set_field`、`insert`、`delete`、`comment`、`accept_changes`/`reject_changes`
+ - `pptx inventory`:页面尺寸、主题字体、每页每个形状(id/名/类/占位符/英寸盒——含组的坐标变换和布局/母版占位符继承)/逐段文本与 run 字体字号/图片媒体
+ - `pptx layout [--autofit]`:文本框相交、跑出页面的 finding;`--autofit` 写 `a:normAutofit`;盒内溢出要渲染才能看到
+ - `pptx slides --order`:按现位置重排,重复位置=复制(slide+rels+备注页+图表+内嵌工作簿),略过的=删除,再跑 clean
+ - `pptx clean [--dry-run]`:不在 sldIdLst 的页、不可达部件、悬空关系/Override、无引用媒体(docx/xlsx 通用)
+ - `xlsx inventory` / `xlsx read --sheet [--range]`:工作表状态/维度/单元格与公式计数/合并/表/图、定义名、错误单元格与其公式、无缓存值提示;网格化读出缓存值、公式、ISO 日期
+ - `sheet`:渲染页拼成标页码的 contact sheet(纯 JS PNG 编解码)
+
+ ## 两个技能
+
+ 由 ds-bot 插件注册(provider `ds-bot-office`,仅在宿主挂了 `skills` 服务时生效——cordis 的子 fiber 让它在没技能服务的环境静默缺席,不挡插件启动):
+
+ - `office`(rank 550):沿用 DSH 的路由 skill 正文,加一条把「结构读取、包检查、定点编辑」指给 `office-tools` 的行,并写明目录里没有的技能在本环境不可用。rank 取 550 是因为同层低值优先——DSH 自带的 office 是 bundled rank 600,用户/项目技能 100–500 仍然压过我们。
+ - `office-tools`(rank 600):原创 SKILL.md——命令怎么选、Word/PowerPoint/Excel 各一条工作流、XML 只走 `unpack` + 真解析器 + `pack --against`、收尾标准、新 deck 的排版规则。加载时按环境追加 `{"officeTools":{"node","cli"}}`:node 依次取 `DS_BOT_OFFICE_NODE`(桌面应用 payload)、纯 Node 宿主的 `process.execPath`,否则要求 `load_workspace_dependencies` 的 node,再不行就说明命令不可用;cli 是 `ds-bot/office.js` 的绝对路径,在 asar 里映射到 `app.asar.unpacked`。
+
+ DSH 的六个格式/操作技能(office-docx/pptx/xlsx、office-render、office-recalculate、office-export-pdf)原样保留,只有小路由被替换。
+
+ ## 各运行面的运行时
+
-- 桌面应用:全部可用——payload 的 Python/Node/LibreOffice、DSH 的 Office 技能、`office.js` 全部命令(host 注入 `DS_BOT_OFFICE_NODE`,office.js 走 `app.asar.unpacked`)
++- 桌面应用:全部可用——payload 的 Python/Node/LibreOffice、DSH 的 Office 技能、`office.js` 全部命令(host 注入 `DS_BOT_OFFICE_NODE`;应用不打 asar,office.js 是普通文件,#679)
+ - DSH Desktop:DSH 自带的 Python 和渲染器照常,外加我们的 `office.js` 命令(纯 Node 宿主用宿主解释器;否则技能文本指示调 `load_workspace_dependencies` 取 node)
+ - DSH Web:只有 `office.js` 命令——没有随包的 Python(建新文件受限),没有渲染器(除非用户自己装 DSH 提供的 Office sidecar)
+
+ ## 不做的
+
+ - 不做模板/母题生成;排版规则写成技能文本
+ - 不做 XSD 校验——`check` 只覆盖「Office 拒开/弹修复」这一档
+ - `accept_changes`/`reject_changes` 不处理嵌套在字段指令里的修订,也不处理 `w:numberingChange` 的内容回滚(编号变更只去标记不还原编号)
+
+ ## 升 DSH 版本时
+
+ 换锁文件版本:从对应 DSH tag 取 `scripts/primary-runtime/lock.json` 覆盖 `app/scripts/primary-runtime.lock.json`,跑 `npm run runtime` 重建 payload,`npm run check-packed` 复验。同时对照新版 `assets/office/SKILL.md` 复核我们的 office 路由。