dsh-zdiary-kit 3.6.0 → 3.8.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 +19 -12
- package/dist/cli.js +24 -2
- package/dist/features/zk-tools/feature.js +201 -24
- package/dist/lib/agents-template.js +10 -2
- package/dist/lib/dream.js +16 -10
- package/dist/lib/lint.js +5 -0
- package/dist/lib/memory.js +84 -1
- package/dist/lib/recall.js +104 -0
- package/dist/lib/wikilink.js +18 -1
- package/dist/lib/zk.js +165 -26
- package/docs/features/memory.md +19 -3
- package/docs/features/readonly.md +1 -1
- package/docs/features/zk-tools.md +42 -3
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* zk 工具(feature 的公共入口):
|
|
2
|
+
* zk 工具(feature 的公共入口):14 个内置工具 + `[alias]` 别名工具,全部经 lib/zk.ts。
|
|
3
3
|
*
|
|
4
4
|
* 设计要点:
|
|
5
5
|
* · 除 zk_context(只读 meta 文件,不依赖 zk)外,每个工具进来先 ensureNotebook —— 第一次调用就自动建好笔记本,用户不用先点设置页;
|
|
@@ -15,13 +15,22 @@ 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, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, taglessCjkWarning, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, runAlias, ZkError, } from '../../lib/zk.js';
|
|
18
|
+
import { searchNotes, searchNotesDetailed, createNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, withTags, taglessCjkWarning, notebookStats, supersedeNote, renameNote, hasNotebook, isUnderDir, localDate as dateOnly, runAlias, hasCjk, ZkError, } from '../../lib/zk.js';
|
|
19
19
|
import { configuredAliases, readAliases } from '../../lib/alias.js';
|
|
20
|
-
import { buildMemoryPayload, META_FILES } from '../../lib/memory.js';
|
|
20
|
+
import { buildMemoryPayload, memoryCapacity, META_FILES } from '../../lib/memory.js';
|
|
21
|
+
import { assembleRecall } from '../../lib/recall.js';
|
|
21
22
|
import { META_NAMES } from '../../lib/meta.js';
|
|
22
23
|
import { formatLintExtras, formatMemoryLinks, lintNotebook } from '../../lib/lint.js';
|
|
23
24
|
import { dreamNotebook, STALE_DAYS } from '../../lib/dream.js';
|
|
24
25
|
const text = (value) => [{ type: 'text', text: value }];
|
|
26
|
+
/** render 的 args 是 unknown:只取 query 判断要不要给中文 0 命中提示(R7) */
|
|
27
|
+
const queryOf = (args) => {
|
|
28
|
+
if (!args || typeof args !== 'object')
|
|
29
|
+
return '';
|
|
30
|
+
return String(args.query ?? '');
|
|
31
|
+
};
|
|
32
|
+
/** R7:中文 0 命中的「为什么空」提示;ASCII / 无 query 不加 */
|
|
33
|
+
const zeroHitHint = (args, extra) => hasCjk(queryOf(args)) ? `;中文全文不切词:换更短的词,${extra}` : '';
|
|
25
34
|
const objSchema = (properties, required) => ({
|
|
26
35
|
type: 'object',
|
|
27
36
|
properties,
|
|
@@ -261,10 +270,15 @@ function withElsewhere(err, cfg, workspace, rel) {
|
|
|
261
270
|
function tagSuffix(record) {
|
|
262
271
|
return record.tags.length ? ' · ' + record.tags.map((t) => '#' + t).join(' ') : '';
|
|
263
272
|
}
|
|
273
|
+
/** R2:snippet 比 lead 多带命中上下文时才替换它,否则维持原输出 */
|
|
274
|
+
function detailOf(n) {
|
|
275
|
+
return n.snippet && n.snippet !== n.lead ? n.snippet : (n.lead ?? '');
|
|
276
|
+
}
|
|
264
277
|
function noteLine(n, index) {
|
|
265
278
|
const head = `${index + 1}. ${n.title || n.path}`;
|
|
266
279
|
const meta = [n.absPath || n.path, dateOnly(n.created)].filter(Boolean).join(' · ');
|
|
267
|
-
const
|
|
280
|
+
const detail = detailOf(n);
|
|
281
|
+
const lead = detail ? `\n ${detail}` : '';
|
|
268
282
|
return `${head}\n ${meta}${tagSuffix(n)}${lead}`;
|
|
269
283
|
}
|
|
270
284
|
function def(spec, workspaceOf) {
|
|
@@ -361,20 +375,21 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
361
375
|
const builtins = [
|
|
362
376
|
t({
|
|
363
377
|
name: 'zk_search',
|
|
364
|
-
description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 /
|
|
378
|
+
description: '在 zk 知识库里搜索笔记(全文 / 标签 / 日期 / 断链 / 孤立笔记),返回标题、相对路径、绝对路径、标签、创建日、摘要与命中片段。' +
|
|
365
379
|
'找到后用原生 read 读全文:notes[].absPath 可以直接传给 read。写笔记前先用它查重。' +
|
|
366
|
-
'
|
|
380
|
+
'中文会自动并用子串,多词按覆盖度合并(FTS 不切中文):matchStrategy 说明这次用了 fts / regex / mixed,mixed 表示补到了全文索引漏掉的笔记。' +
|
|
381
|
+
'有 query 时默认按 FTS 相关性排序,显式给 sort 才改顺序。',
|
|
367
382
|
parameters: {
|
|
368
383
|
type: 'object',
|
|
369
384
|
properties: {
|
|
370
|
-
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR
|
|
385
|
+
query: S.str('全文检索词(FTS,支持 "短语" 与 AND / OR;中文会自动并用子串,多词按覆盖度合并)'),
|
|
371
386
|
tags: S.arr('按标签过滤(AND:必须同时带这些标签)', S.str('标签名,不带 #')),
|
|
372
387
|
since: S.str('只看这个日期之后创建的笔记,自然语言或 ISO 日期,如 2026-01-01 / "last week"'),
|
|
373
388
|
until: S.str('只看这个日期之前创建的笔记'),
|
|
374
389
|
orphan: S.bool('只看没有任何反链的孤立笔记'),
|
|
375
390
|
brokenLinks: S.bool('只看含有断链的笔记'),
|
|
376
391
|
limit: S.num('最多返回几条(1-200,默认 10)'),
|
|
377
|
-
sort: S.enum('
|
|
392
|
+
sort: S.enum('排序方式;有 query 默认 relevance(按 FTS 相关性),无 query 回退 created-desc', ['relevance', 'created-desc', 'created-asc', 'modified-desc', 'title-asc']),
|
|
378
393
|
},
|
|
379
394
|
additionalProperties: false,
|
|
380
395
|
},
|
|
@@ -386,6 +401,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
386
401
|
completeness: { type: 'string', enum: ['complete', 'partial', 'unknown'] },
|
|
387
402
|
hasMore: { type: 'boolean' },
|
|
388
403
|
scanned: { type: 'number' },
|
|
404
|
+
/** R2:只在能精确判定时给(completeness === complete) */
|
|
405
|
+
total: { type: 'number' },
|
|
389
406
|
notes: {
|
|
390
407
|
type: 'array',
|
|
391
408
|
items: objSchema({
|
|
@@ -395,6 +412,9 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
395
412
|
tags: { type: 'array', items: { type: 'string' } },
|
|
396
413
|
created: { type: 'string' },
|
|
397
414
|
lead: { type: 'string' },
|
|
415
|
+
words: { type: 'number' },
|
|
416
|
+
/** 命中片段,没有时整个键不出现(避免 undefined 让宿主判 invalid output) */
|
|
417
|
+
snippet: { type: 'string' },
|
|
398
418
|
}, ['title', 'path', 'absPath', 'tags', 'created', 'lead']),
|
|
399
419
|
},
|
|
400
420
|
}, ['notebook', 'count', 'matchStrategy', 'completeness', 'hasMore', 'scanned', 'notes']),
|
|
@@ -410,7 +430,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
410
430
|
orphan: args.orphan === true,
|
|
411
431
|
brokenLinks: args.brokenLinks === true,
|
|
412
432
|
limit: args.limit === undefined ? 10 : Number(args.limit),
|
|
413
|
-
|
|
433
|
+
// R1:有 query 且没显式给 sort → relevance(不传 --sort,保住 FTS 相关性顺序)
|
|
434
|
+
sort: args.sort ? String(args.sort) : (args.query ? 'relevance' : 'created-desc'),
|
|
414
435
|
});
|
|
415
436
|
return {
|
|
416
437
|
notebook: cfg.notebook,
|
|
@@ -419,13 +440,19 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
419
440
|
completeness: result.completeness,
|
|
420
441
|
hasMore: result.hasMore,
|
|
421
442
|
scanned: result.scanned,
|
|
422
|
-
|
|
443
|
+
...(result.total === undefined ? {} : { total: result.total }),
|
|
444
|
+
notes: result.notes.map((n) => ({
|
|
445
|
+
title: n.title, path: n.path, absPath: n.absPath, tags: n.tags,
|
|
446
|
+
created: dateOnly(n.created), lead: n.lead, words: n.words,
|
|
447
|
+
...(n.snippet ? { snippet: n.snippet } : {}),
|
|
448
|
+
})),
|
|
423
449
|
};
|
|
424
450
|
},
|
|
425
|
-
render(
|
|
451
|
+
render(args, value) {
|
|
426
452
|
const v = value;
|
|
427
453
|
if (!v.count) {
|
|
428
454
|
return text(`没有匹配的笔记(笔记本 ${v.notebook})` +
|
|
455
|
+
zeroHitHint(args, '或按 tags 查') +
|
|
429
456
|
(v.completeness === 'unknown' ? ';但这次检索结果无法完整解析,不能当作「库里没有」' : ''));
|
|
430
457
|
}
|
|
431
458
|
const how = v.matchStrategy === 'mixed'
|
|
@@ -441,11 +468,12 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
441
468
|
name: 'zk_query',
|
|
442
469
|
description: '结构化检索记忆:按 type(daily/source/concept/entity/pattern)、status(active/superseded)、标签、目录、日期、断链、孤立过滤。' +
|
|
443
470
|
'默认只看 active 且不含归档;传 include_archived: true 会连归档一起查,此时未显式给 status 就不再默认过滤 active。' +
|
|
471
|
+
'中文会自动并用子串,多词按覆盖度合并;有 query 时默认按 FTS 相关性排序。' +
|
|
444
472
|
'这是查「记忆里有什么」的主入口。',
|
|
445
473
|
parameters: {
|
|
446
474
|
type: 'object',
|
|
447
475
|
properties: {
|
|
448
|
-
query: S.str('
|
|
476
|
+
query: S.str('全文检索词(中文会自动并用子串,多词按覆盖度合并)'),
|
|
449
477
|
tags: S.arr('按标签过滤(AND)', S.str('标签名,不带 #')),
|
|
450
478
|
dirs: S.arr('只看这些目录(相对笔记本,如 notes/concepts)', S.str('相对目录')),
|
|
451
479
|
type: S.enum('只要这个类型的笔记', ['daily', 'source', 'concept', 'entity', 'pattern']),
|
|
@@ -455,7 +483,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
455
483
|
orphan: S.bool('只看没有反链的孤立笔记'),
|
|
456
484
|
brokenLinks: S.bool('只看含断链的笔记'),
|
|
457
485
|
include_archived: S.bool('连 archive/ 里的废弃笔记一起查(默认 false)'),
|
|
458
|
-
sort: S.enum('
|
|
486
|
+
sort: S.enum('排序方式;有 query 默认 relevance(按 FTS 相关性),无 query 回退 created-desc', ['relevance', 'created-desc', 'created-asc', 'modified-desc', 'title-asc']),
|
|
459
487
|
limit: S.num('最多返回几条(1-200,默认 10)'),
|
|
460
488
|
},
|
|
461
489
|
additionalProperties: false,
|
|
@@ -467,6 +495,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
467
495
|
completeness: { type: 'string', enum: ['complete', 'partial', 'unknown'] },
|
|
468
496
|
hasMore: { type: 'boolean' },
|
|
469
497
|
scanned: { type: 'number' },
|
|
498
|
+
/** R2:只在能精确判定时给(completeness === complete) */
|
|
499
|
+
total: { type: 'number' },
|
|
470
500
|
notes: {
|
|
471
501
|
type: 'array',
|
|
472
502
|
items: objSchema({
|
|
@@ -479,6 +509,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
479
509
|
tags: { type: 'array', items: { type: 'string' } },
|
|
480
510
|
created: { type: 'string' },
|
|
481
511
|
lead: { type: 'string' },
|
|
512
|
+
words: { type: 'number' },
|
|
513
|
+
snippet: { type: 'string' },
|
|
482
514
|
archived: { type: 'boolean' },
|
|
483
515
|
}, ['title', 'path', 'absPath', 'type', 'status', 'authority', 'tags', 'created', 'lead', 'archived']),
|
|
484
516
|
},
|
|
@@ -501,7 +533,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
501
533
|
brokenLinks: args.brokenLinks === true,
|
|
502
534
|
includeArchived,
|
|
503
535
|
limit: args.limit === undefined ? 10 : Number(args.limit),
|
|
504
|
-
|
|
536
|
+
// R1:有 query 且没显式给 sort → relevance
|
|
537
|
+
sort: args.sort ? String(args.sort) : (args.query ? 'relevance' : 'created-desc'),
|
|
505
538
|
}, env.signal);
|
|
506
539
|
const notes = result.notes;
|
|
507
540
|
return {
|
|
@@ -510,6 +543,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
510
543
|
completeness: result.completeness,
|
|
511
544
|
hasMore: result.hasMore,
|
|
512
545
|
scanned: result.scanned,
|
|
546
|
+
...(result.total === undefined ? {} : { total: result.total }),
|
|
513
547
|
notes: notes.map((n) => ({
|
|
514
548
|
title: n.title,
|
|
515
549
|
path: n.path,
|
|
@@ -521,14 +555,17 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
521
555
|
tags: n.tags,
|
|
522
556
|
created: dateOnly(n.created),
|
|
523
557
|
lead: n.lead,
|
|
558
|
+
words: n.words,
|
|
559
|
+
...(n.snippet ? { snippet: n.snippet } : {}),
|
|
524
560
|
archived: n.path.startsWith(cfg.archiveDir + '/'),
|
|
525
561
|
})),
|
|
526
562
|
};
|
|
527
563
|
},
|
|
528
|
-
render(
|
|
564
|
+
render(args, value) {
|
|
529
565
|
const v = value;
|
|
530
566
|
if (!v.count) {
|
|
531
567
|
return text(`没有匹配的笔记(笔记本 ${v.notebook})` +
|
|
568
|
+
zeroHitHint(args, '或给 tags 参数按标签查') +
|
|
532
569
|
(v.completeness === 'unknown' ? ';但这次检索结果无法完整解析,不能当作「记忆里没有」' : ''));
|
|
533
570
|
}
|
|
534
571
|
const tail = v.completeness === 'unknown'
|
|
@@ -536,11 +573,99 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
536
573
|
: v.hasMore ? `\n⚠️ 还有更多匹配没返回(已检查 ${v.scanned} 条候选);要更全就提高 limit 或缩小过滤范围` : '';
|
|
537
574
|
const lines = v.notes.map((n, i) => {
|
|
538
575
|
const badges = [String(n.type || '—'), String(n.status || 'no-status'), n.archived ? '已归档' : ''].filter(Boolean);
|
|
539
|
-
|
|
576
|
+
const detail = detailOf({ lead: String(n.lead ?? ''), snippet: String(n.snippet ?? '') });
|
|
577
|
+
return `${i + 1}. ${String(n.title)} [${badges.join(' · ')}]\n ${String(n.absPath || n.path)} · ${String(n.created)}${detail ? '\n ' + detail : ''}`;
|
|
540
578
|
});
|
|
541
579
|
return text(`${v.count} 条(笔记本 ${v.notebook})\n` + lines.join('\n') + tail);
|
|
542
580
|
},
|
|
543
581
|
}),
|
|
582
|
+
t({
|
|
583
|
+
name: 'zk_recall',
|
|
584
|
+
description: '召回装配:先按 query / 过滤条件检索(与 zk_search 同一套 R1–R3),再按词数预算把命中笔记拼成一段可直接读的上下文。' +
|
|
585
|
+
'每条带标题、路径、absPath 与全文词数,放不下就整条丢弃、不切半句;需要全文仍用原生 read 读 absPath。' +
|
|
586
|
+
'budget 按 countWords 口径(中文 2 字 1 词),used 一定不超过 budget。' +
|
|
587
|
+
'不做语义判断 / 重排 / 跨回合去重;completeness 沿用检索三态,装配过的 ≠ 全部命中。',
|
|
588
|
+
parameters: {
|
|
589
|
+
type: 'object',
|
|
590
|
+
properties: {
|
|
591
|
+
query: S.str('全文检索词(中文自动并用子串、多词按覆盖度合并;不给则按过滤条件列最近的笔记)'),
|
|
592
|
+
tags: S.arr('按标签过滤(AND)', S.str('标签名,不带 #')),
|
|
593
|
+
since: S.str('只看这个日期之后创建的笔记'),
|
|
594
|
+
until: S.str('只看这个日期之前创建的笔记'),
|
|
595
|
+
orphan: S.bool('只看没有反链的孤立笔记'),
|
|
596
|
+
brokenLinks: S.bool('只看含断链的笔记'),
|
|
597
|
+
include_archived: S.bool('连 archive/ 里的废弃笔记一起查(默认 false)'),
|
|
598
|
+
type: S.enum('只要这个类型的笔记', ['daily', 'source', 'concept', 'entity', 'pattern']),
|
|
599
|
+
status: S.enum('只要这个状态(默认 active)', ['active', 'superseded']),
|
|
600
|
+
limit: S.num('候选检索条数(1-200,默认 30;装配只在这些候选里挑)'),
|
|
601
|
+
sort: S.enum('排序方式;有 query 默认 relevance(按 FTS 相关性),无 query 回退 created-desc', ['relevance', 'created-desc', 'created-asc', 'modified-desc', 'title-asc']),
|
|
602
|
+
budget: S.num('装配词数预算(默认 500,范围 1-5000;中文 2 字 1 词)'),
|
|
603
|
+
},
|
|
604
|
+
additionalProperties: false,
|
|
605
|
+
},
|
|
606
|
+
output: {
|
|
607
|
+
schema: objSchema({
|
|
608
|
+
notebook: { type: 'string' },
|
|
609
|
+
text: { type: 'string' },
|
|
610
|
+
used: { type: 'number' },
|
|
611
|
+
budget: { type: 'number' },
|
|
612
|
+
completeness: { type: 'string', enum: ['complete', 'partial', 'unknown'] },
|
|
613
|
+
hasMore: { type: 'boolean' },
|
|
614
|
+
notes: {
|
|
615
|
+
type: 'array',
|
|
616
|
+
items: objSchema({
|
|
617
|
+
title: { type: 'string' },
|
|
618
|
+
path: { type: 'string' },
|
|
619
|
+
absPath: { type: 'string' },
|
|
620
|
+
included: { type: 'boolean' },
|
|
621
|
+
reason: { type: 'string', enum: ['included', 'duplicate', 'empty', 'over-budget'] },
|
|
622
|
+
}, ['title', 'path', 'absPath', 'included', 'reason']),
|
|
623
|
+
},
|
|
624
|
+
}, ['notebook', 'text', 'used', 'budget', 'completeness', 'hasMore', 'notes']),
|
|
625
|
+
},
|
|
626
|
+
async run(args, env) {
|
|
627
|
+
const cfg = configFor(env.workspace, env.sessionId);
|
|
628
|
+
await ensureNotebook(cfg, env.signal);
|
|
629
|
+
const includeArchived = args.include_archived === true;
|
|
630
|
+
const r = await assembleRecall(cfg, {
|
|
631
|
+
query: args.query ? String(args.query) : undefined,
|
|
632
|
+
tags: Array.isArray(args.tags) ? args.tags.map(String) : undefined,
|
|
633
|
+
since: args.since ? String(args.since) : undefined,
|
|
634
|
+
until: args.until ? String(args.until) : undefined,
|
|
635
|
+
orphan: args.orphan === true,
|
|
636
|
+
brokenLinks: args.brokenLinks === true,
|
|
637
|
+
includeArchived,
|
|
638
|
+
type: args.type ? [String(args.type)] : undefined,
|
|
639
|
+
// 与 zk_query 同口径:默认只给活着的,显式 include_archived 时不再默认卡 active
|
|
640
|
+
status: args.status ? [String(args.status)] : includeArchived ? undefined : ['active'],
|
|
641
|
+
limit: args.limit === undefined ? undefined : Number(args.limit),
|
|
642
|
+
sort: args.sort ? String(args.sort) : undefined,
|
|
643
|
+
budget: args.budget === undefined ? undefined : Number(args.budget),
|
|
644
|
+
}, env.signal);
|
|
645
|
+
return { notebook: cfg.notebook, ...r };
|
|
646
|
+
},
|
|
647
|
+
render(args, value) {
|
|
648
|
+
const v = value;
|
|
649
|
+
const kept = v.notes.filter((n) => n.included).length;
|
|
650
|
+
const dropped = v.notes.length - kept;
|
|
651
|
+
if (!v.notes.length) {
|
|
652
|
+
return text(`没有匹配的笔记(笔记本 ${v.notebook})` +
|
|
653
|
+
zeroHitHint(args, '或按 tags 查') +
|
|
654
|
+
(v.completeness === 'unknown' ? ';但这次检索结果无法完整解析,不能当作「库里没有」' : ''));
|
|
655
|
+
}
|
|
656
|
+
const lines = [`召回装配:${v.used}/${v.budget} 词 · 收录 ${kept}/${v.notes.length} 篇(笔记本 ${v.notebook})`];
|
|
657
|
+
if (v.text)
|
|
658
|
+
lines.push('', v.text);
|
|
659
|
+
if (dropped)
|
|
660
|
+
lines.push(`(${dropped} 篇没放进去:整条丢弃,没有切半句;原因见 notes[].reason)`);
|
|
661
|
+
const tail = v.completeness === 'unknown'
|
|
662
|
+
? '⚠️ 无法确认结果是否完整(解析失败 / 补充检索失败),先别把它当成全部命中'
|
|
663
|
+
: v.hasMore ? '⚠️ 还有更多匹配没返回;要提高 limit 或缩小过滤范围' : '';
|
|
664
|
+
if (tail)
|
|
665
|
+
lines.push(tail);
|
|
666
|
+
return text(lines.join('\n'));
|
|
667
|
+
},
|
|
668
|
+
}),
|
|
544
669
|
t({
|
|
545
670
|
name: 'zk_new',
|
|
546
671
|
description: '新建一篇笔记(zk 负责生成文件名、套用模板、写入索引)。适合记下一个概念、决定、来源或想法;' +
|
|
@@ -951,8 +1076,17 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
951
1076
|
description: '读知识库根目录的长期约定与记忆(AGENTS.md / USER.md / MEMORY.md),按注入预算截断后返回;' +
|
|
952
1077
|
'角色人格(PERSONA.md)单独成段、在记忆段之前、不参与截断。' +
|
|
953
1078
|
'同时列出已配置的笔记本(名字 / 路径 / 结构 / 当前)。' +
|
|
1079
|
+
'改 MEMORY.md 之前用它看余量:headroom / wouldTruncate / dropCandidates 说明「再加一条会丢谁」,' +
|
|
1080
|
+
'给 proposed_entry 或 extra_words 就能预估;同日条目按位置决胜(sameDateCount)。' +
|
|
954
1081
|
'宿主支持注入时这些内容每轮已自动进入系统提示;宿主不支持、或想核对「被截断了多少」时用它。',
|
|
955
|
-
parameters: {
|
|
1082
|
+
parameters: {
|
|
1083
|
+
type: 'object',
|
|
1084
|
+
properties: {
|
|
1085
|
+
proposed_entry: S.str('打算写进 MEMORY.md 的新条目;按它估算会不会触发截断并预告会丢谁'),
|
|
1086
|
+
extra_words: S.num('新条目词数;给了就不按 proposed_entry 重算,直接按这个数估'),
|
|
1087
|
+
},
|
|
1088
|
+
additionalProperties: false,
|
|
1089
|
+
},
|
|
956
1090
|
output: {
|
|
957
1091
|
schema: objSchema({
|
|
958
1092
|
text: { type: 'string' },
|
|
@@ -964,6 +1098,23 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
964
1098
|
tocWords: { type: 'number' },
|
|
965
1099
|
totalWords: { type: 'number' },
|
|
966
1100
|
overheadWords: { type: 'number' },
|
|
1101
|
+
// G1 / G4:写 MEMORY 前的容量(纯增量字段,旧客户端只是多看到几列)
|
|
1102
|
+
retiredEntries: { type: 'number' },
|
|
1103
|
+
headroom: { type: 'number' },
|
|
1104
|
+
extraWords: { type: 'number' },
|
|
1105
|
+
wouldTruncate: { type: 'boolean' },
|
|
1106
|
+
sameDateCount: { type: 'number' },
|
|
1107
|
+
format: { type: 'array', items: { type: 'string' } },
|
|
1108
|
+
suggestion: { type: 'string' },
|
|
1109
|
+
dropCandidates: {
|
|
1110
|
+
type: 'array',
|
|
1111
|
+
items: objSchema({
|
|
1112
|
+
title: { type: 'string' },
|
|
1113
|
+
date: { type: 'string' },
|
|
1114
|
+
words: { type: 'number' },
|
|
1115
|
+
reason: { type: 'string', enum: ['oldest', 'same-date', 'undated'] },
|
|
1116
|
+
}, ['title', 'date', 'words', 'reason']),
|
|
1117
|
+
},
|
|
967
1118
|
// 格式债 / 模板版本:只读元数据,比 memoryUsage 的投影早一步就能拿到
|
|
968
1119
|
formatDebt: objSchema({
|
|
969
1120
|
total: { type: 'number' },
|
|
@@ -1010,15 +1161,21 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1010
1161
|
retiredWords: { type: 'number' },
|
|
1011
1162
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
1012
1163
|
},
|
|
1013
|
-
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords',
|
|
1164
|
+
}, ['text', 'words', 'budget', 'ratio', 'truncatedWords', 'retiredWords', 'tocWords', 'totalWords', 'overheadWords',
|
|
1165
|
+
'retiredEntries', 'headroom', 'extraWords', 'wouldTruncate', 'sameDateCount', 'format', 'suggestion', 'dropCandidates',
|
|
1166
|
+
'formatDebt', 'templateVersion', 'persona', 'notebook', 'defaultNotebook', 'pinned', 'notebooks', 'files']),
|
|
1014
1167
|
},
|
|
1015
|
-
async run(
|
|
1168
|
+
async run(args, env) {
|
|
1016
1169
|
// 不 ensureNotebook:读记忆不该依赖 zk,笔记本不存在时就是空载荷
|
|
1017
1170
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
1018
1171
|
const state = sessionState(env.workspace, env.sessionId);
|
|
1019
1172
|
const payload = buildMemoryPayload(cfg);
|
|
1020
1173
|
return {
|
|
1021
1174
|
...payload,
|
|
1175
|
+
...memoryCapacity(cfg, {
|
|
1176
|
+
proposedEntry: args.proposed_entry ? String(args.proposed_entry) : undefined,
|
|
1177
|
+
extraWords: args.extra_words === undefined ? undefined : Number(args.extra_words),
|
|
1178
|
+
}),
|
|
1022
1179
|
notebook: state.active,
|
|
1023
1180
|
defaultNotebook: state.defaultName,
|
|
1024
1181
|
pinned: state.diverged ? state.pinned : '',
|
|
@@ -1038,8 +1195,18 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1038
1195
|
? `笔记本「${current.name}」(${current.structure})→ ${current.path}` +
|
|
1039
1196
|
(others.length ? `\n另有:${others.map((n) => `${n.name}(${n.structure})`).join('、')} —— zk_use 切换本会话` : '')
|
|
1040
1197
|
: `笔记本「${v.notebook}」`;
|
|
1198
|
+
// G1 / G4:写 MEMORY 前的余量、是否触发截断、同日决胜与「下一条会丢谁」
|
|
1199
|
+
const capacity = `\n\n容量:余 ${v.headroom} 词(记忆内容 ${v.words}/${v.budget},总载荷 ${v.totalWords})` +
|
|
1200
|
+
(v.extraWords > 0 ? ` · 拟新增 ${v.extraWords} 词${v.wouldTruncate ? '(会触发截断)' : ''}` : '') +
|
|
1201
|
+
(v.sameDateCount > 1 ? ` · ${v.sameDateCount} 条同日,按位置决胜` : '') +
|
|
1202
|
+
`\n${v.suggestion}` +
|
|
1203
|
+
(v.dropCandidates.length
|
|
1204
|
+
? '\n下一条会丢的 MEMORY 条目(预告,磁盘不动):\n' +
|
|
1205
|
+
v.dropCandidates.map((c, i) => `${i + 1}. ${c.title}(${c.words} 词 · ${c.reason}${c.date ? ' · ' + c.date : ''})`).join('\n')
|
|
1206
|
+
: '');
|
|
1041
1207
|
if (!v.text) {
|
|
1042
|
-
return text(drift + head +
|
|
1208
|
+
return text(drift + head + capacity +
|
|
1209
|
+
`\n\n知识库根目录没有 ${META_FILES.join(' / ')}(或都是空的),也没有 PERSONA.md 人格文件。`);
|
|
1043
1210
|
}
|
|
1044
1211
|
const persona = v.persona?.present
|
|
1045
1212
|
? `\n\n人格:正文(含标题)${v.persona.contentWords}/${v.persona.budget} 词` +
|
|
@@ -1047,7 +1214,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1047
1214
|
(v.persona.overBudget ? `,超 ${v.persona.overWords} 词(人格不截断)` : '')
|
|
1048
1215
|
: '\n\n人格:未启用(根目录没有 PERSONA.md)';
|
|
1049
1216
|
const totals = `\n\n用量:记忆载荷 ${v.totalWords} 词(预算 ${v.budget})`;
|
|
1050
|
-
return text(drift + head + persona + totals + (v.text ? '\n\n' + v.text : ''));
|
|
1217
|
+
return text(drift + head + persona + totals + capacity + (v.text ? '\n\n' + v.text : ''));
|
|
1051
1218
|
},
|
|
1052
1219
|
}),
|
|
1053
1220
|
t({
|
|
@@ -1060,6 +1227,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1060
1227
|
'incomplete 是 frontmatter 缺 type / status / authority 的笔记:缺失被索引落成空串,机械门会静默失效。' +
|
|
1061
1228
|
'tags 查标签卫生(大小写变体 / 单例,标签总数 ≥ 30 才报);template 说根目录 AGENTS.md 是不是当前版本。' +
|
|
1062
1229
|
'similarTitles 是「改一两个字」的疑似重复(同目录、二元组相似度 ≥ 0.6):与全等重名分开,只报告。' +
|
|
1230
|
+
'missingId 是缺稳定 id 的非日记笔记数:zk_new 新建的笔记自动写 id,老笔记只提示、不回填。' +
|
|
1063
1231
|
'timeline 是日记时间轴:最近 90 天的空块 / 倒序 / 格式(11:5x)/ 位置(layered 用 ##、或在 ## Events 外)问题,只报告不改文件。' +
|
|
1064
1232
|
'total / counts 按全量算,items 里每篇最多 50 条明细,整个桶最多 50 篇;skipped 是过大或读不到而没检查的篇数。' +
|
|
1065
1233
|
'indexHint=true 表示笔记(不含日记)已到 150 篇而根目录还没有 INDEX.md(只是提示,不生成静态索引)。' +
|
|
@@ -1084,6 +1252,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1084
1252
|
schema: objSchema({
|
|
1085
1253
|
notebook: { type: 'string' },
|
|
1086
1254
|
notes: { type: 'number' },
|
|
1255
|
+
missingId: { type: 'number' },
|
|
1087
1256
|
truncated: { type: 'boolean' },
|
|
1088
1257
|
completeness: { type: 'string', enum: ['complete', 'partial', 'unknown'] },
|
|
1089
1258
|
scanLimit: { type: 'number' },
|
|
@@ -1104,7 +1273,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1104
1273
|
timeline: LINT_TIMELINE,
|
|
1105
1274
|
indexHint: { type: 'boolean' },
|
|
1106
1275
|
indexLag: { type: 'string' },
|
|
1107
|
-
}, ['notebook', 'notes', 'truncated', 'completeness', 'scanLimit', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'persona', 'timeline', 'indexHint', 'indexLag']),
|
|
1276
|
+
}, ['notebook', 'notes', 'missingId', 'truncated', 'completeness', 'scanLimit', 'staleDays', 'parseErrors', 'orphans', 'brokenLinks', 'stale', 'tagless', 'oneWayLinks', 'duplicateTitles', 'similarTitles', 'memoryLinks', 'incomplete', 'tags', 'template', 'persona', 'timeline', 'indexHint', 'indexLag']),
|
|
1108
1277
|
},
|
|
1109
1278
|
async run(args, env) {
|
|
1110
1279
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1188,6 +1357,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1188
1357
|
'backlog 是窗口外仍未晋升的笔记(按被引数),漏做一次不会永久掉队。' +
|
|
1189
1358
|
'库超过全图统计上限时不再建全图统计入链(默认 2000 篇,设置页可调;graphBudget 给出生效值):' +
|
|
1190
1359
|
'graphSkipped=true,cited / citedBy / topCited 为空 —— 那是「没算」,不是「没人引」。' +
|
|
1360
|
+
'missingId 是缺稳定 id 的非日记笔记数(只提示、不回填);MEMORY 里可以用 [[<id>]] 当来源,改名后仍指向同一篇。' +
|
|
1191
1361
|
'memory 给记忆余量(内容词 + 提示 = 总词,余量按总词算,可以为负);retireCandidates 给「可考虑退役」的条目' +
|
|
1192
1362
|
'(来源归档 / 不存在、超过 ' + STALE_DAYS + ' 天未复核;显式写 archive/ 的有意引用不算)。' +
|
|
1193
1363
|
'days 省略时窗口 = 距 DREAMS.md「上次做梦」的天数(没有则 7 天)。' +
|
|
@@ -1209,12 +1379,17 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1209
1379
|
scanLimit: { type: 'number' },
|
|
1210
1380
|
graphSkipped: { type: 'boolean' },
|
|
1211
1381
|
graphBudget: { type: 'number' },
|
|
1382
|
+
missingId: { type: 'number' },
|
|
1212
1383
|
memory: objSchema({
|
|
1213
1384
|
words: { type: 'number' },
|
|
1214
1385
|
personaWords: { type: 'number' },
|
|
1215
1386
|
totalWords: { type: 'number' },
|
|
1216
1387
|
budget: { type: 'number' },
|
|
1217
1388
|
headroom: { type: 'number' },
|
|
1389
|
+
/** G1:与 zk_lint.memoryLinks 同一口径的格式债 / 退役计数 */
|
|
1390
|
+
undated: { type: 'number' },
|
|
1391
|
+
unlinked: { type: 'number' },
|
|
1392
|
+
retired: { type: 'number' },
|
|
1218
1393
|
files: {
|
|
1219
1394
|
type: 'array',
|
|
1220
1395
|
items: objSchema({
|
|
@@ -1225,7 +1400,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1225
1400
|
retiredWords: { type: 'number' },
|
|
1226
1401
|
}, ['name', 'present', 'words', 'originalWords', 'retiredWords']),
|
|
1227
1402
|
},
|
|
1228
|
-
}, ['words', 'personaWords', 'totalWords', 'budget', 'headroom', 'files']),
|
|
1403
|
+
}, ['words', 'personaWords', 'totalWords', 'budget', 'headroom', 'undated', 'unlinked', 'retired', 'files']),
|
|
1229
1404
|
counts: objSchema({
|
|
1230
1405
|
window: { type: 'number' },
|
|
1231
1406
|
daily: { type: 'number' },
|
|
@@ -1270,7 +1445,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1270
1445
|
reason: { type: 'string', enum: ['stale', 'source-missing', 'source-superseded'] },
|
|
1271
1446
|
}, ['entry', 'date', 'age', 'reason']),
|
|
1272
1447
|
},
|
|
1273
|
-
}, ['notebook', 'windowDays', 'since', 'truncated', 'completeness', 'scanLimit', 'graphSkipped', 'graphBudget', 'memory', 'counts', 'newNotes', 'alreadyPromoted', 'backlog', 'rejected', 'topCited', 'dailyLooseEnds', 'retireCandidates']),
|
|
1448
|
+
}, ['notebook', 'windowDays', 'since', 'truncated', 'completeness', 'scanLimit', 'graphSkipped', 'graphBudget', 'missingId', 'memory', 'counts', 'newNotes', 'alreadyPromoted', 'backlog', 'rejected', 'topCited', 'dailyLooseEnds', 'retireCandidates']),
|
|
1274
1449
|
},
|
|
1275
1450
|
async run(args, env) {
|
|
1276
1451
|
const cfg = configFor(env.workspace, env.sessionId);
|
|
@@ -1291,6 +1466,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
1291
1466
|
lines.push('记忆:内容 ' + v.memory.words + '/' + v.memory.budget + ' 词 + 提示 ' + promptWords +
|
|
1292
1467
|
' = ' + memoryTotal + ' 词(余 ' + v.memory.headroom + ')' +
|
|
1293
1468
|
(v.memory.personaWords > 0 ? ' · 人格 ' + v.memory.personaWords + ' 词(单独注入,不计入记忆预算)' : ''));
|
|
1469
|
+
if (v.missingId > 0)
|
|
1470
|
+
lines.push('· 稳定 ID:' + v.missingId + ' 篇没有 id — 新笔记自动写入,老笔记只提示、不回填(§9.2)');
|
|
1294
1471
|
if (v.retireCandidates.length) {
|
|
1295
1472
|
lines.push('可考虑退役:');
|
|
1296
1473
|
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 用它判断老库是否还在用旧模板(v9:改 MEMORY 前看 zk_context 余量) */
|
|
21
|
+
export const TEMPLATE_VERSION = 9;
|
|
22
22
|
/** 首行版本标记(实测 4 词);不许带日期 —— 带日期的写法实测 6 词,白花 2 词 */
|
|
23
23
|
export const TEMPLATE_MARK = `<!-- zdiary-template: v${TEMPLATE_VERSION} -->`;
|
|
24
24
|
/** 版本标记的正则(本文件内用;外部只通过 `templateVersionOf` 取数,免得又一个口径) */
|
|
@@ -37,6 +37,7 @@ export function templateVersionOf(body) {
|
|
|
37
37
|
*/
|
|
38
38
|
export const TEMPLATE_SENTINELS = {
|
|
39
39
|
8: { required: ['先 read 核对来源'], forbidden: ['DSH 不会自动加载', '从底部往前丢'] },
|
|
40
|
+
9: { required: ['先 read 核对来源', '改 MEMORY 前看 zk_context'], forbidden: ['DSH 不会自动加载', '从底部往前丢'] },
|
|
40
41
|
};
|
|
41
42
|
export const AGENTS_TEMPLATE = `${TEMPLATE_MARK}
|
|
42
43
|
|
|
@@ -64,6 +65,7 @@ notes/{concepts,entities,patterns}/ 原子笔记 · archive/ 废弃(不删)
|
|
|
64
65
|
每周:DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
|
|
65
66
|
MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 read 核对来源;退役写 - [superseded YYYY-MM-DD] 旧结论 → [[新结论]],行不删。
|
|
66
67
|
新条目写顶部;超预算按日期丢最旧的一条。
|
|
68
|
+
改 MEMORY 前看 zk_context 余量(WORKFLOW.md 有做法)。
|
|
67
69
|
`;
|
|
68
70
|
/**
|
|
69
71
|
* flat 结构用的模板:不出现 raw / inbox / archive / WORKFLOW.md 这些 flat 没有的路径。
|
|
@@ -83,6 +85,7 @@ export const AGENTS_TEMPLATE_FLAT = `${TEMPLATE_MARK}
|
|
|
83
85
|
|
|
84
86
|
DREAMS.md 写「上次做梦:YYYY-MM-DD」;到期 zk_lint → zk_dream → 人裁决改 MEMORY。
|
|
85
87
|
MEMORY.md 每条:结论(YYYY-MM-DD)[[来源路径]],先 read 核对来源;退役写 - [superseded] 旧结论 → [[新结论]]。
|
|
88
|
+
改 MEMORY 前看 zk_context 余量。
|
|
86
89
|
`;
|
|
87
90
|
/**
|
|
88
91
|
* 根目录 WORKFLOW.md:只在「要动已有笔记」时才需要读,所以不注入、不计预算。
|
|
@@ -103,6 +106,11 @@ export const WORKFLOW_TEMPLATE = `${TEMPLATE_MARK}
|
|
|
103
106
|
|
|
104
107
|
判断不了就按 3 处理:flag 的成本远低于悄悄改写。
|
|
105
108
|
|
|
109
|
+
## 改 MEMORY.md 之前
|
|
110
|
+
|
|
111
|
+
先看 zk_context 的 headroom 与 dropCandidates:余量不够就先退役 / 精简旧条目,别让新结论把最旧的挤掉。
|
|
112
|
+
给 proposed_entry 能预估会不会触发截断;同日条目按位置决胜(sameDateCount),插件不猜谁更常用。
|
|
113
|
+
|
|
106
114
|
## 动笔前必须出清单
|
|
107
115
|
|
|
108
116
|
1. 用 zk_search / zk_query 找出可能受影响的笔记;
|
package/dist/lib/dream.js
CHANGED
|
@@ -20,7 +20,7 @@ import { parseFrontmatter } from './frontmatter.js';
|
|
|
20
20
|
import { memoryUsage } from './memory.js';
|
|
21
21
|
import { daysSinceDate, entryDate, isRetiredEntry, splitMemoryEntries, stripRetiredEntries } from './memory-format.js';
|
|
22
22
|
import { isDayString } from './dates.js';
|
|
23
|
-
import { normalizeTitle, resolveWikiTarget, WIKI_LINK, wikiIndex } from './wikilink.js';
|
|
23
|
+
import { normalizeTitle, noteKey, resolveWikiTarget, WIKI_LINK, wikiIndex } from './wikilink.js';
|
|
24
24
|
/** 每栏最多回多少条(计划 §4 M3 的 50 条上限) */
|
|
25
25
|
export const MAX_ITEMS = 50;
|
|
26
26
|
/** topCited 只取前几名:给 agent 一个「本周被反复引用」的提示,不是排行榜 */
|
|
@@ -211,20 +211,24 @@ function promotionsOf(cfg, notes) {
|
|
|
211
211
|
if (!body.trim())
|
|
212
212
|
return out;
|
|
213
213
|
const index = wikiIndex(notes);
|
|
214
|
+
const byPath = new Map(notes.map((n) => [n.path, n]));
|
|
214
215
|
for (const match of body.matchAll(WIKI_LINK)) {
|
|
215
216
|
const hit = resolveWikiTarget(cfg, String(match[1] ?? '').trim(), index);
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
// 解析结果是路径,按身份键记账(§9.2):有 id 的笔记改名后仍是同一篇,不会重复晋升。
|
|
218
|
+
const note = byPath.get(hit.path);
|
|
219
|
+
if (hit.status === 'live' && note)
|
|
220
|
+
out.set(noteKey(note), 'link');
|
|
218
221
|
}
|
|
219
222
|
const lines = stripRetiredEntries(body).body.split('\n').map((line) => normalizeTitle(line)).filter(Boolean);
|
|
220
223
|
for (const note of notes) {
|
|
221
|
-
|
|
224
|
+
const key = noteKey(note);
|
|
225
|
+
if (out.has(key))
|
|
222
226
|
continue;
|
|
223
|
-
const
|
|
224
|
-
if ([...
|
|
227
|
+
const title = normalizeTitle(note.title);
|
|
228
|
+
if ([...title].length < MIN_TITLE_MATCH)
|
|
225
229
|
continue;
|
|
226
|
-
if (lines.some((line) => line.includes(
|
|
227
|
-
out.set(
|
|
230
|
+
if (lines.some((line) => line.includes(title)))
|
|
231
|
+
out.set(key, 'title');
|
|
228
232
|
}
|
|
229
233
|
return out;
|
|
230
234
|
}
|
|
@@ -360,7 +364,7 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
|
|
|
360
364
|
if (isUnder(note.path, cfg.dailyDir))
|
|
361
365
|
continue;
|
|
362
366
|
// 已经进 MEMORY 的先说:否则每周原样重复,仪式几次之后就没人看了
|
|
363
|
-
const by = promoted.get(note
|
|
367
|
+
const by = promoted.get(noteKey(note));
|
|
364
368
|
if (by) {
|
|
365
369
|
alreadyPromoted.push(candidateOf(note, by));
|
|
366
370
|
continue;
|
|
@@ -380,7 +384,7 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
|
|
|
380
384
|
const at = dayMs(noteDate(cfg, n));
|
|
381
385
|
if (Number.isFinite(at) && at >= sinceMs)
|
|
382
386
|
return false;
|
|
383
|
-
if (promoted.has(n
|
|
387
|
+
if (promoted.has(noteKey(n)))
|
|
384
388
|
return false;
|
|
385
389
|
return rejectionReason(n) === null;
|
|
386
390
|
})
|
|
@@ -425,6 +429,8 @@ export async function dreamNotebook(cfg, opts = {}, signal) {
|
|
|
425
429
|
scanLimit: scan.limit,
|
|
426
430
|
graphSkipped: !graphReady,
|
|
427
431
|
graphBudget,
|
|
432
|
+
// 只读计数:老笔记 / 日记没有 id 属预期,日记按日期命名、路径天然稳定,不计入
|
|
433
|
+
missingId: notes.filter((n) => !n.id && !isUnder(n.path, cfg.dailyDir)).length,
|
|
428
434
|
counts: {
|
|
429
435
|
window: windowNotes.length,
|
|
430
436
|
daily: windowNotes.filter((n) => isUnder(n.path, cfg.dailyDir)).length,
|
package/dist/lib/lint.js
CHANGED
|
@@ -287,6 +287,9 @@ export function formatLintExtras(r) {
|
|
|
287
287
|
const timeline = formatTimeline(r.timeline);
|
|
288
288
|
if (timeline)
|
|
289
289
|
lines.push(timeline);
|
|
290
|
+
if (r.missingId > 0) {
|
|
291
|
+
lines.push(`· 稳定 ID:${r.missingId} 篇没有 id — 新建的笔记已自动写入,老笔记只提示、不回填(§9.2)`);
|
|
292
|
+
}
|
|
290
293
|
// 缺文件 = 人格未启用(默认状态):不报错、不占行。
|
|
291
294
|
// 有旧版 / 占位符 / 标记不符时才提醒 —— 否则每个老库每次 lint 都多一条永久 ⚠️,反而训练人忽略告警。
|
|
292
295
|
const persona = r.persona.items;
|
|
@@ -925,6 +928,8 @@ export async function lintNotebook(cfg, opts = {}, signal) {
|
|
|
925
928
|
return {
|
|
926
929
|
notebook: cfg.notebook,
|
|
927
930
|
notes: notes.length,
|
|
931
|
+
// 只读计数:日记按日期命名、路径天然稳定,不计入;老笔记缺 id 属预期,不回填
|
|
932
|
+
missingId: nonDaily.filter((n) => !n.id).length,
|
|
928
933
|
truncated: scanTruncated,
|
|
929
934
|
completeness,
|
|
930
935
|
scanLimit: scan.limit,
|