dsh-knit 0.26.0 → 0.27.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.
@@ -8,7 +8,8 @@
8
8
  * 面板本身:列表(相关性或 mtime 排序 + 过滤 + 键盘导航)+ 列表下方的就地预览。
9
9
  * 两个宿主共用同一个 KnitBody,只在「怎么开新标签页」上用适配器分叉。
10
10
  *
11
- * 构建:无。手写脚本,由 __ModuleLoader__ 直接装载,用 React.createElement 而非 JSX。
11
+ * 构建:源码在 `tools/client-src/*.js`,由 `node tools/build-client.mjs` 拼成
12
+ * `src/client/client.js`(DSH 仍只加载这一个文件;无 bundler、无 JSX)。
12
13
  */
13
14
  window.__ModuleLoader__.load({
14
15
  id: 'dsh-knit',
@@ -41,6 +42,8 @@ window.__ModuleLoader__.load({
41
42
  'count.code.filtered': '{hit} / {total} 个代码文件',
42
43
  'count.media': '{n} 个媒体',
43
44
  'count.media.filtered': '{hit} / {total} 个媒体',
45
+ 'count.changes': '{n} 个变更文件',
46
+ 'count.changes.filtered': '{hit} / {total} 个变更文件',
44
47
  'action.refresh': '刷新',
45
48
  'path.openTitle': '在文件管理器中打开',
46
49
  'peek.empty': '这个工作区里还没有 Markdown 文档。',
@@ -49,6 +52,7 @@ window.__ModuleLoader__.load({
49
52
  'sort.relevance': '相关',
50
53
  'sort.time': '最新',
51
54
  'sort.mediaTimeTitle': '图片一律按时间排序(最新在前)',
55
+ 'sort.changesTitle': '变更按文件修改时间列出(最新在前)',
52
56
  'sort.relevanceTitle': '按与当前对话的相关性排序(纯本地关键词匹配,不调模型)',
53
57
  'sort.timeTitle': '按文件修改时间倒序',
54
58
 
@@ -64,6 +68,7 @@ window.__ModuleLoader__.load({
64
68
  // 只扫图片与视频(宿主按扩展名放行,没有音频);③ 「媒体」省 3 个字,窄侧栏少一次
65
69
  // 省略号。**含义由空态说明**(list.emptyMedia 仍写「还没有图片或视频」)。
66
70
  'kind.media': '媒体',
71
+ 'kind.changes': '变更',
67
72
  'kind.title': '切换要列出的产物类型',
68
73
 
69
74
  'filter.placeholder': '过滤文档',
@@ -296,6 +301,24 @@ window.__ModuleLoader__.load({
296
301
  'list.empty': '这个工作区里还没有 Markdown 文档。',
297
302
  'list.emptyCode': '这个工作区里还没有可纳入上下文的代码文件。',
298
303
  'list.emptyMedia': '这个工作区里还没有图片或视频。',
304
+ 'list.emptyChanges': '工作区里没有未提交的改动。',
305
+ 'list.changeOnlyOther': '有 {n} 个变更文件,但没有可列出的 Markdown / 代码。',
306
+ 'list.changesLoading': '正在读取 Git 变更…',
307
+ 'changes.unavailable': '读不到 Git 变更:{reason}',
308
+ 'changes.status.modified': '修改',
309
+ 'changes.status.added': '新增',
310
+ 'changes.status.deleted': '删除',
311
+ 'changes.status.renamed': '重命名',
312
+ 'changes.status.untracked': '新文件',
313
+ 'changes.status.unmerged': '冲突',
314
+ 'changes.status.copied': '复制',
315
+ 'changes.binary': '二进制',
316
+ 'changes.lines': '行数统计不可用',
317
+ 'diff.loading': '正在读取 diff…',
318
+ 'diff.failed': '读取 diff 失败',
319
+ 'diff.binary': '二进制文件,没有文本 diff',
320
+ 'diff.truncated': 'diff 已截断',
321
+ 'changes.title': '未提交的改动(只读 git status + numstat)',
299
322
  'list.noMatch': '没有匹配「{query}」的文档。',
300
323
  // 文档列表这个 listbox 的无障碍名字(原先硬编码在 JSX 里,英文界面下会漏出中文)
301
324
  'list.aria': '最近文档',
@@ -432,6 +455,7 @@ window.__ModuleLoader__.load({
432
455
  'host.mediaTooLarge': '视频过大',
433
456
  'host.readFailed': '读取失败',
434
457
  'host.missingRel': '缺少 rel 参数',
458
+ 'host.diffFailed': '读取 diff 失败',
435
459
  'host.internal': '宿主内部错误',
436
460
  }
437
461
 
@@ -448,6 +472,8 @@ window.__ModuleLoader__.load({
448
472
  'count.code.filtered': '{hit} / {total} code files',
449
473
  'count.media': '{n} media',
450
474
  'count.media.filtered': '{hit} / {total} media',
475
+ 'count.changes': '{n} changed files',
476
+ 'count.changes.filtered': '{hit} / {total} changed files',
451
477
  'action.refresh': 'Refresh',
452
478
  'path.openTitle': 'Open in file manager',
453
479
  'peek.empty': 'No Markdown documents in this workspace yet.',
@@ -456,6 +482,7 @@ window.__ModuleLoader__.load({
456
482
  'sort.relevance': 'Relevant',
457
483
  'sort.time': 'Recent',
458
484
  'sort.mediaTimeTitle': 'Images are always sorted by newest first',
485
+ 'sort.changesTitle': 'Changes are listed by file modification time (newest first)',
459
486
  'sort.relevanceTitle': 'Sort by relevance to the current conversation (local keyword matching, no model call)',
460
487
  'sort.timeTitle': 'Sort by file modified time, newest first',
461
488
 
@@ -465,6 +492,7 @@ window.__ModuleLoader__.load({
465
492
  // follows the same word as count.media ("{n} media"): the tab says Media, and the
466
493
  // explicit "images and videos" wording stays in the empty state / README prose.
467
494
  'kind.media': 'Media',
495
+ 'kind.changes': 'Changes',
468
496
  'kind.title': 'Switch which artifacts are listed',
469
497
 
470
498
  'filter.placeholder': 'Filter docs',
@@ -652,6 +680,24 @@ window.__ModuleLoader__.load({
652
680
  'list.empty': 'No Markdown documents in this workspace yet.',
653
681
  'list.emptyCode': 'No code files eligible for context in this workspace yet.',
654
682
  'list.emptyMedia': 'No images or videos in this workspace yet.',
683
+ 'list.emptyChanges': 'No uncommitted changes in this workspace.',
684
+ 'list.changeOnlyOther': '{n} changed file(s), but no Markdown / code to list.',
685
+ 'list.changesLoading': 'Reading Git changes…',
686
+ 'changes.unavailable': 'Git changes unavailable: {reason}',
687
+ 'changes.status.modified': 'Modified',
688
+ 'changes.status.added': 'Added',
689
+ 'changes.status.deleted': 'Deleted',
690
+ 'changes.status.renamed': 'Renamed',
691
+ 'changes.status.untracked': 'Untracked',
692
+ 'changes.status.unmerged': 'Conflict',
693
+ 'changes.status.copied': 'Copied',
694
+ 'changes.binary': 'binary',
695
+ 'changes.lines': 'line counts unavailable',
696
+ 'diff.loading': 'Reading diff…',
697
+ 'diff.failed': 'Could not read the diff',
698
+ 'diff.binary': 'Binary file — no text diff',
699
+ 'diff.truncated': 'Diff truncated',
700
+ 'changes.title': 'Uncommitted changes (read-only git status + numstat)',
655
701
  'list.noMatch': 'No documents match “{query}”.',
656
702
  // Accessible name of the document listbox (was hardcoded in JSX before)
657
703
  'list.aria': 'Recent documents',
@@ -768,6 +814,7 @@ window.__ModuleLoader__.load({
768
814
  'host.mediaTooLarge': 'Video too large',
769
815
  'host.readFailed': 'Read failed',
770
816
  'host.missingRel': 'Missing the rel parameter',
817
+ 'host.diffFailed': 'Could not read the diff',
771
818
  'host.internal': 'Internal host error',
772
819
  }
773
820
 
@@ -807,6 +854,7 @@ window.__ModuleLoader__.load({
807
854
  'knit/media-too-large': 'host.mediaTooLarge',
808
855
  'knit/read-failed': 'host.readFailed',
809
856
  'knit/missing-rel': 'host.missingRel',
857
+ 'knit/diff-failed': 'host.diffFailed',
810
858
  'knit/internal': 'host.internal',
811
859
  }
812
860
 
@@ -902,6 +950,8 @@ window.__ModuleLoader__.load({
902
950
  /* v0.25:Git 变更关联的**独立接口**。它与列表接口分开,所以「列表的响应形状」
903
951
  不会被这个功能碰到;关掉功能时客户端连这个请求都不发。 */
904
952
  const CHANGES_API = '/knit/api/changes'
953
+ const STATUS_API = '/knit/api/status'
954
+ const DIFF_API = '/knit/api/diff'
905
955
  /* v0.25:媒体档额外显示「对话里工具产出的图」——**独立接口**,`/api/recent` 一个字节没动。
906
956
  列表零 I/O(元数据全在会话事件里);字节按 **sha256** 取(见 `attachmentUrl`)。 */
907
957
  const ATTACH_LIST_API = '/knit/api/attachments'
@@ -961,6 +1011,8 @@ window.__ModuleLoader__.load({
961
1011
  */
962
1012
  const KIND_CODE = 'code'
963
1013
  const KIND_MEDIA = 'media'
1014
+ /** v0.26.x:「变更」档 —— 未提交改动(跨 Markdown / 代码)。 */
1015
+ const KIND_CHANGES = 'changes'
964
1016
 
965
1017
  /**
966
1018
  * v0.19:分类层给的「生成产物」档(`.map` / `*.min.js` / `package-lock.json` …)。
@@ -1308,7 +1360,7 @@ window.__ModuleLoader__.load({
1308
1360
  * 1.(x:62.5%,y:31.0%)文案
1309
1361
  *
1310
1362
  * @param {{n:number,xPct:number,yPct:number,text:string}[]} list - 评论
1311
- * @param {{name?:string,rel?:string,sha?:string}} [image] - 这张图的身份(有就写头行)
1363
+ * @param {{name?:string,rel?:string,sha?:string,index?:number}} [image] - 身份 + 在输入框附件里的序号
1312
1364
  * @returns {string[]} 文本行
1313
1365
  */
1314
1366
  function commentLines(list, image) {
@@ -1316,7 +1368,10 @@ window.__ModuleLoader__.load({
1316
1368
  const label = image && (image.rel || image.name)
1317
1369
  if (label) {
1318
1370
  const sha = image.sha ? String(image.sha).slice(0, 12) : ''
1319
- lines.push(`图像 1:${label}${sha ? `(sha256 ${sha})` : ''}`)
1371
+ /* 编号必须与**输入框里的附件顺序**一致:第一张附过去是「图像 1」,第二张是「图像 2」。
1372
+ 不传 index(旧调用 / 单测)时回落 1。 */
1373
+ const index = image && Number.isFinite(image.index) && image.index > 0 ? Math.round(image.index) : 1
1374
+ lines.push(`图像 ${index}:${label}${sha ? `(sha256 ${sha})` : ''}`)
1320
1375
  }
1321
1376
  for (const item of normalizeComments(list)) {
1322
1377
  lines.push(`${item.n}.(x:${item.xPct.toFixed(1)}%,y:${item.yPct.toFixed(1)}%)${item.text}`)
@@ -1549,6 +1604,52 @@ window.__ModuleLoader__.load({
1549
1604
  }
1550
1605
  }
1551
1606
 
1607
+ /**
1608
+ * 输入框当前状态:已附件几张图、有没有正文。**只读 DOM,不改任何东西**。
1609
+ *
1610
+ * 用途有两个:
1611
+ * ① 新评论的编号 = 已有附件数 + 1(「附件一就是图像一」);
1612
+ * ② 已经有正文时,这次投递前面要空一行(独立段落),不能拼在上一句后面。
1613
+ *
1614
+ * @param {object|null} doc - document(测试可注入)
1615
+ * @returns {{count:number, hasText:boolean}} 状态
1616
+ */
1617
+ function composerState(doc) {
1618
+ const empty = { count: 0, hasText: false }
1619
+ try {
1620
+ if (!doc || typeof doc.querySelector !== 'function') return empty
1621
+ const input = doc.querySelector('[data-composer-input]')
1622
+ if (!input) return empty
1623
+ const hasText = typeof input.textContent === 'string' && input.textContent.trim() !== ''
1624
+ let count = 0
1625
+ const card = typeof input.closest === 'function' ? input.closest('[data-composer-card]') : null
1626
+ if (card && typeof card.querySelectorAll === 'function') {
1627
+ count = [...card.querySelectorAll('img')].filter((img) => {
1628
+ const src = String((img && img.src) || '')
1629
+ if (src.startsWith('blob:')) return true
1630
+ const parent = img && img.parentElement
1631
+ return /thumbnail/i.test(String((parent && parent.className) || ''))
1632
+ }).length
1633
+ }
1634
+ return { count, hasText }
1635
+ } catch { return empty }
1636
+ }
1637
+
1638
+ /** 把光标放到输入框末尾(否则 paste 会插在当前光标处,段落会断在中间)。 */
1639
+ function caretToEnd(input, win, doc) {
1640
+ try {
1641
+ if (!input || !win || typeof win.getSelection !== 'function') return
1642
+ if (!doc || typeof doc.createRange !== 'function') return
1643
+ const selection = win.getSelection()
1644
+ if (!selection) return
1645
+ const range = doc.createRange()
1646
+ range.selectNodeContents(input)
1647
+ range.collapse(false)
1648
+ selection.removeAllRanges()
1649
+ selection.addRange(range)
1650
+ } catch { /* 拿不到 selection 就按默认光标位置投递 */ }
1651
+ }
1652
+
1552
1653
  /**
1553
1654
  * 把一段文本投进**输入框**(不发送)。通道照 dsh-image-annotate 的已验证做法:
1554
1655
  * 合成 paste 到 `[data-composer-input]`;失败按序回落 document drop → clipboard → 下载。
@@ -1565,14 +1666,24 @@ window.__ModuleLoader__.load({
1565
1666
  const doc = env.document === undefined ? (typeof document === 'undefined' ? null : document) : env.document
1566
1667
  const win = env.window === undefined ? (typeof window === 'undefined' ? null : window) : env.window
1567
1668
  const file = env.attachment ? await imageFileFrom(env.attachment.src, env.attachment.name, env) : null
1669
+ /* 每次发送 = **独立段落**:输入框里已经有正文时,前面空两行再投;没有就原样。
1670
+ (只加前缀不补后缀 —— 下一次发送自己会补,避免末尾多出空行。) */
1671
+ const existing = (() => {
1672
+ try {
1673
+ const probe = doc && typeof doc.querySelector === 'function' ? doc.querySelector('[data-composer-input]') : null
1674
+ return probe && typeof probe.textContent === 'string' ? probe.textContent.trim() : ''
1675
+ } catch { return '' }
1676
+ })()
1677
+ const body = existing ? `\n\n${payload}` : payload
1568
1678
 
1569
1679
  // ① 合成 paste 到输入框(文本 + 图片 File 同一个事件)
1570
1680
  const input = doc && typeof doc.querySelector === 'function' ? doc.querySelector('[data-composer-input]') : null
1571
1681
  if (input && typeof input.dispatchEvent === 'function') {
1572
1682
  try { if (typeof input.focus === 'function') input.focus() } catch { /* 拿不到焦点也继续 */ }
1683
+ try { caretToEnd(input, win, doc) } catch { /* 光标放不到末尾就按默认位置 */ }
1573
1684
  const before = typeof input.textContent === 'string' ? input.textContent : ''
1574
1685
  try {
1575
- const event = buildPasteEvent(payload, win, file)
1686
+ const event = buildPasteEvent(body, win, file)
1576
1687
  const notPrevented = input.dispatchEvent(event)
1577
1688
  const after = typeof input.textContent === 'string' ? input.textContent : ''
1578
1689
  /* 宿主(Lexical)收到 paste 会 `preventDefault()` ⇒ dispatchEvent 返回 false。
@@ -1588,7 +1699,7 @@ window.__ModuleLoader__.load({
1588
1699
  // ② document 上的 drop
1589
1700
  if (doc && typeof doc.dispatchEvent === 'function') {
1590
1701
  try {
1591
- const event = buildDropEvent(payload, win)
1702
+ const event = buildDropEvent(body, win)
1592
1703
  if (doc.dispatchEvent(event) === false || (event && event.defaultPrevented)) return { ok: true, via: 'drop', image: false }
1593
1704
  } catch { /* 换下一条通道 */ }
1594
1705
  }
@@ -1597,7 +1708,7 @@ window.__ModuleLoader__.load({
1597
1708
  try {
1598
1709
  const clipboard = win && win.navigator && win.navigator.clipboard
1599
1710
  if (clipboard && typeof clipboard.writeText === 'function') {
1600
- await clipboard.writeText(payload)
1711
+ await clipboard.writeText(body)
1601
1712
  return { ok: true, via: 'clipboard', image: false }
1602
1713
  }
1603
1714
  } catch { /* 换下一条通道 */ }
@@ -1607,7 +1718,7 @@ window.__ModuleLoader__.load({
1607
1718
  const BlobCtor = win && win.Blob
1608
1719
  const UrlApi = win && win.URL
1609
1720
  if (BlobCtor && UrlApi && typeof UrlApi.createObjectURL === 'function' && doc && typeof doc.createElement === 'function') {
1610
- const url = UrlApi.createObjectURL(new BlobCtor([payload], { type: 'text/plain;charset=utf-8' }))
1721
+ const url = UrlApi.createObjectURL(new BlobCtor([body], { type: 'text/plain;charset=utf-8' }))
1611
1722
  const anchor = doc.createElement('a')
1612
1723
  anchor.href = url
1613
1724
  anchor.download = 'knit-comments.txt'
@@ -2642,6 +2753,47 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
2642
2753
  刻意**不是**一个胶囊:没有底色、没有边框、没有圆角 —— 它是一条弱注释,
2643
2754
  不是标签墙。字号比标题小两档,颜色用 caption,永远不抢标题。
2644
2755
  窄侧边栏里它 flex:none,压缩的是标题(.knit-title 会省略号收尾)而不是它。 */
2756
+ .knit-change-badge{margin-left:6px;flex:none;font-size:10px;line-height:16px;padding:0 5px;
2757
+ border-radius:4px;background:var(--knit-chip-bg);color:var(--dsw-alias-label-secondary)}
2758
+ .knit-change-count{display:inline-flex;gap:4px;flex:none;margin-left:6px;font-size:11px;
2759
+ font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-caption)}
2760
+ .knit-change-add{color:var(--dsw-alias-state-success-primary)}
2761
+ .knit-change-del{color:var(--dsw-alias-label-error)}
2762
+ .knit-change-binary{color:var(--dsw-alias-label-caption)}
2763
+ /* v0.26.x 变更档:逐行 diff(只画内容行,不接语法高亮 / 折叠 / 编辑器) */
2764
+ .knit-diff{display:flex;flex-direction:column;gap:8px;min-height:100%;overflow-x:auto}
2765
+ .knit-diff-sum{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;font-size:11px;
2766
+ color:var(--dsw-alias-label-caption);position:sticky;top:0;z-index:1;padding:2px 0;
2767
+ background:var(--dsw-alias-bg-base)}
2768
+ .knit-diff-file{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
2769
+ color:var(--dsw-alias-label-secondary)}
2770
+ .knit-diff-add{color:var(--dsw-alias-state-success-primary);font-variant-numeric:tabular-nums}
2771
+ .knit-diff-del{color:var(--dsw-alias-label-error);font-variant-numeric:tabular-nums}
2772
+ .knit-diff-note{color:var(--dsw-alias-label-caption)}
2773
+ .knit-diff-body{display:flex;flex-direction:column;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
2774
+ font-size:11.5px;line-height:1.7;min-width:max-content;border-radius:6px;overflow:hidden}
2775
+ /* 行底:用**语义色 + 低透明度覆盖层**,不写死 rgba、也不用 color-mix(AGENTS §6.3)。
2776
+ 绿 / 红只表达 diff 的增删,不表达好坏;正文仍在最上层。 */
2777
+ .knit-diff-line{position:relative;display:flex;align-items:baseline;gap:8px;white-space:pre;
2778
+ padding:0 8px 0 4px;border-left:2px solid transparent}
2779
+ .knit-diff-line.add,.knit-diff-line.del{background:var(--knit-hover-bg,var(--dsw-alias-interactive-bg-hover))}
2780
+ .knit-diff-line.add{border-left-color:var(--dsw-alias-state-success-primary)}
2781
+ .knit-diff-line.del{border-left-color:var(--dsw-alias-label-error)}
2782
+ .knit-diff-line.add::before,.knit-diff-line.del::before{content:'';position:absolute;inset:0;
2783
+ pointer-events:none;z-index:0}
2784
+ .knit-diff-line.add::before{background:var(--dsw-alias-state-success-primary);opacity:.13}
2785
+ .knit-diff-line.del::before{background:var(--dsw-alias-label-error);opacity:.11}
2786
+ .knit-diff-line > *{position:relative;z-index:1}
2787
+ .knit-diff-line.hunk{color:var(--dsw-alias-label-caption);background:transparent;
2788
+ border-left-color:transparent;margin-top:6px;padding-top:2px;padding-bottom:2px}
2789
+ .knit-diff-old,.knit-diff-new{flex:none;width:40px;text-align:right;color:var(--dsw-alias-label-caption);
2790
+ font-variant-numeric:tabular-nums;user-select:none;font-size:11px}
2791
+ .knit-diff-line.add .knit-diff-old,.knit-diff-line.add .knit-diff-new{color:var(--dsw-alias-state-success-primary)}
2792
+ .knit-diff-line.del .knit-diff-old,.knit-diff-line.del .knit-diff-new{color:var(--dsw-alias-label-error)}
2793
+ .knit-diff-sign{flex:none;width:12px;text-align:center;color:var(--dsw-alias-label-secondary);font-weight:600}
2794
+ .knit-diff-line.add .knit-diff-sign{color:var(--dsw-alias-state-success-primary)}
2795
+ .knit-diff-line.del .knit-diff-sign{color:var(--dsw-alias-label-error)}
2796
+ .knit-diff-text{flex:none;min-width:0;color:var(--dsw-alias-label-primary)}
2645
2797
  .knit-lang{flex:none;margin-left:6px;font-size:10px;letter-spacing:.04em;
2646
2798
  text-transform:uppercase;color:var(--dsw-alias-label-caption,#80868b)}
2647
2799
 
@@ -2933,11 +3085,11 @@ video.knit-preview-media{width:100%;background:#000}
2933
3085
  *
2934
3086
  * v0.23.1:「全部」档已整体删除 ⇒ 白名单里的 `'all'` 也删掉 ——
2935
3087
  * 老用户 localStorage 里存着 `'all'` 时**回落到 `文档`**(不空白、不抛)。
2936
- * @returns {'doc'|'code'|'media'} 类型
3088
+ * @returns {'doc'|'code'|'media'|'changes'} 类型
2937
3089
  */
2938
3090
  function readKindPref() {
2939
3091
  const v = readPref(KIND_KEY)
2940
- return v === KIND_MEDIA || v === KIND_CODE ? v : KIND_DOC
3092
+ return v === KIND_MEDIA || v === KIND_CODE || v === KIND_CHANGES ? v : KIND_DOC
2941
3093
  }
2942
3094
 
2943
3095
  /**
@@ -3285,6 +3437,65 @@ video.knit-preview-media{width:100%;background:#000}
3285
3437
  }))
3286
3438
  }
3287
3439
 
3440
+ /**
3441
+ * 一个变更条目 → 状态词(只给一枚主徽标,`kinds` 的完整集合仍随行带出)。
3442
+ * @param {string[]} kinds - `git status` 的 kinds
3443
+ * @returns {string} modified|added|deleted|renamed|untracked|unmerged|copied
3444
+ */
3445
+ function changeStatusOfFile(kinds) {
3446
+ const list = Array.isArray(kinds) ? kinds : []
3447
+ if (list.includes('unmerged')) return 'unmerged'
3448
+ if (list.includes('untracked')) return 'untracked'
3449
+ if (list.includes('deleted')) return 'deleted'
3450
+ if (list.includes('renamed')) return 'renamed'
3451
+ if (list.includes('added')) return 'added'
3452
+ if (list.includes('copied')) return 'copied'
3453
+ return 'modified'
3454
+ }
3455
+
3456
+ /**
3457
+ * `/knit/api/status` 的 `git.files` → 列表行(只做形状映射;只收 Markdown / 代码)。
3458
+ *
3459
+ * 变更档的列表行**就是**既有 `DocRow`:点开走同一条预览路径,不新开第二套渲染。
3460
+ * 额外的 `change` 字段只负责状态徽标与 `+N −N`,不影响键盘 / 预览。
3461
+ *
3462
+ * @param {object|null} data - `/knit/api/status` 的载荷
3463
+ * @returns {Array<object>} 行(`rel/title/name/summary/kind/mtimeMs/change`)
3464
+ */
3465
+ function changeDocsOf(data) {
3466
+ const files = data && data.git && Array.isArray(data.git.files) ? data.git.files : []
3467
+ const out = []
3468
+ for (const file of files) {
3469
+ if (!file || file.isDir === true) continue
3470
+ const kind = file.kind
3471
+ if (kind !== ARTIFACT_DOC && kind !== ARTIFACT_CODE) continue
3472
+ const rel = String(file.rel || '')
3473
+ if (!rel) continue
3474
+ const parts = rel.split('/')
3475
+ const name = parts[parts.length - 1]
3476
+ const dir = parts.slice(0, -1).join('/')
3477
+ out.push({
3478
+ rel,
3479
+ title: name,
3480
+ name,
3481
+ summary: dir ? `${dir}/` : '',
3482
+ kind,
3483
+ mtimeMs: Number.isFinite(file.mtimeMs) ? file.mtimeMs : 0,
3484
+ size: Number.isFinite(file.bytes) ? file.bytes : 0,
3485
+ change: {
3486
+ status: changeStatusOfFile(file.kinds),
3487
+ added: Number.isFinite(file.added) ? file.added : null,
3488
+ removed: Number.isFinite(file.removed) ? file.removed : null,
3489
+ binary: file.binary === true,
3490
+ untracked: file.untracked === true,
3491
+ deleted: file.deleted === true,
3492
+ ...(file.origRel ? { origRel: file.origRel } : {}),
3493
+ },
3494
+ })
3495
+ }
3496
+ return out
3497
+ }
3498
+
3288
3499
  /**
3289
3500
  * 一个条目符不符合过滤框里的那串字(标题 / 摘要 / 相对路径)。
3290
3501
  *
@@ -3805,7 +4016,9 @@ video.knit-preview-media{width:100%;background:#000}
3805
4016
  // 全部是**可选** props:平铺列表(时间序 / 过滤结果)一个都不传,那一屏与 v0.20
3806
4017
  // 逐字相同。`onAct` 为 null ⇒ 不渲染动作按钮;`relations` 为空 ⇒ 「为什么」退回
3807
4018
  // 纯文本(没有证据就不装成有证据的样子)。
3808
- prov, pinned, onAct, relations, relationsTotal, whyOpen, onWhyToggle, onOpenRelation }) {
4019
+ prov, pinned, onAct, relations, relationsTotal, whyOpen, onWhyToggle, onOpenRelation,
4020
+ // v0.26.x 变更档:一个可选的 `change` 只负责「状态徽标 + +N −N」,其余路径不变。
4021
+ change }) {
3809
4022
  const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
3810
4023
  const rowRef = React.useRef(null)
3811
4024
  /* v0.19:只有**代码行**带语言徽章。
@@ -3924,6 +4137,14 @@ video.knit-preview-media{width:100%;background:#000}
3924
4137
  fresh ? h('span', { className: 'knit-badge' }, '🆕') : null,
3925
4138
  doc.title || doc.name,
3926
4139
  lang ? h('span', { className: 'knit-lang' }, lang) : null),
4140
+ change
4141
+ ? h('span', { className: 'knit-change-badge' }, t(`changes.status.${change.status}`))
4142
+ : null,
4143
+ change && !change.binary && (Number.isFinite(change.added) || Number.isFinite(change.removed))
4144
+ ? h('span', { className: 'knit-change-count' },
4145
+ Number.isFinite(change.added) ? h('span', { className: 'knit-change-add' }, `+${change.added}`) : null,
4146
+ Number.isFinite(change.removed) ? h('span', { className: 'knit-change-del' }, `−${change.removed}`) : null)
4147
+ : (change && change.binary ? h('span', { className: 'knit-change-count knit-change-binary' }, t('changes.binary')) : null),
3927
4148
  // v0.17:生命周期状态(文案已算好;没有证据时是 null,一个节点都不加)。
3928
4149
  // 插在**标题与时间之间**:`.knit-title` 是 flex:1 1 auto,会把状态与时间一起推到
3929
4150
  // 行尾,状态在时间左侧、行尾仍然是时间。
@@ -3940,7 +4161,7 @@ video.knit-preview-media{width:100%;background:#000}
3940
4161
  h('div', { className: 'knit-time' }, relTime(doc.mtimeMs, now))),
3941
4162
  doc.summary
3942
4163
  ? h('div', { className: 'knit-sum' }, doc.summary)
3943
- : h('div', { className: 'knit-sum empty' }, t('summary.empty')),
4164
+ : (change ? null : h('div', { className: 'knit-sum empty' }, t('summary.empty'))),
3944
4165
  // ⚠️ **列表行里不再有路径**(2026-09-29 用户要求):「文档列表中的文档路径,我觉得
3945
4166
  // 不需要出现了,因为点开查看文档详情的时候已经有了,所以这里是重复的,隐藏掉」。
3946
4167
  // —— 这是**重复信息**,不是「多列砍字段」那种静默降级:预览头
@@ -4871,6 +5092,34 @@ video.knit-preview-media{width:100%;background:#000}
4871
5092
  * `find`(v0.25)= 查找条那一组:状态在 `KnitBody`(快捷键挂在面板根上,
4872
5093
  * 所以状态不能只活在这一层);`bodyRef` = 正文容器 ref,由 `KnitBody` 拿去做 DOM 命中绘制。
4873
5094
  */
5095
+ /**
5096
+ * 逐行 diff 视图(「变更」档点开一行)。只画宿主解析好的内容行:
5097
+ * 旧行号 / 新行号 / +/- / 文本;不加语法高亮、不做折叠(不是编辑器)。
5098
+ * @param {{diff: object}} props - `/knit/api/diff` 的载荷
5099
+ * @returns {import('react').ReactElement} 元素
5100
+ */
5101
+ function DiffPane({ diff }) {
5102
+ const lines = Array.isArray(diff.lines) ? diff.lines : []
5103
+ const rows = lines.map((line, i) => h('div', {
5104
+ key: `${i}-${line.type}`,
5105
+ className: `knit-diff-line ${line.type}`,
5106
+ },
5107
+ h('span', { className: 'knit-diff-old' }, line.oldNo == null ? '' : String(line.oldNo)),
5108
+ h('span', { className: 'knit-diff-new' }, line.newNo == null ? '' : String(line.newNo)),
5109
+ h('span', { className: 'knit-diff-sign' }, line.type === 'add' ? '+' : line.type === 'del' ? '−' : ' '),
5110
+ h('span', { className: 'knit-diff-text' }, line.text === '' ? ' ' : line.text)))
5111
+ const head = h('div', { className: 'knit-diff-sum' },
5112
+ h('span', { className: 'knit-diff-file' }, diff.rel || ''),
5113
+ h('span', { className: 'knit-diff-add' }, `+${Number(diff.added) || 0}`),
5114
+ h('span', { className: 'knit-diff-del' }, `−${Number(diff.removed) || 0}`),
5115
+ diff.binary ? h('span', { className: 'knit-diff-note' }, t('changes.binary')) : null,
5116
+ diff.truncated ? h('span', { className: 'knit-diff-note' }, t('diff.truncated')) : null)
5117
+ const body = diff.binary
5118
+ ? h('div', { className: 'knit-preview-note' }, t('diff.binary'))
5119
+ : h('div', { className: 'knit-diff-body' }, rows)
5120
+ return h('div', { className: 'knit-diff' }, head, body)
5121
+ }
5122
+
4874
5123
  function PreviewPanel({ preview, pathImages, fullscreen, ratio, links, linksExpanded, onToggleLinks, onOpenLink, onClose, onOpenLocal, onReveal, onOpenMap, onOpenWeb, onToggleFullscreen, onResizeStart, find, bodyRef, favorite, onToggleFavorite }) {
4875
5124
  const isMedia = preview.kind === 'image' || preview.kind === 'video'
4876
5125
  const previewPath = splitRelPath(preview.rel)
@@ -5027,7 +5276,13 @@ video.knit-preview-media{width:100%;background:#000}
5027
5276
  // v0.19:代码(含 `.map` 这类生成产物)走轻量 CodePane —— **绝不能落到
5028
5277
  // MarkdownText 那支**,否则 `#` 开头的注释会变成标题、`*` 会变成列表。
5029
5278
  const isCode = preview.kind === ARTIFACT_CODE || preview.kind === KIND_GENERATED
5030
- const body = preview.status === 'loading'
5279
+ const body = preview.diff
5280
+ ? (preview.diff.loading
5281
+ ? h('div', { className: 'knit-preview-note' }, t('diff.loading'))
5282
+ : preview.diff.error
5283
+ ? h('div', { className: 'knit-preview-note' }, t('diff.failed'))
5284
+ : h(DiffPane, { diff: preview.diff }))
5285
+ : preview.status === 'loading'
5031
5286
  ? h('div', { className: 'knit-preview-note' }, t('preview.loading'))
5032
5287
  : preview.status === 'error'
5033
5288
  ? h('div', { className: 'knit-preview-note' }, t('list.failed', { error: preview.error }))
@@ -5111,7 +5366,7 @@ video.knit-preview-media{width:100%;background:#000}
5111
5366
  : null,
5112
5367
  h('span', { className: 'knit-preview-name' }, previewPath.name)),
5113
5368
  // 复制整篇(只给代码;MarkdownText 自己带代码块复制)
5114
- isCodeView
5369
+ isCodeView && !preview.diff
5115
5370
  ? h('button', {
5116
5371
  className: 'knit-btn',
5117
5372
  onClick: onCopySource,
@@ -5120,7 +5375,7 @@ video.knit-preview-media{width:100%;background:#000}
5120
5375
  : null,
5121
5376
  // Source map:**低权重**入口 —— 只在同名 `<file>.map` 真的存在时出现,
5122
5377
  // 且 `.map` 本身不参与检索(需求 §6 §28)。点开仍是这个面板,纯文本。
5123
- isCodeView && preview.mapRel
5378
+ isCodeView && !preview.diff && preview.mapRel
5124
5379
  ? h('button', {
5125
5380
  className: 'knit-btn knit-btn-quiet',
5126
5381
  onClick: () => { if (onOpenMap) onOpenMap(preview.mapRel) },
@@ -5372,7 +5627,7 @@ video.knit-preview-media{width:100%;background:#000}
5372
5627
 
5373
5628
  ⇒ 请求**就是 time**(不只改显示):这样宿主不做无用的相关度计算、截断也按时间切。
5374
5629
  排序偏好本身**不做修改** —— 切回文档/代码还是你原来选的那个。 */
5375
- const effectiveSort = kind === KIND_MEDIA ? 'time' : sort
5630
+ const effectiveSort = kind === KIND_MEDIA || kind === KIND_CHANGES ? 'time' : sort
5376
5631
 
5377
5632
  const load = React.useCallback(async (alive) => {
5378
5633
  const live = () => typeof alive !== 'function' || alive()
@@ -5398,6 +5653,8 @@ video.knit-preview-media{width:100%;background:#000}
5398
5653
  const sig = JSON.stringify(data)
5399
5654
  setState((prev) => (prev.status === 'ready' && prev.sig === sig ? prev : {
5400
5655
  status: 'ready',
5656
+ // 变更档的独立载荷不归 load 管;轮询时原样带过去,别被列表刷新抹掉。
5657
+ changesStatus: prev.changesStatus || null,
5401
5658
  docs: data.docs || [],
5402
5659
  root: data.root || '',
5403
5660
  // v0.19 修订:`hostRoot` 是同一个工作区、但符号链接已展开的那份路径。
@@ -5523,12 +5780,23 @@ video.knit-preview-media{width:100%;background:#000}
5523
5780
  }, [sessionId, load])
5524
5781
 
5525
5782
  /* ── 过滤:纯客户端,不重新请求宿主 ─────────────── */
5783
+ /* v0.26.x「变更」档:数据来自独立 `/api/status`,**不混进 state.docs** ——
5784
+ 列表刷新(5 s 轮询)与变更读取互不影响。`changesStatus` 挂在 state 上是为了
5785
+ 避免新增 hook 位置(测试按位预置 hook);它是纯缓存,不参与排序。 */
5786
+ const changesStatus = state.changesStatus || null
5787
+ const changeView = changeStatusOf(changesStatus)
5788
+ const changeDocsAll = changeDocsOf(changesStatus)
5789
+ const changeText = query.trim().toLowerCase()
5790
+ const changeDocs = changeText
5791
+ ? changeDocsAll.filter((doc) => docMatchesQuery(doc, changeText))
5792
+ : changeDocsAll
5526
5793
  const visibleDocs = React.useMemo(() => {
5794
+ if (kind === KIND_CHANGES) return changeDocs
5527
5795
  const all = Array.isArray(state.docs) ? state.docs : []
5528
5796
  const q = query.trim().toLowerCase()
5529
5797
  if (!q) return all
5530
5798
  return all.filter((doc) => docMatchesQuery(doc, q))
5531
- }, [state.docs, query])
5799
+ }, [kind, changeDocs, state.docs, query])
5532
5800
 
5533
5801
  // ResizeObserver 量到的是 .knit-list(它自己也有左右内边距),
5534
5802
  // 网格的可用宽度 = 列表宽度 − 列表内边距 − 网格内边距。
@@ -5568,7 +5836,7 @@ video.knit-preview-media{width:100%;background:#000}
5568
5836
  renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark, withLife))
5569
5837
  }
5570
5838
 
5571
- const relevance = state.mode === 'relevance'
5839
+ const relevance = state.mode === 'relevance' && kind !== KIND_CHANGES
5572
5840
  const filtering = query.trim().length > 0
5573
5841
 
5574
5842
  /**
@@ -5761,7 +6029,7 @@ video.knit-preview-media{width:100%;background:#000}
5761
6029
  const merged = (Array.isArray(visibleDocs) ? visibleDocs : []).concat(attachmentDocs)
5762
6030
  return orderFavorites(merged.slice().sort(byTimeDesc), favoriteSet)
5763
6031
  }, [visibleDocs, favoriteSet, attachmentDocs])
5764
- const navDocs = kind === KIND_MEDIA && !contextView ? mediaDocs : (contextView ? contextView.flat : visibleDocs)
6032
+ const navDocs = kind === KIND_CHANGES ? visibleDocs : (kind === KIND_MEDIA && !contextView ? mediaDocs : (contextView ? contextView.flat : visibleDocs))
5765
6033
 
5766
6034
  // cursor 消失(被过滤掉 / 被上限截断 / 列表刷新)时落回第一项
5767
6035
  React.useEffect(() => {
@@ -5846,6 +6114,32 @@ video.knit-preview-media{width:100%;background:#000}
5846
6114
  })
5847
6115
  }, [previewFor])
5848
6116
 
6117
+ /**
6118
+ * 「变更」档点开一行:拉 `/api/diff`,在同一个预览面板里画逐行 diff。
6119
+ * 普通行仍走 `togglePreview`;这里只是给变更行换一个打开方式,不新增第二套面板。
6120
+ */
6121
+ const openDiff = async (doc) => {
6122
+ if (!doc) return
6123
+ setNotice('')
6124
+ setCursor(doc.rel)
6125
+ setPreview({
6126
+ rel: doc.rel, title: doc.title || doc.name, path: '', text: '', status: 'ready',
6127
+ kind: doc.kind || ARTIFACT_CODE, diff: { loading: true },
6128
+ added: doc.change ? doc.change.added : null, removed: doc.change ? doc.change.removed : null,
6129
+ })
6130
+ try {
6131
+ const res = await fetch(`${DIFF_API}?sessionId=${encodeURIComponent(sessionId)}&rel=${encodeURIComponent(doc.rel)}`, {
6132
+ headers: { accept: 'application/json' }, cache: 'no-store',
6133
+ })
6134
+ const data = await res.json()
6135
+ setPreview((prev) => (prev && prev.rel === doc.rel
6136
+ ? { ...prev, diff: data && data.ok ? data : { error: true } }
6137
+ : prev))
6138
+ } catch {
6139
+ setPreview((prev) => (prev && prev.rel === doc.rel ? { ...prev, diff: { error: true } } : prev))
6140
+ }
6141
+ }
6142
+
5849
6143
  /** 收起预览;全屏时顺带退出全屏。 */
5850
6144
  const closePreview = React.useCallback(() => {
5851
6145
  setPreview(null)
@@ -6413,6 +6707,7 @@ video.knit-preview-media{width:100%;background:#000}
6413
6707
  const motionRows = (() => {
6414
6708
  if (state.status === 'error' || state.docs.length === 0 || visibleDocs.length === 0) return []
6415
6709
  if (kind === KIND_MEDIA) return [] // 媒体格子不参与:网格里收起高度没有意义
6710
+ if (kind === KIND_CHANGES) return [] // 变更档:列表每次刷新可能整批换,别让整屏飞
6416
6711
  if (contextView) {
6417
6712
  // 有包(相关序):三层的 key 就是运动分组 —— 「全部」与「文档」走同一条路。
6418
6713
  const rows = []
@@ -6525,8 +6820,8 @@ video.knit-preview-media{width:100%;background:#000}
6525
6820
  active: Boolean(preview && preview.rel === doc.rel),
6526
6821
  cursor: doc.rel === cursor,
6527
6822
  optionId: docOptionId(doc),
6528
- onSelect: togglePreview,
6529
- onOpenTab,
6823
+ onSelect: doc.change ? () => openDiff(doc) : togglePreview,
6824
+ onOpenTab: doc.change ? () => openDiff(doc) : onOpenTab,
6530
6825
  // v0.20(需求 §12):只有真的带命中片段的条目才渲染那一行 —— 没有就不渲染,
6531
6826
  // 不编造一个「命中片段:—」的占位(§26:只展示可验证信息)。
6532
6827
  passage: firstMatchOf(doc),
@@ -6562,6 +6857,7 @@ video.knit-preview-media{width:100%;background:#000}
6562
6857
  // 平铺列表里的条目来源未知,不能替它认领一个「检索」。
6563
6858
  const controllable = Boolean(contextView && !isMedia(doc))
6564
6859
  return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary,
6860
+ change: doc.change || null,
6565
6861
  prov: provText(doc.provenance),
6566
6862
  pinned: doc.provenance === 'manual',
6567
6863
  onAct: controllable ? act : null,
@@ -6587,15 +6883,36 @@ video.knit-preview-media{width:100%;background:#000}
6587
6883
 
6588
6884
  // 媒体视图:一格都不隐藏 —— 一屏两行以外的部分在媒体区**内部滚动**,
6589
6885
  // 既不让面板被整面媒体墙顶爆,也不会像旧版那样把剩下的条目直接切掉。
6590
- const emptyText = kind === KIND_MEDIA
6591
- ? t('list.emptyMedia')
6592
- : kind === KIND_CODE
6593
- ? t('list.emptyCode')
6594
- : t('list.empty')
6886
+ const emptyText = kind === KIND_CHANGES
6887
+ ? t('list.emptyChanges')
6888
+ : kind === KIND_MEDIA
6889
+ ? t('list.emptyMedia')
6890
+ : kind === KIND_CODE
6891
+ ? t('list.emptyCode')
6892
+ : t('list.empty')
6595
6893
  /* ⚠️ 为什么是**函数**而不是常量:这里要读「面板末尾才声明」的状态(媒体收藏)。
6596
6894
  写成常量会在这一行就求值 ⇒ TDZ(`Cannot access 'favoriteSet' before initialization`)。
6597
6895
  包成函数、在 return 里调用一次,既不改渲染结果,也不会再被后面的新状态绊倒。 */
6598
- const listBody = () => (state.status === 'loading' && state.docs.length === 0
6896
+ /* 变更档自己的三态:还没读到 / 读不到(带原因)/ 读到了但没东西可列。
6897
+ ⚠️ 它**不**看 `state.status` —— 那是文档列表的加载态,与 git 无关。 */
6898
+ const changesListBody = () => {
6899
+ if (changesStatus === null) return h('div', { className: 'knit-msg' }, t('list.changesLoading'))
6900
+ if (!changeView.read) {
6901
+ return h('div', { className: 'knit-msg' },
6902
+ t('changes.unavailable', { reason: t(changeReasonKey(changeView.reason)) }))
6903
+ }
6904
+ if (changeView.filesTotal === 0) return h('div', { className: 'knit-msg' }, t('list.emptyChanges'))
6905
+ if (changeDocsAll.length === 0) {
6906
+ return h('div', { className: 'knit-msg' }, t('list.changeOnlyOther', { n: changeView.filesTotal }))
6907
+ }
6908
+ if (changeDocs.length === 0) {
6909
+ return h('div', { className: 'knit-msg' }, t('list.noMatch', { query: query.trim() }))
6910
+ }
6911
+ return docsGrid(changeDocs)
6912
+ }
6913
+ const listBody = () => (kind === KIND_CHANGES
6914
+ ? changesListBody()
6915
+ : state.status === 'loading' && state.docs.length === 0
6599
6916
  ? h('div', { className: 'knit-msg' }, t('list.scanning'))
6600
6917
  : state.status === 'error'
6601
6918
  ? h('div', { className: 'knit-msg' }, t('list.failed', { error: state.error }), h('br'), t('list.failedHint'))
@@ -6858,18 +7175,22 @@ video.knit-preview-media{width:100%;background:#000}
6858
7175
  // ⚠️ 2026-10-09 用户要求:**屏幕上只留阿拉伯数字**(`9` / `3 / 79`)——
6859
7176
  // 量词本来就随档位变(同一位置换个档就换一种中文,读起来像两套东西)。
6860
7177
  // 整句降级成 `title`(悬停仍读得到「9 个代码文件」),i18n 键不闲置。
6861
- const countKey = kind === KIND_MEDIA
6862
- ? (filtering ? 'count.media.filtered' : 'count.media')
6863
- : kind === KIND_CODE
6864
- ? (filtering ? 'count.code.filtered' : 'count.code')
6865
- : (filtering ? 'count.filtered' : 'count')
7178
+ const countKey = kind === KIND_CHANGES
7179
+ ? (filtering ? 'count.changes.filtered' : 'count.changes')
7180
+ : kind === KIND_MEDIA
7181
+ ? (filtering ? 'count.media.filtered' : 'count.media')
7182
+ : kind === KIND_CODE
7183
+ ? (filtering ? 'count.code.filtered' : 'count.code')
7184
+ : (filtering ? 'count.filtered' : 'count')
7185
+ const countTotal = kind === KIND_CHANGES ? changeView.filesTotal : state.total
7186
+ const countVisible = kind === KIND_CHANGES ? changeDocs.length : visibleDocs.length
6866
7187
  // 可见文本 = 纯数字;整句(含量词)只出现在 title 里。
6867
7188
  const countText = filtering
6868
- ? `${visibleDocs.length} / ${state.total}`
6869
- : String(state.total ?? 0)
7189
+ ? `${countVisible} / ${countTotal}`
7190
+ : String(countTotal ?? 0)
6870
7191
  const countTitle = filtering
6871
- ? t(countKey, { hit: visibleDocs.length, total: state.total })
6872
- : t(countKey, { n: state.total })
7192
+ ? t(countKey, { hit: countVisible, total: countTotal })
7193
+ : t(countKey, { n: countTotal })
6873
7194
 
6874
7195
  /* ── v0.21 检索状态摘要(需求 §6.3;2026-10-09 用户规格重排)──────────
6875
7196
  每一格都是**已经发生的事实**,不是估算:
@@ -6922,7 +7243,7 @@ video.knit-preview-media{width:100%;background:#000}
6922
7243
  ⚠️ **不再看 provider 配没配**(本次放宽):未配也出现 —— Knit 还没有设置页,
6923
7244
  藏起来用户就永远打不开这个功能;菜单里如实写状态,并就地给配置入口。
6924
7245
  ⚠️ **永远不做置灰禁用态**。 */
6925
- const showRetrieval = sort === 'relevance'
7246
+ const showRetrieval = sort === 'relevance' && kind !== KIND_CHANGES
6926
7247
  const semReason = semInfo && typeof semInfo.reason === 'string' ? semInfo.reason : null
6927
7248
  /** 菜单底部那行状态:如实说这一档现在到底生效成什么(不美化、不猜)。 */
6928
7249
  const semStateText = !semOn
@@ -7470,7 +7791,13 @@ video.knit-preview-media{width:100%;background:#000}
7470
7791
  const label = lightboxDoc.conversation
7471
7792
  ? (lightboxDoc.name || 'image')
7472
7793
  : lightboxDoc.rel
7473
- const text = commentLines(list, { rel: label, sha: shaOfDoc(lightboxDoc) }).join('\n')
7794
+ /* 附件序号就是图像序号:输入框里已经有 N 张附件 ⇒ 这一张是「图像 N+1」。 */
7795
+ const composer = composerState(typeof document === 'undefined' ? null : document)
7796
+ const text = commentLines(list, {
7797
+ rel: label,
7798
+ sha: shaOfDoc(lightboxDoc),
7799
+ index: composer.count + 1,
7800
+ }).join('\n')
7474
7801
  const result = await deliverCommentText(text, {
7475
7802
  attachment: {
7476
7803
  src: srcFor(lightboxDoc),
@@ -7515,6 +7842,41 @@ video.knit-preview-media{width:100%;background:#000}
7515
7842
  ? commentPopoverBox(commentAnchorPoint, { width: COMMENT_POP_W, height: COMMENT_POP_H }, commentView)
7516
7843
  : null
7517
7844
 
7845
+ /* v0.26.x「变更」档:独立的只读状态读取(不混进列表轮询)。
7846
+ · 只在**变更档且面板可见**时请求;切走 / 收起来就停(和列表同一条「看不见不花钱」纪律);
7847
+ · 载荷放 `state.changesStatus`,`load()` 轮询时原样带过去;
7848
+ · 失败有独立形状(`{failed,reason}`),不会把「读不到」显示成「没有改动」。 */
7849
+ React.useEffect(() => {
7850
+ if (visible === false || kind !== KIND_CHANGES) return undefined
7851
+ let alive = true
7852
+ let timer = null
7853
+ const run = async () => {
7854
+ if (!sessionId) return
7855
+ try {
7856
+ const res = await fetch(`${STATUS_API}?sessionId=${encodeURIComponent(sessionId)}`, {
7857
+ headers: { accept: 'application/json' }, cache: 'no-store',
7858
+ })
7859
+ const data = await res.json()
7860
+ if (!alive) return
7861
+ const next = data && data.ok ? data : { failed: true, reason: 'request' }
7862
+ const sig = JSON.stringify(next)
7863
+ setState((prev) => {
7864
+ if (prev.changesStatus && prev.changesStatus.sig === sig) return prev
7865
+ return { ...prev, changesStatus: { ...next, sig } }
7866
+ })
7867
+ } catch {
7868
+ if (!alive) return
7869
+ const next = { failed: true, reason: 'request' }
7870
+ const sig = JSON.stringify(next)
7871
+ setState((prev) => (prev.changesStatus && prev.changesStatus.sig === sig
7872
+ ? prev : { ...prev, changesStatus: { ...next, sig } }))
7873
+ }
7874
+ }
7875
+ const loop = async () => { await run(); if (alive) timer = setTimeout(loop, POLL_MS) }
7876
+ loop()
7877
+ return () => { alive = false; if (timer) clearTimeout(timer) }
7878
+ }, [visible, kind, sessionId])
7879
+
7518
7880
  /* v0.26 返工:画布内容只渲染一次,但有两种挂载点 ——
7519
7881
  · `lightboxDock` = Knit 面板里的画布(会话不盖住、身份清楚)
7520
7882
  · 否则 = 原来的整屏查看器(portal 到 body)
@@ -7890,14 +8252,14 @@ video.knit-preview-media{width:100%;background:#000}
7890
8252
  h('button', {
7891
8253
  className: `knit-seg-btn${effectiveSort === 'relevance' ? ' active' : ''}`,
7892
8254
  onClick: () => pickSort('relevance'),
7893
- disabled: kind === KIND_MEDIA,
7894
- title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.relevanceTitle'),
8255
+ disabled: kind === KIND_MEDIA || kind === KIND_CHANGES,
8256
+ title: kind === KIND_CHANGES ? t('sort.changesTitle') : (kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.relevanceTitle')),
7895
8257
  }, t('sort.relevance')),
7896
8258
  h('button', {
7897
8259
  className: `knit-seg-btn${effectiveSort === 'time' ? ' active' : ''}`,
7898
8260
  onClick: () => pickSort('time'),
7899
- disabled: kind === KIND_MEDIA,
7900
- title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.timeTitle'),
8261
+ disabled: kind === KIND_MEDIA || kind === KIND_CHANGES,
8262
+ title: kind === KIND_CHANGES ? t('sort.changesTitle') : (kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.timeTitle')),
7901
8263
  }, t('sort.time'))),
7902
8264
  // ⚠️ 2026-10-12 用户裁决:排序组与类型组之间**那根竖线去掉了** —— 它的类名与 CSS 规则都已整体删除。
7903
8265
  // 两组靠 `.knit-bar` 的 gap 分开就够 —— 「边界」不再需要一根线来表达。
@@ -7905,7 +8267,7 @@ video.knit-preview-media{width:100%;background:#000}
7905
8267
  // v0.23.1(2026-10-12 用户裁决):**三档**「文档 / 代码 / 媒体」——
7906
8268
  // 「全部」那一档连同它的混合浏览视图在整个界面上删除了(三档等距、页签样式不变)。
7907
8269
  // **没有第二层分类** —— 代码里不按语言(JS / TS / Python…)分组(需求 §46)。
7908
- [[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media']].map(([value, labelKey]) =>
8270
+ [[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media'], [KIND_CHANGES, 'kind.changes']].map(([value, labelKey]) =>
7909
8271
  h('button', {
7910
8272
  type: 'button',
7911
8273
  key: value,
@@ -7969,7 +8331,7 @@ video.knit-preview-media{width:100%;background:#000}
7969
8331
  摘要这一行永远紧贴工具栏,位置不随开关变;观察层仍是「列表上方的观察层」,
7970
8332
  而且比原来更贴近列表。⚠️ 别再把它挪回 `.knit-bar` 后面(有守卫钉着顺序)。
7971
8333
  v0.15:开了才显示。不是弹窗、不是新页面、不是 Dashboard。 */
7972
- usageOn ? lensNode : null,
8334
+ usageOn && kind !== KIND_CHANGES ? lensNode : null,
7973
8335
  // 列表节点**直接挂上去**(2026-09-29 起永远单栏;曾经它要交给一个 IIFE
7974
8336
  // 决定塞进单栏还是双栏的左列)。**输出与 v0.13 逐字一致** ——
7975
8337
  // 时间序、媒体档、「全部」都不受影响。