dsh-zdiary-kit 3.0.1 → 3.2.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 +29 -28
- package/dist/cli.js +34 -26
- package/dist/config/store.js +2 -2
- package/dist/features/readonly/feature.js +26 -13
- package/dist/features/readonly/html.js +1 -0
- package/dist/features/settings/client.js +7 -7
- package/dist/features/settings/feature.js +19 -19
- package/dist/features/zk-tools/feature.js +71 -100
- package/dist/lib/agents-template.js +5 -5
- package/dist/lib/dates.js +15 -0
- package/dist/lib/dream.js +34 -5
- package/dist/lib/lint.js +134 -18
- package/dist/lib/memory.js +42 -42
- package/dist/lib/meta.js +4 -4
- package/dist/lib/notebook.js +17 -13
- package/dist/lib/persona-template.js +14 -14
- package/dist/lib/timeline.js +196 -0
- package/dist/lib/zk.js +22 -5
- package/docs/features/memory.md +28 -25
- package/docs/features/provisioning.md +9 -9
- package/docs/features/readonly.md +8 -5
- package/docs/features/settings.md +11 -11
- package/docs/features/zk-tools.md +40 -14
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* zk 工具(feature 的公共入口):
|
|
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,
|
|
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' },
|
|
@@ -150,8 +178,8 @@ const LINT_TEMPLATE = objSchema({
|
|
|
150
178
|
mismatchDetail: { type: 'string' },
|
|
151
179
|
currentText: { type: 'string' },
|
|
152
180
|
}, ['present', 'version', 'current', 'stale']);
|
|
153
|
-
/**
|
|
154
|
-
const
|
|
181
|
+
/** 人格体检:缺失 / 旧版 / 比插件新 / 标记与内容不符 / 未填占位符(只报告,不覆盖) */
|
|
182
|
+
const LINT_PERSONA = objSchema({
|
|
155
183
|
total: { type: 'number' },
|
|
156
184
|
items: {
|
|
157
185
|
type: 'array',
|
|
@@ -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
|
-
'
|
|
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
|
-
|
|
673
|
+
`整篇重写请用原生 write / edit,别用这个工具。根目录的 ${META_NAMES.join(' / ')} 是 meta 文件,会被拒绝。`,
|
|
706
674
|
parameters: {
|
|
707
675
|
type: 'object',
|
|
708
676
|
properties: {
|
|
@@ -941,7 +909,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
941
909
|
t({
|
|
942
910
|
name: 'zk_context',
|
|
943
911
|
description: '读知识库根目录的长期约定与记忆(AGENTS.md / USER.md / MEMORY.md),按注入预算截断后返回;' +
|
|
944
|
-
'
|
|
912
|
+
'角色人格(PERSONA.md)单独成段、在记忆段之前、不参与截断。' +
|
|
945
913
|
'同时列出已配置的笔记本(名字 / 路径 / 结构 / 当前)。' +
|
|
946
914
|
'宿主支持注入时这些内容每轮已自动进入系统提示;宿主不支持、或想核对「被截断了多少」时用它。',
|
|
947
915
|
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
@@ -956,7 +924,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
956
924
|
tocWords: { type: 'number' },
|
|
957
925
|
totalWords: { type: 'number' },
|
|
958
926
|
overheadWords: { type: 'number' },
|
|
959
|
-
|
|
927
|
+
persona: objSchema({
|
|
960
928
|
present: { type: 'boolean' },
|
|
961
929
|
contentWords: { type: 'number' },
|
|
962
930
|
words: { type: 'number' },
|
|
@@ -995,7 +963,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
995
963
|
retiredWords: { type: 'number' },
|
|
996
964
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
997
965
|
},
|
|
998
|
-
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords', '
|
|
966
|
+
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords', 'persona', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
999
967
|
},
|
|
1000
968
|
async run(_args, env) {
|
|
1001
969
|
// 不 ensureNotebook:读记忆不该依赖 zk,笔记本不存在时就是空载荷
|
|
@@ -1024,15 +992,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1024
992
|
(others.length ? `\n另有:${others.map((n) => `${n.name}(${n.structure})`).join('、')} —— zk_use 切换本会话` : '')
|
|
1025
993
|
: `笔记本「${v.notebook}」`;
|
|
1026
994
|
if (!v.text) {
|
|
1027
|
-
return text(drift + head + `\n\n知识库根目录没有 ${META_FILES.join(' / ')}(或都是空的),也没有 PERSONA.md
|
|
995
|
+
return text(drift + head + `\n\n知识库根目录没有 ${META_FILES.join(' / ')}(或都是空的),也没有 PERSONA.md 人格文件。`);
|
|
1028
996
|
}
|
|
1029
|
-
const
|
|
1030
|
-
? `\n\n
|
|
1031
|
-
`(${v.
|
|
1032
|
-
(v.
|
|
1033
|
-
: '\n\n
|
|
997
|
+
const persona = v.persona?.present
|
|
998
|
+
? `\n\n人格:正文(含标题)${v.persona.contentWords}/${v.persona.budget} 词` +
|
|
999
|
+
`(${v.persona.files.filter((f) => f.present).map((f) => `${f.name} ${f.words} 词`).join(' · ')})` +
|
|
1000
|
+
(v.persona.overBudget ? `,超 ${v.persona.overWords} 词(人格不截断)` : '')
|
|
1001
|
+
: '\n\n人格:未启用(根目录没有 PERSONA.md)';
|
|
1034
1002
|
const totals = `\n\n用量:记忆载荷 ${v.totalWords} 词(预算 ${v.budget})`;
|
|
1035
|
-
return text(drift + head +
|
|
1003
|
+
return text(drift + head + persona + totals + (v.text ? '\n\n' + v.text : ''));
|
|
1036
1004
|
},
|
|
1037
1005
|
}),
|
|
1038
1006
|
t({
|
|
@@ -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;' +
|
|
@@ -1080,9 +1050,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1080
1050
|
incomplete: LINT_INCOMPLETE,
|
|
1081
1051
|
tags: LINT_TAGS,
|
|
1082
1052
|
template: LINT_TEMPLATE,
|
|
1083
|
-
|
|
1053
|
+
persona: LINT_PERSONA,
|
|
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', '
|
|
1056
|
+
}, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'persona', 'timeline', 'indexHint']),
|
|
1086
1057
|
},
|
|
1087
1058
|
async run(args, env) {
|
|
1088
1059
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1172,7 +1143,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1172
1143
|
truncated: { type: 'boolean' },
|
|
1173
1144
|
memory: objSchema({
|
|
1174
1145
|
words: { type: 'number' },
|
|
1175
|
-
|
|
1146
|
+
personaWords: { type: 'number' },
|
|
1176
1147
|
totalWords: { type: 'number' },
|
|
1177
1148
|
budget: { type: 'number' },
|
|
1178
1149
|
headroom: { type: 'number' },
|
|
@@ -1186,7 +1157,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1186
1157
|
retiredWords: { type: 'number' },
|
|
1187
1158
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
1188
1159
|
},
|
|
1189
|
-
}, ['words', '
|
|
1160
|
+
}, ['words', 'personaWords', 'totalWords', 'budget', 'headroom', 'files']),
|
|
1190
1161
|
counts: objSchema({
|
|
1191
1162
|
window: { type: 'number' },
|
|
1192
1163
|
daily: { type: 'number' },
|
|
@@ -1246,12 +1217,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1246
1217
|
' · 未完成 ' + v.counts.looseEnds + ' · 已晋升 ' + v.counts.promoted + ' · 积压 ' + v.counts.backlog,
|
|
1247
1218
|
];
|
|
1248
1219
|
// 余量按记忆侧总词算(框 + 提示 + notice 都算):只报内容词等于说「还有 15 词」,而提示早把它吃完了。
|
|
1249
|
-
//
|
|
1250
|
-
const memoryTotal = v.memory.totalWords - v.memory.
|
|
1220
|
+
// 人格单独注入,先从 totalWords 里扣掉 —— 它不占记忆预算,也不该被叫成「提示」。
|
|
1221
|
+
const memoryTotal = v.memory.totalWords - v.memory.personaWords;
|
|
1251
1222
|
const promptWords = Math.max(0, memoryTotal - v.memory.words);
|
|
1252
1223
|
lines.push('记忆:内容 ' + v.memory.words + '/' + v.memory.budget + ' 词 + 提示 ' + promptWords +
|
|
1253
1224
|
' = ' + memoryTotal + ' 词(余 ' + v.memory.headroom + ')' +
|
|
1254
|
-
(v.memory.
|
|
1225
|
+
(v.memory.personaWords > 0 ? ' · 人格 ' + v.memory.personaWords + ' 词(单独注入,不计入记忆预算)' : ''));
|
|
1255
1226
|
if (v.retireCandidates.length) {
|
|
1256
1227
|
lines.push('可考虑退役:');
|
|
1257
1228
|
for (const c of v.retireCandidates.slice(0, 10)) {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* 首行 `<!-- zdiary-template: vN -->` 是版本标记:lint 据此报告「老库的 AGENTS.md 是旧版」,
|
|
18
18
|
* 只报告不覆盖(模板允许用户改)。
|
|
19
19
|
*/
|
|
20
|
-
/** 模板版本:改模板就 +1;lint
|
|
21
|
-
export const TEMPLATE_VERSION =
|
|
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
|
-
|
|
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)[[来源路径]],先
|
|
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)[[来源路径]],先
|
|
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:
|
|
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 =
|
|
346
|
+
const at = dayMs(noteDate(cfg, n));
|
|
318
347
|
return Number.isFinite(at) && at >= sinceMs;
|
|
319
348
|
})
|
|
320
|
-
.sort((a, b) =>
|
|
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 =
|
|
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:
|
|
400
|
+
dailyLooseEnds.push({ path: note.path, date: noteDate(cfg, note), items });
|
|
372
401
|
}
|
|
373
402
|
}
|
|
374
403
|
// 排序说明(P2-12):先看「被日记提过几天」—— 跨天复现比同一天多次更强;同一天多篇日记
|