@mnemoai/core 1.1.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/index.ts +3395 -0
- package/openclaw.plugin.json +815 -0
- package/package.json +59 -0
- package/src/access-tracker.ts +341 -0
- package/src/adapters/README.md +78 -0
- package/src/adapters/chroma.ts +206 -0
- package/src/adapters/lancedb.ts +237 -0
- package/src/adapters/pgvector.ts +218 -0
- package/src/adapters/qdrant.ts +191 -0
- package/src/adaptive-retrieval.ts +90 -0
- package/src/audit-log.ts +238 -0
- package/src/chunker.ts +254 -0
- package/src/config.ts +271 -0
- package/src/decay-engine.ts +238 -0
- package/src/embedder.ts +735 -0
- package/src/extraction-prompts.ts +339 -0
- package/src/license.ts +258 -0
- package/src/llm-client.ts +125 -0
- package/src/mcp-server.ts +415 -0
- package/src/memory-categories.ts +71 -0
- package/src/memory-upgrader.ts +388 -0
- package/src/migrate.ts +364 -0
- package/src/mnemo.ts +142 -0
- package/src/noise-filter.ts +97 -0
- package/src/noise-prototypes.ts +164 -0
- package/src/observability.ts +81 -0
- package/src/query-tracker.ts +57 -0
- package/src/reflection-event-store.ts +98 -0
- package/src/reflection-item-store.ts +112 -0
- package/src/reflection-mapped-metadata.ts +84 -0
- package/src/reflection-metadata.ts +23 -0
- package/src/reflection-ranking.ts +33 -0
- package/src/reflection-retry.ts +181 -0
- package/src/reflection-slices.ts +265 -0
- package/src/reflection-store.ts +602 -0
- package/src/resonance-state.ts +85 -0
- package/src/retriever.ts +1510 -0
- package/src/scopes.ts +375 -0
- package/src/self-improvement-files.ts +143 -0
- package/src/semantic-gate.ts +121 -0
- package/src/session-recovery.ts +138 -0
- package/src/smart-extractor.ts +923 -0
- package/src/smart-metadata.ts +561 -0
- package/src/storage-adapter.ts +153 -0
- package/src/store.ts +1330 -0
- package/src/tier-manager.ts +189 -0
- package/src/tools.ts +1292 -0
- package/src/wal-recovery.ts +172 -0
- package/test/core.test.mjs +301 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LicenseRef-Mnemo-Pro
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
function asNonEmptyString(value: unknown): string | undefined {
|
|
5
|
+
if (typeof value !== "string") return undefined;
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
return trimmed.length ? trimmed : undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function stripResetSuffix(fileName: string): string {
|
|
11
|
+
const resetIndex = fileName.indexOf(".reset.");
|
|
12
|
+
return resetIndex === -1 ? fileName : fileName.slice(0, resetIndex);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function deriveOpenClawHomeFromWorkspacePath(workspacePath: string): string | undefined {
|
|
16
|
+
const normalized = workspacePath.trim().replace(/[\\/]+$/, "");
|
|
17
|
+
if (!normalized) return undefined;
|
|
18
|
+
const matched = normalized.match(/^(.*?)[\\/]workspace(?:[\\/].*)?$/);
|
|
19
|
+
if (!matched || !matched[1]) return undefined;
|
|
20
|
+
const home = matched[1].trim();
|
|
21
|
+
return home.length ? home : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function deriveOpenClawHomeFromSessionFilePath(sessionFilePath: string): string | undefined {
|
|
25
|
+
const normalized = sessionFilePath.trim();
|
|
26
|
+
if (!normalized) return undefined;
|
|
27
|
+
const matched = normalized.match(/^(.*?)[\\/]agents[\\/][^\\/]+[\\/]sessions(?:[\\/][^\\/]+)?$/);
|
|
28
|
+
if (!matched || !matched[1]) return undefined;
|
|
29
|
+
const home = matched[1].trim();
|
|
30
|
+
return home.length ? home : undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function listConfiguredAgentIds(cfg: unknown): string[] {
|
|
34
|
+
try {
|
|
35
|
+
const root = cfg as Record<string, unknown>;
|
|
36
|
+
const agents = root.agents as Record<string, unknown> | undefined;
|
|
37
|
+
const list = agents?.list as unknown;
|
|
38
|
+
if (!Array.isArray(list)) return [];
|
|
39
|
+
|
|
40
|
+
const ids: string[] = [];
|
|
41
|
+
for (const item of list) {
|
|
42
|
+
if (!item || typeof item !== "object") continue;
|
|
43
|
+
const id = asNonEmptyString((item as Record<string, unknown>).id);
|
|
44
|
+
if (id) ids.push(id);
|
|
45
|
+
}
|
|
46
|
+
return ids;
|
|
47
|
+
} catch {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function resolveReflectionSessionSearchDirs(params: {
|
|
53
|
+
context: Record<string, unknown>;
|
|
54
|
+
cfg: unknown;
|
|
55
|
+
workspaceDir: string;
|
|
56
|
+
currentSessionFile?: string;
|
|
57
|
+
sourceAgentId?: string;
|
|
58
|
+
}): string[] {
|
|
59
|
+
const out: string[] = [];
|
|
60
|
+
const seen = new Set<string>();
|
|
61
|
+
const addDir = (value: string | undefined) => {
|
|
62
|
+
const dir = asNonEmptyString(value);
|
|
63
|
+
if (!dir || seen.has(dir)) return;
|
|
64
|
+
seen.add(dir);
|
|
65
|
+
out.push(dir);
|
|
66
|
+
};
|
|
67
|
+
const addHome = (homes: string[], value: string | undefined) => {
|
|
68
|
+
const home = asNonEmptyString(value);
|
|
69
|
+
if (!home || homes.includes(home)) return;
|
|
70
|
+
homes.push(home);
|
|
71
|
+
};
|
|
72
|
+
const addAgentId = (agentIds: string[], value: string | undefined) => {
|
|
73
|
+
const agentId = asNonEmptyString(value);
|
|
74
|
+
if (!agentId || agentId.includes("/") || agentId.includes("\\") || agentIds.includes(agentId)) return;
|
|
75
|
+
agentIds.push(agentId);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const previousSessionEntry = (params.context.previousSessionEntry || {}) as Record<string, unknown>;
|
|
79
|
+
const sessionEntry = (params.context.sessionEntry || {}) as Record<string, unknown>;
|
|
80
|
+
const sessionEntries = [previousSessionEntry, sessionEntry];
|
|
81
|
+
|
|
82
|
+
if (params.currentSessionFile) addDir(dirname(params.currentSessionFile));
|
|
83
|
+
for (const entry of sessionEntries) {
|
|
84
|
+
const file = asNonEmptyString(entry.sessionFile);
|
|
85
|
+
if (file) addDir(dirname(file));
|
|
86
|
+
addDir(asNonEmptyString(entry.sessionsDir));
|
|
87
|
+
addDir(asNonEmptyString(entry.sessionDir));
|
|
88
|
+
}
|
|
89
|
+
addDir(join(params.workspaceDir, "sessions"));
|
|
90
|
+
|
|
91
|
+
const openclawHomes: string[] = [];
|
|
92
|
+
addHome(openclawHomes, asNonEmptyString(process.env.OPENCLAW_HOME));
|
|
93
|
+
addHome(openclawHomes, deriveOpenClawHomeFromWorkspacePath(params.workspaceDir));
|
|
94
|
+
if (params.currentSessionFile) {
|
|
95
|
+
addHome(openclawHomes, deriveOpenClawHomeFromSessionFilePath(params.currentSessionFile));
|
|
96
|
+
}
|
|
97
|
+
for (const entry of sessionEntries) {
|
|
98
|
+
const entryFile = asNonEmptyString(entry.sessionFile);
|
|
99
|
+
if (entryFile) addHome(openclawHomes, deriveOpenClawHomeFromSessionFilePath(entryFile));
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const root = params.cfg as Record<string, unknown>;
|
|
103
|
+
const agents = root.agents as Record<string, unknown> | undefined;
|
|
104
|
+
const defaults = agents?.defaults as Record<string, unknown> | undefined;
|
|
105
|
+
const defaultWorkspace = asNonEmptyString(defaults?.workspace);
|
|
106
|
+
if (defaultWorkspace) addHome(openclawHomes, deriveOpenClawHomeFromWorkspacePath(defaultWorkspace));
|
|
107
|
+
|
|
108
|
+
const list = agents?.list as unknown;
|
|
109
|
+
if (Array.isArray(list)) {
|
|
110
|
+
for (const item of list) {
|
|
111
|
+
if (!item || typeof item !== "object") continue;
|
|
112
|
+
const workspace = asNonEmptyString((item as Record<string, unknown>).workspace);
|
|
113
|
+
if (workspace) addHome(openclawHomes, deriveOpenClawHomeFromWorkspacePath(workspace));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
// ignore
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const agentIds: string[] = [];
|
|
121
|
+
addAgentId(agentIds, params.sourceAgentId);
|
|
122
|
+
addAgentId(agentIds, asNonEmptyString(params.context.agentId));
|
|
123
|
+
for (const entry of sessionEntries) {
|
|
124
|
+
addAgentId(agentIds, asNonEmptyString(entry.agentId));
|
|
125
|
+
}
|
|
126
|
+
for (const configuredId of listConfiguredAgentIds(params.cfg)) {
|
|
127
|
+
addAgentId(agentIds, configuredId);
|
|
128
|
+
}
|
|
129
|
+
addAgentId(agentIds, "main");
|
|
130
|
+
|
|
131
|
+
for (const home of openclawHomes) {
|
|
132
|
+
for (const agentId of agentIds) {
|
|
133
|
+
addDir(join(home, "agents", agentId, "sessions"));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return out;
|
|
138
|
+
}
|