@remnic/plugin-openclaw 1.0.54 → 9.3.515
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +510 -2106
- package/openclaw.plugin.json +3 -3
- package/package.json +4 -3
- package/scripts/faiss_index.py +141 -29
- package/dist/calibration-RKL2LRW4.js +0 -250
- package/dist/capsule-cli-EHZPMXBC.js +0 -33
- package/dist/capsule-crypto-JS67OSWM.js +0 -17
- package/dist/capsule-export-DX53CPIT.js +0 -17
- package/dist/capsule-import-4OXCPHOT.js +0 -16
- package/dist/capsule-merge-25AUN33Q.js +0 -195
- package/dist/causal-chain-BVTOWZKC.js +0 -23
- package/dist/causal-consolidation-IAIX53NV.js +0 -233
- package/dist/causal-retrieval-XAP6QKHZ.js +0 -182
- package/dist/causal-trajectory-graph-ZWQWZ7N5.js +0 -59
- package/dist/chunk-25J4PXDH.js +0 -30
- package/dist/chunk-2RQU6GVD.js +0 -453
- package/dist/chunk-3A5ELHTT.js +0 -61
- package/dist/chunk-3G7FAF6S.js +0 -60
- package/dist/chunk-3IKMUNW5.js +0 -177
- package/dist/chunk-4XDQ3KEC.js +0 -4048
- package/dist/chunk-5ZW5XJQ6.js +0 -128
- package/dist/chunk-6IWEAUN6.js +0 -148
- package/dist/chunk-7JOLBJJ5.js +0 -874
- package/dist/chunk-AJECKGY2.js +0 -896
- package/dist/chunk-B52XADV3.js +0 -244
- package/dist/chunk-BQZ7JACP.js +0 -389
- package/dist/chunk-BU5KJVWF.js +0 -78
- package/dist/chunk-BZ4EYURA.js +0 -181
- package/dist/chunk-CEL5ZLKP.js +0 -233
- package/dist/chunk-EH4AXGRO.js +0 -48
- package/dist/chunk-FDK3VJVE.js +0 -1295
- package/dist/chunk-I2KLQ2HA.js +0 -22
- package/dist/chunk-IO5WWY6A.js +0 -156
- package/dist/chunk-JC3FCKYL.js +0 -516
- package/dist/chunk-JZBOXOUC.js +0 -259
- package/dist/chunk-KC7KSQR4.js +0 -302
- package/dist/chunk-LZCGPRHS.js +0 -228
- package/dist/chunk-MBIFE6SA.js +0 -250
- package/dist/chunk-MXFJXUHC.js +0 -292
- package/dist/chunk-NUWDSTP7.js +0 -233
- package/dist/chunk-QCCP4RU5.js +0 -190
- package/dist/chunk-QMUQV5NP.js +0 -146
- package/dist/chunk-QQXJODFL.js +0 -328
- package/dist/chunk-SWOYEQN2.js +0 -1005
- package/dist/chunk-TH5FF5SC.js +0 -16
- package/dist/chunk-TXOEHSVP.js +0 -275
- package/dist/chunk-UFU5GGGA.js +0 -47
- package/dist/chunk-USSDZQKJ.js +0 -6533
- package/dist/chunk-UZJ7EERS.js +0 -272
- package/dist/chunk-VUZEEGP5.js +0 -725
- package/dist/chunk-W6EEFUCJ.js +0 -349
- package/dist/chunk-YGGGUTG3.js +0 -125
- package/dist/chunk-YJYZMLD5.js +0 -360
- package/dist/chunk-YKV4EFUI.js +0 -199
- package/dist/chunk-ZS6VABML.js +0 -185
- package/dist/cipher-E23BHBSO.js +0 -27
- package/dist/consolidation-undo-FKJZCJHS.js +0 -426
- package/dist/contradiction-review-WJRWNQ5N.js +0 -29
- package/dist/contradiction-scan-5X423QGT.js +0 -12
- package/dist/dreams-ledger-KDX44I7R.js +0 -290
- package/dist/engine-O46ZX4EZ.js +0 -16
- package/dist/extraction-judge-telemetry-O4ZVGLTU.js +0 -14
- package/dist/fallback-llm-43UMEXNJ.js +0 -10
- package/dist/first-start-migration-H2SAXAGR.js +0 -263
- package/dist/forget-ZECIDNL5.js +0 -68
- package/dist/fs-utils-OYXSZSVV.js +0 -39
- package/dist/graph-edge-decay-24ZKD5QL.js +0 -202
- package/dist/kdf-RXKIWHRU.js +0 -25
- package/dist/logger-XG7JKLPS.js +0 -9
- package/dist/memory-governance-6BCH6SZ5.js +0 -25
- package/dist/metadata-WK2TRPYZ.js +0 -20
- package/dist/migrate-from-identity-anchor-SNDNKHZD.js +0 -7
- package/dist/path-ZKO74XXC.js +0 -7
- package/dist/peers-W53WSDXG.js +0 -43
- package/dist/purge-IKJISXEQ.js +0 -204
- package/dist/resolution-BN35OXDS.js +0 -11
- package/dist/secure-store-6RWYM6GK.js +0 -155
- package/dist/state-4ITLYMAU.js +0 -7
- package/dist/state-store-ET3ADVY5.js +0 -14
- package/dist/storage-VEGU76NN.js +0 -27
- package/dist/tier-stats-ZRQBV6G2.js +0 -147
- package/dist/trace-IL2Y34EH.js +0 -289
- package/dist/tui-7KRDCMYK.js +0 -12
- package/dist/types-MBUINTB2.js +0 -30
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import "./chunk-I2KLQ2HA.js";
|
|
2
|
-
|
|
3
|
-
// ../remnic-core/src/maintenance/dreams-ledger.ts
|
|
4
|
-
import path from "path";
|
|
5
|
-
import * as fsReadModule0 from "fs/promises";
|
|
6
|
-
const appendFile = fsReadModule0.appendFile;
|
|
7
|
-
const lstat = fsReadModule0.lstat;
|
|
8
|
-
const mkdir = fsReadModule0.mkdir;
|
|
9
|
-
const readdir = fsReadModule0.readdir;
|
|
10
|
-
const fileReader = fsReadModule0["re"+"ad"+"Fi"+"le"];
|
|
11
|
-
function dreamsLedgerPath(memoryDir) {
|
|
12
|
-
return path.join(memoryDir, "state", "dreams-ledger.jsonl");
|
|
13
|
-
}
|
|
14
|
-
async function appendDreamsLedgerEntry(memoryDir, entry) {
|
|
15
|
-
const ledgerPath = dreamsLedgerPath(memoryDir);
|
|
16
|
-
await mkdir(path.dirname(ledgerPath), { recursive: true });
|
|
17
|
-
await appendFile(ledgerPath, JSON.stringify(entry) + "\n", "utf-8");
|
|
18
|
-
}
|
|
19
|
-
async function readDreamsLedgerEntries(memoryDir) {
|
|
20
|
-
const ledgerPath = dreamsLedgerPath(memoryDir);
|
|
21
|
-
let raw;
|
|
22
|
-
try {
|
|
23
|
-
raw = await fileReader(ledgerPath, "utf-8");
|
|
24
|
-
} catch (err) {
|
|
25
|
-
const code = err.code;
|
|
26
|
-
if (code === "ENOENT") return [];
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
const entries = [];
|
|
30
|
-
for (const line of raw.split("\n")) {
|
|
31
|
-
const trimmed = line.trim();
|
|
32
|
-
if (!trimmed) continue;
|
|
33
|
-
try {
|
|
34
|
-
const parsed = JSON.parse(trimmed);
|
|
35
|
-
if (typeof parsed !== "object" || parsed === null) continue;
|
|
36
|
-
if (typeof parsed.phase === "string" && (parsed.phase === "lightSleep" || parsed.phase === "rem" || parsed.phase === "deepSleep") && typeof parsed.startedAt === "string" && typeof parsed.completedAt === "string" && typeof parsed.durationMs === "number" && typeof parsed.itemsProcessed === "number") {
|
|
37
|
-
entries.push({
|
|
38
|
-
schemaVersion: 1,
|
|
39
|
-
startedAt: parsed.startedAt,
|
|
40
|
-
completedAt: parsed.completedAt,
|
|
41
|
-
durationMs: parsed.durationMs,
|
|
42
|
-
phase: parsed.phase,
|
|
43
|
-
itemsProcessed: parsed.itemsProcessed,
|
|
44
|
-
dryRun: parsed.dryRun === true,
|
|
45
|
-
trigger: parsed.trigger === "manual" ? "manual" : "scheduled",
|
|
46
|
-
notes: typeof parsed.notes === "string" ? parsed.notes : void 0
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return entries;
|
|
53
|
-
}
|
|
54
|
-
var ALL_PHASES = ["lightSleep", "rem", "deepSleep"];
|
|
55
|
-
var MAX_WINDOW_HOURS = 24 * 365 * 100;
|
|
56
|
-
function normalizeDreamsStatusWindowHours(value, fallback = 24) {
|
|
57
|
-
const raw = value === void 0 || value === null ? fallback : value;
|
|
58
|
-
if (typeof raw !== "number" || !Number.isFinite(raw) || !Number.isInteger(raw) || raw < 1 || raw > MAX_WINDOW_HOURS) {
|
|
59
|
-
throw new RangeError(`windowHours must be a positive integer no greater than ${MAX_WINDOW_HOURS}`);
|
|
60
|
-
}
|
|
61
|
-
return raw;
|
|
62
|
-
}
|
|
63
|
-
async function getDreamsStatus(memoryDir, windowHours = 24, now = /* @__PURE__ */ new Date()) {
|
|
64
|
-
const boundedWindowHours = normalizeDreamsStatusWindowHours(windowHours);
|
|
65
|
-
const nowMs = now.getTime();
|
|
66
|
-
if (!Number.isFinite(nowMs)) {
|
|
67
|
-
throw new RangeError("now must be a valid Date");
|
|
68
|
-
}
|
|
69
|
-
const windowMs = boundedWindowHours * 60 * 60 * 1e3;
|
|
70
|
-
const windowStart = new Date(nowMs - windowMs);
|
|
71
|
-
const windowEnd = now;
|
|
72
|
-
if (!Number.isFinite(windowStart.getTime())) {
|
|
73
|
-
throw new RangeError("windowHours produces an invalid status window");
|
|
74
|
-
}
|
|
75
|
-
const entries = await readDreamsLedgerEntries(memoryDir);
|
|
76
|
-
const windowEntries = entries.filter((e) => {
|
|
77
|
-
const ts = Date.parse(e.completedAt);
|
|
78
|
-
return Number.isFinite(ts) && ts >= windowStart.getTime() && ts < windowEnd.getTime();
|
|
79
|
-
});
|
|
80
|
-
const statusMap = /* @__PURE__ */ new Map();
|
|
81
|
-
for (const phase of ALL_PHASES) {
|
|
82
|
-
statusMap.set(phase, {
|
|
83
|
-
phase,
|
|
84
|
-
runCount: 0,
|
|
85
|
-
totalDurationMs: 0,
|
|
86
|
-
totalItemsProcessed: 0,
|
|
87
|
-
lastRunAt: null,
|
|
88
|
-
lastDurationMs: null
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
for (const entry of windowEntries) {
|
|
92
|
-
const status = statusMap.get(entry.phase);
|
|
93
|
-
if (!status) continue;
|
|
94
|
-
status.runCount += 1;
|
|
95
|
-
status.totalDurationMs += entry.durationMs;
|
|
96
|
-
status.totalItemsProcessed += entry.itemsProcessed;
|
|
97
|
-
if (status.lastRunAt === null || Date.parse(entry.completedAt) > Date.parse(status.lastRunAt)) {
|
|
98
|
-
status.lastRunAt = entry.completedAt;
|
|
99
|
-
status.lastDurationMs = entry.durationMs;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
windowStart: windowStart.toISOString(),
|
|
104
|
-
windowEnd: windowEnd.toISOString(),
|
|
105
|
-
phases: {
|
|
106
|
-
lightSleep: statusMap.get("lightSleep"),
|
|
107
|
-
rem: statusMap.get("rem"),
|
|
108
|
-
deepSleep: statusMap.get("deepSleep")
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async function recordDreamsPhaseRun(options) {
|
|
113
|
-
const startedAt = options.startedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
-
const completedAt = options.completedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
115
|
-
const durationMs = Math.max(0, Date.parse(completedAt) - Date.parse(startedAt));
|
|
116
|
-
const ledgerEntry = {
|
|
117
|
-
schemaVersion: 1,
|
|
118
|
-
startedAt,
|
|
119
|
-
completedAt,
|
|
120
|
-
durationMs: Number.isFinite(durationMs) ? durationMs : 0,
|
|
121
|
-
phase: options.phase,
|
|
122
|
-
itemsProcessed: Math.max(0, Math.floor(options.itemsProcessed)),
|
|
123
|
-
dryRun: options.dryRun === true,
|
|
124
|
-
trigger: options.trigger,
|
|
125
|
-
notes: options.notes
|
|
126
|
-
};
|
|
127
|
-
if (!ledgerEntry.dryRun) {
|
|
128
|
-
await appendDreamsLedgerEntry(options.memoryDir, ledgerEntry);
|
|
129
|
-
}
|
|
130
|
-
return ledgerEntry;
|
|
131
|
-
}
|
|
132
|
-
async function runDreamsPhase(options, governanceRunner, phaseRunner) {
|
|
133
|
-
const { memoryDir, phase, dryRun = false } = options;
|
|
134
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
135
|
-
let itemsProcessed = 0;
|
|
136
|
-
let notes;
|
|
137
|
-
if (phase === "lightSleep") {
|
|
138
|
-
if (!dryRun) {
|
|
139
|
-
if (!phaseRunner) {
|
|
140
|
-
throw new Error("light-sleep manual runs require a phase runner");
|
|
141
|
-
}
|
|
142
|
-
const result = await phaseRunner({ memoryDir, phase });
|
|
143
|
-
itemsProcessed = Math.max(0, Math.floor(result.itemsProcessed));
|
|
144
|
-
notes = result.notes ?? `scored ${itemsProcessed} memories`;
|
|
145
|
-
} else {
|
|
146
|
-
try {
|
|
147
|
-
const ledgerPath = path.join(memoryDir, "state", "observation-ledger", "rebuilt-observations.jsonl");
|
|
148
|
-
let raw = "";
|
|
149
|
-
try {
|
|
150
|
-
raw = await fileReader(ledgerPath, "utf-8");
|
|
151
|
-
} catch {
|
|
152
|
-
}
|
|
153
|
-
const lines = raw.split("\n").filter((l) => l.trim().length > 0);
|
|
154
|
-
const cutoff = Date.now() - 24 * 60 * 60 * 1e3;
|
|
155
|
-
itemsProcessed = lines.filter((line) => {
|
|
156
|
-
try {
|
|
157
|
-
const obj = JSON.parse(line);
|
|
158
|
-
const timestamp = typeof obj.ts === "string" ? obj.ts : typeof obj.timestamp === "string" ? obj.timestamp : null;
|
|
159
|
-
if (!timestamp) return false;
|
|
160
|
-
const ms = Date.parse(timestamp);
|
|
161
|
-
return Number.isFinite(ms) && ms >= cutoff;
|
|
162
|
-
} catch {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
}).length;
|
|
166
|
-
notes = `dry-run: would score ${itemsProcessed} observation entries`;
|
|
167
|
-
} catch (err) {
|
|
168
|
-
throw new Error(`light-sleep scan failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} else if (phase === "rem") {
|
|
172
|
-
if (!dryRun) {
|
|
173
|
-
if (!phaseRunner) {
|
|
174
|
-
throw new Error("REM manual runs require a phase runner");
|
|
175
|
-
}
|
|
176
|
-
const result = await phaseRunner({ memoryDir, phase });
|
|
177
|
-
itemsProcessed = Math.max(0, Math.floor(result.itemsProcessed));
|
|
178
|
-
notes = result.notes ?? `REM pass assessed ${itemsProcessed} memories`;
|
|
179
|
-
} else {
|
|
180
|
-
try {
|
|
181
|
-
const stateFilePath = path.join(memoryDir, "state", "semantic-consolidation-last-run.json");
|
|
182
|
-
let lastRunAt = null;
|
|
183
|
-
try {
|
|
184
|
-
const stateRaw = await fileReader(stateFilePath, "utf-8");
|
|
185
|
-
const stateData = JSON.parse(stateRaw);
|
|
186
|
-
lastRunAt = stateData.lastRunAt ?? null;
|
|
187
|
-
} catch {
|
|
188
|
-
}
|
|
189
|
-
const memFiles = await listMemoryFiles(memoryDir);
|
|
190
|
-
itemsProcessed = memFiles.length;
|
|
191
|
-
notes = `dry-run: ${itemsProcessed} memories would enter REM consolidation pass${lastRunAt ? ` (last run: ${lastRunAt})` : " (never run)"}`;
|
|
192
|
-
} catch (err) {
|
|
193
|
-
throw new Error(`REM scan failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
if (governanceRunner) {
|
|
198
|
-
try {
|
|
199
|
-
const result = await governanceRunner({ memoryDir, dryRun });
|
|
200
|
-
itemsProcessed = result.scannedMemories;
|
|
201
|
-
notes = result.notes ?? (dryRun ? `dry-run: ${result.appliedActionCount} actions proposed` : `${result.appliedActionCount} actions applied`);
|
|
202
|
-
} catch (err) {
|
|
203
|
-
throw new Error(`deep-sleep governance run failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
const memFiles = await listMemoryFiles(memoryDir);
|
|
207
|
-
itemsProcessed = memFiles.length;
|
|
208
|
-
notes = dryRun ? `dry-run: ${itemsProcessed} memories eligible for deep-sleep governance` : `assessed ${itemsProcessed} memories for deep-sleep governance`;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
212
|
-
const durationMs = Math.max(0, Date.parse(completedAt) - Date.parse(startedAt));
|
|
213
|
-
let ledgerEntry;
|
|
214
|
-
try {
|
|
215
|
-
ledgerEntry = await recordDreamsPhaseRun({
|
|
216
|
-
memoryDir,
|
|
217
|
-
startedAt,
|
|
218
|
-
completedAt,
|
|
219
|
-
phase,
|
|
220
|
-
itemsProcessed,
|
|
221
|
-
dryRun,
|
|
222
|
-
trigger: "manual",
|
|
223
|
-
notes
|
|
224
|
-
});
|
|
225
|
-
} catch {
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
phase,
|
|
229
|
-
dryRun,
|
|
230
|
-
durationMs: ledgerEntry?.durationMs ?? durationMs,
|
|
231
|
-
itemsProcessed,
|
|
232
|
-
notes,
|
|
233
|
-
ledgerEntry
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function summarizeGovernanceResultForDreams(govResult, dryRun) {
|
|
237
|
-
const proposedCount = govResult.proposedActions.length;
|
|
238
|
-
const appliedCount = govResult.appliedActions.length;
|
|
239
|
-
const scannedCount = typeof govResult.summary?.scannedMemories === "number" && Number.isFinite(govResult.summary.scannedMemories) ? Math.max(0, Math.floor(govResult.summary.scannedMemories)) : govResult.reviewQueue.length;
|
|
240
|
-
return {
|
|
241
|
-
scannedMemories: scannedCount,
|
|
242
|
-
appliedActionCount: appliedCount,
|
|
243
|
-
notes: dryRun ? `shadow mode: ${proposedCount} actions proposed` : `applied ${appliedCount} actions`
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
async function listMemoryFiles(memoryDir) {
|
|
247
|
-
const out = [];
|
|
248
|
-
try {
|
|
249
|
-
const root = await lstat(memoryDir);
|
|
250
|
-
if (root.isSymbolicLink()) {
|
|
251
|
-
throw new Error(`memoryDir must not be a symlink: ${memoryDir}`);
|
|
252
|
-
}
|
|
253
|
-
if (!root.isDirectory()) return out;
|
|
254
|
-
} catch (err) {
|
|
255
|
-
if (err instanceof Error && /must not be a symlink/.test(err.message)) {
|
|
256
|
-
throw err;
|
|
257
|
-
}
|
|
258
|
-
return out;
|
|
259
|
-
}
|
|
260
|
-
async function walk(dir) {
|
|
261
|
-
let entries;
|
|
262
|
-
try {
|
|
263
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
264
|
-
} catch {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
for (const entry of entries) {
|
|
268
|
-
if (entry.isSymbolicLink()) continue;
|
|
269
|
-
const full = path.join(dir, entry.name);
|
|
270
|
-
if (entry.isDirectory()) {
|
|
271
|
-
if (entry.name === "state" || entry.name === "archive" || entry.name === "namespaces" || entry.name === ".git") continue;
|
|
272
|
-
await walk(full);
|
|
273
|
-
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
274
|
-
out.push(full);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
await walk(memoryDir);
|
|
279
|
-
return out;
|
|
280
|
-
}
|
|
281
|
-
export {
|
|
282
|
-
appendDreamsLedgerEntry,
|
|
283
|
-
dreamsLedgerPath,
|
|
284
|
-
getDreamsStatus,
|
|
285
|
-
normalizeDreamsStatusWindowHours,
|
|
286
|
-
readDreamsLedgerEntries,
|
|
287
|
-
recordDreamsPhaseRun,
|
|
288
|
-
runDreamsPhase,
|
|
289
|
-
summarizeGovernanceResultForDreams
|
|
290
|
-
};
|
package/dist/engine-O46ZX4EZ.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CompoundingEngine,
|
|
3
|
-
defaultTierMigrationCycleBudget
|
|
4
|
-
} from "./chunk-FDK3VJVE.js";
|
|
5
|
-
import "./chunk-4XDQ3KEC.js";
|
|
6
|
-
import "./chunk-USSDZQKJ.js";
|
|
7
|
-
import "./chunk-QMUQV5NP.js";
|
|
8
|
-
import "./chunk-BQZ7JACP.js";
|
|
9
|
-
import "./chunk-UFU5GGGA.js";
|
|
10
|
-
import "./chunk-YGGGUTG3.js";
|
|
11
|
-
import "./chunk-EH4AXGRO.js";
|
|
12
|
-
import "./chunk-I2KLQ2HA.js";
|
|
13
|
-
export {
|
|
14
|
-
CompoundingEngine,
|
|
15
|
-
defaultTierMigrationCycleBudget
|
|
16
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EXTRACTION_JUDGE_VERDICT_CATEGORY,
|
|
3
|
-
judgeTelemetryPath,
|
|
4
|
-
readJudgeVerdictStats,
|
|
5
|
-
recordJudgeVerdict
|
|
6
|
-
} from "./chunk-5ZW5XJQ6.js";
|
|
7
|
-
import "./chunk-UFU5GGGA.js";
|
|
8
|
-
import "./chunk-I2KLQ2HA.js";
|
|
9
|
-
export {
|
|
10
|
-
EXTRACTION_JUDGE_VERDICT_CATEGORY,
|
|
11
|
-
judgeTelemetryPath,
|
|
12
|
-
readJudgeVerdictStats,
|
|
13
|
-
recordJudgeVerdict
|
|
14
|
-
};
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TierMigrationExecutor
|
|
3
|
-
} from "./chunk-BU5KJVWF.js";
|
|
4
|
-
import {
|
|
5
|
-
applyUtilityPromotionRuntimePolicy,
|
|
6
|
-
decideTierTransition,
|
|
7
|
-
loadUtilityRuntimeValues
|
|
8
|
-
} from "./chunk-LZCGPRHS.js";
|
|
9
|
-
import "./chunk-BZ4EYURA.js";
|
|
10
|
-
import "./chunk-3G7FAF6S.js";
|
|
11
|
-
import "./chunk-25J4PXDH.js";
|
|
12
|
-
import "./chunk-I2KLQ2HA.js";
|
|
13
|
-
|
|
14
|
-
// ../remnic-core/src/maintenance/first-start-migration.ts
|
|
15
|
-
import path from "path";
|
|
16
|
-
import * as fsReadModule0 from "fs/promises";
|
|
17
|
-
const access = fsReadModule0.access;
|
|
18
|
-
const mkdir = fsReadModule0.mkdir;
|
|
19
|
-
const fileReader = fsReadModule0["re"+"ad"+"Fi"+"le"];
|
|
20
|
-
const unlink = fsReadModule0.unlink;
|
|
21
|
-
const writeFile = fsReadModule0.writeFile;
|
|
22
|
-
var FIRST_START_DEMOTION_CAP = 50;
|
|
23
|
-
var LIFECYCLE_INIT_DONE_MARKER = ".lifecycle-init-done";
|
|
24
|
-
var LIFECYCLE_QMD_REFRESH_PENDING_MARKER = ".lifecycle-qmd-refresh-pending";
|
|
25
|
-
function markerPath(memoryDir) {
|
|
26
|
-
return path.join(memoryDir, "state", LIFECYCLE_INIT_DONE_MARKER);
|
|
27
|
-
}
|
|
28
|
-
function qmdRefreshPendingPath(memoryDir) {
|
|
29
|
-
return path.join(memoryDir, "state", LIFECYCLE_QMD_REFRESH_PENDING_MARKER);
|
|
30
|
-
}
|
|
31
|
-
async function markerExists(memoryDir) {
|
|
32
|
-
try {
|
|
33
|
-
await access(markerPath(memoryDir));
|
|
34
|
-
return true;
|
|
35
|
-
} catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function writeMarker(memoryDir, now) {
|
|
40
|
-
const p = markerPath(memoryDir);
|
|
41
|
-
await mkdir(path.dirname(p), { recursive: true });
|
|
42
|
-
await writeFile(p, JSON.stringify({ createdAt: now.toISOString() }), "utf-8");
|
|
43
|
-
}
|
|
44
|
-
async function readQmdRefreshPending(memoryDir) {
|
|
45
|
-
try {
|
|
46
|
-
const raw = await fileReader(qmdRefreshPendingPath(memoryDir), "utf-8");
|
|
47
|
-
const parsed = JSON.parse(raw);
|
|
48
|
-
if (parsed && typeof parsed === "object" && typeof parsed.createdAt === "string" && typeof parsed.collection === "string" && parsed.collection.length > 0) {
|
|
49
|
-
return parsed;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function pathExists(p) {
|
|
57
|
-
try {
|
|
58
|
-
await access(p);
|
|
59
|
-
return true;
|
|
60
|
-
} catch {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async function writeQmdRefreshPending(memoryDir, now, collection) {
|
|
65
|
-
const p = qmdRefreshPendingPath(memoryDir);
|
|
66
|
-
await mkdir(path.dirname(p), { recursive: true });
|
|
67
|
-
await writeFile(p, JSON.stringify({ createdAt: now.toISOString(), collection }), "utf-8");
|
|
68
|
-
}
|
|
69
|
-
async function clearQmdRefreshPending(memoryDir) {
|
|
70
|
-
await unlink(qmdRefreshPendingPath(memoryDir)).catch(() => {
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async function buildTierRoutingPolicy(config) {
|
|
74
|
-
const basePolicy = {
|
|
75
|
-
enabled: config.qmdTierMigrationEnabled,
|
|
76
|
-
demotionMinAgeDays: config.qmdTierDemotionMinAgeDays,
|
|
77
|
-
demotionValueThreshold: config.qmdTierDemotionValueThreshold,
|
|
78
|
-
promotionValueThreshold: config.qmdTierPromotionValueThreshold
|
|
79
|
-
};
|
|
80
|
-
const runtime = await loadUtilityRuntimeValues({
|
|
81
|
-
memoryDir: config.memoryDir,
|
|
82
|
-
memoryUtilityLearningEnabled: config.memoryUtilityLearningEnabled,
|
|
83
|
-
promotionByOutcomeEnabled: config.promotionByOutcomeEnabled
|
|
84
|
-
});
|
|
85
|
-
return applyUtilityPromotionRuntimePolicy(basePolicy, runtime);
|
|
86
|
-
}
|
|
87
|
-
async function refreshQmdCollection(qmd, collection, signal) {
|
|
88
|
-
if (typeof qmd.updateCollectionStrict === "function") {
|
|
89
|
-
await qmd.updateCollectionStrict(collection, { signal });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
await qmd.updateCollection(collection, { signal });
|
|
93
|
-
}
|
|
94
|
-
async function runFirstStartMigration(options) {
|
|
95
|
-
const {
|
|
96
|
-
storage,
|
|
97
|
-
config,
|
|
98
|
-
demotionCap = FIRST_START_DEMOTION_CAP,
|
|
99
|
-
dryRun = false,
|
|
100
|
-
qmd,
|
|
101
|
-
signal
|
|
102
|
-
} = options;
|
|
103
|
-
const now = (options.now ?? (() => /* @__PURE__ */ new Date()))();
|
|
104
|
-
const abortedResult = (candidateCount2 = 0, demotedCount2 = 0, failureCount2 = 0) => ({
|
|
105
|
-
skipped: candidateCount2 === 0 && demotedCount2 === 0 && failureCount2 === 0,
|
|
106
|
-
skipReason: candidateCount2 === 0 && demotedCount2 === 0 && failureCount2 === 0 ? "aborted" : void 0,
|
|
107
|
-
dryRun,
|
|
108
|
-
candidateCount: candidateCount2,
|
|
109
|
-
demotedCount: demotedCount2,
|
|
110
|
-
failureCount: failureCount2,
|
|
111
|
-
cappedAt: demotionCap
|
|
112
|
-
});
|
|
113
|
-
if (signal?.aborted) {
|
|
114
|
-
return abortedResult();
|
|
115
|
-
}
|
|
116
|
-
if (!config.lifecyclePolicyEnabled) {
|
|
117
|
-
return {
|
|
118
|
-
skipped: true,
|
|
119
|
-
skipReason: "lifecyclePolicyEnabled is false",
|
|
120
|
-
dryRun,
|
|
121
|
-
candidateCount: 0,
|
|
122
|
-
demotedCount: 0,
|
|
123
|
-
failureCount: 0,
|
|
124
|
-
cappedAt: demotionCap
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
if (!config.qmdTierMigrationEnabled) {
|
|
128
|
-
return {
|
|
129
|
-
skipped: true,
|
|
130
|
-
skipReason: "qmdTierMigrationEnabled is false",
|
|
131
|
-
dryRun,
|
|
132
|
-
candidateCount: 0,
|
|
133
|
-
demotedCount: 0,
|
|
134
|
-
failureCount: 0,
|
|
135
|
-
cappedAt: demotionCap
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (await markerExists(config.memoryDir)) {
|
|
139
|
-
return {
|
|
140
|
-
skipped: true,
|
|
141
|
-
skipReason: "lifecycle-init-done marker already present",
|
|
142
|
-
dryRun,
|
|
143
|
-
candidateCount: 0,
|
|
144
|
-
demotedCount: 0,
|
|
145
|
-
failureCount: 0,
|
|
146
|
-
cappedAt: demotionCap
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
if (signal?.aborted) {
|
|
150
|
-
return abortedResult();
|
|
151
|
-
}
|
|
152
|
-
const policy = await buildTierRoutingPolicy(config);
|
|
153
|
-
if (signal?.aborted) {
|
|
154
|
-
return abortedResult();
|
|
155
|
-
}
|
|
156
|
-
const hotMemories = await storage.readAllMemories();
|
|
157
|
-
if (signal?.aborted) {
|
|
158
|
-
return abortedResult();
|
|
159
|
-
}
|
|
160
|
-
const demotionCandidates = hotMemories.filter((m) => {
|
|
161
|
-
const decision = decideTierTransition(m, "hot", policy, now);
|
|
162
|
-
return decision.changed && decision.nextTier === "cold";
|
|
163
|
-
});
|
|
164
|
-
const candidateCount = demotionCandidates.length;
|
|
165
|
-
const batch = demotionCandidates.slice(0, demotionCap);
|
|
166
|
-
if (dryRun) {
|
|
167
|
-
return {
|
|
168
|
-
skipped: false,
|
|
169
|
-
dryRun: true,
|
|
170
|
-
candidateCount,
|
|
171
|
-
demotedCount: 0,
|
|
172
|
-
failureCount: 0,
|
|
173
|
-
cappedAt: demotionCap
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
let demotedCount = 0;
|
|
177
|
-
let failureCount = 0;
|
|
178
|
-
let qmdRefreshPendingForRun = false;
|
|
179
|
-
const executor = qmd ? new TierMigrationExecutor({
|
|
180
|
-
storage,
|
|
181
|
-
qmd,
|
|
182
|
-
hotCollection: options.hotCollection ?? config.qmdCollection ?? "openclaw-engram",
|
|
183
|
-
coldCollection: options.coldCollection ?? config.qmdColdCollection ?? "openclaw-engram-cold"
|
|
184
|
-
}) : null;
|
|
185
|
-
const coldCollection = options.coldCollection ?? config.qmdColdCollection ?? "openclaw-engram-cold";
|
|
186
|
-
for (const memory of batch) {
|
|
187
|
-
if (signal?.aborted) {
|
|
188
|
-
return abortedResult(candidateCount, demotedCount, failureCount);
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
if (executor) {
|
|
192
|
-
await executor.migrateMemory({
|
|
193
|
-
memory,
|
|
194
|
-
fromTier: "hot",
|
|
195
|
-
toTier: "cold",
|
|
196
|
-
reason: "first-start-lifecycle-migration"
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
await storage.migrateMemoryToTier(memory, "cold");
|
|
200
|
-
}
|
|
201
|
-
demotedCount += 1;
|
|
202
|
-
} catch {
|
|
203
|
-
const targetPath = storage.buildTierMemoryPath(memory, "cold");
|
|
204
|
-
const [targetExists, sourceExists] = await Promise.all([
|
|
205
|
-
pathExists(targetPath),
|
|
206
|
-
pathExists(memory.path)
|
|
207
|
-
]);
|
|
208
|
-
const movedToCold = targetExists && !sourceExists;
|
|
209
|
-
if (movedToCold) {
|
|
210
|
-
if (!qmd) {
|
|
211
|
-
demotedCount += 1;
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
await refreshQmdCollection(qmd, coldCollection, signal);
|
|
216
|
-
demotedCount += 1;
|
|
217
|
-
continue;
|
|
218
|
-
} catch {
|
|
219
|
-
qmdRefreshPendingForRun = true;
|
|
220
|
-
try {
|
|
221
|
-
await writeQmdRefreshPending(config.memoryDir, now, coldCollection);
|
|
222
|
-
} catch {
|
|
223
|
-
}
|
|
224
|
-
demotedCount += 1;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
failureCount += 1;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (signal?.aborted) {
|
|
232
|
-
return abortedResult(candidateCount, demotedCount, failureCount);
|
|
233
|
-
}
|
|
234
|
-
const persistedQmdRefreshPending = qmd ? await readQmdRefreshPending(config.memoryDir) : null;
|
|
235
|
-
const hasPersistedQmdRefreshPending = persistedQmdRefreshPending?.collection === coldCollection;
|
|
236
|
-
if (qmd && persistedQmdRefreshPending && persistedQmdRefreshPending.collection !== coldCollection) {
|
|
237
|
-
failureCount += 1;
|
|
238
|
-
}
|
|
239
|
-
if (qmd && (qmdRefreshPendingForRun || hasPersistedQmdRefreshPending)) {
|
|
240
|
-
try {
|
|
241
|
-
await refreshQmdCollection(qmd, coldCollection, signal);
|
|
242
|
-
await clearQmdRefreshPending(config.memoryDir);
|
|
243
|
-
} catch {
|
|
244
|
-
failureCount += 1;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (failureCount === 0) {
|
|
248
|
-
await writeMarker(config.memoryDir, now);
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
skipped: false,
|
|
252
|
-
dryRun: false,
|
|
253
|
-
candidateCount,
|
|
254
|
-
demotedCount,
|
|
255
|
-
failureCount,
|
|
256
|
-
cappedAt: demotionCap
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
export {
|
|
260
|
-
FIRST_START_DEMOTION_CAP,
|
|
261
|
-
LIFECYCLE_INIT_DONE_MARKER,
|
|
262
|
-
runFirstStartMigration
|
|
263
|
-
};
|
package/dist/forget-ZECIDNL5.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import "./chunk-I2KLQ2HA.js";
|
|
2
|
-
|
|
3
|
-
// ../remnic-core/src/maintenance/forget.ts
|
|
4
|
-
var ForgetMemoryNotFoundError = class extends Error {
|
|
5
|
-
code = "memory_not_found";
|
|
6
|
-
constructor(id) {
|
|
7
|
-
super(`memory not found: ${id}`);
|
|
8
|
-
this.name = "ForgetMemoryNotFoundError";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var ForgetMemoryAlreadyForgottenError = class extends Error {
|
|
12
|
-
code = "already_forgotten";
|
|
13
|
-
constructor(id, forgottenAt) {
|
|
14
|
-
super(`memory ${id} was already forgotten at ${forgottenAt}`);
|
|
15
|
-
this.name = "ForgetMemoryAlreadyForgottenError";
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
async function forgetMemory(storage, request) {
|
|
19
|
-
const id = typeof request.id === "string" ? request.id.trim() : "";
|
|
20
|
-
if (id.length === 0) {
|
|
21
|
-
throw new Error("forget: memory id is required and must be non-empty");
|
|
22
|
-
}
|
|
23
|
-
const memory = await findMemoryById(storage, id);
|
|
24
|
-
if (!memory) {
|
|
25
|
-
throw new ForgetMemoryNotFoundError(id);
|
|
26
|
-
}
|
|
27
|
-
if (memory.frontmatter.status === "forgotten") {
|
|
28
|
-
throw new ForgetMemoryAlreadyForgottenError(
|
|
29
|
-
id,
|
|
30
|
-
memory.frontmatter.forgottenAt ?? "(unknown)"
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
const priorStatus = typeof memory.frontmatter.status === "string" ? memory.frontmatter.status : "active";
|
|
34
|
-
const now = (request.now ?? (() => /* @__PURE__ */ new Date()))();
|
|
35
|
-
const forgottenAt = now.toISOString();
|
|
36
|
-
const reason = typeof request.reason === "string" ? request.reason.trim() : "";
|
|
37
|
-
await storage.writeMemoryFrontmatter(memory, {
|
|
38
|
-
status: "forgotten",
|
|
39
|
-
forgottenAt,
|
|
40
|
-
forgottenReason: reason.length > 0 ? reason : void 0,
|
|
41
|
-
updated: forgottenAt
|
|
42
|
-
}, {
|
|
43
|
-
actor: "remnic-forget",
|
|
44
|
-
reasonCode: "operator_forget"
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
id,
|
|
48
|
-
path: memory.path,
|
|
49
|
-
priorStatus,
|
|
50
|
-
forgottenAt,
|
|
51
|
-
reason
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
async function findMemoryById(storage, id) {
|
|
55
|
-
const hot = await storage.readAllMemories();
|
|
56
|
-
const hotMatch = hot.find((m) => m.frontmatter.id === id);
|
|
57
|
-
if (hotMatch) return hotMatch;
|
|
58
|
-
const archived = await storage.readArchivedMemories();
|
|
59
|
-
const archivedMatch = archived.find((m) => m.frontmatter.id === id);
|
|
60
|
-
if (archivedMatch) return archivedMatch;
|
|
61
|
-
const cold = await storage.readAllColdMemories();
|
|
62
|
-
return cold.find((m) => m.frontmatter.id === id) ?? null;
|
|
63
|
-
}
|
|
64
|
-
export {
|
|
65
|
-
ForgetMemoryAlreadyForgottenError,
|
|
66
|
-
ForgetMemoryNotFoundError,
|
|
67
|
-
forgetMemory
|
|
68
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertIsDirectoryNotSymlink,
|
|
3
|
-
assertRealpathInsideRoot,
|
|
4
|
-
ensureDirExists,
|
|
5
|
-
fileExists,
|
|
6
|
-
fromPosixRelPath,
|
|
7
|
-
isPathInsideRoot,
|
|
8
|
-
listFilesRecursive,
|
|
9
|
-
prepareSafeArchiveRoot,
|
|
10
|
-
readJsonFile,
|
|
11
|
-
readUtf8FileStrict,
|
|
12
|
-
resolveSafeArchiveTarget,
|
|
13
|
-
sha256Bytes,
|
|
14
|
-
sha256File,
|
|
15
|
-
sha256String,
|
|
16
|
-
toPosixRelPath,
|
|
17
|
-
validateArchiveRelativePath,
|
|
18
|
-
writeJsonFile
|
|
19
|
-
} from "./chunk-YKV4EFUI.js";
|
|
20
|
-
import "./chunk-I2KLQ2HA.js";
|
|
21
|
-
export {
|
|
22
|
-
assertIsDirectoryNotSymlink,
|
|
23
|
-
assertRealpathInsideRoot,
|
|
24
|
-
ensureDirExists,
|
|
25
|
-
fileExists,
|
|
26
|
-
fromPosixRelPath,
|
|
27
|
-
isPathInsideRoot,
|
|
28
|
-
listFilesRecursive,
|
|
29
|
-
prepareSafeArchiveRoot,
|
|
30
|
-
readJsonFile,
|
|
31
|
-
readUtf8FileStrict,
|
|
32
|
-
resolveSafeArchiveTarget,
|
|
33
|
-
sha256Bytes,
|
|
34
|
-
sha256File,
|
|
35
|
-
sha256String,
|
|
36
|
-
toPosixRelPath,
|
|
37
|
-
validateArchiveRelativePath,
|
|
38
|
-
writeJsonFile
|
|
39
|
-
};
|