@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
package/dist/chunk-UZJ7EERS.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readPair,
|
|
3
|
-
resolvePair
|
|
4
|
-
} from "./chunk-YJYZMLD5.js";
|
|
5
|
-
import {
|
|
6
|
-
log
|
|
7
|
-
} from "./chunk-UFU5GGGA.js";
|
|
8
|
-
|
|
9
|
-
// ../remnic-core/src/contradiction/resolution.ts
|
|
10
|
-
var VALID_VERBS = ["keep-a", "keep-b", "merge", "both-valid", "needs-more-context"];
|
|
11
|
-
function isValidResolutionVerb(value) {
|
|
12
|
-
return VALID_VERBS.includes(value);
|
|
13
|
-
}
|
|
14
|
-
async function executeResolution(memoryDir, storage, pairId, verb, options = {}) {
|
|
15
|
-
if (typeof verb !== "string" || !isValidResolutionVerb(verb)) {
|
|
16
|
-
throw new Error(`Invalid contradiction resolution verb: ${String(verb)}`);
|
|
17
|
-
}
|
|
18
|
-
const pair = readPair(memoryDir, pairId);
|
|
19
|
-
if (!pair) {
|
|
20
|
-
return { pairId, verb, affectedIds: [], message: `Pair ${pairId} not found` };
|
|
21
|
-
}
|
|
22
|
-
if (pair.namespace && !options.storageForNamespace) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"contradiction resolution requires storageForNamespace for namespaced pairs so callers resolve the correct namespace storage"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
const resolutionStorage = options.storageForNamespace ? await options.storageForNamespace(pair.namespace) : storage;
|
|
28
|
-
if (pair.resolution && pair.resolution !== "needs-more-context") {
|
|
29
|
-
return { pairId, verb, affectedIds: [], message: `Pair already resolved with verb "${pair.resolution}"` };
|
|
30
|
-
}
|
|
31
|
-
const [idA, idB] = pair.memoryIds;
|
|
32
|
-
const affectedIds = [];
|
|
33
|
-
let message = "";
|
|
34
|
-
let supersedeFailed = false;
|
|
35
|
-
switch (verb) {
|
|
36
|
-
case "keep-a": {
|
|
37
|
-
const keepTarget = await validateKeepTarget(resolutionStorage, pairId, idA);
|
|
38
|
-
if (!keepTarget.ok) {
|
|
39
|
-
supersedeFailed = true;
|
|
40
|
-
message = keepTarget.message;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
const sourceB = await loadSourceSnapshot(resolutionStorage, idB);
|
|
44
|
-
const ok = sourceB ? await supersedeSafe(resolutionStorage, idB, idA, "contradiction-resolution:keep-a") : false;
|
|
45
|
-
if (ok) {
|
|
46
|
-
affectedIds.push(idB);
|
|
47
|
-
message = `Kept ${idA}, superseded ${idB}`;
|
|
48
|
-
} else {
|
|
49
|
-
supersedeFailed = true;
|
|
50
|
-
const rolledBack = sourceB ? await restoreMemorySnapshot(resolutionStorage, sourceB, "contradiction-resolution:keep-a-rollback") : false;
|
|
51
|
-
message = rolledBack ? `Supersede failed for ${idB}; restored ${idB} and did not resolve` : `Supersede failed for ${idB}; rollback incomplete for ${idB} and pair is not resolved`;
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "keep-b": {
|
|
56
|
-
const keepTarget = await validateKeepTarget(resolutionStorage, pairId, idB);
|
|
57
|
-
if (!keepTarget.ok) {
|
|
58
|
-
supersedeFailed = true;
|
|
59
|
-
message = keepTarget.message;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
const sourceA = await loadSourceSnapshot(resolutionStorage, idA);
|
|
63
|
-
const ok = sourceA ? await supersedeSafe(resolutionStorage, idA, idB, "contradiction-resolution:keep-b") : false;
|
|
64
|
-
if (ok) {
|
|
65
|
-
affectedIds.push(idA);
|
|
66
|
-
message = `Kept ${idB}, superseded ${idA}`;
|
|
67
|
-
} else {
|
|
68
|
-
supersedeFailed = true;
|
|
69
|
-
const rolledBack = sourceA ? await restoreMemorySnapshot(resolutionStorage, sourceA, "contradiction-resolution:keep-b-rollback") : false;
|
|
70
|
-
message = rolledBack ? `Supersede failed for ${idA}; restored ${idA} and did not resolve` : `Supersede failed for ${idA}; rollback incomplete for ${idA} and pair is not resolved`;
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case "merge": {
|
|
75
|
-
const replacement = await prepareMergeReplacement(resolutionStorage, pairId, idA, idB, options);
|
|
76
|
-
if (!replacement.ok) {
|
|
77
|
-
supersedeFailed = true;
|
|
78
|
-
message = replacement.message;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
const okA = await supersedeSafe(resolutionStorage, idA, replacement.mergedId, "contradiction-resolution:merge");
|
|
82
|
-
if (!okA) {
|
|
83
|
-
supersedeFailed = true;
|
|
84
|
-
const rolledBackA = await restoreMemorySnapshot(resolutionStorage, replacement.sourceA);
|
|
85
|
-
message = rolledBackA ? `Merge failed for ${idA}; restored ${idA} and did not resolve` : `Merge failed for ${idA}; rollback incomplete for ${idA} and pair is not resolved`;
|
|
86
|
-
if (rolledBackA) {
|
|
87
|
-
await cleanupCreatedReplacement(resolutionStorage, replacement);
|
|
88
|
-
}
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
const okB = await supersedeSafe(resolutionStorage, idB, replacement.mergedId, "contradiction-resolution:merge");
|
|
92
|
-
if (!okB) {
|
|
93
|
-
supersedeFailed = true;
|
|
94
|
-
const rolledBackA = await restoreMemorySnapshot(resolutionStorage, replacement.sourceA);
|
|
95
|
-
const rolledBackB = await restoreMemorySnapshot(resolutionStorage, replacement.sourceB);
|
|
96
|
-
message = rolledBackA && rolledBackB ? `Merge failed for ${idB}; restored ${idA} and ${idB} and did not resolve` : `Merge failed for ${idB}; rollback incomplete for ${[
|
|
97
|
-
rolledBackA ? void 0 : idA,
|
|
98
|
-
rolledBackB ? void 0 : idB
|
|
99
|
-
].filter(Boolean).join(", ")} and pair is not resolved`;
|
|
100
|
-
if (rolledBackA && rolledBackB) {
|
|
101
|
-
await cleanupCreatedReplacement(resolutionStorage, replacement);
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
affectedIds.push(idA, idB);
|
|
106
|
-
message = `Both memories superseded by merged ${replacement.mergedId}`;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case "both-valid": {
|
|
110
|
-
message = "Pair marked as both-valid; cooldown applied";
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
case "needs-more-context": {
|
|
114
|
-
message = "Deferred; no action taken, short cooldown applied";
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (!supersedeFailed) {
|
|
119
|
-
resolvePair(memoryDir, pairId, verb);
|
|
120
|
-
}
|
|
121
|
-
log.info("[contradiction-resolution] pair=%s verb=%s affected=%d", pairId, verb, affectedIds.length);
|
|
122
|
-
return { pairId, verb, affectedIds, message };
|
|
123
|
-
}
|
|
124
|
-
async function prepareMergeReplacement(storage, pairId, idA, idB, options) {
|
|
125
|
-
const sourceA = await storage.getMemoryById(idA);
|
|
126
|
-
const sourceB = await storage.getMemoryById(idB);
|
|
127
|
-
if (!sourceA || !sourceB) {
|
|
128
|
-
return { ok: false, message: `Merge requires both source memories to exist; not resolving ${pairId}` };
|
|
129
|
-
}
|
|
130
|
-
const requestedMergedId = options.mergedMemoryId?.trim();
|
|
131
|
-
if (requestedMergedId) {
|
|
132
|
-
if (requestedMergedId === idA || requestedMergedId === idB) {
|
|
133
|
-
return { ok: false, message: "Merge replacement must be distinct from both source memories; not resolving" };
|
|
134
|
-
}
|
|
135
|
-
const replacement2 = await storage.getMemoryById(requestedMergedId);
|
|
136
|
-
if (!replacement2) {
|
|
137
|
-
return { ok: false, message: `Merged memory ${requestedMergedId} not found; not resolving` };
|
|
138
|
-
}
|
|
139
|
-
const replacementStatus = replacement2.frontmatter.status ?? "active";
|
|
140
|
-
if (replacementStatus !== "active") {
|
|
141
|
-
return {
|
|
142
|
-
ok: false,
|
|
143
|
-
message: `Merged memory ${requestedMergedId} is ${replacementStatus}; not resolving`
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return { ok: true, mergedId: requestedMergedId, sourceA, sourceB, created: false };
|
|
147
|
-
}
|
|
148
|
-
const mergedContent = options.mergedContent;
|
|
149
|
-
if (typeof mergedContent !== "string" || mergedContent.trim().length === 0) {
|
|
150
|
-
return {
|
|
151
|
-
ok: false,
|
|
152
|
-
message: "Merge requires mergedMemoryId or mergedContent; no memories changed"
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const category = options.mergedCategory ?? mergedMemoryCategory(sourceA, sourceB);
|
|
156
|
-
let mergedId;
|
|
157
|
-
try {
|
|
158
|
-
mergedId = await storage.writeMemory(category, mergedContent, {
|
|
159
|
-
actor: "contradiction-resolution",
|
|
160
|
-
confidence: Math.min(sourceA.frontmatter.confidence ?? 0.8, sourceB.frontmatter.confidence ?? 0.8),
|
|
161
|
-
tags: ["contradiction-resolution", "merge"],
|
|
162
|
-
source: "contradiction-resolution",
|
|
163
|
-
lineage: [idA, idB],
|
|
164
|
-
derivedFrom: [idA, idB],
|
|
165
|
-
derivedVia: "merge"
|
|
166
|
-
});
|
|
167
|
-
} catch (err) {
|
|
168
|
-
log.warn(
|
|
169
|
-
"[contradiction-resolution] merged memory creation failed for %s: %s",
|
|
170
|
-
pairId,
|
|
171
|
-
err instanceof Error ? err.message : err
|
|
172
|
-
);
|
|
173
|
-
return { ok: false, message: `Merged memory could not be created; not resolving ${pairId}` };
|
|
174
|
-
}
|
|
175
|
-
const replacement = await storage.getMemoryById(mergedId);
|
|
176
|
-
if (!replacement) {
|
|
177
|
-
await cleanupMemoryId(storage, mergedId);
|
|
178
|
-
return { ok: false, message: `Merged memory ${mergedId} could not be verified; not resolving` };
|
|
179
|
-
}
|
|
180
|
-
return { ok: true, mergedId, sourceA, sourceB, created: true };
|
|
181
|
-
}
|
|
182
|
-
function mergedMemoryCategory(sourceA, sourceB) {
|
|
183
|
-
return sourceA.frontmatter.category === sourceB.frontmatter.category ? sourceA.frontmatter.category : "fact";
|
|
184
|
-
}
|
|
185
|
-
async function validateKeepTarget(storage, pairId, keepId) {
|
|
186
|
-
const target = await loadSourceSnapshot(storage, keepId);
|
|
187
|
-
if (!target) {
|
|
188
|
-
return { ok: false, message: `Kept memory ${keepId} not found; not resolving ${pairId}` };
|
|
189
|
-
}
|
|
190
|
-
const status = target.frontmatter.status ?? "active";
|
|
191
|
-
if (status !== "active") {
|
|
192
|
-
return { ok: false, message: `Kept memory ${keepId} is ${status}; not resolving ${pairId}` };
|
|
193
|
-
}
|
|
194
|
-
return { ok: true };
|
|
195
|
-
}
|
|
196
|
-
async function loadSourceSnapshot(storage, memoryId) {
|
|
197
|
-
try {
|
|
198
|
-
return await storage.getMemoryById(memoryId);
|
|
199
|
-
} catch (err) {
|
|
200
|
-
log.warn(
|
|
201
|
-
"[contradiction-resolution] source snapshot failed for %s: %s",
|
|
202
|
-
memoryId,
|
|
203
|
-
err instanceof Error ? err.message : err
|
|
204
|
-
);
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async function restoreMemorySnapshot(storage, memory, reasonCode = "contradiction-resolution:merge-rollback") {
|
|
209
|
-
try {
|
|
210
|
-
const current = await storage.getMemoryById(memory.frontmatter.id);
|
|
211
|
-
if (!current) return false;
|
|
212
|
-
const restoredFrontmatter = {
|
|
213
|
-
...memory.frontmatter,
|
|
214
|
-
status: memory.frontmatter.status,
|
|
215
|
-
supersededBy: memory.frontmatter.supersededBy,
|
|
216
|
-
supersededAt: memory.frontmatter.supersededAt
|
|
217
|
-
};
|
|
218
|
-
return await storage.writeMemoryFrontmatter(current, restoredFrontmatter, {
|
|
219
|
-
actor: "contradiction-resolution",
|
|
220
|
-
reasonCode
|
|
221
|
-
});
|
|
222
|
-
} catch (err) {
|
|
223
|
-
log.warn(
|
|
224
|
-
"[contradiction-resolution] rollback failed for %s: %s",
|
|
225
|
-
memory.frontmatter.id,
|
|
226
|
-
err instanceof Error ? err.message : err
|
|
227
|
-
);
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async function cleanupCreatedReplacement(storage, replacement) {
|
|
232
|
-
if (!replacement.created) return;
|
|
233
|
-
await cleanupMemoryId(storage, replacement.mergedId);
|
|
234
|
-
}
|
|
235
|
-
async function cleanupMemoryId(storage, memoryId) {
|
|
236
|
-
try {
|
|
237
|
-
const memory = await storage.getMemoryById(memoryId);
|
|
238
|
-
const invalidated = await storage.invalidateMemory(memoryId);
|
|
239
|
-
if (invalidated && memory?.frontmatter.category === "fact") {
|
|
240
|
-
await storage.removeFactContentHashesForMemories([memory]);
|
|
241
|
-
}
|
|
242
|
-
} catch (err) {
|
|
243
|
-
log.warn(
|
|
244
|
-
"[contradiction-resolution] cleanup failed for merged memory %s: %s",
|
|
245
|
-
memoryId,
|
|
246
|
-
err instanceof Error ? err.message : err
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
async function supersedeSafe(storage, oldId, newId, reason) {
|
|
251
|
-
try {
|
|
252
|
-
const result = await storage.supersedeMemory(oldId, newId, reason);
|
|
253
|
-
if (result === false) {
|
|
254
|
-
log.warn("[contradiction-resolution] supersede returned false for %s \u2192 %s", oldId, newId);
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
return true;
|
|
258
|
-
} catch (err) {
|
|
259
|
-
log.warn(
|
|
260
|
-
"[contradiction-resolution] supersede failed %s \u2192 %s: %s",
|
|
261
|
-
oldId,
|
|
262
|
-
newId,
|
|
263
|
-
err instanceof Error ? err.message : err
|
|
264
|
-
);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export {
|
|
270
|
-
isValidResolutionVerb,
|
|
271
|
-
executeResolution
|
|
272
|
-
};
|