dsh-share-html 0.5.0 → 0.5.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.
- package/README.md +4 -1
- package/lib/index.js +17 -2
- package/lib/kernel.js +192 -5
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 会话导出插件** —— 把一次对话导出成**单个自包含 HTML 文件**,观感与原会话一致,双击即可离线打开。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
存档复盘、交付会话、贴进 wiki,都不用再截图拼接。
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
18
18
|
|
|
19
|
+
> 完整安装指引(含排错、与同类插件的对比)见 **[INSTALL.md](INSTALL.md)**。
|
|
20
|
+
|
|
21
|
+
|
|
19
22
|
```bash
|
|
20
23
|
dsh plugin --profile web add dsh-share-html
|
|
21
24
|
```
|
package/lib/index.js
CHANGED
|
@@ -30,11 +30,26 @@ export const CHANNEL = '/api'
|
|
|
30
30
|
export const ENDPOINT_PREFIX = 'share-html/'
|
|
31
31
|
|
|
32
32
|
export function apply(ctx) {
|
|
33
|
-
const handlers = createHandlers(ctx)
|
|
34
|
-
|
|
35
33
|
const logger = typeof ctx.get === "function" ? ctx.get("logger") : undefined
|
|
36
34
|
const log = logger && typeof logger.info === "function" ? logger.info.bind(logger) : console.log
|
|
37
35
|
|
|
36
|
+
// workspaceChanges 是**可选**服务:不是每个 profile 都装了文件变更记录插件,
|
|
37
|
+
// 所以不能用 inject 声明(声明了就会在没有它的环境里永远 PENDING)。
|
|
38
|
+
// 用 ctx.get 安全取:取不到时内核就把「文件改动摘要」整块跳过。
|
|
39
|
+
// 另外它也只在会话仍被本 Host 持有、进程没重启时才有数据。
|
|
40
|
+
let workspaceChanges
|
|
41
|
+
try {
|
|
42
|
+
workspaceChanges = typeof ctx.get === "function" ? ctx.get("workspaceChanges") : undefined
|
|
43
|
+
} catch {
|
|
44
|
+
workspaceChanges = undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const handlers = createHandlers({
|
|
48
|
+
sessionQuery: ctx.sessionQuery,
|
|
49
|
+
...(workspaceChanges ? { workspaceChanges } : {}),
|
|
50
|
+
...(logger ? { logger } : {}),
|
|
51
|
+
})
|
|
52
|
+
|
|
38
53
|
const jsonReply = (body) => new Response(JSON.stringify(body), {
|
|
39
54
|
status: 200,
|
|
40
55
|
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
|
package/lib/kernel.js
CHANGED
|
@@ -138,6 +138,25 @@ function project(events, options = {}) {
|
|
|
138
138
|
clearStepSlots();
|
|
139
139
|
break;
|
|
140
140
|
}
|
|
141
|
+
// ---- 本轮文件改动摘要 -----------------------------------------------
|
|
142
|
+
// 事件本身只有 {turn},明细靠 options.changes 从 Host 取回。
|
|
143
|
+
// 挂到本轮最后一条 assistant 消息上,渲染在轮末(与 DSH 的位置一致)。
|
|
144
|
+
case "workspace/changes": {
|
|
145
|
+
const changes = options.changes?.get(raw.seq ?? -1);
|
|
146
|
+
if (!changes || !changes.files.length) break;
|
|
147
|
+
const turnNo = asNumber(data.turn);
|
|
148
|
+
const turn = turnNo !== void 0 ? turns.find((t) => t.index === turnNo) ?? current : current;
|
|
149
|
+
if (!turn) break;
|
|
150
|
+
const last = turn.assistants[turn.assistants.length - 1];
|
|
151
|
+
if (last) {
|
|
152
|
+
last.blocks.push(changes);
|
|
153
|
+
} else {
|
|
154
|
+
const host = { id: `changes-${turn.index}`, role: "assistant", blocks: [changes] };
|
|
155
|
+
if (at !== void 0) host.at = at;
|
|
156
|
+
turn.assistants.push(host);
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
141
160
|
case "step/end":
|
|
142
161
|
break;
|
|
143
162
|
default: {
|
|
@@ -171,18 +190,28 @@ function projectUserMessage(msg, at, dropped) {
|
|
|
171
190
|
}
|
|
172
191
|
case "image": {
|
|
173
192
|
dropped.attachmentBytes += 1;
|
|
174
|
-
|
|
193
|
+
const a = asRecord(p.attachment);
|
|
194
|
+
const meta = {
|
|
195
|
+
name: asString(a?.name) ?? asString(p.name) ?? "image",
|
|
196
|
+
type: "IMG"
|
|
197
|
+
};
|
|
198
|
+
const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
|
|
199
|
+
if (bytes !== void 0) meta.bytes = bytes;
|
|
200
|
+
files.push(meta);
|
|
175
201
|
break;
|
|
176
202
|
}
|
|
177
203
|
case "file":
|
|
178
204
|
case "attachment": {
|
|
179
|
-
const
|
|
205
|
+
const a = asRecord(p.attachment);
|
|
206
|
+
const name = asString(a?.name) ?? asString(p.name) ?? asString(p.filename);
|
|
180
207
|
if (!name) {
|
|
181
208
|
dropped.attachmentBytes += 1;
|
|
182
209
|
break;
|
|
183
210
|
}
|
|
184
211
|
const meta = { name, type: fileType(name) };
|
|
185
|
-
const
|
|
212
|
+
const mediaType = asString(a?.mediaType);
|
|
213
|
+
if (mediaType) meta.type = mediaType;
|
|
214
|
+
const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
|
|
186
215
|
if (bytes !== void 0) meta.bytes = bytes;
|
|
187
216
|
files.push(meta);
|
|
188
217
|
break;
|
|
@@ -224,6 +253,20 @@ function collectAssistantBlocks(msg, target, dropped) {
|
|
|
224
253
|
dropped.attachmentBytes += 1;
|
|
225
254
|
break;
|
|
226
255
|
}
|
|
256
|
+
case "file":
|
|
257
|
+
case "attachment": {
|
|
258
|
+
const a = asRecord(p.attachment);
|
|
259
|
+
const name = asString(a?.name) ?? asString(p.name) ?? asString(p.filename);
|
|
260
|
+
if (!name) {
|
|
261
|
+
dropped.attachmentBytes += 1;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
const meta = { name, type: asString(a?.mediaType) ?? fileType(name) };
|
|
265
|
+
const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
|
|
266
|
+
if (bytes !== void 0) meta.bytes = bytes;
|
|
267
|
+
target.blocks.push({ kind: "files", files: [meta] });
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
227
270
|
case "tool-call":
|
|
228
271
|
case "tool-call-delta":
|
|
229
272
|
break;
|
|
@@ -483,6 +526,8 @@ function pruneBlock(block, include, stats) {
|
|
|
483
526
|
case "files":
|
|
484
527
|
if (!include.files) return null;
|
|
485
528
|
return { kind: "files", files: block.files };
|
|
529
|
+
case "changes":
|
|
530
|
+
return include.toolCalls ? block : null;
|
|
486
531
|
case "research":
|
|
487
532
|
return include.deepResearch ? block : null;
|
|
488
533
|
case "tool": {
|
|
@@ -668,6 +713,15 @@ function redactBlock(block, options, hits) {
|
|
|
668
713
|
kind: "files",
|
|
669
714
|
files: block.files.map((f) => ({ ...f, name: redactText(f.name, options, hits) }))
|
|
670
715
|
};
|
|
716
|
+
case "changes":
|
|
717
|
+
return {
|
|
718
|
+
...block,
|
|
719
|
+
files: block.files.map((f) => ({
|
|
720
|
+
...f,
|
|
721
|
+
path: redactText(f.path, options, hits),
|
|
722
|
+
display: redactText(f.display, options, hits)
|
|
723
|
+
}))
|
|
724
|
+
};
|
|
671
725
|
case "tool": {
|
|
672
726
|
const out = { ...block };
|
|
673
727
|
if (block.args !== void 0) out.args = redactText(block.args, options, hits);
|
|
@@ -1632,6 +1686,82 @@ main { display: flex; flex-direction: column; gap: 28px; }
|
|
|
1632
1686
|
|
|
1633
1687
|
.file-meta { color: var(--dsh-label-tertiary); font-size: 12px; line-height: 15px; }
|
|
1634
1688
|
|
|
1689
|
+
/* ---------- \u672C\u8F6E\u6587\u4EF6\u6539\u52A8\u6458\u8981\uFF08\u5BF9\u5E94 DSH \u7684\u300C\u5DF2\u7F16\u8F91 N \u4E2A\u6587\u4EF6\u300D\uFF09 ---------- */
|
|
1690
|
+
|
|
1691
|
+
details.changes {
|
|
1692
|
+
margin: 8px 0 2px;
|
|
1693
|
+
border: .5px solid var(--dsh-border-l2);
|
|
1694
|
+
border-radius: var(--dsh-radius-lg);
|
|
1695
|
+
background: var(--dsh-input-major);
|
|
1696
|
+
overflow: hidden;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
details.changes > summary {
|
|
1700
|
+
display: flex;
|
|
1701
|
+
align-items: center;
|
|
1702
|
+
gap: 8px;
|
|
1703
|
+
min-height: 40px;
|
|
1704
|
+
padding: 8px 14px;
|
|
1705
|
+
cursor: pointer;
|
|
1706
|
+
list-style: none;
|
|
1707
|
+
color: var(--dsh-label-primary);
|
|
1708
|
+
font-size: 13px;
|
|
1709
|
+
line-height: 20px;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
details.changes > summary::-webkit-details-marker { display: none; }
|
|
1713
|
+
|
|
1714
|
+
/* \u7528\u65CB\u8F6C\u7684\u4E09\u89D2\u66FF\u4EE3\u9ED8\u8BA4\u7BAD\u5934\uFF0C\u4FDD\u6301\u96F6\u811A\u672C\u3001\u7EAF CSS */
|
|
1715
|
+
details.changes > summary::before {
|
|
1716
|
+
content: "";
|
|
1717
|
+
flex: none;
|
|
1718
|
+
width: 0;
|
|
1719
|
+
height: 0;
|
|
1720
|
+
border-left: 5px solid var(--dsh-label-tertiary);
|
|
1721
|
+
border-top: 4px solid transparent;
|
|
1722
|
+
border-bottom: 4px solid transparent;
|
|
1723
|
+
transition: transform .15s ease;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
details.changes[open] > summary::before { transform: rotate(90deg); }
|
|
1727
|
+
|
|
1728
|
+
.chg-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1729
|
+
|
|
1730
|
+
.chg-added { color: var(--dsh-state-success-primary); font-variant-numeric: tabular-nums; }
|
|
1731
|
+
.chg-deleted { color: var(--dsh-state-error-primary); font-variant-numeric: tabular-nums; }
|
|
1732
|
+
|
|
1733
|
+
details.changes > summary .chg-added,
|
|
1734
|
+
details.changes > summary .chg-deleted { flex: none; font-size: 12px; }
|
|
1735
|
+
|
|
1736
|
+
.chg-body { border-top: .5px solid var(--dsh-border-l2); padding: 6px 0; }
|
|
1737
|
+
|
|
1738
|
+
.chg-list { margin: 0; padding: 0; list-style: none; }
|
|
1739
|
+
|
|
1740
|
+
.chg-row {
|
|
1741
|
+
display: flex;
|
|
1742
|
+
align-items: center;
|
|
1743
|
+
gap: 12px;
|
|
1744
|
+
padding: 3px 14px;
|
|
1745
|
+
font-size: 12px;
|
|
1746
|
+
line-height: 20px;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
.chg-path {
|
|
1750
|
+
flex: 1 1 auto;
|
|
1751
|
+
min-width: 0;
|
|
1752
|
+
overflow: hidden;
|
|
1753
|
+
text-overflow: ellipsis;
|
|
1754
|
+
white-space: nowrap;
|
|
1755
|
+
color: var(--dsh-label-secondary);
|
|
1756
|
+
font-family: var(--dsh-font-code);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
.chg-stat { flex: none; display: inline-flex; gap: 8px; font-variant-numeric: tabular-nums; }
|
|
1760
|
+
|
|
1761
|
+
.chg-note { color: var(--dsh-label-tertiary); }
|
|
1762
|
+
|
|
1763
|
+
.chg-more { color: var(--dsh-label-tertiary); font-style: italic; }
|
|
1764
|
+
|
|
1635
1765
|
/* ---------- \u6298\u53E0\u5757\uFF08\u601D\u8003 / \u5DE5\u5177 / \u68C0\u7D22 / \u6DF1\u7814\uFF09 ---------- */
|
|
1636
1766
|
|
|
1637
1767
|
details.process {
|
|
@@ -2161,6 +2291,8 @@ function renderBlock(block) {
|
|
|
2161
2291
|
});
|
|
2162
2292
|
case "files":
|
|
2163
2293
|
return renderFiles(block.files);
|
|
2294
|
+
case "changes":
|
|
2295
|
+
return renderChanges(block);
|
|
2164
2296
|
}
|
|
2165
2297
|
}
|
|
2166
2298
|
function renderDetails(input) {
|
|
@@ -2250,6 +2382,25 @@ function renderFiles(files) {
|
|
|
2250
2382
|
}).join("");
|
|
2251
2383
|
return `<div class="files">${cards}</div>`;
|
|
2252
2384
|
}
|
|
2385
|
+
function renderChanges(block) {
|
|
2386
|
+
const counts = `<span class="chg-added">+${block.added}</span><span class="chg-deleted">-${block.deleted}</span>`;
|
|
2387
|
+
const single = block.total === 1 ? block.files[0] : void 0;
|
|
2388
|
+
const title = single ? `\u5DF2\u7F16\u8F91 ${basename(single.display)}` : `\u5DF2\u7F16\u8F91 ${block.total} \u4E2A\u6587\u4EF6`;
|
|
2389
|
+
const rows = block.files.map((f) => {
|
|
2390
|
+
const stat = f.binary === true ? '<span class="chg-note">\u4E8C\u8FDB\u5236</span>' : f.oversized === true ? '<span class="chg-note">\u8FC7\u5927</span>' : `<span class="chg-added">+${f.added}</span><span class="chg-deleted">-${f.deleted}</span>`;
|
|
2391
|
+
return `<li class="chg-row"><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></li>`;
|
|
2392
|
+
}).join("\n");
|
|
2393
|
+
const more = block.total > block.files.length ? `<li class="chg-row chg-more">\u53E6\u6709 ${block.total - block.files.length} \u4E2A\u6587\u4EF6\u672A\u5217\u51FA</li>` : "";
|
|
2394
|
+
return `<details class="changes">
|
|
2395
|
+
<summary><span class="chg-title">${esc(title)}</span>${counts}</summary>
|
|
2396
|
+
<div class="chg-body">
|
|
2397
|
+
<ul class="chg-list">
|
|
2398
|
+
${rows}
|
|
2399
|
+
${more}
|
|
2400
|
+
</ul>
|
|
2401
|
+
</div>
|
|
2402
|
+
</details>`;
|
|
2403
|
+
}
|
|
2253
2404
|
function basename(name) {
|
|
2254
2405
|
const parts = name.split(/[\\/]/).filter(Boolean);
|
|
2255
2406
|
return parts.length ? parts[parts.length - 1] ?? name : name;
|
|
@@ -2336,7 +2487,7 @@ function filenameStamp(epochMs, timeZone) {
|
|
|
2336
2487
|
}
|
|
2337
2488
|
|
|
2338
2489
|
// src/host/index.ts
|
|
2339
|
-
var VERSION = "0.5.
|
|
2490
|
+
var VERSION = "0.5.1";
|
|
2340
2491
|
function exportSession(input) {
|
|
2341
2492
|
const preset = input.preset ?? "conversation";
|
|
2342
2493
|
const opts = shareOptions(preset, input.options ?? {});
|
|
@@ -2530,6 +2681,7 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
|
|
|
2530
2681
|
if (truncatedEvents.length < events.length) {
|
|
2531
2682
|
warnings.push(`\u4F1A\u8BDD\u4E8B\u4EF6\u8FC7\u591A\uFF0C\u4EC5\u5BFC\u51FA\u524D ${MAX_EVENTS} \u6761\uFF08\u5171 ${events.length} \u6761\uFF09`);
|
|
2532
2683
|
}
|
|
2684
|
+
const changes = collectChanges(ctx, request.sessionId, truncatedEvents);
|
|
2533
2685
|
const shareOptions2 = {};
|
|
2534
2686
|
if (request.turns !== void 0) shareOptions2.turns = request.turns;
|
|
2535
2687
|
if (request.include) shareOptions2.include = { ...presetInclude(request.preset), ...request.include };
|
|
@@ -2545,7 +2697,8 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
|
|
|
2545
2697
|
},
|
|
2546
2698
|
projectOptions: {
|
|
2547
2699
|
sessionId: request.sessionId,
|
|
2548
|
-
...title ? { title } : {}
|
|
2700
|
+
...title ? { title } : {},
|
|
2701
|
+
...changes.size ? { changes } : {}
|
|
2549
2702
|
},
|
|
2550
2703
|
meta: { timeZone },
|
|
2551
2704
|
exportedAt: now()
|
|
@@ -2650,6 +2803,39 @@ function toRawEvents(snapshot) {
|
|
|
2650
2803
|
}
|
|
2651
2804
|
return out;
|
|
2652
2805
|
}
|
|
2806
|
+
function collectChanges(ctx, sessionId, events) {
|
|
2807
|
+
const out = /* @__PURE__ */ new Map();
|
|
2808
|
+
const service = ctx.workspaceChanges;
|
|
2809
|
+
if (!service) return out;
|
|
2810
|
+
for (const event of events) {
|
|
2811
|
+
if (event.type !== "workspace/changes") continue;
|
|
2812
|
+
const seq = event.seq;
|
|
2813
|
+
if (typeof seq !== "number") continue;
|
|
2814
|
+
let summary;
|
|
2815
|
+
try {
|
|
2816
|
+
summary = service.summary(sessionId, seq);
|
|
2817
|
+
} catch (error) {
|
|
2818
|
+
ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6\u6587\u4EF6\u6539\u52A8\u6458\u8981\u5931\u8D25\uFF08seq=%s\uFF09\uFF1A%s", seq, String(error));
|
|
2819
|
+
continue;
|
|
2820
|
+
}
|
|
2821
|
+
if (!summary || !Array.isArray(summary.files)) continue;
|
|
2822
|
+
out.set(seq, {
|
|
2823
|
+
kind: "changes",
|
|
2824
|
+
files: summary.files.map((f) => ({
|
|
2825
|
+
path: f.path,
|
|
2826
|
+
display: f.display,
|
|
2827
|
+
added: f.added,
|
|
2828
|
+
deleted: f.deleted,
|
|
2829
|
+
...f.binary === true ? { binary: true } : {},
|
|
2830
|
+
...f.oversized === true ? { oversized: true } : {}
|
|
2831
|
+
})),
|
|
2832
|
+
total: summary.total,
|
|
2833
|
+
added: summary.added,
|
|
2834
|
+
deleted: summary.deleted
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
return out;
|
|
2838
|
+
}
|
|
2653
2839
|
function defaultTimeZone() {
|
|
2654
2840
|
try {
|
|
2655
2841
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -2678,6 +2864,7 @@ export {
|
|
|
2678
2864
|
MAX_EVENTS,
|
|
2679
2865
|
MAX_HTML_BYTES,
|
|
2680
2866
|
capabilitiesForRequest,
|
|
2867
|
+
collectChanges,
|
|
2681
2868
|
createHandlers,
|
|
2682
2869
|
renderForRequest,
|
|
2683
2870
|
toRawEvents,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-share-html",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Export a DSH session as one self-contained, offline HTML file that looks like the original conversation: three detail presets, per-block switches, built-in redaction, zero scripts and zero external requests.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"snapshot:tokens": "node scripts/snapshot-tokens.mjs",
|
|
12
12
|
"fixture": "node --experimental-strip-types scripts/replay.ts",
|
|
13
13
|
"build": "node scripts/build.mjs",
|
|
14
|
+
"dev": "node scripts/watch.mjs",
|
|
15
|
+
"dev:fast": "node scripts/watch.mjs --no-test",
|
|
14
16
|
"prepublishOnly": "npm run build && npm test"
|
|
15
17
|
},
|
|
16
18
|
"files": [
|