micro-models-agent 0.44.0 → 0.45.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 (188) hide show
  1. package/README.md +312 -312
  2. package/bin/mma.mjs +41 -41
  3. package/dist/main.js +241 -56
  4. package/dist/skills/builtin/git.md +36 -36
  5. package/dist/skills/builtin/typescript.md +35 -35
  6. package/package.json +1 -1
  7. package/dist/cli/commands.js +0 -333
  8. package/dist/cli/completer.js +0 -168
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -140
  11. package/dist/cli/repl-commands.js +0 -633
  12. package/dist/cli/repl.js +0 -486
  13. package/dist/cli/security-commands.js +0 -166
  14. package/dist/cli/setup.js +0 -249
  15. package/dist/config/config.js +0 -202
  16. package/dist/config/defaults.js +0 -100
  17. package/dist/config/experts.js +0 -15
  18. package/dist/config/index.js +0 -3
  19. package/dist/config/security.js +0 -200
  20. package/dist/config/types.js +0 -1
  21. package/dist/core/agent-moe.js +0 -110
  22. package/dist/core/agent.js +0 -695
  23. package/dist/core/bootstrap.js +0 -337
  24. package/dist/core/index.js +0 -2
  25. package/dist/core/prompt-builder.js +0 -55
  26. package/dist/core/session-logger.js +0 -155
  27. package/dist/core/types.js +0 -1
  28. package/dist/core/workspace.js +0 -76
  29. package/dist/i18n/en.json +0 -525
  30. package/dist/i18n/index.js +0 -46
  31. package/dist/i18n/ru.json +0 -525
  32. package/dist/index.js +0 -22
  33. package/dist/llm/image-utils.js +0 -144
  34. package/dist/llm/index.js +0 -4
  35. package/dist/llm/model-loader.js +0 -78
  36. package/dist/llm/openai-compat.js +0 -353
  37. package/dist/llm/orchestrator.js +0 -194
  38. package/dist/llm/provider.js +0 -10
  39. package/dist/llm/response.js +0 -39
  40. package/dist/llm/token-counter.js +0 -39
  41. package/dist/llm/types.js +0 -1
  42. package/dist/logger/app-logger.js +0 -143
  43. package/dist/logger/file-log.js +0 -151
  44. package/dist/logger/index.js +0 -1
  45. package/dist/migration/backup.js +0 -45
  46. package/dist/migration/detect.js +0 -50
  47. package/dist/migration/index.js +0 -2
  48. package/dist/modules/browser/actions.js +0 -46
  49. package/dist/modules/browser/cookie-store.js +0 -24
  50. package/dist/modules/browser/index.js +0 -5
  51. package/dist/modules/browser/module.js +0 -28
  52. package/dist/modules/browser/session.js +0 -335
  53. package/dist/modules/browser/snapshot.js +0 -114
  54. package/dist/modules/browser/types.js +0 -9
  55. package/dist/modules/certification/cli.js +0 -176
  56. package/dist/modules/certification/fact-checker.js +0 -84
  57. package/dist/modules/certification/loader.js +0 -111
  58. package/dist/modules/certification/manifest.js +0 -50
  59. package/dist/modules/certification/runner.js +0 -162
  60. package/dist/modules/certification/scenarios.js +0 -124
  61. package/dist/modules/certification/types.js +0 -1
  62. package/dist/modules/context/index.js +0 -1
  63. package/dist/modules/context/manager.js +0 -349
  64. package/dist/modules/execution/auditor.js +0 -66
  65. package/dist/modules/execution/index.js +0 -8
  66. package/dist/modules/execution/module.js +0 -779
  67. package/dist/modules/execution/moe-executor.js +0 -266
  68. package/dist/modules/execution/plan-coverage.js +0 -68
  69. package/dist/modules/execution/plan-persister.js +0 -46
  70. package/dist/modules/execution/plan-store.js +0 -159
  71. package/dist/modules/execution/plan-validator.js +0 -153
  72. package/dist/modules/execution/planner.js +0 -85
  73. package/dist/modules/execution/stuck-detector.js +0 -347
  74. package/dist/modules/execution/tracker.js +0 -67
  75. package/dist/modules/execution/types.js +0 -1
  76. package/dist/modules/execution/verifier.js +0 -178
  77. package/dist/modules/hallucination/confidence.js +0 -59
  78. package/dist/modules/hallucination/consistency.js +0 -26
  79. package/dist/modules/hallucination/detector.js +0 -46
  80. package/dist/modules/hallucination/factual.js +0 -190
  81. package/dist/modules/hallucination/index.js +0 -5
  82. package/dist/modules/hallucination/js-identifiers.js +0 -72
  83. package/dist/modules/hallucination/llm-judge.js +0 -103
  84. package/dist/modules/index.js +0 -5
  85. package/dist/modules/indexer/cache.js +0 -38
  86. package/dist/modules/indexer/index.js +0 -3
  87. package/dist/modules/indexer/module.js +0 -192
  88. package/dist/modules/indexer/walker.js +0 -101
  89. package/dist/modules/lsp/client.js +0 -235
  90. package/dist/modules/lsp/config.js +0 -81
  91. package/dist/modules/lsp/index.js +0 -3
  92. package/dist/modules/lsp/module.js +0 -68
  93. package/dist/modules/lsp/types.js +0 -1
  94. package/dist/modules/mcp/client.js +0 -399
  95. package/dist/modules/mcp/index.js +0 -3
  96. package/dist/modules/mcp/module.js +0 -146
  97. package/dist/modules/mcp/registry.js +0 -15
  98. package/dist/modules/memory/index.js +0 -1
  99. package/dist/modules/memory/module.js +0 -48
  100. package/dist/modules/memory/search.js +0 -40
  101. package/dist/modules/memory/store.js +0 -69
  102. package/dist/modules/pipelines/engine.js +0 -60
  103. package/dist/modules/pipelines/index.js +0 -3
  104. package/dist/modules/pipelines/parser.js +0 -53
  105. package/dist/modules/pipelines/template.js +0 -14
  106. package/dist/modules/plugins/builtin/lint-on-write.js +0 -226
  107. package/dist/modules/plugins/builtin/notify.js +0 -8
  108. package/dist/modules/plugins/index.js +0 -1
  109. package/dist/modules/plugins/loader.js +0 -28
  110. package/dist/modules/plugins/manager.js +0 -161
  111. package/dist/modules/plugins/types.js +0 -1
  112. package/dist/modules/processes/index.js +0 -2
  113. package/dist/modules/processes/registry.js +0 -238
  114. package/dist/modules/processes/runner.js +0 -23
  115. package/dist/modules/registry.js +0 -45
  116. package/dist/modules/security/audit-log.js +0 -136
  117. package/dist/modules/security/audit-notifier.js +0 -292
  118. package/dist/modules/security/command-validator.js +0 -211
  119. package/dist/modules/security/content-scanner.js +0 -53
  120. package/dist/modules/security/data-sanitizer.js +0 -97
  121. package/dist/modules/security/encryption.js +0 -240
  122. package/dist/modules/security/index.js +0 -14
  123. package/dist/modules/security/network-validator.js +0 -79
  124. package/dist/modules/security/path-validator.js +0 -209
  125. package/dist/modules/security/rate-limiter.js +0 -119
  126. package/dist/modules/security/security-policies.js +0 -547
  127. package/dist/modules/security/session-encryption.js +0 -210
  128. package/dist/modules/security/session-isolation.js +0 -95
  129. package/dist/modules/session/index.js +0 -3
  130. package/dist/modules/session/manager.js +0 -172
  131. package/dist/modules/session/module.js +0 -24
  132. package/dist/modules/session/store.js +0 -228
  133. package/dist/modules/session/types.js +0 -1
  134. package/dist/modules/skills/index.js +0 -2
  135. package/dist/modules/skills/loader.js +0 -72
  136. package/dist/modules/skills/module.js +0 -130
  137. package/dist/modules/types.js +0 -1
  138. package/dist/modules/updater/checker.js +0 -32
  139. package/dist/modules/updater/index.js +0 -1
  140. package/dist/modules/user-profile/compressor.js +0 -16
  141. package/dist/modules/user-profile/index.js +0 -1
  142. package/dist/modules/user-profile/profile.js +0 -68
  143. package/dist/tools/approve.js +0 -32
  144. package/dist/tools/attach-image.js +0 -89
  145. package/dist/tools/bash.js +0 -337
  146. package/dist/tools/browser.js +0 -97
  147. package/dist/tools/create-dir.js +0 -55
  148. package/dist/tools/delete-file.js +0 -62
  149. package/dist/tools/edit-file.js +0 -79
  150. package/dist/tools/executor.js +0 -145
  151. package/dist/tools/file-info.js +0 -45
  152. package/dist/tools/filter-tools.js +0 -10
  153. package/dist/tools/glob-tool.js +0 -26
  154. package/dist/tools/grep-tool.js +0 -86
  155. package/dist/tools/index.js +0 -67
  156. package/dist/tools/list-dir.js +0 -47
  157. package/dist/tools/load-skill.js +0 -44
  158. package/dist/tools/mcp-call.js +0 -68
  159. package/dist/tools/move-file.js +0 -85
  160. package/dist/tools/path-utils.js +0 -51
  161. package/dist/tools/pipeline-run.js +0 -144
  162. package/dist/tools/preview.js +0 -2
  163. package/dist/tools/process-kill.js +0 -29
  164. package/dist/tools/process-list.js +0 -38
  165. package/dist/tools/process-log.js +0 -41
  166. package/dist/tools/question.js +0 -142
  167. package/dist/tools/read-file.js +0 -83
  168. package/dist/tools/recall.js +0 -110
  169. package/dist/tools/registry.js +0 -36
  170. package/dist/tools/remember.js +0 -67
  171. package/dist/tools/scope-check.js +0 -30
  172. package/dist/tools/search-history.js +0 -84
  173. package/dist/tools/subagent.js +0 -151
  174. package/dist/tools/types.js +0 -1
  175. package/dist/tools/user-input.js +0 -123
  176. package/dist/tools/web-browse.js +0 -86
  177. package/dist/tools/web-fetch.js +0 -98
  178. package/dist/tools/web-search.js +0 -78
  179. package/dist/tools/write-file.js +0 -83
  180. package/dist/ui/box.js +0 -81
  181. package/dist/ui/colors.js +0 -4
  182. package/dist/ui/diff.js +0 -178
  183. package/dist/ui/index.js +0 -6
  184. package/dist/ui/md-formatter.js +0 -212
  185. package/dist/ui/output.js +0 -13
  186. package/dist/ui/renderer.js +0 -204
  187. package/dist/ui/spinner.js +0 -70
  188. package/dist/ui/table.js +0 -144
@@ -1,399 +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
- let _resolved = false;
116
- child.on("error", (err) => {
117
- this._connected = false;
118
- if (!_resolved) {
119
- _resolved = true;
120
- reject(err);
121
- }
122
- });
123
- child.on("exit", (code) => {
124
- this._connected = false;
125
- if (code !== 0 && !_resolved) {
126
- _resolved = true;
127
- reject(new Error(`MCP server exited with code ${code}`));
128
- }
129
- });
130
- child.on("spawn", () => {
131
- this._connected = true;
132
- this.process = child;
133
- _resolved = true;
134
- resolve();
135
- });
136
- });
137
- }
138
- async listTools() {
139
- if (!this._connected) {
140
- await this.connect();
141
- }
142
- if (this.config.transport === "http") {
143
- return this.listToolsHTTP();
144
- }
145
- if (this.config.transport === "sse" || this.config.url) {
146
- return this.listToolsSSE();
147
- }
148
- return this.listToolsStdio();
149
- }
150
- async listToolsHTTP() {
151
- const request = {
152
- jsonrpc: "2.0",
153
- id: Date.now(),
154
- method: "tools/list",
155
- };
156
- const response = await fetch(this.config.url, {
157
- method: "POST",
158
- headers: {
159
- "Content-Type": "application/json",
160
- ...this.config.headers,
161
- },
162
- body: JSON.stringify(request),
163
- });
164
- if (!response.ok) {
165
- const text = await response.text().catch(() => "");
166
- throw new Error(`MCP listTools failed: ${response.status} ${text}`);
167
- }
168
- const result = await response.json();
169
- if (result.error) {
170
- throw new Error(result.error.message);
171
- }
172
- return result.result?.tools || [];
173
- }
174
- async listToolsSSE() {
175
- const request = {
176
- jsonrpc: "2.0",
177
- id: Date.now(),
178
- method: "tools/list",
179
- };
180
- const response = await fetch(this.config.url, {
181
- method: "POST",
182
- headers: {
183
- "Content-Type": "application/json",
184
- ...this.config.headers,
185
- },
186
- body: JSON.stringify(request),
187
- signal: this.abortController?.signal,
188
- });
189
- if (!response.ok) {
190
- const text = await response.text().catch(() => "");
191
- throw new Error(`MCP listTools failed: ${response.status} ${text}`);
192
- }
193
- const result = await response.json();
194
- if (result.error) {
195
- throw new Error(result.error.message);
196
- }
197
- return result.result?.tools || [];
198
- }
199
- async listToolsStdio() {
200
- if (!this.process) {
201
- throw new Error("Not connected to MCP server");
202
- }
203
- return new Promise((resolve, reject) => {
204
- const request = {
205
- jsonrpc: "2.0",
206
- id: Date.now(),
207
- method: "tools/list",
208
- };
209
- const requestStr = JSON.stringify(request) + "\n";
210
- this.process.stdin.write(requestStr);
211
- let responseData = "";
212
- const onData = (data) => {
213
- responseData += data.toString();
214
- if (responseData.includes("\n")) {
215
- this.process.stdout.off("data", onData);
216
- try {
217
- const lines = responseData.split("\n").filter((l) => l.trim());
218
- for (const line of lines) {
219
- const response = JSON.parse(line);
220
- if (response.id === request.id) {
221
- if (response.error) {
222
- reject(new Error(response.error.message));
223
- }
224
- else {
225
- resolve(response.result?.tools || []);
226
- }
227
- return;
228
- }
229
- }
230
- reject(new Error("No matching response found"));
231
- }
232
- catch (e) {
233
- reject(new Error(`Parse error: ${e.message}`));
234
- }
235
- }
236
- };
237
- this.process.stdout.on("data", onData);
238
- setTimeout(() => {
239
- this.process.stdout.off("data", onData);
240
- reject(new Error("MCP listTools timeout"));
241
- }, 30000);
242
- });
243
- }
244
- async disconnect() {
245
- if (this.config.transport === "http") {
246
- this._connected = false;
247
- return;
248
- }
249
- if (this.config.transport === "sse" || this.config.url) {
250
- this.abortController?.abort();
251
- this.abortController = null;
252
- }
253
- else if (this.process) {
254
- this.process.kill();
255
- this.process = null;
256
- }
257
- this._connected = false;
258
- }
259
- async callTool(toolName, args) {
260
- if (!this._connected) {
261
- throw new Error("Not connected to MCP server");
262
- }
263
- if (this.config.transport === "http") {
264
- return this.callToolHTTP(toolName, args);
265
- }
266
- if (this.config.transport === "sse" || this.config.url) {
267
- return this.callToolSSE(toolName, args);
268
- }
269
- return this.callToolStdio(toolName, args);
270
- }
271
- async callToolHTTP(toolName, args) {
272
- const request = {
273
- jsonrpc: "2.0",
274
- id: Date.now(),
275
- method: "tools/call",
276
- params: {
277
- name: toolName,
278
- arguments: args,
279
- },
280
- };
281
- const response = await fetch(this.config.url, {
282
- method: "POST",
283
- headers: {
284
- "Content-Type": "application/json",
285
- ...this.config.headers,
286
- },
287
- body: JSON.stringify(request),
288
- });
289
- if (!response.ok) {
290
- const text = await response.text().catch(() => "");
291
- throw new Error(`MCP call failed: ${response.status} ${text}`);
292
- }
293
- const result = await response.json();
294
- if (result.error) {
295
- throw new Error(result.error.message);
296
- }
297
- return result.result || result;
298
- }
299
- async callToolSSE(toolName, args) {
300
- const request = {
301
- jsonrpc: "2.0",
302
- id: Date.now(),
303
- method: "tools/call",
304
- params: {
305
- name: toolName,
306
- arguments: args,
307
- },
308
- };
309
- return new Promise((resolve, reject) => {
310
- this.pendingResolve = resolve;
311
- this.pendingReject = reject;
312
- const timeout = this.config.timeout || 30000;
313
- const timer = setTimeout(() => {
314
- this.pendingResolve = null;
315
- this.pendingReject = null;
316
- reject(new Error("MCP call timeout"));
317
- }, timeout);
318
- fetch(this.config.url, {
319
- method: "POST",
320
- headers: {
321
- "Content-Type": "application/json",
322
- ...this.config.headers,
323
- },
324
- body: JSON.stringify(request),
325
- signal: this.abortController?.signal,
326
- })
327
- .then(async (response) => {
328
- clearTimeout(timer);
329
- if (!response.ok) {
330
- const text = await response.text().catch(() => "");
331
- reject(new Error(`MCP POST failed: ${response.status} ${text}`));
332
- return;
333
- }
334
- const result = await response.json();
335
- if (result.error) {
336
- reject(new Error(result.error.message));
337
- }
338
- else {
339
- resolve(result.result || result);
340
- }
341
- })
342
- .catch((err) => {
343
- clearTimeout(timer);
344
- if (err.name !== "AbortError") {
345
- reject(err);
346
- }
347
- });
348
- });
349
- }
350
- callToolStdio(toolName, args) {
351
- if (!this.process) {
352
- throw new Error("Not connected to MCP server");
353
- }
354
- return new Promise((resolve, reject) => {
355
- const request = {
356
- jsonrpc: "2.0",
357
- id: Date.now(),
358
- method: "tools/call",
359
- params: {
360
- name: toolName,
361
- arguments: args,
362
- },
363
- };
364
- const requestStr = JSON.stringify(request) + "\n";
365
- this.process.stdin.write(requestStr);
366
- let responseData = "";
367
- const onData = (data) => {
368
- responseData += data.toString();
369
- if (responseData.includes("\n")) {
370
- this.process.stdout.off("data", onData);
371
- try {
372
- const lines = responseData.split("\n").filter((l) => l.trim());
373
- for (const line of lines) {
374
- const response = JSON.parse(line);
375
- if (response.id === request.id) {
376
- if (response.error) {
377
- reject(new Error(response.error.message));
378
- }
379
- else {
380
- resolve(response.result);
381
- }
382
- return;
383
- }
384
- }
385
- reject(new Error("No matching response found"));
386
- }
387
- catch (e) {
388
- reject(new Error(`Parse error: ${e.message}`));
389
- }
390
- }
391
- };
392
- this.process.stdout.on("data", onData);
393
- setTimeout(() => {
394
- this.process.stdout.off("data", onData);
395
- reject(new Error("MCP call timeout"));
396
- }, 30000);
397
- });
398
- }
399
- }
@@ -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
- }