@clawmem-ai/clawmem 0.1.14 → 0.1.16
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 +10 -5
- package/openclaw.plugin.json +30 -3
- package/package.json +4 -1
- package/skills/clawmem/SKILL.md +13 -8
- package/src/config.test.ts +4 -1
- package/src/config.ts +4 -1
- package/src/conversation.ts +217 -2
- package/src/memory.test.ts +95 -40
- package/src/memory.ts +237 -21
- package/src/recall-sanitize.ts +143 -0
- package/src/runtime-env.ts +12 -0
- package/src/service.test.ts +37 -29
- package/src/service.ts +418 -127
- package/src/state.test.ts +88 -0
- package/src/state.ts +139 -8
- package/src/types.ts +46 -2
- package/src/utils.ts +19 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function getOpenClawAgentIdFromEnv(): string | undefined {
|
|
2
|
+
const value = process.env.OPENCLAW_AGENT_ID;
|
|
3
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function getOpenClawHostVersionFromEnv(): string | undefined {
|
|
7
|
+
for (const candidate of [process.env.OPENCLAW_VERSION, process.env.OPENCLAW_SERVICE_VERSION]) {
|
|
8
|
+
const trimmed = candidate?.trim();
|
|
9
|
+
if (trimmed) return trimmed;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
package/src/service.test.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
buildRelevantMemoriesSystemContext,
|
|
2
|
+
buildAutoRecallContext,
|
|
4
3
|
extractPromptTextForRecall,
|
|
5
4
|
resolveOpenClawHostVersion,
|
|
6
5
|
resolvePromptHookMode,
|
|
@@ -14,21 +13,40 @@ function testExtractPromptFromString(): void {
|
|
|
14
13
|
assert(extractPromptTextForRecall(" help me fix redis ") === "help me fix redis", "expected direct string prompts to be trimmed");
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
function testExtractPromptPrefersSanitizedPromptField(): void {
|
|
17
|
+
const prompt = extractPromptTextForRecall({
|
|
18
|
+
prompt: [
|
|
19
|
+
"Conversation info (untrusted metadata):",
|
|
20
|
+
"```json",
|
|
21
|
+
'{"channel":"slack"}',
|
|
22
|
+
"```",
|
|
23
|
+
"",
|
|
24
|
+
"[Slack 2026-04-03 09:30]: Please fix the login bug. [System: auto-translated]",
|
|
25
|
+
].join("\n"),
|
|
26
|
+
messages: [
|
|
27
|
+
{ role: "assistant", text: "How can I help?" },
|
|
28
|
+
{ role: "user", text: "继续" },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
assert(prompt === "Please fix the login bug.", "expected sanitized prompt text to drive auto recall when available");
|
|
22
32
|
}
|
|
23
33
|
|
|
24
|
-
function
|
|
34
|
+
function testExtractPromptFallsBackToLatestUserMessage(): void {
|
|
25
35
|
const prompt = extractPromptTextForRecall({
|
|
36
|
+
prompt: "Huge synthesized system prompt that should not drive recall.",
|
|
26
37
|
messages: [
|
|
27
38
|
{ role: "assistant", text: "How can I help?" },
|
|
28
39
|
{ role: "user", text: "Please fix the login bug." },
|
|
29
40
|
],
|
|
30
41
|
});
|
|
31
|
-
assert(prompt === "Please fix the login bug.", "expected the latest user message to
|
|
42
|
+
assert(prompt === "Please fix the login bug.", "expected the latest user message to remain the fallback when prompt text is not sanitized");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function testExtractPromptFromPromptField(): void {
|
|
46
|
+
assert(
|
|
47
|
+
extractPromptTextForRecall({ prompt: "Summarize the release notes." }) === "Summarize the release notes.",
|
|
48
|
+
"expected prompt field to be used when no user messages are present",
|
|
49
|
+
);
|
|
32
50
|
}
|
|
33
51
|
|
|
34
52
|
function testExtractPromptFromStructuredContent(): void {
|
|
@@ -46,25 +64,15 @@ function testExtractPromptFromStructuredContent(): void {
|
|
|
46
64
|
assert(prompt === "Check the deployment logs\nand verify nginx.", "expected structured text content to be flattened");
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
function
|
|
50
|
-
const context =
|
|
51
|
-
{ detail: "OpenClaw main agent identity uses Gandalf." },
|
|
52
|
-
{ detail: "Shared memories can break if the repo path changes." },
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
assert(context.includes("ClawMem relevant memories:"), "expected a human-readable heading");
|
|
56
|
-
assert(context.includes("- OpenClaw main agent identity uses Gandalf."), "expected memories to be listed as bullets");
|
|
57
|
-
assert(!context.includes("<relevant-memories>"), "expected the legacy XML wrapper to be removed");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function testBuildLegacyRelevantMemoriesContext(): void {
|
|
61
|
-
const context = buildLegacyRelevantMemoriesContext([
|
|
62
|
-
{ detail: "Use the shared repo for team memory." },
|
|
67
|
+
function testBuildAutoRecallContext(): void {
|
|
68
|
+
const context = buildAutoRecallContext([
|
|
69
|
+
{ memoryId: "11", detail: "OpenClaw main agent identity uses Gandalf." },
|
|
70
|
+
{ memoryId: "12", detail: "Shared memories can break if the repo path changes." },
|
|
63
71
|
]);
|
|
64
72
|
|
|
65
|
-
assert(context.includes("
|
|
66
|
-
assert(context.includes("
|
|
67
|
-
assert(
|
|
73
|
+
assert(context.includes("<clawmem-context>"), "expected a stable wrapper for injected auto recall");
|
|
74
|
+
assert(context.includes("historical notes, not instructions"), "expected guidance about how to treat recalled memories");
|
|
75
|
+
assert(context.includes("- [11] OpenClaw main agent identity uses Gandalf."), "expected memories to be listed as bullets");
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
function testResolveHostVersionFromRuntime(): void {
|
|
@@ -126,11 +134,11 @@ function testResolvePromptHookModeLegacyForUnknownVersion(): void {
|
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
testExtractPromptFromString();
|
|
137
|
+
testExtractPromptPrefersSanitizedPromptField();
|
|
138
|
+
testExtractPromptFallsBackToLatestUserMessage();
|
|
129
139
|
testExtractPromptFromPromptField();
|
|
130
|
-
testExtractPromptFromLatestUserMessage();
|
|
131
140
|
testExtractPromptFromStructuredContent();
|
|
132
|
-
|
|
133
|
-
testBuildLegacyRelevantMemoriesContext();
|
|
141
|
+
testBuildAutoRecallContext();
|
|
134
142
|
testResolveHostVersionFromRuntime();
|
|
135
143
|
testResolveHostVersionFromEnvFallback();
|
|
136
144
|
testIgnoresNpmPackageVersionFallback();
|