@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
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
# Schemas, Observations & Relations
|
|
2
|
-
|
|
3
|
-
How to make notes structured enough to query and consistent enough to trust. This is the mechanical core of the system the onboarding builds.
|
|
4
|
-
|
|
5
|
-
## Contents
|
|
6
|
-
|
|
7
|
-
1. [Note anatomy](#note-anatomy)
|
|
8
|
-
2. [Observations](#observations)
|
|
9
|
-
3. [Relations](#relations)
|
|
10
|
-
4. [Picoschema syntax](#picoschema-syntax)
|
|
11
|
-
5. [Creating a schema](#creating-a-schema)
|
|
12
|
-
6. [Validation & drift](#validation--drift)
|
|
13
|
-
7. [Design guidelines](#design-guidelines)
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Note anatomy
|
|
18
|
-
|
|
19
|
-
Every well-formed note has: frontmatter (title, type, tags — generated by `write_note` from its parameters), a **body** of substantive prose, an **Observations** section, and a **Relations** section.
|
|
20
|
-
|
|
21
|
-
```markdown
|
|
22
|
-
# Fix Gutter Downspout
|
|
23
|
-
|
|
24
|
-
| Notes | Modification Date | Approved By |
|
|
25
|
-
|:--|:--|:--|
|
|
26
|
-
| Initial Document | July 12, 2026 | Dana Reyes |
|
|
27
|
-
|
|
28
|
-
Back downspout detached during the June storm; water is pooling against the
|
|
29
|
-
foundation on the north side. Needs a bracket and probably a new elbow section.
|
|
30
|
-
Hardware store trip required — measure the downspout diameter first (looks like 3x4).
|
|
31
|
-
|
|
32
|
-
## Observations
|
|
33
|
-
- [status] open
|
|
34
|
-
- [priority] high
|
|
35
|
-
- [due] @due:2026-07-20 Downspout fixed
|
|
36
|
-
- [context] home-maintenance
|
|
37
|
-
|
|
38
|
-
## Relations
|
|
39
|
-
- part_of [[House Projects]]
|
|
40
|
-
- relates_to [[June Storm Damage]]
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Write the body generously.** Search retrieves chunks from note bodies, so richer prose makes notes *more* discoverable, not less. Prose carries meaning; observations carry precision. A note that is only bullet-point observations reads like a database row and loses the context that makes it useful a year later.
|
|
44
|
-
|
|
45
|
-
## Observations
|
|
46
|
-
|
|
47
|
-
Categorized, atomic facts: `- [category] content #optional-tag`
|
|
48
|
-
|
|
49
|
-
- Categories are **free-form** — `[decision]`, `[status]`, `[symptom]`, `[cost]`, `[lesson]` — whatever fits. Consistency within a note type is what matters (and is what schemas enforce).
|
|
50
|
-
- **One fact per line.** `- [decision] Use JWT with 15-minute expiry` not a paragraph of three decisions.
|
|
51
|
-
- **Categories are queryable** — searching by category finds every note carrying that kind of fact.
|
|
52
|
-
- Tags add cross-cutting findability: `- [risk] no SLA on the API #vendor #reliability`.
|
|
53
|
-
|
|
54
|
-
In this system, observations do double duty: they're facts, and they're the **fields** schemas validate — for scalar, enum, and array fields. A Task schema requiring `status` means every task note carries `- [status] ...` as an observation. (Entity-reference fields validate against relations instead — see below.)
|
|
55
|
-
|
|
56
|
-
## Relations
|
|
57
|
-
|
|
58
|
-
Typed, directional links: `- relation_type [[Target Note Title]]`
|
|
59
|
-
|
|
60
|
-
- relation_type is a descriptive snake_case verb: `part_of`, `depends_on`, `assigned_to`, `replaces`, `paid_by`. Invent freely.
|
|
61
|
-
- Wiki-links in body prose also create edges (untyped `references`). Use the Relations section for the structural links, prose links for narrative mentions.
|
|
62
|
-
- Targets may not exist yet — forward links resolve on creation.
|
|
63
|
-
- `build_context` on a `memory://` URL walks these edges to assemble connected context — this is what makes the graph worth building.
|
|
64
|
-
|
|
65
|
-
## Picoschema syntax
|
|
66
|
-
|
|
67
|
-
Schemas are notes (conventionally in a `Schemas/` folder) whose frontmatter metadata defines fields:
|
|
68
|
-
|
|
69
|
-
```yaml
|
|
70
|
-
schema:
|
|
71
|
-
status(enum): "[open, in-progress, blocked, done], current state"
|
|
72
|
-
due?: string, due date if any (YYYY-MM-DD)
|
|
73
|
-
priority?(enum): "[low, medium, high], urgency"
|
|
74
|
-
project?: Project, parent project note
|
|
75
|
-
steps?(array): string, ordered sub-steps
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
- Types: `string`, `integer`, `number`, `boolean`
|
|
79
|
-
- `?` suffix = optional field
|
|
80
|
-
- `(enum)` = fixed value list — use for anything status-like
|
|
81
|
-
- `(array)` = list field
|
|
82
|
-
- A capitalized type name (`Person`, `Project`) makes it a **relation field**, validated against the note's Relations section (the relation type must equal the field name: `- project [[Target Note]]`) — it creates a graph edge, not an observation
|
|
83
|
-
- Every field gets a comma-then-description: it's documentation the next assistant reads
|
|
84
|
-
|
|
85
|
-
## Creating a schema
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
write_note(
|
|
89
|
-
title="Task",
|
|
90
|
-
directory="Schemas",
|
|
91
|
-
note_type="schema",
|
|
92
|
-
metadata={
|
|
93
|
-
"entity": "Task",
|
|
94
|
-
"version": 1,
|
|
95
|
-
"schema": {
|
|
96
|
-
"status(enum)": "[open, in-progress, blocked, done], current state",
|
|
97
|
-
"due?": "string, due date (YYYY-MM-DD)",
|
|
98
|
-
"priority?(enum)": "[low, medium, high], urgency",
|
|
99
|
-
"project?": "Project, parent project"
|
|
100
|
-
},
|
|
101
|
-
"settings": {"validation": "warn"}
|
|
102
|
-
},
|
|
103
|
-
content="""# Task
|
|
104
|
-
|
|
105
|
-
Schema for task notes. Tasks live in Tasks/, titled with a short imperative
|
|
106
|
-
description. Status moves open → in-progress → done; blocked is a holding state.
|
|
107
|
-
|
|
108
|
-
## Observations
|
|
109
|
-
- [convention] Every task carries status as an observation
|
|
110
|
-
- [convention] Done tasks get a close-date appended before archiving"""
|
|
111
|
-
)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Key points:
|
|
115
|
-
|
|
116
|
-
- **`validation: warn`, not `strict`** — the modes are `warn` and `strict`. Warn logs findings without blocking anything; `strict` escalates the same findings to errors. Start every schema on warn — a new user fighting rejected writes will abandon the system. Move a schema to `strict` only if something automated consumes the notes and malformed ones break it.
|
|
117
|
-
- **Content notes declare their type** via `note_type` matching the schema's entity (e.g. `note_type="task"`).
|
|
118
|
-
- **Scalar, enum, and array fields must appear as observations** in the note body (`- [status] open`) to satisfy validation — frontmatter-only values don't count. Putting them in both places gives you metadata search *and* schema validation. **Entity-reference fields are different**: they're satisfied by a relation, not an observation — a line in `## Relations` whose type matches the field name (`project?: Project` is satisfied by `- project [[Kitchen Renovation]]`).
|
|
119
|
-
- **Version in metadata** — bump on breaking changes (new required field, removed field, type change). Additive optional fields don't need a bump.
|
|
120
|
-
|
|
121
|
-
## Validation & drift
|
|
122
|
-
|
|
123
|
-
- `schema_validate(note_type="task")` — check all notes of a type, or a single note via `identifier=`. It reports **missing required fields** and **invalid enum values** — that's the whole contract. Fields the schema doesn't declare are only counted as informational "unmatched" metadata (schemas are a subset, not a straitjacket), and scalar values are not type-checked, so a clean validate doesn't guarantee more than required-field presence and enum conformance. Use `schema_diff` to surface undeclared fields.
|
|
124
|
-
- `schema_diff(note_type="task")` — finds drift: fields notes use that the schema doesn't define (candidates to add as optional), and schema fields nobody uses (candidates to drop).
|
|
125
|
-
- `schema_infer(note_type="task")` — when notes of a type already exist without a schema, infer one from their actual structure instead of designing from scratch.
|
|
126
|
-
|
|
127
|
-
Evolution loop: `schema_diff` → edit the schema note (append changelog row, bump version if breaking) → `schema_validate` → fix outliers. Suggest the user run this monthly-ish once the system has real volume.
|
|
128
|
-
|
|
129
|
-
## Design guidelines
|
|
130
|
-
|
|
131
|
-
- **Every note type gets a schema; every note gets observations.** These two are not scale-dependent. A domain the user wants "loose" gets a one-field schema and a one-observation minimum, not an exemption — unstructured notes can't be queried, validated, or trusted by a future assistant, and retrofitting structure later is far more expensive than carrying one line now.
|
|
132
|
-
- **2–4 required fields, everything else optional.** Required fields are a tax on every note; each one must earn its place. Status almost always earns it. `notes_from_that_one_meeting` does not.
|
|
133
|
-
- **Enums for anything status-like.** Free-text statuses drift (`done`, `Done`, `finished`, `complete ✓`) and become unqueryable. Define the vocabulary in the schema and list it in the domain instruction note.
|
|
134
|
-
- **Schema per entity type, not per folder.** A `Person` schema serves contacts, family, and coworkers even if they live in different folders.
|
|
135
|
-
- **Don't over-constrain.** A schema describes common structure; it is not a straitjacket. If the user fights a field during the first week, make it optional or delete it.
|
|
136
|
-
- **Schemas are documentation.** Even at `warn` with validation never run, the schema note tells the next assistant exactly what a conforming note looks like. Write field descriptions accordingly.
|
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
|
-
}
|