@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
package/src/memory/lifecycle.js
CHANGED
|
@@ -105,3 +105,131 @@ export function readCardLifecycle(cardPath, options = {}) {
|
|
|
105
105
|
export function lifecycleLabel(card) {
|
|
106
106
|
return isHistorical(card) ? '历史口径' : null;
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// 批 C(M20):historical 迁移(写生命周期轴 + 可选归档移动)
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
/** 把 lifecycle:historical 写进 frontmatter(只动这一行,不动正文与其它字段)。 */
|
|
114
|
+
function withHistoricalFrontmatter(text) {
|
|
115
|
+
const src = typeof text === 'string' ? text : '';
|
|
116
|
+
const block = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(\r?\n|$)/.exec(src);
|
|
117
|
+
if (!block) return `---\nlifecycle: historical\n---\n\n${src}`;
|
|
118
|
+
if (/^[ \t]*lifecycle[ \t]*:/m.test(block[1])) {
|
|
119
|
+
return src.replace(/^([ \t]*lifecycle[ \t]*:[ \t]*).+$/m, '$1historical');
|
|
120
|
+
}
|
|
121
|
+
return `---\n${block[1]}\nlifecycle: historical\n---\n${src.slice(block[0].length)}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function resolveCardFile(memoryRoot, rel) {
|
|
125
|
+
if (typeof rel !== 'string' || rel.trim() === '') return null;
|
|
126
|
+
return path.isAbsolute(rel) ? rel : path.resolve(String(memoryRoot), rel);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 标记单张卡为 historical(幂等;已是 historical 则 written:false)。
|
|
131
|
+
* 绝不改 status,绝不删正文;写失败抛错,不静默成功。
|
|
132
|
+
*/
|
|
133
|
+
export function markCardHistorical(memoryRoot, rel, { now = new Date() } = {}) {
|
|
134
|
+
const file = resolveCardFile(memoryRoot, rel);
|
|
135
|
+
if (!file) throw Object.assign(new Error('E_LIFECYCLE_PATH'), { code: 'E_LIFECYCLE_PATH' });
|
|
136
|
+
if (readLifecycleFromText(safeRead(file)) === 'historical') {
|
|
137
|
+
return { ok: true, written: false, rel, lifecycle: 'historical' };
|
|
138
|
+
}
|
|
139
|
+
const src = safeRead(file);
|
|
140
|
+
if (src === null) throw Object.assign(new Error('E_LIFECYCLE_SOURCE_MISSING'), { code: 'E_LIFECYCLE_SOURCE_MISSING' });
|
|
141
|
+
const next = withHistoricalFrontmatter(src);
|
|
142
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
143
|
+
fs.writeFileSync(tmp, next, 'utf8');
|
|
144
|
+
fs.renameSync(tmp, file);
|
|
145
|
+
return { ok: true, written: true, rel, lifecycle: 'historical', at: (now instanceof Date ? now : new Date(now)).toISOString() };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function safeRead(file) {
|
|
149
|
+
try {
|
|
150
|
+
return fs.readFileSync(file, 'utf8');
|
|
151
|
+
} catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 迁移入口(批 C):把给定卡片或「带取代标记的卡」标为 historical。
|
|
158
|
+
*
|
|
159
|
+
* - cards: 显式相对路径列表(夹具/维护链用)
|
|
160
|
+
* - autoDetect: true 时扫描 topics/ 下 frontmatter 含 superseded_by / replaced_by 的卡
|
|
161
|
+
* - archive: true 时移动到 topics/archive/<YYYY-MM>/(不删内容;INDEX 重建由 archive.mjs 负责)
|
|
162
|
+
*
|
|
163
|
+
* 默认只写 lifecycle 字段,不动文件位置——历史过滤(默认召回/注入不含 historical)
|
|
164
|
+
* 由已有的 recall / trust 路径读取该字段生效。
|
|
165
|
+
*/
|
|
166
|
+
export function migrateHistorical({
|
|
167
|
+
memoryRoot,
|
|
168
|
+
now = new Date(),
|
|
169
|
+
cards = null,
|
|
170
|
+
autoDetect = true,
|
|
171
|
+
archive = false,
|
|
172
|
+
} = {}) {
|
|
173
|
+
const root = typeof memoryRoot === 'string' && memoryRoot.trim() !== '' ? path.resolve(memoryRoot) : null;
|
|
174
|
+
if (!root) return { ok: false, reason: 'no-memory-root' };
|
|
175
|
+
const at = now instanceof Date ? now : new Date(now ?? Date.now());
|
|
176
|
+
const month = `${at.getFullYear()}-${String(at.getMonth() + 1).padStart(2, '0')}`;
|
|
177
|
+
const candidates = new Set();
|
|
178
|
+
if (Array.isArray(cards)) {
|
|
179
|
+
for (const rel of cards) if (typeof rel === 'string' && rel.trim() !== '') candidates.add(rel.replace(/\\/g, '/'));
|
|
180
|
+
}
|
|
181
|
+
if (autoDetect === true && candidates.size === 0) {
|
|
182
|
+
const topics = path.join(root, 'topics');
|
|
183
|
+
const walk = (dir) => {
|
|
184
|
+
let entries = [];
|
|
185
|
+
try {
|
|
186
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
187
|
+
} catch {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
const abs = path.join(dir, entry.name);
|
|
192
|
+
if (entry.isDirectory()) {
|
|
193
|
+
if (entry.name === 'archive') continue;
|
|
194
|
+
walk(abs);
|
|
195
|
+
} else if (entry.name.endsWith('.md')) {
|
|
196
|
+
const text = safeRead(abs);
|
|
197
|
+
if (text === null) continue;
|
|
198
|
+
if (/^[ \t]*(superseded_by|replaced_by)[ \t]*:/m.test(text)) {
|
|
199
|
+
candidates.add(path.relative(root, abs).replace(/\\/g, '/'));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
walk(topics);
|
|
205
|
+
}
|
|
206
|
+
const report = { ok: true, scanned: candidates.size, migrated: 0, moved: 0, written: [], moved_to: [], errors: [] };
|
|
207
|
+
for (const rel of candidates) {
|
|
208
|
+
try {
|
|
209
|
+
let targetRel = rel;
|
|
210
|
+
if (archive === true) {
|
|
211
|
+
const toRel = `topics/archive/${month}/${path.basename(rel)}`;
|
|
212
|
+
const fromAbs = path.resolve(root, rel);
|
|
213
|
+
const toAbs = path.resolve(root, toRel);
|
|
214
|
+
if (!fs.existsSync(fromAbs)) throw Object.assign(new Error('E_LIFECYCLE_SOURCE_MISSING'), { code: 'E_LIFECYCLE_SOURCE_MISSING' });
|
|
215
|
+
fs.mkdirSync(path.dirname(toAbs), { recursive: true });
|
|
216
|
+
if (fs.existsSync(toAbs)) throw Object.assign(new Error('E_LIFECYCLE_TARGET_EXISTS'), { code: 'E_LIFECYCLE_TARGET_EXISTS' });
|
|
217
|
+
// 先写历史字段,再移动:移动后不会留下未标 historical 的旧卡。
|
|
218
|
+
const marked = markCardHistorical(root, rel, { now: at });
|
|
219
|
+
fs.renameSync(fromAbs, toAbs);
|
|
220
|
+
targetRel = toRel;
|
|
221
|
+
report.moved += 1;
|
|
222
|
+
report.moved_to.push({ from: rel, to: toRel, written: marked.written });
|
|
223
|
+
} else {
|
|
224
|
+
const marked = markCardHistorical(root, rel, { now: at });
|
|
225
|
+
report.written.push({ rel, written: marked.written });
|
|
226
|
+
}
|
|
227
|
+
report.migrated += 1;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
report.errors.push({ rel, code: String(error?.code ?? error?.message ?? error) });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (report.errors.length > 0) report.ok = false;
|
|
233
|
+
report.at = (at instanceof Date ? at : new Date()).toISOString();
|
|
234
|
+
return report;
|
|
235
|
+
}
|