micro-models-agent 0.28.9 → 0.29.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 (167) hide show
  1. package/dist/cli/commands.js +220 -0
  2. package/dist/cli/completer.js +168 -0
  3. package/dist/cli/index.js +2 -0
  4. package/dist/cli/main.js +113 -0
  5. package/dist/cli/repl.js +987 -0
  6. package/dist/cli/security-commands.js +166 -0
  7. package/dist/cli/setup.js +229 -0
  8. package/dist/config/config.js +186 -0
  9. package/dist/config/defaults.js +91 -0
  10. package/dist/config/experts.js +15 -0
  11. package/dist/config/index.js +3 -0
  12. package/dist/config/security.js +193 -0
  13. package/dist/config/types.js +1 -0
  14. package/dist/core/agent-moe.js +98 -0
  15. package/dist/core/agent.js +461 -0
  16. package/dist/core/bootstrap.js +321 -0
  17. package/dist/core/index.js +2 -0
  18. package/dist/core/prompt-builder.js +55 -0
  19. package/dist/core/session-logger.js +122 -0
  20. package/dist/core/types.js +1 -0
  21. package/dist/i18n/en.json +461 -0
  22. package/dist/i18n/index.js +43 -0
  23. package/dist/i18n/ru.json +461 -0
  24. package/dist/index.js +22 -0
  25. package/dist/llm/image-utils.js +144 -0
  26. package/dist/llm/index.js +4 -0
  27. package/dist/llm/model-loader.js +78 -0
  28. package/dist/llm/openai-compat.js +324 -0
  29. package/dist/llm/orchestrator.js +194 -0
  30. package/dist/llm/provider.js +10 -0
  31. package/dist/llm/response.js +39 -0
  32. package/dist/llm/token-counter.js +39 -0
  33. package/dist/llm/types.js +1 -0
  34. package/dist/logger/app-logger.js +76 -0
  35. package/dist/logger/index.js +1 -0
  36. package/dist/main.js +2251 -724
  37. package/dist/migration/backup.js +45 -0
  38. package/dist/migration/detect.js +50 -0
  39. package/dist/migration/index.js +2 -0
  40. package/dist/modules/browser/actions.js +46 -0
  41. package/dist/modules/browser/cookie-store.js +24 -0
  42. package/dist/modules/browser/index.js +5 -0
  43. package/dist/modules/browser/module.js +28 -0
  44. package/dist/modules/browser/session.js +287 -0
  45. package/dist/modules/browser/snapshot.js +114 -0
  46. package/dist/modules/browser/types.js +9 -0
  47. package/dist/modules/context/history.js +15 -0
  48. package/dist/modules/context/index.js +1 -0
  49. package/dist/modules/context/manager.js +240 -0
  50. package/dist/modules/execution/auditor.js +72 -0
  51. package/dist/modules/execution/index.js +6 -0
  52. package/dist/modules/execution/module.js +337 -0
  53. package/dist/modules/execution/moe-executor.js +209 -0
  54. package/dist/modules/execution/plan-validator.js +153 -0
  55. package/dist/modules/execution/planner.js +35 -0
  56. package/dist/modules/execution/stuck-detector.js +134 -0
  57. package/dist/modules/execution/tracker.js +53 -0
  58. package/dist/modules/execution/types.js +1 -0
  59. package/dist/modules/execution/verifier.js +149 -0
  60. package/dist/modules/hallucination/confidence.js +54 -0
  61. package/dist/modules/hallucination/consistency.js +60 -0
  62. package/dist/modules/hallucination/detector.js +41 -0
  63. package/dist/modules/hallucination/factual.js +170 -0
  64. package/dist/modules/hallucination/index.js +4 -0
  65. package/dist/modules/index.js +5 -0
  66. package/dist/modules/indexer/cache.js +38 -0
  67. package/dist/modules/indexer/index.js +3 -0
  68. package/dist/modules/indexer/module.js +192 -0
  69. package/dist/modules/indexer/walker.js +101 -0
  70. package/dist/modules/mcp/client.js +393 -0
  71. package/dist/modules/mcp/index.js +3 -0
  72. package/dist/modules/mcp/module.js +146 -0
  73. package/dist/modules/mcp/registry.js +15 -0
  74. package/dist/modules/memory/index.js +1 -0
  75. package/dist/modules/memory/module.js +48 -0
  76. package/dist/modules/memory/search.js +40 -0
  77. package/dist/modules/memory/store.js +65 -0
  78. package/dist/modules/pipelines/engine.js +60 -0
  79. package/dist/modules/pipelines/index.js +3 -0
  80. package/dist/modules/pipelines/parser.js +53 -0
  81. package/dist/modules/pipelines/template.js +14 -0
  82. package/dist/modules/plugins/builtin/lint-on-write.js +121 -0
  83. package/dist/modules/plugins/builtin/notify.js +8 -0
  84. package/dist/modules/plugins/index.js +1 -0
  85. package/dist/modules/plugins/loader.js +28 -0
  86. package/dist/modules/plugins/manager.js +161 -0
  87. package/dist/modules/plugins/types.js +1 -0
  88. package/dist/modules/processes/detect.js +34 -0
  89. package/dist/modules/processes/index.js +3 -0
  90. package/dist/modules/processes/registry.js +148 -0
  91. package/dist/modules/processes/runner.js +124 -0
  92. package/dist/modules/registry.js +45 -0
  93. package/dist/modules/security/audit-log.js +116 -0
  94. package/dist/modules/security/audit-notifier.js +292 -0
  95. package/dist/modules/security/command-validator.js +185 -0
  96. package/dist/modules/security/content-scanner.js +52 -0
  97. package/dist/modules/security/data-sanitizer.js +97 -0
  98. package/dist/modules/security/encryption.js +240 -0
  99. package/dist/modules/security/index.js +14 -0
  100. package/dist/modules/security/network-validator.js +79 -0
  101. package/dist/modules/security/path-validator.js +155 -0
  102. package/dist/modules/security/rate-limiter.js +119 -0
  103. package/dist/modules/security/security-policies.js +393 -0
  104. package/dist/modules/security/session-encryption.js +193 -0
  105. package/dist/modules/security/session-isolation.js +95 -0
  106. package/dist/modules/session/index.js +3 -0
  107. package/dist/modules/session/manager.js +167 -0
  108. package/dist/modules/session/module.js +24 -0
  109. package/dist/modules/session/store.js +174 -0
  110. package/dist/modules/session/types.js +1 -0
  111. package/dist/modules/skills/index.js +3 -0
  112. package/dist/modules/skills/loader.js +72 -0
  113. package/dist/modules/skills/matcher.js +27 -0
  114. package/dist/modules/skills/module.js +143 -0
  115. package/dist/modules/types.js +1 -0
  116. package/dist/modules/updater/checker.js +32 -0
  117. package/dist/modules/updater/index.js +1 -0
  118. package/dist/modules/user-profile/compressor.js +16 -0
  119. package/dist/modules/user-profile/index.js +1 -0
  120. package/dist/modules/user-profile/profile.js +68 -0
  121. package/dist/tools/approve.js +32 -0
  122. package/dist/tools/attach-image.js +89 -0
  123. package/dist/tools/bash.js +140 -0
  124. package/dist/tools/browser.js +97 -0
  125. package/dist/tools/create-dir.js +56 -0
  126. package/dist/tools/delete-file.js +63 -0
  127. package/dist/tools/edit-file.js +77 -0
  128. package/dist/tools/executor.js +95 -0
  129. package/dist/tools/file-info.js +45 -0
  130. package/dist/tools/filter-tools.js +10 -0
  131. package/dist/tools/glob-tool.js +26 -0
  132. package/dist/tools/grep-tool.js +64 -0
  133. package/dist/tools/index.js +52 -0
  134. package/dist/tools/list-dir.js +47 -0
  135. package/dist/tools/load-skill.js +48 -0
  136. package/dist/tools/mcp-call.js +68 -0
  137. package/dist/tools/move-file.js +84 -0
  138. package/dist/tools/path-utils.js +51 -0
  139. package/dist/tools/pipeline-run.js +144 -0
  140. package/dist/tools/preview.js +2 -0
  141. package/dist/tools/process-kill.js +29 -0
  142. package/dist/tools/process-list.js +38 -0
  143. package/dist/tools/process-log.js +41 -0
  144. package/dist/tools/question.js +142 -0
  145. package/dist/tools/read-file.js +73 -0
  146. package/dist/tools/recall.js +110 -0
  147. package/dist/tools/registry.js +36 -0
  148. package/dist/tools/remember.js +67 -0
  149. package/dist/tools/scope-check.js +30 -0
  150. package/dist/tools/search-history.js +64 -0
  151. package/dist/tools/subagent.js +142 -0
  152. package/dist/tools/types.js +1 -0
  153. package/dist/tools/user-input.js +123 -0
  154. package/dist/tools/web-browse.js +57 -0
  155. package/dist/tools/web-fetch.js +72 -0
  156. package/dist/tools/web-search.js +59 -0
  157. package/dist/tools/write-file.js +80 -0
  158. package/dist/ui/box.js +81 -0
  159. package/dist/ui/colors.js +4 -0
  160. package/dist/ui/diff.js +185 -0
  161. package/dist/ui/index.js +6 -0
  162. package/dist/ui/md-formatter.js +212 -0
  163. package/dist/ui/output.js +13 -0
  164. package/dist/ui/renderer.js +141 -0
  165. package/dist/ui/spinner.js +70 -0
  166. package/dist/ui/table.js +144 -0
  167. package/package.json +4 -4
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Default security configuration for MMA.
3
+ * These settings provide a balance between security and usability.
4
+ */
5
+ export const DEFAULT_SECURITY_CONFIG = {
6
+ bash: {
7
+ // Commands that are always blocked (dangerous)
8
+ blacklist: [
9
+ "rm",
10
+ "dd",
11
+ "chmod",
12
+ "wget",
13
+ "curl",
14
+ "scp",
15
+ "ssh",
16
+ "nc",
17
+ "netcat",
18
+ "mknod",
19
+ "mkfifo",
20
+ "ln",
21
+ "chown",
22
+ "chgrp",
23
+ "useradd",
24
+ "usermod",
25
+ "passwd",
26
+ "sudo",
27
+ "su",
28
+ "exec",
29
+ "eval",
30
+ "source",
31
+ "kill",
32
+ "pkill",
33
+ "killall",
34
+ "shutdown",
35
+ "reboot",
36
+ "halt",
37
+ "poweroff",
38
+ "format",
39
+ "fdisk",
40
+ "parted",
41
+ "mkfs",
42
+ "mount",
43
+ "umount",
44
+ "powershell",
45
+ "pwsh",
46
+ "cmd",
47
+ ],
48
+ // If whitelist is non-empty, only these commands are allowed
49
+ whitelist: [],
50
+ // Block dangerous flags like --force, -rf, etc.
51
+ // Disabled by default — enable in config if needed.
52
+ blockDangerousFlags: false,
53
+ // Log all executed commands to audit log
54
+ logCommands: true,
55
+ // Dangerous flags that are always blocked
56
+ dangerousFlags: [
57
+ "--force",
58
+ "-rf",
59
+ "--no-preserve-root",
60
+ "--recursive",
61
+ "--all",
62
+ "-x",
63
+ "-e",
64
+ "--delete",
65
+ "--remove",
66
+ "--dangerous",
67
+ "--yes",
68
+ "-y",
69
+ "--no-confirm",
70
+ ],
71
+ // Dangerous operators that are always blocked
72
+ // Note: "&" (background) is not blocked — "&&" (AND) is a legitimate shell operator.
73
+ // Single "&" for backgrounding is harmless and blocking it breaks "cd dir && npm install".
74
+ dangerousOperators: [">", ">>", "2>", "2>>", "`"],
75
+ },
76
+ paths: {
77
+ // Glob patterns for paths that are always denied
78
+ denied: [
79
+ ".git/",
80
+ "node_modules/",
81
+ ".env",
82
+ "*.key",
83
+ "*.pem",
84
+ "*.crt",
85
+ "*.p12",
86
+ "*.pfx",
87
+ "*.secret",
88
+ "*.token",
89
+ "package-lock.json",
90
+ "bun.lock",
91
+ "yarn.lock",
92
+ "pnpm-lock.yaml",
93
+ ],
94
+ // If allowed is non-empty, only these paths are allowed
95
+ allowed: [],
96
+ },
97
+ network: {
98
+ // Domains that are always denied
99
+ deniedDomains: ["localhost", "127.0.0.1", "::1"],
100
+ // If allowedDomains is non-empty, only these domains are allowed
101
+ allowedDomains: [],
102
+ // Timeout for network requests (ms)
103
+ requestTimeout: 15000,
104
+ // Maximum response size (bytes)
105
+ maxResponseSize: 15000,
106
+ },
107
+ // Maximum depth of subagent recursion
108
+ maxRecursionDepth: 3,
109
+ // Maximum number of file operations per session
110
+ maxFileOperations: 100,
111
+ // Rate limits for LLM requests
112
+ rateLimits: {
113
+ maxRequestsPerMinute: 60,
114
+ maxParallelTasks: 5,
115
+ },
116
+ // Content scanning settings
117
+ contentScan: {
118
+ enabled: true,
119
+ // Patterns that are considered dangerous in file content
120
+ dangerousPatterns: [
121
+ /eval\(/,
122
+ /new Function\(/,
123
+ /child_process\.exec\(/,
124
+ /child_process\.spawn\(/,
125
+ /require\('child_process'\)/,
126
+ /require\('http'\)\.createServer/,
127
+ /require\('net'\)\.createServer/,
128
+ /process\.exit\(/,
129
+ /while\(true\)/,
130
+ /for\(\;\;\)/,
131
+ /rm -rf/,
132
+ /dd if=/,
133
+ /chmod 777/,
134
+ ],
135
+ },
136
+ // Session file encryption settings
137
+ sessionEncryption: {
138
+ enabled: false,
139
+ encryptHistory: true,
140
+ encryptSessionLog: true,
141
+ },
142
+ // Audit notification settings
143
+ auditNotifier: {
144
+ enabled: false,
145
+ minSeverity: 'medium',
146
+ eventTypes: [
147
+ 'security_block',
148
+ 'bash_command',
149
+ 'file_operation',
150
+ 'network_request',
151
+ ],
152
+ maxRetries: 3,
153
+ webhookTimeout: 5000,
154
+ },
155
+ };
156
+ /**
157
+ * Merge user-provided security config with defaults.
158
+ * User config takes precedence over defaults.
159
+ */
160
+ export function mergeSecurityConfig(userConfig) {
161
+ return {
162
+ bash: {
163
+ ...DEFAULT_SECURITY_CONFIG.bash,
164
+ ...userConfig?.bash,
165
+ },
166
+ paths: {
167
+ ...DEFAULT_SECURITY_CONFIG.paths,
168
+ ...userConfig?.paths,
169
+ },
170
+ network: {
171
+ ...DEFAULT_SECURITY_CONFIG.network,
172
+ ...userConfig?.network,
173
+ },
174
+ maxRecursionDepth: userConfig?.maxRecursionDepth ?? DEFAULT_SECURITY_CONFIG.maxRecursionDepth,
175
+ maxFileOperations: userConfig?.maxFileOperations ?? DEFAULT_SECURITY_CONFIG.maxFileOperations,
176
+ rateLimits: {
177
+ ...DEFAULT_SECURITY_CONFIG.rateLimits,
178
+ ...userConfig?.rateLimits,
179
+ },
180
+ contentScan: {
181
+ ...DEFAULT_SECURITY_CONFIG.contentScan,
182
+ ...userConfig?.contentScan,
183
+ },
184
+ sessionEncryption: {
185
+ ...DEFAULT_SECURITY_CONFIG.sessionEncryption,
186
+ ...userConfig?.sessionEncryption,
187
+ },
188
+ auditNotifier: {
189
+ ...DEFAULT_SECURITY_CONFIG.auditNotifier,
190
+ ...userConfig?.auditNotifier,
191
+ },
192
+ };
193
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,98 @@
1
+ import { OrchestratorClient } from "../llm/orchestrator";
2
+ import { validatePlan, applyAutoFixes, } from "../modules/execution/plan-validator";
3
+ import { MoEExecutor } from "../modules/execution/moe-executor";
4
+ import { StepVerifier } from "../modules/execution/verifier";
5
+ /**
6
+ * Execute the MoE (Mixture of Experts) path: plan → validate → execute → verify.
7
+ * Returns a fallback signal when MoE cannot proceed so the caller can fall
8
+ * back to the single-agent loop.
9
+ */
10
+ export async function runWithMoE(deps, input, fallback, opts = {}) {
11
+ const { config, llmProvider, logger, toolExecutor, baseDir } = deps;
12
+ const { onMeta, onPhase } = opts;
13
+ const orchestrator = new OrchestratorClient({
14
+ model: config.orchestrator.model,
15
+ provider: config.orchestrator.provider,
16
+ }, llmProvider);
17
+ if (!orchestrator.isEnabled()) {
18
+ logger.debug("MoE enabled but no orchestrator model configured — falling back to single-agent");
19
+ return fallback();
20
+ }
21
+ onMeta?.("🤖 Planning with MoE mode...\n");
22
+ onPhase?.("thinking");
23
+ const planResult = await orchestrator.plan(input);
24
+ onPhase?.("done");
25
+ if ("error" in planResult) {
26
+ logger.warn(`MoE plan failed: ${planResult.error} — falling back to single-agent`);
27
+ return fallback();
28
+ }
29
+ const { plan } = planResult;
30
+ onMeta?.(`📋 Plan created: "${plan.title}" (${plan.subtasks.length} subtasks)\n`);
31
+ const validation = validatePlan(plan, config);
32
+ if (!validation.valid) {
33
+ const applied = applyAutoFixes(plan, validation.autoFixes);
34
+ const retry = validatePlan(applied, config);
35
+ if (!retry.valid) {
36
+ logger.warn(`MoE plan validation failed: ${retry.errors.join("; ")} — falling back to single-agent`);
37
+ onMeta?.(`⚠️ Plan validation failed. Falling back to single-agent mode.\n`);
38
+ return fallback();
39
+ }
40
+ Object.assign(plan, applied);
41
+ onMeta?.(`🔧 Auto-fixed ${validation.autoFixes.length} plan issues.\n`);
42
+ }
43
+ const moeDeps = {
44
+ config,
45
+ toolRegistry: toolExecutor.getRegistry(),
46
+ toolExecutor,
47
+ llmProvider,
48
+ logger,
49
+ baseDir,
50
+ };
51
+ const executor = new MoEExecutor(moeDeps);
52
+ onMeta?.(`⚙️ Executing ${plan.subtasks.length} subtasks...\n`);
53
+ const planResults = await executor.executePlan(plan);
54
+ onMeta?.(`✅ Execution complete: ${planResults.results.filter((r) => r.success).length}/${planResults.results.length} succeeded\n`);
55
+ const verifier = new StepVerifier(baseDir);
56
+ const knownTags = [
57
+ "file",
58
+ "code",
59
+ "shell",
60
+ "research",
61
+ "browser",
62
+ "vision",
63
+ "core",
64
+ ];
65
+ const verification = await verifier.verifyMoEManifest(plan, config, knownTags);
66
+ onPhase?.("thinking");
67
+ const verifyResult = await orchestrator.verifyAndMerge({
68
+ plan,
69
+ results: planResults.results.map((r) => ({
70
+ subtaskId: r.subtaskId,
71
+ success: r.success,
72
+ summary: r.summary,
73
+ result: r.result,
74
+ error: r.error,
75
+ })),
76
+ verifierErrors: verification.errors,
77
+ verifierWarnings: verification.warnings,
78
+ });
79
+ onPhase?.("done");
80
+ const outputLines = [`## MoE Execution Results\n`];
81
+ for (const r of planResults.results) {
82
+ const icon = r.success ? "✅" : "❌";
83
+ outputLines.push(`${icon} **${r.subtaskId}**: ${r.summary} (${r.durationMs}ms)`);
84
+ }
85
+ outputLines.push("");
86
+ if (verifyResult.type === "final") {
87
+ outputLines.push(`**Result:** ${verifyResult.finalAnswer || "Complete"}`);
88
+ }
89
+ else {
90
+ outputLines.push(`**Re-plan requested:** ${verifyResult.explanation || ""}`);
91
+ }
92
+ const failedCount = planResults.results.filter((r) => !r.success).length;
93
+ return {
94
+ success: failedCount === 0 && verification.success,
95
+ text: outputLines.join("\n"),
96
+ iterationCount: planResults.results.length,
97
+ };
98
+ }