dsh-share-html 0.3.1 → 0.4.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.
Files changed (3) hide show
  1. package/README.md +24 -7
  2. package/lib/kernel.js +132 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -85,19 +85,36 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
85
85
  > 想直观看出区别,请用**用过工具**的会话(让模型读过文件、跑过命令)。只有纯问答的会话,
86
86
  > 大部分开关没有可显示的内容,三档看起来会几乎一样 —— 这是正确的,不是开关失灵。
87
87
 
88
- ### 轮次头
88
+ ### 轮次头与折叠
89
89
 
90
- 每轮的助手输出带一个可折叠的头,与 DSH 原会话一致:
90
+ 每轮的助手输出与 DSH 原会话结构一致:
91
91
 
92
92
  ```
93
- 已完成,用时 9分52秒 ⌄
93
+ 已完成,用时 9分52秒 ⌄ ← 轮次头,默认展开
94
+ 明白了:<details> 的容器边界搞错了… ← 正文,直接可见
95
+ ▸ 调用 2 次工具 bash ← 工具调用,默认收起
96
+ 根因找到了… ← 继续的正文,直接可见
97
+ ▸ 调用 1 次工具 read
98
+ ……
94
99
  ```
95
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
+
96
116
  - 状态来自 `turn/end` 的 `reason.kind`(已完成 / 已中止 / 失败 / 已取消)
97
- - 耗时是该轮从开始到结束的实际时长
98
- - 点击头部可折叠整轮,箭头随状态旋转
99
- - **默认展开**:导出的是一份要读的记录,不是要点开才知道内容的折叠板
100
- - 没有 `turn/end` 的会话不显示这一行,也不会留空行
117
+ - 耗时是该轮从开始到结束的实际时长;没有 `turn/end` 的会话不显示轮次头
101
118
 
102
119
  ### 选择轮次
103
120
 
package/lib/kernel.js CHANGED
@@ -1737,6 +1737,93 @@ details.turn > summary.turn-head:focus-visible {
1737
1737
  .turn-body { margin: 2px 0 0; }
1738
1738
  .turn-body > *:first-child { margin-top: 0; }
1739
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
+
1740
1827
  @media (hover: hover) {
1741
1828
  details.process > summary:hover { color: var(--dsh-label-secondary); }
1742
1829
  }
@@ -2080,16 +2167,17 @@ function renderHtml(model, meta = {}) {
2080
2167
  stats.messages += 1;
2081
2168
  body.push(renderUserMessage(turn.user));
2082
2169
  }
2083
- const assistantBlocks = [];
2170
+ const turnBlocks = [];
2084
2171
  const turnModels = [];
2085
2172
  for (const msg of turn.assistants) {
2086
2173
  stats.messages += 1;
2087
2174
  stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
2088
2175
  if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
2089
- assistantBlocks.push(renderAssistantMessage(msg));
2176
+ const rendered = renderAssistantMessage(msg);
2177
+ if (rendered.trim()) turnBlocks.push(rendered);
2090
2178
  }
2091
- if (assistantBlocks.length) {
2092
- body.push(renderTurnArticle(turn, assistantBlocks, turnModels));
2179
+ if (turnBlocks.length) {
2180
+ body.push(renderTurnArticle(turn, turnBlocks, turnModels));
2093
2181
  }
2094
2182
  }
2095
2183
  if (!body.length) {
@@ -2200,28 +2288,54 @@ function renderTurnArticle(turn, blocks, models) {
2200
2288
  const metaParts = [status, duration ? `\u7528\u65F6 ${duration}` : ""].filter(Boolean);
2201
2289
  const metaHtml = metaParts.length ? `<span class="turn-meta">${esc(metaParts.join("\uFF0C"))}</span>` : "";
2202
2290
  const modelHtml = models.length ? `<span class="msg-model">${models.map(esc).join(" \xB7 ")}</span>` : "";
2203
- const head = metaHtml || modelHtml ? `<summary class="turn-head">${metaHtml}${modelHtml}</summary>
2204
- ` : "";
2205
- if (!head) {
2291
+ const inner = blocks.join("\n");
2292
+ if (!metaHtml && !modelHtml) {
2206
2293
  return `<article class="msg" data-role="assistant">
2207
- ${blocks.join("\n")}
2294
+ ${inner}
2208
2295
  </article>`;
2209
2296
  }
2210
2297
  return `<article class="msg" data-role="assistant">
2211
2298
  <details class="turn" open>
2212
- ${head}<div class="turn-body">
2213
- ${blocks.join("\n")}
2299
+ <summary class="turn-head">${metaHtml}${modelHtml}</summary>
2300
+ <div class="turn-body">
2301
+ ${inner}
2214
2302
  </div>
2215
2303
  </details>
2216
2304
  </article>`;
2217
2305
  }
2218
2306
  function renderAssistantMessage(msg) {
2219
2307
  const parts = [];
2308
+ let pendingTools = [];
2309
+ const flushTools = () => {
2310
+ if (!pendingTools.length) return;
2311
+ parts.push(renderToolGroup(pendingTools));
2312
+ pendingTools = [];
2313
+ };
2220
2314
  for (const block of msg.blocks) {
2315
+ if (block.kind === "tool") {
2316
+ pendingTools.push(block);
2317
+ continue;
2318
+ }
2319
+ flushTools();
2221
2320
  parts.push(renderBlock(block));
2222
2321
  }
2322
+ flushTools();
2223
2323
  return parts.filter(Boolean).join("\n");
2224
2324
  }
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
+ }
2225
2339
  function renderBlock(block) {
2226
2340
  switch (block.kind) {
2227
2341
  case "text":
@@ -2251,7 +2365,8 @@ function renderBlock(block) {
2251
2365
  function renderDetails(input) {
2252
2366
  const statusAttr = input.status ? ` data-status="${esc(input.status)}"` : "";
2253
2367
  const nameHtml = input.name ? `<span class="sum-name">${esc(input.name)}</span>` : "";
2254
- return `<details class="process" data-kind="${esc(input.kind)}">
2368
+ const openAttr = input.open ? " open" : "";
2369
+ return `<details class="process" data-kind="${esc(input.kind)}"${openAttr}>
2255
2370
  <summary><span class="sum-text">${esc(input.summary)}</span>${nameHtml}${statusDot(input.status)}</summary>
2256
2371
  <div class="process-body">
2257
2372
  ${input.body}
@@ -2286,12 +2401,13 @@ function renderTool(block) {
2286
2401
  body.push('<div class="trunc-note">\u4F1A\u8BDD\u5BFC\u51FA\u65F6\u8BE5\u8C03\u7528\u5C1A\u672A\u8FD4\u56DE</div>');
2287
2402
  }
2288
2403
  const stateText = block.status === "error" ? "\u5931\u8D25" : block.status === "pending" ? "\u672A\u5B8C\u6210" : "";
2289
- return `<details class="process" data-kind="tool" data-tool="${esc(block.name)}">
2290
- <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>
2291
- <div class="process-body">
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">
2292
2408
  ${body.join("\n")}
2293
2409
  </div>
2294
- </details>`;
2410
+ </div>`;
2295
2411
  }
2296
2412
  function toolSummary(block) {
2297
2413
  const fields = block.argsFields ?? [];
@@ -2448,7 +2564,7 @@ function filenameStamp(epochMs, timeZone) {
2448
2564
  }
2449
2565
 
2450
2566
  // src/host/index.ts
2451
- var VERSION = "0.3.1";
2567
+ var VERSION = "0.4.1";
2452
2568
  function exportSession(input) {
2453
2569
  const preset = input.preset ?? "conversation";
2454
2570
  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.3.1",
3
+ "version": "0.4.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",