dsh-zdiary-kit 0.7.6 → 0.8.3
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 +67 -16
- package/dist/app/plugin.js +54 -20
- package/dist/cli.js +59 -15
- package/dist/features/readonly/feature.js +563 -0
- package/dist/features/readonly/html.js +255 -0
- package/dist/features/settings/client.js +11 -4
- package/dist/features/settings/feature.js +33 -5
- package/dist/features/zk-tools/feature.js +184 -41
- package/dist/lib/agents-template.js +49 -11
- package/dist/lib/dream.js +145 -16
- package/dist/lib/http.js +26 -0
- package/dist/lib/lint.js +302 -66
- package/dist/lib/memory.js +123 -14
- package/dist/lib/notebook.js +33 -14
- package/dist/lib/wikilink.js +77 -0
- package/dist/lib/zk.js +108 -17
- package/docs/features/memory.md +55 -8
- package/docs/features/provisioning.md +17 -6
- package/docs/features/readonly.md +73 -0
- package/docs/features/settings.md +12 -5
- package/docs/features/zk-tools.md +55 -6
- package/package.json +1 -1
|
@@ -14,10 +14,10 @@ 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';
|
|
20
|
+
import { formatLintExtras, formatMemoryLinks, lintNotebook } from '../../lib/lint.js';
|
|
21
21
|
import { dreamNotebook } from '../../lib/dream.js';
|
|
22
22
|
const text = (value) => [{ type: 'text', text: value }];
|
|
23
23
|
const objSchema = (properties, required) => ({
|
|
@@ -57,12 +57,28 @@ 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' },
|
|
66
82
|
items: {
|
|
67
83
|
type: 'array',
|
|
68
84
|
items: objSchema({
|
|
@@ -73,7 +89,68 @@ const LINT_MEMORY = objSchema({
|
|
|
73
89
|
path: { type: 'string' },
|
|
74
90
|
}, ['source', 'entry', 'link', 'reason', 'path']),
|
|
75
91
|
},
|
|
76
|
-
}, ['files', 'links', 'total', 'unlinked', 'items']);
|
|
92
|
+
}, ['files', 'links', 'total', 'unlinked', 'undated', 'retired', 'retiredBroken', 'items']);
|
|
93
|
+
/** frontmatter 缺字段(P2-13) */
|
|
94
|
+
const LINT_INCOMPLETE = objSchema({
|
|
95
|
+
total: { type: 'number' },
|
|
96
|
+
truncated: { type: 'boolean' },
|
|
97
|
+
byField: objSchema({
|
|
98
|
+
type: { type: 'number' },
|
|
99
|
+
status: { type: 'number' },
|
|
100
|
+
authority: { type: 'number' },
|
|
101
|
+
}, ['type', 'status', 'authority']),
|
|
102
|
+
items: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
items: objSchema({
|
|
105
|
+
path: { type: 'string' },
|
|
106
|
+
missing: { type: 'array', items: { type: 'string' } },
|
|
107
|
+
}, ['path', 'missing']),
|
|
108
|
+
},
|
|
109
|
+
}, ['total', 'truncated', 'byField', 'items']);
|
|
110
|
+
/** 标签卫生(P2-14) */
|
|
111
|
+
const LINT_TAGS = objSchema({
|
|
112
|
+
total: { type: 'number' },
|
|
113
|
+
reported: { type: 'boolean' },
|
|
114
|
+
caseVariants: objSchema({
|
|
115
|
+
total: { type: 'number' },
|
|
116
|
+
items: {
|
|
117
|
+
type: 'array',
|
|
118
|
+
items: objSchema({
|
|
119
|
+
variants: { type: 'array', items: { type: 'string' } },
|
|
120
|
+
total: { type: 'number' },
|
|
121
|
+
}, ['variants', 'total']),
|
|
122
|
+
},
|
|
123
|
+
}, ['total', 'items']),
|
|
124
|
+
singletons: objSchema({
|
|
125
|
+
total: { type: 'number' },
|
|
126
|
+
items: { type: 'array', items: { type: 'string' } },
|
|
127
|
+
}, ['total', 'items']),
|
|
128
|
+
}, ['total', 'reported', 'caseVariants', 'singletons']);
|
|
129
|
+
/** 模板版本(P2-15) */
|
|
130
|
+
const LINT_TEMPLATE = objSchema({
|
|
131
|
+
present: { type: 'boolean' },
|
|
132
|
+
version: { type: 'number' },
|
|
133
|
+
current: { type: 'number' },
|
|
134
|
+
stale: { type: 'boolean' },
|
|
135
|
+
currentText: { type: 'string' },
|
|
136
|
+
}, ['present', 'version', 'current', 'stale']);
|
|
137
|
+
/** 晋升候选的共用形状:newNotes / alreadyPromoted / backlog 三栏一致 */
|
|
138
|
+
const DREAM_CANDIDATE = objSchema({
|
|
139
|
+
title: { type: 'string' },
|
|
140
|
+
path: { type: 'string' },
|
|
141
|
+
type: { type: 'string' },
|
|
142
|
+
authority: { type: 'string' },
|
|
143
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
144
|
+
created: { type: 'string' },
|
|
145
|
+
lead: { type: 'string' },
|
|
146
|
+
cited: { type: 'number' },
|
|
147
|
+
citedBy: { type: 'array', items: { type: 'string' } },
|
|
148
|
+
promoted: { type: 'boolean' },
|
|
149
|
+
promotedBy: { type: 'string', enum: ['link', 'title', ''] },
|
|
150
|
+
dailyMentions: { type: 'number' },
|
|
151
|
+
daysMentioned: { type: 'number' },
|
|
152
|
+
lastMentioned: { type: 'string' },
|
|
153
|
+
}, ['title', 'path', 'type', 'authority', 'tags', 'created', 'lead', 'cited', 'citedBy', 'promoted', 'promotedBy', 'dailyMentions', 'daysMentioned', 'lastMentioned']);
|
|
77
154
|
/** frontmatter 解析失败:这些笔记不在索引里,所以单列一桶(path 相对笔记本,不带 title) */
|
|
78
155
|
const LINT_PARSE = objSchema({
|
|
79
156
|
total: { type: 'number' },
|
|
@@ -159,11 +236,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
159
236
|
t({
|
|
160
237
|
name: 'zk_search',
|
|
161
238
|
description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 / 孤立笔记),返回标题、相对路径、标签、创建日与摘要。' +
|
|
162
|
-
'找到后用 zk_read 读全文。写笔记前先用它查重。'
|
|
239
|
+
'找到后用 zk_read 读全文。写笔记前先用它查重。' +
|
|
240
|
+
'中文查询会自动并用子串匹配(FTS 不切中文):matchStrategy 说明这次用了 fts / regex / mixed,mixed 表示补到了全文索引漏掉的笔记。',
|
|
163
241
|
parameters: {
|
|
164
242
|
type: 'object',
|
|
165
243
|
properties: {
|
|
166
|
-
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR
|
|
244
|
+
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR;含中文时自动并用子串匹配补漏)'),
|
|
167
245
|
tags: S.arr('按标签过滤(AND:必须同时带这些标签)', S.str('标签名,不带 #')),
|
|
168
246
|
since: S.str('只看这个日期之后创建的笔记,自然语言或 ISO 日期,如 2026-01-01 / "last week"'),
|
|
169
247
|
until: S.str('只看这个日期之前创建的笔记'),
|
|
@@ -178,6 +256,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
178
256
|
schema: objSchema({
|
|
179
257
|
notebook: { type: 'string' },
|
|
180
258
|
count: { type: 'number' },
|
|
259
|
+
matchStrategy: { type: 'string', enum: ['fts', 'regex', 'mixed'] },
|
|
181
260
|
notes: {
|
|
182
261
|
type: 'array',
|
|
183
262
|
items: objSchema({
|
|
@@ -188,12 +267,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
188
267
|
lead: { type: 'string' },
|
|
189
268
|
}, ['title', 'path', 'tags', 'created', 'lead']),
|
|
190
269
|
},
|
|
191
|
-
}, ['notebook', 'count', 'notes']),
|
|
270
|
+
}, ['notebook', 'count', 'matchStrategy', 'notes']),
|
|
192
271
|
},
|
|
193
272
|
async run(args, env) {
|
|
194
273
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
195
274
|
await ensureNotebook(cfg);
|
|
196
|
-
const
|
|
275
|
+
const result = await searchNotesDetailed(cfg, {
|
|
197
276
|
query: args.query ? String(args.query) : undefined,
|
|
198
277
|
tags: Array.isArray(args.tags) ? args.tags.map(String) : undefined,
|
|
199
278
|
since: args.since ? String(args.since) : undefined,
|
|
@@ -205,15 +284,19 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
205
284
|
});
|
|
206
285
|
return {
|
|
207
286
|
notebook: cfg.notebook,
|
|
208
|
-
count: notes.length,
|
|
209
|
-
|
|
287
|
+
count: result.notes.length,
|
|
288
|
+
matchStrategy: result.matchStrategy,
|
|
289
|
+
notes: result.notes.map((n) => ({ title: n.title, path: n.path, tags: n.tags, created: dateOnly(n.created), lead: n.lead })),
|
|
210
290
|
};
|
|
211
291
|
},
|
|
212
292
|
render(_args, value) {
|
|
213
293
|
const v = value;
|
|
214
294
|
if (!v.count)
|
|
215
295
|
return text(`没有匹配的笔记(笔记本 ${v.notebook})`);
|
|
216
|
-
|
|
296
|
+
const how = v.matchStrategy === 'mixed'
|
|
297
|
+
? '(中文:全文 + 子串合并,已补上全文索引漏掉的)'
|
|
298
|
+
: v.matchStrategy === 'regex' ? '(全文无结果,已退回子串匹配)' : '';
|
|
299
|
+
return text(`${v.count} 条(笔记本 ${v.notebook})${how}\n` + v.notes.map(noteLine).join('\n'));
|
|
217
300
|
},
|
|
218
301
|
}),
|
|
219
302
|
t({
|
|
@@ -381,7 +464,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
381
464
|
'要短文件名就传 name(8–14 字中文短语 / 英文小写短横线名):只换文件名,标题和正文一个字不动。' +
|
|
382
465
|
'归档里有同名旧结论不会拦,但会放进 archived(带 supersede-reason):先读它,别把同一个错误结论重新提出来。' +
|
|
383
466
|
'type / authority 只有 layered 模板会写进 frontmatter。tags 会写成 #hashtag;links 里的目标会被追加成 wiki 双链。' +
|
|
384
|
-
'
|
|
467
|
+
'中文笔记如果没有任何标签(入参 / 默认值 / 正文 hashtag 都没有),会在 tagWarning 里提示 —— 只提示,不阻断。' +
|
|
468
|
+
'根目录 meta 文件(AGENTS / USER / MEMORY 等)与 raw/ 、inbox/ 不能写:前者会被当成人写的工作面,后两者会被排除出索引。',
|
|
385
469
|
parameters: {
|
|
386
470
|
type: 'object',
|
|
387
471
|
properties: {
|
|
@@ -408,6 +492,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
408
492
|
links: { type: 'array', items: { type: 'string' } },
|
|
409
493
|
summaryApplied: { type: 'boolean' },
|
|
410
494
|
summaryWarning: { type: 'string' },
|
|
495
|
+
tagWarning: { type: 'string' },
|
|
411
496
|
archived: {
|
|
412
497
|
type: 'array',
|
|
413
498
|
items: objSchema({
|
|
@@ -424,11 +509,14 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
424
509
|
await ensureNotebook(cfg, env.signal);
|
|
425
510
|
const tags = [...new Set([...(cfg.defaultTags ?? []), ...(Array.isArray(args.tags) ? args.tags.map(String) : [])])];
|
|
426
511
|
const type = args.type ? String(args.type) : undefined;
|
|
512
|
+
const title = String(args.title);
|
|
513
|
+
const body = args.body ? String(args.body) : '';
|
|
514
|
+
const content = withTags(body, tags);
|
|
427
515
|
const created = await createNote(cfg, {
|
|
428
|
-
title
|
|
516
|
+
title,
|
|
429
517
|
name: args.name ? String(args.name) : undefined,
|
|
430
518
|
summary: args.summary ? String(args.summary) : undefined,
|
|
431
|
-
content
|
|
519
|
+
content,
|
|
432
520
|
dir: newNoteDir(cfg, { dir: args.dir ? String(args.dir) : undefined, type }),
|
|
433
521
|
group: args.group ? String(args.group) : undefined,
|
|
434
522
|
type,
|
|
@@ -446,6 +534,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
446
534
|
warnings.push(`${target}:${err instanceof Error ? err.message : String(err)}`);
|
|
447
535
|
}
|
|
448
536
|
}
|
|
537
|
+
// 中文没标签:写路径是唯一便宜的修复点(P2-9)。只提示,不阻断。
|
|
538
|
+
const tagWarning = taglessCjkWarning(title, content, tags);
|
|
449
539
|
// 归档同名只是提醒:zk_new 的查重本来就不含 archive,允许复用标题 —— 但要把废弃原因一起交出来
|
|
450
540
|
// (createNote 建之前那次全库扫描已经算好了,这里不再单独跑一次 zk)
|
|
451
541
|
const archived = created.archived;
|
|
@@ -455,6 +545,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
455
545
|
notebook: cfg.notebook, path: created.path, title: created.title, tags, links,
|
|
456
546
|
summaryApplied: created.summaryApplied, archived, warnings,
|
|
457
547
|
...(created.summaryWarning ? { summaryWarning: created.summaryWarning } : {}),
|
|
548
|
+
...(tagWarning ? { tagWarning } : {}),
|
|
458
549
|
};
|
|
459
550
|
},
|
|
460
551
|
render(_args, value) {
|
|
@@ -466,6 +557,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
466
557
|
lines.push('双链:' + v.links.join(' '));
|
|
467
558
|
if (v.summaryWarning)
|
|
468
559
|
lines.push('⚠️ ' + v.summaryWarning);
|
|
560
|
+
if (v.tagWarning)
|
|
561
|
+
lines.push('⚠️ ' + v.tagWarning);
|
|
469
562
|
if (v.archived.length) {
|
|
470
563
|
lines.push('⚠️ 归档里有同名旧结论:' + v.archived.map((h) => h.path + (h.reason ? `(废弃原因:${h.reason})` : '(没有记录废弃原因)')).join(';') +
|
|
471
564
|
' —— 先读它,确认不是同一个结论再复用标题');
|
|
@@ -761,6 +854,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
761
854
|
text: { type: 'string' },
|
|
762
855
|
words: { type: 'number' },
|
|
763
856
|
budget: { type: 'number' },
|
|
857
|
+
ratio: { type: 'number' },
|
|
764
858
|
truncatedWords: { type: 'number' },
|
|
765
859
|
tocWords: { type: 'number' },
|
|
766
860
|
notebook: { type: 'string' },
|
|
@@ -784,7 +878,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
784
878
|
originalWords: { type: 'number' },
|
|
785
879
|
}, ['name', 'present', 'words', 'originalWords']),
|
|
786
880
|
},
|
|
787
|
-
}, ['text', 'words', 'budget', 'truncatedWords', 'tocWords', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
881
|
+
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'tocWords', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
788
882
|
},
|
|
789
883
|
async run(_args, env) {
|
|
790
884
|
// 不 ensureNotebook:读记忆不该依赖 zk,笔记本不存在时就是空载荷
|
|
@@ -821,7 +915,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
821
915
|
description: '给知识库做体检:断链 / 孤儿 / 无标签 / 单向链接 / 陈旧(N 天没改)/ 重名标题,每类最多 50 条并给总数。' +
|
|
822
916
|
'frontmatter 解析失败的笔记单列一类:它们进不了索引,别的项统计不到,先修它们再看其余。' +
|
|
823
917
|
'memoryLinks 查 MEMORY.md / USER.md 里的 [[来源链接]] 是否还指向活笔记(已废弃 / 不存在)—— ' +
|
|
824
|
-
'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links
|
|
918
|
+
'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links 看不见;另数没附链接(unlinked)、' +
|
|
919
|
+
'没写日期(undated)、已退役(retired)与退役后新结论失效(retiredBroken)的条目。' +
|
|
920
|
+
'incomplete 是 frontmatter 缺 type / status / authority 的笔记:缺失被索引落成空串,机械门会静默失效。' +
|
|
921
|
+
'tags 查标签卫生(大小写变体 / 单例,标签总数 ≥ 30 才报);template 说根目录 AGENTS.md 是不是当前版本。' +
|
|
922
|
+
'similarTitles 是「改一两个字」的疑似重复(同目录、二元组相似度 ≥ 0.6):与全等重名分开,只报告。' +
|
|
923
|
+
'indexHint=true 表示笔记(不含日记)已到 150 篇而根目录还没有 INDEX.md(只是提示,不生成静态索引)。' +
|
|
825
924
|
'孤儿与无标签不含日记(按天写的日记天然如此,报出来只会淹没真问题)。' +
|
|
826
925
|
'oneWayLinks.items 是缺回链的目标 X(不是来源),from 是没被 X 回链的来源 S;' +
|
|
827
926
|
'edges 是全部单向边数(items 截到 50 条时仍计全量),bodyOnly 是正文引用(不在 ## Links / ## 链接 小节)的单向边数。' +
|
|
@@ -851,8 +950,13 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
851
950
|
tagless: LINT_BUCKET,
|
|
852
951
|
oneWayLinks: LINT_ONE_WAY,
|
|
853
952
|
duplicateTitles: LINT_DUPLICATE,
|
|
953
|
+
similarTitles: LINT_SIMILAR,
|
|
854
954
|
memoryLinks: LINT_MEMORY,
|
|
855
|
-
|
|
955
|
+
incomplete: LINT_INCOMPLETE,
|
|
956
|
+
tags: LINT_TAGS,
|
|
957
|
+
template: LINT_TEMPLATE,
|
|
958
|
+
indexHint: { type: 'boolean' },
|
|
959
|
+
}, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'indexHint']),
|
|
856
960
|
},
|
|
857
961
|
async run(args, env) {
|
|
858
962
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -904,6 +1008,9 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
904
1008
|
const memLine = formatMemoryLinks(v.memoryLinks);
|
|
905
1009
|
if (memLine)
|
|
906
1010
|
lines.push(memLine);
|
|
1011
|
+
lines.push(...formatLintExtras(v));
|
|
1012
|
+
if (v.similarTitles.truncated)
|
|
1013
|
+
lines.push('⚠️ 疑似重复只比较了部分笔记(同目录超过 300 篇或扫描触顶):可能漏报');
|
|
907
1014
|
if (v.truncated)
|
|
908
1015
|
lines.push('⚠️ 笔记数触到扫描上限:结果不完整(只会漏报,不会误报),先归档旧笔记再跑一次');
|
|
909
1016
|
if (oneWay.edgesTruncated)
|
|
@@ -916,11 +1023,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
916
1023
|
name: 'zk_dream',
|
|
917
1024
|
description: '整理晋升材料:最近 N 天新增的笔记(机械筛掉 authority=informal 与无标签的,其余作为候选)、' +
|
|
918
1025
|
'daily 里没划掉的 Loose ends、被引用最多的笔记。候选带正文摘要(lead)与入链来源(citedBy),方便重放上下文。' +
|
|
1026
|
+
'topCited 先按「被日记提到几天」排(使用信号),入链数只作并列次序;没有日记时退化为原排序。' +
|
|
1027
|
+
'会读 MEMORY.md:已经晋升过的(`[[链接]]` 命中或条目里写了标题)移出候选、进 alreadyPromoted —— 不会每周原样重复。' +
|
|
1028
|
+
'backlog 是窗口外仍未晋升的笔记(按被引数),漏做一次不会永久掉队。' +
|
|
1029
|
+
'days 省略时窗口 = 距 DREAMS.md「上次做梦」的天数(没有则 7 天)。' +
|
|
919
1030
|
'只返回材料:写 MEMORY.md / DREAMS.md 由你按 AGENTS.md 决定,这个工具不写任何文件。',
|
|
920
1031
|
parameters: {
|
|
921
1032
|
type: 'object',
|
|
922
1033
|
properties: {
|
|
923
|
-
days: S.num('看最近多少天(1-365
|
|
1034
|
+
days: S.num('看最近多少天(1-365);省略时 = 距 DREAMS.md「上次做梦」的天数,没有这行才退回 7'),
|
|
924
1035
|
},
|
|
925
1036
|
additionalProperties: false,
|
|
926
1037
|
},
|
|
@@ -936,28 +1047,26 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
936
1047
|
candidates: { type: 'number' },
|
|
937
1048
|
rejected: { type: 'number' },
|
|
938
1049
|
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
|
-
},
|
|
1050
|
+
promoted: { type: 'number' },
|
|
1051
|
+
backlog: { type: 'number' },
|
|
1052
|
+
}, ['window', 'daily', 'candidates', 'rejected', 'looseEnds', 'promoted', 'backlog']),
|
|
1053
|
+
newNotes: { type: 'array', items: DREAM_CANDIDATE },
|
|
1054
|
+
alreadyPromoted: { type: 'array', items: DREAM_CANDIDATE },
|
|
1055
|
+
backlog: { type: 'array', items: DREAM_CANDIDATE },
|
|
954
1056
|
rejected: {
|
|
955
1057
|
type: 'array',
|
|
956
1058
|
items: objSchema({ title: { type: 'string' }, path: { type: 'string' }, reason: { type: 'string' } }, ['title', 'path', 'reason']),
|
|
957
1059
|
},
|
|
958
1060
|
topCited: {
|
|
959
1061
|
type: 'array',
|
|
960
|
-
items: objSchema({
|
|
1062
|
+
items: objSchema({
|
|
1063
|
+
title: { type: 'string' },
|
|
1064
|
+
path: { type: 'string' },
|
|
1065
|
+
cited: { type: 'number' },
|
|
1066
|
+
dailyMentions: { type: 'number' },
|
|
1067
|
+
daysMentioned: { type: 'number' },
|
|
1068
|
+
lastMentioned: { type: 'string' },
|
|
1069
|
+
}, ['title', 'path', 'cited', 'dailyMentions', 'daysMentioned', 'lastMentioned']),
|
|
961
1070
|
},
|
|
962
1071
|
dailyLooseEnds: {
|
|
963
1072
|
type: 'array',
|
|
@@ -967,7 +1076,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
967
1076
|
items: { type: 'array', items: { type: 'string' } },
|
|
968
1077
|
}, ['path', 'date', 'items']),
|
|
969
1078
|
},
|
|
970
|
-
}, ['notebook', 'windowDays', 'since', 'truncated', 'counts', 'newNotes', 'rejected', 'topCited', 'dailyLooseEnds']),
|
|
1079
|
+
}, ['notebook', 'windowDays', 'since', 'truncated', 'counts', 'newNotes', 'alreadyPromoted', 'backlog', 'rejected', 'topCited', 'dailyLooseEnds']),
|
|
971
1080
|
},
|
|
972
1081
|
async run(args, env) {
|
|
973
1082
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -979,7 +1088,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
979
1088
|
const lines = [
|
|
980
1089
|
'做梦:近 ' + v.windowDays + ' 天(自 ' + v.since + ')— 窗口 ' + v.counts.window +
|
|
981
1090
|
' 篇(日记 ' + v.counts.daily + ')· 候选 ' + v.counts.candidates + ' · 拒绝 ' + v.counts.rejected +
|
|
982
|
-
' · 未完成 ' + v.counts.looseEnds,
|
|
1091
|
+
' · 未完成 ' + v.counts.looseEnds + ' · 已晋升 ' + v.counts.promoted + ' · 积压 ' + v.counts.backlog,
|
|
983
1092
|
];
|
|
984
1093
|
if (v.newNotes.length) {
|
|
985
1094
|
lines.push('晋升候选:');
|
|
@@ -987,13 +1096,29 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
987
1096
|
const badges = [n.type || '—', n.authority || '—'].join(' · ');
|
|
988
1097
|
const lead = n.lead ? '\n ' + n.lead : '';
|
|
989
1098
|
const citedBy = n.citedBy.length ? '\n 被引:' + n.citedBy.join('、') : '';
|
|
1099
|
+
const used = n.daysMentioned > 0 ? ' · 日记 ' + n.daysMentioned + ' 天' : '';
|
|
990
1100
|
lines.push(' ' + (i + 1) + '. ' + (n.title || n.path) + ' [' + badges + '] ' + n.path +
|
|
991
1101
|
(n.tags.length ? ' · ' + n.tags.map((t) => '#' + t).join(' ') : '') +
|
|
992
|
-
' · 被引 ' + n.cited + lead + citedBy);
|
|
1102
|
+
' · 被引 ' + n.cited + used + lead + citedBy);
|
|
993
1103
|
}
|
|
994
1104
|
if (v.newNotes.length > 10)
|
|
995
1105
|
lines.push(' …还有 ' + (v.newNotes.length - 10) + ' 篇');
|
|
996
1106
|
}
|
|
1107
|
+
if (v.alreadyPromoted.length) {
|
|
1108
|
+
lines.push('已在 MEMORY(不再重复提):');
|
|
1109
|
+
for (const n of v.alreadyPromoted.slice(0, 10)) {
|
|
1110
|
+
lines.push(' · ' + (n.title || n.path) + '(' + n.path + ')· ' + (n.promotedBy === 'link' ? '按链接命中' : '标题出现在条目里'));
|
|
1111
|
+
}
|
|
1112
|
+
if (v.alreadyPromoted.length > 10)
|
|
1113
|
+
lines.push(' …还有 ' + (v.alreadyPromoted.length - 10) + ' 篇');
|
|
1114
|
+
}
|
|
1115
|
+
if (v.backlog.length) {
|
|
1116
|
+
lines.push('窗口外仍未晋升(按被引数):');
|
|
1117
|
+
for (const n of v.backlog.slice(0, 10))
|
|
1118
|
+
lines.push(' · ' + (n.title || n.path) + '(' + n.path + ')· 被引 ' + n.cited);
|
|
1119
|
+
if (v.counts.backlog > v.backlog.length)
|
|
1120
|
+
lines.push(' …还有 ' + (v.counts.backlog - v.backlog.length) + ' 篇');
|
|
1121
|
+
}
|
|
997
1122
|
if (v.rejected.length) {
|
|
998
1123
|
lines.push('机械拒绝(不进候选):');
|
|
999
1124
|
for (const r of v.rejected.slice(0, 10))
|
|
@@ -1008,8 +1133,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1008
1133
|
}
|
|
1009
1134
|
if (v.topCited.length) {
|
|
1010
1135
|
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 + ' 次'
|
|
1136
|
+
for (const [i, c] of v.topCited.slice(0, 5).entries()) {
|
|
1137
|
+
lines.push(' ' + (i + 1) + '. ' + (c.title || c.path) + '(' + c.path + ')· 被引 ' + c.cited + ' 次' +
|
|
1138
|
+
(c.daysMentioned > 0 ? ' · 日记 ' + c.daysMentioned + ' 天(最近 ' + c.lastMentioned + ')' : ''));
|
|
1139
|
+
}
|
|
1013
1140
|
}
|
|
1014
1141
|
if (!v.newNotes.length && !v.dailyLooseEnds.length && !v.topCited.length)
|
|
1015
1142
|
lines.push('这个窗口里没有新材料。');
|
|
@@ -1021,7 +1148,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1021
1148
|
}),
|
|
1022
1149
|
t({
|
|
1023
1150
|
name: 'zk_stats',
|
|
1024
|
-
description: '看一眼知识库现状:笔记数、标签数、断链数、孤立笔记数、已归档(superseded
|
|
1151
|
+
description: '看一眼知识库现状:笔记数、标签数、断链数、孤立笔记数、已归档(superseded)数,以及顶层目录 / 前 10 个标签的分布(byDir / byTag)。' +
|
|
1152
|
+
'适合开始工作前了解上下文规模;笔记多了以后用它判断该先看哪里(不是排行榜)。',
|
|
1025
1153
|
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
1026
1154
|
output: {
|
|
1027
1155
|
schema: objSchema({
|
|
@@ -1034,7 +1162,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1034
1162
|
orphans: { type: 'number' },
|
|
1035
1163
|
archived: { type: 'number' },
|
|
1036
1164
|
superseded: { type: 'number' },
|
|
1037
|
-
|
|
1165
|
+
byDir: {
|
|
1166
|
+
type: 'array',
|
|
1167
|
+
items: objSchema({ dir: { type: 'string' }, count: { type: 'number' } }, ['dir', 'count']),
|
|
1168
|
+
},
|
|
1169
|
+
byTag: {
|
|
1170
|
+
type: 'array',
|
|
1171
|
+
items: objSchema({ tag: { type: 'string' }, count: { type: 'number' } }, ['tag', 'count']),
|
|
1172
|
+
},
|
|
1173
|
+
}, ['notebook', 'defaultNotebook', 'pinned', 'notes', 'tags', 'brokenLinks', 'orphans', 'archived', 'superseded', 'byDir', 'byTag']),
|
|
1038
1174
|
},
|
|
1039
1175
|
async run(_args, env) {
|
|
1040
1176
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1053,8 +1189,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1053
1189
|
const drift = v.pinned && v.pinned !== v.defaultNotebook
|
|
1054
1190
|
? `\n本会话固定在「${v.pinned}」;全局默认是「${v.defaultNotebook}」(要跟随用 zk_use ${v.defaultNotebook})`
|
|
1055
1191
|
: '';
|
|
1192
|
+
const dirs = v.byDir.length
|
|
1193
|
+
? '\n目录:' + v.byDir.map((d) => `${d.dir === '.' ? '(根目录)' : d.dir} ${d.count}`).join(' · ')
|
|
1194
|
+
: '';
|
|
1195
|
+
const tags = v.byTag.length
|
|
1196
|
+
? '\n标签:' + v.byTag.map((t) => `#${t.tag} ${t.count}`).join(' · ')
|
|
1197
|
+
: '';
|
|
1056
1198
|
return text(`笔记本 ${v.notebook}${drift}\n` +
|
|
1057
|
-
`笔记 ${v.notes} 篇 · 标签 ${v.tags} 个 · 断链 ${v.brokenLinks} 篇 · 孤立 ${v.orphans} 篇 · 归档 ${v.archived} 篇(superseded ${v.superseded})`
|
|
1199
|
+
`笔记 ${v.notes} 篇 · 标签 ${v.tags} 个 · 断链 ${v.brokenLinks} 篇 · 孤立 ${v.orphans} 篇 · 归档 ${v.archived} 篇(superseded ${v.superseded})` +
|
|
1200
|
+
dirs + tags);
|
|
1058
1201
|
},
|
|
1059
1202
|
}),
|
|
1060
1203
|
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 实测 186、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 = 2;
|
|
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 可审)。
|