@agentmemory/agentmemory 0.7.2 → 0.7.3
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/AGENTS.md +2 -2
- package/README.md +41 -68
- package/dist/cli.mjs +3 -3
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{src-1fTKFEtN.mjs → src-sYZDDbiA.mjs} +4 -3
- package/dist/src-sYZDDbiA.mjs.map +1 -0
- package/dist/standalone.mjs +1 -1
- package/dist/standalone.mjs.map +1 -1
- package/package.json +10 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/scripts/notification.d.mts +1 -0
- package/plugin/scripts/notification.mjs.map +1 -0
- package/plugin/scripts/post-tool-failure.d.mts +1 -0
- package/plugin/scripts/post-tool-failure.mjs.map +1 -0
- package/plugin/scripts/post-tool-use.d.mts +1 -0
- package/plugin/scripts/post-tool-use.mjs.map +1 -0
- package/plugin/scripts/pre-compact.d.mts +1 -0
- package/plugin/scripts/pre-compact.mjs.map +1 -0
- package/plugin/scripts/pre-tool-use.d.mts +1 -0
- package/plugin/scripts/pre-tool-use.mjs.map +1 -0
- package/plugin/scripts/prompt-submit.d.mts +1 -0
- package/plugin/scripts/prompt-submit.mjs.map +1 -0
- package/plugin/scripts/session-end.d.mts +1 -0
- package/plugin/scripts/session-end.mjs.map +1 -0
- package/plugin/scripts/session-start.d.mts +1 -0
- package/plugin/scripts/session-start.mjs.map +1 -0
- package/plugin/scripts/stop.d.mts +1 -0
- package/plugin/scripts/stop.mjs.map +1 -0
- package/plugin/scripts/subagent-start.d.mts +1 -0
- package/plugin/scripts/subagent-start.mjs.map +1 -0
- package/plugin/scripts/subagent-stop.d.mts +1 -0
- package/plugin/scripts/subagent-stop.mjs.map +1 -0
- package/plugin/scripts/task-completed.d.mts +1 -0
- package/plugin/scripts/task-completed.mjs.map +1 -0
- package/.claude-plugin/marketplace.json +0 -14
- package/.github/workflows/ci.yml +0 -22
- package/.github/workflows/publish.yml +0 -28
- package/assets/banner.png +0 -0
- package/assets/demo.gif +0 -0
- package/assets/demo.mp4 +0 -0
- package/benchmark/QUALITY.md +0 -73
- package/benchmark/REAL-EMBEDDINGS.md +0 -67
- package/benchmark/SCALE.md +0 -110
- package/benchmark/dataset.ts +0 -293
- package/benchmark/quality-eval.ts +0 -643
- package/benchmark/real-embeddings-eval.ts +0 -405
- package/benchmark/scale-eval.ts +0 -398
- package/dist/src-1fTKFEtN.mjs.map +0 -1
- package/src/auth.ts +0 -12
- package/src/cli.ts +0 -251
- package/src/config.ts +0 -221
- package/src/eval/metrics-store.ts +0 -65
- package/src/eval/quality.ts +0 -51
- package/src/eval/schemas.ts +0 -124
- package/src/eval/self-correct.ts +0 -28
- package/src/eval/validator.ts +0 -31
- package/src/functions/actions.ts +0 -288
- package/src/functions/audit.ts +0 -61
- package/src/functions/auto-forget.ts +0 -169
- package/src/functions/branch-aware.ts +0 -169
- package/src/functions/cascade.ts +0 -80
- package/src/functions/checkpoints.ts +0 -209
- package/src/functions/claude-bridge.ts +0 -161
- package/src/functions/compress.ts +0 -194
- package/src/functions/consolidate.ts +0 -212
- package/src/functions/consolidation-pipeline.ts +0 -258
- package/src/functions/context.ts +0 -169
- package/src/functions/crystallize.ts +0 -293
- package/src/functions/dedup.ts +0 -57
- package/src/functions/diagnostics.ts +0 -785
- package/src/functions/enrich.ts +0 -132
- package/src/functions/evict.ts +0 -163
- package/src/functions/export-import.ts +0 -508
- package/src/functions/facets.ts +0 -248
- package/src/functions/file-index.ts +0 -106
- package/src/functions/flow-compress.ts +0 -214
- package/src/functions/frontier.ts +0 -196
- package/src/functions/governance.ts +0 -131
- package/src/functions/graph-retrieval.ts +0 -277
- package/src/functions/graph.ts +0 -275
- package/src/functions/leases.ts +0 -216
- package/src/functions/lessons.ts +0 -253
- package/src/functions/mesh.ts +0 -434
- package/src/functions/migrate.ts +0 -165
- package/src/functions/observe.ts +0 -144
- package/src/functions/obsidian-export.ts +0 -310
- package/src/functions/patterns.ts +0 -138
- package/src/functions/privacy.ts +0 -39
- package/src/functions/profile.ts +0 -155
- package/src/functions/query-expansion.ts +0 -186
- package/src/functions/relations.ts +0 -237
- package/src/functions/remember.ts +0 -162
- package/src/functions/retention.ts +0 -235
- package/src/functions/routines.ts +0 -289
- package/src/functions/search.ts +0 -80
- package/src/functions/sentinels.ts +0 -417
- package/src/functions/signals.ts +0 -186
- package/src/functions/sketches.ts +0 -274
- package/src/functions/sliding-window.ts +0 -257
- package/src/functions/smart-search.ts +0 -115
- package/src/functions/snapshot.ts +0 -219
- package/src/functions/summarize.ts +0 -155
- package/src/functions/team.ts +0 -147
- package/src/functions/temporal-graph.ts +0 -476
- package/src/functions/timeline.ts +0 -138
- package/src/functions/verify.ts +0 -117
- package/src/health/monitor.ts +0 -110
- package/src/health/thresholds.ts +0 -73
- package/src/hooks/notification.ts +0 -52
- package/src/hooks/post-tool-failure.ts +0 -58
- package/src/hooks/post-tool-use.ts +0 -62
- package/src/hooks/pre-compact.ts +0 -60
- package/src/hooks/pre-tool-use.ts +0 -72
- package/src/hooks/prompt-submit.ts +0 -46
- package/src/hooks/session-end.ts +0 -71
- package/src/hooks/session-start.ts +0 -48
- package/src/hooks/stop.ts +0 -39
- package/src/hooks/subagent-start.ts +0 -49
- package/src/hooks/subagent-stop.ts +0 -54
- package/src/hooks/task-completed.ts +0 -54
- package/src/index.ts +0 -342
- package/src/mcp/in-memory-kv.ts +0 -61
- package/src/mcp/server.ts +0 -1455
- package/src/mcp/standalone.ts +0 -177
- package/src/mcp/tools-registry.ts +0 -769
- package/src/mcp/transport.ts +0 -91
- package/src/prompts/compression.ts +0 -67
- package/src/prompts/consolidation.ts +0 -48
- package/src/prompts/graph-extraction.ts +0 -35
- package/src/prompts/summary.ts +0 -38
- package/src/prompts/xml.ts +0 -26
- package/src/providers/agent-sdk.ts +0 -34
- package/src/providers/anthropic.ts +0 -35
- package/src/providers/circuit-breaker.ts +0 -82
- package/src/providers/embedding/cohere.ts +0 -46
- package/src/providers/embedding/gemini.ts +0 -54
- package/src/providers/embedding/index.ts +0 -39
- package/src/providers/embedding/local.ts +0 -52
- package/src/providers/embedding/openai.ts +0 -45
- package/src/providers/embedding/openrouter.ts +0 -51
- package/src/providers/embedding/voyage.ts +0 -46
- package/src/providers/fallback-chain.ts +0 -31
- package/src/providers/index.ts +0 -84
- package/src/providers/openrouter.ts +0 -71
- package/src/providers/resilient.ts +0 -37
- package/src/state/hybrid-search.ts +0 -295
- package/src/state/index-persistence.ts +0 -63
- package/src/state/keyed-mutex.ts +0 -18
- package/src/state/kv.ts +0 -33
- package/src/state/schema.ts +0 -71
- package/src/state/search-index.ts +0 -245
- package/src/state/stemmer.ts +0 -104
- package/src/state/synonyms.ts +0 -63
- package/src/state/vector-index.ts +0 -130
- package/src/telemetry/setup.ts +0 -116
- package/src/triggers/api.ts +0 -1904
- package/src/triggers/events.ts +0 -71
- package/src/types.ts +0 -769
- package/src/version.ts +0 -1
- package/src/viewer/index.html +0 -2556
- package/src/viewer/server.ts +0 -207
- package/src/xenova.d.ts +0 -3
- package/test/actions.test.ts +0 -490
- package/test/audit.test.ts +0 -108
- package/test/auto-forget.test.ts +0 -188
- package/test/cascade.test.ts +0 -277
- package/test/checkpoints.test.ts +0 -493
- package/test/circuit-breaker.test.ts +0 -107
- package/test/claude-bridge.test.ts +0 -178
- package/test/confidence.test.ts +0 -247
- package/test/consistency.test.ts +0 -61
- package/test/consolidation-pipeline.test.ts +0 -251
- package/test/crystallize.test.ts +0 -521
- package/test/diagnostics.test.ts +0 -638
- package/test/embedding-provider.test.ts +0 -49
- package/test/enrich.test.ts +0 -209
- package/test/eval.test.ts +0 -300
- package/test/export-import.test.ts +0 -251
- package/test/facets.test.ts +0 -448
- package/test/fallback-chain.test.ts +0 -93
- package/test/frontier.test.ts +0 -485
- package/test/governance.test.ts +0 -147
- package/test/graph-retrieval.test.ts +0 -186
- package/test/graph.test.ts +0 -160
- package/test/helpers/mocks.ts +0 -40
- package/test/hybrid-search.test.ts +0 -145
- package/test/index-persistence.test.ts +0 -124
- package/test/integration.test.ts +0 -265
- package/test/leases.test.ts +0 -399
- package/test/mcp-prompts.test.ts +0 -218
- package/test/mcp-resources.test.ts +0 -286
- package/test/mcp-standalone.test.ts +0 -113
- package/test/mesh.test.ts +0 -700
- package/test/privacy.test.ts +0 -87
- package/test/profile.test.ts +0 -161
- package/test/query-expansion.test.ts +0 -154
- package/test/relations.test.ts +0 -198
- package/test/retention.test.ts +0 -245
- package/test/routines.test.ts +0 -497
- package/test/schema-fingerprint.test.ts +0 -81
- package/test/schema.test.ts +0 -42
- package/test/search-index.test.ts +0 -128
- package/test/sentinels.test.ts +0 -626
- package/test/signals.test.ts +0 -410
- package/test/sketches.test.ts +0 -549
- package/test/sliding-window.test.ts +0 -199
- package/test/smart-search.test.ts +0 -169
- package/test/snapshot.test.ts +0 -165
- package/test/team.test.ts +0 -156
- package/test/temporal-graph.test.ts +0 -378
- package/test/timeline.test.ts +0 -148
- package/test/vector-index.test.ts +0 -79
- package/test/verify.test.ts +0 -209
- package/test/xml.test.ts +0 -65
- package/tsconfig.json +0 -22
- package/tsdown.config.ts +0 -62
package/src/functions/enrich.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type { ISdk } from "iii-sdk";
|
|
2
|
-
import { getContext } from "iii-sdk";
|
|
3
|
-
import type { Memory } from "../types.js";
|
|
4
|
-
import { KV } from "../state/schema.js";
|
|
5
|
-
import { StateKV } from "../state/kv.js";
|
|
6
|
-
|
|
7
|
-
const MAX_CONTEXT_LENGTH = 4000;
|
|
8
|
-
|
|
9
|
-
function escapeXml(s: string): string {
|
|
10
|
-
return s
|
|
11
|
-
.replace(/&/g, "&")
|
|
12
|
-
.replace(/</g, "<")
|
|
13
|
-
.replace(/>/g, ">")
|
|
14
|
-
.replace(/"/g, """)
|
|
15
|
-
.replace(/'/g, "'");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function registerEnrichFunction(sdk: ISdk, kv: StateKV): void {
|
|
19
|
-
sdk.registerFunction(
|
|
20
|
-
{
|
|
21
|
-
id: "mem::enrich",
|
|
22
|
-
description:
|
|
23
|
-
"Aggregate file context, relevant observations, and bug memories for pre-tool enrichment",
|
|
24
|
-
},
|
|
25
|
-
async (data: {
|
|
26
|
-
sessionId: string;
|
|
27
|
-
files: string[];
|
|
28
|
-
terms?: string[];
|
|
29
|
-
toolName?: string;
|
|
30
|
-
}) => {
|
|
31
|
-
const ctx = getContext();
|
|
32
|
-
const parts: string[] = [];
|
|
33
|
-
|
|
34
|
-
const fileContextPromise = sdk
|
|
35
|
-
.trigger<{ sessionId: string; files: string[] }, { context: string }>(
|
|
36
|
-
"mem::file-context",
|
|
37
|
-
{
|
|
38
|
-
sessionId: data.sessionId,
|
|
39
|
-
files: data.files,
|
|
40
|
-
},
|
|
41
|
-
)
|
|
42
|
-
.catch(() => ({ context: "" }));
|
|
43
|
-
|
|
44
|
-
const searchQueries: string[] = [
|
|
45
|
-
...data.files.map((f) => f.split("/").pop() || f),
|
|
46
|
-
...(data.terms || []),
|
|
47
|
-
].filter((q) => q.length > 0);
|
|
48
|
-
|
|
49
|
-
const searchPromise =
|
|
50
|
-
searchQueries.length > 0
|
|
51
|
-
? sdk
|
|
52
|
-
.trigger<
|
|
53
|
-
{ query: string; limit: number },
|
|
54
|
-
{ results: Array<{ observation: { narrative: string } }> }
|
|
55
|
-
>("mem::search", {
|
|
56
|
-
query: searchQueries.join(" "),
|
|
57
|
-
limit: 5,
|
|
58
|
-
})
|
|
59
|
-
.catch(() => ({ results: [] }))
|
|
60
|
-
: Promise.resolve({ results: [] });
|
|
61
|
-
|
|
62
|
-
const bugMemoriesPromise = kv
|
|
63
|
-
.list<Memory>(KV.memories)
|
|
64
|
-
.then((memories) =>
|
|
65
|
-
memories
|
|
66
|
-
.filter(
|
|
67
|
-
(m) =>
|
|
68
|
-
m.type === "bug" &&
|
|
69
|
-
m.isLatest &&
|
|
70
|
-
m.files.some((f) =>
|
|
71
|
-
data.files.some((df) => f.includes(df) || df.includes(f)),
|
|
72
|
-
),
|
|
73
|
-
)
|
|
74
|
-
.sort(
|
|
75
|
-
(a, b) =>
|
|
76
|
-
new Date(b.updatedAt || b.createdAt).getTime() -
|
|
77
|
-
new Date(a.updatedAt || a.createdAt).getTime(),
|
|
78
|
-
),
|
|
79
|
-
)
|
|
80
|
-
.catch(() => []);
|
|
81
|
-
|
|
82
|
-
const [fileContext, searchResult, bugMemories] = await Promise.all([
|
|
83
|
-
fileContextPromise,
|
|
84
|
-
searchPromise,
|
|
85
|
-
bugMemoriesPromise,
|
|
86
|
-
]);
|
|
87
|
-
|
|
88
|
-
if (fileContext.context) {
|
|
89
|
-
parts.push(fileContext.context);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (searchResult.results.length > 0) {
|
|
93
|
-
const observations = searchResult.results
|
|
94
|
-
.map((r) => r.observation?.narrative)
|
|
95
|
-
.filter(Boolean)
|
|
96
|
-
.map((n) => escapeXml(n as string))
|
|
97
|
-
.join("\n");
|
|
98
|
-
if (observations) {
|
|
99
|
-
parts.push(
|
|
100
|
-
`<agentmemory-relevant-context>\n${observations}\n</agentmemory-relevant-context>`,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (bugMemories.length > 0) {
|
|
106
|
-
const bugs = bugMemories
|
|
107
|
-
.slice(0, 3)
|
|
108
|
-
.map((m) => `- ${escapeXml(m.title)}: ${escapeXml(m.content)}`)
|
|
109
|
-
.join("\n");
|
|
110
|
-
parts.push(
|
|
111
|
-
`<agentmemory-past-errors>\n${bugs}\n</agentmemory-past-errors>`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let context = parts.join("\n\n");
|
|
116
|
-
let truncated = false;
|
|
117
|
-
if (context.length > MAX_CONTEXT_LENGTH) {
|
|
118
|
-
context = context.slice(0, MAX_CONTEXT_LENGTH);
|
|
119
|
-
truncated = true;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
ctx.logger.info("Enrichment completed", {
|
|
123
|
-
sessionId: data.sessionId,
|
|
124
|
-
fileCount: data.files.length,
|
|
125
|
-
contextLength: context.length,
|
|
126
|
-
truncated,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return { context, truncated };
|
|
130
|
-
},
|
|
131
|
-
);
|
|
132
|
-
}
|
package/src/functions/evict.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import type { ISdk } from "iii-sdk";
|
|
2
|
-
import { getContext } from "iii-sdk";
|
|
3
|
-
import type {
|
|
4
|
-
Session,
|
|
5
|
-
CompressedObservation,
|
|
6
|
-
SessionSummary,
|
|
7
|
-
Memory,
|
|
8
|
-
} from "../types.js";
|
|
9
|
-
import { KV } from "../state/schema.js";
|
|
10
|
-
import { StateKV } from "../state/kv.js";
|
|
11
|
-
|
|
12
|
-
interface EvictionConfig {
|
|
13
|
-
staleSessionDays: number;
|
|
14
|
-
lowImportanceMaxDays: number;
|
|
15
|
-
lowImportanceThreshold: number;
|
|
16
|
-
maxObservationsPerProject: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
20
|
-
|
|
21
|
-
const DEFAULTS: EvictionConfig = {
|
|
22
|
-
staleSessionDays: 30,
|
|
23
|
-
lowImportanceMaxDays: 90,
|
|
24
|
-
lowImportanceThreshold: 3,
|
|
25
|
-
maxObservationsPerProject: 10_000,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
interface EvictionStats {
|
|
29
|
-
staleSessions: number;
|
|
30
|
-
lowImportanceObs: number;
|
|
31
|
-
capEvictions: number;
|
|
32
|
-
expiredMemories: number;
|
|
33
|
-
nonLatestMemories: number;
|
|
34
|
-
dryRun: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function registerEvictFunction(sdk: ISdk, kv: StateKV): void {
|
|
38
|
-
sdk.registerFunction(
|
|
39
|
-
{
|
|
40
|
-
id: "mem::evict",
|
|
41
|
-
description: "Evict stale memories based on age and importance",
|
|
42
|
-
},
|
|
43
|
-
async (data: { dryRun?: boolean }): Promise<EvictionStats> => {
|
|
44
|
-
const ctx = getContext();
|
|
45
|
-
const dryRun = data?.dryRun ?? false;
|
|
46
|
-
|
|
47
|
-
const configOverride = await kv
|
|
48
|
-
.get<Partial<EvictionConfig>>(KV.config, "eviction")
|
|
49
|
-
.catch(() => null);
|
|
50
|
-
const cfg = { ...DEFAULTS, ...configOverride };
|
|
51
|
-
|
|
52
|
-
const now = Date.now();
|
|
53
|
-
const stats: EvictionStats = {
|
|
54
|
-
staleSessions: 0,
|
|
55
|
-
lowImportanceObs: 0,
|
|
56
|
-
capEvictions: 0,
|
|
57
|
-
expiredMemories: 0,
|
|
58
|
-
nonLatestMemories: 0,
|
|
59
|
-
dryRun,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const sessions = await kv.list<Session>(KV.sessions).catch(() => []);
|
|
63
|
-
const summaries = await kv
|
|
64
|
-
.list<SessionSummary>(KV.summaries)
|
|
65
|
-
.catch(() => []);
|
|
66
|
-
const summaryIds = new Set(summaries.map((s) => s.sessionId));
|
|
67
|
-
|
|
68
|
-
for (const session of sessions) {
|
|
69
|
-
if (!session.startedAt) continue;
|
|
70
|
-
const age = now - new Date(session.startedAt).getTime();
|
|
71
|
-
const staleDays = cfg.staleSessionDays * MS_PER_DAY;
|
|
72
|
-
if (age > staleDays && !summaryIds.has(session.id)) {
|
|
73
|
-
stats.staleSessions++;
|
|
74
|
-
if (!dryRun) {
|
|
75
|
-
await kv.delete(KV.sessions, session.id).catch(() => {});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const projectObs = new Map<string, CompressedObservation[]>();
|
|
81
|
-
for (const session of sessions) {
|
|
82
|
-
const obs = await kv
|
|
83
|
-
.list<CompressedObservation>(KV.observations(session.id))
|
|
84
|
-
.catch(() => []);
|
|
85
|
-
const compressed = obs.filter((o) => o.title);
|
|
86
|
-
|
|
87
|
-
for (const o of compressed) {
|
|
88
|
-
if (!o.timestamp) continue;
|
|
89
|
-
const age = now - new Date(o.timestamp).getTime();
|
|
90
|
-
const maxAge = cfg.lowImportanceMaxDays * MS_PER_DAY;
|
|
91
|
-
if (
|
|
92
|
-
age > maxAge &&
|
|
93
|
-
(o.importance ?? 5) < cfg.lowImportanceThreshold
|
|
94
|
-
) {
|
|
95
|
-
stats.lowImportanceObs++;
|
|
96
|
-
if (!dryRun) {
|
|
97
|
-
await kv
|
|
98
|
-
.delete(KV.observations(session.id), o.id)
|
|
99
|
-
.catch(() => {});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const project = session.project || "unknown";
|
|
105
|
-
const existing = projectObs.get(project) || [];
|
|
106
|
-
existing.push(...compressed);
|
|
107
|
-
projectObs.set(project, existing);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (const [, obs] of projectObs) {
|
|
111
|
-
if (obs.length > cfg.maxObservationsPerProject) {
|
|
112
|
-
const sorted = obs.sort(
|
|
113
|
-
(a, b) => (a.importance ?? 5) - (b.importance ?? 5),
|
|
114
|
-
);
|
|
115
|
-
const toEvict = sorted.slice(
|
|
116
|
-
0,
|
|
117
|
-
obs.length - cfg.maxObservationsPerProject,
|
|
118
|
-
);
|
|
119
|
-
stats.capEvictions += toEvict.length;
|
|
120
|
-
if (!dryRun) {
|
|
121
|
-
for (const o of toEvict) {
|
|
122
|
-
await kv
|
|
123
|
-
.delete(KV.observations(o.sessionId), o.id)
|
|
124
|
-
.catch(() => {});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const memories = await kv.list<Memory>(KV.memories).catch(() => []);
|
|
131
|
-
const evictedMemIds = new Set<string>();
|
|
132
|
-
for (const mem of memories) {
|
|
133
|
-
if (mem.forgetAfter) {
|
|
134
|
-
const expiry = new Date(mem.forgetAfter).getTime();
|
|
135
|
-
if (now > expiry) {
|
|
136
|
-
stats.expiredMemories++;
|
|
137
|
-
evictedMemIds.add(mem.id);
|
|
138
|
-
if (!dryRun) {
|
|
139
|
-
await kv.delete(KV.memories, mem.id).catch(() => {});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
!evictedMemIds.has(mem.id) &&
|
|
146
|
-
mem.isLatest === false &&
|
|
147
|
-
mem.createdAt
|
|
148
|
-
) {
|
|
149
|
-
const age = now - new Date(mem.createdAt).getTime();
|
|
150
|
-
if (age > cfg.lowImportanceMaxDays * MS_PER_DAY) {
|
|
151
|
-
stats.nonLatestMemories++;
|
|
152
|
-
if (!dryRun) {
|
|
153
|
-
await kv.delete(KV.memories, mem.id).catch(() => {});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
ctx.logger.info("Eviction complete", { stats });
|
|
160
|
-
return stats;
|
|
161
|
-
},
|
|
162
|
-
);
|
|
163
|
-
}
|