micro-models-agent 0.19.1 → 0.19.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.
- package/dist/main.js +18046 -0
- package/package.json +1 -1
- package/dist/cli/commands.js +0 -237
- package/dist/cli/completer.js +0 -168
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -113
- package/dist/cli/repl.js +0 -1010
- package/dist/cli/security-commands.js +0 -166
- package/dist/cli/setup.js +0 -229
- package/dist/config/config.js +0 -186
- package/dist/config/defaults.js +0 -91
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -193
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -98
- package/dist/core/agent.js +0 -471
- package/dist/core/bootstrap.js +0 -314
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -55
- package/dist/core/session-logger.js +0 -122
- package/dist/core/types.js +0 -1
- package/dist/i18n/en.json +0 -461
- package/dist/i18n/index.js +0 -43
- package/dist/i18n/ru.json +0 -461
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -144
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -324
- package/dist/llm/orchestrator.js +0 -194
- package/dist/llm/provider.js +0 -10
- package/dist/llm/response.js +0 -39
- package/dist/llm/token-counter.js +0 -39
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -76
- package/dist/logger/index.js +0 -1
- package/dist/migration/backup.js +0 -45
- package/dist/migration/detect.js +0 -50
- package/dist/migration/index.js +0 -2
- package/dist/modules/browser/actions.js +0 -46
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/index.js +0 -5
- package/dist/modules/browser/module.js +0 -28
- package/dist/modules/browser/session.js +0 -287
- package/dist/modules/browser/snapshot.js +0 -114
- package/dist/modules/browser/types.js +0 -9
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -240
- package/dist/modules/execution/auditor.js +0 -72
- package/dist/modules/execution/index.js +0 -6
- package/dist/modules/execution/module.js +0 -337
- package/dist/modules/execution/moe-executor.js +0 -209
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -35
- package/dist/modules/execution/stuck-detector.js +0 -134
- package/dist/modules/execution/tracker.js +0 -53
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -149
- package/dist/modules/hallucination/confidence.js +0 -59
- package/dist/modules/hallucination/consistency.js +0 -66
- package/dist/modules/hallucination/detector.js +0 -33
- package/dist/modules/hallucination/index.js +0 -3
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -38
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -192
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/mcp/client.js +0 -393
- package/dist/modules/mcp/index.js +0 -3
- package/dist/modules/mcp/module.js +0 -146
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -48
- package/dist/modules/memory/search.js +0 -40
- package/dist/modules/memory/store.js +0 -65
- package/dist/modules/pipelines/engine.js +0 -60
- package/dist/modules/pipelines/index.js +0 -3
- package/dist/modules/pipelines/parser.js +0 -53
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -121
- package/dist/modules/plugins/builtin/notify.js +0 -8
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -28
- package/dist/modules/plugins/manager.js +0 -161
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -3
- package/dist/modules/processes/registry.js +0 -148
- package/dist/modules/processes/runner.js +0 -124
- package/dist/modules/registry.js +0 -45
- package/dist/modules/security/audit-log.js +0 -116
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -185
- package/dist/modules/security/content-scanner.js +0 -52
- package/dist/modules/security/data-sanitizer.js +0 -97
- package/dist/modules/security/encryption.js +0 -240
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -79
- package/dist/modules/security/path-validator.js +0 -155
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -393
- package/dist/modules/security/session-encryption.js +0 -193
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -167
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -174
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -3
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -143
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -32
- package/dist/modules/updater/index.js +0 -1
- package/dist/modules/user-profile/compressor.js +0 -16
- package/dist/modules/user-profile/index.js +0 -1
- package/dist/modules/user-profile/profile.js +0 -68
- package/dist/skills/builtin/builtin/git.md +0 -36
- package/dist/skills/builtin/builtin/typescript.md +0 -35
- package/dist/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -140
- package/dist/tools/browser.js +0 -97
- package/dist/tools/create-dir.js +0 -55
- package/dist/tools/delete-file.js +0 -62
- package/dist/tools/edit-file.js +0 -77
- package/dist/tools/executor.js +0 -95
- package/dist/tools/file-info.js +0 -45
- package/dist/tools/filter-tools.js +0 -10
- package/dist/tools/glob-tool.js +0 -26
- package/dist/tools/grep-tool.js +0 -64
- package/dist/tools/index.js +0 -52
- package/dist/tools/list-dir.js +0 -47
- package/dist/tools/load-skill.js +0 -48
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -84
- package/dist/tools/path-utils.js +0 -51
- package/dist/tools/pipeline-run.js +0 -144
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -29
- package/dist/tools/process-list.js +0 -38
- package/dist/tools/process-log.js +0 -41
- package/dist/tools/question.js +0 -142
- package/dist/tools/read-file.js +0 -70
- package/dist/tools/recall.js +0 -110
- package/dist/tools/registry.js +0 -36
- package/dist/tools/remember.js +0 -67
- package/dist/tools/scope-check.js +0 -30
- package/dist/tools/search-history.js +0 -64
- package/dist/tools/subagent.js +0 -142
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -57
- package/dist/tools/web-fetch.js +0 -72
- package/dist/tools/web-search.js +0 -59
- package/dist/tools/write-file.js +0 -79
- package/dist/ui/box.js +0 -81
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -185
- package/dist/ui/index.js +0 -6
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/renderer.js +0 -141
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
package/dist/core/bootstrap.js
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "../config/config";
|
|
2
|
-
import { Logger } from "../logger/app-logger";
|
|
3
|
-
import { OpenAICompatProvider } from "../llm/openai-compat";
|
|
4
|
-
import { ModelLoader } from "../llm/model-loader";
|
|
5
|
-
import { ToolRegistry, registerAllTools } from "../tools/index";
|
|
6
|
-
import { ToolExecutor } from "../tools/executor";
|
|
7
|
-
import { ModuleRegistry } from "../modules/registry";
|
|
8
|
-
import { PluginManager } from "../modules/plugins/manager";
|
|
9
|
-
import { PluginLoader } from "../modules/plugins/loader";
|
|
10
|
-
import { plugin as lintOnWritePlugin } from "../modules/plugins/builtin/lint-on-write";
|
|
11
|
-
import { plugin as notifyPlugin } from "../modules/plugins/builtin/notify";
|
|
12
|
-
import { ContextManager } from "../modules/context/manager";
|
|
13
|
-
import { TokenCounter } from "../llm/token-counter";
|
|
14
|
-
import { HallucinationDetector } from "../modules/hallucination/detector";
|
|
15
|
-
import { ExecutionModule } from "../modules/execution/module";
|
|
16
|
-
import { SessionStore, SessionManager, SessionModule, } from "../modules/session/index";
|
|
17
|
-
import { UserProfile } from "../modules/user-profile/profile";
|
|
18
|
-
import { SkillsLoader, SkillsMatcher, SkillsModule, } from "../modules/skills/index";
|
|
19
|
-
import { BrowserModule } from "../modules/browser/index";
|
|
20
|
-
import { IndexerModule } from "../modules/indexer/index";
|
|
21
|
-
import { MCPModule } from "../modules/mcp/index";
|
|
22
|
-
import { MemoryModule } from "../modules/memory/module";
|
|
23
|
-
import { setLocale } from "../i18n/index";
|
|
24
|
-
import { Agent } from "./agent";
|
|
25
|
-
import { homedir } from "os";
|
|
26
|
-
import { join, resolve } from "path";
|
|
27
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
28
|
-
function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
29
|
-
const now = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
30
|
-
const isWin = profileCompressed.toLowerCase().includes("win32");
|
|
31
|
-
const lines = [
|
|
32
|
-
`You are MMA v2, an AI coding agent for small models (${config.model}).`,
|
|
33
|
-
`Date: ${now}`,
|
|
34
|
-
`Workspace: ${baseDir}`,
|
|
35
|
-
`${profileCompressed}`,
|
|
36
|
-
`Reply in the user's language. Use tools for filesystem, bash, web access.`,
|
|
37
|
-
`Use tools when needed. Explain briefly what you're doing if it's not obvious.`,
|
|
38
|
-
`Answer the user's question directly. Only take action when the user explicitly asks you to change, create, or fix something.`,
|
|
39
|
-
`If a tool call fails, report the error and ask the user how to proceed.`,
|
|
40
|
-
``,
|
|
41
|
-
`Design principles — apply them automatically without naming them:`,
|
|
42
|
-
`- Do not add code, files, or abstractions that are not needed right now (YAGNI — You Ain't Gonna Need It). If something is not required by the current task, omit it.`,
|
|
43
|
-
`- Prefer simple, straightforward solutions over clever or complex ones (KISS — Keep It Simple, Stupid). Flat code beats nested, minimal config beats flexible, explicit beats generic.`,
|
|
44
|
-
`- Do not duplicate code, logic, or configuration (DRY — Don't Repeat Yourself). Extract shared logic into a single place, reuse existing utilities and patterns before writing new ones.`,
|
|
45
|
-
];
|
|
46
|
-
if (isWin) {
|
|
47
|
-
lines.push(``, `Windows environment — use Windows-compatible commands:`, `- Use "dir" instead of "ls". Use "dir /b" for bare listing.`, `- Use "type" or "Get-Content" instead of "cat".`, `- Use "cd" instead of "pwd". Use "echo %cd%" to print working directory.`, `- Use "copy" instead of "cp", "move" instead of "mv", "del" instead of "rm".`, `- Do not use "mkdir -p" — Windows mkdir creates intermediate dirs by default. Use the create_dir tool instead.`, `- Use forward slashes (/) or escaped backslashes (\\\\) in file paths.`, `- Your working directory is: ${baseDir}`);
|
|
48
|
-
}
|
|
49
|
-
lines.push(``, `Bash tool rules:`, `- Use the "workdir" parameter to run commands in a specific directory. Do NOT chain "cd dir && cmd" — the security module blocks the "&&" operator.`, `- Run one command per tool call. Split multi-step shell operations into separate bash calls.`);
|
|
50
|
-
if (config.autoPlan) {
|
|
51
|
-
lines.push(``, `Plan rule: For complex tasks with 3+ steps, you may create a plan using the "plan" tool. For simple questions, just answer directly.`);
|
|
52
|
-
}
|
|
53
|
-
const hasMCP = config.mcpServers &&
|
|
54
|
-
Object.values(config.mcpServers).some((s) => s.enabled !== false);
|
|
55
|
-
if (hasMCP) {
|
|
56
|
-
lines.push(``, `MCP servers are available. Use the named MCP tools (prefixed with mcp__) to query external services.`);
|
|
57
|
-
}
|
|
58
|
-
return lines.join("\n");
|
|
59
|
-
}
|
|
60
|
-
export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
61
|
-
const dir = configDir || join(homedir(), ".mma");
|
|
62
|
-
const projectConfigPath = projectDir
|
|
63
|
-
? join(projectDir, ".mmrc")
|
|
64
|
-
: join(process.cwd(), ".mmrc");
|
|
65
|
-
const config = loadConfig({ configDir: dir, projectConfigPath });
|
|
66
|
-
setLocale(config.locale);
|
|
67
|
-
// Update global audit notifier with config
|
|
68
|
-
try {
|
|
69
|
-
const { globalAuditNotifier } = await import("../modules/security/audit-notifier");
|
|
70
|
-
if (config.security?.auditNotifier) {
|
|
71
|
-
globalAuditNotifier.updateConfig(config.security.auditNotifier);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
// Ignore if audit notifier is not available
|
|
76
|
-
}
|
|
77
|
-
const logger = new Logger(config.logLevel);
|
|
78
|
-
logger.setLogDir(join(dir, "logs"));
|
|
79
|
-
logger.debug("MMA bootstrap", {
|
|
80
|
-
version: config.version,
|
|
81
|
-
model: config.model,
|
|
82
|
-
});
|
|
83
|
-
if (config.modelLoad.autoLoad) {
|
|
84
|
-
const modelLoader = new ModelLoader(config.provider.baseUrl, logger);
|
|
85
|
-
const loadResult = await modelLoader.ensureModelLoaded({
|
|
86
|
-
model: config.model,
|
|
87
|
-
contextLength: config.contextWindow,
|
|
88
|
-
flashAttention: config.modelLoad.flashAttention,
|
|
89
|
-
offloadKvCacheToGpu: config.modelLoad.offloadKvCacheToGpu,
|
|
90
|
-
autoLoad: config.modelLoad.autoLoad,
|
|
91
|
-
});
|
|
92
|
-
if (!loadResult.success) {
|
|
93
|
-
logger.warn(`Model auto-load failed: ${loadResult.error}. Continuing with manual load.`);
|
|
94
|
-
}
|
|
95
|
-
else if (loadResult.alreadyLoaded) {
|
|
96
|
-
logger.debug(`Model ${config.model} already loaded`);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
logger.info(`Model ${config.model} loaded in ${loadResult.loadTime}s`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const profile = new UserProfile(join(dir));
|
|
103
|
-
profile.load() || profile.collect();
|
|
104
|
-
profile.save();
|
|
105
|
-
const llmProvider = new OpenAICompatProvider({
|
|
106
|
-
model: config.model,
|
|
107
|
-
baseUrl: config.provider.baseUrl,
|
|
108
|
-
apiKey: config.provider.apiKey,
|
|
109
|
-
contextWindow: config.contextWindow,
|
|
110
|
-
retry: config.retry,
|
|
111
|
-
rateLimits: config.security?.rateLimits,
|
|
112
|
-
});
|
|
113
|
-
const baseDir = projectDir ? resolve(projectDir) : process.cwd();
|
|
114
|
-
const projectMapCacheDir = join(baseDir, ".mma");
|
|
115
|
-
const indexerModule = new IndexerModule({
|
|
116
|
-
baseDir,
|
|
117
|
-
cacheDir: projectMapCacheDir,
|
|
118
|
-
});
|
|
119
|
-
try {
|
|
120
|
-
await indexerModule.buildIndex();
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
logger.warn(`Project indexing failed: ${err.message}`);
|
|
124
|
-
}
|
|
125
|
-
const skillsLoader = new SkillsLoader();
|
|
126
|
-
const builtinDir = join(import.meta.dirname, "skills", "builtin");
|
|
127
|
-
const globalDir = join(homedir(), ".agents", "skills");
|
|
128
|
-
const projectSkillsDir = join(baseDir, ".mma", "skills");
|
|
129
|
-
const availableSkills = skillsLoader.loadFromAllSources(builtinDir, globalDir, projectSkillsDir);
|
|
130
|
-
const skillsMatcher = new SkillsMatcher();
|
|
131
|
-
const skillsBudget = Math.floor(config.contextWindow * 0.1);
|
|
132
|
-
const skillsModule = new SkillsModule(availableSkills, skillsMatcher, skillsBudget);
|
|
133
|
-
const toolRegistry = new ToolRegistry();
|
|
134
|
-
registerAllTools(toolRegistry, skillsModule);
|
|
135
|
-
const pluginManager = new PluginManager();
|
|
136
|
-
const systemInfoPrompt = {
|
|
137
|
-
content: buildSystemInfo(config, baseDir, profile.compress()),
|
|
138
|
-
priority: "critical",
|
|
139
|
-
essential: true,
|
|
140
|
-
estimatedTokens: 250,
|
|
141
|
-
};
|
|
142
|
-
const agentsMdGlobal = join(dir, "AGENTS.md");
|
|
143
|
-
if (!existsSync(agentsMdGlobal)) {
|
|
144
|
-
writeFileSync(agentsMdGlobal, "", "utf-8");
|
|
145
|
-
}
|
|
146
|
-
const sessionDir = join(dir, "sessions");
|
|
147
|
-
const sessionStore = new SessionStore(sessionDir);
|
|
148
|
-
sessionStore.init();
|
|
149
|
-
const sessionManager = new SessionManager(sessionStore, {
|
|
150
|
-
model: config.model,
|
|
151
|
-
contextWindow: config.contextWindow,
|
|
152
|
-
projectDir: baseDir,
|
|
153
|
-
maxSessions: config.session.maxSessions,
|
|
154
|
-
isolation: config.sessionIsolation,
|
|
155
|
-
});
|
|
156
|
-
if (config.session.autoSave && !sessionManager.getActive()) {
|
|
157
|
-
sessionManager.create();
|
|
158
|
-
}
|
|
159
|
-
const tokenCounter = new TokenCounter(config.model);
|
|
160
|
-
const contextManager = new ContextManager(config.contextWindow, config.contextBudget, tokenCounter);
|
|
161
|
-
const toolCtx = {
|
|
162
|
-
config,
|
|
163
|
-
baseDir,
|
|
164
|
-
logger,
|
|
165
|
-
exitOnComplete,
|
|
166
|
-
contextManager,
|
|
167
|
-
sessionId: sessionManager.getActiveMeta()?.id,
|
|
168
|
-
sessionContext: sessionManager.getSessionContext() ?? undefined,
|
|
169
|
-
recursionDepth: 0,
|
|
170
|
-
fileOperationsCount: 0,
|
|
171
|
-
sessionHistory: {
|
|
172
|
-
append: async (type, content) => {
|
|
173
|
-
const meta = sessionManager.getActiveMeta();
|
|
174
|
-
if (!meta)
|
|
175
|
-
return;
|
|
176
|
-
sessionManager.appendMessage({
|
|
177
|
-
role: "tool",
|
|
178
|
-
content: typeof content === "string" ? content : JSON.stringify(content),
|
|
179
|
-
name: type,
|
|
180
|
-
timestamp: new Date().toISOString(),
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
const toolExecutor = new ToolExecutor(toolRegistry, toolCtx, pluginManager);
|
|
186
|
-
toolCtx.llmProvider = llmProvider;
|
|
187
|
-
toolCtx.toolExecutor = toolExecutor;
|
|
188
|
-
const hallucinationDetector = new HallucinationDetector();
|
|
189
|
-
const moduleRegistry = new ModuleRegistry();
|
|
190
|
-
const execModule = new ExecutionModule(baseDir, config.stuckThreshold);
|
|
191
|
-
moduleRegistry.register(execModule);
|
|
192
|
-
const sessionModule = new SessionModule(sessionManager);
|
|
193
|
-
moduleRegistry.register(sessionModule);
|
|
194
|
-
moduleRegistry.register(skillsModule);
|
|
195
|
-
moduleRegistry.register(indexerModule);
|
|
196
|
-
const mcpModule = new MCPModule(config);
|
|
197
|
-
await mcpModule.initialize();
|
|
198
|
-
moduleRegistry.register(mcpModule);
|
|
199
|
-
const memoryModule = new MemoryModule(join(dir, "memory"));
|
|
200
|
-
moduleRegistry.register(memoryModule);
|
|
201
|
-
if (config.browser.enabled) {
|
|
202
|
-
const browserModule = new BrowserModule();
|
|
203
|
-
moduleRegistry.register(browserModule);
|
|
204
|
-
const browserPlugin = browserModule.getPlugin();
|
|
205
|
-
if (browserPlugin) {
|
|
206
|
-
browserPlugin.isBuiltin = true;
|
|
207
|
-
pluginManager.register(browserPlugin);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const moduleTools = moduleRegistry.collectToolDefinitions();
|
|
211
|
-
for (const tool of moduleTools) {
|
|
212
|
-
toolRegistry.register(tool);
|
|
213
|
-
}
|
|
214
|
-
const plugin = execModule.getPlugin();
|
|
215
|
-
if (plugin) {
|
|
216
|
-
plugin.isBuiltin = true;
|
|
217
|
-
pluginManager.register(plugin);
|
|
218
|
-
}
|
|
219
|
-
const sessionPlugin = sessionModule.getPlugin();
|
|
220
|
-
if (sessionPlugin) {
|
|
221
|
-
sessionPlugin.isBuiltin = true;
|
|
222
|
-
pluginManager.register(sessionPlugin);
|
|
223
|
-
}
|
|
224
|
-
const skillsPlugin = skillsModule.getPlugin();
|
|
225
|
-
if (skillsPlugin) {
|
|
226
|
-
skillsPlugin.isBuiltin = true;
|
|
227
|
-
pluginManager.register(skillsPlugin);
|
|
228
|
-
}
|
|
229
|
-
const indexerPlugin = indexerModule.getPlugin();
|
|
230
|
-
if (indexerPlugin) {
|
|
231
|
-
indexerPlugin.isBuiltin = true;
|
|
232
|
-
pluginManager.register(indexerPlugin);
|
|
233
|
-
}
|
|
234
|
-
const mcpPlugin = mcpModule.getPlugin();
|
|
235
|
-
if (mcpPlugin) {
|
|
236
|
-
mcpPlugin.isBuiltin = true;
|
|
237
|
-
pluginManager.register(mcpPlugin);
|
|
238
|
-
}
|
|
239
|
-
pluginManager.register(lintOnWritePlugin);
|
|
240
|
-
pluginManager.register(notifyPlugin);
|
|
241
|
-
const pluginLoader = new PluginLoader();
|
|
242
|
-
const globalPluginsDir = join(homedir(), ".mma", "plugins");
|
|
243
|
-
const projectPluginsDir = join(dir, ".mma", "plugins");
|
|
244
|
-
pluginLoader.loadFromDir(globalPluginsDir, pluginManager, logger);
|
|
245
|
-
pluginLoader.loadFromDir(projectPluginsDir, pluginManager, logger);
|
|
246
|
-
contextManager.onCompact = (summary) => {
|
|
247
|
-
const meta = sessionManager.getActiveMeta();
|
|
248
|
-
if (!meta || !config.session.autoSave)
|
|
249
|
-
return;
|
|
250
|
-
sessionManager.appendMessage({
|
|
251
|
-
role: summary.role,
|
|
252
|
-
content: summary.content,
|
|
253
|
-
name: summary.name,
|
|
254
|
-
timestamp: new Date().toISOString(),
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const agentsMdBlocks = [];
|
|
258
|
-
const skipAgentsMd = noAgentsMd === true;
|
|
259
|
-
if (!skipAgentsMd) {
|
|
260
|
-
const agentsMdCandidates = [
|
|
261
|
-
join(baseDir, "AGENTS.md"),
|
|
262
|
-
join(baseDir, ".mma", "AGENTS.md"),
|
|
263
|
-
join(dir, "AGENTS.md"),
|
|
264
|
-
];
|
|
265
|
-
for (const p of agentsMdCandidates) {
|
|
266
|
-
if (existsSync(p)) {
|
|
267
|
-
const content = readFileSync(p, "utf-8").trim();
|
|
268
|
-
if (content) {
|
|
269
|
-
agentsMdBlocks.push({
|
|
270
|
-
content,
|
|
271
|
-
priority: "high",
|
|
272
|
-
essential: false,
|
|
273
|
-
estimatedTokens: Math.ceil(content.length / 4),
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const promptBlocks = [
|
|
280
|
-
systemInfoPrompt,
|
|
281
|
-
...moduleRegistry.collectPromptBlocks(),
|
|
282
|
-
...agentsMdBlocks,
|
|
283
|
-
];
|
|
284
|
-
const agentDeps = {
|
|
285
|
-
config,
|
|
286
|
-
llmProvider,
|
|
287
|
-
toolExecutor,
|
|
288
|
-
pluginManager,
|
|
289
|
-
contextManager,
|
|
290
|
-
hallucinationDetector,
|
|
291
|
-
logger,
|
|
292
|
-
baseDir,
|
|
293
|
-
promptBlocks,
|
|
294
|
-
getDynamicPromptBlocks: () => {
|
|
295
|
-
const planBlock = execModule.getSystemPromptBlock();
|
|
296
|
-
return planBlock ? [planBlock] : [];
|
|
297
|
-
},
|
|
298
|
-
finalAudit: () => execModule.runFinalAudit(),
|
|
299
|
-
sessionManager,
|
|
300
|
-
exitOnComplete,
|
|
301
|
-
};
|
|
302
|
-
const agent = new Agent(agentDeps);
|
|
303
|
-
return {
|
|
304
|
-
agent,
|
|
305
|
-
config,
|
|
306
|
-
logger,
|
|
307
|
-
sessionManager,
|
|
308
|
-
skillsModule,
|
|
309
|
-
pluginManager,
|
|
310
|
-
configDir: dir,
|
|
311
|
-
baseDir,
|
|
312
|
-
noAgentsMd: skipAgentsMd,
|
|
313
|
-
};
|
|
314
|
-
}
|
package/dist/core/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const PRIORITY_ORDER = {
|
|
2
|
-
critical: 0,
|
|
3
|
-
high: 1,
|
|
4
|
-
normal: 2,
|
|
5
|
-
low: 3,
|
|
6
|
-
};
|
|
7
|
-
export class PromptBuilder {
|
|
8
|
-
blocks = [];
|
|
9
|
-
budget;
|
|
10
|
-
constructor(budget) {
|
|
11
|
-
this.budget = budget;
|
|
12
|
-
}
|
|
13
|
-
addBlock(block) {
|
|
14
|
-
this.blocks.push(block);
|
|
15
|
-
}
|
|
16
|
-
addBlocks(blocks) {
|
|
17
|
-
for (const b of blocks) {
|
|
18
|
-
this.blocks.push(b);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
build() {
|
|
22
|
-
const essential = [];
|
|
23
|
-
const nonEssential = [];
|
|
24
|
-
for (const block of this.blocks) {
|
|
25
|
-
if (block.essential) {
|
|
26
|
-
essential.push(block);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
nonEssential.push(block);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
nonEssential.sort((a, b) => PRIORITY_ORDER[a.priority] - PRIORITY_ORDER[b.priority]);
|
|
33
|
-
let usedTokens = 0;
|
|
34
|
-
const included = [];
|
|
35
|
-
const excluded = [];
|
|
36
|
-
for (const block of essential) {
|
|
37
|
-
included.push(block.content);
|
|
38
|
-
usedTokens += block.estimatedTokens;
|
|
39
|
-
}
|
|
40
|
-
for (const block of nonEssential) {
|
|
41
|
-
const tokens = block.estimatedTokens;
|
|
42
|
-
if (usedTokens + tokens <= this.budget) {
|
|
43
|
-
included.push(block.content);
|
|
44
|
-
usedTokens += tokens;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
excluded.push(block.content);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
prompt: included.join('\n\n'),
|
|
52
|
-
excluded,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thin wrapper around SessionManager that eliminates repetitive
|
|
3
|
-
* `if (sessionManager)` + `new Date().toISOString()` boilerplate
|
|
4
|
-
* from the agent loop.
|
|
5
|
-
*/
|
|
6
|
-
export class SessionLogger {
|
|
7
|
-
session;
|
|
8
|
-
constructor(session) {
|
|
9
|
-
this.session = session;
|
|
10
|
-
}
|
|
11
|
-
get active() {
|
|
12
|
-
return !!this.session?.getActive();
|
|
13
|
-
}
|
|
14
|
-
logSystem(content) {
|
|
15
|
-
this.session?.appendLog({
|
|
16
|
-
ts: new Date().toISOString(),
|
|
17
|
-
type: "system",
|
|
18
|
-
content,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
logUser(content) {
|
|
22
|
-
this.session?.appendMessage({
|
|
23
|
-
role: "user",
|
|
24
|
-
content,
|
|
25
|
-
timestamp: new Date().toISOString(),
|
|
26
|
-
});
|
|
27
|
-
this.session?.appendLog({
|
|
28
|
-
ts: new Date().toISOString(),
|
|
29
|
-
type: "user",
|
|
30
|
-
content,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
logAssistant(content, reasoning, toolCalls, iteration) {
|
|
34
|
-
if (reasoning) {
|
|
35
|
-
this.session?.appendLog({
|
|
36
|
-
ts: new Date().toISOString(),
|
|
37
|
-
type: "reasoning",
|
|
38
|
-
content: reasoning,
|
|
39
|
-
iteration,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
this.session?.appendLog({
|
|
43
|
-
ts: new Date().toISOString(),
|
|
44
|
-
type: "assistant",
|
|
45
|
-
content,
|
|
46
|
-
...(toolCalls
|
|
47
|
-
? { tool_calls: toolCalls.map((tc) => ({ id: tc.id, name: tc.name, arguments: tc.arguments })) }
|
|
48
|
-
: {}),
|
|
49
|
-
iteration,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
saveAssistantMessage(content) {
|
|
53
|
-
this.session?.appendMessage({
|
|
54
|
-
role: "assistant",
|
|
55
|
-
content: content.slice(0, 500),
|
|
56
|
-
timestamp: new Date().toISOString(),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
logToolDefs(toolCount, toolNames, iteration) {
|
|
60
|
-
this.session?.appendLog({
|
|
61
|
-
ts: new Date().toISOString(),
|
|
62
|
-
type: "tool_defs",
|
|
63
|
-
toolCount,
|
|
64
|
-
toolNames,
|
|
65
|
-
iteration,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
logToolCall(call, iteration) {
|
|
69
|
-
this.session?.appendLog({
|
|
70
|
-
ts: new Date().toISOString(),
|
|
71
|
-
type: "tool_call",
|
|
72
|
-
tool: call.name,
|
|
73
|
-
tool_call_id: call.id,
|
|
74
|
-
args: call.arguments,
|
|
75
|
-
iteration,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
logToolResult(call, result, duration, iteration) {
|
|
79
|
-
this.session?.appendMessage({
|
|
80
|
-
role: "tool",
|
|
81
|
-
content: result.output.slice(0, 500),
|
|
82
|
-
name: call.name,
|
|
83
|
-
timestamp: new Date().toISOString(),
|
|
84
|
-
});
|
|
85
|
-
this.session?.appendLog({
|
|
86
|
-
ts: new Date().toISOString(),
|
|
87
|
-
type: "tool_result",
|
|
88
|
-
tool: call.name,
|
|
89
|
-
tool_call_id: call.id,
|
|
90
|
-
success: result.success,
|
|
91
|
-
content: result.output.slice(0, 1000),
|
|
92
|
-
diff: result.diff,
|
|
93
|
-
duration,
|
|
94
|
-
iteration,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
logCompaction(content, iteration, contextTokens, contextLimit) {
|
|
98
|
-
this.session?.appendLog({
|
|
99
|
-
ts: new Date().toISOString(),
|
|
100
|
-
type: "compaction",
|
|
101
|
-
content,
|
|
102
|
-
iteration,
|
|
103
|
-
...(contextTokens !== undefined ? { contextTokens } : {}),
|
|
104
|
-
...(contextLimit !== undefined ? { contextLimit } : {}),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
logError(message) {
|
|
108
|
-
this.session?.appendLog({
|
|
109
|
-
ts: new Date().toISOString(),
|
|
110
|
-
type: "error",
|
|
111
|
-
content: message,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
logAudit(summary, iteration) {
|
|
115
|
-
this.session?.appendLog({
|
|
116
|
-
ts: new Date().toISOString(),
|
|
117
|
-
type: "audit",
|
|
118
|
-
content: summary,
|
|
119
|
-
iteration,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
package/dist/core/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|