@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
@@ -0,0 +1,196 @@
1
+ import { isNoteNotFoundError, searchResultText, } from "../bm-client.js";
2
+ import { log } from "../logger.js";
3
+ export const MEMORY_PROVIDER_ID = "openclaw-basic-memory";
4
+ // Agent tools this plugin registers that Active Memory may use for deep
5
+ // recall, and that the pre-compaction flush may use to look before writing.
6
+ export const RECALL_TOOL_NAMES = [
7
+ "search_notes",
8
+ "read_note",
9
+ "build_context",
10
+ ];
11
+ const FLUSH_PERSISTENCE_TOOL_NAMES = ["write_note", "edit_note"];
12
+ const FLUSH_LOOKUP_TOOL_NAMES = ["search_notes", "read_note"];
13
+ const DEFAULT_MAX_RESULTS = 10;
14
+ const MAX_EXCERPT_CHARS = 700;
15
+ // memory-core's flush prompts use the same token for "nothing to save".
16
+ const SILENT_REPLY_TOKEN = "NO_REPLY";
17
+ // --- Search and retrieval ---
18
+ /**
19
+ * Basic Memory fuses keyword and vector scores into [0, 1.3] (see
20
+ * search_reader.py FUSION_BONUS). OpenClaw compares provider scores against a
21
+ * caller's minScore on a 0–1 scale, so a fused score above 1 is capped at 1.
22
+ */
23
+ function hostScore(score) {
24
+ return score === undefined ? undefined : Math.min(score, 1);
25
+ }
26
+ function excerptOf(content) {
27
+ return content.length > MAX_EXCERPT_CHARS
28
+ ? `${content.slice(0, MAX_EXCERPT_CHARS)}…`
29
+ : content;
30
+ }
31
+ /**
32
+ * Apply the host's optional line window to a note body. `from` is 1-based,
33
+ * matching the host's memory_get contract.
34
+ */
35
+ function sliceLines(text, from, lines) {
36
+ if (from === undefined && lines === undefined)
37
+ return { text };
38
+ const all = text.split("\n");
39
+ const start = Math.max(1, from ?? 1);
40
+ const count = lines ?? all.length - start + 1;
41
+ const window = all.slice(start - 1, start - 1 + count);
42
+ const end = start - 1 + window.length;
43
+ const truncated = end < all.length;
44
+ return {
45
+ text: window.join("\n"),
46
+ from: start,
47
+ lines: window.length,
48
+ truncated,
49
+ ...(truncated ? { nextFrom: end + 1 } : {}),
50
+ };
51
+ }
52
+ /**
53
+ * Open a caller-bound reader over the plugin's shared BM MCP session.
54
+ *
55
+ * The host rechecks the caller's authority around every provider call;
56
+ * context.assertCurrent() is also called before and after each BM request so
57
+ * a revoked caller is refused rather than served. Every note in the project
58
+ * is visible to every caller, which matches what the plugin's own
59
+ * search_notes and read_note tools already expose.
60
+ */
61
+ export function openBasicMemoryReader(client, context) {
62
+ const guarded = async (run) => {
63
+ context.assertCurrent();
64
+ const result = await run();
65
+ context.assertCurrent();
66
+ return result;
67
+ };
68
+ // Trigger: the reader opens while the plugin service is not running, as in
69
+ // one-shot CLI commands like `openclaw memory status`.
70
+ // Why: the first BM call then spawns a `bm mcp` child that nothing else
71
+ // will stop, and its open pipes keep the CLI process from exiting.
72
+ // Outcome: this reader owns that connection and stops it on close().
73
+ const ownsConnection = !client.isServiceRunning();
74
+ return {
75
+ capabilities: {
76
+ sources: ["memory"],
77
+ pagination: false,
78
+ candidates: [],
79
+ projectFilter: false,
80
+ },
81
+ async search(request) {
82
+ const results = await guarded(() => client.search(request.query, request.maxResults ?? DEFAULT_MAX_RESULTS));
83
+ const hits = results
84
+ .map((result) => ({ result, score: hostScore(result.score) }))
85
+ // Trigger: the caller set a score floor.
86
+ // Why: the host contract requires every provider to enforce minScore.
87
+ // Outcome: unscored or lower-scored hits are dropped.
88
+ .filter(({ score }) => request.minScore === undefined ||
89
+ (score !== undefined && score >= request.minScore))
90
+ .map(({ result, score }) => ({
91
+ reference: { providerId: MEMORY_PROVIDER_ID, id: result.permalink },
92
+ excerpt: excerptOf(searchResultText(result)),
93
+ source: result.file_path,
94
+ ...(score === undefined ? {} : { score }),
95
+ }));
96
+ return { hits };
97
+ },
98
+ async get(request) {
99
+ try {
100
+ const note = await guarded(() => client.readNote(request.reference.id));
101
+ return {
102
+ status: "ok",
103
+ reference: { providerId: MEMORY_PROVIDER_ID, id: note.permalink },
104
+ ...sliceLines(note.content, request.from, request.lines),
105
+ };
106
+ }
107
+ catch (err) {
108
+ // A missing note is an answer; any other failure must surface so the
109
+ // host does not report it as an empty success.
110
+ if (isNoteNotFoundError(err))
111
+ return { status: "not_found" };
112
+ throw err;
113
+ }
114
+ },
115
+ async health() {
116
+ // Listing projects proves the BM MCP session answers without reading
117
+ // any note content, so it is safe for status-only callers.
118
+ try {
119
+ await guarded(() => client.listProjects());
120
+ }
121
+ catch (err) {
122
+ log.warn(`memory health check failed: ${err instanceof Error ? err.message : String(err)}`);
123
+ return {
124
+ status: "unavailable",
125
+ message: "Basic Memory is not reachable",
126
+ };
127
+ }
128
+ // Listing works even when BM refused the plugin's project, so the
129
+ // refusal is checked separately; every search and read would fail.
130
+ const projectProblem = client.projectUnavailableReason();
131
+ if (projectProblem) {
132
+ return { status: "unavailable", message: projectProblem };
133
+ }
134
+ return { status: "ready" };
135
+ },
136
+ // In the gateway the BM MCP session is shared by the whole plugin and
137
+ // owned by its service, so closing one caller's reader releases nothing.
138
+ async close() {
139
+ if (ownsConnection)
140
+ await client.stop();
141
+ },
142
+ };
143
+ }
144
+ // --- Pre-compaction flush ---
145
+ const FLUSH_PROMPT = [
146
+ "Pre-compaction memory flush.",
147
+ "Save durable facts, decisions and open tasks from this session to Basic Memory.",
148
+ "Use search_notes or read_note first to find an existing note, then edit_note to update it;",
149
+ "use write_note only for a new topic.",
150
+ `If nothing is worth saving, reply with ${SILENT_REPLY_TOKEN}.`,
151
+ ].join(" ");
152
+ const FLUSH_SYSTEM_PROMPT = [
153
+ "Pre-compaction memory flush turn.",
154
+ "The session is near auto-compaction; capture durable memories in Basic Memory with write_note or edit_note.",
155
+ `You may reply, but usually ${SILENT_REPLY_TOKEN} is correct.`,
156
+ ].join(" ");
157
+ // Returning a tools-arm plan makes the host persist through this plugin's own
158
+ // tools instead of appending to a workspace memory file. The host has already
159
+ // honored agents.defaults.compaction.memoryFlush.enabled before calling this.
160
+ const resolveFlushPlan = () => ({
161
+ prompt: FLUSH_PROMPT,
162
+ systemPrompt: FLUSH_SYSTEM_PROMPT,
163
+ persistenceToolNames: FLUSH_PERSISTENCE_TOOL_NAMES,
164
+ lookupToolNames: FLUSH_LOOKUP_TOOL_NAMES,
165
+ });
166
+ // --- Prompt guidance ---
167
+ /**
168
+ * OpenClaw fills any capability field the slot owner leaves empty from other
169
+ * memory registrations, including memory-core's prompt section, which points
170
+ * agents at its file-only memory_search. Supplying our own section keeps the
171
+ * agent's guidance on the Basic Memory tools.
172
+ */
173
+ function buildPromptSection(params) {
174
+ if (!params.availableTools.has("search_notes"))
175
+ return [];
176
+ return [
177
+ "## Basic Memory",
178
+ "Long-term memory lives in Basic Memory, a knowledge graph of Markdown notes.",
179
+ "Before answering questions about prior work, decisions, people or preferences, search it with search_notes and read the best match with read_note.",
180
+ "Earlier conversations are saved automatically in daily conversation notes.",
181
+ "memory_search and memory_get cover only the workspace MEMORY.md and memory/ files, not Basic Memory.",
182
+ ];
183
+ }
184
+ // --- Capability ---
185
+ export function buildBasicMemoryCapability(client) {
186
+ return {
187
+ providerRuntime: {
188
+ async open({ context }) {
189
+ return { provider: openBasicMemoryReader(client, context) };
190
+ },
191
+ },
192
+ recallToolNames: RECALL_TOOL_NAMES,
193
+ providerFlushPlanResolver: resolveFlushPlan,
194
+ promptBuilder: buildPromptSection,
195
+ };
196
+ }
@@ -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 registerContextTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerContextTool(api, client) {
4
5
  api.registerTool({
@@ -42,8 +43,13 @@ export function registerContextTool(api, client) {
42
43
  for (const result of ctx.results) {
43
44
  const primary = result.primary_result;
44
45
  sections.push(`## ${primary.title}\n${primary.content}`);
45
- if (result.observations?.length > 0) {
46
- const obs = result.observations
46
+ // The note body already contains its observations as
47
+ // "- [category] text" lines, so listing them again doubled the
48
+ // output. Only observations missing from the shown body (for
49
+ // example when the server truncates a long note) are listed.
50
+ const unseen = (result.observations ?? []).filter((o) => !primary.content?.includes(`[${o.category}] ${o.content}`));
51
+ if (unseen.length > 0) {
52
+ const obs = unseen
47
53
  .map((o) => `- [${o.category}] ${o.content}`)
48
54
  .join("\n");
49
55
  sections.push(`### Observations\n${obs}`);
@@ -52,7 +58,9 @@ export function registerContextTool(api, client) {
52
58
  const rels = result.related_results
53
59
  .map((r) => {
54
60
  if (r.type === "relation") {
55
- return `- ${r.relation_type} → **${r.to_entity}**`;
61
+ return r.to_entity
62
+ ? `- ${r.relation_type} → **${r.to_entity}**`
63
+ : `- ${r.relation_type} → **${r.to_name ?? "unknown"}** (no note yet)`;
56
64
  }
57
65
  const label = r.relation_type
58
66
  ? `${r.relation_type} → **${r.title}**`
@@ -85,7 +93,7 @@ export function registerContextTool(api, client) {
85
93
  content: [
86
94
  {
87
95
  type: "text",
88
- text: `Failed to build context for "${params.url}". Check logs for details.`,
96
+ text: `Failed to build context for "${params.url}": ${describeToolError(err)}`,
89
97
  },
90
98
  ],
91
99
  details: {
@@ -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 registerDeleteTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeNoteError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerDeleteTool(api, client) {
4
5
  api.registerTool({
@@ -38,7 +39,7 @@ export function registerDeleteTool(api, client) {
38
39
  content: [
39
40
  {
40
41
  type: "text",
41
- text: `Failed to delete "${params.identifier}". It may not exist.`,
42
+ text: `Failed to delete "${params.identifier}": ${describeNoteError(err)}`,
42
43
  },
43
44
  ],
44
45
  details: {
@@ -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 registerEditTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,12 +1,16 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeNoteError, } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerEditTool(api, client) {
4
5
  api.registerTool({
5
6
  name: "edit_note",
6
7
  label: "Edit Note",
7
8
  description: "Incrementally edit an existing note in the Basic Memory knowledge graph. " +
8
- "Supports append, prepend, find/replace, and section replacement " +
9
- "without rewriting the entire note. The result returns the note's " +
9
+ "Supports append, prepend, find/replace, replacing a section, and inserting " +
10
+ "next to a section heading, without rewriting the entire note. To add to a " +
11
+ "specific section (for example a new observation), use insert_after_section " +
12
+ "with that heading; append always adds to the very end of the note. " +
13
+ "The result returns the note's " +
10
14
  "permalink and file_path: cite those exact values when confirming " +
11
15
  "the edit — never report a save that no tool call performed.",
12
16
  parameters: Type.Object({
@@ -18,9 +22,13 @@ export function registerEditTool(api, client) {
18
22
  Type.Literal("prepend"),
19
23
  Type.Literal("find_replace"),
20
24
  Type.Literal("replace_section"),
25
+ Type.Literal("insert_before_section"),
26
+ Type.Literal("insert_after_section"),
21
27
  ], {
22
- description: "Edit operation: append (add to end), prepend (add to start), " +
23
- "find_replace (replace matching text), replace_section (replace a heading section)",
28
+ description: "Edit operation: append (add to end of note), prepend (add to start), " +
29
+ "find_replace (replace matching text), replace_section (replace a heading section), " +
30
+ "insert_after_section (add directly below a heading, at the top of its section), " +
31
+ "insert_before_section (add directly above a heading, at the end of the section before it)",
24
32
  }),
25
33
  content: Type.String({
26
34
  description: "New content to add or replace with",
@@ -29,7 +37,8 @@ export function registerEditTool(api, client) {
29
37
  description: "Text to find (required for find_replace)",
30
38
  })),
31
39
  section: Type.Optional(Type.String({
32
- description: "Section heading to replace (required for replace_section)",
40
+ description: "Section heading, e.g. 'Observations' (required for replace_section, " +
41
+ "insert_before_section and insert_after_section; not allowed with other operations)",
33
42
  })),
34
43
  expected_replacements: Type.Optional(Type.Number({
35
44
  description: "Expected replacement count for find_replace (default: 1)",
@@ -55,7 +64,7 @@ export function registerEditTool(api, client) {
55
64
  content: [
56
65
  {
57
66
  type: "text",
58
- text: `Note updated: ${note.title} (${note.permalink})`,
67
+ text: `Note updated: ${note.title} (${note.permalink})\nFile: ${note.file_path}`,
59
68
  },
60
69
  ],
61
70
  details: {
@@ -69,13 +78,14 @@ export function registerEditTool(api, client) {
69
78
  }
70
79
  catch (err) {
71
80
  log.error("edit_note failed", err);
81
+ // Trigger: any edit failure, including invalid arguments and
82
+ // checksum conflicts, not only a missing note.
83
+ // Why: a blanket "may not exist" sent agents hunting for the wrong
84
+ // problem; the server's message says what to change.
85
+ // Outcome: the agent sees the server's reason verbatim.
86
+ const text = `Failed to edit note "${params.identifier}": ${describeNoteError(err)}`;
72
87
  return {
73
- content: [
74
- {
75
- type: "text",
76
- text: `Failed to edit note "${params.identifier}". It may not exist.`,
77
- },
78
- ],
88
+ content: [{ type: "text", text }],
79
89
  details: {
80
90
  identifier: params.identifier,
81
91
  operation: params.operation,
@@ -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 registerProjectListTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError, } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  function normalizeProject(project) {
4
5
  return {
@@ -88,7 +89,7 @@ export function registerProjectListTool(api, client) {
88
89
  content: [
89
90
  {
90
91
  type: "text",
91
- text: "Failed to list Basic Memory projects. Is Basic Memory running? Check logs for details.",
92
+ text: `Failed to list Basic Memory projects: ${describeToolError(err)}`,
92
93
  },
93
94
  ],
94
95
  details: {
@@ -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 registerWorkspaceListTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,15 +1,15 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError, } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  function formatWorkspace(ws, idx) {
4
- const subscription = ws.has_active_subscription ? "active" : "none";
5
5
  return (`${idx + 1}. **${ws.name}**\n` +
6
- ` Type: ${ws.workspace_type} | Role: ${ws.role} | Subscription: ${subscription}`);
6
+ ` Type: ${ws.workspace_type ?? "unknown"}`);
7
7
  }
8
8
  export function registerWorkspaceListTool(api, client) {
9
9
  api.registerTool({
10
10
  name: "list_workspaces",
11
11
  label: "List Workspaces",
12
- description: "List all Basic Memory workspaces (personal and organization) accessible to this user. " +
12
+ description: "List workspaces represented by accessible Basic Memory projects. " +
13
13
  "Use it to find the workspace to pass to list_memory_projects when the same " +
14
14
  "project name may exist in more than one workspace.",
15
15
  parameters: Type.Object({}),
@@ -51,7 +51,7 @@ export function registerWorkspaceListTool(api, client) {
51
51
  content: [
52
52
  {
53
53
  type: "text",
54
- text: "Failed to list workspaces. Is Basic Memory running? Check logs for details.",
54
+ text: `Failed to list workspaces: ${describeToolError(err)}`,
55
55
  },
56
56
  ],
57
57
  details: {
@@ -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 registerMoveTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeNoteError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerMoveTool(api, client) {
4
5
  api.registerTool({
@@ -41,7 +42,7 @@ export function registerMoveTool(api, client) {
41
42
  content: [
42
43
  {
43
44
  type: "text",
44
- text: `Failed to move "${params.identifier}". It may not exist.`,
45
+ text: `Failed to move "${params.identifier}": ${describeNoteError(err)}`,
45
46
  },
46
47
  ],
47
48
  details: {
@@ -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 registerReadTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeNoteError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerReadTool(api, client) {
4
5
  api.registerTool({
@@ -57,7 +58,7 @@ export function registerReadTool(api, client) {
57
58
  content: [
58
59
  {
59
60
  type: "text",
60
- text: `Could not read note "${params.identifier}". It may not exist yet.`,
61
+ text: `Could not read note "${params.identifier}": ${describeNoteError(err)}`,
61
62
  },
62
63
  ],
63
64
  details: {
@@ -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 registerSchemaDiffTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerSchemaDiffTool(api, client) {
4
5
  api.registerTool({
@@ -30,7 +31,7 @@ export function registerSchemaDiffTool(api, client) {
30
31
  details: result,
31
32
  };
32
33
  }
33
- const lines = [`**Type:** ${result.entity_type}`];
34
+ const lines = [`**Type:** ${result.note_type}`];
34
35
  if (result.new_fields.length === 0 &&
35
36
  result.dropped_fields.length === 0 &&
36
37
  result.cardinality_changes.length === 0) {
@@ -44,9 +45,11 @@ export function registerSchemaDiffTool(api, client) {
44
45
  }
45
46
  }
46
47
  if (result.dropped_fields.length > 0) {
47
- lines.push("", "### Dropped Fields (in schema, not in notes)");
48
+ // A dropped field can still appear in a few notes, so report how
49
+ // often it does, as BM's own drift report does.
50
+ lines.push("", "### Dropped Fields (in schema, rare in notes)");
48
51
  for (const f of result.dropped_fields) {
49
- lines.push(`- **${f.name}** — declared in ${f.declared_in}`);
52
+ lines.push(`- **${f.name}** (${f.source}) — ${(f.percentage * 100).toFixed(0)}% (${f.count}/${f.total})`);
50
53
  }
51
54
  }
52
55
  if (result.cardinality_changes.length > 0) {
@@ -67,7 +70,7 @@ export function registerSchemaDiffTool(api, client) {
67
70
  content: [
68
71
  {
69
72
  type: "text",
70
- text: "Schema diff failed. Check logs for details.",
73
+ text: `Schema diff failed: ${describeToolError(err)}`,
71
74
  },
72
75
  ],
73
76
  details: {
@@ -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 registerSchemaInferTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerSchemaInferTool(api, client) {
4
5
  api.registerTool({
@@ -22,7 +23,7 @@ export function registerSchemaInferTool(api, client) {
22
23
  try {
23
24
  const result = await client.schemaInfer(params.noteType, params.threshold, params.project);
24
25
  const lines = [
25
- `**Type:** ${result.entity_type}`,
26
+ `**Type:** ${result.note_type}`,
26
27
  `**Notes analyzed:** ${result.notes_analyzed}`,
27
28
  ];
28
29
  if (result.suggested_required.length > 0) {
@@ -51,7 +52,7 @@ export function registerSchemaInferTool(api, client) {
51
52
  content: [
52
53
  {
53
54
  type: "text",
54
- text: "Schema inference failed. Check logs for details.",
55
+ text: `Schema inference failed: ${describeToolError(err)}`,
55
56
  },
56
57
  ],
57
58
  details: {
@@ -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 registerSchemaValidateTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,4 +1,5 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
3
4
  export function registerSchemaValidateTool(api, client) {
4
5
  api.registerTool({
@@ -30,15 +31,16 @@ export function registerSchemaValidateTool(api, client) {
30
31
  };
31
32
  }
32
33
  const lines = [];
33
- if (result.entity_type) {
34
- lines.push(`**Type:** ${result.entity_type}`);
34
+ if (result.note_type) {
35
+ lines.push(`**Type:** ${result.note_type}`);
35
36
  }
36
37
  lines.push(`**Notes:** ${result.total_notes ?? 0} | **Valid:** ${result.valid_count ?? 0} | **Warnings:** ${result.warning_count ?? 0} | **Errors:** ${result.error_count ?? 0}`);
37
38
  if (result.results && result.results.length > 0) {
38
39
  lines.push("");
39
40
  for (const r of result.results) {
40
- const status = r.valid ? "valid" : "invalid";
41
- lines.push(`- **${r.identifier}** — ${status}`);
41
+ // passed is true when there are no errors; warnings still pass.
42
+ const status = r.passed ? "valid" : "invalid";
43
+ lines.push(`- **${r.note_identifier}** — ${status}`);
42
44
  for (const w of r.warnings) {
43
45
  lines.push(` - warning: ${w}`);
44
46
  }
@@ -58,7 +60,7 @@ export function registerSchemaValidateTool(api, client) {
58
60
  content: [
59
61
  {
60
62
  type: "text",
61
- text: "Schema validation failed. Check logs for details.",
63
+ text: `Schema validation failed: ${describeToolError(err)}`,
62
64
  },
63
65
  ],
64
66
  details: {
@@ -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 registerSearchTool(api: OpenClawPluginApi, client: BmClient): void;
@@ -1,5 +1,9 @@
1
1
  import { Type } from "@sinclair/typebox";
2
+ import { describeToolError, searchResultText, } from "../bm-client.js";
2
3
  import { log } from "../logger.js";
4
+ // Long enough to show a whole captured conversation turn from the matched
5
+ // chunk, short enough that ten results stay readable.
6
+ const MAX_PREVIEW_CHARS = 500;
3
7
  export function registerSearchTool(api, client) {
4
8
  api.registerTool({
5
9
  name: "search_notes",
@@ -7,8 +11,9 @@ export function registerSearchTool(api, client) {
7
11
  description: "Search the Basic Memory knowledge graph for relevant notes, concepts, and connections. " +
8
12
  "Returns matching notes with titles, content previews, and relevance scores. " +
9
13
  "Optionally filter by frontmatter metadata fields, tags, or status, or target " +
10
- "another project. For a quick cross-source recall that also covers MEMORY.md " +
11
- "and active tasks, use memory_search.",
14
+ "another project. This is the search for long-term memory and earlier " +
15
+ "conversations; memory_search covers only the workspace MEMORY.md and memory/ " +
16
+ "files. Read a result in full with read_note, or follow its links with build_context.",
12
17
  parameters: Type.Object({
13
18
  query: Type.String({ description: "Search query" }),
14
19
  limit: Type.Optional(Type.Number({ description: "Max results (default: 10)" })),
@@ -54,9 +59,11 @@ export function registerSearchTool(api, client) {
54
59
  }
55
60
  const text = results
56
61
  .map((r, i) => {
57
- const score = r.score ? ` (${(r.score * 100).toFixed(0)}%)` : "";
58
- const content = r.content ?? "";
59
- const preview = content.length > 200 ? `${content.slice(0, 200)}...` : content;
62
+ const score = r.score ? ` (score ${r.score.toFixed(2)})` : "";
63
+ const text = searchResultText(r);
64
+ const preview = text.length > MAX_PREVIEW_CHARS
65
+ ? `${text.slice(0, MAX_PREVIEW_CHARS)}...`
66
+ : text;
60
67
  return `${i + 1}. **${r.title}**${score}\n ${preview}`;
61
68
  })
62
69
  .join("\n\n");
@@ -83,7 +90,7 @@ export function registerSearchTool(api, client) {
83
90
  content: [
84
91
  {
85
92
  type: "text",
86
- text: "Search failed. Is Basic Memory running? Check logs for details.",
93
+ text: `Search failed: ${describeToolError(err)}`,
87
94
  },
88
95
  ],
89
96
  details: {
@@ -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 registerWriteTool(api: OpenClawPluginApi, client: BmClient): void;