micro-models-agent 0.51.1 → 0.52.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/dist/cli/commands.js +162 -38
- package/dist/cli/completer.js +5 -5
- package/dist/cli/main.js +42 -54
- package/dist/cli/repl-commands.js +138 -38
- package/dist/cli/repl.js +175 -89
- package/dist/cli/run-result.js +11 -0
- package/dist/cli/security-commands.js +6 -6
- package/dist/cli/setup.js +21 -15
- package/dist/config/config.js +54 -27
- package/dist/config/defaults.js +17 -0
- package/dist/config/domains.js +179 -0
- package/dist/config/index.js +2 -1
- package/dist/config/security.js +28 -8
- package/dist/core/agent.js +162 -30
- package/dist/core/bootstrap.js +94 -17
- package/dist/core/crash-handler.js +51 -0
- package/dist/core/environment.js +199 -0
- package/dist/core/session-logger.js +60 -6
- package/dist/core/version.js +2 -0
- package/dist/i18n/en.json +120 -39
- package/dist/i18n/ru.json +91 -10
- package/dist/llm/openai-compat.js +191 -53
- package/dist/llm/orchestrator.js +5 -3
- package/dist/logger/app-logger.js +50 -4
- package/dist/main.js +1288 -635
- package/dist/modules/browser/session.js +4 -0
- package/dist/modules/certification/cli.js +58 -19
- package/dist/modules/certification/loader.js +2 -1
- package/dist/modules/certification/manifest.js +22 -14
- package/dist/modules/certification/runner.js +91 -5
- package/dist/modules/certification/scenarios.js +290 -7
- package/dist/modules/context/fact-extractor.js +6 -0
- package/dist/modules/context/manager.js +19 -2
- package/dist/modules/execution/audit-runners.js +61 -7
- package/dist/modules/execution/execution-plugin.js +219 -60
- package/dist/modules/execution/module.js +207 -18
- package/dist/modules/execution/moe-executor.js +33 -20
- package/dist/modules/execution/plan-store.js +39 -0
- package/dist/modules/execution/plan-tool.js +188 -19
- package/dist/modules/execution/planner.js +27 -23
- package/dist/modules/execution/stuck-detector.js +244 -8
- package/dist/modules/execution/tracker.js +8 -6
- package/dist/modules/execution/verifier.js +15 -2
- package/dist/modules/hallucination/detector.js +4 -0
- package/dist/modules/hallucination/factual.js +45 -5
- package/dist/modules/indexer/module.js +1 -0
- package/dist/modules/lsp/client.js +123 -12
- package/dist/modules/lsp/index.js +1 -1
- package/dist/modules/lsp/module.js +30 -2
- package/dist/modules/lsp/probe.js +11 -1
- package/dist/modules/lsp/startup-check.js +5 -2
- package/dist/modules/plugins/builtin/lint-on-write.js +144 -41
- package/dist/modules/plugins/manager.js +57 -13
- package/dist/modules/pricing/index.js +61 -0
- package/dist/modules/pricing/prices.js +129 -0
- package/dist/modules/providers/create.js +22 -0
- package/dist/modules/providers/fallback.js +79 -0
- package/dist/modules/providers/health.js +46 -0
- package/dist/modules/providers/index.js +5 -0
- package/dist/modules/providers/manager.js +161 -0
- package/dist/modules/providers/presets.js +128 -0
- package/dist/modules/providers/registry.js +22 -0
- package/dist/modules/providers/types.js +1 -0
- package/dist/modules/registry.js +1 -0
- package/dist/modules/security/command-validator.js +14 -0
- package/dist/modules/security/encryption.js +6 -6
- package/dist/modules/security/network-validator.js +17 -0
- package/dist/modules/security/path-validator.js +22 -26
- package/dist/modules/session/store.js +10 -10
- package/dist/tools/approve.js +1 -0
- package/dist/tools/attach-image.js +12 -0
- package/dist/tools/bash.js +27 -4
- package/dist/tools/browser.js +1 -0
- package/dist/tools/chunk-query.js +1 -0
- package/dist/tools/create-dir.js +1 -0
- package/dist/tools/delete-file.js +1 -0
- package/dist/tools/download-file.js +1 -0
- package/dist/tools/edit-file.js +2 -1
- package/dist/tools/enable-tools.js +1 -0
- package/dist/tools/executor.js +17 -7
- package/dist/tools/file-info.js +1 -0
- package/dist/tools/glob-tool.js +1 -0
- package/dist/tools/grep-tool.js +54 -13
- package/dist/tools/list-dir.js +1 -0
- package/dist/tools/load-skill.js +1 -0
- package/dist/tools/mcp-call.js +1 -0
- package/dist/tools/move-file.js +1 -0
- package/dist/tools/path-utils.js +51 -1
- package/dist/tools/pipeline-run.js +1 -0
- package/dist/tools/process-kill.js +11 -0
- package/dist/tools/process-list.js +1 -0
- package/dist/tools/process-log.js +9 -0
- package/dist/tools/question.js +1 -0
- package/dist/tools/read-file.js +94 -6
- package/dist/tools/recall.js +1 -0
- package/dist/tools/remember.js +1 -0
- package/dist/tools/scope-check.js +7 -5
- package/dist/tools/search-history.js +1 -0
- package/dist/tools/subagent.js +4 -4
- package/dist/tools/web-browse.js +1 -0
- package/dist/tools/web-fetch.js +27 -6
- package/dist/tools/web-search.js +70 -43
- package/dist/tools/write-file.js +1 -0
- package/dist/ui/line-editor.js +142 -23
- package/dist/ui/line-math.js +8 -4
- package/dist/ui/renderer.js +57 -7
- package/package.json +50 -48
package/dist/config/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, unlinkSync, writeFileSync, mkdirSync } from "fs";
|
|
2
2
|
import { join, dirname } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
3
4
|
import { DEFAULTS } from "./defaults";
|
|
4
5
|
import { DEFAULT_SECURITY_CONFIG } from "./security";
|
|
5
6
|
import { DEFAULT_LSP_CONFIG } from "../modules/lsp/config";
|
|
@@ -8,6 +9,12 @@ import { MigrationDetector } from "../migration/detect";
|
|
|
8
9
|
import { BackupManager } from "../migration/backup";
|
|
9
10
|
import { validateExpertConfig } from "./experts";
|
|
10
11
|
import { ConfigEncryptor } from "../modules/security/encryption";
|
|
12
|
+
import { loadDomainFiles, saveDomainFiles } from "./domains";
|
|
13
|
+
// ── Centralized path constants ──────────────────────────────────────────
|
|
14
|
+
export const CONFIG_DIR = join(homedir(), ".mma");
|
|
15
|
+
export const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
16
|
+
export const CONFIG_DOMAIN_DIR = join(CONFIG_DIR, "config");
|
|
17
|
+
// ── Internal helpers ────────────────────────────────────────────────────
|
|
11
18
|
/**
|
|
12
19
|
* Restore RegExp instances in dangerousPatterns that were serialized as {}
|
|
13
20
|
* (pre-0.8.0 configs) or as {__regex, source, flags} (new format).
|
|
@@ -21,7 +28,6 @@ function restoreDangerousPatterns(patterns, defaults) {
|
|
|
21
28
|
return patterns.map((p, i) => {
|
|
22
29
|
if (p instanceof RegExp)
|
|
23
30
|
return p;
|
|
24
|
-
// If the pattern was serialized as {__regex, source, flags}, revive it
|
|
25
31
|
if (p && typeof p === "object") {
|
|
26
32
|
const { source, flags } = p;
|
|
27
33
|
if (source && typeof source === "string") {
|
|
@@ -33,7 +39,6 @@ function restoreDangerousPatterns(patterns, defaults) {
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
// Corrupted entry (e.g. serialized as {} pre-0.8.0): use default by index
|
|
37
42
|
return fallback[i] || fallback[0] || p;
|
|
38
43
|
});
|
|
39
44
|
}
|
|
@@ -82,13 +87,7 @@ function regexReviver(_key, value) {
|
|
|
82
87
|
return value;
|
|
83
88
|
}
|
|
84
89
|
/**
|
|
85
|
-
* Legacy npx `args` for LSP servers that predate the fixed invocation
|
|
86
|
-
* (`--yes --package <server> --package typescript@5 …`). These exact arrays
|
|
87
|
-
* are unsafe: without `--yes`/`--package` the servers fail to bootstrap
|
|
88
|
-
* (`Could not find a valid TypeScript installation`) or the package name is
|
|
89
|
-
* wrong, so the server hangs until the initialize timeout. When a stored
|
|
90
|
-
* server's `args` matches one of these (or is missing) it is replaced with the
|
|
91
|
-
* current default args — user-customized arrays that differ are left alone.
|
|
90
|
+
* Legacy npx `args` for LSP servers that predate the fixed invocation.
|
|
92
91
|
*/
|
|
93
92
|
const LEGACY_LSP_SERVER_ARGS = {
|
|
94
93
|
typescript: { args: ["typescript-language-server", "--stdio"], timeout: 30000 },
|
|
@@ -98,11 +97,7 @@ const LEGACY_LSP_SERVER_ARGS = {
|
|
|
98
97
|
css: { args: ["vscode-css-languageserver", "--stdio"], timeout: 60000 },
|
|
99
98
|
};
|
|
100
99
|
/**
|
|
101
|
-
* Replace stale pre-0.41.1 LSP server invocations
|
|
102
|
-
* the current defaults, so an old `~/.mma/config.json` that overrides the
|
|
103
|
-
* fixed server args can't silently re-break every LSP server. In-memory only —
|
|
104
|
-
* mirrors the `restoreDangerousPatterns` precedent; the file keeps the old
|
|
105
|
-
* args and is normalized again on every load.
|
|
100
|
+
* Replace stale pre-0.41.1 LSP server invocations with current defaults.
|
|
106
101
|
*/
|
|
107
102
|
function normalizeLspServerArgs(config) {
|
|
108
103
|
const servers = config.lsp?.servers;
|
|
@@ -168,9 +163,24 @@ function applyEnvVars(config) {
|
|
|
168
163
|
result.moe = { ...result.moe, enabled: env.MMA_MOE_ENABLED === "true" };
|
|
169
164
|
return result;
|
|
170
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Load config from domain files (preferred) or legacy config.json (fallback).
|
|
168
|
+
*
|
|
169
|
+
* Pipeline:
|
|
170
|
+
* 1. DEFAULTS
|
|
171
|
+
* 2. deepMerge(legacy config.json) — if exists
|
|
172
|
+
* 3. deepMerge(domain files) — if exist, override legacy
|
|
173
|
+
* 4. deepMerge(project .mmrc) — overrides everything
|
|
174
|
+
* 5. Post-load fixups (RegExp, LSP args)
|
|
175
|
+
* 6. Env vars
|
|
176
|
+
* 7. Decrypt
|
|
177
|
+
*
|
|
178
|
+
* On first run (no config.json, no domain files), auto-creates domain files.
|
|
179
|
+
*/
|
|
171
180
|
export function loadConfig(options) {
|
|
172
181
|
const globalPath = join(options.configDir, "config.json");
|
|
173
182
|
mkdirSync(options.configDir, { recursive: true });
|
|
183
|
+
// v1 → v2 migration check (reads config.json directly, before domain logic)
|
|
174
184
|
const detector = new MigrationDetector(options.configDir);
|
|
175
185
|
if (detector.needsMigration()) {
|
|
176
186
|
const backup = new BackupManager(options.configDir);
|
|
@@ -183,40 +193,47 @@ export function loadConfig(options) {
|
|
|
183
193
|
catch { }
|
|
184
194
|
}
|
|
185
195
|
let config = { ...DEFAULTS };
|
|
196
|
+
let legacyDetected = false;
|
|
197
|
+
// Step 1: legacy config.json (fallback)
|
|
186
198
|
const globalData = loadJSON(globalPath);
|
|
187
199
|
if (globalData) {
|
|
188
200
|
config = deepMerge(config, globalData);
|
|
201
|
+
legacyDetected = true;
|
|
189
202
|
}
|
|
190
|
-
|
|
191
|
-
|
|
203
|
+
// Step 2: domain files (override legacy)
|
|
204
|
+
const domainConfig = loadDomainFiles(options.configDir);
|
|
205
|
+
if (domainConfig) {
|
|
206
|
+
config = deepMerge(config, domainConfig);
|
|
207
|
+
legacyDetected = false;
|
|
192
208
|
}
|
|
209
|
+
// Step 3: first run — auto-create domain files instead of config.json
|
|
210
|
+
if (!globalData && !domainConfig) {
|
|
211
|
+
saveDomainFiles(config, options.configDir);
|
|
212
|
+
}
|
|
213
|
+
// Step 4: project .mmrc (overrides everything)
|
|
193
214
|
const projectData = loadJSON(options.projectConfigPath);
|
|
194
215
|
if (projectData) {
|
|
195
216
|
config = deepMerge(config, projectData);
|
|
196
217
|
}
|
|
197
|
-
//
|
|
198
|
-
// as {} in pre-0.8.0 config files, or merged from user config.
|
|
218
|
+
// Step 5: post-load fixups — AFTER all merges
|
|
199
219
|
if (config.security?.contentScan?.dangerousPatterns) {
|
|
200
220
|
config.security.contentScan.dangerousPatterns = restoreDangerousPatterns(config.security.contentScan.dangerousPatterns, DEFAULT_SECURITY_CONFIG.contentScan.dangerousPatterns);
|
|
201
221
|
}
|
|
202
|
-
// Replace stale pre-0.41.1 LSP server args with the current defaults.
|
|
203
222
|
normalizeLspServerArgs(config);
|
|
223
|
+
// Step 6: env vars
|
|
204
224
|
config = applyEnvVars(config);
|
|
205
|
-
//
|
|
225
|
+
// Step 7: decrypt
|
|
206
226
|
try {
|
|
207
227
|
const encryptor = new ConfigEncryptor();
|
|
208
228
|
const decrypted = encryptor.decrypt(config);
|
|
209
|
-
// Merge decrypted sensitive fields back into config
|
|
210
229
|
for (const key of Object.keys(decrypted)) {
|
|
211
230
|
config[key] = decrypted[key];
|
|
212
231
|
}
|
|
213
232
|
}
|
|
214
233
|
catch (e) {
|
|
215
|
-
// If decryption fails, log a warning but continue with the config
|
|
216
234
|
console.warn(t("config.decryption_warning", { error: e.message }));
|
|
217
235
|
}
|
|
218
|
-
|
|
219
|
-
return config;
|
|
236
|
+
return { config, legacyDetected };
|
|
220
237
|
}
|
|
221
238
|
export function validateConfig(config, allToolTags) {
|
|
222
239
|
const errors = validateExpertConfig(config, allToolTags);
|
|
@@ -230,10 +247,21 @@ export function validateConfig(config, allToolTags) {
|
|
|
230
247
|
throw new Error(`Config validation failed:\n${errors.join("\n")}`);
|
|
231
248
|
}
|
|
232
249
|
}
|
|
233
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Save config to domain files (preferred) or legacy single file (fallback).
|
|
252
|
+
*
|
|
253
|
+
* @param config Full AppConfig to save
|
|
254
|
+
* @param configPath Legacy path (e.g. ~/.mma/config.json) — used when configDir is absent
|
|
255
|
+
* @param configDir Optional config directory (e.g. ~/.mma). When provided, writes domain files.
|
|
256
|
+
*/
|
|
257
|
+
export function saveConfig(config, configPath, configDir) {
|
|
258
|
+
if (configDir) {
|
|
259
|
+
saveDomainFiles(config, configDir);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Legacy single-file write (backward compat for tests / edge cases)
|
|
234
263
|
const dir = dirname(configPath);
|
|
235
264
|
mkdirSync(dir, { recursive: true });
|
|
236
|
-
// Encrypt sensitive fields before saving
|
|
237
265
|
try {
|
|
238
266
|
const encryptor = new ConfigEncryptor();
|
|
239
267
|
const encryptedConfig = encryptor.encrypt({
|
|
@@ -242,7 +270,6 @@ export function saveConfig(config, configPath) {
|
|
|
242
270
|
writeFileSync(configPath, JSON.stringify(encryptedConfig, regexReplacer, 2), "utf-8");
|
|
243
271
|
}
|
|
244
272
|
catch (e) {
|
|
245
|
-
// If encryption fails, save without encryption
|
|
246
273
|
console.warn(t("config.encryption_warning", { error: e.message }));
|
|
247
274
|
writeFileSync(configPath, JSON.stringify(config, regexReplacer, 2), "utf-8");
|
|
248
275
|
}
|
package/dist/config/defaults.js
CHANGED
|
@@ -56,6 +56,8 @@ export const DEFAULTS = {
|
|
|
56
56
|
maxRetries: 3,
|
|
57
57
|
baseDelay: 1000,
|
|
58
58
|
maxDelay: 30000,
|
|
59
|
+
maxStreamRetries: 2,
|
|
60
|
+
noDataTimeoutMs: 180000,
|
|
59
61
|
},
|
|
60
62
|
maxToolIterations: 1000,
|
|
61
63
|
stuckThreshold: 6,
|
|
@@ -79,6 +81,21 @@ export const DEFAULTS = {
|
|
|
79
81
|
viewportHeight: 720,
|
|
80
82
|
navigationTimeout: 15000,
|
|
81
83
|
},
|
|
84
|
+
webSearch: {
|
|
85
|
+
enabled: true,
|
|
86
|
+
},
|
|
87
|
+
errorWebSearch: {
|
|
88
|
+
enabled: true,
|
|
89
|
+
threshold: 5,
|
|
90
|
+
maxResults: 5,
|
|
91
|
+
maxQueryChars: 200,
|
|
92
|
+
maxSearchesPerSession: 3,
|
|
93
|
+
requestTimeoutMs: 10000,
|
|
94
|
+
},
|
|
95
|
+
pricing: {
|
|
96
|
+
enabled: true,
|
|
97
|
+
overrides: {},
|
|
98
|
+
},
|
|
82
99
|
ui: {
|
|
83
100
|
spinner: true,
|
|
84
101
|
toolStyle: "inline",
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Mapping: domain name → AppConfig keys that belong to it.
|
|
5
|
+
* Each domain becomes one JSON file in ~/.mma/config/<domain>.json.
|
|
6
|
+
*/
|
|
7
|
+
export const CONFIG_DOMAINS = {
|
|
8
|
+
core: [
|
|
9
|
+
"version",
|
|
10
|
+
"model",
|
|
11
|
+
"contextWindow",
|
|
12
|
+
"contextBudget",
|
|
13
|
+
"modelLoad",
|
|
14
|
+
"maxToolIterations",
|
|
15
|
+
"stuckThreshold",
|
|
16
|
+
"autoPlan",
|
|
17
|
+
"showReasoning",
|
|
18
|
+
"logLevel",
|
|
19
|
+
"locale",
|
|
20
|
+
],
|
|
21
|
+
provider: ["provider", "orchestrator", "retry", "pricing"],
|
|
22
|
+
moe: ["moe", "experts"],
|
|
23
|
+
security: ["security"],
|
|
24
|
+
browser: ["browser"],
|
|
25
|
+
search: ["webSearch", "errorWebSearch"],
|
|
26
|
+
tools: ["tools", "subagent"],
|
|
27
|
+
session: ["session", "sessionIsolation"],
|
|
28
|
+
ui: ["ui"],
|
|
29
|
+
mcp: ["mcpServers"],
|
|
30
|
+
lsp: ["lsp"],
|
|
31
|
+
skills: ["skills"],
|
|
32
|
+
updater: ["updater"],
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* JSON replacer that serializes RegExp objects as {__regex, source, flags}
|
|
36
|
+
* so they survive JSON.stringify/parse round-trips.
|
|
37
|
+
*/
|
|
38
|
+
function regexReplacer(_key, value) {
|
|
39
|
+
if (value instanceof RegExp) {
|
|
40
|
+
return { __regex: true, source: value.source, flags: value.flags };
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* JSON reviver that restores RegExp objects serialized by regexReplacer.
|
|
46
|
+
*/
|
|
47
|
+
function regexReviver(_key, value) {
|
|
48
|
+
if (value &&
|
|
49
|
+
typeof value === "object" &&
|
|
50
|
+
value.__regex === true) {
|
|
51
|
+
const { source, flags } = value;
|
|
52
|
+
try {
|
|
53
|
+
return new RegExp(source, flags);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deep merge two objects. Arrays and scalars in source replace target.
|
|
63
|
+
*/
|
|
64
|
+
function deepMerge(target, source) {
|
|
65
|
+
const result = { ...target };
|
|
66
|
+
for (const key of Object.keys(source)) {
|
|
67
|
+
const srcVal = source[key];
|
|
68
|
+
const tgtVal = target[key];
|
|
69
|
+
if (srcVal !== null &&
|
|
70
|
+
srcVal !== undefined &&
|
|
71
|
+
typeof srcVal === "object" &&
|
|
72
|
+
!Array.isArray(srcVal) &&
|
|
73
|
+
typeof tgtVal === "object" &&
|
|
74
|
+
!Array.isArray(tgtVal)) {
|
|
75
|
+
result[key] = deepMerge(tgtVal, srcVal);
|
|
76
|
+
}
|
|
77
|
+
else if (srcVal !== undefined) {
|
|
78
|
+
result[key] = srcVal;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Extract a domain subset from a full AppConfig.
|
|
85
|
+
*/
|
|
86
|
+
export function extractDomain(config, domain) {
|
|
87
|
+
const keys = CONFIG_DOMAINS[domain];
|
|
88
|
+
if (!keys)
|
|
89
|
+
return {};
|
|
90
|
+
const subset = {};
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
if (config[key] !== undefined) {
|
|
93
|
+
subset[key] = config[key];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return subset;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the file path for a domain config file.
|
|
100
|
+
*/
|
|
101
|
+
export function getDomainFilePath(configDir, domain) {
|
|
102
|
+
return join(configDir, "config", `${domain}.json`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if domain files exist in config/ directory.
|
|
106
|
+
*/
|
|
107
|
+
export function hasDomainFiles(configDir) {
|
|
108
|
+
const configDirPath = join(configDir, "config");
|
|
109
|
+
if (!existsSync(configDirPath))
|
|
110
|
+
return false;
|
|
111
|
+
try {
|
|
112
|
+
const files = readdirSync(configDirPath);
|
|
113
|
+
return files.some((f) => f.endsWith(".json"));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Load all domain files from ~/.mma/config/ and merge into a partial AppConfig.
|
|
121
|
+
* Each file is parsed with regexReviver to restore RegExp objects.
|
|
122
|
+
* Returns null if no domain files exist.
|
|
123
|
+
*/
|
|
124
|
+
export function loadDomainFiles(configDir) {
|
|
125
|
+
const configDirPath = join(configDir, "config");
|
|
126
|
+
if (!existsSync(configDirPath))
|
|
127
|
+
return null;
|
|
128
|
+
let result = {};
|
|
129
|
+
let anyLoaded = false;
|
|
130
|
+
for (const domain of Object.keys(CONFIG_DOMAINS)) {
|
|
131
|
+
const filePath = getDomainFilePath(configDir, domain);
|
|
132
|
+
if (!existsSync(filePath))
|
|
133
|
+
continue;
|
|
134
|
+
try {
|
|
135
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
136
|
+
const data = JSON.parse(raw, regexReviver);
|
|
137
|
+
result = deepMerge(result, data);
|
|
138
|
+
anyLoaded = true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Skip malformed domain files
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return anyLoaded ? result : null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Save a full AppConfig to domain files in ~/.mma/config/.
|
|
148
|
+
* Each domain's keys are extracted and written to config/<domain>.json.
|
|
149
|
+
* RegExp objects are serialized via regexReplacer.
|
|
150
|
+
*/
|
|
151
|
+
export function saveDomainFiles(config, configDir) {
|
|
152
|
+
const configDirPath = join(configDir, "config");
|
|
153
|
+
mkdirSync(configDirPath, { recursive: true });
|
|
154
|
+
for (const [domain, keys] of Object.entries(CONFIG_DOMAINS)) {
|
|
155
|
+
const subset = {};
|
|
156
|
+
let hasContent = false;
|
|
157
|
+
for (const key of keys) {
|
|
158
|
+
if (config[key] !== undefined) {
|
|
159
|
+
subset[key] = config[key];
|
|
160
|
+
hasContent = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!hasContent)
|
|
164
|
+
continue;
|
|
165
|
+
const filePath = getDomainFilePath(configDir, domain);
|
|
166
|
+
writeFileSync(filePath, JSON.stringify(subset, regexReplacer, 2), "utf-8");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Determine which domain a config key belongs to.
|
|
171
|
+
* Returns the domain name or null if not found.
|
|
172
|
+
*/
|
|
173
|
+
export function domainForKey(key) {
|
|
174
|
+
for (const [domain, keys] of Object.entries(CONFIG_DOMAINS)) {
|
|
175
|
+
if (keys.includes(key))
|
|
176
|
+
return domain;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
package/dist/config/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { DEFAULTS } from "./defaults";
|
|
2
|
-
export { loadConfig, saveConfig, validateConfig } from "./config";
|
|
2
|
+
export { loadConfig, saveConfig, validateConfig, CONFIG_DIR, CONFIG_FILE, CONFIG_DOMAIN_DIR } from "./config";
|
|
3
3
|
export { getExpertConfig, validateExpertConfig } from "./experts";
|
|
4
|
+
export { CONFIG_DOMAINS, extractDomain, hasDomainFiles, loadDomainFiles, saveDomainFiles, getDomainFilePath, domainForKey, } from "./domains";
|
package/dist/config/security.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* These settings provide a balance between security and usability.
|
|
4
4
|
*/
|
|
5
5
|
export const DEFAULT_SECURITY_CONFIG = {
|
|
6
|
-
enabled:
|
|
6
|
+
enabled: true,
|
|
7
7
|
bash: {
|
|
8
|
-
enabled:
|
|
8
|
+
enabled: true,
|
|
9
9
|
// Commands that are always blocked (dangerous)
|
|
10
10
|
blacklist: [
|
|
11
11
|
"rm",
|
|
@@ -46,15 +46,34 @@ export const DEFAULT_SECURITY_CONFIG = {
|
|
|
46
46
|
"powershell",
|
|
47
47
|
"pwsh",
|
|
48
48
|
"cmd",
|
|
49
|
+
"bash",
|
|
50
|
+
"sh",
|
|
51
|
+
"zsh",
|
|
52
|
+
"dash",
|
|
53
|
+
"python",
|
|
54
|
+
"python3",
|
|
55
|
+
"node",
|
|
56
|
+
// "bun" intentionally NOT blacklisted: the system prompt tells the model
|
|
57
|
+
// to run TypeScript with `bun <file.ts>` — banning it here contradicts
|
|
58
|
+
// that and burned a whole session on blocked `bun run build` calls.
|
|
59
|
+
// Arbitrary-code execution via flags is still caught by INTERPRETER_FLAGS.
|
|
60
|
+
"perl",
|
|
61
|
+
"ruby",
|
|
62
|
+
"del",
|
|
63
|
+
"rd",
|
|
64
|
+
"erase",
|
|
65
|
+
"taskkill",
|
|
49
66
|
],
|
|
50
67
|
// If whitelist is non-empty, only these commands are allowed
|
|
51
68
|
whitelist: [],
|
|
52
69
|
// Block dangerous flags like --force, -rf, etc.
|
|
53
|
-
|
|
54
|
-
blockDangerousFlags: false,
|
|
70
|
+
blockDangerousFlags: true,
|
|
55
71
|
// Log all executed commands to audit log
|
|
56
72
|
logCommands: true,
|
|
57
73
|
// Dangerous flags that are always blocked
|
|
74
|
+
// Note: -y/--yes are intentionally absent — they are routine, harmless
|
|
75
|
+
// confirmation flags (npm init -y, apt-get -y) and blocking them breaks
|
|
76
|
+
// project scaffolding.
|
|
58
77
|
dangerousFlags: [
|
|
59
78
|
"--force",
|
|
60
79
|
"-rf",
|
|
@@ -66,14 +85,12 @@ export const DEFAULT_SECURITY_CONFIG = {
|
|
|
66
85
|
"--delete",
|
|
67
86
|
"--remove",
|
|
68
87
|
"--dangerous",
|
|
69
|
-
"--yes",
|
|
70
|
-
"-y",
|
|
71
88
|
"--no-confirm",
|
|
72
89
|
],
|
|
73
90
|
// Dangerous operators that are always blocked
|
|
74
91
|
// Note: "&" (background) is not blocked — "&&" (AND) is a legitimate shell operator.
|
|
75
92
|
// Single "&" for backgrounding is harmless and blocking it breaks "cd dir && npm install".
|
|
76
|
-
dangerousOperators: [">", ">>", "2>", "2>>", "`"],
|
|
93
|
+
dangerousOperators: [">", ">>", "2>", "2>>", ";", "&&", "||", "|", "`", "$("],
|
|
77
94
|
},
|
|
78
95
|
paths: {
|
|
79
96
|
enabled: false,
|
|
@@ -98,7 +115,10 @@ export const DEFAULT_SECURITY_CONFIG = {
|
|
|
98
115
|
allowed: [],
|
|
99
116
|
},
|
|
100
117
|
network: {
|
|
101
|
-
|
|
118
|
+
// SSRF protection (private/link-local IPs, non-http schemes) is part of
|
|
119
|
+
// the balanced default policy — without this flag the checks in
|
|
120
|
+
// isUrlAllowed never fire and web tools can reach internal networks.
|
|
121
|
+
enabled: true,
|
|
102
122
|
// Domains that are always denied
|
|
103
123
|
deniedDomains: ["localhost", "127.0.0.1", "::1"],
|
|
104
124
|
// If allowedDomains is non-empty, only these domains are allowed
|