dsh-zdiary-kit 0.7.6 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -16
- package/dist/app/plugin.js +54 -20
- package/dist/cli.js +170 -25
- package/dist/config/store.js +37 -0
- package/dist/features/readonly/feature.js +563 -0
- package/dist/features/readonly/html.js +255 -0
- package/dist/features/settings/client.js +32 -9
- package/dist/features/settings/feature.js +71 -17
- package/dist/features/zk-tools/feature.js +228 -42
- package/dist/lib/agents-template.js +49 -11
- package/dist/lib/dream.js +213 -16
- package/dist/lib/http.js +26 -0
- package/dist/lib/lint.js +329 -90
- package/dist/lib/memory-format.js +100 -0
- package/dist/lib/memory.js +201 -24
- package/dist/lib/notebook-config.js +188 -0
- package/dist/lib/notebook.js +357 -21
- package/dist/lib/wikilink.js +77 -0
- package/dist/lib/zk.js +108 -17
- package/docs/features/memory.md +76 -9
- package/docs/features/provisioning.md +47 -9
- package/docs/features/readonly.md +73 -0
- package/docs/features/settings.md +20 -6
- package/docs/features/zk-tools.md +64 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,17 +6,18 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { config, writeConfig, selectNotebook, isNotebookName, CONFIG_KEYS } from './config/store.js';
|
|
8
8
|
import { CFG_FILE } from './config/paths.js';
|
|
9
|
-
import { NOTE_KINDS, ensureNotebook, newNoteDir, structureStatus } from './lib/notebook.js';
|
|
9
|
+
import { NOTE_KINDS, ensureNotebook, fixGroupConfig, groupOverlapNotes, newNoteDir, structureStatus } from './lib/notebook.js';
|
|
10
10
|
import { buildMemoryPayload, formatFileShares } from './lib/memory.js';
|
|
11
11
|
import { installZk, sourceLabel } from './lib/install.js';
|
|
12
|
-
import { resolveZk,
|
|
13
|
-
import { formatMemoryLinks, lintNotebook } from './lib/lint.js';
|
|
14
|
-
import { dreamNotebook } from './lib/dream.js';
|
|
12
|
+
import { resolveZk, searchNotesDetailed, queryNotes, createNote, readNote, findNote, appendToNote, ensureDailyNote, appendDaily, linkNotes, notebookStats, indexNotebook, withTags, taglessCjkWarning, hasNotebook, localDate, ZkError, allNotes, parseErrorWarnings, } from './lib/zk.js';
|
|
13
|
+
import { formatLintExtras, formatMemoryLinks, lintNotebook } from './lib/lint.js';
|
|
14
|
+
import { dreamNotebook, STALE_DAYS } from './lib/dream.js';
|
|
15
15
|
const HELP = `zk-kit —— dsh-zdiary-kit 的命令行
|
|
16
16
|
|
|
17
17
|
zk-kit doctor 自检:zk / 笔记本 / 模板 / group / 索引
|
|
18
18
|
zk-kit install [版本] 安装内置 zk(默认取配置里的版本)
|
|
19
|
-
zk-kit init
|
|
19
|
+
zk-kit init [--with-agents] 建好(或补齐)笔记本;flat 下加 --with-agents 才写 AGENTS.md 模板
|
|
20
|
+
zk-kit groups [--fix] [--dry-run] 对照配置与 .zk/config.toml 的 group(默认 dry-run;--fix 只改插件建的 paths,写前备份)
|
|
20
21
|
zk-kit new --title T [--name 文件名] [--summary 摘要] [--body B] [--tags a,b] [--dir notes] [--type source|concept|entity|pattern]
|
|
21
22
|
zk-kit search [词] [--tags a,b] [--since 日期] [--limit 5] [--json]
|
|
22
23
|
zk-kit read <路径> | --query 词 [--max-chars n] [--json]
|
|
@@ -25,7 +26,7 @@ const HELP = `zk-kit —— dsh-zdiary-kit 的命令行
|
|
|
25
26
|
zk-kit link <来源路径> <目标路径或标题>
|
|
26
27
|
zk-kit lint [--stale-days 90] [--links-only]
|
|
27
28
|
体检:断链 / 孤儿 / 无标签 / 单向链接 / 陈旧 / 重名(只读)
|
|
28
|
-
zk-kit dream [--days
|
|
29
|
+
zk-kit dream [--days N] 晋升材料:窗口新增 / daily 未完成 / 被引最多(只读;不传 days 就按 DREAMS.md 的上次做梦算窗口)
|
|
29
30
|
zk-kit query [-- <zk list 参数>] 透传 zk list(--notebook-dir / --format / -x 会被替换掉)
|
|
30
31
|
zk-kit index 重建索引
|
|
31
32
|
zk-kit notebooks 列出所有笔记本(* 是当前那个;[flat/layered] 是各自的结构)
|
|
@@ -169,6 +170,9 @@ function lintReport(r) {
|
|
|
169
170
|
const memLine = formatMemoryLinks(r.memoryLinks);
|
|
170
171
|
if (memLine)
|
|
171
172
|
lines.push(memLine);
|
|
173
|
+
lines.push(...formatLintExtras(r));
|
|
174
|
+
if (r.similarTitles.truncated)
|
|
175
|
+
lines.push('⚠️ 疑似重复只比较了部分笔记(同目录超过 300 篇或扫描触顶):可能漏报');
|
|
172
176
|
if (r.truncated)
|
|
173
177
|
lines.push('⚠️ 笔记数触到扫描上限:结果不完整(只会漏报,不会误报)');
|
|
174
178
|
if (oneWay.edgesTruncated)
|
|
@@ -178,19 +182,47 @@ function lintReport(r) {
|
|
|
178
182
|
}
|
|
179
183
|
function dreamReport(r) {
|
|
180
184
|
const lines = [
|
|
181
|
-
`做梦:近 ${r.windowDays} 天(自 ${r.since})— 窗口 ${r.counts.window} 篇(日记 ${r.counts.daily})· 候选 ${r.counts.candidates} · 拒绝 ${r.counts.rejected} · 未完成 ${r.counts.looseEnds}`,
|
|
185
|
+
`做梦:近 ${r.windowDays} 天(自 ${r.since})— 窗口 ${r.counts.window} 篇(日记 ${r.counts.daily})· 候选 ${r.counts.candidates} · 拒绝 ${r.counts.rejected} · 未完成 ${r.counts.looseEnds} · 已晋升 ${r.counts.promoted} · 积压 ${r.counts.backlog}`,
|
|
182
186
|
];
|
|
187
|
+
// 余量按总词算:只报内容词等于说「还有 10 词」,而框与提示早就把它吃完了
|
|
188
|
+
lines.push(`记忆:内容 ${r.memory.words}/${r.memory.budget} 词 + 提示 ${r.memory.totalWords - r.memory.words} = ${r.memory.totalWords} 词(余 ${r.memory.headroom})`);
|
|
189
|
+
if (r.retireCandidates.length) {
|
|
190
|
+
lines.push('可考虑退役:');
|
|
191
|
+
for (const c of r.retireCandidates.slice(0, 10)) {
|
|
192
|
+
const when = c.date ? `${c.date}(${c.age} 天)` : '无日期';
|
|
193
|
+
const why = c.reason === 'stale'
|
|
194
|
+
? `超过 ${STALE_DAYS} 天未复核`
|
|
195
|
+
: c.reason === 'source-superseded' ? '来源已归档' : '来源不存在';
|
|
196
|
+
lines.push(` · ${c.entry} — ${when} · ${why}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
183
199
|
if (r.newNotes.length) {
|
|
184
200
|
lines.push('晋升候选:');
|
|
185
201
|
for (const [i, n] of r.newNotes.slice(0, 10).entries()) {
|
|
186
202
|
const tags = n.tags.length ? ' · ' + n.tags.map((t) => '#' + t).join(' ') : '';
|
|
187
203
|
const lead = n.lead ? `\n ${n.lead}` : '';
|
|
188
204
|
const citedBy = n.citedBy.length ? `\n 被引:${n.citedBy.join('、')}` : '';
|
|
189
|
-
|
|
205
|
+
const used = n.daysMentioned > 0 ? ` · 日记 ${n.daysMentioned} 天` : '';
|
|
206
|
+
lines.push(` ${i + 1}. ${n.title || n.path} [${n.type || '—'} · ${n.authority || '—'}] ${n.path}${tags} · 被引 ${n.cited}${used}${lead}${citedBy}`);
|
|
190
207
|
}
|
|
191
208
|
if (r.newNotes.length > 10)
|
|
192
209
|
lines.push(` …还有 ${r.newNotes.length - 10} 篇`);
|
|
193
210
|
}
|
|
211
|
+
if (r.alreadyPromoted.length) {
|
|
212
|
+
lines.push('已在 MEMORY(不再重复提):');
|
|
213
|
+
for (const n of r.alreadyPromoted.slice(0, 10)) {
|
|
214
|
+
lines.push(` · ${n.title || n.path}(${n.path})· ${n.promotedBy === 'link' ? '按链接命中' : '标题出现在条目里'}`);
|
|
215
|
+
}
|
|
216
|
+
if (r.alreadyPromoted.length > 10)
|
|
217
|
+
lines.push(` …还有 ${r.alreadyPromoted.length - 10} 篇`);
|
|
218
|
+
}
|
|
219
|
+
if (r.backlog.length) {
|
|
220
|
+
lines.push('窗口外仍未晋升(按被引数):');
|
|
221
|
+
for (const n of r.backlog.slice(0, 10))
|
|
222
|
+
lines.push(` · ${n.title || n.path}(${n.path})· 被引 ${n.cited}`);
|
|
223
|
+
if (r.counts.backlog > r.backlog.length)
|
|
224
|
+
lines.push(` …还有 ${r.counts.backlog - r.backlog.length} 篇`);
|
|
225
|
+
}
|
|
194
226
|
if (r.rejected.length) {
|
|
195
227
|
lines.push('机械拒绝(不进候选):');
|
|
196
228
|
for (const x of r.rejected.slice(0, 10))
|
|
@@ -205,8 +237,10 @@ function dreamReport(r) {
|
|
|
205
237
|
}
|
|
206
238
|
if (r.topCited.length) {
|
|
207
239
|
lines.push('被引用最多:');
|
|
208
|
-
for (const [i, c] of r.topCited.slice(0, 5).entries())
|
|
209
|
-
lines.push(` ${i + 1}. ${c.title || c.path}(${c.path})· ${c.cited} 次`
|
|
240
|
+
for (const [i, c] of r.topCited.slice(0, 5).entries()) {
|
|
241
|
+
lines.push(` ${i + 1}. ${c.title || c.path}(${c.path})· 被引 ${c.cited} 次` +
|
|
242
|
+
(c.daysMentioned > 0 ? ` · 日记 ${c.daysMentioned} 天(最近 ${c.lastMentioned})` : ''));
|
|
243
|
+
}
|
|
210
244
|
}
|
|
211
245
|
if (!r.newNotes.length && !r.dailyLooseEnds.length && !r.topCited.length)
|
|
212
246
|
lines.push('这个窗口里没有新材料。');
|
|
@@ -215,6 +249,70 @@ function dreamReport(r) {
|
|
|
215
249
|
lines.push('(只报告:MEMORY.md / DREAMS.md 由你按 AGENTS.md 写)');
|
|
216
250
|
return lines.join('\n');
|
|
217
251
|
}
|
|
252
|
+
/** group 路径重叠:config = 配置本身冲突(⚠️),file = config.toml 里已经撞了(✗) */
|
|
253
|
+
function overlapLines(st) {
|
|
254
|
+
return groupOverlapNotes(st).map((note) => `${note.level === 'file' ? '✗' : '⚠️'} ${note.text}`);
|
|
255
|
+
}
|
|
256
|
+
function groupsReport(cfg, st, fixed) {
|
|
257
|
+
if (fixed) {
|
|
258
|
+
if (!fixed.changed) {
|
|
259
|
+
// 有 skip 就不是「没需要修的」—— 是「想修但修不了」,得说清哪一条没改
|
|
260
|
+
const skipped = fixed.updates.filter((update) => update.action === 'skip');
|
|
261
|
+
const lines = [`group 配置:${fixed.notebook} —— ${skipped.length ? '没有写文件' : '没有需要修的(未写文件)'}`];
|
|
262
|
+
for (const update of skipped)
|
|
263
|
+
lines.push(` · ${update.name}:未改 —— ${update.reason ?? ''}`);
|
|
264
|
+
for (const warning of fixed.warnings)
|
|
265
|
+
lines.push('⚠️ ' + warning);
|
|
266
|
+
return lines.join('\n');
|
|
267
|
+
}
|
|
268
|
+
const lines = [`已修复 group 配置:${fixed.notebook}(备份 ${fixed.backup})`];
|
|
269
|
+
for (const update of fixed.updates) {
|
|
270
|
+
if (update.action === 'paths') {
|
|
271
|
+
lines.push(` ✓ ${update.name}:${update.actualPaths?.join('、') ?? '解析不了'} → ${update.expectedPaths.join('、')}`);
|
|
272
|
+
}
|
|
273
|
+
else if (update.action === 'rename') {
|
|
274
|
+
lines.push(` ✓ ${update.from} → ${update.name}(只改组头,路径与模板不变)`);
|
|
275
|
+
}
|
|
276
|
+
else if (update.action === 'append') {
|
|
277
|
+
lines.push(` + ${update.name}:追加 ${update.expectedPaths.join('、')}`);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
lines.push(` · ${update.name}:未改 —— ${update.reason ?? ''}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
lines.push(...overlapLines(st));
|
|
284
|
+
for (const warning of fixed.warnings)
|
|
285
|
+
lines.push('⚠️ ' + warning);
|
|
286
|
+
lines.push('(只改插件建的 group 的 paths / 组头;template / extra / 自定义 group 一字未动)');
|
|
287
|
+
return lines.join('\n');
|
|
288
|
+
}
|
|
289
|
+
const lines = [`group 配置:${cfg.notebook}${st.groupsOk ? '(与配置一致)' : ''}`];
|
|
290
|
+
if (!fs.existsSync(path.join(cfg.notebook, '.zk', 'config.toml'))) {
|
|
291
|
+
lines.push('✗ 还没有 .zk/config.toml —— 先跑 zk-kit init');
|
|
292
|
+
return lines.join('\n');
|
|
293
|
+
}
|
|
294
|
+
for (const group of st.groups) {
|
|
295
|
+
if (!group.present) {
|
|
296
|
+
lines.push(group.conflict
|
|
297
|
+
? `✗ ${group.name}:缺(路径 ${group.expectedPaths.join('、')} 已被 group "${group.conflict}" 占用)`
|
|
298
|
+
: `✗ ${group.name}:缺(期望 ${group.expectedPaths.join('、')})`);
|
|
299
|
+
}
|
|
300
|
+
else if (group.duplicate) {
|
|
301
|
+
lines.push(`⚠️ ${group.name}:重复出现,解析不了`);
|
|
302
|
+
}
|
|
303
|
+
else if (!group.pathsOk) {
|
|
304
|
+
lines.push(`⚠️ ${group.name}:期望 ${group.expectedPaths.join('、')},实际 ${group.actualPaths?.join('、') ?? '解析不了'}` +
|
|
305
|
+
(group.actualPaths === null ? '(可能是多行数组,手动编辑 .zk/config.toml)' : ''));
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
const template = group.templateOk ? '' : ` · template=${group.actualTemplate ?? '(无)'}(配置期望 ${group.expectedTemplate})`;
|
|
309
|
+
lines.push(`✓ ${group.name}:${group.actualPaths?.join('、')}${template}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
lines.push(...overlapLines(st));
|
|
313
|
+
lines.push('(dry-run:不改文件;--fix 只改 dsh-zdiary-kit 建的 group 的 paths,写前备份 .zk/config.toml.bak)');
|
|
314
|
+
return lines.join('\n');
|
|
315
|
+
}
|
|
218
316
|
async function doctor() {
|
|
219
317
|
const cfg = config();
|
|
220
318
|
const zk = await resolveZk(cfg);
|
|
@@ -224,25 +322,49 @@ async function doctor() {
|
|
|
224
322
|
rows.push(`${exists ? '✓' : '✗'} 笔记本:${cfg.notebook}${exists ? '' : '(不是 zk 笔记本 —— 跑 zk-kit init)'}`);
|
|
225
323
|
const template = path.join(cfg.notebook, '.zk', 'templates', 'daily.md');
|
|
226
324
|
rows.push(`${fs.existsSync(template) ? '✓' : '✗'} 日记模板:${template}`);
|
|
227
|
-
let group = false;
|
|
228
|
-
try {
|
|
229
|
-
group = new RegExp(`^\\[group\\."?${cfg.dailyGroup}"?\\]`, 'm').test(fs.readFileSync(path.join(cfg.notebook, '.zk', 'config.toml'), 'utf8'));
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
group = false;
|
|
233
|
-
}
|
|
234
|
-
rows.push(`${group ? '✓' : '✗'} 日记 group:${cfg.dailyGroup} → ${cfg.dailyDir}/`);
|
|
235
325
|
const st = structureStatus(cfg);
|
|
326
|
+
for (const group of st.groups) {
|
|
327
|
+
if (!group.present) {
|
|
328
|
+
rows.push(group.conflict
|
|
329
|
+
? `✗ group ${group.name}:缺(期望 ${group.expectedPaths.join('、')},已被 group "${group.conflict}" 占用;跑 zk-kit groups --fix)`
|
|
330
|
+
: `✗ group ${group.name}:缺(期望 ${group.expectedPaths.join('、')};跑 zk-kit groups --fix)`);
|
|
331
|
+
}
|
|
332
|
+
else if (group.duplicate) {
|
|
333
|
+
rows.push(`⚠️ group ${group.name}:重复出现,解析不了 —— 手动检查 .zk/config.toml`);
|
|
334
|
+
}
|
|
335
|
+
else if (!group.pathsOk) {
|
|
336
|
+
rows.push(`⚠️ group ${group.name}:期望 ${group.expectedPaths.join('、')},实际 ${group.actualPaths?.join('、') ?? '解析不了'}` +
|
|
337
|
+
(group.actualPaths === null ? '(可能是多行数组 —— 手动编辑 .zk/config.toml)' : '(跑 zk-kit groups --fix)'));
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
const templateNote = group.templateOk ? '' : ` · template=${group.actualTemplate ?? '(无)'}`;
|
|
341
|
+
rows.push(`✓ group ${group.name}:${group.actualPaths?.join('、')}${templateNote}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
rows.push(...overlapLines(st));
|
|
236
345
|
const structureOk = st.ready && (!st.agents.required || st.agents.present);
|
|
346
|
+
const drift = st.mode === 'flat' && st.extra.length
|
|
347
|
+
? ` · ⚠️ 盘上有分层目录 ${st.extra.join('、')}:新建笔记会落在 ${cfg.notesDir}/ 根`
|
|
348
|
+
: '';
|
|
237
349
|
rows.push(`${structureOk ? '✓' : '✗'} 结构:${st.mode} · ` +
|
|
238
350
|
(st.ready ? `${st.dirs.length} 个目录齐全` : `缺 ${st.missing.join('、')}(跑 zk-kit init)`) +
|
|
239
|
-
(st.agents.required ? (st.agents.present ? ' · AGENTS.md 就绪' : ' · 缺 AGENTS.md(跑 zk-kit init)') : '')
|
|
351
|
+
(st.agents.required ? (st.agents.present ? ' · AGENTS.md 就绪' : ' · 缺 AGENTS.md(跑 zk-kit init)') : '') +
|
|
352
|
+
drift);
|
|
240
353
|
const payload = buildMemoryPayload(cfg);
|
|
241
354
|
const present = payload.files.filter((f) => f.present);
|
|
242
355
|
rows.push(present.length === 0
|
|
243
356
|
? '✓ 记忆:暂未启用(根目录没有 AGENTS.md / USER.md / MEMORY.md)'
|
|
244
357
|
: `${payload.words <= payload.budget ? '✓' : '✗'} 记忆:${payload.words}/${payload.budget} 词(${formatFileShares(payload.files, payload.tocWords)})` +
|
|
245
358
|
(payload.truncatedWords > 0 ? `,已截断 ${payload.truncatedWords} 词` : ''));
|
|
359
|
+
if (exists) {
|
|
360
|
+
// 记忆在跑、但没有工作约定:默认安装里这是常态(flat 不自动写 AGENTS.md),
|
|
361
|
+
// 代价是「每条结论附来源 / 中文打 tags / 每周整理」四条约定与周提醒全都不生效。
|
|
362
|
+
const hasMemory = fs.existsSync(path.join(cfg.notebook, 'MEMORY.md'));
|
|
363
|
+
const hasAgents = fs.existsSync(path.join(cfg.notebook, 'AGENTS.md'));
|
|
364
|
+
if (hasMemory && !hasAgents) {
|
|
365
|
+
rows.push(`⚠️ 记忆在跑,但缺 AGENTS.md:约定与周提醒未启用 —— 跑 zk-kit init --with-agents(或设置页「写入 AGENTS.md 模板」)`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
246
368
|
if (zk && exists) {
|
|
247
369
|
try {
|
|
248
370
|
const s = await notebookStats(cfg);
|
|
@@ -288,10 +410,24 @@ async function main() {
|
|
|
288
410
|
return;
|
|
289
411
|
}
|
|
290
412
|
case 'init': {
|
|
291
|
-
const
|
|
413
|
+
const withAgents = flags['with-agents'] === true || flags['with-agents'] === 'true';
|
|
414
|
+
const r = await ensureNotebook(cfg, undefined, { withAgents });
|
|
292
415
|
print(json ? r : `笔记本 ${r.notebook}(结构 ${cfg.structure})\n` +
|
|
293
416
|
`初始化:${r.initialized ? '是' : '已是笔记本'} · 目录:${r.dirsCreated.length ? '新建 ' + r.dirsCreated.join('、') : '已齐全'}\n` +
|
|
294
|
-
`模板:${r.templatesWritten.length ? r.templatesWritten.join(' / ') : '已存在'} · group:${r.groupsAdded.length ? r.groupsAdded.join(' / ') : '已存在'} · AGENTS.md:${r.agentsWritten ? '已写入' : (cfg.structure === 'layered' ? '已存在' : 'flat
|
|
417
|
+
`模板:${r.templatesWritten.length ? r.templatesWritten.join(' / ') : '已存在'} · group:${r.groupsAdded.length ? r.groupsAdded.join(' / ') : '已存在'} · AGENTS.md:${r.agentsWritten ? '已写入' : (cfg.structure === 'layered' || withAgents ? '已存在' : '未写(flat 要 --with-agents)')} · WORKFLOW.md:${r.workflowWritten ? '已写入' : (cfg.structure === 'layered' ? '已存在' : 'flat 不写')}` +
|
|
418
|
+
(r.groupWarnings.length ? `\n⚠️ ${r.groupWarnings.join('\n⚠️ ')}` : ''), json);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
case 'groups': {
|
|
422
|
+
const fix = flags.fix === true || flags.fix === 'true';
|
|
423
|
+
const dryRun = flags['dry-run'] === true || flags['dry-run'] === 'true';
|
|
424
|
+
if (fix && !dryRun) {
|
|
425
|
+
const result = fixGroupConfig(cfg);
|
|
426
|
+
print(json ? { ...structureStatus(cfg), fix: result } : groupsReport(cfg, structureStatus(cfg), result), json);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const st = structureStatus(cfg);
|
|
430
|
+
print(json ? { ...st, dryRun: true } : groupsReport(cfg, st, null), json);
|
|
295
431
|
return;
|
|
296
432
|
}
|
|
297
433
|
case 'new': {
|
|
@@ -303,11 +439,12 @@ async function main() {
|
|
|
303
439
|
throw new ZkError(`--type 只能是:${NOTE_KINDS.join(' / ')}`);
|
|
304
440
|
}
|
|
305
441
|
const tags = [...new Set([...cfg.defaultTags, ...list(flags.tags)])];
|
|
442
|
+
const body = str(flags.body);
|
|
306
443
|
const created = await createNote(cfg, {
|
|
307
444
|
title,
|
|
308
445
|
name: str(flags.name) || undefined,
|
|
309
446
|
summary: str(flags.summary) || undefined,
|
|
310
|
-
content: withTags(
|
|
447
|
+
content: withTags(body, tags),
|
|
311
448
|
dir: newNoteDir(cfg, { dir: str(flags.dir) || undefined, type }),
|
|
312
449
|
type,
|
|
313
450
|
});
|
|
@@ -315,20 +452,26 @@ async function main() {
|
|
|
315
452
|
print(json ? { ...created, tags } : `已创建 ${created.path}${tags.length ? ' · ' + tags.map((t) => '#' + t).join(' ') : ''}`, json);
|
|
316
453
|
if (created.summaryWarning)
|
|
317
454
|
console.error('⚠️ ' + created.summaryWarning);
|
|
455
|
+
const tagWarning = taglessCjkWarning(title, withTags(body, tags), tags);
|
|
456
|
+
if (tagWarning)
|
|
457
|
+
console.error('⚠️ ' + tagWarning);
|
|
318
458
|
for (const hit of archived) {
|
|
319
459
|
console.error(`⚠️ 归档里有同名旧结论:${hit.path}${hit.reason ? `(废弃原因:${hit.reason})` : '(没有记录废弃原因)'} —— 先读它,确认不是同一个结论再复用标题`);
|
|
320
460
|
}
|
|
321
461
|
return;
|
|
322
462
|
}
|
|
323
463
|
case 'search': {
|
|
324
|
-
const
|
|
464
|
+
const result = await searchNotesDetailed(cfg, {
|
|
325
465
|
query: pos[0] || str(flags.query) || undefined,
|
|
326
466
|
tags: list(flags.tags),
|
|
327
467
|
since: str(flags.since) || undefined,
|
|
328
468
|
limit: Number(str(flags.limit)) || 10,
|
|
329
469
|
sort: str(flags.sort) || 'created-desc',
|
|
330
470
|
});
|
|
331
|
-
|
|
471
|
+
const how = result.matchStrategy === 'mixed'
|
|
472
|
+
? '\n(中文查询:全文 + 子串合并,已补上全文索引漏掉的)'
|
|
473
|
+
: result.matchStrategy === 'regex' ? '\n(全文无结果,已退回子串匹配)' : '';
|
|
474
|
+
print(json ? result.notes : noteList(result.notes) + how, json);
|
|
332
475
|
return;
|
|
333
476
|
}
|
|
334
477
|
case 'read': {
|
|
@@ -377,7 +520,9 @@ async function main() {
|
|
|
377
520
|
}
|
|
378
521
|
case 'dream': {
|
|
379
522
|
await ensureNotebook(cfg);
|
|
380
|
-
|
|
523
|
+
// 没给 --days 就不传:窗口要跟着 DREAMS.md 的「上次做梦」走,别在这里钉死 7 天
|
|
524
|
+
const days = Number(str(flags.days));
|
|
525
|
+
const r = await dreamNotebook(cfg, Number.isFinite(days) && days > 0 ? { days } : {});
|
|
381
526
|
print(json ? r : dreamReport(r), json);
|
|
382
527
|
return;
|
|
383
528
|
}
|
package/dist/config/store.js
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* 老配置只有 `notebook`(或 structure 是全局键):读进来一次性迁进 `notebooks.default`,
|
|
13
13
|
* 之后就不再有双向合并 —— notebooks 存在时,散落的 `notebook` 顶层键只当没看见。
|
|
14
14
|
*/
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
15
17
|
import { CFG_FILE, CFG_LOCK, defaultNotebook, expandHome, processWorkspace, resolveInWorkspace } from './paths.js';
|
|
16
18
|
import { fileStamp } from '../lib/file-stamp.js';
|
|
17
19
|
import { withFileLockSync } from '../lib/lock.js';
|
|
@@ -245,6 +247,30 @@ export function writeConfig(patch, workspace = processWorkspace(), opts = {}) {
|
|
|
245
247
|
notebooks[active] = { ...entry, structure: structureOf(patch.structure, 'flat') };
|
|
246
248
|
}
|
|
247
249
|
const next = normalizeConfig({ ...merged, notebooks, active }, workspace);
|
|
250
|
+
// archiveDir 是全局项:旧归档目录非空时,任何一本已配置笔记本都不能直接改,
|
|
251
|
+
// 否则切到那本后旧归档不再被排除,废弃笔记会重新进入检索与统计。
|
|
252
|
+
if (next.archiveDir !== current.archiveDir) {
|
|
253
|
+
const checked = new Set();
|
|
254
|
+
for (const info of notebookInfos(next, workspace)) {
|
|
255
|
+
if (checked.has(info.path))
|
|
256
|
+
continue;
|
|
257
|
+
checked.add(info.path);
|
|
258
|
+
const oldAbs = path.join(info.path, current.archiveDir);
|
|
259
|
+
let entries;
|
|
260
|
+
try {
|
|
261
|
+
entries = fs.readdirSync(oldAbs);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
// 只有目录不存在才放行;没权限 / 路径类型异常都失败关闭,不能猜它是空的。
|
|
265
|
+
if (err.code === 'ENOENT')
|
|
266
|
+
continue;
|
|
267
|
+
throw err;
|
|
268
|
+
}
|
|
269
|
+
if (entries.length > 0) {
|
|
270
|
+
throw new ArchiveDirChangeError(current.archiveDir, next.archiveDir, oldAbs, entries.length);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
248
274
|
writeJson(CFG_FILE, toDisk(next));
|
|
249
275
|
configCache = null;
|
|
250
276
|
return next;
|
|
@@ -261,6 +287,17 @@ export class ConfigConflictError extends Error {
|
|
|
261
287
|
this.name = 'ConfigConflictError';
|
|
262
288
|
}
|
|
263
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* archiveDir 从「空目录 / 不存在」改成别的值时被拒。
|
|
292
|
+
* 不是技术限制,是不让「改一个字符串」静默把旧归档放回检索:插件不迁移文件。
|
|
293
|
+
*/
|
|
294
|
+
export class ArchiveDirChangeError extends Error {
|
|
295
|
+
constructor(oldDir, newDir, absPath, count) {
|
|
296
|
+
super(`archiveDir 从 "${oldDir}" 改成 "${newDir}" 被拒绝:旧归档目录 ${absPath} 里还有 ${count} 项。\n` +
|
|
297
|
+
'旧归档不会自动迁移,改完会让废弃笔记重新进入检索 —— 先手动迁移,或保持原值。');
|
|
298
|
+
this.name = 'ArchiveDirChangeError';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
264
301
|
/** 锁内用的干净读取:不吃 configCache,合并基线必须是磁盘上的现状 */
|
|
265
302
|
function readConfigFresh(workspace) {
|
|
266
303
|
return normalizeConfig(readJson(CFG_FILE, {}), workspace);
|