Skip to content

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

Document the Office documents feature

Fei241171abf036bc57
diff --git a/NOTICE b/NOTICE
index 6d7e95f1..fdfb8072 100644
--- a/NOTICE
+++ b/NOTICE
@@ -19,6 +19,10 @@ MIT License, Copyright (c) 2026 DeepSeek
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.
+ - ds-bot/src/office/skills/office/SKILL.md adapts the office routing skill
+ (assets/office/SKILL.md in @deepseek-ai/dsh-skill-office): the routing body
+ is kept, with one added row that routes package checks and in-place edits
+ to office-tools.
- 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
@@ -89,7 +93,9 @@ Apache License, Version 2.0, Copyright (c) Microsoft Corporation
No other third-party code is copied into this repository. At run time the
plugin uses the @deepseek-ai/* packages of the DeepSeek Harness install it
-runs in; they are not bundled. esbuild is a build tool only. The desktop app
+runs in; they are not bundled. The bundled ds-bot/office.js includes
+@xmldom/xmldom (https://github.com/xmldom/xmldom, MIT License, Copyright (c)
+jindw and contributors) from npm. esbuild is a build tool only. The desktop app
in app/ installs the pinned @deepseek-ai/* packages, Electron and pnpm from
npm; they keep their own licenses. The build of its window (app/ui) bundles,
from npm, React and React DOM (MIT, Copyright (c) Meta Platforms, Inc. and
diff --git a/README.md b/README.md
index 529864ba..68fac6e1 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,10 @@ In **Settings** → **Usage**, you can see token usage by time, by bot and by mo
![Usage page](docs/images/usage.png)
+### Office files
+
+Bots work with Office documents offline. They can create and edit .docx, .pptx and .xlsx, read a document's structure with stable ids, check a package for the defects Office would refuse, make targeted edits (comments, tracked changes, fields, table cells), reorder or duplicate slides, list workbook errors, render pages to images and review them on a contact sheet — nothing needs to be installed, the desktop app includes everything needed.
+
## Data
All data stays on your own computer, in `bot/` and `sessions/` in the DSH home folder (`~/.dsh` by default). Uninstalling the plugin does not delete this data.
diff --git a/README.zh.md b/README.zh.md
index b08c4074..943a4365 100644
--- a/README.zh.md
+++ b/README.zh.md
@@ -98,6 +98,10 @@ ds bot 拥有群聊功能。群聊是非常好的多 bot 协作方式,但它
![用量页](docs/images/usage.zh.png)
+### Office 文件
+
+Bot 可以离线处理 Office 文档:创建和编辑 .docx、.pptx、.xlsx;按稳定 id 读文档结构;检查会让 Office 拒开的包缺陷;定点编辑(批注、修订、域、表格单元格);幻灯片重排与复制;列出工作簿错误;渲染成图片并按拼图检查——不用安装任何东西,桌面应用已全部带上。
+
## 数据
所有数据都在你自己的电脑上,在 dsh 主目录(默认 `~/.dsh`)的 `bot/` 和 `sessions/` 里。卸载插件不会删除这些数据。
diff --git a/app/README.md b/app/README.md
index 1b5949f6..d993e084 100644
--- a/app/README.md
+++ b/app/README.md
@@ -12,6 +12,8 @@ npm start # starts the app
When GitHub downloads are slow, set `ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` before the Electron download. Unset `ELECTRON_RUN_AS_NODE` before `npm start` if your terminal has it (terminals inside some Electron-based editors do): with it, Electron runs as plain Node and the app does not start.
+`npm run runtime` downloads the Office payload (Python with the document libraries, a standalone Node, the Office skill assets) into `build/runtime`, so the unpackaged app mounts the Office skills the same way a package does. `beforePack` builds it again for the package; without it the app still runs, only without the Office skills.
+
npm installs `ds-bot` from `../ds-bot` as a copy of its package files (`install-links` in `.npmrc`), so the app runs the plugin of this checkout. Run `npm ci` again after you change `ds-bot` or merge a branch that changes it: while the version stays the same, `npm install` keeps the old copy. `overrides` in `package.json` pins the four peer dependencies of `ds-bot` to the DSH version: they are declared as `*`, and npm does not choose a pre-release to satisfy `*`.
| Variable | What it sets | Default |
diff --git a/docs/plans/2026-10-27-office-documents.md b/docs/plans/2026-10-27-office-documents.md
new file mode 100644
index 00000000..bf4a514a
--- /dev/null
+++ b/docs/plans/2026-10-27-office-documents.md
@@ -0,0 +1,59 @@
+# 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 内建,所有运行面通用(桌面应用、DSH Desktop、DSH Web)。退出码:0 成功、1 仍有 finding、2 用法或失败;`--json` 时输出 `{"ok":true,"data":…}` / `{"ok":false,"error":{…}}`。编辑默认另存(`-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 的 Node(host 注入 `DS_BOT_OFFICE_NODE`),office.js 走 `app.asar.unpacked`
+- DSH Desktop / Web 插件:宿主是纯 Node 时用宿主解释器;否则技能文本指示调 `load_workspace_dependencies` 取 payload node
+
+## 不做的
+
+- 不做模板/母题生成;排版规则写成技能文本
+- 不做 XSD 校验——`check` 只覆盖「Office 拒开/弹修复」这一档
+- docx 的复杂修订细节(字段内修订、编号变更等)按出现再补
+
+## 升 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 路由。
diff --git a/docs/plans/README.md b/docs/plans/README.md
index 283d53e4..3c2ca2fb 100644
--- a/docs/plans/README.md
+++ b/docs/plans/README.md
@@ -49,3 +49,4 @@
| [Bot 视图](2026-10-20-widget-views.md) | Bot 在回答里画视图:固定组件目录的 JSON 蓝图(含图表、输入和本地公式),目录外的放沙箱 html;提问卡回路的泛化 |
| [Side chat(侧边对话)](2026-10-21-btw.md) | 人顺带问一句:侧栏里的常驻对话,以与会话同构的请求回答、不执行工具、不打断、不进模型可见历史;可追问、可开多条;Bot 之间的 `ask_bot` 另行提案 |
| [消息布局和宽度](2026-10-22-message-layout.md) | 气泡 / 平铺两种布局;平铺时 Bot 的话带头像、名字、时间;气泡宽度和平铺正文宽度各用一个滑块,按正文列的百分比调 |
+| [Office 文档](2026-10-27-office-documents.md) | Bot 离线处理 .docx/.pptx/.xlsx:应用带的 payload、`office.js` 命令行、office 路由换成带 `office-tools` 的版本 |