@lotargo/memory_plugin 1.6.3 → 1.6.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotargo/memory_plugin",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "100% local hybrid RAG memory for AI coding agents (OpenCode, Claude Code, Codex, Antigravity). MCP server + plugin: persistent user facts, document ingestion, vector + SQLite FTS5 retrieval across sessions.",
5
5
  "type": "module",
6
6
  "main": "opencode-plugin/index.js",
@@ -33,10 +33,10 @@
33
33
  "mcp-server/tools",
34
34
  "mcp-server/boot.js",
35
35
  "mcp-server/cli_boot.js",
36
- "mcp-server/cli.js",
37
- "mcp-server/codex_config.js",
38
- "mcp-server/codex_diagnostics.js",
39
- "mcp-server/index.js",
36
+ "mcp-server/cli.js",
37
+ "mcp-server/codex_config.js",
38
+ "mcp-server/codex_diagnostics.js",
39
+ "mcp-server/index.js",
40
40
  "mcp-server/fact_format.js",
41
41
  "mcp-server/identity.js",
42
42
  "mcp-server/logger.js",
@@ -1,100 +1,111 @@
1
- ---
2
- name: using-memory
3
- description: Comprehensive guide for using the Memory, Hybrid RAG Knowledge Engine & MCP Helper tools (remember, recall, get_fact, forget, update_fact, memory_info, link_knowledge, link_project_memory, unlink_project_memory, relink_project_memory, ingest_document, query_knowledge_base, manage_knowledge_base, reindex_knowledge_base, list-mcp-tools, mcp-reminder). Trigger proactively whenever user preferences, project conventions, technology stack choices, or architecture decisions are introduced, or when querying ingested documentation, indexing files/repos, managing persistent knowledge, or looking up available MCP tool integrations.
4
- ---
5
-
6
- # Using Memory, Hybrid RAG Knowledge Engine & MCP Helper Tools
7
-
8
- You have access to a persistent dual-layer memory engine supercharged with an **Agent-Driven Knowledge Graph** and general MCP integration helpers:
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.
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
- 4. **Integration Layer (General MCP Helpers)**: Quickly discovers connected MCP servers and identifies appropriate tools for specific tasks.
13
-
14
- ---
15
-
16
- ## 1. Tool Selection Decision Matrix
17
-
18
- | Scenario / Intent | Target Tool | Key Parameters |
19
- |-------------------|-------------|----------------|
20
- | User shares identity, tech stack preference, or workflow rule | `remember` | `fact` (English), `title` (concise 2-5 word headline), `scope`, optional `docId`, `startLine`, `endLine` |
21
- | User asks what you remember about them, the project, or linked docs | `recall` | `scope` ("all", "global", "project", "list_projects"), `mode` ("full", "headers"), `offset`, `limit`, optional `query`, `tags`, `since`, `until`, `project` (at session start, MUST fetch all memories with `scope: "all"` without restrictive query filters) |
22
- | Get a single fact's text and metadata by ID | `get_fact` | `id` (metadata id e.g. "8f3a2c"), `scope` |
23
- | User corrects/updates an old saved fact | `update_fact` | `id` (number/id/text), `newText`, `scope` |
24
- | Replace a fact but keep a version trail | `remember` | `fact`, `supersedes` (number/id/text) |
25
- | Protect a fact from accidental `forget` | `remember` | `keep: true` |
26
- | Set a time-to-live on a fact | `remember` | `ttl` ("90d", "2w", "24h", "12m") |
27
- | Filter facts by keyword / tags / date | `recall` | `query`, `tags`, `since`, `until` |
28
- | Show storage paths, versions, fact & RAG stats, git identity | `memory_info` | |
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` |
31
- | Remove path alias or purge project identity | `unlink_project_memory` | `directory`, `purge` (boolean) |
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` |
36
- | Read full raw content of an ambiguous/abstract document | `manage_knowledge_base` | `action: "read_document"`, `docId` |
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
- | Re-embed all documents after switching embedding model / dimension | `reindex_knowledge_base` | `model`, `dimension` (optional; defaults to active config) |
39
- | Discover available MCP servers and their specific purposes | `list-mcp-tools` | — |
40
- | Ask which MCP tool / server is suitable for a specific task | `mcp-reminder` | `task` (string, e.g., "db migration") |
41
-
42
- ---
43
-
44
- ## 2. Layer 1 & 3: Notebook Store & Agent-Driven Knowledge Graph (`remember`, `recall`, `update_fact`, `forget`, `memory_info`, `link_knowledge`)
45
-
46
- ### Agent-Driven Knowledge Graph Architecture
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
-
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.
50
-
51
- ### What to Save and Link (`remember` & `link_knowledge`)
52
- - **High-Signal Facts**: User name, role, language preferences, architectural constraints, framework choices, coding standards, test rules.
53
- - **Formatting & Fact Titles**:
54
- - Always translate the fact into clear, concise English before calling `remember`.
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.
57
- - **Linking to Knowledge Base Documents**:
58
- - Pass `docId` (or document title/path) and optional `startLine` / `endLine` when calling `remember` or `link_knowledge`.
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)`
60
- - Example: `link_knowledge(factText: "Use PostgreSQL 16 for primary persistence", docId: "database_guide.md", startLine: 20, endLine: 35, relationType: "IMPLEMENTS")`
61
-
62
- ### How Linked Memory Appears (`recall`)
63
- When `recall` is invoked, the engine returns saved facts along with their Agent-linked Knowledge Base documents and exact line ranges:
64
- ```
65
- --- memory_plugin ---
66
- 1. Use Fastify instead of Express for backend services 🔗 [Linked Docs: Project Architecture Specs:L5-7]
67
- 2. PostgreSQL 16 is primary database 🔗 [Linked Docs: database_guide.md:L20-35]
68
- ```
69
-
70
- ### Fact Line Format & Metadata
71
- Each fact is stored as a single Markdown line with an optional invisible HTML comment carrying metadata:
72
- ```
73
- - [2026-08-02 06:08] user prefers TypeScript <!-- id:8f3a2c, ttl:90d, keep:1, tags:pref,arch -->
74
- ```
75
- Supported metadata keys (set via `remember`, rendered as badges by `recall`):
76
- - `id` — auto-generated short id; stable reference for `update_fact` / `forget` / `supersedes`.
77
- - `ttl` — time-to-live ("90d", "2w", "24h", "12m", bare number = days). Expired facts are marked `[EXPIRED]` but never auto-deleted.
78
- - `keep` protection flag; `forget` skips it unless `force: true`.
79
- - `tags` — comma-separated free-form tags for filtering.
80
- - `supersedes` / `supersededBy` versioning: the old fact gets `[SUPERSEDED]` and is excluded from the injected memory block while staying in the store for history.
81
-
82
- ### Remember Options (`remember`)
83
- - `ttl`: "90d", "2w", "24h", "12m" mark the fact for expiry; it will show `[EXPIRED]` once past.
84
- - `keep: true`: protect the fact from `forget` (unless `force: true`).
85
- - `tags`: comma-separated tags for later filtering, e.g. `"pref,arch"`.
86
- - `supersedes`: number (as listed by `recall`), metadata `id`, or text of the fact this one replaces.
87
-
88
- ### Filtering & Viewing Facts (`recall` & `get_fact`)
89
- - `scope`: `"all"` (default), `"global"`, `"project"`, or `"list_projects"` (lists all project stores, total facts, file paths, and git identity bindings).
90
- - `query`: all space-separated terms must match (case-insensitive); searches text, id, tags, and date.
91
- - `tags`: comma-separated; returns facts with ANY matching tag.
92
- - `since` / `until`: "YYYY-MM-DD" (inclusive) to filter by fact date.
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.
1
+ ---
2
+ name: using-memory
3
+ description: Comprehensive guide for using the Memory, Hybrid RAG Knowledge Engine & MCP Helper tools (remember, recall, get_fact, forget, update_fact, memory_info, link_knowledge, link_project_memory, unlink_project_memory, relink_project_memory, ingest_document, query_knowledge_base, manage_knowledge_base, reindex_knowledge_base, list-mcp-tools, mcp-reminder). Trigger proactively whenever user preferences, project conventions, technology stack choices, or architecture decisions are introduced, or when querying ingested documentation, indexing files/repos, managing persistent knowledge, or looking up available MCP tool integrations.
4
+ ---
5
+
6
+ # Using Memory, Hybrid RAG Knowledge Engine & MCP Helper Tools
7
+
8
+ You have access to a persistent dual-layer memory engine supercharged with an **Agent-Driven Knowledge Graph** and general MCP integration helpers:
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: Curated RAG Knowledge Base**: Preserves selected external findings, documentation, repositories, and technical guides that are likely to matter again.
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
+ 4. **Integration Layer (General MCP Helpers)**: Quickly discovers connected MCP servers and identifies appropriate tools for specific tasks.
13
+
14
+ ---
15
+
16
+ ## 1. Tool Selection Decision Matrix
17
+
18
+ | Scenario / Intent | Target Tool | Key Parameters |
19
+ |-------------------|-------------|----------------|
20
+ | User shares identity, tech stack preference, or workflow rule | `remember` | `fact` (English), `title` (concise 2-5 word headline), `scope`, optional `directory` (workspace path), `docId`, `startLine`, `endLine` |
21
+ | User asks what you remember about them, the project, or linked docs | `recall` | `scope` ("all", "global", "project", "list_projects"), `mode` ("full", "headers"), `offset`, `limit`, optional `query`, `tags`, `since`, `until`, `directory` / `project` (at session start, MUST fetch all memories with `scope: "all"` without restrictive query filters) |
22
+ | Get a single fact's text and metadata by ID | `get_fact` | `id` (metadata id e.g. "8f3a2c"), `scope`, optional `directory` |
23
+ | User corrects/updates an old saved fact | `update_fact` | `id` (number/id/text), `newText`, `scope`, optional `directory` |
24
+ | Replace a fact but keep a version trail | `remember` | `fact`, `supersedes` (number/id/text), optional `directory` |
25
+ | Protect a fact from accidental `forget` | `remember` | `keep: true` |
26
+ | Set a time-to-live on a fact | `remember` | `ttl` ("90d", "2w", "24h", "12m") |
27
+ | Filter facts by keyword / tags / date | `recall` | `query`, `tags`, `since`, `until`, optional `directory` |
28
+ | Show storage paths, versions, fact & RAG stats, git identity | `memory_info` | optional `directory` |
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`, optional `directory` |
30
+ | Register current Git project identity / migrate legacy stores | `memory_info` then `link_project_memory` when `Registry: unlinked` | `directory`, optional `remote` |
31
+ | Remove path alias or purge project identity | `unlink_project_memory` | `directory`, `purge` (boolean) |
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`, `scope` (project default), optional `directory` |
34
+ | User asks a complex question about indexed docs or code | `query_knowledge_base` | `query`, `scope` (all default), `limit`, `instruction`, `generateEmbeddings`, optional `directory` |
35
+ | User needs multiple queries executed in batch (comparisons, multi-topic) | `batch_query_knowledge_base` | `queries` (array), `scope` (all default), `limit`, `instruction`, `generateEmbeddings`, optional `directory` |
36
+ | Read full raw content of an ambiguous/abstract document | `manage_knowledge_base` | `action: "read_document"`, `docId` |
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`, optional `directory` |
38
+ | Re-embed all documents after switching embedding model / dimension | `reindex_knowledge_base` | `model`, `dimension` (optional; defaults to active config) |
39
+ | Discover available MCP servers and their specific purposes | `list-mcp-tools` | — |
40
+ | Ask which MCP tool / server is suitable for a specific task | `mcp-reminder` | `task` (string, e.g., "db migration") |
41
+
42
+ ---
43
+
44
+ ## 2. Layer 1 & 3: Notebook Store & Agent-Driven Knowledge Graph (`remember`, `recall`, `update_fact`, `forget`, `memory_info`, `link_knowledge`)
45
+
46
+ ### Agent-Driven Knowledge Graph Architecture
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
+
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
+
51
+ ### What to Save and Link (`remember` & `link_knowledge`)
52
+ - **High-Signal Facts**: User name, role, language preferences, architectural constraints, framework choices, coding standards, test rules.
53
+ - **Formatting & Fact Titles**:
54
+ - Always translate the fact into clear, concise English before calling `remember`.
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. 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
+ - **Targeting Project Directory (`directory`)**:
58
+ - Pass `directory: "<project directory path>"` (or `project`) when calling `remember` or `recall` to ensure the call routes to the target project store even when the MCP server runs in an external folder or outside Git.
59
+ - Example: `remember(title: "Backend Framework Preference", fact: "Use Fastify instead of Express for backend services", scope: "project", directory: "F:/projects/my-app")`
60
+ - **Linking to Knowledge Base Documents**:
61
+ - Pass `docId` (or document title/path) and optional `startLine` / `endLine` when calling `remember` or `link_knowledge`.
62
+ - 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)`
63
+ - Example: `link_knowledge(factText: "Use PostgreSQL 16 for primary persistence", docId: "database_guide.md", startLine: 20, endLine: 35, relationType: "IMPLEMENTS")`
64
+
65
+ ### How Linked Memory Appears (`recall`)
66
+ When `recall` is invoked, the engine returns saved facts along with their Agent-linked Knowledge Base documents and exact line ranges:
67
+ ```
68
+ --- memory_plugin ---
69
+ 1. Use Fastify instead of Express for backend services 🔗 [Linked Docs: Project Architecture Specs:L5-7]
70
+ 2. PostgreSQL 16 is primary database 🔗 [Linked Docs: database_guide.md:L20-35]
71
+ ```
72
+
73
+ ### Fact Line Format & Metadata
74
+ Each fact is stored as a single Markdown line with an optional invisible HTML comment carrying metadata:
75
+ ```
76
+ - [2026-08-02 06:08] user prefers TypeScript <!-- id:8f3a2c, ttl:90d, keep:1, tags:pref,arch -->
77
+ ```
78
+ Supported metadata keys (set via `remember`, rendered as badges by `recall`):
79
+ - `id` — auto-generated short id; stable reference for `update_fact` / `forget` / `supersedes`.
80
+ - `ttl` — time-to-live ("90d", "2w", "24h", "12m", bare number = days). Expired facts are marked `[EXPIRED]` but never auto-deleted.
81
+ - `keep` — protection flag; `forget` skips it unless `force: true`.
82
+ - `tags` comma-separated free-form tags for filtering.
83
+ - `supersedes` / `supersededBy`versioning: the old fact gets `[SUPERSEDED]` and is excluded from the injected memory block while staying in the store for history.
84
+
85
+ ### Remember Options (`remember`)
86
+ - `directory` / `project`: optional workspace/project directory path to target when saving project facts from outside cwd.
87
+ - `ttl`: "90d", "2w", "24h", "12m" — mark the fact for expiry; it will show `[EXPIRED]` once past.
88
+ - `keep: true`: protect the fact from `forget` (unless `force: true`).
89
+ - `tags`: comma-separated tags for later filtering, e.g. `"pref,arch"`.
90
+ - `supersedes`: number (as listed by `recall`), metadata `id`, or text of the fact this one replaces.
91
+
92
+ ### Filtering & Viewing Facts (`recall` & `get_fact`)
93
+ - `scope`: `"all"` (default), `"global"`, `"project"`, or `"list_projects"` (lists all project stores, total facts, file paths, and git identity bindings).
94
+ - `directory` / `project`: read a specific project's store from any working directory.
95
+ - `query`: all space-separated terms must match (case-insensitive); searches text, id, tags, and date.
96
+ - `tags`: comma-separated; returns facts with ANY matching tag.
97
+ - `since` / `until`: "YYYY-MM-DD" (inclusive) to filter by fact date.
98
+ - `mode`: `"full"` (default) or `"headers"` (returns title and badges only, omitting full text body).
99
+ - `includeSuperseded`: `false` by default so obsolete history does not enter active context; set `true` only to inspect version history.
100
+ - `offset` / `limit`: optional numeric pagination parameters.
101
+ - `get_fact`: fetch exact text and full metadata of a single fact by its metadata id (e.g. `get_fact(id: "8f3a2c")`).
102
+ - Output shows `[EXPIRED]`, `[KEEP]`, `[SUPERSEDED]`, `[INJECT]` badges and the `Store file:` path.
103
+
104
+ ### Scope Isolation and Conflicts
105
+ - `scope: "all"` returns the complete global store plus only the current Git project's store.
106
+ - Outside a Git repository, `scope: "all"` returns global memory only. It must not create a `null` project store.
107
+ - 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.
108
+ - 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
109
 
99
110
  ### Updating Facts (`update_fact`)
100
111
  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 +116,52 @@ When the user corrects an old fact, prefer `update_fact` over `forget`+`remember
105
116
  ### Protecting Facts (`forget` with `keep`)
106
117
  `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
118
 
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:
119
+ ### Project Memory Identity Management (`link_project_memory`, `unlink_project_memory`, `relink_project_memory`)
120
+ 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.
121
+
122
+ Session initialization sequence:
123
+ 1. Call `recall(scope: "all")` first, with full bodies and no filters.
124
+ 2. Call `memory_info` for the current workspace.
125
+ 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.
126
+ 4. If the link result reports `migrated: true`, call `recall(scope: "all")` again so the migrated facts enter the active context.
127
+ 5. If it reports `Identity: no-git`, do not create project memory and do not invent a remote; continue with global memory only.
128
+
129
+ Use the identity tools as follows:
110
130
  - `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
131
  - `unlink_project_memory(directory, purge)`: Removes the path alias link for a directory; set `purge: true` to purge the identity from SQLite.
112
132
  - `relink_project_memory(directory, remote)`: Moves and merges memories from the current project identity to a new target remote URL identity.
113
133
 
114
134
  ### 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).
135
+ `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
136
 
117
137
  ---
118
138
 
119
139
  ## 3. Layer 2: RAG Knowledge Base (`ingest_document`, `query_knowledge_base`, `manage_knowledge_base`, `reindex_knowledge_base`)
120
140
 
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.
141
+ ### Document Ingestion (`ingest_document`)
142
+ 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.
143
+
144
+ Good ingestion candidates:
145
+ - Important information found through web research that should remain available after the current session.
146
+ - Official or otherwise authoritative documentation for a library, framework, API, or tool used by the project.
147
+ - New-version features, changed behavior, migration guidance, or APIs that may be newer than the model's training knowledge.
148
+ - A complete document when most of it is relevant, or only the useful excerpt when the rest would add retrieval noise.
149
+
150
+ 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`.
151
+ - **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.
152
+ - **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.
153
+ - **Stable Updates**: Re-ingesting an updated source preserves its `docId` and Notebook links while replacing chunks, vectors, policies, and structural graph edges.
123
154
  - **Hierarchy Chunking**: The engine automatically creates 3-tier chunks (Big Document -> Medium Section -> Small Micro-Chunk) and extracts GraphRAG code symbols.
124
155
  - **Auto Vector Embeddings**: Dense ONNX vectors (`multilingual-e5-small`) are automatically computed and indexed in SQLite.
125
156
  - **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.
157
+ - `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.
158
+ - `type` (optional, enum: `"text"`, `"file"`, `"url"`): `"text"` (default), `"file"` (safe local-path read or supplied content), or `"url"` (fetches page content).
159
+ - `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
160
  - `title` (optional, string): Provide document title (e.g. `README.md`). If omitted for a URL, the page `<title>` is used.
130
161
  - **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.
162
+ - **Correct Example (local file path)**: `ingest_document(content: "f:/project/docs/guide.md", type: "file", title: "guide.md")`
163
+ - **Correct Example (already-read content)**: `ingest_document(content: "<full text content>", path: "f:/project/docs/guide.md", title: "guide.md", type: "file")`
164
+ - ❌ **Common Error**: passing a file path with the default `type: "text"`; that indexes the path string instead of reading the file.
133
165
 
134
166
  - **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
167
 
@@ -183,9 +215,9 @@ In such cases, use the **Full Raw Document Reading** mechanism:
183
215
  - Use `action: "stats"` to inspect stored document count and total micro-chunks.
184
216
  - Use `action: "list"` to see all ingested documents.
185
217
  - 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.
218
+ - 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.
219
+ - Use `action: "export_snapshot"` with `snapshotPath` to export a complete RAG backup, including scopes, vectors, retrieval policies, graph edges, and Notebook links.
220
+ - Use `action: "import_snapshot"` with `snapshotPath` to import and merge a complete backup. Older unscoped snapshots remain globally visible for compatibility.
189
221
 
190
222
  ### Re-Indexing Embeddings (`reindex_knowledge_base`)
191
223
  Use this tool AFTER changing the embedding model or vector dimension so previously ingested documents remain vector-searchable.
@@ -207,10 +239,13 @@ When working in multi-server environments (e.g., OpenCode, Claude Code), you mig
207
239
 
208
240
  ## 5. Core Directives for AI Agents
209
241
 
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.
242
+ 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.
243
+ 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.
244
+ 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.
245
+ 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.
246
+ 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`.
247
+ 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.
248
+ 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.
249
+ 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`.
250
+ 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.
251
+ 10. **Leverage MCP Servers**: Use `list-mcp-tools` and `mcp-reminder` when unsure which connected platform tool fits the task.