@basicmemory/openclaw-basic-memory 0.24.1 → 1.1.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/README.md +28 -16
- package/bm-client.ts +461 -140
- package/commands/cli.ts +5 -6
- package/commands/slash.ts +4 -4
- package/config.ts +5 -0
- package/context-engine/basic-memory-context-engine.ts +74 -9
- package/context-engine/types.ts +21 -0
- package/dist/bm-client.d.ts +101 -32
- package/dist/bm-client.js +346 -108
- package/dist/commands/cli.d.ts +1 -1
- package/dist/commands/cli.js +5 -5
- package/dist/commands/slash.d.ts +1 -1
- package/dist/commands/slash.js +4 -3
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/context-engine/basic-memory-context-engine.d.ts +20 -1
- package/dist/context-engine/basic-memory-context-engine.js +50 -2
- package/dist/context-engine/types.d.ts +9 -0
- package/dist/context-engine/types.js +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +78 -69
- package/dist/memory/basic-memory-capability.d.ts +19 -0
- package/dist/memory/basic-memory-capability.js +196 -0
- package/dist/tools/build-context.d.ts +1 -1
- package/dist/tools/build-context.js +12 -4
- package/dist/tools/delete-note.d.ts +1 -1
- package/dist/tools/delete-note.js +2 -1
- package/dist/tools/edit-note.d.ts +1 -1
- package/dist/tools/edit-note.js +22 -12
- package/dist/tools/list-memory-projects.d.ts +1 -1
- package/dist/tools/list-memory-projects.js +2 -1
- package/dist/tools/list-workspaces.d.ts +1 -1
- package/dist/tools/list-workspaces.js +4 -4
- package/dist/tools/move-note.d.ts +1 -1
- package/dist/tools/move-note.js +2 -1
- package/dist/tools/read-note.d.ts +1 -1
- package/dist/tools/read-note.js +2 -1
- package/dist/tools/schema-diff.d.ts +1 -1
- package/dist/tools/schema-diff.js +7 -4
- package/dist/tools/schema-infer.d.ts +1 -1
- package/dist/tools/schema-infer.js +3 -2
- package/dist/tools/schema-validate.d.ts +1 -1
- package/dist/tools/schema-validate.js +7 -5
- package/dist/tools/search-notes.d.ts +1 -1
- package/dist/tools/search-notes.js +13 -6
- package/dist/tools/write-note.d.ts +1 -1
- package/dist/tools/write-note.js +11 -12
- package/index.ts +92 -84
- package/memory/basic-memory-capability.ts +259 -0
- package/openclaw.plugin.json +1 -3
- package/package.json +6 -5
- package/scripts/setup-bm.sh +1 -4
- package/skills/manifest.json +10 -5
- package/skills/memory-agents/SKILL.md +23 -10
- package/skills/memory-capture/SKILL.md +29 -18
- package/skills/memory-comark/SKILL.md +17 -6
- package/skills/memory-continue/SKILL.md +47 -27
- package/skills/memory-curate/SKILL.md +40 -24
- package/skills/memory-defrag/SKILL.md +18 -7
- package/skills/memory-doctor/SKILL.md +93 -0
- package/skills/memory-ingest/SKILL.md +35 -18
- package/skills/memory-lifecycle/SKILL.md +35 -22
- package/skills/memory-literary-analysis/SKILL.md +112 -75
- package/skills/memory-metadata-search/SKILL.md +39 -28
- package/skills/memory-notes/SKILL.md +75 -50
- package/skills/memory-okf/SKILL.md +27 -15
- package/skills/memory-quest/SKILL.md +24 -8
- package/skills/memory-reflect/SKILL.md +25 -13
- package/skills/memory-research/SKILL.md +28 -13
- package/skills/memory-schema/SKILL.md +36 -24
- package/skills/memory-start/SKILL.md +116 -0
- package/skills/memory-tasks/SKILL.md +34 -22
- package/tools/build-context.ts +14 -5
- package/tools/delete-note.ts +2 -2
- package/tools/edit-note.ts +27 -14
- package/tools/list-memory-projects.ts +6 -2
- package/tools/list-workspaces.ts +8 -5
- package/tools/move-note.ts +2 -2
- package/tools/read-note.ts +2 -2
- package/tools/schema-diff.ts +9 -5
- package/tools/schema-infer.ts +3 -3
- package/tools/schema-validate.ts +7 -6
- package/tools/search-notes.ts +18 -7
- package/tools/write-note.ts +12 -12
- package/dist/tools/memory-provider.d.ts +0 -15
- package/dist/tools/memory-provider.js +0 -275
- package/skills/memory-onboarding/SKILL.md +0 -142
- package/skills/memory-onboarding/evals/evals.json +0 -29
- package/skills/memory-onboarding/references/assistant-setup.md +0 -72
- package/skills/memory-onboarding/references/conventions.md +0 -118
- package/skills/memory-onboarding/references/domain-playbooks.md +0 -159
- package/skills/memory-onboarding/references/schema-guide.md +0 -136
- package/tools/memory-provider.ts +0 -336
package/dist/commands/cli.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
-
import type
|
|
2
|
+
import { type BmClient } from "../bm-client.ts";
|
|
3
3
|
import type { BasicMemoryConfig } from "../config.ts";
|
|
4
4
|
export declare function registerCli(api: OpenClawPluginApi, client: BmClient, cfg: BasicMemoryConfig): void;
|
package/dist/commands/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchResultText } from "../bm-client.js";
|
|
1
2
|
import { log } from "../logger.js";
|
|
2
3
|
export function registerCli(api, client, cfg) {
|
|
3
4
|
api.registerCli(
|
|
@@ -19,12 +20,11 @@ export function registerCli(api, client, cfg) {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
for (const r of results) {
|
|
22
|
-
const score = r.score ? ` (${
|
|
23
|
+
const score = r.score ? ` (score ${r.score.toFixed(2)})` : "";
|
|
23
24
|
console.log(`- ${r.title}${score}`);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: r.content;
|
|
25
|
+
const text = searchResultText(r);
|
|
26
|
+
if (text) {
|
|
27
|
+
const preview = text.length > 100 ? `${text.slice(0, 100)}...` : text;
|
|
28
28
|
console.log(` ${preview}`);
|
|
29
29
|
}
|
|
30
30
|
}
|
package/dist/commands/slash.d.ts
CHANGED
package/dist/commands/slash.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { describeToolError } from "../bm-client.js";
|
|
4
5
|
import { log } from "../logger.js";
|
|
5
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
7
|
export function registerCommands(api, client) {
|
|
@@ -52,7 +53,7 @@ export function registerCommands(api, client) {
|
|
|
52
53
|
catch (err) {
|
|
53
54
|
log.error("/remember failed", err);
|
|
54
55
|
return {
|
|
55
|
-
text:
|
|
56
|
+
text: `Failed to save memory: ${describeToolError(err)}`,
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
},
|
|
@@ -74,7 +75,7 @@ export function registerCommands(api, client) {
|
|
|
74
75
|
return { text: `No notes found for: "${query}"` };
|
|
75
76
|
}
|
|
76
77
|
const lines = results.map((r, i) => {
|
|
77
|
-
const score = r.score ? ` (${
|
|
78
|
+
const score = r.score ? ` (score ${r.score.toFixed(2)})` : "";
|
|
78
79
|
return `${i + 1}. ${r.title}${score}`;
|
|
79
80
|
});
|
|
80
81
|
return {
|
|
@@ -84,7 +85,7 @@ export function registerCommands(api, client) {
|
|
|
84
85
|
catch (err) {
|
|
85
86
|
log.error("/recall failed", err);
|
|
86
87
|
return {
|
|
87
|
-
text:
|
|
88
|
+
text: `Failed to search: ${describeToolError(err)}`,
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
},
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -68,6 +68,7 @@ export function parseConfig(raw) {
|
|
|
68
68
|
projectPath: typeof cfg.projectPath === "string" && cfg.projectPath.length > 0
|
|
69
69
|
? cfg.projectPath
|
|
70
70
|
: ".",
|
|
71
|
+
projectPathConfigured: typeof cfg.projectPath === "string" && cfg.projectPath.length > 0,
|
|
71
72
|
bmPath: typeof cfg.bmPath === "string" && cfg.bmPath.length > 0
|
|
72
73
|
? cfg.bmPath
|
|
73
74
|
: "bm",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { AssembleResult, BootstrapResult, CompactResult, ContextEngine, SubagentSpawnPreparation } from "openclaw/plugin-sdk";
|
|
2
1
|
import type { BmClient } from "../bm-client.ts";
|
|
3
2
|
import type { BasicMemoryConfig } from "../config.ts";
|
|
3
|
+
import type { AssembleResult, BootstrapResult, CommitTurnResult, CompactResult, ContextEngine, SubagentSpawnPreparation } from "./types.ts";
|
|
4
4
|
export declare const MAX_ASSEMBLE_RECALL_CHARS = 1200;
|
|
5
5
|
type BootstrapParams = Parameters<NonNullable<ContextEngine["bootstrap"]>>[0];
|
|
6
6
|
type AssembleParams = Parameters<ContextEngine["assemble"]>[0];
|
|
7
7
|
type AfterTurnParams = Parameters<NonNullable<ContextEngine["afterTurn"]>>[0];
|
|
8
|
+
type CommitTurnParams = Parameters<NonNullable<ContextEngine["commitTurn"]>>[0];
|
|
8
9
|
type CompactParams = Parameters<ContextEngine["compact"]>[0];
|
|
9
10
|
type PrepareSubagentSpawnParams = Parameters<NonNullable<ContextEngine["prepareSubagentSpawn"]>>[0];
|
|
10
11
|
type OnSubagentEndedParams = Parameters<NonNullable<ContextEngine["onSubagentEnded"]>>[0];
|
|
@@ -16,6 +17,10 @@ export declare class BasicMemoryContextEngine implements ContextEngine {
|
|
|
16
17
|
readonly name: "Basic Memory Context Engine";
|
|
17
18
|
readonly version: "0.1.5";
|
|
18
19
|
readonly ownsCompaction: false;
|
|
20
|
+
readonly transcriptSemantics: {
|
|
21
|
+
readonly currentTurnFence: "before-current-turn-entry-v1";
|
|
22
|
+
readonly turnAdvancementIdempotency: "atomic-idempotent-v1";
|
|
23
|
+
};
|
|
19
24
|
};
|
|
20
25
|
private readonly sessionState;
|
|
21
26
|
private readonly subagentState;
|
|
@@ -25,6 +30,20 @@ export declare class BasicMemoryContextEngine implements ContextEngine {
|
|
|
25
30
|
ingested: boolean;
|
|
26
31
|
}>;
|
|
27
32
|
assemble(params: AssembleParams): Promise<AssembleResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Capture one accepted turn on hosts with durable turn advancement.
|
|
35
|
+
*
|
|
36
|
+
* The host calls this instead of afterTurn() for admitted turns, and may
|
|
37
|
+
* call it again with the same advancement key after a crash. Errors
|
|
38
|
+
* propagate so the host keeps the turn queued and retries it.
|
|
39
|
+
*/
|
|
40
|
+
commitTurn(params: CommitTurnParams): Promise<CommitTurnResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Capture fallback for hosts that predate commitTurn().
|
|
43
|
+
*
|
|
44
|
+
* Hosts that route a turn through commitTurn() skip afterTurn() for that
|
|
45
|
+
* turn, so the two paths never record the same exchange.
|
|
46
|
+
*/
|
|
28
47
|
afterTurn(params: AfterTurnParams): Promise<void>;
|
|
29
48
|
compact(params: CompactParams): Promise<CompactResult>;
|
|
30
49
|
prepareSubagentSpawn(params: PrepareSubagentSpawnParams): Promise<SubagentSpawnPreparation | undefined>;
|
|
@@ -6,6 +6,9 @@ export const MAX_ASSEMBLE_RECALL_CHARS = 1200;
|
|
|
6
6
|
const TRUNCATED_RECALL_SUFFIX = "\n\n[Basic Memory recall truncated]";
|
|
7
7
|
const SUBAGENT_HANDOFF_FOLDER = "agent/subagents";
|
|
8
8
|
const MAX_SUBAGENT_RECALL_CHARS = 800;
|
|
9
|
+
// OpenClaw's reply for "nothing to say", used by heartbeat polls and silent
|
|
10
|
+
// maintenance turns.
|
|
11
|
+
const SILENT_REPLY_TOKEN = "NO_REPLY";
|
|
9
12
|
function boundRecallContext(context) {
|
|
10
13
|
if (context.length <= MAX_ASSEMBLE_RECALL_CHARS) {
|
|
11
14
|
return context;
|
|
@@ -15,6 +18,13 @@ function boundRecallContext(context) {
|
|
|
15
18
|
.trimEnd();
|
|
16
19
|
return `${trimmed}${TRUNCATED_RECALL_SUFFIX}`;
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Heartbeat polls and silent replies are host housekeeping, not
|
|
23
|
+
* conversation, so they are acknowledged without being recorded.
|
|
24
|
+
*/
|
|
25
|
+
function isHousekeepingTurn(isHeartbeat, turn) {
|
|
26
|
+
return (isHeartbeat === true || turn.assistantText.trim() === SILENT_REPLY_TOKEN);
|
|
27
|
+
}
|
|
18
28
|
function slugifySessionKey(sessionKey) {
|
|
19
29
|
return sessionKey
|
|
20
30
|
.toLowerCase()
|
|
@@ -43,7 +53,7 @@ function buildSubagentHandoffContent(params) {
|
|
|
43
53
|
}
|
|
44
54
|
function buildSubagentCompletionUpdate(params) {
|
|
45
55
|
const statusLine = params.reason === "completed"
|
|
46
|
-
? "Child run completed. Durable conversation capture continues through the normal
|
|
56
|
+
? "Child run completed. Durable conversation capture continues through the normal turn commit path."
|
|
47
57
|
: `Child run ended with reason: ${params.reason}.`;
|
|
48
58
|
return [
|
|
49
59
|
"",
|
|
@@ -63,6 +73,18 @@ export class BasicMemoryContextEngine {
|
|
|
63
73
|
name: "Basic Memory Context Engine",
|
|
64
74
|
version: "0.1.5",
|
|
65
75
|
ownsCompaction: false,
|
|
76
|
+
// OpenClaw 2026.10+ runs an engine for durable turns only when it
|
|
77
|
+
// declares both semantics; otherwise the turn degrades to "legacy" and
|
|
78
|
+
// nothing is captured (#1880).
|
|
79
|
+
// - The fence holds because assemble() passes the host's messages through
|
|
80
|
+
// unchanged and the engine keeps no transcript of its own, so it never
|
|
81
|
+
// reads past the admitted user entry.
|
|
82
|
+
// - Advancement is idempotent because commitTurn() records the
|
|
83
|
+
// advancement key in the conversation note and skips keys it has seen.
|
|
84
|
+
transcriptSemantics: {
|
|
85
|
+
currentTurnFence: "before-current-turn-entry-v1",
|
|
86
|
+
turnAdvancementIdempotency: "atomic-idempotent-v1",
|
|
87
|
+
},
|
|
66
88
|
};
|
|
67
89
|
sessionState = new Map();
|
|
68
90
|
subagentState = new Map();
|
|
@@ -104,13 +126,39 @@ export class BasicMemoryContextEngine {
|
|
|
104
126
|
systemPromptAddition: state?.recallContext,
|
|
105
127
|
};
|
|
106
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Capture one accepted turn on hosts with durable turn advancement.
|
|
131
|
+
*
|
|
132
|
+
* The host calls this instead of afterTurn() for admitted turns, and may
|
|
133
|
+
* call it again with the same advancement key after a crash. Errors
|
|
134
|
+
* propagate so the host keeps the turn queued and retries it.
|
|
135
|
+
*/
|
|
136
|
+
async commitTurn(params) {
|
|
137
|
+
if (!this.cfg.autoCapture)
|
|
138
|
+
return { status: "committed" };
|
|
139
|
+
// messages spans exactly the admitted user entry through the terminal
|
|
140
|
+
// entry, so the whole payload is the current turn.
|
|
141
|
+
const turn = selectCaptureTurn(params.messages, this.cfg.captureMinChars);
|
|
142
|
+
if (!turn || isHousekeepingTurn(params.isHeartbeat, turn)) {
|
|
143
|
+
return { status: "committed" };
|
|
144
|
+
}
|
|
145
|
+
log.debug(`context-engine commitTurn: session=${params.sessionId} user=${turn.userText.length} assistant=${turn.assistantText.length}`);
|
|
146
|
+
const status = await this.client.indexConversation(turn.userText, turn.assistantText, { turnKey: params.advancementKey });
|
|
147
|
+
return { status };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Capture fallback for hosts that predate commitTurn().
|
|
151
|
+
*
|
|
152
|
+
* Hosts that route a turn through commitTurn() skip afterTurn() for that
|
|
153
|
+
* turn, so the two paths never record the same exchange.
|
|
154
|
+
*/
|
|
107
155
|
async afterTurn(params) {
|
|
108
156
|
if (!this.cfg.autoCapture)
|
|
109
157
|
return;
|
|
110
158
|
const newMessages = params.messages.slice(params.prePromptMessageCount);
|
|
111
159
|
const turn = selectCaptureTurn(newMessages, this.cfg.captureMinChars) ??
|
|
112
160
|
selectCaptureTurn(params.messages, this.cfg.captureMinChars);
|
|
113
|
-
if (!turn)
|
|
161
|
+
if (!turn || isHousekeepingTurn(params.isHeartbeat, turn))
|
|
114
162
|
return;
|
|
115
163
|
log.debug(`context-engine afterTurn: session=${params.sessionId} user=${turn.userText.length} assistant=${turn.assistantText.length}`);
|
|
116
164
|
try {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
|
2
|
+
type ContextEngineFactory = Parameters<OpenClawPluginApi["registerContextEngine"]>[1];
|
|
3
|
+
export type ContextEngine = Awaited<ReturnType<ContextEngineFactory>>;
|
|
4
|
+
export type AssembleResult = Awaited<ReturnType<ContextEngine["assemble"]>>;
|
|
5
|
+
export type BootstrapResult = Awaited<ReturnType<NonNullable<ContextEngine["bootstrap"]>>>;
|
|
6
|
+
export type CompactResult = Awaited<ReturnType<ContextEngine["compact"]>>;
|
|
7
|
+
export type SubagentSpawnPreparation = NonNullable<Awaited<ReturnType<NonNullable<ContextEngine["prepareSubagentSpawn"]>>>>;
|
|
8
|
+
export type CommitTurnResult = Awaited<ReturnType<NonNullable<ContextEngine["commitTurn"]>>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
export declare function isCommandAvailable(command: string): boolean
|
|
2
|
-
declare const _default: {
|
|
1
|
+
export declare function isCommandAvailable(command: string): Promise<boolean>;
|
|
2
|
+
declare const _default: Omit<{
|
|
3
3
|
id: string;
|
|
4
4
|
name: string;
|
|
5
5
|
description: string;
|
|
6
|
-
|
|
6
|
+
kind?: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["kind"];
|
|
7
|
+
configSchema?: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginConfigSchema | (() => import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginConfigSchema);
|
|
8
|
+
reload?: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["reload"];
|
|
9
|
+
nodeHostCommands?: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["nodeHostCommands"];
|
|
10
|
+
securityAuditCollectors?: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["securityAuditCollectors"];
|
|
7
11
|
register: NonNullable<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["register"]>;
|
|
8
|
-
}
|
|
12
|
+
}, "configSchema"> & {
|
|
13
|
+
configSchema: import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginConfigSchema;
|
|
14
|
+
};
|
|
9
15
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { promisify } from "node:util";
|
|
2
4
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
5
|
import { BmClient } from "./bm-client.js";
|
|
4
6
|
import { registerCli } from "./commands/cli.js";
|
|
@@ -7,6 +9,7 @@ import { registerCommands } from "./commands/slash.js";
|
|
|
7
9
|
import { basicMemoryConfigSchema, parseConfig, resolveProjectPath, } from "./config.js";
|
|
8
10
|
import { BasicMemoryContextEngine } from "./context-engine/basic-memory-context-engine.js";
|
|
9
11
|
import { initLogger, log } from "./logger.js";
|
|
12
|
+
import { buildBasicMemoryCapability } from "./memory/basic-memory-capability.js";
|
|
10
13
|
import { CONVERSATION_SCHEMA_CONTENT } from "./schema/conversation-schema.js";
|
|
11
14
|
import { TASK_SCHEMA_CONTENT } from "./schema/task-schema.js";
|
|
12
15
|
import { registerContextTool } from "./tools/build-context.js";
|
|
@@ -14,7 +17,6 @@ import { registerDeleteTool } from "./tools/delete-note.js";
|
|
|
14
17
|
import { registerEditTool } from "./tools/edit-note.js";
|
|
15
18
|
import { registerProjectListTool } from "./tools/list-memory-projects.js";
|
|
16
19
|
import { registerWorkspaceListTool } from "./tools/list-workspaces.js";
|
|
17
|
-
import { registerMemoryProvider, setWorkspaceDir, } from "./tools/memory-provider.js";
|
|
18
20
|
import { registerMoveTool } from "./tools/move-note.js";
|
|
19
21
|
import { registerReadTool } from "./tools/read-note.js";
|
|
20
22
|
import { registerSchemaDiffTool } from "./tools/schema-diff.js";
|
|
@@ -22,19 +24,58 @@ import { registerSchemaInferTool } from "./tools/schema-infer.js";
|
|
|
22
24
|
import { registerSchemaValidateTool } from "./tools/schema-validate.js";
|
|
23
25
|
import { registerSearchTool } from "./tools/search-notes.js";
|
|
24
26
|
import { registerWriteTool } from "./tools/write-note.js";
|
|
25
|
-
|
|
27
|
+
const execFileAsync = promisify(execFile);
|
|
28
|
+
// Async so a probe or an install never blocks OpenClaw's event loop during
|
|
29
|
+
// plugin startup.
|
|
30
|
+
export async function isCommandAvailable(command) {
|
|
26
31
|
try {
|
|
27
|
-
|
|
32
|
+
await execFileAsync(command, ["--version"]);
|
|
28
33
|
return true;
|
|
29
34
|
}
|
|
30
35
|
catch {
|
|
31
36
|
return false;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
39
|
+
async function installBasicMemoryIfMissing(bmBin) {
|
|
40
|
+
if (await isCommandAvailable(bmBin))
|
|
41
|
+
return;
|
|
42
|
+
log.info("bm CLI not found on PATH — attempting auto-install...");
|
|
43
|
+
if (!(await isCommandAvailable("uv"))) {
|
|
44
|
+
throw new Error("Cannot auto-install basic-memory: uv not found. " +
|
|
45
|
+
"Install uv first (brew install uv, or curl -LsSf https://astral.sh/uv/install.sh | sh), " +
|
|
46
|
+
"then restart the gateway.");
|
|
47
|
+
}
|
|
48
|
+
log.info("installing basic-memory via uv (this may take a minute)...");
|
|
49
|
+
const { stdout } = await execFileAsync("uv", ["tool", "install", "basic-memory", "--force"], { encoding: "utf-8", timeout: 120_000 });
|
|
50
|
+
log.info(`basic-memory installed: ${stdout.trim().split("\n").pop()}`);
|
|
51
|
+
if (!(await isCommandAvailable(bmBin))) {
|
|
52
|
+
throw new Error("bm installed but not found on PATH. You may need to add uv's bin directory to your PATH (typically ~/.local/bin).");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function seedSchemas(client) {
|
|
56
|
+
for (const [name, content] of [
|
|
57
|
+
["Task", TASK_SCHEMA_CONTENT],
|
|
58
|
+
["Conversation", CONVERSATION_SCHEMA_CONTENT],
|
|
59
|
+
]) {
|
|
60
|
+
try {
|
|
61
|
+
await client.readNote(`schema/${name}`);
|
|
62
|
+
log.debug(`${name} schema already exists, skipping seed`);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
try {
|
|
66
|
+
await client.writeNote(name, content, "schema");
|
|
67
|
+
log.debug(`seeded ${name} schema note`);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
log.debug(`${name} schema seed failed (non-fatal)`, err);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
34
75
|
export default definePluginEntry({
|
|
35
76
|
id: "openclaw-basic-memory",
|
|
36
77
|
name: "Basic Memory",
|
|
37
|
-
description: "Local-first knowledge graph for OpenClaw — persistent memory with graph search and
|
|
78
|
+
description: "Local-first knowledge graph for OpenClaw — persistent memory with graph search, recall and conversation capture",
|
|
38
79
|
configSchema: basicMemoryConfigSchema,
|
|
39
80
|
register(api) {
|
|
40
81
|
const cfg = parseConfig(api.pluginConfig);
|
|
@@ -54,9 +95,14 @@ export default definePluginEntry({
|
|
|
54
95
|
registerSchemaValidateTool(api, client);
|
|
55
96
|
registerSchemaInferTool(api, client);
|
|
56
97
|
registerSchemaDiffTool(api, client);
|
|
57
|
-
// ---
|
|
58
|
-
|
|
59
|
-
|
|
98
|
+
// --- Memory capability ---
|
|
99
|
+
// OpenClaw 2026.10 owns the memory_search and memory_get tool names
|
|
100
|
+
// (memory-core registers them even when another plugin holds the memory
|
|
101
|
+
// slot), so the plugin serves the host through registerMemoryCapability:
|
|
102
|
+
// gateway memory search, status and doctor, Active Memory recall, and the
|
|
103
|
+
// pre-compaction flush.
|
|
104
|
+
api.registerMemoryCapability(buildBasicMemoryCapability(client));
|
|
105
|
+
log.info("registered Basic Memory memory capability");
|
|
60
106
|
api.registerContextEngine("openclaw-basic-memory", () => new BasicMemoryContextEngine(client, cfg));
|
|
61
107
|
log.info("registered Basic Memory context engine");
|
|
62
108
|
// --- Commands ---
|
|
@@ -68,70 +114,33 @@ export default definePluginEntry({
|
|
|
68
114
|
id: "openclaw-basic-memory",
|
|
69
115
|
start: async (ctx) => {
|
|
70
116
|
log.info("starting...");
|
|
71
|
-
// Auto-install bm CLI if not found
|
|
72
|
-
const bmBin = cfg.bmPath || "bm";
|
|
73
|
-
if (!isCommandAvailable(bmBin)) {
|
|
74
|
-
log.info("bm CLI not found on PATH — attempting auto-install...");
|
|
75
|
-
try {
|
|
76
|
-
if (!isCommandAvailable("uv")) {
|
|
77
|
-
throw new Error("uv not found");
|
|
78
|
-
}
|
|
79
|
-
log.info("installing basic-memory via uv (this may take a minute)...");
|
|
80
|
-
// basic-memory pins a FastMCP pre-release; without this flag uv
|
|
81
|
-
// silently installs the last release that had none (#1338).
|
|
82
|
-
const result = execFileSync("uv", [
|
|
83
|
-
"tool",
|
|
84
|
-
"install",
|
|
85
|
-
"basic-memory",
|
|
86
|
-
"--prerelease=allow",
|
|
87
|
-
"--force",
|
|
88
|
-
], {
|
|
89
|
-
encoding: "utf-8",
|
|
90
|
-
timeout: 120_000,
|
|
91
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
92
|
-
});
|
|
93
|
-
log.info(`basic-memory installed: ${result.trim().split("\n").pop()}`);
|
|
94
|
-
// Verify it worked
|
|
95
|
-
if (isCommandAvailable(bmBin)) {
|
|
96
|
-
log.info("bm CLI now available on PATH");
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
log.error("bm installed but not found on PATH. You may need to add uv's bin directory to your PATH (typically ~/.local/bin).");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (_uvErr) {
|
|
103
|
-
log.error("Cannot auto-install basic-memory: uv not found. " +
|
|
104
|
-
"Install uv first (brew install uv, or curl -LsSf https://astral.sh/uv/install.sh | sh), " +
|
|
105
|
-
"then restart the gateway.");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
117
|
const workspace = ctx.workspaceDir ?? process.cwd();
|
|
109
118
|
const projectPath = resolveProjectPath(cfg.projectPath, workspace);
|
|
110
119
|
cfg.projectPath = projectPath;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
120
|
+
// bm runs with the workspace as its working directory. OpenClaw
|
|
121
|
+
// creates its default workspace only on the first agent run, and
|
|
122
|
+
// spawning into a missing directory fails with an ENOENT that names
|
|
123
|
+
// the bm binary instead of the directory.
|
|
124
|
+
await mkdir(workspace, { recursive: true });
|
|
125
|
+
// OpenClaw gives a service about 5 s to start. A first start (bm
|
|
126
|
+
// install, cold imports, first indexing) takes far longer, and a
|
|
127
|
+
// timed-out start fails the plugin. So startup runs in the
|
|
128
|
+
// background; tool calls wait for it inside BmClient, and a failed
|
|
129
|
+
// startup is retried by the next tool call instead of failing here.
|
|
130
|
+
client
|
|
131
|
+
.start({
|
|
132
|
+
cwd: workspace,
|
|
133
|
+
projectPath,
|
|
134
|
+
adoptExistingProject: !cfg.projectPathConfigured,
|
|
135
|
+
prepare: () => installBasicMemoryIfMissing(cfg.bmPath || "bm"),
|
|
136
|
+
})
|
|
137
|
+
.then(async () => {
|
|
138
|
+
log.info("connected — BM MCP stdio session running");
|
|
139
|
+
await seedSchemas(client);
|
|
140
|
+
})
|
|
141
|
+
.catch((err) => {
|
|
142
|
+
log.error("Basic Memory startup failed; the next tool call will retry", err);
|
|
143
|
+
});
|
|
135
144
|
},
|
|
136
145
|
stop: async () => {
|
|
137
146
|
log.info("stopping BM MCP session...");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MemoryPluginCapability } from "openclaw/plugin-sdk/memory-host-core";
|
|
2
|
+
import { type BmClient } from "../bm-client.ts";
|
|
3
|
+
type MemoryProviderRuntime = NonNullable<MemoryPluginCapability["providerRuntime"]>;
|
|
4
|
+
type MemoryProviderHandle = NonNullable<Awaited<ReturnType<MemoryProviderRuntime["open"]>>["provider"]>;
|
|
5
|
+
type MemoryCallerContext = Parameters<MemoryProviderRuntime["open"]>[0]["context"];
|
|
6
|
+
export declare const MEMORY_PROVIDER_ID = "openclaw-basic-memory";
|
|
7
|
+
export declare const RECALL_TOOL_NAMES: readonly ["search_notes", "read_note", "build_context"];
|
|
8
|
+
/**
|
|
9
|
+
* Open a caller-bound reader over the plugin's shared BM MCP session.
|
|
10
|
+
*
|
|
11
|
+
* The host rechecks the caller's authority around every provider call;
|
|
12
|
+
* context.assertCurrent() is also called before and after each BM request so
|
|
13
|
+
* a revoked caller is refused rather than served. Every note in the project
|
|
14
|
+
* is visible to every caller, which matches what the plugin's own
|
|
15
|
+
* search_notes and read_note tools already expose.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openBasicMemoryReader(client: BmClient, context: MemoryCallerContext): MemoryProviderHandle;
|
|
18
|
+
export declare function buildBasicMemoryCapability(client: BmClient): MemoryPluginCapability;
|
|
19
|
+
export {};
|