dsh-knit 0.23.1 → 0.24.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 +76 -0
- package/README.en.md +36 -7
- package/README.md +30 -6
- package/SECURITY.md +5 -2
- package/package.json +3 -3
- package/src/client/client.js +295 -8
- package/src/host/changes.js +208 -0
- package/src/host/git.js +377 -0
- package/src/host/index.js +228 -5
- package/test/client.test.mjs +270 -4
- package/test/git-changes.test.mjs +1238 -0
- package/test/host-http.test.mjs +4 -58
- package/test/http-harness.mjs +79 -0
package/src/client/client.js
CHANGED
|
@@ -140,12 +140,18 @@ window.__ModuleLoader__.load({
|
|
|
140
140
|
// 所以它们一色到底(都是 caption 灰),靠**字**区分,不靠颜色。
|
|
141
141
|
'context.pinned': '固定上下文',
|
|
142
142
|
'context.pinnedHint': '你自己标记的',
|
|
143
|
+
// v0.25:Git 变更关联。**与三层平行的一区**,不参与 01…0N 的编号。
|
|
144
|
+
'context.changes': '变更关联',
|
|
145
|
+
'context.changesHint': '由未提交的改动牵出来的',
|
|
146
|
+
'context.changesEmpty': '{files} 个变更文件,没有找到关联证据',
|
|
147
|
+
'context.changesUnreadable': '读不到 Git 变更状态:{reason}',
|
|
143
148
|
'prov.retrieval': '检索',
|
|
144
149
|
'prov.relation': '关系',
|
|
145
150
|
'prov.manual': '用户固定',
|
|
146
151
|
// v0.23:第四档来源。它**只**由「标题 + 摘要」的向量与任务相似而来 ——
|
|
147
152
|
// 不是关键词命中、也不是关系证据,而且只可能落在「相关」那一层。
|
|
148
153
|
'prov.semantic': '语义相关',
|
|
154
|
+
'prov.change': '变更关联',
|
|
149
155
|
'control.pin': '固定',
|
|
150
156
|
'control.unpin': '取消固定',
|
|
151
157
|
'control.exclude': '排除',
|
|
@@ -173,6 +179,20 @@ window.__ModuleLoader__.load({
|
|
|
173
179
|
// ⚠️ 「关系 N 条」说的是**这一份包里带了几条关系证据**(三层各条 relations 之和),
|
|
174
180
|
// 不是工作区里的关系总数、也不是候选数(那两类数字宿主另有字段,这里不展示)。
|
|
175
181
|
'pipe.relations': '关系 {n} 条',
|
|
182
|
+
// v0.25:状态行里那一格(**默认关**)。关着也出现 —— 藏起来用户就永远打不开这个功能。
|
|
183
|
+
'pipe.changesOff': '变更',
|
|
184
|
+
'pipe.changesOn': '变更 {n}',
|
|
185
|
+
'pipe.changesUnavailable': '变更 —',
|
|
186
|
+
'changes.titleOff': '按 Git 变更查找需要一起检查的文件(只读:只跑一条 git status,不执行任何写操作)',
|
|
187
|
+
'changes.titleOn': '{files} 个变更文件 · {related} 条关联证据 · 点一下关闭',
|
|
188
|
+
'changes.titleUnavailable': '读不到 Git 变更状态:{reason}',
|
|
189
|
+
'changes.reason.notARepo': '不是 Git 工作区',
|
|
190
|
+
'changes.reason.gitMissing': '找不到 git 命令',
|
|
191
|
+
'changes.reason.timeout': 'git 读取超时',
|
|
192
|
+
'changes.reason.tooLarge': 'git 输出过大(已截断)',
|
|
193
|
+
'changes.reason.failed': 'git 读取失败',
|
|
194
|
+
'changes.reason.request': '变更关联接口请求失败',
|
|
195
|
+
'changes.reason.unknown': '原因未知',
|
|
176
196
|
// ⚠️ 「固定 N」= 有几篇被你固定、因此**从三层移出**进了固定区(pack.pinned 的长度)。
|
|
177
197
|
// 不写「固定覆盖」这种内部说法;也不带量词 —— 固定对象可能是文档、代码或媒体。
|
|
178
198
|
'pipe.pin': '固定 {n}',
|
|
@@ -460,11 +480,16 @@ window.__ModuleLoader__.load({
|
|
|
460
480
|
// in, not how strong it is — so they share one colour and differ by word.
|
|
461
481
|
'context.pinned': 'Pinned',
|
|
462
482
|
'context.pinnedHint': 'you marked these',
|
|
483
|
+
'context.changes': 'Tied to changes',
|
|
484
|
+
'context.changesHint': 'pulled in by your uncommitted edits',
|
|
485
|
+
'context.changesEmpty': '{files} changed file(s), no related evidence found',
|
|
486
|
+
'context.changesUnreadable': 'Git change status unavailable: {reason}',
|
|
463
487
|
'prov.retrieval': 'retrieved',
|
|
464
488
|
'prov.relation': 'relation',
|
|
465
489
|
'prov.manual': 'pinned',
|
|
466
490
|
// v0.23: the fourth provenance (semantic) — same neutral, lowercase word group.
|
|
467
491
|
'prov.semantic': 'semantic',
|
|
492
|
+
'prov.change': 'change',
|
|
468
493
|
'control.pin': 'Pin',
|
|
469
494
|
'control.unpin': 'Unpin',
|
|
470
495
|
'control.exclude': 'Exclude',
|
|
@@ -484,6 +509,19 @@ window.__ModuleLoader__.load({
|
|
|
484
509
|
'pipe.candidates': '{n} candidates',
|
|
485
510
|
'pipe.rank': 'BM25 retrieval',
|
|
486
511
|
'pipe.relations': '{n} relations',
|
|
512
|
+
'pipe.changesOff': 'Changes',
|
|
513
|
+
'pipe.changesOn': 'Changes {n}',
|
|
514
|
+
'pipe.changesUnavailable': 'Changes —',
|
|
515
|
+
'changes.titleOff': 'Find the files to check alongside your Git changes (read-only: one git status, no write commands)',
|
|
516
|
+
'changes.titleOn': '{files} changed file(s) · {related} related by evidence · click to turn off',
|
|
517
|
+
'changes.titleUnavailable': 'Git change status unavailable: {reason}',
|
|
518
|
+
'changes.reason.notARepo': 'not a Git working tree',
|
|
519
|
+
'changes.reason.gitMissing': 'git command not found',
|
|
520
|
+
'changes.reason.timeout': 'git timed out',
|
|
521
|
+
'changes.reason.tooLarge': 'git output too large (truncated)',
|
|
522
|
+
'changes.reason.failed': 'git read failed',
|
|
523
|
+
'changes.reason.request': 'the change-links request failed',
|
|
524
|
+
'changes.reason.unknown': 'unknown reason',
|
|
487
525
|
'pipe.pin': '{n} pinned',
|
|
488
526
|
'pipe.pack': '{n} in pack',
|
|
489
527
|
// v0.23 (Phase A): hybrid retrieval. This cell states the mode **in effect**, not the click.
|
|
@@ -750,6 +788,9 @@ window.__ModuleLoader__.load({
|
|
|
750
788
|
const BS_TAB_ID = 'knit:recent'
|
|
751
789
|
|
|
752
790
|
const LIST_API = '/knit/api/recent'
|
|
791
|
+
/* v0.25:Git 变更关联的**独立接口**。它与列表接口分开,所以「列表的响应形状」
|
|
792
|
+
不会被这个功能碰到;关掉功能时客户端连这个请求都不发。 */
|
|
793
|
+
const CHANGES_API = '/knit/api/changes'
|
|
753
794
|
const DOC_API = '/knit/api/doc'
|
|
754
795
|
const RAW_API = '/knit/api/raw'
|
|
755
796
|
// v0.12:某篇的「谁引用了它 / 它引用了谁」。与上面三条一样是**同源相对地址**,
|
|
@@ -790,6 +831,8 @@ window.__ModuleLoader__.load({
|
|
|
790
831
|
它要用户显式选、并且配了 provider 才会真的跑 —— 「零模型调用 / 零网络出口」
|
|
791
832
|
这条对外承诺只在默认模式成立(细则见 v0.23 方案 §2 的文案纪律)。 */
|
|
792
833
|
const RETRIEVAL_KEY = 'dsh-knit:retrieval'
|
|
834
|
+
/** v0.25:Git 变更关联的开关。**默认关** —— 不写这一项就是关。 */
|
|
835
|
+
const CHANGES_KEY = 'dsh-knit:changes'
|
|
793
836
|
/** 语义 provider 的**唯一写路由**;读走 `/api/recent` 的 `semantic.provider`。 */
|
|
794
837
|
const SEMANTIC_API = '/knit/api/semantic'
|
|
795
838
|
|
|
@@ -1107,6 +1150,21 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
1107
1150
|
.knit-pipe-method:hover .knit-pipe-method-label,
|
|
1108
1151
|
.knit-pipe-method:focus-visible .knit-pipe-method-label{text-decoration:underline}
|
|
1109
1152
|
.knit-pipe-method[aria-expanded="true"]{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
1153
|
+
/* v0.25:Git 变更关联那一格。**与检索方式复用同一份视觉语言**(同 --knit-chip-bg、同圆角 6px、
|
|
1154
|
+
同内边距 1px 6px、同字号 11px / 行高 15px),但它是个**二态开关**:没有菜单、没有箭头。
|
|
1155
|
+
开态只把字色提到主文本色(属性选择器 aria-pressed=true)—— **不换底色、不用品牌色**,
|
|
1156
|
+
与检索方式「展开态」那条规则同一个手法:同一行里同类物,靠字重/字色分层,不靠颜色。
|
|
1157
|
+
⚠️ 尾随的 › 在检索方式那边才画;这一格没有箭头,所以下划线直接给文字层即可。 */
|
|
1158
|
+
.knit-pipe-changes{display:inline-flex;align-items:center;flex:none;white-space:nowrap;cursor:pointer;
|
|
1159
|
+
padding:1px 6px;border:0;outline:none;border-radius:6px;
|
|
1160
|
+
background:var(--knit-chip-bg,rgba(255,255,255,.12));
|
|
1161
|
+
font:inherit;font-size:11px;line-height:15px;
|
|
1162
|
+
color:var(--dsw-alias-label-secondary,#61666b);transition:color .14s ease}
|
|
1163
|
+
.knit-pipe-changes:hover,.knit-pipe-changes:focus-visible{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
1164
|
+
.knit-pipe-changes:hover .knit-pipe-changes-label,
|
|
1165
|
+
.knit-pipe-changes:focus-visible .knit-pipe-changes-label{text-decoration:underline}
|
|
1166
|
+
.knit-pipe-changes[aria-pressed="true"]{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
1167
|
+
@media (prefers-reduced-motion:reduce){.knit-pipe-changes{transition:none}}
|
|
1110
1168
|
/* 箭头:与「最近读取」行最右端那个 › 同一套视觉语言(同字形),基础态旋转 90° 变成「朝下」。
|
|
1111
1169
|
⚠️ 展开态用 **横向翻转 scaleX(-1)**,不是对调角度、也不是 scaleY(-1)(2026-10-13 用户裁决:
|
|
1112
1170
|
「修改成横向翻转……默认箭头向下,交互展开箭头向上」)。
|
|
@@ -1931,6 +1989,28 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
1931
1989
|
return readPref(RETRIEVAL_KEY) === 'hybrid' ? 'hybrid' : 'lexical'
|
|
1932
1990
|
}
|
|
1933
1991
|
|
|
1992
|
+
/**
|
|
1993
|
+
* 读「Git 变更关联」开关。**没写过、写坏了都是关** —— 默认值必须是「不动基础检索行为」那一个。
|
|
1994
|
+
* @returns {boolean} 是否开启
|
|
1995
|
+
*/
|
|
1996
|
+
function readChangesPref() {
|
|
1997
|
+
return readPref(CHANGES_KEY) === '1'
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
/** 宿主给的 Git 原因码 → i18n 键(与 `semanticReasonKey` 同一条纪律:宿主只给码)。 */
|
|
2001
|
+
function changeReasonKey(reason) {
|
|
2002
|
+
if (reason === 'not-a-repo') return 'changes.reason.notARepo'
|
|
2003
|
+
if (reason === 'git-missing') return 'changes.reason.gitMissing'
|
|
2004
|
+
if (reason === 'timeout') return 'changes.reason.timeout'
|
|
2005
|
+
if (reason === 'output-too-large') return 'changes.reason.tooLarge'
|
|
2006
|
+
if (reason === 'failed-fatal') return 'changes.reason.failed'
|
|
2007
|
+
// v0.25 收尾:这一条**不是**宿主的原因码,而是客户端自己的 —— 独立接口那次请求本身
|
|
2008
|
+
// 失败(网络/解析异常、非 ok 响应)。「读不到 git」与「没问到」是两件事,不许都写成
|
|
2009
|
+
// 「原因未知」,否则用户分不清该去检查仓库还是该重试。
|
|
2010
|
+
if (reason === 'request') return 'changes.reason.request'
|
|
2011
|
+
return 'changes.reason.unknown'
|
|
2012
|
+
}
|
|
2013
|
+
|
|
1934
2014
|
/**
|
|
1935
2015
|
* provider 地址是不是**本机回环**。只有回环才敢说「内容不离开这台机器」;
|
|
1936
2016
|
* 其它(含空地址)一律按「会发送到你配置的服务」披露 —— 宁可说得重一点。
|
|
@@ -2166,6 +2246,81 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2166
2246
|
return !!doc && (doc.kind === 'image' || doc.kind === 'video')
|
|
2167
2247
|
}
|
|
2168
2248
|
|
|
2249
|
+
/**
|
|
2250
|
+
* v0.25 收尾:把独立接口那份载荷归成**三种状态之一**(状态行与列表提示共用同一个判断)。
|
|
2251
|
+
*
|
|
2252
|
+
* @param {object|null} data - `state.changes`
|
|
2253
|
+
* @returns {{read: boolean, reason: string|null, filesTotal: number, hasRows: boolean}}
|
|
2254
|
+
* `read=false` ⇒ 读不到(接口失败或 git 读不到),`reason` 是给用户看的原因码;
|
|
2255
|
+
* `read=true` ⇒ 拿到了 git 事实,`filesTotal` 是变更文件数。
|
|
2256
|
+
*/
|
|
2257
|
+
function changeStatusOf(data) {
|
|
2258
|
+
if (!data) return { read: false, reason: null, filesTotal: 0 }
|
|
2259
|
+
if (data.failed === true) return { read: false, reason: data.reason || 'request', filesTotal: 0 }
|
|
2260
|
+
const git = data.git || null
|
|
2261
|
+
if (!git || git.available !== true) {
|
|
2262
|
+
return { read: false, reason: (git && git.reason) || 'unknown', filesTotal: 0 }
|
|
2263
|
+
}
|
|
2264
|
+
return { read: true, reason: null, filesTotal: Number(git.filesTotal) || 0 }
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* v0.25:`/knit/api/changes` 的**专用结构** → 列表行(只做形状映射,不做判断)。
|
|
2269
|
+
*
|
|
2270
|
+
* 宿主给的是「变更起点 / 关联目标 / 关系类型 / 行号」这套事实;这里把它摊成与列表行
|
|
2271
|
+
* 同形状的一层,好让**既有那套行渲染 + 证据弹层**直接用上(零第二条渲染路径)。
|
|
2272
|
+
* 两个刻意的决定:
|
|
2273
|
+
* · `provenance: 'change'` 是**客户端自己**给这一区贴的来源词(宿主的结构里没有这个词),
|
|
2274
|
+
* 只决定行右端那个「变更关联」;**不给 `reason`** —— 见下面那段说明;
|
|
2275
|
+
* · 证据行映射回 `{type, dir, other: 起点, line}`:`other` = 那个被改过的文件,
|
|
2276
|
+
* 与 v0.21 的行级证据**逐字同源**,所以弹层里「谁 · 什么 · 第几行」照旧可读。
|
|
2277
|
+
*
|
|
2278
|
+
* @param {object|null} data - `/knit/api/changes` 的载荷
|
|
2279
|
+
* @returns {Array<object>} 行(没有数据 ⇒ 空数组,调用方据此不渲染这一区)
|
|
2280
|
+
*/
|
|
2281
|
+
function changeRowsOf(data) {
|
|
2282
|
+
const links = (data && Array.isArray(data.links)) ? data.links : []
|
|
2283
|
+
return links.map((link) => ({
|
|
2284
|
+
rel: link.target,
|
|
2285
|
+
title: link.title || link.target,
|
|
2286
|
+
summary: link.summary || '',
|
|
2287
|
+
mtimeMs: link.mtimeMs,
|
|
2288
|
+
kind: link.kind,
|
|
2289
|
+
source: link.source,
|
|
2290
|
+
provenance: 'change',
|
|
2291
|
+
// ⚠️ **刻意不给 `reason`**(v0.25 收尾):`changeRelated` 那个理由码曾经让宿主
|
|
2292
|
+
// 「声明了一个自己不再产出」的码。现在「为什么在这一区」由**区标题 + 提示句**回答
|
|
2293
|
+
// (「变更关联 / 由未提交的改动牵出」),每一行的**具体依据**在证据弹层里
|
|
2294
|
+
// (类型 + 起点 + 行号)—— 行级渲染本来就不给没有 reason 的条目出那一行。
|
|
2295
|
+
relations: (Array.isArray(link.evidence) ? link.evidence : []).map((e) => ({
|
|
2296
|
+
type: e.type,
|
|
2297
|
+
dir: e.dir,
|
|
2298
|
+
other: e.origin,
|
|
2299
|
+
// `line` 是 `null` 时**不给这个键** —— 弹层据此说「文件名约定,没行号」
|
|
2300
|
+
...(Number.isInteger(e.line) ? { line: e.line } : {}),
|
|
2301
|
+
})),
|
|
2302
|
+
...(Number.isInteger(link.evidenceTotal) && link.evidenceTotal > (Array.isArray(link.evidence) ? link.evidence.length : 0)
|
|
2303
|
+
? { relationsTotal: link.evidenceTotal } : {}),
|
|
2304
|
+
}))
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* 一个条目符不符合过滤框里的那串字(标题 / 摘要 / 相对路径)。
|
|
2309
|
+
*
|
|
2310
|
+
* v0.25 抽出来的:`visibleDocs`(列表那一份)与「变更关联」区都要用同一条判据 ——
|
|
2311
|
+
* 用户在搜索框里打了字,两处都该跟着收窄,而**两处都不许**各自写一份。
|
|
2312
|
+
*
|
|
2313
|
+
* @param {object} doc - 条目(面板条目或宿主给的记录)
|
|
2314
|
+
* @param {string} q - 已经 trim + toLowerCase 过的查询串;空串表示不过滤
|
|
2315
|
+
* @returns {boolean}
|
|
2316
|
+
*/
|
|
2317
|
+
function docMatchesQuery(doc, q) {
|
|
2318
|
+
if (!q) return true
|
|
2319
|
+
return String(doc.title || '').toLowerCase().includes(q)
|
|
2320
|
+
|| String(doc.summary || '').toLowerCase().includes(q)
|
|
2321
|
+
|| String(doc.rel || '').toLowerCase().includes(q)
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2169
2324
|
/**
|
|
2170
2325
|
* 命中片段的**行号区间**文本(v0.20,需求 §11 / §12)。
|
|
2171
2326
|
*
|
|
@@ -3818,6 +3973,16 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3818
3973
|
// v0.15「使用情况」的开闸状态(默认关,见 `USAGE_KEY`)。放在最后 —— 前几个 hook
|
|
3819
3974
|
// 的顺序被测试按位预置,别插队。
|
|
3820
3975
|
const [usageOn, setUsageOn] = React.useState(readUsagePref)
|
|
3976
|
+
/* v0.25:Git 变更关联开关。偏好记在 localStorage(与排序 / 类型 / 检索模式同一族),
|
|
3977
|
+
**默认关**。关着时请求里不带 `changes=1` ⇒ 宿主一个 git 进程都不 spawn。
|
|
3978
|
+
⚠️ **刻意声明在 `usageOn` 之后**:`test/client.test.mjs` 用**指数 seed** 来打开
|
|
3979
|
+
「使用情况」(hook 下标 15),插在它前面会把后面所有下标顶开一位。
|
|
3980
|
+
新 hook 一律往**末尾**追加,别插队。 */
|
|
3981
|
+
const [changesOn, setChangesOn] = React.useState(readChangesPref)
|
|
3982
|
+
/* v0.25(第二轮修订):变更关联来自**独立接口** `/knit/api/changes`,不再挂在
|
|
3983
|
+
`/api/recent` 的 `context` 上 —— 所以它有自己的状态槽。**必须追加在末尾**:
|
|
3984
|
+
前面的 hook 位置被 `test/client.test.mjs` 按位预置。 */
|
|
3985
|
+
const [changesData, setChangesData] = React.useState(null)
|
|
3821
3986
|
|
|
3822
3987
|
// v0.17:两个折叠块的开合状态(上下文外读取 / 最近一次变化)。
|
|
3823
3988
|
// **纯瞬时 UI 状态** —— 不写 pref、不进 `dsh-knit:*` 存储,刷新即回默认(收起)。
|
|
@@ -3879,6 +4044,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3879
4044
|
// 没打开「使用情况」的会话,宿主侧一个事件都不读。
|
|
3880
4045
|
// v0.23:`retrieval` 是**选填**参数 —— 老宿主忽略它(那就等于词法),
|
|
3881
4046
|
// 而词法模式下宿主**一次 provider 调用都不会发**(方案 §9.2 判据 1)。
|
|
4047
|
+
// ⚠️ v0.25(第二轮修订):`/api/recent` 上**一个字节的变更关联都没有** ——
|
|
4048
|
+
// 它的响应形状与 v0.24 逐字相同。变更关联走**独立接口**,见下面那次 fetch。
|
|
3882
4049
|
const url = `${LIST_API}?sessionId=${encodeURIComponent(sessionId)}&limit=40&sort=${sort}&kind=${kind}&retrieval=${sort === 'relevance' && retrieval === 'hybrid' ? 'hybrid' : 'lexical'}${usageOn ? '&usage=1' : ''}`
|
|
3883
4050
|
const res = await fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store' })
|
|
3884
4051
|
const data = await res.json()
|
|
@@ -3914,11 +4081,41 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3914
4081
|
if (!live()) return
|
|
3915
4082
|
setState({ status: 'error', docs: [], root: '', total: 0, error: String((error && error.message) || error), mode: 'time', context: null, usage: null })
|
|
3916
4083
|
}
|
|
4084
|
+
/* v0.25(第二轮修订):**独立接口** `/knit/api/changes`。
|
|
4085
|
+
· 关着时**一个请求都不发**(宿主因此一个 git 进程都不 spawn)——判据 5 的客户端那一半;
|
|
4086
|
+
· 只在「相关」序要它(时间序没有 Context Pack,变更关联无处可落);
|
|
4087
|
+
· 复用宿主刚刚那次扫描(服务端 8 s 同窗)⇒ 两个请求 = 一次扫描 + 一次 git;
|
|
4088
|
+
· 失败一律降级成 `null`(这一区消失),**绝不带坏列表** —— 列表已经落好了。 */
|
|
4089
|
+
const wantChanges = sort === 'relevance' && changesOn
|
|
4090
|
+
if (!wantChanges) {
|
|
4091
|
+
setChangesData((prev) => (prev === null ? prev : null))
|
|
4092
|
+
return
|
|
4093
|
+
}
|
|
4094
|
+
try {
|
|
4095
|
+
// ⚠️ **没有 `kind` 参数**:这一路固定用「文档 + 代码」那一份不分档语料,
|
|
4096
|
+
// 和面板当前在哪个档位无关(档位只切列表那一栏)。
|
|
4097
|
+
const res = await fetch(`${CHANGES_API}?sessionId=${encodeURIComponent(sessionId)}&limit=40&sort=relevance`, {
|
|
4098
|
+
headers: { accept: 'application/json' }, cache: 'no-store',
|
|
4099
|
+
})
|
|
4100
|
+
const data = await res.json()
|
|
4101
|
+
if (!live()) return
|
|
4102
|
+
setChangesData((prev) => {
|
|
4103
|
+
// ⚠️ 「请求失败」与「读不到 git」**不许**都变成 `null`:`null` 是「这个功能没开」,
|
|
4104
|
+
// 用它表示失败会让用户以为「没有变更」。失败有自己的形状(见 `changeStatusOf`)。
|
|
4105
|
+
if (!data || !data.ok) return { failed: true, reason: 'request' }
|
|
4106
|
+
// 载荷一字未变就返回**同一个对象**,React 跳过这次更新(与列表同一套去重理由)
|
|
4107
|
+
const sig = JSON.stringify(data)
|
|
4108
|
+
return (prev && prev.sig === sig) ? prev : { ...data, sig }
|
|
4109
|
+
})
|
|
4110
|
+
} catch {
|
|
4111
|
+
if (!live()) return
|
|
4112
|
+
setChangesData({ failed: true, reason: 'request' })
|
|
4113
|
+
}
|
|
3917
4114
|
// 「读了多久」是按分钟变的相对时间:只有**分钟数**真的变了才落一次刷新信号(其余时候
|
|
3918
4115
|
// 返回同一个值,React 直接跳过这次更新)。标签读的是渲染时刻的钟,不受这里影响。
|
|
3919
4116
|
const now = Date.now()
|
|
3920
4117
|
bumpTick((prev) => (Math.floor(now / 60000) === Math.floor(prev / 60000) ? prev : now))
|
|
3921
|
-
}, [sessionId, sort, kind, usageOn, retrieval])
|
|
4118
|
+
}, [sessionId, sort, kind, usageOn, retrieval, changesOn])
|
|
3922
4119
|
|
|
3923
4120
|
React.useEffect(() => {
|
|
3924
4121
|
// 看不见就一个定时器都不挂:`visible` 变回 true 时本 effect 重跑,立刻 load 一次。
|
|
@@ -3970,10 +4167,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3970
4167
|
const all = Array.isArray(state.docs) ? state.docs : []
|
|
3971
4168
|
const q = query.trim().toLowerCase()
|
|
3972
4169
|
if (!q) return all
|
|
3973
|
-
return all.filter((doc) =>
|
|
3974
|
-
String(doc.title || '').toLowerCase().includes(q)
|
|
3975
|
-
|| String(doc.summary || '').toLowerCase().includes(q)
|
|
3976
|
-
|| String(doc.rel || '').toLowerCase().includes(q))
|
|
4170
|
+
return all.filter((doc) => docMatchesQuery(doc, q))
|
|
3977
4171
|
}, [state.docs, query])
|
|
3978
4172
|
|
|
3979
4173
|
// ResizeObserver 量到的是 .knit-list(它自己也有左右内边距),
|
|
@@ -4043,7 +4237,9 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4043
4237
|
// (AGENTS.md §6.5 同一个坑踩过三次)。
|
|
4044
4238
|
h('div', { className: 'knit-tierline', role: 'presentation' },
|
|
4045
4239
|
h('span', { className: 'knit-tiername' }, t(section.titleKey)),
|
|
4046
|
-
section.hintKey
|
|
4240
|
+
section.hintKey
|
|
4241
|
+
? h('span', { className: 'knit-tierhint' }, t(section.hintKey, section.hintParams))
|
|
4242
|
+
: null),
|
|
4047
4243
|
// ⚠️ 幽灵行(正在离开的)也走 `docsGrid`,所以它照样是一个 `.knit-doc` ——
|
|
4048
4244
|
// 会被 `byClass` 数到,但**不在** `navDocs` 里(键盘与 cursor 都到不了)。
|
|
4049
4245
|
docsGrid(withGhosts(section.key, section.docs), view.numbers, section.key === 'primary', true)))
|
|
@@ -4112,6 +4308,45 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4112
4308
|
if (pinned.length > 0) {
|
|
4113
4309
|
sections.push({ key: 'pinned', titleKey: 'context.pinned', hintKey: 'context.pinnedHint', docs: pinned })
|
|
4114
4310
|
}
|
|
4311
|
+
/* v0.25:**Git 变更关联**。它与固定区是同一类东西:一组有证据、但**不属于这一轮名次**的
|
|
4312
|
+
条目,所以独立成一区、不编号(`numbers` 那边一并跳过它)。
|
|
4313
|
+
⚠️ 这里**不能**用 `visible`(它来自 `state.docs` 那 40 条的切片)—— 一条变更关联的
|
|
4314
|
+
文件很可能排在 40 名之外,用 `visible` 过滤会让整区凭空空掉。它只受**过滤框**约束,
|
|
4315
|
+
与用户在搜索框里打的字保持一致。 */
|
|
4316
|
+
const changeRows = changeRowsOf(changesData)
|
|
4317
|
+
// ⚠️ 这里**自己派生一次**,不复用状态行那份 `changeStatus`:那个常量声明在这个
|
|
4318
|
+
// useMemo **之后**(靠近状态行的渲染),引它会 `Cannot access before initialization`
|
|
4319
|
+
// —— 运行时直接白屏(写完当场被测试抓到)。同一个纯函数、同一个入参,不会分叉。
|
|
4320
|
+
const changeState = changeStatusOf(changesData)
|
|
4321
|
+
const q = query.trim().toLowerCase()
|
|
4322
|
+
const changeDocs = changeRows.filter((item) => !isMedia(item) && docMatchesQuery(item, q)).map(withHits)
|
|
4323
|
+
if (changeDocs.length > 0) {
|
|
4324
|
+
sections.push({ key: 'changes', titleKey: 'context.changes', hintKey: 'context.changesHint', docs: changeDocs })
|
|
4325
|
+
} else if (changesOn && changesData !== null && !changeState.read) {
|
|
4326
|
+
/* v0.25 收尾:**读不到时把原因直接写出来**,不再只放在悬停里。
|
|
4327
|
+
为什么加这一条:真人反馈(2026-10-13)—— 用户看到那一格写「变更 —」,
|
|
4328
|
+
读成了「这个数据没记录到」,而真正的原因是「这个工作区不是 Git 仓库」,
|
|
4329
|
+
它只藏在 `title` 里,不悬停就看不见。
|
|
4330
|
+
⚠️ 条件里的 `changesData !== null` 是必须的:功能刚打开、第一次取数还没回来时
|
|
4331
|
+
`read` 也是 false,那时写「原因未知」是**假话**(不是读不到,是还没读到)。
|
|
4332
|
+
那一瞬间不出这一区,等下一条轮询落地。 */
|
|
4333
|
+
sections.push({
|
|
4334
|
+
key: 'changes', titleKey: 'context.changes', hintKey: 'context.changesUnreadable',
|
|
4335
|
+
hintParams: { reason: t(changeReasonKey(changeState.reason)) },
|
|
4336
|
+
docs: [],
|
|
4337
|
+
})
|
|
4338
|
+
} else if (changesOn && changeState.read && changeState.filesTotal > 0) {
|
|
4339
|
+
/* v0.25 收尾:**有变更、但一条关联证据都没有**时要说得出来。
|
|
4340
|
+
这一区是**只带提示句、不带行**的(区头照常出现)—— 用户因此能区分
|
|
4341
|
+
「没有变更」(那一格写 0,这里什么都不出)与「有变更但没找到该一起看的」。
|
|
4342
|
+
读不到 git 的那种情况**不在这里**:它的提示在状态行那一格(「变更 —」 + 悬停原因),
|
|
4343
|
+
因为「读不到」不是一条列表内容。 */
|
|
4344
|
+
sections.push({
|
|
4345
|
+
key: 'changes', titleKey: 'context.changes',
|
|
4346
|
+
hintKey: 'context.changesEmpty', hintParams: { files: changeState.filesTotal },
|
|
4347
|
+
docs: [],
|
|
4348
|
+
})
|
|
4349
|
+
}
|
|
4115
4350
|
for (const [tierKey, titleKey, hintKey] of tiers) {
|
|
4116
4351
|
const items = Array.isArray(pack[tierKey]) ? pack[tierKey] : []
|
|
4117
4352
|
const docs = items.filter((item) => visible.has(item.rel)).map(withHits)
|
|
@@ -4125,6 +4360,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4125
4360
|
}
|
|
4126
4361
|
// 固定区里的也在包里 —— 它们同样不该出现在「其他相关文档」。
|
|
4127
4362
|
for (const item of (Array.isArray(pack.pinned) ? pack.pinned : [])) placed.add(item.rel)
|
|
4363
|
+
// 变更关联区里的也不再出现在「其他相关文档」(同一篇不该在两处出现)
|
|
4364
|
+
for (const item of changeRows) placed.add(item.rel)
|
|
4128
4365
|
const rest = visibleDocs.filter((doc) => !isMedia(doc) && !placed.has(doc.rel))
|
|
4129
4366
|
if (rest.length > 0) {
|
|
4130
4367
|
sections.push({ key: 'other', titleKey: 'context.other', hintKey: '', docs: rest })
|
|
@@ -4136,14 +4373,14 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4136
4373
|
// v0.21:**固定区也不编号** —— 它的位置由用户决定,不由阅读顺序决定。
|
|
4137
4374
|
const numbers = new Map()
|
|
4138
4375
|
for (const section of sections) {
|
|
4139
|
-
if (section.key === 'other' || section.key === 'pinned') continue
|
|
4376
|
+
if (section.key === 'other' || section.key === 'pinned' || section.key === 'changes') continue
|
|
4140
4377
|
for (const doc of section.docs) numbers.set(doc.rel, numbers.size + 1)
|
|
4141
4378
|
}
|
|
4142
4379
|
// 键盘到达顺序 = 屏幕上从上到下的顺序(分组顺序 + 组内顺序)
|
|
4143
4380
|
const flat = []
|
|
4144
4381
|
for (const section of sections) for (const doc of section.docs) flat.push(doc)
|
|
4145
4382
|
return { sections, flat, numbers }
|
|
4146
|
-
}, [relevance, kind, state.context, visibleDocs])
|
|
4383
|
+
}, [relevance, kind, state.context, changesData, visibleDocs, query])
|
|
4147
4384
|
|
|
4148
4385
|
/**
|
|
4149
4386
|
* 键盘与 cursor 真正能到达的条目。
|
|
@@ -4520,6 +4757,16 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4520
4757
|
setSemNotice('')
|
|
4521
4758
|
}, [])
|
|
4522
4759
|
|
|
4760
|
+
/**
|
|
4761
|
+
* v0.25:切换「Git 变更关联」并记住偏好。**只切偏好** —— 真正跑 git 的是宿主,
|
|
4762
|
+
* 下一次 `load()` 会带上 `changes=1`。关掉时请求里就不带了(宿主零开销)。
|
|
4763
|
+
* @param {boolean} value - 是否开启
|
|
4764
|
+
*/
|
|
4765
|
+
const pickChanges = React.useCallback((value) => {
|
|
4766
|
+
writePref(CHANGES_KEY, value ? '1' : '0')
|
|
4767
|
+
setChangesOn(value)
|
|
4768
|
+
}, [])
|
|
4769
|
+
|
|
4523
4770
|
/** 切换列表类型并记住偏好;同时收起上一类型的预览。 */
|
|
4524
4771
|
const pickKind = React.useCallback((value) => {
|
|
4525
4772
|
writePref(KIND_KEY, value)
|
|
@@ -5329,6 +5576,42 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5329
5576
|
className: 'knit-retmenu-cfg',
|
|
5330
5577
|
onClick: () => { setRetMenuOpen(false); setSemCfgOpen((value) => !value) },
|
|
5331
5578
|
}, t(semCfgOpen ? 'sem.cfg.hide' : 'sem.cfg.show')) : null) : null)
|
|
5579
|
+
/* v0.25:Git 变更关联那一格(见上面 CSS 的说明)。三种话术,都由**宿主的事实**决定:
|
|
5580
|
+
关着 / 开着且有数 / 开着但读不到(写原因)。读完就关也不会留下悬念。 */
|
|
5581
|
+
/* v0.25(第二轮修订):这一格的数字来自**独立接口**的那份载荷,不再来自 Context Pack。
|
|
5582
|
+
v0.25 收尾:**三种状态必须互相可辨**(这是原来那版最实的一个缺口 ——
|
|
5583
|
+
请求失败时那一格显示成「关着」的样子,用户会把「读不到」读成「没有变更」):
|
|
5584
|
+
· 关着 → 归一成 `null` → 「变更」
|
|
5585
|
+
· 开着但读不到 → `failed` / `git.available === false` → 「变更 —」+ 悬停写原因
|
|
5586
|
+
· 开着且读到了 → `git.available === true` → 「变更 N」(N = 变更文件数)
|
|
5587
|
+
⚠️ 「有变更但没有关联」与「有变更且有关联」在状态行上是同一个 `变更 N` ——
|
|
5588
|
+
它们的区别在**列表里那一区的提示句**(见 `contextView`),不在这一格。 */
|
|
5589
|
+
const changeStatus = changeStatusOf(changesData)
|
|
5590
|
+
const changeInfo = changeStatus.read ? { ...changeStatus, relatedTotal: Number(changesData.linksTotal) || 0 } : null
|
|
5591
|
+
const changeFiles = changeInfo && Number.isFinite(changeInfo.filesTotal) ? changeInfo.filesTotal : 0
|
|
5592
|
+
const changesLabel = !changesOn
|
|
5593
|
+
? t('pipe.changesOff')
|
|
5594
|
+
: (!changeStatus.read
|
|
5595
|
+
? t('pipe.changesUnavailable')
|
|
5596
|
+
: t('pipe.changesOn', { n: changeFiles }))
|
|
5597
|
+
const changesTitle = !changesOn
|
|
5598
|
+
? t('changes.titleOff')
|
|
5599
|
+
: (!changeStatus.read
|
|
5600
|
+
? t('changes.titleUnavailable', { reason: t(changeReasonKey(changeStatus.reason)) })
|
|
5601
|
+
: t('changes.titleOn', {
|
|
5602
|
+
files: changeFiles,
|
|
5603
|
+
related: changeInfo ? (Number(changeInfo.relatedTotal) || 0) : 0,
|
|
5604
|
+
}))
|
|
5605
|
+
const changesNode = h('button', {
|
|
5606
|
+
type: 'button',
|
|
5607
|
+
className: 'knit-pipe-changes',
|
|
5608
|
+
'aria-pressed': changesOn ? 'true' : 'false',
|
|
5609
|
+
title: changesTitle,
|
|
5610
|
+
onClick: (event) => {
|
|
5611
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
5612
|
+
pickChanges(!changesOn)
|
|
5613
|
+
},
|
|
5614
|
+
}, h('span', { className: 'knit-pipe-changes-label' }, changesLabel))
|
|
5332
5615
|
const pipeNode = h('div', { className: 'knit-pipe' },
|
|
5333
5616
|
pipeCell(t('pipe.collect', { n: collected })),
|
|
5334
5617
|
pipeDot(),
|
|
@@ -5344,6 +5627,10 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5344
5627
|
pipeCell(t('pipe.relations', { n: relCount })),
|
|
5345
5628
|
pipeDot(),
|
|
5346
5629
|
pipeCell(t('pipe.pin', { n: pinnedCount })),
|
|
5630
|
+
pipeDot(),
|
|
5631
|
+
// v0.25:入口就是这一格 —— **默认关**,关着也出现(藏起来用户就永远打不开)。
|
|
5632
|
+
// 它说的是宿主回的**事实**(几个变更文件 / 读不到的原因),不是「你点了什么」。
|
|
5633
|
+
changesNode,
|
|
5347
5634
|
pipeSep(),
|
|
5348
5635
|
// 唯一略微加重的一格:它是这一行里被后续阶段消费的那个数字(需求 §三.8:
|
|
5349
5636
|
// 只提字重,不用品牌色、不做徽章)。
|