@ubundi/openclaw-cortex 0.3.3 → 0.3.5
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/LICENSE +1 -1
- package/README.md +54 -13
- package/dist/core/plugin.d.ts.map +1 -1
- package/dist/core/plugin.js +37 -23
- package/dist/core/plugin.js.map +1 -1
- package/dist/features/sync/watcher.d.ts +2 -0
- package/dist/features/sync/watcher.d.ts.map +1 -1
- package/dist/features/sync/watcher.js +36 -38
- package/dist/features/sync/watcher.js.map +1 -1
- package/dist/shared/queue/retry-queue.d.ts +4 -1
- package/dist/shared/queue/retry-queue.d.ts.map +1 -1
- package/dist/shared/queue/retry-queue.js +62 -31
- package/dist/shared/queue/retry-queue.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# @ubundi/openclaw-cortex
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@ubundi/openclaw-cortex)
|
|
4
|
+
[](https://github.com/Ubundi/openclaw-cortex/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
3
7
|

|
|
4
8
|
|
|
5
|
-
OpenClaw plugin for [Cortex](https://github.com/ubundi/cortex) long-term memory. Gives your agent persistent memory that survives across sessions — who you are, what your project does, decisions you made weeks ago, and how things changed over time.
|
|
9
|
+
[OpenClaw](https://github.com/openclaw/openclaw) plugin for [Cortex](https://github.com/ubundi/cortex) long-term memory. Gives your agent persistent memory that survives across sessions — who you are, what your project does, decisions you made weeks ago, and how things changed over time.
|
|
6
10
|
|
|
7
11
|
- **Auto-Recall** — injects relevant memories before every agent turn via `before_agent_start` hook
|
|
8
12
|
- **Auto-Capture** — extracts facts from conversations via `agent_end` hook
|
|
@@ -10,6 +14,14 @@ OpenClaw plugin for [Cortex](https://github.com/ubundi/cortex) long-term memory.
|
|
|
10
14
|
- **Periodic Reflect** — consolidates memories, resolves SUPERSEDES chains, detects contradictions
|
|
11
15
|
- **Resilience** — retry queue with exponential backoff, cold-start detection, latency metrics
|
|
12
16
|
|
|
17
|
+
> **Cortex availability:** Cortex is currently privately hosted and in early testing — it is not yet a public service. API keys are not self-serve; to request access email [matthew@ubundi.co.za](mailto:matthew@ubundi.co.za). A public sign-up is planned for the future.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js `>=20`
|
|
22
|
+
- [OpenClaw](https://github.com/openclaw/openclaw) with plugin support (`openclaw` peer dependency is `>=0.1.0`)
|
|
23
|
+
- Cortex API key — available on request (see availability note above)
|
|
24
|
+
|
|
13
25
|
## Installation
|
|
14
26
|
|
|
15
27
|
```bash
|
|
@@ -22,6 +34,36 @@ Or link locally for development:
|
|
|
22
34
|
openclaw plugins install -l ./path/to/openclaw-cortex
|
|
23
35
|
```
|
|
24
36
|
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
1. Install the plugin:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
openclaw plugins install @ubundi/openclaw-cortex
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. Add a minimal plugin config to `openclaw.json`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"plugins": {
|
|
50
|
+
"entries": {
|
|
51
|
+
"@ubundi/openclaw-cortex": {
|
|
52
|
+
"enabled": true,
|
|
53
|
+
"config": {
|
|
54
|
+
"apiKey": "${CORTEX_API_KEY}"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"slots": {
|
|
59
|
+
"memory": "@ubundi/openclaw-cortex"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
3. Run an agent turn. If configured correctly, recall data is prepended in a `<cortex_memories>` block before the model turn.
|
|
66
|
+
|
|
25
67
|
## Configuration
|
|
26
68
|
|
|
27
69
|
Add to your `openclaw.json`:
|
|
@@ -34,6 +76,7 @@ Add to your `openclaw.json`:
|
|
|
34
76
|
enabled: true,
|
|
35
77
|
config: {
|
|
36
78
|
apiKey: "sk-cortex-...",
|
|
79
|
+
// Cortex hosted API endpoint — provided with your API key. Omit to use the default.
|
|
37
80
|
baseUrl: "https://q5p64iw9c9.execute-api.us-east-1.amazonaws.com/prod",
|
|
38
81
|
autoRecall: true,
|
|
39
82
|
autoCapture: true,
|
|
@@ -67,17 +110,8 @@ Environment variables are supported via `${VAR_NAME}` syntax:
|
|
|
67
110
|
| Option | Type | Default | Description |
|
|
68
111
|
|---|---|---|---|
|
|
69
112
|
| `apiKey` | string | _required_ | Cortex API key |
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
| `autoCapture` | boolean | `true` | Extract facts after agent responses |
|
|
73
|
-
| `recallTopK` | number | `5` | Number of memories to retrieve per turn |
|
|
74
|
-
| `recallTimeoutMs` | number | `500` | Max time to wait for recall (ms) |
|
|
75
|
-
| `recallMode` | string | `"fast"` | Retrieval depth: `fast`, `balanced`, or `full` |
|
|
76
|
-
| `fileSync` | boolean | `true` | Watch MEMORY.md and daily logs |
|
|
77
|
-
| `transcriptSync` | boolean | `true` | Watch and ingest session transcripts |
|
|
78
|
-
| `reflectIntervalMs` | number | `3600000` | Memory consolidation interval (ms). `0` to disable |
|
|
79
|
-
| `recallQueryType` | string | `"combined"` | Retrieval bias: `factual` (entities/facts), `emotional` (feelings/values), or `combined` |
|
|
80
|
-
| `namespace` | string | _(auto)_ | Memory namespace. Auto-derived from workspace directory; set explicitly to share memory across workspaces |
|
|
113
|
+
|
|
114
|
+
All other options are pre-configured with sensible defaults and can be tuned via the OpenClaw plugin config UI.
|
|
81
115
|
|
|
82
116
|
### Recall Modes
|
|
83
117
|
|
|
@@ -145,12 +179,19 @@ Use this to tune `recallTimeoutMs` and `recallMode` for your deployment.
|
|
|
145
179
|
|
|
146
180
|
If both this plugin and the Cortex SKILL.md are active, the `<cortex_memories>` tag in the prepended context signals to the skill that recall has already happened — the agent can skip manual `curl` calls.
|
|
147
181
|
|
|
182
|
+
## Troubleshooting
|
|
183
|
+
|
|
184
|
+
- `apiKey` errors on startup: confirm `config.apiKey` is set and `${CORTEX_API_KEY}` resolves in your environment.
|
|
185
|
+
- Plugin installed but no memory behavior: verify both `"enabled": true` and `"slots.memory": "@ubundi/openclaw-cortex"` in `openclaw.json`.
|
|
186
|
+
- Frequent recall timeouts: increase `recallTimeoutMs` and/or set `recallMode` to `"fast"`.
|
|
187
|
+
- No useful memories returned: ensure prior sessions were captured (`autoCapture`) or file sync is enabled (`fileSync`, `transcriptSync`).
|
|
188
|
+
|
|
148
189
|
## Development
|
|
149
190
|
|
|
150
191
|
```bash
|
|
151
192
|
npm install
|
|
152
193
|
npm run build # TypeScript → dist/
|
|
153
|
-
npm test # Run vitest (
|
|
194
|
+
npm test # Run vitest (150 tests)
|
|
154
195
|
npm run test:watch # Watch mode
|
|
155
196
|
npm run test:integration # Live Cortex API tests (requires CORTEX_API_KEY)
|
|
156
197
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/core/plugin.ts"],"names":[],"mappings":"AAuBA,UAAU,SAAS;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,MAAM,EAAE;QACN,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACjC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;KACjC,CAAC;IACF,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAA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AAC;QACjD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YAAE,YAAY,CAAC,EAAE,MAAM,CAAA;SAAE,KAAK,IAAI,CAAC;KACjD,GAAG,IAAI,CAAC;CACV;AAuCD,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBASI,SAAS;CA6GxB,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/core/plugin.js
CHANGED
|
@@ -29,6 +29,21 @@ function resolveConfigEnvVars(raw) {
|
|
|
29
29
|
}
|
|
30
30
|
return resolved;
|
|
31
31
|
}
|
|
32
|
+
async function bootstrapClient(client, logger) {
|
|
33
|
+
try {
|
|
34
|
+
const healthy = await client.healthCheck();
|
|
35
|
+
if (!healthy) {
|
|
36
|
+
logger.warn("Cortex health check failed — API may be unreachable");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
logger.info("Cortex health check passed");
|
|
40
|
+
const warmup = await client.warmup();
|
|
41
|
+
logger.info(`Cortex warmup: ${warmup.already_warm ? "already warm" : "initialized"} (tenant: ${warmup.tenant_id})`);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
logger.warn("Cortex warmup failed — first ingest may be slow");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
32
47
|
const plugin = {
|
|
33
48
|
id: "cortex-memory",
|
|
34
49
|
name: "Cortex Memory",
|
|
@@ -51,24 +66,13 @@ const plugin = {
|
|
|
51
66
|
// Whether the user explicitly set a namespace vs. relying on default
|
|
52
67
|
const userSetNamespace = raw.namespace != null;
|
|
53
68
|
let namespace = config.namespace;
|
|
69
|
+
let started = false;
|
|
70
|
+
let watcher = null;
|
|
71
|
+
let reflect = null;
|
|
54
72
|
api.logger.info(`Cortex plugin registered (recallMode=${config.recallMode}, namespace=${namespace})`);
|
|
55
73
|
// Async health check + warmup — validate connection and pre-init the tenant's
|
|
56
74
|
// Cortex instance so the first ingest doesn't pay the cold-start cost.
|
|
57
|
-
client.
|
|
58
|
-
if (ok) {
|
|
59
|
-
api.logger.info("Cortex health check passed");
|
|
60
|
-
return client.warmup();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
api.logger.warn("Cortex health check failed — API may be unreachable");
|
|
64
|
-
}
|
|
65
|
-
}).then((warmup) => {
|
|
66
|
-
if (warmup) {
|
|
67
|
-
api.logger.info(`Cortex warmup: ${warmup.already_warm ? "already warm" : "initialized"} (tenant: ${warmup.tenant_id})`);
|
|
68
|
-
}
|
|
69
|
-
}).catch(() => {
|
|
70
|
-
api.logger.warn("Cortex warmup failed — first ingest may be slow");
|
|
71
|
-
});
|
|
75
|
+
void bootstrapClient(client, api.logger);
|
|
72
76
|
// Auto-Recall: inject relevant memories before every agent turn
|
|
73
77
|
api.on("before_agent_start", createRecallHandler(client, config, api.logger, recallMetrics));
|
|
74
78
|
// Auto-Capture: extract facts after agent responses
|
|
@@ -77,6 +81,11 @@ const plugin = {
|
|
|
77
81
|
api.registerService({
|
|
78
82
|
id: "cortex-services",
|
|
79
83
|
start(ctx) {
|
|
84
|
+
if (started) {
|
|
85
|
+
api.logger.debug?.("Cortex services already started, skipping");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
started = true;
|
|
80
89
|
retryQueue.start();
|
|
81
90
|
// Derive workspace-scoped namespace when user didn't set one explicitly
|
|
82
91
|
if (!userSetNamespace && ctx.workspaceDir) {
|
|
@@ -90,24 +99,29 @@ const plugin = {
|
|
|
90
99
|
api.logger.warn("Cortex file sync: no workspaceDir, skipping");
|
|
91
100
|
}
|
|
92
101
|
else {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
const newWatcher = new FileSyncWatcher(workspaceDir, client, namespace, api.logger, retryQueue, { transcripts: config.transcriptSync });
|
|
103
|
+
newWatcher.start();
|
|
104
|
+
watcher = newWatcher;
|
|
96
105
|
api.logger.info("Cortex file sync started");
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
108
|
// Periodic reflect (memory consolidation)
|
|
100
109
|
if (config.reflectIntervalMs > 0) {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
const newReflect = new PeriodicReflect(client, api.logger, config.reflectIntervalMs);
|
|
111
|
+
newReflect.start();
|
|
112
|
+
reflect = newReflect;
|
|
104
113
|
api.logger.info(`Cortex periodic reflect started (every ${config.reflectIntervalMs / 1000}s)`);
|
|
105
114
|
}
|
|
106
115
|
api.logger.info("Cortex services started");
|
|
107
116
|
},
|
|
108
117
|
stop() {
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
if (!started)
|
|
119
|
+
return;
|
|
120
|
+
started = false;
|
|
121
|
+
watcher?.stop();
|
|
122
|
+
watcher = null;
|
|
123
|
+
reflect?.stop();
|
|
124
|
+
reflect = null;
|
|
111
125
|
retryQueue.stop();
|
|
112
126
|
const summary = recallMetrics.summary();
|
|
113
127
|
if (summary.count > 0) {
|
package/dist/core/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/core/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,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AAC;gBACxC,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;oBACtB,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,0BAA0B,OAAO,CAAC,KAAK,kBAAkB,OAAO,CAAC,GAAG,UAAU,OAAO,CAAC,GAAG,UAAU,OAAO,CAAC,GAAG,IAAI,CACnH,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -20,9 +20,11 @@ export declare class FileSyncWatcher {
|
|
|
20
20
|
private memoryMdSync;
|
|
21
21
|
private dailyLogsSync;
|
|
22
22
|
private transcriptsSync;
|
|
23
|
+
private started;
|
|
23
24
|
constructor(workspaceDir: string, client: CortexClient, sessionPrefix: string, logger: Logger, retryQueue?: RetryQueue | undefined, options?: FileSyncOptions);
|
|
24
25
|
start(): void;
|
|
25
26
|
stop(): void;
|
|
27
|
+
private watchPath;
|
|
26
28
|
}
|
|
27
29
|
export {};
|
|
28
30
|
//# sourceMappingURL=watcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/features/sync/watcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAKpE,KAAK,MAAM,GAAG;IACZ,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B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yncWatcher {
|
|
|
14
14
|
memoryMdSync = null;
|
|
15
15
|
dailyLogsSync = null;
|
|
16
16
|
transcriptsSync = null;
|
|
17
|
+
started = false;
|
|
17
18
|
constructor(workspaceDir, client, sessionPrefix, logger, retryQueue, options = {}) {
|
|
18
19
|
this.workspaceDir = workspaceDir;
|
|
19
20
|
this.client = client;
|
|
@@ -23,55 +24,42 @@ export class FileSyncWatcher {
|
|
|
23
24
|
this.options = options;
|
|
24
25
|
}
|
|
25
26
|
start() {
|
|
27
|
+
if (this.started) {
|
|
28
|
+
this.logger.debug?.("File sync: start() called while already running, skipping");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.started = true;
|
|
26
32
|
const memoryMdPath = join(this.workspaceDir, "MEMORY.md");
|
|
27
33
|
const memoryDir = join(this.workspaceDir, "memory");
|
|
28
34
|
const sessionsDir = join(this.workspaceDir, "sessions");
|
|
29
35
|
this.memoryMdSync = new MemoryMdSync(memoryMdPath, this.client, `${this.sessionPrefix}:memory-md`, this.logger, this.retryQueue, this.workspaceDir);
|
|
30
36
|
this.dailyLogsSync = new DailyLogsSync(this.client, this.sessionPrefix, this.logger, this.retryQueue, memoryDir);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.logger.debug?.("File sync: MEMORY.md not found, skipping");
|
|
41
|
-
}
|
|
42
|
-
// Watch memory/*.md (daily logs)
|
|
43
|
-
try {
|
|
44
|
-
const logsWatcher = watch(memoryDir, { recursive: true }, (_event, filename) => {
|
|
45
|
-
if (!filename?.endsWith(".md"))
|
|
46
|
-
return;
|
|
47
|
-
const fullPath = join(memoryDir, filename);
|
|
48
|
-
this.dailyLogsSync?.onFileChange(fullPath, filename);
|
|
49
|
-
});
|
|
50
|
-
this.watchers.push(logsWatcher);
|
|
51
|
-
this.logger.debug?.("File sync: watching memory/*.md");
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
this.logger.debug?.("File sync: memory/ directory not found, skipping");
|
|
55
|
-
}
|
|
37
|
+
this.watchPath(memoryMdPath, () => {
|
|
38
|
+
this.memoryMdSync?.onFileChange();
|
|
39
|
+
}, "File sync: watching MEMORY.md", "File sync: MEMORY.md not found, skipping");
|
|
40
|
+
this.watchPath(memoryDir, (_event, filename) => {
|
|
41
|
+
if (typeof filename !== "string" || !filename.endsWith(".md"))
|
|
42
|
+
return;
|
|
43
|
+
const fullPath = join(memoryDir, filename);
|
|
44
|
+
this.dailyLogsSync?.onFileChange(fullPath, filename);
|
|
45
|
+
}, "File sync: watching memory/*.md", "File sync: memory/ directory not found, skipping", { recursive: true });
|
|
56
46
|
// Watch sessions/*.jsonl (transcripts)
|
|
57
47
|
if (this.options.transcripts !== false) {
|
|
58
48
|
this.transcriptsSync = new TranscriptsSync(this.client, this.sessionPrefix, this.logger, this.retryQueue, sessionsDir);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
this.watchers.push(sessionsWatcher);
|
|
67
|
-
this.logger.debug?.("File sync: watching sessions/*.jsonl");
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
this.logger.debug?.("File sync: sessions/ directory not found, skipping");
|
|
71
|
-
}
|
|
49
|
+
this.watchPath(sessionsDir, (_event, filename) => {
|
|
50
|
+
if (typeof filename !== "string" || !filename.endsWith(".jsonl"))
|
|
51
|
+
return;
|
|
52
|
+
const fullPath = join(sessionsDir, filename);
|
|
53
|
+
this.transcriptsSync?.onFileChange(fullPath, filename);
|
|
54
|
+
}, "File sync: watching sessions/*.jsonl", "File sync: sessions/ directory not found, skipping", { recursive: true });
|
|
72
55
|
}
|
|
73
56
|
}
|
|
74
57
|
stop() {
|
|
58
|
+
if (!this.started) {
|
|
59
|
+
this.logger.info("File sync stopped");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.started = false;
|
|
75
63
|
for (const w of this.watchers) {
|
|
76
64
|
w.close();
|
|
77
65
|
}
|
|
@@ -81,5 +69,15 @@ export class FileSyncWatcher {
|
|
|
81
69
|
this.transcriptsSync?.stop();
|
|
82
70
|
this.logger.info("File sync stopped");
|
|
83
71
|
}
|
|
72
|
+
watchPath(path, handler, successMessage, skipMessage, options) {
|
|
73
|
+
try {
|
|
74
|
+
const watcher = options ? watch(path, options, handler) : watch(path, handler);
|
|
75
|
+
this.watchers.push(watcher);
|
|
76
|
+
this.logger.debug?.(successMessage);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
this.logger.debug?.(skipMessage);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
84
82
|
}
|
|
85
83
|
//# sourceMappingURL=watcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../../src/features/sync/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAaxD,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../../src/features/sync/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAaxD,MAAM,OAAO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|
17
|
+
private tasksById;
|
|
18
|
+
private taskOrder;
|
|
18
19
|
private timer;
|
|
19
20
|
private taskCounter;
|
|
21
|
+
private isFlushing;
|
|
20
22
|
constructor(logger: Logger, maxRetries?: number, maxCapacity?: number);
|
|
21
23
|
start(): void;
|
|
22
24
|
stop(): void;
|
|
23
25
|
enqueue(execute: () => Promise<void>, label?: string): void;
|
|
24
26
|
get pending(): number;
|
|
25
27
|
private flush;
|
|
28
|
+
private remove;
|
|
26
29
|
}
|
|
27
30
|
export {};
|
|
28
31
|
//# sourceMappingURL=retry-queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-queue.d.ts","sourceRoot":"","sources":["../../../src/shared/queue/retry-queue.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG;IACZ,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;AAQD,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"retry-queue.d.ts","sourceRoot":"","sources":["../../../src/shared/queue/retry-queue.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG;IACZ,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;AAQD,qBAAa,UAAU;IAQnB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,WAAW;IATrB,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,UAAU,CAAS;gBAGjB,MAAM,EAAE,MAAM,EACd,UAAU,SAAc,EACxB,WAAW,SAAe;IAGpC,KAAK,IAAI,IAAI;IAOb,IAAI,IAAI,IAAI;IAcZ,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAmC3D,IAAI,OAAO,IAAI,MAAM,CAEpB;YAEa,KAAK;IAwCnB,OAAO,CAAC,MAAM;CAOf"}
|
|
@@ -7,9 +7,11 @@ export class RetryQueue {
|
|
|
7
7
|
logger;
|
|
8
8
|
maxRetries;
|
|
9
9
|
maxCapacity;
|
|
10
|
-
|
|
10
|
+
tasksById = new Map();
|
|
11
|
+
taskOrder = [];
|
|
11
12
|
timer = null;
|
|
12
13
|
taskCounter = 0;
|
|
14
|
+
isFlushing = false;
|
|
13
15
|
constructor(logger, maxRetries = MAX_RETRIES, maxCapacity = MAX_CAPACITY) {
|
|
14
16
|
this.logger = logger;
|
|
15
17
|
this.maxRetries = maxRetries;
|
|
@@ -18,67 +20,96 @@ export class RetryQueue {
|
|
|
18
20
|
start() {
|
|
19
21
|
if (this.timer)
|
|
20
22
|
return;
|
|
21
|
-
this.timer = setInterval(() =>
|
|
23
|
+
this.timer = setInterval(() => {
|
|
24
|
+
void this.flush();
|
|
25
|
+
}, FLUSH_INTERVAL_MS);
|
|
22
26
|
}
|
|
23
27
|
stop() {
|
|
24
28
|
if (this.timer) {
|
|
25
29
|
clearInterval(this.timer);
|
|
26
30
|
this.timer = null;
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const pendingCount = this.pending;
|
|
33
|
+
if (pendingCount > 0) {
|
|
34
|
+
this.logger.warn(`Retry queue stopped with ${pendingCount} pending tasks`);
|
|
30
35
|
}
|
|
31
|
-
this.
|
|
36
|
+
this.tasksById.clear();
|
|
37
|
+
this.taskOrder = [];
|
|
38
|
+
this.isFlushing = false;
|
|
32
39
|
}
|
|
33
40
|
enqueue(execute, label) {
|
|
34
41
|
const id = label ?? `task-${++this.taskCounter}`;
|
|
35
42
|
// Deduplicate: if a task with the same label exists, replace it
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
const existing = this.tasksById.get(id);
|
|
44
|
+
if (existing) {
|
|
45
|
+
existing.execute = execute;
|
|
46
|
+
existing.retries = 0;
|
|
47
|
+
existing.nextAttemptAt = Date.now();
|
|
41
48
|
this.logger.debug?.(`Retry queue: deduplicated ${id}`);
|
|
42
49
|
return;
|
|
43
50
|
}
|
|
44
51
|
// Capacity check: drop oldest task if at limit
|
|
45
|
-
if (this.
|
|
46
|
-
const
|
|
47
|
-
|
|
52
|
+
if (this.pending >= this.maxCapacity) {
|
|
53
|
+
const droppedId = this.taskOrder.shift();
|
|
54
|
+
const dropped = droppedId ? this.tasksById.get(droppedId) : undefined;
|
|
55
|
+
if (droppedId) {
|
|
56
|
+
this.tasksById.delete(droppedId);
|
|
57
|
+
}
|
|
58
|
+
this.logger.warn(`Retry queue: at capacity (${this.maxCapacity}), dropped oldest task ${dropped?.id ?? "unknown"}`);
|
|
48
59
|
}
|
|
49
|
-
this.
|
|
60
|
+
this.tasksById.set(id, {
|
|
50
61
|
id,
|
|
51
62
|
execute,
|
|
52
63
|
retries: 0,
|
|
53
64
|
nextAttemptAt: Date.now(),
|
|
54
65
|
});
|
|
66
|
+
this.taskOrder.push(id);
|
|
55
67
|
this.logger.debug?.(`Retry queue: enqueued ${id}`);
|
|
56
68
|
}
|
|
57
69
|
get pending() {
|
|
58
|
-
return this.
|
|
70
|
+
return this.tasksById.size;
|
|
59
71
|
}
|
|
60
72
|
async flush() {
|
|
73
|
+
if (this.isFlushing)
|
|
74
|
+
return;
|
|
75
|
+
this.isFlushing = true;
|
|
61
76
|
const now = Date.now();
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.queue = this.queue.filter((t) => t.id !== task.id);
|
|
73
|
-
this.logger.warn(`Retry queue: ${task.id} failed after ${this.maxRetries} retries, dropping: ${String(err)}`);
|
|
77
|
+
const ids = [...this.taskOrder];
|
|
78
|
+
try {
|
|
79
|
+
for (const id of ids) {
|
|
80
|
+
const task = this.tasksById.get(id);
|
|
81
|
+
if (!task || task.nextAttemptAt > now)
|
|
82
|
+
continue;
|
|
83
|
+
try {
|
|
84
|
+
await task.execute();
|
|
85
|
+
this.remove(id);
|
|
86
|
+
this.logger.debug?.(`Retry queue: ${task.id} succeeded`);
|
|
74
87
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
task.
|
|
78
|
-
|
|
88
|
+
catch (err) {
|
|
89
|
+
task.retries++;
|
|
90
|
+
if (task.retries >= this.maxRetries) {
|
|
91
|
+
this.remove(id);
|
|
92
|
+
this.logger.warn(`Retry queue: ${task.id} failed after ${this.maxRetries} retries, dropping: ${String(err)}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const delay = Math.min(BASE_DELAY_MS * Math.pow(2, task.retries), MAX_DELAY_MS);
|
|
96
|
+
task.nextAttemptAt = Date.now() + delay;
|
|
97
|
+
this.logger.debug?.(`Retry queue: ${task.id} retry ${task.retries}/${this.maxRetries} in ${delay}ms`);
|
|
98
|
+
}
|
|
79
99
|
}
|
|
80
100
|
}
|
|
81
101
|
}
|
|
102
|
+
finally {
|
|
103
|
+
this.isFlushing = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
remove(id) {
|
|
107
|
+
if (!this.tasksById.delete(id))
|
|
108
|
+
return;
|
|
109
|
+
const idx = this.taskOrder.indexOf(id);
|
|
110
|
+
if (idx !== -1) {
|
|
111
|
+
this.taskOrder.splice(idx, 1);
|
|
112
|
+
}
|
|
82
113
|
}
|
|
83
114
|
}
|
|
84
115
|
//# sourceMappingURL=retry-queue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-queue.js","sourceRoot":"","sources":["../../../src/shared/queue/retry-queue.ts"],"names":[],"mappings":"AAcA,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"retry-queue.js","sourceRoot":"","sources":["../../../src/shared/queue/retry-queue.ts"],"names":[],"mappings":"AAcA,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,OAAO,UAAU;IAQX;IACA;IACA;IATF,SAAS,GAAG,IAAI,GAAG,EAAqB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AO,IAAI,IAAI,CAAC,UAAU,OAAO,KAAK,IAAI,CACjF,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,EAAU;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAAE,OAAO;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "cortex-memory",
|
|
3
3
|
"name": "Cortex Memory",
|
|
4
4
|
"description": "Long-term memory powered by Cortex — Auto-Recall, Auto-Capture, transcript ingestion, periodic consolidation, and background file sync",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.5",
|
|
6
6
|
"kind": "memory",
|
|
7
7
|
"configSchema": {
|
|
8
8
|
"type": "object",
|