dsh-knit 0.12.0 → 0.12.1
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 +46 -0
- package/README.en.md +5 -3
- package/README.md +3 -2
- package/package.json +1 -1
- package/src/client/client.js +37 -9
- package/test/i18n.test.mjs +123 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,52 @@
|
|
|
3
3
|
本项目的重要变更都记在这里。格式参考 [Keep a Changelog](https://keepachangelog.com/),
|
|
4
4
|
版本号遵循[语义化版本](https://semver.org/lang/zh-CN/)。
|
|
5
5
|
|
|
6
|
+
## [0.12.1] - 2026-09-19
|
|
7
|
+
|
|
8
|
+
**一张真机截图抓出来的修复版。** 没有新功能,两件事:把三处**硬编码中文**收进词典,
|
|
9
|
+
以及让 README 里那张图**第一次真的能在 npm 页面上显示**。
|
|
10
|
+
|
|
11
|
+
### 修了什么
|
|
12
|
+
|
|
13
|
+
英文界面下,文档行右边显示的是中文 `3 分钟前` —— 面板其余部分都是英文。
|
|
14
|
+
扫过整个客户端后确认,词典之外只有三处裸中文(其余文案全部走 `t()`):
|
|
15
|
+
|
|
16
|
+
| 位置 | 原来 | 现在 |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `relTime()` 的六条时间文案 | `刚刚` / `X分钟前` / `X小时前` / `昨天` / `X天前` / `X月X日` | 六个 `time.*` 键,中英各一套 |
|
|
19
|
+
| 文档列表的 `aria-label` | `最近文档` | 键 `list.aria` |
|
|
20
|
+
| better-sidebar 的 tab 标题 | `Knit 最近文档` | 复用 `guide.title`(顺带把两个宿主的口径统一了) |
|
|
21
|
+
|
|
22
|
+
违反的是项目自己的规矩:**文案一律走 i18n,宿主只返回错误码**。
|
|
23
|
+
|
|
24
|
+
### 加了 4 条守卫(测试 276 → 280)
|
|
25
|
+
|
|
26
|
+
1. 英文环境渲染出的整棵树里**一个汉字都没有**
|
|
27
|
+
2. 英文环境下 `aria-label` / `title` / `placeholder` / `alt` 里也没有汉字
|
|
28
|
+
3. 相对时间的**六个分支**都随语言
|
|
29
|
+
4. better-sidebar 的 tab 标题随语言
|
|
30
|
+
|
|
31
|
+
既有那条冒烟用例(只写死 `刷新|按` 两个词去查)**当时没抓住 `3 分钟前`** ——
|
|
32
|
+
新守卫改成「不许有任何汉字」,不再靠枚举词。
|
|
33
|
+
|
|
34
|
+
> ⚠️ **每条守卫都做了证伪**(把三处改回硬编码 → 4 条全红;恢复 → 全绿)。
|
|
35
|
+
> 第一版守卫用的是现成语料,两篇文档只落在 2 个时间分支上 ——
|
|
36
|
+
> **把 `分钟前` 改回去,守卫竟然全绿**。所以新增一份把六个时间粒度走全的语料。
|
|
37
|
+
> **「测试通过」不等于「测到了」。**
|
|
38
|
+
|
|
39
|
+
### 图片
|
|
40
|
+
|
|
41
|
+
- **README 第 1 屏换成当前 UI 的真机截图**(中文界面、引用条两组都展开)。
|
|
42
|
+
之前那张停在 v0.5.x,与 v0.6–v0.12 的改动全都对不上
|
|
43
|
+
- **README 里的图片地址改成绝对 raw URL** —— npm 页面上这张图**从 `0.5.0` 起就没显示过**:
|
|
44
|
+
用的是相对路径,而 `docs/` 不在 `files` 白名单里,文件根本没进包
|
|
45
|
+
(`unpkg.com/dsh-knit@0.12.0/docs/screenshot.png` → 404)。改完之后换图也不必再发版本
|
|
46
|
+
|
|
47
|
+
### 注意
|
|
48
|
+
|
|
49
|
+
- 本版**没有行为变化**:不改排序、不改接口、不改面板逻辑
|
|
50
|
+
- 客户端半边改动**硬刷新浏览器即可**,不需要重启 DSH
|
|
51
|
+
|
|
6
52
|
## [0.12.0] - 2026-09-19
|
|
7
53
|
|
|
8
54
|
**让文档之间那层「引用关系」看得见。** 预览一篇时,面板给出「**这篇被谁引用 / 这篇引用了谁**」,
|
package/README.en.md
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
>
|
|
6
6
|
> **Your agent has the same problem.** It gets the same ranking as a tool — the ranked documents plus the passage that matched in each.
|
|
7
7
|
|
|
8
|
-

|
|
9
9
|
|
|
10
|
-
*Screenshot from a real machine, not a mock-up: a workspace with
|
|
11
|
-
|
|
10
|
+
*Screenshot from a real machine, not a mock-up: a workspace with 34 documents — the list, an inline
|
|
11
|
+
preview, and the references bar.*
|
|
12
|
+
*The references bar is new in v0.12: expand it to see which documents reference this one, and click
|
|
13
|
+
one to jump straight there.*
|
|
12
14
|
*The top line follows whatever you're talking about; when there isn't enough conversation yet it
|
|
13
15
|
falls back to newest-first and states its basis.*
|
|
14
16
|
|
package/README.md
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
>
|
|
6
6
|
> **你的 agent 也一样。** 同一份排序也给它当工具用 —— 它问「哪几篇相关」,拿回排名**加每篇里命中的那段原文**。
|
|
7
7
|
|
|
8
|
-

|
|
9
9
|
|
|
10
|
-
*真机截图(不是原型):一个含
|
|
10
|
+
*真机截图(不是原型):一个含 34 篇文档的工作区 —— 列表 + 就地预览 + 引用条。*
|
|
11
|
+
*引用条是 v0.12 加的:展开就能看到「这篇被谁引用」,点一项直接跳过去。*
|
|
11
12
|
*顶行会跟着你正在聊什么变;对话内容还不足时它退回按时间排,并如实说明依据。*
|
|
12
13
|
|
|
13
14
|
扫整个项目文件夹的 Markdown / 图片 / 视频 · 排序跟着对话走 · 不调模型、不联网
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-knit",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Find the doc your agent just wrote. Lists the DSH workspace's Markdown, images and video in the sidebar, ranked by relevance to the current conversation, with inline preview — and hands the same ranking to the agent as a tool, returning the passage that matched in each document. Zero model calls, zero network.",
|
|
6
6
|
"main": "./src/host/index.js",
|
package/src/client/client.js
CHANGED
|
@@ -68,6 +68,17 @@ window.__ModuleLoader__.load({
|
|
|
68
68
|
'list.empty': '这个工作区里还没有 Markdown 文档。',
|
|
69
69
|
'list.emptyMedia': '这个工作区里还没有图片或视频。',
|
|
70
70
|
'list.noMatch': '没有匹配「{query}」的文档。',
|
|
71
|
+
// 文档列表这个 listbox 的无障碍名字(原先硬编码在 JSX 里,英文界面下会漏出中文)
|
|
72
|
+
'list.aria': '最近文档',
|
|
73
|
+
|
|
74
|
+
// 相对时间。⚠️ 这六条原先**硬编码在 relTime() 里**,英文界面下会漏出中文
|
|
75
|
+
// (2026-09-19 被真机截图抓出来的)。**加时间粒度时必须同时加中英两条。**
|
|
76
|
+
'time.justNow': '刚刚',
|
|
77
|
+
'time.minutesAgo': '{n}分钟前',
|
|
78
|
+
'time.hoursAgo': '{n}小时前',
|
|
79
|
+
'time.yesterday': '昨天',
|
|
80
|
+
'time.daysAgo': '{n}天前',
|
|
81
|
+
'time.monthDay': '{month}月{day}日',
|
|
71
82
|
|
|
72
83
|
'media.play': '播放视频',
|
|
73
84
|
|
|
@@ -166,6 +177,18 @@ window.__ModuleLoader__.load({
|
|
|
166
177
|
'list.empty': 'No Markdown documents in this workspace yet.',
|
|
167
178
|
'list.emptyMedia': 'No images or videos in this workspace yet.',
|
|
168
179
|
'list.noMatch': 'No documents match “{query}”.',
|
|
180
|
+
// Accessible name of the document listbox (was hardcoded in JSX before)
|
|
181
|
+
'list.aria': 'Recent documents',
|
|
182
|
+
|
|
183
|
+
// Relative time. ⚠️ These six used to be **hardcoded inside relTime()** and leaked
|
|
184
|
+
// Chinese into the English UI (caught by a real-machine screenshot, 2026-09-19).
|
|
185
|
+
// **Add both languages whenever you add a granularity.**
|
|
186
|
+
'time.justNow': 'just now',
|
|
187
|
+
'time.minutesAgo': '{n} min ago',
|
|
188
|
+
'time.hoursAgo': '{n} h ago',
|
|
189
|
+
'time.yesterday': 'yesterday',
|
|
190
|
+
'time.daysAgo': '{n} d ago',
|
|
191
|
+
'time.monthDay': '{month}/{day}',
|
|
169
192
|
|
|
170
193
|
'media.play': 'Play video',
|
|
171
194
|
|
|
@@ -881,22 +904,27 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
881
904
|
|
|
882
905
|
/**
|
|
883
906
|
* 人类可读的相对时间。
|
|
907
|
+
*
|
|
908
|
+
* ⚠️ **文案必须走 `t()`。** 这六条原先硬编码中文,英文界面下会漏出「3 分钟前」——
|
|
909
|
+
* 2026-09-19 的真机截图把它抓出来了(`test/i18n.test.mjs` 有守卫:
|
|
910
|
+
* 英文渲染出来的整棵树里不许出现汉字)。
|
|
911
|
+
*
|
|
884
912
|
* @param {number} ms - 文件 mtime(epoch ms)
|
|
885
913
|
* @param {number} now - 当前时间
|
|
886
|
-
* @returns {string} 刚刚 / X分钟前 / X小时前 / 昨天 / X天前 /
|
|
914
|
+
* @returns {string} 刚刚 / X分钟前 / X小时前 / 昨天 / X天前 / 月日(按当前语言)
|
|
887
915
|
*/
|
|
888
916
|
function relTime(ms, now) {
|
|
889
917
|
const diff = Math.max(0, now - ms)
|
|
890
918
|
const min = Math.floor(diff / 60000)
|
|
891
|
-
if (min < 1) return '
|
|
892
|
-
if (min < 60) return
|
|
919
|
+
if (min < 1) return t('time.justNow')
|
|
920
|
+
if (min < 60) return t('time.minutesAgo', { n: min })
|
|
893
921
|
const hour = Math.floor(min / 60)
|
|
894
|
-
if (hour < 24) return
|
|
922
|
+
if (hour < 24) return t('time.hoursAgo', { n: hour })
|
|
895
923
|
const day = Math.floor(hour / 24)
|
|
896
|
-
if (day === 1) return '
|
|
897
|
-
if (day < 30) return
|
|
924
|
+
if (day === 1) return t('time.yesterday')
|
|
925
|
+
if (day < 30) return t('time.daysAgo', { n: day })
|
|
898
926
|
const d = new Date(ms)
|
|
899
|
-
return
|
|
927
|
+
return t('time.monthDay', { month: d.getMonth() + 1, day: d.getDate() })
|
|
900
928
|
}
|
|
901
929
|
|
|
902
930
|
/**
|
|
@@ -1714,7 +1742,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1714
1742
|
tabIndex: 0,
|
|
1715
1743
|
onKeyDown: onListKeyDown,
|
|
1716
1744
|
role: 'listbox',
|
|
1717
|
-
'aria-label': '
|
|
1745
|
+
'aria-label': t('list.aria'),
|
|
1718
1746
|
}, body),
|
|
1719
1747
|
preview ? h(PreviewPanel, {
|
|
1720
1748
|
preview,
|
|
@@ -2253,7 +2281,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2253
2281
|
|
|
2254
2282
|
bsCtx.effect(() => bs.registerTab({
|
|
2255
2283
|
id: BS_TAB_ID,
|
|
2256
|
-
title: () => '
|
|
2284
|
+
title: () => t('guide.title'),
|
|
2257
2285
|
icon: KnitGlyph,
|
|
2258
2286
|
order: 30,
|
|
2259
2287
|
single: true, // 同类型只开一个
|
package/test/i18n.test.mjs
CHANGED
|
@@ -17,9 +17,10 @@ const h = React.createElement
|
|
|
17
17
|
/**
|
|
18
18
|
* 造一个假上下文,用于把模块 apply 起来(真实运行时由 DSH 调用)。
|
|
19
19
|
* @param {string} locale - 活动语言
|
|
20
|
+
* @param {{betterSidebar?: boolean}} [extra] - 额外提供哪些可选服务
|
|
20
21
|
* @returns {{ctx: object, log: object, registered: object}} 上下文与记录
|
|
21
22
|
*/
|
|
22
|
-
function contextFor(locale) {
|
|
23
|
+
function contextFor(locale, extra = {}) {
|
|
23
24
|
const log = { tabs: [], bsTabs: [], slots: [], effects: [] }
|
|
24
25
|
const { locale: localeService, registered } = makeLocale({ active: locale })
|
|
25
26
|
|
|
@@ -30,6 +31,9 @@ function contextFor(locale) {
|
|
|
30
31
|
|
|
31
32
|
const services = { slots, locale: localeService }
|
|
32
33
|
services.sidebarRightTabs = { register(def) { log.tabs.push(def); return () => {} } }
|
|
34
|
+
if (extra.betterSidebar) {
|
|
35
|
+
services.betterSidebar = { registerTab(def) { log.bsTabs.push(def); return () => {} } }
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
const ctx = {
|
|
35
39
|
slots,
|
|
@@ -51,11 +55,12 @@ function contextFor(locale) {
|
|
|
51
55
|
* 装载模块并 apply 到指定语言。
|
|
52
56
|
* @param {string} locale - 活动语言
|
|
53
57
|
* @param {object} [options] - 传给 loadClientModule
|
|
58
|
+
* @param {{betterSidebar?: boolean}} [extra] - 额外提供哪些可选服务
|
|
54
59
|
* @returns {{exports: object, log: object, registered: object}} 结果
|
|
55
60
|
*/
|
|
56
|
-
function boot(locale, options) {
|
|
61
|
+
function boot(locale, options, extra) {
|
|
57
62
|
const loaded = loadClientModule(options)
|
|
58
|
-
const { ctx, log, registered } = contextFor(locale)
|
|
63
|
+
const { ctx, log, registered } = contextFor(locale, extra)
|
|
59
64
|
loaded.exports.apply(ctx)
|
|
60
65
|
return { exports: loaded.exports, log, registered, markdownCalls: loaded.markdownCalls }
|
|
61
66
|
}
|
|
@@ -342,6 +347,121 @@ test('冒烟:中英环境下渲染同一份数据都不抛错,且文案确
|
|
|
342
347
|
assert.ok(!/刷新|按/.test(enText), `英文环境混进了中文:${enText}`)
|
|
343
348
|
})
|
|
344
349
|
|
|
350
|
+
/* ── 硬编码中文的守卫(2026-09-19 加的)──────────────────
|
|
351
|
+
*
|
|
352
|
+
* 起因:真机截图暴露「英文界面 + 中文『3 分钟前』」——`relTime()` 把那六条时间文案
|
|
353
|
+
* 硬编码在函数里,没进词典。同一批还查出两处:文档列表的 `aria-label`、
|
|
354
|
+
* better-sidebar 的 tab 标题。
|
|
355
|
+
*
|
|
356
|
+
* 上面那条冒烟用例**当时没抓住它**,因为它只硬编码地查了 `刷新|按` 两个词 ——
|
|
357
|
+
* 写死几个词等于给未来留了个洞。所以这里换成**通用判据**:
|
|
358
|
+
* 英文环境渲染出的整棵树里,文字与无障碍属性都不许出现汉字。
|
|
359
|
+
*
|
|
360
|
+
* ⚠️ 语料必须保持 ASCII(`listPayload()` 的标题是 'A' / 'B'):
|
|
361
|
+
* 文档自带的中文标题会把这条用例误报成失败,而那是**数据**、不是**文案**。
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* 收集渲染树里所有**直接**文本子节点(不走子树,避免重复)。
|
|
366
|
+
* @param {object[]} nodes - 扁平节点
|
|
367
|
+
* @returns {string[]} 文本片段
|
|
368
|
+
*/
|
|
369
|
+
function ownTexts(nodes) {
|
|
370
|
+
return nodes.flatMap((n) => (n.children || []).filter((c) => typeof c === 'string'))
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* 挑出含汉字的片段,失败信息里就能直接看出漏了哪一条。
|
|
375
|
+
* @param {string[]} texts - 文本片段
|
|
376
|
+
* @returns {string[]} 含汉字的片段
|
|
377
|
+
*/
|
|
378
|
+
function cjkIn(texts) {
|
|
379
|
+
return texts.filter((s) => /[\u3400-\u9fff]/.test(s))
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const MIN = 60 * 1000
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 造一份**把相对时间六个分支全走一遍**的列表载荷。
|
|
386
|
+
*
|
|
387
|
+
* ⚠️ 这份语料不能省。第一版守卫用的是 `listPayload()`,它两篇文档只落在
|
|
388
|
+
* `justNow` 与 `yesterday` 两个分支上 —— 于是「把 `分钟前` 硬编码回去」
|
|
389
|
+
* 这种回归**测不出来**(我实测过:补丁打上去,守卫照样全绿)。
|
|
390
|
+
* 真机截图里漏出来的恰恰就是 `分钟前` 那一条。
|
|
391
|
+
*
|
|
392
|
+
* @returns {object} 载荷
|
|
393
|
+
*/
|
|
394
|
+
function timePayload() {
|
|
395
|
+
const now = Date.now()
|
|
396
|
+
const ages = [
|
|
397
|
+
['now.md', 0],
|
|
398
|
+
['min.md', 5 * MIN],
|
|
399
|
+
['hour.md', 5 * 60 * MIN],
|
|
400
|
+
['yest.md', 25 * 60 * MIN],
|
|
401
|
+
['days.md', 3 * 24 * 60 * MIN],
|
|
402
|
+
['month.md', 40 * 24 * 60 * MIN],
|
|
403
|
+
]
|
|
404
|
+
return {
|
|
405
|
+
ok: true,
|
|
406
|
+
root: '/p',
|
|
407
|
+
total: ages.length,
|
|
408
|
+
mode: 'time',
|
|
409
|
+
topic: '',
|
|
410
|
+
docs: ages.map(([rel, age]) => ({
|
|
411
|
+
path: `/p/${rel}`, rel, name: rel, title: rel, summary: 's', mtimeMs: now - age, score: null,
|
|
412
|
+
})),
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
test('守卫:英文环境渲染出的整棵树里一个汉字都没有', async () => {
|
|
417
|
+
// 用 timePayload:六个时间分支都要真的渲染出来,否则守卫是「没覆盖的空转绿灯」
|
|
418
|
+
const { nodes } = await renderPanel('en', () => timePayload())
|
|
419
|
+
const bad = cjkIn(ownTexts(nodes))
|
|
420
|
+
assert.deepEqual(bad, [], `英文渲染里混进了中文(说明有文案没走 t()):${bad.join(' / ')}`)
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
test('守卫:英文环境下无障碍与提示属性里也没有汉字', async () => {
|
|
424
|
+
const { nodes } = await renderPanel('en', () => timePayload())
|
|
425
|
+
const attrs = ['aria-label', 'title', 'placeholder', 'alt']
|
|
426
|
+
const bad = []
|
|
427
|
+
for (const n of nodes) {
|
|
428
|
+
for (const a of attrs) {
|
|
429
|
+
const v = n.props[a]
|
|
430
|
+
if (typeof v === 'string' && /[\u3400-\u9fff]/.test(v)) bad.push(`${a}="${v}"`)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
assert.deepEqual(bad, [], `英文环境的属性里混进了中文:${bad.join(' / ')}`)
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
test('守卫:相对时间的六个分支都随语言(原来是硬编码中文)', async () => {
|
|
437
|
+
const en = await renderPanel('en', () => timePayload())
|
|
438
|
+
const enTimes = byClass(en.nodes, 'knit-time').map(textOf)
|
|
439
|
+
assert.equal(enTimes.length, 6, `六个分支都该渲染出来,实际只有 ${enTimes.length} 条`)
|
|
440
|
+
assert.deepEqual(
|
|
441
|
+
enTimes.slice(0, 5),
|
|
442
|
+
['just now', '5 min ago', '5 h ago', 'yesterday', '3 d ago'],
|
|
443
|
+
)
|
|
444
|
+
// 第六档是「月/日」,具体日期随当天变,只校验形状
|
|
445
|
+
assert.match(enTimes[5], /^\d{1,2}\/\d{1,2}$/, `英文的月日应形如 8/10,实际是 ${enTimes[5]}`)
|
|
446
|
+
|
|
447
|
+
const zh = await renderPanel('zh', () => timePayload())
|
|
448
|
+
const zhTimes = byClass(zh.nodes, 'knit-time').map(textOf)
|
|
449
|
+
assert.deepEqual(
|
|
450
|
+
zhTimes.slice(0, 5),
|
|
451
|
+
['刚刚', '5分钟前', '5小时前', '昨天', '3天前'],
|
|
452
|
+
)
|
|
453
|
+
assert.match(zhTimes[5], /^\d{1,2}月\d{1,2}日$/, `中文的月日应形如 8月10日,实际是 ${zhTimes[5]}`)
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
test('守卫:better-sidebar 的 tab 标题随语言(复用 guide.title,不再写死)', () => {
|
|
457
|
+
const en = boot('en', undefined, { betterSidebar: true })
|
|
458
|
+
assert.equal(en.log.bsTabs.length, 1, '应注册一个 better-sidebar tab')
|
|
459
|
+
assert.equal(en.log.bsTabs[0].title(), 'Knit — recent documents')
|
|
460
|
+
|
|
461
|
+
const zh = boot('zh', undefined, { betterSidebar: true })
|
|
462
|
+
assert.equal(zh.log.bsTabs[0].title(), 'Knit 最近文档')
|
|
463
|
+
})
|
|
464
|
+
|
|
345
465
|
/* ── 文案洁癖:词典里不出现表情装饰 ───────────────────── */
|
|
346
466
|
|
|
347
467
|
test('词典:不出现 🤖 之类的表情字符(用户明确要求删掉)', async () => {
|