micro-models-agent 0.59.0 → 0.60.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/CHANGELOG.md +578 -564
- package/README.md +358 -358
- package/dist/certification/certifications.json +493 -493
- package/dist/i18n/en.json +732 -718
- package/dist/i18n/ru.json +732 -718
- package/dist/main.js +504 -62
- package/dist/modules/browser/bridge-server.mjs +219 -219
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +51 -51
- package/dist/cli/commands.js +0 -447
- package/dist/cli/completer.js +0 -167
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -153
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/repl-commands.js +0 -761
- package/dist/cli/repl.js +0 -702
- package/dist/cli/run-result.js +0 -33
- package/dist/cli/security-commands.js +0 -164
- package/dist/cli/setup.js +0 -237
- package/dist/config/config.js +0 -276
- package/dist/config/defaults.js +0 -141
- package/dist/config/domains.js +0 -179
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -4
- package/dist/config/security.js +0 -213
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -102
- package/dist/core/agent.js +0 -1018
- package/dist/core/bootstrap.js +0 -481
- package/dist/core/crash-handler.js +0 -51
- package/dist/core/environment.js +0 -199
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -76
- package/dist/core/session-logger.js +0 -251
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -26
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/index.js +0 -46
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -143
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -497
- package/dist/llm/orchestrator.js +0 -200
- 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 -189
- 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/artifacts/store.js +0 -61
- package/dist/modules/browser/actions.js +0 -76
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/browser/index.js +0 -7
- package/dist/modules/browser/module.js +0 -29
- package/dist/modules/browser/session.js +0 -342
- package/dist/modules/browser/snapshot.js +0 -148
- package/dist/modules/browser/types.js +0 -12
- package/dist/modules/certification/cli.js +0 -213
- package/dist/modules/certification/fact-checker.js +0 -82
- package/dist/modules/certification/loader.js +0 -106
- package/dist/modules/certification/manifest.js +0 -58
- package/dist/modules/certification/runner.js +0 -245
- package/dist/modules/certification/scenarios.js +0 -407
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -168
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -440
- package/dist/modules/execution/audit-runners.js +0 -206
- package/dist/modules/execution/auditor.js +0 -218
- package/dist/modules/execution/execution-plugin.js +0 -431
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -625
- package/dist/modules/execution/moe-executor.js +0 -304
- 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 -196
- package/dist/modules/execution/plan-tool.js +0 -677
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -94
- package/dist/modules/execution/stuck-detector.js +0 -746
- package/dist/modules/execution/tracker.js +0 -69
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -235
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/hallucination/confidence.js +0 -66
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -47
- package/dist/modules/hallucination/factual.js +0 -169
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -262
- package/dist/modules/hallucination/llm-judge.js +0 -101
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -40
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -246
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/client.js +0 -389
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/config.js +0 -135
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -260
- package/dist/modules/lsp/probe.js +0 -86
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -144
- 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 -142
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -96
- package/dist/modules/memory/search.js +0 -42
- 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 -56
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -334
- package/dist/modules/plugins/builtin/notify.js +0 -9
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -70
- package/dist/modules/plugins/manager.js +0 -261
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/pricing/index.js +0 -61
- package/dist/modules/pricing/prices.js +0 -129
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -327
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/providers/create.js +0 -22
- package/dist/modules/providers/fallback.js +0 -79
- package/dist/modules/providers/health.js +0 -46
- package/dist/modules/providers/index.js +0 -5
- package/dist/modules/providers/manager.js +0 -161
- package/dist/modules/providers/presets.js +0 -128
- package/dist/modules/providers/registry.js +0 -22
- package/dist/modules/providers/types.js +0 -1
- package/dist/modules/registry.js +0 -48
- 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 -219
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -89
- package/dist/modules/security/encryption.js +0 -242
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -88
- package/dist/modules/security/path-validator.js +0 -203
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -531
- 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 -222
- 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/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -129
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -96
- package/dist/modules/updater/index.js +0 -2
- package/dist/modules/updater/module.js +0 -116
- 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 -33
- package/dist/tools/attach-image.js +0 -101
- package/dist/tools/bash.js +0 -519
- package/dist/tools/browser.js +0 -115
- package/dist/tools/chunk-query.js +0 -100
- package/dist/tools/create-dir.js +0 -56
- package/dist/tools/delete-file.js +0 -63
- package/dist/tools/download-file.js +0 -117
- package/dist/tools/edit-file.js +0 -80
- package/dist/tools/enable-tools.js +0 -59
- package/dist/tools/executor.js +0 -154
- package/dist/tools/file-info.js +0 -47
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -27
- package/dist/tools/grep-tool.js +0 -125
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -78
- package/dist/tools/list-dir.js +0 -49
- package/dist/tools/load-skill.js +0 -43
- package/dist/tools/mcp-call.js +0 -69
- package/dist/tools/move-file.js +0 -86
- package/dist/tools/path-utils.js +0 -101
- package/dist/tools/pipeline-run.js +0 -145
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -40
- package/dist/tools/process-list.js +0 -37
- package/dist/tools/process-log.js +0 -54
- package/dist/tools/question.js +0 -141
- package/dist/tools/read-file.js +0 -179
- package/dist/tools/recall.js +0 -118
- package/dist/tools/registry.js +0 -47
- package/dist/tools/remember.js +0 -68
- package/dist/tools/scope-check.js +0 -32
- package/dist/tools/search-history.js +0 -85
- package/dist/tools/subagent.js +0 -196
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -87
- package/dist/tools/web-fetch.js +0 -119
- package/dist/tools/web-search.js +0 -105
- package/dist/tools/write-file.js +0 -82
- package/dist/ui/box.js +0 -77
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- package/dist/ui/index.js +0 -6
- package/dist/ui/line-editor.js +0 -822
- package/dist/ui/line-math.js +0 -73
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/plan-view.js +0 -103
- package/dist/ui/renderer.js +0 -259
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
package/dist/core/bootstrap.js
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "../config/config";
|
|
2
|
-
import { Logger } from "../logger/app-logger";
|
|
3
|
-
import { ProviderManager } from "../modules/providers/index";
|
|
4
|
-
import { FallbackProvider } from "../modules/providers/fallback";
|
|
5
|
-
import { ModelLoader } from "../llm/model-loader";
|
|
6
|
-
import { ToolRegistry, registerAllTools } from "../tools/index";
|
|
7
|
-
import { buildHiddenToolsBlock } from "../tools/hidden-tools-block";
|
|
8
|
-
import { ToolExecutor } from "../tools/executor";
|
|
9
|
-
import { ModuleRegistry } from "../modules/registry";
|
|
10
|
-
import { PluginManager } from "../modules/plugins/manager";
|
|
11
|
-
import { PluginLoader } from "../modules/plugins/loader";
|
|
12
|
-
import { plugin as lintOnWritePlugin } from "../modules/plugins/builtin/lint-on-write";
|
|
13
|
-
import { plugin as notifyPlugin } from "../modules/plugins/builtin/notify";
|
|
14
|
-
import { ContextManager } from "../modules/context/manager";
|
|
15
|
-
import { TokenCounter } from "../llm/token-counter";
|
|
16
|
-
import { HallucinationDetector } from "../modules/hallucination/detector";
|
|
17
|
-
import { ExecutionModule } from "../modules/execution/module";
|
|
18
|
-
import { SessionStore, SessionManager, SessionModule } from "../modules/session/index";
|
|
19
|
-
import { UserProfile } from "../modules/user-profile/profile";
|
|
20
|
-
import { SkillsLoader, SkillsModule } from "../modules/skills/index";
|
|
21
|
-
import { BrowserModule } from "../modules/browser/index";
|
|
22
|
-
import { LspModule, FileOnlyLogger, DEFAULT_LSP_CONFIG } from "../modules/lsp/index";
|
|
23
|
-
import { runStartupHealthCheck } from "../modules/lsp/startup-check";
|
|
24
|
-
import { IndexerModule } from "../modules/indexer/index";
|
|
25
|
-
import { MCPModule } from "../modules/mcp/index";
|
|
26
|
-
import { MemoryModule } from "../modules/memory/module";
|
|
27
|
-
import { MemoryStore } from "../modules/memory/store";
|
|
28
|
-
import { setLocale } from "../i18n/index";
|
|
29
|
-
import { Agent } from "./agent";
|
|
30
|
-
import { homedir } from "os";
|
|
31
|
-
import { join, resolve } from "path";
|
|
32
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
33
|
-
import { readMmaVersion } from "./version";
|
|
34
|
-
import { collectEnvironment, logEnvironment } from "./environment";
|
|
35
|
-
export function buildSystemInfo(config, baseDir, profileCompressed) {
|
|
36
|
-
const now = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
37
|
-
const isWin = profileCompressed.toLowerCase().includes("win32");
|
|
38
|
-
const lines = [
|
|
39
|
-
`You are MMA v2, an AI coding agent for small models (${config.model}). Date: ${now}. Workspace: ${baseDir}. ${profileCompressed}.`,
|
|
40
|
-
`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.`,
|
|
41
|
-
`Design: YAGNI (no unneeded code), KISS (simple over clever), DRY (reuse existing utilities).`,
|
|
42
|
-
`SCOPE DISCIPLINE: do ONLY what the user explicitly asked — no extra features, files, refactors, "improvements", or fixes beyond the request. Read-only requests ("расскажи", "покажи", "объясни", "check") mean READ-ONLY: inspect and answer, never create/modify/delete anything. If the task is ambiguous (what to create, where, which variant) or the request implies action on something you could not find — STOP and ask the user a short clarifying question in plain text instead of guessing.`,
|
|
43
|
-
`NOT FOUND ≠ MISSING PROJECT: a "not found" tool result means the PATH was wrong (typo, different location), not that the project does not exist. Before creating or scaffolding ANY project/files: first run list_dir on the working directory to see what is already there; if a user-named path is not found, list its parent directory to locate the real path. NEVER create a new project when the user asked about an existing one — inspect first, create only after confirming the workspace is empty AND the user asked for creation.`,
|
|
44
|
-
];
|
|
45
|
-
if (isWin) {
|
|
46
|
-
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}`);
|
|
47
|
-
}
|
|
48
|
-
// MMA is a Bun-only project (package.json scripts, Bun API in code) — the
|
|
49
|
-
// model should prefer bun over node/tsx/ts-node for running TypeScript
|
|
50
|
-
// files and tests (observed: model wasted 10+ iterations installing tsx
|
|
51
|
-
// instead of running `bun file.ts`).
|
|
52
|
-
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).`);
|
|
53
|
-
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.`, `VERIFY EVERY WRITE: after write_file or edit_file, if the tool result contains NO [LSP errors], [LSP warnings], [Syntax check failed], or [Project typecheck failed] feedback, call the "lsp_check" tool on the file you just wrote BEFORE marking the step done. Never assume a written file is valid — prove it.`, `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.`, `For "check/fix errors" tasks, each verification step must name the exact command that proves the errors are gone — "bun run build", "bun test", or the "lsp_check" tool — and the step is done only after that check reports clean.`);
|
|
54
|
-
if (config.autoPlan) {
|
|
55
|
-
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.`);
|
|
56
|
-
}
|
|
57
|
-
// When a bug is described in terms of runtime behavior (what happens when
|
|
58
|
-
// the app runs), the fix is only provable by REPRODUCING it — running the
|
|
59
|
-
// app/build/browser and comparing against actual output. The model decides
|
|
60
|
-
// when this applies (no keyword classification). Stale dev servers started
|
|
61
|
-
// before a config/deps change keep the OLD pipeline in memory and still
|
|
62
|
-
// throw the original error (observed: old vite on 5173-5176 kept failing
|
|
63
|
-
// postcss after the fix was on disk, while a fresh server on 5177 was
|
|
64
|
-
// clean) — the fix is only real when the USER's running server is clean.
|
|
65
|
-
lines.push(`Runtime verification: when a bug is described in terms of runtime behavior (what happens when the app runs), reproduce it — run the app / build / browser tool — and confirm the fix against actual runtime output before calling "plan update step=N status=done". Check existing servers first with process_list/process_log: a stale dev server started BEFORE your change still runs the old pipeline and keeps failing even after the files on disk are fixed. Restart or kill it (process_kill) and verify the exact endpoint/port the user reported — a fresh server on a new port does NOT prove the user's error is gone.`);
|
|
66
|
-
// Security rules: when security is enabled the model should know the
|
|
67
|
-
// restrictions up front — a blocked call costs an iteration, while this
|
|
68
|
-
// block costs ~100 tokens once. Kept compact and capped so a long user
|
|
69
|
-
// blacklist cannot blow the system budget.
|
|
70
|
-
const sec = config.security;
|
|
71
|
-
if (sec?.enabled) {
|
|
72
|
-
const secLines = [`SECURITY RESTRICTIONS (enforced — blocked calls return "[SECURITY BLOCKED]", do not retry them):`];
|
|
73
|
-
if (sec.bash?.enabled && sec.bash.blacklist.length > 0) {
|
|
74
|
-
const cmds = sec.bash.blacklist.slice(0, 15).join(", ");
|
|
75
|
-
secLines.push(`Forbidden bash commands: ${cmds}${sec.bash.blacklist.length > 15 ? ", …" : ""}.`);
|
|
76
|
-
if (sec.bash.whitelist.length > 0) {
|
|
77
|
-
secLines.push(`Only whitelisted bash commands are allowed: ${sec.bash.whitelist.slice(0, 15).join(", ")}.`);
|
|
78
|
-
}
|
|
79
|
-
if (sec.bash.blockDangerousFlags) {
|
|
80
|
-
secLines.push(`Pipes/redirects/chaining (| > >> ; &&) in bash are blocked — one plain command per call.`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (sec.paths?.enabled && sec.paths.denied.length > 0) {
|
|
84
|
-
const paths = sec.paths.denied.slice(0, 10).join(", ");
|
|
85
|
-
secLines.push(`Denied paths (read/write): ${paths}${sec.paths.denied.length > 10 ? ", …" : ""}.`);
|
|
86
|
-
}
|
|
87
|
-
if (sec.network?.enabled && sec.network.deniedDomains.length > 0) {
|
|
88
|
-
const domains = sec.network.deniedDomains.slice(0, 10).join(", ");
|
|
89
|
-
secLines.push(`Denied network domains: ${domains}${sec.network.deniedDomains.length > 10 ? ", …" : ""}.`);
|
|
90
|
-
}
|
|
91
|
-
if (secLines.length > 1) {
|
|
92
|
-
lines.push(...secLines);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const hasMCP = config.mcpServers && Object.values(config.mcpServers).some((s) => s.enabled !== false);
|
|
96
|
-
if (hasMCP) {
|
|
97
|
-
lines.push(`MCP servers are available — use the named MCP tools (prefixed mcp__) to query external services.`);
|
|
98
|
-
}
|
|
99
|
-
return lines.join("\n");
|
|
100
|
-
}
|
|
101
|
-
export async function bootstrap(configDir, projectDir, noAgentsMd, exitOnComplete) {
|
|
102
|
-
const dir = configDir || process.env.MMA_CONFIG_DIR || join(homedir(), ".mma");
|
|
103
|
-
const projectConfigPath = projectDir ? join(projectDir, ".mmrc") : join(process.cwd(), ".mmrc");
|
|
104
|
-
const { config, legacyDetected } = loadConfig({ configDir: dir, projectConfigPath });
|
|
105
|
-
setLocale(config.locale);
|
|
106
|
-
// Update global audit notifier with config
|
|
107
|
-
try {
|
|
108
|
-
const { globalAuditNotifier } = await import("../modules/security/audit-notifier");
|
|
109
|
-
if (config.security?.auditNotifier) {
|
|
110
|
-
globalAuditNotifier.updateConfig(config.security.auditNotifier);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
// Ignore if audit notifier is not available
|
|
115
|
-
}
|
|
116
|
-
const logger = new Logger(config.logLevel);
|
|
117
|
-
logger.setLogDir(join(dir, "logs"));
|
|
118
|
-
logger.debug("MMA bootstrap", {
|
|
119
|
-
version: config.version,
|
|
120
|
-
model: config.model,
|
|
121
|
-
});
|
|
122
|
-
if (config.modelLoad.autoLoad) {
|
|
123
|
-
const modelLoader = new ModelLoader(config.provider.baseUrl, logger);
|
|
124
|
-
const loadResult = await modelLoader.ensureModelLoaded({
|
|
125
|
-
model: config.model,
|
|
126
|
-
contextLength: config.contextWindow,
|
|
127
|
-
flashAttention: config.modelLoad.flashAttention,
|
|
128
|
-
offloadKvCacheToGpu: config.modelLoad.offloadKvCacheToGpu,
|
|
129
|
-
autoLoad: config.modelLoad.autoLoad,
|
|
130
|
-
});
|
|
131
|
-
if (!loadResult.success) {
|
|
132
|
-
logger.warn(`Model auto-load failed: ${loadResult.error}. Continuing with manual load.`);
|
|
133
|
-
}
|
|
134
|
-
else if (loadResult.alreadyLoaded) {
|
|
135
|
-
logger.debug(`Model ${config.model} already loaded`);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
logger.info(`Model ${config.model} loaded in ${loadResult.loadTime}s`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const profile = new UserProfile(join(dir));
|
|
142
|
-
profile.load() || profile.collect();
|
|
143
|
-
profile.save();
|
|
144
|
-
// Multi-provider manager (Phase 2). Built from the (possibly legacy flat)
|
|
145
|
-
// config; the active provider is resolved through it. The initial provider
|
|
146
|
-
// comes from the manager so the active entry is honored on startup.
|
|
147
|
-
const providerManager = new ProviderManager(config.provider, {
|
|
148
|
-
contextWindow: config.contextWindow,
|
|
149
|
-
retry: config.retry,
|
|
150
|
-
rateLimits: config.security?.rateLimits,
|
|
151
|
-
});
|
|
152
|
-
providerManager.setModel(config.model);
|
|
153
|
-
let llmProvider = providerManager.active;
|
|
154
|
-
// Phase 4.2: transparent failover to the next configured provider on
|
|
155
|
-
// 429/5xx/network errors (only with multiple entries + fallback: true).
|
|
156
|
-
if (config.provider.fallback && providerManager.listNames().length > 1) {
|
|
157
|
-
llmProvider = new FallbackProvider(providerManager, (from, to, error) => {
|
|
158
|
-
logger.warn(`provider failover: ${from} -> ${to} (${error.message.slice(0, 120)})`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
const baseDir = projectDir ? resolve(projectDir) : process.cwd();
|
|
162
|
-
// Cross-device diagnosis: log a full environment report (OS, runtime,
|
|
163
|
-
// engines, PATH tools, provider/retry, playwright) at every startup.
|
|
164
|
-
const envReport = collectEnvironment({
|
|
165
|
-
configDir: dir,
|
|
166
|
-
baseDir,
|
|
167
|
-
config,
|
|
168
|
-
scanTools: process.env.NODE_ENV !== "test",
|
|
169
|
-
});
|
|
170
|
-
logEnvironment(envReport, logger);
|
|
171
|
-
for (const warning of envReport.warnings) {
|
|
172
|
-
logger.warn(warning);
|
|
173
|
-
}
|
|
174
|
-
const projectMapCacheDir = join(baseDir, ".mma");
|
|
175
|
-
const indexerModule = new IndexerModule({
|
|
176
|
-
baseDir,
|
|
177
|
-
cacheDir: projectMapCacheDir,
|
|
178
|
-
});
|
|
179
|
-
try {
|
|
180
|
-
await indexerModule.buildIndex();
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
logger.warn(`Project indexing failed: ${err.message}`);
|
|
184
|
-
}
|
|
185
|
-
const skillsLoader = new SkillsLoader();
|
|
186
|
-
const builtinDir = join(import.meta.dirname, "skills", "builtin");
|
|
187
|
-
const globalDir = join(homedir(), ".agents", "skills");
|
|
188
|
-
const projectSkillsDir = join(baseDir, ".mma", "skills");
|
|
189
|
-
const availableSkills = skillsLoader.loadFromAllSources(builtinDir, globalDir, projectSkillsDir);
|
|
190
|
-
const skillsBudget = Math.floor(config.contextWindow * config.skills.budget);
|
|
191
|
-
const skillsModule = new SkillsModule(availableSkills, skillsBudget);
|
|
192
|
-
const toolRegistry = new ToolRegistry();
|
|
193
|
-
registerAllTools(toolRegistry, skillsModule, {
|
|
194
|
-
enableOnDemand: config.tools?.enableOnDemand,
|
|
195
|
-
});
|
|
196
|
-
const pluginManager = new PluginManager();
|
|
197
|
-
const systemInfoContent = buildSystemInfo(config, baseDir, profile.compress());
|
|
198
|
-
const systemInfoPrompt = {
|
|
199
|
-
content: systemInfoContent,
|
|
200
|
-
priority: "critical",
|
|
201
|
-
essential: true,
|
|
202
|
-
estimatedTokens: Math.ceil(systemInfoContent.length / 4),
|
|
203
|
-
};
|
|
204
|
-
const agentsMdGlobal = join(dir, "AGENTS.md");
|
|
205
|
-
if (!existsSync(agentsMdGlobal)) {
|
|
206
|
-
writeFileSync(agentsMdGlobal, "", "utf-8");
|
|
207
|
-
}
|
|
208
|
-
const sessionDir = join(dir, "sessions");
|
|
209
|
-
const sessionStore = new SessionStore(sessionDir);
|
|
210
|
-
sessionStore.init();
|
|
211
|
-
const sessionManager = new SessionManager(sessionStore, {
|
|
212
|
-
model: config.model,
|
|
213
|
-
contextWindow: config.contextWindow,
|
|
214
|
-
projectDir: baseDir,
|
|
215
|
-
maxSessions: config.session.maxSessions,
|
|
216
|
-
isolation: config.sessionIsolation,
|
|
217
|
-
});
|
|
218
|
-
if (config.session.autoSave && !sessionManager.getActive()) {
|
|
219
|
-
sessionManager.create();
|
|
220
|
-
}
|
|
221
|
-
const tokenCounter = new TokenCounter(config.model);
|
|
222
|
-
// Mutable set of active tool tags, shared between the agent loop and the
|
|
223
|
-
// `enable_tools` tool. The loop re-reads it every iteration to recompute the
|
|
224
|
-
// LLM-visible tool set; enable_tools pushes tags into it. When on-demand
|
|
225
|
-
// enabling is disabled the tag set stays empty, which restores the legacy
|
|
226
|
-
// all-tools behavior (getAllForLLM returns everything for empty tags).
|
|
227
|
-
const enableOnDemand = config.tools?.enableOnDemand !== false;
|
|
228
|
-
const activeToolTags = enableOnDemand
|
|
229
|
-
? config.tools?.defaultTags
|
|
230
|
-
? [...config.tools.defaultTags]
|
|
231
|
-
: []
|
|
232
|
-
: [];
|
|
233
|
-
const contextManager = new ContextManager(config.contextWindow, config.contextBudget, tokenCounter);
|
|
234
|
-
const toolCtx = {
|
|
235
|
-
config,
|
|
236
|
-
baseDir,
|
|
237
|
-
logger,
|
|
238
|
-
exitOnComplete,
|
|
239
|
-
contextManager,
|
|
240
|
-
activeToolTags,
|
|
241
|
-
recursionDepth: 0,
|
|
242
|
-
fileOperationsCount: 0,
|
|
243
|
-
sessionHistory: {
|
|
244
|
-
append: async (type, content) => {
|
|
245
|
-
const meta = sessionManager.getActiveMeta();
|
|
246
|
-
if (!meta)
|
|
247
|
-
return;
|
|
248
|
-
sessionManager.appendMessage({
|
|
249
|
-
role: "tool",
|
|
250
|
-
content: typeof content === "string" ? content : JSON.stringify(content),
|
|
251
|
-
name: type,
|
|
252
|
-
timestamp: new Date().toISOString(),
|
|
253
|
-
});
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
sessionLog: {
|
|
257
|
-
plan: (event, detail, iteration) => {
|
|
258
|
-
sessionManager.appendLog({
|
|
259
|
-
ts: new Date().toISOString(),
|
|
260
|
-
type: "plan",
|
|
261
|
-
tool: event,
|
|
262
|
-
content: detail,
|
|
263
|
-
...(iteration !== undefined ? { iteration } : {}),
|
|
264
|
-
});
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
// `sessionId`/`sessionContext` are exposed as LIVE getters over the session
|
|
269
|
-
// manager instead of being captured once at bootstrap. Capturing the values
|
|
270
|
-
// pinned them to the session active at startup, so after a REPL /new or
|
|
271
|
-
// /resume the new session's audit.jsonl entries were tagged with the
|
|
272
|
-
// PREVIOUS session's id (observed: ses_msyghz8w audit entries carrying
|
|
273
|
-
// ses_msyg892p_78kqhc) while sessionHistory kept reading the live meta.
|
|
274
|
-
// Everything that consumes ctx.sessionId — audit log, process registry,
|
|
275
|
-
// file-ops counters — now always sees the session that is actually active.
|
|
276
|
-
Object.defineProperty(toolCtx, "sessionId", {
|
|
277
|
-
get: () => sessionManager.getActiveMeta()?.id,
|
|
278
|
-
configurable: true,
|
|
279
|
-
});
|
|
280
|
-
Object.defineProperty(toolCtx, "sessionContext", {
|
|
281
|
-
get: () => sessionManager.getSessionContext() ?? undefined,
|
|
282
|
-
configurable: true,
|
|
283
|
-
});
|
|
284
|
-
const toolExecutor = new ToolExecutor(toolRegistry, toolCtx, pluginManager);
|
|
285
|
-
toolCtx.llmProvider = llmProvider;
|
|
286
|
-
toolCtx.toolExecutor = toolExecutor;
|
|
287
|
-
const hallucinationDetector = new HallucinationDetector(baseDir, llmProvider);
|
|
288
|
-
const moduleRegistry = new ModuleRegistry();
|
|
289
|
-
const execModule = new ExecutionModule(baseDir, config.stuckThreshold, config.errorWebSearch?.threshold ?? 5);
|
|
290
|
-
// A plan in .mma/plans/active.json is PROJECT state, not session state —
|
|
291
|
-
// restore it in every session so `plan show` works and the checklist is
|
|
292
|
-
// visible. Nothing is printed unprompted: the REPL renders the checklist
|
|
293
|
-
// only on plan/todo tool events.
|
|
294
|
-
execModule.restorePlan();
|
|
295
|
-
moduleRegistry.register(execModule);
|
|
296
|
-
execModule.setHallucinationDetector(hallucinationDetector);
|
|
297
|
-
const sessionModule = new SessionModule(sessionManager);
|
|
298
|
-
moduleRegistry.register(sessionModule);
|
|
299
|
-
moduleRegistry.register(indexerModule);
|
|
300
|
-
const mcpModule = new MCPModule(config);
|
|
301
|
-
await mcpModule.initialize();
|
|
302
|
-
moduleRegistry.register(mcpModule);
|
|
303
|
-
const memoryStore = new MemoryStore(join(dir, "memory"));
|
|
304
|
-
const memoryModule = new MemoryModule(memoryStore);
|
|
305
|
-
moduleRegistry.register(memoryModule);
|
|
306
|
-
if (config.browser.enabled) {
|
|
307
|
-
const browserModule = new BrowserModule();
|
|
308
|
-
moduleRegistry.register(browserModule);
|
|
309
|
-
const browserPlugin = browserModule.getPlugin();
|
|
310
|
-
if (browserPlugin) {
|
|
311
|
-
browserPlugin.isBuiltin = true;
|
|
312
|
-
pluginManager.register(browserPlugin);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
const lspLogger = new FileOnlyLogger(logger);
|
|
316
|
-
const lspModule = new LspModule(config.lsp, undefined, lspLogger);
|
|
317
|
-
moduleRegistry.register(lspModule);
|
|
318
|
-
const lspPlugin = lspModule.getPlugin();
|
|
319
|
-
if (lspPlugin) {
|
|
320
|
-
lspPlugin.isBuiltin = true;
|
|
321
|
-
pluginManager.register(lspPlugin);
|
|
322
|
-
}
|
|
323
|
-
// Startup health check: scan project for existing errors so the model
|
|
324
|
-
// knows the baseline before it starts working. Skip for one-shot runs and
|
|
325
|
-
// test environments. Started in the background (never awaited) so the REPL
|
|
326
|
-
// banner is not blocked by `npx tsc` on the whole project; the Agent awaits
|
|
327
|
-
// it before the first LLM call via `lazyPromptBlocks` (already resolved by
|
|
328
|
-
// the time the user types in the interactive REPL).
|
|
329
|
-
let startupCheckBlock = null;
|
|
330
|
-
const startupCheckPromise = !exitOnComplete && process.env.NODE_ENV !== "test"
|
|
331
|
-
? runStartupHealthCheck(config.lsp ?? DEFAULT_LSP_CONFIG, baseDir, { logger: lspLogger })
|
|
332
|
-
: Promise.resolve(null);
|
|
333
|
-
const moduleTools = moduleRegistry.collectToolDefinitions();
|
|
334
|
-
for (const tool of moduleTools) {
|
|
335
|
-
toolRegistry.register(tool);
|
|
336
|
-
}
|
|
337
|
-
const plugin = execModule.getPlugin();
|
|
338
|
-
if (plugin) {
|
|
339
|
-
plugin.isBuiltin = true;
|
|
340
|
-
pluginManager.register(plugin);
|
|
341
|
-
}
|
|
342
|
-
const sessionPlugin = sessionModule.getPlugin();
|
|
343
|
-
if (sessionPlugin) {
|
|
344
|
-
sessionPlugin.isBuiltin = true;
|
|
345
|
-
pluginManager.register(sessionPlugin);
|
|
346
|
-
}
|
|
347
|
-
const skillsPlugin = skillsModule.getPlugin();
|
|
348
|
-
if (skillsPlugin) {
|
|
349
|
-
skillsPlugin.isBuiltin = true;
|
|
350
|
-
pluginManager.register(skillsPlugin);
|
|
351
|
-
}
|
|
352
|
-
const indexerPlugin = indexerModule.getPlugin();
|
|
353
|
-
if (indexerPlugin) {
|
|
354
|
-
indexerPlugin.isBuiltin = true;
|
|
355
|
-
pluginManager.register(indexerPlugin);
|
|
356
|
-
}
|
|
357
|
-
const mcpPlugin = mcpModule.getPlugin();
|
|
358
|
-
if (mcpPlugin) {
|
|
359
|
-
mcpPlugin.isBuiltin = true;
|
|
360
|
-
pluginManager.register(mcpPlugin);
|
|
361
|
-
}
|
|
362
|
-
pluginManager.register(lintOnWritePlugin);
|
|
363
|
-
pluginManager.register(notifyPlugin);
|
|
364
|
-
const pluginLoader = new PluginLoader();
|
|
365
|
-
const globalPluginsDir = join(homedir(), ".mma", "plugins");
|
|
366
|
-
const projectPluginsDir = join(baseDir, ".mma", "plugins");
|
|
367
|
-
const mmaVersion = readMmaVersion();
|
|
368
|
-
pluginLoader.loadFromDir(globalPluginsDir, pluginManager, logger, {
|
|
369
|
-
source: "global",
|
|
370
|
-
mmaVersion,
|
|
371
|
-
});
|
|
372
|
-
pluginLoader.loadFromDir(projectPluginsDir, pluginManager, logger, {
|
|
373
|
-
source: "project",
|
|
374
|
-
mmaVersion,
|
|
375
|
-
});
|
|
376
|
-
contextManager.onCompact = (summary) => {
|
|
377
|
-
const meta = sessionManager.getActiveMeta();
|
|
378
|
-
if (!meta || !config.session.autoSave)
|
|
379
|
-
return;
|
|
380
|
-
sessionManager.appendMessage({
|
|
381
|
-
role: summary.role,
|
|
382
|
-
content: summary.content,
|
|
383
|
-
name: summary.name,
|
|
384
|
-
timestamp: new Date().toISOString(),
|
|
385
|
-
});
|
|
386
|
-
};
|
|
387
|
-
// Carry the active plan (id, progress, current step) into the compaction
|
|
388
|
-
// summary so a 9B model doesn't re-create the plan from scratch right after
|
|
389
|
-
// compaction (observed: ses_msvuao0h — plan_e07pb2 (1/6) discarded for a
|
|
390
|
-
// fresh plan_xzq9xe the same iteration the old plan was still visible).
|
|
391
|
-
contextManager.setPlanSummaryProvider(() => execModule.getPlanSummary());
|
|
392
|
-
const agentsMdBlocks = [];
|
|
393
|
-
const skipAgentsMd = noAgentsMd === true;
|
|
394
|
-
if (!skipAgentsMd) {
|
|
395
|
-
const agentsMdCandidates = [
|
|
396
|
-
join(baseDir, "AGENTS.md"),
|
|
397
|
-
join(baseDir, ".mma", "AGENTS.md"),
|
|
398
|
-
join(dir, "AGENTS.md"),
|
|
399
|
-
];
|
|
400
|
-
for (const p of agentsMdCandidates) {
|
|
401
|
-
if (existsSync(p)) {
|
|
402
|
-
const content = readFileSync(p, "utf-8").trim();
|
|
403
|
-
if (content) {
|
|
404
|
-
agentsMdBlocks.push({
|
|
405
|
-
content,
|
|
406
|
-
priority: "high",
|
|
407
|
-
essential: false,
|
|
408
|
-
estimatedTokens: Math.ceil(content.length / 4),
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
const promptBlocks = [
|
|
415
|
-
systemInfoPrompt,
|
|
416
|
-
...moduleRegistry.collectPromptBlocks(["indexer"]),
|
|
417
|
-
...agentsMdBlocks,
|
|
418
|
-
];
|
|
419
|
-
const agentDeps = {
|
|
420
|
-
config,
|
|
421
|
-
llmProvider,
|
|
422
|
-
toolExecutor,
|
|
423
|
-
pluginManager,
|
|
424
|
-
contextManager,
|
|
425
|
-
hallucinationDetector,
|
|
426
|
-
logger,
|
|
427
|
-
baseDir,
|
|
428
|
-
toolTags: activeToolTags,
|
|
429
|
-
promptBlocks,
|
|
430
|
-
envReport,
|
|
431
|
-
getDynamicPromptBlocks: () => {
|
|
432
|
-
const blocks = [];
|
|
433
|
-
const planBlock = execModule.getSystemPromptBlock();
|
|
434
|
-
if (planBlock)
|
|
435
|
-
blocks.push(planBlock);
|
|
436
|
-
const skillsBlock = skillsModule.getSystemPromptBlock();
|
|
437
|
-
if (skillsBlock)
|
|
438
|
-
blocks.push(skillsBlock);
|
|
439
|
-
const mapBlock = indexerModule.getSystemPromptBlock();
|
|
440
|
-
if (mapBlock)
|
|
441
|
-
blocks.push(mapBlock);
|
|
442
|
-
const hiddenToolsBlock = buildHiddenToolsBlock(toolRegistry.getAll(), activeToolTags);
|
|
443
|
-
if (hiddenToolsBlock) {
|
|
444
|
-
blocks.push({
|
|
445
|
-
content: hiddenToolsBlock,
|
|
446
|
-
priority: "low",
|
|
447
|
-
essential: false,
|
|
448
|
-
estimatedTokens: Math.ceil(hiddenToolsBlock.length / 4),
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
return blocks;
|
|
452
|
-
},
|
|
453
|
-
finalAudit: () => execModule.runFinalAudit(),
|
|
454
|
-
lazyPromptBlocks: async () => {
|
|
455
|
-
if (startupCheckBlock)
|
|
456
|
-
return [startupCheckBlock];
|
|
457
|
-
startupCheckBlock = (await startupCheckPromise) ?? null;
|
|
458
|
-
return startupCheckBlock ? [startupCheckBlock] : [];
|
|
459
|
-
},
|
|
460
|
-
sessionManager,
|
|
461
|
-
memoryStore,
|
|
462
|
-
moduleRegistry,
|
|
463
|
-
exitOnComplete,
|
|
464
|
-
};
|
|
465
|
-
const agent = new Agent(agentDeps);
|
|
466
|
-
return {
|
|
467
|
-
agent,
|
|
468
|
-
config,
|
|
469
|
-
logger,
|
|
470
|
-
sessionManager,
|
|
471
|
-
skillsModule,
|
|
472
|
-
pluginManager,
|
|
473
|
-
execModule,
|
|
474
|
-
toolCtx,
|
|
475
|
-
configDir: dir,
|
|
476
|
-
baseDir,
|
|
477
|
-
noAgentsMd: skipAgentsMd,
|
|
478
|
-
envReport,
|
|
479
|
-
legacyDetected,
|
|
480
|
-
};
|
|
481
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { collectEnvironment } from "./environment";
|
|
5
|
-
import { sanitizeLogMessage } from "../modules/security/data-sanitizer";
|
|
6
|
-
import { t } from "../i18n/index";
|
|
7
|
-
export const CRASH_LOG_DIR = join(homedir(), ".mma", "logs");
|
|
8
|
-
export const CRASH_LOG_FILE = "crash.jsonl";
|
|
9
|
-
/** Build a sanitized crash entry. Environment is captured at crash time (no tool scan). */
|
|
10
|
-
export function formatCrashEntry(type, err) {
|
|
11
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
12
|
-
const stack = err instanceof Error && err.stack ? err.stack : message;
|
|
13
|
-
return {
|
|
14
|
-
ts: new Date().toISOString(),
|
|
15
|
-
type,
|
|
16
|
-
message: sanitizeLogMessage(message),
|
|
17
|
-
stack: sanitizeLogMessage(stack),
|
|
18
|
-
environment: collectEnvironment({ configDir: homedir(), scanTools: false }),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export function writeCrashEntry(dir, entry) {
|
|
22
|
-
try {
|
|
23
|
-
mkdirSync(dir, { recursive: true });
|
|
24
|
-
appendFileSync(join(dir, CRASH_LOG_FILE), JSON.stringify(entry) + "\n", "utf-8");
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// Best effort — never crash while reporting a crash
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
let installed = false;
|
|
31
|
-
/**
|
|
32
|
-
* Global crash handlers. uncaughtException is logged + re-raised (exit 1 so the
|
|
33
|
-
* process never continues in a broken state); unhandledRejection is logged only
|
|
34
|
-
* (the event loop keeps running). Entries land in ~/.mma/logs/crash.jsonl.
|
|
35
|
-
*/
|
|
36
|
-
export function installCrashHandlers() {
|
|
37
|
-
if (installed)
|
|
38
|
-
return;
|
|
39
|
-
installed = true;
|
|
40
|
-
process.on("uncaughtException", (err) => {
|
|
41
|
-
const entry = formatCrashEntry("uncaughtException", err);
|
|
42
|
-
writeCrashEntry(CRASH_LOG_DIR, entry);
|
|
43
|
-
process.stderr.write(`${t("env.crash_stderr", { type: entry.type, message: entry.message })}\n`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
});
|
|
46
|
-
process.on("unhandledRejection", (reason) => {
|
|
47
|
-
const entry = formatCrashEntry("unhandledRejection", reason);
|
|
48
|
-
writeCrashEntry(CRASH_LOG_DIR, entry);
|
|
49
|
-
process.stderr.write(`${t("env.crash_stderr", { type: entry.type, message: entry.message })}\n`);
|
|
50
|
-
});
|
|
51
|
-
}
|