openclaw-memory-atmem 2.0.1 → 2.2.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/LICENSE +202 -0
- package/README.md +6 -2
- package/dist/index.js +92 -46
- package/dist/src/rpc-client.js +9 -4
- package/openclaw.plugin.json +21 -1
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -5,11 +5,15 @@ This npm package is the host bridge for AtMem. It is not a standalone memory eng
|
|
|
5
5
|
Use the Python-owned installer:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
python -m pip install atmem==2.0
|
|
8
|
+
python -m pip install --upgrade atmem==2.2.0
|
|
9
9
|
atmem openclaw install
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
The installer pins `openclaw-memory-atmem@2.0
|
|
12
|
+
The installer pins `openclaw-memory-atmem@2.2.0`, binds the exact `atmem` executable, copies existing OpenClaw memory, configures shadow mode, restarts the gateway and verifies the loaded plugin. Direct npm installation cannot perform or prove those steps.
|
|
13
|
+
|
|
14
|
+
Existing AtMem 2.1 users run `atmem openclaw upgrade` after upgrading the Python
|
|
15
|
+
package. This preserves the current memory mode and migration, verifies the new
|
|
16
|
+
bridge with a self-test flight, and rolls back the bridge on failure.
|
|
13
17
|
|
|
14
18
|
In shadow mode the bridge observes native-memory changes without injecting AtMem context. In active mode it exposes compatible memory search/get tools, model-semantic capture, bounded recall and native-path protection. `atmem control restore` restores the saved OpenClaw configuration and native memory.
|
|
15
19
|
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,19 @@ function parseConfig(raw) {
|
|
|
43
43
|
const cfg = (raw ?? {});
|
|
44
44
|
const dbPath = expandHome(String(cfg.dbPath ?? "~/.atmem/memories.db"));
|
|
45
45
|
const subject = String(cfg.subject ?? "default");
|
|
46
|
+
const stringMap = (value) => value && typeof value === "object" && !Array.isArray(value)
|
|
47
|
+
? Object.fromEntries(Object.entries(value)
|
|
48
|
+
.filter(([, item]) => typeof item === "string" && item.trim())
|
|
49
|
+
.map(([key, item]) => [key, String(item)]))
|
|
50
|
+
: {};
|
|
51
|
+
const agentSubjects = stringMap(cfg.agentSubjects);
|
|
52
|
+
const agentWorkspaces = Object.fromEntries(Object.entries(stringMap(cfg.agentWorkspaces)).map(([key, value]) => [key, expandHome(value)]));
|
|
53
|
+
const nativeWorkspace = expandHome(String(cfg.nativeWorkspace ?? ""));
|
|
54
|
+
const nativeWorkspaces = [...new Set([
|
|
55
|
+
...(Array.isArray(cfg.nativeWorkspaces) ? cfg.nativeWorkspaces.map((item) => expandHome(String(item))) : []),
|
|
56
|
+
...Object.values(agentWorkspaces),
|
|
57
|
+
nativeWorkspace,
|
|
58
|
+
].filter(Boolean))];
|
|
46
59
|
const controlPlane = {
|
|
47
60
|
enabled: cfg.controlPlane?.enabled === true,
|
|
48
61
|
statePath: expandHome(String(cfg.controlPlane?.statePath ?? "~/.atmem/control-plane.json")),
|
|
@@ -57,8 +70,12 @@ function parseConfig(raw) {
|
|
|
57
70
|
: ["mcp", "--db", dbPath, "--subject", subject],
|
|
58
71
|
dbPath,
|
|
59
72
|
subject,
|
|
73
|
+
defaultAgentId: String(cfg.defaultAgentId ?? "main"),
|
|
74
|
+
agentSubjects,
|
|
75
|
+
agentWorkspaces,
|
|
60
76
|
takeoverActive: cfg.takeoverActive === true,
|
|
61
|
-
nativeWorkspace
|
|
77
|
+
nativeWorkspace,
|
|
78
|
+
nativeWorkspaces,
|
|
62
79
|
recall: {
|
|
63
80
|
enabled: cfg.recall?.enabled !== false,
|
|
64
81
|
maxRecords: Number(cfg.recall?.maxRecords ?? 3),
|
|
@@ -312,7 +329,31 @@ function register(api) {
|
|
|
312
329
|
const inboundAttachments = new Map();
|
|
313
330
|
const inboundAttachmentGeneration = new Map();
|
|
314
331
|
let nextAttachmentGeneration = 0;
|
|
315
|
-
const
|
|
332
|
+
const agentIdFor = (ctx) => {
|
|
333
|
+
if (ctx.agentId?.trim())
|
|
334
|
+
return ctx.agentId.trim();
|
|
335
|
+
const session = ctx.sessionKey ?? ctx.sessionId ?? "";
|
|
336
|
+
const match = /^agent:([^:]+)(?::|$)/.exec(session);
|
|
337
|
+
return match?.[1] ?? cfg.defaultAgentId;
|
|
338
|
+
};
|
|
339
|
+
const subjectFor = (ctx) => {
|
|
340
|
+
const agentId = agentIdFor(ctx);
|
|
341
|
+
if (Object.keys(cfg.agentSubjects).length) {
|
|
342
|
+
const mapped = cfg.agentSubjects[agentId];
|
|
343
|
+
if (!mapped)
|
|
344
|
+
throw new Error(`unmapped OpenClaw persistent agent: ${agentId}`);
|
|
345
|
+
return mapped;
|
|
346
|
+
}
|
|
347
|
+
return cfg.subject;
|
|
348
|
+
};
|
|
349
|
+
const scopedKey = (value, ctx) => `${agentIdFor(ctx)}:${value}`;
|
|
350
|
+
const contextIds = (ctx) => [...new Set([ctx.runId, ctx.sessionKey, ctx.sessionId].filter((value) => Boolean(value)).map((value) => scopedKey(value, ctx)))];
|
|
351
|
+
const callFor = (ctx, name, args, timeoutMs = cfg.recall.timeoutMs) => {
|
|
352
|
+
const scoped = cfg.controlPlane.enabled && !Object.keys(cfg.agentSubjects).length
|
|
353
|
+
? args
|
|
354
|
+
: { ...args, subject_id: subjectFor(ctx) };
|
|
355
|
+
return client.callTool(name, scoped, timeoutMs);
|
|
356
|
+
};
|
|
316
357
|
const digestText = (value) => createHash("sha256").update(value, "utf8").digest("hex");
|
|
317
358
|
const stableValue = (value) => {
|
|
318
359
|
if (Array.isArray(value))
|
|
@@ -346,6 +387,8 @@ function register(api) {
|
|
|
346
387
|
await blackboxClient.callTool("control_record_blackbox_event", {
|
|
347
388
|
event_type: eventType,
|
|
348
389
|
run_id: flightRunId(eventRunId, ctx),
|
|
390
|
+
agent_id: agentIdFor(ctx),
|
|
391
|
+
subject_id: Object.keys(cfg.agentSubjects).length ? subjectFor(ctx) : undefined,
|
|
349
392
|
session_id: ctx.sessionId ?? ctx.sessionKey,
|
|
350
393
|
tool_call_id: toolCallId,
|
|
351
394
|
turn_id: correlation.turnId ?? flightRunId(eventRunId, ctx),
|
|
@@ -382,7 +425,7 @@ function register(api) {
|
|
|
382
425
|
const ids = contextIds(ctx);
|
|
383
426
|
if (!ids.length)
|
|
384
427
|
return;
|
|
385
|
-
await
|
|
428
|
+
await callFor(ctx, "memory_stage_user_message", {
|
|
386
429
|
message: text.trim(),
|
|
387
430
|
source_aliases: ids,
|
|
388
431
|
run_id: ctx.runId,
|
|
@@ -499,7 +542,7 @@ function register(api) {
|
|
|
499
542
|
const visibleText = responses.map(String).join("");
|
|
500
543
|
const assistantVisibleTextSha256 = digestText(visibleText);
|
|
501
544
|
const modelOutputBundleSha256 = digestJson(responses);
|
|
502
|
-
const sessionKey = ctx.sessionKey ?? ctx.sessionId ?? event.sessionId ?? "default-session";
|
|
545
|
+
const sessionKey = scopedKey(ctx.sessionKey ?? ctx.sessionId ?? event.sessionId ?? "default-session", ctx);
|
|
503
546
|
const pending = pendingPrompts.get(sessionKey);
|
|
504
547
|
if (pending) {
|
|
505
548
|
pendingPrompts.set(sessionKey, {
|
|
@@ -570,7 +613,7 @@ function register(api) {
|
|
|
570
613
|
}, { commands: ["atmem"] });
|
|
571
614
|
// L3 persona cache: rebuilt on TTL expiry and invalidated when capture
|
|
572
615
|
// writes new memory, so the snapshot never lags a correction.
|
|
573
|
-
|
|
616
|
+
const personaCaches = new Map();
|
|
574
617
|
const sweep = () => {
|
|
575
618
|
const now = Date.now();
|
|
576
619
|
for (const [key, value] of pendingPrompts) {
|
|
@@ -582,40 +625,43 @@ function register(api) {
|
|
|
582
625
|
inboundAttachments.delete(key);
|
|
583
626
|
}
|
|
584
627
|
};
|
|
585
|
-
async function personaBlock(sessionKey) {
|
|
628
|
+
async function personaBlock(sessionKey, ctx) {
|
|
586
629
|
if (!cfg.persona.enabled)
|
|
587
630
|
return { block: "", recordIds: [] };
|
|
588
631
|
const now = Date.now();
|
|
632
|
+
const subject = subjectFor(ctx);
|
|
633
|
+
const personaCache = personaCaches.get(subject);
|
|
589
634
|
if (personaCache && now - personaCache.ts < cfg.persona.ttlSeconds * 1000) {
|
|
590
635
|
return personaCache;
|
|
591
636
|
}
|
|
592
|
-
const result = (await
|
|
637
|
+
const result = (await callFor(ctx, "memory_persona", {
|
|
593
638
|
session_id: sessionKey,
|
|
594
639
|
max_chars: cfg.persona.maxChars,
|
|
595
640
|
reference_mode: cfg.cacheAware.enabled && cfg.cacheAware.compactReferences
|
|
596
641
|
? "compact"
|
|
597
642
|
: "full",
|
|
598
643
|
}, cfg.recall.timeoutMs));
|
|
599
|
-
|
|
644
|
+
const refreshed = {
|
|
600
645
|
block: result?.block ?? "",
|
|
601
646
|
recordIds: result?.record_ids ?? [],
|
|
602
647
|
contextEventId: result?.context_event_id,
|
|
603
648
|
ts: now,
|
|
604
649
|
};
|
|
605
|
-
|
|
650
|
+
personaCaches.set(subject, refreshed);
|
|
651
|
+
return refreshed;
|
|
606
652
|
}
|
|
607
653
|
// ---- auto-recall: persona + bounded, audited recall injection ---------
|
|
608
654
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
609
655
|
const userText = event.prompt;
|
|
610
656
|
if (!userText)
|
|
611
657
|
return;
|
|
612
|
-
const sessionKey = ctx.sessionKey ?? ctx.sessionId ?? "default-session";
|
|
658
|
+
const sessionKey = scopedKey(ctx.sessionKey ?? ctx.sessionId ?? "default-session", ctx);
|
|
613
659
|
const takeoverGuidance = cfg.takeoverActive ? TAKEOVER_GUIDANCE : "";
|
|
614
660
|
pendingPrompts.set(sessionKey, { text: userText, ts: Date.now() });
|
|
615
661
|
sweep();
|
|
616
662
|
if (cfg.controlPlane.enabled) {
|
|
617
663
|
try {
|
|
618
|
-
const prepared = (await
|
|
664
|
+
const prepared = (await callFor(ctx, "control_prepare", { query: userText, session_id: sessionKey, agent_id: agentIdFor(ctx) }, cfg.recall.timeoutMs));
|
|
619
665
|
pendingPrompts.set(sessionKey, {
|
|
620
666
|
text: userText,
|
|
621
667
|
ts: Date.now(),
|
|
@@ -687,7 +733,7 @@ function register(api) {
|
|
|
687
733
|
let recall = "";
|
|
688
734
|
let recallFailed = false;
|
|
689
735
|
try {
|
|
690
|
-
const personaResult = await personaBlock(sessionKey);
|
|
736
|
+
const personaResult = await personaBlock(sessionKey, ctx);
|
|
691
737
|
persona = personaResult.block;
|
|
692
738
|
personaRecordIds = personaResult.recordIds;
|
|
693
739
|
personaContextEventId = personaResult.contextEventId;
|
|
@@ -698,7 +744,7 @@ function register(api) {
|
|
|
698
744
|
}
|
|
699
745
|
try {
|
|
700
746
|
if (cfg.recall.enabled) {
|
|
701
|
-
const result = (await
|
|
747
|
+
const result = (await callFor(ctx, "memory_recall_block", {
|
|
702
748
|
query: userText,
|
|
703
749
|
session_id: sessionKey,
|
|
704
750
|
max_records: cfg.recall.maxRecords,
|
|
@@ -803,7 +849,7 @@ function register(api) {
|
|
|
803
849
|
? event.derivedPaths.map((value) => digestText(String(value)))
|
|
804
850
|
: [],
|
|
805
851
|
}, event.toolCallId);
|
|
806
|
-
if (!cfg.takeoverActive || !touchesNativeMemory(event,
|
|
852
|
+
if (!cfg.takeoverActive || !cfg.nativeWorkspaces.some((workspace) => touchesNativeMemory(event, workspace)))
|
|
807
853
|
return;
|
|
808
854
|
const reason = "AtMem takeover blocked access to OpenClaw's frozen native memory " +
|
|
809
855
|
"(MEMORY.md or memory/*). Use memory_remember for durable user facts, " +
|
|
@@ -831,20 +877,20 @@ function register(api) {
|
|
|
831
877
|
});
|
|
832
878
|
// ---- auto-capture: user turn through the pipeline, assistant as digest -
|
|
833
879
|
api.on("agent_end", async (event, ctx) => {
|
|
834
|
-
const sessionKey = ctx.sessionKey ?? ctx.sessionId ?? "default-session";
|
|
880
|
+
const sessionKey = scopedKey(ctx.sessionKey ?? ctx.sessionId ?? "default-session", ctx);
|
|
835
881
|
const cached = pendingPrompts.get(sessionKey);
|
|
836
882
|
pendingPrompts.delete(sessionKey);
|
|
837
883
|
const userText = cached?.text?.replace(INJECT_RE, "").trim();
|
|
838
884
|
try {
|
|
839
885
|
if (cfg.takeoverActive) {
|
|
840
|
-
await
|
|
886
|
+
await callFor(ctx, "memory_clear_user_message", { source_aliases: contextIds(ctx) }, cfg.recall.timeoutMs);
|
|
841
887
|
}
|
|
842
888
|
if (cfg.controlPlane.enabled) {
|
|
843
889
|
if (cached?.exposureId) {
|
|
844
|
-
await
|
|
890
|
+
await callFor(ctx, "control_exposure_shown", { exposure_id: cached.exposureId }, cfg.recall.timeoutMs);
|
|
845
891
|
}
|
|
846
892
|
if (event.success !== false) {
|
|
847
|
-
await
|
|
893
|
+
await callFor(ctx, "control_sync_openclaw_memory", {}, cfg.recall.timeoutMs);
|
|
848
894
|
}
|
|
849
895
|
return;
|
|
850
896
|
}
|
|
@@ -857,7 +903,7 @@ function register(api) {
|
|
|
857
903
|
const responseText = messageText(message.content);
|
|
858
904
|
if (responseText) {
|
|
859
905
|
const assistantVisibleTextSha256 = cached.assistantVisibleTextSha256 ?? digestText(responseText);
|
|
860
|
-
await
|
|
906
|
+
await callFor(ctx, "memory_log_action", {
|
|
861
907
|
action_type: "agent.response_after_memory",
|
|
862
908
|
payload: {
|
|
863
909
|
response_sha256: assistantVisibleTextSha256,
|
|
@@ -882,12 +928,12 @@ function register(api) {
|
|
|
882
928
|
!cfg.takeoverActive &&
|
|
883
929
|
event.success !== false &&
|
|
884
930
|
userText) {
|
|
885
|
-
await
|
|
931
|
+
await callFor(ctx, "memory_capture", {
|
|
886
932
|
role: "user",
|
|
887
933
|
content: userText,
|
|
888
934
|
session_id: sessionKey,
|
|
889
935
|
});
|
|
890
|
-
|
|
936
|
+
personaCaches.delete(subjectFor(ctx)); // new memory may change the persona
|
|
891
937
|
}
|
|
892
938
|
if (cfg.capture.enabled &&
|
|
893
939
|
!cfg.takeoverActive &&
|
|
@@ -899,7 +945,7 @@ function register(api) {
|
|
|
899
945
|
if (message?.role === "assistant") {
|
|
900
946
|
const text = messageText(message.content);
|
|
901
947
|
if (text) {
|
|
902
|
-
await
|
|
948
|
+
await callFor(ctx, "memory_capture", {
|
|
903
949
|
role: "assistant",
|
|
904
950
|
content: text,
|
|
905
951
|
session_id: sessionKey,
|
|
@@ -1005,9 +1051,9 @@ function register(api) {
|
|
|
1005
1051
|
additionalProperties: false,
|
|
1006
1052
|
},
|
|
1007
1053
|
async execute(toolCallId, params) {
|
|
1008
|
-
const
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1054
|
+
const rawSessionKey = toolCtx.sessionKey ?? toolCtx.sessionId;
|
|
1055
|
+
const sessionKey = rawSessionKey ? scopedKey(rawSessionKey, toolCtx) : undefined;
|
|
1056
|
+
const sourceAliases = contextIds(toolCtx);
|
|
1011
1057
|
if (!sessionKey || !sourceAliases.length) {
|
|
1012
1058
|
throw new Error("no current authenticated user message is available; memory was not stored");
|
|
1013
1059
|
}
|
|
@@ -1019,7 +1065,7 @@ function register(api) {
|
|
|
1019
1065
|
.filter(Boolean)
|
|
1020
1066
|
.join(":") ??
|
|
1021
1067
|
"openclaw-agent";
|
|
1022
|
-
const result = (await
|
|
1068
|
+
const result = (await callFor(toolCtx, "memory_remember", {
|
|
1023
1069
|
source_aliases: sourceAliases,
|
|
1024
1070
|
interpreted_fact: fact,
|
|
1025
1071
|
interpreted_fact_key: params.factKey,
|
|
@@ -1032,7 +1078,7 @@ function register(api) {
|
|
|
1032
1078
|
const duplicateId = result.duplicate_ids?.[0];
|
|
1033
1079
|
const stored = Boolean(record || duplicateId);
|
|
1034
1080
|
if (stored) {
|
|
1035
|
-
|
|
1081
|
+
personaCaches.delete(subjectFor(toolCtx));
|
|
1036
1082
|
}
|
|
1037
1083
|
return {
|
|
1038
1084
|
content: [{
|
|
@@ -1055,7 +1101,7 @@ function register(api) {
|
|
|
1055
1101
|
// is disabled. Existing agent prompts and workflows can keep using the
|
|
1056
1102
|
// same tool names; only the governed storage/retrieval implementation
|
|
1057
1103
|
// changes underneath them.
|
|
1058
|
-
api.registerTool({
|
|
1104
|
+
api.registerTool((toolCtx) => ({
|
|
1059
1105
|
name: "memory_search",
|
|
1060
1106
|
label: "Memory Search",
|
|
1061
1107
|
description: "Search governed AtMem long-term memory. Compatible with OpenClaw's " +
|
|
@@ -1092,7 +1138,7 @@ function register(api) {
|
|
|
1092
1138
|
}
|
|
1093
1139
|
const sessionId = `openclaw-memory-search:${toolCallId}`;
|
|
1094
1140
|
const maxResults = Math.min(Math.max(Number(params.maxResults) || 6, 1), 20);
|
|
1095
|
-
const records = (await
|
|
1141
|
+
const records = (await callFor(toolCtx, "memory_recall", {
|
|
1096
1142
|
query: String(params.query ?? ""),
|
|
1097
1143
|
session_id: sessionId,
|
|
1098
1144
|
limit: maxResults,
|
|
@@ -1128,8 +1174,8 @@ function register(api) {
|
|
|
1128
1174
|
details: { count: results.length, corpus, sessionId },
|
|
1129
1175
|
};
|
|
1130
1176
|
},
|
|
1131
|
-
}, { name: "memory_search" });
|
|
1132
|
-
api.registerTool({
|
|
1177
|
+
}), { name: "memory_search" });
|
|
1178
|
+
api.registerTool((toolCtx) => ({
|
|
1133
1179
|
name: "memory_get",
|
|
1134
1180
|
label: "Memory Get",
|
|
1135
1181
|
description: "Read one exact governed AtMem record returned by memory_search. " +
|
|
@@ -1150,7 +1196,7 @@ function register(api) {
|
|
|
1150
1196
|
const recordId = recordIdFromPath(lookup);
|
|
1151
1197
|
if (!recordId) {
|
|
1152
1198
|
const sessionId = `openclaw-memory-get:${toolCallId}`;
|
|
1153
|
-
const sourceResult = (await
|
|
1199
|
+
const sourceResult = (await callFor(toolCtx, "memory_get_source", {
|
|
1154
1200
|
path: lookup,
|
|
1155
1201
|
session_id: sessionId,
|
|
1156
1202
|
}));
|
|
@@ -1188,7 +1234,7 @@ function register(api) {
|
|
|
1188
1234
|
};
|
|
1189
1235
|
}
|
|
1190
1236
|
const sessionId = `openclaw-memory-get:${toolCallId}`;
|
|
1191
|
-
const result = (await
|
|
1237
|
+
const result = (await callFor(toolCtx, "memory_get_record", {
|
|
1192
1238
|
record_id: recordId,
|
|
1193
1239
|
session_id: sessionId,
|
|
1194
1240
|
}));
|
|
@@ -1211,8 +1257,8 @@ function register(api) {
|
|
|
1211
1257
|
details: { found: Boolean(result?.record), sessionId },
|
|
1212
1258
|
};
|
|
1213
1259
|
},
|
|
1214
|
-
}, { name: "memory_get" });
|
|
1215
|
-
api.registerTool({
|
|
1260
|
+
}), { name: "memory_get" });
|
|
1261
|
+
api.registerTool((toolCtx) => ({
|
|
1216
1262
|
name: "atmem_search",
|
|
1217
1263
|
label: "Memory Search (atmem)",
|
|
1218
1264
|
description: "Search the user's long-term auditable memory. Use when you need " +
|
|
@@ -1228,7 +1274,7 @@ function register(api) {
|
|
|
1228
1274
|
},
|
|
1229
1275
|
async execute(toolCallId, params) {
|
|
1230
1276
|
const sessionId = `openclaw-tool:${toolCallId}`;
|
|
1231
|
-
const records = (await
|
|
1277
|
+
const records = (await callFor(toolCtx, "memory_recall", {
|
|
1232
1278
|
query: String(params.query ?? ""),
|
|
1233
1279
|
session_id: sessionId,
|
|
1234
1280
|
limit: Math.min(Math.max(Number(params.limit) || 5, 1), 20),
|
|
@@ -1241,8 +1287,8 @@ function register(api) {
|
|
|
1241
1287
|
details: { count: records.length, sessionId },
|
|
1242
1288
|
};
|
|
1243
1289
|
},
|
|
1244
|
-
}, { name: "atmem_search" });
|
|
1245
|
-
api.registerTool({
|
|
1290
|
+
}), { name: "atmem_search" });
|
|
1291
|
+
api.registerTool((toolCtx) => ({
|
|
1246
1292
|
name: "atmem_forget",
|
|
1247
1293
|
label: "Memory Forget (atmem)",
|
|
1248
1294
|
description: "Delete the user's memories matching their request — only call when " +
|
|
@@ -1261,13 +1307,13 @@ function register(api) {
|
|
|
1261
1307
|
},
|
|
1262
1308
|
async execute(toolCallId, params) {
|
|
1263
1309
|
const sessionId = `openclaw-tool:${toolCallId}`;
|
|
1264
|
-
const result = (await
|
|
1310
|
+
const result = (await callFor(toolCtx, "memory_forget", {
|
|
1265
1311
|
utterance: String(params.utterance ?? ""),
|
|
1266
1312
|
session_id: sessionId,
|
|
1267
1313
|
turn_id: toolCallId,
|
|
1268
1314
|
}));
|
|
1269
1315
|
if (result.deleted)
|
|
1270
|
-
|
|
1316
|
+
personaCaches.delete(subjectFor(toolCtx));
|
|
1271
1317
|
const text = result.deleted
|
|
1272
1318
|
? `Deleted ${result.record_ids.length} memorie(s). Receipt: ${JSON.stringify(result.receipt)}`
|
|
1273
1319
|
: "No matching memories found to delete.";
|
|
@@ -1276,7 +1322,7 @@ function register(api) {
|
|
|
1276
1322
|
details: { deleted: result.deleted, sessionId },
|
|
1277
1323
|
};
|
|
1278
1324
|
},
|
|
1279
|
-
}, { name: "atmem_forget" });
|
|
1325
|
+
}), { name: "atmem_forget" });
|
|
1280
1326
|
api.registerTool((toolCtx) => ({
|
|
1281
1327
|
name: "atmem_observe",
|
|
1282
1328
|
label: "Media Observation (atmem)",
|
|
@@ -1392,7 +1438,7 @@ function register(api) {
|
|
|
1392
1438
|
if (suppliedSegment[key] !== undefined)
|
|
1393
1439
|
segment[key] = suppliedSegment[key];
|
|
1394
1440
|
}
|
|
1395
|
-
const result = (await
|
|
1441
|
+
const result = (await callFor(toolCtx, "memory_observe", {
|
|
1396
1442
|
text: String(params.text ?? ""),
|
|
1397
1443
|
modality: requestedModality,
|
|
1398
1444
|
media_sha256: mediaSha256,
|
|
@@ -1426,7 +1472,7 @@ function register(api) {
|
|
|
1426
1472
|
};
|
|
1427
1473
|
},
|
|
1428
1474
|
}), { name: "atmem_observe" });
|
|
1429
|
-
api.registerTool({
|
|
1475
|
+
api.registerTool((toolCtx) => ({
|
|
1430
1476
|
name: "atmem_forget_artifact",
|
|
1431
1477
|
label: "Forget Media Artifact (atmem)",
|
|
1432
1478
|
description: "Only when the user explicitly requests deletion, purge all AtMem " +
|
|
@@ -1448,14 +1494,14 @@ function register(api) {
|
|
|
1448
1494
|
},
|
|
1449
1495
|
async execute(toolCallId, params) {
|
|
1450
1496
|
const sessionId = `openclaw-tool:${toolCallId}`;
|
|
1451
|
-
const result = (await
|
|
1497
|
+
const result = (await callFor(toolCtx, "memory_forget_artifact", {
|
|
1452
1498
|
media_sha256: String(params.media_sha256 ?? ""),
|
|
1453
1499
|
artifact_id: params.artifact_id,
|
|
1454
1500
|
session_id: sessionId,
|
|
1455
1501
|
turn_id: toolCallId,
|
|
1456
1502
|
}));
|
|
1457
1503
|
if (result.deleted)
|
|
1458
|
-
|
|
1504
|
+
personaCaches.delete(subjectFor(toolCtx));
|
|
1459
1505
|
const text = result.deleted
|
|
1460
1506
|
? `Purged ${result.record_ids.length} derived memorie(s). Receipt: ${JSON.stringify(result.receipt)}`
|
|
1461
1507
|
: "No active AtMem artifact matched that exact digest.";
|
|
@@ -1464,7 +1510,7 @@ function register(api) {
|
|
|
1464
1510
|
details: { deleted: result.deleted, sessionId },
|
|
1465
1511
|
};
|
|
1466
1512
|
},
|
|
1467
|
-
}, { name: "atmem_forget_artifact" });
|
|
1513
|
+
}), { name: "atmem_forget_artifact" });
|
|
1468
1514
|
}
|
|
1469
1515
|
api.logger.info(`${TAG} registered (db=${cfg.dbPath}, subject=${cfg.subject}, ` +
|
|
1470
1516
|
`recall=${cfg.recall.enabled}, capture=${cfg.capture.enabled}, ` +
|
package/dist/src/rpc-client.js
CHANGED
|
@@ -106,7 +106,7 @@ export class AtmemClient {
|
|
|
106
106
|
});
|
|
107
107
|
child.on("exit", (code) => {
|
|
108
108
|
this.options.logError?.(`[atmem] server exited (code ${code})`);
|
|
109
|
-
this.teardown(new Error(`atmem server exited (code ${code})`));
|
|
109
|
+
this.teardown(new Error(`atmem server exited (code ${code})`), child);
|
|
110
110
|
});
|
|
111
111
|
child.on("error", (error) => {
|
|
112
112
|
const spawnError = error;
|
|
@@ -119,7 +119,7 @@ export class AtmemClient {
|
|
|
119
119
|
? error
|
|
120
120
|
: new Error(String(error));
|
|
121
121
|
this.options.logError?.(`[atmem] spawn failed: ${actionable.message}`);
|
|
122
|
-
this.teardown(actionable);
|
|
122
|
+
this.teardown(actionable, child);
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
async handshake() {
|
|
@@ -128,7 +128,7 @@ export class AtmemClient {
|
|
|
128
128
|
capabilities: {},
|
|
129
129
|
clientInfo: {
|
|
130
130
|
name: "openclaw-memory-atmem",
|
|
131
|
-
version: "2.0
|
|
131
|
+
version: "2.2.0",
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
134
|
this.notify("notifications/initialized", {});
|
|
@@ -176,7 +176,12 @@ export class AtmemClient {
|
|
|
176
176
|
pending.resolve(message.result);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
teardown(error) {
|
|
179
|
+
teardown(error, sourceChild) {
|
|
180
|
+
// A closed process can emit its exit event after the next request has
|
|
181
|
+
// already spawned a replacement. Never let that stale event tear down the
|
|
182
|
+
// live child or reject its requests.
|
|
183
|
+
if (sourceChild && this.child !== sourceChild)
|
|
184
|
+
return;
|
|
180
185
|
for (const pending of this.pending.values()) {
|
|
181
186
|
clearTimeout(pending.timer);
|
|
182
187
|
pending.reject(error);
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "memory-atmem",
|
|
3
3
|
"name": "Memory (atmem)",
|
|
4
4
|
"description": "OpenClaw bridge installed and managed by the AtMem memory control plane.",
|
|
5
|
-
"version": "2.0
|
|
5
|
+
"version": "2.2.0",
|
|
6
6
|
"commandAliases": ["memory-atmem"],
|
|
7
7
|
"activation": {
|
|
8
8
|
"onStartup": true
|
|
@@ -42,6 +42,21 @@
|
|
|
42
42
|
"default": "default",
|
|
43
43
|
"description": "Subject id used for all memory operations (single-user assistant)"
|
|
44
44
|
},
|
|
45
|
+
"defaultAgentId": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"default": "main",
|
|
48
|
+
"description": "Persistent OpenClaw agent used when a legacy hook does not expose an agent id. Managed by AtMem."
|
|
49
|
+
},
|
|
50
|
+
"agentSubjects": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"additionalProperties": { "type": "string" },
|
|
53
|
+
"description": "Persistent-agent to governed-memory-subject map. Agents sharing an exact workspace intentionally share a subject."
|
|
54
|
+
},
|
|
55
|
+
"agentWorkspaces": {
|
|
56
|
+
"type": "object",
|
|
57
|
+
"additionalProperties": { "type": "string" },
|
|
58
|
+
"description": "Persistent-agent to canonical workspace map. Managed by AtMem."
|
|
59
|
+
},
|
|
45
60
|
"takeoverActive": {
|
|
46
61
|
"type": "boolean",
|
|
47
62
|
"default": false,
|
|
@@ -51,6 +66,11 @@
|
|
|
51
66
|
"type": "string",
|
|
52
67
|
"description": "Absolute OpenClaw workspace path protected during verified takeover. Set by `atmem control activate`; do not configure manually."
|
|
53
68
|
},
|
|
69
|
+
"nativeWorkspaces": {
|
|
70
|
+
"type": "array",
|
|
71
|
+
"items": { "type": "string" },
|
|
72
|
+
"description": "All OpenClaw workspaces protected during takeover, including separate and nested persistent-agent workspaces."
|
|
73
|
+
},
|
|
54
74
|
"recall": {
|
|
55
75
|
"type": "object",
|
|
56
76
|
"description": "Auto-recall injection before each prompt",
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-memory-atmem",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "OpenClaw Agent Black Box and memory control-plane bridge for AtMem",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"files": [
|
|
8
|
+
"LICENSE",
|
|
8
9
|
"dist",
|
|
9
10
|
"openclaw.plugin.json",
|
|
10
11
|
"README.md"
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"bugs": {
|
|
27
28
|
"url": "https://github.com/aetna000/atmem/issues"
|
|
28
29
|
},
|
|
29
|
-
"license": "
|
|
30
|
+
"license": "Apache-2.0",
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|