dsh-zdiary-kit 3.0.1 → 3.1.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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # dsh-zdiary-kit 3.0.1
1
+ # dsh-zdiary-kit 3.1.0
2
2
 
3
3
  > 给 [DSH](https://github.com/deepseek-ai/deepseek-harness) 装一个**内置 [zk](https://github.com/zk-org/zk) 的知识库 / 日记本**:
4
4
  > 插件提供一键安装 zk(官方 release;设置页按钮或 `zk-kit install`)、自动建笔记本(zk init + 日记模板 + 日记 group),
5
- > 然后给 agent 一组 `zk_*` 工具 —— 查、读、写、记日记、连双链,全部走 zk 自己的索引。
5
+ > 然后给 agent 一组 `zk_*` 工具 —— 查、写、记日记、连双链,全部走 zk 自己的索引。
6
6
  >
7
7
  > 装好 zk 后不用先配环境:agent 第一次调用工具时就把笔记本建好;设置页里再调路径、重建索引、跑自检。
8
8
 
@@ -10,17 +10,16 @@
10
10
 
11
11
  | 工具 | 干什么 |
12
12
  |---|---|
13
- | `zk_search` | 全文 / 标签 / 日期 / 断链 / 孤立笔记检索,返回标题、路径、标签、摘要;中文查询自动并用子串匹配(`matchStrategy` 说明用了 `fts` / `regex` / `mixed`,补上全文索引漏掉的笔记) |
13
+ | `zk_search` | 全文 / 标签 / 日期 / 断链 / 孤立笔记检索,返回标题、相对路径、绝对路径、标签、摘要;中文查询自动并用子串匹配(`matchStrategy` 说明用了 `fts` / `regex` / `mixed`,补上全文索引漏掉的笔记) |
14
14
  | `zk_query` | 结构化检索:按 type / status / 标签 / 目录 / 日期过滤,默认只看 active 且不含归档;`include_archived` 连归档一起查(此时未显式给 status 则不再默认过滤 active) |
15
- | `zk_read` | 读一篇全文(按路径,或先按词找最相关的一篇);超长会截断并标注 |
16
- | `zk_new` | 新建原子笔记(zk 生成文件名、套模板、写索引),可带摘要、标签与双链;`summary` 填进模板的 `## Summary`(正文里已写了这一节就不动,返回 `summaryApplied: false`);`name` 可直接指定短文件名(不给则按标题生成,中文标题得到拼音长名);layered 下不给 `dir` 就按 `type` 落位(source → notes/sources),两者都没有、或给的 `dir` 不在任何 group 里都直接报错;`tags` 只补正文里没有的;flat 下按标题查重,重复直接报错;归档里有同名旧结论只警告并带出废弃原因;type / authority 只有 layered 模板会写进 frontmatter;`raw/`、`inbox/` 与根目录 meta 文件一律拒写(写进去会被排除出索引 / 被当成人写的工作面);中文笔记没有任何标签时在 `tagWarning` 里提示(只提示,不阻断) |
15
+ | `zk_new` | 新建原子笔记(zk 生成文件名、套模板、写索引),可带摘要、标签与双链;`summary` 填进模板的 `## Summary`(正文里已写了这一节就不动,返回 `summaryApplied: false`);`name` 可直接指定短文件名(不给则按标题生成,中文标题得到拼音长名);layered 下不给 `dir` 就按 `type` 落位(source → notes/sources),两者都没有、或给的 `dir` 不在任何 group 里都直接报错;`tags` 只补正文里没有的;flat 下按标题查重,重复直接报错;归档里有同名旧结论只警告并带出废弃原因;type / authority 只有 layered 模板会写进 frontmatter;`raw/`、`inbox/`、`archive/` 与根目录 meta 文件一律拒写(写进去会被排除出索引 / 被当成人写的工作面;归档只放 `zk_supersede` 搬进去的旧结论);中文笔记没有任何标签时在 `tagWarning` 里提示(只提示,不阻断) |
17
16
  | `zk_append` | 往已有笔记末尾续写(自动补空行,可先起二级标题);根目录 meta 文件拒写 |
18
17
  | `zk_daily` | 打开/创建某天的日记,并追加一条带时间的记录(layered 模板写进 `## Events` 的 `### HH:MM`,flat 追加到文件末尾的 `## HH:MM`) |
19
18
  | `zk_link` | 在两篇笔记间加 `[[…]]` 双链(已存在不重复加;目标不存在会给出候选;链接追加到文末,已有 Links/链接 小节则不重复起标题);meta 文件不作为来源或目标 |
20
19
  | `zk_supersede` | 废弃过时结论:标 `superseded` + 写 `reason` + 搬进 `archive/` + 重写能精确匹配的 `[[旧路径]]` 入链(其它写法列进 `missingLinks`);默认只预演;meta 文件不能废弃 |
21
20
  | `zk_rename` | 改名 / 换目录并修断链:入链(`[[…]]` 与 Markdown 链接,保留 `#锚点` 与 `\|别名`)按实际解析结果改到新路径,根目录 meta 里的 `[[来源]]` 一起改,被搬走那篇自己的相对 Markdown 链接按新位置重算;默认只预演 |
22
21
  | `zk_context` | 读知识库根目录的 `AGENTS.md` / `USER.md` / `MEMORY.md`(按注入预算截断)与角色契约 `PERSONA.md`(单独成段、不截断),并列出已配置的笔记本(名字 / 路径 / 结构 / 当前);宿主支持注入时这些内容每轮已自动带进系统提示 |
23
- | `zk_lint` | 体检:解析失败 / 断链 / 孤儿 / 无标签 / 单向链接 / 陈旧 / 重名标题 / 疑似重复标题 / 记忆链接失效 / frontmatter 缺字段 / 标签卫生 / 模板版本 / 契约(缺失·旧版·比插件新·标记与内容不符·未填占位符),每类最多 50 条;非日记笔记到 150 篇且没有 `INDEX.md` 时提示一句;只报告不改写 |
22
+ | `zk_lint` | 体检:解析失败 / 断链 / 孤儿 / 无标签 / 单向链接 / 陈旧 / 重名标题 / 疑似重复标题 / 记忆链接失效 / frontmatter 缺字段 / 标签卫生 / 模板版本 / 契约(缺失·旧版·比插件新·标记与内容不符·未填占位符)/ 日记时间轴(最近 90 天的空块·倒序·格式·位置),每类最多 50 条;非日记笔记到 150 篇且没有 `INDEX.md` 时提示一句;只报告不改写 |
24
23
  | `zk_dream` | 晋升材料:窗口新增(机械筛掉 `informal` 与无标签,带正文摘要与入链来源)、已在 MEMORY 的、窗口外积压、daily 未完成项、被引最多(先按「被日记提到几天」排);只报告 |
25
24
  | `zk_stats` | 笔记数 / 标签数 / 断链 / 孤立 / 归档(superseded),以及顶层目录与前 10 个标签的实时分布 |
26
25
  | `zk_use` | 切换**本会话**用的笔记本(只影响这个会话,不改全局默认);不带参数就列出现有的与当前固定的 |
@@ -34,6 +33,8 @@
34
33
  **默认不注册**(`aliasTools` 默认 false,关着时不读 config.toml):在设置页「工具」组勾选,或 `zk-kit config set aliasTools=true`,再重载插件;
35
34
  值只认 `true`(拼错的值会被归一化成 false 并在 `config set` 时回显)。
36
35
 
36
+ 读全文不再包一层工具:`zk_search` / `zk_query` 的每条笔记、`zk_new` / `zk_daily` 的返回都带 `absPath`,直接传给 DSH 原生 `read` 即可;相对笔记本的 `path` 仍然保留,给双链和 `zk_*` 参数用。前提是宿主挂载了 DSH 的 fs 工具(默认 web profile 有);精简 / headless 宿主没挂 `read` 时,读笔记要另配文件工具。
37
+
37
38
  写笔记前 agent 会先 `zk_search` 查重;flat 笔记本的 `zk_new` 还会按标题再查一次,重复直接报错。
38
39
  layered 笔记本的文件名是标题的 slug:英文标题自然得到英文文件名,短不短看标题本身;中文标题会变成很长的拼音名,要短名就在 `zk_new` 时传 `name`;老笔记不自动改名,**手工 `mv` 会断入链**,要改名用 `zk_rename`(默认预演,会重写引用)。
39
40
  layered 下每篇笔记都要落在 group 里:`zk_new` 不给 `dir` 就按 `type` 选目录(source → notes/sources),没给 `type` 会直接报错;显式给的 `dir` 也要在某个 group 下(`notes/sources` 及其子目录,写 `notes/concept` 这种错字一样拦)—— `notes/` 根不属于任何 group,建在那里的笔记不套模板(没有 frontmatter,文件名是随机 id),所以这条路径一律不放过。
@@ -44,13 +45,13 @@ layered 下每篇笔记都要落在 group 里:`zk_new` 不给 `dir` 就按 `ty
44
45
  记忆注入也跟着这个会话固定的那本走。要跟着换,就在**那个会话里**说「切到 X 库」(agent 调 `zk_use`)。
45
46
  每轮系统提示里还会带一行当前笔记本(名字 / 路径 / 结构)和其余已配置库 —— 模型不用先调工具就知道自己在哪本、还能切到哪本。
46
47
  设置页保存时带文件指纹,别处刚改过配置会 409 并要求确认,不会拿旧表单把别人的 `active` 覆盖回去。
47
- 路径找不到时,`zk_read` / `zk_append` 还会顺手查别的笔记本里有没有同名笔记,并告诉你它在哪一本。
48
+ 路径找不到时,`zk_append` 还会顺手查别的笔记本里有没有同名笔记,并告诉你它在哪一本。
48
49
 
49
50
  **长期记忆**:笔记本根目录放 `AGENTS.md`(工作约定)、`USER.md`(偏好)、`MEMORY.md`(精炼记忆),
50
51
  插件会在每个 step 把它们注入系统提示(预算默认 500 词,设置页「记忆 → 注入预算」可改;
51
52
  超了先丢 MEMORY 里**日期最旧**的一条(都没写日期才退回从尾部往前丢),
52
53
  按 `##` 小节 → 顶层列表项 → 空行段落 三级降级切分(`# 记忆` + 要点列表这种最常见的写法也算数),
53
- 丢掉的条目 / 段落留一份目录(标题)—— 需要时用 `zk_read MEMORY.md` 取回;
54
+ 丢掉的条目 / 段落留一份目录(标题)—— 需要时用原生 `read` 读 `<笔记本>/MEMORY.md` 取回;
54
55
  同日期按文件里靠后的先丢,所以带日期的条目不会因为写在底部就先被删;
55
56
  同时明确告诉你截了多少、谁已经没法再丢)。用到预算 80% 以上时还会回显一行「记忆已用 246/300 词(82%)」
56
57
  (数字已含这行提示本身)—— 先合并或退役旧条目,别等第一次截断。
@@ -139,7 +140,7 @@ dsh plugin --profile web add "link:/path/to/dsh-zdiary-kit"
139
140
  | 目录与 group | 归档目录 | `supersede` 后搬到这里(保留原相对路径),默认 `archive` |
140
141
  | 记忆 | 注入预算(词) | AGENTS + USER + MEMORY 的合计上限,默认 500(中文按 2 字 1 词) |
141
142
  | 记忆 | 契约预算 | 契约 240(不截断、超了告警) |
142
- | 写入 | 默认标签 / zk_read 上限 | 新笔记自动带标签;单次读取字符上限 |
143
+ | 写入 | 默认标签 / 单次读取上限 | 新笔记自动带标签;`zk-kit read` 与别名工具的输出上限 |
143
144
  | 工具 | 把 `[alias]` 注册成工具 | 复选框,默认关。打开后 `.zk/config.toml` 的 `[alias]` 变成 `zk_<名>` 工具;**加载时才注册**,勾完保存要重载插件 |
144
145
  | zk | zk 路径 / 内置版本 | 路径空 = 自动找;版本默认 0.15.7 |
145
146
 
@@ -399,11 +400,11 @@ zk-kit doctor # 自检:zk / 笔记本 / 模板 / group
399
400
  | 体检报「frontmatter 缺字段」(layered) | 缺 `type` / `status` / `authority`:索引把缺失落成空串,`authority=informal` 这类机械门对它们静默失效。按模板补上即可;flat 不查这一项 |
400
401
  | `doctor` 提示「记忆在跑,但缺 AGENTS.md」 | `flat` 默认不写工作约定:跑 `zk-kit init --with-agents`,或设置页点「写入 AGENTS.md 模板」(已存在不覆盖) |
401
402
  | 提示「盘上有分层目录,但配置是 flat」 | 以前是 layered、后来改成 flat(或手工搬过目录):新建笔记会落在 `notes/` 根、不套模板。要么把配置改回 layered,要么把这些目录移走;插件只提示,不动文件 |
402
- | `Read` / `Edit` 笔记本报 `file access denied under workspace-write mode` | 笔记本被指到了工作区外。改用 `zk_*` 工具(不经这层策略),或把目录加进 `additionalWritableRoots`,或开会话到 `danger-full-access` |
403
+ | `read` / `edit` 笔记本报 `file access denied under workspace-write mode` | 笔记本被指到了工作区外。读也只能走原生 `read`(`zk_read` 已移除):把笔记本放回工作区(默认 `<工作区>/zdiary` 就是为此选的),或把目录加进 `additionalWritableRoots`,或开会话到 `danger-full-access` |
403
404
  | 设置页出现「结构是 layered,但缺目录」 | 配置与磁盘不一致(换过机器 / 手动删过目录):点「补建 *名* 的目录」,别手改配置去将就磁盘 |
404
405
  | 切了笔记本,笔记数对不上 | 每个笔记本各自一份 `.zk/` 索引与笔记:切换是换库,不是合并;`zk-kit notebooks` 看当前是哪个 |
405
- | 新建时提示「归档里有同名旧结论」 | 允许复用标题,但先 `zk_read` 归档那篇,确认不是同一个错误;插件只警告、不拦 |
406
- | 往 `raw/` 或 `inbox/` 写笔记报「只读」 | 两者都被排除出索引,写进去的笔记不会报错、只是永远搜不到;所以 `zk_new` / `zk_append` / `zk_link` / `zk_supersede` / `zk_rename` 直接拒绝 | 结论写到 `notes/`;原文留在原位,用 `zk_read raw/xxx.md` 或直接读文件对照。`inbox/` 是停用入口,老目录只读保留 |
406
+ | 新建时提示「归档里有同名旧结论」 | 允许复用标题,但先 `read` 归档那篇,确认不是同一个错误;插件只警告、不拦 |
407
+ | 往 `raw/` 或 `inbox/` 写笔记报「只读」 | 两者都被排除出索引,写进去的笔记不会报错、只是永远搜不到;所以 `zk_new` / `zk_append` / `zk_link` / `zk_supersede` / `zk_rename` 直接拒绝。结论写到 `notes/`;原文留在原位,用原生 `read` 读 `raw/xxx.md` 或直接读文件对照。`inbox/` 是停用入口,老目录只读保留 |
407
408
  | `config set notebook=…` 报「派生值」 | `notebook` 是 `notebooks[active]` 解析后的派生值、不落盘也不可写:改路径用 `zk-kit notebooks add 名 路径`,切换用 `use` |
408
409
 
409
410
  ## 开发
@@ -412,7 +413,7 @@ zk-kit doctor # 自检:zk / 笔记本 / 模板 / group
412
413
  浏览器半边 `client.ts` 零 import,`postbuild` 把 tsc 补的 `export {}` 删掉,并检查没有顶层声明
413
414
  (DSH 会把多个插件的 `client.js` 拼进同一个 combo 脚本,顶层 `const` / `function` 会撞名导致插件不激活)。
414
415
  - `bun run typecheck` · `bun run build` · `bun run test`(真起 zk)·
415
- `bun run smoke`(加载 dist:14 个内置工具各跑一遍 + 7 条设置路由都发真实请求(`/install` 只验非法版本,不下载),并检查输出 schema 在 DSH 支持的子集内)·
416
+ `bun run smoke`(加载 dist:13 个内置工具各跑一遍 + 12 条路由(设置 8 + 只读 4)都发真实请求(`/install` 只验非法版本,不下载),并检查输出 schema 在 DSH 支持的子集内)·
416
417
  `bun run docs`(把 README / docs 里 `zk-kit …` 代码块在临时 vault 上逐条真跑;`smoke` 末尾会带上)
417
418
  - `bun run test` 会先按插件自己的顺序找 zk(配置 → `ZK_BIN` → PATH → `~/.dsh/zdiary/bin`),跑完要求 **skip = 0**:
418
419
  集成测试跳过一律按失败处理,否则「全绿」可能是「什么都没跑」。要换 zk 就 `ZK_BIN=/path/to/zk bun run check`。
@@ -441,7 +442,7 @@ src/
441
442
  │ ├── dsh.ts # 宿主契约(纯类型,编译后为空)
442
443
  │ └── exec.ts / http.ts / json-file.ts
443
444
  ├── features/
444
- │ ├── zk-tools/feature.ts # 14 个内置工具 + [alias] 别名工具
445
+ │ ├── zk-tools/feature.ts # 13 个内置工具 + [alias] 别名工具
445
446
  │ ├── settings/ # 宿主 API + 浏览器 section
446
447
  │ └── readonly/ # 只读视图:GET-only 路由 + Web 1.0 渲染(无 JS)
447
448
  └── cli.ts # zk-kit 命令行
package/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import { NOTE_KINDS, ensureNotebook, fixGroupConfig, groupOverlapNotes, newNoteD
10
10
  import { buildMemoryPayload, formatFileShares } from './lib/memory.js';
11
11
  import { installZk, sourceLabel } from './lib/install.js';
12
12
  import { resolveZk, searchNotesDetailed, queryNotes, createNote, readNote, findNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, notebookStats, indexNotebook, withTags, taglessCjkWarning, hasNotebook, localDate, ZkError, allNotes, parseErrorWarnings, } from './lib/zk.js';
13
- import { formatLintExtras, formatMemoryLinks, lintNotebook, contractStatus } from './lib/lint.js';
13
+ import { formatLintExtras, formatMemoryLinks, lintNotebook, contractStatus, timelineStatus } from './lib/lint.js';
14
14
  import { dreamNotebook, STALE_DAYS } from './lib/dream.js';
15
15
  const HELP = `zk-kit —— dsh-zdiary-kit 的命令行
16
16
 
@@ -356,6 +356,14 @@ async function doctor() {
356
356
  (st.ready ? `${st.dirs.length} 个目录齐全` : `缺 ${st.missing.join('、')}(跑 zk-kit init)`) +
357
357
  (st.agents.required ? (st.agents.present ? ' · AGENTS.md 就绪' : ' · 缺 AGENTS.md(跑 zk-kit init)') : '') +
358
358
  drift);
359
+ if (exists) {
360
+ const timeline = timelineStatus(cfg);
361
+ // 跳过的篇数也点名:不写就等于「这块查过了、没问题」
362
+ const skipped = timeline.skipped > 0 ? `;跳过 ${timeline.skipped} 篇` : '';
363
+ rows.push(timeline.total > 0
364
+ ? `· 时间轴:${timeline.total} 处(${timeline.notes} 篇${skipped};zk_lint 看详情)`
365
+ : `· 时间轴:0 处${skipped}`);
366
+ }
359
367
  const payload = buildMemoryPayload(cfg);
360
368
  const present = payload.files.filter((f) => f.present);
361
369
  rows.push(present.length === 0
@@ -22,6 +22,7 @@ import { RETIRED_ENTRY_RE } from '../../lib/memory-format.js';
22
22
  import { parseFrontmatter } from '../../lib/frontmatter.js';
23
23
  import { stripContractMarker } from '../../lib/persona-template.js';
24
24
  import { esc, layout, renderMarkdown } from './html.js';
25
+ import { timelineIssues, timelineSummary } from '../../lib/timeline.js';
25
26
  const BASE = ROUTE_BASE;
26
27
  const VIEW = `${BASE}/view`;
27
28
  const FEED = `${BASE}/feed.xml`;
@@ -464,10 +465,22 @@ async function handleNote(res, cfg, rel) {
464
465
  ? loaded.doc.content.slice(0, MAX_CONTENT)
465
466
  : loaded.doc.content;
466
467
  const truncated = content.length < loaded.doc.content.length;
468
+ // 时间轴警告(计划 §2 D3):只在日记页出现,正文照原 markdown 渲染(空块保持空 h3)。
469
+ // 不受 zk_lint 的 90 天窗口限制:打开哪篇查哪篇。
470
+ const timeline = isUnderDir(loaded.rel, cfg.dailyDir)
471
+ ? timelineIssues(loaded.doc.content, 'auto')
472
+ : [];
473
+ const timelineNotice = timeline.length === 0 ? '' : [
474
+ `<div class="notice">${esc(timelineSummary(timeline))}`,
475
+ '<details><summary>明细</summary>',
476
+ `<ul>${timeline.map((i) => `<li>行 ${i.line}:${esc(i.title)} — ${esc(i.detail)}</li>`).join('')}</ul>`,
477
+ '</details></div>',
478
+ ].join('\n');
467
479
  const body = [
468
480
  `<p class="crumb"><a href="${VIEW}">首页</a> / ${esc(loaded.doc.type || '笔记')}</p>`,
469
481
  `<h1>${esc(loaded.doc.title || loaded.rel)}</h1>`,
470
482
  `<p class="meta">${esc(localDate(loaded.doc.created) || '—')} · ${loaded.doc.words} 词${loaded.doc.tags.length ? ' · ' + tagLinks(loaded.doc.tags) : ''}</p>`,
483
+ timelineNotice,
471
484
  truncated ? `<p class="notice">正文超过 ${MAX_CONTENT} 字符,这里只显示前 ${MAX_CONTENT} 字符。</p>` : '',
472
485
  `<article>${renderMarkdown(content, { linkFor, skipFirstH1: true })}</article>`,
473
486
  '<h2>反链</h2>',
@@ -45,6 +45,7 @@ const CSS = [
45
45
  'th{font-weight:bold;border-bottom:1px solid #bbb}',
46
46
  '.meta{color:#555;font-size:13px}.meta a{color:#0000cc}',
47
47
  '.notice{border:1px solid #d9a300;background:#fffbe6;padding:8px 10px;margin:12px 0;font-size:14px}',
48
+ '.notice details{margin-top:6px}.notice summary{cursor:pointer}',
48
49
  '.error{border:1px solid #c00;background:#fff2f2;padding:8px 10px;margin:12px 0;font-size:14px}',
49
50
  '.tags a{margin-right:10px;white-space:nowrap}.tags .count{color:#777;font-size:12px}',
50
51
  'form.search{margin:12px 0}form.search input{font:inherit;padding:3px 6px;width:min(100%,360px);border:1px solid #999}',
@@ -65,7 +65,7 @@ window.__ModuleLoader__?.load({
65
65
  { group: '记忆', key: 'memoryBudgetWords', label: '注入预算(词)', hint: 'AGENTS.md + USER.md + MEMORY.md 的合计上限,默认 500(中文按 2 字 1 词)。超了先丢 MEMORY 里日期最旧的条目(一条日期都没有才退回从尾部丢),并回显截断了多少' },
66
66
  { group: '记忆', key: 'contractBudgetWords', label: '契约预算(词)', hint: 'PERSONA.md 的上限,默认 240(50-800)。契约是硬规则,永远注入、不参与截断;超了只告警' },
67
67
  { group: '写入', key: 'defaultTagsText', label: '默认标签', hint: '新笔记自动追加的标签,逗号分隔,不带 #(可空)' },
68
- { group: '写入', key: 'maxReadChars', label: 'zk_read 单次上限(字符)', hint: '默认 20000;超了会截断并明确告知模型' },
68
+ { group: '写入', key: 'maxReadChars', label: '单次读取上限(字符)', hint: '默认 20000;zk-kit read 与别名工具的输出超了会截断并明确告知模型' },
69
69
  { group: '工具', key: 'aliasTools', label: '把 [alias] 注册成工具', hint: '默认关闭。打开后,加载插件时把各笔记本 .zk/config.toml 的 [alias] 里未注释的别名注册成 zk_<名>,模型可以像调内置工具一样调它们。\n别名是 $SHELL -c 执行的任意命令 —— 打开等于把这些命令交给 agent,只在你信得过 config.toml 内容时开。\n交互式命令(edit / 带 --interactive)会卡到超时,不适合当工具。改完要重载插件(或重启 DSH)才会出现在工具列表里', type: 'bool' },
70
70
  { group: 'zk', key: 'zkPath', label: 'zk 路径(可空)', hint: '空 = 自动找:配置 → $ZK_BIN → PATH → 插件内置(~/.dsh/zdiary/bin)' },
71
71
  { group: 'zk', key: 'zkVersion', label: '内置 zk 版本', hint: '「安装内置 zk」下载的版本,默认 0.15.7;改完点安装即升级' },
@@ -385,7 +385,7 @@ window.__ModuleLoader__?.load({
385
385
  }, h('option', { value: 'flat' }, 'flat'), h('option', { value: 'layered' }, 'layered')), h('button', { className: 'zdk-btn zdk-btn2', onClick: () => removeNotebook(name), disabled: nbNames.length <= 1 || !!busy }, '删除')))), h('div', { className: 'zdk-row' }, h('div', null, h('div', { className: 'zdk-label' }, '新增笔记本'), h('div', { className: 'zdk-hint' }, '名字只接受字母、数字、_ 与 -(1-32 字符);路径空着就是 <工作区>/zdiary,结构跟当前笔记本一致。改完点「保存」')), h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center' } }, h('input', { ...input, style: { minWidth: '0', width: '110px' }, placeholder: '名字', value: nbName, onChange: (e) => setNbName(e.target.value) }), h('input', { ...input, style: { minWidth: '0', width: '190px' }, placeholder: '路径', value: nbPath, onChange: (e) => setNbPath(e.target.value) }), h('button', { className: 'zdk-btn zdk-btn2', onClick: addNotebook, disabled: !nbName.trim() || !!busy }, '新增')))), ...groups.map((g) => h('div', { key: g }, h('div', { className: 'zdk-group' }, GROUP_LABELS[g] || g), h('div', null, FIELDS.filter((f) => f.group === g).map((f) => h('div', { className: 'zdk-row', key: f.key }, h('div', null, h('div', { className: 'zdk-label' }, f.label), h('div', { className: 'zdk-hint' }, f.hint)), control(f)))))), h('div', { className: 'zdk-actions' }, h('button', { className: 'zdk-btn', onClick: save, disabled: !!busy }, busy === 'save' ? '保存中…' : '保存'), h('button', { className: 'zdk-btn zdk-btn2', onClick: () => action('init', 'init'), disabled: !!busy }, busy === 'init' ? '处理中…' : initLabel), structure && snap?.notebook.exists && !structure.agents.present
386
386
  ? h('button', { className: 'zdk-btn zdk-btn2', onClick: () => action('agents', 'agents'), disabled: !!busy }, busy === 'agents' ? '写入中…' : '写入 AGENTS.md 模板')
387
387
  : null, h('button', { className: 'zdk-btn zdk-btn2', onClick: () => action('contract', 'contract'), disabled: !!busy }, busy === 'contract' ? '写入中…' : '写入契约模板'), h('button', { className: 'zdk-btn zdk-btn2', onClick: () => action('index', 'index'), disabled: !!busy }, busy === 'index' ? '索引进…' : '重建索引'), h('button', { className: 'zdk-btn zdk-btn2', onClick: () => action('install', 'install'), disabled: !!busy }, busy === 'install' ? '下载中…' : '安装内置 zk'), h('button', { className: 'zdk-btn zdk-btn2', onClick: selftest, disabled: !!busy }, busy === 'selftest' ? '自检中…' : '自检'), h('a', { className: 'zdk-btn zdk-btn2', href: '/dsh-zdiary-kit/view', target: '_blank', rel: 'noopener noreferrer', style: { display: 'inline-flex', alignItems: 'center', textDecoration: 'none' } }, '只读视图'), h('button', { className: 'zdk-btn zdk-btn2', onClick: load, disabled: !!busy }, '刷新'), dirty ? h('span', { style: { marginLeft: '10px', color: '#ffb020', fontSize: '13px', alignSelf: 'center' } }, '● 有改动还没保存') : null), okMsg ? h('div', { className: 'zdk-ok' }, okMsg) : null, err ? h('div', { className: 'zdk-err' }, err) : null, out ? h('div', { className: 'zdk-out' }, out) : null, snap?.countsError ? h('div', { className: 'zdk-err' }, '计数失败:' + snap.countsError) : null, h('div', { className: 'zdk-hint' }, `配置:${snap?.configPath || '~/.dsh/zdiary/zdiary.config.json'}\n` +
388
- '工具的用法:zk_search 查 → zk_read 读 → zk_new 新建 → zk_daily 写日记 → zk_link 连双链;zk_stats 看规模。'));
388
+ '工具的用法:zk_search 查 → 原生 read 读 → zk_new 新建 → zk_daily 写日记 → zk_link 连双链;zk_stats 看规模。'));
389
389
  }
390
390
  function apply(ctx) {
391
391
  ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'zdiary', order: 8, label: () => '知识库(zk)' }, Section), 'zdiary: settings section'), 'zdiary: settings section');
@@ -1,5 +1,5 @@
1
1
  /**
2
- * zk 工具(feature 的公共入口):14 个内置工具 + `[alias]` 别名工具,全部经 lib/zk.ts。
2
+ * zk 工具(feature 的公共入口):13 个内置工具 + `[alias]` 别名工具,全部经 lib/zk.ts。
3
3
  *
4
4
  * 设计要点:
5
5
  * · 除 zk_context(只读 meta 文件,不依赖 zk)外,每个工具进来先 ensureNotebook —— 第一次调用就自动建好笔记本,用户不用先点设置页;
@@ -15,7 +15,7 @@ import { configFor, pinSession, sessionNotebook, sessionState } from '../../conf
15
15
  import { defaultNotebook, expandHome, processWorkspace, resolveInWorkspace } from '../../config/paths.js';
16
16
  import { S, validateArgs } from '../../lib/tool.js';
17
17
  import { ensureNotebook, newNoteDir } from '../../lib/notebook.js';
18
- import { searchNotes, searchNotesDetailed, createNote, readNote, findNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, taglessCjkWarning, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, runAlias, ZkError, } from '../../lib/zk.js';
18
+ import { searchNotes, searchNotesDetailed, createNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, taglessCjkWarning, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, runAlias, ZkError, } from '../../lib/zk.js';
19
19
  import { configuredAliases, readAliases } from '../../lib/alias.js';
20
20
  import { buildMemoryPayload, META_FILES } from '../../lib/memory.js';
21
21
  import { META_NAMES } from '../../lib/meta.js';
@@ -104,6 +104,34 @@ const LINT_MEMORY = objSchema({
104
104
  }, ['source', 'entry', 'link', 'reason', 'path']),
105
105
  },
106
106
  }, ['files', 'links', 'total', 'unlinked', 'undated', 'retired', 'retiredBroken', 'stale', 'items']);
107
+ /** 日记时间轴:最近 90 天的空块 / 倒序 / 格式 / 位置(只报告) */
108
+ const LINT_TIMELINE = objSchema({
109
+ scanned: { type: 'number' },
110
+ skipped: { type: 'number' },
111
+ notes: { type: 'number' },
112
+ total: { type: 'number' },
113
+ counts: objSchema({
114
+ empty: { type: 'number' },
115
+ order: { type: 'number' },
116
+ format: { type: 'number' },
117
+ placement: { type: 'number' },
118
+ }, ['empty', 'order', 'format', 'placement']),
119
+ items: {
120
+ type: 'array',
121
+ items: objSchema({
122
+ path: { type: 'string' },
123
+ issues: {
124
+ type: 'array',
125
+ items: objSchema({
126
+ line: { type: 'number' },
127
+ kind: { type: 'string', enum: ['empty', 'order', 'format', 'placement'] },
128
+ title: { type: 'string' },
129
+ detail: { type: 'string' },
130
+ }, ['line', 'kind', 'title', 'detail']),
131
+ },
132
+ }, ['path', 'issues']),
133
+ },
134
+ }, ['scanned', 'skipped', 'notes', 'total', 'counts', 'items']);
107
135
  /** frontmatter 缺字段(P2-13) */
108
136
  const LINT_INCOMPLETE = objSchema({
109
137
  total: { type: 'number' },
@@ -232,7 +260,7 @@ function tagSuffix(record) {
232
260
  }
233
261
  function noteLine(n, index) {
234
262
  const head = `${index + 1}. ${n.title || n.path}`;
235
- const meta = [n.path, dateOnly(n.created)].filter(Boolean).join(' · ');
263
+ const meta = [n.absPath || n.path, dateOnly(n.created)].filter(Boolean).join(' · ');
236
264
  const lead = n.lead ? `\n ${n.lead}` : '';
237
265
  return `${head}\n ${meta}${tagSuffix(n)}${lead}`;
238
266
  }
@@ -330,8 +358,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
330
358
  const builtins = [
331
359
  t({
332
360
  name: 'zk_search',
333
- description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 / 孤立笔记),返回标题、相对路径、标签、创建日与摘要。' +
334
- '找到后用 zk_read 读全文。写笔记前先用它查重。' +
361
+ description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 / 孤立笔记),返回标题、相对路径、绝对路径、标签、创建日与摘要。' +
362
+ '找到后用原生 read 读全文:notes[].absPath 可以直接传给 read。写笔记前先用它查重。' +
335
363
  '中文查询会自动并用子串匹配(FTS 不切中文):matchStrategy 说明这次用了 fts / regex / mixed,mixed 表示补到了全文索引漏掉的笔记。',
336
364
  parameters: {
337
365
  type: 'object',
@@ -357,10 +385,11 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
357
385
  items: objSchema({
358
386
  title: { type: 'string' },
359
387
  path: { type: 'string' },
388
+ absPath: { type: 'string' },
360
389
  tags: { type: 'array', items: { type: 'string' } },
361
390
  created: { type: 'string' },
362
391
  lead: { type: 'string' },
363
- }, ['title', 'path', 'tags', 'created', 'lead']),
392
+ }, ['title', 'path', 'absPath', 'tags', 'created', 'lead']),
364
393
  },
365
394
  }, ['notebook', 'count', 'matchStrategy', 'notes']),
366
395
  },
@@ -381,7 +410,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
381
410
  notebook: cfg.notebook,
382
411
  count: result.notes.length,
383
412
  matchStrategy: result.matchStrategy,
384
- notes: result.notes.map((n) => ({ title: n.title, path: n.path, tags: n.tags, created: dateOnly(n.created), lead: n.lead })),
413
+ notes: result.notes.map((n) => ({ title: n.title, path: n.path, absPath: n.absPath, tags: n.tags, created: dateOnly(n.created), lead: n.lead })),
385
414
  };
386
415
  },
387
416
  render(_args, value) {
@@ -426,6 +455,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
426
455
  items: objSchema({
427
456
  title: { type: 'string' },
428
457
  path: { type: 'string' },
458
+ absPath: { type: 'string' },
429
459
  type: { type: 'string' },
430
460
  status: { type: 'string' },
431
461
  authority: { type: 'string' },
@@ -433,7 +463,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
433
463
  created: { type: 'string' },
434
464
  lead: { type: 'string' },
435
465
  archived: { type: 'boolean' },
436
- }, ['title', 'path', 'type', 'status', 'authority', 'tags', 'created', 'lead', 'archived']),
466
+ }, ['title', 'path', 'absPath', 'type', 'status', 'authority', 'tags', 'created', 'lead', 'archived']),
437
467
  },
438
468
  }, ['notebook', 'count', 'notes']),
439
469
  },
@@ -462,6 +492,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
462
492
  notes: notes.map((n) => ({
463
493
  title: n.title,
464
494
  path: n.path,
495
+ absPath: n.absPath,
465
496
  // daily 模板没有 frontmatter:按 dailyDir 回显,和 type=daily 的过滤口径一致
466
497
  type: n.type || (isUnderDir(n.path, cfg.dailyDir) ? 'daily' : ''),
467
498
  status: n.status || 'active',
@@ -479,76 +510,11 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
479
510
  return text(`没有匹配的笔记(笔记本 ${v.notebook})`);
480
511
  const lines = v.notes.map((n, i) => {
481
512
  const badges = [String(n.type || '—'), String(n.status || 'no-status'), n.archived ? '已归档' : ''].filter(Boolean);
482
- return `${i + 1}. ${String(n.title)} [${badges.join(' · ')}]\n ${String(n.path)} · ${String(n.created)}${String(n.lead) ? '\n ' + String(n.lead) : ''}`;
513
+ return `${i + 1}. ${String(n.title)} [${badges.join(' · ')}]\n ${String(n.absPath || n.path)} · ${String(n.created)}${String(n.lead) ? '\n ' + String(n.lead) : ''}`;
483
514
  });
484
515
  return text(`${v.count} 条(笔记本 ${v.notebook})\n` + lines.join('\n'));
485
516
  },
486
517
  }),
487
- t({
488
- name: 'zk_read',
489
- description: '读一篇笔记的全文(或先按搜索词找到最相关的一篇再读)。路径是相对笔记本根目录的路径,如 notes/ab12.md。' +
490
- '也可以读根目录的 meta 文件(MEMORY.md / USER.md),注入时被截掉的段落用这个取回。' +
491
- '长笔记会被截断并明确标注。',
492
- parameters: {
493
- type: 'object',
494
- properties: {
495
- path: S.str('笔记的相对路径;与 query 二选一'),
496
- query: S.str('搜索词:取最相关的一篇读;与 path 二选一'),
497
- maxChars: S.num('最多返回多少字符(默认取设置里的值)'),
498
- },
499
- additionalProperties: false,
500
- },
501
- output: {
502
- schema: objSchema({
503
- notebook: { type: 'string' },
504
- path: { type: 'string' },
505
- title: { type: 'string' },
506
- tags: { type: 'array', items: { type: 'string' } },
507
- created: { type: 'string' },
508
- modified: { type: 'string' },
509
- chars: { type: 'number' },
510
- truncated: { type: 'boolean' },
511
- content: { type: 'string' },
512
- }, ['notebook', 'path', 'title', 'tags', 'created', 'modified', 'chars', 'truncated', 'content']),
513
- },
514
- async run(args, env) {
515
- const p = args.path ? String(args.path) : '';
516
- const q = args.query ? String(args.query) : '';
517
- if (!p && !q)
518
- throw new ZkError('path 和 query 至少给一个');
519
- const cfg = configFor(env.workspace, env.sessionId);
520
- await ensureNotebook(cfg);
521
- let doc;
522
- try {
523
- doc = p ? await readNote(cfg, p, env.signal) : await findNote(cfg, q, env.signal);
524
- }
525
- catch (err) {
526
- throw withElsewhere(err, cfg, env.workspace, p);
527
- }
528
- if (!doc)
529
- throw new ZkError(`没找到匹配的笔记:${q}`, '换一个搜索词,或用 zk_search 先看看有哪些笔记');
530
- const limit = Math.min(200_000, Math.max(1000, Math.trunc(Number(args.maxChars ?? cfg.maxReadChars))));
531
- const truncated = doc.content.length > limit;
532
- return {
533
- notebook: cfg.notebook,
534
- path: doc.path,
535
- title: doc.title,
536
- tags: doc.tags,
537
- created: dateOnly(doc.created),
538
- modified: dateOnly(doc.modified),
539
- chars: doc.content.length,
540
- truncated,
541
- content: truncated ? doc.content.slice(0, limit) : doc.content,
542
- };
543
- },
544
- render(_args, value) {
545
- const v = value;
546
- // 正文本身就带一级标题(zk 模板),别再重复一次;这一行只放元信息
547
- const head = [v.path, v.created].filter(Boolean).join(' · ');
548
- const cut = v.truncated ? `\n\n…(已截断:共 ${v.chars} 字,传 maxChars 可读更多)` : '';
549
- return text(`${head}${tagSuffix(v)}\n\n${v.content}${cut}`);
550
- },
551
- }),
552
518
  t({
553
519
  name: 'zk_new',
554
520
  description: '新建一篇笔记(zk 负责生成文件名、套用模板、写入索引)。适合记下一个概念、决定、来源或想法;' +
@@ -582,6 +548,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
582
548
  schema: objSchema({
583
549
  notebook: { type: 'string' },
584
550
  path: { type: 'string' },
551
+ absPath: { type: 'string' },
585
552
  title: { type: 'string' },
586
553
  tags: { type: 'array', items: { type: 'string' } },
587
554
  links: { type: 'array', items: { type: 'string' } },
@@ -597,7 +564,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
597
564
  }, ['path', 'title', 'reason']),
598
565
  },
599
566
  warnings: { type: 'array', items: { type: 'string' } },
600
- }, ['notebook', 'path', 'title', 'tags', 'links', 'summaryApplied', 'archived', 'warnings']),
567
+ }, ['notebook', 'path', 'absPath', 'title', 'tags', 'links', 'summaryApplied', 'archived', 'warnings']),
601
568
  },
602
569
  async run(args, env) {
603
570
  const cfg = configFor(env.workspace, env.sessionId);
@@ -637,7 +604,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
637
604
  // 没有告警就不要写 summaryWarning: undefined —— 宿主按无损 JSON 快照校验输出,
638
605
  // 值为 undefined 的字段会让整次调用报 INVALID_TOOL_OUTPUT(文件其实已经建好)。
639
606
  return {
640
- notebook: cfg.notebook, path: created.path, title: created.title, tags, links,
607
+ notebook: cfg.notebook, path: created.path, absPath: created.absPath, title: created.title, tags, links,
641
608
  summaryApplied: created.summaryApplied, archived, warnings,
642
609
  ...(created.summaryWarning ? { summaryWarning: created.summaryWarning } : {}),
643
610
  ...(tagWarning ? { tagWarning } : {}),
@@ -645,7 +612,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
645
612
  },
646
613
  render(_args, value) {
647
614
  const v = value;
648
- const lines = [`已记下「${v.title}」→ ${v.path}`];
615
+ const lines = [`已记下「${v.title}」→ ${v.absPath || v.path}`];
649
616
  if (v.tags.length)
650
617
  lines.push('标签:' + v.tags.map((t) => '#' + t).join(' '));
651
618
  if (v.links.length)
@@ -680,9 +647,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
680
647
  schema: objSchema({
681
648
  notebook: { type: 'string' },
682
649
  path: { type: 'string' },
650
+ absPath: { type: 'string' },
683
651
  created: { type: 'boolean' },
684
652
  appended: { type: 'boolean' },
685
- }, ['notebook', 'path', 'created', 'appended']),
653
+ }, ['notebook', 'path', 'absPath', 'created', 'appended']),
686
654
  },
687
655
  async run(args, env) {
688
656
  const cfg = configFor(env.workspace, env.sessionId);
@@ -691,18 +659,18 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
691
659
  const appended = Boolean(args.entry && String(args.entry).trim());
692
660
  if (appended)
693
661
  appendDaily(cfg, daily.path, String(args.entry), new Date());
694
- return { notebook: cfg.notebook, path: daily.path, created: daily.created, appended };
662
+ return { notebook: cfg.notebook, path: daily.path, absPath: daily.absPath, created: daily.created, appended };
695
663
  },
696
664
  render(_args, value) {
697
665
  const v = value;
698
666
  const state = v.created ? '新建' : '已有';
699
- return text(`日记 ${state} → ${v.path}${v.appended ? '(已追加一段)' : ''}\n笔记本:${v.notebook}`);
667
+ return text(`日记 ${state} → ${v.absPath || v.path}${v.appended ? '(已追加一段)' : ''}\n笔记本:${v.notebook}`);
700
668
  },
701
669
  }),
702
670
  t({
703
671
  name: 'zk_append',
704
672
  description: '往一篇已有笔记末尾追加内容(自动补空行,可选先起一个二级标题)。适合补充证据、跟进结论、在会议记录里续写;' +
705
- `整篇重写请用编辑器,别用这个工具。根目录的 ${META_NAMES.join(' / ')} 是 meta 文件,会被拒绝。`,
673
+ `整篇重写请用原生 write / edit,别用这个工具。根目录的 ${META_NAMES.join(' / ')} 是 meta 文件,会被拒绝。`,
706
674
  parameters: {
707
675
  type: 'object',
708
676
  properties: {
@@ -1045,6 +1013,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1045
1013
  'incomplete 是 frontmatter 缺 type / status / authority 的笔记:缺失被索引落成空串,机械门会静默失效。' +
1046
1014
  'tags 查标签卫生(大小写变体 / 单例,标签总数 ≥ 30 才报);template 说根目录 AGENTS.md 是不是当前版本。' +
1047
1015
  'similarTitles 是「改一两个字」的疑似重复(同目录、二元组相似度 ≥ 0.6):与全等重名分开,只报告。' +
1016
+ 'timeline 是日记时间轴:最近 90 天的空块 / 倒序 / 格式(11:5x)/ 位置(layered 用 ##、或在 ## Events 外)问题,只报告不改文件。' +
1017
+ 'total / counts 按全量算,items 里每篇最多 50 条明细,整个桶最多 50 篇;skipped 是过大或读不到而没检查的篇数。' +
1048
1018
  'indexHint=true 表示笔记(不含日记)已到 150 篇而根目录还没有 INDEX.md(只是提示,不生成静态索引)。' +
1049
1019
  '孤儿与无标签不含日记(按天写的日记天然如此,报出来只会淹没真问题)。' +
1050
1020
  'oneWayLinks.items 是缺回链的目标 X(不是来源),from 是没被 X 回链的来源 S;' +
@@ -1081,8 +1051,9 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1081
1051
  tags: LINT_TAGS,
1082
1052
  template: LINT_TEMPLATE,
1083
1053
  contract: LINT_CONTRACT,
1054
+ timeline: LINT_TIMELINE,
1084
1055
  indexHint: { type: 'boolean' },
1085
- }, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'contract', 'indexHint']),
1056
+ }, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'contract', 'timeline', 'indexHint']),
1086
1057
  },
1087
1058
  async run(args, env) {
1088
1059
  const cfg = configFor(env.workspace, env.sessionId);
@@ -17,8 +17,8 @@
17
17
  * 首行 `<!-- zdiary-template: vN -->` 是版本标记:lint 据此报告「老库的 AGENTS.md 是旧版」,
18
18
  * 只报告不覆盖(模板允许用户改)。
19
19
  */
20
- /** 模板版本:改模板就 +1;lint 用它判断老库是否还在用旧契约(v7:精简模板) */
21
- export const TEMPLATE_VERSION = 7;
20
+ /** 模板版本:改模板就 +1;lint 用它判断老库是否还在用旧契约(v8:读取交给原生 read) */
21
+ export const TEMPLATE_VERSION = 8;
22
22
  /** 首行版本标记(实测 4 词);不许带日期 —— 带日期的写法实测 6 词,白花 2 词 */
23
23
  export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
24
24
  /**
@@ -26,7 +26,7 @@ export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
26
26
  * 「只把首行数字改成 vN、正文还是旧版」。
27
27
  */
28
28
  export const TEMPLATE_SENTINELS = {
29
- 7: { required: ['先 zk_read 核对来源'], forbidden: ['DSH 不会自动加载', '从底部往前丢'] },
29
+ 8: { required: ['先 read 核对来源'], forbidden: ['DSH 不会自动加载', '从底部往前丢'] },
30
30
  };
31
31
  export const AGENTS_TEMPLATE = `${TEMPLATE_MARK}
32
32
 
@@ -52,7 +52,7 @@ notes/{concepts,entities,patterns}/ 原子笔记 · archive/ 废弃(不删)
52
52
  ## 每周
53
53
 
54
54
  每周:DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
55
- MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 zk_read 核对来源;退役写 - [superseded YYYY-MM-DD] 旧结论 → [[新结论]],行不删。
55
+ MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 read 核对来源;退役写 - [superseded YYYY-MM-DD] 旧结论 → [[新结论]],行不删。
56
56
  新条目写顶部;超预算按日期丢最旧的一条。
57
57
  `;
58
58
  /**
@@ -72,7 +72,7 @@ export const AGENTS_TEMPLATE_FLAT = `${TEMPLATE_MARK}
72
72
  ## 每周
73
73
 
74
74
  DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
75
- MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 zk_read 核对来源;退役写 - [superseded] 旧结论 → [[新结论]]。
75
+ MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 read 核对来源;退役写 - [superseded] 旧结论 → [[新结论]]。
76
76
  `;
77
77
  /**
78
78
  * 根目录 WORKFLOW.md:只在「要动已有笔记」时才需要读,所以不注入、不计预算。
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 日期口径(3.1):`YYYY-MM-DD` 的严格校验只写一份。
3
+ *
4
+ * 为什么单独一层:`zk_lint` 的 90 天窗口、`zk_dream` 的 noteDate 判的其实是同一件事 ——
5
+ * 「这串是不是一天」。各写一份就会在边界上漂移(`2026-02-30` 一边认、一边不认)。
6
+ * 这里只有纯函数、不 import 任何东西:被 lint / dream / timeline 共用,不能反向依赖它们。
7
+ */
8
+ /** 严格的 YYYY-MM-DD(2 月 30 日、13 月都不算) */
9
+ export function isDayString(value) {
10
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
11
+ return false;
12
+ const [year, month, day] = value.split('-').map(Number);
13
+ const at = new Date(year, month - 1, day);
14
+ return at.getFullYear() === year && at.getMonth() === month - 1 && at.getDate() === day;
15
+ }
package/dist/lib/dream.js CHANGED
@@ -19,6 +19,7 @@ import { parseFrontmatter } from './frontmatter.js';
19
19
  // 循环引用在 ESM 下安全 —— 不要在模块顶层调用 memoryUsage。
20
20
  import { memoryUsage } from './memory.js';
21
21
  import { daysSinceDate, entryDate, isRetiredEntry, splitMemoryEntries, stripRetiredEntries } from './memory-format.js';
22
+ import { isDayString } from './dates.js';
22
23
  import { normalizeTitle, resolveWikiTarget, WIKI_LINK, wikiIndex } from './wikilink.js';
23
24
  /** 每栏最多回多少条(计划 §4 M3 的 50 条上限) */
24
25
  export const MAX_ITEMS = 50;
@@ -104,6 +105,34 @@ function isUnder(rel, dir) {
104
105
  const d = dir.replace(/\/+$/, '');
105
106
  return rel === d || rel.startsWith(d + '/');
106
107
  }
108
+ /**
109
+ * 笔记的日历日期(计划 §2 D7 / Q6)。
110
+ *
111
+ * 日记补写时 `zk_daily --date` 只改文件名,zk 的 `created` 仍是今天 —— 按 created 筛窗口
112
+ * 会把 10 月的日记算成本周新增。所以:日记看文件名,其他笔记看 frontmatter `date`,
113
+ * 都没有才退回 created(老笔记行为不变)。
114
+ */
115
+ export function noteDate(cfg, note) {
116
+ if (isUnder(note.path, cfg.dailyDir)) {
117
+ const stem = path.basename(note.path, path.extname(note.path));
118
+ if (isDayString(stem))
119
+ return stem;
120
+ }
121
+ else {
122
+ const raw = note.metadata?.date;
123
+ const value = typeof raw === 'string' ? raw.trim() : '';
124
+ if (isDayString(value))
125
+ return value;
126
+ }
127
+ return localDate(note.created);
128
+ }
129
+ /** 日期字符串 → 本地零点毫秒;非法日期返回 NaN */
130
+ function dayMs(day) {
131
+ if (!isDayString(day))
132
+ return Number.NaN;
133
+ const [year, month, date] = day.split('-').map(Number);
134
+ return new Date(year, month - 1, date).getTime();
135
+ }
107
136
  /**
108
137
  * 机械摘要:frontmatter 之后、第一个正文段落,压空白后最多 200 字。
109
138
  * 为什么不用 NoteRecord.lead:zk 的 lead 是笔记首行(通常是标题行),当摘要没有信息量。
@@ -303,7 +332,7 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
303
332
  type: note.type,
304
333
  authority: note.authority,
305
334
  tags: note.tags,
306
- created: localDate(note.created),
335
+ created: noteDate(cfg, note),
307
336
  lead: excerptOf(cfg, note),
308
337
  cited: citedOf(note),
309
338
  citedBy: (inbound.get(note.path) ?? []).slice(0, 5),
@@ -314,10 +343,10 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
314
343
  const promoted = promotionsOf(cfg, notes);
315
344
  const windowNotes = notes
316
345
  .filter((n) => {
317
- const at = Date.parse(n.created);
346
+ const at = dayMs(noteDate(cfg, n));
318
347
  return Number.isFinite(at) && at >= sinceMs;
319
348
  })
320
- .sort((a, b) => Date.parse(b.created) - Date.parse(a.created));
349
+ .sort((a, b) => noteDate(cfg, b).localeCompare(noteDate(cfg, a)));
321
350
  const newNotes = [];
322
351
  const alreadyPromoted = [];
323
352
  const rejected = [];
@@ -343,7 +372,7 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
343
372
  .filter((n) => {
344
373
  if (isUnder(n.path, cfg.dailyDir))
345
374
  return false;
346
- const at = Date.parse(n.created);
375
+ const at = dayMs(noteDate(cfg, n));
347
376
  if (Number.isFinite(at) && at >= sinceMs)
348
377
  return false;
349
378
  if (promoted.has(n.path))
@@ -368,7 +397,7 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
368
397
  continue;
369
398
  looseEndCount += items.length;
370
399
  if (dailyLooseEnds.length < MAX_ITEMS) {
371
- dailyLooseEnds.push({ path: note.path, date: localDate(note.created), items });
400
+ dailyLooseEnds.push({ path: note.path, date: noteDate(cfg, note), items });
372
401
  }
373
402
  }
374
403
  // 排序说明(P2-12):先看「被日记提过几天」—— 跨天复现比同一天多次更强;同一天多篇日记