@jjh32456/longlive 1.8.12 → 2.0.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 +232 -202
- package/QUICKSTART.md +10 -11
- package/README.en.md +13 -4
- package/README.md +42 -11
- package/SPEC.md +3 -3
- package/build-info.json +231 -121
- package/cordis.patch.yml +32 -1
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/AUTO-RECALL.md +1 -1
- package/docs/CONFIG.md +41 -9
- package/docs/FAQ.md +7 -7
- package/docs/FEATURES.md +6 -6
- package/docs/OPERATIONS.md +1 -1
- package/docs/PANEL-INTEGRATION.md +1 -1
- package/docs/PRIVACY.md +5 -5
- package/docs/QUICKSTART.md +3 -3
- package/docs/README.en.md +4 -2
- package/docs/TROUBLESHOOTING.md +4 -4
- package/package.json +6 -3
- package/runbook.md +3 -3
- package/scripts/migrate-200.mjs +8 -0
- package/scripts/migrate-lifecycle.mjs +2 -2
- package/src/answer/claim-guard.mjs +234 -0
- package/src/backup.js +165 -1
- package/src/config.js +18 -7
- package/src/features.js +128 -5
- package/src/handoff/index.js +133 -0
- package/src/handoff/model.js +48 -0
- package/src/identity/handover.js +203 -15
- package/src/identity/inject-position.js +3 -1
- package/src/memory/a1-migration.js +72 -6
- package/src/memory/archive-cold-state.mjs +794 -0
- package/src/memory/archive-staging.mjs +305 -0
- package/src/memory/archive.mjs +415 -0
- package/src/memory/capture-host.js +71 -2
- package/src/memory/capture.js +45 -6
- package/src/memory/catchup.mjs +534 -0
- package/src/memory/conclusion-distill.js +51 -2
- package/src/memory/conclusion-drafts.js +7 -3
- package/src/memory/conflicts.js +915 -2
- package/src/memory/consolidate.js +20 -1
- package/src/memory/forget-v2.js +272 -2
- package/src/memory/forget.js +20 -1
- package/src/memory/frames-activation.js +3 -1
- package/src/memory/fts-query.js +2 -2
- package/src/memory/index.js +80 -7
- package/src/memory/land.mjs +743 -0
- package/src/memory/lifecycle.js +128 -0
- package/src/memory/maintenance.js +386 -22
- package/src/memory/memory-health.mjs +607 -0
- package/src/memory/migrate-200.js +1681 -0
- package/src/memory/migrate-lifecycle.js +3 -3
- package/src/memory/procedure-candidate.mjs +377 -0
- package/src/memory/procedure.js +20 -1
- package/src/memory/prospective-memory.mjs +362 -0
- package/src/memory/recall-feedback.mjs +406 -0
- package/src/memory/recall-v2.js +13 -1
- package/src/memory/recall.js +102 -1
- package/src/memory/reinforce.js +138 -2
- package/src/memory/retention.js +34 -0
- package/src/memory/turn-budget.mjs +290 -0
- package/src/memory/wake-bridge.mjs +2999 -0
- package/src/memory/working-frame.js +271 -8
- package/src/metrics/classify.mjs +3 -1
- package/src/recall/archive-config.mjs +130 -0
- package/src/recall/archive-fallback.mjs +174 -19
- package/src/recall/archive-search.mjs +3 -0
- package/src/recall/archive-state.mjs +588 -0
- package/src/recall/brain.mjs +501 -0
- package/src/recall/current-line.mjs +110 -0
- package/src/recall/edges.js +21 -2
- package/src/recall/explain.mjs +10 -0
- package/src/recall/gate-log.mjs +280 -0
- package/src/recall/gate-metrics.mjs +191 -0
- package/src/recall/index.js +322 -21
- package/src/recall/inject-order.mjs +3 -1
- package/src/recall/recall-core.mjs +47 -2
- package/src/recall/turn-budget-inject.mjs +154 -0
- package/src/retention/cold-gate.mjs +146 -0
- package/src/retention/config.js +58 -1
- package/src/retention/index.js +193 -35
- package/src/router/design-headings.json +10 -10
- package/src/tools.js +122 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// B3 已落 worktree · 召回块按「每轮统一预算」注入的挂点模块(2026-11-29 已接线:src/recall/index.js 渲染 + src/recall/brain.mjs 判决)
|
|
2
|
+
//
|
|
3
|
+
// 挂点位置(worktree 现状):
|
|
4
|
+
// - src/recall/index.js:1020-1031:finalText 组装后只有 token 口径的 while 裁剪(cfg.budget 默认 1200 token),
|
|
5
|
+
// 没有 2,000 字/轮 的字符口径上限 → 本模块替换该段。
|
|
6
|
+
// - src/recall/index.js:1105-1115:logRecall 只带 tokens=estimateTokens(finalText),没有延迟/字符数。
|
|
7
|
+
// - src/recall/brain.mjs:211/374/440:writeGateRow / finishPendingInjection / recordPendingResult 写 gate 行,
|
|
8
|
+
// ok 行 reason 为空、且没有 injectedTokens/elapsedMs → 本模块 + gate-metrics.mjs 补齐。
|
|
9
|
+
//
|
|
10
|
+
// 拆账(DESIGN.v0.5.2 L103 / MERGE-PLAN §10):召回块 990 字 =
|
|
11
|
+
// 头/recallId/取代冲突/零命中 60 + 卡区 750(5 卡 × 150 字)+ 程序卡 2×60=120 + 当前线 60。
|
|
12
|
+
// 这里拆出子额度只做诊断和渲染参数(卡摘要 120 字、每卡 150 字),硬保证仍是整块 990 字上限。
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
TURN_BUDGET_RECALL_CHARS,
|
|
16
|
+
charLength,
|
|
17
|
+
estimateTurnTokens,
|
|
18
|
+
trimToChars,
|
|
19
|
+
} from '../memory/turn-budget.mjs';
|
|
20
|
+
|
|
21
|
+
export const RECALL_LANE_HEADER_CHARS = 60;
|
|
22
|
+
export const RECALL_LANE_CARD_AREA_CHARS = 750;
|
|
23
|
+
export const RECALL_LANE_PROCEDURE_AREA_CHARS = 120;
|
|
24
|
+
export const RECALL_LANE_CURRENT_LINE_CHARS = 60;
|
|
25
|
+
export const RECALL_CARD_TOTAL_CHARS = 150;
|
|
26
|
+
export const RECALL_CARD_EXCERPT_CHARS = 120;
|
|
27
|
+
|
|
28
|
+
export const RECALL_LANE_SUB_BUDGET = Object.freeze({
|
|
29
|
+
header: RECALL_LANE_HEADER_CHARS,
|
|
30
|
+
cards: RECALL_LANE_CARD_AREA_CHARS,
|
|
31
|
+
procedures: RECALL_LANE_PROCEDURE_AREA_CHARS,
|
|
32
|
+
currentLine: RECALL_LANE_CURRENT_LINE_CHARS,
|
|
33
|
+
total: TURN_BUDGET_RECALL_CHARS,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 召回注入的判决空间:B3 口径下不存在 'skip'(每用户轮必注入);
|
|
37
|
+
// 关掉硬门 = disabled,子代理/非用户轮 = warn 且不注入,失败 = fail 带原因码,零命中 = zero-hit 仍注入兜底块。
|
|
38
|
+
export const RECALL_INJECTION_DECISIONS = Object.freeze(['ok', 'zero-hit', 'disabled', 'fail', 'warn']);
|
|
39
|
+
|
|
40
|
+
function codedError(code, message, detail) {
|
|
41
|
+
const error = new Error(`${code} ${message}`);
|
|
42
|
+
error.code = code;
|
|
43
|
+
if (detail !== undefined) error.detail = detail;
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function recallLaneSubBudget() {
|
|
48
|
+
return { ...RECALL_LANE_SUB_BUDGET };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function recallSubBudgetSum() {
|
|
52
|
+
return (
|
|
53
|
+
RECALL_LANE_HEADER_CHARS + RECALL_LANE_CARD_AREA_CHARS + RECALL_LANE_PROCEDURE_AREA_CHARS + RECALL_LANE_CURRENT_LINE_CHARS
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function recallLaneCapChars() {
|
|
58
|
+
return TURN_BUDGET_RECALL_CHARS;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 传给 recall-core.chooseRecall 的 token 预算:990 字扣掉固定头 60 字后按 2 字/token 折算(≈465 token)。
|
|
62
|
+
// 只作为 chooseRecall 的中间约束,最终仍由 applyRecallLaneBudget 用字符口径兜底。
|
|
63
|
+
export function recallChooseBudgetTokens() {
|
|
64
|
+
const chars = Math.max(0, TURN_BUDGET_RECALL_CHARS - RECALL_LANE_HEADER_CHARS);
|
|
65
|
+
return Math.max(1, estimateTurnTokens(chars));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 单卡摘要的 token 上限:DESIGN 每卡 150 字含 title/path/锚点,摘要 120 字 → ≈60 token。
|
|
69
|
+
export function recallExcerptTokens() {
|
|
70
|
+
return Math.max(1, estimateTurnTokens(RECALL_CARD_EXCERPT_CHARS));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isProcedureBlock(block) {
|
|
74
|
+
return /(^|\n)\s*(?:[-*]\s*)?(\[程序\]|【程序】)/.test(block);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isCurrentLineBlock(block) {
|
|
78
|
+
return /当前线/.test(block);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 诊断用:把最终注入文本按「头 / 卡区 / 程序卡 / 当前线」粗分,检查是否超子额度。
|
|
82
|
+
// 注意:超子额度只告警,硬上限是整块 990 字,裁剪从尾部做(DESIGN L103「超限从尾裁剪」)。
|
|
83
|
+
export function measureRecallLane(text) {
|
|
84
|
+
const source = typeof text === 'string' ? text : '';
|
|
85
|
+
const totalChars = charLength(source);
|
|
86
|
+
const blocks = source.length > 0 ? source.split(/\n{2,}/) : [];
|
|
87
|
+
const holder = blocks[0] ?? '';
|
|
88
|
+
const headerChars = charLength(holder);
|
|
89
|
+
const procedureChars = blocks.slice(1).filter(isProcedureBlock).reduce((sum, block) => sum + charLength(block), 0);
|
|
90
|
+
const currentLineChars = blocks.slice(1).filter(isCurrentLineBlock).reduce((sum, block) => sum + charLength(block), 0);
|
|
91
|
+
const cardAreaChars = Math.max(0, totalChars - headerChars - procedureChars - currentLineChars);
|
|
92
|
+
const subBudget = recallLaneSubBudget();
|
|
93
|
+
const overflows = [];
|
|
94
|
+
if (totalChars > subBudget.total) overflows.push({ part: 'total', chars: totalChars, cap: subBudget.total });
|
|
95
|
+
if (headerChars > subBudget.header) overflows.push({ part: 'header', chars: headerChars, cap: subBudget.header });
|
|
96
|
+
if (cardAreaChars > subBudget.cards) overflows.push({ part: 'cards', chars: cardAreaChars, cap: subBudget.cards });
|
|
97
|
+
if (procedureChars > subBudget.procedures) overflows.push({ part: 'procedures', chars: procedureChars, cap: subBudget.procedures });
|
|
98
|
+
if (currentLineChars > subBudget.currentLine) overflows.push({ part: 'currentLine', chars: currentLineChars, cap: subBudget.currentLine });
|
|
99
|
+
return { totalChars, headerChars, cardAreaChars, procedureChars, currentLineChars, subBudget, overflows };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 挂点主函数:召回注入前把 finalText 压进 990 字车道(超限从尾裁剪,保留头/recallId)。
|
|
103
|
+
export function applyRecallLaneBudget(text, options = {}) {
|
|
104
|
+
const laneChars = Number.isFinite(Number(options.laneChars))
|
|
105
|
+
? Math.max(0, Math.floor(Number(options.laneChars)))
|
|
106
|
+
: TURN_BUDGET_RECALL_CHARS;
|
|
107
|
+
const source = typeof text === 'string' ? text : '';
|
|
108
|
+
const holder = trimToChars(source, laneChars, { ellipsis: options.ellipsis ?? '…' });
|
|
109
|
+
const measurement = measureRecallLane(holder.text);
|
|
110
|
+
if (holder.chars > laneChars) {
|
|
111
|
+
throw codedError('E_HG_RECALL_LANE_OVERFLOW', `召回注入 ${holder.chars} 字超 ${laneChars} 字`, { chars: holder.chars, laneChars });
|
|
112
|
+
}
|
|
113
|
+
return { text: holder.text, chars: holder.chars, trimmed: holder.trimmed, laneChars, measurement };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// gate-log / recall-log 记录用:字符数 + token 估算 + 本轮耗时(L7 的 token/延迟字段来源)。
|
|
117
|
+
export function buildRecallLaneMetrics(lane, elapsedMs = 0) {
|
|
118
|
+
const chars = Math.max(0, Math.floor(Number(lane?.chars) || 0));
|
|
119
|
+
const elapsed = Math.max(0, Math.floor(Number(elapsedMs) || 0));
|
|
120
|
+
return { injectedChars: chars, injectedTokens: estimateTurnTokens(chars), elapsedMs: elapsed };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function assertRecallLaneFit(lane) {
|
|
124
|
+
const chars = Math.max(0, Math.floor(Number(lane?.chars) || 0));
|
|
125
|
+
if (chars > recallLaneCapChars()) {
|
|
126
|
+
throw codedError('E_HG_RECALL_LANE_OVERFLOW', `召回注入 ${chars} 字超 ${recallLaneCapChars()} 字`, { chars, cap: recallLaneCapChars() });
|
|
127
|
+
}
|
|
128
|
+
return lane;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 注入判决:B3 每用户轮必注入;子代理/非用户轮只记 warn 不注入;关硬门记 disabled;
|
|
132
|
+
// 失败记 fail + 原因码;零命中仍注入兜底块并记 zero-hit。任何分支都不返回 'skip'。
|
|
133
|
+
export function resolveRecallInjectionDecision(options = {}) {
|
|
134
|
+
const { killswitch = false, subagent = false, nonUser = false, zeroHit = false, failed = false, noChannel = false } = options;
|
|
135
|
+
if (failed || noChannel) {
|
|
136
|
+
return { inject: false, decision: 'fail', reason: noChannel ? 'E_HG_RECALL_NO_CHANNEL' : 'E_HG_RECALL_INJECT', metricsRequired: true };
|
|
137
|
+
}
|
|
138
|
+
if (killswitch) return { inject: false, decision: 'disabled', reason: 'killswitch', metricsRequired: false };
|
|
139
|
+
if (subagent) return { inject: false, decision: 'warn', reason: 'W_HG_SUBAGENT', metricsRequired: false };
|
|
140
|
+
if (nonUser) return { inject: false, decision: 'warn', reason: 'W_HG_NONUSER', metricsRequired: false };
|
|
141
|
+
if (zeroHit) return { inject: true, decision: 'zero-hit', reason: 'zero-hit', metricsRequired: true };
|
|
142
|
+
return { inject: true, decision: 'ok', reason: 'hit', metricsRequired: true };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function assertRecallInjectionDecision(verdict) {
|
|
146
|
+
const decision = String(verdict?.decision ?? '');
|
|
147
|
+
if (!RECALL_INJECTION_DECISIONS.includes(decision)) {
|
|
148
|
+
throw codedError('E_HG_RECALL_DECISION', `非法召回判决 ${decision || '(空)'}`, { decision });
|
|
149
|
+
}
|
|
150
|
+
if (String(verdict?.reason ?? '').trim() === '') {
|
|
151
|
+
throw codedError('E_HG_RECALL_REASON', '召回判决必须带非空 reason', { decision });
|
|
152
|
+
}
|
|
153
|
+
return verdict;
|
|
154
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// B7b 草案:retention 冷档门禁 —— janitor 删除前的统一入口。
|
|
2
|
+
//
|
|
3
|
+
// 契约(V0.5.2-RETENTION-PATCH §3 L19-20、D11 T4):
|
|
4
|
+
// - 冷档未配置(recall.archiveRoot 缺省)→ 保持 2.0.0 旧行为(allowDeleting=true,reason=not-configured),
|
|
5
|
+
// 但调用方必须写 gate-log 提示"未迁移冷档";
|
|
6
|
+
// - 冷档已配置 → 只有 archive-state 的 {phase:'migrated', migrated:true, coldManifestSha} 且冷副本
|
|
7
|
+
// sha 全部匹配,才允许删原件;否则 allowDeleting=false,绝不写 C: 影子副本、绝不降级;
|
|
8
|
+
// (archive-reconcile 契约 §0-2:冷迁移清单 sha 名为 coldManifestSha,state.manifestSha 只属 B5 探针/digest)
|
|
9
|
+
// - 冷盘离线:无论 archiveFailOpen 真假,都不允许删除(failOpen 只影响 recall 读,不放行删除);
|
|
10
|
+
// - 状态文件坏/缺字段:fail-closed 拒删(E_HG_ARCHIVE_MIGRATE_MISMATCH)。
|
|
11
|
+
//
|
|
12
|
+
// 本模块只读 + 纯判定,不删文件;真正删除走 memory/archive-cold-state.mjs 的
|
|
13
|
+
// deleteOriginalAfterMigrate(带 intent WAL)或由 janitor 先过本模块再删。
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import { normalizeArchiveConfig, resolveArchiveStatePath } from '../recall/archive-config.mjs';
|
|
16
|
+
import { readColdState, gateColdArchive, gateColdDeletion, COLD_CODES } from '../memory/archive-cold-state.mjs';
|
|
17
|
+
|
|
18
|
+
export const COLD_GATE_SCHEMA = 'retention-cold-gate/v1';
|
|
19
|
+
export const COLD_GATE_CODES = Object.freeze({
|
|
20
|
+
notConfigured: 'E_HG_ARCHIVE_NOT_CONFIGURED',
|
|
21
|
+
offline: COLD_CODES.offline,
|
|
22
|
+
unmigrated: COLD_CODES.unmigrated,
|
|
23
|
+
migratedDigestMismatch: 'E_HG_ARCHIVE_MIGRATE_MISMATCH',
|
|
24
|
+
coldMismatch: COLD_CODES.coldMismatch,
|
|
25
|
+
coldTampered: COLD_CODES.coldTampered,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function boolOr(value, fallback) {
|
|
29
|
+
return typeof value === 'boolean' ? value : fallback;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 判定 retention 层是否可删原件。
|
|
34
|
+
* 返回 {schema, configured, allowDeleting, migrated, phase, code, reason, failOpen, online,
|
|
35
|
+
* manifestSha, statePath, state, gate, archiveConfig, warnings}
|
|
36
|
+
*/
|
|
37
|
+
export function evaluateRetentionColdGate({ memoryRoot, config = null, now = new Date(), online, requireConfigured = false } = {}) {
|
|
38
|
+
const cfg = normalizeArchiveConfig(config ?? {});
|
|
39
|
+
const statePath = resolveArchiveStatePath(memoryRoot, cfg);
|
|
40
|
+
const configured = cfg.configured;
|
|
41
|
+
const failOpen = boolOr(cfg.archiveFailOpen, false);
|
|
42
|
+
const base = {
|
|
43
|
+
schema: COLD_GATE_SCHEMA,
|
|
44
|
+
configured,
|
|
45
|
+
failOpen,
|
|
46
|
+
online: true,
|
|
47
|
+
statePath,
|
|
48
|
+
archiveConfig: cfg,
|
|
49
|
+
warnings: cfg.warnings,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!configured) {
|
|
53
|
+
return {
|
|
54
|
+
...base,
|
|
55
|
+
allowDeleting: requireConfigured !== true,
|
|
56
|
+
migrated: false,
|
|
57
|
+
phase: 'idle',
|
|
58
|
+
code: requireConfigured === true ? COLD_GATE_CODES.notConfigured : null,
|
|
59
|
+
reason: 'cold-archive-not-configured',
|
|
60
|
+
manifestSha: null,
|
|
61
|
+
state: null,
|
|
62
|
+
gate: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let onlineFlag = boolOr(online, null);
|
|
67
|
+
if (onlineFlag === null) {
|
|
68
|
+
try {
|
|
69
|
+
onlineFlag = fs.existsSync(cfg.archiveRoot);
|
|
70
|
+
} catch {
|
|
71
|
+
onlineFlag = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
base.online = onlineFlag;
|
|
75
|
+
|
|
76
|
+
const read = readColdState({ memoryRoot, statePath, now });
|
|
77
|
+
if (read.ok !== true) {
|
|
78
|
+
return {
|
|
79
|
+
...base,
|
|
80
|
+
allowDeleting: false,
|
|
81
|
+
migrated: false,
|
|
82
|
+
phase: read.cold?.phase ?? 'unknown',
|
|
83
|
+
code: COLD_GATE_CODES.migratedDigestMismatch,
|
|
84
|
+
reason: `archive-state 不可读:${read.reason ?? 'unknown'}`,
|
|
85
|
+
manifestSha: null,
|
|
86
|
+
state: null,
|
|
87
|
+
gate: null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const gate = gateColdArchive({
|
|
92
|
+
memoryRoot,
|
|
93
|
+
cold: read.cold,
|
|
94
|
+
statePath,
|
|
95
|
+
online: onlineFlag,
|
|
96
|
+
failOpen,
|
|
97
|
+
expectedManifestSha: null,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
...base,
|
|
102
|
+
allowDeleting: gate.allowed === true,
|
|
103
|
+
migrated: read.cold.migrated === true && read.cold.phase === 'migrated',
|
|
104
|
+
phase: read.cold.phase,
|
|
105
|
+
code: gate.allowed === true ? null : (gate.code ?? COLD_GATE_CODES.unmigrated),
|
|
106
|
+
reason: gate.reason ?? null,
|
|
107
|
+
manifestSha: read.cold.coldManifestSha,
|
|
108
|
+
state: read.cold,
|
|
109
|
+
gate,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* janitor 层入口:返回 null = 可以继续;返回 {code,reason} = 跳过该层。
|
|
115
|
+
* 语义与 P5/P6 一致:未迁移/离线/状态坏 → 整层跳过,事件 retention.skip.unmigrated。
|
|
116
|
+
*/
|
|
117
|
+
export function coldGateLayer({ memoryRoot, layer, config = null, now = new Date(), online, requireConfigured = true } = {}) {
|
|
118
|
+
const gate = evaluateRetentionColdGate({ memoryRoot, config, now, online, requireConfigured });
|
|
119
|
+
if (gate.allowDeleting === true) return null;
|
|
120
|
+
return {
|
|
121
|
+
layer: layer ?? 'hot-truncate',
|
|
122
|
+
code: gate.code ?? COLD_GATE_CODES.unmigrated,
|
|
123
|
+
reason: gate.reason ?? 'cold-gate-denied',
|
|
124
|
+
event: 'retention.skip.unmigrated',
|
|
125
|
+
phase: gate.phase,
|
|
126
|
+
failOpen: gate.failOpen,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 单文件入口:层门禁放行后,逐文件复核 manifest 条目 + 冷副本 sha + 源 sha。 */
|
|
131
|
+
export function coldGateFile({ memoryRoot, relPath, config = null, now = new Date(), online, sha256 = null } = {}) {
|
|
132
|
+
const gate = evaluateRetentionColdGate({ memoryRoot, config, now, online, requireConfigured: true });
|
|
133
|
+
if (gate.allowDeleting !== true) {
|
|
134
|
+
return { allowed: false, code: gate.code, reason: gate.reason, gate };
|
|
135
|
+
}
|
|
136
|
+
const perFile = gateColdDeletion({
|
|
137
|
+
memoryRoot,
|
|
138
|
+
rel: relPath,
|
|
139
|
+
sha256,
|
|
140
|
+
statePath: gate.statePath,
|
|
141
|
+
coldRoot: gate.archiveConfig.archiveRoot,
|
|
142
|
+
failOpen: gate.failOpen,
|
|
143
|
+
online: gate.online,
|
|
144
|
+
});
|
|
145
|
+
return { allowed: perFile.allowed === true, code: perFile.code ?? null, reason: perFile.reason ?? null, gate, perFile };
|
|
146
|
+
}
|
package/src/retention/config.js
CHANGED
|
@@ -11,7 +11,8 @@ export const RETENTION_DEFAULTS = Object.freeze({
|
|
|
11
11
|
enabled: false,
|
|
12
12
|
dryRun: true,
|
|
13
13
|
intervalMs: 24 * 60 * 60 * 1000,
|
|
14
|
-
|
|
14
|
+
// 批 C(M25):默认不许在启动瞬间跑清理;必须等门禁(冷档校验 + approve)就绪。
|
|
15
|
+
runOnStart: false,
|
|
15
16
|
hotTruncate: Object.freeze({
|
|
16
17
|
maxBytes: 2 * GIB,
|
|
17
18
|
maxAgeDays: 14,
|
|
@@ -42,8 +43,62 @@ export const RETENTION_DEFAULTS = Object.freeze({
|
|
|
42
43
|
budgetBytes: 8 * GIB,
|
|
43
44
|
warnRatio: 0.85,
|
|
44
45
|
}),
|
|
46
|
+
// 分层开关:null = 未显式配置(沿用 enabled);配置后每层默认 false。
|
|
47
|
+
layers: null,
|
|
48
|
+
// 冷档校验参数(由调用方显式传;不配置即不启用该门)。
|
|
49
|
+
coldArchive: null,
|
|
45
50
|
});
|
|
46
51
|
|
|
52
|
+
function normalizeLayers(raw) {
|
|
53
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const name of ['hotTruncate', 'toolOutput', 'indexArtifacts', 'handoff', 'backup']) {
|
|
56
|
+
if (typeof raw[name] === 'boolean') out[name] = raw[name];
|
|
57
|
+
}
|
|
58
|
+
if (typeof raw.all === 'boolean') {
|
|
59
|
+
for (const name of Object.keys(out)) out[name] = raw.all;
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function normalizeColdArchive(raw) {
|
|
65
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
66
|
+
return {
|
|
67
|
+
root: text(raw.root, ''),
|
|
68
|
+
manifest: text(raw.manifest, ''),
|
|
69
|
+
requireApprove: bool(raw.requireApprove, false),
|
|
70
|
+
approvalFile: text(raw.approvalFile, ''),
|
|
71
|
+
manifestSha256: text(raw.manifestSha256, ''),
|
|
72
|
+
// 2.0.0 W3c(B7):冷层迁移二次 approve 账本(相对 memoryRoot;空=不启用)。
|
|
73
|
+
approveLedger: text(raw.approveLedger, ''),
|
|
74
|
+
requireMigrateApprovals: bool(raw.requireMigrateApprovals, false),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 某层是否允许执行:显式 layers 优先,未配置时沿用 enabled。 */
|
|
79
|
+
export function retentionLayerEnabled(config, name) {
|
|
80
|
+
const layers = config && config.layers;
|
|
81
|
+
if (layers && typeof layers === 'object' && typeof layers[name] === 'boolean') return layers[name];
|
|
82
|
+
return Boolean(config && config.enabled === true);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 零上限层(maxAgeDays=0 或 maxBytes=0):语义是「删光整层」,必须 fail-closed。
|
|
87
|
+
* 返回需要拒绝执行的层名列表;空数组 = 正常。
|
|
88
|
+
*/
|
|
89
|
+
export function retentionZeroLimitLayers(config) {
|
|
90
|
+
const out = [];
|
|
91
|
+
for (const [name, block] of [
|
|
92
|
+
['hotTruncate', config && config.hotTruncate],
|
|
93
|
+
['toolOutput', config && config.toolOutput],
|
|
94
|
+
['handoff', config && config.handoff],
|
|
95
|
+
]) {
|
|
96
|
+
if (!block || typeof block !== 'object') continue;
|
|
97
|
+
if (Number(block.maxAgeDays) === 0 || Number(block.maxBytes) === 0) out.push(name);
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
47
102
|
function num(value, fallback, min, max) {
|
|
48
103
|
const n = Number(value);
|
|
49
104
|
if (!Number.isFinite(n)) return fallback;
|
|
@@ -102,5 +157,7 @@ export function normalizeRetentionConfig(raw) {
|
|
|
102
157
|
budgetBytes: int(health.budgetBytes, RETENTION_DEFAULTS.health.budgetBytes, 0, Number.MAX_SAFE_INTEGER),
|
|
103
158
|
warnRatio: num(health.warnRatio, RETENTION_DEFAULTS.health.warnRatio, 0, 1),
|
|
104
159
|
},
|
|
160
|
+
layers: normalizeLayers(src.layers),
|
|
161
|
+
coldArchive: normalizeColdArchive(src.coldArchive),
|
|
105
162
|
};
|
|
106
163
|
}
|
package/src/retention/index.js
CHANGED
|
@@ -17,10 +17,33 @@
|
|
|
17
17
|
|
|
18
18
|
import fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
|
-
import {
|
|
20
|
+
import { createRequire } from 'node:module';
|
|
21
|
+
import { RETENTION_DEFAULTS, normalizeRetentionConfig, retentionLayerEnabled, retentionZeroLimitLayers } from './config.js';
|
|
22
|
+
// B7b 草案:冷档门禁 / 三键归一化 / 审计事件。
|
|
23
|
+
import { normalizeArchiveConfig } from '../recall/archive-config.mjs';
|
|
24
|
+
import { evaluateRetentionColdGate } from './cold-gate.mjs';
|
|
25
|
+
import { appendGateLog } from '../recall/gate-log.mjs';
|
|
21
26
|
|
|
22
27
|
export { RETENTION_DEFAULTS, normalizeRetentionConfig } from './config.js';
|
|
23
28
|
|
|
29
|
+
// 2.0.0 W3c(B7):冷层迁移二次 approve 账本(只读校验,不写)。
|
|
30
|
+
// archive-reconcile §0-3:migrate-200.js 只在 B7a 落地后存在(已装 2.0.0 没有该文件),
|
|
31
|
+
// 顶层静态 import 会在未迁移环境直接 ERR_MODULE_NOT_FOUND、拖垮整个插件。这里改为
|
|
32
|
+
// 惰性能力探测:函数缺失(或旧 Node 不支持 require(ESM))返回 null,调用点 fail-closed
|
|
33
|
+
//(handoff 层拒删 + 审计事件),不让整轮 retention 崩。
|
|
34
|
+
const requireCjs = createRequire(import.meta.url);
|
|
35
|
+
let coldMoveApprovedLoader = null;
|
|
36
|
+
function loadIsColdMoveApproved() {
|
|
37
|
+
if (typeof coldMoveApprovedLoader === 'function') return coldMoveApprovedLoader;
|
|
38
|
+
try {
|
|
39
|
+
const mod = requireCjs('../memory/migrate-200.js');
|
|
40
|
+
if (typeof mod?.isColdMoveApproved === 'function') coldMoveApprovedLoader = mod.isColdMoveApproved;
|
|
41
|
+
} catch {
|
|
42
|
+
coldMoveApprovedLoader = null;
|
|
43
|
+
}
|
|
44
|
+
return coldMoveApprovedLoader;
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
25
48
|
const RETENTION_SCHEMA = 'dsh-retention/v1';
|
|
26
49
|
const RETENTION_DIR = 'retention';
|
|
@@ -476,6 +499,25 @@ export function runRetention(options = {}) {
|
|
|
476
499
|
if (!cfg.enabled && options.force !== true) {
|
|
477
500
|
return { ok: true, enabled: false, dryRun, skipped: 'disabled', audit };
|
|
478
501
|
}
|
|
502
|
+
// 批 C(M25):零上限 = 删光整层。fail-closed:报错并拒绝执行,绝不删任何文件。
|
|
503
|
+
const zeroLayers = retentionZeroLimitLayers(cfg);
|
|
504
|
+
if (zeroLayers.length > 0) {
|
|
505
|
+
for (const layer of zeroLayers) {
|
|
506
|
+
audit.errors.push({ layer, code: 'E_HG_RETENTION_ZERO_LIMIT', reason: 'zero-limit' });
|
|
507
|
+
}
|
|
508
|
+
audit.status = 'partial';
|
|
509
|
+
audit.warnings.push(`[retention] zero limit refused: ${zeroLayers.join(',')}`);
|
|
510
|
+
return {
|
|
511
|
+
ok: false,
|
|
512
|
+
enabled: true,
|
|
513
|
+
dryRun,
|
|
514
|
+
error: 'E_HG_RETENTION_ZERO_LIMIT',
|
|
515
|
+
code: 'E_HG_RETENTION_ZERO_LIMIT',
|
|
516
|
+
skipped: 'zero-limit',
|
|
517
|
+
zeroLimitLayers: zeroLayers,
|
|
518
|
+
audit,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
479
521
|
if (!memoryRoot) {
|
|
480
522
|
return { ok: false, enabled: true, dryRun, error: 'memory-root-missing', audit };
|
|
481
523
|
}
|
|
@@ -484,40 +526,140 @@ export function runRetention(options = {}) {
|
|
|
484
526
|
audit.warnings.push(`[retention] .longlive health=${audit.health.state} ${audit.health.totalBytes}/${audit.health.budgetBytes} bytes`);
|
|
485
527
|
}
|
|
486
528
|
|
|
529
|
+
// B7b(P5/P6):冷档门禁——已配置冷档但未 migrated / 离线 / 状态坏 → hotTruncate/toolOutput
|
|
530
|
+
// 整层跳过,绝不把"未冷档"的原件当垃圾删掉;缺省未配置冷档 → 保持 2.0.0 legacy 行为。
|
|
531
|
+
const recallRaw = options.recallConfig ?? options.config?.recall ?? {};
|
|
532
|
+
const coldGate = evaluateRetentionColdGate({
|
|
533
|
+
memoryRoot,
|
|
534
|
+
config: { recall: recallRaw },
|
|
535
|
+
now,
|
|
536
|
+
online: options.archiveOnline,
|
|
537
|
+
});
|
|
538
|
+
audit.coldArchive = {
|
|
539
|
+
configured: coldGate.configured,
|
|
540
|
+
allowDeleting: coldGate.allowDeleting,
|
|
541
|
+
migrated: coldGate.migrated,
|
|
542
|
+
phase: coldGate.phase,
|
|
543
|
+
code: coldGate.code,
|
|
544
|
+
reason: coldGate.reason,
|
|
545
|
+
failOpen: coldGate.failOpen,
|
|
546
|
+
online: coldGate.online,
|
|
547
|
+
manifestSha: coldGate.manifestSha,
|
|
548
|
+
};
|
|
549
|
+
const coldSkip = coldGate.configured && coldGate.allowDeleting !== true;
|
|
550
|
+
if (coldSkip) {
|
|
551
|
+
audit.errors.push({ layer: 'cold', code: coldGate.code, reason: coldGate.reason, event: 'retention.skip.unmigrated' });
|
|
552
|
+
}
|
|
553
|
+
|
|
487
554
|
const layers = [];
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
555
|
+
if (retentionLayerEnabled(cfg, 'hotTruncate') && !coldSkip) {
|
|
556
|
+
const hot = planHotTruncate(memoryRoot, cfg.hotTruncate, now);
|
|
557
|
+
const hotAudit = runLayer('hotTruncate', () => hot, hot.root, audit, { dryRun, errors: audit.errors });
|
|
558
|
+
layers.push(hotAudit);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (retentionLayerEnabled(cfg, 'toolOutput') && !coldSkip) {
|
|
562
|
+
const tool = planToolOutput(memoryRoot, cfg.toolOutput, now);
|
|
563
|
+
const toolAudit = runLayer('toolOutput', () => tool, tool.root, audit, { dryRun, errors: audit.errors });
|
|
564
|
+
layers.push(toolAudit);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (retentionLayerEnabled(cfg, 'indexArtifacts')) {
|
|
568
|
+
const index = planIndexArtifacts(memoryRoot, cfg.indexArtifacts);
|
|
569
|
+
const indexAudit = runLayer('indexArtifacts', () => index, index.root, audit, { dryRun, errors: audit.errors });
|
|
570
|
+
layers.push(indexAudit);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// 批 C(M25/M26 相邻):冷档门禁。没 approve / 清单不可验 → handoff 层整层拒删。
|
|
574
|
+
const cold = cfg.coldArchive && typeof cfg.coldArchive === 'object' ? cfg.coldArchive : null;
|
|
575
|
+
if (cold && (cold.requireApprove === true || cold.manifest !== '')) {
|
|
576
|
+
const approvalFile = cold.approvalFile === '' ? '.longlive/archive/cold-approval.json' : cold.approvalFile;
|
|
577
|
+
const approvalAbs = path.isAbsolute(approvalFile) ? approvalFile : path.resolve(memoryRoot, approvalFile);
|
|
578
|
+
if (!fs.existsSync(approvalAbs)) {
|
|
579
|
+
audit.errors.push({ layer: 'handoff', code: 'E_HG_ARCHIVE_APPROVAL_REQUIRED', reason: 'cold-archive-approval-missing' });
|
|
580
|
+
} else if (cold.manifest !== '') {
|
|
581
|
+
const manifestAbs = path.isAbsolute(cold.manifest) ? cold.manifest : path.resolve(memoryRoot, cold.manifest);
|
|
582
|
+
let manifestOk = false;
|
|
583
|
+
try {
|
|
584
|
+
const parsed = JSON.parse(fs.readFileSync(manifestAbs, 'utf8'));
|
|
585
|
+
manifestOk = Boolean(parsed && (parsed.digestSha256 || parsed.manifestSha256 || parsed.entries));
|
|
586
|
+
} catch {
|
|
587
|
+
manifestOk = false;
|
|
588
|
+
}
|
|
589
|
+
if (!manifestOk) {
|
|
590
|
+
audit.errors.push({ layer: 'handoff', code: 'E_HG_RETENTION_COLD_MISMATCH', reason: 'cold-manifest-unverifiable' });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
// 2.0.0 W3c(B7):二次 approve 门(默认关闭)。配置 approveLedger 或 requireMigrateApprovals=true 时,
|
|
595
|
+
// 要求 migrate-200 账本里 plan 阶段(数据计划)与 apply 阶段(备份 sha 绑定)两次 approve 齐备,
|
|
596
|
+
// 且 plan 指纹仍新鲜;缺任一次 → handoff 层整层拒删(不迁移、不删除)。
|
|
597
|
+
if (cold && (cold.requireMigrateApprovals === true || cold.approveLedger !== '')) {
|
|
598
|
+
let approved = { approved: false, reason: 'migrate-200-approval-missing' };
|
|
599
|
+
const isColdMoveApproved = loadIsColdMoveApproved();
|
|
600
|
+
if (typeof isColdMoveApproved !== 'function') {
|
|
601
|
+
// fail-closed:账本能力不可用(B7a 未落/旧装)→ 视为无 approve,handoff 层拒删。
|
|
602
|
+
approved = { approved: false, reason: 'migrate-200-unavailable' };
|
|
603
|
+
} else {
|
|
604
|
+
try {
|
|
605
|
+
approved = isColdMoveApproved({ memoryRoot, checkFresh: true });
|
|
606
|
+
} catch (error) {
|
|
607
|
+
approved = { approved: false, reason: error?.code ?? 'E_HG_MIGRATE_200_APPROVAL_ERROR' };
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (!approved || approved.approved !== true) {
|
|
611
|
+
audit.errors.push({
|
|
612
|
+
layer: 'handoff',
|
|
613
|
+
code: 'E_HG_MIGRATE_200_APPROVAL_REQUIRED',
|
|
614
|
+
reason: approved?.reason ?? 'migrate-200-approval-missing',
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const handoffBlocked = coldSkip || audit.errors.some((item) => item.layer === 'handoff'
|
|
619
|
+
&& (item.code === 'E_HG_ARCHIVE_APPROVAL_REQUIRED'
|
|
620
|
+
|| item.code === 'E_HG_RETENTION_COLD_MISMATCH'
|
|
621
|
+
|| item.code === 'E_HG_MIGRATE_200_APPROVAL_REQUIRED'));
|
|
622
|
+
// P7:handoff 层移出 janitor 默认射程——只有显式 layers.handoff=true 才跑
|
|
623
|
+
//(真交接卡路径永不进清单;release evidence 由 planHandoff 只标记不保护的口径不动)。
|
|
624
|
+
// lead 裁决(2026-11-30,B7b 条款 b):janitor 永不删 handoff 层卡片。显式 opt-in 也不够,
|
|
625
|
+
// 还必须 (1) 冷档已配置 (2) 冷档门禁放行(migrated + 冷副本 sha 全部匹配);未配置冷档的
|
|
626
|
+
// legacy 模式只允许其它层(hotTruncate/toolOutput/indexArtifacts 等非 handoff 文件)按旧规则删。
|
|
627
|
+
const handoffOptIn = cfg.layers !== null && typeof cfg.layers === 'object' && cfg.layers.handoff === true;
|
|
628
|
+
const handoffColdReady = coldGate.configured === true && coldGate.allowDeleting === true;
|
|
629
|
+
if (handoffOptIn && !handoffBlocked && handoffColdReady) {
|
|
630
|
+
const handoff = planHandoff(memoryRoot, cfg.handoff, now);
|
|
631
|
+
const paths = dryRun ? null : retentionPaths(memoryRoot, now);
|
|
632
|
+
if (!dryRun && handoff.plan.length > 0) {
|
|
633
|
+
// Archive the exact list BEFORE any handoff file is removed. A release
|
|
634
|
+
// evidence file must remain recoverable from the manifest even after the
|
|
635
|
+
// source file is pruned.
|
|
636
|
+
writeJson(paths.handoffArchivePath, {
|
|
637
|
+
schema: RETENTION_SCHEMA,
|
|
638
|
+
at: now.toISOString(),
|
|
639
|
+
reason: 'handoff-retention-archive-before-delete',
|
|
640
|
+
files: handoff.plan.map((item) => ({
|
|
641
|
+
rel: item.rel,
|
|
642
|
+
size: item.size,
|
|
643
|
+
mtimeMs: item.mtimeMs,
|
|
644
|
+
releaseEvidence: Boolean(item.releaseEvidence),
|
|
645
|
+
})),
|
|
646
|
+
});
|
|
647
|
+
audit.handoffArchive = paths.handoffArchivePath;
|
|
648
|
+
}
|
|
649
|
+
const handoffAudit = runLayer('handoff', () => handoff, handoff.root, audit, { dryRun, errors: audit.errors });
|
|
650
|
+
layers.push(handoffAudit);
|
|
651
|
+
} else if (handoffOptIn && !handoffBlocked && !handoffColdReady) {
|
|
652
|
+
// 未配置冷档(legacy)或冷档门禁未放行 → handoff 卡片一律不删;audit 明示 configured=false。
|
|
653
|
+
audit.handoffSkipped = {
|
|
654
|
+
layer: 'handoff',
|
|
655
|
+
reason: coldGate.configured === true ? 'cold-gate-denied' : 'cold-archive-not-configured',
|
|
656
|
+
configured: coldGate.configured,
|
|
657
|
+
allowDeleting: coldGate.allowDeleting === true,
|
|
658
|
+
code: coldGate.configured === true ? (coldGate.code ?? null) : 'E_HG_ARCHIVE_NOT_CONFIGURED',
|
|
659
|
+
event: 'retention.skip.handoff',
|
|
660
|
+
};
|
|
661
|
+
audit.warnings.push(`[retention] handoff layer skipped: ${audit.handoffSkipped.reason} (configured=${coldGate.configured})`);
|
|
518
662
|
}
|
|
519
|
-
const handoffAudit = runLayer('handoff', () => handoff, handoff.root, audit, { dryRun, errors: audit.errors });
|
|
520
|
-
layers.push(handoffAudit);
|
|
521
663
|
|
|
522
664
|
const backup = planBackup(cfg);
|
|
523
665
|
for (const name of ['sessions', 'profiles']) {
|
|
@@ -553,8 +695,10 @@ export function runRetention(options = {}) {
|
|
|
553
695
|
};
|
|
554
696
|
}
|
|
555
697
|
|
|
698
|
+
if (audit.errors.length > 0) audit.status = 'partial';
|
|
699
|
+
// B7b T3:dry-run 也要留账(P4)——写 .dryrun 审计,绝不覆盖真审计/状态。
|
|
700
|
+
const paths = retentionPaths(memoryRoot, now);
|
|
556
701
|
if (!dryRun) {
|
|
557
|
-
const paths = retentionPaths(memoryRoot, now);
|
|
558
702
|
writeJson(paths.auditPath, audit);
|
|
559
703
|
writeJson(paths.statusPath, {
|
|
560
704
|
schema: RETENTION_SCHEMA,
|
|
@@ -565,9 +709,23 @@ export function runRetention(options = {}) {
|
|
|
565
709
|
});
|
|
566
710
|
audit.auditPath = paths.auditPath;
|
|
567
711
|
audit.statusPath = paths.statusPath;
|
|
712
|
+
} else {
|
|
713
|
+
audit.dryRunPath = `${paths.auditPath}.dryrun`;
|
|
714
|
+
writeJson(audit.dryRunPath, audit);
|
|
715
|
+
}
|
|
716
|
+
// B7b/T6:每次 run(含 dry-run)都留一行 gate-log,作为"跨日补跑恰好一次"的判据。
|
|
717
|
+
try {
|
|
718
|
+
appendGateLog(memoryRoot, {
|
|
719
|
+
gate: 'retention.run',
|
|
720
|
+
decision: dryRun ? 'skip' : 'ok',
|
|
721
|
+
reason: `dryRun=${dryRun} status=${audit.status} cold=${coldGate.configured ? coldGate.phase : 'not-configured'}`,
|
|
722
|
+
evidence: [dryRun ? 'dryRun' : 'apply', `deleted=${audit.actions.length}`],
|
|
723
|
+
code: audit.errors[0]?.code ?? null,
|
|
724
|
+
});
|
|
725
|
+
} catch {
|
|
726
|
+
/* gate-log 写失败不影响删除结论;审计文件已写 */
|
|
568
727
|
}
|
|
569
728
|
|
|
570
|
-
if (audit.errors.length > 0) audit.status = 'partial';
|
|
571
729
|
return { ok: audit.errors.length === 0, enabled: true, dryRun, audit, plans: layers };
|
|
572
730
|
}
|
|
573
731
|
|