dsh-zdiary-kit 3.4.0 → 3.6.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/dist/lib/lint.js CHANGED
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import fs from 'node:fs';
26
26
  import path from 'node:path';
27
- import { allNotes, backlinksOf, GRAPH_BUDGET_NOTES, graphEdges, localDate, MAX_SCAN, notesWithFlag, outlinksOf, parseErrorWarnings, } from './zk.js';
27
+ import { backlinksOf, GRAPH_BUDGET_NOTES, graphEdges, indexLagHint, localDate, MAX_SCAN, scanNotes, scanNotesWithFlag, outlinksOf, parseErrorWarnings, } from './zk.js';
28
28
  import { normalizeTitle, resolveWikiTarget, WIKI_LINK, wikiIndex } from './wikilink.js';
29
29
  import { parseFrontmatter } from './frontmatter.js';
30
30
  import { daysSinceDate, entryDate, isRetiredEntry, memoryFormatDebt, splitMemoryEntries } from './memory-format.js';
@@ -91,11 +91,13 @@ export function similarTitles(notes, scanTruncated, max = MAX_ITEMS) {
91
91
  groups.set(dir, list);
92
92
  }
93
93
  let truncated = scanTruncated;
94
+ let droppedGroups = 0;
94
95
  const found = [];
95
96
  for (const group of groups.values()) {
96
97
  let list = group;
97
98
  if (list.length > SIMILAR_GROUP_MAX) {
98
99
  truncated = true;
100
+ droppedGroups += 1;
99
101
  list = list.slice(0, SIMILAR_GROUP_MAX);
100
102
  }
101
103
  for (let i = 0; i < list.length; i++) {
@@ -118,7 +120,8 @@ export function similarTitles(notes, scanTruncated, max = MAX_ITEMS) {
118
120
  }
119
121
  }
120
122
  found.sort((a, b) => b.score - a.score || a.paths[0].localeCompare(b.paths[0]));
121
- return { total: found.length, truncated, items: found.slice(0, max) };
123
+ const completeness = truncated ? 'partial' : 'complete';
124
+ return { total: found.length, truncated, completeness, droppedGroups, items: found.slice(0, max) };
122
125
  }
123
126
  /** 注入的三份 meta 里只有 MEMORY / USER 会写来源链接;AGENTS 是规则,不查 */
124
127
  const MEMORY_LINK_FILES = ['MEMORY.md', 'USER.md'];
@@ -673,10 +676,17 @@ export async function lintNotebook(cfg, opts = {}, signal) {
673
676
  const warnings = [];
674
677
  const dailyAbs = path.resolve(cfg.notebook, cfg.dailyDir);
675
678
  const isDaily = (abs) => path.resolve(abs) === dailyAbs || path.resolve(abs).startsWith(dailyAbs + path.sep);
676
- const notes = await allNotes(cfg, { warnings }, signal);
677
- const orphanAbs = await notesWithFlag(cfg, '--orphan', signal);
678
- const brokenAbs = await notesWithFlag(cfg, '--broken-links', signal);
679
- const taglessAbs = await notesWithFlag(cfg, '--tagless', signal);
679
+ const scan = await scanNotes(cfg, { warnings }, signal);
680
+ const notes = scan.notes;
681
+ const orphanScan = await scanNotesWithFlag(cfg, '--orphan', signal);
682
+ const brokenScan = await scanNotesWithFlag(cfg, '--broken-links', signal);
683
+ const taglessScan = await scanNotesWithFlag(cfg, '--tagless', signal);
684
+ const orphanAbs = orphanScan.paths;
685
+ const brokenAbs = brokenScan.paths;
686
+ const taglessAbs = taglessScan.paths;
687
+ // 任一过滤器触顶都意味着对应桶少了;三态取最坏值(partial > unknown > complete)
688
+ const worst = (values) => values.includes('partial') ? 'partial' : values.includes('unknown') ? 'unknown' : 'complete';
689
+ const completeness = worst([scan.completeness, orphanScan.completeness, brokenScan.completeness, taglessScan.completeness]);
680
690
  // 别用 `path.resolve(n.absPath || n.path)`:absPath 缺失时相对路径会按进程 cwd 解析,键就错了。
681
691
  const byAbs = new Map(notes.map((n) => [n.absPath ? path.resolve(n.absPath) : path.resolve(cfg.notebook, n.path), n]));
682
692
  const byPath = new Map(notes.map((n) => [n.path, n]));
@@ -775,13 +785,15 @@ export async function lintNotebook(cfg, opts = {}, signal) {
775
785
  const oneWayByQueries = async () => {
776
786
  let left = MAX_ONE_WAY_QUERIES;
777
787
  const spend = () => (left > 0 ? ((left -= 1), true) : false);
778
- const missingAbs = await notesWithFlag(cfg, '--missing-backlink', signal);
779
- const targets = missingAbs
788
+ const missing = await scanNotesWithFlag(cfg, '--missing-backlink', signal);
789
+ let truncated = missing.completeness !== 'complete';
790
+ const targets = missing.paths
780
791
  .map((abs) => path.relative(cfg.notebook, abs).split(path.sep).join('/'))
781
792
  .filter((rel) => byPath.has(rel) && !isDaily(path.resolve(cfg.notebook, rel)))
782
793
  .sort((a, b) => a.localeCompare(b));
783
794
  const capped = targets.slice(0, MAX_ONE_WAY_TARGETS);
784
- let truncated = targets.length > capped.length;
795
+ if (targets.length > capped.length)
796
+ truncated = true;
785
797
  const rows = [];
786
798
  for (const target of capped) {
787
799
  if (!spend()) {
@@ -819,9 +831,11 @@ export async function lintNotebook(cfg, opts = {}, signal) {
819
831
  const graphBudget = Math.max(0, Math.trunc(opts.graphBudget ?? cfg.graphBudgetNotes ?? GRAPH_BUDGET_NOTES));
820
832
  const oneWayRows = [];
821
833
  let oneWayTruncated = false;
834
+ let oneWayCompleteness = 'complete';
822
835
  if (notes.length <= graphBudget) {
823
836
  const graph = await graphEdges(cfg, signal);
824
837
  oneWayTruncated = graph.truncated;
838
+ oneWayCompleteness = graph.completeness;
825
839
  // 图里的路径是笔记本相对:先拼回绝对路径再判断是不是日记(isDaily 收的是绝对路径)
826
840
  for (const row of oneWayLinks(graph.edges, notes, (p) => isDaily(path.resolve(cfg.notebook, p)))) {
827
841
  oneWayRows.push({
@@ -834,6 +848,7 @@ export async function lintNotebook(cfg, opts = {}, signal) {
834
848
  const scanned = await oneWayByQueries();
835
849
  oneWayRows.push(...scanned.rows);
836
850
  oneWayTruncated = scanned.truncated;
851
+ oneWayCompleteness = scanned.truncated ? 'partial' : 'complete';
837
852
  }
838
853
  const linksOnly = opts.linksOnly === true;
839
854
  const oneWayItems = [];
@@ -887,10 +902,11 @@ export async function lintNotebook(cfg, opts = {}, signal) {
887
902
  bodyOnly,
888
903
  linksOnly,
889
904
  edgesTruncated: oneWayTruncated,
905
+ completeness: oneWayCompleteness,
890
906
  items: oneWayItems.slice(0, MAX_ITEMS),
891
907
  };
892
908
  const parseErrors = parseErrorWarnings(cfg, warnings);
893
- const scanTruncated = notes.length >= MAX_SCAN;
909
+ const scanTruncated = completeness !== 'complete';
894
910
  const staleNotes = notes
895
911
  .map((n) => ({ note: n, at: Date.parse(n.modified) }))
896
912
  .filter((x) => Number.isFinite(x.at) && x.at < cutoff)
@@ -910,6 +926,8 @@ export async function lintNotebook(cfg, opts = {}, signal) {
910
926
  notebook: cfg.notebook,
911
927
  notes: notes.length,
912
928
  truncated: scanTruncated,
929
+ completeness,
930
+ scanLimit: scan.limit,
913
931
  staleDays,
914
932
  parseErrors: { total: parseErrors.length, items: parseErrors.slice(0, MAX_ITEMS) },
915
933
  orphans: bucket(orphanAbs.filter((abs) => !isDaily(abs))),
@@ -930,5 +948,7 @@ export async function lintNotebook(cfg, opts = {}, signal) {
930
948
  timeline: timelineStatus(cfg, now),
931
949
  // 150 篇(不含日记)是检索开始变糊的拐点:提示一下,不生成静态索引(会过期,还要决定谁更新)
932
950
  indexHint: nonDaily.length >= 150 && !fs.existsSync(path.join(cfg.notebook, 'INDEX.md')),
951
+ // 放在最后算:前面的读命令已经把 pending 的 dirty 补掉了,剩下的是「补不上 / 外部编辑」
952
+ indexLag: indexLagHint(cfg) ?? '',
933
953
  };
934
954
  }