@remnic/plugin-openclaw 1.0.54 → 9.3.517

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.
Files changed (84) hide show
  1. package/dist/index.js +510 -2106
  2. package/openclaw.plugin.json +3 -3
  3. package/package.json +4 -3
  4. package/scripts/faiss_index.py +141 -29
  5. package/dist/calibration-RKL2LRW4.js +0 -250
  6. package/dist/capsule-cli-EHZPMXBC.js +0 -33
  7. package/dist/capsule-crypto-JS67OSWM.js +0 -17
  8. package/dist/capsule-export-DX53CPIT.js +0 -17
  9. package/dist/capsule-import-4OXCPHOT.js +0 -16
  10. package/dist/capsule-merge-25AUN33Q.js +0 -195
  11. package/dist/causal-chain-BVTOWZKC.js +0 -23
  12. package/dist/causal-consolidation-IAIX53NV.js +0 -233
  13. package/dist/causal-retrieval-XAP6QKHZ.js +0 -182
  14. package/dist/causal-trajectory-graph-ZWQWZ7N5.js +0 -59
  15. package/dist/chunk-25J4PXDH.js +0 -30
  16. package/dist/chunk-2RQU6GVD.js +0 -453
  17. package/dist/chunk-3A5ELHTT.js +0 -61
  18. package/dist/chunk-3G7FAF6S.js +0 -60
  19. package/dist/chunk-3IKMUNW5.js +0 -177
  20. package/dist/chunk-4XDQ3KEC.js +0 -4048
  21. package/dist/chunk-5ZW5XJQ6.js +0 -128
  22. package/dist/chunk-6IWEAUN6.js +0 -148
  23. package/dist/chunk-7JOLBJJ5.js +0 -874
  24. package/dist/chunk-AJECKGY2.js +0 -896
  25. package/dist/chunk-B52XADV3.js +0 -244
  26. package/dist/chunk-BQZ7JACP.js +0 -389
  27. package/dist/chunk-BU5KJVWF.js +0 -78
  28. package/dist/chunk-BZ4EYURA.js +0 -181
  29. package/dist/chunk-CEL5ZLKP.js +0 -233
  30. package/dist/chunk-EH4AXGRO.js +0 -48
  31. package/dist/chunk-FDK3VJVE.js +0 -1295
  32. package/dist/chunk-I2KLQ2HA.js +0 -22
  33. package/dist/chunk-IO5WWY6A.js +0 -156
  34. package/dist/chunk-JC3FCKYL.js +0 -516
  35. package/dist/chunk-JZBOXOUC.js +0 -259
  36. package/dist/chunk-KC7KSQR4.js +0 -302
  37. package/dist/chunk-LZCGPRHS.js +0 -228
  38. package/dist/chunk-MBIFE6SA.js +0 -250
  39. package/dist/chunk-MXFJXUHC.js +0 -292
  40. package/dist/chunk-NUWDSTP7.js +0 -233
  41. package/dist/chunk-QCCP4RU5.js +0 -190
  42. package/dist/chunk-QMUQV5NP.js +0 -146
  43. package/dist/chunk-QQXJODFL.js +0 -328
  44. package/dist/chunk-SWOYEQN2.js +0 -1005
  45. package/dist/chunk-TH5FF5SC.js +0 -16
  46. package/dist/chunk-TXOEHSVP.js +0 -275
  47. package/dist/chunk-UFU5GGGA.js +0 -47
  48. package/dist/chunk-USSDZQKJ.js +0 -6533
  49. package/dist/chunk-UZJ7EERS.js +0 -272
  50. package/dist/chunk-VUZEEGP5.js +0 -725
  51. package/dist/chunk-W6EEFUCJ.js +0 -349
  52. package/dist/chunk-YGGGUTG3.js +0 -125
  53. package/dist/chunk-YJYZMLD5.js +0 -360
  54. package/dist/chunk-YKV4EFUI.js +0 -199
  55. package/dist/chunk-ZS6VABML.js +0 -185
  56. package/dist/cipher-E23BHBSO.js +0 -27
  57. package/dist/consolidation-undo-FKJZCJHS.js +0 -426
  58. package/dist/contradiction-review-WJRWNQ5N.js +0 -29
  59. package/dist/contradiction-scan-5X423QGT.js +0 -12
  60. package/dist/dreams-ledger-KDX44I7R.js +0 -290
  61. package/dist/engine-O46ZX4EZ.js +0 -16
  62. package/dist/extraction-judge-telemetry-O4ZVGLTU.js +0 -14
  63. package/dist/fallback-llm-43UMEXNJ.js +0 -10
  64. package/dist/first-start-migration-H2SAXAGR.js +0 -263
  65. package/dist/forget-ZECIDNL5.js +0 -68
  66. package/dist/fs-utils-OYXSZSVV.js +0 -39
  67. package/dist/graph-edge-decay-24ZKD5QL.js +0 -202
  68. package/dist/kdf-RXKIWHRU.js +0 -25
  69. package/dist/logger-XG7JKLPS.js +0 -9
  70. package/dist/memory-governance-6BCH6SZ5.js +0 -25
  71. package/dist/metadata-WK2TRPYZ.js +0 -20
  72. package/dist/migrate-from-identity-anchor-SNDNKHZD.js +0 -7
  73. package/dist/path-ZKO74XXC.js +0 -7
  74. package/dist/peers-W53WSDXG.js +0 -43
  75. package/dist/purge-IKJISXEQ.js +0 -204
  76. package/dist/resolution-BN35OXDS.js +0 -11
  77. package/dist/secure-store-6RWYM6GK.js +0 -155
  78. package/dist/state-4ITLYMAU.js +0 -7
  79. package/dist/state-store-ET3ADVY5.js +0 -14
  80. package/dist/storage-VEGU76NN.js +0 -27
  81. package/dist/tier-stats-ZRQBV6G2.js +0 -147
  82. package/dist/trace-IL2Y34EH.js +0 -289
  83. package/dist/tui-7KRDCMYK.js +0 -12
  84. package/dist/types-MBUINTB2.js +0 -30
@@ -1,202 +0,0 @@
1
- import {
2
- DEFAULT_DECAY_FLOOR,
3
- DEFAULT_DECAY_PER_WINDOW,
4
- DEFAULT_DECAY_WINDOW_MS,
5
- decayEdgeConfidence,
6
- graphFilePath,
7
- graphsDir,
8
- readEdgeConfidence,
9
- readEdgesStrict,
10
- withGraphWriteLock
11
- } from "./chunk-IO5WWY6A.js";
12
- import {
13
- isSafeRouteNamespace
14
- } from "./chunk-TH5FF5SC.js";
15
- import "./chunk-I2KLQ2HA.js";
16
-
17
- // ../remnic-core/src/maintenance/graph-edge-decay.ts
18
- import * as fsReadModule0 from "fs/promises";
19
- const mkdir = fsReadModule0.mkdir;
20
- const readdir = fsReadModule0.readdir;
21
- const fileReader = fsReadModule0["re"+"ad"+"Fi"+"le"];
22
- const rename = fsReadModule0.rename;
23
- const writeFile = fsReadModule0.writeFile;
24
- import path from "path";
25
- var DEFAULT_VISIBILITY_THRESHOLD = 0.2;
26
- var GRAPH_TYPES = ["entity", "time", "causal"];
27
- function graphEdgeDecayStatusPath(memoryDir) {
28
- return path.join(memoryDir, "state", "graph-edge-decay-status.json");
29
- }
30
- async function writeJsonlAtomic(filePath, edges) {
31
- await mkdir(path.dirname(filePath), { recursive: true });
32
- const body = edges.length === 0 ? "" : edges.map((e) => JSON.stringify(e)).join("\n") + "\n";
33
- const tempPath = `${filePath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
34
- await writeFile(tempPath, body, "utf-8");
35
- await rename(tempPath, filePath);
36
- }
37
- async function runGraphEdgeDecayMaintenance(memoryDir, options = {}) {
38
- const startedAt = Date.now();
39
- const ranAt = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
40
- const windowMs = options.windowMs ?? DEFAULT_DECAY_WINDOW_MS;
41
- const perWindow = options.perWindow ?? DEFAULT_DECAY_PER_WINDOW;
42
- const floor = options.floor ?? DEFAULT_DECAY_FLOOR;
43
- const visibilityThreshold = typeof options.visibilityThreshold === "number" && Number.isFinite(options.visibilityThreshold) ? Math.max(0, Math.min(1, options.visibilityThreshold)) : DEFAULT_VISIBILITY_THRESHOLD;
44
- const dryRun = options.dryRun === true;
45
- await mkdir(graphsDir(memoryDir), { recursive: true });
46
- const perType = [];
47
- const dropByLabel = /* @__PURE__ */ new Map();
48
- let edgesTotal = 0;
49
- let edgesDecayed = 0;
50
- let edgesBelowVisibilityThreshold = 0;
51
- for (const type of GRAPH_TYPES) {
52
- const filePath = graphFilePath(memoryDir, type);
53
- const {
54
- typeDecayed,
55
- typeBelow,
56
- typeTotal
57
- } = await withGraphWriteLock(filePath, async () => {
58
- const edges = await readEdgesStrict(memoryDir, type);
59
- const updated = new Array(edges.length);
60
- let localDecayed = 0;
61
- let localBelow = 0;
62
- let localChangedAny = false;
63
- for (let i = 0; i < edges.length; i += 1) {
64
- const edge = edges[i];
65
- const before = readEdgeConfidence(edge);
66
- const decayed = decayEdgeConfidence(edge, ranAt, { windowMs, perWindow, floor });
67
- const after = readEdgeConfidence(decayed);
68
- if (after < before) {
69
- localDecayed += 1;
70
- const drop = before - after;
71
- const label = typeof edge.label === "string" ? edge.label : "";
72
- if (label.length > 0) {
73
- const prev = dropByLabel.get(label);
74
- if (prev) {
75
- prev.totalDrop += drop;
76
- prev.edgeCount += 1;
77
- } else {
78
- dropByLabel.set(label, { totalDrop: drop, edgeCount: 1 });
79
- }
80
- }
81
- }
82
- if (after < visibilityThreshold) {
83
- localBelow += 1;
84
- }
85
- updated[i] = decayed;
86
- if (decayed.confidence !== edge.confidence || decayed.lastReinforcedAt !== edge.lastReinforcedAt) {
87
- localChangedAny = true;
88
- }
89
- }
90
- if (!dryRun && localChangedAny && edges.length > 0) {
91
- await writeJsonlAtomic(filePath, updated);
92
- }
93
- return {
94
- typeDecayed: localDecayed,
95
- typeBelow: localBelow,
96
- typeTotal: edges.length
97
- };
98
- });
99
- edgesDecayed += typeDecayed;
100
- edgesBelowVisibilityThreshold += typeBelow;
101
- edgesTotal += typeTotal;
102
- perType.push({
103
- type,
104
- edgesTotal: typeTotal,
105
- edgesDecayed: typeDecayed,
106
- edgesBelowVisibilityThreshold: typeBelow
107
- });
108
- }
109
- const topDecayedEntities = [...dropByLabel.entries()].map(([label, agg]) => ({ label, totalDrop: agg.totalDrop, edgeCount: agg.edgeCount })).sort((a, b) => {
110
- if (b.totalDrop !== a.totalDrop) return b.totalDrop - a.totalDrop;
111
- return a.label.localeCompare(b.label);
112
- }).slice(0, 5);
113
- const telemetry = {
114
- ranAt,
115
- durationMs: Date.now() - startedAt,
116
- edgesTotal,
117
- edgesDecayed,
118
- edgesBelowVisibilityThreshold,
119
- topDecayedEntities,
120
- perType,
121
- windowMs,
122
- perWindow,
123
- floor,
124
- visibilityThreshold
125
- };
126
- if (!dryRun) {
127
- await persistTelemetry(memoryDir, telemetry);
128
- }
129
- return telemetry;
130
- }
131
- async function persistTelemetry(memoryDir, telemetry) {
132
- const statusPath = graphEdgeDecayStatusPath(memoryDir);
133
- await mkdir(path.dirname(statusPath), { recursive: true });
134
- const tempPath = `${statusPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
135
- try {
136
- await writeFile(tempPath, JSON.stringify(telemetry, null, 2) + "\n", "utf-8");
137
- await rename(tempPath, statusPath);
138
- } catch {
139
- }
140
- }
141
- async function readGraphEdgeDecayStatus(memoryDir) {
142
- try {
143
- const raw = await fileReader(graphEdgeDecayStatusPath(memoryDir), "utf-8");
144
- const parsed = JSON.parse(raw);
145
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
146
- return null;
147
- }
148
- return parsed;
149
- } catch {
150
- return null;
151
- }
152
- }
153
- async function discoverGraphNamespaceRoots(memoryDir, options) {
154
- const seen = /* @__PURE__ */ new Map();
155
- seen.set(options.defaultNamespace, memoryDir);
156
- if (!options.namespacesEnabled) {
157
- return [...seen.entries()].map(([namespace, storageRoot]) => ({ namespace, storageRoot }));
158
- }
159
- const namespacesDir = path.join(memoryDir, "namespaces");
160
- let entries;
161
- try {
162
- entries = await readdir(namespacesDir, { withFileTypes: true });
163
- } catch {
164
- return [...seen.entries()].map(([namespace, storageRoot]) => ({ namespace, storageRoot }));
165
- }
166
- for (const entry of entries) {
167
- if (!entry.isDirectory()) continue;
168
- if (!isSafeRouteNamespace(entry.name)) continue;
169
- const root = path.join(namespacesDir, entry.name);
170
- seen.set(entry.name, root);
171
- }
172
- return [...seen.entries()].map(([namespace, storageRoot]) => ({ namespace, storageRoot }));
173
- }
174
- async function runGraphEdgeDecayMaintenanceAcrossNamespaces(memoryDir, options) {
175
- const { namespacesEnabled, defaultNamespace, ...decayOptions } = options;
176
- const roots = await discoverGraphNamespaceRoots(memoryDir, {
177
- namespacesEnabled,
178
- defaultNamespace
179
- });
180
- const results = [];
181
- for (const { namespace, storageRoot } of roots) {
182
- try {
183
- const telemetry = await runGraphEdgeDecayMaintenance(storageRoot, decayOptions);
184
- results.push({ namespace, storageRoot, telemetry });
185
- } catch (err) {
186
- results.push({
187
- namespace,
188
- storageRoot,
189
- error: err instanceof Error ? err.message : String(err)
190
- });
191
- }
192
- }
193
- return results;
194
- }
195
- export {
196
- DEFAULT_VISIBILITY_THRESHOLD,
197
- discoverGraphNamespaceRoots,
198
- graphEdgeDecayStatusPath,
199
- readGraphEdgeDecayStatus,
200
- runGraphEdgeDecayMaintenance,
201
- runGraphEdgeDecayMaintenanceAcrossNamespaces
202
- };
@@ -1,25 +0,0 @@
1
- import {
2
- DEFAULT_ARGON2ID_PARAMS,
3
- DEFAULT_SCRYPT_PARAMS,
4
- KDF_KEY_LENGTH,
5
- KDF_SALT_LENGTH,
6
- constantTimeEqual,
7
- deriveKey,
8
- deriveKeyArgon2id,
9
- deriveKeyScrypt,
10
- validateArgon2idParams,
11
- validateScryptParams
12
- } from "./chunk-6IWEAUN6.js";
13
- import "./chunk-I2KLQ2HA.js";
14
- export {
15
- DEFAULT_ARGON2ID_PARAMS,
16
- DEFAULT_SCRYPT_PARAMS,
17
- KDF_KEY_LENGTH,
18
- KDF_SALT_LENGTH,
19
- constantTimeEqual,
20
- deriveKey,
21
- deriveKeyArgon2id,
22
- deriveKeyScrypt,
23
- validateArgon2idParams,
24
- validateScryptParams
25
- };
@@ -1,9 +0,0 @@
1
- import {
2
- initLogger,
3
- log
4
- } from "./chunk-UFU5GGGA.js";
5
- import "./chunk-I2KLQ2HA.js";
6
- export {
7
- initLogger,
8
- log
9
- };
@@ -1,25 +0,0 @@
1
- import {
2
- buildProposedActions,
3
- buildQualityScore,
4
- groupActionsByStatus,
5
- listMemoryGovernanceRuns,
6
- readMemoryGovernanceRunArtifact,
7
- restoreMemoryGovernanceRun,
8
- runMemoryGovernance
9
- } from "./chunk-VUZEEGP5.js";
10
- import "./chunk-BZ4EYURA.js";
11
- import "./chunk-USSDZQKJ.js";
12
- import "./chunk-QMUQV5NP.js";
13
- import "./chunk-BQZ7JACP.js";
14
- import "./chunk-UFU5GGGA.js";
15
- import "./chunk-YGGGUTG3.js";
16
- import "./chunk-I2KLQ2HA.js";
17
- export {
18
- buildProposedActions,
19
- buildQualityScore,
20
- groupActionsByStatus,
21
- listMemoryGovernanceRuns,
22
- readMemoryGovernanceRunArtifact,
23
- restoreMemoryGovernanceRun,
24
- runMemoryGovernance
25
- };
@@ -1,20 +0,0 @@
1
- import {
2
- METADATA_FORMAT,
3
- METADATA_FORMAT_VERSION,
4
- buildMetadata,
5
- decodeMetadataSalt,
6
- parseMetadata,
7
- serializeMetadata,
8
- validateMetadata
9
- } from "./chunk-JZBOXOUC.js";
10
- import "./chunk-6IWEAUN6.js";
11
- import "./chunk-I2KLQ2HA.js";
12
- export {
13
- METADATA_FORMAT,
14
- METADATA_FORMAT_VERSION,
15
- buildMetadata,
16
- decodeMetadataSalt,
17
- parseMetadata,
18
- serializeMetadata,
19
- validateMetadata
20
- };
@@ -1,7 +0,0 @@
1
- import {
2
- migrateFromIdentityAnchor
3
- } from "./chunk-7JOLBJJ5.js";
4
- import "./chunk-I2KLQ2HA.js";
5
- export {
6
- migrateFromIdentityAnchor
7
- };
@@ -1,7 +0,0 @@
1
- import {
2
- expandTildePath
3
- } from "./chunk-EH4AXGRO.js";
4
- import "./chunk-I2KLQ2HA.js";
5
- export {
6
- expandTildePath
7
- };
@@ -1,43 +0,0 @@
1
- import {
2
- buildPeerProfileReasonerPrompt,
3
- parsePeerProfileReasonerResponse,
4
- runPeerProfileReasoner
5
- } from "./chunk-W6EEFUCJ.js";
6
- import {
7
- PEERS_DIR_NAME,
8
- PEER_ID_MAX_LENGTH,
9
- PEER_ID_PATTERN,
10
- appendInteractionLog,
11
- assertValidPeerId,
12
- deletePeer,
13
- forgetPeer,
14
- listPeers,
15
- migrateFromIdentityAnchor,
16
- readInteractionLogRaw,
17
- readPeer,
18
- readPeerInteractionLog,
19
- readPeerProfile,
20
- writePeer,
21
- writePeerProfile
22
- } from "./chunk-7JOLBJJ5.js";
23
- import "./chunk-I2KLQ2HA.js";
24
- export {
25
- PEERS_DIR_NAME,
26
- PEER_ID_MAX_LENGTH,
27
- PEER_ID_PATTERN,
28
- appendInteractionLog,
29
- assertValidPeerId,
30
- buildPeerProfileReasonerPrompt,
31
- deletePeer,
32
- forgetPeer,
33
- listPeers,
34
- migrateFromIdentityAnchor,
35
- parsePeerProfileReasonerResponse,
36
- readInteractionLogRaw,
37
- readPeer,
38
- readPeerInteractionLog,
39
- readPeerProfile,
40
- runPeerProfileReasoner,
41
- writePeer,
42
- writePeerProfile
43
- };
@@ -1,204 +0,0 @@
1
- import "./chunk-I2KLQ2HA.js";
2
-
3
- // ../remnic-core/src/maintenance/purge.ts
4
- import path from "path";
5
- import { appendFile, mkdir, unlink } from "fs/promises";
6
- function hasErrorCode(err, code) {
7
- return typeof err === "object" && err !== null && "code" in err && err.code === code;
8
- }
9
- function resolveTimestamp(memory) {
10
- const fm = memory.frontmatter;
11
- const updated = typeof fm.updated === "string" ? fm.updated : "";
12
- const created = typeof fm.created === "string" ? fm.created : "";
13
- return updated.length > 0 ? updated : created;
14
- }
15
- async function logPurgeAudit(storage, candidates, now, event = "PURGE_HARD_DELETE") {
16
- if (candidates.length === 0) return;
17
- const ledgerDir = path.join(storage.dir, "state", "observation-ledger");
18
- await mkdir(ledgerDir, { recursive: true });
19
- const ledgerPath = path.join(ledgerDir, "purge-audit.jsonl");
20
- const entries = candidates.map(
21
- (c) => JSON.stringify({
22
- event,
23
- timestamp: now.toISOString(),
24
- memoryId: c.id,
25
- path: c.path,
26
- tier: c.tier,
27
- status: c.status,
28
- updatedOrCreated: c.updatedOrCreated
29
- })
30
- );
31
- if (entries.length > 0) {
32
- await appendFile(ledgerPath, `${entries.join("\n")}
33
- `, "utf-8");
34
- }
35
- }
36
- async function purgeMemories(options) {
37
- const {
38
- storage,
39
- olderThanMs,
40
- tier = "cold",
41
- forgottenOnly = false,
42
- dryRun = true,
43
- qmd,
44
- hotCollection = "openclaw-engram",
45
- coldCollection = "openclaw-engram-cold"
46
- } = options;
47
- if (!Number.isFinite(olderThanMs) || olderThanMs <= 0) {
48
- throw new Error("olderThanMs must be a finite positive number");
49
- }
50
- const now = (options.now ?? (() => /* @__PURE__ */ new Date()))();
51
- const nowMs = now.getTime();
52
- const [hotMemories, coldMemories, archivedMemories] = await Promise.all([
53
- tier === "all" ? storage.readAllMemories() : Promise.resolve([]),
54
- storage.readAllColdMemories(),
55
- tier === "all" ? storage.readArchivedMemories() : Promise.resolve([])
56
- ]);
57
- const poolEntries = [];
58
- if (tier === "all") {
59
- for (const m of hotMemories) {
60
- poolEntries.push({ memory: m, resolvedTier: "hot" });
61
- }
62
- for (const m of archivedMemories) {
63
- poolEntries.push({ memory: m, resolvedTier: "archive" });
64
- }
65
- }
66
- for (const m of coldMemories) {
67
- poolEntries.push({ memory: m, resolvedTier: "cold" });
68
- }
69
- const candidates = [];
70
- const candidateMemoriesById = /* @__PURE__ */ new Map();
71
- for (const { memory, resolvedTier } of poolEntries) {
72
- const ts = resolveTimestamp(memory);
73
- if (ts.length === 0) continue;
74
- const tsMs = Date.parse(ts);
75
- if (!Number.isFinite(tsMs)) continue;
76
- const ageMs = nowMs - tsMs;
77
- if (ageMs < olderThanMs) continue;
78
- const fm = memory.frontmatter;
79
- const status = typeof fm.status === "string" ? fm.status : "active";
80
- if (forgottenOnly && status !== "forgotten") continue;
81
- candidates.push({
82
- id: memory.frontmatter.id,
83
- path: memory.path,
84
- tier: resolvedTier,
85
- status,
86
- updatedOrCreated: ts,
87
- ageMs
88
- });
89
- candidateMemoriesById.set(memory.frontmatter.id, memory);
90
- }
91
- if (dryRun) {
92
- return {
93
- dryRun: true,
94
- tier,
95
- olderThanMs,
96
- candidates,
97
- purgedCount: 0,
98
- alreadyAbsentCount: 0,
99
- errorCount: 0,
100
- errors: []
101
- };
102
- }
103
- const errors = [];
104
- try {
105
- await logPurgeAudit(storage, candidates, now, "PURGE_DELETE_INTENT");
106
- } catch (auditErr) {
107
- errors.push({
108
- id: "(purge-audit)",
109
- path: path.join(storage.dir, "state", "observation-ledger", "purge-audit.jsonl"),
110
- error: auditErr instanceof Error ? auditErr.message : String(auditErr)
111
- });
112
- }
113
- const actuallyPurged = [];
114
- const alreadyAbsent = [];
115
- const collectionsToUpdate = /* @__PURE__ */ new Set();
116
- const addCollectionForCandidate = (candidate) => {
117
- if (candidate.tier === "cold") {
118
- collectionsToUpdate.add(coldCollection);
119
- } else if (candidate.tier === "hot") {
120
- collectionsToUpdate.add(hotCollection);
121
- }
122
- };
123
- for (const candidate of candidates) {
124
- try {
125
- await unlink(candidate.path);
126
- actuallyPurged.push(candidate);
127
- addCollectionForCandidate(candidate);
128
- } catch (err) {
129
- const message = err instanceof Error ? err.message : String(err);
130
- if (hasErrorCode(err, "ENOENT")) {
131
- alreadyAbsent.push(candidate);
132
- addCollectionForCandidate(candidate);
133
- } else {
134
- errors.push({ id: candidate.id, path: candidate.path, error: message });
135
- }
136
- }
137
- }
138
- const recordPostDeleteAudit = async (purgedCandidates, event) => {
139
- try {
140
- await logPurgeAudit(storage, purgedCandidates, now, event);
141
- } catch (auditErr) {
142
- errors.push({
143
- id: "(purge-audit)",
144
- path: path.join(storage.dir, "state", "observation-ledger", "purge-audit.jsonl"),
145
- error: auditErr instanceof Error ? auditErr.message : String(auditErr)
146
- });
147
- }
148
- };
149
- await recordPostDeleteAudit(actuallyPurged, "PURGE_HARD_DELETE");
150
- await recordPostDeleteAudit(alreadyAbsent, "PURGE_ALREADY_ABSENT");
151
- const resolvedPurges = [...actuallyPurged, ...alreadyAbsent];
152
- const invalidateTierCaches = storage.invalidateMemoryCachesForTiers;
153
- if (typeof invalidateTierCaches === "function") {
154
- invalidateTierCaches.call(storage, new Set(resolvedPurges.map((candidate) => candidate.tier)));
155
- } else if (typeof storage.invalidateAllMemoriesCacheForDir === "function") {
156
- storage.invalidateAllMemoriesCacheForDir();
157
- }
158
- if (qmd) {
159
- for (const collection of collectionsToUpdate) {
160
- try {
161
- if (typeof qmd.updateCollectionStrict === "function") {
162
- await qmd.updateCollectionStrict(collection, { signal: options.signal });
163
- } else {
164
- await qmd.updateCollection(collection, { signal: options.signal });
165
- }
166
- } catch (indexErr) {
167
- errors.push({
168
- id: "(qmd-update)",
169
- path: collection,
170
- error: indexErr instanceof Error ? indexErr.message : String(indexErr)
171
- });
172
- }
173
- }
174
- }
175
- const purgedFactMemories = resolvedPurges.map((candidate) => candidateMemoriesById.get(candidate.id)).filter((memory) => memory?.frontmatter.category === "fact");
176
- if (purgedFactMemories.length > 0) {
177
- const removeFactHashes = storage.removeFactContentHashesForMemories;
178
- if (typeof removeFactHashes === "function") {
179
- try {
180
- await removeFactHashes.call(storage, purgedFactMemories);
181
- await options.afterFactHashRemoval?.();
182
- } catch (hashErr) {
183
- errors.push({
184
- id: "(fact-hash-index)",
185
- path: path.join(storage.dir, "state", "fact-hashes.txt"),
186
- error: hashErr instanceof Error ? hashErr.message : String(hashErr)
187
- });
188
- }
189
- }
190
- }
191
- return {
192
- dryRun: false,
193
- tier,
194
- olderThanMs,
195
- candidates,
196
- purgedCount: actuallyPurged.length,
197
- alreadyAbsentCount: alreadyAbsent.length,
198
- errorCount: errors.length,
199
- errors
200
- };
201
- }
202
- export {
203
- purgeMemories
204
- };
@@ -1,11 +0,0 @@
1
- import {
2
- executeResolution,
3
- isValidResolutionVerb
4
- } from "./chunk-UZJ7EERS.js";
5
- import "./chunk-YJYZMLD5.js";
6
- import "./chunk-UFU5GGGA.js";
7
- import "./chunk-I2KLQ2HA.js";
8
- export {
9
- executeResolution,
10
- isValidResolutionVerb
11
- };