dsh-share-html 0.0.0-stage → 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 unknown3310v0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # dsh-share-html
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 把一次 DSH 会话导出为**单个自包含 HTML 文件**,观感对齐 DSH 本身,支持按粒度选择内容。
4
+
5
+ > **要发布这个插件?先读 [`HANDOFF.md`](./HANDOFF.md)** —— 它假定你没有任何历史上下文,
6
+ > 覆盖发布路线、市场规则、迁移后要改的配置、以及已知缺口。
7
+ >
8
+ > 设计文档:[DESIGN.md](./DESIGN.md) | 当前版本:**v0.1.0(阶段一 + 阶段二接线已完成)**
9
+
10
+ ## 安装
11
+
12
+ 从 npm 装(最短):
13
+
14
+ ```bash
15
+ dsh plugin --profile web add dsh-share-html
16
+ ```
17
+
18
+ 从 GitHub Release 装(预构建产物,**无需构建、无需批准安装脚本**):
19
+
20
+ ```bash
21
+ dsh plugin --profile web add https://github.com/unknown3310v0/dsh-share-html/releases/download/v0.1.0/dsh-share-html-0.1.0.tgz
22
+ ```
23
+
24
+ 也可以直接从源码装:
25
+
26
+ ```bash
27
+ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
28
+ ```
29
+
30
+ 装完**重启 `dsh web`**,打开任意会话,header 出现「分享」按钮即生效。
31
+
32
+ ## 两条硬约束
33
+
34
+ 1. **只出 HTML**:任何代码路径都不生成 `.md` / `.json`。
35
+ 2. **视觉对齐 DSH,且是显式内联字面值**:产物里不出现 `var(--dsw-*)`(那些变量只在宿主 DOM 内有效);令牌由脚本从 `@deepseek-ai/dsh-client-ui-theme` 抽取成字面值快照。
36
+
37
+ ## 阶段一做了什么
38
+
39
+ | 任务 | 文件 | 说明 |
40
+ |---|---|---|
41
+ | M1 会话模型 | [`src/host/model.ts`](./src/host/model.ts) | 可辨识联合的块类型;硬约束在类型上没有入口 |
42
+ | M2 投影器 | [`src/host/project.ts`](./src/host/project.ts) | 事件 → 模型;system/注入上下文在这里就被丢弃 |
43
+ | M3 策略裁剪 | [`src/host/policy.ts`](./src/host/policy.ts) | 三档预设 + 逐项开关,保证严格递减 |
44
+ | M4 脱敏 | [`src/host/redact.ts`](./src/host/redact.ts) | mask / mask-hash 两档,纯 JS 哈希 |
45
+ | M5 Markdown | [`src/host/md.ts`](./src/host/md.ts) | 先转义再生产标签,不识别 raw HTML |
46
+ | 高亮 | [`src/host/highlight.ts`](./src/host/highlight.ts) | 极简 tokenizer,未知语言不猜 |
47
+ | M6 装配 | [`src/host/html.ts`](./src/host/html.ts) | 零 `<script>`、零外链、深浅主题跟随系统 |
48
+ | 令牌快照 | [`src/host/tokens.generated.ts`](./src/host/tokens.generated.ts) | 由脚本生成,带主题包版本号 |
49
+
50
+ 一条链跑通:`project → applySharePolicy → redact → renderHtml`,入口见 [`src/host/index.ts`](./src/host/index.ts) 的 `exportSession()`。
51
+
52
+ ## 阶段二做了什么(接入 DSH)
53
+
54
+ | 任务 | 落地 | 说明 |
55
+ |---|---|---|
56
+ | M7 Host 取事件 | [`src/host/session.ts`](./src/host/session.ts) | `ctx.sessionQuery.readSession(id)` → `project` → `exportSession` |
57
+ | M8 契约 | [`src/host/contract.ts`](./src/host/contract.ts) | 手写严格校验:未知字段/越界/路径穿越一律拒;错误码可区分 |
58
+ | M7/M8 接线 | [`lib/index.js`](./lib/index.js) | 优先用 `connection.fetch.register` 在 `/api/share-html/<method>` 注册 exact route;老 core 退回 `connection.rpc.intercept` 认领 `share-html/` 前缀 |
59
+ | M9 入口 | [`lib/client.js`](./lib/client.js) | `conversation.session.header.actions` 插槽注册「分享」按钮 |
60
+ | M10 弹窗 | [`lib/client.js`](./lib/client.js) | 档位 + 逐项开关 + iframe `srcdoc` 预览,选项变化 180ms 防抖重渲染 |
61
+ | M11 下载 | [`lib/client.js`](./lib/client.js) | `Blob` + `<a download>`,文件名来自 Host,不经服务端 |
62
+
63
+ ### 传输层为什么是 `connection.rpc.intercept`
64
+
65
+ 这几条是**逐条实测**得出的,不是照文档猜的:
66
+
67
+ | 尝试 | 结果 |
68
+ |---|---|
69
+ | `ctx.provide('shareHtml', …)` | Host 进程内作用域,浏览器半 `ctx.get` 取不到 |
70
+ | `harness.handle` / `host.call` | 只属于运行时动态插件(cordis runner),包形式没有这个 seat |
71
+ | `connection.rpc.handle(channel, fn)` | 内部往 `webServer` 注册独立路由,而 `webServer` 是**调用方 fiber** 的依赖,插件在 `inject` 里声明也不够 |
72
+ | **`connection.rpc.intercept('/api', matches, fn)`** | ✅ 只挂内存拦截器,不碰 webServer —— 包形式插件可用的那条路 |
73
+
74
+ 因此:Host 拦截 `share-html/` 前缀,Client 调
75
+ `ctx.connection.rpc.call('/api', 'share-html/<method>', payload)`。
76
+ 两端各有一个真机回归测试(`test/host-entry.test.ts`)锁住这条契约。
77
+
78
+ ### 实测结果(测试 profile,端口 3099)
79
+
80
+ - Host 半激活:`[dsh-share-html] host half ready on /api share-html/`
81
+ - 浏览器半激活:`registered share button on conversation.session.header.actions`
82
+ - 真实会话经 RPC 渲染:17 轮 / 285 条消息 / 252 次工具调用 / 272 KB / 零 `<script>`
83
+ - 非法入参:`{ sessionId: "../../../etc" }` → `bad-session`(在读取会话**之前**被拒)
84
+
85
+ **仍未做**:阶段三(体积优化、locale 接线、长会话回归)。
86
+
87
+ ## 用法
88
+
89
+ ### 跑测试
90
+
91
+ ```bash
92
+ cd ~/projects/dsh-share-html
93
+ node --test --experimental-strip-types "test/**/*.test.ts"
94
+ ```
95
+
96
+ 不需要 `npm install`:Node 24 直接剥离类型,测试只依赖内置 `node:test`。
97
+
98
+ ### 拿真实会话回放
99
+
100
+ ```bash
101
+ node --experimental-strip-types scripts/replay.ts \
102
+ ~/.dsh/sessions/<workspace>/<session>/session.v4.jsonl.zstd
103
+ ```
104
+
105
+ 产物落在 `.out/`,三档各一份 `.html`,可直接双击离线打开。
106
+
107
+ ### 刷新令牌快照
108
+
109
+ ```bash
110
+ node scripts/snapshot-tokens.mjs
111
+ ```
112
+
113
+ 读不到主题包时**不会**覆盖现有快照。DSH 换肤后重跑即可,不手抄。
114
+
115
+ ## 验收状态(对应 DESIGN 第 9 节)
116
+
117
+ | 标准 | 状态 | 证据 |
118
+ |---|---|---|
119
+ | 0. 只产出 `.html` | ✅ | `html.test.ts`「只产出 .html」 |
120
+ | 1. 双击可离线打开、无报错 | ✅ | 无头 Chromium 实测:零 console 报错、零外部请求 |
121
+ | 2. `grep -c '<script'` 为 0、无外链 | ✅ | 真实会话产物 0 处 script、0 个 `<link>/<img>`,http 仅出现在正文文本 |
122
+ | 3. 三档严格递增 | ✅ | `policy.test.ts` + `html.test.ts` 双重锁定 |
123
+ | 4. 关闭脱敏标记 `unredacted` | ✅ | meta + 页脚双重告警 |
124
+ | 5. 长会话 < 2MB | ✅ | 120 轮模拟与真实 16 轮会话均在目标内 |
125
+ | 6. 恶意 Markdown 转义 | ✅ | `md.test.ts` 10 组 XSS 载荷 + 最终产物校验 |
126
+ | 7. 文件只显示元信息 | ✅ | 只渲染名/类型/大小,无字节无链接 |
127
+ | 8. 深浅主题随系统 | ✅ | 主题测试 + 无头浏览器 `colorScheme` 实测 |
128
+
129
+ ## 与 DESIGN 的差异(实现期决策)
130
+
131
+ - **`fileBytes` 恒为 false**:类型上就是 `false`,`shareOptions()` 会强制纠正外部传入的 `true`。
132
+ - **工具结果不重复渲染**:assistant 的 `tool-call` 部分跳过,调用统一来自 `tool/call` 事件,避免双卡片。
133
+ - **高亮色不复用 `state-*`**:DSH 的 `state-success-primary` 在浅色下对比度仅 2.18:1,做代码着色读不清;改用同族色阶里小字达标的值(≥ 4.5:1),并有测试兜底。
134
+ - **用户消息按纯文本渲染**:与 DSH 一致,用户输入的 `<` 不该被当成排版意图。
135
+
136
+ ## 待确认(阶段二)
137
+
138
+ - O2 深研事件形态:`ResearchBlock` 已就位,但目前没有事件会投影出它。
139
+ - O3 附件名/类型:模型能带,取决于 DSH 事件里是否提供。
@@ -0,0 +1,5 @@
1
+ # 插入 dsh-share-html 的 Host 行。
2
+ # `name` 必须是裸包名:加载器据此解析包,浏览器半侧也靠它挂上。
3
+ - insert:
4
+ - id: share-html
5
+ name: 'dsh-share-html'