dsh-share-html 0.5.0 → 0.6.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/lib/kernel.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  // src/host/model.ts
6
6
  function emptyDropped() {
7
- return { systemMessages: 0, injectedUserContext: 0, attachmentBytes: 0, unknownEvents: 0 };
7
+ return { systemMessages: 0, injectedUserContext: 0, attachmentBytes: 0, unknownEvents: 0, pendingToolCalls: 0 };
8
8
  }
9
9
 
10
10
  // src/host/events.ts
@@ -30,8 +30,15 @@ function project(events, options = {}) {
30
30
  let lastModel;
31
31
  const pendingCalls = /* @__PURE__ */ new Map();
32
32
  const callOwner = /* @__PURE__ */ new Map();
33
- const openTurn = (user) => {
34
- const turn = { index: turns.length + 1, user, assistants: [] };
33
+ const openTurn = (user, at) => {
34
+ const turn = {
35
+ index: turns.length + 1,
36
+ user,
37
+ assistants: [],
38
+ // 默认 open:只有真的收到 turn/end 才算结束
39
+ status: "open"
40
+ };
41
+ if (at !== void 0) turn.startedAt = at;
35
42
  turns.push(turn);
36
43
  current = turn;
37
44
  return turn;
@@ -44,7 +51,7 @@ function project(events, options = {}) {
44
51
  const existing = assistantSlot.get(key);
45
52
  if (existing) return existing;
46
53
  const turn = ensureTurn();
47
- const msg = { id: `a-${turnNo}-${stepNo}-${turn.assistants.length}`, role: "assistant", blocks: [] };
54
+ const msg = { id: `a-${turnNo}-${stepNo}-${turn.assistants.length}`, role: "assistant", blocks: [], step: stepNo };
48
55
  if (at !== void 0) msg.at = at;
49
56
  turn.assistants.push(msg);
50
57
  assistantSlot.set(key, msg);
@@ -82,7 +89,7 @@ function project(events, options = {}) {
82
89
  }
83
90
  const user = projectUserMessage(msg, at, dropped);
84
91
  if (!user) break;
85
- openTurn(user);
92
+ openTurn(user, at);
86
93
  clearStepSlots();
87
94
  break;
88
95
  }
@@ -111,6 +118,10 @@ function project(events, options = {}) {
111
118
  if (argsText !== void 0) block.args = argsText;
112
119
  const fields = argsToFields(rawArgs);
113
120
  if (fields.length) block.argsFields = fields;
121
+ if (name === "ask_user_question" || name === "request_user_input") {
122
+ const questions = parseAskedQuestions(rawArgs);
123
+ if (questions.length) block.questions = questions;
124
+ }
114
125
  owner.blocks.push(block);
115
126
  if (callId) {
116
127
  pendingCalls.set(callId, block);
@@ -130,14 +141,71 @@ function project(events, options = {}) {
130
141
  const text = partsToText(msg.content);
131
142
  const isError = msg.isError === true || asRecord(data)?.isError === true;
132
143
  applyResult(block, text, isError, options.maxToolResultChars);
144
+ if (block.questions?.length) {
145
+ const answers = parseAskedAnswers(text);
146
+ if (answers.length) block.answers = answers;
147
+ }
148
+ break;
149
+ }
150
+ // ---- 轮次与步骤边界 -----------------------------------------------
151
+ case "turn/start": {
152
+ if (current !== null && current.startedAt === void 0 && at !== void 0) current.startedAt = at;
133
153
  break;
134
154
  }
135
- // ---- 轮次与步骤边界(只影响归并) -----------------------------------
136
155
  case "turn/end": {
156
+ if (current !== null) {
157
+ current.status = "closed";
158
+ if (at !== void 0) current.endedAt = at;
159
+ const reasonKind = asString(asRecord(data.reason)?.kind);
160
+ current.endReason = reasonKind === "aborted" || reasonKind === "interrupted" || reasonKind === "error" ? reasonKind : "completed";
161
+ }
137
162
  current = null;
138
163
  clearStepSlots();
139
164
  break;
140
165
  }
166
+ // ---- 本轮文件改动摘要 -----------------------------------------------
167
+ // 事件本身只有 {turn},明细靠 options.changes 从 Host 取回。
168
+ // 挂到本轮最后一条 assistant 消息上,渲染在轮末(与 DSH 的位置一致)。
169
+ case "workspace/changes": {
170
+ const changes = options.changes?.get(raw.seq ?? -1);
171
+ if (!changes || !changes.files.length) break;
172
+ const turnNo = asNumber(data.turn);
173
+ const turn = turnNo !== void 0 ? turns.find((t) => t.index === turnNo) ?? current : current;
174
+ if (!turn) break;
175
+ const last = turn.assistants[turn.assistants.length - 1];
176
+ if (last) {
177
+ last.blocks.push(changes);
178
+ } else {
179
+ const host = { id: `changes-${turn.index}`, role: "assistant", blocks: [changes] };
180
+ if (at !== void 0) host.at = at;
181
+ turn.assistants.push(host);
182
+ }
183
+ break;
184
+ }
185
+ // ---- 交付文件卡片 -----------------------------------------------
186
+ // AI 生成/修改完文件后主动交付的东西。DSH 在轮末渲染成文件卡片,
187
+ // 带一句面向读者的说明。旧实现完全没处理这个事件,所以产出的文件不显示。
188
+ case "deliverables/presented": {
189
+ const list = Array.isArray(data.files) ? data.files : [];
190
+ const files = list.map((item) => {
191
+ const rec = asRecord(item);
192
+ const path = asString(rec?.path);
193
+ if (!path) return null;
194
+ const description = asString(rec?.description);
195
+ const file = { path };
196
+ if (description && description.trim()) file.description = description.trim();
197
+ return file;
198
+ }).filter((f) => f !== null);
199
+ if (!files.length) break;
200
+ const turn = current;
201
+ if (!turn) break;
202
+ turn.assistants.push({
203
+ id: `deliverables-${turn.index}-${raw.seq ?? 0}`,
204
+ role: "assistant",
205
+ blocks: [{ kind: "deliverables", files }]
206
+ });
207
+ break;
208
+ }
141
209
  case "step/end":
142
210
  break;
143
211
  default: {
@@ -145,6 +213,19 @@ function project(events, options = {}) {
145
213
  }
146
214
  }
147
215
  }
216
+ for (const turn of turns) {
217
+ for (let i = 0; i < turn.assistants.length; i += 1) {
218
+ const msg = turn.assistants[i];
219
+ if (!msg) continue;
220
+ const kept = msg.blocks.filter((b) => !(b.kind === "tool" && b.status === "pending" && b.questions === void 0));
221
+ if (kept.length === msg.blocks.length) continue;
222
+ dropped.pendingToolCalls += msg.blocks.length - kept.length;
223
+ turn.assistants[i] = { ...msg, blocks: kept };
224
+ }
225
+ }
226
+ for (const turn of turns) {
227
+ turn.answerStep = latestAnswerStep(turn);
228
+ }
148
229
  const model = {
149
230
  id: sessionId ?? "",
150
231
  title: options.title?.trim() || sessionTitle || DEFAULT_TITLE,
@@ -171,18 +252,28 @@ function projectUserMessage(msg, at, dropped) {
171
252
  }
172
253
  case "image": {
173
254
  dropped.attachmentBytes += 1;
174
- files.push({ name: asString(p.name) ?? "image", type: "IMG" });
255
+ const a = asRecord(p.attachment);
256
+ const meta = {
257
+ name: asString(a?.name) ?? asString(p.name) ?? "image",
258
+ type: "IMG"
259
+ };
260
+ const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
261
+ if (bytes !== void 0) meta.bytes = bytes;
262
+ files.push(meta);
175
263
  break;
176
264
  }
177
265
  case "file":
178
266
  case "attachment": {
179
- const name = asString(p.name) ?? asString(p.filename);
267
+ const a = asRecord(p.attachment);
268
+ const name = asString(a?.name) ?? asString(p.name) ?? asString(p.filename);
180
269
  if (!name) {
181
270
  dropped.attachmentBytes += 1;
182
271
  break;
183
272
  }
184
273
  const meta = { name, type: fileType(name) };
185
- const bytes = asNumber(p.bytes) ?? asNumber(p.size);
274
+ const mediaType = asString(a?.mediaType);
275
+ if (mediaType) meta.type = mediaType;
276
+ const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
186
277
  if (bytes !== void 0) meta.bytes = bytes;
187
278
  files.push(meta);
188
279
  break;
@@ -224,6 +315,20 @@ function collectAssistantBlocks(msg, target, dropped) {
224
315
  dropped.attachmentBytes += 1;
225
316
  break;
226
317
  }
318
+ case "file":
319
+ case "attachment": {
320
+ const a = asRecord(p.attachment);
321
+ const name = asString(a?.name) ?? asString(p.name) ?? asString(p.filename);
322
+ if (!name) {
323
+ dropped.attachmentBytes += 1;
324
+ break;
325
+ }
326
+ const meta = { name, type: asString(a?.mediaType) ?? fileType(name) };
327
+ const bytes = asNumber(a?.bytes) ?? asNumber(p.bytes) ?? asNumber(p.size);
328
+ if (bytes !== void 0) meta.bytes = bytes;
329
+ target.blocks.push({ kind: "files", files: [meta] });
330
+ break;
331
+ }
227
332
  case "tool-call":
228
333
  case "tool-call-delta":
229
334
  break;
@@ -254,6 +359,81 @@ function partsToText(content) {
254
359
  }
255
360
  return out.join("\n");
256
361
  }
362
+ function parseAskedQuestions(rawArgs) {
363
+ let parsed = rawArgs;
364
+ if (typeof rawArgs === "string") {
365
+ try {
366
+ parsed = JSON.parse(rawArgs);
367
+ } catch {
368
+ return [];
369
+ }
370
+ }
371
+ const rec = asRecord(parsed);
372
+ const list = Array.isArray(rec?.questions) ? rec.questions : null;
373
+ if (!list) return [];
374
+ const out = [];
375
+ for (const item of list) {
376
+ const q = asRecord(item);
377
+ if (!q) continue;
378
+ const text = asString(q.question);
379
+ if (!text) continue;
380
+ const question = { id: asString(q.id) ?? String(out.length), question: text };
381
+ const header = asString(q.header);
382
+ if (header) question.header = header;
383
+ if (Array.isArray(q.options)) {
384
+ const options = [];
385
+ for (const opt of q.options) {
386
+ const o = asRecord(opt);
387
+ const label = asString(o?.label);
388
+ if (!label) continue;
389
+ const description = asString(o?.description);
390
+ options.push(description ? { label, description } : { label });
391
+ }
392
+ if (options.length) question.options = options;
393
+ }
394
+ const multi = q.multi_select === true || q.multiSelect === true;
395
+ if (multi) question.multiSelect = true;
396
+ out.push(question);
397
+ }
398
+ return out;
399
+ }
400
+ function parseAskedAnswers(text) {
401
+ const trimmed = text.trim();
402
+ if (!trimmed) return [];
403
+ let parsed;
404
+ try {
405
+ parsed = JSON.parse(trimmed);
406
+ } catch {
407
+ return [];
408
+ }
409
+ const rec = asRecord(parsed);
410
+ const list = Array.isArray(rec?.answers) ? rec.answers : null;
411
+ if (!list) return [];
412
+ const out = [];
413
+ for (const item of list) {
414
+ const a = asRecord(item);
415
+ if (!a) continue;
416
+ const id = asString(a.id);
417
+ if (!id) continue;
418
+ const selected = Array.isArray(a.selected) ? a.selected.map((v) => asString(v)).filter((v) => typeof v === "string" && v !== "") : [];
419
+ const custom = asString(a.custom);
420
+ const answer = { id, selected };
421
+ if (custom && custom.trim()) answer.custom = custom;
422
+ out.push(answer);
423
+ }
424
+ return out;
425
+ }
426
+ function latestAnswerStep(turn) {
427
+ const last = turn.assistants[turn.assistants.length - 1];
428
+ if (!last || last.step === void 0) return null;
429
+ const hasReply = last.blocks.some((b) => {
430
+ if (b.kind === "text") return b.md.trim() !== "";
431
+ return b.kind === "reasoning" && b.text.trim() !== "";
432
+ });
433
+ if (!hasReply) return null;
434
+ if (last.blocks.some((b) => b.kind === "tool")) return null;
435
+ return last.step;
436
+ }
257
437
  function argsToFields(rawArgs) {
258
438
  let parsed = rawArgs;
259
439
  if (typeof rawArgs === "string") {
@@ -374,7 +554,9 @@ function presetInclude(preset) {
374
554
  files: false,
375
555
  fileBytes: false,
376
556
  deepResearch: false,
377
- modelMeta: false
557
+ modelMeta: false,
558
+ finalAnswerOnly: true,
559
+ foldProcess: false
378
560
  };
379
561
  case "process":
380
562
  return {
@@ -388,7 +570,9 @@ function presetInclude(preset) {
388
570
  files: true,
389
571
  fileBytes: false,
390
572
  deepResearch: true,
391
- modelMeta: false
573
+ modelMeta: false,
574
+ finalAnswerOnly: false,
575
+ foldProcess: false
392
576
  };
393
577
  case "full":
394
578
  return {
@@ -401,7 +585,9 @@ function presetInclude(preset) {
401
585
  files: true,
402
586
  fileBytes: false,
403
587
  deepResearch: true,
404
- modelMeta: true
588
+ modelMeta: true,
589
+ finalAnswerOnly: false,
590
+ foldProcess: true
405
591
  };
406
592
  }
407
593
  }
@@ -483,12 +669,25 @@ function pruneBlock(block, include, stats) {
483
669
  case "files":
484
670
  if (!include.files) return null;
485
671
  return { kind: "files", files: block.files };
672
+ case "deliverables":
673
+ return block;
674
+ case "changes":
675
+ return block;
486
676
  case "research":
487
677
  return include.deepResearch ? block : null;
488
678
  case "tool": {
679
+ if (block.questions?.length) {
680
+ const out2 = { kind: "tool", name: block.name, status: block.status };
681
+ if (block.callId) out2.callId = block.callId;
682
+ out2.questions = block.questions;
683
+ if (block.answers) out2.answers = block.answers;
684
+ return out2;
685
+ }
489
686
  if (!include.toolCalls) return null;
490
687
  const out = { kind: "tool", name: block.name, status: block.status };
491
688
  if (block.callId) out.callId = block.callId;
689
+ if (block.questions) out.questions = block.questions;
690
+ if (block.answers) out.answers = block.answers;
492
691
  if (block.args !== void 0) {
493
692
  const cut = clip(block.args, include.toolArgumentChars);
494
693
  out.args = cut.text;
@@ -668,6 +867,23 @@ function redactBlock(block, options, hits) {
668
867
  kind: "files",
669
868
  files: block.files.map((f) => ({ ...f, name: redactText(f.name, options, hits) }))
670
869
  };
870
+ case "deliverables":
871
+ return {
872
+ ...block,
873
+ files: block.files.map((f) => ({
874
+ path: redactText(f.path, options, hits),
875
+ ...f.description !== void 0 ? { description: redactText(f.description, options, hits) } : {}
876
+ }))
877
+ };
878
+ case "changes":
879
+ return {
880
+ ...block,
881
+ files: block.files.map((f) => ({
882
+ ...f,
883
+ path: redactText(f.path, options, hits),
884
+ display: redactText(f.display, options, hits)
885
+ }))
886
+ };
671
887
  case "tool": {
672
888
  const out = { ...block };
673
889
  if (block.args !== void 0) out.args = redactText(block.args, options, hits);
@@ -1448,7 +1664,7 @@ html { -webkit-text-size-adjust: 100%; }
1448
1664
 
1449
1665
  body {
1450
1666
  margin: 0;
1451
- background: var(--dsh-bg-base);
1667
+ background: var(--dsh-input-major);
1452
1668
  color: var(--dsh-label-primary);
1453
1669
  font-family: var(--dsh-font-text);
1454
1670
  font-size: 14px;
@@ -1632,6 +1848,583 @@ main { display: flex; flex-direction: column; gap: 28px; }
1632
1848
 
1633
1849
  .file-meta { color: var(--dsh-label-tertiary); font-size: 12px; line-height: 15px; }
1634
1850
 
1851
+ /* ---------- \u672C\u8F6E\u6587\u4EF6\u6539\u52A8\u6458\u8981\uFF08\u5BF9\u5E94 DSH \u7684\u300C\u5DF2\u7F16\u8F91 N \u4E2A\u6587\u4EF6\u300D\uFF09 ---------- */
1852
+
1853
+ details.changes {
1854
+ margin: 8px 0 2px;
1855
+ border: .5px solid var(--dsh-border-l2);
1856
+ border-radius: var(--dsh-radius-lg);
1857
+ background: var(--dsh-input-major);
1858
+ overflow: hidden;
1859
+ }
1860
+
1861
+ details.changes > summary {
1862
+ display: flex;
1863
+ align-items: center;
1864
+ gap: 8px;
1865
+ min-height: 40px;
1866
+ padding: 8px 14px;
1867
+ cursor: pointer;
1868
+ list-style: none;
1869
+ color: var(--dsh-label-primary);
1870
+ font-size: 13px;
1871
+ line-height: 20px;
1872
+ }
1873
+
1874
+ details.changes > summary::-webkit-details-marker { display: none; }
1875
+
1876
+ /* \u7528\u65CB\u8F6C\u7684\u4E09\u89D2\u66FF\u4EE3\u9ED8\u8BA4\u7BAD\u5934\uFF0C\u4FDD\u6301\u96F6\u811A\u672C\u3001\u7EAF CSS */
1877
+ details.changes > summary::before {
1878
+ content: "";
1879
+ flex: none;
1880
+ width: 0;
1881
+ height: 0;
1882
+ border-left: 5px solid var(--dsh-label-tertiary);
1883
+ border-top: 4px solid transparent;
1884
+ border-bottom: 4px solid transparent;
1885
+ transition: transform .15s ease;
1886
+ }
1887
+
1888
+ details.changes[open] > summary::before { transform: rotate(90deg); }
1889
+
1890
+ .chg-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1891
+
1892
+ .chg-added { color: var(--dsh-state-success-primary); font-variant-numeric: tabular-nums; }
1893
+ .chg-deleted { color: var(--dsh-state-error-primary); font-variant-numeric: tabular-nums; }
1894
+
1895
+ details.changes > summary .chg-added,
1896
+ details.changes > summary .chg-deleted { flex: none; font-size: 12px; }
1897
+
1898
+ .chg-body { border-top: .5px solid var(--dsh-border-l2); padding: 6px 0; }
1899
+
1900
+ .chg-list { margin: 0; padding: 0; list-style: none; }
1901
+
1902
+ .chg-row {
1903
+ display: flex;
1904
+ align-items: center;
1905
+ gap: 12px;
1906
+ padding: 3px 14px;
1907
+ font-size: 12px;
1908
+ line-height: 20px;
1909
+ }
1910
+
1911
+ .chg-path {
1912
+ flex: 1 1 auto;
1913
+ min-width: 0;
1914
+ overflow: hidden;
1915
+ text-overflow: ellipsis;
1916
+ white-space: nowrap;
1917
+ color: var(--dsh-label-secondary);
1918
+ font-family: var(--dsh-font-code);
1919
+ }
1920
+
1921
+ .chg-stat { flex: none; display: inline-flex; gap: 8px; font-variant-numeric: tabular-nums; }
1922
+
1923
+ .chg-note { color: var(--dsh-label-tertiary); }
1924
+
1925
+ .chg-more { color: var(--dsh-label-tertiary); font-style: italic; }
1926
+
1927
+ /* \u53EF\u70B9\u7684\u6587\u4EF6\u884C\uFF1A\u6574\u884C\u662F\u4E00\u6761\u6307\u5411\u62BD\u5C49\u7684\u94FE\u63A5 */
1928
+ .chg-row .chg-link,
1929
+ .chg-link {
1930
+ display: flex;
1931
+ align-items: center;
1932
+ gap: 12px;
1933
+ flex: 1 1 auto;
1934
+ min-width: 0;
1935
+ padding: 3px 0;
1936
+ color: inherit;
1937
+ text-decoration: none;
1938
+ border-radius: var(--dsh-radius-sm);
1939
+ transition: background 100ms ease;
1940
+ }
1941
+
1942
+ .chg-link:hover { background: var(--dsh-markdown-tag); }
1943
+
1944
+ .chg-link .chg-path {
1945
+ text-decoration: underline;
1946
+ text-decoration-color: transparent;
1947
+ text-underline-offset: 2px;
1948
+ transition: text-decoration-color 100ms ease;
1949
+ }
1950
+
1951
+ .chg-link:hover .chg-path { text-decoration-color: currentColor; }
1952
+
1953
+ /* \u6CA1\u6709 diff \u7684\u884C\u4E0D\u53EF\u70B9 */
1954
+ .chg-row[data-no-diff] .chg-path { text-decoration: none; }
1955
+
1956
+ .chg-note-line {
1957
+ margin: 8px 14px 0;
1958
+ color: var(--dsh-label-tertiary);
1959
+ font-size: 12px;
1960
+ line-height: 18px;
1961
+ }
1962
+
1963
+ /* ---------- diff \u53F3\u4FA7\u62BD\u5C49\uFF08\u7EAF CSS :target\uFF0C\u96F6 JS\uFF09 ---------- */
1964
+
1965
+ /*
1966
+ * \u70B9\u51FB\u6587\u4EF6\u884C \u2192 \u6D4F\u89C8\u5668\u8DF3\u5230 #diff-N-M \u2192 \u8BE5\u62BD\u5C49\u5339\u914D :target \u2192 \u6ED1\u5165\u3002
1967
+ * \u5173\u95ED\u6309\u94AE\u6307\u5411\u4E0D\u5B58\u5728\u7684\u951A\u70B9 #diff-closed\uFF0C\u70B9\u51FB\u540E :target \u5931\u914D \u2192 \u6ED1\u51FA\u3002
1968
+ * \u62BD\u5C49\u56FA\u5B9A\u5728\u53F3\u4FA7\u3001\u59CB\u7EC8\u5360\u636E\u6587\u6863\u4F46\u9ED8\u8BA4\u79FB\u51FA\u5C4F\u5E55\uFF0C\u6240\u4EE5\u4E0D\u5F71\u54CD\u6B63\u6587\u6392\u7248\u3002
1969
+ */
1970
+ .dif-drawer {
1971
+ position: fixed;
1972
+ top: 0;
1973
+ right: 0;
1974
+ z-index: 40;
1975
+ display: flex;
1976
+ flex-direction: column;
1977
+ width: min(560px, 92vw);
1978
+ height: 100vh;
1979
+ border-left: .5px solid var(--dsh-border-l2);
1980
+ background: var(--dsh-bg-base);
1981
+ box-shadow: -8px 0 24px rgba(0, 0, 0, .08);
1982
+ transform: translateX(102%);
1983
+ visibility: hidden;
1984
+ transition: transform .18s ease, visibility .18s ease;
1985
+ }
1986
+
1987
+ .dif-drawer:target {
1988
+ transform: translateX(0);
1989
+ visibility: visible;
1990
+ }
1991
+
1992
+ .dif-head {
1993
+ display: flex;
1994
+ align-items: center;
1995
+ gap: 10px;
1996
+ flex: none;
1997
+ padding: 12px 16px;
1998
+ border-bottom: .5px solid var(--dsh-border-l2);
1999
+ }
2000
+
2001
+ .dif-path {
2002
+ flex: 1 1 auto;
2003
+ min-width: 0;
2004
+ overflow: hidden;
2005
+ text-overflow: ellipsis;
2006
+ white-space: nowrap;
2007
+ color: var(--dsh-label-primary);
2008
+ font-family: var(--dsh-font-code);
2009
+ font-size: 13px;
2010
+ }
2011
+
2012
+ .dif-stat { flex: none; display: inline-flex; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
2013
+
2014
+ .dif-close {
2015
+ flex: none;
2016
+ display: grid;
2017
+ place-items: center;
2018
+ width: 24px;
2019
+ height: 24px;
2020
+ border-radius: var(--dsh-radius-sm);
2021
+ color: var(--dsh-label-tertiary);
2022
+ font-size: 18px;
2023
+ line-height: 1;
2024
+ text-decoration: none;
2025
+ }
2026
+
2027
+ .dif-close:hover { background: var(--dsh-markdown-tag); color: var(--dsh-label-primary); }
2028
+
2029
+ .dif-body {
2030
+ flex: 1 1 auto;
2031
+ min-height: 0;
2032
+ overflow: auto;
2033
+ padding: 8px 0 24px;
2034
+ }
2035
+
2036
+ .dif-empty {
2037
+ margin: 12px 16px;
2038
+ color: var(--dsh-label-tertiary);
2039
+ font-size: 13px;
2040
+ line-height: 20px;
2041
+ }
2042
+
2043
+ .dif-hunk {
2044
+ border-collapse: collapse;
2045
+ width: 100%;
2046
+ font-family: var(--dsh-font-code);
2047
+ font-size: 12px;
2048
+ line-height: 18px;
2049
+ }
2050
+
2051
+ .dif-no {
2052
+ width: 1%;
2053
+ padding: 0 8px;
2054
+ color: var(--dsh-label-caption);
2055
+ text-align: right;
2056
+ font-variant-numeric: tabular-nums;
2057
+ white-space: nowrap;
2058
+ vertical-align: top;
2059
+ user-select: none;
2060
+ }
2061
+
2062
+ .dif-text {
2063
+ padding: 0 16px 0 8px;
2064
+ white-space: pre-wrap;
2065
+ overflow-wrap: anywhere;
2066
+ color: var(--dsh-label-primary);
2067
+ vertical-align: top;
2068
+ }
2069
+
2070
+ .dif-mark { display: inline-block; width: 1ch; color: inherit; opacity: .5; }
2071
+
2072
+ /* \u589E\u5220\u884C\u7684\u5E95\u8272\uFF0C\u6DF1\u6D45\u4E3B\u9898\u90FD\u53EF\u7528 color-mix */
2073
+ .dif-line[data-kind="add"] { background: color-mix(in srgb, var(--dsh-state-success-primary) 12%, transparent); }
2074
+ .dif-line[data-kind="del"] { background: color-mix(in srgb, var(--dsh-state-error-primary) 12%, transparent); }
2075
+ .dif-line[data-kind="ctx"] { color: var(--dsh-label-secondary); }
2076
+
2077
+ @media (prefers-reduced-motion: reduce) {
2078
+ .dif-drawer { transition: none; }
2079
+ }
2080
+
2081
+ /* \u6253\u5370\u65F6\u62BD\u5C49\u4E0D\u5360\u4F4D */
2082
+ @media print {
2083
+ .dif-drawer { display: none; }
2084
+ }
2085
+
2086
+
2087
+ /* ---------- \u8FD0\u884C\u4E2D\u8F6E\u6B21\u7684\u6A2A\u5E45 ---------- */
2088
+
2089
+ /*
2090
+ * \u5BFC\u51FA\u4EA7\u7269\u4EE5\u300C\u5DF2\u5B8C\u6210\u300D\u6001\u4E3A\u57FA\u51C6\uFF1B\u4F1A\u8BDD\u4ECD\u5728\u8DD1\u65F6\u8FD9\u4E00\u8F6E\u6CA1\u6709 turn/end\uFF0C
2091
+ * \u4E0D\u80FD\u7ED9\u300C\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 X\u300D\uFF0C\u6539\u4E3A\u660E\u786E\u6807\u6CE8\u8FD9\u662F\u5FEB\u7167\u3002
2092
+ */
2093
+ .turn-open {
2094
+ display: flex;
2095
+ align-items: center;
2096
+ gap: 8px;
2097
+ margin: 2px 0 6px;
2098
+ padding: 6px 12px;
2099
+ border: .5px solid var(--dsh-border-l2);
2100
+ border-radius: var(--dsh-radius-sm);
2101
+ background: var(--dsh-markdown-tag);
2102
+ color: var(--dsh-label-tertiary);
2103
+ font-size: 13px;
2104
+ line-height: 20px;
2105
+ }
2106
+
2107
+ .open-dot {
2108
+ flex: none;
2109
+ width: 7px;
2110
+ height: 7px;
2111
+ border-radius: 50%;
2112
+ background: var(--dsh-state-warn-primary);
2113
+ }
2114
+
2115
+ .open-text { color: var(--dsh-label-secondary); }
2116
+
2117
+ .open-elapsed { font-variant-numeric: tabular-nums; }
2118
+
2119
+ .open-note { margin-left: auto; font-size: 12px; }
2120
+
2121
+ /* ---------- \u63D0\u95EE\uFF08ask_user_question\uFF09 ---------- */
2122
+
2123
+ /*
2124
+ * \u7ED3\u6784\u5BF9\u9F50 DSH \u7684 QuestionToolRow\uFF1A
2125
+ * \u884C\uFF1A\u56FE\u6807 16px + \u300C\u63D0\u95EE\u300D13/24 + 2\xD72 \u5706\u70B9 + \u6458\u8981 13/24 \u622A\u65AD + \u7BAD\u5934
2126
+ * \u4F53\uFF1AAskQuestionCard\uFF0Cdt \u95EE\u9898 tertiary \u7070 / dd \u56DE\u7B54 primary
2127
+ * \u884C\u4E0E\u5176\u5B83\u5DE5\u5177\u884C\u540C\u4E00\u5957\u89C6\u89C9\uFF08\u5C0F\u578B\u7070\u8272\u53EF\u70B9\u51FB\u6587\u5B57\uFF09\uFF0C\u9ED8\u8BA4\u6536\u8D77\u3002
2128
+ */
2129
+
2130
+ .ask-row { display: flex; flex-direction: column; }
2131
+
2132
+ .ask-disclosure { margin: 2px 0; }
2133
+
2134
+ .ask-disclosure > summary {
2135
+ display: flex;
2136
+ align-items: center;
2137
+ gap: 6px;
2138
+ min-height: 28px;
2139
+ padding: 2px 0;
2140
+ list-style: none;
2141
+ cursor: pointer;
2142
+ color: var(--dsh-label-tertiary);
2143
+ font-size: 13px;
2144
+ line-height: 24px;
2145
+ transition: color 100ms ease;
2146
+ }
2147
+
2148
+ .ask-disclosure > summary::-webkit-details-marker { display: none; }
2149
+ .ask-disclosure > summary:hover { color: var(--dsh-label-secondary); }
2150
+
2151
+ /* \u95EE\u53F7\u56FE\u6807\uFF1ADSH \u7528 IconQuestionOutlineRegular\uFF0C\u9759\u6001\u4EA7\u7269\u7528\u7EAF CSS \u753B */
2152
+ .ask-icon {
2153
+ position: relative;
2154
+ flex: none;
2155
+ width: 16px;
2156
+ height: 16px;
2157
+ border: 1px solid currentColor;
2158
+ border-radius: 50%;
2159
+ opacity: .75;
2160
+ }
2161
+
2162
+ .ask-icon::after {
2163
+ content: "?";
2164
+ position: absolute;
2165
+ inset: 0;
2166
+ display: grid;
2167
+ place-items: center;
2168
+ font-size: 10px;
2169
+ line-height: 1;
2170
+ }
2171
+
2172
+ .ask-title { flex: none; font-weight: 400; }
2173
+
2174
+ /* 2\xD72 \u5706\u70B9\u5206\u9694\u7B26\uFF1ADSH \u7684 .sep */
2175
+ .ask-sep {
2176
+ flex: none;
2177
+ width: 2px;
2178
+ height: 2px;
2179
+ margin: 0 8px 0 -2px;
2180
+ border-radius: 1px;
2181
+ background: var(--dsh-label-caption);
2182
+ }
2183
+
2184
+ .ask-summary {
2185
+ flex: 1 1 auto;
2186
+ min-width: 0;
2187
+ overflow: hidden;
2188
+ text-overflow: ellipsis;
2189
+ white-space: nowrap;
2190
+ font-size: 13px;
2191
+ line-height: 24px;
2192
+ }
2193
+
2194
+ .ask-chevron {
2195
+ flex: none;
2196
+ width: 0;
2197
+ height: 0;
2198
+ margin-left: 4px;
2199
+ border-top: 4px solid transparent;
2200
+ border-bottom: 4px solid transparent;
2201
+ border-left: 5px solid currentColor;
2202
+ opacity: .7;
2203
+ transition: transform 100ms ease;
2204
+ }
2205
+
2206
+ .ask-disclosure[open] > summary .ask-chevron { transform: rotate(90deg); }
2207
+
2208
+ /* ---- AskQuestionCard ---- */
2209
+
2210
+ .ask-body { padding: 4px 0 2px; }
2211
+
2212
+ .ask-card {
2213
+ display: flex;
2214
+ flex-direction: column;
2215
+ gap: 16px;
2216
+ max-height: 360px;
2217
+ margin: 4px 0 4px 4px;
2218
+ padding: 16px 20px;
2219
+ overflow-y: auto;
2220
+ border: .5px solid var(--dsh-border-l1);
2221
+ border-radius: var(--dsh-radius-lg);
2222
+ background: var(--dsh-input-major);
2223
+ }
2224
+
2225
+ .ask-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
2226
+
2227
+ .ask-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
2228
+
2229
+ .ask-dt,
2230
+ .ask-dd { margin: 0; }
2231
+
2232
+ .ask-header {
2233
+ display: block;
2234
+ color: var(--dsh-label-tertiary);
2235
+ font-size: 14px;
2236
+ line-height: 24px;
2237
+ }
2238
+
2239
+ /* \u95EE\u9898\uFF1Atertiary \u7070\uFF0C\u4E0E\u56DE\u7B54\u5F62\u6210\u5C42\u7EA7\u5DEE */
2240
+ .ask-question {
2241
+ display: block;
2242
+ margin: 0;
2243
+ color: var(--dsh-label-tertiary);
2244
+ font-size: 14px;
2245
+ line-height: 24px;
2246
+ white-space: pre-wrap;
2247
+ overflow-wrap: anywhere;
2248
+ }
2249
+
2250
+ /* \u56DE\u7B54\uFF1Aprimary \u767D\uFF0C\u4E00\u6574\u884C */
2251
+ .ask-dd {
2252
+ color: var(--dsh-label-primary);
2253
+ font-size: 14px;
2254
+ line-height: 24px;
2255
+ white-space: pre-wrap;
2256
+ overflow-wrap: anywhere;
2257
+ }
2258
+
2259
+ .ask-answer-line { display: block; }
2260
+
2261
+ .ask-skipped { color: var(--dsh-label-tertiary); }
2262
+
2263
+ /* \u672A\u56DE\u7B54\u6001\uFF1A\u4E00\u53E5\u7ED3\u8BBA + \u95EE\u9898\u5217\u8868 */
2264
+ .ask-verdict {
2265
+ margin: 0;
2266
+ color: var(--dsh-label-primary);
2267
+ font-size: 14px;
2268
+ line-height: 24px;
2269
+ }
2270
+
2271
+ .ask-question-list {
2272
+ display: flex;
2273
+ flex-direction: column;
2274
+ gap: 8px;
2275
+ margin: 0;
2276
+ padding-left: 20px;
2277
+ color: var(--dsh-label-tertiary);
2278
+ font-size: 14px;
2279
+ line-height: 24px;
2280
+ }
2281
+
2282
+ .ask-list-item { white-space: pre-wrap; overflow-wrap: anywhere; }
2283
+
2284
+ /* ---------- \u4E00\u8F6E\u7684\u8FC7\u7A0B\u6298\u53E0\uFF08\u300C\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 2\u520626\u79D2\u300D\uFF09 ---------- */
2285
+
2286
+ /*
2287
+ * \u7ED3\u6784\uFF08\u5BF9\u9F50 DSH \u7684\u5E73\u7EA7\u6A21\u578B\uFF09\uFF1A
2288
+ *
2289
+ * details.turn-process \u6298\u53E0\u5934\uFF0C\u72EC\u7ACB\u5757
2290
+ * div.turn-flow \u5185\u5BB9\u533A\uFF0C\u662F\u6298\u53E0\u5934\u7684\u76F8\u90BB\u5144\u5F1F
2291
+ * div.turn-run \u8FC7\u7A0B\u7EC4 \u2014\u2014 \u53D7\u6298\u53E0\u5934\u63A7\u5236
2292
+ * div.turn-reply \u4E2D\u95F4\u56DE\u590D \u2014\u2014 \u6C38\u8FDC\u53EF\u89C1
2293
+ * div.turn-run \u8FC7\u7A0B\u7EC4
2294
+ * div.turn-answer \u6700\u7EC8\u7B54\u6848 \u2014\u2014 \u6C38\u8FDC\u53EF\u89C1
2295
+ *
2296
+ * \u4E0D\u8981\u7ED9 details \u8BBE display\uFF08\u4F1A\u7834\u574F\u6536\u8D77\u65F6\u7684\u5185\u5BB9\u9690\u85CF\uFF09\uFF1B
2297
+ * \u4E5F\u4E0D\u8981\u8BA9\u5B83\u5305\u88F9\u5185\u5BB9\u533A\uFF08\u90A3\u4F1A\u628A\u56DE\u590D\u4E00\u8D77\u85CF\u6389\uFF09\u3002
2298
+ */
2299
+ details.turn-process {
2300
+ margin: 2px 0 0;
2301
+ }
2302
+
2303
+ details.turn-process > summary {
2304
+ display: flex;
2305
+ align-items: center;
2306
+ gap: 6px;
2307
+ min-height: 33px;
2308
+ padding: 0 0 8px;
2309
+ list-style: none;
2310
+ cursor: pointer;
2311
+ color: var(--dsh-label-tertiary);
2312
+ font-size: 14px;
2313
+ line-height: 24px;
2314
+ border-bottom: .5px solid var(--dsh-border-l2);
2315
+ transition: color 100ms ease;
2316
+ }
2317
+
2318
+ details.turn-process > summary::-webkit-details-marker { display: none; }
2319
+ details.turn-process > summary:hover { color: var(--dsh-label-secondary); }
2320
+
2321
+ .tp-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2322
+
2323
+ .tp-num {
2324
+ font-family: var(--dsh-font-code);
2325
+ font-variant-numeric: tabular-nums;
2326
+ }
2327
+
2328
+ .tp-chevron {
2329
+ flex: none;
2330
+ width: 0;
2331
+ height: 0;
2332
+ margin-left: 4px;
2333
+ border-top: 4px solid transparent;
2334
+ border-bottom: 4px solid transparent;
2335
+ border-left: 5px solid currentColor;
2336
+ transition: transform 100ms ease;
2337
+ }
2338
+
2339
+ details.turn-process[open] > summary .tp-chevron { transform: rotate(90deg); }
2340
+
2341
+ .turn-flow {
2342
+ display: flex;
2343
+ flex-direction: column;
2344
+ gap: 4px;
2345
+ padding-top: 8px;
2346
+ }
2347
+
2348
+ .turn-run {
2349
+ display: flex;
2350
+ flex-direction: column;
2351
+ gap: 4px;
2352
+ }
2353
+
2354
+ /*
2355
+ * \u6536\u8D77\u65F6\u53EA\u9690\u85CF\u8FC7\u7A0B\u7EC4\u3002\u9009\u62E9\u5668\u8981\u6C42 details \u4E0E .turn-flow \u662F\u76F8\u90BB\u5144\u5F1F\uFF0C
2356
+ * \u4E0E HTML \u7ED3\u6784\u4E00\u4E00\u5BF9\u5E94\uFF1B.turn-reply / .turn-answer \u4E0D\u5728\u5339\u914D\u8303\u56F4\uFF0C
2357
+ * \u6240\u4EE5\u56DE\u590D\u4E0E\u6700\u7EC8\u7B54\u6848\u6C38\u8FDC\u53EF\u89C1 \u2014\u2014 \u8FD9\u6B63\u662F DSH \u7684 foldedReplies: 'all'\u3002
2358
+ */
2359
+ details.turn-process:not([open]) + .turn-flow > .turn-run { display: none; }
2360
+
2361
+ .turn-reply,
2362
+ .turn-answer,
2363
+ .turn-ask {
2364
+ display: flex;
2365
+ flex-direction: column;
2366
+ gap: 4px;
2367
+ }
2368
+
2369
+ /* ---------- \u4EA4\u4ED8\u6587\u4EF6\u5361\u7247\uFF08deliverables/presented\uFF09 ---------- */
2370
+
2371
+ .deliverables {
2372
+ display: flex;
2373
+ flex-direction: column;
2374
+ gap: 8px;
2375
+ margin: 8px 0 2px;
2376
+ }
2377
+
2378
+ /* \u5BF9\u9F50 DSH \u7684 PresentedFileCard\uFF1A60px \u9AD8\u3001\u56FE\u6807 40px\u3001\u5706\u89D2 16px */
2379
+ .dl-card {
2380
+ display: flex;
2381
+ align-items: center;
2382
+ gap: 10px;
2383
+ min-width: 0;
2384
+ height: 60px;
2385
+ padding: 8px 10px;
2386
+ border: .5px solid var(--dsh-border-l1);
2387
+ border-radius: var(--dsh-radius-lg);
2388
+ background: var(--dsh-bg-base);
2389
+ }
2390
+
2391
+ .dl-icon {
2392
+ flex: none;
2393
+ display: grid;
2394
+ place-items: center;
2395
+ width: 40px;
2396
+ height: 40px;
2397
+ border: .5px solid var(--dsh-border-l1);
2398
+ border-radius: 10px;
2399
+ background: var(--dsh-markdown-tag);
2400
+ color: var(--dsh-label-secondary);
2401
+ font-family: var(--dsh-font-code);
2402
+ font-size: 10px;
2403
+ font-weight: 600;
2404
+ letter-spacing: -.02em;
2405
+ }
2406
+
2407
+ .dl-body { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
2408
+
2409
+ .dl-name {
2410
+ overflow: hidden;
2411
+ text-overflow: ellipsis;
2412
+ white-space: nowrap;
2413
+ color: var(--dsh-label-primary);
2414
+ font-size: 13px;
2415
+ font-weight: 500;
2416
+ line-height: 20px;
2417
+ }
2418
+
2419
+ .dl-desc {
2420
+ overflow: hidden;
2421
+ text-overflow: ellipsis;
2422
+ white-space: nowrap;
2423
+ color: var(--dsh-label-tertiary);
2424
+ font-size: 10px;
2425
+ line-height: 16px;
2426
+ }
2427
+
1635
2428
  /* ---------- \u6298\u53E0\u5757\uFF08\u601D\u8003 / \u5DE5\u5177 / \u68C0\u7D22 / \u6DF1\u7814\uFF09 ---------- */
1636
2429
 
1637
2430
  details.process {
@@ -2012,21 +2805,100 @@ function renderHtml(model, meta = {}) {
2012
2805
  stats.messages += 1;
2013
2806
  body.push(renderUserMessage(turn.user));
2014
2807
  }
2015
- const assistantBlocks = [];
2016
2808
  const turnModels = [];
2017
2809
  for (const msg of turn.assistants) {
2018
2810
  stats.messages += 1;
2019
2811
  stats.toolCalls += msg.blocks.filter((b) => b.kind === "tool").length;
2020
2812
  if (msg.model && !turnModels.includes(msg.model)) turnModels.push(msg.model);
2021
- assistantBlocks.push(renderAssistantMessage(msg));
2022
2813
  }
2023
- if (assistantBlocks.length) {
2024
- const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
2814
+ if (!turn.assistants.length) continue;
2815
+ const answerStep = turn.answerStep ?? null;
2816
+ const rows = [];
2817
+ const tailRows = [];
2818
+ let run = null;
2819
+ const ensureRun = () => run ??= { parts: [], tools: [] };
2820
+ const flushRun = () => {
2821
+ if (run === null) return;
2822
+ const { parts, tools } = run;
2823
+ run = null;
2824
+ if (!parts.length && !tools.length) return;
2825
+ rows.push({ kind: "process", html: parts.join("\n"), tools });
2826
+ };
2827
+ for (const msg of turn.assistants) {
2828
+ const isAnswer = answerStep !== null && msg.step !== void 0 && msg.step >= answerStep;
2829
+ const replies = msg.blocks.filter((b) => b.kind === "text" && b.md.trim() !== "");
2830
+ const thinks = msg.blocks.filter((b) => b.kind === "reasoning" && b.text.trim() !== "");
2831
+ const tools = msg.blocks.filter((b) => b.kind === "tool");
2832
+ const changeBlocks = msg.blocks.filter((b) => b.kind === "changes");
2833
+ const deliverableBlocks = msg.blocks.filter(
2834
+ (b) => b.kind === "deliverables"
2835
+ );
2836
+ const others = msg.blocks.filter(
2837
+ (b) => b.kind !== "text" && b.kind !== "reasoning" && b.kind !== "tool" && b.kind !== "changes" && b.kind !== "deliverables"
2838
+ );
2839
+ const asks = tools.filter((t) => t.questions !== void 0);
2840
+ const plainTools = tools.filter((t) => t.questions === void 0);
2841
+ for (const ask of asks) {
2842
+ flushRun();
2843
+ rows.push({ kind: "ask", html: renderTool(ask) });
2844
+ }
2845
+ if (thinks.length || others.length) {
2846
+ const r = ensureRun();
2847
+ for (const b of thinks) r.parts.push(renderBlock(b));
2848
+ for (const b of others) r.parts.push(renderBlock(b));
2849
+ }
2850
+ if (plainTools.length) ensureRun().tools.push(...plainTools);
2851
+ if (replies.length) {
2852
+ flushRun();
2853
+ const html2 = replies.map((b) => renderBlock(b)).join("\n");
2854
+ rows.push({ kind: isAnswer ? "answer" : "reply", html: html2 });
2855
+ } else if (isAnswer) {
2856
+ flushRun();
2857
+ }
2858
+ for (const cb of changeBlocks) tailRows.push({ kind: "changes", html: renderBlock(cb) });
2859
+ for (const db of deliverableBlocks) tailRows.push({ kind: "changes", html: renderBlock(db) });
2860
+ }
2861
+ flushRun();
2862
+ rows.push(...tailRows);
2863
+ const visibleRows = meta.finalAnswerOnly === true ? rows.filter((r) => r.kind === "answer" || r.kind === "ask" || r.kind === "changes") : rows;
2864
+ const processRows = visibleRows.filter((r) => r.kind === "process");
2865
+ const toolCount = processRows.reduce((n, r) => n + r.tools.length, 0);
2866
+ const hasProcess = processRows.length > 0;
2867
+ const head = turnModels.length ? `<header class="msg-head"><span class="msg-model">${turnModels.map(esc).join(" \xB7 ")}</span></header>
2025
2868
  ` : "";
2026
- body.push(`<article class="msg" data-role="assistant">
2027
- ${head}${assistantBlocks.join("\n")}
2869
+ const attrs = turn.status === "open" ? ' data-status="open"' : "";
2870
+ const banner = turn.status === "open" ? renderOpenBanner(turn, meta.exportedAt) : "";
2871
+ const renderRun = (row) => {
2872
+ const toolHtml = row.tools.map((t) => renderTool(t)).join("\n");
2873
+ const inner = [row.html, toolHtml].filter(Boolean).join("\n");
2874
+ return inner ? `<div class="turn-run">${inner}</div>` : "";
2875
+ };
2876
+ const renderRow = (row) => {
2877
+ if (row.kind === "process") return renderRun(row);
2878
+ const cls = row.kind === "answer" ? "turn-answer" : row.kind === "ask" ? "turn-ask" : row.kind === "changes" ? "turn-changes" : "turn-reply";
2879
+ return `<div class="${cls}">${row.html}</div>`;
2880
+ };
2881
+ if (meta.foldProcess !== true) {
2882
+ const flat = visibleRows.map(renderRow).filter(Boolean).join("\n");
2883
+ if (flat) body.push(`<article class="msg" data-role="assistant"${attrs}>
2884
+ ${head}${banner}${flat}
2885
+ </article>`);
2886
+ continue;
2887
+ }
2888
+ if (!hasProcess) {
2889
+ const only = visibleRows.map(renderRow).filter(Boolean).join("\n");
2890
+ if (only) body.push(`<article class="msg" data-role="assistant"${attrs}>
2891
+ ${head}${banner}${only}
2028
2892
  </article>`);
2893
+ continue;
2029
2894
  }
2895
+ const flow = visibleRows.map((row) => row.kind === "process" ? renderRun(row) : renderRow(row)).filter(Boolean).join("\n");
2896
+ body.push(`<article class="msg" data-role="assistant"${attrs}>
2897
+ ${head}${banner}${renderTurnProcessHeader(turn, toolCount, processRows.length)}
2898
+ <div class="turn-flow">
2899
+ ${flow}
2900
+ </div>
2901
+ </article>`);
2030
2902
  }
2031
2903
  if (!body.length) {
2032
2904
  body.push('<p class="empty-note">\u8FD9\u4E2A\u4F1A\u8BDD\u5728\u6240\u9009\u7C92\u5EA6\u4E0B\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684\u5185\u5BB9\u3002</p>');
@@ -2114,6 +2986,56 @@ function buildFooter(input) {
2114
2986
  lines.push(`<p>\u7EDF\u8BA1\uFF1A${esc(String(stats.turns))} \u8F6E / ${esc(String(stats.messages))} \u6761\u6D88\u606F / ${esc(String(stats.toolCalls))} \u6B21\u5DE5\u5177\u8C03\u7528\u3002</p>`);
2115
2987
  return lines.join("\n");
2116
2988
  }
2989
+ function renderOpenBanner(turn, now) {
2990
+ const elapsed = turn.startedAt !== void 0 && now !== void 0 && now > turn.startedAt ? formatElapsed(now - turn.startedAt) : void 0;
2991
+ const time = elapsed === void 0 ? "" : `<span class="open-elapsed">\u5DF2\u7528 ${esc(elapsed)}</span>`;
2992
+ return `<div class="turn-open" role="note"><span class="open-dot"></span><span class="open-text">\u8FDB\u884C\u4E2D</span>${time}<span class="open-note">\u5BFC\u51FA\u65F6\u7684\u5FEB\u7167</span></div>
2993
+ `;
2994
+ }
2995
+ function formatElapsed(ms) {
2996
+ const total = Math.max(0, Math.floor(ms / 1e3));
2997
+ const minutes = Math.floor(total / 60);
2998
+ const seconds = total % 60;
2999
+ return minutes > 0 ? `${minutes} \u5206 ${seconds} \u79D2` : `${seconds} \u79D2`;
3000
+ }
3001
+ function renderTurnProcessHeader(turn, toolCount, runCount) {
3002
+ const stopped = turn.endReason === "aborted" || turn.endReason === "interrupted";
3003
+ const failed = turn.endReason === "error";
3004
+ const elapsed = turn.startedAt !== void 0 && turn.endedAt !== void 0 ? Math.max(1e3, turn.endedAt - turn.startedAt) : void 0;
3005
+ const duration = elapsed === void 0 || stopped || failed ? void 0 : formatDuration(elapsed);
3006
+ const label = [];
3007
+ if (stopped) label.push("\u5DF2\u4E2D\u65AD");
3008
+ else if (failed) label.push("\u51FA\u9519");
3009
+ else if (duration === void 0) label.push("\u5DF2\u5B8C\u6210");
3010
+ else {
3011
+ label.push("\u5DF2\u5B8C\u6210\uFF0C\u7528\u65F6 ");
3012
+ for (const part of duration) {
3013
+ label.push(part.numeric ? `<span class="tp-num">${esc(part.text)}</span>` : esc(part.text));
3014
+ }
3015
+ }
3016
+ const forced = turn.status === "open" || stopped || failed;
3017
+ const openAttr = forced ? " open" : "";
3018
+ const status = stopped ? "stopped" : failed ? "failed" : turn.status === "open" ? "open" : "completed";
3019
+ const dataAttrs = [
3020
+ ` data-status="${status}"`,
3021
+ toolCount > 0 ? ` data-tools="${toolCount}"` : "",
3022
+ runCount > 1 ? ` data-runs="${runCount}"` : ""
3023
+ ].join("");
3024
+ return `<details class="turn-process"${dataAttrs}${openAttr}>
3025
+ <summary><span class="tp-label">${label.join("")}</span><span class="tp-chevron"></span></summary>
3026
+ </details>`;
3027
+ }
3028
+ function formatDuration(ms) {
3029
+ const total = Math.max(0, Math.floor(ms / 1e3));
3030
+ const hours = Math.floor(total / 3600);
3031
+ const minutes = Math.floor(total / 60) % 60;
3032
+ const seconds = total % 60;
3033
+ const parts = [];
3034
+ if (hours > 0) parts.push({ text: String(hours), numeric: true }, { text: "\u5C0F\u65F6", numeric: false });
3035
+ if (total >= 60) parts.push({ text: String(minutes), numeric: true }, { text: "\u5206", numeric: false });
3036
+ parts.push({ text: String(seconds), numeric: true }, { text: "\u79D2", numeric: false });
3037
+ return parts;
3038
+ }
2117
3039
  function renderUserMessage(msg) {
2118
3040
  const parts = [];
2119
3041
  const fileBlocks = msg.blocks.filter((b) => b.kind === "files");
@@ -2130,13 +3052,6 @@ function renderUserMessage(msg) {
2130
3052
  ${parts.join("\n")}
2131
3053
  </article>`;
2132
3054
  }
2133
- function renderAssistantMessage(msg) {
2134
- const parts = [];
2135
- for (const block of msg.blocks) {
2136
- parts.push(renderBlock(block));
2137
- }
2138
- return parts.filter(Boolean).join("\n");
2139
- }
2140
3055
  function renderBlock(block) {
2141
3056
  switch (block.kind) {
2142
3057
  case "text":
@@ -2161,6 +3076,10 @@ function renderBlock(block) {
2161
3076
  });
2162
3077
  case "files":
2163
3078
  return renderFiles(block.files);
3079
+ case "changes":
3080
+ return renderChanges(block);
3081
+ case "deliverables":
3082
+ return renderDeliverables(block);
2164
3083
  }
2165
3084
  }
2166
3085
  function renderDetails(input) {
@@ -2180,6 +3099,7 @@ function statusDot(status) {
2180
3099
  return "";
2181
3100
  }
2182
3101
  function renderTool(block) {
3102
+ if (block.questions?.length) return renderAskedQuestions(block);
2183
3103
  const summaryText = toolSummary(block);
2184
3104
  const body = [];
2185
3105
  if (block.argsFields?.length) {
@@ -2208,6 +3128,41 @@ ${body.join("\n")}
2208
3128
  </div>
2209
3129
  </details>`;
2210
3130
  }
3131
+ function renderAskedQuestions(block) {
3132
+ const questions = block.questions ?? [];
3133
+ const answers = new Map((block.answers ?? []).map((a) => [a.id, a]));
3134
+ const head = questions[0];
3135
+ const summaryText = head === void 0 ? "" : questions.length === 1 ? head.question ?? "" : head.header ?? head.question ?? "";
3136
+ const interrupted = block.status === "error";
3137
+ const pending = block.answers === void 0 && !interrupted;
3138
+ const state = interrupted ? "interrupted" : pending ? "pending" : "answered";
3139
+ const items = questions.map((q) => {
3140
+ const a = answers.get(q.id);
3141
+ const chosen = a === void 0 ? [] : a.selected;
3142
+ const lines = [];
3143
+ if (a?.custom !== void 0) lines.push(a.custom);
3144
+ for (const label of chosen) lines.push(label);
3145
+ const dd = lines.length ? lines.map((line) => `<span class="ask-answer-line">${esc(line)}</span>`).join("") : `<span class="ask-skipped">\u672A\u56DE\u7B54</span>`;
3146
+ const dt = q.header ? `<span class="ask-header">${esc(q.header)}</span><span class="ask-question">${esc(q.question)}</span>` : `<span class="ask-question">${esc(q.question)}</span>`;
3147
+ return `<div class="ask-item"><dt class="ask-dt">${dt}</dt><dd class="ask-dd">${dd}</dd></div>`;
3148
+ }).join("\n");
3149
+ const body = pending || interrupted ? `<p class="ask-verdict">${interrupted ? "\u672C\u8F6E\u5DF2\u4E2D\u65AD\uFF0C\u672A\u63D0\u4EA4\u56DE\u7B54" : "\u7B49\u5F85\u56DE\u7B54"}</p>
3150
+ <ul class="ask-question-list">
3151
+ ${questions.map((q) => `<li class="ask-list-item">${esc(q.question)}</li>`).join("\n")}
3152
+ </ul>` : `<dl class="ask-list">
3153
+ ${items}
3154
+ </dl>`;
3155
+ return `<div class="ask-row" data-tool="ask_user_question" data-state="${state}">
3156
+ <details class="ask-disclosure">
3157
+ <summary><span class="ask-icon" aria-hidden="true"></span><span class="ask-title">\u63D0\u95EE</span><span class="ask-sep" aria-hidden="true"></span><span class="ask-summary">${esc(summaryText)}</span><span class="ask-chevron"></span></summary>
3158
+ <div class="ask-body">
3159
+ <div class="ask-card">
3160
+ ${body}
3161
+ </div>
3162
+ </div>
3163
+ </details>
3164
+ </div>`;
3165
+ }
2211
3166
  function toolSummary(block) {
2212
3167
  const fields = block.argsFields ?? [];
2213
3168
  const preferred = ["description", "command", "file_path", "path", "pattern", "query", "url", "name", "prompt", "code"];
@@ -2250,6 +3205,96 @@ function renderFiles(files) {
2250
3205
  }).join("");
2251
3206
  return `<div class="files">${cards}</div>`;
2252
3207
  }
3208
+ function renderDeliverables(block) {
3209
+ const cards = block.files.map((f) => {
3210
+ const name = basename(f.path);
3211
+ const ext = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toUpperCase().slice(0, 8) : "FILE";
3212
+ const desc = f.description ? `<span class="dl-desc">${esc(f.description)}</span>` : "";
3213
+ return `<div class="dl-card" title="${esc(f.path)}"><span class="dl-icon">${esc(ext)}</span><span class="dl-body"><span class="dl-name">${esc(name)}</span>${desc}</span></div>`;
3214
+ }).join("\n");
3215
+ return `<div class="deliverables">
3216
+ ${cards}
3217
+ </div>`;
3218
+ }
3219
+ function renderChanges(block) {
3220
+ const counts = `<span class="chg-added">+${block.added}</span><span class="chg-deleted">-${block.deleted}</span>`;
3221
+ const single = block.total === 1 ? block.files[0] : void 0;
3222
+ const title = single ? `\u5DF2\u7F16\u8F91 ${basename(single.display)}` : `\u5DF2\u7F16\u8F91 ${block.total} \u4E2A\u6587\u4EF6`;
3223
+ const uid = `diff-${changeCounter++}`;
3224
+ const drawers = [];
3225
+ const rows = block.files.map((f, index) => {
3226
+ 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>`;
3227
+ const diff = block.diffs?.get(index);
3228
+ if (!diff) {
3229
+ return `<li class="chg-row" data-no-diff><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></li>`;
3230
+ }
3231
+ const id = `${uid}-${index}`;
3232
+ drawers.push(renderDiffDrawer(id, f, diff));
3233
+ return `<li class="chg-row"><a class="chg-link" href="#${esc(id)}"><span class="chg-path">${esc(f.display)}</span><span class="chg-stat">${stat}</span></a></li>`;
3234
+ }).join("\n");
3235
+ 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>` : "";
3236
+ const missingNote = block.files.length > 0 && drawers.length === 0 && block.diffs === void 0 ? '<p class="chg-note-line">diff \u660E\u7EC6\u672A\u968F\u4F1A\u8BDD\u4FDD\u7559\uFF08DSH \u91CD\u542F\u540E\u65E7\u4F1A\u8BDD\u7684\u6539\u52A8\u8BB0\u5F55\u4F1A\u4E22\u5931\uFF09\uFF0C\u53EA\u80FD\u770B\u5230\u589E\u5220\u884C\u6570\u3002</p>' : block.files.length > drawers.length ? '<p class="chg-note-line">\u90E8\u5206\u6587\u4EF6\u6CA1\u6709 diff \u660E\u7EC6\uFF0C\u70B9\u51FB\u65E0\u9884\u89C8\u3002</p>' : "";
3237
+ return `<details class="changes">
3238
+ <summary><span class="chg-title">${esc(title)}</span>${counts}</summary>
3239
+ <div class="chg-body">
3240
+ <ul class="chg-list">
3241
+ ${rows}
3242
+ ${more}
3243
+ </ul>
3244
+ ${missingNote}
3245
+ </div>
3246
+ </details>
3247
+ ${drawers.join("\n")}`;
3248
+ }
3249
+ var changeCounter = 0;
3250
+ function renderDiffDrawer(id, file, diff) {
3251
+ const closeHref = "#diff-closed";
3252
+ let body;
3253
+ if (diff.kind === "binary") {
3254
+ body = '<p class="dif-empty">\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u65E0\u6CD5\u9010\u884C\u5BF9\u6BD4\u3002</p>';
3255
+ } else if (diff.kind === "oversized") {
3256
+ body = '<p class="dif-empty">\u6587\u4EF6\u8FC7\u5927\uFF0C\u672A\u505A\u9010\u884C\u5BF9\u6BD4\u3002</p>';
3257
+ } else if (!diff.hunks?.length) {
3258
+ body = diff.before === false ? '<p class="dif-empty">\u65B0\u589E\u6587\u4EF6\uFF08\u5185\u5BB9\u4E3A\u7A7A\u6216\u65E0\u6CD5\u5BF9\u6BD4\uFF09\u3002</p>' : diff.after === false ? '<p class="dif-empty">\u5220\u9664\u8BE5\u6587\u4EF6\uFF08\u5185\u5BB9\u4E3A\u7A7A\u6216\u65E0\u6CD5\u5BF9\u6BD4\uFF09\u3002</p>' : '<p class="dif-empty">\u4E24\u4FA7\u5185\u5BB9\u76F8\u540C\uFF0C\u6CA1\u6709\u5DEE\u5F02\u3002</p>';
3259
+ } else {
3260
+ body = renderHunks(diff.hunks, diff.coarse === true);
3261
+ }
3262
+ const stat = diff.kind === "text" ? `<span class="chg-added">+${file.added}</span><span class="chg-deleted">-${file.deleted}</span>` : "";
3263
+ return `<aside class="dif-drawer" id="${esc(id)}" role="dialog" aria-label="${esc(file.display)} \u7684\u6539\u52A8">
3264
+ <div class="dif-head">
3265
+ <span class="dif-path">${esc(file.display)}</span>
3266
+ <span class="dif-stat">${stat}</span>
3267
+ <a class="dif-close" href="${closeHref}" aria-label="\u5173\u95ED">\xD7</a>
3268
+ </div>
3269
+ <div class="dif-body">
3270
+ ${body}
3271
+ </div>
3272
+ </aside>`;
3273
+ }
3274
+ function renderHunks(hunks, coarse) {
3275
+ const parts = [];
3276
+ for (const hunk of hunks) {
3277
+ let oldNo = hunk.oldStart;
3278
+ let newNo = hunk.newStart;
3279
+ const rows = hunk.lines.map((line) => {
3280
+ const mark = line.charAt(0);
3281
+ const text = line.slice(1);
3282
+ const isAdd = mark === "+";
3283
+ const isDel = mark === "-";
3284
+ const oldCell = isAdd ? "" : String(oldNo);
3285
+ const newCell = isDel ? "" : String(newNo);
3286
+ if (!isAdd) oldNo += 1;
3287
+ if (!isDel) newNo += 1;
3288
+ const kind = isAdd ? "add" : isDel ? "del" : "ctx";
3289
+ return `<tr class="dif-line" data-kind="${kind}"><td class="dif-no">${oldCell}</td><td class="dif-no">${newCell}</td><td class="dif-text"><span class="dif-mark">${esc(mark === " " ? "" : mark)}</span>${esc(text)}</td></tr>`;
3290
+ }).join("\n");
3291
+ parts.push(`<table class="dif-hunk"><tbody>
3292
+ ${rows}
3293
+ </tbody></table>`);
3294
+ }
3295
+ const note = coarse ? '<p class="dif-empty">\u9010\u884C\u5BF9\u6BD4\u8D85\u65F6\uFF0C\u4EE5\u4E0B\u6309\u6574\u6587\u4EF6\u66FF\u6362\u5C55\u793A\u3002</p>' : "";
3296
+ return `${note}${parts.join("\n")}`;
3297
+ }
2253
3298
  function basename(name) {
2254
3299
  const parts = name.split(/[\\/]/).filter(Boolean);
2255
3300
  return parts.length ? parts[parts.length - 1] ?? name : name;
@@ -2336,7 +3381,7 @@ function filenameStamp(epochMs, timeZone) {
2336
3381
  }
2337
3382
 
2338
3383
  // src/host/index.ts
2339
- var VERSION = "0.5.0";
3384
+ var VERSION = "0.6.0";
2340
3385
  function exportSession(input) {
2341
3386
  const preset = input.preset ?? "conversation";
2342
3387
  const opts = shareOptions(preset, input.options ?? {});
@@ -2358,7 +3403,9 @@ function exportSession(input) {
2358
3403
  redactions: redacted.stats.total,
2359
3404
  redacted: opts.redact,
2360
3405
  exportedAt,
2361
- warnings
3406
+ warnings,
3407
+ finalAnswerOnly: opts.include.finalAnswerOnly,
3408
+ foldProcess: opts.include.foldProcess
2362
3409
  });
2363
3410
  return {
2364
3411
  html: render.html,
@@ -2530,6 +3577,7 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
2530
3577
  if (truncatedEvents.length < events.length) {
2531
3578
  warnings.push(`\u4F1A\u8BDD\u4E8B\u4EF6\u8FC7\u591A\uFF0C\u4EC5\u5BFC\u51FA\u524D ${MAX_EVENTS} \u6761\uFF08\u5171 ${events.length} \u6761\uFF09`);
2532
3579
  }
3580
+ const changes = await collectChanges(ctx, request.sessionId, truncatedEvents);
2533
3581
  const shareOptions2 = {};
2534
3582
  if (request.turns !== void 0) shareOptions2.turns = request.turns;
2535
3583
  if (request.include) shareOptions2.include = { ...presetInclude(request.preset), ...request.include };
@@ -2545,7 +3593,8 @@ async function renderForRequest(ctx, rawRequest, options = {}) {
2545
3593
  },
2546
3594
  projectOptions: {
2547
3595
  sessionId: request.sessionId,
2548
- ...title ? { title } : {}
3596
+ ...title ? { title } : {},
3597
+ ...changes.size ? { changes } : {}
2549
3598
  },
2550
3599
  meta: { timeZone },
2551
3600
  exportedAt: now()
@@ -2650,6 +3699,84 @@ function toRawEvents(snapshot) {
2650
3699
  }
2651
3700
  return out;
2652
3701
  }
3702
+ async function collectChanges(ctx, sessionId, events) {
3703
+ const out = /* @__PURE__ */ new Map();
3704
+ const service = ctx.workspaceChanges;
3705
+ if (!service) return out;
3706
+ for (const event of events) {
3707
+ if (event.type !== "workspace/changes") continue;
3708
+ const seq = event.seq;
3709
+ if (typeof seq !== "number") continue;
3710
+ let summary;
3711
+ try {
3712
+ summary = service.summary(sessionId, seq);
3713
+ } catch (error) {
3714
+ ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6\u6587\u4EF6\u6539\u52A8\u6458\u8981\u5931\u8D25\uFF08seq=%s\uFF09\uFF1A%s", seq, String(error));
3715
+ continue;
3716
+ }
3717
+ if (!summary || !Array.isArray(summary.files)) continue;
3718
+ const files = summary.files.map((f) => ({
3719
+ path: f.path,
3720
+ display: f.display,
3721
+ added: f.added,
3722
+ deleted: f.deleted,
3723
+ ...f.binary === true ? { binary: true } : {},
3724
+ ...f.oversized === true ? { oversized: true } : {}
3725
+ }));
3726
+ const diffs = await collectDiffs(ctx, service, sessionId, seq, files.length);
3727
+ out.set(seq, {
3728
+ kind: "changes",
3729
+ files,
3730
+ total: summary.total,
3731
+ added: summary.added,
3732
+ deleted: summary.deleted,
3733
+ ...diffs.size ? { diffs } : {}
3734
+ });
3735
+ }
3736
+ return out;
3737
+ }
3738
+ var DIFF_CONCURRENCY = 4;
3739
+ async function collectDiffs(ctx, service, sessionId, seq, count) {
3740
+ const out = /* @__PURE__ */ new Map();
3741
+ if (count === 0) return out;
3742
+ const take = async (index) => {
3743
+ const controller = new AbortController();
3744
+ try {
3745
+ const diff = await service.diff(sessionId, seq, index, controller.signal);
3746
+ if (!diff) return;
3747
+ const file = { kind: diff.kind };
3748
+ if (diff.kind === "text") {
3749
+ if (diff.before !== void 0) file.before = diff.before;
3750
+ if (diff.after !== void 0) file.after = diff.after;
3751
+ if (diff.coarse === true) file.coarse = true;
3752
+ file.hunks = (diff.hunks ?? []).map((h) => ({
3753
+ oldStart: h.oldStart,
3754
+ oldLines: h.oldLines,
3755
+ newStart: h.newStart,
3756
+ newLines: h.newLines,
3757
+ lines: Array.isArray(h.lines) ? h.lines.map((l) => String(l)) : []
3758
+ }));
3759
+ }
3760
+ out.set(index, file);
3761
+ } catch (error) {
3762
+ ctx.logger?.warn("[dsh-share-html] \u8BFB\u53D6 diff \u5931\u8D25\uFF08seq=%s index=%s\uFF09\uFF1A%s", seq, index, String(error));
3763
+ }
3764
+ };
3765
+ let next = 0;
3766
+ const workers = [];
3767
+ for (let w = 0; w < Math.min(DIFF_CONCURRENCY, count); w += 1) {
3768
+ workers.push((async () => {
3769
+ for (; ; ) {
3770
+ const index = next;
3771
+ next += 1;
3772
+ if (index >= count) return;
3773
+ await take(index);
3774
+ }
3775
+ })());
3776
+ }
3777
+ await Promise.all(workers);
3778
+ return out;
3779
+ }
2653
3780
  function defaultTimeZone() {
2654
3781
  try {
2655
3782
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -2678,6 +3805,7 @@ export {
2678
3805
  MAX_EVENTS,
2679
3806
  MAX_HTML_BYTES,
2680
3807
  capabilitiesForRequest,
3808
+ collectChanges,
2681
3809
  createHandlers,
2682
3810
  renderForRequest,
2683
3811
  toRawEvents,