dsh-share-html 0.4.1 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +2 -33
  2. package/lib/kernel.js +16 -244
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -64,7 +64,7 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
64
64
  | **工具调用** | 整段工具交互消失 | 折叠的「工具名 + 参数摘要」 |
65
65
  | **工具结果** | 只留一行摘要(`共 3 行 / 52 字符`) | 结果正文全文 |
66
66
  | **附件** | 不显示文件条目 | 文件名 + 类型 + 大小(不含内容)|
67
- | **模型信息** | 轮次头只显示状态与耗时 | 轮次头多一个模型名 |
67
+ | **模型信息** | 消息头部不显示模型名 | 消息头部左侧显示模型名 |
68
68
 
69
69
  > **关于「检索结果」和「深度研究」**:这两个开关曾经存在,v0.3.1 起已从界面上移除。
70
70
  > 它们的渲染与裁剪逻辑都已写好,但 DSH 的事件流里没有对应的结构化事件 ——
@@ -80,42 +80,11 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
80
80
 
81
81
  - [对话档](docs/example-conversation.html) —— 只有两轮问答
82
82
  - [过程档](docs/example-process.html) —— 多出思考、工具调用、附件;工具结果只剩一行摘要
83
- - [完整档](docs/example-full.html) —— 工具结果全文,轮次头带模型名
83
+ - [完整档](docs/example-full.html) —— 工具结果全文,消息头带模型名
84
84
 
85
85
  > 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
86
86
  > 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
87
87
 
88
- ### 轮次头与折叠
89
-
90
- 每轮的助手输出与 DSH 原会话结构一致:
91
-
92
- ```
93
- 已完成,用时 9分52秒 ⌄ ← 轮次头,默认展开
94
- 明白了:<details> 的容器边界搞错了… ← 正文,直接可见
95
- ▸ 调用 2 次工具 bash ← 工具调用,默认收起
96
- 根因找到了… ← 继续的正文,直接可见
97
- ▸ 调用 1 次工具 read
98
- ……
99
- ```
100
-
101
- 两层折叠,各管各的:
102
-
103
- | 折叠项 | 默认 | 展开后 |
104
- |---|---|---|
105
- | **轮次头**(已完成,用时 X) | 展开 | 该轮的全部内容 |
106
- | **调用 N 次工具** | 收起 | 每次调用的参数与结果 |
107
-
108
- 两条硬规则,都来自 DSH 的做法:
109
-
110
- 1. **助手回复永远不被折叠**。折叠的是过程,回复必须直接可见 ——
111
- DSH 文档对它的几种展示模式都是这个约定("fold … while keeping every Assistant reply visible")。
112
- 收起轮次头是读者主动选择跳过这一轮,不是我们偷偷把回答藏起来。
113
- 2. **过程里不再套第三层**。同一段连续的工具调用聚合成一个「调用 N 次工具」,
114
- 展开就是参数和结果;不会出现「轮次 → 过程 → 工具」要点三次才看到一行输出。
115
-
116
- - 状态来自 `turn/end` 的 `reason.kind`(已完成 / 已中止 / 失败 / 已取消)
117
- - 耗时是该轮从开始到结束的实际时长;没有 `turn/end` 的会话不显示轮次头
118
-
119
88
  ### 选择轮次
120
89
 
121
90
  会话很长时,可以只导出其中几轮。展开「导出轮次」后按轮勾选:
package/lib/kernel.js CHANGED
@@ -30,12 +30,10 @@ function project(events, options = {}) {
30
30
  let lastModel;
31
31
  const pendingCalls = /* @__PURE__ */ new Map();
32
32
  const callOwner = /* @__PURE__ */ new Map();
33
- const turnStartedAt = /* @__PURE__ */ new Map();
34
- const openTurn = (user, at) => {
33
+ const openTurn = (user) => {
35
34
  const turn = { index: turns.length + 1, user, assistants: [] };
36
35
  turns.push(turn);
37
36
  current = turn;
38
- if (at !== void 0) turnStartedAt.set(turn.index, at);
39
37
  return turn;
40
38
  };
41
39
  const ensureTurn = () => current ?? openTurn(null);
@@ -84,7 +82,7 @@ function project(events, options = {}) {
84
82
  }
85
83
  const user = projectUserMessage(msg, at, dropped);
86
84
  if (!user) break;
87
- openTurn(user, at);
85
+ openTurn(user);
88
86
  clearStepSlots();
89
87
  break;
90
88
  }
@@ -135,21 +133,7 @@ function project(events, options = {}) {
135
133
  break;
136
134
  }
137
135
  // ---- 轮次与步骤边界(只影响归并) -----------------------------------
138
- case "turn/start": {
139
- if (!current) openTurn(null, at);
140
- else if (at !== void 0 && !turnStartedAt.has(current.index)) turnStartedAt.set(current.index, at);
141
- break;
142
- }
143
136
  case "turn/end": {
144
- if (current) {
145
- const reason = asRecord(data.reason);
146
- const kind = asString(reason?.kind);
147
- if (kind) current.status = kind;
148
- const startedAt = turnStartedAt.get(current.index);
149
- if (startedAt !== void 0 && at !== void 0 && at >= startedAt) {
150
- current.durationMs = at - startedAt;
151
- }
152
- }
153
137
  current = null;
154
138
  clearStepSlots();
155
139
  break;
@@ -1685,145 +1669,6 @@ details.process > summary::after {
1685
1669
 
1686
1670
  details.process[open] > summary::after { transform: rotate(45deg); }
1687
1671
 
1688
- /* ---------- \u8F6E\u6B21\u5934\uFF08\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 9\u520652\u79D2\uFF09 ---------- */
1689
-
1690
- /* \u4E0E .process \u540C\u4E00\u5957\u6298\u53E0\u624B\u611F\uFF1A\u540C\u4E00\u4E2A\u7BAD\u5934\u3001\u540C\u4E00\u5904\u5BF9\u9F50\u3001\u540C\u6837\u53EA\u5728\u60AC\u505C/tab \u65F6\u56DE\u5E94\u3002 */
1691
- details.turn {
1692
- margin: 2px 0;
1693
- }
1694
-
1695
- details.turn > summary.turn-head {
1696
- display: flex;
1697
- align-items: center;
1698
- gap: 10px;
1699
- min-height: 28px;
1700
- padding: 2px 0;
1701
- cursor: pointer;
1702
- list-style: none;
1703
- color: var(--dsh-label-tertiary);
1704
- font-size: 12px;
1705
- line-height: 18px;
1706
- }
1707
-
1708
- details.turn > summary.turn-head::-webkit-details-marker { display: none; }
1709
-
1710
- details.turn > summary.turn-head::after {
1711
- content: "";
1712
- flex: none;
1713
- width: 6px;
1714
- height: 6px;
1715
- border-right: 1.5px solid currentColor;
1716
- border-bottom: 1.5px solid currentColor;
1717
- transform: rotate(-45deg);
1718
- transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
1719
- }
1720
-
1721
- details.turn[open] > summary.turn-head::after { transform: rotate(45deg); }
1722
-
1723
- .turn-head .turn-meta { font-variant-numeric: tabular-nums; }
1724
- .turn-head .msg-model { color: var(--dsh-label-caption); }
1725
-
1726
- details.turn > summary.turn-head:focus-visible {
1727
- outline: 1.5px solid var(--dsh-link);
1728
- outline-offset: 2px;
1729
- border-radius: var(--dsh-radius-sm);
1730
- }
1731
-
1732
- @media (hover: hover) {
1733
- details.turn > summary.turn-head:hover { color: var(--dsh-label-secondary); }
1734
- }
1735
-
1736
- /* \u5C55\u5F00\u540E\u6B63\u6587\u4E0E\u5934\u90E8\u5DE6\u8FB9\u7F18\u5BF9\u9F50\uFF0C\u4E0D\u989D\u5916\u7F29\u8FDB\uFF08\u8FD9\u4E00\u5C42\u4E0D\u662F"\u8FC7\u7A0B"\u7684\u5B50\u9879\uFF09 */
1737
- .turn-body { margin: 2px 0 0; }
1738
- .turn-body > *:first-child { margin-top: 0; }
1739
-
1740
- /* ---------- \u5DE5\u5177\u8C03\u7528\u7EC4\uFF08\u8C03\u7528 N \u6B21\u5DE5\u5177\uFF09 ---------- */
1741
-
1742
- /* \u4E0E .process \u540C\u4E00\u5957\u6298\u53E0\u624B\u611F\uFF0C\u4F46\u6807\u9898\u662F\u5BBF\u4E3B\u90A3\u79CD"\u8C03\u7528 2 \u6B21\u5DE5\u5177"\u7684\u8BF4\u6CD5\u3002 */
1743
- details.tool-group {
1744
- margin: 6px 0;
1745
- border-radius: var(--dsh-radius-sm);
1746
- }
1747
-
1748
- details.tool-group > summary {
1749
- display: flex;
1750
- align-items: center;
1751
- gap: 8px;
1752
- min-height: 26px;
1753
- padding: 2px 0;
1754
- cursor: pointer;
1755
- list-style: none;
1756
- font-size: 12px;
1757
- line-height: 18px;
1758
- color: var(--dsh-label-tertiary);
1759
- }
1760
-
1761
- details.tool-group > summary::-webkit-details-marker { display: none; }
1762
-
1763
- details.tool-group > summary::after {
1764
- content: "";
1765
- flex: none;
1766
- width: 6px;
1767
- height: 6px;
1768
- border-right: 1.5px solid currentColor;
1769
- border-bottom: 1.5px solid currentColor;
1770
- transform: rotate(-45deg);
1771
- transition: transform var(--dsh-duration-fast) var(--dsh-ease-in-out);
1772
- }
1773
-
1774
- details.tool-group[open] > summary::after { transform: rotate(45deg); }
1775
-
1776
- details.tool-group > summary:focus-visible {
1777
- outline: 1.5px solid var(--dsh-link);
1778
- outline-offset: 2px;
1779
- border-radius: var(--dsh-radius-sm);
1780
- }
1781
-
1782
- @media (hover: hover) {
1783
- details.tool-group > summary:hover { color: var(--dsh-label-secondary); }
1784
- }
1785
-
1786
- .tool-group .sum-names {
1787
- color: var(--dsh-label-caption);
1788
- font-family: var(--dsh-font-code);
1789
- font-size: 11px;
1790
- }
1791
-
1792
- .tool-group-body {
1793
- margin: 2px 0 4px 14px;
1794
- padding-left: 10px;
1795
- border-left: 1px solid var(--dsh-border-l2);
1796
- }
1797
-
1798
- /* ---------- \u5DE5\u5177\u8C03\u7528\u7684\u6241\u5E73\u5185\u5BB9 ---------- */
1799
- /* \u5DF2\u7ECF\u5728\u300C\u8C03\u7528 N \u6B21\u5DE5\u5177\u300D\u91CC\u4E86\uFF0C\u5C31\u4E0D\u518D\u5957\u7B2C\u4E8C\u5C42 <details>\uFF1A
1800
- \u5426\u5219\u8BFB\u4E00\u884C\u8F93\u51FA\u8981\u70B9\u4E24\u6B21\uFF08\u8F6E\u6B21 \u2192 \u5DE5\u5177\u7EC4 \u2192 \u5DE5\u5177\uFF09\u3002 */
1801
- .flat-block {
1802
- margin: 6px 0;
1803
- }
1804
-
1805
- .flat-head {
1806
- display: flex;
1807
- align-items: center;
1808
- gap: 8px;
1809
- font-size: 12px;
1810
- line-height: 18px;
1811
- color: var(--dsh-label-tertiary);
1812
- }
1813
-
1814
- .flat-head .sum-name {
1815
- color: var(--dsh-label-secondary);
1816
- font-family: var(--dsh-font-code);
1817
- }
1818
-
1819
- .flat-body {
1820
- margin: 2px 0 0;
1821
- overflow-wrap: anywhere;
1822
- }
1823
-
1824
- .flat-body > *:first-child { margin-top: 0; }
1825
- .flat-body > *:last-child { margin-bottom: 0; }
1826
-
1827
1672
  @media (hover: hover) {
1828
1673
  details.process > summary:hover { color: var(--dsh-label-secondary); }
1829
1674
  }
@@ -2167,17 +2012,20 @@ function renderHtml(model, meta = {}) {
2167
2012
  stats.messages += 1;
2168
2013
  body.push(renderUserMessage(turn.user));
2169
2014
  }
2170
- const turnBlocks = [];
2015
+ const assistantBlocks = [];
2171
2016
  const turnModels = [];
2172
2017
  for (const msg of turn.assistants) {
2173
2018
  stats.messages += 1;
2174
2019
  stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
2175
2020
  if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
2176
- const rendered = renderAssistantMessage(msg);
2177
- if (rendered.trim()) turnBlocks.push(rendered);
2021
+ assistantBlocks.push(renderAssistantMessage(msg));
2178
2022
  }
2179
- if (turnBlocks.length) {
2180
- body.push(renderTurnArticle(turn, turnBlocks, turnModels));
2023
+ if (assistantBlocks.length) {
2024
+ const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
2025
+ ` : "";
2026
+ body.push(`<article class="msg" data-role="assistant">
2027
+ ${head}${assistantBlocks.join("\n")}
2028
+ </article>`);
2181
2029
  }
2182
2030
  }
2183
2031
  if (!body.length) {
@@ -2282,60 +2130,13 @@ function renderUserMessage(msg) {
2282
2130
  ${parts.join("\n")}
2283
2131
  </article>`;
2284
2132
  }
2285
- function renderTurnArticle(turn, blocks, models) {
2286
- const status = statusLabel(turn.status);
2287
- const duration = turn.durationMs !== void 0 ? formatDuration(turn.durationMs) : "";
2288
- const metaParts = [status, duration ? `\u7528\u65F6 ${duration}` : ""].filter(Boolean);
2289
- const metaHtml = metaParts.length ? `<span class="turn-meta">${esc(metaParts.join("\uFF0C"))}</span>` : "";
2290
- const modelHtml = models.length ? `<span class="msg-model">${models.map(esc).join(" \xB7 ")}</span>` : "";
2291
- const inner = blocks.join("\n");
2292
- if (!metaHtml && !modelHtml) {
2293
- return `<article class="msg" data-role="assistant">
2294
- ${inner}
2295
- </article>`;
2296
- }
2297
- return `<article class="msg" data-role="assistant">
2298
- <details class="turn" open>
2299
- <summary class="turn-head">${metaHtml}${modelHtml}</summary>
2300
- <div class="turn-body">
2301
- ${inner}
2302
- </div>
2303
- </details>
2304
- </article>`;
2305
- }
2306
2133
  function renderAssistantMessage(msg) {
2307
2134
  const parts = [];
2308
- let pendingTools = [];
2309
- const flushTools = () => {
2310
- if (!pendingTools.length) return;
2311
- parts.push(renderToolGroup(pendingTools));
2312
- pendingTools = [];
2313
- };
2314
2135
  for (const block of msg.blocks) {
2315
- if (block.kind === "tool") {
2316
- pendingTools.push(block);
2317
- continue;
2318
- }
2319
- flushTools();
2320
2136
  parts.push(renderBlock(block));
2321
2137
  }
2322
- flushTools();
2323
2138
  return parts.filter(Boolean).join("\n");
2324
2139
  }
2325
- function renderToolGroup(tools) {
2326
- const n = tools.length;
2327
- const failed = tools.filter((t) => t.status === "error").length;
2328
- const label = n === 1 ? "\u8C03\u7528 1 \u6B21\u5DE5\u5177" : `\u8C03\u7528 ${n} \u6B21\u5DE5\u5177`;
2329
- const names = [...new Set(tools.map((t) => t.name))].join(", ");
2330
- const failBadge = failed ? `<span class="sum-state" data-status="error">${failed} \u4E2A\u5931\u8D25</span>` : "";
2331
- const body = tools.map((t) => renderTool(t, true)).join("\n");
2332
- return `<details class="tool-group" data-kind="tool-group">
2333
- <summary><span class="sum-text">${esc(label)}</span><span class="sum-names">${esc(names)}</span>${failBadge}</summary>
2334
- <div class="tool-group-body">
2335
- ${body}
2336
- </div>
2337
- </details>`;
2338
- }
2339
2140
  function renderBlock(block) {
2340
2141
  switch (block.kind) {
2341
2142
  case "text":
@@ -2365,8 +2166,7 @@ function renderBlock(block) {
2365
2166
  function renderDetails(input) {
2366
2167
  const statusAttr = input.status ? ` data-status="${esc(input.status)}"` : "";
2367
2168
  const nameHtml = input.name ? `<span class="sum-name">${esc(input.name)}</span>` : "";
2368
- const openAttr = input.open ? " open" : "";
2369
- return `<details class="process" data-kind="${esc(input.kind)}"${openAttr}>
2169
+ return `<details class="process" data-kind="${esc(input.kind)}">
2370
2170
  <summary><span class="sum-text">${esc(input.summary)}</span>${nameHtml}${statusDot(input.status)}</summary>
2371
2171
  <div class="process-body">
2372
2172
  ${input.body}
@@ -2401,13 +2201,12 @@ function renderTool(block) {
2401
2201
  body.push('<div class="trunc-note">\u4F1A\u8BDD\u5BFC\u51FA\u65F6\u8BE5\u8C03\u7528\u5C1A\u672A\u8FD4\u56DE</div>');
2402
2202
  }
2403
2203
  const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
2404
- const head = `<span class="sum-name">${esc(block.name)}</span><span class="sum-dot"></span><span class="sum-text">${esc(summaryText)}</span>${stateText ? `<span class="sum-state" data-status="${esc(block.status)}">${esc(stateText)}</span>` : ""}`;
2405
- return `<div class="flat-block" data-kind="tool" data-tool="${esc(block.name)}">
2406
- <div class="flat-head">${head}</div>
2407
- <div class="flat-body">
2204
+ return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
2205
+ <summary><span class="sum-name">${esc(block.name)}</span><span class="sum-dot"></span><span class="sum-text">${esc(summaryText)}</span>${stateText ? `<span class="sum-state" data-status="${esc(block.status)}">${esc(stateText)}</span>` : ""}</summary>
2206
+ <div class="process-body">
2408
2207
  ${body.join("\n")}
2409
2208
  </div>
2410
- </div>`;
2209
+ </details>`;
2411
2210
  }
2412
2211
  function toolSummary(block) {
2413
2212
  const fields = block.argsFields ?? [];
@@ -2467,33 +2266,6 @@ function formatBytes(bytes) {
2467
2266
  }
2468
2267
  return `${value >= 10 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
2469
2268
  }
2470
- function formatDuration(ms) {
2471
- if (!Number.isFinite(ms) || ms < 0) return "";
2472
- const totalSeconds = Math.floor(ms / 1e3);
2473
- if (totalSeconds < 1) return "\u4E0D\u8DB31\u79D2";
2474
- const hours = Math.floor(totalSeconds / 3600);
2475
- const minutes = Math.floor(totalSeconds % 3600 / 60);
2476
- const seconds = totalSeconds % 60;
2477
- if (hours > 0) return `${hours}\u5C0F\u65F6${minutes}\u5206${seconds}\u79D2`;
2478
- if (minutes > 0) return `${minutes}\u5206${seconds}\u79D2`;
2479
- return `${seconds}\u79D2`;
2480
- }
2481
- function statusLabel(status) {
2482
- switch (status) {
2483
- case "completed":
2484
- return "\u5DF2\u5B8C\u6210";
2485
- case "aborted":
2486
- return "\u5DF2\u4E2D\u6B62";
2487
- case "failed":
2488
- return "\u5931\u8D25";
2489
- case "cancelled":
2490
- return "\u5DF2\u53D6\u6D88";
2491
- case void 0:
2492
- return "";
2493
- default:
2494
- return status;
2495
- }
2496
- }
2497
2269
  function presetLabel(preset) {
2498
2270
  switch (preset) {
2499
2271
  case "conversation":
@@ -2564,7 +2336,7 @@ function filenameStamp(epochMs, timeZone) {
2564
2336
  }
2565
2337
 
2566
2338
  // src/host/index.ts
2567
- var VERSION = "0.4.1";
2339
+ var VERSION = "0.5.0";
2568
2340
  function exportSession(input) {
2569
2341
  const preset = input.preset ?? "conversation";
2570
2342
  const opts = shareOptions(preset, input.options ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-share-html",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
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",