micro-models-agent 0.43.3 → 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 +333 -66
- 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
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from "child_process";
|
|
2
|
-
import { platform } from "os";
|
|
3
|
-
const MAX_LOG_LINES = 2000;
|
|
4
|
-
const MAX_KEPT_PROCESSES = 20;
|
|
5
|
-
let seq = 0;
|
|
6
|
-
function killTree(child) {
|
|
7
|
-
const pid = child.pid;
|
|
8
|
-
if (!pid)
|
|
9
|
-
return;
|
|
10
|
-
if (platform() === "win32") {
|
|
11
|
-
try {
|
|
12
|
-
spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
13
|
-
windowsHide: true,
|
|
14
|
-
stdio: "ignore",
|
|
15
|
-
timeout: 3000,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
/* already dead */
|
|
20
|
-
}
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
process.kill(-pid, "SIGTERM");
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
try {
|
|
28
|
-
child.kill("SIGKILL");
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
/* already dead */
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class ProcessRegistry {
|
|
36
|
-
procs = new Map();
|
|
37
|
-
children = new Map();
|
|
38
|
-
exitWaiters = new Map();
|
|
39
|
-
/**
|
|
40
|
-
* Start a command. The returned entry buffers output and reports status; a
|
|
41
|
-
* call may check `waitForExit(id)` to learn when (if ever) it finishes.
|
|
42
|
-
*/
|
|
43
|
-
start(command, cwd, sessionId) {
|
|
44
|
-
const id = `proc_${Date.now()}_${++seq}`;
|
|
45
|
-
const entry = {
|
|
46
|
-
id,
|
|
47
|
-
pid: 0,
|
|
48
|
-
command,
|
|
49
|
-
cwd,
|
|
50
|
-
sessionId,
|
|
51
|
-
status: "running",
|
|
52
|
-
exitCode: null,
|
|
53
|
-
startedAt: new Date().toISOString(),
|
|
54
|
-
log: [],
|
|
55
|
-
};
|
|
56
|
-
this.trimOldEntries();
|
|
57
|
-
this.procs.set(id, entry);
|
|
58
|
-
let child;
|
|
59
|
-
try {
|
|
60
|
-
child = spawn(command, {
|
|
61
|
-
cwd,
|
|
62
|
-
shell: true,
|
|
63
|
-
windowsHide: true,
|
|
64
|
-
detached: platform() !== "win32",
|
|
65
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
entry.status = "killed";
|
|
70
|
-
entry.spawnError = e?.message || String(e);
|
|
71
|
-
entry.log.push(`[process error] ${entry.spawnError}`);
|
|
72
|
-
return entry;
|
|
73
|
-
}
|
|
74
|
-
this.children.set(id, child);
|
|
75
|
-
entry.pid = child.pid ?? 0;
|
|
76
|
-
// On Windows, children spawned via cmd.exe output in the OEM code page,
|
|
77
|
-
// NOT UTF-8. Detect the active code page via chcp.com; fall back to
|
|
78
|
-
// ibm866 (Russian CP866) when detection fails — still correct for the
|
|
79
|
-
// majority of users, and always better than the UTF-8 default.
|
|
80
|
-
const decoder = platform() === "win32"
|
|
81
|
-
? (() => {
|
|
82
|
-
try {
|
|
83
|
-
const cpOut = require("child_process")
|
|
84
|
-
.execSync("chcp.com", {
|
|
85
|
-
encoding: "buffer",
|
|
86
|
-
timeout: 2000,
|
|
87
|
-
windowsHide: true,
|
|
88
|
-
})
|
|
89
|
-
.toString("latin1");
|
|
90
|
-
const m = cpOut.match(/(\d+)/);
|
|
91
|
-
if (m)
|
|
92
|
-
return new TextDecoder("ibm" + m[1]);
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
/* ignore */
|
|
96
|
-
}
|
|
97
|
-
return new TextDecoder("ibm866");
|
|
98
|
-
})()
|
|
99
|
-
: new TextDecoder("utf-8");
|
|
100
|
-
let buf = "";
|
|
101
|
-
const pushLine = (line) => {
|
|
102
|
-
if (entry.log.length >= MAX_LOG_LINES) {
|
|
103
|
-
entry.log.shift();
|
|
104
|
-
}
|
|
105
|
-
entry.log.push(line);
|
|
106
|
-
};
|
|
107
|
-
const append = (chunk) => {
|
|
108
|
-
const decoded = decoder.decode(chunk, { stream: true });
|
|
109
|
-
buf += decoded;
|
|
110
|
-
const lines = buf.split(/\r?\n/);
|
|
111
|
-
buf = lines.pop() ?? "";
|
|
112
|
-
for (const line of lines) {
|
|
113
|
-
pushLine(line);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const flush = () => {
|
|
117
|
-
buf += decoder.decode();
|
|
118
|
-
if (buf) {
|
|
119
|
-
pushLine(buf);
|
|
120
|
-
buf = "";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const resolveExit = () => {
|
|
124
|
-
this.exitWaiters.get(id)?.resolve();
|
|
125
|
-
};
|
|
126
|
-
child.stdout?.on("data", append);
|
|
127
|
-
child.stderr?.on("data", append);
|
|
128
|
-
child.on("error", (err) => {
|
|
129
|
-
if (entry.status === "running") {
|
|
130
|
-
entry.status = "killed";
|
|
131
|
-
}
|
|
132
|
-
entry.spawnError = err.message;
|
|
133
|
-
append(Buffer.from(`[process error] ${err.message}`));
|
|
134
|
-
resolveExit();
|
|
135
|
-
});
|
|
136
|
-
child.on("close", (code) => {
|
|
137
|
-
flush();
|
|
138
|
-
if (entry.status === "running") {
|
|
139
|
-
entry.status = "exited";
|
|
140
|
-
}
|
|
141
|
-
entry.exitCode = code;
|
|
142
|
-
this.children.delete(id);
|
|
143
|
-
resolveExit();
|
|
144
|
-
});
|
|
145
|
-
let resolve;
|
|
146
|
-
const promise = new Promise((r) => {
|
|
147
|
-
resolve = r;
|
|
148
|
-
});
|
|
149
|
-
this.exitWaiters.set(id, { promise, resolve });
|
|
150
|
-
return entry;
|
|
151
|
-
}
|
|
152
|
-
list(sessionId) {
|
|
153
|
-
const all = Array.from(this.procs.values());
|
|
154
|
-
if (!sessionId)
|
|
155
|
-
return all;
|
|
156
|
-
return all.filter((p) => p.sessionId === sessionId);
|
|
157
|
-
}
|
|
158
|
-
get(id) {
|
|
159
|
-
return this.procs.get(id);
|
|
160
|
-
}
|
|
161
|
-
getLog(id, tail) {
|
|
162
|
-
const entry = this.procs.get(id);
|
|
163
|
-
if (!entry)
|
|
164
|
-
return "";
|
|
165
|
-
const lines = tail && tail > 0 ? entry.log.slice(-tail) : entry.log;
|
|
166
|
-
return lines.join("\n");
|
|
167
|
-
}
|
|
168
|
-
/** Kill a background process tree. Returns false when not found. */
|
|
169
|
-
kill(id) {
|
|
170
|
-
const entry = this.procs.get(id);
|
|
171
|
-
if (!entry)
|
|
172
|
-
return false;
|
|
173
|
-
if (entry.status === "running") {
|
|
174
|
-
entry.status = "killed";
|
|
175
|
-
const child = this.children.get(id);
|
|
176
|
-
if (child) {
|
|
177
|
-
killTree(child);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
/** Kill every managed background process (used on agent shutdown). */
|
|
183
|
-
killAll(sessionId) {
|
|
184
|
-
const targets = this.list(sessionId);
|
|
185
|
-
for (const entry of targets) {
|
|
186
|
-
this.kill(entry.id);
|
|
187
|
-
}
|
|
188
|
-
return targets.length;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Resolve `true` when the process exits (or fails to spawn) within
|
|
192
|
-
* `timeoutMs`, otherwise `false` (still running → a background process).
|
|
193
|
-
*/
|
|
194
|
-
waitForExit(id, timeoutMs) {
|
|
195
|
-
const entry = this.procs.get(id);
|
|
196
|
-
const waiter = this.exitWaiters.get(id);
|
|
197
|
-
if (!entry || entry.status !== "running" || !waiter) {
|
|
198
|
-
return Promise.resolve(true);
|
|
199
|
-
}
|
|
200
|
-
return new Promise((resolve) => {
|
|
201
|
-
const timer = setTimeout(() => resolve(false), timeoutMs);
|
|
202
|
-
waiter.promise.then(() => {
|
|
203
|
-
clearTimeout(timer);
|
|
204
|
-
resolve(true);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Remove a finished entry (foreground results do not linger). A still-running
|
|
210
|
-
* entry is killed first so nothing is orphaned.
|
|
211
|
-
*/
|
|
212
|
-
remove(id) {
|
|
213
|
-
const entry = this.procs.get(id);
|
|
214
|
-
if (!entry)
|
|
215
|
-
return false;
|
|
216
|
-
if (entry.status === "running") {
|
|
217
|
-
const child = this.children.get(id);
|
|
218
|
-
if (child) {
|
|
219
|
-
killTree(child);
|
|
220
|
-
}
|
|
221
|
-
entry.status = "killed";
|
|
222
|
-
}
|
|
223
|
-
this.procs.delete(id);
|
|
224
|
-
this.children.delete(id);
|
|
225
|
-
this.exitWaiters.delete(id);
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
trimOldEntries() {
|
|
229
|
-
if (this.procs.size < MAX_KEPT_PROCESSES)
|
|
230
|
-
return;
|
|
231
|
-
const sorted = Array.from(this.procs.values()).sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
232
|
-
const toRemove = sorted.slice(0, sorted.length - MAX_KEPT_PROCESSES + 1);
|
|
233
|
-
for (const entry of toRemove) {
|
|
234
|
-
this.remove(entry.id);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
export const processRegistry = new ProcessRegistry();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const activeChildren = new Map();
|
|
2
|
-
/** Register a kill callback for a tool call id (executor timeout/abort). */
|
|
3
|
-
export function registerKillable(callId, kill) {
|
|
4
|
-
activeChildren.set(callId, { kill });
|
|
5
|
-
}
|
|
6
|
-
/** Unregister a tool call's kill callback once its handler finished. */
|
|
7
|
-
export function unregisterKillable(callId) {
|
|
8
|
-
activeChildren.delete(callId);
|
|
9
|
-
}
|
|
10
|
-
/** Invoke (and drop) the kill callback registered for `callId`. */
|
|
11
|
-
export function killByCallId(callId) {
|
|
12
|
-
const entry = activeChildren.get(callId);
|
|
13
|
-
if (!entry)
|
|
14
|
-
return false;
|
|
15
|
-
activeChildren.delete(callId);
|
|
16
|
-
try {
|
|
17
|
-
entry.kill();
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
/* already dead */
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
package/dist/modules/registry.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export class ModuleRegistry {
|
|
2
|
-
modules = new Map();
|
|
3
|
-
register(mod) {
|
|
4
|
-
this.modules.set(mod.name, mod);
|
|
5
|
-
}
|
|
6
|
-
get(name) {
|
|
7
|
-
return this.modules.get(name);
|
|
8
|
-
}
|
|
9
|
-
listModules() {
|
|
10
|
-
return Array.from(this.modules.keys()).sort();
|
|
11
|
-
}
|
|
12
|
-
collectPromptBlocks() {
|
|
13
|
-
const blocks = [];
|
|
14
|
-
for (const mod of this.modules.values()) {
|
|
15
|
-
if (mod.getSystemPromptBlock) {
|
|
16
|
-
const block = mod.getSystemPromptBlock();
|
|
17
|
-
if (block)
|
|
18
|
-
blocks.push(block);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return blocks;
|
|
22
|
-
}
|
|
23
|
-
collectToolDefinitions() {
|
|
24
|
-
const tools = [];
|
|
25
|
-
for (const mod of this.modules.values()) {
|
|
26
|
-
if (mod.getToolDefinitions) {
|
|
27
|
-
const defs = mod.getToolDefinitions();
|
|
28
|
-
if (defs)
|
|
29
|
-
tools.push(...defs);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return tools;
|
|
33
|
-
}
|
|
34
|
-
collectPlugins() {
|
|
35
|
-
const plugins = [];
|
|
36
|
-
for (const mod of this.modules.values()) {
|
|
37
|
-
if (mod.getPlugin) {
|
|
38
|
-
const plugin = mod.getPlugin();
|
|
39
|
-
if (plugin)
|
|
40
|
-
plugins.push(plugin);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return plugins;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, appendFileSync } from "fs";
|
|
2
|
-
import { resolve, join } from "path";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { globalAuditNotifier } from "./audit-notifier";
|
|
5
|
-
let _globalAuditDir = resolve(homedir(), ".mma", "logs");
|
|
6
|
-
let _sessionAuditDir = null;
|
|
7
|
-
function getAuditDir() {
|
|
8
|
-
return _sessionAuditDir ?? _globalAuditDir;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Set the session directory for audit logs. When set, all audit entries
|
|
12
|
-
* are written to the session-specific directory instead of the global one.
|
|
13
|
-
*/
|
|
14
|
-
export function setAuditSessionDir(dir) {
|
|
15
|
-
_sessionAuditDir = dir;
|
|
16
|
-
if (!existsSync(dir)) {
|
|
17
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Clear the session directory — fall back to global audit dir.
|
|
22
|
-
*/
|
|
23
|
-
export function clearAuditSessionDir() {
|
|
24
|
-
_sessionAuditDir = null;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Set the global audit log directory (used when no session dir is active).
|
|
28
|
-
*/
|
|
29
|
-
export function setGlobalAuditDir(dir) {
|
|
30
|
-
_globalAuditDir = dir;
|
|
31
|
-
if (!existsSync(dir)) {
|
|
32
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Write an audit log entry
|
|
37
|
-
*/
|
|
38
|
-
export function logAudit(entry) {
|
|
39
|
-
const dir = getAuditDir();
|
|
40
|
-
if (!existsSync(dir)) {
|
|
41
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const logEntry = JSON.stringify(entry);
|
|
45
|
-
appendFileSync(join(dir, "audit.jsonl"), logEntry + "\n", "utf8");
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// Silently fail if we can't write to audit log
|
|
49
|
-
// This shouldn't break the agent
|
|
50
|
-
}
|
|
51
|
-
// Notify audit notifier if enabled
|
|
52
|
-
try {
|
|
53
|
-
globalAuditNotifier.notify(entry);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
// Silently fail if notification fails
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Log a tool call
|
|
61
|
-
*/
|
|
62
|
-
export function logToolCall(sessionId, tool, success, details) {
|
|
63
|
-
logAudit({
|
|
64
|
-
timestamp: new Date().toISOString(),
|
|
65
|
-
sessionId,
|
|
66
|
-
action: "tool_call",
|
|
67
|
-
tool,
|
|
68
|
-
success,
|
|
69
|
-
details,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Log a file write operation
|
|
74
|
-
*/
|
|
75
|
-
export function logFileWrite(sessionId, path, success, details) {
|
|
76
|
-
logAudit({
|
|
77
|
-
timestamp: new Date().toISOString(),
|
|
78
|
-
sessionId,
|
|
79
|
-
action: "file_write",
|
|
80
|
-
path,
|
|
81
|
-
success,
|
|
82
|
-
details,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Log a file delete operation
|
|
87
|
-
*/
|
|
88
|
-
export function logFileDelete(sessionId, path, success, details) {
|
|
89
|
-
logAudit({
|
|
90
|
-
timestamp: new Date().toISOString(),
|
|
91
|
-
sessionId,
|
|
92
|
-
action: "file_delete",
|
|
93
|
-
path,
|
|
94
|
-
success,
|
|
95
|
-
details,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Log a bash command execution
|
|
100
|
-
*/
|
|
101
|
-
export function logBashCommand(sessionId, command, success, details) {
|
|
102
|
-
logAudit({
|
|
103
|
-
timestamp: new Date().toISOString(),
|
|
104
|
-
sessionId,
|
|
105
|
-
action: "bash_command",
|
|
106
|
-
command,
|
|
107
|
-
success,
|
|
108
|
-
details,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Log a network request
|
|
113
|
-
*/
|
|
114
|
-
export function logNetworkRequest(sessionId, url, success, details) {
|
|
115
|
-
logAudit({
|
|
116
|
-
timestamp: new Date().toISOString(),
|
|
117
|
-
sessionId,
|
|
118
|
-
action: "network_request",
|
|
119
|
-
url,
|
|
120
|
-
success,
|
|
121
|
-
details,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Log a security block event
|
|
126
|
-
*/
|
|
127
|
-
export function logSecurityBlock(sessionId, action, reason, details) {
|
|
128
|
-
logAudit({
|
|
129
|
-
timestamp: new Date().toISOString(),
|
|
130
|
-
sessionId,
|
|
131
|
-
action: "security_block",
|
|
132
|
-
success: false,
|
|
133
|
-
reason,
|
|
134
|
-
details,
|
|
135
|
-
});
|
|
136
|
-
}
|