@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.
Files changed (93) hide show
  1. package/README.md +28 -16
  2. package/bm-client.ts +461 -140
  3. package/commands/cli.ts +5 -6
  4. package/commands/slash.ts +4 -4
  5. package/config.ts +5 -0
  6. package/context-engine/basic-memory-context-engine.ts +74 -9
  7. package/context-engine/types.ts +21 -0
  8. package/dist/bm-client.d.ts +101 -32
  9. package/dist/bm-client.js +346 -108
  10. package/dist/commands/cli.d.ts +1 -1
  11. package/dist/commands/cli.js +5 -5
  12. package/dist/commands/slash.d.ts +1 -1
  13. package/dist/commands/slash.js +4 -3
  14. package/dist/config.d.ts +1 -0
  15. package/dist/config.js +1 -0
  16. package/dist/context-engine/basic-memory-context-engine.d.ts +20 -1
  17. package/dist/context-engine/basic-memory-context-engine.js +50 -2
  18. package/dist/context-engine/types.d.ts +9 -0
  19. package/dist/context-engine/types.js +1 -0
  20. package/dist/index.d.ts +10 -4
  21. package/dist/index.js +78 -69
  22. package/dist/memory/basic-memory-capability.d.ts +19 -0
  23. package/dist/memory/basic-memory-capability.js +196 -0
  24. package/dist/tools/build-context.d.ts +1 -1
  25. package/dist/tools/build-context.js +12 -4
  26. package/dist/tools/delete-note.d.ts +1 -1
  27. package/dist/tools/delete-note.js +2 -1
  28. package/dist/tools/edit-note.d.ts +1 -1
  29. package/dist/tools/edit-note.js +22 -12
  30. package/dist/tools/list-memory-projects.d.ts +1 -1
  31. package/dist/tools/list-memory-projects.js +2 -1
  32. package/dist/tools/list-workspaces.d.ts +1 -1
  33. package/dist/tools/list-workspaces.js +4 -4
  34. package/dist/tools/move-note.d.ts +1 -1
  35. package/dist/tools/move-note.js +2 -1
  36. package/dist/tools/read-note.d.ts +1 -1
  37. package/dist/tools/read-note.js +2 -1
  38. package/dist/tools/schema-diff.d.ts +1 -1
  39. package/dist/tools/schema-diff.js +7 -4
  40. package/dist/tools/schema-infer.d.ts +1 -1
  41. package/dist/tools/schema-infer.js +3 -2
  42. package/dist/tools/schema-validate.d.ts +1 -1
  43. package/dist/tools/schema-validate.js +7 -5
  44. package/dist/tools/search-notes.d.ts +1 -1
  45. package/dist/tools/search-notes.js +13 -6
  46. package/dist/tools/write-note.d.ts +1 -1
  47. package/dist/tools/write-note.js +11 -12
  48. package/index.ts +92 -84
  49. package/memory/basic-memory-capability.ts +259 -0
  50. package/openclaw.plugin.json +1 -3
  51. package/package.json +6 -5
  52. package/scripts/setup-bm.sh +1 -4
  53. package/skills/manifest.json +10 -5
  54. package/skills/memory-agents/SKILL.md +23 -10
  55. package/skills/memory-capture/SKILL.md +29 -18
  56. package/skills/memory-comark/SKILL.md +17 -6
  57. package/skills/memory-continue/SKILL.md +47 -27
  58. package/skills/memory-curate/SKILL.md +40 -24
  59. package/skills/memory-defrag/SKILL.md +18 -7
  60. package/skills/memory-doctor/SKILL.md +93 -0
  61. package/skills/memory-ingest/SKILL.md +35 -18
  62. package/skills/memory-lifecycle/SKILL.md +35 -22
  63. package/skills/memory-literary-analysis/SKILL.md +112 -75
  64. package/skills/memory-metadata-search/SKILL.md +39 -28
  65. package/skills/memory-notes/SKILL.md +75 -50
  66. package/skills/memory-okf/SKILL.md +27 -15
  67. package/skills/memory-quest/SKILL.md +24 -8
  68. package/skills/memory-reflect/SKILL.md +25 -13
  69. package/skills/memory-research/SKILL.md +28 -13
  70. package/skills/memory-schema/SKILL.md +36 -24
  71. package/skills/memory-start/SKILL.md +116 -0
  72. package/skills/memory-tasks/SKILL.md +34 -22
  73. package/tools/build-context.ts +14 -5
  74. package/tools/delete-note.ts +2 -2
  75. package/tools/edit-note.ts +27 -14
  76. package/tools/list-memory-projects.ts +6 -2
  77. package/tools/list-workspaces.ts +8 -5
  78. package/tools/move-note.ts +2 -2
  79. package/tools/read-note.ts +2 -2
  80. package/tools/schema-diff.ts +9 -5
  81. package/tools/schema-infer.ts +3 -3
  82. package/tools/schema-validate.ts +7 -6
  83. package/tools/search-notes.ts +18 -7
  84. package/tools/write-note.ts +12 -12
  85. package/dist/tools/memory-provider.d.ts +0 -15
  86. package/dist/tools/memory-provider.js +0 -275
  87. package/skills/memory-onboarding/SKILL.md +0 -142
  88. package/skills/memory-onboarding/evals/evals.json +0 -29
  89. package/skills/memory-onboarding/references/assistant-setup.md +0 -72
  90. package/skills/memory-onboarding/references/conventions.md +0 -118
  91. package/skills/memory-onboarding/references/domain-playbooks.md +0 -159
  92. package/skills/memory-onboarding/references/schema-guide.md +0 -136
  93. package/tools/memory-provider.ts +0 -336
@@ -1,4 +1,4 @@
1
1
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
2
- import type { BmClient } from "../bm-client.ts";
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;
@@ -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 ? ` (${(r.score * 100).toFixed(0)}%)` : "";
23
+ const score = r.score ? ` (score ${r.score.toFixed(2)})` : "";
23
24
  console.log(`- ${r.title}${score}`);
24
- if (r.content) {
25
- const preview = r.content.length > 100
26
- ? `${r.content.slice(0, 100)}...`
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
  }
@@ -1,3 +1,3 @@
1
1
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
2
- import type { BmClient } from "../bm-client.ts";
2
+ import { type BmClient } from "../bm-client.ts";
3
3
  export declare function registerCommands(api: OpenClawPluginApi, client: BmClient): void;
@@ -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: "Failed to save memory. Is Basic Memory running?",
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 ? ` (${(r.score * 100).toFixed(0)}%)` : "";
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: "Failed to search. Is Basic Memory running?",
88
+ text: `Failed to search: ${describeToolError(err)}`,
88
89
  };
89
90
  }
90
91
  },
package/dist/config.d.ts CHANGED
@@ -4,6 +4,7 @@ export type BasicMemoryConfig = {
4
4
  memoryDir: string;
5
5
  memoryFile: string;
6
6
  projectPath: string;
7
+ projectPathConfigured: boolean;
7
8
  autoCapture: boolean;
8
9
  captureMinChars: number;
9
10
  autoRecall: boolean;
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 afterTurn path."
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
- configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
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
- } & Pick<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition, "kind" | "reload" | "nodeHostCommands" | "securityAuditCollectors">;
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 { execFileSync } from "node:child_process";
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
- export function isCommandAvailable(command) {
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
- execFileSync(command, ["--version"], { stdio: "ignore" });
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 composited memory_search",
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
- // --- Composited memory_search + memory_get (always registered) ---
58
- registerMemoryProvider(api, client, cfg);
59
- log.info("registered composited memory_search + memory_get");
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
- await client.start({ cwd: workspace });
112
- await client.ensureProject(projectPath);
113
- log.debug(`project "${cfg.project}" at ${projectPath}`);
114
- // Seed schemas if not already present
115
- for (const [name, content] of [
116
- ["Task", TASK_SCHEMA_CONTENT],
117
- ["Conversation", CONVERSATION_SCHEMA_CONTENT],
118
- ]) {
119
- try {
120
- await client.readNote(`schema/${name}`);
121
- log.debug(`${name} schema already exists, skipping seed`);
122
- }
123
- catch {
124
- try {
125
- await client.writeNote(name, content, "schema");
126
- log.debug(`seeded ${name} schema note`);
127
- }
128
- catch (err) {
129
- log.debug(`${name} schema seed failed (non-fatal)`, err);
130
- }
131
- }
132
- }
133
- setWorkspaceDir(workspace);
134
- log.info("connected — BM MCP stdio session running");
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 {};