dsh-document-view 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,12 @@
4
4
 
5
5
  | 项目 | 值 | 依据 |
6
6
  | --- | --- | --- |
7
- | 运行中的 DSH | `0.2.2-rc.3` | 安装包 `app.asar` 内 `@deepseek-ai/dsh-desktop` 与 `@deepseek-ai/dsh-desktop-runtime` 的 `package.json` |
8
- | 官方最新 release | `dsh-v0.2.2-rc.3` | [deepseek-ai/DeepSeek-Harness releases](https://github.com/deepseek-ai/DeepSeek-Harness/releases/tag/dsh-v0.2.2-rc.3) |
9
- | 插件版本 | `1.1.0` | `package.json` |
7
+ | 运行中的 DSH | `0.2.2-rc.5` | `dsh -V` 与本机安装包 |
8
+ | 插件版本 | `1.1.1` | `package.json` |
10
9
  | Node.js | >= 20(仅构建时) | `engines.node` |
10
+ | 宿主要求 | `>=0.2.2-rc.3` | `dsh.engines.dsh` |
11
11
 
12
- 本插件就是在上述版本上开发并实际运行的,因此**与当前最新官方版本兼容**。DSH 内置插件清单里 `ui-sidebar-right`、`ui-sidebar-documentpreview`、`office-kit`、`ui-conversation` 等条目均存在,与本插件依赖的宿主能力一致。
12
+ 本插件就是在上述版本上开发并实际运行的,因此**与当前安装版本兼容**。DSH 内置插件清单里 `ui-sidebar-right`、`ui-sidebar-documentpreview`、`office-kit`、`ui-conversation` 等条目均存在,与本插件依赖的宿主能力一致。HTML 预览依赖宿主 `iframe[data-html-preview]` 标记(当前版本存在);布局通过地址后缀与 DOM 双重判定,任一命中即生效。批注依赖宿主 PDF 预览的文字层(`data-pdf-page` / `data-pdf-text` / `data-document-zoom-surface`),文字层缺失时批注静默不生效,阅读与布局不受影响。
13
13
 
14
14
  > 无法承诺「未来所有 DSH 版本都兼容」——插件依赖宿主内部 DOM 与 slot 名称,这些不属于公开稳定 API。下面说明失效时的行为与复核方法。
15
15
 
@@ -21,11 +21,14 @@
21
21
  - `conversation.session.header.actions`
22
22
  - `sidebar.right.tab.document.actions`
23
23
  - `sidebarRight` — `mounted`(`getSnapshot` / `subscribe`)、`openTabs`(`getSnapshot` / `subscribe`)、`isExpanded()`、`active()`
24
+ - `sessions`(提交批注时按需读取,不参与激活检查)— `list.getSnapshot().byId`、`scope(sessionId).get('conversation').send(text)`
24
25
 
25
26
  **DOM 钩子(稳定 data 属性,非构建哈希类名)**
26
27
 
27
28
  `data-rightbar-col`、`data-sidebar-right-panel`、`data-sidebar-right-session`、`data-sidebar-right-mode`、`data-sidebar-collapsed`、`data-textpreview-tool`、`data-excel-preview`、`data-slot="conversation.session.header.actions"`、`.fortune-zoom-container`
28
29
 
30
+ 批注额外依赖 PDF 预览层:`data-pdf-preview`、`data-pdf-page`、`data-pdf-text`、`data-document-zoom-surface`,以及 pdf.js 的文字层(`.textLayer`)。
31
+
29
32
  ## 失效时不会拖垮页面(v1.1.0 起)
30
33
 
31
34
  两道保护,都是「 fail closed 」——宿主结构变了就安静停用,而不是抛错:
@@ -35,9 +38,13 @@
35
38
 
36
39
  因此升级 DSH 后最坏的结果是「插件暂时不生效」,而不是「DSH 起不来」。
37
40
 
38
- ## 为什么不设 `engines.dsh`
41
+ ## 宿主要求怎么声明
42
+
43
+ 写在 `package.json` 的 `dsh.engines.dsh`,当前为 `>=0.2.2-rc.3`。
39
44
 
40
- `engines.dsh` 写错或过窄会在安装阶段直接拒绝插件,且第三方无法自行判断该填哪个范围。兼容性改为写在本文件、README 与 `meta.description` 里,由用户和维护者判断。
45
+ - 采用**下界**而非 `^` 或精确值:本插件的失效方式是「自动停用 + 页面照常可用」,不会拖垮宿主,所以新版本 DSH 不该被这个字段挡住。
46
+ - 这条声明的作用是:低于验证基线时由宿主直接拒绝安装并提示 `incompatible-version`,而不是装上去才发现不生效。
47
+ - 插件市场据此显示「符合宿主要求」,不再显示「未声明宿主要求」。
41
48
 
42
49
  ## 升级复核清单
43
50
 
@@ -48,9 +55,11 @@ DSH 发布新版本后,维护者按以下步骤复核(可提 PR):
48
55
  3. 拖动分隔线,确认比例变化且刷新后保持;`←` / `→` / `Home` / 双击复位逐一验证。
49
56
  4. 打开设置,验证自动进入、三种布局预设、自动更新 / 暂停。
50
57
  5. 缩窄窗口,验证「文档 / 对话」切换、未发送输入保留、焦点不丢失。
51
- 6. 退出 / 停用插件,确认宿主原生布局完全恢复、无残留样式与属性。
52
- 7. 检查浏览器 Console 是否出现 `[dsh-document-view] client host contract changed` 警告——出现即表示宿主契约已变,需对照上表适配选择器。
53
- 8. 更新本文件与 `locale/*.json` 的验证版本,发新版。
58
+ 6. 在 Word 或 PDF 里选中文字,验证浮条出现「删除线 / 批注」,保存后页面出现标记,缩放后标记仍贴合原文。
59
+ 7. 打开「批注 N」面板,验证定位、编辑、删除与「提交给 AI」;提交后右侧会话收到结构化清单,批注变为已提交。
60
+ 8. 退出 / 停用插件,确认宿主原生布局完全恢复、无残留样式与属性。
61
+ 9. 检查浏览器 Console 是否出现 `[dsh-document-view] client host contract changed` 警告——出现即表示宿主契约已变,需对照上表适配选择器。
62
+ 10. 更新本文件与 `locale/*.json` 的验证版本,发新版。
54
63
 
55
64
  ## 密钥与个人信息核查
56
65
 
package/docs/DETAIL.md CHANGED
@@ -1 +1 @@
1
- ![Document view: document in the center, conversation on the right, with a resizable divider](preview.svg)
1
+ ![Document view: the document in the center with annotation marks (amber highlight, numbered badge), the conversation on the right](screenshots/preview.png)
package/docs/DETAIL.zh.md CHANGED
@@ -1 +1 @@
1
- ![文档视图:中间是文档,右侧是对话,中间分隔线可拖动调整宽度](preview.svg)
1
+ ![文档视图:文档在中间并带批注标记(黄底虚线 + 编号),右侧保留当前会话](screenshots/preview.png)
@@ -107,19 +107,23 @@ npm publish --access public
107
107
 
108
108
  ## 提升曝光的可做事项
109
109
 
110
- - [ ] 仓库 **About** 写一句清晰描述 + 填 Homepage + 加 `dsh-plugin`、`deepseek-harness`、`dsh` 等 topic
111
- - [ ] README 首屏放一张能一眼看懂的界面图(本仓库已放)
112
- - [ ] 每次发版写清 Release notes,并打 `vN` tag
113
- - [ ] 中英文 README 都齐全
110
+ - [x] 仓库 **About** 写一句清晰描述 + 填 Homepage + 加 `dsh-plugin`、`deepseek-harness`、`dsh` 等 topic
111
+ - [x] README 首屏放一张能一眼看懂的界面图(三张脱敏示意图)
112
+ - [x] 每次发版写清 Release notes,并打 `vN` tag
113
+ - [x] 中英文 README 都齐全(价值前置、徽章、目录、30 秒安装、Star 引导)
114
+ - [x] `CONTRIBUTING.md` + Bug / Feature 两个 Issue 模板,降低参与门槛
115
+ - [x] 已发布到 npm(`dsh-document-view@1.1.1`),解锁一键安装
114
116
  - [ ] 在 DSH 社区 / 讨论区发一篇使用场景介绍(**对外发布前需你确认**)
115
117
  - [ ] 回复 Issue、按反馈迭代,保持仓库活跃
116
118
 
117
- ## 需要你确认后我才能代做的动作
119
+ ## 已完成的对外动作(2026-11-15 / 11-16)
118
120
 
119
- 以下都是**对外部服务的写操作**,本指南只准备材料、不擅自执行:
121
+ 以下为仓库维护者已执行、可在仓库页面核对的动作;本指南只记录,不再重复执行:
120
122
 
121
- 1. 给 GitHub 仓库加 `dsh-plugin` topic
122
- 2. `npm publish`(需要你的 npm 账号登录)
123
- 3. Fork 目录仓库并创建 catalog PR
124
- 4. 修改仓库 About 描述
125
- 5. 在社区发帖宣传
123
+ 1. GitHub topics 已加(含 `dsh-plugin`)
124
+ 2. `npm publish` 已发布 1.1.1,改用 trusted publishing(Actions OIDC,无需令牌)
125
+ 3. 1024 Store / awesome 目录 catalog PR #942 已合并;dsh-market 数据源 PR 已提交待审
126
+ 4. 仓库 About 描述与 Homepage 已填(2026-11-16 按推广口径优化)
127
+ 5. Discussions #1 介绍帖已发布(Show and tell)
128
+
129
+ > 社区推广帖、外部 IM / 邮件等**对外发送**动作仍需用户明确确认,本仓库文档不代为执行。
Binary file
Binary file
Binary file
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Document view",
4
- "description": "Adds a split document view to DeepSeek Harness: the opened document stays in the center while the current conversation remains visible on the right, so you can read a file and ask the AI about it on the same screen. Open a file from the right sidebar, then enable 'Document view' in the conversation header actions or the file tab actions. The arrow next to the toggle opens settings: 'Auto-enter on document view' (off by default, triggered only by your own file clicks), three layout presets (Document-first / Balanced / Chat-first), and an Auto update / Paused control that reuses the host's native file watcher. Drag the divider to resize; Left/Right arrows nudge, Home or double-click resets the ratio. In a narrow window, switch between Document and Chat with unsent input preserved. The toggle and ratio are saved per session. This is a layout-only plugin: it makes no network requests, reads or writes no files, ships no credentials, and stores only the toggle and ratios in localStorage under dsh.document-view.v1. Editing, saving and preview continue to use DSH's native document and Office viewers. Disabling the plugin restores the default layout. Verified on DSH Desktop 0.2.2-rc.3; because it relies on the host's DOM structure and slot names, a future DSH upgrade may change them — in that case the plugin disables itself safely so the page keeps working.",
4
+ "description": "Adds a split document view to DeepSeek Harness: the opened document stays in the center while the current conversation remains visible on the right, so you can read a file and ask the AI about it on the same screen. Open a file from the right sidebar, then enable 'Document view' in the conversation header actions or the file tab actions. The arrow next to the toggle opens settings: 'Auto-enter on document view' (off by default, triggered only by your own file clicks), three layout presets (Document-first / Balanced / Chat-first), and an Auto update / Paused control that reuses the host's native file watcher. Drag the divider to resize; Left/Right arrows nudge, Home or double-click resets the ratio. In a narrow window, switch between Document and Chat with unsent input preserved. The toggle and ratio are saved per session. Select text in Word / PDF / PowerPoint to add a strikethrough or a comment; the review panel lists marks by page, supports jump / edit / delete, and sends the whole review to the AI as one structured message. After the agent edits the file, the text that changed is highlighted in green (a deleted passage gets a green caret), so you can see exactly what moved. Annotations are stored per file path under dsh.document-view.annotations.v2/ with one key per mark, so multiple windows do not overwrite each other. The plugin makes no network requests, reads or writes no original files, ships no credentials, and leaves editing, saving and preview to DSH's native document and Office viewers. Disabling the plugin restores the default layout. Verified on DSH Desktop 0.2.2-rc.3; because it relies on the host's DOM structure and slot names, a future DSH upgrade may change them — in that case the plugin disables itself safely so the page keeps working.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "文档视图",
4
- "description": "为 DeepSeek Harness 增加分栏文档视图:打开的文档居中显示,当前会话保留在右侧,可以边看文档边让 AI 对照回答,不用再来回切换。在右侧栏打开文件后,从会话头部操作区或文件标签操作区开启「文档视图」。开关旁的箭头打开设置:可启用「查看文档时自动进入」(默认关闭,仅响应你主动点击文件)、选择文档优先 / 均衡 / 对话优先三种布局预设,以及沿用宿主原生文件监听的「自动更新 / 已暂停」。拖动分隔线调整宽度,左右方向键微调、Home 或双击复位;窄窗口下可在「文档 / 对话」间切换且保留未发送的输入。开关与比例按会话保存。本插件只调整布局:不发任何网络请求、不读写文件、不含任何凭据,仅在 localStorage 的 dsh.document-view.v1 中保存开关与比例;编辑、保存与预览继续沿用 DSH 原生文档 / Office 查看器。停用插件即恢复默认布局。已在 DSH Desktop 0.2.2-rc.3 上验证;因依赖宿主 DOM 结构与 slot 名称,DSH 升级后这些内部结构若变化,插件会安全自动停用、页面照常可用,届时按仓库 docs/COMPATIBILITY.md 的升级复核清单重验。",
4
+ "description": "为 DeepSeek Harness 增加分栏文档视图:打开的文档居中显示,当前会话保留在右侧,可以边看文档边让 AI 对照回答,不用再来回切换。在右侧栏打开文件后,从会话头部操作区或文件标签操作区开启「文档视图」。开关旁的箭头打开设置:可启用「查看文档时自动进入」(默认关闭,仅响应你主动点击文件)、选择文档优先 / 均衡 / 对话优先三种布局预设,以及沿用宿主原生文件监听的「自动更新 / 已暂停」。拖动分隔线调整宽度,左右方向键微调、Home 或双击复位;窄窗口下可在「文档 / 对话」间切换且保留未发送的输入。开关与比例按会话保存。文档里选中文字可加「删除线」或「批注意见」,汇总面板支持定位、编辑、删除,并一键整理成结构化清单交给右侧 AI;提交后 AI 按条改原文件,被改动的文字会标绿(整段删除处为绿色竖线),一眼看到改了哪里。批注按文件路径保存在 localStorage 的 dsh.document-view.annotations.v2/ 下,每条一个键,多窗口互不覆盖。本插件只调整布局与批注:不发任何网络请求、不读写原文件、不含任何凭据;编辑、保存与预览继续沿用 DSH 原生文档 / Office 查看器。停用插件即恢复默认布局。已在 DSH Desktop 0.2.2-rc.3 上验证;因依赖宿主 DOM 结构与 slot 名称,DSH 升级后这些内部结构若变化,插件会安全自动停用、页面照常可用,届时按仓库 docs/COMPATIBILITY.md 的升级复核清单重验。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-document-view",
3
- "version": "1.1.1",
4
- "description": "Split document view for DeepSeek Harness: read a document in the center while the conversation stays on the right.",
3
+ "version": "1.2.1",
4
+ "description": "Split document view for DeepSeek Harness: read a document in the center while the conversation stays on the right, mark up the page, and hand the review to the AI.",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {
@@ -18,7 +18,7 @@
18
18
  "client.js",
19
19
  "cordis.patch.yml",
20
20
  "README.md",
21
- "README.en.md",
21
+ "README.zh.md",
22
22
  "LICENSE",
23
23
  "SECURITY.md",
24
24
  "CHANGELOG.md",
@@ -60,6 +60,9 @@
60
60
  },
61
61
  "client": {
62
62
  "platform": "web"
63
+ },
64
+ "engines": {
65
+ "dsh": ">=0.2.2-rc.3"
63
66
  }
64
67
  }
65
68
  }
package/scripts/build.mjs CHANGED
@@ -8,6 +8,7 @@ const name = 'dsh-document-view';
8
8
 
9
9
  const strip = p => readFileSync(root + p, 'utf8').replace(/^export /gm, '');
10
10
  const model = strip('src/model.mjs');
11
+ const annotations = strip('src/annotations.mjs');
11
12
  const browser = strip('src/collaboration.mjs');
12
13
 
13
14
  const client = `// Independent document collaboration client; no UI patch bundle included.
@@ -15,6 +16,7 @@ window.__ModuleLoader__.load({
15
16
  id: '${name}',
16
17
  factory: (require) => {
17
18
  ${model}
19
+ ${annotations}
18
20
  ${browser}
19
21
  // Fail-safe activation: a future DSH release may change the module
20
22
  // loader or host contract. Never let an unexpected error inside this
@@ -1,8 +1,10 @@
1
1
  // Lightweight release verification: model unit checks + artifact integrity.
2
2
  // Run: node scripts/verify.mjs
3
3
  import { readFileSync } from 'node:fs';
4
+ import { execFileSync } from 'node:child_process';
4
5
  import { fileURLToPath } from 'node:url';
5
6
  import { CollaborationState, solveColumns, isDocument } from '../src/model.mjs';
7
+ import { AnnotationBook, clipQuote, decodeFilePath, formatAnnotationPrompt, locateChangedSpan, locateQuoteLoose, normalizeQuote, relativeToWorkspace } from '../src/annotations.mjs';
6
8
 
7
9
  const root = fileURLToPath(new URL('../', import.meta.url));
8
10
  let failures = 0;
@@ -14,6 +16,8 @@ const check = (name, cond) => {
14
16
  console.log('== model ==');
15
17
  check('isDocument accepts dsh-resource://file/', isDocument('dsh-resource://file/a.md'));
16
18
  check('isDocument rejects other addresses', !isDocument('https://example.com/a.md'));
19
+ check('isDocument accepts html addresses', isDocument('file:///D:/tmp/page.html'));
20
+ check('isDocument accepts html viewer titles', isDocument('index.html'));
17
21
  check('solveColumns narrow below 760px', solveColumns(700, 0, 0.35).narrow === true);
18
22
  check('solveColumns wide splits document/chat', (() => {
19
23
  const r = solveColumns(1200, 0, 0.35);
@@ -31,9 +35,10 @@ const store = {
31
35
  };
32
36
  const state = new CollaborationState(store);
33
37
  check('auto mode off by default', state.auto === false);
34
- state.auto = true;
38
+ state.setAuto(true);
35
39
  state.session('s1').enabled = true;
36
40
  state.session('s1').ratio = 0.5;
41
+ state.dirty.add('s1');
37
42
  state.save();
38
43
  const restored = new CollaborationState(store);
39
44
  check('auto mode persists', restored.auto === true);
@@ -41,14 +46,171 @@ check('per-session toggle persists', restored.session('s1').enabled === true);
41
46
  check('per-session ratio persists', restored.session('s1').ratio === 0.5);
42
47
  const corrupted = new CollaborationState({ getItem: () => '{not json', setItem() {} });
43
48
  check('corrupted storage does not throw', corrupted.auto === false);
49
+ const sharedStore = memoryStorage();
50
+ const windowA = new CollaborationState(sharedStore);
51
+ const windowB = new CollaborationState(sharedStore);
52
+ windowA.session('s1').enabled = true; windowA.dirty.add('s1'); windowA.save();
53
+ windowB.reload();
54
+ check('layout merge sees another window session', windowB.session('s1').enabled === true);
55
+ windowB.session('s2').enabled = true; windowB.dirty.add('s2'); windowB.save();
56
+ windowA.reload();
57
+ check('layout merge keeps both windows sessions', windowA.session('s1').enabled === true && windowA.session('s2').enabled === true);
58
+ windowA.setAuto(true); windowB.reload();
59
+ check('layout merge keeps the auto flag', windowB.auto === true);
60
+ const dragStore = memoryStorage();
61
+ const dragging = new CollaborationState(dragStore);
62
+ dragging.setRatio('s1', 0.5, false);
63
+ dragging.save();
64
+ const afterDrag = new CollaborationState(dragStore);
65
+ check('ratio committed on drag end', afterDrag.session('s1').ratio === 0.5);
66
+
67
+ console.log('== annotations ==');
68
+ check('decode session file address', decodeFilePath('dsh-resource://file/session/s1/docs/%E6%B5%8B%E8%AF%95.docx') === 'docs/测试.docx');
69
+ check('decode absolute file address', decodeFilePath('dsh-resource://file/absolute/D:/docs/a.docx') === 'D:/docs/a.docx');
70
+ check('decode rejects other addresses', decodeFilePath('https://example.com/a.docx') === '');
71
+ check('decode rejects an empty session tail', decodeFilePath('dsh-resource://file/session/s1') === '');
72
+ check('decode tolerates a bad percent escape', decodeFilePath('dsh-resource://file/absolute/%E0%A4%A') === '');
73
+ check('normalizeQuote collapses whitespace', normalizeQuote(' a \n b ') === 'a b');
74
+ check('clipQuote truncates with an ellipsis', clipQuote('abcdef', 3) === 'abc…');
75
+ check('relative path inside workspace', relativeToWorkspace('C:\\ws\\docs\\a.docx', 'C:\\ws') === 'docs\\a.docx');
76
+ check('relative path keeps POSIX separators', relativeToWorkspace('/ws/docs/a.docx', '/ws') === 'docs/a.docx');
77
+ check('path outside workspace stays absolute', relativeToWorkspace('D:\\other\\a.docx', 'C:\\ws') === 'D:\\other\\a.docx');
78
+ function memoryStorage(seed = {}) {
79
+ const data = { ...seed };
80
+ return {
81
+ _data: data,
82
+ get length() { return Object.keys(data).length; },
83
+ key(index) { return Object.keys(data)[index] ?? null; },
84
+ getItem(key) { return Object.hasOwn(data, key) ? data[key] : null; },
85
+ setItem(key, value) { data[key] = String(value); },
86
+ removeItem(key) { delete data[key]; },
87
+ };
88
+ }
89
+ const annotationStore = memoryStorage();
90
+ const book = new AnnotationBook(annotationStore);
91
+ const noted = book.add('docs/a.docx', {
92
+ page: 2, type: 'comment', quote: '原文 有空格', note: '把口径改成 2026 年',
93
+ rects: [{ x: 0.1, y: 0.2, w: 0.3, h: 0.02 }], prefix: '前文', suffix: '后文',
94
+ });
95
+ check('quote whitespace is normalized', noted.quote === '原文 有空格');
96
+ check('annotation is stored per file', book.count('docs/a.docx') === 1);
97
+ check('annotation uses one key per record', Object.keys(annotationStore._data).filter(key => key.startsWith('dsh.document-view.annotations.v2/')).length === 1);
98
+ book.markSent('docs/a.docx', [noted.id]);
99
+ check('sent marks are tracked', book.items('docs/a.docx')[0].status === 'sent');
100
+ const restoredBook = new AnnotationBook(annotationStore);
101
+ check('annotations persist', restoredBook.count('docs/a.docx') === 1 && restoredBook.items('docs/a.docx')[0].status === 'sent');
102
+ const reopened = restoredBook.update('docs/a.docx', noted.id, { note: '改成 2027 年' });
103
+ check('editing a sent annotation reopens it', reopened.status === 'open' && reopened.note === '改成 2027 年');
104
+ const legacyStore = memoryStorage({
105
+ 'dsh.document-view.annotations.v1': JSON.stringify({
106
+ files: { 'legacy.docx': { items: [{ id: 'legacy1', page: 1, type: 'comment', quote: '旧批注', note: '迁移' }] } },
107
+ }),
108
+ });
109
+ const migrated = new AnnotationBook(legacyStore);
110
+ check('legacy annotations migrate to per-record keys', migrated.count('legacy.docx') === 1 && !Object.hasOwn(legacyStore._data, 'dsh.document-view.annotations.v1'));
111
+ const beforeRemote = book.count('docs/a.docx');
112
+ book.applyStorageEvent('dsh.document-view.annotations.v2/' + encodeURIComponent('docs/a.docx') + '/remote1', JSON.stringify({ id: 'remote1', page: 1, type: 'comment', quote: '远程批注', note: '', createdAt: Date.now() }));
113
+ check('storage event adds a remote annotation', book.count('docs/a.docx') === beforeRemote + 1);
114
+ const sharedBookStore = memoryStorage();
115
+ const firstWindow = new AnnotationBook(sharedBookStore);
116
+ const secondWindow = new AnnotationBook(sharedBookStore);
117
+ const sharedItem = firstWindow.add('shared.docx', { page: 1, type: 'comment', quote: '共享', note: 'A' });
118
+ secondWindow.reload();
119
+ check('second window sees the first window annotation', secondWindow.count('shared.docx') === 1);
120
+ const sharedKey = Object.keys(sharedBookStore._data).find(key => key.startsWith('dsh.document-view.annotations.v2/'));
121
+ const edited = JSON.parse(sharedBookStore._data[sharedKey]);
122
+ edited.note = 'B 改的';
123
+ firstWindow.applyStorageEvent(sharedKey, JSON.stringify(edited));
124
+ check('storage event updates the other window', firstWindow.items('shared.docx')[0].note === 'B 改的');
125
+ firstWindow.applyStorageEvent(sharedKey, null);
126
+ check('storage event delete removes the mark', firstWindow.count('shared.docx') === 0);
127
+ const prompt = formatAnnotationPrompt('docs/a.docx', [
128
+ { page: 2, type: 'comment', quote: '原文', note: '改成 2026 年', prefix: '前文', suffix: '后文' },
129
+ { page: 3, type: 'delete', quote: '删这段', note: '' },
130
+ ]);
131
+ check('prompt names file and count', prompt.includes('`docs/a.docx`') && prompt.includes('共 2 条'));
132
+ check('prompt keeps page and quote', prompt.includes('第 2 页 · 修改') && prompt.includes('「原文」'));
133
+ check('delete gets default instruction', prompt.includes('删掉这段文字'));
134
+ check('prompt labels target apart from context',
135
+ prompt.includes('- 目标(只替换「」内的字符):「原文」') &&
136
+ prompt.includes('- 前文(仅定位,不要改):…前文') &&
137
+ prompt.includes('- 后文(仅定位,不要改):后文…') &&
138
+ prompt.includes('- 目标(只删「」内的字符):「删这段」'));
139
+ check('prompt never clips the target', (() => {
140
+ const long = '长'.repeat(300);
141
+ const out = formatAnnotationPrompt('a.docx', [{ page: 1, type: 'delete', quote: long, note: '', prefix: '前', suffix: '后' }]);
142
+ return out.includes(`「${long}」`) && out.includes('前文(仅定位,不要改):…前');
143
+ })());
144
+ check('prompt states the punctuation rule for deletes', prompt.includes('多余的标点'));
145
+ check('prompt forbids touching context text', prompt.includes('一个字都不要改'));
146
+
147
+ console.log('== changed span ==');
148
+ {
149
+ // A delete leaves the two anchors apart by the whitespace the PDF layer puts
150
+ // between them, and the comma that used to start the next sentence is gone.
151
+ const seam = locateChangedSpan(
152
+ '日内将款项一次性全额支付至甲方指定账户。价格适用 贵公司不得将酒店提供的优惠价格',
153
+ '日内将款项一次性全额支付至甲方指定账户。价格适用',
154
+ ',贵公司不得将酒店提供的优惠价格',
155
+ '本协议内的优惠价格仅限于贵公司内部使用',
156
+ );
157
+ check('locates the seam left by a deletion', Boolean(seam) && seam.to - seam.from === 1);
158
+ const joined = locateChangedSpan(
159
+ '价格适用贵公司不得将酒店提供的优惠价格',
160
+ '价格适用',
161
+ ',贵公司不得将酒店提供的优惠价格',
162
+ '本协议内的优惠价格仅限于贵公司内部使用',
163
+ );
164
+ check('locates a deletion that left the anchors adjacent', Boolean(joined) && joined.to === joined.from);
165
+ const replaced = locateChangedSpan(
166
+ '如发现贵公司有以上情况发生,酒店将立即终止双方合作,收回已售房间并退预付款,并保留追究因此',
167
+ '如发现贵公司有以上情况发生,酒店将立即终止双方合作,',
168
+ ',并保留追究因此',
169
+ '收回已售房间并不退预付款',
170
+ );
171
+ check('locates the replacement text', Boolean(replaced) &&
172
+ '如发现贵公司有以上情况发生,酒店将立即终止双方合作,收回已售房间并退预付款,并保留追究因此'.slice(replaced.from, replaced.to) === '收回已售房间并退预付款');
173
+ check('refuses a gap that still holds the original quote',
174
+ locateChangedSpan('甲,原文,乙', '甲,', ',乙', '原文') === null);
175
+ check('refuses without both anchors', locateChangedSpan('甲,新文', '甲,', '', '原文') === null);
176
+ }
177
+
178
+ console.log('== anchors ==');
179
+ {
180
+ // The text layer drops the space the selection carried; without this the mark
181
+ // would be stored without anchors and could never be re-found after an edit.
182
+ const spaced = locateQuoteLoose('1、此协议将在酒店收到签署并回传的协议后7天内起生效。', '7 天');
183
+ check('loose match survives a spacing difference', Boolean(spaced) &&
184
+ '1、此协议将在酒店收到签署并回传的协议后7天内起生效。'.slice(spaced.from, spaced.to) === '7天');
185
+ check('loose match gives up on a real mismatch',
186
+ locateQuoteLoose('1、此协议将在酒店收到签署并回传的协议后7天内起生效。', '9 天') === null);
187
+ }
44
188
 
45
189
  console.log('== artifact ==');
46
190
  const client = readFileSync(root + 'client.js', 'utf8');
191
+ try {
192
+ execFileSync(process.execPath, ['--check', root + 'client.js'], { stdio: 'ignore' });
193
+ check('client.js parses as JavaScript', true);
194
+ } catch {
195
+ check('client.js parses as JavaScript', false);
196
+ }
47
197
  check('client.js registers module loader id', client.includes("id: 'dsh-document-view'"));
48
198
  check('client.js contains host contract guard', client.includes('hostContractIntact'));
199
+ check('client.js includes annotation prompt formatter', client.includes('formatAnnotationPrompt'));
200
+ check('client.js includes annotation marks', client.includes('fdc-anno-mark') && client.includes('AnnotationBook'));
201
+ check('client.js highlights the ledger span', client.includes('fdc-anno-mark.is-done') && client.includes('annotationAnchorRects'));
202
+ check('client.js marks a landed edit differently', client.includes('is-done') && client.includes('已改动(原批注'));
49
203
  check('client.js wraps activation in try/catch', client.includes('disabled safely after activation error'));
50
204
  check('client.js has no external URL', !/https?:\/\//.test(client));
51
- check('client.js has no network API', !/\b(fetch|XMLHttpRequest|WebSocket|EventSource)\s*\(/.test(client));
205
+ // The only fetch allowed is the host's local dsh-resource:// protocol, used to
206
+ // read the file you already opened so our own HTML preview can render it. It is
207
+ // not a network call: no http(s) URL, no WebSocket, no XHR.
208
+ check('client.js makes no network request', !/https?:\/\//.test(client) && !/\b(XMLHttpRequest|WebSocket|EventSource)\s*\(/.test(client));
209
+ check('client.js fetches only the local resource protocol', (() => {
210
+ const calls = client.match(/\bfetch\(/g) || [];
211
+ if (calls.length === 0) return true;
212
+ return !/fetch\((?!address)/.test(client) && client.includes('dsh-resource://');
213
+ })());
52
214
  check('client.js has no hardcoded local path', !/[A-Za-z]:\\|C:\/Users|\/Users\//.test(client));
53
215
  check('client.js inlines CSS (no external stylesheet)', !/\.css['"]\s*\)/.test(client) && client.includes('style.textContent'));
54
216