@lotargo/memory_plugin 1.6.3 → 1.6.4

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.
@@ -7,7 +7,7 @@ description: Comprehensive guide for using the Memory, Hybrid RAG Knowledge Engi
7
7
 
8
8
  You have access to a persistent dual-layer memory engine supercharged with an **Agent-Driven Knowledge Graph** and general MCP integration helpers:
9
9
  1. **Layer 1: Notebook Store (Key-Value Facts)**: Stores high-signal personal preferences, project conventions, and durable rules in clean Markdown.
10
- 2. **Layer 2: RAG Knowledge Base**: Indexes documentation, repositories, and technical guides for hybrid semantic retrieval.
10
+ 2. **Layer 2: Curated RAG Knowledge Base**: Preserves selected external findings, documentation, repositories, and technical guides that are likely to matter again.
11
11
  3. **Layer 3: Agent-Driven Knowledge Graph**: Connects Notebook facts (Layer 1) to specific Knowledge Base documents, sections, and **exact line ranges** (Layer 2).
12
12
  4. **Integration Layer (General MCP Helpers)**: Quickly discovers connected MCP servers and identifies appropriate tools for specific tasks.
13
13
 
@@ -27,12 +27,12 @@ You have access to a persistent dual-layer memory engine supercharged with an **
27
27
  | Filter facts by keyword / tags / date | `recall` | `query`, `tags`, `since`, `until` |
28
28
  | Show storage paths, versions, fact & RAG stats, git identity | `memory_info` | — |
29
29
  | Connect a Notebook fact to a document, section, or line range | `link_knowledge` | `action` ("link", "list_links", "get_doc_links"), `factText`, `docId`, `startLine`, `endLine`, `relationType` |
30
- | Link directory to Git project identity / migrate legacy stores | `link_project_memory` | `directory`, optional `remote` |
30
+ | Register current Git project identity / migrate legacy stores | `memory_info` then `link_project_memory` when `Registry: unlinked` | `directory`, optional `remote` |
31
31
  | Remove path alias or purge project identity | `unlink_project_memory` | `directory`, `purge` (boolean) |
32
32
  | Move or merge project memories to new target identity | `relink_project_memory` | `directory`, `remote` (target remote URL) |
33
- | User asks to index a documentation URL, file, or repository | `ingest_document` | `content` (text/file path/URL), `type` ("text", "file", "url"), `title`, `path` |
34
- | User asks a complex question about indexed docs or code | `query_knowledge_base` | `query`, `limit`, `instruction`, `generateEmbeddings` |
35
- | User needs multiple queries executed in batch (comparisons, multi-topic) | `batch_query_knowledge_base` | `queries` (array), `limit`, `instruction`, `generateEmbeddings` |
33
+ | User asks to index a documentation URL, file, or repository | `ingest_document` | `content` (text/file path/URL), `type` ("text", "file", "url"), `title`, `path`, `scope` (project default) |
34
+ | User asks a complex question about indexed docs or code | `query_knowledge_base` | `query`, `scope` (all default), `limit`, `instruction`, `generateEmbeddings` |
35
+ | User needs multiple queries executed in batch (comparisons, multi-topic) | `batch_query_knowledge_base` | `queries` (array), `scope` (all default), `limit`, `instruction`, `generateEmbeddings` |
36
36
  | Read full raw content of an ambiguous/abstract document | `manage_knowledge_base` | `action: "read_document"`, `docId` |
37
37
  | View DB stats, list indexed docs, read/delete docs, export/import snapshots | `manage_knowledge_base` | `action` ("stats", "list", "read_document", "delete", "export_snapshot", "import_snapshot"), `docId`, `snapshotPath` |
38
38
  | Re-embed all documents after switching embedding model / dimension | `reindex_knowledge_base` | `model`, `dimension` (optional; defaults to active config) |
@@ -46,14 +46,14 @@ You have access to a persistent dual-layer memory engine supercharged with an **
46
46
  ### Agent-Driven Knowledge Graph Architecture
47
47
  Automatic regex/heuristic algorithms alone CANNOT infer high-level semantic intent or cross-document relationships. **You (the AI Agent) are the primary architect of the Knowledge Graph.**
48
48
 
49
- Whenever you ingest project documentation, web pages, or local files, you should link durable facts in the Notebook store directly to the corresponding RAG documents and exact line ranges.
49
+ When an ingested source supports a durable project decision or rule, link the corresponding Notebook fact directly to the RAG document and, when useful, its exact line range. The Notebook fact is the concise orientation point; the linked RAG source is its detailed evidence and technical context.
50
50
 
51
51
  ### What to Save and Link (`remember` & `link_knowledge`)
52
52
  - **High-Signal Facts**: User name, role, language preferences, architectural constraints, framework choices, coding standards, test rules.
53
53
  - **Formatting & Fact Titles**:
54
54
  - Always translate the fact into clear, concise English before calling `remember`.
55
55
  - **Always specify a descriptive `title` parameter** (a 2-5 word headline, e.g., `title: "Backend Framework Preference"`).
56
- - Facts are stored in `**Title** — body` format. In `mode: "full"` (default in `recall`), both title and body are displayed. In `mode: "headers"` and in auto-injected `<MEMORY>` system prompt blocks, only `**Title**` is displayed to keep the system prompt lean.
56
+ - Facts are stored in `**Title** — body` format. Initial session recall and auto-injected `<MEMORY>` blocks MUST include full fact bodies. Header-only recall was tested and rejected because it loses essential context. Use `mode: "headers"` only when the user explicitly asks for a compact inventory, never for session initialization.
57
57
  - **Linking to Knowledge Base Documents**:
58
58
  - Pass `docId` (or document title/path) and optional `startLine` / `endLine` when calling `remember` or `link_knowledge`.
59
59
  - Example: `remember(title: "Backend Framework Preference", fact: "Use Fastify instead of Express for backend services", scope: "project", docId: "arch_specs.md", startLine: 5, endLine: 7)`
@@ -91,10 +91,17 @@ Supported metadata keys (set via `remember`, rendered as badges by `recall`):
91
91
  - `tags`: comma-separated; returns facts with ANY matching tag.
92
92
  - `since` / `until`: "YYYY-MM-DD" (inclusive) to filter by fact date.
93
93
  - `project`: read a specific project's store from any working directory.
94
- - `mode`: `"full"` (default) or `"headers"` (returns title and badges only, omitting full text body).
95
- - `offset` / `limit`: optional numeric pagination parameters.
96
- - `get_fact`: fetch exact text and full metadata of a single fact by its metadata id (e.g. `get_fact(id: "8f3a2c")`).
97
- - Output shows `[EXPIRED]`, `[KEEP]`, `[SUPERSEDED]`, `[INJECT]` badges and the `Store file:` path.
94
+ - `mode`: `"full"` (default) or `"headers"` (returns title and badges only, omitting full text body).
95
+ - `includeSuperseded`: `false` by default so obsolete history does not enter active context; set `true` only to inspect version history.
96
+ - `offset` / `limit`: optional numeric pagination parameters.
97
+ - `get_fact`: fetch exact text and full metadata of a single fact by its metadata id (e.g. `get_fact(id: "8f3a2c")`).
98
+ - Output shows `[EXPIRED]`, `[KEEP]`, `[SUPERSEDED]`, `[INJECT]` badges and the `Store file:` path.
99
+
100
+ ### Scope Isolation and Conflicts
101
+ - `scope: "all"` returns the complete global store plus only the current Git project's store.
102
+ - Outside a Git repository, `scope: "all"` returns global memory only. It must not create a `null` project store.
103
+ - Memories from unrelated projects are never included in normal session initialization. Use the explicit `project` parameter only when the user asks to inspect another project.
104
+ - Global and project facts are both context sources. Neither store automatically overrides the other; if facts conflict, the agent evaluates the available context and decides how to proceed.
98
105
 
99
106
  ### Updating Facts (`update_fact`)
100
107
  When the user corrects an old fact, prefer `update_fact` over `forget`+`remember` — it rewrites the text while preserving the original date and all metadata (`ttl`, `keep`, `tags`, `supersedes`), and re-points any linked Knowledge Base documents.
@@ -105,31 +112,52 @@ When the user corrects an old fact, prefer `update_fact` over `forget`+`remember
105
112
  ### Protecting Facts (`forget` with `keep`)
106
113
  `forget` refuses to delete facts saved with `keep: true`; pass `force: true` to override. It still supports deleting by index number, range ("3-30"), or text.
107
114
 
108
- ### Project Memory Identity Management (`link_project_memory`, `unlink_project_memory`, `relink_project_memory`)
109
- Project stores are bound to Git-based project identities (`git:remote` or `git:local:<repo basename>`). Use these tools to manage bindings:
115
+ ### Project Memory Identity Management (`link_project_memory`, `unlink_project_memory`, `relink_project_memory`)
116
+ Project stores are bound to Git-based project identities (`git:<normalized remote>` or `git:local:<repo basename>`). Normal recall resolves the current identity automatically from Git and never scans unrelated project stores.
117
+
118
+ Session initialization sequence:
119
+ 1. Call `recall(scope: "all")` first, with full bodies and no filters.
120
+ 2. Call `memory_info` for the current workspace.
121
+ 3. If it reports `Identity: git` and `Registry: unlinked`, immediately call `link_project_memory` for the current directory. This registers the identity and aliases and migrates any matching legacy path store.
122
+ 4. If the link result reports `migrated: true`, call `recall(scope: "all")` again so the migrated facts enter the active context.
123
+ 5. If it reports `Identity: no-git`, do not create project memory and do not invent a remote; continue with global memory only.
124
+
125
+ Use the identity tools as follows:
110
126
  - `link_project_memory(directory, remote)`: Links a working directory to a Git identity, registers path/remote aliases, and automatically merges any legacy path-based stores.
111
127
  - `unlink_project_memory(directory, purge)`: Removes the path alias link for a directory; set `purge: true` to purge the identity from SQLite.
112
128
  - `relink_project_memory(directory, remote)`: Moves and merges memories from the current project identity to a new target remote URL identity.
113
129
 
114
130
  ### Storage Diagnostics (`memory_info`)
115
- `memory_info` returns the package version, `MEMORY_DIR`, SQLite DB path, store-file locations, fact counts per store, Git identity info, and RAG stats (documents, sections, chunks, graph edges, links).
131
+ `memory_info` returns the package version, `MEMORY_DIR`, SQLite DB path, store-file locations, fact counts per store, current Git identity, its registry status (`linked`, `unlinked`, or `not-applicable`), and RAG stats (documents, sections, chunks, graph edges, links).
116
132
 
117
133
  ---
118
134
 
119
135
  ## 3. Layer 2: RAG Knowledge Base (`ingest_document`, `query_knowledge_base`, `manage_knowledge_base`, `reindex_knowledge_base`)
120
136
 
121
- ### Document Ingestion (`ingest_document`)
122
- Use this tool when adding technical documentation, API specs, architectural documents, or code repos into the searchable knowledge base.
137
+ ### Document Ingestion (`ingest_document`)
138
+ RAG is a curated project reference library, not an automatic archive of everything the agent reads. Ingest content only when the agent judges that it is reliable, relevant to the current project, and likely to be needed in future work.
139
+
140
+ Good ingestion candidates:
141
+ - Important information found through web research that should remain available after the current session.
142
+ - Official or otherwise authoritative documentation for a library, framework, API, or tool used by the project.
143
+ - New-version features, changed behavior, migration guidance, or APIs that may be newer than the model's training knowledge.
144
+ - A complete document when most of it is relevant, or only the useful excerpt when the rest would add retrieval noise.
145
+
146
+ Do not ingest search-result dumps, incidental pages, duplicate explanations, transient troubleshooting output, or documentation with no expected future project value. After ingestion, create or update a concise project-scoped Notebook fact when the source supports a durable choice, constraint, or discovery, and link that fact to the document with `remember(docId, ...)` or `link_knowledge`.
147
+ - **RAG Scope Isolation**: `scope: "project"` is the ingestion default and associates the source with the current Git identity. Query scope `"all"` searches global RAG plus only the current project; outside Git it searches global only. Use global ingestion only for sources intentionally reusable across projects.
148
+ - **Shared Sources**: Re-ingesting the same path or URL from another project adds that project association without duplicating the document. Removing it from one scope leaves it available to other linked scopes; the underlying document is deleted only after its last scope is removed.
149
+ - **Stable Updates**: Re-ingesting an updated source preserves its `docId` and Notebook links while replacing chunks, vectors, policies, and structural graph edges.
123
150
  - **Hierarchy Chunking**: The engine automatically creates 3-tier chunks (Big Document -> Medium Section -> Small Micro-Chunk) and extracts GraphRAG code symbols.
124
151
  - **Auto Vector Embeddings**: Dense ONNX vectors (`multilingual-e5-small`) are automatically computed and indexed in SQLite.
125
152
  - **CRITICAL Schema Usage & Parameters**:
126
- - `content` (required, string): For `type: "text"`/`"file"` it must be the **actual raw text or markdown content** of the document, NOT just a file path! For `type: "url"` it must be the **page URL** the page is fetched automatically and its content is indexed (not just the URL).
127
- - `type` (optional, enum: `"text"`, `"file"`, `"url"`): `"text"` (default), `"file"`, or `"url"` (fetches the web page and indexes its content).
128
- - `path` (optional, string): Provide the absolute file path (e.g. `f:\projects\plugins\memory\README.md`). For URLs the final URL is used for deduplication.
153
+ - `content` (required, string): For `type: "text"`, pass actual raw text or Markdown. For `type: "file"`, pass either an allowed local file path or already-read file content. For `type: "url"`, pass the page URL; the page is fetched and its content is indexed.
154
+ - `type` (optional, enum: `"text"`, `"file"`, `"url"`): `"text"` (default), `"file"` (safe local-path read or supplied content), or `"url"` (fetches page content).
155
+ - `path` (optional, string): Original/deduplication path. With `type: "file"`, the server reads `path` when supplied; otherwise it treats `content` as the path when applicable. File reads are restricted by the built-in cwd/MEMORY_DIR allowlist and `ingestAllowedPaths`.
129
156
  - `title` (optional, string): Provide document title (e.g. `README.md`). If omitted for a URL, the page `<title>` is used.
130
157
  - **Correct Example (URL)**: `ingest_document(content: "https://docs.example.com/guide", type: "url", title: "Example Guide")`
131
- - **Correct Example (text)**: `ingest_document(content: "<full text content>", path: "f:/path/to/file.md", title: "file.md", type: "file")`
132
- - **Common Error**: `ingest_document(content: "f:/path/to/file.md")` this causes validation failures because `content` is missing the text content.
158
+ - **Correct Example (local file path)**: `ingest_document(content: "f:/project/docs/guide.md", type: "file", title: "guide.md")`
159
+ - **Correct Example (already-read content)**: `ingest_document(content: "<full text content>", path: "f:/project/docs/guide.md", title: "guide.md", type: "file")`
160
+ - ❌ **Common Error**: passing a file path with the default `type: "text"`; that indexes the path string instead of reading the file.
133
161
 
134
162
  - **CLI/Script Execution Note**: When writing batch node scripts to call `ingestDocument`, remember that `@lotargo/memory_plugin` uses ES Modules (`"type": "module"`). Use `import` syntax instead of `require()`.
135
163
 
@@ -183,9 +211,9 @@ In such cases, use the **Full Raw Document Reading** mechanism:
183
211
  - Use `action: "stats"` to inspect stored document count and total micro-chunks.
184
212
  - Use `action: "list"` to see all ingested documents.
185
213
  - Use `action: "read_document"` with `docId` to read the complete raw text content of any document.
186
- - Use `action: "delete"` with `docId` to remove an outdated document and purge its CAS blob.
187
- - Use `action: "export_snapshot"` with `snapshotPath` to export a JSON backup of the RAG base.
188
- - Use `action: "import_snapshot"` with `snapshotPath` to import and merge a JSON backup into the current database.
214
+ - Use `action: "delete"` with `docId` to unlink a source from the current project by default (or global outside Git). Pass `scope: "global"` or `scope: "all"` only when broader removal is intentional. The document and CAS blob are purged only when no scopes remain.
215
+ - Use `action: "export_snapshot"` with `snapshotPath` to export a complete RAG backup, including scopes, vectors, retrieval policies, graph edges, and Notebook links.
216
+ - Use `action: "import_snapshot"` with `snapshotPath` to import and merge a complete backup. Older unscoped snapshots remain globally visible for compatibility.
189
217
 
190
218
  ### Re-Indexing Embeddings (`reindex_knowledge_base`)
191
219
  Use this tool AFTER changing the embedding model or vector dimension so previously ingested documents remain vector-searchable.
@@ -207,10 +235,13 @@ When working in multi-server environments (e.g., OpenCode, Claude Code), you mig
207
235
 
208
236
  ## 5. Core Directives for AI Agents
209
237
 
210
- 1. **Read Memories First (MANDATORY)**: At the very start of any session or conversation, your VERY FIRST STEP MUST BE to execute `recall` with `scope: "all"` (and without restrictive query filters) to load ALL saved global facts, user context, and project guidelines BEFORE performing any other task or code analysis. Do NOT filter or restrict the initial `recall` call with specific query keywords.
211
- 2. **Be Proactive**: When the user mentions a durable preference, personal fact, or constraint, save it immediately using `remember`. Do not wait for explicit user commands.
212
- 3. **Check Knowledge Base First**: If a query is related to specialized documentation, APIs, or project architectures, call `query_knowledge_base` using concept-dense search phrases. For multi-part queries (comparisons, cross-period analysis), prefer `batch_query_knowledge_base` to reduce API calls and ONNX inference overhead.
213
- 4. **Optimize Search Queries**: Transform the user's natural language question into targeted search queries. "Compare revenue in Q1 vs Q3" `["Выручка план факт Q1 2025", "Выручка план факт Q3 2025"]`. Avoid sending raw conversational questions to the RAG formulated queries improve fact retrieval by 20-40%.
214
- 4. **Inspect Ambiguous Docs Directly**: If querying produces low relevance scores on abstractly-named documents, call `manage_knowledge_base(action: "read_document")` to inspect the full text directly.
215
- 5. **Keep Memory Clean**: If a preference changes, call `update_fact` to edit it in place, or `remember` with `supersedes` to keep a version trail. Use `keep: true` for facts that must survive an accidental `forget`, and give ephemeral facts a `ttl` so stale ones surface as `[EXPIRED]`.
216
- 6. **Leverage MCP Servers**: Proactively list available tools using `list-mcp-tools` and query `mcp-reminder` if unsure of which platform tool can help you automate tasks.
238
+ 1. **Read Full Memories First (MANDATORY)**: At the very start of any session or conversation, your VERY FIRST STEP MUST BE to execute `recall` with `scope: "all"`, full bodies, and no restrictive filters. Do not use `mode: "headers"` for initialization.
239
+ 2. **Ensure Git Project Registration**: After initial recall, call `memory_info`. If the current Git identity is `Registry: unlinked`, call `link_project_memory` automatically. Re-run full recall only when legacy facts were migrated. Outside Git, stay global-only.
240
+ 3. **Be Proactive**: When the user mentions a durable preference, personal fact, or constraint, save it immediately using `remember`. Do not wait for explicit user commands.
241
+ 4. **Curate RAG Selectively**: Preserve important web findings and current technical documentation that the project is likely to need again, especially knowledge newer than model training. Ingest the relevant whole source or excerpt with project scope, not everything encountered, and link it to the project fact it supports. Use global scope only for intentionally cross-project sources.
242
+ 5. **Check Knowledge Base First**: If a query depends on ingested specialized documentation, APIs, code, or project architecture, call `query_knowledge_base` using a concept-dense phrase. Do not use RAG for ordinary conversation or facts already present in Notebook memory. For multi-part queries, prefer `batch_query_knowledge_base`.
243
+ 6. **Optimize Search Queries**: Transform the user's natural language question into targeted search queries. "Compare revenue in Q1 vs Q3" `["Выручка план факт Q1 2025", "Выручка план факт Q3 2025"]`. Avoid raw conversational questions in RAG queries.
244
+ 7. **Inspect Ambiguous Docs Directly**: If querying produces low relevance scores on abstractly named documents, call `manage_knowledge_base(action: "list")`, then `manage_knowledge_base(action: "read_document")` to inspect the full text.
245
+ 8. **Keep Memory Clean**: If a preference changes, call `update_fact` to edit it in place, or `remember` with `supersedes` to keep a version trail. Use `keep: true` for facts that must survive accidental deletion, and give ephemeral facts a `ttl`.
246
+ 9. **Resolve Context, Do Not Enforce Store Precedence**: Global and current-project facts are both evidence. If they conflict, reason over both; do not apply an automatic global-wins or project-wins rule.
247
+ 10. **Leverage MCP Servers**: Use `list-mcp-tools` and `mcp-reminder` when unsure which connected platform tool fits the task.