dsh-knit 0.20.0 → 0.21.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/CHANGELOG.md +123 -0
- package/README.en.md +109 -0
- package/README.md +92 -3
- package/SECURITY.md +3 -2
- package/package.json +2 -2
- package/src/client/client.js +530 -50
- package/src/host/context.js +42 -6
- package/src/host/control.js +421 -0
- package/src/host/index.js +224 -6
- package/src/host/links.js +74 -24
- package/src/host/relations.js +306 -0
- package/src/host/tool.js +96 -6
- package/test/client.test.mjs +540 -12
- package/test/code-context.test.mjs +3 -1
- package/test/context-eval.test.mjs +5 -1
- package/test/context.test.mjs +32 -2
- package/test/control.test.mjs +324 -0
- package/test/deep-corpus.mjs +110 -0
- package/test/deep-scale.test.mjs +1 -1
- package/test/harness.mjs +6 -2
- package/test/host-http.test.mjs +107 -0
- package/test/i18n.test.mjs +12 -6
- package/test/links.test.mjs +50 -0
- package/test/relations.test.mjs +360 -0
- package/test/tier1.test.mjs +2 -2
- package/test/tool.test.mjs +79 -1
package/src/client/client.js
CHANGED
|
@@ -138,6 +138,45 @@ window.__ModuleLoader__.load({
|
|
|
138
138
|
'context.supportingHint': '辅助',
|
|
139
139
|
'context.relatedHint': '背景',
|
|
140
140
|
'context.why': '为什么在这里',
|
|
141
|
+
// ── v0.21 上下文控制(固定 / 排除)与关系来源 ────────────────────
|
|
142
|
+
// ⚠️ 三个来源词是**中性词**:来源只说明「它怎么进来的」,不表达强弱。
|
|
143
|
+
// 所以它们一色到底(都是 caption 灰),靠**字**区分,不靠颜色。
|
|
144
|
+
'context.pinned': '固定上下文',
|
|
145
|
+
'context.pinnedHint': '你自己标记的',
|
|
146
|
+
'prov.retrieval': '检索',
|
|
147
|
+
'prov.relation': '关系',
|
|
148
|
+
'prov.manual': '用户固定',
|
|
149
|
+
'control.pin': '固定',
|
|
150
|
+
'control.unpin': '取消固定',
|
|
151
|
+
'control.exclude': '排除',
|
|
152
|
+
'control.restore': '恢复',
|
|
153
|
+
'control.excluded': '被用户排除:{rel}',
|
|
154
|
+
'control.failed': '操作没生效:{error}',
|
|
155
|
+
// 行级证据(需求 §6.2):类型 + 方向 + 谁 + 第几行 + 打开。点「为什么」才展开。
|
|
156
|
+
'rel.toggle': '点开看这一行的证据',
|
|
157
|
+
'rel.references': '引用',
|
|
158
|
+
'rel.imports': '导入',
|
|
159
|
+
'rel.tests': '测试',
|
|
160
|
+
'rel.documents': '描述',
|
|
161
|
+
'rel.line': '第 {line} 行',
|
|
162
|
+
'rel.open': '打开',
|
|
163
|
+
'rel.more': '共 {n} 条关系,每项最多投影 {max} 条(预算,不是建议)',
|
|
164
|
+
// 检索状态摘要(需求 §6.3):**分组与顺序本身就是这条设计要传达的信息** ——
|
|
165
|
+
// 工作区候选 | 检索与调整 | 最终结果;三组之间是细竖线,组内是中点(见 CSS 的 .knit-pipe)。
|
|
166
|
+
// ⚠️ 每一格都是**已经发生过的事实**,不是估算,也不许改成别的口径(见宿主侧注释)。
|
|
167
|
+
'pipe.collect': '收集 {n}',
|
|
168
|
+
'pipe.exclude': '排除 {n}',
|
|
169
|
+
// v0.21.x(2026-10-09 用户规格):排除之后的候选数原来是一个**光数字**(只有
|
|
170
|
+
// 「→ 79」),现在给它一个名字 —— 状态摘要里每一格都必须能独立读懂。
|
|
171
|
+
'pipe.candidates': '候选 {n}',
|
|
172
|
+
'pipe.rank': 'BM25 词法检索',
|
|
173
|
+
// ⚠️ 「关系 N 条」说的是**这一份包里带了几条关系证据**(三层各条 relations 之和),
|
|
174
|
+
// 不是工作区里的关系总数、也不是候选数(那两类数字宿主另有字段,这里不展示)。
|
|
175
|
+
'pipe.relations': '关系 {n} 条',
|
|
176
|
+
// ⚠️ 「固定 N」= 有几篇被你固定、因此**从三层移出**进了固定区(pack.pinned 的长度)。
|
|
177
|
+
// 不写「固定覆盖」这种内部说法;也不带量词 —— 固定对象可能是文档、代码或媒体。
|
|
178
|
+
'pipe.pin': '固定 {n}',
|
|
179
|
+
'pipe.pack': '入包 {n}',
|
|
141
180
|
// 理由码 → 文案。宿主只给码(AGENTS.md §4.5),翻译在这里。
|
|
142
181
|
// ⚠️ 2026-09-29 用户要求把这行压得更克制:原来是「直接命中当前话题:…」,
|
|
143
182
|
// 读起来像调试信息。现在它是**标签 + 值**,词之间用「 · 」分隔。
|
|
@@ -365,6 +404,35 @@ window.__ModuleLoader__.load({
|
|
|
365
404
|
'context.supportingHint': 'supporting',
|
|
366
405
|
'context.relatedHint': 'background',
|
|
367
406
|
'context.why': 'Why it is here',
|
|
407
|
+
// ── v0.21 context control (pin / exclude) and relation provenance ──
|
|
408
|
+
// ⚠️ The three provenance words are **neutral**: provenance says how an item got
|
|
409
|
+
// in, not how strong it is — so they share one colour and differ by word.
|
|
410
|
+
'context.pinned': 'Pinned',
|
|
411
|
+
'context.pinnedHint': 'you marked these',
|
|
412
|
+
'prov.retrieval': 'retrieved',
|
|
413
|
+
'prov.relation': 'relation',
|
|
414
|
+
'prov.manual': 'pinned',
|
|
415
|
+
'control.pin': 'Pin',
|
|
416
|
+
'control.unpin': 'Unpin',
|
|
417
|
+
'control.exclude': 'Exclude',
|
|
418
|
+
'control.restore': 'Restore',
|
|
419
|
+
'control.excluded': 'Excluded by you: {rel}',
|
|
420
|
+
'control.failed': 'Action failed: {error}',
|
|
421
|
+
'rel.toggle': 'open the evidence for this line',
|
|
422
|
+
'rel.references': 'references',
|
|
423
|
+
'rel.imports': 'imports',
|
|
424
|
+
'rel.tests': 'tests',
|
|
425
|
+
'rel.documents': 'documents',
|
|
426
|
+
'rel.line': 'line {line}',
|
|
427
|
+
'rel.open': 'Open',
|
|
428
|
+
'rel.more': '{n} relations total, at most {max} projected per item',
|
|
429
|
+
'pipe.collect': '{n} collected',
|
|
430
|
+
'pipe.exclude': '{n} excluded',
|
|
431
|
+
'pipe.candidates': '{n} candidates',
|
|
432
|
+
'pipe.rank': 'BM25 lexical retrieval',
|
|
433
|
+
'pipe.relations': '{n} relations',
|
|
434
|
+
'pipe.pin': '{n} pinned',
|
|
435
|
+
'pipe.pack': '{n} in pack',
|
|
368
436
|
// Reason codes → copy. The host only ships codes (AGENTS.md §4.5).
|
|
369
437
|
// ⚠️ Flattened on 2026-09-29: "direct topic match: …" read like debug output.
|
|
370
438
|
'why.direct': 'direct match: {term}',
|
|
@@ -593,6 +661,14 @@ window.__ModuleLoader__.load({
|
|
|
593
661
|
// v0.12:某篇的「谁引用了它 / 它引用了谁」。与上面三条一样是**同源相对地址**,
|
|
594
662
|
// 所以仍然满足「客户端零网络出口」那条守卫(test/security.test.mjs)。
|
|
595
663
|
const LINKS_API = '/knit/api/links'
|
|
664
|
+
// v0.21:整个 HTTP 面**唯一**的写动作(固定 / 排除)。只回环、只 POST、只认
|
|
665
|
+
// `{action, rel}`;工作区根由 `sessionId` 解析 —— 与其余路由同一条纪律。
|
|
666
|
+
const CONTROL_API = '/knit/api/control'
|
|
667
|
+
// v0.21:**镜像**宿主的面板投影上限(`src/host/relations.js` 的
|
|
668
|
+
// `MAX_RELATIONS_PER_ITEM = 3`)。客户端只需要它来写「共 N 条关系,每项最多投影 3 条」
|
|
669
|
+
// 那句话 —— 真正的截断在宿主做,这里**不截断**(截断两次就会出现两份真相)。
|
|
670
|
+
// ⚠️ 两个数字必须一致:`test/client.test.mjs` 有一条源码级守卫同时读两侧。
|
|
671
|
+
const REL_MAX = 3
|
|
596
672
|
|
|
597
673
|
/** 轮询间隔。 */
|
|
598
674
|
const POLL_MS = 5000
|
|
@@ -841,8 +917,17 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
841
917
|
横本身就是 .5px,色值对上而粗细仍写 1px,高分屏上比它粗一倍。三处同粗:.knit-seg
|
|
842
918
|
外框、.knit-seg 内部竖线、.knit-filter。CSS 里统一写 0.5px(与官方 .wSkVaW_header 的 .5px 同值)。
|
|
843
919
|
⚠️ 选中态只改**底色 + 字重 600**(不是 700),hover 只改底色 —— 不许 scale / translate /
|
|
844
|
-
box-shadow(md §五)。暗色下靠 --knit-active-bg 这个 token,不写死颜色。
|
|
920
|
+
box-shadow(md §五)。暗色下靠 --knit-active-bg 这个 token,不写死颜色。
|
|
921
|
+
⚠️ 2026-10-09(v0.21.x 用户规格):这一行现在是**三组一行**,顺序就是控件顺序,
|
|
922
|
+
别再挪 —— ① 排序「相关 / 最新」(灰底分段控件)② 一条浅灰竖线
|
|
923
|
+
③ 类型「文档 / 代码 / 媒体 / 全部」(下划线页签)④ 搜索框(排尾、贴右、宽度自适应)。
|
|
924
|
+
那根竖线是**边界**,不是把六个选项连成一个整体:排序与类型是两个互不干扰的条件,
|
|
925
|
+
搜索只过滤当前范围、不重置它们(用户规格 §三.3)。 */
|
|
845
926
|
.knit-bar{display:flex;align-items:center;gap:8px;padding:0 12px 8px;flex:none}
|
|
927
|
+
/* 排序组与类型组之间**就这一根线**(用户规格 §二.2:中间用一条浅灰竖线与排序区隔开)。
|
|
928
|
+
色号取 .knit-seg 外框、.knit-filter 描边同一个 border-l3 ⇒ 三处一样淡;粗细写 1px ——
|
|
929
|
+
0.5px 的竖线在高分屏上会淡到看不见,它不是描边而是分隔。纯装饰:aria-hidden。 */
|
|
930
|
+
.knit-bar-sep{flex:none;width:1px;height:16px;background:var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
846
931
|
.knit-seg{display:inline-flex;flex:none;border-radius:10px;overflow:hidden;
|
|
847
932
|
border:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
848
933
|
.knit-seg-btn{height:28px;padding:0 15px;cursor:pointer;font-size:13px;font-weight:400;
|
|
@@ -852,7 +937,11 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
852
937
|
.knit-seg-btn:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
853
938
|
.knit-seg-btn.active{background:var(--knit-active-bg,rgba(255,255,255,.085));
|
|
854
939
|
color:var(--dsw-alias-label-primary,#e8eaed);font-weight:600}
|
|
855
|
-
|
|
940
|
+
/* 搜索框在工具栏**尾部**(用户规格 §二.3:搜索是对当前列表的进一步过滤,放最右符合
|
|
941
|
+
工具栏惯例)。flex-basis 180px + grow ⇒ 常规面板里就是 180–240px 并贴住右边;
|
|
942
|
+
max-width 240px 封顶之后剩下的空间交给 margin-left:auto(否则它会一路长到面板边缘)。
|
|
943
|
+
⚠️ min-width:0 = 面板窄了**先缩搜索框**;前面两组都 flex:none,永远不被它挤。 */
|
|
944
|
+
.knit-filter{flex:1 1 180px;min-width:0;max-width:240px;margin-left:auto;height:28px;padding:0 12px;border-radius:10px;font-size:13px;
|
|
856
945
|
background:transparent;color:var(--dsw-alias-label-primary,#e8eaed);
|
|
857
946
|
border:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12));outline:none;
|
|
858
947
|
transition:border-color .16s ease}
|
|
@@ -1053,8 +1142,12 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
1053
1142
|
「这样就会减少文档列表的高度」。命中段在左(本版最该被看见的那一格),
|
|
1054
1143
|
中间一条 1px 中性竖线分隔 —— 不是虚线、不是分隔带、不加底色。
|
|
1055
1144
|
⚠️ 仍然**独占一行**,不并到标题行右侧:那里的省略号会把它截成
|
|
1056
|
-
「标题命中当前…」,恰好把要传达的东西吃掉(Design §11 的字段顺序不变)。
|
|
1145
|
+
「标题命中当前…」,恰好把要传达的东西吃掉(Design §11 的字段顺序不变)。
|
|
1146
|
+
2026-10-08 用户规格:这一行的**右端**现在是操作组(固定 / 排除 / 来源词),
|
|
1147
|
+
所以行本身是「左证据 + 右动作」的两段式 —— 左边 flex:1 可截断,右边 flex:none。
|
|
1148
|
+
行高不变、也不因为动作出现或隐藏而跳动(隐藏用的是 visibility,位置一直留着)。 */
|
|
1057
1149
|
.knit-subrow{display:flex;flex-wrap:nowrap;align-items:baseline;gap:8px;min-width:0;padding-top:2px}
|
|
1150
|
+
.knit-subrow-main{flex:1 1 auto;display:flex;flex-wrap:nowrap;align-items:baseline;gap:8px;min-width:0}
|
|
1058
1151
|
.knit-subrow-sep{flex:none;align-self:stretch;width:1px;margin:2px 0;
|
|
1059
1152
|
background:var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
1060
1153
|
/* 11px 而不是 10px,因为它承担的是**信息**(可核验的理由),不是装饰标注。 */
|
|
@@ -1075,6 +1168,94 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
1075
1168
|
border-radius:6px;background:var(--knit-chip-bg,rgba(255,255,255,.12));font:inherit;
|
|
1076
1169
|
font-size:11px;line-height:15px;cursor:pointer;color:var(--dsw-alias-label-secondary,#61666b)}
|
|
1077
1170
|
.knit-hit:hover,.knit-hit:focus-visible{color:var(--dsw-alias-label-primary,#0f1115);text-decoration:underline}
|
|
1171
|
+
/* ── v0.21 来源词 / 行级证据 / 固定与排除(需求 §6、§8)────────────
|
|
1172
|
+
这一层整体是**弱化层**:来源、动作、证据都排在标题与摘要之下,字号 10–11px、
|
|
1173
|
+
都是 caption / tertiary 灰。两条纪律:
|
|
1174
|
+
① **来源不是强弱**:检索 / 关系 / 用户固定 三个词**共用一种灰**,靠字区分,
|
|
1175
|
+
不做彩色徽标、不做分数(需求 §8:颜色只用来区分来源,不用来表达强弱);
|
|
1176
|
+
② 证据列表是「点开才有」的第二层,默认一个节点都不渲染(默认视图一个字节都不变)。
|
|
1177
|
+
2026-10-08 用户规格(v0.21.x 布局改造):来源词从标题行搬进证据行右端的操作组,
|
|
1178
|
+
成为那一组里的**第三个文字按钮**(固定 → 排除 → 来源词)—— 于是它不能再是
|
|
1179
|
+
一枚有底色的胶囊(§3.4:默认根本不显示,出现时就是克制的文字操作)。
|
|
1180
|
+
⚠️ 它仍然是「这一条怎么进来的」这条**事实**:没有图标、没有描边、同一种灰;
|
|
1181
|
+
有关系可展开时才是 button(多一个 hover / 焦点的下划线反馈),
|
|
1182
|
+
没有证据可展开时就是一个 span:**不装成能点的样子**。 */
|
|
1183
|
+
.knit-prov{flex:none;margin:0;padding:0 5px;border:0;outline:none;background:transparent;
|
|
1184
|
+
border-radius:5px;font:inherit;font-size:11px;line-height:15px;
|
|
1185
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
1186
|
+
button.knit-prov{cursor:pointer}
|
|
1187
|
+
button.knit-prov:hover,button.knit-prov:focus-visible{background:var(--knit-hover-bg,rgba(255,255,255,.03));
|
|
1188
|
+
color:var(--dsw-alias-label-primary,#0f1115)}
|
|
1189
|
+
/* 证据行右端的操作组:固定 → 排除 → 来源词。
|
|
1190
|
+
**默认整组不显示** —— 悬停到这一行、键盘光标在这一行(.cursor 类)、这一行处于
|
|
1191
|
+
选中态(.active 类)、或焦点进入这一行(:focus-within)才出现(2026-10-08 用户规格 §3.3)。
|
|
1192
|
+
⚠️ 用 visibility:hidden 而**不是** opacity:0:隐藏时必须同时退出焦点序与命中测试,
|
|
1193
|
+
否则「看不见却 Tab 得到 / 点得到」就是骗人的(§3.3 第 4 条)。
|
|
1194
|
+
⚠️ 没有 opacity / visibility 的过渡动画(§3.3 第 6 条:不加悬停动画、发光、装饰)。
|
|
1195
|
+
⚠️ flex:none + visibility ⇒ 出现与隐藏都**不改变行高、不推挤左侧证据**。 */
|
|
1196
|
+
.knit-rowacts{flex:none;display:flex;align-items:center;gap:2px;visibility:hidden}
|
|
1197
|
+
.knit-doc:hover .knit-rowacts,.knit-doc.active .knit-rowacts,.knit-doc.cursor .knit-rowacts,
|
|
1198
|
+
.knit-doc:focus-within .knit-rowacts{visibility:visible}
|
|
1199
|
+
.knit-act{flex:none;margin:0;padding:0 5px;border:0;outline:none;background:transparent;
|
|
1200
|
+
border-radius:5px;font:inherit;font-size:11px;line-height:15px;cursor:pointer;
|
|
1201
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
1202
|
+
.knit-act:hover,.knit-act:focus-visible{background:var(--knit-hover-bg,rgba(255,255,255,.03));
|
|
1203
|
+
color:var(--dsw-alias-label-primary,#0f1115)}
|
|
1204
|
+
/* 2026-10-09 用户反馈(真机体验过第一版之后):① 「固定 / 排除 / 检索 这个字号有点太小了,
|
|
1205
|
+
可以跟命中段一样大小」⇒ 10px → **11px / 15px**,与命中段(.knit-hit)同档;
|
|
1206
|
+
② 「悬停的时候那个背景可以再左右各加 4 个像素,热区有点小、有点点不到」⇒
|
|
1207
|
+
padding 5px → **9px**,同时用 **-4px 的负外边距**把那 4px 从布局宽度里收回来:
|
|
1208
|
+
于是**行宽与三个词之间的视觉间距一点没变**,只有悬停底色与可点区域向左右各长 4px。
|
|
1209
|
+
⚠️ 只作用于证据行右端这一组(恢复那个单独的 .knit-act 不动,它旁边没有兄弟会被挤)。 */
|
|
1210
|
+
.knit-rowacts .knit-act,.knit-rowacts .knit-prov{padding:0 9px;margin:0 -4px}
|
|
1211
|
+
/* 「为什么」在**有关系可看**时是一个按钮(点开就是那一行的证据),但看起来必须仍是
|
|
1212
|
+
一行灰字:没有图标、没有描边、没有底色,只有 hover 时加下划线 —— 与 .knit-hit
|
|
1213
|
+
同一套语言(那是事实,不是操作)。
|
|
1214
|
+
⚠️ 文本**一个字节都没变**(test/client.test.mjs 按 knit-why 取这一行的原文)。 */
|
|
1215
|
+
button.knit-why{margin:0;padding:0;border:0;outline:none;background:transparent;font:inherit;
|
|
1216
|
+
font-size:11px;line-height:17px;text-align:left;cursor:pointer;
|
|
1217
|
+
color:var(--dsw-alias-label-tertiary,#81858c)}
|
|
1218
|
+
button.knit-why:hover,button.knit-why:focus-visible{color:var(--dsw-alias-label-secondary,#61666b);
|
|
1219
|
+
text-decoration:underline}
|
|
1220
|
+
/* 行级证据(需求 §6.2):默认不渲染,点开才有。每条一行,四个字段都不省略:
|
|
1221
|
+
类型 · 方向 · 谁 · 第几行。.knit-relline 用等宽体承接行号(对齐扫读)。 */
|
|
1222
|
+
.knit-rellist{margin-top:4px;padding:5px 0 0;display:flex;flex-direction:column;gap:2px;
|
|
1223
|
+
border-top:.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
1224
|
+
.knit-relrow{display:flex;align-items:baseline;gap:6px;min-width:0;font-size:11px;line-height:16px;
|
|
1225
|
+
color:var(--dsw-alias-label-tertiary,#81858c)}
|
|
1226
|
+
.knit-reltag{flex:none;font-size:10px;padding:0 4px;border-radius:4px;
|
|
1227
|
+
background:var(--knit-active-bg,rgba(38,49,72,.061));color:var(--dsw-alias-label-caption,#80868b)}
|
|
1228
|
+
.knit-relwho{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1229
|
+
.knit-relline{flex:none;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:10.5px}
|
|
1230
|
+
.knit-relopen{flex:none;margin:0;padding:0 4px;border:0;outline:none;background:transparent;
|
|
1231
|
+
border-radius:4px;font:inherit;font-size:10px;line-height:15px;cursor:pointer;
|
|
1232
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
1233
|
+
.knit-relopen:hover,.knit-relopen:focus-visible{color:var(--dsw-alias-label-primary,#0f1115);
|
|
1234
|
+
text-decoration:underline}
|
|
1235
|
+
.knit-relmore{font-size:10px;line-height:16px;color:var(--dsw-alias-label-caption,#80868b)}
|
|
1236
|
+
/* 被用户排除的那一行:**单行弱化说明**,空的时候不出现、也不占位(需求 §6.3)。
|
|
1237
|
+
它说的是「这一批少了什么」,所以用中性描边而不是警告色 —— 这不是错误,是用户的选择。 */
|
|
1238
|
+
.knit-excl{flex:none;display:flex;align-items:baseline;gap:6px;margin:0 12px 6px;padding:5px 8px;
|
|
1239
|
+
border-radius:6px;font-size:11px;line-height:16px;
|
|
1240
|
+
background:var(--knit-hover-bg,rgba(255,255,255,.03));color:var(--dsw-alias-label-caption,#80868b)}
|
|
1241
|
+
.knit-excl-what{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1242
|
+
/* 检索状态摘要(需求 §6.3;2026-10-09 用户规格重排):**单行、三组、竖线分组** ——
|
|
1243
|
+
收集 79 · 排除 0 · 候选 79 | BM25 词法检索 · 关系 24 条 · 固定 0 | 入包 9。
|
|
1244
|
+
三组就是阅读顺序:工作区候选 → 检索与调整 → 最终结果。
|
|
1245
|
+
⚠️ 箭头(↓ / →)和「检索 / 排序(BM25 词法)」「关系投影」「固定覆盖」这些内部说法
|
|
1246
|
+
**已整体删除** —— 它们把一条**已经完成**的管线画成了流程图(用户原话:箭头「增加理解成本」)。
|
|
1247
|
+
⚠️ 它仍然只是一串计数:没有图标、没有胶囊、没有卡片、没有色块、没有装饰性边框,
|
|
1248
|
+
只有灰字 + 中点 + 一根细竖线。
|
|
1249
|
+
⚠️ 中点与竖线都是**文本节点**(不是伪元素、不是边框):它们跟同一行流排版,
|
|
1250
|
+
基线天然对齐,窄面板换行时也不会留下一条贴边的孤线。
|
|
1251
|
+
⚠️ 这段是模板字符串:注释里**不许出现反引号**(AGENTS.md §6.1,踩过三回了)。 */
|
|
1252
|
+
.knit-pipe{flex:none;display:flex;align-items:baseline;flex-wrap:wrap;gap:4px;
|
|
1253
|
+
margin:0 12px 8px;font-size:10.5px;line-height:15px;
|
|
1254
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
1255
|
+
.knit-pipecell{flex:none;white-space:nowrap}
|
|
1256
|
+
.knit-pipecell.strong{color:var(--dsw-alias-label-secondary,#61666b);font-weight:500}
|
|
1257
|
+
.knit-pipedot,.knit-pipesep{flex:none;color:var(--dsw-alias-label-caption,#80868b)}
|
|
1258
|
+
.knit-pipesep{margin:0 3px}
|
|
1078
1259
|
/* 滚动条**不要自己画**:DSH 主题里已有全局样式
|
|
1079
1260
|
(::-webkit-scrollbar 宽 8px + --dsh-scrollbar-thumb,见 dsh-client-ui-theme)。
|
|
1080
1261
|
曾经在这里写死 6px 宽 + rgba(255,255,255,.14) 的滑块 —— 白色 14% 在白底上完全隐形,
|
|
@@ -1352,8 +1533,13 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
|
|
|
1352
1533
|
⚠️ 2026-09-30 用户反馈:页签条底下原本还有一条全宽 hairline(border-l1)——
|
|
1353
1534
|
「最细最淡那条横线」与下面的列表割裂,**删掉**。层级现在只由选中项自己那条
|
|
1354
1535
|
2px 下划线表达,页签条本身不画线(也不是「下划线悬空」:它画在自己的文字下面)。
|
|
1355
|
-
⚠️ 排序切换(.knit-seg-btn,Design §18)是**另一个控件**,它保持灰底不变。
|
|
1356
|
-
.knit-
|
|
1536
|
+
⚠️ 排序切换(.knit-seg-btn,Design §18)是**另一个控件**,它保持灰底不变。
|
|
1537
|
+
⚠️ 2026-10-09(v0.21.x 用户规格):这一组从**自己一行**搬进了 .knit-bar,排在排序组
|
|
1538
|
+
右边、与它之间隔一根 .knit-bar-sep。于是这里**不再自带左右 12px 内边距**(那是
|
|
1539
|
+
.knit-bar 的事,再写一遍就是双重缩进、两组对不齐)。下划线式选中态**保持不变** ——
|
|
1540
|
+
用户这次说「选中项用浅色背景或文字强调即可」,下划线 + 主色文字正是「文字强调」,
|
|
1541
|
+
而且它覆盖 2026-09-29 那条「不要灰底」的裁决,不要因为并排就退回灰底按钮。 */
|
|
1542
|
+
.knit-types{display:flex;gap:14px;flex:none}
|
|
1357
1543
|
.knit-type-btn{flex:none;height:30px;padding:0;cursor:pointer;
|
|
1358
1544
|
border:none;border-bottom:2px solid transparent;background:transparent;
|
|
1359
1545
|
color:var(--dsw-alias-label-secondary,#9aa0a6);font-family:inherit;font-size:14px;
|
|
@@ -2030,6 +2216,34 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2030
2216
|
return true
|
|
2031
2217
|
}
|
|
2032
2218
|
|
|
2219
|
+
/**
|
|
2220
|
+
* 入场补间播完时的**收尾**:注销补间 + 清掉那两行内联样式。
|
|
2221
|
+
*
|
|
2222
|
+
* ⚠️ `cancel()` 不是可省的礼节,是这件事的全部要点:入场补间用 `fill:'both'`
|
|
2223
|
+
* (延迟期间要按住 `height:0`),而 **fill 会在补间播完之后继续生效** ——
|
|
2224
|
+
* 于是这一行被**入场那一刻量到的高度**永久钉住;`el.style.height=''` 清不掉它
|
|
2225
|
+
* (内联样式与补间效果是两层)。后果:之后行内长出新的内容(点开「检索」多出来的
|
|
2226
|
+
* 那几条行级证据)不会把下面的行挤下去,而是**溢出到下一行上面**。
|
|
2227
|
+
* 2026-10-09 用户真机截图报的「检索的数据压在下一个列表的下面」就是它。
|
|
2228
|
+
*
|
|
2229
|
+
* 纯对象即可测(替身里没有 DOM,跑不到 DocRow 那段 layout effect ⇒
|
|
2230
|
+
* `test/client.test.mjs` 直接喂假 el / 假 anim 守这一条,并另有一条钉住调用点)。
|
|
2231
|
+
*
|
|
2232
|
+
* @param {{style?: object}|null} el - 行节点
|
|
2233
|
+
* @param {{cancel?: Function}|null} anim - `el.animate()` 返回的补间
|
|
2234
|
+
*/
|
|
2235
|
+
function settleEnterAnim(el, anim) {
|
|
2236
|
+
if (anim && typeof anim.cancel === 'function') {
|
|
2237
|
+
try {
|
|
2238
|
+
anim.cancel()
|
|
2239
|
+
} catch (err) { /* cancel 抛错也不能把收尾卡住 */ }
|
|
2240
|
+
}
|
|
2241
|
+
if (el && el.style) {
|
|
2242
|
+
el.style.height = ''
|
|
2243
|
+
el.style.overflow = ''
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2033
2247
|
/**
|
|
2034
2248
|
* 算这一帧哪些行是**新来的**、哪些行**走了**(纯函数,测试直接喂它)。
|
|
2035
2249
|
*
|
|
@@ -2192,7 +2406,12 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2192
2406
|
}
|
|
2193
2407
|
|
|
2194
2408
|
function DocRow({ doc, now, active, cursor, relevance, why, num, mark, primary, life,
|
|
2195
|
-
glyph, onGlyph, onSelect, onOpenTab, passage, onPassage, optionId, entering, leaving
|
|
2409
|
+
glyph, onGlyph, onSelect, onOpenTab, passage, onPassage, optionId, entering, leaving,
|
|
2410
|
+
// ── v0.21(需求 §6.3 / §8):来源徽标、行级证据、固定与排除 ──────────
|
|
2411
|
+
// 全部是**可选** props:平铺列表(时间序 / 过滤结果)一个都不传,那一屏与 v0.20
|
|
2412
|
+
// 逐字相同。`onAct` 为 null ⇒ 不渲染动作按钮;`relations` 为空 ⇒ 「为什么」退回
|
|
2413
|
+
// 纯文本(没有证据就不装成有证据的样子)。
|
|
2414
|
+
prov, pinned, onAct, relations, relationsTotal, whyOpen, onWhyToggle, onOpenRelation }) {
|
|
2196
2415
|
const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
|
|
2197
2416
|
const rowRef = React.useRef(null)
|
|
2198
2417
|
/* v0.19:只有**代码行**带语言徽章。
|
|
@@ -2236,12 +2455,12 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2236
2455
|
{ height: `${height}px`, transform: 'translateY(0)', opacity: 1, filter: 'blur(0px)' },
|
|
2237
2456
|
], { duration: MOTION_ENTER_MS, delay: entering, easing: MOTION_EASE, fill: 'both' })
|
|
2238
2457
|
const done = anim && anim.finished
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2458
|
+
// ⚠️ 收尾必须**注销补间**(`settleEnterAnim` 里那句 `cancel()`)——
|
|
2459
|
+
// 只清 `el.style.height` 会把这一行按入场高度永久钉住,之后点开「检索」
|
|
2460
|
+
// 长出来的证据列表就只会溢出到下一行上面(2026-10-09 用户真机反馈)。
|
|
2461
|
+
const settle = () => settleEnterAnim(el, anim)
|
|
2462
|
+
if (done && typeof done.then === 'function') done.then(settle).catch(settle)
|
|
2463
|
+
else settle()
|
|
2245
2464
|
})
|
|
2246
2465
|
|
|
2247
2466
|
return h('div', {
|
|
@@ -2319,6 +2538,11 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2319
2538
|
// 永远不抢标题。
|
|
2320
2539
|
life ? h('span', { className: 'knit-life' }, life) : null,
|
|
2321
2540
|
// 时间在标题右边的行尾 —— 靠 .knit-title 的 flex-grow 推过去,不是靠 margin。
|
|
2541
|
+
// ⚠️ 2026-10-08 用户规格:标题行**到此为止** —— 只剩「序号 · 标记 · 标题 · 时间」。
|
|
2542
|
+
// 来源词(检索 / 关系 / 用户固定)与固定 / 排除原来都挤在这一行的右端,
|
|
2543
|
+
// 现在全部搬到下面那条证据行的右端(见 `.knit-subrow` / `.knit-rowacts`)。
|
|
2544
|
+
// 原因:来源与命中段、理由说的是**同一件事的两级证据**,而固定 / 排除是
|
|
2545
|
+
// 操作入口 —— 四样东西并排 = 标题行信息过载,且每一行都重复一遍。
|
|
2322
2546
|
h('div', { className: 'knit-time' }, relTime(doc.mtimeMs, now))),
|
|
2323
2547
|
doc.summary
|
|
2324
2548
|
? h('div', { className: 'knit-sum' }, doc.summary)
|
|
@@ -2337,25 +2561,120 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2337
2561
|
// 分两行等于每行都变高;合一行列表就矮回来一格。
|
|
2338
2562
|
// ⚠️ 这一行**仍然独占一行**,不并进标题行:标题右侧的省略号会把它截成
|
|
2339
2563
|
// 「标题命中当前…」,恰好把要传达的东西吃掉(Design §11 字段顺序不变)。
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2564
|
+
// ── 2026-10-08 用户规格(v0.21.x 布局改造):这一行现在是**证据行 + 操作行** ──
|
|
2565
|
+
// 左边=证据(命中段 | 理由),右边=三个文字动作(固定 → 排除 → 来源词)。
|
|
2566
|
+
// 为什么来源词也搬到这里:它和命中段、理由说的是**同一层证据**(这一条怎么进来的),
|
|
2567
|
+
// 而固定 / 排除是操作入口 —— 原来四样东西并排挤在标题行右端,是信息过载。
|
|
2568
|
+
// ⚠️ 那一组默认**不显示**(`.knit-rowacts` 的 `visibility:hidden`),
|
|
2569
|
+
// 悬停到这一行 / 键盘光标在这一行 / 焦点进入这一行才出现。
|
|
2570
|
+
// ⚠️ 没有命中段、也没有理由时这一行**仍然渲染**(左边就是空的,一个字的占位都不写):
|
|
2571
|
+
// 否则那一条会连固定 / 排除的入口一起没有。为什么不留占位文字 —— 需求 §6.4
|
|
2572
|
+
// 「没有证据就不装成有证据的样子」,所以这里连一个「—」都不给。
|
|
2573
|
+
(passage || why || onAct || prov) ? h('div', { className: 'knit-subrow' },
|
|
2574
|
+
// 左(flex:1 1 auto,可被截断)=证据。右(flex:none)=动作,永远有位置:
|
|
2575
|
+
// 窄宽度下先截证据,不让动作压到证据上面(需求 §3.2)。
|
|
2576
|
+
h('div', { className: 'knit-subrow-main' },
|
|
2577
|
+
/* ── 命中段(需求 §12)─────────────────────────────────────────
|
|
2578
|
+
只有一个行号区间 —— 这是「文件 → 相关内容片段」升级在列表里唯一露出的
|
|
2579
|
+
那一格。它**不是**:分数、百分比、置信度、AI 摘要、高亮预览卡片
|
|
2580
|
+
(§26 明令禁止那一类展示)。
|
|
2581
|
+
⚠️ 它是真 `button`(Tab 得到、回车能开、读屏读得出),并且
|
|
2582
|
+
`stopPropagation` —— 否则点它会顺带触发行的 onSelect(预览开/关切换),
|
|
2583
|
+
于是「点片段」在同一行上点第二次会把预览关掉。 */
|
|
2584
|
+
passage ? h('button', {
|
|
2585
|
+
className: 'knit-hit',
|
|
2586
|
+
type: 'button',
|
|
2587
|
+
title: t('row.passages', { range: fmtRange(passage) }),
|
|
2588
|
+
onClick: (event) => {
|
|
2589
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2590
|
+
onPassage(doc, passage)
|
|
2591
|
+
},
|
|
2592
|
+
}, t('row.passages', { range: fmtRange(passage) })) : null,
|
|
2593
|
+
(passage && why) ? h('span', { className: 'knit-subrow-sep', 'aria-hidden': 'true' }) : null,
|
|
2594
|
+
why ? (onWhyToggle && relations
|
|
2595
|
+
// v0.21:**有关系可看时,「为什么」就是那个开关**(需求 §6.6:点「原因」展开证据)。
|
|
2596
|
+
// 文本一个字节都没变,只是从 div 变成 button —— 它现在真的可点、可 Tab、可回车。
|
|
2597
|
+
// 2026-10-08:证据行右端的来源词(检索 / 关系 / 用户固定)**是同一个开关** ——
|
|
2598
|
+
// 用户规格要的就是它,而理由那一行的原文与交互一个字都没动。
|
|
2599
|
+
? h('button', {
|
|
2600
|
+
className: 'knit-why',
|
|
2601
|
+
type: 'button',
|
|
2602
|
+
title: t('rel.toggle'),
|
|
2603
|
+
'aria-expanded': whyOpen ? 'true' : 'false',
|
|
2604
|
+
onClick: (event) => {
|
|
2605
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2606
|
+
onWhyToggle()
|
|
2607
|
+
},
|
|
2608
|
+
}, why)
|
|
2609
|
+
: h('div', { className: 'knit-why', title: `${t('context.why')}:${why}` }, why)) : null),
|
|
2610
|
+
/* ── 右端=操作组(2026-10-08 用户规格)───────────────────────────
|
|
2611
|
+
顺序是**硬的**:固定 → 排除 → 来源词。**只有文字、没有任何图标**
|
|
2612
|
+
(不加 Pin / 放大镜 / 禁止符号 / 星形,不加 SVG 装饰),也不给三个按钮
|
|
2613
|
+
各自的彩色胶囊 —— 它们默认根本不显示,出现时就是一行克制的灰字。
|
|
2614
|
+
⚠️ 来源词是**第三个**:它既是「这一条怎么进来的」这条事实,又是展开证据的入口
|
|
2615
|
+
(有关系可看时才是 button;没有证据可展开时只是一个词,不装成能点)。
|
|
2616
|
+
⚠️ 三个动作都 `stopPropagation` —— 否则点它会顺带开 / 关这一篇的预览。 */
|
|
2617
|
+
(onAct || prov) ? h('div', { className: 'knit-rowacts' },
|
|
2618
|
+
onAct ? h('button', {
|
|
2619
|
+
className: 'knit-act',
|
|
2620
|
+
type: 'button',
|
|
2621
|
+
title: t(pinned ? 'control.unpin' : 'control.pin'),
|
|
2622
|
+
onClick: (event) => {
|
|
2623
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2624
|
+
onAct(pinned ? 'unpin' : 'pin', doc.rel)
|
|
2625
|
+
},
|
|
2626
|
+
}, t(pinned ? 'control.unpin' : 'control.pin')) : null,
|
|
2627
|
+
onAct ? h('button', {
|
|
2628
|
+
className: 'knit-act',
|
|
2629
|
+
type: 'button',
|
|
2630
|
+
title: t('control.exclude'),
|
|
2631
|
+
onClick: (event) => {
|
|
2632
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2633
|
+
onAct('exclude', doc.rel)
|
|
2634
|
+
},
|
|
2635
|
+
}, t('control.exclude')) : null,
|
|
2636
|
+
prov ? (onWhyToggle && relations
|
|
2637
|
+
? h('button', {
|
|
2638
|
+
className: 'knit-prov',
|
|
2639
|
+
type: 'button',
|
|
2640
|
+
title: t('rel.toggle'),
|
|
2641
|
+
'aria-expanded': whyOpen ? 'true' : 'false',
|
|
2642
|
+
onClick: (event) => {
|
|
2643
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2644
|
+
onWhyToggle()
|
|
2645
|
+
},
|
|
2646
|
+
}, prov)
|
|
2647
|
+
: h('span', { className: 'knit-prov', title: t('context.why') }, prov)) : null) : null) : null,
|
|
2648
|
+
// ── v0.21 行级证据(需求 §6.2)──────────────────────────────────
|
|
2649
|
+
// **默认一个节点都不渲染**,点开「为什么」才有。每条一行,四个字段全都可核验:
|
|
2650
|
+
// 类型 · 方向 · 谁 · 第几行。⚠️ 它渲染在 `.knit-subrow` **之外**(.knit-subrow 是
|
|
2651
|
+
// 「一条 metadata 行」那个容器,有测试钉着它每行恰好一个)。
|
|
2652
|
+
// ⚠️ 类名刻意避开 `knit-why` 子串 —— `byClass` 是子串匹配,测试用
|
|
2653
|
+
// `byClass(nodes,'knit-why')` 数理由行,撞上就会多算。
|
|
2654
|
+
// `tests` 那一类**没有行号**:它的证据是「文件名约定」这个事实,不是某一行文字,
|
|
2655
|
+
// 所以不编一个行号出来。
|
|
2656
|
+
whyOpen && relations ? h('div', { className: 'knit-rellist' },
|
|
2657
|
+
...relations.slice(0, REL_MAX).map((rel, index) => {
|
|
2658
|
+
// 「谁在提这件事」的那个文件:`in` 边是对方指向这一篇(对方是叙述方),
|
|
2659
|
+
// `out` 边是这一篇指向对方。行号属于**叙述方**那份文件。
|
|
2660
|
+
const owner = rel.dir === 'in' ? rel.other : doc.rel
|
|
2661
|
+
return h('div', { className: 'knit-relrow', key: `${rel.type}:${rel.dir}:${rel.other}:${index}` },
|
|
2662
|
+
h('span', { className: 'knit-reltag' }, t(`rel.${rel.type}`)),
|
|
2663
|
+
h('span', { className: 'knit-relwho' }, `${rel.dir === 'in' ? '←' : '→'} ${rel.other}`),
|
|
2664
|
+
Number.isInteger(rel.line) ? h('span', { className: 'knit-relline' }, t('rel.line', { line: rel.line })) : null,
|
|
2665
|
+
h('button', {
|
|
2666
|
+
className: 'knit-relopen',
|
|
2667
|
+
type: 'button',
|
|
2668
|
+
onClick: (event) => {
|
|
2669
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2670
|
+
onOpenRelation(owner, rel.line)
|
|
2671
|
+
},
|
|
2672
|
+
}, t('rel.open')))
|
|
2673
|
+
}),
|
|
2674
|
+
relationsTotal > relations.length
|
|
2675
|
+
? h('div', { className: 'knit-relmore' },
|
|
2676
|
+
t('rel.more', { n: relationsTotal, max: REL_MAX }))
|
|
2677
|
+
: null) : null))
|
|
2359
2678
|
}
|
|
2360
2679
|
|
|
2361
2680
|
/**
|
|
@@ -3206,6 +3525,10 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3206
3525
|
usage: null,
|
|
3207
3526
|
// v0.20 性能治理:这一份数据自己的签名 —— 轮询回来的载荷与它相同就不重渲染(见 `load`)。
|
|
3208
3527
|
sig: '',
|
|
3528
|
+
// v0.21:用户自己的上下文控制(固定 / 排除)。宿主在 `/api/recent` 里回
|
|
3529
|
+
// `{pinned, excluded, skipped, persisted}`;`skipped` 是**这一批真的被排掉几篇**
|
|
3530
|
+
// (不是 excluded 的长度 —— 被排除的文件可能已经不在工作区里了)。
|
|
3531
|
+
control: null,
|
|
3209
3532
|
})
|
|
3210
3533
|
const [preview, setPreview] = React.useState(null)
|
|
3211
3534
|
/* v0.20 性能治理:**一分钟一次**的刷新信号。相对时间标签是按分钟变的,所以轮询只在
|
|
@@ -3240,6 +3563,9 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3240
3563
|
// 仍然放在最后:前面那些 hook 的位置被测试按位预置,别插队。
|
|
3241
3564
|
const [gapOpen, setGapOpen] = React.useState(false)
|
|
3242
3565
|
const [deltaOpen, setDeltaOpen] = React.useState(false)
|
|
3566
|
+
// v0.21:哪一条的**行级证据**是展开的。按 `rel` 记、一次只开一条 —— 证据是「这一行
|
|
3567
|
+
// 为什么在这里」的补充说明,同时展开多条就不是在看一行了。仍然放在最后(同上)。
|
|
3568
|
+
const [whyOpen, setWhyOpen] = React.useState('')
|
|
3243
3569
|
|
|
3244
3570
|
/* ── 曾经在这里的三个状态 + 一个 ref:右栏的形态 ──────────
|
|
3245
3571
|
`packWidth`(310) / `packFloat`(null) / `packSnap`(false) / `packColRef`。
|
|
@@ -3302,6 +3628,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3302
3628
|
mode: data.mode || 'time',
|
|
3303
3629
|
context: data.context || null,
|
|
3304
3630
|
usage: data.usage || null,
|
|
3631
|
+
// v0.21:固定 / 排除的原始记录(面板要拿它画固定区、排除说明与管道条)。
|
|
3632
|
+
control: data.control || null,
|
|
3305
3633
|
sig,
|
|
3306
3634
|
}))
|
|
3307
3635
|
} else {
|
|
@@ -3331,6 +3659,37 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3331
3659
|
return () => { alive = false; if (timer) clearTimeout(timer) }
|
|
3332
3660
|
}, [load, visible])
|
|
3333
3661
|
|
|
3662
|
+
/* ── v0.21 固定 / 排除:整个 HTTP 面唯一的**写**动作 ──────────────
|
|
3663
|
+
一次点击 = 一次 POST + 一次重取。为什么要重取而不是本地改状态:被固定的那篇
|
|
3664
|
+
要从三层里**移出**、被排除的那篇要**离开候选集**(连 `matched` 计数都变),
|
|
3665
|
+
这些判断都在宿主侧(`context.js` 的分层与 `scan()` 的候选集)—— 客户端自己
|
|
3666
|
+
算一份就是第二个真相。`sig: ''` 是让紧接着的 `load` 一定落一次状态,
|
|
3667
|
+
不等下一次轮询(即时信号那条纪律:点一下就该有反应)。
|
|
3668
|
+
⚠️ 失败必须是**说明**而不是静默:失败只写 notice,不动任何本地状态
|
|
3669
|
+
(乐观更新在这条路径上会让界面先骗人再改口)。 */
|
|
3670
|
+
const act = React.useCallback(async (action, rel) => {
|
|
3671
|
+
if (!sessionId || !rel) return
|
|
3672
|
+
try {
|
|
3673
|
+
const res = await fetch(`${CONTROL_API}?sessionId=${encodeURIComponent(sessionId)}`, {
|
|
3674
|
+
method: 'POST',
|
|
3675
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
3676
|
+
cache: 'no-store',
|
|
3677
|
+
body: JSON.stringify({ action, rel }),
|
|
3678
|
+
})
|
|
3679
|
+
const data = await res.json()
|
|
3680
|
+
if (data && data.ok && data.control) {
|
|
3681
|
+
setNotice('')
|
|
3682
|
+
setWhyOpen('')
|
|
3683
|
+
setState((prev) => ({ ...prev, control: data.control, sig: '' }))
|
|
3684
|
+
await load(true)
|
|
3685
|
+
} else {
|
|
3686
|
+
setNotice(t('control.failed', { error: hostMessage(data) }))
|
|
3687
|
+
}
|
|
3688
|
+
} catch (error) {
|
|
3689
|
+
setNotice(t('control.failed', { error: String((error && error.message) || error) }))
|
|
3690
|
+
}
|
|
3691
|
+
}, [sessionId, load])
|
|
3692
|
+
|
|
3334
3693
|
/* ── 过滤:纯客户端,不重新请求宿主 ─────────────── */
|
|
3335
3694
|
const visibleDocs = React.useMemo(() => {
|
|
3336
3695
|
const all = Array.isArray(state.docs) ? state.docs : []
|
|
@@ -3474,6 +3833,14 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3474
3833
|
const withHits = (item) => (item.matches ? item
|
|
3475
3834
|
: (hitByRel.has(item.rel) ? { ...item, matches: hitByRel.get(item.rel) } : item))
|
|
3476
3835
|
const sections = []
|
|
3836
|
+
/* v0.21:**用户固定**在最上面,独立一区、不编号(需求 §6.3)。它排在三层之前不是
|
|
3837
|
+
因为它更重要,而是因为它是**用户自己的动作**:三层是这一轮的检索结果,下一轮
|
|
3838
|
+
就变了;固定的那几篇会一直在。`pack.pinned` 由宿主从三层里**移出**后给出,
|
|
3839
|
+
所以这里不会与下面三层重复。 */
|
|
3840
|
+
const pinned = Array.isArray(pack.pinned) ? pack.pinned.filter((item) => visible.has(item.rel)).map(withHits) : []
|
|
3841
|
+
if (pinned.length > 0) {
|
|
3842
|
+
sections.push({ key: 'pinned', titleKey: 'context.pinned', hintKey: 'context.pinnedHint', docs: pinned })
|
|
3843
|
+
}
|
|
3477
3844
|
for (const [tierKey, titleKey, hintKey] of tiers) {
|
|
3478
3845
|
const items = Array.isArray(pack[tierKey]) ? pack[tierKey] : []
|
|
3479
3846
|
const docs = items.filter((item) => visible.has(item.rel)).map(withHits)
|
|
@@ -3485,6 +3852,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3485
3852
|
for (const tierKey of ['primary', 'supporting', 'related']) {
|
|
3486
3853
|
for (const item of (Array.isArray(pack[tierKey]) ? pack[tierKey] : [])) placed.add(item.rel)
|
|
3487
3854
|
}
|
|
3855
|
+
// 固定区里的也在包里 —— 它们同样不该出现在「其他相关文档」。
|
|
3856
|
+
for (const item of (Array.isArray(pack.pinned) ? pack.pinned : [])) placed.add(item.rel)
|
|
3488
3857
|
const rest = visibleDocs.filter((doc) => !isMedia(doc) && !placed.has(doc.rel))
|
|
3489
3858
|
if (rest.length > 0) {
|
|
3490
3859
|
sections.push({ key: 'other', titleKey: 'context.other', hintKey: '', docs: rest })
|
|
@@ -3493,9 +3862,10 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3493
3862
|
// 行首序号(Design §11):**只编三层里的**,而且是跨层连续的
|
|
3494
3863
|
// (01 属于 Primary、02/03 属于 Supporting……),与右栏证据行的计数对齐。
|
|
3495
3864
|
// 「其他相关文档」不编号 —— 它们不在这个包里面。
|
|
3865
|
+
// v0.21:**固定区也不编号** —— 它的位置由用户决定,不由阅读顺序决定。
|
|
3496
3866
|
const numbers = new Map()
|
|
3497
3867
|
for (const section of sections) {
|
|
3498
|
-
if (section.key === 'other') continue
|
|
3868
|
+
if (section.key === 'other' || section.key === 'pinned') continue
|
|
3499
3869
|
for (const doc of section.docs) numbers.set(doc.rel, numbers.size + 1)
|
|
3500
3870
|
}
|
|
3501
3871
|
// 键盘到达顺序 = 屏幕上从上到下的顺序(分组顺序 + 组内顺序)
|
|
@@ -4161,7 +4531,25 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4161
4531
|
// v0.18:生命周期现在是**一枚 glyph + 一段极短的文字**。glyph 可点:
|
|
4162
4532
|
// 点它=打开 / 选中这一篇(**已经打开则保持原预览**,不重开也不重拉)。
|
|
4163
4533
|
const info = withLife ? lifeInfo(doc.rel) : null
|
|
4534
|
+
// v0.21:上下文控制只在**有包的视图**里给出(相关序 + 宿主真的给了 Context Pack)
|
|
4535
|
+
// —— 固定与排除说的都是「这个包 / 这份候选集里的这一条」,管道条与排除说明
|
|
4536
|
+
// 也在同一条件下出现。来源徽标只有宿主真的给了 `provenance` 才渲染:
|
|
4537
|
+
// 平铺列表里的条目来源未知,不能替它认领一个「检索」。
|
|
4538
|
+
const controllable = Boolean(contextView && !isMedia(doc))
|
|
4164
4539
|
return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary,
|
|
4540
|
+
prov: doc.provenance ? t(`prov.${doc.provenance}`) : null,
|
|
4541
|
+
pinned: doc.provenance === 'manual',
|
|
4542
|
+
onAct: controllable ? act : null,
|
|
4543
|
+
whyOpen: Boolean(whyOpen) && whyOpen === doc.rel,
|
|
4544
|
+
// 「为什么」只有在**真的有关系可看**时才是一个可点的开关(没有证据就不装成
|
|
4545
|
+
// 有证据的样子 —— 需求 §6.4:解释必须来自真实关系)。
|
|
4546
|
+
relations: Array.isArray(doc.relations) && doc.relations.length > 0 ? doc.relations : null,
|
|
4547
|
+
relationsTotal: Number.isInteger(doc.relationsTotal) ? doc.relationsTotal : 0,
|
|
4548
|
+
onWhyToggle: controllable ? () => setWhyOpen((prev) => (prev === doc.rel ? '' : doc.rel)) : null,
|
|
4549
|
+
onOpenRelation: (rel, line) => {
|
|
4550
|
+
const target = visibleDocs.find((item) => item.rel === rel) || { rel }
|
|
4551
|
+
openPassage(target, Number.isInteger(line) ? { startLine: line, endLine: line } : null)
|
|
4552
|
+
},
|
|
4165
4553
|
life: info ? info.text : null,
|
|
4166
4554
|
glyph: info,
|
|
4167
4555
|
onGlyph: (target) => {
|
|
@@ -4471,7 +4859,10 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4471
4859
|
lensOpen ? h('div', { className: 'knit-lens-body' },
|
|
4472
4860
|
coverageNode, recentNode, outsideNode, deltaNode) : null)
|
|
4473
4861
|
|
|
4474
|
-
//
|
|
4862
|
+
// 不同类型用不同量词:文档「篇」、代码「个代码文件」、媒体「个媒体」、混排「项」。
|
|
4863
|
+
// ⚠️ 2026-10-09 用户要求:**屏幕上只留阿拉伯数字**(`9` / `3 / 79`)——
|
|
4864
|
+
// 量词本来就随档位变(同一位置换个档就换一种中文,读起来像两套东西)。
|
|
4865
|
+
// 整句降级成 `title`(悬停仍读得到「9 个代码文件」),i18n 键不闲置。
|
|
4475
4866
|
const countKey = kind === KIND_MEDIA
|
|
4476
4867
|
? (filtering ? 'count.media.filtered' : 'count.media')
|
|
4477
4868
|
: kind === KIND_CODE
|
|
@@ -4479,10 +4870,67 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4479
4870
|
: kind === KIND_ALL
|
|
4480
4871
|
? (filtering ? 'count.all.filtered' : 'count.all')
|
|
4481
4872
|
: (filtering ? 'count.filtered' : 'count')
|
|
4873
|
+
// 可见文本 = 纯数字;整句(含量词)只出现在 title 里。
|
|
4482
4874
|
const countText = filtering
|
|
4875
|
+
? `${visibleDocs.length} / ${state.total}`
|
|
4876
|
+
: String(state.total ?? 0)
|
|
4877
|
+
const countTitle = filtering
|
|
4483
4878
|
? t(countKey, { hit: visibleDocs.length, total: state.total })
|
|
4484
4879
|
: t(countKey, { n: state.total })
|
|
4485
4880
|
|
|
4881
|
+
/* ── v0.21 检索状态摘要(需求 §6.3;2026-10-09 用户规格重排)──────────
|
|
4882
|
+
每一格都是**已经发生的事实**,不是估算:
|
|
4883
|
+
· 收集 = `total` + `skipped`(`total` 是排除**之后**的候选数,加回被排掉的那些
|
|
4884
|
+
才是扫描到的篇数 —— 面板头部的计数仍然只用 `total`,口径不变);
|
|
4885
|
+
· 排除 = 这一批里真的被排掉几篇(宿主按候选集算的 `skipped`,不是 excluded 的长度:
|
|
4886
|
+
切到代码档时,被排除的那篇 Markdown 根本不在语料里,那时它没被排掉);
|
|
4887
|
+
· 候选 = 排除之后进入检索的篇数(就是 `state.total`,原来是那个没有名字的光数字);
|
|
4888
|
+
· BM25 词法检索 = 这一路是纯本地词法检索 + 排序(**零模型**,这句话本身就是产品承诺);
|
|
4889
|
+
· 关系 N 条 = 这一份包里一共带了几条关系证据(三层各条 relations 之和);
|
|
4890
|
+
· 固定 N = 有几篇被用户固定、因此**从三层移出**进了固定区(`pack.pinned` 的长度);
|
|
4891
|
+
· 入包 N = 三层现有条目数(固定区不算 —— 它不在包里)。
|
|
4892
|
+
布局是**三组、单行、竖线分隔**:候选 | 检索与调整 | 入包。组内用中点。
|
|
4893
|
+
⚠️ 没有箭头、没有图标、没有色块(需求 §三):顺序与分组本身就是信息。
|
|
4894
|
+
⚠️ 不显示任何分数 / 百分比 / 索引内部量(需求 §十二)。 */
|
|
4895
|
+
const pack = state.context || null
|
|
4896
|
+
const packCount = pack
|
|
4897
|
+
? ['primary', 'supporting', 'related'].reduce((sum, key) => sum + (Array.isArray(pack[key]) ? pack[key].length : 0), 0)
|
|
4898
|
+
: 0
|
|
4899
|
+
const relCount = pack
|
|
4900
|
+
? ['primary', 'supporting', 'related'].reduce((sum, key) => sum + (Array.isArray(pack[key])
|
|
4901
|
+
? pack[key].reduce((n, item) => n + (Array.isArray(item.relations) ? item.relations.length : 0), 0) : 0), 0)
|
|
4902
|
+
: 0
|
|
4903
|
+
const skipped = Number(state.control && state.control.skipped) || 0
|
|
4904
|
+
const collected = state.total + skipped
|
|
4905
|
+
const pipeCell = (text, strong) => h('span', { className: `knit-pipecell${strong ? ' strong' : ''}` }, text)
|
|
4906
|
+
// 组内中点 / 组间竖线:都是文本节点,跟着同一行流排版(基线天然一致、换行不留孤线)。
|
|
4907
|
+
const pipeDot = () => h('span', { className: 'knit-pipedot', 'aria-hidden': 'true' }, '·')
|
|
4908
|
+
const pipeSep = () => h('span', { className: 'knit-pipesep', 'aria-hidden': 'true' }, '|')
|
|
4909
|
+
const pinnedCount = pack && Array.isArray(pack.pinned) ? pack.pinned.length : 0
|
|
4910
|
+
const pipeNode = h('div', { className: 'knit-pipe' },
|
|
4911
|
+
pipeCell(t('pipe.collect', { n: collected })),
|
|
4912
|
+
pipeDot(),
|
|
4913
|
+
pipeCell(t('pipe.exclude', { n: skipped })),
|
|
4914
|
+
pipeDot(),
|
|
4915
|
+
pipeCell(t('pipe.candidates', { n: state.total })),
|
|
4916
|
+
pipeSep(),
|
|
4917
|
+
pipeCell(t('pipe.rank')),
|
|
4918
|
+
pipeDot(),
|
|
4919
|
+
pipeCell(t('pipe.relations', { n: relCount })),
|
|
4920
|
+
pipeDot(),
|
|
4921
|
+
pipeCell(t('pipe.pin', { n: pinnedCount })),
|
|
4922
|
+
pipeSep(),
|
|
4923
|
+
// 唯一略微加重的一格:它是这一行里被后续阶段消费的那个数字(需求 §三.8:
|
|
4924
|
+
// 只提字重,不用品牌色、不做徽章)。
|
|
4925
|
+
pipeCell(t('pipe.pack', { n: packCount }), true))
|
|
4926
|
+
// 排除说明只列**还能找回来**的那些:宿主保留了记录(用户排除过就是排除过),
|
|
4927
|
+
// 但文件已经删掉的不该给一个按下去什么都不会发生的「恢复」(需求 §6.4)。
|
|
4928
|
+
// ⚠️ 判据是宿主给的 `exists`,**不能**拿 `state.docs` 去反查 ——
|
|
4929
|
+
// 被排除的那一篇恰恰不在 `docs` 里(那正是「排除」的意思),反查恒为空。
|
|
4930
|
+
const excludedList = (state.control && Array.isArray(state.control.excluded))
|
|
4931
|
+
? state.control.excluded.filter((item) => item.exists)
|
|
4932
|
+
: []
|
|
4933
|
+
|
|
4486
4934
|
return h('div', {
|
|
4487
4935
|
className: `knit-root${fullscreen ? ' fullscreen' : ''}`,
|
|
4488
4936
|
ref: rootRef,
|
|
@@ -4499,7 +4947,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4499
4947
|
setNotice((await openLocalPath(state.hostRoot || state.root)) || '')
|
|
4500
4948
|
},
|
|
4501
4949
|
}, state.root || '—'),
|
|
4502
|
-
|
|
4950
|
+
// v0.21.x(2026-10-09):计数只剩数字(量词在 title 里,悬停才读得到)。
|
|
4951
|
+
h('div', { className: 'knit-count', title: countTitle }, countText),
|
|
4503
4952
|
// v0.15:默认关的自查开关。开着才有 `&usage=1` —— 宿主也只在那一刻开始记账。
|
|
4504
4953
|
h('button', {
|
|
4505
4954
|
type: 'button',
|
|
@@ -4510,6 +4959,11 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4510
4959
|
}, t('usage.toggle')),
|
|
4511
4960
|
h('button', { className: 'knit-btn', onClick: load, title: t('action.refreshNow') }, t('action.refresh'))),
|
|
4512
4961
|
h('div', { className: 'knit-bar' },
|
|
4962
|
+
/* v0.21.x(2026-10-09 用户规格):三组一行 —— 排序 | 类型 | 搜索。
|
|
4963
|
+
① 排序与类型**不做成一个整体**:中间那根 `.knit-bar-sep` 就是边界,两个条件各管各的。
|
|
4964
|
+
② 搜索排最后、贴最右:它只过滤当前列表,不重置排序与类型(§三.3)。
|
|
4965
|
+
③ 六个选项彼此独立 —— 选「代码」再选「最新」= 最新的代码。
|
|
4966
|
+
顺序即控件顺序,别再挪(细则在 CSS 那边的 .knit-bar / .knit-filter 注释里)。 */
|
|
4513
4967
|
h('div', { className: 'knit-seg' },
|
|
4514
4968
|
h('button', {
|
|
4515
4969
|
className: `knit-seg-btn${sort === 'relevance' ? ' active' : ''}`,
|
|
@@ -4521,6 +4975,22 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4521
4975
|
onClick: () => pickSort('time'),
|
|
4522
4976
|
title: t('sort.timeTitle'),
|
|
4523
4977
|
}, t('sort.time'))),
|
|
4978
|
+
// 排序组 / 类型组之间**就这一根线**(2026-10-09 用户规格 §二.2)。
|
|
4979
|
+
h('span', { className: 'knit-bar-sep', 'aria-hidden': 'true' }),
|
|
4980
|
+
h('div', { className: 'knit-types', role: 'tablist', 'aria-label': t('kind.title') },
|
|
4981
|
+
// v0.19:四档「文档 / 代码 / 媒体 / 全部」。**没有第二层分类** ——
|
|
4982
|
+
// 代码里不再按语言(JS / TS / Python…)分组(需求 §46:不给代码加视觉层级压迫)。
|
|
4983
|
+
[[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media'], [KIND_ALL, 'kind.all']].map(([value, labelKey]) =>
|
|
4984
|
+
h('button', {
|
|
4985
|
+
type: 'button',
|
|
4986
|
+
key: value,
|
|
4987
|
+
role: 'tab',
|
|
4988
|
+
'aria-selected': kind === value,
|
|
4989
|
+
className: `knit-type-btn${kind === value ? ' active' : ''}`,
|
|
4990
|
+
title: t('kind.title'),
|
|
4991
|
+
onClick: () => pickKind(value),
|
|
4992
|
+
}, t(labelKey)))),
|
|
4993
|
+
// 搜索排最后(工具栏尾部):它对**当前这一份列表**再过滤,不动排序与类型。
|
|
4524
4994
|
h('input', {
|
|
4525
4995
|
className: 'knit-filter',
|
|
4526
4996
|
value: query,
|
|
@@ -4531,23 +5001,33 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4531
5001
|
if (event.key === 'Escape') { event.stopPropagation(); setQuery('') }
|
|
4532
5002
|
},
|
|
4533
5003
|
})),
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
5004
|
+
/* ── v0.21:检索状态摘要 + 排除说明(需求 §6.3)──────────────────────
|
|
5005
|
+
两条都是**事实行**,都在列表上方、都只在相关序出现(那是唯一有「包」的视图)。
|
|
5006
|
+
⚠️ 它们的排位是**紧贴工具栏**的(2026-10-09 用户反馈):观察层排在它们下面,
|
|
5007
|
+
所以开关「使用情况」不会把这一行顶下去(详见下面的 Lens 注释)。
|
|
5008
|
+
① 状态摘要 `收集 137 · 排除 1 · 候选 136 | BM25 词法检索 · 关系 24 条 · 固定 1 | 入包 8`:
|
|
5009
|
+
**分组与顺序本身就是这条设计要传达的信息** —— 排除发生在检索**之前**、固定发生在
|
|
5010
|
+
排序**之后**。所以它不是装饰,也不是进度条,更没有流程图箭头(2026-10-09 用户规格)。
|
|
5011
|
+
② 排除说明:被排掉的那几篇 + 一个「恢复」。它说的是「这一批少了什么」,
|
|
5012
|
+
空的时候**不出现、也不占位**。 */
|
|
5013
|
+
relevance && contextView ? pipeNode : null,
|
|
5014
|
+
relevance && excludedList.length > 0 ? h('div', { className: 'knit-excl' },
|
|
5015
|
+
h('span', { className: 'knit-excl-what' },
|
|
5016
|
+
t('control.excluded', { rel: excludedList.map((item) => item.rel).join('、') })),
|
|
5017
|
+
h('button', {
|
|
5018
|
+
className: 'knit-act',
|
|
5019
|
+
type: 'button',
|
|
5020
|
+
onClick: () => act('restore', excludedList[0].rel),
|
|
5021
|
+
}, t('control.restore'))) : null,
|
|
4550
5022
|
notice ? h('div', { className: 'knit-notice' }, notice) : null,
|
|
5023
|
+
/* ── v0.18 的「Context Usage Lens」**排在最后**(2026-10-09 用户反馈)───────
|
|
5024
|
+
它原来是紧随 `.knit-bar` 的:一开「使用情况」,整块观察层插在状态摘要**上面**,
|
|
5025
|
+
把那一行数字顶下去 —— 用户原话「这一列…向下排,我觉得这列不用向下排,而是固定在原来的位置」。
|
|
5026
|
+
所以顺序改成 **工具栏 → 状态摘要 → 排除说明 → 通知 → 观察层 → 列表**:
|
|
5027
|
+
摘要这一行永远紧贴工具栏,位置不随开关变;观察层仍是「列表上方的观察层」,
|
|
5028
|
+
而且比原来更贴近列表。⚠️ 别再把它挪回 `.knit-bar` 后面(有守卫钉着顺序)。
|
|
5029
|
+
v0.15:开了才显示。不是弹窗、不是新页面、不是 Dashboard。 */
|
|
5030
|
+
usageOn ? lensNode : null,
|
|
4551
5031
|
// 列表节点**直接挂上去**(2026-09-29 起永远单栏;曾经它要交给一个 IIFE
|
|
4552
5032
|
// 决定塞进单栏还是双栏的左列)。**输出与 v0.13 逐字一致** ——
|
|
4553
5033
|
// 时间序、媒体档、「全部」都不受影响。
|