@jjh32456/longlive 2.1.0 → 2.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/CHANGELOG.md +108 -1
- package/QUICKSTART.md +7 -7
- package/README.en.md +13 -1
- package/README.md +26 -8
- package/SPEC.md +6 -5
- package/build-info.json +143 -73
- package/cordis.patch.yml +2 -0
- package/docs/ARCHITECTURE.md +6 -3
- package/docs/CONFIG.md +25 -1
- package/docs/FAQ.md +2 -2
- package/docs/FEATURES.md +125 -2
- package/docs/INDEX-FRESHNESS.md +8 -1
- package/docs/OPERATIONS.md +63 -2
- package/docs/QUICKSTART.md +2 -2
- package/docs/README.en.md +1 -1
- package/docs/TROUBLESHOOTING.md +1 -1
- package/package.json +10 -2
- package/scripts/assert-install.mjs +124 -0
- package/scripts/backlog-report.mjs +98 -0
- package/scripts/install-230.mjs +787 -0
- package/scripts/lib/eng-common.mjs +428 -0
- package/scripts/rebuild-index.mjs +148 -0
- package/scripts/restore-drill.mjs +351 -0
- package/scripts/run-autoresolve.mjs +123 -0
- package/scripts/watchdog-230.mjs +379 -0
- package/src/config.js +7 -0
- package/src/features.js +35 -0
- package/src/gate/action-gate.js +545 -0
- package/src/memory/backup-retention.mjs +823 -0
- package/src/memory/cards.js +73 -12
- package/src/memory/conflict-scan.mjs +356 -0
- package/src/memory/conflicts.js +202 -9
- package/src/memory/consolidate.js +537 -35
- package/src/memory/decay.js +133 -19
- package/src/memory/event-index.js +62 -4
- package/src/memory/forget-scheduler.mjs +303 -0
- package/src/memory/forget-v2.js +94 -8
- package/src/memory/index-cache.mjs +216 -0
- package/src/memory/index.js +179 -16
- package/src/memory/lock.js +53 -12
- package/src/memory/maintenance.js +295 -19
- package/src/memory/recall-feedback.mjs +159 -17
- package/src/memory/recall-v2.js +5 -3
- package/src/memory/recall.js +10 -4
- package/src/memory/state.js +446 -38
- package/src/memory/task-state.mjs +569 -0
- package/src/recall/brain.mjs +55 -6
- package/src/recall/continuity-volatile.mjs +195 -1
- package/src/recall/index.js +8 -0
- package/src/tools.js +141 -21
- package/src/ui/routes-readonly.js +63 -5
|
@@ -26,18 +26,25 @@ import crypto from 'node:crypto';
|
|
|
26
26
|
|
|
27
27
|
import { dayString, isoStamp } from './frontmatter.js';
|
|
28
28
|
import { memoryRootFromConfig, resolveInside, relativePath } from './paths.js';
|
|
29
|
-
import { ensureDir, writeFileAtomic } from './state.js';
|
|
30
|
-
import { memoryConsolidate } from './consolidate.js';
|
|
29
|
+
import { ensureDir, readState, writeFileAtomic } from './state.js';
|
|
30
|
+
import { memoryConsolidate, autoResolveProposals, proposalBacklog } from './consolidate.js';
|
|
31
31
|
import { memoryForget } from './forget.js';
|
|
32
|
+
// 2.3.0 W2.3 lane forget:衰减/遗忘调度报告(只读提案;自动链绝不执行立碑/降级)。
|
|
33
|
+
import { runForgetDecayScheduler } from './forget-scheduler.mjs';
|
|
32
34
|
import { proposeForget, FORGET_SUGGESTIONS_REL } from './forget-v2.js';
|
|
33
35
|
import { runConclusionDistillJob } from './conclusion-distill.js';
|
|
34
36
|
// 2.0.0 W3b(⑧):冷档状态探针——archive-state.json 的唯一写入方(fail-closed,自身不抛)。
|
|
35
37
|
import { probeAndWriteArchiveState } from '../recall/archive-state.mjs';
|
|
36
38
|
// 2.0.0 W3c(B7):冷层迁移待办探针——只写 pending.json,永不自动迁移(两次人工 approve 缺一不可)。
|
|
37
39
|
import { probePending as probeMigrationPending } from './migrate-200.js';
|
|
40
|
+
// 2.3.0 W2.2 lane conflict:每日冲突扫描槽(候选检测 + pending 对账;只读卡/只 append 账本)。
|
|
41
|
+
import { runDailyConflictScan } from './conflict-scan.mjs';
|
|
38
42
|
|
|
39
43
|
export const SCHEDULE_VERSION = 1;
|
|
40
44
|
export const SCHEDULE_REL = path.join('.longlive', 'bridge', 'schedule.json');
|
|
45
|
+
// 2.2.0 lane A: small backlog sidecar so recall/status can read the proposal
|
|
46
|
+
// backlog without parsing the (300KB+) memory-state.json on every step.
|
|
47
|
+
export const BACKLOG_REL = path.join('.longlive', 'bridge', 'backlog.json');
|
|
41
48
|
export const LOCK_REL = path.join('.longlive', 'bridge', 'schedule.lock');
|
|
42
49
|
export const PENDING_REPORT_PREFIX = 'forget-pending-';
|
|
43
50
|
export const RUN_HISTORY_LIMIT = 30;
|
|
@@ -50,6 +57,8 @@ export const AUTO_MAINTENANCE_DEFAULTS = Object.freeze({
|
|
|
50
57
|
consolidate: true,
|
|
51
58
|
forget: true,
|
|
52
59
|
forgetSuggestions: true,
|
|
60
|
+
// 2.3.0 W2.2:每日冲突候选扫描 + 再巩固对账(conflictScan:false 可关)。
|
|
61
|
+
conflictScan: true,
|
|
53
62
|
runOnStart: true,
|
|
54
63
|
startDelayMs: DEFAULT_START_DELAY_MS,
|
|
55
64
|
});
|
|
@@ -76,8 +85,45 @@ function warnTo(logger, message) {
|
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
/**
|
|
89
|
+
* 2.2.0 lane A: auto-resolve knobs may arrive through an existing raw
|
|
90
|
+
* passthrough (`autoResolve: {enabled, maxAccept, maxAcceptNew}`); no new
|
|
91
|
+
* schema leaf is added, and when nothing is configured the consolidate.js
|
|
92
|
+
* defaults (100 mutations / 10 new cards per run) apply.
|
|
93
|
+
*/
|
|
94
|
+
function autoResolveOptions(config) {
|
|
95
|
+
const rows = [config?.autoResolve, config?.autoMaintenance?.autoResolve];
|
|
96
|
+
for (const row of rows) {
|
|
97
|
+
if (row && typeof row === 'object' && !Array.isArray(row)) return row;
|
|
98
|
+
}
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 2.2.0 lane A: the small backlog sidecar. Readers (recall/status) can stat this
|
|
104
|
+
* file instead of parsing the 300KB+ memory-state.json on every step.
|
|
105
|
+
* Atomic tmp+rename through writeFileAtomic; no backup needed (rebuildable).
|
|
106
|
+
*/
|
|
107
|
+
function writeBacklogSidecar(root, { now = new Date(), day = null } = {}) {
|
|
108
|
+
const file = resolveInside(root, BACKLOG_REL);
|
|
109
|
+
const state = readState(root);
|
|
110
|
+
const backlog = proposalBacklog(Array.isArray(state.seenProposals) ? state.seenProposals : []);
|
|
111
|
+
const payload = {
|
|
112
|
+
day: day ?? dayString(now),
|
|
113
|
+
total: backlog.total,
|
|
114
|
+
pending: backlog.pending,
|
|
115
|
+
resolved: backlog.resolved,
|
|
116
|
+
accepted: backlog.accepted,
|
|
117
|
+
rejected: backlog.rejected,
|
|
118
|
+
lastConsolidated: state.lastConsolidated ?? null,
|
|
119
|
+
at: isoStamp(now),
|
|
120
|
+
};
|
|
121
|
+
ensureDir(root, path.dirname(file));
|
|
122
|
+
const write = writeFileAtomic(root, file, `${JSON.stringify(payload, null, 2)}\n`, { backup: false, now });
|
|
123
|
+
return { rel: relativePath(root, file), ...payload, sha256: write.sha256, bytes: write.bytes };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function toClock(now) { if (typeof now === 'function') {
|
|
81
127
|
return () => {
|
|
82
128
|
const value = now();
|
|
83
129
|
const date = value instanceof Date ? value : new Date(value);
|
|
@@ -98,6 +144,12 @@ function emptyState() {
|
|
|
98
144
|
lastConsolidateReport: null,
|
|
99
145
|
lastConsolidateProposals: null,
|
|
100
146
|
lastConsolidateError: null,
|
|
147
|
+
// 2.2.0 lane A:提案积压自动处理(consolidate.autoResolveProposals)的每日槽。
|
|
148
|
+
// 2.3.0 lane pipeline(W1-4):独立日期槽,B1 已跑而 B1b 未跑时启动补跑。
|
|
149
|
+
lastAutoResolveDate: null,
|
|
150
|
+
lastAutoResolveAt: null,
|
|
151
|
+
lastAutoResolveResult: null,
|
|
152
|
+
lastAutoResolveError: null,
|
|
101
153
|
lastForgetDate: null,
|
|
102
154
|
lastForgetAt: null,
|
|
103
155
|
lastForgetPending: null,
|
|
@@ -121,6 +173,11 @@ function emptyState() {
|
|
|
121
173
|
lastMigrate200At: null,
|
|
122
174
|
lastMigrate200Status: null,
|
|
123
175
|
lastMigrate200Error: null,
|
|
176
|
+
// 2.3.0 W2.2 lane conflict:每日冲突扫描槽(conflict-scan 写入方,B6)。
|
|
177
|
+
lastConflictScanDate: null,
|
|
178
|
+
lastConflictScanAt: null,
|
|
179
|
+
lastConflictScanStatus: null,
|
|
180
|
+
lastConflictScanError: null,
|
|
124
181
|
lastRunAt: null,
|
|
125
182
|
lastRunDay: null,
|
|
126
183
|
lastTrigger: null,
|
|
@@ -132,21 +189,24 @@ function normalizeState(raw) {
|
|
|
132
189
|
const state = emptyState();
|
|
133
190
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return state;
|
|
134
191
|
state.lastConsolidateDate = isDay(raw.lastConsolidateDate) ? raw.lastConsolidateDate : null;
|
|
192
|
+
state.lastAutoResolveDate = isDay(raw.lastAutoResolveDate) ? raw.lastAutoResolveDate : null;
|
|
135
193
|
state.lastForgetDate = isDay(raw.lastForgetDate) ? raw.lastForgetDate : null;
|
|
136
194
|
state.lastForgetSuggestionsDate = isDay(raw.lastForgetSuggestionsDate) ? raw.lastForgetSuggestionsDate : null;
|
|
137
195
|
state.lastConclusionDistillDate = isDay(raw.lastConclusionDistillDate) ? raw.lastConclusionDistillDate : null;
|
|
138
196
|
state.lastArchiveStateDate = isDay(raw.lastArchiveStateDate) ? raw.lastArchiveStateDate : null;
|
|
139
197
|
state.lastMigrate200Date = isDay(raw.lastMigrate200Date) ? raw.lastMigrate200Date : null;
|
|
198
|
+
state.lastConflictScanDate = isDay(raw.lastConflictScanDate) ? raw.lastConflictScanDate : null;
|
|
140
199
|
for (const key of [
|
|
141
200
|
'lastConsolidateAt', 'lastConsolidateReport',
|
|
142
201
|
'lastForgetAt', 'lastForgetPending', 'lastForgetSuggestionsAt',
|
|
143
202
|
'lastConclusionDistillAt', 'lastArchiveStateAt', 'lastArchiveStateStatus',
|
|
144
|
-
'lastMigrate200At', 'lastMigrate200Status',
|
|
203
|
+
'lastMigrate200At', 'lastMigrate200Status', 'lastAutoResolveAt',
|
|
204
|
+
'lastConflictScanAt', 'lastConflictScanStatus',
|
|
145
205
|
'lastRunAt', 'lastRunDay', 'lastTrigger',
|
|
146
206
|
]) {
|
|
147
207
|
if (raw[key] == null || typeof raw[key] === 'string') state[key] = raw[key] ?? null;
|
|
148
208
|
}
|
|
149
|
-
for (const key of ['lastConsolidateError', 'lastForgetError', 'lastForgetSuggestionsError', 'lastConclusionDistillError', 'lastArchiveStateError', 'lastMigrate200Error']) {
|
|
209
|
+
for (const key of ['lastConsolidateError', 'lastForgetError', 'lastForgetSuggestionsError', 'lastConclusionDistillError', 'lastArchiveStateError', 'lastMigrate200Error', 'lastAutoResolveError', 'lastConflictScanError']) {
|
|
150
210
|
const value = raw[key];
|
|
151
211
|
if (value == null) {
|
|
152
212
|
state[key] = null;
|
|
@@ -176,6 +236,16 @@ function normalizeState(raw) {
|
|
|
176
236
|
skipped: Number(raw.lastConclusionDistillResult.skipped) || 0,
|
|
177
237
|
}
|
|
178
238
|
: null;
|
|
239
|
+
state.lastAutoResolveResult = raw.lastAutoResolveResult
|
|
240
|
+
&& typeof raw.lastAutoResolveResult === 'object'
|
|
241
|
+
&& !Array.isArray(raw.lastAutoResolveResult)
|
|
242
|
+
? {
|
|
243
|
+
accepted: Number(raw.lastAutoResolveResult.accepted) || 0,
|
|
244
|
+
rejected: Number(raw.lastAutoResolveResult.rejected) || 0,
|
|
245
|
+
reviewed: Number(raw.lastAutoResolveResult.reviewed) || 0,
|
|
246
|
+
pending: Number(raw.lastAutoResolveResult.pending) || 0,
|
|
247
|
+
}
|
|
248
|
+
: null;
|
|
179
249
|
state.runs = Array.isArray(raw.runs)
|
|
180
250
|
? raw.runs.filter((entry) => entry && typeof entry === 'object').slice(-RUN_HISTORY_LIMIT)
|
|
181
251
|
: [];
|
|
@@ -444,6 +514,8 @@ function runDailyMaintenanceSync({
|
|
|
444
514
|
consolidate = memoryConsolidate,
|
|
445
515
|
forget = memoryForget,
|
|
446
516
|
forgetSuggestions = proposeForget,
|
|
517
|
+
// 2.3.0 W2.2:冲突扫描槽可注入(测试用假实现),默认走 conflict-scan.mjs 的真实实现。
|
|
518
|
+
conflictScan = runDailyConflictScan,
|
|
447
519
|
lockHeld = false,
|
|
448
520
|
} = {}) {
|
|
449
521
|
let root;
|
|
@@ -465,7 +537,12 @@ function runDailyMaintenanceSync({
|
|
|
465
537
|
const wantArchiveState = config.archiveState !== false;
|
|
466
538
|
// 2.0.0 W3c(B7):冷层迁移待办探针槽(migrate200:false 可关);只探测、不迁移。
|
|
467
539
|
const wantMigrate200 = config.migrate200 !== false;
|
|
468
|
-
|
|
540
|
+
// 2.3.0 W2.2 lane conflict:每日冲突候选扫描 + pending 对账槽(conflictScan:false 可关)。
|
|
541
|
+
const wantConflictScan = config.conflictScan !== false;
|
|
542
|
+
// 2.3.0 lane pipeline(W1-4):B1b 有独立日期槽,B1 当天跑过而 B1b 没跑时启动补跑。
|
|
543
|
+
const autoCfg = autoResolveOptions(config);
|
|
544
|
+
const wantAutoResolve = wantConsolidate && autoCfg.enabled !== false;
|
|
545
|
+
if (!wantConsolidate && !wantForget && !wantSuggestions && !wantDrafts && !wantArchiveState && !wantMigrate200 && !wantConflictScan) {
|
|
469
546
|
return { ok: true, ran: false, reason: 'disabled', day, trigger };
|
|
470
547
|
}
|
|
471
548
|
|
|
@@ -475,11 +552,13 @@ function runDailyMaintenanceSync({
|
|
|
475
552
|
day,
|
|
476
553
|
trigger,
|
|
477
554
|
consolidate: null,
|
|
555
|
+
autoResolve: null,
|
|
478
556
|
forget: null,
|
|
479
557
|
forgetSuggestions: null,
|
|
480
558
|
conclusionDistill: null,
|
|
481
559
|
archiveState: null,
|
|
482
560
|
migrate200: null,
|
|
561
|
+
conflictScan: null,
|
|
483
562
|
rotation: null,
|
|
484
563
|
state: null,
|
|
485
564
|
corruptState: false,
|
|
@@ -501,12 +580,14 @@ function runDailyMaintenanceSync({
|
|
|
501
580
|
let state = read.state;
|
|
502
581
|
|
|
503
582
|
let needConsolidate = wantConsolidate && state.lastConsolidateDate !== day;
|
|
583
|
+
let needAutoResolve = wantAutoResolve && state.lastAutoResolveDate !== day;
|
|
504
584
|
let needForget = wantForget && state.lastForgetDate !== day;
|
|
505
585
|
let needSuggestions = wantSuggestions && state.lastForgetSuggestionsDate !== day;
|
|
506
586
|
let needDrafts = wantDrafts && state.lastConclusionDistillDate !== day;
|
|
507
587
|
let needArchiveState = wantArchiveState && state.lastArchiveStateDate !== day;
|
|
508
588
|
let needMigrate200 = wantMigrate200 && state.lastMigrate200Date !== day;
|
|
509
|
-
|
|
589
|
+
let needConflictScan = wantConflictScan && state.lastConflictScanDate !== day;
|
|
590
|
+
if (!needConsolidate && !needAutoResolve && !needForget && !needSuggestions && !needDrafts && !needArchiveState && !needMigrate200 && !needConflictScan) {
|
|
510
591
|
return { ...summary, reason: 'already-ran-today', state };
|
|
511
592
|
}
|
|
512
593
|
|
|
@@ -530,19 +611,23 @@ function runDailyMaintenanceSync({
|
|
|
530
611
|
if (latest.corrupt) summary.corruptState = true;
|
|
531
612
|
state = latest.state;
|
|
532
613
|
needConsolidate = wantConsolidate && state.lastConsolidateDate !== day;
|
|
614
|
+
needAutoResolve = wantAutoResolve && state.lastAutoResolveDate !== day;
|
|
533
615
|
needForget = wantForget && state.lastForgetDate !== day;
|
|
534
616
|
needSuggestions = wantSuggestions && state.lastForgetSuggestionsDate !== day;
|
|
535
617
|
needDrafts = wantDrafts && state.lastConclusionDistillDate !== day;
|
|
536
618
|
needArchiveState = wantArchiveState && state.lastArchiveStateDate !== day;
|
|
537
619
|
needMigrate200 = wantMigrate200 && state.lastMigrate200Date !== day;
|
|
538
|
-
|
|
620
|
+
needConflictScan = wantConflictScan && state.lastConflictScanDate !== day;
|
|
621
|
+
if (!needConsolidate && !needAutoResolve && !needForget && !needSuggestions && !needDrafts && !needArchiveState && !needMigrate200 && !needConflictScan) {
|
|
539
622
|
return { ...summary, reason: 'already-ran-today', state };
|
|
540
623
|
}
|
|
541
624
|
|
|
542
625
|
// ---- B1: consolidate (report only) ------------------------------------
|
|
543
626
|
if (needConsolidate) {
|
|
544
627
|
try {
|
|
545
|
-
|
|
628
|
+
// 2.3.0 lane pipeline:把 autoResolve 的 maxSpan/maxText 也交给提案生成侧,
|
|
629
|
+
// 让新提案在进积压前就按同一上限切单元(只切提案,不动 journal)。
|
|
630
|
+
const result = consolidate({}, { memoryRoot: root, now: at, autoResolve: { ...autoCfg } });
|
|
546
631
|
const proposals = Array.isArray(result?.proposals) ? result.proposals.length : 0;
|
|
547
632
|
summary.consolidate = {
|
|
548
633
|
status: 'ran',
|
|
@@ -565,6 +650,58 @@ function runDailyMaintenanceSync({
|
|
|
565
650
|
}
|
|
566
651
|
}
|
|
567
652
|
|
|
653
|
+
// ---- B1b: 2.2.0 lane A — 提案积压自动处理 ----------------------------
|
|
654
|
+
// 「全量入库,取舍交给遗忘机制」:维护跑完 consolidate 后,把提案积压自动
|
|
655
|
+
// 消化一部分——只对完全重复/结构异常 reject、对干净无目标段 accept,其余
|
|
656
|
+
// 留人工。失败只记 autoResolve 错误,不影响 B2-B7,也不改 consolidate 状态。
|
|
657
|
+
//
|
|
658
|
+
// 2.3.0 lane pipeline(W1-4):B1b 改为独立每日槽(lastAutoResolveDate)。
|
|
659
|
+
// 旧逻辑要求 `needConsolidate && consolidate.status==='ran'`,一旦当天 B1 先跑
|
|
660
|
+
// 成功而 B1b 失败/升级前没跑,当天就再也不会补跑。现在只要当日 B1b 槽未打勾
|
|
661
|
+
// 就补跑(先 B1 后 B1b,顺序不变);失败不推进日期,下一次启动维护重试。
|
|
662
|
+
if (needAutoResolve) {
|
|
663
|
+
if (autoCfg.enabled !== false) {
|
|
664
|
+
try {
|
|
665
|
+
const auto = autoResolveProposals({
|
|
666
|
+
root,
|
|
667
|
+
now: at,
|
|
668
|
+
maxAccept: autoCfg.maxAccept,
|
|
669
|
+
maxAcceptNew: autoCfg.maxAcceptNew,
|
|
670
|
+
maxSpan: autoCfg.maxSpan,
|
|
671
|
+
maxText: autoCfg.maxText,
|
|
672
|
+
});
|
|
673
|
+
summary.autoResolve = {
|
|
674
|
+
status: auto.status,
|
|
675
|
+
accepted: auto.accepted,
|
|
676
|
+
rejected: auto.rejected,
|
|
677
|
+
reviewed: auto.reviewed,
|
|
678
|
+
pending: auto.pending,
|
|
679
|
+
mutations: auto.mutations,
|
|
680
|
+
lastConsolidated: auto.lastConsolidated ?? null,
|
|
681
|
+
pointerMoved: auto.pointerMoved === true,
|
|
682
|
+
stateWritten: auto.stateWritten === true,
|
|
683
|
+
reviewReasons: auto.reviewReasons ?? {},
|
|
684
|
+
};
|
|
685
|
+
state.lastAutoResolveDate = day;
|
|
686
|
+
state.lastAutoResolveAt = isoStamp(at);
|
|
687
|
+
state.lastAutoResolveResult = {
|
|
688
|
+
accepted: auto.accepted,
|
|
689
|
+
rejected: auto.rejected,
|
|
690
|
+
reviewed: auto.reviewed,
|
|
691
|
+
pending: auto.pending,
|
|
692
|
+
};
|
|
693
|
+
state.lastAutoResolveError = null;
|
|
694
|
+
} catch (error) {
|
|
695
|
+
summary.autoResolve = { status: 'failed', ...errorInfo(error) };
|
|
696
|
+
state.lastAutoResolveError = { ...errorInfo(error), at: isoStamp(at), day };
|
|
697
|
+
warnTo(
|
|
698
|
+
logger,
|
|
699
|
+
`[auto-maintenance] autoResolve 失败(${summary.autoResolve.code})— ${summary.autoResolve.message};提案保持原状,不推进日期,下次补跑`,
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
568
705
|
// ---- B2: forget dry-run + pending list --------------------------------
|
|
569
706
|
if (needForget) {
|
|
570
707
|
try {
|
|
@@ -589,6 +726,22 @@ function runDailyMaintenanceSync({
|
|
|
589
726
|
undated: Array.isArray(result.undated) ? result.undated.length : 0,
|
|
590
727
|
sha256: write.sha256,
|
|
591
728
|
};
|
|
729
|
+
// 2.3.0 W2.3 lane forget:在 B2 之后产出「衰减/遗忘待办」报告(只读;执行仍只走人工 memory_forget confirm)。
|
|
730
|
+
const forgetDecay = runForgetDecayScheduler({
|
|
731
|
+
root,
|
|
732
|
+
config,
|
|
733
|
+
now: at,
|
|
734
|
+
day,
|
|
735
|
+
forgetResult: result,
|
|
736
|
+
});
|
|
737
|
+
summary.forgetDecay = {
|
|
738
|
+
status: 'ran',
|
|
739
|
+
decayProposals: forgetDecay.decay.proposals.length,
|
|
740
|
+
forgetProposals: forgetDecay.forget.proposals.length,
|
|
741
|
+
report: forgetDecay.report.rel,
|
|
742
|
+
sha256: forgetDecay.report.sha256,
|
|
743
|
+
privacy: forgetDecay.report.privacy.ok,
|
|
744
|
+
};
|
|
592
745
|
state.lastForgetDate = day;
|
|
593
746
|
state.lastForgetAt = isoStamp(at);
|
|
594
747
|
state.lastForgetPending = summary.forget.pendingRel;
|
|
@@ -683,6 +836,14 @@ function runDailyMaintenanceSync({
|
|
|
683
836
|
if (config.journalRotate !== false) {
|
|
684
837
|
try {
|
|
685
838
|
summary.rotation = rotateJournals({ memoryRoot: root, now: at, config });
|
|
839
|
+
// 2.3.0 lane pipeline:拆分失败/无日期行不再静默 no-op —— report.ok=false 时
|
|
840
|
+
// 明确告警(原因进 report.errors,维护摘要与 run 历史都留痕)。
|
|
841
|
+
if (summary.rotation && summary.rotation.ok === false) {
|
|
842
|
+
warnTo(
|
|
843
|
+
logger,
|
|
844
|
+
`[auto-maintenance] journal 轮转有告警:${summary.rotation.errors?.map((item) => `${item.name ?? '?'}:${item.code ?? item.reason ?? '?'}`).join(', ') || 'unknown'} — 原文件未动`,
|
|
845
|
+
);
|
|
846
|
+
}
|
|
686
847
|
} catch (error) {
|
|
687
848
|
summary.rotation = { ok: false, ...errorInfo(error) };
|
|
688
849
|
warnTo(
|
|
@@ -774,8 +935,49 @@ function runDailyMaintenanceSync({
|
|
|
774
935
|
}
|
|
775
936
|
}
|
|
776
937
|
|
|
938
|
+
// ---- B6(2.3.0 W2.2 lane conflict):每日冲突扫描 + 再巩固对账 ------------------
|
|
939
|
+
// 候选检测(runConflictCandidateJob 按天幂等,落 .longlive/conflicts/candidates.jsonl 的 pending)
|
|
940
|
+
// + pending 对账归档(端点消失 / 已有 conflicts_with 边 / 端点已 superseded → archived)。
|
|
941
|
+
// 只读卡、只 append 账本,不删卡、不合并卡;失败只告警、不推进日期,下次补跑重试。
|
|
942
|
+
if (needConflictScan) {
|
|
943
|
+
try {
|
|
944
|
+
const result = conflictScan({ memoryRoot: root, config, now: at, logger });
|
|
945
|
+
if (result && result.ok === true) {
|
|
946
|
+
summary.conflictScan = {
|
|
947
|
+
status: 'ran',
|
|
948
|
+
created: result.steps?.candidates?.created ?? 0,
|
|
949
|
+
archived: result.steps?.candidates?.archived ?? 0,
|
|
950
|
+
pending: result.steps?.candidates?.pending ?? null,
|
|
951
|
+
reconcileArchived: result.steps?.reconcile?.archived ?? 0,
|
|
952
|
+
candidatesStatus: result.steps?.candidates?.status ?? null,
|
|
953
|
+
reconcileStatus: result.steps?.reconcile?.status ?? null,
|
|
954
|
+
};
|
|
955
|
+
state.lastConflictScanDate = day;
|
|
956
|
+
state.lastConflictScanAt = isoStamp(at);
|
|
957
|
+
state.lastConflictScanStatus = result.steps?.candidates?.status ?? 'ran';
|
|
958
|
+
state.lastConflictScanError = null;
|
|
959
|
+
} else {
|
|
960
|
+
const code = String(result?.code ?? result?.steps?.candidates?.code ?? result?.steps?.reconcile?.code ?? 'E_HG_CONFLICT_SCAN_FAILED');
|
|
961
|
+
const info = { code, message: `conflict-scan 未完成(${code})`, at: isoStamp(at), day };
|
|
962
|
+
summary.conflictScan = { status: 'failed', ...info, steps: result?.steps ?? null };
|
|
963
|
+
state.lastConflictScanError = info;
|
|
964
|
+
warnTo(
|
|
965
|
+
logger,
|
|
966
|
+
`[auto-maintenance] conflict-scan 未成功(${code})— 不推进日期,下次补跑重试;不影响对话`,
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
} catch (error) {
|
|
970
|
+
summary.conflictScan = { status: 'failed', ...errorInfo(error) };
|
|
971
|
+
state.lastConflictScanError = { ...errorInfo(error), at: isoStamp(at), day };
|
|
972
|
+
warnTo(
|
|
973
|
+
logger,
|
|
974
|
+
`[auto-maintenance] conflict-scan 失败(${summary.conflictScan.code})— 已跳过,不影响对话`,
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
777
979
|
// ---- state -------------------------------------------------------------
|
|
778
|
-
if (!summary.consolidate && !summary.forget && !summary.conclusionDistill && !summary.archiveState && !summary.migrate200 && !summary.rotation) {
|
|
980
|
+
if (!summary.consolidate && !summary.autoResolve && !summary.forget && !summary.conclusionDistill && !summary.archiveState && !summary.migrate200 && !summary.conflictScan && !summary.rotation) {
|
|
779
981
|
return { ...summary, reason: 'nothing-to-do', state };
|
|
780
982
|
}
|
|
781
983
|
summary.ran = true;
|
|
@@ -799,13 +1001,42 @@ function runDailyMaintenanceSync({
|
|
|
799
1001
|
...(summary.conclusionDistill?.status === 'failed' ? { conclusionDistillError: summary.conclusionDistill.code } : {}),
|
|
800
1002
|
archiveState: summary.archiveState?.status ?? 'skipped',
|
|
801
1003
|
migrate200: summary.migrate200?.status ?? 'skipped',
|
|
1004
|
+
conflictScan: summary.conflictScan?.status ?? 'skipped',
|
|
1005
|
+
...(summary.conflictScan?.status === 'ran'
|
|
1006
|
+
? {
|
|
1007
|
+
conflictCandidates: summary.conflictScan.created ?? 0,
|
|
1008
|
+
conflictReconcileArchived: summary.conflictScan.reconcileArchived ?? 0,
|
|
1009
|
+
}
|
|
1010
|
+
: {}),
|
|
1011
|
+
...(summary.conflictScan?.status === 'failed' ? { conflictScanError: summary.conflictScan.code } : {}),
|
|
802
1012
|
...(summary.archiveState?.probeStatus ? { archiveStateStatus: summary.archiveState.probeStatus } : {}),
|
|
803
1013
|
...(summary.archiveState?.status === 'failed' ? { archiveStateError: summary.archiveState.code } : {}),
|
|
804
1014
|
...(summary.migrate200?.state ? { migrate200State: summary.migrate200.state } : {}),
|
|
805
1015
|
...(summary.rotation ? { rotationArchived: summary.rotation.archived ?? 0 } : {}),
|
|
1016
|
+
autoResolve: summary.autoResolve?.status ?? 'skipped',
|
|
1017
|
+
...(summary.autoResolve && summary.autoResolve.status !== 'failed'
|
|
1018
|
+
? {
|
|
1019
|
+
autoAccepted: summary.autoResolve.accepted ?? 0,
|
|
1020
|
+
autoRejected: summary.autoResolve.rejected ?? 0,
|
|
1021
|
+
autoPending: summary.autoResolve.pending ?? 0,
|
|
1022
|
+
}
|
|
1023
|
+
: {}),
|
|
1024
|
+
...(summary.autoResolve?.status === 'failed' ? { autoResolveError: summary.autoResolve.code } : {}),
|
|
806
1025
|
},
|
|
807
1026
|
].slice(-RUN_HISTORY_LIMIT);
|
|
808
1027
|
|
|
1028
|
+
// 2.2.0 lane A: backlog sidecar (<1KB) so recall/status never parse the
|
|
1029
|
+
// 300KB+ memory-state.json just to show "how much is pending".
|
|
1030
|
+
try {
|
|
1031
|
+
summary.backlog = writeBacklogSidecar(root, { now: at, day });
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
summary.backlog = { status: 'failed', ...errorInfo(error) };
|
|
1034
|
+
warnTo(
|
|
1035
|
+
logger,
|
|
1036
|
+
`[auto-maintenance] backlog sidecar 写入失败(${summary.backlog.code})— 不影响维护结果`,
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
809
1040
|
try {
|
|
810
1041
|
const written = writeScheduleState(root, state, { now: at });
|
|
811
1042
|
summary.state = written.state;
|
|
@@ -991,13 +1222,32 @@ export const JOURNAL_MANIFEST_REL = '.longlive/archive/journal/manifest.jsonl';
|
|
|
991
1222
|
export const JOURNAL_ROTATE_DEFAULTS = Object.freeze({ afterDays: 30, maxBytes: 2 * 1024 * 1024 });
|
|
992
1223
|
const MONTH_JOURNAL_RE = /^(\d{4})-(\d{2})\.md$/;
|
|
993
1224
|
const DAY_JOURNAL_RE = /^(\d{4}-\d{2}-\d{2})\.md$/;
|
|
1225
|
+
// 2.3.0 lane pipeline(W1-3):真实 journal 的行首不是裸日期:
|
|
1226
|
+
// `# 2026-11-21` / `## 2026-11-02 · 标题` / `- 18:30 · 轮次…`
|
|
1227
|
+
// 旧识别只认「行首恰为 YYYY-MM-DD」,所以月文件永远 groups.size===0 → 静默 no-op。
|
|
1228
|
+
const JOURNAL_DAY_HEADING_RE = /^\s{0,3}#{1,6}\s*(\d{4}-\d{2}-\d{2})(?![\d-])/;
|
|
1229
|
+
const JOURNAL_DAY_BARE_RE = /^(\d{4}-\d{2}-\d{2})(?![\d-])/;
|
|
1230
|
+
const JOURNAL_TIME_BULLET_RE = /^\s*[-*]\s*\d{1,2}:\d{2}\b/;
|
|
1231
|
+
|
|
1232
|
+
/** 从一行认出所属日期(heading 或裸日期行);认不出返回 null。 */
|
|
1233
|
+
function journalDayOfLine(line) {
|
|
1234
|
+
const heading = JOURNAL_DAY_HEADING_RE.exec(line);
|
|
1235
|
+
if (heading) return heading[1];
|
|
1236
|
+
const bare = JOURNAL_DAY_BARE_RE.exec(line);
|
|
1237
|
+
if (bare) return bare[1];
|
|
1238
|
+
return null;
|
|
1239
|
+
}
|
|
994
1240
|
|
|
995
1241
|
function sha256Bytes(bytes) {
|
|
996
1242
|
return crypto.createHash('sha256').update(bytes).digest('hex');
|
|
997
1243
|
}
|
|
998
1244
|
|
|
999
1245
|
function gzipTo(archiveDir, rel, bytes, now) {
|
|
1000
|
-
|
|
1246
|
+
// archiveDir may not exist yet on the first rotation (2.3.0 lane pipeline):
|
|
1247
|
+
// ensureDir(archiveDir, archiveDir) would fail realpathSync on a missing root,
|
|
1248
|
+
// so create the absolute archive directory directly; callers already proved it
|
|
1249
|
+
// lives inside the memory root.
|
|
1250
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
1001
1251
|
const gzRel = `${rel}.gz`;
|
|
1002
1252
|
const gzAbs = path.join(archiveDir, gzRel);
|
|
1003
1253
|
const gz = zlib.gzipSync(bytes, { level: 9 });
|
|
@@ -1013,9 +1263,12 @@ function appendRotationManifest(root, row) {
|
|
|
1013
1263
|
}
|
|
1014
1264
|
|
|
1015
1265
|
/**
|
|
1016
|
-
* 月文件 →
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1266
|
+
* 月文件 → 日文件:按真实行首分组——`## YYYY-MM-DD · 标题` / `# YYYY-MM-DD` /
|
|
1267
|
+
* 裸日期 `YYYY-MM-DD` 开头都算当天入口;`- HH:MM · 轮次…` 这类只有时间的流水行
|
|
1268
|
+
* 跟随最近的日期段(2026-11/12 真实 journal 就是这两种行首)。
|
|
1269
|
+
* 开头无日期的行(frontmatter、`# 2026 年…` 旧标题)留给归档,不硬塞进某一天;
|
|
1270
|
+
* 如果一个日期都认不出来,返回 ok:false + 计数,由 rotateJournals/maintenance 告警,
|
|
1271
|
+
* 不再静默 no-op。
|
|
1019
1272
|
*/
|
|
1020
1273
|
function splitMonthJournal(root, name, now, dryRun) {
|
|
1021
1274
|
const journalDir = resolveInside(root, JOURNAL_DIR_REL);
|
|
@@ -1024,14 +1277,26 @@ function splitMonthJournal(root, name, now, dryRun) {
|
|
|
1024
1277
|
const lines = text.split('\n');
|
|
1025
1278
|
const groups = new Map();
|
|
1026
1279
|
let current = null;
|
|
1280
|
+
let undated = 0;
|
|
1281
|
+
let timeOnlyWithoutDay = 0;
|
|
1027
1282
|
for (const line of lines) {
|
|
1028
|
-
const hit =
|
|
1029
|
-
if (hit)
|
|
1030
|
-
|
|
1283
|
+
const hit = journalDayOfLine(line);
|
|
1284
|
+
if (hit) {
|
|
1285
|
+
current = hit;
|
|
1286
|
+
} else if (current === null) {
|
|
1287
|
+
// 头部无日期的行:归档时原样保留,不属于任何一天。
|
|
1288
|
+
if (line.trim() !== '') {
|
|
1289
|
+
undated += 1;
|
|
1290
|
+
if (JOURNAL_TIME_BULLET_RE.test(line)) timeOnlyWithoutDay += 1;
|
|
1291
|
+
}
|
|
1292
|
+
continue;
|
|
1293
|
+
}
|
|
1031
1294
|
if (!groups.has(current)) groups.set(current, []);
|
|
1032
1295
|
groups.get(current).push(line);
|
|
1033
1296
|
}
|
|
1034
|
-
if (groups.size === 0)
|
|
1297
|
+
if (groups.size === 0) {
|
|
1298
|
+
return { name, ok: false, reason: 'no-dated-lines', lines: lines.length, undated, timeOnlyWithoutDay };
|
|
1299
|
+
}
|
|
1035
1300
|
const written = [];
|
|
1036
1301
|
if (!dryRun) {
|
|
1037
1302
|
for (const [day, groupLines] of groups) {
|
|
@@ -1079,6 +1344,17 @@ export function rotateJournals({ memoryRoot, now = new Date(), config = {}, dryR
|
|
|
1079
1344
|
try {
|
|
1080
1345
|
const result = splitMonthJournal(root, name, at, dryRun);
|
|
1081
1346
|
if (result.ok) report.split.push(result);
|
|
1347
|
+
else {
|
|
1348
|
+
// 2.3.0 lane pipeline:认不出日期不是「无事发生」,必须进 errors 让上游可见。
|
|
1349
|
+
report.errors.push({
|
|
1350
|
+
name,
|
|
1351
|
+
code: 'W_MONTH_SPLIT_NO_DATED_LINES',
|
|
1352
|
+
reason: result.reason ?? 'no-dated-lines',
|
|
1353
|
+
lines: result.lines ?? null,
|
|
1354
|
+
undated: result.undated ?? null,
|
|
1355
|
+
timeOnlyWithoutDay: result.timeOnlyWithoutDay ?? null,
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1082
1358
|
} catch (error) {
|
|
1083
1359
|
report.errors.push({ name, code: String(error?.code ?? error?.message ?? error) });
|
|
1084
1360
|
}
|