dsh-zdiary-kit 3.1.0 → 3.3.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 +17 -17
- package/dist/cli.js +26 -26
- package/dist/config/store.js +2 -2
- package/dist/features/readonly/feature.js +30 -13
- package/dist/features/settings/client.js +5 -5
- package/dist/features/settings/feature.js +19 -19
- package/dist/features/zk-tools/feature.js +40 -19
- package/dist/lib/agents-template.js +11 -1
- package/dist/lib/lint.js +36 -73
- package/dist/lib/memory-format.js +23 -0
- package/dist/lib/memory.js +147 -73
- package/dist/lib/meta.js +4 -4
- package/dist/lib/notebook.js +10 -10
- package/dist/lib/persona-template.js +14 -14
- package/dist/lib/similar.js +103 -0
- package/dist/lib/zk.js +10 -6
- package/docs/features/memory.md +48 -25
- package/docs/features/provisioning.md +9 -9
- package/docs/features/readonly.md +10 -6
- package/docs/features/settings.md +11 -11
- package/docs/features/zk-tools.md +18 -10
- package/package.json +1 -1
|
@@ -178,8 +178,8 @@ const LINT_TEMPLATE = objSchema({
|
|
|
178
178
|
mismatchDetail: { type: 'string' },
|
|
179
179
|
currentText: { type: 'string' },
|
|
180
180
|
}, ['present', 'version', 'current', 'stale']);
|
|
181
|
-
/**
|
|
182
|
-
const
|
|
181
|
+
/** 人格体检:缺失 / 旧版 / 比插件新 / 标记与内容不符 / 未填占位符(只报告,不覆盖) */
|
|
182
|
+
const LINT_PERSONA = objSchema({
|
|
183
183
|
total: { type: 'number' },
|
|
184
184
|
items: {
|
|
185
185
|
type: 'array',
|
|
@@ -526,6 +526,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
526
526
|
'归档里有同名旧结论不会拦,但会放进 archived(带 supersede-reason):先读它,别把同一个错误结论重新提出来。' +
|
|
527
527
|
'type / authority 只有 layered 模板会写进 frontmatter。tags 会写成 #hashtag;links 里的目标会被追加成 wiki 双链。' +
|
|
528
528
|
'中文笔记如果没有任何标签(入参 / 默认值 / 正文 hashtag 都没有),会在 tagWarning 里提示 —— 只提示,不阻断。' +
|
|
529
|
+
'同目录里有「改一两个字」的相似标题时会放进 similar(带分数):只提示,不阻断,也不自动建链接。' +
|
|
529
530
|
'根目录 meta 文件(AGENTS / USER / MEMORY 等)与 raw/ 、inbox/ 不能写:前者会被当成人写的工作面,后两者会被排除出索引。',
|
|
530
531
|
parameters: {
|
|
531
532
|
type: 'object',
|
|
@@ -563,6 +564,14 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
563
564
|
reason: { type: 'string' },
|
|
564
565
|
}, ['path', 'title', 'reason']),
|
|
565
566
|
},
|
|
567
|
+
similar: {
|
|
568
|
+
type: 'array',
|
|
569
|
+
items: objSchema({
|
|
570
|
+
title: { type: 'string' },
|
|
571
|
+
path: { type: 'string' },
|
|
572
|
+
score: { type: 'number' },
|
|
573
|
+
}, ['title', 'path', 'score']),
|
|
574
|
+
},
|
|
566
575
|
warnings: { type: 'array', items: { type: 'string' } },
|
|
567
576
|
}, ['notebook', 'path', 'absPath', 'title', 'tags', 'links', 'summaryApplied', 'archived', 'warnings']),
|
|
568
577
|
},
|
|
@@ -606,6 +615,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
606
615
|
return {
|
|
607
616
|
notebook: cfg.notebook, path: created.path, absPath: created.absPath, title: created.title, tags, links,
|
|
608
617
|
summaryApplied: created.summaryApplied, archived, warnings,
|
|
618
|
+
...(created.similar.length ? { similar: created.similar } : {}),
|
|
609
619
|
...(created.summaryWarning ? { summaryWarning: created.summaryWarning } : {}),
|
|
610
620
|
...(tagWarning ? { tagWarning } : {}),
|
|
611
621
|
};
|
|
@@ -621,6 +631,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
621
631
|
lines.push('⚠️ ' + v.summaryWarning);
|
|
622
632
|
if (v.tagWarning)
|
|
623
633
|
lines.push('⚠️ ' + v.tagWarning);
|
|
634
|
+
if (v.similar?.length) {
|
|
635
|
+
lines.push('⚠️ 疑似已有:' + v.similar.map((s) => `${s.title}(${s.path},${s.score.toFixed(2)})`).join('、') +
|
|
636
|
+
' —— 先 read 确认是不是同一条;要合并就 zk_supersede,不要直接再写一遍');
|
|
637
|
+
}
|
|
624
638
|
if (v.archived.length) {
|
|
625
639
|
lines.push('⚠️ 归档里有同名旧结论:' + v.archived.map((h) => h.path + (h.reason ? `(废弃原因:${h.reason})` : '(没有记录废弃原因)')).join(';') +
|
|
626
640
|
' —— 先读它,确认不是同一个结论再复用标题');
|
|
@@ -909,7 +923,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
909
923
|
t({
|
|
910
924
|
name: 'zk_context',
|
|
911
925
|
description: '读知识库根目录的长期约定与记忆(AGENTS.md / USER.md / MEMORY.md),按注入预算截断后返回;' +
|
|
912
|
-
'
|
|
926
|
+
'角色人格(PERSONA.md)单独成段、在记忆段之前、不参与截断。' +
|
|
913
927
|
'同时列出已配置的笔记本(名字 / 路径 / 结构 / 当前)。' +
|
|
914
928
|
'宿主支持注入时这些内容每轮已自动进入系统提示;宿主不支持、或想核对「被截断了多少」时用它。',
|
|
915
929
|
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
@@ -924,7 +938,14 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
924
938
|
tocWords: { type: 'number' },
|
|
925
939
|
totalWords: { type: 'number' },
|
|
926
940
|
overheadWords: { type: 'number' },
|
|
927
|
-
|
|
941
|
+
// 格式债 / 模板版本:只读元数据,比 memoryUsage 的投影早一步就能拿到
|
|
942
|
+
formatDebt: objSchema({
|
|
943
|
+
total: { type: 'number' },
|
|
944
|
+
undated: { type: 'number' },
|
|
945
|
+
unlinked: { type: 'number' },
|
|
946
|
+
}, ['total', 'undated', 'unlinked']),
|
|
947
|
+
templateVersion: { type: 'number' },
|
|
948
|
+
persona: objSchema({
|
|
928
949
|
present: { type: 'boolean' },
|
|
929
950
|
contentWords: { type: 'number' },
|
|
930
951
|
words: { type: 'number' },
|
|
@@ -963,7 +984,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
963
984
|
retiredWords: { type: 'number' },
|
|
964
985
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
965
986
|
},
|
|
966
|
-
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords', '
|
|
987
|
+
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords', 'formatDebt', 'templateVersion', 'persona', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
967
988
|
},
|
|
968
989
|
async run(_args, env) {
|
|
969
990
|
// 不 ensureNotebook:读记忆不该依赖 zk,笔记本不存在时就是空载荷
|
|
@@ -992,15 +1013,15 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
992
1013
|
(others.length ? `\n另有:${others.map((n) => `${n.name}(${n.structure})`).join('、')} —— zk_use 切换本会话` : '')
|
|
993
1014
|
: `笔记本「${v.notebook}」`;
|
|
994
1015
|
if (!v.text) {
|
|
995
|
-
return text(drift + head + `\n\n知识库根目录没有 ${META_FILES.join(' / ')}(或都是空的),也没有 PERSONA.md
|
|
1016
|
+
return text(drift + head + `\n\n知识库根目录没有 ${META_FILES.join(' / ')}(或都是空的),也没有 PERSONA.md 人格文件。`);
|
|
996
1017
|
}
|
|
997
|
-
const
|
|
998
|
-
? `\n\n
|
|
999
|
-
`(${v.
|
|
1000
|
-
(v.
|
|
1001
|
-
: '\n\n
|
|
1018
|
+
const persona = v.persona?.present
|
|
1019
|
+
? `\n\n人格:正文(含标题)${v.persona.contentWords}/${v.persona.budget} 词` +
|
|
1020
|
+
`(${v.persona.files.filter((f) => f.present).map((f) => `${f.name} ${f.words} 词`).join(' · ')})` +
|
|
1021
|
+
(v.persona.overBudget ? `,超 ${v.persona.overWords} 词(人格不截断)` : '')
|
|
1022
|
+
: '\n\n人格:未启用(根目录没有 PERSONA.md)';
|
|
1002
1023
|
const totals = `\n\n用量:记忆载荷 ${v.totalWords} 词(预算 ${v.budget})`;
|
|
1003
|
-
return text(drift + head +
|
|
1024
|
+
return text(drift + head + persona + totals + (v.text ? '\n\n' + v.text : ''));
|
|
1004
1025
|
},
|
|
1005
1026
|
}),
|
|
1006
1027
|
t({
|
|
@@ -1050,10 +1071,10 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1050
1071
|
incomplete: LINT_INCOMPLETE,
|
|
1051
1072
|
tags: LINT_TAGS,
|
|
1052
1073
|
template: LINT_TEMPLATE,
|
|
1053
|
-
|
|
1074
|
+
persona: LINT_PERSONA,
|
|
1054
1075
|
timeline: LINT_TIMELINE,
|
|
1055
1076
|
indexHint: { type: 'boolean' },
|
|
1056
|
-
}, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', '
|
|
1077
|
+
}, ['notebook', 'notes', 'truncated', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'persona', 'timeline', 'indexHint']),
|
|
1057
1078
|
},
|
|
1058
1079
|
async run(args, env) {
|
|
1059
1080
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1143,7 +1164,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1143
1164
|
truncated: { type: 'boolean' },
|
|
1144
1165
|
memory: objSchema({
|
|
1145
1166
|
words: { type: 'number' },
|
|
1146
|
-
|
|
1167
|
+
personaWords: { type: 'number' },
|
|
1147
1168
|
totalWords: { type: 'number' },
|
|
1148
1169
|
budget: { type: 'number' },
|
|
1149
1170
|
headroom: { type: 'number' },
|
|
@@ -1157,7 +1178,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1157
1178
|
retiredWords: { type: 'number' },
|
|
1158
1179
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
1159
1180
|
},
|
|
1160
|
-
}, ['words', '
|
|
1181
|
+
}, ['words', 'personaWords', 'totalWords', 'budget', 'headroom', 'files']),
|
|
1161
1182
|
counts: objSchema({
|
|
1162
1183
|
window: { type: 'number' },
|
|
1163
1184
|
daily: { type: 'number' },
|
|
@@ -1217,12 +1238,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1217
1238
|
' · 未完成 ' + v.counts.looseEnds + ' · 已晋升 ' + v.counts.promoted + ' · 积压 ' + v.counts.backlog,
|
|
1218
1239
|
];
|
|
1219
1240
|
// 余量按记忆侧总词算(框 + 提示 + notice 都算):只报内容词等于说「还有 15 词」,而提示早把它吃完了。
|
|
1220
|
-
//
|
|
1221
|
-
const memoryTotal = v.memory.totalWords - v.memory.
|
|
1241
|
+
// 人格单独注入,先从 totalWords 里扣掉 —— 它不占记忆预算,也不该被叫成「提示」。
|
|
1242
|
+
const memoryTotal = v.memory.totalWords - v.memory.personaWords;
|
|
1222
1243
|
const promptWords = Math.max(0, memoryTotal - v.memory.words);
|
|
1223
1244
|
lines.push('记忆:内容 ' + v.memory.words + '/' + v.memory.budget + ' 词 + 提示 ' + promptWords +
|
|
1224
1245
|
' = ' + memoryTotal + ' 词(余 ' + v.memory.headroom + ')' +
|
|
1225
|
-
(v.memory.
|
|
1246
|
+
(v.memory.personaWords > 0 ? ' · 人格 ' + v.memory.personaWords + ' 词(单独注入,不计入记忆预算)' : ''));
|
|
1226
1247
|
if (v.retireCandidates.length) {
|
|
1227
1248
|
lines.push('可考虑退役:');
|
|
1228
1249
|
for (const c of v.retireCandidates.slice(0, 10)) {
|
|
@@ -17,10 +17,20 @@
|
|
|
17
17
|
* 首行 `<!-- zdiary-template: vN -->` 是版本标记:lint 据此报告「老库的 AGENTS.md 是旧版」,
|
|
18
18
|
* 只报告不覆盖(模板允许用户改)。
|
|
19
19
|
*/
|
|
20
|
-
/** 模板版本:改模板就 +1;lint
|
|
20
|
+
/** 模板版本:改模板就 +1;lint 用它判断老库是否还在用旧模板(v8:读取交给原生 read) */
|
|
21
21
|
export const TEMPLATE_VERSION = 8;
|
|
22
22
|
/** 首行版本标记(实测 4 词);不许带日期 —— 带日期的写法实测 6 词,白花 2 词 */
|
|
23
23
|
export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
|
|
24
|
+
/** 版本标记的正则(本文件内用;外部只通过 `templateVersionOf` 取数,免得又一个口径) */
|
|
25
|
+
const TEMPLATE_MARK_RE = /<!--\s*zdiary-template:\s*v(\d+)\s*-->/;
|
|
26
|
+
/**
|
|
27
|
+
* AGENTS.md 里的模板版本;没有标记返回 0。
|
|
28
|
+
* 只读标记、不校验正文哨兵 —— 哨兵是 lint 的事,记忆页只要一眼可读的版本号。
|
|
29
|
+
*/
|
|
30
|
+
export function templateVersionOf(body) {
|
|
31
|
+
const hit = TEMPLATE_MARK_RE.exec(String(body ?? ''));
|
|
32
|
+
return hit ? Number(hit[1]) : 0;
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* 当前版本的正文哨兵:只查「标记已经是当前版本」的文件,用来发现
|
|
26
36
|
* 「只把首行数字改成 vN、正文还是旧版」。
|
package/dist/lib/lint.js
CHANGED
|
@@ -26,11 +26,12 @@ import path from 'node:path';
|
|
|
26
26
|
import { allNotes, graphEdges, localDate, MAX_SCAN, notesWithFlag, parseErrorWarnings } from './zk.js';
|
|
27
27
|
import { normalizeTitle, resolveWikiTarget, WIKI_LINK, wikiIndex } from './wikilink.js';
|
|
28
28
|
import { parseFrontmatter } from './frontmatter.js';
|
|
29
|
-
import { daysSinceDate, entryDate, isRetiredEntry, splitMemoryEntries } from './memory-format.js';
|
|
30
|
-
import { AGENTS_TEMPLATE, AGENTS_TEMPLATE_FLAT, TEMPLATE_SENTINELS, TEMPLATE_VERSION } from './agents-template.js';
|
|
31
|
-
import {
|
|
29
|
+
import { daysSinceDate, entryDate, isRetiredEntry, memoryFormatDebt, splitMemoryEntries } from './memory-format.js';
|
|
30
|
+
import { AGENTS_TEMPLATE, AGENTS_TEMPLATE_FLAT, TEMPLATE_SENTINELS, TEMPLATE_VERSION, templateVersionOf } from './agents-template.js';
|
|
31
|
+
import { PERSONA_TEMPLATE_SENTINELS, PERSONA_TEMPLATE_VERSION } from './persona-template.js';
|
|
32
32
|
import { timelineCounts, timelineIssues } from './timeline.js';
|
|
33
33
|
import { isDayString } from './dates.js';
|
|
34
|
+
import { similarKeyOf, similarScore } from './similar.js';
|
|
34
35
|
/** 每类最多回多少条(计划 §4 M3);总数另给 */
|
|
35
36
|
export const MAX_ITEMS = 50;
|
|
36
37
|
/** 时间轴只扫最近多少天(计划 §2 D4):一年日记会报几百条旧问题,把今天的问题挤出 50 条上限 */
|
|
@@ -56,33 +57,8 @@ export function duplicateTitles(notes, max = MAX_ITEMS) {
|
|
|
56
57
|
dup.sort((a, b) => b.paths.length - a.paths.length || a.title.localeCompare(b.title));
|
|
57
58
|
return { total: dup.length, items: dup.slice(0, max) };
|
|
58
59
|
}
|
|
59
|
-
/** 相似标题的判定:字符二元组 Jaccard 下限;短串被长串包含时另算(短串至少 6 字) */
|
|
60
|
-
const SIMILAR_RATIO = 0.6;
|
|
61
|
-
const SIMILAR_SHORT = 6;
|
|
62
60
|
/** 同目录最多两两比较多少篇:超过就截断并置 truncated,别让 1 万篇变成 O(n²) */
|
|
63
61
|
const SIMILAR_GROUP_MAX = 300;
|
|
64
|
-
/** 比较用的标题:NFKC → 小写 → 去标点 / 空白。中文不改字,只抹掉排版差异 */
|
|
65
|
-
function similarKey(title) {
|
|
66
|
-
return String(title ?? '').normalize('NFKC').toLowerCase().replace(/[\s\p{P}\p{S}]/gu, '');
|
|
67
|
-
}
|
|
68
|
-
function bigrams(key) {
|
|
69
|
-
const chars = [...key];
|
|
70
|
-
const out = new Set();
|
|
71
|
-
for (let i = 0; i < chars.length - 1; i++)
|
|
72
|
-
out.add(chars[i] + chars[i + 1]);
|
|
73
|
-
if (out.size === 0 && chars.length > 0)
|
|
74
|
-
out.add(chars[0]);
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
function jaccard(a, b) {
|
|
78
|
-
if (a.size === 0 || b.size === 0)
|
|
79
|
-
return 0;
|
|
80
|
-
let shared = 0;
|
|
81
|
-
for (const gram of a)
|
|
82
|
-
if (b.has(gram))
|
|
83
|
-
shared += 1;
|
|
84
|
-
return shared / (a.size + b.size - shared);
|
|
85
|
-
}
|
|
86
62
|
/**
|
|
87
63
|
* 疑似重复标题(P2-10):精确查重只能挡住手滑 —— 中文改两个字就绕过去了。
|
|
88
64
|
*
|
|
@@ -98,15 +74,13 @@ export function similarTitles(notes, scanTruncated, max = MAX_ITEMS) {
|
|
|
98
74
|
const groups = new Map();
|
|
99
75
|
for (const note of notes) {
|
|
100
76
|
const title = note.title || path.basename(note.path, path.extname(note.path));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// 纯数字:日期 / 编号类标题,相似度只反映「数字挨着」,不反映重复结论
|
|
105
|
-
if (/^\d+$/.test(key))
|
|
77
|
+
// 空标题、纯数字(日期 / 编号)都在这里被挡掉,口径与 zk_new 的写路径提示同一份
|
|
78
|
+
const target = similarKeyOf(title);
|
|
79
|
+
if (!target)
|
|
106
80
|
continue;
|
|
107
81
|
const dir = path.posix.dirname(note.path);
|
|
108
82
|
const list = groups.get(dir) ?? [];
|
|
109
|
-
list.push({ title, path: note.path,
|
|
83
|
+
list.push({ title, path: note.path, exact: normalizeTitle(title), ...target });
|
|
110
84
|
groups.set(dir, list);
|
|
111
85
|
}
|
|
112
86
|
let truncated = scanTruncated;
|
|
@@ -124,24 +98,14 @@ export function similarTitles(notes, scanTruncated, max = MAX_ITEMS) {
|
|
|
124
98
|
// 归一化后完全一样:那是 duplicateTitles 的活(这里报会让同一件事出现两遍)
|
|
125
99
|
if (a.exact === b.exact)
|
|
126
100
|
continue;
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let score = jaccard(a.grams, b.grams);
|
|
131
|
-
let hit = score >= SIMILAR_RATIO;
|
|
132
|
-
if (!hit) {
|
|
133
|
-
const [short, long, shortSize] = a.size <= b.size ? [a.key, b.key, a.size] : [b.key, a.key, b.size];
|
|
134
|
-
if (shortSize >= SIMILAR_SHORT && long.includes(short)) {
|
|
135
|
-
hit = true;
|
|
136
|
-
score = SIMILAR_RATIO;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (!hit)
|
|
101
|
+
// 相似判定只有 similar.ts 一份:短标题(< 4 码点)也由它挡掉
|
|
102
|
+
const score = similarScore(a, b);
|
|
103
|
+
if (score === null)
|
|
140
104
|
continue;
|
|
141
105
|
found.push({
|
|
142
106
|
titles: [a.title, b.title],
|
|
143
107
|
paths: [a.path, b.path],
|
|
144
|
-
score
|
|
108
|
+
score,
|
|
145
109
|
});
|
|
146
110
|
}
|
|
147
111
|
}
|
|
@@ -211,10 +175,13 @@ export function memoryLinkIssues(cfg, notes, opts = {}) {
|
|
|
211
175
|
}
|
|
212
176
|
// 只对 MEMORY.md 数「没附来源 / 没日期 / 退役 / 陈旧」:USER.md 是偏好清单,大多数条目本来就没有来源
|
|
213
177
|
if (name === 'MEMORY.md') {
|
|
178
|
+
// 日期 / 来源缺口取唯一口径 memoryFormatDebt(退役条目不算、`[[ ]]` 不算来源),
|
|
179
|
+
// 注入提示与记忆页用的也是它 —— 同一个「N 条没来源」不许在三处给出三个数。
|
|
180
|
+
const debt = memoryFormatDebt(body);
|
|
181
|
+
undated = debt.undated;
|
|
182
|
+
unlinked = debt.unlinked;
|
|
214
183
|
for (const entry of splitMemoryEntries(body)) {
|
|
215
184
|
const first = entry.split('\n', 1)[0] ?? '';
|
|
216
|
-
if (!entry.includes('[['))
|
|
217
|
-
unlinked += 1;
|
|
218
185
|
// 退役行:磁盘保留、注入从 0.9 起省略(D3),只核对它指向的新结论是否还活着
|
|
219
186
|
if (isRetiredEntry(entry)) {
|
|
220
187
|
retired += 1;
|
|
@@ -226,10 +193,8 @@ export function memoryLinkIssues(cfg, notes, opts = {}) {
|
|
|
226
193
|
}
|
|
227
194
|
// 日期要真校验:`2026-99-99` 既不算「有日期」,也不该在陈旧里报一次
|
|
228
195
|
const date = entryDate(entry);
|
|
229
|
-
if (!date)
|
|
230
|
-
undated += 1;
|
|
196
|
+
if (!date)
|
|
231
197
|
continue;
|
|
232
|
-
}
|
|
233
198
|
const age = daysSinceDate(date, now);
|
|
234
199
|
if (age !== null && age > staleDays) {
|
|
235
200
|
staleTotal += 1;
|
|
@@ -312,39 +277,39 @@ export function formatLintExtras(r) {
|
|
|
312
277
|
const timeline = formatTimeline(r.timeline);
|
|
313
278
|
if (timeline)
|
|
314
279
|
lines.push(timeline);
|
|
315
|
-
// 缺文件 =
|
|
280
|
+
// 缺文件 = 人格未启用(默认状态):不报错、不占行。
|
|
316
281
|
// 有旧版 / 占位符 / 标记不符时才提醒 —— 否则每个老库每次 lint 都多一条永久 ⚠️,反而训练人忽略告警。
|
|
317
|
-
const
|
|
318
|
-
const allMissing =
|
|
319
|
-
if (!allMissing &&
|
|
282
|
+
const persona = r.persona.items;
|
|
283
|
+
const allMissing = persona.length > 0 && persona.every((i) => i.kind === 'missing');
|
|
284
|
+
if (!allMissing && persona.length > 0) {
|
|
320
285
|
// 不同方向给不同指令:旧版要合并内容,比插件新要升级插件,标记与内容不符要查哨兵。
|
|
321
|
-
//
|
|
286
|
+
// 混成一句「旧版由人按需处理」会把「比插件新」也说成旧版,模型最省力的动作就是改数字。
|
|
322
287
|
const groups = [
|
|
323
288
|
{
|
|
324
289
|
label: '旧版',
|
|
325
|
-
items:
|
|
290
|
+
items: persona.filter((i) => i.kind === 'old'),
|
|
326
291
|
hint: '合并新版内容后再改首行标记;只改数字不算升级',
|
|
327
292
|
},
|
|
328
293
|
{
|
|
329
294
|
label: '版本比插件新',
|
|
330
|
-
items:
|
|
295
|
+
items: persona.filter((i) => i.kind === 'newer'),
|
|
331
296
|
hint: '插件才是旧的那个,别改文件里的版本号;升级插件后再看',
|
|
332
297
|
},
|
|
333
298
|
{
|
|
334
299
|
label: '标记与内容不符',
|
|
335
|
-
items:
|
|
300
|
+
items: persona.filter((i) => i.kind === 'mismatch'),
|
|
336
301
|
hint: '疑似只改了版本号;按新版模板合并内容,别只改数字',
|
|
337
302
|
},
|
|
338
303
|
{
|
|
339
304
|
label: '',
|
|
340
|
-
items:
|
|
305
|
+
items: persona.filter((i) => i.kind === 'missing' || i.kind === 'placeholder'),
|
|
341
306
|
hint: '只报告:缺文件 = 未启用,占位符由人填',
|
|
342
307
|
},
|
|
343
308
|
];
|
|
344
309
|
for (const group of groups) {
|
|
345
310
|
if (group.items.length === 0)
|
|
346
311
|
continue;
|
|
347
|
-
lines.push(`⚠️
|
|
312
|
+
lines.push(`⚠️ 人格${group.label}:${group.items.map((i) => `${i.file} ${i.detail}`).join(';')}|${group.hint}`);
|
|
348
313
|
}
|
|
349
314
|
}
|
|
350
315
|
if (r.incomplete.total > 0) {
|
|
@@ -501,7 +466,6 @@ export function tagHygiene(notes, max = 20) {
|
|
|
501
466
|
singletons: { total: singletons.length, items: singletons.slice(0, 10) },
|
|
502
467
|
};
|
|
503
468
|
}
|
|
504
|
-
const TEMPLATE_MARK_RE = /<!--\s*zdiary-template:\s*v(\d+)\s*-->/;
|
|
505
469
|
const PERSONA_MARK_RE = /<!--\s*zdiary-persona:\s*v(\d+)\s*-->/;
|
|
506
470
|
const PLACEHOLDER_RE = /\{\{\s*[^}]+\s*\}\}/g;
|
|
507
471
|
/**
|
|
@@ -528,13 +492,13 @@ function sentinelIssue(body, rule) {
|
|
|
528
492
|
return parts.length > 0 ? parts.join(';') : null;
|
|
529
493
|
}
|
|
530
494
|
/**
|
|
531
|
-
*
|
|
495
|
+
* 人格体检(M1):缺文件 = 未启用(不算错,但要让 zk_lint 可见);
|
|
532
496
|
* 旧版 = 标记比当前模板旧;比插件新 = 插件才是旧的那个,别改文件去配;
|
|
533
497
|
* 标记与内容不符 = 标记已是当前版本,正文还留着旧版内容(只改了首行数字);
|
|
534
498
|
* 占位符 = 模板里的 {{...}} 还没填(“未填”是机械可发现的“未启用一半”状态)。
|
|
535
|
-
* 全部只报告,不覆盖 ——
|
|
499
|
+
* 全部只报告,不覆盖 —— 人格允许人改。
|
|
536
500
|
*/
|
|
537
|
-
export function
|
|
501
|
+
export function personaStatus(cfg) {
|
|
538
502
|
const items = [];
|
|
539
503
|
const files = [
|
|
540
504
|
{ name: 'PERSONA.md', mark: PERSONA_MARK_RE, current: PERSONA_TEMPLATE_VERSION },
|
|
@@ -545,7 +509,7 @@ export function contractStatus(cfg) {
|
|
|
545
509
|
body = fs.readFileSync(path.join(cfg.notebook, f.name), 'utf8');
|
|
546
510
|
}
|
|
547
511
|
catch {
|
|
548
|
-
items.push({ file: f.name, kind: 'missing', detail: '根目录没有这份文件(zk-kit init --with-
|
|
512
|
+
items.push({ file: f.name, kind: 'missing', detail: '根目录没有这份文件(zk-kit init --with-persona 或设置页可写入模板)' });
|
|
549
513
|
continue;
|
|
550
514
|
}
|
|
551
515
|
const hit = f.mark.exec(body);
|
|
@@ -567,7 +531,7 @@ export function contractStatus(cfg) {
|
|
|
567
531
|
});
|
|
568
532
|
}
|
|
569
533
|
else {
|
|
570
|
-
const mismatch = sentinelIssue(body,
|
|
534
|
+
const mismatch = sentinelIssue(body, PERSONA_TEMPLATE_SENTINELS[f.name]?.[version]);
|
|
571
535
|
if (mismatch) {
|
|
572
536
|
items.push({ file: f.name, kind: 'mismatch', detail: `标记是 v${version},但正文${mismatch}` });
|
|
573
537
|
}
|
|
@@ -580,7 +544,7 @@ export function contractStatus(cfg) {
|
|
|
580
544
|
return { total: items.length, items };
|
|
581
545
|
}
|
|
582
546
|
/**
|
|
583
|
-
* 模板版本(P2-15
|
|
547
|
+
* 模板版本(P2-15):模板是行为约定,不是静态文档 —— 它每轮注入,写错一句就是每轮都在执行错规则。
|
|
584
548
|
* 但模板允许用户改,不能自动覆盖;版本标记把「过期」变成可发现状态,只报告。
|
|
585
549
|
*
|
|
586
550
|
* 标记等于当前版本时再查正文哨兵:只把首行数字改成 vN、正文还是旧版,
|
|
@@ -594,8 +558,7 @@ export function templateStatus(cfg) {
|
|
|
594
558
|
catch {
|
|
595
559
|
return { present: false, version: 0, current: TEMPLATE_VERSION, stale: false };
|
|
596
560
|
}
|
|
597
|
-
const
|
|
598
|
-
const version = hit ? Number(hit[1]) : 0;
|
|
561
|
+
const version = templateVersionOf(body);
|
|
599
562
|
const mismatchDetail = version === TEMPLATE_VERSION
|
|
600
563
|
? sentinelIssue(body, TEMPLATE_SENTINELS[TEMPLATE_VERSION])
|
|
601
564
|
: null;
|
|
@@ -849,7 +812,7 @@ export async function lintNotebook(cfg, opts = {}, signal) {
|
|
|
849
812
|
: { total: 0, truncated: false, byField: { type: 0, status: 0, authority: 0 }, items: [] },
|
|
850
813
|
tags: tagHygiene(notes),
|
|
851
814
|
template: templateStatus(cfg),
|
|
852
|
-
|
|
815
|
+
persona: personaStatus(cfg),
|
|
853
816
|
timeline: timelineStatus(cfg, now),
|
|
854
817
|
// 150 篇(不含日记)是检索开始变糊的拐点:提示一下,不生成静态索引(会过期,还要决定谁更新)
|
|
855
818
|
indexHint: nonDaily.length >= 150 && !fs.existsSync(path.join(cfg.notebook, 'INDEX.md')),
|
|
@@ -60,6 +60,29 @@ export function entryDate(entry) {
|
|
|
60
60
|
return null;
|
|
61
61
|
return validDate(m[1], m[2], m[3]) ? `${m[1]}-${m[2]}-${m[3]}` : null;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* 条目里的双链来源;只看写没写,链接是否真存在是 lint 的事。
|
|
65
|
+
* 目标是「非空白」:`[[ ]]` 不算来源(lint 的 `WIKI_LINK` 也把空目标当没链接),
|
|
66
|
+
* `[[目标|别名]]` / `[[目标#小节]]` 算。
|
|
67
|
+
*/
|
|
68
|
+
const LINK = /\[\[[^\]\n]*\S[^\]\n]*\]\]/;
|
|
69
|
+
/**
|
|
70
|
+
* 数一遍格式债:只机械计数,不猜日期、不补来源 —— 两者仍由人和 agent 写。
|
|
71
|
+
* 注入与记忆页只负责把缺口摆出来,否则「按日期淘汰」对没日期的老库永远空转。
|
|
72
|
+
* 退役条目不算:它们按约定退役,不该因为格式被继续提醒。
|
|
73
|
+
*/
|
|
74
|
+
export function memoryFormatDebt(body) {
|
|
75
|
+
const entries = splitMemoryEntries(body).filter((entry) => !isRetiredEntry(entry));
|
|
76
|
+
let undated = 0;
|
|
77
|
+
let unlinked = 0;
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
if (!entryDate(entry))
|
|
80
|
+
undated += 1;
|
|
81
|
+
if (!LINK.test(entry))
|
|
82
|
+
unlinked += 1;
|
|
83
|
+
}
|
|
84
|
+
return { total: entries.length, undated, unlinked };
|
|
85
|
+
}
|
|
63
86
|
/**
|
|
64
87
|
* 去掉退役条目(整条,不留半行),返回正文与删掉的条数。
|
|
65
88
|
* 磁盘上的文件不动 —— 省略只发生在注入路径上;记忆页 / git 仍看得到它们。
|