dsh-zdiary-kit 0.7.6 → 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 +96 -16
- package/dist/app/plugin.js +54 -20
- package/dist/cli.js +170 -25
- package/dist/config/store.js +37 -0
- package/dist/features/readonly/feature.js +563 -0
- package/dist/features/readonly/html.js +255 -0
- package/dist/features/settings/client.js +32 -9
- package/dist/features/settings/feature.js +71 -17
- package/dist/features/zk-tools/feature.js +228 -42
- package/dist/lib/agents-template.js +49 -11
- package/dist/lib/dream.js +213 -16
- package/dist/lib/http.js +26 -0
- package/dist/lib/lint.js +329 -90
- package/dist/lib/memory-format.js +100 -0
- package/dist/lib/memory.js +201 -24
- package/dist/lib/notebook-config.js +188 -0
- package/dist/lib/notebook.js +357 -21
- package/dist/lib/wikilink.js +77 -0
- package/dist/lib/zk.js +108 -17
- package/docs/features/memory.md +76 -9
- package/docs/features/provisioning.md +47 -9
- package/docs/features/readonly.md +73 -0
- package/docs/features/settings.md +20 -6
- package/docs/features/zk-tools.md +64 -6
- package/package.json +1 -1
|
@@ -14,11 +14,11 @@ import { configFor, pinSession, sessionNotebook, sessionState } from '../../conf
|
|
|
14
14
|
import { defaultNotebook, expandHome, processWorkspace, resolveInWorkspace } from '../../config/paths.js';
|
|
15
15
|
import { S, validateArgs } from '../../lib/tool.js';
|
|
16
16
|
import { ensureNotebook, newNoteDir } from '../../lib/notebook.js';
|
|
17
|
-
import { searchNotes, createNote, readNote, findNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, ZkError, } from '../../lib/zk.js';
|
|
17
|
+
import { searchNotes, searchNotesDetailed, createNote, readNote, findNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, taglessCjkWarning, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, ZkError, } from '../../lib/zk.js';
|
|
18
18
|
import { buildMemoryPayload, META_FILES } from '../../lib/memory.js';
|
|
19
19
|
import { META_NAMES } from '../../lib/meta.js';
|
|
20
|
-
import { formatMemoryLinks, lintNotebook } from '../../lib/lint.js';
|
|
21
|
-
import { dreamNotebook } from '../../lib/dream.js';
|
|
20
|
+
import { formatLintExtras, formatMemoryLinks, lintNotebook } from '../../lib/lint.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',
|
|
@@ -57,12 +57,40 @@ const LINT_DUPLICATE = objSchema({
|
|
|
57
57
|
items: objSchema({ title: { type: 'string' }, paths: { type: 'array', items: { type: 'string' } } }, ['title', 'paths']),
|
|
58
58
|
},
|
|
59
59
|
}, ['total', 'items']);
|
|
60
|
+
/** 疑似重复标题(P2-10):只差一两个字 */
|
|
61
|
+
const LINT_SIMILAR = objSchema({
|
|
62
|
+
total: { type: 'number' },
|
|
63
|
+
truncated: { type: 'boolean' },
|
|
64
|
+
items: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: objSchema({
|
|
67
|
+
titles: { type: 'array', items: { type: 'string' } },
|
|
68
|
+
paths: { type: 'array', items: { type: 'string' } },
|
|
69
|
+
score: { type: 'number' },
|
|
70
|
+
}, ['titles', 'paths', 'score']),
|
|
71
|
+
},
|
|
72
|
+
}, ['total', 'truncated', 'items']);
|
|
60
73
|
/** 记忆层体检:MEMORY.md / USER.md 里的来源链是否还指向活笔记 */
|
|
61
74
|
const LINT_MEMORY = objSchema({
|
|
62
75
|
files: { type: 'number' },
|
|
63
76
|
links: { type: 'number' },
|
|
64
77
|
total: { type: 'number' },
|
|
65
78
|
unlinked: { type: 'number' },
|
|
79
|
+
undated: { type: 'number' },
|
|
80
|
+
retired: { type: 'number' },
|
|
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']),
|
|
66
94
|
items: {
|
|
67
95
|
type: 'array',
|
|
68
96
|
items: objSchema({
|
|
@@ -73,7 +101,68 @@ const LINT_MEMORY = objSchema({
|
|
|
73
101
|
path: { type: 'string' },
|
|
74
102
|
}, ['source', 'entry', 'link', 'reason', 'path']),
|
|
75
103
|
},
|
|
76
|
-
}, ['files', 'links', 'total', 'unlinked', 'items']);
|
|
104
|
+
}, ['files', 'links', 'total', 'unlinked', 'undated', 'retired', 'retiredBroken', 'stale', 'items']);
|
|
105
|
+
/** frontmatter 缺字段(P2-13) */
|
|
106
|
+
const LINT_INCOMPLETE = objSchema({
|
|
107
|
+
total: { type: 'number' },
|
|
108
|
+
truncated: { type: 'boolean' },
|
|
109
|
+
byField: objSchema({
|
|
110
|
+
type: { type: 'number' },
|
|
111
|
+
status: { type: 'number' },
|
|
112
|
+
authority: { type: 'number' },
|
|
113
|
+
}, ['type', 'status', 'authority']),
|
|
114
|
+
items: {
|
|
115
|
+
type: 'array',
|
|
116
|
+
items: objSchema({
|
|
117
|
+
path: { type: 'string' },
|
|
118
|
+
missing: { type: 'array', items: { type: 'string' } },
|
|
119
|
+
}, ['path', 'missing']),
|
|
120
|
+
},
|
|
121
|
+
}, ['total', 'truncated', 'byField', 'items']);
|
|
122
|
+
/** 标签卫生(P2-14) */
|
|
123
|
+
const LINT_TAGS = objSchema({
|
|
124
|
+
total: { type: 'number' },
|
|
125
|
+
reported: { type: 'boolean' },
|
|
126
|
+
caseVariants: objSchema({
|
|
127
|
+
total: { type: 'number' },
|
|
128
|
+
items: {
|
|
129
|
+
type: 'array',
|
|
130
|
+
items: objSchema({
|
|
131
|
+
variants: { type: 'array', items: { type: 'string' } },
|
|
132
|
+
total: { type: 'number' },
|
|
133
|
+
}, ['variants', 'total']),
|
|
134
|
+
},
|
|
135
|
+
}, ['total', 'items']),
|
|
136
|
+
singletons: objSchema({
|
|
137
|
+
total: { type: 'number' },
|
|
138
|
+
items: { type: 'array', items: { type: 'string' } },
|
|
139
|
+
}, ['total', 'items']),
|
|
140
|
+
}, ['total', 'reported', 'caseVariants', 'singletons']);
|
|
141
|
+
/** 模板版本(P2-15) */
|
|
142
|
+
const LINT_TEMPLATE = objSchema({
|
|
143
|
+
present: { type: 'boolean' },
|
|
144
|
+
version: { type: 'number' },
|
|
145
|
+
current: { type: 'number' },
|
|
146
|
+
stale: { type: 'boolean' },
|
|
147
|
+
currentText: { type: 'string' },
|
|
148
|
+
}, ['present', 'version', 'current', 'stale']);
|
|
149
|
+
/** 晋升候选的共用形状:newNotes / alreadyPromoted / backlog 三栏一致 */
|
|
150
|
+
const DREAM_CANDIDATE = objSchema({
|
|
151
|
+
title: { type: 'string' },
|
|
152
|
+
path: { type: 'string' },
|
|
153
|
+
type: { type: 'string' },
|
|
154
|
+
authority: { type: 'string' },
|
|
155
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
156
|
+
created: { type: 'string' },
|
|
157
|
+
lead: { type: 'string' },
|
|
158
|
+
cited: { type: 'number' },
|
|
159
|
+
citedBy: { type: 'array', items: { type: 'string' } },
|
|
160
|
+
promoted: { type: 'boolean' },
|
|
161
|
+
promotedBy: { type: 'string', enum: ['link', 'title', ''] },
|
|
162
|
+
dailyMentions: { type: 'number' },
|
|
163
|
+
daysMentioned: { type: 'number' },
|
|
164
|
+
lastMentioned: { type: 'string' },
|
|
165
|
+
}, ['title', 'path', 'type', 'authority', 'tags', 'created', 'lead', 'cited', 'citedBy', 'promoted', 'promotedBy', 'dailyMentions', 'daysMentioned', 'lastMentioned']);
|
|
77
166
|
/** frontmatter 解析失败:这些笔记不在索引里,所以单列一桶(path 相对笔记本,不带 title) */
|
|
78
167
|
const LINT_PARSE = objSchema({
|
|
79
168
|
total: { type: 'number' },
|
|
@@ -159,11 +248,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
159
248
|
t({
|
|
160
249
|
name: 'zk_search',
|
|
161
250
|
description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 / 孤立笔记),返回标题、相对路径、标签、创建日与摘要。' +
|
|
162
|
-
'找到后用 zk_read 读全文。写笔记前先用它查重。'
|
|
251
|
+
'找到后用 zk_read 读全文。写笔记前先用它查重。' +
|
|
252
|
+
'中文查询会自动并用子串匹配(FTS 不切中文):matchStrategy 说明这次用了 fts / regex / mixed,mixed 表示补到了全文索引漏掉的笔记。',
|
|
163
253
|
parameters: {
|
|
164
254
|
type: 'object',
|
|
165
255
|
properties: {
|
|
166
|
-
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR
|
|
256
|
+
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR;含中文时自动并用子串匹配补漏)'),
|
|
167
257
|
tags: S.arr('按标签过滤(AND:必须同时带这些标签)', S.str('标签名,不带 #')),
|
|
168
258
|
since: S.str('只看这个日期之后创建的笔记,自然语言或 ISO 日期,如 2026-01-01 / "last week"'),
|
|
169
259
|
until: S.str('只看这个日期之前创建的笔记'),
|
|
@@ -178,6 +268,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
178
268
|
schema: objSchema({
|
|
179
269
|
notebook: { type: 'string' },
|
|
180
270
|
count: { type: 'number' },
|
|
271
|
+
matchStrategy: { type: 'string', enum: ['fts', 'regex', 'mixed'] },
|
|
181
272
|
notes: {
|
|
182
273
|
type: 'array',
|
|
183
274
|
items: objSchema({
|
|
@@ -188,12 +279,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
188
279
|
lead: { type: 'string' },
|
|
189
280
|
}, ['title', 'path', 'tags', 'created', 'lead']),
|
|
190
281
|
},
|
|
191
|
-
}, ['notebook', 'count', 'notes']),
|
|
282
|
+
}, ['notebook', 'count', 'matchStrategy', 'notes']),
|
|
192
283
|
},
|
|
193
284
|
async run(args, env) {
|
|
194
285
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
195
286
|
await ensureNotebook(cfg);
|
|
196
|
-
const
|
|
287
|
+
const result = await searchNotesDetailed(cfg, {
|
|
197
288
|
query: args.query ? String(args.query) : undefined,
|
|
198
289
|
tags: Array.isArray(args.tags) ? args.tags.map(String) : undefined,
|
|
199
290
|
since: args.since ? String(args.since) : undefined,
|
|
@@ -205,15 +296,19 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
205
296
|
});
|
|
206
297
|
return {
|
|
207
298
|
notebook: cfg.notebook,
|
|
208
|
-
count: notes.length,
|
|
209
|
-
|
|
299
|
+
count: result.notes.length,
|
|
300
|
+
matchStrategy: result.matchStrategy,
|
|
301
|
+
notes: result.notes.map((n) => ({ title: n.title, path: n.path, tags: n.tags, created: dateOnly(n.created), lead: n.lead })),
|
|
210
302
|
};
|
|
211
303
|
},
|
|
212
304
|
render(_args, value) {
|
|
213
305
|
const v = value;
|
|
214
306
|
if (!v.count)
|
|
215
307
|
return text(`没有匹配的笔记(笔记本 ${v.notebook})`);
|
|
216
|
-
|
|
308
|
+
const how = v.matchStrategy === 'mixed'
|
|
309
|
+
? '(中文:全文 + 子串合并,已补上全文索引漏掉的)'
|
|
310
|
+
: v.matchStrategy === 'regex' ? '(全文无结果,已退回子串匹配)' : '';
|
|
311
|
+
return text(`${v.count} 条(笔记本 ${v.notebook})${how}\n` + v.notes.map(noteLine).join('\n'));
|
|
217
312
|
},
|
|
218
313
|
}),
|
|
219
314
|
t({
|
|
@@ -381,7 +476,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
381
476
|
'要短文件名就传 name(8–14 字中文短语 / 英文小写短横线名):只换文件名,标题和正文一个字不动。' +
|
|
382
477
|
'归档里有同名旧结论不会拦,但会放进 archived(带 supersede-reason):先读它,别把同一个错误结论重新提出来。' +
|
|
383
478
|
'type / authority 只有 layered 模板会写进 frontmatter。tags 会写成 #hashtag;links 里的目标会被追加成 wiki 双链。' +
|
|
384
|
-
'
|
|
479
|
+
'中文笔记如果没有任何标签(入参 / 默认值 / 正文 hashtag 都没有),会在 tagWarning 里提示 —— 只提示,不阻断。' +
|
|
480
|
+
'根目录 meta 文件(AGENTS / USER / MEMORY 等)与 raw/ 、inbox/ 不能写:前者会被当成人写的工作面,后两者会被排除出索引。',
|
|
385
481
|
parameters: {
|
|
386
482
|
type: 'object',
|
|
387
483
|
properties: {
|
|
@@ -408,6 +504,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
408
504
|
links: { type: 'array', items: { type: 'string' } },
|
|
409
505
|
summaryApplied: { type: 'boolean' },
|
|
410
506
|
summaryWarning: { type: 'string' },
|
|
507
|
+
tagWarning: { type: 'string' },
|
|
411
508
|
archived: {
|
|
412
509
|
type: 'array',
|
|
413
510
|
items: objSchema({
|
|
@@ -424,11 +521,14 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
424
521
|
await ensureNotebook(cfg, env.signal);
|
|
425
522
|
const tags = [...new Set([...(cfg.defaultTags ?? []), ...(Array.isArray(args.tags) ? args.tags.map(String) : [])])];
|
|
426
523
|
const type = args.type ? String(args.type) : undefined;
|
|
524
|
+
const title = String(args.title);
|
|
525
|
+
const body = args.body ? String(args.body) : '';
|
|
526
|
+
const content = withTags(body, tags);
|
|
427
527
|
const created = await createNote(cfg, {
|
|
428
|
-
title
|
|
528
|
+
title,
|
|
429
529
|
name: args.name ? String(args.name) : undefined,
|
|
430
530
|
summary: args.summary ? String(args.summary) : undefined,
|
|
431
|
-
content
|
|
531
|
+
content,
|
|
432
532
|
dir: newNoteDir(cfg, { dir: args.dir ? String(args.dir) : undefined, type }),
|
|
433
533
|
group: args.group ? String(args.group) : undefined,
|
|
434
534
|
type,
|
|
@@ -446,6 +546,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
446
546
|
warnings.push(`${target}:${err instanceof Error ? err.message : String(err)}`);
|
|
447
547
|
}
|
|
448
548
|
}
|
|
549
|
+
// 中文没标签:写路径是唯一便宜的修复点(P2-9)。只提示,不阻断。
|
|
550
|
+
const tagWarning = taglessCjkWarning(title, content, tags);
|
|
449
551
|
// 归档同名只是提醒:zk_new 的查重本来就不含 archive,允许复用标题 —— 但要把废弃原因一起交出来
|
|
450
552
|
// (createNote 建之前那次全库扫描已经算好了,这里不再单独跑一次 zk)
|
|
451
553
|
const archived = created.archived;
|
|
@@ -455,6 +557,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
455
557
|
notebook: cfg.notebook, path: created.path, title: created.title, tags, links,
|
|
456
558
|
summaryApplied: created.summaryApplied, archived, warnings,
|
|
457
559
|
...(created.summaryWarning ? { summaryWarning: created.summaryWarning } : {}),
|
|
560
|
+
...(tagWarning ? { tagWarning } : {}),
|
|
458
561
|
};
|
|
459
562
|
},
|
|
460
563
|
render(_args, value) {
|
|
@@ -466,6 +569,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
466
569
|
lines.push('双链:' + v.links.join(' '));
|
|
467
570
|
if (v.summaryWarning)
|
|
468
571
|
lines.push('⚠️ ' + v.summaryWarning);
|
|
572
|
+
if (v.tagWarning)
|
|
573
|
+
lines.push('⚠️ ' + v.tagWarning);
|
|
469
574
|
if (v.archived.length) {
|
|
470
575
|
lines.push('⚠️ 归档里有同名旧结论:' + v.archived.map((h) => h.path + (h.reason ? `(废弃原因:${h.reason})` : '(没有记录废弃原因)')).join(';') +
|
|
471
576
|
' —— 先读它,确认不是同一个结论再复用标题');
|
|
@@ -761,6 +866,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
761
866
|
text: { type: 'string' },
|
|
762
867
|
words: { type: 'number' },
|
|
763
868
|
budget: { type: 'number' },
|
|
869
|
+
ratio: { type: 'number' },
|
|
764
870
|
truncatedWords: { type: 'number' },
|
|
765
871
|
tocWords: { type: 'number' },
|
|
766
872
|
notebook: { type: 'string' },
|
|
@@ -784,7 +890,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
784
890
|
originalWords: { type: 'number' },
|
|
785
891
|
}, ['name', 'present', 'words', 'originalWords']),
|
|
786
892
|
},
|
|
787
|
-
}, ['text', 'words', 'budget', 'truncatedWords', 'tocWords', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
893
|
+
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'tocWords', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
788
894
|
},
|
|
789
895
|
async run(_args, env) {
|
|
790
896
|
// 不 ensureNotebook:读记忆不该依赖 zk,笔记本不存在时就是空载荷
|
|
@@ -821,7 +927,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
821
927
|
description: '给知识库做体检:断链 / 孤儿 / 无标签 / 单向链接 / 陈旧(N 天没改)/ 重名标题,每类最多 50 条并给总数。' +
|
|
822
928
|
'frontmatter 解析失败的笔记单列一类:它们进不了索引,别的项统计不到,先修它们再看其余。' +
|
|
823
929
|
'memoryLinks 查 MEMORY.md / USER.md 里的 [[来源链接]] 是否还指向活笔记(已废弃 / 不存在)—— ' +
|
|
824
|
-
'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links
|
|
930
|
+
'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links 看不见;另数没附链接(unlinked)、' +
|
|
931
|
+
'没写日期(undated)、已退役(retired)、退役后新结论失效(retiredBroken)与超过 90 天没复核(stale)的条目。' +
|
|
932
|
+
'incomplete 是 frontmatter 缺 type / status / authority 的笔记:缺失被索引落成空串,机械门会静默失效。' +
|
|
933
|
+
'tags 查标签卫生(大小写变体 / 单例,标签总数 ≥ 30 才报);template 说根目录 AGENTS.md 是不是当前版本。' +
|
|
934
|
+
'similarTitles 是「改一两个字」的疑似重复(同目录、二元组相似度 ≥ 0.6):与全等重名分开,只报告。' +
|
|
935
|
+
'indexHint=true 表示笔记(不含日记)已到 150 篇而根目录还没有 INDEX.md(只是提示,不生成静态索引)。' +
|
|
825
936
|
'孤儿与无标签不含日记(按天写的日记天然如此,报出来只会淹没真问题)。' +
|
|
826
937
|
'oneWayLinks.items 是缺回链的目标 X(不是来源),from 是没被 X 回链的来源 S;' +
|
|
827
938
|
'edges 是全部单向边数(items 截到 50 条时仍计全量),bodyOnly 是正文引用(不在 ## Links / ## 链接 小节)的单向边数。' +
|
|
@@ -851,8 +962,13 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
851
962
|
tagless: LINT_BUCKET,
|
|
852
963
|
oneWayLinks: LINT_ONE_WAY,
|
|
853
964
|
duplicateTitles: LINT_DUPLICATE,
|
|
965
|
+
similarTitles: LINT_SIMILAR,
|
|
854
966
|
memoryLinks: LINT_MEMORY,
|
|
855
|
-
|
|
967
|
+
incomplete: LINT_INCOMPLETE,
|
|
968
|
+
tags: LINT_TAGS,
|
|
969
|
+
template: LINT_TEMPLATE,
|
|
970
|
+
indexHint: { type: 'boolean' },
|
|
971
|
+
}, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'indexHint']),
|
|
856
972
|
},
|
|
857
973
|
async run(args, env) {
|
|
858
974
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -904,6 +1020,9 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
904
1020
|
const memLine = formatMemoryLinks(v.memoryLinks);
|
|
905
1021
|
if (memLine)
|
|
906
1022
|
lines.push(memLine);
|
|
1023
|
+
lines.push(...formatLintExtras(v));
|
|
1024
|
+
if (v.similarTitles.truncated)
|
|
1025
|
+
lines.push('⚠️ 疑似重复只比较了部分笔记(同目录超过 300 篇或扫描触顶):可能漏报');
|
|
907
1026
|
if (v.truncated)
|
|
908
1027
|
lines.push('⚠️ 笔记数触到扫描上限:结果不完整(只会漏报,不会误报),先归档旧笔记再跑一次');
|
|
909
1028
|
if (oneWay.edgesTruncated)
|
|
@@ -916,11 +1035,18 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
916
1035
|
name: 'zk_dream',
|
|
917
1036
|
description: '整理晋升材料:最近 N 天新增的笔记(机械筛掉 authority=informal 与无标签的,其余作为候选)、' +
|
|
918
1037
|
'daily 里没划掉的 Loose ends、被引用最多的笔记。候选带正文摘要(lead)与入链来源(citedBy),方便重放上下文。' +
|
|
1038
|
+
'topCited 先按「被日记提到几天」排(使用信号),入链数只作并列次序;没有日记时退化为原排序。' +
|
|
1039
|
+
'会读 MEMORY.md:已经晋升过的(`[[链接]]` 命中或条目里写了标题)移出候选、进 alreadyPromoted —— 不会每周原样重复。' +
|
|
1040
|
+
'退役行里的旧标题不再算已晋升,但 `→ [[新结论]]` 仍算。' +
|
|
1041
|
+
'backlog 是窗口外仍未晋升的笔记(按被引数),漏做一次不会永久掉队。' +
|
|
1042
|
+
'memory 给记忆余量(内容词 + 提示 = 总词,余量按总词算,可以为负);retireCandidates 给「可考虑退役」的条目' +
|
|
1043
|
+
'(来源归档 / 不存在、超过 ' + STALE_DAYS + ' 天未复核;显式写 archive/ 的有意引用不算)。' +
|
|
1044
|
+
'days 省略时窗口 = 距 DREAMS.md「上次做梦」的天数(没有则 7 天)。' +
|
|
919
1045
|
'只返回材料:写 MEMORY.md / DREAMS.md 由你按 AGENTS.md 决定,这个工具不写任何文件。',
|
|
920
1046
|
parameters: {
|
|
921
1047
|
type: 'object',
|
|
922
1048
|
properties: {
|
|
923
|
-
days: S.num('看最近多少天(1-365
|
|
1049
|
+
days: S.num('看最近多少天(1-365);省略时 = 距 DREAMS.md「上次做梦」的天数,没有这行才退回 7'),
|
|
924
1050
|
},
|
|
925
1051
|
additionalProperties: false,
|
|
926
1052
|
},
|
|
@@ -930,34 +1056,38 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
930
1056
|
windowDays: { type: 'number' },
|
|
931
1057
|
since: { type: 'string' },
|
|
932
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']),
|
|
933
1065
|
counts: objSchema({
|
|
934
1066
|
window: { type: 'number' },
|
|
935
1067
|
daily: { type: 'number' },
|
|
936
1068
|
candidates: { type: 'number' },
|
|
937
1069
|
rejected: { type: 'number' },
|
|
938
1070
|
looseEnds: { type: 'number' },
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
type: { type: 'string' },
|
|
946
|
-
authority: { type: 'string' },
|
|
947
|
-
tags: { type: 'array', items: { type: 'string' } },
|
|
948
|
-
created: { type: 'string' },
|
|
949
|
-
lead: { type: 'string' },
|
|
950
|
-
cited: { type: 'number' },
|
|
951
|
-
citedBy: { type: 'array', items: { type: 'string' } },
|
|
952
|
-
}, ['title', 'path', 'type', 'authority', 'tags', 'created', 'lead', 'cited', 'citedBy']),
|
|
953
|
-
},
|
|
1071
|
+
promoted: { type: 'number' },
|
|
1072
|
+
backlog: { type: 'number' },
|
|
1073
|
+
}, ['window', 'daily', 'candidates', 'rejected', 'looseEnds', 'promoted', 'backlog']),
|
|
1074
|
+
newNotes: { type: 'array', items: DREAM_CANDIDATE },
|
|
1075
|
+
alreadyPromoted: { type: 'array', items: DREAM_CANDIDATE },
|
|
1076
|
+
backlog: { type: 'array', items: DREAM_CANDIDATE },
|
|
954
1077
|
rejected: {
|
|
955
1078
|
type: 'array',
|
|
956
1079
|
items: objSchema({ title: { type: 'string' }, path: { type: 'string' }, reason: { type: 'string' } }, ['title', 'path', 'reason']),
|
|
957
1080
|
},
|
|
958
1081
|
topCited: {
|
|
959
1082
|
type: 'array',
|
|
960
|
-
items: objSchema({
|
|
1083
|
+
items: objSchema({
|
|
1084
|
+
title: { type: 'string' },
|
|
1085
|
+
path: { type: 'string' },
|
|
1086
|
+
cited: { type: 'number' },
|
|
1087
|
+
dailyMentions: { type: 'number' },
|
|
1088
|
+
daysMentioned: { type: 'number' },
|
|
1089
|
+
lastMentioned: { type: 'string' },
|
|
1090
|
+
}, ['title', 'path', 'cited', 'dailyMentions', 'daysMentioned', 'lastMentioned']),
|
|
961
1091
|
},
|
|
962
1092
|
dailyLooseEnds: {
|
|
963
1093
|
type: 'array',
|
|
@@ -967,7 +1097,16 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
967
1097
|
items: { type: 'array', items: { type: 'string' } },
|
|
968
1098
|
}, ['path', 'date', 'items']),
|
|
969
1099
|
},
|
|
970
|
-
|
|
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']),
|
|
971
1110
|
},
|
|
972
1111
|
async run(args, env) {
|
|
973
1112
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -979,21 +1118,50 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
979
1118
|
const lines = [
|
|
980
1119
|
'做梦:近 ' + v.windowDays + ' 天(自 ' + v.since + ')— 窗口 ' + v.counts.window +
|
|
981
1120
|
' 篇(日记 ' + v.counts.daily + ')· 候选 ' + v.counts.candidates + ' · 拒绝 ' + v.counts.rejected +
|
|
982
|
-
' · 未完成 ' + v.counts.looseEnds,
|
|
1121
|
+
' · 未完成 ' + v.counts.looseEnds + ' · 已晋升 ' + v.counts.promoted + ' · 积压 ' + v.counts.backlog,
|
|
983
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
|
+
}
|
|
984
1136
|
if (v.newNotes.length) {
|
|
985
1137
|
lines.push('晋升候选:');
|
|
986
1138
|
for (const [i, n] of v.newNotes.slice(0, 10).entries()) {
|
|
987
1139
|
const badges = [n.type || '—', n.authority || '—'].join(' · ');
|
|
988
1140
|
const lead = n.lead ? '\n ' + n.lead : '';
|
|
989
1141
|
const citedBy = n.citedBy.length ? '\n 被引:' + n.citedBy.join('、') : '';
|
|
1142
|
+
const used = n.daysMentioned > 0 ? ' · 日记 ' + n.daysMentioned + ' 天' : '';
|
|
990
1143
|
lines.push(' ' + (i + 1) + '. ' + (n.title || n.path) + ' [' + badges + '] ' + n.path +
|
|
991
1144
|
(n.tags.length ? ' · ' + n.tags.map((t) => '#' + t).join(' ') : '') +
|
|
992
|
-
' · 被引 ' + n.cited + lead + citedBy);
|
|
1145
|
+
' · 被引 ' + n.cited + used + lead + citedBy);
|
|
993
1146
|
}
|
|
994
1147
|
if (v.newNotes.length > 10)
|
|
995
1148
|
lines.push(' …还有 ' + (v.newNotes.length - 10) + ' 篇');
|
|
996
1149
|
}
|
|
1150
|
+
if (v.alreadyPromoted.length) {
|
|
1151
|
+
lines.push('已在 MEMORY(不再重复提):');
|
|
1152
|
+
for (const n of v.alreadyPromoted.slice(0, 10)) {
|
|
1153
|
+
lines.push(' · ' + (n.title || n.path) + '(' + n.path + ')· ' + (n.promotedBy === 'link' ? '按链接命中' : '标题出现在条目里'));
|
|
1154
|
+
}
|
|
1155
|
+
if (v.alreadyPromoted.length > 10)
|
|
1156
|
+
lines.push(' …还有 ' + (v.alreadyPromoted.length - 10) + ' 篇');
|
|
1157
|
+
}
|
|
1158
|
+
if (v.backlog.length) {
|
|
1159
|
+
lines.push('窗口外仍未晋升(按被引数):');
|
|
1160
|
+
for (const n of v.backlog.slice(0, 10))
|
|
1161
|
+
lines.push(' · ' + (n.title || n.path) + '(' + n.path + ')· 被引 ' + n.cited);
|
|
1162
|
+
if (v.counts.backlog > v.backlog.length)
|
|
1163
|
+
lines.push(' …还有 ' + (v.counts.backlog - v.backlog.length) + ' 篇');
|
|
1164
|
+
}
|
|
997
1165
|
if (v.rejected.length) {
|
|
998
1166
|
lines.push('机械拒绝(不进候选):');
|
|
999
1167
|
for (const r of v.rejected.slice(0, 10))
|
|
@@ -1008,8 +1176,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1008
1176
|
}
|
|
1009
1177
|
if (v.topCited.length) {
|
|
1010
1178
|
lines.push('被引用最多:');
|
|
1011
|
-
for (const [i, c] of v.topCited.slice(0, 5).entries())
|
|
1012
|
-
lines.push(' ' + (i + 1) + '. ' + (c.title || c.path) + '(' + c.path + ')· ' + c.cited + ' 次'
|
|
1179
|
+
for (const [i, c] of v.topCited.slice(0, 5).entries()) {
|
|
1180
|
+
lines.push(' ' + (i + 1) + '. ' + (c.title || c.path) + '(' + c.path + ')· 被引 ' + c.cited + ' 次' +
|
|
1181
|
+
(c.daysMentioned > 0 ? ' · 日记 ' + c.daysMentioned + ' 天(最近 ' + c.lastMentioned + ')' : ''));
|
|
1182
|
+
}
|
|
1013
1183
|
}
|
|
1014
1184
|
if (!v.newNotes.length && !v.dailyLooseEnds.length && !v.topCited.length)
|
|
1015
1185
|
lines.push('这个窗口里没有新材料。');
|
|
@@ -1021,7 +1191,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1021
1191
|
}),
|
|
1022
1192
|
t({
|
|
1023
1193
|
name: 'zk_stats',
|
|
1024
|
-
description: '看一眼知识库现状:笔记数、标签数、断链数、孤立笔记数、已归档(superseded
|
|
1194
|
+
description: '看一眼知识库现状:笔记数、标签数、断链数、孤立笔记数、已归档(superseded)数,以及顶层目录 / 前 10 个标签的分布(byDir / byTag)。' +
|
|
1195
|
+
'适合开始工作前了解上下文规模;笔记多了以后用它判断该先看哪里(不是排行榜)。',
|
|
1025
1196
|
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
1026
1197
|
output: {
|
|
1027
1198
|
schema: objSchema({
|
|
@@ -1034,7 +1205,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1034
1205
|
orphans: { type: 'number' },
|
|
1035
1206
|
archived: { type: 'number' },
|
|
1036
1207
|
superseded: { type: 'number' },
|
|
1037
|
-
|
|
1208
|
+
byDir: {
|
|
1209
|
+
type: 'array',
|
|
1210
|
+
items: objSchema({ dir: { type: 'string' }, count: { type: 'number' } }, ['dir', 'count']),
|
|
1211
|
+
},
|
|
1212
|
+
byTag: {
|
|
1213
|
+
type: 'array',
|
|
1214
|
+
items: objSchema({ tag: { type: 'string' }, count: { type: 'number' } }, ['tag', 'count']),
|
|
1215
|
+
},
|
|
1216
|
+
}, ['notebook', 'defaultNotebook', 'pinned', 'notes', 'tags', 'brokenLinks', 'orphans', 'archived', 'superseded', 'byDir', 'byTag']),
|
|
1038
1217
|
},
|
|
1039
1218
|
async run(_args, env) {
|
|
1040
1219
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1053,8 +1232,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1053
1232
|
const drift = v.pinned && v.pinned !== v.defaultNotebook
|
|
1054
1233
|
? `\n本会话固定在「${v.pinned}」;全局默认是「${v.defaultNotebook}」(要跟随用 zk_use ${v.defaultNotebook})`
|
|
1055
1234
|
: '';
|
|
1235
|
+
const dirs = v.byDir.length
|
|
1236
|
+
? '\n目录:' + v.byDir.map((d) => `${d.dir === '.' ? '(根目录)' : d.dir} ${d.count}`).join(' · ')
|
|
1237
|
+
: '';
|
|
1238
|
+
const tags = v.byTag.length
|
|
1239
|
+
? '\n标签:' + v.byTag.map((t) => `#${t.tag} ${t.count}`).join(' · ')
|
|
1240
|
+
: '';
|
|
1056
1241
|
return text(`笔记本 ${v.notebook}${drift}\n` +
|
|
1057
|
-
`笔记 ${v.notes} 篇 · 标签 ${v.tags} 个 · 断链 ${v.brokenLinks} 篇 · 孤立 ${v.orphans} 篇 · 归档 ${v.archived} 篇(superseded ${v.superseded})`
|
|
1242
|
+
`笔记 ${v.notes} 篇 · 标签 ${v.tags} 个 · 断链 ${v.brokenLinks} 篇 · 孤立 ${v.orphans} 篇 · 归档 ${v.archived} 篇(superseded ${v.superseded})` +
|
|
1243
|
+
dirs + tags);
|
|
1058
1244
|
},
|
|
1059
1245
|
}),
|
|
1060
1246
|
t({
|
|
@@ -1,45 +1,83 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 根目录 AGENTS.md
|
|
2
|
+
* 根目录 AGENTS.md 模板:初始化时写进 vault,已存在就不碰。
|
|
3
|
+
*
|
|
4
|
+
* 两份模板:layered 用 AGENTS_TEMPLATE(目录 / group / WORKFLOW 那些路径都存在),
|
|
5
|
+
* flat 用 AGENTS_TEMPLATE_FLAT(只有 notes/ + 日记,不出现 raw / inbox / archive / WORKFLOW)。
|
|
6
|
+
* flat 默认不写(0.1.0 的 vault 升级过来必须一个文件都不多),要的人显式 `zk-kit init --with-agents`
|
|
7
|
+
* 或在设置页点「写入 AGENTS.md 模板」—— 否则默认安装既没有约定、也没有周节奏提醒。
|
|
3
8
|
*
|
|
4
9
|
* 为什么单独一个文件:它是「给人读的文档」,不是逻辑;放在这里也方便直接对照
|
|
5
10
|
* docs/features/memory.md 的三条口径(检索词归宿 / 中文必打 tags / 宿主不会自动加载)。
|
|
11
|
+
* 注意别让运行期消息只指向 docs/:插件发布后文档在 profile 的 node_modules 里,agent 够不着;
|
|
12
|
+
* lint 的旧版提示直接带模板全文(见 lib/lint.ts 的 LintTemplateBucket.currentText)。
|
|
6
13
|
*
|
|
7
14
|
* 长度是设计约束:AGENTS.md 属于注入预算(默认 500 词,中文 2 字 = 1 词)且**永不截断**,
|
|
8
15
|
* 模板自己吃掉过半预算,USER / MEMORY 就没位置了 —— 所以这里只留规则,不写教程。
|
|
9
|
-
* 目标
|
|
16
|
+
* 目标 ≤190 词(AGENTS_TEMPLATE 实测 187、AGENTS_TEMPLATE_FLAT 实测 88),单测里锁住。
|
|
17
|
+
* 首行 `<!-- zdiary-template: vN -->` 是版本标记:lint 据此报告「老库的 AGENTS.md 是旧版」,
|
|
18
|
+
* 只报告不覆盖(模板允许用户改)。
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
/** 模板版本:改模板就 +1;lint 用它判断老库是否还在用旧契约(v2:去掉 inbox/) */
|
|
21
|
+
export const TEMPLATE_VERSION = 3;
|
|
22
|
+
/** 首行版本标记(实测 4 词);不许带日期 —— 带日期的写法实测 6 词,白花 2 词 */
|
|
23
|
+
export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
|
|
24
|
+
export const AGENTS_TEMPLATE = `${TEMPLATE_MARK}
|
|
25
|
+
|
|
26
|
+
# 知识库工作约定
|
|
12
27
|
|
|
13
|
-
> zdiary 生成;DSH
|
|
28
|
+
> zdiary 生成;DSH 不会自动加载,插件每轮注入。
|
|
14
29
|
|
|
15
30
|
## 目录
|
|
16
31
|
|
|
17
|
-
raw/ 只读材料 ·
|
|
32
|
+
raw/ 只读材料 · notes/sources/ 来源
|
|
18
33
|
notes/{concepts,entities,patterns}/ 原子笔记 · archive/ 废弃(不删)
|
|
19
34
|
|
|
20
35
|
## 检索词
|
|
21
36
|
|
|
22
37
|
值得检索 → tags 或正文;不值得 → 不写。
|
|
23
|
-
中文必打 tags
|
|
38
|
+
中文必打 tags:全文索引不切中文,只查正文会静默查空、建重复笔记。
|
|
24
39
|
|
|
25
40
|
## 写之前
|
|
26
41
|
|
|
27
42
|
1. zk_query / zk_search 查重(中文查 tags)。
|
|
28
|
-
2. 一条笔记一件事,标题即结论;文件名用 zk_new 的 name
|
|
43
|
+
2. 一条笔记一件事,标题即结论;文件名用 zk_new 的 name(8–14 字);来源给 type=source、结论给 type=concept(目录跟 type 走,别落 notes/ 根),zk_link 相连。
|
|
29
44
|
3. 结论过时用 zk_supersede(默认预演,带 reason):不删文件、不改旧结论。
|
|
30
45
|
4. 改已有笔记前读 WORKFLOW.md:先列清单等确认,再按三分类动手。
|
|
31
46
|
|
|
32
47
|
## 每周
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
每周:DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
|
|
50
|
+
MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]];退役写 - [superseded YYYY-MM-DD] 旧结论 → [[新结论]],行不删。
|
|
51
|
+
新条目写顶部;超预算按日期丢最旧的一条。
|
|
52
|
+
`;
|
|
53
|
+
/**
|
|
54
|
+
* flat 结构用的模板:不出现 raw / inbox / archive / WORKFLOW.md 这些 flat 没有的路径。
|
|
55
|
+
* 目标 ≤90 词 —— 它和服务端那份共用同一笔预算,而 flat 用户往往只是想要「有一个约定」。
|
|
56
|
+
*/
|
|
57
|
+
export const AGENTS_TEMPLATE_FLAT = `${TEMPLATE_MARK}
|
|
58
|
+
|
|
59
|
+
# 知识库工作约定
|
|
60
|
+
|
|
61
|
+
> zdiary 生成;DSH 不会自动加载,插件每轮注入。
|
|
62
|
+
|
|
63
|
+
## 写之前
|
|
64
|
+
|
|
65
|
+
1. zk_search 查重;中文必打 tags(FTS 不切中文)。
|
|
66
|
+
2. 一笔记一件事,标题即结论;文件名 8–14 字。
|
|
67
|
+
3. 结论过时用 zk_supersede(默认预演,带 reason)。
|
|
68
|
+
|
|
69
|
+
## 每周
|
|
70
|
+
|
|
71
|
+
DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
|
|
72
|
+
MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]];退役写 - [superseded] 旧结论 → [[新结论]]。
|
|
37
73
|
`;
|
|
38
74
|
/**
|
|
39
75
|
* 根目录 WORKFLOW.md:只在「要动已有笔记」时才需要读,所以不注入、不计预算。
|
|
40
76
|
* 放进注入的话,AGENTS.md 一膨胀就会挤掉 MEMORY —— 这些规则低频但重要,适合按需读。
|
|
41
77
|
*/
|
|
42
|
-
export const WORKFLOW_TEMPLATE =
|
|
78
|
+
export const WORKFLOW_TEMPLATE = `${TEMPLATE_MARK}
|
|
79
|
+
|
|
80
|
+
# 改笔记的工作流(按需读)
|
|
43
81
|
|
|
44
82
|
> 由 dsh-zdiary-kit 生成。AGENTS.md 只放每轮都要用的规则;这一页在要动已有笔记时才读。
|
|
45
83
|
> 它不进检索,也不要往里追加内容(整篇重写,git diff 可审)。
|