dsh-zdiary-kit 3.8.0 → 3.9.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/dist/lib/zk.js CHANGED
@@ -17,7 +17,8 @@ import { withFileLockSync } from './lock.js';
17
17
  import { parseFrontmatter, setFrontmatter } from './frontmatter.js';
18
18
  import { isMetaPath, META_NAMES } from './meta.js';
19
19
  import { similarCandidates } from './similar.js';
20
- import { normalizeTitle } from './wikilink.js';
20
+ import { linkContextOf } from './edge-context.js';
21
+ import { normalizeTitle, noteKey } from './wikilink.js';
21
22
  export class ZkError extends Error {
22
23
  hint;
23
24
  /**
@@ -1283,9 +1284,18 @@ async function linkedNotes(cfg, flag, rel, opts = {}, signal) {
1283
1284
  const args = ['list', '--quiet', '--no-pager', '--format', 'json', '--limit', String(limit + 1), flag, abs];
1284
1285
  for (const name of excludedNames(cfg, { includeArchived: opts.includeArchived }))
1285
1286
  args.push('-x', name);
1286
- const notes = parseList(await zk(cfg, args, { signal })).map((raw) => toRecord(raw, cfg));
1287
+ const raws = parseList(await zk(cfg, args, { signal }));
1288
+ const notes = raws.map((raw) => toRecord(raw, cfg));
1287
1289
  const truncated = notes.length > limit;
1288
- return { notes: notes.slice(0, limit), truncated, completeness: truncated ? 'partial' : 'complete' };
1290
+ const result = { notes: notes.slice(0, limit), truncated, completeness: truncated ? 'partial' : 'complete' };
1291
+ if (opts.keepContent) {
1292
+ const contents = new Map();
1293
+ for (let i = 0; i < notes.length; i += 1) {
1294
+ contents.set(notes[i].path, String(raws[i]?.rawContent ?? raws[i]?.body ?? ''));
1295
+ }
1296
+ result.contents = contents;
1297
+ }
1298
+ return result;
1289
1299
  }
1290
1300
  /** 谁链到这篇(入链 / 反链)。路径是笔记本相对的;目标不存在时返回空,不返回全库 */
1291
1301
  export async function backlinksOf(cfg, rel, opts = {}, signal) {
@@ -1297,6 +1307,138 @@ export async function outlinksOf(cfg, rel, opts = {}, signal) {
1297
1307
  const found = await linkedNotes(cfg, '--linked-by', rel, opts, signal);
1298
1308
  return { ...found, notes: found.notes.filter((n) => n.path !== rel) };
1299
1309
  }
1310
+ /** `[[目标|别名]]` / `[[目标#小节]]` / `./notes/x.md` → `notes/x` 形态的裸目标 */
1311
+ function walkSeedTarget(raw) {
1312
+ let target = String(raw ?? '').trim();
1313
+ const wrapped = /^\[\[([^\]]*)\]\]$/.exec(target);
1314
+ if (wrapped)
1315
+ target = String(wrapped[1] ?? '');
1316
+ return target.split('|')[0].split('#')[0].trim().replace(/\\/g, '/').replace(/^\.\//, '');
1317
+ }
1318
+ /** 看起来是路径(含目录分隔符或 .md 后缀)—— 路径种子不查索引,直接看磁盘 */
1319
+ function looksLikePath(target) {
1320
+ return target.includes('/') || /\.(md|markdown)$/i.test(target);
1321
+ }
1322
+ function seedAt(cfg, rel, opts = {}) {
1323
+ const root = path.resolve(cfg.notebook);
1324
+ const abs = path.resolve(cfg.notebook, rel);
1325
+ if (abs !== root && !abs.startsWith(root + path.sep))
1326
+ return null;
1327
+ // 种子也是「进入网络的入口」:meta / raw / inbox 不是可导航的笔记,归档要先显式允许。
1328
+ // 与邻居侧的 `excludedNames` 同口径 —— 不能只有邻居过滤、种子随便进(plan §14.5)。
1329
+ const norm = rel.replace(/\\/g, '/').replace(/^\.\//, '');
1330
+ if (isMetaPath(norm))
1331
+ return null;
1332
+ if (norm === 'raw' || norm.startsWith('raw/') || norm === 'inbox' || norm.startsWith('inbox/'))
1333
+ return null;
1334
+ if (!opts.includeArchived && inArchive(cfg, norm))
1335
+ return null;
1336
+ try {
1337
+ if (!fs.statSync(abs).isFile())
1338
+ return null;
1339
+ }
1340
+ catch {
1341
+ return null;
1342
+ }
1343
+ let title = '';
1344
+ try {
1345
+ title = String(parseFrontmatter(fs.readFileSync(abs, 'utf8')).fields.title ?? '');
1346
+ }
1347
+ catch { /* 标题只作回显 */ }
1348
+ return { title: title || path.basename(rel, path.extname(rel)), path: rel, absPath: abs };
1349
+ }
1350
+ /**
1351
+ * 种子解析:路径 / `[[路径]]` 只看磁盘(0 个子进程);标题 / `[[id]]` 走一次 `zk list -M exact`(1 个子进程)。
1352
+ *
1353
+ * 为什么不用「全库扫描 + resolveWikiTarget」:10k 上那是一整趟 `zk list`(约 2.6 s / 2 MB),
1354
+ * 会把单种子 1 跳从 2 个进程抬到 3 个,与 R8 的成本口径(§11.3)不符。
1355
+ * `-M exact` 实测能命中 frontmatter 的 id 与标题,但它是「逐词精确」而不是「整串相等」
1356
+ * (`记忆预算` 会同时命中 `记忆预算的另一篇`),所以拿到候选后还要在 JS 里比对一次
1357
+ * id / 标题 / 文件名,对不上就当没找到 —— 不拿第一个命中冒充种子。
1358
+ */
1359
+ async function resolveWalkSeed(cfg, raw, opts = {}, signal) {
1360
+ const target = walkSeedTarget(raw);
1361
+ if (!target)
1362
+ return null;
1363
+ if (looksLikePath(target)) {
1364
+ const candidates = /\.(md|markdown)$/i.test(target) ? [target] : [target, `${target}.md`];
1365
+ for (const candidate of candidates) {
1366
+ const hit = seedAt(cfg, candidate, opts);
1367
+ if (hit)
1368
+ return hit;
1369
+ }
1370
+ return null;
1371
+ }
1372
+ const args = [
1373
+ 'list', '--quiet', '--no-pager', '--format', LEAN_TEMPLATE, '-d', LEAN_RECORD,
1374
+ '--limit', '5', '-M', 'exact', '-m', target,
1375
+ ];
1376
+ // 与邻居的排除口径一致:include_archived 时种子也可以是一篇归档笔记
1377
+ for (const name of excludedNames(cfg, { includeArchived: opts.includeArchived }))
1378
+ args.push('-x', name);
1379
+ const notes = parseLeanList(await zk(cfg, args, { signal }), cfg).notes;
1380
+ const wanted = normalizeTitle(target);
1381
+ const hit = notes.find((n) => n.id && n.id === target)
1382
+ ?? notes.find((n) => normalizeTitle(n.title) === wanted)
1383
+ ?? notes.find((n) => normalizeTitle(path.basename(n.path, path.extname(n.path))) === wanted);
1384
+ return hit ? { title: hit.title || path.basename(hit.path, path.extname(hit.path)), path: hit.path, absPath: hit.absPath } : null;
1385
+ }
1386
+ /**
1387
+ * R8:从一篇种子出发走一跳(按篇反查,不建全图)。
1388
+ *
1389
+ * 成本:路径种子 = `both` 2 个子进程(backlinksOf + outlinksOf,10k 实测见 docs/bench-baseline.md);
1390
+ * 标题 / id 种子再加一次 `-M exact` 解析(共 3 个)。`limit` 硬钳 `MAX_LINK_NOTES` = 200,
1391
+ * 不用 `MAX_SCAN` —— 后者配合 `--format json` 会吐 17 MB,等于把全图成本放回来。
1392
+ * 默认排除 archive / raw / meta(与 `excludedNames` 同口径):邻居与**种子**两侧都过滤,
1393
+ * 不能只过滤一侧(plan §14.5)。
1394
+ *
1395
+ * 每条邻居多带 `section` / `linkLine`(那条边所在的小节与那一行):
1396
+ * 入链用邻居 JSON 里已经在传输的 `rawContent`,出链读一次种子文件 —— 两边都是 **0 个额外子进程**。
1397
+ * 没有这两个字段,`lead` 对同一篇种子的所有出链是同一段文字,等于只给了 8 个标题(plan §14.1)。
1398
+ */
1399
+ export async function walkFrom(cfg, opts, signal) {
1400
+ const direction = opts.direction ?? 'both';
1401
+ const limit = Math.min(MAX_LINK_NOTES, Math.max(1, Math.trunc(opts.limit ?? 10)));
1402
+ const seed = await resolveWalkSeed(cfg, opts.seed, { includeArchived: opts.includeArchived }, signal);
1403
+ if (!seed)
1404
+ return { seed: null, notes: [], truncated: false, completeness: 'complete' };
1405
+ const directions = direction === 'both' ? ['in', 'out'] : [direction];
1406
+ const notes = [];
1407
+ const seen = new Set();
1408
+ let truncated = false;
1409
+ // 出链的「那一行」写在种子里;入链的写在邻居里(JSON 里已经带了 rawContent)
1410
+ let seedContent = '';
1411
+ if (direction !== 'in') {
1412
+ try {
1413
+ seedContent = fs.readFileSync(seed.absPath, 'utf8');
1414
+ }
1415
+ catch {
1416
+ seedContent = '';
1417
+ }
1418
+ }
1419
+ for (const relation of directions) {
1420
+ const found = relation === 'in'
1421
+ ? await backlinksOf(cfg, seed.path, { limit, includeArchived: opts.includeArchived, keepContent: true }, signal)
1422
+ : await outlinksOf(cfg, seed.path, { limit, includeArchived: opts.includeArchived }, signal);
1423
+ if (found.truncated)
1424
+ truncated = true;
1425
+ for (const note of found.notes) {
1426
+ // 按身份键去重:互链的笔记两个方向都会出现,只报一次(先 in 后 out)
1427
+ const key = noteKey(note);
1428
+ if (seen.has(key))
1429
+ continue;
1430
+ seen.add(key);
1431
+ const ctx = relation === 'out'
1432
+ ? linkContextOf(seedContent, note, seed.path)
1433
+ : linkContextOf(found.contents?.get(note.path) ?? '', seed, note.path);
1434
+ notes.push({
1435
+ title: note.title, path: note.path, absPath: note.absPath, relation, lead: note.lead,
1436
+ ...(ctx ? { section: ctx.section, linkLine: ctx.line } : {}),
1437
+ });
1438
+ }
1439
+ }
1440
+ return { seed, notes, truncated, completeness: truncated ? 'partial' : 'complete' };
1441
+ }
1300
1442
  /**
1301
1443
  * `zk-kit query` 会被**丢掉**的参数:它们要么绕开「统一排除」,要么弄坏 JSON 解析。
1302
1444
  * 长名与短名都列出来(`--exclude` / `-x` 是同一个东西的两个写法)。
@@ -12,12 +12,14 @@
12
12
  - `lib/memory-format.ts`:条目的唯一切分口径 —— `splitMemoryEntries` / `isRetiredEntry` / `entryDate` /
13
13
  `stripRetiredEntries` / `daysSinceDate` / `memoryFormatDebt`(日期与来源缺口的机械计数);
14
14
  memory、dream、lint 共用,禁止各写一套
15
+ - `lib/entry-points.ts`:MEMORY 当检索入口(R9)—— `liveMemoryEntries` / `entryPointsOf`(`via: query` 的来源可以不在结果集里),
16
+ 把「命中笔记 ← 已在 MEMORY 的哪条结论」接出来;索引只用本次结果笔记建、路径式来源直接读盘,零子进程(见下)
15
17
  - `lib/dream.ts`:`lastDreamDate` / `daysSinceDream`(只认整齐的一行,按本地日历天算);`dreamNotebook` 用它算默认窗口
16
18
  - `lib/wikilink.ts`:`[[链接]]` 的解析口径(路径 → `.md` → `archive/` → 活笔记标题),lint 与 dream 共用一份
17
19
  - `lib/persona-template.ts`:`PERSONA_TEMPLATE` 与独立版本标记(`<!-- zdiary-persona: vN -->`,
18
20
  不复用 `zdiary-template` —— AGENTS 改版不该让人格文件误报旧版);只走 opt-in 写入,已存在不覆盖
19
- - `lib/agents-template.ts`:`AGENTS.md` 模板两份 —— layered 用完整版(当前 180 词),flat 用精简版
20
- (80 词,不出现 `raw` / `inbox` / `archive` / `WORKFLOW.md`);两份首行都是 `<!-- zdiary-template: vN -->`。
21
+ - `lib/agents-template.ts`:`AGENTS.md` 模板两份 —— layered 用完整版(当前 190 词),flat 用精简版
22
+ (88 词,不出现 `raw` / `inbox` / `archive` / `WORKFLOW.md`);两份首行都是 `<!-- zdiary-template: vN -->`。
21
23
  layered 初始化自动写,flat 只有 `ensureNotebook(cfg, signal, { withAgents: true })` / `zk-kit init --with-agents` /
22
24
  设置页「写入 AGENTS.md 模板」才写;已存在一律不覆盖。
23
25
  `WORKFLOW.md` 模板(改已有笔记的清单确认 + 三分类;不注入、不计预算,AGENTS 只留一行指针)
@@ -67,6 +69,20 @@
67
69
  P1-3 再加三项,都只报告:`undated`(条目首行没有 `YYYY-MM-DD`,退役行不计)、`retired`(`- [superseded …]` 条目数)、
68
70
  `retiredBroken`(退役行的 `→ [[新结论]]` 解析不到活笔记)。0.9 起注入会省略退役条目(notice 说明省略了几条),
69
71
  但文件不删、不改 —— 「注入 = 文件原文」收窄为「注入 = 原文去掉退役条目」(D3)。
72
+
73
+ **MEMORY 不只当注入载荷(R9,§10.4 第 9 项 / §14.2)。** 宿主支持注入时 MEMORY 正文每轮都在系统提示里,
74
+ 缺的不是「可见」,是「可导航」。
75
+ `zk_search` / `zk_query` / `zk_recall` 因此多一个可选 `entryPoints`,两种来源分开标 `via`:
76
+ - `via: 'result'`:条目指向**本次命中**的笔记 → 那条结论首行 + 路径(3.9.0 原语义,是注解);
77
+ - `via: 'query'`:**条目本身命中检索词** → 来源不必在结果集里。这是索引该有的方向:关键词 → 卡号,
78
+ 而那张卡可以不含这个词。路径式 `[[notes/x]]` 直接读盘落地(`resolved: true`,0 子进程);
79
+ 标题 / id 式且不在本批结果里时 `resolved: false`,只给入口名,渲染成「用 `zk_walk` 走进去」——
80
+ 不为补一次路径再起一个 zk 进程。
81
+ 口径集中在 `lib/entry-points.ts`:条目切分 / 退役判断复用 `splitMemoryEntries` / `isRetiredEntry`,
82
+ `[[链接]]` 解析复用 `WIKI_LINK` / `resolveWikiTarget`(与 lint / dream 同一份);退役行不计、显式 `archive/` 链接
83
+ 不算活入口(旧结论归死胡同探针)。索引只用本次结果笔记建,所以**不扫库**;没有 MEMORY.md 或解析失败时整个键不出现,
84
+ 老库输出与改动前一致。查询比对是机械的(空格分词 + CJK 二元组),最多 5 条,只做字符串比较 ——
85
+ 「哪条更相关」仍是 agent 的活。
70
86
  为什么要有:`zk_supersede` 只重写 `zk graph` 里的入链,meta 文件被 `excludedNames` 排除在图外 ——
71
87
  链接不会跟着搬,`--broken-links` 也看不见。语义重复仍留给 agent,插件不碰。
72
88
  稳定 ID 让来源链接可以选择不绑路径:写成 `[[<id>]]`(从笔记 frontmatter 读)时,改名后仍落到同一篇;
@@ -97,7 +113,8 @@ P1-3 的日期 / 退役格式 + P2-15 的版本标记后为 189 词;P2-8 去
97
113
  v4 去掉「宿主不会自动加载本文件」一句后为 175 词(单测锁 `≤190`;flat 精简版锁 `≤90`,v4 起实测 76);
98
114
  v5 在 MEMORY 条目约定后补「先 zk_read 核对来源」后为 180 词(flat 80);v7 精简模板后仍为 180 词(flat 80);
99
115
  v8 把 `zk_read` 改成原生 `read` 后仍为 180 词(flat 80);
100
- v9 两份模板各补一句「改 MEMORY 前看 zk_context 余量」、WORKFLOW.md 补做法后为 188 词(flat 86)。
116
+ v9 两份模板各补一句「改 MEMORY 前看 zk_context 余量」、WORKFLOW.md 补做法后为 188 词(flat 86);
117
+ v10 两份模板把 `zk_walk 一跳` 并进查重那一步后为 190 词(flat 88,各 +2 词,不提高预算)。
101
118
  `AGENTS.md` 是硬规则,单独超预算也不截断,只回显告警;文件内容里的 `</system-reminder>` 会被转义,
102
119
  截断目录里的段落标题同样转义 —— 不许提前闭合插件自己的框;任何一份文件读不到都当作不存在,笔记本没建好时返回空载荷而不是报错。
103
120
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Purpose.** 让模型用 zk 思维工作:先查重、再写原子笔记、用双链连起来、每天记一段。
4
4
 
5
- **Owns.** 14 个内置工具定义(`zk_search` / `zk_query` / `zk_recall` / `zk_new` / `zk_append` / `zk_daily` / `zk_link` /
5
+ **Owns.** 15 个内置工具定义(`zk_search` / `zk_query` / `zk_recall` / `zk_walk` / `zk_new` / `zk_append` / `zk_daily` / `zk_link` /
6
6
  `zk_supersede` / `zk_rename` / `zk_context` / `zk_lint` / `zk_dream` / `zk_stats` / `zk_use`)以及笔记本
7
7
  `.zk/config.toml` 的 `[alias]` 派生的 `zk_<别名>` 工具:
8
8
  参数 schema、输出 schema、render、每个工具自己的 `ensureNotebook` 与参数校验。
@@ -36,7 +36,7 @@ LEAN 模板加一列 `{{metadata.id}}`,`parseLeanList` 的定长字段从 11
36
36
  相似标题继续只作 warning,不升级为去重方案。
37
37
 
38
38
  **Alias tools(`zk_<别名>`).** 默认**不注册**:`aliasTools` 为 false 时 `buildTools` 连 `.zk/config.toml` 都不读,
39
- 内置工具固定 14 个。别名是 `$SHELL -c` 的任意命令,注册成工具等于把它交到模型手里,所以要人显式打开
39
+ 内置工具固定 15 个。别名是 `$SHELL -c` 的任意命令,注册成工具等于把它交到模型手里,所以要人显式打开
40
40
  (设置页「工具」组的复选框,或 `zk-kit config set aliasTools=true`,只认 `true`;拼错的值归一化成 false 并在 `config set` 时回显)。
41
41
  打开后,插件加载时读所有已配置笔记本的 `.zk/config.toml`,把 `[alias]` 表里未注释的键注册成工具;
42
42
  同名只取第一本。工具名用下划线而不是点号:DSH 的 function-name 契约是 `[A-Za-z0-9_-]`(`zk.lucky` 会被 provider 拒绝)。
@@ -300,7 +300,67 @@ v2 去掉了 `inbox/`(P2-8),老库会在下次 `zk_lint` 看到「旧版
300
300
  - 分组轮转:按 `type` → 首个标签 → 「未分类」分组,各组轮流取一条,组内保持检索顺序;预算不会被排在最前的那一类全吃掉。
301
301
  - 每条取 `title` / `path` / `absPath` / `words` 与 `snippet`(比 `lead` 多信息时用它),`budget` / `used` 走 `countWords` 口径(中文 2 字 1 词)。放不下就**整条丢弃、不切半句**,`notes[].reason` 明写 `included` / `duplicate` / `empty` / `over-budget`;`used` 是对最终整段文本算的(分隔符也计入),所以一定 `<= budget`。
302
302
  - 0 命中返回空 `text` / 空 `notes` / `used = 0`,不编造;`completeness` / `hasMore` 沿用检索三态 —— 装配过的只是本次候选,不代表库里没有别的。需要全文仍由宿主原生 `read` 按 `absPath` 取。
303
- - 命令行 `zk-kit recall [词] [--budget 500] [--limit 30] [--json]`,与工具走同一份 `assembleRecall`。
303
+ - 命令行 `zk-kit recall [词] [--budget 500] [--limit 30] [--json]`,与工具走同一份 `assembleRecall`;
304
+ 入口块的落位也同口径(见下)。
305
+ - 入口块(`via=query`)排在装配正文之前、占同一份预算。它进没进 `text` 是**结构化状态** `entryPointsInText`,
306
+ render 读这个字段(`lib/entry-points.ts` 的 `entryPointLines` 与 `zk-kit search` / `zk-kit recall` 共用一份措辞):
307
+ `false` 时在正文外补列 —— 不从 `text` 里嗅字符串,笔记正文里也可能出现同样的字。
308
+ 命中却全被预算挡下时,CLI 明说「放不进 N 词预算」,不再打印「没有匹配的笔记」。
309
+
310
+ **一跳入口(R8,§10.4 第 8 项).** 新增只读 `zk_walk`(`lib/zk.ts` 的 `walkFrom`):从一篇种子出发走一跳,补上「沿链接走」的入口。
311
+ - **种子解析**:路径(相对 / 绝对 / `[[路径]]`)只看磁盘,**0 个子进程**;标题 / `[[标题]]` / `[[id]]` 走一次
312
+ `zk list -M exact --limit 5`,再在 JS 里按 id / 标题 / 文件名精确比对 —— `-M exact` 是「逐词精确」而不是整串相等
313
+ (实测 `记忆预算` 会同时命中 `记忆预算的另一篇`),所以对不上就当没找到,**不拿第一个命中冒充种子,也不退回全库**。
314
+ - **走法**:`backlinksOf` / `outlinksOf`(各一次 `zk list --link-to` / `--linked-by`),默认 `both` = 2 个子进程;
315
+ 标题 / id 种子再加一次解析(3 个)。互链的邻居按身份键去重,`in` 先 `out` 后。**不建全图、不递归、不 depth 2**。
316
+ - **边界**:`limit` 硬钳 `MAX_LINK_NOTES` = 200(不是 `MAX_SCAN` 10 000:后者配 `--format json` 会吐 17 MB,等于把全图成本放回来);
317
+ 默认排除 archive / raw / meta(`excludedNames` 同口径),`include_archived: true` 才连归档一起看;
318
+ `complete / partial` 二态(按篇反查没有产生 `unknown` 的路径,**不谎称三态**),触顶明说「邻居没列全,不代表没有」。
319
+ 每条邻居还带 `section` / `linkLine`(§14.1,`lib/edge-context.ts` 的 `linkContextOf`):那条边所在的 `##` / `###` 小节与**那一行**。
320
+ 没有它,`lead` 对同一篇种子的所有出链是同一段文字(邻居首段),等于只给了 8 个标题 ——
321
+ 而 Sammelverweise 的价值在于「关于 X 见这几处」。字节是白捡的:入链用邻居 JSON 里已经在传输的 `rawContent`,
322
+ 出链读一次种子文件,**0 个额外子进程**;只认 wiki 双链与 Markdown 行内链接,代码块里的 `[[…]]` 不算,
323
+ 找不到就整个键不出现(不拿「提到了标题」冒充链接)。
324
+ 只回标题 / 路径 / `absPath` / 摘要 / 那一行,全文仍由宿主原生 `read` 取;不改标题、不自动 link、不写任何文件。
325
+ - 命令行 `zk-kit walk <种子> [--direction both|in|out] [--limit 10] [--json]`,与工具共用 `walkFrom`。
326
+ - 成本(`docs/bench-baseline.md` 的三档实测):路径种子 `both` 恒 2 子进程,10k 上 p95 1.3 / 1.1 / 1.8 s,
327
+ 传输 7.2 / 15.1 / 32.3 KB(0.2 / 1 / 3 链每篇);全图同库 26–31 s / 17 MB。
328
+
329
+ **MEMORY 当检索入口(R9,§10.4 第 9 项 / §14.2).** `zk_search` / `zk_query` / `zk_recall` 的结果多一个可选 `entryPoints`。
330
+ 两条来源,`via` 分开写:
331
+ - `via: 'result'` —— 条目指向**本次命中**的笔记:把「这条已晋升结论」贴回结果(3.9.0 原语义);
332
+ - `via: 'query'` —— **条目本身命中检索词**:来源不必在结果集里。这才是索引的方向(关键词 → 卡号 → 那张卡
333
+ 可以不含这个词)。原来用 `byPath` 卡死,只做成了注解。
334
+ - 落地(`resolved`):路径式 `[[notes/x]]` 直接读盘、**0 子进程**;标题 / id 式且不在结果集里时
335
+ `resolved: false`,只给入口名(`title` 就是 `[[…]]` 里那一串,`path` / `absPath` 是空串 —— 不编),
336
+ 渲染成「用 zk_walk 走进去」。不为了补一次路径再起一个 zk 进程(10k 上 `zk list -M re` 实测 0.7–1.0 s)。
337
+ - 口径在 `lib/entry-points.ts`:条目切分 / 退役判断复用 `splitMemoryEntries` / `isRetiredEntry`,
338
+ 链接解析复用 `WIKI_LINK` / `resolveWikiTarget`;退役行不计(D3),归档目标归死胡同探针、不当活入口,
339
+ `raw/` / `inbox/` / 根目录 meta 一律不算入口。
340
+ - 查询比对是**机械的**:ASCII 按空格分词、CJK 长串补二元组,`entry` 文本包含任一比对项即命中;
341
+ 不排序(按 MEMORY 文件顺序)、不做语义判断(「哪条更相关」仍是 agent 的活);最多 5 条(`MAX_ENTRY_POINTS`),
342
+ 超出置 `entryPointsTruncated`。
343
+ - 解析失败或没有 MEMORY.md 时整个键不出现(老库输出与改动前一致),不谎称完整。
344
+
345
+ **死胡同可见(§14.3).** `lib/archive-probe.ts`:检索命中一篇活笔记时,顺手看 `archive/` 里有没有**同名旧结论**,
346
+ 带出 `supersede-reason` 与 `superseded-by`,放进 `counterEntries`(最多 3 条)。
347
+ - 为什么:`zk_supersede` 搬进归档的旧结论被 `excludedNames` 排除出检索,只有 `zk_new` 写同名时才提示一次 ——
348
+ 于是 agent 在读 / 想的阶段看不到「这条路试过、为什么废」,只能重新踩一遍。这不是「不查全」的谦逊,
349
+ 是主动隐藏反例。
350
+ - 成本:**零子进程、零 zk 调用**。只读 `archive/` 下的文件(10k 夹具 800 篇 → 10 条命中比对 p50 50 ms),
351
+ 标题相似度复用 `lib/similar.ts` 的同一份口径;扫描上限 `MAX_ARCHIVE_SCAN` = 2000,触顶置 `counterEntriesTruncated`
352
+ (没看全 ≠ 没有);对照项最多 `MAX_COUNTER_PROBES` = 50 条命中。
353
+ - 0 命中且给了 query 时改拿查询词当标题比 —— 「库里没有」不等于「从来没出现过」;渲染文案不再是「没有匹配」,
354
+ 而是「没有活笔记命中,但归档里有同名旧结论」。
355
+ - 只提示:不改默认结果集、不改 `completeness` 口径、不判断「是不是同一个错误」;`include_archived: true` 时
356
+ 归档已经在结果里,不再重复报。
357
+
358
+ **本地聚合计数(§14.4).** `lib/usage.ts` 在 `.zk/dsh-usage.json` 记「哪个工具被调了几次」
359
+ (`search` / `query` / `recall` / `walk` / `entryPoints` / `counterEntries`)+首次计数时间,`zk_stats.usage` 读出来。
360
+ - 只存键与数字:不记查询词、不记路径、不上报。写入失败 / 文件损坏一律静默降级,不影响工具调用。
361
+ - 目的:到 3.9.0 为止入口 / 一跳的验收全是机械口径(子进程数、字节、schema、与 `graph` 对账),
362
+ 没有一条问「这条路有没有被真的用上」。`zk_stats` 的 `usage` 是唯一可观测的代理 ——
363
+ 发布后过一段时间看 `walk` / `entryPoints` / `counterEntries` 有没有涨。
304
364
 
305
365
  **写 MEMORY 前的容量(G1 / G4,§10.4 第 6 项).** 复用 `zk_context`,不新增 `zk_memory_check`:
306
366
  入参加 `proposed_entry` / `extra_words`,输出增量 `headroom` / `extraWords` / `wouldTruncate` /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-zdiary-kit",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "内置 zk 的 DSH 知识库 / 日记插件:装好即用 —— 自动装 zk、建笔记本,给 agent 一组 zk_* 工具(搜索、读写、日记、双链),设置页里管路径、索引与自检。",
5
5
  "icon": "./icon.svg",
6
6
  "repository": {