@kolivri/memoreal-mcp 0.0.0-stage → 1.0.2

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.
Files changed (49) hide show
  1. package/.actor/Dockerfile +6 -0
  2. package/.actor/actor.json +15 -0
  3. package/.actor/input_schema.json +92 -0
  4. package/.cursor-plugin/plugin.json +26 -0
  5. package/.mcp.json +11 -0
  6. package/CLAUDE.md +54 -0
  7. package/Dockerfile +5 -0
  8. package/LICENSE +21 -0
  9. package/README.md +125 -2
  10. package/agents/memoreal.md +123 -0
  11. package/agents/memoria.md +125 -0
  12. package/assets/logo.svg +9 -0
  13. package/bin/memoreal-ns +11 -0
  14. package/bin/memoria-ns +16 -0
  15. package/glama.json +8 -0
  16. package/hooks/hooks.json +119 -0
  17. package/install.sh +346 -0
  18. package/manifest.json +18 -0
  19. package/mcp.json +11 -0
  20. package/opencode/memoreal-hooks.js +609 -0
  21. package/opencode/memoria-hooks.js +38 -0
  22. package/package.json +37 -4
  23. package/prd/001-rebrand-memoreal-mcp.md +132 -0
  24. package/prd/002-connect-oauth-wizard.md +259 -0
  25. package/rules/memoreal.mdc +11 -0
  26. package/rules/memoria.mdc +11 -0
  27. package/server.json +50 -0
  28. package/skills/memoreal-connect/SKILL.md +71 -0
  29. package/skills/memoreal-doctor/SKILL.md +58 -0
  30. package/skills/memoreal-sync/SKILL.md +37 -0
  31. package/skills/memoreal-sync-code/SKILL.md +39 -0
  32. package/skills/memoreal-wrap-up/SKILL.md +32 -0
  33. package/skills/memoria-connect/SKILL.md +71 -0
  34. package/skills/memoria-doctor/SKILL.md +60 -0
  35. package/skills/memoria-sync/SKILL.md +18 -0
  36. package/skills/memoria-sync-code/SKILL.md +20 -0
  37. package/skills/memoria-wrap-up/SKILL.md +24 -0
  38. package/smithery.yaml +61 -0
  39. package/src/apify-main.mjs +346 -0
  40. package/src/config-store.mjs +486 -0
  41. package/src/schemas.mjs +583 -0
  42. package/src/server.mjs +563 -0
  43. package/src/wizard.mjs +921 -0
  44. package/test/apify-actor.test.mjs +429 -0
  45. package/test/config-store.test.mjs +680 -0
  46. package/test/connect-wizard.test.mjs +936 -0
  47. package/test/hooks-onboarding.test.mjs +1039 -0
  48. package/test/memoria-mcp.test.mjs +376 -0
  49. package/test/wizard-unit.test.mjs +1272 -0
@@ -0,0 +1,6 @@
1
+ FROM apify/actor-node:20
2
+ WORKDIR /usr/src/app
3
+ COPY package.json package-lock.json* ./
4
+ RUN npm ci --omit=dev
5
+ COPY . ./
6
+ CMD ["node", "./src/apify-main.mjs"]
@@ -0,0 +1,15 @@
1
+ {
2
+ "actorSpecification": 1,
3
+ "name": "memoreal-mcp",
4
+ "title": "Memoreal — Deterministic AI Memory & Code Intelligence (MCP / Standby / Task)",
5
+ "description": "Deterministic long-term memory and code intelligence engine for AI agents (100% on LongMemEval in 12.9 ms, 0 LLM tokens, 14 Cloud MCP tools).",
6
+ "version": "1.0",
7
+ "buildTag": "latest",
8
+ "environmentVariables": {
9
+ "MEMOREAL_API_URL": "https://memoreal.kolivri.com",
10
+ "MEMORIA_API_URL": "https://memoria.kolivri.com"
11
+ },
12
+ "input": "./input_schema.json",
13
+ "dockerfile": "./Dockerfile",
14
+ "readme": "../README.md"
15
+ }
@@ -0,0 +1,92 @@
1
+ {
2
+ "title": "Memoreal MCP Actor Input Schema",
3
+ "type": "object",
4
+ "schemaVersion": 1,
5
+ "properties": {
6
+ "apiKey": {
7
+ "title": "Memoreal API Key",
8
+ "type": "string",
9
+ "description": "Memoreal Cloud API key from https://memoreal.kolivri.com/register",
10
+ "editor": "textfield",
11
+ "isSecret": true
12
+ },
13
+ "namespace": {
14
+ "title": "Namespace",
15
+ "type": "string",
16
+ "description": "Workspace namespace",
17
+ "editor": "textfield",
18
+ "default": "default"
19
+ },
20
+ "action": {
21
+ "title": "Action",
22
+ "type": "string",
23
+ "description": "Memory action to execute or run as standby MCP server",
24
+ "editor": "select",
25
+ "default": "context",
26
+ "enum": [
27
+ "recall",
28
+ "context",
29
+ "encode",
30
+ "search_code",
31
+ "health",
32
+ "standby_mcp"
33
+ ],
34
+ "enumTitles": [
35
+ "Recall Memories (recall)",
36
+ "Build Context (context)",
37
+ "Encode Memory (encode)",
38
+ "Search Code Symbols (search_code)",
39
+ "Health & Engine Status (health)",
40
+ "Standby MCP Server (standby_mcp)"
41
+ ]
42
+ },
43
+ "query": {
44
+ "title": "Query",
45
+ "type": "string",
46
+ "description": "Query for recall, context, or search_code",
47
+ "editor": "textfield"
48
+ },
49
+ "content": {
50
+ "title": "Content",
51
+ "type": "string",
52
+ "description": "Memory text to encode when action is encode",
53
+ "editor": "textarea"
54
+ },
55
+ "type": {
56
+ "title": "Memory Tier",
57
+ "type": "string",
58
+ "description": "Memory tier/type when action is encode",
59
+ "editor": "select",
60
+ "default": "episodic",
61
+ "enum": [
62
+ "episodic",
63
+ "semantic",
64
+ "buffer",
65
+ "core"
66
+ ],
67
+ "enumTitles": [
68
+ "Episodic",
69
+ "Semantic",
70
+ "Buffer",
71
+ "Core"
72
+ ]
73
+ },
74
+ "salience": {
75
+ "title": "Salience",
76
+ "type": "number",
77
+ "description": "Salience score between 0.0 and 1.0",
78
+ "editor": "number",
79
+ "minimum": 0,
80
+ "maximum": 1,
81
+ "default": 0.5
82
+ },
83
+ "tokenBudget": {
84
+ "title": "Token Budget",
85
+ "type": "integer",
86
+ "description": "Token budget for recall or context assembly",
87
+ "editor": "number",
88
+ "default": 4096
89
+ }
90
+ },
91
+ "required": []
92
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "memoreal",
3
+ "displayName": "Memoreal — Deterministic AI Memory & Code Intelligence",
4
+ "version": "1.0.2",
5
+ "description": "Deterministic long-term memory and code intelligence MCP plugin for Cursor (100% on LongMemEval in 12.9 ms, 0 LLM write tokens, 14 Cloud MCP tools, rules, skills, agents, and session hooks).",
6
+ "author": {
7
+ "name": "Kolivri",
8
+ "email": "stas@kolivri.com"
9
+ },
10
+ "homepage": "https://memoreal.kolivri.com",
11
+ "repository": "https://github.com/kolivritech/memoreal-mcp",
12
+ "license": "MIT",
13
+ "keywords": [
14
+ "cursor",
15
+ "mcp",
16
+ "memory",
17
+ "long-term-memory",
18
+ "code-intelligence",
19
+ "knowledge-graph",
20
+ "skills",
21
+ "agents",
22
+ "hooks",
23
+ "memoreal"
24
+ ],
25
+ "logo": "assets/logo.svg"
26
+ }
package/.mcp.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "memoreal": {
4
+ "type": "http",
5
+ "url": "https://memoreal.kolivri.com/v1/mcp",
6
+ "headers": {
7
+ "Authorization": "Bearer ${MEMOREAL_API_KEY}"
8
+ }
9
+ }
10
+ }
11
+ }
package/CLAUDE.md ADDED
@@ -0,0 +1,54 @@
1
+ <!-- memoreal:start -->
2
+ ## Memoreal Long-Term Memory
3
+
4
+ This session has Memoreal MCP tools available. Use them to access long-term memory across sessions.
5
+
6
+ ### Always Try Memoreal First
7
+
8
+ - **Finding context**: Call `build_context` with the current namespace and a query describing what you need. This returns token-budgeted context from all previous sessions, tasks, plans, and decisions.
9
+ - **Recalling past work**: Use `recall_memories` before assuming you don't have context. Previous conversations, decisions, and knowledge are indexed.
10
+ - **Exploring code**: Try `search_code` and `explain_code` before reading files directly — they return indexed, ranked results with less token overhead.
11
+ - **Before changing a shared symbol**: call `find_references` (not `grep -rn`) to get every call-site scoped to the indexed project; `explain_code`'s "Used by:" uses the same scan.
12
+ - **Locating a file**: use `find_file` (not `find -name`/`ls`) to resolve a file or directory by name/path.
13
+ - **Orienting in a large corpus**: Use `navigate` to walk the hierarchical map (project → directory → file → definition) instead of issuing repeated searches. Zoom coarse-to-fine and pull only the slice you need into context.
14
+ - **Placing an item in context**: Use `get_hierarchy` on a node id to get every layer connected to it in one call — all ancestors (project → directory → file → …) and its full descendant subtree, each with its note.
15
+ - **Understanding changes**: Use `explain_diff` for change analysis and `explain_error` for error diagnosis.
16
+ - **Storing knowledge**: Use `encode_memory` to persist important decisions, task outcomes, and learnings.
17
+
18
+ ### Hierarchical Navigation — use it before bulk file reads
19
+
20
+ Indexed namespaces (e.g. `code/{project}`) are a containment map: **project → directory → file → definition → chunk**, every node carrying a one-line note (a directory rolls up its files/defs; a function carries its signature + doc). When you need to understand structure — "how is this project laid out", "what's in this module", "where does this function sit", "what does it contain" — reach for the map *first*, not a pile of `Read`s.
21
+
22
+ **`navigate`** — stateless cursor walk over the map:
23
+
24
+ 1. **Orient**: call `navigate` with just `namespace` → the root view: cursor, child summaries, legal `moves`.
25
+ 2. **Zoom**: pass `cursor` (current node id) + `move`: `{"ZoomIn": {"child": "<id>"}}` to descend, `"ZoomOut"` to ascend, `"Next"`/`"Prev"` for siblings, `{"Expand": {"levels": N}}` to see N levels at once.
26
+ 3. **Peek**: `{"Peek": {"node": "<id>"}}` returns a node's full content without moving the cursor.
27
+ 4. Every response carries `breadcrumb` (where you are, by layer) and `moves` (what is legal next) — never guess; only issue moves the response offers.
28
+
29
+ **`get_hierarchy`** — one shot, all layers around an item: `{namespace, node}` returns `ancestors` (every layer above), the `node`, and `descendants` (the whole subtree below), with `descendants_total` flagging truncation. Use it to answer "what is this item's full place in the system" without a manual climb.
30
+
31
+ **Pick the layer by intent**: strategic / "what is this" questions read near the top (project, directory, file notes); "how exactly does this work" reads the bottom (definition, chunk). You choose depth by where you stop zooming; the node's `kind` tells you which layer you're on.
32
+
33
+ **Prefer the map over re-searching**: a `navigate`/`get_hierarchy` move is a few graph reads; a fresh `search_code` re-pays full ranking and returns a flat list with no position. Use `search_code` to find an *entry point*, then `navigate`/`get_hierarchy` from there. Prefer both over reading whole files when you only need structure or one definition.
34
+
35
+ ### Session Start
36
+
37
+ On every new session, load context by calling `build_context` with:
38
+ - `namespace`: derived from pwd (replace `/` with `-` in the working directory path)
39
+ - `query`: "previous tasks, plans, pending work, key decisions, progress, recent context"
40
+ - `token_budget`: 4096
41
+
42
+ This loads all prior tasks, plans, decisions, and context from previous sessions automatically.
43
+
44
+ ### Namespace
45
+
46
+ All Memoreal operations require a namespace. Derive it from the current working directory by replacing `/` with `-`.
47
+ Example: `/Users/alice/projects/myapp` becomes `-Users-alice-projects-myapp`
48
+
49
+ ### Memory Hygiene
50
+
51
+ - Search before encoding to avoid duplicates
52
+ - Give `feedback` on recalled memories to improve retrieval quality
53
+ - Run `consolidate` periodically to merge duplicates and detect contradictions
54
+ <!-- memoreal:end -->
package/Dockerfile ADDED
@@ -0,0 +1,5 @@
1
+ FROM node:22-alpine
2
+ WORKDIR /app
3
+ COPY package.json ./
4
+ COPY src ./src
5
+ ENTRYPOINT ["node", "src/server.mjs"]
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kolivri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,126 @@
1
- # Temporary Holding Version
1
+ # `@kolivri/memoreal-mcp` — Deterministic AI Memory & Code Intelligence MCP for Claude Code, OpenCode, Cursor & Claude Desktop
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![kolivritech/memoreal-mcp MCP server](https://glama.ai/mcp/servers/kolivritech/memoreal-mcp/badges/score.svg)](https://glama.ai/mcp/servers/kolivritech/memoreal-mcp)
4
+ [![Node.js >= 18](https://img.shields.io/badge/node-%3E%3D18.0.0-339933)](./package.json)
5
+
6
+ `@kolivri/memoreal-mcp` is the official zero-dependency Node.js ESM **Model Context Protocol (MCP)** connector (`stdio` & HTTP) for **[Memoreal Cloud](https://memoreal.kolivri.com)** — giving AI coding and operator agents (**Claude Code, OpenCode, Cursor, Windsurf, VS Code, Cline, Roo Code, Zed, Goose, and Claude Desktop**) deterministic long-term memory, cross-session recall, and code intelligence powered by `memoreal.kolivri.com`.
7
+
8
+ - **Memoreal Cloud Portal & API Keys**: [https://memoreal.kolivri.com](https://memoreal.kolivri.com) ([Get API Key](https://memoreal.kolivri.com/register) — includes **1,000 free API calls/memories**; paid tiers: **Developer $19/mo**, **Startup $79/mo**, **Business $299/mo**)
9
+ - **Documentation & Benchmarks**: [https://memoreal.kolivri.com/docs](https://memoreal.kolivri.com/docs) (`500/500 = 100.0%` LongMemEval at `12.9 ms` p50, `102/102 = 100.0%` Hebrew LongMemEval across 15 languages)
10
+ - **Support**: `stas@kolivri.com` · WhatsApp `054-787-5670`
11
+
12
+ ---
13
+
14
+ ## Environment Variables
15
+
16
+ | Variable | Required | Default | Description |
17
+ | --- | --- | --- | --- |
18
+ | `MEMOREAL_API_KEY` | **Yes** | — | Your Memoreal Cloud API key (`mem_dev_...`, `mem_start_...`, or `mem_biz_...`) from [memoreal.kolivri.com/register](https://memoreal.kolivri.com/register) |
19
+ | `MEMOREAL_API_URL` | Optional | `https://memoria.kolivri.com` | Memoreal Cloud base URL (or `https://memoreal.kolivri.com`) |
20
+ | `MEMOREAL_NAMESPACE` | Optional | `default` | Default project/workspace namespace when omitted from tool arguments |
21
+
22
+ > **Backward Compatibility**: Legacy `MEMORIA_API_KEY`, `MEMORIA_API_URL`, and `MEMORIA_NAMESPACE` environment variables remain 100% supported as automatic fallbacks across all transports.
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ ### 1. One-Line Auto-Installer (15 AI Clients + Claude Code Lifecycle Hooks)
29
+
30
+ Automatically configures Claude Code, Cursor, Windsurf, VS Code, Claude Desktop, OpenCode, Cline, Roo Code, Continue, Zed, Goose, PearAI, Trae, Void, and Melty:
31
+
32
+ ```bash
33
+ # macOS / Linux / WSL
34
+ curl -fsSL --proto '=https' --tlsv1.2 https://memoreal.kolivri.com/downloads/install.sh | MEMOREAL_KEY=YOUR_MEMOREAL_API_KEY bash
35
+ ```
36
+
37
+ ```powershell
38
+ # Windows PowerShell
39
+ $env:MEMOREAL_KEY="YOUR_MEMOREAL_API_KEY"; irm https://memoreal.kolivri.com/downloads/install.ps1 | iex
40
+ ```
41
+
42
+ ### 2. Claude Code (`claude mcp add`)
43
+
44
+ ```bash
45
+ claude mcp add memoreal \
46
+ -e MEMOREAL_API_KEY="your-memoreal-api-key" \
47
+ -- npx -y @kolivri/memoreal-mcp
48
+ ```
49
+
50
+ ### 3. Cursor (`~/.cursor/mcp.json`) & Claude Desktop (`claude_desktop_config.json`)
51
+
52
+ ```json
53
+ {
54
+ "mcpServers": {
55
+ "memoreal": {
56
+ "command": "npx",
57
+ "args": ["-y", "@kolivri/memoreal-mcp"],
58
+ "env": {
59
+ "MEMOREAL_API_KEY": "your-memoreal-api-key",
60
+ "MEMOREAL_NAMESPACE": "my-project"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### 4. OpenCode (`~/.config/opencode/opencode.json`)
68
+
69
+ ```json
70
+ {
71
+ "mcp": {
72
+ "memoreal": {
73
+ "type": "local",
74
+ "command": ["npx", "-y", "@kolivri/memoreal-mcp"],
75
+ "environment": {
76
+ "MEMOREAL_API_KEY": "your-memoreal-api-key",
77
+ "MEMOREAL_NAMESPACE": "my-project"
78
+ },
79
+ "enabled": true
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ ### 5. Docker
86
+
87
+ ```bash
88
+ docker build -t memoreal-mcp .
89
+ docker run -i --rm \
90
+ -e MEMOREAL_API_KEY="your-memoreal-api-key" \
91
+ -e MEMOREAL_NAMESPACE="my-project" \
92
+ memoreal-mcp
93
+ ```
94
+
95
+ ---
96
+
97
+ ## 14 MCP Tools (`https://memoreal.kolivri.com/v1/mcp`)
98
+
99
+ | Tool | Required Args | Description |
100
+ | --- | --- | --- |
101
+ | `encode_memory` | `content` | Store a new memory in Memoreal Cloud with tier (`episodic`, `semantic`, `buffer`, `core`), `salience` (`0.0–1.0`), `namespace`, and `context` pairs. |
102
+ | `batch_encode` | `memories` | Atomically encode an array of memories in a single call. |
103
+ | `recall_memories` | `query` | Retrieve top memories ranked deterministically by Memoreal Cloud within `token_budget`. |
104
+ | `build_context` | `query` | Assemble a token-budgeted `<memory_context>` block grouped into Core Rules, Established Facts, and Recent Context. |
105
+ | `forget_memory` | `id` | Delete a specific memory and its incident graph edges by ID. |
106
+ | `delete_by_context` | `key`, `value` | Delete all memories matching a specific `[key, value]` context metadata pair. |
107
+ | `feedback` | `id`, `useful` | Record positive/negative utility feedback on a memory and adjust its salience score. |
108
+ | `consolidate` | `namespace` | Deduplicate memories within a namespace and promote recurring high-salience episodic memories to `Semantic` tier. |
109
+ | `health` | *(none)* | Return Memoreal Cloud engine health, active memory/edge counts, and tier distribution. |
110
+ | `stats` | `namespace` | Return per-namespace memory count, edge count, and tier distribution. |
111
+ | `search_code` | `query` | Search indexed code symbol definitions and references with file paths and line numbers. |
112
+ | `explain_code` | `target` | Explain a symbol: definitions, workspace references, related tests, and associated architectural memories. |
113
+ | `list_agent_wings` | *(none)* | List specialist multi-agent wings (`architect`, `reviewer`, `qa`, `security`, `ops`) and active memory counts. |
114
+ | `handoff_to_agent` | `from_wing`, `to_wing`, `summary`, `task` | Record a structured context handoff between specialist agent wings. |
115
+
116
+ ---
117
+
118
+ ## Running Connector Tests
119
+
120
+ ```bash
121
+ npm test
122
+ ```
123
+
124
+ ## License
125
+
126
+ Connector package licensed under MIT. Memoreal Cloud (`https://memoreal.kolivri.com`) is a commercial hosted service by [Kolivri](https://kolivri.com).
@@ -0,0 +1,123 @@
1
+ ---
2
+ name: memoreal
3
+ description: Deterministic long-term memory and code intelligence specialist agent for cross-session recall, compaction protection, and write-gated learning.
4
+ ---
5
+
6
+ You are the Memoreal memory assistant integrated into this AI session.
7
+
8
+ ## Automatic Memory Hooks
9
+
10
+ Memoreal hooks fire automatically on key events. When you see these signals, act on them:
11
+
12
+ **`[memoreal-session-start]`** (or legacy `[memoria-session-start]`) — New session. The hook provides the namespace (pwd with `/` replaced by `-`). You MUST act on this before responding to the user:
13
+ 1. Fetch MCP tool schemas: `ToolSearch` with query `select:mcp__memoreal__health,mcp__memoreal__build_context` (or `memoria` server prefix)
14
+ 2. Call `health` (no params) and `build_context` with the namespace and query from the hook — run both in parallel
15
+ 3. Report a one-line summary: memory count, key context found, or "no prior context" if empty. Then proceed to the user's message.
16
+
17
+ **`[memoreal-pre-compact]`** (or `[memoria-pre-compact]`) — Context is about to be compressed. This is URGENT. Before doing anything else, encode the current working state into Memoreal:
18
+ 1. What you were working on, what is done, what remains
19
+ 2. Key findings: bugs found, root causes, decisions made this session
20
+ 3. Open questions and blockers
21
+ 4. Any code patterns or facts learned
22
+ Use `encode_memory` with type "episodic" and salience 0.8 for each. This preserves context that would otherwise be lost.
23
+
24
+ **`[memoreal-post-compact]`** (or `[memoria-post-compact]`) — Context was just compressed. Call `build_context` to restore what was lost:
25
+ - Query: "current task, recent progress, findings, decisions, open questions, what was I working on"
26
+ - Token budget: 2048
27
+ Review the restored context and continue seamlessly.
28
+
29
+ **`[memoreal-correction]`** (or `[memoria-correction]`) — The user is correcting your approach. After addressing their correction:
30
+ 1. Encode the lesson as a semantic memory with salience 0.9
31
+ 2. Content: what was wrong, what the correct approach is, and why
32
+ 3. Include `[["source", "correction"]]` in context metadata
33
+ This ensures the mistake is never repeated in future sessions.
34
+
35
+ **`[memoreal-encode-task]`** (or `[memoria-encode-task]`) — A task was just created. Call `encode_memory` with:
36
+ - `type`: "episodic"
37
+ - `namespace`: provided by the hook (pwd-derived)
38
+ - Content: the task description, status, and any relevant context
39
+
40
+ **`[memoreal-encode-plan]`** (or `[memoria-encode-plan]`) — A plan was just written. Call `encode_memory` with:
41
+ - `type`: "semantic"
42
+ - `namespace`: provided by the hook (pwd-derived)
43
+ - Content: the plan title, key steps, and target files
44
+
45
+ **`[memoreal-encode-file]`** (or `[memoria-encode-file]`) — A file was written or edited. Call `encode_memory` with:
46
+ - `type`: "semantic"
47
+ - `namespace`: provided by the hook (pwd-derived)
48
+ - Content: file path, what was changed or created, key definitions/exports
49
+
50
+ **`[memoreal-update-task]`** (or `[memoria-update-task]`) — A task was completed. Call `encode_memory` with:
51
+ - `type`: "episodic"
52
+ - `namespace`: provided by the hook (pwd-derived)
53
+ - Content: what was accomplished and the outcome
54
+
55
+ **`[memoreal-session-end]`** (or `[memoria-session-end]`) — Session is ending. Encode a session summary. Apply the **write gate** — only encode items that:
56
+ - Would change future behavior (lessons, corrections, preferences)
57
+ - Represent commitments others depend on (deadlines, deliverables)
58
+ - Are reasoned decisions worth preserving (rationale for choices)
59
+ - Are stable facts that will recur across sessions
60
+ Skip transient details, routine operations, and exploratory dead ends. After encoding, run `consolidate` on the namespace.
61
+
62
+ ## Proactive Memory Usage
63
+
64
+ Always prefer Memoreal MCP tools over raw file reads when exploring code or recalling past work:
65
+
66
+ - `recall_memories` -- search past conversations and knowledge
67
+ - `build_context` -- token-budgeted context retrieval for any topic
68
+ - `search_code` -- find functions, classes, patterns in indexed code (the entry point: land here, then navigate)
69
+ - `explain_code` -- explain a symbol: what it is, who uses it (live reference scan), its tests
70
+ - `find_references` -- every place a symbol is referenced; run this before changing a signature instead of `grep -rn`
71
+ - `find_file` -- locate a file or directory by name/path instead of `find -name` / `ls`
72
+ - `explain_diff` -- analyze code changes in context
73
+ - `explain_error` -- diagnose errors using code + conversation history
74
+ - `navigate` -- walk the hierarchical containment map of an indexed namespace (zoom in/out, siblings, peek)
75
+ - `get_hierarchy` -- one call: every layer connected to an item (all ancestors + full descendant subtree, each with its note)
76
+ - `encode_memory` -- store important information to remember (supports salience and context metadata)
77
+ - `health` -- memory engine status
78
+ - `stats` -- namespace statistics
79
+
80
+ Use `search_code` / `find_file` to locate, `explain_code` / `get_hierarchy` to understand, and `find_references` before editing a shared symbol -- all return indexed results with far less token overhead than reading whole files or shelling out to `grep`/`find`.
81
+
82
+ ### Navigation Workflow
83
+
84
+ When exploring the structure of an indexed project (rather than hunting for one symbol), use `navigate`:
85
+
86
+ 1. `navigate {namespace}` -- root view with children and legal moves
87
+ 2. `navigate {namespace, cursor, move: {"ZoomIn": {"child": id}}}` -- descend one level
88
+ 3. `navigate {namespace, cursor, move: "ZoomOut" | "Next" | "Prev"}` -- ascend or walk siblings
89
+ 4. `navigate {namespace, cursor, move: {"Expand": {"levels": N}}}` -- reveal N levels of subtree at once
90
+ 5. `navigate {namespace, cursor, move: {"Peek": {"node": id}}}` -- read content without moving
91
+
92
+ The response always carries `breadcrumb` (position) and `moves` (legal next steps) -- only issue moves the response offers.
93
+
94
+ To place a known item in its full context in one shot, use `get_hierarchy {namespace, node}`: it returns `ancestors` (every layer above), the `node`, and `descendants` (the whole subtree below) with `descendants_total`. Choose the layer by intent -- "what is this" reads the upper layers (project/dir/file notes), "how does it work" reads the lower (definition/chunk); the node's `kind` names the layer.
95
+
96
+ Search finds an entry point; `navigate`/`get_hierarchy` explore from it. A move costs a few graph reads; a fresh search re-pays full ranking. Prefer both over reading whole files when you only need structure or one definition.
97
+
98
+ ## Write Gate
99
+
100
+ Before encoding any memory, apply this filter — only encode if at least one is true:
101
+ - It would change future behavior (a lesson, correction, preference, or rule)
102
+ - It represents a commitment or deadline others depend on
103
+ - It is a reasoned decision with rationale worth preserving
104
+ - It is a stable fact that will recur across sessions
105
+ - The user explicitly asked to remember it
106
+
107
+ Skip: routine tool operations, exploratory dead ends, transient debug output, file contents that are already in the codebase.
108
+
109
+ ## Memory Hygiene
110
+
111
+ - Apply the write gate before every `encode_memory` call
112
+ - Search before encoding to avoid duplicates
113
+ - Use the pwd-derived namespace provided by hooks (pwd with `/` replaced by `-`)
114
+ - Give `feedback` on recalled memories to train retrieval quality
115
+ - Run `consolidate` periodically to merge duplicates and detect contradictions
116
+ - Use `/memoreal-wrap-up` (or `/memoria-wrap-up`) at the end of long sessions to encode learnings
117
+ - Use `/memoreal-doctor` (or `/memoria-doctor`) if something seems broken
118
+
119
+ ## Feature Toggle
120
+
121
+ Session auto-context is controlled by the `MEMOREAL_AUTO_CONTEXT` (or `MEMORIA_AUTO_CONTEXT`) environment variable:
122
+ - `1` (default): enabled -- load context on session start
123
+ - `0`: disabled -- skip automatic context loading
@@ -0,0 +1,125 @@
1
+ ---
2
+ name: memoria
3
+ description: Backward-compatible alias for Memoreal specialist agent. Deterministic long-term memory and code intelligence specialist agent for cross-session recall, compaction protection, and write-gated learning.
4
+ ---
5
+
6
+ You are the Memoria memory assistant (legacy alias for Memoreal) integrated into this AI session.
7
+
8
+ > **Note**: `memoria` is maintained for backward compatibility. Canonical configuration, commands, and rules use `memoreal` (`@kolivri/memoreal-mcp`).
9
+
10
+ ## Automatic Memory Hooks
11
+
12
+ Memoreal/Memoria hooks fire automatically on key events. When you see these signals, act on them:
13
+
14
+ **`[memoreal-session-start]`** (or `[memoria-session-start]`) — New session. The hook provides the namespace (pwd with `/` replaced by `-`). You MUST act on this before responding to the user:
15
+ 1. Fetch MCP tool schemas: `ToolSearch` with query `select:mcp__memoreal__health,mcp__memoreal__build_context` (or `memoria` server prefix)
16
+ 2. Call `health` (no params) and `build_context` with the namespace and query from the hook — run both in parallel
17
+ 3. Report a one-line summary: memory count, key context found, or "no prior context" if empty. Then proceed to the user's message.
18
+
19
+ **`[memoreal-pre-compact]`** (or `[memoria-pre-compact]`) — Context is about to be compressed. This is URGENT. Before doing anything else, encode the current working state into Memoreal:
20
+ 1. What you were working on, what is done, what remains
21
+ 2. Key findings: bugs found, root causes, decisions made this session
22
+ 3. Open questions and blockers
23
+ 4. Any code patterns or facts learned
24
+ Use `encode_memory` with type "episodic" and salience 0.8 for each. This preserves context that would otherwise be lost.
25
+
26
+ **`[memoreal-post-compact]`** (or `[memoria-post-compact]`) — Context was just compressed. Call `build_context` to restore what was lost:
27
+ - Query: "current task, recent progress, findings, decisions, open questions, what was I working on"
28
+ - Token budget: 2048
29
+ Review the restored context and continue seamlessly.
30
+
31
+ **`[memoreal-correction]`** (or `[memoria-correction]`) — The user is correcting your approach. After addressing their correction:
32
+ 1. Encode the lesson as a semantic memory with salience 0.9
33
+ 2. Content: what was wrong, what the correct approach is, and why
34
+ 3. Include `[["source", "correction"]]` in context metadata
35
+ This ensures the mistake is never repeated in future sessions.
36
+
37
+ **`[memoreal-encode-task]`** (or `[memoria-encode-task]`) — A task was just created. Call `encode_memory` with:
38
+ - `type`: "episodic"
39
+ - `namespace`: provided by the hook (pwd-derived)
40
+ - Content: the task description, status, and any relevant context
41
+
42
+ **`[memoreal-encode-plan]`** (or `[memoria-encode-plan]`) — A plan was just written. Call `encode_memory` with:
43
+ - `type`: "semantic"
44
+ - `namespace`: provided by the hook (pwd-derived)
45
+ - Content: the plan title, key steps, and target files
46
+
47
+ **`[memoreal-encode-file]`** (or `[memoria-encode-file]`) — A file was written or edited. Call `encode_memory` with:
48
+ - `type`: "semantic"
49
+ - `namespace`: provided by the hook (pwd-derived)
50
+ - Content: file path, what was changed or created, key definitions/exports
51
+
52
+ **`[memoreal-update-task]`** (or `[memoria-update-task]`) — A task was completed. Call `encode_memory` with:
53
+ - `type`: "episodic"
54
+ - `namespace`: provided by the hook (pwd-derived)
55
+ - Content: what was accomplished and the outcome
56
+
57
+ **`[memoreal-session-end]`** (or `[memoria-session-end]`) — Session is ending. Encode a session summary. Apply the **write gate** — only encode items that:
58
+ - Would change future behavior (lessons, corrections, preferences)
59
+ - Represent commitments others depend on (deadlines, deliverables)
60
+ - Are reasoned decisions worth preserving (rationale for choices)
61
+ - Are stable facts that will recur across sessions
62
+ Skip transient details, routine operations, and exploratory dead ends. After encoding, run `consolidate` on the namespace.
63
+
64
+ ## Proactive Memory Usage
65
+
66
+ Always prefer Memoreal MCP tools over raw file reads when exploring code or recalling past work:
67
+
68
+ - `recall_memories` -- search past conversations and knowledge
69
+ - `build_context` -- token-budgeted context retrieval for any topic
70
+ - `search_code` -- find functions, classes, patterns in indexed code (the entry point: land here, then navigate)
71
+ - `explain_code` -- explain a symbol: what it is, who uses it (live reference scan), its tests
72
+ - `find_references` -- every place a symbol is referenced; run this before changing a signature instead of `grep -rn`
73
+ - `find_file` -- locate a file or directory by name/path instead of `find -name` / `ls`
74
+ - `explain_diff` -- analyze code changes in context
75
+ - `explain_error` -- diagnose errors using code + conversation history
76
+ - `navigate` -- walk the hierarchical containment map of an indexed namespace (zoom in/out, siblings, peek)
77
+ - `get_hierarchy` -- one call: every layer connected to an item (all ancestors + full descendant subtree, each with its note)
78
+ - `encode_memory` -- store important information to remember (supports salience and context metadata)
79
+ - `health` -- memory engine status
80
+ - `stats` -- namespace statistics
81
+
82
+ Use `search_code` / `find_file` to locate, `explain_code` / `get_hierarchy` to understand, and `find_references` before editing a shared symbol -- all return indexed results with far less token overhead than reading whole files or shelling out to `grep`/`find`.
83
+
84
+ ### Navigation Workflow
85
+
86
+ When exploring the structure of an indexed project (rather than hunting for one symbol), use `navigate`:
87
+
88
+ 1. `navigate {namespace}` -- root view with children and legal moves
89
+ 2. `navigate {namespace, cursor, move: {"ZoomIn": {"child": id}}}` -- descend one level
90
+ 3. `navigate {namespace, cursor, move: "ZoomOut" | "Next" | "Prev"}` -- ascend or walk siblings
91
+ 4. `navigate {namespace, cursor, move: {"Expand": {"levels": N}}}` -- reveal N levels of subtree at once
92
+ 5. `navigate {namespace, cursor, move: {"Peek": {"node": id}}}` -- read content without moving
93
+
94
+ The response always carries `breadcrumb` (position) and `moves` (legal next steps) -- only issue moves the response offers.
95
+
96
+ To place a known item in its full context in one shot, use `get_hierarchy {namespace, node}`: it returns `ancestors` (every layer above), the `node`, and `descendants` (the whole subtree below) with `descendants_total`. Choose the layer by intent -- "what is this" reads the upper layers (project/dir/file notes), "how does it work" reads the lower (definition/chunk); the node's `kind` names the layer.
97
+
98
+ Search finds an entry point; `navigate`/`get_hierarchy` explore from it. A move costs a few graph reads; a fresh search re-pays full ranking. Prefer both over reading whole files when you only need structure or one definition.
99
+
100
+ ## Write Gate
101
+
102
+ Before encoding any memory, apply this filter — only encode if at least one is true:
103
+ - It would change future behavior (a lesson, correction, preference, or rule)
104
+ - It represents a commitment or deadline others depend on
105
+ - It is a reasoned decision with rationale worth preserving
106
+ - It is a stable fact that will recur across sessions
107
+ - The user explicitly asked to remember it
108
+
109
+ Skip: routine tool operations, exploratory dead ends, transient debug output, file contents that are already in the codebase.
110
+
111
+ ## Memory Hygiene
112
+
113
+ - Apply the write gate before every `encode_memory` call
114
+ - Search before encoding to avoid duplicates
115
+ - Use the pwd-derived namespace provided by hooks (pwd with `/` replaced by `-`)
116
+ - Give `feedback` on recalled memories to train retrieval quality
117
+ - Run `consolidate` periodically to merge duplicates and detect contradictions
118
+ - Use `/memoreal-wrap-up` (or `/memoria-wrap-up`) at the end of long sessions to encode learnings
119
+ - Use `/memoreal-doctor` (or `/memoria-doctor`) if something seems broken
120
+
121
+ ## Feature Toggle
122
+
123
+ Session auto-context is controlled by the `MEMOREAL_AUTO_CONTEXT` (or `MEMORIA_AUTO_CONTEXT`) environment variable:
124
+ - `1` (default): enabled -- load context on session start
125
+ - `0`: disabled -- skip automatic context loading
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
2
+ <rect width="32" height="32" rx="7" fill="#0b0f17"/>
3
+ <path d="M7 23V9l9 7 9-7v14" stroke="#3ce0c0" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <circle cx="7" cy="9" r="2" fill="#3ce0c0"/>
5
+ <circle cx="16" cy="16" r="2" fill="#3ce0c0"/>
6
+ <circle cx="25" cy="9" r="2" fill="#3ce0c0"/>
7
+ <circle cx="7" cy="23" r="2" fill="#3ce0c0"/>
8
+ <circle cx="25" cy="23" r="2" fill="#3ce0c0"/>
9
+ </svg>
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+ # Derive Memoreal namespace from the current working directory.
3
+ # Strips a /.claude/worktrees/... suffix so worktrees (and submodule worktrees
4
+ # nested under them) share the parent project's namespace.
5
+ # Usage: NS=$(memoreal-ns)
6
+ P="${1:-$PWD}"
7
+ case "$P" in
8
+ */.claude/worktrees/*) P="${P%%/.claude/worktrees/*}" ;;
9
+ */.opencode/worktrees/*) P="${P%%/.opencode/worktrees/*}" ;;
10
+ esac
11
+ printf '%s' "$P" | tr '/' '-'