openclaw-cortex-memory 0.1.0-Alpha.2 → 0.1.0-Alpha.20

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 (65) hide show
  1. package/README.md +115 -90
  2. package/SKILL.md +96 -32
  3. package/dist/index.d.ts +52 -15
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +677 -1195
  6. package/dist/index.js.map +1 -1
  7. package/dist/openclaw.plugin.json +157 -5
  8. package/dist/src/dedup/three_stage_deduplicator.d.ts +25 -0
  9. package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -0
  10. package/dist/src/dedup/three_stage_deduplicator.js +225 -0
  11. package/dist/src/dedup/three_stage_deduplicator.js.map +1 -0
  12. package/dist/src/engine/memory_engine.d.ts +2 -1
  13. package/dist/src/engine/memory_engine.d.ts.map +1 -1
  14. package/dist/src/engine/ts_engine.d.ts +95 -0
  15. package/dist/src/engine/ts_engine.d.ts.map +1 -1
  16. package/dist/src/engine/ts_engine.js +918 -38
  17. package/dist/src/engine/ts_engine.js.map +1 -1
  18. package/dist/src/engine/types.d.ts +11 -0
  19. package/dist/src/engine/types.d.ts.map +1 -1
  20. package/dist/src/graph/ontology.d.ts +53 -0
  21. package/dist/src/graph/ontology.d.ts.map +1 -0
  22. package/dist/src/graph/ontology.js +252 -0
  23. package/dist/src/graph/ontology.js.map +1 -0
  24. package/dist/src/reflect/reflector.d.ts +7 -0
  25. package/dist/src/reflect/reflector.d.ts.map +1 -1
  26. package/dist/src/reflect/reflector.js +75 -1
  27. package/dist/src/reflect/reflector.js.map +1 -1
  28. package/dist/src/session/session_end.d.ts +56 -0
  29. package/dist/src/session/session_end.d.ts.map +1 -1
  30. package/dist/src/session/session_end.js +270 -55
  31. package/dist/src/session/session_end.js.map +1 -1
  32. package/dist/src/store/archive_store.d.ts +115 -0
  33. package/dist/src/store/archive_store.d.ts.map +1 -0
  34. package/dist/src/store/archive_store.js +446 -0
  35. package/dist/src/store/archive_store.js.map +1 -0
  36. package/dist/src/store/embedding_utils.d.ts +32 -0
  37. package/dist/src/store/embedding_utils.d.ts.map +1 -0
  38. package/dist/src/store/embedding_utils.js +173 -0
  39. package/dist/src/store/embedding_utils.js.map +1 -0
  40. package/dist/src/store/read_store.d.ts +59 -0
  41. package/dist/src/store/read_store.d.ts.map +1 -1
  42. package/dist/src/store/read_store.js +1114 -17
  43. package/dist/src/store/read_store.js.map +1 -1
  44. package/dist/src/store/vector_store.d.ts +43 -0
  45. package/dist/src/store/vector_store.d.ts.map +1 -0
  46. package/dist/src/store/vector_store.js +200 -0
  47. package/dist/src/store/vector_store.js.map +1 -0
  48. package/dist/src/store/write_store.d.ts +45 -0
  49. package/dist/src/store/write_store.d.ts.map +1 -1
  50. package/dist/src/store/write_store.js +230 -0
  51. package/dist/src/store/write_store.js.map +1 -1
  52. package/dist/src/sync/session_sync.d.ts +52 -2
  53. package/dist/src/sync/session_sync.d.ts.map +1 -1
  54. package/dist/src/sync/session_sync.js +474 -22
  55. package/dist/src/sync/session_sync.js.map +1 -1
  56. package/dist/src/utils/runtime_env.d.ts +4 -0
  57. package/dist/src/utils/runtime_env.d.ts.map +1 -0
  58. package/dist/src/utils/runtime_env.js +51 -0
  59. package/dist/src/utils/runtime_env.js.map +1 -0
  60. package/openclaw.plugin.json +157 -5
  61. package/package.json +21 -6
  62. package/scripts/cli.js +19 -14
  63. package/scripts/uninstall.js +22 -5
  64. package/index.ts +0 -2092
  65. package/scripts/install.js +0 -27
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getEnvValue = getEnvValue;
37
+ exports.getHomeDir = getHomeDir;
38
+ exports.getProcessEnvCopy = getProcessEnvCopy;
39
+ const os = __importStar(require("os"));
40
+ function getEnvValue(key) {
41
+ const value = process.env[key];
42
+ return typeof value === "string" ? value : "";
43
+ }
44
+ function getHomeDir() {
45
+ return os.homedir() || "";
46
+ }
47
+ function getProcessEnvCopy() {
48
+ const entries = Object.entries(process.env).filter((entry) => typeof entry[1] === "string");
49
+ return Object.fromEntries(entries);
50
+ }
51
+ //# sourceMappingURL=runtime_env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime_env.js","sourceRoot":"","sources":["../../../src/utils/runtime_env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kCAGC;AAED,gCAEC;AAED,8CAGC;AAdD,uCAAyB;AAEzB,SAAgB,WAAW,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,SAAgB,UAAU;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,SAAgB,iBAAiB;IAC/B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAA6B,EAAE,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;IACvH,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "id": "openclaw-cortex-memory",
3
3
  "name": "Cortex Memory",
4
- "version": "0.1.0-Alpha.1",
4
+ "version": "0.1.0-Alpha.20",
5
5
  "description": "Long-term memory system with semantic, episodic, and procedural memory for AI Agents",
6
6
  "main": "dist/index.js",
7
- "author": "OpenClaw Community",
7
+ "author": "deki18",
8
8
  "license": "MIT",
9
9
  "type": "memory",
10
10
  "repository": {
@@ -56,7 +56,26 @@
56
56
  "type": "array",
57
57
  "description": "Involved entities",
58
58
  "items": {
59
- "type": "string"
59
+ "oneOf": [
60
+ {
61
+ "type": "string"
62
+ },
63
+ {
64
+ "type": "object",
65
+ "properties": {
66
+ "id": {
67
+ "type": "string"
68
+ },
69
+ "name": {
70
+ "type": "string"
71
+ },
72
+ "type": {
73
+ "type": "string"
74
+ }
75
+ },
76
+ "additionalProperties": false
77
+ }
78
+ ]
60
79
  }
61
80
  },
62
81
  "outcome": {
@@ -67,7 +86,27 @@
67
86
  "type": "array",
68
87
  "description": "Entity relationships",
69
88
  "items": {
70
- "type": "string"
89
+ "oneOf": [
90
+ {
91
+ "type": "string"
92
+ },
93
+ {
94
+ "type": "object",
95
+ "properties": {
96
+ "source": {
97
+ "type": "string"
98
+ },
99
+ "target": {
100
+ "type": "string"
101
+ },
102
+ "type": {
103
+ "type": "string"
104
+ }
105
+ },
106
+ "required": ["source", "target"],
107
+ "additionalProperties": false
108
+ }
109
+ ]
71
110
  }
72
111
  }
73
112
  },
@@ -84,6 +123,23 @@
84
123
  "entity": {
85
124
  "type": "string",
86
125
  "description": "Entity name"
126
+ },
127
+ "rel": {
128
+ "type": "string",
129
+ "description": "Optional relation type filter"
130
+ },
131
+ "dir": {
132
+ "type": "string",
133
+ "description": "Relation direction filter",
134
+ "enum": ["incoming", "outgoing", "both"]
135
+ },
136
+ "path_to": {
137
+ "type": "string",
138
+ "description": "Find path from entity to this target entity"
139
+ },
140
+ "max_depth": {
141
+ "type": "integer",
142
+ "description": "Path query max depth (2~4)"
87
143
  }
88
144
  },
89
145
  "required": ["entity"],
@@ -177,7 +233,7 @@
177
233
  "apiUrl": {
178
234
  "type": "string",
179
235
  "description": "URL of the memory service API",
180
- "default": "http://127.0.0.1:8765"
236
+ "default": "http://localhost:8765"
181
237
  },
182
238
  "engineMode": {
183
239
  "type": "string",
@@ -199,6 +255,11 @@
199
255
  "description": "Automatically trigger reflection periodically",
200
256
  "default": false
201
257
  },
258
+ "autoReflectIntervalMinutes": {
259
+ "type": "integer",
260
+ "description": "Auto reflection scan interval in minutes",
261
+ "default": 30
262
+ },
202
263
  "embedding": {
203
264
  "type": "object",
204
265
  "description": "Embedding model configuration",
@@ -226,8 +287,19 @@
226
287
  "dimensions": {
227
288
  "type": "integer",
228
289
  "description": "Embedding dimensions"
290
+ },
291
+ "timeoutMs": {
292
+ "type": "integer",
293
+ "description": "Embedding request timeout in milliseconds",
294
+ "default": 20000
295
+ },
296
+ "maxRetries": {
297
+ "type": "integer",
298
+ "description": "Maximum retry attempts for embedding requests",
299
+ "default": 4
229
300
  }
230
301
  },
302
+ "required": ["provider", "model", "apiKey", "baseURL"],
231
303
  "additionalProperties": false
232
304
  },
233
305
  "llm": {
@@ -255,6 +327,7 @@
255
327
  "description": "LLM API base URL (camelCase alias)"
256
328
  }
257
329
  },
330
+ "required": ["provider", "model", "apiKey", "baseURL"],
258
331
  "additionalProperties": false
259
332
  },
260
333
  "reranker": {
@@ -282,12 +355,91 @@
282
355
  "description": "Reranker API base URL (camelCase alias)"
283
356
  }
284
357
  },
358
+ "required": ["provider", "model", "apiKey", "baseURL"],
285
359
  "additionalProperties": false
286
360
  },
287
361
  "fallbackToBuiltin": {
288
362
  "type": "boolean",
289
363
  "description": "Fallback to OpenClaw builtin memory when Cortex Memory fails",
290
364
  "default": true
365
+ },
366
+ "readFusion": {
367
+ "type": "object",
368
+ "description": "Post-rerank LLM fusion for multi-route retrieval results",
369
+ "properties": {
370
+ "enabled": {
371
+ "type": "boolean",
372
+ "description": "Enable LLM fusion after rerank",
373
+ "default": true
374
+ },
375
+ "maxCandidates": {
376
+ "type": "integer",
377
+ "description": "Maximum reranked candidates used for fusion",
378
+ "default": 10
379
+ },
380
+ "authoritative": {
381
+ "type": "boolean",
382
+ "description": "Return only fused authoritative memory package to agent",
383
+ "default": true
384
+ }
385
+ },
386
+ "additionalProperties": false
387
+ },
388
+ "memoryDecay": {
389
+ "type": "object",
390
+ "description": "Time-decay controls for retrieval ranking by event_type",
391
+ "properties": {
392
+ "enabled": {
393
+ "type": "boolean",
394
+ "description": "Enable event-type half-life decay in retrieval ranking",
395
+ "default": true
396
+ },
397
+ "minFloor": {
398
+ "type": "number",
399
+ "description": "Minimum decay factor floor in [0,1]",
400
+ "default": 0.15
401
+ },
402
+ "defaultHalfLifeDays": {
403
+ "type": "number",
404
+ "description": "Default half-life in days for unconfigured event types",
405
+ "default": 90
406
+ },
407
+ "halfLifeByEventType": {
408
+ "type": "object",
409
+ "description": "Half-life days overrides by event_type",
410
+ "additionalProperties": {
411
+ "type": "number"
412
+ }
413
+ },
414
+ "antiDecay": {
415
+ "type": "object",
416
+ "description": "Hit-frequency anti-decay controls",
417
+ "properties": {
418
+ "enabled": {
419
+ "type": "boolean",
420
+ "description": "Enable anti-decay boost for frequently hit memories",
421
+ "default": true
422
+ },
423
+ "maxBoost": {
424
+ "type": "number",
425
+ "description": "Maximum multiplicative anti-decay boost (>=1)",
426
+ "default": 1.6
427
+ },
428
+ "hitWeight": {
429
+ "type": "number",
430
+ "description": "Hit count to boost conversion weight",
431
+ "default": 0.08
432
+ },
433
+ "recentWindowDays": {
434
+ "type": "number",
435
+ "description": "Recent hit window in days for freshness contribution",
436
+ "default": 30
437
+ }
438
+ },
439
+ "additionalProperties": false
440
+ }
441
+ },
442
+ "additionalProperties": false
291
443
  }
292
444
  },
293
445
  "additionalProperties": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-cortex-memory",
3
- "version": "0.1.0-Alpha.2",
3
+ "version": "0.1.0-Alpha.20",
4
4
  "description": "Long-term memory system for OpenClaw AI Agent",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,9 +9,17 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsc && node -e \"require('fs').copyFileSync('openclaw.plugin.json','dist/openclaw.plugin.json')\"",
12
+ "typecheck": "tsc --noEmit",
13
+ "check:version": "node scripts/check-version.js",
14
+ "test:compat": "node scripts/compat-regression.js",
15
+ "test:model": "node scripts/model-regression.js",
16
+ "test:graph": "node scripts/graph-eval.js",
17
+ "test:lengthnorm": "node scripts/lengthnorm-regression.js",
18
+ "test:all": "npm run test:compat && npm run test:model && npm run test:graph && npm run test:lengthnorm",
19
+ "release:check": "node scripts/release-pipeline.js",
12
20
  "dev": "tsc --watch",
13
- "prepublishOnly": "npm run build",
14
- "postinstall": "node scripts/install.js"
21
+ "prepack": "npm run build",
22
+ "prepublishOnly": "npm run check:version && npm run build && npm run test:all"
15
23
  },
16
24
  "keywords": [
17
25
  "openclaw",
@@ -20,11 +28,14 @@
20
28
  "agent",
21
29
  "rag"
22
30
  ],
23
- "author": "",
31
+ "author": "deki18",
24
32
  "license": "MIT",
25
33
  "dependencies": {
26
34
  "undici": "^6.21.0"
27
35
  },
36
+ "optionalDependencies": {
37
+ "@lancedb/lancedb": "^0.22.0"
38
+ },
28
39
  "devDependencies": {
29
40
  "@types/node": "^22.19.15",
30
41
  "typescript": "^5.7.2"
@@ -37,9 +48,7 @@
37
48
  },
38
49
  "files": [
39
50
  "dist/",
40
- "index.ts",
41
51
  "scripts/cli.js",
42
- "scripts/install.js",
43
52
  "scripts/uninstall.js",
44
53
  "openclaw.plugin.json",
45
54
  "SKILL.md"
@@ -48,6 +57,12 @@
48
57
  "plugin": true,
49
58
  "requiresPython": false,
50
59
  "cli": "cortex-memory",
60
+ "build": {
61
+ "openclawVersion": "2026.3.22"
62
+ },
63
+ "compat": {
64
+ "pluginApi": ">=2026.3.22"
65
+ },
51
66
  "extensions": [
52
67
  "./dist/index.js"
53
68
  ]
package/scripts/cli.js CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
- const { spawn } = require('child_process');
6
5
 
7
6
  const PLUGIN_NAME = 'openclaw-cortex-memory';
8
7
 
9
8
  function findOpenClawConfig() {
10
9
  const explicitConfigPath = process.env.OPENCLAW_CONFIG_PATH || '';
10
+ const stateDir = process.env.OPENCLAW_STATE_DIR || '';
11
11
  const basePath = process.env.OPENCLAW_BASE_PATH || '';
12
12
  const homePath = process.env.USERPROFILE || process.env.HOME || '';
13
13
  const possiblePaths = [
14
14
  explicitConfigPath,
15
+ stateDir ? path.join(stateDir, 'openclaw.json') : '',
15
16
  basePath ? path.join(basePath, 'openclaw.json') : '',
16
17
  path.join(process.cwd(), 'openclaw.json'),
17
18
  homePath ? path.join(homePath, '.openclaw', 'openclaw.json') : '',
@@ -53,7 +54,10 @@ function enablePlugin() {
53
54
  const configPath = findOpenClawConfig();
54
55
 
55
56
  if (!configPath) {
56
- const defaultPath = path.join(process.env.USERPROFILE || process.env.HOME || '', '.openclaw', 'openclaw.json');
57
+ const defaultPath = process.env.OPENCLAW_CONFIG_PATH
58
+ || (process.env.OPENCLAW_STATE_DIR ? path.join(process.env.OPENCLAW_STATE_DIR, 'openclaw.json') : '')
59
+ || (process.env.OPENCLAW_BASE_PATH ? path.join(process.env.OPENCLAW_BASE_PATH, 'openclaw.json') : '')
60
+ || path.join(process.env.USERPROFILE || process.env.HOME || '', '.openclaw', 'openclaw.json');
57
61
  console.log(`No config file found. Creating: ${defaultPath}`);
58
62
 
59
63
  const config = {
@@ -170,21 +174,22 @@ function getStatus() {
170
174
  }
171
175
 
172
176
  function runUninstall(args) {
173
- const uninstallScript = path.join(__dirname, 'uninstall.js');
174
-
175
- if (!fs.existsSync(uninstallScript)) {
177
+ const uninstallScriptPath = path.join(__dirname, 'uninstall.js');
178
+ if (!fs.existsSync(uninstallScriptPath)) {
176
179
  console.error('Uninstall script not found.');
177
180
  process.exit(1);
178
181
  }
179
-
180
- const child = spawn(process.execPath, [uninstallScript, 'uninstall', ...args], {
181
- stdio: 'inherit',
182
- cwd: process.cwd()
183
- });
184
-
185
- child.on('exit', (code) => {
186
- process.exit(code || 0);
187
- });
182
+ try {
183
+ const uninstallModule = require(uninstallScriptPath);
184
+ if (!uninstallModule || typeof uninstallModule.uninstall !== 'function') {
185
+ console.error('Invalid uninstall script export.');
186
+ process.exit(1);
187
+ }
188
+ uninstallModule.uninstall(args);
189
+ } catch (error) {
190
+ console.error(`Failed to run uninstall: ${error instanceof Error ? error.message : String(error)}`);
191
+ process.exit(1);
192
+ }
188
193
  }
189
194
 
190
195
  function showHelp() {
@@ -17,14 +17,20 @@ function findProjectRoot() {
17
17
  }
18
18
 
19
19
  function findOpenClawConfig() {
20
+ const explicitConfigPath = process.env.OPENCLAW_CONFIG_PATH || '';
21
+ const stateDir = process.env.OPENCLAW_STATE_DIR || '';
22
+ const basePath = process.env.OPENCLAW_BASE_PATH || '';
23
+ const homePath = process.env.USERPROFILE || process.env.HOME || '';
20
24
  const possiblePaths = [
25
+ explicitConfigPath,
26
+ stateDir ? path.join(stateDir, 'openclaw.json') : '',
27
+ basePath ? path.join(basePath, 'openclaw.json') : '',
21
28
  path.join(process.cwd(), 'openclaw.json'),
22
- path.join(process.env.USERPROFILE || process.env.HOME || '', '.openclaw', 'openclaw.json'),
23
- path.join(process.env.OPENCLAW_BASE_PATH || '', 'openclaw.json'),
29
+ homePath ? path.join(homePath, '.openclaw', 'openclaw.json') : '',
24
30
  ];
25
31
 
26
32
  for (const p of possiblePaths) {
27
- if (fs.existsSync(p)) {
33
+ if (p && fs.existsSync(p)) {
28
34
  return p;
29
35
  }
30
36
  }
@@ -114,15 +120,20 @@ function removeFromConfig() {
114
120
  const content = fs.readFileSync(configPath, 'utf-8');
115
121
  const config = JSON.parse(content);
116
122
 
123
+ if (Array.isArray(config.plugins?.allow)) {
124
+ config.plugins.allow = config.plugins.allow.filter((item) => item !== PLUGIN_NAME);
125
+ }
117
126
  if (config.plugins?.entries?.[PLUGIN_NAME]) {
118
127
  delete config.plugins.entries[PLUGIN_NAME];
119
-
120
128
  if (config.plugins.slots?.memory === PLUGIN_NAME) {
121
129
  delete config.plugins.slots.memory;
122
130
  }
123
131
 
124
132
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
125
133
  console.log(`Removed plugin from config: ${configPath}`);
134
+ } else if (Array.isArray(config.plugins?.allow)) {
135
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
136
+ console.log(`Removed plugin allowlist entry from config: ${configPath}`);
126
137
  } else {
127
138
  console.log('Plugin not found in config.');
128
139
  }
@@ -209,4 +220,10 @@ function main() {
209
220
  }
210
221
  }
211
222
 
212
- main();
223
+ module.exports = {
224
+ uninstall,
225
+ };
226
+
227
+ if (require.main === module) {
228
+ main();
229
+ }