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

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/README.md CHANGED
@@ -23,36 +23,37 @@ OpenClaw 长期记忆插件,提供跨会话检索、事件存储、规则反
23
23
 
24
24
  ### 安装步骤
25
25
 
26
- 快速安装(推荐,npm 发布版):
26
+ 快速安装(推荐,显式来源):
27
27
 
28
28
  ```bash
29
29
  cd ~/openclaw
30
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
30
+ pnpm openclaw plugins install clawhub:openclaw-cortex-memory
31
31
  pnpm openclaw plugins enable openclaw-cortex-memory
32
- pnpm openclaw gateway restart
33
32
  ```
34
33
 
35
- 后续更新:
34
+ npm 安装方式:
36
35
 
37
36
  ```bash
38
37
  cd ~/openclaw
39
38
  pnpm openclaw plugins install openclaw-cortex-memory@alpha
40
- pnpm openclaw gateway restart
39
+ pnpm openclaw plugins enable openclaw-cortex-memory
41
40
  ```
42
41
 
43
- 安装前如果 `openclaw.json` 已经提前写了 `allow/slots/entries` 指向本插件,先临时移除,安装后再加回,避免安装前校验报 `plugin not found`。
44
-
45
- ### 本地打包安装(源码模式)
42
+ 后续更新:
46
43
 
47
44
  ```bash
48
- git clone https://github.com/deki18/openclaw-cortex-memory.git ~/openclaw-cortex-memory-src
49
- cd ~/openclaw-cortex-memory-src
50
- npm install && npm run build && npm pack
51
45
  cd ~/openclaw
52
- pnpm openclaw plugins install ~/openclaw-cortex-memory-src/openclaw-cortex-memory-0.1.0-Alpha.1.tgz
53
- pnpm openclaw gateway restart
46
+ pnpm openclaw plugins uninstall openclaw-cortex-memory
47
+ pnpm openclaw plugins install clawhub:openclaw-cortex-memory
48
+ pnpm openclaw plugins enable openclaw-cortex-memory
54
49
  ```
55
50
 
51
+ 说明:
52
+ - 推荐显式安装来源,减少 ClawHub-first 时代的来源歧义。
53
+ - 使用 `plugins install` 的安装记录方式,避免 `loaded without install/load-path provenance`。
54
+ - 保持 `plugins.allow` 显式包含 `openclaw-cortex-memory`,避免运行时把插件判定为未绑定信任源。
55
+
56
+
56
57
  ### 本地开发模式(无安装记录)
57
58
 
58
59
  ```bash
@@ -71,6 +72,7 @@ npm install
71
72
  ```json
72
73
  {
73
74
  "plugins": {
75
+ "allow": ["openclaw-cortex-memory"],
74
76
  "slots": { "memory": "openclaw-cortex-memory" },
75
77
  "entries": {
76
78
  "openclaw-cortex-memory": {
@@ -194,10 +196,12 @@ npx cortex-memory help # 查看命令帮助
194
196
 
195
197
  ## 注意事项
196
198
 
197
- 1. **API Key 安全**:使用环境变量 `${OPENAI_API_KEY}` 而非硬编码
199
+ 1. **API Key 安全**:使用 `${EMBEDDING_API_KEY}`、`${LLM_API_KEY}`、`${RERANKER_API_KEY}` 等环境变量而非硬编码
198
200
  2. **向量维度**:必须与嵌入模型匹配,如 `text-embedding-3-large` 为 3072
199
201
  3. **重排序**:可选配置 `reranker` 以提升检索精度
200
- 4. **单栈运行**:当前版本为纯 TS,无 Python 运行时依赖
202
+ 4. **外部传输**:检索与反思会调用你配置的 embedding/llm/reranker endpoint,请使用可信服务并最小化密钥权限
203
+ 5. **会话数据**:启用 `autoSync` 时会读取 OpenClaw 会话文件并写入本地记忆目录,生产环境建议先小范围验证
204
+ 6. **单栈运行**:当前版本为纯 TS,无 Python 运行时依赖
201
205
 
202
206
  ## 许可证
203
207
 
package/SKILL.md CHANGED
@@ -8,9 +8,9 @@ metadata:
8
8
  "emoji": "🧠",
9
9
  "os": ["darwin", "linux", "win32"],
10
10
  "requires": {
11
- "env": ["OPENAI_API_KEY"]
11
+ "env": ["EMBEDDING_API_KEY", "LLM_API_KEY", "RERANKER_API_KEY"]
12
12
  },
13
- "primaryEnv": "OPENAI_API_KEY"
13
+ "primaryEnv": "EMBEDDING_API_KEY"
14
14
  }
15
15
  }
16
16
  ---
@@ -36,7 +36,16 @@ metadata:
36
36
 
37
37
  ### 安装
38
38
 
39
- 快速安装(推荐,npm 发布版):
39
+ 快速安装(推荐,显式来源):
40
+
41
+ ```bash
42
+ cd ~/openclaw
43
+ pnpm openclaw plugins install clawhub:openclaw-cortex-memory
44
+ pnpm openclaw plugins enable openclaw-cortex-memory
45
+ pnpm openclaw gateway restart
46
+ ```
47
+
48
+ 若尚未在 ClawHub 发布,使用 npm 回退安装:
40
49
 
41
50
  ```bash
42
51
  cd ~/openclaw
@@ -49,11 +58,16 @@ pnpm openclaw gateway restart
49
58
 
50
59
  ```bash
51
60
  cd ~/openclaw
52
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
61
+ pnpm openclaw plugins uninstall openclaw-cortex-memory
62
+ pnpm openclaw plugins install clawhub:openclaw-cortex-memory
63
+ pnpm openclaw plugins enable openclaw-cortex-memory
53
64
  pnpm openclaw gateway restart
54
65
  ```
55
66
 
56
- 安装前如果 `openclaw.json` 已经提前写了 `allow/slots/entries` 指向本插件,先临时移除,安装后再加回,避免安装前校验报 `plugin not found`。
67
+ 说明:
68
+ - 推荐显式安装来源,减少 ClawHub-first 时代的来源歧义。
69
+ - 使用 `plugins install` 的安装记录方式,避免 `loaded without install/load-path provenance`。
70
+ - 保持 `plugins.allow` 显式包含 `openclaw-cortex-memory`,避免运行时把插件判定为未绑定信任源。
57
71
 
58
72
  ### 本地打包安装(源码模式)
59
73
 
@@ -62,7 +76,7 @@ git clone https://github.com/deki18/openclaw-cortex-memory.git ~/openclaw-cortex
62
76
  cd ~/openclaw-cortex-memory-src
63
77
  npm install && npm run build && npm pack
64
78
  cd ~/openclaw
65
- pnpm openclaw plugins install ~/openclaw-cortex-memory-src/openclaw-cortex-memory-0.1.0-Alpha.1.tgz
79
+ pnpm openclaw plugins install ~/openclaw-cortex-memory-src/openclaw-cortex-memory-0.1.0-Alpha.4.tgz
66
80
  pnpm openclaw gateway restart
67
81
  ```
68
82
 
@@ -82,6 +96,7 @@ npm install
82
96
  ```json
83
97
  {
84
98
  "plugins": {
99
+ "allow": ["openclaw-cortex-memory"],
85
100
  "slots": { "memory": "openclaw-cortex-memory" },
86
101
  "entries": {
87
102
  "openclaw-cortex-memory": {
@@ -265,4 +280,4 @@ openclaw gateway restart
265
280
  ## 依赖
266
281
 
267
282
  - Node.js >= 22
268
- - OPENAI_API_KEY(或兼容 API 配置)
283
+ - EMBEDDING_API_KEY、LLM_API_KEY、RERANKER_API_KEY(或兼容 API 配置)
package/dist/index.d.ts CHANGED
@@ -64,10 +64,7 @@ interface OpenClawPluginApi {
64
64
  args?: Record<string, unknown>;
65
65
  context: ToolContext;
66
66
  }) => Promise<ToolResult>;
67
- handler?: (params: {
68
- args?: Record<string, unknown>;
69
- context: ToolContext;
70
- }) => Promise<ToolResult>;
67
+ handler?: (...params: unknown[]) => Promise<ToolResult>;
71
68
  }): void;
72
69
  unregisterTool?(name: string): void;
73
70
  registerHook(hook: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACj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,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACpI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACrG,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,SAAS,CAAC,IAAI,MAAM,CAAC;IACrB,gBAAgB,CAAC,IAAI,aAAa,CAAC;CACpC;AAuwDD,wBAAsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CA2B5C;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CA2B7C;AAiED,wBAAgB,SAAS,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CAKzE;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAkChD;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,iBAAiB,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI,CA6GrG"}
package/dist/index.js CHANGED
@@ -96,6 +96,7 @@ const defaultConfig = {
96
96
  let autoSearchCacheBySession = new Map();
97
97
  const AUTO_SEARCH_CACHE_TTL = 60000;
98
98
  const MAX_AUTO_SEARCH_CACHE_SESSIONS = 200;
99
+ const HOOK_GUARD_TIMEOUT_MS = 2000;
99
100
  let config = null;
100
101
  let logger;
101
102
  let pythonProcess = null;
@@ -150,6 +151,33 @@ function getSessionCachedAutoSearch(sessionId) {
150
151
  ageSeconds: Math.floor((Date.now() - cache.timestamp) / 1000),
151
152
  };
152
153
  }
154
+ function isInternalSession(sessionId) {
155
+ if (!sessionId)
156
+ return false;
157
+ return sessionId.startsWith("slug-generator-") || sessionId.startsWith("fallback:");
158
+ }
159
+ async function runWithTimeout(task, timeoutMs, label) {
160
+ let timeoutHandle = null;
161
+ try {
162
+ const timeoutPromise = new Promise((resolve) => {
163
+ timeoutHandle = setTimeout(() => resolve(null), timeoutMs);
164
+ });
165
+ const result = await Promise.race([task, timeoutPromise]);
166
+ if (result === null) {
167
+ logger.warn(`${label} timed out after ${timeoutMs}ms; skipped to protect gateway responsiveness`);
168
+ }
169
+ return result;
170
+ }
171
+ catch (error) {
172
+ logger.warn(`${label} failed: ${error instanceof Error ? error.message : String(error)}`);
173
+ return null;
174
+ }
175
+ finally {
176
+ if (timeoutHandle) {
177
+ clearTimeout(timeoutHandle);
178
+ }
179
+ }
180
+ }
153
181
  function resolveEngine() {
154
182
  if (!config) {
155
183
  throw new Error("Configuration not loaded");
@@ -164,11 +192,14 @@ function resolveEngine() {
164
192
  projectRoot,
165
193
  dbPath: config.dbPath,
166
194
  logger,
195
+ embedding: config.embedding,
196
+ reranker: config.reranker,
167
197
  });
168
198
  const writeStore = (0, write_store_1.createWriteStore)({
169
199
  projectRoot,
170
200
  dbPath: config.dbPath,
171
201
  logger,
202
+ embedding: config.embedding,
172
203
  });
173
204
  const sessionSync = (0, session_sync_1.createSessionSync)({
174
205
  projectRoot,
@@ -192,6 +223,7 @@ function resolveEngine() {
192
223
  dbPath: config.dbPath,
193
224
  logger,
194
225
  ruleStore,
226
+ llm: config.llm,
195
227
  });
196
228
  memoryEngine = (0, ts_engine_1.createTsEngine)({
197
229
  readStore,
@@ -257,6 +289,15 @@ function sanitizeForLogging(obj) {
257
289
  }
258
290
  return sanitized;
259
291
  }
292
+ function logLifecycle(event, details = {}) {
293
+ const payload = sanitizeForLogging({
294
+ event,
295
+ plugin: PLUGIN_ID,
296
+ ts: new Date().toISOString(),
297
+ ...details,
298
+ });
299
+ logger.info(`[Lifecycle] ${JSON.stringify(payload)}`);
300
+ }
260
301
  function asRecord(value) {
261
302
  if (typeof value === "object" && value !== null) {
262
303
  return value;
@@ -415,13 +456,19 @@ function findProjectRoot() {
415
456
  throw new Error("Cannot find project root directory");
416
457
  }
417
458
  function findOpenClawConfig() {
459
+ const explicitConfigPath = process.env.OPENCLAW_CONFIG_PATH || "";
460
+ const stateDir = process.env.OPENCLAW_STATE_DIR || "";
461
+ const basePath = process.env.OPENCLAW_BASE_PATH || "";
462
+ const homePath = process.env.USERPROFILE || process.env.HOME || "";
418
463
  const possiblePaths = [
464
+ explicitConfigPath,
465
+ stateDir ? path.join(stateDir, "openclaw.json") : "",
466
+ basePath ? path.join(basePath, "openclaw.json") : "",
419
467
  path.join(process.cwd(), "openclaw.json"),
420
- path.join(process.env.USERPROFILE || process.env.HOME || "", ".openclaw", "openclaw.json"),
421
- path.join(process.env.OPENCLAW_BASE_PATH || "", "openclaw.json"),
468
+ homePath ? path.join(homePath, ".openclaw", "openclaw.json") : "",
422
469
  ];
423
470
  for (const p of possiblePaths) {
424
- if (fs.existsSync(p)) {
471
+ if (p && fs.existsSync(p)) {
425
472
  return p;
426
473
  }
427
474
  }
@@ -1365,10 +1412,18 @@ async function onTimerPythonHandler(payload, _context) {
1365
1412
  }
1366
1413
  }
1367
1414
  async function onMessageHandler(payload, context) {
1368
- await resolveEngine().onMessage(payload, context);
1415
+ const sessionId = resolveSessionId(context, payload);
1416
+ if (isInternalSession(sessionId)) {
1417
+ return;
1418
+ }
1419
+ await runWithTimeout(resolveEngine().onMessage(payload, context), HOOK_GUARD_TIMEOUT_MS, "onMessage hook");
1369
1420
  }
1370
1421
  async function onSessionEndHandler(payload, context) {
1371
- await resolveEngine().onSessionEnd(payload, context);
1422
+ const sessionId = resolveSessionId(context, payload);
1423
+ if (isInternalSession(sessionId)) {
1424
+ return;
1425
+ }
1426
+ await runWithTimeout(resolveEngine().onSessionEnd(payload, context), HOOK_GUARD_TIMEOUT_MS, "onSessionEnd hook");
1372
1427
  }
1373
1428
  async function onTimerHandler(payload, context) {
1374
1429
  await resolveEngine().onTimer(payload, context);
@@ -1536,13 +1591,30 @@ function registerTools() {
1536
1591
  function registerToolCompat(tool) {
1537
1592
  if (!api)
1538
1593
  return;
1539
- const execute = async (params) => tool.execute({ args: params?.args || {}, context: params.context });
1594
+ const execute = async (params) => tool.execute({
1595
+ args: params?.args || {},
1596
+ context: params.context,
1597
+ });
1598
+ const handler = async (...params) => {
1599
+ const first = params[0];
1600
+ const second = params[1];
1601
+ if (first && typeof first === "object" && "context" in first) {
1602
+ return execute({
1603
+ args: first.args || {},
1604
+ context: first.context,
1605
+ });
1606
+ }
1607
+ return execute({
1608
+ args: first || {},
1609
+ context: (second || {}),
1610
+ });
1611
+ };
1540
1612
  api.registerTool({
1541
1613
  name: tool.name,
1542
1614
  description: tool.description,
1543
1615
  parameters: tool.parameters,
1544
1616
  execute,
1545
- handler: execute,
1617
+ handler,
1546
1618
  });
1547
1619
  }
1548
1620
  function unregisterTools() {
@@ -1649,6 +1721,7 @@ async function enable() {
1649
1721
  return;
1650
1722
  }
1651
1723
  logger.info("Enabling Cortex Memory plugin...");
1724
+ logLifecycle("enable_start");
1652
1725
  try {
1653
1726
  unregisterFallbackTools();
1654
1727
  if (shouldUsePythonRuntime()) {
@@ -1660,10 +1733,12 @@ async function enable() {
1660
1733
  registerHooks();
1661
1734
  startAutoReflectScheduler();
1662
1735
  logger.info("Cortex Memory plugin enabled successfully");
1736
+ logLifecycle("enable_success", { registeredTools: registeredTools.length, registeredHooks: registeredHooks.length });
1663
1737
  }
1664
1738
  catch (error) {
1665
1739
  const message = error instanceof Error ? error.message : String(error);
1666
1740
  logger.error(`Failed to enable Cortex Memory plugin: ${message}`);
1741
+ logLifecycle("enable_failed", { error: message });
1667
1742
  throw error;
1668
1743
  }
1669
1744
  }
@@ -1673,6 +1748,7 @@ async function disable() {
1673
1748
  return;
1674
1749
  }
1675
1750
  logger.info("Disabling Cortex Memory plugin...");
1751
+ logLifecycle("disable_start");
1676
1752
  unregisterHooks();
1677
1753
  unregisterTools();
1678
1754
  unregisterFallbackTools();
@@ -1685,8 +1761,10 @@ async function disable() {
1685
1761
  if (config?.fallbackToBuiltin && builtinMemory) {
1686
1762
  logger.info("Falling back to OpenClaw builtin memory system");
1687
1763
  registerFallbackTools();
1764
+ logLifecycle("fallback_enabled", { fallbackTools: registeredFallbackTools.length });
1688
1765
  }
1689
1766
  logger.info("Cortex Memory plugin disabled successfully");
1767
+ logLifecycle("disable_success", { fallbackEnabled: registeredFallbackTools.length > 0 });
1690
1768
  }
1691
1769
  function registerFallbackTools() {
1692
1770
  if (!api || !builtinMemory)
@@ -1754,6 +1832,7 @@ function getStatus() {
1754
1832
  }
1755
1833
  async function unregister() {
1756
1834
  logger.info("Unregistering Cortex Memory plugin...");
1835
+ logLifecycle("unregister_start");
1757
1836
  stopConfigWatcher();
1758
1837
  stopAutoReflectScheduler();
1759
1838
  unregisterHooks();
@@ -1780,6 +1859,7 @@ async function unregister() {
1780
1859
  stopAutoReflectScheduler();
1781
1860
  configPath = null;
1782
1861
  logger.info("Cortex Memory plugin unregistered successfully");
1862
+ logLifecycle("unregister_success");
1783
1863
  }
1784
1864
  function register(pluginApi, userConfig) {
1785
1865
  if (isInitializing || isRegistered) {
@@ -1852,6 +1932,11 @@ function register(pluginApi, userConfig) {
1852
1932
  isRegistered = true;
1853
1933
  logger.info("Cortex Memory plugin registered successfully");
1854
1934
  logger.info(`Cortex Memory engine mode: ${resolveEngine().mode}`);
1935
+ logLifecycle("register_success", {
1936
+ engineMode: config.engineMode,
1937
+ enabled: isEnabled,
1938
+ hasBuiltinFallback: Boolean(builtinMemory),
1939
+ });
1855
1940
  if (isEnabled) {
1856
1941
  registerTools();
1857
1942
  registerHooks();
@@ -1865,11 +1950,13 @@ function register(pluginApi, userConfig) {
1865
1950
  logger.info("Falling back to builtin memory");
1866
1951
  isEnabled = false;
1867
1952
  registerFallbackTools();
1953
+ logLifecycle("fallback_after_init_error", { fallbackTools: registeredFallbackTools.length, error: message });
1868
1954
  }
1869
1955
  });
1870
1956
  }
1871
1957
  else if (config?.fallbackToBuiltin && builtinMemory) {
1872
1958
  registerFallbackTools();
1959
+ logLifecycle("fallback_registered_on_start", { fallbackTools: registeredFallbackTools.length });
1873
1960
  }
1874
1961
  }
1875
1962
  async function initializeAsync() {