micro-models-agent 0.50.4 → 0.51.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 (218) hide show
  1. package/README.md +358 -358
  2. package/dist/main.js +923 -590
  3. package/dist/modules/browser/bridge-server.mjs +202 -202
  4. package/dist/skills/builtin/git.md +36 -36
  5. package/dist/skills/builtin/typescript.md +35 -35
  6. package/package.json +48 -48
  7. package/dist/cli/commands.js +0 -323
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -165
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -661
  13. package/dist/cli/repl.js +0 -616
  14. package/dist/cli/run-result.js +0 -22
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -231
  17. package/dist/config/config.js +0 -249
  18. package/dist/config/defaults.js +0 -124
  19. package/dist/config/experts.js +0 -15
  20. package/dist/config/index.js +0 -3
  21. package/dist/config/security.js +0 -193
  22. package/dist/config/types.js +0 -1
  23. package/dist/core/agent-moe.js +0 -102
  24. package/dist/core/agent.js +0 -886
  25. package/dist/core/bootstrap.js +0 -404
  26. package/dist/core/index.js +0 -2
  27. package/dist/core/prompt-builder.js +0 -76
  28. package/dist/core/session-logger.js +0 -197
  29. package/dist/core/types.js +0 -1
  30. package/dist/core/version.js +0 -24
  31. package/dist/core/workspace.js +0 -76
  32. package/dist/i18n/en.json +0 -598
  33. package/dist/i18n/index.js +0 -46
  34. package/dist/i18n/ru.json +0 -598
  35. package/dist/index.js +0 -22
  36. package/dist/llm/image-utils.js +0 -143
  37. package/dist/llm/index.js +0 -4
  38. package/dist/llm/model-loader.js +0 -78
  39. package/dist/llm/openai-compat.js +0 -359
  40. package/dist/llm/orchestrator.js +0 -198
  41. package/dist/llm/provider.js +0 -10
  42. package/dist/llm/response.js +0 -39
  43. package/dist/llm/token-counter.js +0 -39
  44. package/dist/llm/types.js +0 -1
  45. package/dist/logger/app-logger.js +0 -143
  46. package/dist/logger/file-log.js +0 -151
  47. package/dist/logger/index.js +0 -1
  48. package/dist/migration/backup.js +0 -45
  49. package/dist/migration/detect.js +0 -50
  50. package/dist/migration/index.js +0 -2
  51. package/dist/modules/artifacts/store.js +0 -61
  52. package/dist/modules/browser/actions.js +0 -76
  53. package/dist/modules/browser/bridge-client.js +0 -199
  54. package/dist/modules/browser/bridge-path.js +0 -10
  55. package/dist/modules/browser/cookie-store.js +0 -24
  56. package/dist/modules/browser/driver.js +0 -136
  57. package/dist/modules/browser/index.js +0 -7
  58. package/dist/modules/browser/module.js +0 -29
  59. package/dist/modules/browser/session.js +0 -338
  60. package/dist/modules/browser/snapshot.js +0 -148
  61. package/dist/modules/browser/types.js +0 -12
  62. package/dist/modules/certification/cli.js +0 -174
  63. package/dist/modules/certification/fact-checker.js +0 -82
  64. package/dist/modules/certification/loader.js +0 -105
  65. package/dist/modules/certification/manifest.js +0 -50
  66. package/dist/modules/certification/runner.js +0 -159
  67. package/dist/modules/certification/scenarios.js +0 -124
  68. package/dist/modules/certification/types.js +0 -1
  69. package/dist/modules/context/chunk-query.js +0 -100
  70. package/dist/modules/context/fact-extractor.js +0 -162
  71. package/dist/modules/context/history.js +0 -15
  72. package/dist/modules/context/index.js +0 -1
  73. package/dist/modules/context/manager.js +0 -423
  74. package/dist/modules/execution/audit-runners.js +0 -152
  75. package/dist/modules/execution/auditor.js +0 -218
  76. package/dist/modules/execution/execution-plugin.js +0 -272
  77. package/dist/modules/execution/index.js +0 -8
  78. package/dist/modules/execution/module.js +0 -436
  79. package/dist/modules/execution/moe-executor.js +0 -291
  80. package/dist/modules/execution/plan-coverage.js +0 -68
  81. package/dist/modules/execution/plan-persister.js +0 -46
  82. package/dist/modules/execution/plan-store.js +0 -157
  83. package/dist/modules/execution/plan-tool.js +0 -508
  84. package/dist/modules/execution/plan-validator.js +0 -153
  85. package/dist/modules/execution/planner.js +0 -90
  86. package/dist/modules/execution/stuck-detector.js +0 -510
  87. package/dist/modules/execution/tracker.js +0 -67
  88. package/dist/modules/execution/types.js +0 -1
  89. package/dist/modules/execution/verifier.js +0 -222
  90. package/dist/modules/execution/windows-commands.js +0 -41
  91. package/dist/modules/hallucination/confidence.js +0 -66
  92. package/dist/modules/hallucination/consistency.js +0 -26
  93. package/dist/modules/hallucination/detector.js +0 -43
  94. package/dist/modules/hallucination/factual.js +0 -129
  95. package/dist/modules/hallucination/index.js +0 -5
  96. package/dist/modules/hallucination/js-identifiers.js +0 -262
  97. package/dist/modules/hallucination/llm-judge.js +0 -101
  98. package/dist/modules/index.js +0 -5
  99. package/dist/modules/indexer/cache.js +0 -40
  100. package/dist/modules/indexer/index.js +0 -3
  101. package/dist/modules/indexer/module.js +0 -245
  102. package/dist/modules/indexer/project-profile.js +0 -183
  103. package/dist/modules/indexer/walker.js +0 -101
  104. package/dist/modules/lsp/check-tool.js +0 -58
  105. package/dist/modules/lsp/client.js +0 -278
  106. package/dist/modules/lsp/command.js +0 -60
  107. package/dist/modules/lsp/config.js +0 -135
  108. package/dist/modules/lsp/index.js +0 -3
  109. package/dist/modules/lsp/module.js +0 -232
  110. package/dist/modules/lsp/probe.js +0 -76
  111. package/dist/modules/lsp/project-root.js +0 -32
  112. package/dist/modules/lsp/startup-check.js +0 -141
  113. package/dist/modules/lsp/types.js +0 -1
  114. package/dist/modules/mcp/client.js +0 -399
  115. package/dist/modules/mcp/index.js +0 -3
  116. package/dist/modules/mcp/module.js +0 -142
  117. package/dist/modules/mcp/registry.js +0 -15
  118. package/dist/modules/memory/index.js +0 -1
  119. package/dist/modules/memory/module.js +0 -96
  120. package/dist/modules/memory/search.js +0 -42
  121. package/dist/modules/memory/store.js +0 -69
  122. package/dist/modules/pipelines/engine.js +0 -60
  123. package/dist/modules/pipelines/index.js +0 -3
  124. package/dist/modules/pipelines/parser.js +0 -56
  125. package/dist/modules/pipelines/template.js +0 -14
  126. package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
  127. package/dist/modules/plugins/builtin/notify.js +0 -9
  128. package/dist/modules/plugins/index.js +0 -1
  129. package/dist/modules/plugins/loader.js +0 -70
  130. package/dist/modules/plugins/manager.js +0 -217
  131. package/dist/modules/plugins/types.js +0 -1
  132. package/dist/modules/processes/detect.js +0 -34
  133. package/dist/modules/processes/index.js +0 -2
  134. package/dist/modules/processes/registry.js +0 -327
  135. package/dist/modules/processes/runner.js +0 -23
  136. package/dist/modules/registry.js +0 -47
  137. package/dist/modules/security/audit-log.js +0 -136
  138. package/dist/modules/security/audit-notifier.js +0 -292
  139. package/dist/modules/security/command-validator.js +0 -205
  140. package/dist/modules/security/content-scanner.js +0 -53
  141. package/dist/modules/security/data-sanitizer.js +0 -89
  142. package/dist/modules/security/encryption.js +0 -242
  143. package/dist/modules/security/index.js +0 -14
  144. package/dist/modules/security/network-validator.js +0 -71
  145. package/dist/modules/security/path-validator.js +0 -207
  146. package/dist/modules/security/rate-limiter.js +0 -119
  147. package/dist/modules/security/security-policies.js +0 -531
  148. package/dist/modules/security/session-encryption.js +0 -210
  149. package/dist/modules/security/session-isolation.js +0 -95
  150. package/dist/modules/session/index.js +0 -3
  151. package/dist/modules/session/manager.js +0 -172
  152. package/dist/modules/session/module.js +0 -24
  153. package/dist/modules/session/store.js +0 -222
  154. package/dist/modules/session/types.js +0 -1
  155. package/dist/modules/skills/index.js +0 -2
  156. package/dist/modules/skills/loader.js +0 -72
  157. package/dist/modules/skills/matcher.js +0 -27
  158. package/dist/modules/skills/module.js +0 -129
  159. package/dist/modules/types.js +0 -1
  160. package/dist/modules/updater/checker.js +0 -96
  161. package/dist/modules/updater/index.js +0 -2
  162. package/dist/modules/updater/module.js +0 -116
  163. package/dist/modules/user-profile/compressor.js +0 -16
  164. package/dist/modules/user-profile/index.js +0 -1
  165. package/dist/modules/user-profile/profile.js +0 -68
  166. package/dist/tools/approve.js +0 -32
  167. package/dist/tools/attach-image.js +0 -89
  168. package/dist/tools/bash.js +0 -496
  169. package/dist/tools/browser.js +0 -114
  170. package/dist/tools/chunk-query.js +0 -99
  171. package/dist/tools/create-dir.js +0 -55
  172. package/dist/tools/delete-file.js +0 -62
  173. package/dist/tools/download-file.js +0 -116
  174. package/dist/tools/edit-file.js +0 -79
  175. package/dist/tools/enable-tools.js +0 -58
  176. package/dist/tools/executor.js +0 -144
  177. package/dist/tools/file-info.js +0 -46
  178. package/dist/tools/filter-tools.js +0 -17
  179. package/dist/tools/glob-tool.js +0 -26
  180. package/dist/tools/grep-tool.js +0 -84
  181. package/dist/tools/hidden-tools-block.js +0 -37
  182. package/dist/tools/index.js +0 -78
  183. package/dist/tools/list-dir.js +0 -48
  184. package/dist/tools/load-skill.js +0 -42
  185. package/dist/tools/mcp-call.js +0 -68
  186. package/dist/tools/move-file.js +0 -85
  187. package/dist/tools/path-utils.js +0 -51
  188. package/dist/tools/pipeline-run.js +0 -144
  189. package/dist/tools/preview.js +0 -2
  190. package/dist/tools/process-kill.js +0 -29
  191. package/dist/tools/process-list.js +0 -36
  192. package/dist/tools/process-log.js +0 -45
  193. package/dist/tools/question.js +0 -140
  194. package/dist/tools/read-file.js +0 -91
  195. package/dist/tools/recall.js +0 -117
  196. package/dist/tools/registry.js +0 -47
  197. package/dist/tools/remember.js +0 -67
  198. package/dist/tools/scope-check.js +0 -30
  199. package/dist/tools/search-history.js +0 -84
  200. package/dist/tools/subagent.js +0 -196
  201. package/dist/tools/types.js +0 -1
  202. package/dist/tools/user-input.js +0 -123
  203. package/dist/tools/web-browse.js +0 -86
  204. package/dist/tools/web-fetch.js +0 -98
  205. package/dist/tools/web-search.js +0 -78
  206. package/dist/tools/write-file.js +0 -81
  207. package/dist/ui/box.js +0 -77
  208. package/dist/ui/colors.js +0 -4
  209. package/dist/ui/diff.js +0 -178
  210. package/dist/ui/index.js +0 -6
  211. package/dist/ui/line-editor.js +0 -703
  212. package/dist/ui/line-math.js +0 -69
  213. package/dist/ui/md-formatter.js +0 -212
  214. package/dist/ui/output.js +0 -13
  215. package/dist/ui/plan-view.js +0 -103
  216. package/dist/ui/renderer.js +0 -209
  217. package/dist/ui/spinner.js +0 -70
  218. 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,142 +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) ? schema.required : [];
11
- return {
12
- type: "object",
13
- properties: schema.properties,
14
- required: required.length > 0 ? required : undefined,
15
- };
16
- }
17
- return { type: "object", properties: {} };
18
- }
19
- export class MCPModule {
20
- config;
21
- name = "mcp";
22
- connections = new Map();
23
- discovered = [];
24
- initialized = false;
25
- initError = null;
26
- constructor(config) {
27
- this.config = config;
28
- }
29
- async initialize() {
30
- if (this.initialized)
31
- return;
32
- this.initialized = true;
33
- const servers = this.config.mcpServers || {};
34
- const serverEntries = Object.entries(servers).filter(([, cfg]) => cfg.enabled !== false);
35
- if (serverEntries.length === 0)
36
- return;
37
- const registry = new MCPRegistry();
38
- for (const [key, cfg] of serverEntries) {
39
- const serverConfig = {
40
- name: cfg.name || key,
41
- command: cfg.command,
42
- args: cfg.args,
43
- env: cfg.env,
44
- transport: cfg.transport,
45
- url: cfg.url,
46
- headers: cfg.headers,
47
- timeout: cfg.timeout,
48
- };
49
- registry.register(serverConfig);
50
- }
51
- for (const serverName of registry.list()) {
52
- const serverConfig = registry.get(serverName);
53
- const client = new MCPClient(serverConfig);
54
- try {
55
- await client.connect();
56
- const tools = await client.listTools();
57
- this.connections.set(serverName, client);
58
- for (const tool of tools) {
59
- this.discovered.push({
60
- serverName,
61
- toolName: tool.name,
62
- description: tool.description || `Tool on MCP server "${serverName}"`,
63
- inputSchema: tool.inputSchema || {},
64
- });
65
- }
66
- }
67
- catch (e) {
68
- this.initError = `MCP server "${serverName}" init failed: ${e.message}`;
69
- await client.disconnect().catch(() => { });
70
- }
71
- }
72
- }
73
- getSystemPromptBlock() {
74
- if (this.discovered.length === 0)
75
- return null;
76
- const lines = ["---", "MCP servers available:"];
77
- const byServer = new Map();
78
- for (const d of this.discovered) {
79
- const list = byServer.get(d.serverName) || [];
80
- list.push(d);
81
- byServer.set(d.serverName, list);
82
- }
83
- for (const [server, tools] of byServer) {
84
- lines.push(` [${server}]`);
85
- for (const t of tools) {
86
- const toolRef = sanitizeToolName(server, t.toolName);
87
- lines.push(` - ${toolRef}: ${t.description}`);
88
- }
89
- }
90
- lines.push("---");
91
- return {
92
- content: lines.join("\n"),
93
- priority: "high",
94
- essential: false,
95
- estimatedTokens: this.discovered.length * 20 + 20,
96
- };
97
- }
98
- getToolDefinitions() {
99
- return this.discovered.map((d) => ({
100
- name: sanitizeToolName(d.serverName, d.toolName),
101
- description: `${d.description} [MCP server: ${d.serverName}]`,
102
- parameters: convertInputSchema(d.inputSchema),
103
- tags: ["code", "research"],
104
- handler: async (_ctx, args) => {
105
- const client = this.connections.get(d.serverName);
106
- if (!client) {
107
- return {
108
- success: false,
109
- output: `MCP server "${d.serverName}" not connected`,
110
- };
111
- }
112
- try {
113
- if (!client.isConnected()) {
114
- await client.connect();
115
- }
116
- const result = await client.callTool(d.toolName, args);
117
- return {
118
- success: true,
119
- output: typeof result === "string" ? result : JSON.stringify(result, null, 2),
120
- };
121
- }
122
- catch (e) {
123
- return { success: false, output: `MCP call failed: ${e.message}` };
124
- }
125
- },
126
- }));
127
- }
128
- getPlugin() {
129
- return {
130
- name: "mcp_module",
131
- priority: 0,
132
- onSessionEnd: async () => {
133
- for (const client of this.connections.values()) {
134
- try {
135
- await client.disconnect();
136
- }
137
- catch { }
138
- }
139
- },
140
- };
141
- }
142
- }
@@ -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,96 +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
- const MEMORY_MD_FILES = ["errors", "conventions", "decisions", "facts"];
7
- export class MemoryModule {
8
- name = "memory";
9
- store;
10
- constructor(storeOrDir) {
11
- if (storeOrDir instanceof MemoryStore) {
12
- this.store = storeOrDir;
13
- }
14
- else {
15
- const dir = storeOrDir || join(homedir(), ".mma", "memory");
16
- this.store = new MemoryStore(dir);
17
- }
18
- }
19
- getSystemPromptBlock() {
20
- const parts = [];
21
- const prefs = this.store.getPreferences();
22
- if (Object.keys(prefs).length > 0) {
23
- const prefStr = Object.entries(prefs)
24
- .map(([k, v]) => `${k}=${v}`)
25
- .join(", ");
26
- parts.push(`User preferences: ${prefStr}`);
27
- }
28
- const memoryTail = this.getMemoryTail();
29
- if (memoryTail)
30
- parts.push(memoryTail);
31
- if (parts.length === 0)
32
- return null;
33
- const content = parts.join("\n\n");
34
- return {
35
- content,
36
- priority: "normal",
37
- essential: false,
38
- estimatedTokens: Math.ceil(content.length / 4) + 10,
39
- };
40
- }
41
- /**
42
- * Bounded tail of the append-only .md memory files (errors, conventions,
43
- * decisions, facts). This is what makes past-session lessons visible in the
44
- * system prompt — without it the loop's error rules are write-only.
45
- */
46
- getMemoryTail() {
47
- const sections = [];
48
- const tailPerFile = 3;
49
- for (const name of MEMORY_MD_FILES) {
50
- const content = this.store.read(name).trim();
51
- if (!content)
52
- continue;
53
- const entries = content
54
- .split(/\r?\n/)
55
- .map((l) => l.trim())
56
- .filter((l) => l.startsWith("- "))
57
- .slice(-tailPerFile);
58
- if (entries.length === 0)
59
- continue;
60
- sections.push(`[Memory ${name}]:\n${entries.join("\n")}`);
61
- }
62
- if (sections.length === 0)
63
- return null;
64
- let joined = sections.join("\n\n");
65
- // Hard cap so a huge errors.md can never blow the system prompt budget.
66
- if (joined.length > 1200)
67
- joined = joined.slice(0, 1200) + "\n…";
68
- return joined;
69
- }
70
- getToolDefinitions() {
71
- return [rememberTool, recallTool];
72
- }
73
- getPlugin() {
74
- return {
75
- name: "memory",
76
- isBuiltin: true,
77
- onBuildPrompt: () => {
78
- const parts = [];
79
- const prefs = this.store.getPreferences();
80
- if (Object.keys(prefs).length > 0) {
81
- const prefStr = Object.entries(prefs)
82
- .map(([k, v]) => `${k}=${v}`)
83
- .join(", ");
84
- parts.push(`User preferences: ${prefStr}`);
85
- }
86
- const memoryTail = this.getMemoryTail();
87
- if (memoryTail)
88
- parts.push(memoryTail);
89
- return parts.length > 0 ? parts.join("\n\n") : null;
90
- },
91
- };
92
- }
93
- getStore() {
94
- return this.store;
95
- }
96
- }
@@ -1,42 +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 {
37
- /* skip */
38
- }
39
- }
40
- return results;
41
- }
42
- }