dsh-knit 0.16.0 → 0.17.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.
@@ -65,6 +65,29 @@ window.__ModuleLoader__.load({
65
65
  'usage.changes': '上下文换过 {n} 次',
66
66
  'usage.note': '只统计本会话 · 数据在内核内存里,重启 DSH 就没了',
67
67
 
68
+ // ── v0.17 文档生命周期(Document Lifecycle)──────────────────
69
+ // ⚠️ 四态全是**事实**,不是评价:「读后已更新」只说「文件在最后一次成功读取之后
70
+ // 变过」,绝不许写成「Agent 还不知道最新版本」「Agent 用了旧版本」这类推断。
71
+ // ⚠️ 「最近读取」不是「正在阅读」—— Knit 证明不了 Agent 此刻是否还在读它。
72
+ // ⚠️ 「上下文外读取」只陈述「这篇不在当前包内、但被成功读过」,
73
+ // 不许写成「Knit 漏了 / 推荐错了 / 命中率低」。
74
+ 'usage.recentRead': '最近读取:{rel} · {time}',
75
+ 'usage.outsideDocs': '上下文外读取 · {n} 篇',
76
+ 'usage.deltaTitle': '上下文刚刚变化',
77
+ 'usage.deltaEnter': '进入',
78
+ 'usage.deltaLeave': '离开',
79
+ 'usage.deltaMove': '换层',
80
+ 'usage.deltaTask': '任务上下文已更新',
81
+ 'usage.deltaMore': '还有 {n} 条',
82
+ 'lifecycle.unread': '未读',
83
+ 'lifecycle.read': '已读',
84
+ 'lifecycle.readCount': '已读 ×{n}',
85
+ 'lifecycle.updatedAfterRead': '读后已更新',
86
+ 'lifecycle.rereadAfterUpdate': '修改后已重新读取',
87
+ 'tierName.primary': '主要',
88
+ 'tierName.supporting': '辅助',
89
+ 'tierName.related': '相关',
90
+
68
91
  // ── v0.14 当前任务上下文(Context Pack)──────────────────────
69
92
  // ⚠️ 文案纪律:不出现「AI / 智能 / 推荐 / 置信度 / 百分比」。
70
93
  // 这一层是确定性规则算出来的,说成 AI 就是在骗用户。也不能放表情符号
@@ -211,6 +234,29 @@ window.__ModuleLoader__.load({
211
234
  'usage.changes': 'context changed {n}×',
212
235
  'usage.note': 'This session only · kept in kernel memory, gone after a DSH restart',
213
236
 
237
+ // ── v0.17 document lifecycle ───────────────────────────────
238
+ // ⚠️ All four states are facts, never judgements: "Updated after read" only says the
239
+ // file changed after the last successful read. Never "the agent has not seen the
240
+ // latest version" or "the agent used a stale copy" — that would be inference.
241
+ // ⚠️ "Recently read" is not "currently reading": Knit cannot prove the agent is
242
+ // still reading it. An out-of-pack file is shown as-is, with no explanation.
243
+ 'usage.recentRead': 'Recently read: {rel} · {time}',
244
+ 'usage.outsideDocs': 'Read outside the pack · {n}',
245
+ 'usage.deltaTitle': 'Context just changed',
246
+ 'usage.deltaEnter': 'Entered',
247
+ 'usage.deltaLeave': 'Left',
248
+ 'usage.deltaMove': 'Moved tier',
249
+ 'usage.deltaTask': 'Task context updated',
250
+ 'usage.deltaMore': '+{n} more',
251
+ 'lifecycle.unread': 'Unread',
252
+ 'lifecycle.read': 'Read',
253
+ 'lifecycle.readCount': 'Read ×{n}',
254
+ 'lifecycle.updatedAfterRead': 'Updated after read',
255
+ 'lifecycle.rereadAfterUpdate': 'Re-read after update',
256
+ 'tierName.primary': 'Primary',
257
+ 'tierName.supporting': 'Supporting',
258
+ 'tierName.related': 'Related',
259
+
214
260
  // ── v0.14 current-task context (Context Pack) ──────────────
215
261
  // ⚠️ Never say "AI", "smart", "recommended", "confidence" or show percentages:
216
262
  // this tiering is deterministic local rules, and pretending otherwise is a lie.
@@ -605,6 +651,24 @@ body[data-ds-dark-theme] .knit-root{
605
651
  color:var(--dsw-alias-label-caption,#80868b);
606
652
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
607
653
 
654
+ /* v0.17 文档生命周期(Document Lifecycle)—— 三条新信息,都只是**事实**。
655
+ ⚠️ 状态是文字,不是徽章:不加底色、不加边框、不用红绿 —— 红绿会把「事实」读成
656
+ 「好 / 坏」(PRD §7.3)。字号 10.5px,比 14px 的标题弱一档,永远不抢标题。
657
+ ⚠️ 折叠块沿用 .knit-usage 的弱化灰阶:它们是同一行事实的展开,不是新卡片。
658
+ ⚠️ 这一段**不含反引号**,整段可以直接放在 CSS 模板串里。 */
659
+ .knit-life{flex:none;font-size:10.5px;line-height:1.4;white-space:nowrap;
660
+ color:var(--dsw-alias-label-caption,#80868b)}
661
+ .knit-usage-more{margin-top:3px}
662
+ .knit-more-btn{appearance:none;border:0;background:none;margin:0;padding:0;
663
+ font:inherit;line-height:inherit;color:var(--dsw-alias-label-secondary,#9aa0a6);cursor:pointer}
664
+ .knit-more-btn:hover{color:var(--knit-accent)}
665
+ .knit-more-btn:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
666
+ .knit-gap-row,.knit-delta-row{display:flex;gap:6px;align-items:baseline;margin-top:2px;
667
+ color:var(--dsw-alias-label-caption,#80868b)}
668
+ .knit-gap-rel,.knit-delta-rel{flex:1 1 auto;min-width:0;overflow:hidden;
669
+ text-overflow:ellipsis;white-space:nowrap}
670
+ .knit-delta-head{margin-top:3px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
671
+
608
672
 
609
673
  /* ── v0.14 右栏(Context Pack 面板)已整体删除(2026-09-29)────────
610
674
  用户裁定:Context Pack 是**数据层**结构(Primary / Supporting / Related),
@@ -688,6 +752,15 @@ body[data-ds-dark-theme] .knit-root{
688
752
  再加描边会与 .active 的整块背景重复,显得突兀。
689
753
  (曾经有一条 「.knit-multicol .knit-doc.cursor」 的中性环,是为多列网格补的 ——
690
754
  多列没了,那条也删了。) */
755
+ /* ── 列表进出动效的**静态**部分(v0.17,2026-10-03 用户要求)───────────────
756
+ 补间本身在 JS 里用 WAAPI 跑(见 client.js 的 DocRow 与 MOTION_* 那段)—— 高度要按
757
+ 量出来的自然高度补间,CSS 的 @keyframes 做不到(height:auto 不可插值)。这里只管两件事:
758
+ ① .leaving =正在离开的幽灵行:不吃指针事件、内容裁掉;
759
+ ② 系统开了「减弱动态效果」时,连底色过渡一起去掉(进出本来就不播)。 */
760
+ .knit-doc.leaving{pointer-events:none;user-select:none;overflow:hidden}
761
+ @media (prefers-reduced-motion: reduce){
762
+ .knit-doc{transition:none}
763
+ }
691
764
  /* 行一=**标题行**:Primary 点 + 标题 + 相对时间(**时间靠右**)。
692
765
  2026-09-29 这一天里这一行改了三次:先是「序号 + 标题 + 时间」,然后
693
766
  「时间跟那个置顶的序号可以一行」(序号留下、标题移出去),再后来
@@ -1347,16 +1420,273 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1347
1420
  return `knit-opt-${safe}-${(hash >>> 0).toString(36)}`
1348
1421
  }
1349
1422
 
1350
- function DocRow({ doc, now, active, cursor, relevance, why, num, mark, primary, onSelect, onOpenTab, optionId }) {
1423
+ /* ── 列表进出动效(v0.17)─────────────────────────────────────────
1424
+ 用户原话(2026-10-03):「文档列表,新读取跟挤掉旧的未读的,这里的交互可能要优化,
1425
+ 因为现在是一闪一闪的,就非常的快……如果说从当前的,如辅助上下文中新增,它应该是
1426
+ 从低向上的,有种交互动效飞上的感觉,然后消失的时候从上到下,就隐掉了」。
1427
+
1428
+ 手感来自 `02_方案与 Demo/knit-list-motion-prototype.html`(用户点头的那一版):
1429
+ 缓动 cubic-bezier(.22,1,.36,1)、进入 translateY(26px)→0 + 渐现 + blur(3px)→0、
1430
+ 离开高度收到 0 且**自上而下**擦掉。参数照抄原型,不要再另调。
1431
+
1432
+ ⚠️ 只碰**文档行**(`.knit-doc`):媒体格子是网格布局,收起高度没有意义。
1433
+ ⚠️ 补间用 WAAPI(`Element.animate`)手写,不用 @keyframes —— 高度要按量出来的
1434
+ 自然高度补间,而 CSS 里 `height:auto` 不可插值。
1435
+ ⚠️ 行节点是按 key 复用的(`doc.path || doc.rel`),所以「闪」不是重挂 —— 是增删
1436
+ 瞬间落位、一点过渡都没有。因此动效分三件独立的事:**新来的行自己飞进来**、
1437
+ **走了的行留一个幽灵行把高度收掉**(React 一删节点就没机会补间了)、
1438
+ **活下来的行换了位置(换层 / 重排)走 FLIP** —— 量出新位置、先从老位置拉回来
1439
+ 再补间归位,逻辑也在 `KnitBody` 那次提交后的 layout effect 里(那里才有列表)。 */
1440
+ const MOTION_ENTER_MS = 320
1441
+ const MOTION_EXIT_MS = 260
1442
+ const MOTION_STAGGER_MS = 45
1443
+ const MOTION_STAGGER_MAX = 6
1444
+ const MOTION_EASE = 'cubic-bezier(.22,1,.36,1)'
1445
+ /** 幽灵行所在的「区」:分层视图用层名,平铺与「全部」各一个 —— 幽灵要插回原位。 */
1446
+ const MOTION_TIER_FLAT = 'flat'
1447
+ const MOTION_TIER_ALL_DOCS = 'all-docs'
1448
+ /** 幸存行位移(换层 / 重排)的 FLIP 时长:比进入略长,它要真的「走」完一段距离。 */
1449
+ const MOTION_MOVE_MS = 340
1450
+ /** 位移小于这个像素数(含亚像素抖动)就当没动过,不排补间。 */
1451
+ const MOTION_MOVE_EPS = 0.5
1452
+
1453
+ /**
1454
+ * 这台机器上要不要播动效。
1455
+ *
1456
+ * 三种情况**不播**:没有 DOM(Node 里的测试替身)、浏览器/系统要求「减弱动态效果」、
1457
+ * 以及不认 WAAPI 的宿主。返回假时一行补间都不排、也不留幽灵行 —— 渲染树与没有这段动效时逐字一致。
1458
+ *
1459
+ * @returns {boolean} 是否播动效
1460
+ */
1461
+ function motionAllowed() {
1462
+ if (typeof document === 'undefined' || typeof document.createElement !== 'function') return false
1463
+ if (typeof Element !== 'function' || typeof Element.prototype.animate !== 'function') return false
1464
+ const view = typeof window === 'undefined' ? null : window
1465
+ if (view && typeof view.matchMedia === 'function') {
1466
+ try {
1467
+ if (view.matchMedia('(prefers-reduced-motion: reduce)').matches) return false
1468
+ } catch (err) { /* matchMedia 抛错就当用户没提要求 */ }
1469
+ }
1470
+ return true
1471
+ }
1472
+
1473
+ /**
1474
+ * 算这一帧哪些行是**新来的**、哪些行**走了**(纯函数,测试直接喂它)。
1475
+ *
1476
+ * 「走了」的行带回它上一帧的 `tierKey` / `index` —— 幽灵行要靠这两个值插回原来的位置,
1477
+ * 不能一律塞到列表末尾(那样看起来是「这篇文档跳到了下面然后消失」)。
1478
+ *
1479
+ * ⚠️ 视图整体换掉时(换类型 / 换排序 / 搜索词变了)返回空:那是「换屏」,不是
1480
+ * 「列表里多了一行」,整屏一起飞会很吵(原型里首屏也刻意不播)。
1481
+ * ⚠️ 同一篇**换层**(rel 不变、tierKey 变了)既不算进入也不算离开 —— 这不是「不播」:
1482
+ * 那一行交给 `KnitBody` 里的 FLIP(`motionShift` + 上一帧按 rel 记下的矩形)。跨分区时
1483
+ * React 会重建节点,但位置是按 **rel** 记的,所以它照样能从老位置补间到新位置;
1484
+ * 在这里把它当「进入」反而会让它先闪一下再飞,两段补间会互相打架。
1485
+ *
1486
+ * @param {{view: string, rows: object[]}|null} prev - 上一帧的快照(没提交过就是 null)
1487
+ * @param {string} view - 本帧的视图签名
1488
+ * @param {object[]} rows - 本帧的行表,顺序=屏幕顺序
1489
+ * @returns {{entered: Array<{rel: string, delay: number}>, left: object[]}} 新来的 / 走了的
1490
+ */
1491
+ function planRowMotion(prev, view, rows) {
1492
+ const next = (Array.isArray(rows) ? rows : []).filter((row) => row && row.rel)
1493
+ if (!prev || prev.view !== view) return { entered: [], left: [] }
1494
+ const before = new Map((prev.rows || []).map((row) => [row.rel, row]))
1495
+ const after = new Set(next.map((row) => row.rel))
1496
+ const entered = []
1497
+ let order = 0
1498
+ for (const row of next) {
1499
+ if (before.has(row.rel)) continue
1500
+ entered.push({ rel: row.rel, delay: Math.min(order, MOTION_STAGGER_MAX) * MOTION_STAGGER_MS })
1501
+ order += 1
1502
+ }
1503
+ return {
1504
+ entered,
1505
+ left: (prev.rows || []).filter((row) => row && row.rel && !after.has(row.rel)),
1506
+ }
1507
+ }
1508
+
1509
+ /**
1510
+ * 幸存行这一帧**相对上一帧挪了多远**(FLIP 的第一步:算反方向的位移)。
1511
+ *
1512
+ * 纯函数:喂两个 `{left, top}` 位置(**布局坐标**,见 `rowLayoutPoint`),返回要「拉回来」的
1513
+ * 位移;没得比或者没动过就返回 `null`。
1514
+ *
1515
+ * ⚠️ 阈值不是洁癖:`offsetTop` 也会给亚像素值,浏览器缩放导致的零点几像素抖动如果也排一段
1516
+ * 补间,那一屏会一直有东西在微微地飘。
1517
+ *
1518
+ * @param {{left: number, top: number}|null} prev - 上一帧的位置(没记过就是 null)
1519
+ * @param {{left: number, top: number}|null} now - 这一帧的位置
1520
+ * @param {number} [threshold] - 小于它就算没动(默认 `MOTION_MOVE_EPS`)
1521
+ * @returns {{dx: number, dy: number}|null} 位移(正数=上一帧更靠右下,要往左上拉)
1522
+ */
1523
+ function motionShift(prev, now, threshold = MOTION_MOVE_EPS) {
1524
+ if (!prev || !now) return null
1525
+ const dx = prev.left - now.left
1526
+ const dy = prev.top - now.top
1527
+ if (!Number.isFinite(dx) || !Number.isFinite(dy)) return null
1528
+ if (Math.abs(dx) < threshold && Math.abs(dy) < threshold) return null
1529
+ return { dx, dy }
1530
+ }
1531
+
1532
+ /**
1533
+ * 一行在**列表自己的坐标系**里的位置 —— FLIP 量位置只能用这个。
1534
+ *
1535
+ * ⚠️ 不能拿 `getBoundingClientRect()` 当「位置」:它是**视口坐标**,于是三件与「谁换了位置」
1536
+ * 毫无关系的机械动作都会让整屏的行凭空产生位移 ——
1537
+ * ① 容器滚动(含滚动位置被 clamp);
1538
+ * ② 容器自己的高度 / 顶边变了(预览面板一开一合、头上那块「使用情况」长高一行);
1539
+ * ③ 行上挂着 transform(`.knit-doc:hover{transform:translateX(-2px)}` 是死区 0.5px 的四倍)。
1540
+ * 2026-10-04 交互审用户报的两件事都是它:「我一点它就跳……闪得很快」与「我没有输入任何对话,
1541
+ * 文档列表就开始跳动」。`offsetTop/offsetLeft` 是**布局坐标**:不含滚动、不含 transform,
1542
+ * 容器自己怎么变都不动它。节点拿不到 offset*(测试替身 / 已卸载)时才退回视口矩形,并减掉
1543
+ * 容器那一块,好歹把滚动与容器位移去掉。
1544
+ *
1545
+ * @param {{getBoundingClientRect?: Function, scrollLeft?: number, scrollTop?: number}|null} host - 列表容器
1546
+ * @param {object} el - 行节点
1547
+ * @returns {{left: number, top: number}|null} 布局坐标;量不到就是 null
1548
+ */
1549
+ function rowLayoutPoint(host, el) {
1550
+ if (!el) return null
1551
+ if (Number.isFinite(el.offsetTop) && Number.isFinite(el.offsetLeft)) {
1552
+ return { left: el.offsetLeft, top: el.offsetTop }
1553
+ }
1554
+ if (typeof el.getBoundingClientRect !== 'function') return null
1555
+ const box = el.getBoundingClientRect()
1556
+ if (!box) return null
1557
+ const base = host && typeof host.getBoundingClientRect === 'function'
1558
+ ? host.getBoundingClientRect()
1559
+ : null
1560
+ if (!base) return { left: box.left, top: box.top }
1561
+ return {
1562
+ left: box.left - base.left + (Number.isFinite(host.scrollLeft) ? host.scrollLeft : 0),
1563
+ top: box.top - base.top + (Number.isFinite(host.scrollTop) ? host.scrollTop : 0),
1564
+ }
1565
+ }
1566
+
1567
+ /**
1568
+ * 给这一帧**挪了位置**的幸存行排 FLIP,并返回这一帧的位置表留给下一帧。
1569
+ *
1570
+ * 换层(同一个 rel 从「包外」升进「Primary」)与区内重排都走这里。位置按 **rel** 记 ——
1571
+ * 跨分区时 React 会重建节点,老节点量到的位置照样能用在新节点上。
1572
+ *
1573
+ * ⚠️ 调用点必须是**提交之后**、绘制之前的 layout effect,而且在 `DocRow` 的进 / 出补间
1574
+ * **之后**(React 是子先父后):那一刻新行已经是 0 高、幽灵行还占着原高度,所以这里
1575
+ * 量到的位移就只剩「真的挪了位置」的行,不会和进 / 出补间算两遍。
1576
+ * ⚠️ `skip` 里的行(正在进 / 出的)一个都不碰:它们有自己的补间;幽灵行连数据都没有。
1577
+ * ⚠️ 只补 `transform`,不碰高度 —— 高度是进 / 出补间的事,两处都改会互相踩。
1578
+ *
1579
+ * @param {{querySelectorAll: Function}|null} host - 列表容器(`.knit-list`)
1580
+ * @param {Map<string, {left: number, top: number}>} before - 上一帧的位置表(按 rel,布局坐标)
1581
+ * @param {Set<string>} [skip] - 这一帧正在进 / 出的 rel
1582
+ * @returns {Map<string, {left: number, top: number}>} 这一帧的位置表(按 rel,布局坐标)
1583
+ */
1584
+ function applyRowFlips(host, before, skip) {
1585
+ const after = new Map()
1586
+ const was = before instanceof Map ? before : new Map()
1587
+ const nodes = host && typeof host.querySelectorAll === 'function'
1588
+ ? host.querySelectorAll('.knit-doc[data-knit-rel]') : []
1589
+ for (const el of nodes) {
1590
+ const rel = el && typeof el.getAttribute === 'function' ? el.getAttribute('data-knit-rel') : null
1591
+ if (!rel || (skip && skip.has(rel))) continue
1592
+ const point = rowLayoutPoint(host, el)
1593
+ if (!point) continue
1594
+ const shift = motionShift(was.get(rel), point)
1595
+ if (shift && typeof el.animate === 'function') {
1596
+ const anim = el.animate([
1597
+ { transform: `translate(${shift.dx}px, ${shift.dy}px)` },
1598
+ { transform: 'translate(0px, 0px)' },
1599
+ ], { duration: MOTION_MOVE_MS, easing: MOTION_EASE })
1600
+ if (anim && anim.finished && typeof anim.finished.catch === 'function') anim.finished.catch(() => {})
1601
+ }
1602
+ after.set(rel, { left: point.left, top: point.top })
1603
+ }
1604
+ return after
1605
+ }
1606
+
1607
+ /**
1608
+ * 把要「离开」的行插回它们**原来的位置**(纯函数)。
1609
+ *
1610
+ * 位置是上一帧记下来的 `index` —— 不插回原位的话,看到的会是「这篇文档跳到了列表
1611
+ * 末尾才消失」。数据里已经有同一篇时跳过:那一行还活着(比如它只是换了层),
1612
+ * 不该在同一区里再多出一个幽灵。
1613
+ *
1614
+ * @param {object[]} docs - 这一区这一帧的数据
1615
+ * @param {object[]} ghosts - 全部要离开的行(`{rel, doc, tierKey, index}`)
1616
+ * @param {string} tierKey - 哪一个区(分层视图=层名,平铺 / 「全部」各一个常量)
1617
+ * @returns {object[]} 带幽灵行的新数组(这一区没幽灵时原样返回)
1618
+ */
1619
+ function mergeGhostRows(docs, ghosts, tierKey) {
1620
+ const mine = []
1621
+ for (const ghost of Array.isArray(ghosts) ? ghosts : []) {
1622
+ if (ghost && ghost.tierKey === tierKey) mine.push(ghost)
1623
+ }
1624
+ if (mine.length === 0) return docs
1625
+ mine.sort((a, b) => a.index - b.index)
1626
+ const out = docs.slice()
1627
+ for (const ghost of mine) {
1628
+ if (out.some((doc) => doc.rel === ghost.rel)) continue
1629
+ out.splice(Math.min(ghost.index, out.length), 0, { ...ghost.doc, knitLeaving: true })
1630
+ }
1631
+ return out
1632
+ }
1633
+
1634
+ function DocRow({ doc, now, active, cursor, relevance, why, num, mark, primary, life,
1635
+ onSelect, onOpenTab, optionId, entering, leaving }) {
1351
1636
  const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
1637
+ const rowRef = React.useRef(null)
1638
+
1639
+ /* 进 / 出两段补间都跑在 **layout effect** 里:放到 paint 之后会先闪一帧完整高度的
1640
+ 行,那正是用户抱怨的那一下。没有 DOM 时 `motionAllowed()` 直接挡掉。 */
1641
+ React.useLayoutEffect(() => {
1642
+ if (!motionAllowed()) return
1643
+ const el = rowRef.current
1644
+ if (!el || typeof el.getBoundingClientRect !== 'function') return
1645
+ const box = el.getBoundingClientRect()
1646
+ const height = box && box.height > 0 ? box.height : 0
1647
+ if (height <= 0) return
1648
+ // 量的高度是 border-box,补间也得按 border-box 算,否则第一帧会把行撑高一个内边距。
1649
+ el.style.boxSizing = 'border-box'
1650
+ if (leaving) {
1651
+ // 离开:高度收到 0,同时**自上而下**擦掉(clip-path 的 top 从 0 涨到 100%),
1652
+ // 末尾补一点模糊 —— 与原型里那条 mask 擦除是同一个读法。
1653
+ el.style.overflow = 'hidden'
1654
+ const anim = el.animate([
1655
+ { height: `${height}px`, clipPath: 'inset(0% 0 0 0)', opacity: 1, filter: 'blur(0px)' },
1656
+ { height: `${height * 0.55}px`, clipPath: 'inset(45% 0 0 0)', opacity: 0.7, filter: 'blur(1px)', offset: 0.55 },
1657
+ { height: '0px', clipPath: 'inset(100% 0 0 0)', opacity: 0, filter: 'blur(2px)' },
1658
+ ], { duration: MOTION_EXIT_MS, easing: MOTION_EASE, fill: 'forwards' })
1659
+ if (anim && anim.finished && typeof anim.finished.catch === 'function') anim.finished.catch(() => {})
1660
+ return
1661
+ }
1662
+ if (entering === null || entering === undefined) return
1663
+ // 进入:先把高度收成 0 再补间到自然高度 —— 下面的行是被**挤**下去的,不是跳下去的
1664
+ // (原型里踩过的坑:不先量自然高度,插入瞬间会把下面那行蹬一下)。
1665
+ el.style.overflow = 'hidden'
1666
+ const anim = el.animate([
1667
+ { height: '0px', transform: 'translateY(26px)', opacity: 0, filter: 'blur(3px)' },
1668
+ { height: `${height}px`, transform: 'translateY(0)', opacity: 1, filter: 'blur(0px)' },
1669
+ ], { duration: MOTION_ENTER_MS, delay: entering, easing: MOTION_EASE, fill: 'both' })
1670
+ const done = anim && anim.finished
1671
+ if (done && typeof done.then === 'function') {
1672
+ done.then(() => { el.style.height = ''; el.style.overflow = '' }).catch(() => {})
1673
+ } else {
1674
+ el.style.height = ''
1675
+ el.style.overflow = ''
1676
+ }
1677
+ })
1352
1678
 
1353
1679
  return h('div', {
1354
- className: `knit-doc${active ? ' active' : ''}${cursor ? ' cursor' : ''}${fresh ? ' fresh' : ''}`,
1680
+ className: `knit-doc${active ? ' active' : ''}${cursor ? ' cursor' : ''}${fresh ? ' fresh' : ''}${leaving ? ' leaving' : ''}`,
1681
+ ref: rowRef,
1355
1682
  // listbox 的选项语义:有 role 才能被读成「N 项中的第 i 项」,
1356
1683
  // 有 aria-selected 才能播报「当前选中」。
1357
1684
  role: 'option',
1358
1685
  id: optionId,
1359
1686
  'aria-selected': active ? 'true' : 'false',
1687
+ // 「正在离开」的幽灵行已经不在数据里了(点不动、键盘也到不了),
1688
+ // 只是占着位置把高度收掉 —— 别让它被读成一项。
1689
+ 'aria-hidden': leaving ? 'true' : undefined,
1360
1690
  'data-knit-rel': doc.rel,
1361
1691
  title: t('row.tooltip', { path: doc.rel }),
1362
1692
  onClick: () => onSelect(doc),
@@ -1385,6 +1715,13 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1385
1715
  h('div', { className: 'knit-title' },
1386
1716
  fresh ? h('span', { className: 'knit-badge' }, '🆕') : null,
1387
1717
  doc.title || doc.name),
1718
+ // v0.17:生命周期状态(文案已算好;没有证据时是 null,一个节点都不加)。
1719
+ // 插在**标题与时间之间**:`.knit-title` 是 flex:1 1 auto,会把状态与时间一起推到
1720
+ // 行尾,状态在时间左侧、行尾仍然是时间。
1721
+ // ⚠️ 状态是**纯文字**:不加图标、不加底色、不加边框、不用红绿表达好坏 ——
1722
+ // 它陈述事实,不是评分(AGENTS.md §6.2 / PRD §7.3)。字号比标题弱一档,
1723
+ // 永远不抢标题。
1724
+ life ? h('span', { className: 'knit-life' }, life) : null,
1388
1725
  // 时间在标题右边的行尾 —— 靠 .knit-title 的 flex-grow 推过去,不是靠 margin。
1389
1726
  h('div', { className: 'knit-time' }, relTime(doc.mtimeMs, now))),
1390
1727
  doc.summary
@@ -1581,7 +1918,15 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1581
1918
 
1582
1919
  return h('div', {
1583
1920
  className: 'knit-preview',
1584
- style: fullscreen ? undefined : { maxHeight: `${Math.round(ratio * 100)}%` },
1921
+ /* ⚠️ 高度**打开期间是固定的**(= 拖出来的那个比例),不是 `maxHeight`(2026-10-04 交互审)。
1922
+ 原来是 `maxHeight: 46%` ⇒ 面板高度由**内容**决定,于是:
1923
+ ① 点一篇 → 先出「加载中」(一两行高),正文到了再窜到 46% ⇒ 列表跟着一伸一缩;
1924
+ ② 在预览里点「相关文档」换一篇 ⇒ 正文长短变了 ⇒ 列表又跟着一伸一缩。
1925
+ 用户的原话是「我选中一个文档查看全文……我一点它就跳,我一点它就很跳,闪的很快」。
1926
+ 固定高度之后这两次几何变化一次都不发生:加载中 / 换篇都不再改动列表的高度,
1927
+ 长文照样在 `.knit-preview-body` 里滚(它本来就是 `overflow-y:auto`)。
1928
+ 短文档会因此下方留白 —— 这是拿「点一下不跳」换来的,别再改回 maxHeight。 */
1929
+ style: fullscreen ? undefined : { height: `${Math.round(ratio * 100)}%` },
1585
1930
  },
1586
1931
  fullscreen ? null : h('div', { className: 'knit-resize', onPointerDown: onResizeStart, title: t('preview.resizeTitle') }),
1587
1932
  h('div', { className: 'knit-preview-head' },
@@ -1674,6 +2019,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1674
2019
  // 的顺序被测试按位预置,别插队。
1675
2020
  const [usageOn, setUsageOn] = React.useState(readUsagePref)
1676
2021
 
2022
+ // v0.17:两个折叠块的开合状态(上下文外读取 / 最近一次变化)。
2023
+ // **纯瞬时 UI 状态** —— 不写 pref、不进 `dsh-knit:*` 存储,刷新即回默认(收起)。
2024
+ // 仍然放在最后:前面那些 hook 的位置被测试按位预置,别插队。
2025
+ const [gapOpen, setGapOpen] = React.useState(false)
2026
+ const [deltaOpen, setDeltaOpen] = React.useState(false)
2027
+
1677
2028
  /* ── 曾经在这里的三个状态 + 一个 ref:右栏的形态 ──────────
1678
2029
  `packWidth`(310) / `packFloat`(null) / `packSnap`(false) / `packColRef`。
1679
2030
  **2026-09-29 随右栏一起删除**。当时它们**只存在内存里**(刷新回默认值),
@@ -1793,12 +2144,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1793
2144
  * 时间序、筛选结果、「其他相关文档」都不编号 —— 但**这一屏里有号时**,没号的行会在
1794
2145
  * 同一列拿到 `mark`(渲染 `.knit-gapmark` 占位),算法见下面。
1795
2146
  */
1796
- const docsGrid = (docs, numbers, primary) => {
2147
+ const docsGrid = (docs, numbers, primary, withLife) => {
1797
2148
  // 一屏里「要么都有号、要么都没有」(2026-10-01):只要这个视图里存在序号,
1798
2149
  // 没号的那些行(「其他相关文档」)就在同一列渲染占位标记;整屏没号时不渲染。
1799
2150
  const mark = Boolean(numbers && numbers.size > 0)
1800
2151
  return docs.map((doc) =>
1801
- renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark))
2152
+ renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark, withLife))
1802
2153
  }
1803
2154
 
1804
2155
  const relevance = state.mode === 'relevance'
@@ -1827,7 +2178,9 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1827
2178
  h('div', { className: 'knit-tierline', role: 'presentation' },
1828
2179
  h('span', { className: 'knit-tiername' }, t(section.titleKey)),
1829
2180
  section.hintKey ? h('span', { className: 'knit-tierhint' }, t(section.hintKey)) : null),
1830
- docsGrid(section.docs, view.numbers, section.key === 'primary')))
2181
+ // ⚠️ 幽灵行(正在离开的)也走 `docsGrid`,所以它照样是一个 `.knit-doc` ——
2182
+ // 会被 `byClass` 数到,但**不在** `navDocs` 里(键盘与 cursor 都到不了)。
2183
+ docsGrid(withGhosts(section.key, section.docs), view.numbers, section.key === 'primary', true)))
1831
2184
 
1832
2185
  /* ── 曾经在这里的一个函数:`contextPanel` ─────────────────
1833
2186
  它渲染右栏那三样东西(当前任务原文 / 「命中 N 篇」/ 三条证据行)。
@@ -1912,15 +2265,23 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
1912
2265
  if (!navDocs.some((doc) => doc.rel === cursor)) setCursor(navDocs[0].rel)
1913
2266
  }, [navDocs, cursor])
1914
2267
 
1915
- // 键盘焦点跟手滚进视口(测试环境没有 DOM,静默跳过)
2268
+ /* 键盘焦点跟手滚进视口(测试环境没有 DOM,静默跳过)。
2269
+ ⚠️ 2026-10-04(交互审的那个 bug):这里曾经把 `state.docs` 也放进依赖里,而那是**每 5 秒
2270
+ 轮询一次的新数组** —— 于是「刷新到了新数据」被当成了「用户按了方向键」。光标默认落在第一行,
2271
+ 用户往下滚过之后那一行必然不在视口里 ⇒ 列表每 5 秒被拽回第一行一次,用户的原话是
2272
+ 「我没有输入任何的对话……文档列表就开始跳动」。滚动**只在光标真的换了**(或搜索词变了)时发生,
2273
+ 而且只在列表拿着键盘焦点时发生 —— 这条服务的是键盘导航;鼠标点过 / 悬停过的行本来就在视口里,
2274
+ 而「数据刷新」一次都不该动列表。 */
1916
2275
  React.useEffect(() => {
1917
2276
  if (!cursor || typeof document === 'undefined') return
1918
2277
  const host = listRef.current
1919
2278
  if (!host || typeof host.querySelector !== 'function') return
2279
+ const active = document.activeElement
2280
+ if (active !== host && !(active && host.contains && host.contains(active))) return
1920
2281
  const escaped = typeof CSS !== 'undefined' && CSS.escape ? CSS.escape(cursor) : cursor
1921
2282
  const el = host.querySelector(`[data-knit-rel="${escaped}"]`)
1922
2283
  if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest' })
1923
- }, [cursor, query, state.docs])
2284
+ }, [cursor, query])
1924
2285
 
1925
2286
  // 预览高度:拖完就记住
1926
2287
  React.useEffect(() => { writePref(RATIO_KEY, String(ratio)) }, [ratio])
@@ -2177,8 +2538,150 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2177
2538
 
2178
2539
 
2179
2540
 
2180
- /** 渲染一个条目:媒体一律出方形卡片(媒体视图与「全部」的媒体区共用),其余出文档行。 */
2181
- const renderEntry = (doc, num, primary, mark) => {
2541
+ /**
2542
+ * v0.17:这一篇当前的**事实状态**,文案已按语言算好(没有证据时是 null)。
2543
+ *
2544
+ * ⚠️ 只有「使用情况」开着、并且宿主真的回传了 `usage` 时才有文案 —— 关掉时
2545
+ * 一个状态节点都不渲染,DOM 与 v0.16 逐字一致。
2546
+ * ⚠️ `lifecycle` 里没有这篇 = 本会话没有一次成功 read ⇒ 未读。这是事实陈述,
2547
+ * 不是「你漏了它」的提醒,更不许写成「Agent 忽略了它」(PRD §8)。
2548
+ * ⚠️ 状态值本身是英文(数据层只有一个口径),中文只存在于词典(§15.4 / §24)。
2549
+ *
2550
+ * @param {string} rel - 相对路径
2551
+ * @returns {string|null} 状态文案
2552
+ */
2553
+ const lifecycleLabel = (rel) => {
2554
+ if (!usageOn) return null
2555
+ const usageNow = state.usage
2556
+ if (!usageNow || !usageNow.stats) return null
2557
+ const row = usageNow.lifecycle && usageNow.lifecycle[rel]
2558
+ const status = row ? row.status : 'unread'
2559
+ if (status === 'unread') return t('lifecycle.unread')
2560
+ if (status === 'read') {
2561
+ return row && row.count >= 2 ? t('lifecycle.readCount', { n: row.count }) : t('lifecycle.read')
2562
+ }
2563
+ if (status === 'updated_after_read') return t('lifecycle.updatedAfterRead')
2564
+ if (status === 'reread_after_update') return t('lifecycle.rereadAfterUpdate')
2565
+ return null
2566
+ }
2567
+
2568
+ /* ── 列表进出动效:这一帧谁新来了、谁走了 ─────────────────────────
2569
+ (参数与手感见模块级 `planRowMotion` / `MOTION_*` 那段注释。)
2570
+
2571
+ ⚠️ 渲染期**只读** `motionRef`,落盘与计时器都在下面的 layout effect 里 ——
2572
+ 并发渲染下这一帧可能根本没提交,渲染里写 ref 会把幽灵行记进一个被丢掉的帧。 */
2573
+ const motionRef = React.useRef({
2574
+ committed: null,
2575
+ ghosts: new Map(),
2576
+ timers: new Map(),
2577
+ positions: new Map(),
2578
+ // 位置表是在**哪一屏**量下来的(视图签名)。换屏时必须整表作废:见下面 settled 那条。
2579
+ view: '',
2580
+ // 进 / 出补间还在飞的截止时刻(毫秒时间戳)。那段时间里行高是中间态,量不得。
2581
+ tweenUntil: 0,
2582
+ })
2583
+ const [, setMotionSeq] = React.useState(0)
2584
+ const motionOn = motionAllowed()
2585
+ // 视图签名:换类型 / 换排序 / 搜索词变了都算「换屏」——整屏一起飞会很吵。
2586
+ const motionView = `${kind}|${state.mode}|${query.trim()}`
2587
+ // 只列**真会渲染成 .knit-doc 的行**,顺序=屏幕顺序(幽灵行要按这个位置插回去)。
2588
+ const motionRows = (() => {
2589
+ if (state.status === 'error' || state.docs.length === 0 || visibleDocs.length === 0) return []
2590
+ if (kind === KIND_MEDIA) return [] // 媒体格子不参与:网格里收起高度没有意义
2591
+ if (kind === KIND_ALL) {
2592
+ if (docItems.length === 0) return []
2593
+ return shownDocs.map((doc, index) => (
2594
+ { rel: doc.rel, tierKey: MOTION_TIER_ALL_DOCS, index, doc }))
2595
+ }
2596
+ if (contextView) {
2597
+ const rows = []
2598
+ for (const section of contextView.sections) {
2599
+ section.docs.forEach((doc, index) => rows.push(
2600
+ { rel: doc.rel, tierKey: section.key, index, doc }))
2601
+ }
2602
+ return rows
2603
+ }
2604
+ return visibleDocs.map((doc, index) => (
2605
+ { rel: doc.rel, tierKey: MOTION_TIER_FLAT, index, doc }))
2606
+ })()
2607
+ const motion = (() => {
2608
+ const live = new Set(motionRows.map((row) => row.rel))
2609
+ const plan = motionOn
2610
+ ? planRowMotion(motionRef.current.committed, motionView, motionRows)
2611
+ : { entered: [], left: [] }
2612
+ const ghosts = new Map()
2613
+ if (motionOn) {
2614
+ // 上一帧留下的幽灵,这一帧还不在数据里 ⇒ 继续收着(同一篇回来了就撤掉)。
2615
+ for (const [rel, ghost] of motionRef.current.ghosts) if (!live.has(rel)) ghosts.set(rel, ghost)
2616
+ for (const row of plan.left) {
2617
+ if (ghosts.has(row.rel)) continue
2618
+ ghosts.set(row.rel, { rel: row.rel, doc: row.doc, tierKey: row.tierKey, index: row.index })
2619
+ }
2620
+ }
2621
+ return { entered: new Map(plan.entered.map((row) => [row.rel, row.delay])), ghosts, live }
2622
+ })()
2623
+ React.useLayoutEffect(() => {
2624
+ const store = motionRef.current
2625
+ store.committed = motionOn && motionRows.length > 0 ? { view: motionView, rows: motionRows } : null
2626
+ store.ghosts = motion.ghosts
2627
+ for (const [rel, timer] of store.timers) {
2628
+ if (motion.ghosts.has(rel)) continue
2629
+ clearTimeout(timer)
2630
+ store.timers.delete(rel)
2631
+ }
2632
+ for (const rel of motion.ghosts.keys()) {
2633
+ if (store.timers.has(rel)) continue
2634
+ // 补间跑完(外加一点交错余量)就把幽灵行摘掉 —— 摘的时候高度已经是 0,
2635
+ // 所以下面的行不会再跳一下。
2636
+ const timer = setTimeout(() => {
2637
+ store.timers.delete(rel)
2638
+ if (!store.ghosts.has(rel)) return
2639
+ const next = new Map(store.ghosts)
2640
+ next.delete(rel)
2641
+ store.ghosts = next
2642
+ setMotionSeq((n) => n + 1)
2643
+ }, MOTION_EXIT_MS + MOTION_STAGGER_MS)
2644
+ store.timers.set(rel, timer)
2645
+ }
2646
+ /* ── 活下来的行换了位置:FLIP(算法在模块级 `applyRowFlips`)────
2647
+ 正在进 / 出的行不参与:它们有自己的补间(幽灵行连数据都没有,别去量)。
2648
+
2649
+ ⚠️ 另外两种时候**一个都不量**(2026-10-04 交互审那两个 bug 的正主):
2650
+ ① **换屏**(视图签名变了):那是「整屏换了一批内容」,不是「列表里有人挪了位置」。
2651
+ `planRowMotion` 对换屏就是不播,FLIP 却会照两张布局的差把每一行都补一遍 ——
2652
+ 换排序 / 第一次拿到数据 / 搜索词一变,整屏一起飞。
2653
+ ② **进 / 出补间还在飞**:那几百毫秒里行高在 0 与自然高之间,量到的全是中间态。
2654
+ 拿中间态当基准,等补间落地后下一帧就把这段位移当成「有人挪了位置」再补一遍 ——
2655
+ 一屏就这么飘起来(而且会一直飘:每次进 / 出都留下一个错基准)。
2656
+ 两种时候都把位置表**清空**(不是照记):清空等于「没有上一帧可比」,下一帧只会安静
2657
+ 落位、不补间;等落地后再量一帧,基准就又是干净的了。 */
2658
+ const tweening = store.tweenUntil > Date.now()
2659
+ if (motion.entered.size > 0 || motion.ghosts.size > 0) {
2660
+ // 取较长的那一套(进入 + 一点交错余量),离开比它短,等它一定够了。
2661
+ store.tweenUntil = Date.now() + MOTION_ENTER_MS + MOTION_STAGGER_MS
2662
+ }
2663
+ const skip = new Set([...motion.entered.keys(), ...motion.ghosts.keys()])
2664
+ const settled = motionOn
2665
+ && motionRows.length > 0
2666
+ && !tweening
2667
+ && motion.entered.size === 0
2668
+ && motion.ghosts.size === 0
2669
+ && store.view === motionView
2670
+ store.positions = settled ? applyRowFlips(listRef.current, store.positions, skip) : new Map()
2671
+ store.view = motionView
2672
+ })
2673
+ React.useEffect(() => () => {
2674
+ for (const timer of motionRef.current.timers.values()) clearTimeout(timer)
2675
+ motionRef.current.timers.clear()
2676
+ }, [])
2677
+ /** 把这一帧要「离开」的行按原位插回去(只在真机上会非空,逻辑在 `mergeGhostRows`)。 */
2678
+ const withGhosts = (tierKey, docs) =>
2679
+ mergeGhostRows(docs, [...motion.ghosts.values()], tierKey)
2680
+
2681
+ /** 渲染一个条目:媒体一律出方形卡片(媒体视图与「全部」的媒体区共用),其余出文档行。
2682
+ * `withLife` 只有**分层视图**(Context Pack 三层 + 其他相关文档)才给真 —— 时间序、
2683
+ * 筛选结果、「全部」都不显示生命周期:那一屏说的不是「这个包里的文档现在什么状态」。 */
2684
+ const renderEntry = (doc, num, primary, mark, withLife) => {
2182
2685
  const common = {
2183
2686
  key: doc.path || doc.rel,
2184
2687
  doc,
@@ -2194,7 +2697,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2194
2697
  // 于是返回空串,那一行不渲染。
2195
2698
  // `num` / `primary` 只有分层视图会传(Design §11 / §13);平铺列表照旧无序号。
2196
2699
  // `mark`=没号时同列的占位标记,只在「这一屏里有号」时为真。
2197
- return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary })
2700
+ // 进出动效只在真机上跑(`motionOn`):测试替身没有 DOM,`motionAllowed()` 挡掉,
2701
+ // 于是渲染树里既没有 `entering` 也没有 `leaving`,与没有这段动效时逐字一致。
2702
+ return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary,
2703
+ life: withLife ? lifecycleLabel(doc.rel) : null,
2704
+ entering: motion.entered.has(doc.rel) ? motion.entered.get(doc.rel) : null,
2705
+ leaving: Boolean(doc.knitLeaving) })
2198
2706
  }
2199
2707
 
2200
2708
  /** 「全部」的分区标题:类型名 + 「已显示 / 总数」+ 被截断时的「查看全部」。 */
@@ -2216,7 +2724,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2216
2724
  const allSections = [
2217
2725
  docItems.length === 0 ? null : h('div', { className: 'knit-section', key: 'docs' },
2218
2726
  sectionHead('kind.doc', shownDocs.length, docItems.length, KIND_DOC),
2219
- docsGrid(shownDocs)),
2727
+ docsGrid(withGhosts(MOTION_TIER_ALL_DOCS, shownDocs))),
2220
2728
  mediaItems.length === 0 ? null : h('div', { className: 'knit-section', key: 'media' },
2221
2729
  // 媒体不截断,所以只给一个标题,不给「已显示 / 总数」和「查看全部」
2222
2730
  h('div', { className: 'knit-section-head' },
@@ -2242,7 +2750,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2242
2750
  ? allSections
2243
2751
  : contextView
2244
2752
  ? contextBody(contextView)
2245
- : docsGrid(visibleDocs)
2753
+ : docsGrid(withGhosts(MOTION_TIER_FLAT, visibleDocs))
2246
2754
 
2247
2755
  // 排序说明那一行(.knit-topic)**2026-09-30 已整体删除**:排序方式由头部那个
2248
2756
  // 「相关 / 最新」切换按钮自己表达(按钮上就写着当前选的是哪个),再补一句
@@ -2276,6 +2784,92 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2276
2784
  return parts.join(' · ')
2277
2785
  })()
2278
2786
 
2787
+ /* v0.17:三条新事实 —— 全部只在「使用情况」开着、且宿主真的回传了 `usage` 时出现。
2788
+ ① 最近读取(按事件 seq 认「谁是最近一次」,墙钟只用来算相对时间)
2789
+ ② 上下文外读取的明细(当前包外、但真实成功读过)
2790
+ ③ 最近**一次** Context Delta
2791
+ ⚠️ 关掉使用情况时**一个节点都不加**:DOM 与 v0.16 逐字一致。
2792
+ ⚠️ 这里没有时间线、没有全量事件、没有评分 —— 「最近一次」就只有一条。 */
2793
+ const usageFacts = usageOn && state.usage && state.usage.stats ? state.usage : null
2794
+
2795
+ const recentReadNode = usageFacts && usageFacts.recentRead && usageFacts.recentRead.rel
2796
+ ? h('div', { className: 'knit-usage-more' },
2797
+ t('usage.recentRead', {
2798
+ rel: usageFacts.recentRead.rel,
2799
+ time: relTime(usageFacts.recentRead.at, tick),
2800
+ }))
2801
+ : null
2802
+
2803
+ const outsideList = usageFacts && Array.isArray(usageFacts.outsideDocs) ? usageFacts.outsideDocs : []
2804
+ const gapNode = outsideList.length > 0
2805
+ ? h('div', { className: 'knit-usage-more', key: 'gap' },
2806
+ h('button', {
2807
+ className: 'knit-more-btn',
2808
+ type: 'button',
2809
+ 'aria-expanded': gapOpen ? 'true' : 'false',
2810
+ onClick: () => setGapOpen((value) => !value),
2811
+ }, t('usage.outsideDocs', { n: outsideList.length })),
2812
+ gapOpen ? h('div', { className: 'knit-gap-list' },
2813
+ outsideList.slice(0, 10).map((row) => h('div', { className: 'knit-gap-row', key: row.rel },
2814
+ h('span', { className: 'knit-gap-rel', title: row.rel }, row.rel),
2815
+ h('span', { className: 'knit-life' }, lifecycleLabel(row.rel))))) : null)
2816
+ : null
2817
+
2818
+ // 层级的**短名**:分组标题那套长文案(主要上下文 / 辅助上下文 / 相关上下文)在变化行里太长。
2819
+ const tierShort = (key) => {
2820
+ if (key === 'primary') return t('tierName.primary')
2821
+ if (key === 'supporting') return t('tierName.supporting')
2822
+ if (key === 'related') return t('tierName.related')
2823
+ return ''
2824
+ }
2825
+ const delta = usageFacts && usageFacts.latestDelta ? usageFacts.latestDelta : null
2826
+ const deltaLine = (text, key) => h('div', { className: 'knit-delta-row', key },
2827
+ h('span', { className: 'knit-delta-rel' }, text))
2828
+ // 摘要行的符号只用 `+` `-` `↔` 三个通用符号,不用颜色区分「进 / 出」。
2829
+ const deltaDigest = []
2830
+ if (delta) {
2831
+ for (const item of (Array.isArray(delta.appeared) ? delta.appeared : [])) {
2832
+ deltaDigest.push({ key: `plus-${item.rel}`, text: `+ ${item.rel}` })
2833
+ }
2834
+ for (const item of (Array.isArray(delta.disappeared) ? delta.disappeared : [])) {
2835
+ deltaDigest.push({ key: `minus-${item.rel}`, text: `- ${item.rel}` })
2836
+ }
2837
+ for (const item of (Array.isArray(delta.moved) ? delta.moved : [])) {
2838
+ deltaDigest.push({
2839
+ key: `move-${item.rel}`,
2840
+ text: `↔ ${item.rel} · ${tierShort(item.from)} → ${tierShort(item.to)}`,
2841
+ })
2842
+ }
2843
+ if (delta.taskChanged) deltaDigest.push({ key: 'task', text: t('usage.deltaTask') })
2844
+ }
2845
+ const deltaGroups = delta ? [
2846
+ { key: 'enter', label: t('usage.deltaEnter'), rows: deltaDigest.filter((line) => line.key.startsWith('plus-')) },
2847
+ { key: 'leave', label: t('usage.deltaLeave'), rows: deltaDigest.filter((line) => line.key.startsWith('minus-')) },
2848
+ { key: 'move', label: t('usage.deltaMove'), rows: deltaDigest.filter((line) => line.key.startsWith('move-')) },
2849
+ ] : []
2850
+ const deltaNode = delta
2851
+ ? h('div', { className: 'knit-usage-more', key: 'delta' },
2852
+ h('button', {
2853
+ className: 'knit-more-btn',
2854
+ type: 'button',
2855
+ 'aria-expanded': deltaOpen ? 'true' : 'false',
2856
+ onClick: () => setDeltaOpen((value) => !value),
2857
+ }, t('usage.deltaTitle')),
2858
+ deltaDigest.slice(0, 3).map((line) => deltaLine(line.text, line.key)),
2859
+ deltaDigest.length > 3
2860
+ ? deltaLine(t('usage.deltaMore', { n: deltaDigest.length - 3 }), 'more')
2861
+ : null,
2862
+ deltaOpen ? deltaGroups
2863
+ .filter((group) => group.rows.length > 0)
2864
+ .map((group) => [
2865
+ h('div', { className: 'knit-delta-head', key: `${group.key}-head` }, group.label),
2866
+ ...group.rows.slice(0, 5).map((line) => deltaLine(line.text, `${group.key}-${line.key}`)),
2867
+ group.rows.length > 5
2868
+ ? deltaLine(t('usage.deltaMore', { n: group.rows.length - 5 }), `${group.key}-more`)
2869
+ : null,
2870
+ ]) : null)
2871
+ : null
2872
+
2279
2873
  // 不同类型用不同量词:文档「篇」、媒体「个」、混排「项」。
2280
2874
  const countKey = kind === KIND_MEDIA
2281
2875
  ? (filtering ? 'count.media.filtered' : 'count.media')
@@ -2345,7 +2939,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
2345
2939
  onClick: () => pickKind(value),
2346
2940
  }, t(labelKey)))),
2347
2941
  // v0.15:开了才显示。一行事实,没有卡片、没有分数条。
2348
- usageOn ? h('div', { className: 'knit-usage', title: t('usage.note') }, usageText || t('usage.none')) : null,
2942
+ // v0.17:这一行下面最多再加三块 —— 最近读取、上下文外读取(折叠)、最近一次变化(折叠)。
2943
+ usageOn ? h('div', { className: 'knit-usage', title: t('usage.note') },
2944
+ usageText || t('usage.none'),
2945
+ recentReadNode,
2946
+ gapNode,
2947
+ deltaNode) : null,
2349
2948
  notice ? h('div', { className: 'knit-notice' }, notice) : null,
2350
2949
  // 列表节点**直接挂上去**(2026-09-29 起永远单栏;曾经它要交给一个 IIFE
2351
2950
  // 决定塞进单栏还是双栏的左列)。**输出与 v0.13 逐字一致** ——