@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
|
@@ -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,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
|
-
|
|
46
|
-
|
|
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
|
|
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}"
|
|
96
|
+
text: `Failed to build context for "${params.url}": ${describeToolError(err)}`,
|
|
89
97
|
},
|
|
90
98
|
],
|
|
91
99
|
details: {
|
|
@@ -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}"
|
|
42
|
+
text: `Failed to delete "${params.identifier}": ${describeNoteError(err)}`,
|
|
42
43
|
},
|
|
43
44
|
],
|
|
44
45
|
details: {
|
package/dist/tools/edit-note.js
CHANGED
|
@@ -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,
|
|
9
|
-
"without rewriting the entire note.
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
54
|
+
text: `Failed to list workspaces: ${describeToolError(err)}`,
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
57
|
details: {
|
package/dist/tools/move-note.js
CHANGED
|
@@ -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}"
|
|
45
|
+
text: `Failed to move "${params.identifier}": ${describeNoteError(err)}`,
|
|
45
46
|
},
|
|
46
47
|
],
|
|
47
48
|
details: {
|
package/dist/tools/read-note.js
CHANGED
|
@@ -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}"
|
|
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
|
|
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.
|
|
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
|
-
|
|
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}** —
|
|
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:
|
|
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
|
|
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.
|
|
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:
|
|
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
|
|
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.
|
|
34
|
-
lines.push(`**Type:** ${result.
|
|
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
|
-
|
|
41
|
-
|
|
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:
|
|
63
|
+
text: `Schema validation failed: ${describeToolError(err)}`,
|
|
62
64
|
},
|
|
63
65
|
],
|
|
64
66
|
details: {
|
|
@@ -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.
|
|
11
|
-
"
|
|
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 ? ` (${
|
|
58
|
-
const
|
|
59
|
-
const preview =
|
|
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:
|
|
93
|
+
text: `Search failed: ${describeToolError(err)}`,
|
|
87
94
|
},
|
|
88
95
|
],
|
|
89
96
|
details: {
|