@basicmemory/openclaw-basic-memory 0.24.0 → 1.0.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 +24 -12
- package/bm-client.ts +302 -112
- package/commands/cli.ts +5 -6
- package/commands/slash.ts +4 -4
- package/context-engine/basic-memory-context-engine.ts +74 -9
- package/context-engine/types.ts +21 -0
- package/dist/bm-client.d.ts +61 -12
- package/dist/bm-client.js +250 -101
- 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/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 +79 -69
- package/dist/memory/basic-memory-capability.d.ts +19 -0
- package/dist/memory/basic-memory-capability.js +190 -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 +2 -1
- package/dist/tools/schema-infer.d.ts +1 -1
- package/dist/tools/schema-infer.js +2 -1
- package/dist/tools/schema-validate.d.ts +1 -1
- package/dist/tools/schema-validate.js +2 -1
- 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 +93 -84
- package/memory/basic-memory-capability.ts +253 -0
- package/openclaw.plugin.json +0 -2
- package/package.json +6 -5
- package/skills/manifest.json +5 -0
- 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 +33 -17
- 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-onboarding/SKILL.md +20 -9
- package/skills/memory-onboarding/references/assistant-setup.md +1 -1
- package/skills/memory-onboarding/references/conventions.md +4 -4
- package/skills/memory-onboarding/references/domain-playbooks.md +1 -1
- package/skills/memory-onboarding/references/schema-guide.md +9 -8
- package/skills/memory-quest/SKILL.md +18 -7
- 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-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 +2 -2
- package/tools/schema-infer.ts +2 -2
- package/tools/schema-validate.ts +2 -2
- 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/tools/memory-provider.ts +0 -336
package/tools/memory-provider.ts
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { readdir, readFile } from "node:fs/promises"
|
|
2
|
-
import { join, resolve } from "node:path"
|
|
3
|
-
import { Type } from "@sinclair/typebox"
|
|
4
|
-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry"
|
|
5
|
-
import type { BmClient } from "../bm-client.ts"
|
|
6
|
-
import type { BasicMemoryConfig } from "../config.ts"
|
|
7
|
-
import { log } from "../logger.ts"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Search MEMORY.md for lines matching the query.
|
|
11
|
-
* Returns matching lines with 1 line of surrounding context.
|
|
12
|
-
*/
|
|
13
|
-
async function searchMemoryFile(
|
|
14
|
-
query: string,
|
|
15
|
-
workspaceDir: string,
|
|
16
|
-
memoryFile: string,
|
|
17
|
-
): Promise<string> {
|
|
18
|
-
try {
|
|
19
|
-
const filePath = resolve(workspaceDir, memoryFile)
|
|
20
|
-
const content = await readFile(filePath, "utf-8")
|
|
21
|
-
const lines = content.split("\n")
|
|
22
|
-
const queryLower = query.toLowerCase()
|
|
23
|
-
const terms = queryLower.split(/\s+/).filter((t) => t.length > 0)
|
|
24
|
-
|
|
25
|
-
// Find lines that match any search term
|
|
26
|
-
const matchingIndices = new Set<number>()
|
|
27
|
-
for (let i = 0; i < lines.length; i++) {
|
|
28
|
-
const lineLower = lines[i].toLowerCase()
|
|
29
|
-
if (terms.some((term) => lineLower.includes(term))) {
|
|
30
|
-
// Add the matching line + 1 line before/after for context
|
|
31
|
-
if (i > 0) matchingIndices.add(i - 1)
|
|
32
|
-
matchingIndices.add(i)
|
|
33
|
-
if (i < lines.length - 1) matchingIndices.add(i + 1)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (matchingIndices.size === 0) return ""
|
|
38
|
-
|
|
39
|
-
// Group consecutive lines into snippets
|
|
40
|
-
const sorted = [...matchingIndices].sort((a, b) => a - b)
|
|
41
|
-
const snippets: string[] = []
|
|
42
|
-
let current: string[] = []
|
|
43
|
-
let lastIdx = -2
|
|
44
|
-
|
|
45
|
-
for (const idx of sorted) {
|
|
46
|
-
if (idx !== lastIdx + 1 && current.length > 0) {
|
|
47
|
-
snippets.push(current.join("\n"))
|
|
48
|
-
current = []
|
|
49
|
-
}
|
|
50
|
-
current.push(`- ${lines[idx]}`)
|
|
51
|
-
lastIdx = idx
|
|
52
|
-
}
|
|
53
|
-
if (current.length > 0) snippets.push(current.join("\n"))
|
|
54
|
-
|
|
55
|
-
return snippets.join("\n…\n")
|
|
56
|
-
} catch {
|
|
57
|
-
return ""
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Search for active tasks via BM knowledge graph.
|
|
63
|
-
* Uses search_notes with note_types and status filters for precise querying.
|
|
64
|
-
* Falls back to filesystem scan if search fails.
|
|
65
|
-
*/
|
|
66
|
-
async function searchActiveTasks(
|
|
67
|
-
query: string,
|
|
68
|
-
client: BmClient,
|
|
69
|
-
workspaceDir: string,
|
|
70
|
-
memoryDir: string,
|
|
71
|
-
): Promise<string> {
|
|
72
|
-
// Try structured search first
|
|
73
|
-
try {
|
|
74
|
-
const results = await client.search(query || undefined, 10, undefined, {
|
|
75
|
-
note_types: ["task"],
|
|
76
|
-
status: "active",
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
if (results.length > 0) {
|
|
80
|
-
const matches: string[] = []
|
|
81
|
-
for (const r of results) {
|
|
82
|
-
const score = r.score ? ` (${r.score.toFixed(2)})` : ""
|
|
83
|
-
const preview =
|
|
84
|
-
(r.content ?? "").length > 200
|
|
85
|
-
? `${(r.content ?? "").slice(0, 200)}…`
|
|
86
|
-
: (r.content ?? "")
|
|
87
|
-
matches.push(
|
|
88
|
-
`- **${r.title}**${score} — ${r.file_path}\n > ${preview.replace(/\n/g, "\n > ")}`,
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
return matches.join("\n\n")
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
log.debug("BM task search failed, falling back to filesystem scan", err)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Fallback: filesystem scan for tasks not yet indexed
|
|
98
|
-
try {
|
|
99
|
-
const tasksDir = resolve(workspaceDir, memoryDir, "tasks")
|
|
100
|
-
let entries: import("node:fs").Dirent[]
|
|
101
|
-
try {
|
|
102
|
-
entries = (await readdir(tasksDir, {
|
|
103
|
-
withFileTypes: true,
|
|
104
|
-
})) as unknown as import("node:fs").Dirent[]
|
|
105
|
-
} catch {
|
|
106
|
-
return ""
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const queryLower = query.toLowerCase()
|
|
110
|
-
const terms = queryLower.split(/\s+/).filter((t) => t.length > 0)
|
|
111
|
-
const matches: string[] = []
|
|
112
|
-
|
|
113
|
-
for (const entry of entries) {
|
|
114
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue
|
|
115
|
-
|
|
116
|
-
const filePath = join(entry.parentPath ?? tasksDir, entry.name)
|
|
117
|
-
const content = await readFile(filePath, "utf-8")
|
|
118
|
-
|
|
119
|
-
const statusMatch = content.match(/status:\s*(\S+)/)
|
|
120
|
-
const status = statusMatch?.[1] ?? "unknown"
|
|
121
|
-
if (status === "done") continue
|
|
122
|
-
|
|
123
|
-
const contentLower = content.toLowerCase()
|
|
124
|
-
const matchesQuery =
|
|
125
|
-
terms.length === 0 || terms.some((term) => contentLower.includes(term))
|
|
126
|
-
if (!matchesQuery) continue
|
|
127
|
-
|
|
128
|
-
const titleMatch = content.match(/title:\s*(.+)/)
|
|
129
|
-
const title = titleMatch?.[1] ?? entry.name.replace(/\.md$/, "")
|
|
130
|
-
const stepMatch = content.match(/current_step:\s*(\S+)/)
|
|
131
|
-
const currentStep = stepMatch?.[1] ?? "?"
|
|
132
|
-
|
|
133
|
-
const contextMatch = content.match(
|
|
134
|
-
/## Context\s*\n([\s\S]*?)(?=\n##|\n---|$)/,
|
|
135
|
-
)
|
|
136
|
-
const context = contextMatch?.[1]?.trim().slice(0, 150) ?? ""
|
|
137
|
-
|
|
138
|
-
matches.push(
|
|
139
|
-
`- **${title}** (status: ${status}, step: ${currentStep})\n ${context}`,
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return matches.join("\n")
|
|
144
|
-
} catch {
|
|
145
|
-
return ""
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Store workspace dir for use in memory_search (set during service start)
|
|
150
|
-
let _workspaceDir = ""
|
|
151
|
-
export function setWorkspaceDir(dir: string) {
|
|
152
|
-
_workspaceDir = dir
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Register composited memory_search and memory_get tools.
|
|
157
|
-
*
|
|
158
|
-
* memory_search queries 3 sources in parallel:
|
|
159
|
-
* 1. MEMORY.md — grep/text search
|
|
160
|
-
* 2. BM knowledge graph — semantic + FTS search
|
|
161
|
-
* 3. Active tasks — memory/tasks/ files with status != done
|
|
162
|
-
*
|
|
163
|
-
* memory_get reads a specific note by identifier.
|
|
164
|
-
*/
|
|
165
|
-
export function registerMemoryProvider(
|
|
166
|
-
api: OpenClawPluginApi,
|
|
167
|
-
client: BmClient,
|
|
168
|
-
cfg: BasicMemoryConfig,
|
|
169
|
-
): void {
|
|
170
|
-
// --- composited memory_search ---
|
|
171
|
-
api.registerTool(
|
|
172
|
-
{
|
|
173
|
-
name: "memory_search",
|
|
174
|
-
label: "Memory Search",
|
|
175
|
-
description:
|
|
176
|
-
"Search across all memory sources: MEMORY.md (working memory), " +
|
|
177
|
-
"Basic Memory knowledge graph (long-term archive), and active tasks. " +
|
|
178
|
-
"Returns composited results from all sources. Use it for broad recall; use " +
|
|
179
|
-
"search_notes when you need metadata, tag, or status filters or a specific project.",
|
|
180
|
-
parameters: Type.Object({
|
|
181
|
-
query: Type.String({
|
|
182
|
-
description: "Search query — natural language or keywords",
|
|
183
|
-
}),
|
|
184
|
-
}),
|
|
185
|
-
async execute(_toolCallId: string, params: { query: string }) {
|
|
186
|
-
log.debug(`memory_search: query="${params.query}"`)
|
|
187
|
-
|
|
188
|
-
const workspaceDir = _workspaceDir || process.cwd()
|
|
189
|
-
|
|
190
|
-
// Query all 3 sources in parallel
|
|
191
|
-
const [memoryMd, bmResults, taskResults] = await Promise.all([
|
|
192
|
-
searchMemoryFile(params.query, workspaceDir, cfg.memoryFile),
|
|
193
|
-
client
|
|
194
|
-
.search(params.query, 5)
|
|
195
|
-
.then((results) => {
|
|
196
|
-
if (results.length === 0) return ""
|
|
197
|
-
return results
|
|
198
|
-
.map((r) => {
|
|
199
|
-
const score = r.score ? ` (${r.score.toFixed(2)})` : ""
|
|
200
|
-
const preview =
|
|
201
|
-
(r.content ?? "").length > 200
|
|
202
|
-
? `${(r.content ?? "").slice(0, 200)}…`
|
|
203
|
-
: (r.content ?? "")
|
|
204
|
-
const source = r.file_path || r.permalink
|
|
205
|
-
return `- ${source}${score}\n > ${preview.replace(/\n/g, "\n > ")}`
|
|
206
|
-
})
|
|
207
|
-
.join("\n\n")
|
|
208
|
-
})
|
|
209
|
-
.catch((err) => {
|
|
210
|
-
log.error("BM search failed in composited search", err)
|
|
211
|
-
return "(search unavailable)"
|
|
212
|
-
}),
|
|
213
|
-
searchActiveTasks(params.query, client, workspaceDir, cfg.memoryDir),
|
|
214
|
-
])
|
|
215
|
-
|
|
216
|
-
// Build composited result
|
|
217
|
-
const sections: string[] = []
|
|
218
|
-
|
|
219
|
-
if (memoryMd) {
|
|
220
|
-
sections.push(`## ${cfg.memoryFile}\n${memoryMd}`)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (bmResults) {
|
|
224
|
-
sections.push(`## Knowledge Graph (${cfg.memoryDir})\n${bmResults}`)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (taskResults) {
|
|
228
|
-
sections.push(`## Active Tasks\n${taskResults}`)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (sections.length === 0) {
|
|
232
|
-
return {
|
|
233
|
-
content: [
|
|
234
|
-
{
|
|
235
|
-
type: "text" as const,
|
|
236
|
-
text: "No matches found across memory sources.",
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
details: {
|
|
240
|
-
query: params.query,
|
|
241
|
-
sectionCount: 0,
|
|
242
|
-
hasMemoryFileMatches: false,
|
|
243
|
-
hasKnowledgeGraphMatches: false,
|
|
244
|
-
hasTaskMatches: false,
|
|
245
|
-
},
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
content: [
|
|
251
|
-
{
|
|
252
|
-
type: "text" as const,
|
|
253
|
-
text: sections.join("\n\n"),
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
details: {
|
|
257
|
-
query: params.query,
|
|
258
|
-
sectionCount: sections.length,
|
|
259
|
-
hasMemoryFileMatches: memoryMd.length > 0,
|
|
260
|
-
hasKnowledgeGraphMatches: bmResults.length > 0,
|
|
261
|
-
hasTaskMatches: taskResults.length > 0,
|
|
262
|
-
},
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
{ names: ["memory_search"] },
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
// --- memory_get (unchanged) ---
|
|
270
|
-
api.registerTool(
|
|
271
|
-
{
|
|
272
|
-
name: "memory_get",
|
|
273
|
-
label: "Memory Get",
|
|
274
|
-
description:
|
|
275
|
-
"Read a specific note from the knowledge graph by title, permalink, or path. " +
|
|
276
|
-
"Returns the full note content. Use after memory_search to read a specific result in full.",
|
|
277
|
-
parameters: Type.Object({
|
|
278
|
-
path: Type.String({
|
|
279
|
-
description:
|
|
280
|
-
"Note identifier — title, permalink, memory:// URL, or file path",
|
|
281
|
-
}),
|
|
282
|
-
from: Type.Optional(
|
|
283
|
-
Type.Number({
|
|
284
|
-
description:
|
|
285
|
-
"Starting line number (ignored — included for compatibility)",
|
|
286
|
-
}),
|
|
287
|
-
),
|
|
288
|
-
lines: Type.Optional(
|
|
289
|
-
Type.Number({
|
|
290
|
-
description:
|
|
291
|
-
"Number of lines to read (ignored — included for compatibility)",
|
|
292
|
-
}),
|
|
293
|
-
),
|
|
294
|
-
}),
|
|
295
|
-
async execute(
|
|
296
|
-
_toolCallId: string,
|
|
297
|
-
params: { path: string; from?: number; lines?: number },
|
|
298
|
-
) {
|
|
299
|
-
log.debug(`memory_get: path="${params.path}"`)
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
const note = await client.readNote(params.path)
|
|
303
|
-
|
|
304
|
-
return {
|
|
305
|
-
content: [
|
|
306
|
-
{
|
|
307
|
-
type: "text" as const,
|
|
308
|
-
text: `# ${note.title}\n\n${note.content}`,
|
|
309
|
-
},
|
|
310
|
-
],
|
|
311
|
-
details: {
|
|
312
|
-
title: note.title,
|
|
313
|
-
permalink: note.permalink,
|
|
314
|
-
file_path: note.file_path,
|
|
315
|
-
},
|
|
316
|
-
}
|
|
317
|
-
} catch (err) {
|
|
318
|
-
log.error("memory_get failed", err)
|
|
319
|
-
return {
|
|
320
|
-
content: [
|
|
321
|
-
{
|
|
322
|
-
type: "text" as const,
|
|
323
|
-
text: `Could not read "${params.path}". It may not exist in the knowledge graph.`,
|
|
324
|
-
},
|
|
325
|
-
],
|
|
326
|
-
details: {
|
|
327
|
-
path: params.path,
|
|
328
|
-
error: "memory_get_failed",
|
|
329
|
-
},
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
{ names: ["memory_get"] },
|
|
335
|
-
)
|
|
336
|
-
}
|