micro-models-agent 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +312 -312
  2. package/bin/mma.mjs +8 -8
  3. package/dist/main.js +8777 -864
  4. package/package.json +3 -2
  5. package/dist/cli/commands.js +0 -220
  6. package/dist/cli/completer.js +0 -168
  7. package/dist/cli/index.js +0 -2
  8. package/dist/cli/main.js +0 -113
  9. package/dist/cli/repl.js +0 -987
  10. package/dist/cli/security-commands.js +0 -166
  11. package/dist/cli/setup.js +0 -229
  12. package/dist/config/config.js +0 -186
  13. package/dist/config/defaults.js +0 -91
  14. package/dist/config/experts.js +0 -15
  15. package/dist/config/index.js +0 -3
  16. package/dist/config/security.js +0 -193
  17. package/dist/config/types.js +0 -1
  18. package/dist/core/agent-moe.js +0 -98
  19. package/dist/core/agent.js +0 -461
  20. package/dist/core/bootstrap.js +0 -321
  21. package/dist/core/index.js +0 -2
  22. package/dist/core/prompt-builder.js +0 -55
  23. package/dist/core/session-logger.js +0 -122
  24. package/dist/core/types.js +0 -1
  25. package/dist/i18n/en.json +0 -461
  26. package/dist/i18n/index.js +0 -43
  27. package/dist/i18n/ru.json +0 -461
  28. package/dist/index.js +0 -22
  29. package/dist/llm/image-utils.js +0 -144
  30. package/dist/llm/index.js +0 -4
  31. package/dist/llm/model-loader.js +0 -78
  32. package/dist/llm/openai-compat.js +0 -324
  33. package/dist/llm/orchestrator.js +0 -194
  34. package/dist/llm/provider.js +0 -10
  35. package/dist/llm/response.js +0 -39
  36. package/dist/llm/token-counter.js +0 -39
  37. package/dist/llm/types.js +0 -1
  38. package/dist/logger/app-logger.js +0 -76
  39. package/dist/logger/index.js +0 -1
  40. package/dist/migration/backup.js +0 -45
  41. package/dist/migration/detect.js +0 -50
  42. package/dist/migration/index.js +0 -2
  43. package/dist/modules/browser/actions.js +0 -46
  44. package/dist/modules/browser/cookie-store.js +0 -24
  45. package/dist/modules/browser/index.js +0 -5
  46. package/dist/modules/browser/module.js +0 -28
  47. package/dist/modules/browser/session.js +0 -287
  48. package/dist/modules/browser/snapshot.js +0 -114
  49. package/dist/modules/browser/types.js +0 -9
  50. package/dist/modules/context/history.js +0 -15
  51. package/dist/modules/context/index.js +0 -1
  52. package/dist/modules/context/manager.js +0 -240
  53. package/dist/modules/execution/auditor.js +0 -72
  54. package/dist/modules/execution/index.js +0 -6
  55. package/dist/modules/execution/module.js +0 -337
  56. package/dist/modules/execution/moe-executor.js +0 -209
  57. package/dist/modules/execution/plan-validator.js +0 -153
  58. package/dist/modules/execution/planner.js +0 -35
  59. package/dist/modules/execution/stuck-detector.js +0 -134
  60. package/dist/modules/execution/tracker.js +0 -53
  61. package/dist/modules/execution/types.js +0 -1
  62. package/dist/modules/execution/verifier.js +0 -149
  63. package/dist/modules/hallucination/confidence.js +0 -54
  64. package/dist/modules/hallucination/consistency.js +0 -60
  65. package/dist/modules/hallucination/detector.js +0 -41
  66. package/dist/modules/hallucination/factual.js +0 -170
  67. package/dist/modules/hallucination/index.js +0 -4
  68. package/dist/modules/index.js +0 -5
  69. package/dist/modules/indexer/cache.js +0 -38
  70. package/dist/modules/indexer/index.js +0 -3
  71. package/dist/modules/indexer/module.js +0 -192
  72. package/dist/modules/indexer/walker.js +0 -101
  73. package/dist/modules/mcp/client.js +0 -393
  74. package/dist/modules/mcp/index.js +0 -3
  75. package/dist/modules/mcp/module.js +0 -146
  76. package/dist/modules/mcp/registry.js +0 -15
  77. package/dist/modules/memory/index.js +0 -1
  78. package/dist/modules/memory/module.js +0 -48
  79. package/dist/modules/memory/search.js +0 -40
  80. package/dist/modules/memory/store.js +0 -65
  81. package/dist/modules/pipelines/engine.js +0 -60
  82. package/dist/modules/pipelines/index.js +0 -3
  83. package/dist/modules/pipelines/parser.js +0 -53
  84. package/dist/modules/pipelines/template.js +0 -14
  85. package/dist/modules/plugins/builtin/lint-on-write.js +0 -121
  86. package/dist/modules/plugins/builtin/notify.js +0 -8
  87. package/dist/modules/plugins/index.js +0 -1
  88. package/dist/modules/plugins/loader.js +0 -28
  89. package/dist/modules/plugins/manager.js +0 -161
  90. package/dist/modules/plugins/types.js +0 -1
  91. package/dist/modules/processes/detect.js +0 -34
  92. package/dist/modules/processes/index.js +0 -3
  93. package/dist/modules/processes/registry.js +0 -148
  94. package/dist/modules/processes/runner.js +0 -124
  95. package/dist/modules/registry.js +0 -45
  96. package/dist/modules/security/audit-log.js +0 -116
  97. package/dist/modules/security/audit-notifier.js +0 -292
  98. package/dist/modules/security/command-validator.js +0 -185
  99. package/dist/modules/security/content-scanner.js +0 -52
  100. package/dist/modules/security/data-sanitizer.js +0 -97
  101. package/dist/modules/security/encryption.js +0 -240
  102. package/dist/modules/security/index.js +0 -14
  103. package/dist/modules/security/network-validator.js +0 -79
  104. package/dist/modules/security/path-validator.js +0 -155
  105. package/dist/modules/security/rate-limiter.js +0 -119
  106. package/dist/modules/security/security-policies.js +0 -393
  107. package/dist/modules/security/session-encryption.js +0 -193
  108. package/dist/modules/security/session-isolation.js +0 -95
  109. package/dist/modules/session/index.js +0 -3
  110. package/dist/modules/session/manager.js +0 -167
  111. package/dist/modules/session/module.js +0 -24
  112. package/dist/modules/session/store.js +0 -174
  113. package/dist/modules/session/types.js +0 -1
  114. package/dist/modules/skills/index.js +0 -3
  115. package/dist/modules/skills/loader.js +0 -72
  116. package/dist/modules/skills/matcher.js +0 -27
  117. package/dist/modules/skills/module.js +0 -143
  118. package/dist/modules/types.js +0 -1
  119. package/dist/modules/updater/checker.js +0 -32
  120. package/dist/modules/updater/index.js +0 -1
  121. package/dist/modules/user-profile/compressor.js +0 -16
  122. package/dist/modules/user-profile/index.js +0 -1
  123. package/dist/modules/user-profile/profile.js +0 -68
  124. package/dist/tools/approve.js +0 -32
  125. package/dist/tools/attach-image.js +0 -89
  126. package/dist/tools/bash.js +0 -140
  127. package/dist/tools/browser.js +0 -97
  128. package/dist/tools/create-dir.js +0 -56
  129. package/dist/tools/delete-file.js +0 -63
  130. package/dist/tools/edit-file.js +0 -77
  131. package/dist/tools/executor.js +0 -95
  132. package/dist/tools/file-info.js +0 -45
  133. package/dist/tools/filter-tools.js +0 -10
  134. package/dist/tools/glob-tool.js +0 -26
  135. package/dist/tools/grep-tool.js +0 -64
  136. package/dist/tools/index.js +0 -52
  137. package/dist/tools/list-dir.js +0 -47
  138. package/dist/tools/load-skill.js +0 -48
  139. package/dist/tools/mcp-call.js +0 -68
  140. package/dist/tools/move-file.js +0 -84
  141. package/dist/tools/path-utils.js +0 -51
  142. package/dist/tools/pipeline-run.js +0 -144
  143. package/dist/tools/preview.js +0 -2
  144. package/dist/tools/process-kill.js +0 -29
  145. package/dist/tools/process-list.js +0 -38
  146. package/dist/tools/process-log.js +0 -41
  147. package/dist/tools/question.js +0 -142
  148. package/dist/tools/read-file.js +0 -73
  149. package/dist/tools/recall.js +0 -110
  150. package/dist/tools/registry.js +0 -36
  151. package/dist/tools/remember.js +0 -67
  152. package/dist/tools/scope-check.js +0 -30
  153. package/dist/tools/search-history.js +0 -64
  154. package/dist/tools/subagent.js +0 -142
  155. package/dist/tools/types.js +0 -1
  156. package/dist/tools/user-input.js +0 -123
  157. package/dist/tools/web-browse.js +0 -57
  158. package/dist/tools/web-fetch.js +0 -72
  159. package/dist/tools/web-search.js +0 -59
  160. package/dist/tools/write-file.js +0 -80
  161. package/dist/ui/box.js +0 -81
  162. package/dist/ui/colors.js +0 -4
  163. package/dist/ui/diff.js +0 -185
  164. package/dist/ui/index.js +0 -6
  165. package/dist/ui/md-formatter.js +0 -212
  166. package/dist/ui/output.js +0 -13
  167. package/dist/ui/renderer.js +0 -141
  168. package/dist/ui/spinner.js +0 -70
  169. package/dist/ui/table.js +0 -144
@@ -1,393 +0,0 @@
1
- import { spawn } from "child_process";
2
- export class MCPClient {
3
- serverName;
4
- config;
5
- process = null;
6
- _connected = false;
7
- abortController = null;
8
- pendingResolve = null;
9
- pendingReject = null;
10
- constructor(config) {
11
- this.config = config;
12
- this.serverName = config.name;
13
- }
14
- isConnected() {
15
- return this._connected;
16
- }
17
- async connect() {
18
- if (this._connected)
19
- return;
20
- if (this.config.transport === "http") {
21
- this._connected = true;
22
- return;
23
- }
24
- if (this.config.transport === "sse" || this.config.url) {
25
- return this.connectSSE();
26
- }
27
- return this.connectStdio();
28
- }
29
- async connectSSE() {
30
- const url = this.config.url;
31
- if (!url)
32
- throw new Error("SSE transport requires a url");
33
- this.abortController = new AbortController();
34
- const response = await fetch(url, {
35
- method: "GET",
36
- headers: {
37
- Accept: "text/event-stream",
38
- ...this.config.headers,
39
- },
40
- signal: this.abortController.signal,
41
- });
42
- if (!response.ok) {
43
- throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
44
- }
45
- this._connected = true;
46
- const reader = response.body.getReader();
47
- const decoder = new TextDecoder();
48
- let buffer = "";
49
- this.readSSE(reader, decoder, buffer);
50
- }
51
- async readSSE(reader, decoder, buffer) {
52
- try {
53
- while (this._connected) {
54
- const { done, value } = await reader.read();
55
- if (done)
56
- break;
57
- buffer += decoder.decode(value, { stream: true });
58
- const lines = buffer.split("\n");
59
- buffer = lines.pop() || "";
60
- let eventType = "";
61
- let data = "";
62
- for (const line of lines) {
63
- if (line.startsWith("event: ")) {
64
- eventType = line.slice(7).trim();
65
- }
66
- else if (line.startsWith("data: ")) {
67
- data = line.slice(6);
68
- }
69
- else if (line === "") {
70
- if (eventType === "message" && data) {
71
- this.handleSSEMessage(data);
72
- }
73
- eventType = "";
74
- data = "";
75
- }
76
- }
77
- }
78
- }
79
- catch (err) {
80
- if (err.name !== "AbortError") {
81
- this.handleSSEError(err);
82
- }
83
- }
84
- this._connected = false;
85
- }
86
- handleSSEMessage(data) {
87
- try {
88
- const msg = JSON.parse(data);
89
- if (this.pendingResolve && msg.id) {
90
- if (msg.error) {
91
- this.pendingReject?.(new Error(msg.error.message));
92
- }
93
- else {
94
- this.pendingResolve(msg.result);
95
- }
96
- this.pendingResolve = null;
97
- this.pendingReject = null;
98
- }
99
- }
100
- catch { }
101
- }
102
- handleSSEError(err) {
103
- if (this.pendingReject) {
104
- this.pendingReject(err);
105
- this.pendingResolve = null;
106
- this.pendingReject = null;
107
- }
108
- }
109
- connectStdio() {
110
- return new Promise((resolve, reject) => {
111
- const child = spawn(this.config.command, this.config.args || [], {
112
- env: { ...process.env, ...this.config.env },
113
- stdio: ["pipe", "pipe", "pipe"],
114
- });
115
- child.on("error", (err) => {
116
- this._connected = false;
117
- reject(err);
118
- });
119
- child.on("exit", (code) => {
120
- this._connected = false;
121
- if (code !== 0) {
122
- reject(new Error(`MCP server exited with code ${code}`));
123
- }
124
- });
125
- child.on("spawn", () => {
126
- this._connected = true;
127
- this.process = child;
128
- resolve();
129
- });
130
- });
131
- }
132
- async listTools() {
133
- if (!this._connected) {
134
- await this.connect();
135
- }
136
- if (this.config.transport === "http") {
137
- return this.listToolsHTTP();
138
- }
139
- if (this.config.transport === "sse" || this.config.url) {
140
- return this.listToolsSSE();
141
- }
142
- return this.listToolsStdio();
143
- }
144
- async listToolsHTTP() {
145
- const request = {
146
- jsonrpc: "2.0",
147
- id: Date.now(),
148
- method: "tools/list",
149
- };
150
- const response = await fetch(this.config.url, {
151
- method: "POST",
152
- headers: {
153
- "Content-Type": "application/json",
154
- ...this.config.headers,
155
- },
156
- body: JSON.stringify(request),
157
- });
158
- if (!response.ok) {
159
- const text = await response.text().catch(() => "");
160
- throw new Error(`MCP listTools failed: ${response.status} ${text}`);
161
- }
162
- const result = await response.json();
163
- if (result.error) {
164
- throw new Error(result.error.message);
165
- }
166
- return result.result?.tools || [];
167
- }
168
- async listToolsSSE() {
169
- const request = {
170
- jsonrpc: "2.0",
171
- id: Date.now(),
172
- method: "tools/list",
173
- };
174
- const response = await fetch(this.config.url, {
175
- method: "POST",
176
- headers: {
177
- "Content-Type": "application/json",
178
- ...this.config.headers,
179
- },
180
- body: JSON.stringify(request),
181
- signal: this.abortController?.signal,
182
- });
183
- if (!response.ok) {
184
- const text = await response.text().catch(() => "");
185
- throw new Error(`MCP listTools failed: ${response.status} ${text}`);
186
- }
187
- const result = await response.json();
188
- if (result.error) {
189
- throw new Error(result.error.message);
190
- }
191
- return result.result?.tools || [];
192
- }
193
- async listToolsStdio() {
194
- if (!this.process) {
195
- throw new Error("Not connected to MCP server");
196
- }
197
- return new Promise((resolve, reject) => {
198
- const request = {
199
- jsonrpc: "2.0",
200
- id: Date.now(),
201
- method: "tools/list",
202
- };
203
- const requestStr = JSON.stringify(request) + "\n";
204
- this.process.stdin.write(requestStr);
205
- let responseData = "";
206
- const onData = (data) => {
207
- responseData += data.toString();
208
- if (responseData.includes("\n")) {
209
- this.process.stdout.off("data", onData);
210
- try {
211
- const lines = responseData.split("\n").filter((l) => l.trim());
212
- for (const line of lines) {
213
- const response = JSON.parse(line);
214
- if (response.id === request.id) {
215
- if (response.error) {
216
- reject(new Error(response.error.message));
217
- }
218
- else {
219
- resolve(response.result?.tools || []);
220
- }
221
- return;
222
- }
223
- }
224
- reject(new Error("No matching response found"));
225
- }
226
- catch (e) {
227
- reject(new Error(`Parse error: ${e.message}`));
228
- }
229
- }
230
- };
231
- this.process.stdout.on("data", onData);
232
- setTimeout(() => {
233
- this.process.stdout.off("data", onData);
234
- reject(new Error("MCP listTools timeout"));
235
- }, 30000);
236
- });
237
- }
238
- async disconnect() {
239
- if (this.config.transport === "http") {
240
- this._connected = false;
241
- return;
242
- }
243
- if (this.config.transport === "sse" || this.config.url) {
244
- this.abortController?.abort();
245
- this.abortController = null;
246
- }
247
- else if (this.process) {
248
- this.process.kill();
249
- this.process = null;
250
- }
251
- this._connected = false;
252
- }
253
- async callTool(toolName, args) {
254
- if (!this._connected) {
255
- throw new Error("Not connected to MCP server");
256
- }
257
- if (this.config.transport === "http") {
258
- return this.callToolHTTP(toolName, args);
259
- }
260
- if (this.config.transport === "sse" || this.config.url) {
261
- return this.callToolSSE(toolName, args);
262
- }
263
- return this.callToolStdio(toolName, args);
264
- }
265
- async callToolHTTP(toolName, args) {
266
- const request = {
267
- jsonrpc: "2.0",
268
- id: Date.now(),
269
- method: "tools/call",
270
- params: {
271
- name: toolName,
272
- arguments: args,
273
- },
274
- };
275
- const response = await fetch(this.config.url, {
276
- method: "POST",
277
- headers: {
278
- "Content-Type": "application/json",
279
- ...this.config.headers,
280
- },
281
- body: JSON.stringify(request),
282
- });
283
- if (!response.ok) {
284
- const text = await response.text().catch(() => "");
285
- throw new Error(`MCP call failed: ${response.status} ${text}`);
286
- }
287
- const result = await response.json();
288
- if (result.error) {
289
- throw new Error(result.error.message);
290
- }
291
- return result.result || result;
292
- }
293
- async callToolSSE(toolName, args) {
294
- const request = {
295
- jsonrpc: "2.0",
296
- id: Date.now(),
297
- method: "tools/call",
298
- params: {
299
- name: toolName,
300
- arguments: args,
301
- },
302
- };
303
- return new Promise((resolve, reject) => {
304
- this.pendingResolve = resolve;
305
- this.pendingReject = reject;
306
- const timeout = this.config.timeout || 30000;
307
- const timer = setTimeout(() => {
308
- this.pendingResolve = null;
309
- this.pendingReject = null;
310
- reject(new Error("MCP call timeout"));
311
- }, timeout);
312
- fetch(this.config.url, {
313
- method: "POST",
314
- headers: {
315
- "Content-Type": "application/json",
316
- ...this.config.headers,
317
- },
318
- body: JSON.stringify(request),
319
- signal: this.abortController?.signal,
320
- })
321
- .then(async (response) => {
322
- clearTimeout(timer);
323
- if (!response.ok) {
324
- const text = await response.text().catch(() => "");
325
- reject(new Error(`MCP POST failed: ${response.status} ${text}`));
326
- return;
327
- }
328
- const result = await response.json();
329
- if (result.error) {
330
- reject(new Error(result.error.message));
331
- }
332
- else {
333
- resolve(result.result || result);
334
- }
335
- })
336
- .catch((err) => {
337
- clearTimeout(timer);
338
- if (err.name !== "AbortError") {
339
- reject(err);
340
- }
341
- });
342
- });
343
- }
344
- callToolStdio(toolName, args) {
345
- if (!this.process) {
346
- throw new Error("Not connected to MCP server");
347
- }
348
- return new Promise((resolve, reject) => {
349
- const request = {
350
- jsonrpc: "2.0",
351
- id: Date.now(),
352
- method: "tools/call",
353
- params: {
354
- name: toolName,
355
- arguments: args,
356
- },
357
- };
358
- const requestStr = JSON.stringify(request) + "\n";
359
- this.process.stdin.write(requestStr);
360
- let responseData = "";
361
- const onData = (data) => {
362
- responseData += data.toString();
363
- if (responseData.includes("\n")) {
364
- this.process.stdout.off("data", onData);
365
- try {
366
- const lines = responseData.split("\n").filter((l) => l.trim());
367
- for (const line of lines) {
368
- const response = JSON.parse(line);
369
- if (response.id === request.id) {
370
- if (response.error) {
371
- reject(new Error(response.error.message));
372
- }
373
- else {
374
- resolve(response.result);
375
- }
376
- return;
377
- }
378
- }
379
- reject(new Error("No matching response found"));
380
- }
381
- catch (e) {
382
- reject(new Error(`Parse error: ${e.message}`));
383
- }
384
- }
385
- };
386
- this.process.stdout.on("data", onData);
387
- setTimeout(() => {
388
- this.process.stdout.off("data", onData);
389
- reject(new Error("MCP call timeout"));
390
- }, 30000);
391
- });
392
- }
393
- }
@@ -1,3 +0,0 @@
1
- export { MCPClient } from "./client";
2
- export { MCPRegistry } from "./registry";
3
- export { MCPModule } from "./module";
@@ -1,146 +0,0 @@
1
- import { MCPClient } from "./client";
2
- import { MCPRegistry } from "./registry";
3
- function sanitizeToolName(server, tool) {
4
- const safeServer = server.replace(/[^a-zA-Z0-9_-]/g, "_");
5
- const safeTool = tool.replace(/[^a-zA-Z0-9_-]/g, "_");
6
- return `mcp__${safeServer}__${safeTool}`;
7
- }
8
- function convertInputSchema(schema) {
9
- if (schema && typeof schema === "object" && "properties" in schema) {
10
- const required = Array.isArray(schema.required)
11
- ? schema.required
12
- : [];
13
- return {
14
- type: "object",
15
- properties: schema.properties,
16
- required: required.length > 0 ? required : undefined,
17
- };
18
- }
19
- return { type: "object", properties: {} };
20
- }
21
- export class MCPModule {
22
- config;
23
- name = "mcp";
24
- connections = new Map();
25
- discovered = [];
26
- initialized = false;
27
- initError = null;
28
- constructor(config) {
29
- this.config = config;
30
- }
31
- async initialize() {
32
- if (this.initialized)
33
- return;
34
- this.initialized = true;
35
- const servers = this.config.mcpServers || {};
36
- const serverEntries = Object.entries(servers).filter(([, cfg]) => cfg.enabled !== false);
37
- if (serverEntries.length === 0)
38
- return;
39
- const registry = new MCPRegistry();
40
- for (const [key, cfg] of serverEntries) {
41
- const serverConfig = {
42
- name: cfg.name || key,
43
- command: cfg.command,
44
- args: cfg.args,
45
- env: cfg.env,
46
- transport: cfg.transport,
47
- url: cfg.url,
48
- headers: cfg.headers,
49
- timeout: cfg.timeout,
50
- };
51
- registry.register(serverConfig);
52
- }
53
- for (const serverName of registry.list()) {
54
- const serverConfig = registry.get(serverName);
55
- const client = new MCPClient(serverConfig);
56
- try {
57
- await client.connect();
58
- const tools = await client.listTools();
59
- this.connections.set(serverName, client);
60
- for (const tool of tools) {
61
- this.discovered.push({
62
- serverName,
63
- toolName: tool.name,
64
- description: tool.description || `Tool on MCP server "${serverName}"`,
65
- inputSchema: tool.inputSchema || {},
66
- });
67
- }
68
- }
69
- catch (e) {
70
- this.initError = `MCP server "${serverName}" init failed: ${e.message}`;
71
- await client.disconnect().catch(() => { });
72
- }
73
- }
74
- }
75
- getSystemPromptBlock() {
76
- if (this.discovered.length === 0)
77
- return null;
78
- const lines = ["---", "MCP servers available:"];
79
- const byServer = new Map();
80
- for (const d of this.discovered) {
81
- const list = byServer.get(d.serverName) || [];
82
- list.push(d);
83
- byServer.set(d.serverName, list);
84
- }
85
- for (const [server, tools] of byServer) {
86
- lines.push(` [${server}]`);
87
- for (const t of tools) {
88
- const toolRef = sanitizeToolName(server, t.toolName);
89
- lines.push(` - ${toolRef}: ${t.description}`);
90
- }
91
- }
92
- lines.push("---");
93
- return {
94
- content: lines.join("\n"),
95
- priority: "high",
96
- essential: false,
97
- estimatedTokens: this.discovered.length * 20 + 20,
98
- };
99
- }
100
- getToolDefinitions() {
101
- return this.discovered.map((d) => ({
102
- name: sanitizeToolName(d.serverName, d.toolName),
103
- description: `${d.description} [MCP server: ${d.serverName}]`,
104
- parameters: convertInputSchema(d.inputSchema),
105
- tags: ["code", "research"],
106
- handler: async (_ctx, args) => {
107
- const client = this.connections.get(d.serverName);
108
- if (!client) {
109
- return {
110
- success: false,
111
- output: `MCP server "${d.serverName}" not connected`,
112
- };
113
- }
114
- try {
115
- if (!client.isConnected()) {
116
- await client.connect();
117
- }
118
- const result = await client.callTool(d.toolName, args);
119
- return {
120
- success: true,
121
- output: typeof result === "string"
122
- ? result
123
- : JSON.stringify(result, null, 2),
124
- };
125
- }
126
- catch (e) {
127
- return { success: false, output: `MCP call failed: ${e.message}` };
128
- }
129
- },
130
- }));
131
- }
132
- getPlugin() {
133
- return {
134
- name: "mcp_module",
135
- priority: 0,
136
- onSessionEnd: async () => {
137
- for (const client of this.connections.values()) {
138
- try {
139
- await client.disconnect();
140
- }
141
- catch { }
142
- }
143
- },
144
- };
145
- }
146
- }
@@ -1,15 +0,0 @@
1
- export class MCPRegistry {
2
- servers = new Map();
3
- register(config) {
4
- this.servers.set(config.name, config);
5
- }
6
- get(name) {
7
- return this.servers.get(name);
8
- }
9
- list() {
10
- return Array.from(this.servers.keys()).sort();
11
- }
12
- remove(name) {
13
- this.servers.delete(name);
14
- }
15
- }
@@ -1 +0,0 @@
1
- export { MemoryStore } from './store';
@@ -1,48 +0,0 @@
1
- import { homedir } from 'os';
2
- import { join } from 'path';
3
- import { MemoryStore } from './store';
4
- import { rememberTool } from '../../tools/remember';
5
- import { recallTool } from '../../tools/recall';
6
- export class MemoryModule {
7
- name = 'memory';
8
- store;
9
- constructor(memoryDir) {
10
- const dir = memoryDir || join(homedir(), '.mma', 'memory');
11
- this.store = new MemoryStore(dir);
12
- }
13
- getSystemPromptBlock() {
14
- const prefs = this.store.getPreferences();
15
- if (Object.keys(prefs).length === 0)
16
- return null;
17
- const prefStr = Object.entries(prefs)
18
- .map(([k, v]) => `${k}=${v}`)
19
- .join(', ');
20
- return {
21
- content: `User preferences: ${prefStr}`,
22
- priority: 'normal',
23
- essential: false,
24
- estimatedTokens: Math.ceil(prefStr.length / 4) + 10,
25
- };
26
- }
27
- getToolDefinitions() {
28
- return [rememberTool, recallTool];
29
- }
30
- getPlugin() {
31
- return {
32
- name: 'memory',
33
- isBuiltin: true,
34
- onBuildPrompt: () => {
35
- const prefs = this.store.getPreferences();
36
- if (Object.keys(prefs).length === 0)
37
- return null;
38
- const prefStr = Object.entries(prefs)
39
- .map(([k, v]) => `${k}=${v}`)
40
- .join(', ');
41
- return `User preferences: ${prefStr}`;
42
- },
43
- };
44
- }
45
- getStore() {
46
- return this.store;
47
- }
48
- }
@@ -1,40 +0,0 @@
1
- import { readFileSync, existsSync } from 'fs';
2
- import { join } from 'path';
3
- const MEMORY_FILES = ['conventions', 'decisions', 'errors', 'facts'];
4
- export class MemorySearch {
5
- memoryDir;
6
- constructor(memoryDir) {
7
- this.memoryDir = memoryDir;
8
- }
9
- query(query) {
10
- const results = [];
11
- const lowerQuery = query.toLowerCase();
12
- for (const name of MEMORY_FILES) {
13
- const path = join(this.memoryDir, `${name}.md`);
14
- if (!existsSync(path))
15
- continue;
16
- const content = readFileSync(path, 'utf-8');
17
- const lines = content.split('\n');
18
- for (const line of lines) {
19
- if (line.toLowerCase().includes(lowerQuery)) {
20
- results.push({ file: name, match: line.trim() });
21
- }
22
- }
23
- }
24
- // Search preferences.json
25
- const prefsPath = join(this.memoryDir, 'preferences.json');
26
- if (existsSync(prefsPath)) {
27
- try {
28
- const prefs = JSON.parse(readFileSync(prefsPath, 'utf-8'));
29
- for (const [key, value] of Object.entries(prefs)) {
30
- const searchStr = `${key}=${value}`;
31
- if (searchStr.toLowerCase().includes(lowerQuery)) {
32
- results.push({ file: 'preferences', match: `${key} = ${value}` });
33
- }
34
- }
35
- }
36
- catch { /* skip */ }
37
- }
38
- return results;
39
- }
40
- }