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.
- package/README.md +312 -312
- package/bin/mma.mjs +41 -41
- package/dist/main.js +241 -56
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +1 -1
- package/dist/cli/commands.js +0 -333
- package/dist/cli/completer.js +0 -168
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -140
- package/dist/cli/repl-commands.js +0 -633
- package/dist/cli/repl.js +0 -486
- package/dist/cli/security-commands.js +0 -166
- package/dist/cli/setup.js +0 -249
- package/dist/config/config.js +0 -202
- package/dist/config/defaults.js +0 -100
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -200
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -110
- package/dist/core/agent.js +0 -695
- package/dist/core/bootstrap.js +0 -337
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -55
- package/dist/core/session-logger.js +0 -155
- package/dist/core/types.js +0 -1
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/en.json +0 -525
- package/dist/i18n/index.js +0 -46
- package/dist/i18n/ru.json +0 -525
- 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 -353
- 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 -143
- package/dist/logger/file-log.js +0 -151
- 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 -335
- package/dist/modules/browser/snapshot.js +0 -114
- package/dist/modules/browser/types.js +0 -9
- package/dist/modules/certification/cli.js +0 -176
- package/dist/modules/certification/fact-checker.js +0 -84
- package/dist/modules/certification/loader.js +0 -111
- package/dist/modules/certification/manifest.js +0 -50
- package/dist/modules/certification/runner.js +0 -162
- package/dist/modules/certification/scenarios.js +0 -124
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -349
- package/dist/modules/execution/auditor.js +0 -66
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -779
- package/dist/modules/execution/moe-executor.js +0 -266
- package/dist/modules/execution/plan-coverage.js +0 -68
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-store.js +0 -159
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -85
- package/dist/modules/execution/stuck-detector.js +0 -347
- package/dist/modules/execution/tracker.js +0 -67
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -178
- package/dist/modules/hallucination/confidence.js +0 -59
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -46
- package/dist/modules/hallucination/factual.js +0 -190
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -72
- package/dist/modules/hallucination/llm-judge.js +0 -103
- 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/lsp/client.js +0 -235
- package/dist/modules/lsp/config.js +0 -81
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -68
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -399
- 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 -69
- 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 -226
- 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/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -238
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/registry.js +0 -45
- package/dist/modules/security/audit-log.js +0 -136
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -211
- package/dist/modules/security/content-scanner.js +0 -53
- 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 -209
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -547
- package/dist/modules/security/session-encryption.js +0 -210
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -172
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -228
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -2
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/module.js +0 -130
- 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/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -337
- 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 -79
- package/dist/tools/executor.js +0 -145
- 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 -86
- package/dist/tools/index.js +0 -67
- package/dist/tools/list-dir.js +0 -47
- package/dist/tools/load-skill.js +0 -44
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -85
- 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 -83
- 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 -84
- package/dist/tools/subagent.js +0 -151
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -86
- package/dist/tools/web-fetch.js +0 -98
- package/dist/tools/web-search.js +0 -78
- package/dist/tools/write-file.js +0 -83
- package/dist/ui/box.js +0 -81
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- 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 -204
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
package/dist/core/bootstrap.js
DELETED
|
@@ -1,337 +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, SkillsModule } from "../modules/skills/index";
|
|
19
|
-
import { BrowserModule } from "../modules/browser/index";
|
|
20
|
-
import { LspModule } from "../modules/lsp/index";
|
|
21
|
-
import { IndexerModule } from "../modules/indexer/index";
|
|
22
|
-
import { MCPModule } from "../modules/mcp/index";
|
|
23
|
-
import { MemoryModule } from "../modules/memory/module";
|
|
24
|
-
import { setLocale } from "../i18n/index";
|
|
25
|
-
import { Agent } from "./agent";
|
|
26
|
-
import { homedir } from "os";
|
|
27
|
-
import { join, resolve } from "path";
|
|
28
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
29
|
-
export function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
30
|
-
const now = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
31
|
-
const isWin = profileCompressed.toLowerCase().includes("win32");
|
|
32
|
-
const lines = [
|
|
33
|
-
`You are MMA v2, an AI coding agent for small models (${config.model}). Date: ${now}. Workspace: ${baseDir}. ${profileCompressed}.`,
|
|
34
|
-
`Reply in the user's language. Use tools for file ops (read/write/edit/delete), search (glob/grep), shell (bash), web, subagents, browser, MCP. Explain briefly if not obvious. On tool failure: analyze, fix the call, retry up to 2x with different approaches, then ask the user.`,
|
|
35
|
-
`Design: YAGNI (no unneeded code), KISS (simple over clever), DRY (reuse existing utilities).`,
|
|
36
|
-
];
|
|
37
|
-
if (isWin) {
|
|
38
|
-
lines.push(`Windows (PowerShell): use list_dir/read_file/delete_file/create_dir tools instead of dir/type/del/mkdir. No PowerShell cmdlets (Get-Content, Select-Object, Write-Output), no head/tail/grep/cat. Use forward slashes in paths. CWD: ${baseDir}`);
|
|
39
|
-
}
|
|
40
|
-
// MMA is a Bun-only project (package.json scripts, Bun API in code) — the
|
|
41
|
-
// model should prefer bun over node/tsx/ts-node for running TypeScript
|
|
42
|
-
// files and tests (observed: model wasted 10+ iterations installing tsx
|
|
43
|
-
// instead of running `bun file.ts`).
|
|
44
|
-
lines.push(`Runtime: Bun is available — run TypeScript directly with "bun <file.ts>" and tests with "bun test" (no tsx/ts-node/npm install needed for that).`);
|
|
45
|
-
lines.push(`Bash: use "workdir" param instead of "cd dir && cmd". One command per call. Long-running processes: pass "background: true" (id immediately), otherwise auto-backgrounded after a few seconds — check with process_log.`, `DEVELOPMENT RULES (strict): 1) install deps BEFORE writing source (npm/pip/cargo, verify lockfile exists; never import uninstalled packages); 2) framework/toolkit init BEFORE app code; 3) follow plan sequentially, after each step verify deliverables exist with real content, then "plan update step=N status=done"; 4) verify work on disk + command output — don't assume success; 5) no premature work (no files/imports for future steps); 6) stuck after 2+ failures: STOP, try a different approach, write files directly, ask the user.`, `PLAN QUALITY: each step = CONCRETE deliverables (exact file paths with extensions, exact packages, exact commands). Vague steps ("Setup the project") forbidden. Cover init → deps → framework → code → verification. 5-8 steps.`);
|
|
46
|
-
if (config.autoPlan) {
|
|
47
|
-
lines.push(`Plan rule (MANDATORY): any task creating files, installing packages, or requiring multiple actions MUST create a plan with the "plan" tool BEFORE starting. Each step = a concrete deliverable.`);
|
|
48
|
-
}
|
|
49
|
-
const hasMCP = config.mcpServers &&
|
|
50
|
-
Object.values(config.mcpServers).some((s) => s.enabled !== false);
|
|
51
|
-
if (hasMCP) {
|
|
52
|
-
lines.push(`MCP servers are available — use the named MCP tools (prefixed mcp__) to query external services.`);
|
|
53
|
-
}
|
|
54
|
-
return lines.join("\n");
|
|
55
|
-
}
|
|
56
|
-
export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
57
|
-
const dir = configDir || join(homedir(), ".mma");
|
|
58
|
-
const projectConfigPath = projectDir
|
|
59
|
-
? join(projectDir, ".mmrc")
|
|
60
|
-
: join(process.cwd(), ".mmrc");
|
|
61
|
-
const config = loadConfig({ configDir: dir, projectConfigPath });
|
|
62
|
-
setLocale(config.locale);
|
|
63
|
-
// Update global audit notifier with config
|
|
64
|
-
try {
|
|
65
|
-
const { globalAuditNotifier } = await import("../modules/security/audit-notifier");
|
|
66
|
-
if (config.security?.auditNotifier) {
|
|
67
|
-
globalAuditNotifier.updateConfig(config.security.auditNotifier);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// Ignore if audit notifier is not available
|
|
72
|
-
}
|
|
73
|
-
const logger = new Logger(config.logLevel);
|
|
74
|
-
logger.setLogDir(join(dir, "logs"));
|
|
75
|
-
logger.debug("MMA bootstrap", {
|
|
76
|
-
version: config.version,
|
|
77
|
-
model: config.model,
|
|
78
|
-
});
|
|
79
|
-
if (config.modelLoad.autoLoad) {
|
|
80
|
-
const modelLoader = new ModelLoader(config.provider.baseUrl, logger);
|
|
81
|
-
const loadResult = await modelLoader.ensureModelLoaded({
|
|
82
|
-
model: config.model,
|
|
83
|
-
contextLength: config.contextWindow,
|
|
84
|
-
flashAttention: config.modelLoad.flashAttention,
|
|
85
|
-
offloadKvCacheToGpu: config.modelLoad.offloadKvCacheToGpu,
|
|
86
|
-
autoLoad: config.modelLoad.autoLoad,
|
|
87
|
-
});
|
|
88
|
-
if (!loadResult.success) {
|
|
89
|
-
logger.warn(`Model auto-load failed: ${loadResult.error}. Continuing with manual load.`);
|
|
90
|
-
}
|
|
91
|
-
else if (loadResult.alreadyLoaded) {
|
|
92
|
-
logger.debug(`Model ${config.model} already loaded`);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
logger.info(`Model ${config.model} loaded in ${loadResult.loadTime}s`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const profile = new UserProfile(join(dir));
|
|
99
|
-
profile.load() || profile.collect();
|
|
100
|
-
profile.save();
|
|
101
|
-
const llmProvider = new OpenAICompatProvider({
|
|
102
|
-
model: config.model,
|
|
103
|
-
baseUrl: config.provider.baseUrl,
|
|
104
|
-
apiKey: config.provider.apiKey,
|
|
105
|
-
contextWindow: config.contextWindow,
|
|
106
|
-
retry: config.retry,
|
|
107
|
-
rateLimits: config.security?.rateLimits,
|
|
108
|
-
});
|
|
109
|
-
const baseDir = projectDir ? resolve(projectDir) : process.cwd();
|
|
110
|
-
const projectMapCacheDir = join(baseDir, ".mma");
|
|
111
|
-
const indexerModule = new IndexerModule({
|
|
112
|
-
baseDir,
|
|
113
|
-
cacheDir: projectMapCacheDir,
|
|
114
|
-
});
|
|
115
|
-
try {
|
|
116
|
-
await indexerModule.buildIndex();
|
|
117
|
-
}
|
|
118
|
-
catch (err) {
|
|
119
|
-
logger.warn(`Project indexing failed: ${err.message}`);
|
|
120
|
-
}
|
|
121
|
-
const skillsLoader = new SkillsLoader();
|
|
122
|
-
const builtinDir = join(import.meta.dirname, "skills", "builtin");
|
|
123
|
-
const globalDir = join(homedir(), ".agents", "skills");
|
|
124
|
-
const projectSkillsDir = join(baseDir, ".mma", "skills");
|
|
125
|
-
const availableSkills = skillsLoader.loadFromAllSources(builtinDir, globalDir, projectSkillsDir);
|
|
126
|
-
const skillsBudget = Math.floor(config.contextWindow * config.skills.budget);
|
|
127
|
-
const skillsModule = new SkillsModule(availableSkills, skillsBudget);
|
|
128
|
-
const toolRegistry = new ToolRegistry();
|
|
129
|
-
registerAllTools(toolRegistry, skillsModule);
|
|
130
|
-
const pluginManager = new PluginManager();
|
|
131
|
-
const systemInfoContent = buildSystemInfo(config, baseDir, profile.compress());
|
|
132
|
-
const systemInfoPrompt = {
|
|
133
|
-
content: systemInfoContent,
|
|
134
|
-
priority: "critical",
|
|
135
|
-
essential: true,
|
|
136
|
-
estimatedTokens: Math.ceil(systemInfoContent.length / 4),
|
|
137
|
-
};
|
|
138
|
-
const agentsMdGlobal = join(dir, "AGENTS.md");
|
|
139
|
-
if (!existsSync(agentsMdGlobal)) {
|
|
140
|
-
writeFileSync(agentsMdGlobal, "", "utf-8");
|
|
141
|
-
}
|
|
142
|
-
const sessionDir = join(dir, "sessions");
|
|
143
|
-
const sessionStore = new SessionStore(sessionDir);
|
|
144
|
-
sessionStore.init();
|
|
145
|
-
const sessionManager = new SessionManager(sessionStore, {
|
|
146
|
-
model: config.model,
|
|
147
|
-
contextWindow: config.contextWindow,
|
|
148
|
-
projectDir: baseDir,
|
|
149
|
-
maxSessions: config.session.maxSessions,
|
|
150
|
-
isolation: config.sessionIsolation,
|
|
151
|
-
});
|
|
152
|
-
if (config.session.autoSave && !sessionManager.getActive()) {
|
|
153
|
-
sessionManager.create();
|
|
154
|
-
}
|
|
155
|
-
const tokenCounter = new TokenCounter(config.model);
|
|
156
|
-
const contextManager = new ContextManager(config.contextWindow, config.contextBudget, tokenCounter);
|
|
157
|
-
const toolCtx = {
|
|
158
|
-
config,
|
|
159
|
-
baseDir,
|
|
160
|
-
logger,
|
|
161
|
-
exitOnComplete,
|
|
162
|
-
contextManager,
|
|
163
|
-
sessionId: sessionManager.getActiveMeta()?.id,
|
|
164
|
-
sessionContext: sessionManager.getSessionContext() ?? undefined,
|
|
165
|
-
recursionDepth: 0,
|
|
166
|
-
fileOperationsCount: 0,
|
|
167
|
-
sessionHistory: {
|
|
168
|
-
append: async (type, content) => {
|
|
169
|
-
const meta = sessionManager.getActiveMeta();
|
|
170
|
-
if (!meta)
|
|
171
|
-
return;
|
|
172
|
-
sessionManager.appendMessage({
|
|
173
|
-
role: "tool",
|
|
174
|
-
content: typeof content === "string" ? content : JSON.stringify(content),
|
|
175
|
-
name: type,
|
|
176
|
-
timestamp: new Date().toISOString(),
|
|
177
|
-
});
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
sessionLog: {
|
|
181
|
-
plan: (event, detail, iteration) => {
|
|
182
|
-
sessionManager.appendLog({
|
|
183
|
-
ts: new Date().toISOString(),
|
|
184
|
-
type: "plan",
|
|
185
|
-
tool: event,
|
|
186
|
-
content: detail,
|
|
187
|
-
...(iteration !== undefined ? { iteration } : {}),
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
const toolExecutor = new ToolExecutor(toolRegistry, toolCtx, pluginManager);
|
|
193
|
-
toolCtx.llmProvider = llmProvider;
|
|
194
|
-
toolCtx.toolExecutor = toolExecutor;
|
|
195
|
-
const hallucinationDetector = new HallucinationDetector(baseDir, llmProvider);
|
|
196
|
-
const moduleRegistry = new ModuleRegistry();
|
|
197
|
-
const execModule = new ExecutionModule(baseDir, config.stuckThreshold);
|
|
198
|
-
const activeMeta = sessionManager.getActiveMeta();
|
|
199
|
-
if (activeMeta && activeMeta.messageCount > 0) {
|
|
200
|
-
execModule.restorePlan();
|
|
201
|
-
}
|
|
202
|
-
moduleRegistry.register(execModule);
|
|
203
|
-
const sessionModule = new SessionModule(sessionManager);
|
|
204
|
-
moduleRegistry.register(sessionModule);
|
|
205
|
-
moduleRegistry.register(indexerModule);
|
|
206
|
-
const mcpModule = new MCPModule(config);
|
|
207
|
-
await mcpModule.initialize();
|
|
208
|
-
moduleRegistry.register(mcpModule);
|
|
209
|
-
const memoryModule = new MemoryModule(join(dir, "memory"));
|
|
210
|
-
moduleRegistry.register(memoryModule);
|
|
211
|
-
if (config.browser.enabled) {
|
|
212
|
-
const browserModule = new BrowserModule();
|
|
213
|
-
moduleRegistry.register(browserModule);
|
|
214
|
-
const browserPlugin = browserModule.getPlugin();
|
|
215
|
-
if (browserPlugin) {
|
|
216
|
-
browserPlugin.isBuiltin = true;
|
|
217
|
-
pluginManager.register(browserPlugin);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const lspModule = new LspModule(config.lsp);
|
|
221
|
-
moduleRegistry.register(lspModule);
|
|
222
|
-
const lspPlugin = lspModule.getPlugin();
|
|
223
|
-
if (lspPlugin) {
|
|
224
|
-
lspPlugin.isBuiltin = true;
|
|
225
|
-
pluginManager.register(lspPlugin);
|
|
226
|
-
}
|
|
227
|
-
const moduleTools = moduleRegistry.collectToolDefinitions();
|
|
228
|
-
for (const tool of moduleTools) {
|
|
229
|
-
toolRegistry.register(tool);
|
|
230
|
-
}
|
|
231
|
-
const plugin = execModule.getPlugin();
|
|
232
|
-
if (plugin) {
|
|
233
|
-
plugin.isBuiltin = true;
|
|
234
|
-
pluginManager.register(plugin);
|
|
235
|
-
}
|
|
236
|
-
const sessionPlugin = sessionModule.getPlugin();
|
|
237
|
-
if (sessionPlugin) {
|
|
238
|
-
sessionPlugin.isBuiltin = true;
|
|
239
|
-
pluginManager.register(sessionPlugin);
|
|
240
|
-
}
|
|
241
|
-
const skillsPlugin = skillsModule.getPlugin();
|
|
242
|
-
if (skillsPlugin) {
|
|
243
|
-
skillsPlugin.isBuiltin = true;
|
|
244
|
-
pluginManager.register(skillsPlugin);
|
|
245
|
-
}
|
|
246
|
-
const indexerPlugin = indexerModule.getPlugin();
|
|
247
|
-
if (indexerPlugin) {
|
|
248
|
-
indexerPlugin.isBuiltin = true;
|
|
249
|
-
pluginManager.register(indexerPlugin);
|
|
250
|
-
}
|
|
251
|
-
const mcpPlugin = mcpModule.getPlugin();
|
|
252
|
-
if (mcpPlugin) {
|
|
253
|
-
mcpPlugin.isBuiltin = true;
|
|
254
|
-
pluginManager.register(mcpPlugin);
|
|
255
|
-
}
|
|
256
|
-
pluginManager.register(lintOnWritePlugin);
|
|
257
|
-
pluginManager.register(notifyPlugin);
|
|
258
|
-
const pluginLoader = new PluginLoader();
|
|
259
|
-
const globalPluginsDir = join(homedir(), ".mma", "plugins");
|
|
260
|
-
const projectPluginsDir = join(baseDir, ".mma", "plugins");
|
|
261
|
-
pluginLoader.loadFromDir(globalPluginsDir, pluginManager, logger);
|
|
262
|
-
pluginLoader.loadFromDir(projectPluginsDir, pluginManager, logger);
|
|
263
|
-
contextManager.onCompact = (summary) => {
|
|
264
|
-
const meta = sessionManager.getActiveMeta();
|
|
265
|
-
if (!meta || !config.session.autoSave)
|
|
266
|
-
return;
|
|
267
|
-
sessionManager.appendMessage({
|
|
268
|
-
role: summary.role,
|
|
269
|
-
content: summary.content,
|
|
270
|
-
name: summary.name,
|
|
271
|
-
timestamp: new Date().toISOString(),
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
const agentsMdBlocks = [];
|
|
275
|
-
const skipAgentsMd = noAgentsMd === true;
|
|
276
|
-
if (!skipAgentsMd) {
|
|
277
|
-
const agentsMdCandidates = [
|
|
278
|
-
join(baseDir, "AGENTS.md"),
|
|
279
|
-
join(baseDir, ".mma", "AGENTS.md"),
|
|
280
|
-
join(dir, "AGENTS.md"),
|
|
281
|
-
];
|
|
282
|
-
for (const p of agentsMdCandidates) {
|
|
283
|
-
if (existsSync(p)) {
|
|
284
|
-
const content = readFileSync(p, "utf-8").trim();
|
|
285
|
-
if (content) {
|
|
286
|
-
agentsMdBlocks.push({
|
|
287
|
-
content,
|
|
288
|
-
priority: "high",
|
|
289
|
-
essential: false,
|
|
290
|
-
estimatedTokens: Math.ceil(content.length / 4),
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const promptBlocks = [
|
|
297
|
-
systemInfoPrompt,
|
|
298
|
-
...moduleRegistry.collectPromptBlocks(),
|
|
299
|
-
...agentsMdBlocks,
|
|
300
|
-
];
|
|
301
|
-
const agentDeps = {
|
|
302
|
-
config,
|
|
303
|
-
llmProvider,
|
|
304
|
-
toolExecutor,
|
|
305
|
-
pluginManager,
|
|
306
|
-
contextManager,
|
|
307
|
-
hallucinationDetector,
|
|
308
|
-
logger,
|
|
309
|
-
baseDir,
|
|
310
|
-
promptBlocks,
|
|
311
|
-
getDynamicPromptBlocks: () => {
|
|
312
|
-
const blocks = [];
|
|
313
|
-
const planBlock = execModule.getSystemPromptBlock();
|
|
314
|
-
if (planBlock)
|
|
315
|
-
blocks.push(planBlock);
|
|
316
|
-
const skillsBlock = skillsModule.getSystemPromptBlock();
|
|
317
|
-
if (skillsBlock)
|
|
318
|
-
blocks.push(skillsBlock);
|
|
319
|
-
return blocks;
|
|
320
|
-
},
|
|
321
|
-
finalAudit: () => execModule.runFinalAudit(),
|
|
322
|
-
sessionManager,
|
|
323
|
-
exitOnComplete,
|
|
324
|
-
};
|
|
325
|
-
const agent = new Agent(agentDeps);
|
|
326
|
-
return {
|
|
327
|
-
agent,
|
|
328
|
-
config,
|
|
329
|
-
logger,
|
|
330
|
-
sessionManager,
|
|
331
|
-
skillsModule,
|
|
332
|
-
pluginManager,
|
|
333
|
-
configDir: dir,
|
|
334
|
-
baseDir,
|
|
335
|
-
noAgentsMd: skipAgentsMd,
|
|
336
|
-
};
|
|
337
|
-
}
|
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,155 +0,0 @@
|
|
|
1
|
-
import { setAuditSessionDir } from "../modules/security/audit-log";
|
|
2
|
-
/**
|
|
3
|
-
* Thin wrapper around SessionManager that eliminates repetitive
|
|
4
|
-
* `if (sessionManager)` + `new Date().toISOString()` boilerplate
|
|
5
|
-
* from the agent loop.
|
|
6
|
-
*
|
|
7
|
-
* When constructed, it configures the app logger and audit log to write into
|
|
8
|
-
* the session directory (instead of global ~/.mma/logs/).
|
|
9
|
-
*/
|
|
10
|
-
export class SessionLogger {
|
|
11
|
-
session;
|
|
12
|
-
logger;
|
|
13
|
-
constructor(session, logger) {
|
|
14
|
-
this.session = session;
|
|
15
|
-
this.logger = logger;
|
|
16
|
-
this.bindSessionDir();
|
|
17
|
-
}
|
|
18
|
-
bindSessionDir() {
|
|
19
|
-
const meta = this.session?.getActiveMeta();
|
|
20
|
-
if (!meta)
|
|
21
|
-
return;
|
|
22
|
-
const dir = this.session.getSessionDirectory(meta.id);
|
|
23
|
-
if (this.logger) {
|
|
24
|
-
this.logger.setSessionDir(dir);
|
|
25
|
-
this.logger.initSessionLog(meta.id);
|
|
26
|
-
}
|
|
27
|
-
setAuditSessionDir(dir);
|
|
28
|
-
}
|
|
29
|
-
get active() {
|
|
30
|
-
return !!this.session?.getActive();
|
|
31
|
-
}
|
|
32
|
-
logSystem(content) {
|
|
33
|
-
this.session?.appendLog({
|
|
34
|
-
ts: new Date().toISOString(),
|
|
35
|
-
type: "system",
|
|
36
|
-
content,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
logUser(content) {
|
|
40
|
-
this.session?.appendMessage({
|
|
41
|
-
role: "user",
|
|
42
|
-
content,
|
|
43
|
-
timestamp: new Date().toISOString(),
|
|
44
|
-
});
|
|
45
|
-
this.session?.appendLog({
|
|
46
|
-
ts: new Date().toISOString(),
|
|
47
|
-
type: "user",
|
|
48
|
-
content,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
logAssistant(content, reasoning, toolCalls, iteration) {
|
|
52
|
-
if (reasoning) {
|
|
53
|
-
this.session?.appendLog({
|
|
54
|
-
ts: new Date().toISOString(),
|
|
55
|
-
type: "reasoning",
|
|
56
|
-
content: reasoning,
|
|
57
|
-
iteration,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
this.session?.appendLog({
|
|
61
|
-
ts: new Date().toISOString(),
|
|
62
|
-
type: "assistant",
|
|
63
|
-
content,
|
|
64
|
-
...(toolCalls
|
|
65
|
-
? {
|
|
66
|
-
tool_calls: toolCalls.map((tc) => ({
|
|
67
|
-
id: tc.id,
|
|
68
|
-
name: tc.name,
|
|
69
|
-
arguments: tc.arguments,
|
|
70
|
-
})),
|
|
71
|
-
}
|
|
72
|
-
: {}),
|
|
73
|
-
iteration,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
saveAssistantMessage(content) {
|
|
77
|
-
this.session?.appendMessage({
|
|
78
|
-
role: "assistant",
|
|
79
|
-
content: content.slice(0, 500),
|
|
80
|
-
timestamp: new Date().toISOString(),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
logToolDefs(toolCount, toolNames, iteration) {
|
|
84
|
-
this.session?.appendLog({
|
|
85
|
-
ts: new Date().toISOString(),
|
|
86
|
-
type: "tool_defs",
|
|
87
|
-
toolCount,
|
|
88
|
-
toolNames,
|
|
89
|
-
iteration,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
logToolCall(call, iteration) {
|
|
93
|
-
this.session?.appendLog({
|
|
94
|
-
ts: new Date().toISOString(),
|
|
95
|
-
type: "tool_call",
|
|
96
|
-
tool: call.name,
|
|
97
|
-
tool_call_id: call.id,
|
|
98
|
-
args: call.arguments,
|
|
99
|
-
iteration,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
logToolResult(call, result, duration, iteration) {
|
|
103
|
-
this.session?.appendMessage({
|
|
104
|
-
role: "tool",
|
|
105
|
-
content: result.output.slice(0, 500),
|
|
106
|
-
name: call.name,
|
|
107
|
-
timestamp: new Date().toISOString(),
|
|
108
|
-
});
|
|
109
|
-
this.session?.appendLog({
|
|
110
|
-
ts: new Date().toISOString(),
|
|
111
|
-
type: "tool_result",
|
|
112
|
-
tool: call.name,
|
|
113
|
-
tool_call_id: call.id,
|
|
114
|
-
success: result.success,
|
|
115
|
-
content: result.output.slice(0, 1000),
|
|
116
|
-
diff: result.diff,
|
|
117
|
-
duration,
|
|
118
|
-
iteration,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
logCompaction(content, iteration, contextTokens, contextLimit) {
|
|
122
|
-
this.session?.appendLog({
|
|
123
|
-
ts: new Date().toISOString(),
|
|
124
|
-
type: "compaction",
|
|
125
|
-
content,
|
|
126
|
-
iteration,
|
|
127
|
-
...(contextTokens !== undefined ? { contextTokens } : {}),
|
|
128
|
-
...(contextLimit !== undefined ? { contextLimit } : {}),
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
logError(message) {
|
|
132
|
-
this.session?.appendLog({
|
|
133
|
-
ts: new Date().toISOString(),
|
|
134
|
-
type: "error",
|
|
135
|
-
content: message,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
logAudit(summary, iteration) {
|
|
139
|
-
this.session?.appendLog({
|
|
140
|
-
ts: new Date().toISOString(),
|
|
141
|
-
type: "audit",
|
|
142
|
-
content: summary,
|
|
143
|
-
iteration,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
logPlan(event, detail, iteration) {
|
|
147
|
-
this.session?.appendLog({
|
|
148
|
-
ts: new Date().toISOString(),
|
|
149
|
-
type: "plan",
|
|
150
|
-
content: detail,
|
|
151
|
-
tool: event,
|
|
152
|
-
...(iteration !== undefined ? { iteration } : {}),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
package/dist/core/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/core/workspace.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "fs";
|
|
2
|
-
import { resolve, isAbsolute, join } from "path";
|
|
3
|
-
/** Files/dirs that mark a directory as a project root. */
|
|
4
|
-
const PROJECT_MANIFESTS = [
|
|
5
|
-
"package.json",
|
|
6
|
-
"bun.lockb",
|
|
7
|
-
"bun.lock",
|
|
8
|
-
"yarn.lock",
|
|
9
|
-
"pnpm-lock.yaml",
|
|
10
|
-
"go.mod",
|
|
11
|
-
"Cargo.toml",
|
|
12
|
-
"pyproject.toml",
|
|
13
|
-
"requirements.txt",
|
|
14
|
-
"Gemfile",
|
|
15
|
-
"composer.json",
|
|
16
|
-
];
|
|
17
|
-
/** Immediate subdirectories that are never candidate project roots. */
|
|
18
|
-
const SKIP_DIRS = new Set(["node_modules", "dist", ".git", ".hg", ".svn"]);
|
|
19
|
-
const subdirCache = new Map();
|
|
20
|
-
function scanSubdirs(baseDir) {
|
|
21
|
-
const cached = subdirCache.get(baseDir);
|
|
22
|
-
if (cached)
|
|
23
|
-
return cached;
|
|
24
|
-
let dirs = [];
|
|
25
|
-
try {
|
|
26
|
-
dirs = readdirSync(baseDir, { withFileTypes: true })
|
|
27
|
-
.filter((e) => e.isDirectory() && !e.name.startsWith("."))
|
|
28
|
-
.map((e) => e.name)
|
|
29
|
-
.filter((name) => !SKIP_DIRS.has(name));
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
dirs = [];
|
|
33
|
-
}
|
|
34
|
-
if (dirs.length > 0)
|
|
35
|
-
subdirCache.set(baseDir, dirs);
|
|
36
|
-
return dirs;
|
|
37
|
-
}
|
|
38
|
-
export function hasProjectManifest(dir) {
|
|
39
|
-
return PROJECT_MANIFESTS.some((m) => existsSync(join(dir, m)));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Resolve a file/dir path inside a workspace, tolerating the common case
|
|
43
|
-
* where the agent runs from a parent directory while the actual project
|
|
44
|
-
* lives in a single immediate subdirectory (e.g. baseDir=<repo>,
|
|
45
|
-
* project=<repo>/app). Resolution order:
|
|
46
|
-
* 1. absolute path as-is;
|
|
47
|
-
* 2. baseDir/<p> тАФ project rooted directly at baseDir;
|
|
48
|
-
* 3. <subdir>/<p> for each immediate project subdirectory of baseDir
|
|
49
|
-
* (manifest-bearing subdirectories are preferred).
|
|
50
|
-
* Returns baseDir/<p> as a fallback when nothing exists, so callers that
|
|
51
|
-
* check existsSync() still correctly report the path as missing.
|
|
52
|
-
*/
|
|
53
|
-
export function resolveProjectPath(baseDir, p) {
|
|
54
|
-
const abs = isAbsolute(p) ? p : resolve(baseDir, p);
|
|
55
|
-
if (existsSync(abs))
|
|
56
|
-
return abs;
|
|
57
|
-
// baseDir itself is a project root тАФ paths are relative to it. Probing
|
|
58
|
-
// subdirectories here would match files in unrelated nested packages.
|
|
59
|
-
if (hasProjectManifest(baseDir))
|
|
60
|
-
return abs;
|
|
61
|
-
let fallback = abs;
|
|
62
|
-
for (const name of scanSubdirs(baseDir)) {
|
|
63
|
-
const candidate = resolve(baseDir, name, p);
|
|
64
|
-
if (existsSync(candidate)) {
|
|
65
|
-
if (hasProjectManifest(join(baseDir, name)))
|
|
66
|
-
return candidate;
|
|
67
|
-
if (fallback === abs)
|
|
68
|
-
fallback = candidate;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return fallback;
|
|
72
|
-
}
|
|
73
|
-
/** Clear the internal subdirectory cache (used by tests). */
|
|
74
|
-
export function clearWorkspaceCache() {
|
|
75
|
-
subdirCache.clear();
|
|
76
|
-
}
|