dsh-zdiary-kit 0.8.3 → 0.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dsh-zdiary-kit 0.8.3
1
+ # dsh-zdiary-kit 0.9.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),
@@ -39,15 +39,17 @@ layered 下每篇笔记都要落在 group 里:`zk_new` 不给 `dir` 就按 `ty
39
39
 
40
40
  **长期记忆**:笔记本根目录放 `AGENTS.md`(工作约定)、`USER.md`(偏好)、`MEMORY.md`(精炼记忆),
41
41
  插件会在每个 step 把它们注入系统提示(预算默认 500 词,设置页「记忆 → 注入预算」可改;
42
- 超了先丢 MEMORY 的尾部,按 `##` 小节 → 顶层列表项 → 空行段落 三级降级切分(`# 记忆` + 要点列表这种最常见的写法也算数),
42
+ 超了先丢 MEMORY 里**日期最旧**的一条(都没写日期才退回从尾部往前丢),
43
+ 按 `##` 小节 → 顶层列表项 → 空行段落 三级降级切分(`# 记忆` + 要点列表这种最常见的写法也算数),
43
44
  丢掉的条目 / 段落留一份目录(标题)—— 需要时用 `zk_read MEMORY.md` 取回;
44
- 条目列表按条丢、从末尾往前,所以新条目若加在底部会先被丢;
45
+ 同日期按文件里靠后的先丢,所以带日期的条目不会因为写在底部就先被删;
45
46
  同时明确告诉你截了多少、谁已经没法再丢)。用到预算 80% 以上时还会回显一行「记忆已用 246/300 词(82%)」
46
47
  (数字已含这行提示本身)—— 先合并或退役旧条目,别等第一次截断。
47
48
  笔记本提示是单独的一段,不占这 500 词预算。
48
49
  DSH 自带的 AGENTS.md 加载只看「项目根 → 当前目录」链,**不会**读笔记本根目录,所以别指望宿主帮你加载 —— 是插件自己读、自己注入。
49
50
  记忆条目的格式约定在 `AGENTS.md` 里:每条写 `结论(YYYY-MM-DD)[[来源路径]]`;退役写成
50
- `- [superseded YYYY-MM-DD] 旧结论 → [[新结论]]`,行留在原处(`zk_lint` 会核对退役行指向的新结论是否还活着,但不会替你删)。
51
+ `- [superseded YYYY-MM-DD] 旧结论 → [[新结论]]`,行留在原处。注入时会**省略退役条目**(并回显省略了几条),
52
+ 但文件本身不动 —— git 与记忆页仍看得到「这里曾经有过什么」。
51
53
  `flat` 结构默认**不写** `AGENTS.md`(从 0.1.0 升级过来的库一个文件都不多);要约定与周提醒就显式
52
54
  `zk-kit init --with-agents`,或在设置页点「写入 AGENTS.md 模板」—— 已存在的文件绝不覆盖。
53
55
  模板首行有 `<!-- zdiary-template: vN -->` 版本标记:老库的 `AGENTS.md` 是旧版时 `zk_lint` 只提示,不自动改。
@@ -55,9 +57,12 @@ DSH 自带的 AGENTS.md 加载只看「项目根 → 当前目录」链,**不
55
57
  维护用 `zk_lint`(结构体检 + 记忆链接核对)和 `zk_dream`(晋升候选 / 拒绝原因 / 未完成项):两个工具都**只读**,
56
58
  写 `MEMORY.md` / `DREAMS.md` 由 agent 按 `AGENTS.md` 自己决定 —— 机械活留在插件,语义判断留在可审计的地方。
57
59
  `zk_dream` 会先读一遍 `MEMORY.md`:已经晋升过的(`[[链接]]` 命中,或条目里直接写了标题)移出候选、单列「已在 MEMORY」,
58
- 不会每周原样重复;窗口外仍未晋升的进 `backlog`,漏做一次不会永久掉队;不传 `days` 时窗口 = 距 `DREAMS.md`
60
+ 不会每周原样重复(退役行里的旧标题不算已晋升,但退役行里的 `→ [[新结论]]` 仍算);
61
+ 窗口外仍未晋升的进 `backlog`,漏做一次不会永久掉队;不传 `days` 时窗口 = 距 `DREAMS.md`
59
62
  「上次做梦」的天数(没有就 7 天)。被引排行先按「被日记提到几天」(`daysMentioned`)排,入链数只作并列次序 ——
60
63
  日记是这个插件里唯一按时间记录真实工作的层,空信号只说明日记里没写过,不等于没被用过。
64
+ `zk_dream` 还会回一行**记忆余量**(内容词 + 提示 = 总量,余量按总量算,可以为负)和「可考虑退役」的条目
65
+ (来源已归档 / 不存在、或超过 90 天没复核)—— 只给材料,不写任何文件。
61
66
  `zk_lint` 会核对 `MEMORY.md` / `USER.md` 里的 `[[来源路径]]` 是否还指向活笔记 ——
62
67
  `zk_supersede` 只重写笔记之间的入链,meta 文件不在图里,链接不会跟着搬,`--broken-links` 也看不见。
63
68
  改名同理:`zk_rename` 会把 `zk graph` 里的入链和根目录 meta 的 `[[来源]]` 一起改到新路径,被搬走那篇自己的相对 Markdown 链接也按新位置重算 —— 手工 `mv` 会一次断掉这三处。
@@ -160,6 +165,7 @@ dsh plugin --profile web add "link:/path/to/dsh-zdiary-kit"
160
165
  - 顶层 `notebook` 与 `structure` 是**派生的**(`notebooks[active]` 解析后的绝对路径 / 该条目的结构),只在内存里、不落盘也不可写;可写的是条目里的 `notebooks[名].structure`(`zk-kit config set structure=…` 改的就是当前笔记本那一条)—— 磁盘上笔记本只有一个真相,就是 `notebooks` + `active`。
161
166
  老配置里那个单独的 `notebook` 字段(和全局 `structure`)读进来会**一次性**迁进 `notebooks.default`,之后不再互相覆盖。
162
167
  - **共享的是全局项**:笔记 / 日记子目录、`daily` group、归档目录、注入预算 —— 这些不按笔记本分开。
168
+ 改子目录 / group 名后要跑 `zk-kit groups --fix` 让 `.zk/config.toml` 跟上;归档目录非空时不允许改(不自动迁移文件)。
163
169
 
164
170
  ```bash
165
171
  zk-kit notebooks # 列出所有笔记本(* 是当前那个;[flat/layered] 是各自的结构)
@@ -207,6 +213,26 @@ filename = '{{format-date now "%Y-%m-%d"}}'
207
213
  template = "daily.md"
208
214
  ```
209
215
 
216
+ ### 改了目录 / group 之后
217
+
218
+ 插件**不会自动重写**已有的 `[group.*]`:你改过 `notesDir` / `dailyDir` / `dailyGroup` 后,
219
+ `zk-kit init` 只追加缺失的 group,不会把旧 paths 改掉(也不会有两个 group 抢同一路径)。
220
+ 差异由 `doctor` / `groups` / 设置页报告,确认后用显式修复:
221
+
222
+ ```bash
223
+ zk-kit groups # 默认 dry-run:逐组打印期望 / 实际
224
+ zk-kit groups --fix # 只改 dsh-zdiary-kit 自己写的 group:paths 行或旧组头改名
225
+ ```
226
+
227
+ `--fix` 写前备份 `.zk/config.toml.bak`,只改 paths 与组头;自定义的 `template` / `extra` / 注释 / 别的 group 一字不动。
228
+ 两个 group 要落到**同一条路径**时它拒绝写(整轮不改,并在 `groups` / `doctor` / 设置页里报出来)——
229
+ 那样 zk 命中哪个模板就只剩实现细节了。父子目录不算冲突:`dailyDir=notes` 与 `notes/concepts` 可以共存;
230
+ 没写 `paths` 的 group 按同名目录算(zk 的语义),同样算抢同一路径。
231
+ `dailyGroup` 改名且 `dailyDir` 没变时,`--fix` 直接把旧组头改成新名字(连同 `.note` / `.extra` 子表),不追加第二个日记组。
232
+
233
+ `archiveDir` 是另一条硬规则:**旧归档目录非空时拒绝改**。插件不迁移归档文件,改了会让废弃笔记重新进入检索、
234
+ 统计也会把它们算成活跃 —— 先手动迁移,或保持原值。空目录 / 不存在的目录可以改。
235
+
210
236
  ### 分层结构(可选)
211
237
 
212
238
  给某个笔记本选 `layered`:设置页笔记本那一行的结构下拉,或切到它后 `zk-kit config set structure=layered`
@@ -266,6 +292,8 @@ template = "daily.md"
266
292
  ```bash
267
293
  zk-kit init # 建库 / 补齐目录、模板、group、AGENTS.md(幂等)
268
294
  zk-kit init --with-agents # flat 库也写一份精简版 AGENTS.md(已存在不覆盖)
295
+ zk-kit groups # 对照配置与 .zk/config.toml 的 group(默认 dry-run)
296
+ zk-kit groups --fix # 只改插件建的 group 的 paths / 组头(写前备份 .zk/config.toml.bak)
269
297
  zk-kit new --title "示例笔记" --body "正文" --tags demo --type concept
270
298
  zk-kit search --tags demo --limit 5
271
299
  zk-kit daily --entry "今天把 zk-kit 跑了一遍"
@@ -330,9 +358,10 @@ zk-kit doctor # 自检:zk / 笔记本 / 模板 / group
330
358
  | 设置页 503 | 宿主没有 `connection` 服务,信任栅栏按 fail-closed 拒绝(工具不受影响) |
331
359
  | 安装 zk 报「解包失败」 | 系统没有 `tar`;手动解包后把 `zk` 放进 `~/.dsh/zdiary/bin` |
332
360
  | 搜索结果不全 | 索引落后:点「重建索引」(`zk index`),或确认文件没被 `.zk/config.toml` 的 `exclude` 排除 |
333
- | 自检报「✗ 长期记忆:N/预算 词」 | AGENTS + USER + MEMORY 写太长:先压缩,或在设置页调高「注入预算」(超预算时注入会先丢 MEMORY 尾部,条目 / 段落按条从末尾往前丢) |
361
+ | 自检报「✗ 长期记忆:N/预算 词」 | AGENTS + USER + MEMORY 写太长:先压缩,或在设置页调高「注入预算」(超预算时注入先丢 MEMORY 里日期最旧的条目,一条日期都没有才退回从末尾往前丢) |
334
362
  | 体检报「记忆链接:N 条失效」 | `MEMORY.md` / `USER.md` 里的 `[[来源]]` 指向的笔记已归档或删除:改成 `archive/` 下的新路径,或改指活笔记;显式写 `archive/` 的链接不算失效 |
335
- | 体检报「N 个条目没写日期 / 已退役」 | 按 `AGENTS.md` 的格式补 `结论(YYYY-MM-DD)[[来源路径]]`;退役行写 `- [superseded …] 旧结论 → [[新结论]]`,行留着不删。只报告,注入仍按原文 |
363
+ | 体检报「N 个条目没写日期 / 已退役」 | 按 `AGENTS.md` 的格式补 `结论(YYYY-MM-DD)[[来源路径]]`;退役行写 `- [superseded …] 旧结论 → [[新结论]]`,行留着不删(注入时会省略退役条目,文件本身不动)。只报告 |
364
+ | 体检报「N 条超过 90 天未复核」 | 条目的日期太旧:确认结论还成立就改日期,否则按退役格式写一行 `- [superseded …]`。`zk_dream` 的「可考虑退役」会给同一批材料 |
336
365
  | 体检报「AGENTS.md 是旧版 / 无版本标记」 | 模板升级过,老库不会自动覆盖(可能有你自己的改动):`zk_lint` 的输出里会直接附上新版模板全文,按需合并到自己的 `AGENTS.md`;不合并也能用,只是少新加的约定 |
337
366
  | 体检报「疑似重复标题」 | 同目录里有两篇标题只差一两个字(二元组相似度 ≥ 0.6,或短标题被长标题包含)。只报告:确认是同一结论就用 `zk_supersede` 合并,不是就留着 |
338
367
  | 体检提示「笔记已到 150 篇(不含日记)」 | 检索开始变糊的拐点,但插件不生成 `INDEX.md`(静态索引会过期)。用 `zk_stats` 看目录 / 标签分布决定先读哪里;真要总索引就自己写,提示会消失 |
package/dist/cli.js CHANGED
@@ -6,17 +6,18 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { config, writeConfig, selectNotebook, isNotebookName, CONFIG_KEYS } from './config/store.js';
8
8
  import { CFG_FILE } from './config/paths.js';
9
- import { NOTE_KINDS, ensureNotebook, newNoteDir, structureStatus } from './lib/notebook.js';
9
+ import { NOTE_KINDS, ensureNotebook, fixGroupConfig, groupOverlapNotes, newNoteDir, structureStatus } from './lib/notebook.js';
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
13
  import { formatLintExtras, formatMemoryLinks, lintNotebook } from './lib/lint.js';
14
- import { dreamNotebook } from './lib/dream.js';
14
+ import { dreamNotebook, STALE_DAYS } from './lib/dream.js';
15
15
  const HELP = `zk-kit —— dsh-zdiary-kit 的命令行
16
16
 
17
17
  zk-kit doctor 自检:zk / 笔记本 / 模板 / group / 索引
18
18
  zk-kit install [版本] 安装内置 zk(默认取配置里的版本)
19
19
  zk-kit init [--with-agents] 建好(或补齐)笔记本;flat 下加 --with-agents 才写 AGENTS.md 模板
20
+ zk-kit groups [--fix] [--dry-run] 对照配置与 .zk/config.toml 的 group(默认 dry-run;--fix 只改插件建的 paths,写前备份)
20
21
  zk-kit new --title T [--name 文件名] [--summary 摘要] [--body B] [--tags a,b] [--dir notes] [--type source|concept|entity|pattern]
21
22
  zk-kit search [词] [--tags a,b] [--since 日期] [--limit 5] [--json]
22
23
  zk-kit read <路径> | --query 词 [--max-chars n] [--json]
@@ -183,6 +184,18 @@ function dreamReport(r) {
183
184
  const lines = [
184
185
  `做梦:近 ${r.windowDays} 天(自 ${r.since})— 窗口 ${r.counts.window} 篇(日记 ${r.counts.daily})· 候选 ${r.counts.candidates} · 拒绝 ${r.counts.rejected} · 未完成 ${r.counts.looseEnds} · 已晋升 ${r.counts.promoted} · 积压 ${r.counts.backlog}`,
185
186
  ];
187
+ // 余量按总词算:只报内容词等于说「还有 10 词」,而框与提示早就把它吃完了
188
+ lines.push(`记忆:内容 ${r.memory.words}/${r.memory.budget} 词 + 提示 ${r.memory.totalWords - r.memory.words} = ${r.memory.totalWords} 词(余 ${r.memory.headroom})`);
189
+ if (r.retireCandidates.length) {
190
+ lines.push('可考虑退役:');
191
+ for (const c of r.retireCandidates.slice(0, 10)) {
192
+ const when = c.date ? `${c.date}(${c.age} 天)` : '无日期';
193
+ const why = c.reason === 'stale'
194
+ ? `超过 ${STALE_DAYS} 天未复核`
195
+ : c.reason === 'source-superseded' ? '来源已归档' : '来源不存在';
196
+ lines.push(` · ${c.entry} — ${when} · ${why}`);
197
+ }
198
+ }
186
199
  if (r.newNotes.length) {
187
200
  lines.push('晋升候选:');
188
201
  for (const [i, n] of r.newNotes.slice(0, 10).entries()) {
@@ -236,6 +249,70 @@ function dreamReport(r) {
236
249
  lines.push('(只报告:MEMORY.md / DREAMS.md 由你按 AGENTS.md 写)');
237
250
  return lines.join('\n');
238
251
  }
252
+ /** group 路径重叠:config = 配置本身冲突(⚠️),file = config.toml 里已经撞了(✗) */
253
+ function overlapLines(st) {
254
+ return groupOverlapNotes(st).map((note) => `${note.level === 'file' ? '✗' : '⚠️'} ${note.text}`);
255
+ }
256
+ function groupsReport(cfg, st, fixed) {
257
+ if (fixed) {
258
+ if (!fixed.changed) {
259
+ // 有 skip 就不是「没需要修的」—— 是「想修但修不了」,得说清哪一条没改
260
+ const skipped = fixed.updates.filter((update) => update.action === 'skip');
261
+ const lines = [`group 配置:${fixed.notebook} —— ${skipped.length ? '没有写文件' : '没有需要修的(未写文件)'}`];
262
+ for (const update of skipped)
263
+ lines.push(` · ${update.name}:未改 —— ${update.reason ?? ''}`);
264
+ for (const warning of fixed.warnings)
265
+ lines.push('⚠️ ' + warning);
266
+ return lines.join('\n');
267
+ }
268
+ const lines = [`已修复 group 配置:${fixed.notebook}(备份 ${fixed.backup})`];
269
+ for (const update of fixed.updates) {
270
+ if (update.action === 'paths') {
271
+ lines.push(` ✓ ${update.name}:${update.actualPaths?.join('、') ?? '解析不了'} → ${update.expectedPaths.join('、')}`);
272
+ }
273
+ else if (update.action === 'rename') {
274
+ lines.push(` ✓ ${update.from} → ${update.name}(只改组头,路径与模板不变)`);
275
+ }
276
+ else if (update.action === 'append') {
277
+ lines.push(` + ${update.name}:追加 ${update.expectedPaths.join('、')}`);
278
+ }
279
+ else {
280
+ lines.push(` · ${update.name}:未改 —— ${update.reason ?? ''}`);
281
+ }
282
+ }
283
+ lines.push(...overlapLines(st));
284
+ for (const warning of fixed.warnings)
285
+ lines.push('⚠️ ' + warning);
286
+ lines.push('(只改插件建的 group 的 paths / 组头;template / extra / 自定义 group 一字未动)');
287
+ return lines.join('\n');
288
+ }
289
+ const lines = [`group 配置:${cfg.notebook}${st.groupsOk ? '(与配置一致)' : ''}`];
290
+ if (!fs.existsSync(path.join(cfg.notebook, '.zk', 'config.toml'))) {
291
+ lines.push('✗ 还没有 .zk/config.toml —— 先跑 zk-kit init');
292
+ return lines.join('\n');
293
+ }
294
+ for (const group of st.groups) {
295
+ if (!group.present) {
296
+ lines.push(group.conflict
297
+ ? `✗ ${group.name}:缺(路径 ${group.expectedPaths.join('、')} 已被 group "${group.conflict}" 占用)`
298
+ : `✗ ${group.name}:缺(期望 ${group.expectedPaths.join('、')})`);
299
+ }
300
+ else if (group.duplicate) {
301
+ lines.push(`⚠️ ${group.name}:重复出现,解析不了`);
302
+ }
303
+ else if (!group.pathsOk) {
304
+ lines.push(`⚠️ ${group.name}:期望 ${group.expectedPaths.join('、')},实际 ${group.actualPaths?.join('、') ?? '解析不了'}` +
305
+ (group.actualPaths === null ? '(可能是多行数组,手动编辑 .zk/config.toml)' : ''));
306
+ }
307
+ else {
308
+ const template = group.templateOk ? '' : ` · template=${group.actualTemplate ?? '(无)'}(配置期望 ${group.expectedTemplate})`;
309
+ lines.push(`✓ ${group.name}:${group.actualPaths?.join('、')}${template}`);
310
+ }
311
+ }
312
+ lines.push(...overlapLines(st));
313
+ lines.push('(dry-run:不改文件;--fix 只改 dsh-zdiary-kit 建的 group 的 paths,写前备份 .zk/config.toml.bak)');
314
+ return lines.join('\n');
315
+ }
239
316
  async function doctor() {
240
317
  const cfg = config();
241
318
  const zk = await resolveZk(cfg);
@@ -245,15 +322,26 @@ async function doctor() {
245
322
  rows.push(`${exists ? '✓' : '✗'} 笔记本:${cfg.notebook}${exists ? '' : '(不是 zk 笔记本 —— 跑 zk-kit init)'}`);
246
323
  const template = path.join(cfg.notebook, '.zk', 'templates', 'daily.md');
247
324
  rows.push(`${fs.existsSync(template) ? '✓' : '✗'} 日记模板:${template}`);
248
- let group = false;
249
- try {
250
- group = new RegExp(`^\\[group\\."?${cfg.dailyGroup}"?\\]`, 'm').test(fs.readFileSync(path.join(cfg.notebook, '.zk', 'config.toml'), 'utf8'));
251
- }
252
- catch {
253
- group = false;
254
- }
255
- rows.push(`${group ? '✓' : '✗'} 日记 group:${cfg.dailyGroup} → ${cfg.dailyDir}/`);
256
325
  const st = structureStatus(cfg);
326
+ for (const group of st.groups) {
327
+ if (!group.present) {
328
+ rows.push(group.conflict
329
+ ? `✗ group ${group.name}:缺(期望 ${group.expectedPaths.join('、')},已被 group "${group.conflict}" 占用;跑 zk-kit groups --fix)`
330
+ : `✗ group ${group.name}:缺(期望 ${group.expectedPaths.join('、')};跑 zk-kit groups --fix)`);
331
+ }
332
+ else if (group.duplicate) {
333
+ rows.push(`⚠️ group ${group.name}:重复出现,解析不了 —— 手动检查 .zk/config.toml`);
334
+ }
335
+ else if (!group.pathsOk) {
336
+ rows.push(`⚠️ group ${group.name}:期望 ${group.expectedPaths.join('、')},实际 ${group.actualPaths?.join('、') ?? '解析不了'}` +
337
+ (group.actualPaths === null ? '(可能是多行数组 —— 手动编辑 .zk/config.toml)' : '(跑 zk-kit groups --fix)'));
338
+ }
339
+ else {
340
+ const templateNote = group.templateOk ? '' : ` · template=${group.actualTemplate ?? '(无)'}`;
341
+ rows.push(`✓ group ${group.name}:${group.actualPaths?.join('、')}${templateNote}`);
342
+ }
343
+ }
344
+ rows.push(...overlapLines(st));
257
345
  const structureOk = st.ready && (!st.agents.required || st.agents.present);
258
346
  const drift = st.mode === 'flat' && st.extra.length
259
347
  ? ` · ⚠️ 盘上有分层目录 ${st.extra.join('、')}:新建笔记会落在 ${cfg.notesDir}/ 根`
@@ -326,7 +414,20 @@ async function main() {
326
414
  const r = await ensureNotebook(cfg, undefined, { withAgents });
327
415
  print(json ? r : `笔记本 ${r.notebook}(结构 ${cfg.structure})\n` +
328
416
  `初始化:${r.initialized ? '是' : '已是笔记本'} · 目录:${r.dirsCreated.length ? '新建 ' + r.dirsCreated.join('、') : '已齐全'}\n` +
329
- `模板:${r.templatesWritten.length ? r.templatesWritten.join(' / ') : '已存在'} · group:${r.groupsAdded.length ? r.groupsAdded.join(' / ') : '已存在'} · AGENTS.md:${r.agentsWritten ? '已写入' : (cfg.structure === 'layered' || withAgents ? '已存在' : '未写(flat 要 --with-agents)')} · WORKFLOW.md:${r.workflowWritten ? '已写入' : (cfg.structure === 'layered' ? '已存在' : 'flat 不写')}`, json);
417
+ `模板:${r.templatesWritten.length ? r.templatesWritten.join(' / ') : '已存在'} · group:${r.groupsAdded.length ? r.groupsAdded.join(' / ') : '已存在'} · AGENTS.md:${r.agentsWritten ? '已写入' : (cfg.structure === 'layered' || withAgents ? '已存在' : '未写(flat 要 --with-agents)')} · WORKFLOW.md:${r.workflowWritten ? '已写入' : (cfg.structure === 'layered' ? '已存在' : 'flat 不写')}` +
418
+ (r.groupWarnings.length ? `\n⚠️ ${r.groupWarnings.join('\n⚠️ ')}` : ''), json);
419
+ return;
420
+ }
421
+ case 'groups': {
422
+ const fix = flags.fix === true || flags.fix === 'true';
423
+ const dryRun = flags['dry-run'] === true || flags['dry-run'] === 'true';
424
+ if (fix && !dryRun) {
425
+ const result = fixGroupConfig(cfg);
426
+ print(json ? { ...structureStatus(cfg), fix: result } : groupsReport(cfg, structureStatus(cfg), result), json);
427
+ return;
428
+ }
429
+ const st = structureStatus(cfg);
430
+ print(json ? { ...st, dryRun: true } : groupsReport(cfg, st, null), json);
330
431
  return;
331
432
  }
332
433
  case 'new': {
@@ -12,6 +12,8 @@
12
12
  * 老配置只有 `notebook`(或 structure 是全局键):读进来一次性迁进 `notebooks.default`,
13
13
  * 之后就不再有双向合并 —— notebooks 存在时,散落的 `notebook` 顶层键只当没看见。
14
14
  */
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
15
17
  import { CFG_FILE, CFG_LOCK, defaultNotebook, expandHome, processWorkspace, resolveInWorkspace } from './paths.js';
16
18
  import { fileStamp } from '../lib/file-stamp.js';
17
19
  import { withFileLockSync } from '../lib/lock.js';
@@ -245,6 +247,30 @@ export function writeConfig(patch, workspace = processWorkspace(), opts = {}) {
245
247
  notebooks[active] = { ...entry, structure: structureOf(patch.structure, 'flat') };
246
248
  }
247
249
  const next = normalizeConfig({ ...merged, notebooks, active }, workspace);
250
+ // archiveDir 是全局项:旧归档目录非空时,任何一本已配置笔记本都不能直接改,
251
+ // 否则切到那本后旧归档不再被排除,废弃笔记会重新进入检索与统计。
252
+ if (next.archiveDir !== current.archiveDir) {
253
+ const checked = new Set();
254
+ for (const info of notebookInfos(next, workspace)) {
255
+ if (checked.has(info.path))
256
+ continue;
257
+ checked.add(info.path);
258
+ const oldAbs = path.join(info.path, current.archiveDir);
259
+ let entries;
260
+ try {
261
+ entries = fs.readdirSync(oldAbs);
262
+ }
263
+ catch (err) {
264
+ // 只有目录不存在才放行;没权限 / 路径类型异常都失败关闭,不能猜它是空的。
265
+ if (err.code === 'ENOENT')
266
+ continue;
267
+ throw err;
268
+ }
269
+ if (entries.length > 0) {
270
+ throw new ArchiveDirChangeError(current.archiveDir, next.archiveDir, oldAbs, entries.length);
271
+ }
272
+ }
273
+ }
248
274
  writeJson(CFG_FILE, toDisk(next));
249
275
  configCache = null;
250
276
  return next;
@@ -261,6 +287,17 @@ export class ConfigConflictError extends Error {
261
287
  this.name = 'ConfigConflictError';
262
288
  }
263
289
  }
290
+ /**
291
+ * archiveDir 从「空目录 / 不存在」改成别的值时被拒。
292
+ * 不是技术限制,是不让「改一个字符串」静默把旧归档放回检索:插件不迁移文件。
293
+ */
294
+ export class ArchiveDirChangeError extends Error {
295
+ constructor(oldDir, newDir, absPath, count) {
296
+ super(`archiveDir 从 "${oldDir}" 改成 "${newDir}" 被拒绝:旧归档目录 ${absPath} 里还有 ${count} 项。\n` +
297
+ '旧归档不会自动迁移,改完会让废弃笔记重新进入检索 —— 先手动迁移,或保持原值。');
298
+ this.name = 'ArchiveDirChangeError';
299
+ }
300
+ }
264
301
  /** 锁内用的干净读取:不吃 configCache,合并基线必须是磁盘上的现状 */
265
302
  function readConfigFresh(workspace) {
266
303
  return normalizeConfig(readJson(CFG_FILE, {}), workspace);
@@ -59,8 +59,8 @@ window.__ModuleLoader__?.load({
59
59
  { group: '目录与 group', key: 'notesDir', label: '笔记子目录', hint: '普通笔记放哪(相对笔记本),默认 notes —— 所有笔记本共用' },
60
60
  { group: '目录与 group', key: 'dailyDir', label: '日记子目录', hint: '日记放哪(相对笔记本),默认 journal;文件名由日期模板生成 —— 所有笔记本共用' },
61
61
  { group: '目录与 group', key: 'dailyGroup', label: '日记 group 名', hint: 'zk 配置里的 [group."…"],默认 daily —— 初始化时会自动补上;所有笔记本共用' },
62
- { group: '目录与 group', key: 'archiveDir', label: '归档目录', hint: 'supersede 之后笔记搬到这里(保留原相对路径,不删除),默认 archive;所有笔记本共用,改动后点「初始化 / 补建」' },
63
- { group: '记忆', key: 'memoryBudgetWords', label: '注入预算(词)', hint: 'AGENTS.md + USER.md + MEMORY.md 的合计上限,默认 500(中文按 2 字 1 词)。超了先丢 MEMORY 尾部整段,并回显截断了多少' },
62
+ { group: '目录与 group', key: 'archiveDir', label: '归档目录', hint: 'supersede 之后笔记搬到这里(保留原相对路径,不删除),默认 archive;所有笔记本共用。旧归档目录非空时拒绝改动 —— 插件不会自动迁移文件' },
63
+ { group: '记忆', key: 'memoryBudgetWords', label: '注入预算(词)', hint: 'AGENTS.md + USER.md + MEMORY.md 的合计上限,默认 500(中文按 2 字 1 词)。超了先丢 MEMORY 里日期最旧的条目(一条日期都没有才退回从尾部丢),并回显截断了多少' },
64
64
  { group: '写入', key: 'defaultTagsText', label: '默认标签', hint: '新笔记自动追加的标签,逗号分隔,不带 #(可空)' },
65
65
  { group: '写入', key: 'maxReadChars', label: 'zk_read 单次上限(字符)', hint: '默认 20000;超了会截断并明确告知模型' },
66
66
  { group: 'zk', key: 'zkPath', label: 'zk 路径(可空)', hint: '空 = 自动找:配置 → $ZK_BIN → PATH → 插件内置(~/.dsh/zdiary/bin)' },
@@ -195,7 +195,7 @@ window.__ModuleLoader__?.load({
195
195
  parts.push('写入 WORKFLOW.md');
196
196
  if (r.configPatched && !(r.templatesWritten && r.templatesWritten.length) && !(r.dirsCreated && r.dirsCreated.length))
197
197
  parts.push('补齐 group');
198
- setOkMsg('✓ ' + parts.join(' · '));
198
+ setOkMsg('✓ ' + parts.join(' · ') + (d.warn ? '\n⚠️ ' + d.warn : ''));
199
199
  }
200
200
  if (name === 'index')
201
201
  setOkMsg('✓ 索引已重建');
@@ -306,6 +306,17 @@ window.__ModuleLoader__?.load({
306
306
  : structure.mode === 'flat' && structure.extra.length
307
307
  ? `盘上有分层目录(${structure.extra.join('、')}),但配置是 flat —— 新建笔记会落在 notes/ 根,不套模板`
308
308
  : '';
309
+ // group 与配置不一致不会自己好:改目录 / 改 dailyGroup 后要显式跑 groups --fix
310
+ const groupBroken = (structure?.groups || []).filter((g) => !g.present || !g.pathsOk);
311
+ // 多行数组 / 重复组等解析失败不是 --fix 能修的;缺 group(present=false)仍可补建
312
+ const groupNeedsManual = groupBroken.some((g) => g.present && g.actualPaths === null);
313
+ // 也可能只是路径互相重叠(配置本身冲突):那时没有「坏掉的组」,只有一条说明
314
+ const groupWarnText = snap?.notebook.exists && structure?.groupsOk === false
315
+ ? groupBroken.length
316
+ ? `配置与 .zk/config.toml 的 group 不一致(${groupBroken.map((g) => g.name).join('、')})`
317
+ : (structure.groupWarnings?.[0] ?? 'group 路径互相重叠')
318
+ : '';
319
+ const configWarn = [structureWarn, groupWarnText].filter(Boolean).join(';');
309
320
  // 底部只留一个按钮:没建过就叫「初始化」,缺东西就叫「补建」,都带上当前笔记本名。
310
321
  // 用已保存的 active 而不是 cfg.active —— 按钮执行的是服务端已落盘的那份配置。
311
322
  const savedActive = snap?.config?.active || cfg.active;
@@ -317,8 +328,13 @@ window.__ModuleLoader__?.load({
317
328
  ? `补建 ${savedActive} 的目录`
318
329
  : `初始化 / 补建 ${savedActive}`;
319
330
  return h('div', { className: 'zdk' }, h('h3', { className: 'zdk-title' }, '知识库(zk)'), h('p', { className: 'zdk-intro' }, '把你的 zk 笔记本接进 DSH:agent 用 zk_* 工具搜索、读写笔记与日记,双链交给 zk 索引。' +
320
- '没装 zk 就让插件装一个 —— 第一次调用工具时会自动建好笔记本,不需要先来这里点任何按钮。'), statusLine ? h('div', { className: 'zdk-hint' }, '📚 ' + statusLine) : null, memoryLine ? h('div', { className: 'zdk-hint' }, '🧠 ' + memoryLine) : null, structureWarn
321
- ? h('div', { className: 'zdk-err' }, '⚠️ ' + structureWarn + ' —— 点底部「' + initLabel + '」')
331
+ '没装 zk 就让插件装一个 —— 第一次调用工具时会自动建好笔记本,不需要先来这里点任何按钮。'), statusLine ? h('div', { className: 'zdk-hint' }, '📚 ' + statusLine) : null, memoryLine ? h('div', { className: 'zdk-hint' }, '🧠 ' + memoryLine) : null, configWarn
332
+ ? h('div', { className: 'zdk-err' }, '⚠️ ' + configWarn +
333
+ (groupBroken.length
334
+ ? groupNeedsManual
335
+ ? ' —— 有 paths 解析不了,请手动编辑 .zk/config.toml'
336
+ : ' —— 跑 zk-kit groups --fix'
337
+ : groupWarnText ? '' : ' —— 点底部「' + initLabel + '」'))
322
338
  : null, h('div', null, h('div', { className: 'zdk-group' }, '笔记本 · 每个笔记本自己的路径与结构'), h('div', { className: 'zdk-row' }, h('div', null, h('div', { className: 'zdk-label' }, '当前笔记本'), h('div', { className: 'zdk-hint' }, '这里是**新会话的默认值**:每个会话第一次用 zk_* 时会把当时的值固定下来,之后各走各的。' +
323
339
  '改这里不会带着已经跑着的会话走 —— 要让某个会话跟过去,在那个会话里说「切到 X 库」(zk_use)。\n' +
324
340
  '路径与结构是每个笔记本自己的;笔记/日记子目录、归档目录、注入预算是全局的。\n' +
@@ -13,7 +13,7 @@ import fs from 'node:fs';
13
13
  import path from 'node:path';
14
14
  import { json, readBody, ROUTE_BASE } from '../../lib/http.js';
15
15
  import { CFG_FILE, processWorkspace } from '../../config/paths.js';
16
- import { config, configStamp, ConfigConflictError, writeConfig } from '../../config/store.js';
16
+ import { ArchiveDirChangeError, config, configStamp, ConfigConflictError, writeConfig } from '../../config/store.js';
17
17
  import { ensureNotebook, structureStatus, writeAgentsTemplate } from '../../lib/notebook.js';
18
18
  import { buildMemoryPayload, formatFileShares } from '../../lib/memory.js';
19
19
  import { installZk, sourceLabel } from '../../lib/install.js';
@@ -121,6 +121,18 @@ export function registerSettings({ route, isTrusted }) {
121
121
  });
122
122
  return;
123
123
  }
124
+ if (err instanceof ArchiveDirChangeError) {
125
+ const latest = config();
126
+ json(res, 400, {
127
+ ok: false,
128
+ error: err.message,
129
+ config: latest,
130
+ configPath: CFG_FILE,
131
+ stamp: configStamp(),
132
+ ...(await snapshot(latest)),
133
+ });
134
+ return;
135
+ }
124
136
  throw err;
125
137
  }
126
138
  const warn = [];
@@ -155,6 +167,10 @@ export function registerSettings({ route, isTrusted }) {
155
167
  if (exists && st.mode === 'flat' && st.extra.length) {
156
168
  warn.push(`盘上有分层目录(${st.extra.join('、')}),但配置是 flat —— 新建笔记会落在 ${next.notesDir}/ 根`);
157
169
  }
170
+ // 改目录不改 group 是最常见的静默坏法:group 的 paths 还指着旧目录,zk 就不按模板归组
171
+ if (exists && !st.groupsOk && st.groupWarnings.length) {
172
+ warn.push('配置与 .zk/config.toml 的 group 不一致:' + st.groupWarnings.join(';'));
173
+ }
158
174
  json(res, 200, { ok: true, config: next, configPath: CFG_FILE, stamp: configStamp(), warn: warn.length ? warn.join(';') : null, ...(await snapshot(next)) });
159
175
  });
160
176
  // ── 状态 ──
@@ -177,7 +193,8 @@ export function registerSettings({ route, isTrusted }) {
177
193
  const cfg = config();
178
194
  try {
179
195
  const result = await ensureNotebook(cfg);
180
- json(res, 200, { ok: true, result, ...(await snapshot(cfg)) });
196
+ const warn = result.groupWarnings.length ? result.groupWarnings.join(';') : null;
197
+ json(res, 200, { ok: true, result, warn, ...(await snapshot(cfg)) });
181
198
  }
182
199
  catch (err) {
183
200
  json(res, 400, { ok: false, error: err instanceof Error ? err.message : String(err) });
@@ -273,20 +290,29 @@ export function registerSettings({ route, isTrusted }) {
273
290
  ok: fs.existsSync(templateFile),
274
291
  detail: fs.existsSync(templateFile) ? templateFile : '缺 .zk/templates/daily.md,点「初始化 / 补建」补上',
275
292
  });
276
- let groupOk = false;
277
- try {
278
- const toml = fs.readFileSync(path.join(cfg.notebook, '.zk', 'config.toml'), 'utf8');
279
- groupOk = new RegExp(`^\\[group\\."?${cfg.dailyGroup}"?\\]`, 'm').test(toml);
280
- }
281
- catch {
282
- groupOk = false;
283
- }
293
+ const st = structureStatus(cfg);
294
+ const dailyGroup = st.groups.find((group) => group.name === cfg.dailyGroup);
295
+ const dailyOk = !!dailyGroup && dailyGroup.present && dailyGroup.pathsOk;
296
+ // 自检覆盖全部期望 group 与路径冲突,不是只看 daily 自己能不能对上
297
+ const groupOk = st.groupsOk;
298
+ const otherBroken = st.groups.filter((group) => group.name !== cfg.dailyGroup && (!group.present || !group.pathsOk));
299
+ const overlapped = st.expectedOverlaps.length > 0 || st.actualOverlaps.length > 0;
284
300
  items.push({
285
301
  name: `日记 group(${cfg.dailyGroup})`,
286
302
  ok: groupOk,
287
- detail: groupOk ? `group."${cfg.dailyGroup}" → ${cfg.dailyDir}/` : '配置里没有这个 group,点「初始化 / 补建」补上',
303
+ detail: !dailyGroup
304
+ ? '当前结构没有这个 group'
305
+ : dailyGroup.present
306
+ ? dailyOk
307
+ ? `group."${cfg.dailyGroup}" → ${dailyGroup.actualPaths?.join('、')}` +
308
+ (otherBroken.length ? `;另有 ${otherBroken.length} 个 group 与配置不一致 —— 跑 zk-kit groups --fix` : '') +
309
+ (overlapped ? ';有 group 共用同一路径,zk 命中哪个模板不确定 —— 跑 zk-kit groups 看详情' : '')
310
+ : `期望 ${dailyGroup.expectedPaths.join('、')},实际 ${dailyGroup.actualPaths?.join('、') ?? '解析不了'}` +
311
+ (dailyGroup.actualPaths === null ? '(可能是多行数组)—— 手动编辑 .zk/config.toml' : ' —— 跑 zk-kit groups --fix')
312
+ : dailyGroup.conflict
313
+ ? `配置里没有这个 group(期望 ${dailyGroup.expectedPaths.join('、')}),路径已被 group "${dailyGroup.conflict}" 占用 —— 跑 zk-kit groups --fix`
314
+ : `配置里没有这个 group(期望 ${dailyGroup.expectedPaths.join('、')}),点「初始化 / 补建」补上`,
288
315
  });
289
- const st = structureStatus(cfg);
290
316
  const drift = st.mode === 'flat' && st.extra.length
291
317
  ? `;盘上有分层目录 ${st.extra.join('、')},新建笔记会落在 ${cfg.notesDir}/ 根`
292
318
  : '';
@@ -18,7 +18,7 @@ import { searchNotes, searchNotesDetailed, createNote, readNote, findNote, appen
18
18
  import { buildMemoryPayload, META_FILES } from '../../lib/memory.js';
19
19
  import { META_NAMES } from '../../lib/meta.js';
20
20
  import { formatLintExtras, formatMemoryLinks, lintNotebook } from '../../lib/lint.js';
21
- import { dreamNotebook } from '../../lib/dream.js';
21
+ import { dreamNotebook, STALE_DAYS } from '../../lib/dream.js';
22
22
  const text = (value) => [{ type: 'text', text: value }];
23
23
  const objSchema = (properties, required) => ({
24
24
  type: 'object',
@@ -79,6 +79,18 @@ const LINT_MEMORY = objSchema({
79
79
  undated: { type: 'number' },
80
80
  retired: { type: 'number' },
81
81
  retiredBroken: { type: 'number' },
82
+ stale: objSchema({
83
+ total: { type: 'number' },
84
+ staleDays: { type: 'number' },
85
+ items: {
86
+ type: 'array',
87
+ items: objSchema({
88
+ entry: { type: 'string' },
89
+ date: { type: 'string' },
90
+ age: { type: 'number' },
91
+ }, ['entry', 'date', 'age']),
92
+ },
93
+ }, ['total', 'staleDays', 'items']),
82
94
  items: {
83
95
  type: 'array',
84
96
  items: objSchema({
@@ -89,7 +101,7 @@ const LINT_MEMORY = objSchema({
89
101
  path: { type: 'string' },
90
102
  }, ['source', 'entry', 'link', 'reason', 'path']),
91
103
  },
92
- }, ['files', 'links', 'total', 'unlinked', 'undated', 'retired', 'retiredBroken', 'items']);
104
+ }, ['files', 'links', 'total', 'unlinked', 'undated', 'retired', 'retiredBroken', 'stale', 'items']);
93
105
  /** frontmatter 缺字段(P2-13) */
94
106
  const LINT_INCOMPLETE = objSchema({
95
107
  total: { type: 'number' },
@@ -916,7 +928,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
916
928
  'frontmatter 解析失败的笔记单列一类:它们进不了索引,别的项统计不到,先修它们再看其余。' +
917
929
  'memoryLinks 查 MEMORY.md / USER.md 里的 [[来源链接]] 是否还指向活笔记(已废弃 / 不存在)—— ' +
918
930
  'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links 看不见;另数没附链接(unlinked)、' +
919
- '没写日期(undated)、已退役(retired)与退役后新结论失效(retiredBroken)的条目。' +
931
+ '没写日期(undated)、已退役(retired)、退役后新结论失效(retiredBroken)与超过 90 天没复核(stale)的条目。' +
920
932
  'incomplete 是 frontmatter 缺 type / status / authority 的笔记:缺失被索引落成空串,机械门会静默失效。' +
921
933
  'tags 查标签卫生(大小写变体 / 单例,标签总数 ≥ 30 才报);template 说根目录 AGENTS.md 是不是当前版本。' +
922
934
  'similarTitles 是「改一两个字」的疑似重复(同目录、二元组相似度 ≥ 0.6):与全等重名分开,只报告。' +
@@ -1025,7 +1037,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1025
1037
  'daily 里没划掉的 Loose ends、被引用最多的笔记。候选带正文摘要(lead)与入链来源(citedBy),方便重放上下文。' +
1026
1038
  'topCited 先按「被日记提到几天」排(使用信号),入链数只作并列次序;没有日记时退化为原排序。' +
1027
1039
  '会读 MEMORY.md:已经晋升过的(`[[链接]]` 命中或条目里写了标题)移出候选、进 alreadyPromoted —— 不会每周原样重复。' +
1040
+ '退役行里的旧标题不再算已晋升,但 `→ [[新结论]]` 仍算。' +
1028
1041
  'backlog 是窗口外仍未晋升的笔记(按被引数),漏做一次不会永久掉队。' +
1042
+ 'memory 给记忆余量(内容词 + 提示 = 总词,余量按总词算,可以为负);retireCandidates 给「可考虑退役」的条目' +
1043
+ '(来源归档 / 不存在、超过 ' + STALE_DAYS + ' 天未复核;显式写 archive/ 的有意引用不算)。' +
1029
1044
  'days 省略时窗口 = 距 DREAMS.md「上次做梦」的天数(没有则 7 天)。' +
1030
1045
  '只返回材料:写 MEMORY.md / DREAMS.md 由你按 AGENTS.md 决定,这个工具不写任何文件。',
1031
1046
  parameters: {
@@ -1041,6 +1056,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1041
1056
  windowDays: { type: 'number' },
1042
1057
  since: { type: 'string' },
1043
1058
  truncated: { type: 'boolean' },
1059
+ memory: objSchema({
1060
+ words: { type: 'number' },
1061
+ totalWords: { type: 'number' },
1062
+ budget: { type: 'number' },
1063
+ headroom: { type: 'number' },
1064
+ }, ['words', 'totalWords', 'budget', 'headroom']),
1044
1065
  counts: objSchema({
1045
1066
  window: { type: 'number' },
1046
1067
  daily: { type: 'number' },
@@ -1076,7 +1097,16 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1076
1097
  items: { type: 'array', items: { type: 'string' } },
1077
1098
  }, ['path', 'date', 'items']),
1078
1099
  },
1079
- }, ['notebook', 'windowDays', 'since', 'truncated', 'counts', 'newNotes', 'alreadyPromoted', 'backlog', 'rejected', 'topCited', 'dailyLooseEnds']),
1100
+ retireCandidates: {
1101
+ type: 'array',
1102
+ items: objSchema({
1103
+ entry: { type: 'string' },
1104
+ date: { type: 'string' },
1105
+ age: { type: 'number' },
1106
+ reason: { type: 'string', enum: ['stale', 'source-missing', 'source-superseded'] },
1107
+ }, ['entry', 'date', 'age', 'reason']),
1108
+ },
1109
+ }, ['notebook', 'windowDays', 'since', 'truncated', 'memory', 'counts', 'newNotes', 'alreadyPromoted', 'backlog', 'rejected', 'topCited', 'dailyLooseEnds', 'retireCandidates']),
1080
1110
  },
1081
1111
  async run(args, env) {
1082
1112
  const cfg = configFor(env.workspace, env.sessionId);
@@ -1090,6 +1120,19 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
1090
1120
  ' 篇(日记 ' + v.counts.daily + ')· 候选 ' + v.counts.candidates + ' · 拒绝 ' + v.counts.rejected +
1091
1121
  ' · 未完成 ' + v.counts.looseEnds + ' · 已晋升 ' + v.counts.promoted + ' · 积压 ' + v.counts.backlog,
1092
1122
  ];
1123
+ // 余量按总词算(框 + 提示 + notice 都算):只报内容词等于说「还有 15 词」,而提示早把它吃完了
1124
+ lines.push('记忆:内容 ' + v.memory.words + '/' + v.memory.budget + ' 词 + 提示 ' +
1125
+ (v.memory.totalWords - v.memory.words) + ' = ' + v.memory.totalWords + ' 词(余 ' + v.memory.headroom + ')');
1126
+ if (v.retireCandidates.length) {
1127
+ lines.push('可考虑退役:');
1128
+ for (const c of v.retireCandidates.slice(0, 10)) {
1129
+ const when = c.date ? c.date + '(' + c.age + ' 天)' : '无日期';
1130
+ const why = c.reason === 'stale'
1131
+ ? '超过 ' + STALE_DAYS + ' 天未复核'
1132
+ : c.reason === 'source-superseded' ? '来源已归档' : '来源不存在';
1133
+ lines.push(' · ' + c.entry + ' — ' + when + ' · ' + why);
1134
+ }
1135
+ }
1093
1136
  if (v.newNotes.length) {
1094
1137
  lines.push('晋升候选:');
1095
1138
  for (const [i, n] of v.newNotes.slice(0, 10).entries()) {
@@ -13,12 +13,12 @@
13
13
  *
14
14
  * 长度是设计约束:AGENTS.md 属于注入预算(默认 500 词,中文 2 字 = 1 词)且**永不截断**,
15
15
  * 模板自己吃掉过半预算,USER / MEMORY 就没位置了 —— 所以这里只留规则,不写教程。
16
- * 目标 ≤190 词(AGENTS_TEMPLATE 实测 186、AGENTS_TEMPLATE_FLAT 实测 88),单测里锁住。
16
+ * 目标 ≤190 词(AGENTS_TEMPLATE 实测 187、AGENTS_TEMPLATE_FLAT 实测 88),单测里锁住。
17
17
  * 首行 `<!-- zdiary-template: vN -->` 是版本标记:lint 据此报告「老库的 AGENTS.md 是旧版」,
18
18
  * 只报告不覆盖(模板允许用户改)。
19
19
  */
20
20
  /** 模板版本:改模板就 +1;lint 用它判断老库是否还在用旧契约(v2:去掉 inbox/) */
21
- export const TEMPLATE_VERSION = 2;
21
+ export const TEMPLATE_VERSION = 3;
22
22
  /** 首行版本标记(实测 4 词);不许带日期 —— 带日期的写法实测 6 词,白花 2 词 */
23
23
  export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
24
24
  export const AGENTS_TEMPLATE = `${TEMPLATE_MARK}
@@ -48,7 +48,7 @@ notes/{concepts,entities,patterns}/ 原子笔记 · archive/ 废弃(不删)
48
48
 
49
49
  每周:DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
50
50
  MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]];退役写 - [superseded YYYY-MM-DD] 旧结论 → [[新结论]],行不删。
51
- 新条目写顶部;超预算从底部往前丢。
51
+ 新条目写顶部;超预算按日期丢最旧的一条。
52
52
  `;
53
53
  /**
54
54
  * flat 结构用的模板:不出现 raw / inbox / archive / WORKFLOW.md 这些 flat 没有的路径。