memoryai-mcp 2.2.0 → 2.3.1

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.
@@ -1,7 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * memoryai-kiro-setup
4
- * Zero-dependency setup script that creates .kiro/settings/mcp.json
5
- * and .kiro/steering/memoryai.md in the current project directory.
4
+ * Zero-dependency setup script that creates, in the current project:
5
+ * - .kiro/settings/mcp.json (MCP server wiring)
6
+ * - .kiro/steering/memoryai.md (always-on instructions, soft fallback)
7
+ * - .kiro/hooks/memoryai-auto-recall.kiro.hook (promptSubmit → bootstrap/recall)
8
+ * - .kiro/hooks/memoryai-auto-capture.kiro.hook (agentStop → store/compact)
9
+ *
10
+ * The two hooks are what make memory TRULY automatic: they fire on IDE events
11
+ * (every prompt / end of every turn) instead of relying on the agent to
12
+ * remember the steering instructions. Result: the user installs once and never
13
+ * has to think about memory again — recall happens before answers, persistence
14
+ * happens after turns, compaction happens when context fills.
6
15
  */
7
16
  export {};
@@ -1,12 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * memoryai-kiro-setup
4
- * Zero-dependency setup script that creates .kiro/settings/mcp.json
5
- * and .kiro/steering/memoryai.md in the current project directory.
4
+ * Zero-dependency setup script that creates, in the current project:
5
+ * - .kiro/settings/mcp.json (MCP server wiring)
6
+ * - .kiro/steering/memoryai.md (always-on instructions, soft fallback)
7
+ * - .kiro/hooks/memoryai-auto-recall.kiro.hook (promptSubmit → bootstrap/recall)
8
+ * - .kiro/hooks/memoryai-auto-capture.kiro.hook (agentStop → store/compact)
9
+ *
10
+ * The two hooks are what make memory TRULY automatic: they fire on IDE events
11
+ * (every prompt / end of every turn) instead of relying on the agent to
12
+ * remember the steering instructions. Result: the user installs once and never
13
+ * has to think about memory again — recall happens before answers, persistence
14
+ * happens after turns, compaction happens when context fills.
6
15
  */
7
16
  import { createInterface } from "node:readline";
8
17
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
9
- import { join } from "node:path";
18
+ import { join, dirname } from "node:path";
10
19
  const rl = createInterface({ input: process.stdin, output: process.stdout });
11
20
  function ask(question, fallback) {
12
21
  const suffix = fallback ? ` [${fallback}]` : "";
@@ -21,12 +30,42 @@ function writeIfMissing(filePath, content, label) {
21
30
  console.log(` skip ${label} (already exists)`);
22
31
  return false;
23
32
  }
24
- const dir = filePath.substring(0, filePath.lastIndexOf("/"));
33
+ const dir = dirname(filePath);
25
34
  mkdirSync(dir, { recursive: true });
26
35
  writeFileSync(filePath, content, "utf-8");
27
36
  console.log(` create ${label}`);
28
37
  return true;
29
38
  }
39
+ /**
40
+ * Auto-provision a fresh API key from the public self-service endpoint so the
41
+ * user does nothing — no curl, no dashboard. Returns the key, or null on
42
+ * failure (caller falls back to asking). Public + IP-rate-limited server-side.
43
+ */
44
+ async function provisionKey(endpoint, name) {
45
+ const base = endpoint.replace(/\/+$/, "");
46
+ try {
47
+ const resp = await fetch(`${base}/v1/admin/provision`, {
48
+ method: "POST",
49
+ headers: { "Content-Type": "application/json" },
50
+ body: JSON.stringify({ name: name || "kiro", tos_accepted: true }),
51
+ });
52
+ if (!resp.ok) {
53
+ const txt = await resp.text().catch(() => "");
54
+ console.error(` warn auto-provision failed (HTTP ${resp.status}). ${txt.slice(0, 200)}`);
55
+ return null;
56
+ }
57
+ const data = (await resp.json());
58
+ if (data?.api_key) {
59
+ console.log(` ok provisioned new API key (${String(data.api_key).slice(0, 10)}…, plan=${data.plan || "?"})`);
60
+ return data.api_key;
61
+ }
62
+ return null;
63
+ }
64
+ catch (e) {
65
+ console.error(` warn auto-provision request error: ${e instanceof Error ? e.message : String(e)}`);
66
+ return null;
67
+ }
68
+ }
30
69
  const MCP_CONFIG = (apiKey, endpoint) => JSON.stringify({
31
70
  mcpServers: {
32
71
  memoryai: {
@@ -36,76 +75,120 @@ const MCP_CONFIG = (apiKey, endpoint) => JSON.stringify({
36
75
  HM_API_KEY: apiKey,
37
76
  HM_ENDPOINT: endpoint,
38
77
  },
78
+ // Auto-approve the everyday memory tools so the hooks can run them
79
+ // without prompting the user — this is what makes memory truly
80
+ // hands-off. These are all low-risk (read + append-only store +
81
+ // context bookkeeping); no destructive operations are listed.
82
+ autoApprove: [
83
+ "memory_bootstrap",
84
+ "memory_recall",
85
+ "memory_store",
86
+ "memory_recover",
87
+ "context_guard_check",
88
+ "context_guard_compact",
89
+ "ide_turn_check",
90
+ "memory_pitfall_check",
91
+ ],
39
92
  },
40
93
  },
41
94
  }, null, 2) + "\n";
42
- const STEERING = `---
43
- inclusion: always
44
- ---
45
-
46
- # MemoryAI — Persistent Memory Instructions
47
-
48
- You have access to MemoryAI tools via MCP. Use them to maintain long-term memory across sessions.
49
-
50
- ## Session Start
51
-
52
- Call \`memory_bootstrap\` at the beginning of every session to load prior context.
53
- If bootstrap returns nothing, call \`memory_recover\` to check for recent session state.
54
-
55
- ## During Work
56
-
57
- - Before answering questions about past decisions, architecture, or preferences: call \`memory_recall\` with a relevant query.
58
- - After making a significant decision, completing a task, or learning something about the codebase: call \`memory_store\` with appropriate \`memory_type\`:
59
- - \`decision\` — architectural or technical decisions (DNA-protected, never decays)
60
- - \`preference\` user preferences and conventions (DNA-protected, never decays)
61
- - \`fact\` — codebase facts, API details, configs
62
- - \`error\` — lessons learned from mistakes
63
- - \`goal\` — current objectives and milestones
64
- - After learning from a mistake or unexpected result: call \`learn\` with action, result, and lesson fields.
65
-
66
- ## Entity Tracking
67
-
68
- When you create, modify, or reference important files, packages, or people:
69
- 1. Call \`entity_list\` to check if already tracked
70
- 2. If not tracked, call \`memory_store\` with \`memory_type=entity\`
71
-
72
- ## Memory Health
73
-
74
- If a session is running long, call \`memory_health\` to check working memory usage.
75
- If above 80%, call \`memory_compact\` proactively to consolidate context.
76
-
77
- ## Session End
78
-
79
- When wrapping up or when the agent is about to stop:
80
- 1. Call \`memory_compact\` to consolidate the session's context into durable memories
81
- 2. Call \`memory_store\` with a brief summary of what was accomplished
82
-
83
- ## Rules
84
-
85
- - Recall only when past context is actually needed — not on every message
86
- - Store important outcomes after completing tasks, not after every interaction
87
- - Present memories naturally — integrate recalled info into responses, don't show raw API output
88
- - Use \`zone: "critical"\` for decisions that must never be forgotten
89
- - Use \`retention: "forever"\` for permanent project knowledge
95
+ const STEERING = `---
96
+ inclusion: always
97
+ ---
98
+
99
+ # MemoryAI — Persistent Memory (mostly automatic)
100
+
101
+ You have MemoryAI tools via MCP. Two Agent Hooks automate the common path:
102
+ - **Auto-Recall** (on every prompt) loads memory before you answer.
103
+ - **Auto-Capture** (end of every turn) stores important memory and compacts when full.
104
+
105
+ So you normally do NOT need to manage memory by hand. This file is a fallback
106
+ for cases the hooks don't cover, plus the rules for HOW to use memory well.
107
+
108
+ ## What the hooks already handle
109
+ - Session-start \`memory_bootstrap\`, per-prompt \`memory_recall\`.
110
+ - Post-turn \`memory_store\` for decisions/preferences/facts/pitfalls/procedures.
111
+ - \`context_guard_check\` \`context_guard_compact\` when context fills.
112
+
113
+ Don't duplicate these on your own unless a hook clearly didn't run.
114
+
115
+ ## Memory types
116
+ - \`decision\` — architectural/technical decisions (DNA-protected, never decays)
117
+ - \`preference\` user preferences and conventions (DNA-protected)
118
+ - \`fact\` — codebase facts, API details, configs
119
+ - \`pitfall\` — a mistake + its lesson (DNA-protected)
120
+ - \`procedure\` — a reusable workflow (DNA-protected)
121
+ - \`error\` / \`goal\` lessons and current objectives
122
+
123
+ ## Rules
124
+ - Recall only when past context is actually needed — not on every trivial message.
125
+ - Store important outcomes, not every interaction. Dedup is automatic.
126
+ - Integrate recalled info naturally; never show raw tool output.
127
+ - Never store secrets, credentials, tokens, or full API keys.
128
+ - Use \`zone: "critical"\` for things that must never be forgotten.
129
+ - Use \`retention: "forever"\` for permanent project knowledge.
90
130
  `;
131
+ // ── Agent Hooks — event-level automation (the real "zero-action" layer) ──
132
+ // These fire on IDE events so memory works even if the agent ignores steering.
133
+ const HOOK_AUTO_RECALL = JSON.stringify({
134
+ enabled: true,
135
+ name: "MemoryAI Auto-Recall",
136
+ description: "Before answering each user message, automatically load relevant memory so the agent always has prior context — zero user action.",
137
+ version: "1",
138
+ when: { type: "promptSubmit" },
139
+ then: {
140
+ type: "askAgent",
141
+ prompt: "Before responding, ensure you have the relevant long-term memory (do this silently, integrate naturally, never show raw tool output):\n\n" +
142
+ "1. If this is the first turn of the session, call memory_bootstrap once to load preferences, decisions, and recent project context.\n" +
143
+ "2. If the user's message references past work, decisions, preferences, or anything that might be stored (\"what did we\", \"last time\", \"our approach\", \"why did we\", or a question about the project), call memory_recall with a focused query first, then answer using what you find.\n" +
144
+ "3. If the message is trivial small-talk, skip recall.\n\n" +
145
+ "Use recalled memory to inform the answer; do not announce that a memory system exists unless asked.",
146
+ },
147
+ }, null, 2) + "\n";
148
+ const HOOK_AUTO_CAPTURE = JSON.stringify({
149
+ enabled: true,
150
+ name: "MemoryAI Auto-Capture",
151
+ description: "Fully automatic: persist memorable events to MemoryAI after every turn, and persist session state silently when pressure thresholds hit. No user action ever required — the IDE host handles window eviction on its own and the auto-recall hook rehydrates context afterwards.",
152
+ version: "5",
153
+ when: { type: "agentStop" },
154
+ then: {
155
+ type: "askAgent",
156
+ prompt: "Run two background tasks SILENTLY. Do not tell the user about either task, do not change your normal reply, do not suggest /compact or 'open a new conversation' — those are not user actions in this design.\n\n" +
157
+ "1. PERSIST: If the turn produced a decision, preference, important project fact, lesson from a mistake (pitfall), or reusable procedure, call memory_store with the correct memory_type. Skip greetings and trivia. Dedup is automatic. Never store secrets.\n\n" +
158
+ "2. RELEASE CHECK: Count the assistant turns in this conversation, then call ide_turn_check with turn_count = (your count) and max_tokens = 200000. Read the response's action_prompt field and follow it VERBATIM. Every action_prompt in this design tells you to act SILENTLY — call context_guard_compact when asked, do nothing when asked. Never message the user from this hook.\n\n" +
159
+ "The design: MemoryAI persists to DB on threshold; the IDE host (Kiro auto-summarize, Claude Code /clear, Cursor /reset) evicts the window on its own schedule; the auto-recall hook on the next user message rehydrates context. From the user's view, nothing ever happens — the chat just keeps working.",
160
+ },
161
+ }, null, 2) + "\n";
91
162
  async function main() {
92
163
  const cwd = process.cwd();
93
164
  console.log(`\nMemoryAI Kiro Setup`);
94
165
  console.log(`Project: ${cwd}\n`);
95
- const apiKey = process.env.HM_API_KEY || (await ask("MemoryAI API key (hm_sk_...)"));
166
+ const endpoint = await ask("Endpoint", process.env.HM_ENDPOINT || "https://memoryai.dev");
167
+ let apiKey = process.env.HM_API_KEY || (await ask("MemoryAI API key (blank = auto-provision a free one)")).trim();
96
168
  if (!apiKey) {
97
- console.error("Error: API key is required. Set HM_API_KEY or enter it above.");
169
+ console.log(" ... no key given provisioning one for you");
170
+ const provisioned = await provisionKey(endpoint, "kiro");
171
+ if (provisioned)
172
+ apiKey = provisioned;
173
+ }
174
+ if (!apiKey) {
175
+ console.error("Error: could not obtain an API key (auto-provision failed). Set HM_API_KEY and re-run.");
98
176
  process.exit(1);
99
177
  }
100
- const endpoint = await ask("Endpoint", process.env.HM_ENDPOINT || "https://memoryai.dev");
101
178
  console.log("");
102
179
  writeIfMissing(join(cwd, ".kiro", "settings", "mcp.json"), MCP_CONFIG(apiKey, endpoint), ".kiro/settings/mcp.json");
103
180
  writeIfMissing(join(cwd, ".kiro", "steering", "memoryai.md"), STEERING, ".kiro/steering/memoryai.md");
104
- console.log(`
105
- Done. Next steps:
106
- 1. Restart Kiro
107
- 2. Ask: "What do you remember about this project?"
108
- 3. The agent should call memory_bootstrap automatically
181
+ writeIfMissing(join(cwd, ".kiro", "hooks", "memoryai-auto-recall.kiro.hook"), HOOK_AUTO_RECALL, ".kiro/hooks/memoryai-auto-recall.kiro.hook");
182
+ writeIfMissing(join(cwd, ".kiro", "hooks", "memoryai-auto-capture.kiro.hook"), HOOK_AUTO_CAPTURE, ".kiro/hooks/memoryai-auto-capture.kiro.hook");
183
+ console.log(`
184
+ Done. MemoryAI now runs automatically — you don't have to do anything.
185
+ - Auto-Recall hook loads relevant memory before each answer.
186
+ - Auto-Capture hook stores decisions/preferences and compacts when full.
187
+
188
+ Next steps:
189
+ 1. Restart Kiro (loads the MCP server + hooks)
190
+ 2. Just work normally. Memory persists across sessions on its own.
191
+ 3. Optional check: ask "What do you remember about this project?"
109
192
  `);
110
193
  rl.close();
111
194
  }
package/package.json CHANGED
@@ -1,45 +1,46 @@
1
- {
2
- "name": "memoryai-mcp",
3
- "version": "2.2.0",
4
- "description": "MCP server for MemoryAI v2.0 — One brain. ∞ agents. Forever. Adds Brain Export/Import (vendor-neutral bundles), Public Benchmark (smart recall vs full context), Trust Graph (per-agent reputation), Cognitive Twin (simulate user voice). Plus the v1.5 base: 11 biological behaviors, DNA-protected memories, Multi-Agent Mesh.",
5
- "homepage": "https://memoryai.dev",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/memoryai-dev/memoryai"
9
- },
10
- "type": "module",
11
- "main": "dist/index.js",
12
- "bin": {
13
- "memoryai-mcp": "dist/index.js",
14
- "memoryai-kiro-setup": "dist/kiro-setup.js"
15
- },
16
- "scripts": {
17
- "build": "tsc",
18
- "start": "node dist/index.js",
19
- "dev": "tsx src/index.ts"
20
- },
21
- "keywords": [
22
- "mcp",
23
- "memory",
24
- "ai",
25
- "llm",
26
- "context"
27
- ],
28
- "license": "MIT",
29
- "engines": {
30
- "node": ">=18.0.0"
31
- },
32
- "files": [
33
- "dist",
34
- "README.md",
35
- "LICENSE"
36
- ],
37
- "dependencies": {
38
- "@modelcontextprotocol/sdk": "^1.12.0"
39
- },
40
- "devDependencies": {
41
- "@types/node": "^22.19.15",
42
- "tsx": "^4.0.0",
43
- "typescript": "^5.5.0"
44
- }
45
- }
1
+ {
2
+ "name": "memoryai-mcp",
3
+ "version": "2.3.1",
4
+ "description": "MCP server for MemoryAI v2.3 — One brain. ∞ agents. Forever. Adds Brain Inheritance/Federation (P2.3), L2 Inject endpoint (DNA #2 retina), Protocol v1 spec lookup. Plus the v2.0 base: Brain Export/Import, Public Benchmark, Trust Graph, Cognitive Twin. Plus the v1.5 base: 11 biological behaviors, DNA-protected memories, Multi-Agent Mesh.",
5
+ "homepage": "https://memoryai.dev",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/memoryai-dev/memoryai"
9
+ },
10
+ "type": "module",
11
+ "main": "dist/index.js",
12
+ "bin": {
13
+ "memoryai-mcp": "dist/index.js",
14
+ "memoryai-kiro-setup": "dist/kiro-setup.js",
15
+ "memoryai-claude-setup": "dist/claude-setup.js"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "start": "node dist/index.js",
20
+ "dev": "tsx src/index.ts"
21
+ },
22
+ "keywords": [
23
+ "mcp",
24
+ "memory",
25
+ "ai",
26
+ "llm",
27
+ "context"
28
+ ],
29
+ "license": "MIT",
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "dependencies": {
39
+ "@modelcontextprotocol/sdk": "^1.12.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.19.15",
43
+ "tsx": "^4.0.0",
44
+ "typescript": "^5.5.0"
45
+ }
46
+ }