micro-models-agent 0.39.0 → 0.40.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/bin/mma.mjs +41 -41
- package/dist/cli/commands.js +116 -3
- package/dist/cli/main.js +35 -8
- package/dist/cli/repl-commands.js +633 -0
- package/dist/cli/repl.js +110 -611
- package/dist/cli/setup.js +32 -12
- package/dist/config/config.js +46 -30
- package/dist/config/defaults.js +10 -1
- package/dist/config/security.js +15 -8
- package/dist/core/agent-moe.js +24 -12
- package/dist/core/agent.js +281 -47
- package/dist/core/bootstrap.js +52 -36
- package/dist/core/session-logger.js +35 -2
- package/dist/core/workspace.js +76 -0
- package/dist/i18n/en.json +79 -15
- package/dist/i18n/index.js +12 -9
- package/dist/i18n/ru.json +79 -15
- package/dist/index.js +13 -13
- package/dist/llm/openai-compat.js +39 -10
- package/dist/logger/app-logger.js +83 -16
- package/dist/logger/file-log.js +151 -0
- package/dist/main.js +537 -284
- package/dist/modules/browser/bridge-server.mjs +113 -105
- package/dist/modules/browser/session.js +108 -60
- package/dist/modules/certification/cli.js +176 -0
- package/dist/modules/certification/fact-checker.js +84 -0
- package/dist/modules/certification/loader.js +111 -0
- package/dist/modules/certification/manifest.js +50 -0
- package/dist/modules/certification/runner.js +162 -0
- package/dist/modules/certification/scenarios.js +124 -0
- package/dist/modules/certification/types.js +1 -0
- package/dist/modules/context/manager.js +119 -10
- package/dist/modules/execution/auditor.js +33 -39
- package/dist/modules/execution/index.js +8 -6
- package/dist/modules/execution/module.js +474 -32
- package/dist/modules/execution/moe-executor.js +97 -40
- package/dist/modules/execution/plan-coverage.js +68 -0
- package/dist/modules/execution/plan-persister.js +46 -0
- package/dist/modules/execution/plan-store.js +159 -0
- package/dist/modules/execution/planner.js +63 -13
- package/dist/modules/execution/stuck-detector.js +252 -39
- package/dist/modules/execution/tracker.js +21 -7
- package/dist/modules/execution/verifier.js +46 -17
- package/dist/modules/hallucination/confidence.js +7 -2
- package/dist/modules/hallucination/consistency.js +8 -42
- package/dist/modules/hallucination/detector.js +26 -21
- package/dist/modules/hallucination/factual.js +170 -150
- package/dist/modules/hallucination/index.js +5 -4
- package/dist/modules/hallucination/js-identifiers.js +72 -0
- package/dist/modules/hallucination/llm-judge.js +103 -0
- package/dist/modules/index.js +5 -5
- package/dist/modules/lsp/client.js +235 -0
- package/dist/modules/lsp/config.js +81 -0
- package/dist/modules/lsp/index.js +3 -0
- package/dist/modules/lsp/module.js +68 -0
- package/dist/modules/lsp/types.js +1 -0
- package/dist/modules/mcp/client.js +8 -2
- package/dist/modules/memory/store.js +4 -0
- package/dist/modules/plugins/builtin/lint-on-write.js +143 -38
- package/dist/modules/processes/index.js +1 -2
- package/dist/modules/processes/registry.js +125 -35
- package/dist/modules/processes/runner.js +9 -110
- package/dist/modules/security/audit-log.js +30 -10
- package/dist/modules/security/command-validator.js +42 -16
- package/dist/modules/security/content-scanner.js +9 -8
- package/dist/modules/security/network-validator.js +2 -2
- package/dist/modules/security/path-validator.js +64 -10
- package/dist/modules/security/security-policies.js +221 -67
- package/dist/modules/security/session-encryption.js +42 -25
- package/dist/modules/session/manager.js +15 -10
- package/dist/modules/session/store.js +62 -8
- package/dist/modules/skills/index.js +2 -3
- package/dist/modules/skills/module.js +10 -23
- package/dist/tools/bash.js +287 -90
- package/dist/tools/create-dir.js +0 -1
- package/dist/tools/delete-file.js +0 -1
- package/dist/tools/edit-file.js +10 -8
- package/dist/tools/executor.js +57 -7
- package/dist/tools/grep-tool.js +51 -29
- package/dist/tools/index.js +55 -40
- package/dist/tools/load-skill.js +14 -18
- package/dist/tools/move-file.js +3 -2
- package/dist/tools/pipeline-run.js +1 -1
- package/dist/tools/read-file.js +15 -5
- package/dist/tools/search-history.js +42 -22
- package/dist/tools/subagent.js +21 -12
- package/dist/tools/web-browse.js +54 -25
- package/dist/tools/web-fetch.js +60 -34
- package/dist/tools/web-search.js +39 -20
- package/dist/tools/write-file.js +13 -10
- package/dist/ui/diff.js +9 -16
- package/dist/ui/renderer.js +69 -6
- package/package.json +48 -45
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/skills/matcher.js +0 -27
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, existsSync, readdirSync, renameSync, statSync, unlinkSync, } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
4
|
+
const MAX_LOG_FILES = 30;
|
|
5
|
+
const DEFAULT_MAX_DAYS = 30;
|
|
6
|
+
const TOOL_OUTPUT_LIMIT = 2000;
|
|
7
|
+
/**
|
|
8
|
+
* Tagged file logger (legacy MMA v1 behavior).
|
|
9
|
+
*
|
|
10
|
+
* Writes human-readable log lines to `~/.mma/logs/`:
|
|
11
|
+
* - `<sessionId>.log` while a session is active
|
|
12
|
+
* - `YYYY-MM-DD.log` for everything outside a session
|
|
13
|
+
*
|
|
14
|
+
* Features restored from v1:
|
|
15
|
+
* - size-based rotation (5 MB → file.log.1, file.log.2, ...)
|
|
16
|
+
* - cleanup of old logs (age + max file count)
|
|
17
|
+
* - tagged helpers: LLM request/response, tool calls, REPL
|
|
18
|
+
*/
|
|
19
|
+
export class FileLogWriter {
|
|
20
|
+
logDir = null;
|
|
21
|
+
sessionLogPath = null;
|
|
22
|
+
setLogDir(dir) {
|
|
23
|
+
this.logDir = dir;
|
|
24
|
+
if (!existsSync(dir)) {
|
|
25
|
+
mkdirSync(dir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Open a per-session log file. Triggers cleanup of old logs. */
|
|
29
|
+
initSessionLog(sessionId) {
|
|
30
|
+
if (!this.logDir)
|
|
31
|
+
return;
|
|
32
|
+
if (!existsSync(this.logDir)) {
|
|
33
|
+
mkdirSync(this.logDir, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
this.sessionLogPath = join(this.logDir, `${sessionId}.log`);
|
|
36
|
+
this.cleanupOldLogs();
|
|
37
|
+
}
|
|
38
|
+
/** Fall back to daily log files when no session is active. */
|
|
39
|
+
closeSessionLog() {
|
|
40
|
+
this.sessionLogPath = null;
|
|
41
|
+
}
|
|
42
|
+
getLogPath() {
|
|
43
|
+
if (this.sessionLogPath)
|
|
44
|
+
return this.sessionLogPath;
|
|
45
|
+
if (!this.logDir)
|
|
46
|
+
return "";
|
|
47
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
48
|
+
return join(this.logDir, `${date}.log`);
|
|
49
|
+
}
|
|
50
|
+
/** Rotate the file if it exceeds the size limit. */
|
|
51
|
+
rotateIfNeeded(filePath) {
|
|
52
|
+
if (!existsSync(filePath))
|
|
53
|
+
return;
|
|
54
|
+
const size = statSync(filePath).size;
|
|
55
|
+
if (size < MAX_LOG_SIZE)
|
|
56
|
+
return;
|
|
57
|
+
let idx = 1;
|
|
58
|
+
while (existsSync(`${filePath}.${idx}`))
|
|
59
|
+
idx++;
|
|
60
|
+
renameSync(filePath, `${filePath}.${idx}`);
|
|
61
|
+
}
|
|
62
|
+
log(level, tag, message) {
|
|
63
|
+
const fp = this.getLogPath();
|
|
64
|
+
if (!fp)
|
|
65
|
+
return;
|
|
66
|
+
if (this.logDir && !existsSync(this.logDir)) {
|
|
67
|
+
mkdirSync(this.logDir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
this.rotateIfNeeded(fp);
|
|
70
|
+
const line = `[${new Date().toISOString()}] [${level}] [${tag}] ${message}\n`;
|
|
71
|
+
try {
|
|
72
|
+
appendFileSync(fp, line, "utf-8");
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
/* file logging is best-effort */
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
logLLMRequest(model, messagesCount, promptPreview, caller) {
|
|
79
|
+
const tag = caller ? `LLM/${caller}` : "LLM";
|
|
80
|
+
this.log("INFO", tag, `→ ${model} | ${messagesCount} messages | "${promptPreview.slice(0, 100)}"`);
|
|
81
|
+
}
|
|
82
|
+
logLLMResponse(model, responseLength, genTimeMs, error, caller) {
|
|
83
|
+
const tag = caller ? `LLM/${caller}` : "LLM";
|
|
84
|
+
if (error) {
|
|
85
|
+
this.log("ERROR", tag, `← ${model} | ${responseLength} chars | ${genTimeMs}ms | ERROR: ${error}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.log("INFO", tag, `← ${model} | ${responseLength} chars | ${genTimeMs}ms`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
logToolCall(tool, preview, result) {
|
|
92
|
+
const previewTrimmed = preview.length > 200 ? preview.slice(0, 200) + "..." : preview;
|
|
93
|
+
if (result !== undefined) {
|
|
94
|
+
const resultTrimmed = result.length > 200 ? result.slice(0, 200) + "..." : result;
|
|
95
|
+
this.log("INFO", "TOOL", `${tool} | ${previewTrimmed} → ${resultTrimmed}`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.log("INFO", "TOOL", `${tool} | ${previewTrimmed}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
logToolOutput(tool, output, exitCode) {
|
|
102
|
+
const trimmed = output.length > TOOL_OUTPUT_LIMIT
|
|
103
|
+
? output.slice(0, TOOL_OUTPUT_LIMIT) +
|
|
104
|
+
`\n... (truncated ${output.length - TOOL_OUTPUT_LIMIT} chars)`
|
|
105
|
+
: output;
|
|
106
|
+
this.log("DEBUG", "TOOL_OUTPUT", `${tool} exit:${exitCode}\n${trimmed}`);
|
|
107
|
+
}
|
|
108
|
+
logREPL(tag, content) {
|
|
109
|
+
const trimmed = content.length > 400 ? content.slice(0, 400) + "..." : content;
|
|
110
|
+
this.log("INFO", `REPL/${tag}`, trimmed);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Clean up old log files.
|
|
114
|
+
* - Deletes files older than maxDays
|
|
115
|
+
* - Keeps at most maxFiles most recent .log files
|
|
116
|
+
*/
|
|
117
|
+
cleanupOldLogs(maxDays = DEFAULT_MAX_DAYS, maxFiles = MAX_LOG_FILES) {
|
|
118
|
+
if (!this.logDir || !existsSync(this.logDir))
|
|
119
|
+
return;
|
|
120
|
+
const now = Date.now();
|
|
121
|
+
const list = () => readdirSync(this.logDir)
|
|
122
|
+
.filter((f) => f.endsWith(".log") || /\.log\.\d+$/.test(f))
|
|
123
|
+
.map((f) => ({
|
|
124
|
+
name: f,
|
|
125
|
+
path: join(this.logDir, f),
|
|
126
|
+
mtime: statSync(join(this.logDir, f)).mtimeMs,
|
|
127
|
+
}))
|
|
128
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
129
|
+
// 1. Delete by age.
|
|
130
|
+
for (const f of list()) {
|
|
131
|
+
if (now - f.mtime > maxDays * 24 * 60 * 60 * 1000) {
|
|
132
|
+
try {
|
|
133
|
+
unlinkSync(f.path);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
/* ignore */
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// 2. Delete excess (fresh but more than maxFiles).
|
|
141
|
+
const remaining = list();
|
|
142
|
+
for (let i = maxFiles; i < remaining.length; i++) {
|
|
143
|
+
try {
|
|
144
|
+
unlinkSync(remaining[i].path);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* ignore */
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|